Blender V5.3
GHOST_SystemWin32.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <limits>
10#include <map>
11
14#include "GHOST_SystemWin32.hh"
15
16#ifndef _WIN32_IE
17# define _WIN32_IE 0x0501 /* shipped before XP, so doesn't impose additional requirements */
18#endif
19
20#include <commctrl.h>
21#include <dwmapi.h>
22#include <psapi.h>
23#include <shellapi.h>
24#include <shellscalingapi.h>
25#include <shlobj.h>
26#include <tlhelp32.h>
27#include <windowsx.h>
28
29#include "utf_winfunc.hh"
30#include "utfconv.hh"
31
32#include "IMB_imbuf.hh"
33#include "IMB_imbuf_types.hh"
34
35#include "GHOST_EventButton.hh"
36#include "GHOST_EventCursor.hh"
37#include "GHOST_EventKey.hh"
38#include "GHOST_EventWheel.hh"
39#include "GHOST_TimerManager.hh"
40#include "GHOST_TimerTask.hh"
42#include "GHOST_WindowWin32.hh"
43
44#include "GHOST_ContextD3D.hh"
45#ifdef WITH_OPENGL_BACKEND
46# include "GHOST_ContextWGL.hh"
47#endif
48#ifdef WITH_VULKAN_BACKEND
49# include "GHOST_ContextVK.hh"
50#endif
51
52#ifdef WITH_INPUT_NDOF
54#endif
55
56/* Key code values not found in `winuser.h`. */
57#ifndef VK_MINUS
58# define VK_MINUS 0xBD
59#endif /* VK_MINUS */
60#ifndef VK_SEMICOLON
61# define VK_SEMICOLON 0xBA
62#endif /* VK_SEMICOLON */
63#ifndef VK_PERIOD
64# define VK_PERIOD 0xBE
65#endif /* VK_PERIOD */
66#ifndef VK_COMMA
67# define VK_COMMA 0xBC
68#endif /* VK_COMMA */
69#ifndef VK_BACK_QUOTE
70# define VK_BACK_QUOTE 0xC0
71#endif /* VK_BACK_QUOTE */
72#ifndef VK_SLASH
73# define VK_SLASH 0xBF
74#endif /* VK_SLASH */
75#ifndef VK_BACK_SLASH
76# define VK_BACK_SLASH 0xDC
77#endif /* VK_BACK_SLASH */
78#ifndef VK_EQUALS
79# define VK_EQUALS 0xBB
80#endif /* VK_EQUALS */
81#ifndef VK_OPEN_BRACKET
82# define VK_OPEN_BRACKET 0xDB
83#endif /* VK_OPEN_BRACKET */
84#ifndef VK_CLOSE_BRACKET
85# define VK_CLOSE_BRACKET 0xDD
86#endif /* VK_CLOSE_BRACKET */
87#ifndef VK_GR_LESS
88# define VK_GR_LESS 0xE2
89#endif /* VK_GR_LESS */
90
101#define BROKEN_PEEK_TOUCHPAD
102
103static bool isStartedFromCommandPrompt();
104
122
124{
125 const auto iter = longButtonHIDsToGHOST_NDOFButtons.find(longKey);
126 if (iter == longButtonHIDsToGHOST_NDOFButtons.end()) {
127 return static_cast<GHOST_NDOF_ButtonT>(longKey);
128 }
129 return iter->second;
130}
131
132static void initRawInput()
133{
134#ifdef WITH_INPUT_NDOF
135# define DEVICE_COUNT 2
136#else
137# define DEVICE_COUNT 1
138#endif
139
140 RAWINPUTDEVICE devices[DEVICE_COUNT];
141 memset(devices, 0, DEVICE_COUNT * sizeof(RAWINPUTDEVICE));
142
143 /* Initiates WM_INPUT messages from keyboard
144 * That way GHOST can retrieve true keys. */
145 devices[0].usUsagePage = 0x01;
146 devices[0].usUsage = 0x06; /* http://msdn.microsoft.com/en-us/windows/hardware/gg487473.aspx */
147
148#ifdef WITH_INPUT_NDOF
149 /* multi-axis mouse (SpaceNavigator, etc.). */
150 devices[1].usUsagePage = 0x01;
151 devices[1].usUsage = 0x08;
152#endif
153
154 if (RegisterRawInputDevices(devices, DEVICE_COUNT, sizeof(RAWINPUTDEVICE))) {
155 /* Success. */
156 }
157 else {
158 GHOST_PRINTF("could not register for RawInput: %d\n", int(GetLastError()));
159 }
160#undef DEVICE_COUNT
161}
162
164
166{
167 console_status_ = true;
168
169 /* Tell Windows we are per monitor DPI aware. This disables the default
170 * blurry scaling and enables WM_DPICHANGED to allow us to draw at proper DPI. */
171 SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
172
173 /* Set App Id for the process so our console will be grouped on the Task Bar. */
174 UTF16_ENCODE(BLENDER_WIN_APPID);
175 SetCurrentProcessExplicitAppUserModelID(BLENDER_WIN_APPID_16);
176 UTF16_UN_ENCODE(BLENDER_WIN_APPID);
177
178 /* Check if current keyboard layout uses AltGr and save keylayout ID for
179 * specialized handling if keys like VK_OEM_*. I.e. french keylayout
180 * generates #VK_OEM_8 for their exclamation key (key left of right shift). */
181 this->handleKeyboardChange();
182 /* Require COM for GHOST_DropTargetWin32 created in GHOST_WindowWin32. */
183 OleInitialize(0);
184
185#ifdef WITH_INPUT_NDOF
186 ndof_manager_ = new GHOST_NDOFManagerWin32(*this);
187#endif
188}
189
191{
192 /* Shutdown COM. */
193 OleUninitialize();
194
197 }
198
199 /* We must call exit from here, since by the time ~GHOST_System calls it, the GHOST_SystemWin32
200 * override is no longer reachable. */
201 exit();
202}
203
205{
206 /* Calculate the time passed since system initialization. */
207 __int64 delta = perf_ticks * 1000;
208
209 uint64_t t = uint64_t(delta / freq_);
210 return t;
211}
212
214{
215 /* Hardware does not support high resolution timers. We will use GetTickCount instead then. */
217 return ::GetTickCount64();
218 }
219
220 /* Retrieve current count */
221 __int64 count = 0;
222 ::QueryPerformanceCounter((LARGE_INTEGER *)&count);
223
224 return performanceCounterToMillis(count);
225}
226
233{
234 /* Get difference between last message time and now. */
235 int64_t t_delta = GetMessageTime() - GetTickCount();
236
237 /* Handle 32-bit rollover. */
238 if (t_delta > 0) {
239 t_delta -= int64_t(UINT32_MAX) + 1;
240 }
241
242 /* Return message time as 64-bit milliseconds with the delta applied. */
243 return system->getMilliSeconds() + t_delta;
244}
245
247{
248 return ::GetSystemMetrics(SM_CMONITORS);
249}
250
251void GHOST_SystemWin32::getMainDisplayDimensions(uint32_t &width, uint32_t &height) const
252{
253 width = ::GetSystemMetrics(SM_CXSCREEN);
254 height = ::GetSystemMetrics(SM_CYSCREEN);
255}
256
257void GHOST_SystemWin32::getAllDisplayDimensions(uint32_t &width, uint32_t &height) const
258{
259 width = ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
260 height = ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
261}
262
264 int32_t left,
265 int32_t top,
266 uint32_t width,
267 uint32_t height,
269 GHOST_GPUSettings gpu_settings,
270 const bool /*exclusive*/,
271 const bool is_dialog,
272 const GHOST_IWindow *parent_window)
273{
274 const GHOST_ContextParams context_params = GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS(gpu_settings);
275 GHOST_WindowWin32 *window = new GHOST_WindowWin32(this,
276 title,
277 left,
278 top,
279 width,
280 height,
281 state,
282 gpu_settings.context_type,
283 context_params,
284 (GHOST_WindowWin32 *)parent_window,
285 is_dialog,
286 gpu_settings.preferred_device);
287
288 if (window->getValid()) {
289 /* Store the pointer to the window */
290 window_manager_->addWindow(window);
292 }
293 else {
294 GHOST_PRINT("GHOST_SystemWin32::createWindow(): window invalid\n");
295 delete window;
296 window = nullptr;
297 }
298
299 return window;
300}
301
308{
309 const GHOST_ContextParams context_params_offscreen =
311
312 switch (gpu_settings.context_type) {
313#ifdef WITH_VULKAN_BACKEND
314 case GHOST_kDrawingContextTypeVulkan: {
315 GHOST_Context *context = new GHOST_ContextVK(
316 context_params_offscreen, (HWND)0, 1, 1, gpu_settings.preferred_device);
317 if (context->initializeDrawingContext()) {
318 return context;
319 }
320 delete context;
321 return nullptr;
322 }
323#endif
324
325#ifdef WITH_OPENGL_BACKEND
326 case GHOST_kDrawingContextTypeOpenGL: {
327
328 HGLRC prev_context = wglGetCurrentContext();
329 HDC prev_hdc = wglGetCurrentDC();
330
331 for (int minor = 6; minor >= 3; --minor) {
332 GHOST_ContextWGL *context = new GHOST_ContextWGL(
333 context_params_offscreen,
334 true,
335 nullptr,
336 nullptr,
337 WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
338 4,
339 minor,
340 (context_params_offscreen.is_debug ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
342
343 if (context->initializeDrawingContext()) {
344 wglMakeCurrent(prev_hdc, prev_context);
345 return context;
346 }
347 delete context;
348 }
349 wglMakeCurrent(prev_hdc, prev_context);
350 return nullptr;
351 }
352#endif
353 default:
354 /* Unsupported backend. */
355 return nullptr;
356 }
357}
358
365{
366 delete context;
367
368 return GHOST_kSuccess;
369}
370
377{
378 /* NOTE: the `gpu_settings` could be passed in here, as it is with similar functions. */
379 const GHOST_ContextParams context_params_offscreen = GHOST_CONTEXT_PARAMS_NONE;
380 HWND wnd = CreateWindowA("STATIC",
381 "Blender XR",
382 WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
383 0,
384 0,
385 64,
386 64,
387 nullptr,
388 nullptr,
389 GetModuleHandle(nullptr),
390 nullptr);
391
392 GHOST_ContextD3D *context = new GHOST_ContextD3D(context_params_offscreen, wnd);
393 if (context->initializeDrawingContext()) {
394 return context;
395 }
396 delete context;
397 return nullptr;
398}
399
401{
402 delete context;
403
404 return GHOST_kSuccess;
405}
406
407bool GHOST_SystemWin32::processEvents(bool waitForEvent)
408{
409 MSG msg;
410 bool hasEventHandled = false;
411
412 do {
414
415 if (waitForEvent && !::PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) {
416#if 1
417 ::Sleep(1);
418#else
419 uint64_t next = timerMgr->nextFireTime();
420 int64_t maxSleep = next - getMilliSeconds();
421
422 if (next == GHOST_kFireTimeNever) {
423 ::WaitMessage();
424 }
425 else if (maxSleep >= 0.0) {
426 ::SetTimer(nullptr, 0, maxSleep, nullptr);
427 ::WaitMessage();
428 ::KillTimer(nullptr, 0);
429 }
430#endif
431 }
432
433 if (timerMgr->fireTimers(getMilliSeconds())) {
434 hasEventHandled = true;
435 }
436
438
439 /* Process all the events waiting for us. */
440 while (::PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE) != 0) {
441 /* #TranslateMessage doesn't alter the message, and doesn't change our raw keyboard data.
442 * Needed for #MapVirtualKey or if we ever need to get chars from wm_ime_char or similar. */
443 ::TranslateMessage(&msg);
444 ::DispatchMessageW(&msg);
445 hasEventHandled = true;
446 }
447
449
450 /* `PeekMessage` above is allowed to dispatch messages to the `wndproc` without us
451 * noticing, so we need to check the event manager here to see if there are
452 * events waiting in the queue. */
453 hasEventHandled |= this->event_manager_->getNumEvents() > 0;
454
455 } while (waitForEvent && !hasEventHandled);
456
457 return hasEventHandled;
458}
459
461{
462 POINT point;
463 if (::GetCursorPos(&point)) {
464 x = point.x;
465 y = point.y;
466 return GHOST_kSuccess;
467 }
468 return GHOST_kFailure;
469}
470
472{
473 if (!::GetActiveWindow()) {
474 return GHOST_kFailure;
475 }
476 return ::SetCursorPos(x, y) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
477}
478
480{
481 POINT point;
482 if (!GetCursorPos(&point)) {
483 return GHOST_kFailure;
484 }
485
486 HDC dc = GetDC(NULL);
487 if (dc == NULL) {
488 return GHOST_kFailure;
489 }
490
491 COLORREF color = GetPixel(dc, point.x, point.y);
492 ReleaseDC(NULL, dc);
493
494 if (color == CLR_INVALID) {
495 return GHOST_kFailure;
496 }
497
498 r_color[0] = GetRValue(color) / 255.0f;
499 r_color[1] = GetGValue(color) / 255.0f;
500 r_color[2] = GetBValue(color) / 255.0f;
501 return GHOST_kSuccess;
502}
503
505{
506 int size = -1;
507
508 HKEY hKey;
509 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Cursors", 0, KEY_READ, &hKey) ==
510 ERROR_SUCCESS)
511 {
512 DWORD cursorSizeSetting;
513 DWORD setting_size = sizeof(cursorSizeSetting);
514 if (RegQueryValueEx(hKey,
515 "CursorBaseSize",
516 nullptr,
517 nullptr,
518 reinterpret_cast<BYTE *>(&cursorSizeSetting),
519 &setting_size) == ERROR_SUCCESS &&
520 setting_size == sizeof(cursorSizeSetting))
521 {
522 size = cursorSizeSetting;
523 }
524 RegCloseKey(hKey);
525 }
526
527 if (size == -1) {
528 size = GetSystemMetrics(SM_CXCURSOR);
529 }
530
531 /* Default size is 32 even though the cursor is smaller than this. Scale
532 * so that 32 returns 21 to better match our size to OS-supplied cursors. */
533 size = int(roundf(float(size) * 0.65f));
534
535 return size;
536}
537
539{
540 /* Get cursor position from the OS. Do not use the supplied positions as those
541 * could be incorrect, especially if using multiple windows of differing OS scale. */
542 POINT point;
543 if (!GetCursorPos(&point)) {
544 return nullptr;
545 }
546
547 HWND win = WindowFromPoint(point);
548 if (win == NULL) {
549 return nullptr;
550 }
551
552 return window_manager_->getWindowAssociatedWithOSWindow((const void *)win);
553}
554
556{
557 /* `GetAsyncKeyState` returns the current interrupt-level state of the hardware, which is needed
558 * when passing key states to a newly-activated window - #40059. Alternative `GetKeyState` only
559 * returns the state as processed by the thread's message queue. */
560 bool down = HIBYTE(::GetAsyncKeyState(VK_LSHIFT)) != 0;
562 down = HIBYTE(::GetAsyncKeyState(VK_RSHIFT)) != 0;
564
565 down = HIBYTE(::GetAsyncKeyState(VK_LMENU)) != 0;
566 keys.set(GHOST_kModifierKeyLeftAlt, down);
567 down = HIBYTE(::GetAsyncKeyState(VK_RMENU)) != 0;
569
570 down = HIBYTE(::GetAsyncKeyState(VK_LCONTROL)) != 0;
572 down = HIBYTE(::GetAsyncKeyState(VK_RCONTROL)) != 0;
574
575 down = HIBYTE(::GetAsyncKeyState(VK_LWIN)) != 0;
576 keys.set(GHOST_kModifierKeyLeftOS, down);
577 down = HIBYTE(::GetAsyncKeyState(VK_RWIN)) != 0;
578 keys.set(GHOST_kModifierKeyRightOS, down);
579
580 return GHOST_kSuccess;
581}
582
584{
585 /* Check for swapped buttons (left-handed mouse buttons)
586 * GetAsyncKeyState() will give back the state of the physical mouse buttons.
587 */
588 bool swapped = ::GetSystemMetrics(SM_SWAPBUTTON) == TRUE;
589
590 bool down = HIBYTE(::GetAsyncKeyState(VK_LBUTTON)) != 0;
591 buttons.set(swapped ? GHOST_kButtonMaskRight : GHOST_kButtonMaskLeft, down);
592
593 down = HIBYTE(::GetAsyncKeyState(VK_MBUTTON)) != 0;
594 buttons.set(GHOST_kButtonMaskMiddle, down);
595
596 down = HIBYTE(::GetAsyncKeyState(VK_RBUTTON)) != 0;
597 buttons.set(swapped ? GHOST_kButtonMaskLeft : GHOST_kButtonMaskRight, down);
598 return GHOST_kSuccess;
599}
600
602{
605 /* NOTE: order the following flags as they they're declared in the source. */
606 ~(
607 /* WIN32 has no support for a primary selection clipboard. */
609 /* WIN32 doesn't define a Hyper modifier key,
610 * it's possible another modifier could be optionally used in it's place. */
612 /* No support yet for cursors generated on demand. */
614 /* No support for window path meta-data. */
616}
617
619{
621 InitCommonControls();
622
623 /* Disable scaling on high DPI displays on Vista */
624 SetProcessDPIAware();
625 initRawInput();
626
627 /* Determine whether this system has a high frequency performance counter. */
628 has_performance_counter_ = ::QueryPerformanceFrequency((LARGE_INTEGER *)&freq_) == TRUE;
629
630 if (success) {
631 WNDCLASSW wc = {0};
632 wc.style = CS_HREDRAW | CS_VREDRAW;
633 wc.lpfnWndProc = s_wndProc;
634 wc.cbClsExtra = 0;
635 wc.cbWndExtra = 0;
636 wc.hInstance = ::GetModuleHandle(0);
637 wc.hIcon = ::LoadIcon(wc.hInstance, "APPICON");
638
639 if (!wc.hIcon) {
640 ::LoadIcon(nullptr, IDI_APPLICATION);
641 }
642 wc.hCursor = ::LoadCursor(0, IDC_ARROW);
643 wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
644 wc.lpszMenuName = 0;
645 wc.lpszClassName = L"GHOST_WindowClass";
646
647 /* Use #RegisterClassEx for setting small icon. */
648 if (::RegisterClassW(&wc) == 0) {
649 success = GHOST_kFailure;
650 }
651 }
652
653 return success;
654}
655
657{
659 /* All windows created with the specified class must be destroyed before unregistering it. */
660 ::UnregisterClassW(L"GHOST_WindowClass", ::GetModuleHandle(0));
661 return success;
662}
663
664GHOST_TKey GHOST_SystemWin32::hardKey(RAWINPUT const &raw, bool *r_key_down)
665{
666 /* #RI_KEY_BREAK doesn't work for sticky keys release, so we also check for the up message. */
667 uint msg = raw.data.keyboard.Message;
668 *r_key_down = !(raw.data.keyboard.Flags & RI_KEY_BREAK) && msg != WM_KEYUP && msg != WM_SYSKEYUP;
669
670 return this->convertKey(raw.data.keyboard.VKey,
671 raw.data.keyboard.MakeCode,
672 (raw.data.keyboard.Flags & (RI_KEY_E1 | RI_KEY_E0)));
673}
674
681GHOST_TKey GHOST_SystemWin32::processSpecialKey(short vKey, short /*scanCode*/) const
682{
684 if (vKey == 0xFF) {
685 /* 0xFF is not a valid virtual key code. */
686 return key;
687 }
688
689 char ch = char(MapVirtualKeyA(vKey, MAPVK_VK_TO_CHAR));
690 switch (ch) {
691 case u'\"':
692 case u'\'':
693 key = GHOST_kKeyQuote;
694 break;
695 case u'.':
697 break;
698 case u'/':
699 key = GHOST_kKeySlash;
700 break;
701 case u'`':
702 case u'²':
704 break;
705 case u'i':
706 /* `i` key on Turkish keyboard. */
707 key = GHOST_kKeyI;
708 break;
709 default:
710 if (vKey == VK_OEM_7) {
711 key = GHOST_kKeyQuote;
712 }
713 else if (vKey == VK_OEM_8) {
714 if (PRIMARYLANGID(lang_id_) == LANG_FRENCH) {
715 /* OEM key; used purely for shortcuts. */
716 key = GHOST_kKeyF13;
717 }
718 }
719 break;
720 }
721
722 return key;
723}
724
725GHOST_TKey GHOST_SystemWin32::convertKey(short vKey, short scanCode, short extend) const
726{
727 GHOST_TKey key;
728
729 if ((vKey >= '0') && (vKey <= '9')) {
730 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39). */
731 key = (GHOST_TKey)(vKey - '0' + GHOST_kKey0);
732 }
733 else if ((vKey >= 'A') && (vKey <= 'Z')) {
734 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A). */
735 key = (GHOST_TKey)(vKey - 'A' + GHOST_kKeyA);
736 }
737 else if ((vKey >= VK_F1) && (vKey <= VK_F24)) {
738 key = (GHOST_TKey)(vKey - VK_F1 + GHOST_kKeyF1);
739 }
740 else {
741 switch (vKey) {
742 case VK_RETURN:
743 key = (extend) ? GHOST_kKeyNumpadEnter : GHOST_kKeyEnter;
744 break;
745
746 case VK_BACK:
748 break;
749 case VK_TAB:
750 key = GHOST_kKeyTab;
751 break;
752 case VK_ESCAPE:
753 key = GHOST_kKeyEsc;
754 break;
755 case VK_SPACE:
756 key = GHOST_kKeySpace;
757 break;
758
759 case VK_INSERT:
760 case VK_NUMPAD0:
761 key = (extend) ? GHOST_kKeyInsert : GHOST_kKeyNumpad0;
762 break;
763 case VK_END:
764 case VK_NUMPAD1:
765 key = (extend) ? GHOST_kKeyEnd : GHOST_kKeyNumpad1;
766 break;
767 case VK_DOWN:
768 case VK_NUMPAD2:
769 key = (extend) ? GHOST_kKeyDownArrow : GHOST_kKeyNumpad2;
770 break;
771 case VK_NEXT:
772 case VK_NUMPAD3:
773 key = (extend) ? GHOST_kKeyDownPage : GHOST_kKeyNumpad3;
774 break;
775 case VK_LEFT:
776 case VK_NUMPAD4:
777 key = (extend) ? GHOST_kKeyLeftArrow : GHOST_kKeyNumpad4;
778 break;
779 case VK_CLEAR:
780 case VK_NUMPAD5:
781 key = (extend) ? GHOST_kKeyUnknown : GHOST_kKeyNumpad5;
782 break;
783 case VK_RIGHT:
784 case VK_NUMPAD6:
785 key = (extend) ? GHOST_kKeyRightArrow : GHOST_kKeyNumpad6;
786 break;
787 case VK_HOME:
788 case VK_NUMPAD7:
789 key = (extend) ? GHOST_kKeyHome : GHOST_kKeyNumpad7;
790 break;
791 case VK_UP:
792 case VK_NUMPAD8:
793 key = (extend) ? GHOST_kKeyUpArrow : GHOST_kKeyNumpad8;
794 break;
795 case VK_PRIOR:
796 case VK_NUMPAD9:
797 key = (extend) ? GHOST_kKeyUpPage : GHOST_kKeyNumpad9;
798 break;
799 case VK_DECIMAL:
800 case VK_DELETE:
801 key = (extend) ? GHOST_kKeyDelete : GHOST_kKeyNumpadPeriod;
802 break;
803
804 case VK_SNAPSHOT:
806 break;
807 case VK_PAUSE:
808 key = GHOST_kKeyPause;
809 break;
810 case VK_MULTIPLY:
812 break;
813 case VK_SUBTRACT:
815 break;
816 case VK_DIVIDE:
818 break;
819 case VK_ADD:
821 break;
822
823 case VK_SEMICOLON:
825 break;
826 case VK_EQUALS:
827 key = GHOST_kKeyEqual;
828 break;
829 case VK_COMMA:
830 key = GHOST_kKeyComma;
831 break;
832 case VK_MINUS:
833 key = GHOST_kKeyMinus;
834 break;
835 case VK_PERIOD:
836 key = GHOST_kKeyPeriod;
837 break;
838 case VK_SLASH:
839 key = GHOST_kKeySlash;
840 break;
841 case VK_BACK_QUOTE:
843 break;
844 case VK_OPEN_BRACKET:
846 break;
847 case VK_BACK_SLASH:
849 break;
850 case VK_CLOSE_BRACKET:
852 break;
853 case VK_GR_LESS:
854 key = GHOST_kKeyGrLess;
855 break;
856
857 case VK_SHIFT:
858 /* Check single shift presses */
859 if (scanCode == 0x36) {
861 }
862 else if (scanCode == 0x2a) {
864 }
865 else {
866 /* Must be a combination SHIFT (Left or Right) + a Key
867 * Ignore this as the next message will contain
868 * the desired "Key" */
869 key = GHOST_kKeyUnknown;
870 }
871 break;
872 case VK_CONTROL:
874 break;
875 case VK_MENU:
876 key = (extend) ? GHOST_kKeyRightAlt : GHOST_kKeyLeftAlt;
877 break;
878 case VK_LWIN:
879 key = GHOST_kKeyLeftOS;
880 break;
881 case VK_RWIN:
882 key = GHOST_kKeyRightOS;
883 break;
884 case VK_APPS:
885 key = GHOST_kKeyApp;
886 break;
887 case VK_NUMLOCK:
888 key = GHOST_kKeyNumLock;
889 break;
890 case VK_SCROLL:
892 break;
893 case VK_CAPITAL:
894 key = GHOST_kKeyCapsLock;
895 break;
896 case VK_MEDIA_PLAY_PAUSE:
898 break;
899 case VK_MEDIA_STOP:
901 break;
902 case VK_MEDIA_PREV_TRACK:
904 break;
905 case VK_MEDIA_NEXT_TRACK:
907 break;
908 case VK_OEM_7:
909 case VK_OEM_8:
910 default:
911 key = ((GHOST_SystemWin32 *)getSystem())->processSpecialKey(vKey, scanCode);
912 break;
913 }
914 }
915
916 return key;
917}
918
919std::unique_ptr<GHOST_EventButton> GHOST_SystemWin32::processButtonEvent(GHOST_TEventType type,
920 GHOST_WindowWin32 *window,
922{
924
925 GHOST_TabletData td = window->getTabletData();
926 const uint64_t event_ms = getMessageTime(system);
927
928 /* Move mouse to button event position. */
929 if (window->getTabletData().Active != GHOST_kTabletModeNone) {
930 /* Tablet should be handling in between mouse moves, only move to event position. */
931 DWORD msgPos = ::GetMessagePos();
932 int msgPosX = GET_X_LPARAM(msgPos);
933 int msgPosY = GET_Y_LPARAM(msgPos);
934 system->pushEvent(std::make_unique<GHOST_EventCursor>(
935 event_ms, GHOST_kEventCursorMove, window, msgPosX, msgPosY, td));
936
937 if (type == GHOST_kEventButtonDown) {
938 WINTAB_PRINTF("HWND %p OS button down\n", window->getHWND());
939 }
940 else if (type == GHOST_kEventButtonUp) {
941 WINTAB_PRINTF("HWND %p OS button up\n", window->getHWND());
942 }
943 }
944
946 return std::make_unique<GHOST_EventButton>(event_ms, type, window, mask, td);
947}
948
950{
951 GHOST_Wintab *wt = window->getWintab();
952 if (!wt) {
953 return;
954 }
955
957
958 std::vector<GHOST_WintabInfoWin32> wintabInfo;
959 wt->getInput(wintabInfo);
960
961 /* Wintab provided coordinates are untrusted until a Wintab and Win32 button down event match.
962 * This is checked on every button down event, and revoked if there is a mismatch. This can
963 * happen when Wintab incorrectly scales cursor position or is in mouse mode.
964 *
965 * If Wintab was never trusted while processing this Win32 event, a fallback Ghost cursor move
966 * event is created at the position of the Win32 WT_PACKET event. */
967 bool mouseMoveHandled;
968 bool useWintabPos;
969 mouseMoveHandled = useWintabPos = wt->trustCoordinates();
970
971 for (GHOST_WintabInfoWin32 &info : wintabInfo) {
972 switch (info.type) {
974 if (!useWintabPos) {
975 continue;
976 }
977
978 wt->mapWintabToSysCoordinates(info.x, info.y, info.x, info.y);
979 system->pushEvent(std::make_unique<GHOST_EventCursor>(
980 info.time, GHOST_kEventCursorMove, window, info.x, info.y, info.tabletData));
981
982 break;
983 }
985 WINTAB_PRINTF("HWND %p Wintab button down", window->getHWND());
986
987 uint message;
988 switch (info.button) {
990 message = WM_LBUTTONDOWN;
991 break;
993 message = WM_RBUTTONDOWN;
994 break;
996 message = WM_MBUTTONDOWN;
997 break;
998 default:
999 continue;
1000 }
1001
1002 /* Wintab buttons are modal, but the API does not inform us what mode a pressed button is
1003 * in. Only issue button events if we can steal an equivalent Win32 button event from the
1004 * event queue. */
1005 MSG msg;
1006 if (PeekMessage(&msg, window->getHWND(), message, message, PM_NOYIELD) &&
1007 msg.message != WM_QUIT)
1008 {
1009
1010 /* Test for Win32/Wintab button down match. */
1011 useWintabPos = wt->testCoordinates(msg.pt.x, msg.pt.y, info.x, info.y);
1012 if (!useWintabPos) {
1013 WINTAB_PRINTF(" ... but associated system button mismatched position\n");
1014 continue;
1015 }
1016
1017 WINTAB_PRINTF(" ... associated to system button\n");
1018
1019 /* Steal the Win32 event which was previously peeked. */
1020 PeekMessage(&msg, window->getHWND(), message, message, PM_REMOVE | PM_NOYIELD);
1021
1022 /* Move cursor to button location, to prevent incorrect cursor position when
1023 * transitioning from unsynchronized Win32 to Wintab cursor control. */
1024 wt->mapWintabToSysCoordinates(info.x, info.y, info.x, info.y);
1025 system->pushEvent(std::make_unique<GHOST_EventCursor>(
1026 info.time, GHOST_kEventCursorMove, window, info.x, info.y, info.tabletData));
1027
1029 system->pushEvent(std::make_unique<GHOST_EventButton>(
1030 info.time, info.type, window, info.button, info.tabletData));
1031
1032 mouseMoveHandled = true;
1033 }
1034 else {
1035 WINTAB_PRINTF(" ... but no system button\n");
1036 }
1037 break;
1038 }
1039 case GHOST_kEventButtonUp: {
1040 WINTAB_PRINTF("HWND %p Wintab button up", window->getHWND());
1041 if (!useWintabPos) {
1042 WINTAB_PRINTF(" ... but Wintab position isn't trusted\n");
1043 continue;
1044 }
1045
1046 uint message;
1047 switch (info.button) {
1049 message = WM_LBUTTONUP;
1050 break;
1052 message = WM_RBUTTONUP;
1053 break;
1055 message = WM_MBUTTONUP;
1056 break;
1057 default:
1058 continue;
1059 }
1060
1061 /* Wintab buttons are modal, but the API does not inform us what mode a pressed button is
1062 * in. Only issue button events if we can steal an equivalent Win32 button event from the
1063 * event queue. */
1064 MSG msg;
1065 if (PeekMessage(&msg, window->getHWND(), message, message, PM_REMOVE | PM_NOYIELD) &&
1066 msg.message != WM_QUIT)
1067 {
1068
1069 WINTAB_PRINTF(" ... associated to system button\n");
1071 system->pushEvent(std::make_unique<GHOST_EventButton>(
1072 info.time, info.type, window, info.button, info.tabletData));
1073 }
1074 else {
1075 WINTAB_PRINTF(" ... but no system button\n");
1076 }
1077 break;
1078 }
1079 default:
1080 break;
1081 }
1082 }
1083
1084 /* Fallback cursor movement if Wintab position were never trusted while processing this event. */
1085 if (!mouseMoveHandled) {
1086 DWORD pos = GetMessagePos();
1087 int x = GET_X_LPARAM(pos);
1088 int y = GET_Y_LPARAM(pos);
1090
1091 system->pushEvent(std::make_unique<GHOST_EventCursor>(
1092 getMessageTime(system), GHOST_kEventCursorMove, window, x, y, td));
1093 }
1094}
1095
1097 uint type, GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam, bool &eventHandled)
1098{
1099 /* Pointer events might fire when changing windows for a device which is set to use Wintab,
1100 * even when Wintab is left enabled but set to the bottom of Wintab overlap order. */
1102 return;
1103 }
1104
1106 std::vector<GHOST_PointerInfoWin32> pointerInfo;
1107
1108 if (window->getPointerInfo(pointerInfo, wParam, lParam) != GHOST_kSuccess) {
1109 return;
1110 }
1111
1112 switch (type) {
1113 case WM_POINTERUPDATE: {
1114 /* Coalesced pointer events are reverse chronological order, reorder chronologically.
1115 * Only contiguous move events are coalesced. */
1116 for (uint32_t i = pointerInfo.size(); i-- > 0;) {
1117 system->pushEvent(std::make_unique<GHOST_EventCursor>(pointerInfo[i].time,
1119 window,
1120 pointerInfo[i].pixelLocation.x,
1121 pointerInfo[i].pixelLocation.y,
1122 pointerInfo[i].tabletData));
1123 }
1124
1125 /* Leave event unhandled so that system cursor is moved. */
1126
1127 break;
1128 }
1129 case WM_POINTERDOWN: {
1130 /* Move cursor to point of contact because GHOST_EventButton does not include position. */
1131 system->pushEvent(std::make_unique<GHOST_EventCursor>(pointerInfo[0].time,
1133 window,
1134 pointerInfo[0].pixelLocation.x,
1135 pointerInfo[0].pixelLocation.y,
1136 pointerInfo[0].tabletData));
1137 system->pushEvent(std::make_unique<GHOST_EventButton>(pointerInfo[0].time,
1139 window,
1140 pointerInfo[0].buttonMask,
1141 pointerInfo[0].tabletData));
1143
1144 /* Mark event handled so that mouse button events are not generated. */
1145 eventHandled = true;
1146
1147 break;
1148 }
1149 case WM_POINTERUP: {
1150 system->pushEvent(std::make_unique<GHOST_EventButton>(pointerInfo[0].time,
1152 window,
1153 pointerInfo[0].buttonMask,
1154 pointerInfo[0].tabletData));
1156
1157 /* Mark event handled so that mouse button events are not generated. */
1158 eventHandled = true;
1159
1160 break;
1161 }
1162 default: {
1163 break;
1164 }
1165 }
1166}
1167
1168std::unique_ptr<GHOST_EventCursor> GHOST_SystemWin32::processCursorEvent(
1169 GHOST_WindowWin32 *window, const int32_t screen_co[2])
1170{
1172
1173 if (window->getTabletData().Active != GHOST_kTabletModeNone) {
1174 /* While pen devices are in range, cursor movement is handled by tablet input processing. */
1175 return nullptr;
1176 }
1177
1178 int32_t x_screen = screen_co[0], y_screen = screen_co[1];
1179 if (window->getCursorGrabModeIsWarp()) {
1180 /* WORKAROUND:
1181 * Sometimes Windows ignores `SetCursorPos()` or `SendInput()` calls or the mouse event is
1182 * outdated. Identify these cases by checking if the cursor is not yet within bounds. */
1183 static bool is_warping_x = false;
1184 static bool is_warping_y = false;
1185
1186 int32_t x_new = x_screen;
1187 int32_t y_new = y_screen;
1188 int32_t x_accum, y_accum;
1189
1190 /* Warp within bounds. */
1191 {
1192 GHOST_Rect bounds;
1193 if (window->getCursorGrabBounds(bounds) == GHOST_kFailure) {
1194 /* Use custom grab bounds if available, window bounds if not. */
1195 window->getClientBounds(bounds);
1196 }
1197
1198 /* WARNING(@ideasman42): The current warping logic fails to warp on every event,
1199 * so the box needs to small enough not to let the cursor escape the window but large
1200 * enough that the cursor isn't being warped every time. If this was not the case it
1201 * would be less trouble to simply warp the cursor to the center of the screen on
1202 * every motion, see: D16558 (alternative fix for #102346). */
1203
1204 /* Rather than adjust the bounds, use a margin based on the bounds width. */
1205 int32_t bounds_margin = (window->getCursorGrabMode() == GHOST_kGrabHide) ?
1206 bounds.getWidth() / 10 :
1207 2;
1208 GHOST_TAxisFlag bounds_axis = window->getCursorGrabAxis();
1209
1210 /* Could also clamp to screen bounds wrap with a window outside the view will
1211 * fail at the moment. Use inset in case the window is at screen bounds. */
1212 bounds.wrapPoint(x_new, y_new, bounds_margin, bounds_axis);
1213 }
1214
1215 window->getCursorGrabAccum(x_accum, y_accum);
1216 if (x_new != x_screen || y_new != y_screen) {
1217 system->setCursorPosition(x_new, y_new); /* wrap */
1218
1219 /* Do not update the accum values if we are an outdated or failed pos-warp event. */
1220 if (!is_warping_x) {
1221 is_warping_x = x_new != x_screen;
1222 if (is_warping_x) {
1223 x_accum += (x_screen - x_new);
1224 }
1225 }
1226
1227 if (!is_warping_y) {
1228 is_warping_y = y_new != y_screen;
1229 if (is_warping_y) {
1230 y_accum += (y_screen - y_new);
1231 }
1232 }
1233 window->setCursorGrabAccum(x_accum, y_accum);
1234
1235 /* When wrapping we don't need to add an event because the setCursorPosition call will cause
1236 * a new event after. */
1237 return nullptr;
1238 }
1239
1240 is_warping_x = false;
1241 is_warping_y = false;
1242 x_screen += x_accum;
1243 y_screen += y_accum;
1244 }
1245
1246 return std::make_unique<GHOST_EventCursor>(getMessageTime(system),
1248 window,
1249 x_screen,
1250 y_screen,
1251 GHOST_TABLET_DATA_NONE);
1252}
1253
1255 WPARAM wParam,
1256 LPARAM /*lParam*/)
1257{
1259
1260 int acc = system->wheel_delta_accum_vertical_;
1261 int delta = GET_WHEEL_DELTA_WPARAM(wParam);
1262
1263 if (acc * delta < 0) {
1264 /* Scroll direction reversed. */
1265 acc = 0;
1266 }
1267 acc += delta;
1268 int direction = (acc >= 0) ? 1 : -1;
1269 acc = abs(acc);
1270
1271 while (acc >= WHEEL_DELTA) {
1272 system->pushEvent(std::make_unique<GHOST_EventWheel>(
1273 getMessageTime(system), window, GHOST_kEventWheelAxisVertical, direction));
1274 acc -= WHEEL_DELTA;
1275 }
1276 system->wheel_delta_accum_vertical_ = acc * direction;
1277}
1278
1281 WPARAM wParam,
1282 LPARAM /*lParam*/)
1283{
1285
1286 int acc = system->wheel_delta_accum_horizontal_;
1287 int delta = GET_WHEEL_DELTA_WPARAM(wParam);
1288
1289 if (acc * delta < 0) {
1290 /* Scroll direction reversed. */
1291 acc = 0;
1292 }
1293 acc += delta;
1294 int direction = (acc >= 0) ? 1 : -1;
1295 acc = abs(acc);
1296
1297 while (acc >= WHEEL_DELTA) {
1298 system->pushEvent(std::make_unique<GHOST_EventWheel>(
1299 getMessageTime(system), window, GHOST_kEventWheelAxisHorizontal, direction));
1300 acc -= WHEEL_DELTA;
1301 }
1302 system->wheel_delta_accum_horizontal_ = acc * direction;
1303}
1304
1305std::unique_ptr<GHOST_EventKey> GHOST_SystemWin32::processKeyEvent(GHOST_WindowWin32 *window,
1306 RAWINPUT const &raw)
1307{
1308 const char vk = raw.data.keyboard.VKey;
1309 bool key_down = false;
1311 GHOST_TKey key = system->hardKey(raw, &key_down);
1312 std::unique_ptr<GHOST_EventKey> event;
1313
1314 /* Scan code (device-dependent identifier for the key on the keyboard) for the Alt key.
1315 * https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#scan-codes */
1316 constexpr USHORT ALTGR_MAKE_CODE = 0x38;
1317
1318 /* If the keyboard layout includes AltGr and the virtual key is Control, yet the
1319 * scan-code is actually for Right Alt (ALTGR_MAKE_CODE scan code with E0 prefix).
1320 * Ignore these, so treating AltGR as regular Alt. #68256 */
1321 if (system->has_alt_gr_ && vk == VK_CONTROL && raw.data.keyboard.MakeCode == ALTGR_MAKE_CODE &&
1322 (raw.data.keyboard.Flags & RI_KEY_E0))
1323 {
1324 return nullptr;
1325 }
1326
1327 /* NOTE(@ideasman42): key repeat in WIN32 also applies to modifier-keys.
1328 * Check for this case and filter out modifier-repeat.
1329 * Typically keyboard events are *not* filtered as part of GHOST's event handling.
1330 * As other GHOST back-ends don't have the behavior, it's simplest not to send them through.
1331 * Ideally it would be possible to check the key-map for keys that repeat but this doesn't look
1332 * to be supported. */
1333 bool is_repeat = false;
1334 bool is_repeated_modifier = false;
1335 if (key_down) {
1336 if (HIBYTE(::GetKeyState(vk)) != 0) {
1337 /* This thread's message queue shows this key as already down. */
1338 is_repeat = true;
1339 is_repeated_modifier = GHOST_KEY_MODIFIER_CHECK(key);
1340 }
1341 }
1342
1343 /* We used to check `if (key != GHOST_kKeyUnknown)`, however,
1344 * given the message values `WM_SYSKEYUP`, `WM_KEYUP` and `WM_CHAR` are ignored,
1345 * we capture those events here as well. */
1346 if (!is_repeated_modifier) {
1347 char utf8_char[6] = {0};
1348 BYTE state[256];
1349 const BOOL has_state = GetKeyboardState((PBYTE)state);
1350 const bool ctrl_pressed = has_state && state[VK_CONTROL] & 0x80;
1351 const bool alt_pressed = has_state && state[VK_MENU] & 0x80;
1352 const bool win_pressed = has_state && (state[VK_LWIN] | state[VK_RWIN]) & 0x80;
1353
1354 /* We can be here with !key_down if processing dead keys (diacritics). See #103119. */
1355
1356 /* No text with control key pressed (Alt can be used to insert special characters though!). */
1357 if (ctrl_pressed && !alt_pressed) {
1358 /* Pass. */
1359 }
1360 else if (win_pressed) {
1361 /* Pass. No text if either Win key is pressed. #79702. */
1362 }
1363 /* Don't call #ToUnicodeEx on dead keys as it clears the buffer and so won't allow diacritical
1364 * composition. XXX: we are not checking return of #MapVirtualKeyW for high bit set, which is
1365 * what is supposed to indicate dead keys. But this is working now so approach cautiously. */
1366 else if (MapVirtualKeyW(vk, MAPVK_VK_TO_CHAR) != 0) {
1367 wchar_t utf16[3] = {0};
1368 int r;
1369 /* TODO: #ToUnicodeEx can respond with up to 4 UTF16 chars (only 2 here).
1370 * Could be up to 24 UTF8 bytes. */
1371 if ((r = ToUnicodeEx(
1372 vk, raw.data.keyboard.MakeCode, state, utf16, 2, 0, system->keylayout_)))
1373 {
1374 if ((r > 0 && r < 3)) {
1375 utf16[r] = 0;
1376 conv_utf_16_to_8(utf16, utf8_char, 6);
1377 }
1378 else if (r == -1) {
1379 utf8_char[0] = '\0';
1380 }
1381 }
1382 if (!key_down) {
1383 /* Clear or wm_event_add_ghostevent will warn of unexpected data on key up. */
1384 utf8_char[0] = '\0';
1385 }
1386 }
1387
1388#ifdef WITH_INPUT_IME
1389 if (key_down && ((utf8_char[0] & 0x80) == 0)) {
1390 const char ascii = utf8_char[0];
1391 if (window->getImeInput()->IsImeKeyEvent(ascii, key)) {
1392 return nullptr;
1393 }
1394 }
1395#endif /* WITH_INPUT_IME */
1396
1397 event = std::make_unique<GHOST_EventKey>(getMessageTime(system),
1399 window,
1400 key,
1401 is_repeat,
1402 utf8_char);
1403
1404#if 0 /* we already get this info via EventPrinter. */
1405 GHOST_PRINTF("%c\n", ascii);
1406#endif
1407 }
1408 else {
1409 event = nullptr;
1410 }
1411
1412 return event;
1413}
1414
1416{
1418 auto sizeEvent = std::make_unique<GHOST_Event>(
1419 getMessageTime(system), GHOST_kEventWindowSize, window);
1420
1421 /* We get WM_SIZE before we fully init. Do not dispatch before we are continuously resizing. */
1422 if (window->in_live_resize_) {
1423 system->pushEvent(std::move(sizeEvent));
1424 system->dispatchEvents();
1425 return nullptr;
1426 }
1427
1428 window->updateHDRInfo();
1429 return sizeEvent;
1430}
1431
1433 GHOST_WindowWin32 *window)
1434{
1436
1437 if (type == GHOST_kEventWindowActivate) {
1438 system->getWindowManager()->setActiveWindow(window);
1439 }
1440 else if (type == GHOST_kEventWindowDeactivate) {
1441 system->getWindowManager()->setWindowInactive(window);
1442 }
1443
1444 return std::make_unique<GHOST_Event>(getMessageTime(system), type, window);
1445}
1446
1447#ifdef WITH_INPUT_IME
1448std::unique_ptr<GHOST_Event> GHOST_SystemWin32::processImeEvent(GHOST_TEventType type,
1449 GHOST_WindowWin32 *window,
1450 const GHOST_TEventImeData *data)
1451{
1453 return std::make_unique<GHOST_EventIME>(getMessageTime(system), type, window, data);
1454}
1455#endif
1456
1458 GHOST_TDragnDropTypes draggedObjectType,
1459 GHOST_WindowWin32 *window,
1460 int mouseX,
1461 int mouseY,
1462 void *data)
1463{
1465 return system->pushEvent(std::make_unique<GHOST_EventDragnDrop>(
1466 getMessageTime(system), eventType, draggedObjectType, window, mouseX, mouseY, data));
1467}
1468
1470{
1472
1473 /* If API is set to WinPointer (Windows Ink), unload Wintab so that trouble drivers don't disable
1474 * Windows Ink. Load Wintab when API is Automatic because decision logic relies on knowing
1475 * whether a Wintab device is present. */
1476 const bool loadWintab = GHOST_kTabletWinPointer != api;
1478
1479 for (GHOST_IWindow *win : wm->getWindows()) {
1480 GHOST_WindowWin32 *windowWin32 = (GHOST_WindowWin32 *)win;
1481 if (loadWintab) {
1482 windowWin32->loadWintab(GHOST_kWindowStateMinimized != windowWin32->getState());
1483
1484 if (windowWin32->usingTabletAPI(GHOST_kTabletWintab)) {
1485 windowWin32->resetPointerPenInfo();
1486 }
1487 }
1488 else {
1489 windowWin32->closeWintab();
1490 }
1491 }
1492}
1493
1499
1501{
1502 minmax->ptMinTrackSize.x = 320;
1503 minmax->ptMinTrackSize.y = 240;
1504}
1505
1506#ifdef WITH_INPUT_NDOF
1507bool GHOST_SystemWin32::processNDOF(RAWINPUT const &raw)
1508{
1509 bool eventSent = false;
1510 uint64_t now = getMilliSeconds();
1511
1512 RID_DEVICE_INFO info;
1513 unsigned infoSize = sizeof(RID_DEVICE_INFO);
1514 info.cbSize = infoSize;
1515
1516 GetRawInputDeviceInfo(raw.header.hDevice, RIDI_DEVICEINFO, &info, &infoSize);
1517 /* Since there can be multiple NDOF devices connected, always set the current device. */
1518 if (info.dwType == RIM_TYPEHID) {
1519 ndof_manager_->setDevice(info.hid.dwVendorId, info.hid.dwProductId);
1520 }
1521 else {
1522 GHOST_PRINT("<!> not a HID device... mouse/kb perhaps?\n");
1523 }
1524
1525 /* The NDOF manager sends button changes immediately, and *pretends* to
1526 * send motion. Mark as 'sent' so motion will always get dispatched. */
1527 eventSent = true;
1528
1529 BYTE const *data = raw.data.hid.bRawData;
1530
1531 BYTE packetType = data[0];
1532 switch (packetType) {
1533 case 0x1: { /* Translation. */
1534 const short *axis = (short *)(data + 1);
1535 /* Massage into blender view coords (same goes for rotation). */
1536 const int t[3] = {axis[0], -axis[2], axis[1]};
1537 ndof_manager_->updateTranslation(t, now);
1538
1539 if (raw.data.hid.dwSizeHid == 13) {
1540 /* This report also includes rotation. */
1541 const int r[3] = {-axis[3], axis[5], -axis[4]};
1542 ndof_manager_->updateRotation(r, now);
1543
1544 /* I've never gotten one of these, has anyone else? */
1545 GHOST_PRINT("ndof: combined T + R\n");
1546 }
1547 break;
1548 }
1549 case 0x2: { /* Rotation. */
1550
1551 const short *axis = (short *)(data + 1);
1552 const int r[3] = {-axis[0], axis[2], -axis[1]};
1553 ndof_manager_->updateRotation(r, now);
1554 break;
1555 }
1556 case 0x3: { /* Buttons bitmask (older devices). */
1557 int button_bits;
1558 memcpy(&button_bits, data + 1, sizeof(button_bits));
1559 ndof_manager_->updateButtonsBitmask(button_bits, now);
1560 break;
1561 }
1562 case 0x1c: { /* Buttons numbers (newer devices). */
1563 NDOF_Button_Array buttons;
1564 const uint16_t *payload = reinterpret_cast<const uint16_t *>(data + 1);
1565 for (int i = 0; i < buttons.size(); i++) {
1566 buttons[i] = static_cast<GHOST_NDOF_ButtonT>(*(payload + i));
1567 }
1568 ndof_manager_->updateButtonsArray(buttons, now, NDOF_Button_Type::ShortButton);
1569 break;
1570 }
1571 case 0x1d: { /* Buttons (long press, newer devices). */
1572 NDOF_Button_Array buttons;
1573 const uint16_t *payload = reinterpret_cast<const uint16_t *>(data + 1);
1574 for (int i = 0; i < buttons.size(); i++) {
1575 buttons[i] = translateLongButtonToNDOFButton(*(payload + i));
1576 }
1577 ndof_manager_->updateButtonsArray(buttons, now, NDOF_Button_Type::LongButton);
1578 break;
1579 }
1580 }
1581 return eventSent;
1582}
1583#endif /* WITH_INPUT_NDOF */
1584
1586{
1587 GHOST_WindowWin32 *active_window = static_cast<GHOST_WindowWin32 *>(
1589 if (active_window) {
1590 active_window->updateDirectManipulation();
1591 }
1592}
1593
1595{
1596 GHOST_WindowWin32 *active_window = static_cast<GHOST_WindowWin32 *>(
1598
1599 if (!active_window) {
1600 return;
1601 }
1602
1603 GHOST_TTrackpadInfo trackpad_info = active_window->getTrackpadInfo();
1605
1606 int32_t cursor_x, cursor_y;
1607 system->getCursorPosition(cursor_x, cursor_y);
1608
1609 if (trackpad_info.x != 0 || trackpad_info.y != 0) {
1610 system->pushEvent(
1611 std::make_unique<GHOST_EventTrackpad>(getMessageTime(system),
1612 active_window,
1614 cursor_x,
1615 cursor_y,
1616 trackpad_info.x,
1617 trackpad_info.y,
1618 trackpad_info.isScrollDirectionInverted));
1619 }
1620 if (trackpad_info.scale != 0) {
1621 system->pushEvent(std::make_unique<GHOST_EventTrackpad>(getMessageTime(system),
1622 active_window,
1624 cursor_x,
1625 cursor_y,
1626 trackpad_info.scale,
1627 0,
1628 false));
1629 }
1630}
1631
1632LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, uint msg, WPARAM wParam, LPARAM lParam)
1633{
1634 std::unique_ptr<GHOST_Event> event = nullptr;
1635 bool eventHandled = false;
1636
1637 LRESULT lResult = 0;
1639#ifdef WITH_INPUT_IME
1640 GHOST_EventManager *eventManager = system->getEventManager();
1641#endif
1642 GHOST_ASSERT(system, "GHOST_SystemWin32::s_wndProc(): system not initialized");
1643
1644 if (hwnd) {
1645
1646 if (msg == WM_NCCREATE) {
1647 /* Tell Windows to automatically handle scaling of non-client areas
1648 * such as the caption bar. #EnableNonClientDpiScaling was introduced in Windows 10. */
1649 HMODULE user32_ = ::LoadLibrary("User32.dll");
1650 if (user32_) {
1651 GHOST_WIN32_EnableNonClientDpiScaling fpEnableNonClientDpiScaling =
1652 (GHOST_WIN32_EnableNonClientDpiScaling)::GetProcAddress(user32_,
1653 "EnableNonClientDpiScaling");
1654 if (fpEnableNonClientDpiScaling) {
1655 fpEnableNonClientDpiScaling(hwnd);
1656 }
1657 }
1658 }
1659
1660 GHOST_WindowWin32 *window = (GHOST_WindowWin32 *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
1661 if (window) {
1662 switch (msg) {
1663 /* We need to check if new key layout has AltGr. */
1664 case WM_INPUTLANGCHANGE: {
1665 system->handleKeyboardChange();
1666#ifdef WITH_INPUT_IME
1667 window->getImeInput()->UpdateInputLanguage();
1668 window->getImeInput()->UpdateConversionStatus(hwnd);
1669#endif
1670 break;
1671 }
1672 /* ==========================
1673 * Keyboard events, processed
1674 * ========================== */
1675 case WM_INPUT: {
1676 RAWINPUT raw;
1677 RAWINPUT *raw_ptr = &raw;
1678 uint rawSize = sizeof(RAWINPUT);
1679
1680 GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw_ptr, &rawSize, sizeof(RAWINPUTHEADER));
1681
1682 switch (raw.header.dwType) {
1683 case RIM_TYPEKEYBOARD: {
1684 event = processKeyEvent(window, raw);
1685 if (!event) {
1686 GHOST_PRINT("GHOST_SystemWin32::wndProc: key event ");
1687 GHOST_PRINT(msg);
1688 GHOST_PRINT(" key ignored\n");
1689 }
1690 break;
1691 }
1692#ifdef WITH_INPUT_NDOF
1693 case RIM_TYPEHID: {
1694 if (system->processNDOF(raw)) {
1695 eventHandled = true;
1696 }
1697 break;
1698 }
1699#endif
1700 }
1701 break;
1702 }
1703#ifdef WITH_INPUT_IME
1704 /* =================================================
1705 * IME events, processed, read more in `GHOST_IME.h`
1706 * ================================================= */
1707 case WM_IME_NOTIFY: {
1708 /* Update conversion status when IME is changed or input mode is changed. */
1709 if (wParam == IMN_SETOPENSTATUS || wParam == IMN_SETCONVERSIONMODE) {
1710 window->getImeInput()->UpdateConversionStatus(hwnd);
1711 }
1712 break;
1713 }
1714 case WM_IME_SETCONTEXT: {
1715 GHOST_ImeWin32 *ime = window->getImeInput();
1716 ime->UpdateInputLanguage();
1717 ime->UpdateConversionStatus(hwnd);
1718 ime->CreateImeWindow(hwnd);
1719 ime->CleanupComposition(hwnd);
1720 ime->CheckFirst(hwnd);
1721 break;
1722 }
1723 case WM_IME_STARTCOMPOSITION: {
1724 GHOST_ImeWin32 *ime = window->getImeInput();
1725 eventHandled = true;
1726 ime->CreateImeWindow(hwnd);
1727 ime->ResetComposition(hwnd);
1728 event = processImeEvent(GHOST_kEventImeCompositionStart, window, &ime->eventImeData);
1729 break;
1730 }
1731 case WM_IME_COMPOSITION: {
1732 GHOST_ImeWin32 *ime = window->getImeInput();
1733 eventHandled = true;
1734 ime->UpdateImeWindow(hwnd);
1735 ime->UpdateInfo(hwnd);
1736 if (ime->eventImeData.result.size()) {
1737 /* remove redundant IME event */
1738 eventManager->removeTypeEvents(GHOST_kEventImeComposition, window);
1739 }
1740 event = processImeEvent(GHOST_kEventImeComposition, window, &ime->eventImeData);
1741 break;
1742 }
1743 case WM_IME_ENDCOMPOSITION: {
1744 GHOST_ImeWin32 *ime = window->getImeInput();
1745 eventHandled = true;
1746 /* remove input event after end comp event, avoid redundant input */
1747 eventManager->removeTypeEvents(GHOST_kEventKeyDown, window);
1748 ime->ResetComposition(hwnd);
1749 ime->DestroyImeWindow(hwnd);
1750 event = processImeEvent(GHOST_kEventImeCompositionEnd, window, &ime->eventImeData);
1751 break;
1752 }
1753#endif /* WITH_INPUT_IME */
1754 /* ========================
1755 * Keyboard events, ignored
1756 * ======================== */
1757 case WM_KEYDOWN:
1758 case WM_SYSKEYDOWN:
1759 case WM_KEYUP:
1760 case WM_SYSKEYUP:
1761 /* These functions were replaced by #WM_INPUT. */
1762 case WM_CHAR:
1763 /* The #WM_CHAR message is posted to the window with the keyboard focus when
1764 * a WM_KEYDOWN message is translated by the #TranslateMessage function.
1765 * WM_CHAR contains the character code of the key that was pressed. */
1766 case WM_DEADCHAR:
1767 /* The #WM_DEADCHAR message is posted to the window with the keyboard focus when a
1768 * WM_KEYUP message is translated by the #TranslateMessage function. WM_DEADCHAR
1769 * specifies a character code generated by a dead key. A dead key is a key that
1770 * generates a character, such as the umlaut (double-dot), that is combined with
1771 * another character to form a composite character. For example, the umlaut-O
1772 * character (Ö) is generated by typing the dead key for the umlaut character, and
1773 * then typing the O key. */
1774 break;
1775 case WM_SYSDEADCHAR:
1776 /* The #WM_SYSDEADCHAR message is sent to the window with the keyboard focus when
1777 * a WM_SYSKEYDOWN message is translated by the #TranslateMessage function.
1778 * WM_SYSDEADCHAR specifies the character code of a system dead key - that is,
1779 * a dead key that is pressed while holding down the alt key. */
1780 case WM_SYSCHAR: {
1781 /* #The WM_SYSCHAR message is sent to the window with the keyboard focus when
1782 * a WM_SYSCHAR message is translated by the #TranslateMessage function.
1783 * WM_SYSCHAR specifies the character code of a dead key - that is,
1784 * a dead key that is pressed while holding down the alt key.
1785 * To prevent the sound, #DefWindowProc must be avoided by return. */
1786 break;
1787 }
1788 case WM_SYSCOMMAND: {
1789 /* The #WM_SYSCOMMAND message is sent to the window when system commands such as
1790 * maximize, minimize or close the window are triggered. Also it is sent when ALT
1791 * button is press for menu. To prevent this we must return preventing #DefWindowProc.
1792 *
1793 * Note that the four low-order bits of the wParam parameter are used internally by the
1794 * OS. To obtain the correct result when testing the value of wParam, an application must
1795 * combine the value 0xFFF0 with the wParam value by using the bit-wise AND operator. */
1796 switch (wParam & 0xFFF0) {
1797 case SC_KEYMENU: {
1798 eventHandled = true;
1799 break;
1800 }
1801 case SC_RESTORE: {
1802 ::ShowWindow(hwnd, SW_RESTORE);
1803 window->setState(window->getState());
1804
1805 GHOST_Wintab *wt = window->getWintab();
1806 if (wt) {
1807 wt->enable();
1808 }
1809
1810 eventHandled = true;
1811 break;
1812 }
1813 case SC_MAXIMIZE: {
1814 GHOST_Wintab *wt = window->getWintab();
1815 if (wt) {
1816 wt->enable();
1817 }
1818 /* Don't report event as handled so that default handling occurs. */
1819 break;
1820 }
1821 case SC_MINIMIZE: {
1822 GHOST_Wintab *wt = window->getWintab();
1823 if (wt) {
1824 wt->disable();
1825 }
1826 /* Don't report event as handled so that default handling occurs. */
1827 break;
1828 }
1829 }
1830 break;
1831 }
1832 /* ========================
1833 * Wintab events, processed
1834 * ======================== */
1835 case WT_CSRCHANGE: {
1836 WINTAB_PRINTF("HWND %p HCTX %p WT_CSRCHANGE\n", window->getHWND(), (void *)lParam);
1837 GHOST_Wintab *wt = window->getWintab();
1838 if (wt) {
1839 wt->updateCursorInfo();
1840 }
1841 eventHandled = true;
1842 break;
1843 }
1844 case WT_PROXIMITY: {
1845 WINTAB_PRINTF("HWND %p HCTX %p WT_PROXIMITY\n", window->getHWND(), (void *)wParam);
1846 if (LOWORD(lParam)) {
1847 WINTAB_PRINTF(" Cursor entering context.\n");
1848 }
1849 else {
1850 WINTAB_PRINTF(" Cursor leaving context.\n");
1851 }
1852 if (HIWORD(lParam)) {
1853 WINTAB_PRINTF(" Cursor entering or leaving hardware proximity.\n");
1854 }
1855 else {
1856 WINTAB_PRINTF(" Cursor neither entering nor leaving hardware proximity.\n");
1857 }
1858
1859 GHOST_Wintab *wt = window->getWintab();
1860 if (wt) {
1861 bool inRange = LOWORD(lParam);
1862 if (inRange) {
1863 /* Some devices don't emit WT_CSRCHANGE events, so update cursor info here. */
1864 wt->updateCursorInfo();
1865 }
1866 else {
1867 wt->leaveRange();
1868 }
1869 }
1870 eventHandled = true;
1871 break;
1872 }
1873 case WT_INFOCHANGE: {
1874 WINTAB_PRINTF("HWND %p HCTX %p WT_INFOCHANGE\n", window->getHWND(), (void *)wParam);
1875 GHOST_Wintab *wt = window->getWintab();
1876 if (wt) {
1877 wt->processInfoChange(lParam);
1878
1879 if (window->usingTabletAPI(GHOST_kTabletWintab)) {
1880 window->resetPointerPenInfo();
1881 }
1882 }
1883 eventHandled = true;
1884 break;
1885 }
1886 case WT_PACKET: {
1887 processWintabEvent(window);
1888 eventHandled = true;
1889 break;
1890 }
1891 /* ====================
1892 * Wintab events, debug
1893 * ==================== */
1894 case WT_CTXOPEN: {
1895 WINTAB_PRINTF("HWND %p HCTX %p WT_CTXOPEN\n", window->getHWND(), (void *)wParam);
1896 break;
1897 }
1898 case WT_CTXCLOSE: {
1899 WINTAB_PRINTF("HWND %p HCTX %p WT_CTXCLOSE\n", window->getHWND(), (void *)wParam);
1900 break;
1901 }
1902 case WT_CTXUPDATE: {
1903 WINTAB_PRINTF("HWND %p HCTX %p WT_CTXUPDATE\n", window->getHWND(), (void *)wParam);
1904 break;
1905 }
1906 case WT_CTXOVERLAP: {
1907 WINTAB_PRINTF("HWND %p HCTX %p WT_CTXOVERLAP", window->getHWND(), (void *)wParam);
1908 switch (lParam) {
1909 case CXS_DISABLED: {
1910 WINTAB_PRINTF(" CXS_DISABLED\n");
1911 break;
1912 }
1913 case CXS_OBSCURED: {
1914 WINTAB_PRINTF(" CXS_OBSCURED\n");
1915 break;
1916 }
1917 case CXS_ONTOP: {
1918 WINTAB_PRINTF(" CXS_ONTOP\n");
1919 break;
1920 }
1921 }
1922 break;
1923 }
1924 /* =========================
1925 * Pointer events, processed
1926 * ========================= */
1927 case WM_POINTERUPDATE:
1928 case WM_POINTERDOWN:
1929 case WM_POINTERUP: {
1930 processPointerEvent(msg, window, wParam, lParam, eventHandled);
1931 break;
1932 }
1933 case WM_POINTERLEAVE: {
1934 uint32_t pointerId = GET_POINTERID_WPARAM(wParam);
1935 POINTER_INFO pointerInfo;
1936 if (!GetPointerInfo(pointerId, &pointerInfo)) {
1937 break;
1938 }
1939
1940 /* Reset pointer pen info if pen device has left tracking range. */
1941 if (pointerInfo.pointerType == PT_PEN) {
1942 window->resetPointerPenInfo();
1943 eventHandled = true;
1944 }
1945 break;
1946 }
1947 /* =======================
1948 * Mouse events, processed
1949 * ======================= */
1950 case WM_LBUTTONDOWN: {
1952 break;
1953 }
1954 case WM_MBUTTONDOWN: {
1956 break;
1957 }
1958 case WM_RBUTTONDOWN: {
1960 break;
1961 }
1962 case WM_XBUTTONDOWN: {
1963 if (short(HIWORD(wParam)) == XBUTTON1) {
1965 }
1966 else if (short(HIWORD(wParam)) == XBUTTON2) {
1968 }
1969 break;
1970 }
1971 case WM_LBUTTONUP: {
1973 break;
1974 }
1975 case WM_MBUTTONUP: {
1977 break;
1978 }
1979 case WM_RBUTTONUP: {
1981 break;
1982 }
1983 case WM_XBUTTONUP: {
1984 if (short(HIWORD(wParam)) == XBUTTON1) {
1986 }
1987 else if (short(HIWORD(wParam)) == XBUTTON2) {
1989 }
1990 break;
1991 }
1992 case WM_MOUSEMOVE: {
1993 if (!window->mouse_present_) {
1994 WINTAB_PRINTF("HWND %p mouse enter\n", window->getHWND());
1995 TRACKMOUSEEVENT tme = {sizeof(tme)};
1996 /* Request WM_MOUSELEAVE message when the cursor leaves the client area. */
1997 tme.dwFlags = TME_LEAVE;
1998 if (system->auto_focus_) {
1999 /* Request WM_MOUSEHOVER message after 100ms when in the client area. */
2000 tme.dwFlags |= TME_HOVER;
2001 tme.dwHoverTime = 100;
2002 }
2003 tme.hwndTrack = hwnd;
2004 TrackMouseEvent(&tme);
2005 window->mouse_present_ = true;
2006 GHOST_Wintab *wt = window->getWintab();
2007 if (wt) {
2008 wt->gainFocus();
2009 }
2010 }
2011
2012 const int32_t window_co[2] = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
2013 int32_t screen_co[2];
2014 window->clientToScreen(UNPACK2(window_co), UNPACK2(screen_co));
2015 event = processCursorEvent(window, screen_co);
2016
2017 break;
2018 }
2019 case WM_MOUSEHOVER: {
2020 /* Mouse Tracking is now off. TrackMouseEvent restarts in MouseMove. */
2021 window->mouse_present_ = false;
2022
2023 /* Auto-focus only occurs within Blender windows, not with _other_ applications. We are
2024 * notified of change of focus from our console, but it returns null from GetFocus. */
2025 HWND old_hwnd = ::GetFocus();
2026 if (old_hwnd && hwnd != old_hwnd) {
2027 HWND new_parent = ::GetParent(hwnd);
2028 HWND old_parent = ::GetParent(old_hwnd);
2029 if (hwnd == old_parent || old_hwnd == new_parent) {
2030 /* Child to its parent, parent to its child. */
2031 ::SetFocus(hwnd);
2032 }
2033 else if (new_parent != HWND_DESKTOP && new_parent == old_parent) {
2034 /* Between siblings of same parent. */
2035 ::SetFocus(hwnd);
2036 }
2037 else if (!new_parent && !old_parent) {
2038 /* Between main windows that don't overlap. */
2039 RECT new_rect, old_rect, dest_rect;
2040
2041 /* The rects without the outside shadows and slightly inset. */
2042 DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &new_rect, sizeof(RECT));
2043 ::InflateRect(&new_rect, -1, -1);
2044 DwmGetWindowAttribute(
2045 old_hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &old_rect, sizeof(RECT));
2046 ::InflateRect(&old_rect, -1, -1);
2047
2048 if (!IntersectRect(&dest_rect, &new_rect, &old_rect)) {
2049 ::SetFocus(hwnd);
2050 }
2051 }
2052 }
2053 break;
2054 }
2055 case WM_MOUSEWHEEL: {
2056 /* The WM_MOUSEWHEEL message is sent to the focus window
2057 * when the mouse wheel is rotated. The DefWindowProc
2058 * function propagates the message to the window's parent.
2059 * There should be no internal forwarding of the message,
2060 * since DefWindowProc propagates it up the parent chain
2061 * until it finds a window that processes it.
2062 */
2063 processWheelEventVertical(window, wParam, lParam);
2064 eventHandled = true;
2065#ifdef BROKEN_PEEK_TOUCHPAD
2066 PostMessage(hwnd, WM_USER, 0, 0);
2067#endif
2068 break;
2069 }
2070 case WM_MOUSEHWHEEL: {
2071 processWheelEventHorizontal(window, wParam, lParam);
2072 eventHandled = true;
2073 break;
2074 }
2075 case WM_SETCURSOR: {
2076 /* The WM_SETCURSOR message is sent to a window if the mouse causes the cursor
2077 * to move within a window and mouse input is not captured.
2078 * This means we have to set the cursor shape every time the mouse moves!
2079 * The DefWindowProc function uses this message to set the cursor to an
2080 * arrow if it is not in the client area.
2081 */
2082 if (LOWORD(lParam) == HTCLIENT) {
2083 /* Load the current cursor. */
2084 window->loadCursor(window->getCursorVisibility(), window->getCursorShape());
2085 /* Bypass call to #DefWindowProc. */
2086 return 0;
2087 }
2088 else {
2089 /* Outside of client area show standard cursor. */
2091 }
2092 break;
2093 }
2094 case WM_MOUSELEAVE: {
2095 WINTAB_PRINTF("HWND %p mouse leave\n", window->getHWND());
2096 window->mouse_present_ = false;
2097 if (window->getTabletData().Active == GHOST_kTabletModeNone) {
2098 /* FIXME: document why the cursor motion event on mouse leave is needed. */
2099 int32_t screen_co[2] = {0, 0};
2100 system->getCursorPosition(screen_co[0], screen_co[1]);
2101 event = processCursorEvent(window, screen_co);
2102 }
2103 GHOST_Wintab *wt = window->getWintab();
2104 if (wt) {
2105 wt->loseFocus();
2106 }
2107 break;
2108 }
2109 /* =====================
2110 * Mouse events, ignored
2111 * ===================== */
2112 case WM_NCMOUSEMOVE: {
2113 /* The WM_NCMOUSEMOVE message is posted to a window when the cursor is moved
2114 * within the non-client area of the window. This message is posted to the window that
2115 * contains the cursor. If a window has captured the mouse, this message is not posted.
2116 */
2117 }
2118 case WM_NCHITTEST: {
2119 /* The WM_NCHITTEST message is sent to a window when the cursor moves, or
2120 * when a mouse button is pressed or released. If the mouse is not captured,
2121 * the message is sent to the window beneath the cursor. Otherwise, the message
2122 * is sent to the window that has captured the mouse.
2123 */
2124 break;
2125 }
2126 /* ========================
2127 * Window events, processed
2128 * ======================== */
2129 case WM_CLOSE: {
2130 /* The WM_CLOSE message is sent as a signal that a window
2131 * or an application should terminate. Restore if minimized. */
2132 if (IsIconic(hwnd)) {
2133 ShowWindow(hwnd, SW_RESTORE);
2134 }
2136 break;
2137 }
2138 case WM_ACTIVATE: {
2139 /* The WM_ACTIVATE message is sent to both the window being activated and the window
2140 * being deactivated. If the windows use the same input queue, the message is sent
2141 * synchronously, first to the window procedure of the top-level window being
2142 * deactivated, then to the window procedure of the top-level window being activated.
2143 * If the windows use different input queues, the message is sent asynchronously,
2144 * so the window is activated immediately. */
2145
2146 system->wheel_delta_accum_vertical_ = 0;
2148 event = processWindowEvent(
2149 LOWORD(wParam) ? GHOST_kEventWindowActivate : GHOST_kEventWindowDeactivate, window);
2150 /* WARNING: Let DefWindowProc handle WM_ACTIVATE, otherwise WM_MOUSEWHEEL
2151 * will not be dispatched to OUR active window if we minimize one of OUR windows. */
2152 if (LOWORD(wParam) == WA_INACTIVE) {
2153 window->lostMouseCapture();
2154 }
2155 else {
2156 window->updateHDRInfo();
2157 }
2158
2159 lResult = ::DefWindowProc(hwnd, msg, wParam, lParam);
2160 break;
2161 }
2162 case WM_ENTERSIZEMOVE: {
2163 /* The WM_ENTERSIZEMOVE message is sent one time to a window after it enters the moving
2164 * or sizing modal loop. The window enters the moving or sizing modal loop when the user
2165 * clicks the window's title bar or sizing border, or when the window passes the
2166 * WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the
2167 * message specifies the SC_MOVE or SC_SIZE value. The operation is complete when
2168 * DefWindowProc returns.
2169 */
2170 window->in_live_resize_ = 1;
2171 break;
2172 }
2173 case WM_EXITSIZEMOVE: {
2174 window->in_live_resize_ = 0;
2175 window->updateHDRInfo();
2176 break;
2177 }
2178 case WM_PAINT: {
2179 /* An application sends the WM_PAINT message when the system or another application
2180 * makes a request to paint a portion of an application's window. The message is sent
2181 * when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage
2182 * function when the application obtains a WM_PAINT message by using the GetMessage or
2183 * PeekMessage function.
2184 */
2185 if (!window->in_live_resize_) {
2187 ::ValidateRect(hwnd, nullptr);
2188 }
2189 else {
2190 eventHandled = true;
2191 }
2192 break;
2193 }
2194 case WM_GETMINMAXINFO: {
2195 /* The WM_GETMINMAXINFO message is sent to a window when the size or
2196 * position of the window is about to change. An application can use
2197 * this message to override the window's default maximized size and
2198 * position, or its default minimum or maximum tracking size.
2199 */
2200 processMinMaxInfo((MINMAXINFO *)lParam);
2201 /* Let DefWindowProc handle it. */
2202 break;
2203 }
2204 case WM_SIZING: {
2205 event = processWindowSizeEvent(window);
2206 break;
2207 }
2208 case WM_SIZE: {
2209 /* The WM_SIZE message is sent to a window after its size has changed.
2210 * The WM_SIZE and WM_MOVE messages are not sent if an application handles the
2211 * WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient
2212 * to perform any move or size change processing during the WM_WINDOWPOSCHANGED
2213 * message without calling DefWindowProc.
2214 */
2215 event = processWindowSizeEvent(window);
2216 break;
2217 }
2218 case WM_CAPTURECHANGED: {
2219 window->lostMouseCapture();
2220 break;
2221 }
2222 case WM_MOVING:
2223 /* The WM_MOVING message is sent to a window that the user is moving. By processing
2224 * this message, an application can monitor the size and position of the drag rectangle
2225 * and, if needed, change its size or position.
2226 */
2227 case WM_MOVE: {
2228 /* The WM_SIZE and WM_MOVE messages are not sent if an application handles the
2229 * WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient
2230 * to perform any move or size change processing during the WM_WINDOWPOSCHANGED
2231 * message without calling DefWindowProc.
2232 */
2233 /* See #WM_SIZE comment. */
2234 if (window->in_live_resize_) {
2236 system->dispatchEvents();
2237 }
2238 else {
2240 window->updateHDRInfo();
2241 }
2242
2243 break;
2244 }
2245 case WM_DPICHANGED: {
2246 /* The WM_DPICHANGED message is sent when the effective dots per inch (dpi) for a
2247 * window has changed. The DPI is the scale factor for a window. There are multiple
2248 * events that can cause the DPI to change such as when the window is moved to a monitor
2249 * with a different DPI. */
2250
2251 /* The suggested new size and position of the window. */
2252 RECT *const suggestedWindowRect = (RECT *)lParam;
2253
2254 /* Push DPI change event first. */
2256 system->dispatchEvents();
2257 eventHandled = true;
2258
2259 /* Then move and resize window. */
2260 SetWindowPos(hwnd,
2261 nullptr,
2262 suggestedWindowRect->left,
2263 suggestedWindowRect->top,
2264 suggestedWindowRect->right - suggestedWindowRect->left,
2265 suggestedWindowRect->bottom - suggestedWindowRect->top,
2266 SWP_NOZORDER | SWP_NOACTIVATE);
2267
2268 window->updateDPI();
2269 break;
2270 }
2271 case WM_DISPLAYCHANGE: {
2272 GHOST_Wintab *wt = window->getWintab();
2273 if (wt) {
2274 wt->remapCoordinates();
2275 }
2276 window->updateHDRInfo();
2277 break;
2278 }
2279 case WM_KILLFOCUS: {
2280 /* The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard
2281 * focus. We want to prevent this if a window is still active and it loses focus to
2282 * nowhere. */
2283 if (!wParam && hwnd == ::GetActiveWindow()) {
2284 ::SetFocus(hwnd);
2285 }
2286 break;
2287 }
2288 case WM_SETTINGCHANGE: {
2289 /* Microsoft: "Note that some applications send this message with lParam set to nullptr"
2290 */
2291 if (((void *)lParam != nullptr) && (wcscmp(LPCWSTR(lParam), L"ImmersiveColorSet") == 0))
2292 {
2293 window->ThemeRefresh();
2294 }
2295 window->updateHDRInfo();
2296 break;
2297 }
2298 /* ======================
2299 * Window events, ignored
2300 * ====================== */
2301 case WM_WINDOWPOSCHANGED:
2302 /* The WM_WINDOWPOSCHANGED message is sent to a window whose size, position, or place
2303 * in the Z order has changed as a result of a call to the SetWindowPos function or
2304 * another window-management function.
2305 * The WM_SIZE and WM_MOVE messages are not sent if an application handles the
2306 * WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient
2307 * to perform any move or size change processing during the WM_WINDOWPOSCHANGED
2308 * message without calling DefWindowProc.
2309 */
2310 case WM_ERASEBKGND:
2311 /* An application sends the WM_ERASEBKGND message when the window background must be
2312 * erased (for example, when a window is resized). The message is sent to prepare an
2313 * invalidated portion of a window for painting. */
2314 {
2315 HBRUSH bgBrush = (HBRUSH)GetClassLongPtr(hwnd, GCLP_HBRBACKGROUND);
2316 if (bgBrush) {
2317 RECT rect;
2318 GetClientRect(hwnd, &rect);
2319 FillRect((HDC)(wParam), &rect, bgBrush);
2320 /* Clear the background brush after the initial fill as we don't
2321 * need or want any default Windows fill behavior on redraw. */
2322 SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND, (LONG_PTR) nullptr);
2323 }
2324 break;
2325 }
2326 case WM_NCPAINT:
2327 /* An application sends the WM_NCPAINT message to a window
2328 * when its frame must be painted. */
2329 case WM_NCACTIVATE:
2330 /* The WM_NCACTIVATE message is sent to a window when its non-client area needs to be
2331 * changed to indicate an active or inactive state. */
2332 case WM_DESTROY:
2333 /* The WM_DESTROY message is sent when a window is being destroyed. It is sent to the
2334 * window procedure of the window being destroyed after the window is removed from the
2335 * screen. This message is sent first to the window being destroyed and then to the child
2336 * windows (if any) as they are destroyed. During the processing of the message, it can
2337 * be assumed that all child windows still exist. */
2338 case WM_NCDESTROY: {
2339 /* The WM_NCDESTROY message informs a window that its non-client area is being
2340 * destroyed. The DestroyWindow function sends the WM_NCDESTROY message to the window
2341 * following the WM_DESTROY message. WM_DESTROY is used to free the allocated memory
2342 * object associated with the window.
2343 */
2344 break;
2345 }
2346 case WM_SHOWWINDOW:
2347 /* The WM_SHOWWINDOW message is sent to a window when the window is
2348 * about to be hidden or shown. */
2349 case WM_WINDOWPOSCHANGING:
2350 /* The WM_WINDOWPOSCHANGING message is sent to a window whose size, position, or place in
2351 * the Z order is about to change as a result of a call to the SetWindowPos function or
2352 * another window-management function. */
2353 case WM_SETFOCUS: {
2354 /* The WM_SETFOCUS message is sent to a window after it has gained the keyboard focus. */
2355 window->updateHDRInfo();
2356 break;
2357 }
2358 /* ============
2359 * Other events
2360 * ============ */
2361 case WM_GETTEXT:
2362 /* An application sends a WM_GETTEXT message to copy the text that
2363 * corresponds to a window into a buffer provided by the caller. */
2364 case WM_ACTIVATEAPP:
2365 /* The WM_ACTIVATEAPP message is sent when a window belonging to a
2366 * different application than the active window is about to be activated.
2367 * The message is sent to the application whose window is being activated
2368 * and to the application whose window is being deactivated. */
2369 case WM_TIMER: {
2370 /* The WIN32 docs say:
2371 * The WM_TIMER message is posted to the installing thread's message queue
2372 * when a timer expires. You can process the message by providing a WM_TIMER
2373 * case in the window procedure. Otherwise, the default window procedure will
2374 * call the TimerProc callback function specified in the call to the SetTimer
2375 * function used to install the timer.
2376 *
2377 * In GHOST, we let DefWindowProc call the timer callback. */
2378 break;
2379 }
2380 case DM_POINTERHITTEST: {
2381 /* The DM_POINTERHITTEST message is sent to a window, when pointer input is first
2382 * detected, in order to determine the most probable input target for Direct
2383 * Manipulation. */
2384 if (system->multitouch_gestures_) {
2385 window->onPointerHitTest(wParam);
2386 }
2387 break;
2388 }
2389 }
2390 }
2391 else {
2392 /* Event found for a window before the pointer to the class has been set. */
2393 GHOST_PRINT("GHOST_SystemWin32::wndProc: GHOST window event before creation\n");
2394 /* These are events we typically miss at this point:
2395 * WM_GETMINMAXINFO 0x24
2396 * WM_NCCREATE 0x81
2397 * WM_NCCALCSIZE 0x83
2398 * WM_CREATE 0x01
2399 * We let DefWindowProc do the work.
2400 */
2401 }
2402 }
2403 else {
2404 /* Events without valid `hwnd`. */
2405 GHOST_PRINT("GHOST_SystemWin32::wndProc: event without window\n");
2406 }
2407
2408 if (event) {
2409 system->pushEvent(std::move(event));
2410 eventHandled = true;
2411 }
2412
2413 if (!eventHandled) {
2414 lResult = ::DefWindowProcW(hwnd, msg, wParam, lParam);
2415 }
2416
2417 return lResult;
2418}
2419
2420char *GHOST_SystemWin32::getClipboard(bool /*selection*/) const
2421{
2422 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(nullptr)) {
2423 wchar_t *buffer;
2424 HANDLE hData = GetClipboardData(CF_UNICODETEXT);
2425 if (hData == nullptr) {
2426 CloseClipboard();
2427 return nullptr;
2428 }
2429 buffer = (wchar_t *)GlobalLock(hData);
2430 if (!buffer) {
2431 CloseClipboard();
2432 return nullptr;
2433 }
2434
2435 char *temp_buff = alloc_utf_8_from_16(buffer, 0);
2436
2437 /* Buffer mustn't be accessed after CloseClipboard
2438 * it would like accessing free-d memory */
2439 GlobalUnlock(hData);
2440 CloseClipboard();
2441
2442 return temp_buff;
2443 }
2444 if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(nullptr)) {
2445 char *buffer;
2446 size_t len = 0;
2447 HANDLE hData = GetClipboardData(CF_TEXT);
2448 if (hData == nullptr) {
2449 CloseClipboard();
2450 return nullptr;
2451 }
2452 buffer = (char *)GlobalLock(hData);
2453 if (!buffer) {
2454 CloseClipboard();
2455 return nullptr;
2456 }
2457
2458 len = strlen(buffer);
2459 char *temp_buff = (char *)malloc(len + 1);
2460 memcpy(temp_buff, buffer, len + 1);
2461
2462 /* Buffer mustn't be accessed after CloseClipboard
2463 * it would like accessing free-d memory */
2464 GlobalUnlock(hData);
2465 CloseClipboard();
2466
2467 return temp_buff;
2468 }
2469 return nullptr;
2470}
2471
2472void GHOST_SystemWin32::putClipboard(const char *buffer, bool selection) const
2473{
2474 if (selection || !buffer) {
2475 return;
2476 } /* For copying the selection, used on X11. */
2477
2478 if (OpenClipboard(nullptr)) {
2479 EmptyClipboard();
2480
2481 /* Get length of buffer including the terminating null. */
2482 size_t len = count_utf_16_from_8(buffer);
2483
2484 HGLOBAL clipbuffer = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * len);
2485 if (clipbuffer) {
2486 wchar_t *data = (wchar_t *)GlobalLock(clipbuffer);
2487
2488 conv_utf_8_to_16(buffer, data, len);
2489
2490 GlobalUnlock(clipbuffer);
2491 SetClipboardData(CF_UNICODETEXT, clipbuffer);
2492 }
2493
2494 CloseClipboard();
2495 }
2496}
2497
2499{
2500 if (IsClipboardFormatAvailable(CF_DIBV5) ||
2501 IsClipboardFormatAvailable(RegisterClipboardFormat("PNG")))
2502 {
2503 return GHOST_kSuccess;
2504 }
2505
2506 /* This could be a file path to an image file. */
2508 if (IsClipboardFormatAvailable(CF_HDROP)) {
2509 if (OpenClipboard(nullptr)) {
2510 if (HANDLE hGlobal = GetClipboardData(CF_HDROP)) {
2511 if (HDROP hDrop = static_cast<HDROP>(GlobalLock(hGlobal))) {
2512 UINT fileCount = DragQueryFile(hDrop, 0xffffffff, nullptr, 0);
2513 if (fileCount == 1) {
2514 WCHAR lpszFile[MAX_PATH] = {0};
2515 DragQueryFileW(hDrop, 0, lpszFile, MAX_PATH);
2516 char *filepath = alloc_utf_8_from_16(lpszFile, 0);
2518 filepath,
2521 free(filepath);
2522 if (ibuf) {
2524 result = GHOST_kSuccess;
2525 }
2526 }
2527 GlobalUnlock(hGlobal);
2528 }
2529 }
2530 CloseClipboard();
2531 }
2532 }
2533 return result;
2534}
2535
2536static uint *getClipboardImageFilepath(int *r_width, int *r_height)
2537{
2538 char *filepath = nullptr;
2539
2540 if (OpenClipboard(nullptr)) {
2541 if (HANDLE hGlobal = GetClipboardData(CF_HDROP)) {
2542 if (HDROP hDrop = static_cast<HDROP>(GlobalLock(hGlobal))) {
2543 UINT fileCount = DragQueryFile(hDrop, 0xffffffff, nullptr, 0);
2544 if (fileCount == 1) {
2545 WCHAR lpszFile[MAX_PATH] = {0};
2546 DragQueryFileW(hDrop, 0, lpszFile, MAX_PATH);
2547 filepath = alloc_utf_8_from_16(lpszFile, 0);
2548 }
2549 GlobalUnlock(hGlobal);
2550 }
2551 }
2552 CloseClipboard();
2553 }
2554
2555 if (filepath) {
2558 free(filepath);
2559 if (ibuf) {
2560 *r_width = ibuf->x;
2561 *r_height = ibuf->y;
2562 const uint64_t byte_count = static_cast<uint64_t>(ibuf->x) * ibuf->y * 4;
2563 uint *rgba = static_cast<uint *>(malloc(byte_count));
2564 if (rgba) {
2565 memcpy(rgba, ibuf->byte_data(), byte_count);
2566 }
2568 return rgba;
2569 }
2570 }
2571
2572 return nullptr;
2573}
2574
2575static uint *getClipboardImageDibV5(int *r_width, int *r_height)
2576{
2577 HANDLE hGlobal = GetClipboardData(CF_DIBV5);
2578 if (hGlobal == nullptr) {
2579 return nullptr;
2580 }
2581
2582 BITMAPV5HEADER *bitmapV5Header = (BITMAPV5HEADER *)GlobalLock(hGlobal);
2583 if (bitmapV5Header == nullptr) {
2584 return nullptr;
2585 }
2586
2587 int offset = bitmapV5Header->bV5Size + bitmapV5Header->bV5ClrUsed * sizeof(RGBQUAD);
2588
2589 BYTE *buffer = (BYTE *)bitmapV5Header + offset;
2590 int bitcount = bitmapV5Header->bV5BitCount;
2591 int width = bitmapV5Header->bV5Width;
2592 int height = bitmapV5Header->bV5Height;
2593
2594 /* Clipboard data is untrusted. Protect against arithmetic overflow as DibV5
2595 * only supports up to DWORD size bytes. */
2596 if (uint64_t(width) * uint64_t(height) > (std::numeric_limits<DWORD>::max() / 4)) {
2597 GlobalUnlock(hGlobal);
2598 return nullptr;
2599 }
2600
2601 *r_width = width;
2602 *r_height = height;
2603
2604 uchar *source = (uchar *)buffer;
2605 uint *rgba = (uint *)malloc(uint64_t(width) * height * 4);
2606 uint8_t *target = (uint8_t *)rgba;
2607
2608 if (bitmapV5Header->bV5Compression == BI_BITFIELDS && bitcount == 32) {
2609 /* It is unclear from the MSDN documentation whether or not the 3 RGB mask values are always
2610 * written as part of the main BITMAPV5HEADER header or if they are included after the
2611 * structure. In reality there are applications (Windows Snipping Tool) that write both,
2612 * and there are applications (Krita, Paint.NET) that only set the header values. Handle
2613 * both by checking against our expected size. */
2614 const SIZE_T mask_size = sizeof(DWORD) * 3;
2615 const SIZE_T actual_size = GlobalSize(hGlobal);
2616 const SIZE_T expected_size = offset + (SIZE_T(width) * height * 4);
2617 if (expected_size == actual_size - mask_size) {
2618 source += mask_size; /* Skip redundant color masks. */
2619 }
2620
2621 DWORD ColorMasks[4];
2622 ColorMasks[0] = bitmapV5Header->bV5RedMask ? bitmapV5Header->bV5RedMask : 0xff;
2623 ColorMasks[1] = bitmapV5Header->bV5GreenMask ? bitmapV5Header->bV5GreenMask : 0xff00;
2624 ColorMasks[2] = bitmapV5Header->bV5BlueMask ? bitmapV5Header->bV5BlueMask : 0xff0000;
2625 ColorMasks[3] = bitmapV5Header->bV5AlphaMask ? bitmapV5Header->bV5AlphaMask : 0xff000000;
2626
2627 /* Bit shifts needed for the ColorMasks. */
2628 DWORD ColorShifts[4];
2629 for (int i = 0; i < 4; i++) {
2630 _BitScanForward(&ColorShifts[i], ColorMasks[i]);
2631 }
2632
2633 for (int h = 0; h < height; h++) {
2634 for (int w = 0; w < width; w++, target += 4, source += 4) {
2635 const DWORD *pix = (DWORD *)source;
2636 target[0] = uint8_t((*pix & ColorMasks[0]) >> ColorShifts[0]);
2637 target[1] = uint8_t((*pix & ColorMasks[1]) >> ColorShifts[1]);
2638 target[2] = uint8_t((*pix & ColorMasks[2]) >> ColorShifts[2]);
2639 target[3] = uint8_t((*pix & ColorMasks[3]) >> ColorShifts[3]);
2640 }
2641 }
2642 }
2643 else if (bitmapV5Header->bV5Compression == BI_RGB && bitcount == 32) {
2644 for (int h = 0; h < height; h++) {
2645 for (int w = 0; w < width; w++, target += 4, source += 4) {
2646 const RGBQUAD *quad = (RGBQUAD *)source;
2647 target[0] = uint8_t(quad->rgbRed);
2648 target[1] = uint8_t(quad->rgbGreen);
2649 target[2] = uint8_t(quad->rgbBlue);
2650 target[3] = (bitmapV5Header->bV5AlphaMask) ? uint8_t(quad->rgbReserved) : 255;
2651 }
2652 }
2653 }
2654 else if (bitmapV5Header->bV5Compression == BI_RGB && bitcount == 24) {
2655 int bytes_per_row = ((((width * bitcount) + 31) & ~31) >> 3);
2656 int slack = bytes_per_row - (width * 3);
2657 for (int h = 0; h < height; h++, source += slack) {
2658 for (int w = 0; w < width; w++, target += 4, source += 3) {
2659 const RGBTRIPLE *triple = (RGBTRIPLE *)source;
2660 target[0] = uint8_t(triple->rgbtRed);
2661 target[1] = uint8_t(triple->rgbtGreen);
2662 target[2] = uint8_t(triple->rgbtBlue);
2663 target[3] = 255;
2664 }
2665 }
2666 }
2667
2668 GlobalUnlock(hGlobal);
2669 return rgba;
2670}
2671
2672/* Works with any image format that ImBuf can load. */
2673static uint *getClipboardImageImBuf(int *r_width, int *r_height, UINT format)
2674{
2675 HANDLE hGlobal = GetClipboardData(format);
2676 if (hGlobal == nullptr) {
2677 return nullptr;
2678 }
2679
2680 LPVOID pMem = GlobalLock(hGlobal);
2681 if (!pMem) {
2682 return nullptr;
2683 }
2684
2685 uint *rgba = nullptr;
2686
2688 (uchar *)pMem, GlobalSize(hGlobal), blender::ImBufFlags::ByteData, "<clipboard>");
2689
2690 if (ibuf) {
2691 *r_width = ibuf->x;
2692 *r_height = ibuf->y;
2693 const uint64_t byte_count = uint64_t(ibuf->x) * ibuf->y * 4;
2694 rgba = (uint *)malloc(byte_count);
2695 memcpy(rgba, ibuf->byte_data(), byte_count);
2697 }
2698
2699 GlobalUnlock(hGlobal);
2700 return rgba;
2701}
2702
2703uint *GHOST_SystemWin32::getClipboardImage(int *r_width, int *r_height) const
2704{
2705 if (IsClipboardFormatAvailable(CF_HDROP)) {
2706 return getClipboardImageFilepath(r_width, r_height);
2707 }
2708
2709 if (!OpenClipboard(nullptr)) {
2710 return nullptr;
2711 }
2712
2713 /* Synthesized formats are placed after posted formats. */
2714 UINT cfPNG = RegisterClipboardFormat("PNG");
2715 UINT format = 0;
2716 for (int cf = EnumClipboardFormats(0); cf; cf = EnumClipboardFormats(cf)) {
2717 if (ELEM(cf, CF_DIBV5, cfPNG)) {
2718 format = cf;
2719 }
2720 if (cf == CF_DIBV5 || (cf == CF_BITMAP && format == cfPNG)) {
2721 break; /* Favor CF_DIBV5, but not if synthesized. */
2722 }
2723 }
2724
2725 uint *rgba = nullptr;
2726
2727 if (format == CF_DIBV5) {
2728 rgba = getClipboardImageDibV5(r_width, r_height);
2729 }
2730 else if (format == cfPNG) {
2731 rgba = getClipboardImageImBuf(r_width, r_height, cfPNG);
2732 }
2733 else {
2734 *r_width = 0;
2735 *r_height = 0;
2736 }
2737
2738 CloseClipboard();
2739 return rgba;
2740}
2741
2742static bool putClipboardImageDibV5(uint *rgba, int width, int height)
2743{
2744 /* DibV5 only supports up to DWORD size bytes. Skip processing entirely
2745 * in case of overflow but return true to the caller to allow PNG to be
2746 * used on its own. */
2747 if (uint64_t(width) * uint64_t(height) > (std::numeric_limits<DWORD>::max() / 4)) {
2748 return true;
2749 }
2750
2751 DWORD size_pixels = width * height * 4;
2752
2753 HGLOBAL hMem = GlobalAlloc(GHND, sizeof(BITMAPV5HEADER) + size_pixels);
2754 if (!hMem) {
2755 return false;
2756 }
2757
2758 BITMAPV5HEADER *hdr = (BITMAPV5HEADER *)GlobalLock(hMem);
2759 if (!hdr) {
2760 GlobalFree(hMem);
2761 return false;
2762 }
2763
2764 hdr->bV5Size = sizeof(BITMAPV5HEADER);
2765 hdr->bV5Width = width;
2766 hdr->bV5Height = height;
2767 hdr->bV5Planes = 1;
2768 hdr->bV5BitCount = 32;
2769 hdr->bV5SizeImage = size_pixels;
2770 hdr->bV5Compression = BI_BITFIELDS;
2771 hdr->bV5RedMask = 0x000000ff;
2772 hdr->bV5GreenMask = 0x0000ff00;
2773 hdr->bV5BlueMask = 0x00ff0000;
2774 hdr->bV5AlphaMask = 0xff000000;
2775 hdr->bV5CSType = LCS_sRGB;
2776 hdr->bV5Intent = LCS_GM_IMAGES;
2777 hdr->bV5ClrUsed = 0;
2778
2779 memcpy((char *)hdr + sizeof(BITMAPV5HEADER), rgba, size_pixels);
2780
2781 GlobalUnlock(hMem);
2782
2783 if (!SetClipboardData(CF_DIBV5, hMem)) {
2784 GlobalFree(hMem);
2785 return false;
2786 }
2787
2788 return true;
2789}
2790
2791static bool putClipboardImagePNG(uint *rgba, int width, int height)
2792{
2793 UINT cf = RegisterClipboardFormat("PNG");
2794
2795 /* Load buffer into ImBuf, convert to PNG. */
2797 reinterpret_cast<uint8_t *>(rgba), nullptr, width, height, 32);
2799 ibuf->foptions.quality = 15;
2802 if (encoded.is_empty()) {
2804 return false;
2805 }
2806
2807 HGLOBAL hMem = GlobalAlloc(GHND, encoded.size());
2808 if (!hMem) {
2810 return false;
2811 }
2812
2813 LPVOID pMem = GlobalLock(hMem);
2814 if (!pMem) {
2816 GlobalFree(hMem);
2817 return false;
2818 }
2819
2820 memcpy(pMem, encoded.data(), encoded.size());
2821
2822 GlobalUnlock(hMem);
2824
2825 if (!SetClipboardData(cf, hMem)) {
2826 GlobalFree(hMem);
2827 return false;
2828 }
2829
2830 return true;
2831}
2832
2833GHOST_TSuccess GHOST_SystemWin32::putClipboardImage(uint *rgba, int width, int height) const
2834{
2835 if (!OpenClipboard(nullptr) || !EmptyClipboard()) {
2836 return GHOST_kFailure;
2837 }
2838
2839 bool ok = putClipboardImageDibV5(rgba, width, height) &&
2840 putClipboardImagePNG(rgba, width, height);
2841
2842 CloseClipboard();
2843
2844 return (ok) ? GHOST_kSuccess : GHOST_kFailure;
2845}
2846
2847/* -------------------------------------------------------------------- */
2850
2852 const char *message,
2853 const char *help_label,
2854 const char *continue_label,
2855 const char *link,
2856 GHOST_DialogOptions dialog_options) const
2857{
2858 const wchar_t *title_16 = alloc_utf16_from_8(title, 0);
2859 const wchar_t *message_16 = alloc_utf16_from_8(message, 0);
2860 const wchar_t *help_label_16 = alloc_utf16_from_8(help_label, 0);
2861 const wchar_t *continue_label_16 = alloc_utf16_from_8(continue_label, 0);
2862
2863 int nButtonPressed = 0;
2864 TASKDIALOGCONFIG config = {0};
2865 const TASKDIALOG_BUTTON buttons[] = {{IDOK, help_label_16}, {IDCONTINUE, continue_label_16}};
2866
2867 config.cbSize = sizeof(config);
2868 config.hInstance = 0;
2869 config.dwCommonButtons = 0;
2870 config.pszMainIcon = (dialog_options & GHOST_DialogError ? TD_ERROR_ICON :
2871 dialog_options & GHOST_DialogWarning ? TD_WARNING_ICON :
2872 TD_INFORMATION_ICON);
2873 config.pszWindowTitle = L"Blender";
2874 config.pszMainInstruction = title_16;
2875 config.pszContent = message_16;
2876 const bool has_link = link && strlen(link);
2877 config.pButtons = has_link ? buttons : buttons + 1;
2878 config.cButtons = has_link ? 2 : 1;
2879
2880 TaskDialogIndirect(&config, &nButtonPressed, nullptr, nullptr);
2881 switch (nButtonPressed) {
2882 case IDOK:
2883 ShellExecute(nullptr, "open", link, nullptr, nullptr, SW_SHOWNORMAL);
2884 break;
2885 case IDCONTINUE:
2886 break;
2887 default:
2888 break; /* Should never happen. */
2889 }
2890
2891 free((void *)title_16);
2892 free((void *)message_16);
2893 free((void *)help_label_16);
2894 free((void *)continue_label_16);
2895
2896 return GHOST_kSuccess;
2897}
2898
2900
2901static DWORD GetParentProcessID(void)
2902{
2903 HANDLE snapshot;
2904 PROCESSENTRY32 pe32 = {0};
2905 DWORD ppid = 0, pid = GetCurrentProcessId();
2906 snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
2907 if (snapshot == INVALID_HANDLE_VALUE) {
2908 return -1;
2909 }
2910 pe32.dwSize = sizeof(pe32);
2911 if (!Process32First(snapshot, &pe32)) {
2912 CloseHandle(snapshot);
2913 return -1;
2914 }
2915 do {
2916 if (pe32.th32ProcessID == pid) {
2917 ppid = pe32.th32ParentProcessID;
2918 break;
2919 }
2920 } while (Process32Next(snapshot, &pe32));
2921 CloseHandle(snapshot);
2922 return ppid;
2923}
2924
2925static bool getProcessName(int pid, char *buffer, int max_len)
2926{
2927 bool result = false;
2928 HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
2929 if (handle) {
2930 GetModuleFileNameEx(handle, 0, buffer, max_len);
2931 result = true;
2932 }
2933 CloseHandle(handle);
2934 return result;
2935}
2936
2938{
2939 HWND hwnd = GetConsoleWindow();
2940
2941 if (hwnd) {
2942 DWORD pid = (DWORD)-1;
2943 DWORD ppid = GetParentProcessID();
2944 char parent_name[MAX_PATH];
2945 bool start_from_launcher = false;
2946
2947 GetWindowThreadProcessId(hwnd, &pid);
2948 if (getProcessName(ppid, parent_name, sizeof(parent_name))) {
2949 char *filename = strrchr(parent_name, '\\');
2950 if (filename != nullptr) {
2951 start_from_launcher = strstr(filename, "blender.exe") != nullptr;
2952 }
2953 }
2954
2955 /* When we're starting from a wrapper we need to compare with parent process ID. */
2956 if (pid != (start_from_launcher ? ppid : GetCurrentProcessId())) {
2957 return true;
2958 }
2959 }
2960
2961 return false;
2962}
2963
2965{
2966 HWND wnd = GetConsoleWindow();
2967
2968 switch (action) {
2971 ShowWindow(wnd, SW_HIDE);
2972 console_status_ = false;
2973 }
2974 break;
2975 }
2977 ShowWindow(wnd, SW_HIDE);
2978 console_status_ = false;
2979 break;
2980 }
2982 ShowWindow(wnd, SW_SHOW);
2984 DeleteMenu(GetSystemMenu(wnd, FALSE), SC_CLOSE, MF_BYCOMMAND);
2985 }
2986 console_status_ = true;
2987 break;
2988 }
2990 ShowWindow(wnd, console_status_ ? SW_HIDE : SW_SHOW);
2993 DeleteMenu(GetSystemMenu(wnd, FALSE), SC_CLOSE, MF_BYCOMMAND);
2994 }
2995 break;
2996 }
2997 }
2998
2999 return console_status_;
3000}
#define UINT32_MAX
#define GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY
#define GHOST_PRINTF(x,...)
#define GHOST_ASSERT(x, info)
#define GHOST_PRINT(x)
std::array< GHOST_NDOF_ButtonT, 6 > NDOF_Button_Array
@ ShortButton
@ LongButton
#define VK_EQUALS
static uint * getClipboardImageFilepath(int *r_width, int *r_height)
static void initRawInput()
static bool putClipboardImageDibV5(uint *rgba, int width, int height)
#define DEVICE_COUNT
#define VK_BACK_QUOTE
static uint * getClipboardImageImBuf(int *r_width, int *r_height, UINT format)
static const std::map< uint16_t, GHOST_NDOF_ButtonT > longButtonHIDsToGHOST_NDOFButtons
#define VK_CLOSE_BRACKET
static GHOST_NDOF_ButtonT translateLongButtonToNDOFButton(uint16_t longKey)
#define VK_SEMICOLON
#define VK_COMMA
#define VK_SLASH
static bool isStartedFromCommandPrompt()
#define VK_OPEN_BRACKET
BOOL(API *) GHOST_WIN32_EnableNonClientDpiScaling(HWND)
static uint * getClipboardImageDibV5(int *r_width, int *r_height)
static bool putClipboardImagePNG(uint *rgba, int width, int height)
#define VK_BACK_SLASH
#define VK_GR_LESS
#define VK_PERIOD
static uint64_t getMessageTime(GHOST_SystemWin32 *system)
static DWORD GetParentProcessID(void)
static bool getProcessName(int pid, char *buffer, int max_len)
#define VK_MINUS
@ GHOST_kEventWheelAxisVertical
@ GHOST_kEventWheelAxisHorizontal
@ GHOST_kTrackpadEventMagnify
@ GHOST_kTrackpadEventScroll
GHOST_TWindowState
@ GHOST_kWindowStateMinimized
@ GHOST_kStandardCursorDefault
GHOST_NDOF_ButtonT
@ GHOST_NDOF_BUTTON_TILT_CCW
@ GHOST_NDOF_BUTTON_SAVE_V1
@ GHOST_NDOF_BUTTON_ROLL_CCW
@ GHOST_NDOF_BUTTON_BACK
@ GHOST_NDOF_BUTTON_ISO2
@ GHOST_NDOF_BUTTON_SPIN_CCW
@ GHOST_NDOF_BUTTON_SAVE_V3
@ GHOST_NDOF_BUTTON_SAVE_V2
@ GHOST_NDOF_BUTTON_BOTTOM
@ GHOST_NDOF_BUTTON_LEFT
GHOST_TEventType
@ GHOST_kEventWindowClose
@ GHOST_kEventWindowMove
@ GHOST_kEventWindowSize
@ GHOST_kEventImeComposition
@ GHOST_kEventCursorMove
@ GHOST_kEventButtonUp
@ GHOST_kEventWindowActivate
@ GHOST_kEventWindowUpdate
@ GHOST_kEventWindowDeactivate
@ GHOST_kEventButtonDown
@ GHOST_kEventKeyDown
@ GHOST_kEventImeCompositionStart
@ GHOST_kEventImeCompositionEnd
@ GHOST_kEventWindowDPIHintChanged
@ GHOST_kEventKeyUp
@ GHOST_kDebugWintab
#define GHOST_KEY_MODIFIER_CHECK(key)
@ GHOST_kTabletModeNone
GHOST_TCapabilityFlag
@ GHOST_kCapabilityClipboardPrimary
@ GHOST_kCapabilityKeyboardHyperKey
@ GHOST_kCapabilityCursorGenerator
@ GHOST_kCapabilityWindowPath
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS(gpu_settings)
GHOST_TAxisFlag
#define GHOST_CAPABILITY_FLAG_ALL
GHOST_TKey
@ GHOST_kKeyLeftOS
@ GHOST_kKeyInsert
@ GHOST_kKeySemicolon
@ GHOST_kKeyMediaPlay
@ GHOST_kKeyQuote
@ GHOST_kKeyNumpad3
@ GHOST_kKeyAccentGrave
@ GHOST_kKeyNumpad1
@ GHOST_kKeyLeftAlt
@ GHOST_kKeyRightShift
@ GHOST_kKeyNumLock
@ GHOST_kKeyI
@ GHOST_kKeyEnter
@ GHOST_kKeyNumpadSlash
@ GHOST_kKeyRightArrow
@ GHOST_kKeyF13
@ GHOST_kKeyNumpad4
@ GHOST_kKeyPause
@ GHOST_kKeyCapsLock
@ GHOST_kKeyApp
@ GHOST_kKeyMinus
@ GHOST_kKeyMediaStop
@ GHOST_kKeyBackSpace
@ GHOST_kKey0
@ GHOST_kKeyDownPage
@ GHOST_kKeyGrLess
@ GHOST_kKeyDownArrow
@ GHOST_kKeyRightOS
@ GHOST_kKeyNumpadPeriod
@ GHOST_kKeyF1
@ GHOST_kKeyNumpadAsterisk
@ GHOST_kKeyPrintScreen
@ GHOST_kKeyLeftControl
@ GHOST_kKeyLeftBracket
@ GHOST_kKeyTab
@ GHOST_kKeyComma
@ GHOST_kKeyRightBracket
@ GHOST_kKeyBackslash
@ GHOST_kKeyNumpad2
@ GHOST_kKeyRightAlt
@ GHOST_kKeyPeriod
@ GHOST_kKeyNumpadPlus
@ GHOST_kKeyUpPage
@ GHOST_kKeyNumpad5
@ GHOST_kKeyLeftArrow
@ GHOST_kKeyEqual
@ GHOST_kKeyHome
@ GHOST_kKeyNumpad6
@ GHOST_kKeyNumpad8
@ GHOST_kKeyNumpad9
@ GHOST_kKeyEnd
@ GHOST_kKeyUpArrow
@ GHOST_kKeyDelete
@ GHOST_kKeyNumpad0
@ GHOST_kKeyA
@ GHOST_kKeyMediaFirst
@ GHOST_kKeyNumpad7
@ GHOST_kKeyRightControl
@ GHOST_kKeyEsc
@ GHOST_kKeyUnknown
@ GHOST_kKeyScrollLock
@ GHOST_kKeySlash
@ GHOST_kKeyNumpadEnter
@ GHOST_kKeyNumpadMinus
@ GHOST_kKeyLeftShift
@ GHOST_kKeyMediaLast
@ GHOST_kKeySpace
@ GHOST_kModifierKeyRightControl
@ GHOST_kModifierKeyLeftControl
@ GHOST_kModifierKeyRightAlt
@ GHOST_kModifierKeyRightShift
@ GHOST_kModifierKeyLeftAlt
@ GHOST_kModifierKeyLeftShift
@ GHOST_kModifierKeyLeftOS
@ GHOST_kModifierKeyRightOS
GHOST_TSuccess
@ GHOST_kFailure
@ GHOST_kSuccess
@ GHOST_kFireTimeNever
@ GHOST_kGrabHide
#define GHOST_CONTEXT_PARAMS_NONE
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS_OFFSCREEN(gpu_settings)
GHOST_TDragnDropTypes
GHOST_TButton
@ GHOST_kButtonMaskRight
@ GHOST_kButtonMaskButton4
@ GHOST_kButtonMaskLeft
@ GHOST_kButtonMaskButton5
@ GHOST_kButtonMaskMiddle
GHOST_TConsoleWindowState
@ GHOST_kConsoleWindowStateShow
@ GHOST_kConsoleWindowStateHideForNonConsoleLaunch
@ GHOST_kConsoleWindowStateHide
@ GHOST_kConsoleWindowStateToggle
GHOST_TTabletAPI
@ GHOST_kTabletWinPointer
@ GHOST_kTabletWintab
GHOST_DialogOptions
@ GHOST_DialogError
@ GHOST_DialogWarning
#define GET_POINTERID_WPARAM(wParam)
@ MousePressed
@ MouseReleased
#define WINTAB_PRINTF(x,...)
#define USHORT
Definition GeoCommon.h:9
#define UNPACK2(a)
#define ELEM(...)
long long int int64_t
unsigned long long int uint64_t
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
SIMD_FORCE_INLINE btScalar triple(const btVector3 &v1, const btVector3 &v2) const
Definition btVector3.h:419
GHOST_ContextD3D(const GHOST_ContextParams &context_params, HWND hWnd)
GHOST_ContextVK(const GHOST_ContextParams &context_params, GHOST_TVulkanPlatformType platform, Window window, Display *display, wl_surface *wayland_surface, wl_display *wayland_display, const GHOST_ContextVK_WindowInfo *wayland_window_info, int contextMajorVersion, int contextMinorVersion, const GHOST_GPUDevice &preferred_device, const GHOST_WindowHDRInfo *hdr_info_=nullptr)
GHOST_ContextWGL(const GHOST_ContextParams &context_params, bool alphaBackground, HWND hWnd, HDC hDC, int contextProfileMask, int contextMajorVersion, int contextMinorVersion, int contextFlags, int contextResetNotificationStrategy)
void removeTypeEvents(GHOST_TEventType type, const GHOST_IWindow *window=nullptr)
static GHOST_ISystem * getSystem()
GHOST_NDOFManagerWin32(GHOST_System &)
virtual void wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis)
virtual int32_t getWidth() const
GHOST_TKey hardKey(RAWINPUT const &raw, bool *r_key_down)
void setTabletAPI(GHOST_TTabletAPI api) override
GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override
GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_GPUSettings gpu_settings, const bool exclusive=false, const bool is_dialog=false, const GHOST_IWindow *parent_window=nullptr) override
GHOST_TKey processSpecialKey(short vKey, short scanCode) const
GHOST_TKey convertKey(short vKey, short ScanCode, short extend) const
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y) override
GHOST_TSuccess showMessageBox(const char *title, const char *message, const char *help_label, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options) const override
static void processWheelEventHorizontal(GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam)
void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override
static GHOST_ContextD3D * createOffscreenContextD3D()
static GHOST_TSuccess disposeContextD3D(GHOST_ContextD3D *context)
GHOST_TSuccess hasClipboardImage() const override
static void processWintabEvent(GHOST_WindowWin32 *window)
uint64_t performanceCounterToMillis(__int64 perf_ticks) const
static std::unique_ptr< GHOST_EventButton > processButtonEvent(GHOST_TEventType type, GHOST_WindowWin32 *window, GHOST_TButton mask)
uint * getClipboardImage(int *r_width, int *r_height) const override
GHOST_TCapabilityFlag getCapabilities() const override
void initDebug(GHOST_Debug debug) override
char * getClipboard(bool selection) const override
GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const override
uint8_t getNumDisplays() const override
static std::unique_ptr< GHOST_Event > processWindowEvent(GHOST_TEventType type, GHOST_WindowWin32 *window)
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const override
static void processMinMaxInfo(MINMAXINFO *minmax)
static void processWheelEventVertical(GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam)
void putClipboard(const char *buffer, bool selection) const override
static std::unique_ptr< GHOST_EventCursor > processCursorEvent(GHOST_WindowWin32 *window, const int32_t screen_co[2])
uint32_t getCursorPreferredLogicalSize() const override
static std::unique_ptr< GHOST_EventKey > processKeyEvent(GHOST_WindowWin32 *window, RAWINPUT const &raw)
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override
GHOST_TSuccess init() override
bool setConsoleWindowState(GHOST_TConsoleWindowState action) override
GHOST_TSuccess exit() override
bool processEvents(bool waitForEvent) override
static void processPointerEvent(UINT type, GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam, bool &eventhandled)
uint64_t getMilliSeconds() const override
GHOST_IWindow * getWindowUnderCursor(int32_t, int32_t) override
GHOST_TSuccess getPixelAtCursor(float r_color[3]) const override
static LRESULT WINAPI s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
static std::unique_ptr< GHOST_Event > processWindowSizeEvent(GHOST_WindowWin32 *window)
static GHOST_TSuccess pushDragDropEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType, GHOST_WindowWin32 *window, int mouseX, int mouseY, void *data)
GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override
GHOST_TSuccess disposeContext(GHOST_IContext *context) override
GHOST_IContext * createOffscreenContext(GHOST_GPUSettings gpu_settings) override
GHOST_EventManager * getEventManager() const
GHOST_WindowManager * getWindowManager() const
GHOST_WindowManager * window_manager_
GHOST_TSuccess init() override
GHOST_TimerManager * getTimerManager() const
void initDebug(GHOST_Debug debug) override
void setTabletAPI(GHOST_TTabletAPI api) override
GHOST_TSuccess pushEvent(std::unique_ptr< const GHOST_IEvent > event)
bool multitouch_gestures_
GHOST_TSuccess exit() override
GHOST_EventManager * event_manager_
void dispatchEvents() override
bool fireTimers(uint64_t time)
GHOST_TSuccess addWindow(GHOST_IWindow *window)
GHOST_IWindow * getWindowAssociatedWithOSWindow(const void *osWindow)
const std::vector< GHOST_IWindow * > & getWindows() const
GHOST_IWindow * getActiveWindow() const
GHOST_TSuccess setActiveWindow(GHOST_IWindow *window)
void setWindowInactive(const GHOST_IWindow *window)
GHOST_TSuccess setState(GHOST_TWindowState state) override
GHOST_TTrackpadInfo getTrackpadInfo()
bool getValid() const override
void getClientBounds(GHOST_Rect &bounds) const override
void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
bool usingTabletAPI(GHOST_TTabletAPI api) const
GHOST_TSuccess getPointerInfo(std::vector< GHOST_PointerInfoWin32 > &outPointerInfo, WPARAM wParam, LPARAM lParam)
void loadWintab(bool enable)
GHOST_TabletData getTabletData()
GHOST_Wintab * getWintab() const
void updateMouseCapture(GHOST_MouseCaptureEventWin32 event)
GHOST_TWindowState getState() const override
void onPointerHitTest(WPARAM wParam)
GHOST_WindowWin32(GHOST_SystemWin32 *system, const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_TDrawingContextType type, const GHOST_ContextParams &context_params, GHOST_WindowWin32 *parent_window, bool dialog, const GHOST_GPUDevice &preferred_device)
void loadCursor(bool visible, GHOST_TStandardCursor cursor_shape) const
virtual GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds) const
void setCursorGrabAccum(int32_t x, int32_t y)
GHOST_TAxisFlag getCursorGrabAxis() const
GHOST_TStandardCursor getCursorShape() const override
bool getCursorVisibility() const override
GHOST_TGrabCursorMode getCursorGrabMode() const
bool getCursorGrabModeIsWarp() const
void getCursorGrabAccum(int32_t &x, int32_t &y) const
void mapWintabToSysCoordinates(int x_in, int y_in, int &x_out, int &y_out)
GHOST_TabletData getLastTabletData()
void getInput(std::vector< GHOST_WintabInfoWin32 > &outWintabInfo)
void processInfoChange(LPARAM lParam)
void updateCursorInfo()
void remapCoordinates()
bool trustCoordinates()
bool testCoordinates(int sysX, int sysY, int wtX, int wtY)
static void setDebug(bool debug)
int64_t size() const
bool is_empty() const
#define roundf(x)
#define API(returnType)
#define abs
unsigned int uchar
const int state
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
#define L
Vector< uint8_t > IMB_save_image_to_buffer(ImBuf *ibuf, ImBufFlags flags)
Definition writeimage.cc:64
unsigned short uint16_t
Definition BKE_text.h:80
ImBuf * IMB_load_image_from_filepath(const char *filepath, ImBufFlags flags, ColorManagedColorspaceSettings *colorspace_settings=nullptr)
Definition readimage.cc:201
void IMB_freeImBuf(ImBuf *ibuf)
BMesh const char void * data
ImBuf * IMB_load_image_from_memory(const unsigned char *mem, size_t size, ImBufFlags flags, const char *descr, const char *filepath=nullptr, ColorManagedColorspaceSettings *colorspace_settings=nullptr)
Definition readimage.cc:132
ImBuf * IMB_allocFromBuffer(const uint8_t *byte_buffer, const float *float_buffer, unsigned int w, unsigned int h, unsigned int channels)
void set(GHOST_TButton mask, bool down)
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device
void set(GHOST_TModifierKey mask, bool down)
GHOST_TTabletMode Active
ImbFormatOptions foptions
const uint8_t * byte_data() const
eImbFileType ftype
wchar_t * alloc_utf16_from_8(const char *in8, size_t add)
Definition utfconv.cc:294
char * alloc_utf_8_from_16(const wchar_t *in16, size_t add)
Definition utfconv.cc:282
int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16)
Definition utfconv.cc:182
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
Definition utfconv.cc:116
size_t count_utf_16_from_8(const char *string8)
Definition utfconv.cc:58
#define UTF16_ENCODE(in8str)
Definition utfconv.hh:80
#define UTF16_UN_ENCODE(in8str)
Definition utfconv.hh:84