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/string.h>
42 #include <rtl/ustring.h>
43 #include <sal/log.hxx>
45 #include <osl/module.h>
47 #include <tools/debug.hxx>
48 #include <o3tl/enumarray.hxx>
49 #include <o3tl/char16_t2wchar_t.hxx>
51 #include <vcl/event.hxx>
52 #include <vcl/sysdata.hxx>
53 #include <vcl/timer.hxx>
54 #include <vcl/settings.hxx>
55 #include <vcl/keycodes.hxx>
56 #include <vcl/window.hxx>
57 #include <vcl/wrkwin.hxx>
58 #include <vcl/svapp.hxx>
59 #include <vcl/ptrstyle.hxx>
61 #include <win/wincomp.hxx>
62 #include <win/salids.hrc>
63 #include <win/saldata.hxx>
64 #include <win/salinst.h>
65 #include <win/salbmp.h>
66 #include <win/salgdi.h>
67 #include <win/salsys.h>
68 #include <win/salframe.h>
69 #include <win/salvd.h>
70 #include <win/salmenu.h>
71 #include <win/salobj.h>
72 #include <win/saltimer.h>
74 #include <helpwin.hxx>
76 #include <sallayout.hxx>
78 #define COMPILE_MULTIMON_STUBS
80 #pragma warning(disable:4996) // 'GetVersionExA': was declared deprecated
85 #include <com/sun/star/uno/Exception.hpp>
88 #include <com/sun/star/accessibility/XMSAAService.hpp>
89 #ifndef WM_GETOBJECT // TESTME does this ever happen ?
90 # define WM_GETOBJECT 0x003D
95 #if !defined WIN32_LEAN_AND_MEAN
96 # define WIN32_LEAN_AND_MEAN
101 #include <propvarutil.h>
102 #include <shellapi.h>
104 using namespace ::com::sun::star
;
105 using namespace ::com::sun::star::uno
;
106 using namespace ::com::sun::star::lang
;
107 using namespace ::com::sun::star::container
;
108 using namespace ::com::sun::star::beans
;
110 #ifndef SPI_GETWHEELSCROLLCHARS
111 # define SPI_GETWHEELSCROLLCHARS 0x006C
113 #ifndef SPI_SETWHEELSCROLLCHARS
114 # define SPI_SETWHEELSCROLLCHARS 0x006D
116 #ifndef WM_MOUSEHWHEEL
117 # define WM_MOUSEHWHEEL 0x020E
120 # define IDC_PEN MAKEINTRESOURCE(32631)
123 const unsigned int WM_USER_SYSTEM_WINDOW_ACTIVATED
= RegisterWindowMessageW(L
"SYSTEM_WINDOW_ACTIVATED");
125 bool WinSalFrame::mbInReparent
= false;
127 // Macros for support of WM_UNICHAR & Keyman 6.0
128 //#define Uni_UTF32ToSurrogate1(ch) (((unsigned long) (ch) - 0x10000) / 0x400 + 0xD800)
129 #define Uni_UTF32ToSurrogate2(ch) ((static_cast<tools::ULong>(ch) - 0x10000) % 0x400 + 0xDC00)
130 #define Uni_SupplementaryPlanesStart 0x10000
132 static void UpdateFrameGeometry( HWND hWnd
, WinSalFrame
* pFrame
);
133 static void SetMaximizedFrameGeometry( HWND hWnd
, WinSalFrame
* pFrame
, RECT
* pParentRect
= nullptr );
135 static void ImplSaveFrameState( WinSalFrame
* pFrame
)
137 // save position, size and state for GetWindowState()
138 if ( !pFrame
->mbFullScreen
)
140 bool bVisible
= (GetWindowStyle( pFrame
->mhWnd
) & WS_VISIBLE
) != 0;
141 if ( IsIconic( pFrame
->mhWnd
) )
143 pFrame
->maState
.mnState
|= WindowStateState::Minimized
;
145 pFrame
->mnShowState
= SW_SHOWMAXIMIZED
;
147 else if ( IsZoomed( pFrame
->mhWnd
) )
149 pFrame
->maState
.mnState
&= ~WindowStateState::Minimized
;
150 pFrame
->maState
.mnState
|= WindowStateState::Maximized
;
152 pFrame
->mnShowState
= SW_SHOWMAXIMIZED
;
153 pFrame
->mbRestoreMaximize
= true;
155 WINDOWPLACEMENT aPlacement
;
156 aPlacement
.length
= sizeof(aPlacement
);
157 if( GetWindowPlacement( pFrame
->mhWnd
, &aPlacement
) )
159 RECT aRect
= aPlacement
.rcNormalPosition
;
161 AdjustWindowRectEx( &aRect2
, GetWindowStyle( pFrame
->mhWnd
),
162 FALSE
, GetWindowExStyle( pFrame
->mhWnd
) );
163 tools::Long nTopDeco
= abs( aRect
.top
- aRect2
.top
);
164 tools::Long nLeftDeco
= abs( aRect
.left
- aRect2
.left
);
165 tools::Long nBottomDeco
= abs( aRect
.bottom
- aRect2
.bottom
);
166 tools::Long nRightDeco
= abs( aRect
.right
- aRect2
.right
);
168 pFrame
->maState
.mnX
= aRect
.left
+ nLeftDeco
;
169 pFrame
->maState
.mnY
= aRect
.top
+ nTopDeco
;
170 pFrame
->maState
.mnWidth
= aRect
.right
- aRect
.left
- nLeftDeco
- nRightDeco
;
171 pFrame
->maState
.mnHeight
= aRect
.bottom
- aRect
.top
- nTopDeco
- nBottomDeco
;
177 GetWindowRect( pFrame
->mhWnd
, &aRect
);
179 // to be consistent with Unix, the frame state is without(!) decoration
181 AdjustWindowRectEx( &aRect2
, GetWindowStyle( pFrame
->mhWnd
),
182 FALSE
, GetWindowExStyle( pFrame
->mhWnd
) );
183 tools::Long nTopDeco
= abs( aRect
.top
- aRect2
.top
);
184 tools::Long nLeftDeco
= abs( aRect
.left
- aRect2
.left
);
185 tools::Long nBottomDeco
= abs( aRect
.bottom
- aRect2
.bottom
);
186 tools::Long nRightDeco
= abs( aRect
.right
- aRect2
.right
);
188 pFrame
->maState
.mnState
&= ~WindowStateState(WindowStateState::Minimized
| WindowStateState::Maximized
);
189 // subtract decoration
190 pFrame
->maState
.mnX
= aRect
.left
+nLeftDeco
;
191 pFrame
->maState
.mnY
= aRect
.top
+nTopDeco
;
192 pFrame
->maState
.mnWidth
= aRect
.right
-aRect
.left
-nLeftDeco
-nRightDeco
;
193 pFrame
->maState
.mnHeight
= aRect
.bottom
-aRect
.top
-nTopDeco
-nBottomDeco
;
195 pFrame
->mnShowState
= SW_SHOWNORMAL
;
196 pFrame
->mbRestoreMaximize
= false;
201 // if pParentRect is set, the workarea of the monitor that contains pParentRect is returned
202 void ImplSalGetWorkArea( HWND hWnd
, RECT
*pRect
, const RECT
*pParentRect
)
204 // check if we or our parent is fullscreen, then the taskbar should be ignored
205 bool bIgnoreTaskbar
= false;
206 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
209 vcl::Window
*pWin
= pFrame
->GetWindow();
212 WorkWindow
*pWorkWin
= (pWin
->GetType() == WindowType::WORKWINDOW
) ? static_cast<WorkWindow
*>(pWin
) : nullptr;
213 if( pWorkWin
&& pWorkWin
->ImplGetWindowImpl()->mbReallyVisible
&& pWorkWin
->IsFullScreenMode() )
215 bIgnoreTaskbar
= true;
219 pWin
= pWin
->ImplGetWindowImpl()->mpParent
;
223 // calculates the work area taking multiple monitors into account
224 static int nMonitors
= GetSystemMetrics( SM_CMONITORS
);
229 pRect
->left
= pRect
->top
= 0;
230 pRect
->right
= GetSystemMetrics( SM_CXSCREEN
);
231 pRect
->bottom
= GetSystemMetrics( SM_CYSCREEN
);
234 SystemParametersInfoW( SPI_GETWORKAREA
, 0, pRect
, 0 );
238 if( pParentRect
!= nullptr )
240 // return the size of the monitor where pParentRect lives
244 // get the nearest monitor to the passed rect.
245 hMonitor
= MonitorFromRect(pParentRect
, MONITOR_DEFAULTTONEAREST
);
247 // get the work area or entire monitor rect.
248 mi
.cbSize
= sizeof(mi
);
249 GetMonitorInfo(hMonitor
, &mi
);
250 if( !bIgnoreTaskbar
)
253 *pRect
= mi
.rcMonitor
;
257 // return the union of all monitors
258 pRect
->left
= GetSystemMetrics( SM_XVIRTUALSCREEN
);
259 pRect
->top
= GetSystemMetrics( SM_YVIRTUALSCREEN
);
260 pRect
->right
= pRect
->left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
);
261 pRect
->bottom
= pRect
->top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
);
263 // virtualscreen does not take taskbar into account, so use the corresponding
264 // diffs between screen and workarea from the default screen
265 // however, this is still not perfect: the taskbar might not be on the primary screen
266 if( !bIgnoreTaskbar
)
269 SystemParametersInfoW( SPI_GETWORKAREA
, 0, &wRect
, 0 );
272 scrRect
.right
= GetSystemMetrics( SM_CXSCREEN
);
273 scrRect
.bottom
= GetSystemMetrics( SM_CYSCREEN
);
275 pRect
->left
+= wRect
.left
;
276 pRect
->top
+= wRect
.top
;
277 pRect
->right
-= scrRect
.right
- wRect
.right
;
278 pRect
->bottom
-= scrRect
.bottom
- wRect
.bottom
;
284 SalFrame
* ImplSalCreateFrame( WinSalInstance
* pInst
,
285 HWND hWndParent
, SalFrameStyleFlags nSalFrameStyle
)
287 WinSalFrame
* pFrame
= new WinSalFrame
;
290 DWORD nExSysStyle
= 0;
291 bool bSubFrame
= false;
293 static const char* pEnvSynchronize
= getenv("SAL_SYNCHRONIZE");
294 if ( pEnvSynchronize
) // no buffering of drawing commands
295 GdiSetBatchLimit( 1 );
297 static const char* pEnvTransparentFloats
= getenv("SAL_TRANSPARENT_FLOATS" );
299 // determine creation data
300 if ( nSalFrameStyle
& (SalFrameStyleFlags::PLUG
| SalFrameStyleFlags::SYSTEMCHILD
) )
302 nSysStyle
|= WS_CHILD
;
303 if( nSalFrameStyle
& SalFrameStyleFlags::SYSTEMCHILD
)
304 nSysStyle
|= WS_CLIPSIBLINGS
;
308 // #i87402# commenting out WS_CLIPCHILDREN
309 // this breaks SalFrameStyleFlags::SYSTEMCHILD handling, which is not
310 // used currently. Probably SalFrameStyleFlags::SYSTEMCHILD should be
313 // nSysStyle |= WS_CLIPCHILDREN;
316 nSysStyle
|= WS_POPUP
;
318 pFrame
->mbNoIcon
= true;
322 // Only with WS_OVERLAPPED we get a useful default position/size
323 if ( (nSalFrameStyle
& (SalFrameStyleFlags::SIZEABLE
| SalFrameStyleFlags::MOVEABLE
)) ==
324 (SalFrameStyleFlags::SIZEABLE
| SalFrameStyleFlags::MOVEABLE
) )
325 nSysStyle
|= WS_OVERLAPPED
;
328 nSysStyle
|= WS_POPUP
;
329 if ( !(nSalFrameStyle
& SalFrameStyleFlags::MOVEABLE
) )
330 nExSysStyle
|= WS_EX_TOOLWINDOW
; // avoid taskbar appearance, for eg splash screen
334 if ( nSalFrameStyle
& SalFrameStyleFlags::MOVEABLE
)
336 pFrame
->mbCaption
= true;
337 nSysStyle
|= WS_SYSMENU
| WS_CAPTION
;
339 nSysStyle
|= WS_SYSMENU
| WS_MINIMIZEBOX
;
341 nExSysStyle
|= WS_EX_DLGMODALFRAME
;
343 if ( nSalFrameStyle
& SalFrameStyleFlags::SIZEABLE
)
345 pFrame
->mbSizeBorder
= true;
346 nSysStyle
|= WS_THICKFRAME
;
348 nSysStyle
|= WS_MAXIMIZEBOX
;
351 pFrame
->mbFixBorder
= true;
353 if ( nSalFrameStyle
& SalFrameStyleFlags::DEFAULT
)
354 nExSysStyle
|= WS_EX_APPWINDOW
;
356 if( nSalFrameStyle
& SalFrameStyleFlags::TOOLWINDOW
357 // #100656# toolwindows lead to bad alt-tab behaviour, if they have the focus
358 // you must press it twice to leave the application
359 // so toolwindows are only used for non sizeable windows
360 // which are typically small, so a small caption makes sense
362 // #103578# looked too bad - above changes reverted
363 /* && !(nSalFrameStyle & SalFrameStyleFlags::SIZEABLE) */ )
365 pFrame
->mbNoIcon
= true;
366 nExSysStyle
|= WS_EX_TOOLWINDOW
;
367 if ( pEnvTransparentFloats
/*&& !(nSalFrameStyle & SalFrameStyleFlags::MOVEABLE) */)
368 nExSysStyle
|= WS_EX_LAYERED
;
371 if ( nSalFrameStyle
& SalFrameStyleFlags::FLOAT
)
373 nExSysStyle
|= WS_EX_TOOLWINDOW
;
374 pFrame
->mbFloatWin
= true;
376 if (pEnvTransparentFloats
)
377 nExSysStyle
|= WS_EX_LAYERED
;
380 if (nSalFrameStyle
& SalFrameStyleFlags::TOOLTIP
)
381 nExSysStyle
|= WS_EX_TOPMOST
;
384 pFrame
->mnStyle
= nSalFrameStyle
;
386 // determine show style
387 pFrame
->mnShowState
= SW_SHOWNORMAL
;
388 if ( (nSysStyle
& (WS_POPUP
| WS_MAXIMIZEBOX
| WS_THICKFRAME
)) == (WS_MAXIMIZEBOX
| WS_THICKFRAME
) )
390 if ( GetSystemMetrics( SM_CXSCREEN
) <= 1024 )
391 pFrame
->mnShowState
= SW_SHOWMAXIMIZED
;
394 if ( nSalFrameStyle
& SalFrameStyleFlags::DEFAULT
)
396 SalData
* pSalData
= GetSalData();
397 pFrame
->mnShowState
= pSalData
->mnCmdShow
;
398 if ( (pFrame
->mnShowState
!= SW_SHOWMINIMIZED
) &&
399 (pFrame
->mnShowState
!= SW_MINIMIZE
) &&
400 (pFrame
->mnShowState
!= SW_SHOWMINNOACTIVE
) )
402 if ( (pFrame
->mnShowState
== SW_SHOWMAXIMIZED
) ||
403 (pFrame
->mnShowState
== SW_MAXIMIZE
) )
404 pFrame
->mbOverwriteState
= false;
405 pFrame
->mnShowState
= SW_SHOWMAXIMIZED
;
408 pFrame
->mbOverwriteState
= false;
412 // Document Windows are also maximized, if the current Document Window
414 HWND hWnd2
= GetForegroundWindow();
415 if ( hWnd2
&& IsMaximized( hWnd2
) &&
416 (GetWindowInstance( hWnd2
) == pInst
->mhInst
) &&
417 ((GetWindowStyle( hWnd2
) & (WS_POPUP
| WS_MAXIMIZEBOX
| WS_THICKFRAME
)) == (WS_MAXIMIZEBOX
| WS_THICKFRAME
)) )
418 pFrame
->mnShowState
= SW_SHOWMAXIMIZED
;
427 if ( nSalFrameStyle
& (SalFrameStyleFlags::MOVEABLE
|SalFrameStyleFlags::NOSHADOW
) ) // check if shadow not wanted
428 pClassName
= SAL_SUBFRAME_CLASSNAMEW
;
430 pClassName
= SAL_TMPSUBFRAME_CLASSNAMEW
; // undecorated floaters will get shadow on XP
434 if ( nSalFrameStyle
& SalFrameStyleFlags::MOVEABLE
)
435 pClassName
= SAL_FRAME_CLASSNAMEW
;
437 pClassName
= SAL_TMPSUBFRAME_CLASSNAMEW
;
439 hWnd
= CreateWindowExW( nExSysStyle
, pClassName
, L
"", nSysStyle
,
440 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
441 hWndParent
, nullptr, pInst
->mhInst
, pFrame
);
442 SAL_WARN_IF(!hWnd
, "vcl", "CreateWindowExW failed: " << WindowsErrorString(GetLastError()));
444 #if OSL_DEBUG_LEVEL > 1
445 // set transparency value
446 if( GetWindowExStyle( hWnd
) & WS_EX_LAYERED
)
447 SetLayeredWindowAttributes( hWnd
, 0, 230, 0x00000002 /*LWA_ALPHA*/ );
455 // If we have a Window with a Caption Bar and without
456 // a MaximizeBox, we change the SystemMenu
457 if ( (nSysStyle
& (WS_CAPTION
| WS_MAXIMIZEBOX
)) == (WS_CAPTION
) )
459 HMENU hSysMenu
= GetSystemMenu( hWnd
, FALSE
);
462 if ( !(nSysStyle
& (WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
)) )
463 DeleteMenu( hSysMenu
, SC_RESTORE
, MF_BYCOMMAND
);
465 EnableMenuItem( hSysMenu
, SC_RESTORE
, MF_BYCOMMAND
| MF_GRAYED
| MF_DISABLED
);
466 if ( !(nSysStyle
& WS_MINIMIZEBOX
) )
467 DeleteMenu( hSysMenu
, SC_MINIMIZE
, MF_BYCOMMAND
);
468 if ( !(nSysStyle
& WS_MAXIMIZEBOX
) )
469 DeleteMenu( hSysMenu
, SC_MAXIMIZE
, MF_BYCOMMAND
);
470 if ( !(nSysStyle
& WS_THICKFRAME
) )
471 DeleteMenu( hSysMenu
, SC_SIZE
, MF_BYCOMMAND
);
474 if ( (nSysStyle
& WS_SYSMENU
) && !(nSalFrameStyle
& SalFrameStyleFlags::CLOSEABLE
) )
476 HMENU hSysMenu
= GetSystemMenu( hWnd
, FALSE
);
478 EnableMenuItem( hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
| MF_GRAYED
| MF_DISABLED
);
481 // reset input context
482 pFrame
->mhDefIMEContext
= ImmAssociateContext( hWnd
, nullptr );
484 // determine output size and state
486 GetClientRect( hWnd
, &aRect
);
487 pFrame
->mnWidth
= aRect
.right
;
488 pFrame
->mnHeight
= aRect
.bottom
;
489 ImplSaveFrameState( pFrame
);
490 pFrame
->mbDefPos
= true;
492 UpdateFrameGeometry( hWnd
, pFrame
);
494 if( pFrame
->mnShowState
== SW_SHOWMAXIMIZED
)
496 // #96084 set a useful internal window size because
497 // the window will not be maximized (and the size updated) before show()
499 SetMaximizedFrameGeometry( hWnd
, pFrame
);
505 // helper that only creates the HWND
506 // to allow for easy reparenting of system windows, (i.e. destroy and create new)
507 HWND
ImplSalReCreateHWND( HWND hWndParent
, HWND oldhWnd
, bool bAsChild
)
509 HINSTANCE hInstance
= GetSalData()->mhInst
;
510 sal_uLong nSysStyle
= GetWindowLongW( oldhWnd
, GWL_STYLE
);
511 sal_uLong nExSysStyle
= GetWindowLongW( oldhWnd
, GWL_EXSTYLE
);
515 nSysStyle
= WS_CHILD
;
519 LPCWSTR pClassName
= SAL_SUBFRAME_CLASSNAMEW
;
520 return CreateWindowExW( nExSysStyle
, pClassName
, L
"", nSysStyle
,
521 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
522 hWndParent
, nullptr, hInstance
, GetWindowPtr( oldhWnd
) );
525 // translation table from System keycodes into StartView keycodes
526 #define KEY_TAB_SIZE 146
528 const sal_uInt16 aImplTranslateKeyTab
[KEY_TAB_SIZE
] =
530 // StarView-Code System-Code Index
539 KEY_BACKSPACE
, // VK_BACK 8
544 KEY_RETURN
, // VK_RETURN 13
556 KEY_HANGUL_HANJA
, // VK_HANJA 25
558 KEY_ESCAPE
, // VK_ESCAPE 27
563 KEY_SPACE
, // VK_SPACE 32
564 KEY_PAGEUP
, // VK_PRIOR 33
565 KEY_PAGEDOWN
, // VK_NEXT 34
566 KEY_END
, // VK_END 35
567 KEY_HOME
, // VK_HOME 36
568 KEY_LEFT
, // VK_LEFT 37
570 KEY_RIGHT
, // VK_RIGHT 39
571 KEY_DOWN
, // VK_DOWN 40
576 KEY_INSERT
, // VK_INSERT 45
577 KEY_DELETE
, // VK_DELETE 46
578 KEY_HELP
, // VK_HELP 47
624 KEY_CONTEXTMENU
, // VK_APPS 93
627 KEY_0
, // VK_NUMPAD0 96
628 KEY_1
, // VK_NUMPAD1 97
629 KEY_2
, // VK_NUMPAD2 98
630 KEY_3
, // VK_NUMPAD3 99
631 KEY_4
, // VK_NUMPAD4 100
632 KEY_5
, // VK_NUMPAD5 101
633 KEY_6
, // VK_NUMPAD6 102
634 KEY_7
, // VK_NUMPAD7 103
635 KEY_8
, // VK_NUMPAD8 104
636 KEY_9
, // VK_NUMPAD9 105
637 KEY_MULTIPLY
, // VK_MULTIPLY 106
638 KEY_ADD
, // VK_ADD 107
639 KEY_DECIMAL
, // VK_SEPARATOR 108
640 KEY_SUBTRACT
, // VK_SUBTRACT 109
641 KEY_DECIMAL
, // VK_DECIMAL 110
642 KEY_DIVIDE
, // VK_DIVIDE 111
652 KEY_F10
, // VK_F10 121
653 KEY_F11
, // VK_F11 122
654 KEY_F12
, // VK_F12 123
655 KEY_F13
, // VK_F13 124
656 KEY_F14
, // VK_F14 125
657 KEY_F15
, // VK_F15 126
658 KEY_F16
, // VK_F16 127
659 KEY_F17
, // VK_F17 128
660 KEY_F18
, // VK_F18 129
661 KEY_F19
, // VK_F19 130
662 KEY_F20
, // VK_F20 131
663 KEY_F21
, // VK_F21 132
664 KEY_F22
, // VK_F22 133
665 KEY_F23
, // VK_F23 134
666 KEY_F24
, // VK_F24 135
679 static UINT
ImplSalGetWheelScrollLines()
682 HWND hWndMsWheel
= FindWindowW( MSH_WHEELMODULE_CLASS
, MSH_WHEELMODULE_TITLE
);
685 UINT nGetScrollLinesMsgId
= RegisterWindowMessageW( MSH_SCROLL_LINES
);
686 nScrLines
= static_cast<UINT
>(SendMessageW( hWndMsWheel
, nGetScrollLinesMsgId
, 0, 0 ));
690 if( !SystemParametersInfoW( SPI_GETWHEELSCROLLLINES
, 0, &nScrLines
, 0 ) )
699 static UINT
ImplSalGetWheelScrollChars()
702 if( !SystemParametersInfoW( SPI_GETWHEELSCROLLCHARS
, 0, &nScrChars
, 0 ) )
707 // system settings successfully read
711 static void ImplSalAddBorder( const WinSalFrame
* pFrame
, int& width
, int& height
)
713 // transform client size into window size
716 aWinRect
.right
= width
-1;
718 aWinRect
.bottom
= height
-1;
719 AdjustWindowRectEx( &aWinRect
, GetWindowStyle( pFrame
->mhWnd
),
720 FALSE
, GetWindowExStyle( pFrame
->mhWnd
) );
721 width
= aWinRect
.right
- aWinRect
.left
+ 1;
722 height
= aWinRect
.bottom
- aWinRect
.top
+ 1;
725 static void ImplSalCalcFullScreenSize( const WinSalFrame
* pFrame
,
726 int& rX
, int& rY
, int& rDX
, int& rDY
)
728 // set window to screen size
737 if ( pFrame
->mbSizeBorder
)
739 nFrameX
= GetSystemMetrics( SM_CXSIZEFRAME
);
740 nFrameY
= GetSystemMetrics( SM_CYSIZEFRAME
);
742 else if ( pFrame
->mbFixBorder
)
744 nFrameX
= GetSystemMetrics( SM_CXFIXEDFRAME
);
745 nFrameY
= GetSystemMetrics( SM_CYFIXEDFRAME
);
747 else if ( pFrame
->mbBorder
)
749 nFrameX
= GetSystemMetrics( SM_CXBORDER
);
750 nFrameY
= GetSystemMetrics( SM_CYBORDER
);
757 if ( pFrame
->mbCaption
)
758 nCaptionY
= GetSystemMetrics( SM_CYCAPTION
);
764 sal_Int32 nMonitors
= Application::GetScreenCount();
765 if( (pFrame
->mnDisplay
>= 0) && (pFrame
->mnDisplay
< nMonitors
) )
767 tools::Rectangle aRect
= Application::GetScreenPosSizePixel( pFrame
->mnDisplay
);
768 nScreenX
= aRect
.Left();
769 nScreenY
= aRect
.Top();
770 nScreenDX
= aRect
.GetWidth();
771 nScreenDY
= aRect
.GetHeight();
775 tools::Rectangle aCombined
= Application::GetScreenPosSizePixel( 0 );
776 for( sal_Int32 i
= 1 ; i
< nMonitors
; i
++ )
778 aCombined
.Union( Application::GetScreenPosSizePixel( i
) );
780 nScreenX
= aCombined
.Left();
781 nScreenY
= aCombined
.Top();
782 nScreenDX
= aCombined
.GetWidth();
783 nScreenDY
= aCombined
.GetHeight();
790 if( !nScreenDX
|| !nScreenDY
)
792 nScreenDX
= GetSystemMetrics( SM_CXSCREEN
);
793 nScreenDY
= GetSystemMetrics( SM_CYSCREEN
);
796 rX
= nScreenX
-nFrameX
;
797 rY
= nScreenY
-(nFrameY
+nCaptionY
);
798 rDX
= nScreenDX
+(nFrameX
*2);
799 rDY
= nScreenDY
+(nFrameY
*2)+nCaptionY
;
802 static void ImplSalFrameFullScreenPos( WinSalFrame
* pFrame
, bool bAlways
= false )
804 if ( bAlways
|| !IsIconic( pFrame
->mhWnd
) )
806 // set window to screen size
811 ImplSalCalcFullScreenSize( pFrame
, nX
, nY
, nWidth
, nHeight
);
812 SetWindowPos( pFrame
->mhWnd
, nullptr,
813 nX
, nY
, nWidth
, nHeight
,
814 SWP_NOZORDER
| SWP_NOACTIVATE
);
820 void SetForegroundWindow_Impl(HWND hwnd
)
822 if (!Application::IsHeadlessModeEnabled())
823 SetForegroundWindow(hwnd
);
828 WinSalFrame::WinSalFrame()
830 SalData
* pSalData
= GetSalData();
833 mhCursor
= LoadCursor( nullptr, IDC_ARROW
);
834 mhDefIMEContext
= nullptr;
835 mpLocalGraphics
= nullptr;
836 mpThreadGraphics
= nullptr;
837 mnShowState
= SW_SHOWNORMAL
;
842 mnMaxWidth
= SHRT_MAX
;
843 mnMaxHeight
= SHRT_MAX
;
850 mbSizeBorder
= false;
851 mbFullScreenCaption
= false;
852 mbFullScreen
= false;
853 mbPresentation
= false;
855 mbRestoreMaximize
= false;
858 mbFullScreenToolWin
= false;
860 mbOverwriteState
= true;
864 mbAtCursorIME
= false;
865 mbCandidateMode
= false;
868 mSelectedhMenu
= nullptr;
869 mLastActivatedhMenu
= nullptr;
870 mpClipRgnData
= nullptr;
871 mbFirstClipRect
= true;
872 mpNextClipRect
= nullptr;
874 mbPropertiesStored
= false;
876 // get data, when making 1st frame
877 if ( !pSalData
->mpFirstFrame
)
879 if ( !aSalShlData
.mnWheelScrollLines
)
880 aSalShlData
.mnWheelScrollLines
= ImplSalGetWheelScrollLines();
881 if ( !aSalShlData
.mnWheelScrollChars
)
882 aSalShlData
.mnWheelScrollChars
= ImplSalGetWheelScrollChars();
885 // insert frame in framelist
886 mpNextFrame
= pSalData
->mpFirstFrame
;
887 pSalData
->mpFirstFrame
= this;
890 void WinSalFrame::updateScreenNumber()
892 if( mnDisplay
== -1 ) // spans all monitors
894 WinSalSystem
* pSys
= static_cast<WinSalSystem
*>(ImplGetSalSystem());
897 const std::vector
<WinSalSystem::DisplayMonitor
>& rMonitors
=
899 Point
aPoint( maGeometry
.nX
, maGeometry
.nY
);
900 size_t nMon
= rMonitors
.size();
901 for( size_t i
= 0; i
< nMon
; i
++ )
903 if( rMonitors
[i
].m_aArea
.IsInside( aPoint
) )
905 mnDisplay
= static_cast<sal_Int32
>(i
);
906 maGeometry
.nDisplayScreenNumber
= static_cast<unsigned int>(i
);
912 bool WinSalFrame::ReleaseFrameGraphicsDC( WinSalGraphics
* pGraphics
)
915 SalData
* pSalData
= GetSalData();
916 HDC hDC
= pGraphics
->getHDC();
919 if ( pGraphics
->getDefPal() )
920 SelectPalette( hDC
, pGraphics
->getDefPal(), TRUE
);
921 pGraphics
->DeInitGraphics();
922 SendMessageW( pSalData
->mpInstance
->mhComWnd
, SAL_MSG_RELEASEDC
,
923 reinterpret_cast<WPARAM
>(mhWnd
), reinterpret_cast<LPARAM
>(hDC
) );
924 if ( pGraphics
== mpThreadGraphics
)
925 pSalData
->mnCacheDCInUse
--;
926 pGraphics
->setHDC(nullptr);
930 WinSalFrame::~WinSalFrame()
932 SalData
* pSalData
= GetSalData();
935 delete [] reinterpret_cast<BYTE
*>(mpClipRgnData
);
937 // remove frame from framelist
938 WinSalFrame
** ppFrame
= &pSalData
->mpFirstFrame
;
939 for(; (*ppFrame
!= this) && *ppFrame
; ppFrame
= &(*ppFrame
)->mpNextFrame
);
941 *ppFrame
= mpNextFrame
;
942 mpNextFrame
= nullptr;
944 // destroy the thread SalGraphics
945 if ( mpThreadGraphics
)
947 ReleaseFrameGraphicsDC( mpThreadGraphics
);
948 delete mpThreadGraphics
;
949 mpThreadGraphics
= nullptr;
952 // destroy the local SalGraphics
953 if ( mpLocalGraphics
)
955 ReleaseFrameGraphicsDC( mpLocalGraphics
);
956 delete mpLocalGraphics
;
957 mpLocalGraphics
= nullptr;
962 // reset mouse leave data
963 if ( pSalData
->mhWantLeaveMsg
== mhWnd
)
965 pSalData
->mhWantLeaveMsg
= nullptr;
966 if ( pSalData
->mpMouseLeaveTimer
)
968 delete pSalData
->mpMouseLeaveTimer
;
969 pSalData
->mpMouseLeaveTimer
= nullptr;
973 // remove windows properties
974 if ( mbPropertiesStored
)
975 SetApplicationID( OUString() );
977 // destroy system frame
978 if ( !DestroyWindow( mhWnd
) )
979 SetWindowPtr( mhWnd
, nullptr );
985 bool WinSalFrame::InitFrameGraphicsDC( WinSalGraphics
*pGraphics
, HDC hDC
, HWND hWnd
)
987 SalData
* pSalData
= GetSalData();
989 pGraphics
->setHWND( hWnd
);
991 HDC hCurrentDC
= pGraphics
->getHDC();
992 assert( !hCurrentDC
|| (hCurrentDC
== hDC
) );
995 pGraphics
->setHDC( hDC
);
1000 if ( pSalData
->mhDitherPal
)
1002 pGraphics
->setDefPal(SelectPalette( hDC
, pSalData
->mhDitherPal
, TRUE
));
1003 RealizePalette( hDC
);
1005 pGraphics
->InitGraphics();
1007 if ( pGraphics
== mpThreadGraphics
)
1008 pSalData
->mnCacheDCInUse
++;
1012 SalGraphics
* WinSalFrame::AcquireGraphics()
1014 if ( mbGraphics
|| !mhWnd
)
1017 SalData
* pSalData
= GetSalData();
1018 WinSalGraphics
*pGraphics
= nullptr;
1021 // Other threads get an own DC, because Windows modify in the
1022 // other case our DC (changing clip region), when they send a
1023 // WM_ERASEBACKGROUND message
1024 if ( !pSalData
->mpInstance
->IsMainThread() )
1026 // We use only three CacheDC's for all threads, because W9x is limited
1027 // to max. 5 Cache DC's per thread
1028 if ( pSalData
->mnCacheDCInUse
>= 3 )
1031 if ( !mpThreadGraphics
)
1032 mpThreadGraphics
= new WinSalGraphics(WinSalGraphics::WINDOW
, true, mhWnd
, this);
1033 pGraphics
= mpThreadGraphics
;
1034 assert( !pGraphics
->getHDC() );
1035 hDC
= reinterpret_cast<HDC
>(static_cast<sal_IntPtr
>(SendMessageW( pSalData
->mpInstance
->mhComWnd
,
1036 SAL_MSG_GETCACHEDDC
, reinterpret_cast<WPARAM
>(mhWnd
), 0 )));
1040 if ( !mpLocalGraphics
)
1041 mpLocalGraphics
= new WinSalGraphics(WinSalGraphics::WINDOW
, true, mhWnd
, this);
1042 pGraphics
= mpLocalGraphics
;
1043 hDC
= pGraphics
->getHDC();
1045 hDC
= GetDC( mhWnd
);
1048 mbGraphics
= InitFrameGraphicsDC( pGraphics
, hDC
, mhWnd
);
1049 return mbGraphics
? pGraphics
: nullptr;
1052 void WinSalFrame::ReleaseGraphics( SalGraphics
* pGraphics
)
1054 if ( mpThreadGraphics
== pGraphics
)
1055 ReleaseFrameGraphicsDC( mpThreadGraphics
);
1059 bool WinSalFrame::PostEvent(std::unique_ptr
<ImplSVEvent
> pData
)
1061 bool const ret
= PostMessageW(mhWnd
, SAL_MSG_USEREVENT
, 0, reinterpret_cast<LPARAM
>(pData
.release()));
1062 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
1066 void WinSalFrame::SetTitle( const OUString
& rTitle
)
1068 static_assert( sizeof( WCHAR
) == sizeof( sal_Unicode
), "must be the same size" );
1070 SetWindowTextW( mhWnd
, o3tl::toW(rTitle
.getStr()) );
1073 void WinSalFrame::SetIcon( sal_uInt16 nIcon
)
1075 // If we have a window without an Icon (for example a dialog), ignore this call
1079 // 0 means default (class) icon
1080 HICON hIcon
= nullptr, hSmIcon
= nullptr;
1084 ImplLoadSalIcon( nIcon
, hIcon
, hSmIcon
);
1086 SAL_WARN_IF( !hIcon
, "vcl", "WinSalFrame::SetIcon(): Could not load large icon !" );
1087 SAL_WARN_IF( !hSmIcon
, "vcl", "WinSalFrame::SetIcon(): Could not load small icon !" );
1089 SendMessageW( mhWnd
, WM_SETICON
, ICON_BIG
, reinterpret_cast<LPARAM
>(hIcon
) );
1090 SendMessageW( mhWnd
, WM_SETICON
, ICON_SMALL
, reinterpret_cast<LPARAM
>(hSmIcon
) );
1093 void WinSalFrame::SetMenu( SalMenu
* pSalMenu
)
1095 WinSalMenu
* pWMenu
= static_cast<WinSalMenu
*>(pSalMenu
);
1096 if( pSalMenu
&& pWMenu
->mbMenuBar
)
1097 ::SetMenu( mhWnd
, pWMenu
->mhMenu
);
1100 void WinSalFrame::DrawMenuBar()
1102 ::DrawMenuBar( mhWnd
);
1105 static HWND
ImplGetParentHwnd( HWND hWnd
)
1107 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
1108 if( !pFrame
|| !pFrame
->GetWindow())
1109 return ::GetParent( hWnd
);
1110 vcl::Window
*pRealParent
= pFrame
->GetWindow()->ImplGetWindowImpl()->mpRealParent
;
1112 return static_cast<WinSalFrame
*>(pRealParent
->ImplGetWindowImpl()->mpFrame
)->mhWnd
;
1114 return ::GetParent( hWnd
);
1118 SalFrame
* WinSalFrame::GetParent() const
1120 return GetWindowPtr( ImplGetParentHwnd( mhWnd
) );
1123 static void ImplSalShow( HWND hWnd
, bool bVisible
, bool bNoActivate
)
1125 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
1131 pFrame
->mbDefPos
= false;
1132 pFrame
->mbOverwriteState
= true;
1133 pFrame
->mbInShow
= true;
1135 // #i4715, save position
1136 RECT aRectPreMatrox
, aRectPostMatrox
;
1137 GetWindowRect( hWnd
, &aRectPreMatrox
);
1139 vcl::DeletionListener
aDogTag( pFrame
);
1141 ShowWindow( hWnd
, SW_SHOWNOACTIVATE
);
1143 ShowWindow( hWnd
, pFrame
->mnShowState
);
1144 if( aDogTag
.isDeleted() )
1147 if (pFrame
->mbFloatWin
&& !(pFrame
->mnStyle
& SalFrameStyleFlags::NOSHADOW
))
1149 // erase the window immediately to improve XP shadow effect
1150 // otherwise the shadow may appears long time before the rest of the window
1151 // especially when accessibility is on
1152 HDC dc
= GetDC( hWnd
);
1154 GetClientRect( hWnd
, &aRect
);
1155 FillRect( dc
, &aRect
, reinterpret_cast<HBRUSH
>(COLOR_MENU
+1) ); // choose the menucolor, because its mostly noticeable for menus
1156 ReleaseDC( hWnd
, dc
);
1159 // #i4715, matrox centerpopup might have changed our position
1160 // reposition popups without caption (menus, dropdowns, tooltips)
1161 GetWindowRect( hWnd
, &aRectPostMatrox
);
1162 if( (GetWindowStyle( hWnd
) & WS_POPUP
) &&
1163 !pFrame
->mbCaption
&&
1164 (aRectPreMatrox
.left
!= aRectPostMatrox
.left
|| aRectPreMatrox
.top
!= aRectPostMatrox
.top
) )
1165 SetWindowPos( hWnd
, nullptr, aRectPreMatrox
.left
, aRectPreMatrox
.top
, 0, 0, SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
);
1167 if( aDogTag
.isDeleted() )
1169 vcl::Window
*pClientWin
= pFrame
->GetWindow()->ImplGetClientWindow();
1170 if ( pFrame
->mbFloatWin
|| ( pClientWin
&& (pClientWin
->GetStyle() & WB_SYSTEMFLOATWIN
) ) )
1171 pFrame
->mnShowState
= SW_SHOWNOACTIVATE
;
1173 pFrame
->mnShowState
= SW_SHOW
;
1174 // hide toolbar for W98
1175 if ( pFrame
->mbPresentation
)
1177 HWND hWndParent
= ::GetParent( hWnd
);
1179 SetForegroundWindow_Impl( hWndParent
);
1180 SetForegroundWindow_Impl( hWnd
);
1183 pFrame
->mbInShow
= false;
1184 pFrame
->updateScreenNumber();
1186 // Direct Paint only, if we get the SolarMutex
1187 if ( ImplSalYieldMutexTryToAcquire() )
1189 UpdateWindow( hWnd
);
1190 ImplSalYieldMutexRelease();
1195 ShowWindow( hWnd
, SW_HIDE
);
1199 void WinSalFrame::SetExtendedFrameStyle( SalExtStyle
)
1203 void WinSalFrame::Show( bool bVisible
, bool bNoActivate
)
1205 // Post this Message to the window, because this only works
1206 // in the thread of the window, which has create this window.
1207 // We post this message to avoid deadlocks
1208 if ( GetSalData()->mnAppThreadId
!= GetCurrentThreadId() )
1210 bool const ret
= PostMessageW(mhWnd
, SAL_MSG_SHOW
, WPARAM(bVisible
), LPARAM(bNoActivate
));
1211 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
1214 ImplSalShow( mhWnd
, bVisible
, bNoActivate
);
1217 void WinSalFrame::SetMinClientSize( tools::Long nWidth
, tools::Long nHeight
)
1219 mnMinWidth
= nWidth
;
1220 mnMinHeight
= nHeight
;
1223 void WinSalFrame::SetMaxClientSize( tools::Long nWidth
, tools::Long nHeight
)
1225 mnMaxWidth
= nWidth
;
1226 mnMaxHeight
= nHeight
;
1229 void WinSalFrame::SetPosSize( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
,
1232 bool bVisible
= (GetWindowStyle( mhWnd
) & WS_VISIBLE
) != 0;
1235 vcl::Window
*pClientWin
= GetWindow()->ImplGetClientWindow();
1236 if ( mbFloatWin
|| ( pClientWin
&& (pClientWin
->GetStyle() & WB_SYSTEMFLOATWIN
) ) )
1237 mnShowState
= SW_SHOWNOACTIVATE
;
1239 mnShowState
= SW_SHOWNORMAL
;
1243 if ( IsIconic( mhWnd
) || IsZoomed( mhWnd
) )
1244 ShowWindow( mhWnd
, SW_RESTORE
);
1247 SalEvent nEvent
= SalEvent::NONE
;
1249 RECT aClientRect
, aWindowRect
;
1250 GetClientRect( mhWnd
, &aClientRect
); // x,y always 0,0, but width and height without border
1251 GetWindowRect( mhWnd
, &aWindowRect
); // x,y in screen coordinates, width and height with border
1253 if ( !(nFlags
& (SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
)) )
1254 nPosSize
|= SWP_NOMOVE
;
1257 //SAL_WARN_IF( !nX || !nY, "vcl", " Windowposition of (0,0) requested!" );
1258 nEvent
= SalEvent::Move
;
1260 if ( !(nFlags
& (SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
)) )
1261 nPosSize
|= SWP_NOSIZE
;
1263 nEvent
= (nEvent
== SalEvent::Move
) ? SalEvent::MoveResize
: SalEvent::Resize
;
1265 if ( !(nFlags
& SAL_FRAME_POSSIZE_X
) )
1266 nX
= aWindowRect
.left
;
1267 if ( !(nFlags
& SAL_FRAME_POSSIZE_Y
) )
1268 nY
= aWindowRect
.top
;
1269 if ( !(nFlags
& SAL_FRAME_POSSIZE_WIDTH
) )
1270 nWidth
= aClientRect
.right
-aClientRect
.left
;
1271 if ( !(nFlags
& SAL_FRAME_POSSIZE_HEIGHT
) )
1272 nHeight
= aClientRect
.bottom
-aClientRect
.top
;
1274 // Calculate window size including the border
1277 aWinRect
.right
= static_cast<int>(nWidth
)-1;
1279 aWinRect
.bottom
= static_cast<int>(nHeight
)-1;
1280 AdjustWindowRectEx( &aWinRect
, GetWindowStyle( mhWnd
),
1281 FALSE
, GetWindowExStyle( mhWnd
) );
1282 nWidth
= aWinRect
.right
- aWinRect
.left
+ 1;
1283 nHeight
= aWinRect
.bottom
- aWinRect
.top
+ 1;
1285 if ( !(nPosSize
& SWP_NOMOVE
) && ::GetParent( mhWnd
) )
1288 GetClientRect( ImplGetParentHwnd( mhWnd
), &aParentRect
);
1289 if( AllSettings::GetLayoutRTL() )
1290 nX
= (aParentRect
.right
- aParentRect
.left
) - nWidth
-1 - nX
;
1292 //#110386#, do not transform coordinates for system child windows
1293 if( !(GetWindowStyle( mhWnd
) & WS_CHILD
) )
1299 HWND parentHwnd
= ImplGetParentHwnd( mhWnd
);
1300 WinSalFrame
* pParentFrame
= GetWindowPtr( parentHwnd
);
1301 if ( pParentFrame
&& pParentFrame
->mnShowState
== SW_SHOWMAXIMIZED
)
1303 // #i42485#: parent will be shown maximized in which case
1304 // a ClientToScreen uses the wrong coordinates (i.e. those from the restore pos)
1305 // so use the (already updated) frame geometry for the transformation
1306 aPt
.x
+= pParentFrame
->maGeometry
.nX
;
1307 aPt
.y
+= pParentFrame
->maGeometry
.nY
;
1310 ClientToScreen( parentHwnd
, &aPt
);
1315 // the position is set
1320 // #i3338# to be conformant to UNIX we must position the client window, ie without the decoration
1321 // #i43250# if the position was read from the system (GetWindowRect(), see above), it must not be modified
1322 if ( nFlags
& SAL_FRAME_POSSIZE_X
)
1323 nX
+= aWinRect
.left
;
1324 if ( nFlags
& SAL_FRAME_POSSIZE_Y
)
1333 ImplSalGetWorkArea( mhWnd
, &aRect
, nullptr );
1334 nScreenX
= aRect
.left
;
1335 nScreenY
= aRect
.top
;
1336 nScreenWidth
= aRect
.right
-aRect
.left
;
1337 nScreenHeight
= aRect
.bottom
-aRect
.top
;
1339 if ( mbDefPos
&& (nPosSize
& SWP_NOMOVE
)) // we got no positioning request, so choose default position
1343 HWND hWndParent
= ::GetParent( mhWnd
);
1344 // Search for TopLevel Frame
1345 while ( hWndParent
&& (GetWindowStyle( hWndParent
) & WS_CHILD
) )
1346 hWndParent
= ::GetParent( hWndParent
);
1347 // if the Window has a Parent, then center the window to
1348 // the parent, in the other case to the screen
1349 if ( hWndParent
&& !IsIconic( hWndParent
) &&
1350 (GetWindowStyle( hWndParent
) & WS_VISIBLE
) )
1353 GetWindowRect( hWndParent
, &aParentRect
);
1354 int nParentWidth
= aParentRect
.right
-aParentRect
.left
;
1355 int nParentHeight
= aParentRect
.bottom
-aParentRect
.top
;
1357 // We don't center, when Parent is smaller than our window
1358 if ( (nParentWidth
-GetSystemMetrics( SM_CXFIXEDFRAME
) <= nWidth
) &&
1359 (nParentHeight
-GetSystemMetrics( SM_CYFIXEDFRAME
) <= nHeight
) )
1361 int nOff
= GetSystemMetrics( SM_CYSIZEFRAME
) + GetSystemMetrics( SM_CYCAPTION
);
1362 nX
= aParentRect
.left
+nOff
;
1363 nY
= aParentRect
.top
+nOff
;
1367 nX
= (nParentWidth
-nWidth
)/2 + aParentRect
.left
;
1368 nY
= (nParentHeight
-nHeight
)/2 + aParentRect
.top
;
1374 GetCursorPos( &pt
);
1378 aRect2
.right
= pt
.x
+2;
1379 aRect2
.bottom
= pt
.y
+2;
1381 // dualmonitor support:
1382 // Get screensize of the monitor with the mouse pointer
1383 ImplSalGetWorkArea( mhWnd
, &aRect2
, &aRect2
);
1385 nX
= ((aRect2
.right
-aRect2
.left
)-nWidth
)/2 + aRect2
.left
;
1386 nY
= ((aRect2
.bottom
-aRect2
.top
)-nHeight
)/2 + aRect2
.top
;
1390 // mbDefPos = FALSE;
1392 mbDefPos
= false; // center only once
1393 nPosSize
&= ~SWP_NOMOVE
; // activate positioning
1394 nEvent
= SalEvent::MoveResize
;
1397 // Adjust Window in the screen
1398 bool bCheckOffScreen
= true;
1400 // but don't do this for floaters or ownerdraw windows that are currently moved interactively
1401 if( (mnStyle
& SalFrameStyleFlags::FLOAT
) && !(mnStyle
& SalFrameStyleFlags::OWNERDRAWDECORATION
) )
1402 bCheckOffScreen
= false;
1404 if( mnStyle
& SalFrameStyleFlags::OWNERDRAWDECORATION
)
1406 // may be the window is currently being moved (mouse is captured), then no check is required
1407 if( mhWnd
== ::GetCapture() )
1408 bCheckOffScreen
= false;
1410 bCheckOffScreen
= true;
1413 if( bCheckOffScreen
)
1415 if ( nX
+nWidth
> nScreenX
+nScreenWidth
)
1416 nX
= (nScreenX
+nScreenWidth
) - nWidth
;
1417 if ( nY
+nHeight
> nScreenY
+nScreenHeight
)
1418 nY
= (nScreenY
+nScreenHeight
) - nHeight
;
1419 if ( nX
< nScreenX
)
1421 if ( nY
< nScreenY
)
1425 UINT nPosFlags
= SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| nPosSize
;
1426 // bring floating windows always to top
1427 if( !(mnStyle
& SalFrameStyleFlags::FLOAT
) )
1428 nPosFlags
|= SWP_NOZORDER
; // do not change z-order
1430 SetWindowPos( mhWnd
, HWND_TOP
, nX
, nY
, static_cast<int>(nWidth
), static_cast<int>(nHeight
), nPosFlags
);
1432 UpdateFrameGeometry( mhWnd
, this );
1434 // Notification -- really ???
1435 if( nEvent
!= SalEvent::NONE
)
1436 CallCallback( nEvent
, nullptr );
1439 void WinSalFrame::ImplSetParentFrame( HWND hNewParentWnd
, bool bAsChild
)
1441 // save hwnd, will be overwritten in WM_CREATE during createwindow
1442 HWND hWndOld
= mhWnd
;
1443 HWND hWndOldParent
= ::GetParent( hWndOld
);
1444 SalData
* pSalData
= GetSalData();
1446 if( hNewParentWnd
== hWndOldParent
)
1449 ::std::vector
< WinSalFrame
* > children
;
1450 ::std::vector
< WinSalObject
* > systemChildren
;
1452 // search child windows
1453 WinSalFrame
*pFrame
= pSalData
->mpFirstFrame
;
1456 HWND hWndParent
= ::GetParent( pFrame
->mhWnd
);
1457 if( mhWnd
== hWndParent
)
1458 children
.push_back( pFrame
);
1459 pFrame
= pFrame
->mpNextFrame
;
1462 // search system child windows (plugins etc.)
1463 WinSalObject
*pObject
= pSalData
->mpFirstObject
;
1466 HWND hWndParent
= ::GetParent( pObject
->mhWnd
);
1467 if( mhWnd
== hWndParent
)
1468 systemChildren
.push_back( pObject
);
1469 pObject
= pObject
->mpNextObject
;
1472 // to recreate the DCs, if they were destroyed
1473 bool bHadLocalGraphics
= false, bHadThreadGraphics
= false;
1475 HFONT hFont
= nullptr;
1476 HPEN hPen
= nullptr;
1477 HBRUSH hBrush
= nullptr;
1479 int oldCount
= pSalData
->mnCacheDCInUse
;
1481 // release the thread DC
1482 if ( mpThreadGraphics
)
1484 // save current gdi objects before hdc is gone
1485 HDC hDC
= mpThreadGraphics
->getHDC();
1488 hFont
= static_cast<HFONT
>(GetCurrentObject( hDC
, OBJ_FONT
));
1489 hPen
= static_cast<HPEN
>(GetCurrentObject( hDC
, OBJ_PEN
));
1490 hBrush
= static_cast<HBRUSH
>(GetCurrentObject( hDC
, OBJ_BRUSH
));
1493 bHadThreadGraphics
= ReleaseFrameGraphicsDC( mpThreadGraphics
);
1494 assert( (bHadThreadGraphics
&& hDC
) || (!bHadThreadGraphics
&& !hDC
) );
1497 // release the local DC
1498 if ( mpLocalGraphics
)
1499 bHadLocalGraphics
= ReleaseFrameGraphicsDC( mpLocalGraphics
);
1501 // create a new hwnd with the same styles
1502 HWND hWndParent
= hNewParentWnd
;
1503 // forward to main thread
1504 HWND hWnd
= reinterpret_cast<HWND
>(static_cast<sal_IntPtr
>(SendMessageW( pSalData
->mpInstance
->mhComWnd
,
1505 bAsChild
? SAL_MSG_RECREATECHILDHWND
: SAL_MSG_RECREATEHWND
,
1506 reinterpret_cast<WPARAM
>(hWndParent
), reinterpret_cast<LPARAM
>(mhWnd
) )));
1509 SAL_WARN_IF( !IsWindow( hWnd
), "vcl", "WinSalFrame::SetParent not successful");
1511 // re-create thread DC
1512 if( bHadThreadGraphics
)
1514 HDC hDC
= reinterpret_cast<HDC
>(static_cast<sal_IntPtr
>(
1515 SendMessageW( pSalData
->mpInstance
->mhComWnd
,
1516 SAL_MSG_GETCACHEDDC
, reinterpret_cast<WPARAM
>(hWnd
), 0 )));
1517 InitFrameGraphicsDC( mpThreadGraphics
, hDC
, hWnd
);
1520 // re-select saved gdi objects
1522 SelectObject( hDC
, hFont
);
1524 SelectObject( hDC
, hPen
);
1526 SelectObject( hDC
, hBrush
);
1528 SAL_WARN_IF( oldCount
!= pSalData
->mnCacheDCInUse
, "vcl", "WinSalFrame::SetParent() hDC count corrupted");
1532 // re-create local DC
1533 if( bHadLocalGraphics
)
1534 InitFrameGraphicsDC( mpLocalGraphics
, GetDC( hWnd
), hWnd
);
1536 // TODO: add SetParent() call for SalObjects
1537 SAL_WARN_IF( !systemChildren
.empty(), "vcl", "WinSalFrame::SetParent() parent of living system child window will be destroyed!");
1539 // reparent children before old parent is destroyed
1540 for (auto & child
: children
)
1541 child
->ImplSetParentFrame( hWnd
, false );
1544 systemChildren
.clear();
1546 // Now destroy original HWND in the thread where it was created.
1547 SendMessageW( GetSalData()->mpInstance
->mhComWnd
,
1548 SAL_MSG_DESTROYHWND
, WPARAM(0), reinterpret_cast<LPARAM
>(hWndOld
));
1551 void WinSalFrame::SetParent( SalFrame
* pNewParent
)
1553 WinSalFrame::mbInReparent
= true;
1554 ImplSetParentFrame( static_cast<WinSalFrame
*>(pNewParent
)->mhWnd
, false );
1555 WinSalFrame::mbInReparent
= false;
1558 bool WinSalFrame::SetPluginParent( SystemParentData
* pNewParent
)
1560 if ( pNewParent
->hWnd
== nullptr )
1562 pNewParent
->hWnd
= GetDesktopWindow();
1565 WinSalFrame::mbInReparent
= true;
1566 ImplSetParentFrame( pNewParent
->hWnd
, true );
1567 WinSalFrame::mbInReparent
= false;
1571 void WinSalFrame::GetWorkArea( tools::Rectangle
&rRect
)
1574 ImplSalGetWorkArea( mhWnd
, &aRect
, nullptr );
1575 rRect
.SetLeft( aRect
.left
);
1576 rRect
.SetRight( aRect
.right
-1 );
1577 rRect
.SetTop( aRect
.top
);
1578 rRect
.SetBottom( aRect
.bottom
-1 );
1581 void WinSalFrame::GetClientSize( tools::Long
& rWidth
, tools::Long
& rHeight
)
1583 rWidth
= maGeometry
.nWidth
;
1584 rHeight
= maGeometry
.nHeight
;
1587 void WinSalFrame::SetWindowState( const SalFrameState
* pState
)
1589 // Check if the window fits into the screen, in case the screen
1590 // resolution changed
1601 ImplSalGetWorkArea( mhWnd
, &aRect
, nullptr );
1602 // #102500# allow some overlap, the window could have been made a little larger than the physical screen
1603 nScreenX
= aRect
.left
-10;
1604 nScreenY
= aRect
.top
-10;
1605 nScreenWidth
= aRect
.right
-aRect
.left
+20;
1606 nScreenHeight
= aRect
.bottom
-aRect
.top
+20;
1610 GetWindowRect( mhWnd
, &aWinRect
);
1612 // to be consistent with Unix, the frame state is without(!) decoration
1613 // ->add the decoration
1614 RECT aRect2
= aWinRect
;
1615 AdjustWindowRectEx( &aRect2
, GetWindowStyle( mhWnd
),
1616 FALSE
, GetWindowExStyle( mhWnd
) );
1617 tools::Long nTopDeco
= abs( aWinRect
.top
- aRect2
.top
);
1618 tools::Long nLeftDeco
= abs( aWinRect
.left
- aRect2
.left
);
1619 tools::Long nBottomDeco
= abs( aWinRect
.bottom
- aRect2
.bottom
);
1620 tools::Long nRightDeco
= abs( aWinRect
.right
- aRect2
.right
);
1622 // adjust window position/size to fit the screen
1623 if ( !(pState
->mnMask
& (WindowStateMask::X
| WindowStateMask::Y
)) )
1624 nPosSize
|= SWP_NOMOVE
;
1625 if ( !(pState
->mnMask
& (WindowStateMask::Width
| WindowStateMask::Height
)) )
1626 nPosSize
|= SWP_NOSIZE
;
1627 if ( pState
->mnMask
& WindowStateMask::X
)
1628 nX
= static_cast<int>(pState
->mnX
) - nLeftDeco
;
1631 if ( pState
->mnMask
& WindowStateMask::Y
)
1632 nY
= static_cast<int>(pState
->mnY
) - nTopDeco
;
1635 if ( pState
->mnMask
& WindowStateMask::Width
)
1636 nWidth
= static_cast<int>(pState
->mnWidth
) + nLeftDeco
+ nRightDeco
;
1638 nWidth
= aWinRect
.right
-aWinRect
.left
;
1639 if ( pState
->mnMask
& WindowStateMask::Height
)
1640 nHeight
= static_cast<int>(pState
->mnHeight
) + nTopDeco
+ nBottomDeco
;
1642 nHeight
= aWinRect
.bottom
-aWinRect
.top
;
1644 // Adjust Window in the screen:
1645 // if it does not fit into the screen do nothing, ie default pos/size will be used
1646 // if there is an overlap with the screen border move the window while keeping its size
1648 if( nWidth
> nScreenWidth
|| nHeight
> nScreenHeight
)
1649 nPosSize
|= (SWP_NOMOVE
| SWP_NOSIZE
);
1651 if ( nX
+nWidth
> nScreenX
+nScreenWidth
)
1652 nX
= (nScreenX
+nScreenWidth
) - nWidth
;
1653 if ( nY
+nHeight
> nScreenY
+nScreenHeight
)
1654 nY
= (nScreenY
+nScreenHeight
) - nHeight
;
1655 if ( nX
< nScreenX
)
1657 if ( nY
< nScreenY
)
1660 // set Restore-Position
1661 WINDOWPLACEMENT aPlacement
;
1662 aPlacement
.length
= sizeof( aPlacement
);
1663 GetWindowPlacement( mhWnd
, &aPlacement
);
1666 bool bVisible
= (GetWindowStyle( mhWnd
) & WS_VISIBLE
) != 0;
1667 bool bUpdateHiddenFramePos
= false;
1670 aPlacement
.showCmd
= SW_HIDE
;
1672 if ( mbOverwriteState
)
1674 if ( pState
->mnMask
& WindowStateMask::State
)
1676 if ( pState
->mnState
& WindowStateState::Minimized
)
1677 mnShowState
= SW_SHOWMINIMIZED
;
1678 else if ( pState
->mnState
& WindowStateState::Maximized
)
1680 mnShowState
= SW_SHOWMAXIMIZED
;
1681 bUpdateHiddenFramePos
= true;
1683 else if ( pState
->mnState
& WindowStateState::Normal
)
1684 mnShowState
= SW_SHOWNORMAL
;
1690 if ( pState
->mnMask
& WindowStateMask::State
)
1692 if ( pState
->mnState
& WindowStateState::Minimized
)
1694 if ( pState
->mnState
& WindowStateState::Maximized
)
1695 aPlacement
.flags
|= WPF_RESTORETOMAXIMIZED
;
1696 aPlacement
.showCmd
= SW_SHOWMINIMIZED
;
1698 else if ( pState
->mnState
& WindowStateState::Maximized
)
1699 aPlacement
.showCmd
= SW_SHOWMAXIMIZED
;
1700 else if ( pState
->mnState
& WindowStateState::Normal
)
1701 aPlacement
.showCmd
= SW_RESTORE
;
1705 // if a window is neither minimized nor maximized or need not be
1706 // positioned visibly (that is in visible state), do not use
1707 // SetWindowPlacement since it calculates including the TaskBar
1708 if ( !IsIconic( mhWnd
) && !IsZoomed( mhWnd
) &&
1709 (!bVisible
|| (aPlacement
.showCmd
== SW_RESTORE
)) )
1711 if( bUpdateHiddenFramePos
)
1714 aStateRect
.left
= nX
;
1715 aStateRect
.top
= nY
;
1716 aStateRect
.right
= nX
+nWidth
;
1717 aStateRect
.bottom
= nY
+nHeight
;
1718 // #96084 set a useful internal window size because
1719 // the window will not be maximized (and the size updated) before show()
1720 SetMaximizedFrameGeometry( mhWnd
, this, &aStateRect
);
1721 SetWindowPos( mhWnd
, nullptr,
1722 maGeometry
.nX
, maGeometry
.nY
, maGeometry
.nWidth
, maGeometry
.nHeight
,
1723 SWP_NOZORDER
| SWP_NOACTIVATE
| nPosSize
);
1726 SetWindowPos( mhWnd
, nullptr,
1727 nX
, nY
, nWidth
, nHeight
,
1728 SWP_NOZORDER
| SWP_NOACTIVATE
| nPosSize
);
1732 if( !(nPosSize
& (SWP_NOMOVE
|SWP_NOSIZE
)) )
1734 aPlacement
.rcNormalPosition
.left
= nX
-nScreenX
;
1735 aPlacement
.rcNormalPosition
.top
= nY
-nScreenY
;
1736 aPlacement
.rcNormalPosition
.right
= nX
+nWidth
-nScreenX
;
1737 aPlacement
.rcNormalPosition
.bottom
= nY
+nHeight
-nScreenY
;
1739 SetWindowPlacement( mhWnd
, &aPlacement
);
1742 if( !(nPosSize
& SWP_NOMOVE
) )
1743 mbDefPos
= false; // window was positioned
1746 bool WinSalFrame::GetWindowState( SalFrameState
* pState
)
1748 if ( maState
.mnWidth
&& maState
.mnHeight
)
1751 // #94144# allow Minimize again, should be masked out when read from configuration
1752 // 91625 - Don't save minimize
1753 //if ( !(pState->mnState & WindowStateState::Maximized) )
1754 if ( !(pState
->mnState
& (WindowStateState::Minimized
| WindowStateState::Maximized
)) )
1755 pState
->mnState
|= WindowStateState::Normal
;
1762 void WinSalFrame::SetScreenNumber( unsigned int nNewScreen
)
1764 WinSalSystem
* pSys
= static_cast<WinSalSystem
*>(ImplGetSalSystem());
1767 const std::vector
<WinSalSystem::DisplayMonitor
>& rMonitors
=
1768 pSys
->getMonitors();
1769 size_t nMon
= rMonitors
.size();
1770 if( nNewScreen
< nMon
)
1772 Point aOldMonPos
, aNewMonPos( rMonitors
[nNewScreen
].m_aArea
.TopLeft() );
1773 Point
aCurPos( maGeometry
.nX
, maGeometry
.nY
);
1774 for( size_t i
= 0; i
< nMon
; i
++ )
1776 if( rMonitors
[i
].m_aArea
.IsInside( aCurPos
) )
1778 aOldMonPos
= rMonitors
[i
].m_aArea
.TopLeft();
1782 mnDisplay
= nNewScreen
;
1783 maGeometry
.nDisplayScreenNumber
= nNewScreen
;
1784 SetPosSize( aNewMonPos
.X() + (maGeometry
.nX
- aOldMonPos
.X()),
1785 aNewMonPos
.Y() + (maGeometry
.nY
- aOldMonPos
.Y()),
1787 SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
);
1792 void WinSalFrame::SetApplicationID( const OUString
&rApplicationID
)
1794 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd378430(v=vs.85).aspx
1795 // A window's properties must be removed before the window is closed.
1797 IPropertyStore
*pps
;
1798 HRESULT hr
= SHGetPropertyStoreForWindow(mhWnd
, IID_PPV_ARGS(&pps
));
1802 if (!rApplicationID
.isEmpty())
1804 hr
= InitPropVariantFromString(o3tl::toW(rApplicationID
.getStr()), &pv
);
1805 mbPropertiesStored
= true;
1808 // if rApplicationID we remove the property from the window, if present
1809 PropVariantInit(&pv
);
1813 hr
= pps
->SetValue(PKEY_AppUserModel_ID
, pv
);
1814 PropVariantClear(&pv
);
1820 void WinSalFrame::ShowFullScreen( bool bFullScreen
, sal_Int32 nDisplay
)
1822 if ( (mbFullScreen
== bFullScreen
) && (!bFullScreen
|| (mnDisplay
== nDisplay
)) )
1825 mbFullScreen
= bFullScreen
;
1826 mnDisplay
= nDisplay
;
1830 // to hide the Windows taskbar
1831 DWORD nExStyle
= GetWindowExStyle( mhWnd
);
1832 if ( nExStyle
& WS_EX_TOOLWINDOW
)
1834 mbFullScreenToolWin
= true;
1835 nExStyle
&= ~WS_EX_TOOLWINDOW
;
1836 SetWindowExStyle( mhWnd
, nExStyle
);
1838 // save old position
1839 GetWindowRect( mhWnd
, &maFullScreenRect
);
1842 mnFullScreenShowState
= mnShowState
;
1843 if ( !(GetWindowStyle( mhWnd
) & WS_VISIBLE
) )
1844 mnShowState
= SW_SHOW
;
1846 // Save caption state.
1847 mbFullScreenCaption
= mbCaption
;
1850 DWORD nStyle
= GetWindowStyle(mhWnd
);
1851 SetWindowStyle(mhWnd
, nStyle
& ~WS_CAPTION
);
1855 // set window to screen size
1856 ImplSalFrameFullScreenPos( this, true );
1860 // when the ShowState has to be reset, hide the window first to
1862 bool bVisible
= (GetWindowStyle( mhWnd
) & WS_VISIBLE
) != 0;
1863 if ( bVisible
&& (mnShowState
!= mnFullScreenShowState
) )
1864 ShowWindow( mhWnd
, SW_HIDE
);
1866 if ( mbFullScreenToolWin
)
1867 SetWindowExStyle( mhWnd
, GetWindowExStyle( mhWnd
) | WS_EX_TOOLWINDOW
);
1868 mbFullScreenToolWin
= false;
1870 // Restore caption state.
1871 if (mbFullScreenCaption
)
1873 DWORD nStyle
= GetWindowStyle(mhWnd
);
1874 SetWindowStyle(mhWnd
, nStyle
| WS_CAPTION
);
1876 mbCaption
= mbFullScreenCaption
;
1878 SetWindowPos( mhWnd
, nullptr,
1879 maFullScreenRect
.left
,
1880 maFullScreenRect
.top
,
1881 maFullScreenRect
.right
-maFullScreenRect
.left
,
1882 maFullScreenRect
.bottom
-maFullScreenRect
.top
,
1883 SWP_NOZORDER
| SWP_NOACTIVATE
);
1885 // restore show state
1886 if ( mnShowState
!= mnFullScreenShowState
)
1888 mnShowState
= mnFullScreenShowState
;
1892 ShowWindow( mhWnd
, mnShowState
);
1894 UpdateWindow( mhWnd
);
1900 void WinSalFrame::StartPresentation( bool bStart
)
1902 if ( mbPresentation
== bStart
)
1905 mbPresentation
= bStart
;
1907 SalData
* pSalData
= GetSalData();
1910 // turn off screen-saver when in Presentation mode
1911 SystemParametersInfoW( SPI_GETSCREENSAVEACTIVE
, 0,
1912 &(pSalData
->mbScrSvrEnabled
), 0 );
1913 if ( pSalData
->mbScrSvrEnabled
)
1914 SystemParametersInfoW( SPI_SETSCREENSAVEACTIVE
, FALSE
, nullptr, 0 );
1918 // turn on screen-saver
1919 if ( pSalData
->mbScrSvrEnabled
)
1920 SystemParametersInfoW( SPI_SETSCREENSAVEACTIVE
, pSalData
->mbScrSvrEnabled
, nullptr, 0 );
1924 void WinSalFrame::SetAlwaysOnTop( bool bOnTop
)
1928 hWnd
= HWND_TOPMOST
;
1930 hWnd
= HWND_NOTOPMOST
;
1931 SetWindowPos( mhWnd
, hWnd
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1934 static bool EnableAttachThreadInputHack()
1936 OUString aBootstrapUri
;
1937 if (osl_getProcessWorkingDir(&aBootstrapUri
.pData
) != osl_Process_E_None
)
1939 aBootstrapUri
+= "/bootstrap.ini";
1941 OUString aSystemFileName
;
1942 if (osl::FileBase::getSystemPathFromFileURL(aBootstrapUri
, aSystemFileName
) != osl::FileBase::E_None
)
1944 if (aSystemFileName
.getLength() > MAX_PATH
)
1947 // this uses the Boost ini parser, instead of tools::Config, as we already use it to read other
1948 // values from bootstrap.ini in desktop/win32/source/loader.cxx, because that watchdog process
1949 // can't access LO libs. This way the handling is consistent.
1952 boost::property_tree::ptree pt
;
1953 std::ifstream
aFile(o3tl::toW(aSystemFileName
.getStr()));
1954 boost::property_tree::ini_parser::read_ini(aFile
, pt
);
1955 const bool bEnabled
= pt
.get("Win32.EnableAttachThreadInputHack", false);
1956 SAL_WARN_IF(bEnabled
, "vcl", "AttachThreadInput hack is enabled. Watch out for deadlocks!");
1965 static void ImplSalToTop( HWND hWnd
, SalFrameToTop nFlags
)
1967 static const bool bEnableAttachThreadInputHack
= EnableAttachThreadInputHack();
1969 WinSalFrame
* pToTopFrame
= GetWindowPtr( hWnd
);
1970 if( pToTopFrame
&& (pToTopFrame
->mnStyle
& SalFrameStyleFlags::SYSTEMCHILD
) )
1971 BringWindowToTop( hWnd
);
1973 if ( nFlags
& SalFrameToTop::ForegroundTask
)
1975 // LO used to always call AttachThreadInput here, which resulted in deadlocks
1976 // in some installations for unknown reasons!
1977 if (bEnableAttachThreadInputHack
)
1979 // This magic code is necessary to connect the input focus of the
1980 // current window thread and the thread which owns the window that
1981 // should be the new foreground window.
1982 HWND hCurrWnd
= GetForegroundWindow();
1983 DWORD myThreadID
= GetCurrentThreadId();
1984 DWORD currThreadID
= GetWindowThreadProcessId(hCurrWnd
,nullptr);
1985 AttachThreadInput(myThreadID
, currThreadID
, TRUE
);
1986 SetForegroundWindow_Impl(hWnd
);
1987 AttachThreadInput(myThreadID
, currThreadID
, FALSE
);
1990 SetForegroundWindow_Impl(hWnd
);
1993 if ( nFlags
& SalFrameToTop::RestoreWhenMin
)
1995 HWND hIconicWnd
= hWnd
;
1996 while ( hIconicWnd
)
1998 if ( IsIconic( hIconicWnd
) )
2000 WinSalFrame
* pFrame
= GetWindowPtr( hIconicWnd
);
2003 if ( GetWindowPtr( hWnd
)->mbRestoreMaximize
)
2004 ShowWindow( hIconicWnd
, SW_MAXIMIZE
);
2006 ShowWindow( hIconicWnd
, SW_RESTORE
);
2009 ShowWindow( hIconicWnd
, SW_RESTORE
);
2012 hIconicWnd
= ::GetParent( hIconicWnd
);
2016 if ( !IsIconic( hWnd
) && IsWindowVisible( hWnd
) )
2020 // Windows sometimes incorrectly reports to have the focus;
2021 // thus make sure to really get the focus
2022 if ( ::GetFocus() == hWnd
)
2023 SetForegroundWindow_Impl( hWnd
);
2027 void WinSalFrame::ToTop( SalFrameToTop nFlags
)
2029 nFlags
&= ~SalFrameToTop::GrabFocus
; // this flag is not needed on win32
2030 // Post this Message to the window, because this only works
2031 // in the thread of the window, which has create this window.
2032 // We post this message to avoid deadlocks
2033 if ( GetSalData()->mnAppThreadId
!= GetCurrentThreadId() )
2035 bool const ret
= PostMessageW( mhWnd
, SAL_MSG_TOTOP
, static_cast<WPARAM
>(nFlags
), 0 );
2036 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
2039 ImplSalToTop( mhWnd
, nFlags
);
2042 void WinSalFrame::SetPointer( PointerStyle ePointerStyle
)
2051 static o3tl::enumarray
<PointerStyle
, ImplPtrData
> aImplPtrTab
=
2053 ImplPtrData
{ nullptr, IDC_ARROW
, 0 }, // POINTER_ARROW
2054 { nullptr, nullptr, SAL_RESID_POINTER_NULL
}, // POINTER_NULL
2055 { nullptr, IDC_WAIT
, 0 }, // POINTER_WAIT
2056 { nullptr, IDC_IBEAM
, 0 }, // POINTER_TEXT
2057 { nullptr, IDC_HELP
, 0 }, // POINTER_HELP
2058 { nullptr, IDC_CROSS
, 0 }, // POINTER_CROSS
2059 { nullptr, IDC_SIZEALL
, 0 }, // POINTER_MOVE
2060 { nullptr, IDC_SIZENS
, 0 }, // POINTER_NSIZE
2061 { nullptr, IDC_SIZENS
, 0 }, // POINTER_SSIZE
2062 { nullptr, IDC_SIZEWE
, 0 }, // POINTER_WSIZE
2063 { nullptr, IDC_SIZEWE
, 0 }, // POINTER_ESIZE
2064 { nullptr, IDC_SIZENWSE
, 0 }, // POINTER_NWSIZE
2065 { nullptr, IDC_SIZENESW
, 0 }, // POINTER_NESIZE
2066 { nullptr, IDC_SIZENESW
, 0 }, // POINTER_SWSIZE
2067 { nullptr, IDC_SIZENWSE
, 0 }, // POINTER_SESIZE
2068 { nullptr, IDC_SIZENS
, 0 }, // POINTER_WINDOW_NSIZE
2069 { nullptr, IDC_SIZENS
, 0 }, // POINTER_WINDOW_SSIZE
2070 { nullptr, IDC_SIZEWE
, 0 }, // POINTER_WINDOW_WSIZE
2071 { nullptr, IDC_SIZEWE
, 0 }, // POINTER_WINDOW_ESIZE
2072 { nullptr, IDC_SIZENWSE
, 0 }, // POINTER_WINDOW_NWSIZE
2073 { nullptr, IDC_SIZENESW
, 0 }, // POINTER_WINDOW_NESIZE
2074 { nullptr, IDC_SIZENESW
, 0 }, // POINTER_WINDOW_SWSIZE
2075 { nullptr, IDC_SIZENWSE
, 0 }, // POINTER_WINDOW_SESIZE
2076 { nullptr, IDC_SIZEWE
, 0 }, // POINTER_HSPLIT
2077 { nullptr, IDC_SIZENS
, 0 }, // POINTER_VSPLIT
2078 { nullptr, IDC_SIZEWE
, 0 }, // POINTER_HSIZEBAR
2079 { nullptr, IDC_SIZENS
, 0 }, // POINTER_VSIZEBAR
2080 { nullptr, IDC_HAND
, 0 }, // POINTER_HAND
2081 { nullptr, IDC_HAND
, 0 }, // POINTER_REFHAND
2082 { nullptr, IDC_PEN
, 0 }, // POINTER_PEN
2083 { nullptr, nullptr, SAL_RESID_POINTER_MAGNIFY
}, // POINTER_MAGNIFY
2084 { nullptr, nullptr, SAL_RESID_POINTER_FILL
}, // POINTER_FILL
2085 { nullptr, nullptr, SAL_RESID_POINTER_ROTATE
}, // POINTER_ROTATE
2086 { nullptr, nullptr, SAL_RESID_POINTER_HSHEAR
}, // POINTER_HSHEAR
2087 { nullptr, nullptr, SAL_RESID_POINTER_VSHEAR
}, // POINTER_VSHEAR
2088 { nullptr, nullptr, SAL_RESID_POINTER_MIRROR
}, // POINTER_MIRROR
2089 { nullptr, nullptr, SAL_RESID_POINTER_CROOK
}, // POINTER_CROOK
2090 { nullptr, nullptr, SAL_RESID_POINTER_CROP
}, // POINTER_CROP
2091 { nullptr, nullptr, SAL_RESID_POINTER_MOVEPOINT
}, // POINTER_MOVEPOINT
2092 { nullptr, nullptr, SAL_RESID_POINTER_MOVEBEZIERWEIGHT
}, // POINTER_MOVEBEZIERWEIGHT
2093 { nullptr, nullptr, SAL_RESID_POINTER_MOVEDATA
}, // POINTER_MOVEDATA
2094 { nullptr, nullptr, SAL_RESID_POINTER_COPYDATA
}, // POINTER_COPYDATA
2095 { nullptr, nullptr, SAL_RESID_POINTER_LINKDATA
}, // POINTER_LINKDATA
2096 { nullptr, nullptr, SAL_RESID_POINTER_MOVEDATALINK
}, // POINTER_MOVEDATALINK
2097 { nullptr, nullptr, SAL_RESID_POINTER_COPYDATALINK
}, // POINTER_COPYDATALINK
2098 { nullptr, nullptr, SAL_RESID_POINTER_MOVEFILE
}, // POINTER_MOVEFILE
2099 { nullptr, nullptr, SAL_RESID_POINTER_COPYFILE
}, // POINTER_COPYFILE
2100 { nullptr, nullptr, SAL_RESID_POINTER_LINKFILE
}, // POINTER_LINKFILE
2101 { nullptr, nullptr, SAL_RESID_POINTER_MOVEFILELINK
}, // POINTER_MOVEFILELINK
2102 { nullptr, nullptr, SAL_RESID_POINTER_COPYFILELINK
}, // POINTER_COPYFILELINK
2103 { nullptr, nullptr, SAL_RESID_POINTER_MOVEFILES
}, // POINTER_MOVEFILES
2104 { nullptr, nullptr, SAL_RESID_POINTER_COPYFILES
}, // POINTER_COPYFILES
2105 { nullptr, IDC_NO
, 0 }, // POINTER_NOTALLOWED
2106 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_LINE
}, // POINTER_DRAW_LINE
2107 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_RECT
}, // POINTER_DRAW_RECT
2108 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_POLYGON
}, // POINTER_DRAW_POLYGON
2109 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_BEZIER
}, // POINTER_DRAW_BEZIER
2110 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_ARC
}, // POINTER_DRAW_ARC
2111 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_PIE
}, // POINTER_DRAW_PIE
2112 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_CIRCLECUT
}, // POINTER_DRAW_CIRCLECUT
2113 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_ELLIPSE
}, // POINTER_DRAW_ELLIPSE
2114 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_FREEHAND
}, // POINTER_DRAW_FREEHAND
2115 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_CONNECT
}, // POINTER_DRAW_CONNECT
2116 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_TEXT
}, // POINTER_DRAW_TEXT
2117 { nullptr, nullptr, SAL_RESID_POINTER_DRAW_CAPTION
}, // POINTER_DRAW_CAPTION
2118 { nullptr, nullptr, SAL_RESID_POINTER_CHART
}, // POINTER_CHART
2119 { nullptr, nullptr, SAL_RESID_POINTER_DETECTIVE
}, // POINTER_DETECTIVE
2120 { nullptr, nullptr, SAL_RESID_POINTER_PIVOT_COL
}, // POINTER_PIVOT_COL
2121 { nullptr, nullptr, SAL_RESID_POINTER_PIVOT_ROW
}, // POINTER_PIVOT_ROW
2122 { nullptr, nullptr, SAL_RESID_POINTER_PIVOT_FIELD
}, // POINTER_PIVOT_FIELD
2123 { nullptr, nullptr, SAL_RESID_POINTER_CHAIN
}, // POINTER_CHAIN
2124 { nullptr, nullptr, SAL_RESID_POINTER_CHAIN_NOTALLOWED
}, // POINTER_CHAIN_NOTALLOWED
2125 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_N
}, // POINTER_AUTOSCROLL_N
2126 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_S
}, // POINTER_AUTOSCROLL_S
2127 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_W
}, // POINTER_AUTOSCROLL_W
2128 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_E
}, // POINTER_AUTOSCROLL_E
2129 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NW
}, // POINTER_AUTOSCROLL_NW
2130 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NE
}, // POINTER_AUTOSCROLL_NE
2131 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_SW
}, // POINTER_AUTOSCROLL_SW
2132 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_SE
}, // POINTER_AUTOSCROLL_SE
2133 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NS
}, // POINTER_AUTOSCROLL_NS
2134 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_WE
}, // POINTER_AUTOSCROLL_WE
2135 { nullptr, nullptr, SAL_RESID_POINTER_AUTOSCROLL_NSWE
}, // POINTER_AUTOSCROLL_NSWE
2136 { nullptr, nullptr, SAL_RESID_POINTER_TEXT_VERTICAL
}, // POINTER_TEXT_VERTICAL
2137 { nullptr, nullptr, SAL_RESID_POINTER_PIVOT_DELETE
}, // POINTER_PIVOT_DELETE
2140 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_S
}, // POINTER_TAB_SELECT_S
2141 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_E
}, // POINTER_TAB_SELECT_E
2142 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_SE
}, // POINTER_TAB_SELECT_SE
2143 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_W
}, // POINTER_TAB_SELECT_W
2144 { nullptr, nullptr, SAL_RESID_POINTER_TAB_SELECT_SW
}, // POINTER_TAB_SELECT_SW
2146 { nullptr, nullptr, SAL_RESID_POINTER_HIDEWHITESPACE
}, // POINTER_HIDEWHITESPACE
2147 { nullptr, nullptr, SAL_RESID_POINTER_SHOWWHITESPACE
} // POINTER_UNHIDEWHITESPACE
2150 // Mousepointer loaded ?
2151 if ( !aImplPtrTab
[ePointerStyle
].mhCursor
)
2153 if ( aImplPtrTab
[ePointerStyle
].mnOwnId
)
2154 aImplPtrTab
[ePointerStyle
].mhCursor
= ImplLoadSalCursor( aImplPtrTab
[ePointerStyle
].mnOwnId
);
2156 aImplPtrTab
[ePointerStyle
].mhCursor
= LoadCursor( nullptr, aImplPtrTab
[ePointerStyle
].mnSysId
);
2159 // change the mouse pointer if different
2160 if ( mhCursor
!= aImplPtrTab
[ePointerStyle
].mhCursor
)
2162 mhCursor
= aImplPtrTab
[ePointerStyle
].mhCursor
;
2163 SetCursor( mhCursor
);
2167 void WinSalFrame::CaptureMouse( bool bCapture
)
2169 // Send this Message to the window, because CaptureMouse() only work
2170 // in the thread of the window, which has create this window
2173 nMsg
= SAL_MSG_CAPTUREMOUSE
;
2175 nMsg
= SAL_MSG_RELEASEMOUSE
;
2176 SendMessageW( mhWnd
, nMsg
, 0, 0 );
2179 void WinSalFrame::SetPointerPos( tools::Long nX
, tools::Long nY
)
2182 aPt
.x
= static_cast<int>(nX
);
2183 aPt
.y
= static_cast<int>(nY
);
2184 ClientToScreen( mhWnd
, &aPt
);
2185 SetCursorPos( aPt
.x
, aPt
.y
);
2188 void WinSalFrame::Flush()
2191 mpLocalGraphics
->Flush();
2192 if(mpThreadGraphics
)
2193 mpThreadGraphics
->Flush();
2197 static void ImplSalFrameSetInputContext( HWND hWnd
, const SalInputContext
* pContext
)
2199 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
2200 bool bIME(pContext
->mnOptions
& InputContextFlags::Text
);
2203 if ( !pFrame
->mbIME
)
2205 pFrame
->mbIME
= true;
2207 if ( pFrame
->mhDefIMEContext
)
2209 ImmAssociateContext( pFrame
->mhWnd
, pFrame
->mhDefIMEContext
);
2210 UINT nImeProps
= ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY
);
2211 pFrame
->mbSpezIME
= (nImeProps
& IME_PROP_SPECIAL_UI
) != 0;
2212 pFrame
->mbAtCursorIME
= (nImeProps
& IME_PROP_AT_CARET
) != 0;
2213 pFrame
->mbHandleIME
= !pFrame
->mbSpezIME
;
2217 // When the application can't handle IME messages, then the
2218 // System should handle the IME handling
2219 if ( !(pContext
->mnOptions
& InputContextFlags::ExtText
) )
2220 pFrame
->mbHandleIME
= false;
2222 // Set the Font for IME Handling
2223 if ( pContext
->mpFont
)
2225 HIMC hIMC
= ImmGetContext( pFrame
->mhWnd
);
2229 HDC hDC
= GetDC( pFrame
->mhWnd
);
2230 // In case of vertical writing, always append a '@' to the
2231 // Windows font name, not only if such a Windows font really is
2232 // available (bTestVerticalAvail == false in the below call):
2233 // The Windows IME's candidates window seems to always use a
2234 // font that has all necessary glyphs, not necessarily the one
2235 // specified by this font name; but it seems to decide whether
2236 // to use that font's horizontal or vertical variant based on a
2237 // '@' in front of this font name.
2238 ImplGetLogFontFromFontSelect(hDC
, pContext
->mpFont
->GetFontSelectPattern(),
2240 ReleaseDC( pFrame
->mhWnd
, hDC
);
2241 ImmSetCompositionFontW( hIMC
, &aLogFont
);
2242 ImmReleaseContext( pFrame
->mhWnd
, hIMC
);
2248 if ( pFrame
->mbIME
)
2250 pFrame
->mbIME
= false;
2251 pFrame
->mbHandleIME
= false;
2252 ImmAssociateContext( pFrame
->mhWnd
, nullptr );
2257 void WinSalFrame::SetInputContext( SalInputContext
* pContext
)
2259 // Must be called in the main thread!
2260 SendMessageW( mhWnd
, SAL_MSG_SETINPUTCONTEXT
, 0, reinterpret_cast<LPARAM
>(pContext
) );
2263 static void ImplSalFrameEndExtTextInput( HWND hWnd
, EndExtTextInputFlags nFlags
)
2265 HIMC hIMC
= ImmGetContext( hWnd
);
2269 if ( nFlags
& EndExtTextInputFlags::Complete
)
2270 nIndex
= CPS_COMPLETE
;
2272 nIndex
= CPS_CANCEL
;
2274 ImmNotifyIME( hIMC
, NI_COMPOSITIONSTR
, nIndex
, 0 );
2275 ImmReleaseContext( hWnd
, hIMC
);
2279 void WinSalFrame::EndExtTextInput( EndExtTextInputFlags nFlags
)
2281 // Must be called in the main thread!
2282 SendMessageW( mhWnd
, SAL_MSG_ENDEXTTEXTINPUT
, static_cast<WPARAM
>(nFlags
), 0 );
2285 static void ImplGetKeyNameText( LONG lParam
, sal_Unicode
* pBuf
,
2286 UINT
& rCount
, UINT nMaxSize
,
2287 const char* pReplace
)
2289 static_assert( sizeof( WCHAR
) == sizeof( sal_Unicode
), "must be the same size" );
2291 static const int nMaxKeyLen
= 350;
2292 WCHAR aKeyBuf
[ nMaxKeyLen
];
2296 OUString aLang
= Application::GetSettings().GetUILanguageTag().getLanguage();
2299 aRet
= ::vcl_sal::getKeysReplacementName( aLang
, lParam
);
2300 if( aRet
.isEmpty() )
2302 nKeyLen
= GetKeyNameTextW( lParam
, aKeyBuf
, nMaxKeyLen
);
2303 SAL_WARN_IF( nKeyLen
> nMaxKeyLen
, "vcl", "Invalid key name length!" );
2304 if( nKeyLen
> nMaxKeyLen
)
2306 else if( nKeyLen
> 0 )
2308 // Capitalize just the first letter of key names
2309 CharLowerBuffW( aKeyBuf
, nKeyLen
);
2312 for( WCHAR
*pW
=aKeyBuf
, *pE
=pW
+nKeyLen
; pW
< pE
; ++pW
)
2315 CharUpperBuffW( pW
, 1 );
2316 bUpper
= (*pW
=='+') || (*pW
=='-') || (*pW
==' ') || (*pW
=='.');
2322 nKeyLen
= aRet
.getLength();
2323 wcscpy( aKeyBuf
, o3tl::toW( aRet
.getStr() ));
2327 if ( (nKeyLen
> 0) || pReplace
)
2329 if( (rCount
> 0) && (rCount
< nMaxSize
) )
2337 WCHAR
*pW
= aKeyBuf
, *pE
= aKeyBuf
+ nKeyLen
;
2338 while ((pW
< pE
) && *pW
&& (rCount
< nMaxSize
))
2339 pBuf
[rCount
++] = *pW
++;
2341 else // fall back to provided default name
2343 while( *pReplace
&& (rCount
< nMaxSize
) )
2345 pBuf
[rCount
] = *pReplace
;
2355 OUString
WinSalFrame::GetKeyName( sal_uInt16 nKeyCode
)
2357 static const UINT nMaxKeyLen
= 350;
2358 sal_Unicode aKeyBuf
[ nMaxKeyLen
];
2359 UINT nKeyBufLen
= 0;
2362 if ( nKeyCode
& KEY_MOD1
)
2364 nSysCode
= MapVirtualKeyW( VK_CONTROL
, 0 );
2365 nSysCode
= (nSysCode
<< 16) | ((sal_uLong(1)) << 25);
2366 ImplGetKeyNameText( nSysCode
, aKeyBuf
, nKeyBufLen
, nMaxKeyLen
, "Ctrl" );
2369 if ( nKeyCode
& KEY_MOD2
)
2371 nSysCode
= MapVirtualKeyW( VK_MENU
, 0 );
2372 nSysCode
= (nSysCode
<< 16) | ((sal_uLong(1)) << 25);
2373 ImplGetKeyNameText( nSysCode
, aKeyBuf
, nKeyBufLen
, nMaxKeyLen
, "Alt" );
2376 if ( nKeyCode
& KEY_SHIFT
)
2378 nSysCode
= MapVirtualKeyW( VK_SHIFT
, 0 );
2379 nSysCode
= (nSysCode
<< 16) | ((sal_uLong(1)) << 25);
2380 ImplGetKeyNameText( nSysCode
, aKeyBuf
, nKeyBufLen
, nMaxKeyLen
, "Shift" );
2383 sal_uInt16 nCode
= nKeyCode
& 0x0FFF;
2384 sal_uLong nSysCode2
= 0;
2385 const char* pReplace
= nullptr;
2386 sal_Unicode cSVCode
= 0;
2390 if ( (nCode
>= KEY_0
) && (nCode
<= KEY_9
) )
2391 cSVCode
= '0' + (nCode
- KEY_0
);
2392 else if ( (nCode
>= KEY_A
) && (nCode
<= KEY_Z
) )
2393 cSVCode
= 'A' + (nCode
- KEY_A
);
2394 else if ( (nCode
>= KEY_F1
) && (nCode
<= KEY_F26
) )
2396 nSysCode
= VK_F1
+ (nCode
- KEY_F1
);
2398 if (nCode
<= KEY_F9
)
2400 aFBuf
[1] = sal::static_int_cast
<char>('1' + (nCode
- KEY_F1
));
2403 else if (nCode
<= KEY_F19
)
2406 aFBuf
[2] = sal::static_int_cast
<char>('0' + (nCode
- KEY_F10
));
2412 aFBuf
[2] = sal::static_int_cast
<char>('0' + (nCode
- KEY_F20
));
2423 nSysCode2
= ((sal_uLong(1)) << 24);
2428 nSysCode2
= ((sal_uLong(1)) << 24);
2433 nSysCode2
= ((sal_uLong(1)) << 24);
2437 nSysCode
= VK_RIGHT
;
2438 nSysCode2
= ((sal_uLong(1)) << 24);
2443 nSysCode2
= ((sal_uLong(1)) << 24);
2448 nSysCode2
= ((sal_uLong(1)) << 24);
2452 nSysCode
= VK_PRIOR
;
2453 nSysCode2
= ((sal_uLong(1)) << 24);
2454 pReplace
= "Page Up";
2458 nSysCode2
= ((sal_uLong(1)) << 24);
2459 pReplace
= "Page Down";
2462 nSysCode
= VK_RETURN
;
2466 nSysCode
= VK_ESCAPE
;
2467 pReplace
= "Escape";
2475 pReplace
= "Backspace";
2478 nSysCode
= VK_SPACE
;
2482 nSysCode
= VK_INSERT
;
2483 nSysCode2
= ((sal_uLong(1)) << 24);
2484 pReplace
= "Insert";
2487 nSysCode
= VK_DELETE
;
2488 nSysCode2
= ((sal_uLong(1)) << 24);
2489 pReplace
= "Delete";
2522 case KEY_QUOTERIGHT
:
2525 case KEY_BRACKETLEFT
:
2528 case KEY_BRACKETRIGHT
:
2536 nSysCode
= MapVirtualKeyW( nSysCode
, 0 );
2538 nSysCode
= (nSysCode
<< 16) | nSysCode2
;
2539 ImplGetKeyNameText( nSysCode
, aKeyBuf
, nKeyBufLen
, nMaxKeyLen
, pReplace
);
2545 if ( nKeyBufLen
> 0 )
2546 aKeyBuf
[ nKeyBufLen
++ ] = '+';
2547 if( nKeyBufLen
< nMaxKeyLen
)
2548 aKeyBuf
[ nKeyBufLen
++ ] = cSVCode
;
2555 return OUString( aKeyBuf
, sal::static_int_cast
< sal_uInt16
>(nKeyBufLen
) );
2558 static Color
ImplWinColorToSal( COLORREF nColor
)
2560 return Color( GetRValue( nColor
), GetGValue( nColor
), GetBValue( nColor
) );
2563 static void ImplSalUpdateStyleFontW( HDC hDC
, const LOGFONTW
& rLogFont
, vcl::Font
& rFont
)
2565 ImplSalLogFontToFontW( hDC
, rLogFont
, rFont
);
2567 // On Windows 9x, Windows NT we get sometimes very small sizes
2568 // (for example for the small Caption height).
2569 // So if it is MS Sans Serif, a none scalable font we use
2570 // 8 Point as the minimum control height, in all other cases
2571 // 6 Point is the smallest one
2572 if ( rFont
.GetFontHeight() < 8 )
2574 if ( rtl_ustr_compareIgnoreAsciiCase( o3tl::toU(rLogFont
.lfFaceName
), o3tl::toU(L
"MS Sans Serif") ) == 0 )
2575 rFont
.SetFontHeight( 8 );
2576 else if ( rFont
.GetFontHeight() < 6 )
2577 rFont
.SetFontHeight( 6 );
2581 static tools::Long
ImplW2I( const wchar_t* pStr
)
2592 while( (*pStr
>= 48) && (*pStr
<= 57) )
2595 n
+= ((*pStr
) - 48);
2604 void WinSalFrame::UpdateSettings( AllSettings
& rSettings
)
2606 MouseSettings aMouseSettings
= rSettings
.GetMouseSettings();
2607 aMouseSettings
.SetDoubleClickTime( GetDoubleClickTime() );
2608 aMouseSettings
.SetDoubleClickWidth( GetSystemMetrics( SM_CXDOUBLECLK
) );
2609 aMouseSettings
.SetDoubleClickHeight( GetSystemMetrics( SM_CYDOUBLECLK
) );
2610 tools::Long nDragWidth
= GetSystemMetrics( SM_CXDRAG
);
2611 tools::Long nDragHeight
= GetSystemMetrics( SM_CYDRAG
);
2613 aMouseSettings
.SetStartDragWidth( nDragWidth
);
2615 aMouseSettings
.SetStartDragHeight( nDragHeight
);
2617 if ( RegOpenKeyW( HKEY_CURRENT_USER
,
2618 L
"Control Panel\\Desktop",
2619 &hRegKey
) == ERROR_SUCCESS
)
2621 wchar_t aValueBuf
[10];
2622 DWORD nValueSize
= sizeof( aValueBuf
);
2624 if ( RegQueryValueExW( hRegKey
, L
"MenuShowDelay", nullptr,
2625 &nType
, reinterpret_cast<LPBYTE
>(aValueBuf
), &nValueSize
) == ERROR_SUCCESS
)
2627 if ( nType
== REG_SZ
)
2628 aMouseSettings
.SetMenuDelay( static_cast<sal_uLong
>(ImplW2I( aValueBuf
)) );
2631 RegCloseKey( hRegKey
);
2634 StyleSettings aStyleSettings
= rSettings
.GetStyleSettings();
2636 aStyleSettings
.SetScrollBarSize( GetSystemMetrics( SM_CXVSCROLL
) );
2637 aStyleSettings
.SetSpinSize( GetSystemMetrics( SM_CXVSCROLL
) );
2638 UINT blinkTime
= GetCaretBlinkTime();
2639 aStyleSettings
.SetCursorBlinkTime(
2640 blinkTime
== 0 || blinkTime
== INFINITE
// 0 indicates error
2641 ? STYLE_CURSOR_NOBLINKTIME
: blinkTime
);
2642 aStyleSettings
.SetFloatTitleHeight( GetSystemMetrics( SM_CYSMCAPTION
) );
2643 aStyleSettings
.SetTitleHeight( GetSystemMetrics( SM_CYCAPTION
) );
2644 aStyleSettings
.SetActiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVEBORDER
) ) );
2645 aStyleSettings
.SetDeactiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVEBORDER
) ) );
2646 aStyleSettings
.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_GRADIENTINACTIVECAPTION
) ) );
2647 aStyleSettings
.SetFaceColor( ImplWinColorToSal( GetSysColor( COLOR_3DFACE
) ) );
2648 aStyleSettings
.SetInactiveTabColor( aStyleSettings
.GetFaceColor() );
2649 aStyleSettings
.SetLightColor( ImplWinColorToSal( GetSysColor( COLOR_3DHILIGHT
) ) );
2650 aStyleSettings
.SetLightBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DLIGHT
) ) );
2651 aStyleSettings
.SetShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW
) ) );
2652 aStyleSettings
.SetDarkShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DDKSHADOW
) ) );
2653 aStyleSettings
.SetHelpColor( ImplWinColorToSal( GetSysColor( COLOR_INFOBK
) ) );
2654 aStyleSettings
.SetHelpTextColor( ImplWinColorToSal( GetSysColor( COLOR_INFOTEXT
) ) );
2656 Color
aControlTextColor(ImplWinColorToSal(GetSysColor(COLOR_BTNTEXT
)));
2658 aStyleSettings
.SetDialogColor(aStyleSettings
.GetFaceColor());
2659 aStyleSettings
.SetDialogTextColor(aControlTextColor
);
2661 aStyleSettings
.SetDefaultButtonTextColor(aControlTextColor
);
2662 aStyleSettings
.SetButtonTextColor(aControlTextColor
);
2663 aStyleSettings
.SetDefaultActionButtonTextColor(aControlTextColor
);
2664 aStyleSettings
.SetActionButtonTextColor(aControlTextColor
);
2665 aStyleSettings
.SetFlatButtonTextColor(aControlTextColor
);
2666 aStyleSettings
.SetDefaultButtonRolloverTextColor(aControlTextColor
);
2667 aStyleSettings
.SetButtonRolloverTextColor(aControlTextColor
);
2668 aStyleSettings
.SetDefaultActionButtonRolloverTextColor(aControlTextColor
);
2669 aStyleSettings
.SetActionButtonRolloverTextColor(aControlTextColor
);
2670 aStyleSettings
.SetFlatButtonRolloverTextColor(aControlTextColor
);
2671 aStyleSettings
.SetDefaultButtonPressedRolloverTextColor(aControlTextColor
);
2672 aStyleSettings
.SetButtonPressedRolloverTextColor(aControlTextColor
);
2673 aStyleSettings
.SetDefaultActionButtonPressedRolloverTextColor(aControlTextColor
);
2674 aStyleSettings
.SetActionButtonPressedRolloverTextColor(aControlTextColor
);
2675 aStyleSettings
.SetFlatButtonPressedRolloverTextColor(aControlTextColor
);
2677 aStyleSettings
.SetTabTextColor(aControlTextColor
);
2678 aStyleSettings
.SetTabRolloverTextColor(aControlTextColor
);
2679 aStyleSettings
.SetTabHighlightTextColor(aControlTextColor
);
2681 aStyleSettings
.SetRadioCheckTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT
) ) );
2682 aStyleSettings
.SetGroupTextColor( aStyleSettings
.GetRadioCheckTextColor() );
2683 aStyleSettings
.SetLabelTextColor( aStyleSettings
.GetRadioCheckTextColor() );
2684 aStyleSettings
.SetWindowColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOW
) ) );
2685 aStyleSettings
.SetActiveTabColor( aStyleSettings
.GetWindowColor() );
2686 aStyleSettings
.SetWindowTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT
) ) );
2687 aStyleSettings
.SetToolTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT
) ) );
2688 aStyleSettings
.SetFieldColor( aStyleSettings
.GetWindowColor() );
2689 aStyleSettings
.SetFieldTextColor( aStyleSettings
.GetWindowTextColor() );
2690 aStyleSettings
.SetFieldRolloverTextColor( aStyleSettings
.GetFieldTextColor() );
2691 aStyleSettings
.SetHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHT
) ) );
2692 aStyleSettings
.SetHighlightTextColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHTTEXT
) ) );
2693 aStyleSettings
.SetMenuHighlightColor( aStyleSettings
.GetHighlightColor() );
2694 aStyleSettings
.SetMenuHighlightTextColor( aStyleSettings
.GetHighlightTextColor() );
2696 ImplSVData
* pSVData
= ImplGetSVData();
2697 pSVData
->maNWFData
.mnMenuFormatBorderX
= 0;
2698 pSVData
->maNWFData
.mnMenuFormatBorderY
= 0;
2699 pSVData
->maNWFData
.maMenuBarHighlightTextColor
= COL_TRANSPARENT
;
2700 GetSalData()->mbThemeMenuSupport
= false;
2701 if (officecfg::Office::Common::Accessibility::AutoDetectSystemHC::get())
2703 aStyleSettings
.SetShadowColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVEBORDER
) ) );
2704 aStyleSettings
.SetWorkspaceColor( ImplWinColorToSal( GetSysColor( COLOR_MENU
) ) );
2706 aStyleSettings
.SetMenuColor( ImplWinColorToSal( GetSysColor( COLOR_MENU
) ) );
2707 aStyleSettings
.SetMenuBarColor( aStyleSettings
.GetMenuColor() );
2708 aStyleSettings
.SetMenuBarRolloverColor( aStyleSettings
.GetHighlightColor() );
2709 aStyleSettings
.SetMenuBorderColor( aStyleSettings
.GetLightBorderColor() ); // overridden below for flat menus
2710 aStyleSettings
.SetUseFlatBorders( false );
2711 aStyleSettings
.SetUseFlatMenus( false );
2712 aStyleSettings
.SetMenuTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT
) ) );
2713 if ( std::optional
<Color
> aColor
= aStyleSettings
.GetPersonaMenuBarTextColor() )
2715 aStyleSettings
.SetMenuBarTextColor( *aColor
);
2716 aStyleSettings
.SetMenuBarRolloverTextColor( *aColor
);
2720 aStyleSettings
.SetMenuBarTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT
) ) );
2721 aStyleSettings
.SetMenuBarRolloverTextColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHTTEXT
) ) );
2723 aStyleSettings
.SetMenuBarHighlightTextColor(aStyleSettings
.GetMenuHighlightTextColor());
2724 aStyleSettings
.SetActiveColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVECAPTION
) ) );
2725 aStyleSettings
.SetActiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_CAPTIONTEXT
) ) );
2726 aStyleSettings
.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTION
) ) );
2727 aStyleSettings
.SetDeactiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTIONTEXT
) ) );
2728 BOOL bFlatMenus
= FALSE
;
2729 SystemParametersInfoW( SPI_GETFLATMENU
, 0, &bFlatMenus
, 0);
2732 aStyleSettings
.SetUseFlatMenus( true );
2733 aStyleSettings
.SetMenuBarColor( ImplWinColorToSal( GetSysColor( COLOR_MENUBAR
) ) );
2734 aStyleSettings
.SetMenuHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_MENUHILIGHT
) ) );
2735 aStyleSettings
.SetMenuBarRolloverColor( ImplWinColorToSal( GetSysColor( COLOR_MENUHILIGHT
) ) );
2736 aStyleSettings
.SetMenuBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW
) ) );
2738 // flat borders for our controls etc. as well in this mode (ie, no 3d borders)
2739 // this is not active in the classic style appearance
2740 aStyleSettings
.SetUseFlatBorders( true );
2742 aStyleSettings
.SetCheckedColorSpecialCase( );
2745 DWORD nCaretWidth
= 2;
2746 if( SystemParametersInfoW( SPI_GETCARETWIDTH
, 0, &nCaretWidth
, 0 ) )
2747 aStyleSettings
.SetCursorSize( nCaretWidth
);
2751 hc
.cbSize
= sizeof( HIGHCONTRAST
);
2752 if( SystemParametersInfoW( SPI_GETHIGHCONTRAST
, hc
.cbSize
, &hc
, 0 )
2753 && (hc
.dwFlags
& HCF_HIGHCONTRASTON
) )
2754 aStyleSettings
.SetHighContrastMode( true );
2756 aStyleSettings
.SetHighContrastMode( false );
2759 vcl::Font aMenuFont
= aStyleSettings
.GetMenuFont();
2760 vcl::Font aTitleFont
= aStyleSettings
.GetTitleFont();
2761 vcl::Font aFloatTitleFont
= aStyleSettings
.GetFloatTitleFont();
2762 vcl::Font aHelpFont
= aStyleSettings
.GetHelpFont();
2763 vcl::Font aAppFont
= aStyleSettings
.GetAppFont();
2764 vcl::Font aIconFont
= aStyleSettings
.GetIconFont();
2765 HDC hDC
= GetDC( nullptr );
2766 NONCLIENTMETRICSW aNonClientMetrics
;
2767 aNonClientMetrics
.cbSize
= sizeof( aNonClientMetrics
);
2768 if ( SystemParametersInfoW( SPI_GETNONCLIENTMETRICS
, sizeof( aNonClientMetrics
), &aNonClientMetrics
, 0 ) )
2770 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfMenuFont
, aMenuFont
);
2771 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfCaptionFont
, aTitleFont
);
2772 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfSmCaptionFont
, aFloatTitleFont
);
2773 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfStatusFont
, aHelpFont
);
2774 ImplSalUpdateStyleFontW( hDC
, aNonClientMetrics
.lfMessageFont
, aAppFont
);
2777 if ( SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, 0, &aLogFont
, 0 ) )
2778 ImplSalUpdateStyleFontW( hDC
, aLogFont
, aIconFont
);
2781 ReleaseDC( nullptr, hDC
);
2783 aStyleSettings
.SetToolbarIconSize(ToolbarIconSize::Large
);
2785 aStyleSettings
.BatchSetFonts( aAppFont
, aAppFont
);
2787 aStyleSettings
.SetMenuFont( aMenuFont
);
2788 aStyleSettings
.SetTitleFont( aTitleFont
);
2789 aStyleSettings
.SetFloatTitleFont( aFloatTitleFont
);
2790 aStyleSettings
.SetHelpFont( aHelpFont
);
2791 aStyleSettings
.SetIconFont( aIconFont
);
2793 if ( aAppFont
.GetWeight() > WEIGHT_NORMAL
)
2794 aAppFont
.SetWeight( WEIGHT_NORMAL
);
2795 aStyleSettings
.SetToolFont( aAppFont
);
2796 aStyleSettings
.SetTabFont( aAppFont
);
2799 if ( SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &bDragFull
, 0 ) )
2801 DragFullOptions nDragFullOptions
= aStyleSettings
.GetDragFullOptions();
2803 nDragFullOptions
|= DragFullOptions::WindowMove
| DragFullOptions::WindowSize
| DragFullOptions::Docking
| DragFullOptions::Split
;
2805 nDragFullOptions
&= ~DragFullOptions(DragFullOptions::WindowMove
| DragFullOptions::WindowSize
| DragFullOptions::Docking
| DragFullOptions::Split
);
2806 aStyleSettings
.SetDragFullOptions( nDragFullOptions
);
2809 if ( RegOpenKeyW( HKEY_CURRENT_USER
,
2810 L
"Control Panel\\International\\Calendars\\TwoDigitYearMax",
2811 &hRegKey
) == ERROR_SUCCESS
)
2813 wchar_t aValueBuf
[10];
2815 DWORD nValueSize
= sizeof( aValueBuf
);
2817 if ( RegQueryValueExW( hRegKey
, L
"1", nullptr,
2818 &nType
, reinterpret_cast<LPBYTE
>(aValueBuf
), &nValueSize
) == ERROR_SUCCESS
)
2820 if ( nType
== REG_SZ
)
2822 nValue
= static_cast<sal_uLong
>(ImplW2I( aValueBuf
));
2823 if ( (nValue
> 1000) && (nValue
< 10000) )
2825 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(comphelper::ConfigurationChanges::create());
2826 officecfg::Office::Common::DateFormat::TwoDigitYear::set(static_cast<sal_Int32
>(nValue
-99), batch
);
2832 RegCloseKey( hRegKey
);
2835 rSettings
.SetMouseSettings( aMouseSettings
);
2836 rSettings
.SetStyleSettings( aStyleSettings
);
2838 // now apply the values from theming, if available
2839 WinSalGraphics::updateSettingsNative( rSettings
);
2842 const SystemEnvData
* WinSalFrame::GetSystemData() const
2847 void WinSalFrame::Beep()
2853 SalFrame::SalPointerState
WinSalFrame::GetPointerState()
2855 SalPointerState aState
;
2858 if ( GetKeyState( VK_LBUTTON
) & 0x8000 )
2859 aState
.mnState
|= MOUSE_LEFT
;
2860 if ( GetKeyState( VK_MBUTTON
) & 0x8000 )
2861 aState
.mnState
|= MOUSE_MIDDLE
;
2862 if ( GetKeyState( VK_RBUTTON
) & 0x8000 )
2863 aState
.mnState
|= MOUSE_RIGHT
;
2864 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
2865 aState
.mnState
|= KEY_SHIFT
;
2866 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
2867 aState
.mnState
|= KEY_MOD1
;
2868 if ( GetKeyState( VK_MENU
) & 0x8000 )
2869 aState
.mnState
|= KEY_MOD2
;
2872 GetCursorPos( &pt
);
2874 aState
.maPos
= Point( pt
.x
- maGeometry
.nX
, pt
.y
- maGeometry
.nY
);
2878 KeyIndicatorState
WinSalFrame::GetIndicatorState()
2880 KeyIndicatorState aState
= KeyIndicatorState::NONE
;
2881 if (::GetKeyState(VK_CAPITAL
))
2882 aState
|= KeyIndicatorState::CAPSLOCK
;
2884 if (::GetKeyState(VK_NUMLOCK
))
2885 aState
|= KeyIndicatorState::NUMLOCK
;
2887 if (::GetKeyState(VK_SCROLL
))
2888 aState
|= KeyIndicatorState::SCROLLLOCK
;
2893 void WinSalFrame::SimulateKeyPress( sal_uInt16 nKeyCode
)
2903 if (nVKey
> 0 && nVKey
< 255)
2905 ::keybd_event(nVKey
, 0x45, KEYEVENTF_EXTENDEDKEY
, 0);
2906 ::keybd_event(nVKey
, 0x45, KEYEVENTF_EXTENDEDKEY
|KEYEVENTF_KEYUP
, 0);
2910 void WinSalFrame::ResetClipRegion()
2912 SetWindowRgn( mhWnd
, nullptr, TRUE
);
2915 void WinSalFrame::BeginSetClipRegion( sal_uInt32 nRects
)
2918 delete [] reinterpret_cast<BYTE
*>(mpClipRgnData
);
2919 sal_uLong nRectBufSize
= sizeof(RECT
)*nRects
;
2920 mpClipRgnData
= reinterpret_cast<RGNDATA
*>(new BYTE
[sizeof(RGNDATA
)-1+nRectBufSize
]);
2921 mpClipRgnData
->rdh
.dwSize
= sizeof( RGNDATAHEADER
);
2922 mpClipRgnData
->rdh
.iType
= RDH_RECTANGLES
;
2923 mpClipRgnData
->rdh
.nCount
= nRects
;
2924 mpClipRgnData
->rdh
.nRgnSize
= nRectBufSize
;
2925 SetRectEmpty( &(mpClipRgnData
->rdh
.rcBound
) );
2926 mpNextClipRect
= reinterpret_cast<RECT
*>(&(mpClipRgnData
->Buffer
));
2927 mbFirstClipRect
= true;
2930 void WinSalFrame::UnionClipRegion( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
)
2932 if( ! mpClipRgnData
)
2935 RECT
* pRect
= mpNextClipRect
;
2936 RECT
* pBoundRect
= &(mpClipRgnData
->rdh
.rcBound
);
2937 tools::Long nRight
= nX
+ nWidth
;
2938 tools::Long nBottom
= nY
+ nHeight
;
2940 if ( mbFirstClipRect
)
2942 pBoundRect
->left
= nX
;
2943 pBoundRect
->top
= nY
;
2944 pBoundRect
->right
= nRight
;
2945 pBoundRect
->bottom
= nBottom
;
2946 mbFirstClipRect
= false;
2950 if ( nX
< pBoundRect
->left
)
2951 pBoundRect
->left
= static_cast<int>(nX
);
2953 if ( nY
< pBoundRect
->top
)
2954 pBoundRect
->top
= static_cast<int>(nY
);
2956 if ( nRight
> pBoundRect
->right
)
2957 pBoundRect
->right
= static_cast<int>(nRight
);
2959 if ( nBottom
> pBoundRect
->bottom
)
2960 pBoundRect
->bottom
= static_cast<int>(nBottom
);
2963 pRect
->left
= static_cast<int>(nX
);
2964 pRect
->top
= static_cast<int>(nY
);
2965 pRect
->right
= static_cast<int>(nRight
);
2966 pRect
->bottom
= static_cast<int>(nBottom
);
2967 if( (mpNextClipRect
- reinterpret_cast<RECT
*>(&mpClipRgnData
->Buffer
)) < static_cast<int>(mpClipRgnData
->rdh
.nCount
) )
2971 void WinSalFrame::EndSetClipRegion()
2973 if( ! mpClipRgnData
)
2978 // create region from accumulated rectangles
2979 if ( mpClipRgnData
->rdh
.nCount
== 1 )
2981 RECT
* pRect
= &(mpClipRgnData
->rdh
.rcBound
);
2982 hRegion
= CreateRectRgn( pRect
->left
, pRect
->top
,
2983 pRect
->right
, pRect
->bottom
);
2987 sal_uLong nSize
= mpClipRgnData
->rdh
.nRgnSize
+sizeof(RGNDATAHEADER
);
2988 hRegion
= ExtCreateRegion( nullptr, nSize
, mpClipRgnData
);
2990 delete [] reinterpret_cast<BYTE
*>(mpClipRgnData
);
2991 mpClipRgnData
= nullptr;
2993 SAL_WARN_IF( !hRegion
, "vcl", "WinSalFrame::EndSetClipRegion() - Can't create ClipRegion" );
2997 GetWindowRect( mhWnd
, &aWindowRect
);
3001 ClientToScreen( mhWnd
, &aPt
);
3002 OffsetRgn( hRegion
, aPt
.x
- aWindowRect
.left
, aPt
.y
- aWindowRect
.top
);
3004 if( SetWindowRgn( mhWnd
, hRegion
, TRUE
) == 0 )
3005 DeleteObject( hRegion
);
3009 static bool ImplHandleMouseMsg( HWND hWnd
, UINT nMsg
,
3010 WPARAM wParam
, LPARAM lParam
)
3012 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3016 if( nMsg
== WM_LBUTTONDOWN
|| nMsg
== WM_MBUTTONDOWN
|| nMsg
== WM_RBUTTONDOWN
)
3018 // #103168# post again if async focus has not arrived yet
3019 // hopefully we will not receive the corresponding button up before this
3020 // button down arrives again
3021 vcl::Window
*pWin
= pFrame
->GetWindow();
3022 if( pWin
&& pWin
->ImplGetWindowImpl()->mpFrameData
->mnFocusId
)
3024 bool const ret
= PostMessageW( hWnd
, nMsg
, wParam
, lParam
);
3025 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
3029 SalMouseEvent aMouseEvt
;
3031 SalEvent nEvent
= SalEvent::NONE
;
3034 aMouseEvt
.mnX
= static_cast<short>(LOWORD( lParam
));
3035 aMouseEvt
.mnY
= static_cast<short>(HIWORD( lParam
));
3036 aMouseEvt
.mnCode
= 0;
3037 aMouseEvt
.mnTime
= GetMessageTime();
3039 // Use GetKeyState(), as some Logitech mouse drivers do not check
3040 // KeyState when simulating double-click with center mouse button
3042 if ( GetKeyState( VK_LBUTTON
) & 0x8000 )
3043 aMouseEvt
.mnCode
|= MOUSE_LEFT
;
3044 if ( GetKeyState( VK_MBUTTON
) & 0x8000 )
3045 aMouseEvt
.mnCode
|= MOUSE_MIDDLE
;
3046 if ( GetKeyState( VK_RBUTTON
) & 0x8000 )
3047 aMouseEvt
.mnCode
|= MOUSE_RIGHT
;
3048 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3049 aMouseEvt
.mnCode
|= KEY_SHIFT
;
3050 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3051 aMouseEvt
.mnCode
|= KEY_MOD1
;
3052 if ( GetKeyState( VK_MENU
) & 0x8000 )
3053 aMouseEvt
.mnCode
|= KEY_MOD2
;
3059 // As the mouse events are not collected correctly when
3060 // pressing modifier keys (as interrupted by KeyEvents)
3061 // we do this here ourselves
3062 if ( aMouseEvt
.mnCode
& (KEY_SHIFT
| KEY_MOD1
| KEY_MOD2
) )
3065 if ( PeekMessageW( &aTempMsg
, hWnd
, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_NOREMOVE
| PM_NOYIELD
) )
3067 if ( (aTempMsg
.message
== WM_MOUSEMOVE
) &&
3068 (aTempMsg
.wParam
== wParam
) )
3073 SalData
* pSalData
= GetSalData();
3074 // Test for MouseLeave
3075 if ( pSalData
->mhWantLeaveMsg
&& (pSalData
->mhWantLeaveMsg
!= hWnd
) )
3076 SendMessageW( pSalData
->mhWantLeaveMsg
, SAL_MSG_MOUSELEAVE
, 0, GetMessagePos() );
3078 pSalData
->mhWantLeaveMsg
= hWnd
;
3079 // Start MouseLeave-Timer
3080 if ( !pSalData
->mpMouseLeaveTimer
)
3082 pSalData
->mpMouseLeaveTimer
= new AutoTimer
;
3083 pSalData
->mpMouseLeaveTimer
->SetDebugName( "ImplHandleMouseMsg SalData::mpMouseLeaveTimer" );
3084 pSalData
->mpMouseLeaveTimer
->SetTimeout( SAL_MOUSELEAVE_TIMEOUT
);
3085 pSalData
->mpMouseLeaveTimer
->Start();
3086 // We don't need to set a timeout handler, because we test
3087 // for mouseleave in the timeout callback
3089 aMouseEvt
.mnButton
= 0;
3090 nEvent
= SalEvent::MouseMove
;
3094 case WM_NCMOUSEMOVE
:
3095 case SAL_MSG_MOUSELEAVE
:
3097 SalData
* pSalData
= GetSalData();
3098 if ( pSalData
->mhWantLeaveMsg
== hWnd
)
3100 // Mouse-Coordinates are relative to the screen
3102 aPt
.x
= static_cast<short>(LOWORD(lParam
));
3103 aPt
.y
= static_cast<short>(HIWORD(lParam
));
3104 ScreenToClient(hWnd
, &aPt
);
3105 if (const auto& pHelpWin
= ImplGetSVHelpData().mpHelpWin
)
3107 const tools::Rectangle
& rHelpRect
= pHelpWin
->GetHelpArea();
3108 if (rHelpRect
.IsInside(Point(aPt
.x
, aPt
.y
)))
3110 // We have entered a tooltip (help window). Don't call the handler here; it
3111 // would launch the sequence "Mouse leaves the Control->Control redraws->
3112 // Help window gets destroyed->Mouse enters the Control->Control redraws",
3113 // which takes CPU and may flicker. Just destroy the help window and pretend
3114 // we are still over the original window.
3115 ImplDestroyHelpWindow(true);
3120 pSalData
->mhWantLeaveMsg
= nullptr;
3121 if ( pSalData
->mpMouseLeaveTimer
)
3123 delete pSalData
->mpMouseLeaveTimer
;
3124 pSalData
->mpMouseLeaveTimer
= nullptr;
3126 aMouseEvt
.mnX
= aPt
.x
;
3127 aMouseEvt
.mnY
= aPt
.y
;
3128 aMouseEvt
.mnButton
= 0;
3129 nEvent
= SalEvent::MouseLeave
;
3136 case WM_LBUTTONDOWN
:
3137 aMouseEvt
.mnButton
= MOUSE_LEFT
;
3138 nEvent
= SalEvent::MouseButtonDown
;
3141 case WM_MBUTTONDOWN
:
3142 aMouseEvt
.mnButton
= MOUSE_MIDDLE
;
3143 nEvent
= SalEvent::MouseButtonDown
;
3146 case WM_RBUTTONDOWN
:
3147 aMouseEvt
.mnButton
= MOUSE_RIGHT
;
3148 nEvent
= SalEvent::MouseButtonDown
;
3152 aMouseEvt
.mnButton
= MOUSE_LEFT
;
3153 nEvent
= SalEvent::MouseButtonUp
;
3157 aMouseEvt
.mnButton
= MOUSE_MIDDLE
;
3158 nEvent
= SalEvent::MouseButtonUp
;
3162 aMouseEvt
.mnButton
= MOUSE_RIGHT
;
3163 nEvent
= SalEvent::MouseButtonUp
;
3167 // check if this window was destroyed - this might happen if we are the help window
3168 // and sent a mouse leave message to the application which killed the help window, ie ourselves
3169 if( !IsWindow( hWnd
) )
3174 if ( nEvent
== SalEvent::MouseButtonDown
)
3175 UpdateWindow( hWnd
);
3177 if( AllSettings::GetLayoutRTL() )
3178 aMouseEvt
.mnX
= pFrame
->maGeometry
.nWidth
-1-aMouseEvt
.mnX
;
3180 nRet
= pFrame
->CallCallback( nEvent
, &aMouseEvt
);
3181 if ( nMsg
== WM_MOUSEMOVE
)
3182 SetCursor( pFrame
->mhCursor
);
3190 static bool ImplHandleMouseActivateMsg( HWND hWnd
)
3192 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3196 if ( pFrame
->mbFloatWin
)
3199 return pFrame
->CallCallback( SalEvent::MouseActivate
, nullptr );
3202 static bool ImplHandleWheelMsg( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
)
3204 DBG_ASSERT( nMsg
== WM_MOUSEWHEEL
||
3205 nMsg
== WM_MOUSEHWHEEL
,
3206 "ImplHandleWheelMsg() called with no wheel mouse event" );
3208 ImplSalYieldMutexAcquireWithWait();
3211 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3214 WORD nWinModCode
= LOWORD( wParam
);
3216 aWinPt
.x
= static_cast<short>(LOWORD( lParam
));
3217 aWinPt
.y
= static_cast<short>(HIWORD( lParam
));
3218 ScreenToClient( hWnd
, &aWinPt
);
3220 SalWheelMouseEvent aWheelEvt
;
3221 aWheelEvt
.mnTime
= GetMessageTime();
3222 aWheelEvt
.mnX
= aWinPt
.x
;
3223 aWheelEvt
.mnY
= aWinPt
.y
;
3224 aWheelEvt
.mnCode
= 0;
3225 aWheelEvt
.mnDelta
= static_cast<short>(HIWORD( wParam
));
3226 aWheelEvt
.mnNotchDelta
= aWheelEvt
.mnDelta
/WHEEL_DELTA
;
3227 if( aWheelEvt
.mnNotchDelta
== 0 )
3229 if( aWheelEvt
.mnDelta
> 0 )
3230 aWheelEvt
.mnNotchDelta
= 1;
3231 else if( aWheelEvt
.mnDelta
< 0 )
3232 aWheelEvt
.mnNotchDelta
= -1;
3235 if( nMsg
== WM_MOUSEWHEEL
)
3237 if ( aSalShlData
.mnWheelScrollLines
== WHEEL_PAGESCROLL
)
3238 aWheelEvt
.mnScrollLines
= SAL_WHEELMOUSE_EVENT_PAGESCROLL
;
3240 aWheelEvt
.mnScrollLines
= aSalShlData
.mnWheelScrollLines
;
3241 aWheelEvt
.mbHorz
= false;
3245 aWheelEvt
.mnScrollLines
= aSalShlData
.mnWheelScrollChars
;
3246 aWheelEvt
.mbHorz
= true;
3248 // fdo#36380 - seems horiz scrolling has swapped direction
3249 aWheelEvt
.mnDelta
*= -1;
3250 aWheelEvt
.mnNotchDelta
*= -1;
3253 if ( nWinModCode
& MK_SHIFT
)
3254 aWheelEvt
.mnCode
|= KEY_SHIFT
;
3255 if ( nWinModCode
& MK_CONTROL
)
3256 aWheelEvt
.mnCode
|= KEY_MOD1
;
3257 if ( GetKeyState( VK_MENU
) & 0x8000 )
3258 aWheelEvt
.mnCode
|= KEY_MOD2
;
3260 if( AllSettings::GetLayoutRTL() )
3261 aWheelEvt
.mnX
= pFrame
->maGeometry
.nWidth
-1-aWheelEvt
.mnX
;
3263 nRet
= pFrame
->CallCallback( SalEvent::WheelMouse
, &aWheelEvt
);
3266 ImplSalYieldMutexRelease();
3271 static sal_uInt16
ImplSalGetKeyCode( WPARAM wParam
)
3273 sal_uInt16 nKeyCode
;
3276 if ( wParam
< KEY_TAB_SIZE
)
3277 nKeyCode
= aImplTranslateKeyTab
[wParam
];
3280 SalData
* pSalData
= GetSalData();
3281 std::map
< UINT
, sal_uInt16
>::const_iterator it
= pSalData
->maVKMap
.find( static_cast<UINT
>(wParam
) );
3282 if( it
!= pSalData
->maVKMap
.end() )
3283 nKeyCode
= it
->second
;
3291 static void ImplUpdateInputLang( WinSalFrame
* pFrame
)
3293 UINT nLang
= LOWORD( GetKeyboardLayout( 0 ) );
3294 if ( nLang
&& nLang
!= pFrame
->mnInputLang
)
3296 // keep input lang up-to-date
3297 pFrame
->mnInputLang
= nLang
;
3300 // We are on Windows NT so we use Unicode FrameProcs and get
3301 // Unicode charcodes directly from Windows no need to set up a
3306 static sal_Unicode
ImplGetCharCode( WinSalFrame
* pFrame
, WPARAM nCharCode
)
3308 ImplUpdateInputLang( pFrame
);
3310 // We are on Windows NT so we use Unicode FrameProcs and we
3311 // get Unicode charcodes directly from Windows
3312 return static_cast<sal_Unicode
>(nCharCode
);
3315 LanguageType
WinSalFrame::GetInputLanguage()
3318 ImplUpdateInputLang( this );
3321 return LANGUAGE_DONTKNOW
;
3323 return LanguageType(mnInputLang
);
3326 bool WinSalFrame::MapUnicodeToKeyCode( sal_Unicode aUnicode
, LanguageType aLangType
, vcl::KeyCode
& rKeyCode
)
3329 sal_IntPtr nLangType
= static_cast<sal_uInt16
>(aLangType
);
3330 // just use the passed language identifier, do not try to load additional keyboard support
3331 HKL hkl
= reinterpret_cast<HKL
>(nLangType
);
3335 SHORT scan
= VkKeyScanExW( aUnicode
, hkl
);
3336 if( LOWORD(scan
) == 0xFFFF )
3337 // keyboard not loaded or key cannot be mapped
3341 BYTE vkeycode
= LOBYTE(scan
);
3342 BYTE shiftstate
= HIBYTE(scan
);
3344 // Last argument is set to false, because there's no decision made
3345 // yet which key should be assigned to MOD3 modifier on Windows.
3346 // Windows key - user's can be confused, because it should display
3347 // Windows menu (applies to both left/right key)
3348 // Menu key - this key is used to display context menu
3349 // AltGr key - probably it has no sense
3350 rKeyCode
= vcl::KeyCode( ImplSalGetKeyCode( vkeycode
),
3351 (shiftstate
& 0x01) != 0, // shift
3352 (shiftstate
& 0x02) != 0, // ctrl
3353 (shiftstate
& 0x04) != 0, // alt
3362 static bool ImplHandleKeyMsg( HWND hWnd
, UINT nMsg
,
3363 WPARAM wParam
, LPARAM lParam
, LRESULT
& rResult
)
3365 static bool bIgnoreCharMsg
= false;
3366 static WPARAM nDeadChar
= 0;
3367 static WPARAM nLastVKChar
= 0;
3368 static sal_uInt16 nLastChar
= 0;
3369 static ModKeyFlags nLastModKeyCode
= ModKeyFlags::NONE
;
3370 static bool bWaitForModKeyRelease
= false;
3371 sal_uInt16 nRepeat
= LOWORD( lParam
)-1;
3372 sal_uInt16 nModCode
= 0;
3374 // this key might have been relayed by SysChild and thus
3375 // may not be processed twice
3376 GetSalData()->mnSalObjWantKeyEvt
= 0;
3378 if ( nMsg
== WM_DEADCHAR
)
3384 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3388 // reset the background mode for each text input,
3389 // as some tools such as RichWin may have changed it
3390 if ( pFrame
->mpLocalGraphics
&&
3391 pFrame
->mpLocalGraphics
->getHDC() )
3392 SetBkMode( pFrame
->mpLocalGraphics
->getHDC(), TRANSPARENT
);
3394 // determine modifiers
3395 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3396 nModCode
|= KEY_SHIFT
;
3397 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3398 nModCode
|= KEY_MOD1
;
3399 if (GetKeyState(VK_MENU
) & 0x8000)
3400 nModCode
|= KEY_MOD2
;
3402 if ( (nMsg
== WM_CHAR
) || (nMsg
== WM_SYSCHAR
) )
3406 if ( bIgnoreCharMsg
)
3408 bIgnoreCharMsg
= false;
3409 // #101635# if zero is returned here for WM_SYSCHAR (ALT+<key>) Windows will beep
3410 // because this 'hotkey' was not processed -> better return 1
3411 // except for Alt-SPACE which should always open the sysmenu (#104616#)
3413 // also return zero if a system menubar is available that might process this hotkey
3414 // this also applies to the OLE inplace embedding where we are a child window
3415 if( (GetWindowStyle( hWnd
) & WS_CHILD
) || GetMenu( hWnd
) || (wParam
== 0x20) )
3421 // ignore backspace as a single key, so that
3422 // we do not get problems for combinations w/ a DeadKey
3423 if ( wParam
== 0x08 ) // BACKSPACE
3426 // only "free flying" WM_CHAR messages arrive here, that are
3427 // created by typing an ALT-NUMPAD combination
3428 SalKeyEvent aKeyEvt
;
3430 if ( (wParam
>= '0') && (wParam
<= '9') )
3431 aKeyEvt
.mnCode
= sal::static_int_cast
<sal_uInt16
>(KEYGROUP_NUM
+ wParam
- '0');
3432 else if ( (wParam
>= 'A') && (wParam
<= 'Z') )
3433 aKeyEvt
.mnCode
= sal::static_int_cast
<sal_uInt16
>(KEYGROUP_ALPHA
+ wParam
- 'A');
3434 else if ( (wParam
>= 'a') && (wParam
<= 'z') )
3435 aKeyEvt
.mnCode
= sal::static_int_cast
<sal_uInt16
>(KEYGROUP_ALPHA
+ wParam
- 'a');
3436 else if ( wParam
== 0x0D ) // RETURN
3437 aKeyEvt
.mnCode
= KEY_RETURN
;
3438 else if ( wParam
== 0x1B ) // ESCAPE
3439 aKeyEvt
.mnCode
= KEY_ESCAPE
;
3440 else if ( wParam
== 0x09 ) // TAB
3441 aKeyEvt
.mnCode
= KEY_TAB
;
3442 else if ( wParam
== 0x20 ) // SPACE
3443 aKeyEvt
.mnCode
= KEY_SPACE
;
3447 aKeyEvt
.mnCode
|= nModCode
;
3448 aKeyEvt
.mnCharCode
= ImplGetCharCode( pFrame
, wParam
);
3449 aKeyEvt
.mnRepeat
= nRepeat
;
3452 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
3453 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
3456 // #i11583#, MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition begins
3457 else if( nMsg
== WM_UNICHAR
)
3459 // If Windows is asking if we accept WM_UNICHAR, return TRUE
3460 if(wParam
== UNICODE_NOCHAR
)
3462 rResult
= TRUE
; // ssa: this will actually return TRUE to windows
3463 return true; // ...but this will only avoid calling the defwindowproc
3466 SalKeyEvent aKeyEvt
;
3467 aKeyEvt
.mnCode
= nModCode
; // Or should it be 0? - as this is always a character returned
3468 aKeyEvt
.mnRepeat
= 0;
3470 if( wParam
>= Uni_SupplementaryPlanesStart
)
3472 // character is supplementary char in UTF-32 format - must be converted to UTF-16 supplementary pair
3473 // sal_Unicode ch = (sal_Unicode) Uni_UTF32ToSurrogate1(wParam);
3476 pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
3477 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
3478 wParam
= static_cast<sal_Unicode
>(Uni_UTF32ToSurrogate2( wParam
));
3481 aKeyEvt
.mnCharCode
= static_cast<sal_Unicode
>(wParam
);
3485 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
3486 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
3490 // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition ends
3493 // for shift, control and menu we issue a KeyModChange event
3494 if ( (wParam
== VK_SHIFT
) || (wParam
== VK_CONTROL
) || (wParam
== VK_MENU
) )
3496 SalKeyModEvent aModEvt
;
3497 aModEvt
.mbDown
= false; // auto-accelerator feature not supported here.
3498 aModEvt
.mnCode
= nModCode
;
3499 aModEvt
.mnModKeyCode
= ModKeyFlags::NONE
; // no command events will be sent if this member is 0
3501 ModKeyFlags tmpCode
= ModKeyFlags::NONE
;
3502 if( GetKeyState( VK_LSHIFT
) & 0x8000 )
3503 tmpCode
|= ModKeyFlags::LeftShift
;
3504 if( GetKeyState( VK_RSHIFT
) & 0x8000 )
3505 tmpCode
|= ModKeyFlags::RightShift
;
3506 if( GetKeyState( VK_LCONTROL
) & 0x8000 )
3507 tmpCode
|= ModKeyFlags::LeftMod1
;
3508 if( GetKeyState( VK_RCONTROL
) & 0x8000 )
3509 tmpCode
|= ModKeyFlags::RightMod1
;
3510 if( GetKeyState( VK_LMENU
) & 0x8000 )
3511 tmpCode
|= ModKeyFlags::LeftMod2
;
3512 if( GetKeyState( VK_RMENU
) & 0x8000 )
3513 tmpCode
|= ModKeyFlags::RightMod2
;
3515 if( tmpCode
< nLastModKeyCode
)
3517 aModEvt
.mnModKeyCode
= nLastModKeyCode
;
3518 nLastModKeyCode
= ModKeyFlags::NONE
;
3519 bWaitForModKeyRelease
= true;
3523 if( !bWaitForModKeyRelease
)
3524 nLastModKeyCode
= tmpCode
;
3527 if( tmpCode
== ModKeyFlags::NONE
)
3528 bWaitForModKeyRelease
= false;
3530 return pFrame
->CallCallback( SalEvent::KeyModChange
, &aModEvt
);
3534 SalKeyEvent aKeyEvt
;
3537 bool bCharPeek
= false;
3538 UINT nCharMsg
= WM_CHAR
;
3539 bool bKeyUp
= (nMsg
== WM_KEYUP
) || (nMsg
== WM_SYSKEYUP
);
3541 nLastModKeyCode
= ModKeyFlags::NONE
; // make sure no modkey messages are sent if they belong to a hotkey (see above)
3542 aKeyEvt
.mnCharCode
= 0;
3543 aKeyEvt
.mnCode
= ImplSalGetKeyCode( wParam
);
3546 // check for charcode
3547 // Get the related WM_CHAR message using PeekMessage, if available.
3548 // The WM_CHAR message is always at the beginning of the
3549 // message queue. Also it is made certain that there is always only
3550 // one WM_CHAR message in the queue.
3551 bCharPeek
= PeekMessageW( &aCharMsg
, hWnd
,
3552 WM_CHAR
, WM_CHAR
, PM_NOREMOVE
| PM_NOYIELD
);
3553 if ( bCharPeek
&& (nDeadChar
== aCharMsg
.wParam
) )
3558 if ( wParam
== VK_BACK
)
3560 PeekMessageW( &aCharMsg
, hWnd
,
3561 nCharMsg
, nCharMsg
, PM_REMOVE
| PM_NOYIELD
);
3569 bCharPeek
= PeekMessageW( &aCharMsg
, hWnd
,
3570 WM_SYSCHAR
, WM_SYSCHAR
, PM_NOREMOVE
| PM_NOYIELD
);
3571 nCharMsg
= WM_SYSCHAR
;
3575 aKeyEvt
.mnCharCode
= ImplGetCharCode( pFrame
, aCharMsg
.wParam
);
3577 aKeyEvt
.mnCharCode
= 0;
3579 nLastChar
= aKeyEvt
.mnCharCode
;
3580 nLastVKChar
= wParam
;
3584 if ( wParam
== nLastVKChar
)
3586 aKeyEvt
.mnCharCode
= nLastChar
;
3592 if ( aKeyEvt
.mnCode
|| aKeyEvt
.mnCharCode
)
3595 nEvent
= SalEvent::KeyUp
;
3597 nEvent
= SalEvent::KeyInput
;
3599 aKeyEvt
.mnCode
|= nModCode
;
3600 aKeyEvt
.mnRepeat
= nRepeat
;
3602 if ((nModCode
& (KEY_MOD1
| KEY_MOD2
)) == (KEY_MOD1
| KEY_MOD2
) &&
3605 // this is actually AltGr and should not be handled as Alt
3606 aKeyEvt
.mnCode
&= ~(KEY_MOD1
| KEY_MOD2
);
3609 bIgnoreCharMsg
= bCharPeek
;
3610 bool nRet
= pFrame
->CallCallback( nEvent
, &aKeyEvt
);
3611 // independent part only reacts on keyup but Windows does not send
3612 // keyup for VK_HANJA
3613 if( aKeyEvt
.mnCode
== KEY_HANGUL_HANJA
)
3614 nRet
= pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
3616 bIgnoreCharMsg
= false;
3618 // char-message, then remove or ignore
3624 PeekMessageW( &aCharMsg
, hWnd
,
3625 nCharMsg
, nCharMsg
, PM_REMOVE
| PM_NOYIELD
);
3628 bIgnoreCharMsg
= true;
3639 bool ImplHandleSalObjKeyMsg( HWND hWnd
, UINT nMsg
,
3640 WPARAM wParam
, LPARAM lParam
)
3642 if ( (nMsg
== WM_KEYDOWN
) || (nMsg
== WM_KEYUP
) )
3644 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3648 sal_uInt16 nRepeat
= LOWORD( lParam
)-1;
3649 sal_uInt16 nModCode
= 0;
3651 // determine modifiers
3652 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3653 nModCode
|= KEY_SHIFT
;
3654 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3655 nModCode
|= KEY_MOD1
;
3656 if ( GetKeyState( VK_MENU
) & 0x8000 )
3657 nModCode
|= KEY_MOD2
;
3659 if ( (wParam
!= VK_SHIFT
) && (wParam
!= VK_CONTROL
) && (wParam
!= VK_MENU
) )
3661 SalKeyEvent aKeyEvt
;
3665 aKeyEvt
.mnCode
= ImplSalGetKeyCode( wParam
);
3666 aKeyEvt
.mnCharCode
= 0;
3668 if ( aKeyEvt
.mnCode
)
3670 if (nMsg
== WM_KEYUP
)
3671 nEvent
= SalEvent::KeyUp
;
3673 nEvent
= SalEvent::KeyInput
;
3675 aKeyEvt
.mnCode
|= nModCode
;
3676 aKeyEvt
.mnRepeat
= nRepeat
;
3677 bool nRet
= pFrame
->CallCallback( nEvent
, &aKeyEvt
);
3688 bool ImplHandleSalObjSysCharMsg( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
3690 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3694 sal_uInt16 nRepeat
= LOWORD( lParam
)-1;
3695 sal_uInt16 nModCode
= 0;
3696 sal_uInt16 cKeyCode
= static_cast<sal_uInt16
>(wParam
);
3698 // determine modifiers
3699 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
3700 nModCode
|= KEY_SHIFT
;
3701 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
3702 nModCode
|= KEY_MOD1
;
3703 nModCode
|= KEY_MOD2
;
3705 // assemble KeyEvent
3706 SalKeyEvent aKeyEvt
;
3707 if ( (cKeyCode
>= 48) && (cKeyCode
<= 57) )
3708 aKeyEvt
.mnCode
= KEY_0
+(cKeyCode
-48);
3709 else if ( (cKeyCode
>= 65) && (cKeyCode
<= 90) )
3710 aKeyEvt
.mnCode
= KEY_A
+(cKeyCode
-65);
3711 else if ( (cKeyCode
>= 97) && (cKeyCode
<= 122) )
3712 aKeyEvt
.mnCode
= KEY_A
+(cKeyCode
-97);
3715 aKeyEvt
.mnCode
|= nModCode
;
3716 aKeyEvt
.mnCharCode
= ImplGetCharCode( pFrame
, cKeyCode
);
3717 aKeyEvt
.mnRepeat
= nRepeat
;
3718 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
3719 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
3725 enum class DeferPolicy
3733 // Remember to release the solar mutex on success!
3734 static WinSalFrame
* ProcessOrDeferMessage( HWND hWnd
, INT nMsg
, WPARAM pWParam
= 0,
3735 DeferPolicy eCanDefer
= DeferPolicy::Allowed
)
3737 bool bFailedCondition
= false, bGotMutex
= false;
3738 WinSalFrame
* pFrame
= nullptr;
3740 if ( DeferPolicy::Blocked
== eCanDefer
)
3741 assert( (DeferPolicy::Blocked
== eCanDefer
) && (nMsg
== 0) && (pWParam
== 0) );
3743 assert( (DeferPolicy::Allowed
== eCanDefer
) && (nMsg
!= 0) );
3745 if ( DeferPolicy::Blocked
== eCanDefer
)
3747 ImplSalYieldMutexAcquireWithWait();
3750 else if ( !(bGotMutex
= ImplSalYieldMutexTryToAcquire()) )
3751 bFailedCondition
= true;
3753 if ( !bFailedCondition
)
3755 pFrame
= GetWindowPtr( hWnd
);
3756 bFailedCondition
= pFrame
== nullptr;
3759 if ( bFailedCondition
)
3762 ImplSalYieldMutexRelease();
3763 if ( DeferPolicy::Allowed
== eCanDefer
)
3765 bool const ret
= PostMessageW(hWnd
, nMsg
, pWParam
, 0);
3766 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
3775 enum class PostedState
3783 static bool ImplHandlePostPaintMsg( HWND hWnd
, RECT
* pRect
,
3784 PostedState eProcessed
= PostedState::IsPosted
)
3787 if ( PostedState::IsInitial
== eProcessed
)
3789 pMsgRect
= new RECT
;
3790 CopyRect( pMsgRect
, pRect
);
3795 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, SAL_MSG_POSTPAINT
,
3796 reinterpret_cast<WPARAM
>(pMsgRect
) );
3799 SalPaintEvent
aPEvt( pRect
->left
, pRect
->top
, pRect
->right
-pRect
->left
, pRect
->bottom
-pRect
->top
);
3800 pFrame
->CallCallback( SalEvent::Paint
, &aPEvt
);
3801 ImplSalYieldMutexRelease();
3802 if ( PostedState::IsPosted
== eProcessed
)
3806 return (pFrame
!= nullptr);
3809 static bool ImplHandlePaintMsg( HWND hWnd
)
3811 bool bPaintSuccessful
= false;
3813 // even without the Yield mutex, we can still change the clip region,
3814 // because other threads don't use the Yield mutex
3815 // --> see AcquireGraphics()
3817 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3820 // clip region must be set, as we don't get a proper
3821 // bounding rectangle otherwise
3822 WinSalGraphics
*pGraphics
= pFrame
->mpLocalGraphics
;
3823 bool bHasClipRegion
= pGraphics
&&
3824 pGraphics
->getHDC() && pGraphics
->getRegion();
3825 if ( bHasClipRegion
)
3826 SelectClipRgn( pGraphics
->getHDC(), nullptr );
3828 // according to Windows documentation one shall check first if
3829 // there really is a paint-region
3832 bool bHasPaintRegion
= GetUpdateRect( hWnd
, nullptr, FALSE
);
3833 if ( bHasPaintRegion
)
3835 // call BeginPaint/EndPaint to query the paint rect and use
3836 // this information in the (deferred) paint
3837 BeginPaint( hWnd
, &aPs
);
3838 CopyRect( &aUpdateRect
, &aPs
.rcPaint
);
3841 // reset clip region
3842 if ( bHasClipRegion
)
3843 SelectClipRgn( pGraphics
->getHDC(), pGraphics
->getRegion() );
3846 if ( bHasPaintRegion
)
3848 bPaintSuccessful
= ImplHandlePostPaintMsg(
3849 hWnd
, &aUpdateRect
, PostedState::IsInitial
);
3850 EndPaint( hWnd
, &aPs
);
3852 else // if there is nothing to paint, the paint is successful
3853 bPaintSuccessful
= true;
3856 return bPaintSuccessful
;
3859 static void SetMaximizedFrameGeometry( HWND hWnd
, WinSalFrame
* pFrame
, RECT
* pParentRect
)
3861 // calculate and set frame geometry of a maximized window - useful if the window is still hidden
3863 // dualmonitor support:
3864 // Get screensize of the monitor with the mouse pointer
3870 GetCursorPos( &pt
);
3871 aRectMouse
.left
= pt
.x
;
3872 aRectMouse
.top
= pt
.y
;
3873 aRectMouse
.right
= pt
.x
+2;
3874 aRectMouse
.bottom
= pt
.y
+2;
3875 pParentRect
= &aRectMouse
;
3879 ImplSalGetWorkArea( hWnd
, &aRect
, pParentRect
);
3881 // a maximized window has no other borders than the caption
3882 pFrame
->maGeometry
.nLeftDecoration
= pFrame
->maGeometry
.nRightDecoration
= pFrame
->maGeometry
.nBottomDecoration
= 0;
3883 pFrame
->maGeometry
.nTopDecoration
= pFrame
->mbCaption
? GetSystemMetrics( SM_CYCAPTION
) : 0;
3885 aRect
.top
+= pFrame
->maGeometry
.nTopDecoration
;
3886 pFrame
->maGeometry
.nX
= aRect
.left
;
3887 pFrame
->maGeometry
.nY
= aRect
.top
;
3888 pFrame
->maGeometry
.nWidth
= aRect
.right
- aRect
.left
;
3889 pFrame
->maGeometry
.nHeight
= aRect
.bottom
- aRect
.top
;
3892 static void UpdateFrameGeometry( HWND hWnd
, WinSalFrame
* pFrame
)
3898 GetWindowRect( hWnd
, &aRect
);
3899 pFrame
->maGeometry
.nX
= 0;
3900 pFrame
->maGeometry
.nY
= 0;
3901 pFrame
->maGeometry
.nWidth
= 0;
3902 pFrame
->maGeometry
.nHeight
= 0;
3903 pFrame
->maGeometry
.nLeftDecoration
= 0;
3904 pFrame
->maGeometry
.nTopDecoration
= 0;
3905 pFrame
->maGeometry
.nRightDecoration
= 0;
3906 pFrame
->maGeometry
.nBottomDecoration
= 0;
3907 pFrame
->maGeometry
.nDisplayScreenNumber
= 0;
3909 if ( IsIconic( hWnd
) )
3915 ClientToScreen(hWnd
, &aPt
);
3916 int cx
= aPt
.x
- aRect
.left
;
3917 pFrame
->maGeometry
.nTopDecoration
= aPt
.y
- aRect
.top
;
3919 pFrame
->maGeometry
.nLeftDecoration
= cx
;
3920 pFrame
->maGeometry
.nRightDecoration
= cx
;
3922 pFrame
->maGeometry
.nX
= aPt
.x
;
3923 pFrame
->maGeometry
.nY
= aPt
.y
;
3926 GetClientRect( hWnd
, &aInnerRect
);
3927 if( aInnerRect
.right
)
3929 // improve right decoration
3930 aPt
.x
=aInnerRect
.right
;
3931 aPt
.y
=aInnerRect
.top
;
3932 ClientToScreen(hWnd
, &aPt
);
3933 pFrame
->maGeometry
.nRightDecoration
= aRect
.right
- aPt
.x
;
3935 if( aInnerRect
.bottom
) // may be zero if window was not shown yet
3936 pFrame
->maGeometry
.nBottomDecoration
+= aRect
.bottom
- aPt
.y
- aInnerRect
.bottom
;
3938 // bottom border is typically the same as left/right
3939 pFrame
->maGeometry
.nBottomDecoration
= pFrame
->maGeometry
.nLeftDecoration
;
3941 int nWidth
= aRect
.right
- aRect
.left
3942 - pFrame
->maGeometry
.nRightDecoration
- pFrame
->maGeometry
.nLeftDecoration
;
3943 int nHeight
= aRect
.bottom
- aRect
.top
3944 - pFrame
->maGeometry
.nBottomDecoration
- pFrame
->maGeometry
.nTopDecoration
;
3946 pFrame
->maGeometry
.nHeight
= nHeight
< 0 ? 0 : nHeight
;
3947 pFrame
->maGeometry
.nWidth
= nWidth
< 0 ? 0 : nWidth
;
3948 pFrame
->updateScreenNumber();
3951 static void ImplCallMoveHdl( HWND hWnd
)
3953 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3956 pFrame
->CallCallback( SalEvent::Move
, nullptr );
3957 // to avoid doing Paint twice by VCL and SAL
3958 //if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
3959 // UpdateWindow( hWnd );
3963 static void ImplCallClosePopupsHdl( HWND hWnd
)
3965 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
3968 pFrame
->CallCallback( SalEvent::ClosePopups
, nullptr );
3972 static void ImplHandleMoveMsg( HWND hWnd
)
3974 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, SAL_MSG_POSTMOVE
);
3977 UpdateFrameGeometry( hWnd
, pFrame
);
3979 if ( GetWindowStyle( hWnd
) & WS_VISIBLE
)
3980 pFrame
->mbDefPos
= false;
3982 // protect against recursion
3983 if ( !pFrame
->mbInMoveMsg
)
3985 // adjust window again for FullScreenMode
3986 pFrame
->mbInMoveMsg
= true;
3987 if ( pFrame
->mbFullScreen
)
3988 ImplSalFrameFullScreenPos( pFrame
);
3989 pFrame
->mbInMoveMsg
= false;
3993 ImplSaveFrameState( pFrame
);
3996 //#93851 if we call this handler, VCL floating windows are not updated correctly
3997 ImplCallMoveHdl( hWnd
);
3999 ImplSalYieldMutexRelease();
4003 static void ImplCallSizeHdl( HWND hWnd
)
4005 // as Windows can send these messages also, we have to use
4006 // the Solar semaphore
4007 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, SAL_MSG_POSTCALLSIZE
);
4010 pFrame
->CallCallback( SalEvent::Resize
, nullptr );
4011 // to avoid double Paints by VCL and SAL
4012 if ( IsWindowVisible( hWnd
) && !pFrame
->mbInShow
)
4013 UpdateWindow( hWnd
);
4015 ImplSalYieldMutexRelease();
4019 static void ImplHandleSizeMsg( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
4021 if ( (wParam
!= SIZE_MAXSHOW
) && (wParam
!= SIZE_MAXHIDE
) )
4023 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4026 UpdateFrameGeometry( hWnd
, pFrame
);
4028 pFrame
->mnWidth
= static_cast<int>(LOWORD(lParam
));
4029 pFrame
->mnHeight
= static_cast<int>(HIWORD(lParam
));
4031 ImplSaveFrameState( pFrame
);
4033 ImplCallSizeHdl( hWnd
);
4035 WinSalTimer
* pTimer
= static_cast<WinSalTimer
*>( ImplGetSVData()->maSchedCtx
.mpSalTimer
);
4037 pTimer
->SetForceRealTimer( true );
4042 static void ImplHandleFocusMsg( HWND hWnd
)
4044 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, SAL_MSG_POSTFOCUS
);
4047 if ( !WinSalFrame::mbInReparent
)
4049 bool bGotFocus
= ::GetFocus() == hWnd
;
4052 if ( IsWindowVisible( hWnd
) && !pFrame
->mbInShow
)
4053 UpdateWindow( hWnd
);
4055 // do we support IME?
4056 if ( pFrame
->mbIME
&& pFrame
->mhDefIMEContext
)
4058 UINT nImeProps
= ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY
);
4060 pFrame
->mbSpezIME
= (nImeProps
& IME_PROP_SPECIAL_UI
) != 0;
4061 pFrame
->mbAtCursorIME
= (nImeProps
& IME_PROP_AT_CARET
) != 0;
4062 pFrame
->mbHandleIME
= !pFrame
->mbSpezIME
;
4065 pFrame
->CallCallback( bGotFocus
? SalEvent::GetFocus
: SalEvent::LoseFocus
, nullptr );
4067 ImplSalYieldMutexRelease();
4071 static void ImplHandleCloseMsg( HWND hWnd
)
4073 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, WM_CLOSE
);
4076 pFrame
->CallCallback( SalEvent::Close
, nullptr );
4077 ImplSalYieldMutexRelease();
4081 static bool ImplHandleShutDownMsg( HWND hWnd
)
4084 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, 0, 0, DeferPolicy::Blocked
);
4087 nRet
= pFrame
->CallCallback( SalEvent::Shutdown
, nullptr );
4088 ImplSalYieldMutexRelease();
4093 static void ImplHandleSettingsChangeMsg( HWND hWnd
, UINT nMsg
,
4094 WPARAM wParam
, LPARAM lParam
)
4096 SalEvent nSalEvent
= SalEvent::SettingsChanged
;
4098 if ( nMsg
== WM_DEVMODECHANGE
)
4099 nSalEvent
= SalEvent::PrinterChanged
;
4100 else if ( nMsg
== WM_DISPLAYCHANGE
)
4101 nSalEvent
= SalEvent::DisplayChanged
;
4102 else if ( nMsg
== WM_FONTCHANGE
)
4103 nSalEvent
= SalEvent::FontChanged
;
4104 else if ( nMsg
== WM_WININICHANGE
)
4108 if ( ImplSalWICompareAscii( reinterpret_cast<const wchar_t*>(lParam
), "devices" ) == 0 )
4109 nSalEvent
= SalEvent::PrinterChanged
;
4113 if ( nMsg
== WM_SETTINGCHANGE
)
4115 if ( wParam
== SPI_SETWHEELSCROLLLINES
)
4116 aSalShlData
.mnWheelScrollLines
= ImplSalGetWheelScrollLines();
4117 else if( wParam
== SPI_SETWHEELSCROLLCHARS
)
4118 aSalShlData
.mnWheelScrollChars
= ImplSalGetWheelScrollChars();
4121 if ( WM_SYSCOLORCHANGE
== nMsg
&& GetSalData()->mhDitherPal
)
4122 ImplUpdateSysColorEntries();
4124 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, 0, 0, DeferPolicy::Blocked
);
4127 if ( (nMsg
== WM_DISPLAYCHANGE
) || (nMsg
== WM_WININICHANGE
) )
4129 if ( pFrame
->mbFullScreen
)
4130 ImplSalFrameFullScreenPos( pFrame
);
4133 pFrame
->CallCallback( nSalEvent
, nullptr );
4134 ImplSalYieldMutexRelease();
4138 static void ImplHandleUserEvent( HWND hWnd
, LPARAM lParam
)
4140 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, 0, 0, DeferPolicy::Blocked
);
4143 pFrame
->CallCallback( SalEvent::UserEvent
, reinterpret_cast<void*>(lParam
) );
4144 ImplSalYieldMutexRelease();
4148 static void ImplHandleForcePalette( HWND hWnd
)
4150 SalData
* pSalData
= GetSalData();
4151 HPALETTE hPal
= pSalData
->mhDitherPal
;
4154 WinSalFrame
* pFrame
= ProcessOrDeferMessage( hWnd
, SAL_MSG_FORCEPALETTE
);
4155 if ( pFrame
&& pFrame
->mpLocalGraphics
&& pFrame
->mpLocalGraphics
->getHDC() )
4157 WinSalGraphics
* pGraphics
= pFrame
->mpLocalGraphics
;
4158 if (pGraphics
->getDefPal())
4160 SelectPalette( pGraphics
->getHDC(), hPal
, FALSE
);
4161 if ( RealizePalette( pGraphics
->getHDC() ) )
4163 InvalidateRect( hWnd
, nullptr, FALSE
);
4164 UpdateWindow( hWnd
);
4165 pFrame
->CallCallback( SalEvent::DisplayChanged
, nullptr );
4170 ImplSalYieldMutexRelease();
4174 static LRESULT
ImplHandlePalette( bool bFrame
, HWND hWnd
, UINT nMsg
,
4175 WPARAM wParam
, LPARAM lParam
, bool& rDef
)
4177 SalData
* pSalData
= GetSalData();
4178 HPALETTE hPal
= pSalData
->mhDitherPal
;
4183 if ( pSalData
->mbInPalChange
)
4186 if ( (nMsg
== WM_PALETTECHANGED
) || (nMsg
== SAL_MSG_POSTPALCHANGED
) )
4188 if ( reinterpret_cast<HWND
>(wParam
) == hWnd
)
4192 bool bReleaseMutex
= false;
4193 if ( (nMsg
== WM_QUERYNEWPALETTE
) || (nMsg
== WM_PALETTECHANGED
) )
4195 // as Windows can send these messages also, we have to use
4196 // the Solar semaphore
4197 if ( ImplSalYieldMutexTryToAcquire() )
4198 bReleaseMutex
= true;
4199 else if ( nMsg
== WM_QUERYNEWPALETTE
)
4201 bool const ret
= PostMessageW(hWnd
, SAL_MSG_POSTQUERYNEWPAL
, wParam
, lParam
);
4202 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
4204 else /* ( nMsg == WM_PALETTECHANGED ) */
4206 bool const ret
= PostMessageW(hWnd
, SAL_MSG_POSTPALCHANGED
, wParam
, lParam
);
4207 SAL_WARN_IF(!ret
, "vcl", "ERROR: PostMessage() failed!");
4211 WinSalVirtualDevice
*pTempVD
;
4212 WinSalFrame
* pTempFrame
;
4213 WinSalGraphics
* pGraphics
;
4220 pSalData
->mbInPalChange
= true;
4222 // reset all palettes in VirDevs and Frames
4223 pTempVD
= pSalData
->mpFirstVD
;
4226 pGraphics
= pTempVD
->getGraphics();
4227 if ( pGraphics
->getDefPal() )
4229 SelectPalette( pGraphics
->getHDC(),
4230 pGraphics
->getDefPal(),
4233 pTempVD
= pTempVD
->getNext();
4235 pTempFrame
= pSalData
->mpFirstFrame
;
4236 while ( pTempFrame
)
4238 pGraphics
= pTempFrame
->mpLocalGraphics
;
4239 if ( pGraphics
&& pGraphics
->getHDC() && pGraphics
->getDefPal() )
4241 SelectPalette( pGraphics
->getHDC(),
4242 pGraphics
->getDefPal(),
4245 pTempFrame
= pTempFrame
->mpNextFrame
;
4248 // re-initialize palette
4249 WinSalFrame
* pFrame
= nullptr;
4251 pFrame
= GetWindowPtr( hWnd
);
4252 if ( pFrame
&& pFrame
->mpLocalGraphics
&& pFrame
->mpLocalGraphics
->getHDC() )
4254 hDC
= pFrame
->mpLocalGraphics
->getHDC();
4259 hDC
= GetDC( hWnd
);
4262 UnrealizeObject( hPal
);
4263 hOldPal
= SelectPalette( hDC
, hPal
, TRUE
);
4264 nCols
= RealizePalette( hDC
);
4265 bUpdate
= nCols
!= 0;
4268 SelectPalette( hDC
, hOldPal
, TRUE
);
4269 ReleaseDC( hWnd
, hDC
);
4272 // reset all palettes in VirDevs and Frames
4273 pTempVD
= pSalData
->mpFirstVD
;
4276 pGraphics
= pTempVD
->getGraphics();
4277 if ( pGraphics
->getDefPal() )
4279 SelectPalette( pGraphics
->getHDC(), hPal
, TRUE
);
4280 RealizePalette( pGraphics
->getHDC() );
4282 pTempVD
= pTempVD
->getNext();
4284 pTempFrame
= pSalData
->mpFirstFrame
;
4285 while ( pTempFrame
)
4287 if ( pTempFrame
!= pFrame
)
4289 pGraphics
= pTempFrame
->mpLocalGraphics
;
4290 if ( pGraphics
&& pGraphics
->getHDC() && pGraphics
->getDefPal() )
4292 SelectPalette( pGraphics
->getHDC(), hPal
, TRUE
);
4293 if ( RealizePalette( pGraphics
->getHDC() ) )
4297 pTempFrame
= pTempFrame
->mpNextFrame
;
4300 // if colors changed, update the window
4303 pTempFrame
= pSalData
->mpFirstFrame
;
4304 while ( pTempFrame
)
4306 pGraphics
= pTempFrame
->mpLocalGraphics
;
4307 if ( pGraphics
&& pGraphics
->getHDC() && pGraphics
->getDefPal() )
4309 InvalidateRect( pTempFrame
->mhWnd
, nullptr, FALSE
);
4310 UpdateWindow( pTempFrame
->mhWnd
);
4311 pTempFrame
->CallCallback( SalEvent::DisplayChanged
, nullptr );
4313 pTempFrame
= pTempFrame
->mpNextFrame
;
4317 pSalData
->mbInPalChange
= false;
4319 if ( bReleaseMutex
)
4320 ImplSalYieldMutexRelease();
4322 if ( nMsg
== WM_PALETTECHANGED
)
4328 static bool ImplHandleMinMax( HWND hWnd
, LPARAM lParam
)
4332 if ( ImplSalYieldMutexTryToAcquire() )
4334 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4337 MINMAXINFO
* pMinMax
= reinterpret_cast<MINMAXINFO
*>(lParam
);
4339 if ( pFrame
->mbFullScreen
)
4345 ImplSalCalcFullScreenSize( pFrame
, nX
, nY
, nDX
, nDY
);
4347 if ( pMinMax
->ptMaxPosition
.x
> nX
)
4348 pMinMax
->ptMaxPosition
.x
= nX
;
4349 if ( pMinMax
->ptMaxPosition
.y
> nY
)
4350 pMinMax
->ptMaxPosition
.y
= nY
;
4352 if ( pMinMax
->ptMaxSize
.x
< nDX
)
4353 pMinMax
->ptMaxSize
.x
= nDX
;
4354 if ( pMinMax
->ptMaxSize
.y
< nDY
)
4355 pMinMax
->ptMaxSize
.y
= nDY
;
4356 if ( pMinMax
->ptMaxTrackSize
.x
< nDX
)
4357 pMinMax
->ptMaxTrackSize
.x
= nDX
;
4358 if ( pMinMax
->ptMaxTrackSize
.y
< nDY
)
4359 pMinMax
->ptMaxTrackSize
.y
= nDY
;
4361 pMinMax
->ptMinTrackSize
.x
= nDX
;
4362 pMinMax
->ptMinTrackSize
.y
= nDY
;
4367 if ( pFrame
->mnMinWidth
|| pFrame
->mnMinHeight
)
4369 int nWidth
= pFrame
->mnMinWidth
;
4370 int nHeight
= pFrame
->mnMinHeight
;
4372 ImplSalAddBorder( pFrame
, nWidth
, nHeight
);
4374 if ( pMinMax
->ptMinTrackSize
.x
< nWidth
)
4375 pMinMax
->ptMinTrackSize
.x
= nWidth
;
4376 if ( pMinMax
->ptMinTrackSize
.y
< nHeight
)
4377 pMinMax
->ptMinTrackSize
.y
= nHeight
;
4380 if ( pFrame
->mnMaxWidth
|| pFrame
->mnMaxHeight
)
4382 int nWidth
= pFrame
->mnMaxWidth
;
4383 int nHeight
= pFrame
->mnMaxHeight
;
4385 ImplSalAddBorder( pFrame
, nWidth
, nHeight
);
4387 if( nWidth
> 0 && nHeight
> 0 ) // protect against int overflow due to INT_MAX initialisation
4389 if ( pMinMax
->ptMaxTrackSize
.x
> nWidth
)
4390 pMinMax
->ptMaxTrackSize
.x
= nWidth
;
4391 if ( pMinMax
->ptMaxTrackSize
.y
> nHeight
)
4392 pMinMax
->ptMaxTrackSize
.y
= nHeight
;
4397 ImplSalYieldMutexRelease();
4403 // retrieves the SalMenuItem pointer from a hMenu
4404 // the pointer is stored in every item, so if no position
4405 // is specified we just use the first item (ie, pos=0)
4406 // if bByPosition is false then nPos denotes a menu id instead of a position
4407 static WinSalMenuItem
* ImplGetSalMenuItem( HMENU hMenu
, UINT nPos
, bool bByPosition
=true )
4409 MENUITEMINFOW mi
= {};
4410 mi
.cbSize
= sizeof( mi
);
4411 mi
.fMask
= MIIM_DATA
;
4412 if( !GetMenuItemInfoW( hMenu
, nPos
, bByPosition
, &mi
) )
4413 SAL_WARN("vcl", "GetMenuItemInfoW failed: " << WindowsErrorString(GetLastError()));
4415 return reinterpret_cast<WinSalMenuItem
*>(mi
.dwItemData
);
4418 // returns the index of the currently selected item if any or -1
4419 static int ImplGetSelectedIndex( HMENU hMenu
)
4421 MENUITEMINFOW mi
= {};
4422 mi
.cbSize
= sizeof( mi
);
4423 mi
.fMask
= MIIM_STATE
;
4424 int n
= GetMenuItemCount( hMenu
);
4427 for(int i
=0; i
<n
; i
++ )
4429 if( !GetMenuItemInfoW( hMenu
, i
, TRUE
, &mi
) )
4430 SAL_WARN( "vcl", "GetMenuItemInfoW failed: " << WindowsErrorString( GetLastError() ) );
4433 if( mi
.fState
& MFS_HILITE
)
4441 static LRESULT
ImplMenuChar( HWND
, WPARAM wParam
, LPARAM lParam
)
4443 LRESULT nRet
= MNC_IGNORE
;
4444 HMENU hMenu
= reinterpret_cast<HMENU
>(lParam
);
4445 OUString
aMnemonic( "&" + OUStringChar(static_cast<sal_Unicode
>(LOWORD(wParam
))) );
4446 aMnemonic
= aMnemonic
.toAsciiLowerCase(); // we only have ascii mnemonics
4448 // search the mnemonic in the current menu
4449 int nItemCount
= GetMenuItemCount( hMenu
);
4452 int idxSelected
= ImplGetSelectedIndex( hMenu
);
4453 int idx
= idxSelected
!= -1 ? idxSelected
+1 : 0; // if duplicate mnemonics cycle through menu
4454 for( int i
=0; i
< nItemCount
; i
++, idx
++ )
4456 WinSalMenuItem
* pSalMenuItem
= ImplGetSalMenuItem( hMenu
, idx
% nItemCount
);
4459 OUString aStr
= pSalMenuItem
->mText
;
4460 aStr
= aStr
.toAsciiLowerCase();
4461 if( aStr
.indexOf( aMnemonic
) != -1 )
4463 if( idxFound
== -1 )
4464 idxFound
= idx
% nItemCount
;
4466 break; // duplicate found
4470 nRet
= MAKELRESULT( idxFound
, MNC_EXECUTE
);
4472 // duplicate mnemonics, just select the next occurrence
4473 nRet
= MAKELRESULT( idxFound
, MNC_SELECT
);
4478 static LRESULT
ImplMeasureItem( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
4483 // request was sent by a menu
4485 MEASUREITEMSTRUCT
*pMI
= reinterpret_cast<LPMEASUREITEMSTRUCT
>(lParam
);
4486 if( pMI
->CtlType
!= ODT_MENU
)
4489 WinSalMenuItem
*pSalMenuItem
= reinterpret_cast<WinSalMenuItem
*>(pMI
->itemData
);
4493 HDC hdc
= GetDC( hWnd
);
4496 NONCLIENTMETRICSW ncm
= {};
4497 ncm
.cbSize
= sizeof( ncm
);
4498 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0 );
4500 // Assume every menu item can be default and printed bold
4501 //ncm.lfMenuFont.lfWeight = FW_BOLD;
4503 HFONT hfntOld
= static_cast<HFONT
>(SelectObject(hdc
, CreateFontIndirectW( &ncm
.lfMenuFont
)));
4505 // menu text and accelerator
4506 OUString
aStr(pSalMenuItem
->mText
);
4507 if( pSalMenuItem
->mAccelText
.getLength() )
4509 aStr
+= " " + pSalMenuItem
->mAccelText
;
4511 GetTextExtentPoint32W( hdc
, o3tl::toW(aStr
.getStr()),
4512 aStr
.getLength(), &strSize
);
4515 Size
bmpSize( 16, 16 );
4516 //if( !!pSalMenuItem->maBitmap )
4517 // bmpSize = pSalMenuItem->maBitmap.GetSizePixel();
4520 Size
checkSize( GetSystemMetrics( SM_CXMENUCHECK
), GetSystemMetrics( SM_CYMENUCHECK
) );
4522 pMI
->itemWidth
= checkSize
.Width() + 3 + bmpSize
.Width() + 3 + strSize
.cx
;
4523 pMI
->itemHeight
= std::max( std::max( checkSize
.Height(), bmpSize
.Height() ), tools::Long(strSize
.cy
) );
4524 pMI
->itemHeight
+= 4;
4526 DeleteObject( SelectObject(hdc
, hfntOld
) );
4527 ReleaseDC( hWnd
, hdc
);
4533 static LRESULT
ImplDrawItem(HWND
, WPARAM wParam
, LPARAM lParam
)
4538 // request was sent by a menu
4540 DRAWITEMSTRUCT
*pDI
= reinterpret_cast<LPDRAWITEMSTRUCT
>(lParam
);
4541 if( pDI
->CtlType
!= ODT_MENU
)
4544 WinSalMenuItem
*pSalMenuItem
= reinterpret_cast<WinSalMenuItem
*>(pDI
->itemData
);
4548 COLORREF clrPrevText
, clrPrevBkgnd
;
4551 bool fChecked
= (pDI
->itemState
& ODS_CHECKED
);
4552 bool fSelected
= (pDI
->itemState
& ODS_SELECTED
);
4553 bool fDisabled
= (pDI
->itemState
& (ODS_DISABLED
| ODS_GRAYED
));
4555 // Set the appropriate foreground and background colors.
4556 RECT aRect
= pDI
->rcItem
;
4559 clrPrevText
= SetTextColor( pDI
->hDC
, GetSysColor( COLOR_GRAYTEXT
) );
4561 clrPrevText
= SetTextColor( pDI
->hDC
, GetSysColor( fSelected
? COLOR_HIGHLIGHTTEXT
: COLOR_MENUTEXT
) );
4563 DWORD colBackground
= GetSysColor( fSelected
? COLOR_HIGHLIGHT
: COLOR_MENU
);
4564 clrPrevBkgnd
= SetBkColor( pDI
->hDC
, colBackground
);
4566 hbrOld
= static_cast<HBRUSH
>(SelectObject( pDI
->hDC
, CreateSolidBrush( GetBkColor( pDI
->hDC
) ) ));
4569 if(!PatBlt( pDI
->hDC
, aRect
.left
, aRect
.top
, aRect
.right
-aRect
.left
, aRect
.bottom
-aRect
.top
, PATCOPY
))
4570 SAL_WARN("vcl", "PatBlt failed: " << WindowsErrorString(GetLastError()));
4572 int lineHeight
= aRect
.bottom
-aRect
.top
;
4577 int checkWidth
= GetSystemMetrics( SM_CXMENUCHECK
);
4578 int checkHeight
= GetSystemMetrics( SM_CYMENUCHECK
);
4584 r
.right
= checkWidth
;
4585 r
.bottom
= checkWidth
;
4586 HDC memDC
= CreateCompatibleDC( pDI
->hDC
);
4587 HBITMAP memBmp
= CreateCompatibleBitmap( pDI
->hDC
, checkWidth
, checkHeight
);
4588 HBITMAP hOldBmp
= static_cast<HBITMAP
>(SelectObject( memDC
, memBmp
));
4589 DrawFrameControl( memDC
, &r
, DFC_MENU
, DFCS_MENUCHECK
);
4590 BitBlt( pDI
->hDC
, x
, y
+(lineHeight
-checkHeight
)/2, checkWidth
, checkHeight
, memDC
, 0, 0, SRCAND
);
4591 DeleteObject( SelectObject( memDC
, hOldBmp
) );
4596 //Size bmpSize = aBitmap.GetSizePixel();
4597 Size
bmpSize(16, 16);
4598 if( !!pSalMenuItem
->maBitmap
)
4600 Bitmap
aBitmap( pSalMenuItem
->maBitmap
);
4602 // set transparent pixels to background color
4604 colBackground
= RGB(255,255,255);
4605 aBitmap
.Replace( COL_LIGHTMAGENTA
,
4606 Color( GetRValue(colBackground
),GetGValue(colBackground
),GetBValue(colBackground
) ));
4608 WinSalBitmap
* pSalBmp
= static_cast<WinSalBitmap
*>(aBitmap
.ImplGetSalBitmap().get());
4609 HGLOBAL hDrawDIB
= pSalBmp
->ImplGethDIB();
4613 PBITMAPINFO pBI
= static_cast<PBITMAPINFO
>(GlobalLock( hDrawDIB
));
4614 PBYTE pBits
= reinterpret_cast<PBYTE
>(pBI
) + pBI
->bmiHeader
.biSize
+
4615 WinSalBitmap::ImplGetDIBColorCount( hDrawDIB
) * sizeof( RGBQUAD
);
4617 HBITMAP hBmp
= CreateDIBitmap( pDI
->hDC
, &pBI
->bmiHeader
, CBM_INIT
, pBits
, pBI
, DIB_RGB_COLORS
);
4618 GlobalUnlock( hDrawDIB
);
4620 HBRUSH hbrIcon
= CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT
) );
4621 DrawStateW( pDI
->hDC
, hbrIcon
, nullptr, reinterpret_cast<LPARAM
>(hBmp
), WPARAM(0),
4622 x
, y
+(lineHeight
-bmpSize
.Height())/2, bmpSize
.Width(), bmpSize
.Height(),
4623 DST_BITMAP
| (fDisabled
? (fSelected
? DSS_MONO
: DSS_DISABLED
) : DSS_NORMAL
) );
4625 DeleteObject( hbrIcon
);
4626 DeleteObject( hBmp
);
4630 x
+= bmpSize
.Width() + 3;
4633 NONCLIENTMETRICSW ncm
= {};
4634 ncm
.cbSize
= sizeof( ncm
);
4635 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0 );
4637 // Print default menu entry with bold font
4638 //if ( pDI->itemState & ODS_DEFAULT )
4639 // ncm.lfMenuFont.lfWeight = FW_BOLD;
4641 hfntOld
= static_cast<HFONT
>(SelectObject(pDI
->hDC
, CreateFontIndirectW( &ncm
.lfMenuFont
)));
4644 OUString
aStr( pSalMenuItem
->mText
);
4645 GetTextExtentPoint32W( pDI
->hDC
, o3tl::toW(aStr
.getStr()),
4646 aStr
.getLength(), &strSize
);
4648 if(!DrawStateW( pDI
->hDC
, nullptr, nullptr,
4649 reinterpret_cast<LPARAM
>(aStr
.getStr()),
4650 WPARAM(0), aRect
.left
, aRect
.top
+ (lineHeight
- strSize
.cy
)/2, 0, 0,
4651 DST_PREFIXTEXT
| (fDisabled
&& !fSelected
? DSS_DISABLED
: DSS_NORMAL
) ) )
4652 SAL_WARN("vcl", "DrawStateW failed: " << WindowsErrorString(GetLastError()));
4654 if( pSalMenuItem
->mAccelText
.getLength() )
4657 aStr
= pSalMenuItem
->mAccelText
;
4658 GetTextExtentPoint32W( pDI
->hDC
, o3tl::toW(aStr
.getStr()),
4659 aStr
.getLength(), &strSizeA
);
4661 GetTextMetricsW( pDI
->hDC
, &tm
);
4663 // position the accelerator string to the right but leave space for the
4664 // (potential) submenu arrow (tm.tmMaxCharWidth)
4665 if(!DrawStateW( pDI
->hDC
, nullptr, nullptr,
4666 reinterpret_cast<LPARAM
>(aStr
.getStr()),
4667 WPARAM(0), aRect
.right
-strSizeA
.cx
-tm
.tmMaxCharWidth
, aRect
.top
+ (lineHeight
- strSizeA
.cy
)/2, 0, 0,
4668 DST_TEXT
| (fDisabled
&& !fSelected
? DSS_DISABLED
: DSS_NORMAL
) ) )
4669 SAL_WARN("vcl", "DrawStateW failed: " << WindowsErrorString(GetLastError()));
4672 // Restore the original font and colors.
4673 DeleteObject( SelectObject( pDI
->hDC
, hbrOld
) );
4674 DeleteObject( SelectObject( pDI
->hDC
, hfntOld
) );
4675 SetTextColor(pDI
->hDC
, clrPrevText
);
4676 SetBkColor(pDI
->hDC
, clrPrevBkgnd
);
4681 static bool ImplHandleMenuActivate( HWND hWnd
, WPARAM wParam
, LPARAM
)
4684 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4688 HMENU hMenu
= reinterpret_cast<HMENU
>(wParam
);
4689 // WORD nPos = LOWORD (lParam);
4690 // bool bWindowMenu = (bool) HIWORD(lParam);
4692 // Send activate and deactivate together, so we have not keep track of opened menus
4693 // this will be enough to have the menus updated correctly
4694 SalMenuEvent aMenuEvt
;
4695 WinSalMenuItem
*pSalMenuItem
= ImplGetSalMenuItem( hMenu
, 0 );
4697 aMenuEvt
.mpMenu
= pSalMenuItem
->mpMenu
;
4699 aMenuEvt
.mpMenu
= nullptr;
4701 bool nRet
= pFrame
->CallCallback( SalEvent::MenuActivate
, &aMenuEvt
);
4703 nRet
= pFrame
->CallCallback( SalEvent::MenuDeactivate
, &aMenuEvt
);
4705 pFrame
->mLastActivatedhMenu
= hMenu
;
4710 static bool ImplHandleMenuSelect( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
4713 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4717 WORD nId
= LOWORD(wParam
); // menu item or submenu index
4718 WORD nFlags
= HIWORD(wParam
);
4719 HMENU hMenu
= reinterpret_cast<HMENU
>(lParam
);
4721 // check if we have to process the message
4722 if( !GetSalData()->IsKnownMenuHandle( hMenu
) )
4725 bool bByPosition
= false;
4726 if( nFlags
& MF_POPUP
)
4730 if ( hMenu
&& !pFrame
->mLastActivatedhMenu
)
4732 // we never activated a menu (ie, no WM_INITMENUPOPUP has occurred yet)
4733 // which means this must be the menubar -> send activation/deactivation
4734 SalMenuEvent aMenuEvt
;
4735 WinSalMenuItem
*pSalMenuItem
= ImplGetSalMenuItem( hMenu
, nId
, bByPosition
);
4737 aMenuEvt
.mpMenu
= pSalMenuItem
->mpMenu
;
4739 aMenuEvt
.mpMenu
= nullptr;
4741 nRet
= pFrame
->CallCallback( SalEvent::MenuActivate
, &aMenuEvt
);
4743 nRet
= pFrame
->CallCallback( SalEvent::MenuDeactivate
, &aMenuEvt
);
4745 pFrame
->mLastActivatedhMenu
= hMenu
;
4748 if( !hMenu
&& nFlags
== 0xFFFF )
4750 // all menus are closed, reset activation logic
4751 pFrame
->mLastActivatedhMenu
= nullptr;
4756 // hMenu must be saved, as it is not passed in WM_COMMAND which always occurs after a selection
4757 // if a menu is closed due to a command selection then hMenu is NULL, but WM_COMMAND comes later
4758 // so we must not overwrite it in this case
4759 pFrame
->mSelectedhMenu
= hMenu
;
4761 // send highlight event
4762 if( nFlags
& MF_POPUP
)
4765 // wParam now carries an index instead of an id -> retrieve id
4766 MENUITEMINFOW mi
= {};
4767 mi
.cbSize
= sizeof( mi
);
4769 if( GetMenuItemInfoW( hMenu
, LOWORD(wParam
), TRUE
, &mi
) )
4770 nId
= sal::static_int_cast
<WORD
>(mi
.wID
);
4773 SalMenuEvent aMenuEvt
;
4774 aMenuEvt
.mnId
= nId
;
4775 WinSalMenuItem
*pSalMenuItem
= ImplGetSalMenuItem( hMenu
, nId
, false );
4777 aMenuEvt
.mpMenu
= pSalMenuItem
->mpMenu
;
4779 aMenuEvt
.mpMenu
= nullptr;
4781 nRet
= pFrame
->CallCallback( SalEvent::MenuHighlight
, &aMenuEvt
);
4787 static bool ImplHandleCommand( HWND hWnd
, WPARAM wParam
, LPARAM
)
4789 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4794 if( !HIWORD(wParam
) )
4797 WORD nId
= LOWORD(wParam
);
4798 if( nId
) // zero for separators
4800 SalMenuEvent aMenuEvt
;
4801 aMenuEvt
.mnId
= nId
;
4802 WinSalMenuItem
*pSalMenuItem
= ImplGetSalMenuItem( pFrame
->mSelectedhMenu
, nId
, false );
4804 aMenuEvt
.mpMenu
= pSalMenuItem
->mpMenu
;
4806 aMenuEvt
.mpMenu
= nullptr;
4808 nRet
= pFrame
->CallCallback( SalEvent::MenuCommand
, &aMenuEvt
);
4814 static bool ImplHandleSysCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
4816 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4820 WPARAM nCommand
= wParam
& 0xFFF0;
4822 if ( pFrame
->mbFullScreen
)
4824 bool bMaximize
= IsZoomed( pFrame
->mhWnd
);
4825 bool bMinimize
= IsIconic( pFrame
->mhWnd
);
4826 if ( (nCommand
== SC_SIZE
) ||
4827 (!bMinimize
&& (nCommand
== SC_MOVE
)) ||
4828 (!bMaximize
&& (nCommand
== SC_MAXIMIZE
)) ||
4829 (bMaximize
&& (nCommand
== SC_RESTORE
)) )
4835 if ( nCommand
== SC_MOVE
)
4837 WinSalTimer
* pTimer
= static_cast<WinSalTimer
*>( ImplGetSVData()->maSchedCtx
.mpSalTimer
);
4839 pTimer
->SetForceRealTimer( true );
4842 if ( nCommand
== SC_KEYMENU
)
4844 // do not process SC_KEYMENU if we have a native menu
4845 // Windows should handle this
4846 if( GetMenu( hWnd
) )
4849 // Process here KeyMenu events only for Alt to activate the MenuBar,
4850 // or if a SysChild window is in focus, as Alt-key-combinations are
4851 // only processed via this event
4852 if ( !LOWORD( lParam
) )
4854 // Only trigger if no other key is pressed.
4855 // Contrary to Docu the CharCode is delivered with the x-coordinate
4856 // that is pressed in addition.
4857 // Also 32 for space, 99 for c, 100 for d, ...
4858 // As this is not documented, we check the state of the space-bar
4859 if ( GetKeyState( VK_SPACE
) & 0x8000 )
4862 // to avoid activating the MenuBar for Alt+MouseKey
4863 if ( (GetKeyState( VK_LBUTTON
) & 0x8000) ||
4864 (GetKeyState( VK_RBUTTON
) & 0x8000) ||
4865 (GetKeyState( VK_MBUTTON
) & 0x8000) ||
4866 (GetKeyState( VK_SHIFT
) & 0x8000) )
4869 SalKeyEvent aKeyEvt
;
4870 aKeyEvt
.mnCode
= KEY_MENU
;
4871 aKeyEvt
.mnCharCode
= 0;
4872 aKeyEvt
.mnRepeat
= 0;
4873 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
4874 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
4879 // check if a SysChild is in focus
4880 HWND hFocusWnd
= ::GetFocus();
4881 if ( hFocusWnd
&& ImplFindSalObject( hFocusWnd
) )
4883 char cKeyCode
= static_cast<char>(static_cast<unsigned char>(LOWORD( lParam
)));
4885 if ( (cKeyCode
>= 65) && (cKeyCode
<= 90) )
4887 // We only accept 0-9 and A-Z; all other keys have to be
4888 // processed by the SalObj hook
4889 if ( ((cKeyCode
>= 48) && (cKeyCode
<= 57)) ||
4890 ((cKeyCode
>= 97) && (cKeyCode
<= 122)) )
4892 sal_uInt16 nModCode
= 0;
4893 if ( GetKeyState( VK_SHIFT
) & 0x8000 )
4894 nModCode
|= KEY_SHIFT
;
4895 if ( GetKeyState( VK_CONTROL
) & 0x8000 )
4896 nModCode
|= KEY_MOD1
;
4897 nModCode
|= KEY_MOD2
;
4899 SalKeyEvent aKeyEvt
;
4900 if ( (cKeyCode
>= 48) && (cKeyCode
<= 57) )
4901 aKeyEvt
.mnCode
= KEY_0
+(cKeyCode
-48);
4903 aKeyEvt
.mnCode
= KEY_A
+(cKeyCode
-97);
4904 aKeyEvt
.mnCode
|= nModCode
;
4905 aKeyEvt
.mnCharCode
= cKeyCode
;
4906 aKeyEvt
.mnRepeat
= 0;
4907 bool nRet
= pFrame
->CallCallback( SalEvent::KeyInput
, &aKeyEvt
);
4908 pFrame
->CallCallback( SalEvent::KeyUp
, &aKeyEvt
);
4918 static void ImplHandleInputLangChange( HWND hWnd
, WPARAM
, LPARAM lParam
)
4920 ImplSalYieldMutexAcquireWithWait();
4922 // check if we support IME
4923 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4928 if ( pFrame
->mbIME
&& pFrame
->mhDefIMEContext
)
4930 HKL hKL
= reinterpret_cast<HKL
>(lParam
);
4931 UINT nImeProps
= ImmGetProperty( hKL
, IGP_PROPERTY
);
4933 pFrame
->mbSpezIME
= (nImeProps
& IME_PROP_SPECIAL_UI
) != 0;
4934 pFrame
->mbAtCursorIME
= (nImeProps
& IME_PROP_AT_CARET
) != 0;
4935 pFrame
->mbHandleIME
= !pFrame
->mbSpezIME
;
4938 // trigger input language and codepage update
4939 UINT nLang
= pFrame
->mnInputLang
;
4940 ImplUpdateInputLang( pFrame
);
4943 if( nLang
!= pFrame
->mnInputLang
)
4944 pFrame
->CallCallback( SalEvent::InputLanguageChange
, nullptr );
4946 // reinit spec. keys
4947 GetSalData()->initKeyCodeMap();
4949 ImplSalYieldMutexRelease();
4952 static void ImplUpdateIMECursorPos( WinSalFrame
* pFrame
, HIMC hIMC
)
4954 COMPOSITIONFORM aForm
= {};
4956 // get cursor position and from it calculate default position
4957 // for the composition window
4958 SalExtTextInputPosEvent aPosEvt
;
4959 pFrame
->CallCallback( SalEvent::ExtTextInputPos
, &aPosEvt
);
4960 if ( (aPosEvt
.mnX
== -1) && (aPosEvt
.mnY
== -1) )
4961 aForm
.dwStyle
|= CFS_DEFAULT
;
4964 aForm
.dwStyle
|= CFS_POINT
;
4965 aForm
.ptCurrentPos
.x
= aPosEvt
.mnX
;
4966 aForm
.ptCurrentPos
.y
= aPosEvt
.mnY
;
4968 ImmSetCompositionWindow( hIMC
, &aForm
);
4970 // Because not all IME's use this values, we create
4971 // a Windows caret to force the Position from the IME
4972 if ( GetFocus() == pFrame
->mhWnd
)
4974 CreateCaret( pFrame
->mhWnd
, nullptr,
4975 aPosEvt
.mnWidth
, aPosEvt
.mnHeight
);
4976 SetCaretPos( aPosEvt
.mnX
, aPosEvt
.mnY
);
4980 static bool ImplHandleIMEStartComposition( HWND hWnd
)
4984 ImplSalYieldMutexAcquireWithWait();
4986 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
4989 HIMC hIMC
= ImmGetContext( hWnd
);
4992 ImplUpdateIMECursorPos( pFrame
, hIMC
);
4993 ImmReleaseContext( hWnd
, hIMC
);
4996 if ( pFrame
->mbHandleIME
)
4998 if ( pFrame
->mbAtCursorIME
)
5003 ImplSalYieldMutexRelease();
5008 static bool ImplHandleIMECompositionInput( WinSalFrame
* pFrame
,
5009 HIMC hIMC
, LPARAM lParam
)
5014 SalExtTextInputEvent aEvt
;
5015 aEvt
.mpTextAttr
= nullptr;
5016 aEvt
.mnCursorPos
= 0;
5017 aEvt
.mnCursorFlags
= 0;
5019 // If we get a result string, then we handle this input
5020 if ( lParam
& GCS_RESULTSTR
)
5024 LONG nTextLen
= ImmGetCompositionStringW( hIMC
, GCS_RESULTSTR
, nullptr, 0 ) / sizeof( WCHAR
);
5025 if ( nTextLen
>= 0 )
5027 auto pTextBuf
= std::make_unique
<WCHAR
[]>(nTextLen
);
5028 ImmGetCompositionStringW( hIMC
, GCS_RESULTSTR
, pTextBuf
.get(), nTextLen
*sizeof( WCHAR
) );
5029 aEvt
.maText
= OUString( o3tl::toU(pTextBuf
.get()), static_cast<sal_Int32
>(nTextLen
) );
5032 aEvt
.mnCursorPos
= aEvt
.maText
.getLength();
5033 pFrame
->CallCallback( SalEvent::ExtTextInput
, &aEvt
);
5034 pFrame
->CallCallback( SalEvent::EndExtTextInput
, nullptr );
5035 ImplUpdateIMECursorPos( pFrame
, hIMC
);
5038 // If the IME doesn't support OnSpot input, then there is nothing to do
5039 if ( !pFrame
->mbAtCursorIME
)
5042 // If we get new Composition data, then we handle this new input
5043 if ( (lParam
& (GCS_COMPSTR
| GCS_COMPATTR
)) ||
5044 ((lParam
& GCS_CURSORPOS
) && !(lParam
& GCS_RESULTSTR
)) )
5048 ExtTextInputAttr
* pSalAttrAry
= nullptr;
5049 LONG nTextLen
= ImmGetCompositionStringW( hIMC
, GCS_COMPSTR
, nullptr, 0 ) / sizeof( WCHAR
);
5053 auto pTextBuf
= std::make_unique
<WCHAR
[]>(nTextLen
);
5054 ImmGetCompositionStringW( hIMC
, GCS_COMPSTR
, pTextBuf
.get(), nTextLen
*sizeof( WCHAR
) );
5055 aEvt
.maText
= OUString( o3tl::toU(pTextBuf
.get()), static_cast<sal_Int32
>(nTextLen
) );
5058 std::unique_ptr
<BYTE
[]> pAttrBuf
;
5059 LONG nAttrLen
= ImmGetCompositionStringW( hIMC
, GCS_COMPATTR
, nullptr, 0 );
5062 pAttrBuf
.reset(new BYTE
[nAttrLen
]);
5063 ImmGetCompositionStringW( hIMC
, GCS_COMPATTR
, pAttrBuf
.get(), nAttrLen
);
5068 sal_Int32 nTextLen2
= aEvt
.maText
.getLength();
5069 pSalAttrAry
= new ExtTextInputAttr
[nTextLen2
];
5070 memset( pSalAttrAry
, 0, nTextLen2
*sizeof( sal_uInt16
) );
5071 for( sal_Int32 i
= 0; (i
< nTextLen2
) && (i
< nAttrLen
); i
++ )
5073 BYTE nWinAttr
= pAttrBuf
.get()[i
];
5074 ExtTextInputAttr nSalAttr
;
5075 if ( nWinAttr
== ATTR_TARGET_CONVERTED
)
5077 nSalAttr
= ExtTextInputAttr::BoldUnderline
;
5078 aEvt
.mnCursorFlags
|= EXTTEXTINPUT_CURSOR_INVISIBLE
;
5080 else if ( nWinAttr
== ATTR_CONVERTED
)
5081 nSalAttr
= ExtTextInputAttr::DashDotUnderline
;
5082 else if ( nWinAttr
== ATTR_TARGET_NOTCONVERTED
)
5083 nSalAttr
= ExtTextInputAttr::Highlight
;
5084 else if ( nWinAttr
== ATTR_INPUT_ERROR
)
5085 nSalAttr
= ExtTextInputAttr::RedText
| ExtTextInputAttr::DottedUnderline
;
5086 else /* ( nWinAttr == ATTR_INPUT ) */
5087 nSalAttr
= ExtTextInputAttr::DottedUnderline
;
5088 pSalAttrAry
[i
] = nSalAttr
;
5091 aEvt
.mpTextAttr
= pSalAttrAry
;
5095 // Only when we get new composition data, we must send this event
5096 if ( (nTextLen
> 0) || !(lParam
& GCS_RESULTSTR
) )
5098 // End the mode, if the last character is deleted
5099 if ( !nTextLen
&& !pFrame
->mbCandidateMode
)
5101 pFrame
->CallCallback( SalEvent::ExtTextInput
, &aEvt
);
5102 pFrame
->CallCallback( SalEvent::EndExtTextInput
, nullptr );
5106 // Because Cursor-Position and DeltaStart never updated
5107 // from the korean input engine, we must handle this here
5108 if ( lParam
& CS_INSERTCHAR
)
5110 aEvt
.mnCursorPos
= nTextLen
;
5111 if ( aEvt
.mnCursorPos
&& (lParam
& CS_NOMOVECARET
) )
5115 aEvt
.mnCursorPos
= LOWORD( ImmGetCompositionStringW( hIMC
, GCS_CURSORPOS
, nullptr, 0 ) );
5117 if ( pFrame
->mbCandidateMode
)
5118 aEvt
.mnCursorFlags
|= EXTTEXTINPUT_CURSOR_INVISIBLE
;
5119 if ( lParam
& CS_NOMOVECARET
)
5120 aEvt
.mnCursorFlags
|= EXTTEXTINPUT_CURSOR_OVERWRITE
;
5122 pFrame
->CallCallback( SalEvent::ExtTextInput
, &aEvt
);
5124 ImplUpdateIMECursorPos( pFrame
, hIMC
);
5128 delete [] pSalAttrAry
;
5134 static bool ImplHandleIMEComposition( HWND hWnd
, LPARAM lParam
)
5137 ImplSalYieldMutexAcquireWithWait();
5139 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5140 if ( pFrame
&& (!lParam
|| (lParam
& GCS_RESULTSTR
)) )
5142 // reset the background mode for each text input,
5143 // as some tools such as RichWin may have changed it
5144 if ( pFrame
->mpLocalGraphics
&&
5145 pFrame
->mpLocalGraphics
->getHDC() )
5146 SetBkMode( pFrame
->mpLocalGraphics
->getHDC(), TRANSPARENT
);
5149 if ( pFrame
&& pFrame
->mbHandleIME
)
5153 SalExtTextInputEvent aEvt
;
5154 aEvt
.mpTextAttr
= nullptr;
5155 aEvt
.mnCursorPos
= 0;
5156 aEvt
.mnCursorFlags
= 0;
5157 pFrame
->CallCallback( SalEvent::ExtTextInput
, &aEvt
);
5158 pFrame
->CallCallback( SalEvent::EndExtTextInput
, nullptr );
5160 else if ( lParam
& (GCS_RESULTSTR
| GCS_COMPSTR
| GCS_COMPATTR
| GCS_CURSORPOS
) )
5162 HIMC hIMC
= ImmGetContext( hWnd
);
5165 if ( ImplHandleIMECompositionInput( pFrame
, hIMC
, lParam
) )
5168 ImmReleaseContext( hWnd
, hIMC
);
5173 ImplSalYieldMutexRelease();
5177 static bool ImplHandleIMEEndComposition( HWND hWnd
)
5181 ImplSalYieldMutexAcquireWithWait();
5183 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5184 if ( pFrame
&& pFrame
->mbHandleIME
)
5186 if ( pFrame
->mbAtCursorIME
)
5190 ImplSalYieldMutexRelease();
5195 static bool ImplHandleAppCommand( HWND hWnd
, LPARAM lParam
, LRESULT
& nRet
)
5197 MediaCommand nCommand
;
5198 switch( GET_APPCOMMAND_LPARAM(lParam
) )
5200 case APPCOMMAND_MEDIA_CHANNEL_DOWN
: nCommand
= MediaCommand::ChannelDown
; break;
5201 case APPCOMMAND_MEDIA_CHANNEL_UP
: nCommand
= MediaCommand::ChannelUp
; break;
5202 case APPCOMMAND_MEDIA_NEXTTRACK
: nCommand
= MediaCommand::NextTrack
; break;
5203 case APPCOMMAND_MEDIA_PAUSE
: nCommand
= MediaCommand::Pause
; break;
5204 case APPCOMMAND_MEDIA_PLAY
: nCommand
= MediaCommand::Play
; break;
5205 case APPCOMMAND_MEDIA_PLAY_PAUSE
: nCommand
= MediaCommand::PlayPause
; break;
5206 case APPCOMMAND_MEDIA_PREVIOUSTRACK
: nCommand
= MediaCommand::PreviousTrack
; break;
5207 case APPCOMMAND_MEDIA_RECORD
: nCommand
= MediaCommand::Record
; break;
5208 case APPCOMMAND_MEDIA_REWIND
: nCommand
= MediaCommand::Rewind
; break;
5209 case APPCOMMAND_MEDIA_STOP
: nCommand
= MediaCommand::Stop
; break;
5210 case APPCOMMAND_MIC_ON_OFF_TOGGLE
: nCommand
= MediaCommand::MicOnOffToggle
; break;
5211 case APPCOMMAND_MICROPHONE_VOLUME_DOWN
: nCommand
= MediaCommand::MicrophoneVolumeDown
; break;
5212 case APPCOMMAND_MICROPHONE_VOLUME_MUTE
: nCommand
= MediaCommand::MicrophoneVolumeMute
; break;
5213 case APPCOMMAND_MICROPHONE_VOLUME_UP
: nCommand
= MediaCommand::MicrophoneVolumeUp
; break;
5214 case APPCOMMAND_VOLUME_DOWN
: nCommand
= MediaCommand::VolumeDown
; break;
5215 case APPCOMMAND_VOLUME_MUTE
: nCommand
= MediaCommand::VolumeMute
; break;
5216 case APPCOMMAND_VOLUME_UP
: nCommand
= MediaCommand::VolumeUp
; break;
5221 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5222 vcl::Window
*pWindow
= pFrame
? pFrame
->GetWindow() : nullptr;
5227 CommandMediaData
aMediaData(nCommand
);
5228 CommandEvent
aCEvt( aPoint
, CommandEventId::Media
, false, &aMediaData
);
5229 NotifyEvent
aNCmdEvt( MouseNotifyEvent::COMMAND
, pWindow
, &aCEvt
);
5231 if ( !ImplCallPreNotify( aNCmdEvt
) )
5233 pWindow
->Command( aCEvt
);
5235 return !aMediaData
.GetPassThroughToOS();
5242 static void ImplHandleIMENotify( HWND hWnd
, WPARAM wParam
)
5244 if ( wParam
== WPARAM(IMN_OPENCANDIDATE
) )
5246 ImplSalYieldMutexAcquireWithWait();
5248 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5249 if ( pFrame
&& pFrame
->mbHandleIME
&&
5250 pFrame
->mbAtCursorIME
)
5252 // we want to hide the cursor
5253 pFrame
->mbCandidateMode
= true;
5254 ImplHandleIMEComposition( hWnd
, GCS_CURSORPOS
);
5256 HWND hWnd2
= pFrame
->mhWnd
;
5257 HIMC hIMC
= ImmGetContext( hWnd2
);
5260 LONG nBufLen
= ImmGetCompositionStringW( hIMC
, GCS_COMPSTR
, nullptr, 0 );
5263 SalExtTextInputPosEvent aPosEvt
;
5264 pFrame
->CallCallback( SalEvent::ExtTextInputPos
, &aPosEvt
);
5267 CANDIDATEFORM aForm
;
5269 aForm
.dwStyle
= CFS_EXCLUDE
;
5270 aForm
.ptCurrentPos
.x
= aPosEvt
.mnX
;
5271 aForm
.ptCurrentPos
.y
= aPosEvt
.mnY
+1;
5272 aForm
.rcArea
.left
= aPosEvt
.mnX
;
5273 aForm
.rcArea
.top
= aPosEvt
.mnY
;
5274 aForm
.rcArea
.right
= aForm
.rcArea
.left
+aPosEvt
.mnExtWidth
+1;
5275 aForm
.rcArea
.bottom
= aForm
.rcArea
.top
+aPosEvt
.mnHeight
+1;
5276 ImmSetCandidateWindow( hIMC
, &aForm
);
5279 ImmReleaseContext( hWnd2
, hIMC
);
5283 ImplSalYieldMutexRelease();
5285 else if ( wParam
== WPARAM(IMN_CLOSECANDIDATE
) )
5287 ImplSalYieldMutexAcquireWithWait();
5288 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5290 pFrame
->mbCandidateMode
= false;
5291 ImplSalYieldMutexRelease();
5296 ImplHandleGetObject(HWND hWnd
, LPARAM lParam
, WPARAM wParam
, LRESULT
& nRet
)
5298 if (!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
5300 // IA2 should be enabled automatically
5301 AllSettings aSettings
= Application::GetSettings();
5302 MiscSettings aMisc
= aSettings
.GetMiscSettings();
5303 aMisc
.SetEnableATToolSupport(true);
5304 // The above is enough, since aMisc changes the same shared ImplMiscData as used in global
5305 // settings, so no need to call aSettings.SetMiscSettings and Application::SetSettings
5307 if (!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
5308 return false; // locked down somehow ?
5311 ImplSVData
* pSVData
= ImplGetSVData();
5313 // Make sure to launch Accessibility only the following criteria are satisfied
5314 // to avoid RFT interrupts regular accessibility processing
5315 if ( !pSVData
->mxAccessBridge
.is() )
5317 if( !InitAccessBridge() )
5321 uno::Reference
< accessibility::XMSAAService
> xMSAA( pSVData
->mxAccessBridge
, uno::UNO_QUERY
);
5324 sal_Int32 lParam32
= static_cast<sal_Int32
>(lParam
);
5325 sal_uInt32 wParam32
= static_cast<sal_uInt32
>(wParam
);
5327 // mhOnSetTitleWnd not set to reasonable value anywhere...
5328 if ( lParam32
== OBJID_CLIENT
)
5330 nRet
= xMSAA
->getAccObjectPtr(
5331 reinterpret_cast<sal_Int64
>(hWnd
), lParam32
, wParam32
);
5339 static LRESULT
ImplHandleIMEReconvertString( HWND hWnd
, LPARAM lParam
)
5341 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5342 LPRECONVERTSTRING pReconvertString
= reinterpret_cast<LPRECONVERTSTRING
>(lParam
);
5344 SalSurroundingTextRequestEvent aEvt
;
5345 aEvt
.maText
.clear();
5346 aEvt
.mnStart
= aEvt
.mnEnd
= 0;
5348 UINT nImeProps
= ImmGetProperty( GetKeyboardLayout( 0 ), IGP_SETCOMPSTR
);
5349 if( (nImeProps
& SCS_CAP_SETRECONVERTSTRING
) == 0 )
5351 // This IME does not support reconversion.
5355 if( !pReconvertString
)
5357 // The first call for reconversion.
5358 pFrame
->CallCallback( SalEvent::StartReconversion
, nullptr );
5360 // Retrieve the surrounding text from the focused control.
5361 pFrame
->CallCallback( SalEvent::SurroundingTextRequest
, &aEvt
);
5363 if( aEvt
.maText
.isEmpty())
5368 nRet
= sizeof(RECONVERTSTRING
) + (aEvt
.maText
.getLength() + 1) * sizeof(WCHAR
);
5372 // The second call for reconversion.
5374 // Retrieve the surrounding text from the focused control.
5375 pFrame
->CallCallback( SalEvent::SurroundingTextRequest
, &aEvt
);
5376 nRet
= sizeof(RECONVERTSTRING
) + (aEvt
.maText
.getLength() + 1) * sizeof(WCHAR
);
5378 pReconvertString
->dwStrOffset
= sizeof(RECONVERTSTRING
);
5379 pReconvertString
->dwStrLen
= aEvt
.maText
.getLength();
5380 pReconvertString
->dwCompStrOffset
= aEvt
.mnStart
* sizeof(WCHAR
);
5381 pReconvertString
->dwCompStrLen
= aEvt
.mnEnd
- aEvt
.mnStart
;
5382 pReconvertString
->dwTargetStrOffset
= pReconvertString
->dwCompStrOffset
;
5383 pReconvertString
->dwTargetStrLen
= pReconvertString
->dwCompStrLen
;
5385 memcpy( pReconvertString
+ 1, aEvt
.maText
.getStr(), (aEvt
.maText
.getLength() + 1) * sizeof(WCHAR
) );
5388 // just return the required size of buffer to reconvert.
5392 static LRESULT
ImplHandleIMEConfirmReconvertString( HWND hWnd
, LPARAM lParam
)
5394 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5395 LPRECONVERTSTRING pReconvertString
= reinterpret_cast<LPRECONVERTSTRING
>(lParam
);
5396 SalSurroundingTextRequestEvent aEvt
;
5397 aEvt
.maText
.clear();
5398 aEvt
.mnStart
= aEvt
.mnEnd
= 0;
5400 pFrame
->CallCallback( SalEvent::SurroundingTextRequest
, &aEvt
);
5402 sal_uLong nTmpStart
= pReconvertString
->dwCompStrOffset
/ sizeof(WCHAR
);
5403 sal_uLong nTmpEnd
= nTmpStart
+ pReconvertString
->dwCompStrLen
;
5405 if( nTmpStart
!= aEvt
.mnStart
|| nTmpEnd
!= aEvt
.mnEnd
)
5407 SalSurroundingTextSelectionChangeEvent aSelEvt
{ nTmpStart
, nTmpEnd
};
5408 pFrame
->CallCallback( SalEvent::SurroundingTextSelectionChange
, &aSelEvt
);
5414 static LRESULT
ImplHandleIMEQueryCharPosition( HWND hWnd
, LPARAM lParam
) {
5415 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5416 PIMECHARPOSITION pQueryCharPosition
= reinterpret_cast<PIMECHARPOSITION
>(lParam
);
5417 if ( pQueryCharPosition
->dwSize
< sizeof(IMECHARPOSITION
) )
5420 SalQueryCharPositionEvent aEvt
;
5421 aEvt
.mbValid
= false;
5422 aEvt
.mnCharPos
= pQueryCharPosition
->dwCharPos
;
5424 pFrame
->CallCallback( SalEvent::QueryCharPosition
, &aEvt
);
5426 if ( !aEvt
.mbValid
)
5429 if ( aEvt
.mbVertical
)
5431 // For vertical writing, the base line is left edge of the rectangle
5432 // and the target position is top-right corner.
5433 pQueryCharPosition
->pt
.x
= aEvt
.mnCursorBoundX
+ aEvt
.mnCursorBoundWidth
;
5434 pQueryCharPosition
->pt
.y
= aEvt
.mnCursorBoundY
;
5435 pQueryCharPosition
->cLineHeight
= aEvt
.mnCursorBoundWidth
;
5439 // For horizontal writing, the base line is the bottom edge of the rectangle.
5440 // and the target position is top-left corner.
5441 pQueryCharPosition
->pt
.x
= aEvt
.mnCursorBoundX
;
5442 pQueryCharPosition
->pt
.y
= aEvt
.mnCursorBoundY
;
5443 pQueryCharPosition
->cLineHeight
= aEvt
.mnCursorBoundHeight
;
5446 // Currently not supported but many IMEs usually ignore them.
5447 pQueryCharPosition
->rcDocument
.left
= 0;
5448 pQueryCharPosition
->rcDocument
.top
= 0;
5449 pQueryCharPosition
->rcDocument
.right
= 0;
5450 pQueryCharPosition
->rcDocument
.bottom
= 0;
5455 void SalTestMouseLeave()
5457 SalData
* pSalData
= GetSalData();
5459 if ( pSalData
->mhWantLeaveMsg
&& !::GetCapture() )
5462 GetCursorPos( &aPt
);
5463 if ( pSalData
->mhWantLeaveMsg
!= WindowFromPoint( aPt
) )
5464 SendMessageW( pSalData
->mhWantLeaveMsg
, SAL_MSG_MOUSELEAVE
, 0, MAKELPARAM( aPt
.x
, aPt
.y
) );
5468 static bool ImplSalWheelMousePos( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
,
5473 aScreenPt
.x
= static_cast<short>(LOWORD( lParam
));
5474 aScreenPt
.y
= static_cast<short>(HIWORD( lParam
));
5475 // find child window that is at this position
5477 HWND hWheelWnd
= hWnd
;
5480 hChildWnd
= hWheelWnd
;
5482 ScreenToClient( hChildWnd
, &aPt
);
5483 hWheelWnd
= ChildWindowFromPointEx( hChildWnd
, aPt
, CWP_SKIPINVISIBLE
| CWP_SKIPTRANSPARENT
);
5485 while ( hWheelWnd
&& (hWheelWnd
!= hChildWnd
) );
5486 if ( hWheelWnd
&& (hWheelWnd
!= hWnd
) &&
5487 (hWheelWnd
!= ::GetFocus()) && IsWindowEnabled( hWheelWnd
) )
5489 rResult
= SendMessageW( hWheelWnd
, nMsg
, wParam
, lParam
);
5496 static LRESULT CALLBACK
SalFrameWndProc( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
, bool& rDef
)
5499 static bool bInWheelMsg
= false;
5500 static bool bInQueryEnd
= false;
5502 SAL_INFO("vcl.gdi.wndproc", "SalFrameWndProc(nMsg=" << nMsg
<< ", wParam=" << wParam
<< ", lParam=" << lParam
<< ")");
5504 // By WM_CREATE we connect the frame with the window handle
5505 if ( nMsg
== WM_CREATE
)
5507 // Save Window-Instance in Windowhandle
5508 // Can also be used for the A-Version, because the struct
5509 // to access lpCreateParams is the same structure
5510 CREATESTRUCTW
* pStruct
= reinterpret_cast<CREATESTRUCTW
*>(lParam
);
5511 WinSalFrame
* pFrame
= static_cast<WinSalFrame
*>(pStruct
->lpCreateParams
);
5512 if ( pFrame
!= nullptr )
5514 SetWindowPtr( hWnd
, pFrame
);
5515 // Set HWND already here, as data might be used already
5516 // when messages are being sent by CreateWindow()
5517 pFrame
->mhWnd
= hWnd
;
5518 pFrame
->maSysData
.hWnd
= hWnd
;
5523 ImplSVData
* pSVData
= ImplGetSVData();
5524 // #i72707# TODO: the mbDeInit check will not be needed
5525 // once all windows that are not properly closed on exit got fixed
5526 if( pSVData
->mbDeInit
)
5529 if ( WM_USER_SYSTEM_WINDOW_ACTIVATED
== nMsg
)
5538 case WM_LBUTTONDOWN
:
5539 case WM_MBUTTONDOWN
:
5540 case WM_RBUTTONDOWN
:
5544 case WM_NCMOUSEMOVE
:
5545 case SAL_MSG_MOUSELEAVE
:
5546 ImplSalYieldMutexAcquireWithWait();
5547 rDef
= !ImplHandleMouseMsg( hWnd
, nMsg
, wParam
, lParam
);
5548 ImplSalYieldMutexRelease();
5551 case WM_NCLBUTTONDOWN
:
5552 case WM_NCMBUTTONDOWN
:
5553 case WM_NCRBUTTONDOWN
:
5554 ImplSalYieldMutexAcquireWithWait();
5555 ImplCallClosePopupsHdl( hWnd
); // close popups...
5556 ImplSalYieldMutexRelease();
5559 case WM_MOUSEACTIVATE
:
5560 if ( LOWORD( lParam
) == HTCLIENT
)
5562 ImplSalYieldMutexAcquireWithWait();
5563 nRet
= LRESULT(ImplHandleMouseActivateMsg( hWnd
));
5564 ImplSalYieldMutexRelease();
5567 nRet
= MA_NOACTIVATE
;
5577 case WM_UNICHAR
: // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0
5581 ImplSalYieldMutexAcquireWithWait();
5582 rDef
= !ImplHandleKeyMsg( hWnd
, nMsg
, wParam
, lParam
, nRet
);
5583 ImplSalYieldMutexRelease();
5587 case WM_MOUSEHWHEEL
:
5588 // protect against recursion, in case the message is returned
5589 // by IE or the external window
5593 rDef
= !ImplHandleWheelMsg( hWnd
, nMsg
, wParam
, lParam
);
5594 // If we did not process the message, re-check if here is a
5595 // connected (?) window that we have to notify.
5597 rDef
= ImplSalWheelMousePos( hWnd
, nMsg
, wParam
, lParam
, nRet
);
5598 bInWheelMsg
= false;
5603 ImplSalYieldMutexAcquireWithWait();
5604 rDef
= !ImplHandleCommand( hWnd
, wParam
, lParam
);
5605 ImplSalYieldMutexRelease();
5608 case WM_INITMENUPOPUP
:
5609 ImplSalYieldMutexAcquireWithWait();
5610 rDef
= !ImplHandleMenuActivate( hWnd
, wParam
, lParam
);
5611 ImplSalYieldMutexRelease();
5615 ImplSalYieldMutexAcquireWithWait();
5616 rDef
= !ImplHandleMenuSelect( hWnd
, wParam
, lParam
);
5617 ImplSalYieldMutexRelease();
5621 ImplSalYieldMutexAcquireWithWait();
5622 nRet
= LRESULT(ImplHandleSysCommand( hWnd
, wParam
, lParam
));
5623 ImplSalYieldMutexRelease();
5629 nRet
= ImplMenuChar( hWnd
, wParam
, lParam
);
5634 case WM_MEASUREITEM
:
5635 nRet
= ImplMeasureItem(hWnd
, wParam
, lParam
);
5641 nRet
= ImplDrawItem(hWnd
, wParam
, lParam
);
5647 case SAL_MSG_POSTMOVE
:
5648 ImplHandleMoveMsg( hWnd
);
5652 ImplHandleSizeMsg( hWnd
, wParam
, lParam
);
5655 case SAL_MSG_POSTCALLSIZE
:
5656 ImplCallSizeHdl( hWnd
);
5660 case WM_GETMINMAXINFO
:
5661 if ( ImplHandleMinMax( hWnd
, lParam
) )
5670 ImplHandlePaintMsg( hWnd
);
5673 case SAL_MSG_POSTPAINT
:
5674 ImplHandlePostPaintMsg( hWnd
, reinterpret_cast<RECT
*>(wParam
) );
5678 case SAL_MSG_FORCEPALETTE
:
5679 ImplHandleForcePalette( hWnd
);
5683 case WM_QUERYNEWPALETTE
:
5684 case SAL_MSG_POSTQUERYNEWPAL
:
5685 nRet
= ImplHandlePalette( true, hWnd
, nMsg
, wParam
, lParam
, rDef
);
5689 // Getting activated, we also want to set our palette.
5690 // We do this in Activate, so that other external child windows
5691 // can overwrite our palette. Thus our palette is set only once
5692 // and not recursively, as at all other places it is set only as
5693 // the background palette.
5694 if ( LOWORD( wParam
) != WA_INACTIVE
)
5695 SendMessageW( hWnd
, SAL_MSG_FORCEPALETTE
, 0, 0 );
5699 // #95133# a system dialog is opened/closed, using our app window as parent
5701 WinSalFrame
* pFrame
= GetWindowPtr( hWnd
);
5702 vcl::Window
*pWin
= nullptr;
5704 pWin
= pFrame
->GetWindow();
5708 pSVData
->maAppData
.mnModalMode
++;
5713 pWin
->EnableInput( false, nullptr );
5714 pWin
->IncModalCount(); // #106303# support frame based modal count
5719 ImplGetSVData()->maAppData
.mnModalMode
--;
5722 pWin
->EnableInput( true, nullptr );
5723 pWin
->DecModalCount(); // #106303# support frame based modal count
5733 case SAL_MSG_POSTFOCUS
:
5734 ImplHandleFocusMsg( hWnd
);
5739 ImplHandleCloseMsg( hWnd
);
5743 case WM_QUERYENDSESSION
:
5746 // handle queryendsession only once
5748 nRet
= LRESULT(!ImplHandleShutDownMsg( hWnd
));
5751 // Issue #16314#: ImplHandleShutDownMsg causes a PostMessage in case of allowing shutdown.
5752 // This posted message was never processed and cause Windows XP to hang after log off
5753 // if there are multiple sessions and the current session wasn't the first one started.
5754 // So if shutdown is allowed we assume that a post message was done and retrieve all
5755 // messages in the message queue and dispatch them before we return control to the system.
5759 SolarMutexGuard aGuard
;
5760 while ( Application::Reschedule( true ) );
5765 ImplSalYieldMutexAcquireWithWait();
5766 ImplSalYieldMutexRelease();
5773 bInQueryEnd
= false; // no shutdown: allow query again
5778 case WM_DISPLAYCHANGE
:
5779 case WM_SETTINGCHANGE
:
5780 case WM_DEVMODECHANGE
:
5782 case WM_SYSCOLORCHANGE
:
5784 ImplHandleSettingsChangeMsg( hWnd
, nMsg
, wParam
, lParam
);
5787 case WM_THEMECHANGED
:
5788 GetSalData()->mbThemeChanged
= true;
5791 case SAL_MSG_USEREVENT
:
5792 ImplHandleUserEvent( hWnd
, lParam
);
5796 case SAL_MSG_CAPTUREMOUSE
:
5800 case SAL_MSG_RELEASEMOUSE
:
5801 if ( ::GetCapture() == hWnd
)
5806 ImplSalToTop( hWnd
, static_cast<SalFrameToTop
>(wParam
) );
5810 ImplSalShow( hWnd
, static_cast<bool>(wParam
), static_cast<bool>(lParam
) );
5813 case SAL_MSG_SETINPUTCONTEXT
:
5814 ImplSalFrameSetInputContext( hWnd
, reinterpret_cast<const SalInputContext
*>(lParam
) );
5817 case SAL_MSG_ENDEXTTEXTINPUT
:
5818 ImplSalFrameEndExtTextInput( hWnd
, static_cast<EndExtTextInputFlags
>(wParam
) );
5822 case WM_INPUTLANGCHANGE
:
5823 ImplHandleInputLangChange( hWnd
, wParam
, lParam
);
5827 // #103487#, some IMEs (eg, those that do not work onspot)
5828 // may send WM_IME_CHAR instead of WM_IME_COMPOSITION
5829 // we just handle it like a WM_CHAR message - seems to work fine
5830 ImplSalYieldMutexAcquireWithWait();
5831 rDef
= !ImplHandleKeyMsg( hWnd
, WM_CHAR
, wParam
, lParam
, nRet
);
5832 ImplSalYieldMutexRelease();
5835 case WM_IME_STARTCOMPOSITION
:
5836 rDef
= ImplHandleIMEStartComposition( hWnd
);
5839 case WM_IME_COMPOSITION
:
5840 rDef
= ImplHandleIMEComposition( hWnd
, lParam
);
5843 case WM_IME_ENDCOMPOSITION
:
5844 rDef
= ImplHandleIMEEndComposition( hWnd
);
5848 ImplHandleIMENotify( hWnd
, wParam
);
5852 ImplSalYieldMutexAcquireWithWait();
5853 if ( ImplHandleGetObject( hWnd
, lParam
, wParam
, nRet
) )
5857 ImplSalYieldMutexRelease();
5861 if( ImplHandleAppCommand( hWnd
, lParam
, nRet
) )
5866 case WM_IME_REQUEST
:
5867 if ( static_cast<sal_uIntPtr
>(wParam
) == IMR_RECONVERTSTRING
)
5869 nRet
= ImplHandleIMEReconvertString( hWnd
, lParam
);
5872 else if( static_cast<sal_uIntPtr
>(wParam
) == IMR_CONFIRMRECONVERTSTRING
)
5874 nRet
= ImplHandleIMEConfirmReconvertString( hWnd
, lParam
);
5877 else if ( static_cast<sal_uIntPtr
>(wParam
) == IMR_QUERYCHARPOSITION
)
5879 if ( ImplSalYieldMutexTryToAcquire() )
5881 nRet
= ImplHandleIMEQueryCharPosition( hWnd
, lParam
);
5882 ImplSalYieldMutexRelease();
5894 LRESULT CALLBACK
SalFrameWndProcW( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
)
5900 nRet
= SalFrameWndProc( hWnd
, nMsg
, wParam
, lParam
, bDef
);
5902 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
5907 nRet
= DefWindowProcW( hWnd
, nMsg
, wParam
, lParam
);
5911 bool ImplHandleGlobalMsg( HWND hWnd
, UINT nMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
& rlResult
)
5913 // handle all messages concerning all frames so they get processed only once
5914 // Must work for Unicode and none Unicode
5915 bool bResult
= false;
5916 if ( (nMsg
== WM_PALETTECHANGED
) || (nMsg
== SAL_MSG_POSTPALCHANGED
) )
5919 rlResult
= ImplHandlePalette( false, hWnd
, nMsg
, wParam
, lParam
, bResult
);
5921 else if( nMsg
== WM_DISPLAYCHANGE
)
5923 WinSalSystem
* pSys
= static_cast<WinSalSystem
*>(ImplGetSalSystem());
5925 pSys
->clearMonitors();
5926 bResult
= (pSys
!= nullptr);
5931 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */