Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/programs/explorer/systray.c
4389 views
1
/*
2
* Copyright (C) 2004 Mike Hearn, for CodeWeavers
3
* Copyright (C) 2005 Robert Shearman
4
* Copyright (C) 2008 Alexandre Julliard
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19
*/
20
21
#include <assert.h>
22
23
#include <windows.h>
24
#include <ntuser.h>
25
#include <commctrl.h>
26
#include <shellapi.h>
27
28
#include <wine/debug.h>
29
#include <wine/list.h>
30
31
#include "explorer_private.h"
32
#include "resource.h"
33
34
WINE_DEFAULT_DEBUG_CHANNEL(systray);
35
36
#define TRAY_MINIMIZE_ALL 419
37
#define TRAY_MINIMIZE_ALL_UNDO 416
38
39
struct notify_data_icon
40
{
41
/* data for the icon bitmap */
42
UINT width;
43
UINT height;
44
UINT planes;
45
UINT bpp;
46
};
47
48
struct notify_data /* platform-independent format for NOTIFYICONDATA */
49
{
50
LONG hWnd;
51
UINT uID;
52
UINT uFlags;
53
UINT uCallbackMessage;
54
struct notify_data_icon icon_info; /* systray icon bitmap info */
55
WCHAR szTip[128];
56
DWORD dwState;
57
DWORD dwStateMask;
58
WCHAR szInfo[256];
59
union {
60
UINT uTimeout;
61
UINT uVersion;
62
} u;
63
WCHAR szInfoTitle[64];
64
DWORD dwInfoFlags;
65
GUID guidItem;
66
struct notify_data_icon balloon_icon_info; /* balloon icon bitmap info */
67
BYTE icon_data[];
68
};
69
70
#define ICON_DISPLAY_HIDDEN -1
71
#define ICON_DISPLAY_DOCKED -2
72
73
/* an individual systray icon, unpacked from the NOTIFYICONDATA and always in unicode */
74
struct icon
75
{
76
struct list entry;
77
HICON image; /* the image to render */
78
HWND owner; /* the HWND passed in to the Shell_NotifyIcon call */
79
HWND window; /* the adaptor window */
80
BOOL layered; /* whether we are using a layered window */
81
HWND tooltip; /* Icon tooltip */
82
UINT state; /* state flags */
83
UINT id; /* the unique id given by the app */
84
UINT callback_message;
85
int display; /* index in display list, or -1 if hidden */
86
WCHAR tiptext[128]; /* Tooltip text. If empty => tooltip disabled */
87
WCHAR info_text[256]; /* info balloon text */
88
WCHAR info_title[64]; /* info balloon title */
89
UINT info_flags; /* flags for info balloon */
90
UINT info_timeout; /* timeout for info balloon */
91
HICON info_icon; /* info balloon icon */
92
UINT version; /* notify icon api version */
93
};
94
95
static struct list icon_list = LIST_INIT( icon_list );
96
97
struct taskbar_button
98
{
99
struct list entry;
100
HWND hwnd;
101
HWND button;
102
BOOL active;
103
BOOL visible;
104
};
105
106
static struct list taskbar_buttons = LIST_INIT( taskbar_buttons );
107
108
static HWND tray_window;
109
110
static unsigned int nb_displayed;
111
112
static BOOL enable_taskbar; /* show full taskbar, with dedicated systray area */
113
static BOOL show_systray; /* show a standalone systray window */
114
static BOOL enable_dock; /* allow systray icons to be docked in the host systray */
115
static BOOL no_tray_items; /* hide the systray and all systray icons */
116
117
static int icon_cx, icon_cy, tray_width, tray_height;
118
static int start_button_width, taskbar_button_width;
119
static WCHAR start_label[50];
120
121
static struct icon *balloon_icon;
122
static HWND balloon_window;
123
static POINT balloon_pos;
124
125
#define MIN_DISPLAYED 8
126
#define ICON_BORDER 2
127
128
#define BALLOON_CREATE_TIMER 1
129
#define BALLOON_SHOW_TIMER 2
130
131
#define BALLOON_CREATE_TIMEOUT 2000
132
#define BALLOON_SHOW_MIN_TIMEOUT 10000
133
#define BALLOON_SHOW_MAX_TIMEOUT 30000
134
135
#define WM_POPUPSYSTEMMENU 0x0313
136
137
static LRESULT WINAPI shell_traywnd_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam );
138
static LRESULT WINAPI tray_icon_wndproc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam );
139
140
static void show_icon( struct icon *icon );
141
static void hide_icon( struct icon *icon );
142
static BOOL delete_icon( struct icon *icon );
143
144
static WNDCLASSEXW shell_traywnd_class =
145
{
146
.cbSize = sizeof(WNDCLASSEXW),
147
.style = CS_DBLCLKS | CS_HREDRAW,
148
.lpfnWndProc = shell_traywnd_proc,
149
.hbrBackground = (HBRUSH)COLOR_WINDOW,
150
.lpszClassName = L"Shell_TrayWnd",
151
};
152
static WNDCLASSEXW tray_icon_class =
153
{
154
.cbSize = sizeof(WNDCLASSEXW),
155
.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
156
.lpfnWndProc = tray_icon_wndproc,
157
.lpszClassName = L"__wine_tray_icon",
158
};
159
160
static void do_hide_systray(void);
161
static void do_show_systray(void);
162
163
/* Retrieves icon record by owner window and ID */
164
static struct icon *get_icon(HWND owner, UINT id)
165
{
166
struct icon *this;
167
168
/* search for the icon */
169
LIST_FOR_EACH_ENTRY( this, &icon_list, struct icon, entry )
170
if ((this->id == id) && (this->owner == owner)) return this;
171
172
return NULL;
173
}
174
175
static void init_common_controls(void)
176
{
177
static BOOL initialized = FALSE;
178
179
if (!initialized)
180
{
181
INITCOMMONCONTROLSEX init_tooltip;
182
183
init_tooltip.dwSize = sizeof(INITCOMMONCONTROLSEX);
184
init_tooltip.dwICC = ICC_TAB_CLASSES|ICC_STANDARD_CLASSES;
185
186
InitCommonControlsEx(&init_tooltip);
187
initialized = TRUE;
188
}
189
}
190
191
/* Creates tooltip window for icon. */
192
static void create_tooltip(struct icon *icon)
193
{
194
TTTOOLINFOW ti;
195
196
init_common_controls();
197
icon->tooltip = CreateWindowExW( WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
198
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
199
icon->window, NULL, NULL, NULL );
200
201
ZeroMemory(&ti, sizeof(ti));
202
ti.cbSize = sizeof(TTTOOLINFOW);
203
ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
204
ti.hwnd = icon->window;
205
ti.uId = (UINT_PTR)icon->window;
206
ti.lpszText = icon->tiptext;
207
SendMessageW(icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
208
}
209
210
static void set_balloon_position( struct icon *icon )
211
{
212
RECT rect;
213
POINT pos;
214
215
GetWindowRect( icon->window, &rect );
216
pos.x = (rect.left + rect.right) / 2;
217
pos.y = (rect.top + rect.bottom) / 2;
218
SendMessageW( balloon_window, TTM_TRACKPOSITION, 0, MAKELONG( pos.x, pos.y ));
219
}
220
221
static void update_systray_balloon_position(void)
222
{
223
RECT rect;
224
POINT pos;
225
226
if (!balloon_icon) return;
227
GetWindowRect( balloon_icon->window, &rect );
228
pos.x = (rect.left + rect.right) / 2;
229
pos.y = (rect.top + rect.bottom) / 2;
230
if (pos.x == balloon_pos.x && pos.y == balloon_pos.y) return; /* nothing changed */
231
balloon_pos = pos;
232
SendMessageW( balloon_window, TTM_TRACKPOSITION, 0, MAKELONG( pos.x, pos.y ));
233
}
234
235
static void balloon_create_timer( struct icon *icon )
236
{
237
TTTOOLINFOW ti;
238
239
init_common_controls();
240
balloon_window = CreateWindowExW( WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL,
241
WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
242
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
243
icon->window, NULL, NULL, NULL );
244
245
memset( &ti, 0, sizeof(ti) );
246
ti.cbSize = sizeof(TTTOOLINFOW);
247
ti.hwnd = icon->window;
248
ti.uId = (UINT_PTR)icon->window;
249
ti.uFlags = TTF_TRACK | TTF_IDISHWND;
250
ti.lpszText = icon->info_text;
251
SendMessageW( balloon_window, TTM_ADDTOOLW, 0, (LPARAM)&ti );
252
if ((icon->info_flags & NIIF_ICONMASK) == NIIF_USER)
253
{
254
SendMessageW( balloon_window, TTM_SETTITLEW, (WPARAM)icon->info_icon, (LPARAM)icon->info_title );
255
}
256
else
257
{
258
UINT info_flags_wparam = icon->info_flags & NIIF_ERROR;
259
260
if (icon->info_flags & NIIF_LARGEICON)
261
info_flags_wparam += TTI_ERROR;
262
SendMessageW( balloon_window, TTM_SETTITLEW, info_flags_wparam, (LPARAM)icon->info_title );
263
}
264
balloon_icon = icon;
265
balloon_pos.x = balloon_pos.y = MAXLONG;
266
update_systray_balloon_position();
267
SendMessageW( balloon_window, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti );
268
KillTimer( icon->window, BALLOON_CREATE_TIMER );
269
SetTimer( icon->window, BALLOON_SHOW_TIMER, icon->info_timeout, NULL );
270
}
271
272
static BOOL show_balloon( struct icon *icon )
273
{
274
if (!show_systray) return FALSE; /* systray has been hidden */
275
if (icon->display == ICON_DISPLAY_HIDDEN) return FALSE; /* not displayed */
276
if (!icon->info_text[0]) return FALSE; /* no balloon */
277
balloon_icon = icon;
278
SetTimer( icon->window, BALLOON_CREATE_TIMER, BALLOON_CREATE_TIMEOUT, NULL );
279
return TRUE;
280
}
281
282
static void hide_balloon( struct icon *icon )
283
{
284
if (!balloon_icon) return;
285
if (balloon_window)
286
{
287
KillTimer( balloon_icon->window, BALLOON_SHOW_TIMER );
288
DestroyWindow( balloon_window );
289
balloon_window = 0;
290
}
291
else KillTimer( balloon_icon->window, BALLOON_CREATE_TIMER );
292
balloon_icon = NULL;
293
}
294
295
static void show_next_balloon(void)
296
{
297
struct icon *icon;
298
299
LIST_FOR_EACH_ENTRY( icon, &icon_list, struct icon, entry )
300
if (show_balloon( icon )) break;
301
}
302
303
static void update_balloon( struct icon *icon )
304
{
305
if (balloon_icon == icon)
306
{
307
hide_balloon( icon );
308
show_balloon( icon );
309
}
310
else if (!balloon_icon)
311
{
312
show_balloon( icon );
313
}
314
}
315
316
static void balloon_timer( struct icon *icon )
317
{
318
icon->info_text[0] = 0; /* clear text now that balloon has been shown */
319
hide_balloon( icon );
320
show_next_balloon();
321
}
322
323
/* Synchronize tooltip text with tooltip window */
324
static void update_tooltip_text(struct icon *icon)
325
{
326
TTTOOLINFOW ti;
327
328
ZeroMemory(&ti, sizeof(ti));
329
ti.cbSize = sizeof(TTTOOLINFOW);
330
ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
331
ti.hwnd = icon->window;
332
ti.uId = (UINT_PTR)icon->window;
333
ti.lpszText = icon->tiptext;
334
335
SendMessageW(icon->tooltip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
336
}
337
338
/* get the position of an icon in the stand-alone tray */
339
static POINT get_icon_pos( struct icon *icon )
340
{
341
POINT pos;
342
343
if (enable_taskbar)
344
{
345
pos.x = tray_width - icon_cx * (icon->display + 1);
346
pos.y = (tray_height - icon_cy) / 2;
347
}
348
else
349
{
350
pos.x = icon_cx * icon->display;
351
pos.y = 0;
352
}
353
354
return pos;
355
}
356
357
/* get the size of the stand-alone tray window */
358
static SIZE get_window_size(void)
359
{
360
SIZE size;
361
RECT rect;
362
363
rect.left = 0;
364
rect.top = 0;
365
rect.right = icon_cx * max( nb_displayed, MIN_DISPLAYED );
366
rect.bottom = icon_cy;
367
AdjustWindowRect( &rect, WS_CAPTION, FALSE );
368
size.cx = rect.right - rect.left;
369
size.cy = rect.bottom - rect.top;
370
return size;
371
}
372
373
/* synchronize tooltip position with tooltip window */
374
static void update_tooltip_position( struct icon *icon )
375
{
376
TTTOOLINFOW ti;
377
378
ZeroMemory(&ti, sizeof(ti));
379
ti.cbSize = sizeof(TTTOOLINFOW);
380
ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
381
ti.hwnd = icon->window;
382
ti.uId = (UINT_PTR)icon->window;
383
ti.lpszText = icon->tiptext;
384
SendMessageW( icon->tooltip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti );
385
if (balloon_icon == icon) set_balloon_position( icon );
386
}
387
388
static void paint_layered_icon( struct icon *icon )
389
{
390
BLENDFUNCTION blend = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
391
int width = GetSystemMetrics( SM_CXSMICON );
392
int height = GetSystemMetrics( SM_CYSMICON );
393
BITMAPINFO *info;
394
HBITMAP dib, mask;
395
HDC hdc;
396
RECT rc;
397
SIZE size;
398
POINT pos;
399
int i, x, y;
400
void *color_bits, *mask_bits;
401
DWORD *ptr;
402
BOOL has_alpha = FALSE;
403
404
GetWindowRect( icon->window, &rc );
405
size.cx = rc.right - rc.left;
406
size.cy = rc.bottom - rc.top;
407
pos.x = (size.cx - width) / 2;
408
pos.y = (size.cy - height) / 2;
409
410
if (!(info = calloc( 1, FIELD_OFFSET( BITMAPINFO, bmiColors[2] ) ))) return;
411
info->bmiHeader.biSize = sizeof(info->bmiHeader);
412
info->bmiHeader.biWidth = size.cx;
413
info->bmiHeader.biHeight = size.cy;
414
info->bmiHeader.biBitCount = 32;
415
info->bmiHeader.biPlanes = 1;
416
info->bmiHeader.biCompression = BI_RGB;
417
418
hdc = CreateCompatibleDC( 0 );
419
if (!(dib = CreateDIBSection( 0, info, DIB_RGB_COLORS, &color_bits, NULL, 0 ))) goto done;
420
SelectObject( hdc, dib );
421
DrawIconEx( hdc, pos.x, pos.y, icon->image, width, height, 0, 0, DI_DEFAULTSIZE | DI_NORMAL );
422
423
/* check if the icon was drawn with an alpha channel */
424
for (i = 0, ptr = color_bits; i < size.cx * size.cy; i++)
425
if ((has_alpha = (ptr[i] & 0xff000000) != 0)) break;
426
427
if (!has_alpha)
428
{
429
unsigned int width_bytes = (size.cx + 31) / 32 * 4;
430
431
info->bmiHeader.biBitCount = 1;
432
info->bmiColors[0].rgbRed = 0;
433
info->bmiColors[0].rgbGreen = 0;
434
info->bmiColors[0].rgbBlue = 0;
435
info->bmiColors[0].rgbReserved = 0;
436
info->bmiColors[1].rgbRed = 0xff;
437
info->bmiColors[1].rgbGreen = 0xff;
438
info->bmiColors[1].rgbBlue = 0xff;
439
info->bmiColors[1].rgbReserved = 0;
440
441
if (!(mask = CreateDIBSection( 0, info, DIB_RGB_COLORS, &mask_bits, NULL, 0 ))) goto done;
442
memset( mask_bits, 0xff, width_bytes * size.cy );
443
SelectObject( hdc, mask );
444
DrawIconEx( hdc, pos.x, pos.y, icon->image, width, height, 0, 0, DI_DEFAULTSIZE | DI_MASK );
445
446
for (y = 0, ptr = color_bits; y < size.cy; y++)
447
for (x = 0; x < size.cx; x++, ptr++)
448
if (!((((BYTE *)mask_bits)[y * width_bytes + x / 8] << (x % 8)) & 0x80))
449
*ptr |= 0xff000000;
450
451
SelectObject( hdc, dib );
452
DeleteObject( mask );
453
}
454
455
UpdateLayeredWindow( icon->window, 0, NULL, NULL, hdc, NULL, 0, &blend, ULW_ALPHA );
456
done:
457
free( info );
458
if (hdc) DeleteDC( hdc );
459
if (dib) DeleteObject( dib );
460
}
461
462
static BOOL notify_owner( struct icon *icon, UINT msg, LPARAM lparam )
463
{
464
WPARAM wp = icon->id;
465
LPARAM lp = msg;
466
467
if (icon->version >= NOTIFYICON_VERSION_4)
468
{
469
POINT pt = {.x = (short)LOWORD(lparam), .y = (short)HIWORD(lparam)};
470
ClientToScreen( icon->window, &pt );
471
wp = MAKEWPARAM( pt.x, pt.y );
472
lp = MAKELPARAM( msg, icon->id );
473
}
474
475
TRACE( "relaying 0x%x\n", msg );
476
if (!SendNotifyMessageW( icon->owner, icon->callback_message, wp, lp ) &&
477
(GetLastError() == ERROR_INVALID_WINDOW_HANDLE))
478
{
479
WARN( "application window was destroyed, removing icon %u\n", icon->id );
480
delete_icon( icon );
481
return FALSE;
482
}
483
return TRUE;
484
}
485
486
/* window procedure for the individual tray icon window */
487
static LRESULT WINAPI tray_icon_wndproc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
488
{
489
struct icon *icon = (struct icon *)GetWindowLongPtrW( hwnd, GWLP_USERDATA );
490
491
TRACE( "hwnd %p, msg %#x, wparam %#Ix, lparam %#Ix\n", hwnd, msg, wparam, lparam );
492
493
switch (msg)
494
{
495
case WM_NCCREATE:
496
{
497
/* set the icon data for the window from the data passed into CreateWindow */
498
const CREATESTRUCTW *info = (const CREATESTRUCTW *)lparam;
499
icon = info->lpCreateParams;
500
SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR)icon );
501
break;
502
}
503
504
case WM_CLOSE:
505
if (icon->display == ICON_DISPLAY_DOCKED)
506
{
507
TRACE( "icon %u no longer embedded\n", icon->id );
508
hide_icon( icon );
509
show_icon( icon );
510
}
511
return 0;
512
513
case WM_CREATE:
514
icon->window = hwnd;
515
create_tooltip( icon );
516
break;
517
518
case WM_SIZE:
519
case WM_MOVE:
520
if (icon->layered) paint_layered_icon( icon );
521
break;
522
523
case WM_PAINT:
524
{
525
PAINTSTRUCT ps;
526
RECT rc;
527
HDC hdc;
528
int cx, cy;
529
530
if (icon->layered) break;
531
532
cx = GetSystemMetrics( SM_CXSMICON );
533
cy = GetSystemMetrics( SM_CYSMICON );
534
hdc = BeginPaint( hwnd, &ps );
535
GetClientRect( hwnd, &rc );
536
TRACE( "painting rect %s\n", wine_dbgstr_rect( &rc ) );
537
DrawIconEx( hdc, (rc.left + rc.right - cx) / 2, (rc.top + rc.bottom - cy) / 2,
538
icon->image, cx, cy, 0, 0, DI_DEFAULTSIZE | DI_NORMAL );
539
EndPaint( hwnd, &ps );
540
return 0;
541
}
542
543
case WM_MOUSEMOVE:
544
case WM_LBUTTONDOWN:
545
case WM_LBUTTONUP:
546
case WM_RBUTTONDOWN:
547
case WM_RBUTTONUP:
548
case WM_MBUTTONDOWN:
549
case WM_MBUTTONUP:
550
case WM_LBUTTONDBLCLK:
551
case WM_RBUTTONDBLCLK:
552
case WM_MBUTTONDBLCLK:
553
{
554
MSG message = {.hwnd = hwnd, .message = msg, .wParam = wparam, .lParam = lparam};
555
SendMessageW( icon->tooltip, TTM_RELAYEVENT, 0, (LPARAM)&message );
556
if (!notify_owner( icon, msg, lparam )) break;
557
if (icon->version > 0)
558
{
559
if (msg == WM_LBUTTONUP) notify_owner( icon, NIN_SELECT, lparam );
560
if (msg == WM_RBUTTONUP) notify_owner( icon, WM_CONTEXTMENU, lparam );
561
}
562
break;
563
}
564
565
case WM_WINDOWPOSCHANGING:
566
if (icon->display == ICON_DISPLAY_HIDDEN)
567
{
568
/* Changing the icon's parent via SetParent would activate it, stealing the focus. */
569
WINDOWPOS *wp = (WINDOWPOS*)lparam;
570
wp->flags |= SWP_NOACTIVATE;
571
}
572
break;
573
574
case WM_WINDOWPOSCHANGED:
575
update_systray_balloon_position();
576
break;
577
578
case WM_TIMER:
579
switch (wparam)
580
{
581
case BALLOON_CREATE_TIMER: balloon_create_timer( icon ); break;
582
case BALLOON_SHOW_TIMER: balloon_timer( icon ); break;
583
}
584
return 0;
585
}
586
587
return DefWindowProcW( hwnd, msg, wparam, lparam );
588
}
589
590
/* add an icon to the system tray window */
591
static void systray_add_icon( struct icon *icon )
592
{
593
POINT pos;
594
595
if (icon->display != ICON_DISPLAY_HIDDEN) return; /* already added */
596
597
SetWindowLongW( icon->window, GWL_STYLE, GetWindowLongW( icon->window, GWL_STYLE ) | WS_CHILD );
598
SetParent( icon->window, tray_window );
599
icon->display = nb_displayed++;
600
pos = get_icon_pos( icon );
601
SetWindowPos( icon->window, 0, pos.x, pos.y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
602
603
if (nb_displayed == 1 && show_systray) do_show_systray();
604
TRACE( "added %u now %d icons\n", icon->id, nb_displayed );
605
}
606
607
/* remove an icon from the stand-alone tray */
608
static void systray_remove_icon( struct icon *icon )
609
{
610
struct icon *ptr;
611
POINT pos;
612
613
if (icon->display == ICON_DISPLAY_HIDDEN) return; /* already removed */
614
615
assert( nb_displayed );
616
LIST_FOR_EACH_ENTRY( ptr, &icon_list, struct icon, entry )
617
{
618
if (ptr == icon) continue;
619
if (ptr->display < icon->display) continue;
620
ptr->display--;
621
update_tooltip_position( ptr );
622
pos = get_icon_pos( ptr );
623
SetWindowPos( ptr->window, 0, pos.x, pos.y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
624
}
625
626
if (!--nb_displayed && !enable_taskbar) do_hide_systray();
627
TRACE( "removed %u now %d icons\n", icon->id, nb_displayed );
628
629
icon->display = ICON_DISPLAY_HIDDEN;
630
SetParent( icon->window, GetDesktopWindow() );
631
SetWindowLongW( icon->window, GWL_STYLE, GetWindowLongW( icon->window, GWL_STYLE ) & ~WS_CHILD );
632
}
633
634
/* make an icon visible */
635
static void show_icon(struct icon *icon)
636
{
637
TRACE( "id=0x%x, hwnd=%p\n", icon->id, icon->owner );
638
639
if (no_tray_items) return;
640
641
if (icon->display != ICON_DISPLAY_HIDDEN) return; /* already displayed */
642
643
if (enable_dock)
644
{
645
DWORD old_exstyle = GetWindowLongW( icon->window, GWL_EXSTYLE );
646
647
/* make sure it is layered before calling into the driver */
648
SetWindowLongW( icon->window, GWL_EXSTYLE, old_exstyle | WS_EX_LAYERED );
649
paint_layered_icon( icon );
650
651
if (!NtUserMessageCall( icon->window, WINE_SYSTRAY_DOCK_INSERT, icon_cx, icon_cy,
652
icon, NtUserSystemTrayCall, FALSE ))
653
SetWindowLongW( icon->window, GWL_EXSTYLE, old_exstyle );
654
else
655
{
656
icon->display = ICON_DISPLAY_DOCKED;
657
icon->layered = TRUE;
658
SendMessageW( icon->window, WM_SIZE, SIZE_RESTORED, MAKELONG( icon_cx, icon_cy ) );
659
}
660
}
661
systray_add_icon( icon );
662
663
update_tooltip_position( icon );
664
update_balloon( icon );
665
}
666
667
/* make an icon invisible */
668
static void hide_icon(struct icon *icon)
669
{
670
TRACE( "id=0x%x, hwnd=%p\n", icon->id, icon->owner );
671
672
if (icon->display == ICON_DISPLAY_HIDDEN) return; /* already hidden */
673
674
if (enable_dock && NtUserMessageCall( icon->window, WINE_SYSTRAY_DOCK_REMOVE, 0, 0,
675
NULL, NtUserSystemTrayCall, FALSE ))
676
{
677
icon->display = ICON_DISPLAY_HIDDEN;
678
icon->layered = FALSE;
679
SetWindowLongW( icon->window, GWL_EXSTYLE, GetWindowLongW( icon->window, GWL_EXSTYLE ) & ~WS_EX_LAYERED );
680
}
681
ShowWindow( icon->window, SW_HIDE );
682
systray_remove_icon( icon );
683
684
update_balloon( icon );
685
update_tooltip_position( icon );
686
}
687
688
/* Modifies an existing icon record */
689
static BOOL modify_icon( struct icon *icon, NOTIFYICONDATAW *nid )
690
{
691
TRACE( "id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd );
692
693
/* demarshal the request from the NID */
694
if (!icon)
695
{
696
WARN( "Invalid icon ID (0x%x) for HWND %p\n", nid->uID, nid->hWnd );
697
return FALSE;
698
}
699
700
if (nid->uFlags & NIF_STATE)
701
{
702
icon->state = (icon->state & ~nid->dwStateMask) | (nid->dwState & nid->dwStateMask);
703
}
704
705
if (nid->uFlags & NIF_ICON)
706
{
707
if (icon->image) DestroyIcon(icon->image);
708
icon->image = CopyIcon(nid->hIcon);
709
710
if (icon->display >= 0)
711
InvalidateRect( icon->window, NULL, TRUE );
712
else if (icon->layered)
713
paint_layered_icon( icon );
714
else if (enable_dock)
715
NtUserMessageCall( icon->window, WINE_SYSTRAY_DOCK_CLEAR, 0, 0,
716
NULL, NtUserSystemTrayCall, FALSE );
717
}
718
719
if (nid->uFlags & NIF_MESSAGE)
720
{
721
icon->callback_message = nid->uCallbackMessage;
722
}
723
if (nid->uFlags & NIF_TIP)
724
{
725
lstrcpynW( icon->tiptext, nid->szTip, ARRAY_SIZE( icon->tiptext ));
726
update_tooltip_text( icon );
727
}
728
if (nid->uFlags & NIF_INFO && nid->cbSize >= NOTIFYICONDATAA_V2_SIZE)
729
{
730
lstrcpynW( icon->info_text, nid->szInfo, ARRAY_SIZE( icon->info_text ));
731
lstrcpynW( icon->info_title, nid->szInfoTitle, ARRAY_SIZE( icon->info_title ));
732
icon->info_flags = nid->dwInfoFlags;
733
icon->info_timeout = max(min(nid->uTimeout, BALLOON_SHOW_MAX_TIMEOUT), BALLOON_SHOW_MIN_TIMEOUT);
734
735
if (icon->info_icon) DestroyIcon( icon->info_icon );
736
icon->info_icon = CopyIcon( nid->hBalloonIcon );
737
738
update_balloon( icon );
739
}
740
if (icon->state & NIS_HIDDEN) hide_icon( icon );
741
else show_icon( icon );
742
return TRUE;
743
}
744
745
/* Adds a new icon record to the list */
746
static BOOL add_icon(NOTIFYICONDATAW *nid)
747
{
748
struct icon *icon;
749
750
TRACE( "id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd );
751
752
if ((icon = get_icon(nid->hWnd, nid->uID)))
753
{
754
WARN( "duplicate tray icon add, buggy app?\n" );
755
return FALSE;
756
}
757
758
if (!(icon = calloc( 1, sizeof(*icon) )))
759
{
760
ERR( "out of memory\n" );
761
return FALSE;
762
}
763
764
ZeroMemory(icon, sizeof(struct icon));
765
icon->id = nid->uID;
766
icon->owner = nid->hWnd;
767
icon->display = ICON_DISPLAY_HIDDEN;
768
769
CreateWindowExW( 0, tray_icon_class.lpszClassName, NULL, WS_CLIPSIBLINGS | WS_POPUP,
770
0, 0, icon_cx, icon_cy, 0, NULL, NULL, icon );
771
if (!icon->window) ERR( "Failed to create systray icon window\n" );
772
773
list_add_tail(&icon_list, &icon->entry);
774
775
return modify_icon( icon, nid );
776
}
777
778
/* Deletes tray icon window and icon record */
779
static BOOL delete_icon( struct icon *icon )
780
{
781
hide_icon( icon );
782
list_remove( &icon->entry );
783
DestroyWindow( icon->tooltip );
784
DestroyWindow( icon->window );
785
DestroyIcon( icon->image );
786
free( icon );
787
return TRUE;
788
}
789
790
/* cleanup icons belonging to a window that has been destroyed */
791
static void cleanup_systray_window( HWND hwnd )
792
{
793
NOTIFYICONDATAW nid = {.cbSize = sizeof(nid), .hWnd = hwnd};
794
struct icon *icon, *next;
795
796
LIST_FOR_EACH_ENTRY_SAFE( icon, next, &icon_list, struct icon, entry )
797
if (icon->owner == hwnd) delete_icon( icon );
798
799
NtUserMessageCall( hwnd, WINE_SYSTRAY_CLEANUP_ICONS, 0, 0, NULL, NtUserSystemTrayCall, FALSE );
800
}
801
802
/* update the taskbar buttons when something changed */
803
static void sync_taskbar_buttons(void)
804
{
805
struct taskbar_button *win;
806
int pos = 0, count = 0;
807
int width = taskbar_button_width;
808
int right = tray_width - nb_displayed * icon_cx;
809
HWND foreground = GetAncestor( GetForegroundWindow(), GA_ROOTOWNER );
810
811
if (!enable_taskbar) return;
812
if (!IsWindowVisible( tray_window )) return;
813
814
LIST_FOR_EACH_ENTRY( win, &taskbar_buttons, struct taskbar_button, entry )
815
{
816
if (!win->hwnd) /* start button */
817
{
818
SetWindowPos( win->button, 0, pos, 0, start_button_width, tray_height,
819
SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW );
820
pos += start_button_width;
821
continue;
822
}
823
win->active = (win->hwnd == foreground);
824
win->visible = IsWindowVisible( win->hwnd ) && !GetWindow( win->hwnd, GW_OWNER );
825
if (win->visible) count++;
826
}
827
828
/* shrink buttons if space is tight */
829
if (count && (count * width > right - pos))
830
width = max( taskbar_button_width / 4, (right - pos) / count );
831
832
LIST_FOR_EACH_ENTRY( win, &taskbar_buttons, struct taskbar_button, entry )
833
{
834
if (!win->hwnd) continue; /* start button */
835
if (win->visible && right - pos >= width)
836
{
837
SetWindowPos( win->button, 0, pos, 0, width, tray_height,
838
SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW );
839
InvalidateRect( win->button, NULL, TRUE );
840
pos += width;
841
}
842
else SetWindowPos( win->button, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW );
843
}
844
}
845
846
static BOOL handle_incoming(HWND hwndSource, COPYDATASTRUCT *cds)
847
{
848
struct icon *icon = NULL;
849
const struct notify_data *data;
850
const BYTE *icon_data;
851
NOTIFYICONDATAW nid;
852
int ret = FALSE;
853
854
if (cds->cbData < sizeof(*data)) return FALSE;
855
data = cds->lpData;
856
icon_data = data->icon_data;
857
858
nid.cbSize = sizeof(nid);
859
nid.hWnd = LongToHandle( data->hWnd );
860
nid.uID = data->uID;
861
nid.uFlags = data->uFlags;
862
nid.uCallbackMessage = data->uCallbackMessage;
863
nid.hIcon = 0;
864
nid.dwState = data->dwState;
865
nid.dwStateMask = data->dwStateMask;
866
nid.uTimeout = data->u.uTimeout;
867
nid.dwInfoFlags = data->dwInfoFlags;
868
nid.guidItem = data->guidItem;
869
lstrcpyW( nid.szTip, data->szTip );
870
lstrcpyW( nid.szInfo, data->szInfo );
871
lstrcpyW( nid.szInfoTitle, data->szInfoTitle );
872
nid.hBalloonIcon = 0;
873
874
/* FIXME: if statement only needed because we don't support interprocess
875
* icon handles */
876
if (nid.uFlags & NIF_ICON)
877
{
878
LONG cbMaskBits;
879
LONG cbColourBits;
880
881
cbMaskBits = (data->icon_info.width * data->icon_info.height + 15) / 16 * 2;
882
cbColourBits = (data->icon_info.planes * data->icon_info.width * data->icon_info.height * data->icon_info.bpp + 15) / 16 * 2;
883
884
if (cds->cbData < sizeof(*data) + cbMaskBits + cbColourBits)
885
{
886
ERR( "buffer underflow\n" );
887
return FALSE;
888
}
889
nid.hIcon = CreateIcon(NULL, data->icon_info.width, data->icon_info.height, data->icon_info.planes, data->icon_info.bpp,
890
icon_data, icon_data + cbMaskBits);
891
icon_data += cbMaskBits + cbColourBits;
892
}
893
894
if ((nid.uFlags & NIF_INFO) && (nid.dwInfoFlags & NIIF_ICONMASK) == NIIF_USER)
895
{
896
/* Balloon icon */
897
LONG cbMaskBits;
898
LONG cbColourBits;
899
900
cbMaskBits = (data->balloon_icon_info.width * data->balloon_icon_info.height + 15) / 16 * 2;
901
cbColourBits = (data->balloon_icon_info.planes * data->balloon_icon_info.width * data->balloon_icon_info.height * data->balloon_icon_info.bpp + 15) / 16 * 2;
902
903
if (cds->cbData < ((char*)icon_data - (char*)data) + cbMaskBits + cbColourBits)
904
{
905
ERR( "buffer underflow\n" );
906
return FALSE;
907
}
908
nid.hBalloonIcon = CreateIcon(NULL, data->balloon_icon_info.width, data->balloon_icon_info.height, data->balloon_icon_info.planes, data->balloon_icon_info.bpp,
909
icon_data, icon_data + cbMaskBits);
910
}
911
/* try forwarding to the display driver first */
912
if (cds->dwData == NIM_ADD || !(icon = get_icon( nid.hWnd, nid.uID )))
913
{
914
if ((ret = NtUserMessageCall( hwndSource, WINE_SYSTRAY_NOTIFY_ICON, cds->dwData, 0,
915
&nid, NtUserSystemTrayCall, FALSE )) != -1)
916
goto done;
917
ret = FALSE;
918
}
919
920
switch (cds->dwData)
921
{
922
case NIM_ADD:
923
ret = add_icon(&nid);
924
break;
925
case NIM_DELETE:
926
if (icon) ret = delete_icon( icon );
927
break;
928
case NIM_MODIFY:
929
if (icon) ret = modify_icon( icon, &nid );
930
break;
931
case NIM_SETVERSION:
932
if (icon)
933
{
934
icon->version = nid.uVersion;
935
ret = TRUE;
936
}
937
break;
938
default:
939
FIXME( "unhandled tray message: %Id\n", cds->dwData );
940
break;
941
}
942
943
done:
944
if (nid.hIcon) DestroyIcon( nid.hIcon );
945
if (nid.hBalloonIcon) DestroyIcon( nid.hBalloonIcon );
946
sync_taskbar_buttons();
947
return ret;
948
}
949
950
static void add_taskbar_button( HWND hwnd )
951
{
952
struct taskbar_button *win;
953
954
if (!enable_taskbar) return;
955
956
/* ignore our own windows */
957
if (hwnd)
958
{
959
DWORD process;
960
if (!GetWindowThreadProcessId( hwnd, &process ) || process == GetCurrentProcessId()) return;
961
}
962
963
if (!(win = malloc( sizeof(*win) ))) return;
964
win->hwnd = hwnd;
965
win->button = CreateWindowW( WC_BUTTONW, NULL, WS_CHILD | BS_OWNERDRAW,
966
0, 0, 0, 0, tray_window, (HMENU)hwnd, 0, 0 );
967
list_add_tail( &taskbar_buttons, &win->entry );
968
}
969
970
static struct taskbar_button *find_taskbar_button( HWND hwnd )
971
{
972
struct taskbar_button *win;
973
974
LIST_FOR_EACH_ENTRY( win, &taskbar_buttons, struct taskbar_button, entry )
975
if (win->hwnd == hwnd) return win;
976
977
return NULL;
978
}
979
980
static void remove_taskbar_button( HWND hwnd )
981
{
982
struct taskbar_button *win = find_taskbar_button( hwnd );
983
984
if (!win) return;
985
list_remove( &win->entry );
986
DestroyWindow( win->button );
987
free( win );
988
}
989
990
static void paint_taskbar_button( const DRAWITEMSTRUCT *dis )
991
{
992
RECT rect;
993
UINT flags = DC_TEXT;
994
struct taskbar_button *win = find_taskbar_button( LongToHandle( dis->CtlID ));
995
996
if (!win) return;
997
GetClientRect( dis->hwndItem, &rect );
998
DrawFrameControl( dis->hDC, &rect, DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_ADJUSTRECT |
999
((dis->itemState & ODS_SELECTED) ? DFCS_PUSHED : 0 ));
1000
if (win->hwnd)
1001
{
1002
flags |= win->active ? DC_ACTIVE : DC_INBUTTON;
1003
DrawCaptionTempW( win->hwnd, dis->hDC, &rect, 0, 0, NULL, flags );
1004
}
1005
else /* start button */
1006
DrawCaptionTempW( 0, dis->hDC, &rect, 0, 0, start_label, flags | DC_INBUTTON | DC_ICON );
1007
}
1008
1009
static void click_taskbar_button( HWND button )
1010
{
1011
LONG_PTR id = GetWindowLongPtrW( button, GWLP_ID );
1012
HWND hwnd = (HWND)id;
1013
1014
if (!hwnd) /* start button */
1015
{
1016
do_startmenu( tray_window );
1017
return;
1018
}
1019
1020
if (IsIconic( hwnd ))
1021
{
1022
SendMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0 );
1023
return;
1024
}
1025
1026
if (IsWindowEnabled( hwnd ))
1027
{
1028
if (hwnd == GetForegroundWindow())
1029
{
1030
SendMessageW( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0 );
1031
return;
1032
}
1033
}
1034
else /* look for an enabled window owned by this one */
1035
{
1036
HWND owned = GetWindow( GetDesktopWindow(), GW_CHILD );
1037
while (owned && owned != hwnd)
1038
{
1039
if (IsWindowVisible( owned ) &&
1040
IsWindowEnabled( owned ) &&
1041
(GetWindow( owned, GW_OWNER ) == hwnd))
1042
break;
1043
owned = GetWindow( owned, GW_HWNDNEXT );
1044
}
1045
hwnd = owned;
1046
}
1047
SetForegroundWindow( hwnd );
1048
}
1049
1050
static void show_taskbar_contextmenu( HWND button, LPARAM lparam )
1051
{
1052
ULONG_PTR id = GetWindowLongPtrW( button, GWLP_ID );
1053
1054
if (id) SendNotifyMessageW( (HWND)id, WM_POPUPSYSTEMMENU, 0, lparam );
1055
}
1056
1057
static void do_hide_systray(void)
1058
{
1059
ShowWindow( tray_window, SW_HIDE );
1060
}
1061
1062
static void do_show_systray(void)
1063
{
1064
SIZE size;
1065
NONCLIENTMETRICSW ncm;
1066
HFONT font;
1067
HDC hdc;
1068
1069
if (!enable_taskbar)
1070
{
1071
size = get_window_size();
1072
SetWindowPos( tray_window, 0, 0, 0, size.cx, size.cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
1073
return;
1074
}
1075
1076
hdc = GetDC( 0 );
1077
1078
ncm.cbSize = sizeof(NONCLIENTMETRICSW);
1079
SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncm, 0 );
1080
font = CreateFontIndirectW( &ncm.lfCaptionFont );
1081
/* FIXME: Implement BCM_GETIDEALSIZE and use that instead. */
1082
SelectObject( hdc, font );
1083
GetTextExtentPointA( hdc, "abcdefghijklmnopqrstuvwxyz", 26, &size );
1084
taskbar_button_width = size.cx;
1085
GetTextExtentPointW( hdc, start_label, lstrlenW(start_label), &size );
1086
/* add some margins (FIXME) */
1087
size.cx += 12 + GetSystemMetrics( SM_CXSMICON );
1088
size.cy += 4;
1089
ReleaseDC( 0, hdc );
1090
DeleteObject( font );
1091
1092
tray_width = GetSystemMetrics( SM_CXSCREEN );
1093
tray_height = max( icon_cy, size.cy );
1094
start_button_width = size.cx;
1095
SetWindowPos( tray_window, 0, 0, GetSystemMetrics( SM_CYSCREEN ) - tray_height,
1096
tray_width, tray_height, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW );
1097
sync_taskbar_buttons();
1098
}
1099
1100
static LRESULT WINAPI shell_traywnd_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1101
{
1102
switch (msg)
1103
{
1104
case WM_COPYDATA:
1105
return handle_incoming((HWND)wparam, (COPYDATASTRUCT *)lparam);
1106
1107
case WM_DISPLAYCHANGE:
1108
if (!show_systray) do_hide_systray();
1109
else if (!nb_displayed && !enable_taskbar) do_hide_systray();
1110
else do_show_systray();
1111
break;
1112
1113
case WM_WINDOWPOSCHANGING:
1114
{
1115
WINDOWPOS *p = (WINDOWPOS *)lparam;
1116
1117
if (p->flags & SWP_SHOWWINDOW && (!show_systray || !nb_displayed) && !enable_taskbar)
1118
{
1119
TRACE( "WM_WINDOWPOSCHANGING clearing SWP_SHOWWINDOW.\n" );
1120
p->flags &= ~SWP_SHOWWINDOW;
1121
}
1122
break;
1123
}
1124
1125
case WM_MOVE:
1126
update_systray_balloon_position();
1127
break;
1128
1129
case WM_CLOSE:
1130
/* don't destroy the tray window, just hide it */
1131
ShowWindow( hwnd, SW_HIDE );
1132
hide_balloon( balloon_icon );
1133
show_systray = FALSE;
1134
return 0;
1135
1136
case WM_DRAWITEM:
1137
paint_taskbar_button( (const DRAWITEMSTRUCT *)lparam );
1138
break;
1139
1140
case WM_COMMAND:
1141
if (HIWORD(wparam) == BN_CLICKED)
1142
{
1143
if (LOWORD(wparam) == TRAY_MINIMIZE_ALL || LOWORD(wparam) == TRAY_MINIMIZE_ALL_UNDO)
1144
{
1145
FIXME( "Shell command %u is not supported.\n", LOWORD(wparam) );
1146
break;
1147
}
1148
click_taskbar_button( (HWND)lparam );
1149
}
1150
break;
1151
1152
case WM_CONTEXTMENU:
1153
show_taskbar_contextmenu( (HWND)wparam, lparam );
1154
break;
1155
1156
case WM_MOUSEACTIVATE:
1157
return MA_NOACTIVATE;
1158
1159
case WM_INITMENUPOPUP:
1160
case WM_MENUCOMMAND:
1161
return menu_wndproc(hwnd, msg, wparam, lparam);
1162
1163
case WM_USER + 0:
1164
update_systray_balloon_position();
1165
return 0;
1166
1167
case WM_USER + 1:
1168
{
1169
struct icon *icon;
1170
1171
LIST_FOR_EACH_ENTRY( icon, &icon_list, struct icon, entry )
1172
{
1173
if (!icon->window) continue;
1174
hide_icon( icon );
1175
show_icon( icon );
1176
}
1177
1178
return 0;
1179
}
1180
1181
default:
1182
return DefWindowProcW( hwnd, msg, wparam, lparam );
1183
}
1184
return 0;
1185
}
1186
1187
/* notification posted to the desktop window */
1188
void handle_parent_notify( HWND hwnd, WPARAM wp )
1189
{
1190
switch (LOWORD(wp))
1191
{
1192
case WM_CREATE:
1193
add_taskbar_button( hwnd );
1194
break;
1195
case WM_DESTROY:
1196
remove_taskbar_button( hwnd );
1197
cleanup_systray_window( hwnd );
1198
break;
1199
}
1200
sync_taskbar_buttons();
1201
}
1202
1203
/* this function creates the listener window */
1204
void initialize_systray( BOOL arg_using_root, BOOL arg_enable_shell, BOOL arg_show_systray, BOOL arg_no_tray_items )
1205
{
1206
RECT work_rect, primary_rect, taskbar_rect;
1207
1208
shell_traywnd_class.hIcon = LoadIconW( 0, (const WCHAR *)IDI_WINLOGO );
1209
shell_traywnd_class.hCursor = LoadCursorW( 0, (const WCHAR *)IDC_ARROW );
1210
tray_icon_class.hIcon = shell_traywnd_class.hIcon;
1211
tray_icon_class.hCursor = shell_traywnd_class.hCursor;
1212
1213
icon_cx = GetSystemMetrics( SM_CXSMICON ) + 2*ICON_BORDER;
1214
icon_cy = GetSystemMetrics( SM_CYSMICON ) + 2*ICON_BORDER;
1215
1216
if (arg_using_root)
1217
{
1218
show_systray = arg_show_systray;
1219
enable_taskbar = FALSE;
1220
enable_dock = TRUE;
1221
}
1222
else
1223
{
1224
show_systray = arg_show_systray && !arg_enable_shell;
1225
enable_taskbar = arg_enable_shell;
1226
enable_dock = FALSE;
1227
}
1228
1229
no_tray_items = arg_no_tray_items;
1230
1231
/* register the systray listener window class */
1232
if (!RegisterClassExW( &shell_traywnd_class ))
1233
{
1234
ERR( "Could not register SysTray window class\n" );
1235
return;
1236
}
1237
if (!RegisterClassExW( &tray_icon_class ))
1238
{
1239
ERR( "Could not register Wine SysTray window classes\n" );
1240
return;
1241
}
1242
1243
if (enable_taskbar)
1244
{
1245
SystemParametersInfoW( SPI_GETWORKAREA, 0, &work_rect, 0 );
1246
SetRect( &primary_rect, 0, 0, GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ) );
1247
SubtractRect( &taskbar_rect, &primary_rect, &work_rect );
1248
1249
tray_window = CreateWindowExW( WS_EX_NOACTIVATE, shell_traywnd_class.lpszClassName, NULL, WS_POPUP,
1250
taskbar_rect.left, taskbar_rect.top, taskbar_rect.right - taskbar_rect.left,
1251
taskbar_rect.bottom - taskbar_rect.top, 0, 0, 0, 0 );
1252
}
1253
else
1254
{
1255
SIZE size = get_window_size();
1256
tray_window = CreateWindowExW( 0, shell_traywnd_class.lpszClassName, L"", WS_CAPTION | WS_SYSMENU,
1257
CW_USEDEFAULT, CW_USEDEFAULT, size.cx, size.cy, 0, 0, 0, 0 );
1258
NtUserMessageCall( tray_window, WINE_SYSTRAY_DOCK_INIT, 0, 0, NULL, NtUserSystemTrayCall, FALSE );
1259
}
1260
1261
if (!tray_window)
1262
{
1263
ERR( "Could not create tray window\n" );
1264
return;
1265
}
1266
1267
LoadStringW( NULL, IDS_START_LABEL, start_label, ARRAY_SIZE( start_label ));
1268
1269
add_taskbar_button( 0 );
1270
1271
if (enable_taskbar) do_show_systray();
1272
else do_hide_systray();
1273
}
1274
1275