[PATCH] implement SHAppBarMessage
Vincent Povirk
vincent at codeweavers.com
Wed Jul 30 08:40:14 CDT 2008
---
dlls/shell32/Makefile.in | 1 +
dlls/shell32/appbar.c | 127 +++++++++++
dlls/shell32/shell32_main.c | 55 -----
dlls/shell32/tests/Makefile.in | 1 +
dlls/shell32/tests/appbar.c | 410 ++++++++++++++++++++++++++++++++++
dlls/shell32/tests/systray.c | 63 +-----
programs/explorer/Makefile.in | 1 +
programs/explorer/appbar.c | 305 +++++++++++++++++++++++++
programs/explorer/desktop.c | 1 +
programs/explorer/explorer_private.h | 2 +
10 files changed, 849 insertions(+), 117 deletions(-)
create mode 100644 dlls/shell32/appbar.c
create mode 100644 dlls/shell32/tests/appbar.c
create mode 100644 programs/explorer/appbar.c
diff --git a/dlls/shell32/Makefile.in b/dlls/shell32/Makefile.in
index d98bdb3..7d8cc0b 100644
--- a/dlls/shell32/Makefile.in
+++ b/dlls/shell32/Makefile.in
@@ -10,6 +10,7 @@ DELAYIMPORTS = ole32 oleaut32
C_SRCS = \
autocomplete.c \
+ appbar.c \
brsfolder.c \
changenotify.c \
classes.c \
diff --git a/dlls/shell32/appbar.c b/dlls/shell32/appbar.c
new file mode 100644
index 0000000..f999b53
--- /dev/null
+++ b/dlls/shell32/appbar.c
@@ -0,0 +1,127 @@
+/*
+ * SHAppBarMessage implementation
+ *
+ * Copyright 2008 Vincent Povirk for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "winerror.h"
+#include "winreg.h"
+#include "dlgs.h"
+#include "shellapi.h"
+#include "winuser.h"
+#include "wingdi.h"
+
+#include <wine/debug.h>
+#include <wine/unicode.h>
+
+WINE_DEFAULT_DEBUG_CHANNEL(appbar);
+
+struct appbar_cmd
+{
+ HANDLE return_map;
+ DWORD return_process;
+ APPBARDATA abd;
+};
+
+struct appbar_response
+{
+ UINT_PTR result;
+ RECT rc;
+};
+
+/*************************************************************************
+ * SHAppBarMessage [SHELL32.@]
+ */
+UINT_PTR WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
+{
+ struct appbar_cmd command;
+ struct appbar_response* response;
+ HANDLE return_map;
+ LPVOID return_view;
+ HWND appbarmsg_window;
+ COPYDATASTRUCT cds;
+ DWORD_PTR msg_result;
+ static const WCHAR classname[] = {'W','i','n','e','A','p','p','B','a','r',0};
+
+ UINT_PTR ret = 0;
+
+ TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
+ msg, data->cbSize, data->hWnd, data->uCallbackMessage, data->uEdge,
+ wine_dbgstr_rect(&data->rc), data->lParam);
+
+ if (data->cbSize < sizeof(APPBARDATA))
+ {
+ WARN("data at %p is too small\n", data);
+ return FALSE;
+ }
+
+ command.abd = *data;
+
+ return_map = CreateFileMappingW(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, sizeof(struct appbar_response), NULL);
+ if (return_map == NULL)
+ {
+ ERR("couldn't create file mapping\n");
+ return 0;
+ }
+ command.return_map = return_map;
+
+ command.return_process = GetCurrentProcessId();
+
+ appbarmsg_window = FindWindowW(classname, NULL);
+ if (appbarmsg_window == NULL)
+ {
+ ERR("couldn't find appbar window\n");
+ CloseHandle(return_map);
+ return 0;
+ }
+
+ cds.dwData = msg;
+ cds.cbData = sizeof(command);
+ cds.lpData = &command;
+
+ SendMessageTimeoutW(appbarmsg_window, WM_COPYDATA, (WPARAM)data->hWnd, (LPARAM)&cds, SMTO_BLOCK, INFINITE, &msg_result);
+
+ return_view = MapViewOfFile(return_map, FILE_MAP_READ, 0, 0, sizeof(struct appbar_response));
+ if (return_view == NULL)
+ {
+ ERR("MapViewOfFile failed\n");
+ CloseHandle(return_map);
+ return 0;
+ }
+
+ response = (struct appbar_response*)return_view;
+
+ ret = response->result;
+ data->rc = response->rc;
+
+ UnmapViewOfFile(return_view);
+
+ CloseHandle(return_map);
+
+ return ret;
+}
+
+
diff --git a/dlls/shell32/shell32_main.c b/dlls/shell32/shell32_main.c
index 3026582..9c400e4 100644
--- a/dlls/shell32/shell32_main.c
+++ b/dlls/shell32/shell32_main.c
@@ -867,61 +867,6 @@ static void paint_dropline( HDC hdc, HWND hWnd )
}
/*************************************************************************
- * SHAppBarMessage [SHELL32.@]
- */
-UINT_PTR WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
-{
- int width=data->rc.right - data->rc.left;
- int height=data->rc.bottom - data->rc.top;
- RECT rec=data->rc;
-
- FIXME("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}: stub\n",
- msg, data->cbSize, data->hWnd, data->uCallbackMessage, data->uEdge,
- wine_dbgstr_rect(&data->rc), data->lParam);
-
- switch (msg)
- {
- case ABM_GETSTATE:
- return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
- case ABM_GETTASKBARPOS:
- /* FIXME: This is wrong. It should return the taskbar co-ords and edge from the monitor
- which contains data->hWnd */
- GetWindowRect(data->hWnd, &rec);
- data->rc=rec;
- return TRUE;
- case ABM_ACTIVATE:
- SetActiveWindow(data->hWnd);
- return TRUE;
- case ABM_GETAUTOHIDEBAR:
- return 0; /* pretend there is no autohide bar */
- case ABM_NEW:
- /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
- SetWindowPos(data->hWnd,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
- return TRUE;
- case ABM_QUERYPOS:
- GetWindowRect(data->hWnd, &(data->rc));
- return TRUE;
- case ABM_REMOVE:
- FIXME("ABM_REMOVE broken\n");
- /* FIXME: this is wrong; should it be DestroyWindow instead? */
- /*CloseHandle(data->hWnd);*/
- return TRUE;
- case ABM_SETAUTOHIDEBAR:
- SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
- width,height,SWP_SHOWWINDOW);
- return TRUE;
- case ABM_SETPOS:
- data->uEdge=(ABE_RIGHT | ABE_LEFT);
- SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
- width,height,SWP_SHOWWINDOW);
- return TRUE;
- case ABM_WINDOWPOSCHANGED:
- return TRUE;
- }
- return FALSE;
-}
-
-/*************************************************************************
* SHHelpShortcuts_RunDLLA [SHELL32.@]
*
*/
diff --git a/dlls/shell32/tests/Makefile.in b/dlls/shell32/tests/Makefile.in
index 36e0754..4b1a140 100644
--- a/dlls/shell32/tests/Makefile.in
+++ b/dlls/shell32/tests/Makefile.in
@@ -6,6 +6,7 @@ TESTDLL = shell32.dll
IMPORTS = shell32 ole32 oleaut32 user32 advapi32 kernel32
CTESTS = \
+ appbar.c \
generated.c \
shelllink.c \
shellpath.c \
diff --git a/dlls/shell32/tests/appbar.c b/dlls/shell32/tests/appbar.c
new file mode 100644
index 0000000..e1c8fa7
--- /dev/null
+++ b/dlls/shell32/tests/appbar.c
@@ -0,0 +1,410 @@
+/* Unit tests for appbars
+ *
+ * Copyright 2008 Vincent Povirk for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <assert.h>
+#include <stdarg.h>
+
+#include <windows.h>
+
+#include "wine/test.h"
+
+#define MSG_APPBAR WM_APP
+
+static const WCHAR testwindow_class[] = {'t','e','s','t','w','i','n','d','o','w',0};
+
+static HMONITOR (WINAPI *pMonitorFromWindow)(HWND, DWORD);
+
+struct testwindow_info
+{
+ RECT desired_rect;
+ UINT edge;
+ RECT allocated_rect;
+};
+
+static void testwindow_setpos(HWND hwnd)
+{
+ struct testwindow_info* info = (struct testwindow_info*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ APPBARDATA abd;
+ BOOL ret;
+
+ ok(info != NULL, "got unexpected ABN_POSCHANGED notification\n");
+
+ if (!info)
+ {
+ return;
+ }
+
+ abd.cbSize = sizeof(abd);
+ abd.hWnd = hwnd;
+ abd.uEdge = info->edge;
+ abd.rc = info->desired_rect;
+ ret = SHAppBarMessage(ABM_QUERYPOS, &abd);
+ ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
+ switch (info->edge)
+ {
+ case ABE_BOTTOM:
+ ok(info->desired_rect.top == abd.rc.top, "ABM_QUERYPOS changed top of rect from %i to %i\n", info->desired_rect.top, abd.rc.top);
+ abd.rc.top = abd.rc.bottom - (info->desired_rect.bottom - info->desired_rect.top);
+ break;
+ case ABE_LEFT:
+ ok(info->desired_rect.right == abd.rc.right, "ABM_QUERYPOS changed right of rect from %i to %i\n", info->desired_rect.top, abd.rc.top);
+ abd.rc.right = abd.rc.left + (info->desired_rect.right - info->desired_rect.left);
+ break;
+ case ABE_RIGHT:
+ ok(info->desired_rect.left == abd.rc.left, "ABM_QUERYPOS changed left of rect from %i to %i\n", info->desired_rect.top, abd.rc.top);
+ abd.rc.left = abd.rc.right - (info->desired_rect.right - info->desired_rect.left);
+ break;
+ case ABE_TOP:
+ ok(info->desired_rect.bottom == abd.rc.bottom, "ABM_QUERYPOS changed bottom of rect from %i to %i\n", info->desired_rect.top, abd.rc.top);
+ abd.rc.bottom = abd.rc.top + (info->desired_rect.bottom - info->desired_rect.top);
+ break;
+ }
+
+ ret = SHAppBarMessage(ABM_SETPOS, &abd);
+ ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
+
+ info->allocated_rect = abd.rc;
+ MoveWindow(hwnd, abd.rc.left, abd.rc.top, abd.rc.right-abd.rc.left, abd.rc.bottom-abd.rc.top, TRUE);
+}
+
+static LRESULT CALLBACK testwindow_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ switch(msg)
+ {
+ case MSG_APPBAR:
+ {
+ switch(wparam)
+ {
+ case ABN_POSCHANGED:
+ testwindow_setpos(hwnd);
+ break;
+ }
+ return 0;
+ }
+ }
+
+ return DefWindowProc(hwnd, msg, wparam, lparam);
+}
+
+/* process messages for 1 second */
+static void do_events(void)
+{
+ MSG msg;
+ UINT_PTR timerid;
+
+ timerid = SetTimer(NULL, 0, 1000, NULL);
+ while (GetMessageW(&msg, NULL, 0, 0) &&
+ !(msg.message == WM_TIMER && msg.hwnd == NULL && msg.wParam == timerid))
+ {
+ TranslateMessage(&msg);
+ DispatchMessageW(&msg);
+ }
+
+ KillTimer(NULL, timerid);
+}
+
+static void register_testwindow_class(void)
+{
+ WNDCLASSEXW cls;
+
+ ZeroMemory(&cls, sizeof(cls));
+ cls.cbSize = sizeof(cls);
+ cls.style = 0;
+ cls.lpfnWndProc = testwindow_wndproc;
+ cls.hInstance = NULL;
+ cls.hCursor = LoadCursor(0, IDC_ARROW);
+ cls.hbrBackground = (HBRUSH) COLOR_WINDOW;
+ cls.lpszClassName = testwindow_class;
+
+ RegisterClassExW(&cls);
+}
+
+static void test_setpos(void)
+{
+ APPBARDATA abd;
+ RECT rc;
+ int screen_width, screen_height, expected;
+ HWND window1, window2, window3;
+ struct testwindow_info window1_info, window2_info, window3_info;
+ BOOL ret;
+
+ screen_width = GetSystemMetrics(SM_CXSCREEN);
+ screen_height = GetSystemMetrics(SM_CYSCREEN);
+
+ /* create and register window1 */
+ window1 = CreateWindowExW(WS_EX_TOOLWINDOW|WS_EX_TOPMOST,
+ testwindow_class, testwindow_class, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0,
+ NULL, NULL, NULL, NULL);
+ ok(window1 != NULL, "couldn't create window\n");
+ do_events();
+ abd.cbSize = sizeof(abd);
+ abd.hWnd = window1;
+ abd.uCallbackMessage = MSG_APPBAR;
+ ret = SHAppBarMessage(ABM_NEW, &abd);
+ ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
+
+ /* ABM_NEW should return FALSE if the window is already registered */
+ ret = SHAppBarMessage(ABM_NEW, &abd);
+ ok(ret == FALSE, "SHAppBarMessage returned %i\n", ret);
+ do_events();
+
+ /* dock window1 to the bottom of the screen */
+ window1_info.edge = ABE_BOTTOM;
+ window1_info.desired_rect.left = 0;
+ window1_info.desired_rect.right = screen_width;
+ window1_info.desired_rect.top = screen_height - 15;
+ window1_info.desired_rect.bottom = screen_height;
+ SetWindowLongPtr(window1, GWLP_USERDATA, (LONG_PTR)&window1_info);
+ testwindow_setpos(window1);
+ do_events();
+
+ /* create and register window2 */
+ window2 = CreateWindowExW(WS_EX_TOOLWINDOW|WS_EX_TOPMOST,
+ testwindow_class, testwindow_class, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0,
+ NULL, NULL, NULL, NULL);
+ ok(window2 != NULL, "couldn't create window\n");
+ abd.hWnd = window2;
+ ret = SHAppBarMessage(ABM_NEW, &abd);
+ ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
+
+ /* dock window2 to the bottom of the screen */
+ window2_info.edge = ABE_BOTTOM;
+ window2_info.desired_rect.left = 0;
+ window2_info.desired_rect.right = screen_width;
+ window2_info.desired_rect.top = screen_height - 10;
+ window2_info.desired_rect.bottom = screen_height;
+ SetWindowLongPtr(window2, GWLP_USERDATA, (LONG_PTR)&window2_info);
+ testwindow_setpos(window2);
+ do_events();
+
+ /* the windows are adjusted to they don't overlap */
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+
+ /* make window1 larger, forcing window2 to move out of its way */
+ window1_info.desired_rect.top = screen_height - 20;
+ testwindow_setpos(window1);
+ do_events();
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+
+ /* create and register window3 */
+ window3 = CreateWindowExW(WS_EX_TOOLWINDOW|WS_EX_TOPMOST,
+ testwindow_class, testwindow_class, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0,
+ NULL, NULL, NULL, NULL);
+ ok(window3 != NULL, "couldn't create window\n");
+ do_events();
+
+ abd.hWnd = window3;
+ ret = SHAppBarMessage(ABM_NEW, &abd);
+ ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
+
+ /* dock window3 to the bottom of the screen */
+ window3_info.edge = ABE_BOTTOM;
+ window3_info.desired_rect.left = 0;
+ window3_info.desired_rect.right = screen_width;
+ window3_info.desired_rect.top = screen_height - 10;
+ window3_info.desired_rect.bottom = screen_height;
+ SetWindowLongPtr(window3, GWLP_USERDATA, (LONG_PTR)&window3_info);
+ testwindow_setpos(window3);
+ do_events();
+
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window3_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom);
+ ok(!IntersectRect(&rc, &window3_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+
+ /* move window3 to the right side of the screen */
+ window3_info.edge = ABE_RIGHT;
+ window3_info.desired_rect.left = screen_width - 15;
+ window3_info.desired_rect.right = screen_width;
+ window3_info.desired_rect.top = 0;
+ window3_info.desired_rect.bottom = screen_height;
+ testwindow_setpos(window3);
+ do_events();
+
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window3_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom);
+ ok(!IntersectRect(&rc, &window3_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+
+ /* move window2 to the top of the screen */
+ window2_info.edge = ABE_TOP;
+ window2_info.desired_rect.left = 0;
+ window2_info.desired_rect.right = screen_width;
+ window2_info.desired_rect.top = 0;
+ window2_info.desired_rect.bottom = 15;
+ testwindow_setpos(window2);
+ do_events();
+
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window3_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom);
+ ok(!IntersectRect(&rc, &window3_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+
+ /* move window2 back to the bottom of the screen */
+ window2_info.edge = ABE_BOTTOM;
+ window2_info.desired_rect.left = 0;
+ window2_info.desired_rect.right = screen_width;
+ window2_info.desired_rect.top = screen_height - 10;
+ window2_info.desired_rect.bottom = screen_height;
+ testwindow_setpos(window2);
+ do_events();
+
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+ ok(!IntersectRect(&rc, &window1_info.allocated_rect, &window3_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window1_info.allocated_rect.left, window1_info.allocated_rect.top, window1_info.allocated_rect.right, window1_info.allocated_rect.bottom,
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom);
+ ok(!IntersectRect(&rc, &window3_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+
+ /* removing window1 will cause window2 to move down into its space */
+ expected = max(window1_info.allocated_rect.bottom, window2_info.allocated_rect.bottom);
+
+ SetWindowLongPtr(window1, GWLP_USERDATA, 0); /* don't expect further ABN_POSCHANGED notifications */
+ abd.hWnd = window1;
+ ret = SHAppBarMessage(ABM_REMOVE, &abd);
+ ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
+ do_events();
+ DestroyWindow(window1);
+
+ ok(window2_info.allocated_rect.bottom = expected, "window2's bottom is %i, expected %i\n", window2_info.allocated_rect.bottom, expected);
+
+ ok(!IntersectRect(&rc, &window3_info.allocated_rect, &window2_info.allocated_rect),
+ "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n",
+ window3_info.allocated_rect.left, window3_info.allocated_rect.top, window3_info.allocated_rect.right, window3_info.allocated_rect.bottom,
+ window2_info.allocated_rect.left, window2_info.allocated_rect.top, window2_info.allocated_rect.right, window2_info.allocated_rect.bottom);
+
+ /* remove the other windows */
+ SetWindowLongPtr(window2, GWLP_USERDATA, 0);
+ abd.hWnd = window2;
+ ret = SHAppBarMessage(ABM_REMOVE, &abd);
+ ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
+ do_events();
+ DestroyWindow(window2);
+
+ SetWindowLongPtr(window3, GWLP_USERDATA, 0);
+ abd.hWnd = window3;
+ ret = SHAppBarMessage(ABM_REMOVE, &abd);
+ ok(ret == TRUE, "SHAppBarMessage returned %i\n", ret);
+ do_events();
+ DestroyWindow(window3);
+}
+
+static void test_appbarget(void)
+{
+ APPBARDATA abd;
+ HWND hwnd, foregnd;
+ UINT_PTR ret;
+
+ memset(&abd, 0xcc, sizeof(abd));
+ abd.cbSize = sizeof(abd);
+ abd.uEdge = ABE_BOTTOM;
+
+ hwnd = (HWND)SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
+ ok(hwnd == NULL || IsWindow(hwnd), "ret %p which is not a window\n", hwnd);
+ ok(abd.hWnd == (HWND)0xcccccccc, "hWnd overwritten\n");
+
+ if (!pMonitorFromWindow)
+ {
+ skip("MonitorFromWindow is not available\n");
+ }
+ else
+ {
+ /* Presumably one can pass a hwnd with ABM_GETAUTOHIDEBAR to specify a monitor.
+ Pass the foreground window and check */
+ foregnd = GetForegroundWindow();
+ if(foregnd)
+ {
+ abd.hWnd = foregnd;
+ hwnd = (HWND)SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
+ ok(hwnd == NULL || IsWindow(hwnd), "ret %p which is not a window\n", hwnd);
+ ok(abd.hWnd == foregnd, "hWnd overwritten\n");
+ if(hwnd)
+ {
+ HMONITOR appbar_mon, foregnd_mon;
+ appbar_mon = pMonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
+ foregnd_mon = pMonitorFromWindow(foregnd, MONITOR_DEFAULTTONEAREST);
+ ok(appbar_mon == foregnd_mon, "Windows on different monitors\n");
+ }
+ }
+ }
+
+ memset(&abd, 0xcc, sizeof(abd));
+ abd.cbSize = sizeof(abd);
+ ret = SHAppBarMessage(ABM_GETTASKBARPOS, &abd);
+ if(ret)
+ {
+ ok(abd.hWnd == (HWND)0xcccccccc, "hWnd overwritten\n");
+todo_wine
+{
+ ok(abd.uEdge <= ABE_BOTTOM, "uEdge not returned\n");
+ ok(abd.rc.left != 0xcccccccc, "rc not updated\n");
+}
+ }
+
+ return;
+}
+
+START_TEST(appbar)
+{
+ HMODULE huser32;
+
+ huser32 = GetModuleHandleA("user32.dll");
+ pMonitorFromWindow = (void*)GetProcAddress(huser32, "MonitorFromWindow");
+
+ register_testwindow_class();
+
+ test_setpos();
+ test_appbarget();
+}
diff --git a/dlls/shell32/tests/systray.c b/dlls/shell32/tests/systray.c
index 42d2d4a..5675806 100644
--- a/dlls/shell32/tests/systray.c
+++ b/dlls/shell32/tests/systray.c
@@ -27,7 +27,6 @@
static HWND hMainWnd;
static BOOL (WINAPI *pShell_NotifyIconW)(DWORD,PNOTIFYICONDATAW);
-static HMONITOR (WINAPI *pMonitorFromWindow)(HWND, DWORD);
void test_cbsize(void)
{
@@ -76,74 +75,16 @@ void test_cbsize(void)
ok(!Shell_NotifyIconA(NIM_DELETE, &nidA), "The icon was not deleted\n");
}
-static void test_SHAppBarMessage(void)
-{
- APPBARDATA abd;
- HWND hwnd, foregnd;
- UINT_PTR ret;
-
- memset(&abd, 0xcc, sizeof(abd));
- abd.cbSize = sizeof(abd);
- abd.uEdge = ABE_BOTTOM;
-
- hwnd = (HWND)SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
- ok(hwnd == NULL || IsWindow(hwnd), "ret %p which is not a window\n", hwnd);
- ok(abd.hWnd == (HWND)0xcccccccc, "hWnd overwritten\n");
-
- if (!pMonitorFromWindow)
- {
- skip("MonitorFromWindow is not available\n");
- }
- else
- {
- /* Presumably one can pass a hwnd with ABM_GETAUTOHIDEBAR to specify a monitor.
- Pass the foreground window and check */
- foregnd = GetForegroundWindow();
- if(foregnd)
- {
- abd.hWnd = foregnd;
- hwnd = (HWND)SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
- ok(hwnd == NULL || IsWindow(hwnd), "ret %p which is not a window\n", hwnd);
- ok(abd.hWnd == foregnd, "hWnd overwritten\n");
- if(hwnd)
- {
- HMONITOR appbar_mon, foregnd_mon;
- appbar_mon = pMonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
- foregnd_mon = pMonitorFromWindow(foregnd, MONITOR_DEFAULTTONEAREST);
- ok(appbar_mon == foregnd_mon, "Windows on different monitors\n");
- }
- }
- }
-
- memset(&abd, 0xcc, sizeof(abd));
- abd.cbSize = sizeof(abd);
- ret = SHAppBarMessage(ABM_GETTASKBARPOS, &abd);
- if(ret)
- {
- ok(abd.hWnd == (HWND)0xcccccccc, "hWnd overwritten\n");
-todo_wine
-{
- ok(abd.uEdge <= ABE_BOTTOM, "uEdge not returned\n");
- ok(abd.rc.left != 0xcccccccc, "rc not updated\n");
-}
- }
-
- return;
-}
-
START_TEST(systray)
{
WNDCLASSA wc;
MSG msg;
RECT rc;
- HMODULE huser32, hshell32;
+ HMODULE hshell32;
hshell32 = GetModuleHandleA("shell32.dll");
pShell_NotifyIconW = (void*)GetProcAddress(hshell32, "Shell_NotifyIconW");
- huser32 = GetModuleHandleA("user32.dll");
- pMonitorFromWindow = (void*)GetProcAddress(huser32, "MonitorFromWindow");
-
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
@@ -169,6 +110,4 @@ START_TEST(systray)
DispatchMessageA(&msg);
}
DestroyWindow(hMainWnd);
-
- test_SHAppBarMessage();
}
diff --git a/programs/explorer/Makefile.in b/programs/explorer/Makefile.in
index 97b2c74..725708e 100644
--- a/programs/explorer/Makefile.in
+++ b/programs/explorer/Makefile.in
@@ -8,6 +8,7 @@ IMPORTS = rpcrt4 user32 gdi32 advapi32 kernel32 ntdll
DELAYIMPORTS = comctl32
C_SRCS = \
+ appbar.c \
desktop.c \
explorer.c \
systray.c
diff --git a/programs/explorer/appbar.c b/programs/explorer/appbar.c
new file mode 100644
index 0000000..b5cee20
--- /dev/null
+++ b/programs/explorer/appbar.c
@@ -0,0 +1,305 @@
+/*
+ * SHAppBarMessage implementation
+ *
+ * Copyright 2008 Vincent Povirk for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * TODO: freedesktop _NET_WM_STRUT integration
+ *
+ * TODO: find when a fullscreen app is in the foreground and send FULLSCREENAPP
+ * notifications
+ *
+ * TODO: detect changes in the screen size and send ABN_POSCHANGED ?
+ *
+ * TODO: multiple monitor support
+ */
+
+#include "wine/unicode.h"
+
+#include <windows.h>
+#include <wine/debug.h>
+#include "explorer_private.h"
+
+#include "wine/list.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(appbar);
+
+struct appbar_cmd
+{
+ HANDLE return_map;
+ DWORD return_process;
+ APPBARDATA abd;
+};
+
+struct appbar_response
+{
+ UINT_PTR result;
+ RECT rc;
+};
+
+static HWND appbarmsg_window = NULL;
+
+struct appbar_data
+{
+ struct list entry;
+ HWND hwnd;
+ UINT callback_msg;
+ UINT edge;
+ RECT rc;
+ BOOL space_reserved;
+ /* BOOL autohide; */
+};
+
+static struct list appbars = LIST_INIT(appbars);
+
+static struct appbar_data* get_appbar(HWND hwnd)
+{
+ struct appbar_data* data;
+
+ LIST_FOR_EACH_ENTRY(data, &appbars, struct appbar_data, entry)
+ {
+ if (data->hwnd == hwnd)
+ return data;
+ }
+
+ return NULL;
+}
+
+/* send_poschanged: send ABN_POSCHANGED to every appbar except one */
+static void send_poschanged(HWND hwnd)
+{
+ struct appbar_data* data;
+ LIST_FOR_EACH_ENTRY(data, &appbars, struct appbar_data, entry)
+ {
+ if (data->hwnd != hwnd)
+ {
+ PostMessageW(data->hwnd, data->callback_msg, ABN_POSCHANGED, 0);
+ }
+ }
+}
+
+/* appbar_cliprect: cut out parts of the rectangle that interfere with existing appbars */
+static void appbar_cliprect(PAPPBARDATA abd)
+{
+ struct appbar_data* data;
+ LIST_FOR_EACH_ENTRY(data, &appbars, struct appbar_data, entry)
+ {
+ if (data->hwnd == abd->hWnd)
+ {
+ /* we only care about appbars that were added before this one */
+ return;
+ }
+ if (data->space_reserved)
+ {
+ /* move in the side that corresponds to the other appbar's edge */
+ switch (data->edge)
+ {
+ case ABE_BOTTOM:
+ abd->rc.bottom = min(abd->rc.bottom, data->rc.top);
+ break;
+ case ABE_LEFT:
+ abd->rc.left = max(abd->rc.left, data->rc.right);
+ break;
+ case ABE_RIGHT:
+ abd->rc.right = min(abd->rc.right, data->rc.left);
+ break;
+ case ABE_TOP:
+ abd->rc.top = max(abd->rc.top, data->rc.bottom);
+ break;
+ }
+ }
+ }
+}
+
+static UINT_PTR handle_appbarmessage(DWORD msg, PAPPBARDATA abd)
+{
+ struct appbar_data* data;
+
+ switch (msg)
+ {
+ case ABM_NEW:
+ if (get_appbar(abd->hWnd))
+ {
+ /* fail when adding an hwnd the second time */
+ return FALSE;
+ }
+
+ data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct appbar_data));
+ if (!data)
+ {
+ WINE_ERR("out of memory\n");
+ return FALSE;
+ }
+ data->hwnd = abd->hWnd;
+ data->callback_msg = abd->uCallbackMessage;
+
+ list_add_tail(&appbars, &data->entry);
+
+ return TRUE;
+ case ABM_REMOVE:
+ if ((data = get_appbar(abd->hWnd)))
+ {
+ list_remove(&data->entry);
+
+ send_poschanged(abd->hWnd);
+
+ HeapFree(GetProcessHeap(), 0, data);
+ }
+ else
+ WINE_WARN("removing hwnd %p not on the list\n", abd->hWnd);
+ return TRUE;
+ case ABM_QUERYPOS:
+ if (abd->uEdge > ABE_BOTTOM)
+ WINE_WARN("invalid edge %i for %p\n", abd->uEdge, abd->hWnd);
+ appbar_cliprect(abd);
+ return TRUE;
+ case ABM_SETPOS:
+ if (abd->uEdge > ABE_BOTTOM)
+ {
+ WINE_WARN("invalid edge %i for %p\n", abd->uEdge, abd->hWnd);
+ return TRUE;
+ }
+ if ((data = get_appbar(abd->hWnd)))
+ {
+ BOOL poschanged;
+
+ /* calculate acceptable space */
+ appbar_cliprect(abd);
+
+ poschanged = !EqualRect(&abd->rc, &data->rc);
+
+ /* reserve that space for this appbar */
+ data->edge = abd->uEdge;
+ data->rc = abd->rc;
+ data->space_reserved = TRUE;
+
+ if (poschanged)
+ send_poschanged(abd->hWnd);
+ }
+ else
+ {
+ WINE_WARN("app sent ABM_SETPOS message for %p without ABM_ADD\n", abd->hWnd);
+ }
+ return TRUE;
+ case ABM_GETSTATE:
+ WINE_FIXME("SHAppBarMessage(ABM_GETSTATE): stub\n");
+ return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
+ case ABM_GETTASKBARPOS:
+ WINE_FIXME("SHAppBarMessage(ABM_GETTASKBARPOS, hwnd=%p): stub\n", abd->hWnd);
+ return FALSE;
+ case ABM_ACTIVATE:
+ WINE_FIXME("SHAppBarMessage(ABM_ACTIVATE, hwnd=%p, lparam=%lx): stub\n", abd->hWnd, abd->lParam);
+ return TRUE;
+ case ABM_GETAUTOHIDEBAR:
+ WINE_FIXME("SHAppBarMessage(ABM_GETAUTOHIDEBAR, hwnd=%p, edge=%x): stub\n", abd->hWnd, abd->uEdge);
+ return 0;
+ case ABM_SETAUTOHIDEBAR:
+ WINE_FIXME("SHAppBarMessage(ABM_SETAUTOHIDEBAR, hwnd=%p, edge=%x, lparam=%lx): stub\n", abd->hWnd, abd->uEdge, abd->lParam);
+ return 0;
+ case ABM_WINDOWPOSCHANGED:
+ WINE_FIXME("SHAppBarMessage(ABM_WINDOWPOSCHANGED, hwnd=%p): stub\n", abd->hWnd);
+ return TRUE;
+ default:
+ WINE_FIXME("SHAppBarMessage(%x) unimplemented\n", msg);
+ return FALSE;
+ }
+}
+
+LRESULT CALLBACK appbar_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ switch (msg)
+ {
+ case WM_COPYDATA:
+ {
+ COPYDATASTRUCT* cds;
+ struct appbar_cmd cmd;
+ UINT_PTR result;
+ HANDLE return_hproc;
+ HANDLE return_map;
+ LPVOID return_view;
+ struct appbar_response* response;
+
+ cds = (COPYDATASTRUCT*)lparam;
+ if (cds->cbData != sizeof(struct appbar_cmd))
+ return TRUE;
+ CopyMemory(&cmd, cds->lpData, cds->cbData);
+
+ result = handle_appbarmessage(cds->dwData, &cmd.abd);
+
+ return_hproc = OpenProcess(PROCESS_DUP_HANDLE, FALSE, cmd.return_process);
+ if (return_hproc == NULL)
+ {
+ WINE_ERR("couldn't open calling process\n");
+ return TRUE;
+ }
+
+ if (!DuplicateHandle(return_hproc, cmd.return_map, GetCurrentProcess(), &return_map, 0, FALSE, DUPLICATE_SAME_ACCESS))
+ {
+ WINE_ERR("couldn't duplicate handle\n");
+ CloseHandle(return_hproc);
+ return TRUE;
+ }
+ CloseHandle(return_hproc);
+
+ return_view = MapViewOfFile(return_map, FILE_MAP_WRITE, 0, 0, sizeof(struct appbar_response));
+
+ if (return_view)
+ {
+ response = (struct appbar_response*)return_view;
+ response->result = result;
+ response->rc = cmd.abd.rc;
+
+ UnmapViewOfFile(return_view);
+ }
+ else
+ WINE_ERR("couldn't map view of file\n");
+
+ CloseHandle(return_map);
+ return TRUE;
+ }
+ default:
+ break;
+ }
+
+ return DefWindowProcW(hwnd, msg, wparam, lparam);
+}
+
+void initialize_appbar(void)
+{
+ WNDCLASSEXW class;
+ static const WCHAR classname[] = {'W','i','n','e','A','p','p','B','a','r',0};
+
+ /* register the appbar window class */
+ ZeroMemory(&class, sizeof(class));
+ class.cbSize = sizeof(class);
+ class.lpfnWndProc = appbar_wndproc;
+ class.hInstance = NULL;
+ class.lpszClassName = classname;
+
+ if (!RegisterClassExW(&class))
+ {
+ WINE_ERR("Could not register appbar message window class\n");
+ return;
+ }
+
+ appbarmsg_window = CreateWindowW(classname, classname, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
+ if (!appbarmsg_window)
+ {
+ WINE_ERR("Could not create appbar message window\n");
+ return;
+ }
+}
+
diff --git a/programs/explorer/desktop.c b/programs/explorer/desktop.c
index 552d11b..8c6259d 100644
--- a/programs/explorer/desktop.c
+++ b/programs/explorer/desktop.c
@@ -307,6 +307,7 @@ void manage_desktop( WCHAR *arg )
SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
SetDeskWallPaper( (LPSTR)-1 );
initialize_display_settings( hwnd );
+ initialize_appbar();
initialize_systray();
}
else
diff --git a/programs/explorer/explorer_private.h b/programs/explorer/explorer_private.h
index ebff4de..f2a222b 100644
--- a/programs/explorer/explorer_private.h
+++ b/programs/explorer/explorer_private.h
@@ -23,5 +23,7 @@
extern void manage_desktop( WCHAR *arg );
extern void initialize_systray(void);
+extern void initialize_appbar(void);
#endif /* __WINE_EXPLORER_PRIVATE_H */
+
--
1.5.4.3
--=-gdY7KFmNAtD8mIO7KX6F--
More information about the wine-patches
mailing list