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/dialog.cpp | 31 ++++++------- plugins/FileAsMessage/src/dialog.h | 28 +++++------ plugins/FileAsMessage/src/main.cpp | 90 ++++++++++++++---------------------- plugins/FileAsMessage/src/resource.h | 2 +- plugins/FileAsMessage/src/stdafx.h | 18 ++++---- plugins/FileAsMessage/src/version.h | 2 +- 6 files changed, 70 insertions(+), 101 deletions(-) (limited to 'plugins/FileAsMessage/src') diff --git a/plugins/FileAsMessage/src/dialog.cpp b/plugins/FileAsMessage/src/dialog.cpp index 60670e4e8c..6c0873a29f 100644 --- a/plugins/FileAsMessage/src/dialog.cpp +++ b/plugins/FileAsMessage/src/dialog.cpp @@ -98,7 +98,7 @@ void MakePopupMsg(HWND hDlg, MCONTACT hContact, wchar_t *msg) POPUPDATAW ppd; ppd.lchContact = hContact; - ppd.lchIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SMALLICON)); + ppd.lchIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_MAIN)); mir_wstrcpy(ppd.lpwzContactName, Clist_GetContactDisplayName(hContact)); mir_wstrcpy(ppd.lpwzText, msg); ppd.colorBack = GetSysColor(COLOR_INFOBK); @@ -165,10 +165,10 @@ void FILEECHO::setState(uint32_t state) EnableWindow(GetDlgItem(hDlg, IDC_BROWSE), (iState & (STATE_PRERECV | STATE_FINISHED))); if (state & (STATE_IDLE | STATE_FINISHED | STATE_CANCELLED | STATE_PRERECV)) - kind = ICON_PLAY; + kind = IDI_PLAY; else - kind = ICON_REFRESH; - SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[kind]); + kind = IDI_REFRESH; + SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(kind)); SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[kind]), 0); } else { @@ -181,12 +181,12 @@ void FILEECHO::setState(uint32_t state) case STATE_IDLE: case STATE_PAUSED: EnableWindow(GetDlgItem(hDlg, IDC_PLAY), TRUE); - SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_PLAY]); - SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[ICON_PLAY]), 0); + SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_PLAY)); + SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[IDI_PLAY]), 0); break; case STATE_OPERATE: - SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_PAUSE]); - SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[ICON_PAUSE]), 0); + SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_PAUSE)); + SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[IDI_PAUSE]), 0); break; } } @@ -404,7 +404,7 @@ void FILEECHO::incomeRequest(char *param) if (!IsWindowVisible(hDlg) && !AutoMin) { CLISTEVENT cle = {}; cle.hContact = hContact; - cle.hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SMALLICON)); + cle.hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_MAIN)); cle.flags = CLEF_URGENT; cle.hDbEvent = 0; cle.pszService = MODULENAME "/FERecvFile"; @@ -851,15 +851,15 @@ INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE, L"", hDlg, IDC_STATUS); SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)dat); WindowList_Add(hFileList, hDlg, dat->hContact); - Window_SetIcon_IcoLib(hDlg, iconList[ICON_MAIN].hIcolib); - SendDlgItemMessage(hDlg, IDC_STOP, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[ICON_STOP]), 0); + Window_SetIcon_IcoLib(hDlg, g_plugin.getIconHandle(IDI_MAIN)); + SendDlgItemMessage(hDlg, IDC_STOP, BUTTONADDTOOLTIP, (WPARAM)Translate(hint_controls[IDI_STOP]), 0); mir_subclassWindow(GetDlgItem(hDlg, IDC_PROGRESS), ProgressWndProc); SendDlgItemMessage(hDlg, IDC_PLAY, BUTTONSETASFLATBTN, 0, 0); - SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_PLAY]); + SendDlgItemMessage(hDlg, IDC_PLAY, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_PLAY)); SendDlgItemMessage(hDlg, IDC_STOP, BUTTONSETASFLATBTN, 0, 0); - SendDlgItemMessage(hDlg, IDC_STOP, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_STOP]); + SendDlgItemMessage(hDlg, IDC_STOP, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_STOP)); dat->setState(STATE_IDLE); if (dat->inSend) @@ -872,10 +872,9 @@ INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) return TRUE; case WM_FE_SKINCHANGE: - Window_SetIcon_IcoLib(hDlg, iconList[ICON_MAIN].hIcolib); + Window_SetIcon_IcoLib(hDlg, g_plugin.getIconHandle(IDI_MAIN)); dat->setState(dat->iState); - SendDlgItemMessage(hDlg, IDC_STOP, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcons[ICON_STOP]); - + SendDlgItemMessage(hDlg, IDC_STOP, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_STOP)); break; case WM_FE_STATUSCHANGE: diff --git a/plugins/FileAsMessage/src/dialog.h b/plugins/FileAsMessage/src/dialog.h index 1fffdf96d8..e7e2ce5877 100644 --- a/plugins/FileAsMessage/src/dialog.h +++ b/plugins/FileAsMessage/src/dialog.h @@ -32,24 +32,18 @@ enum extern char cFECmd[CMD_COUNT]; -#define STATE_IDLE 0x100 // idle, no operation -#define STATE_REQSENT 0x02 // request sent, awaiting of response -#define STATE_PRERECV 0x04 // incoming request, awaiting of user -#define STATE_OPERATE 0x08 // operating mode -#define STATE_ACKREQ 0x10 // ACK-request scheduled +#define STATE_IDLE 0x100 // idle, no operation +#define STATE_REQSENT 0x02 // request sent, awaiting of response +#define STATE_PRERECV 0x04 // incoming request, awaiting of user +#define STATE_OPERATE 0x08 // operating mode +#define STATE_ACKREQ 0x10 // ACK-request scheduled #define STATE_CANCELLED 0x20 // operation aborted -#define STATE_FINISHED 0x40 // ... finished successfully -#define STATE_PAUSED 0x80 // ... paused - -#define CHUNK_UNSENT 0x00 -#define CHUNK_SENT 0x01 -#define CHUNK_ACK 0x02 - -#define ICON_PLAY 0 -#define ICON_PAUSE 1 -#define ICON_REFRESH 2 -#define ICON_STOP 3 -#define ICON_MAIN 4 +#define STATE_FINISHED 0x40 // ... finished successfully +#define STATE_PAUSED 0x80 // ... paused + +#define CHUNK_UNSENT 0x00 +#define CHUNK_SENT 0x01 +#define CHUNK_ACK 0x02 struct FILEECHO : public MZeroedObject { 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(); diff --git a/plugins/FileAsMessage/src/resource.h b/plugins/FileAsMessage/src/resource.h index 952fba4a65..26a4f2ecc1 100644 --- a/plugins/FileAsMessage/src/resource.h +++ b/plugins/FileAsMessage/src/resource.h @@ -4,7 +4,7 @@ // #define IDC_PLAY 1 #define IDD_MAIN 101 -#define IDI_SMALLICON 102 +#define IDI_MAIN 102 #define IDD_OPTIONS 103 #define IDI_STOP 104 #define IDI_PAUSE 105 diff --git a/plugins/FileAsMessage/src/stdafx.h b/plugins/FileAsMessage/src/stdafx.h index 85e2ddf980..99a4703f55 100644 --- a/plugins/FileAsMessage/src/stdafx.h +++ b/plugins/FileAsMessage/src/stdafx.h @@ -8,18 +8,19 @@ #include #include +#include +#include #include #include -#include +#include +#include #include -#include +#include +#include #include -#include #include -#include -#include -#include -#include +#include +#include #include "dialog.h" #include "resource.h" @@ -52,8 +53,5 @@ extern const ulong INITCRC; extern MWindowList hFileList; extern HANDLE hEventNewFile; -extern HICON hIcons[5]; -extern IconItem iconList[]; - ulong memcrc32(uchar *ptr, int size, ulong crc); int OnOptInitialise(WPARAM wParam, LPARAM); diff --git a/plugins/FileAsMessage/src/version.h b/plugins/FileAsMessage/src/version.h index 6983f2321e..ac9ee338fe 100644 --- a/plugins/FileAsMessage/src/version.h +++ b/plugins/FileAsMessage/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3