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>
|
|
|
|
|
|
|
|
#define UNICODE
|
|
|
|
#define _WIN32_IE 0x500
|
|
|
|
#include <windows.h>
|
2006-08-31 03:42:49 +02:00
|
|
|
#include <commctrl.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"
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(systray);
|
|
|
|
|
2006-02-22 17:01:15 +01:00
|
|
|
#define IS_OPTION_FALSE(ch) \
|
|
|
|
((ch) == 'n' || (ch) == 'N' || (ch) == 'f' || (ch) == 'F' || (ch) == '0')
|
|
|
|
|
2008-05-13 20:56:25 +02:00
|
|
|
static int (*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 */
|
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 */
|
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 );
|
|
|
|
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
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
static BOOL hide_systray;
|
|
|
|
static int icon_cx, icon_cy;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
#define MIN_DISPLAYED 8
|
|
|
|
#define ICON_BORDER 2
|
2006-02-19 18:50:27 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
/* compute the size of the tray window */
|
|
|
|
static SIZE get_window_size(void)
|
|
|
|
{
|
|
|
|
SIZE size;
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
rect.left = 0;
|
|
|
|
rect.top = 0;
|
|
|
|
rect.right = icon_cx * max( nb_displayed, MIN_DISPLAYED );
|
|
|
|
rect.bottom = icon_cy;
|
|
|
|
AdjustWindowRect( &rect, WS_CAPTION, FALSE );
|
|
|
|
size.cx = rect.right - rect.left;
|
|
|
|
size.cy = rect.bottom - rect.top;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2008-02-07 16:23:52 +01:00
|
|
|
/* Creates tooltip window for icon. */
|
|
|
|
static void create_tooltip(struct icon *icon)
|
2006-08-31 03:42:49 +02:00
|
|
|
{
|
|
|
|
TTTOOLINFOW ti;
|
2008-02-07 16:23:52 +01:00
|
|
|
static BOOL tooltips_initialized = FALSE;
|
|
|
|
|
|
|
|
/* Register tooltip classes if this is the first icon */
|
|
|
|
if (!tooltips_initialized)
|
|
|
|
{
|
|
|
|
INITCOMMONCONTROLSEX init_tooltip;
|
|
|
|
|
|
|
|
init_tooltip.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
|
|
|
init_tooltip.dwICC = ICC_TAB_CLASSES;
|
|
|
|
|
|
|
|
InitCommonControlsEx(&init_tooltip);
|
|
|
|
tooltips_initialized = TRUE;
|
|
|
|
}
|
2006-08-31 03:42:49 +02:00
|
|
|
|
2008-02-07 16:23:52 +01:00
|
|
|
icon->tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
|
|
|
|
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;
|
2008-04-08 15:56:24 +02:00
|
|
|
if (icon->display != -1)
|
|
|
|
{
|
|
|
|
ti.rect.left = icon_cx * icon->display;
|
|
|
|
ti.rect.right = icon_cx * (icon->display + 1);
|
|
|
|
ti.rect.top = 0;
|
|
|
|
ti.rect.bottom = icon_cy;
|
|
|
|
}
|
2008-02-07 16:23:52 +01:00
|
|
|
SendMessageW(icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
|
|
|
|
}
|
2006-08-31 03:42:49 +02:00
|
|
|
|
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;
|
|
|
|
if (icon->display != -1)
|
|
|
|
{
|
|
|
|
ti.rect.left = icon_cx * icon->display;
|
|
|
|
ti.rect.right = icon_cx * (icon->display + 1);
|
|
|
|
ti.rect.top = 0;
|
|
|
|
ti.rect.bottom = icon_cy;
|
|
|
|
}
|
|
|
|
SendMessageW( icon->tooltip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
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;
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
rect.left = start * icon_cx;
|
|
|
|
rect.top = 0;
|
|
|
|
rect.right = (end + 1) * icon_cx;
|
|
|
|
rect.bottom = icon_cy;
|
|
|
|
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 );
|
|
|
|
|
|
|
|
if (nb_displayed > MIN_DISPLAYED)
|
|
|
|
{
|
|
|
|
SIZE size = get_window_size();
|
|
|
|
SetWindowPos( tray_window, 0, 0, 0, size.cx, size.cy, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE );
|
|
|
|
}
|
|
|
|
else if (nb_displayed == 1)
|
|
|
|
{
|
|
|
|
if (!hide_systray) ShowWindow( tray_window, SW_SHOWNA );
|
|
|
|
}
|
2008-02-05 15:19:40 +01:00
|
|
|
|
2008-02-07 16:23:52 +01:00
|
|
|
create_tooltip(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;
|
|
|
|
|
|
|
|
if (nb_displayed >= MIN_DISPLAYED)
|
|
|
|
{
|
|
|
|
SIZE size = get_window_size();
|
|
|
|
SetWindowPos( tray_window, 0, 0, 0, size.cx, size.cy, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE );
|
|
|
|
}
|
|
|
|
else if (!nb_displayed)
|
|
|
|
{
|
|
|
|
ShowWindow( tray_window, SW_HIDE );
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-02-07 16:23:54 +01:00
|
|
|
if ((nid->uFlags & NIF_STATE) && (nid->dwStateMask & NIS_HIDDEN))
|
2008-04-08 15:56:24 +02:00
|
|
|
{
|
|
|
|
if (nid->dwState & NIS_HIDDEN) hide_icon( icon );
|
|
|
|
else show_icon( icon );
|
|
|
|
}
|
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)
|
|
|
|
{
|
2008-02-07 16:23:52 +01:00
|
|
|
lstrcpynW(icon->tiptext, nid->szTip, sizeof(icon->tiptext)/sizeof(WCHAR));
|
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)
|
|
|
|
{
|
|
|
|
WINE_FIXME("balloon tip title %s, message %s\n", wine_dbgstr_w(nid->szInfoTitle), wine_dbgstr_w(nid->szInfo));
|
|
|
|
}
|
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
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
modify_icon( icon, nid );
|
|
|
|
/* show icon, unless hidden state was explicitly specified */
|
|
|
|
if (!((nid->uFlags & NIF_STATE) && (nid->dwStateMask & NIS_HIDDEN))) show_icon( icon );
|
|
|
|
return TRUE;
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
/* cleanup icons belonging to windows that have been destroyed */
|
|
|
|
static void cleanup_destroyed_windows(void)
|
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 )
|
|
|
|
if (!IsWindow( icon->owner )) delete_icon( icon );
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
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;
|
2006-02-19 18:50:27 +01:00
|
|
|
NOTIFYICONDATAW nid;
|
2007-03-18 11:49:03 +01:00
|
|
|
DWORD cbSize;
|
2008-05-13 20:56:25 +02:00
|
|
|
int ret = FALSE;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2008-02-05 15:17:49 +01:00
|
|
|
if (cds->cbData < NOTIFYICONDATAW_V1_SIZE) return FALSE;
|
2007-03-18 11:49:03 +01:00
|
|
|
cbSize = ((PNOTIFYICONDATA)cds->lpData)->cbSize;
|
2008-02-05 15:17:49 +01:00
|
|
|
if (cbSize < NOTIFYICONDATAW_V1_SIZE) return FALSE;
|
2007-03-18 11:49:03 +01:00
|
|
|
|
|
|
|
ZeroMemory(&nid, sizeof(nid));
|
|
|
|
memcpy(&nid, cds->lpData, min(sizeof(nid), cbSize));
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
/* FIXME: if statement only needed because we don't support interprocess
|
|
|
|
* icon handles */
|
2007-03-18 11:49:03 +01:00
|
|
|
if ((nid.uFlags & NIF_ICON) && (cds->cbData >= nid.cbSize + 2 * sizeof(BITMAP)))
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
LONG cbMaskBits;
|
|
|
|
LONG cbColourBits;
|
|
|
|
BITMAP bmMask;
|
|
|
|
BITMAP bmColour;
|
|
|
|
const char *buffer = cds->lpData;
|
|
|
|
|
2007-03-18 11:49:03 +01:00
|
|
|
buffer += nid.cbSize;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
memcpy(&bmMask, buffer, sizeof(bmMask));
|
|
|
|
buffer += sizeof(bmMask);
|
|
|
|
memcpy(&bmColour, buffer, sizeof(bmColour));
|
|
|
|
buffer += sizeof(bmColour);
|
|
|
|
|
|
|
|
cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel) / 8;
|
|
|
|
cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel) / 8;
|
|
|
|
|
2007-03-18 11:49:03 +01:00
|
|
|
if (cds->cbData < nid.cbSize + 2 * sizeof(BITMAP) + 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
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if ((bmColour.bmWidth != bmMask.bmWidth) || (bmColour.bmHeight != bmMask.bmHeight))
|
|
|
|
{
|
|
|
|
WINE_ERR("colour and mask bitmaps aren't consistent\n");
|
2008-02-05 15:17:49 +01:00
|
|
|
return FALSE;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nid.hIcon = CreateIcon(NULL, bmColour.bmWidth, bmColour.bmHeight,
|
|
|
|
bmColour.bmPlanes, bmColour.bmBitsPixel,
|
|
|
|
buffer, buffer + cbMaskBits);
|
|
|
|
}
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
/* try forward to x11drv first */
|
|
|
|
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
|
|
|
{
|
|
|
|
if (nid.uFlags & NIF_ICON) 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;
|
|
|
|
default:
|
|
|
|
WINE_FIXME("unhandled tray message: %ld\n", cds->dwData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: if statement only needed because we don't support interprocess
|
|
|
|
* icon handles */
|
|
|
|
if (nid.uFlags & NIF_ICON)
|
|
|
|
DestroyIcon(nid.hIcon);
|
2008-02-05 15:17:49 +01:00
|
|
|
|
|
|
|
return ret;
|
2006-02-19 18:50:27 +01: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-04-08 15:56:24 +02:00
|
|
|
case WM_TIMER:
|
|
|
|
cleanup_destroyed_windows();
|
|
|
|
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 );
|
|
|
|
for (i = ps.rcPaint.left / icon_cx;
|
|
|
|
(i < (ps.rcPaint.right + icon_cx - 1) / icon_cx) && (i < nb_displayed);
|
|
|
|
i++)
|
|
|
|
{
|
|
|
|
DrawIconEx( hdc, i * icon_cx + ICON_BORDER, ICON_BORDER, displayed[i]->image,
|
|
|
|
icon_cx - 2*ICON_BORDER, icon_cy - 2*ICON_BORDER,
|
|
|
|
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;
|
|
|
|
struct icon *icon = icon_from_point( (short)LOWORD(lparam), (short)HIWORD(lparam) );
|
|
|
|
if (!icon) break;
|
|
|
|
|
2008-02-07 16:23:54 +01:00
|
|
|
/* notify the owner hwnd of the message */
|
|
|
|
WINE_TRACE("relaying 0x%x\n", msg);
|
2008-04-08 15:56:24 +02:00
|
|
|
|
|
|
|
message.hwnd = hwnd;
|
|
|
|
message.message = msg;
|
|
|
|
message.wParam = wparam;
|
|
|
|
message.lParam = lparam;
|
|
|
|
SendMessageW( icon->tooltip, TTM_RELAYEVENT, 0, (LPARAM)&message );
|
|
|
|
|
|
|
|
if (!PostMessageW( icon->owner, icon->callback_message, (WPARAM) icon->id, (LPARAM) msg ) &&
|
|
|
|
GetLastError() == ERROR_INVALID_WINDOW_HANDLE)
|
2008-02-07 16:23:54 +01:00
|
|
|
{
|
|
|
|
WINE_WARN("application window was destroyed without removing "
|
|
|
|
"notification icon, removing automatically\n");
|
2008-04-08 15:56:24 +02:00
|
|
|
delete_icon( icon );
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
static BOOL is_systray_hidden(void)
|
|
|
|
{
|
2006-02-22 17:01:15 +01:00
|
|
|
const WCHAR show_systray_keyname[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
|
|
|
|
'X','1','1',' ','D','r','i','v','e','r',0};
|
|
|
|
const WCHAR show_systray_valuename[] = {'S','h','o','w','S','y','s','t','r','a','y',0};
|
2006-02-19 18:50:27 +01:00
|
|
|
HKEY hkey;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2006-02-22 17:01:15 +01:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\X11 Driver */
|
|
|
|
if (RegOpenKeyW(HKEY_CURRENT_USER, show_systray_keyname, &hkey) == ERROR_SUCCESS)
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
2006-02-22 17:01:15 +01:00
|
|
|
WCHAR value[10];
|
|
|
|
DWORD type, size = sizeof(value);
|
|
|
|
if (RegQueryValueExW(hkey, show_systray_valuename, 0, &type, (LPBYTE)&value, &size) == ERROR_SUCCESS)
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
2006-02-22 17:01:15 +01:00
|
|
|
ret = IS_OPTION_FALSE(value[0]);
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-23 15:30:30 +02:00
|
|
|
/* this function creates the listener window */
|
2006-02-19 18:50:27 +01:00
|
|
|
void initialize_systray(void)
|
|
|
|
{
|
2008-04-08 15:47:36 +02:00
|
|
|
HMODULE x11drv;
|
2008-04-08 15:56:24 +02:00
|
|
|
SIZE size;
|
2006-02-19 18:50:27 +01:00
|
|
|
WNDCLASSEX 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};
|
|
|
|
static const WCHAR winname[] = {'W','i','n','e',' ','S','y','s','t','e','m',' ','T','r','a','y',0};
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2008-04-08 15:47:36 +02:00
|
|
|
if ((x11drv = GetModuleHandleA( "winex11.drv" )))
|
|
|
|
wine_notify_icon = (void *)GetProcAddress( x11drv, "wine_notify_icon" );
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
icon_cx = GetSystemMetrics( SM_CXSMICON ) + 2*ICON_BORDER;
|
|
|
|
icon_cy = GetSystemMetrics( SM_CYSMICON ) + 2*ICON_BORDER;
|
2006-02-19 18:50:27 +01:00
|
|
|
hide_systray = is_systray_hidden();
|
|
|
|
|
|
|
|
/* register the systray listener window class */
|
|
|
|
ZeroMemory(&class, sizeof(class));
|
|
|
|
class.cbSize = sizeof(class);
|
2008-04-08 15:56:24 +02:00
|
|
|
class.style = CS_DBLCLKS;
|
|
|
|
class.lpfnWndProc = tray_wndproc;
|
2006-02-19 18:50:27 +01:00
|
|
|
class.hInstance = NULL;
|
|
|
|
class.hIcon = LoadIcon(0, IDI_WINLOGO);
|
|
|
|
class.hCursor = LoadCursor(0, IDC_ARROW);
|
|
|
|
class.hbrBackground = (HBRUSH) COLOR_WINDOW;
|
|
|
|
class.lpszClassName = (WCHAR *) &classname;
|
|
|
|
|
|
|
|
if (!RegisterClassEx(&class))
|
|
|
|
{
|
|
|
|
WINE_ERR("Could not register SysTray window class\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-08 15:56:24 +02:00
|
|
|
size = get_window_size();
|
|
|
|
tray_window = CreateWindowW( classname, winname, WS_OVERLAPPED | WS_CAPTION,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, size.cx, size.cy, 0, 0, 0, 0 );
|
|
|
|
if (!tray_window)
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
WINE_ERR("Could not create tray window\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-04-08 15:56:24 +02:00
|
|
|
SetTimer( tray_window, 1, 2000, NULL );
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|