Add support for tooltips for system tray icons
James Liggett
jrliggett at cox.net
Fri Aug 25 00:44:26 CDT 2006
Add support for tooltips for system tray icons.
This patch partially based on the original systray implementation by Kai Morich <kai.morich at bigfoot.de>.
---
programs/explorer/Makefile.in | 2 +
programs/explorer/systray.c | 62 ++++++++++++++++++++++++++++++++++++-----
2 files changed, 56 insertions(+), 8 deletions(-)
f49a0fd11ae78b68f8978f8f7b423c2c5f541e81
diff --git a/programs/explorer/Makefile.in b/programs/explorer/Makefile.in
index 740611a..db7d6fc 100644
--- a/programs/explorer/Makefile.in
+++ b/programs/explorer/Makefile.in
@@ -4,7 +4,7 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = explorer.exe
APPMODE = -mwindows
-IMPORTS = user32 gdi32 advapi32 kernel32 ntdll
+IMPORTS = user32 gdi32 advapi32 comctl32 kernel32 ntdll
EXTRADEFS = @HALINCL@
C_SRCS = \
diff --git a/programs/explorer/systray.c b/programs/explorer/systray.c
index 70d29bf..8a26ca9 100644
--- a/programs/explorer/systray.c
+++ b/programs/explorer/systray.c
@@ -33,6 +33,7 @@
#define UNICODE
#define _WIN32_IE 0x500
#include <windows.h>
+#include <commctrl.h>
#include <wine/debug.h>
#include <wine/list.h>
@@ -60,6 +61,7 @@ struct icon
HICON image; /* the image to render */
HWND owner; /* the HWND passed in to the Shell_NotifyIcon call */
HWND window; /* the adaptor window */
+ HWND tooltip; /* Icon tooltip */
UINT id; /* the unique id given by the app */
UINT callback_message;
};
@@ -160,7 +162,33 @@ static struct icon *get_icon(HWND owner,
return NULL;
}
-static void modify_icon(const NOTIFYICONDATAW *nid)
+static void set_tooltip(struct icon *icon, WCHAR *szTip, BOOL modify)
+{
+ TTTOOLINFOW ti;
+ RECT window_rect;
+
+ GetWindowRect(icon->window, &window_rect);
+
+ ti.cbSize = sizeof(TTTOOLINFOW);
+ ti.uFlags = TTF_SUBCLASS;
+ ti.hwnd = icon->window;
+ ti.hinst = 0;
+ ti.uId = 0;
+ ti.lpszText = szTip;
+ ti.rect.left = 0;
+ ti.rect.top = 0;
+ ti.rect.right = window_rect.right - window_rect.left;
+ ti.rect.bottom = window_rect.bottom - window_rect.top;
+ ti.lParam = 0;
+ ti.lpReserved = NULL;
+
+ if (modify)
+ SendMessageW(icon->tooltip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
+ else
+ SendMessageW(icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
+}
+
+static void modify_icon(NOTIFYICONDATAW *nid, BOOL modify_tooltip)
{
struct icon *icon;
@@ -186,9 +214,14 @@ static void modify_icon(const NOTIFYICON
{
icon->callback_message = nid->uCallbackMessage;
}
+
+ if (nid->uFlags & NIF_TIP)
+ {
+ set_tooltip(icon, nid->szTip, modify_tooltip);
+ }
}
-static void add_icon(const NOTIFYICONDATAW *nid)
+static void add_icon(NOTIFYICONDATAW *nid)
{
RECT rect;
struct icon *icon;
@@ -226,13 +259,20 @@ static void add_icon(const NOTIFYICONDAT
rect.right - rect.left,
rect.bottom - rect.top,
NULL, NULL, NULL, icon);
-
+
if (!hide_systray)
- ShowWindow(icon->window, SW_SHOWNA);
+ ShowWindow(icon->window, SW_SHOWNA);
+
+ /* create icon tooltip */
+ icon->tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
+ WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ icon->window, NULL, NULL, NULL);
list_add_tail(&tray.icons, &icon->entry);
- modify_icon(nid);
+ modify_icon(nid, FALSE);
}
static void delete_icon(const NOTIFYICONDATAW *nid)
@@ -247,6 +287,7 @@ static void delete_icon(const NOTIFYICON
return;
}
+ DestroyWindow(icon->tooltip);
DestroyWindow(icon->window);
}
@@ -304,7 +345,7 @@ static void handle_incoming(HWND hwndSou
delete_icon(&nid);
break;
case NIM_MODIFY:
- modify_icon(&nid);
+ modify_icon(&nid, TRUE);
break;
default:
WINE_FIXME("unhandled tray message: %ld\n", cds->dwData);
@@ -356,7 +397,8 @@ void initialize_systray(void)
static const WCHAR classname[] = /* Shell_TrayWnd */ {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
static const WCHAR winname[] = /* Wine Systray Listener */
{'W','i','n','e',' ','S','y','s','t','r','a','y',' ','L','i','s','t','e','n','e','r',0};
-
+ INITCOMMONCONTROLSEX init_tooltip;
+
WINE_TRACE("initiaizing\n");
hide_systray = is_systray_hidden();
@@ -395,6 +437,12 @@ void initialize_systray(void)
WINE_ERR("Could not register adaptor class\n");
return;
}
+
+ /* Initialize tooltip classes */
+ init_tooltip.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ init_tooltip.dwICC = ICC_TAB_CLASSES;
+ InitCommonControlsEx(&init_tooltip);
+
tray.window = CreateWindow(classname, winname, WS_OVERLAPPED,
CW_USEDEFAULT, CW_USEDEFAULT,
--
1.2.4
More information about the wine-patches
mailing list