From e94651e159fc0cea45d8d925603bb8884f634527 Mon Sep 17 00:00:00 2001 From: Date: Thu, 1 May 2014 04:34:00 +0200 Subject: [PATCH] A little memory leak fixed. Incorrect account menu in the status bar in case of hidden accounts fixed. --- plugins/Clist_modern/src/modern_statusbar.cpp | 49 ++++++++++++--------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/plugins/Clist_modern/src/modern_statusbar.cpp b/plugins/Clist_modern/src/modern_statusbar.cpp index 1f83fca..41b5ba0 100644 --- a/plugins/Clist_modern/src/modern_statusbar.cpp +++ b/plugins/Clist_modern/src/modern_statusbar.cpp @@ -185,6 +185,7 @@ int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC) if (protoCount == 0) return 0; + int iProtoInStatusMenu = 0; for (int j = 0; j < protoCount; j++) { int i = pcli->pfnGetAccountIndexByPos(j); if (i == -1) @@ -194,18 +195,19 @@ int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC) if (!pcli->pfnGetProtocolVisibility(szProto)) continue; + iProtoInStatusMenu++; + char buf[256]; mir_snprintf(buf, SIZEOF(buf), "SBarAccountIsCustom_%s", szProto); + BOOL bCustomSettings = g_StatusBarData.perProtoConfig && db_get_b(NULL, "CLUI", buf, SETTING_SBARACCOUNTISCUSTOM_DEFAULT); - ProtoItemData *p = new ProtoItemData; - - if (g_StatusBarData.perProtoConfig && db_get_b(NULL, "CLUI", buf, SETTING_SBARACCOUNTISCUSTOM_DEFAULT)) { - mir_snprintf(buf, SIZEOF(buf), "HideAccount_%s", szProto); - if (db_get_b(NULL, "CLUI", buf, SETTING_SBARHIDEACCOUNT_DEFAULT)) - continue; + mir_snprintf(buf, SIZEOF(buf), "HideAccount_%s", accs[i]->szModuleName); + if (bCustomSettings && db_get_b(NULL, "CLUI", buf, SETTING_SBARHIDEACCOUNT_DEFAULT)) + continue; + ProtoItemData *p = new ProtoItemData; + if (bCustomSettings) { mir_snprintf(buf, SIZEOF(buf), "SBarShow_%s", szProto); - BYTE showOps = db_get_b(NULL, "CLUI", buf, SETTING_SBARSHOW_DEFAULT); p->bShowProtoIcon = (showOps & 1) != 0; p->bShowProtoName = (showOps & 2) != 0; @@ -257,7 +259,7 @@ int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC) p->szAccountName = mir_strdup(szProto); p->szProtoName = mir_strdup(accs[i]->szProtoName); p->tszProtoStatusText = mir_tstrdup(pcli->pfnGetStatusModeDescription(p->iProtoStatus, 0)); - p->iProtoPos = ProtosData.getCount(); + p->iProtoPos = iProtoInStatusMenu-1; p->bIsDimmed = 0; if (g_CluiData.bFilterEffective & CLVM_FILTER_PROTOS) { @@ -578,18 +580,17 @@ int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC) return 0; } -static BOOL _ModernStatus_OnExtraIconClick(int protoIndex) +static BOOL _ModernStatus_OnExtraIconClick(ProtoItemData *p) { - ProtoItemData &p = ProtosData[protoIndex]; - if (!mir_strcmpi(p.szProtoName, "ICQ")) { - if (p.iProtoStatus < ID_STATUS_ONLINE) + if (!mir_strcmpi(p->szProtoName, "ICQ")) { + if (p->iProtoStatus < ID_STATUS_ONLINE) return FALSE; HMENU hMainStatusMenu = (HMENU)CallService(MS_CLIST_MENUGETSTATUS, 0, 0); if (!hMainStatusMenu) return FALSE; - HMENU hProtoStatusMenu = GetSubMenu(hMainStatusMenu, protoIndex); + HMENU hProtoStatusMenu = GetSubMenu(hMainStatusMenu, p->iProtoPos); if (!hProtoStatusMenu) return FALSE; @@ -604,14 +605,14 @@ static BOOL _ModernStatus_OnExtraIconClick(int protoIndex) return TRUE; } - if (!mir_strcmpi(p.szProtoName, "JABBER")) { - if (p.iProtoStatus < ID_STATUS_ONLINE) + if (!mir_strcmpi(p->szProtoName, "JABBER")) { + if (p->iProtoStatus < ID_STATUS_ONLINE) return FALSE; // Show Moods #define PS_JABBER_MOOD "/AdvStatusSet/Mood" - if (ProtoServiceExists(p.szAccountName, PS_JABBER_MOOD)) { - ProtoCallService(p.szAccountName, PS_JABBER_MOOD, 0, 0); + if (ProtoServiceExists(p->szAccountName, PS_JABBER_MOOD)) { + ProtoCallService(p->szAccountName, PS_JABBER_MOOD, 0, 0); return TRUE; } } @@ -812,7 +813,7 @@ LRESULT CALLBACK ModernStatusProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa BOOL bShift = (GetKeyState(VK_SHIFT) & 0x8000); BOOL bCtrl = (GetKeyState(VK_CONTROL) & 0x8000); - if ((msg == WM_MBUTTONDOWN || (msg == WM_RBUTTONDOWN && bCtrl) || isOnExtra) && _ModernStatus_OnExtraIconClick(i)) + if ((msg == WM_MBUTTONDOWN || (msg == WM_RBUTTONDOWN && bCtrl) || isOnExtra) && _ModernStatus_OnExtraIconClick(&p)) return TRUE; if (msg == WM_LBUTTONDOWN && bCtrl) { @@ -888,15 +889,9 @@ LRESULT CALLBACK ModernStatusProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa } else { hMenu = (HMENU)CallService(MS_CLIST_MENUGETSTATUS, 0, 0); - unsigned int cpnl = 0; - int mcnt = GetMenuItemCount(hMenu); - for (int j = 0; j < mcnt; ++j) { - HMENU hMenus = GetSubMenu(hMenu, j); - if (hMenus && cpnl++ == i) { - hMenu = hMenus; - break; - } - } + HMENU hSubMenu = GetSubMenu(hMenu, p.iProtoPos); + if (hSubMenu) + hMenu = hSubMenu; } } -- 1.8.3.msysgit.0