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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-12-12 00:54:59 +01:00
|
|
|
*/
|
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
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"
|
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-02-19 18:50:27 +01:00
|
|
|
const static 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
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
/* start timeout of 1 second */
|
|
|
|
#define SYSTRAY_START_TIMEOUT 1000
|
2005-11-08 17:08:17 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
static BOOL start_systray_process(void)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
2006-02-19 18:50:27 +01:00
|
|
|
STARTUPINFOW sinfo;
|
|
|
|
PROCESS_INFORMATION pinfo;
|
|
|
|
WCHAR command_line[] = {'e','x','p','l','o','r','e','r',' ','/','s','y','s','t','r','a','y',0};
|
|
|
|
static const WCHAR event_name[] = {'W','i','n','e','S','y','s','t','r','a','y','I','n','i','t','e','d',0};
|
|
|
|
HANDLE systray_ready_event;
|
|
|
|
DWORD wait;
|
|
|
|
|
|
|
|
TRACE("No tray window found, starting %s\n", debugstr_w(command_line));
|
|
|
|
|
|
|
|
ZeroMemory(&sinfo, sizeof(sinfo));
|
|
|
|
sinfo.cb = sizeof(sinfo);
|
|
|
|
|
|
|
|
if (CreateProcessW(NULL, command_line, NULL, NULL, FALSE, 0, NULL, NULL, &sinfo, &pinfo) == 0)
|
|
|
|
{
|
|
|
|
ERR("Could not start %s, error 0x%lx\n", debugstr_w(command_line), GetLastError());
|
|
|
|
return FALSE;
|
2000-02-07 17:02:41 +01:00
|
|
|
}
|
2006-02-19 18:50:27 +01:00
|
|
|
|
|
|
|
CloseHandle(pinfo.hThread);
|
|
|
|
CloseHandle(pinfo.hProcess);
|
|
|
|
|
|
|
|
systray_ready_event = CreateEventW(NULL, TRUE, FALSE, event_name);
|
|
|
|
if (!systray_ready_event) return FALSE;
|
|
|
|
|
|
|
|
/* don't guess how long to wait, just wait for process to signal to us
|
|
|
|
* that it has created the Shell_TrayWnd class before continuing */
|
|
|
|
wait = WaitForSingleObject(systray_ready_event, SYSTRAY_START_TIMEOUT);
|
|
|
|
CloseHandle(systray_ready_event);
|
|
|
|
|
|
|
|
if (wait == WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
ERR("timeout waiting for %s to start\n", debugstr_w(command_line));
|
|
|
|
return FALSE;
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
return TRUE;
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 */
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pnid->szTip, sizeof(pnid->szTip), nidW.szTip, sizeof(nidW.szTip));
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
nidW.dwState = pnid->dwState;
|
|
|
|
nidW.dwStateMask = pnid->dwStateMask;
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
/* szInfo */
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pnid->szInfo, sizeof(pnid->szInfo), nidW.szInfo, sizeof(nidW.szInfo));
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
nidW.u.uTimeout = pnid->u.uTimeout;
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
/* szInfoTitle */
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pnid->szInfoTitle, sizeof(pnid->szInfoTitle), nidW.szInfoTitle, sizeof(nidW.szInfoTitle));
|
|
|
|
|
|
|
|
nidW.dwInfoFlags = pnid->dwInfoFlags;
|
2000-02-07 17:02:41 +01:00
|
|
|
|
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;
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
TRACE("dwMessage = %ld\n", dwMessage);
|
2000-02-07 17:02:41 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
tray = FindWindowExW(0, NULL, classname, NULL);
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
/* this isn't how native does it - it assumes that Explorer is always
|
|
|
|
* running */
|
|
|
|
if (!tray)
|
|
|
|
{
|
|
|
|
if (!start_systray_process())
|
|
|
|
return FALSE;
|
|
|
|
tray = FindWindowExW(0, NULL, classname, NULL);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
if (!tray) return FALSE;
|
|
|
|
|
|
|
|
cds.dwData = dwMessage;
|
|
|
|
|
|
|
|
/* FIXME: if statement only needed because we don't support interprocess
|
|
|
|
* icon handles */
|
|
|
|
if (nid->uFlags & NIF_ICON)
|
|
|
|
{
|
|
|
|
ICONINFO iconinfo;
|
|
|
|
char *buffer;
|
|
|
|
BITMAP bmMask;
|
|
|
|
BITMAP bmColour;
|
|
|
|
LONG cbMaskBits;
|
|
|
|
LONG cbColourBits;
|
|
|
|
|
|
|
|
if (!GetIconInfo(nid->hIcon, &iconinfo))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
|
|
|
|
!GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour))
|
|
|
|
{
|
|
|
|
DeleteObject(iconinfo.hbmMask);
|
|
|
|
DeleteObject(iconinfo.hbmColor);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel) / 8;
|
|
|
|
cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel) / 8;
|
|
|
|
cds.cbData = sizeof(*nid) + 2*sizeof(BITMAP) + cbMaskBits + cbColourBits;
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, cds.cbData);
|
|
|
|
if (!buffer) return FALSE;
|
|
|
|
cds.lpData = buffer;
|
|
|
|
|
|
|
|
memcpy(buffer, nid, sizeof(*nid));
|
|
|
|
buffer += sizeof(*nid);
|
|
|
|
memcpy(buffer, &bmMask, sizeof(bmMask));
|
|
|
|
buffer += sizeof(bmMask);
|
|
|
|
memcpy(buffer, &bmColour, sizeof(bmColour));
|
|
|
|
buffer += sizeof(bmColour);
|
|
|
|
GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
|
|
|
|
buffer += cbMaskBits;
|
|
|
|
GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
|
|
|
|
buffer += cbColourBits;
|
|
|
|
|
|
|
|
DeleteObject(iconinfo.hbmMask);
|
|
|
|
DeleteObject(iconinfo.hbmColor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cds.cbData = sizeof(*nid);
|
|
|
|
cds.lpData = nid;
|
|
|
|
}
|
2000-01-04 01:33:56 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
|
2000-01-04 01:33:56 +01:00
|
|
|
|
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)
|
|
|
|
HeapFree(GetProcessHeap(), 0, cds.lpData);
|
2000-01-04 01:33:56 +01:00
|
|
|
|
2006-02-19 18:50:27 +01:00
|
|
|
return TRUE;
|
2000-01-04 01:33:56 +01:00
|
|
|
}
|