diff options
author | George Hazan <george.hazan@gmail.com> | 2012-11-20 18:41:56 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-11-20 18:41:56 +0000 |
commit | 44141ccc8e279bfd390b91f2f0b737b39da6481c (patch) | |
tree | c3cee7cf5fde12c891c834272272b85911328198 /src | |
parent | c5c8084eff5beffa9c007de67782b973f2c64fde (diff) |
automatic extra icon removal on dynamic plugin unloading
git-svn-id: http://svn.miranda-ng.org/main/trunk@2399 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r-- | src/core/miranda.h | 4 | ||||
-rw-r--r-- | src/modules/extraicons/BaseExtraIcon.h | 3 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIcon.cpp | 2 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIcon.h | 2 | ||||
-rw-r--r-- | src/modules/extraicons/extraicons.cpp | 35 | ||||
-rw-r--r-- | src/modules/extraicons/extraicons.h | 2 | ||||
-rw-r--r-- | src/modules/extraicons/options_ei.cpp | 10 | ||||
-rw-r--r-- | src/modules/plugins/newplugins.cpp | 1 |
8 files changed, 45 insertions, 14 deletions
diff --git a/src/core/miranda.h b/src/core/miranda.h index 614c4aee98..49fbfa68ae 100644 --- a/src/core/miranda.h +++ b/src/core/miranda.h @@ -117,6 +117,10 @@ extern LIST<DATABASELINK> arDbPlugins; int InitIni(void);
void UninitIni(void);
+/**** extraicons.cpp *******************************************************************/
+
+void KillModuleExtraIcons(int hLangpack);
+
/**** fontService.cpp ******************************************************************/
void KillModuleFonts(int hLangpack);
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<BaseExtraIcon*> registeredExtraIcons;
+typedef vector<ExtraIcon*>::iterator IconIter;
+
+LIST<BaseExtraIcon> registeredExtraIcons(10);
vector<ExtraIcon*> extraIconsByHandle;
vector<ExtraIcon*> 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<ExtraIconGroup *> 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<BaseExtraIcon*> registeredExtraIcons;
+extern LIST<BaseExtraIcon> registeredExtraIcons;
extern vector<ExtraIcon*> extraIconsByHandle;
extern vector<ExtraIcon*> extraIconsBySlot;
void RebuildListsBasedOnGroups(vector<ExtraIconGroup *> &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);
|