From d22dcaba4b0b34637f7430c2fe000b0483aacb23 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 29 Jun 2025 18:47:33 +0300 Subject: fixes #5048 (fileasmessage.dll: add button to chat toolbar) --- plugins/FileAsMessage/src/main.cpp | 90 ++++++++++++++------------------------ 1 file changed, 34 insertions(+), 56 deletions(-) (limited to 'plugins/FileAsMessage/src/main.cpp') diff --git a/plugins/FileAsMessage/src/main.cpp b/plugins/FileAsMessage/src/main.cpp index d19e7c2b37..88557eb18f 100644 --- a/plugins/FileAsMessage/src/main.cpp +++ b/plugins/FileAsMessage/src/main.cpp @@ -8,19 +8,6 @@ char *szServiceTitle = SERVICE_TITLE; char *szServicePrefix = SERVICE_PREFIX; HANDLE hHookDbSettingChange, hHookContactAdded, hHookSkinIconsChanged; -HICON hIcons[5]; - -IconItem iconList[] = -{ - { LPGEN("Play"), "FePlay", IDI_PLAY }, - { LPGEN("Pause"), "FePause", IDI_PAUSE }, - { LPGEN("Revive"), "FeRefresh", IDI_REFRESH }, - { LPGEN("Stop"), "FeStop", IDI_STOP }, - { LPGEN("Main"), "FeMain", IDI_SMALLICON }, -}; - -int iIconId[5] = { 3, 2, 4, 1, 0 }; - ///////////////////////////////////////////////////////////////////////////////////////// PLUGININFOEX pluginInfoEx = @@ -47,9 +34,6 @@ CMPlugin::CMPlugin() : int OnSkinIconsChanged(WPARAM, LPARAM) { - for (int indx = 0; indx < _countof(hIcons); indx++) - hIcons[indx] = IcoLib_GetIconByHandle(iconList[indx].hIcolib); - WindowList_Broadcast(hFileList, WM_FE_SKINCHANGE, 0, 0); return 0; } @@ -58,8 +42,7 @@ int OnSettingChanged(WPARAM hContact, LPARAM lParam) { DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam; - if (hContact && !strcmp(cws->szSetting, "Status")) - { + if (hContact && !strcmp(cws->szSetting, "Status")) { HWND hwnd = WindowList_Find(hFileList, hContact); PostMessage(hwnd, WM_FE_STATUSCHANGE, 0, 0); } @@ -68,54 +51,35 @@ int OnSettingChanged(WPARAM hContact, LPARAM lParam) INT_PTR OnRecvFile(WPARAM, LPARAM lParam) { - CLISTEVENT *clev = (CLISTEVENT*)lParam; + auto *clev = (CLISTEVENT *)lParam; HWND hwnd = WindowList_Find(hFileList, clev->hContact); - if (IsWindow(hwnd)) - { + if (IsWindow(hwnd)) { ShowWindow(hwnd, SW_SHOWNORMAL); SetForegroundWindow(hwnd); SetFocus(hwnd); } - /* - else - { - if(hwnd != 0) WindowList_Remove(hFileList, hwnd); - FILEECHO *fe = new FILEECHO((HANDLE)clev->hContact); - fe->inSend = FALSE; - hwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DialogProc, (LPARAM)fe); - if(hwnd == NULL) - { - delete fe; - return 0; - } - //SendMessage(hwnd, WM_FE_SERVICE, 0, TRUE); - ShowWindow(hwnd, SW_SHOWNORMAL); - } - */ + return 1; } INT_PTR OnSendFile(WPARAM wParam, LPARAM) { HWND hwnd = WindowList_Find(hFileList, wParam); - if (IsWindow(hwnd)) - { + if (IsWindow(hwnd)) { SetForegroundWindow(hwnd); SetFocus(hwnd); } - else - { + else { if (hwnd != nullptr) WindowList_Remove(hFileList, hwnd); FILEECHO *fe = new FILEECHO(wParam); fe->inSend = TRUE; hwnd = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_MAIN), nullptr, DialogProc, (LPARAM)fe); - if (hwnd == nullptr) - { + if (hwnd == nullptr) { delete fe; return 0; } - //SendMessage(hwnd, WM_FE_SERVICE, 0, TRUE); + ShowWindow(hwnd, SW_SHOWNORMAL); } return 1; @@ -124,48 +88,62 @@ INT_PTR OnSendFile(WPARAM wParam, LPARAM) INT_PTR OnRecvMessage(WPARAM wParam, LPARAM lParam) { CCSDATA *ccs = (CCSDATA *)lParam; - auto *dbei = (DB::EventInfo*)ccs->lParam; + auto *dbei = (DB::EventInfo *)ccs->lParam; if (strncmp(dbei->pBlob, szServicePrefix, mir_strlen(szServicePrefix))) return Proto_ChainRecv(wParam, ccs); HWND hwnd = WindowList_Find(hFileList, ccs->hContact); - if (!IsWindow(hwnd)) - { + if (!IsWindow(hwnd)) { if (hwnd != nullptr) WindowList_Remove(hFileList, hwnd); - FILEECHO *fe = new FILEECHO(ccs->hContact); + auto *fe = new FILEECHO(ccs->hContact); fe->inSend = FALSE; hwnd = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_MAIN), nullptr, DialogProc, (LPARAM)fe); - if (hwnd == nullptr) - { + if (hwnd == nullptr) { delete fe; return 0; } } + char *msg = mir_strdup(dbei->pBlob + mir_strlen(szServicePrefix)); PostMessage(hwnd, WM_FE_MESSAGE, (WPARAM)ccs->hContact, (LPARAM)msg); - return 0; } ///////////////////////////////////////////////////////////////////////////////////////// // Startup initializing -static int OnModulesLoaded(WPARAM, LPARAM) +static IconItem iconList[] = { - for (int indx = 0; indx < _countof(hIcons); indx++) - hIcons[indx] = IcoLib_GetIconByHandle(iconList[indx].hIcolib); + { LPGEN("Play"), "FePlay", IDI_PLAY }, + { LPGEN("Pause"), "FePause", IDI_PAUSE }, + { LPGEN("Revive"), "FeRefresh", IDI_REFRESH }, + { LPGEN("Stop"), "FeStop", IDI_STOP }, + { LPGEN("Main"), "FeMain", IDI_MAIN }, +}; +static int OnModulesLoaded(WPARAM, LPARAM) +{ hHookSkinIconsChanged = HookEvent(ME_SKIN_ICONSCHANGED, OnSkinIconsChanged); + // main menu item CMenuItem mi(&g_plugin); SET_UID(mi, 0xe4a98d2a, 0xa54a, 0x4db1, 0x8d, 0x29, 0xd, 0x5c, 0xf1, 0x10, 0x69, 0x35); mi.position = 200011; - mi.hIcolibItem = iconList[ICON_MAIN].hIcolib; + mi.hIcolibItem = g_plugin.getIconHandle(IDI_MAIN); mi.name.a = LPGEN("File As Message..."); mi.pszService = MODULENAME "/FESendFile"; mi.flags = CMIF_NOTOFFLINE; Menu_AddContactMenuItem(&mi); + + // toolbar button + BBButton bbd = {}; + bbd.pszModuleName = MODULENAME; + bbd.dwDefPos = 1500; + bbd.pwszTooltip = LPGENW("File As Message..."); + bbd.bbbFlags = BBBF_ISRSIDEBUTTON | BBBF_CANBEHIDDEN | BBBF_HIDDEN; + bbd.hIcon = mi.hIcolibItem; + g_plugin.addButton(&bbd); return 0; } @@ -173,7 +151,7 @@ int CMPlugin::Load() { InitCRC32(); - g_plugin.registerIcon("fileAsMessage", iconList); + g_plugin.registerIcon(MODULENAME, iconList); hFileList = WindowList_Create(); -- cgit v1.2.3