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