dplayx: Implement proper interface locking for DP_EnumSession.
[wine/multimedia.git] / dlls / shell32 / systray.c
blob824eeb9fcba6e1b33be5a5a768c89ec602224fd5
1 /*
2 * Systray handling
4 * Copyright 1999 Kai Morich <kai.morich@bigfoot.de>
5 * Copyright 2004 Mike Hearn, for CodeWeavers
6 * Copyright 2005 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winnls.h"
32 #include "winuser.h"
33 #include "shellapi.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(systray);
39 static const WCHAR classname[] = /* Shell_TrayWnd */ {'S','h','e','l','l','_','T','r','a','y','W','n','d','\0'};
41 /*************************************************************************
42 * Shell_NotifyIcon [SHELL32.296]
43 * Shell_NotifyIconA [SHELL32.297]
45 BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid)
47 NOTIFYICONDATAW nidW;
49 ZeroMemory(&nidW, sizeof(nidW));
50 nidW.cbSize = sizeof(nidW);
51 nidW.hWnd = pnid->hWnd;
52 nidW.uID = pnid->uID;
53 nidW.uFlags = pnid->uFlags;
54 nidW.uCallbackMessage = pnid->uCallbackMessage;
55 nidW.hIcon = pnid->hIcon;
57 /* szTip */
58 if (pnid->uFlags & NIF_TIP)
59 MultiByteToWideChar(CP_ACP, 0, pnid->szTip, -1, nidW.szTip, sizeof(nidW.szTip)/sizeof(WCHAR));
61 if (pnid->cbSize >= NOTIFYICONDATAA_V2_SIZE)
63 nidW.dwState = pnid->dwState;
64 nidW.dwStateMask = pnid->dwStateMask;
66 /* szInfo, szInfoTitle */
67 if (pnid->uFlags & NIF_INFO)
69 MultiByteToWideChar(CP_ACP, 0, pnid->szInfo, -1, nidW.szInfo, sizeof(nidW.szInfo)/sizeof(WCHAR));
70 MultiByteToWideChar(CP_ACP, 0, pnid->szInfoTitle, -1, nidW.szInfoTitle, sizeof(nidW.szInfoTitle)/sizeof(WCHAR));
73 nidW.u.uTimeout = pnid->u.uTimeout;
74 nidW.dwInfoFlags = pnid->dwInfoFlags;
77 if (pnid->cbSize >= NOTIFYICONDATAA_V3_SIZE)
78 nidW.guidItem = pnid->guidItem;
80 if (pnid->cbSize >= sizeof(NOTIFYICONDATAA))
81 nidW.hBalloonIcon = pnid->hBalloonIcon;
82 return Shell_NotifyIconW(dwMessage, &nidW);
85 /*************************************************************************
86 * Shell_NotifyIconW [SHELL32.298]
88 BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW nid)
90 HWND tray;
91 COPYDATASTRUCT cds;
92 char *buffer = NULL;
94 TRACE("dwMessage = %d, nid->cbSize=%d\n", dwMessage, nid->cbSize);
96 tray = FindWindowExW(0, NULL, classname, NULL);
97 if (!tray) return FALSE;
99 cds.dwData = dwMessage;
101 /* FIXME: if statement only needed because we don't support interprocess
102 * icon handles */
103 if (nid->uFlags & NIF_ICON)
105 ICONINFO iconinfo;
106 BITMAP bmMask;
107 BITMAP bmColour;
108 LONG cbMaskBits;
109 LONG cbColourBits;
111 if (!GetIconInfo(nid->hIcon, &iconinfo))
112 goto noicon;
114 if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
115 !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour))
117 DeleteObject(iconinfo.hbmMask);
118 DeleteObject(iconinfo.hbmColor);
119 goto noicon;
122 cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel) / 8;
123 cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel) / 8;
124 cds.cbData = nid->cbSize + 2*sizeof(BITMAP) + cbMaskBits + cbColourBits;
125 buffer = HeapAlloc(GetProcessHeap(), 0, cds.cbData);
126 if (!buffer)
128 DeleteObject(iconinfo.hbmMask);
129 DeleteObject(iconinfo.hbmColor);
130 return FALSE;
132 cds.lpData = buffer;
134 memcpy(buffer, nid, sizeof(*nid));
135 buffer += nid->cbSize;
136 memcpy(buffer, &bmMask, sizeof(bmMask));
137 buffer += sizeof(bmMask);
138 memcpy(buffer, &bmColour, sizeof(bmColour));
139 buffer += sizeof(bmColour);
140 GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
141 buffer += cbMaskBits;
142 GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
143 buffer += cbColourBits;
145 DeleteObject(iconinfo.hbmMask);
146 DeleteObject(iconinfo.hbmColor);
148 else
150 noicon:
151 cds.cbData = nid->cbSize;
152 cds.lpData = nid;
155 SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
157 /* FIXME: if statement only needed because we don't support interprocess
158 * icon handles */
159 HeapFree(GetProcessHeap(), 0, buffer);
161 return TRUE;