summaryrefslogtreecommitdiff
path: root/src/modules/extraicons/extraicons.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-11-04 18:51:53 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-11-04 18:51:53 +0000
commitecb177cadbcff850a16c4b9e306beb15f61ac6f9 (patch)
treeda36e3107747a5f37dbd078197d584054057609f /src/modules/extraicons/extraicons.cpp
parent808f3b5e0fefeb560ce5393bf8311927d0927411 (diff)
kernel extraicons, part II
git-svn-id: http://svn.miranda-ng.org/main/trunk@2188 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/extraicons/extraicons.cpp')
-rw-r--r--src/modules/extraicons/extraicons.cpp384
1 files changed, 223 insertions, 161 deletions
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<ExtraIconGroup *> &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<ExtraIconGroup *> &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<ExtraIconGroup *> &groups)
}
}
- if (group->items.size() < 2)
- {
+ if (group->items.size() < 2) {
delete group;
continue;
}
@@ -243,11 +172,9 @@ static void LoadGroups(vector<ExtraIconGroup *> &groups)
static ExtraIconGroup * IsInGroup(vector<ExtraIconGroup *> &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<const ExtraIcon *, const ExtraIcon *,
void RebuildListsBasedOnGroups(vector<ExtraIconGroup *> &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<ExtraIconGroup *> &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<ExtraIconGroup *> &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];
}