cryptui: Implement specifying the destination store in CryptUIWizImport.
[wine/wine64.git] / programs / explorer / appbar.c
blobf6e1eb1c9e6953ab387882614a99276f59718039
1 /*
2 * SHAppBarMessage implementation
4 * Copyright 2008 Vincent Povirk for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * TODO: freedesktop _NET_WM_STRUT integration
22 * TODO: find when a fullscreen app is in the foreground and send FULLSCREENAPP
23 * notifications
25 * TODO: detect changes in the screen size and send ABN_POSCHANGED ?
27 * TODO: multiple monitor support
30 #include "wine/unicode.h"
32 #include <windows.h>
33 #include <wine/debug.h>
34 #include "explorer_private.h"
36 #include "wine/list.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(appbar);
40 struct appbar_cmd
42 HANDLE return_map;
43 DWORD return_process;
44 APPBARDATA abd;
47 struct appbar_response
49 UINT_PTR result;
50 APPBARDATA abd;
53 static HWND appbarmsg_window = NULL;
55 struct appbar_data
57 struct list entry;
58 HWND hwnd;
59 UINT callback_msg;
60 UINT edge;
61 RECT rc;
62 BOOL space_reserved;
63 /* BOOL autohide; */
66 static struct list appbars = LIST_INIT(appbars);
68 static struct appbar_data* get_appbar(HWND hwnd)
70 struct appbar_data* data;
72 LIST_FOR_EACH_ENTRY(data, &appbars, struct appbar_data, entry)
74 if (data->hwnd == hwnd)
75 return data;
78 return NULL;
81 /* send_poschanged: send ABN_POSCHANGED to every appbar except one */
82 static void send_poschanged(HWND hwnd)
84 struct appbar_data* data;
85 LIST_FOR_EACH_ENTRY(data, &appbars, struct appbar_data, entry)
87 if (data->hwnd != hwnd)
89 PostMessageW(data->hwnd, data->callback_msg, ABN_POSCHANGED, 0);
94 /* appbar_cliprect: cut out parts of the rectangle that interfere with existing appbars */
95 static void appbar_cliprect(PAPPBARDATA abd)
97 struct appbar_data* data;
98 LIST_FOR_EACH_ENTRY(data, &appbars, struct appbar_data, entry)
100 if (data->hwnd == abd->hWnd)
102 /* we only care about appbars that were added before this one */
103 return;
105 if (data->space_reserved)
107 /* move in the side that corresponds to the other appbar's edge */
108 switch (data->edge)
110 case ABE_BOTTOM:
111 abd->rc.bottom = min(abd->rc.bottom, data->rc.top);
112 break;
113 case ABE_LEFT:
114 abd->rc.left = max(abd->rc.left, data->rc.right);
115 break;
116 case ABE_RIGHT:
117 abd->rc.right = min(abd->rc.right, data->rc.left);
118 break;
119 case ABE_TOP:
120 abd->rc.top = max(abd->rc.top, data->rc.bottom);
121 break;
127 static UINT_PTR handle_appbarmessage(DWORD msg, PAPPBARDATA abd)
129 struct appbar_data* data;
131 switch (msg)
133 case ABM_NEW:
134 if (get_appbar(abd->hWnd))
136 /* fail when adding an hwnd the second time */
137 return FALSE;
140 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct appbar_data));
141 if (!data)
143 WINE_ERR("out of memory\n");
144 return FALSE;
146 data->hwnd = abd->hWnd;
147 data->callback_msg = abd->uCallbackMessage;
149 list_add_tail(&appbars, &data->entry);
151 return TRUE;
152 case ABM_REMOVE:
153 if ((data = get_appbar(abd->hWnd)))
155 list_remove(&data->entry);
157 send_poschanged(abd->hWnd);
159 HeapFree(GetProcessHeap(), 0, data);
161 else
162 WINE_WARN("removing hwnd %p not on the list\n", abd->hWnd);
163 return TRUE;
164 case ABM_QUERYPOS:
165 if (abd->uEdge > ABE_BOTTOM)
166 WINE_WARN("invalid edge %i for %p\n", abd->uEdge, abd->hWnd);
167 appbar_cliprect(abd);
168 return TRUE;
169 case ABM_SETPOS:
170 if (abd->uEdge > ABE_BOTTOM)
172 WINE_WARN("invalid edge %i for %p\n", abd->uEdge, abd->hWnd);
173 return TRUE;
175 if ((data = get_appbar(abd->hWnd)))
177 /* calculate acceptable space */
178 appbar_cliprect(abd);
180 if (!EqualRect(&abd->rc, &data->rc))
181 send_poschanged(abd->hWnd);
183 /* reserve that space for this appbar */
184 data->edge = abd->uEdge;
185 data->rc = abd->rc;
186 data->space_reserved = TRUE;
188 else
190 WINE_WARN("app sent ABM_SETPOS message for %p without ABM_ADD\n", abd->hWnd);
192 return TRUE;
193 case ABM_GETSTATE:
194 WINE_FIXME("SHAppBarMessage(ABM_GETSTATE): stub\n");
195 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
196 case ABM_GETTASKBARPOS:
197 WINE_FIXME("SHAppBarMessage(ABM_GETTASKBARPOS, hwnd=%p): stub\n", abd->hWnd);
198 /* Report the taskbar is at the bottom of the screen. */
199 abd->rc.left = 0;
200 abd->rc.right = GetSystemMetrics(SM_CXSCREEN);
201 abd->rc.bottom = GetSystemMetrics(SM_CYSCREEN);
202 abd->rc.top = abd->rc.bottom-1;
203 abd->uEdge = ABE_BOTTOM;
204 return TRUE;
205 case ABM_ACTIVATE:
206 WINE_FIXME("SHAppBarMessage(ABM_ACTIVATE, hwnd=%p, lparam=%lx): stub\n", abd->hWnd, abd->lParam);
207 return TRUE;
208 case ABM_GETAUTOHIDEBAR:
209 WINE_FIXME("SHAppBarMessage(ABM_GETAUTOHIDEBAR, hwnd=%p, edge=%x): stub\n", abd->hWnd, abd->uEdge);
210 return 0;
211 case ABM_SETAUTOHIDEBAR:
212 WINE_FIXME("SHAppBarMessage(ABM_SETAUTOHIDEBAR, hwnd=%p, edge=%x, lparam=%lx): stub\n", abd->hWnd, abd->uEdge, abd->lParam);
213 return TRUE;
214 case ABM_WINDOWPOSCHANGED:
215 WINE_FIXME("SHAppBarMessage(ABM_WINDOWPOSCHANGED, hwnd=%p): stub\n", abd->hWnd);
216 return TRUE;
217 default:
218 WINE_FIXME("SHAppBarMessage(%x) unimplemented\n", msg);
219 return FALSE;
223 static LRESULT CALLBACK appbar_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
225 switch (msg)
227 case WM_COPYDATA:
229 COPYDATASTRUCT* cds;
230 struct appbar_cmd cmd;
231 UINT_PTR result;
232 HANDLE return_hproc;
233 HANDLE return_map;
234 LPVOID return_view;
235 struct appbar_response* response;
237 cds = (COPYDATASTRUCT*)lparam;
238 if (cds->cbData != sizeof(struct appbar_cmd))
239 return TRUE;
240 CopyMemory(&cmd, cds->lpData, cds->cbData);
242 result = handle_appbarmessage(cds->dwData, &cmd.abd);
244 return_hproc = OpenProcess(PROCESS_DUP_HANDLE, FALSE, cmd.return_process);
245 if (return_hproc == NULL)
247 WINE_ERR("couldn't open calling process\n");
248 return TRUE;
251 if (!DuplicateHandle(return_hproc, cmd.return_map, GetCurrentProcess(), &return_map, 0, FALSE, DUPLICATE_SAME_ACCESS))
253 WINE_ERR("couldn't duplicate handle\n");
254 CloseHandle(return_hproc);
255 return TRUE;
257 CloseHandle(return_hproc);
259 return_view = MapViewOfFile(return_map, FILE_MAP_WRITE, 0, 0, sizeof(struct appbar_response));
261 if (return_view)
263 response = (struct appbar_response*)return_view;
264 response->result = result;
265 response->abd = cmd.abd;
267 UnmapViewOfFile(return_view);
269 else
270 WINE_ERR("couldn't map view of file\n");
272 CloseHandle(return_map);
273 return TRUE;
275 default:
276 break;
279 return DefWindowProcW(hwnd, msg, wparam, lparam);
282 void initialize_appbar(void)
284 WNDCLASSEXW class;
285 static const WCHAR classname[] = {'W','i','n','e','A','p','p','B','a','r',0};
287 /* register the appbar window class */
288 ZeroMemory(&class, sizeof(class));
289 class.cbSize = sizeof(class);
290 class.lpfnWndProc = appbar_wndproc;
291 class.hInstance = NULL;
292 class.lpszClassName = classname;
294 if (!RegisterClassExW(&class))
296 WINE_ERR("Could not register appbar message window class\n");
297 return;
300 appbarmsg_window = CreateWindowW(classname, classname, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
301 if (!appbarmsg_window)
303 WINE_ERR("Could not create appbar message window\n");
304 return;