[TRY 2] Add support for tooltips for system tray icons

James Liggett jrliggett at cox.net
Sun Aug 27 16:09:02 CDT 2006


TRY 2: Integrate suggestions from Oleg Krylov and fix a tooltip rectangle bug.

ChangeLog:
Add support for tooltips for system tray icons.

James Liggett

---

 programs/explorer/Makefile.in |    2 +
 programs/explorer/systray.c   |   55 ++++++++++++++++++++++++++++++++++++-----
 2 files changed, 49 insertions(+), 8 deletions(-)

afcb31da459254f91bf485e2165c5413cae4835d
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..31a64fa 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,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;  /* avoid a build warning */
+    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,9 +207,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 +252,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_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 +280,7 @@ static void delete_icon(const NOTIFYICON
         return;
     }
 
+    DestroyWindow(icon->tooltip);
     DestroyWindow(icon->window);
 }
 
@@ -304,7 +338,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 +390,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 +430,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