diff options
author | George Hazan <george.hazan@gmail.com> | 2012-11-19 12:51:53 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-11-19 12:51:53 +0000 |
commit | 32dedc767dec565c576b78b786e7a95d76ac806e (patch) | |
tree | 0f2eb209b3716569a8e3c3ef146a91f402ebbb4d /src/modules/extraicons | |
parent | adf7367cfdb57b32aadeb74af45dce9a6a3c02a5 (diff) |
- added another helper, ExtraIcon_Clear, to remove an icon from slot;
- added ability to pass IcoLib handles instead of icons' names
git-svn-id: http://svn.miranda-ng.org/main/trunk@2371 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/extraicons')
-rw-r--r-- | src/modules/extraicons/CallbackExtraIcon.cpp | 9 | ||||
-rw-r--r-- | src/modules/extraicons/CallbackExtraIcon.h | 3 | ||||
-rw-r--r-- | src/modules/extraicons/DefaultExtraIcons.cpp | 14 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIcon.h | 17 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIconGroup.cpp | 63 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIconGroup.h | 6 | ||||
-rw-r--r-- | src/modules/extraicons/IcolibExtraIcon.cpp | 61 | ||||
-rw-r--r-- | src/modules/extraicons/IcolibExtraIcon.h | 6 | ||||
-rw-r--r-- | src/modules/extraicons/extraicons.cpp | 33 | ||||
-rw-r--r-- | src/modules/extraicons/options_ei.cpp | 4 | ||||
-rw-r--r-- | src/modules/extraicons/usedIcons.cpp | 69 | ||||
-rw-r--r-- | src/modules/extraicons/usedIcons.h | 9 |
12 files changed, 196 insertions, 98 deletions
diff --git a/src/modules/extraicons/CallbackExtraIcon.cpp b/src/modules/extraicons/CallbackExtraIcon.cpp index 703628e73d..8c07bfd327 100644 --- a/src/modules/extraicons/CallbackExtraIcon.cpp +++ b/src/modules/extraicons/CallbackExtraIcon.cpp @@ -60,12 +60,17 @@ void CallbackExtraIcon::applyIcon(HANDLE hContact) ApplyIcon((WPARAM) hContact, 0);
}
-int CallbackExtraIcon::setIcon(int id, HANDLE hContact, void *icon)
+int CallbackExtraIcon::setIcon(int id, HANDLE hContact, HANDLE icon)
{
if (!isEnabled() || hContact == NULL || id != this->id)
return -1;
- return ClistSetExtraIcon(hContact, (HANDLE) icon);
+ return ClistSetExtraIcon(hContact, icon);
+}
+
+int CallbackExtraIcon::setIconByName(int id, HANDLE hContact, const char *icon)
+{
+ return -1;
}
void CallbackExtraIcon::storeIcon(HANDLE hContact, void *icon)
diff --git a/src/modules/extraicons/CallbackExtraIcon.h b/src/modules/extraicons/CallbackExtraIcon.h index 547f81a477..b339ce53d3 100644 --- a/src/modules/extraicons/CallbackExtraIcon.h +++ b/src/modules/extraicons/CallbackExtraIcon.h @@ -34,7 +34,8 @@ public: virtual void rebuildIcons();
virtual void applyIcon(HANDLE hContact);
- virtual int setIcon(int id, HANDLE hContact, void *icon);
+ virtual int setIcon(int id, HANDLE hContact, HANDLE icon);
+ virtual int setIconByName(int id, HANDLE hContact, const char* icon);
virtual void storeIcon(HANDLE hContact, void *icon);
private:
diff --git a/src/modules/extraicons/DefaultExtraIcons.cpp b/src/modules/extraicons/DefaultExtraIcons.cpp index 539475b10a..5a7917a331 100644 --- a/src/modules/extraicons/DefaultExtraIcons.cpp +++ b/src/modules/extraicons/DefaultExtraIcons.cpp @@ -63,7 +63,7 @@ static void SetVisibility(HANDLE hContact, int apparentMode, BOOL clear) return;
char *proto = (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
- if (IsEmpty(proto))
+ if ( IsEmpty(proto))
return;
if (apparentMode <= 0)
@@ -102,7 +102,7 @@ static void SetGender(HANDLE hContact, int gender, BOOL clear) return;
char *proto = (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
- if (IsEmpty(proto))
+ if ( IsEmpty(proto))
return;
if (gender <= 0)
@@ -172,7 +172,7 @@ static void SetExtraIcons(HANDLE hContact) return;
char *proto = (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
- if (IsEmpty(proto))
+ if ( IsEmpty(proto))
return;
for (unsigned int i = 0; i < SIZEOF(infos); i++) {
@@ -189,7 +189,7 @@ static void SetExtraIcons(HANDLE hContact) info.SetIcon(hContact, &info, dbv.pszVal);
show = true;
}
- DBFreeVariant(&dbv);
+ db_free(&dbv);
}
}
}
@@ -252,7 +252,7 @@ static int DefaultOnClick(WPARAM wParam, LPARAM lParam, LPARAM param) return 0;
char *proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
- if (IsEmpty(proto))
+ if ( IsEmpty(proto))
return 0;
bool found = false;
@@ -267,7 +267,7 @@ static int DefaultOnClick(WPARAM wParam, LPARAM lParam, LPARAM param) found = true;
}
- DBFreeVariant(&dbv);
+ db_free(&dbv);
}
}
@@ -347,7 +347,7 @@ static int ProtocolApplyIcon(WPARAM wParam, LPARAM lParam) HANDLE hContact = (HANDLE)wParam;
char *proto = (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
- if (IsEmpty(proto))
+ if ( IsEmpty(proto))
return 0;
ProtoInfo *pi = FindProto(proto);
diff --git a/src/modules/extraicons/ExtraIcon.h b/src/modules/extraicons/ExtraIcon.h index 281e9e25eb..0fec56562c 100644 --- a/src/modules/extraicons/ExtraIcon.h +++ b/src/modules/extraicons/ExtraIcon.h @@ -30,18 +30,19 @@ public: ExtraIcon(const char *name);
virtual ~ExtraIcon();
- virtual void rebuildIcons() =0;
+ virtual void rebuildIcons() = 0;
virtual void applyIcons();
- virtual void applyIcon(HANDLE hContact) =0;
- virtual void onClick(HANDLE hContact) =0;
+ virtual void applyIcon(HANDLE hContact) =0 ;
+ virtual void onClick(HANDLE hContact) = 0;
- virtual int setIcon(int id, HANDLE hContact, void *icon) =0;
- virtual void storeIcon(HANDLE hContact, void *icon) =0;
+ virtual int setIcon(int id, HANDLE hContact, HANDLE icon) = 0;
+ virtual int setIconByName(int id, HANDLE hContact, const char* icon) = 0;
+ virtual void storeIcon(HANDLE hContact, void *icon) = 0;
virtual const char *getName() const;
- virtual const TCHAR *getDescription() const =0;
- virtual const char *getDescIcon() const =0;
- virtual int getType() const =0;
+ virtual const TCHAR *getDescription() const = 0;
+ virtual const char *getDescIcon() const = 0;
+ virtual int getType() const = 0;
virtual int getSlot() const;
virtual void setSlot(int slot);
diff --git a/src/modules/extraicons/ExtraIconGroup.cpp b/src/modules/extraicons/ExtraIconGroup.cpp index 5d26f8488c..0f9e162877 100644 --- a/src/modules/extraicons/ExtraIconGroup.cpp +++ b/src/modules/extraicons/ExtraIconGroup.cpp @@ -65,17 +65,15 @@ void ExtraIconGroup::applyIcon(HANDLE hContact) insideApply = true;
unsigned int i;
- for (i = 0; i < items.size(); i++)
- {
+ for (i = 0; i < items.size(); i++) {
items[i]->applyIcon(hContact);
-
if (setValidExtraIcon)
break;
}
insideApply = false;
- DBWriteContactSettingDword(hContact, MODULE_NAME, name.c_str(), setValidExtraIcon ? items[i]->getID() : 0);
+ db_set_dw(hContact, MODULE_NAME, name.c_str(), setValidExtraIcon ? items[i]->getID() : 0);
}
int ExtraIconGroup::getPosition() const
@@ -96,7 +94,7 @@ void ExtraIconGroup::setSlot(int slot) ExtraIcon * ExtraIconGroup::getCurrentItem(HANDLE hContact) const
{
- int id = (int) DBGetContactSettingDword(hContact, MODULE_NAME, name.c_str(), 0);
+ int id = (int)DBGetContactSettingDword(hContact, MODULE_NAME, name.c_str(), 0);
if (id < 1)
return NULL;
@@ -114,13 +112,25 @@ void ExtraIconGroup::onClick(HANDLE hContact) extra->onClick(hContact);
}
-int ExtraIconGroup::setIcon(int id, HANDLE hContact, void *icon)
+int ExtraIconGroup::setIcon(int id, HANDLE hContact, HANDLE value)
{
- if (insideApply)
- {
+ return internalSetIcon(id, hContact, (void*)value, false);
+}
+
+int ExtraIconGroup::setIconByName(int id, HANDLE hContact, const char *value)
+{
+ return internalSetIcon(id, hContact, (void*)value, true);
+}
+
+int ExtraIconGroup::internalSetIcon(int id, HANDLE hContact, void *value, bool bByName)
+{
+ if (insideApply) {
for (unsigned int i = 0; i < items.size(); i++)
- if (items[i]->getID() == id)
- return items[i]->setIcon(id, hContact, icon);
+ if (items[i]->getID() == id) {
+ if (bByName)
+ return items[i]->setIconByName(id, hContact, (const char*)value);
+ return items[i]->setIcon(id, hContact, (HANDLE)value);
+ }
return -1;
}
@@ -128,8 +138,7 @@ int ExtraIconGroup::setIcon(int id, HANDLE hContact, void *icon) ExtraIcon *current = getCurrentItem(hContact);
int currentPos = (int)items.size();
int storePos = (int)items.size();
- for (unsigned int i = 0; i < items.size(); i++)
- {
+ for (unsigned int i = 0; i < items.size(); i++) {
if (items[i]->getID() == id)
storePos = i;
@@ -140,9 +149,8 @@ int ExtraIconGroup::setIcon(int id, HANDLE hContact, void *icon) if (storePos == items.size())
return -1;
- if (storePos > currentPos)
- {
- items[storePos]->storeIcon(hContact, icon);
+ if (storePos > currentPos) {
+ items[storePos]->storeIcon(hContact, value);
return 0;
}
@@ -150,25 +158,24 @@ int ExtraIconGroup::setIcon(int id, HANDLE hContact, void *icon) setValidExtraIcon = false;
- int ret = items[storePos]->setIcon(id, hContact, icon);
+ int ret;
+ if (bByName)
+ ret = items[storePos]->setIconByName(id, hContact, (const char*)value);
+ else
+ ret = items[storePos]->setIcon(id, hContact, (HANDLE)value);
- if (storePos < currentPos)
- {
+ if (storePos < currentPos) {
if (setValidExtraIcon)
- DBWriteContactSettingDword(hContact, MODULE_NAME, name.c_str(), items[storePos]->getID());
+ db_set_dw(hContact, MODULE_NAME, name.c_str(), items[storePos]->getID());
}
- else if (storePos == currentPos)
- {
- if (!setValidExtraIcon)
- {
- DBWriteContactSettingDword(hContact, MODULE_NAME, name.c_str(), 0);
+ else if (storePos == currentPos) {
+ if (!setValidExtraIcon) {
+ db_set_dw(hContact, MODULE_NAME, name.c_str(), 0);
insideApply = true;
- for (++storePos; storePos < (int)items.size(); ++storePos)
- {
+ for (++storePos; storePos < (int)items.size(); ++storePos) {
items[storePos]->applyIcon(hContact);
-
if (setValidExtraIcon)
break;
}
@@ -176,7 +183,7 @@ int ExtraIconGroup::setIcon(int id, HANDLE hContact, void *icon) insideApply = false;
if (setValidExtraIcon)
- DBWriteContactSettingDword(hContact, MODULE_NAME, name.c_str(), items[storePos]->getID());
+ db_set_dw(hContact, MODULE_NAME, name.c_str(), items[storePos]->getID());
}
}
diff --git a/src/modules/extraicons/ExtraIconGroup.h b/src/modules/extraicons/ExtraIconGroup.h index eb2aec5561..bddc3bed5e 100644 --- a/src/modules/extraicons/ExtraIconGroup.h +++ b/src/modules/extraicons/ExtraIconGroup.h @@ -27,6 +27,7 @@ class BaseExtraIcon; class ExtraIconGroup : public ExtraIcon
{
+ int internalSetIcon(int id, HANDLE hContact, HANDLE icon, bool bByName);
public:
ExtraIconGroup(const char *name);
virtual ~ExtraIconGroup();
@@ -37,7 +38,8 @@ public: virtual void applyIcon(HANDLE hContact);
virtual void onClick(HANDLE hContact);
- virtual int setIcon(int id, HANDLE hContact, void *icon);
+ virtual int setIcon(int id, HANDLE hContact, HANDLE icon);
+ virtual int setIconByName(int id, HANDLE hContact, const char* icon);
virtual void storeIcon(HANDLE hContact, void *icon);
virtual const TCHAR *getDescription() const;
@@ -56,7 +58,7 @@ protected: bool setValidExtraIcon;
bool insideApply;
- virtual ExtraIcon * getCurrentItem(HANDLE hContact) const;
+ virtual ExtraIcon *getCurrentItem(HANDLE hContact) const;
};
#endif // __EXTRAICONGROUP_H__
diff --git a/src/modules/extraicons/IcolibExtraIcon.cpp b/src/modules/extraicons/IcolibExtraIcon.cpp index bfc273fd0b..53d627da9e 100644 --- a/src/modules/extraicons/IcolibExtraIcon.cpp +++ b/src/modules/extraicons/IcolibExtraIcon.cpp @@ -54,18 +54,50 @@ void IcolibExtraIcon::applyIcon(HANDLE hContact) HANDLE hImage = INVALID_HANDLE_VALUE;
DBVARIANT dbv = { 0 };
- if (!DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv))
- {
+ if ( !DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv)) {
if (!IsEmpty(dbv.pszVal))
hImage = GetIcon(dbv.pszVal);
- DBFreeVariant(&dbv);
+ db_free(&dbv);
}
ClistSetExtraIcon(hContact, hImage);
}
-int IcolibExtraIcon::setIcon(int id, HANDLE hContact, void *icon)
+int IcolibExtraIcon::setIcon(int id, HANDLE hContact, HANDLE hIcoLib)
+{
+ if (hContact == NULL || id != this->id)
+ return -1;
+
+ if (hIcoLib == INVALID_HANDLE_VALUE)
+ hIcoLib = NULL;
+
+ if (isEnabled()) {
+ DBVARIANT dbv = { 0 };
+ if ( !DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv)) {
+ if (!IsEmpty(dbv.pszVal))
+ RemoveIcon(dbv.pszVal);
+
+ db_free(&dbv);
+ }
+ }
+
+ storeIcon(hContact, hIcoLib);
+
+ if (isEnabled()) {
+ HANDLE hImage;
+ if (hIcoLib == NULL)
+ hImage = INVALID_HANDLE_VALUE;
+ else
+ hImage = AddIcon(hIcoLib);
+
+ return ClistSetExtraIcon(hContact, hImage);
+ }
+
+ return 0;
+}
+
+int IcolibExtraIcon::setIconByName(int id, HANDLE hContact, const char *icon)
{
if (hContact == NULL || id != this->id)
return -1;
@@ -73,26 +105,23 @@ int IcolibExtraIcon::setIcon(int id, HANDLE hContact, void *icon) if (icon == INVALID_HANDLE_VALUE)
icon = NULL;
- if (isEnabled())
- {
+ if (isEnabled()) {
DBVARIANT dbv = { 0 };
- if (!DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv))
- {
+ if ( !DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv)) {
if (!IsEmpty(dbv.pszVal))
RemoveIcon(dbv.pszVal);
- DBFreeVariant(&dbv);
+ db_free(&dbv);
}
}
- storeIcon(hContact, icon);
+ storeIcon(hContact, "");
- if (isEnabled())
- {
+ if (isEnabled()) {
const char *icolibName = (const char *) icon;
HANDLE hImage;
- if (IsEmpty(icolibName))
+ if ( IsEmpty(icolibName))
hImage = INVALID_HANDLE_VALUE;
else
hImage = AddIcon(icolibName);
@@ -109,8 +138,8 @@ void IcolibExtraIcon::storeIcon(HANDLE hContact, void *icon) return;
const char *icolibName = (const char *) icon;
- if (IsEmpty(icolibName))
- icolibName = ""; // Delete don't work and I don't know why
+ if ( IsEmpty(icolibName))
+ icolibName = ""; // Delete doesn't work, and I don't know why
- DBWriteContactSettingString(hContact, MODULE_NAME, name.c_str(), icolibName);
+ db_set_s(hContact, MODULE_NAME, name.c_str(), icolibName);
}
diff --git a/src/modules/extraicons/IcolibExtraIcon.h b/src/modules/extraicons/IcolibExtraIcon.h index 5f113e7251..beb24fbdc3 100644 --- a/src/modules/extraicons/IcolibExtraIcon.h +++ b/src/modules/extraicons/IcolibExtraIcon.h @@ -25,8 +25,7 @@ class IcolibExtraIcon : public BaseExtraIcon
{
public:
- IcolibExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon, MIRANDAHOOKPARAM OnClick,
- LPARAM param);
+ IcolibExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon, MIRANDAHOOKPARAM OnClick, LPARAM param);
virtual ~IcolibExtraIcon();
virtual int getType() const;
@@ -34,7 +33,8 @@ public: virtual void rebuildIcons();
virtual void applyIcon(HANDLE hContact);
- virtual int setIcon(int id, HANDLE hContact, void *icon);
+ virtual int setIcon(int id, HANDLE hContact, HANDLE icon);
+ virtual int setIconByName(int id, HANDLE hContact, const char* icon);
virtual void storeIcon(HANDLE hContact, void *icon);
};
diff --git a/src/modules/extraicons/extraicons.cpp b/src/modules/extraicons/extraicons.cpp index 45a81235e6..9f119d5706 100644 --- a/src/modules/extraicons/extraicons.cpp +++ b/src/modules/extraicons/extraicons.cpp @@ -102,7 +102,7 @@ int Clist_SetExtraIcon(HANDLE hContact, int slot, HANDLE hImage) ExtraIcon* GetExtraIcon(HANDLE id)
{
- unsigned int i = (int) id;
+ unsigned int i = (int)id;
if (i < 1 || i > extraIconsByHandle.size())
return NULL;
@@ -157,7 +157,7 @@ static void LoadGroups(vector<ExtraIconGroup *> &groups) group->setSlot(extra->getSlot());
}
}
- DBFreeVariant(&dbv);
+ db_free(&dbv);
}
}
@@ -257,7 +257,7 @@ int ClistExtraClick(WPARAM wParam, LPARAM lParam) if (hContact == NULL)
return 0;
- int clistSlot = (int) lParam;
+ int clistSlot = (int)lParam;
for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) {
ExtraIcon *extra = extraIconsBySlot[i];
@@ -349,11 +349,11 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) return 0;
EXTRAICON_INFO *ei = (EXTRAICON_INFO *) wParam;
- if (ei->cbSize < (int) sizeof(EXTRAICON_INFO))
+ if (ei->cbSize < (int)sizeof(EXTRAICON_INFO))
return 0;
if (ei->type != EXTRAICON_TYPE_CALLBACK && ei->type != EXTRAICON_TYPE_ICOLIB)
return 0;
- if (IsEmpty(ei->name) || IsEmpty(ei->description))
+ if ( IsEmpty(ei->name) || IsEmpty(ei->description))
return 0;
if (ei->type == EXTRAICON_TYPE_CALLBACK && (ei->ApplyIcon == NULL || ei->RebuildIcons == NULL))
return 0;
@@ -457,17 +457,31 @@ INT_PTR ExtraIcon_SetIcon(WPARAM wParam, LPARAM lParam) if (wParam == 0)
return -1;
- EXTRAICON *ei = (EXTRAICON *) wParam;
- if (ei->cbSize < (int) sizeof(EXTRAICON))
+ EXTRAICON *ei = (EXTRAICON*)wParam;
+ if (ei->cbSize < (int)sizeof(EXTRAICON) || ei->hExtraIcon == NULL || ei->hContact == NULL)
return -1;
- if (ei->hExtraIcon == NULL || ei->hContact == NULL)
+
+ ExtraIcon *extra = GetExtraIcon(ei->hExtraIcon);
+ if (extra == NULL)
+ return -1;
+
+ return extra->setIcon((int)ei->hExtraIcon, ei->hContact, ei->hImage);
+}
+
+INT_PTR ExtraIcon_SetIconByName(WPARAM wParam, LPARAM lParam)
+{
+ if (wParam == 0)
+ return -1;
+
+ EXTRAICON *ei = (EXTRAICON*)wParam;
+ if (ei->cbSize < (int)sizeof(EXTRAICON) || ei->hExtraIcon == NULL || ei->hContact == NULL)
return -1;
ExtraIcon *extra = GetExtraIcon(ei->hExtraIcon);
if (extra == NULL)
return -1;
- return extra->setIcon((int) ei->hExtraIcon, ei->hContact, ei->hImage);
+ return extra->setIconByName((int)ei->hExtraIcon, ei->hContact, ei->icoName);
}
static INT_PTR svcExtraIcon_Add(WPARAM wParam, LPARAM lParam)
@@ -486,6 +500,7 @@ void LoadExtraIconsModule() // Services
CreateServiceFunction(MS_EXTRAICON_REGISTER, &ExtraIcon_Register);
CreateServiceFunction(MS_EXTRAICON_SET_ICON, &ExtraIcon_SetIcon);
+ CreateServiceFunction(MS_EXTRAICON_SET_ICON_BY_NAME, &ExtraIcon_SetIconByName);
CreateServiceFunction(MS_CLIST_EXTRA_ADD_ICON, &svcExtraIcon_Add);
diff --git a/src/modules/extraicons/options_ei.cpp b/src/modules/extraicons/options_ei.cpp index b04ec3fec3..2d4e9fd7df 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.size()) {
TCHAR txt[512];
mir_sntprintf(txt, SIZEOF(txt), TranslateT("* only the first %d icons will be shown"), numSlots);
@@ -573,7 +573,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP BaseExtraIcon *extra = group->items[j];
mir_snprintf(setting, SIZEOF(setting), "%d_%d", i, j);
- DBWriteContactSettingString(NULL, MODULE_NAME "Groups", setting, extra->getName());
+ db_set_s(NULL, MODULE_NAME "Groups", setting, extra->getName());
}
}
diff --git a/src/modules/extraicons/usedIcons.cpp b/src/modules/extraicons/usedIcons.cpp index 1c42104490..e810dd1878 100644 --- a/src/modules/extraicons/usedIcons.cpp +++ b/src/modules/extraicons/usedIcons.cpp @@ -25,41 +25,69 @@ struct Icon {
string name;
int refCount;
- HANDLE hImage;
+ HANDLE hIcoLib, hImage;
Icon(const char *icolibName) :
- name(icolibName), refCount(0), hImage(INVALID_HANDLE_VALUE)
+ name(icolibName), hIcoLib(0), refCount(0), hImage(INVALID_HANDLE_VALUE)
+ {
+ }
+
+ Icon(HANDLE _hIcolib) :
+ name(""), hIcoLib(_hIcolib), refCount(0), hImage(INVALID_HANDLE_VALUE)
{
}
};
static vector<Icon> usedIcons;
-static Icon * FindIcon(const char *icolibName)
+static Icon* FindIcon(const char *icolibName)
{
Icon *icon = NULL;
- for (unsigned int i = 0; i < usedIcons.size(); i++)
- {
+ for (unsigned int i = 0; i < usedIcons.size(); i++) {
Icon *tmp = &usedIcons[i];
- if (tmp->name != icolibName)
- continue;
-
- icon = tmp;
- break;
+ if (tmp->name == icolibName) {
+ icon = tmp;
+ break;
+ }
}
- if (icon == NULL)
- {
- usedIcons.push_back(Icon(icolibName));
+ if (icon == NULL) {
+ usedIcons.push_back( Icon(icolibName));
icon = &usedIcons[usedIcons.size() - 1];
}
- if (icon->hImage == INVALID_HANDLE_VALUE)
- {
+ if (icon->hImage == INVALID_HANDLE_VALUE) {
HICON hIcon = Skin_GetIcon(icon->name.c_str());
- if (hIcon != NULL)
- {
+ if (hIcon != NULL) {
+ icon->hImage = ExtraIcon_Add(hIcon);
+ Skin_ReleaseIcon(hIcon);
+ }
+ }
+
+ return icon;
+}
+
+static Icon* FindIcon(HANDLE hIcolib)
+{
+ Icon *icon = NULL;
+
+ for (unsigned int i = 0; i < usedIcons.size(); i++) {
+ Icon *tmp = &usedIcons[i];
+ if (tmp->hImage == hIcolib) {
+ icon = tmp;
+ break;
+ }
+ }
+
+ if (icon == NULL) {
+ usedIcons.push_back( Icon(hIcolib));
+ icon = &usedIcons[usedIcons.size() - 1];
+ }
+
+ if (icon->hImage == INVALID_HANDLE_VALUE) {
+ HICON hIcon = Skin_GetIconByHandle(icon->hIcoLib);
+ if (hIcon != NULL) {
icon->hImage = ExtraIcon_Add(hIcon);
Skin_ReleaseIcon(hIcon);
}
@@ -80,6 +108,13 @@ HANDLE AddIcon(const char *icolibName) return icon->hImage;
}
+HANDLE AddIcon(HANDLE hIcolib)
+{
+ Icon *icon = FindIcon(hIcolib);
+ icon->refCount++;
+ return icon->hImage;
+}
+
void RemoveIcon(const char *icolibName)
{
for (unsigned int i = 0; i < usedIcons.size(); i++)
diff --git a/src/modules/extraicons/usedIcons.h b/src/modules/extraicons/usedIcons.h index ef3a0f0200..b8aeee226c 100644 --- a/src/modules/extraicons/usedIcons.h +++ b/src/modules/extraicons/usedIcons.h @@ -20,9 +20,12 @@ #ifndef __USEDICONS_H__
#define __USEDICONS_H__
-HANDLE GetIcon(const char *icolibName);
-HANDLE AddIcon(const char *icolibName);
-void RemoveIcon(const char *icolibName);
+HANDLE GetIcon(LPCSTR icolibName);
+
+HANDLE AddIcon(LPCSTR icolibName);
+HANDLE AddIcon(HANDLE hIcolib);
+
+void RemoveIcon(LPCSTR icolibName);
void ResetIcons();
|