2006-02-19 18:50:27 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 Mike Hearn, for CodeWeavers
|
|
|
|
* Copyright (C) 2005 Robert Shearman
|
2008-04-08 15:56:24 +02:00
|
|
|
* Copyright (C) 2008 Alexandre Julliard
|
2006-02-19 18:50:27 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-02-19 18:50:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2010-03-30 21:26:26 +02:00
|
|
|
#define NONAMELESSUNION
|
2006-02-19 18:50:27 +01:00
|
|
|
#define _WIN32_IE 0x500
|
|
|
|
#include <windows.h>
|
2006-08-31 03:42:49 +02:00
|
|
|
#include <commctrl.h>
|
2012-01-23 12:16:36 +01:00
|
|
|
#include <shellapi.h>
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
#include <wine/debug.h>
|
|
|
|
#include <wine/list.h>
|
|
|
|
|
2006-03-07 11:50:05 +01:00
|
|
|
#include "explorer_private.h"
|
2013-12-05 23:29:31 +01:00
|
|
|
#include "resource.h"
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(systray);
|
|
|
|
|
2010-03-30 21:26:26 +02:00
|
|
|
struct notify_data /* platform-independent format for NOTIFYICONDATA */
|
|
|
|
{
|
|
|
|
LONG hWnd;
|
|
|
|
UINT uID;
|
|
|
|
UINT uFlags;
|
|
|
|
UINT uCallbackMessage;
|
|
|
|
WCHAR szTip[128];
|
|
|
|
DWORD dwState;
|
|
|
|
DWORD dwStateMask;
|
|
|
|
WCHAR szInfo[256];
|
|
|
|
union {
|
|
|
|
UINT uTimeout;
|
|
|
|
UINT uVersion;
|
|
|
|
} u;
|
|
|
|
WCHAR szInfoTitle[64];
|
|
|
|
DWORD dwInfoFlags;
|
|
|
|
GUID guidItem;
|
|
|
|
/* data for the icon bitmap */
|
|
|
|
UINT width;
|
|
|
|
UINT height;
|
|
|
|
UINT planes;
|
|
|
|
UINT bpp;
|
|
|
|
};
|
|
|
|
|
2008-12-16 14:59:00 +01:00
|
|
|
static int (CDECL *wine_notify_icon)(DWORD,NOTIFYICONDATAW *);
|
2008-04-08 15:47:36 +02:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
/* an individual systray icon, unpacked from the NOTIFYICONDATA and always in unicode */
|
|
|
|
struct icon
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
HICON image; /* the image to render */
|
|
|
|
HWND owner; /* the HWND passed in to the Shell_NotifyIcon call */
|
2006-08-31 03:42:49 +02:00
|
|
|
HWND tooltip; /* Icon tooltip */
|
2010-12-15 16:31:12 +01:00
|
|
|
UINT state; /* state flags */
|
2006-02-19 18:50:27 +01:00
|
|
|
UINT id; /* the unique id given by the app */
|
|
|
|
UINT callback_message;
|
2008-04-08 15:56:24 +02:00
|
|
|
int display; /* index in display list, or -1 if hidden */
|
2008-02-07 16:23:52 +01:00
|
|
|
WCHAR tiptext[128]; /* Tooltip text. If empty => tooltip disabled */
|
2010-12-15 16:31:12 +01:00
|
|
|
WCHAR info_text[256]; /* info balloon text */
|
|
|
|
WCHAR info_title[64]; /* info balloon title */
|
|
|
|
UINT info_flags; /* flags for info balloon */
|
|
|
|
UINT info_timeout; /* timeout for info balloon */
|
|
|
|
HICON info_icon; /* info balloon icon */
|
2016-10-10 16:35:40 +02:00
|
|
|
UINT version; /* notify icon api version */
|
2006-02-19 18:50:27 +01:00
|
|
|
};
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
static struct list icon_list = LIST_INIT( icon_list );
|
2016-05-31 07:01:33 +02:00
|
|
|
|
|
|
|
struct taskbar_button
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
HWND hwnd;
|
|
|
|
HWND button;
|
|
|
|
BOOL active;
|
|
|
|
BOOL visible;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct list taskbar_buttons = LIST_INIT( taskbar_buttons );
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
static HWND tray_window;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
static unsigned int alloc_displayed;
|
|
|
|
static unsigned int nb_displayed;
|
|
|
|
static struct icon **displayed; /* array of currently displayed icons */
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2013-12-16 23:17:21 +01:00
|
|
|
static BOOL hide_systray, enable_shell;
|
2016-05-27 14:08:44 +02:00
|
|
|
static int icon_cx, icon_cy, tray_width, tray_height;
|
2016-05-31 07:01:33 +02:00
|
|
|
static int start_button_width, taskbar_button_width;
|
2016-05-27 14:08:44 +02:00
|
|
|
static WCHAR start_label[50];
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2010-12-15 17:16:52 +01:00
|
|
|
static struct icon *balloon_icon;
|
|
|
|
static HWND balloon_window;
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
#define MIN_DISPLAYED 8
|
|
|
|
#define ICON_BORDER 2
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2015-03-27 09:13:32 +01:00
|
|
|
#define BALLOON_CREATE_TIMER 1
|
|
|
|
#define BALLOON_SHOW_TIMER 2
|
2010-12-15 17:16:52 +01:00
|
|
|
|
|
|
|
#define BALLOON_CREATE_TIMEOUT 2000
|
2010-12-15 16:31:12 +01:00
|
|
|
#define BALLOON_SHOW_MIN_TIMEOUT 10000
|
|
|
|
#define BALLOON_SHOW_MAX_TIMEOUT 30000
|
|
|
|
|
2016-06-08 08:35:38 +02:00
|
|
|
#define WM_POPUPSYSTEMMENU 0x0313
|
|
|
|
|
2016-06-17 05:08:03 +02:00
|
|
|
static void do_hide_systray(void);
|
2016-05-27 14:08:44 +02:00
|
|
|
static void do_show_systray(void);
|
|
|
|
|
2008-02-07 16:23:52 +01:00
|
|
|
/* Retrieves icon record by owner window and ID */
|
2006-02-19 18:50:27 +01:00
|
|
|
static struct icon *get_icon(HWND owner, UINT id)
|
|
|
|
{
|
|
|
|
struct icon *this;
|
|
|
|
|
|
|
|
/* search for the icon */
|
2008-04-08 15:56:24 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( this, &icon_list, struct icon, entry )
|
2006-04-14 19:58:40 +02:00
|
|
|
if ((this->id == id) && (this->owner == owner)) return this;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-01 19:38:28 +01:00
|
|
|
static RECT get_icon_rect( struct icon *icon )
|
2008-04-08 15:56:24 +02:00
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
|
2010-11-01 19:38:28 +01:00
|
|
|
rect.right = tray_width - icon_cx * icon->display;
|
|
|
|
rect.left = rect.right - icon_cx;
|
2016-05-27 14:16:40 +02:00
|
|
|
rect.top = (tray_height - icon_cy) / 2;
|
|
|
|
rect.bottom = rect.top + icon_cy;
|
2010-11-01 19:38:28 +01:00
|
|
|
return rect;
|
2008-04-08 15:56:24 +02:00
|
|
|
}
|
|
|
|
|
2010-12-15 17:16:52 +01:00
|
|
|
static void init_common_controls(void)
|
2006-08-31 03:42:49 +02:00
|
|
|
{
|
2010-12-15 17:16:52 +01:00
|
|
|
static BOOL initialized = FALSE;
|
2008-02-07 16:23:52 +01:00
|
|
|
|
2010-12-15 17:16:52 +01:00
|
|
|
if (!initialized)
|
2008-02-07 16:23:52 +01:00
|
|
|
{
|
|
|
|
INITCOMMONCONTROLSEX init_tooltip;
|
|
|
|
|
|
|
|
init_tooltip.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
2013-12-05 23:29:31 +01:00
|
|
|
init_tooltip.dwICC = ICC_TAB_CLASSES|ICC_STANDARD_CLASSES;
|
2008-02-07 16:23:52 +01:00
|
|
|
|
|
|
|
InitCommonControlsEx(&init_tooltip);
|
2010-12-15 17:16:52 +01:00
|
|
|
initialized = TRUE;
|
2008-02-07 16:23:52 +01:00
|
|
|
}
|
2010-12-15 17:16:52 +01:00
|
|
|
}
|
2006-08-31 03:42:49 +02:00
|
|
|
|
2010-12-15 17:16:52 +01:00
|
|
|
/* Creates tooltip window for icon. */
|
|
|
|
static void create_tooltip(struct icon *icon)
|
|
|
|
{
|
|
|
|
TTTOOLINFOW ti;
|
|
|
|
|
|
|
|
init_common_controls();
|
2008-09-03 11:30:44 +02:00
|
|
|
icon->tooltip = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL,
|
2008-02-07 16:23:52 +01:00
|
|
|
WS_POPUP | TTS_ALWAYSTIP,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
2008-04-08 15:56:24 +02:00
|
|
|
tray_window, NULL, NULL, NULL);
|
2008-02-07 16:23:52 +01:00
|
|
|
|
|
|
|
ZeroMemory(&ti, sizeof(ti));
|
2006-08-31 03:42:49 +02:00
|
|
|
ti.cbSize = sizeof(TTTOOLINFOW);
|
2008-04-08 15:56:24 +02:00
|
|
|
ti.hwnd = tray_window;
|
2008-02-07 16:23:52 +01:00
|
|
|
ti.lpszText = icon->tiptext;
|
2010-11-01 19:38:28 +01:00
|
|
|
if (icon->display != -1) ti.rect = get_icon_rect( icon );
|
2008-02-07 16:23:52 +01:00
|
|
|
SendMessageW(icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
|
|
|
|
}
|
2006-08-31 03:42:49 +02:00
|
|
|
|
2010-12-15 17:16:52 +01:00
|
|
|
static void set_balloon_position( struct icon *icon )
|
|
|
|
{
|
|
|
|
RECT rect = get_icon_rect( icon );
|
|
|
|
POINT pos;
|
|
|
|
|
|
|
|
MapWindowPoints( tray_window, 0, (POINT *)&rect, 2 );
|
|
|
|
pos.x = (rect.left + rect.right) / 2;
|
|
|
|
pos.y = (rect.top + rect.bottom) / 2;
|
|
|
|
SendMessageW( balloon_window, TTM_TRACKPOSITION, 0, MAKELONG( pos.x, pos.y ));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void balloon_create_timer(void)
|
|
|
|
{
|
|
|
|
TTTOOLINFOW ti;
|
|
|
|
|
|
|
|
init_common_controls();
|
|
|
|
balloon_window = CreateWindowExW( WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL,
|
|
|
|
WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
tray_window, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
memset( &ti, 0, sizeof(ti) );
|
|
|
|
ti.cbSize = sizeof(TTTOOLINFOW);
|
|
|
|
ti.hwnd = tray_window;
|
|
|
|
ti.uFlags = TTF_TRACK;
|
|
|
|
ti.lpszText = balloon_icon->info_text;
|
|
|
|
SendMessageW( balloon_window, TTM_ADDTOOLW, 0, (LPARAM)&ti );
|
|
|
|
if ((balloon_icon->info_flags & NIIF_ICONMASK) == NIIF_USER)
|
|
|
|
SendMessageW( balloon_window, TTM_SETTITLEW, (WPARAM)balloon_icon->info_icon,
|
|
|
|
(LPARAM)balloon_icon->info_title );
|
|
|
|
else
|
|
|
|
SendMessageW( balloon_window, TTM_SETTITLEW, balloon_icon->info_flags,
|
|
|
|
(LPARAM)balloon_icon->info_title );
|
|
|
|
set_balloon_position( balloon_icon );
|
|
|
|
SendMessageW( balloon_window, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti );
|
|
|
|
KillTimer( tray_window, BALLOON_CREATE_TIMER );
|
|
|
|
SetTimer( tray_window, BALLOON_SHOW_TIMER, balloon_icon->info_timeout, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL show_balloon( struct icon *icon )
|
|
|
|
{
|
|
|
|
if (icon->display == -1) return FALSE; /* not displayed */
|
|
|
|
if (!icon->info_text[0]) return FALSE; /* no balloon */
|
|
|
|
balloon_icon = icon;
|
|
|
|
SetTimer( tray_window, BALLOON_CREATE_TIMER, BALLOON_CREATE_TIMEOUT, NULL );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hide_balloon(void)
|
|
|
|
{
|
|
|
|
if (!balloon_icon) return;
|
|
|
|
if (balloon_window)
|
|
|
|
{
|
|
|
|
KillTimer( tray_window, BALLOON_SHOW_TIMER );
|
|
|
|
DestroyWindow( balloon_window );
|
|
|
|
balloon_window = 0;
|
|
|
|
}
|
|
|
|
else KillTimer( tray_window, BALLOON_CREATE_TIMER );
|
|
|
|
balloon_icon = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_next_balloon(void)
|
|
|
|
{
|
|
|
|
struct icon *icon;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( icon, &icon_list, struct icon, entry )
|
|
|
|
if (show_balloon( icon )) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_balloon( struct icon *icon )
|
|
|
|
{
|
|
|
|
if (balloon_icon == icon)
|
|
|
|
{
|
|
|
|
hide_balloon();
|
|
|
|
show_balloon( icon );
|
|
|
|
}
|
|
|
|
else if (!balloon_icon)
|
|
|
|
{
|
|
|
|
if (!show_balloon( icon )) return;
|
|
|
|
}
|
|
|
|
if (!balloon_icon) show_next_balloon();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void balloon_timer(void)
|
|
|
|
{
|
|
|
|
if (balloon_icon) balloon_icon->info_text[0] = 0; /* clear text now that balloon has been shown */
|
|
|
|
hide_balloon();
|
|
|
|
show_next_balloon();
|
|
|
|
}
|
|
|
|
|
2008-02-07 16:23:52 +01:00
|
|
|
/* Synchronize tooltip text with tooltip window */
|
|
|
|
static void update_tooltip_text(struct icon *icon)
|
|
|
|
{
|
|
|
|
TTTOOLINFOW ti;
|
|
|
|
|
|
|
|
ZeroMemory(&ti, sizeof(ti));
|
|
|
|
ti.cbSize = sizeof(TTTOOLINFOW);
|
2008-04-08 15:56:24 +02:00
|
|
|
ti.hwnd = tray_window;
|
2008-02-07 16:23:52 +01:00
|
|
|
ti.lpszText = icon->tiptext;
|
|
|
|
|
|
|
|
SendMessageW(icon->tooltip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
|
2006-08-31 03:42:49 +02:00
|
|
|
}
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
/* synchronize tooltip position with tooltip window */
|
|
|
|
static void update_tooltip_position( struct icon *icon )
|
|
|
|
{
|
|
|
|
TTTOOLINFOW ti;
|
|
|
|
|
|
|
|
ZeroMemory(&ti, sizeof(ti));
|
|
|
|
ti.cbSize = sizeof(TTTOOLINFOW);
|
|
|
|
ti.hwnd = tray_window;
|
2010-11-01 19:38:28 +01:00
|
|
|
if (icon->display != -1) ti.rect = get_icon_rect( icon );
|
2008-04-08 15:56:24 +02:00
|
|
|
SendMessageW( icon->tooltip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti );
|
2010-12-15 17:16:52 +01:00
|
|
|
if (balloon_icon == icon) set_balloon_position( icon );
|
2008-04-08 15:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find the icon located at a certain point in the tray window */
|
|
|
|
static struct icon *icon_from_point( int x, int y )
|
|
|
|
{
|
|
|
|
if (y < 0 || y >= icon_cy) return NULL;
|
2010-11-01 19:38:28 +01:00
|
|
|
x = tray_width - x;
|
2008-04-08 15:56:24 +02:00
|
|
|
if (x < 0 || x >= icon_cx * nb_displayed) return NULL;
|
|
|
|
return displayed[x / icon_cx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* invalidate the portion of the tray window that contains the specified icons */
|
|
|
|
static void invalidate_icons( unsigned int start, unsigned int end )
|
2008-02-05 15:19:40 +01:00
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
|
2010-11-01 19:38:28 +01:00
|
|
|
rect.left = tray_width - (end + 1) * icon_cx;
|
2016-05-27 14:16:40 +02:00
|
|
|
rect.top = (tray_height - icon_cy) / 2;
|
2010-11-01 19:38:28 +01:00
|
|
|
rect.right = tray_width - start * icon_cx;
|
2016-05-27 14:16:40 +02:00
|
|
|
rect.bottom = rect.top + icon_cy;
|
2008-04-08 15:56:24 +02:00
|
|
|
InvalidateRect( tray_window, &rect, TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make an icon visible */
|
|
|
|
static BOOL show_icon(struct icon *icon)
|
|
|
|
{
|
|
|
|
WINE_TRACE("id=0x%x, hwnd=%p\n", icon->id, icon->owner);
|
2008-02-05 15:19:40 +01:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
if (icon->display != -1) return TRUE; /* already displayed */
|
2008-02-07 16:23:54 +01:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
if (nb_displayed >= alloc_displayed)
|
2008-02-05 15:19:40 +01:00
|
|
|
{
|
2008-04-08 15:56:24 +02:00
|
|
|
unsigned int new_count = max( alloc_displayed * 2, 32 );
|
|
|
|
struct icon **ptr;
|
|
|
|
if (displayed) ptr = HeapReAlloc( GetProcessHeap(), 0, displayed, new_count * sizeof(*ptr) );
|
|
|
|
else ptr = HeapAlloc( GetProcessHeap(), 0, new_count * sizeof(*ptr) );
|
|
|
|
if (!ptr) return FALSE;
|
|
|
|
displayed = ptr;
|
|
|
|
alloc_displayed = new_count;
|
2008-02-05 15:19:40 +01:00
|
|
|
}
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
icon->display = nb_displayed;
|
|
|
|
displayed[nb_displayed++] = icon;
|
|
|
|
update_tooltip_position( icon );
|
|
|
|
invalidate_icons( nb_displayed-1, nb_displayed-1 );
|
|
|
|
|
2016-05-27 14:08:44 +02:00
|
|
|
if (nb_displayed == 1 && !hide_systray) do_show_systray();
|
2008-02-05 15:19:40 +01:00
|
|
|
|
2008-02-07 16:23:52 +01:00
|
|
|
create_tooltip(icon);
|
2010-12-15 17:16:52 +01:00
|
|
|
update_balloon( icon );
|
2008-04-08 15:56:24 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make an icon invisible */
|
|
|
|
static BOOL hide_icon(struct icon *icon)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2008-02-05 15:19:40 +01:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
WINE_TRACE("id=0x%x, hwnd=%p\n", icon->id, icon->owner);
|
|
|
|
|
|
|
|
if (icon->display == -1) return TRUE; /* already hidden */
|
|
|
|
|
|
|
|
assert( nb_displayed );
|
|
|
|
for (i = icon->display; i < nb_displayed - 1; i++)
|
|
|
|
{
|
|
|
|
displayed[i] = displayed[i + 1];
|
|
|
|
displayed[i]->display = i;
|
|
|
|
update_tooltip_position( displayed[i] );
|
|
|
|
}
|
|
|
|
nb_displayed--;
|
|
|
|
invalidate_icons( icon->display, nb_displayed );
|
|
|
|
icon->display = -1;
|
|
|
|
|
2016-06-17 05:08:03 +02:00
|
|
|
if (!nb_displayed && !enable_shell) do_hide_systray();
|
2008-04-08 15:56:24 +02:00
|
|
|
|
2010-12-15 17:16:52 +01:00
|
|
|
update_balloon( icon );
|
2008-04-08 15:56:24 +02:00
|
|
|
update_tooltip_position( icon );
|
2008-02-05 15:19:40 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-02-07 16:23:52 +01:00
|
|
|
/* Modifies an existing icon record */
|
2008-04-08 15:56:24 +02:00
|
|
|
static BOOL modify_icon( struct icon *icon, NOTIFYICONDATAW *nid )
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
|
|
|
|
|
|
|
|
/* demarshal the request from the NID */
|
|
|
|
if (!icon)
|
|
|
|
{
|
|
|
|
WINE_WARN("Invalid icon ID (0x%x) for HWND %p\n", nid->uID, nid->hWnd);
|
2008-02-05 15:17:49 +01:00
|
|
|
return FALSE;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
2010-12-15 16:31:12 +01:00
|
|
|
if (nid->uFlags & NIF_STATE)
|
2008-04-08 15:56:24 +02:00
|
|
|
{
|
2010-12-15 16:31:12 +01:00
|
|
|
icon->state = (icon->state & ~nid->dwStateMask) | (nid->dwState & nid->dwStateMask);
|
2008-04-08 15:56:24 +02:00
|
|
|
}
|
2008-02-05 15:19:40 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
if (nid->uFlags & NIF_ICON)
|
|
|
|
{
|
|
|
|
if (icon->image) DestroyIcon(icon->image);
|
|
|
|
icon->image = CopyIcon(nid->hIcon);
|
2008-04-08 15:56:24 +02:00
|
|
|
if (icon->display != -1) invalidate_icons( icon->display, icon->display );
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nid->uFlags & NIF_MESSAGE)
|
|
|
|
{
|
|
|
|
icon->callback_message = nid->uCallbackMessage;
|
|
|
|
}
|
2006-08-31 03:42:49 +02:00
|
|
|
if (nid->uFlags & NIF_TIP)
|
|
|
|
{
|
2018-08-21 23:10:20 +02:00
|
|
|
lstrcpynW( icon->tiptext, nid->szTip, ARRAY_SIZE( icon->tiptext ));
|
2008-04-08 15:56:24 +02:00
|
|
|
if (icon->display != -1) update_tooltip_text(icon);
|
2006-08-31 03:42:49 +02:00
|
|
|
}
|
2007-11-19 16:32:12 +01:00
|
|
|
if (nid->uFlags & NIF_INFO && nid->cbSize >= NOTIFYICONDATAA_V2_SIZE)
|
|
|
|
{
|
2018-08-21 23:10:20 +02:00
|
|
|
lstrcpynW( icon->info_text, nid->szInfo, ARRAY_SIZE( icon->info_text ));
|
|
|
|
lstrcpynW( icon->info_title, nid->szInfoTitle, ARRAY_SIZE( icon->info_title ));
|
2010-12-15 16:31:12 +01:00
|
|
|
icon->info_flags = nid->dwInfoFlags;
|
|
|
|
icon->info_timeout = max(min(nid->u.uTimeout, BALLOON_SHOW_MAX_TIMEOUT), BALLOON_SHOW_MIN_TIMEOUT);
|
|
|
|
icon->info_icon = nid->hBalloonIcon;
|
2010-12-15 17:16:52 +01:00
|
|
|
update_balloon( icon );
|
2007-11-19 16:32:12 +01:00
|
|
|
}
|
2010-12-15 16:31:12 +01:00
|
|
|
if (icon->state & NIS_HIDDEN) hide_icon( icon );
|
|
|
|
else show_icon( icon );
|
2008-02-05 15:17:49 +01:00
|
|
|
return TRUE;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
2008-02-07 16:23:52 +01:00
|
|
|
/* Adds a new icon record to the list */
|
2008-02-05 15:17:49 +01:00
|
|
|
static BOOL add_icon(NOTIFYICONDATAW *nid)
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
struct icon *icon;
|
|
|
|
|
|
|
|
WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
|
|
|
|
|
|
|
|
if ((icon = get_icon(nid->hWnd, nid->uID)))
|
|
|
|
{
|
|
|
|
WINE_WARN("duplicate tray icon add, buggy app?\n");
|
2008-02-05 15:17:49 +01:00
|
|
|
return FALSE;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(icon = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*icon))))
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
2008-02-05 15:17:49 +01:00
|
|
|
return FALSE;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
2008-02-07 16:23:54 +01:00
|
|
|
ZeroMemory(icon, sizeof(struct icon));
|
2008-02-05 15:19:40 +01:00
|
|
|
icon->id = nid->uID;
|
|
|
|
icon->owner = nid->hWnd;
|
2008-04-08 15:56:24 +02:00
|
|
|
icon->display = -1;
|
2006-08-31 03:42:49 +02:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
list_add_tail(&icon_list, &icon->entry);
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2010-12-15 16:31:12 +01:00
|
|
|
return modify_icon( icon, nid );
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
2008-02-07 16:23:54 +01:00
|
|
|
/* Deletes tray icon window and icon record */
|
2008-04-08 15:56:24 +02:00
|
|
|
static BOOL delete_icon(struct icon *icon)
|
2008-02-07 16:23:54 +01:00
|
|
|
{
|
2008-04-08 15:56:24 +02:00
|
|
|
hide_icon(icon);
|
2008-02-07 16:23:54 +01:00
|
|
|
list_remove(&icon->entry);
|
|
|
|
DestroyIcon(icon->image);
|
|
|
|
HeapFree(GetProcessHeap(), 0, icon);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-27 09:13:32 +01:00
|
|
|
/* cleanup icons belonging to a window that has been destroyed */
|
2016-05-31 06:54:07 +02:00
|
|
|
static void cleanup_systray_window( HWND hwnd )
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
2008-04-08 15:56:24 +02:00
|
|
|
struct icon *icon, *next;
|
2008-02-07 16:23:54 +01:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( icon, next, &icon_list, struct icon, entry )
|
2015-03-27 09:13:32 +01:00
|
|
|
if (icon->owner == hwnd) delete_icon( icon );
|
|
|
|
|
|
|
|
if (wine_notify_icon)
|
|
|
|
{
|
|
|
|
NOTIFYICONDATAW nid = { sizeof(nid), hwnd };
|
|
|
|
wine_notify_icon( 0xdead, &nid );
|
|
|
|
}
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
2016-05-31 07:01:33 +02:00
|
|
|
/* update the taskbar buttons when something changed */
|
|
|
|
static void sync_taskbar_buttons(void)
|
|
|
|
{
|
|
|
|
struct taskbar_button *win;
|
|
|
|
int pos = 0, count = 0;
|
|
|
|
int width = taskbar_button_width;
|
|
|
|
int right = tray_width - nb_displayed * icon_cx;
|
|
|
|
HWND foreground = GetAncestor( GetForegroundWindow(), GA_ROOTOWNER );
|
|
|
|
|
2016-06-10 10:39:54 +02:00
|
|
|
if (!IsWindowVisible( tray_window )) return;
|
|
|
|
|
2016-05-31 07:01:33 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( win, &taskbar_buttons, struct taskbar_button, entry )
|
|
|
|
{
|
|
|
|
if (!win->hwnd) /* start button */
|
|
|
|
{
|
|
|
|
SetWindowPos( win->button, 0, pos, 0, start_button_width, tray_height,
|
|
|
|
SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW );
|
|
|
|
pos += start_button_width;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
win->active = (win->hwnd == foreground);
|
|
|
|
win->visible = IsWindowVisible( win->hwnd ) && !GetWindow( win->hwnd, GW_OWNER );
|
|
|
|
if (win->visible) count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shrink buttons if space is tight */
|
|
|
|
if (count && (count * width > right - pos))
|
|
|
|
width = max( taskbar_button_width / 4, (right - pos) / count );
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( win, &taskbar_buttons, struct taskbar_button, entry )
|
|
|
|
{
|
|
|
|
if (!win->hwnd) continue; /* start button */
|
|
|
|
if (win->visible && right - pos >= width)
|
|
|
|
{
|
|
|
|
SetWindowPos( win->button, 0, pos, 0, width, tray_height,
|
|
|
|
SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW );
|
|
|
|
InvalidateRect( win->button, NULL, TRUE );
|
|
|
|
pos += width;
|
|
|
|
}
|
|
|
|
else SetWindowPos( win->button, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-05 15:17:49 +01:00
|
|
|
static BOOL handle_incoming(HWND hwndSource, COPYDATASTRUCT *cds)
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
2008-04-08 15:56:24 +02:00
|
|
|
struct icon *icon = NULL;
|
2010-03-30 21:26:26 +02:00
|
|
|
const struct notify_data *data;
|
2006-02-19 18:50:27 +01:00
|
|
|
NOTIFYICONDATAW nid;
|
2008-05-13 20:56:25 +02:00
|
|
|
int ret = FALSE;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2010-03-30 21:26:26 +02:00
|
|
|
if (cds->cbData < sizeof(*data)) return FALSE;
|
|
|
|
data = cds->lpData;
|
|
|
|
|
|
|
|
nid.cbSize = sizeof(nid);
|
|
|
|
nid.hWnd = LongToHandle( data->hWnd );
|
|
|
|
nid.uID = data->uID;
|
|
|
|
nid.uFlags = data->uFlags;
|
|
|
|
nid.uCallbackMessage = data->uCallbackMessage;
|
|
|
|
nid.hIcon = 0;
|
|
|
|
nid.dwState = data->dwState;
|
|
|
|
nid.dwStateMask = data->dwStateMask;
|
|
|
|
nid.u.uTimeout = data->u.uTimeout;
|
|
|
|
nid.dwInfoFlags = data->dwInfoFlags;
|
|
|
|
nid.guidItem = data->guidItem;
|
|
|
|
lstrcpyW( nid.szTip, data->szTip );
|
|
|
|
lstrcpyW( nid.szInfo, data->szInfo );
|
|
|
|
lstrcpyW( nid.szInfoTitle, data->szInfoTitle );
|
|
|
|
nid.hBalloonIcon = 0;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
/* FIXME: if statement only needed because we don't support interprocess
|
|
|
|
* icon handles */
|
2010-03-30 21:26:26 +02:00
|
|
|
if ((nid.uFlags & NIF_ICON) && cds->cbData > sizeof(*data))
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
LONG cbMaskBits;
|
|
|
|
LONG cbColourBits;
|
2010-03-30 21:26:26 +02:00
|
|
|
const char *buffer = (const char *)(data + 1);
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2010-03-30 21:26:26 +02:00
|
|
|
cbMaskBits = (data->width * data->height + 15) / 16 * 2;
|
|
|
|
cbColourBits = (data->planes * data->width * data->height * data->bpp + 15) / 16 * 2;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2010-03-30 21:26:26 +02:00
|
|
|
if (cds->cbData < sizeof(*data) + cbMaskBits + cbColourBits)
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
WINE_ERR("buffer underflow\n");
|
2008-02-05 15:17:49 +01:00
|
|
|
return FALSE;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
2010-03-30 21:26:26 +02:00
|
|
|
nid.hIcon = CreateIcon(NULL, data->width, data->height, data->planes, data->bpp,
|
2006-02-19 18:50:27 +01:00
|
|
|
buffer, buffer + cbMaskBits);
|
|
|
|
}
|
|
|
|
|
2017-06-02 17:20:33 +02:00
|
|
|
/* try forwarding to the display driver first */
|
2008-04-08 15:56:24 +02:00
|
|
|
if (cds->dwData == NIM_ADD || !(icon = get_icon( nid.hWnd, nid.uID )))
|
2008-04-08 15:47:36 +02:00
|
|
|
{
|
2008-05-13 20:56:25 +02:00
|
|
|
if (wine_notify_icon && ((ret = wine_notify_icon( cds->dwData, &nid )) != -1))
|
2008-04-08 15:56:24 +02:00
|
|
|
{
|
2010-03-30 21:26:26 +02:00
|
|
|
if (nid.hIcon) DestroyIcon( nid.hIcon );
|
2008-05-13 20:56:25 +02:00
|
|
|
return ret;
|
2008-04-08 15:56:24 +02:00
|
|
|
}
|
2008-05-13 20:56:25 +02:00
|
|
|
ret = FALSE;
|
2008-04-08 15:47:36 +02:00
|
|
|
}
|
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
switch (cds->dwData)
|
|
|
|
{
|
|
|
|
case NIM_ADD:
|
2008-02-05 15:17:49 +01:00
|
|
|
ret = add_icon(&nid);
|
2006-02-19 18:50:27 +01:00
|
|
|
break;
|
|
|
|
case NIM_DELETE:
|
2008-04-08 15:56:24 +02:00
|
|
|
if (icon) ret = delete_icon( icon );
|
2006-02-19 18:50:27 +01:00
|
|
|
break;
|
|
|
|
case NIM_MODIFY:
|
2008-04-08 15:56:24 +02:00
|
|
|
if (icon) ret = modify_icon( icon, &nid );
|
2006-02-19 18:50:27 +01:00
|
|
|
break;
|
2016-10-10 16:35:40 +02:00
|
|
|
case NIM_SETVERSION:
|
2016-10-19 09:22:48 +02:00
|
|
|
if (icon)
|
|
|
|
{
|
|
|
|
icon->version = nid.u.uVersion;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
2016-10-10 16:35:40 +02:00
|
|
|
break;
|
2006-02-19 18:50:27 +01:00
|
|
|
default:
|
|
|
|
WINE_FIXME("unhandled tray message: %ld\n", cds->dwData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-30 21:26:26 +02:00
|
|
|
if (nid.hIcon) DestroyIcon( nid.hIcon );
|
2016-05-31 07:01:33 +02:00
|
|
|
sync_taskbar_buttons();
|
2008-02-05 15:17:49 +01:00
|
|
|
return ret;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
2016-05-31 07:01:33 +02:00
|
|
|
static void add_taskbar_button( HWND hwnd )
|
|
|
|
{
|
|
|
|
struct taskbar_button *win;
|
|
|
|
|
2016-06-10 10:39:54 +02:00
|
|
|
if (hide_systray) return;
|
|
|
|
|
2016-05-31 07:01:33 +02:00
|
|
|
/* ignore our own windows */
|
|
|
|
if (hwnd)
|
|
|
|
{
|
|
|
|
DWORD process;
|
|
|
|
if (!GetWindowThreadProcessId( hwnd, &process ) || process == GetCurrentProcessId()) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(win = HeapAlloc( GetProcessHeap(), 0, sizeof(*win) ))) return;
|
|
|
|
win->hwnd = hwnd;
|
|
|
|
win->button = CreateWindowW( WC_BUTTONW, NULL, WS_CHILD | BS_OWNERDRAW,
|
|
|
|
0, 0, 0, 0, tray_window, (HMENU)hwnd, 0, 0 );
|
|
|
|
list_add_tail( &taskbar_buttons, &win->entry );
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct taskbar_button *find_taskbar_button( HWND hwnd )
|
|
|
|
{
|
|
|
|
struct taskbar_button *win;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( win, &taskbar_buttons, struct taskbar_button, entry )
|
|
|
|
if (win->hwnd == hwnd) return win;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_taskbar_button( HWND hwnd )
|
|
|
|
{
|
|
|
|
struct taskbar_button *win = find_taskbar_button( hwnd );
|
|
|
|
|
|
|
|
if (!win) return;
|
|
|
|
list_remove( &win->entry );
|
|
|
|
DestroyWindow( win->button );
|
|
|
|
HeapFree( GetProcessHeap(), 0, win );
|
|
|
|
}
|
|
|
|
|
2016-05-27 14:26:17 +02:00
|
|
|
static void paint_taskbar_button( const DRAWITEMSTRUCT *dis )
|
|
|
|
{
|
|
|
|
RECT rect;
|
2016-05-31 07:01:33 +02:00
|
|
|
UINT flags = DC_TEXT;
|
|
|
|
struct taskbar_button *win = find_taskbar_button( LongToHandle( dis->CtlID ));
|
2016-05-27 14:26:17 +02:00
|
|
|
|
2016-05-31 07:01:33 +02:00
|
|
|
if (!win) return;
|
2016-05-27 14:26:17 +02:00
|
|
|
GetClientRect( dis->hwndItem, &rect );
|
|
|
|
DrawFrameControl( dis->hDC, &rect, DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_ADJUSTRECT |
|
|
|
|
((dis->itemState & ODS_SELECTED) ? DFCS_PUSHED : 0 ));
|
2016-05-31 07:01:33 +02:00
|
|
|
if (win->hwnd)
|
|
|
|
{
|
|
|
|
flags |= win->active ? DC_ACTIVE : DC_INBUTTON;
|
|
|
|
DrawCaptionTempW( win->hwnd, dis->hDC, &rect, 0, 0, NULL, flags );
|
|
|
|
}
|
|
|
|
else /* start button */
|
|
|
|
DrawCaptionTempW( 0, dis->hDC, &rect, 0, 0, start_label, flags | DC_INBUTTON | DC_ICON );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void click_taskbar_button( HWND button )
|
|
|
|
{
|
|
|
|
LONG_PTR id = GetWindowLongPtrW( button, GWLP_ID );
|
|
|
|
HWND hwnd = (HWND)id;
|
|
|
|
|
|
|
|
if (!hwnd) /* start button */
|
|
|
|
{
|
|
|
|
do_startmenu( tray_window );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsIconic( hwnd ))
|
|
|
|
{
|
|
|
|
SendMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWindowEnabled( hwnd ))
|
|
|
|
{
|
|
|
|
if (hwnd == GetForegroundWindow())
|
|
|
|
{
|
|
|
|
SendMessageW( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* look for an enabled window owned by this one */
|
|
|
|
{
|
|
|
|
HWND owned = GetWindow( GetDesktopWindow(), GW_CHILD );
|
|
|
|
while (owned && owned != hwnd)
|
|
|
|
{
|
|
|
|
if (IsWindowVisible( owned ) &&
|
|
|
|
IsWindowEnabled( owned ) &&
|
|
|
|
(GetWindow( owned, GW_OWNER ) == hwnd))
|
|
|
|
break;
|
|
|
|
owned = GetWindow( owned, GW_HWNDNEXT );
|
|
|
|
}
|
|
|
|
hwnd = owned;
|
|
|
|
}
|
|
|
|
SetForegroundWindow( hwnd );
|
2016-05-27 14:26:17 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 08:35:38 +02:00
|
|
|
static void show_taskbar_contextmenu( HWND button, LPARAM lparam )
|
|
|
|
{
|
|
|
|
ULONG_PTR id = GetWindowLongPtrW( button, GWLP_ID );
|
|
|
|
|
|
|
|
if (id) SendNotifyMessageW( (HWND)id, WM_POPUPSYSTEMMENU, 0, lparam );
|
|
|
|
}
|
|
|
|
|
2008-08-27 19:31:14 +02:00
|
|
|
static void do_hide_systray(void)
|
|
|
|
{
|
|
|
|
SetWindowPos( tray_window, 0,
|
|
|
|
GetSystemMetrics(SM_XVIRTUALSCREEN) + GetSystemMetrics(SM_CXVIRTUALSCREEN),
|
|
|
|
GetSystemMetrics(SM_YVIRTUALSCREEN) + GetSystemMetrics(SM_CYVIRTUALSCREEN),
|
|
|
|
0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
|
|
|
|
}
|
|
|
|
|
2016-10-12 10:57:45 +02:00
|
|
|
static BOOL notify_owner( struct icon *icon, UINT msg, POINT pt )
|
|
|
|
{
|
|
|
|
WPARAM wp = icon->id;
|
|
|
|
LPARAM lp = msg;
|
|
|
|
|
|
|
|
if (icon->version >= NOTIFY_VERSION_4)
|
|
|
|
{
|
|
|
|
ClientToScreen( tray_window, &pt );
|
|
|
|
wp = MAKEWPARAM( pt.x, pt.y );
|
|
|
|
lp = MAKELPARAM( msg, icon->id );
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "relaying 0x%x\n", msg );
|
|
|
|
if (!PostMessageW( icon->owner, icon->callback_message, wp, lp ) &&
|
|
|
|
(GetLastError() == ERROR_INVALID_WINDOW_HANDLE))
|
|
|
|
{
|
|
|
|
WARN( "application window was destroyed, removing icon %u\n", icon->id );
|
|
|
|
delete_icon( icon );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-27 14:08:44 +02:00
|
|
|
static void do_show_systray(void)
|
|
|
|
{
|
2016-05-31 07:01:33 +02:00
|
|
|
SIZE size;
|
2016-05-27 14:15:12 +02:00
|
|
|
NONCLIENTMETRICSW ncm;
|
|
|
|
HFONT font;
|
2016-05-27 14:08:44 +02:00
|
|
|
HDC hdc = GetDC( 0 );
|
|
|
|
|
2016-05-27 14:15:12 +02:00
|
|
|
ncm.cbSize = sizeof(NONCLIENTMETRICSW);
|
|
|
|
SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncm, 0 );
|
|
|
|
font = CreateFontIndirectW( &ncm.lfCaptionFont );
|
2016-05-27 14:08:44 +02:00
|
|
|
/* FIXME: Implement BCM_GETIDEALSIZE and use that instead. */
|
2016-05-27 14:15:12 +02:00
|
|
|
SelectObject( hdc, font );
|
2016-05-31 07:01:33 +02:00
|
|
|
GetTextExtentPointA( hdc, "abcdefghijklmnopqrstuvwxyz", 26, &size );
|
|
|
|
taskbar_button_width = size.cx;
|
|
|
|
GetTextExtentPointW( hdc, start_label, lstrlenW(start_label), &size );
|
2016-05-27 14:08:44 +02:00
|
|
|
/* add some margins (FIXME) */
|
2016-05-31 07:01:33 +02:00
|
|
|
size.cx += 12 + GetSystemMetrics( SM_CXSMICON );
|
|
|
|
size.cy += 4;
|
2016-05-27 14:08:44 +02:00
|
|
|
ReleaseDC( 0, hdc );
|
2016-05-27 14:26:17 +02:00
|
|
|
DeleteObject( font );
|
2016-05-27 14:08:44 +02:00
|
|
|
|
|
|
|
tray_width = GetSystemMetrics( SM_CXSCREEN );
|
2016-05-31 07:01:33 +02:00
|
|
|
tray_height = max( icon_cy, size.cy );
|
|
|
|
start_button_width = size.cx;
|
2016-05-27 14:08:44 +02:00
|
|
|
SetWindowPos( tray_window, HWND_TOPMOST, 0, GetSystemMetrics( SM_CYSCREEN ) - tray_height,
|
|
|
|
tray_width, tray_height, SWP_NOACTIVATE | SWP_SHOWWINDOW );
|
2016-06-10 10:39:54 +02:00
|
|
|
sync_taskbar_buttons();
|
2016-05-27 14:08:44 +02:00
|
|
|
}
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
static LRESULT WINAPI tray_wndproc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
2008-02-07 16:23:54 +01:00
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
2008-04-08 15:56:24 +02:00
|
|
|
case WM_COPYDATA:
|
|
|
|
return handle_incoming((HWND)wparam, (COPYDATASTRUCT *)lparam);
|
2008-02-07 16:23:54 +01:00
|
|
|
|
2008-08-27 19:31:14 +02:00
|
|
|
case WM_DISPLAYCHANGE:
|
2016-06-17 05:08:03 +02:00
|
|
|
if (hide_systray || (!nb_displayed && !enable_shell)) do_hide_systray();
|
2016-05-27 14:08:44 +02:00
|
|
|
else do_show_systray();
|
2008-08-27 19:31:14 +02:00
|
|
|
break;
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
case WM_TIMER:
|
2010-12-15 17:16:52 +01:00
|
|
|
switch (wparam)
|
|
|
|
{
|
|
|
|
case BALLOON_CREATE_TIMER: balloon_create_timer(); break;
|
|
|
|
case BALLOON_SHOW_TIMER: balloon_timer(); break;
|
|
|
|
}
|
2008-04-08 15:56:24 +02:00
|
|
|
break;
|
2008-02-07 16:23:54 +01:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
hdc = BeginPaint( hwnd, &ps );
|
2010-11-01 19:38:28 +01:00
|
|
|
for (i = 0; i < nb_displayed; i++)
|
2008-04-08 15:56:24 +02:00
|
|
|
{
|
2010-11-01 19:38:28 +01:00
|
|
|
RECT dummy, rect = get_icon_rect( displayed[i] );
|
|
|
|
if (IntersectRect( &dummy, &rect, &ps.rcPaint ))
|
|
|
|
DrawIconEx( hdc, rect.left + ICON_BORDER, rect.top + ICON_BORDER, displayed[i]->image,
|
|
|
|
icon_cx - 2*ICON_BORDER, icon_cy - 2*ICON_BORDER,
|
2008-04-08 15:56:24 +02:00
|
|
|
0, 0, DI_DEFAULTSIZE|DI_NORMAL);
|
|
|
|
}
|
|
|
|
EndPaint( hwnd, &ps );
|
2008-02-07 16:23:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
|
case WM_RBUTTONDBLCLK:
|
|
|
|
case WM_MBUTTONDBLCLK:
|
|
|
|
{
|
|
|
|
MSG message;
|
2016-10-12 10:57:45 +02:00
|
|
|
POINT pt = { (short)LOWORD(lparam), (short)HIWORD(lparam) };
|
|
|
|
struct icon *icon = icon_from_point( pt.x, pt.y );
|
2008-04-08 15:56:24 +02:00
|
|
|
if (!icon) break;
|
|
|
|
|
|
|
|
message.hwnd = hwnd;
|
|
|
|
message.message = msg;
|
|
|
|
message.wParam = wparam;
|
|
|
|
message.lParam = lparam;
|
|
|
|
SendMessageW( icon->tooltip, TTM_RELAYEVENT, 0, (LPARAM)&message );
|
|
|
|
|
2016-10-12 10:57:45 +02:00
|
|
|
if (!notify_owner( icon, msg, pt )) break;
|
2016-10-10 16:35:42 +02:00
|
|
|
|
2016-10-12 10:57:45 +02:00
|
|
|
if (icon->version > 0)
|
2008-02-07 16:23:54 +01:00
|
|
|
{
|
2016-10-12 10:57:45 +02:00
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
notify_owner( icon, WM_CONTEXTMENU, pt );
|
|
|
|
break;
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
notify_owner( icon, NIN_SELECT, pt );
|
|
|
|
break;
|
|
|
|
}
|
2008-02-07 16:23:54 +01:00
|
|
|
}
|
|
|
|
break;
|
2008-04-08 15:56:24 +02:00
|
|
|
}
|
2008-02-07 16:23:54 +01:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
case WM_CLOSE:
|
|
|
|
/* don't destroy the tray window, just hide it */
|
|
|
|
ShowWindow( hwnd, SW_HIDE );
|
|
|
|
return 0;
|
2008-02-07 16:23:54 +01:00
|
|
|
|
2016-05-27 14:26:17 +02:00
|
|
|
case WM_DRAWITEM:
|
|
|
|
paint_taskbar_button( (const DRAWITEMSTRUCT *)lparam );
|
|
|
|
break;
|
|
|
|
|
2013-12-06 21:16:54 +01:00
|
|
|
case WM_COMMAND:
|
2016-05-31 07:01:33 +02:00
|
|
|
if (HIWORD(wparam) == BN_CLICKED) click_taskbar_button( (HWND)lparam );
|
2013-12-06 21:16:54 +01:00
|
|
|
break;
|
|
|
|
|
2016-06-08 08:35:38 +02:00
|
|
|
case WM_CONTEXTMENU:
|
|
|
|
show_taskbar_contextmenu( (HWND)wparam, lparam );
|
|
|
|
break;
|
|
|
|
|
2016-05-31 07:01:33 +02:00
|
|
|
case WM_MOUSEACTIVATE:
|
|
|
|
return MA_NOACTIVATE;
|
|
|
|
|
2013-12-06 21:16:54 +01:00
|
|
|
case WM_INITMENUPOPUP:
|
|
|
|
case WM_MENUCOMMAND:
|
|
|
|
return menu_wndproc(hwnd, msg, wparam, lparam);
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
default:
|
|
|
|
return DefWindowProcW( hwnd, msg, wparam, lparam );
|
2008-02-07 16:23:54 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-11 13:53:34 +02:00
|
|
|
/* notification posted to the desktop window */
|
2016-05-31 06:54:07 +02:00
|
|
|
void handle_parent_notify( HWND hwnd, WPARAM wp )
|
|
|
|
{
|
|
|
|
switch (LOWORD(wp))
|
|
|
|
{
|
2016-05-31 07:01:33 +02:00
|
|
|
case WM_CREATE:
|
|
|
|
add_taskbar_button( hwnd );
|
|
|
|
break;
|
2016-05-31 06:54:07 +02:00
|
|
|
case WM_DESTROY:
|
2016-05-31 07:01:33 +02:00
|
|
|
remove_taskbar_button( hwnd );
|
2016-05-31 06:54:07 +02:00
|
|
|
cleanup_systray_window( hwnd );
|
|
|
|
break;
|
|
|
|
}
|
2016-05-31 07:01:33 +02:00
|
|
|
sync_taskbar_buttons();
|
2016-05-31 06:54:07 +02:00
|
|
|
}
|
|
|
|
|
2007-10-23 15:30:30 +02:00
|
|
|
/* this function creates the listener window */
|
2013-12-16 23:17:21 +01:00
|
|
|
void initialize_systray( HMODULE graphics_driver, BOOL using_root, BOOL arg_enable_shell )
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
2008-09-03 11:30:44 +02:00
|
|
|
WNDCLASSEXW class;
|
2008-04-08 15:56:24 +02:00
|
|
|
static const WCHAR classname[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2017-06-02 17:20:33 +02:00
|
|
|
if (using_root) wine_notify_icon = (void *)GetProcAddress( graphics_driver, "wine_notify_icon" );
|
2008-04-08 15:47:36 +02:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
icon_cx = GetSystemMetrics( SM_CXSMICON ) + 2*ICON_BORDER;
|
|
|
|
icon_cy = GetSystemMetrics( SM_CYSMICON ) + 2*ICON_BORDER;
|
2010-11-01 19:38:28 +01:00
|
|
|
hide_systray = using_root;
|
2013-12-16 23:17:21 +01:00
|
|
|
enable_shell = arg_enable_shell;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
/* register the systray listener window class */
|
|
|
|
ZeroMemory(&class, sizeof(class));
|
|
|
|
class.cbSize = sizeof(class);
|
2010-11-01 19:38:28 +01:00
|
|
|
class.style = CS_DBLCLKS | CS_HREDRAW;
|
2008-04-08 15:56:24 +02:00
|
|
|
class.lpfnWndProc = tray_wndproc;
|
2006-02-19 18:50:27 +01:00
|
|
|
class.hInstance = NULL;
|
2008-09-03 11:30:44 +02:00
|
|
|
class.hIcon = LoadIconW(0, (LPCWSTR)IDI_WINLOGO);
|
|
|
|
class.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
|
2006-02-19 18:50:27 +01:00
|
|
|
class.hbrBackground = (HBRUSH) COLOR_WINDOW;
|
2013-02-06 12:46:14 +01:00
|
|
|
class.lpszClassName = classname;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2008-09-03 11:30:44 +02:00
|
|
|
if (!RegisterClassExW(&class))
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
WINE_ERR("Could not register SysTray window class\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-01 19:38:28 +01:00
|
|
|
tray_window = CreateWindowExW( WS_EX_NOACTIVATE, classname, NULL, WS_POPUP,
|
2016-05-27 14:08:44 +02:00
|
|
|
0, GetSystemMetrics( SM_CYSCREEN ), 0, 0, 0, 0, 0, 0 );
|
2008-04-08 15:56:24 +02:00
|
|
|
if (!tray_window)
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
WINE_ERR("Could not create tray window\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-08-27 19:31:14 +02:00
|
|
|
|
2018-08-21 23:10:20 +02:00
|
|
|
LoadStringW( NULL, IDS_START_LABEL, start_label, ARRAY_SIZE( start_label ));
|
2013-12-05 23:29:31 +01:00
|
|
|
|
2016-05-31 07:01:33 +02:00
|
|
|
add_taskbar_button( 0 );
|
2013-12-16 23:17:21 +01:00
|
|
|
|
2008-08-27 19:31:14 +02:00
|
|
|
if (hide_systray) do_hide_systray();
|
2016-05-27 14:08:44 +02:00
|
|
|
else if (enable_shell) do_show_systray();
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|