diff options
author | George Hazan <ghazan@miranda.im> | 2016-12-07 17:57:30 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2016-12-07 17:57:30 +0300 |
commit | d6902f812511786ded73a5d87e3e788e47853365 (patch) | |
tree | dfd58de94078c9a163144f2e827d7bdb440fc2c5 /plugins/TabSRMM/src/modplus.cpp | |
parent | fb2614dce27af59cc5385934eb1d893c47ee0cdd (diff) |
TabSRMM:
- fixes #643 (Tabsrmm "insert image" button regression);
- massive code cleaning
Diffstat (limited to 'plugins/TabSRMM/src/modplus.cpp')
-rw-r--r-- | plugins/TabSRMM/src/modplus.cpp | 88 |
1 files changed, 32 insertions, 56 deletions
diff --git a/plugins/TabSRMM/src/modplus.cpp b/plugins/TabSRMM/src/modplus.cpp index 3885fbe072..99620abb18 100644 --- a/plugins/TabSRMM/src/modplus.cpp +++ b/plugins/TabSRMM/src/modplus.cpp @@ -68,9 +68,9 @@ static int CustomButtonPressed(WPARAM wParam, LPARAM lParam) BBButton bbd = {};
bbd.dwButtonID = 1;
bbd.pszModuleName = "Tabmodplus";
- Srmm_SetButtonState(wParam, &bbd);
+ Srmm_GetButtonState(cbcd->hwndFrom, &bbd);
- wchar_t *pszText = L"";
+ ptrW pszText;
CHARRANGE cr;
cr.cpMin = cr.cpMax = 0;
SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_EXGETSEL, 0, (LPARAM)&cr);
@@ -81,80 +81,56 @@ static int CustomButtonPressed(WPARAM wParam, LPARAM lParam) SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_GETSELTEXT, 0, (LPARAM)pszText);
}
- int state = 0;
- if (cbcd->flags & BBCF_RIGHTBUTTON)
- state = 1;
- else if (textlenght)
- state = 2;
- else if (bbd.bbbFlags & BBSF_PUSHED)
- state = 3;
- else
- state = 4;
-
- wchar_t *pszFormatedText = NULL, *pszMenu[256] = { 0 };
-
size_t bufSize;
+ CMStringW pwszFormatedText;
- switch (state) {
- case 1:
- {
+ if (cbcd->flags & BBCF_RIGHTBUTTON) {
int menulimit = M.GetByte("tabmodplus", "MenuCount", 0);
- if (menulimit == 0)
- break;
-
- HMENU hMenu = CreatePopupMenu();
-
- for (int menunum = 0; menunum < menulimit; menunum++) {
- pszMenu[menunum] = getMenuEntry(menunum);
- AppendMenu(hMenu, MF_STRING, menunum + 1, pszMenu[menunum]);
+ if (menulimit != 0) {
+ HMENU hMenu = CreatePopupMenu();
+ LIST<wchar_t> arMenuLines(1);
+
+ for (int menunum = 0; menunum < menulimit; menunum++) {
+ wchar_t *pwszText = getMenuEntry(menunum);
+ arMenuLines.insert(pwszText);
+ AppendMenu(hMenu, MF_STRING, menunum + 1, pwszText);
+ }
+
+ int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL);
+ if (res != 0) {
+ bufSize = textlenght + mir_wstrlen(arMenuLines[res-1]) + 2;
+ pwszFormatedText.Format(arMenuLines[res-1], pszText);
+ }
+
+ for (int i = 0; i < arMenuLines.getCount(); i++)
+ mir_free(arMenuLines[i]);
}
-
- int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL);
- if (res == 0)
- break;
-
- bufSize = textlenght + mir_wstrlen(pszMenu[res - 1]) + 2;
- pszFormatedText = (wchar_t*)_alloca(bufSize*sizeof(wchar_t));
- mir_snwprintf(pszFormatedText, bufSize, pszMenu[res - 1], pszText);
}
- break;
-
- case 2:
+ else if (textlenght) {
SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_GETSELTEXT, 0, (LPARAM)pszText);
- bufSize = textlenght + 12;
- pszFormatedText = (wchar_t*)_alloca(bufSize*sizeof(wchar_t));
- mir_snwprintf(pszFormatedText, bufSize, L"[img]%s[/img]", pszText);
+ pwszFormatedText.Format(L"[img]%s[/img]", pszText);
bbd.pwszTooltip = 0;
bbd.hIcon = 0;
bbd.bbbFlags = BBSF_RELEASED;
Srmm_SetButtonState(wParam, &bbd);
- break;
-
- case 3:
- pszFormatedText = L"[img]";
+ }
+ else if (bbd.bbbFlags & BBSF_PUSHED) {
+ pwszFormatedText = L"[img]";
bbd.pwszTooltip = LPGENW("Insert [img] tag / surround selected text with [img][/img]");
Srmm_SetButtonState(wParam, &bbd);
- break;
-
- case 4:
- pszFormatedText = L"[/img]";
+ }
+ else {
+ pwszFormatedText = L"[/img]";
bbd.pwszTooltip = LPGENW("Insert [img] tag / surround selected text with [img][/img]");
Srmm_SetButtonState(wParam, &bbd);
- break;
}
- for (int i = 0; pszMenu[i]; i++)
- mir_free(pszMenu[i]);
-
- if (pszFormatedText)
- SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_REPLACESEL, TRUE, (LPARAM)pszFormatedText);
-
- if (textlenght)
- mir_free(pszText);
+ if (!pwszFormatedText.IsEmpty())
+ SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_REPLACESEL, TRUE, (LPARAM)pwszFormatedText.c_str());
return 1;
}
|