diff options
author | George Hazan <ghazan@miranda.im> | 2018-05-30 13:09:55 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-05-30 13:09:55 +0300 |
commit | d2020205b35f89ca6db613873f0c68f04db2c9e4 (patch) | |
tree | b4ce0cd1a8587724904177cc50ac594a15f037e3 /src | |
parent | b683fecbe05a612c21c86c98b5af5df26f04b1f2 (diff) |
extra icons: gettimg rid of IDs
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/ei_baseIcon.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/ei_groupIcon.cpp | 43 | ||||
-rw-r--r-- | src/mir_app/src/ei_services.cpp | 16 | ||||
-rw-r--r-- | src/mir_app/src/extraicons.h | 14 |
4 files changed, 27 insertions, 51 deletions
diff --git a/src/mir_app/src/ei_baseIcon.cpp b/src/mir_app/src/ei_baseIcon.cpp index 550bd97d69..607d79cf8a 100644 --- a/src/mir_app/src/ei_baseIcon.cpp +++ b/src/mir_app/src/ei_baseIcon.cpp @@ -43,11 +43,6 @@ void BaseExtraIcon::setOnClick(MIRANDAHOOKPARAM pFunc, LPARAM pParam) m_onClickParam = pParam; } -int BaseExtraIcon::getID() const -{ - return m_id; -} - const wchar_t* BaseExtraIcon::getDescription() const { return TranslateW_LP(m_tszDescription, m_hLangpack); diff --git a/src/mir_app/src/ei_groupIcon.cpp b/src/mir_app/src/ei_groupIcon.cpp index 7bc068c32e..36bbe8fea9 100644 --- a/src/mir_app/src/ei_groupIcon.cpp +++ b/src/mir_app/src/ei_groupIcon.cpp @@ -62,16 +62,15 @@ void ExtraIconGroup::applyIcon(MCONTACT hContact) m_setValidExtraIcon = false; m_insideApply = true; - int i; - for (i = 0; i < m_items.getCount(); i++) { - m_items[i]->applyIcon(hContact); - if (m_setValidExtraIcon) + for (auto &p : m_items) { + p->applyIcon(hContact); + if (m_setValidExtraIcon) { + m_pCurrentItem = p; break; + } } m_insideApply = false; - - db_set_dw(hContact, EI_MODULE_NAME, m_szName, m_setValidExtraIcon ? m_items[i]->getID() : 0); } int ExtraIconGroup::getPosition() const @@ -90,24 +89,10 @@ void ExtraIconGroup::setSlot(int slot) p->setSlot(slot); } -ExtraIcon * ExtraIconGroup::getCurrentItem(MCONTACT hContact) const -{ - int id = (int)db_get_dw(hContact, EI_MODULE_NAME, m_szName, 0); - if (id < 1) - return nullptr; - - for (auto &p : m_items) - if (id == p->getID()) - return p; - - return nullptr; -} - void ExtraIconGroup::onClick(MCONTACT hContact) { - ExtraIcon *extra = getCurrentItem(hContact); - if (extra != nullptr) - extra->onClick(hContact); + if (m_pCurrentItem != nullptr) + m_pCurrentItem->onClick(hContact); } int ExtraIconGroup::setIcon(int id, MCONTACT hContact, HANDLE value) @@ -133,14 +118,13 @@ int ExtraIconGroup::internalSetIcon(int id, MCONTACT hContact, HANDLE value, boo return -1; } - ExtraIcon *current = getCurrentItem(hContact); int currentPos = m_items.getCount(); int storePos = m_items.getCount(); for (int i = 0; i < m_items.getCount(); i++) { if (m_items[i]->getID() == id) storePos = i; - if (m_items[i] == current) + if (m_items[i] == m_pCurrentItem) currentPos = i; } @@ -164,24 +148,23 @@ int ExtraIconGroup::internalSetIcon(int id, MCONTACT hContact, HANDLE value, boo if (storePos < currentPos) { if (m_setValidExtraIcon) - db_set_dw(hContact, EI_MODULE_NAME, m_szName, m_items[storePos]->getID()); + m_pCurrentItem = m_items[storePos]; } else if (storePos == currentPos) { if (!m_setValidExtraIcon) { - db_set_dw(hContact, EI_MODULE_NAME, m_szName, 0); + m_pCurrentItem = nullptr; m_insideApply = true; for (++storePos; storePos < m_items.getCount(); ++storePos) { m_items[storePos]->applyIcon(hContact); - if (m_setValidExtraIcon) + if (m_setValidExtraIcon) { + m_pCurrentItem = m_items[storePos]; break; + } } m_insideApply = false; - - if (m_setValidExtraIcon && storePos < m_items.getCount()) - db_set_dw(hContact, EI_MODULE_NAME, m_szName, m_items[storePos]->getID()); } } diff --git a/src/mir_app/src/ei_services.cpp b/src/mir_app/src/ei_services.cpp index 98d53f0c9b..354b0a8a72 100644 --- a/src/mir_app/src/ei_services.cpp +++ b/src/mir_app/src/ei_services.cpp @@ -204,6 +204,7 @@ MIR_APP_DLL(void) KillModuleExtraIcons(int _hLang) LIST<ExtraIconGroup> groups(1); LoadGroups(groups); RebuildListsBasedOnGroups(groups); + ExtraIcon_SetAll(); for (auto &it : arIcons) delete it; @@ -291,22 +292,17 @@ MIR_APP_DLL(void) ExtraIcon_SetAll(MCONTACT hContact) if (g_clistApi.hwndContactTree == nullptr) return; - bool hcontgiven = (hContact != 0); - if (!bImageCreated) ExtraIcon_Reload(); SendMessage(g_clistApi.hwndContactTree, CLM_SETEXTRACOLUMNS, EXTRA_ICON_COUNT, 0); - if (hContact == 0) - hContact = db_find_first(); - - for (; hContact; hContact = db_find_next(hContact)) { - NotifyEventHooks(hEventExtraImageApplying, hContact, 0); - if (hcontgiven) - break; + if (hContact == 0) { + for (auto &it : Contacts()) + NotifyEventHooks(hEventExtraImageApplying, it, 0); } - + else NotifyEventHooks(hEventExtraImageApplying, hContact, 0); + g_clistApi.pfnInvalidateRect(g_clistApi.hwndContactTree, nullptr, FALSE); } diff --git a/src/mir_app/src/extraicons.h b/src/mir_app/src/extraicons.h index 8b3c50108a..b15a9dd352 100644 --- a/src/mir_app/src/extraicons.h +++ b/src/mir_app/src/extraicons.h @@ -81,12 +81,13 @@ public: BaseExtraIcon(int id, const char *name, const wchar_t *description, const char *descIcon, MIRANDAHOOKPARAM OnClick, LPARAM param);
virtual ~BaseExtraIcon();
- virtual int getID() const;
- virtual const wchar_t *getDescription() const;
+ __forceinline int getID() const { return m_id; }
+
+ virtual const wchar_t* getDescription() const;
virtual void setDescription(const wchar_t *desc);
- virtual const char *getDescIcon() const;
+ virtual const char* getDescIcon() const;
virtual void setDescIcon(const char *icon);
- virtual int getType() const =0;
+ virtual int getType() const = 0;
virtual void onClick(MCONTACT hContact);
virtual void setOnClick(MIRANDAHOOKPARAM OnClick, LPARAM param);
@@ -151,6 +152,7 @@ public: class ExtraIconGroup : public ExtraIcon
{
int internalSetIcon(int id, MCONTACT hContact, HANDLE icon, bool bByName);
+
public:
ExtraIconGroup(const char *name);
virtual ~ExtraIconGroup();
@@ -179,8 +181,8 @@ protected: ptrW m_tszDescription;
bool m_setValidExtraIcon;
bool m_insideApply;
-
- virtual ExtraIcon *getCurrentItem(MCONTACT hContact) const;
+
+ ExtraIcon *m_pCurrentItem = nullptr;
};
/////////////////////////////////////////////////////////////////////////////////////////
|