FreeRDP/client/Windows/wf_rail.c

1001 lines
30 KiB
C
Raw Normal View History

/**
2012-10-09 07:02:04 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
*
2014-10-24 19:30:04 +04:00
* Copyright 2013-2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2022-02-16 13:20:38 +03:00
#include <freerdp/config.h>
2018-08-24 14:49:19 +03:00
#include <winpr/crt.h>
#include <freerdp/log.h>
#include <freerdp/client/rail.h>
2014-10-25 02:30:04 +04:00
#include <winpr/tchar.h>
#include <winpr/print.h>
2014-10-24 19:30:04 +04:00
#include "wf_rail.h"
#define TAG CLIENT_TAG("windows")
2019-11-06 17:24:51 +03:00
#define GET_X_LPARAM(lParam) ((UINT16)(lParam & 0xFFFF))
#define GET_Y_LPARAM(lParam) ((UINT16)((lParam >> 16) & 0xFFFF))
struct wf_rail_window
{
wfContext* wfc;
HWND hWnd;
DWORD dwStyle;
DWORD dwExStyle;
int x;
int y;
int width;
int height;
char* title;
};
2014-10-24 19:30:04 +04:00
/* RemoteApp Core Protocol Extension */
typedef struct
2014-10-24 19:30:04 +04:00
{
UINT32 style;
const char* name;
BOOL multi;
} WINDOW_STYLE;
2014-10-24 19:30:04 +04:00
2019-11-06 17:24:51 +03:00
static const WINDOW_STYLE WINDOW_STYLES[] = { { WS_BORDER, "WS_BORDER", FALSE },
{ WS_CAPTION, "WS_CAPTION", FALSE },
{ WS_CHILD, "WS_CHILD", FALSE },
{ WS_CLIPCHILDREN, "WS_CLIPCHILDREN", FALSE },
{ WS_CLIPSIBLINGS, "WS_CLIPSIBLINGS", FALSE },
{ WS_DISABLED, "WS_DISABLED", FALSE },
{ WS_DLGFRAME, "WS_DLGFRAME", FALSE },
{ WS_GROUP, "WS_GROUP", FALSE },
{ WS_HSCROLL, "WS_HSCROLL", FALSE },
{ WS_ICONIC, "WS_ICONIC", FALSE },
{ WS_MAXIMIZE, "WS_MAXIMIZE", FALSE },
{ WS_MAXIMIZEBOX, "WS_MAXIMIZEBOX", FALSE },
{ WS_MINIMIZE, "WS_MINIMIZE", FALSE },
{ WS_MINIMIZEBOX, "WS_MINIMIZEBOX", FALSE },
{ WS_OVERLAPPED, "WS_OVERLAPPED", FALSE },
{ WS_OVERLAPPEDWINDOW, "WS_OVERLAPPEDWINDOW", TRUE },
{ WS_POPUP, "WS_POPUP", FALSE },
{ WS_POPUPWINDOW, "WS_POPUPWINDOW", TRUE },
{ WS_SIZEBOX, "WS_SIZEBOX", FALSE },
{ WS_SYSMENU, "WS_SYSMENU", FALSE },
{ WS_TABSTOP, "WS_TABSTOP", FALSE },
{ WS_THICKFRAME, "WS_THICKFRAME", FALSE },
{ WS_VISIBLE, "WS_VISIBLE", FALSE } };
static const WINDOW_STYLE EXTENDED_WINDOW_STYLES[] = {
2014-10-24 19:30:04 +04:00
{ WS_EX_ACCEPTFILES, "WS_EX_ACCEPTFILES", FALSE },
{ WS_EX_APPWINDOW, "WS_EX_APPWINDOW", FALSE },
{ WS_EX_CLIENTEDGE, "WS_EX_CLIENTEDGE", FALSE },
{ WS_EX_COMPOSITED, "WS_EX_COMPOSITED", FALSE },
{ WS_EX_CONTEXTHELP, "WS_EX_CONTEXTHELP", FALSE },
{ WS_EX_CONTROLPARENT, "WS_EX_CONTROLPARENT", FALSE },
{ WS_EX_DLGMODALFRAME, "WS_EX_DLGMODALFRAME", FALSE },
{ WS_EX_LAYERED, "WS_EX_LAYERED", FALSE },
{ WS_EX_LAYOUTRTL, "WS_EX_LAYOUTRTL", FALSE },
{ WS_EX_LEFT, "WS_EX_LEFT", FALSE },
{ WS_EX_LEFTSCROLLBAR, "WS_EX_LEFTSCROLLBAR", FALSE },
{ WS_EX_LTRREADING, "WS_EX_LTRREADING", FALSE },
{ WS_EX_MDICHILD, "WS_EX_MDICHILD", FALSE },
{ WS_EX_NOACTIVATE, "WS_EX_NOACTIVATE", FALSE },
{ WS_EX_NOINHERITLAYOUT, "WS_EX_NOINHERITLAYOUT", FALSE },
{ WS_EX_NOPARENTNOTIFY, "WS_EX_NOPARENTNOTIFY", FALSE },
{ WS_EX_OVERLAPPEDWINDOW, "WS_EX_OVERLAPPEDWINDOW", TRUE },
{ WS_EX_PALETTEWINDOW, "WS_EX_PALETTEWINDOW", TRUE },
{ WS_EX_RIGHT, "WS_EX_RIGHT", FALSE },
{ WS_EX_RIGHTSCROLLBAR, "WS_EX_RIGHTSCROLLBAR", FALSE },
{ WS_EX_RTLREADING, "WS_EX_RTLREADING", FALSE },
{ WS_EX_STATICEDGE, "WS_EX_STATICEDGE", FALSE },
{ WS_EX_TOOLWINDOW, "WS_EX_TOOLWINDOW", FALSE },
{ WS_EX_TOPMOST, "WS_EX_TOPMOST", FALSE },
{ WS_EX_TRANSPARENT, "WS_EX_TRANSPARENT", FALSE },
{ WS_EX_WINDOWEDGE, "WS_EX_WINDOWEDGE", FALSE }
};
static void PrintWindowStyles(UINT32 style)
2014-10-24 19:30:04 +04:00
{
int i;
WLog_INFO(TAG, "\tWindow Styles:\t{");
2016-08-03 13:09:24 +03:00
2014-10-24 19:30:04 +04:00
for (i = 0; i < ARRAYSIZE(WINDOW_STYLES); i++)
{
if (style & WINDOW_STYLES[i].style)
{
if (WINDOW_STYLES[i].multi)
{
if ((style & WINDOW_STYLES[i].style) != WINDOW_STYLES[i].style)
continue;
}
2016-08-03 13:09:24 +03:00
WLog_INFO(TAG, "\t\t%s", WINDOW_STYLES[i].name);
2014-10-24 19:30:04 +04:00
}
}
}
static void PrintExtendedWindowStyles(UINT32 style)
2014-10-24 19:30:04 +04:00
{
int i;
WLog_INFO(TAG, "\tExtended Window Styles:\t{");
2016-08-03 13:09:24 +03:00
2014-10-24 19:30:04 +04:00
for (i = 0; i < ARRAYSIZE(EXTENDED_WINDOW_STYLES); i++)
{
if (style & EXTENDED_WINDOW_STYLES[i].style)
{
if (EXTENDED_WINDOW_STYLES[i].multi)
{
2019-11-06 17:24:51 +03:00
if ((style & EXTENDED_WINDOW_STYLES[i].style) != EXTENDED_WINDOW_STYLES[i].style)
2014-10-24 19:30:04 +04:00
continue;
}
2016-08-03 13:09:24 +03:00
WLog_INFO(TAG, "\t\t%s", EXTENDED_WINDOW_STYLES[i].name);
2014-10-24 19:30:04 +04:00
}
}
}
static void PrintRailWindowState(const WINDOW_ORDER_INFO* orderInfo,
2019-11-06 17:24:51 +03:00
const WINDOW_STATE_ORDER* windowState)
2014-10-24 19:30:04 +04:00
{
if (orderInfo->fieldFlags & WINDOW_ORDER_STATE_NEW)
WLog_INFO(TAG, "WindowCreate: WindowId: 0x%08X", orderInfo->windowId);
2014-10-24 19:30:04 +04:00
else
WLog_INFO(TAG, "WindowUpdate: WindowId: 0x%08X", orderInfo->windowId);
2014-10-24 19:30:04 +04:00
WLog_INFO(TAG, "{");
2014-10-24 19:30:04 +04:00
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER)
{
WLog_INFO(TAG, "\tOwnerWindowId: 0x%08X", windowState->ownerWindowId);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE)
{
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tStyle: 0x%08X ExtendedStyle: 0x%08X", windowState->style,
windowState->extendedStyle);
2014-10-24 19:30:04 +04:00
PrintWindowStyles(windowState->style);
PrintExtendedWindowStyles(windowState->extendedStyle);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW)
{
WLog_INFO(TAG, "\tShowState: %u", windowState->showState);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE)
{
char* title = ConvertWCharNToUtf8Alloc(windowState->titleInfo.string,
windowState->titleInfo.length / sizeof(WCHAR), NULL);
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tTitleInfo: %s (length = %hu)", title, windowState->titleInfo.length);
2014-10-24 19:30:04 +04:00
free(title);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET)
{
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tClientOffsetX: %d ClientOffsetY: %d", windowState->clientOffsetX,
windowState->clientOffsetY);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE)
{
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tClientAreaWidth: %u ClientAreaHeight: %u", windowState->clientAreaWidth,
windowState->clientAreaHeight);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT)
{
WLog_INFO(TAG, "\tRPContent: %u", windowState->RPContent);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT)
{
WLog_INFO(TAG, "\tRootParentHandle: 0x%08X", windowState->rootParentHandle);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
{
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tWindowOffsetX: %d WindowOffsetY: %d", windowState->windowOffsetX,
windowState->windowOffsetY);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA)
{
WLog_INFO(TAG, "\tWindowClientDeltaX: %d WindowClientDeltaY: %d",
2016-10-04 10:00:00 +03:00
windowState->windowClientDeltaX, windowState->windowClientDeltaY);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)
{
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tWindowWidth: %u WindowHeight: %u", windowState->windowWidth,
windowState->windowHeight);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS)
{
UINT32 index;
RECTANGLE_16* rect;
WLog_INFO(TAG, "\tnumWindowRects: %u", windowState->numWindowRects);
2014-10-24 19:30:04 +04:00
for (index = 0; index < windowState->numWindowRects; index++)
{
rect = &windowState->windowRects[index];
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\twindowRect[%u]: left: %hu top: %hu right: %hu bottom: %hu", index,
rect->left, rect->top, rect->right, rect->bottom);
2014-10-24 19:30:04 +04:00
}
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET)
{
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tvisibileOffsetX: %d visibleOffsetY: %d", windowState->visibleOffsetX,
windowState->visibleOffsetY);
2014-10-24 19:30:04 +04:00
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY)
{
UINT32 index;
RECTANGLE_16* rect;
WLog_INFO(TAG, "\tnumVisibilityRects: %u", windowState->numVisibilityRects);
2014-10-24 19:30:04 +04:00
for (index = 0; index < windowState->numVisibilityRects; index++)
{
rect = &windowState->visibilityRects[index];
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tvisibilityRect[%u]: left: %hu top: %hu right: %hu bottom: %hu", index,
rect->left, rect->top, rect->right, rect->bottom);
2014-10-24 19:30:04 +04:00
}
}
WLog_INFO(TAG, "}");
2014-10-24 19:30:04 +04:00
}
static void PrintRailIconInfo(const WINDOW_ORDER_INFO* orderInfo, const ICON_INFO* iconInfo)
2014-10-24 19:30:04 +04:00
{
WLog_INFO(TAG, "ICON_INFO");
WLog_INFO(TAG, "{");
2016-08-03 13:09:24 +03:00
WLog_INFO(TAG, "\tbigIcon: %s",
2016-10-04 10:00:00 +03:00
(orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ICON_BIG) ? "true" : "false");
WLog_INFO(TAG, "\tcacheEntry; 0x%08X", iconInfo->cacheEntry);
WLog_INFO(TAG, "\tcacheId: 0x%08X", iconInfo->cacheId);
WLog_INFO(TAG, "\tbpp: %u", iconInfo->bpp);
WLog_INFO(TAG, "\twidth: %u", iconInfo->width);
WLog_INFO(TAG, "\theight: %u", iconInfo->height);
WLog_INFO(TAG, "\tcbColorTable: %u", iconInfo->cbColorTable);
WLog_INFO(TAG, "\tcbBitsMask: %u", iconInfo->cbBitsMask);
WLog_INFO(TAG, "\tcbBitsColor: %u", iconInfo->cbBitsColor);
2019-11-06 17:24:51 +03:00
WLog_INFO(TAG, "\tcolorTable: %p", (void*)iconInfo->colorTable);
WLog_INFO(TAG, "\tbitsMask: %p", (void*)iconInfo->bitsMask);
WLog_INFO(TAG, "\tbitsColor: %p", (void*)iconInfo->bitsColor);
WLog_INFO(TAG, "}");
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
LRESULT CALLBACK wf_RailWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2014-10-25 02:30:04 +04:00
{
HDC hDC;
int x, y;
int width;
int height;
UINT32 xPos;
UINT32 yPos;
2014-10-25 02:30:04 +04:00
PAINTSTRUCT ps;
UINT32 inputFlags;
2014-10-25 02:30:04 +04:00
wfContext* wfc = NULL;
rdpInput* input = NULL;
rdpContext* context = NULL;
2014-10-25 02:30:04 +04:00
wfRailWindow* railWindow;
2019-11-06 17:24:51 +03:00
railWindow = (wfRailWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
2014-10-25 02:30:04 +04:00
if (railWindow)
wfc = railWindow->wfc;
if (wfc)
2019-11-06 17:24:51 +03:00
context = (rdpContext*)wfc;
if (context)
input = context->input;
2014-10-25 02:30:04 +04:00
switch (msg)
{
2016-10-04 10:00:00 +03:00
case WM_PAINT:
2019-11-06 17:24:51 +03:00
{
if (!wfc)
return 0;
hDC = BeginPaint(hWnd, &ps);
x = ps.rcPaint.left;
y = ps.rcPaint.top;
width = ps.rcPaint.right - ps.rcPaint.left + 1;
height = ps.rcPaint.bottom - ps.rcPaint.top + 1;
BitBlt(hDC, x, y, width, height, wfc->primary->hdc, railWindow->x + x,
railWindow->y + y, SRCCOPY);
EndPaint(hWnd, &ps);
}
break;
2016-10-04 10:00:00 +03:00
case WM_LBUTTONDOWN:
2019-11-06 17:24:51 +03:00
{
if (!railWindow || !input)
return 0;
2019-11-06 17:24:51 +03:00
xPos = GET_X_LPARAM(lParam) + railWindow->x;
yPos = GET_Y_LPARAM(lParam) + railWindow->y;
inputFlags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1;
2019-11-06 17:24:51 +03:00
if (input)
input->MouseEvent(input, inputFlags, xPos, yPos);
}
break;
2016-10-04 10:00:00 +03:00
case WM_LBUTTONUP:
2019-11-06 17:24:51 +03:00
{
if (!railWindow || !input)
return 0;
2019-11-06 17:24:51 +03:00
xPos = GET_X_LPARAM(lParam) + railWindow->x;
yPos = GET_Y_LPARAM(lParam) + railWindow->y;
inputFlags = PTR_FLAGS_BUTTON1;
2019-11-06 17:24:51 +03:00
if (input)
input->MouseEvent(input, inputFlags, xPos, yPos);
}
break;
2016-10-04 10:00:00 +03:00
case WM_RBUTTONDOWN:
2019-11-06 17:24:51 +03:00
{
if (!railWindow || !input)
return 0;
2019-11-06 17:24:51 +03:00
xPos = GET_X_LPARAM(lParam) + railWindow->x;
yPos = GET_Y_LPARAM(lParam) + railWindow->y;
inputFlags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2;
2019-11-06 17:24:51 +03:00
if (input)
input->MouseEvent(input, inputFlags, xPos, yPos);
}
break;
2016-10-04 10:00:00 +03:00
case WM_RBUTTONUP:
2019-11-06 17:24:51 +03:00
{
if (!railWindow || !input)
return 0;
2019-11-06 17:24:51 +03:00
xPos = GET_X_LPARAM(lParam) + railWindow->x;
yPos = GET_Y_LPARAM(lParam) + railWindow->y;
inputFlags = PTR_FLAGS_BUTTON2;
2019-11-06 17:24:51 +03:00
if (input)
input->MouseEvent(input, inputFlags, xPos, yPos);
}
break;
2016-08-03 13:37:40 +03:00
2016-10-04 10:00:00 +03:00
case WM_MOUSEMOVE:
2019-11-06 17:24:51 +03:00
{
if (!railWindow || !input)
return 0;
2019-11-06 17:24:51 +03:00
xPos = GET_X_LPARAM(lParam) + railWindow->x;
yPos = GET_Y_LPARAM(lParam) + railWindow->y;
inputFlags = PTR_FLAGS_MOVE;
2019-11-06 17:24:51 +03:00
if (input)
input->MouseEvent(input, inputFlags, xPos, yPos);
}
break;
2016-10-04 10:00:00 +03:00
case WM_MOUSEWHEEL:
break;
2016-10-04 10:00:00 +03:00
case WM_CLOSE:
DestroyWindow(hWnd);
break;
2014-10-25 02:30:04 +04:00
2016-10-04 10:00:00 +03:00
case WM_DESTROY:
PostQuitMessage(0);
break;
2014-10-25 02:30:04 +04:00
2016-10-04 10:00:00 +03:00
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
2014-10-25 02:30:04 +04:00
}
return 0;
}
2019-11-06 17:24:51 +03:00
#define RAIL_DISABLED_WINDOW_STYLES \
(WS_BORDER | WS_THICKFRAME | WS_DLGFRAME | WS_CAPTION | WS_OVERLAPPED | WS_VSCROLL | \
WS_HSCROLL | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
#define RAIL_DISABLED_EXTENDED_WINDOW_STYLES \
(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_WINDOWEDGE)
2014-10-25 02:30:04 +04:00
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_window_common(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
const WINDOW_STATE_ORDER* windowState)
2014-10-24 19:30:04 +04:00
{
2014-10-25 02:30:04 +04:00
wfRailWindow* railWindow = NULL;
2019-11-06 17:24:51 +03:00
wfContext* wfc = (wfContext*)context;
2014-10-24 19:30:04 +04:00
RailClientContext* rail = wfc->rail;
2014-10-25 02:30:04 +04:00
UINT32 fieldFlags = orderInfo->fieldFlags;
2014-10-24 19:30:04 +04:00
PrintRailWindowState(orderInfo, windowState);
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_STATE_NEW)
2014-10-24 19:30:04 +04:00
{
2021-06-16 11:54:31 +03:00
BOOL rc;
2014-10-25 02:30:04 +04:00
HANDLE hInstance;
WCHAR* titleW = NULL;
WNDCLASSEX wndClassEx = { 0 };
2019-11-06 17:24:51 +03:00
railWindow = (wfRailWindow*)calloc(1, sizeof(wfRailWindow));
2014-10-25 02:30:04 +04:00
if (!railWindow)
return FALSE;
2014-10-25 02:30:04 +04:00
railWindow->wfc = wfc;
railWindow->dwStyle = windowState->style;
railWindow->dwStyle &= ~RAIL_DISABLED_WINDOW_STYLES;
railWindow->dwExStyle = windowState->extendedStyle;
railWindow->dwExStyle &= ~RAIL_DISABLED_EXTENDED_WINDOW_STYLES;
railWindow->x = windowState->windowOffsetX;
railWindow->y = windowState->windowOffsetY;
railWindow->width = windowState->windowWidth;
railWindow->height = windowState->windowHeight;
if (fieldFlags & WINDOW_ORDER_FIELD_TITLE)
{
char* title = NULL;
2014-10-24 19:30:04 +04:00
if (windowState->titleInfo.length == 0)
{
if (!(title = _strdup("")))
{
WLog_ERR(TAG, "failed to duplicate empty window title string");
/* error handled below */
}
}
else if (!(title = ConvertWCharNToUtf8Alloc(
windowState->titleInfo.string,
windowState->titleInfo.length / sizeof(WCHAR), NULL)))
{
WLog_ERR(TAG, "failed to convert window title");
/* error handled below */
}
2014-10-25 02:30:04 +04:00
railWindow->title = title;
}
else
{
if (!(railWindow->title = _strdup("RdpRailWindow")))
WLog_ERR(TAG, "failed to duplicate default window title string");
}
if (!railWindow->title)
{
free(railWindow);
return FALSE;
2014-10-25 02:30:04 +04:00
}
titleW = ConvertUtf8ToWCharAlloc(railWindow->title, NULL);
2014-10-25 02:30:04 +04:00
hInstance = GetModuleHandle(NULL);
2014-10-25 02:30:04 +04:00
wndClassEx.cbSize = sizeof(WNDCLASSEX);
wndClassEx.style = 0;
wndClassEx.lpfnWndProc = wf_RailWndProc;
wndClassEx.cbClsExtra = 0;
wndClassEx.cbWndExtra = 0;
wndClassEx.hIcon = NULL;
wndClassEx.hCursor = NULL;
wndClassEx.hbrBackground = NULL;
wndClassEx.lpszMenuName = NULL;
wndClassEx.lpszClassName = _T("RdpRailWindow");
wndClassEx.hInstance = hInstance;
wndClassEx.hIconSm = NULL;
RegisterClassEx(&wndClassEx);
2019-11-06 17:24:51 +03:00
railWindow->hWnd = CreateWindowExW(railWindow->dwExStyle, /* dwExStyle */
_T("RdpRailWindow"), /* lpClassName */
titleW, /* lpWindowName */
railWindow->dwStyle, /* dwStyle */
railWindow->x, /* x */
railWindow->y, /* y */
railWindow->width, /* nWidth */
railWindow->height, /* nHeight */
NULL, /* hWndParent */
NULL, /* hMenu */
hInstance, /* hInstance */
NULL /* lpParam */
);
if (!railWindow->hWnd)
{
free(titleW);
free(railWindow->title);
free(railWindow);
WLog_ERR(TAG, "CreateWindowExW failed with error %" PRIu32 "", GetLastError());
return FALSE;
}
2019-11-06 17:24:51 +03:00
SetWindowLongPtr(railWindow->hWnd, GWLP_USERDATA, (LONG_PTR)railWindow);
2021-06-16 11:54:31 +03:00
rc = HashTable_Insert(wfc->railWindows, (void*)(UINT_PTR)orderInfo->windowId,
(void*)railWindow);
2014-10-25 02:30:04 +04:00
free(titleW);
UpdateWindow(railWindow->hWnd);
2021-06-16 11:54:31 +03:00
return rc;
2014-10-24 19:30:04 +04:00
}
else
{
2019-11-06 17:24:51 +03:00
railWindow = (wfRailWindow*)HashTable_GetItemValue(wfc->railWindows,
(void*)(UINT_PTR)orderInfo->windowId);
2014-10-24 19:30:04 +04:00
}
2014-10-25 02:30:04 +04:00
if (!railWindow)
return TRUE;
2014-10-24 19:30:04 +04:00
2019-11-06 17:24:51 +03:00
if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) || (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE))
2014-10-24 19:30:04 +04:00
{
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
{
railWindow->x = windowState->windowOffsetX;
railWindow->y = windowState->windowOffsetY;
}
if (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)
{
railWindow->width = windowState->windowWidth;
railWindow->height = windowState->windowHeight;
}
2019-11-06 17:24:51 +03:00
SetWindowPos(railWindow->hWnd, NULL, railWindow->x, railWindow->y, railWindow->width,
railWindow->height, 0);
2014-10-24 19:30:04 +04:00
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_OWNER)
2014-10-24 19:30:04 +04:00
{
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_STYLE)
2014-10-24 19:30:04 +04:00
{
2014-10-25 02:30:04 +04:00
railWindow->dwStyle = windowState->style;
railWindow->dwStyle &= ~RAIL_DISABLED_WINDOW_STYLES;
railWindow->dwExStyle = windowState->extendedStyle;
railWindow->dwExStyle &= ~RAIL_DISABLED_EXTENDED_WINDOW_STYLES;
2019-11-06 17:24:51 +03:00
SetWindowLongPtr(railWindow->hWnd, GWL_STYLE, (LONG)railWindow->dwStyle);
SetWindowLongPtr(railWindow->hWnd, GWL_EXSTYLE, (LONG)railWindow->dwExStyle);
2014-10-24 19:30:04 +04:00
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_SHOW)
2014-10-24 19:30:04 +04:00
{
2014-10-25 02:30:04 +04:00
ShowWindow(railWindow->hWnd, windowState->showState);
2014-10-24 19:30:04 +04:00
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_TITLE)
2014-10-24 19:30:04 +04:00
{
char* title = NULL;
if (windowState->titleInfo.length == 0)
{
if (!(title = _strdup("")))
{
WLog_ERR(TAG, "failed to duplicate empty window title string");
return FALSE;
}
}
else if (!(title = ConvertWCharNToUtf8Alloc(windowState->titleInfo.string,
windowState->titleInfo.length / sizeof(WCHAR),
NULL)))
{
WLog_ERR(TAG, "failed to convert window title");
return FALSE;
}
2014-10-24 19:30:04 +04:00
2014-10-25 02:30:04 +04:00
free(railWindow->title);
railWindow->title = title;
SetWindowTextW(railWindow->hWnd, windowState->titleInfo.string);
2014-10-24 19:30:04 +04:00
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET)
2014-10-24 19:30:04 +04:00
{
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE)
2014-10-24 19:30:04 +04:00
{
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA)
2014-10-24 19:30:04 +04:00
{
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT)
2014-10-24 19:30:04 +04:00
{
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT)
2014-10-24 19:30:04 +04:00
{
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS)
2014-10-24 19:30:04 +04:00
{
2014-10-25 02:30:04 +04:00
UINT32 index;
HRGN hWndRect;
HRGN hWndRects;
RECTANGLE_16* rect;
2014-10-24 19:30:04 +04:00
2014-10-25 02:30:04 +04:00
if (windowState->numWindowRects > 0)
{
rect = &(windowState->windowRects[0]);
hWndRects = CreateRectRgn(rect->left, rect->top, rect->right, rect->bottom);
for (index = 1; index < windowState->numWindowRects; index++)
{
rect = &(windowState->windowRects[index]);
hWndRect = CreateRectRgn(rect->left, rect->top, rect->right, rect->bottom);
CombineRgn(hWndRects, hWndRects, hWndRect, RGN_OR);
DeleteObject(hWndRect);
}
SetWindowRgn(railWindow->hWnd, hWndRects, TRUE);
DeleteObject(hWndRects);
}
2014-10-24 19:30:04 +04:00
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET)
2014-10-24 19:30:04 +04:00
{
}
2014-10-25 02:30:04 +04:00
if (fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY)
2014-10-24 19:30:04 +04:00
{
}
2014-10-25 02:30:04 +04:00
UpdateWindow(railWindow->hWnd);
return TRUE;
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_window_delete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
2014-10-24 19:30:04 +04:00
{
2014-10-25 02:30:04 +04:00
wfRailWindow* railWindow = NULL;
2019-11-06 17:24:51 +03:00
wfContext* wfc = (wfContext*)context;
2014-10-24 19:30:04 +04:00
RailClientContext* rail = wfc->rail;
WLog_DBG(TAG, "RailWindowDelete");
2019-11-06 17:24:51 +03:00
railWindow = (wfRailWindow*)HashTable_GetItemValue(wfc->railWindows,
(void*)(UINT_PTR)orderInfo->windowId);
2014-10-25 02:30:04 +04:00
if (!railWindow)
return TRUE;
2014-10-25 02:30:04 +04:00
2019-11-06 17:24:51 +03:00
HashTable_Remove(wfc->railWindows, (void*)(UINT_PTR)orderInfo->windowId);
2014-10-25 02:30:04 +04:00
DestroyWindow(railWindow->hWnd);
free(railWindow);
return TRUE;
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_window_icon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
const WINDOW_ICON_ORDER* windowIcon)
2014-10-24 19:30:04 +04:00
{
2014-10-25 02:30:04 +04:00
HDC hDC;
int bpp;
int width;
int height;
HICON hIcon;
2014-10-24 19:30:04 +04:00
BOOL bigIcon;
ICONINFO iconInfo = { 0 };
BITMAPINFO bitmapInfo = { 0 };
2014-10-25 02:30:04 +04:00
wfRailWindow* railWindow;
BITMAPINFOHEADER* bitmapInfoHeader;
2019-11-06 17:24:51 +03:00
wfContext* wfc = (wfContext*)context;
2014-10-24 19:30:04 +04:00
RailClientContext* rail = wfc->rail;
WLog_DBG(TAG, "RailWindowIcon");
2014-10-24 19:30:04 +04:00
PrintRailIconInfo(orderInfo, windowIcon->iconInfo);
2019-11-06 17:24:51 +03:00
railWindow = (wfRailWindow*)HashTable_GetItemValue(wfc->railWindows,
(void*)(UINT_PTR)orderInfo->windowId);
2014-10-25 02:30:04 +04:00
if (!railWindow)
return TRUE;
2014-10-24 19:30:04 +04:00
bigIcon = (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ICON_BIG) ? TRUE : FALSE;
2014-10-25 02:30:04 +04:00
hDC = GetDC(railWindow->hWnd);
iconInfo.fIcon = TRUE;
iconInfo.xHotspot = 0;
iconInfo.yHotspot = 0;
2014-10-25 02:30:04 +04:00
bitmapInfoHeader = &(bitmapInfo.bmiHeader);
bpp = windowIcon->iconInfo->bpp;
width = windowIcon->iconInfo->width;
height = windowIcon->iconInfo->height;
bitmapInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
bitmapInfoHeader->biWidth = width;
bitmapInfoHeader->biHeight = height;
bitmapInfoHeader->biPlanes = 1;
bitmapInfoHeader->biBitCount = bpp;
bitmapInfoHeader->biCompression = 0;
bitmapInfoHeader->biSizeImage = height * width * ((bpp + 7) / 8);
bitmapInfoHeader->biXPelsPerMeter = width;
bitmapInfoHeader->biYPelsPerMeter = height;
bitmapInfoHeader->biClrUsed = 0;
bitmapInfoHeader->biClrImportant = 0;
2019-11-06 17:24:51 +03:00
iconInfo.hbmMask = CreateDIBitmap(hDC, bitmapInfoHeader, CBM_INIT,
windowIcon->iconInfo->bitsMask, &bitmapInfo, DIB_RGB_COLORS);
iconInfo.hbmColor =
CreateDIBitmap(hDC, bitmapInfoHeader, CBM_INIT, windowIcon->iconInfo->bitsColor,
&bitmapInfo, DIB_RGB_COLORS);
2014-10-25 02:30:04 +04:00
hIcon = CreateIconIndirect(&iconInfo);
if (hIcon)
{
WPARAM wParam;
LPARAM lParam;
2019-11-06 17:24:51 +03:00
wParam = (WPARAM)bigIcon ? ICON_BIG : ICON_SMALL;
lParam = (LPARAM)hIcon;
2014-10-25 02:30:04 +04:00
SendMessage(railWindow->hWnd, WM_SETICON, wParam, lParam);
}
ReleaseDC(NULL, hDC);
if (windowIcon->iconInfo->cacheEntry != 0xFFFF)
2014-10-24 19:30:04 +04:00
{
/* icon should be cached */
}
2016-08-03 13:09:24 +03:00
return TRUE;
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_window_cached_icon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
const WINDOW_CACHED_ICON_ORDER* windowCachedIcon)
2014-10-24 19:30:04 +04:00
{
WLog_DBG(TAG, "RailWindowCachedIcon");
return TRUE;
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
static void wf_rail_notify_icon_common(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
const NOTIFY_ICON_STATE_ORDER* notifyIconState)
2014-10-24 19:30:04 +04:00
{
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_VERSION)
{
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_TIP)
{
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP)
{
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_STATE)
{
}
if (orderInfo->fieldFlags & WINDOW_ORDER_ICON)
{
const ICON_INFO* iconInfo = &(notifyIconState->icon);
2014-10-24 19:30:04 +04:00
PrintRailIconInfo(orderInfo, iconInfo);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_CACHED_ICON)
{
}
}
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_notify_icon_create(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
const NOTIFY_ICON_STATE_ORDER* notifyIconState)
2014-10-24 19:30:04 +04:00
{
2019-11-06 17:24:51 +03:00
wfContext* wfc = (wfContext*)context;
2014-10-24 19:30:04 +04:00
RailClientContext* rail = wfc->rail;
WLog_DBG(TAG, "RailNotifyIconCreate");
2014-10-24 19:30:04 +04:00
wf_rail_notify_icon_common(context, orderInfo, notifyIconState);
return TRUE;
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_notify_icon_update(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
const NOTIFY_ICON_STATE_ORDER* notifyIconState)
2014-10-24 19:30:04 +04:00
{
2019-11-06 17:24:51 +03:00
wfContext* wfc = (wfContext*)context;
2014-10-24 19:30:04 +04:00
RailClientContext* rail = wfc->rail;
WLog_DBG(TAG, "RailNotifyIconUpdate");
2014-10-24 19:30:04 +04:00
wf_rail_notify_icon_common(context, orderInfo, notifyIconState);
return TRUE;
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_notify_icon_delete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
2014-10-24 19:30:04 +04:00
{
2019-11-06 17:24:51 +03:00
wfContext* wfc = (wfContext*)context;
2014-10-24 19:30:04 +04:00
RailClientContext* rail = wfc->rail;
WLog_DBG(TAG, "RailNotifyIconDelete");
return TRUE;
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_monitored_desktop(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
const MONITORED_DESKTOP_ORDER* monitoredDesktop)
2014-10-24 19:30:04 +04:00
{
2019-11-06 17:24:51 +03:00
wfContext* wfc = (wfContext*)context;
2014-10-24 19:30:04 +04:00
RailClientContext* rail = wfc->rail;
WLog_DBG(TAG, "RailMonitorDesktop");
return TRUE;
2014-10-24 19:30:04 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL wf_rail_non_monitored_desktop(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
2014-10-24 19:30:04 +04:00
{
2019-11-06 17:24:51 +03:00
wfContext* wfc = (wfContext*)context;
2014-10-24 19:30:04 +04:00
RailClientContext* rail = wfc->rail;
WLog_DBG(TAG, "RailNonMonitorDesktop");
return TRUE;
2014-10-24 19:30:04 +04:00
}
void wf_rail_register_update_callbacks(rdpUpdate* update)
{
rdpWindowUpdate* window = update->window;
window->WindowCreate = wf_rail_window_common;
window->WindowUpdate = wf_rail_window_common;
window->WindowDelete = wf_rail_window_delete;
window->WindowIcon = wf_rail_window_icon;
window->WindowCachedIcon = wf_rail_window_cached_icon;
window->NotifyIconCreate = wf_rail_notify_icon_create;
window->NotifyIconUpdate = wf_rail_notify_icon_update;
window->NotifyIconDelete = wf_rail_notify_icon_delete;
window->MonitoredDesktop = wf_rail_monitored_desktop;
window->NonMonitoredDesktop = wf_rail_non_monitored_desktop;
}
/* RemoteApp Virtual Channel Extension */
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
2016-08-03 13:09:24 +03:00
static UINT wf_rail_server_execute_result(RailClientContext* context,
2019-11-06 17:24:51 +03:00
const RAIL_EXEC_RESULT_ORDER* execResult)
2014-10-24 19:30:04 +04:00
{
WLog_DBG(TAG, "RailServerExecuteResult: 0x%08X", execResult->rawResult);
2015-06-08 19:04:05 +03:00
return CHANNEL_RC_OK;
2014-10-24 19:30:04 +04:00
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
2016-08-03 13:09:24 +03:00
static UINT wf_rail_server_system_param(RailClientContext* context,
const RAIL_SYSPARAM_ORDER* sysparam)
2014-10-24 19:30:04 +04:00
{
2015-06-08 19:04:05 +03:00
return CHANNEL_RC_OK;
2014-10-24 19:30:04 +04:00
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT wf_rail_server_handshake(RailClientContext* context,
const RAIL_HANDSHAKE_ORDER* handshake)
{
return client_rail_server_start_cmd(context);
2014-10-24 19:30:04 +04:00
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
2016-08-03 13:09:24 +03:00
static UINT wf_rail_server_handshake_ex(RailClientContext* context,
const RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
2014-10-24 19:30:04 +04:00
{
return client_rail_server_start_cmd(context);
2014-10-24 19:30:04 +04:00
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
2016-08-03 13:09:24 +03:00
static UINT wf_rail_server_local_move_size(RailClientContext* context,
2019-11-06 17:24:51 +03:00
const RAIL_LOCALMOVESIZE_ORDER* localMoveSize)
2014-10-24 19:30:04 +04:00
{
2015-06-08 19:04:05 +03:00
return CHANNEL_RC_OK;
2014-10-24 19:30:04 +04:00
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
2016-08-03 13:09:24 +03:00
static UINT wf_rail_server_min_max_info(RailClientContext* context,
const RAIL_MINMAXINFO_ORDER* minMaxInfo)
2014-10-24 19:30:04 +04:00
{
2015-06-08 19:04:05 +03:00
return CHANNEL_RC_OK;
2014-10-24 19:30:04 +04:00
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
2016-08-03 13:09:24 +03:00
static UINT wf_rail_server_language_bar_info(RailClientContext* context,
2019-11-06 17:24:51 +03:00
const RAIL_LANGBAR_INFO_ORDER* langBarInfo)
2014-10-24 19:30:04 +04:00
{
2015-06-08 19:04:05 +03:00
return CHANNEL_RC_OK;
2014-10-24 19:30:04 +04:00
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
2016-08-03 13:09:24 +03:00
static UINT wf_rail_server_get_appid_response(RailClientContext* context,
2019-11-06 17:24:51 +03:00
const RAIL_GET_APPID_RESP_ORDER* getAppIdResp)
2014-10-24 19:30:04 +04:00
{
2015-06-08 19:04:05 +03:00
return CHANNEL_RC_OK;
2014-10-24 19:30:04 +04:00
}
void wf_rail_invalidate_region(wfContext* wfc, REGION16* invalidRegion)
{
int index;
int count;
RECT updateRect;
RECTANGLE_16 windowRect;
ULONG_PTR* pKeys = NULL;
wfRailWindow* railWindow;
const RECTANGLE_16* extents;
REGION16 windowInvalidRegion;
region16_init(&windowInvalidRegion);
count = HashTable_GetKeys(wfc->railWindows, &pKeys);
for (index = 0; index < count; index++)
{
2019-11-06 17:24:51 +03:00
railWindow = (wfRailWindow*)HashTable_GetItemValue(wfc->railWindows, (void*)pKeys[index]);
if (railWindow)
{
windowRect.left = railWindow->x;
windowRect.top = railWindow->y;
windowRect.right = railWindow->x + railWindow->width;
windowRect.bottom = railWindow->y + railWindow->height;
region16_clear(&windowInvalidRegion);
region16_intersect_rect(&windowInvalidRegion, invalidRegion, &windowRect);
if (!region16_is_empty(&windowInvalidRegion))
{
extents = region16_extents(&windowInvalidRegion);
updateRect.left = extents->left - railWindow->x;
updateRect.top = extents->top - railWindow->y;
updateRect.right = extents->right - railWindow->x;
updateRect.bottom = extents->bottom - railWindow->y;
InvalidateRect(railWindow->hWnd, &updateRect, FALSE);
}
}
}
region16_uninit(&windowInvalidRegion);
}
BOOL wf_rail_init(wfContext* wfc, RailClientContext* rail)
2014-10-24 19:30:04 +04:00
{
2019-11-06 17:24:51 +03:00
rdpContext* context = (rdpContext*)wfc;
2014-10-24 19:30:04 +04:00
wfc->rail = rail;
2019-11-06 17:24:51 +03:00
rail->custom = (void*)wfc;
2014-10-24 19:30:04 +04:00
rail->ServerExecuteResult = wf_rail_server_execute_result;
rail->ServerSystemParam = wf_rail_server_system_param;
rail->ServerHandshake = wf_rail_server_handshake;
rail->ServerHandshakeEx = wf_rail_server_handshake_ex;
rail->ServerLocalMoveSize = wf_rail_server_local_move_size;
rail->ServerMinMaxInfo = wf_rail_server_min_max_info;
rail->ServerLanguageBarInfo = wf_rail_server_language_bar_info;
rail->ServerGetAppIdResponse = wf_rail_server_get_appid_response;
2014-10-25 02:30:04 +04:00
wf_rail_register_update_callbacks(context->update);
wfc->railWindows = HashTable_New(TRUE);
return (wfc->railWindows != NULL);
2014-10-24 19:30:04 +04:00
}
void wf_rail_uninit(wfContext* wfc, RailClientContext* rail)
{
wfc->rail = NULL;
rail->custom = NULL;
2014-10-25 02:30:04 +04:00
HashTable_Free(wfc->railWindows);
2014-10-24 19:30:04 +04:00
}