shell32: Replaced folder_open.ico with a Tango compliant icon.
[wine.git] / dlls / shell32 / systray.c
blob3e0b5acfadfa47b252dacb13f115a688d941df42
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;
167 char *buffer;
169 if (!GetIconInfo(nid->hIcon, &iconinfo))
170 goto noicon;
172 if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
173 !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour))
175 DeleteObject(iconinfo.hbmMask);
176 DeleteObject(iconinfo.hbmColor);
177 goto noicon;
180 cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel + 15) / 16 * 2;
181 cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel + 15) / 16 * 2;
182 cds.cbData = sizeof(*data) + cbMaskBits + cbColourBits;
183 buffer = HeapAlloc(GetProcessHeap(), 0, cds.cbData);
184 if (!buffer)
186 DeleteObject(iconinfo.hbmMask);
187 DeleteObject(iconinfo.hbmColor);
188 return FALSE;
191 data = (struct notify_data *)buffer;
192 memset( data, 0, sizeof(*data) );
193 data->width = bmColour.bmWidth;
194 data->height = bmColour.bmHeight;
195 data->planes = bmColour.bmPlanes;
196 data->bpp = bmColour.bmBitsPixel;
197 buffer += sizeof(*data);
198 GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
199 buffer += cbMaskBits;
200 GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
201 DeleteObject(iconinfo.hbmMask);
202 DeleteObject(iconinfo.hbmColor);
205 noicon:
206 data->hWnd = HandleToLong( nid->hWnd );
207 data->uID = nid->uID;
208 data->uFlags = nid->uFlags;
209 if (data->uFlags & NIF_MESSAGE)
210 data->uCallbackMessage = nid->uCallbackMessage;
211 if (data->uFlags & NIF_TIP)
212 lstrcpynW( data->szTip, nid->szTip, sizeof(data->szTip)/sizeof(WCHAR) );
213 if (data->uFlags & NIF_STATE)
215 data->dwState = nid->dwState;
216 data->dwStateMask = nid->dwStateMask;
218 if (data->uFlags & NIF_INFO)
220 lstrcpynW( data->szInfo, nid->szInfo, sizeof(data->szInfo)/sizeof(WCHAR) );
221 lstrcpynW( data->szInfoTitle, nid->szInfoTitle, sizeof(data->szInfoTitle)/sizeof(WCHAR) );
222 data->u.uTimeout = nid->u.uTimeout;
223 data->dwInfoFlags = nid->dwInfoFlags;
225 if (data->uFlags & NIF_GUID)
226 data->guidItem = nid->guidItem;
227 /* FIXME: balloon icon */
229 cds.lpData = data;
230 ret = SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
231 if (data != &data_buffer) HeapFree( GetProcessHeap(), 0, data );
232 return ret;