gdi32: Consider whether the logical font face is vertical when selecting.
[wine/multimedia.git] / dlls / shell32 / systray.c
blob59df2f8f51a52630da26de3f71954d68e459eac9
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 struct notify_data /* platform-independent format for NOTIFYICONDATA */
43 LONG hWnd;
44 UINT uID;
45 UINT uFlags;
46 UINT uCallbackMessage;
47 WCHAR szTip[128];
48 DWORD dwState;
49 DWORD dwStateMask;
50 WCHAR szInfo[256];
51 union {
52 UINT uTimeout;
53 UINT uVersion;
54 } u;
55 WCHAR szInfoTitle[64];
56 DWORD dwInfoFlags;
57 GUID guidItem;
58 /* data for the icon bitmap */
59 UINT width;
60 UINT height;
61 UINT planes;
62 UINT bpp;
65 /*************************************************************************
66 * Shell_NotifyIcon [SHELL32.296]
67 * Shell_NotifyIconA [SHELL32.297]
69 BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid)
71 NOTIFYICONDATAW nidW;
72 INT cbSize;
74 /* Validate the cbSize as Windows XP does */
75 if (pnid->cbSize != NOTIFYICONDATAA_V1_SIZE &&
76 pnid->cbSize != NOTIFYICONDATAA_V2_SIZE &&
77 pnid->cbSize != NOTIFYICONDATAA_V3_SIZE &&
78 pnid->cbSize != sizeof(NOTIFYICONDATAA))
80 WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
81 pnid->cbSize, NOTIFYICONDATAA_V1_SIZE);
82 cbSize = NOTIFYICONDATAA_V1_SIZE;
84 else
85 cbSize = pnid->cbSize;
87 ZeroMemory(&nidW, sizeof(nidW));
88 nidW.cbSize = sizeof(nidW);
89 nidW.hWnd = pnid->hWnd;
90 nidW.uID = pnid->uID;
91 nidW.uFlags = pnid->uFlags;
92 nidW.uCallbackMessage = pnid->uCallbackMessage;
93 nidW.hIcon = pnid->hIcon;
95 /* szTip */
96 if (pnid->uFlags & NIF_TIP)
97 MultiByteToWideChar(CP_ACP, 0, pnid->szTip, -1, nidW.szTip, sizeof(nidW.szTip)/sizeof(WCHAR));
99 if (cbSize >= NOTIFYICONDATAA_V2_SIZE)
101 nidW.dwState = pnid->dwState;
102 nidW.dwStateMask = pnid->dwStateMask;
104 /* szInfo, szInfoTitle */
105 if (pnid->uFlags & NIF_INFO)
107 MultiByteToWideChar(CP_ACP, 0, pnid->szInfo, -1, nidW.szInfo, sizeof(nidW.szInfo)/sizeof(WCHAR));
108 MultiByteToWideChar(CP_ACP, 0, pnid->szInfoTitle, -1, nidW.szInfoTitle, sizeof(nidW.szInfoTitle)/sizeof(WCHAR));
111 nidW.u.uTimeout = pnid->u.uTimeout;
112 nidW.dwInfoFlags = pnid->dwInfoFlags;
115 if (cbSize >= NOTIFYICONDATAA_V3_SIZE)
116 nidW.guidItem = pnid->guidItem;
118 if (cbSize >= sizeof(NOTIFYICONDATAA))
119 nidW.hBalloonIcon = pnid->hBalloonIcon;
120 return Shell_NotifyIconW(dwMessage, &nidW);
123 /*************************************************************************
124 * Shell_NotifyIconW [SHELL32.298]
126 BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW nid)
128 HWND tray;
129 COPYDATASTRUCT cds;
130 struct notify_data data_buffer;
131 struct notify_data *data = &data_buffer;
132 BOOL ret;
134 TRACE("dwMessage = %d, nid->cbSize=%d\n", dwMessage, nid->cbSize);
136 /* Validate the cbSize so that WM_COPYDATA doesn't crash the application */
137 if (nid->cbSize != NOTIFYICONDATAW_V1_SIZE &&
138 nid->cbSize != NOTIFYICONDATAW_V2_SIZE &&
139 nid->cbSize != NOTIFYICONDATAW_V3_SIZE &&
140 nid->cbSize != sizeof(NOTIFYICONDATAW))
142 NOTIFYICONDATAW newNid;
144 WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
145 nid->cbSize, NOTIFYICONDATAW_V1_SIZE);
146 CopyMemory(&newNid, nid, NOTIFYICONDATAW_V1_SIZE);
147 newNid.cbSize = NOTIFYICONDATAW_V1_SIZE;
148 return Shell_NotifyIconW(dwMessage, &newNid);
151 tray = FindWindowExW(0, NULL, classname, NULL);
152 if (!tray) return FALSE;
154 cds.dwData = dwMessage;
155 cds.cbData = sizeof(*data);
156 memset( data, 0, sizeof(*data) );
158 /* FIXME: if statement only needed because we don't support interprocess
159 * icon handles */
160 if (nid->uFlags & NIF_ICON)
162 ICONINFO iconinfo;
163 BITMAP bmMask;
164 BITMAP bmColour;
165 LONG cbMaskBits;
166 LONG cbColourBits = 0;
167 char *buffer;
169 if (!GetIconInfo(nid->hIcon, &iconinfo))
170 goto noicon;
172 if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
173 (iconinfo.hbmColor && !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour)))
175 DeleteObject(iconinfo.hbmMask);
176 if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);
177 goto noicon;
180 cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel + 15) / 16 * 2;
181 if (iconinfo.hbmColor)
182 cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel + 15) / 16 * 2;
183 cds.cbData = sizeof(*data) + cbMaskBits + cbColourBits;
184 buffer = HeapAlloc(GetProcessHeap(), 0, cds.cbData);
185 if (!buffer)
187 DeleteObject(iconinfo.hbmMask);
188 if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);
189 return FALSE;
192 data = (struct notify_data *)buffer;
193 memset( data, 0, sizeof(*data) );
194 buffer += sizeof(*data);
195 GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
196 if (!iconinfo.hbmColor)
198 data->width = bmMask.bmWidth;
199 data->height = bmMask.bmHeight / 2;
200 data->planes = 1;
201 data->bpp = 1;
203 else
205 data->width = bmColour.bmWidth;
206 data->height = bmColour.bmHeight;
207 data->planes = bmColour.bmPlanes;
208 data->bpp = bmColour.bmBitsPixel;
209 buffer += cbMaskBits;
210 GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
211 DeleteObject(iconinfo.hbmColor);
213 DeleteObject(iconinfo.hbmMask);
216 noicon:
217 data->hWnd = HandleToLong( nid->hWnd );
218 data->uID = nid->uID;
219 data->uFlags = nid->uFlags;
220 if (data->uFlags & NIF_MESSAGE)
221 data->uCallbackMessage = nid->uCallbackMessage;
222 if (data->uFlags & NIF_TIP)
223 lstrcpynW( data->szTip, nid->szTip, sizeof(data->szTip)/sizeof(WCHAR) );
224 if (data->uFlags & NIF_STATE)
226 data->dwState = nid->dwState;
227 data->dwStateMask = nid->dwStateMask;
229 if (data->uFlags & NIF_INFO)
231 lstrcpynW( data->szInfo, nid->szInfo, sizeof(data->szInfo)/sizeof(WCHAR) );
232 lstrcpynW( data->szInfoTitle, nid->szInfoTitle, sizeof(data->szInfoTitle)/sizeof(WCHAR) );
233 data->u.uTimeout = nid->u.uTimeout;
234 data->dwInfoFlags = nid->dwInfoFlags;
236 if (data->uFlags & NIF_GUID)
237 data->guidItem = nid->guidItem;
238 /* FIXME: balloon icon */
240 cds.lpData = data;
241 ret = SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
242 if (data != &data_buffer) HeapFree( GetProcessHeap(), 0, data );
243 return ret;