summaryrefslogtreecommitdiff
path: root/plugins/QuickMessages
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-08-03 17:02:23 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-08-03 17:02:23 +0300
commit26ab3f4905bdfe972c6daba4a3a4aaaa8183dae5 (patch)
tree309aab538bcf40267067df85b3bd1b21fab7b58b /plugins/QuickMessages
parent86d2407716be2fac39fd2b64b0af6cdf6bb5dd01 (diff)
QuickMessages: code cleaning
Diffstat (limited to 'plugins/QuickMessages')
-rw-r--r--plugins/QuickMessages/src/main.cpp77
-rw-r--r--plugins/QuickMessages/src/options.cpp105
-rw-r--r--plugins/QuickMessages/src/stdafx.h8
3 files changed, 77 insertions, 113 deletions
diff --git a/plugins/QuickMessages/src/main.cpp b/plugins/QuickMessages/src/main.cpp
index 506fe593c1..9508f19899 100644
--- a/plugins/QuickMessages/src/main.cpp
+++ b/plugins/QuickMessages/src/main.cpp
@@ -57,8 +57,9 @@ static int InputMenuPopup(WPARAM, LPARAM lParam)
{
HMENU hSubMenu = NULL;
int i = 0;
- MessageWindowPopupData * mwpd = (MessageWindowPopupData *)lParam;
- if (mwpd->uFlags == MSG_WINDOWPOPUP_LOG || !g_bQuickMenu || !QuickList->realCount) return 0;
+ MessageWindowPopupData *mwpd = (MessageWindowPopupData *)lParam;
+ if (mwpd->uFlags == MSG_WINDOWPOPUP_LOG || !g_bQuickMenu || !QuickList->realCount)
+ return 0;
if (mwpd->uType == MSG_WINDOWPOPUP_SHOWING) {
hSubMenu = CreatePopupMenu();
@@ -67,8 +68,8 @@ static int InputMenuPopup(WPARAM, LPARAM lParam)
InsertMenu((HMENU)mwpd->hMenu, 7, MF_SEPARATOR | MF_BYPOSITION, 0, 0);
qsort(QuickList->items, QuickList->realCount, sizeof(QuickData *), sstQuickSortButtons);
for (i = 0; i < QuickList->realCount; i++) {
- QuickData* qd = (QuickData *)QuickList->items[i];
- if (qd->fEntryType&QMF_EX_SEPARATOR)
+ QuickData *qd = (QuickData*)QuickList->items[i];
+ if (qd->fEntryType & QMF_EX_SEPARATOR)
AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
else
AppendMenu(hSubMenu, MF_STRING, qd->dwPos + 254, qd->ptszValueName);
@@ -76,13 +77,11 @@ static int InputMenuPopup(WPARAM, LPARAM lParam)
}
else if (mwpd->uType == MSG_WINDOWPOPUP_SELECTED && mwpd->selection >= 254) {
for (i = 0; i < QuickList->realCount; i++) {
- QuickData* qd = (QuickData *)QuickList->items[i];
+ QuickData *qd = (QuickData *)QuickList->items[i];
if ((qd->dwPos + 254) == mwpd->selection) {
CHARRANGE cr;
UINT textlenght = 0;
- wchar_t* pszText = NULL;
- wchar_t* ptszQValue = NULL;
- wchar_t* pszCBText = NULL;
+ ptrW pszText, ptszQValue, pszCBText;
BOOL bIsService = 0;
if (IsClipboardFormatAvailable(CF_TEXT)) {
@@ -112,17 +111,11 @@ static int InputMenuPopup(WPARAM, LPARAM lParam)
if (qd->ptszValue) {
ptszQValue = ParseString(mwpd->hContact, qd->ptszValue, pszText ? pszText : L"", pszCBText ? pszCBText : L"", (int)mir_wstrlen(qd->ptszValue), textlenght, pszCBText ? (int)mir_wstrlen(pszCBText) : 0);
if ((bIsService = qd->bIsService) && ptszQValue)
-
CallService(mir_u2a(ptszQValue), (WPARAM)mwpd->hContact, 0);
-
}
if (ptszQValue)
SendMessage(mwpd->hwnd, EM_REPLACESEL, TRUE, (LPARAM)ptszQValue);
-
- if (pszText) mir_free(pszText);
- if (ptszQValue) free(ptszQValue);
- if (pszCBText) mir_free(pszCBText);
break;
}
}
@@ -134,37 +127,24 @@ static int InputMenuPopup(WPARAM, LPARAM lParam)
static int CustomButtonPressed(WPARAM, LPARAM lParam)
{
CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam;
+ if (mir_strcmp(cbcd->pszModule, PLGNAME))
+ return 0;
- CHARRANGE cr;
- HWND hEdit = NULL;
- BOOL bCTRL = 0;
- BOOL bIsService = 0;
- wchar_t* pszText = NULL;
- wchar_t* pszCBText = NULL;
- wchar_t* ptszQValue = NULL;
- UINT textlenght = 0;
- SortedList* sl = NULL;
- int state = 0;
-
- if (mir_strcmp(cbcd->pszModule, PLGNAME)) return 0;
-
- if (!ButtonsList[cbcd->dwButtonId]) return 1;
+ if (!ButtonsList[cbcd->dwButtonId])
+ return 1;
- sl = ButtonsList[cbcd->dwButtonId]->sl;
+ SortedList *sl = ButtonsList[cbcd->dwButtonId]->sl;
+ if (!sl)
+ return 1;
- if (!sl) return 1;
+ BOOL bCTRL = 0;
+ BOOL bIsService = 0;
+ ptrW pszText, pszCBText, ptszQValue;
if (IsClipboardFormatAvailable(CF_TEXT)) {
if (OpenClipboard(cbcd->hwndFrom)) {
- HANDLE hData = NULL;
- wchar_t* chBuffer = NULL;
- int textLength = 0;
-
- hData = GetClipboardData(CF_UNICODETEXT);
-
- chBuffer = (wchar_t*)GlobalLock(hData);
- textLength = (int)mir_wstrlen(chBuffer);
- pszCBText = mir_wstrdup(chBuffer);
+ HANDLE hData = GetClipboardData(CF_UNICODETEXT);
+ pszCBText = mir_wstrdup((wchar_t*)GlobalLock(hData));
GlobalUnlock(hData);
CloseClipboard();
}
@@ -172,20 +152,21 @@ static int CustomButtonPressed(WPARAM, LPARAM lParam)
qsort(sl->items, sl->realCount, sizeof(ButtonData *), sstSortButtons);
- hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE);
- if (!hEdit) hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE);
+ HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_SRMM_MESSAGE);
+ CHARRANGE cr;
cr.cpMin = cr.cpMax = 0;
SendMessage(hEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
- textlenght = cr.cpMax - cr.cpMin;
+ UINT textlenght = cr.cpMax - cr.cpMin;
if (textlenght) {
pszText = (wchar_t *)mir_alloc((textlenght + 10)*sizeof(wchar_t));
memset(pszText, 0, ((textlenght + 10) * sizeof(wchar_t)));
SendMessage(hEdit, EM_GETSELTEXT, 0, (LPARAM)pszText);
}
- if (cbcd->flags&BBCF_RIGHTBUTTON)
+ int state;
+ if (cbcd->flags & BBCF_RIGHTBUTTON)
state = 1;
else if (sl->realCount == 1)
state = 2;
@@ -219,7 +200,7 @@ static int CustomButtonPressed(WPARAM, LPARAM lParam)
for (int menunum = 0; menunum < sl->realCount; menunum++) {
ButtonData *bd = (ButtonData *)sl->items[menunum];
- if (bd->dwOPFlags&QMF_NEW)
+ if (bd->dwOPFlags & QMF_NEW)
continue;
BOOL bSetPopupMark = FALSE;
@@ -231,7 +212,7 @@ static int CustomButtonPressed(WPARAM, LPARAM lParam)
if (bd->pszValue && bd->fEntryType == 0)
hSubMenu = NULL;
- if (bd->fEntryType&QMF_EX_SEPARATOR)
+ if (bd->fEntryType & QMF_EX_SEPARATOR)
AppendMenu((HMENU)((hSubMenu && !bSetPopupMark) ? hSubMenu : hMenu), MF_SEPARATOR, 0, NULL);
else
AppendMenu((HMENU)((hSubMenu && !bSetPopupMark) ? hSubMenu : hMenu),
@@ -257,15 +238,11 @@ static int CustomButtonPressed(WPARAM, LPARAM lParam)
if (!bIsService) {
SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)ptszQValue);
- if ((g_bLClickAuto&&state != 1) || (g_bRClickAuto&&state == 1) || cbcd->flags&BBCF_CONTROLPRESSED || bCTRL)
+ if ((g_bLClickAuto && state != 1) || (g_bRClickAuto && state == 1) || cbcd->flags & BBCF_CONTROLPRESSED || bCTRL)
SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
}
- free(ptszQValue);
}
-
- mir_free(pszText);
- mir_free(pszCBText);
return 1;
}
diff --git a/plugins/QuickMessages/src/options.cpp b/plugins/QuickMessages/src/options.cpp
index 482d750c79..e26d36c13a 100644
--- a/plugins/QuickMessages/src/options.cpp
+++ b/plugins/QuickMessages/src/options.cpp
@@ -26,7 +26,7 @@ HTREEITEM hDragItem = NULL;
HWND hButtonsList = NULL;
HWND hMenuTree = NULL;
HWND hwndEdit = NULL;
-
+
HWND g_opHdlg = NULL, g_varhelpDlg = NULL;
INT_PTR CALLBACK HelpDlgProc(HWND hdlg, UINT msg, WPARAM, LPARAM lparam)
@@ -95,13 +95,13 @@ static LRESULT CALLBACK EditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPA
break;
case WM_KEYDOWN:
- {
- if (wParam == VK_RETURN)
- if (hwnd == GetDlgItem(hParent, IDC_BUTTONNAME))
- SendMessage(hParent, WM_COMMAND, IDC_BLISTADD, 0);
- else
- SendMessage(hParent, WM_COMMAND, IDC_MTREEADD, 0);
- }break;
+ if (wParam == VK_RETURN) {
+ if (hwnd == GetDlgItem(hParent, IDC_BUTTONNAME))
+ SendMessage(hParent, WM_COMMAND, IDC_BLISTADD, 0);
+ else
+ SendMessage(hParent, WM_COMMAND, IDC_MTREEADD, 0);
+ }
+ break;
}
return mir_callNextSubclass(hwnd, EditSubclassProc, msg, wParam, lParam);
@@ -238,6 +238,7 @@ void SaveMenuTree()
if (ld->ptszButtonName)
mir_free(ld->ptszButtonName);
+
if (iBl > 0)
if (hti = TreeView_GetNextSibling(hButtonsList, hti ? hti : tvi.hItem)) {
tvi.hItem = hti;
@@ -251,7 +252,6 @@ void SaveMenuTree()
db_set_ws(NULL, PLGNAME, szMEntry, ld->ptszQValue);
}
-
if (((ld->dwOPFlags & QMF_NEW) || (ld->dwOPFlags & QMF_RENAMED) || bDeleted)) {
BBButton bb = { 0 };
bb.pszModuleName = PLGNAME;
@@ -260,7 +260,6 @@ void SaveMenuTree()
Srmm_ModifyButton(&bb);
}
-
mir_snprintf(szMEntry, "ButtonName_%u", iBl);
db_set_ws(NULL, PLGNAME, szMEntry, ld->ptszButtonName);
@@ -346,9 +345,9 @@ void RestoreModuleData()
qsort(sl->items, sl->realCount, sizeof(ButtonData *), sstSortButtons);
for (i = 0; i < sl->realCount; i++) {
- ButtonData * bd = (ButtonData *)sl->items[i];
+ ButtonData *bd = (ButtonData *)sl->items[i];
- if (bd->dwOPFlags&QMF_NEW) {
+ if (bd->dwOPFlags & QMF_NEW) {
RemoveMenuEntryNode(sl, i--);
continue;
}
@@ -391,7 +390,7 @@ static int BuildMenuTree(HWND hToolBarTree, SortedList * sl)
for (i = 0; i < sl->realCount; i++) {
ButtonData * bd = (ButtonData *)sl->items[i];
- if (bd->dwOPFlags&QMF_DELETNEEDED)
+ if (bd->dwOPFlags & QMF_DELETNEEDED)
continue;
tvis.item.lParam = (LPARAM)bd;
@@ -402,11 +401,8 @@ static int BuildMenuTree(HWND hToolBarTree, SortedList * sl)
hParent = TreeView_InsertItem(hToolBarTree, &tvis);
if (tvis.hParent) TreeView_Expand(hMenuTree, tvis.hParent, TVE_EXPAND);
- if (!bd->pszOpValue&&bd->fEntryOpType == 0) {
+ if (!bd->pszOpValue&&bd->fEntryOpType == 0)
tvis.hParent = hParent;
- }
- // else if (!(bd->fEntryOpType&QMF_EX_CHILD))
- // tvis.hParent = NULL;
}
return 1;
@@ -503,7 +499,7 @@ void MoveItem(HTREEITEM hItem, HTREEITEM hInsertAfter, BOOLEAN bAsChild)
INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg) {
- case WM_INITDIALOG:{
+ case WM_INITDIALOG: {
DWORD style;
g_opHdlg = hdlg;
bOptionsInit = TRUE;
@@ -647,50 +643,43 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
}
break;
- ///////////////////////////////////
- //From UserInfoEx by DeathAxe
- //
case WM_MOUSEMOVE:
+ if (!drag) break;
{
- if (!drag) break;
- {
- TVHITTESTINFO hti;
-
- hti.pt.x = (short)LOWORD(lparam);
- hti.pt.y = (short)HIWORD(lparam);
- ClientToScreen(hdlg, &hti.pt);
- ScreenToClient(hMenuTree, &hti.pt);
- TreeView_HitTest(hMenuTree, &hti);
- if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) {
- RECT rc;
- BYTE height;
-
- if (TreeView_GetItemRect(hMenuTree, hti.hItem, &rc, FALSE)) {
- height = (BYTE)(rc.bottom - rc.top);
-
- if (hti.pt.y - (height / 3) < rc.top) {
+ TVHITTESTINFO hti;
+ hti.pt.x = (short)LOWORD(lparam);
+ hti.pt.y = (short)HIWORD(lparam);
+ ClientToScreen(hdlg, &hti.pt);
+ ScreenToClient(hMenuTree, &hti.pt);
+ TreeView_HitTest(hMenuTree, &hti);
+ if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) {
+ RECT rc;
+ if (TreeView_GetItemRect(hMenuTree, hti.hItem, &rc, FALSE)) {
+ BYTE height = (BYTE)(rc.bottom - rc.top);
+
+ if (hti.pt.y - (height / 3) < rc.top) {
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+ TreeView_SetInsertMark(hMenuTree, hti.hItem, 0);
+ }
+ else
+ if (hti.pt.y + (height / 3) > rc.bottom) {
SetCursor(LoadCursor(NULL, IDC_ARROW));
- TreeView_SetInsertMark(hMenuTree, hti.hItem, 0);
+ TreeView_SetInsertMark(hMenuTree, hti.hItem, 1);
+ }
+ else {
+ TreeView_SetInsertMark(hMenuTree, NULL, 0);
+ SetCursor(LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(183)));
}
- else
- if (hti.pt.y + (height / 3) > rc.bottom) {
- SetCursor(LoadCursor(NULL, IDC_ARROW));
- TreeView_SetInsertMark(hMenuTree, hti.hItem, 1);
- }
- else {
- TreeView_SetInsertMark(hMenuTree, NULL, 0);
- SetCursor(LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(183)));
- }
- }
- }
- else {
- if (hti.flags & TVHT_ABOVE) SendMessage(hMenuTree, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
- if (hti.flags & TVHT_BELOW) SendMessage(hMenuTree, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
- TreeView_SetInsertMark(hMenuTree, NULL, 0);
}
}
- }break;
- /////////////
+ else {
+ if (hti.flags & TVHT_ABOVE) SendMessage(hMenuTree, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
+ if (hti.flags & TVHT_BELOW) SendMessage(hMenuTree, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
+ TreeView_SetInsertMark(hMenuTree, NULL, 0);
+ }
+ }
+ break;
+
case WM_DESTROY:
if (g_varhelpDlg)
DestroyWindow(g_varhelpDlg);
@@ -719,7 +708,7 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
case IDC_MENUTREE:
switch (((LPNMHDR)lparam)->code) {
- case TVN_KEYDOWN:{
+ case TVN_KEYDOWN: {
TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)((LPNMHDR)lparam);
if (pTVKeyDown->wVKey == VK_F2)
TreeView_EditLabel(hMenuTree, TreeView_GetSelection(hMenuTree));
@@ -849,7 +838,7 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
case IDC_BUTTONSLIST:
switch (((LPNMHDR)lparam)->code) {
- case TVN_KEYDOWN:{
+ case TVN_KEYDOWN: {
TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)((LPNMHDR)lparam);
if (pTVKeyDown->wVKey == VK_F2)
TreeView_EditLabel(hButtonsList, TreeView_GetSelection(hButtonsList));
diff --git a/plugins/QuickMessages/src/stdafx.h b/plugins/QuickMessages/src/stdafx.h
index 940b38838f..63209952aa 100644
--- a/plugins/QuickMessages/src/stdafx.h
+++ b/plugins/QuickMessages/src/stdafx.h
@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <m_options.h>
#include <m_utils.h>
#include <m_protosvc.h>
+#include <m_chat_int.h>
#include <m_langpack.h>
#include <m_icolib.h>
#include <m_message.h>
@@ -42,14 +43,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern HINSTANCE hinstance;
extern HANDLE hIcolib;
-extern ListData* ButtonsList[100];
-extern SortedList* QuickList;
+extern ListData *ButtonsList[100];
+extern SortedList *QuickList;
extern BOOL g_bRClickAuto;
extern BOOL g_bLClickAuto;
extern BOOL g_bQuickMenu;
extern int g_iButtonsCount;
int OptionsInit(WPARAM,LPARAM);
-
-#define IDC_MESSAGE 1002
-#define IDC_CHATMESSAGE 1009