From ecb177cadbcff850a16c4b9e306beb15f61ac6f9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 4 Nov 2012 18:51:53 +0000 Subject: kernel extraicons, part II git-svn-id: http://svn.miranda-ng.org/main/trunk@2188 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/extraicons/DefaultExtraIcons.cpp | 10 +- src/modules/extraicons/ExtraIconGroup.cpp | 18 +- src/modules/extraicons/extraicons.cpp | 384 ++++++++++++++++----------- src/modules/extraicons/extraicons.h | 5 + src/modules/extraicons/options_ei.cpp | 24 +- src/modules/extraicons/usedIcons.cpp | 10 +- 6 files changed, 259 insertions(+), 192 deletions(-) (limited to 'src/modules/extraicons') diff --git a/src/modules/extraicons/DefaultExtraIcons.cpp b/src/modules/extraicons/DefaultExtraIcons.cpp index f7e44dafab..4c05a8e590 100644 --- a/src/modules/extraicons/DefaultExtraIcons.cpp +++ b/src/modules/extraicons/DefaultExtraIcons.cpp @@ -177,7 +177,7 @@ static void SetExtraIcons(HANDLE hContact) if (IsEmpty(proto)) return; - for (unsigned int i = 0; i < SIZEOF(infos); ++i) + for (unsigned int i = 0; i < SIZEOF(infos); i++) { Info &info = infos[i]; @@ -227,7 +227,7 @@ static int SettingChanged(WPARAM wParam, LPARAM lParam) return 0; } - for (unsigned int i = 0; i < SIZEOF(infos); ++i) + for (unsigned int i = 0; i < SIZEOF(infos); i++) { Info &info = infos[i]; @@ -293,7 +293,7 @@ static void DBExtraIconsInit() hExtraChat = ExtraIcon_Register("chat_activity", "Chat activity", "ChatActivity"); hExtraVisibility = ExtraIcon_Register("visibility", "Visibility", "AlwaysVis"); hExtraGender = ExtraIcon_Register("gender", "Gender", "gender_male"); - for (unsigned int i = 0; i < SIZEOF(infos); ++i) + for (unsigned int i = 0; i < SIZEOF(infos); i++) { Info &info = infos[i]; if (info.OnClick) @@ -335,7 +335,7 @@ static int ProtocolRebuildIcons(WPARAM wParam, LPARAM lParam) static ProtoInfo *FindProto(const char * proto) { - for (unsigned int i = 0; i < protos.size(); ++i) + for (unsigned int i = 0; i < protos.size(); i++) { ProtoInfo *pi = &protos[i]; if (strcmp(pi->proto.c_str(), proto) == 0) @@ -346,7 +346,7 @@ static ProtoInfo *FindProto(const char * proto) if (hIcon == NULL) return NULL; - HANDLE hImage = (HANDLE) CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM) hIcon, 0); + HANDLE hImage = ExtraIcon_Add(hIcon); if (hImage == INVALID_HANDLE_VALUE) return NULL; diff --git a/src/modules/extraicons/ExtraIconGroup.cpp b/src/modules/extraicons/ExtraIconGroup.cpp index 6e823bde03..c38aed8bf7 100644 --- a/src/modules/extraicons/ExtraIconGroup.cpp +++ b/src/modules/extraicons/ExtraIconGroup.cpp @@ -41,7 +41,7 @@ void ExtraIconGroup::addExtraIcon(BaseExtraIcon *extra) items.push_back(extra); description.clear(); - for (unsigned int i = 0; i < items.size(); ++i) + for (unsigned int i = 0; i < items.size(); i++) { if (i > 0) description += _T(" / "); @@ -51,7 +51,7 @@ void ExtraIconGroup::addExtraIcon(BaseExtraIcon *extra) void ExtraIconGroup::rebuildIcons() { - for (unsigned int i = 0; i < items.size(); ++i) + for (unsigned int i = 0; i < items.size(); i++) items[i]->rebuildIcons(); } @@ -65,7 +65,7 @@ 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); @@ -81,7 +81,7 @@ void ExtraIconGroup::applyIcon(HANDLE hContact) int ExtraIconGroup::getPosition() const { int pos = INT_MAX; - for (unsigned int i = 0; i < items.size(); ++i) + for (unsigned int i = 0; i < items.size(); i++) pos = MIN(pos, items[i]->getPosition()); return pos; } @@ -90,7 +90,7 @@ void ExtraIconGroup::setSlot(int slot) { ExtraIcon::setSlot(slot); - for (unsigned int i = 0; i < items.size(); ++i) + for (unsigned int i = 0; i < items.size(); i++) items[i]->setSlot(slot); } @@ -100,7 +100,7 @@ ExtraIcon * ExtraIconGroup::getCurrentItem(HANDLE hContact) const if (id < 1) return NULL; - for (unsigned int i = 0; i < items.size(); ++i) + for (unsigned int i = 0; i < items.size(); i++) if (id == items[i]->getID()) return items[i]; @@ -118,7 +118,7 @@ int ExtraIconGroup::setIcon(int id, HANDLE hContact, void *icon) { if (insideApply) { - for (unsigned int i = 0; i < items.size(); ++i) + for (unsigned int i = 0; i < items.size(); i++) if (items[i]->getID() == id) return items[i]->setIcon(id, hContact, icon); @@ -128,7 +128,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; @@ -194,7 +194,7 @@ const TCHAR *ExtraIconGroup::getDescription() const const char *ExtraIconGroup::getDescIcon() const { - for (unsigned int i = 0; i < items.size(); ++i) + for (unsigned int i = 0; i < items.size(); i++) if (!IsEmpty(items[i]->getDescIcon())) return items[i]->getDescIcon(); diff --git a/src/modules/extraicons/extraicons.cpp b/src/modules/extraicons/extraicons.cpp index a2d7c3b34a..9688ec364c 100644 --- a/src/modules/extraicons/extraicons.cpp +++ b/src/modules/extraicons/extraicons.cpp @@ -30,6 +30,7 @@ #include "extraicons.h" #include "usedIcons.h" +#include "..\clist\clc.h" // Prototypes /////////////////////////////////////////////////////////////////////////// @@ -43,79 +44,9 @@ BOOL clistApplyAlreadyCalled = FALSE; int clistFirstSlot = 0; int clistSlotCount = 0; -int ModulesLoaded(WPARAM wParam, LPARAM lParam); -int PreShutdown(WPARAM wParam, LPARAM lParam); -int IconsChanged(WPARAM wParam, LPARAM lParam); -int ClistExtraListRebuild(WPARAM wParam, LPARAM lParam); -int ClistExtraImageApply(WPARAM wParam, LPARAM lParam); -int ClistExtraClick(WPARAM wParam, LPARAM lParam); -int InitOptionsCallback(WPARAM wParam, LPARAM lParam); - -INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam); -INT_PTR ExtraIcon_SetIcon(WPARAM wParam, LPARAM lParam); - // Functions //////////////////////////////////////////////////////////////////////////// -void LoadExtraIconsModule() -{ - DWORD ret = CallService(MS_CLUI_GETCAPS, CLUICAPS_FLAGS2, 0); - clistFirstSlot = HIWORD(ret); - clistSlotCount = LOWORD(ret); - - // Icons - TCHAR tszFile[MAX_PATH]; - GetModuleFileName(NULL, tszFile, MAX_PATH); - - SKINICONDESC sid = {0}; - sid.cbSize = sizeof(SKINICONDESC); - sid.flags = SIDF_PATH_TCHAR; - sid.ptszDefaultFile = tszFile; - sid.pszSection = "Contact List"; - - sid.pszName = "AlwaysVis"; - sid.pszDescription = LPGEN("Always Visible"); - sid.iDefaultIndex = -IDI_ALWAYSVIS; - Skin_AddIcon(&sid); - - sid.pszName = "NeverVis"; - sid.pszDescription = LPGEN("Never Visible"); - sid.iDefaultIndex = -IDI_NEVERVIS; - Skin_AddIcon(&sid); - - sid.pszName = "ChatActivity"; - sid.pszDescription = LPGEN("Chat Activity"); - sid.iDefaultIndex = -IDI_CHAT; - Skin_AddIcon(&sid); - - sid.pszName = "gender_male"; - sid.pszDescription = LPGEN("Male"); - sid.iDefaultIndex = -IDI_MALE; - Skin_AddIcon(&sid); - - sid.pszName = "gender_female"; - sid.pszDescription = LPGEN("Female"); - sid.iDefaultIndex = -IDI_FEMALE; - Skin_AddIcon(&sid); - - // Hooks - HookEvent(ME_SYSTEM_MODULESLOADED, &ModulesLoaded); - HookEvent(ME_SYSTEM_PRESHUTDOWN, &PreShutdown); - HookEvent(ME_CLIST_EXTRA_LIST_REBUILD, &ClistExtraListRebuild); - HookEvent(ME_CLIST_EXTRA_IMAGE_APPLY, &ClistExtraImageApply); - HookEvent(ME_CLIST_EXTRA_CLICK, &ClistExtraClick); - - // Services - CreateServiceFunction(MS_EXTRAICON_REGISTER, &ExtraIcon_Register); - CreateServiceFunction(MS_EXTRAICON_SET_ICON, &ExtraIcon_SetIcon); - - DefaultExtraIcons_Load(); -} - -void UnloadExtraIconsModule(void) -{ - for (size_t i=0; i < registeredExtraIcons.size(); i++) - delete registeredExtraIcons[i]; -} +int InitOptionsCallback(WPARAM wParam, LPARAM lParam); // Called when all the modules are loaded int ModulesLoaded(WPARAM wParam, LPARAM lParam) @@ -124,16 +55,10 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) CallService("DBEditorpp/RegisterSingleModule", (WPARAM) MODULE_NAME, 0); CallService("DBEditorpp/RegisterSingleModule", (WPARAM) MODULE_NAME "Groups", 0); - HookEvent(ME_SKIN2_ICONSCHANGED, &IconsChanged); HookEvent(ME_OPT_INITIALISE, InitOptionsCallback); return 0; } -int IconsChanged(WPARAM wParam, LPARAM lParam) -{ - return 0; -} - int PreShutdown(WPARAM wParam, LPARAM lParam) { DefaultExtraIcons_Unload(); @@ -153,17 +78,29 @@ int ConvertToClistSlot(int slot) return clistFirstSlot + slot; } +int ExtraImage_ExtraIDToColumnNum(int extra) +{ + return (extra < 1 || extra > EXTRA_ICON_COUNT) ? -1 : extra-1; +} + int Clist_SetExtraIcon(HANDLE hContact, int slot, HANDLE hImage) { - IconExtraColumn iec = { 0 }; - iec.cbSize = sizeof(iec); - iec.ColumnType = ConvertToClistSlot(slot); - iec.hImage = hImage; + if (cli.hwndContactTree == 0) + return -1; + + int icol = ExtraImage_ExtraIDToColumnNum( ConvertToClistSlot(slot)); + if (icol == -1) + return -1; - return CallService(MS_CLIST_EXTRA_SET_ICON, (WPARAM) hContact, (LPARAM) &iec); + HANDLE hItem = (HANDLE)SendMessage(cli.hwndContactTree, CLM_FINDCONTACT, (WPARAM)hContact, 0); + if (hItem == 0) + return -1; + + SendMessage(cli.hwndContactTree, CLM_SETWIDEEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(icol,hImage)); + return 0; } -ExtraIcon * GetExtraIcon(HANDLE id) +ExtraIcon* GetExtraIcon(HANDLE id) { unsigned int i = (int) id; @@ -173,10 +110,9 @@ ExtraIcon * GetExtraIcon(HANDLE id) return extraIconsByHandle[i - 1]; } -ExtraIcon * GetExtraIconBySlot(int slot) +ExtraIcon* GetExtraIconBySlot(int slot) { - for (unsigned int i = 0; i < extraIconsBySlot.size(); ++i) - { + for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) { ExtraIcon *extra = extraIconsBySlot[i]; if (extra->getSlot() == slot) return extra; @@ -184,10 +120,9 @@ ExtraIcon * GetExtraIconBySlot(int slot) return NULL; } -BaseExtraIcon * GetExtraIconByName(const char *name) +BaseExtraIcon* GetExtraIconByName(const char *name) { - for (unsigned int i = 0; i < registeredExtraIcons.size(); ++i) - { + for (unsigned int i = 0; i < registeredExtraIcons.size(); i++) { BaseExtraIcon *extra = registeredExtraIcons[i]; if (strcmp(name, extra->getName()) == 0) return extra; @@ -198,8 +133,7 @@ BaseExtraIcon * GetExtraIconByName(const char *name) static void LoadGroups(vector &groups) { unsigned int count = DBGetContactSettingWord(NULL, MODULE_NAME "Groups", "Count", 0); - for (unsigned int i = 0; i < count; ++i) - { + for (unsigned int i = 0; i < count; i++) { char setting[512]; mir_snprintf(setting, SIZEOF(setting), "%d_count", i); unsigned int items = DBGetContactSettingWord(NULL, MODULE_NAME "Groups", setting, 0); @@ -209,18 +143,14 @@ static void LoadGroups(vector &groups) mir_snprintf(setting, SIZEOF(setting), "__group_%d", i); ExtraIconGroup *group = new ExtraIconGroup(setting); - for (unsigned int j = 0; j < items; ++j) - { + for (unsigned int j = 0; j < items; j++) { mir_snprintf(setting, SIZEOF(setting), "%d_%d", i, j); DBVARIANT dbv = { 0 }; - if (!DBGetContactSettingString(NULL, MODULE_NAME "Groups", setting, &dbv)) - { - if (!IsEmpty(dbv.pszVal)) - { + if (!DBGetContactSettingString(NULL, MODULE_NAME "Groups", setting, &dbv)) { + if (!IsEmpty(dbv.pszVal)) { BaseExtraIcon *extra = GetExtraIconByName(dbv.pszVal); - if (extra != NULL) - { + if (extra != NULL) { group->items.push_back(extra); if (extra->getSlot() >= 0) @@ -231,8 +161,7 @@ static void LoadGroups(vector &groups) } } - if (group->items.size() < 2) - { + if (group->items.size() < 2) { delete group; continue; } @@ -243,11 +172,9 @@ static void LoadGroups(vector &groups) static ExtraIconGroup * IsInGroup(vector &groups, BaseExtraIcon *extra) { - for (unsigned int i = 0; i < groups.size(); ++i) - { + for (unsigned int i = 0; i < groups.size(); i++) { ExtraIconGroup *group = groups[i]; - for (unsigned int j = 0; j < group->items.size(); ++j) - { + for (unsigned int j = 0; j < group->items.size(); j++) { if (extra == group->items[j]) return group; } @@ -266,11 +193,10 @@ struct compareFunc : std::binary_function &groups) { unsigned int i; - for (i = 0; i < extraIconsByHandle.size(); ++i) + for (i = 0; i < extraIconsByHandle.size(); i++) extraIconsByHandle[i] = registeredExtraIcons[i]; - for (i = 0; i < extraIconsBySlot.size(); ++i) - { + for (i = 0; i < extraIconsBySlot.size(); i++) { ExtraIcon *extra = extraIconsBySlot[i]; if (extra->getType() != EXTRAICON_TYPE_GROUP) continue; @@ -279,18 +205,16 @@ void RebuildListsBasedOnGroups(vector &groups) } extraIconsBySlot.clear(); - for (i = 0; i < groups.size(); ++i) - { + for (i = 0; i < groups.size(); i++) { ExtraIconGroup *group = groups[i]; - for (unsigned int j = 0; j < group->items.size(); ++j) + for (unsigned int j = 0; j < group->items.size(); j++) extraIconsByHandle[group->items[j]->getID() - 1] = group; extraIconsBySlot.push_back(group); } - for (i = 0; i < extraIconsByHandle.size(); ++i) - { + for (i = 0; i < extraIconsByHandle.size(); i++) { ExtraIcon *extra = extraIconsByHandle[i]; if (extra->getType() != EXTRAICON_TYPE_GROUP) extraIconsBySlot.push_back(extra); @@ -299,6 +223,124 @@ void RebuildListsBasedOnGroups(vector &groups) std::sort(extraIconsBySlot.begin(), extraIconsBySlot.end(), compareFunc()); } +/////////////////////////////////////////////////////////////////////////////// + +int ClistExtraListRebuild(WPARAM wParam, LPARAM lParam) +{ + clistRebuildAlreadyCalled = TRUE; + + ResetIcons(); + + for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) + extraIconsBySlot[i]->rebuildIcons(); + + return 0; +} + +int ClistExtraImageApply(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = (HANDLE)wParam; + if (hContact == NULL) + return 0; + + clistApplyAlreadyCalled = TRUE; + + for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) + extraIconsBySlot[i]->applyIcon(hContact); + + return 0; +} + +int ClistExtraClick(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = (HANDLE)wParam; + if (hContact == NULL) + return 0; + + int clistSlot = (int) lParam; + + for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) { + ExtraIcon *extra = extraIconsBySlot[i]; + if (ConvertToClistSlot(extra->getSlot()) == clistSlot) { + extra->onClick(hContact); + break; + } + } + + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// +// Extra image list functions + +static HANDLE hEventExtraImageListRebuilding, hEventExtraImageApplying, hEventExtraClick; +static bool bImageCreated = false; +static int g_mutex_bSetAllExtraIconsCycle = 0; + +HANDLE ExtraIcon_Add(HICON hIcon) +{ + if (cli.hExtraImageList == 0 || hIcon == 0) + return INVALID_HANDLE_VALUE; + + int res = ImageList_AddIcon(cli.hExtraImageList, hIcon); + return (res > 0xFFFE) ? INVALID_HANDLE_VALUE : (HANDLE)res; +} + +void fnReloadExtraIcons() +{ + SendMessage(cli.hwndContactTree, CLM_SETEXTRACOLUMNSSPACE, db_get_b(NULL,"CLUI","ExtraColumnSpace",18), 0); + SendMessage(cli.hwndContactTree, CLM_SETEXTRAIMAGELIST, 0, 0); + + if (cli.hExtraImageList) + ImageList_Destroy(cli.hExtraImageList); + + cli.hExtraImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLOR32|ILC_MASK,1,256); + + SendMessage(cli.hwndContactTree,CLM_SETEXTRAIMAGELIST,(WPARAM)cli.hExtraImageList,0); + SendMessage(cli.hwndContactTree,CLM_SETEXTRACOLUMNS, EXTRA_ICON_COUNT, 0); + NotifyEventHooks(hEventExtraImageListRebuilding,0,0); + bImageCreated = true; +} + +void fnSetAllExtraIcons(HWND hwndList,HANDLE hContact) +{ + if (cli.hwndContactTree == 0) + return; + + g_mutex_bSetAllExtraIconsCycle = 1; + bool hcontgiven = (hContact != 0); + + if (!bImageCreated) + cli.pfnReloadExtraIcons(); + + SendMessage(cli.hwndContactTree,CLM_SETEXTRACOLUMNS, EXTRA_ICON_COUNT, 0); + + if (hContact == NULL) + hContact = db_find_first(); + + do { + HANDLE hItem = hContact; + if (hItem == 0) + continue; + + ClcCacheEntry* pdnce = (ClcCacheEntry*)cli.pfnGetCacheEntry(hItem); + if (pdnce == NULL) + continue; + + NotifyEventHooks(hEventExtraImageApplying, (WPARAM)hContact, 0); + if (hcontgiven) break; + Sleep(0); + } + while(hContact = db_find_next(hContact)); + + g_mutex_bSetAllExtraIconsCycle = 0; + cli.pfnInvalidateRect(hwndList, NULL, FALSE); + Sleep(0); +} + +/////////////////////////////////////////////////////////////////////////////// +// Services + INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) { if (wParam == 0) @@ -317,15 +359,13 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) TCHAR *desc = Langpack_PcharToTchar(ei->description); BaseExtraIcon *extra = GetExtraIconByName(ei->name); - if (extra != NULL) - { + if (extra != NULL) { if (ei->type != extra->getType() || ei->type != EXTRAICON_TYPE_ICOLIB) return 0; // Found one, now merge it - if (_tcsicmp(extra->getDescription(), desc)) - { + if ( _tcsicmp(extra->getDescription(), desc)) { tstring newDesc = extra->getDescription(); newDesc += _T(" / "); newDesc += desc; @@ -338,8 +378,7 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) if (ei->OnClick != NULL) extra->setOnClick(ei->OnClick, ei->onClickParam); - if (extra->getSlot() > 0) - { + if (extra->getSlot() > 0) { if (clistRebuildAlreadyCalled) extra->rebuildIcons(); if (clistApplyAlreadyCalled) @@ -382,26 +421,21 @@ INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) ExtraIconGroup *group = IsInGroup(groups, extra); if (group != NULL) - { RebuildListsBasedOnGroups(groups); - } - else - { - for (unsigned int i = 0; i < groups.size(); ++i) + else { + for (unsigned int i = 0; i < groups.size(); i++) delete groups[i]; extraIconsBySlot.push_back(extra); std::sort(extraIconsBySlot.begin(), extraIconsBySlot.end(), compareFunc()); } - if (slot >= 0 || group != NULL) - { + if (slot >= 0 || group != NULL) { if (clistRebuildAlreadyCalled) extra->rebuildIcons(); slot = 0; - for (unsigned int i = 0; i < extraIconsBySlot.size(); ++i) - { + for (unsigned int i = 0; i < extraIconsBySlot.size(); i++) { ExtraIcon *ex = extraIconsBySlot[i]; if (ex->getSlot() < 0) continue; @@ -435,49 +469,77 @@ INT_PTR ExtraIcon_SetIcon(WPARAM wParam, LPARAM lParam) return extra->setIcon((int) ei->hExtraIcon, ei->hContact, ei->hImage); } -int ClistExtraListRebuild(WPARAM wParam, LPARAM lParam) +static INT_PTR svcExtraIcon_Add(WPARAM wParam, LPARAM lParam) { - clistRebuildAlreadyCalled = TRUE; + return (INT_PTR)ExtraIcon_Add((HICON)wParam); +} - ResetIcons(); +/////////////////////////////////////////////////////////////////////////////// - for (unsigned int i = 0; i < extraIconsBySlot.size(); ++i) - extraIconsBySlot[i]->rebuildIcons(); +void LoadExtraIconsModule() +{ + DWORD ret = CallService(MS_CLUI_GETCAPS, CLUICAPS_FLAGS2, 0); + clistFirstSlot = HIWORD(ret); + clistSlotCount = LOWORD(ret); - return 0; -} + // Services + CreateServiceFunction(MS_EXTRAICON_REGISTER, &ExtraIcon_Register); + CreateServiceFunction(MS_EXTRAICON_SET_ICON, &ExtraIcon_SetIcon); -int ClistExtraImageApply(WPARAM wParam, LPARAM lParam) -{ - HANDLE hContact = (HANDLE) wParam; - if (hContact == NULL) - return 0; + CreateServiceFunction(MS_CLIST_EXTRA_ADD_ICON, &svcExtraIcon_Add); - clistApplyAlreadyCalled = TRUE; + hEventExtraClick = CreateHookableEvent(ME_CLIST_EXTRA_CLICK); + hEventExtraImageApplying = CreateHookableEvent(ME_CLIST_EXTRA_IMAGE_APPLY); + hEventExtraImageListRebuilding = CreateHookableEvent(ME_CLIST_EXTRA_LIST_REBUILD); - for (unsigned int i = 0; i < extraIconsBySlot.size(); ++i) - extraIconsBySlot[i]->applyIcon(hContact); + // Icons + TCHAR tszFile[MAX_PATH]; + GetModuleFileName(NULL, tszFile, MAX_PATH); - return 0; -} + SKINICONDESC sid = {0}; + sid.cbSize = sizeof(SKINICONDESC); + sid.flags = SIDF_PATH_TCHAR; + sid.ptszDefaultFile = tszFile; + sid.pszSection = "Contact List"; -int ClistExtraClick(WPARAM wParam, LPARAM lParam) -{ - HANDLE hContact = (HANDLE) wParam; - if (hContact == NULL) - return 0; + sid.pszName = "AlwaysVis"; + sid.pszDescription = LPGEN("Always Visible"); + sid.iDefaultIndex = -IDI_ALWAYSVIS; + Skin_AddIcon(&sid); - int clistSlot = (int) lParam; + sid.pszName = "NeverVis"; + sid.pszDescription = LPGEN("Never Visible"); + sid.iDefaultIndex = -IDI_NEVERVIS; + Skin_AddIcon(&sid); - for (unsigned int i = 0; i < extraIconsBySlot.size(); ++i) - { - ExtraIcon *extra = extraIconsBySlot[i]; - if (ConvertToClistSlot(extra->getSlot()) == clistSlot) - { - extra->onClick(hContact); - break; - } - } + sid.pszName = "ChatActivity"; + sid.pszDescription = LPGEN("Chat Activity"); + sid.iDefaultIndex = -IDI_CHAT; + Skin_AddIcon(&sid); - return 0; + sid.pszName = "gender_male"; + sid.pszDescription = LPGEN("Male"); + sid.iDefaultIndex = -IDI_MALE; + Skin_AddIcon(&sid); + + sid.pszName = "gender_female"; + sid.pszDescription = LPGEN("Female"); + sid.iDefaultIndex = -IDI_FEMALE; + Skin_AddIcon(&sid); + + // Hooks + HookEvent(ME_SYSTEM_MODULESLOADED, &ModulesLoaded); + HookEvent(ME_SYSTEM_PRESHUTDOWN, &PreShutdown); + + HookEvent(ME_CLIST_EXTRA_LIST_REBUILD, &ClistExtraListRebuild); + HookEvent(ME_CLIST_EXTRA_IMAGE_APPLY, &ClistExtraImageApply); + HookEvent(ME_CLIST_EXTRA_CLICK, &ClistExtraClick); + + DefaultExtraIcons_Load(); +} + +void UnloadExtraIconsModule(void) +{ + for (size_t i=0; i < registeredExtraIcons.size(); i++) + delete registeredExtraIcons[i]; } diff --git a/src/modules/extraicons/extraicons.h b/src/modules/extraicons/extraicons.h index 21ad6e955f..2ee5982e9c 100644 --- a/src/modules/extraicons/extraicons.h +++ b/src/modules/extraicons/extraicons.h @@ -44,6 +44,11 @@ int ConvertToClistSlot(int slot); int Clist_SetExtraIcon(HANDLE hContact, int slot, HANDLE hImage); +HANDLE ExtraIcon_Add(HICON hIcon); + +void fnReloadExtraIcons(); +void fnSetAllExtraIcons(HWND hwndList,HANDLE hContact); + static inline BOOL IsEmpty(const char *str) { return str == NULL || str[0] == 0; diff --git a/src/modules/extraicons/options_ei.cpp b/src/modules/extraicons/options_ei.cpp index b23a4a4bed..36e05d4179 100644 --- a/src/modules/extraicons/options_ei.cpp +++ b/src/modules/extraicons/options_ei.cpp @@ -271,7 +271,7 @@ static HTREEITEM Tree_AddExtraIconGroup(HWND tree, vector &group, bool sele vector *ids = new vector ; tstring desc; int img = 0; - for (unsigned int i = 0; i < group.size(); ++i) { + for (unsigned int i = 0; i < group.size(); i++) { BaseExtraIcon *extra = registeredExtraIcons[group[i] - 1]; ids->push_back(extra->getID()); @@ -338,7 +338,7 @@ static void GroupSelectedItems(HWND tree) // Remove old - for (unsigned int i = 0; i < toRemove.size(); ++i) { + for (unsigned int i = 0; i < toRemove.size(); i++) { delete Tree_GetIDs(tree, toRemove[i]); TreeView_DeleteItem(tree, toRemove[i]); } @@ -443,7 +443,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.size(); i++) { ExtraIcon *extra = registeredExtraIcons[i]; HICON hIcon = Skin_GetIcon(extra->getDescIcon()); @@ -460,13 +460,13 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP } TreeView_SetImageList(tree, hImageList, TVSIL_NORMAL); - for (i = 0; i < extraIconsBySlot.size(); ++i) { + for (i = 0; i < extraIconsBySlot.size(); i++) { ExtraIcon *extra = extraIconsBySlot[i]; if (extra->getType() == EXTRAICON_TYPE_GROUP) { ExtraIconGroup *group = (ExtraIconGroup *) extra; vector ids; - for (unsigned int j = 0; j < group->items.size(); ++j) + for (unsigned int j = 0; j < group->items.size(); j++) ids.push_back(group->items[j]->getID()); Tree_AddExtraIconGroup(tree, ids, extra->isEnabled()); } @@ -496,7 +496,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP // Store old slots int *oldSlots = new int[registeredExtraIcons.size()]; int lastUsedSlot = -1; - for (i = 0; i < registeredExtraIcons.size(); ++i) { + for (i = 0; i < registeredExtraIcons.size(); i++) { if (extraIconsByHandle[i] == registeredExtraIcons[i]) oldSlots[i] = registeredExtraIcons[i]->getSlot(); else @@ -539,7 +539,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP ExtraIconGroup *group = new ExtraIconGroup(name); - for (i = 0; i < ids->size(); ++i) { + for (i = 0; i < ids->size(); i++) { BaseExtraIcon *extra = registeredExtraIcons[ids->at(i) - 1]; extra->setPosition(pos++); @@ -554,7 +554,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.size(); i++) { BaseExtraIcon *extra = registeredExtraIcons[i]; char setting[512]; @@ -567,14 +567,14 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP CallService(MS_DB_MODULE_DELETE, 0, (LPARAM) MODULE_NAME "Groups"); DBWriteContactSettingWord(NULL, MODULE_NAME "Groups", "Count", (WORD)groups.size()); - for (i = 0; i < groups.size(); ++i) { + for (i = 0; i < groups.size(); i++) { ExtraIconGroup *group = groups[i]; char setting[512]; mir_snprintf(setting, SIZEOF(setting), "%d_count", i); DBWriteContactSettingWord(NULL, MODULE_NAME "Groups", setting, (WORD)group->items.size()); - for (unsigned int j = 0; j < group->items.size(); ++j) { + for (unsigned int j = 0; j < group->items.size(); j++) { BaseExtraIcon *extra = group->items[j]; mir_snprintf(setting, SIZEOF(setting), "%d_%d", i, j); @@ -583,12 +583,12 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP } // Clean removed slots - for (int j = firstEmptySlot; j <= lastUsedSlot; ++j) + for (int j = firstEmptySlot; j <= lastUsedSlot; j++) RemoveExtraIcons(j); // Apply icons to new slots RebuildListsBasedOnGroups(groups); - for (i = 0; i < extraIconsBySlot.size(); ++i) { + for (i = 0; i < extraIconsBySlot.size(); i++) { ExtraIcon *extra = extraIconsBySlot[i]; if (extra->getType() != EXTRAICON_TYPE_GROUP) diff --git a/src/modules/extraicons/usedIcons.cpp b/src/modules/extraicons/usedIcons.cpp index 79ea375803..1c42104490 100644 --- a/src/modules/extraicons/usedIcons.cpp +++ b/src/modules/extraicons/usedIcons.cpp @@ -19,7 +19,7 @@ #include "..\..\core\commonheaders.h" -#include "m_cluiframes.h" +#include "extraicons.h" struct Icon { @@ -39,7 +39,7 @@ 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) @@ -60,7 +60,7 @@ static Icon * FindIcon(const char *icolibName) HICON hIcon = Skin_GetIcon(icon->name.c_str()); if (hIcon != NULL) { - icon->hImage = (HANDLE) CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM) hIcon, 0); + icon->hImage = ExtraIcon_Add(hIcon); Skin_ReleaseIcon(hIcon); } } @@ -82,7 +82,7 @@ HANDLE AddIcon(const char *icolibName) void RemoveIcon(const char *icolibName) { - for (unsigned int i = 0; i < usedIcons.size(); ++i) + for (unsigned int i = 0; i < usedIcons.size(); i++) { Icon *icon = &usedIcons[i]; @@ -103,6 +103,6 @@ void ResetIcons() { usedIcons.erase(std::remove_if(usedIcons.begin(), usedIcons.end(), NotUsedIcon), usedIcons.end()); - for (unsigned int i = 0; i < usedIcons.size(); ++i) + for (unsigned int i = 0; i < usedIcons.size(); i++) usedIcons[i].hImage = INVALID_HANDLE_VALUE; } -- cgit v1.2.3