From 44141ccc8e279bfd390b91f2f0b737b39da6481c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 20 Nov 2012 18:41:56 +0000 Subject: automatic extra icon removal on dynamic plugin unloading git-svn-id: http://svn.miranda-ng.org/main/trunk@2399 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/extraicons/BaseExtraIcon.h | 3 +-- src/modules/extraicons/ExtraIcon.cpp | 2 +- src/modules/extraicons/ExtraIcon.h | 2 ++ src/modules/extraicons/extraicons.cpp | 35 +++++++++++++++++++++++++++++----- src/modules/extraicons/extraicons.h | 2 +- src/modules/extraicons/options_ei.cpp | 10 +++++----- src/modules/plugins/newplugins.cpp | 1 + 7 files changed, 41 insertions(+), 14 deletions(-) (limited to 'src/modules') diff --git a/src/modules/extraicons/BaseExtraIcon.h b/src/modules/extraicons/BaseExtraIcon.h index e382d0d3a9..3f5e15c986 100644 --- a/src/modules/extraicons/BaseExtraIcon.h +++ b/src/modules/extraicons/BaseExtraIcon.h @@ -25,8 +25,7 @@ class BaseExtraIcon : public ExtraIcon { public: - BaseExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon, MIRANDAHOOKPARAM OnClick, - LPARAM param); + BaseExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon, MIRANDAHOOKPARAM OnClick, LPARAM param); virtual ~BaseExtraIcon(); virtual int getID() const; diff --git a/src/modules/extraicons/ExtraIcon.cpp b/src/modules/extraicons/ExtraIcon.cpp index 50758a4056..3a2d7f4139 100644 --- a/src/modules/extraicons/ExtraIcon.cpp +++ b/src/modules/extraicons/ExtraIcon.cpp @@ -24,7 +24,7 @@ #include "extraicons.h" ExtraIcon::ExtraIcon(const char *name) : - name(name), slot(-1), position(1000) + name(name), slot(-1), position(1000), hLangpack(0) { } diff --git a/src/modules/extraicons/ExtraIcon.h b/src/modules/extraicons/ExtraIcon.h index 576b330dea..ae9e1ab797 100644 --- a/src/modules/extraicons/ExtraIcon.h +++ b/src/modules/extraicons/ExtraIcon.h @@ -64,6 +64,8 @@ public: virtual int ClistSetExtraIcon(HANDLE hContact, HANDLE hImage) =0; + int hLangpack; + protected: std::string name; diff --git a/src/modules/extraicons/extraicons.cpp b/src/modules/extraicons/extraicons.cpp index 71565bb89a..c2d1cb1e1e 100644 --- a/src/modules/extraicons/extraicons.cpp +++ b/src/modules/extraicons/extraicons.cpp @@ -34,7 +34,9 @@ // Prototypes /////////////////////////////////////////////////////////////////////////// -vector registeredExtraIcons; +typedef vector::iterator IconIter; + +LIST registeredExtraIcons(10); vector extraIconsByHandle; vector extraIconsBySlot; @@ -59,6 +61,25 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) return 0; } +void KillModuleExtraIcons(int hLangpack) +{ + for (IconIter p1 = extraIconsByHandle.begin(); p1 != extraIconsByHandle.end(); p1++) + if ((*p1)->hLangpack == hLangpack) + extraIconsByHandle.erase(p1--); + + for (IconIter p2 = extraIconsBySlot.begin(); p2 != extraIconsBySlot.end(); p2++) + if ((*p2)->hLangpack == hLangpack) + extraIconsBySlot.erase(p2--); + + for (int i=registeredExtraIcons.getCount()-1; i >= 0; i--) { + BaseExtraIcon *p = registeredExtraIcons[i]; + if (p->hLangpack == hLangpack) { + registeredExtraIcons.remove(i); + delete p; + } + } +} + int PreShutdown(WPARAM wParam, LPARAM lParam) { DefaultExtraIcons_Unload(); @@ -122,7 +143,7 @@ ExtraIcon* GetExtraIconBySlot(int slot) BaseExtraIcon* GetExtraIconByName(const char *name) { - for (unsigned int i = 0; i < registeredExtraIcons.size(); i++) { + for (int i=0; i < registeredExtraIcons.getCount(); i++) { BaseExtraIcon *extra = registeredExtraIcons[i]; if (strcmp(name, extra->getName()) == 0) return extra; @@ -389,7 +410,7 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) return extra->getID(); } - int id = (int)registeredExtraIcons.size() + 1; + int id = registeredExtraIcons.getCount() + 1; switch (ei->type) { case EXTRAICON_TYPE_CALLBACK: @@ -414,7 +435,9 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) slot = -1; extra->setSlot(slot); - registeredExtraIcons.push_back(extra); + extra->hLangpack = (int)lParam; + + registeredExtraIcons.insert(extra); extraIconsByHandle.push_back(extra); vector groups; @@ -546,6 +569,8 @@ void LoadExtraIconsModule() void UnloadExtraIconsModule(void) { - for (size_t i=0; i < registeredExtraIcons.size(); i++) + for (int i=0; i < registeredExtraIcons.getCount(); i++) delete registeredExtraIcons[i]; + + registeredExtraIcons.destroy(); } diff --git a/src/modules/extraicons/extraicons.h b/src/modules/extraicons/extraicons.h index 2ee5982e9c..95807832e3 100644 --- a/src/modules/extraicons/extraicons.h +++ b/src/modules/extraicons/extraicons.h @@ -33,7 +33,7 @@ class ExtraIconGroup; class ExtraIcon; class BaseExtraIcon; -extern vector registeredExtraIcons; +extern LIST registeredExtraIcons; extern vector extraIconsByHandle; extern vector extraIconsBySlot; void RebuildListsBasedOnGroups(vector &groups); diff --git a/src/modules/extraicons/options_ei.cpp b/src/modules/extraicons/options_ei.cpp index 2d4e9fd7df..3a70169f98 100644 --- a/src/modules/extraicons/options_ei.cpp +++ b/src/modules/extraicons/options_ei.cpp @@ -419,7 +419,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP TranslateDialogDefault(hwndDlg); { int numSlots = GetNumberOfSlots(); - if (numSlots < (int)registeredExtraIcons.size()) { + if (numSlots < (int)registeredExtraIcons.getCount()) { TCHAR txt[512]; mir_sntprintf(txt, SIZEOF(txt), TranslateT("* only the first %d icons will be shown"), numSlots); @@ -439,7 +439,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP DestroyIcon(hDefaultIcon); unsigned int i; - for (i = 0; i < registeredExtraIcons.size(); i++) { + for (i = 0; i < registeredExtraIcons.getCount(); i++) { ExtraIcon *extra = registeredExtraIcons[i]; HICON hIcon = Skin_GetIcon(extra->getDescIcon()); @@ -489,9 +489,9 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP HWND tree = GetDlgItem(hwndDlg, IDC_EXTRAORDER); // Store old slots - int *oldSlots = new int[registeredExtraIcons.size()]; + int *oldSlots = new int[registeredExtraIcons.getCount()]; int lastUsedSlot = -1; - for (i = 0; i < registeredExtraIcons.size(); i++) { + for (i = 0; i < registeredExtraIcons.getCount(); i++) { if (extraIconsByHandle[i] == registeredExtraIcons[i]) oldSlots[i] = registeredExtraIcons[i]->getSlot(); else @@ -549,7 +549,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP } // Store data - for (i = 0; i < registeredExtraIcons.size(); i++) { + for (i = 0; i < registeredExtraIcons.getCount(); i++) { BaseExtraIcon *extra = registeredExtraIcons[i]; char setting[512]; diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp index 753720efb1..c80db5c948 100644 --- a/src/modules/plugins/newplugins.cpp +++ b/src/modules/plugins/newplugins.cpp @@ -361,6 +361,7 @@ int Plugin_UnloadDyn(pluginEntry* p) KillModuleIcons(hLangpack); KillModuleHotkeys(hLangpack); KillModuleSounds(hLangpack); + KillModuleExtraIcons(hLangpack); } Plugin_Uninit(p); -- cgit v1.2.3