ReactOS 0.4.16-dev-340-g0540c21
appbar.cpp
Go to the documentation of this file.
1/*
2 * SHAppBarMessage implementation
3 *
4 * Copyright 2008 Vincent Povirk for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 *
20 * TODO: freedesktop _NET_WM_STRUT integration
21 *
22 * TODO: find when a fullscreen app is in the foreground and send FULLSCREENAPP
23 * notifications
24 *
25 * TODO: detect changes in the screen size and send ABN_POSCHANGED ?
26 *
27 * TODO: multiple monitor support
28 */
29
30//
31// Adapted from Wine appbar.c .
32//
33
34#include "precomp.h"
35
36#include <wine/list.h>
37
38#define GetPrimaryTaskbar() FindWindowW(L"Shell_TrayWnd", NULL)
39
41{
46};
47
49{
52};
53
55{
56 struct list entry;
62 /* BOOL autohide; */
63};
64
65static struct list appbars = LIST_INIT(appbars);
66
68{
69 struct appbar_data* data;
70
72 {
73 if (data->hwnd == hwnd)
74 return data;
75 }
76
77 return NULL;
78}
79
80void appbar_notify_all(HMONITOR hMon, UINT uMsg, HWND hwndExclude, LPARAM lParam)
81{
82 struct appbar_data* data;
83
85 {
86 if (data->hwnd == hwndExclude)
87 continue;
88
89 if (hMon && hMon != MonitorFromWindow(data->hwnd, MONITOR_DEFAULTTONULL))
90 continue;
91
92 SendMessageW(data->hwnd, data->callback_msg, uMsg, lParam);
93 }
94}
95
96/* send_poschanged: send ABN_POSCHANGED to every appbar except one */
98{
100}
101
102/* appbar_cliprect: cut out parts of the rectangle that interfere with existing appbars */
104{
105 struct appbar_data* data;
107 {
108 if (data->hwnd == hwnd)
109 {
110 /* we only care about appbars that were added before this one */
111 return;
112 }
113 if (data->space_reserved)
114 {
115 /* move in the side that corresponds to the other appbar's edge */
116 switch (data->edge)
117 {
118 case ABE_BOTTOM:
119 rect->bottom = min(rect->bottom, data->rc.top);
120 break;
121 case ABE_LEFT:
122 rect->left = max(rect->left, data->rc.right);
123 break;
124 case ABE_RIGHT:
125 rect->right = min(rect->right, data->rc.left);
126 break;
127 case ABE_TOP:
128 rect->top = max(rect->top, data->rc.bottom);
129 break;
130 }
131 }
132 }
133}
134
136{
137 struct appbar_data* data;
138 HWND hwnd = abd->hWnd;
139
140 switch (msg)
141 {
142 case ABM_NEW:
143 if (get_appbar(hwnd))
144 {
145 /* fail when adding an hwnd the second time */
146 return FALSE;
147 }
148
150 if (!data)
151 {
152 ERR("out of memory\n");
153 return FALSE;
154 }
155 data->hwnd = hwnd;
156 data->callback_msg = abd->uCallbackMessage;
157
158 list_add_tail(&appbars, &data->entry);
159
160 return TRUE;
161 case ABM_REMOVE:
162 if ((data = get_appbar(hwnd)))
163 {
164 list_remove(&data->entry);
165
167
169 }
170 else
171 WARN("removing hwnd %p not on the list\n", hwnd);
172 return TRUE;
173 case ABM_QUERYPOS:
174 if (abd->uEdge > ABE_BOTTOM)
175 WARN("invalid edge %i for %p\n", abd->uEdge, hwnd);
176 appbar_cliprect( hwnd, &abd->rc );
177 return TRUE;
178 case ABM_SETPOS:
179 if (abd->uEdge > ABE_BOTTOM)
180 {
181 WARN("invalid edge %i for %p\n", abd->uEdge, hwnd);
182 return TRUE;
183 }
184 if ((data = get_appbar(hwnd)))
185 {
186 /* calculate acceptable space */
187 appbar_cliprect( hwnd, &abd->rc );
188
189 if (!EqualRect(&abd->rc, &data->rc))
191
192 /* reserve that space for this appbar */
193 data->edge = abd->uEdge;
194 data->rc = abd->rc;
195 data->space_reserved = TRUE;
196 }
197 else
198 {
199 WARN("app sent ABM_SETPOS message for %p without ABM_ADD\n", hwnd);
200 }
201 return TRUE;
202 case ABM_GETSTATE:
203 TRACE("SHAppBarMessage(ABM_GETSTATE)\n");
206 case ABM_SETSTATE:
207 TRACE("SHAppBarMessage(ABM_SETSTATE lparam=%s)\n", wine_dbgstr_longlong(abd->lParam));
209 if (hwnd)
210 {
212 settings.sr.AutoHide = (abd->lParam & ABS_AUTOHIDE) != 0;
213 settings.sr.AlwaysOnTop = (abd->lParam & ABS_ALWAYSONTOP) != 0;
215 return TRUE;
216 }
217 return FALSE;
219 TRACE("SHAppBarMessage(ABM_GETTASKBARPOS, hwnd=%p)\n", hwnd);
221 abd->hWnd = GetPrimaryTaskbar();
222 return abd->hWnd && GetWindowRect(abd->hWnd, &abd->rc);
223 case ABM_ACTIVATE:
224 return TRUE;
226 FIXME("SHAppBarMessage(ABM_GETAUTOHIDEBAR, hwnd=%p, edge=%x): stub\n", hwnd, abd->uEdge);
228 return (SIZE_T)GetPrimaryTaskbar();
229 return NULL;
231 FIXME("SHAppBarMessage(ABM_SETAUTOHIDEBAR, hwnd=%p, edge=%x, lparam=%s): stub\n",
233 return TRUE;
235 return TRUE;
236 default:
237 FIXME("SHAppBarMessage(%x) unimplemented\n", msg);
238 return FALSE;
239 }
240}
241
243{
244 struct appbar_cmd cmd;
246 HANDLE return_hproc;
248 LPVOID return_view;
249 struct appbar_response* response;
250
251 if (cds->cbData != sizeof(struct appbar_cmd))
252 return TRUE;
253
254 RtlCopyMemory(&cmd, cds->lpData, cds->cbData);
255
256 result = handle_appbarmessage(cmd.dwMsg, &cmd.abd);
257
258 return_hproc = OpenProcess(PROCESS_DUP_HANDLE, FALSE, cmd.return_process);
259 if (return_hproc == NULL)
260 {
261 ERR("couldn't open calling process\n");
262 return TRUE;
263 }
264
265 if (!DuplicateHandle(return_hproc, UlongToHandle(cmd.return_map), GetCurrentProcess(), &return_map, 0, FALSE, DUPLICATE_SAME_ACCESS))
266 {
267 ERR("couldn't duplicate handle\n");
268 CloseHandle(return_hproc);
269 return TRUE;
270 }
271 CloseHandle(return_hproc);
272
273 return_view = MapViewOfFile(return_map, FILE_MAP_WRITE, 0, 0, sizeof(struct appbar_response));
274
275 if (return_view)
276 {
277 response = (struct appbar_response*)return_view;
278 response->result = result;
279 response->abd = cmd.abd;
280
281 UnmapViewOfFile(return_view);
282 }
283 else
284 {
285 ERR("couldn't map view of file\n");
286 }
287
288 CloseHandle(return_map);
289 return TRUE;
290}
struct mke2fs_defaults settings[]
static struct list appbars
Definition: appbar.cpp:65
LRESULT appbar_message(COPYDATASTRUCT *cds)
Definition: appbar.cpp:242
#define GetPrimaryTaskbar()
Definition: appbar.cpp:38
void appbar_notify_all(HMONITOR hMon, UINT uMsg, HWND hwndExclude, LPARAM lParam)
Definition: appbar.cpp:80
static struct appbar_data * get_appbar(HWND hwnd)
Definition: appbar.cpp:67
static void appbar_cliprect(HWND hwnd, RECT *rect)
Definition: appbar.cpp:103
static UINT_PTR handle_appbarmessage(DWORD msg, _AppBarData *abd)
Definition: appbar.cpp:135
static void send_poschanged(HWND hwnd)
Definition: appbar.cpp:97
#define msg(x)
Definition: auth_time.c:54
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
TaskbarSettings g_TaskbarSettings
Definition: settings.cpp:23
#define TWM_SETTINGSCHANGED
Definition: precomp.h:133
#define UlongToHandle(ul)
Definition: basetsd.h:97
Definition: list.h:37
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define UnmapViewOfFile
Definition: compat.h:746
#define HeapAlloc
Definition: compat.h:733
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define GetCurrentProcess()
Definition: compat.h:759
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MapViewOfFile
Definition: compat.h:745
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint64EXT * result
Definition: glext.h:11304
#define PROCESS_DUP_HANDLE
uint32_t entry
Definition: isohybrid.c:63
#define min(a, b)
Definition: monoChain.cc:55
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
HMONITOR WINAPI MonitorFromWindow(HWND, DWORD)
unsigned int UINT
Definition: ndis.h:50
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define ABM_WINDOWPOSCHANGED
Definition: shellapi.h:71
#define ABE_BOTTOM
Definition: shellapi.h:20
#define ABM_GETTASKBARPOS
Definition: shellapi.h:67
#define ABM_GETSTATE
Definition: shellapi.h:66
#define ABM_SETAUTOHIDEBAR
Definition: shellapi.h:70
#define ABE_RIGHT
Definition: shellapi.h:19
#define ABE_TOP
Definition: shellapi.h:18
#define ABM_SETSTATE
Definition: shellapi.h:72
#define ABM_SETPOS
Definition: shellapi.h:65
#define ABM_ACTIVATE
Definition: shellapi.h:68
#define ABE_LEFT
Definition: shellapi.h:17
#define ABS_ALWAYSONTOP
Definition: shellapi.h:22
#define ABM_REMOVE
Definition: shellapi.h:63
#define ABS_AUTOHIDE
Definition: shellapi.h:21
#define ABM_NEW
Definition: shellapi.h:62
#define ABM_GETAUTOHIDEBAR
Definition: shellapi.h:69
#define ABN_POSCHANGED
Definition: shellapi.h:74
#define ABM_QUERYPOS
Definition: shellapi.h:64
#define TRACE(s)
Definition: solgame.cpp:4
& rect
Definition: startmenu.cpp:1413
TW_STRUCKRECTS2 sr
Definition: precomp.h:225
UINT uCallbackMessage
Definition: shellapi.h:220
LPARAM lParam
Definition: shellapi.h:223
HWND hWnd
Definition: shellapi.h:219
UINT uEdge
Definition: shellapi.h:221
DWORD AutoHide
Definition: precomp.h:204
DWORD AlwaysOnTop
Definition: precomp.h:205
DWORD Position
Definition: precomp.h:210
struct _AppBarData abd
Definition: appbar.cpp:45
DWORD return_process
Definition: appbar.cpp:44
DWORD dwMsg
Definition: appbar.cpp:42
ULONG return_map
Definition: appbar.cpp:43
UINT edge
Definition: appbar.cpp:59
RECT rc
Definition: appbar.cpp:60
UINT callback_msg
Definition: appbar.cpp:58
BOOL space_reserved
Definition: appbar.cpp:61
HWND hwnd
Definition: appbar.cpp:57
struct list entry
Definition: appbar.cpp:56
struct _AppBarData abd
Definition: appbar.cpp:51
ULONGLONG result
Definition: appbar.cpp:50
Definition: ftp_var.h:139
#define max(a, b)
Definition: svc.c:63
#define LIST_INIT(head)
Definition: queue.h:197
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define FILE_MAP_WRITE
Definition: winbase.h:155
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI EqualRect(_In_ LPCRECT, _In_ LPCRECT)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define DUPLICATE_SAME_ACCESS