user/tests: Add lparam to all HCBT_MINMAX hook messages.
[wine] / dlls / shell32 / systray.c
1 /*
2  * Systray handling
3  *
4  * Copyright 1999 Kai Morich    <kai.morich@bigfoot.de>
5  * Copyright 2004 Mike Hearn, for CodeWeavers
6  * Copyright 2005 Robert Shearman
7  *
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.
12  *
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.
17  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winnls.h"
32 #include "winuser.h"
33 #include "shellapi.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(systray);
38
39 const static WCHAR classname[] = /* Shell_TrayWnd */ {'S','h','e','l','l','_','T','r','a','y','W','n','d','\0'};
40
41 /*************************************************************************
42  * Shell_NotifyIcon                     [SHELL32.296]
43  * Shell_NotifyIconA                    [SHELL32.297]
44  */
45 BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid)
46 {
47     NOTIFYICONDATAW nidW;
48     
49     nidW.cbSize = sizeof(nidW);
50     nidW.hWnd   = pnid->hWnd;
51     nidW.uID    = pnid->uID;
52     nidW.uFlags = pnid->uFlags;
53     nidW.uCallbackMessage = pnid->uCallbackMessage;
54     nidW.hIcon  = pnid->hIcon;
55
56     /* szTip */
57     MultiByteToWideChar(CP_ACP, 0, pnid->szTip, sizeof(pnid->szTip), nidW.szTip, sizeof(nidW.szTip));
58
59     nidW.dwState      = pnid->dwState;
60     nidW.dwStateMask  = pnid->dwStateMask;
61
62     /* szInfo */
63     MultiByteToWideChar(CP_ACP, 0, pnid->szInfo, sizeof(pnid->szInfo),  nidW.szInfo, sizeof(nidW.szInfo));
64
65     nidW.u.uTimeout = pnid->u.uTimeout;
66
67     /* szInfoTitle */
68     MultiByteToWideChar(CP_ACP, 0, pnid->szInfoTitle, sizeof(pnid->szInfoTitle), nidW.szInfoTitle, sizeof(nidW.szInfoTitle));
69     
70     nidW.dwInfoFlags = pnid->dwInfoFlags;
71
72     return Shell_NotifyIconW(dwMessage, &nidW);
73 }
74
75 /*************************************************************************
76  * Shell_NotifyIconW                    [SHELL32.298]
77  */
78 BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW nid)
79 {
80     HWND tray;
81     COPYDATASTRUCT cds;
82
83     TRACE("dwMessage = %ld\n", dwMessage);
84
85     tray = FindWindowExW(0, NULL, classname, NULL);
86     if (!tray) return FALSE;
87
88     cds.dwData = dwMessage;
89
90     /* FIXME: if statement only needed because we don't support interprocess
91      * icon handles */
92     if (nid->uFlags & NIF_ICON)
93     {
94         ICONINFO iconinfo;
95         char *buffer;
96         BITMAP bmMask;
97         BITMAP bmColour;
98         LONG cbMaskBits;
99         LONG cbColourBits;
100
101         if (!GetIconInfo(nid->hIcon, &iconinfo))
102             goto noicon;
103
104         if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
105             !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour))
106         {
107             DeleteObject(iconinfo.hbmMask);
108             DeleteObject(iconinfo.hbmColor);
109             goto noicon;
110         }
111
112         cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * bmMask.bmBitsPixel) / 8;
113         cbColourBits = (bmColour.bmPlanes * bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel) / 8;
114         cds.cbData = sizeof(*nid) + 2*sizeof(BITMAP) + cbMaskBits + cbColourBits;
115         buffer = HeapAlloc(GetProcessHeap(), 0, cds.cbData);
116         if (!buffer)
117         {
118             DeleteObject(iconinfo.hbmMask);
119             DeleteObject(iconinfo.hbmColor);
120             return FALSE;
121         }
122         cds.lpData = buffer;
123
124         memcpy(buffer, nid, sizeof(*nid));
125         buffer += sizeof(*nid);
126         memcpy(buffer, &bmMask, sizeof(bmMask));
127         buffer += sizeof(bmMask);
128         memcpy(buffer, &bmColour, sizeof(bmColour));
129         buffer += sizeof(bmColour);
130         GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
131         buffer += cbMaskBits;
132         GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
133         buffer += cbColourBits;
134
135         DeleteObject(iconinfo.hbmMask);
136         DeleteObject(iconinfo.hbmColor);
137     }
138     else
139     {
140 noicon:
141         cds.cbData = sizeof(*nid);
142         cds.lpData = nid;
143     }
144
145     SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
146
147     /* FIXME: if statement only needed because we don't support interprocess
148      * icon handles */
149     if (nid->uFlags & NIF_ICON)
150         HeapFree(GetProcessHeap(), 0, cds.lpData);
151
152     return TRUE;
153 }