From fab3905d91890102046dcc4554721991ae8ff413 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 7 Mar 2019 18:48:03 +0300 Subject: Skin_GetProtoIcon - new function to retrieve status icon's handle --- src/mir_app/src/meta_services.cpp | 2 +- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/skinicons.cpp | 39 +++++++++++++++++++------------- src/mir_app/src/srmm_statusicon.cpp | 45 +++++++++++++++++++++---------------- 5 files changed, 52 insertions(+), 36 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/meta_services.cpp b/src/mir_app/src/meta_services.cpp index 39874a71c9..b54e652c56 100644 --- a/src/mir_app/src/meta_services.cpp +++ b/src/mir_app/src/meta_services.cpp @@ -631,7 +631,7 @@ int Meta_ModulesLoaded(WPARAM, LPARAM) StatusIconData sid = {}; sid.szModule = META_PROTO; sid.flags = MBF_UNICODE; - sid.tszTooltip = LPGENW("Select metacontact"); + sid.szTooltip.w = LPGENW("Select metacontact"); sid.hIcon = Skin_LoadProtoIcon(META_PROTO, ID_STATUS_ONLINE); Srmm_AddIcon(&sid, &g_plugin); return 0; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 26df34bbb4..a1730123f0 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -673,3 +673,4 @@ Popup_Enabled @762 Popup_AddClass @763 Popup_Add @764 Popup_Change @765 +Skin_GetProtoIcon @766 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 44315b8df0..1cda05d3e1 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -673,3 +673,4 @@ Popup_Enabled @762 Popup_AddClass @763 Popup_Add @764 Popup_Change @765 +Skin_GetProtoIcon @766 diff --git a/src/mir_app/src/skinicons.cpp b/src/mir_app/src/skinicons.cpp index 7ed66af300..8daff88fa2 100644 --- a/src/mir_app/src/skinicons.cpp +++ b/src/mir_app/src/skinicons.cpp @@ -229,6 +229,11 @@ MIR_APP_DLL(void) Button_FreeIcon_IcoLib(HWND hwndDlg, int itemId) } MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big) +{ + return IcoLib_GetIconByHandle(Skin_GetProtoIcon(szProto, status), big); +} + +MIR_APP_DLL(HANDLE) Skin_GetProtoIcon(const char *szProto, int status) { char iconName[MAX_PATH]; INT_PTR caps2; @@ -239,7 +244,7 @@ MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big) if (IsStatusConnecting(status)) { mir_snprintf(iconName, "%s%d", mainIconsFmt, 7); - return IcoLib_GetIcon(iconName, big); + return IcoLib_GetIconHandle(iconName); } int statusIndx = -1; @@ -259,26 +264,28 @@ MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big) // format: core_status_%proto%statusindex mir_snprintf(iconName, "%s%s%d", statusIconsFmt, szProto, statusIndx); - HICON hIcon = IcoLib_GetIcon(iconName, big); - if (hIcon) - return hIcon; + HANDLE hIcolib = IcoLib_GetIconHandle(iconName); + if (hIcolib) + return hIcolib; } // format: core_status_%s%d mir_snprintf(iconName, "%s%s%d", statusIconsFmt, GLOBAL_PROTO_NAME, statusIndx); - return IcoLib_GetIcon(iconName, big); + return IcoLib_GetIconHandle(iconName); } // format: core_status_%s%d mir_snprintf(iconName, "%s%s%d", statusIconsFmt, szProto, statusIndx); - HICON hIcon = IcoLib_GetIcon(iconName, big); - if (hIcon == nullptr && (caps2 == 0 || (caps2 & statusIcons[statusIndx].pf2))) { + if (HANDLE hIcolib = IcoLib_GetIconHandle(iconName)) + return hIcolib; + + // Queried protocol isn't in list, adding them + if (caps2 == 0 || (caps2 & statusIcons[statusIndx].pf2)) { PROTOACCOUNT *pa = Proto_GetAccount(szProto); if (pa) { wchar_t szPath[MAX_PATH], szFullPath[MAX_PATH], *str; GetModuleFileName(nullptr, szPath, _countof(szPath)); - // Queried protocol isn't in list, adding wchar_t tszSection[MAX_PATH]; mir_snwprintf(tszSection, _A2W(PROTOCOLS_PREFIX)L"/%s", pa->tszAccountName); @@ -289,11 +296,13 @@ MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big) str = wcsrchr(szPath, '\\'); if (str != nullptr) *str = 0; + mir_snwprintf(szFullPath, L"%s\\Icons\\proto_%S.dll", szPath, pa->szProtoName); if (GetFileAttributes(szFullPath) != INVALID_FILE_ATTRIBUTES) sid.defaultFile.w = szFullPath; else { mir_snwprintf(szFullPath, L"%s\\Plugins\\%S.dll", szPath, szProto); + HICON hIcon = nullptr; if (int(ExtractIconEx(szFullPath, statusIcons[statusIndx].resource_id, nullptr, &hIcon, 1)) > 0) { DestroyIcon(hIcon); sid.defaultFile.w = szFullPath; @@ -328,17 +337,15 @@ MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big) // format: core_status_%s%d mir_snprintf(iconName, "%s%s%d", statusIconsFmt, szProto, statusIndx); - hIcon = IcoLib_GetIcon(iconName, big); - if (hIcon) - return hIcon; + if (HANDLE hIcolib = IcoLib_GetIconHandle(iconName)) + return hIcolib; } - if (hIcon == nullptr) { - mir_snprintf(iconName, "%s%s%d", statusIconsFmt, GLOBAL_PROTO_NAME, statusIndx); - hIcon = IcoLib_GetIcon(iconName, big); - } + mir_snprintf(iconName, "%s%s%d", statusIconsFmt, GLOBAL_PROTO_NAME, statusIndx); + if (HANDLE hIcolib = IcoLib_GetIconHandle(iconName)) + return hIcolib; - return hIcon; + return nullptr; } MIR_APP_DLL(HANDLE) Skin_GetIconHandle(int idx) diff --git a/src/mir_app/src/srmm_statusicon.cpp b/src/mir_app/src/srmm_statusicon.cpp index 27c5f48def..2b737edb19 100644 --- a/src/mir_app/src/srmm_statusicon.cpp +++ b/src/mir_app/src/srmm_statusicon.cpp @@ -44,13 +44,14 @@ struct StatusIconChild : public MZeroedObject { SafeDestroyIcon(hIcon); SafeDestroyIcon(hIconDisabled); - mir_free(tszTooltip); + mir_free(pwszTooltip); } MCONTACT hContact; - HICON hIcon, hIconDisabled; + HICON hIcon, hIconDisabled; + HANDLE hIcolibOn, hIcolibOff; int flags; - wchar_t *tszTooltip; + wchar_t *pwszTooltip; }; struct StatusIconMain : public MZeroedObject @@ -61,12 +62,13 @@ struct StatusIconMain : public MZeroedObject ~StatusIconMain() { - mir_free(sid.szModule); - mir_free(sid.szTooltip); + mir_free((void*)sid.szModule); + mir_free((void*)sid.szTooltip.w); } StatusIconData sid; + HANDLE hIcolibOn, hIcolibOff; HPLUGIN pPlugin; OBJLIST arChildren; }; @@ -80,7 +82,7 @@ static int CompareIcons(const StatusIconMain *p1, const StatusIconMain *p2) return p1->sid.dwId - p2->sid.dwId; } -static OBJLIST arIcons(3, CompareIcons); +static OBJLIST arIcons(10, CompareIcons); ///////////////////////////////////////////////////////////////////////////////////////// @@ -97,10 +99,12 @@ MIR_APP_DLL(int) Srmm_AddIcon(StatusIconData *sid, HPLUGIN pPlugin) memcpy(&p->sid, sid, sizeof(p->sid)); p->pPlugin = pPlugin; p->sid.szModule = mir_strdup(sid->szModule); + p->hIcolibOn = IcoLib_IsManaged(sid->hIcon); + p->hIcolibOff = IcoLib_IsManaged(sid->hIconDisabled); if (sid->flags & MBF_UNICODE) - p->sid.tszTooltip = mir_wstrdup(sid->wszTooltip); + p->sid.szTooltip.w = mir_wstrdup(sid->szTooltip.w); else - p->sid.tszTooltip = mir_a2u(sid->szTooltip); + p->sid.szTooltip.w = mir_a2u(sid->szTooltip.a); arIcons.insert(p); NotifyEventHooks(hHookIconsChanged, 0, (LPARAM)p); @@ -119,11 +123,13 @@ MIR_APP_DLL(int) Srmm_ModifyIcon(MCONTACT hContact, StatusIconData *sid) return 1; if (hContact == 0) { - mir_free(p->sid.szModule); - mir_free(p->sid.szTooltip); + mir_free((void*)p->sid.szModule); + mir_free((void*)p->sid.szTooltip.w); memcpy(&p->sid, sid, sizeof(p->sid)); + p->hIcolibOn = IcoLib_IsManaged(sid->hIcon); + p->hIcolibOff = IcoLib_IsManaged(sid->hIconDisabled); p->sid.szModule = mir_strdup(sid->szModule); - p->sid.tszTooltip = (sid->flags & MBF_UNICODE) ? mir_wstrdup(sid->wszTooltip) : mir_a2u(sid->szTooltip); + p->sid.szTooltip.w = (sid->flags & MBF_UNICODE) ? mir_wstrdup(sid->szTooltip.w) : mir_a2u(sid->szTooltip.a); NotifyEventHooks(hHookIconsChanged, 0, (LPARAM)p); return 0; @@ -135,14 +141,13 @@ MIR_APP_DLL(int) Srmm_ModifyIcon(MCONTACT hContact, StatusIconData *sid) pc->hContact = hContact; p->arChildren.insert(pc); } - else SafeDestroyIcon(pc->hIcon); pc->flags = sid->flags; pc->hIcon = sid->hIcon; pc->hIconDisabled = sid->hIconDisabled; - - mir_free(pc->tszTooltip); - pc->tszTooltip = (sid->flags & MBF_UNICODE) ? mir_wstrdup(sid->wszTooltip) : mir_a2u(sid->szTooltip); + pc->hIcolibOn = IcoLib_IsManaged(sid->hIcon); + pc->hIcolibOff = IcoLib_IsManaged(sid->hIconDisabled); + replaceStrW(pc->pwszTooltip, (sid->flags & MBF_UNICODE) ? mir_wstrdup(sid->szTooltip.w) : mir_a2u(sid->szTooltip.a)); NotifyEventHooks(hHookIconsChanged, hContact, (LPARAM)p); return 0; @@ -177,15 +182,17 @@ MIR_APP_DLL(StatusIconData*) Srmm_GetNthIcon(MCONTACT hContact, int index) if (nVis == index) { memcpy(&res, it, sizeof(res)); if (pc) { - if (pc->hIcon) res.hIcon = pc->hIcon; + if (pc->hIcon) + res.hIcon = pc->hIcon; if (pc->hIconDisabled) res.hIconDisabled = pc->hIconDisabled; else if (pc->hIcon) res.hIconDisabled = pc->hIcon; - if (pc->tszTooltip) res.tszTooltip = pc->tszTooltip; + if (pc->pwszTooltip) + res.szTooltip.w = pc->pwszTooltip; res.flags = pc->flags; } - res.tszTooltip = TranslateW_LP(res.tszTooltip, it->pPlugin); + res.szTooltip.w = TranslateW_LP(res.szTooltip.w, it->pPlugin); return &res; } nVis++; @@ -216,7 +223,7 @@ int LoadSrmmModule() g_hCurHyperlinkHand = LoadCursor(nullptr, IDC_HAND); LoadSrmmToolbarModule(); - + hHookSrmmEvent = CreateHookableEvent(ME_MSG_WINDOWEVENT); hHookIconsChanged = CreateHookableEvent(ME_MSG_ICONSCHANGED); hHookIconPressedEvt = CreateHookableEvent(ME_MSG_ICONPRESSED); -- cgit v1.2.3