[PATCH] move SHAppBarMessage implementation from shell32 to explorer

Vincent Povirk vincent at codeweavers.com
Tue Sep 2 13:58:01 CDT 2008


---
 dlls/shell32/Makefile.in             |    1 +
 dlls/shell32/appbar.c                |  124 +++++++++++++++++++++++
 dlls/shell32/shell32_main.c          |   55 ----------
 programs/explorer/Makefile.in        |    1 +
 programs/explorer/appbar.c           |  182 ++++++++++++++++++++++++++++++++++
 programs/explorer/desktop.c          |    1 +
 programs/explorer/explorer_private.h |    2 +
 7 files changed, 311 insertions(+), 55 deletions(-)
 create mode 100644 dlls/shell32/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..facf72c
--- /dev/null
+++ b/dlls/shell32/appbar.c
@@ -0,0 +1,124 @@
+/*
+ * 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 "shellapi.h"
+#include "winuser.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/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..cb56788
--- /dev/null
+++ b/programs/explorer/appbar.c
@@ -0,0 +1,182 @@
+/*
+ * 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 "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;
+
+static UINT_PTR handle_appbarmessage(DWORD msg, PAPPBARDATA data)
+{
+    int width=data->rc.right - data->rc.left;
+    int height=data->rc.bottom - data->rc.top;
+    RECT rec=data->rc;
+
+    WINE_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_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_REMOVE:
+        WINE_FIXME("ABM_REMOVE broken\n");
+        /* FIXME: this is wrong; should it be DestroyWindow instead? */
+        /*CloseHandle(data->hWnd);*/
+        return TRUE;
+    case ABM_QUERYPOS:
+        GetWindowRect(data->hWnd, &(data->rc));
+        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_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_SETAUTOHIDEBAR:
+        SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
+                         width,height,SWP_SHOWWINDOW);
+        return TRUE;
+    case ABM_WINDOWPOSCHANGED:
+        return TRUE;
+    }
+    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


--=-mp9QP++yuR50lWPczvKG--




More information about the wine-patches mailing list