From 2bbcdb330bbf4d3bbd636f7014ee447c9be95495 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 11 Jul 2012 21:12:00 +0000 Subject: fix for a TTB to remove buttons of the dynamically unloaded plugins git-svn-id: http://svn.miranda-ng.org/main/trunk@911 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TopToolBar/main.rc | 2 +- plugins/TopToolBar/toolbar.cpp | 31 +++++++++++++++++++++++++++++-- plugins/TopToolBar/topbutton.cpp | 3 +++ src/modules/plugins/newplugins.cpp | 13 +++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/plugins/TopToolBar/main.rc b/plugins/TopToolBar/main.rc index 3f795295fa..f6efd9369b 100644 --- a/plugins/TopToolBar/main.rc +++ b/plugins/TopToolBar/main.rc @@ -36,7 +36,7 @@ BEGIN LTEXT "Button width",IDC_STATIC,169,150,100,8 EDITTEXT IDC_BUTTWIDTH,272,148,27,12,ES_NUMBER CONTROL "",IDC_SPIN_WIDTH,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS | UDS_HOTTRACK,289,148,8,12 - LTEXT "Inteval between buttons",IDC_STATIC,169,166,100,8 + LTEXT "Interval between buttons",IDC_STATIC,169,166,100,8 EDITTEXT IDC_BUTTGAP,272,164,27,12,ES_NUMBER CONTROL "",IDC_SPIN_GAP,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS | UDS_HOTTRACK,289,164,8,12 CONTROL "Use flat mode",IDC_USEFLAT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,167,185,130,10 diff --git a/plugins/TopToolBar/toolbar.cpp b/plugins/TopToolBar/toolbar.cpp index a41c43607f..ac81128d50 100644 --- a/plugins/TopToolBar/toolbar.cpp +++ b/plugins/TopToolBar/toolbar.cpp @@ -267,6 +267,7 @@ INT_PTR TTBAddButton(WPARAM wParam, LPARAM lParam) return -1; b = CreateButton(but); + b->hLangpack = (int)lParam; b->LoadSettings(); Buttons.insert(b); b->CreateWnd(); @@ -549,6 +550,31 @@ static INT_PTR TTBSetCustomProc(WPARAM wParam, LPARAM lParam) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// +// Removes buttons of plugins being unloads. lParam = HINSTANCE + +int OnPluginUnload(WPARAM wParam, LPARAM lParam) +{ + int hLangpack = CallService(MS_LANGPACK_LOOKUPHANDLE, 0, lParam); + if (hLangpack) { + bool bNeedUpdate = false; + mir_cslock lck(csButtonsHook); + + for (int i=Buttons.getCount()-1; i >= 0; i--) + if (Buttons[i]->hLangpack == hLangpack) { + TTBRemoveButton(Buttons[i]->id, 0); + bNeedUpdate = true; + } + + if (bNeedUpdate) { + ArrangeButtons(); + if (g_ctrl->hWnd) + PostMessage(g_ctrl->hWnd, TTB_UPDATEFRAMEVISIBILITY, TRUE, 0); + } + } + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// int OnModulesLoad(WPARAM wParam, LPARAM lParam) @@ -605,6 +631,7 @@ int LoadToolbarModule() InitializeCriticalSection(&csButtonsHook); hBmpSeparator = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SEP)); + HookEvent(ME_SYSTEM_MODULEUNLOAD, OnPluginUnload); HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoad); HookEvent(ME_SKIN2_ICONSCHANGED, OnIconChange); HookEvent(ME_OPT_INITIALISE, TTBOptInit); @@ -618,12 +645,12 @@ int LoadToolbarModule() CreateServiceFunction(MS_TTB_SETBUTTONSTATE, TTBSetState); CreateServiceFunction(MS_TTB_GETBUTTONSTATE, TTBGetState); - + CreateServiceFunction(MS_TTB_GETBUTTONOPTIONS, TTBGetOptions); CreateServiceFunction(MS_TTB_SETBUTTONOPTIONS, TTBSetOptions); CreateServiceFunction(TTB_LAUNCHSERVICE, LaunchService); - + CreateServiceFunction("TopToolBar/SetCustomProc", TTBSetCustomProc); CreateServiceFunction("TTB_ONSTARTUPFIRE", OnEventFire); diff --git a/plugins/TopToolBar/topbutton.cpp b/plugins/TopToolBar/topbutton.cpp index 762b784934..34a6c4d5df 100644 --- a/plugins/TopToolBar/topbutton.cpp +++ b/plugins/TopToolBar/topbutton.cpp @@ -7,6 +7,9 @@ static int maxid = 10000; TopButtonInt::~TopButtonInt() { + if (hwnd) + DestroyWindow(hwnd); + if (dwFlags & TTBBF_ISLBUTTON) { mir_free(ptszProgram); } diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp index cfccdfaf62..6b2eb6d63a 100644 --- a/src/modules/plugins/newplugins.cpp +++ b/src/modules/plugins/newplugins.cpp @@ -127,6 +127,19 @@ char* GetPluginNameByInstance(HINSTANCE hInstance) return NULL; } +int GetPluginLangByInstance(HINSTANCE hInstance) +{ + if (pluginList.getCount() == 0) + return NULL; + + for (int i=0; i < pluginList.getCount(); i++) { + pluginEntry* p = pluginList[i]; + if (p->bpi.pluginInfo && p->bpi.hInst == hInstance) + return p->hLangpack; + } + return NULL; +} + int GetPluginFakeId(const MUUID &uuid, int hLangpack) { for (int i=0; i < pluginList.getCount(); i++) { -- cgit v1.2.3