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
31 #include "shell32_main.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(systray
);
37 struct notify_data
/* platform-independent format for NOTIFYICONDATA */
42 UINT uCallbackMessage
;
51 WCHAR szInfoTitle
[64];
54 /* data for the icon bitmap */
61 /*************************************************************************
62 * Shell_NotifyIcon [SHELL32.296]
63 * Shell_NotifyIconA [SHELL32.297]
65 BOOL WINAPI
Shell_NotifyIconA(DWORD dwMessage
, PNOTIFYICONDATAA pnid
)
70 /* Validate the cbSize as Windows XP does */
71 if (pnid
->cbSize
!= NOTIFYICONDATAA_V1_SIZE
&&
72 pnid
->cbSize
!= NOTIFYICONDATAA_V2_SIZE
&&
73 pnid
->cbSize
!= NOTIFYICONDATAA_V3_SIZE
&&
74 pnid
->cbSize
!= sizeof(NOTIFYICONDATAA
))
76 WARN("Invalid cbSize (%ld) - using only Win95 fields (size=%ld)\n",
77 pnid
->cbSize
, NOTIFYICONDATAA_V1_SIZE
);
78 cbSize
= NOTIFYICONDATAA_V1_SIZE
;
81 cbSize
= pnid
->cbSize
;
83 ZeroMemory(&nidW
, sizeof(nidW
));
84 nidW
.cbSize
= sizeof(nidW
);
85 nidW
.hWnd
= pnid
->hWnd
;
87 nidW
.uFlags
= pnid
->uFlags
;
88 nidW
.uCallbackMessage
= pnid
->uCallbackMessage
;
89 nidW
.hIcon
= pnid
->hIcon
;
92 if (pnid
->uFlags
& NIF_TIP
)
93 MultiByteToWideChar(CP_ACP
, 0, pnid
->szTip
, -1, nidW
.szTip
, ARRAY_SIZE(nidW
.szTip
));
95 if (cbSize
>= NOTIFYICONDATAA_V2_SIZE
)
97 nidW
.dwState
= pnid
->dwState
;
98 nidW
.dwStateMask
= pnid
->dwStateMask
;
100 /* szInfo, szInfoTitle */
101 if (pnid
->uFlags
& NIF_INFO
)
103 MultiByteToWideChar(CP_ACP
, 0, pnid
->szInfo
, -1, nidW
.szInfo
, ARRAY_SIZE(nidW
.szInfo
));
104 MultiByteToWideChar(CP_ACP
, 0, pnid
->szInfoTitle
, -1, nidW
.szInfoTitle
, ARRAY_SIZE(nidW
.szInfoTitle
));
107 nidW
.uTimeout
= pnid
->uTimeout
;
108 nidW
.dwInfoFlags
= pnid
->dwInfoFlags
;
111 if (cbSize
>= NOTIFYICONDATAA_V3_SIZE
)
112 nidW
.guidItem
= pnid
->guidItem
;
114 if (cbSize
>= sizeof(NOTIFYICONDATAA
))
115 nidW
.hBalloonIcon
= pnid
->hBalloonIcon
;
116 return Shell_NotifyIconW(dwMessage
, &nidW
);
119 /*************************************************************************
120 * Shell_NotifyIconW [SHELL32.298]
122 BOOL WINAPI
Shell_NotifyIconW(DWORD dwMessage
, PNOTIFYICONDATAW nid
)
126 struct notify_data data_buffer
;
127 struct notify_data
*data
= &data_buffer
;
130 TRACE("dwMessage = %ld, nid->cbSize=%ld\n", dwMessage
, nid
->cbSize
);
132 /* Validate the cbSize so that WM_COPYDATA doesn't crash the application */
133 if (nid
->cbSize
!= NOTIFYICONDATAW_V1_SIZE
&&
134 nid
->cbSize
!= NOTIFYICONDATAW_V2_SIZE
&&
135 nid
->cbSize
!= NOTIFYICONDATAW_V3_SIZE
&&
136 nid
->cbSize
!= sizeof(NOTIFYICONDATAW
))
138 NOTIFYICONDATAW newNid
;
140 WARN("Invalid cbSize (%ld) - using only Win95 fields (size=%ld)\n",
141 nid
->cbSize
, NOTIFYICONDATAW_V1_SIZE
);
142 CopyMemory(&newNid
, nid
, NOTIFYICONDATAW_V1_SIZE
);
143 newNid
.cbSize
= NOTIFYICONDATAW_V1_SIZE
;
144 return Shell_NotifyIconW(dwMessage
, &newNid
);
147 tray
= FindWindowExW(0, NULL
, L
"Shell_TrayWnd", NULL
);
150 SetLastError(E_FAIL
);
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
160 if (nid
->uFlags
& NIF_ICON
)
166 LONG cbColourBits
= 0;
169 if (!GetIconInfo(nid
->hIcon
, &iconinfo
))
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
);
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
= malloc(cds
.cbData
);
187 DeleteObject(iconinfo
.hbmMask
);
188 if (iconinfo
.hbmColor
) DeleteObject(iconinfo
.hbmColor
);
189 SetLastError(E_OUTOFMEMORY
);
193 data
= (struct notify_data
*)buffer
;
194 memset( data
, 0, sizeof(*data
) );
195 buffer
+= sizeof(*data
);
196 GetBitmapBits(iconinfo
.hbmMask
, cbMaskBits
, buffer
);
197 if (!iconinfo
.hbmColor
)
199 data
->width
= bmMask
.bmWidth
;
200 data
->height
= bmMask
.bmHeight
/ 2;
206 data
->width
= bmColour
.bmWidth
;
207 data
->height
= bmColour
.bmHeight
;
208 data
->planes
= bmColour
.bmPlanes
;
209 data
->bpp
= bmColour
.bmBitsPixel
;
210 buffer
+= cbMaskBits
;
211 GetBitmapBits(iconinfo
.hbmColor
, cbColourBits
, buffer
);
212 DeleteObject(iconinfo
.hbmColor
);
214 DeleteObject(iconinfo
.hbmMask
);
218 data
->hWnd
= HandleToLong( nid
->hWnd
);
219 data
->uID
= nid
->uID
;
220 data
->uFlags
= nid
->uFlags
;
221 if (data
->uFlags
& NIF_MESSAGE
)
222 data
->uCallbackMessage
= nid
->uCallbackMessage
;
223 if (data
->uFlags
& NIF_TIP
)
224 lstrcpynW( data
->szTip
, nid
->szTip
, ARRAY_SIZE(data
->szTip
));
225 if (data
->uFlags
& NIF_STATE
)
227 data
->dwState
= nid
->dwState
;
228 data
->dwStateMask
= nid
->dwStateMask
;
230 if (data
->uFlags
& NIF_INFO
)
232 lstrcpynW( data
->szInfo
, nid
->szInfo
, ARRAY_SIZE(data
->szInfo
) );
233 lstrcpynW( data
->szInfoTitle
, nid
->szInfoTitle
, ARRAY_SIZE(data
->szInfoTitle
));
234 data
->u
.uTimeout
= nid
->uTimeout
;
235 data
->dwInfoFlags
= nid
->dwInfoFlags
;
237 if (data
->uFlags
& NIF_GUID
)
238 data
->guidItem
= nid
->guidItem
;
239 if (dwMessage
== NIM_SETVERSION
)
240 data
->u
.uVersion
= nid
->uVersion
;
241 /* FIXME: balloon icon */
244 ret
= SendMessageW(tray
, WM_COPYDATA
, (WPARAM
)nid
->hWnd
, (LPARAM
)&cds
);
245 if (data
!= &data_buffer
) free(data
);
246 SetLastError(ret
? S_OK
: E_FAIL
);
250 /*************************************************************************
251 * Shell_NotifyIconGetRect [SHELL32.@]
253 HRESULT WINAPI
Shell_NotifyIconGetRect(const NOTIFYICONIDENTIFIER
* identifier
, RECT
* icon_location
)
255 FIXME("stub (%p) (%p)\n", identifier
, icon_location
);