2011-09-26 00:30:20 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-09-26 00:30:20 +04:00
|
|
|
* Event Handling
|
|
|
|
*
|
|
|
|
* Copyright 2009-2011 Jay Sorg
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
|
|
|
* Copyright 2010-2011 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-09-26 00:30:20 +04:00
|
|
|
#include <stdio.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
2011-09-26 00:30:20 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
2013-03-19 06:09:52 +04:00
|
|
|
#include "wf_interface.h"
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2012-12-25 08:10:24 +04:00
|
|
|
#include "wf_gdi.h"
|
2011-09-26 00:30:20 +04:00
|
|
|
#include "wf_event.h"
|
2014-01-18 03:17:10 +04:00
|
|
|
#include "freerdp/event.h"
|
2011-09-26 00:30:20 +04:00
|
|
|
|
|
|
|
static HWND g_focus_hWnd;
|
|
|
|
|
2014-02-10 09:34:17 +04:00
|
|
|
#define X_POS(lParam) ((UINT16) (lParam & 0xFFFF))
|
|
|
|
#define Y_POS(lParam) ((UINT16) ((lParam >> 16) & 0xFFFF))
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2013-06-16 08:51:48 +04:00
|
|
|
BOOL wf_scale_blt(wfContext* wfc, HDC hdc, int x, int y, int w, int h, HDC hdcSrc, int x1, int y1, DWORD rop);
|
|
|
|
void wf_scale_mouse_event(wfContext* wfc, rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
|
2013-04-11 00:58:14 +04:00
|
|
|
|
2011-09-26 00:30:20 +04:00
|
|
|
LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
2013-03-06 21:50:25 +04:00
|
|
|
DWORD rdp_scancode;
|
2011-09-26 00:30:20 +04:00
|
|
|
rdpInput* input;
|
|
|
|
PKBDLLHOOKSTRUCT p;
|
|
|
|
|
2012-02-22 02:22:01 +04:00
|
|
|
DEBUG_KBD("Low-level keyboard hook, hWnd %X nCode %X wParam %X", g_focus_hWnd, nCode, wParam);
|
2011-09-26 00:30:20 +04:00
|
|
|
|
|
|
|
if (g_focus_hWnd && (nCode == HC_ACTION))
|
|
|
|
{
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc = (wfContext*) GetWindowLongPtr(g_focus_hWnd, GWLP_USERDATA);
|
2011-09-26 00:30:20 +04:00
|
|
|
p = (PKBDLLHOOKSTRUCT) lParam;
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc || !p)
|
2012-10-02 11:04:58 +04:00
|
|
|
return 1;
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
input = wfc->instance->input;
|
2012-10-09 11:01:37 +04:00
|
|
|
rdp_scancode = MAKE_RDP_SCANCODE((BYTE) p->scanCode, p->flags & LLKHF_EXTENDED);
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2012-02-22 02:22:01 +04:00
|
|
|
DEBUG_KBD("keydown %d scanCode %04X flags %02X vkCode %02X",
|
2012-10-09 11:01:37 +04:00
|
|
|
(wParam == WM_KEYDOWN), (BYTE) p->scanCode, p->flags, p->vkCode);
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->fs_toggle &&
|
2011-09-26 00:30:20 +04:00
|
|
|
((p->vkCode == VK_RETURN) || (p->vkCode == VK_CANCEL)) &&
|
|
|
|
(GetAsyncKeyState(VK_CONTROL) & 0x8000) &&
|
|
|
|
(GetAsyncKeyState(VK_MENU) & 0x8000)) /* could also use flags & LLKHF_ALTDOWN */
|
|
|
|
{
|
|
|
|
if (wParam == WM_KEYDOWN)
|
2012-12-25 08:10:24 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_toggle_fullscreen(wfc);
|
2012-12-25 08:10:24 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2011-09-26 00:30:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-29 03:12:48 +04:00
|
|
|
if (rdp_scancode == RDP_SCANCODE_NUMLOCK_EXTENDED)
|
2011-09-26 00:30:20 +04:00
|
|
|
{
|
2012-03-29 03:12:48 +04:00
|
|
|
/* Windows sends NumLock as extended - rdp doesn't */
|
|
|
|
DEBUG_KBD("hack: NumLock (x45) should not be extended");
|
|
|
|
rdp_scancode = RDP_SCANCODE_NUMLOCK;
|
|
|
|
}
|
|
|
|
else if (rdp_scancode == RDP_SCANCODE_NUMLOCK)
|
|
|
|
{
|
|
|
|
/* Windows sends Pause as if it was a RDP NumLock (handled above).
|
|
|
|
* It must however be sent as a one-shot Ctrl+NumLock */
|
|
|
|
if (wParam == WM_KEYDOWN)
|
2011-09-26 00:30:20 +04:00
|
|
|
{
|
2012-03-29 03:12:48 +04:00
|
|
|
DEBUG_KBD("Pause, sent as Ctrl+NumLock");
|
2012-10-09 10:31:28 +04:00
|
|
|
freerdp_input_send_keyboard_event_ex(input, TRUE, RDP_SCANCODE_LCONTROL);
|
|
|
|
freerdp_input_send_keyboard_event_ex(input, TRUE, RDP_SCANCODE_NUMLOCK);
|
|
|
|
freerdp_input_send_keyboard_event_ex(input, FALSE, RDP_SCANCODE_LCONTROL);
|
|
|
|
freerdp_input_send_keyboard_event_ex(input, FALSE, RDP_SCANCODE_NUMLOCK);
|
2011-09-26 00:30:20 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-29 03:12:48 +04:00
|
|
|
DEBUG_KBD("Pause up");
|
2011-09-26 00:30:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-29 03:12:48 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (rdp_scancode == RDP_SCANCODE_RSHIFT_EXTENDED)
|
2011-09-26 00:30:20 +04:00
|
|
|
{
|
2012-03-29 03:12:48 +04:00
|
|
|
DEBUG_KBD("right shift (x36) should not be extended");
|
|
|
|
rdp_scancode = RDP_SCANCODE_RSHIFT;
|
2011-09-26 00:30:20 +04:00
|
|
|
}
|
|
|
|
|
2012-09-22 22:27:30 +04:00
|
|
|
freerdp_input_send_keyboard_event_ex(input, !(p->flags & LLKHF_UP), rdp_scancode);
|
2011-09-26 00:30:20 +04:00
|
|
|
|
|
|
|
if (p->vkCode == VK_CAPITAL)
|
2012-02-22 02:22:01 +04:00
|
|
|
DEBUG_KBD("caps lock is processed on client side too to toggle caps lock indicator");
|
2011-09-26 00:30:20 +04:00
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
static int wf_event_process_WM_MOUSEWHEEL(wfContext* wfc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
2012-10-16 20:57:12 +04:00
|
|
|
{
|
|
|
|
int delta;
|
|
|
|
int flags;
|
|
|
|
rdpInput* input;
|
|
|
|
|
|
|
|
DefWindowProc(hWnd, Msg, wParam, lParam);
|
2013-06-16 06:57:21 +04:00
|
|
|
input = wfc->instance->input;
|
2012-10-17 15:48:24 +04:00
|
|
|
delta = ((signed short) HIWORD(wParam)); /* GET_WHEEL_DELTA_WPARAM(wParam); */
|
|
|
|
|
2012-10-16 20:57:12 +04:00
|
|
|
if (delta > 0)
|
|
|
|
{
|
|
|
|
flags = PTR_FLAGS_WHEEL | 0x0078;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flags = PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0088;
|
|
|
|
}
|
2012-10-17 15:48:24 +04:00
|
|
|
|
2012-10-16 20:57:12 +04:00
|
|
|
input->MouseEvent(input, flags, 0, 0);
|
2012-10-17 15:48:24 +04:00
|
|
|
|
2012-10-16 20:57:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
void wf_sizing(wfContext* wfc, WPARAM wParam, LPARAM lParam)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
|
|
|
// Holding the CTRL key down while resizing the window will force the desktop aspect ratio.
|
|
|
|
LPRECT rect;
|
2013-06-16 06:57:21 +04:00
|
|
|
|
|
|
|
if (wfc->instance->settings->SmartSizing && (GetAsyncKeyState(VK_CONTROL) & 0x8000))
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
|
|
|
rect = (LPRECT) wParam;
|
|
|
|
|
|
|
|
switch(lParam)
|
|
|
|
{
|
|
|
|
case WMSZ_LEFT:
|
|
|
|
case WMSZ_RIGHT:
|
|
|
|
case WMSZ_BOTTOMRIGHT:
|
|
|
|
// Adjust height
|
2013-06-16 06:57:21 +04:00
|
|
|
rect->bottom = rect->top + wfc->height * (rect->right - rect->left) / wfc->instance->settings->DesktopWidth;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WMSZ_TOP:
|
|
|
|
case WMSZ_BOTTOM:
|
|
|
|
case WMSZ_TOPRIGHT:
|
|
|
|
// Adjust width
|
2013-06-16 06:57:21 +04:00
|
|
|
rect->right = rect->left + wfc->width * (rect->bottom - rect->top) / wfc->instance->settings->DesktopHeight;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WMSZ_BOTTOMLEFT:
|
|
|
|
case WMSZ_TOPLEFT:
|
|
|
|
// adjust width
|
2013-06-16 06:57:21 +04:00
|
|
|
rect->left = rect->right - (wfc->width * (rect->bottom - rect->top) / wfc->instance->settings->DesktopHeight);
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-09-26 00:30:20 +04:00
|
|
|
LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
2014-02-10 09:34:17 +04:00
|
|
|
LONG_PTR ptr;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
2011-10-07 22:55:07 +04:00
|
|
|
int x, y, w, h;
|
2011-09-26 00:30:20 +04:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
rdpInput* input;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL processed;
|
2013-06-16 06:57:21 +04:00
|
|
|
RECT windowRect;
|
|
|
|
MINMAXINFO* minmax;
|
2013-04-26 23:46:36 +04:00
|
|
|
SCROLLINFO si;
|
2013-04-26 01:18:14 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
processed = TRUE;
|
2011-09-26 00:30:20 +04:00
|
|
|
ptr = GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc = (wfContext*) ptr;
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc != NULL)
|
2011-09-26 00:30:20 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
input = wfc->instance->input;
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2011-09-26 01:47:40 +04:00
|
|
|
switch (Msg)
|
|
|
|
{
|
2013-04-25 23:42:40 +04:00
|
|
|
case WM_MOVE:
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc->disablewindowtracking)
|
2013-04-25 23:42:40 +04:00
|
|
|
{
|
2013-04-26 23:46:36 +04:00
|
|
|
int x = (int)(short) LOWORD(lParam);
|
|
|
|
int y = (int)(short) HIWORD(lParam);
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->client_x = x;
|
|
|
|
wfc->client_y = y;
|
2013-04-25 23:42:40 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-04-26 01:18:14 +04:00
|
|
|
case WM_GETMINMAXINFO:
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->instance->settings->SmartSizing)
|
2013-04-26 01:18:14 +04:00
|
|
|
{
|
2013-04-26 23:46:36 +04:00
|
|
|
processed = FALSE;
|
2013-04-26 01:18:14 +04:00
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
else
|
2013-04-25 23:42:40 +04:00
|
|
|
{
|
2013-04-26 23:46:36 +04:00
|
|
|
// Set maximum window size for resizing
|
2013-04-25 23:42:40 +04:00
|
|
|
|
2013-04-26 23:46:36 +04:00
|
|
|
minmax = (MINMAXINFO*) lParam;
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_update_canvas_diff(wfc);
|
|
|
|
|
|
|
|
if (!wfc->fullscreen)
|
2013-04-25 23:42:40 +04:00
|
|
|
{
|
2013-04-26 23:46:36 +04:00
|
|
|
// add window decoration
|
2013-06-16 06:57:21 +04:00
|
|
|
minmax->ptMaxTrackSize.x = wfc->width + wfc->diff.x;
|
|
|
|
minmax->ptMaxTrackSize.y = wfc->height + wfc->diff.y;
|
2013-04-25 23:42:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-04-26 23:46:36 +04:00
|
|
|
case WM_SIZING:
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_sizing(wfc, lParam, wParam);
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SIZE:
|
2013-06-16 06:57:21 +04:00
|
|
|
GetWindowRect(wfc->hwnd, &windowRect);
|
2013-04-30 19:15:04 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc->fullscreen)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->client_width = LOWORD(lParam);
|
|
|
|
wfc->client_height = HIWORD(lParam);
|
|
|
|
wfc->client_x = windowRect.left;
|
|
|
|
wfc->client_y = windowRect.top;
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_size_scrollbars(wfc, LOWORD(lParam), HIWORD(lParam));
|
2013-04-30 19:15:04 +04:00
|
|
|
|
|
|
|
// Workaround: when the window is maximized, the call to "ShowScrollBars" returns TRUE but has no effect.
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wParam == SIZE_MAXIMIZED && !wfc->fullscreen)
|
|
|
|
SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, SWP_NOMOVE | SWP_FRAMECHANGED);
|
2013-04-30 19:15:04 +04:00
|
|
|
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_EXITSIZEMOVE:
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_size_scrollbars(wfc, wfc->client_width, wfc->client_height);
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
2013-04-11 00:58:14 +04:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
/* Say we handled it - prevents flickering */
|
|
|
|
return (LRESULT) 1;
|
|
|
|
|
2011-09-26 01:47:40 +04:00
|
|
|
case WM_PAINT:
|
2011-09-26 00:30:20 +04:00
|
|
|
hdc = BeginPaint(hWnd, &ps);
|
2012-10-16 22:20:04 +04:00
|
|
|
|
2011-10-07 22:55:07 +04:00
|
|
|
x = ps.rcPaint.left;
|
|
|
|
y = ps.rcPaint.top;
|
|
|
|
w = ps.rcPaint.right - ps.rcPaint.left + 1;
|
|
|
|
h = ps.rcPaint.bottom - ps.rcPaint.top + 1;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_scale_blt(wfc, hdc, x, y, w, h, wfc->primary->hdc, x - wfc->offset_x + wfc->xCurrentScroll, y - wfc->offset_y + wfc->yCurrentScroll, SRCCOPY);
|
2011-10-07 22:55:07 +04:00
|
|
|
|
2011-09-26 00:30:20 +04:00
|
|
|
EndPaint(hWnd, &ps);
|
2011-09-26 01:47:40 +04:00
|
|
|
break;
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2011-09-26 01:47:40 +04:00
|
|
|
case WM_LBUTTONDOWN:
|
2014-02-10 09:34:17 +04:00
|
|
|
wf_scale_mouse_event(wfc, input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
|
2011-09-26 01:47:40 +04:00
|
|
|
break;
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2011-09-26 01:47:40 +04:00
|
|
|
case WM_LBUTTONUP:
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_scale_mouse_event(wfc, input, PTR_FLAGS_BUTTON1, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
|
2011-09-26 01:47:40 +04:00
|
|
|
break;
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2011-09-26 01:47:40 +04:00
|
|
|
case WM_RBUTTONDOWN:
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_scale_mouse_event(wfc, input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
|
2011-09-26 01:47:40 +04:00
|
|
|
break;
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2011-09-26 01:47:40 +04:00
|
|
|
case WM_RBUTTONUP:
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_scale_mouse_event(wfc, input, PTR_FLAGS_BUTTON2, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
|
2011-09-26 01:47:40 +04:00
|
|
|
break;
|
2011-09-26 00:30:20 +04:00
|
|
|
|
2011-09-26 01:47:40 +04:00
|
|
|
case WM_MOUSEMOVE:
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_scale_mouse_event(wfc, input, PTR_FLAGS_MOVE, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
|
2011-09-26 01:47:40 +04:00
|
|
|
break;
|
2012-10-16 22:20:04 +04:00
|
|
|
|
2012-10-16 20:57:12 +04:00
|
|
|
case WM_MOUSEWHEEL:
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_event_process_WM_MOUSEWHEEL(wfc, hWnd, Msg, wParam, lParam);
|
2012-10-16 20:57:12 +04:00
|
|
|
break;
|
2011-09-26 01:47:40 +04:00
|
|
|
|
|
|
|
case WM_SETCURSOR:
|
2012-10-16 22:06:23 +04:00
|
|
|
if (LOWORD(lParam) == HTCLIENT)
|
2013-06-16 06:57:21 +04:00
|
|
|
SetCursor(wfc->cursor);
|
2012-10-16 22:06:23 +04:00
|
|
|
else
|
|
|
|
DefWindowProc(hWnd, Msg, wParam, lParam);
|
2011-09-26 01:47:40 +04:00
|
|
|
break;
|
|
|
|
|
2013-04-26 23:46:36 +04:00
|
|
|
case WM_HSCROLL:
|
|
|
|
{
|
|
|
|
int xDelta; // xDelta = new_pos - current_pos
|
|
|
|
int xNewPos; // new position
|
|
|
|
int yDelta = 0;
|
|
|
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
// User clicked the scroll bar shaft left of the scroll box.
|
|
|
|
case SB_PAGEUP:
|
2013-06-16 06:57:21 +04:00
|
|
|
xNewPos = wfc->xCurrentScroll - 50;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// User clicked the scroll bar shaft right of the scroll box.
|
|
|
|
case SB_PAGEDOWN:
|
2013-06-16 06:57:21 +04:00
|
|
|
xNewPos = wfc->xCurrentScroll + 50;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// User clicked the left arrow.
|
|
|
|
case SB_LINEUP:
|
2013-06-16 06:57:21 +04:00
|
|
|
xNewPos = wfc->xCurrentScroll - 5;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// User clicked the right arrow.
|
|
|
|
case SB_LINEDOWN:
|
2013-06-16 06:57:21 +04:00
|
|
|
xNewPos = wfc->xCurrentScroll + 5;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// User dragged the scroll box.
|
|
|
|
case SB_THUMBPOSITION:
|
|
|
|
xNewPos = HIWORD(wParam);
|
|
|
|
|
|
|
|
// user is dragging the scrollbar
|
|
|
|
case SB_THUMBTRACK :
|
|
|
|
xNewPos = HIWORD(wParam);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-06-16 06:57:21 +04:00
|
|
|
xNewPos = wfc->xCurrentScroll;
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// New position must be between 0 and the screen width.
|
|
|
|
xNewPos = MAX(0, xNewPos);
|
2013-06-16 06:57:21 +04:00
|
|
|
xNewPos = MIN(wfc->xMaxScroll, xNewPos);
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
// If the current position does not change, do not scroll.
|
2013-06-16 06:57:21 +04:00
|
|
|
if (xNewPos == wfc->xCurrentScroll)
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Determine the amount scrolled (in pixels).
|
2013-06-16 06:57:21 +04:00
|
|
|
xDelta = xNewPos - wfc->xCurrentScroll;
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
// Reset the current scroll position.
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xCurrentScroll = xNewPos;
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
// Scroll the window. (The system repaints most of the
|
|
|
|
// client area when ScrollWindowEx is called; however, it is
|
|
|
|
// necessary to call UpdateWindow in order to repaint the
|
|
|
|
// rectangle of pixels that were invalidated.)
|
2013-06-16 06:57:21 +04:00
|
|
|
ScrollWindowEx(wfc->hwnd, -xDelta, -yDelta, (CONST RECT *) NULL,
|
2013-04-26 23:46:36 +04:00
|
|
|
(CONST RECT *) NULL, (HRGN) NULL, (PRECT) NULL,
|
|
|
|
SW_INVALIDATE);
|
2013-06-16 06:57:21 +04:00
|
|
|
UpdateWindow(wfc->hwnd);
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
// Reset the scroll bar.
|
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_POS;
|
2013-06-16 06:57:21 +04:00
|
|
|
si.nPos = wfc->xCurrentScroll;
|
|
|
|
SetScrollInfo(wfc->hwnd, SB_HORZ, &si, TRUE);
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_VSCROLL:
|
|
|
|
{
|
|
|
|
int xDelta = 0;
|
|
|
|
int yDelta; // yDelta = new_pos - current_pos
|
|
|
|
int yNewPos; // new position
|
|
|
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
// User clicked the scroll bar shaft above the scroll box.
|
|
|
|
case SB_PAGEUP:
|
2013-06-16 06:57:21 +04:00
|
|
|
yNewPos = wfc->yCurrentScroll - 50;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// User clicked the scroll bar shaft below the scroll box.
|
|
|
|
case SB_PAGEDOWN:
|
2013-06-16 06:57:21 +04:00
|
|
|
yNewPos = wfc->yCurrentScroll + 50;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// User clicked the top arrow.
|
|
|
|
case SB_LINEUP:
|
2013-06-16 06:57:21 +04:00
|
|
|
yNewPos = wfc->yCurrentScroll - 5;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// User clicked the bottom arrow.
|
|
|
|
case SB_LINEDOWN:
|
2013-06-16 06:57:21 +04:00
|
|
|
yNewPos = wfc->yCurrentScroll + 5;
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// User dragged the scroll box.
|
|
|
|
case SB_THUMBPOSITION:
|
|
|
|
yNewPos = HIWORD(wParam);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// user is dragging the scrollbar
|
|
|
|
case SB_THUMBTRACK :
|
|
|
|
yNewPos = HIWORD(wParam);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-06-16 06:57:21 +04:00
|
|
|
yNewPos = wfc->yCurrentScroll;
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// New position must be between 0 and the screen height.
|
|
|
|
yNewPos = MAX(0, yNewPos);
|
2013-06-16 06:57:21 +04:00
|
|
|
yNewPos = MIN(wfc->yMaxScroll, yNewPos);
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
// If the current position does not change, do not scroll.
|
2013-06-16 06:57:21 +04:00
|
|
|
if (yNewPos == wfc->yCurrentScroll)
|
2013-04-26 23:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Determine the amount scrolled (in pixels).
|
2013-06-16 06:57:21 +04:00
|
|
|
yDelta = yNewPos - wfc->yCurrentScroll;
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
// Reset the current scroll position.
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->yCurrentScroll = yNewPos;
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
// Scroll the window. (The system repaints most of the
|
|
|
|
// client area when ScrollWindowEx is called; however, it is
|
|
|
|
// necessary to call UpdateWindow in order to repaint the
|
|
|
|
// rectangle of pixels that were invalidated.)
|
2013-06-16 06:57:21 +04:00
|
|
|
ScrollWindowEx(wfc->hwnd, -xDelta, -yDelta, (CONST RECT *) NULL,
|
2013-04-26 23:46:36 +04:00
|
|
|
(CONST RECT *) NULL, (HRGN) NULL, (PRECT) NULL,
|
|
|
|
SW_INVALIDATE);
|
2013-06-16 06:57:21 +04:00
|
|
|
UpdateWindow(wfc->hwnd);
|
2013-04-26 23:46:36 +04:00
|
|
|
|
|
|
|
// Reset the scroll bar.
|
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_POS;
|
2013-06-16 06:57:21 +04:00
|
|
|
si.nPos = wfc->yCurrentScroll;
|
|
|
|
SetScrollInfo(wfc->hwnd, SB_VERT, &si, TRUE);
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-04-30 19:15:04 +04:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
{
|
|
|
|
if (wParam == SYSCOMMAND_ID_SMARTSIZING)
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
HMENU hMenu = GetSystemMenu(wfc->hwnd, FALSE);
|
|
|
|
freerdp_set_param_bool(wfc->instance->settings, FreeRDP_SmartSizing, !wfc->instance->settings->SmartSizing);
|
|
|
|
CheckMenuItem(hMenu, SYSCOMMAND_ID_SMARTSIZING, wfc->instance->settings->SmartSizing ? MF_CHECKED : MF_UNCHECKED);
|
2013-04-30 19:15:04 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
processed = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-09-26 01:47:40 +04:00
|
|
|
default:
|
2012-10-09 10:31:28 +04:00
|
|
|
processed = FALSE;
|
2011-09-26 01:47:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
processed = FALSE;
|
2011-09-26 01:47:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (processed)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (Msg)
|
|
|
|
{
|
|
|
|
case WM_DESTROY:
|
|
|
|
PostQuitMessage(WM_QUIT);
|
2011-09-26 00:30:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SETCURSOR:
|
2012-10-16 22:06:23 +04:00
|
|
|
if (LOWORD(lParam) == HTCLIENT)
|
2013-06-16 06:57:21 +04:00
|
|
|
SetCursor(wfc->hDefaultCursor);
|
2012-10-16 22:06:23 +04:00
|
|
|
else
|
|
|
|
DefWindowProc(hWnd, Msg, wParam, lParam);
|
2011-09-26 00:30:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SETFOCUS:
|
2012-02-22 02:22:01 +04:00
|
|
|
DEBUG_KBD("getting focus %X", hWnd);
|
2011-09-26 00:30:20 +04:00
|
|
|
g_focus_hWnd = hWnd;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_KILLFOCUS:
|
2013-06-16 06:57:21 +04:00
|
|
|
if (g_focus_hWnd == hWnd && wfc && !wfc->fullscreen)
|
2013-04-25 00:47:32 +04:00
|
|
|
{
|
|
|
|
DEBUG_KBD("loosing focus %X", hWnd);
|
2011-09-26 00:30:20 +04:00
|
|
|
g_focus_hWnd = NULL;
|
2013-04-25 00:47:32 +04:00
|
|
|
}
|
2011-09-26 00:30:20 +04:00
|
|
|
break;
|
|
|
|
|
2013-05-31 22:20:43 +04:00
|
|
|
case WM_ACTIVATE:
|
|
|
|
{
|
2013-10-23 10:03:04 +04:00
|
|
|
int activate = (int)(short) LOWORD(wParam);
|
2013-05-31 22:20:43 +04:00
|
|
|
if (activate != WA_INACTIVE)
|
|
|
|
{
|
|
|
|
g_focus_hWnd = hWnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_focus_hWnd = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 00:30:20 +04:00
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, Msg, wParam, lParam);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-04-11 00:58:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
BOOL wf_scale_blt(wfContext* wfc, HDC hdc, int x, int y, int w, int h, HDC hdcSrc, int x1, int y1, DWORD rop)
|
2013-04-11 00:58:14 +04:00
|
|
|
{
|
|
|
|
int ww, wh, dw, dh;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc->client_width)
|
|
|
|
wfc->client_width = wfc->width;
|
2013-04-11 00:58:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc->client_height)
|
|
|
|
wfc->client_height = wfc->height;
|
2013-04-11 00:58:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
ww = wfc->client_width;
|
|
|
|
wh = wfc->client_height;
|
|
|
|
dw = wfc->instance->settings->DesktopWidth;
|
|
|
|
dh = wfc->instance->settings->DesktopHeight;
|
2013-04-11 00:58:14 +04:00
|
|
|
|
|
|
|
if (!ww)
|
|
|
|
ww = dw;
|
|
|
|
|
|
|
|
if (!wh)
|
|
|
|
wh = dh;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->fullscreen || !wfc->instance->settings->SmartSizing || (ww == dw && wh == dh))
|
2013-04-11 00:58:14 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
return BitBlt(hdc, x, y, w, h, wfc->primary->hdc, x1, y1, SRCCOPY);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetStretchBltMode(hdc, HALFTONE);
|
|
|
|
SetBrushOrgEx(hdc, 0, 0, NULL);
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
return StretchBlt(hdc, 0, 0, ww, wh, wfc->primary->hdc, 0, 0, dw, dh, SRCCOPY);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
void wf_scale_mouse_event(wfContext* wfc, rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2013-04-11 00:58:14 +04:00
|
|
|
{
|
|
|
|
int ww, wh, dw, dh;
|
2014-01-18 03:17:10 +04:00
|
|
|
rdpContext* context;
|
|
|
|
MouseEventEventArgs eventArgs;
|
2013-04-11 00:58:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc->client_width)
|
|
|
|
wfc->client_width = wfc->width;
|
2013-04-11 00:58:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc->client_height)
|
|
|
|
wfc->client_height = wfc->height;
|
2013-04-11 00:58:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
ww = wfc->client_width;
|
|
|
|
wh = wfc->client_height;
|
|
|
|
dw = wfc->instance->settings->DesktopWidth;
|
|
|
|
dh = wfc->instance->settings->DesktopHeight;
|
2013-04-11 00:58:14 +04:00
|
|
|
|
2013-10-01 23:45:50 +04:00
|
|
|
if (!wfc->instance->settings->SmartSizing || ((ww == dw) && (wh == dh)))
|
2013-06-16 06:57:21 +04:00
|
|
|
input->MouseEvent(input, flags, x + wfc->xCurrentScroll, y + wfc->yCurrentScroll);
|
2013-04-11 00:58:14 +04:00
|
|
|
else
|
2013-06-16 06:57:21 +04:00
|
|
|
input->MouseEvent(input, flags, x * dw / ww + wfc->xCurrentScroll, y * dh / wh + wfc->yCurrentScroll);
|
2014-01-18 03:17:10 +04:00
|
|
|
|
|
|
|
eventArgs.flags = flags;
|
|
|
|
eventArgs.x = x;
|
|
|
|
eventArgs.y = y;
|
|
|
|
context = (rdpContext*) wfc;
|
|
|
|
PubSub_OnMouseEvent(context->pubSub, context, &eventArgs);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|