James Liggett : explorer: Add support for tooltips for system tray
icons.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Sep 11 06:05:06 CDT 2006
Module: wine
Branch: master
Commit: 70cb31e4e6e6ab6e37dabc54b23d6ae4d31c0be3
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=70cb31e4e6e6ab6e37dabc54b23d6ae4d31c0be3
Author: James Liggett <jrliggett at cox.net>
Date: Wed Aug 30 18:42:49 2006 -0700
explorer: Add support for tooltips for system tray icons.
Based on the original systray implementation by Kai Morich <kai.morich at bigfoot.de>.
---
programs/explorer/Makefile.in | 3 +-
programs/explorer/systray.c | 55 ++++++++++++++++++++++++++++++++++++++---
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/programs/explorer/Makefile.in b/programs/explorer/Makefile.in
index 740611a..e386c2e 100644
--- a/programs/explorer/Makefile.in
+++ b/programs/explorer/Makefile.in
@@ -4,7 +4,8 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = explorer.exe
APPMODE = -mwindows
-IMPORTS = user32 gdi32 advapi32 kernel32 ntdll
+IMPORTS = user32 gdi32 advapi32 kernel32 ntdll
+DELAYIMPORTS = comctl32
EXTRADEFS = @HALINCL@
C_SRCS = \
diff --git a/programs/explorer/systray.c b/programs/explorer/systray.c
index 70d29bf..7fc66fd 100644
--- a/programs/explorer/systray.c
+++ b/programs/explorer/systray.c
@@ -33,6 +33,7 @@ #include <assert.h>
#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,26 @@ 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;
+
+ ti.cbSize = sizeof(TTTOOLINFOW);
+ ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
+ ti.hwnd = icon->window;
+ ti.hinst = 0;
+ ti.uId = (UINT_PTR)icon->window;
+ ti.lpszText = szTip;
+ 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,13 +207,18 @@ 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;
static const WCHAR adaptor_windowname[] = /* Wine System Tray Adaptor */ {'W','i','n','e',' ','S','y','s','t','e','m',' ','T','r','a','y',' ','A','d','a','p','t','o','r',0};
+ static BOOL tooltps_initialized = FALSE;
WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
@@ -230,9 +256,29 @@ static void add_icon(const NOTIFYICONDAT
if (!hide_systray)
ShowWindow(icon->window, SW_SHOWNA);
+ /* create icon tooltip */
+
+ /* Register tooltip classes if this is the first icon */
+ if (!tooltps_initialized)
+ {
+ INITCOMMONCONTROLSEX init_tooltip;
+
+ init_tooltip.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ init_tooltip.dwICC = ICC_TAB_CLASSES;
+
+ InitCommonControlsEx(&init_tooltip);
+ tooltps_initialized = TRUE;
+ }
+
+ icon->tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
+ WS_POPUP | 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 +293,7 @@ static void delete_icon(const NOTIFYICON
return;
}
+ DestroyWindow(icon->tooltip);
DestroyWindow(icon->window);
}
@@ -304,7 +351,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);
More information about the wine-cvs
mailing list