diff options
author | George Hazan <george.hazan@gmail.com> | 2013-04-11 07:08:40 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-04-11 07:08:40 +0000 |
commit | bd820972afe24409e6b570adbc45f5dc0fa2385d (patch) | |
tree | e600bf39409083219c7928e10ec2b61002529641 /src/core/stdmsg | |
parent | 6029165c364f93a84ab7e98ef71d3a711b0f588c (diff) |
SRMM icons to be unloaded automatically
git-svn-id: http://svn.miranda-ng.org/main/trunk@4418 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/core/stdmsg')
-rw-r--r-- | src/core/stdmsg/src/statusicon.cpp | 222 |
1 files changed, 47 insertions, 175 deletions
diff --git a/src/core/stdmsg/src/statusicon.cpp b/src/core/stdmsg/src/statusicon.cpp index 6dc1017b8f..68ad9d25d5 100644 --- a/src/core/stdmsg/src/statusicon.cpp +++ b/src/core/stdmsg/src/statusicon.cpp @@ -22,202 +22,74 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
#include "statusicon.h"
-struct StatusIconListNode {
- StatusIconData sid;
- struct StatusIconListNode *next;
-};
-
HANDLE hHookIconPressedEvt;
-struct StatusIconListNode *status_icon_list = 0;
-int status_icon_list_size = 0;
-
-INT_PTR AddStatusIcon(WPARAM wParam, LPARAM lParam) {
- StatusIconData *sid = (StatusIconData *)lParam;
- struct StatusIconListNode *siln = (struct StatusIconListNode *)mir_calloc(sizeof(struct StatusIconListNode));
-
- siln->sid.cbSize = sid->cbSize;
- siln->sid.szModule = mir_strdup(sid->szModule);
- siln->sid.dwId = sid->dwId;
- siln->sid.hIcon = sid->hIcon;
- siln->sid.hIconDisabled = sid->hIconDisabled;
- siln->sid.flags = sid->flags;
- if(sid->szTooltip) siln->sid.szTooltip = mir_strdup(sid->szTooltip);
- else siln->sid.szTooltip = 0;
-
- siln->next = status_icon_list;
- status_icon_list = siln;
- status_icon_list_size++;
-
- WindowList_Broadcast(g_dat.hMessageWindowList, DM_STATUSICONCHANGE, 0, 0);
- return 0;
-}
-
-INT_PTR RemoveStatusIcon(WPARAM wParam, LPARAM lParam) {
- StatusIconData *sid = (StatusIconData *)lParam;
- struct StatusIconListNode *current = status_icon_list, *prev = 0;
-
- while(current) {
- if(strcmp(current->sid.szModule, sid->szModule) == 0 && current->sid.dwId == sid->dwId) {
- if(prev) prev->next = current->next;
- else status_icon_list = current->next;
-
- status_icon_list_size--;
-
- mir_free(current->sid.szModule);
- DestroyIcon(current->sid.hIcon);
- if(current->sid.hIconDisabled) DestroyIcon(current->sid.hIconDisabled);
- mir_free(current->sid.szTooltip);
- mir_free(current);
- WindowList_Broadcast(g_dat.hMessageWindowList, DM_STATUSICONCHANGE, 0, 0);
- return 0;
- }
-
- prev = current;
- current = current->next;
- }
-
- return 1;
-}
-
-void RemoveAllStatusIcons(void) {
- struct StatusIconListNode *current;
-
- while(status_icon_list) {
- current = status_icon_list;
- status_icon_list = status_icon_list->next;
- status_icon_list_size--;
-
- mir_free(current->sid.szModule);
- DestroyIcon(current->sid.hIcon);
- if(current->sid.hIconDisabled) DestroyIcon(current->sid.hIconDisabled);
- if(current->sid.szTooltip) mir_free(current->sid.szTooltip);
- mir_free(current);
- }
- WindowList_Broadcast(g_dat.hMessageWindowList, DM_STATUSICONCHANGE, 0, 0);
-}
-
-INT_PTR ModifyStatusIcon(WPARAM wParam, LPARAM lParam) {
+static int OnSrmmIconChanged(WPARAM wParam, LPARAM)
+{
HANDLE hContact = (HANDLE)wParam;
-
- StatusIconData *sid = (StatusIconData *)lParam;
- struct StatusIconListNode *current = status_icon_list, *prev = 0;
-
- while(current) {
- if(strcmp(current->sid.szModule, sid->szModule) == 0 && current->sid.dwId == sid->dwId) {
- if (!hContact) {
- current->sid.flags = sid->flags;
- if(sid->hIcon) {
- DestroyIcon(current->sid.hIcon);
- current->sid.hIcon = sid->hIcon;
- }
- if(sid->hIconDisabled) {
- DestroyIcon(current->sid.hIconDisabled);
- current->sid.hIconDisabled = sid->hIconDisabled;
- }
- if(sid->szTooltip) {
- mir_free(current->sid.szTooltip);
- current->sid.szTooltip = mir_strdup(sid->szTooltip);
- }
-
- WindowList_Broadcast(g_dat.hMessageWindowList, DM_STATUSICONCHANGE, 0, 0);
- } else {
- char buff[256];
- HWND hwnd;
- sprintf(buff, "SRMMStatusIconFlags%d", sid->dwId);
- db_set_b(hContact, sid->szModule, buff, (BYTE)sid->flags);
- if (hwnd = WindowList_Find(g_dat.hMessageWindowList, hContact)) {
- PostMessage(hwnd, DM_STATUSICONCHANGE, 0, 0);
- }
- }
- return 0;
- }
-
- current = current->next;
+ if (hContact == NULL)
+ WindowList_Broadcast(g_dat.hMessageWindowList, DM_STATUSICONCHANGE, 0, 0);
+ else {
+ HWND hwnd = WindowList_Find(g_dat.hMessageWindowList, hContact);
+ if (hwnd != NULL)
+ PostMessage(GetParent(hwnd), DM_STATUSICONCHANGE, 0, 0);
}
-
- return 1;
+ return 0;
}
-void DrawStatusIcons(HANDLE hContact, HDC hDC, RECT r, int gap) {
- struct StatusIconListNode *current = status_icon_list;
+void DrawStatusIcons(HANDLE hContact, HDC hDC, RECT r, int gap)
+{
HICON hIcon;
- char buff[256];
- int flags;
int x = r.left;
- while(current && x < r.right) {
- sprintf(buff, "SRMMStatusIconFlags%d", current->sid.dwId);
- flags = db_get_b(hContact, current->sid.szModule, buff, current->sid.flags);
- if (!(flags & MBF_HIDDEN)) {
- if ((flags & MBF_DISABLED) && current->sid.hIconDisabled) hIcon = current->sid.hIconDisabled;
- else hIcon = current->sid.hIcon;
-
- SetBkMode(hDC, TRANSPARENT);
- DrawIconEx(hDC, x, (r.top + r.bottom - GetSystemMetrics(SM_CYSMICON)) >> 1, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);
-
- x += GetSystemMetrics(SM_CYSMICON) + gap;
- }
- current = current->next;
- }
-}
-void CheckIconClick(HANDLE hContact, HWND hwndFrom, POINT pt, RECT r, int gap, int click_flags) {
- StatusIconClickData sicd;
- struct StatusIconListNode *current = status_icon_list;
- int iconNum = (pt.x - r.left) / (GetSystemMetrics(SM_CXSMICON) + gap);
- char buff[256];
- int flags;
-
- while(current && iconNum >= 0) {
- sprintf(buff, "SRMMStatusIconFlags%d", current->sid.dwId);
- flags = db_get_b(hContact, current->sid.szModule, buff, current->sid.flags);
- if (!(flags & MBF_HIDDEN)) iconNum--;
- if(iconNum >= 0)
- current = current->next;
- }
+ StatusIconData *sid;
+ int nIcon = 0;
+ while ((sid = (StatusIconData*)CallService(MS_MSG_GETNTHICON, (WPARAM)hContact, nIcon++)) != NULL && x < r.right) {
+ if ((sid->flags & MBF_DISABLED) && sid->hIconDisabled) hIcon = sid->hIconDisabled;
+ else hIcon = sid->hIcon;
- if(current) {
- sicd.cbSize = sizeof(StatusIconClickData);
- ClientToScreen(hwndFrom, &pt);
- sicd.clickLocation = pt;
- sicd.dwId = current->sid.dwId;
- sicd.szModule = current->sid.szModule;
- sicd.flags = click_flags;
+ SetBkMode(hDC, TRANSPARENT);
+ DrawIconEx(hDC, x, (r.top + r.bottom - GetSystemMetrics(SM_CYSMICON)) >> 1, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);
- NotifyEventHooks(hHookIconPressedEvt, (WPARAM)hContact, (LPARAM)&sicd);
+ x += GetSystemMetrics(SM_CYSMICON) + gap;
}
}
+void CheckIconClick(HANDLE hContact, HWND hwndFrom, POINT pt, RECT r, int gap, int click_flags)
+{
+ int iconNum = (pt.x - r.left) / (GetSystemMetrics(SM_CXSMICON) + gap);
+ StatusIconData *sid = (StatusIconData*)CallService(MS_MSG_GETNTHICON, (WPARAM)hContact, iconNum);
+ if (sid == NULL)
+ return;
+
+ StatusIconClickData sicd = { sizeof(sicd) };
+ ClientToScreen(hwndFrom, &pt);
+ sicd.clickLocation = pt;
+ sicd.dwId = sid->dwId;
+ sicd.szModule = sid->szModule;
+ sicd.flags = click_flags;
+
+ NotifyEventHooks(hHookIconPressedEvt, (WPARAM)hContact, (LPARAM)&sicd);
+}
+
HANDLE hServiceIcon[3];
-int InitStatusIcons() {
- hServiceIcon[0] = CreateServiceFunction(MS_MSG_ADDICON, AddStatusIcon);
- hServiceIcon[1] = CreateServiceFunction(MS_MSG_REMOVEICON, RemoveStatusIcon);
- hServiceIcon[2] = CreateServiceFunction(MS_MSG_MODIFYICON, ModifyStatusIcon);
- hHookIconPressedEvt = CreateHookableEvent(ME_MSG_ICONPRESSED);
+int InitStatusIcons()
+{
+ hHookIconPressedEvt = CreateHookableEvent(ME_MSG_ICONPRESSED);
return 0;
}
-int DeinitStatusIcons() {
- int i;
+int DeinitStatusIcons()
+{
DestroyHookableEvent(hHookIconPressedEvt);
- for(i = 0; i < 3; i++) DestroyServiceFunction(hServiceIcon[i]);
- RemoveAllStatusIcons();
return 0;
}
-int GetStatusIconsCount(HANDLE hContact) {
- char buff[256];
- int count = 0;
- int flags;
- struct StatusIconListNode *current = status_icon_list;
- while(current) {
- sprintf(buff, "SRMMStatusIconFlags%d", (int)current->sid.dwId);
- flags = db_get_b(hContact, current->sid.szModule, buff, current->sid.flags);
- if (!(flags & MBF_HIDDEN)) {
- count ++;
- }
- current = current->next;
- }
- return count;
+int GetStatusIconsCount(HANDLE hContact)
+{
+ int nIcon = 0;
+ while ( CallService(MS_MSG_GETNTHICON, (WPARAM)hContact, nIcon) != NULL)
+ nIcon++;
+ return nIcon;
}
|