2 * X11 system tray management
4 * Copyright (C) 2004 Mike Hearn, for CodeWeavers
5 * Copyright (C) 2005 Robert Shearman
6 * Copyright (C) 2008 Alexandre Julliard
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #define NONAMELESSUNION
44 #include "wine/list.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(systray);
49 /* an individual systray icon */
53 HICON image; /* the image to render */
54 HWND owner; /* the HWND passed in to the Shell_NotifyIcon call */
55 HWND window; /* the adaptor window */
56 BOOL layered; /* whether we are using a layered window */
57 HWND tooltip; /* Icon tooltip */
58 UINT state; /* state flags */
59 UINT id; /* the unique id given by the app */
60 UINT callback_message;
61 int display; /* display index, or -1 if hidden */
62 WCHAR tiptext[128]; /* tooltip text */
63 WCHAR info_text[256]; /* info balloon text */
64 WCHAR info_title[64]; /* info balloon title */
65 UINT info_flags; /* flags for info balloon */
66 UINT info_timeout; /* timeout for info balloon */
67 HICON info_icon; /* info balloon icon */
70 static struct list icon_list = LIST_INIT( icon_list );
72 static const WCHAR icon_classname[] = {'_','_','w','i','n','e','x','1','1','_','t','r','a','y','_','i','c','o','n',0};
73 static const WCHAR tray_classname[] = {'_','_','w','i','n','e','x','1','1','_','s','t','a','n','d','a','l','o','n','e','_','t','r','a','y',0};
75 static BOOL show_icon( struct tray_icon *icon );
76 static BOOL hide_icon( struct tray_icon *icon );
77 static BOOL delete_icon( struct tray_icon *icon );
79 #define SYSTEM_TRAY_REQUEST_DOCK 0
80 #define SYSTEM_TRAY_BEGIN_MESSAGE 1
81 #define SYSTEM_TRAY_CANCEL_MESSAGE 2
83 Atom systray_atom = 0;
85 #define MIN_DISPLAYED 8
88 #define VALID_WIN_TIMER 1
89 #define BALLOON_CREATE_TIMER 2
90 #define BALLOON_SHOW_TIMER 3
92 #define VALID_WIN_TIMEOUT 2000
93 #define BALLOON_CREATE_TIMEOUT 2000
94 #define BALLOON_SHOW_MIN_TIMEOUT 10000
95 #define BALLOON_SHOW_MAX_TIMEOUT 30000
97 static struct tray_icon *balloon_icon;
98 static HWND balloon_window;
99 static POINT balloon_pos;
101 /* stand-alone tray window */
102 static HWND standalone_tray;
103 static int icon_cx, icon_cy;
104 static unsigned int nb_displayed;
106 /* retrieves icon record by owner window and ID */
107 static struct tray_icon *get_icon(HWND owner, UINT id)
109 struct tray_icon *this;
111 LIST_FOR_EACH_ENTRY( this, &icon_list, struct tray_icon, entry )
112 if ((this->id == id) && (this->owner == owner)) return this;
116 static void init_common_controls(void)
118 static BOOL initialized = FALSE;
122 INITCOMMONCONTROLSEX init_tooltip;
124 init_tooltip.dwSize = sizeof(INITCOMMONCONTROLSEX);
125 init_tooltip.dwICC = ICC_TAB_CLASSES;
127 InitCommonControlsEx(&init_tooltip);
132 /* create tooltip window for icon */
133 static void create_tooltip(struct tray_icon *icon)
135 init_common_controls();
136 icon->tooltip = CreateWindowExW( WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL,
137 WS_POPUP | TTS_ALWAYSTIP,
138 CW_USEDEFAULT, CW_USEDEFAULT,
139 CW_USEDEFAULT, CW_USEDEFAULT,
140 icon->window, NULL, NULL, NULL);
144 ZeroMemory(&ti, sizeof(ti));
145 ti.cbSize = sizeof(TTTOOLINFOW);
146 ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
147 ti.hwnd = icon->window;
148 ti.uId = (UINT_PTR)icon->window;
149 ti.lpszText = icon->tiptext;
150 SendMessageW(icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
154 void update_systray_balloon_position(void)
159 if (!balloon_icon) return;
160 GetWindowRect( balloon_icon->window, &rect );
161 pos.x = (rect.left + rect.right) / 2;
162 pos.y = (rect.top + rect.bottom) / 2;
163 if (pos.x == balloon_pos.x && pos.y == balloon_pos.y) return; /* nothing changed */
165 SendMessageW( balloon_window, TTM_TRACKPOSITION, 0, MAKELONG( pos.x, pos.y ));
168 static void balloon_create_timer( struct tray_icon *icon )
172 init_common_controls();
173 balloon_window = CreateWindowExW( WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL,
174 WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
175 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
176 icon->window, NULL, NULL, NULL);
178 memset( &ti, 0, sizeof(ti) );
179 ti.cbSize = sizeof(TTTOOLINFOW);
180 ti.hwnd = icon->window;
181 ti.uId = (UINT_PTR)icon->window;
182 ti.uFlags = TTF_TRACK | TTF_IDISHWND;
183 ti.lpszText = icon->info_text;
184 SendMessageW( balloon_window, TTM_ADDTOOLW, 0, (LPARAM)&ti );
185 if ((icon->info_flags & NIIF_ICONMASK) == NIIF_USER)
186 SendMessageW( balloon_window, TTM_SETTITLEW, (WPARAM)icon->info_icon, (LPARAM)icon->info_title );
188 SendMessageW( balloon_window, TTM_SETTITLEW, icon->info_flags, (LPARAM)icon->info_title );
190 balloon_pos.x = balloon_pos.y = MAXLONG;
191 update_systray_balloon_position();
192 SendMessageW( balloon_window, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti );
193 KillTimer( icon->window, BALLOON_CREATE_TIMER );
194 SetTimer( icon->window, BALLOON_SHOW_TIMER, icon->info_timeout, NULL );
197 static BOOL show_balloon( struct tray_icon *icon )
199 if (standalone_tray && !show_systray) return FALSE; /* no systray window */
200 if (!icon->window) return FALSE; /* not displayed */
201 if (!icon->info_text[0]) return FALSE; /* no balloon */
203 SetTimer( icon->window, BALLOON_CREATE_TIMER, BALLOON_CREATE_TIMEOUT, NULL );
207 static void hide_balloon(void)
209 if (!balloon_icon) return;
212 KillTimer( balloon_icon->window, BALLOON_SHOW_TIMER );
213 DestroyWindow( balloon_window );
216 else KillTimer( balloon_icon->window, BALLOON_CREATE_TIMER );
220 static void show_next_balloon(void)
222 struct tray_icon *icon;
224 LIST_FOR_EACH_ENTRY( icon, &icon_list, struct tray_icon, entry )
225 if (show_balloon( icon )) break;
228 static void update_balloon( struct tray_icon *icon )
230 if (balloon_icon == icon)
233 show_balloon( icon );
235 else if (!balloon_icon)
237 if (!show_balloon( icon )) return;
239 if (!balloon_icon) show_next_balloon();
242 static void balloon_timer(void)
244 if (balloon_icon) balloon_icon->info_text[0] = 0; /* clear text now that balloon has been shown */
249 /* synchronize tooltip text with tooltip window */
250 static void update_tooltip_text(struct tray_icon *icon)
254 ZeroMemory(&ti, sizeof(ti));
255 ti.cbSize = sizeof(TTTOOLINFOW);
256 ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
257 ti.hwnd = icon->window;
258 ti.uId = (UINT_PTR)icon->window;
259 ti.lpszText = icon->tiptext;
261 SendMessageW(icon->tooltip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
264 /* get the size of the stand-alone tray window */
265 static SIZE get_window_size(void)
272 rect.right = icon_cx * max( nb_displayed, MIN_DISPLAYED );
273 rect.bottom = icon_cy;
274 AdjustWindowRect( &rect, WS_CAPTION, FALSE );
275 size.cx = rect.right - rect.left;
276 size.cy = rect.bottom - rect.top;
280 /* get the position of an icon in the stand-alone tray */
281 static POINT get_icon_pos( struct tray_icon *icon )
285 pos.x = icon_cx * icon->display;
290 /* window procedure for the standalone tray window */
291 static LRESULT WINAPI standalone_tray_wndproc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
296 update_systray_balloon_position();
299 ShowWindow( hwnd, SW_HIDE );
301 show_systray = FALSE;
307 return DefWindowProcW( hwnd, msg, wparam, lparam );
310 /* add an icon to the standalone tray window */
311 static void add_to_standalone_tray( struct tray_icon *icon )
316 if (!standalone_tray)
318 static const WCHAR winname[] = {'W','i','n','e',' ','S','y','s','t','e','m',' ','T','r','a','y',0};
320 size = get_window_size();
321 standalone_tray = CreateWindowExW( 0, tray_classname, winname, WS_CAPTION | WS_SYSMENU,
322 CW_USEDEFAULT, CW_USEDEFAULT, size.cx, size.cy, 0, 0, 0, 0 );
323 if (!standalone_tray) return;
326 icon->display = nb_displayed;
327 pos = get_icon_pos( icon );
328 icon->window = CreateWindowW( icon_classname, NULL, WS_CHILD | WS_VISIBLE,
329 pos.x, pos.y, icon_cx, icon_cy, standalone_tray, NULL, NULL, icon );
335 create_tooltip( icon );
338 size = get_window_size();
339 SetWindowPos( standalone_tray, 0, 0, 0, size.cx, size.cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
340 if (nb_displayed == 1 && show_systray) ShowWindow( standalone_tray, SW_SHOWNA );
341 TRACE( "added %u now %d icons\n", icon->id, nb_displayed );
344 /* remove an icon from the stand-alone tray */
345 static void remove_from_standalone_tray( struct tray_icon *icon )
347 struct tray_icon *ptr;
350 if (icon->display == -1) return;
352 LIST_FOR_EACH_ENTRY( ptr, &icon_list, struct tray_icon, entry )
354 if (ptr == icon) continue;
355 if (ptr->display < icon->display) continue;
357 pos = get_icon_pos( ptr );
358 SetWindowPos( ptr->window, 0, pos.x, pos.y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
361 if (!--nb_displayed) ShowWindow( standalone_tray, SW_HIDE );
362 TRACE( "removed %u now %d icons\n", icon->id, nb_displayed );
365 static void repaint_tray_icon( struct tray_icon *icon )
367 BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
368 int width = GetSystemMetrics( SM_CXSMICON );
369 int height = GetSystemMetrics( SM_CYSMICON );
377 void *color_bits, *mask_bits;
379 BOOL has_alpha = FALSE;
381 GetWindowRect( icon->window, &rc );
382 size.cx = rc.right - rc.left;
383 size.cy = rc.bottom - rc.top;
384 pos.x = (size.cx - width) / 2;
385 pos.y = (size.cy - height) / 2;
387 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[2] ));
389 info->bmiHeader.biSize = sizeof(info->bmiHeader);
390 info->bmiHeader.biWidth = size.cx;
391 info->bmiHeader.biHeight = size.cy;
392 info->bmiHeader.biBitCount = 32;
393 info->bmiHeader.biPlanes = 1;
394 info->bmiHeader.biCompression = BI_RGB;
396 hdc = CreateCompatibleDC( 0 );
397 if (!(dib = CreateDIBSection( 0, info, DIB_RGB_COLORS, &color_bits, NULL, 0 ))) goto done;
398 SelectObject( hdc, dib );
399 DrawIconEx( hdc, pos.x, pos.y, icon->image, width, height, 0, 0, DI_DEFAULTSIZE | DI_NORMAL );
401 /* check if the icon was drawn with an alpha channel */
402 for (i = 0, ptr = color_bits; i < size.cx * size.cy; i++)
403 if ((has_alpha = (ptr[i] & 0xff000000) != 0)) break;
407 unsigned int width_bytes = (size.cx + 31) / 32 * 4;
409 info->bmiHeader.biBitCount = 1;
410 info->bmiColors[0].rgbRed = 0;
411 info->bmiColors[0].rgbGreen = 0;
412 info->bmiColors[0].rgbBlue = 0;
413 info->bmiColors[0].rgbReserved = 0;
414 info->bmiColors[1].rgbRed = 0xff;
415 info->bmiColors[1].rgbGreen = 0xff;
416 info->bmiColors[1].rgbBlue = 0xff;
417 info->bmiColors[1].rgbReserved = 0;
419 if (!(mask = CreateDIBSection( 0, info, DIB_RGB_COLORS, &mask_bits, NULL, 0 ))) goto done;
420 memset( mask_bits, 0xff, width_bytes * size.cy );
421 SelectObject( hdc, mask );
422 DrawIconEx( hdc, pos.x, pos.y, icon->image, width, height, 0, 0, DI_DEFAULTSIZE | DI_MASK );
424 for (y = 0, ptr = color_bits; y < size.cy; y++)
425 for (x = 0; x < size.cx; x++, ptr++)
426 if (!((((BYTE *)mask_bits)[y * width_bytes + x / 8] << (x % 8)) & 0x80))
429 SelectObject( hdc, dib );
430 DeleteObject( mask );
433 UpdateLayeredWindow( icon->window, 0, NULL, NULL, hdc, NULL, 0, &blend, ULW_ALPHA );
435 if (hdc) DeleteDC( hdc );
436 if (dib) DeleteObject( dib );
439 /* window procedure for the individual tray icon window */
440 static LRESULT WINAPI tray_icon_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
442 struct tray_icon *icon = NULL;
445 TRACE("hwnd=%p, msg=0x%x\n", hwnd, msg);
447 /* set the icon data for the window from the data passed into CreateWindow */
448 if (msg == WM_NCCREATE)
449 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LPARAM)((const CREATESTRUCTW *)lparam)->lpCreateParams);
451 icon = (struct tray_icon *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
456 SetTimer( hwnd, VALID_WIN_TIMER, VALID_WIN_TIMEOUT, NULL );
460 if (icon->window && icon->layered) repaint_tray_icon( icon );
468 int cx = GetSystemMetrics( SM_CXSMICON );
469 int cy = GetSystemMetrics( SM_CYSMICON );
471 hdc = BeginPaint(hwnd, &ps);
472 GetClientRect(hwnd, &rc);
473 TRACE("painting rect %s\n", wine_dbgstr_rect(&rc));
474 DrawIconEx( hdc, (rc.left + rc.right - cx) / 2, (rc.top + rc.bottom - cy) / 2,
475 icon->image, cx, cy, 0, 0, DI_DEFAULTSIZE|DI_NORMAL );
487 case WM_LBUTTONDBLCLK:
488 case WM_RBUTTONDBLCLK:
489 case WM_MBUTTONDBLCLK:
490 /* notify the owner hwnd of the message */
491 TRACE("relaying 0x%x\n", msg);
492 ret = PostMessageW(icon->owner, icon->callback_message, icon->id, msg);
493 if (!ret && (GetLastError() == ERROR_INVALID_WINDOW_HANDLE))
495 WARN( "application window was destroyed, removing icon %u\n", icon->id );
500 case WM_WINDOWPOSCHANGED:
501 update_systray_balloon_position();
507 case VALID_WIN_TIMER:
508 if (!IsWindow( icon->owner )) delete_icon( icon );
510 case BALLOON_CREATE_TIMER:
511 balloon_create_timer( icon );
513 case BALLOON_SHOW_TIMER:
520 if (icon->display == -1)
522 TRACE( "icon %u no longer embedded\n", icon->id );
524 add_to_standalone_tray( icon );
528 return DefWindowProcW( hwnd, msg, wparam, lparam );
531 /* find the X11 window owner the system tray selection */
532 static Window get_systray_selection_owner( Display *display )
534 return XGetSelectionOwner( display, systray_atom );
537 static void get_systray_visual_info( Display *display, Window systray_window, XVisualInfo *info )
539 XVisualInfo *list, template;
543 unsigned long count, remaining;
545 *info = default_visual;
546 if (XGetWindowProperty( display, systray_window, x11drv_atom(_NET_SYSTEM_TRAY_VISUAL), 0,
547 65536/sizeof(CARD32), False, XA_VISUALID, &type, &format, &count,
548 &remaining, (unsigned char **)&visual_id ))
551 if (type == XA_VISUALID && format == 32)
553 template.visualid = visual_id[0];
554 if ((list = XGetVisualInfo( display, VisualIDMask, &template, &num )))
557 TRACE( "systray window %lx got visual %lx\n", systray_window, info->visualid );
564 static BOOL init_systray(void)
566 static BOOL init_done;
570 if (root_window != DefaultRootWindow( gdi_display )) return FALSE;
571 if (init_done) return TRUE;
573 icon_cx = GetSystemMetrics( SM_CXSMICON ) + 2 * ICON_BORDER;
574 icon_cy = GetSystemMetrics( SM_CYSMICON ) + 2 * ICON_BORDER;
576 memset( &class, 0, sizeof(class) );
577 class.cbSize = sizeof(class);
578 class.lpfnWndProc = tray_icon_wndproc;
579 class.hIcon = LoadIconW(0, (LPCWSTR)IDI_WINLOGO);
580 class.hCursor = LoadCursorW( 0, (LPCWSTR)IDC_ARROW );
581 class.lpszClassName = icon_classname;
582 class.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
584 if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
586 ERR( "Could not register icon tray window class\n" );
590 class.lpfnWndProc = standalone_tray_wndproc;
591 class.hbrBackground = (HBRUSH)COLOR_WINDOW;
592 class.lpszClassName = tray_classname;
593 class.style = CS_DBLCLKS;
595 if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
597 ERR( "Could not register standalone tray window class\n" );
601 display = thread_init_display();
602 if (DefaultScreen( display ) == 0)
603 systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0);
606 char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
607 sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) );
608 systray_atom = XInternAtom( display, systray_buffer, False );
610 XSelectInput( display, root_window, StructureNotifyMask );
616 /* dock the given icon with the NETWM system tray */
617 static void dock_systray_icon( Display *display, struct tray_icon *icon, Window systray_window )
621 XSetWindowAttributes attr;
623 struct x11drv_win_data *data;
625 get_systray_visual_info( display, systray_window, &visual );
627 icon->layered = (visual.visualid != default_visual.visualid);
628 icon->window = CreateWindowExW( icon->layered ? WS_EX_LAYERED : 0,
629 icon_classname, NULL, WS_CLIPSIBLINGS | WS_POPUP,
630 CW_USEDEFAULT, CW_USEDEFAULT, icon_cx, icon_cy,
631 NULL, NULL, NULL, icon );
633 if (!(data = get_win_data( icon->window ))) return;
634 if (icon->layered) set_window_visual( data, &visual );
635 make_window_embedded( data );
636 window = data->whole_window;
637 release_win_data( data );
639 create_tooltip( icon );
640 ShowWindow( icon->window, SW_SHOWNA );
642 TRACE( "icon window %p/%lx\n", icon->window, window );
644 /* send the docking request message */
645 ev.xclient.type = ClientMessage;
646 ev.xclient.window = systray_window;
647 ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE );
648 ev.xclient.format = 32;
649 ev.xclient.data.l[0] = CurrentTime;
650 ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
651 ev.xclient.data.l[2] = window;
652 ev.xclient.data.l[3] = 0;
653 ev.xclient.data.l[4] = 0;
654 XSendEvent( display, systray_window, False, NoEventMask, &ev );
658 attr.background_pixmap = ParentRelative;
659 attr.bit_gravity = ForgetGravity;
660 XChangeWindowAttributes( display, window, CWBackPixmap | CWBitGravity, &attr );
662 else repaint_tray_icon( icon );
665 /* dock systray windows again with the new owner */
666 void change_systray_owner( Display *display, Window systray_window )
668 struct tray_icon *icon;
670 TRACE( "new owner %lx\n", systray_window );
671 LIST_FOR_EACH_ENTRY( icon, &icon_list, struct tray_icon, entry )
673 if (icon->display == -1) continue;
675 dock_systray_icon( display, icon, systray_window );
679 /* hide a tray icon */
680 static BOOL hide_icon( struct tray_icon *icon )
682 struct x11drv_win_data *data;
684 TRACE( "id=0x%x, hwnd=%p\n", icon->id, icon->owner );
686 if (!icon->window) return TRUE; /* already hidden */
688 /* make sure we don't try to unmap it, it confuses some systray docks */
689 if ((data = get_win_data( icon->window )))
691 if (data->embedded) data->mapped = FALSE;
692 release_win_data( data );
694 DestroyWindow(icon->window);
695 DestroyWindow(icon->tooltip);
697 icon->layered = FALSE;
699 remove_from_standalone_tray( icon );
700 update_balloon( icon );
704 /* make the icon visible */
705 static BOOL show_icon( struct tray_icon *icon )
707 Window systray_window;
708 Display *display = thread_init_display();
710 TRACE( "id=0x%x, hwnd=%p\n", icon->id, icon->owner );
712 if (icon->window) return TRUE; /* already shown */
714 if ((systray_window = get_systray_selection_owner( display )))
715 dock_systray_icon( display, icon, systray_window );
717 add_to_standalone_tray( icon );
719 update_balloon( icon );
723 /* Modifies an existing icon record */
724 static BOOL modify_icon( struct tray_icon *icon, NOTIFYICONDATAW *nid )
726 TRACE( "id=0x%x hwnd=%p flags=%x\n", nid->uID, nid->hWnd, nid->uFlags );
728 if (nid->uFlags & NIF_STATE)
730 icon->state = (icon->state & ~nid->dwStateMask) | (nid->dwState & nid->dwStateMask);
733 if (nid->uFlags & NIF_ICON)
735 if (icon->image) DestroyIcon(icon->image);
736 icon->image = CopyIcon(nid->hIcon);
739 if (icon->display != -1) InvalidateRect( icon->window, NULL, TRUE );
740 else if (icon->layered) repaint_tray_icon( icon );
743 Window win = X11DRV_get_whole_window( icon->window );
744 if (win) XClearArea( gdi_display, win, 0, 0, 0, 0, True );
749 if (nid->uFlags & NIF_MESSAGE)
751 icon->callback_message = nid->uCallbackMessage;
753 if (nid->uFlags & NIF_TIP)
755 lstrcpynW(icon->tiptext, nid->szTip, sizeof(icon->tiptext)/sizeof(WCHAR));
756 if (icon->tooltip) update_tooltip_text(icon);
758 if (nid->uFlags & NIF_INFO && nid->cbSize >= NOTIFYICONDATAA_V2_SIZE)
760 lstrcpynW( icon->info_text, nid->szInfo, sizeof(icon->info_text)/sizeof(WCHAR) );
761 lstrcpynW( icon->info_title, nid->szInfoTitle, sizeof(icon->info_title)/sizeof(WCHAR) );
762 icon->info_flags = nid->dwInfoFlags;
763 icon->info_timeout = max(min(nid->u.uTimeout, BALLOON_SHOW_MAX_TIMEOUT), BALLOON_SHOW_MIN_TIMEOUT);
764 icon->info_icon = nid->hBalloonIcon;
765 update_balloon( icon );
767 if (icon->state & NIS_HIDDEN) hide_icon( icon );
768 else show_icon( icon );
772 /* Adds a new icon record to the list */
773 static BOOL add_icon(NOTIFYICONDATAW *nid)
775 struct tray_icon *icon;
777 TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
779 if ((icon = get_icon(nid->hWnd, nid->uID)))
781 WARN("duplicate tray icon add, buggy app?\n");
785 if (!(icon = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*icon))))
787 ERR("out of memory\n");
791 ZeroMemory(icon, sizeof(struct tray_icon));
793 icon->owner = nid->hWnd;
796 list_add_tail(&icon_list, &icon->entry);
798 return modify_icon( icon, nid );
801 /* delete tray icon window and icon structure */
802 static BOOL delete_icon( struct tray_icon *icon )
805 list_remove( &icon->entry );
806 DestroyIcon( icon->image );
807 HeapFree( GetProcessHeap(), 0, icon );
812 /***********************************************************************
813 * wine_notify_icon (X11DRV.@)
815 * Driver-side implementation of Shell_NotifyIcon.
817 int CDECL wine_notify_icon( DWORD msg, NOTIFYICONDATAW *data )
820 struct tray_icon *icon;
825 if (!init_systray()) return -1; /* fall back to default handling */
826 ret = add_icon( data );
829 if ((icon = get_icon( data->hWnd, data->uID ))) ret = delete_icon( icon );
832 if ((icon = get_icon( data->hWnd, data->uID ))) ret = modify_icon( icon, data );
835 FIXME( "unhandled tray message: %u\n", msg );