1999-12-12 00:54:59 +01:00
|
|
|
/*
|
2006-02-19 18:50:27 +01:00
|
|
|
* Systray handling
|
1999-12-12 00:54:59 +01:00
|
|
|
*
|
2006-02-19 18:50:27 +01:00
|
|
|
* Copyright 1999 Kai Morich <kai.morich@bigfoot.de>
|
|
|
|
* Copyright 2004 Mike Hearn, for CodeWeavers
|
|
|
|
* Copyright 2005 Robert Shearman
|
1999-12-12 00:54:59 +01:00
|
|
|
*
|
2002-03-10 00:29:33 +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
|
1999-12-12 00:54:59 +01:00
|
|
|
*/
|
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
#define NONAMELESSUNION
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-08-20 20:22:31 +02:00
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
2006-02-19 18:50:27 +01:00
|
|
|
#include "winnls.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winuser.h"
|
1999-12-12 00:54:59 +01:00
|
|
|
#include "shellapi.h"
|
2005-11-08 17:08:17 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
#include "wine/debug.h"
|
2018-02-22 08:43:28 +01:00
|
|
|
#include "wine/heap.h"
|
2005-11-08 17:08:17 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(systray);
|
2005-11-08 17:08:17 +01:00
|
|
|
|
2006-07-07 00:23:14 +02:00
|
|
|
static const WCHAR classname[] = /* Shell_TrayWnd */ {'S','h','e','l','l','_','T','r','a','y','W','n','d','\0'};
|
2005-11-08 17:08:17 +01:00
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Shell_NotifyIcon [SHELL32.296]
|
|
|
|
* Shell_NotifyIconA [SHELL32.297]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
2006-02-19 18:50:27 +01:00
|
|
|
NOTIFYICONDATAW nidW;
|
2007-05-09 23:47:36 +02:00
|
|
|
INT cbSize;
|
|
|
|
|
|
|
|
/* Validate the cbSize as Windows XP does */
|
|
|
|
if (pnid->cbSize != NOTIFYICONDATAA_V1_SIZE &&
|
|
|
|
pnid->cbSize != NOTIFYICONDATAA_V2_SIZE &&
|
|
|
|
pnid->cbSize != NOTIFYICONDATAA_V3_SIZE &&
|
|
|
|
pnid->cbSize != sizeof(NOTIFYICONDATAA))
|
|
|
|
{
|
|
|
|
WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
|
|
|
|
pnid->cbSize, NOTIFYICONDATAA_V1_SIZE);
|
|
|
|
cbSize = NOTIFYICONDATAA_V1_SIZE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cbSize = pnid->cbSize;
|
2007-03-18 11:49:03 +01:00
|
|
|
|
|
|
|
ZeroMemory(&nidW, sizeof(nidW));
|
2006-02-19 18:50:27 +01:00
|
|
|
nidW.cbSize = sizeof(nidW);
|
|
|
|
nidW.hWnd = pnid->hWnd;
|
|
|
|
nidW.uID = pnid->uID;
|
|
|
|
nidW.uFlags = pnid->uFlags;
|
|
|
|
nidW.uCallbackMessage = pnid->uCallbackMessage;
|
|
|
|
nidW.hIcon = pnid->hIcon;
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
/* szTip */
|
2007-03-18 11:49:03 +01:00
|
|
|
if (pnid->uFlags & NIF_TIP)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pnid->szTip, -1, nidW.szTip, sizeof(nidW.szTip)/sizeof(WCHAR));
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2007-05-09 23:47:36 +02:00
|
|
|
if (cbSize >= NOTIFYICONDATAA_V2_SIZE)
|
2007-03-18 11:49:03 +01:00
|
|
|
{
|
|
|
|
nidW.dwState = pnid->dwState;
|
|
|
|
nidW.dwStateMask = pnid->dwStateMask;
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2007-03-18 11:49:03 +01:00
|
|
|
/* szInfo, szInfoTitle */
|
|
|
|
if (pnid->uFlags & NIF_INFO)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pnid->szInfo, -1, nidW.szInfo, sizeof(nidW.szInfo)/sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pnid->szInfoTitle, -1, nidW.szInfoTitle, sizeof(nidW.szInfoTitle)/sizeof(WCHAR));
|
|
|
|
}
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2007-03-18 11:49:03 +01:00
|
|
|
nidW.u.uTimeout = pnid->u.uTimeout;
|
|
|
|
nidW.dwInfoFlags = pnid->dwInfoFlags;
|
|
|
|
}
|
2006-02-19 18:50:27 +01:00
|
|
|
|
2007-05-09 23:47:36 +02:00
|
|
|
if (cbSize >= NOTIFYICONDATAA_V3_SIZE)
|
2007-03-18 11:49:03 +01:00
|
|
|
nidW.guidItem = pnid->guidItem;
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2007-05-09 23:47:36 +02:00
|
|
|
if (cbSize >= sizeof(NOTIFYICONDATAA))
|
2007-03-18 11:49:03 +01:00
|
|
|
nidW.hBalloonIcon = pnid->hBalloonIcon;
|
2006-02-19 18:50:27 +01:00
|
|
|
return Shell_NotifyIconW(dwMessage, &nidW);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Shell_NotifyIconW [SHELL32.298]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW nid)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
2006-02-19 18:50:27 +01:00
|
|
|
HWND tray;
|
|
|
|
COPYDATASTRUCT cds;
|
2010-03-30 21:26:26 +02:00
|
|
|
struct notify_data data_buffer;
|
|
|
|
struct notify_data *data = &data_buffer;
|
2008-02-05 15:17:49 +01:00
|
|
|
BOOL ret;
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2007-03-18 11:49:03 +01:00
|
|
|
TRACE("dwMessage = %d, nid->cbSize=%d\n", dwMessage, nid->cbSize);
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2007-05-09 23:47:36 +02:00
|
|
|
/* Validate the cbSize so that WM_COPYDATA doesn't crash the application */
|
|
|
|
if (nid->cbSize != NOTIFYICONDATAW_V1_SIZE &&
|
|
|
|
nid->cbSize != NOTIFYICONDATAW_V2_SIZE &&
|
|
|
|
nid->cbSize != NOTIFYICONDATAW_V3_SIZE &&
|
|
|
|
nid->cbSize != sizeof(NOTIFYICONDATAW))
|
|
|
|
{
|
|
|
|
NOTIFYICONDATAW newNid;
|
|
|
|
|
|
|
|
WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
|
|
|
|
nid->cbSize, NOTIFYICONDATAW_V1_SIZE);
|
|
|
|
CopyMemory(&newNid, nid, NOTIFYICONDATAW_V1_SIZE);
|
|
|
|
newNid.cbSize = NOTIFYICONDATAW_V1_SIZE;
|
|
|
|
return Shell_NotifyIconW(dwMessage, &newNid);
|
|
|
|
}
|
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
tray = FindWindowExW(0, NULL, classname, NULL);
|
|
|
|
if (!tray) return FALSE;
|
|
|
|
|
|
|
|
cds.dwData = dwMessage;
|
2010-03-30 21:26:26 +02:00
|
|
|
cds.cbData = sizeof(*data);
|
|
|
|
memset( data, 0, sizeof(*data) );
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
/* FIXME: if statement only needed because we don't support interprocess
|
|
|
|
* icon handles */
|
|
|
|
if (nid->uFlags & NIF_ICON)
|
|
|
|
{
|
|
|
|
ICONINFO iconinfo;
|
|
|
|
BITMAP bmMask;
|
|
|
|
BITMAP bmColour;
|
|
|
|
LONG cbMaskBits;
|
2010-05-07 12:45:55 +02:00
|
|
|
LONG cbColourBits = 0;
|
2010-03-30 21:26:26 +02:00
|
|
|
char *buffer;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
if (!GetIconInfo(nid->hIcon, &iconinfo))
|
2006-03-27 17:55:37 +02:00
|
|
|
goto noicon;
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
|
2010-05-07 12:45:55 +02:00
|
|
|
(iconinfo.hbmColor && !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour)))
|
2006-02-19 18:50:27 +01:00
|
|
|
{
|
|
|
|
DeleteObject(iconinfo.hbmMask);
|
2010-05-07 12:45:55 +02:00
|
|
|
if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);
|
2006-03-27 17:55:37 +02:00
|
|
|
goto noicon;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2010-03-30 21:26:26 +02:00
|
|
|
cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel + 15) / 16 * 2;
|
2010-05-07 12:45:55 +02:00
|
|
|
if (iconinfo.hbmColor)
|
|
|
|
cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel + 15) / 16 * 2;
|
2010-03-30 21:26:26 +02:00
|
|
|
cds.cbData = sizeof(*data) + cbMaskBits + cbColourBits;
|
2018-02-22 08:43:28 +01:00
|
|
|
buffer = heap_alloc(cds.cbData);
|
2006-03-27 17:55:37 +02:00
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
DeleteObject(iconinfo.hbmMask);
|
2010-05-07 12:45:55 +02:00
|
|
|
if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);
|
2006-03-27 17:55:37 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-03-30 21:26:26 +02:00
|
|
|
|
|
|
|
data = (struct notify_data *)buffer;
|
|
|
|
memset( data, 0, sizeof(*data) );
|
|
|
|
buffer += sizeof(*data);
|
2006-02-19 18:50:27 +01:00
|
|
|
GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
|
2010-05-07 12:45:55 +02:00
|
|
|
if (!iconinfo.hbmColor)
|
|
|
|
{
|
|
|
|
data->width = bmMask.bmWidth;
|
|
|
|
data->height = bmMask.bmHeight / 2;
|
|
|
|
data->planes = 1;
|
|
|
|
data->bpp = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data->width = bmColour.bmWidth;
|
|
|
|
data->height = bmColour.bmHeight;
|
|
|
|
data->planes = bmColour.bmPlanes;
|
|
|
|
data->bpp = bmColour.bmBitsPixel;
|
|
|
|
buffer += cbMaskBits;
|
|
|
|
GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
|
|
|
|
DeleteObject(iconinfo.hbmColor);
|
|
|
|
}
|
2006-02-19 18:50:27 +01:00
|
|
|
DeleteObject(iconinfo.hbmMask);
|
|
|
|
}
|
2010-03-30 21:26:26 +02:00
|
|
|
|
2006-03-27 17:55:37 +02:00
|
|
|
noicon:
|
2010-03-30 21:26:26 +02:00
|
|
|
data->hWnd = HandleToLong( nid->hWnd );
|
|
|
|
data->uID = nid->uID;
|
|
|
|
data->uFlags = nid->uFlags;
|
|
|
|
if (data->uFlags & NIF_MESSAGE)
|
|
|
|
data->uCallbackMessage = nid->uCallbackMessage;
|
|
|
|
if (data->uFlags & NIF_TIP)
|
|
|
|
lstrcpynW( data->szTip, nid->szTip, sizeof(data->szTip)/sizeof(WCHAR) );
|
|
|
|
if (data->uFlags & NIF_STATE)
|
|
|
|
{
|
|
|
|
data->dwState = nid->dwState;
|
|
|
|
data->dwStateMask = nid->dwStateMask;
|
|
|
|
}
|
|
|
|
if (data->uFlags & NIF_INFO)
|
|
|
|
{
|
|
|
|
lstrcpynW( data->szInfo, nid->szInfo, sizeof(data->szInfo)/sizeof(WCHAR) );
|
|
|
|
lstrcpynW( data->szInfoTitle, nid->szInfoTitle, sizeof(data->szInfoTitle)/sizeof(WCHAR) );
|
|
|
|
data->u.uTimeout = nid->u.uTimeout;
|
|
|
|
data->dwInfoFlags = nid->dwInfoFlags;
|
2006-02-19 18:50:27 +01:00
|
|
|
}
|
2010-03-30 21:26:26 +02:00
|
|
|
if (data->uFlags & NIF_GUID)
|
|
|
|
data->guidItem = nid->guidItem;
|
2016-10-10 16:35:38 +02:00
|
|
|
if (dwMessage == NIM_SETVERSION)
|
|
|
|
data->u.uVersion = nid->u.uVersion;
|
2010-03-30 21:26:26 +02:00
|
|
|
/* FIXME: balloon icon */
|
2000-01-04 01:33:56 +01:00
|
|
|
|
2010-03-30 21:26:26 +02:00
|
|
|
cds.lpData = data;
|
2008-02-05 15:17:49 +01:00
|
|
|
ret = SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
|
2018-02-22 08:43:28 +01:00
|
|
|
if (data != &data_buffer) heap_free( data );
|
2008-02-05 15:17:49 +01:00
|
|
|
return ret;
|
2000-01-04 01:33:56 +01:00
|
|
|
}
|
2017-11-29 19:24:54 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Shell_NotifyIconGetRect [SHELL32.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI Shell_NotifyIconGetRect(const NOTIFYICONIDENTIFIER* identifier, RECT* icon_location)
|
|
|
|
{
|
|
|
|
FIXME("stub (%p) (%p)\n", identifier, icon_location);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|