1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include <officecfg/Office/Common.hxx>
33 #include <comphelper/windowserrorstring.hxx>
36 #include <boost/property_tree/ptree.hpp>
37 #include <boost/property_tree/ini_parser.hpp>
38 #include <osl/file.hxx>
39 #include <osl/process.h>
41 #include <rtl/character.hxx>
42 #include <rtl/string.h>
43 #include <rtl/ustring.h>
44 #include <sal/log.hxx>
46 #include <osl/module.h>
47 #include <comphelper/scopeguard.hxx>
48 #include <tools/debug.hxx>
49 #include <o3tl/enumarray.hxx>
50 #include <o3tl/char16_t2wchar_t.hxx>
52 #include <vcl/event.hxx>
53 #include <vcl/sysdata.hxx>
54 #include <vcl/timer.hxx>
55 #include <vcl/settings.hxx>
56 #include <vcl/keycodes.hxx>
57 #include <vcl/window.hxx>
58 #include <vcl/wrkwin.hxx>
59 #include <vcl/svapp.hxx>
60 #include <vcl/ptrstyle.hxx>
62 #include <win/wincomp.hxx>
63 #include <win/salids.hrc>
64 #include <win/saldata.hxx>
65 #include <win/salinst.h>
66 #include <win/salbmp.h>
67 #include <win/salgdi.h>
68 #include <win/salsys.h>
69 #include <win/salframe.h>
70 #include <win/salvd.h>
71 #include <win/salmenu.h>
72 #include <win/salobj.h>
73 #include <win/saltimer.h>
75 #include <helpwin.hxx>
77 #include <sallayout.hxx>
81 #include <com/sun/star/uno/Exception.hpp>
84 #include <com/sun/star/accessibility/XMSAAService.hpp>
88 #if !defined WIN32_LEAN_AND_MEAN
89 # define WIN32_LEAN_AND_MEAN
95 #include <propvarutil.h>
100 using namespace ::com::sun::star
;
101 using namespace ::com::sun::star::uno
;
102 using namespace ::com::sun::star::lang
;
103 using namespace ::com::sun::star::container
;
104 using namespace ::com::sun::star::beans
;
107 # define IDC_PEN MAKEINTRESOURCE(32631)
110 const unsigned int WM_USER_SYSTEM_WINDOW_ACTIVATED
= RegisterWindowMessageW(L
"SYSTEM_WINDOW_ACTIVATED");
112 bool WinSalFrame::mbInReparent
= false;
114 // Macros for support of WM_UNICHAR & Keyman 6.0
115 #define Uni_SupplementaryPlanesStart 0x10000
117 static void UpdateFrameGeometry(WinSalFrame
* pFrame
);
118 static void SetMaximizedFrameGeometry( HWND hWnd
, WinSalFrame
* pFrame
, RECT
* pParentRect
= nullptr );
120 static void SetGeometrySize(vcl::WindowPosSize
& rWinPosSize
, const Size
& rSize
)
122 rWinPosSize
.setWidth(rSize
.Width() < 0 ? 0 : rSize
.Width());
123 rWinPosSize
.setHeight(rSize
.Height() < 0 ? 0 : rSize
.Height());
126 // If called with UpdateFrameGeometry, it must be called after it, as UpdateFrameGeometry
127 // updates the geometry depending on the old state!
128 void WinSalFrame::UpdateFrameState()
130 // don't overwrite restore state in fullscreen mode
134 const bool bVisible
= (GetWindowStyle(mhWnd
) & WS_VISIBLE
);
137 m_eState
&= ~vcl::WindowState(vcl::WindowState::Normal
| vcl::WindowState::Maximized
);
138 m_eState
|= vcl::WindowState::Minimized
;
140 mnShowState
= SW_SHOWMINIMIZED
;
142 else if (IsZoomed(mhWnd
))
144 m_eState
&= ~vcl::WindowState(vcl::WindowState::Minimized
| vcl::WindowState::Normal
);
145 m_eState
|= vcl::WindowState::Maximized
;
147 mnShowState
= SW_SHOWMAXIMIZED
;
148 mbRestoreMaximize
= true;
152 m_eState
&= ~vcl::WindowState(vcl::WindowState::Minimized
| vcl::WindowState::Maximized
);
153 m_eState
|= vcl::WindowState::Normal
;
155 mnShowState
= SW_SHOWNORMAL
;
156 mbRestoreMaximize
= false;
160 // if pParentRect is set, the workarea of the monitor that contains pParentRect is returned
161 void ImplSalGetWorkArea( HWND hWnd
, RECT
*pRect
, const RECT
*pParentRect
)
163 if (Application::IsHeadlessModeEnabled()) {
166 pRect
->right
= VIRTUAL_DESKTOP_WIDTH
;
167 pRect
->bottom
= VIRTUAL_DESKTOP_HEIGHT
;
170 // check if we or our parent is fullscreen, then the taskbar should be ignored
171 bool bIgnoreTaskbar
= false;
172 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
175 vcl::Window
*pWin
= pFrame
->GetWindow();
178 WorkWindow
*pWorkWin
= (pWin
->GetType() == WindowType::WORKWINDOW
) ? static_cast<WorkWindow
*>(pWin
) : nullptr;
179 if( pWorkWin
&& pWorkWin
->ImplGetWindowImpl()->mbReallyVisible
&& pWorkWin
->IsFullScreenMode() )
181 bIgnoreTaskbar
= true;
185 pWin
= pWin
->ImplGetWindowImpl()->mpParent
;
189 // calculates the work area taking multiple monitors into account
190 static int nMonitors
= GetSystemMetrics( SM_CMONITORS
);
195 pRect
->left
= pRect
->top
= 0;
196 pRect
->right
= GetSystemMetrics( SM_CXSCREEN
);
197 pRect
->bottom
= GetSystemMetrics( SM_CYSCREEN
);
200 SystemParametersInfoW( SPI_GETWORKAREA
, 0, pRect
, 0 );
204 if( pParentRect
!= nullptr )
206 // return the size of the monitor where pParentRect lives
210 // get the nearest monitor to the passed rect.
211 hMonitor
= MonitorFromRect(pParentRect
, MONITOR_DEFAULTTONEAREST
);
213 // get the work area or entire monitor rect.
214 mi
.cbSize
= sizeof(mi
);
215 GetMonitorInfo(hMonitor
, &mi
);
216 if( !bIgnoreTaskbar
)
219 *pRect
= mi
.rcMonitor
;
223 // return the union of all monitors
224 pRect
->left
= GetSystemMetrics( SM_XVIRTUALSCREEN
);
225 pRect
->top
= GetSystemMetrics( SM_YVIRTUALSCREEN
);
226 pRect
->right
= pRect
->left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
);
227 pRect
->bottom
= pRect
->top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
);
229 // virtualscreen does not take taskbar into account, so use the corresponding
230 // diffs between screen and workarea from the default screen
231 // however, this is still not perfect: the taskbar might not be on the primary screen
232 if( !bIgnoreTaskbar
)
235 SystemParametersInfoW( SPI_GETWORKAREA
, 0, &wRect
, 0 );
238 scrRect
.right
= GetSystemMetrics( SM_CXSCREEN
);
239 scrRect
.bottom
= GetSystemMetrics( SM_CYSCREEN
);
241 pRect
->left
+= wRect
.left
;
242 pRect
->top
+= wRect
.top
;
243 pRect
->right
-= scrRect
.right
- wRect
.right
;
244 pRect
->bottom
-= scrRect
.bottom
- wRect
.bottom
;
252 enum PreferredAppMode
261 static void UpdateDarkMode(HWND hWnd
)
263 static bool bOSSupportsDarkMode
= OSSupportsDarkMode();
264 if (!bOSSupportsDarkMode
)
267 HINSTANCE hUxthemeLib
= LoadLibraryExW(L
"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32
);
271 typedef PreferredAppMode(WINAPI
* SetPreferredAppMode_t
)(PreferredAppMode
);
272 auto SetPreferredAppMode
= reinterpret_cast<SetPreferredAppMode_t
>(GetProcAddress(hUxthemeLib
, MAKEINTRESOURCEA(135)));
273 if (SetPreferredAppMode
)
275 switch (MiscSettings::GetDarkMode())
278 SetPreferredAppMode(AllowDark
);
281 SetPreferredAppMode(ForceLight
);
284 SetPreferredAppMode(ForceDark
);
289 BOOL bDarkMode
= UseDarkMode();
291 typedef void(WINAPI
* AllowDarkModeForWindow_t
)(HWND
, BOOL
);
292 auto AllowDarkModeForWindow
= reinterpret_cast<AllowDarkModeForWindow_t
>(GetProcAddress(hUxthemeLib
, MAKEINTRESOURCEA(133)));
293 if (AllowDarkModeForWindow
)
294 AllowDarkModeForWindow(hWnd
, bDarkMode
);
296 FreeLibrary(hUxthemeLib
);
298 if (!AllowDarkModeForWindow
)
301 DwmSetWindowAttribute(hWnd
, 20, &bDarkMode
, sizeof(bDarkMode
));
304 SalFrame
* ImplSalCreateFrame( WinSalInstance
* pInst
,
305 HWND hWndParent
, SalFrameStyleFlags nSalFrameStyle
)
307 WinSalFrame
* pFrame
= new WinSalFrame
;
310 DWORD nExSysStyle
= 0;
311 bool bSubFrame
= false;
313 static const char* pEnvSynchronize
= getenv("SAL_SYNCHRONIZE");
314 if ( pEnvSynchronize
) // no buffering of drawing commands
315 GdiSetBatchLimit( 1 );
317 static const char* pEnvTransparentFloats
= getenv("SAL_TRANSPARENT_FLOATS" );
319 // determine creation data
320 if ( nSalFrameStyle
& (SalFrameStyleFlags::PLUG
| SalFrameStyleFlags::SYSTEMCHILD
) )
322 nSysStyle
|= WS_CHILD
;
323 if( nSalFrameStyle
& SalFrameStyleFlags::SYSTEMCHILD
)
324 nSysStyle
|= WS_CLIPSIBLINGS
;
328 // #i87402# commenting out WS_CLIPCHILDREN
329 // this breaks SalFrameStyleFlags::SYSTEMCHILD handling, which is not
330 // used currently. Probably SalFrameStyleFlags::SYSTEMCHILD should be
333 // nSysStyle |= WS_CLIPCHILDREN;
336 nSysStyle
|= WS_POPUP
;
338 pFrame
->mbNoIcon
= true;
342 // Only with WS_OVERLAPPED we get a useful default position/size
343 if ( (nSalFrameStyle
& (SalFrameStyleFlags::SIZEABLE
| SalFrameStyleFlags::MOVEABLE
)) ==
344 (SalFrameStyleFlags::SIZEABLE
| SalFrameStyleFlags::MOVEABLE
) )
345 nSysStyle
|= WS_OVERLAPPED
;
348 nSysStyle
|= WS_POPUP
;
349 if ( !(nSalFrameStyle
& SalFrameStyleFlags::MOVEABLE
) )
350 nExSysStyle
|= WS_EX_TOOLWINDOW
; // avoid taskbar appearance, for eg splash screen
354 if ( nSalFrameStyle
& SalFrameStyleFlags::MOVEABLE
)
356 pFrame
->mbCaption
= true;
357 nSysStyle
|= WS_SYSMENU
| WS_CAPTION
;
359 nSysStyle
|= WS_SYSMENU
| WS_MINIMIZEBOX
;
361 nExSysStyle
|= WS_EX_DLGMODALFRAME
;
363 if ( nSalFrameStyle
& SalFrameStyleFlags::SIZEABLE
)
365 pFrame
->mbSizeBorder
= true;
366 nSysStyle
|= WS_THICKFRAME
;
368 nSysStyle
|= WS_MAXIMIZEBOX
;
371 pFrame
->mbFixBorder
= true;
373 if ( nSalFrameStyle
& SalFrameStyleFlags::DEFAULT
)
374 nExSysStyle
|= WS_EX_APPWINDOW
;
376 if( nSalFrameStyle
& SalFrameStyleFlags::TOOLWINDOW
377 // #100656# toolwindows lead to bad alt-tab behaviour, if they have the focus
378 // you must press it twice to leave the application
379 // so toolwindows are only used for non sizeable windows
380 // which are typically small, so a small caption makes sense
382 // #103578# looked too bad - above changes reverted
383 /* && !(nSalFrameStyle & SalFrameStyleFlags::SIZEABLE) */ )
385 pFrame
->mbNoIcon
= true;
386 nExSysStyle
|= WS_EX_TOOLWINDOW
;
387 if ( pEnvTransparentFloats
/*&& !(nSalFrameStyle & SalFrameStyleFlags::MOVEABLE) */)
388 nExSysStyle
|= WS_EX_LAYERED
;
391 if ( nSalFrameStyle
& SalFrameStyleFlags::FLOAT
)
393 nExSysStyle
|= WS_EX_TOOLWINDOW
;
394 pFrame
->mbFloatWin
= true;
396 if (pEnvTransparentFloats
)
397 nExSysStyle
|= WS_EX_LAYERED
;
400 if (nSalFrameStyle
& SalFrameStyleFlags::TOOLTIP
)
401 nExSysStyle
|= WS_EX_TOPMOST
;
404 pFrame
->mnStyle
= nSalFrameStyle
;
406 // determine show style
407 pFrame
->mnShowState
= SW_SHOWNORMAL
;
408 if ( (nSysStyle
& (WS_POPUP
| WS_MAXIMIZEBOX
| WS_THICKFRAME
)) == (WS_MAXIMIZEBOX
| WS_THICKFRAME
) )
410 if ( GetSystemMetrics( SM_CXSCREEN
) <= 1024 )
411 pFrame
->mnShowState
= SW_SHOWMAXIMIZED
;
414 if ( nSalFrameStyle
& SalFrameStyleFlags::DEFAULT
)
416 SalData
* pSalData
= GetSalData();
417 pFrame
->mnShowState
= pSalData
->mnCmdShow
;
418 if ( (pFrame
->mnShowState
!= SW_SHOWMINIMIZED
) &&
419 (pFrame
->mnShowState
!= SW_MINIMIZE
) &&
420 (pFrame
->mnShowState
!= SW_SHOWMINNOACTIVE
) )
422 if ( (pFrame
->mnShowState
== SW_SHOWMAXIMIZED
) ||
423 (pFrame
->mnShowState
== SW_MAXIMIZE
) )
424 pFrame
->mbOverwriteState
= false;
425 pFrame
->mnShowState
= SW_SHOWMAXIMIZED
;
428 pFrame
->mbOverwriteState
= false;
432 // Document Windows are also maximized, if the current Document Window
434 HWND hWnd2
= GetForegroundWindow();
435 if ( hWnd2
&& IsMaximized( hWnd2
) &&
436 (GetWindowInstance( hWnd2
) == pInst
->mhInst
) &&
437 ((GetWindowStyle( hWnd2
) & (WS_POPUP
| WS_MAXIMIZEBOX
| WS_THICKFRAME
)) == (WS_MAXIMIZEBOX
| WS_THICKFRAME
)) )
438 pFrame
->mnShowState
= SW_SHOWMAXIMIZED
;
447 if ( nSalFrameStyle
& (SalFrameStyleFlags::MOVEABLE
|SalFrameStyleFlags::NOSHADOW
) ) // check if shadow not wanted
448 pClassName
= SAL_SUBFRAME_CLASSNAMEW
;
450 pClassName
= SAL_TMPSUBFRAME_CLASSNAMEW
; // undecorated floaters will get shadow on XP
454 if ( nSalFrameStyle
& SalFrameStyleFlags::MOVEABLE
)
455 pClassName
= SAL_FRAME_CLASSNAMEW
;
457 pClassName
= SAL_TMPSUBFRAME_CLASSNAMEW
;
459 hWnd
= CreateWindowExW( nExSysStyle
, pClassName
, L
"", nSysStyle
,
460 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
461 hWndParent
, nullptr, pInst
->mhInst
, pFrame
);
462 SAL_WARN_IF(!hWnd
, "vcl", "CreateWindowExW failed: " << WindowsErrorString(GetLastError()));
464 #if OSL_DEBUG_LEVEL > 1
465 // set transparency value
466 if( GetWindowExStyle( hWnd
) & WS_EX_LAYERED
)
467 SetLayeredWindowAttributes( hWnd
, 0, 230, 0x00000002 /*LWA_ALPHA*/ );
475 // If we have a Window with a Caption Bar and without
476 // a MaximizeBox, we change the SystemMenu
477 if ( (nSysStyle
& (WS_CAPTION
| WS_MAXIMIZEBOX
)) == (WS_CAPTION
) )
479 HMENU hSysMenu
= GetSystemMenu( hWnd
, FALSE
);
482 if ( !(nSysStyle
& (WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
)) )
483 DeleteMenu( hSysMenu
, SC_RESTORE
, MF_BYCOMMAND
);
485 EnableMenuItem( hSysMenu
, SC_RESTORE
, MF_BYCOMMAND
| MF_GRAYED
| MF_DISABLED
);
486 if ( !(nSysStyle
& WS_MINIMIZEBOX
) )
487 DeleteMenu( hSysMenu
, SC_MINIMIZE
, MF_BYCOMMAND
);
488 if ( !(nSysStyle
& WS_MAXIMIZEBOX
) )
489 DeleteMenu( hSysMenu
, SC_MAXIMIZE
, MF_BYCOMMAND
);
490 if ( !(nSysStyle
& WS_THICKFRAME
) )
491 DeleteMenu( hSysMenu
, SC_SIZE
, MF_BYCOMMAND
);
494 if ( (nSysStyle
& WS_SYSMENU
) && !(nSalFrameStyle
& SalFrameStyleFlags::CLOSEABLE
) )
496 HMENU hSysMenu
= GetSystemMenu( hWnd
, FALSE
);
498 EnableMenuItem( hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
| MF_GRAYED
| MF_DISABLED
);
501 // reset input context
502 pFrame
->mhDefIMEContext
= ImmAssociateContext( hWnd
, nullptr );
504 // determine output size and state
506 GetClientRect( hWnd
, &aRect
);
507 pFrame
->mbDefPos
= true;
509 UpdateFrameGeometry(pFrame
);
510 pFrame
->UpdateFrameState();
512 if( pFrame
->mnShowState
== SW_SHOWMAXIMIZED
)
514 // #96084 set a useful internal window size because
515 // the window will not be maximized (and the size updated) before show()
517 SetMaximizedFrameGeometry( hWnd
, pFrame
);
523 // helper that only creates the HWND
524 // to allow for easy reparenting of system windows, (i.e. destroy and create new)
525 HWND
ImplSalReCreateHWND( HWND hWndParent
, HWND oldhWnd
, bool bAsChild
)
527 HINSTANCE hInstance
= GetSalData()->mhInst
;
528 sal_uLong nSysStyle
= GetWindowLongW( oldhWnd
, GWL_STYLE
);
529 sal_uLong nExSysStyle
= GetWindowLongW( oldhWnd
, GWL_EXSTYLE
);
533 nSysStyle
= WS_CHILD
;
537 LPCWSTR pClassName
= SAL_SUBFRAME_CLASSNAMEW
;
538 return CreateWindowExW( nExSysStyle
, pClassName
, L
"", nSysStyle
,
539 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
540 hWndParent
, nullptr, hInstance
, GetWindowPtr( oldhWnd
) );
543 // translation table from System keycodes into StartView keycodes
544 #define KEY_TAB_SIZE 168
546 const sal_uInt16 aImplTranslateKeyTab
[KEY_TAB_SIZE
] =
548 // StarView-Code System-Code Index
557 KEY_BACKSPACE
, // VK_BACK 8
562 KEY_RETURN
, // VK_RETURN 13
574 KEY_HANGUL_HANJA
, // VK_HANJA 25
576 KEY_ESCAPE
, // VK_ESCAPE 27
581 KEY_SPACE
, // VK_SPACE 32
582 KEY_PAGEUP
, // VK_PRIOR 33
583 KEY_PAGEDOWN
, // VK_NEXT 34
584 KEY_END
, // VK_END 35
585 KEY_HOME
, // VK_HOME 36
586 KEY_LEFT
, // VK_LEFT 37
588 KEY_RIGHT
, // VK_RIGHT 39
589 KEY_DOWN
, // VK_DOWN 40
594 KEY_INSERT
, // VK_INSERT 45
595 KEY_DELETE
, // VK_DELETE 46
596 KEY_HELP
, // VK_HELP 47
642 KEY_CONTEXTMENU
, // VK_APPS 93
645 KEY_0
, // VK_NUMPAD0 96
646 KEY_1
, // VK_NUMPAD1 97
647 KEY_2
, // VK_NUMPAD2 98
648 KEY_3
, // VK_NUMPAD3 99
649 KEY_4
, // VK_NUMPAD4 100
650 KEY_5
, // VK_NUMPAD5 101
651 KEY_6
, // VK_NUMPAD6 102
652 KEY_7
, // VK_NUMPAD7 103
653 KEY_8
, // VK_NUMPAD8 104
654 KEY_9
, // VK_NUMPAD9 105
655 KEY_MULTIPLY
, // VK_MULTIPLY 106
656 KEY_ADD
, // VK_ADD 107
657 KEY_DECIMAL
, // VK_SEPARATOR 108
658 KEY_SUBTRACT
, // VK_SUBTRACT 109
659 KEY_DECIMAL
, // VK_DECIMAL 110
660 KEY_DIVIDE
, // VK_DIVIDE 111
670 KEY_F10
, // VK_F10 121
671 KEY_F11
, // VK_F11 122
672 KEY_F12
, // VK_F12 123
673 KEY_F13
, // VK_F13 124
674 KEY_F14
, // VK_F14 125
675 KEY_F15
, // VK_F15 126
676 KEY_F16
, // VK_F16 127
677 KEY_F17
, // VK_F17 128
678 KEY_F18
, // VK_F18 129
679 KEY_F19
, // VK_F19 130
680 KEY_F20
, // VK_F20 131
681 KEY_F21
, // VK_F21 132
682 KEY_F22
, // VK_F22 133
683 KEY_F23
, // VK_F23 134
684 KEY_F24
, // VK_F24 135
715 KEY_XF86BACK
, // VK_BROWSER_BACK 166
716 KEY_XF86FORWARD
// VK_BROWSER_FORWARD 167
719 static UINT
ImplSalGetWheelScrollLines()
722 HWND hWndMsWheel
= FindWindowW( MSH_WHEELMODULE_CLASS
, MSH_WHEELMODULE_TITLE
);
725 UINT nGetScrollLinesMsgId
= RegisterWindowMessageW( MSH_SCROLL_LINES
);
726 nScrLines
= static_cast<UINT
>(SendMessageW( hWndMsWheel
, nGetScrollLinesMsgId
, 0, 0 ));
730 if( !SystemParametersInfoW( SPI_GETWHEELSCROLLLINES
, 0, &nScrLines
, 0 ) )
739 static UINT
ImplSalGetWheelScrollChars()
742 if( !SystemParametersInfoW( SPI_GETWHEELSCROLLCHARS
, 0, &nScrChars
, 0 ) )
747 // system settings successfully read
751 static void ImplSalAddBorder( const WinSalFrame
* pFrame
, int& width
, int& height
)
753 // transform client size into window size
756 aWinRect
.right
= width
-1;
758 aWinRect
.bottom
= height
-1;
759 AdjustWindowRectEx( &aWinRect
, GetWindowStyle( pFrame
->mhWnd
),
760 FALSE
, GetWindowExStyle( pFrame
->mhWnd
) );
761 width
= aWinRect
.right
- aWinRect
.left
+ 1;
762 height
= aWinRect
.bottom
- aWinRect
.top
+ 1;
765 static void ImplSalCalcFullScreenSize( const WinSalFrame
* pFrame
,
766 int& rX
, int& rY
, int& rDX
, int& rDY
)
768 // set window to screen size
777 if ( pFrame
->mbSizeBorder
)
779 nFrameX
= GetSystemMetrics( SM_CXSIZEFRAME
);
780 nFrameY
= GetSystemMetrics( SM_CYSIZEFRAME
);
782 else if ( pFrame
->mbFixBorder
)
784 nFrameX
= GetSystemMetrics( SM_CXFIXEDFRAME
);
785 nFrameY
= GetSystemMetrics( SM_CYFIXEDFRAME
);
787 else if ( pFrame
->mbBorder
)
789 nFrameX
= GetSystemMetrics( SM_CXBORDER
);
790 nFrameY
= GetSystemMetrics( SM_CYBORDER
);
797 if ( pFrame
->mbCaption
)
798 nCaptionY
= GetSystemMetrics( SM_CYCAPTION
);
804 AbsoluteScreenPixelRectangle aRect
;
805 sal_Int32 nMonitors
= Application::GetScreenCount();
806 if( (pFrame
->mnDisplay
>= 0) && (pFrame
->mnDisplay
< nMonitors
) )
808 aRect
= Application::GetScreenPosSizePixel(pFrame
->mnDisplay
);
812 for (sal_Int32 i
= 0; i
< nMonitors
; i
++)
813 aRect
.Union(Application::GetScreenPosSizePixel(i
));
815 nScreenX
= aRect
.Left();
816 nScreenY
= aRect
.Top();
817 nScreenDX
= aRect
.GetWidth();
818 nScreenDY
= aRect
.GetHeight();
824 if( !nScreenDX
|| !nScreenDY
)
826 nScreenDX
= GetSystemMetrics( SM_CXSCREEN
);
827 nScreenDY
= GetSystemMetrics( SM_CYSCREEN
);
830 rX
= nScreenX
-nFrameX
;
831 rY
= nScreenY
-(nFrameY
+nCaptionY
);
832 rDX
= nScreenDX
+(nFrameX
*2);
833 rDY
= nScreenDY
+(nFrameY
*2)+nCaptionY
;
836 static void ImplSalFrameFullScreenPos( WinSalFrame
* pFrame
, bool bAlways
= false )
838 if ( bAlways
|| !IsIconic( pFrame
->mhWnd
) )
840 // set window to screen size
845 ImplSalCalcFullScreenSize( pFrame
, nX
, nY
, nWidth
, nHeight
);
846 SetWindowPos( pFrame
->mhWnd
, nullptr,
847 nX
, nY
, nWidth
, nHeight
,
848 SWP_NOZORDER
| SWP_NOACTIVATE
);
854 void SetForegroundWindow_Impl(HWND hwnd
)
856 if (!Application::IsHeadlessModeEnabled())
857 SetForegroundWindow(hwnd
);
862 WinSalFrame::WinSalFrame()
864 SalData
* pSalData
= GetSalData();
867 mhCursor
= LoadCursor( nullptr, IDC_ARROW
);
868 mhDefIMEContext
= nullptr;
869 mpLocalGraphics
= nullptr;
870 mpThreadGraphics
= nullptr;
871 m_eState
= vcl::WindowState::Normal
;
872 mnShowState
= SW_SHOWNORMAL
;
875 mnMaxWidth
= SHRT_MAX
;
876 mnMaxHeight
= SHRT_MAX
;
883 mbSizeBorder
= false;
884 mbFullScreenCaption
= false;
885 mbPresentation
= false;
887 mbRestoreMaximize
= false;
890 mbFullScreenToolWin
= false;
892 mbOverwriteState
= true;
896 mbAtCursorIME
= false;
897 mbCandidateMode
= false;
900 mSelectedhMenu
= nullptr;
901 mLastActivatedhMenu
= nullptr;
902 mpClipRgnData
= nullptr;
903 mbFirstClipRect
= true;
904 mpNextClipRect
= nullptr;
906 mbPropertiesStored
= false;
908 // get data, when making 1st frame
909 if ( !pSalData
->mpFirstFrame
)
911 if ( !aSalShlData
.mnWheelScrollLines
)
912 aSalShlData
.mnWheelScrollLines
= ImplSalGetWheelScrollLines();
913 if ( !aSalShlData
.mnWheelScrollChars
)
914 aSalShlData
.mnWheelScrollChars
= ImplSalGetWheelScrollChars();
917 // insert frame in framelist
918 mpNextFrame
= pSalData
->mpFirstFrame
;
919 pSalData
->mpFirstFrame
= this;
922 void WinSalFrame::updateScreenNumber()
924 if( mnDisplay
== -1 ) // spans all monitors
926 WinSalSystem
* pSys
= static_cast<WinSalSystem
*>(ImplGetSalSystem());
929 const std::vector
<WinSalSystem::DisplayMonitor
>& rMonitors
=
931 AbsoluteScreenPixelPoint
aPoint(maGeometry
.pos());
932 size_t nMon
= rMonitors
.size();
933 for( size_t i
= 0; i
< nMon
; i
++ )
935 if( rMonitors
[i
].m_aArea
.Contains( aPoint
) )
937 mnDisplay
= static_cast<sal_Int32
>(i
);
938 maGeometry
.setScreen(static_cast<unsigned int>(i
));
944 bool WinSalFrame::ReleaseFrameGraphicsDC( WinSalGraphics
* pGraphics
)
947 SalData
* pSalData
= GetSalData();
948 HDC hDC
= pGraphics
->getHDC();
951 pGraphics
->setHDC(nullptr);
952 SendMessageW( pSalData
->mpInstance
->mhComWnd
, SAL_MSG_RELEASEDC
,
953 reinterpret_cast<WPARAM
>(mhWnd
), reinterpret_cast<LPARAM
>(hDC
) );
954 if ( pGraphics
== mpThreadGraphics
)
955 pSalData
->mnCacheDCInUse
--;
959 WinSalFrame::~WinSalFrame()
961 SalData
* pSalData
= GetSalData();
964 delete [] reinterpret_cast<BYTE
*>(mpClipRgnData
);
966 // remove frame from framelist
967 WinSalFrame
** ppFrame
= &pSalData
->mpFirstFrame
;
968 for(; (*ppFrame
!= this) && *ppFrame
; ppFrame
= &(*ppFrame
)->mpNextFrame
);
970 *ppFrame
= mpNextFrame
;
971 mpNextFrame
= nullptr;
973 // destroy the thread SalGraphics
974 if ( mpThreadGraphics
)
976 ReleaseFrameGraphicsDC( mpThreadGraphics
);
977 delete mpThreadGraphics
;
978 mpThreadGraphics
= nullptr;
981 // destroy the local SalGraphics
982 if ( mpLocalGraphics
)
984 ReleaseFrameGraphicsDC( mpLocalGraphics
);
985 delete mpLocalGraphics
;
986 mpLocalGraphics
= nullptr;
991 // reset mouse leave data
992 if ( pSalData
->mhWantLeaveMsg
== mhWnd
)
994 pSalData
->mhWantLeaveMsg
= nullptr;
997 // remove windows properties
998 if ( mbPropertiesStored
)
999 SetApplicationID( OUString() );
1001 // destroy system frame
1002 if ( !DestroyWindow( mhWnd
) )
1003 SetWindowPtr( mhWnd
, nullptr );
1009 bool WinSalFrame::InitFrameGraphicsDC( WinSalGraphics
*pGraphics
, HDC hDC
, HWND hWnd
)
1011 SalData
* pSalData
= GetSalData();
1012 assert( pGraphics
);
1013 pGraphics
->setHWND( hWnd
);
1015 HDC hCurrentDC
= pGraphics
->getHDC();
1016 assert( !hCurrentDC
|| (hCurrentDC
== hDC
) );
1019 pGraphics
->setHDC( hDC
);
1024 if ( pSalData
->mhDitherPal
)
1025 pGraphics
->setPalette(pSalData
->mhDitherPal
);
1027 if ( pGraphics
== mpThreadGraphics
)
1028 pSalData
->mnCacheDCInUse
++;
1032 SalGraphics
* WinSalFrame::AcquireGraphics()
1034 if ( mbGraphics
|| !mhWnd
)
1037 SalData
* pSalData
= GetSalData();
1038 WinSalGraphics
*pGraphics
= nullptr;
1041 // Other threads get an own DC, because Windows modify in the
1042 // other case our DC (changing clip region), when they send a
1043 // WM_ERASEBACKGROUND message
1044 if ( !pSalData
->mpInstance
->IsMainThread() )
1046 // We use only three CacheDC's for all threads, because W9x is limited
1047 // to max. 5 Cache DC's per thread
1048 if ( pSalData
->mnCacheDCInUse
>= 3 )
1051 if ( !mpThreadGraphics
)
1052 mpThreadGraphics
= new WinSalGraphics(WinSalGraphics::WINDOW
, true, mhWnd
, this);
1053 pGraphics
= mpThreadGraphics
;
1054 assert( !pGraphics
->getHDC() );
1055 hDC
= reinterpret_cast<HDC
>(static_cast<sal_IntPtr
>(SendMessageW( pSalData
->mpInstance
->mhComWnd
,
1056 SAL_MSG_GETCACHEDDC
, reinterpret_cast<WPARAM
>(mhWnd
), 0 )));
1060 if ( !mpLocalGraphics
)
1061 mpLocalGraphics
= new WinSalGraphics(WinSalGraphics::WINDOW
, true, mhWnd
, this);
1062 pGraphics
= mpLocalGraphics
;
1063 hDC
= pGraphics
->getHDC();
1065 hDC
= GetDC( mhWnd
);
1068 mbGraphics
= InitFrameGraphicsDC( pGraphics
, hDC
, mhWnd
);
1069 return mbGraphics
? pGraphics
: nullptr;
1072 void WinSalFrame::ReleaseGraphics( SalGraphics
* pGraphics
)
1074 if ( mpThreadGraphics
== pGraphics
)
1075 ReleaseFrameGraphicsDC( mpThreadGraphics
);
1079 bool WinSalFrame::PostEvent(std::unique_ptr
<ImplSVEvent
> pData
)
1081 bool const ret
= PostMessageW(mhWnd
, SAL_MSG_USEREVENT
, 0, reinterpret_cast<LPARAM
>(pData
.get()));
1082 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
1088 void WinSalFrame::SetTitle( const OUString
& rTitle
)
1090 static_assert( sizeof( WCHAR
) == sizeof( sal_Unicode
), "must be the same size" );
1092 SetWindowTextW( mhWnd
, o3tl::toW(rTitle
.getStr()) );
1095 void WinSalFrame::SetIcon( sal_uInt16 nIcon
)
1097 // If we have a window without an Icon (for example a dialog), ignore this call
1101 // 0 means default (class) icon
1102 HICON hIcon
= nullptr, hSmIcon
= nullptr;
1106 ImplLoadSalIcon( nIcon
, hIcon
, hSmIcon
);
1108 SAL_WARN_IF( !hIcon
, "vcl", "WinSalFrame::SetIcon(): Could not load large icon !" );
1109 SAL_WARN_IF( !hSmIcon
, "vcl", "WinSalFrame::SetIcon(): Could not load small icon !" );
1111 SendMessageW( mhWnd
, WM_SETICON
, ICON_BIG
, reinterpret_cast<LPARAM
>(hIcon
) );
1112 SendMessageW( mhWnd
, WM_SETICON
, ICON_SMALL
, reinterpret_cast<LPARAM
>(hSmIcon
) );
1115 void WinSalFrame::SetMenu( SalMenu
* pSalMenu
)
1117 WinSalMenu
* pWMenu
= static_cast<WinSalMenu
*>(pSalMenu
);
1118 if( pSalMenu
&& pWMenu
->mbMenuBar
)
1119 ::SetMenu( mhWnd
, pWMenu
->mhMenu
);
1122 static HWND
ImplGetParentHwnd( HWND hWnd
)
1124 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
1125 if( !pFrame
|| !pFrame
->GetWindow())
1126 return ::GetParent( hWnd
);
1127 vcl::Window
*pRealParent
= pFrame
->GetWindow()->ImplGetWindowImpl()->mpRealParent
;
1129 return static_cast<WinSalFrame
*>(pRealParent
->ImplGetWindowImpl()->mpFrame
)->mhWnd
;
1131 return ::GetParent( hWnd
);
1135 SalFrame
* WinSalFrame::GetParent() const
1137 return GetWindowPtr( ImplGetParentHwnd( mhWnd
) );
1140 static void ImplSalShow( HWND hWnd
, bool bVisible
, bool bNoActivate
)
1142 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
1148 pFrame
->mbDefPos
= false;
1149 pFrame
->mbOverwriteState
= true;
1150 pFrame
->mbInShow
= true;
1152 // #i4715, save position
1153 RECT aRectPreMatrox
, aRectPostMatrox
;
1154 GetWindowRect( hWnd
, &aRectPreMatrox
);
1156 vcl::DeletionListener
aDogTag( pFrame
);
1158 ShowWindow( hWnd
, SW_SHOWNOACTIVATE
);
1160 ShowWindow( hWnd
, pFrame
->mnShowState
);
1161 if( aDogTag
.isDeleted() )
1164 if (pFrame
->mbFloatWin
&& !(pFrame
->mnStyle
& SalFrameStyleFlags::NOSHADOW
))
1166 // erase the window immediately to improve XP shadow effect
1167 // otherwise the shadow may appears long time before the rest of the window
1168 // especially when accessibility is on
1169 HDC dc
= GetDC( hWnd
);
1171 GetClientRect( hWnd
, &aRect
);
1172 FillRect( dc
, &aRect
, reinterpret_cast<HBRUSH
>(COLOR_MENU
+1) ); // choose the menucolor, because its mostly noticeable for menus
1173 ReleaseDC( hWnd
, dc
);
1176 // #i4715, matrox centerpopup might have changed our position
1177 // reposition popups without caption (menus, dropdowns, tooltips)
1178 GetWindowRect( hWnd
, &aRectPostMatrox
);
1179 if( (GetWindowStyle( hWnd
) & WS_POPUP
) &&
1180 !pFrame
->mbCaption
&&
1181 (aRectPreMatrox
.left
!= aRectPostMatrox
.left
|| aRectPreMatrox
.top
!= aRectPostMatrox
.top
) )
1182 SetWindowPos( hWnd
, nullptr, aRectPreMatrox
.left
, aRectPreMatrox
.top
, 0, 0, SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
);
1184 if( aDogTag
.isDeleted() )
1186 vcl::Window
*pClientWin
= pFrame
->GetWindow()->ImplGetClientWindow();
1187 if ( pFrame
->mbFloatWin
|| ( pClientWin
&& (pClientWin
->GetStyle() & WB_SYSTEMFLOATWIN
) ) )
1188 pFrame
->mnShowState
= SW_SHOWNOACTIVATE
;
1190 pFrame
->mnShowState
= SW_SHOW
;
1191 // hide toolbar for W98
1192 if ( pFrame
->mbPresentation
)
1194 HWND hWndParent
= ::GetParent( hWnd
);
1196 SetForegroundWindow_Impl( hWndParent
);
1197 SetForegroundWindow_Impl( hWnd
);
1200 pFrame
->mbInShow
= false;
1201 pFrame
->updateScreenNumber();
1203 // Direct Paint only, if we get the SolarMutex
1204 if ( ImplSalYieldMutexTryToAcquire() )
1206 UpdateWindow( hWnd
);
1207 ImplSalYieldMutexRelease();
1212 ShowWindow( hWnd
, SW_HIDE
);
1216 void WinSalFrame::SetExtendedFrameStyle( SalExtStyle
)
1220 void WinSalFrame::Show( bool bVisible
, bool bNoActivate
)
1222 // Post this Message to the window, because this only works
1223 // in the thread of the window, which has create this window.
1224 // We post this message to avoid deadlocks
1225 if ( GetSalData()->mnAppThreadId
!= GetCurrentThreadId() )
1227 bool const ret
= PostMessageW(mhWnd
, SAL_MSG_SHOW
, WPARAM(bVisible
), LPARAM(bNoActivate
));
1228 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
1231 ImplSalShow( mhWnd
, bVisible
, bNoActivate
);
1234 void WinSalFrame::SetMinClientSize( tools::Long nWidth
, tools::Long nHeight
)
1236 mnMinWidth
= nWidth
;
1237 mnMinHeight
= nHeight
;
1240 void WinSalFrame::SetMaxClientSize( tools::Long nWidth
, tools::Long nHeight
)
1242 mnMaxWidth
= nWidth
;
1243 mnMaxHeight
= nHeight
;
1246 void WinSalFrame::SetPosSize( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
,
1249 bool bVisible
= (GetWindowStyle( mhWnd
) & WS_VISIBLE
) != 0;
1252 vcl::Window
*pClientWin
= GetWindow()->ImplGetClientWindow();
1253 if ( mbFloatWin
|| ( pClientWin
&& (pClientWin
->GetStyle() & WB_SYSTEMFLOATWIN
) ) )
1254 mnShowState
= SW_SHOWNOACTIVATE
;
1256 mnShowState
= SW_SHOWNORMAL
;
1260 if ( IsIconic( mhWnd
) || IsZoomed( mhWnd
) )
1261 ShowWindow( mhWnd
, SW_RESTORE
);
1264 SalEvent nEvent
= SalEvent::NONE
;
1266 RECT aClientRect
, aWindowRect
;
1267 GetClientRect( mhWnd
, &aClientRect
); // x,y always 0,0, but width and height without border
1268 GetWindowRect( mhWnd
, &aWindowRect
); // x,y in screen coordinates, width and height with border
1270 if ( !(nFlags
& (SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
)) )
1271 nPosSize
|= SWP_NOMOVE
;
1274 //SAL_WARN_IF( !nX || !nY, "vcl", " Windowposition of (0,0) requested!" );
1275 nEvent
= SalEvent::Move
;
1277 if ( !(nFlags
& (SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
)) )
1278 nPosSize
|= SWP_NOSIZE
;
1280 nEvent
= (nEvent
== SalEvent::Move
) ? SalEvent::MoveResize
: SalEvent::Resize
;
1282 if ( !(nFlags
& SAL_FRAME_POSSIZE_X
) )
1283 nX
= aWindowRect
.left
;
1284 if ( !(nFlags
& SAL_FRAME_POSSIZE_Y
) )
1285 nY
= aWindowRect
.top
;
1286 if ( !(nFlags
& SAL_FRAME_POSSIZE_WIDTH
) )
1287 nWidth
= aClientRect
.right
-aClientRect
.left
;
1288 if ( !(nFlags
& SAL_FRAME_POSSIZE_HEIGHT
) )
1289 nHeight
= aClientRect
.bottom
-aClientRect
.top
;
1291 // Calculate window size including the border
1294 aWinRect
.right
= static_cast<int>(nWidth
)-1;
1296 aWinRect
.bottom
= static_cast<int>(nHeight
)-1;
1297 AdjustWindowRectEx( &aWinRect
, GetWindowStyle( mhWnd
),
1298 FALSE
, GetWindowExStyle( mhWnd
) );
1299 nWidth
= aWinRect
.right
- aWinRect
.left
+ 1;
1300 nHeight
= aWinRect
.bottom
- aWinRect
.top
+ 1;
1302 HWND hWndParent
= ImplGetParentHwnd(mhWnd
);
1303 // For dialogs (WS_POPUP && WS_DLGFRAME), we need to find the "real" parent,
1304 // in case multiple dialogs are stacked on each other
1305 // (we don't want to position the second dialog relative to the first one, but relative to the main window)
1306 if ( (GetWindowStyle( mhWnd
) & WS_POPUP
) && (GetWindowStyle( mhWnd
) & WS_DLGFRAME
) ) // mhWnd is a dialog
1308 while ( hWndParent
&& (GetWindowStyle( hWndParent
) & WS_POPUP
) && (GetWindowStyle( hWndParent
) & WS_DLGFRAME
) )
1310 hWndParent
= ::ImplGetParentHwnd( hWndParent
);
1314 if ( !(nPosSize
& SWP_NOMOVE
) && hWndParent
)
1317 GetClientRect( hWndParent
, &aParentRect
);
1318 if( AllSettings::GetLayoutRTL() )
1319 nX
= (aParentRect
.right
- aParentRect
.left
) - nWidth
-1 - nX
;
1321 //#110386#, do not transform coordinates for system child windows
1322 if( !(GetWindowStyle( mhWnd
) & WS_CHILD
) )
1328 WinSalFrame
* pParentFrame
= GetWindowPtr( hWndParent
);
1329 if ( pParentFrame
&& pParentFrame
->mnShowState
== SW_SHOWMAXIMIZED
)
1331 // #i42485#: parent will be shown maximized in which case
1332 // a ClientToScreen uses the wrong coordinates (i.e. those from the restore pos)
1333 // so use the (already updated) frame geometry for the transformation
1334 aPt
.x
+= pParentFrame
->maGeometry
.x();
1335 aPt
.y
+= pParentFrame
->maGeometry
.y();
1338 ClientToScreen( hWndParent
, &aPt
);
1343 // the position is set
1348 // #i3338# to be conformant to UNIX we must position the client window, ie without the decoration
1349 // #i43250# if the position was read from the system (GetWindowRect(), see above), it must not be modified
1350 if ( nFlags
& SAL_FRAME_POSSIZE_X
)
1351 nX
+= aWinRect
.left
;
1352 if ( nFlags
& SAL_FRAME_POSSIZE_Y
)
1361 ImplSalGetWorkArea( mhWnd
, &aRect
, nullptr );
1362 nScreenX
= aRect
.left
;
1363 nScreenY
= aRect
.top
;
1364 nScreenWidth
= aRect
.right
-aRect
.left
;
1365 nScreenHeight
= aRect
.bottom
-aRect
.top
;
1367 if ( mbDefPos
&& (nPosSize
& SWP_NOMOVE
)) // we got no positioning request, so choose default position
1371 HWND hWndParent2
= ::GetParent( mhWnd
);
1372 // Search for TopLevel Frame
1373 while ( hWndParent2
&& (GetWindowStyle( hWndParent2
) & WS_CHILD
) )
1374 hWndParent2
= ::GetParent( hWndParent2
);
1375 // if the Window has a Parent, then center the window to
1376 // the parent, in the other case to the screen
1377 if ( hWndParent2
&& !IsIconic( hWndParent2
) &&
1378 (GetWindowStyle( hWndParent2
) & WS_VISIBLE
) )
1381 GetWindowRect( hWndParent2
, &aParentRect
);
1382 int nParentWidth
= aParentRect
.right
-aParentRect
.left
;
1383 int nParentHeight
= aParentRect
.bottom
-aParentRect
.top
;
1385 // We don't center, when Parent is smaller than our window
1386 if ( (nParentWidth
-GetSystemMetrics( SM_CXFIXEDFRAME
) <= nWidth
) &&
1387 (nParentHeight
-GetSystemMetrics( SM_CYFIXEDFRAME
) <= nHeight
) )
1389 int nOff
= GetSystemMetrics( SM_CYSIZEFRAME
) + GetSystemMetrics( SM_CYCAPTION
);
1390 nX
= aParentRect
.left
+nOff
;
1391 nY
= aParentRect
.top
+nOff
;
1395 nX
= (nParentWidth
-nWidth
)/2 + aParentRect
.left
;
1396 nY
= (nParentHeight
-nHeight
)/2 + aParentRect
.top
;
1402 GetCursorPos( &pt
);
1406 aRect2
.right
= pt
.x
+2;
1407 aRect2
.bottom
= pt
.y
+2;
1409 // dualmonitor support:
1410 // Get screensize of the monitor with the mouse pointer
1411 ImplSalGetWorkArea( mhWnd
, &aRect2
, &aRect2
);
1413 nX
= ((aRect2
.right
-aRect2
.left
)-nWidth
)/2 + aRect2
.left
;
1414 nY
= ((aRect2
.bottom
-aRect2
.top
)-nHeight
)/2 + aRect2
.top
;
1418 // mbDefPos = FALSE;
1420 mbDefPos
= false; // center only once
1421 nPosSize
&= ~SWP_NOMOVE
; // activate positioning
1422 nEvent
= SalEvent::MoveResize
;
1425 // Adjust Window in the screen
1426 bool bCheckOffScreen
= true;
1428 // but don't do this for floaters or ownerdraw windows that are currently moved interactively
1429 if( (mnStyle
& SalFrameStyleFlags::FLOAT
) && !(mnStyle
& SalFrameStyleFlags::OWNERDRAWDECORATION
) )
1430 bCheckOffScreen
= false;
1432 if( mnStyle
& SalFrameStyleFlags::OWNERDRAWDECORATION
)
1434 // may be the window is currently being moved (mouse is captured), then no check is required
1435 if( mhWnd
== ::GetCapture() )
1436 bCheckOffScreen
= false;
1438 bCheckOffScreen
= true;
1441 if( bCheckOffScreen
)
1443 if ( nX
+nWidth
> nScreenX
+nScreenWidth
)
1444 nX
= (nScreenX
+nScreenWidth
) - nWidth
;
1445 if ( nY
+nHeight
> nScreenY
+nScreenHeight
)
1446 nY
= (nScreenY
+nScreenHeight
) - nHeight
;
1447 if ( nX
< nScreenX
)
1449 if ( nY
< nScreenY
)
1453 UINT nPosFlags
= SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| nPosSize
;
1454 // bring floating windows always to top
1455 if( !(mnStyle
& SalFrameStyleFlags::FLOAT
) )
1456 nPosFlags
|= SWP_NOZORDER
; // do not change z-order
1458 SetWindowPos( mhWnd
, HWND_TOP
, nX
, nY
, static_cast<int>(nWidth
), static_cast<int>(nHeight
), nPosFlags
);
1460 UpdateFrameGeometry(this);
1462 // Notification -- really ???
1463 if( nEvent
!= SalEvent::NONE
)
1464 CallCallback( nEvent
, nullptr );
1467 void WinSalFrame::ImplSetParentFrame( HWND hNewParentWnd
, bool bAsChild
)
1469 // save hwnd, will be overwritten in WM_CREATE during createwindow
1470 HWND hWndOld
= mhWnd
;
1471 HWND hWndOldParent
= ::GetParent( hWndOld
);
1472 SalData
* pSalData
= GetSalData();
1474 if( hNewParentWnd
== hWndOldParent
)
1477 ::std::vector
< WinSalFrame
* > children
;
1478 ::std::vector
< WinSalObject
* > systemChildren
;
1480 // search child windows
1481 WinSalFrame
*pFrame
= pSalData
->mpFirstFrame
;
1484 HWND hWndParent
= ::GetParent( pFrame
->mhWnd
);
1485 if( mhWnd
== hWndParent
)
1486 children
.push_back( pFrame
);
1487 pFrame
= pFrame
->mpNextFrame
;
1490 // search system child windows (plugins etc.)
1491 WinSalObject
*pObject
= pSalData
->mpFirstObject
;
1494 HWND hWndParent
= ::GetParent( pObject
->mhWnd
);
1495 if( mhWnd
== hWndParent
)
1496 systemChildren
.push_back( pObject
);
1497 pObject
= pObject
->mpNextObject
;
1500 // to recreate the DCs, if they were destroyed
1501 bool bHadLocalGraphics
= false, bHadThreadGraphics
= false;
1503 HFONT hFont
= nullptr;
1504 HPEN hPen
= nullptr;
1505 HBRUSH hBrush
= nullptr;
1507 int oldCount
= pSalData
->mnCacheDCInUse
;
1509 // release the thread DC
1510 if ( mpThreadGraphics
)
1512 // save current gdi objects before hdc is gone
1513 HDC hDC
= mpThreadGraphics
->getHDC();
1516 hFont
= static_cast<HFONT
>(GetCurrentObject( hDC
, OBJ_FONT
));
1517 hPen
= static_cast<HPEN
>(GetCurrentObject( hDC
, OBJ_PEN
));
1518 hBrush
= static_cast<HBRUSH
>(GetCurrentObject( hDC
, OBJ_BRUSH
));
1521 bHadThreadGraphics
= ReleaseFrameGraphicsDC( mpThreadGraphics
);
1522 assert( (bHadThreadGraphics
&& hDC
) || (!bHadThreadGraphics
&& !hDC
) );
1525 // release the local DC
1526 if ( mpLocalGraphics
)
1527 bHadLocalGraphics
= ReleaseFrameGraphicsDC( mpLocalGraphics
);
1529 // create a new hwnd with the same styles
1530 HWND hWndParent
= hNewParentWnd
;
1531 // forward to main thread
1532 HWND hWnd
= reinterpret_cast<HWND
>(static_cast<sal_IntPtr
>(SendMessageW( pSalData
->mpInstance
->mhComWnd
,
1533 bAsChild
? SAL_MSG_RECREATECHILDHWND
: SAL_MSG_RECREATEHWND
,
1534 reinterpret_cast<WPARAM
>(hWndParent
), reinterpret_cast<LPARAM
>(mhWnd
) )));
1537 SAL_WARN_IF( !IsWindow( hWnd
), "vcl", "WinSalFrame::SetParent not successful");
1539 // re-create thread DC
1540 if( bHadThreadGraphics
)
1542 HDC hDC
= reinterpret_cast<HDC
>(static_cast<sal_IntPtr
>(
1543 SendMessageW( pSalData
->mpInstance
->mhComWnd
,
1544 SAL_MSG_GETCACHEDDC
, reinterpret_cast<WPARAM
>(hWnd
), 0 )));
1545 InitFrameGraphicsDC( mpThreadGraphics
, hDC
, hWnd
);
1548 // re-select saved gdi objects
1550 SelectObject( hDC
, hFont
);
1552 SelectObject( hDC
, hPen
);
1554 SelectObject( hDC
, hBrush
);
1556 SAL_WARN_IF( oldCount
!= pSalData
->mnCacheDCInUse
, "vcl", "WinSalFrame::SetParent() hDC count corrupted");
1560 // re-create local DC
1561 if( bHadLocalGraphics
)
1562 InitFrameGraphicsDC( mpLocalGraphics
, GetDC( hWnd
), hWnd
);
1564 // TODO: add SetParent() call for SalObjects
1565 SAL_WARN_IF( !systemChildren
.empty(), "vcl", "WinSalFrame::SetParent() parent of living system child window will be destroyed!");
1567 // reparent children before old parent is destroyed
1568 for (auto & child
: children
)
1569 child
->ImplSetParentFrame( hWnd
, false );
1572 systemChildren
.clear();
1574 // Now destroy original HWND in the thread where it was created.
1575 SendMessageW( GetSalData()->mpInstance
->mhComWnd
,
1576 SAL_MSG_DESTROYHWND
, WPARAM(0), reinterpret_cast<LPARAM
>(hWndOld
));
1579 void WinSalFrame::SetParent( SalFrame
* pNewParent
)
1581 WinSalFrame::mbInReparent
= true;
1582 ImplSetParentFrame( static_cast<WinSalFrame
*>(pNewParent
)->mhWnd
, false );
1583 WinSalFrame::mbInReparent
= false;
1586 void WinSalFrame::SetPluginParent( SystemParentData
* pNewParent
)
1588 if ( pNewParent
->hWnd
== nullptr )
1590 pNewParent
->hWnd
= GetDesktopWindow();
1593 WinSalFrame::mbInReparent
= true;
1594 ImplSetParentFrame( pNewParent
->hWnd
, true );
1595 WinSalFrame::mbInReparent
= false;
1598 void WinSalFrame::GetWorkArea( AbsoluteScreenPixelRectangle
&rRect
)
1602 // pass cursor's position to ImplSalGetWorkArea to determine work area on
1603 // multi monitor setups correctly.
1605 GetCursorPos(&aPoint
);
1606 RECT aRect2
{ aPoint
.x
, aPoint
.y
, aPoint
.x
+ 2, aPoint
.y
+ 2 };
1608 ImplSalGetWorkArea( mhWnd
, &aRect
, &aRect2
);
1609 rRect
.SetLeft( aRect
.left
);
1610 rRect
.SetRight( aRect
.right
-1 );
1611 rRect
.SetTop( aRect
.top
);
1612 rRect
.SetBottom( aRect
.bottom
-1 );
1615 void WinSalFrame::GetClientSize( tools::Long
& rWidth
, tools::Long
& rHeight
)
1617 rWidth
= maGeometry
.width();
1618 rHeight
= maGeometry
.height();
1621 void WinSalFrame::SetWindowState(const vcl::WindowData
* pState
)
1623 // Check if the window fits into the screen, in case the screen
1624 // resolution changed
1635 ImplSalGetWorkArea( mhWnd
, &aRect
, nullptr );
1636 // #102500# allow some overlap, the window could have been made a little larger than the physical screen
1637 nScreenX
= aRect
.left
-10;
1638 nScreenY
= aRect
.top
-10;
1639 nScreenWidth
= aRect
.right
-aRect
.left
+20;
1640 nScreenHeight
= aRect
.bottom
-aRect
.top
+20;
1644 GetWindowRect( mhWnd
, &aWinRect
);
1646 // to be consistent with Unix, the frame state is without(!) decoration
1647 // ->add the decoration
1648 RECT aRect2
= aWinRect
;
1649 AdjustWindowRectEx( &aRect2
, GetWindowStyle( mhWnd
),
1650 FALSE
, GetWindowExStyle( mhWnd
) );
1651 tools::Long nTopDeco
= abs( aWinRect
.top
- aRect2
.top
);
1652 tools::Long nLeftDeco
= abs( aWinRect
.left
- aRect2
.left
);
1653 tools::Long nBottomDeco
= abs( aWinRect
.bottom
- aRect2
.bottom
);
1654 tools::Long nRightDeco
= abs( aWinRect
.right
- aRect2
.right
);
1656 // adjust window position/size to fit the screen
1657 if ( !(pState
->mask() & vcl::WindowDataMask::Pos
) )
1658 nPosSize
|= SWP_NOMOVE
;
1659 if ( !(pState
->mask() & vcl::WindowDataMask::Size
) )
1660 nPosSize
|= SWP_NOSIZE
;
1661 if ( pState
->mask() & vcl::WindowDataMask::X
)
1662 nX
= static_cast<int>(pState
->x()) - nLeftDeco
;
1665 if ( pState
->mask() & vcl::WindowDataMask::Y
)
1666 nY
= static_cast<int>(pState
->y()) - nTopDeco
;
1669 if ( pState
->mask() & vcl::WindowDataMask::Width
)
1670 nWidth
= static_cast<int>(pState
->width()) + nLeftDeco
+ nRightDeco
;
1672 nWidth
= aWinRect
.right
-aWinRect
.left
;
1673 if ( pState
->mask() & vcl::WindowDataMask::Height
)
1674 nHeight
= static_cast<int>(pState
->height()) + nTopDeco
+ nBottomDeco
;
1676 nHeight
= aWinRect
.bottom
-aWinRect
.top
;
1678 // Adjust Window in the screen:
1679 // if it does not fit into the screen do nothing, ie default pos/size will be used
1680 // if there is an overlap with the screen border move the window while keeping its size
1682 if( nWidth
> nScreenWidth
|| nHeight
> nScreenHeight
)
1683 nPosSize
|= (SWP_NOMOVE
| SWP_NOSIZE
);
1685 if ( nX
+nWidth
> nScreenX
+nScreenWidth
)
1686 nX
= (nScreenX
+nScreenWidth
) - nWidth
;
1687 if ( nY
+nHeight
> nScreenY
+nScreenHeight
)
1688 nY
= (nScreenY
+nScreenHeight
) - nHeight
;
1689 if ( nX
< nScreenX
)
1691 if ( nY
< nScreenY
)
1694 // set Restore-Position
1695 WINDOWPLACEMENT aPlacement
;
1696 aPlacement
.length
= sizeof( aPlacement
);
1697 GetWindowPlacement( mhWnd
, &aPlacement
);
1700 const bool bIsMinimized
= IsIconic(mhWnd
);
1701 const bool bIsMaximized
= IsZoomed(mhWnd
);
1702 const bool bVisible
= (GetWindowStyle(mhWnd
) & WS_VISIBLE
);
1703 bool bUpdateHiddenFramePos
= false;
1706 aPlacement
.showCmd
= SW_HIDE
;
1708 if (mbOverwriteState
&& (pState
->mask() & vcl::WindowDataMask::State
))
1710 if (pState
->state() & vcl::WindowState::Minimized
)
1711 mnShowState
= SW_SHOWMINIMIZED
;
1712 else if (pState
->state() & vcl::WindowState::Maximized
)
1714 mnShowState
= SW_SHOWMAXIMIZED
;
1715 bUpdateHiddenFramePos
= true;
1717 else if (pState
->state() & vcl::WindowState::Normal
)
1718 mnShowState
= SW_SHOWNORMAL
;
1723 if ( pState
->mask() & vcl::WindowDataMask::State
)
1725 if ( pState
->state() & vcl::WindowState::Minimized
)
1727 if ( pState
->state() & vcl::WindowState::Maximized
)
1728 aPlacement
.flags
|= WPF_RESTORETOMAXIMIZED
;
1729 aPlacement
.showCmd
= SW_SHOWMINIMIZED
;
1731 else if ( pState
->state() & vcl::WindowState::Maximized
)
1732 aPlacement
.showCmd
= SW_SHOWMAXIMIZED
;
1733 else if ( pState
->state() & vcl::WindowState::Normal
)
1734 aPlacement
.showCmd
= SW_RESTORE
;
1738 // if a window is neither minimized nor maximized or need not be
1739 // positioned visibly (that is in visible state), do not use
1740 // SetWindowPlacement since it calculates including the TaskBar
1741 if (!bIsMinimized
&& !bIsMaximized
&& (!bVisible
|| (aPlacement
.showCmd
== SW_RESTORE
)))
1743 if( bUpdateHiddenFramePos
)
1746 aStateRect
.left
= nX
;
1747 aStateRect
.top
= nY
;
1748 aStateRect
.right
= nX
+nWidth
;
1749 aStateRect
.bottom
= nY
+nHeight
;
1750 // #96084 set a useful internal window size because
1751 // the window will not be maximized (and the size updated) before show()
1752 SetMaximizedFrameGeometry( mhWnd
, this, &aStateRect
);
1753 SetWindowPos( mhWnd
, nullptr,
1754 maGeometry
.x(), maGeometry
.y(), maGeometry
.width(), maGeometry
.height(),
1755 SWP_NOZORDER
| SWP_NOACTIVATE
| nPosSize
);
1758 SetWindowPos( mhWnd
, nullptr,
1759 nX
, nY
, nWidth
, nHeight
,
1760 SWP_NOZORDER
| SWP_NOACTIVATE
| nPosSize
);
1764 if( !(nPosSize
& (SWP_NOMOVE
|SWP_NOSIZE
)) )
1766 aPlacement
.rcNormalPosition
.left
= nX
-nScreenX
;
1767 aPlacement
.rcNormalPosition
.top
= nY
-nScreenY
;
1768 aPlacement
.rcNormalPosition
.right
= nX
+nWidth
-nScreenX
;
1769 aPlacement
.rcNormalPosition
.bottom
= nY
+nHeight
-nScreenY
;
1771 SetWindowPlacement( mhWnd
, &aPlacement
);
1774 if( !(nPosSize
& SWP_NOMOVE
) )
1775 mbDefPos
= false; // window was positioned
1778 bool WinSalFrame::GetWindowState(vcl::WindowData
* pState
)
1780 pState
->setPosSize(maGeometry
.posSize());
1781 pState
->setState(m_eState
);
1782 pState
->setMask(vcl::WindowDataMask::PosSizeState
);
1786 void WinSalFrame::SetScreenNumber( unsigned int nNewScreen
)
1788 WinSalSystem
* pSys
= static_cast<WinSalSystem
*>(ImplGetSalSystem());
1791 const std::vector
<WinSalSystem::DisplayMonitor
>& rMonitors
=
1792 pSys
->getMonitors();
1793 size_t nMon
= rMonitors
.size();
1794 if( nNewScreen
< nMon
)
1796 AbsoluteScreenPixelPoint aOldMonPos
, aNewMonPos( rMonitors
[nNewScreen
].m_aArea
.TopLeft() );
1797 AbsoluteScreenPixelPoint
aCurPos(maGeometry
.pos());
1798 for( size_t i
= 0; i
< nMon
; i
++ )
1800 if( rMonitors
[i
].m_aArea
.Contains( aCurPos
) )
1802 aOldMonPos
= rMonitors
[i
].m_aArea
.TopLeft();
1806 mnDisplay
= nNewScreen
;
1807 maGeometry
.setScreen(nNewScreen
);
1808 SetPosSize( aNewMonPos
.X() + (maGeometry
.x() - aOldMonPos
.X()),
1809 aNewMonPos
.Y() + (maGeometry
.y() - aOldMonPos
.Y()),
1811 SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
);
1816 void WinSalFrame::SetApplicationID( const OUString
&rApplicationID
)
1818 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd378430(v=vs.85).aspx
1819 // A window's properties must be removed before the window is closed.
1821 IPropertyStore
*pps
;
1822 HRESULT hr
= SHGetPropertyStoreForWindow(mhWnd
, IID_PPV_ARGS(&pps
));
1826 if (!rApplicationID
.isEmpty())
1828 hr
= InitPropVariantFromString(o3tl::toW(rApplicationID
.getStr()), &pv
);
1829 mbPropertiesStored
= true;
1832 // if rApplicationID we remove the property from the window, if present
1833 PropVariantInit(&pv
);
1837 hr
= pps
->SetValue(PKEY_AppUserModel_ID
, pv
);
1838 PropVariantClear(&pv
);
1844 void WinSalFrame::ShowFullScreen(const bool bFullScreen
, const sal_Int32 nDisplay
)
1846 if ((isFullScreen() == bFullScreen
) && (!bFullScreen
|| (mnDisplay
== nDisplay
)))
1849 mnDisplay
= nDisplay
;
1853 m_eState
|= vcl::WindowState::FullScreen
;
1854 // to hide the Windows taskbar
1855 DWORD nExStyle
= GetWindowExStyle( mhWnd
);
1856 if ( nExStyle
& WS_EX_TOOLWINDOW
)
1858 mbFullScreenToolWin
= true;
1859 nExStyle
&= ~WS_EX_TOOLWINDOW
;
1860 SetWindowExStyle( mhWnd
, nExStyle
);
1862 // save old position
1863 GetWindowRect( mhWnd
, &maFullScreenRect
);
1866 mnFullScreenShowState
= mnShowState
;
1867 if ( !(GetWindowStyle( mhWnd
) & WS_VISIBLE
) )
1868 mnShowState
= SW_SHOW
;
1870 // Save caption state.
1871 mbFullScreenCaption
= mbCaption
;
1874 DWORD nStyle
= GetWindowStyle(mhWnd
);
1875 SetWindowStyle(mhWnd
, nStyle
& ~WS_CAPTION
);
1879 // set window to screen size
1880 ImplSalFrameFullScreenPos( this, true );
1884 m_eState
&= ~vcl::WindowState::FullScreen
;
1885 // when the ShowState has to be reset, hide the window first to
1887 bool bVisible
= (GetWindowStyle( mhWnd
) & WS_VISIBLE
) != 0;
1888 if ( bVisible
&& (mnShowState
!= mnFullScreenShowState
) )
1889 ShowWindow( mhWnd
, SW_HIDE
);
1891 if ( mbFullScreenToolWin
)
1892 SetWindowExStyle( mhWnd
, GetWindowExStyle( mhWnd
) | WS_EX_TOOLWINDOW
);
1893 mbFullScreenToolWin
= false;
1895 // Restore caption state.
1896 if (mbFullScreenCaption
)
1898 DWORD nStyle
= GetWindowStyle(mhWnd
);
1899 SetWindowStyle(mhWnd
, nStyle
| WS_CAPTION
);
1901 mbCaption
= mbFullScreenCaption
;
1903 SetWindowPos( mhWnd
, nullptr,
1904 maFullScreenRect
.left
,
1905 maFullScreenRect
.top
,
1906 maFullScreenRect
.right
-maFullScreenRect
.left
,
1907 maFullScreenRect
.bottom
-maFullScreenRect
.top
,
1908 SWP_NOZORDER
| SWP_NOACTIVATE
);
1910 // restore show state
1911 if ( mnShowState
!= mnFullScreenShowState
)
1913 mnShowState
= mnFullScreenShowState
;
1917 ShowWindow( mhWnd
, mnShowState
);
1919 UpdateWindow( mhWnd
);
1925 void WinSalFrame::StartPresentation( bool bStart
)
1927 if ( mbPresentation
== bStart
)
1930 mbPresentation
= bStart
;
1934 // turn off screen-saver / power saving when in Presentation mode
1935 SetThreadExecutionState(ES_CONTINUOUS
| ES_SYSTEM_REQUIRED
| ES_DISPLAY_REQUIRED
);
1939 // turn on screen-saver / power saving back
1940 SetThreadExecutionState(ES_CONTINUOUS
);
1944 void WinSalFrame::SetAlwaysOnTop( bool bOnTop
)
1948 hWnd
= HWND_TOPMOST
;
1950 hWnd
= HWND_NOTOPMOST
;
1951 SetWindowPos( mhWnd
, hWnd
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1954 static bool EnableAttachThreadInputHack()
1956 OUString aBootstrapUri
;
1957 if (osl_getProcessWorkingDir(&aBootstrapUri
.pData
) != osl_Process_E_None
)
1959 aBootstrapUri
+= "/bootstrap.ini";
1961 OUString aSystemFileName
;
1962 if (osl::FileBase::getSystemPathFromFileURL(aBootstrapUri
, aSystemFileName
) != osl::FileBase::E_None
)
1964 if (aSystemFileName
.getLength() > MAX_PATH
)
1967 // this uses the Boost ini parser, instead of tools::Config, as we already use it to read other
1968 // values from bootstrap.ini in desktop/win32/source/loader.cxx, because that watchdog process
1969 // can't access LO libs. This way the handling is consistent.
1972 boost::property_tree::ptree pt
;
1973 std::ifstream
aFile(o3tl::toW(aSystemFileName
.getStr()));
1974 boost::property_tree::ini_parser::read_ini(aFile
, pt
);
1975 const bool bEnabled
= pt
.get("Win32.EnableAttachThreadInputHack", false);
1976 SAL_WARN_IF(bEnabled
, "vcl", "AttachThreadInput hack is enabled. Watch out for deadlocks!");
1985 static void ImplSalToTop( HWND hWnd
, SalFrameToTop nFlags
)
1987 static const bool bEnableAttachThreadInputHack
= EnableAttachThreadInputHack();
1989 WinSalFrame
* pToTopFrame
= GetWindowPtr( hWnd
);
1990 if( pToTopFrame
&& (pToTopFrame
->mnStyle
& SalFrameStyleFlags::SYSTEMCHILD
) )
1991 BringWindowToTop( hWnd
);
1993 if ( nFlags
& SalFrameToTop::ForegroundTask
)
1995 // LO used to always call AttachThreadInput here, which resulted in deadlocks
1996 // in some installations for unknown reasons!
1997 if (bEnableAttachThreadInputHack
)
1999 // This magic code is necessary to connect the input focus of the
2000 // current window thread and the thread which owns the window that
2001 // should be the new foreground window.
2002 HWND hCurrWnd
= GetForegroundWindow();
2003 DWORD myThreadID
= GetCurrentThreadId();
2004 DWORD currThreadID
= GetWindowThreadProcessId(hCurrWnd
,nullptr);
2005 AttachThreadInput(myThreadID
, currThreadID
, TRUE
);
2006 SetForegroundWindow_Impl(hWnd
);
2007 AttachThreadInput(myThreadID
, currThreadID
, FALSE
);
2010 SetForegroundWindow_Impl(hWnd
);
2013 if ( nFlags
& SalFrameToTop::RestoreWhenMin
)
2015 HWND hIconicWnd
= hWnd
;
2016 while ( hIconicWnd
)
2018 if ( IsIconic( hIconicWnd
) )
2020 WinSalFrame
* pFrame
= GetWindowPtr( hIconicWnd
);
2023 if ( GetWindowPtr( hWnd
)->mbRestoreMaximize
)
2024 ShowWindow( hIconicWnd
, SW_MAXIMIZE
);
2026 ShowWindow( hIconicWnd
, SW_RESTORE
);
2029 ShowWindow( hIconicWnd
, SW_RESTORE
);
2032 hIconicWnd
= ::GetParent( hIconicWnd
);
2036 if ( !IsIconic( hWnd
) && IsWindowVisible( hWnd
) )
2040 // Windows sometimes incorrectly reports to have the focus;
2041 // thus make sure to really get the focus
2042 if ( ::GetFocus() == hWnd
)
2043 SetForegroundWindow_Impl( hWnd
);
2047 void WinSalFrame::ToTop( SalFrameToTop nFlags
)
2049 nFlags
&= ~SalFrameToTop::GrabFocus
; // this flag is not needed on win32
2050 // Post this Message to the window, because this only works
2051 // in the thread of the window, which has create this window.
2052 // We post this message to avoid deadlocks
2053 if ( GetSalData()->mnAppThreadId
!= GetCurrentThreadId() )
2055 bool const ret
= PostMessageW( mhWnd
, SAL_MSG_TOTOP
, static_cast<WPARAM
>(nFlags
), 0 );
2056 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
2059 ImplSalToTop( mhWnd
, nFlags
);
2062 void WinSalFrame::SetPointer( PointerStyle ePointerStyle
)
2071 static o3tl::enumarray
<PointerStyle
, ImplPtrData
> aImplPtrTab
=
2073 // [-loplugin:redundantfcast]:
2074 ImplPtrData
{ nullptr, IDC_ARROW
, 0 }, // POINTER_ARROW
2075 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_NULL
}, // POINTER_NULL
2076 ImplPtrData
{ nullptr, IDC_WAIT
, 0 }, // POINTER_WAIT
2077 ImplPtrData
{ nullptr, IDC_IBEAM
, 0 }, // POINTER_TEXT
2078 ImplPtrData
{ nullptr, IDC_HELP
, 0 }, // POINTER_HELP
2079 ImplPtrData
{ nullptr, IDC_CROSS
, 0 }, // POINTER_CROSS
2080 ImplPtrData
{ nullptr, IDC_SIZEALL
, 0 }, // POINTER_MOVE
2081 ImplPtrData
{ nullptr, IDC_SIZENS
, 0 }, // POINTER_NSIZE
2082 ImplPtrData
{ nullptr, IDC_SIZENS
, 0 }, // POINTER_SSIZE
2083 ImplPtrData
{ nullptr, IDC_SIZEWE
, 0 }, // POINTER_WSIZE
2084 ImplPtrData
{ nullptr, IDC_SIZEWE
, 0 }, // POINTER_ESIZE
2085 ImplPtrData
{ nullptr, IDC_SIZENWSE
, 0 }, // POINTER_NWSIZE
2086 ImplPtrData
{ nullptr, IDC_SIZENESW
, 0 }, // POINTER_NESIZE
2087 ImplPtrData
{ nullptr, IDC_SIZENESW
, 0 }, // POINTER_SWSIZE
2088 ImplPtrData
{ nullptr, IDC_SIZENWSE
, 0 }, // POINTER_SESIZE
2089 ImplPtrData
{ nullptr, IDC_SIZENS
, 0 }, // POINTER_WINDOW_NSIZE
2090 ImplPtrData
{ nullptr, IDC_SIZENS
, 0 }, // POINTER_WINDOW_SSIZE
2091 ImplPtrData
{ nullptr, IDC_SIZEWE
, 0 }, // POINTER_WINDOW_WSIZE
2092 ImplPtrData
{ nullptr, IDC_SIZEWE
, 0 }, // POINTER_WINDOW_ESIZE
2093 ImplPtrData
{ nullptr, IDC_SIZENWSE
, 0 }, // POINTER_WINDOW_NWSIZE
2094 ImplPtrData
{ nullptr, IDC_SIZENESW
, 0 }, // POINTER_WINDOW_NESIZE
2095 ImplPtrData
{ nullptr, IDC_SIZENESW
, 0 }, // POINTER_WINDOW_SWSIZE
2096 ImplPtrData
{ nullptr, IDC_SIZENWSE
, 0 }, // POINTER_WINDOW_SESIZE
2097 ImplPtrData
{ nullptr, IDC_SIZEWE
, 0 }, // POINTER_HSPLIT
2098 ImplPtrData
{ nullptr, IDC_SIZENS
, 0 }, // POINTER_VSPLIT
2099 ImplPtrData
{ nullptr, IDC_SIZEWE
, 0 }, // POINTER_HSIZEBAR
2100 ImplPtrData
{ nullptr, IDC_SIZENS
, 0 }, // POINTER_VSIZEBAR
2101 ImplPtrData
{ nullptr, IDC_HAND
, 0 }, // POINTER_HAND
2102 ImplPtrData
{ nullptr, IDC_HAND
, 0 }, // POINTER_REFHAND
2103 ImplPtrData
{ nullptr, IDC_PEN
, 0 }, // POINTER_PEN
2104 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MAGNIFY
}, // POINTER_MAGNIFY
2105 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_FILL
}, // POINTER_FILL
2106 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_ROTATE
}, // POINTER_ROTATE
2107 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_HSHEAR
}, // POINTER_HSHEAR
2108 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_VSHEAR
}, // POINTER_VSHEAR
2109 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MIRROR
}, // POINTER_MIRROR
2110 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_CROOK
}, // POINTER_CROOK
2111 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_CROP
}, // POINTER_CROP
2112 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MOVEPOINT
}, // POINTER_MOVEPOINT
2113 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MOVEBEZIERWEIGHT
}, // POINTER_MOVEBEZIERWEIGHT
2114 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MOVEDATA
}, // POINTER_MOVEDATA
2115 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_COPYDATA
}, // POINTER_COPYDATA
2116 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_LINKDATA
}, // POINTER_LINKDATA
2117 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MOVEDATALINK
}, // POINTER_MOVEDATALINK
2118 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_COPYDATALINK
}, // POINTER_COPYDATALINK
2119 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MOVEFILE
}, // POINTER_MOVEFILE
2120 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_COPYFILE
}, // POINTER_COPYFILE
2121 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_LINKFILE
}, // POINTER_LINKFILE
2122 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MOVEFILELINK
}, // POINTER_MOVEFILELINK
2123 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_COPYFILELINK
}, // POINTER_COPYFILELINK
2124 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_MOVEFILES
}, // POINTER_MOVEFILES
2125 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_COPYFILES
}, // POINTER_COPYFILES
2126 ImplPtrData
{ nullptr, IDC_NO
, 0 }, // POINTER_NOTALLOWED
2127 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_LINE
}, // POINTER_DRAW_LINE
2128 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_RECT
}, // POINTER_DRAW_RECT
2129 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_POLYGON
}, // POINTER_DRAW_POLYGON
2130 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_BEZIER
}, // POINTER_DRAW_BEZIER
2131 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_ARC
}, // POINTER_DRAW_ARC
2132 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_PIE
}, // POINTER_DRAW_PIE
2133 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_CIRCLECUT
}, // POINTER_DRAW_CIRCLECUT
2134 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_ELLIPSE
}, // POINTER_DRAW_ELLIPSE
2135 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_FREEHAND
}, // POINTER_DRAW_FREEHAND
2136 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_CONNECT
}, // POINTER_DRAW_CONNECT
2137 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_TEXT
}, // POINTER_DRAW_TEXT
2138 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DRAW_CAPTION
}, // POINTER_DRAW_CAPTION
2139 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_CHART
}, // POINTER_CHART
2140 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_DETECTIVE
}, // POINTER_DETECTIVE
2141 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_PIVOT_COL
}, // POINTER_PIVOT_COL
2142 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_PIVOT_ROW
}, // POINTER_PIVOT_ROW
2143 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_PIVOT_FIELD
}, // POINTER_PIVOT_FIELD
2144 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_CHAIN
}, // POINTER_CHAIN
2145 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_CHAIN_NOTALLOWED
}, // POINTER_CHAIN_NOTALLOWED
2146 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_N
}, // POINTER_AUTOSCROLL_N
2147 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_S
}, // POINTER_AUTOSCROLL_S
2148 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_W
}, // POINTER_AUTOSCROLL_W
2149 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_E
}, // POINTER_AUTOSCROLL_E
2150 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NW
}, // POINTER_AUTOSCROLL_NW
2151 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NE
}, // POINTER_AUTOSCROLL_NE
2152 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_SW
}, // POINTER_AUTOSCROLL_SW
2153 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_SE
}, // POINTER_AUTOSCROLL_SE
2154 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NS
}, // POINTER_AUTOSCROLL_NS
2155 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_WE
}, // POINTER_AUTOSCROLL_WE
2156 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NSWE
}, // POINTER_AUTOSCROLL_NSWE
2157 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_TEXT_VERTICAL
}, // POINTER_TEXT_VERTICAL
2158 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_PIVOT_DELETE
}, // POINTER_PIVOT_DELETE
2161 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_S
}, // POINTER_TAB_SELECT_S
2162 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_E
}, // POINTER_TAB_SELECT_E
2163 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_SE
}, // POINTER_TAB_SELECT_SE
2164 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_W
}, // POINTER_TAB_SELECT_W
2165 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_SW
}, // POINTER_TAB_SELECT_SW
2167 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_HIDEWHITESPACE
}, // POINTER_HIDEWHITESPACE
2168 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_SHOWWHITESPACE
}, // POINTER_UNHIDEWHITESPACE
2170 ImplPtrData
{ nullptr, nullptr, SAL_RESID_POINTER_FATCROSS
} // POINTER_FATCROSS
2173 // Mousepointer loaded ?
2174 if ( !aImplPtrTab
[ePointerStyle
].mhCursor
)
2176 if ( aImplPtrTab
[ePointerStyle
].mnOwnId
)
2177 aImplPtrTab
[ePointerStyle
].mhCursor
= ImplLoadSalCursor( aImplPtrTab
[ePointerStyle
].mnOwnId
);
2179 aImplPtrTab
[ePointerStyle
].mhCursor
= LoadCursor( nullptr, aImplPtrTab
[ePointerStyle
].mnSysId
);
2182 // change the mouse pointer if different
2183 if ( mhCursor
!= aImplPtrTab
[ePointerStyle
].mhCursor
)
2185 mhCursor
= aImplPtrTab
[ePointerStyle
].mhCursor
;
2186 SetCursor( mhCursor
);
2190 void WinSalFrame::CaptureMouse( bool bCapture
)
2192 // Send this Message to the window, because CaptureMouse() only work
2193 // in the thread of the window, which has create this window
2196 nMsg
= SAL_MSG_CAPTUREMOUSE
;
2198 nMsg
= SAL_MSG_RELEASEMOUSE
;
2199 SendMessageW( mhWnd
, nMsg
, 0, 0 );
2202 void WinSalFrame::SetPointerPos( tools::Long nX
, tools::Long nY
)
2205 aPt
.x
= static_cast<int>(nX
);
2206 aPt
.y
= static_cast<int>(nY
);
2207 ClientToScreen( mhWnd
, &aPt
);
2208 SetCursorPos( aPt
.x
, aPt
.y
);
2211 void WinSalFrame::Flush()
2214 mpLocalGraphics
->Flush();
2215 if(mpThreadGraphics
)
2216 mpThreadGraphics
->Flush();
2220 static void ImplSalFrameSetInputContext( HWND hWnd
, const SalInputContext
* pContext
)
2222 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
2223 bool bIME(pContext
->mnOptions
& InputContextFlags::Text
);
2226 if ( !pFrame
->mbIME
)
2228 pFrame
->mbIME
= true;
2230 if ( pFrame
->mhDefIMEContext
)
2232 ImmAssociateContext( pFrame
->mhWnd
, pFrame
->mhDefIMEContext
);
2233 UINT nImeProps
= ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY
);
2234 pFrame
->mbSpezIME
= (nImeProps
& IME_PROP_SPECIAL_UI
) != 0;
2235 pFrame
->mbAtCursorIME
= (nImeProps
& IME_PROP_AT_CARET
) != 0;
2236 pFrame
->mbHandleIME
= !pFrame
->mbSpezIME
;
2240 // When the application can't handle IME messages, then the
2241 // System should handle the IME handling
2242 if ( !(pContext
->mnOptions
& InputContextFlags::ExtText
) )
2243 pFrame
->mbHandleIME
= false;
2245 // Set the Font for IME Handling
2246 if ( pContext
->mpFont
)
2248 HIMC hIMC
= ImmGetContext( pFrame
->mhWnd
);
2252 ImplGetLogFontFromFontSelect(pContext
->mpFont
->GetFontSelectPattern(),
2254 ImmSetCompositionFontW( hIMC
, &aLogFont
);
2255 ImmReleaseContext( pFrame
->mhWnd
, hIMC
);
2261 if ( pFrame
->mbIME
)
2263 pFrame
->mbIME
= false;
2264 pFrame
->mbHandleIME
= false;
2265 ImmAssociateContext( pFrame
->mhWnd
, nullptr );
2270 void WinSalFrame::SetInputContext( SalInputContext
* pContext
)
2272 // Must be called in the main thread!
2273 SendMessageW( mhWnd
, SAL_MSG_SETINPUTCONTEXT
, 0, reinterpret_cast<LPARAM
>(pContext
) );
2276 static void ImplSalFrameEndExtTextInput( HWND hWnd
, EndExtTextInputFlags nFlags
)
2278 HIMC hIMC
= ImmGetContext( hWnd
);
2282 if ( nFlags
& EndExtTextInputFlags::Complete
)
2283 nIndex
= CPS_COMPLETE
;
2285 nIndex
= CPS_CANCEL
;
2287 ImmNotifyIME( hIMC
, NI_COMPOSITIONSTR
, nIndex
, 0 );
2288 ImmReleaseContext( hWnd
, hIMC
);
2292 void WinSalFrame::EndExtTextInput( EndExtTextInputFlags nFlags
)
2294 // Must be called in the main thread!
2295 SendMessageW( mhWnd
, SAL_MSG_ENDEXTTEXTINPUT
, static_cast<WPARAM
>(nFlags
), 0 );
2298 static void ImplGetKeyNameText( LONG lParam
, sal_Unicode
* pBuf
,
2299 UINT
& rCount
, UINT nMaxSize
,
2300 const char* pReplace
)
2302 static_assert( sizeof( WCHAR
) == sizeof( sal_Unicode
), "must be the same size" );
2304 static const int nMaxKeyLen
= 350;
2305 WCHAR aKeyBuf
[ nMaxKeyLen
];
2309 OUString aLang
= Application::GetSettings().GetUILanguageTag().getLanguage();
2312 aRet
= ::vcl_sal::getKeysReplacementName( aLang
, lParam
);
2313 if( aRet
.isEmpty() )
2315 nKeyLen
= GetKeyNameTextW( lParam
, aKeyBuf
, nMaxKeyLen
);
2316 SAL_WARN_IF( nKeyLen
> nMaxKeyLen
, "vcl", "Invalid key name length!" );
2317 if( nKeyLen
> nMaxKeyLen
)
2319 else if( nKeyLen
> 0 )
2321 // Capitalize just the first letter of key names
2322 CharLowerBuffW( aKeyBuf
, nKeyLen
);
2325 for( WCHAR
*pW
=aKeyBuf
, *pE
=pW
+nKeyLen
; pW
< pE
; ++pW
)
2328 CharUpperBuffW( pW
, 1 );
2329 bUpper
= (*pW
=='+') || (*pW
=='-') || (*pW
==' ') || (*pW
=='.');
2335 nKeyLen
= aRet
.getLength();
2336 wcscpy( aKeyBuf
, o3tl::toW( aRet
.getStr() ));
2340 if ( (nKeyLen
> 0) || pReplace
)
2342 if( (rCount
> 0) && (rCount
< nMaxSize
) )
2350 WCHAR
*pW
= aKeyBuf
, *pE
= aKeyBuf
+ nKeyLen
;
2351 while ((pW
< pE
) && *pW
&& (rCount
< nMaxSize
))
2352 pBuf
[rCount
++] = *pW
++;
2354 else // fall back to provided default name
2356 while( *pReplace
&& (rCount
< nMaxSize
) )
2358 pBuf
[rCount
] = *pReplace
;
2368 OUString
WinSalFrame::GetKeyName( sal_uInt16 nKeyCode
)
2370 static const UINT nMaxKeyLen
= 350;
2371 sal_Unicode aKeyBuf
[ nMaxKeyLen
];
2372 UINT nKeyBufLen
= 0;
2375 if ( nKeyCode
& KEY_MOD1
)
2377 nSysCode
= MapVirtualKeyW( VK_CONTROL
, 0 );
2378 nSysCode
= (nSysCode
<< 16) | ((sal_uLong(1)) << 25);
2379 ImplGetKeyNameText( nSysCode
, aKeyBuf
, nKeyBufLen
, nMaxKeyLen
, "Ctrl" );
2382 if ( nKeyCode
& KEY_MOD2
)
2384 nSysCode
= MapVirtualKeyW( VK_MENU
, 0 );
2385 nSysCode
= (nSysCode
<< 16) | ((sal_uLong(1)) << 25);
2386 ImplGetKeyNameText( nSysCode
, aKeyBuf
, nKeyBufLen
, nMaxKeyLen
, "Alt" );
2389 if ( nKeyCode
& KEY_SHIFT
)
2391 nSysCode
= MapVirtualKeyW( VK_SHIFT
, 0 );
2392 nSysCode
= (nSysCode
<< 16) | ((sal_uLong(1)) << 25);
2393 ImplGetKeyNameText( nSysCode
, aKeyBuf
, nKeyBufLen
, nMaxKeyLen
, "Shift" );
2396 sal_uInt16 nCode
= nKeyCode
& 0x0FFF;
2397 sal_uLong nSysCode2
= 0;
2398 const char* pReplace
= nullptr;
2399 sal_Unicode cSVCode
= 0;
2403 if ( (nCode
>= KEY_0
) && (nCode
<= KEY_9
) )
2404 cSVCode
= '0' + (nCode
- KEY_0
);
2405 else if ( (nCode
>= KEY_A
) && (nCode
<= KEY_Z
) )
2406 cSVCode
= 'A' + (nCode
- KEY_A
);
2407 else if ( (nCode
>= KEY_F1
) && (nCode
<= KEY_F26
) )
2409 nSysCode
= VK_F1
+ (nCode
- KEY_F1
);
2411 if (nCode
<= KEY_F9
)
2413 aFBuf
[1] = sal::static_int_cast
<char>('1' + (nCode
- KEY_F1
));
2416 else if (nCode
<= KEY_F19
)
2419 aFBuf
[2] = sal::static_int_cast
<char>('0' + (nCode
- KEY_F10
));
2425 aFBuf
[2] = sal::static_int_cast
<char>('0' + (nCode
- KEY_F20
));
2436 nSysCode2
= ((sal_uLong(1)) << 24);
2441 nSysCode2
= ((sal_uLong(1)) << 24);
2446 nSysCode2
= ((sal_uLong(1)) << 24);
2450 nSysCode
= VK_RIGHT
;
2451 nSysCode2
= ((sal_uLong(1)) << 24);
2456 nSysCode2
= ((sal_uLong(1)) << 24);
2461 nSysCode2
= ((sal_uLong(1)) << 24);
2465 nSysCode
= VK_PRIOR
;
2466 nSysCode2
= ((sal_uLong(1)) << 24);
2467 pReplace
= "Page Up";
2471 nSysCode2
= ((sal_uLong(1)) << 24);
2472 pReplace
= "Page Down";
2475 nSysCode
= VK_RETURN
;
2479 nSysCode
= VK_ESCAPE
;
2480 pReplace
= "Escape";
2488 pReplace
= "Backspace";
2491 nSysCode
= VK_SPACE
;
2495 nSysCode
= VK_INSERT
;
2496 nSysCode2
= ((sal_uLong(1)) << 24);
2497 pReplace
= "Insert";
2500 nSysCode
= VK_DELETE
;
2501 nSysCode2
= ((sal_uLong(1)) << 24);
2502 pReplace
= "Delete";
2532 case KEY_NUMBERSIGN
:
2535 case KEY_XF86FORWARD
:
2536 cSVCode
= VK_BROWSER_FORWARD
;
2539 cSVCode
= VK_BROWSER_BACK
;
2547 case KEY_QUOTERIGHT
:
2550 case KEY_BRACKETLEFT
:
2553 case KEY_BRACKETRIGHT
:
2559 case KEY_RIGHTCURLYBRACKET
:
2567 nSysCode
= MapVirtualKeyW( nSysCode
, 0 );
2569 nSysCode
= (nSysCode
<< 16) | nSysCode2
;
2570 ImplGetKeyNameText( nSysCode
, aKeyBuf
, nKeyBufLen
, nMaxKeyLen
, pReplace
);
2576 if ( nKeyBufLen
> 0 )
2577 aKeyBuf
[ nKeyBufLen
++ ] = '+';
2578 if( nKeyBufLen
< nMaxKeyLen
)
2579 aKeyBuf
[ nKeyBufLen
++ ] = cSVCode
;
2586 return OUString( aKeyBuf
, sal::static_int_cast
< sal_uInt16
>(nKeyBufLen
) );
2589 static Color
ImplWinColorToSal( COLORREF nColor
)
2591 return Color( GetRValue( nColor
), GetGValue( nColor
), GetBValue( nColor
) );
2594 static void ImplSalUpdateStyleFontW( HDC hDC
, const LOGFONTW
& rLogFont
, vcl::Font
& rFont
)
2596 ImplSalLogFontToFontW( hDC
, rLogFont
, rFont
);
2598 // On Windows 9x, Windows NT we get sometimes very small sizes
2599 // (for example for the small Caption height).
2600 // So if it is MS Sans Serif, a none scalable font we use
2601 // 8 Point as the minimum control height, in all other cases
2602 // 6 Point is the smallest one
2603 if ( rFont
.GetFontHeight() < 8 )
2605 if ( rtl_ustr_compareIgnoreAsciiCase( o3tl::toU(rLogFont
.lfFaceName
), o3tl::toU(L
"MS Sans Serif") ) == 0 )
2606 rFont
.SetFontHeight( 8 );
2607 else if ( rFont
.GetFontHeight() < 6 )
2608 rFont
.SetFontHeight( 6 );
2612 static tools::Long
ImplW2I( const wchar_t* pStr
)
2623 while( (*pStr
>= 48) && (*pStr
<= 57) )
2626 n
+= ((*pStr
) - 48);
2635 void WinSalFrame::UpdateSettings( AllSettings
& rSettings
)
2637 MouseSettings aMouseSettings
= rSettings
.GetMouseSettings();
2638 aMouseSettings
.SetDoubleClickTime( GetDoubleClickTime() );
2639 aMouseSettings
.SetDoubleClickWidth( GetSystemMetrics( SM_CXDOUBLECLK
) );
2640 aMouseSettings
.SetDoubleClickHeight( GetSystemMetrics( SM_CYDOUBLECLK
) );
2641 tools::Long nDragWidth
= GetSystemMetrics( SM_CXDRAG
);
2642 tools::Long nDragHeight
= GetSystemMetrics( SM_CYDRAG
);
2644 aMouseSettings
.SetStartDragWidth( nDragWidth
);
2646 aMouseSettings
.SetStartDragHeight( nDragHeight
);
2648 if ( RegOpenKeyW( HKEY_CURRENT_USER
,
2649 L
"Control Panel\\Desktop",
2650 &hRegKey
) == ERROR_SUCCESS
)
2652 wchar_t aValueBuf
[10];
2653 DWORD nValueSize
= sizeof( aValueBuf
);
2655 if ( RegQueryValueExW( hRegKey
, L
"MenuShowDelay", nullptr,
2656 &nType
, reinterpret_cast<LPBYTE
>(aValueBuf
), &nValueSize
) == ERROR_SUCCESS
)
2658 if ( nType
== REG_SZ
)
2659 aMouseSettings
.SetMenuDelay( static_cast<sal_uLong
>(ImplW2I( aValueBuf
)) );
2662 RegCloseKey( hRegKey
);
2665 StyleSettings aStyleSettings
= rSettings
.GetStyleSettings();
2669 hc
.cbSize
= sizeof( HIGHCONTRAST
);
2670 if( SystemParametersInfoW( SPI_GETHIGHCONTRAST
, hc
.cbSize
, &hc
, 0 )
2671 && (hc
.dwFlags
& HCF_HIGHCONTRASTON
) )
2672 aStyleSettings
.SetHighContrastMode( true );
2674 aStyleSettings
.SetHighContrastMode( false );
2676 aStyleSettings
.SetScrollBarSize( GetSystemMetrics( SM_CXVSCROLL
) );
2677 aStyleSettings
.SetSpinSize( GetSystemMetrics( SM_CXVSCROLL
) );
2678 UINT blinkTime
= GetCaretBlinkTime();
2679 aStyleSettings
.SetCursorBlinkTime(
2680 blinkTime
== 0 || blinkTime
== INFINITE
// 0 indicates error
2681 ? STYLE_CURSOR_NOBLINKTIME
: blinkTime
);
2682 aStyleSettings
.SetFloatTitleHeight( GetSystemMetrics( SM_CYSMCAPTION
) );
2683 aStyleSettings
.SetTitleHeight( GetSystemMetrics( SM_CYCAPTION
) );
2684 aStyleSettings
.SetActiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVEBORDER
) ) );
2685 aStyleSettings
.SetDeactiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVEBORDER
) ) );
2686 aStyleSettings
.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_GRADIENTINACTIVECAPTION
) ) );
2688 Color aControlTextColor
;
2689 Color aMenuBarTextColor
;
2690 Color aMenuBarRolloverTextColor
;
2691 Color aHighlightTextColor
= ImplWinColorToSal(GetSysColor(COLOR_HIGHLIGHTTEXT
));
2693 BOOL bFlatMenus
= FALSE
;
2694 SystemParametersInfoW( SPI_GETFLATMENU
, 0, &bFlatMenus
, 0);
2697 aStyleSettings
.SetUseFlatMenus( true );
2698 // flat borders for our controls etc. as well in this mode (ie, no 3d borders)
2699 // this is not active in the classic style appearance
2700 aStyleSettings
.SetUseFlatBorders( true );
2704 aStyleSettings
.SetUseFlatMenus( false );
2705 aStyleSettings
.SetUseFlatBorders( false );
2710 aStyleSettings
.SetMenuHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_MENUHILIGHT
) ) );
2711 aStyleSettings
.SetMenuBarRolloverColor( ImplWinColorToSal( GetSysColor( COLOR_MENUHILIGHT
) ) );
2712 aStyleSettings
.SetMenuBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW
) ) );
2716 aStyleSettings
.SetMenuHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHT
) ) );
2717 aStyleSettings
.SetMenuBarRolloverColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHT
) ) );
2718 aStyleSettings
.SetMenuBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DLIGHT
) ) );
2721 const bool bUseDarkMode(UseDarkMode());
2723 OUString
sThemeName(!bUseDarkMode
? u
"colibre" : u
"colibre_dark");
2724 aStyleSettings
.SetPreferredIconTheme(sThemeName
, bUseDarkMode
);
2728 SetWindowTheme(mhWnd
, L
"Explorer", nullptr);
2730 HTHEME hTheme
= OpenThemeData(nullptr, L
"ItemsView");
2732 GetThemeColor(hTheme
, 0, 0, TMT_FILLCOLOR
, &color
);
2733 aStyleSettings
.SetFaceColor( ImplWinColorToSal( color
) );
2734 aStyleSettings
.SetWindowColor( ImplWinColorToSal( color
) );
2736 // tdf#156040 in the absence of a better idea, do like
2737 // StyleSettings::Set3DColors does
2738 Color
aLightColor(ImplWinColorToSal(color
));
2739 aLightColor
.DecreaseLuminance(64);
2740 aStyleSettings
.SetLightColor(aLightColor
);
2742 GetThemeColor(hTheme
, 0, 0, TMT_TEXTCOLOR
, &color
);
2743 aStyleSettings
.SetWindowTextColor( ImplWinColorToSal( color
) );
2744 aStyleSettings
.SetToolTextColor( ImplWinColorToSal( color
) );
2745 GetThemeColor(hTheme
, 0, 0, TMT_SHADOWCOLOR
, &color
);
2746 aStyleSettings
.SetShadowColor( ImplWinColorToSal( color
) );
2747 GetThemeColor(hTheme
, 0, 0, TMT_DKSHADOW3D
, &color
);
2748 aStyleSettings
.SetDarkShadowColor( ImplWinColorToSal( color
) );
2749 CloseThemeData(hTheme
);
2751 hTheme
= OpenThemeData(mhWnd
, L
"Button");
2752 GetThemeColor(hTheme
, BP_PUSHBUTTON
, PBS_NORMAL
, TMT_TEXTCOLOR
, &color
);
2753 aControlTextColor
= ImplWinColorToSal(color
);
2754 GetThemeColor(hTheme
, BP_CHECKBOX
, CBS_CHECKEDNORMAL
, TMT_TEXTCOLOR
, &color
);
2755 aStyleSettings
.SetRadioCheckTextColor( ImplWinColorToSal( color
) );
2756 CloseThemeData(hTheme
);
2758 SetWindowTheme(mhWnd
, nullptr, nullptr);
2760 hTheme
= OpenThemeData(mhWnd
, L
"Menu");
2761 GetThemeColor(hTheme
, MENU_POPUPITEM
, MBI_NORMAL
, TMT_TEXTCOLOR
, &color
);
2762 aStyleSettings
.SetMenuTextColor( ImplWinColorToSal( color
) );
2763 aMenuBarTextColor
= ImplWinColorToSal( color
);
2764 aMenuBarRolloverTextColor
= ImplWinColorToSal( color
);
2765 CloseThemeData(hTheme
);
2767 aStyleSettings
.SetActiveTabColor( aStyleSettings
.GetWindowColor() );
2768 hTheme
= OpenThemeData(mhWnd
, L
"Toolbar");
2769 GetThemeColor(hTheme
, 0, 0, TMT_FILLCOLOR
, &color
);
2770 aStyleSettings
.SetInactiveTabColor( ImplWinColorToSal( color
) );
2771 // see ImplDrawNativeControl for dark mode
2772 aStyleSettings
.SetMenuBarColor( aStyleSettings
.GetWindowColor() );
2773 CloseThemeData(hTheme
);
2775 hTheme
= OpenThemeData(mhWnd
, L
"Textstyle");
2778 GetThemeColor(hTheme
, TEXT_HYPERLINKTEXT
, TS_HYPERLINK_NORMAL
, TMT_TEXTCOLOR
, &color
);
2779 aStyleSettings
.SetLinkColor(ImplWinColorToSal(color
));
2780 CloseThemeData(hTheme
);
2783 // tdf#148448 pick a warning color more likely to be readable as a
2784 // background in a dark theme
2785 aStyleSettings
.SetWarningColor(Color(0xf5, 0x79, 0x00));
2789 aStyleSettings
.SetFaceColor( ImplWinColorToSal( GetSysColor( COLOR_3DFACE
) ) );
2790 aStyleSettings
.SetWindowColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOW
) ) );
2791 aStyleSettings
.SetWindowTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT
) ) );
2792 aStyleSettings
.SetToolTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT
) ) );
2793 aStyleSettings
.SetLightColor( ImplWinColorToSal( GetSysColor( COLOR_3DHILIGHT
) ) );
2794 aStyleSettings
.SetShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW
) ) );
2795 aStyleSettings
.SetDarkShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DDKSHADOW
) ) );
2796 aControlTextColor
= ImplWinColorToSal(GetSysColor(COLOR_BTNTEXT
));
2797 aStyleSettings
.SetRadioCheckTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT
) ) );
2798 aStyleSettings
.SetMenuTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT
) ) );
2799 aMenuBarTextColor
= ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT
) );
2800 aMenuBarRolloverTextColor
= aHighlightTextColor
;
2802 aStyleSettings
.SetMenuBarColor( ImplWinColorToSal( GetSysColor( COLOR_MENUBAR
) ) );
2804 aStyleSettings
.SetMenuBarColor( ImplWinColorToSal( GetSysColor( COLOR_MENU
) ) );
2805 aStyleSettings
.SetActiveTabColor( aStyleSettings
.GetWindowColor() );
2806 aStyleSettings
.SetInactiveTabColor( aStyleSettings
.GetFaceColor() );
2809 if ( std::optional
<Color
> aColor
= aStyleSettings
.GetPersonaMenuBarTextColor() )
2811 aMenuBarTextColor
= *aColor
;
2812 if (!aStyleSettings
.GetHighContrastMode())
2813 aMenuBarRolloverTextColor
= *aColor
;
2816 aStyleSettings
.SetMenuBarTextColor( aMenuBarTextColor
);
2817 aStyleSettings
.SetMenuBarRolloverTextColor( aMenuBarRolloverTextColor
);
2819 aStyleSettings
.SetLightBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DLIGHT
) ) );
2820 aStyleSettings
.SetHelpColor( ImplWinColorToSal( GetSysColor( COLOR_INFOBK
) ) );
2821 aStyleSettings
.SetHelpTextColor( ImplWinColorToSal( GetSysColor( COLOR_INFOTEXT
) ) );
2823 aStyleSettings
.SetWorkspaceColor(aStyleSettings
.GetFaceColor());
2824 aStyleSettings
.SetDialogColor(aStyleSettings
.GetFaceColor());
2825 aStyleSettings
.SetDialogTextColor(aControlTextColor
);
2827 Color aHighlightButtonTextColor
= aStyleSettings
.GetHighContrastMode() ?
2828 aHighlightTextColor
: aControlTextColor
;
2830 if (aStyleSettings
.GetHighContrastMode())
2832 Color
aLinkColor(ImplWinColorToSal(GetSysColor(COLOR_HOTLIGHT
)));
2833 aStyleSettings
.SetLinkColor(aLinkColor
);
2834 aStyleSettings
.SetVisitedLinkColor(aLinkColor
);
2837 aStyleSettings
.SetDefaultButtonTextColor(aHighlightButtonTextColor
);
2838 aStyleSettings
.SetButtonTextColor(aControlTextColor
);
2839 aStyleSettings
.SetDefaultActionButtonTextColor(aHighlightButtonTextColor
);
2840 aStyleSettings
.SetActionButtonTextColor(aControlTextColor
);
2841 aStyleSettings
.SetFlatButtonTextColor(aControlTextColor
);
2842 aStyleSettings
.SetDefaultButtonRolloverTextColor(aHighlightButtonTextColor
);
2843 aStyleSettings
.SetButtonRolloverTextColor(aHighlightButtonTextColor
);
2844 aStyleSettings
.SetDefaultActionButtonRolloverTextColor(aHighlightButtonTextColor
);
2845 aStyleSettings
.SetActionButtonRolloverTextColor(aHighlightButtonTextColor
);
2846 aStyleSettings
.SetFlatButtonRolloverTextColor(aHighlightButtonTextColor
);
2847 aStyleSettings
.SetDefaultButtonPressedRolloverTextColor(aControlTextColor
);
2848 aStyleSettings
.SetButtonPressedRolloverTextColor(aControlTextColor
);
2849 aStyleSettings
.SetDefaultActionButtonPressedRolloverTextColor(aControlTextColor
);
2850 aStyleSettings
.SetActionButtonPressedRolloverTextColor(aControlTextColor
);
2851 aStyleSettings
.SetFlatButtonPressedRolloverTextColor(aControlTextColor
);
2853 aStyleSettings
.SetTabTextColor(aControlTextColor
);
2854 aStyleSettings
.SetTabRolloverTextColor(aControlTextColor
);
2855 aStyleSettings
.SetTabHighlightTextColor(aControlTextColor
);
2857 aStyleSettings
.SetGroupTextColor( aStyleSettings
.GetRadioCheckTextColor() );
2858 aStyleSettings
.SetLabelTextColor( aStyleSettings
.GetRadioCheckTextColor() );
2859 aStyleSettings
.SetFieldColor( aStyleSettings
.GetWindowColor() );
2860 aStyleSettings
.SetListBoxWindowBackgroundColor( aStyleSettings
.GetWindowColor() );
2861 aStyleSettings
.SetFieldTextColor( aStyleSettings
.GetWindowTextColor() );
2862 aStyleSettings
.SetFieldRolloverTextColor( aStyleSettings
.GetFieldTextColor() );
2863 aStyleSettings
.SetListBoxWindowTextColor( aStyleSettings
.GetFieldTextColor() );
2865 aStyleSettings
.SetAccentColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHT
) ) );
2866 // https://devblogs.microsoft.com/oldnewthing/20170405-00/?p=95905
2868 aStyleSettings
.SetHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHT
) ) );
2869 aStyleSettings
.SetHighlightTextColor(aHighlightTextColor
);
2870 aStyleSettings
.SetListBoxWindowHighlightColor( aStyleSettings
.GetHighlightColor() );
2871 aStyleSettings
.SetListBoxWindowHighlightTextColor( aStyleSettings
.GetHighlightTextColor() );
2872 aStyleSettings
.SetMenuHighlightTextColor( aStyleSettings
.GetHighlightTextColor() );
2874 ImplSVData
* pSVData
= ImplGetSVData();
2875 pSVData
->maNWFData
.mnMenuFormatBorderX
= 0;
2876 pSVData
->maNWFData
.mnMenuFormatBorderY
= 0;
2877 pSVData
->maNWFData
.maMenuBarHighlightTextColor
= COL_TRANSPARENT
;
2878 GetSalData()->mbThemeMenuSupport
= false;
2879 aStyleSettings
.SetMenuColor( ImplWinColorToSal( GetSysColor( COLOR_MENU
) ) );
2880 aStyleSettings
.SetMenuBarHighlightTextColor(aStyleSettings
.GetMenuHighlightTextColor());
2881 aStyleSettings
.SetActiveColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVECAPTION
) ) );
2882 aStyleSettings
.SetActiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_CAPTIONTEXT
) ) );
2883 aStyleSettings
.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTION
) ) );
2884 aStyleSettings
.SetDeactiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTIONTEXT
) ) );
2886 aStyleSettings
.SetCheckedColorSpecialCase( );
2889 DWORD nCaretWidth
= 2;
2890 if( SystemParametersInfoW( SPI_GETCARETWIDTH
, 0, &nCaretWidth
, 0 ) )
2891 aStyleSettings
.SetCursorSize( nCaretWidth
);
2894 vcl::Font aMenuFont
= aStyleSettings
.GetMenuFont();
2895 vcl::Font aTitleFont
= aStyleSettings
.GetTitleFont();
2896 vcl::Font aFloatTitleFont
= aStyleSettings
.GetFloatTitleFont();
2897 vcl::Font aHelpFont
= aStyleSettings
.GetHelpFont();
2898 vcl::Font aAppFont
= aStyleSettings
.GetAppFont();
2899 vcl::Font aIconFont
= aStyleSettings
.GetIconFont();
2900 HDC hDC
= GetDC( nullptr );
2901 NONCLIENTMETRICSW aNonClientMetrics
;
2902 aNonClientMetrics
.cbSize
= sizeof( aNonClientMetrics
);
2903 if ( SystemParametersInfoW( SPI_GETNONCLIENTMETRICS
, sizeof( aNonClientMetrics
), &aNonClientMetrics
, 0 ) )
2905 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfMenuFont
, aMenuFont
);
2906 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfCaptionFont
, aTitleFont
);
2907 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfSmCaptionFont
, aFloatTitleFont
);
2908 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfStatusFont
, aHelpFont
);
2909 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfMessageFont
, aAppFont
);
2912 if ( SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, 0, &aLogFont
, 0 ) )
2913 ImplSalUpdateStyleFontW( hDC
, aLogFont
, aIconFont
);
2916 ReleaseDC( nullptr, hDC
);
2918 aStyleSettings
.SetToolbarIconSize(ToolbarIconSize::Large
);
2920 aStyleSettings
.BatchSetFonts( aAppFont
, aAppFont
);
2922 aStyleSettings
.SetMenuFont( aMenuFont
);
2923 aStyleSettings
.SetTitleFont( aTitleFont
);
2924 aStyleSettings
.SetFloatTitleFont( aFloatTitleFont
);
2925 aStyleSettings
.SetHelpFont( aHelpFont
);
2926 aStyleSettings
.SetIconFont( aIconFont
);
2928 if ( aAppFont
.GetWeight() > WEIGHT_NORMAL
)
2929 aAppFont
.SetWeight( WEIGHT_NORMAL
);
2930 aStyleSettings
.SetToolFont( aAppFont
);
2931 aStyleSettings
.SetTabFont( aAppFont
);
2934 if ( SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &bDragFull
, 0 ) )
2936 DragFullOptions nDragFullOptions
= aStyleSettings
.GetDragFullOptions();
2938 nDragFullOptions
|= DragFullOptions::WindowMove
| DragFullOptions::WindowSize
| DragFullOptions::Docking
| DragFullOptions::Split
;
2940 nDragFullOptions
&= ~DragFullOptions(DragFullOptions::WindowMove
| DragFullOptions::WindowSize
| DragFullOptions::Docking
| DragFullOptions::Split
);
2941 aStyleSettings
.SetDragFullOptions( nDragFullOptions
);
2944 if ( RegOpenKeyW( HKEY_CURRENT_USER
,
2945 L
"Control Panel\\International\\Calendars\\TwoDigitYearMax",
2946 &hRegKey
) == ERROR_SUCCESS
)
2948 wchar_t aValueBuf
[10];
2950 DWORD nValueSize
= sizeof( aValueBuf
);
2952 if ( RegQueryValueExW( hRegKey
, L
"1", nullptr,
2953 &nType
, reinterpret_cast<LPBYTE
>(aValueBuf
), &nValueSize
) == ERROR_SUCCESS
)
2955 if ( nType
== REG_SZ
)
2957 nValue
= static_cast<sal_uLong
>(ImplW2I( aValueBuf
));
2958 if ( (nValue
> 1000) && (nValue
< 10000) )
2960 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(comphelper::ConfigurationChanges::create());
2961 officecfg::Office::Common::DateFormat::TwoDigitYear::set(static_cast<sal_Int32
>(nValue
-99), batch
);
2967 RegCloseKey( hRegKey
);
2970 rSettings
.SetMouseSettings( aMouseSettings
);
2971 rSettings
.SetStyleSettings( aStyleSettings
);
2973 // now apply the values from theming, if available
2974 WinSalGraphics::updateSettingsNative( rSettings
);
2977 const SystemEnvData
* WinSalFrame::GetSystemData() const
2982 void WinSalFrame::Beep()
2988 SalFrame::SalPointerState
WinSalFrame::GetPointerState()
2990 SalPointerState aState
;
2993 if ( GetKeyState( VK_LBUTTON
) & 0x8000 )
2994 aState
.mnState
|= MOUSE_LEFT
;
2995 if ( GetKeyState( VK_MBUTTON
) & 0x8000 )
2996 aState
.mnState
|= MOUSE_MIDDLE
;
2997 if ( GetKeyState( VK_RBUTTON
) & 0x8000 )
2998 aState
.mnState
|= MOUSE_RIGHT
;
2999 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3000 aState
.mnState
|= KEY_SHIFT
;
3001 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3002 aState
.mnState
|= KEY_MOD1
;
3003 if ( GetKeyState( VK_MENU
) & 0x8000 )
3004 aState
.mnState
|= KEY_MOD2
;
3007 GetCursorPos( &pt
);
3009 aState
.maPos
= Point(pt
.x
- maGeometry
.x(), pt
.y
- maGeometry
.y());
3013 KeyIndicatorState
WinSalFrame::GetIndicatorState()
3015 KeyIndicatorState aState
= KeyIndicatorState::NONE
;
3016 if (::GetKeyState(VK_CAPITAL
))
3017 aState
|= KeyIndicatorState::CAPSLOCK
;
3019 if (::GetKeyState(VK_NUMLOCK
))
3020 aState
|= KeyIndicatorState::NUMLOCK
;
3022 if (::GetKeyState(VK_SCROLL
))
3023 aState
|= KeyIndicatorState::SCROLLLOCK
;
3028 void WinSalFrame::SimulateKeyPress( sal_uInt16 nKeyCode
)
3038 if (nVKey
> 0 && nVKey
< 255)
3040 ::keybd_event(nVKey
, 0x45, KEYEVENTF_EXTENDEDKEY
, 0);
3041 ::keybd_event(nVKey
, 0x45, KEYEVENTF_EXTENDEDKEY
|KEYEVENTF_KEYUP
, 0);
3045 void WinSalFrame::ResetClipRegion()
3047 SetWindowRgn( mhWnd
, nullptr, TRUE
);
3050 void WinSalFrame::BeginSetClipRegion( sal_uInt32 nRects
)
3053 delete [] reinterpret_cast<BYTE
*>(mpClipRgnData
);
3054 sal_uLong nRectBufSize
= sizeof(RECT
)*nRects
;
3055 mpClipRgnData
= reinterpret_cast<RGNDATA
*>(new BYTE
[sizeof(RGNDATA
)-1+nRectBufSize
]);
3056 mpClipRgnData
->rdh
.dwSize
= sizeof( RGNDATAHEADER
);
3057 mpClipRgnData
->rdh
.iType
= RDH_RECTANGLES
;
3058 mpClipRgnData
->rdh
.nCount
= nRects
;
3059 mpClipRgnData
->rdh
.nRgnSize
= nRectBufSize
;
3060 SetRectEmpty( &(mpClipRgnData
->rdh
.rcBound
) );
3061 mpNextClipRect
= reinterpret_cast<RECT
*>(&(mpClipRgnData
->Buffer
));
3062 mbFirstClipRect
= true;
3065 void WinSalFrame::UnionClipRegion( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
)
3067 if( ! mpClipRgnData
)
3070 RECT
* pRect
= mpNextClipRect
;
3071 RECT
* pBoundRect
= &(mpClipRgnData
->rdh
.rcBound
);
3072 tools::Long nRight
= nX
+ nWidth
;
3073 tools::Long nBottom
= nY
+ nHeight
;
3075 if ( mbFirstClipRect
)
3077 pBoundRect
->left
= nX
;
3078 pBoundRect
->top
= nY
;
3079 pBoundRect
->right
= nRight
;
3080 pBoundRect
->bottom
= nBottom
;
3081 mbFirstClipRect
= false;
3085 if ( nX
< pBoundRect
->left
)
3086 pBoundRect
->left
= static_cast<int>(nX
);
3088 if ( nY
< pBoundRect
->top
)
3089 pBoundRect
->top
= static_cast<int>(nY
);
3091 if ( nRight
> pBoundRect
->right
)
3092 pBoundRect
->right
= static_cast<int>(nRight
);
3094 if ( nBottom
> pBoundRect
->bottom
)
3095 pBoundRect
->bottom
= static_cast<int>(nBottom
);
3098 pRect
->left
= static_cast<int>(nX
);
3099 pRect
->top
= static_cast<int>(nY
);
3100 pRect
->right
= static_cast<int>(nRight
);
3101 pRect
->bottom
= static_cast<int>(nBottom
);
3102 if( (mpNextClipRect
- reinterpret_cast<RECT
*>(&mpClipRgnData
->Buffer
)) < static_cast<int>(mpClipRgnData
->rdh
.nCount
) )
3106 void WinSalFrame::EndSetClipRegion()
3108 if( ! mpClipRgnData
)
3113 // create region from accumulated rectangles
3114 if ( mpClipRgnData
->rdh
.nCount
== 1 )
3116 RECT
* pRect
= &(mpClipRgnData
->rdh
.rcBound
);
3117 hRegion
= CreateRectRgn( pRect
->left
, pRect
->top
,
3118 pRect
->right
, pRect
->bottom
);
3122 sal_uLong nSize
= mpClipRgnData
->rdh
.nRgnSize
+sizeof(RGNDATAHEADER
);
3123 hRegion
= ExtCreateRegion( nullptr, nSize
, mpClipRgnData
);
3125 delete [] reinterpret_cast<BYTE
*>(mpClipRgnData
);
3126 mpClipRgnData
= nullptr;
3128 SAL_WARN_IF( !hRegion
, "vcl", "WinSalFrame::EndSetClipRegion() - Can't create ClipRegion" );
3132 GetWindowRect( mhWnd
, &aWindowRect
);
3136 ClientToScreen( mhWnd
, &aPt
);
3137 OffsetRgn( hRegion
, aPt
.x
- aWindowRect
.left
, aPt
.y
- aWindowRect
.top
);
3139 if( SetWindowRgn( mhWnd
, hRegion
, TRUE
) == 0 )
3140 DeleteObject( hRegion
);
3144 void WinSalFrame::UpdateDarkMode()
3146 ::UpdateDarkMode(mhWnd
);
3149 bool WinSalFrame::GetUseDarkMode() const
3151 return UseDarkMode();
3154 bool WinSalFrame::GetUseReducedAnimation() const
3156 BOOL bEnableAnimation
= FALSE
;
3157 SystemParametersInfoW(SPI_GETCLIENTAREAANIMATION
, 0, &bEnableAnimation
, 0);
3158 return !bEnableAnimation
;
3161 static bool ImplHandleMouseMsg( HWND hWnd
, UINT nMsg
,
3162 WPARAM wParam
, LPARAM lParam
)
3164 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3168 if( nMsg
== WM_LBUTTONDOWN
|| nMsg
== WM_MBUTTONDOWN
|| nMsg
== WM_RBUTTONDOWN
)
3170 // #103168# post again if async focus has not arrived yet
3171 // hopefully we will not receive the corresponding button up before this
3172 // button down arrives again
3173 vcl::Window
*pWin
= pFrame
->GetWindow();
3174 if( pWin
&& pWin
->ImplGetWindowImpl()->mpFrameData
->mnFocusId
)
3176 bool const ret
= PostMessageW( hWnd
, nMsg
, wParam
, lParam
);
3177 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
3181 SalMouseEvent aMouseEvt
;
3183 SalEvent nEvent
= SalEvent::NONE
;
3186 aMouseEvt
.mnX
= static_cast<short>(LOWORD( lParam
));
3187 aMouseEvt
.mnY
= static_cast<short>(HIWORD( lParam
));
3188 aMouseEvt
.mnCode
= 0;
3189 aMouseEvt
.mnTime
= GetMessageTime();
3191 // Use GetKeyState(), as some Logitech mouse drivers do not check
3192 // KeyState when simulating double-click with center mouse button
3194 if ( GetKeyState( VK_LBUTTON
) & 0x8000 )
3195 aMouseEvt
.mnCode
|= MOUSE_LEFT
;
3196 if ( GetKeyState( VK_MBUTTON
) & 0x8000 )
3197 aMouseEvt
.mnCode
|= MOUSE_MIDDLE
;
3198 if ( GetKeyState( VK_RBUTTON
) & 0x8000 )
3199 aMouseEvt
.mnCode
|= MOUSE_RIGHT
;
3200 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3201 aMouseEvt
.mnCode
|= KEY_SHIFT
;
3202 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3203 aMouseEvt
.mnCode
|= KEY_MOD1
;
3204 if ( GetKeyState( VK_MENU
) & 0x8000 )
3205 aMouseEvt
.mnCode
|= KEY_MOD2
;
3211 // As the mouse events are not collected correctly when
3212 // pressing modifier keys (as interrupted by KeyEvents)
3213 // we do this here ourselves
3214 if ( aMouseEvt
.mnCode
& (KEY_SHIFT
| KEY_MOD1
| KEY_MOD2
) )
3217 if ( PeekMessageW( &aTempMsg
, hWnd
, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_NOREMOVE
| PM_NOYIELD
) )
3219 if ( (aTempMsg
.message
== WM_MOUSEMOVE
) &&
3220 (aTempMsg
.wParam
== wParam
) )
3225 SalData
* pSalData
= GetSalData();
3226 // Test for MouseLeave
3227 if ( pSalData
->mhWantLeaveMsg
&& (pSalData
->mhWantLeaveMsg
!= hWnd
) )
3228 SendMessageW( pSalData
->mhWantLeaveMsg
, SAL_MSG_MOUSELEAVE
, 0, GetMessagePos() );
3230 pSalData
->mhWantLeaveMsg
= hWnd
;
3231 aMouseEvt
.mnButton
= 0;
3232 nEvent
= SalEvent::MouseMove
;
3236 case WM_NCMOUSEMOVE
:
3237 case SAL_MSG_MOUSELEAVE
:
3239 SalData
* pSalData
= GetSalData();
3240 if ( pSalData
->mhWantLeaveMsg
== hWnd
)
3242 // Mouse-Coordinates are relative to the screen
3244 aPt
.x
= static_cast<short>(LOWORD(lParam
));
3245 aPt
.y
= static_cast<short>(HIWORD(lParam
));
3246 ScreenToClient(hWnd
, &aPt
);
3247 if (const auto& pHelpWin
= ImplGetSVHelpData().mpHelpWin
)
3249 const tools::Rectangle
& rHelpRect
= pHelpWin
->GetHelpArea();
3250 if (rHelpRect
.Contains(Point(aPt
.x
, aPt
.y
)))
3252 // We have entered a tooltip (help window). Don't call the handler here; it
3253 // would launch the sequence "Mouse leaves the Control->Control redraws->
3254 // Help window gets destroyed->Mouse enters the Control->Control redraws",
3255 // which takes CPU and may flicker. Just destroy the help window and pretend
3256 // we are still over the original window.
3257 ImplDestroyHelpWindow(true);
3262 pSalData
->mhWantLeaveMsg
= nullptr;
3263 aMouseEvt
.mnX
= aPt
.x
;
3264 aMouseEvt
.mnY
= aPt
.y
;
3265 aMouseEvt
.mnButton
= 0;
3266 nEvent
= SalEvent::MouseLeave
;
3273 case WM_LBUTTONDOWN
:
3274 aMouseEvt
.mnButton
= MOUSE_LEFT
;
3275 nEvent
= SalEvent::MouseButtonDown
;
3278 case WM_MBUTTONDOWN
:
3279 aMouseEvt
.mnButton
= MOUSE_MIDDLE
;
3280 nEvent
= SalEvent::MouseButtonDown
;
3283 case WM_RBUTTONDOWN
:
3284 aMouseEvt
.mnButton
= MOUSE_RIGHT
;
3285 nEvent
= SalEvent::MouseButtonDown
;
3289 aMouseEvt
.mnButton
= MOUSE_LEFT
;
3290 nEvent
= SalEvent::MouseButtonUp
;
3294 aMouseEvt
.mnButton
= MOUSE_MIDDLE
;
3295 nEvent
= SalEvent::MouseButtonUp
;
3299 aMouseEvt
.mnButton
= MOUSE_RIGHT
;
3300 nEvent
= SalEvent::MouseButtonUp
;
3304 // check if this window was destroyed - this might happen if we are the help window
3305 // and sent a mouse leave message to the application which killed the help window, ie ourselves
3306 if( !IsWindow( hWnd
) )
3311 if ( nEvent
== SalEvent::MouseButtonDown
)
3312 UpdateWindow( hWnd
);
3314 if( AllSettings::GetLayoutRTL() )
3315 aMouseEvt
.mnX
= pFrame
->maGeometry
.width() - 1 - aMouseEvt
.mnX
;
3317 nRet
= pFrame
->CallCallback( nEvent
, &aMouseEvt
);
3318 if ( nMsg
== WM_MOUSEMOVE
)
3319 SetCursor( pFrame
->mhCursor
);
3327 static bool ImplHandleMouseActivateMsg( HWND hWnd
)
3329 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3333 if ( pFrame
->mbFloatWin
)
3336 return pFrame
->CallCallback( SalEvent::MouseActivate
, nullptr );
3339 static bool ImplHandleWheelMsg( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
)
3341 DBG_ASSERT( nMsg
== WM_MOUSEWHEEL
||
3342 nMsg
== WM_MOUSEHWHEEL
,
3343 "ImplHandleWheelMsg() called with no wheel mouse event" );
3345 ImplSalYieldMutexAcquireWithWait();
3348 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3351 WORD nWinModCode
= LOWORD( wParam
);
3353 aWinPt
.x
= static_cast<short>(LOWORD( lParam
));
3354 aWinPt
.y
= static_cast<short>(HIWORD( lParam
));
3355 ScreenToClient( hWnd
, &aWinPt
);
3357 SalWheelMouseEvent aWheelEvt
;
3358 aWheelEvt
.mnTime
= GetMessageTime();
3359 aWheelEvt
.mnX
= aWinPt
.x
;
3360 aWheelEvt
.mnY
= aWinPt
.y
;
3361 aWheelEvt
.mnCode
= 0;
3362 aWheelEvt
.mnDelta
= static_cast<short>(HIWORD( wParam
));
3363 aWheelEvt
.mnNotchDelta
= aWheelEvt
.mnDelta
/WHEEL_DELTA
;
3364 if( aWheelEvt
.mnNotchDelta
== 0 )
3366 if( aWheelEvt
.mnDelta
> 0 )
3367 aWheelEvt
.mnNotchDelta
= 1;
3368 else if( aWheelEvt
.mnDelta
< 0 )
3369 aWheelEvt
.mnNotchDelta
= -1;
3372 if( nMsg
== WM_MOUSEWHEEL
)
3374 if ( aSalShlData
.mnWheelScrollLines
== WHEEL_PAGESCROLL
)
3375 aWheelEvt
.mnScrollLines
= SAL_WHEELMOUSE_EVENT_PAGESCROLL
;
3377 aWheelEvt
.mnScrollLines
= aSalShlData
.mnWheelScrollLines
;
3378 aWheelEvt
.mbHorz
= false;
3382 aWheelEvt
.mnScrollLines
= aSalShlData
.mnWheelScrollChars
;
3383 aWheelEvt
.mbHorz
= true;
3385 // fdo#36380 - seems horiz scrolling has swapped direction
3386 aWheelEvt
.mnDelta
*= -1;
3387 aWheelEvt
.mnNotchDelta
*= -1;
3390 if ( nWinModCode
& MK_SHIFT
)
3391 aWheelEvt
.mnCode
|= KEY_SHIFT
;
3392 if ( nWinModCode
& MK_CONTROL
)
3393 aWheelEvt
.mnCode
|= KEY_MOD1
;
3394 if ( GetKeyState( VK_MENU
) & 0x8000 )
3395 aWheelEvt
.mnCode
|= KEY_MOD2
;
3397 if( AllSettings::GetLayoutRTL() )
3398 aWheelEvt
.mnX
= pFrame
->maGeometry
.width() - 1 - aWheelEvt
.mnX
;
3400 nRet
= pFrame
->CallCallback( SalEvent::WheelMouse
, &aWheelEvt
);
3403 ImplSalYieldMutexRelease();
3408 static sal_uInt16
ImplSalGetKeyCode( WPARAM wParam
)
3410 sal_uInt16 nKeyCode
;
3413 if ( wParam
< KEY_TAB_SIZE
)
3414 nKeyCode
= aImplTranslateKeyTab
[wParam
];
3417 SalData
* pSalData
= GetSalData();
3418 std::map
< UINT
, sal_uInt16
>::const_iterator it
= pSalData
->maVKMap
.find( static_cast<UINT
>(wParam
) );
3419 if( it
!= pSalData
->maVKMap
.end() )
3420 nKeyCode
= it
->second
;
3428 static void ImplUpdateInputLang( WinSalFrame
* pFrame
)
3430 UINT nLang
= LOWORD( GetKeyboardLayout( 0 ) );
3431 if ( nLang
&& nLang
!= pFrame
->mnInputLang
)
3433 // keep input lang up-to-date
3434 pFrame
->mnInputLang
= nLang
;
3437 // We are on Windows NT so we use Unicode FrameProcs and get
3438 // Unicode charcodes directly from Windows no need to set up a
3443 static sal_Unicode
ImplGetCharCode( WinSalFrame
* pFrame
, WPARAM nCharCode
)
3445 ImplUpdateInputLang( pFrame
);
3447 // We are on Windows NT so we use Unicode FrameProcs and we
3448 // get Unicode charcodes directly from Windows
3449 return static_cast<sal_Unicode
>(nCharCode
);
3452 LanguageType
WinSalFrame::GetInputLanguage()
3455 ImplUpdateInputLang( this );
3458 return LANGUAGE_DONTKNOW
;
3460 return LanguageType(mnInputLang
);
3463 bool WinSalFrame::MapUnicodeToKeyCode( sal_Unicode aUnicode
, LanguageType aLangType
, vcl::KeyCode
& rKeyCode
)
3466 sal_IntPtr nLangType
= static_cast<sal_uInt16
>(aLangType
);
3467 // just use the passed language identifier, do not try to load additional keyboard support
3468 HKL hkl
= reinterpret_cast<HKL
>(nLangType
);
3472 SHORT scan
= VkKeyScanExW( aUnicode
, hkl
);
3473 if( LOWORD(scan
) == 0xFFFF )
3474 // keyboard not loaded or key cannot be mapped
3478 BYTE vkeycode
= LOBYTE(scan
);
3479 BYTE shiftstate
= HIBYTE(scan
);
3481 // Last argument is set to false, because there's no decision made
3482 // yet which key should be assigned to MOD3 modifier on Windows.
3483 // Windows key - user's can be confused, because it should display
3484 // Windows menu (applies to both left/right key)
3485 // Menu key - this key is used to display context menu
3486 // AltGr key - probably it has no sense
3487 rKeyCode
= vcl::KeyCode( ImplSalGetKeyCode( vkeycode
),
3488 (shiftstate
& 0x01) != 0, // shift
3489 (shiftstate
& 0x02) != 0, // ctrl
3490 (shiftstate
& 0x04) != 0, // alt
3499 static void UnsetAltIfAltGr(SalKeyEvent
& rKeyEvt
, sal_uInt16 nModCode
)
3501 if ((nModCode
& (KEY_MOD1
| KEY_MOD2
)) == (KEY_MOD1
| KEY_MOD2
) &&
3504 // this is actually AltGr and should not be handled as Alt
3505 rKeyEvt
.mnCode
&= ~(KEY_MOD1
| KEY_MOD2
);
3509 // tdf#152404 Commit uncommitted text before dispatching key shortcuts. In
3510 // certain cases such as pressing Control-Alt-C in a Writer document while
3511 // there is uncommitted text will call WinSalFrame::EndExtTextInput() which
3512 // will dispatch a SalEvent::EndExtTextInput event. Writer's handler for that
3513 // event will delete the uncommitted text and then insert the committed text
3514 // but LibreOffice will crash when deleting the uncommitted text because
3515 // deletion of the text also removes and deletes the newly inserted comment.
3516 static void FlushIMBeforeShortCut(WinSalFrame
* pFrame
, SalEvent nEvent
, sal_uInt16 nModCode
)
3518 if (pFrame
->mbCandidateMode
&& nEvent
== SalEvent::KeyInput
3519 && (nModCode
& (KEY_MOD1
| KEY_MOD2
)))
3521 pFrame
->EndExtTextInput(EndExtTextInputFlags::Complete
);
3525 // When Num Lock is off, the key codes from NumPag come as arrows, PgUp/PgDn, etc.
3526 static WORD
NumPadFromArrows(WORD vk
)
3555 static bool HandleAltNumPadCode(HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
)
3559 bool started
= false;
3560 //static bool hex = false; // TODO: support HKEY_CURRENT_USER\Control Panel\Input Method\EnableHexNumpad
3562 bool wait_WM_CHAR
= false;
3567 wait_WM_CHAR
= false;
3571 WORD vk
= LOWORD(wParam
);
3572 WORD keyFlags
= HIWORD(lParam
);
3577 if (state
.wait_WM_CHAR
&& MapVirtualKeyW(LOBYTE(keyFlags
), MAPVK_VSC_TO_VK
) == VK_MENU
)
3580 // Ignore it - it is synthetized (incorrect, truncated) character from system
3589 if (!(keyFlags
& KF_REPEAT
))
3591 state
.started
= true;
3592 return false; // This must be processed further - e.g., to show accelerators
3598 if (keyFlags
& KF_EXTENDED
)
3599 break; // NUMPAD numeric keys are *not* considered extended
3601 vk
= NumPadFromArrows(vk
);
3602 if (vk
>= VK_NUMPAD0
&& vk
<= VK_NUMPAD9
)
3611 if (keyFlags
& KF_EXTENDED
)
3612 break; // NUMPAD numeric keys are *not* considered extended
3614 vk
= NumPadFromArrows(vk
);
3615 if (vk
>= VK_NUMPAD0
&& vk
<= VK_NUMPAD9
)
3618 state
.ch
+= vk
- VK_NUMPAD0
;
3625 if (vk
== VK_MENU
&& state
.started
&& state
.ch
)
3627 sal_UCS4 ch
= state
.ch
;
3629 // Let system provide codes for values below 256
3630 if (ch
>= 256 && rtl::isUnicodeCodePoint(ch
))
3632 PostMessageW(hWnd
, WM_UNICHAR
, ch
, 0);
3633 state
.wait_WM_CHAR
= true;
3644 static bool ImplHandleKeyMsg( HWND hWnd
, UINT nMsg
,
3645 WPARAM wParam
, LPARAM lParam
, LRESULT
& rResult
)
3647 static bool bIgnoreCharMsg
= false;
3648 static WPARAM nDeadChar
= 0;
3649 static WPARAM nLastVKChar
= 0;
3650 static sal_uInt16 nLastChar
= 0;
3651 static ModKeyFlags nLastModKeyCode
= ModKeyFlags::NONE
;
3652 static bool bWaitForModKeyRelease
= false;
3653 sal_uInt16 nRepeat
= LOWORD( lParam
);
3656 sal_uInt16 nModCode
= 0;
3658 // this key might have been relayed by SysChild and thus
3659 // may not be processed twice
3660 GetSalData()->mnSalObjWantKeyEvt
= 0;
3662 if ( nMsg
== WM_DEADCHAR
)
3668 if (HandleAltNumPadCode(hWnd
, nMsg
, wParam
, lParam
))
3669 return true; // no default processing
3671 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3675 // reset the background mode for each text input,
3676 // as some tools such as RichWin may have changed it
3677 if ( pFrame
->mpLocalGraphics
&&
3678 pFrame
->mpLocalGraphics
->getHDC() )
3679 SetBkMode( pFrame
->mpLocalGraphics
->getHDC(), TRANSPARENT
);
3681 // determine modifiers
3682 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3683 nModCode
|= KEY_SHIFT
;
3684 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3685 nModCode
|= KEY_MOD1
;
3686 if (GetKeyState(VK_MENU
) & 0x8000)
3687 nModCode
|= KEY_MOD2
;
3689 if ( (nMsg
== WM_CHAR
) || (nMsg
== WM_SYSCHAR
) )
3693 if ( bIgnoreCharMsg
)
3695 bIgnoreCharMsg
= false;
3696 // #101635# if zero is returned here for WM_SYSCHAR (ALT+<key>) Windows will beep
3697 // because this 'hotkey' was not processed -> better return 1
3698 // except for Alt-SPACE which should always open the sysmenu (#104616#)
3700 // also return zero if a system menubar is available that might process this hotkey
3701 // this also applies to the OLE inplace embedding where we are a child window
3702 if( (GetWindowStyle( hWnd
) & WS_CHILD
) || GetMenu( hWnd
) || (wParam
== 0x20) )
3708 // ignore backspace as a single key, so that
3709 // we do not get problems for combinations w/ a DeadKey
3710 if ( wParam
== 0x08 ) // BACKSPACE
3713 // only "free flying" WM_CHAR messages arrive here, that are
3714 // created by typing an ALT-NUMPAD combination
3715 SalKeyEvent aKeyEvt
;
3717 if ( (wParam
>= '0') && (wParam
<= '9') )
3718 aKeyEvt
.mnCode
= sal::static_int_cast
<sal_uInt16
>(KEYGROUP_NUM
+ wParam
- '0');
3719 else if ( (wParam
>= 'A') && (wParam
<= 'Z') )
3720 aKeyEvt
.mnCode
= sal::static_int_cast
<sal_uInt16
>(KEYGROUP_ALPHA
+ wParam
- 'A');
3721 else if ( (wParam
>= 'a') && (wParam
<= 'z') )
3722 aKeyEvt
.mnCode
= sal::static_int_cast
<sal_uInt16
>(KEYGROUP_ALPHA
+ wParam
- 'a');
3723 else if ( wParam
== 0x0D ) // RETURN
3724 aKeyEvt
.mnCode
= KEY_RETURN
;
3725 else if ( wParam
== 0x1B ) // ESCAPE
3726 aKeyEvt
.mnCode
= KEY_ESCAPE
;
3727 else if ( wParam
== 0x09 ) // TAB
3728 aKeyEvt
.mnCode
= KEY_TAB
;
3729 else if ( wParam
== 0x20 ) // SPACE
3730 aKeyEvt
.mnCode
= KEY_SPACE
;
3734 aKeyEvt
.mnCode
|= nModCode
;
3735 aKeyEvt
.mnCharCode
= ImplGetCharCode( pFrame
, wParam
);
3736 aKeyEvt
.mnRepeat
= nRepeat
;
3738 UnsetAltIfAltGr(aKeyEvt
, nModCode
);
3739 FlushIMBeforeShortCut(pFrame
, SalEvent::KeyInput
, nModCode
);
3744 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
3745 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
3748 // #i11583#, MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition begins
3749 else if( nMsg
== WM_UNICHAR
)
3751 // If Windows is asking if we accept WM_UNICHAR, return TRUE
3752 if(wParam
== UNICODE_NOCHAR
)
3754 rResult
= TRUE
; // ssa: this will actually return TRUE to windows
3755 return true; // ...but this will only avoid calling the defwindowproc
3758 if (!rtl::isUnicodeCodePoint(wParam
))
3761 SalKeyEvent aKeyEvt
;
3762 aKeyEvt
.mnCode
= nModCode
; // Or should it be 0? - as this is always a character returned
3763 aKeyEvt
.mnRepeat
= 0;
3765 if( wParam
>= Uni_SupplementaryPlanesStart
)
3767 // character is supplementary char in UTF-32 format - must be converted to UTF-16 supplementary pair
3768 aKeyEvt
.mnCharCode
= rtl::getHighSurrogate(wParam
);
3771 pFrame
->CallCallback(SalEvent::KeyInput
, &aKeyEvt
);
3772 pFrame
->CallCallback(SalEvent::KeyUp
, &aKeyEvt
);
3773 wParam
= rtl::getLowSurrogate(wParam
);
3776 aKeyEvt
.mnCharCode
= static_cast<sal_Unicode
>(wParam
);
3780 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
3781 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
3785 // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition ends
3788 // for shift, control and menu we issue a KeyModChange event
3789 if ( (wParam
== VK_SHIFT
) || (wParam
== VK_CONTROL
) || (wParam
== VK_MENU
) )
3791 SalKeyModEvent aModEvt
;
3792 aModEvt
.mbDown
= false; // auto-accelerator feature not supported here.
3793 aModEvt
.mnCode
= nModCode
;
3794 aModEvt
.mnModKeyCode
= ModKeyFlags::NONE
; // no command events will be sent if this member is 0
3796 ModKeyFlags tmpCode
= ModKeyFlags::NONE
;
3797 if( GetKeyState( VK_LSHIFT
) & 0x8000 )
3798 tmpCode
|= ModKeyFlags::LeftShift
;
3799 if( GetKeyState( VK_RSHIFT
) & 0x8000 )
3800 tmpCode
|= ModKeyFlags::RightShift
;
3801 if( GetKeyState( VK_LCONTROL
) & 0x8000 )
3802 tmpCode
|= ModKeyFlags::LeftMod1
;
3803 if( GetKeyState( VK_RCONTROL
) & 0x8000 )
3804 tmpCode
|= ModKeyFlags::RightMod1
;
3805 if( GetKeyState( VK_LMENU
) & 0x8000 )
3806 tmpCode
|= ModKeyFlags::LeftMod2
;
3807 if( GetKeyState( VK_RMENU
) & 0x8000 )
3808 tmpCode
|= ModKeyFlags::RightMod2
;
3810 if( tmpCode
< nLastModKeyCode
)
3812 aModEvt
.mnModKeyCode
= nLastModKeyCode
;
3813 nLastModKeyCode
= ModKeyFlags::NONE
;
3814 bWaitForModKeyRelease
= true;
3818 if( !bWaitForModKeyRelease
)
3819 nLastModKeyCode
= tmpCode
;
3822 if( tmpCode
== ModKeyFlags::NONE
)
3823 bWaitForModKeyRelease
= false;
3825 return pFrame
->CallCallback( SalEvent::KeyModChange
, &aModEvt
);
3829 SalKeyEvent aKeyEvt
;
3832 bool bCharPeek
= false;
3833 UINT nCharMsg
= WM_CHAR
;
3834 bool bKeyUp
= (nMsg
== WM_KEYUP
) || (nMsg
== WM_SYSKEYUP
);
3836 nLastModKeyCode
= ModKeyFlags::NONE
; // make sure no modkey messages are sent if they belong to a hotkey (see above)
3837 aKeyEvt
.mnCharCode
= 0;
3838 aKeyEvt
.mnCode
= ImplSalGetKeyCode( wParam
);
3841 // check for charcode
3842 // Get the related WM_CHAR message using PeekMessage, if available.
3843 // The WM_CHAR message is always at the beginning of the
3844 // message queue. Also it is made certain that there is always only
3845 // one WM_CHAR message in the queue.
3846 bCharPeek
= PeekMessageW( &aCharMsg
, hWnd
,
3847 WM_CHAR
, WM_CHAR
, PM_NOREMOVE
| PM_NOYIELD
);
3848 if ( bCharPeek
&& (nDeadChar
== aCharMsg
.wParam
) )
3853 if ( wParam
== VK_BACK
)
3855 PeekMessageW( &aCharMsg
, hWnd
,
3856 nCharMsg
, nCharMsg
, PM_REMOVE
| PM_NOYIELD
);
3864 bCharPeek
= PeekMessageW( &aCharMsg
, hWnd
,
3865 WM_SYSCHAR
, WM_SYSCHAR
, PM_NOREMOVE
| PM_NOYIELD
);
3866 nCharMsg
= WM_SYSCHAR
;
3870 aKeyEvt
.mnCharCode
= ImplGetCharCode( pFrame
, aCharMsg
.wParam
);
3872 aKeyEvt
.mnCharCode
= 0;
3874 nLastChar
= aKeyEvt
.mnCharCode
;
3875 nLastVKChar
= wParam
;
3879 if ( wParam
== nLastVKChar
)
3881 aKeyEvt
.mnCharCode
= nLastChar
;
3887 if ( aKeyEvt
.mnCode
|| aKeyEvt
.mnCharCode
)
3890 nEvent
= SalEvent::KeyUp
;
3892 nEvent
= SalEvent::KeyInput
;
3894 aKeyEvt
.mnCode
|= nModCode
;
3895 aKeyEvt
.mnRepeat
= nRepeat
;
3897 UnsetAltIfAltGr(aKeyEvt
, nModCode
);
3898 FlushIMBeforeShortCut(pFrame
, nEvent
, nModCode
);
3900 bIgnoreCharMsg
= bCharPeek
;
3901 bool nRet
= pFrame
->CallCallback( nEvent
, &aKeyEvt
);
3902 // independent part only reacts on keyup but Windows does not send
3903 // keyup for VK_HANJA
3904 if( aKeyEvt
.mnCode
== KEY_HANGUL_HANJA
)
3905 nRet
= pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
3907 bIgnoreCharMsg
= false;
3909 // char-message, then remove or ignore
3915 PeekMessageW( &aCharMsg
, hWnd
,
3916 nCharMsg
, nCharMsg
, PM_REMOVE
| PM_NOYIELD
);
3919 bIgnoreCharMsg
= true;
3930 bool ImplHandleSalObjKeyMsg( HWND hWnd
, UINT nMsg
,
3931 WPARAM wParam
, LPARAM lParam
)
3933 if ( (nMsg
== WM_KEYDOWN
) || (nMsg
== WM_KEYUP
) )
3935 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3939 sal_uInt16 nRepeat
= LOWORD( lParam
)-1;
3940 sal_uInt16 nModCode
= 0;
3942 // determine modifiers
3943 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3944 nModCode
|= KEY_SHIFT
;
3945 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3946 nModCode
|= KEY_MOD1
;
3947 if ( GetKeyState( VK_MENU
) & 0x8000 )
3948 nModCode
|= KEY_MOD2
;
3950 if ( (wParam
!= VK_SHIFT
) && (wParam
!= VK_CONTROL
) && (wParam
!= VK_MENU
) )
3952 SalKeyEvent aKeyEvt
;
3956 aKeyEvt
.mnCode
= ImplSalGetKeyCode( wParam
);
3957 aKeyEvt
.mnCharCode
= 0;
3959 if ( aKeyEvt
.mnCode
)
3961 if (nMsg
== WM_KEYUP
)
3962 nEvent
= SalEvent::KeyUp
;
3964 nEvent
= SalEvent::KeyInput
;
3966 aKeyEvt
.mnCode
|= nModCode
;
3967 aKeyEvt
.mnRepeat
= nRepeat
;
3968 bool nRet
= pFrame
->CallCallback( nEvent
, &aKeyEvt
);
3979 bool ImplHandleSalObjSysCharMsg( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
3981 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3985 sal_uInt16 nRepeat
= LOWORD( lParam
)-1;
3986 sal_uInt16 nModCode
= 0;
3987 sal_uInt16 cKeyCode
= static_cast<sal_uInt16
>(wParam
);
3989 // determine modifiers
3990 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3991 nModCode
|= KEY_SHIFT
;
3992 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3993 nModCode
|= KEY_MOD1
;
3994 nModCode
|= KEY_MOD2
;
3996 // assemble KeyEvent
3997 SalKeyEvent aKeyEvt
;
3998 if ( (cKeyCode
>= 48) && (cKeyCode
<= 57) )
3999 aKeyEvt
.mnCode
= KEY_0
+(cKeyCode
-48);
4000 else if ( (cKeyCode
>= 65) && (cKeyCode
<= 90) )
4001 aKeyEvt
.mnCode
= KEY_A
+(cKeyCode
-65);
4002 else if ( (cKeyCode
>= 97) && (cKeyCode
<= 122) )
4003 aKeyEvt
.mnCode
= KEY_A
+(cKeyCode
-97);
4006 aKeyEvt
.mnCode
|= nModCode
;
4007 aKeyEvt
.mnCharCode
= ImplGetCharCode( pFrame
, cKeyCode
);
4008 aKeyEvt
.mnRepeat
= nRepeat
;
4009 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
4010 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
4016 enum class DeferPolicy
4024 // Remember to release the solar mutex on success!
4025 static WinSalFrame
* ProcessOrDeferMessage( HWND hWnd
, INT nMsg
, WPARAM pWParam
= 0,
4026 DeferPolicy eCanDefer
= DeferPolicy::Allowed
)
4028 bool bFailedCondition
= false, bGotMutex
= false;
4029 WinSalFrame
* pFrame
= nullptr;
4031 if ( DeferPolicy::Blocked
== eCanDefer
)
4032 assert( (DeferPolicy::Blocked
== eCanDefer
) && (nMsg
== 0) && (pWParam
== 0) );
4034 assert( (DeferPolicy::Allowed
== eCanDefer
) && (nMsg
!= 0) );
4036 if ( DeferPolicy::Blocked
== eCanDefer
)
4038 ImplSalYieldMutexAcquireWithWait();
4041 else if ( !(bGotMutex
= ImplSalYieldMutexTryToAcquire()) )
4042 bFailedCondition
= true;
4044 if ( !bFailedCondition
)
4046 pFrame
= GetWindowPtr( hWnd
);
4047 bFailedCondition
= pFrame
== nullptr;
4050 if ( bFailedCondition
)
4053 ImplSalYieldMutexRelease();
4054 if ( DeferPolicy::Allowed
== eCanDefer
)
4056 bool const ret
= PostMessageW(hWnd
, nMsg
, pWParam
, 0);
4057 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
4066 enum class PostedState
4074 static bool ImplHandlePostPaintMsg( HWND hWnd
, RECT
* pRect
,
4075 PostedState eProcessed
= PostedState::IsPosted
)
4078 if ( PostedState::IsInitial
== eProcessed
)
4080 pMsgRect
= new RECT
;
4081 CopyRect( pMsgRect
, pRect
);
4086 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, SAL_MSG_POSTPAINT
,
4087 reinterpret_cast<WPARAM
>(pMsgRect
) );
4090 SalPaintEvent
aPEvt( pRect
->left
, pRect
->top
, pRect
->right
-pRect
->left
, pRect
->bottom
-pRect
->top
);
4091 pFrame
->CallCallback( SalEvent::Paint
, &aPEvt
);
4092 ImplSalYieldMutexRelease();
4093 if ( PostedState::IsPosted
== eProcessed
)
4097 return (pFrame
!= nullptr);
4100 static bool ImplHandlePaintMsg( HWND hWnd
)
4102 bool bPaintSuccessful
= false;
4104 // even without the Yield mutex, we can still change the clip region,
4105 // because other threads don't use the Yield mutex
4106 // --> see AcquireGraphics()
4108 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4111 // clip region must be set, as we don't get a proper
4112 // bounding rectangle otherwise
4113 WinSalGraphics
*pGraphics
= pFrame
->mpLocalGraphics
;
4114 bool bHasClipRegion
= pGraphics
&&
4115 pGraphics
->getHDC() && pGraphics
->getRegion();
4116 if ( bHasClipRegion
)
4117 SelectClipRgn( pGraphics
->getHDC(), nullptr );
4119 // according to Windows documentation one shall check first if
4120 // there really is a paint-region
4123 bool bHasPaintRegion
= GetUpdateRect( hWnd
, nullptr, FALSE
);
4124 if ( bHasPaintRegion
)
4126 // call BeginPaint/EndPaint to query the paint rect and use
4127 // this information in the (deferred) paint
4128 BeginPaint( hWnd
, &aPs
);
4129 CopyRect( &aUpdateRect
, &aPs
.rcPaint
);
4132 // reset clip region
4133 if ( bHasClipRegion
)
4134 SelectClipRgn( pGraphics
->getHDC(), pGraphics
->getRegion() );
4137 if ( bHasPaintRegion
)
4139 bPaintSuccessful
= ImplHandlePostPaintMsg(
4140 hWnd
, &aUpdateRect
, PostedState::IsInitial
);
4141 EndPaint( hWnd
, &aPs
);
4143 else // if there is nothing to paint, the paint is successful
4144 bPaintSuccessful
= true;
4147 return bPaintSuccessful
;
4150 static void SetMaximizedFrameGeometry( HWND hWnd
, WinSalFrame
* pFrame
, RECT
* pParentRect
)
4152 // calculate and set frame geometry of a maximized window - useful if the window is still hidden
4154 // dualmonitor support:
4155 // Get screensize of the monitor with the mouse pointer
4161 GetCursorPos( &pt
);
4162 aRectMouse
.left
= pt
.x
;
4163 aRectMouse
.top
= pt
.y
;
4164 aRectMouse
.right
= pt
.x
+2;
4165 aRectMouse
.bottom
= pt
.y
+2;
4166 pParentRect
= &aRectMouse
;
4170 ImplSalGetWorkArea( hWnd
, &aRect
, pParentRect
);
4172 // a maximized window has no other borders than the caption
4173 pFrame
->maGeometry
.setDecorations(0, pFrame
->mbCaption
? GetSystemMetrics(SM_CYCAPTION
) : 0, 0, 0);
4175 aRect
.top
+= pFrame
->maGeometry
.topDecoration();
4176 pFrame
->maGeometry
.setPos({ aRect
.left
, aRect
.top
});
4177 SetGeometrySize(pFrame
->maGeometry
, { aRect
.right
- aRect
.left
, aRect
.bottom
- aRect
.top
});
4180 static void UpdateFrameGeometry(WinSalFrame
* pFrame
)
4184 const HWND hWnd
= pFrame
->mhWnd
;
4187 GetWindowRect( hWnd
, &aRect
);
4188 pFrame
->maGeometry
.setPosSize({ 0, 0 }, { 0, 0 });
4189 pFrame
->maGeometry
.setDecorations(0, 0, 0, 0);
4190 pFrame
->maGeometry
.setScreen(0);
4192 if ( IsIconic( hWnd
) )
4198 ClientToScreen(hWnd
, &aPt
);
4199 int cx
= aPt
.x
- aRect
.left
;
4201 pFrame
->maGeometry
.setDecorations(cx
, aPt
.y
- aRect
.top
, cx
, 0);
4202 pFrame
->maGeometry
.setPos({ aPt
.x
, aPt
.y
});
4205 GetClientRect( hWnd
, &aInnerRect
);
4206 if( aInnerRect
.right
)
4208 // improve right decoration
4209 aPt
.x
=aInnerRect
.right
;
4210 aPt
.y
=aInnerRect
.top
;
4211 ClientToScreen(hWnd
, &aPt
);
4212 pFrame
->maGeometry
.setRightDecoration(aRect
.right
- aPt
.x
);
4214 if( aInnerRect
.bottom
) // may be zero if window was not shown yet
4215 pFrame
->maGeometry
.setBottomDecoration(aRect
.bottom
- aPt
.y
- aInnerRect
.bottom
);
4217 // bottom border is typically the same as left/right
4218 pFrame
->maGeometry
.setBottomDecoration(pFrame
->maGeometry
.leftDecoration());
4220 int nWidth
= aRect
.right
- aRect
.left
4221 - pFrame
->maGeometry
.rightDecoration() - pFrame
->maGeometry
.leftDecoration();
4222 int nHeight
= aRect
.bottom
- aRect
.top
4223 - pFrame
->maGeometry
.bottomDecoration() - pFrame
->maGeometry
.topDecoration();
4224 SetGeometrySize(pFrame
->maGeometry
, { nWidth
, nHeight
});
4225 pFrame
->updateScreenNumber();
4228 static void ImplCallClosePopupsHdl( HWND hWnd
)
4230 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4233 pFrame
->CallCallback( SalEvent::ClosePopups
, nullptr );
4237 static void ImplCallMoveHdl(HWND hWnd
)
4239 WinSalFrame
* pFrame
= ProcessOrDeferMessage(hWnd
, SAL_MSG_POSTMOVE
);
4243 pFrame
->CallCallback(SalEvent::Move
, nullptr);
4245 ImplSalYieldMutexRelease();
4248 static void ImplHandleMoveMsg(HWND hWnd
, LPARAM lParam
)
4250 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4254 UpdateFrameGeometry(pFrame
);
4259 assert(IsIconic(hWnd
) || (pFrame
->maGeometry
.x() == static_cast<sal_Int16
>(LOWORD(lParam
))));
4260 assert(IsIconic(hWnd
) || (pFrame
->maGeometry
.y() == static_cast<sal_Int16
>(HIWORD(lParam
))));
4262 if (GetWindowStyle(hWnd
) & WS_VISIBLE
)
4263 pFrame
->mbDefPos
= false;
4265 // protect against recursion
4266 if (!pFrame
->mbInMoveMsg
)
4268 // adjust window again for FullScreenMode
4269 pFrame
->mbInMoveMsg
= true;
4270 if (pFrame
->isFullScreen())
4271 ImplSalFrameFullScreenPos(pFrame
);
4272 pFrame
->mbInMoveMsg
= false;
4275 pFrame
->UpdateFrameState();
4277 ImplCallMoveHdl(hWnd
);
4280 static void ImplCallSizeHdl( HWND hWnd
)
4282 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, SAL_MSG_POSTCALLSIZE
);
4286 pFrame
->CallCallback(SalEvent::Resize
, nullptr);
4287 // to avoid double Paints by VCL and SAL
4288 if (IsWindowVisible(hWnd
) && !pFrame
->mbInShow
)
4291 ImplSalYieldMutexRelease();
4294 static void ImplHandleSizeMsg(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
4296 if ((wParam
== SIZE_MAXSHOW
) || (wParam
== SIZE_MAXHIDE
))
4299 WinSalFrame
* pFrame
= GetWindowPtr(hWnd
);
4303 UpdateFrameGeometry(pFrame
);
4308 assert(pFrame
->maGeometry
.width() == static_cast<sal_Int16
>(LOWORD(lParam
)));
4309 assert(pFrame
->maGeometry
.height() == static_cast<sal_Int16
>(HIWORD(lParam
)));
4311 pFrame
->UpdateFrameState();
4313 ImplCallSizeHdl(hWnd
);
4315 WinSalTimer
* pTimer
= static_cast<WinSalTimer
*>(ImplGetSVData()->maSchedCtx
.mpSalTimer
);
4317 pTimer
->SetForceRealTimer(true);
4320 static void ImplHandleFocusMsg( HWND hWnd
)
4322 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, SAL_MSG_POSTFOCUS
);
4325 const ::comphelper::ScopeGuard
aScopeGuard([](){ ImplSalYieldMutexRelease(); });
4327 if (WinSalFrame::mbInReparent
)
4330 const bool bGotFocus
= ::GetFocus() == hWnd
;
4333 if (IsWindowVisible(hWnd
) && !pFrame
->mbInShow
)
4336 // do we support IME?
4337 if (pFrame
->mbIME
&& pFrame
->mhDefIMEContext
)
4339 UINT nImeProps
= ImmGetProperty(GetKeyboardLayout(0), IGP_PROPERTY
);
4340 pFrame
->mbSpezIME
= (nImeProps
& IME_PROP_SPECIAL_UI
) != 0;
4341 pFrame
->mbAtCursorIME
= (nImeProps
& IME_PROP_AT_CARET
) != 0;
4342 pFrame
->mbHandleIME
= !pFrame
->mbSpezIME
;
4346 pFrame
->CallCallback(bGotFocus
? SalEvent::GetFocus
: SalEvent::LoseFocus
, nullptr);
4349 static void ImplHandleCloseMsg( HWND hWnd
)
4351 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, WM_CLOSE
);
4354 pFrame
->CallCallback( SalEvent::Close
, nullptr );
4355 ImplSalYieldMutexRelease();
4359 static bool ImplHandleShutDownMsg( HWND hWnd
)
4362 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, 0, 0, DeferPolicy::Blocked
);
4365 nRet
= pFrame
->CallCallback( SalEvent::Shutdown
, nullptr );
4366 ImplSalYieldMutexRelease();
4371 static void ImplHandleSettingsChangeMsg( HWND hWnd
, UINT nMsg
,
4372 WPARAM wParam
, LPARAM lParam
)
4374 SalEvent nSalEvent
= SalEvent::SettingsChanged
;
4376 if ( nMsg
== WM_DEVMODECHANGE
)
4377 nSalEvent
= SalEvent::PrinterChanged
;
4378 else if ( nMsg
== WM_DISPLAYCHANGE
)
4379 nSalEvent
= SalEvent::DisplayChanged
;
4380 else if ( nMsg
== WM_FONTCHANGE
)
4381 nSalEvent
= SalEvent::FontChanged
;
4382 else if ( nMsg
== WM_WININICHANGE
)
4386 if ( ImplSalWICompareAscii( reinterpret_cast<const wchar_t*>(lParam
), "devices" ) == 0 )
4387 nSalEvent
= SalEvent::PrinterChanged
;
4391 if ( nMsg
== WM_SETTINGCHANGE
)
4393 if ( wParam
== SPI_SETWHEELSCROLLLINES
)
4394 aSalShlData
.mnWheelScrollLines
= ImplSalGetWheelScrollLines();
4395 else if( wParam
== SPI_SETWHEELSCROLLCHARS
)
4396 aSalShlData
.mnWheelScrollChars
= ImplSalGetWheelScrollChars();
4397 UpdateDarkMode(hWnd
);
4398 GetSalData()->mbThemeChanged
= true;
4401 if ( WM_SYSCOLORCHANGE
== nMsg
&& GetSalData()->mhDitherPal
)
4402 ImplUpdateSysColorEntries();
4404 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, 0, 0, DeferPolicy::Blocked
);
4408 if (((nMsg
== WM_DISPLAYCHANGE
) || (nMsg
== WM_WININICHANGE
)) && pFrame
->isFullScreen())
4409 ImplSalFrameFullScreenPos(pFrame
);
4411 pFrame
->CallCallback(nSalEvent
, nullptr);
4413 ImplSalYieldMutexRelease();
4416 static void ImplHandleUserEvent( HWND hWnd
, LPARAM lParam
)
4418 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, 0, 0, DeferPolicy::Blocked
);
4421 pFrame
->CallCallback( SalEvent::UserEvent
, reinterpret_cast<void*>(lParam
) );
4422 ImplSalYieldMutexRelease();
4426 static void ImplHandleForcePalette( HWND hWnd
)
4428 SalData
* pSalData
= GetSalData();
4429 HPALETTE hPal
= pSalData
->mhDitherPal
;
4433 WinSalFrame
* pFrame
= ProcessOrDeferMessage(hWnd
, SAL_MSG_FORCEPALETTE
);
4436 const ::comphelper::ScopeGuard
aScopeGuard([](){ ImplSalYieldMutexRelease(); });
4438 WinSalGraphics
* pGraphics
= pFrame
->mpLocalGraphics
;
4439 if (!pGraphics
|| !pGraphics
->getHDC() || !pGraphics
->getDefPal()
4440 || (pGraphics
->setPalette(hPal
, FALSE
) == GDI_ERROR
))
4443 InvalidateRect(hWnd
, nullptr, FALSE
);
4445 pFrame
->CallCallback(SalEvent::DisplayChanged
, nullptr);
4448 static LRESULT
ImplHandlePalette( bool bFrame
, HWND hWnd
, UINT nMsg
,
4449 WPARAM wParam
, LPARAM lParam
, bool& rDef
)
4451 SalData
* pSalData
= GetSalData();
4452 HPALETTE hPal
= pSalData
->mhDitherPal
;
4457 if ( pSalData
->mbInPalChange
)
4460 if ( (nMsg
== WM_PALETTECHANGED
) || (nMsg
== SAL_MSG_POSTPALCHANGED
) )
4462 if ( reinterpret_cast<HWND
>(wParam
) == hWnd
)
4466 bool bReleaseMutex
= false;
4467 if ( (nMsg
== WM_QUERYNEWPALETTE
) || (nMsg
== WM_PALETTECHANGED
) )
4469 // as Windows can send these messages also, we have to use
4470 // the Solar semaphore
4471 if ( ImplSalYieldMutexTryToAcquire() )
4472 bReleaseMutex
= true;
4473 else if ( nMsg
== WM_QUERYNEWPALETTE
)
4475 bool const ret
= PostMessageW(hWnd
, SAL_MSG_POSTQUERYNEWPAL
, wParam
, lParam
);
4476 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
4478 else /* ( nMsg == WM_PALETTECHANGED ) */
4480 bool const ret
= PostMessageW(hWnd
, SAL_MSG_POSTPALCHANGED
, wParam
, lParam
);
4481 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
4485 WinSalVirtualDevice
*pTempVD
;
4486 WinSalFrame
* pTempFrame
;
4487 WinSalGraphics
* pGraphics
;
4489 HPALETTE hOldPal
= nullptr;
4490 UINT nCols
= GDI_ERROR
;
4493 pSalData
->mbInPalChange
= true;
4495 // reset all palettes in VirDevs and Frames
4496 pTempVD
= pSalData
->mpFirstVD
;
4499 pGraphics
= pTempVD
->getGraphics();
4500 pGraphics
->setPalette(nullptr);
4501 pTempVD
= pTempVD
->getNext();
4503 pTempFrame
= pSalData
->mpFirstFrame
;
4504 while ( pTempFrame
)
4506 pGraphics
= pTempFrame
->mpLocalGraphics
;
4507 pGraphics
->setPalette(nullptr);
4508 pTempFrame
= pTempFrame
->mpNextFrame
;
4511 // re-initialize palette
4512 WinSalFrame
* pFrame
= nullptr;
4514 pFrame
= GetWindowPtr( hWnd
);
4516 UnrealizeObject(hPal
);
4517 const bool bStdDC
= pFrame
&& pFrame
->mpLocalGraphics
&& pFrame
->mpLocalGraphics
->getHDC();
4521 hOldPal
= SelectPalette(hDC
, hPal
, TRUE
);
4523 nCols
= RealizePalette(hDC
);
4527 hDC
= pFrame
->mpLocalGraphics
->getHDC();
4528 nCols
= pFrame
->mpLocalGraphics
->setPalette(hPal
);
4531 bUpdate
= nCols
!= 0 && nCols
!= GDI_ERROR
;
4536 SelectPalette(hDC
, hOldPal
, TRUE
);
4537 ReleaseDC( hWnd
, hDC
);
4540 // reset all palettes in VirDevs and Frames
4541 pTempVD
= pSalData
->mpFirstVD
;
4544 pGraphics
= pTempVD
->getGraphics();
4545 if ( pGraphics
->getDefPal() )
4546 pGraphics
->setPalette(hPal
);
4547 pTempVD
= pTempVD
->getNext();
4550 pTempFrame
= pSalData
->mpFirstFrame
;
4551 while ( pTempFrame
)
4553 if ( pTempFrame
!= pFrame
)
4555 pGraphics
= pTempFrame
->mpLocalGraphics
;
4556 if (pGraphics
&& pGraphics
->getDefPal())
4558 UINT nRes
= pGraphics
->setPalette(hPal
);
4559 if (nRes
!= 0 && nRes
!= GDI_ERROR
)
4563 pTempFrame
= pTempFrame
->mpNextFrame
;
4566 // if colors changed, update the window
4569 pTempFrame
= pSalData
->mpFirstFrame
;
4570 while ( pTempFrame
)
4572 pGraphics
= pTempFrame
->mpLocalGraphics
;
4573 if (pGraphics
&& pGraphics
->getDefPal())
4575 InvalidateRect( pTempFrame
->mhWnd
, nullptr, FALSE
);
4576 UpdateWindow( pTempFrame
->mhWnd
);
4577 pTempFrame
->CallCallback( SalEvent::DisplayChanged
, nullptr );
4579 pTempFrame
= pTempFrame
->mpNextFrame
;
4583 pSalData
->mbInPalChange
= false;
4585 if ( bReleaseMutex
)
4586 ImplSalYieldMutexRelease();
4588 if ( nMsg
== WM_PALETTECHANGED
)
4594 static bool ImplHandleMinMax( HWND hWnd
, LPARAM lParam
)
4598 if ( ImplSalYieldMutexTryToAcquire() )
4600 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4603 MINMAXINFO
* pMinMax
= reinterpret_cast<MINMAXINFO
*>(lParam
);
4605 if (pFrame
->isFullScreen())
4611 ImplSalCalcFullScreenSize( pFrame
, nX
, nY
, nDX
, nDY
);
4613 if ( pMinMax
->ptMaxPosition
.x
> nX
)
4614 pMinMax
->ptMaxPosition
.x
= nX
;
4615 if ( pMinMax
->ptMaxPosition
.y
> nY
)
4616 pMinMax
->ptMaxPosition
.y
= nY
;
4618 if ( pMinMax
->ptMaxSize
.x
< nDX
)
4619 pMinMax
->ptMaxSize
.x
= nDX
;
4620 if ( pMinMax
->ptMaxSize
.y
< nDY
)
4621 pMinMax
->ptMaxSize
.y
= nDY
;
4622 if ( pMinMax
->ptMaxTrackSize
.x
< nDX
)
4623 pMinMax
->ptMaxTrackSize
.x
= nDX
;
4624 if ( pMinMax
->ptMaxTrackSize
.y
< nDY
)
4625 pMinMax
->ptMaxTrackSize
.y
= nDY
;
4627 pMinMax
->ptMinTrackSize
.x
= nDX
;
4628 pMinMax
->ptMinTrackSize
.y
= nDY
;
4633 if ( pFrame
->mnMinWidth
|| pFrame
->mnMinHeight
)
4635 int nWidth
= pFrame
->mnMinWidth
;
4636 int nHeight
= pFrame
->mnMinHeight
;
4638 ImplSalAddBorder( pFrame
, nWidth
, nHeight
);
4640 if ( pMinMax
->ptMinTrackSize
.x
< nWidth
)
4641 pMinMax
->ptMinTrackSize
.x
= nWidth
;
4642 if ( pMinMax
->ptMinTrackSize
.y
< nHeight
)
4643 pMinMax
->ptMinTrackSize
.y
= nHeight
;
4646 if ( pFrame
->mnMaxWidth
|| pFrame
->mnMaxHeight
)
4648 int nWidth
= pFrame
->mnMaxWidth
;
4649 int nHeight
= pFrame
->mnMaxHeight
;
4651 ImplSalAddBorder( pFrame
, nWidth
, nHeight
);
4653 if( nWidth
> 0 && nHeight
> 0 ) // protect against int overflow due to INT_MAX initialisation
4655 if ( pMinMax
->ptMaxTrackSize
.x
> nWidth
)
4656 pMinMax
->ptMaxTrackSize
.x
= nWidth
;
4657 if ( pMinMax
->ptMaxTrackSize
.y
> nHeight
)
4658 pMinMax
->ptMaxTrackSize
.y
= nHeight
;
4663 ImplSalYieldMutexRelease();
4669 // retrieves the SalMenuItem pointer from a hMenu
4670 // the pointer is stored in every item, so if no position
4671 // is specified we just use the first item (ie, pos=0)
4672 // if bByPosition is false then nPos denotes a menu id instead of a position
4673 static WinSalMenuItem
* ImplGetSalMenuItem( HMENU hMenu
, UINT nPos
, bool bByPosition
=true )
4675 MENUITEMINFOW mi
= {};
4676 mi
.cbSize
= sizeof( mi
);
4677 mi
.fMask
= MIIM_DATA
;
4678 if( !GetMenuItemInfoW( hMenu
, nPos
, bByPosition
, &mi
) )
4679 SAL_WARN("vcl", "GetMenuItemInfoW failed: " << WindowsErrorString(GetLastError()));
4681 return reinterpret_cast<WinSalMenuItem
*>(mi
.dwItemData
);
4684 // returns the index of the currently selected item if any or -1
4685 static int ImplGetSelectedIndex( HMENU hMenu
)
4687 MENUITEMINFOW mi
= {};
4688 mi
.cbSize
= sizeof( mi
);
4689 mi
.fMask
= MIIM_STATE
;
4690 int n
= GetMenuItemCount( hMenu
);
4693 for(int i
=0; i
<n
; i
++ )
4695 if( !GetMenuItemInfoW( hMenu
, i
, TRUE
, &mi
) )
4696 SAL_WARN( "vcl", "GetMenuItemInfoW failed: " << WindowsErrorString( GetLastError() ) );
4699 if( mi
.fState
& MFS_HILITE
)
4707 static LRESULT
ImplMenuChar( HWND
, WPARAM wParam
, LPARAM lParam
)
4709 LRESULT nRet
= MNC_IGNORE
;
4710 HMENU hMenu
= reinterpret_cast<HMENU
>(lParam
);
4711 OUString
aMnemonic( "&" + OUStringChar(static_cast<sal_Unicode
>(LOWORD(wParam
))) );
4712 aMnemonic
= aMnemonic
.toAsciiLowerCase(); // we only have ascii mnemonics
4714 // search the mnemonic in the current menu
4715 int nItemCount
= GetMenuItemCount( hMenu
);
4718 int idxSelected
= ImplGetSelectedIndex( hMenu
);
4719 int idx
= idxSelected
!= -1 ? idxSelected
+1 : 0; // if duplicate mnemonics cycle through menu
4720 for( int i
=0; i
< nItemCount
; i
++, idx
++ )
4722 WinSalMenuItem
* pSalMenuItem
= ImplGetSalMenuItem( hMenu
, idx
% nItemCount
);
4725 OUString aStr
= pSalMenuItem
->mText
;
4726 aStr
= aStr
.toAsciiLowerCase();
4727 if( aStr
.indexOf( aMnemonic
) != -1 )
4729 if( idxFound
== -1 )
4730 idxFound
= idx
% nItemCount
;
4732 break; // duplicate found
4736 nRet
= MAKELRESULT( idxFound
, MNC_EXECUTE
);
4738 // duplicate mnemonics, just select the next occurrence
4739 nRet
= MAKELRESULT( idxFound
, MNC_SELECT
);
4744 static LRESULT
ImplMeasureItem( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
4749 // request was sent by a menu
4751 MEASUREITEMSTRUCT
*pMI
= reinterpret_cast<LPMEASUREITEMSTRUCT
>(lParam
);
4752 if( pMI
->CtlType
!= ODT_MENU
)
4755 WinSalMenuItem
*pSalMenuItem
= reinterpret_cast<WinSalMenuItem
*>(pMI
->itemData
);
4759 HDC hdc
= GetDC( hWnd
);
4762 NONCLIENTMETRICSW ncm
= {};
4763 ncm
.cbSize
= sizeof( ncm
);
4764 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0 );
4766 // Assume every menu item can be default and printed bold
4767 //ncm.lfMenuFont.lfWeight = FW_BOLD;
4769 HFONT hfntOld
= static_cast<HFONT
>(SelectObject(hdc
, CreateFontIndirectW( &ncm
.lfMenuFont
)));
4771 // menu text and accelerator
4772 OUString
aStr(pSalMenuItem
->mText
);
4773 if( pSalMenuItem
->mAccelText
.getLength() )
4775 aStr
+= " " + pSalMenuItem
->mAccelText
;
4777 GetTextExtentPoint32W( hdc
, o3tl::toW(aStr
.getStr()),
4778 aStr
.getLength(), &strSize
);
4781 Size
bmpSize( 16, 16 );
4782 //if( pSalMenuItem->maBitmap )
4783 // bmpSize = pSalMenuItem->maBitmap.GetSizePixel();
4786 Size
checkSize( GetSystemMetrics( SM_CXMENUCHECK
), GetSystemMetrics( SM_CYMENUCHECK
) );
4788 pMI
->itemWidth
= checkSize
.Width() + 3 + bmpSize
.Width() + 3 + strSize
.cx
;
4789 pMI
->itemHeight
= std::max( std::max( checkSize
.Height(), bmpSize
.Height() ), tools::Long(strSize
.cy
) );
4790 pMI
->itemHeight
+= 4;
4792 DeleteObject( SelectObject(hdc
, hfntOld
) );
4793 ReleaseDC( hWnd
, hdc
);
4799 static LRESULT
ImplDrawItem(HWND
, WPARAM wParam
, LPARAM lParam
)
4804 // request was sent by a menu
4806 DRAWITEMSTRUCT
*pDI
= reinterpret_cast<LPDRAWITEMSTRUCT
>(lParam
);
4807 if( pDI
->CtlType
!= ODT_MENU
)
4810 WinSalMenuItem
*pSalMenuItem
= reinterpret_cast<WinSalMenuItem
*>(pDI
->itemData
);
4814 COLORREF clrPrevText
, clrPrevBkgnd
;
4817 bool fChecked
= (pDI
->itemState
& ODS_CHECKED
);
4818 bool fSelected
= (pDI
->itemState
& ODS_SELECTED
);
4819 bool fDisabled
= (pDI
->itemState
& (ODS_DISABLED
| ODS_GRAYED
));
4821 // Set the appropriate foreground and background colors.
4822 RECT aRect
= pDI
->rcItem
;
4825 clrPrevText
= SetTextColor( pDI
->hDC
, GetSysColor( COLOR_GRAYTEXT
) );
4827 clrPrevText
= SetTextColor( pDI
->hDC
, GetSysColor( fSelected
? COLOR_HIGHLIGHTTEXT
: COLOR_MENUTEXT
) );
4829 DWORD colBackground
= GetSysColor( fSelected
? COLOR_HIGHLIGHT
: COLOR_MENU
);
4830 clrPrevBkgnd
= SetBkColor( pDI
->hDC
, colBackground
);
4832 hbrOld
= static_cast<HBRUSH
>(SelectObject( pDI
->hDC
, CreateSolidBrush( GetBkColor( pDI
->hDC
) ) ));
4835 if(!PatBlt( pDI
->hDC
, aRect
.left
, aRect
.top
, aRect
.right
-aRect
.left
, aRect
.bottom
-aRect
.top
, PATCOPY
))
4836 SAL_WARN("vcl", "PatBlt failed: " << WindowsErrorString(GetLastError()));
4838 int lineHeight
= aRect
.bottom
-aRect
.top
;
4843 int checkWidth
= GetSystemMetrics( SM_CXMENUCHECK
);
4844 int checkHeight
= GetSystemMetrics( SM_CYMENUCHECK
);
4850 r
.right
= checkWidth
;
4851 r
.bottom
= checkWidth
;
4852 HDC memDC
= CreateCompatibleDC( pDI
->hDC
);
4853 HBITMAP memBmp
= CreateCompatibleBitmap( pDI
->hDC
, checkWidth
, checkHeight
);
4854 HBITMAP hOldBmp
= static_cast<HBITMAP
>(SelectObject( memDC
, memBmp
));
4855 DrawFrameControl( memDC
, &r
, DFC_MENU
, DFCS_MENUCHECK
);
4856 BitBlt( pDI
->hDC
, x
, y
+(lineHeight
-checkHeight
)/2, checkWidth
, checkHeight
, memDC
, 0, 0, SRCAND
);
4857 DeleteObject( SelectObject( memDC
, hOldBmp
) );
4862 //Size bmpSize = aBitmap.GetSizePixel();
4863 Size
bmpSize(16, 16);
4864 if( !pSalMenuItem
->maBitmap
.IsEmpty() )
4866 Bitmap
aBitmap( pSalMenuItem
->maBitmap
);
4868 // set transparent pixels to background color
4870 colBackground
= RGB(255,255,255);
4871 aBitmap
.Replace( COL_LIGHTMAGENTA
,
4872 Color( GetRValue(colBackground
),GetGValue(colBackground
),GetBValue(colBackground
) ));
4874 WinSalBitmap
* pSalBmp
= static_cast<WinSalBitmap
*>(aBitmap
.ImplGetSalBitmap().get());
4875 HGLOBAL hDrawDIB
= pSalBmp
->ImplGethDIB();
4879 PBITMAPINFO pBI
= static_cast<PBITMAPINFO
>(GlobalLock( hDrawDIB
));
4880 PBYTE pBits
= reinterpret_cast<PBYTE
>(pBI
) + pBI
->bmiHeader
.biSize
+
4881 WinSalBitmap::ImplGetDIBColorCount( hDrawDIB
) * sizeof( RGBQUAD
);
4883 HBITMAP hBmp
= CreateDIBitmap( pDI
->hDC
, &pBI
->bmiHeader
, CBM_INIT
, pBits
, pBI
, DIB_RGB_COLORS
);
4884 GlobalUnlock( hDrawDIB
);
4886 HBRUSH hbrIcon
= CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT
) );
4887 DrawStateW( pDI
->hDC
, hbrIcon
, nullptr, reinterpret_cast<LPARAM
>(hBmp
), WPARAM(0),
4888 x
, y
+(lineHeight
-bmpSize
.Height())/2, bmpSize
.Width(), bmpSize
.Height(),
4889 DST_BITMAP
| (fDisabled
? (fSelected
? DSS_MONO
: DSS_DISABLED
) : DSS_NORMAL
) );
4891 DeleteObject( hbrIcon
);
4892 DeleteObject( hBmp
);
4896 x
+= bmpSize
.Width() + 3;
4899 NONCLIENTMETRICSW ncm
= {};
4900 ncm
.cbSize
= sizeof( ncm
);
4901 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0 );
4903 // Print default menu entry with bold font
4904 //if ( pDI->itemState & ODS_DEFAULT )
4905 // ncm.lfMenuFont.lfWeight = FW_BOLD;
4907 hfntOld
= static_cast<HFONT
>(SelectObject(pDI
->hDC
, CreateFontIndirectW( &ncm
.lfMenuFont
)));
4910 OUString
aStr( pSalMenuItem
->mText
);
4911 GetTextExtentPoint32W( pDI
->hDC
, o3tl::toW(aStr
.getStr()),
4912 aStr
.getLength(), &strSize
);
4914 if(!DrawStateW( pDI
->hDC
, nullptr, nullptr,
4915 reinterpret_cast<LPARAM
>(aStr
.getStr()),
4916 WPARAM(0), aRect
.left
, aRect
.top
+ (lineHeight
- strSize
.cy
)/2, 0, 0,
4917 DST_PREFIXTEXT
| (fDisabled
&& !fSelected
? DSS_DISABLED
: DSS_NORMAL
) ) )
4918 SAL_WARN("vcl", "DrawStateW failed: " << WindowsErrorString(GetLastError()));
4920 if( pSalMenuItem
->mAccelText
.getLength() )
4923 aStr
= pSalMenuItem
->mAccelText
;
4924 GetTextExtentPoint32W( pDI
->hDC
, o3tl::toW(aStr
.getStr()),
4925 aStr
.getLength(), &strSizeA
);
4927 GetTextMetricsW( pDI
->hDC
, &tm
);
4929 // position the accelerator string to the right but leave space for the
4930 // (potential) submenu arrow (tm.tmMaxCharWidth)
4931 if(!DrawStateW( pDI
->hDC
, nullptr, nullptr,
4932 reinterpret_cast<LPARAM
>(aStr
.getStr()),
4933 WPARAM(0), aRect
.right
-strSizeA
.cx
-tm
.tmMaxCharWidth
, aRect
.top
+ (lineHeight
- strSizeA
.cy
)/2, 0, 0,
4934 DST_TEXT
| (fDisabled
&& !fSelected
? DSS_DISABLED
: DSS_NORMAL
) ) )
4935 SAL_WARN("vcl", "DrawStateW failed: " << WindowsErrorString(GetLastError()));
4938 // Restore the original font and colors.
4939 DeleteObject( SelectObject( pDI
->hDC
, hbrOld
) );
4940 DeleteObject( SelectObject( pDI
->hDC
, hfntOld
) );
4941 SetTextColor(pDI
->hDC
, clrPrevText
);
4942 SetBkColor(pDI
->hDC
, clrPrevBkgnd
);
4947 static bool ImplHandleMenuActivate( HWND hWnd
, WPARAM wParam
, LPARAM
)
4950 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4954 HMENU hMenu
= reinterpret_cast<HMENU
>(wParam
);
4955 // WORD nPos = LOWORD (lParam);
4956 // bool bWindowMenu = (bool) HIWORD(lParam);
4958 // Send activate and deactivate together, so we have not keep track of opened menus
4959 // this will be enough to have the menus updated correctly
4960 SalMenuEvent aMenuEvt
;
4961 WinSalMenuItem
*pSalMenuItem
= ImplGetSalMenuItem( hMenu
, 0 );
4963 aMenuEvt
.mpMenu
= pSalMenuItem
->mpMenu
;
4965 aMenuEvt
.mpMenu
= nullptr;
4967 bool nRet
= pFrame
->CallCallback( SalEvent::MenuActivate
, &aMenuEvt
);
4969 nRet
= pFrame
->CallCallback( SalEvent::MenuDeactivate
, &aMenuEvt
);
4971 pFrame
->mLastActivatedhMenu
= hMenu
;
4976 static bool ImplHandleMenuSelect( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
4979 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4983 WORD nId
= LOWORD(wParam
); // menu item or submenu index
4984 WORD nFlags
= HIWORD(wParam
);
4985 HMENU hMenu
= reinterpret_cast<HMENU
>(lParam
);
4987 // check if we have to process the message
4988 if( !GetSalData()->IsKnownMenuHandle( hMenu
) )
4991 bool bByPosition
= false;
4992 if( nFlags
& MF_POPUP
)
4996 if ( hMenu
&& !pFrame
->mLastActivatedhMenu
)
4998 // we never activated a menu (ie, no WM_INITMENUPOPUP has occurred yet)
4999 // which means this must be the menubar -> send activation/deactivation
5000 SalMenuEvent aMenuEvt
;
5001 WinSalMenuItem
*pSalMenuItem
= ImplGetSalMenuItem( hMenu
, nId
, bByPosition
);
5003 aMenuEvt
.mpMenu
= pSalMenuItem
->mpMenu
;
5005 aMenuEvt
.mpMenu
= nullptr;
5007 nRet
= pFrame
->CallCallback( SalEvent::MenuActivate
, &aMenuEvt
);
5009 nRet
= pFrame
->CallCallback( SalEvent::MenuDeactivate
, &aMenuEvt
);
5011 pFrame
->mLastActivatedhMenu
= hMenu
;
5014 if( !hMenu
&& nFlags
== 0xFFFF )
5016 // all menus are closed, reset activation logic
5017 pFrame
->mLastActivatedhMenu
= nullptr;
5022 // hMenu must be saved, as it is not passed in WM_COMMAND which always occurs after a selection
5023 // if a menu is closed due to a command selection then hMenu is NULL, but WM_COMMAND comes later
5024 // so we must not overwrite it in this case
5025 pFrame
->mSelectedhMenu
= hMenu
;
5027 // send highlight event
5028 if( nFlags
& MF_POPUP
)
5031 // wParam now carries an index instead of an id -> retrieve id
5032 MENUITEMINFOW mi
= {};
5033 mi
.cbSize
= sizeof( mi
);
5035 if( GetMenuItemInfoW( hMenu
, LOWORD(wParam
), TRUE
, &mi
) )
5036 nId
= sal::static_int_cast
<WORD
>(mi
.wID
);
5039 SalMenuEvent aMenuEvt
;
5040 aMenuEvt
.mnId
= nId
;
5041 WinSalMenuItem
*pSalMenuItem
= ImplGetSalMenuItem( hMenu
, nId
, false );
5043 aMenuEvt
.mpMenu
= pSalMenuItem
->mpMenu
;
5045 aMenuEvt
.mpMenu
= nullptr;
5047 nRet
= pFrame
->CallCallback( SalEvent::MenuHighlight
, &aMenuEvt
);
5053 static bool ImplHandleCommand( HWND hWnd
, WPARAM wParam
, LPARAM
)
5055 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5060 if( !HIWORD(wParam
) )
5063 WORD nId
= LOWORD(wParam
);
5064 if( nId
) // zero for separators
5066 SalMenuEvent aMenuEvt
;
5067 aMenuEvt
.mnId
= nId
;
5068 WinSalMenuItem
*pSalMenuItem
= ImplGetSalMenuItem( pFrame
->mSelectedhMenu
, nId
, false );
5070 aMenuEvt
.mpMenu
= pSalMenuItem
->mpMenu
;
5072 aMenuEvt
.mpMenu
= nullptr;
5074 nRet
= pFrame
->CallCallback( SalEvent::MenuCommand
, &aMenuEvt
);
5080 static bool ImplHandleSysCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
5082 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5086 WPARAM nCommand
= wParam
& 0xFFF0;
5088 if (pFrame
->isFullScreen())
5090 bool bMaximize
= IsZoomed( pFrame
->mhWnd
);
5091 bool bMinimize
= IsIconic( pFrame
->mhWnd
);
5092 if ( (nCommand
== SC_SIZE
) ||
5093 (!bMinimize
&& (nCommand
== SC_MOVE
)) ||
5094 (!bMaximize
&& (nCommand
== SC_MAXIMIZE
)) ||
5095 (bMaximize
&& (nCommand
== SC_RESTORE
)) )
5101 if ( nCommand
== SC_MOVE
)
5103 WinSalTimer
* pTimer
= static_cast<WinSalTimer
*>( ImplGetSVData()->maSchedCtx
.mpSalTimer
);
5105 pTimer
->SetForceRealTimer( true );
5108 if ( nCommand
== SC_KEYMENU
)
5110 // do not process SC_KEYMENU if we have a native menu
5111 // Windows should handle this
5112 if( GetMenu( hWnd
) )
5115 // Process here KeyMenu events only for Alt to activate the MenuBar,
5116 // or if a SysChild window is in focus, as Alt-key-combinations are
5117 // only processed via this event
5118 if ( !LOWORD( lParam
) )
5120 // Only trigger if no other key is pressed.
5121 // Contrary to Docu the CharCode is delivered with the x-coordinate
5122 // that is pressed in addition.
5123 // Also 32 for space, 99 for c, 100 for d, ...
5124 // As this is not documented, we check the state of the space-bar
5125 if ( GetKeyState( VK_SPACE
) & 0x8000 )
5128 // to avoid activating the MenuBar for Alt+MouseKey
5129 if ( (GetKeyState( VK_LBUTTON
) & 0x8000) ||
5130 (GetKeyState( VK_RBUTTON
) & 0x8000) ||
5131 (GetKeyState( VK_MBUTTON
) & 0x8000) ||
5132 (GetKeyState( VK_SHIFT
) & 0x8000) )
5135 SalKeyEvent aKeyEvt
;
5136 aKeyEvt
.mnCode
= KEY_MENU
;
5137 aKeyEvt
.mnCharCode
= 0;
5138 aKeyEvt
.mnRepeat
= 0;
5139 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
5140 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
5145 // check if a SysChild is in focus
5146 HWND hFocusWnd
= ::GetFocus();
5147 if ( hFocusWnd
&& ImplFindSalObject( hFocusWnd
) )
5149 char cKeyCode
= static_cast<char>(static_cast<unsigned char>(LOWORD( lParam
)));
5151 if ( (cKeyCode
>= 65) && (cKeyCode
<= 90) )
5153 // We only accept 0-9 and A-Z; all other keys have to be
5154 // processed by the SalObj hook
5155 if ( ((cKeyCode
>= 48) && (cKeyCode
<= 57)) ||
5156 ((cKeyCode
>= 97) && (cKeyCode
<= 122)) )
5158 sal_uInt16 nModCode
= 0;
5159 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
5160 nModCode
|= KEY_SHIFT
;
5161 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
5162 nModCode
|= KEY_MOD1
;
5163 nModCode
|= KEY_MOD2
;
5165 SalKeyEvent aKeyEvt
;
5166 if ( (cKeyCode
>= 48) && (cKeyCode
<= 57) )
5167 aKeyEvt
.mnCode
= KEY_0
+(cKeyCode
-48);
5169 aKeyEvt
.mnCode
= KEY_A
+(cKeyCode
-97);
5170 aKeyEvt
.mnCode
|= nModCode
;
5171 aKeyEvt
.mnCharCode
= cKeyCode
;
5172 aKeyEvt
.mnRepeat
= 0;
5173 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
5174 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
5184 static void ImplHandleInputLangChange( HWND hWnd
, WPARAM
, LPARAM lParam
)
5186 ImplSalYieldMutexAcquireWithWait();
5188 // check if we support IME
5189 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5194 if ( pFrame
->mbIME
&& pFrame
->mhDefIMEContext
)
5196 HKL hKL
= reinterpret_cast<HKL
>(lParam
);
5197 UINT nImeProps
= ImmGetProperty( hKL
, IGP_PROPERTY
);
5199 pFrame
->mbSpezIME
= (nImeProps
& IME_PROP_SPECIAL_UI
) != 0;
5200 pFrame
->mbAtCursorIME
= (nImeProps
& IME_PROP_AT_CARET
) != 0;
5201 pFrame
->mbHandleIME
= !pFrame
->mbSpezIME
;
5204 // trigger input language and codepage update
5205 UINT nLang
= pFrame
->mnInputLang
;
5206 ImplUpdateInputLang( pFrame
);
5209 if( nLang
!= pFrame
->mnInputLang
)
5210 pFrame
->CallCallback( SalEvent::InputLanguageChange
, nullptr );
5212 // reinit spec. keys
5213 GetSalData()->initKeyCodeMap();
5215 ImplSalYieldMutexRelease();
5218 static void ImplUpdateIMECursorPos( WinSalFrame
* pFrame
, HIMC hIMC
)
5220 COMPOSITIONFORM aForm
= {};
5222 // get cursor position and from it calculate default position
5223 // for the composition window
5224 SalExtTextInputPosEvent aPosEvt
;
5225 pFrame
->CallCallback( SalEvent::ExtTextInputPos
, &aPosEvt
);
5226 if ( (aPosEvt
.mnX
== -1) && (aPosEvt
.mnY
== -1) )
5227 aForm
.dwStyle
|= CFS_DEFAULT
;
5230 aForm
.dwStyle
|= CFS_POINT
;
5231 aForm
.ptCurrentPos
.x
= aPosEvt
.mnX
;
5232 aForm
.ptCurrentPos
.y
= aPosEvt
.mnY
;
5234 ImmSetCompositionWindow( hIMC
, &aForm
);
5236 // Because not all IME's use this values, we create
5237 // a Windows caret to force the Position from the IME
5238 if ( GetFocus() == pFrame
->mhWnd
)
5240 CreateCaret( pFrame
->mhWnd
, nullptr,
5241 aPosEvt
.mnWidth
, aPosEvt
.mnHeight
);
5242 SetCaretPos( aPosEvt
.mnX
, aPosEvt
.mnY
);
5246 static bool ImplHandleIMEStartComposition( HWND hWnd
)
5250 ImplSalYieldMutexAcquireWithWait();
5252 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5255 HIMC hIMC
= ImmGetContext( hWnd
);
5258 ImplUpdateIMECursorPos( pFrame
, hIMC
);
5259 ImmReleaseContext( hWnd
, hIMC
);
5262 if ( pFrame
->mbHandleIME
)
5264 if ( pFrame
->mbAtCursorIME
)
5269 ImplSalYieldMutexRelease();
5274 static bool ImplHandleIMECompositionInput( WinSalFrame
* pFrame
,
5275 HIMC hIMC
, LPARAM lParam
)
5280 SalExtTextInputEvent aEvt
;
5281 aEvt
.mpTextAttr
= nullptr;
5282 aEvt
.mnCursorPos
= 0;
5283 aEvt
.mnCursorFlags
= 0;
5285 // If we get a result string, then we handle this input
5286 if ( lParam
& GCS_RESULTSTR
)
5290 LONG nTextLen
= ImmGetCompositionStringW( hIMC
, GCS_RESULTSTR
, nullptr, 0 ) / sizeof( WCHAR
);
5291 if ( nTextLen
>= 0 )
5293 auto pTextBuf
= std::make_unique
<WCHAR
[]>(nTextLen
);
5294 ImmGetCompositionStringW( hIMC
, GCS_RESULTSTR
, pTextBuf
.get(), nTextLen
*sizeof( WCHAR
) );
5295 aEvt
.maText
= OUString( o3tl::toU(pTextBuf
.get()), static_cast<sal_Int32
>(nTextLen
) );
5298 aEvt
.mnCursorPos
= aEvt
.maText
.getLength();
5299 pFrame
->CallCallback( SalEvent::ExtTextInput
, &aEvt
);
5300 pFrame
->CallCallback( SalEvent::EndExtTextInput
, nullptr );
5301 ImplUpdateIMECursorPos( pFrame
, hIMC
);
5304 // If the IME doesn't support OnSpot input, then there is nothing to do
5305 if ( !pFrame
->mbAtCursorIME
)
5308 // If we get new Composition data, then we handle this new input
5309 if ( (lParam
& (GCS_COMPSTR
| GCS_COMPATTR
)) ||
5310 ((lParam
& GCS_CURSORPOS
) && !(lParam
& GCS_RESULTSTR
)) )
5314 std::unique_ptr
<ExtTextInputAttr
[]> pSalAttrAry
;
5315 LONG nTextLen
= ImmGetCompositionStringW( hIMC
, GCS_COMPSTR
, nullptr, 0 ) / sizeof( WCHAR
);
5319 auto pTextBuf
= std::make_unique
<WCHAR
[]>(nTextLen
);
5320 ImmGetCompositionStringW( hIMC
, GCS_COMPSTR
, pTextBuf
.get(), nTextLen
*sizeof( WCHAR
) );
5321 aEvt
.maText
= OUString( o3tl::toU(pTextBuf
.get()), static_cast<sal_Int32
>(nTextLen
) );
5324 std::unique_ptr
<BYTE
[]> pAttrBuf
;
5325 LONG nAttrLen
= ImmGetCompositionStringW( hIMC
, GCS_COMPATTR
, nullptr, 0 );
5328 pAttrBuf
.reset(new BYTE
[nAttrLen
]);
5329 ImmGetCompositionStringW( hIMC
, GCS_COMPATTR
, pAttrBuf
.get(), nAttrLen
);
5334 sal_Int32 nTextLen2
= aEvt
.maText
.getLength();
5335 pSalAttrAry
.reset(new ExtTextInputAttr
[nTextLen2
]);
5336 memset( pSalAttrAry
.get(), 0, nTextLen2
*sizeof( sal_uInt16
) );
5337 for( sal_Int32 i
= 0; (i
< nTextLen2
) && (i
< nAttrLen
); i
++ )
5339 BYTE nWinAttr
= pAttrBuf
.get()[i
];
5340 ExtTextInputAttr nSalAttr
;
5341 if ( nWinAttr
== ATTR_TARGET_CONVERTED
)
5343 nSalAttr
= ExtTextInputAttr::BoldUnderline
;
5344 aEvt
.mnCursorFlags
|= EXTTEXTINPUT_CURSOR_INVISIBLE
;
5346 else if ( nWinAttr
== ATTR_CONVERTED
)
5347 nSalAttr
= ExtTextInputAttr::DashDotUnderline
;
5348 else if ( nWinAttr
== ATTR_TARGET_NOTCONVERTED
)
5349 nSalAttr
= ExtTextInputAttr::Highlight
;
5350 else if ( nWinAttr
== ATTR_INPUT_ERROR
)
5351 nSalAttr
= ExtTextInputAttr::RedText
| ExtTextInputAttr::DottedUnderline
;
5352 else /* ( nWinAttr == ATTR_INPUT ) */
5353 nSalAttr
= ExtTextInputAttr::DottedUnderline
;
5354 pSalAttrAry
[i
] = nSalAttr
;
5357 aEvt
.mpTextAttr
= pSalAttrAry
.get();
5361 // Only when we get new composition data, we must send this event
5362 if ( (nTextLen
> 0) || !(lParam
& GCS_RESULTSTR
) )
5364 // End the mode, if the last character is deleted
5367 pFrame
->CallCallback( SalEvent::ExtTextInput
, &aEvt
);
5368 pFrame
->CallCallback( SalEvent::EndExtTextInput
, nullptr );
5372 // Because Cursor-Position and DeltaStart never updated
5373 // from the korean input engine, we must handle this here
5374 if ( lParam
& CS_INSERTCHAR
)
5376 aEvt
.mnCursorPos
= nTextLen
;
5377 if ( aEvt
.mnCursorPos
&& (lParam
& CS_NOMOVECARET
) )
5381 aEvt
.mnCursorPos
= LOWORD( ImmGetCompositionStringW( hIMC
, GCS_CURSORPOS
, nullptr, 0 ) );
5383 if ( pFrame
->mbCandidateMode
)
5384 aEvt
.mnCursorFlags
|= EXTTEXTINPUT_CURSOR_INVISIBLE
;
5385 if ( lParam
& CS_NOMOVECARET
)
5386 aEvt
.mnCursorFlags
|= EXTTEXTINPUT_CURSOR_OVERWRITE
;
5388 pFrame
->CallCallback( SalEvent::ExtTextInput
, &aEvt
);
5390 ImplUpdateIMECursorPos( pFrame
, hIMC
);
5397 static bool ImplHandleIMEComposition( HWND hWnd
, LPARAM lParam
)
5400 ImplSalYieldMutexAcquireWithWait();
5402 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5403 if ( pFrame
&& (!lParam
|| (lParam
& GCS_RESULTSTR
)) )
5405 // reset the background mode for each text input,
5406 // as some tools such as RichWin may have changed it
5407 if ( pFrame
->mpLocalGraphics
&&
5408 pFrame
->mpLocalGraphics
->getHDC() )
5409 SetBkMode( pFrame
->mpLocalGraphics
->getHDC(), TRANSPARENT
);
5412 if ( pFrame
&& pFrame
->mbHandleIME
)
5416 SalExtTextInputEvent aEvt
;
5417 aEvt
.mpTextAttr
= nullptr;
5418 aEvt
.mnCursorPos
= 0;
5419 aEvt
.mnCursorFlags
= 0;
5420 pFrame
->CallCallback( SalEvent::ExtTextInput
, &aEvt
);
5421 pFrame
->CallCallback( SalEvent::EndExtTextInput
, nullptr );
5423 else if ( lParam
& (GCS_RESULTSTR
| GCS_COMPSTR
| GCS_COMPATTR
| GCS_CURSORPOS
) )
5425 HIMC hIMC
= ImmGetContext( hWnd
);
5428 if ( ImplHandleIMECompositionInput( pFrame
, hIMC
, lParam
) )
5431 ImmReleaseContext( hWnd
, hIMC
);
5436 ImplSalYieldMutexRelease();
5440 static bool ImplHandleIMEEndComposition( HWND hWnd
)
5444 ImplSalYieldMutexAcquireWithWait();
5446 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5447 if ( pFrame
&& pFrame
->mbHandleIME
)
5449 if ( pFrame
->mbAtCursorIME
)
5451 pFrame
->mbCandidateMode
= false;
5456 ImplSalYieldMutexRelease();
5461 static bool ImplHandleAppCommand( HWND hWnd
, LPARAM lParam
, LRESULT
& nRet
)
5463 MediaCommand nCommand
;
5464 switch( GET_APPCOMMAND_LPARAM(lParam
) )
5466 case APPCOMMAND_MEDIA_CHANNEL_DOWN
: nCommand
= MediaCommand::ChannelDown
; break;
5467 case APPCOMMAND_MEDIA_CHANNEL_UP
: nCommand
= MediaCommand::ChannelUp
; break;
5468 case APPCOMMAND_MEDIA_NEXTTRACK
: nCommand
= MediaCommand::NextTrack
; break;
5469 case APPCOMMAND_MEDIA_PAUSE
: nCommand
= MediaCommand::Pause
; break;
5470 case APPCOMMAND_MEDIA_PLAY
: nCommand
= MediaCommand::Play
; break;
5471 case APPCOMMAND_MEDIA_PLAY_PAUSE
: nCommand
= MediaCommand::PlayPause
; break;
5472 case APPCOMMAND_MEDIA_PREVIOUSTRACK
: nCommand
= MediaCommand::PreviousTrack
; break;
5473 case APPCOMMAND_MEDIA_RECORD
: nCommand
= MediaCommand::Record
; break;
5474 case APPCOMMAND_MEDIA_REWIND
: nCommand
= MediaCommand::Rewind
; break;
5475 case APPCOMMAND_MEDIA_STOP
: nCommand
= MediaCommand::Stop
; break;
5476 case APPCOMMAND_MIC_ON_OFF_TOGGLE
: nCommand
= MediaCommand::MicOnOffToggle
; break;
5477 case APPCOMMAND_MICROPHONE_VOLUME_DOWN
: nCommand
= MediaCommand::MicrophoneVolumeDown
; break;
5478 case APPCOMMAND_MICROPHONE_VOLUME_MUTE
: nCommand
= MediaCommand::MicrophoneVolumeMute
; break;
5479 case APPCOMMAND_MICROPHONE_VOLUME_UP
: nCommand
= MediaCommand::MicrophoneVolumeUp
; break;
5480 case APPCOMMAND_VOLUME_DOWN
: nCommand
= MediaCommand::VolumeDown
; break;
5481 case APPCOMMAND_VOLUME_MUTE
: nCommand
= MediaCommand::VolumeMute
; break;
5482 case APPCOMMAND_VOLUME_UP
: nCommand
= MediaCommand::VolumeUp
; break;
5487 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5488 vcl::Window
*pWindow
= pFrame
? pFrame
->GetWindow() : nullptr;
5493 CommandMediaData
aMediaData(nCommand
);
5494 CommandEvent
aCEvt( aPoint
, CommandEventId::Media
, false, &aMediaData
);
5495 NotifyEvent
aNCmdEvt( NotifyEventType::COMMAND
, pWindow
, &aCEvt
);
5497 if ( !ImplCallPreNotify( aNCmdEvt
) )
5499 pWindow
->Command( aCEvt
);
5501 return !aMediaData
.GetPassThroughToOS();
5508 static void ImplHandleIMENotify( HWND hWnd
, WPARAM wParam
)
5510 if ( wParam
== WPARAM(IMN_OPENCANDIDATE
) )
5512 ImplSalYieldMutexAcquireWithWait();
5514 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5515 if ( pFrame
&& pFrame
->mbHandleIME
&&
5516 pFrame
->mbAtCursorIME
)
5518 // we want to hide the cursor
5519 pFrame
->mbCandidateMode
= true;
5520 ImplHandleIMEComposition( hWnd
, GCS_CURSORPOS
);
5522 HWND hWnd2
= pFrame
->mhWnd
;
5523 HIMC hIMC
= ImmGetContext( hWnd2
);
5526 LONG nBufLen
= ImmGetCompositionStringW( hIMC
, GCS_COMPSTR
, nullptr, 0 );
5529 SalExtTextInputPosEvent aPosEvt
;
5530 pFrame
->CallCallback( SalEvent::ExtTextInputPos
, &aPosEvt
);
5533 CANDIDATEFORM aForm
;
5535 aForm
.dwStyle
= CFS_EXCLUDE
;
5536 aForm
.ptCurrentPos
.x
= aPosEvt
.mnX
;
5537 aForm
.ptCurrentPos
.y
= aPosEvt
.mnY
+1;
5538 aForm
.rcArea
.left
= aPosEvt
.mnX
;
5539 aForm
.rcArea
.top
= aPosEvt
.mnY
;
5540 aForm
.rcArea
.right
= aForm
.rcArea
.left
+aPosEvt
.mnExtWidth
+1;
5541 aForm
.rcArea
.bottom
= aForm
.rcArea
.top
+aPosEvt
.mnHeight
+1;
5542 ImmSetCandidateWindow( hIMC
, &aForm
);
5545 ImmReleaseContext( hWnd2
, hIMC
);
5549 ImplSalYieldMutexRelease();
5551 else if ( wParam
== WPARAM(IMN_CLOSECANDIDATE
) )
5553 ImplSalYieldMutexAcquireWithWait();
5554 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5556 pFrame
->mbCandidateMode
= false;
5557 ImplSalYieldMutexRelease();
5562 ImplHandleGetObject(HWND hWnd
, LPARAM lParam
, WPARAM wParam
, LRESULT
& nRet
)
5564 uno::Reference
<accessibility::XMSAAService
> xMSAA
;
5565 if (ImplSalYieldMutexTryToAcquire())
5567 if (!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
5569 // IA2 should be enabled automatically
5570 AllSettings aSettings
= Application::GetSettings();
5571 MiscSettings aMisc
= aSettings
.GetMiscSettings();
5572 aMisc
.SetEnableATToolSupport(true);
5573 // The above is enough, since aMisc changes the same shared ImplMiscData as used in global
5574 // settings, so no need to call aSettings.SetMiscSettings and Application::SetSettings
5576 if (!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
5577 return false; // locked down somehow ?
5580 ImplSVData
* pSVData
= ImplGetSVData();
5582 // Make sure to launch Accessibility only the following criteria are satisfied
5583 // to avoid RFT interrupts regular accessibility processing
5584 if ( !pSVData
->mxAccessBridge
.is() )
5586 if( !InitAccessBridge() )
5589 xMSAA
.set(pSVData
->mxAccessBridge
, uno::UNO_QUERY
);
5590 ImplSalYieldMutexRelease();
5593 { // tdf#155794: access without locking: hopefully this should be fine
5594 // as the bridge is typically inited in Desktop::Main() already and the
5595 // WM_GETOBJECT is received only on the main thread and by the time in
5596 // VCL shutdown when ImplSvData dies there should not be Windows any
5597 // more that could receive messages.
5598 xMSAA
.set(ImplGetSVData()->mxAccessBridge
, uno::UNO_QUERY
);
5603 sal_Int32 lParam32
= static_cast<sal_Int32
>(lParam
);
5604 sal_uInt32 wParam32
= static_cast<sal_uInt32
>(wParam
);
5606 // mhOnSetTitleWnd not set to reasonable value anywhere...
5607 if ( lParam32
== OBJID_CLIENT
)
5609 nRet
= xMSAA
->getAccObjectPtr(
5610 reinterpret_cast<sal_Int64
>(hWnd
), lParam32
, wParam32
);
5618 static LRESULT
ImplHandleIMEReconvertString( HWND hWnd
, LPARAM lParam
)
5620 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5621 LPRECONVERTSTRING pReconvertString
= reinterpret_cast<LPRECONVERTSTRING
>(lParam
);
5623 SalSurroundingTextRequestEvent aEvt
;
5624 aEvt
.maText
.clear();
5625 aEvt
.mnStart
= aEvt
.mnEnd
= 0;
5627 UINT nImeProps
= ImmGetProperty( GetKeyboardLayout( 0 ), IGP_SETCOMPSTR
);
5628 if( (nImeProps
& SCS_CAP_SETRECONVERTSTRING
) == 0 )
5630 // This IME does not support reconversion.
5634 if( !pReconvertString
)
5636 // The first call for reconversion.
5637 pFrame
->CallCallback( SalEvent::StartReconversion
, nullptr );
5639 // Retrieve the surrounding text from the focused control.
5640 pFrame
->CallCallback( SalEvent::SurroundingTextRequest
, &aEvt
);
5642 if( aEvt
.maText
.isEmpty())
5647 nRet
= sizeof(RECONVERTSTRING
) + (aEvt
.maText
.getLength() + 1) * sizeof(WCHAR
);
5651 // The second call for reconversion.
5653 // Retrieve the surrounding text from the focused control.
5654 pFrame
->CallCallback( SalEvent::SurroundingTextRequest
, &aEvt
);
5655 nRet
= sizeof(RECONVERTSTRING
) + (aEvt
.maText
.getLength() + 1) * sizeof(WCHAR
);
5657 pReconvertString
->dwStrOffset
= sizeof(RECONVERTSTRING
);
5658 pReconvertString
->dwStrLen
= aEvt
.maText
.getLength();
5659 pReconvertString
->dwCompStrOffset
= aEvt
.mnStart
* sizeof(WCHAR
);
5660 pReconvertString
->dwCompStrLen
= aEvt
.mnEnd
- aEvt
.mnStart
;
5661 pReconvertString
->dwTargetStrOffset
= pReconvertString
->dwCompStrOffset
;
5662 pReconvertString
->dwTargetStrLen
= pReconvertString
->dwCompStrLen
;
5664 memcpy( pReconvertString
+ 1, aEvt
.maText
.getStr(), (aEvt
.maText
.getLength() + 1) * sizeof(WCHAR
) );
5667 // just return the required size of buffer to reconvert.
5671 static LRESULT
ImplHandleIMEConfirmReconvertString( HWND hWnd
, LPARAM lParam
)
5673 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5674 LPRECONVERTSTRING pReconvertString
= reinterpret_cast<LPRECONVERTSTRING
>(lParam
);
5675 SalSurroundingTextRequestEvent aEvt
;
5676 aEvt
.maText
.clear();
5677 aEvt
.mnStart
= aEvt
.mnEnd
= 0;
5679 pFrame
->CallCallback( SalEvent::SurroundingTextRequest
, &aEvt
);
5681 sal_uLong nTmpStart
= pReconvertString
->dwCompStrOffset
/ sizeof(WCHAR
);
5682 sal_uLong nTmpEnd
= nTmpStart
+ pReconvertString
->dwCompStrLen
;
5684 if( nTmpStart
!= aEvt
.mnStart
|| nTmpEnd
!= aEvt
.mnEnd
)
5686 SalSurroundingTextSelectionChangeEvent aSelEvt
{ nTmpStart
, nTmpEnd
};
5687 pFrame
->CallCallback( SalEvent::SurroundingTextSelectionChange
, &aSelEvt
);
5693 static LRESULT
ImplHandleIMEQueryCharPosition( HWND hWnd
, LPARAM lParam
) {
5694 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5695 PIMECHARPOSITION pQueryCharPosition
= reinterpret_cast<PIMECHARPOSITION
>(lParam
);
5696 if ( pQueryCharPosition
->dwSize
< sizeof(IMECHARPOSITION
) )
5699 SalQueryCharPositionEvent aEvt
;
5700 aEvt
.mbValid
= false;
5701 aEvt
.mnCharPos
= pQueryCharPosition
->dwCharPos
;
5703 pFrame
->CallCallback( SalEvent::QueryCharPosition
, &aEvt
);
5705 if ( !aEvt
.mbValid
)
5708 if ( aEvt
.mbVertical
)
5710 // For vertical writing, the base line is left edge of the rectangle
5711 // and the target position is top-right corner.
5712 pQueryCharPosition
->pt
.x
= aEvt
.maCursorBound
.getX() + aEvt
.maCursorBound
.GetWidth();
5713 pQueryCharPosition
->pt
.y
= aEvt
.maCursorBound
.getY();
5714 pQueryCharPosition
->cLineHeight
= aEvt
.maCursorBound
.GetWidth();
5718 // For horizontal writing, the base line is the bottom edge of the rectangle.
5719 // and the target position is top-left corner.
5720 pQueryCharPosition
->pt
.x
= aEvt
.maCursorBound
.getX();
5721 pQueryCharPosition
->pt
.y
= aEvt
.maCursorBound
.getY();
5722 pQueryCharPosition
->cLineHeight
= aEvt
.maCursorBound
.GetHeight();
5725 // Currently not supported but many IMEs usually ignore them.
5726 pQueryCharPosition
->rcDocument
.left
= 0;
5727 pQueryCharPosition
->rcDocument
.top
= 0;
5728 pQueryCharPosition
->rcDocument
.right
= 0;
5729 pQueryCharPosition
->rcDocument
.bottom
= 0;
5734 void SalTestMouseLeave()
5736 SalData
* pSalData
= GetSalData();
5738 if ( pSalData
->mhWantLeaveMsg
&& !::GetCapture() )
5741 GetCursorPos( &aPt
);
5743 // a one item cache, because this function is sometimes hot - if the cursor has not moved, then
5744 // no need to call WindowFromPoint
5745 static POINT cachedPoint
;
5746 if (cachedPoint
.x
== aPt
.x
&& cachedPoint
.y
== aPt
.y
)
5750 if ( pSalData
->mhWantLeaveMsg
!= WindowFromPoint( aPt
) )
5751 SendMessageW( pSalData
->mhWantLeaveMsg
, SAL_MSG_MOUSELEAVE
, 0, MAKELPARAM( aPt
.x
, aPt
.y
) );
5755 static bool ImplSalWheelMousePos( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
,
5760 aScreenPt
.x
= static_cast<short>(LOWORD( lParam
));
5761 aScreenPt
.y
= static_cast<short>(HIWORD( lParam
));
5762 // find child window that is at this position
5764 HWND hWheelWnd
= hWnd
;
5767 hChildWnd
= hWheelWnd
;
5769 ScreenToClient( hChildWnd
, &aPt
);
5770 hWheelWnd
= ChildWindowFromPointEx( hChildWnd
, aPt
, CWP_SKIPINVISIBLE
| CWP_SKIPTRANSPARENT
);
5772 while ( hWheelWnd
&& (hWheelWnd
!= hChildWnd
) );
5773 if ( hWheelWnd
&& (hWheelWnd
!= hWnd
) &&
5774 (hWheelWnd
!= ::GetFocus()) && IsWindowEnabled( hWheelWnd
) )
5776 rResult
= SendMessageW( hWheelWnd
, nMsg
, wParam
, lParam
);
5783 static LRESULT CALLBACK
SalFrameWndProc( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
, bool& rDef
)
5786 static bool bInWheelMsg
= false;
5787 static bool bInQueryEnd
= false;
5789 SAL_INFO("vcl.gdi.wndproc", "SalFrameWndProc(nMsg=" << nMsg
<< ", wParam=" << wParam
<< ", lParam=" << lParam
<< ")");
5791 // By WM_CREATE we connect the frame with the window handle
5792 if ( nMsg
== WM_CREATE
)
5794 // Save Window-Instance in Windowhandle
5795 // Can also be used for the A-Version, because the struct
5796 // to access lpCreateParams is the same structure
5797 CREATESTRUCTW
* pStruct
= reinterpret_cast<CREATESTRUCTW
*>(lParam
);
5798 WinSalFrame
* pFrame
= static_cast<WinSalFrame
*>(pStruct
->lpCreateParams
);
5799 if ( pFrame
!= nullptr )
5801 SetWindowPtr( hWnd
, pFrame
);
5803 UpdateDarkMode(hWnd
);
5805 // Set HWND already here, as data might be used already
5806 // when messages are being sent by CreateWindow()
5807 pFrame
->mhWnd
= hWnd
;
5808 pFrame
->maSysData
.hWnd
= hWnd
;
5813 ImplSVData
* pSVData
= ImplGetSVData();
5814 // #i72707# TODO: the mbDeInit check will not be needed
5815 // once all windows that are not properly closed on exit got fixed
5816 if( pSVData
->mbDeInit
)
5819 if ( WM_USER_SYSTEM_WINDOW_ACTIVATED
== nMsg
)
5828 case WM_LBUTTONDOWN
:
5829 case WM_MBUTTONDOWN
:
5830 case WM_RBUTTONDOWN
:
5834 case WM_NCMOUSEMOVE
:
5835 case SAL_MSG_MOUSELEAVE
:
5836 ImplSalYieldMutexAcquireWithWait();
5837 rDef
= !ImplHandleMouseMsg( hWnd
, nMsg
, wParam
, lParam
);
5838 ImplSalYieldMutexRelease();
5841 case WM_NCLBUTTONDOWN
:
5842 case WM_NCMBUTTONDOWN
:
5843 case WM_NCRBUTTONDOWN
:
5844 ImplSalYieldMutexAcquireWithWait();
5845 ImplCallClosePopupsHdl( hWnd
); // close popups...
5846 ImplSalYieldMutexRelease();
5849 case WM_MOUSEACTIVATE
:
5850 if ( LOWORD( lParam
) == HTCLIENT
)
5852 ImplSalYieldMutexAcquireWithWait();
5853 nRet
= LRESULT(ImplHandleMouseActivateMsg( hWnd
));
5854 ImplSalYieldMutexRelease();
5857 nRet
= MA_NOACTIVATE
;
5867 case WM_UNICHAR
: // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0
5871 ImplSalYieldMutexAcquireWithWait();
5872 rDef
= !ImplHandleKeyMsg( hWnd
, nMsg
, wParam
, lParam
, nRet
);
5873 ImplSalYieldMutexRelease();
5877 case WM_MOUSEHWHEEL
:
5878 // protect against recursion, in case the message is returned
5879 // by IE or the external window
5883 rDef
= !ImplHandleWheelMsg( hWnd
, nMsg
, wParam
, lParam
);
5884 // If we did not process the message, re-check if here is a
5885 // connected (?) window that we have to notify.
5887 rDef
= ImplSalWheelMousePos( hWnd
, nMsg
, wParam
, lParam
, nRet
);
5888 bInWheelMsg
= false;
5893 ImplSalYieldMutexAcquireWithWait();
5894 rDef
= !ImplHandleCommand( hWnd
, wParam
, lParam
);
5895 ImplSalYieldMutexRelease();
5898 case WM_INITMENUPOPUP
:
5899 ImplSalYieldMutexAcquireWithWait();
5900 rDef
= !ImplHandleMenuActivate( hWnd
, wParam
, lParam
);
5901 ImplSalYieldMutexRelease();
5905 ImplSalYieldMutexAcquireWithWait();
5906 rDef
= !ImplHandleMenuSelect( hWnd
, wParam
, lParam
);
5907 ImplSalYieldMutexRelease();
5911 ImplSalYieldMutexAcquireWithWait();
5912 nRet
= LRESULT(ImplHandleSysCommand( hWnd
, wParam
, lParam
));
5913 ImplSalYieldMutexRelease();
5919 nRet
= ImplMenuChar( hWnd
, wParam
, lParam
);
5924 case WM_MEASUREITEM
:
5925 nRet
= ImplMeasureItem(hWnd
, wParam
, lParam
);
5931 nRet
= ImplDrawItem(hWnd
, wParam
, lParam
);
5937 ImplHandleMoveMsg(hWnd
, lParam
);
5940 case SAL_MSG_POSTMOVE
:
5941 ImplCallMoveHdl(hWnd
);
5945 ImplHandleSizeMsg(hWnd
, wParam
, lParam
);
5948 case SAL_MSG_POSTCALLSIZE
:
5949 ImplCallSizeHdl( hWnd
);
5953 case WM_GETMINMAXINFO
:
5954 if ( ImplHandleMinMax( hWnd
, lParam
) )
5963 ImplHandlePaintMsg( hWnd
);
5966 case SAL_MSG_POSTPAINT
:
5967 ImplHandlePostPaintMsg( hWnd
, reinterpret_cast<RECT
*>(wParam
) );
5971 case SAL_MSG_FORCEPALETTE
:
5972 ImplHandleForcePalette( hWnd
);
5976 case WM_QUERYNEWPALETTE
:
5977 case SAL_MSG_POSTQUERYNEWPAL
:
5978 nRet
= ImplHandlePalette( true, hWnd
, nMsg
, wParam
, lParam
, rDef
);
5982 // Getting activated, we also want to set our palette.
5983 // We do this in Activate, so that other external child windows
5984 // can overwrite our palette. Thus our palette is set only once
5985 // and not recursively, as at all other places it is set only as
5986 // the background palette.
5987 if ( LOWORD( wParam
) != WA_INACTIVE
)
5988 SendMessageW( hWnd
, SAL_MSG_FORCEPALETTE
, 0, 0 );
5992 // #95133# a system dialog is opened/closed, using our app window as parent
5994 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5995 vcl::Window
*pWin
= nullptr;
5997 pWin
= pFrame
->GetWindow();
6001 pSVData
->maAppData
.mnModalMode
++;
6006 pWin
->EnableInput( false, nullptr );
6007 pWin
->IncModalCount(); // #106303# support frame based modal count
6012 ImplGetSVData()->maAppData
.mnModalMode
--;
6015 pWin
->EnableInput( true, nullptr );
6016 pWin
->DecModalCount(); // #106303# support frame based modal count
6026 case SAL_MSG_POSTFOCUS
:
6027 ImplHandleFocusMsg( hWnd
);
6032 ImplHandleCloseMsg( hWnd
);
6036 case WM_QUERYENDSESSION
:
6039 // handle queryendsession only once
6041 nRet
= LRESULT(!ImplHandleShutDownMsg( hWnd
));
6044 // Issue #16314#: ImplHandleShutDownMsg causes a PostMessage in case of allowing shutdown.
6045 // This posted message was never processed and cause Windows XP to hang after log off
6046 // if there are multiple sessions and the current session wasn't the first one started.
6047 // So if shutdown is allowed we assume that a post message was done and retrieve all
6048 // messages in the message queue and dispatch them before we return control to the system.
6052 SolarMutexGuard aGuard
;
6053 while ( Application::Reschedule( true ) );
6058 ImplSalYieldMutexAcquireWithWait();
6059 ImplSalYieldMutexRelease();
6066 bInQueryEnd
= false; // no shutdown: allow query again
6071 case WM_DISPLAYCHANGE
:
6072 case WM_SETTINGCHANGE
:
6073 case WM_DEVMODECHANGE
:
6075 case WM_SYSCOLORCHANGE
:
6077 ImplHandleSettingsChangeMsg( hWnd
, nMsg
, wParam
, lParam
);
6080 case WM_THEMECHANGED
:
6081 GetSalData()->mbThemeChanged
= true;
6084 case SAL_MSG_USEREVENT
:
6085 ImplHandleUserEvent( hWnd
, lParam
);
6089 case SAL_MSG_CAPTUREMOUSE
:
6093 case SAL_MSG_RELEASEMOUSE
:
6094 if ( ::GetCapture() == hWnd
)
6099 ImplSalToTop( hWnd
, static_cast<SalFrameToTop
>(wParam
) );
6103 ImplSalShow( hWnd
, static_cast<bool>(wParam
), static_cast<bool>(lParam
) );
6106 case SAL_MSG_SETINPUTCONTEXT
:
6107 ImplSalFrameSetInputContext( hWnd
, reinterpret_cast<const SalInputContext
*>(lParam
) );
6110 case SAL_MSG_ENDEXTTEXTINPUT
:
6111 ImplSalFrameEndExtTextInput( hWnd
, static_cast<EndExtTextInputFlags
>(wParam
) );
6115 case WM_INPUTLANGCHANGE
:
6116 ImplHandleInputLangChange( hWnd
, wParam
, lParam
);
6120 // #103487#, some IMEs (eg, those that do not work onspot)
6121 // may send WM_IME_CHAR instead of WM_IME_COMPOSITION
6122 // we just handle it like a WM_CHAR message - seems to work fine
6123 ImplSalYieldMutexAcquireWithWait();
6124 rDef
= !ImplHandleKeyMsg( hWnd
, WM_CHAR
, wParam
, lParam
, nRet
);
6125 ImplSalYieldMutexRelease();
6128 case WM_IME_STARTCOMPOSITION
:
6129 rDef
= ImplHandleIMEStartComposition( hWnd
);
6132 case WM_IME_COMPOSITION
:
6133 rDef
= ImplHandleIMEComposition( hWnd
, lParam
);
6136 case WM_IME_ENDCOMPOSITION
:
6137 rDef
= ImplHandleIMEEndComposition( hWnd
);
6141 ImplHandleIMENotify( hWnd
, wParam
);
6145 // tdf#155794: this must complete without taking SolarMutex
6146 if ( ImplHandleGetObject( hWnd
, lParam
, wParam
, nRet
) )
6153 if( ImplHandleAppCommand( hWnd
, lParam
, nRet
) )
6158 case WM_IME_REQUEST
:
6159 if ( static_cast<sal_uIntPtr
>(wParam
) == IMR_RECONVERTSTRING
)
6161 nRet
= ImplHandleIMEReconvertString( hWnd
, lParam
);
6164 else if( static_cast<sal_uIntPtr
>(wParam
) == IMR_CONFIRMRECONVERTSTRING
)
6166 nRet
= ImplHandleIMEConfirmReconvertString( hWnd
, lParam
);
6169 else if ( static_cast<sal_uIntPtr
>(wParam
) == IMR_QUERYCHARPOSITION
)
6171 if ( ImplSalYieldMutexTryToAcquire() )
6173 nRet
= ImplHandleIMEQueryCharPosition( hWnd
, lParam
);
6174 ImplSalYieldMutexRelease();
6186 LRESULT CALLBACK
SalFrameWndProcW( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
)
6192 nRet
= SalFrameWndProc( hWnd
, nMsg
, wParam
, lParam
, bDef
);
6194 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
6199 nRet
= DefWindowProcW( hWnd
, nMsg
, wParam
, lParam
);
6203 bool ImplHandleGlobalMsg( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
& rlResult
)
6205 // handle all messages concerning all frames so they get processed only once
6206 // Must work for Unicode and none Unicode
6207 bool bResult
= false;
6208 if ( (nMsg
== WM_PALETTECHANGED
) || (nMsg
== SAL_MSG_POSTPALCHANGED
) )
6211 rlResult
= ImplHandlePalette( false, hWnd
, nMsg
, wParam
, lParam
, bResult
);
6213 else if( nMsg
== WM_DISPLAYCHANGE
)
6215 WinSalSystem
* pSys
= static_cast<WinSalSystem
*>(ImplGetSalSystem());
6217 pSys
->clearMonitors();
6218 bResult
= (pSys
!= nullptr);
6223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */