2008-09-02 20:58:01 +02:00
|
|
|
/*
|
|
|
|
* 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
|
2008-09-02 23:06:42 +02:00
|
|
|
*
|
|
|
|
* 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
|
2008-09-02 20:58:01 +02:00
|
|
|
*/
|
|
|
|
|
2012-01-23 12:16:36 +01:00
|
|
|
#include "windows.h"
|
|
|
|
#include "shellapi.h"
|
|
|
|
#include "wine/debug.h"
|
2008-09-02 20:58:01 +02:00
|
|
|
#include "explorer_private.h"
|
|
|
|
|
|
|
|
#include "wine/list.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(appbar);
|
|
|
|
|
2010-03-30 20:48:40 +02:00
|
|
|
struct appbar_data_msg /* platform-independent data */
|
|
|
|
{
|
|
|
|
LONG hWnd;
|
|
|
|
UINT uCallbackMessage;
|
|
|
|
UINT uEdge;
|
|
|
|
RECT rc;
|
|
|
|
ULONGLONG lParam;
|
|
|
|
};
|
|
|
|
|
2008-09-02 20:58:01 +02:00
|
|
|
struct appbar_cmd
|
|
|
|
{
|
2010-03-30 20:48:40 +02:00
|
|
|
ULONG return_map;
|
|
|
|
DWORD return_process;
|
|
|
|
struct appbar_data_msg abd;
|
2008-09-02 20:58:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct appbar_response
|
|
|
|
{
|
2010-03-30 20:48:40 +02:00
|
|
|
ULONGLONG result;
|
|
|
|
struct appbar_data_msg abd;
|
2008-09-02 20:58:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static HWND appbarmsg_window = NULL;
|
|
|
|
|
2008-09-02 22:17:09 +02:00
|
|
|
struct appbar_data
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
HWND hwnd;
|
|
|
|
UINT callback_msg;
|
2008-09-02 22:36:21 +02:00
|
|
|
UINT edge;
|
|
|
|
RECT rc;
|
|
|
|
BOOL space_reserved;
|
|
|
|
/* BOOL autohide; */
|
2008-09-02 22:17:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-02 22:36:21 +02:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-02 23:06:42 +02:00
|
|
|
/* appbar_cliprect: cut out parts of the rectangle that interfere with existing appbars */
|
2010-03-30 20:48:40 +02:00
|
|
|
static void appbar_cliprect( HWND hwnd, RECT *rect )
|
2008-09-02 23:06:42 +02:00
|
|
|
{
|
|
|
|
struct appbar_data* data;
|
|
|
|
LIST_FOR_EACH_ENTRY(data, &appbars, struct appbar_data, entry)
|
|
|
|
{
|
2010-03-30 20:48:40 +02:00
|
|
|
if (data->hwnd == hwnd)
|
2008-09-02 23:06:42 +02:00
|
|
|
{
|
|
|
|
/* 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:
|
2010-03-30 20:48:40 +02:00
|
|
|
rect->bottom = min(rect->bottom, data->rc.top);
|
2008-09-02 23:06:42 +02:00
|
|
|
break;
|
|
|
|
case ABE_LEFT:
|
2010-03-30 20:48:40 +02:00
|
|
|
rect->left = max(rect->left, data->rc.right);
|
2008-09-02 23:06:42 +02:00
|
|
|
break;
|
|
|
|
case ABE_RIGHT:
|
2010-03-30 20:48:40 +02:00
|
|
|
rect->right = min(rect->right, data->rc.left);
|
2008-09-02 23:06:42 +02:00
|
|
|
break;
|
|
|
|
case ABE_TOP:
|
2010-03-30 20:48:40 +02:00
|
|
|
rect->top = max(rect->top, data->rc.bottom);
|
2008-09-02 23:06:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-30 20:48:40 +02:00
|
|
|
static UINT_PTR handle_appbarmessage(DWORD msg, struct appbar_data_msg *abd)
|
2008-09-02 20:58:01 +02:00
|
|
|
{
|
2008-09-02 22:17:09 +02:00
|
|
|
struct appbar_data* data;
|
2010-03-30 20:48:40 +02:00
|
|
|
HWND hwnd = LongToHandle( abd->hWnd );
|
2008-09-02 22:17:09 +02:00
|
|
|
|
2008-09-02 20:58:01 +02:00
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case ABM_NEW:
|
2010-03-30 20:48:40 +02:00
|
|
|
if (get_appbar(hwnd))
|
2008-09-02 22:17:09 +02:00
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
}
|
2010-03-30 20:48:40 +02:00
|
|
|
data->hwnd = hwnd;
|
2008-09-02 22:17:09 +02:00
|
|
|
data->callback_msg = abd->uCallbackMessage;
|
|
|
|
|
|
|
|
list_add_tail(&appbars, &data->entry);
|
|
|
|
|
2008-09-02 20:58:01 +02:00
|
|
|
return TRUE;
|
|
|
|
case ABM_REMOVE:
|
2010-03-30 20:48:40 +02:00
|
|
|
if ((data = get_appbar(hwnd)))
|
2008-09-02 22:17:09 +02:00
|
|
|
{
|
|
|
|
list_remove(&data->entry);
|
|
|
|
|
2010-03-30 20:48:40 +02:00
|
|
|
send_poschanged(hwnd);
|
2008-09-02 22:36:21 +02:00
|
|
|
|
2008-09-02 22:17:09 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
}
|
|
|
|
else
|
2010-03-30 20:48:40 +02:00
|
|
|
WINE_WARN("removing hwnd %p not on the list\n", hwnd);
|
2008-09-02 20:58:01 +02:00
|
|
|
return TRUE;
|
|
|
|
case ABM_QUERYPOS:
|
2008-09-02 23:06:42 +02:00
|
|
|
if (abd->uEdge > ABE_BOTTOM)
|
2010-03-30 20:48:40 +02:00
|
|
|
WINE_WARN("invalid edge %i for %p\n", abd->uEdge, hwnd);
|
|
|
|
appbar_cliprect( hwnd, &abd->rc );
|
2008-09-02 20:58:01 +02:00
|
|
|
return TRUE;
|
|
|
|
case ABM_SETPOS:
|
2008-09-02 22:36:21 +02:00
|
|
|
if (abd->uEdge > ABE_BOTTOM)
|
|
|
|
{
|
2010-03-30 20:48:40 +02:00
|
|
|
WINE_WARN("invalid edge %i for %p\n", abd->uEdge, hwnd);
|
2008-09-02 22:36:21 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-03-30 20:48:40 +02:00
|
|
|
if ((data = get_appbar(hwnd)))
|
2008-09-02 22:36:21 +02:00
|
|
|
{
|
2008-09-02 23:06:42 +02:00
|
|
|
/* calculate acceptable space */
|
2010-03-30 20:48:40 +02:00
|
|
|
appbar_cliprect( hwnd, &abd->rc );
|
2008-09-02 23:06:42 +02:00
|
|
|
|
2008-09-02 22:36:21 +02:00
|
|
|
if (!EqualRect(&abd->rc, &data->rc))
|
2010-03-30 20:48:40 +02:00
|
|
|
send_poschanged(hwnd);
|
2008-09-02 22:36:21 +02:00
|
|
|
|
2008-09-02 23:06:42 +02:00
|
|
|
/* reserve that space for this appbar */
|
2008-09-02 22:36:21 +02:00
|
|
|
data->edge = abd->uEdge;
|
|
|
|
data->rc = abd->rc;
|
|
|
|
data->space_reserved = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-30 20:48:40 +02:00
|
|
|
WINE_WARN("app sent ABM_SETPOS message for %p without ABM_ADD\n", hwnd);
|
2008-09-02 22:36:21 +02:00
|
|
|
}
|
2008-09-02 20:58:01 +02:00
|
|
|
return TRUE;
|
|
|
|
case ABM_GETSTATE:
|
|
|
|
WINE_FIXME("SHAppBarMessage(ABM_GETSTATE): stub\n");
|
|
|
|
return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
|
|
|
|
case ABM_GETTASKBARPOS:
|
2010-03-30 20:48:40 +02:00
|
|
|
WINE_FIXME("SHAppBarMessage(ABM_GETTASKBARPOS, hwnd=%p): stub\n", hwnd);
|
2008-12-06 19:43:03 +01:00
|
|
|
/* Report the taskbar is at the bottom of the screen. */
|
|
|
|
abd->rc.left = 0;
|
|
|
|
abd->rc.right = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
abd->rc.bottom = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
abd->rc.top = abd->rc.bottom-1;
|
|
|
|
abd->uEdge = ABE_BOTTOM;
|
|
|
|
return TRUE;
|
2008-09-02 20:58:01 +02:00
|
|
|
case ABM_ACTIVATE:
|
|
|
|
return TRUE;
|
|
|
|
case ABM_GETAUTOHIDEBAR:
|
2010-03-30 20:48:40 +02:00
|
|
|
WINE_FIXME("SHAppBarMessage(ABM_GETAUTOHIDEBAR, hwnd=%p, edge=%x): stub\n", hwnd, abd->uEdge);
|
2008-09-02 20:58:01 +02:00
|
|
|
return 0;
|
|
|
|
case ABM_SETAUTOHIDEBAR:
|
2010-03-30 20:48:40 +02:00
|
|
|
WINE_FIXME("SHAppBarMessage(ABM_SETAUTOHIDEBAR, hwnd=%p, edge=%x, lparam=%s): stub\n",
|
|
|
|
hwnd, abd->uEdge, wine_dbgstr_longlong(abd->lParam));
|
2008-09-02 20:58:01 +02:00
|
|
|
return TRUE;
|
|
|
|
case ABM_WINDOWPOSCHANGED:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
2022-02-04 09:56:32 +01:00
|
|
|
WINE_FIXME("SHAppBarMessage(%lx) unimplemented\n", msg);
|
2008-09-02 20:58:01 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-13 12:04:34 +01:00
|
|
|
static LRESULT CALLBACK appbar_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
2008-09-02 20:58:01 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-03-30 20:48:40 +02:00
|
|
|
if (!DuplicateHandle(return_hproc, UlongToHandle(cmd.return_map),
|
|
|
|
GetCurrentProcess(), &return_map, 0, FALSE, DUPLICATE_SAME_ACCESS))
|
2008-09-02 20:58:01 +02:00
|
|
|
{
|
|
|
|
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;
|
2008-12-06 19:43:03 +01:00
|
|
|
response->abd = cmd.abd;
|
2008-09-02 20:58:01 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|