Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / win / window / salframe.cxx
blob8b0a64232927ac4c72d4d4b7fd441cc2979d4500
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
21 #include <com/sun/star/container/XIndexAccess.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/awt/Rectangle.hpp>
24 #include <unotools/misccfg.hxx>
26 #include <officecfg/Office/Common.hxx>
28 #include <memory>
29 #include <string.h>
30 #include <limits.h>
32 #include <svsys.h>
34 #include <comphelper/windowserrorstring.hxx>
36 #include <rtl/string.h>
37 #include <rtl/ustring.h>
39 #include <osl/module.h>
41 #include <tools/debug.hxx>
42 #include <o3tl/enumarray.hxx>
43 #include <o3tl/char16_t2wchar_t.hxx>
45 #include <vcl/sysdata.hxx>
46 #include <vcl/timer.hxx>
47 #include <vcl/settings.hxx>
48 #include <vcl/keycodes.hxx>
49 #include <vcl/window.hxx>
50 #include <vcl/wrkwin.hxx>
51 #include <vcl/svapp.hxx>
53 #include <win/wincomp.hxx>
54 #include <win/salids.hrc>
55 #include <win/saldata.hxx>
56 #include <win/salinst.h>
57 #include <win/salbmp.h>
58 #include <win/salgdi.h>
59 #include <win/salsys.h>
60 #include <win/salframe.h>
61 #include <win/salvd.h>
62 #include <win/salmenu.h>
63 #include <win/salobj.h>
64 #include <win/saltimer.h>
66 #include <helpwin.hxx>
67 #include <window.h>
68 #include <sallayout.hxx>
70 #define COMPILE_MULTIMON_STUBS
71 #pragma warning(push)
72 #pragma warning(disable:4996) // 'GetVersionExA': was declared deprecated
73 #include <multimon.h>
74 #pragma warning(pop)
75 #include <vector>
77 #include <com/sun/star/uno/Exception.hpp>
79 #include <oleacc.h>
80 #include <com/sun/star/accessibility/XMSAAService.hpp>
81 #ifndef WM_GETOBJECT // TESTME does this ever happen ?
82 # define WM_GETOBJECT 0x003D
83 #endif
85 #include <time.h>
87 #if !defined WIN32_LEAN_AND_MEAN
88 # define WIN32_LEAN_AND_MEAN
89 #endif
90 #include <windows.h>
91 #include <shobjidl.h>
92 #include <propkey.h>
93 #include <propvarutil.h>
94 #include <shellapi.h>
96 using namespace ::com::sun::star;
97 using namespace ::com::sun::star::uno;
98 using namespace ::com::sun::star::lang;
99 using namespace ::com::sun::star::container;
100 using namespace ::com::sun::star::beans;
102 #ifndef SPI_GETWHEELSCROLLCHARS
103 # define SPI_GETWHEELSCROLLCHARS 0x006C
104 #endif
105 #ifndef SPI_SETWHEELSCROLLCHARS
106 # define SPI_SETWHEELSCROLLCHARS 0x006D
107 #endif
108 #ifndef WM_MOUSEHWHEEL
109 # define WM_MOUSEHWHEEL 0x020E
110 #endif
111 #ifndef IDC_PEN
112 # define IDC_PEN MAKEINTRESOURCE(32631)
113 #endif
115 const unsigned int WM_USER_SYSTEM_WINDOW_ACTIVATED = RegisterWindowMessageW(L"SYSTEM_WINDOW_ACTIVATED");
117 bool WinSalFrame::mbInReparent = false;
119 // Macros for support of WM_UNICHAR & Keyman 6.0
120 //#define Uni_UTF32ToSurrogate1(ch) (((unsigned long) (ch) - 0x10000) / 0x400 + 0xD800)
121 #define Uni_UTF32ToSurrogate2(ch) ((static_cast<unsigned long>(ch) - 0x10000) % 0x400 + 0xDC00)
122 #define Uni_SupplementaryPlanesStart 0x10000
124 static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame );
125 static void SetMaximizedFrameGeometry( HWND hWnd, WinSalFrame* pFrame, RECT* pParentRect = nullptr );
127 static void ImplSaveFrameState( WinSalFrame* pFrame )
129 // save position, size and state for GetWindowState()
130 if ( !pFrame->mbFullScreen )
132 bool bVisible = (GetWindowStyle( pFrame->mhWnd ) & WS_VISIBLE) != 0;
133 if ( IsIconic( pFrame->mhWnd ) )
135 pFrame->maState.mnState |= WindowStateState::Minimized;
136 if ( bVisible )
137 pFrame->mnShowState = SW_SHOWMAXIMIZED;
139 else if ( IsZoomed( pFrame->mhWnd ) )
141 pFrame->maState.mnState &= ~WindowStateState::Minimized;
142 pFrame->maState.mnState |= WindowStateState::Maximized;
143 if ( bVisible )
144 pFrame->mnShowState = SW_SHOWMAXIMIZED;
145 pFrame->mbRestoreMaximize = true;
147 WINDOWPLACEMENT aPlacement;
148 aPlacement.length = sizeof(aPlacement);
149 if( GetWindowPlacement( pFrame->mhWnd, &aPlacement ) )
151 RECT aRect = aPlacement.rcNormalPosition;
152 RECT aRect2 = aRect;
153 AdjustWindowRectEx( &aRect2, GetWindowStyle( pFrame->mhWnd ),
154 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
155 long nTopDeco = abs( aRect.top - aRect2.top );
156 long nLeftDeco = abs( aRect.left - aRect2.left );
157 long nBottomDeco = abs( aRect.bottom - aRect2.bottom );
158 long nRightDeco = abs( aRect.right - aRect2.right );
160 pFrame->maState.mnX = aRect.left + nLeftDeco;
161 pFrame->maState.mnY = aRect.top + nTopDeco;
162 pFrame->maState.mnWidth = aRect.right - aRect.left - nLeftDeco - nRightDeco;
163 pFrame->maState.mnHeight = aRect.bottom - aRect.top - nTopDeco - nBottomDeco;
166 else
168 RECT aRect;
169 GetWindowRect( pFrame->mhWnd, &aRect );
171 // to be consistent with Unix, the frame state is without(!) decoration
172 RECT aRect2 = aRect;
173 AdjustWindowRectEx( &aRect2, GetWindowStyle( pFrame->mhWnd ),
174 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
175 long nTopDeco = abs( aRect.top - aRect2.top );
176 long nLeftDeco = abs( aRect.left - aRect2.left );
177 long nBottomDeco = abs( aRect.bottom - aRect2.bottom );
178 long nRightDeco = abs( aRect.right - aRect2.right );
180 pFrame->maState.mnState &= ~WindowStateState(WindowStateState::Minimized | WindowStateState::Maximized);
181 // subtract decoration
182 pFrame->maState.mnX = aRect.left+nLeftDeco;
183 pFrame->maState.mnY = aRect.top+nTopDeco;
184 pFrame->maState.mnWidth = aRect.right-aRect.left-nLeftDeco-nRightDeco;
185 pFrame->maState.mnHeight = aRect.bottom-aRect.top-nTopDeco-nBottomDeco;
186 if ( bVisible )
187 pFrame->mnShowState = SW_SHOWNORMAL;
188 pFrame->mbRestoreMaximize = false;
193 // if pParentRect is set, the workarea of the monitor that contains pParentRect is returned
194 void ImplSalGetWorkArea( HWND hWnd, RECT *pRect, const RECT *pParentRect )
196 // check if we or our parent is fullscreen, then the taskbar should be ignored
197 bool bIgnoreTaskbar = false;
198 WinSalFrame* pFrame = GetWindowPtr( hWnd );
199 if( pFrame )
201 vcl::Window *pWin = pFrame->GetWindow();
202 while( pWin )
204 WorkWindow *pWorkWin = (pWin->GetType() == WindowType::WORKWINDOW) ? static_cast<WorkWindow *>(pWin) : nullptr;
205 if( pWorkWin && pWorkWin->ImplGetWindowImpl()->mbReallyVisible && pWorkWin->IsFullScreenMode() )
207 bIgnoreTaskbar = true;
208 break;
210 else
211 pWin = pWin->ImplGetWindowImpl()->mpParent;
215 // calculates the work area taking multiple monitors into account
216 static int nMonitors = GetSystemMetrics( SM_CMONITORS );
217 if( nMonitors == 1 )
219 if( bIgnoreTaskbar )
221 pRect->left = pRect->top = 0;
222 pRect->right = GetSystemMetrics( SM_CXSCREEN );
223 pRect->bottom = GetSystemMetrics( SM_CYSCREEN );
225 else
226 SystemParametersInfoW( SPI_GETWORKAREA, 0, pRect, 0 );
228 else
230 if( pParentRect != nullptr )
232 // return the size of the monitor where pParentRect lives
233 HMONITOR hMonitor;
234 MONITORINFO mi;
236 // get the nearest monitor to the passed rect.
237 hMonitor = MonitorFromRect(pParentRect, MONITOR_DEFAULTTONEAREST);
239 // get the work area or entire monitor rect.
240 mi.cbSize = sizeof(mi);
241 GetMonitorInfo(hMonitor, &mi);
242 if( !bIgnoreTaskbar )
243 *pRect = mi.rcWork;
244 else
245 *pRect = mi.rcMonitor;
247 else
249 // return the union of all monitors
250 pRect->left = GetSystemMetrics( SM_XVIRTUALSCREEN );
251 pRect->top = GetSystemMetrics( SM_YVIRTUALSCREEN );
252 pRect->right = pRect->left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
253 pRect->bottom = pRect->top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
255 // virtualscreen does not take taskbar into account, so use the corresponding
256 // diffs between screen and workarea from the default screen
257 // however, this is still not perfect: the taskbar might not be on the primary screen
258 if( !bIgnoreTaskbar )
260 RECT wRect, scrRect;
261 SystemParametersInfoW( SPI_GETWORKAREA, 0, &wRect, 0 );
262 scrRect.left = 0;
263 scrRect.top = 0;
264 scrRect.right = GetSystemMetrics( SM_CXSCREEN );
265 scrRect.bottom = GetSystemMetrics( SM_CYSCREEN );
267 pRect->left += wRect.left;
268 pRect->top += wRect.top;
269 pRect->right -= scrRect.right - wRect.right;
270 pRect->bottom -= scrRect.bottom - wRect.bottom;
276 SalFrame* ImplSalCreateFrame( WinSalInstance* pInst,
277 HWND hWndParent, SalFrameStyleFlags nSalFrameStyle )
279 WinSalFrame* pFrame = new WinSalFrame;
280 HWND hWnd;
281 DWORD nSysStyle = 0;
282 DWORD nExSysStyle = 0;
283 bool bSubFrame = false;
285 static const char* pEnvSynchronize = getenv("SAL_SYNCHRONIZE");
286 if ( pEnvSynchronize ) // no buffering of drawing commands
287 GdiSetBatchLimit( 1 );
289 static const char* pEnvTransparentFloats = getenv("SAL_TRANSPARENT_FLOATS" );
291 // determine creation data
292 if ( nSalFrameStyle & (SalFrameStyleFlags::PLUG | SalFrameStyleFlags::SYSTEMCHILD) )
294 nSysStyle |= WS_CHILD;
295 if( nSalFrameStyle & SalFrameStyleFlags::SYSTEMCHILD )
296 nSysStyle |= WS_CLIPSIBLINGS;
298 else
300 // #i87402# commenting out WS_CLIPCHILDREN
301 // this breaks SalFrameStyleFlags::SYSTEMCHILD handling, which is not
302 // used currently. Probably SalFrameStyleFlags::SYSTEMCHILD should be
303 // removed again.
305 // nSysStyle |= WS_CLIPCHILDREN;
306 if ( hWndParent )
308 nSysStyle |= WS_POPUP;
309 bSubFrame = true;
310 pFrame->mbNoIcon = true;
312 else
314 // Only with WS_OVRLAPPED we get a useful default position/size
315 if ( (nSalFrameStyle & (SalFrameStyleFlags::SIZEABLE | SalFrameStyleFlags::MOVEABLE)) ==
316 (SalFrameStyleFlags::SIZEABLE | SalFrameStyleFlags::MOVEABLE) )
317 nSysStyle |= WS_OVERLAPPED;
318 else
320 nSysStyle |= WS_POPUP;
321 if ( !(nSalFrameStyle & SalFrameStyleFlags::MOVEABLE) )
322 nExSysStyle |= WS_EX_TOOLWINDOW; // avoid taskbar appearance, for eg splash screen
326 if ( nSalFrameStyle & SalFrameStyleFlags::MOVEABLE )
328 pFrame->mbCaption = true;
329 nSysStyle |= WS_SYSMENU | WS_CAPTION;
330 if ( !hWndParent )
331 nSysStyle |= WS_SYSMENU | WS_MINIMIZEBOX;
332 else
333 nExSysStyle |= WS_EX_DLGMODALFRAME;
335 if ( nSalFrameStyle & SalFrameStyleFlags::SIZEABLE )
337 pFrame->mbSizeBorder = true;
338 nSysStyle |= WS_THICKFRAME;
339 if ( !hWndParent )
340 nSysStyle |= WS_MAXIMIZEBOX;
342 else
343 pFrame->mbFixBorder = true;
345 if ( nSalFrameStyle & SalFrameStyleFlags::DEFAULT )
346 nExSysStyle |= WS_EX_APPWINDOW;
348 if( nSalFrameStyle & SalFrameStyleFlags::TOOLWINDOW
349 // #100656# toolwindows lead to bad alt-tab behaviour, if they have the focus
350 // you must press it twice to leave the application
351 // so toolwindows are only used for non sizeable windows
352 // which are typically small, so a small caption makes sense
354 // #103578# looked too bad - above changes reverted
355 /* && !(nSalFrameStyle & SalFrameStyleFlags::SIZEABLE) */ )
357 pFrame->mbNoIcon = true;
358 nExSysStyle |= WS_EX_TOOLWINDOW;
359 if ( pEnvTransparentFloats /*&& !(nSalFrameStyle & SalFrameStyleFlags::MOVEABLE) */)
360 nExSysStyle |= WS_EX_LAYERED;
363 if ( nSalFrameStyle & SalFrameStyleFlags::FLOAT )
365 nExSysStyle |= WS_EX_TOOLWINDOW;
366 pFrame->mbFloatWin = true;
368 if (pEnvTransparentFloats)
369 nExSysStyle |= WS_EX_LAYERED;
372 if (nSalFrameStyle & SalFrameStyleFlags::TOOLTIP)
373 nExSysStyle |= WS_EX_TOPMOST;
375 // init frame data
376 pFrame->mnStyle = nSalFrameStyle;
378 // determine show style
379 pFrame->mnShowState = SW_SHOWNORMAL;
380 if ( (nSysStyle & (WS_POPUP | WS_MAXIMIZEBOX | WS_THICKFRAME)) == (WS_MAXIMIZEBOX | WS_THICKFRAME) )
382 if ( GetSystemMetrics( SM_CXSCREEN ) <= 1024 )
383 pFrame->mnShowState = SW_SHOWMAXIMIZED;
384 else
386 if ( nSalFrameStyle & SalFrameStyleFlags::DEFAULT )
388 SalData* pSalData = GetSalData();
389 pFrame->mnShowState = pSalData->mnCmdShow;
390 if ( (pFrame->mnShowState != SW_SHOWMINIMIZED) &&
391 (pFrame->mnShowState != SW_MINIMIZE) &&
392 (pFrame->mnShowState != SW_SHOWMINNOACTIVE) )
394 if ( (pFrame->mnShowState == SW_SHOWMAXIMIZED) ||
395 (pFrame->mnShowState == SW_MAXIMIZE) )
396 pFrame->mbOverwriteState = false;
397 pFrame->mnShowState = SW_SHOWMAXIMIZED;
399 else
400 pFrame->mbOverwriteState = false;
402 else
404 // Document Windows are also maximized, if the current Document Window
405 // is also maximized
406 HWND hWnd2 = GetForegroundWindow();
407 if ( hWnd2 && IsMaximized( hWnd2 ) &&
408 (GetWindowInstance( hWnd2 ) == pInst->mhInst) &&
409 ((GetWindowStyle( hWnd2 ) & (WS_POPUP | WS_MAXIMIZEBOX | WS_THICKFRAME)) == (WS_MAXIMIZEBOX | WS_THICKFRAME)) )
410 pFrame->mnShowState = SW_SHOWMAXIMIZED;
415 // create frame
416 LPCWSTR pClassName;
417 if ( bSubFrame )
419 if ( nSalFrameStyle & (SalFrameStyleFlags::MOVEABLE|SalFrameStyleFlags::NOSHADOW) ) // check if shadow not wanted
420 pClassName = SAL_SUBFRAME_CLASSNAMEW;
421 else
422 pClassName = SAL_TMPSUBFRAME_CLASSNAMEW; // undecorated floaters will get shadow on XP
424 else
426 if ( nSalFrameStyle & SalFrameStyleFlags::MOVEABLE )
427 pClassName = SAL_FRAME_CLASSNAMEW;
428 else
429 pClassName = SAL_TMPSUBFRAME_CLASSNAMEW;
431 hWnd = CreateWindowExW( nExSysStyle, pClassName, L"", nSysStyle,
432 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
433 hWndParent, nullptr, pInst->mhInst, pFrame );
434 SAL_WARN_IF(!hWnd, "vcl", "CreateWindowExW failed: " << WindowsErrorString(GetLastError()));
436 #if OSL_DEBUG_LEVEL > 1
437 // set transparency value
438 if( GetWindowExStyle( hWnd ) & WS_EX_LAYERED )
439 SetLayeredWindowAttributes( hWnd, 0, 230, 0x00000002 /*LWA_ALPHA*/ );
440 #endif
441 if ( !hWnd )
443 delete pFrame;
444 return nullptr;
447 // If we have a Window with an Caption Bar and without
448 // an MaximizeBox, we change the SystemMenu
449 if ( (nSysStyle & (WS_CAPTION | WS_MAXIMIZEBOX)) == (WS_CAPTION) )
451 HMENU hSysMenu = GetSystemMenu( hWnd, FALSE );
452 if ( hSysMenu )
454 if ( !(nSysStyle & (WS_MINIMIZEBOX | WS_MAXIMIZEBOX)) )
455 DeleteMenu( hSysMenu, SC_RESTORE, MF_BYCOMMAND );
456 else
457 EnableMenuItem( hSysMenu, SC_RESTORE, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED );
458 if ( !(nSysStyle & WS_MINIMIZEBOX) )
459 DeleteMenu( hSysMenu, SC_MINIMIZE, MF_BYCOMMAND );
460 if ( !(nSysStyle & WS_MAXIMIZEBOX) )
461 DeleteMenu( hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND );
462 if ( !(nSysStyle & WS_THICKFRAME) )
463 DeleteMenu( hSysMenu, SC_SIZE, MF_BYCOMMAND );
466 if ( (nSysStyle & WS_SYSMENU) && !(nSalFrameStyle & SalFrameStyleFlags::CLOSEABLE) )
468 HMENU hSysMenu = GetSystemMenu( hWnd, FALSE );
469 if ( hSysMenu )
470 EnableMenuItem( hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED );
473 // reset input context
474 pFrame->mhDefIMEContext = ImmAssociateContext( hWnd, nullptr );
476 // determine output size and state
477 RECT aRect;
478 GetClientRect( hWnd, &aRect );
479 pFrame->mnWidth = aRect.right;
480 pFrame->mnHeight = aRect.bottom;
481 ImplSaveFrameState( pFrame );
482 pFrame->mbDefPos = true;
484 UpdateFrameGeometry( hWnd, pFrame );
486 if( pFrame->mnShowState == SW_SHOWMAXIMIZED )
488 // #96084 set a useful internal window size because
489 // the window will not be maximized (and the size updated) before show()
491 SetMaximizedFrameGeometry( hWnd, pFrame );
494 return pFrame;
497 // helper that only creates the HWND
498 // to allow for easy reparenting of system windows, (i.e. destroy and create new)
499 HWND ImplSalReCreateHWND( HWND hWndParent, HWND oldhWnd, bool bAsChild )
501 HINSTANCE hInstance = GetSalData()->mhInst;
502 sal_uLong nSysStyle = GetWindowLongW( oldhWnd, GWL_STYLE );
503 sal_uLong nExSysStyle = GetWindowLongW( oldhWnd, GWL_EXSTYLE );
505 if( bAsChild )
507 nSysStyle = WS_CHILD;
508 nExSysStyle = 0;
511 LPCWSTR pClassName = SAL_SUBFRAME_CLASSNAMEW;
512 return CreateWindowExW( nExSysStyle, pClassName, L"", nSysStyle,
513 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
514 hWndParent, nullptr, hInstance, GetWindowPtr( oldhWnd ) );
517 // translation table from System keycodes into StartView keycodes
518 #define KEY_TAB_SIZE 146
520 static const sal_uInt16 aImplTranslateKeyTab[KEY_TAB_SIZE] =
522 // StarView-Code System-Code Index
523 0, // 0
524 0, // VK_LBUTTON 1
525 0, // VK_RBUTTON 2
526 0, // VK_CANCEL 3
527 0, // VK_MBUTTON 4
528 0, // 5
529 0, // 6
530 0, // 7
531 KEY_BACKSPACE, // VK_BACK 8
532 KEY_TAB, // VK_TAB 9
533 0, // 10
534 0, // 11
535 0, // VK_CLEAR 12
536 KEY_RETURN, // VK_RETURN 13
537 0, // 14
538 0, // 15
539 0, // VK_SHIFT 16
540 0, // VK_CONTROL 17
541 0, // VK_MENU 18
542 0, // VK_PAUSE 19
543 0, // VK_CAPITAL 20
544 0, // VK_HANGUL 21
545 0, // 22
546 0, // 23
547 0, // 24
548 KEY_HANGUL_HANJA, // VK_HANJA 25
549 0, // 26
550 KEY_ESCAPE, // VK_ESCAPE 27
551 0, // 28
552 0, // 29
553 0, // 30
554 0, // 31
555 KEY_SPACE, // VK_SPACE 32
556 KEY_PAGEUP, // VK_PRIOR 33
557 KEY_PAGEDOWN, // VK_NEXT 34
558 KEY_END, // VK_END 35
559 KEY_HOME, // VK_HOME 36
560 KEY_LEFT, // VK_LEFT 37
561 KEY_UP, // VK_UP 38
562 KEY_RIGHT, // VK_RIGHT 39
563 KEY_DOWN, // VK_DOWN 40
564 0, // VK_SELECT 41
565 0, // VK_PRINT 42
566 0, // VK_EXECUTE 43
567 0, // VK_SNAPSHOT 44
568 KEY_INSERT, // VK_INSERT 45
569 KEY_DELETE, // VK_DELETE 46
570 KEY_HELP, // VK_HELP 47
571 KEY_0, // 48
572 KEY_1, // 49
573 KEY_2, // 50
574 KEY_3, // 51
575 KEY_4, // 52
576 KEY_5, // 53
577 KEY_6, // 54
578 KEY_7, // 55
579 KEY_8, // 56
580 KEY_9, // 57
581 0, // 58
582 0, // 59
583 0, // 60
584 0, // 61
585 0, // 62
586 0, // 63
587 0, // 64
588 KEY_A, // 65
589 KEY_B, // 66
590 KEY_C, // 67
591 KEY_D, // 68
592 KEY_E, // 69
593 KEY_F, // 70
594 KEY_G, // 71
595 KEY_H, // 72
596 KEY_I, // 73
597 KEY_J, // 74
598 KEY_K, // 75
599 KEY_L, // 76
600 KEY_M, // 77
601 KEY_N, // 78
602 KEY_O, // 79
603 KEY_P, // 80
604 KEY_Q, // 81
605 KEY_R, // 82
606 KEY_S, // 83
607 KEY_T, // 84
608 KEY_U, // 85
609 KEY_V, // 86
610 KEY_W, // 87
611 KEY_X, // 88
612 KEY_Y, // 89
613 KEY_Z, // 90
614 0, // VK_LWIN 91
615 0, // VK_RWIN 92
616 KEY_CONTEXTMENU, // VK_APPS 93
617 0, // 94
618 0, // 95
619 KEY_0, // VK_NUMPAD0 96
620 KEY_1, // VK_NUMPAD1 97
621 KEY_2, // VK_NUMPAD2 98
622 KEY_3, // VK_NUMPAD3 99
623 KEY_4, // VK_NUMPAD4 100
624 KEY_5, // VK_NUMPAD5 101
625 KEY_6, // VK_NUMPAD6 102
626 KEY_7, // VK_NUMPAD7 103
627 KEY_8, // VK_NUMPAD8 104
628 KEY_9, // VK_NUMPAD9 105
629 KEY_MULTIPLY, // VK_MULTIPLY 106
630 KEY_ADD, // VK_ADD 107
631 KEY_DECIMAL, // VK_SEPARATOR 108
632 KEY_SUBTRACT, // VK_SUBTRACT 109
633 KEY_DECIMAL, // VK_DECIMAL 110
634 KEY_DIVIDE, // VK_DIVIDE 111
635 KEY_F1, // VK_F1 112
636 KEY_F2, // VK_F2 113
637 KEY_F3, // VK_F3 114
638 KEY_F4, // VK_F4 115
639 KEY_F5, // VK_F5 116
640 KEY_F6, // VK_F6 117
641 KEY_F7, // VK_F7 118
642 KEY_F8, // VK_F8 119
643 KEY_F9, // VK_F9 120
644 KEY_F10, // VK_F10 121
645 KEY_F11, // VK_F11 122
646 KEY_F12, // VK_F12 123
647 KEY_F13, // VK_F13 124
648 KEY_F14, // VK_F14 125
649 KEY_F15, // VK_F15 126
650 KEY_F16, // VK_F16 127
651 KEY_F17, // VK_F17 128
652 KEY_F18, // VK_F18 129
653 KEY_F19, // VK_F19 130
654 KEY_F20, // VK_F20 131
655 KEY_F21, // VK_F21 132
656 KEY_F22, // VK_F22 133
657 KEY_F23, // VK_F23 134
658 KEY_F24, // VK_F24 135
659 0, // 136
660 0, // 137
661 0, // 138
662 0, // 139
663 0, // 140
664 0, // 141
665 0, // 142
666 0, // 143
667 0, // NUMLOCK 144
668 0 // SCROLLLOCK 145
671 static UINT ImplSalGetWheelScrollLines()
673 UINT nScrLines = 0;
674 HWND hWndMsWheel = FindWindowW( MSH_WHEELMODULE_CLASS, MSH_WHEELMODULE_TITLE );
675 if ( hWndMsWheel )
677 UINT nGetScrollLinesMsgId = RegisterWindowMessageW( MSH_SCROLL_LINES );
678 nScrLines = static_cast<UINT>(SendMessageW( hWndMsWheel, nGetScrollLinesMsgId, 0, 0 ));
681 if ( !nScrLines )
682 if( !SystemParametersInfoW( SPI_GETWHEELSCROLLLINES, 0, &nScrLines, 0 ) )
683 nScrLines = 0 ;
685 if ( !nScrLines )
686 nScrLines = 3;
688 return nScrLines;
691 static UINT ImplSalGetWheelScrollChars()
693 UINT nScrChars = 0;
694 if( !SystemParametersInfoW( SPI_GETWHEELSCROLLCHARS, 0, &nScrChars, 0 ) )
696 return 3;
699 // system settings successfully read
700 return nScrChars;
703 static void ImplSalAddBorder( const WinSalFrame* pFrame, int& width, int& height )
705 // transform client size into window size
706 RECT aWinRect;
707 aWinRect.left = 0;
708 aWinRect.right = width-1;
709 aWinRect.top = 0;
710 aWinRect.bottom = height-1;
711 AdjustWindowRectEx( &aWinRect, GetWindowStyle( pFrame->mhWnd ),
712 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
713 width = aWinRect.right - aWinRect.left + 1;
714 height = aWinRect.bottom - aWinRect.top + 1;
717 static void ImplSalCalcFullScreenSize( const WinSalFrame* pFrame,
718 int& rX, int& rY, int& rDX, int& rDY )
720 // set window to screen size
721 int nFrameX;
722 int nFrameY;
723 int nCaptionY;
724 int nScreenX = 0;
725 int nScreenY = 0;
726 int nScreenDX = 0;
727 int nScreenDY = 0;
729 if ( pFrame->mbSizeBorder )
731 nFrameX = GetSystemMetrics( SM_CXSIZEFRAME );
732 nFrameY = GetSystemMetrics( SM_CYSIZEFRAME );
734 else if ( pFrame->mbFixBorder )
736 nFrameX = GetSystemMetrics( SM_CXFIXEDFRAME );
737 nFrameY = GetSystemMetrics( SM_CYFIXEDFRAME );
739 else if ( pFrame->mbBorder )
741 nFrameX = GetSystemMetrics( SM_CXBORDER );
742 nFrameY = GetSystemMetrics( SM_CYBORDER );
744 else
746 nFrameX = 0;
747 nFrameY = 0;
749 if ( pFrame->mbCaption )
750 nCaptionY = GetSystemMetrics( SM_CYCAPTION );
751 else
752 nCaptionY = 0;
756 sal_Int32 nMonitors = Application::GetScreenCount();
757 if( (pFrame->mnDisplay >= 0) && (pFrame->mnDisplay < nMonitors) )
759 tools::Rectangle aRect = Application::GetScreenPosSizePixel( pFrame->mnDisplay );
760 nScreenX = aRect.Left();
761 nScreenY = aRect.Top();
762 nScreenDX = aRect.getWidth()+1; // difference between java/awt convention and vcl
763 nScreenDY = aRect.getHeight()+1; // difference between java/awt convention and vcl
765 else
767 tools::Rectangle aCombined = Application::GetScreenPosSizePixel( 0 );
768 for( sal_Int32 i = 1 ; i < nMonitors ; i++ )
770 aCombined.Union( Application::GetScreenPosSizePixel( i ) );
772 nScreenX = aCombined.Left();
773 nScreenY = aCombined.Top();
774 nScreenDX = aCombined.getWidth();
775 nScreenDY = aCombined.getHeight();
778 catch( Exception& )
782 if( !nScreenDX || !nScreenDY )
784 nScreenDX = GetSystemMetrics( SM_CXSCREEN );
785 nScreenDY = GetSystemMetrics( SM_CYSCREEN );
788 rX = nScreenX -nFrameX;
789 rY = nScreenY -(nFrameY+nCaptionY);
790 rDX = nScreenDX+(nFrameX*2);
791 rDY = nScreenDY+(nFrameY*2)+nCaptionY;
794 static void ImplSalFrameFullScreenPos( WinSalFrame* pFrame, bool bAlways = false )
796 if ( bAlways || !IsIconic( pFrame->mhWnd ) )
798 // set window to screen size
799 int nX;
800 int nY;
801 int nWidth;
802 int nHeight;
803 ImplSalCalcFullScreenSize( pFrame, nX, nY, nWidth, nHeight );
804 SetWindowPos( pFrame->mhWnd, nullptr,
805 nX, nY, nWidth, nHeight,
806 SWP_NOZORDER | SWP_NOACTIVATE );
810 namespace {
812 void SetForegroundWindow_Impl(HWND hwnd)
814 static bool bUseForegroundWindow = !std::getenv("VCL_HIDE_WINDOWS");
815 if (bUseForegroundWindow)
816 SetForegroundWindow(hwnd);
821 WinSalFrame::WinSalFrame()
823 SalData* pSalData = GetSalData();
825 mhWnd = nullptr;
826 mhCursor = LoadCursor( nullptr, IDC_ARROW );
827 mhDefIMEContext = nullptr;
828 mpLocalGraphics = nullptr;
829 mpThreadGraphics = nullptr;
830 mnShowState = SW_SHOWNORMAL;
831 mnWidth = 0;
832 mnHeight = 0;
833 mnMinWidth = 0;
834 mnMinHeight = 0;
835 mnMaxWidth = SHRT_MAX;
836 mnMaxHeight = SHRT_MAX;
837 mnInputLang = 0;
838 mnInputCodePage = 0;
839 mbGraphics = false;
840 mbCaption = false;
841 mbBorder = false;
842 mbFixBorder = false;
843 mbSizeBorder = false;
844 mbFullScreen = false;
845 mbPresentation = false;
846 mbInShow = false;
847 mbRestoreMaximize = false;
848 mbInMoveMsg = false;
849 mbInSizeMsg = false;
850 mbFullScreenToolWin = false;
851 mbDefPos = true;
852 mbOverwriteState = true;
853 mbIME = false;
854 mbHandleIME = false;
855 mbSpezIME = false;
856 mbAtCursorIME = false;
857 mbCandidateMode = false;
858 mbFloatWin = false;
859 mbNoIcon = false;
860 mSelectedhMenu = nullptr;
861 mLastActivatedhMenu = nullptr;
862 mpClipRgnData = nullptr;
863 mbFirstClipRect = true;
864 mpNextClipRect = nullptr;
865 mnDisplay = 0;
866 mbPropertiesStored = false;
868 memset( &maState, 0, sizeof( SalFrameState ) );
869 maSysData.nSize = sizeof( SystemEnvData );
871 memset( &maGeometry, 0, sizeof( maGeometry ) );
873 // get data, when making 1st frame
874 if ( !pSalData->mpFirstFrame )
876 if ( !aSalShlData.mnWheelScrollLines )
877 aSalShlData.mnWheelScrollLines = ImplSalGetWheelScrollLines();
878 if ( !aSalShlData.mnWheelScrollChars )
879 aSalShlData.mnWheelScrollChars = ImplSalGetWheelScrollChars();
882 // insert frame in framelist
883 mpNextFrame = pSalData->mpFirstFrame;
884 pSalData->mpFirstFrame = this;
887 void WinSalFrame::updateScreenNumber()
889 if( mnDisplay == -1 ) // spans all monitors
890 return;
891 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
892 if( pSys )
894 const std::vector<WinSalSystem::DisplayMonitor>& rMonitors =
895 pSys->getMonitors();
896 Point aPoint( maGeometry.nX, maGeometry.nY );
897 size_t nMon = rMonitors.size();
898 for( size_t i = 0; i < nMon; i++ )
900 if( rMonitors[i].m_aArea.IsInside( aPoint ) )
902 mnDisplay = static_cast<sal_Int32>(i);
903 maGeometry.nDisplayScreenNumber = static_cast<unsigned int>(i);
909 bool WinSalFrame::ReleaseFrameGraphicsDC( WinSalGraphics* pGraphics )
911 assert( pGraphics );
912 SalData* pSalData = GetSalData();
913 HDC hDC = pGraphics->getHDC();
914 if ( !hDC )
915 return false;
916 if ( pGraphics->getDefPal() )
917 SelectPalette( hDC, pGraphics->getDefPal(), TRUE );
918 pGraphics->DeInitGraphics();
919 SendMessageW( pSalData->mpInstance->mhComWnd, SAL_MSG_RELEASEDC,
920 reinterpret_cast<WPARAM>(mhWnd), reinterpret_cast<LPARAM>(hDC) );
921 if ( pGraphics == mpThreadGraphics )
922 pSalData->mnCacheDCInUse--;
923 pGraphics->setHDC(nullptr);
924 return true;
927 WinSalFrame::~WinSalFrame()
929 SalData* pSalData = GetSalData();
931 if( mpClipRgnData )
932 delete [] reinterpret_cast<BYTE*>(mpClipRgnData);
934 // remove frame from framelist
935 WinSalFrame** ppFrame = &pSalData->mpFirstFrame;
936 for(; (*ppFrame != this) && *ppFrame; ppFrame = &(*ppFrame)->mpNextFrame );
937 if( *ppFrame )
938 *ppFrame = mpNextFrame;
939 mpNextFrame = nullptr;
941 // destroy the thread SalGraphics
942 if ( mpThreadGraphics )
944 ReleaseFrameGraphicsDC( mpThreadGraphics );
945 delete mpThreadGraphics;
946 mpThreadGraphics = nullptr;
949 // destroy the local SalGraphics
950 if ( mpLocalGraphics )
952 ReleaseFrameGraphicsDC( mpLocalGraphics );
953 delete mpLocalGraphics;
954 mpLocalGraphics = nullptr;
957 if ( mhWnd )
959 // reset mouse leave data
960 if ( pSalData->mhWantLeaveMsg == mhWnd )
962 pSalData->mhWantLeaveMsg = nullptr;
963 if ( pSalData->mpMouseLeaveTimer )
965 delete pSalData->mpMouseLeaveTimer;
966 pSalData->mpMouseLeaveTimer = nullptr;
970 // remove windows properties
971 if ( mbPropertiesStored )
972 SetApplicationID( OUString() );
974 // destroy system frame
975 if ( !DestroyWindow( mhWnd ) )
976 SetWindowPtr( mhWnd, nullptr );
978 mhWnd = nullptr;
982 bool WinSalFrame::InitFrameGraphicsDC( WinSalGraphics *pGraphics, HDC hDC, HWND hWnd )
984 SalData* pSalData = GetSalData();
985 assert( pGraphics );
986 pGraphics->setHWND( hWnd );
988 HDC hCurrentDC = pGraphics->getHDC();
989 assert( !hCurrentDC || (hCurrentDC == hDC) );
990 if ( hCurrentDC )
991 return true;
992 pGraphics->setHDC( hDC );
994 if ( !hDC )
995 return false;
997 if ( pSalData->mhDitherPal )
999 pGraphics->setDefPal(SelectPalette( hDC, pSalData->mhDitherPal, TRUE ));
1000 RealizePalette( hDC );
1002 pGraphics->InitGraphics();
1004 if ( pGraphics == mpThreadGraphics )
1005 pSalData->mnCacheDCInUse++;
1006 return true;
1009 SalGraphics* WinSalFrame::AcquireGraphics()
1011 if ( mbGraphics || !mhWnd )
1012 return nullptr;
1014 SalData* pSalData = GetSalData();
1015 WinSalGraphics *pGraphics = nullptr;
1016 HDC hDC = nullptr;
1018 // Other threads get an own DC, because Windows modify in the
1019 // other case our DC (changing clip region), when they send a
1020 // WM_ERASEBACKGROUND message
1021 if ( !pSalData->mpInstance->IsMainThread() )
1023 // We use only three CacheDC's for all threads, because W9x is limited
1024 // to max. 5 Cache DC's per thread
1025 if ( pSalData->mnCacheDCInUse >= 3 )
1026 return nullptr;
1028 if ( !mpThreadGraphics )
1029 mpThreadGraphics = new WinSalGraphics(WinSalGraphics::WINDOW, true, mhWnd, this);
1030 pGraphics = mpThreadGraphics;
1031 assert( !pGraphics->getHDC() );
1032 hDC = reinterpret_cast<HDC>(static_cast<sal_IntPtr>(SendMessageW( pSalData->mpInstance->mhComWnd,
1033 SAL_MSG_GETCACHEDDC, reinterpret_cast<WPARAM>(mhWnd), 0 )));
1035 else
1037 if ( !mpLocalGraphics )
1038 mpLocalGraphics = new WinSalGraphics(WinSalGraphics::WINDOW, true, mhWnd, this);
1039 pGraphics = mpLocalGraphics;
1040 hDC = pGraphics->getHDC();
1041 if ( !hDC )
1042 hDC = GetDC( mhWnd );
1045 mbGraphics = InitFrameGraphicsDC( pGraphics, hDC, mhWnd );
1046 return mbGraphics ? pGraphics : nullptr;
1049 void WinSalFrame::ReleaseGraphics( SalGraphics* pGraphics )
1051 if ( mpThreadGraphics == pGraphics )
1052 ReleaseFrameGraphicsDC( mpThreadGraphics );
1053 mbGraphics = false;
1056 bool WinSalFrame::PostEvent(ImplSVEvent* pData)
1058 BOOL const ret = PostMessageW(mhWnd, SAL_MSG_USEREVENT, 0, reinterpret_cast<LPARAM>(pData));
1059 SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
1060 return static_cast<bool>(ret);
1063 void WinSalFrame::SetTitle( const OUString& rTitle )
1065 static_assert( sizeof( WCHAR ) == sizeof( sal_Unicode ), "must be the same size" );
1067 SetWindowTextW( mhWnd, o3tl::toW(rTitle.getStr()) );
1070 void WinSalFrame::SetIcon( sal_uInt16 nIcon )
1072 // If we have a window without an Icon (for example a dialog), ignore this call
1073 if ( mbNoIcon )
1074 return;
1076 // 0 means default (class) icon
1077 HICON hIcon = nullptr, hSmIcon = nullptr;
1078 if ( !nIcon )
1079 nIcon = 1;
1081 ImplLoadSalIcon( nIcon, hIcon, hSmIcon );
1083 SAL_WARN_IF( !hIcon , "vcl", "WinSalFrame::SetIcon(): Could not load large icon !" );
1084 SAL_WARN_IF( !hSmIcon , "vcl", "WinSalFrame::SetIcon(): Could not load small icon !" );
1086 SendMessageW( mhWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hIcon) );
1087 SendMessageW( mhWnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(hSmIcon) );
1090 void WinSalFrame::SetMenu( SalMenu* pSalMenu )
1092 WinSalMenu* pWMenu = static_cast<WinSalMenu*>(pSalMenu);
1093 if( pSalMenu && pWMenu->mbMenuBar )
1094 ::SetMenu( mhWnd, pWMenu->mhMenu );
1097 void WinSalFrame::DrawMenuBar()
1099 ::DrawMenuBar( mhWnd );
1102 HWND ImplGetParentHwnd( HWND hWnd )
1104 WinSalFrame* pFrame = GetWindowPtr( hWnd );
1105 if( !pFrame || !pFrame->GetWindow())
1106 return ::GetParent( hWnd );
1107 vcl::Window *pRealParent = pFrame->GetWindow()->ImplGetWindowImpl()->mpRealParent;
1108 if( pRealParent )
1109 return static_cast<WinSalFrame*>(pRealParent->ImplGetWindowImpl()->mpFrame)->mhWnd;
1110 else
1111 return ::GetParent( hWnd );
1115 SalFrame* WinSalFrame::GetParent() const
1117 return GetWindowPtr( ImplGetParentHwnd( mhWnd ) );
1120 static void ImplSalShow( HWND hWnd, bool bVisible, bool bNoActivate )
1122 WinSalFrame* pFrame = GetWindowPtr( hWnd );
1123 if ( !pFrame )
1124 return;
1126 if ( bVisible )
1128 pFrame->mbDefPos = false;
1129 pFrame->mbOverwriteState = true;
1130 pFrame->mbInShow = true;
1132 // #i4715, save position
1133 RECT aRectPreMatrox, aRectPostMatrox;
1134 GetWindowRect( hWnd, &aRectPreMatrox );
1136 vcl::DeletionListener aDogTag( pFrame );
1137 if( bNoActivate )
1138 ShowWindow( hWnd, SW_SHOWNOACTIVATE );
1139 else
1140 ShowWindow( hWnd, pFrame->mnShowState );
1141 if( aDogTag.isDeleted() )
1142 return;
1144 if (pFrame->mbFloatWin && !(pFrame->mnStyle & SalFrameStyleFlags::NOSHADOW))
1146 // erase the window immediately to improve XP shadow effect
1147 // otherwise the shadow may appears long time before the rest of the window
1148 // especially when accessibility is on
1149 HDC dc = GetDC( hWnd );
1150 RECT aRect;
1151 GetClientRect( hWnd, &aRect );
1152 FillRect( dc, &aRect, reinterpret_cast<HBRUSH>(COLOR_MENU+1) ); // choose the menucolor, because its mostly noticeable for menus
1153 ReleaseDC( hWnd, dc );
1156 // #i4715, matrox centerpopup might have changed our position
1157 // reposition popups without caption (menus, dropdowns, tooltips)
1158 GetWindowRect( hWnd, &aRectPostMatrox );
1159 if( (GetWindowStyle( hWnd ) & WS_POPUP) &&
1160 !pFrame->mbCaption &&
1161 (aRectPreMatrox.left != aRectPostMatrox.left || aRectPreMatrox.top != aRectPostMatrox.top) )
1162 SetWindowPos( hWnd, nullptr, aRectPreMatrox.left, aRectPreMatrox.top, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE );
1164 if( aDogTag.isDeleted() )
1165 return;
1166 vcl::Window *pClientWin = pFrame->GetWindow()->ImplGetClientWindow();
1167 if ( pFrame->mbFloatWin || ( pClientWin && (pClientWin->GetStyle() & WB_SYSTEMFLOATWIN) ) )
1168 pFrame->mnShowState = SW_SHOWNOACTIVATE;
1169 else
1170 pFrame->mnShowState = SW_SHOW;
1171 // hide toolbar for W98
1172 if ( pFrame->mbPresentation )
1174 HWND hWndParent = ::GetParent( hWnd );
1175 if ( hWndParent )
1176 SetForegroundWindow_Impl( hWndParent );
1177 SetForegroundWindow_Impl( hWnd );
1180 pFrame->mbInShow = false;
1181 pFrame->updateScreenNumber();
1183 // Direct Paint only, if we get the SolarMutex
1184 if ( ImplSalYieldMutexTryToAcquire() )
1186 UpdateWindow( hWnd );
1187 ImplSalYieldMutexRelease();
1190 else
1192 ShowWindow( hWnd, SW_HIDE );
1196 void WinSalFrame::SetExtendedFrameStyle( SalExtStyle )
1200 void WinSalFrame::Show( bool bVisible, bool bNoActivate )
1202 // Post this Message to the window, because this only works
1203 // in the thread of the window, which has create this window.
1204 // We post this message to avoid deadlocks
1205 if ( GetSalData()->mnAppThreadId != GetCurrentThreadId() )
1207 BOOL const ret = PostMessageW(mhWnd, SAL_MSG_SHOW, WPARAM(bVisible), LPARAM(bNoActivate));
1208 SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
1210 else
1211 ImplSalShow( mhWnd, bVisible, bNoActivate );
1214 void WinSalFrame::SetMinClientSize( long nWidth, long nHeight )
1216 mnMinWidth = nWidth;
1217 mnMinHeight = nHeight;
1220 void WinSalFrame::SetMaxClientSize( long nWidth, long nHeight )
1222 mnMaxWidth = nWidth;
1223 mnMaxHeight = nHeight;
1226 void WinSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight,
1227 sal_uInt16 nFlags )
1229 bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
1230 if ( !bVisible )
1232 vcl::Window *pClientWin = GetWindow()->ImplGetClientWindow();
1233 if ( mbFloatWin || ( pClientWin && (pClientWin->GetStyle() & WB_SYSTEMFLOATWIN) ) )
1234 mnShowState = SW_SHOWNOACTIVATE;
1235 else
1236 mnShowState = SW_SHOWNORMAL;
1238 else
1240 if ( IsIconic( mhWnd ) || IsZoomed( mhWnd ) )
1241 ShowWindow( mhWnd, SW_RESTORE );
1244 SalEvent nEvent = SalEvent::NONE;
1245 UINT nPosSize = 0;
1246 RECT aClientRect, aWindowRect;
1247 GetClientRect( mhWnd, &aClientRect ); // x,y always 0,0, but width and height without border
1248 GetWindowRect( mhWnd, &aWindowRect ); // x,y in screen coordinates, width and height with border
1250 if ( !(nFlags & (SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y)) )
1251 nPosSize |= SWP_NOMOVE;
1252 else
1254 //SAL_WARN_IF( !nX || !nY, "vcl", " Windowposition of (0,0) requested!" );
1255 nEvent = SalEvent::Move;
1257 if ( !(nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) )
1258 nPosSize |= SWP_NOSIZE;
1259 else
1260 nEvent = (nEvent == SalEvent::Move) ? SalEvent::MoveResize : SalEvent::Resize;
1262 if ( !(nFlags & SAL_FRAME_POSSIZE_X) )
1263 nX = aWindowRect.left;
1264 if ( !(nFlags & SAL_FRAME_POSSIZE_Y) )
1265 nY = aWindowRect.top;
1266 if ( !(nFlags & SAL_FRAME_POSSIZE_WIDTH) )
1267 nWidth = aClientRect.right-aClientRect.left;
1268 if ( !(nFlags & SAL_FRAME_POSSIZE_HEIGHT) )
1269 nHeight = aClientRect.bottom-aClientRect.top;
1271 // Calculate window size including the border
1272 RECT aWinRect;
1273 aWinRect.left = 0;
1274 aWinRect.right = static_cast<int>(nWidth)-1;
1275 aWinRect.top = 0;
1276 aWinRect.bottom = static_cast<int>(nHeight)-1;
1277 AdjustWindowRectEx( &aWinRect, GetWindowStyle( mhWnd ),
1278 FALSE, GetWindowExStyle( mhWnd ) );
1279 nWidth = aWinRect.right - aWinRect.left + 1;
1280 nHeight = aWinRect.bottom - aWinRect.top + 1;
1282 if ( !(nPosSize & SWP_NOMOVE) && ::GetParent( mhWnd ) )
1284 RECT aParentRect;
1285 GetClientRect( ImplGetParentHwnd( mhWnd ), &aParentRect );
1286 if( AllSettings::GetLayoutRTL() )
1287 nX = (aParentRect.right - aParentRect.left) - nWidth-1 - nX;
1289 //#110386#, do not transform coordinates for system child windows
1290 if( !(GetWindowStyle( mhWnd ) & WS_CHILD) )
1292 POINT aPt;
1293 aPt.x = nX;
1294 aPt.y = nY;
1296 HWND parentHwnd = ImplGetParentHwnd( mhWnd );
1297 WinSalFrame* pParentFrame = GetWindowPtr( parentHwnd );
1298 if ( pParentFrame && pParentFrame->mnShowState == SW_SHOWMAXIMIZED )
1300 // #i42485#: parent will be shown maximized in which case
1301 // a ClientToScreen uses the wrong coordinates (i.e. those from the restore pos)
1302 // so use the (already updated) frame geometry for the transformation
1303 aPt.x += pParentFrame->maGeometry.nX;
1304 aPt.y += pParentFrame->maGeometry.nY;
1306 else
1307 ClientToScreen( parentHwnd, &aPt );
1309 nX = aPt.x;
1310 nY = aPt.y;
1312 // the position is set
1313 mbDefPos = false;
1317 // #i3338# to be conformant to UNIX we must position the client window, ie without the decoration
1318 // #i43250# if the position was read from the system (GetWindowRect(), see above), it must not be modified
1319 if ( nFlags & SAL_FRAME_POSSIZE_X )
1320 nX += aWinRect.left;
1321 if ( nFlags & SAL_FRAME_POSSIZE_Y )
1322 nY += aWinRect.top;
1324 int nScreenX;
1325 int nScreenY;
1326 int nScreenWidth;
1327 int nScreenHeight;
1329 RECT aRect;
1330 ImplSalGetWorkArea( mhWnd, &aRect, nullptr );
1331 nScreenX = aRect.left;
1332 nScreenY = aRect.top;
1333 nScreenWidth = aRect.right-aRect.left;
1334 nScreenHeight = aRect.bottom-aRect.top;
1336 if ( mbDefPos && (nPosSize & SWP_NOMOVE)) // we got no positioning request, so choose default position
1338 // center window
1340 HWND hWndParent = ::GetParent( mhWnd );
1341 // Search for TopLevel Frame
1342 while ( hWndParent && (GetWindowStyle( hWndParent ) & WS_CHILD) )
1343 hWndParent = ::GetParent( hWndParent );
1344 // if the Window has a Parent, than center the window to
1345 // the parent, in the other case to the screen
1346 if ( hWndParent && !IsIconic( hWndParent ) &&
1347 (GetWindowStyle( hWndParent ) & WS_VISIBLE) )
1349 RECT aParentRect;
1350 GetWindowRect( hWndParent, &aParentRect );
1351 int nParentWidth = aParentRect.right-aParentRect.left;
1352 int nParentHeight = aParentRect.bottom-aParentRect.top;
1354 // We don't center, when Parent is smaller than our window
1355 if ( (nParentWidth-GetSystemMetrics( SM_CXFIXEDFRAME ) <= nWidth) &&
1356 (nParentHeight-GetSystemMetrics( SM_CYFIXEDFRAME ) <= nHeight) )
1358 int nOff = GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION );
1359 nX = aParentRect.left+nOff;
1360 nY = aParentRect.top+nOff;
1362 else
1364 nX = (nParentWidth-nWidth)/2 + aParentRect.left;
1365 nY = (nParentHeight-nHeight)/2 + aParentRect.top;
1368 else
1370 POINT pt;
1371 GetCursorPos( &pt );
1372 RECT aRect2;
1373 aRect2.left = pt.x;
1374 aRect2.top = pt.y;
1375 aRect2.right = pt.x+2;
1376 aRect2.bottom = pt.y+2;
1378 // dualmonitor support:
1379 // Get screensize of the monitor with the mouse pointer
1380 ImplSalGetWorkArea( mhWnd, &aRect2, &aRect2 );
1382 nX = ((aRect2.right-aRect2.left)-nWidth)/2 + aRect2.left;
1383 nY = ((aRect2.bottom-aRect2.top)-nHeight)/2 + aRect2.top;
1386 //if ( bVisible )
1387 // mbDefPos = FALSE;
1389 mbDefPos = false; // center only once
1390 nPosSize &= ~SWP_NOMOVE; // activate positioning
1391 nEvent = SalEvent::MoveResize;
1394 // Adjust Window in the screen
1395 bool bCheckOffScreen = true;
1397 // but don't do this for floaters or ownerdraw windows that are currently moved interactively
1398 if( (mnStyle & SalFrameStyleFlags::FLOAT) && !(mnStyle & SalFrameStyleFlags::OWNERDRAWDECORATION) )
1399 bCheckOffScreen = false;
1401 if( mnStyle & SalFrameStyleFlags::OWNERDRAWDECORATION )
1403 // may be the window is currently being moved (mouse is captured), then no check is required
1404 if( mhWnd == ::GetCapture() )
1405 bCheckOffScreen = false;
1406 else
1407 bCheckOffScreen = true;
1410 if( bCheckOffScreen )
1412 if ( nX+nWidth > nScreenX+nScreenWidth )
1413 nX = (nScreenX+nScreenWidth) - nWidth;
1414 if ( nY+nHeight > nScreenY+nScreenHeight )
1415 nY = (nScreenY+nScreenHeight) - nHeight;
1416 if ( nX < nScreenX )
1417 nX = nScreenX;
1418 if ( nY < nScreenY )
1419 nY = nScreenY;
1422 UINT nPosFlags = SWP_NOACTIVATE | SWP_NOOWNERZORDER | nPosSize;
1423 // bring floating windows always to top
1424 if( !(mnStyle & SalFrameStyleFlags::FLOAT) )
1425 nPosFlags |= SWP_NOZORDER; // do not change z-order
1427 SetWindowPos( mhWnd, HWND_TOP, nX, nY, static_cast<int>(nWidth), static_cast<int>(nHeight), nPosFlags );
1429 UpdateFrameGeometry( mhWnd, this );
1431 // Notification -- really ???
1432 if( nEvent != SalEvent::NONE )
1433 CallCallback( nEvent, nullptr );
1436 void WinSalFrame::ImplSetParentFrame( HWND hNewParentWnd, bool bAsChild )
1438 // save hwnd, will be overwritten in WM_CREATE during createwindow
1439 HWND hWndOld = mhWnd;
1440 HWND hWndOldParent = ::GetParent( hWndOld );
1441 SalData* pSalData = GetSalData();
1443 if( hNewParentWnd == hWndOldParent )
1444 return;
1446 ::std::vector< WinSalFrame* > children;
1447 ::std::vector< WinSalObject* > systemChildren;
1449 // search child windows
1450 WinSalFrame *pFrame = pSalData->mpFirstFrame;
1451 while( pFrame )
1453 HWND hWndParent = ::GetParent( pFrame->mhWnd );
1454 if( mhWnd == hWndParent )
1455 children.push_back( pFrame );
1456 pFrame = pFrame->mpNextFrame;
1459 // search system child windows (plugins etc.)
1460 WinSalObject *pObject = pSalData->mpFirstObject;
1461 while( pObject )
1463 HWND hWndParent = ::GetParent( pObject->mhWnd );
1464 if( mhWnd == hWndParent )
1465 systemChildren.push_back( pObject );
1466 pObject = pObject->mpNextObject;
1469 // to recreate the DCs, if they were destroyed
1470 bool bHadLocalGraphics = false, bHadThreadGraphics = false;
1472 HFONT hFont = nullptr;
1473 HPEN hPen = nullptr;
1474 HBRUSH hBrush = nullptr;
1476 int oldCount = pSalData->mnCacheDCInUse;
1478 // release the thread DC
1479 if ( mpThreadGraphics )
1481 // save current gdi objects before hdc is gone
1482 HDC hDC = mpThreadGraphics->getHDC();
1483 if ( hDC )
1485 hFont = static_cast<HFONT>(GetCurrentObject( hDC, OBJ_FONT ));
1486 hPen = static_cast<HPEN>(GetCurrentObject( hDC, OBJ_PEN ));
1487 hBrush = static_cast<HBRUSH>(GetCurrentObject( hDC, OBJ_BRUSH ));
1490 bHadThreadGraphics = ReleaseFrameGraphicsDC( mpThreadGraphics );
1491 assert( (bHadThreadGraphics && hDC) || (!bHadThreadGraphics && !hDC) );
1494 // release the local DC
1495 if ( mpLocalGraphics )
1496 bHadLocalGraphics = ReleaseFrameGraphicsDC( mpLocalGraphics );
1498 // create a new hwnd with the same styles
1499 HWND hWndParent = hNewParentWnd;
1500 // forward to main thread
1501 HWND hWnd = reinterpret_cast<HWND>(static_cast<sal_IntPtr>(SendMessageW( pSalData->mpInstance->mhComWnd,
1502 bAsChild ? SAL_MSG_RECREATECHILDHWND : SAL_MSG_RECREATEHWND,
1503 reinterpret_cast<WPARAM>(hWndParent), reinterpret_cast<LPARAM>(mhWnd) )));
1505 // succeeded ?
1506 SAL_WARN_IF( !IsWindow( hWnd ), "vcl", "WinSalFrame::SetParent not successful");
1508 // re-create thread DC
1509 if( bHadThreadGraphics )
1511 HDC hDC = reinterpret_cast<HDC>(static_cast<sal_IntPtr>(
1512 SendMessageW( pSalData->mpInstance->mhComWnd,
1513 SAL_MSG_GETCACHEDDC, reinterpret_cast<WPARAM>(hWnd), 0 )));
1514 InitFrameGraphicsDC( mpThreadGraphics, hDC, hWnd );
1515 if ( hDC )
1517 // re-select saved gdi objects
1518 if( hFont )
1519 SelectObject( hDC, hFont );
1520 if( hPen )
1521 SelectObject( hDC, hPen );
1522 if( hBrush )
1523 SelectObject( hDC, hBrush );
1525 SAL_WARN_IF( oldCount != pSalData->mnCacheDCInUse, "vcl", "WinSalFrame::SetParent() hDC count corrupted");
1529 // re-create local DC
1530 if( bHadLocalGraphics )
1531 InitFrameGraphicsDC( mpLocalGraphics, GetDC( hWnd ), hWnd );
1533 // TODO: add SetParent() call for SalObjects
1534 SAL_WARN_IF( !systemChildren.empty(), "vcl", "WinSalFrame::SetParent() parent of living system child window will be destroyed!");
1536 // reparent children before old parent is destroyed
1537 for (auto & child : children)
1538 child->ImplSetParentFrame( hWnd, false );
1540 children.clear();
1541 systemChildren.clear();
1543 // Now destroy original HWND in the thread where it was created.
1544 SendMessageW( GetSalData()->mpInstance->mhComWnd,
1545 SAL_MSG_DESTROYHWND, WPARAM(0), reinterpret_cast<LPARAM>(hWndOld));
1548 void WinSalFrame::SetParent( SalFrame* pNewParent )
1550 WinSalFrame::mbInReparent = true;
1551 ImplSetParentFrame( static_cast<WinSalFrame*>(pNewParent)->mhWnd, false );
1552 WinSalFrame::mbInReparent = false;
1555 bool WinSalFrame::SetPluginParent( SystemParentData* pNewParent )
1557 if ( pNewParent->hWnd == nullptr )
1559 pNewParent->hWnd = GetDesktopWindow();
1562 WinSalFrame::mbInReparent = true;
1563 ImplSetParentFrame( pNewParent->hWnd, true );
1564 WinSalFrame::mbInReparent = false;
1565 return true;
1568 void WinSalFrame::GetWorkArea( tools::Rectangle &rRect )
1570 RECT aRect;
1571 ImplSalGetWorkArea( mhWnd, &aRect, nullptr );
1572 rRect.SetLeft( aRect.left );
1573 rRect.SetRight( aRect.right-1 );
1574 rRect.SetTop( aRect.top );
1575 rRect.SetBottom( aRect.bottom-1 );
1578 void WinSalFrame::GetClientSize( long& rWidth, long& rHeight )
1580 rWidth = maGeometry.nWidth;
1581 rHeight = maGeometry.nHeight;
1584 void WinSalFrame::SetWindowState( const SalFrameState* pState )
1586 // Check if the window fits into the screen, in case the screen
1587 // resolution changed
1588 int nX;
1589 int nY;
1590 int nWidth;
1591 int nHeight;
1592 int nScreenX;
1593 int nScreenY;
1594 int nScreenWidth;
1595 int nScreenHeight;
1597 RECT aRect;
1598 ImplSalGetWorkArea( mhWnd, &aRect, nullptr );
1599 // #102500# allow some overlap, the window could have been made a little larger than the physical screen
1600 nScreenX = aRect.left-10;
1601 nScreenY = aRect.top-10;
1602 nScreenWidth = aRect.right-aRect.left+20;
1603 nScreenHeight = aRect.bottom-aRect.top+20;
1605 UINT nPosSize = 0;
1606 RECT aWinRect;
1607 GetWindowRect( mhWnd, &aWinRect );
1609 // to be consistent with Unix, the frame state is without(!) decoration
1610 // ->add the decoration
1611 RECT aRect2 = aWinRect;
1612 AdjustWindowRectEx( &aRect2, GetWindowStyle( mhWnd ),
1613 FALSE, GetWindowExStyle( mhWnd ) );
1614 long nTopDeco = abs( aWinRect.top - aRect2.top );
1615 long nLeftDeco = abs( aWinRect.left - aRect2.left );
1616 long nBottomDeco = abs( aWinRect.bottom - aRect2.bottom );
1617 long nRightDeco = abs( aWinRect.right - aRect2.right );
1619 // adjust window position/size to fit the screen
1620 if ( !(pState->mnMask & (WindowStateMask::X | WindowStateMask::Y)) )
1621 nPosSize |= SWP_NOMOVE;
1622 if ( !(pState->mnMask & (WindowStateMask::Width | WindowStateMask::Height)) )
1623 nPosSize |= SWP_NOSIZE;
1624 if ( pState->mnMask & WindowStateMask::X )
1625 nX = static_cast<int>(pState->mnX) - nLeftDeco;
1626 else
1627 nX = aWinRect.left;
1628 if ( pState->mnMask & WindowStateMask::Y )
1629 nY = static_cast<int>(pState->mnY) - nTopDeco;
1630 else
1631 nY = aWinRect.top;
1632 if ( pState->mnMask & WindowStateMask::Width )
1633 nWidth = static_cast<int>(pState->mnWidth) + nLeftDeco + nRightDeco;
1634 else
1635 nWidth = aWinRect.right-aWinRect.left;
1636 if ( pState->mnMask & WindowStateMask::Height )
1637 nHeight = static_cast<int>(pState->mnHeight) + nTopDeco + nBottomDeco;
1638 else
1639 nHeight = aWinRect.bottom-aWinRect.top;
1641 // Adjust Window in the screen:
1642 // if it does not fit into the screen do nothing, ie default pos/size will be used
1643 // if there is an overlap with the screen border move the window while keeping its size
1645 if( nWidth > nScreenWidth || nHeight > nScreenHeight )
1646 nPosSize |= (SWP_NOMOVE | SWP_NOSIZE);
1648 if ( nX+nWidth > nScreenX+nScreenWidth )
1649 nX = (nScreenX+nScreenWidth) - nWidth;
1650 if ( nY+nHeight > nScreenY+nScreenHeight )
1651 nY = (nScreenY+nScreenHeight) - nHeight;
1652 if ( nX < nScreenX )
1653 nX = nScreenX;
1654 if ( nY < nScreenY )
1655 nY = nScreenY;
1657 // set Restore-Position
1658 WINDOWPLACEMENT aPlacement;
1659 aPlacement.length = sizeof( aPlacement );
1660 GetWindowPlacement( mhWnd, &aPlacement );
1662 // set State
1663 bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
1664 bool bUpdateHiddenFramePos = false;
1665 if ( !bVisible )
1667 aPlacement.showCmd = SW_HIDE;
1669 if ( mbOverwriteState )
1671 if ( pState->mnMask & WindowStateMask::State )
1673 if ( pState->mnState & WindowStateState::Minimized )
1674 mnShowState = SW_SHOWMINIMIZED;
1675 else if ( pState->mnState & WindowStateState::Maximized )
1677 mnShowState = SW_SHOWMAXIMIZED;
1678 bUpdateHiddenFramePos = true;
1680 else if ( pState->mnState & WindowStateState::Normal )
1681 mnShowState = SW_SHOWNORMAL;
1685 else
1687 if ( pState->mnMask & WindowStateMask::State )
1689 if ( pState->mnState & WindowStateState::Minimized )
1691 if ( pState->mnState & WindowStateState::Maximized )
1692 aPlacement.flags |= WPF_RESTORETOMAXIMIZED;
1693 aPlacement.showCmd = SW_SHOWMINIMIZED;
1695 else if ( pState->mnState & WindowStateState::Maximized )
1696 aPlacement.showCmd = SW_SHOWMAXIMIZED;
1697 else if ( pState->mnState & WindowStateState::Normal )
1698 aPlacement.showCmd = SW_RESTORE;
1702 // if a window is neither minimized nor maximized or need not be
1703 // positioned visibly (that is in visible state), do not use
1704 // SetWindowPlacement since it calculates including the TaskBar
1705 if ( !IsIconic( mhWnd ) && !IsZoomed( mhWnd ) &&
1706 (!bVisible || (aPlacement.showCmd == SW_RESTORE)) )
1708 if( bUpdateHiddenFramePos )
1710 RECT aStateRect;
1711 aStateRect.left = nX;
1712 aStateRect.top = nY;
1713 aStateRect.right = nX+nWidth;
1714 aStateRect.bottom = nY+nHeight;
1715 // #96084 set a useful internal window size because
1716 // the window will not be maximized (and the size updated) before show()
1717 SetMaximizedFrameGeometry( mhWnd, this, &aStateRect );
1718 SetWindowPos( mhWnd, nullptr,
1719 maGeometry.nX, maGeometry.nY, maGeometry.nWidth, maGeometry.nHeight,
1720 SWP_NOZORDER | SWP_NOACTIVATE | nPosSize );
1722 else
1723 SetWindowPos( mhWnd, nullptr,
1724 nX, nY, nWidth, nHeight,
1725 SWP_NOZORDER | SWP_NOACTIVATE | nPosSize );
1727 else
1729 if( !(nPosSize & (SWP_NOMOVE|SWP_NOSIZE)) )
1731 aPlacement.rcNormalPosition.left = nX-nScreenX;
1732 aPlacement.rcNormalPosition.top = nY-nScreenY;
1733 aPlacement.rcNormalPosition.right = nX+nWidth-nScreenX;
1734 aPlacement.rcNormalPosition.bottom = nY+nHeight-nScreenY;
1736 SetWindowPlacement( mhWnd, &aPlacement );
1739 if( !(nPosSize & SWP_NOMOVE) )
1740 mbDefPos = false; // window was positioned
1743 bool WinSalFrame::GetWindowState( SalFrameState* pState )
1745 if ( maState.mnWidth && maState.mnHeight )
1747 *pState = maState;
1748 // #94144# allow Minimize again, should be masked out when read from configuration
1749 // 91625 - Don't save minimize
1750 //if ( !(pState->mnState & WindowStateState::Maximized) )
1751 if ( !(pState->mnState & (WindowStateState::Minimized | WindowStateState::Maximized)) )
1752 pState->mnState |= WindowStateState::Normal;
1753 return true;
1756 return false;
1759 void WinSalFrame::SetScreenNumber( unsigned int nNewScreen )
1761 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
1762 if( pSys )
1764 const std::vector<WinSalSystem::DisplayMonitor>& rMonitors =
1765 pSys->getMonitors();
1766 size_t nMon = rMonitors.size();
1767 if( nNewScreen < nMon )
1769 Point aOldMonPos, aNewMonPos( rMonitors[nNewScreen].m_aArea.TopLeft() );
1770 Point aCurPos( maGeometry.nX, maGeometry.nY );
1771 for( size_t i = 0; i < nMon; i++ )
1773 if( rMonitors[i].m_aArea.IsInside( aCurPos ) )
1775 aOldMonPos = rMonitors[i].m_aArea.TopLeft();
1776 break;
1779 mnDisplay = nNewScreen;
1780 maGeometry.nDisplayScreenNumber = nNewScreen;
1781 SetPosSize( aNewMonPos.X() + (maGeometry.nX - aOldMonPos.X()),
1782 aNewMonPos.Y() + (maGeometry.nY - aOldMonPos.Y()),
1783 0, 0,
1784 SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y );
1789 void WinSalFrame::SetApplicationID( const OUString &rApplicationID )
1791 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd378430(v=vs.85).aspx
1792 // A window's properties must be removed before the window is closed.
1794 typedef HRESULT ( WINAPI *SHGETPROPERTYSTOREFORWINDOW )( HWND, REFIID, void ** );
1795 SHGETPROPERTYSTOREFORWINDOW pSHGetPropertyStoreForWindow;
1796 pSHGetPropertyStoreForWindow = reinterpret_cast<SHGETPROPERTYSTOREFORWINDOW>(GetProcAddress(
1797 GetModuleHandleW (L"shell32.dll"), "SHGetPropertyStoreForWindow" ));
1799 if( pSHGetPropertyStoreForWindow )
1801 IPropertyStore *pps;
1802 HRESULT hr = pSHGetPropertyStoreForWindow ( mhWnd, IID_PPV_ARGS(&pps) );
1803 if ( SUCCEEDED(hr) )
1805 PROPVARIANT pv;
1806 if ( !rApplicationID.isEmpty() )
1808 hr = InitPropVariantFromString( o3tl::toW(rApplicationID.getStr()), &pv );
1809 mbPropertiesStored = true;
1811 else
1812 // if rApplicationID we remove the property from the window, if present
1813 PropVariantInit( &pv );
1815 if ( SUCCEEDED(hr) )
1817 hr = pps->SetValue( PKEY_AppUserModel_ID, pv );
1818 PropVariantClear( &pv );
1820 pps->Release();
1825 void WinSalFrame::ShowFullScreen( bool bFullScreen, sal_Int32 nDisplay )
1827 if ( (mbFullScreen == bFullScreen) && (!bFullScreen || (mnDisplay == nDisplay)) )
1828 return;
1830 mbFullScreen = bFullScreen;
1831 mnDisplay = nDisplay;
1833 if ( bFullScreen )
1835 // to hide the Windows taskbar
1836 DWORD nExStyle = GetWindowExStyle( mhWnd );
1837 if ( nExStyle & WS_EX_TOOLWINDOW )
1839 mbFullScreenToolWin = true;
1840 nExStyle &= ~WS_EX_TOOLWINDOW;
1841 SetWindowExStyle( mhWnd, nExStyle );
1843 // save old position
1844 GetWindowRect( mhWnd, &maFullScreenRect );
1846 // save show state
1847 mnFullScreenShowState = mnShowState;
1848 if ( !(GetWindowStyle( mhWnd ) & WS_VISIBLE) )
1849 mnShowState = SW_SHOW;
1851 // set window to screen size
1852 ImplSalFrameFullScreenPos( this, true );
1854 else
1856 // when the ShowState has to be reset, hide the window first to
1857 // reduce flicker
1858 bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
1859 if ( bVisible && (mnShowState != mnFullScreenShowState) )
1860 ShowWindow( mhWnd, SW_HIDE );
1862 if ( mbFullScreenToolWin )
1863 SetWindowExStyle( mhWnd, GetWindowExStyle( mhWnd ) | WS_EX_TOOLWINDOW );
1864 mbFullScreenToolWin = false;
1866 SetWindowPos( mhWnd, nullptr,
1867 maFullScreenRect.left,
1868 maFullScreenRect.top,
1869 maFullScreenRect.right-maFullScreenRect.left,
1870 maFullScreenRect.bottom-maFullScreenRect.top,
1871 SWP_NOZORDER | SWP_NOACTIVATE );
1873 // restore show state
1874 if ( mnShowState != mnFullScreenShowState )
1876 mnShowState = mnFullScreenShowState;
1877 if ( bVisible )
1879 mbInShow = true;
1880 ShowWindow( mhWnd, mnShowState );
1881 mbInShow = false;
1882 UpdateWindow( mhWnd );
1888 void WinSalFrame::StartPresentation( bool bStart )
1890 if ( mbPresentation == bStart )
1891 return;
1893 mbPresentation = bStart;
1895 SalData* pSalData = GetSalData();
1896 if ( bStart )
1898 // turn off screen-saver when in Presentation mode
1899 SystemParametersInfoW( SPI_GETSCREENSAVEACTIVE, 0,
1900 &(pSalData->mbScrSvrEnabled), 0 );
1901 if ( pSalData->mbScrSvrEnabled )
1902 SystemParametersInfoW( SPI_SETSCREENSAVEACTIVE, FALSE, nullptr, 0 );
1904 else
1906 // turn on screen-saver
1907 if ( pSalData->mbScrSvrEnabled )
1908 SystemParametersInfoW( SPI_SETSCREENSAVEACTIVE, pSalData->mbScrSvrEnabled, nullptr, 0 );
1912 void WinSalFrame::SetAlwaysOnTop( bool bOnTop )
1914 HWND hWnd;
1915 if ( bOnTop )
1916 hWnd = HWND_TOPMOST;
1917 else
1918 hWnd = HWND_NOTOPMOST;
1919 SetWindowPos( mhWnd, hWnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
1922 static void ImplSalToTop( HWND hWnd, SalFrameToTop nFlags )
1924 WinSalFrame* pToTopFrame = GetWindowPtr( hWnd );
1925 if( pToTopFrame && (pToTopFrame->mnStyle & SalFrameStyleFlags::SYSTEMCHILD) )
1926 BringWindowToTop( hWnd );
1928 if ( nFlags & SalFrameToTop::ForegroundTask )
1930 // This magic code is necessary to connect the input focus of the
1931 // current window thread and the thread which owns the window that
1932 // should be the new foreground window.
1933 HWND hCurrWnd = GetForegroundWindow();
1934 DWORD myThreadID = GetCurrentThreadId();
1935 DWORD currThreadID = GetWindowThreadProcessId(hCurrWnd,nullptr);
1936 AttachThreadInput(myThreadID, currThreadID,TRUE);
1937 SetForegroundWindow_Impl(hWnd);
1938 AttachThreadInput(myThreadID,currThreadID,FALSE);
1941 if ( nFlags & SalFrameToTop::RestoreWhenMin )
1943 HWND hIconicWnd = hWnd;
1944 while ( hIconicWnd )
1946 if ( IsIconic( hIconicWnd ) )
1948 WinSalFrame* pFrame = GetWindowPtr( hIconicWnd );
1949 if ( pFrame )
1951 if ( GetWindowPtr( hWnd )->mbRestoreMaximize )
1952 ShowWindow( hIconicWnd, SW_MAXIMIZE );
1953 else
1954 ShowWindow( hIconicWnd, SW_RESTORE );
1956 else
1957 ShowWindow( hIconicWnd, SW_RESTORE );
1960 hIconicWnd = ::GetParent( hIconicWnd );
1964 if ( !IsIconic( hWnd ) && IsWindowVisible( hWnd ) )
1966 SetFocus( hWnd );
1968 // Windows sometimes incorrectly reports to have the focus;
1969 // thus make sure to really get the focus
1970 if ( ::GetFocus() == hWnd )
1971 SetForegroundWindow_Impl( hWnd );
1975 void WinSalFrame::ToTop( SalFrameToTop nFlags )
1977 nFlags &= ~SalFrameToTop::GrabFocus; // this flag is not needed on win32
1978 // Post this Message to the window, because this only works
1979 // in the thread of the window, which has create this window.
1980 // We post this message to avoid deadlocks
1981 if ( GetSalData()->mnAppThreadId != GetCurrentThreadId() )
1983 BOOL const ret = PostMessageW( mhWnd, SAL_MSG_TOTOP, static_cast<WPARAM>(nFlags), 0 );
1984 SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
1986 else
1987 ImplSalToTop( mhWnd, nFlags );
1990 void WinSalFrame::SetPointer( PointerStyle ePointerStyle )
1992 struct ImplPtrData
1994 HCURSOR mhCursor;
1995 LPCTSTR mnSysId;
1996 UINT mnOwnId;
1999 static o3tl::enumarray<PointerStyle, ImplPtrData> aImplPtrTab =
2001 ImplPtrData{ nullptr, IDC_ARROW, 0 }, // POINTER_ARROW
2002 { nullptr, nullptr, SAL_RESID_POINTER_NULL }, // POINTER_NULL
2003 { nullptr, IDC_WAIT, 0 }, // POINTER_WAIT
2004 { nullptr, IDC_IBEAM, 0 }, // POINTER_TEXT
2005 { nullptr, IDC_HELP, 0 }, // POINTER_HELP
2006 { nullptr, IDC_CROSS, 0 }, // POINTER_CROSS
2007 { nullptr, IDC_SIZEALL, 0 }, // POINTER_MOVE
2008 { nullptr, IDC_SIZENS, 0 }, // POINTER_NSIZE
2009 { nullptr, IDC_SIZENS, 0 }, // POINTER_SSIZE
2010 { nullptr, IDC_SIZEWE, 0 }, // POINTER_WSIZE
2011 { nullptr, IDC_SIZEWE, 0 }, // POINTER_ESIZE
2012 { nullptr, IDC_SIZENWSE, 0 }, // POINTER_NWSIZE
2013 { nullptr, IDC_SIZENESW, 0 }, // POINTER_NESIZE
2014 { nullptr, IDC_SIZENESW, 0 }, // POINTER_SWSIZE
2015 { nullptr, IDC_SIZENWSE, 0 }, // POINTER_SESIZE
2016 { nullptr, IDC_SIZENS, 0 }, // POINTER_WINDOW_NSIZE
2017 { nullptr, IDC_SIZENS, 0 }, // POINTER_WINDOW_SSIZE
2018 { nullptr, IDC_SIZEWE, 0 }, // POINTER_WINDOW_WSIZE
2019 { nullptr, IDC_SIZEWE, 0 }, // POINTER_WINDOW_ESIZE
2020 { nullptr, IDC_SIZENWSE, 0 }, // POINTER_WINDOW_NWSIZE
2021 { nullptr, IDC_SIZENESW, 0 }, // POINTER_WINDOW_NESIZE
2022 { nullptr, IDC_SIZENESW, 0 }, // POINTER_WINDOW_SWSIZE
2023 { nullptr, IDC_SIZENWSE, 0 }, // POINTER_WINDOW_SESIZE
2024 { nullptr, IDC_SIZEWE, 0 }, // POINTER_HSPLIT
2025 { nullptr, IDC_SIZENS, 0 }, // POINTER_VSPLIT
2026 { nullptr, IDC_SIZEWE, 0 }, // POINTER_HSIZEBAR
2027 { nullptr, IDC_SIZENS, 0 }, // POINTER_VSIZEBAR
2028 { nullptr, IDC_HAND, 0 }, // POINTER_HAND
2029 { nullptr, IDC_HAND, 0 }, // POINTER_REFHAND
2030 { nullptr, IDC_PEN, 0 }, // POINTER_PEN
2031 { nullptr, nullptr, SAL_RESID_POINTER_MAGNIFY }, // POINTER_MAGNIFY
2032 { nullptr, nullptr, SAL_RESID_POINTER_FILL }, // POINTER_FILL
2033 { nullptr, nullptr, SAL_RESID_POINTER_ROTATE }, // POINTER_ROTATE
2034 { nullptr, nullptr, SAL_RESID_POINTER_HSHEAR }, // POINTER_HSHEAR
2035 { nullptr, nullptr, SAL_RESID_POINTER_VSHEAR }, // POINTER_VSHEAR
2036 { nullptr, nullptr, SAL_RESID_POINTER_MIRROR }, // POINTER_MIRROR
2037 { nullptr, nullptr, SAL_RESID_POINTER_CROOK }, // POINTER_CROOK
2038 { nullptr, nullptr, SAL_RESID_POINTER_CROP }, // POINTER_CROP
2039 { nullptr, nullptr, SAL_RESID_POINTER_MOVEPOINT }, // POINTER_MOVEPOINT
2040 { nullptr, nullptr, SAL_RESID_POINTER_MOVEBEZIERWEIGHT }, // POINTER_MOVEBEZIERWEIGHT
2041 { nullptr, nullptr, SAL_RESID_POINTER_MOVEDATA }, // POINTER_MOVEDATA
2042 { nullptr, nullptr, SAL_RESID_POINTER_COPYDATA }, // POINTER_COPYDATA
2043 { nullptr, nullptr, SAL_RESID_POINTER_LINKDATA }, // POINTER_LINKDATA
2044 { nullptr, nullptr, SAL_RESID_POINTER_MOVEDATALINK }, // POINTER_MOVEDATALINK
2045 { nullptr, nullptr, SAL_RESID_POINTER_COPYDATALINK }, // POINTER_COPYDATALINK
2046 { nullptr, nullptr, SAL_RESID_POINTER_MOVEFILE }, // POINTER_MOVEFILE
2047 { nullptr, nullptr, SAL_RESID_POINTER_COPYFILE }, // POINTER_COPYFILE
2048 { nullptr, nullptr, SAL_RESID_POINTER_LINKFILE }, // POINTER_LINKFILE
2049 { nullptr, nullptr, SAL_RESID_POINTER_MOVEFILELINK }, // POINTER_MOVEFILELINK
2050 { nullptr, nullptr, SAL_RESID_POINTER_COPYFILELINK }, // POINTER_COPYFILELINK
2051 { nullptr, nullptr, SAL_RESID_POINTER_MOVEFILES }, // POINTER_MOVEFILES
2052 { nullptr, nullptr, SAL_RESID_POINTER_COPYFILES }, // POINTER_COPYFILES
2053 { nullptr, IDC_NO, 0 }, // POINTER_NOTALLOWED
2054 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_LINE }, // POINTER_DRAW_LINE
2055 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_RECT }, // POINTER_DRAW_RECT
2056 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_POLYGON }, // POINTER_DRAW_POLYGON
2057 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_BEZIER }, // POINTER_DRAW_BEZIER
2058 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_ARC }, // POINTER_DRAW_ARC
2059 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_PIE }, // POINTER_DRAW_PIE
2060 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_CIRCLECUT }, // POINTER_DRAW_CIRCLECUT
2061 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_ELLIPSE }, // POINTER_DRAW_ELLIPSE
2062 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_FREEHAND }, // POINTER_DRAW_FREEHAND
2063 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_CONNECT }, // POINTER_DRAW_CONNECT
2064 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_TEXT }, // POINTER_DRAW_TEXT
2065 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_CAPTION }, // POINTER_DRAW_CAPTION
2066 { nullptr, nullptr, SAL_RESID_POINTER_CHART }, // POINTER_CHART
2067 { nullptr, nullptr, SAL_RESID_POINTER_DETECTIVE }, // POINTER_DETECTIVE
2068 { nullptr, nullptr, SAL_RESID_POINTER_PIVOT_COL }, // POINTER_PIVOT_COL
2069 { nullptr, nullptr, SAL_RESID_POINTER_PIVOT_ROW }, // POINTER_PIVOT_ROW
2070 { nullptr, nullptr, SAL_RESID_POINTER_PIVOT_FIELD }, // POINTER_PIVOT_FIELD
2071 { nullptr, nullptr, SAL_RESID_POINTER_CHAIN }, // POINTER_CHAIN
2072 { nullptr, nullptr, SAL_RESID_POINTER_CHAIN_NOTALLOWED }, // POINTER_CHAIN_NOTALLOWED
2073 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_N }, // POINTER_AUTOSCROLL_N
2074 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_S }, // POINTER_AUTOSCROLL_S
2075 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_W }, // POINTER_AUTOSCROLL_W
2076 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_E }, // POINTER_AUTOSCROLL_E
2077 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NW }, // POINTER_AUTOSCROLL_NW
2078 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NE }, // POINTER_AUTOSCROLL_NE
2079 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_SW }, // POINTER_AUTOSCROLL_SW
2080 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_SE }, // POINTER_AUTOSCROLL_SE
2081 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NS }, // POINTER_AUTOSCROLL_NS
2082 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_WE }, // POINTER_AUTOSCROLL_WE
2083 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NSWE }, // POINTER_AUTOSCROLL_NSWE
2084 { nullptr, nullptr, SAL_RESID_POINTER_TEXT_VERTICAL }, // POINTER_TEXT_VERTICAL
2085 { nullptr, nullptr, SAL_RESID_POINTER_PIVOT_DELETE }, // POINTER_PIVOT_DELETE
2087 // #i32329#
2088 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_S }, // POINTER_TAB_SELECT_S
2089 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_E }, // POINTER_TAB_SELECT_E
2090 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_SE }, // POINTER_TAB_SELECT_SE
2091 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_W }, // POINTER_TAB_SELECT_W
2092 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_SW }, // POINTER_TAB_SELECT_SW
2094 { nullptr, nullptr, SAL_RESID_POINTER_HIDEWHITESPACE }, // POINTER_HIDEWHITESPACE
2095 { nullptr, nullptr, SAL_RESID_POINTER_SHOWWHITESPACE } // POINTER_UNHIDEWHITESPACE
2098 // Mousepointer loaded ?
2099 if ( !aImplPtrTab[ePointerStyle].mhCursor )
2101 if ( aImplPtrTab[ePointerStyle].mnOwnId )
2102 aImplPtrTab[ePointerStyle].mhCursor = ImplLoadSalCursor( aImplPtrTab[ePointerStyle].mnOwnId );
2103 else
2104 aImplPtrTab[ePointerStyle].mhCursor = LoadCursor( nullptr, aImplPtrTab[ePointerStyle].mnSysId );
2107 // change the mouse pointer if different
2108 if ( mhCursor != aImplPtrTab[ePointerStyle].mhCursor )
2110 mhCursor = aImplPtrTab[ePointerStyle].mhCursor;
2111 SetCursor( mhCursor );
2115 void WinSalFrame::CaptureMouse( bool bCapture )
2117 // Send this Message to the window, because CaptureMouse() only work
2118 // in the thread of the window, which has create this window
2119 int nMsg;
2120 if ( bCapture )
2121 nMsg = SAL_MSG_CAPTUREMOUSE;
2122 else
2123 nMsg = SAL_MSG_RELEASEMOUSE;
2124 SendMessageW( mhWnd, nMsg, 0, 0 );
2127 void WinSalFrame::SetPointerPos( long nX, long nY )
2129 POINT aPt;
2130 aPt.x = static_cast<int>(nX);
2131 aPt.y = static_cast<int>(nY);
2132 ClientToScreen( mhWnd, &aPt );
2133 SetCursorPos( aPt.x, aPt.y );
2136 void WinSalFrame::Flush()
2138 GdiFlush();
2141 static void ImplSalFrameSetInputContext( HWND hWnd, const SalInputContext* pContext )
2143 WinSalFrame* pFrame = GetWindowPtr( hWnd );
2144 bool bIME(pContext->mnOptions & InputContextFlags::Text);
2145 if ( bIME )
2147 if ( !pFrame->mbIME )
2149 pFrame->mbIME = true;
2151 if ( pFrame->mhDefIMEContext )
2153 ImmAssociateContext( pFrame->mhWnd, pFrame->mhDefIMEContext );
2154 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY );
2155 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
2156 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
2157 pFrame->mbHandleIME = !pFrame->mbSpezIME;
2161 // When the application can't handle IME messages, then the
2162 // System should handle the IME handling
2163 if ( !(pContext->mnOptions & InputContextFlags::ExtText) )
2164 pFrame->mbHandleIME = false;
2166 // Set the Font for IME Handling
2167 if ( pContext->mpFont )
2169 HIMC hIMC = ImmGetContext( pFrame->mhWnd );
2170 if ( hIMC )
2172 LOGFONTW aLogFont;
2173 HDC hDC = GetDC( pFrame->mhWnd );
2174 // In case of vertical writing, always append a '@' to the
2175 // Windows font name, not only if such a Windows font really is
2176 // available (bTestVerticalAvail == false in the below call):
2177 // The Windows IME's candidates window seems to always use a
2178 // font that has all necessary glyphs, not necessarily the one
2179 // specified by this font name; but it seems to decide whether
2180 // to use that font's horizontal or vertical variant based on a
2181 // '@' in front of this font name.
2182 ImplGetLogFontFromFontSelect(hDC, &pContext->mpFont->GetFontSelectPattern(),
2183 nullptr, aLogFont);
2184 ReleaseDC( pFrame->mhWnd, hDC );
2185 ImmSetCompositionFontW( hIMC, &aLogFont );
2186 ImmReleaseContext( pFrame->mhWnd, hIMC );
2190 else
2192 if ( pFrame->mbIME )
2194 pFrame->mbIME = false;
2195 pFrame->mbHandleIME = false;
2196 ImmAssociateContext( pFrame->mhWnd, nullptr );
2201 void WinSalFrame::SetInputContext( SalInputContext* pContext )
2203 // Must be called in the main thread!
2204 SendMessageW( mhWnd, SAL_MSG_SETINPUTCONTEXT, 0, reinterpret_cast<LPARAM>(pContext) );
2207 static void ImplSalFrameEndExtTextInput( HWND hWnd, EndExtTextInputFlags nFlags )
2209 HIMC hIMC = ImmGetContext( hWnd );
2210 if ( hIMC )
2212 DWORD nIndex;
2213 if ( nFlags & EndExtTextInputFlags::Complete )
2214 nIndex = CPS_COMPLETE;
2215 else
2216 nIndex = CPS_CANCEL;
2218 ImmNotifyIME( hIMC, NI_COMPOSITIONSTR, nIndex, 0 );
2219 ImmReleaseContext( hWnd, hIMC );
2223 void WinSalFrame::EndExtTextInput( EndExtTextInputFlags nFlags )
2225 // Must be called in the main thread!
2226 SendMessageW( mhWnd, SAL_MSG_ENDEXTTEXTINPUT, static_cast<WPARAM>(nFlags), 0 );
2229 static void ImplGetKeyNameText( LONG lParam, sal_Unicode* pBuf,
2230 UINT& rCount, UINT nMaxSize,
2231 const sal_Char* pReplace )
2233 static_assert( sizeof( WCHAR ) == sizeof( sal_Unicode ), "must be the same size" );
2235 static const int nMaxKeyLen = 350;
2236 WCHAR aKeyBuf[ nMaxKeyLen ];
2237 int nKeyLen = 0;
2238 if ( lParam )
2240 OUString aLang = Application::GetSettings().GetUILanguageTag().getLanguage();
2241 OUString aRet;
2243 aRet = ::vcl_sal::getKeysReplacementName( aLang, lParam );
2244 if( aRet.isEmpty() )
2246 nKeyLen = GetKeyNameTextW( lParam, aKeyBuf, nMaxKeyLen );
2247 SAL_WARN_IF( nKeyLen > nMaxKeyLen, "vcl", "Invalid key name length!" );
2248 if( nKeyLen > nMaxKeyLen )
2249 nKeyLen = 0;
2250 else if( nKeyLen > 0 )
2252 // Capitalize just the first letter of key names
2253 CharLowerBuffW( aKeyBuf, nKeyLen );
2255 bool bUpper = true;
2256 for( WCHAR *pW=aKeyBuf, *pE=pW+nKeyLen; pW < pE; ++pW )
2258 if( bUpper )
2259 CharUpperBuffW( pW, 1 );
2260 bUpper = (*pW=='+') || (*pW=='-') || (*pW==' ') || (*pW=='.');
2264 else
2266 nKeyLen = aRet.getLength();
2267 wcscpy( aKeyBuf, o3tl::toW( aRet.getStr() ));
2271 if ( (nKeyLen > 0) || pReplace )
2273 if( (rCount > 0) && (rCount < nMaxSize) )
2275 pBuf[rCount] = '+';
2276 rCount++;
2279 if( nKeyLen > 0 )
2281 WCHAR *pW = aKeyBuf, *pE = aKeyBuf + nKeyLen;
2282 while ((pW < pE) && *pW && (rCount < nMaxSize))
2283 pBuf[rCount++] = *pW++;
2285 else // fall back to provided default name
2287 while( *pReplace && (rCount < nMaxSize) )
2289 pBuf[rCount] = *pReplace;
2290 rCount++;
2291 pReplace++;
2295 else
2296 rCount = 0;
2299 OUString WinSalFrame::GetKeyName( sal_uInt16 nKeyCode )
2301 static const UINT nMaxKeyLen = 350;
2302 sal_Unicode aKeyBuf[ nMaxKeyLen ];
2303 UINT nKeyBufLen = 0;
2304 UINT nSysCode = 0;
2306 if ( nKeyCode & KEY_MOD1 )
2308 nSysCode = MapVirtualKeyW( VK_CONTROL, 0 );
2309 nSysCode = (nSysCode << 16) | ((sal_uLong(1)) << 25);
2310 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Ctrl" );
2313 if ( nKeyCode & KEY_MOD2 )
2315 nSysCode = MapVirtualKeyW( VK_MENU, 0 );
2316 nSysCode = (nSysCode << 16) | ((sal_uLong(1)) << 25);
2317 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Alt" );
2320 if ( nKeyCode & KEY_SHIFT )
2322 nSysCode = MapVirtualKeyW( VK_SHIFT, 0 );
2323 nSysCode = (nSysCode << 16) | ((sal_uLong(1)) << 25);
2324 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Shift" );
2327 sal_uInt16 nCode = nKeyCode & 0x0FFF;
2328 sal_uLong nSysCode2 = 0;
2329 const sal_Char* pReplace = nullptr;
2330 sal_Unicode cSVCode = 0;
2331 sal_Char aFBuf[4];
2332 nSysCode = 0;
2334 if ( (nCode >= KEY_0) && (nCode <= KEY_9) )
2335 cSVCode = '0' + (nCode - KEY_0);
2336 else if ( (nCode >= KEY_A) && (nCode <= KEY_Z) )
2337 cSVCode = 'A' + (nCode - KEY_A);
2338 else if ( (nCode >= KEY_F1) && (nCode <= KEY_F26) )
2340 nSysCode = VK_F1 + (nCode - KEY_F1);
2341 aFBuf[0] = 'F';
2342 if ( (nCode >= KEY_F1) && (nCode <= KEY_F9) )
2344 aFBuf[1] = sal::static_int_cast<sal_Char>('1' + (nCode - KEY_F1));
2345 aFBuf[2] = 0;
2347 else if ( (nCode >= KEY_F10) && (nCode <= KEY_F19) )
2349 aFBuf[1] = '1';
2350 aFBuf[2] = sal::static_int_cast<sal_Char>('0' + (nCode - KEY_F10));
2351 aFBuf[3] = 0;
2353 else
2355 aFBuf[1] = '2';
2356 aFBuf[2] = sal::static_int_cast<sal_Char>('0' + (nCode - KEY_F20));
2357 aFBuf[3] = 0;
2359 pReplace = aFBuf;
2361 else
2363 switch ( nCode )
2365 case KEY_DOWN:
2366 nSysCode = VK_DOWN;
2367 nSysCode2 = ((sal_uLong(1)) << 24);
2368 pReplace = "Down";
2369 break;
2370 case KEY_UP:
2371 nSysCode = VK_UP;
2372 nSysCode2 = ((sal_uLong(1)) << 24);
2373 pReplace = "Up";
2374 break;
2375 case KEY_LEFT:
2376 nSysCode = VK_LEFT;
2377 nSysCode2 = ((sal_uLong(1)) << 24);
2378 pReplace = "Left";
2379 break;
2380 case KEY_RIGHT:
2381 nSysCode = VK_RIGHT;
2382 nSysCode2 = ((sal_uLong(1)) << 24);
2383 pReplace = "Right";
2384 break;
2385 case KEY_HOME:
2386 nSysCode = VK_HOME;
2387 nSysCode2 = ((sal_uLong(1)) << 24);
2388 pReplace = "Home";
2389 break;
2390 case KEY_END:
2391 nSysCode = VK_END;
2392 nSysCode2 = ((sal_uLong(1)) << 24);
2393 pReplace = "End";
2394 break;
2395 case KEY_PAGEUP:
2396 nSysCode = VK_PRIOR;
2397 nSysCode2 = ((sal_uLong(1)) << 24);
2398 pReplace = "Page Up";
2399 break;
2400 case KEY_PAGEDOWN:
2401 nSysCode = VK_NEXT;
2402 nSysCode2 = ((sal_uLong(1)) << 24);
2403 pReplace = "Page Down";
2404 break;
2405 case KEY_RETURN:
2406 nSysCode = VK_RETURN;
2407 pReplace = "Enter";
2408 break;
2409 case KEY_ESCAPE:
2410 nSysCode = VK_ESCAPE;
2411 pReplace = "Escape";
2412 break;
2413 case KEY_TAB:
2414 nSysCode = VK_TAB;
2415 pReplace = "Tab";
2416 break;
2417 case KEY_BACKSPACE:
2418 nSysCode = VK_BACK;
2419 pReplace = "Backspace";
2420 break;
2421 case KEY_SPACE:
2422 nSysCode = VK_SPACE;
2423 pReplace = "Space";
2424 break;
2425 case KEY_INSERT:
2426 nSysCode = VK_INSERT;
2427 nSysCode2 = ((sal_uLong(1)) << 24);
2428 pReplace = "Insert";
2429 break;
2430 case KEY_DELETE:
2431 nSysCode = VK_DELETE;
2432 nSysCode2 = ((sal_uLong(1)) << 24);
2433 pReplace = "Delete";
2434 break;
2436 case KEY_ADD:
2437 cSVCode = '+';
2438 break;
2439 case KEY_SUBTRACT:
2440 cSVCode = '-';
2441 break;
2442 case KEY_MULTIPLY:
2443 cSVCode = '*';
2444 break;
2445 case KEY_DIVIDE:
2446 cSVCode = '/';
2447 break;
2448 case KEY_POINT:
2449 cSVCode = '.';
2450 break;
2451 case KEY_COMMA:
2452 cSVCode = ',';
2453 break;
2454 case KEY_LESS:
2455 cSVCode = '<';
2456 break;
2457 case KEY_GREATER:
2458 cSVCode = '>';
2459 break;
2460 case KEY_EQUAL:
2461 cSVCode = '=';
2462 break;
2463 case KEY_SEMICOLON:
2464 cSVCode = ';';
2465 break;
2466 case KEY_QUOTERIGHT:
2467 cSVCode = '\'';
2468 break;
2469 case KEY_BRACKETLEFT:
2470 cSVCode = '[';
2471 break;
2472 case KEY_BRACKETRIGHT:
2473 cSVCode = ']';
2474 break;
2478 if ( nSysCode )
2480 nSysCode = MapVirtualKeyW( nSysCode, 0 );
2481 if ( nSysCode )
2482 nSysCode = (nSysCode << 16) | nSysCode2;
2483 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, pReplace );
2485 else
2487 if ( cSVCode )
2489 if ( nKeyBufLen > 0 )
2490 aKeyBuf[ nKeyBufLen++ ] = '+';
2491 if( nKeyBufLen < nMaxKeyLen )
2492 aKeyBuf[ nKeyBufLen++ ] = cSVCode;
2496 if( !nKeyBufLen )
2497 return OUString();
2499 return OUString( aKeyBuf, sal::static_int_cast< sal_uInt16 >(nKeyBufLen) );
2502 inline Color ImplWinColorToSal( COLORREF nColor )
2504 return Color( GetRValue( nColor ), GetGValue( nColor ), GetBValue( nColor ) );
2507 static void ImplSalUpdateStyleFontW( HDC hDC, const LOGFONTW& rLogFont, vcl::Font& rFont )
2509 ImplSalLogFontToFontW( hDC, rLogFont, rFont );
2511 // On Windows 9x, Windows NT we get sometimes very small sizes
2512 // (for example for the small Caption height).
2513 // So if it is MS Sans Serif, a none scalable font we use
2514 // 8 Point as the minimum control height, in all other cases
2515 // 6 Point is the smallest one
2516 if ( rFont.GetFontHeight() < 8 )
2518 if ( rtl_ustr_compareIgnoreAsciiCase( o3tl::toU(rLogFont.lfFaceName), o3tl::toU(L"MS Sans Serif") ) == 0 )
2519 rFont.SetFontHeight( 8 );
2520 else if ( rFont.GetFontHeight() < 6 )
2521 rFont.SetFontHeight( 6 );
2525 static long ImplW2I( const wchar_t* pStr )
2527 long n = 0;
2528 int nSign = 1;
2530 if ( *pStr == '-' )
2532 nSign = -1;
2533 pStr++;
2536 while( (*pStr >= 48) && (*pStr <= 57) )
2538 n *= 10;
2539 n += ((*pStr) - 48);
2540 pStr++;
2543 n *= nSign;
2545 return n;
2548 void WinSalFrame::UpdateSettings( AllSettings& rSettings )
2550 MouseSettings aMouseSettings = rSettings.GetMouseSettings();
2551 aMouseSettings.SetDoubleClickTime( GetDoubleClickTime() );
2552 aMouseSettings.SetDoubleClickWidth( GetSystemMetrics( SM_CXDOUBLECLK ) );
2553 aMouseSettings.SetDoubleClickHeight( GetSystemMetrics( SM_CYDOUBLECLK ) );
2554 long nDragWidth = GetSystemMetrics( SM_CXDRAG );
2555 long nDragHeight = GetSystemMetrics( SM_CYDRAG );
2556 if ( nDragWidth )
2557 aMouseSettings.SetStartDragWidth( nDragWidth );
2558 if ( nDragHeight )
2559 aMouseSettings.SetStartDragHeight( nDragHeight );
2560 HKEY hRegKey;
2561 if ( RegOpenKeyW( HKEY_CURRENT_USER,
2562 L"Control Panel\\Desktop",
2563 &hRegKey ) == ERROR_SUCCESS )
2565 wchar_t aValueBuf[10];
2566 DWORD nValueSize = sizeof( aValueBuf );
2567 DWORD nType;
2568 if ( RegQueryValueExW( hRegKey, L"MenuShowDelay", nullptr,
2569 &nType, reinterpret_cast<LPBYTE>(aValueBuf), &nValueSize ) == ERROR_SUCCESS )
2571 if ( nType == REG_SZ )
2572 aMouseSettings.SetMenuDelay( static_cast<sal_uLong>(ImplW2I( aValueBuf )) );
2575 RegCloseKey( hRegKey );
2578 StyleSettings aStyleSettings = rSettings.GetStyleSettings();
2580 aStyleSettings.SetScrollBarSize( GetSystemMetrics( SM_CXVSCROLL ) );
2581 aStyleSettings.SetSpinSize( GetSystemMetrics( SM_CXVSCROLL ) );
2582 UINT blinkTime = GetCaretBlinkTime();
2583 aStyleSettings.SetCursorBlinkTime(
2584 blinkTime == 0 || blinkTime == INFINITE // 0 indicates error
2585 ? STYLE_CURSOR_NOBLINKTIME : blinkTime );
2586 aStyleSettings.SetFloatTitleHeight( GetSystemMetrics( SM_CYSMCAPTION ) );
2587 aStyleSettings.SetTitleHeight( GetSystemMetrics( SM_CYCAPTION ) );
2588 aStyleSettings.SetActiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVEBORDER ) ) );
2589 aStyleSettings.SetDeactiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVEBORDER ) ) );
2590 aStyleSettings.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_GRADIENTINACTIVECAPTION ) ) );
2591 aStyleSettings.SetFaceColor( ImplWinColorToSal( GetSysColor( COLOR_3DFACE ) ) );
2592 aStyleSettings.SetInactiveTabColor( aStyleSettings.GetFaceColor() );
2593 aStyleSettings.SetLightColor( ImplWinColorToSal( GetSysColor( COLOR_3DHILIGHT ) ) );
2594 aStyleSettings.SetLightBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DLIGHT ) ) );
2595 aStyleSettings.SetShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW ) ) );
2596 aStyleSettings.SetDarkShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DDKSHADOW ) ) );
2597 aStyleSettings.SetHelpColor( ImplWinColorToSal( GetSysColor( COLOR_INFOBK ) ) );
2598 aStyleSettings.SetHelpTextColor( ImplWinColorToSal( GetSysColor( COLOR_INFOTEXT ) ) );
2600 aStyleSettings.SetDialogColor( aStyleSettings.GetFaceColor() );
2602 aStyleSettings.SetDialogTextColor( aStyleSettings.GetButtonTextColor() );
2603 aStyleSettings.SetButtonTextColor( ImplWinColorToSal( GetSysColor( COLOR_BTNTEXT ) ) );
2604 aStyleSettings.SetButtonRolloverTextColor( aStyleSettings.GetButtonTextColor() );
2605 aStyleSettings.SetButtonPressedRolloverTextColor( aStyleSettings.GetButtonTextColor() );
2606 aStyleSettings.SetTabTextColor( aStyleSettings.GetButtonTextColor() );
2607 aStyleSettings.SetTabRolloverTextColor( aStyleSettings.GetButtonTextColor() );
2608 aStyleSettings.SetTabHighlightTextColor( aStyleSettings.GetButtonTextColor() );
2609 aStyleSettings.SetRadioCheckTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT ) ) );
2610 aStyleSettings.SetGroupTextColor( aStyleSettings.GetRadioCheckTextColor() );
2611 aStyleSettings.SetLabelTextColor( aStyleSettings.GetRadioCheckTextColor() );
2612 aStyleSettings.SetWindowColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOW ) ) );
2613 aStyleSettings.SetActiveTabColor( aStyleSettings.GetWindowColor() );
2614 aStyleSettings.SetWindowTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT ) ) );
2615 aStyleSettings.SetToolTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT ) ) );
2616 aStyleSettings.SetFieldColor( aStyleSettings.GetWindowColor() );
2617 aStyleSettings.SetFieldTextColor( aStyleSettings.GetWindowTextColor() );
2618 aStyleSettings.SetFieldRolloverTextColor( aStyleSettings.GetFieldTextColor() );
2619 aStyleSettings.SetHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHT ) ) );
2620 aStyleSettings.SetHighlightTextColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHTTEXT ) ) );
2621 aStyleSettings.SetMenuHighlightColor( aStyleSettings.GetHighlightColor() );
2622 aStyleSettings.SetMenuHighlightTextColor( aStyleSettings.GetHighlightTextColor() );
2624 ImplSVData* pSVData = ImplGetSVData();
2625 pSVData->maNWFData.mnMenuFormatBorderX = 0;
2626 pSVData->maNWFData.mnMenuFormatBorderY = 0;
2627 pSVData->maNWFData.maMenuBarHighlightTextColor = COL_TRANSPARENT;
2628 GetSalData()->mbThemeMenuSupport = false;
2629 if (officecfg::Office::Common::Accessibility::AutoDetectSystemHC::get())
2631 aStyleSettings.SetShadowColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVEBORDER ) ) );
2632 aStyleSettings.SetWorkspaceColor( ImplWinColorToSal( GetSysColor( COLOR_MENU ) ) );
2634 aStyleSettings.SetMenuColor( ImplWinColorToSal( GetSysColor( COLOR_MENU ) ) );
2635 aStyleSettings.SetMenuBarColor( aStyleSettings.GetMenuColor() );
2636 aStyleSettings.SetMenuBarRolloverColor( aStyleSettings.GetHighlightColor() );
2637 aStyleSettings.SetMenuBorderColor( aStyleSettings.GetLightBorderColor() ); // overridden below for flat menus
2638 aStyleSettings.SetUseFlatBorders( false );
2639 aStyleSettings.SetUseFlatMenus( false );
2640 aStyleSettings.SetMenuTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT ) ) );
2641 if ( boost::optional<Color> aColor = aStyleSettings.GetPersonaMenuBarTextColor() )
2643 aStyleSettings.SetMenuBarTextColor( *aColor );
2644 aStyleSettings.SetMenuBarRolloverTextColor( *aColor );
2646 else
2648 aStyleSettings.SetMenuBarTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT ) ) );
2649 aStyleSettings.SetMenuBarRolloverTextColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHTTEXT ) ) );
2651 aStyleSettings.SetMenuBarHighlightTextColor(aStyleSettings.GetMenuHighlightTextColor());
2652 aStyleSettings.SetActiveColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVECAPTION ) ) );
2653 aStyleSettings.SetActiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_CAPTIONTEXT ) ) );
2654 aStyleSettings.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTION ) ) );
2655 aStyleSettings.SetDeactiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTIONTEXT ) ) );
2656 BOOL bFlatMenus = FALSE;
2657 SystemParametersInfoW( SPI_GETFLATMENU, 0, &bFlatMenus, 0);
2658 if( bFlatMenus )
2660 aStyleSettings.SetUseFlatMenus( true );
2661 aStyleSettings.SetMenuBarColor( ImplWinColorToSal( GetSysColor( COLOR_MENUBAR ) ) );
2662 aStyleSettings.SetMenuHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_MENUHILIGHT ) ) );
2663 aStyleSettings.SetMenuBarRolloverColor( ImplWinColorToSal( GetSysColor( COLOR_MENUHILIGHT ) ) );
2664 aStyleSettings.SetMenuBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW ) ) );
2666 // flat borders for our controls etc. as well in this mode (ie, no 3d borders)
2667 // this is not active in the classic style appearance
2668 aStyleSettings.SetUseFlatBorders( true );
2670 aStyleSettings.SetCheckedColorSpecialCase( );
2672 // caret width
2673 DWORD nCaretWidth = 2;
2674 if( SystemParametersInfoW( SPI_GETCARETWIDTH, 0, &nCaretWidth, 0 ) )
2675 aStyleSettings.SetCursorSize( nCaretWidth );
2677 // High contrast
2678 HIGHCONTRAST hc;
2679 hc.cbSize = sizeof( HIGHCONTRAST );
2680 if( SystemParametersInfoW( SPI_GETHIGHCONTRAST, hc.cbSize, &hc, 0 )
2681 && (hc.dwFlags & HCF_HIGHCONTRASTON) )
2682 aStyleSettings.SetHighContrastMode( true );
2683 else
2684 aStyleSettings.SetHighContrastMode( false );
2686 // Query Fonts
2687 vcl::Font aMenuFont = aStyleSettings.GetMenuFont();
2688 vcl::Font aTitleFont = aStyleSettings.GetTitleFont();
2689 vcl::Font aFloatTitleFont = aStyleSettings.GetFloatTitleFont();
2690 vcl::Font aHelpFont = aStyleSettings.GetHelpFont();
2691 vcl::Font aAppFont = aStyleSettings.GetAppFont();
2692 vcl::Font aIconFont = aStyleSettings.GetIconFont();
2693 HDC hDC = GetDC( nullptr );
2694 NONCLIENTMETRICSW aNonClientMetrics;
2695 aNonClientMetrics.cbSize = sizeof( aNonClientMetrics );
2696 if ( SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, sizeof( aNonClientMetrics ), &aNonClientMetrics, 0 ) )
2698 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfMenuFont, aMenuFont );
2699 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfCaptionFont, aTitleFont );
2700 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfSmCaptionFont, aFloatTitleFont );
2701 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfStatusFont, aHelpFont );
2702 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfMessageFont, aAppFont );
2704 LOGFONTW aLogFont;
2705 if ( SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &aLogFont, 0 ) )
2706 ImplSalUpdateStyleFontW( hDC, aLogFont, aIconFont );
2709 ReleaseDC( nullptr, hDC );
2711 aStyleSettings.SetToolbarIconSize(ToolbarIconSize::Large);
2713 aStyleSettings.BatchSetFonts( aAppFont, aAppFont );
2715 aStyleSettings.SetMenuFont( aMenuFont );
2716 aStyleSettings.SetTitleFont( aTitleFont );
2717 aStyleSettings.SetFloatTitleFont( aFloatTitleFont );
2718 aStyleSettings.SetHelpFont( aHelpFont );
2719 aStyleSettings.SetIconFont( aIconFont );
2720 // We prefer Arial in the russian version, because MS Sans Serif
2721 // is to wide for the dialogs
2722 if ( rSettings.GetLanguageTag().getLanguageType() == LANGUAGE_RUSSIAN )
2724 OUString aFontName = aAppFont.GetFamilyName();
2725 OUString aFirstName = aFontName.getToken( 0, ';' );
2726 if ( aFirstName.equalsIgnoreAsciiCase( "MS Sans Serif" ) )
2728 aFontName = "Arial;" + aFontName;
2729 aAppFont.SetFamilyName( aFontName );
2733 if ( aAppFont.GetWeight() > WEIGHT_NORMAL )
2734 aAppFont.SetWeight( WEIGHT_NORMAL );
2735 aStyleSettings.SetToolFont( aAppFont );
2736 aStyleSettings.SetTabFont( aAppFont );
2738 BOOL bDragFull;
2739 if ( SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS, 0, &bDragFull, 0 ) )
2741 DragFullOptions nDragFullOptions = aStyleSettings.GetDragFullOptions();
2742 if ( bDragFull )
2743 nDragFullOptions |= DragFullOptions::WindowMove | DragFullOptions::WindowSize | DragFullOptions::Docking | DragFullOptions::Split;
2744 else
2745 nDragFullOptions &= ~DragFullOptions(DragFullOptions::WindowMove | DragFullOptions::WindowSize | DragFullOptions::Docking | DragFullOptions::Split);
2746 aStyleSettings.SetDragFullOptions( nDragFullOptions );
2749 if ( RegOpenKeyW( HKEY_CURRENT_USER,
2750 L"Control Panel\\International\\Calendars\\TwoDigitYearMax",
2751 &hRegKey ) == ERROR_SUCCESS )
2753 wchar_t aValueBuf[10];
2754 DWORD nValue;
2755 DWORD nValueSize = sizeof( aValueBuf );
2756 DWORD nType;
2757 if ( RegQueryValueExW( hRegKey, L"1", nullptr,
2758 &nType, reinterpret_cast<LPBYTE>(aValueBuf), &nValueSize ) == ERROR_SUCCESS )
2760 if ( nType == REG_SZ )
2762 nValue = static_cast<sal_uLong>(ImplW2I( aValueBuf ));
2763 if ( (nValue > 1000) && (nValue < 10000) )
2765 MiscSettings aMiscSettings = rSettings.GetMiscSettings();
2766 utl::MiscCfg().SetYear2000( static_cast<sal_Int32>(nValue-99) );
2767 rSettings.SetMiscSettings( aMiscSettings );
2772 RegCloseKey( hRegKey );
2775 rSettings.SetMouseSettings( aMouseSettings );
2776 rSettings.SetStyleSettings( aStyleSettings );
2778 // now apply the values from theming, if available
2779 WinSalGraphics::updateSettingsNative( rSettings );
2782 const SystemEnvData* WinSalFrame::GetSystemData() const
2784 return &maSysData;
2787 void WinSalFrame::Beep()
2789 // a simple beep
2790 MessageBeep( 0 );
2793 SalFrame::SalPointerState WinSalFrame::GetPointerState()
2795 SalPointerState aState;
2796 aState.mnState = 0;
2798 if ( GetKeyState( VK_LBUTTON ) & 0x8000 )
2799 aState.mnState |= MOUSE_LEFT;
2800 if ( GetKeyState( VK_MBUTTON ) & 0x8000 )
2801 aState.mnState |= MOUSE_MIDDLE;
2802 if ( GetKeyState( VK_RBUTTON ) & 0x8000 )
2803 aState.mnState |= MOUSE_RIGHT;
2804 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
2805 aState.mnState |= KEY_SHIFT;
2806 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
2807 aState.mnState |= KEY_MOD1;
2808 if ( GetKeyState( VK_MENU ) & 0x8000 )
2809 aState.mnState |= KEY_MOD2;
2811 POINT pt;
2812 GetCursorPos( &pt );
2814 aState.maPos = Point( pt.x - maGeometry.nX, pt.y - maGeometry.nY );
2815 return aState;
2818 KeyIndicatorState WinSalFrame::GetIndicatorState()
2820 KeyIndicatorState aState = KeyIndicatorState::NONE;
2821 if (::GetKeyState(VK_CAPITAL))
2822 aState |= KeyIndicatorState::CAPSLOCK;
2824 if (::GetKeyState(VK_NUMLOCK))
2825 aState |= KeyIndicatorState::NUMLOCK;
2827 if (::GetKeyState(VK_SCROLL))
2828 aState |= KeyIndicatorState::SCROLLLOCK;
2830 return aState;
2833 void WinSalFrame::SimulateKeyPress( sal_uInt16 nKeyCode )
2835 BYTE nVKey = 0;
2836 switch (nKeyCode)
2838 case KEY_CAPSLOCK:
2839 nVKey = VK_CAPITAL;
2840 break;
2843 if (nVKey > 0 && nVKey < 255)
2845 ::keybd_event(nVKey, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
2846 ::keybd_event(nVKey, 0x45, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0);
2850 void WinSalFrame::ResetClipRegion()
2852 SetWindowRgn( mhWnd, nullptr, TRUE );
2855 void WinSalFrame::BeginSetClipRegion( sal_uLong nRects )
2857 if( mpClipRgnData )
2858 delete [] reinterpret_cast<BYTE*>(mpClipRgnData);
2859 sal_uLong nRectBufSize = sizeof(RECT)*nRects;
2860 mpClipRgnData = reinterpret_cast<RGNDATA*>(new BYTE[sizeof(RGNDATA)-1+nRectBufSize]);
2861 mpClipRgnData->rdh.dwSize = sizeof( RGNDATAHEADER );
2862 mpClipRgnData->rdh.iType = RDH_RECTANGLES;
2863 mpClipRgnData->rdh.nCount = nRects;
2864 mpClipRgnData->rdh.nRgnSize = nRectBufSize;
2865 SetRectEmpty( &(mpClipRgnData->rdh.rcBound) );
2866 mpNextClipRect = reinterpret_cast<RECT*>(&(mpClipRgnData->Buffer));
2867 mbFirstClipRect = true;
2870 void WinSalFrame::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
2872 if( ! mpClipRgnData )
2873 return;
2875 RECT* pRect = mpNextClipRect;
2876 RECT* pBoundRect = &(mpClipRgnData->rdh.rcBound);
2877 long nRight = nX + nWidth;
2878 long nBottom = nY + nHeight;
2880 if ( mbFirstClipRect )
2882 pBoundRect->left = nX;
2883 pBoundRect->top = nY;
2884 pBoundRect->right = nRight;
2885 pBoundRect->bottom = nBottom;
2886 mbFirstClipRect = false;
2888 else
2890 if ( nX < pBoundRect->left )
2891 pBoundRect->left = static_cast<int>(nX);
2893 if ( nY < pBoundRect->top )
2894 pBoundRect->top = static_cast<int>(nY);
2896 if ( nRight > pBoundRect->right )
2897 pBoundRect->right = static_cast<int>(nRight);
2899 if ( nBottom > pBoundRect->bottom )
2900 pBoundRect->bottom = static_cast<int>(nBottom);
2903 pRect->left = static_cast<int>(nX);
2904 pRect->top = static_cast<int>(nY);
2905 pRect->right = static_cast<int>(nRight);
2906 pRect->bottom = static_cast<int>(nBottom);
2907 if( (mpNextClipRect - reinterpret_cast<RECT*>(&mpClipRgnData->Buffer)) < static_cast<int>(mpClipRgnData->rdh.nCount) )
2908 mpNextClipRect++;
2911 void WinSalFrame::EndSetClipRegion()
2913 if( ! mpClipRgnData )
2914 return;
2916 HRGN hRegion;
2918 // create region from accumulated rectangles
2919 if ( mpClipRgnData->rdh.nCount == 1 )
2921 RECT* pRect = &(mpClipRgnData->rdh.rcBound);
2922 hRegion = CreateRectRgn( pRect->left, pRect->top,
2923 pRect->right, pRect->bottom );
2925 else
2927 sal_uLong nSize = mpClipRgnData->rdh.nRgnSize+sizeof(RGNDATAHEADER);
2928 hRegion = ExtCreateRegion( nullptr, nSize, mpClipRgnData );
2930 delete [] reinterpret_cast<BYTE*>(mpClipRgnData);
2931 mpClipRgnData = nullptr;
2933 SAL_WARN_IF( !hRegion, "vcl", "WinSalFrame::EndSetClipRegion() - Can't create ClipRegion" );
2934 if( hRegion )
2936 RECT aWindowRect;
2937 GetWindowRect( mhWnd, &aWindowRect );
2938 POINT aPt;
2939 aPt.x=0;
2940 aPt.y=0;
2941 ClientToScreen( mhWnd, &aPt );
2942 OffsetRgn( hRegion, aPt.x - aWindowRect.left, aPt.y - aWindowRect.top );
2944 if( SetWindowRgn( mhWnd, hRegion, TRUE ) == 0 )
2945 DeleteObject( hRegion );
2949 static bool ImplHandleMouseMsg( HWND hWnd, UINT nMsg,
2950 WPARAM wParam, LPARAM lParam )
2952 WinSalFrame* pFrame = GetWindowPtr( hWnd );
2953 if ( !pFrame )
2954 return false;
2956 if( nMsg == WM_LBUTTONDOWN || nMsg == WM_MBUTTONDOWN || nMsg == WM_RBUTTONDOWN )
2958 // #103168# post again if async focus has not arrived yet
2959 // hopefully we will not receive the corresponding button up before this
2960 // button down arrives again
2961 vcl::Window *pWin = pFrame->GetWindow();
2962 if( pWin && pWin->ImplGetWindowImpl()->mpFrameData->mnFocusId )
2964 BOOL const ret = PostMessageW( hWnd, nMsg, wParam, lParam );
2965 SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
2966 return true;
2969 SalMouseEvent aMouseEvt;
2970 bool nRet;
2971 SalEvent nEvent = SalEvent::NONE;
2972 bool bCall = true;
2974 aMouseEvt.mnX = static_cast<short>(LOWORD( lParam ));
2975 aMouseEvt.mnY = static_cast<short>(HIWORD( lParam ));
2976 aMouseEvt.mnCode = 0;
2977 aMouseEvt.mnTime = GetMessageTime();
2979 // Use GetKeyState(), as some Logitech mouse drivers do not check
2980 // KeyState when simulating double-click with center mouse button
2982 if ( GetKeyState( VK_LBUTTON ) & 0x8000 )
2983 aMouseEvt.mnCode |= MOUSE_LEFT;
2984 if ( GetKeyState( VK_MBUTTON ) & 0x8000 )
2985 aMouseEvt.mnCode |= MOUSE_MIDDLE;
2986 if ( GetKeyState( VK_RBUTTON ) & 0x8000 )
2987 aMouseEvt.mnCode |= MOUSE_RIGHT;
2988 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
2989 aMouseEvt.mnCode |= KEY_SHIFT;
2990 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
2991 aMouseEvt.mnCode |= KEY_MOD1;
2992 if ( GetKeyState( VK_MENU ) & 0x8000 )
2993 aMouseEvt.mnCode |= KEY_MOD2;
2995 switch ( nMsg )
2997 case WM_MOUSEMOVE:
2999 // As the mouse events are not collected correctly when
3000 // pressing modifier keys (as interrupted by KeyEvents)
3001 // we do this here ourselves
3002 if ( aMouseEvt.mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2) )
3004 MSG aTempMsg;
3005 if ( PeekMessageW( &aTempMsg, hWnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE | PM_NOYIELD ) )
3007 if ( (aTempMsg.message == WM_MOUSEMOVE) &&
3008 (aTempMsg.wParam == wParam) )
3009 return true;
3013 SalData* pSalData = GetSalData();
3014 // Test for MouseLeave
3015 if ( pSalData->mhWantLeaveMsg && (pSalData->mhWantLeaveMsg != hWnd) )
3016 SendMessageW( pSalData->mhWantLeaveMsg, SAL_MSG_MOUSELEAVE, 0, GetMessagePos() );
3018 pSalData->mhWantLeaveMsg = hWnd;
3019 // Start MouseLeave-Timer
3020 if ( !pSalData->mpMouseLeaveTimer )
3022 pSalData->mpMouseLeaveTimer = new AutoTimer;
3023 pSalData->mpMouseLeaveTimer->SetDebugName( "ImplHandleMouseMsg SalData::mpMouseLeaveTimer" );
3024 pSalData->mpMouseLeaveTimer->SetTimeout( SAL_MOUSELEAVE_TIMEOUT );
3025 pSalData->mpMouseLeaveTimer->Start();
3026 // We don't need to set a timeout handler, because we test
3027 // for mouseleave in the timeout callback
3029 aMouseEvt.mnButton = 0;
3030 nEvent = SalEvent::MouseMove;
3032 break;
3034 case WM_NCMOUSEMOVE:
3035 case SAL_MSG_MOUSELEAVE:
3037 SalData* pSalData = GetSalData();
3038 if ( pSalData->mhWantLeaveMsg == hWnd )
3040 // Mouse-Coordinates are relative to the screen
3041 POINT aPt;
3042 aPt.x = static_cast<short>(LOWORD(lParam));
3043 aPt.y = static_cast<short>(HIWORD(lParam));
3044 ScreenToClient(hWnd, &aPt);
3045 if (const auto& pHelpWin = ImplGetSVData()->maHelpData.mpHelpWin)
3047 const tools::Rectangle& rHelpRect = pHelpWin->GetHelpArea();
3048 if (rHelpRect.IsInside(Point(aPt.x, aPt.y)))
3050 // We have entered a tooltip (help window). Don't call the handler here; it
3051 // would launch the sequence "Mouse leaves the Control->Control redraws->
3052 // Help window gets destroyed->Mouse enters the Control->Control redraws",
3053 // which takes CPU and may flicker. Just destroy the help window and pretend
3054 // we are still over the original window.
3055 ImplDestroyHelpWindow(true);
3056 bCall = false;
3057 break;
3060 pSalData->mhWantLeaveMsg = nullptr;
3061 if ( pSalData->mpMouseLeaveTimer )
3063 delete pSalData->mpMouseLeaveTimer;
3064 pSalData->mpMouseLeaveTimer = nullptr;
3066 aMouseEvt.mnX = aPt.x;
3067 aMouseEvt.mnY = aPt.y;
3068 aMouseEvt.mnButton = 0;
3069 nEvent = SalEvent::MouseLeave;
3071 else
3072 bCall = false;
3074 break;
3076 case WM_LBUTTONDOWN:
3077 aMouseEvt.mnButton = MOUSE_LEFT;
3078 nEvent = SalEvent::MouseButtonDown;
3079 break;
3081 case WM_MBUTTONDOWN:
3082 aMouseEvt.mnButton = MOUSE_MIDDLE;
3083 nEvent = SalEvent::MouseButtonDown;
3084 break;
3086 case WM_RBUTTONDOWN:
3087 aMouseEvt.mnButton = MOUSE_RIGHT;
3088 nEvent = SalEvent::MouseButtonDown;
3089 break;
3091 case WM_LBUTTONUP:
3092 aMouseEvt.mnButton = MOUSE_LEFT;
3093 nEvent = SalEvent::MouseButtonUp;
3094 break;
3096 case WM_MBUTTONUP:
3097 aMouseEvt.mnButton = MOUSE_MIDDLE;
3098 nEvent = SalEvent::MouseButtonUp;
3099 break;
3101 case WM_RBUTTONUP:
3102 aMouseEvt.mnButton = MOUSE_RIGHT;
3103 nEvent = SalEvent::MouseButtonUp;
3104 break;
3107 // check if this window was destroyed - this might happen if we are the help window
3108 // and sent a mouse leave message to the application which killed the help window, ie ourselves
3109 if( !IsWindow( hWnd ) )
3110 return false;
3112 if ( bCall )
3114 if ( nEvent == SalEvent::MouseButtonDown )
3115 UpdateWindow( hWnd );
3117 if( AllSettings::GetLayoutRTL() )
3118 aMouseEvt.mnX = pFrame->maGeometry.nWidth-1-aMouseEvt.mnX;
3120 nRet = pFrame->CallCallback( nEvent, &aMouseEvt );
3121 if ( nMsg == WM_MOUSEMOVE )
3122 SetCursor( pFrame->mhCursor );
3124 else
3125 nRet = false;
3127 return nRet;
3130 static bool ImplHandleMouseActivateMsg( HWND hWnd )
3132 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3133 if ( !pFrame )
3134 return false;
3136 if ( pFrame->mbFloatWin )
3137 return true;
3139 return pFrame->CallCallback( SalEvent::MouseActivate, nullptr );
3142 static bool ImplHandleWheelMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
3144 DBG_ASSERT( nMsg == WM_MOUSEWHEEL ||
3145 nMsg == WM_MOUSEHWHEEL,
3146 "ImplHandleWheelMsg() called with no wheel mouse event" );
3148 ImplSalYieldMutexAcquireWithWait();
3150 bool nRet = false;
3151 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3152 if ( pFrame )
3154 WORD nWinModCode = LOWORD( wParam );
3155 POINT aWinPt;
3156 aWinPt.x = static_cast<short>(LOWORD( lParam ));
3157 aWinPt.y = static_cast<short>(HIWORD( lParam ));
3158 ScreenToClient( hWnd, &aWinPt );
3160 SalWheelMouseEvent aWheelEvt;
3161 aWheelEvt.mnTime = GetMessageTime();
3162 aWheelEvt.mnX = aWinPt.x;
3163 aWheelEvt.mnY = aWinPt.y;
3164 aWheelEvt.mnCode = 0;
3165 aWheelEvt.mnDelta = static_cast<short>(HIWORD( wParam ));
3166 aWheelEvt.mnNotchDelta = aWheelEvt.mnDelta/WHEEL_DELTA;
3167 if( aWheelEvt.mnNotchDelta == 0 )
3169 if( aWheelEvt.mnDelta > 0 )
3170 aWheelEvt.mnNotchDelta = 1;
3171 else if( aWheelEvt.mnDelta < 0 )
3172 aWheelEvt.mnNotchDelta = -1;
3175 if( nMsg == WM_MOUSEWHEEL )
3177 if ( aSalShlData.mnWheelScrollLines == WHEEL_PAGESCROLL )
3178 aWheelEvt.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
3179 else
3180 aWheelEvt.mnScrollLines = aSalShlData.mnWheelScrollLines;
3181 aWheelEvt.mbHorz = false;
3183 else
3185 aWheelEvt.mnScrollLines = aSalShlData.mnWheelScrollChars;
3186 aWheelEvt.mbHorz = true;
3188 // fdo#36380 - seems horiz scrolling has swapped direction
3189 aWheelEvt.mnDelta *= -1;
3190 aWheelEvt.mnNotchDelta *= -1;
3193 if ( nWinModCode & MK_SHIFT )
3194 aWheelEvt.mnCode |= KEY_SHIFT;
3195 if ( nWinModCode & MK_CONTROL )
3196 aWheelEvt.mnCode |= KEY_MOD1;
3197 if ( GetKeyState( VK_MENU ) & 0x8000 )
3198 aWheelEvt.mnCode |= KEY_MOD2;
3200 if( AllSettings::GetLayoutRTL() )
3201 aWheelEvt.mnX = pFrame->maGeometry.nWidth-1-aWheelEvt.mnX;
3203 nRet = pFrame->CallCallback( SalEvent::WheelMouse, &aWheelEvt );
3206 ImplSalYieldMutexRelease();
3208 return nRet;
3211 static sal_uInt16 ImplSalGetKeyCode( WPARAM wParam )
3213 sal_uInt16 nKeyCode;
3215 // convert KeyCode
3216 if ( wParam < KEY_TAB_SIZE )
3217 nKeyCode = aImplTranslateKeyTab[wParam];
3218 else
3220 SalData* pSalData = GetSalData();
3221 std::map< UINT, sal_uInt16 >::const_iterator it = pSalData->maVKMap.find( static_cast<UINT>(wParam) );
3222 if( it != pSalData->maVKMap.end() )
3223 nKeyCode = it->second;
3224 else
3225 nKeyCode = 0;
3228 return nKeyCode;
3231 static void ImplUpdateInputLang( WinSalFrame* pFrame )
3233 UINT nLang = LOWORD( GetKeyboardLayout( 0 ) );
3234 if ( nLang && nLang != pFrame->mnInputLang )
3236 // keep input lang up-to-date
3237 pFrame->mnInputLang = nLang;
3240 // We are on Windows NT so we use Unicode FrameProcs and get
3241 // Unicode charcodes directly from Windows no need to set up a
3242 // code page
3243 return;
3246 static sal_Unicode ImplGetCharCode( WinSalFrame* pFrame, WPARAM nCharCode )
3248 ImplUpdateInputLang( pFrame );
3250 // We are on Windows NT so we use Unicode FrameProcs and we
3251 // get Unicode charcodes directly from Windows
3252 return static_cast<sal_Unicode>(nCharCode);
3255 LanguageType WinSalFrame::GetInputLanguage()
3257 if( !mnInputLang )
3258 ImplUpdateInputLang( this );
3260 if( !mnInputLang )
3261 return LANGUAGE_DONTKNOW;
3262 else
3263 return LanguageType(mnInputLang);
3266 bool WinSalFrame::MapUnicodeToKeyCode( sal_Unicode aUnicode, LanguageType aLangType, vcl::KeyCode& rKeyCode )
3268 bool bRet = false;
3269 sal_IntPtr nLangType = static_cast<sal_uInt16>(aLangType);
3270 // just use the passed language identifier, do not try to load additional keyboard support
3271 HKL hkl = reinterpret_cast<HKL>(nLangType);
3273 if( hkl )
3275 SHORT scan = VkKeyScanExW( aUnicode, hkl );
3276 if( LOWORD(scan) == 0xFFFF )
3277 // keyboard not loaded or key cannot be mapped
3278 bRet = false;
3279 else
3281 BYTE vkeycode = LOBYTE(scan);
3282 BYTE shiftstate = HIBYTE(scan);
3284 // Last argument is set to false, because there's no decision made
3285 // yet which key should be assigned to MOD3 modifier on Windows.
3286 // Windows key - user's can be confused, because it should display
3287 // Windows menu (applies to both left/right key)
3288 // Menu key - this key is used to display context menu
3289 // AltGr key - probably it has no sense
3290 rKeyCode = vcl::KeyCode( ImplSalGetKeyCode( vkeycode ),
3291 (shiftstate & 0x01) != 0, // shift
3292 (shiftstate & 0x02) != 0, // ctrl
3293 (shiftstate & 0x04) != 0, // alt
3294 false );
3295 bRet = true;
3299 return bRet;
3302 static bool ImplHandleKeyMsg( HWND hWnd, UINT nMsg,
3303 WPARAM wParam, LPARAM lParam, LRESULT& rResult )
3305 static bool bIgnoreCharMsg = false;
3306 static WPARAM nDeadChar = 0;
3307 static WPARAM nLastVKChar = 0;
3308 static sal_uInt16 nLastChar = 0;
3309 static ModKeyFlags nLastModKeyCode = ModKeyFlags::NONE;
3310 static bool bWaitForModKeyRelease = false;
3311 sal_uInt16 nRepeat = LOWORD( lParam )-1;
3312 sal_uInt16 nModCode = 0;
3314 // this key might have been relayed by SysChild and thus
3315 // may not be processed twice
3316 GetSalData()->mnSalObjWantKeyEvt = 0;
3318 if ( nMsg == WM_DEADCHAR )
3320 nDeadChar = wParam;
3321 return false;
3324 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3325 if ( !pFrame )
3326 return false;
3328 // reset the background mode for each text input,
3329 // as some tools such as RichWin may have changed it
3330 if ( pFrame->mpLocalGraphics &&
3331 pFrame->mpLocalGraphics->getHDC() )
3332 SetBkMode( pFrame->mpLocalGraphics->getHDC(), TRANSPARENT );
3334 // determine modifiers
3335 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3336 nModCode |= KEY_SHIFT;
3337 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3338 nModCode |= KEY_MOD1;
3339 if (GetKeyState(VK_MENU) & 0x8000)
3340 nModCode |= KEY_MOD2;
3342 if ( (nMsg == WM_CHAR) || (nMsg == WM_SYSCHAR) )
3344 nDeadChar = 0;
3346 if ( bIgnoreCharMsg )
3348 bIgnoreCharMsg = false;
3349 // #101635# if zero is returned here for WM_SYSCHAR (ALT+<key>) Windows will beep
3350 // because this 'hotkey' was not processed -> better return 1
3351 // except for Alt-SPACE which should always open the sysmenu (#104616#)
3353 // also return zero if a system menubar is available that might process this hotkey
3354 // this also applies to the OLE inplace embedding where we are a child window
3355 if( (GetWindowStyle( hWnd ) & WS_CHILD) || GetMenu( hWnd ) || (wParam == 0x20) )
3356 return false;
3357 else
3358 return true;
3361 // ignore backspace as a single key, so that
3362 // we do not get problems for combinations w/ a DeadKey
3363 if ( wParam == 0x08 ) // BACKSPACE
3364 return false;
3366 // only "free flying" WM_CHAR messages arrive here, that are
3367 // created by typing a ALT-NUMPAD combination
3368 SalKeyEvent aKeyEvt;
3370 if ( (wParam >= '0') && (wParam <= '9') )
3371 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_NUM + wParam - '0');
3372 else if ( (wParam >= 'A') && (wParam <= 'Z') )
3373 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_ALPHA + wParam - 'A');
3374 else if ( (wParam >= 'a') && (wParam <= 'z') )
3375 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_ALPHA + wParam - 'a');
3376 else if ( wParam == 0x0D ) // RETURN
3377 aKeyEvt.mnCode = KEY_RETURN;
3378 else if ( wParam == 0x1B ) // ESCAPE
3379 aKeyEvt.mnCode = KEY_ESCAPE;
3380 else if ( wParam == 0x09 ) // TAB
3381 aKeyEvt.mnCode = KEY_TAB;
3382 else if ( wParam == 0x20 ) // SPACE
3383 aKeyEvt.mnCode = KEY_SPACE;
3384 else
3385 aKeyEvt.mnCode = 0;
3387 aKeyEvt.mnCode |= nModCode;
3388 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, wParam );
3389 aKeyEvt.mnRepeat = nRepeat;
3390 nLastChar = 0;
3391 nLastVKChar = 0;
3392 bool nRet = pFrame->CallCallback( SalEvent::KeyInput, &aKeyEvt );
3393 pFrame->CallCallback( SalEvent::KeyUp, &aKeyEvt );
3394 return nRet;
3396 // #i11583#, MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition begins
3397 else if( nMsg == WM_UNICHAR )
3399 // If Windows is asking if we accept WM_UNICHAR, return TRUE
3400 if(wParam == UNICODE_NOCHAR)
3402 rResult = TRUE; // ssa: this will actually return TRUE to windows
3403 return true; // ...but this will only avoid calling the defwindowproc
3406 SalKeyEvent aKeyEvt;
3407 aKeyEvt.mnCode = nModCode; // Or should it be 0? - as this is always a character returned
3408 aKeyEvt.mnRepeat = 0;
3410 if( wParam >= Uni_SupplementaryPlanesStart )
3412 // character is supplementary char in UTF-32 format - must be converted to UTF-16 supplementary pair
3413 // sal_Unicode ch = (sal_Unicode) Uni_UTF32ToSurrogate1(wParam);
3414 nLastChar = 0;
3415 nLastVKChar = 0;
3416 pFrame->CallCallback( SalEvent::KeyInput, &aKeyEvt );
3417 pFrame->CallCallback( SalEvent::KeyUp, &aKeyEvt );
3418 wParam = static_cast<sal_Unicode>(Uni_UTF32ToSurrogate2( wParam ));
3421 aKeyEvt.mnCharCode = static_cast<sal_Unicode>(wParam);
3423 nLastChar = 0;
3424 nLastVKChar = 0;
3425 bool nRet = pFrame->CallCallback( SalEvent::KeyInput, &aKeyEvt );
3426 pFrame->CallCallback( SalEvent::KeyUp, &aKeyEvt );
3428 return nRet;
3430 // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition ends
3431 else
3433 // for shift, control and menu we issue a KeyModChange event
3434 if ( (wParam == VK_SHIFT) || (wParam == VK_CONTROL) || (wParam == VK_MENU) )
3436 SalKeyModEvent aModEvt;
3437 aModEvt.mbDown = false; // auto-accelerator feature not supported here.
3438 aModEvt.mnCode = nModCode;
3439 aModEvt.mnModKeyCode = ModKeyFlags::NONE; // no command events will be sent if this member is 0
3441 ModKeyFlags tmpCode = ModKeyFlags::NONE;
3442 if( GetKeyState( VK_LSHIFT ) & 0x8000 )
3443 tmpCode |= ModKeyFlags::LeftShift;
3444 if( GetKeyState( VK_RSHIFT ) & 0x8000 )
3445 tmpCode |= ModKeyFlags::RightShift;
3446 if( GetKeyState( VK_LCONTROL ) & 0x8000 )
3447 tmpCode |= ModKeyFlags::LeftMod1;
3448 if( GetKeyState( VK_RCONTROL ) & 0x8000 )
3449 tmpCode |= ModKeyFlags::RightMod1;
3450 if( GetKeyState( VK_LMENU ) & 0x8000 )
3451 tmpCode |= ModKeyFlags::LeftMod2;
3452 if( GetKeyState( VK_RMENU ) & 0x8000 )
3453 tmpCode |= ModKeyFlags::RightMod2;
3455 if( tmpCode < nLastModKeyCode )
3457 aModEvt.mnModKeyCode = nLastModKeyCode;
3458 nLastModKeyCode = ModKeyFlags::NONE;
3459 bWaitForModKeyRelease = true;
3461 else
3463 if( !bWaitForModKeyRelease )
3464 nLastModKeyCode = tmpCode;
3467 if( tmpCode == ModKeyFlags::NONE )
3468 bWaitForModKeyRelease = false;
3470 return pFrame->CallCallback( SalEvent::KeyModChange, &aModEvt );
3472 else
3474 SalKeyEvent aKeyEvt;
3475 SalEvent nEvent;
3476 MSG aCharMsg;
3477 BOOL bCharPeek = FALSE;
3478 UINT nCharMsg = WM_CHAR;
3479 bool bKeyUp = (nMsg == WM_KEYUP) || (nMsg == WM_SYSKEYUP);
3481 nLastModKeyCode = ModKeyFlags::NONE; // make sure no modkey messages are sent if they belong to a hotkey (see above)
3482 aKeyEvt.mnCharCode = 0;
3483 aKeyEvt.mnCode = 0;
3485 aKeyEvt.mnCode = ImplSalGetKeyCode( wParam );
3486 if ( !bKeyUp )
3488 // check for charcode
3489 // Get the related WM_CHAR message using PeekMessage, if available.
3490 // The WM_CHAR message is always at the beginning of the
3491 // message queue. Also it is made certain that there is always only
3492 // one WM_CHAR message in the queue.
3493 bCharPeek = PeekMessageW( &aCharMsg, hWnd,
3494 WM_CHAR, WM_CHAR, PM_NOREMOVE | PM_NOYIELD );
3495 if ( bCharPeek && (nDeadChar == aCharMsg.wParam) )
3497 bCharPeek = FALSE;
3498 nDeadChar = 0;
3500 if ( wParam == VK_BACK )
3502 PeekMessageW( &aCharMsg, hWnd,
3503 nCharMsg, nCharMsg, PM_REMOVE | PM_NOYIELD );
3504 return false;
3507 else
3509 if ( !bCharPeek )
3511 bCharPeek = PeekMessageW( &aCharMsg, hWnd,
3512 WM_SYSCHAR, WM_SYSCHAR, PM_NOREMOVE | PM_NOYIELD );
3513 nCharMsg = WM_SYSCHAR;
3516 if ( bCharPeek )
3517 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, aCharMsg.wParam );
3518 else
3519 aKeyEvt.mnCharCode = 0;
3521 nLastChar = aKeyEvt.mnCharCode;
3522 nLastVKChar = wParam;
3524 else
3526 if ( wParam == nLastVKChar )
3528 aKeyEvt.mnCharCode = nLastChar;
3529 nLastChar = 0;
3530 nLastVKChar = 0;
3534 if ( aKeyEvt.mnCode || aKeyEvt.mnCharCode )
3536 if ( bKeyUp )
3537 nEvent = SalEvent::KeyUp;
3538 else
3539 nEvent = SalEvent::KeyInput;
3541 aKeyEvt.mnCode |= nModCode;
3542 aKeyEvt.mnRepeat = nRepeat;
3544 if ((nModCode & (KEY_MOD1 | KEY_MOD2)) == (KEY_MOD1 | KEY_MOD2) &&
3545 aKeyEvt.mnCharCode)
3547 // this is actually AltGr and should not be handled as Alt
3548 aKeyEvt.mnCode &= ~(KEY_MOD1 | KEY_MOD2);
3551 bIgnoreCharMsg = bCharPeek;
3552 bool nRet = pFrame->CallCallback( nEvent, &aKeyEvt );
3553 // independent part only reacts on keyup but Windows does not send
3554 // keyup for VK_HANJA
3555 if( aKeyEvt.mnCode == KEY_HANGUL_HANJA )
3556 nRet = pFrame->CallCallback( SalEvent::KeyUp, &aKeyEvt );
3558 bIgnoreCharMsg = false;
3560 // char-message, than remove or ignore
3561 if ( bCharPeek )
3563 nDeadChar = 0;
3564 if ( nRet )
3566 PeekMessageW( &aCharMsg, hWnd,
3567 nCharMsg, nCharMsg, PM_REMOVE | PM_NOYIELD );
3569 else
3570 bIgnoreCharMsg = true;
3573 return nRet;
3575 else
3576 return false;
3581 bool ImplHandleSalObjKeyMsg( HWND hWnd, UINT nMsg,
3582 WPARAM wParam, LPARAM lParam )
3584 if ( (nMsg == WM_KEYDOWN) || (nMsg == WM_KEYUP) )
3586 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3587 if ( !pFrame )
3588 return false;
3590 sal_uInt16 nRepeat = LOWORD( lParam )-1;
3591 sal_uInt16 nModCode = 0;
3593 // determine modifiers
3594 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3595 nModCode |= KEY_SHIFT;
3596 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3597 nModCode |= KEY_MOD1;
3598 if ( GetKeyState( VK_MENU ) & 0x8000 )
3599 nModCode |= KEY_MOD2;
3601 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) && (wParam != VK_MENU) )
3603 SalKeyEvent aKeyEvt;
3604 SalEvent nEvent;
3605 bool bKeyUp = (nMsg == WM_KEYUP) || (nMsg == WM_SYSKEYUP);
3607 // convert KeyCode
3608 aKeyEvt.mnCode = ImplSalGetKeyCode( wParam );
3609 aKeyEvt.mnCharCode = 0;
3611 if ( aKeyEvt.mnCode )
3613 if ( bKeyUp )
3614 nEvent = SalEvent::KeyUp;
3615 else
3616 nEvent = SalEvent::KeyInput;
3618 aKeyEvt.mnCode |= nModCode;
3619 aKeyEvt.mnRepeat = nRepeat;
3620 bool nRet = pFrame->CallCallback( nEvent, &aKeyEvt );
3621 return nRet;
3623 else
3624 return false;
3628 return false;
3631 bool ImplHandleSalObjSysCharMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
3633 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3634 if ( !pFrame )
3635 return false;
3637 sal_uInt16 nRepeat = LOWORD( lParam )-1;
3638 sal_uInt16 nModCode = 0;
3639 sal_uInt16 cKeyCode = static_cast<sal_uInt16>(wParam);
3641 // determine modifiers
3642 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3643 nModCode |= KEY_SHIFT;
3644 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3645 nModCode |= KEY_MOD1;
3646 nModCode |= KEY_MOD2;
3648 // assemble KeyEvent
3649 SalKeyEvent aKeyEvt;
3650 if ( (cKeyCode >= 48) && (cKeyCode <= 57) )
3651 aKeyEvt.mnCode = KEY_0+(cKeyCode-48);
3652 else if ( (cKeyCode >= 65) && (cKeyCode <= 90) )
3653 aKeyEvt.mnCode = KEY_A+(cKeyCode-65);
3654 else if ( (cKeyCode >= 97) && (cKeyCode <= 122) )
3655 aKeyEvt.mnCode = KEY_A+(cKeyCode-97);
3656 else
3657 aKeyEvt.mnCode = 0;
3658 aKeyEvt.mnCode |= nModCode;
3659 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, cKeyCode );
3660 aKeyEvt.mnRepeat = nRepeat;
3661 bool nRet = pFrame->CallCallback( SalEvent::KeyInput, &aKeyEvt );
3662 pFrame->CallCallback( SalEvent::KeyUp, &aKeyEvt );
3663 return nRet;
3666 enum class DeferPolicy
3668 Blocked,
3669 Allowed
3672 // Remember to release the solar mutex on success!
3673 static inline WinSalFrame* ProcessOrDeferMessage( HWND hWnd, INT nMsg, WPARAM pWParam = 0,
3674 DeferPolicy eCanDefer = DeferPolicy::Allowed )
3676 bool bFailedCondition = false, bGotMutex = false;
3677 WinSalFrame* pFrame = nullptr;
3679 if ( DeferPolicy::Blocked == eCanDefer )
3680 assert( (DeferPolicy::Blocked == eCanDefer) && (nMsg == 0) && (pWParam == 0) );
3681 else
3682 assert( (DeferPolicy::Allowed == eCanDefer) && (nMsg != 0) );
3684 if ( DeferPolicy::Blocked == eCanDefer )
3686 ImplSalYieldMutexAcquireWithWait();
3687 bGotMutex = true;
3689 else if ( !(bGotMutex = ImplSalYieldMutexTryToAcquire()) )
3690 bFailedCondition = true;
3692 if ( !bFailedCondition )
3694 pFrame = GetWindowPtr( hWnd );
3695 bFailedCondition = pFrame == nullptr;
3698 if ( bFailedCondition )
3700 if ( bGotMutex )
3701 ImplSalYieldMutexRelease();
3702 if ( DeferPolicy::Allowed == eCanDefer )
3704 BOOL const ret = PostMessageW(hWnd, nMsg, pWParam, 0);
3705 SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
3709 return pFrame;
3712 enum class PostedState
3714 IsPosted,
3715 IsInitial
3718 static bool ImplHandlePostPaintMsg( HWND hWnd, RECT* pRect,
3719 PostedState eProcessed = PostedState::IsPosted )
3721 RECT* pMsgRect;
3722 if ( PostedState::IsInitial == eProcessed )
3724 pMsgRect = new RECT;
3725 CopyRect( pMsgRect, pRect );
3727 else
3728 pMsgRect = pRect;
3730 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTPAINT,
3731 reinterpret_cast<WPARAM>(pMsgRect) );
3732 if ( pFrame )
3734 SalPaintEvent aPEvt( pRect->left, pRect->top, pRect->right-pRect->left, pRect->bottom-pRect->top );
3735 pFrame->CallCallback( SalEvent::Paint, &aPEvt );
3736 ImplSalYieldMutexRelease();
3737 if ( PostedState::IsPosted == eProcessed )
3738 delete pRect;
3741 return (pFrame != nullptr);
3744 static bool ImplHandlePaintMsg( HWND hWnd )
3746 bool bPaintSuccessful = false;
3748 // even without the Yield mutex, we can still change the clip region,
3749 // because other threads don't use the Yield mutex
3750 // --> see AcquireGraphics()
3752 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3753 if ( pFrame )
3755 // clip region must be set, as we don't get a proper
3756 // bounding rectangle otherwise
3757 WinSalGraphics *pGraphics = pFrame->mpLocalGraphics;
3758 bool bHasClipRegion = pGraphics &&
3759 pGraphics->getHDC() && pGraphics->getRegion();
3760 if ( bHasClipRegion )
3761 SelectClipRgn( pGraphics->getHDC(), nullptr );
3763 // according to Windows documentation one shall check first if
3764 // there really is a paint-region
3765 RECT aUpdateRect;
3766 PAINTSTRUCT aPs;
3767 bool bHasPaintRegion = GetUpdateRect( hWnd, nullptr, FALSE );
3768 if ( bHasPaintRegion )
3770 // call BeginPaint/EndPaint to query the paint rect and use
3771 // this information in the (deferred) paint
3772 BeginPaint( hWnd, &aPs );
3773 CopyRect( &aUpdateRect, &aPs.rcPaint );
3776 // reset clip region
3777 if ( bHasClipRegion )
3778 SelectClipRgn( pGraphics->getHDC(), pGraphics->getRegion() );
3780 // try painting
3781 if ( bHasPaintRegion )
3783 bPaintSuccessful = ImplHandlePostPaintMsg(
3784 hWnd, &aUpdateRect, PostedState::IsInitial );
3785 EndPaint( hWnd, &aPs );
3787 else // if there is nothing to paint, the paint is successful
3788 bPaintSuccessful = true;
3791 return bPaintSuccessful;
3794 static void SetMaximizedFrameGeometry( HWND hWnd, WinSalFrame* pFrame, RECT* pParentRect )
3796 // calculate and set frame geometry of a maximized window - useful if the window is still hidden
3798 // dualmonitor support:
3799 // Get screensize of the monitor with the mouse pointer
3801 RECT aRectMouse;
3802 if( ! pParentRect )
3804 POINT pt;
3805 GetCursorPos( &pt );
3806 aRectMouse.left = pt.x;
3807 aRectMouse.top = pt.y;
3808 aRectMouse.right = pt.x+2;
3809 aRectMouse.bottom = pt.y+2;
3810 pParentRect = &aRectMouse;
3813 RECT aRect;
3814 ImplSalGetWorkArea( hWnd, &aRect, pParentRect );
3816 // a maximized window has no other borders than the caption
3817 pFrame->maGeometry.nLeftDecoration = pFrame->maGeometry.nRightDecoration = pFrame->maGeometry.nBottomDecoration = 0;
3818 pFrame->maGeometry.nTopDecoration = pFrame->mbCaption ? GetSystemMetrics( SM_CYCAPTION ) : 0;
3820 aRect.top += pFrame->maGeometry.nTopDecoration;
3821 pFrame->maGeometry.nX = aRect.left;
3822 pFrame->maGeometry.nY = aRect.top;
3823 pFrame->maGeometry.nWidth = aRect.right - aRect.left;
3824 pFrame->maGeometry.nHeight = aRect.bottom - aRect.top;
3827 static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame )
3829 if( !pFrame )
3830 return;
3832 RECT aRect;
3833 GetWindowRect( hWnd, &aRect );
3834 memset(&pFrame->maGeometry, 0, sizeof(SalFrameGeometry) );
3836 if ( IsIconic( hWnd ) )
3837 return;
3839 POINT aPt;
3840 aPt.x=0;
3841 aPt.y=0;
3842 ClientToScreen(hWnd, &aPt);
3843 int cx = aPt.x - aRect.left;
3844 pFrame->maGeometry.nTopDecoration = aPt.y - aRect.top;
3846 pFrame->maGeometry.nLeftDecoration = cx;
3847 pFrame->maGeometry.nRightDecoration = cx;
3849 pFrame->maGeometry.nX = aPt.x;
3850 pFrame->maGeometry.nY = aPt.y;
3852 RECT aInnerRect;
3853 GetClientRect( hWnd, &aInnerRect );
3854 if( aInnerRect.right )
3856 // improve right decoration
3857 aPt.x=aInnerRect.right;
3858 aPt.y=aInnerRect.top;
3859 ClientToScreen(hWnd, &aPt);
3860 pFrame->maGeometry.nRightDecoration = aRect.right - aPt.x;
3862 if( aInnerRect.bottom ) // may be zero if window was not shown yet
3863 pFrame->maGeometry.nBottomDecoration += aRect.bottom - aPt.y - aInnerRect.bottom;
3864 else
3865 // bottom border is typically the same as left/right
3866 pFrame->maGeometry.nBottomDecoration = pFrame->maGeometry.nLeftDecoration;
3868 int nWidth = aRect.right - aRect.left
3869 - pFrame->maGeometry.nRightDecoration - pFrame->maGeometry.nLeftDecoration;
3870 int nHeight = aRect.bottom - aRect.top
3871 - pFrame->maGeometry.nBottomDecoration - pFrame->maGeometry.nTopDecoration;
3872 // clamp to zero
3873 pFrame->maGeometry.nHeight = nHeight < 0 ? 0 : nHeight;
3874 pFrame->maGeometry.nWidth = nWidth < 0 ? 0 : nWidth;
3875 pFrame->updateScreenNumber();
3878 static void ImplCallMoveHdl( HWND hWnd )
3880 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3881 if ( pFrame )
3883 pFrame->CallCallback( SalEvent::Move, nullptr );
3884 // to avoid doing Paint twice by VCL and SAL
3885 //if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
3886 // UpdateWindow( hWnd );
3890 static void ImplCallClosePopupsHdl( HWND hWnd )
3892 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3893 if ( pFrame )
3895 pFrame->CallCallback( SalEvent::ClosePopups, nullptr );
3899 static void ImplHandleMoveMsg( HWND hWnd )
3901 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTMOVE );
3902 if ( pFrame )
3904 UpdateFrameGeometry( hWnd, pFrame );
3906 if ( GetWindowStyle( hWnd ) & WS_VISIBLE )
3907 pFrame->mbDefPos = false;
3909 // protect against recursion
3910 if ( !pFrame->mbInMoveMsg )
3912 // adjust window again for FullScreenMode
3913 pFrame->mbInMoveMsg = true;
3914 if ( pFrame->mbFullScreen )
3915 ImplSalFrameFullScreenPos( pFrame );
3916 pFrame->mbInMoveMsg = false;
3919 // save state
3920 ImplSaveFrameState( pFrame );
3922 // Call Hdl
3923 //#93851 if we call this handler, VCL floating windows are not updated correctly
3924 ImplCallMoveHdl( hWnd );
3926 ImplSalYieldMutexRelease();
3930 static void ImplCallSizeHdl( HWND hWnd )
3932 // as Windows can send these messages also, we have to use
3933 // the Solar semaphore
3934 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTCALLSIZE );
3935 if ( pFrame )
3937 pFrame->CallCallback( SalEvent::Resize, nullptr );
3938 // to avoid double Paints by VCL and SAL
3939 if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
3940 UpdateWindow( hWnd );
3942 ImplSalYieldMutexRelease();
3946 static void ImplHandleSizeMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
3948 if ( (wParam != SIZE_MAXSHOW) && (wParam != SIZE_MAXHIDE) )
3950 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3951 if ( pFrame )
3953 UpdateFrameGeometry( hWnd, pFrame );
3955 pFrame->mnWidth = static_cast<int>(LOWORD(lParam));
3956 pFrame->mnHeight = static_cast<int>(HIWORD(lParam));
3957 // save state
3958 ImplSaveFrameState( pFrame );
3959 // Call Hdl
3960 ImplCallSizeHdl( hWnd );
3962 WinSalTimer* pTimer = static_cast<WinSalTimer*>( ImplGetSVData()->maSchedCtx.mpSalTimer );
3963 if ( pTimer )
3964 pTimer->SetForceRealTimer( true );
3969 static void ImplHandleFocusMsg( HWND hWnd )
3971 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTFOCUS );
3972 if ( pFrame )
3974 if ( !WinSalFrame::mbInReparent )
3976 bool bGotFocus = ::GetFocus() == hWnd;
3977 if ( bGotFocus )
3979 if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
3980 UpdateWindow( hWnd );
3982 // do we support IME?
3983 if ( pFrame->mbIME && pFrame->mhDefIMEContext )
3985 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY );
3987 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
3988 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
3989 pFrame->mbHandleIME = !pFrame->mbSpezIME;
3992 pFrame->CallCallback( bGotFocus ? SalEvent::GetFocus : SalEvent::LoseFocus, nullptr );
3994 ImplSalYieldMutexRelease();
3998 static void ImplHandleCloseMsg( HWND hWnd )
4000 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, WM_CLOSE );
4001 if ( pFrame )
4003 pFrame->CallCallback( SalEvent::Close, nullptr );
4004 ImplSalYieldMutexRelease();
4008 static bool ImplHandleShutDownMsg( HWND hWnd )
4010 bool nRet = false;
4011 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, 0, 0, DeferPolicy::Blocked );
4012 if ( pFrame )
4014 nRet = pFrame->CallCallback( SalEvent::Shutdown, nullptr );
4015 ImplSalYieldMutexRelease();
4017 return nRet;
4020 static void ImplHandleSettingsChangeMsg( HWND hWnd, UINT nMsg,
4021 WPARAM wParam, LPARAM lParam )
4023 SalEvent nSalEvent = SalEvent::SettingsChanged;
4025 if ( nMsg == WM_DEVMODECHANGE )
4026 nSalEvent = SalEvent::PrinterChanged;
4027 else if ( nMsg == WM_DISPLAYCHANGE )
4028 nSalEvent = SalEvent::DisplayChanged;
4029 else if ( nMsg == WM_FONTCHANGE )
4030 nSalEvent = SalEvent::FontChanged;
4031 else if ( nMsg == WM_WININICHANGE )
4033 if ( lParam )
4035 if ( ImplSalWICompareAscii( reinterpret_cast<const wchar_t*>(lParam), "devices" ) == 0 )
4036 nSalEvent = SalEvent::PrinterChanged;
4040 if ( nMsg == WM_SETTINGCHANGE )
4042 if ( wParam == SPI_SETWHEELSCROLLLINES )
4043 aSalShlData.mnWheelScrollLines = ImplSalGetWheelScrollLines();
4044 else if( wParam == SPI_SETWHEELSCROLLCHARS )
4045 aSalShlData.mnWheelScrollChars = ImplSalGetWheelScrollChars();
4048 if ( WM_SYSCOLORCHANGE == nMsg && GetSalData()->mhDitherPal )
4049 ImplUpdateSysColorEntries();
4051 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, 0, 0, DeferPolicy::Blocked );
4052 if ( pFrame )
4054 if ( (nMsg == WM_DISPLAYCHANGE) || (nMsg == WM_WININICHANGE) )
4056 if ( pFrame->mbFullScreen )
4057 ImplSalFrameFullScreenPos( pFrame );
4060 pFrame->CallCallback( nSalEvent, nullptr );
4061 ImplSalYieldMutexRelease();
4065 static void ImplHandleUserEvent( HWND hWnd, LPARAM lParam )
4067 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, 0, 0, DeferPolicy::Blocked );
4068 if ( pFrame )
4070 pFrame->CallCallback( SalEvent::UserEvent, reinterpret_cast<void*>(lParam) );
4071 ImplSalYieldMutexRelease();
4075 static void ImplHandleForcePalette( HWND hWnd )
4077 SalData* pSalData = GetSalData();
4078 HPALETTE hPal = pSalData->mhDitherPal;
4079 if ( hPal )
4081 WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_FORCEPALETTE );
4082 if ( pFrame && pFrame->mpLocalGraphics && pFrame->mpLocalGraphics->getHDC() )
4084 WinSalGraphics* pGraphics = pFrame->mpLocalGraphics;
4085 if ( pGraphics && pGraphics->getDefPal() )
4087 SelectPalette( pGraphics->getHDC(), hPal, FALSE );
4088 if ( RealizePalette( pGraphics->getHDC() ) )
4090 InvalidateRect( hWnd, nullptr, FALSE );
4091 UpdateWindow( hWnd );
4092 pFrame->CallCallback( SalEvent::DisplayChanged, nullptr );
4096 if ( pFrame )
4097 ImplSalYieldMutexRelease();
4101 static LRESULT ImplHandlePalette( bool bFrame, HWND hWnd, UINT nMsg,
4102 WPARAM wParam, LPARAM lParam, bool& rDef )
4104 SalData* pSalData = GetSalData();
4105 HPALETTE hPal = pSalData->mhDitherPal;
4106 if ( !hPal )
4107 return 0;
4109 rDef = false;
4110 if ( pSalData->mbInPalChange )
4111 return 0;
4113 if ( (nMsg == WM_PALETTECHANGED) || (nMsg == SAL_MSG_POSTPALCHANGED) )
4115 if ( reinterpret_cast<HWND>(wParam) == hWnd )
4116 return 0;
4119 bool bReleaseMutex = false;
4120 if ( (nMsg == WM_QUERYNEWPALETTE) || (nMsg == WM_PALETTECHANGED) )
4122 // as Windows can send these messages also, we have to use
4123 // the Solar semaphore
4124 if ( ImplSalYieldMutexTryToAcquire() )
4125 bReleaseMutex = true;
4126 else if ( nMsg == WM_QUERYNEWPALETTE )
4128 BOOL const ret = PostMessageW(hWnd, SAL_MSG_POSTQUERYNEWPAL, wParam, lParam);
4129 SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
4131 else /* ( nMsg == WM_PALETTECHANGED ) */
4133 BOOL const ret = PostMessageW(hWnd, SAL_MSG_POSTPALCHANGED, wParam, lParam);
4134 SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
4138 WinSalVirtualDevice*pTempVD;
4139 WinSalFrame* pTempFrame;
4140 WinSalGraphics* pGraphics;
4141 HDC hDC;
4142 HPALETTE hOldPal;
4143 UINT nCols;
4144 bool bStdDC;
4145 bool bUpdate;
4147 pSalData->mbInPalChange = true;
4149 // reset all palettes in VirDevs and Frames
4150 pTempVD = pSalData->mpFirstVD;
4151 while ( pTempVD )
4153 pGraphics = pTempVD->getGraphics();
4154 if ( pGraphics->getDefPal() )
4156 SelectPalette( pGraphics->getHDC(),
4157 pGraphics->getDefPal(),
4158 TRUE );
4160 pTempVD = pTempVD->getNext();
4162 pTempFrame = pSalData->mpFirstFrame;
4163 while ( pTempFrame )
4165 pGraphics = pTempFrame->mpLocalGraphics;
4166 if ( pGraphics && pGraphics->getHDC() && pGraphics->getDefPal() )
4168 SelectPalette( pGraphics->getHDC(),
4169 pGraphics->getDefPal(),
4170 TRUE );
4172 pTempFrame = pTempFrame->mpNextFrame;
4175 // re-initialize palette
4176 WinSalFrame* pFrame = nullptr;
4177 if ( bFrame )
4178 pFrame = GetWindowPtr( hWnd );
4179 if ( pFrame && pFrame->mpLocalGraphics && pFrame->mpLocalGraphics->getHDC() )
4181 hDC = pFrame->mpLocalGraphics->getHDC();
4182 bStdDC = true;
4184 else
4186 hDC = GetDC( hWnd );
4187 bStdDC = false;
4189 UnrealizeObject( hPal );
4190 hOldPal = SelectPalette( hDC, hPal, TRUE );
4191 nCols = RealizePalette( hDC );
4192 bUpdate = nCols != 0;
4193 if ( !bStdDC )
4195 SelectPalette( hDC, hOldPal, TRUE );
4196 ReleaseDC( hWnd, hDC );
4199 // reset all palettes in VirDevs and Frames
4200 pTempVD = pSalData->mpFirstVD;
4201 while ( pTempVD )
4203 pGraphics = pTempVD->getGraphics();
4204 if ( pGraphics->getDefPal() )
4206 SelectPalette( pGraphics->getHDC(), hPal, TRUE );
4207 RealizePalette( pGraphics->getHDC() );
4209 pTempVD = pTempVD->getNext();
4211 pTempFrame = pSalData->mpFirstFrame;
4212 while ( pTempFrame )
4214 if ( pTempFrame != pFrame )
4216 pGraphics = pTempFrame->mpLocalGraphics;
4217 if ( pGraphics && pGraphics->getHDC() && pGraphics->getDefPal() )
4219 SelectPalette( pGraphics->getHDC(), hPal, TRUE );
4220 if ( RealizePalette( pGraphics->getHDC() ) )
4221 bUpdate = true;
4224 pTempFrame = pTempFrame->mpNextFrame;
4227 // if colors changed, update the window
4228 if ( bUpdate )
4230 pTempFrame = pSalData->mpFirstFrame;
4231 while ( pTempFrame )
4233 pGraphics = pTempFrame->mpLocalGraphics;
4234 if ( pGraphics && pGraphics->getHDC() && pGraphics->getDefPal() )
4236 InvalidateRect( pTempFrame->mhWnd, nullptr, FALSE );
4237 UpdateWindow( pTempFrame->mhWnd );
4238 pTempFrame->CallCallback( SalEvent::DisplayChanged, nullptr );
4240 pTempFrame = pTempFrame->mpNextFrame;
4244 pSalData->mbInPalChange = false;
4246 if ( bReleaseMutex )
4247 ImplSalYieldMutexRelease();
4249 if ( nMsg == WM_PALETTECHANGED )
4250 return 0;
4251 else
4252 return nCols;
4255 static bool ImplHandleMinMax( HWND hWnd, LPARAM lParam )
4257 bool bRet = false;
4259 if ( ImplSalYieldMutexTryToAcquire() )
4261 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4262 if ( pFrame )
4264 MINMAXINFO* pMinMax = reinterpret_cast<MINMAXINFO*>(lParam);
4266 if ( pFrame->mbFullScreen )
4268 int nX;
4269 int nY;
4270 int nDX;
4271 int nDY;
4272 ImplSalCalcFullScreenSize( pFrame, nX, nY, nDX, nDY );
4274 if ( pMinMax->ptMaxPosition.x > nX )
4275 pMinMax->ptMaxPosition.x = nX;
4276 if ( pMinMax->ptMaxPosition.y > nY )
4277 pMinMax->ptMaxPosition.y = nY;
4279 if ( pMinMax->ptMaxSize.x < nDX )
4280 pMinMax->ptMaxSize.x = nDX;
4281 if ( pMinMax->ptMaxSize.y < nDY )
4282 pMinMax->ptMaxSize.y = nDY;
4283 if ( pMinMax->ptMaxTrackSize.x < nDX )
4284 pMinMax->ptMaxTrackSize.x = nDX;
4285 if ( pMinMax->ptMaxTrackSize.y < nDY )
4286 pMinMax->ptMaxTrackSize.y = nDY;
4288 pMinMax->ptMinTrackSize.x = nDX;
4289 pMinMax->ptMinTrackSize.y = nDY;
4291 bRet = true;
4294 if ( pFrame->mnMinWidth || pFrame->mnMinHeight )
4296 int nWidth = pFrame->mnMinWidth;
4297 int nHeight = pFrame->mnMinHeight;
4299 ImplSalAddBorder( pFrame, nWidth, nHeight );
4301 if ( pMinMax->ptMinTrackSize.x < nWidth )
4302 pMinMax->ptMinTrackSize.x = nWidth;
4303 if ( pMinMax->ptMinTrackSize.y < nHeight )
4304 pMinMax->ptMinTrackSize.y = nHeight;
4307 if ( pFrame->mnMaxWidth || pFrame->mnMaxHeight )
4309 int nWidth = pFrame->mnMaxWidth;
4310 int nHeight = pFrame->mnMaxHeight;
4312 ImplSalAddBorder( pFrame, nWidth, nHeight );
4314 if( nWidth > 0 && nHeight > 0 ) // protect against int overflow due to INT_MAX initialisation
4316 if ( pMinMax->ptMaxTrackSize.x > nWidth )
4317 pMinMax->ptMaxTrackSize.x = nWidth;
4318 if ( pMinMax->ptMaxTrackSize.y > nHeight )
4319 pMinMax->ptMaxTrackSize.y = nHeight;
4324 ImplSalYieldMutexRelease();
4327 return bRet;
4330 // retrieves the SalMenuItem pointer from a hMenu
4331 // the pointer is stored in every item, so if no position
4332 // is specified we just use the first item (ie, pos=0)
4333 // if bByPosition is false then nPos denotes a menu id instead of a position
4334 static WinSalMenuItem* ImplGetSalMenuItem( HMENU hMenu, UINT nPos, bool bByPosition=true )
4336 MENUITEMINFOW mi;
4337 memset(&mi, 0, sizeof(mi));
4338 mi.cbSize = sizeof( mi );
4339 mi.fMask = MIIM_DATA;
4340 if( !GetMenuItemInfoW( hMenu, nPos, bByPosition, &mi) )
4341 SAL_WARN("vcl", "GetMenuItemInfoW failed: " << WindowsErrorString(GetLastError()));
4343 return reinterpret_cast<WinSalMenuItem *>(mi.dwItemData);
4346 // returns the index of the currently selected item if any or -1
4347 static int ImplGetSelectedIndex( HMENU hMenu )
4349 MENUITEMINFOW mi;
4350 memset(&mi, 0, sizeof(mi));
4351 mi.cbSize = sizeof( mi );
4352 mi.fMask = MIIM_STATE;
4353 int n = GetMenuItemCount( hMenu );
4354 if( n != -1 )
4356 for(int i=0; i<n; i++ )
4358 if( !GetMenuItemInfoW( hMenu, i, TRUE, &mi) )
4359 SAL_WARN( "vcl", "GetMenuItemInfoW faled: " << WindowsErrorString( GetLastError() ) );
4360 else
4362 if( mi.fState & MFS_HILITE )
4363 return i;
4367 return -1;
4370 static LRESULT ImplMenuChar( HWND, WPARAM wParam, LPARAM lParam )
4372 LRESULT nRet = MNC_IGNORE;
4373 HMENU hMenu = reinterpret_cast<HMENU>(lParam);
4374 OUString aMnemonic( "&" + OUStringLiteral1(static_cast<sal_Unicode>(LOWORD(wParam))) );
4375 aMnemonic = aMnemonic.toAsciiLowerCase(); // we only have ascii mnemonics
4377 // search the mnemonic in the current menu
4378 int nItemCount = GetMenuItemCount( hMenu );
4379 int nFound = 0;
4380 int idxFound = -1;
4381 int idxSelected = ImplGetSelectedIndex( hMenu );
4382 int idx = idxSelected != -1 ? idxSelected+1 : 0; // if duplicate mnemonics cycle through menu
4383 for( int i=0; i< nItemCount; i++, idx++ )
4385 WinSalMenuItem* pSalMenuItem = ImplGetSalMenuItem( hMenu, idx % nItemCount );
4386 if( !pSalMenuItem )
4387 continue;
4388 OUString aStr = pSalMenuItem->mText;
4389 aStr = aStr.toAsciiLowerCase();
4390 if( aStr.indexOf( aMnemonic ) != -1 )
4392 if( idxFound == -1 )
4393 idxFound = idx % nItemCount;
4394 if( nFound++ )
4395 break; // duplicate found
4398 if( nFound == 1 )
4399 nRet = MAKELRESULT( idxFound, MNC_EXECUTE );
4400 else
4401 // duplicate mnemonics, just select the next occurrence
4402 nRet = MAKELRESULT( idxFound, MNC_SELECT );
4404 return nRet;
4407 static LRESULT ImplMeasureItem( HWND hWnd, WPARAM wParam, LPARAM lParam )
4409 LRESULT nRet = 0;
4410 if( !wParam )
4412 // request was sent by a menu
4413 nRet = 1;
4414 MEASUREITEMSTRUCT *pMI = reinterpret_cast<LPMEASUREITEMSTRUCT>(lParam);
4415 if( pMI->CtlType != ODT_MENU )
4416 return 0;
4418 WinSalMenuItem *pSalMenuItem = reinterpret_cast<WinSalMenuItem *>(pMI->itemData);
4419 if( !pSalMenuItem )
4420 return 0;
4422 HDC hdc = GetDC( hWnd );
4423 SIZE strSize;
4425 NONCLIENTMETRICSW ncm;
4426 memset( &ncm, 0, sizeof(ncm) );
4427 ncm.cbSize = sizeof( ncm );
4428 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0 );
4430 // Assume every menu item can be default and printed bold
4431 //ncm.lfMenuFont.lfWeight = FW_BOLD;
4433 HFONT hfntOld = static_cast<HFONT>(SelectObject(hdc, CreateFontIndirectW( &ncm.lfMenuFont )));
4435 // menu text and accelerator
4436 OUString aStr(pSalMenuItem->mText);
4437 if( pSalMenuItem->mAccelText.getLength() )
4439 aStr += " ";
4440 aStr += pSalMenuItem->mAccelText;
4442 GetTextExtentPoint32W( hdc, o3tl::toW(aStr.getStr()),
4443 aStr.getLength(), &strSize );
4445 // image
4446 Size bmpSize( 16, 16 );
4447 //if( !!pSalMenuItem->maBitmap )
4448 // bmpSize = pSalMenuItem->maBitmap.GetSizePixel();
4450 // checkmark
4451 Size checkSize( GetSystemMetrics( SM_CXMENUCHECK ), GetSystemMetrics( SM_CYMENUCHECK ) );
4453 pMI->itemWidth = checkSize.Width() + 3 + bmpSize.Width() + 3 + strSize.cx;
4454 pMI->itemHeight = std::max( std::max( checkSize.Height(), bmpSize.Height() ), strSize.cy );
4455 pMI->itemHeight += 4;
4457 DeleteObject( SelectObject(hdc, hfntOld) );
4458 ReleaseDC( hWnd, hdc );
4461 return nRet;
4464 static LRESULT ImplDrawItem(HWND, WPARAM wParam, LPARAM lParam )
4466 LRESULT nRet = 0;
4467 if( !wParam )
4469 // request was sent by a menu
4470 nRet = 1;
4471 DRAWITEMSTRUCT *pDI = reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);
4472 if( pDI->CtlType != ODT_MENU )
4473 return 0;
4475 WinSalMenuItem *pSalMenuItem = reinterpret_cast<WinSalMenuItem *>(pDI->itemData);
4476 if( !pSalMenuItem )
4477 return 0;
4479 COLORREF clrPrevText, clrPrevBkgnd;
4480 HFONT hfntOld;
4481 HBRUSH hbrOld;
4482 bool fChecked = (pDI->itemState & ODS_CHECKED);
4483 bool fSelected = (pDI->itemState & ODS_SELECTED);
4484 bool fDisabled = (pDI->itemState & (ODS_DISABLED | ODS_GRAYED));
4486 // Set the appropriate foreground and background colors.
4487 RECT aRect = pDI->rcItem;
4489 clrPrevBkgnd = SetBkColor( pDI->hDC, GetSysColor( COLOR_MENU ) );
4491 if ( fDisabled )
4492 clrPrevText = SetTextColor( pDI->hDC, GetSysColor( COLOR_GRAYTEXT ) );
4493 else
4494 clrPrevText = SetTextColor( pDI->hDC, GetSysColor( fSelected ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT ) );
4496 DWORD colBackground = GetSysColor( fSelected ? COLOR_HIGHLIGHT : COLOR_MENU );
4497 clrPrevBkgnd = SetBkColor( pDI->hDC, colBackground );
4499 hbrOld = static_cast<HBRUSH>(SelectObject( pDI->hDC, CreateSolidBrush( GetBkColor( pDI->hDC ) ) ));
4501 // Fill background
4502 if(!PatBlt( pDI->hDC, aRect.left, aRect.top, aRect.right-aRect.left, aRect.bottom-aRect.top, PATCOPY ))
4503 SAL_WARN("vcl", "PatBlt failed: " << WindowsErrorString(GetLastError()));
4505 int lineHeight = aRect.bottom-aRect.top;
4507 int x = aRect.left;
4508 int y = aRect.top;
4510 int checkWidth = GetSystemMetrics( SM_CXMENUCHECK );
4511 int checkHeight = GetSystemMetrics( SM_CYMENUCHECK );
4512 if( fChecked )
4514 RECT r;
4515 r.left = 0;
4516 r.top = 0;
4517 r.right = checkWidth;
4518 r.bottom = checkWidth;
4519 HDC memDC = CreateCompatibleDC( pDI->hDC );
4520 HBITMAP memBmp = CreateCompatibleBitmap( pDI->hDC, checkWidth, checkHeight );
4521 HBITMAP hOldBmp = static_cast<HBITMAP>(SelectObject( memDC, memBmp ));
4522 DrawFrameControl( memDC, &r, DFC_MENU, DFCS_MENUCHECK );
4523 BitBlt( pDI->hDC, x, y+(lineHeight-checkHeight)/2, checkWidth, checkHeight, memDC, 0, 0, SRCAND );
4524 DeleteObject( SelectObject( memDC, hOldBmp ) );
4525 DeleteDC( memDC );
4527 x += checkWidth+3;
4529 //Size bmpSize = aBitmap.GetSizePixel();
4530 Size bmpSize(16, 16);
4531 if( !!pSalMenuItem->maBitmap )
4533 Bitmap aBitmap( pSalMenuItem->maBitmap );
4535 // set transparent pixels to background color
4536 if( fDisabled )
4537 colBackground = RGB(255,255,255);
4538 aBitmap.Replace( COL_LIGHTMAGENTA,
4539 Color( GetRValue(colBackground),GetGValue(colBackground),GetBValue(colBackground) ));
4541 WinSalBitmap* pSalBmp = static_cast<WinSalBitmap*>(aBitmap.ImplGetSalBitmap().get());
4542 HGLOBAL hDrawDIB = pSalBmp->ImplGethDIB();
4544 if( hDrawDIB )
4546 PBITMAPINFO pBI = static_cast<PBITMAPINFO>(GlobalLock( hDrawDIB ));
4547 PBYTE pBits = reinterpret_cast<PBYTE>(pBI) + pBI->bmiHeader.biSize +
4548 WinSalBitmap::ImplGetDIBColorCount( hDrawDIB ) * sizeof( RGBQUAD );
4550 HBITMAP hBmp = CreateDIBitmap( pDI->hDC, &pBI->bmiHeader, CBM_INIT, pBits, pBI, DIB_RGB_COLORS );
4551 GlobalUnlock( hDrawDIB );
4553 HBRUSH hbrIcon = CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT ) );
4554 DrawStateW( pDI->hDC, hbrIcon, nullptr, reinterpret_cast<LPARAM>(hBmp), WPARAM(0),
4555 x, y+(lineHeight-bmpSize.Height())/2, bmpSize.Width(), bmpSize.Height(),
4556 DST_BITMAP | (fDisabled ? (fSelected ? DSS_MONO : DSS_DISABLED) : DSS_NORMAL) );
4558 DeleteObject( hbrIcon );
4559 DeleteObject( hBmp );
4563 x += bmpSize.Width() + 3;
4564 aRect.left = x;
4566 NONCLIENTMETRICSW ncm;
4567 memset( &ncm, 0, sizeof(ncm) );
4568 ncm.cbSize = sizeof( ncm );
4569 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0 );
4571 // Print default menu entry with bold font
4572 //if ( pDI->itemState & ODS_DEFAULT )
4573 // ncm.lfMenuFont.lfWeight = FW_BOLD;
4575 hfntOld = static_cast<HFONT>(SelectObject(pDI->hDC, CreateFontIndirectW( &ncm.lfMenuFont )));
4577 SIZE strSize;
4578 OUString aStr( pSalMenuItem->mText );
4579 GetTextExtentPoint32W( pDI->hDC, o3tl::toW(aStr.getStr()),
4580 aStr.getLength(), &strSize );
4582 if(!DrawStateW( pDI->hDC, nullptr, nullptr,
4583 reinterpret_cast<LPARAM>(aStr.getStr()),
4584 WPARAM(0), aRect.left, aRect.top + (lineHeight - strSize.cy)/2, 0, 0,
4585 DST_PREFIXTEXT | (fDisabled && !fSelected ? DSS_DISABLED : DSS_NORMAL) ) )
4586 SAL_WARN("vcl", "DrawStateW failed: " << WindowsErrorString(GetLastError()));
4588 if( pSalMenuItem->mAccelText.getLength() )
4590 SIZE strSizeA;
4591 aStr = pSalMenuItem->mAccelText;
4592 GetTextExtentPoint32W( pDI->hDC, o3tl::toW(aStr.getStr()),
4593 aStr.getLength(), &strSizeA );
4594 TEXTMETRICW tm;
4595 GetTextMetricsW( pDI->hDC, &tm );
4597 // position the accelerator string to the right but leave space for the
4598 // (potential) submenu arrow (tm.tmMaxCharWidth)
4599 if(!DrawStateW( pDI->hDC, nullptr, nullptr,
4600 reinterpret_cast<LPARAM>(aStr.getStr()),
4601 WPARAM(0), aRect.right-strSizeA.cx-tm.tmMaxCharWidth, aRect.top + (lineHeight - strSizeA.cy)/2, 0, 0,
4602 DST_TEXT | (fDisabled && !fSelected ? DSS_DISABLED : DSS_NORMAL) ) )
4603 SAL_WARN("vcl", "DrawStateW failed: " << WindowsErrorString(GetLastError()));
4606 // Restore the original font and colors.
4607 DeleteObject( SelectObject( pDI->hDC, hbrOld ) );
4608 DeleteObject( SelectObject( pDI->hDC, hfntOld) );
4609 SetTextColor(pDI->hDC, clrPrevText);
4610 SetBkColor(pDI->hDC, clrPrevBkgnd);
4612 return nRet;
4615 static bool ImplHandleMenuActivate( HWND hWnd, WPARAM wParam, LPARAM )
4617 // Menu activation
4618 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4619 if ( !pFrame )
4620 return false;
4622 HMENU hMenu = reinterpret_cast<HMENU>(wParam);
4623 // WORD nPos = LOWORD (lParam);
4624 // bool bWindowMenu = (bool) HIWORD(lParam);
4626 // Send activate and deactivate together, so we have not keep track of opened menus
4627 // this will be enough to have the menus updated correctly
4628 SalMenuEvent aMenuEvt;
4629 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, 0 );
4630 if( pSalMenuItem )
4631 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
4632 else
4633 aMenuEvt.mpMenu = nullptr;
4635 bool nRet = pFrame->CallCallback( SalEvent::MenuActivate, &aMenuEvt );
4636 if( nRet )
4637 nRet = pFrame->CallCallback( SalEvent::MenuDeactivate, &aMenuEvt );
4638 if( nRet )
4639 pFrame->mLastActivatedhMenu = hMenu;
4641 return nRet;
4644 static bool ImplHandleMenuSelect( HWND hWnd, WPARAM wParam, LPARAM lParam )
4646 // Menu selection
4647 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4648 if ( !pFrame )
4649 return false;
4651 WORD nId = LOWORD(wParam); // menu item or submenu index
4652 WORD nFlags = HIWORD(wParam);
4653 HMENU hMenu = reinterpret_cast<HMENU>(lParam);
4655 // check if we have to process the message
4656 if( !GetSalData()->IsKnownMenuHandle( hMenu ) )
4657 return false;
4659 bool bByPosition = false;
4660 if( nFlags & MF_POPUP )
4661 bByPosition = true;
4663 bool nRet = false;
4664 if ( hMenu && !pFrame->mLastActivatedhMenu )
4666 // we never activated a menu (ie, no WM_INITMENUPOPUP has occurred yet)
4667 // which means this must be the menubar -> send activation/deactivation
4668 SalMenuEvent aMenuEvt;
4669 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, nId, bByPosition );
4670 if( pSalMenuItem )
4671 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
4672 else
4673 aMenuEvt.mpMenu = nullptr;
4675 nRet = pFrame->CallCallback( SalEvent::MenuActivate, &aMenuEvt );
4676 if( nRet )
4677 nRet = pFrame->CallCallback( SalEvent::MenuDeactivate, &aMenuEvt );
4678 if( nRet )
4679 pFrame->mLastActivatedhMenu = hMenu;
4682 if( !hMenu && nFlags == 0xFFFF )
4684 // all menus are closed, reset activation logic
4685 pFrame->mLastActivatedhMenu = nullptr;
4688 if( hMenu )
4690 // hMenu must be saved, as it is not passed in WM_COMMAND which always occurs after a selection
4691 // if a menu is closed due to a command selection then hMenu is NULL, but WM_COMMAND comes later
4692 // so we must not overwrite it in this case
4693 pFrame->mSelectedhMenu = hMenu;
4695 // send highlight event
4696 if( nFlags & MF_POPUP )
4698 // submenu selected
4699 // wParam now carries an index instead of an id -> retrieve id
4700 MENUITEMINFOW mi;
4701 memset(&mi, 0, sizeof(mi));
4702 mi.cbSize = sizeof( mi );
4703 mi.fMask = MIIM_ID;
4704 if( GetMenuItemInfoW( hMenu, LOWORD(wParam), TRUE, &mi) )
4705 nId = sal::static_int_cast<WORD>(mi.wID);
4708 SalMenuEvent aMenuEvt;
4709 aMenuEvt.mnId = nId;
4710 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, nId, false );
4711 if( pSalMenuItem )
4712 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
4713 else
4714 aMenuEvt.mpMenu = nullptr;
4716 nRet = pFrame->CallCallback( SalEvent::MenuHighlight, &aMenuEvt );
4719 return nRet;
4722 static bool ImplHandleCommand( HWND hWnd, WPARAM wParam, LPARAM )
4724 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4725 if ( !pFrame )
4726 return false;
4728 bool nRet = false;
4729 if( !HIWORD(wParam) )
4731 // Menu command
4732 WORD nId = LOWORD(wParam);
4733 if( nId ) // zero for separators
4735 SalMenuEvent aMenuEvt;
4736 aMenuEvt.mnId = nId;
4737 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( pFrame->mSelectedhMenu, nId, false );
4738 if( pSalMenuItem )
4739 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
4740 else
4741 aMenuEvt.mpMenu = nullptr;
4743 nRet = pFrame->CallCallback( SalEvent::MenuCommand, &aMenuEvt );
4746 return nRet;
4749 static bool ImplHandleSysCommand( HWND hWnd, WPARAM wParam, LPARAM lParam )
4751 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4752 if ( !pFrame )
4753 return false;
4755 WPARAM nCommand = wParam & 0xFFF0;
4757 if ( pFrame->mbFullScreen )
4759 BOOL bMaximize = IsZoomed( pFrame->mhWnd );
4760 BOOL bMinimize = IsIconic( pFrame->mhWnd );
4761 if ( (nCommand == SC_SIZE) ||
4762 (!bMinimize && (nCommand == SC_MOVE)) ||
4763 (!bMaximize && (nCommand == SC_MAXIMIZE)) ||
4764 (bMaximize && (nCommand == SC_RESTORE)) )
4766 return true;
4770 if ( nCommand == SC_MOVE )
4772 WinSalTimer* pTimer = static_cast<WinSalTimer*>( ImplGetSVData()->maSchedCtx.mpSalTimer );
4773 if ( pTimer )
4774 pTimer->SetForceRealTimer( true );
4777 if ( nCommand == SC_KEYMENU )
4779 // do not process SC_KEYMENU if we have a native menu
4780 // Windows should handle this
4781 if( GetMenu( hWnd ) )
4782 return false;
4784 // Process here KeyMenu events only for Alt to activate the MenuBar,
4785 // or if a SysChild window is in focus, as Alt-key-combinations are
4786 // only processed via this event
4787 if ( !LOWORD( lParam ) )
4789 // Only trigger if no other key is pressed.
4790 // Contrary to Docu the CharCode is delivered with the x-coordinate
4791 // that is pressed in addition.
4792 // Also 32 for space, 99 for c, 100 for d, ...
4793 // As this is not documented, we check the state of the space-bar
4794 if ( GetKeyState( VK_SPACE ) & 0x8000 )
4795 return false;
4797 // to avoid activating the MenuBar for Alt+MouseKey
4798 if ( (GetKeyState( VK_LBUTTON ) & 0x8000) ||
4799 (GetKeyState( VK_RBUTTON ) & 0x8000) ||
4800 (GetKeyState( VK_MBUTTON ) & 0x8000) ||
4801 (GetKeyState( VK_SHIFT ) & 0x8000) )
4802 return true;
4804 SalKeyEvent aKeyEvt;
4805 aKeyEvt.mnCode = KEY_MENU;
4806 aKeyEvt.mnCharCode = 0;
4807 aKeyEvt.mnRepeat = 0;
4808 bool nRet = pFrame->CallCallback( SalEvent::KeyInput, &aKeyEvt );
4809 pFrame->CallCallback( SalEvent::KeyUp, &aKeyEvt );
4810 return nRet;
4812 else
4814 // check if a SysChild is in focus
4815 HWND hFocusWnd = ::GetFocus();
4816 if ( hFocusWnd && ImplFindSalObject( hFocusWnd ) )
4818 char cKeyCode = static_cast<char>(static_cast<unsigned char>(LOWORD( lParam )));
4819 // LowerCase
4820 if ( (cKeyCode >= 65) && (cKeyCode <= 90) )
4821 cKeyCode += 32;
4822 // We only accept 0-9 and A-Z; all other keys have to be
4823 // processed by the SalObj hook
4824 if ( ((cKeyCode >= 48) && (cKeyCode <= 57)) ||
4825 ((cKeyCode >= 97) && (cKeyCode <= 122)) )
4827 sal_uInt16 nModCode = 0;
4828 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
4829 nModCode |= KEY_SHIFT;
4830 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
4831 nModCode |= KEY_MOD1;
4832 nModCode |= KEY_MOD2;
4834 SalKeyEvent aKeyEvt;
4835 if ( (cKeyCode >= 48) && (cKeyCode <= 57) )
4836 aKeyEvt.mnCode = KEY_0+(cKeyCode-48);
4837 else
4838 aKeyEvt.mnCode = KEY_A+(cKeyCode-97);
4839 aKeyEvt.mnCode |= nModCode;
4840 aKeyEvt.mnCharCode = cKeyCode;
4841 aKeyEvt.mnRepeat = 0;
4842 bool nRet = pFrame->CallCallback( SalEvent::KeyInput, &aKeyEvt );
4843 pFrame->CallCallback( SalEvent::KeyUp, &aKeyEvt );
4844 return nRet;
4850 return false;
4853 static void ImplHandleInputLangChange( HWND hWnd, WPARAM, LPARAM lParam )
4855 ImplSalYieldMutexAcquireWithWait();
4857 // check if we support IME
4858 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4860 if ( !pFrame )
4861 return;
4863 if ( pFrame->mbIME && pFrame->mhDefIMEContext )
4865 HKL hKL = reinterpret_cast<HKL>(lParam);
4866 UINT nImeProps = ImmGetProperty( hKL, IGP_PROPERTY );
4868 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
4869 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
4870 pFrame->mbHandleIME = !pFrame->mbSpezIME;
4873 // trigger input language and codepage update
4874 UINT nLang = pFrame->mnInputLang;
4875 ImplUpdateInputLang( pFrame );
4877 // notify change
4878 if( nLang != pFrame->mnInputLang )
4879 pFrame->CallCallback( SalEvent::InputLanguageChange, nullptr );
4881 // reinit spec. keys
4882 GetSalData()->initKeyCodeMap();
4884 ImplSalYieldMutexRelease();
4887 static void ImplUpdateIMECursorPos( WinSalFrame* pFrame, HIMC hIMC )
4889 COMPOSITIONFORM aForm;
4890 memset( &aForm, 0, sizeof( aForm ) );
4892 // get cursor position and from it calculate default position
4893 // for the composition window
4894 SalExtTextInputPosEvent aPosEvt;
4895 pFrame->CallCallback( SalEvent::ExtTextInputPos, &aPosEvt );
4896 if ( (aPosEvt.mnX == -1) && (aPosEvt.mnY == -1) )
4897 aForm.dwStyle |= CFS_DEFAULT;
4898 else
4900 aForm.dwStyle |= CFS_POINT;
4901 aForm.ptCurrentPos.x = aPosEvt.mnX;
4902 aForm.ptCurrentPos.y = aPosEvt.mnY;
4904 ImmSetCompositionWindow( hIMC, &aForm );
4906 // Because not all IME's use this values, we create
4907 // a Windows caret to force the Position from the IME
4908 if ( GetFocus() == pFrame->mhWnd )
4910 CreateCaret( pFrame->mhWnd, nullptr,
4911 aPosEvt.mnWidth, aPosEvt.mnHeight );
4912 SetCaretPos( aPosEvt.mnX, aPosEvt.mnY );
4916 static bool ImplHandleIMEStartComposition( HWND hWnd )
4918 bool bDef = true;
4920 ImplSalYieldMutexAcquireWithWait();
4922 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4923 if ( pFrame )
4925 HIMC hIMC = ImmGetContext( hWnd );
4926 if ( hIMC )
4928 ImplUpdateIMECursorPos( pFrame, hIMC );
4929 ImmReleaseContext( hWnd, hIMC );
4932 if ( pFrame->mbHandleIME )
4934 if ( pFrame->mbAtCursorIME )
4935 bDef = false;
4939 ImplSalYieldMutexRelease();
4941 return bDef;
4944 static bool ImplHandleIMECompositionInput( WinSalFrame* pFrame,
4945 HIMC hIMC, LPARAM lParam )
4947 bool bDef = true;
4949 // Init Event
4950 SalExtTextInputEvent aEvt;
4951 aEvt.mpTextAttr = nullptr;
4952 aEvt.mnCursorPos = 0;
4953 aEvt.mnCursorFlags = 0;
4955 // If we get a result string, then we handle this input
4956 if ( lParam & GCS_RESULTSTR )
4958 bDef = false;
4960 LONG nTextLen = ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, nullptr, 0 ) / sizeof( WCHAR );
4961 if ( nTextLen >= 0 )
4963 auto pTextBuf = std::unique_ptr<WCHAR[]>(new WCHAR[nTextLen]);
4964 ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, pTextBuf.get(), nTextLen*sizeof( WCHAR ) );
4965 aEvt.maText = OUString( o3tl::toU(pTextBuf.get()), static_cast<sal_Int32>(nTextLen) );
4968 aEvt.mnCursorPos = aEvt.maText.getLength();
4969 pFrame->CallCallback( SalEvent::ExtTextInput, &aEvt );
4970 pFrame->CallCallback( SalEvent::EndExtTextInput, nullptr );
4971 ImplUpdateIMECursorPos( pFrame, hIMC );
4974 // If the IME doesn't support OnSpot input, then there is nothing to do
4975 if ( !pFrame->mbAtCursorIME )
4976 return !bDef;
4978 // If we get new Composition data, then we handle this new input
4979 if ( (lParam & (GCS_COMPSTR | GCS_COMPATTR)) ||
4980 ((lParam & GCS_CURSORPOS) && !(lParam & GCS_RESULTSTR)) )
4982 bDef = false;
4984 ExtTextInputAttr* pSalAttrAry = nullptr;
4985 LONG nTextLen = ImmGetCompositionStringW( hIMC, GCS_COMPSTR, nullptr, 0 ) / sizeof( WCHAR );
4986 if ( nTextLen > 0 )
4989 auto pTextBuf = std::unique_ptr<WCHAR>(new WCHAR[nTextLen]);
4990 ImmGetCompositionStringW( hIMC, GCS_COMPSTR, pTextBuf.get(), nTextLen*sizeof( WCHAR ) );
4991 aEvt.maText = OUString( o3tl::toU(pTextBuf.get()), static_cast<sal_Int32>(nTextLen) );
4994 std::unique_ptr<BYTE> pAttrBuf;
4995 LONG nAttrLen = ImmGetCompositionStringW( hIMC, GCS_COMPATTR, nullptr, 0 );
4996 if ( nAttrLen > 0 )
4998 pAttrBuf.reset(new BYTE[nAttrLen]);
4999 ImmGetCompositionStringW( hIMC, GCS_COMPATTR, pAttrBuf.get(), nAttrLen );
5002 if ( pAttrBuf )
5004 sal_Int32 nTextLen2 = aEvt.maText.getLength();
5005 pSalAttrAry = new ExtTextInputAttr[nTextLen2];
5006 memset( pSalAttrAry, 0, nTextLen2*sizeof( sal_uInt16 ) );
5007 for( sal_Int32 i = 0; (i < nTextLen2) && (i < nAttrLen); i++ )
5009 BYTE nWinAttr = pAttrBuf.get()[i];
5010 ExtTextInputAttr nSalAttr;
5011 if ( nWinAttr == ATTR_TARGET_CONVERTED )
5013 nSalAttr = ExtTextInputAttr::BoldUnderline;
5014 aEvt.mnCursorFlags |= EXTTEXTINPUT_CURSOR_INVISIBLE;
5016 else if ( nWinAttr == ATTR_CONVERTED )
5017 nSalAttr = ExtTextInputAttr::DashDotUnderline;
5018 else if ( nWinAttr == ATTR_TARGET_NOTCONVERTED )
5019 nSalAttr = ExtTextInputAttr::Highlight;
5020 else if ( nWinAttr == ATTR_INPUT_ERROR )
5021 nSalAttr = ExtTextInputAttr::RedText | ExtTextInputAttr::DottedUnderline;
5022 else /* ( nWinAttr == ATTR_INPUT ) */
5023 nSalAttr = ExtTextInputAttr::DottedUnderline;
5024 pSalAttrAry[i] = nSalAttr;
5027 aEvt.mpTextAttr = pSalAttrAry;
5031 // Only when we get new composition data, we must send this event
5032 if ( (nTextLen > 0) || !(lParam & GCS_RESULTSTR) )
5034 // End the mode, if the last character is deleted
5035 if ( !nTextLen && !pFrame->mbCandidateMode )
5037 pFrame->CallCallback( SalEvent::ExtTextInput, &aEvt );
5038 pFrame->CallCallback( SalEvent::EndExtTextInput, nullptr );
5040 else
5042 // Because Cursor-Position and DeltaStart never updated
5043 // from the korean input engine, we must handle this here
5044 if ( lParam & CS_INSERTCHAR )
5046 aEvt.mnCursorPos = nTextLen;
5047 if ( aEvt.mnCursorPos && (lParam & CS_NOMOVECARET) )
5048 aEvt.mnCursorPos--;
5050 else
5051 aEvt.mnCursorPos = LOWORD( ImmGetCompositionStringW( hIMC, GCS_CURSORPOS, nullptr, 0 ) );
5053 if ( pFrame->mbCandidateMode )
5054 aEvt.mnCursorFlags |= EXTTEXTINPUT_CURSOR_INVISIBLE;
5055 if ( lParam & CS_NOMOVECARET )
5056 aEvt.mnCursorFlags |= EXTTEXTINPUT_CURSOR_OVERWRITE;
5058 pFrame->CallCallback( SalEvent::ExtTextInput, &aEvt );
5060 ImplUpdateIMECursorPos( pFrame, hIMC );
5063 if ( pSalAttrAry )
5064 delete [] pSalAttrAry;
5067 return !bDef;
5070 static bool ImplHandleIMEComposition( HWND hWnd, LPARAM lParam )
5072 bool bDef = true;
5073 ImplSalYieldMutexAcquireWithWait();
5075 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5076 if ( pFrame && (!lParam || (lParam & GCS_RESULTSTR)) )
5078 // reset the background mode for each text input,
5079 // as some tools such as RichWin may have changed it
5080 if ( pFrame->mpLocalGraphics &&
5081 pFrame->mpLocalGraphics->getHDC() )
5082 SetBkMode( pFrame->mpLocalGraphics->getHDC(), TRANSPARENT );
5085 if ( pFrame && pFrame->mbHandleIME )
5087 if ( !lParam )
5089 SalExtTextInputEvent aEvt;
5090 aEvt.mpTextAttr = nullptr;
5091 aEvt.mnCursorPos = 0;
5092 aEvt.mnCursorFlags = 0;
5093 pFrame->CallCallback( SalEvent::ExtTextInput, &aEvt );
5094 pFrame->CallCallback( SalEvent::EndExtTextInput, nullptr );
5096 else if ( lParam & (GCS_RESULTSTR | GCS_COMPSTR | GCS_COMPATTR | GCS_CURSORPOS) )
5098 HIMC hIMC = ImmGetContext( hWnd );
5099 if ( hIMC )
5101 if ( ImplHandleIMECompositionInput( pFrame, hIMC, lParam ) )
5102 bDef = false;
5104 ImmReleaseContext( hWnd, hIMC );
5109 ImplSalYieldMutexRelease();
5110 return bDef;
5113 static bool ImplHandleIMEEndComposition( HWND hWnd )
5115 bool bDef = true;
5117 ImplSalYieldMutexAcquireWithWait();
5119 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5120 if ( pFrame && pFrame->mbHandleIME )
5122 if ( pFrame->mbAtCursorIME )
5123 bDef = false;
5126 ImplSalYieldMutexRelease();
5128 return bDef;
5131 static bool ImplHandleAppCommand( HWND hWnd, LPARAM lParam, LRESULT & nRet )
5133 MediaCommand nCommand;
5134 switch( GET_APPCOMMAND_LPARAM(lParam) )
5136 case APPCOMMAND_MEDIA_CHANNEL_DOWN: nCommand = MediaCommand::ChannelDown; break;
5137 case APPCOMMAND_MEDIA_CHANNEL_UP: nCommand = MediaCommand::ChannelUp; break;
5138 case APPCOMMAND_MEDIA_NEXTTRACK: nCommand = MediaCommand::NextTrack; break;
5139 case APPCOMMAND_MEDIA_PAUSE: nCommand = MediaCommand::Pause; break;
5140 case APPCOMMAND_MEDIA_PLAY: nCommand = MediaCommand::Play; break;
5141 case APPCOMMAND_MEDIA_PLAY_PAUSE: nCommand = MediaCommand::PlayPause; break;
5142 case APPCOMMAND_MEDIA_PREVIOUSTRACK: nCommand = MediaCommand::PreviousTrack; break;
5143 case APPCOMMAND_MEDIA_RECORD: nCommand = MediaCommand::Record; break;
5144 case APPCOMMAND_MEDIA_REWIND: nCommand = MediaCommand::Rewind; break;
5145 case APPCOMMAND_MEDIA_STOP: nCommand = MediaCommand::Stop; break;
5146 case APPCOMMAND_MIC_ON_OFF_TOGGLE: nCommand = MediaCommand::MicOnOffToggle; break;
5147 case APPCOMMAND_MICROPHONE_VOLUME_DOWN: nCommand = MediaCommand::MicrophoneVolumeDown; break;
5148 case APPCOMMAND_MICROPHONE_VOLUME_MUTE: nCommand = MediaCommand::MicrophoneVolumeMute; break;
5149 case APPCOMMAND_MICROPHONE_VOLUME_UP: nCommand = MediaCommand::MicrophoneVolumeUp; break;
5150 case APPCOMMAND_VOLUME_DOWN: nCommand = MediaCommand::VolumeDown; break;
5151 case APPCOMMAND_VOLUME_MUTE: nCommand = MediaCommand::VolumeMute; break;
5152 case APPCOMMAND_VOLUME_UP: nCommand = MediaCommand::VolumeUp; break;
5153 default:
5154 return false;
5157 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5158 vcl::Window *pWindow = pFrame ? pFrame->GetWindow() : nullptr;
5160 if( pWindow )
5162 const Point aPoint;
5163 CommandMediaData aMediaData(nCommand);
5164 CommandEvent aCEvt( aPoint, CommandEventId::Media, false, &aMediaData );
5165 NotifyEvent aNCmdEvt( MouseNotifyEvent::COMMAND, pWindow, &aCEvt );
5167 if ( !ImplCallPreNotify( aNCmdEvt ) )
5169 pWindow->Command( aCEvt );
5170 nRet = 1;
5171 return !aMediaData.GetPassThroughToOS();
5175 return false;
5178 static void ImplHandleIMENotify( HWND hWnd, WPARAM wParam )
5180 if ( wParam == WPARAM(IMN_OPENCANDIDATE) )
5182 ImplSalYieldMutexAcquireWithWait();
5184 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5185 if ( pFrame && pFrame->mbHandleIME &&
5186 pFrame->mbAtCursorIME )
5188 // we want to hide the cursor
5189 pFrame->mbCandidateMode = true;
5190 ImplHandleIMEComposition( hWnd, GCS_CURSORPOS );
5192 HWND hWnd2 = pFrame->mhWnd;
5193 HIMC hIMC = ImmGetContext( hWnd2 );
5194 if ( hIMC )
5196 LONG nBufLen = ImmGetCompositionStringW( hIMC, GCS_COMPSTR, nullptr, 0 );
5197 if ( nBufLen >= 1 )
5199 SalExtTextInputPosEvent aPosEvt;
5200 pFrame->CallCallback( SalEvent::ExtTextInputPos, &aPosEvt );
5202 // Vertical !!!
5203 CANDIDATEFORM aForm;
5204 aForm.dwIndex = 0;
5205 aForm.dwStyle = CFS_EXCLUDE;
5206 aForm.ptCurrentPos.x = aPosEvt.mnX;
5207 aForm.ptCurrentPos.y = aPosEvt.mnY+1;
5208 aForm.rcArea.left = aPosEvt.mnX;
5209 aForm.rcArea.top = aPosEvt.mnY;
5210 aForm.rcArea.right = aForm.rcArea.left+aPosEvt.mnExtWidth+1;
5211 aForm.rcArea.bottom = aForm.rcArea.top+aPosEvt.mnHeight+1;
5212 ImmSetCandidateWindow( hIMC, &aForm );
5215 ImmReleaseContext( hWnd2, hIMC );
5219 ImplSalYieldMutexRelease();
5221 else if ( wParam == WPARAM(IMN_CLOSECANDIDATE) )
5223 ImplSalYieldMutexAcquireWithWait();
5224 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5225 if ( pFrame )
5226 pFrame->mbCandidateMode = false;
5227 ImplSalYieldMutexRelease();
5231 static bool
5232 ImplHandleGetObject(HWND hWnd, LPARAM lParam, WPARAM wParam, LRESULT & nRet)
5234 // IA2 should be enabled automatically
5235 AllSettings aSettings = Application::GetSettings();
5236 MiscSettings aMisc = aSettings.GetMiscSettings();
5237 aMisc.SetEnableATToolSupport( true );
5238 aSettings.SetMiscSettings( aMisc );
5239 Application::SetSettings( aSettings );
5241 if (!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
5242 return false; // locked down somehow ?
5244 ImplSVData* pSVData = ImplGetSVData();
5246 // Make sure to launch Accessibility only the following criteria are satisfied
5247 // to avoid RFT interrupts regular accessibility processing
5248 if ( !pSVData->mxAccessBridge.is() )
5250 if( !InitAccessBridge() )
5251 return false;
5254 uno::Reference< accessibility::XMSAAService > xMSAA( pSVData->mxAccessBridge, uno::UNO_QUERY );
5255 if ( xMSAA.is() )
5257 sal_Int32 lParam32 = (sal_Int32)lParam;
5258 sal_uInt32 wParam32 = (sal_uInt32)wParam;
5260 // mhOnSetTitleWnd not set to reasonable value anywhere...
5261 if ( lParam32 == OBJID_CLIENT )
5263 nRet = xMSAA->getAccObjectPtr(
5264 reinterpret_cast<sal_Int64>(hWnd), lParam32, wParam32);
5265 if (nRet != 0)
5266 return true;
5269 return false;
5272 static LRESULT ImplHandleIMEReconvertString( HWND hWnd, LPARAM lParam )
5274 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5275 LPRECONVERTSTRING pReconvertString = reinterpret_cast<LPRECONVERTSTRING>(lParam);
5276 LRESULT nRet = 0;
5277 SalSurroundingTextRequestEvent aEvt;
5278 aEvt.maText.clear();
5279 aEvt.mnStart = aEvt.mnEnd = 0;
5281 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_SETCOMPSTR );
5282 if( (nImeProps & SCS_CAP_SETRECONVERTSTRING) == 0 )
5284 // This IME does not support reconversion.
5285 return 0;
5288 if( !pReconvertString )
5290 // The first call for reconversion.
5291 pFrame->CallCallback( SalEvent::StartReconversion, nullptr );
5293 // Retrieve the surrounding text from the focused control.
5294 pFrame->CallCallback( SalEvent::SurroundingTextRequest, &aEvt );
5296 if( aEvt.maText.isEmpty())
5298 return 0;
5301 nRet = sizeof(RECONVERTSTRING) + (aEvt.maText.getLength() + 1) * sizeof(WCHAR);
5303 else
5305 // The second call for reconversion.
5307 // Retrieve the surrounding text from the focused control.
5308 pFrame->CallCallback( SalEvent::SurroundingTextRequest, &aEvt );
5309 nRet = sizeof(RECONVERTSTRING) + (aEvt.maText.getLength() + 1) * sizeof(WCHAR);
5311 pReconvertString->dwStrOffset = sizeof(RECONVERTSTRING);
5312 pReconvertString->dwStrLen = aEvt.maText.getLength();
5313 pReconvertString->dwCompStrOffset = aEvt.mnStart * sizeof(WCHAR);
5314 pReconvertString->dwCompStrLen = aEvt.mnEnd - aEvt.mnStart;
5315 pReconvertString->dwTargetStrOffset = pReconvertString->dwCompStrOffset;
5316 pReconvertString->dwTargetStrLen = pReconvertString->dwCompStrLen;
5318 memcpy( pReconvertString + 1, aEvt.maText.getStr(), (aEvt.maText.getLength() + 1) * sizeof(WCHAR) );
5321 // just return the required size of buffer to reconvert.
5322 return nRet;
5325 static LRESULT ImplHandleIMEConfirmReconvertString( HWND hWnd, LPARAM lParam )
5327 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5328 LPRECONVERTSTRING pReconvertString = reinterpret_cast<LPRECONVERTSTRING>(lParam);
5329 SalSurroundingTextRequestEvent aEvt;
5330 aEvt.maText.clear();
5331 aEvt.mnStart = aEvt.mnEnd = 0;
5333 pFrame->CallCallback( SalEvent::SurroundingTextRequest, &aEvt );
5335 sal_uLong nTmpStart = pReconvertString->dwCompStrOffset / sizeof(WCHAR);
5336 sal_uLong nTmpEnd = nTmpStart + pReconvertString->dwCompStrLen;
5338 if( nTmpStart != aEvt.mnStart || nTmpEnd != aEvt.mnEnd )
5340 SalSurroundingTextSelectionChangeEvent aSelEvt;
5341 aSelEvt.mnStart = nTmpStart;
5342 aSelEvt.mnEnd = nTmpEnd;
5344 pFrame->CallCallback( SalEvent::SurroundingTextSelectionChange, &aSelEvt );
5347 return TRUE;
5350 static LRESULT ImplHandleIMEQueryCharPosition( HWND hWnd, LPARAM lParam ) {
5351 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5352 PIMECHARPOSITION pQueryCharPosition = reinterpret_cast<PIMECHARPOSITION>(lParam);
5353 if ( pQueryCharPosition->dwSize < sizeof(IMECHARPOSITION) )
5354 return FALSE;
5356 SalQueryCharPositionEvent aEvt;
5357 aEvt.mbValid = false;
5358 aEvt.mnCharPos = pQueryCharPosition->dwCharPos;
5360 pFrame->CallCallback( SalEvent::QueryCharPosition, &aEvt );
5362 if ( !aEvt.mbValid )
5363 return FALSE;
5365 if ( aEvt.mbVertical )
5367 // For vertical writing, the base line is left edge of the rectangle
5368 // and the target position is top-right corner.
5369 pQueryCharPosition->pt.x = aEvt.mnCursorBoundX + aEvt.mnCursorBoundWidth;
5370 pQueryCharPosition->pt.y = aEvt.mnCursorBoundY;
5371 pQueryCharPosition->cLineHeight = aEvt.mnCursorBoundWidth;
5373 else
5375 // For horizontal writing, the base line is the bottom edge of the rectangle.
5376 // and the target position is top-left corner.
5377 pQueryCharPosition->pt.x = aEvt.mnCursorBoundX;
5378 pQueryCharPosition->pt.y = aEvt.mnCursorBoundY;
5379 pQueryCharPosition->cLineHeight = aEvt.mnCursorBoundHeight;
5382 // Currently not supported but many IMEs usually ignore them.
5383 pQueryCharPosition->rcDocument.left = 0;
5384 pQueryCharPosition->rcDocument.top = 0;
5385 pQueryCharPosition->rcDocument.right = 0;
5386 pQueryCharPosition->rcDocument.bottom = 0;
5388 return TRUE;
5391 void SalTestMouseLeave()
5393 SalData* pSalData = GetSalData();
5395 if ( pSalData->mhWantLeaveMsg && !::GetCapture() )
5397 POINT aPt;
5398 GetCursorPos( &aPt );
5399 if ( pSalData->mhWantLeaveMsg != WindowFromPoint( aPt ) )
5400 SendMessageW( pSalData->mhWantLeaveMsg, SAL_MSG_MOUSELEAVE, 0, MAKELPARAM( aPt.x, aPt.y ) );
5404 static bool ImplSalWheelMousePos( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam ,
5405 LRESULT& rResult )
5407 POINT aPt;
5408 POINT aScreenPt;
5409 aScreenPt.x = static_cast<short>(LOWORD( lParam ));
5410 aScreenPt.y = static_cast<short>(HIWORD( lParam ));
5411 // find child window that is at this position
5412 HWND hChildWnd;
5413 HWND hWheelWnd = hWnd;
5416 hChildWnd = hWheelWnd;
5417 aPt = aScreenPt;
5418 ScreenToClient( hChildWnd, &aPt );
5419 hWheelWnd = ChildWindowFromPointEx( hChildWnd, aPt, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT );
5421 while ( hWheelWnd && (hWheelWnd != hChildWnd) );
5422 if ( hWheelWnd && (hWheelWnd != hWnd) &&
5423 (hWheelWnd != ::GetFocus()) && IsWindowEnabled( hWheelWnd ) )
5425 rResult = SendMessageW( hWheelWnd, nMsg, wParam, lParam );
5426 return false;
5429 return true;
5432 LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, bool& rDef )
5434 LRESULT nRet = 0;
5435 static bool bInWheelMsg = false;
5436 static bool bInQueryEnd = false;
5438 SAL_INFO("vcl.gdi.wndproc", "SalFrameWndProc(nMsg=" << nMsg << ", wParam=" << wParam << ", lParam=" << lParam << ")");
5440 // By WM_CREATE we connect the frame with the window handle
5441 if ( nMsg == WM_CREATE )
5443 // Save Window-Instance in Windowhandle
5444 // Can also be used for the A-Version, because the struct
5445 // to access lpCreateParams is the same structure
5446 CREATESTRUCTW* pStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
5447 WinSalFrame* pFrame = static_cast<WinSalFrame*>(pStruct->lpCreateParams);
5448 if ( pFrame != nullptr )
5450 SetWindowPtr( hWnd, pFrame );
5451 // Set HWND already here, as data might be used already
5452 // when messages are being sent by CreateWindow()
5453 pFrame->mhWnd = hWnd;
5454 pFrame->maSysData.hWnd = hWnd;
5456 return 0;
5459 ImplSVData* pSVData = ImplGetSVData();
5460 // #i72707# TODO: the mbDeInit check will not be needed
5461 // once all windows that are not properly closed on exit got fixed
5462 if( pSVData->mbDeInit )
5463 return 0;
5465 if ( WM_USER_SYSTEM_WINDOW_ACTIVATED == nMsg )
5467 ImplHideSplash();
5468 return 0;
5471 switch( nMsg )
5473 case WM_MOUSEMOVE:
5474 case WM_LBUTTONDOWN:
5475 case WM_MBUTTONDOWN:
5476 case WM_RBUTTONDOWN:
5477 case WM_LBUTTONUP:
5478 case WM_MBUTTONUP:
5479 case WM_RBUTTONUP:
5480 case WM_NCMOUSEMOVE:
5481 case SAL_MSG_MOUSELEAVE:
5482 ImplSalYieldMutexAcquireWithWait();
5483 rDef = !ImplHandleMouseMsg( hWnd, nMsg, wParam, lParam );
5484 ImplSalYieldMutexRelease();
5485 break;
5487 case WM_NCLBUTTONDOWN:
5488 case WM_NCMBUTTONDOWN:
5489 case WM_NCRBUTTONDOWN:
5490 ImplSalYieldMutexAcquireWithWait();
5491 ImplCallClosePopupsHdl( hWnd ); // close popups...
5492 ImplSalYieldMutexRelease();
5493 break;
5495 case WM_MOUSEACTIVATE:
5496 if ( LOWORD( lParam ) == HTCLIENT )
5498 ImplSalYieldMutexAcquireWithWait();
5499 nRet = LRESULT(ImplHandleMouseActivateMsg( hWnd ));
5500 ImplSalYieldMutexRelease();
5501 if ( nRet )
5503 nRet = MA_NOACTIVATE;
5504 rDef = false;
5507 break;
5509 case WM_KEYDOWN:
5510 case WM_KEYUP:
5511 case WM_DEADCHAR:
5512 case WM_CHAR:
5513 case WM_UNICHAR: // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0
5514 case WM_SYSKEYDOWN:
5515 case WM_SYSKEYUP:
5516 case WM_SYSCHAR:
5517 ImplSalYieldMutexAcquireWithWait();
5518 rDef = !ImplHandleKeyMsg( hWnd, nMsg, wParam, lParam, nRet );
5519 ImplSalYieldMutexRelease();
5520 break;
5522 case WM_MOUSEWHEEL:
5523 // FALLTHROUGH intended
5524 case WM_MOUSEHWHEEL:
5525 // protect against recursion, in case the message is returned
5526 // by IE or the external window
5527 if ( !bInWheelMsg )
5529 bInWheelMsg = true;
5530 rDef = !ImplHandleWheelMsg( hWnd, nMsg, wParam, lParam );
5531 // If we did not process the message, re-check if here is a
5532 // connected (?) window that we have to notify.
5533 if ( rDef )
5534 rDef = ImplSalWheelMousePos( hWnd, nMsg, wParam, lParam, nRet );
5535 bInWheelMsg = false;
5537 break;
5539 case WM_COMMAND:
5540 ImplSalYieldMutexAcquireWithWait();
5541 rDef = !ImplHandleCommand( hWnd, wParam, lParam );
5542 ImplSalYieldMutexRelease();
5543 break;
5545 case WM_INITMENUPOPUP:
5546 ImplSalYieldMutexAcquireWithWait();
5547 rDef = !ImplHandleMenuActivate( hWnd, wParam, lParam );
5548 ImplSalYieldMutexRelease();
5549 break;
5551 case WM_MENUSELECT:
5552 ImplSalYieldMutexAcquireWithWait();
5553 rDef = !ImplHandleMenuSelect( hWnd, wParam, lParam );
5554 ImplSalYieldMutexRelease();
5555 break;
5557 case WM_SYSCOMMAND:
5558 ImplSalYieldMutexAcquireWithWait();
5559 nRet = LRESULT(ImplHandleSysCommand( hWnd, wParam, lParam ));
5560 ImplSalYieldMutexRelease();
5561 if ( nRet )
5562 rDef = false;
5563 break;
5565 case WM_MENUCHAR:
5566 nRet = ImplMenuChar( hWnd, wParam, lParam );
5567 if( nRet )
5568 rDef = false;
5569 break;
5571 case WM_MEASUREITEM:
5572 nRet = ImplMeasureItem(hWnd, wParam, lParam);
5573 if( nRet )
5574 rDef = false;
5575 break;
5577 case WM_DRAWITEM:
5578 nRet = ImplDrawItem(hWnd, wParam, lParam);
5579 if( nRet )
5580 rDef = false;
5581 break;
5583 case WM_MOVE:
5584 case SAL_MSG_POSTMOVE:
5585 ImplHandleMoveMsg( hWnd );
5586 rDef = false;
5587 break;
5588 case WM_SIZE:
5589 ImplHandleSizeMsg( hWnd, wParam, lParam );
5590 rDef = false;
5591 break;
5592 case SAL_MSG_POSTCALLSIZE:
5593 ImplCallSizeHdl( hWnd );
5594 rDef = false;
5595 break;
5597 case WM_GETMINMAXINFO:
5598 if ( ImplHandleMinMax( hWnd, lParam ) )
5599 rDef = false;
5600 break;
5602 case WM_ERASEBKGND:
5603 nRet = 1;
5604 rDef = false;
5605 break;
5606 case WM_PAINT:
5607 ImplHandlePaintMsg( hWnd );
5608 rDef = false;
5609 break;
5610 case SAL_MSG_POSTPAINT:
5611 ImplHandlePostPaintMsg( hWnd, reinterpret_cast<RECT*>(wParam) );
5612 rDef = false;
5613 break;
5615 case SAL_MSG_FORCEPALETTE:
5616 ImplHandleForcePalette( hWnd );
5617 rDef = false;
5618 break;
5620 case WM_QUERYNEWPALETTE:
5621 case SAL_MSG_POSTQUERYNEWPAL:
5622 nRet = ImplHandlePalette( true, hWnd, nMsg, wParam, lParam, rDef );
5623 break;
5625 case WM_ACTIVATE:
5626 // Getting activated, we also want to set our palette.
5627 // We do this in Activate, so that other external child windows
5628 // can overwrite our palette. Thus our palette is set only once
5629 // and not recursively, as at all other places it is set only as
5630 // the background palette.
5631 if ( LOWORD( wParam ) != WA_INACTIVE )
5632 SendMessageW( hWnd, SAL_MSG_FORCEPALETTE, 0, 0 );
5633 break;
5635 case WM_ENABLE:
5636 // #95133# a system dialog is opened/closed, using our app window as parent
5638 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5639 vcl::Window *pWin = nullptr;
5640 if( pFrame )
5641 pWin = pFrame->GetWindow();
5643 if( !wParam )
5645 pSVData->maAppData.mnModalMode++;
5647 ImplHideSplash();
5648 if( pWin )
5650 pWin->EnableInput( false, nullptr );
5651 pWin->IncModalCount(); // #106303# support frame based modal count
5654 else
5656 ImplGetSVData()->maAppData.mnModalMode--;
5657 if( pWin )
5659 pWin->EnableInput( true, nullptr );
5660 pWin->DecModalCount(); // #106303# support frame based modal count
5664 break;
5666 case WM_KILLFOCUS:
5667 DestroyCaret();
5668 SAL_FALLTHROUGH;
5669 case WM_SETFOCUS:
5670 case SAL_MSG_POSTFOCUS:
5671 ImplHandleFocusMsg( hWnd );
5672 rDef = false;
5673 break;
5675 case WM_CLOSE:
5676 ImplHandleCloseMsg( hWnd );
5677 rDef = false;
5678 break;
5680 case WM_QUERYENDSESSION:
5681 if( !bInQueryEnd )
5683 // handle queryendsession only once
5684 bInQueryEnd = true;
5685 nRet = LRESULT(!ImplHandleShutDownMsg( hWnd ));
5686 rDef = false;
5688 // Issue #16314#: ImplHandleShutDownMsg causes a PostMessage in case of allowing shutdown.
5689 // This posted message was never processed and cause Windows XP to hang after log off
5690 // if there are multiple sessions and the current session wasn't the first one started.
5691 // So if shutdown is allowed we assume that a post message was done and retrieve all
5692 // messages in the message queue and dispatch them before we return control to the system.
5694 if ( nRet )
5696 SolarMutexGuard aGuard;
5697 while ( Application::Reschedule( true ) );
5700 else
5702 ImplSalYieldMutexAcquireWithWait();
5703 ImplSalYieldMutexRelease();
5704 rDef = true;
5706 break;
5708 case WM_ENDSESSION:
5709 if( !wParam )
5710 bInQueryEnd = false; // no shutdown: allow query again
5711 nRet = FALSE;
5712 rDef = false;
5713 break;
5715 case WM_DISPLAYCHANGE:
5716 case WM_SETTINGCHANGE:
5717 case WM_DEVMODECHANGE:
5718 case WM_FONTCHANGE:
5719 case WM_SYSCOLORCHANGE:
5720 case WM_TIMECHANGE:
5721 ImplHandleSettingsChangeMsg( hWnd, nMsg, wParam, lParam );
5722 break;
5724 case WM_THEMECHANGED:
5725 GetSalData()->mbThemeChanged = true;
5726 break;
5728 case SAL_MSG_USEREVENT:
5729 ImplHandleUserEvent( hWnd, lParam );
5730 rDef = false;
5731 break;
5733 case SAL_MSG_CAPTUREMOUSE:
5734 SetCapture( hWnd );
5735 rDef = false;
5736 break;
5737 case SAL_MSG_RELEASEMOUSE:
5738 if ( ::GetCapture() == hWnd )
5739 ReleaseCapture();
5740 rDef = false;
5741 break;
5742 case SAL_MSG_TOTOP:
5743 ImplSalToTop( hWnd, static_cast<SalFrameToTop>(wParam) );
5744 rDef = false;
5745 break;
5746 case SAL_MSG_SHOW:
5747 ImplSalShow( hWnd, static_cast<bool>(wParam), static_cast<bool>(lParam) );
5748 rDef = false;
5749 break;
5750 case SAL_MSG_SETINPUTCONTEXT:
5751 ImplSalFrameSetInputContext( hWnd, reinterpret_cast<const SalInputContext*>(lParam) );
5752 rDef = false;
5753 break;
5754 case SAL_MSG_ENDEXTTEXTINPUT:
5755 ImplSalFrameEndExtTextInput( hWnd, static_cast<EndExtTextInputFlags>(wParam) );
5756 rDef = false;
5757 break;
5759 case WM_INPUTLANGCHANGE:
5760 ImplHandleInputLangChange( hWnd, wParam, lParam );
5761 break;
5763 case WM_IME_CHAR:
5764 // #103487#, some IMEs (eg, those that do not work onspot)
5765 // may send WM_IME_CHAR instead of WM_IME_COMPOSITION
5766 // we just handle it like a WM_CHAR message - seems to work fine
5767 ImplSalYieldMutexAcquireWithWait();
5768 rDef = !ImplHandleKeyMsg( hWnd, WM_CHAR, wParam, lParam, nRet );
5769 ImplSalYieldMutexRelease();
5770 break;
5772 case WM_IME_STARTCOMPOSITION:
5773 rDef = ImplHandleIMEStartComposition( hWnd );
5774 break;
5776 case WM_IME_COMPOSITION:
5777 rDef = ImplHandleIMEComposition( hWnd, lParam );
5778 break;
5780 case WM_IME_ENDCOMPOSITION:
5781 rDef = ImplHandleIMEEndComposition( hWnd );
5782 break;
5784 case WM_IME_NOTIFY:
5785 ImplHandleIMENotify( hWnd, wParam );
5786 break;
5788 case WM_GETOBJECT:
5789 ImplSalYieldMutexAcquireWithWait();
5790 if ( ImplHandleGetObject( hWnd, lParam, wParam, nRet ) )
5792 rDef = false;
5794 ImplSalYieldMutexRelease();
5795 break;
5797 case WM_APPCOMMAND:
5798 if( ImplHandleAppCommand( hWnd, lParam, nRet ) )
5800 rDef = false;
5802 break;
5803 case WM_IME_REQUEST:
5804 if ( static_cast<sal_uIntPtr>(wParam) == IMR_RECONVERTSTRING )
5806 nRet = ImplHandleIMEReconvertString( hWnd, lParam );
5807 rDef = false;
5809 else if( static_cast<sal_uIntPtr>(wParam) == IMR_CONFIRMRECONVERTSTRING )
5811 nRet = ImplHandleIMEConfirmReconvertString( hWnd, lParam );
5812 rDef = false;
5814 else if ( static_cast<sal_uIntPtr>(wParam) == IMR_QUERYCHARPOSITION )
5816 if ( ImplSalYieldMutexTryToAcquire() )
5818 nRet = ImplHandleIMEQueryCharPosition( hWnd, lParam );
5819 ImplSalYieldMutexRelease();
5821 else
5822 nRet = FALSE;
5823 rDef = false;
5825 break;
5828 return nRet;
5831 LRESULT CALLBACK SalFrameWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
5833 bool bDef = true;
5834 LRESULT nRet = 0;
5835 __try
5837 nRet = SalFrameWndProc( hWnd, nMsg, wParam, lParam, bDef );
5839 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
5843 if ( bDef )
5844 nRet = DefWindowProcW( hWnd, nMsg, wParam, lParam );
5845 return nRet;
5848 bool ImplHandleGlobalMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT& rlResult )
5850 // handle all messages concerning all frames so they get processed only once
5851 // Must work for Unicode and none Unicode
5852 bool bResult = false;
5853 if ( (nMsg == WM_PALETTECHANGED) || (nMsg == SAL_MSG_POSTPALCHANGED) )
5855 bResult = true;
5856 rlResult = ImplHandlePalette( false, hWnd, nMsg, wParam, lParam, bResult );
5858 else if( nMsg == WM_DISPLAYCHANGE )
5860 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
5861 if( pSys )
5862 pSys->clearMonitors();
5863 bResult = (pSys != nullptr);
5865 return bResult;
5868 #ifdef _WIN32
5869 bool HasAtHook()
5871 BOOL bIsRunning = FALSE;
5872 // pvParam must be BOOL
5873 return SystemParametersInfoW(SPI_GETSCREENREADER, 0, &bIsRunning, 0)
5874 && bIsRunning;
5876 #endif
5878 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */