merged tag ooo/DEV300_m102
[LibreOffice.git] / vcl / win / source / window / salframe.cxx
blobc1b3a632556e8eba490e2eabfa2acde1fc2cf063
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
31 // i72022: ad-hoc to forcibly enable reconversion
32 #if WINVER < 0x0500
33 #undef WINVER
34 #define WINVER 0x0500
35 #endif
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/container/XIndexAccess.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/awt/Rectangle.hpp>
41 #include <comphelper/processfactory.hxx>
42 #include <unotools/misccfg.hxx>
44 #include <string.h>
45 #include <limits.h>
47 #include <stdio.h>
49 #ifndef _SVWIN_HXX
50 #include <tools/svwin.h>
51 #endif
52 #ifdef __MINGW32__
53 #include <excpt.h>
54 #endif
55 #include <rtl/string.h>
56 #include <rtl/ustring.h>
58 #include <osl/module.h>
59 #include <tools/debug.hxx>
61 // Warning in SDK header
62 #if defined(_MSC_VER) && (_MSC_VER > 1400)
63 #pragma warning( disable: 4242 4244 )
64 #endif
65 #include <wincomp.hxx>
66 #ifndef _SV_SALIDS_HRC
67 #include <salids.hrc>
68 #endif
69 #include <vcl/sysdata.hxx>
70 #include <saldata.hxx>
71 #include <salinst.h>
72 #include <salbmp.h>
73 #include <salgdi.h>
74 #include <salsys.h>
75 #include <salframe.h>
76 #include <salvd.h>
77 #include <salmenu.h>
78 #include <salobj.h>
79 #include <vcl/impbmp.hxx>
80 #include <vcl/timer.hxx>
81 #include <saltimer.h>
82 #include <vcl/settings.hxx>
83 #ifndef _SV_KEYCOES_HXX
84 #include <vcl/keycodes.hxx>
85 #endif
86 #include <vcl/window.h>
87 #include <vcl/window.hxx>
88 #include <vcl/wrkwin.hxx>
89 #include <vcl/sallayout.hxx>
90 #include <vcl/svapp.hxx>
91 #ifndef _VCL_IMPDEL_HXX
92 #include <impdel.hxx>
93 #endif
94 #define COMPILE_MULTIMON_STUBS
95 #include <multimon.h>
96 #include <vector>
97 #ifdef __MINGW32__
98 #include <algorithm>
99 using ::std::max;
100 #endif
102 #include <com/sun/star/uno/Exception.hdl>
104 #include <time.h>
106 using ::rtl::OUString;
107 using namespace ::com::sun::star;
108 using namespace ::com::sun::star::uno;
109 using namespace ::com::sun::star::lang;
110 using namespace ::com::sun::star::container;
111 using namespace ::com::sun::star::beans;
113 // The following defines are newly added in Longhorn
114 #ifndef WM_MOUSEHWHEEL
115 # define WM_MOUSEHWHEEL 0x020E
116 #endif
117 #ifndef SPI_GETWHEELSCROLLCHARS
118 # define SPI_GETWHEELSCROLLCHARS 0x006C
119 #endif
120 #ifndef SPI_SETWHEELSCROLLCHARS
121 # define SPI_SETWHEELSCROLLCHARS 0x006D
122 #endif
126 #if OSL_DEBUG_LEVEL > 1
127 void MyOutputDebugString( char *s) { OutputDebugString( s ); }
128 #endif
130 // misssing prototypes and constants for LayeredWindows
131 extern "C" {
132 //WINUSERAPI sal_Bool WINAPI SetLayeredWindowAttributes(HWND,COLORREF,BYTE,DWORD);
133 typedef sal_Bool ( WINAPI * SetLayeredWindowAttributes_Proc_T ) (HWND,COLORREF,BYTE,DWORD);
134 static SetLayeredWindowAttributes_Proc_T lpfnSetLayeredWindowAttributes;
137 // =======================================================================
139 const unsigned int WM_USER_SYSTEM_WINDOW_ACTIVATED = RegisterWindowMessageA("SYSTEM_WINDOW_ACTIVATED");
141 sal_Bool WinSalFrame::mbInReparent = FALSE;
143 // =======================================================================
145 // Wegen Fehler in Windows-Headerfiles
146 #ifndef IMN_OPENCANDIDATE
147 #define IMN_OPENCANDIDATE 0x0005
148 #endif
149 #ifndef IMN_CLOSECANDIDATE
150 #define IMN_CLOSECANDIDATE 0x0004
151 #endif
153 #ifndef WM_THEMECHANGED
154 #define WM_THEMECHANGED 0x031A
155 #endif
157 // Macros for support of WM_UNICHAR & Keyman 6.0
158 #define Uni_UTF32ToSurrogate1(ch) (((unsigned long) (ch) - 0x10000) / 0x400 + 0xD800)
159 #define Uni_UTF32ToSurrogate2(ch) (((unsigned long) (ch) - 0x10000) % 0x400 + 0xDC00)
160 #define Uni_SupplementaryPlanesStart 0x10000
162 // =======================================================================
164 static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame );
165 static void SetMaximizedFrameGeometry( HWND hWnd, WinSalFrame* pFrame, RECT* pParentRect = NULL );
167 static void ImplSaveFrameState( WinSalFrame* pFrame )
169 // Position, Groesse und Status fuer GetWindowState() merken
170 if ( !pFrame->mbFullScreen )
172 sal_Bool bVisible = (GetWindowStyle( pFrame->mhWnd ) & WS_VISIBLE) != 0;
173 if ( IsIconic( pFrame->mhWnd ) )
175 pFrame->maState.mnState |= SAL_FRAMESTATE_MINIMIZED;
176 if ( bVisible )
177 pFrame->mnShowState = SW_SHOWMAXIMIZED;
179 else if ( IsZoomed( pFrame->mhWnd ) )
181 pFrame->maState.mnState &= ~SAL_FRAMESTATE_MINIMIZED;
182 pFrame->maState.mnState |= SAL_FRAMESTATE_MAXIMIZED;
183 if ( bVisible )
184 pFrame->mnShowState = SW_SHOWMAXIMIZED;
185 pFrame->mbRestoreMaximize = TRUE;
187 WINDOWPLACEMENT aPlacement;
188 aPlacement.length = sizeof(aPlacement);
189 if( GetWindowPlacement( pFrame->mhWnd, &aPlacement ) )
191 RECT aRect = aPlacement.rcNormalPosition;
192 RECT aRect2 = aRect;
193 AdjustWindowRectEx( &aRect2, GetWindowStyle( pFrame->mhWnd ),
194 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
195 long nTopDeco = abs( aRect.top - aRect2.top );
196 long nLeftDeco = abs( aRect.left - aRect2.left );
197 long nBottomDeco = abs( aRect.bottom - aRect2.bottom );
198 long nRightDeco = abs( aRect.right - aRect2.right );
200 pFrame->maState.mnX = aRect.left + nLeftDeco;
201 pFrame->maState.mnY = aRect.top + nTopDeco;
202 pFrame->maState.mnWidth = aRect.right - aRect.left - nLeftDeco - nRightDeco;
203 pFrame->maState.mnHeight = aRect.bottom - aRect.top - nTopDeco - nBottomDeco;
206 else
208 RECT aRect;
209 GetWindowRect( pFrame->mhWnd, &aRect );
211 // to be consistent with Unix, the frame state is without(!) decoration
212 RECT aRect2 = aRect;
213 AdjustWindowRectEx( &aRect2, GetWindowStyle( pFrame->mhWnd ),
214 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
215 long nTopDeco = abs( aRect.top - aRect2.top );
216 long nLeftDeco = abs( aRect.left - aRect2.left );
217 long nBottomDeco = abs( aRect.bottom - aRect2.bottom );
218 long nRightDeco = abs( aRect.right - aRect2.right );
220 pFrame->maState.mnState &= ~(SAL_FRAMESTATE_MINIMIZED | SAL_FRAMESTATE_MAXIMIZED);
221 // subtract decoration
222 pFrame->maState.mnX = aRect.left+nLeftDeco;
223 pFrame->maState.mnY = aRect.top+nTopDeco;
224 pFrame->maState.mnWidth = aRect.right-aRect.left-nLeftDeco-nRightDeco;
225 pFrame->maState.mnHeight = aRect.bottom-aRect.top-nTopDeco-nBottomDeco;
226 if ( bVisible )
227 pFrame->mnShowState = SW_SHOWNORMAL;
228 pFrame->mbRestoreMaximize = FALSE;
233 // -----------------------------------------------------------------------
235 // if pParentRect is set, the workarea of the monitor that contains pParentRect is returned
236 void ImplSalGetWorkArea( HWND hWnd, RECT *pRect, const RECT *pParentRect )
238 static int winVerChecked = 0;
239 static int winVerOk = 0;
241 // check if we or our parent is fullscreen, then the taskbar should be ignored
242 bool bIgnoreTaskbar = false;
243 WinSalFrame* pFrame = GetWindowPtr( hWnd );
244 if( pFrame )
246 Window *pWin = pFrame->GetWindow();
247 while( pWin )
249 WorkWindow *pWorkWin = (pWin->GetType() == WINDOW_WORKWINDOW) ? (WorkWindow *) pWin : NULL;
250 if( pWorkWin && pWorkWin->ImplGetWindowImpl()->mbReallyVisible && pWorkWin->IsFullScreenMode() )
252 bIgnoreTaskbar = true;
253 break;
255 else
256 pWin = pWin->ImplGetWindowImpl()->mpParent;
260 if( !winVerChecked )
262 winVerChecked = 1;
263 winVerOk = 1;
265 // multi monitor calls not available on Win95/NT
266 if ( aSalShlData.maVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
268 if ( aSalShlData.maVersionInfo.dwMajorVersion <= 4 )
269 winVerOk = 0; // NT
271 else if( aSalShlData.maVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
273 if ( aSalShlData.maVersionInfo.dwMajorVersion == 4 && aSalShlData.maVersionInfo.dwMinorVersion == 0 )
274 winVerOk = 0; // Win95
278 // calculates the work area taking multiple monitors into account
279 if( winVerOk )
281 static int nMonitors = GetSystemMetrics( SM_CMONITORS );
282 if( nMonitors == 1 )
284 if( bIgnoreTaskbar )
286 pRect->left = pRect->top = 0;
287 pRect->right = GetSystemMetrics( SM_CXSCREEN );
288 pRect->bottom = GetSystemMetrics( SM_CYSCREEN );
290 else
291 SystemParametersInfo( SPI_GETWORKAREA, 0, pRect, 0 );
293 else
295 if( pParentRect != NULL )
297 // return the size of the monitor where pParentRect lives
298 HMONITOR hMonitor;
299 MONITORINFO mi;
301 // get the nearest monitor to the passed rect.
302 hMonitor = MonitorFromRect(pParentRect, MONITOR_DEFAULTTONEAREST);
304 // get the work area or entire monitor rect.
305 mi.cbSize = sizeof(mi);
306 GetMonitorInfo(hMonitor, &mi);
307 if( !bIgnoreTaskbar )
308 *pRect = mi.rcWork;
309 else
310 *pRect = mi.rcMonitor;
312 else
314 // return the union of all monitors
315 pRect->left = GetSystemMetrics( SM_XVIRTUALSCREEN );
316 pRect->top = GetSystemMetrics( SM_YVIRTUALSCREEN );
317 pRect->right = pRect->left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
318 pRect->bottom = pRect->top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
320 // virtualscreen does not take taskbar into account, so use the corresponding
321 // diffs between screen and workarea from the default screen
322 // however, this is still not perfect: the taskbar might not be on the primary screen
323 if( !bIgnoreTaskbar )
325 RECT wRect, scrRect;
326 SystemParametersInfo( SPI_GETWORKAREA, 0, &wRect, 0 );
327 scrRect.left = 0;
328 scrRect.top = 0;
329 scrRect.right = GetSystemMetrics( SM_CXSCREEN );
330 scrRect.bottom = GetSystemMetrics( SM_CYSCREEN );
332 pRect->left += wRect.left;
333 pRect->top += wRect.top;
334 pRect->right -= scrRect.right - wRect.right;
335 pRect->bottom -= scrRect.bottom - wRect.bottom;
340 else
342 if( bIgnoreTaskbar )
344 pRect->left = pRect->top = 0;
345 pRect->right = GetSystemMetrics( SM_CXSCREEN );
346 pRect->bottom = GetSystemMetrics( SM_CYSCREEN );
348 else
349 SystemParametersInfo( SPI_GETWORKAREA, 0, pRect, 0 );
353 // =======================================================================
355 SalFrame* ImplSalCreateFrame( WinSalInstance* pInst,
356 HWND hWndParent, sal_uLong nSalFrameStyle )
358 WinSalFrame* pFrame = new WinSalFrame;
359 HWND hWnd;
360 DWORD nSysStyle = 0;
361 DWORD nExSysStyle = 0;
362 sal_Bool bSubFrame = FALSE;
364 if( getenv( "SAL_SYNCHRONIZE" ) ) // no buffering of drawing commands
365 GdiSetBatchLimit( 1 );
367 static int bLayeredAPI = -1;
368 if( bLayeredAPI == -1 )
370 bLayeredAPI = 0;
371 // check for W2k and XP
372 if ( aSalShlData.maVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT && aSalShlData.maVersionInfo.dwMajorVersion >= 5 )
374 OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM( "user32" ) );
375 oslModule pLib = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT );
376 oslGenericFunction pFunc = NULL;
377 if( pLib )
378 pFunc = osl_getAsciiFunctionSymbol( pLib, "SetLayeredWindowAttributes" );
380 lpfnSetLayeredWindowAttributes = ( SetLayeredWindowAttributes_Proc_T ) pFunc;
382 bLayeredAPI = pFunc ? 1 : 0;
385 static const char* pEnvTransparentFloats = getenv("SAL_TRANSPARENT_FLOATS" );
387 // determine creation data
388 if ( nSalFrameStyle & (SAL_FRAME_STYLE_PLUG | SAL_FRAME_STYLE_SYSTEMCHILD) )
390 nSysStyle |= WS_CHILD;
391 if( nSalFrameStyle & SAL_FRAME_STYLE_SYSTEMCHILD )
392 nSysStyle |= WS_CLIPSIBLINGS;
394 else
396 // #i87402# commenting out WS_CLIPCHILDREN
397 // this breaks SAL_FRAME_STYLE_SYSTEMCHILD handling, which is not
398 // used currently. Probably SAL_FRAME_STYLE_SYSTEMCHILD should be
399 // removed again.
401 // nSysStyle |= WS_CLIPCHILDREN;
402 if ( hWndParent )
404 nSysStyle |= WS_POPUP;
405 bSubFrame = TRUE;
406 pFrame->mbNoIcon = TRUE;
408 else
410 // Only with WS_OVRLAPPED we get a useful default position/size
411 if ( (nSalFrameStyle & (SAL_FRAME_STYLE_SIZEABLE | SAL_FRAME_STYLE_MOVEABLE)) ==
412 (SAL_FRAME_STYLE_SIZEABLE | SAL_FRAME_STYLE_MOVEABLE) )
413 nSysStyle |= WS_OVERLAPPED;
414 else
416 nSysStyle |= WS_POPUP;
417 if ( !(nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE) )
418 nExSysStyle |= WS_EX_TOOLWINDOW; // avoid taskbar appearance, for eg splash screen
422 if ( nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE )
424 pFrame->mbCaption = TRUE;
425 nSysStyle |= WS_SYSMENU | WS_CAPTION;
426 if ( !hWndParent )
427 nSysStyle |= WS_SYSMENU | WS_MINIMIZEBOX;
428 else
429 nExSysStyle |= WS_EX_DLGMODALFRAME;
431 if ( nSalFrameStyle & SAL_FRAME_STYLE_SIZEABLE )
433 pFrame->mbSizeBorder = TRUE;
434 nSysStyle |= WS_THICKFRAME;
435 if ( !hWndParent )
436 nSysStyle |= WS_MAXIMIZEBOX;
438 else
439 pFrame->mbFixBorder = TRUE;
441 if ( nSalFrameStyle & SAL_FRAME_STYLE_DEFAULT )
442 nExSysStyle |= WS_EX_APPWINDOW;
444 if( nSalFrameStyle & SAL_FRAME_STYLE_TOOLWINDOW
445 // #100656# toolwindows lead to bad alt-tab behaviour, if they have the focus
446 // you must press it twice to leave the application
447 // so toolwindows are only used for non sizeable windows
448 // which are typically small, so a small caption makes sense
450 // #103578# looked too bad - above changes reverted
451 /* && !(nSalFrameStyle & SAL_FRAME_STYLE_SIZEABLE) */ )
453 pFrame->mbNoIcon = TRUE;
454 nExSysStyle |= WS_EX_TOOLWINDOW;
455 if ( pEnvTransparentFloats && bLayeredAPI == 1 /*&& !(nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE) */)
456 nExSysStyle |= WS_EX_LAYERED;
459 if ( nSalFrameStyle & SAL_FRAME_STYLE_FLOAT )
461 nExSysStyle |= WS_EX_TOOLWINDOW;
462 pFrame->mbFloatWin = TRUE;
464 if ( (bLayeredAPI == 1) && (pEnvTransparentFloats /* does not work remote! || (nSalFrameStyle & SAL_FRAME_STYLE_FLOAT_FOCUSABLE) */ ) )
465 nExSysStyle |= WS_EX_LAYERED;
468 if( (nSalFrameStyle & SAL_FRAME_STYLE_TOOLTIP) || (nSalFrameStyle & SAL_FRAME_STYLE_FLOAT_FOCUSABLE) )
469 nExSysStyle |= WS_EX_TOPMOST;
471 // init frame data
472 pFrame->mnStyle = nSalFrameStyle;
474 // determine show style
475 pFrame->mnShowState = SW_SHOWNORMAL;
476 if ( (nSysStyle & (WS_POPUP | WS_MAXIMIZEBOX | WS_THICKFRAME)) == (WS_MAXIMIZEBOX | WS_THICKFRAME) )
478 if ( GetSystemMetrics( SM_CXSCREEN ) <= 1024 )
479 pFrame->mnShowState = SW_SHOWMAXIMIZED;
480 else
482 if ( nSalFrameStyle & SAL_FRAME_STYLE_DEFAULT )
484 SalData* pSalData = GetSalData();
485 pFrame->mnShowState = pSalData->mnCmdShow;
486 if ( (pFrame->mnShowState != SW_SHOWMINIMIZED) &&
487 (pFrame->mnShowState != SW_MINIMIZE) &&
488 (pFrame->mnShowState != SW_SHOWMINNOACTIVE) )
490 if ( (pFrame->mnShowState == SW_SHOWMAXIMIZED) ||
491 (pFrame->mnShowState == SW_MAXIMIZE) )
492 pFrame->mbOverwriteState = FALSE;
493 pFrame->mnShowState = SW_SHOWMAXIMIZED;
495 else
496 pFrame->mbOverwriteState = FALSE;
498 else
500 // Document Windows are also maximized, if the current Document Window
501 // is also maximized
502 HWND hWnd = GetForegroundWindow();
503 if ( hWnd && IsMaximized( hWnd ) &&
504 (GetWindowInstance( hWnd ) == pInst->mhInst) &&
505 ((GetWindowStyle( hWnd ) & (WS_POPUP | WS_MAXIMIZEBOX | WS_THICKFRAME)) == (WS_MAXIMIZEBOX | WS_THICKFRAME)) )
506 pFrame->mnShowState = SW_SHOWMAXIMIZED;
511 // create frame
512 if( true/*aSalShlData.mbWNT*/ )
514 LPCWSTR pClassName;
515 if ( bSubFrame )
517 if ( nSalFrameStyle & (SAL_FRAME_STYLE_MOVEABLE|SAL_FRAME_STYLE_NOSHADOW) ) // check if shadow not wanted
518 pClassName = SAL_SUBFRAME_CLASSNAMEW;
519 else
520 pClassName = SAL_TMPSUBFRAME_CLASSNAMEW; // undecorated floaters will get shadow on XP
522 else
524 if ( nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE )
525 pClassName = SAL_FRAME_CLASSNAMEW;
526 else
527 pClassName = SAL_TMPSUBFRAME_CLASSNAMEW;
529 hWnd = CreateWindowExW( nExSysStyle, pClassName, L"", nSysStyle,
530 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
531 hWndParent, 0, pInst->mhInst, (void*)pFrame );
532 if( !hWnd )
533 ImplWriteLastError( GetLastError(), "CreateWindowEx" );
534 #if OSL_DEBUG_LEVEL > 1
535 // set transparency value
536 if( bLayeredAPI == 1 && GetWindowExStyle( hWnd ) & WS_EX_LAYERED )
537 lpfnSetLayeredWindowAttributes( hWnd, 0, 230, 0x00000002 /*LWA_ALPHA*/ );
538 #endif
540 if ( !hWnd )
542 delete pFrame;
543 return NULL;
546 // If we have an Window with an Caption Bar and without
547 // an MaximizeBox, we change the SystemMenu
548 if ( (nSysStyle & (WS_CAPTION | WS_MAXIMIZEBOX)) == (WS_CAPTION) )
550 HMENU hSysMenu = GetSystemMenu( hWnd, FALSE );
551 if ( hSysMenu )
553 if ( !(nSysStyle & (WS_MINIMIZEBOX | WS_MAXIMIZEBOX)) )
554 DeleteMenu( hSysMenu, SC_RESTORE, MF_BYCOMMAND );
555 else
556 EnableMenuItem( hSysMenu, SC_RESTORE, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED );
557 if ( !(nSysStyle & WS_MINIMIZEBOX) )
558 DeleteMenu( hSysMenu, SC_MINIMIZE, MF_BYCOMMAND );
559 if ( !(nSysStyle & WS_MAXIMIZEBOX) )
560 DeleteMenu( hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND );
561 if ( !(nSysStyle & WS_THICKFRAME) )
562 DeleteMenu( hSysMenu, SC_SIZE, MF_BYCOMMAND );
565 if ( (nSysStyle & WS_SYSMENU) && !(nSalFrameStyle & SAL_FRAME_STYLE_CLOSEABLE) )
567 HMENU hSysMenu = GetSystemMenu( hWnd, FALSE );
568 if ( hSysMenu )
569 EnableMenuItem( hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED );
572 // reset input context
573 pFrame->mhDefIMEContext = ImmAssociateContext( hWnd, 0 );
575 // determine output size and state
576 RECT aRect;
577 GetClientRect( hWnd, &aRect );
578 pFrame->mnWidth = aRect.right;
579 pFrame->mnHeight = aRect.bottom;
580 ImplSaveFrameState( pFrame );
581 pFrame->mbDefPos = TRUE;
583 UpdateFrameGeometry( hWnd, pFrame );
585 if( pFrame->mnShowState == SW_SHOWMAXIMIZED )
587 // #96084 set a useful internal window size because
588 // the window will not be maximized (and the size updated) before show()
590 SetMaximizedFrameGeometry( hWnd, pFrame );
593 return pFrame;
596 // helper that only creates the HWND
597 // to allow for easy reparenting of system windows, (i.e. destroy and create new)
598 HWND ImplSalReCreateHWND( HWND hWndParent, HWND oldhWnd, sal_Bool bAsChild )
600 HINSTANCE hInstance = GetSalData()->mhInst;
601 ULONG nSysStyle = GetWindowLong( oldhWnd, GWL_STYLE );
602 ULONG nExSysStyle = GetWindowLong( oldhWnd, GWL_EXSTYLE );
604 if( bAsChild )
606 nSysStyle = WS_CHILD;
607 nExSysStyle = 0;
610 LPCWSTR pClassName = SAL_SUBFRAME_CLASSNAMEW;
611 HWND hWnd = CreateWindowExW( nExSysStyle, pClassName, L"", nSysStyle,
612 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
613 hWndParent, 0, hInstance, (void*)GetWindowPtr( oldhWnd ) );
614 return hWnd;
617 // =======================================================================
619 // Uebersetzungstabelle von System-Keycodes in StarView-Keycodes
620 #define KEY_TAB_SIZE 146
622 static sal_uInt16 aImplTranslateKeyTab[KEY_TAB_SIZE] =
624 // StarView-Code System-Code Index
625 0, // 0
626 0, // VK_LBUTTON 1
627 0, // VK_RBUTTON 2
628 0, // VK_CANCEL 3
629 0, // VK_MBUTTON 4
630 0, // 5
631 0, // 6
632 0, // 7
633 KEY_BACKSPACE, // VK_BACK 8
634 KEY_TAB, // VK_TAB 9
635 0, // 10
636 0, // 11
637 0, // VK_CLEAR 12
638 KEY_RETURN, // VK_RETURN 13
639 0, // 14
640 0, // 15
641 0, // VK_SHIFT 16
642 0, // VK_CONTROL 17
643 0, // VK_MENU 18
644 0, // VK_PAUSE 19
645 0, // VK_CAPITAL 20
646 0, // VK_HANGUL 21
647 0, // 22
648 0, // 23
649 0, // 24
650 KEY_HANGUL_HANJA, // VK_HANJA 25
651 0, // 26
652 KEY_ESCAPE, // VK_ESCAPE 27
653 0, // 28
654 0, // 29
655 0, // 30
656 0, // 31
657 KEY_SPACE, // VK_SPACE 32
658 KEY_PAGEUP, // VK_PRIOR 33
659 KEY_PAGEDOWN, // VK_NEXT 34
660 KEY_END, // VK_END 35
661 KEY_HOME, // VK_HOME 36
662 KEY_LEFT, // VK_LEFT 37
663 KEY_UP, // VK_UP 38
664 KEY_RIGHT, // VK_RIGHT 39
665 KEY_DOWN, // VK_DOWN 40
666 0, // VK_SELECT 41
667 0, // VK_PRINT 42
668 0, // VK_EXECUTE 43
669 0, // VK_SNAPSHOT 44
670 KEY_INSERT, // VK_INSERT 45
671 KEY_DELETE, // VK_DELETE 46
672 KEY_HELP, // VK_HELP 47
673 KEY_0, // 48
674 KEY_1, // 49
675 KEY_2, // 50
676 KEY_3, // 51
677 KEY_4, // 52
678 KEY_5, // 53
679 KEY_6, // 54
680 KEY_7, // 55
681 KEY_8, // 56
682 KEY_9, // 57
683 0, // 58
684 0, // 59
685 0, // 60
686 0, // 61
687 0, // 62
688 0, // 63
689 0, // 64
690 KEY_A, // 65
691 KEY_B, // 66
692 KEY_C, // 67
693 KEY_D, // 68
694 KEY_E, // 69
695 KEY_F, // 70
696 KEY_G, // 71
697 KEY_H, // 72
698 KEY_I, // 73
699 KEY_J, // 74
700 KEY_K, // 75
701 KEY_L, // 76
702 KEY_M, // 77
703 KEY_N, // 78
704 KEY_O, // 79
705 KEY_P, // 80
706 KEY_Q, // 81
707 KEY_R, // 82
708 KEY_S, // 83
709 KEY_T, // 84
710 KEY_U, // 85
711 KEY_V, // 86
712 KEY_W, // 87
713 KEY_X, // 88
714 KEY_Y, // 89
715 KEY_Z, // 90
716 0, // VK_LWIN 91
717 0, // VK_RWIN 92
718 KEY_CONTEXTMENU, // VK_APPS 93
719 0, // 94
720 0, // 95
721 KEY_0, // VK_NUMPAD0 96
722 KEY_1, // VK_NUMPAD1 97
723 KEY_2, // VK_NUMPAD2 98
724 KEY_3, // VK_NUMPAD3 99
725 KEY_4, // VK_NUMPAD4 100
726 KEY_5, // VK_NUMPAD5 101
727 KEY_6, // VK_NUMPAD6 102
728 KEY_7, // VK_NUMPAD7 103
729 KEY_8, // VK_NUMPAD8 104
730 KEY_9, // VK_NUMPAD9 105
731 KEY_MULTIPLY, // VK_MULTIPLY 106
732 KEY_ADD, // VK_ADD 107
733 KEY_DECIMAL, // VK_SEPARATOR 108
734 KEY_SUBTRACT, // VK_SUBTRACT 109
735 KEY_DECIMAL, // VK_DECIMAL 110
736 KEY_DIVIDE, // VK_DIVIDE 111
737 KEY_F1, // VK_F1 112
738 KEY_F2, // VK_F2 113
739 KEY_F3, // VK_F3 114
740 KEY_F4, // VK_F4 115
741 KEY_F5, // VK_F5 116
742 KEY_F6, // VK_F6 117
743 KEY_F7, // VK_F7 118
744 KEY_F8, // VK_F8 119
745 KEY_F9, // VK_F9 120
746 KEY_F10, // VK_F10 121
747 KEY_F11, // VK_F11 122
748 KEY_F12, // VK_F12 123
749 KEY_F13, // VK_F13 124
750 KEY_F14, // VK_F14 125
751 KEY_F15, // VK_F15 126
752 KEY_F16, // VK_F16 127
753 KEY_F17, // VK_F17 128
754 KEY_F18, // VK_F18 129
755 KEY_F19, // VK_F19 130
756 KEY_F20, // VK_F20 131
757 KEY_F21, // VK_F21 132
758 KEY_F22, // VK_F22 133
759 KEY_F23, // VK_F23 134
760 KEY_F24, // VK_F24 135
761 0, // 136
762 0, // 137
763 0, // 138
764 0, // 139
765 0, // 140
766 0, // 141
767 0, // 142
768 0, // 143
769 0, // NUMLOCK 144
770 0 // SCROLLLOCK 145
773 // =======================================================================
775 static UINT ImplSalGetWheelScrollLines()
777 UINT nScrLines = 0;
778 HWND hWndMsWheel = WIN_FindWindow( MSH_WHEELMODULE_CLASS, MSH_WHEELMODULE_TITLE );
779 if ( hWndMsWheel )
781 UINT nGetScrollLinesMsgId = RegisterWindowMessage( MSH_SCROLL_LINES );
782 nScrLines = (UINT)ImplSendMessage( hWndMsWheel, nGetScrollLinesMsgId, 0, 0 );
785 if ( !nScrLines )
786 if( !SystemParametersInfo( SPI_GETWHEELSCROLLLINES, 0, &nScrLines, 0 ) )
787 nScrLines = 0 ;
789 if ( !nScrLines )
790 nScrLines = 3;
792 return nScrLines;
795 // -----------------------------------------------------------------------
797 static UINT ImplSalGetWheelScrollChars()
799 UINT nScrChars = 0;
800 if( !SystemParametersInfo( SPI_GETWHEELSCROLLCHARS, 0, &nScrChars, 0 ) )
802 // Depending on Windows version, use proper default or 1 (when
803 // driver emulates hscroll)
804 if( VER_PLATFORM_WIN32_NT == aSalShlData.maVersionInfo.dwPlatformId &&
805 aSalShlData.maVersionInfo.dwMajorVersion < 6 )
807 // Windows 2000 & WinXP : emulating driver, use step size
808 // of 1
809 return 1;
811 else
813 // Longhorn or above: use proper default value of 3
814 return 3;
818 // system settings successfully read
819 return nScrChars;
822 // -----------------------------------------------------------------------
824 static void ImplSalAddBorder( const WinSalFrame* pFrame, int& width, int& height )
826 // transform client size into window size
827 RECT aWinRect;
828 aWinRect.left = 0;
829 aWinRect.right = width-1;
830 aWinRect.top = 0;
831 aWinRect.bottom = height-1;
832 AdjustWindowRectEx( &aWinRect, GetWindowStyle( pFrame->mhWnd ),
833 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
834 width = aWinRect.right - aWinRect.left + 1;
835 height = aWinRect.bottom - aWinRect.top + 1;
838 // -----------------------------------------------------------------------
840 static void ImplSalCalcFullScreenSize( const WinSalFrame* pFrame,
841 int& rX, int& rY, int& rDX, int& rDY )
843 // set window to screen size
844 int nFrameX;
845 int nFrameY;
846 int nCaptionY;
847 int nScreenX = 0;
848 int nScreenY = 0;
849 int nScreenDX = 0;
850 int nScreenDY = 0;
852 if ( pFrame->mbSizeBorder )
854 nFrameX = GetSystemMetrics( SM_CXSIZEFRAME );
855 nFrameY = GetSystemMetrics( SM_CYSIZEFRAME );
857 else if ( pFrame->mbFixBorder )
859 nFrameX = GetSystemMetrics( SM_CXFIXEDFRAME );
860 nFrameY = GetSystemMetrics( SM_CYFIXEDFRAME );
862 else if ( pFrame->mbBorder )
864 nFrameX = GetSystemMetrics( SM_CXBORDER );
865 nFrameY = GetSystemMetrics( SM_CYBORDER );
867 else
869 nFrameX = 0;
870 nFrameY = 0;
872 if ( pFrame->mbCaption )
873 nCaptionY = GetSystemMetrics( SM_CYCAPTION );
874 else
875 nCaptionY = 0;
879 uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
880 uno::Reference< XIndexAccess > xMultiMon( xFactory->createInstance(OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) ) ), UNO_QUERY_THROW );
881 if( (pFrame->mnDisplay >= 0) && (pFrame->mnDisplay < xMultiMon->getCount()) )
883 uno::Reference< XPropertySet > xMonitor( xMultiMon->getByIndex( pFrame->mnDisplay ), UNO_QUERY_THROW );
884 com::sun::star::awt::Rectangle aRect;
885 if( xMonitor->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "ScreenArea" ) ) ) >>= aRect )
887 nScreenX = aRect.X;
888 nScreenY = aRect.Y;
889 nScreenDX = aRect.Width+1; // difference between java/awt convention and vcl
890 nScreenDY = aRect.Height+1; // difference between java/awt convention and vcl
893 else
895 nScreenX = GetSystemMetrics( SM_XVIRTUALSCREEN );
896 nScreenY = GetSystemMetrics( SM_YVIRTUALSCREEN );
897 nScreenDX = GetSystemMetrics( SM_CXVIRTUALSCREEN );
898 nScreenDY = GetSystemMetrics( SM_CYVIRTUALSCREEN );
901 catch( Exception& )
905 if( !nScreenDX || !nScreenDY )
907 nScreenDX = GetSystemMetrics( SM_CXSCREEN );
908 nScreenDY = GetSystemMetrics( SM_CYSCREEN );
911 rX = nScreenX -nFrameX;
912 rY = nScreenY -(nFrameY+nCaptionY);
913 rDX = nScreenDX+(nFrameX*2);
914 rDY = nScreenDY+(nFrameY*2)+nCaptionY;
917 // -----------------------------------------------------------------------
919 static void ImplSalFrameFullScreenPos( WinSalFrame* pFrame, sal_Bool bAlways = FALSE )
921 if ( bAlways || !IsIconic( pFrame->mhWnd ) )
923 // set window to screen size
924 int nX;
925 int nY;
926 int nWidth;
927 int nHeight;
928 ImplSalCalcFullScreenSize( pFrame, nX, nY, nWidth, nHeight );
929 SetWindowPos( pFrame->mhWnd, 0,
930 nX, nY, nWidth, nHeight,
931 SWP_NOZORDER | SWP_NOACTIVATE );
935 // -----------------------------------------------------------------------
937 WinSalFrame::WinSalFrame()
939 SalData* pSalData = GetSalData();
941 mhWnd = 0;
942 mhCursor = LoadCursor( 0, IDC_ARROW );
943 mhDefIMEContext = 0;
944 mpGraphics = NULL;
945 mpGraphics2 = NULL;
946 mnShowState = SW_SHOWNORMAL;
947 mnWidth = 0;
948 mnHeight = 0;
949 mnMinWidth = 0;
950 mnMinHeight = 0;
951 mnMaxWidth = SHRT_MAX;
952 mnMaxHeight = SHRT_MAX;
953 mnInputLang = 0;
954 mnInputCodePage = 0;
955 mbGraphics = FALSE;
956 mbCaption = FALSE;
957 mbBorder = FALSE;
958 mbFixBorder = FALSE;
959 mbSizeBorder = FALSE;
960 mbFullScreen = FALSE;
961 mbPresentation = FALSE;
962 mbInShow = FALSE;
963 mbRestoreMaximize = FALSE;
964 mbInMoveMsg = FALSE;
965 mbInSizeMsg = FALSE;
966 mbFullScreenToolWin = FALSE;
967 mbDefPos = TRUE;
968 mbOverwriteState = TRUE;
969 mbIME = FALSE;
970 mbHandleIME = FALSE;
971 mbSpezIME = FALSE;
972 mbAtCursorIME = FALSE;
973 mbCandidateMode = FALSE;
974 mbFloatWin = FALSE;
975 mbNoIcon = FALSE;
976 mSelectedhMenu = 0;
977 mLastActivatedhMenu = 0;
978 mpClipRgnData = NULL;
979 mbFirstClipRect = TRUE;
980 mpNextClipRect = NULL;
981 mnDisplay = 0;
983 memset( &maState, 0, sizeof( SalFrameState ) );
984 maSysData.nSize = sizeof( SystemEnvData );
986 memset( &maGeometry, 0, sizeof( maGeometry ) );
988 // Daten ermitteln, wenn erster Frame angelegt wird
989 if ( !pSalData->mpFirstFrame )
991 if ( !aSalShlData.mnWheelMsgId )
992 aSalShlData.mnWheelMsgId = RegisterWindowMessage( MSH_MOUSEWHEEL );
993 if ( !aSalShlData.mnWheelScrollLines )
994 aSalShlData.mnWheelScrollLines = ImplSalGetWheelScrollLines();
995 if ( !aSalShlData.mnWheelScrollChars )
996 aSalShlData.mnWheelScrollChars = ImplSalGetWheelScrollChars();
999 // insert frame in framelist
1000 mpNextFrame = pSalData->mpFirstFrame;
1001 pSalData->mpFirstFrame = this;
1004 // -----------------------------------------------------------------------
1005 void WinSalFrame::updateScreenNumber()
1007 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
1008 if( pSys )
1010 const std::vector<WinSalSystem::DisplayMonitor>& rMonitors =
1011 pSys->getMonitors();
1012 Point aPoint( maGeometry.nX, maGeometry.nY );
1013 size_t nMon = rMonitors.size();
1014 for( size_t i = 0; i < nMon; i++ )
1016 if( rMonitors[i].m_aArea.IsInside( aPoint ) )
1018 mnDisplay = static_cast<sal_Int32>(i);
1019 maGeometry.nScreenNumber = static_cast<unsigned int>(i);
1025 // -----------------------------------------------------------------------
1027 WinSalFrame::~WinSalFrame()
1029 SalData* pSalData = GetSalData();
1031 if( mpClipRgnData )
1032 delete [] (BYTE*)mpClipRgnData;
1034 // remove frame from framelist
1035 WinSalFrame** ppFrame = &pSalData->mpFirstFrame;
1036 for(; (*ppFrame != this) && *ppFrame; ppFrame = &(*ppFrame)->mpNextFrame );
1037 if( *ppFrame )
1038 *ppFrame = mpNextFrame;
1039 mpNextFrame = NULL;
1041 // Release Cache DC
1042 if ( mpGraphics2 &&
1043 mpGraphics2->mhDC )
1044 ReleaseGraphics( mpGraphics2 );
1046 // destroy saved DC
1047 if ( mpGraphics )
1049 if ( mpGraphics->mhDefPal )
1050 SelectPalette( mpGraphics->mhDC, mpGraphics->mhDefPal, TRUE );
1051 ImplSalDeInitGraphics( mpGraphics );
1052 ReleaseDC( mhWnd, mpGraphics->mhDC );
1053 delete mpGraphics;
1054 mpGraphics = NULL;
1057 if ( mhWnd )
1059 // reset mouse leave data
1060 if ( pSalData->mhWantLeaveMsg == mhWnd )
1062 pSalData->mhWantLeaveMsg = 0;
1063 if ( pSalData->mpMouseLeaveTimer )
1065 delete pSalData->mpMouseLeaveTimer;
1066 pSalData->mpMouseLeaveTimer = NULL;
1070 // destroy system frame
1071 if ( !DestroyWindow( mhWnd ) )
1072 SetWindowPtr( mhWnd, 0 );
1074 mhWnd = 0;
1078 // -----------------------------------------------------------------------
1080 SalGraphics* WinSalFrame::GetGraphics()
1082 if ( mbGraphics )
1083 return NULL;
1085 // Other threads get an own DC, because Windows modify in the
1086 // other case our DC (changing clip region), when they send a
1087 // WM_ERASEBACKGROUND message
1088 SalData* pSalData = GetSalData();
1089 if ( pSalData->mnAppThreadId != GetCurrentThreadId() )
1091 // We use only three CacheDC's for all threads, because W9x is limited
1092 // to max. 5 Cache DC's per thread
1093 if ( pSalData->mnCacheDCInUse >= 3 )
1094 return NULL;
1096 if ( !mpGraphics2 )
1098 mpGraphics2 = new WinSalGraphics;
1099 mpGraphics2->mhDC = 0;
1100 mpGraphics2->mhWnd = mhWnd;
1101 mpGraphics2->mbPrinter = FALSE;
1102 mpGraphics2->mbVirDev = FALSE;
1103 mpGraphics2->mbWindow = TRUE;
1104 mpGraphics2->mbScreen = TRUE;
1107 HDC hDC = (HDC)ImplSendMessage( pSalData->mpFirstInstance->mhComWnd,
1108 SAL_MSG_GETDC,
1109 (WPARAM)mhWnd, 0 );
1110 if ( hDC )
1112 mpGraphics2->mhDC = hDC;
1113 if ( pSalData->mhDitherPal )
1115 mpGraphics2->mhDefPal = SelectPalette( hDC, pSalData->mhDitherPal, TRUE );
1116 RealizePalette( hDC );
1118 ImplSalInitGraphics( mpGraphics2 );
1119 mbGraphics = TRUE;
1121 pSalData->mnCacheDCInUse++;
1122 return mpGraphics2;
1124 else
1125 return NULL;
1127 else
1129 if ( !mpGraphics )
1131 HDC hDC = GetDC( mhWnd );
1132 if ( hDC )
1134 mpGraphics = new WinSalGraphics;
1135 mpGraphics->mhDC = hDC;
1136 mpGraphics->mhWnd = mhWnd;
1137 mpGraphics->mbPrinter = FALSE;
1138 mpGraphics->mbVirDev = FALSE;
1139 mpGraphics->mbWindow = TRUE;
1140 mpGraphics->mbScreen = TRUE;
1141 if ( pSalData->mhDitherPal )
1143 mpGraphics->mhDefPal = SelectPalette( hDC, pSalData->mhDitherPal, TRUE );
1144 RealizePalette( hDC );
1146 ImplSalInitGraphics( mpGraphics );
1147 mbGraphics = TRUE;
1150 else
1151 mbGraphics = TRUE;
1153 return mpGraphics;
1157 // -----------------------------------------------------------------------
1159 void WinSalFrame::ReleaseGraphics( SalGraphics* pGraphics )
1161 if ( mpGraphics2 == pGraphics )
1163 if ( mpGraphics2->mhDC )
1165 SalData* pSalData = GetSalData();
1166 if ( mpGraphics2->mhDefPal )
1167 SelectPalette( mpGraphics2->mhDC, mpGraphics2->mhDefPal, TRUE );
1168 ImplSalDeInitGraphics( mpGraphics2 );
1169 ImplSendMessage( pSalData->mpFirstInstance->mhComWnd,
1170 SAL_MSG_RELEASEDC,
1171 (WPARAM)mhWnd,
1172 (LPARAM)mpGraphics2->mhDC );
1173 mpGraphics2->mhDC = 0;
1174 pSalData->mnCacheDCInUse--;
1178 mbGraphics = FALSE;
1181 // -----------------------------------------------------------------------
1183 sal_Bool WinSalFrame::PostEvent( void* pData )
1185 return (sal_Bool)ImplPostMessage( mhWnd, SAL_MSG_USEREVENT, 0, (LPARAM)pData );
1188 // -----------------------------------------------------------------------
1190 void WinSalFrame::SetTitle( const XubString& rTitle )
1192 DBG_ASSERT( sizeof( WCHAR ) == sizeof( xub_Unicode ), "WinSalFrame::SetTitle(): WCHAR != sal_Unicode" );
1194 if ( !SetWindowTextW( mhWnd, reinterpret_cast<LPCWSTR>(rTitle.GetBuffer()) ) )
1196 ByteString aAnsiTitle = ImplSalGetWinAnsiString( rTitle );
1197 SetWindowTextA( mhWnd, aAnsiTitle.GetBuffer() );
1201 // -----------------------------------------------------------------------
1203 void WinSalFrame::SetIcon( sal_uInt16 nIcon )
1205 // If we have a window without an Icon (for example a dialog), ignore this call
1206 if ( mbNoIcon )
1207 return;
1209 // 0 means default (class) icon
1210 HICON hIcon = NULL, hSmIcon = NULL;
1211 if ( !nIcon )
1212 nIcon = 1;
1214 ImplLoadSalIcon( nIcon, hIcon, hSmIcon );
1216 DBG_ASSERT( hIcon , "WinSalFrame::SetIcon(): Could not load large icon !" );
1217 DBG_ASSERT( hSmIcon , "WinSalFrame::SetIcon(): Could not load small icon !" );
1219 ImplSendMessage( mhWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon );
1220 ImplSendMessage( mhWnd, WM_SETICON, ICON_SMALL, (LPARAM)hSmIcon );
1223 // -----------------------------------------------------------------------
1225 void WinSalFrame::SetMenu( SalMenu* pSalMenu )
1227 WinSalMenu* pWMenu = static_cast<WinSalMenu*>(pSalMenu);
1228 if( pSalMenu && pWMenu->mbMenuBar )
1229 ::SetMenu( mhWnd, pWMenu->mhMenu );
1232 void WinSalFrame::DrawMenuBar()
1234 ::DrawMenuBar( mhWnd );
1237 // -----------------------------------------------------------------------
1238 HWND ImplGetParentHwnd( HWND hWnd )
1240 WinSalFrame* pFrame = GetWindowPtr( hWnd );
1241 if( !pFrame || !pFrame->GetWindow())
1242 return ::GetParent( hWnd );
1243 Window *pRealParent = pFrame->GetWindow()->ImplGetWindowImpl()->mpRealParent;
1244 if( pRealParent )
1245 return static_cast<WinSalFrame*>(pRealParent->ImplGetWindowImpl()->mpFrame)->mhWnd;
1246 else
1247 return ::GetParent( hWnd );
1251 // -----------------------------------------------------------------------
1253 SalFrame* WinSalFrame::GetParent() const
1255 return GetWindowPtr( ImplGetParentHwnd( mhWnd ) );
1258 // -----------------------------------------------------------------------
1260 static void ImplSalShow( HWND hWnd, sal_Bool bVisible, sal_Bool bNoActivate )
1262 WinSalFrame* pFrame = GetWindowPtr( hWnd );
1263 if ( !pFrame )
1264 return;
1266 if ( bVisible )
1268 pFrame->mbDefPos = FALSE;
1269 pFrame->mbOverwriteState = TRUE;
1270 pFrame->mbInShow = TRUE;
1272 // #i4715, save position
1273 RECT aRectPreMatrox, aRectPostMatrox;
1274 GetWindowRect( hWnd, &aRectPreMatrox );
1276 vcl::DeletionListener aDogTag( pFrame );
1277 if( bNoActivate )
1278 ShowWindow( hWnd, SW_SHOWNOACTIVATE );
1279 else
1280 ShowWindow( hWnd, pFrame->mnShowState );
1281 if( aDogTag.isDeleted() )
1282 return;
1284 if ( aSalShlData.mbWXP && pFrame->mbFloatWin && !(pFrame->mnStyle & SAL_FRAME_STYLE_NOSHADOW))
1286 // erase the window immediately to improve XP shadow effect
1287 // otherwise the shadow may appears long time before the rest of the window
1288 // especially when accessibility is on
1289 HDC dc = GetDC( hWnd );
1290 RECT aRect;
1291 GetClientRect( hWnd, &aRect );
1292 FillRect( dc, &aRect, (HBRUSH) (COLOR_MENU+1) ); // choose the menucolor, because its mostly noticeable for menues
1293 ReleaseDC( hWnd, dc );
1296 // #i4715, matrox centerpopup might have changed our position
1297 // reposition popups without caption (menues, dropdowns, tooltips)
1298 GetWindowRect( hWnd, &aRectPostMatrox );
1299 if( (GetWindowStyle( hWnd ) & WS_POPUP) &&
1300 !pFrame->mbCaption &&
1301 (aRectPreMatrox.left != aRectPostMatrox.left || aRectPreMatrox.top != aRectPostMatrox.top) )
1302 SetWindowPos( hWnd, 0, aRectPreMatrox.left, aRectPreMatrox.top, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE );
1304 if( aDogTag.isDeleted() )
1305 return;
1306 Window *pClientWin = pFrame->GetWindow()->ImplGetClientWindow();
1307 if ( pFrame->mbFloatWin || ( pClientWin && (pClientWin->GetStyle() & WB_SYSTEMFLOATWIN) ) )
1308 pFrame->mnShowState = SW_SHOWNOACTIVATE;
1309 else
1310 pFrame->mnShowState = SW_SHOW;
1311 // Damit Taskleiste unter W98 auch gleich ausgeblendet wird
1312 if ( pFrame->mbPresentation )
1314 HWND hWndParent = ::GetParent( hWnd );
1315 if ( hWndParent )
1316 SetForegroundWindow( hWndParent );
1317 SetForegroundWindow( hWnd );
1320 pFrame->mbInShow = FALSE;
1321 pFrame->updateScreenNumber();
1323 // Direct Paint only, if we get the SolarMutx
1324 if ( ImplSalYieldMutexTryToAcquire() )
1326 UpdateWindow( hWnd );
1327 ImplSalYieldMutexRelease();
1330 else
1332 // See also Bug #91813# and #68467#
1333 if ( pFrame->mbFullScreen &&
1334 pFrame->mbPresentation &&
1335 (aSalShlData.mnVersion < 500) &&
1336 !::GetParent( hWnd ) )
1338 // Damit im Impress-Player in der Taskleiste nicht durch
1339 // einen Windows-Fehler hin- und wieder mal ein leerer
1340 // Button stehen bleibt, muessen wir hier die Taskleiste
1341 // etwas austricksen. Denn wenn wir im FullScreenMode sind
1342 // und das Fenster hiden kommt Windows anscheinend etwas aus
1343 // dem tritt und somit minimieren wir das Fenster damit es
1344 // nicht flackert
1345 ANIMATIONINFO aInfo;
1346 aInfo.cbSize = sizeof( aInfo );
1347 SystemParametersInfo( SPI_GETANIMATION, 0, &aInfo, 0 );
1348 if ( aInfo.iMinAnimate )
1350 int nOldAni = aInfo.iMinAnimate;
1351 aInfo.iMinAnimate = 0;
1352 SystemParametersInfo( SPI_SETANIMATION, 0, &aInfo, 0 );
1353 ShowWindow( pFrame->mhWnd, SW_SHOWMINNOACTIVE );
1354 aInfo.iMinAnimate = nOldAni;
1355 SystemParametersInfo( SPI_SETANIMATION, 0, &aInfo, 0 );
1357 else
1358 ShowWindow( hWnd, SW_SHOWMINNOACTIVE );
1359 ShowWindow( hWnd, SW_HIDE );
1361 else
1362 ShowWindow( hWnd, SW_HIDE );
1366 // -----------------------------------------------------------------------
1369 void WinSalFrame::SetExtendedFrameStyle( SalExtStyle )
1373 // -----------------------------------------------------------------------
1375 void WinSalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
1377 // Post this Message to the window, because this only works
1378 // in the thread of the window, which has create this window.
1379 // We post this message to avoid deadlocks
1380 if ( GetSalData()->mnAppThreadId != GetCurrentThreadId() )
1381 ImplPostMessage( mhWnd, SAL_MSG_SHOW, bVisible, bNoActivate );
1382 else
1383 ImplSalShow( mhWnd, bVisible, bNoActivate );
1386 // -----------------------------------------------------------------------
1388 void WinSalFrame::Enable( sal_Bool bEnable )
1390 EnableWindow( mhWnd, bEnable );
1393 // -----------------------------------------------------------------------
1395 void WinSalFrame::SetMinClientSize( long nWidth, long nHeight )
1397 mnMinWidth = nWidth;
1398 mnMinHeight = nHeight;
1401 void WinSalFrame::SetMaxClientSize( long nWidth, long nHeight )
1403 mnMaxWidth = nWidth;
1404 mnMaxHeight = nHeight;
1407 // -----------------------------------------------------------------------
1409 void WinSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight,
1410 sal_uInt16 nFlags )
1412 sal_Bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
1413 if ( !bVisible )
1415 Window *pClientWin = GetWindow()->ImplGetClientWindow();
1416 if ( mbFloatWin || ( pClientWin && (pClientWin->GetStyle() & WB_SYSTEMFLOATWIN) ) )
1417 mnShowState = SW_SHOWNOACTIVATE;
1418 else
1419 mnShowState = SW_SHOWNORMAL;
1421 else
1423 if ( IsIconic( mhWnd ) || IsZoomed( mhWnd ) )
1424 ShowWindow( mhWnd, SW_RESTORE );
1427 sal_uInt16 nEvent = 0;
1428 UINT nPosSize = 0;
1429 RECT aClientRect, aWindowRect;
1430 GetClientRect( mhWnd, &aClientRect ); // x,y always 0,0, but width and height without border
1431 GetWindowRect( mhWnd, &aWindowRect ); // x,y in screen coordinates, width and height with border
1433 if ( !(nFlags & (SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y)) )
1434 nPosSize |= SWP_NOMOVE;
1435 else
1437 //DBG_ASSERT( nX && nY, " Windowposition of (0,0) requested!" );
1438 nEvent = SALEVENT_MOVE;
1440 if ( !(nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) )
1441 nPosSize |= SWP_NOSIZE;
1442 else
1443 nEvent = (nEvent == SALEVENT_MOVE) ? SALEVENT_MOVERESIZE : SALEVENT_RESIZE;
1445 if ( !(nFlags & SAL_FRAME_POSSIZE_X) )
1446 nX = aWindowRect.left;
1447 if ( !(nFlags & SAL_FRAME_POSSIZE_Y) )
1448 nY = aWindowRect.top;
1449 if ( !(nFlags & SAL_FRAME_POSSIZE_WIDTH) )
1450 nWidth = aClientRect.right-aClientRect.left;
1451 if ( !(nFlags & SAL_FRAME_POSSIZE_HEIGHT) )
1452 nHeight = aClientRect.bottom-aClientRect.top;
1454 // Calculate window size including the border
1455 RECT aWinRect;
1456 aWinRect.left = 0;
1457 aWinRect.right = (int)nWidth-1;
1458 aWinRect.top = 0;
1459 aWinRect.bottom = (int)nHeight-1;
1460 AdjustWindowRectEx( &aWinRect, GetWindowStyle( mhWnd ),
1461 FALSE, GetWindowExStyle( mhWnd ) );
1462 nWidth = aWinRect.right - aWinRect.left + 1;
1463 nHeight = aWinRect.bottom - aWinRect.top + 1;
1465 if ( !(nPosSize & SWP_NOMOVE) && ::GetParent( mhWnd ) )
1467 // --- RTL --- (mirror window pos)
1468 RECT aParentRect;
1469 GetClientRect( ImplGetParentHwnd( mhWnd ), &aParentRect );
1470 if( Application::GetSettings().GetLayoutRTL() )
1471 nX = (aParentRect.right - aParentRect.left) - nWidth-1 - nX;
1473 //#110386#, do not transform coordinates for system child windows
1474 if( !(GetWindowStyle( mhWnd ) & WS_CHILD) )
1476 POINT aPt;
1477 aPt.x = nX;
1478 aPt.y = nY;
1480 HWND parentHwnd = ImplGetParentHwnd( mhWnd );
1481 WinSalFrame* pParentFrame = GetWindowPtr( parentHwnd );
1482 if ( pParentFrame && pParentFrame->mnShowState == SW_SHOWMAXIMIZED )
1484 // #i42485#: parent will be shown maximized in which case
1485 // a ClientToScreen uses the wrong coordinates (i.e. those from the restore pos)
1486 // so use the (already updated) frame geometry for the transformation
1487 aPt.x += pParentFrame->maGeometry.nX;
1488 aPt.y += pParentFrame->maGeometry.nY;
1490 else
1491 ClientToScreen( parentHwnd, &aPt );
1493 nX = aPt.x;
1494 nY = aPt.y;
1498 // #i3338# to be conformant to UNIX we must position the client window, ie without the decoration
1499 // #i43250# if the position was read from the system (GetWindowRect(), see above), it must not be modified
1500 if ( nFlags & SAL_FRAME_POSSIZE_X )
1501 nX += aWinRect.left;
1502 if ( nFlags & SAL_FRAME_POSSIZE_Y )
1503 nY += aWinRect.top;
1505 int nScreenX;
1506 int nScreenY;
1507 int nScreenWidth;
1508 int nScreenHeight;
1511 RECT aRect;
1512 ImplSalGetWorkArea( mhWnd, &aRect, NULL );
1513 nScreenX = aRect.left;
1514 nScreenY = aRect.top;
1515 nScreenWidth = aRect.right-aRect.left;
1516 nScreenHeight = aRect.bottom-aRect.top;
1518 if ( mbDefPos && (nPosSize & SWP_NOMOVE)) // we got no positioning request, so choose default position
1520 // center window
1522 HWND hWndParent = ::GetParent( mhWnd );
1523 // Search for TopLevel Frame
1524 while ( hWndParent && (GetWindowStyle( hWndParent ) & WS_CHILD) )
1525 hWndParent = ::GetParent( hWndParent );
1526 // if the Window has a Parent, than center the window to
1527 // the parent, in the other case to the screen
1528 if ( hWndParent && !IsIconic( hWndParent ) &&
1529 (GetWindowStyle( hWndParent ) & WS_VISIBLE) )
1531 RECT aParentRect;
1532 GetWindowRect( hWndParent, &aParentRect );
1533 int nParentWidth = aParentRect.right-aParentRect.left;
1534 int nParentHeight = aParentRect.bottom-aParentRect.top;
1536 // We don't center, when Parent is smaller than our window
1537 if ( (nParentWidth-GetSystemMetrics( SM_CXFIXEDFRAME ) <= nWidth) &&
1538 (nParentHeight-GetSystemMetrics( SM_CYFIXEDFRAME ) <= nHeight) )
1540 int nOff = GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION );
1541 nX = aParentRect.left+nOff;
1542 nY = aParentRect.top+nOff;
1544 else
1546 nX = (nParentWidth-nWidth)/2 + aParentRect.left;
1547 nY = (nParentHeight-nHeight)/2 + aParentRect.top;
1550 else
1552 POINT pt;
1553 GetCursorPos( &pt );
1554 RECT aRect;
1555 aRect.left = pt.x;
1556 aRect.top = pt.y;
1557 aRect.right = pt.x+2;
1558 aRect.bottom = pt.y+2;
1560 // dualmonitor support:
1561 // Get screensize of the monitor whith the mouse pointer
1562 ImplSalGetWorkArea( mhWnd, &aRect, &aRect );
1564 nX = ((aRect.right-aRect.left)-nWidth)/2 + aRect.left;
1565 nY = ((aRect.bottom-aRect.top)-nHeight)/2 + aRect.top;
1569 //if ( bVisible )
1570 // mbDefPos = FALSE;
1572 mbDefPos = FALSE; // center only once
1573 nPosSize &= ~SWP_NOMOVE; // activate positioning
1574 nEvent = SALEVENT_MOVERESIZE;
1578 // Adjust Window in the screen
1579 sal_Bool bCheckOffScreen = TRUE;
1581 // but don't do this for floaters or ownerdraw windows that are currently moved interactively
1582 if( (mnStyle & SAL_FRAME_STYLE_FLOAT) && !(mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
1583 bCheckOffScreen = FALSE;
1585 if( mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION )
1587 // may be the window is currently being moved (mouse is captured), then no check is required
1588 if( mhWnd == ::GetCapture() )
1589 bCheckOffScreen = FALSE;
1590 else
1591 bCheckOffScreen = TRUE;
1594 if( bCheckOffScreen )
1596 if ( nX+nWidth > nScreenX+nScreenWidth )
1597 nX = (nScreenX+nScreenWidth) - nWidth;
1598 if ( nY+nHeight > nScreenY+nScreenHeight )
1599 nY = (nScreenY+nScreenHeight) - nHeight;
1600 if ( nX < nScreenX )
1601 nX = nScreenX;
1602 if ( nY < nScreenY )
1603 nY = nScreenY;
1606 UINT nPosFlags = SWP_NOACTIVATE | SWP_NOOWNERZORDER | nPosSize;
1607 // bring floating windows always to top
1608 if( !(mnStyle & SAL_FRAME_STYLE_FLOAT) )
1609 nPosFlags |= SWP_NOZORDER; // do not change z-order
1611 SetWindowPos( mhWnd, HWND_TOP, nX, nY, (int)nWidth, (int)nHeight, nPosFlags );
1613 UpdateFrameGeometry( mhWnd, this );
1615 // Notification -- really ???
1616 if( nEvent )
1617 CallCallback( nEvent, NULL );
1620 // -----------------------------------------------------------------------
1622 static void ImplSetParentFrame( WinSalFrame* pThis, HWND hNewParentWnd, sal_Bool bAsChild )
1624 // save hwnd, will be overwritten in WM_CREATE during createwindow
1625 HWND hWndOld = pThis->mhWnd;
1626 HWND hWndOldParent = ::GetParent( hWndOld );
1627 SalData* pSalData = GetSalData();
1629 if( hNewParentWnd == hWndOldParent )
1630 return;
1632 ::std::vector< WinSalFrame* > children;
1633 ::std::vector< WinSalObject* > systemChildren;
1635 // search child windows
1636 WinSalFrame *pFrame = pSalData->mpFirstFrame;
1637 while( pFrame )
1639 HWND hWndParent = ::GetParent( pFrame->mhWnd );
1640 if( pThis->mhWnd == hWndParent )
1641 children.push_back( pFrame );
1642 pFrame = pFrame->mpNextFrame;
1645 // search system child windows (plugins etc.)
1646 WinSalObject *pObject = pSalData->mpFirstObject;
1647 while( pObject )
1649 HWND hWndParent = ::GetParent( pObject->mhWnd );
1650 if( pThis->mhWnd == hWndParent )
1651 systemChildren.push_back( pObject );
1652 pObject = pObject->mpNextObject;
1655 sal_Bool bNeedGraphics = pThis->mbGraphics;
1656 sal_Bool bNeedCacheDC = FALSE;
1658 HFONT hFont = NULL;
1659 HPEN hPen = NULL;
1660 HBRUSH hBrush = NULL;
1662 #if OSL_DEBUG_LEVEL > 0
1663 int oldCount = pSalData->mnCacheDCInUse;
1664 (void)oldCount;
1665 #endif
1667 // Release Cache DC
1668 if ( pThis->mpGraphics2 &&
1669 pThis->mpGraphics2->mhDC )
1671 // save current gdi objects before hdc is gone
1672 hFont = (HFONT) GetCurrentObject( pThis->mpGraphics2->mhDC, OBJ_FONT);
1673 hPen = (HPEN) GetCurrentObject( pThis->mpGraphics2->mhDC, OBJ_PEN);
1674 hBrush = (HBRUSH) GetCurrentObject( pThis->mpGraphics2->mhDC, OBJ_BRUSH);
1675 pThis->ReleaseGraphics( pThis->mpGraphics2 );
1677 // recreate cache dc only if it was destroyed
1678 bNeedCacheDC = TRUE;
1681 // destroy saved DC
1682 if ( pThis->mpGraphics )
1684 if ( pThis->mpGraphics->mhDefPal )
1685 SelectPalette( pThis->mpGraphics->mhDC, pThis->mpGraphics->mhDefPal, TRUE );
1686 ImplSalDeInitGraphics( pThis->mpGraphics );
1687 ReleaseDC( pThis->mhWnd, pThis->mpGraphics->mhDC );
1690 // create a new hwnd with the same styles
1691 HWND hWndParent = hNewParentWnd;
1692 // forward to main thread
1693 HWND hWnd = (HWND) ImplSendMessage( pSalData->mpFirstInstance->mhComWnd,
1694 bAsChild ? SAL_MSG_RECREATECHILDHWND : SAL_MSG_RECREATEHWND,
1695 (WPARAM) hWndParent, (LPARAM)pThis->mhWnd );
1697 // succeeded ?
1698 DBG_ASSERT( IsWindow( hWnd ), "WinSalFrame::SetParent not successful");
1700 // recreate DCs
1701 if( bNeedGraphics )
1703 if( pThis->mpGraphics2 )
1705 pThis->mpGraphics2->mhWnd = hWnd;
1707 if( bNeedCacheDC )
1709 // re-create cached DC
1710 HDC hDC = (HDC)ImplSendMessage( pSalData->mpFirstInstance->mhComWnd,
1711 SAL_MSG_GETDC,
1712 (WPARAM) hWnd, 0 );
1713 if ( hDC )
1715 pThis->mpGraphics2->mhDC = hDC;
1716 if ( pSalData->mhDitherPal )
1718 pThis->mpGraphics2->mhDefPal = SelectPalette( hDC, pSalData->mhDitherPal, TRUE );
1719 RealizePalette( hDC );
1721 ImplSalInitGraphics( pThis->mpGraphics2 );
1723 // re-select saved gdi objects
1724 if( hFont )
1725 SelectObject( hDC, hFont );
1726 if( hPen )
1727 SelectObject( hDC, hPen );
1728 if( hBrush )
1729 SelectObject( hDC, hBrush );
1731 pThis->mbGraphics = TRUE;
1733 pSalData->mnCacheDCInUse++;
1735 DBG_ASSERT( oldCount == pSalData->mnCacheDCInUse, "WinSalFrame::SetParent() hDC count corrupted");
1740 if( pThis->mpGraphics )
1742 // re-create DC
1743 pThis->mpGraphics->mhWnd = hWnd;
1744 pThis->mpGraphics->mhDC = GetDC( hWnd );
1745 if ( GetSalData()->mhDitherPal )
1747 pThis->mpGraphics->mhDefPal = SelectPalette( pThis->mpGraphics->mhDC, GetSalData()->mhDitherPal, TRUE );
1748 RealizePalette( pThis->mpGraphics->mhDC );
1750 ImplSalInitGraphics( pThis->mpGraphics );
1751 pThis->mbGraphics = TRUE;
1756 // TODO: add SetParent() call for SalObjects
1757 DBG_ASSERT( systemChildren.empty(), "WinSalFrame::SetParent() parent of living system child window will be destroyed!");
1759 // reparent children before old parent is destroyed
1760 for( ::std::vector< WinSalFrame* >::iterator iChild = children.begin(); iChild != children.end(); iChild++ )
1761 ImplSetParentFrame( *iChild, hWnd, FALSE );
1763 children.clear();
1764 systemChildren.clear();
1766 // Now destroy original HWND in the thread where it was created.
1767 ImplSendMessage( GetSalData()->mpFirstInstance->mhComWnd,
1768 SAL_MSG_DESTROYHWND, (WPARAM) 0, (LPARAM)hWndOld);
1771 // -----------------------------------------------------------------------
1773 void WinSalFrame::SetParent( SalFrame* pNewParent )
1775 WinSalFrame::mbInReparent = TRUE;
1776 ImplSetParentFrame( this, static_cast<WinSalFrame*>(pNewParent)->mhWnd, FALSE );
1777 WinSalFrame::mbInReparent = FALSE;
1780 bool WinSalFrame::SetPluginParent( SystemParentData* pNewParent )
1782 if ( pNewParent->hWnd == 0 )
1784 pNewParent->hWnd = GetDesktopWindow();
1787 WinSalFrame::mbInReparent = TRUE;
1788 ImplSetParentFrame( this, pNewParent->hWnd, TRUE );
1789 WinSalFrame::mbInReparent = FALSE;
1790 return true;
1794 // -----------------------------------------------------------------------
1796 void WinSalFrame::GetWorkArea( Rectangle &rRect )
1798 RECT aRect;
1799 ImplSalGetWorkArea( mhWnd, &aRect, NULL );
1800 rRect.nLeft = aRect.left;
1801 rRect.nRight = aRect.right-1;
1802 rRect.nTop = aRect.top;
1803 rRect.nBottom = aRect.bottom-1;
1806 // -----------------------------------------------------------------------
1808 void WinSalFrame::GetClientSize( long& rWidth, long& rHeight )
1810 rWidth = maGeometry.nWidth;
1811 rHeight = maGeometry.nHeight;
1814 // -----------------------------------------------------------------------
1816 void WinSalFrame::SetWindowState( const SalFrameState* pState )
1818 // Wir testen, ob das Fenster ueberhaupt auf den Bildschirm passt, damit
1819 // nicht wenn die Bildschirm-Aufloesung geaendert wurde, das Fenster aus
1820 // diesem herausragt
1821 int nX;
1822 int nY;
1823 int nWidth;
1824 int nHeight;
1825 int nScreenX;
1826 int nScreenY;
1827 int nScreenWidth;
1828 int nScreenHeight;
1830 RECT aRect;
1831 ImplSalGetWorkArea( mhWnd, &aRect, NULL );
1832 // #102500# allow some overlap, the window could have been made a little larger than the physical screen
1833 nScreenX = aRect.left-10;
1834 nScreenY = aRect.top-10;
1835 nScreenWidth = aRect.right-aRect.left+20;
1836 nScreenHeight = aRect.bottom-aRect.top+20;
1838 UINT nPosSize = 0;
1839 RECT aWinRect;
1840 GetWindowRect( mhWnd, &aWinRect );
1842 // to be consistent with Unix, the frame state is without(!) decoration
1843 // ->add the decoration
1844 RECT aRect2 = aWinRect;
1845 AdjustWindowRectEx( &aRect2, GetWindowStyle( mhWnd ),
1846 FALSE, GetWindowExStyle( mhWnd ) );
1847 long nTopDeco = abs( aWinRect.top - aRect2.top );
1848 long nLeftDeco = abs( aWinRect.left - aRect2.left );
1849 long nBottomDeco = abs( aWinRect.bottom - aRect2.bottom );
1850 long nRightDeco = abs( aWinRect.right - aRect2.right );
1852 // Fenster-Position/Groesse in den Bildschirm einpassen
1853 if ( !(pState->mnMask & (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_Y)) )
1854 nPosSize |= SWP_NOMOVE;
1855 if ( !(pState->mnMask & (SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT)) )
1856 nPosSize |= SWP_NOSIZE;
1857 if ( pState->mnMask & SAL_FRAMESTATE_MASK_X )
1858 nX = (int)pState->mnX - nLeftDeco;
1859 else
1860 nX = aWinRect.left;
1861 if ( pState->mnMask & SAL_FRAMESTATE_MASK_Y )
1862 nY = (int)pState->mnY - nTopDeco;
1863 else
1864 nY = aWinRect.top;
1865 if ( pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH )
1866 nWidth = (int)pState->mnWidth + nLeftDeco + nRightDeco;
1867 else
1868 nWidth = aWinRect.right-aWinRect.left;
1869 if ( pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT )
1870 nHeight = (int)pState->mnHeight + nTopDeco + nBottomDeco;
1871 else
1872 nHeight = aWinRect.bottom-aWinRect.top;
1874 // Adjust Window in the screen:
1875 // if it does not fit into the screen do nothing, ie default pos/size will be used
1876 // if there is an overlap with the screen border move the window while keeping its size
1878 if( nWidth > nScreenWidth || nHeight > nScreenHeight )
1879 nPosSize |= (SWP_NOMOVE | SWP_NOSIZE);
1881 if ( nX+nWidth > nScreenX+nScreenWidth )
1882 nX = (nScreenX+nScreenWidth) - nWidth;
1883 if ( nY+nHeight > nScreenY+nScreenHeight )
1884 nY = (nScreenY+nScreenHeight) - nHeight;
1885 if ( nX < nScreenX )
1886 nX = nScreenX;
1887 if ( nY < nScreenY )
1888 nY = nScreenY;
1890 // Restore-Position setzen
1891 WINDOWPLACEMENT aPlacement;
1892 aPlacement.length = sizeof( aPlacement );
1893 GetWindowPlacement( mhWnd, &aPlacement );
1895 // Status setzen
1896 sal_Bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
1897 sal_Bool bUpdateHiddenFramePos = FALSE;
1898 if ( !bVisible )
1900 aPlacement.showCmd = SW_HIDE;
1902 if ( mbOverwriteState )
1904 if ( pState->mnMask & SAL_FRAMESTATE_MASK_STATE )
1906 if ( pState->mnState & SAL_FRAMESTATE_MINIMIZED )
1907 mnShowState = SW_SHOWMINIMIZED;
1908 else if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1910 mnShowState = SW_SHOWMAXIMIZED;
1911 bUpdateHiddenFramePos = TRUE;
1913 else if ( pState->mnState & SAL_FRAMESTATE_NORMAL )
1914 mnShowState = SW_SHOWNORMAL;
1918 else
1920 if ( pState->mnMask & SAL_FRAMESTATE_MASK_STATE )
1922 if ( pState->mnState & SAL_FRAMESTATE_MINIMIZED )
1924 if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1925 aPlacement.flags |= WPF_RESTORETOMAXIMIZED;
1926 aPlacement.showCmd = SW_SHOWMINIMIZED;
1928 else if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1929 aPlacement.showCmd = SW_SHOWMAXIMIZED;
1930 else if ( pState->mnState & SAL_FRAMESTATE_NORMAL )
1931 aPlacement.showCmd = SW_RESTORE;
1935 // if a window is neither minimized nor maximized or need not be
1936 // positioned visibly (that is in visible state), do not use
1937 // SetWindowPlacement since it calculates including the TaskBar
1938 if ( !IsIconic( mhWnd ) && !IsZoomed( mhWnd ) &&
1939 (!bVisible || (aPlacement.showCmd == SW_RESTORE)) )
1941 if( bUpdateHiddenFramePos )
1943 RECT aStateRect;
1944 aStateRect.left = nX;
1945 aStateRect.top = nY;
1946 aStateRect.right = nX+nWidth;
1947 aStateRect.bottom = nY+nHeight;
1948 // #96084 set a useful internal window size because
1949 // the window will not be maximized (and the size updated) before show()
1950 SetMaximizedFrameGeometry( mhWnd, this, &aStateRect );
1951 SetWindowPos( mhWnd, 0,
1952 maGeometry.nX, maGeometry.nY, maGeometry.nWidth, maGeometry.nHeight,
1953 SWP_NOZORDER | SWP_NOACTIVATE | nPosSize );
1955 else
1956 SetWindowPos( mhWnd, 0,
1957 nX, nY, nWidth, nHeight,
1958 SWP_NOZORDER | SWP_NOACTIVATE | nPosSize );
1960 else
1962 if( !(nPosSize & (SWP_NOMOVE|SWP_NOSIZE)) )
1964 aPlacement.rcNormalPosition.left = nX-nScreenX;
1965 aPlacement.rcNormalPosition.top = nY-nScreenY;
1966 aPlacement.rcNormalPosition.right = nX+nWidth-nScreenX;
1967 aPlacement.rcNormalPosition.bottom = nY+nHeight-nScreenY;
1969 SetWindowPlacement( mhWnd, &aPlacement );
1972 if( !(nPosSize & SWP_NOMOVE) )
1973 mbDefPos = FALSE; // window was positioned
1976 // -----------------------------------------------------------------------
1978 sal_Bool WinSalFrame::GetWindowState( SalFrameState* pState )
1980 if ( maState.mnWidth && maState.mnHeight )
1982 *pState = maState;
1983 // #94144# allow Minimize again, should be masked out when read from configuration
1984 // 91625 - Don't save minimize
1985 //if ( !(pState->mnState & SAL_FRAMESTATE_MAXIMIZED) )
1986 if ( !(pState->mnState & (SAL_FRAMESTATE_MINIMIZED | SAL_FRAMESTATE_MAXIMIZED)) )
1987 pState->mnState |= SAL_FRAMESTATE_NORMAL;
1988 return TRUE;
1991 return FALSE;
1994 // -----------------------------------------------------------------------
1996 void WinSalFrame::SetScreenNumber( unsigned int nNewScreen )
1998 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
1999 if( pSys )
2001 const std::vector<WinSalSystem::DisplayMonitor>& rMonitors =
2002 pSys->getMonitors();
2003 size_t nMon = rMonitors.size();
2004 if( nNewScreen < nMon )
2006 Point aOldMonPos, aNewMonPos( rMonitors[nNewScreen].m_aArea.TopLeft() );
2007 Point aCurPos( maGeometry.nX, maGeometry.nY );
2008 for( size_t i = 0; i < nMon; i++ )
2010 if( rMonitors[i].m_aArea.IsInside( aCurPos ) )
2012 aOldMonPos = rMonitors[i].m_aArea.TopLeft();
2013 break;
2016 mnDisplay = nNewScreen;
2017 maGeometry.nScreenNumber = nNewScreen;
2018 SetPosSize( aNewMonPos.X() + (maGeometry.nX - aOldMonPos.X()),
2019 aNewMonPos.Y() + (maGeometry.nY - aOldMonPos.Y()),
2020 0, 0,
2021 SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y );
2026 // -----------------------------------------------------------------------
2028 void WinSalFrame::ShowFullScreen( sal_Bool bFullScreen, sal_Int32 nDisplay )
2030 if ( (mbFullScreen == bFullScreen) && (!bFullScreen || (mnDisplay == nDisplay)) )
2031 return;
2033 mbFullScreen = bFullScreen;
2034 mnDisplay = nDisplay;
2036 if ( bFullScreen )
2038 // Damit Taskleiste von Windows ausgeblendet wird
2039 DWORD nExStyle = GetWindowExStyle( mhWnd );
2040 if ( nExStyle & WS_EX_TOOLWINDOW )
2042 mbFullScreenToolWin = TRUE;
2043 nExStyle &= ~WS_EX_TOOLWINDOW;
2044 SetWindowExStyle( mhWnd, nExStyle );
2046 // save old position
2047 GetWindowRect( mhWnd, &maFullScreenRect );
2049 // save show state
2050 mnFullScreenShowState = mnShowState;
2051 if ( !(GetWindowStyle( mhWnd ) & WS_VISIBLE) )
2052 mnShowState = SW_SHOW;
2054 // set window to screen size
2055 ImplSalFrameFullScreenPos( this, TRUE );
2057 else
2059 // wenn ShowState wieder hergestellt werden muss, hiden wir zuerst
2060 // das Fenster, damit es nicht so sehr flackert
2061 sal_Bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
2062 if ( bVisible && (mnShowState != mnFullScreenShowState) )
2063 ShowWindow( mhWnd, SW_HIDE );
2065 if ( mbFullScreenToolWin )
2066 SetWindowExStyle( mhWnd, GetWindowExStyle( mhWnd ) | WS_EX_TOOLWINDOW );
2067 mbFullScreenToolWin = FALSE;
2069 SetWindowPos( mhWnd, 0,
2070 maFullScreenRect.left,
2071 maFullScreenRect.top,
2072 maFullScreenRect.right-maFullScreenRect.left,
2073 maFullScreenRect.bottom-maFullScreenRect.top,
2074 SWP_NOZORDER | SWP_NOACTIVATE );
2076 // restore show state
2077 if ( mnShowState != mnFullScreenShowState )
2079 mnShowState = mnFullScreenShowState;
2080 if ( bVisible )
2082 mbInShow = TRUE;
2083 ShowWindow( mhWnd, mnShowState );
2084 mbInShow = FALSE;
2085 UpdateWindow( mhWnd );
2091 // -----------------------------------------------------------------------
2093 void WinSalFrame::StartPresentation( sal_Bool bStart )
2095 if ( mbPresentation == bStart )
2096 return;
2098 mbPresentation = bStart;
2100 SalData* pSalData = GetSalData();
2101 if ( bStart )
2103 if ( !pSalData->mpSageEnableProc )
2105 if ( pSalData->mnSageStatus != DISABLE_AGENT )
2107 OFSTRUCT aOS;
2108 OpenFile( "SAGE.DLL", &aOS, OF_EXIST );
2110 if ( !aOS.nErrCode )
2112 OUString aLibraryName( OUString::createFromAscii( aOS.szPathName ) );
2113 oslModule mhSageInst = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT );
2114 pSalData->mpSageEnableProc = (SysAgt_Enable_PROC)osl_getAsciiFunctionSymbol( mhSageInst, "System_Agent_Enable" );
2116 else
2117 pSalData->mnSageStatus = DISABLE_AGENT;
2121 if ( pSalData->mpSageEnableProc )
2123 pSalData->mnSageStatus = pSalData->mpSageEnableProc( GET_AGENT_STATUS );
2124 if ( pSalData->mnSageStatus == ENABLE_AGENT )
2125 pSalData->mpSageEnableProc( DISABLE_AGENT );
2128 // Bildschirmschoner ausschalten, wenn Praesentation laueft
2129 SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 0,
2130 &(pSalData->mbScrSvrEnabled), 0 );
2131 if ( pSalData->mbScrSvrEnabled )
2132 SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, FALSE, 0, 0 );
2134 else
2136 // Bildschirmschoner wieder einschalten
2137 if ( pSalData->mbScrSvrEnabled )
2138 SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, pSalData->mbScrSvrEnabled, 0, 0 );
2140 // Systemagenten wieder aktivieren
2141 if ( pSalData->mnSageStatus == ENABLE_AGENT )
2142 pSalData->mpSageEnableProc( pSalData->mnSageStatus );
2146 // -----------------------------------------------------------------------
2148 void WinSalFrame::SetAlwaysOnTop( sal_Bool bOnTop )
2150 HWND hWnd;
2151 if ( bOnTop )
2152 hWnd = HWND_TOPMOST;
2153 else
2154 hWnd = HWND_NOTOPMOST;
2155 SetWindowPos( mhWnd, hWnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
2158 // -----------------------------------------------------------------------
2160 static void ImplSalToTop( HWND hWnd, sal_uInt16 nFlags )
2162 WinSalFrame* pToTopFrame = GetWindowPtr( hWnd );
2163 if( pToTopFrame && (pToTopFrame->mnStyle & SAL_FRAME_STYLE_SYSTEMCHILD) != 0 )
2164 BringWindowToTop( hWnd );
2166 if ( nFlags & SAL_FRAME_TOTOP_FOREGROUNDTASK )
2168 // This magic code is necessary to connect the input focus of the
2169 // current window thread and the thread which owns the window that
2170 // should be the new foreground window.
2171 HWND hCurrWnd = GetForegroundWindow();
2172 DWORD myThreadID = GetCurrentThreadId();
2173 DWORD currThreadID = GetWindowThreadProcessId(hCurrWnd,NULL);
2174 AttachThreadInput(myThreadID, currThreadID,TRUE);
2175 SetForegroundWindow(hWnd);
2176 AttachThreadInput(myThreadID,currThreadID,FALSE);
2179 if ( nFlags & SAL_FRAME_TOTOP_RESTOREWHENMIN )
2181 HWND hIconicWnd = hWnd;
2182 while ( hIconicWnd )
2184 if ( IsIconic( hIconicWnd ) )
2186 WinSalFrame* pFrame = GetWindowPtr( hIconicWnd );
2187 if ( pFrame )
2189 if ( GetWindowPtr( hWnd )->mbRestoreMaximize )
2190 ShowWindow( hIconicWnd, SW_MAXIMIZE );
2191 else
2192 ShowWindow( hIconicWnd, SW_RESTORE );
2194 else
2195 ShowWindow( hIconicWnd, SW_RESTORE );
2198 hIconicWnd = ::GetParent( hIconicWnd );
2202 if ( !IsIconic( hWnd ) && IsWindowVisible( hWnd ) )
2204 SetFocus( hWnd );
2206 // Windows behauptet oefters mal, das man den Focus hat, obwohl
2207 // man diesen nicht hat. Wenn dies der Fall ist, dann versuchen
2208 // wir diesen auch ganz richtig zu bekommen.
2209 if ( ::GetFocus() == hWnd )
2210 SetForegroundWindow( hWnd );
2214 // -----------------------------------------------------------------------
2216 void WinSalFrame::ToTop( sal_uInt16 nFlags )
2218 nFlags &= ~SAL_FRAME_TOTOP_GRABFOCUS; // this flag is not needed on win32
2219 // Post this Message to the window, because this only works
2220 // in the thread of the window, which has create this window.
2221 // We post this message to avoid deadlocks
2222 if ( GetSalData()->mnAppThreadId != GetCurrentThreadId() )
2223 ImplPostMessage( mhWnd, SAL_MSG_TOTOP, nFlags, 0 );
2224 else
2225 ImplSalToTop( mhWnd, nFlags );
2228 // -----------------------------------------------------------------------
2230 void WinSalFrame::SetPointer( PointerStyle ePointerStyle )
2232 struct ImplPtrData
2234 HCURSOR mhCursor;
2235 LPCSTR mnSysId;
2236 UINT mnOwnId;
2239 static ImplPtrData aImplPtrTab[POINTER_COUNT] =
2241 { 0, IDC_ARROW, 0 }, // POINTER_ARROW
2242 { 0, 0, SAL_RESID_POINTER_NULL }, // POINTER_NULL
2243 { 0, IDC_WAIT, 0 }, // POINTER_WAIT
2244 { 0, IDC_IBEAM, 0 }, // POINTER_TEXT
2245 { 0, IDC_HELP, 0 }, // POINTER_HELP
2246 { 0, 0, SAL_RESID_POINTER_CROSS }, // POINTER_CROSS
2247 { 0, 0, SAL_RESID_POINTER_MOVE }, // POINTER_MOVE
2248 { 0, IDC_SIZENS, 0 }, // POINTER_NSIZE
2249 { 0, IDC_SIZENS, 0 }, // POINTER_SSIZE
2250 { 0, IDC_SIZEWE, 0 }, // POINTER_WSIZE
2251 { 0, IDC_SIZEWE, 0 }, // POINTER_ESIZE
2252 { 0, IDC_SIZENWSE, 0 }, // POINTER_NWSIZE
2253 { 0, IDC_SIZENESW, 0 }, // POINTER_NESIZE
2254 { 0, IDC_SIZENESW, 0 }, // POINTER_SWSIZE
2255 { 0, IDC_SIZENWSE, 0 }, // POINTER_SESIZE
2256 { 0, IDC_SIZENS, 0 }, // POINTER_WINDOW_NSIZE
2257 { 0, IDC_SIZENS, 0 }, // POINTER_WINDOW_SSIZE
2258 { 0, IDC_SIZEWE, 0 }, // POINTER_WINDOW_WSIZE
2259 { 0, IDC_SIZEWE, 0 }, // POINTER_WINDOW_ESIZE
2260 { 0, IDC_SIZENWSE, 0 }, // POINTER_WINDOW_NWSIZE
2261 { 0, IDC_SIZENESW, 0 }, // POINTER_WINDOW_NESIZE
2262 { 0, IDC_SIZENESW, 0 }, // POINTER_WINDOW_SWSIZE
2263 { 0, IDC_SIZENWSE, 0 }, // POINTER_WINDOW_SESIZE
2264 { 0, 0, SAL_RESID_POINTER_HSPLIT }, // POINTER_HSPLIT
2265 { 0, 0, SAL_RESID_POINTER_VSPLIT }, // POINTER_VSPLIT
2266 { 0, 0, SAL_RESID_POINTER_HSIZEBAR }, // POINTER_HSIZEBAR
2267 { 0, 0, SAL_RESID_POINTER_VSIZEBAR }, // POINTER_VSIZEBAR
2268 { 0, 0, SAL_RESID_POINTER_HAND }, // POINTER_HAND
2269 { 0, 0, SAL_RESID_POINTER_REFHAND }, // POINTER_REFHAND
2270 { 0, 0, SAL_RESID_POINTER_PEN }, // POINTER_PEN
2271 { 0, 0, SAL_RESID_POINTER_MAGNIFY }, // POINTER_MAGNIFY
2272 { 0, 0, SAL_RESID_POINTER_FILL }, // POINTER_FILL
2273 { 0, 0, SAL_RESID_POINTER_ROTATE }, // POINTER_ROTATE
2274 { 0, 0, SAL_RESID_POINTER_HSHEAR }, // POINTER_HSHEAR
2275 { 0, 0, SAL_RESID_POINTER_VSHEAR }, // POINTER_VSHEAR
2276 { 0, 0, SAL_RESID_POINTER_MIRROR }, // POINTER_MIRROR
2277 { 0, 0, SAL_RESID_POINTER_CROOK }, // POINTER_CROOK
2278 { 0, 0, SAL_RESID_POINTER_CROP }, // POINTER_CROP
2279 { 0, 0, SAL_RESID_POINTER_MOVEPOINT }, // POINTER_MOVEPOINT
2280 { 0, 0, SAL_RESID_POINTER_MOVEBEZIERWEIGHT }, // POINTER_MOVEBEZIERWEIGHT
2281 { 0, 0, SAL_RESID_POINTER_MOVEDATA }, // POINTER_MOVEDATA
2282 { 0, 0, SAL_RESID_POINTER_COPYDATA }, // POINTER_COPYDATA
2283 { 0, 0, SAL_RESID_POINTER_LINKDATA }, // POINTER_LINKDATA
2284 { 0, 0, SAL_RESID_POINTER_MOVEDATALINK }, // POINTER_MOVEDATALINK
2285 { 0, 0, SAL_RESID_POINTER_COPYDATALINK }, // POINTER_COPYDATALINK
2286 { 0, 0, SAL_RESID_POINTER_MOVEFILE }, // POINTER_MOVEFILE
2287 { 0, 0, SAL_RESID_POINTER_COPYFILE }, // POINTER_COPYFILE
2288 { 0, 0, SAL_RESID_POINTER_LINKFILE }, // POINTER_LINKFILE
2289 { 0, 0, SAL_RESID_POINTER_MOVEFILELINK }, // POINTER_MOVEFILELINK
2290 { 0, 0, SAL_RESID_POINTER_COPYFILELINK }, // POINTER_COPYFILELINK
2291 { 0, 0, SAL_RESID_POINTER_MOVEFILES }, // POINTER_MOVEFILES
2292 { 0, 0, SAL_RESID_POINTER_COPYFILES }, // POINTER_COPYFILES
2293 { 0, 0, SAL_RESID_POINTER_NOTALLOWED }, // POINTER_NOTALLOWED
2294 { 0, 0, SAL_RESID_POINTER_DRAW_LINE }, // POINTER_DRAW_LINE
2295 { 0, 0, SAL_RESID_POINTER_DRAW_RECT }, // POINTER_DRAW_RECT
2296 { 0, 0, SAL_RESID_POINTER_DRAW_POLYGON }, // POINTER_DRAW_POLYGON
2297 { 0, 0, SAL_RESID_POINTER_DRAW_BEZIER }, // POINTER_DRAW_BEZIER
2298 { 0, 0, SAL_RESID_POINTER_DRAW_ARC }, // POINTER_DRAW_ARC
2299 { 0, 0, SAL_RESID_POINTER_DRAW_PIE }, // POINTER_DRAW_PIE
2300 { 0, 0, SAL_RESID_POINTER_DRAW_CIRCLECUT }, // POINTER_DRAW_CIRCLECUT
2301 { 0, 0, SAL_RESID_POINTER_DRAW_ELLIPSE }, // POINTER_DRAW_ELLIPSE
2302 { 0, 0, SAL_RESID_POINTER_DRAW_FREEHAND }, // POINTER_DRAW_FREEHAND
2303 { 0, 0, SAL_RESID_POINTER_DRAW_CONNECT }, // POINTER_DRAW_CONNECT
2304 { 0, 0, SAL_RESID_POINTER_DRAW_TEXT }, // POINTER_DRAW_TEXT
2305 { 0, 0, SAL_RESID_POINTER_DRAW_CAPTION }, // POINTER_DRAW_CAPTION
2306 { 0, 0, SAL_RESID_POINTER_CHART }, // POINTER_CHART
2307 { 0, 0, SAL_RESID_POINTER_DETECTIVE }, // POINTER_DETECTIVE
2308 { 0, 0, SAL_RESID_POINTER_PIVOT_COL }, // POINTER_PIVOT_COL
2309 { 0, 0, SAL_RESID_POINTER_PIVOT_ROW }, // POINTER_PIVOT_ROW
2310 { 0, 0, SAL_RESID_POINTER_PIVOT_FIELD }, // POINTER_PIVOT_FIELD
2311 { 0, 0, SAL_RESID_POINTER_CHAIN }, // POINTER_CHAIN
2312 { 0, 0, SAL_RESID_POINTER_CHAIN_NOTALLOWED }, // POINTER_CHAIN_NOTALLOWED
2313 { 0, 0, SAL_RESID_POINTER_TIMEEVENT_MOVE }, // POINTER_TIMEEVENT_MOVE
2314 { 0, 0, SAL_RESID_POINTER_TIMEEVENT_SIZE }, // POINTER_TIMEEVENT_SIZE
2315 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_N }, // POINTER_AUTOSCROLL_N
2316 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_S }, // POINTER_AUTOSCROLL_S
2317 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_W }, // POINTER_AUTOSCROLL_W
2318 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_E }, // POINTER_AUTOSCROLL_E
2319 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NW }, // POINTER_AUTOSCROLL_NW
2320 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NE }, // POINTER_AUTOSCROLL_NE
2321 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_SW }, // POINTER_AUTOSCROLL_SW
2322 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_SE }, // POINTER_AUTOSCROLL_SE
2323 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NS }, // POINTER_AUTOSCROLL_NS
2324 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_WE }, // POINTER_AUTOSCROLL_WE
2325 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NSWE }, // POINTER_AUTOSCROLL_NSWE
2326 { 0, 0, SAL_RESID_POINTER_AIRBRUSH }, // POINTER_AIRBRUSH
2327 { 0, 0, SAL_RESID_POINTER_TEXT_VERTICAL }, // POINTER_TEXT_VERTICAL
2328 { 0, 0, SAL_RESID_POINTER_PIVOT_DELETE }, // POINTER_PIVOT_DELETE
2330 // --> FME 2004-07-30 #i32329# Enhanced table selection
2331 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_S }, // POINTER_TAB_SELECT_S
2332 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_E }, // POINTER_TAB_SELECT_E
2333 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_SE }, // POINTER_TAB_SELECT_SE
2334 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_W }, // POINTER_TAB_SELECT_W
2335 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_SW }, // POINTER_TAB_SELECT_SW
2336 // <--
2338 // --> FME 2004-08-16 #i20119# Paintbrush tool
2339 { 0, 0, SAL_RESID_POINTER_PAINTBRUSH } // POINTER_PAINTBRUSH
2340 // <--
2344 #if POINTER_COUNT != 94
2345 #error New Pointer must be defined!
2346 #endif
2348 // Mousepointer loaded ?
2349 if ( !aImplPtrTab[ePointerStyle].mhCursor )
2351 if ( aImplPtrTab[ePointerStyle].mnOwnId )
2352 aImplPtrTab[ePointerStyle].mhCursor = ImplLoadSalCursor( aImplPtrTab[ePointerStyle].mnOwnId );
2353 else
2354 aImplPtrTab[ePointerStyle].mhCursor = LoadCursor( 0, aImplPtrTab[ePointerStyle].mnSysId );
2357 // Unterscheidet sich der Mauspointer, dann den neuen setzen
2358 if ( mhCursor != aImplPtrTab[ePointerStyle].mhCursor )
2360 mhCursor = aImplPtrTab[ePointerStyle].mhCursor;
2361 SetCursor( mhCursor );
2365 // -----------------------------------------------------------------------
2367 void WinSalFrame::CaptureMouse( sal_Bool bCapture )
2369 // Send this Message to the window, because CaptureMouse() only work
2370 // in the thread of the window, which has create this window
2371 int nMsg;
2372 if ( bCapture )
2373 nMsg = SAL_MSG_CAPTUREMOUSE;
2374 else
2375 nMsg = SAL_MSG_RELEASEMOUSE;
2376 ImplSendMessage( mhWnd, nMsg, 0, 0 );
2379 // -----------------------------------------------------------------------
2381 void WinSalFrame::SetPointerPos( long nX, long nY )
2383 POINT aPt;
2384 aPt.x = (int)nX;
2385 aPt.y = (int)nY;
2386 ClientToScreen( mhWnd, &aPt );
2387 SetCursorPos( aPt.x, aPt.y );
2390 // -----------------------------------------------------------------------
2392 void WinSalFrame::Flush()
2394 GdiFlush();
2397 // -----------------------------------------------------------------------
2399 void WinSalFrame::Sync()
2401 GdiFlush();
2404 // -----------------------------------------------------------------------
2406 static void ImplSalFrameSetInputContext( HWND hWnd, const SalInputContext* pContext )
2408 WinSalFrame* pFrame = GetWindowPtr( hWnd );
2409 sal_Bool bIME = (pContext->mnOptions & SAL_INPUTCONTEXT_TEXT) != 0;
2410 if ( bIME )
2412 if ( !pFrame->mbIME )
2414 pFrame->mbIME = TRUE;
2416 if ( pFrame->mhDefIMEContext )
2418 ImmAssociateContext( pFrame->mhWnd, pFrame->mhDefIMEContext );
2419 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY );
2420 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
2421 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
2422 pFrame->mbHandleIME = !pFrame->mbSpezIME;
2426 // When the application can't handle IME messages, then the
2427 // System should handle the IME handling
2428 if ( !(pContext->mnOptions & SAL_INPUTCONTEXT_EXTTEXTINPUT) )
2429 pFrame->mbHandleIME = FALSE;
2431 // Set the Font for IME Handling
2432 if ( pContext->mpFont )
2434 HIMC hIMC = ImmGetContext( pFrame->mhWnd );
2435 if ( hIMC )
2437 LOGFONTW aLogFont;
2438 HDC hDC = GetDC( pFrame->mhWnd );
2439 // In case of vertical writing, always append a '@' to the
2440 // Windows font name, not only if such a Windows font really is
2441 // available (bTestVerticalAvail == false in the below call):
2442 // The Windows IME's candidates window seems to always use a
2443 // font that has all necessary glyphs, not necessarily the one
2444 // specified by this font name; but it seems to decide whether
2445 // to use that font's horizontal or vertical variant based on a
2446 // '@' in front of this font name.
2447 ImplGetLogFontFromFontSelect( hDC, pContext->mpFont, aLogFont,
2448 false );
2449 ReleaseDC( pFrame->mhWnd, hDC );
2450 ImmSetCompositionFontW( hIMC, &aLogFont );
2451 ImmReleaseContext( pFrame->mhWnd, hIMC );
2455 else
2457 if ( pFrame->mbIME )
2459 pFrame->mbIME = FALSE;
2460 pFrame->mbHandleIME = FALSE;
2461 ImmAssociateContext( pFrame->mhWnd, 0 );
2466 // -----------------------------------------------------------------------
2468 void WinSalFrame::SetInputContext( SalInputContext* pContext )
2470 // Must be called in the main thread!
2471 ImplSendMessage( mhWnd, SAL_MSG_SETINPUTCONTEXT, 0, (LPARAM)(void*)pContext );
2474 // -----------------------------------------------------------------------
2476 static void ImplSalFrameEndExtTextInput( HWND hWnd, sal_uInt16 nFlags )
2478 HIMC hIMC = ImmGetContext( hWnd );
2479 if ( hIMC )
2481 DWORD nIndex;
2482 if ( nFlags & SAL_FRAME_ENDEXTTEXTINPUT_COMPLETE )
2483 nIndex = CPS_COMPLETE;
2484 else
2485 nIndex = CPS_CANCEL;
2487 ImmNotifyIME( hIMC, NI_COMPOSITIONSTR, nIndex, 0 );
2488 ImmReleaseContext( hWnd, hIMC );
2492 // -----------------------------------------------------------------------
2494 void WinSalFrame::EndExtTextInput( sal_uInt16 nFlags )
2496 // Must be called in the main thread!
2497 ImplSendMessage( mhWnd, SAL_MSG_ENDEXTTEXTINPUT, (WPARAM)nFlags, 0 );
2500 // -----------------------------------------------------------------------
2502 static void ImplGetKeyNameText( LONG lParam, sal_Unicode* pBuf,
2503 UINT& rCount, UINT nMaxSize,
2504 const sal_Char* pReplace )
2506 DBG_ASSERT( sizeof( WCHAR ) == sizeof( xub_Unicode ), "WinSalFrame::ImplGetKeyNameTextW(): WCHAR != sal_Unicode" );
2508 static const int nMaxKeyLen = 350;
2509 WCHAR aKeyBuf[ nMaxKeyLen ];
2510 int nKeyLen = 0;
2511 if ( lParam )
2513 if ( true/*aSalShlData.mbWNT*/ )
2515 nKeyLen = GetKeyNameTextW( lParam, aKeyBuf, nMaxKeyLen );
2516 // #i12401# the current unicows.dll has a bug in CharUpperBuffW, which corrupts the stack
2517 // fall back to the ANSI version instead
2518 DBG_ASSERT( nKeyLen <= nMaxKeyLen, "Invalid key name length!" );
2519 if( nKeyLen > nMaxKeyLen )
2520 nKeyLen = 0;
2521 else if( nKeyLen > 0 )
2523 // Capitalize just the first letter of key names
2524 CharLowerBuffW( aKeyBuf, nKeyLen );
2526 bool bUpper = true;
2527 for( WCHAR *pW=aKeyBuf, *pE=pW+nKeyLen; pW < pE; ++pW )
2529 if( bUpper )
2530 CharUpperBuffW( pW, 1 );
2531 bUpper = (*pW=='+') || (*pW=='-') || (*pW==' ') || (*pW=='.');
2537 if ( (nKeyLen > 0) || pReplace )
2539 if( (rCount > 0) && (rCount < nMaxSize) )
2541 pBuf[rCount] = '+';
2542 rCount++;
2545 if( nKeyLen > 0 )
2547 if( nKeyLen + rCount > nMaxSize )
2548 nKeyLen = nMaxSize - rCount;
2549 memcpy( pBuf+rCount, aKeyBuf, nKeyLen*sizeof( sal_Unicode ) );
2550 rCount += nKeyLen;
2552 else // fall back to provided default name
2554 while( *pReplace && (rCount < nMaxSize) )
2556 pBuf[rCount] = *pReplace;
2557 rCount++;
2558 pReplace++;
2562 else
2563 rCount = 0;
2566 // -----------------------------------------------------------------------
2568 XubString WinSalFrame::GetKeyName( sal_uInt16 nKeyCode )
2570 static const int nMaxKeyLen = 350;
2571 sal_Unicode aKeyBuf[ nMaxKeyLen ];
2572 UINT nKeyBufLen = 0;
2573 UINT nSysCode = 0;
2575 if ( nKeyCode & KEY_MOD1 )
2577 nSysCode = MapVirtualKey( VK_CONTROL, 0 );
2578 nSysCode = (nSysCode << 16) | (((sal_uLong)1) << 25);
2579 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Ctrl" );
2582 if ( nKeyCode & KEY_MOD2 )
2584 nSysCode = MapVirtualKey( VK_MENU, 0 );
2585 nSysCode = (nSysCode << 16) | (((sal_uLong)1) << 25);
2586 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Alt" );
2589 if ( nKeyCode & KEY_SHIFT )
2591 nSysCode = MapVirtualKey( VK_SHIFT, 0 );
2592 nSysCode = (nSysCode << 16) | (((sal_uLong)1) << 25);
2593 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Shift" );
2596 sal_uInt16 nCode = nKeyCode & 0x0FFF;
2597 sal_uLong nSysCode2 = 0;
2598 sal_Char* pReplace = NULL;
2599 sal_Unicode cSVCode = 0;
2600 sal_Char aFBuf[4];
2601 nSysCode = 0;
2603 if ( (nCode >= KEY_0) && (nCode <= KEY_9) )
2604 cSVCode = '0' + (nCode - KEY_0);
2605 else if ( (nCode >= KEY_A) && (nCode <= KEY_Z) )
2606 cSVCode = 'A' + (nCode - KEY_A);
2607 else if ( (nCode >= KEY_F1) && (nCode <= KEY_F26) )
2609 nSysCode = VK_F1 + (nCode - KEY_F1);
2610 aFBuf[0] = 'F';
2611 if ( (nCode >= KEY_F1) && (nCode <= KEY_F9) )
2613 aFBuf[1] = sal::static_int_cast<sal_Char>('1' + (nCode - KEY_F1));
2614 aFBuf[2] = 0;
2616 else if ( (nCode >= KEY_F10) && (nCode <= KEY_F19) )
2618 aFBuf[1] = '1';
2619 aFBuf[2] = sal::static_int_cast<sal_Char>('0' + (nCode - KEY_F10));
2620 aFBuf[3] = 0;
2622 else
2624 aFBuf[1] = '2';
2625 aFBuf[2] = sal::static_int_cast<sal_Char>('0' + (nCode - KEY_F20));
2626 aFBuf[3] = 0;
2628 pReplace = aFBuf;
2630 else
2632 switch ( nCode )
2634 case KEY_DOWN:
2635 nSysCode = VK_DOWN;
2636 nSysCode2 = (((sal_uLong)1) << 24);
2637 pReplace = "Down";
2638 break;
2639 case KEY_UP:
2640 nSysCode = VK_UP;
2641 nSysCode2 = (((sal_uLong)1) << 24);
2642 pReplace = "Up";
2643 break;
2644 case KEY_LEFT:
2645 nSysCode = VK_LEFT;
2646 nSysCode2 = (((sal_uLong)1) << 24);
2647 pReplace = "Left";
2648 break;
2649 case KEY_RIGHT:
2650 nSysCode = VK_RIGHT;
2651 nSysCode2 = (((sal_uLong)1) << 24);
2652 pReplace = "Right";
2653 break;
2654 case KEY_HOME:
2655 nSysCode = VK_HOME;
2656 nSysCode2 = (((sal_uLong)1) << 24);
2657 pReplace = "Home";
2658 break;
2659 case KEY_END:
2660 nSysCode = VK_END;
2661 nSysCode2 = (((sal_uLong)1) << 24);
2662 pReplace = "End";
2663 break;
2664 case KEY_PAGEUP:
2665 nSysCode = VK_PRIOR;
2666 nSysCode2 = (((sal_uLong)1) << 24);
2667 pReplace = "Page Up";
2668 break;
2669 case KEY_PAGEDOWN:
2670 nSysCode = VK_NEXT;
2671 nSysCode2 = (((sal_uLong)1) << 24);
2672 pReplace = "Page Down";
2673 break;
2674 case KEY_RETURN:
2675 nSysCode = VK_RETURN;
2676 pReplace = "Enter";
2677 break;
2678 case KEY_ESCAPE:
2679 nSysCode = VK_ESCAPE;
2680 pReplace = "Escape";
2681 break;
2682 case KEY_TAB:
2683 nSysCode = VK_TAB;
2684 pReplace = "Tab";
2685 break;
2686 case KEY_BACKSPACE:
2687 nSysCode = VK_BACK;
2688 pReplace = "Backspace";
2689 break;
2690 case KEY_SPACE:
2691 nSysCode = VK_SPACE;
2692 pReplace = "Space";
2693 break;
2694 case KEY_INSERT:
2695 nSysCode = VK_INSERT;
2696 nSysCode2 = (((sal_uLong)1) << 24);
2697 pReplace = "Insert";
2698 break;
2699 case KEY_DELETE:
2700 nSysCode = VK_DELETE;
2701 nSysCode2 = (((sal_uLong)1) << 24);
2702 pReplace = "Delete";
2703 break;
2705 case KEY_ADD:
2706 cSVCode = '+';
2707 break;
2708 case KEY_SUBTRACT:
2709 cSVCode = '-';
2710 break;
2711 case KEY_MULTIPLY:
2712 cSVCode = '*';
2713 break;
2714 case KEY_DIVIDE:
2715 cSVCode = '/';
2716 break;
2717 case KEY_POINT:
2718 cSVCode = '.';
2719 break;
2720 case KEY_COMMA:
2721 cSVCode = ',';
2722 break;
2723 case KEY_LESS:
2724 cSVCode = '<';
2725 break;
2726 case KEY_GREATER:
2727 cSVCode = '>';
2728 break;
2729 case KEY_EQUAL:
2730 cSVCode = '=';
2731 break;
2735 if ( nSysCode )
2737 nSysCode = MapVirtualKey( (UINT)nSysCode, 0 );
2738 if ( nSysCode )
2739 nSysCode = (nSysCode << 16) | nSysCode2;
2740 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, pReplace );
2742 else
2744 if ( cSVCode )
2746 if ( nKeyBufLen > 0 )
2747 aKeyBuf[ nKeyBufLen++ ] = '+';
2748 if( nKeyBufLen < nMaxKeyLen )
2749 aKeyBuf[ nKeyBufLen++ ] = cSVCode;
2753 if( !nKeyBufLen )
2754 return XubString();
2756 return XubString( aKeyBuf, sal::static_int_cast< sal_uInt16 >(nKeyBufLen) );
2759 // -----------------------------------------------------------------------
2761 XubString WinSalFrame::GetSymbolKeyName( const XubString&, sal_uInt16 nKeyCode )
2763 return GetKeyName( nKeyCode );
2766 // -----------------------------------------------------------------------
2768 inline Color ImplWinColorToSal( COLORREF nColor )
2770 return Color( GetRValue( nColor ), GetGValue( nColor ), GetBValue( nColor ) );
2773 // -----------------------------------------------------------------------
2775 static void ImplSalUpdateStyleFontA( HDC hDC, const LOGFONTA& rLogFont, Font& rFont )
2777 ImplSalLogFontToFontA( hDC, rLogFont, rFont );
2779 // On Windows 9x, Windows NT we get sometimes very small sizes
2780 // (for example for the small Caption height).
2781 // So if it is MS Sans Serif, a none scalable font we use
2782 // 8 Point as the minimum control height, in all other cases
2783 // 6 Point is the smallest one
2784 if ( rFont.GetHeight() < 8 )
2786 if ( rtl_str_compareIgnoreAsciiCase( rLogFont.lfFaceName, "MS Sans Serif" ) == 0 )
2787 rFont.SetHeight( 8 );
2788 else if ( rFont.GetHeight() < 6 )
2789 rFont.SetHeight( 6 );
2793 // -----------------------------------------------------------------------
2795 static void ImplSalUpdateStyleFontW( HDC hDC, const LOGFONTW& rLogFont, Font& rFont )
2797 ImplSalLogFontToFontW( hDC, rLogFont, rFont );
2799 // On Windows 9x, Windows NT we get sometimes very small sizes
2800 // (for example for the small Caption height).
2801 // So if it is MS Sans Serif, a none scalable font we use
2802 // 8 Point as the minimum control height, in all other cases
2803 // 6 Point is the smallest one
2804 if ( rFont.GetHeight() < 8 )
2806 if ( rtl_ustr_compareIgnoreAsciiCase( reinterpret_cast<const sal_Unicode*>(rLogFont.lfFaceName), reinterpret_cast<const sal_Unicode*>(L"MS Sans Serif") ) == 0 )
2807 rFont.SetHeight( 8 );
2808 else if ( rFont.GetHeight() < 6 )
2809 rFont.SetHeight( 6 );
2813 // -----------------------------------------------------------------------
2815 static long ImplA2I( const BYTE* pStr )
2817 long n = 0;
2818 int nSign = 1;
2820 if ( *pStr == '-' )
2822 nSign = -1;
2823 pStr++;
2826 while( (*pStr >= 48) && (*pStr <= 57) )
2828 n *= 10;
2829 n += ((*pStr) - 48);
2830 pStr++;
2833 n *= nSign;
2835 return n;
2838 // -----------------------------------------------------------------------
2839 static HRESULT WINAPI backwardCompatibleDwmIsCompositionEnabled( BOOL* pOut )
2841 *pOut = FALSE;
2842 return S_OK;
2845 static BOOL ImplDwmIsCompositionEnabled()
2847 SalData* pSalData = GetSalData();
2848 if( ! pSalData->mpDwmIsCompositionEnabled )
2850 rtl::OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM( "Dwmapi.dll" ) );
2851 pSalData->maDwmLib = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT );
2852 if( pSalData->maDwmLib )
2853 pSalData->mpDwmIsCompositionEnabled = (DwmIsCompositionEnabled_ptr)osl_getAsciiFunctionSymbol( pSalData->maDwmLib, "DwmIsCompositionEnabled" );
2854 if( ! pSalData->mpDwmIsCompositionEnabled ) // something failed
2855 pSalData->mpDwmIsCompositionEnabled = backwardCompatibleDwmIsCompositionEnabled;
2857 BOOL aResult = FALSE;
2858 HRESULT nError = pSalData->mpDwmIsCompositionEnabled( &aResult );
2859 return nError == S_OK && aResult;
2863 void WinSalFrame::UpdateSettings( AllSettings& rSettings )
2865 MouseSettings aMouseSettings = rSettings.GetMouseSettings();
2866 aMouseSettings.SetDoubleClickTime( GetDoubleClickTime() );
2867 aMouseSettings.SetDoubleClickWidth( GetSystemMetrics( SM_CXDOUBLECLK ) );
2868 aMouseSettings.SetDoubleClickHeight( GetSystemMetrics( SM_CYDOUBLECLK ) );
2869 long nDragWidth = GetSystemMetrics( SM_CXDRAG );
2870 long nDragHeight = GetSystemMetrics( SM_CYDRAG );
2871 if ( nDragWidth )
2872 aMouseSettings.SetStartDragWidth( nDragWidth );
2873 if ( nDragHeight )
2874 aMouseSettings.SetStartDragHeight( nDragHeight );
2875 HKEY hRegKey;
2876 if ( RegOpenKey( HKEY_CURRENT_USER,
2877 "Control Panel\\Desktop",
2878 &hRegKey ) == ERROR_SUCCESS )
2880 BYTE aValueBuf[10];
2881 DWORD nValueSize = sizeof( aValueBuf );
2882 DWORD nType;
2883 if ( RegQueryValueEx( hRegKey, "MenuShowDelay", 0,
2884 &nType, aValueBuf, &nValueSize ) == ERROR_SUCCESS )
2886 if ( nType == REG_SZ )
2887 aMouseSettings.SetMenuDelay( (sal_uLong)ImplA2I( aValueBuf ) );
2890 RegCloseKey( hRegKey );
2893 StyleSettings aStyleSettings = rSettings.GetStyleSettings();
2894 // TODO: once those options vanish: just set bCompBorder to TRUE
2895 // to have the system colors read
2896 aStyleSettings.SetScrollBarSize( GetSystemMetrics( SM_CXVSCROLL ) );
2897 aStyleSettings.SetSpinSize( GetSystemMetrics( SM_CXVSCROLL ) );
2898 aStyleSettings.SetCursorBlinkTime( GetCaretBlinkTime() );
2899 aStyleSettings.SetFloatTitleHeight( GetSystemMetrics( SM_CYSMCAPTION ) );
2900 aStyleSettings.SetTitleHeight( GetSystemMetrics( SM_CYCAPTION ) );
2901 aStyleSettings.SetActiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVEBORDER ) ) );
2902 aStyleSettings.SetDeactiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVEBORDER ) ) );
2903 if ( aSalShlData.mnVersion >= 410 )
2905 aStyleSettings.SetActiveColor2( ImplWinColorToSal( GetSysColor( COLOR_GRADIENTACTIVECAPTION ) ) );
2906 aStyleSettings.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_GRADIENTINACTIVECAPTION ) ) );
2908 aStyleSettings.SetFaceColor( ImplWinColorToSal( GetSysColor( COLOR_3DFACE ) ) );
2909 aStyleSettings.SetInactiveTabColor( aStyleSettings.GetFaceColor() );
2910 aStyleSettings.SetLightColor( ImplWinColorToSal( GetSysColor( COLOR_3DHILIGHT ) ) );
2911 aStyleSettings.SetLightBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DLIGHT ) ) );
2912 aStyleSettings.SetShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW ) ) );
2913 aStyleSettings.SetDarkShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DDKSHADOW ) ) );
2914 aStyleSettings.SetWorkspaceColor( ImplWinColorToSal( GetSysColor( COLOR_APPWORKSPACE ) ) );
2915 aStyleSettings.SetHelpColor( ImplWinColorToSal( GetSysColor( COLOR_INFOBK ) ) );
2916 aStyleSettings.SetHelpTextColor( ImplWinColorToSal( GetSysColor( COLOR_INFOTEXT ) ) );
2917 aStyleSettings.SetDialogColor( aStyleSettings.GetFaceColor() );
2918 aStyleSettings.SetDialogTextColor( aStyleSettings.GetButtonTextColor() );
2919 aStyleSettings.SetButtonTextColor( ImplWinColorToSal( GetSysColor( COLOR_BTNTEXT ) ) );
2920 aStyleSettings.SetButtonRolloverTextColor( aStyleSettings.GetButtonTextColor() );
2921 aStyleSettings.SetRadioCheckTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT ) ) );
2922 aStyleSettings.SetGroupTextColor( aStyleSettings.GetRadioCheckTextColor() );
2923 aStyleSettings.SetLabelTextColor( aStyleSettings.GetRadioCheckTextColor() );
2924 aStyleSettings.SetInfoTextColor( aStyleSettings.GetRadioCheckTextColor() );
2925 aStyleSettings.SetWindowColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOW ) ) );
2926 aStyleSettings.SetActiveTabColor( aStyleSettings.GetWindowColor() );
2927 aStyleSettings.SetWindowTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT ) ) );
2928 aStyleSettings.SetFieldColor( aStyleSettings.GetWindowColor() );
2929 aStyleSettings.SetFieldTextColor( aStyleSettings.GetWindowTextColor() );
2930 aStyleSettings.SetFieldRolloverTextColor( aStyleSettings.GetFieldTextColor() );
2931 aStyleSettings.SetHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHT ) ) );
2932 aStyleSettings.SetHighlightTextColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHTTEXT ) ) );
2933 aStyleSettings.SetMenuHighlightColor( aStyleSettings.GetHighlightColor() );
2934 aStyleSettings.SetMenuHighlightTextColor( aStyleSettings.GetHighlightTextColor() );
2936 ImplSVData* pSVData = ImplGetSVData();
2937 pSVData->maNWFData.mnMenuFormatExtraBorder = 0;
2938 pSVData->maNWFData.maMenuBarHighlightTextColor = Color( COL_TRANSPARENT );
2939 GetSalData()->mbThemeMenuSupport = FALSE;
2940 aStyleSettings.SetMenuColor( ImplWinColorToSal( GetSysColor( COLOR_MENU ) ) );
2941 aStyleSettings.SetMenuBarColor( aStyleSettings.GetMenuColor() );
2942 aStyleSettings.SetMenuBorderColor( aStyleSettings.GetLightBorderColor() ); // overriden below for flat menus
2943 aStyleSettings.SetUseFlatBorders( FALSE );
2944 aStyleSettings.SetUseFlatMenues( FALSE );
2945 aStyleSettings.SetMenuTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT ) ) );
2946 aStyleSettings.SetMenuBarTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT ) ) );
2947 aStyleSettings.SetActiveColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVECAPTION ) ) );
2948 aStyleSettings.SetActiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_CAPTIONTEXT ) ) );
2949 aStyleSettings.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTION ) ) );
2950 aStyleSettings.SetDeactiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTIONTEXT ) ) );
2951 if ( aSalShlData.mbWXP )
2953 // only xp supports a different menu bar color
2954 long bFlatMenues = 0;
2955 SystemParametersInfo( SPI_GETFLATMENU, 0, &bFlatMenues, 0);
2956 if( bFlatMenues )
2958 aStyleSettings.SetUseFlatMenues( TRUE );
2959 aStyleSettings.SetMenuBarColor( ImplWinColorToSal( GetSysColor( COLOR_MENUBAR ) ) );
2960 aStyleSettings.SetMenuHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_MENUHILIGHT ) ) );
2961 aStyleSettings.SetMenuBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW ) ) );
2963 // flat borders for our controls etc. as well in this mode (ie, no 3d borders)
2964 // this is not active in the classic style appearance
2965 aStyleSettings.SetUseFlatBorders( TRUE );
2968 // check if vista or newer runs
2969 // in Aero theme (and similar ?) the menu text color does not change
2970 // for selected items; also on WinXP and earlier menus are not themed
2971 if( aSalShlData.maVersionInfo.dwMajorVersion >= 6 &&
2972 ImplDwmIsCompositionEnabled()
2975 // in aero menuitem highlight text is drawn in the same color as normal
2976 aStyleSettings.SetMenuHighlightTextColor( aStyleSettings.GetMenuTextColor() );
2977 pSVData->maNWFData.mnMenuFormatExtraBorder = 2;
2978 pSVData->maNWFData.maMenuBarHighlightTextColor = aStyleSettings.GetMenuTextColor();
2979 GetSalData()->mbThemeMenuSupport = TRUE;
2981 // Bei hellgrau geben wir die Farbe vor, damit es besser aussieht
2982 if ( aStyleSettings.GetFaceColor() == COL_LIGHTGRAY )
2983 aStyleSettings.SetCheckedColor( Color( 0xCC, 0xCC, 0xCC ) );
2984 else
2986 // Checked-Color berechnen
2987 Color aColor1 = aStyleSettings.GetFaceColor();
2988 Color aColor2 = aStyleSettings.GetLightColor();
2989 BYTE nRed = (BYTE)(((sal_uInt16)aColor1.GetRed() + (sal_uInt16)aColor2.GetRed())/2);
2990 BYTE nGreen = (BYTE)(((sal_uInt16)aColor1.GetGreen() + (sal_uInt16)aColor2.GetGreen())/2);
2991 BYTE nBlue = (BYTE)(((sal_uInt16)aColor1.GetBlue() + (sal_uInt16)aColor2.GetBlue())/2);
2992 aStyleSettings.SetCheckedColor( Color( nRed, nGreen, nBlue ) );
2995 // caret width
2996 DWORD nCaretWidth = 2;
2997 if( SystemParametersInfo( SPI_GETCARETWIDTH, 0, &nCaretWidth, 0 ) )
2998 aStyleSettings.SetCursorSize( nCaretWidth );
3000 // High contrast
3001 HIGHCONTRAST hc;
3002 hc.cbSize = sizeof( HIGHCONTRAST );
3003 if( SystemParametersInfo( SPI_GETHIGHCONTRAST, hc.cbSize, &hc, 0) && (hc.dwFlags & HCF_HIGHCONTRASTON) )
3004 aStyleSettings.SetHighContrastMode( 1 );
3005 else
3006 aStyleSettings.SetHighContrastMode( 0 );
3009 // Query Fonts
3010 Font aMenuFont = aStyleSettings.GetMenuFont();
3011 Font aTitleFont = aStyleSettings.GetTitleFont();
3012 Font aFloatTitleFont = aStyleSettings.GetFloatTitleFont();
3013 Font aHelpFont = aStyleSettings.GetHelpFont();
3014 Font aAppFont = aStyleSettings.GetAppFont();
3015 Font aIconFont = aStyleSettings.GetIconFont();
3016 HDC hDC = GetDC( 0 );
3017 if( true/*aSalShlData.mbWNT*/ )
3019 NONCLIENTMETRICSW aNonClientMetrics;
3020 aNonClientMetrics.cbSize = sizeof( aNonClientMetrics );
3021 if ( SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, sizeof( aNonClientMetrics ), &aNonClientMetrics, 0 ) )
3023 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfMenuFont, aMenuFont );
3024 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfCaptionFont, aTitleFont );
3025 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfSmCaptionFont, aFloatTitleFont );
3026 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfStatusFont, aHelpFont );
3027 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfMessageFont, aAppFont );
3029 LOGFONTW aLogFont;
3030 if ( SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &aLogFont, 0 ) )
3031 ImplSalUpdateStyleFontW( hDC, aLogFont, aIconFont );
3035 // get screen font resolution to calculate toolbox item size
3036 long nDPIY = GetDeviceCaps( hDC, LOGPIXELSY );
3038 ReleaseDC( 0, hDC );
3040 long nHeightPx = aMenuFont.GetHeight() * nDPIY / 72;
3041 aStyleSettings.SetToolbarIconSize( (((nHeightPx-1)*2) >= 28) ? STYLE_TOOLBAR_ICONSIZE_LARGE : STYLE_TOOLBAR_ICONSIZE_SMALL );
3043 aStyleSettings.SetMenuFont( aMenuFont );
3044 aStyleSettings.SetTitleFont( aTitleFont );
3045 aStyleSettings.SetFloatTitleFont( aFloatTitleFont );
3046 aStyleSettings.SetHelpFont( aHelpFont );
3047 aStyleSettings.SetIconFont( aIconFont );
3048 // We prefer Arial in the russian version, because MS Sans Serif
3049 // is to wide for the dialogs
3050 if ( rSettings.GetLanguage() == LANGUAGE_RUSSIAN )
3052 XubString aFontName = aAppFont.GetName();
3053 XubString aFirstName = aFontName.GetToken( 0, ';' );
3054 if ( aFirstName.EqualsIgnoreCaseAscii( "MS Sans Serif" ) )
3056 aFontName.InsertAscii( "Arial;", 0 );
3057 aAppFont.SetName( aFontName );
3060 aStyleSettings.SetAppFont( aAppFont );
3061 aStyleSettings.SetGroupFont( aAppFont );
3062 aStyleSettings.SetLabelFont( aAppFont );
3063 aStyleSettings.SetRadioCheckFont( aAppFont );
3064 aStyleSettings.SetPushButtonFont( aAppFont );
3065 aStyleSettings.SetFieldFont( aAppFont );
3066 if ( aAppFont.GetWeight() > WEIGHT_NORMAL )
3067 aAppFont.SetWeight( WEIGHT_NORMAL );
3068 aStyleSettings.SetInfoFont( aAppFont );
3069 aStyleSettings.SetToolFont( aAppFont );
3071 BOOL bDragFull;
3072 if ( SystemParametersInfo( SPI_GETDRAGFULLWINDOWS, 0, &bDragFull, 0 ) )
3074 sal_uLong nDragFullOptions = aStyleSettings.GetDragFullOptions();
3075 if ( bDragFull )
3076 nDragFullOptions |= DRAGFULL_OPTION_WINDOWMOVE | DRAGFULL_OPTION_WINDOWSIZE | DRAGFULL_OPTION_DOCKING | DRAGFULL_OPTION_SPLIT;
3077 else
3078 nDragFullOptions &= ~(DRAGFULL_OPTION_WINDOWMOVE | DRAGFULL_OPTION_WINDOWSIZE | DRAGFULL_OPTION_DOCKING | DRAGFULL_OPTION_SPLIT);
3079 aStyleSettings.SetDragFullOptions( nDragFullOptions );
3082 aStyleSettings.SetIconHorzSpace( GetSystemMetrics( SM_CXICONSPACING ) );
3083 aStyleSettings.SetIconVertSpace( GetSystemMetrics( SM_CYICONSPACING ) );
3084 if ( RegOpenKey( HKEY_CURRENT_USER,
3085 "Control Panel\\International\\Calendars\\TwoDigitYearMax",
3086 &hRegKey ) == ERROR_SUCCESS )
3088 BYTE aValueBuf[10];
3089 DWORD nValue;
3090 DWORD nValueSize = sizeof( aValueBuf );
3091 DWORD nType;
3092 if ( RegQueryValueEx( hRegKey, "1", 0,
3093 &nType, aValueBuf, &nValueSize ) == ERROR_SUCCESS )
3095 if ( nType == REG_SZ )
3097 nValue = (sal_uLong)ImplA2I( aValueBuf );
3098 if ( (nValue > 1000) && (nValue < 10000) )
3100 MiscSettings aMiscSettings = rSettings.GetMiscSettings();
3101 utl::MiscCfg().SetYear2000( (sal_Int32)(nValue-99) );
3102 rSettings.SetMiscSettings( aMiscSettings );
3107 RegCloseKey( hRegKey );
3110 rSettings.SetMouseSettings( aMouseSettings );
3111 rSettings.SetStyleSettings( aStyleSettings );
3114 // -----------------------------------------------------------------------
3116 SalBitmap* WinSalFrame::SnapShot()
3118 WinSalBitmap* pSalBitmap = NULL;
3120 RECT aRect;
3121 GetWindowRect( mhWnd, &aRect );
3123 int nDX = aRect.right-aRect.left;
3124 int nDY = aRect.bottom-aRect.top;
3125 HDC hDC = GetWindowDC( mhWnd );
3126 HBITMAP hBmpBitmap = CreateCompatibleBitmap( hDC, nDX, nDY );
3127 HDC hBmpDC = ImplGetCachedDC( CACHED_HDC_1, hBmpBitmap );
3128 sal_Bool bRet;
3130 bRet = BitBlt( hBmpDC, 0, 0, nDX, nDY, hDC, 0, 0, SRCCOPY ) ? TRUE : FALSE;
3131 ImplReleaseCachedDC( CACHED_HDC_1 );
3133 if ( bRet )
3135 pSalBitmap = new WinSalBitmap;
3137 if ( !pSalBitmap->Create( hBmpBitmap, FALSE, FALSE ) )
3139 delete pSalBitmap;
3140 pSalBitmap = NULL;
3144 return pSalBitmap;
3147 // -----------------------------------------------------------------------
3149 const SystemEnvData* WinSalFrame::GetSystemData() const
3151 return &maSysData;
3154 // -----------------------------------------------------------------------
3156 void WinSalFrame::Beep( SoundType eSoundType )
3158 static UINT aImplSoundTab[5] =
3160 0, // SOUND_DEFAULT
3161 MB_ICONASTERISK, // SOUND_INFO
3162 MB_ICONEXCLAMATION, // SOUND_WARNING
3163 MB_ICONHAND, // SOUND_ERROR
3164 MB_ICONQUESTION // SOUND_QUERY
3167 if( eSoundType != SOUND_DISABLE ) // don't beep on disable
3168 MessageBeep( aImplSoundTab[eSoundType] );
3171 // -----------------------------------------------------------------------
3173 SalFrame::SalPointerState WinSalFrame::GetPointerState()
3175 SalPointerState aState;
3176 aState.mnState = 0;
3178 if ( GetKeyState( VK_LBUTTON ) & 0x8000 )
3179 aState.mnState |= MOUSE_LEFT;
3180 if ( GetKeyState( VK_MBUTTON ) & 0x8000 )
3181 aState.mnState |= MOUSE_MIDDLE;
3182 if ( GetKeyState( VK_RBUTTON ) & 0x8000 )
3183 aState.mnState |= MOUSE_RIGHT;
3184 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3185 aState.mnState |= KEY_SHIFT;
3186 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3187 aState.mnState |= KEY_MOD1;
3188 if ( GetKeyState( VK_MENU ) & 0x8000 )
3189 aState.mnState |= KEY_MOD2;
3191 POINT pt;
3192 GetCursorPos( &pt );
3194 aState.maPos = Point( pt.x - maGeometry.nX, pt.y - maGeometry.nY );
3195 return aState;
3198 // -----------------------------------------------------------------------
3200 void WinSalFrame::SetBackgroundBitmap( SalBitmap* )
3204 // -----------------------------------------------------------------------
3206 void WinSalFrame::ResetClipRegion()
3208 SetWindowRgn( mhWnd, 0, TRUE );
3211 // -----------------------------------------------------------------------
3213 void WinSalFrame::BeginSetClipRegion( sal_uLong nRects )
3215 if( mpClipRgnData )
3216 delete [] (BYTE*)mpClipRgnData;
3217 sal_uLong nRectBufSize = sizeof(RECT)*nRects;
3218 mpClipRgnData = (RGNDATA*)new BYTE[sizeof(RGNDATA)-1+nRectBufSize];
3219 mpClipRgnData->rdh.dwSize = sizeof( RGNDATAHEADER );
3220 mpClipRgnData->rdh.iType = RDH_RECTANGLES;
3221 mpClipRgnData->rdh.nCount = nRects;
3222 mpClipRgnData->rdh.nRgnSize = nRectBufSize;
3223 SetRectEmpty( &(mpClipRgnData->rdh.rcBound) );
3224 mpNextClipRect = (RECT*)(&(mpClipRgnData->Buffer));
3225 mbFirstClipRect = TRUE;
3228 // -----------------------------------------------------------------------
3230 void WinSalFrame::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
3232 if( ! mpClipRgnData )
3233 return;
3235 RECT* pRect = mpNextClipRect;
3236 RECT* pBoundRect = &(mpClipRgnData->rdh.rcBound);
3237 long nRight = nX + nWidth;
3238 long nBottom = nY + nHeight;
3240 if ( mbFirstClipRect )
3242 pBoundRect->left = nX;
3243 pBoundRect->top = nY;
3244 pBoundRect->right = nRight;
3245 pBoundRect->bottom = nBottom;
3246 mbFirstClipRect = FALSE;
3248 else
3250 if ( nX < pBoundRect->left )
3251 pBoundRect->left = (int)nX;
3253 if ( nY < pBoundRect->top )
3254 pBoundRect->top = (int)nY;
3256 if ( nRight > pBoundRect->right )
3257 pBoundRect->right = (int)nRight;
3259 if ( nBottom > pBoundRect->bottom )
3260 pBoundRect->bottom = (int)nBottom;
3263 pRect->left = (int)nX;
3264 pRect->top = (int)nY;
3265 pRect->right = (int)nRight;
3266 pRect->bottom = (int)nBottom;
3267 if( (mpNextClipRect - (RECT*)(&mpClipRgnData->Buffer)) < (int)mpClipRgnData->rdh.nCount )
3268 mpNextClipRect++;
3271 // -----------------------------------------------------------------------
3273 void WinSalFrame::EndSetClipRegion()
3275 if( ! mpClipRgnData )
3276 return;
3278 HRGN hRegion;
3280 // create region from accumulated rectangles
3281 if ( mpClipRgnData->rdh.nCount == 1 )
3283 RECT* pRect = &(mpClipRgnData->rdh.rcBound);
3284 hRegion = CreateRectRgn( pRect->left, pRect->top,
3285 pRect->right, pRect->bottom );
3287 else
3289 sal_uLong nSize = mpClipRgnData->rdh.nRgnSize+sizeof(RGNDATAHEADER);
3290 hRegion = ExtCreateRegion( NULL, nSize, mpClipRgnData );
3292 delete [] (BYTE*)mpClipRgnData;
3293 mpClipRgnData = NULL;
3295 DBG_ASSERT( hRegion, "WinSalFrame::EndSetClipRegion() - Can't create ClipRegion" );
3296 if( hRegion )
3298 RECT aWindowRect;
3299 GetWindowRect( mhWnd, &aWindowRect );
3300 POINT aPt;
3301 aPt.x=0;
3302 aPt.y=0;
3303 ClientToScreen( mhWnd, &aPt );
3304 OffsetRgn( hRegion, aPt.x - aWindowRect.left, aPt.y - aWindowRect.top );
3306 if( SetWindowRgn( mhWnd, hRegion, TRUE ) == 0 )
3307 DeleteObject( hRegion );
3311 // -----------------------------------------------------------------------
3313 static long ImplHandleMouseMsg( HWND hWnd, UINT nMsg,
3314 WPARAM wParam, LPARAM lParam )
3316 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3317 if ( !pFrame )
3318 return 0;
3320 if( nMsg == WM_LBUTTONDOWN || nMsg == WM_MBUTTONDOWN || nMsg == WM_RBUTTONDOWN )
3322 // #103168# post again if async focus has not arrived yet
3323 // hopefully we will not receive the corresponding button up before this
3324 // button down arrives again
3325 Window *pWin = pFrame->GetWindow();
3326 if( pWin && pWin->ImplGetWindowImpl()->mpFrameData->mnFocusId )
3328 ImplPostMessage( hWnd, nMsg, wParam, lParam );
3329 return 1;
3332 SalMouseEvent aMouseEvt;
3333 long nRet;
3334 sal_uInt16 nEvent = 0;
3335 sal_Bool bCall = TRUE;
3337 aMouseEvt.mnX = (short)LOWORD( lParam );
3338 aMouseEvt.mnY = (short)HIWORD( lParam );
3339 aMouseEvt.mnCode = 0;
3340 aMouseEvt.mnTime = GetMessageTime();
3342 // Wegen (Logitech-)MouseTreiber ueber GetKeyState() gehen, die auf
3343 // mittlerer Maustaste Doppelklick simulieren und den KeyStatus nicht
3344 // beruecksichtigen
3346 if ( GetKeyState( VK_LBUTTON ) & 0x8000 )
3347 aMouseEvt.mnCode |= MOUSE_LEFT;
3348 if ( GetKeyState( VK_MBUTTON ) & 0x8000 )
3349 aMouseEvt.mnCode |= MOUSE_MIDDLE;
3350 if ( GetKeyState( VK_RBUTTON ) & 0x8000 )
3351 aMouseEvt.mnCode |= MOUSE_RIGHT;
3352 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3353 aMouseEvt.mnCode |= KEY_SHIFT;
3354 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3355 aMouseEvt.mnCode |= KEY_MOD1;
3356 if ( GetKeyState( VK_MENU ) & 0x8000 )
3357 aMouseEvt.mnCode |= KEY_MOD2;
3359 switch ( nMsg )
3361 case WM_MOUSEMOVE:
3363 // Da bei Druecken von Modifier-Tasten die MouseEvents
3364 // nicht zusammengefast werden (da diese durch KeyEvents
3365 // unterbrochen werden), machen wir dieses hier selber
3366 if ( aMouseEvt.mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2) )
3368 MSG aTempMsg;
3369 if ( ImplPeekMessage( &aTempMsg, hWnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE | PM_NOYIELD ) )
3371 if ( (aTempMsg.message == WM_MOUSEMOVE) &&
3372 (aTempMsg.wParam == wParam) )
3373 return 1;
3377 SalData* pSalData = GetSalData();
3378 // Test for MouseLeave
3379 if ( pSalData->mhWantLeaveMsg && (pSalData->mhWantLeaveMsg != hWnd) )
3380 ImplSendMessage( pSalData->mhWantLeaveMsg, SAL_MSG_MOUSELEAVE, 0, GetMessagePos() );
3382 pSalData->mhWantLeaveMsg = hWnd;
3383 // Start MouseLeave-Timer
3384 if ( !pSalData->mpMouseLeaveTimer )
3386 pSalData->mpMouseLeaveTimer = new AutoTimer;
3387 pSalData->mpMouseLeaveTimer->SetTimeout( SAL_MOUSELEAVE_TIMEOUT );
3388 pSalData->mpMouseLeaveTimer->Start();
3389 // We dont need to set a timeout handler, because we test
3390 // for mouseleave in the timeout callback
3392 aMouseEvt.mnButton = 0;
3393 nEvent = SALEVENT_MOUSEMOVE;
3395 break;
3397 case WM_NCMOUSEMOVE:
3398 case SAL_MSG_MOUSELEAVE:
3400 SalData* pSalData = GetSalData();
3401 if ( pSalData->mhWantLeaveMsg == hWnd )
3403 pSalData->mhWantLeaveMsg = 0;
3404 if ( pSalData->mpMouseLeaveTimer )
3406 delete pSalData->mpMouseLeaveTimer;
3407 pSalData->mpMouseLeaveTimer = NULL;
3409 // Mouse-Coordinaates are relativ to the screen
3410 POINT aPt;
3411 aPt.x = (short)LOWORD( lParam );
3412 aPt.y = (short)HIWORD( lParam );
3413 ScreenToClient( hWnd, &aPt );
3414 aMouseEvt.mnX = aPt.x;
3415 aMouseEvt.mnY = aPt.y;
3416 aMouseEvt.mnButton = 0;
3417 nEvent = SALEVENT_MOUSELEAVE;
3419 else
3420 bCall = FALSE;
3422 break;
3424 case WM_LBUTTONDOWN:
3425 aMouseEvt.mnButton = MOUSE_LEFT;
3426 nEvent = SALEVENT_MOUSEBUTTONDOWN;
3427 break;
3429 case WM_MBUTTONDOWN:
3430 aMouseEvt.mnButton = MOUSE_MIDDLE;
3431 nEvent = SALEVENT_MOUSEBUTTONDOWN;
3432 break;
3434 case WM_RBUTTONDOWN:
3435 aMouseEvt.mnButton = MOUSE_RIGHT;
3436 nEvent = SALEVENT_MOUSEBUTTONDOWN;
3437 break;
3439 case WM_LBUTTONUP:
3440 aMouseEvt.mnButton = MOUSE_LEFT;
3441 nEvent = SALEVENT_MOUSEBUTTONUP;
3442 break;
3444 case WM_MBUTTONUP:
3445 aMouseEvt.mnButton = MOUSE_MIDDLE;
3446 nEvent = SALEVENT_MOUSEBUTTONUP;
3447 break;
3449 case WM_RBUTTONUP:
3450 aMouseEvt.mnButton = MOUSE_RIGHT;
3451 nEvent = SALEVENT_MOUSEBUTTONUP;
3452 break;
3455 // check if this window was destroyed - this might happen if we are the help window
3456 // and sent a mouse leave message to the application which killed the help window, ie ourself
3457 if( !IsWindow( hWnd ) )
3458 return 0;
3460 if ( bCall )
3462 if ( nEvent == SALEVENT_MOUSEBUTTONDOWN )
3463 UpdateWindow( hWnd );
3465 // --- RTL --- (mirror mouse pos)
3466 if( Application::GetSettings().GetLayoutRTL() )
3467 aMouseEvt.mnX = pFrame->maGeometry.nWidth-1-aMouseEvt.mnX;
3469 nRet = pFrame->CallCallback( nEvent, &aMouseEvt );
3470 if ( nMsg == WM_MOUSEMOVE )
3471 SetCursor( pFrame->mhCursor );
3473 else
3474 nRet = 0;
3476 return nRet;
3479 // -----------------------------------------------------------------------
3481 static long ImplHandleMouseActivateMsg( HWND hWnd )
3483 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3484 if ( !pFrame )
3485 return 0;
3487 if ( pFrame->mbFloatWin )
3488 return TRUE;
3490 SalMouseActivateEvent aMouseActivateEvt;
3491 POINT aPt;
3492 GetCursorPos( &aPt );
3493 ScreenToClient( hWnd, &aPt );
3494 aMouseActivateEvt.mnX = aPt.x;
3495 aMouseActivateEvt.mnY = aPt.y;
3496 return pFrame->CallCallback( SALEVENT_MOUSEACTIVATE, &aMouseActivateEvt );
3499 // -----------------------------------------------------------------------
3501 static long ImplHandleWheelMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
3503 DBG_ASSERT( nMsg == WM_MOUSEWHEEL ||
3504 nMsg == WM_MOUSEHWHEEL,
3505 "ImplHandleWheelMsg() called with no wheel mouse event" );
3507 ImplSalYieldMutexAcquireWithWait();
3509 long nRet = 0;
3510 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3511 if ( pFrame )
3513 WORD nWinModCode = LOWORD( wParam );
3514 POINT aWinPt;
3515 aWinPt.x = (short)LOWORD( lParam );
3516 aWinPt.y = (short)HIWORD( lParam );
3517 ScreenToClient( hWnd, &aWinPt );
3519 SalWheelMouseEvent aWheelEvt;
3520 aWheelEvt.mnTime = GetMessageTime();
3521 aWheelEvt.mnX = aWinPt.x;
3522 aWheelEvt.mnY = aWinPt.y;
3523 aWheelEvt.mnCode = 0;
3524 aWheelEvt.mnDelta = (short)HIWORD( wParam );
3525 aWheelEvt.mnNotchDelta = aWheelEvt.mnDelta/WHEEL_DELTA;
3526 if( aWheelEvt.mnNotchDelta == 0 )
3528 if( aWheelEvt.mnDelta > 0 )
3529 aWheelEvt.mnNotchDelta = 1;
3530 else if( aWheelEvt.mnDelta < 0 )
3531 aWheelEvt.mnNotchDelta = -1;
3534 if( nMsg == WM_MOUSEWHEEL )
3536 if ( aSalShlData.mnWheelScrollLines == WHEEL_PAGESCROLL )
3537 aWheelEvt.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
3538 else
3539 aWheelEvt.mnScrollLines = aSalShlData.mnWheelScrollLines;
3540 aWheelEvt.mbHorz = FALSE;
3542 else
3544 aWheelEvt.mnScrollLines = aSalShlData.mnWheelScrollChars;
3545 aWheelEvt.mbHorz = TRUE;
3548 if ( nWinModCode & MK_SHIFT )
3549 aWheelEvt.mnCode |= KEY_SHIFT;
3550 if ( nWinModCode & MK_CONTROL )
3551 aWheelEvt.mnCode |= KEY_MOD1;
3552 if ( GetKeyState( VK_MENU ) & 0x8000 )
3553 aWheelEvt.mnCode |= KEY_MOD2;
3555 // --- RTL --- (mirror mouse pos)
3556 if( Application::GetSettings().GetLayoutRTL() )
3557 aWheelEvt.mnX = pFrame->maGeometry.nWidth-1-aWheelEvt.mnX;
3559 nRet = pFrame->CallCallback( SALEVENT_WHEELMOUSE, &aWheelEvt );
3562 ImplSalYieldMutexRelease();
3564 return nRet;
3567 // -----------------------------------------------------------------------
3569 static sal_uInt16 ImplSalGetKeyCode( WPARAM wParam )
3571 sal_uInt16 nKeyCode;
3573 // convert KeyCode
3574 if ( wParam < KEY_TAB_SIZE )
3575 nKeyCode = aImplTranslateKeyTab[wParam];
3576 else
3578 SalData* pSalData = GetSalData();
3579 std::map< UINT, sal_uInt16 >::const_iterator it = pSalData->maVKMap.find( (UINT)wParam );
3580 if( it != pSalData->maVKMap.end() )
3581 nKeyCode = it->second;
3582 else
3583 nKeyCode = 0;
3586 return nKeyCode;
3589 // -----------------------------------------------------------------------
3591 static UINT ImplStrToNum( const sal_Char* pStr )
3593 sal_uInt16 n = 0;
3595 // Solange es sich um eine Ziffer handelt, String umwandeln
3596 while( (*pStr >= 48) && (*pStr <= 57) )
3598 n *= 10;
3599 n += ((*pStr) - 48);
3600 pStr++;
3603 return n;
3606 // -----------------------------------------------------------------------
3608 static void ImplUpdateInputLang( WinSalFrame* pFrame )
3610 sal_Bool bLanguageChange = FALSE;
3611 UINT nLang = LOWORD( GetKeyboardLayout( 0 ) );
3612 if ( nLang && nLang != pFrame->mnInputLang )
3614 // keep input lang up-to-date
3615 pFrame->mnInputLang = nLang;
3616 bLanguageChange = TRUE;
3619 // If we are on Windows NT we use Unicode FrameProcs and so we
3620 // get Unicode charcodes directly from Windows
3621 // no need to set up a code page
3622 return;
3626 static sal_Unicode ImplGetCharCode( WinSalFrame* pFrame, WPARAM nCharCode )
3628 ImplUpdateInputLang( pFrame );
3630 // If we are on Windows NT we use Unicode FrameProcs and so we
3631 // get Unicode charcodes directly from Windows
3632 return (sal_Unicode)nCharCode;
3635 // -----------------------------------------------------------------------
3637 LanguageType WinSalFrame::GetInputLanguage()
3639 if( !mnInputLang )
3640 ImplUpdateInputLang( this );
3642 if( !mnInputLang )
3643 return LANGUAGE_DONTKNOW;
3644 else
3645 return (LanguageType) mnInputLang;
3648 // -----------------------------------------------------------------------
3650 sal_Bool WinSalFrame::MapUnicodeToKeyCode( sal_Unicode aUnicode, LanguageType aLangType, KeyCode& rKeyCode )
3652 sal_Bool bRet = FALSE;
3653 HKL hkl = 0;
3655 // just use the passed language identifier, do not try to load additional keyboard support
3656 hkl = (HKL) aLangType;
3658 if( hkl )
3660 SHORT scan = VkKeyScanExW( aUnicode, hkl );
3661 if( LOWORD(scan) == 0xFFFF )
3662 // keyboard not loaded or key cannot be mapped
3663 bRet = FALSE;
3664 else
3666 BYTE vkeycode = LOBYTE(scan);
3667 BYTE shiftstate = HIBYTE(scan);
3669 // Last argument is set to FALSE, because there's no decission made
3670 // yet which key should be assigned to MOD3 modifier on Windows.
3671 // Windows key - user's can be confused, because it should display
3672 // Windows menu (applies to both left/right key)
3673 // Menu key - this key is used to display context menu
3674 // AltGr key - probably it has no sense
3675 rKeyCode = KeyCode( ImplSalGetKeyCode( vkeycode ),
3676 (shiftstate & 0x01) ? TRUE : FALSE, // shift
3677 (shiftstate & 0x02) ? TRUE : FALSE, // ctrl
3678 (shiftstate & 0x04) ? TRUE : FALSE, // alt
3679 FALSE );
3680 bRet = TRUE;
3684 return bRet;
3687 // -----------------------------------------------------------------------
3689 static long ImplHandleKeyMsg( HWND hWnd, UINT nMsg,
3690 WPARAM wParam, LPARAM lParam, LRESULT& rResult )
3692 static sal_Bool bIgnoreCharMsg = FALSE;
3693 static WPARAM nDeadChar = 0;
3694 static WPARAM nLastVKChar = 0;
3695 static sal_uInt16 nLastChar = 0;
3696 static sal_uInt16 nLastModKeyCode = 0;
3697 static bool bWaitForModKeyRelease = false;
3698 sal_uInt16 nRepeat = LOWORD( lParam )-1;
3699 sal_uInt16 nModCode = 0;
3701 // Key wurde evtl. durch SysChild an uns weitergeleitet und
3702 // darf somit dann nicht doppelt verarbeitet werden
3703 GetSalData()->mnSalObjWantKeyEvt = 0;
3705 if ( nMsg == WM_DEADCHAR )
3707 nDeadChar = wParam;
3708 return 0;
3711 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3712 if ( !pFrame )
3713 return 0;
3715 // Wir restaurieren den Background-Modus bei jeder Texteingabe,
3716 // da einige Tools wie RichWin uns diesen hin- und wieder umsetzen
3717 if ( pFrame->mpGraphics &&
3718 pFrame->mpGraphics->mhDC )
3719 SetBkMode( pFrame->mpGraphics->mhDC, TRANSPARENT );
3721 // determine modifiers
3722 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3723 nModCode |= KEY_SHIFT;
3724 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3725 nModCode |= KEY_MOD1;
3726 if ( GetKeyState( VK_MENU ) & 0x8000 )
3727 nModCode |= KEY_MOD2;
3729 if ( (nMsg == WM_CHAR) || (nMsg == WM_SYSCHAR) )
3731 nDeadChar = 0;
3733 if ( bIgnoreCharMsg )
3735 bIgnoreCharMsg = FALSE;
3736 // #101635# if zero is returned here for WM_SYSCHAR (ALT+<key>) Windows will beep
3737 // becaus this 'hotkey' was not processed -> better return 1
3738 // except for Alt-SPACE which should always open the sysmenu (#104616#)
3740 // also return zero if a system menubar is available that might process this hotkey
3741 // this also applies to the OLE inplace embedding where we are a child window
3742 if( (GetWindowStyle( hWnd ) & WS_CHILD) || GetMenu( hWnd ) || (wParam == 0x20) )
3743 return 0;
3744 else
3745 return 1;
3748 // Backspace ignorieren wir als eigenstaendige Taste,
3749 // damit wir keine Probleme in Kombination mit einem
3750 // DeadKey bekommen
3751 if ( wParam == 0x08 ) // BACKSPACE
3752 return 0;
3754 // Hier kommen nur "freifliegende" WM_CHAR Message an, die durch
3755 // eintippen einer ALT-NUMPAD Kombination erzeugt wurden
3756 SalKeyEvent aKeyEvt;
3758 if ( (wParam >= '0') && (wParam <= '9') )
3759 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_NUM + wParam - '0');
3760 else if ( (wParam >= 'A') && (wParam <= 'Z') )
3761 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_ALPHA + wParam - 'A');
3762 else if ( (wParam >= 'a') && (wParam <= 'z') )
3763 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_ALPHA + wParam - 'a');
3764 else if ( wParam == 0x0D ) // RETURN
3765 aKeyEvt.mnCode = KEY_RETURN;
3766 else if ( wParam == 0x1B ) // ESCAPE
3767 aKeyEvt.mnCode = KEY_ESCAPE;
3768 else if ( wParam == 0x09 ) // TAB
3769 aKeyEvt.mnCode = KEY_TAB;
3770 else if ( wParam == 0x20 ) // SPACE
3771 aKeyEvt.mnCode = KEY_SPACE;
3772 else
3773 aKeyEvt.mnCode = 0;
3775 aKeyEvt.mnTime = GetMessageTime();
3776 aKeyEvt.mnCode |= nModCode;
3777 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, wParam );
3778 aKeyEvt.mnRepeat = nRepeat;
3779 nLastChar = 0;
3780 nLastVKChar = 0;
3781 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
3782 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3783 return nRet;
3785 // #i11583#, MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition begins
3786 else if( nMsg == WM_UNICHAR )
3788 // If Windows is asking if we accept WM_UNICHAR, return TRUE
3789 if(wParam == UNICODE_NOCHAR)
3791 rResult = TRUE; // ssa: this will actually return TRUE to windows
3792 return 1; // ...but this will only avoid calling the defwindowproc
3795 SalKeyEvent aKeyEvt;
3796 aKeyEvt.mnCode = nModCode; // Or should it be 0? - as this is always a character returned
3797 aKeyEvt.mnTime = GetMessageTime();
3798 aKeyEvt.mnRepeat = 0;
3800 if( wParam >= Uni_SupplementaryPlanesStart )
3802 // character is supplementary char in UTF-32 format - must be converted to UTF-16 supplementary pair
3803 // sal_Unicode ch = (sal_Unicode) Uni_UTF32ToSurrogate1(wParam);
3804 nLastChar = 0;
3805 nLastVKChar = 0;
3806 pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
3807 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3808 wParam = (sal_Unicode) Uni_UTF32ToSurrogate2( wParam );
3811 aKeyEvt.mnCharCode = (sal_Unicode) wParam;
3813 nLastChar = 0;
3814 nLastVKChar = 0;
3815 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
3816 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3818 return nRet;
3820 // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition ends
3821 else
3823 // Bei Shift, Control und Menu schicken wir einen KeyModChange-Event
3824 if ( (wParam == VK_SHIFT) || (wParam == VK_CONTROL) || (wParam == VK_MENU) )
3826 SalKeyModEvent aModEvt;
3827 aModEvt.mnTime = GetMessageTime();
3828 aModEvt.mnCode = nModCode;
3829 aModEvt.mnModKeyCode = 0; // no command events will be sent if this member is 0
3831 sal_uInt16 tmpCode = 0;
3832 if( GetKeyState( VK_LSHIFT ) & 0x8000 )
3833 tmpCode |= MODKEY_LSHIFT;
3834 if( GetKeyState( VK_RSHIFT ) & 0x8000 )
3835 tmpCode |= MODKEY_RSHIFT;
3836 if( GetKeyState( VK_LCONTROL ) & 0x8000 )
3837 tmpCode |= MODKEY_LMOD1;
3838 if( GetKeyState( VK_RCONTROL ) & 0x8000 )
3839 tmpCode |= MODKEY_RMOD1;
3840 if( GetKeyState( VK_LMENU ) & 0x8000 )
3841 tmpCode |= MODKEY_LMOD2;
3842 if( GetKeyState( VK_RMENU ) & 0x8000 )
3843 tmpCode |= MODKEY_RMOD2;
3845 if( tmpCode < nLastModKeyCode )
3847 aModEvt.mnModKeyCode = nLastModKeyCode;
3848 nLastModKeyCode = 0;
3849 bWaitForModKeyRelease = true;
3851 else
3853 if( !bWaitForModKeyRelease )
3854 nLastModKeyCode = tmpCode;
3857 if( !tmpCode )
3858 bWaitForModKeyRelease = false;
3860 return pFrame->CallCallback( SALEVENT_KEYMODCHANGE, &aModEvt );
3862 else
3864 SalKeyEvent aKeyEvt;
3865 sal_uInt16 nEvent;
3866 MSG aCharMsg;
3867 BOOL bCharPeek = FALSE;
3868 UINT nCharMsg = WM_CHAR;
3869 sal_Bool bKeyUp = (nMsg == WM_KEYUP) || (nMsg == WM_SYSKEYUP);
3871 nLastModKeyCode = 0; // make sure no modkey messages are sent if they belong to a hotkey (see above)
3872 aKeyEvt.mnCharCode = 0;
3873 aKeyEvt.mnCode = 0;
3875 aKeyEvt.mnCode = ImplSalGetKeyCode( wParam );
3876 if ( !bKeyUp )
3878 // check for charcode
3879 // Mit Hilfe von PeekMessage holen wir uns jetzt die
3880 // zugehoerige WM_CHAR Message, wenn vorhanden.
3881 // Diese WM_CHAR Message steht immer am Anfang der
3882 // Messagequeue. Ausserdem ist sichergestellt, dass immer
3883 // nur eine WM_CHAR Message in der Queue steht.
3884 bCharPeek = ImplPeekMessage( &aCharMsg, hWnd,
3885 WM_CHAR, WM_CHAR, PM_NOREMOVE | PM_NOYIELD );
3886 if ( bCharPeek && (nDeadChar == aCharMsg.wParam) )
3888 bCharPeek = FALSE;
3889 nDeadChar = 0;
3891 if ( wParam == VK_BACK )
3893 ImplPeekMessage( &aCharMsg, hWnd,
3894 nCharMsg, nCharMsg, PM_REMOVE | PM_NOYIELD );
3895 return 0;
3898 else
3900 if ( !bCharPeek )
3902 bCharPeek = ImplPeekMessage( &aCharMsg, hWnd,
3903 WM_SYSCHAR, WM_SYSCHAR, PM_NOREMOVE | PM_NOYIELD );
3904 nCharMsg = WM_SYSCHAR;
3907 if ( bCharPeek )
3908 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, aCharMsg.wParam );
3909 else
3910 aKeyEvt.mnCharCode = 0;
3912 nLastChar = aKeyEvt.mnCharCode;
3913 nLastVKChar = wParam;
3915 else
3917 if ( wParam == nLastVKChar )
3919 aKeyEvt.mnCharCode = nLastChar;
3920 nLastChar = 0;
3921 nLastVKChar = 0;
3925 if ( aKeyEvt.mnCode || aKeyEvt.mnCharCode )
3927 if ( bKeyUp )
3928 nEvent = SALEVENT_KEYUP;
3929 else
3930 nEvent = SALEVENT_KEYINPUT;
3932 aKeyEvt.mnTime = GetMessageTime();
3933 aKeyEvt.mnCode |= nModCode;
3934 aKeyEvt.mnRepeat = nRepeat;
3936 if( (nModCode & (KEY_MOD1|KEY_MOD2)) == (KEY_MOD1|KEY_MOD2) &&
3937 aKeyEvt.mnCharCode )
3939 // this is actually AltGr and should not be handled as Alt
3940 aKeyEvt.mnCode &= ~(KEY_MOD1|KEY_MOD2);
3943 bIgnoreCharMsg = bCharPeek ? TRUE : FALSE;
3944 long nRet = pFrame->CallCallback( nEvent, &aKeyEvt );
3945 // independent part only reacts on keyup but Windows does not send
3946 // keyup for VK_HANJA
3947 if( aKeyEvt.mnCode == KEY_HANGUL_HANJA )
3948 nRet = pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3950 bIgnoreCharMsg = FALSE;
3952 // char-message, than remove or ignore
3953 if ( bCharPeek )
3955 nDeadChar = 0;
3956 if ( nRet )
3958 ImplPeekMessage( &aCharMsg, hWnd,
3959 nCharMsg, nCharMsg, PM_REMOVE | PM_NOYIELD );
3961 else
3962 bIgnoreCharMsg = TRUE;
3965 return nRet;
3967 else
3968 return 0;
3973 // -----------------------------------------------------------------------
3975 long ImplHandleSalObjKeyMsg( HWND hWnd, UINT nMsg,
3976 WPARAM wParam, LPARAM lParam )
3978 if ( (nMsg == WM_KEYDOWN) || (nMsg == WM_KEYUP) )
3980 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3981 if ( !pFrame )
3982 return 0;
3984 sal_uInt16 nRepeat = LOWORD( lParam )-1;
3985 sal_uInt16 nModCode = 0;
3987 // determine modifiers
3988 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3989 nModCode |= KEY_SHIFT;
3990 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3991 nModCode |= KEY_MOD1;
3992 if ( GetKeyState( VK_MENU ) & 0x8000 )
3993 nModCode |= KEY_MOD2;
3995 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) && (wParam != VK_MENU) )
3997 SalKeyEvent aKeyEvt;
3998 sal_uInt16 nEvent;
3999 sal_Bool bKeyUp = (nMsg == WM_KEYUP) || (nMsg == WM_SYSKEYUP);
4001 // convert KeyCode
4002 aKeyEvt.mnCode = ImplSalGetKeyCode( wParam );
4003 aKeyEvt.mnCharCode = 0;
4005 if ( aKeyEvt.mnCode )
4007 if ( bKeyUp )
4008 nEvent = SALEVENT_KEYUP;
4009 else
4010 nEvent = SALEVENT_KEYINPUT;
4012 aKeyEvt.mnTime = GetMessageTime();
4013 aKeyEvt.mnCode |= nModCode;
4014 aKeyEvt.mnRepeat = nRepeat;
4015 long nRet = pFrame->CallCallback( nEvent, &aKeyEvt );
4016 return nRet;
4018 else
4019 return 0;
4023 return 0;
4026 // -----------------------------------------------------------------------
4028 long ImplHandleSalObjSysCharMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
4030 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4031 if ( !pFrame )
4032 return 0;
4034 sal_uInt16 nRepeat = LOWORD( lParam )-1;
4035 sal_uInt16 nModCode = 0;
4036 sal_uInt16 cKeyCode = (sal_uInt16)wParam;
4038 // determine modifiers
4039 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
4040 nModCode |= KEY_SHIFT;
4041 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
4042 nModCode |= KEY_MOD1;
4043 nModCode |= KEY_MOD2;
4045 // KeyEvent zusammenbauen
4046 SalKeyEvent aKeyEvt;
4047 aKeyEvt.mnTime = GetMessageTime();
4048 if ( (cKeyCode >= 48) && (cKeyCode <= 57) )
4049 aKeyEvt.mnCode = KEY_0+(cKeyCode-48);
4050 else if ( (cKeyCode >= 65) && (cKeyCode <= 90) )
4051 aKeyEvt.mnCode = KEY_A+(cKeyCode-65);
4052 else if ( (cKeyCode >= 97) && (cKeyCode <= 122) )
4053 aKeyEvt.mnCode = KEY_A+(cKeyCode-97);
4054 else
4055 aKeyEvt.mnCode = 0;
4056 aKeyEvt.mnCode |= nModCode;
4057 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, cKeyCode );
4058 aKeyEvt.mnRepeat = nRepeat;
4059 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
4060 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
4061 return nRet;
4064 // -----------------------------------------------------------------------
4066 static bool ImplHandlePaintMsg( HWND hWnd )
4068 sal_Bool bMutex = FALSE;
4069 if ( ImplSalYieldMutexTryToAcquire() )
4070 bMutex = TRUE;
4072 // if we don't get the mutex, we can also change the clip region,
4073 // because other threads doesn't use the mutex from the main
4074 // thread --> see GetGraphics()
4076 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4077 if ( pFrame )
4079 // Clip-Region muss zurueckgesetzt werden, da wir sonst kein
4080 // ordentliches Bounding-Rectangle bekommen
4081 if ( pFrame->mpGraphics && pFrame->mpGraphics->mhRegion )
4082 SelectClipRgn( pFrame->mpGraphics->mhDC, 0 );
4084 // Laut Window-Doku soll man erst abfragen, ob ueberhaupt eine
4085 // Paint-Region anliegt
4086 if ( GetUpdateRect( hWnd, NULL, FALSE ) )
4088 // Call BeginPaint/EndPaint to query the rect and send
4089 // this Notofication to rect
4090 RECT aUpdateRect;
4091 PAINTSTRUCT aPs;
4092 BeginPaint( hWnd, &aPs );
4093 CopyRect( &aUpdateRect, &aPs.rcPaint );
4095 // Paint
4096 // ClipRegion wieder herstellen
4097 if ( pFrame->mpGraphics && pFrame->mpGraphics->mhRegion )
4099 SelectClipRgn( pFrame->mpGraphics->mhDC,
4100 pFrame->mpGraphics->mhRegion );
4103 if ( bMutex )
4105 SalPaintEvent aPEvt( aUpdateRect.left, aUpdateRect.top, aUpdateRect.right-aUpdateRect.left, aUpdateRect.bottom-aUpdateRect.top, pFrame->mbPresentation );
4106 pFrame->CallCallback( SALEVENT_PAINT, &aPEvt );
4108 else
4110 RECT* pRect = new RECT;
4111 CopyRect( pRect, &aUpdateRect );
4112 ImplPostMessage( hWnd, SAL_MSG_POSTPAINT, (WPARAM)pRect, 0 );
4114 EndPaint( hWnd, &aPs );
4116 else
4118 // ClipRegion wieder herstellen
4119 if ( pFrame->mpGraphics && pFrame->mpGraphics->mhRegion )
4121 SelectClipRgn( pFrame->mpGraphics->mhDC,
4122 pFrame->mpGraphics->mhRegion );
4127 if ( bMutex )
4128 ImplSalYieldMutexRelease();
4130 return bMutex ? true : false;
4133 // -----------------------------------------------------------------------
4135 static void ImplHandlePaintMsg2( HWND hWnd, RECT* pRect )
4137 // Paint
4138 if ( ImplSalYieldMutexTryToAcquire() )
4140 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4141 if ( pFrame )
4143 SalPaintEvent aPEvt( pRect->left, pRect->top, pRect->right-pRect->left, pRect->bottom-pRect->top );
4144 pFrame->CallCallback( SALEVENT_PAINT, &aPEvt );
4146 ImplSalYieldMutexRelease();
4147 delete pRect;
4149 else
4150 ImplPostMessage( hWnd, SAL_MSG_POSTPAINT, (WPARAM)pRect, 0 );
4153 // -----------------------------------------------------------------------
4155 static void SetMaximizedFrameGeometry( HWND hWnd, WinSalFrame* pFrame, RECT* pParentRect )
4157 // calculate and set frame geometry of a maximized window - useful if the window is still hidden
4159 // dualmonitor support:
4160 // Get screensize of the monitor whith the mouse pointer
4162 RECT aRectMouse;
4163 if( ! pParentRect )
4165 POINT pt;
4166 GetCursorPos( &pt );
4167 aRectMouse.left = pt.x;
4168 aRectMouse.top = pt.y;
4169 aRectMouse.right = pt.x+2;
4170 aRectMouse.bottom = pt.y+2;
4171 pParentRect = &aRectMouse;
4174 RECT aRect;
4175 ImplSalGetWorkArea( hWnd, &aRect, pParentRect );
4177 // a maximized window has no other borders than the caption
4178 pFrame->maGeometry.nLeftDecoration = pFrame->maGeometry.nRightDecoration = pFrame->maGeometry.nBottomDecoration = 0;
4179 pFrame->maGeometry.nTopDecoration = pFrame->mbCaption ? GetSystemMetrics( SM_CYCAPTION ) : 0;
4181 aRect.top += pFrame->maGeometry.nTopDecoration;
4182 pFrame->maGeometry.nX = aRect.left;
4183 pFrame->maGeometry.nY = aRect.top;
4184 pFrame->maGeometry.nWidth = aRect.right - aRect.left;
4185 pFrame->maGeometry.nHeight = aRect.bottom - aRect.top;
4188 static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame )
4190 if( !pFrame )
4191 return;
4193 RECT aRect;
4194 GetWindowRect( hWnd, &aRect );
4195 memset(&pFrame->maGeometry, 0, sizeof(SalFrameGeometry) );
4197 if ( IsIconic( hWnd ) )
4198 return;
4200 POINT aPt;
4201 aPt.x=0;
4202 aPt.y=0;
4203 ClientToScreen(hWnd, &aPt);
4204 int cx = aPt.x - aRect.left;
4205 pFrame->maGeometry.nTopDecoration = aPt.y - aRect.top;
4207 pFrame->maGeometry.nLeftDecoration = cx;
4208 pFrame->maGeometry.nRightDecoration = cx;
4210 pFrame->maGeometry.nX = aPt.x;
4211 pFrame->maGeometry.nY = aPt.y;
4213 RECT aInnerRect;
4214 GetClientRect( hWnd, &aInnerRect );
4215 if( aInnerRect.right )
4217 // improve right decoration
4218 aPt.x=aInnerRect.right;
4219 aPt.y=aInnerRect.top;
4220 ClientToScreen(hWnd, &aPt);
4221 pFrame->maGeometry.nRightDecoration = aRect.right - aPt.x;
4223 if( aInnerRect.bottom ) // may be zero if window was not shown yet
4224 pFrame->maGeometry.nBottomDecoration += aRect.bottom - aPt.y - aInnerRect.bottom;
4225 else
4226 // bottom border is typically the same as left/right
4227 pFrame->maGeometry.nBottomDecoration = pFrame->maGeometry.nLeftDecoration;
4229 int nWidth = aRect.right - aRect.left
4230 - pFrame->maGeometry.nRightDecoration - pFrame->maGeometry.nLeftDecoration;
4231 int nHeight = aRect.bottom - aRect.top
4232 - pFrame->maGeometry.nBottomDecoration - pFrame->maGeometry.nTopDecoration;
4233 // clamp to zero
4234 pFrame->maGeometry.nHeight = nHeight < 0 ? 0 : nHeight;
4235 pFrame->maGeometry.nWidth = nWidth < 0 ? 0 : nWidth;
4236 pFrame->updateScreenNumber();
4239 // -----------------------------------------------------------------------
4241 static void ImplCallMoveHdl( HWND hWnd )
4243 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4244 if ( pFrame )
4246 pFrame->CallCallback( SALEVENT_MOVE, 0 );
4247 // Um doppelte Paints von VCL und SAL zu vermeiden
4248 //if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
4249 // UpdateWindow( hWnd );
4253 // -----------------------------------------------------------------------
4255 static void ImplCallClosePopupsHdl( HWND hWnd )
4257 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4258 if ( pFrame )
4260 pFrame->CallCallback( SALEVENT_CLOSEPOPUPS, 0 );
4264 // -----------------------------------------------------------------------
4266 static void ImplHandleMoveMsg( HWND hWnd )
4268 if ( ImplSalYieldMutexTryToAcquire() )
4270 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4271 if ( pFrame )
4273 UpdateFrameGeometry( hWnd, pFrame );
4275 if ( GetWindowStyle( hWnd ) & WS_VISIBLE )
4276 pFrame->mbDefPos = FALSE;
4278 // Gegen moegliche Rekursionen sichern
4279 if ( !pFrame->mbInMoveMsg )
4281 // Fenster im FullScreenModus wieder einpassen
4282 pFrame->mbInMoveMsg = TRUE;
4283 if ( pFrame->mbFullScreen )
4284 ImplSalFrameFullScreenPos( pFrame );
4285 pFrame->mbInMoveMsg = FALSE;
4288 // Status merken
4289 ImplSaveFrameState( pFrame );
4291 // Call Hdl
4292 //#93851 if we call this handler, VCL floating windows are not updated correctly
4293 ImplCallMoveHdl( hWnd );
4297 ImplSalYieldMutexRelease();
4299 else
4300 ImplPostMessage( hWnd, SAL_MSG_POSTMOVE, 0, 0 );
4303 // -----------------------------------------------------------------------
4305 static void ImplCallSizeHdl( HWND hWnd )
4307 // Da Windows diese Messages auch senden kann, muss hier auch die
4308 // Solar-Semaphore beruecksichtigt werden
4309 if ( ImplSalYieldMutexTryToAcquire() )
4311 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4312 if ( pFrame )
4314 pFrame->CallCallback( SALEVENT_RESIZE, 0 );
4315 // Um doppelte Paints von VCL und SAL zu vermeiden
4316 if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
4317 UpdateWindow( hWnd );
4320 ImplSalYieldMutexRelease();
4322 else
4323 ImplPostMessage( hWnd, SAL_MSG_POSTCALLSIZE, 0, 0 );
4326 // -----------------------------------------------------------------------
4328 static void ImplHandleSizeMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
4330 if ( (wParam != SIZE_MAXSHOW) && (wParam != SIZE_MAXHIDE) )
4332 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4333 if ( pFrame )
4335 UpdateFrameGeometry( hWnd, pFrame );
4337 pFrame->mnWidth = (int)LOWORD(lParam);
4338 pFrame->mnHeight = (int)HIWORD(lParam);
4339 // Status merken
4340 ImplSaveFrameState( pFrame );
4341 // Call Hdl
4342 ImplCallSizeHdl( hWnd );
4347 // -----------------------------------------------------------------------
4349 static void ImplHandleFocusMsg( HWND hWnd )
4351 if ( ImplSalYieldMutexTryToAcquire() )
4353 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4354 if ( pFrame && !WinSalFrame::mbInReparent )
4356 // Query the actual status
4357 if ( ::GetFocus() == hWnd )
4359 if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
4360 UpdateWindow( hWnd );
4362 // Feststellen, ob wir IME unterstuetzen
4363 if ( pFrame->mbIME && pFrame->mhDefIMEContext )
4365 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY );
4367 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
4368 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
4369 pFrame->mbHandleIME = !pFrame->mbSpezIME;
4372 pFrame->CallCallback( SALEVENT_GETFOCUS, 0 );
4374 else
4376 pFrame->CallCallback( SALEVENT_LOSEFOCUS, 0 );
4380 ImplSalYieldMutexRelease();
4382 else
4383 ImplPostMessage( hWnd, SAL_MSG_POSTFOCUS, 0, 0 );
4386 // -----------------------------------------------------------------------
4388 static void ImplHandleCloseMsg( HWND hWnd )
4390 if ( ImplSalYieldMutexTryToAcquire() )
4392 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4393 if ( pFrame )
4395 pFrame->CallCallback( SALEVENT_CLOSE, 0 );
4398 ImplSalYieldMutexRelease();
4400 else
4401 ImplPostMessage( hWnd, WM_CLOSE, 0, 0 );
4404 // -----------------------------------------------------------------------
4406 static long ImplHandleShutDownMsg( HWND hWnd )
4408 ImplSalYieldMutexAcquireWithWait();
4409 long nRet = 0;
4410 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4411 if ( pFrame )
4413 nRet = pFrame->CallCallback( SALEVENT_SHUTDOWN, 0 );
4415 ImplSalYieldMutexRelease();
4416 return nRet;
4419 // -----------------------------------------------------------------------
4421 static void ImplHandleSettingsChangeMsg( HWND hWnd, UINT nMsg,
4422 WPARAM wParam, LPARAM lParam )
4424 sal_uInt16 nSalEvent = SALEVENT_SETTINGSCHANGED;
4426 if ( nMsg == WM_DEVMODECHANGE )
4427 nSalEvent = SALEVENT_PRINTERCHANGED;
4428 else if ( nMsg == WM_DISPLAYCHANGE )
4429 nSalEvent = SALEVENT_DISPLAYCHANGED;
4430 else if ( nMsg == WM_FONTCHANGE )
4431 nSalEvent = SALEVENT_FONTCHANGED;
4432 else if ( nMsg == WM_TIMECHANGE )
4433 nSalEvent = SALEVENT_DATETIMECHANGED;
4434 else if ( nMsg == WM_WININICHANGE )
4436 if ( lParam )
4438 if ( ImplSalWICompareAscii( (const wchar_t*)lParam, "devices" ) == 0 )
4439 nSalEvent = SALEVENT_PRINTERCHANGED;
4443 if ( nMsg == WM_SETTINGCHANGE )
4445 if ( wParam == SPI_SETWHEELSCROLLLINES )
4446 aSalShlData.mnWheelScrollLines = ImplSalGetWheelScrollLines();
4447 else if( wParam == SPI_SETWHEELSCROLLCHARS )
4448 aSalShlData.mnWheelScrollChars = ImplSalGetWheelScrollChars();
4451 if ( WM_SYSCOLORCHANGE == nMsg && GetSalData()->mhDitherPal )
4452 ImplUpdateSysColorEntries();
4454 ImplSalYieldMutexAcquireWithWait();
4456 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4457 if ( pFrame )
4459 if ( (nMsg == WM_DISPLAYCHANGE) || (nMsg == WM_WININICHANGE) )
4461 if ( pFrame->mbFullScreen )
4462 ImplSalFrameFullScreenPos( pFrame );
4465 pFrame->CallCallback( nSalEvent, 0 );
4468 ImplSalYieldMutexRelease();
4471 // -----------------------------------------------------------------------
4473 static void ImplHandleUserEvent( HWND hWnd, LPARAM lParam )
4475 ImplSalYieldMutexAcquireWithWait();
4476 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4477 if ( pFrame )
4479 pFrame->CallCallback( SALEVENT_USEREVENT, (void*)lParam );
4481 ImplSalYieldMutexRelease();
4484 // -----------------------------------------------------------------------
4486 static void ImplHandleForcePalette( HWND hWnd )
4488 SalData* pSalData = GetSalData();
4489 HPALETTE hPal = pSalData->mhDitherPal;
4490 if ( hPal )
4492 if ( !ImplSalYieldMutexTryToAcquire() )
4494 ImplPostMessage( hWnd, SAL_MSG_FORCEPALETTE, 0, 0 );
4495 return;
4498 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4499 if ( pFrame && pFrame->mpGraphics )
4501 WinSalGraphics* pGraphics = pFrame->mpGraphics;
4502 if ( pGraphics && pGraphics->mhDefPal )
4504 SelectPalette( pGraphics->mhDC, hPal, FALSE );
4505 if ( RealizePalette( pGraphics->mhDC ) )
4507 InvalidateRect( hWnd, NULL, FALSE );
4508 UpdateWindow( hWnd );
4509 pFrame->CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
4514 ImplSalYieldMutexRelease();
4518 // -----------------------------------------------------------------------
4520 static LRESULT ImplHandlePalette( sal_Bool bFrame, HWND hWnd, UINT nMsg,
4521 WPARAM wParam, LPARAM lParam, int& rDef )
4523 SalData* pSalData = GetSalData();
4524 HPALETTE hPal = pSalData->mhDitherPal;
4525 if ( !hPal )
4526 return 0;
4528 rDef = FALSE;
4529 if ( pSalData->mbInPalChange )
4530 return 0;
4532 if ( (nMsg == WM_PALETTECHANGED) || (nMsg == SAL_MSG_POSTPALCHANGED) )
4534 if ( (HWND)wParam == hWnd )
4535 return 0;
4538 sal_Bool bReleaseMutex = FALSE;
4539 if ( (nMsg == WM_QUERYNEWPALETTE) || (nMsg == WM_PALETTECHANGED) )
4541 // Da Windows diese Messages auch sendet, muss hier auch die
4542 // Solar-Semaphore beruecksichtigt werden
4543 if ( ImplSalYieldMutexTryToAcquire() )
4544 bReleaseMutex = TRUE;
4545 else if ( nMsg == WM_QUERYNEWPALETTE )
4546 ImplPostMessage( hWnd, SAL_MSG_POSTQUERYNEWPAL, wParam, lParam );
4547 else /* ( nMsg == WM_PALETTECHANGED ) */
4548 ImplPostMessage( hWnd, SAL_MSG_POSTPALCHANGED, wParam, lParam );
4551 WinSalVirtualDevice*pTempVD;
4552 WinSalFrame* pTempFrame;
4553 WinSalGraphics* pGraphics;
4554 HDC hDC;
4555 HPALETTE hOldPal;
4556 UINT nCols;
4557 sal_Bool bStdDC;
4558 sal_Bool bUpdate;
4560 pSalData->mbInPalChange = TRUE;
4562 // Alle Paletten in VirDevs und Frames zuruecksetzen
4563 pTempVD = pSalData->mpFirstVD;
4564 while ( pTempVD )
4566 pGraphics = pTempVD->mpGraphics;
4567 if ( pGraphics->mhDefPal )
4569 SelectPalette( pGraphics->mhDC,
4570 pGraphics->mhDefPal,
4571 TRUE );
4573 pTempVD = pTempVD->mpNext;
4575 pTempFrame = pSalData->mpFirstFrame;
4576 while ( pTempFrame )
4578 pGraphics = pTempFrame->mpGraphics;
4579 if ( pGraphics && pGraphics->mhDefPal )
4581 SelectPalette( pGraphics->mhDC,
4582 pGraphics->mhDefPal,
4583 TRUE );
4585 pTempFrame = pTempFrame->mpNextFrame;
4588 // Palette neu realizen
4589 WinSalFrame* pFrame = NULL;
4590 if ( bFrame )
4591 pFrame = GetWindowPtr( hWnd );
4592 if ( pFrame && pFrame->mpGraphics )
4594 hDC = pFrame->mpGraphics->mhDC;
4595 bStdDC = TRUE;
4597 else
4599 hDC = GetDC( hWnd );
4600 bStdDC = FALSE;
4602 UnrealizeObject( hPal );
4603 hOldPal = SelectPalette( hDC, hPal, TRUE );
4604 nCols = RealizePalette( hDC );
4605 bUpdate = nCols != 0;
4606 if ( !bStdDC )
4608 SelectPalette( hDC, hOldPal, TRUE );
4609 ReleaseDC( hWnd, hDC );
4612 // Alle Paletten in VirDevs und Frames neu setzen
4613 pTempVD = pSalData->mpFirstVD;
4614 while ( pTempVD )
4616 pGraphics = pTempVD->mpGraphics;
4617 if ( pGraphics->mhDefPal )
4619 SelectPalette( pGraphics->mhDC, hPal, TRUE );
4620 RealizePalette( pGraphics->mhDC );
4622 pTempVD = pTempVD->mpNext;
4624 pTempFrame = pSalData->mpFirstFrame;
4625 while ( pTempFrame )
4627 if ( pTempFrame != pFrame )
4629 pGraphics = pTempFrame->mpGraphics;
4630 if ( pGraphics && pGraphics->mhDefPal )
4632 SelectPalette( pGraphics->mhDC, hPal, TRUE );
4633 if ( RealizePalette( pGraphics->mhDC ) )
4634 bUpdate = TRUE;
4637 pTempFrame = pTempFrame->mpNextFrame;
4640 // Wenn sich Farben geaendert haben, dann die Fenster updaten
4641 if ( bUpdate )
4643 pTempFrame = pSalData->mpFirstFrame;
4644 while ( pTempFrame )
4646 pGraphics = pTempFrame->mpGraphics;
4647 if ( pGraphics && pGraphics->mhDefPal )
4649 InvalidateRect( pTempFrame->mhWnd, NULL, FALSE );
4650 UpdateWindow( pTempFrame->mhWnd );
4651 pTempFrame->CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
4653 pTempFrame = pTempFrame->mpNextFrame;
4657 pSalData->mbInPalChange = FALSE;
4659 if ( bReleaseMutex )
4660 ImplSalYieldMutexRelease();
4662 if ( nMsg == WM_PALETTECHANGED )
4663 return 0;
4664 else
4665 return nCols;
4668 // -----------------------------------------------------------------------
4670 static int ImplHandleMinMax( HWND hWnd, LPARAM lParam )
4672 int bRet = FALSE;
4674 if ( ImplSalYieldMutexTryToAcquire() )
4676 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4677 if ( pFrame )
4679 MINMAXINFO* pMinMax = (MINMAXINFO*)lParam;
4681 if ( pFrame->mbFullScreen )
4683 int nX;
4684 int nY;
4685 int nDX;
4686 int nDY;
4687 ImplSalCalcFullScreenSize( pFrame, nX, nY, nDX, nDY );
4689 if ( pMinMax->ptMaxPosition.x > nX )
4690 pMinMax->ptMaxPosition.x = nX;
4691 if ( pMinMax->ptMaxPosition.y > nY )
4692 pMinMax->ptMaxPosition.y = nY;
4694 if ( pMinMax->ptMaxSize.x < nDX )
4695 pMinMax->ptMaxSize.x = nDX;
4696 if ( pMinMax->ptMaxSize.y < nDY )
4697 pMinMax->ptMaxSize.y = nDY;
4698 if ( pMinMax->ptMaxTrackSize.x < nDX )
4699 pMinMax->ptMaxTrackSize.x = nDX;
4700 if ( pMinMax->ptMaxTrackSize.y < nDY )
4701 pMinMax->ptMaxTrackSize.y = nDY;
4703 pMinMax->ptMinTrackSize.x = nDX;
4704 pMinMax->ptMinTrackSize.y = nDY;
4706 bRet = TRUE;
4709 if ( pFrame->mnMinWidth || pFrame->mnMinHeight )
4711 int nWidth = pFrame->mnMinWidth;
4712 int nHeight = pFrame->mnMinHeight;
4714 ImplSalAddBorder( pFrame, nWidth, nHeight );
4716 if ( pMinMax->ptMinTrackSize.x < nWidth )
4717 pMinMax->ptMinTrackSize.x = nWidth;
4718 if ( pMinMax->ptMinTrackSize.y < nHeight )
4719 pMinMax->ptMinTrackSize.y = nHeight;
4722 if ( pFrame->mnMaxWidth || pFrame->mnMaxHeight )
4724 int nWidth = pFrame->mnMaxWidth;
4725 int nHeight = pFrame->mnMaxHeight;
4727 ImplSalAddBorder( pFrame, nWidth, nHeight );
4729 if( nWidth > 0 && nHeight > 0 ) // protect against int overflow due to INT_MAX initialisation
4731 if ( pMinMax->ptMaxTrackSize.x > nWidth )
4732 pMinMax->ptMaxTrackSize.x = nWidth;
4733 if ( pMinMax->ptMaxTrackSize.y > nHeight )
4734 pMinMax->ptMaxTrackSize.y = nHeight;
4739 ImplSalYieldMutexRelease();
4742 return bRet;
4745 // -----------------------------------------------------------------------
4747 // retrieves the SalMenuItem pointer from a hMenu
4748 // the pointer is stored in every item, so if no position
4749 // is specified we just use the first item (ie, pos=0)
4750 // if bByPosition is FALSE then nPos denotes a menu id instead of a position
4751 static WinSalMenuItem* ImplGetSalMenuItem( HMENU hMenu, UINT nPos, sal_Bool bByPosition=TRUE )
4753 DWORD err=0;
4755 MENUITEMINFOW mi;
4756 memset(&mi, 0, sizeof(mi));
4757 mi.cbSize = sizeof( mi );
4758 mi.fMask = MIIM_DATA;
4759 if( !GetMenuItemInfoW( hMenu, nPos, bByPosition, &mi) )
4760 err = GetLastError();
4762 return (WinSalMenuItem *) mi.dwItemData;
4765 // returns the index of the currently selected item if any or -1
4766 static int ImplGetSelectedIndex( HMENU hMenu )
4768 DWORD err=0;
4770 MENUITEMINFOW mi;
4771 memset(&mi, 0, sizeof(mi));
4772 mi.cbSize = sizeof( mi );
4773 mi.fMask = MIIM_STATE;
4774 int n = GetMenuItemCount( hMenu );
4775 if( n != -1 )
4777 for(int i=0; i<n; i++ )
4779 if( !GetMenuItemInfoW( hMenu, i, TRUE, &mi) )
4780 err = GetLastError();
4781 else
4783 if( mi.fState & MFS_HILITE )
4784 return i;
4788 return -1;
4791 static int ImplMenuChar( HWND, WPARAM wParam, LPARAM lParam )
4793 int nRet = MNC_IGNORE;
4794 HMENU hMenu = (HMENU) lParam;
4795 String aMnemonic;
4796 aMnemonic.AssignAscii("&");
4797 aMnemonic.Append( (sal_Unicode) LOWORD(wParam) );
4798 aMnemonic.ToLowerAscii(); // we only have ascii mnemonics
4800 // search the mnemonic in the current menu
4801 int nItemCount = GetMenuItemCount( hMenu );
4802 int nFound = 0;
4803 int idxFound = -1;
4804 int idxSelected = ImplGetSelectedIndex( hMenu );
4805 int idx = idxSelected != -1 ? idxSelected+1 : 0; // if duplicate mnemonics cycle through menu
4806 for( int i=0; i< nItemCount; i++, idx++ )
4808 WinSalMenuItem* pSalMenuItem = ImplGetSalMenuItem( hMenu, idx % nItemCount );
4809 if( !pSalMenuItem )
4810 continue;
4811 String aStr = pSalMenuItem->mText;
4812 aStr.ToLowerAscii();
4813 if( aStr.Search( aMnemonic ) != STRING_NOTFOUND)
4815 if( idxFound == -1 )
4816 idxFound = idx % nItemCount;
4817 if( nFound++ )
4818 break; // duplicate found
4821 if( nFound == 1 )
4822 nRet = MAKELRESULT( idxFound, MNC_EXECUTE );
4823 else
4824 // duplicate mnemonics, just select the next occurence
4825 nRet = MAKELRESULT( idxFound, MNC_SELECT );
4827 return nRet;
4830 static int ImplMeasureItem( HWND hWnd, WPARAM wParam, LPARAM lParam )
4832 int nRet = 0;
4833 if( !wParam )
4835 // request was sent by a menu
4836 nRet = 1;
4837 MEASUREITEMSTRUCT *pMI = (LPMEASUREITEMSTRUCT) lParam;
4838 if( pMI->CtlType != ODT_MENU )
4839 return 0;
4841 WinSalMenuItem *pSalMenuItem = (WinSalMenuItem *) pMI->itemData;
4842 if( !pSalMenuItem )
4843 return 0;
4845 HDC hdc = GetDC( hWnd );
4846 SIZE strSize;
4848 NONCLIENTMETRICS ncm;
4849 memset( &ncm, 0, sizeof(ncm) );
4850 ncm.cbSize = sizeof( ncm );
4851 SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, (PVOID) &ncm, 0 );
4853 // Assume every menu item can be default and printed bold
4854 //ncm.lfMenuFont.lfWeight = FW_BOLD;
4856 HFONT hfntOld = (HFONT) SelectObject(hdc, (HFONT) CreateFontIndirect( &ncm.lfMenuFont ));
4858 // menu text and accelerator
4859 String aStr(pSalMenuItem->mText.GetBuffer() );
4860 if( pSalMenuItem->mAccelText.Len() )
4862 aStr.AppendAscii(" ");
4863 aStr.Append( pSalMenuItem->mAccelText );
4865 GetTextExtentPoint32W( hdc, (LPWSTR) aStr.GetBuffer(),
4866 aStr.Len(), &strSize );
4868 // image
4869 Size bmpSize( 16, 16 );
4870 //if( !!pSalMenuItem->maBitmap )
4871 // bmpSize = pSalMenuItem->maBitmap.GetSizePixel();
4873 // checkmark
4874 Size checkSize( GetSystemMetrics( SM_CXMENUCHECK ), GetSystemMetrics( SM_CYMENUCHECK ) );
4876 pMI->itemWidth = checkSize.Width() + 3 + bmpSize.Width() + 3 + strSize.cx;
4877 pMI->itemHeight = Max( Max( checkSize.Height(), bmpSize.Height() ), strSize.cy );
4878 pMI->itemHeight += 4;
4880 DeleteObject( SelectObject(hdc, hfntOld) );
4881 ReleaseDC( hWnd, hdc );
4884 return nRet;
4887 static int ImplDrawItem(HWND, WPARAM wParam, LPARAM lParam )
4889 int nRet = 0;
4890 DWORD err = 0;
4891 if( !wParam )
4893 // request was sent by a menu
4894 nRet = 1;
4895 DRAWITEMSTRUCT *pDI = (LPDRAWITEMSTRUCT) lParam;
4896 if( pDI->CtlType != ODT_MENU )
4897 return 0;
4899 WinSalMenuItem *pSalMenuItem = (WinSalMenuItem *) pDI->itemData;
4900 if( !pSalMenuItem )
4901 return 0;
4903 COLORREF clrPrevText, clrPrevBkgnd;
4904 HFONT hfntOld;
4905 HBRUSH hbrOld;
4906 sal_Bool fChecked = (pDI->itemState & ODS_CHECKED) ? TRUE : FALSE;
4907 sal_Bool fSelected = (pDI->itemState & ODS_SELECTED) ? TRUE : FALSE;
4908 sal_Bool fDisabled = (pDI->itemState & (ODS_DISABLED | ODS_GRAYED)) ? TRUE : FALSE;
4910 // Set the appropriate foreground and background colors.
4911 RECT aRect = pDI->rcItem;
4913 clrPrevBkgnd = SetBkColor( pDI->hDC, GetSysColor( COLOR_MENU ) );
4915 if ( fDisabled )
4916 clrPrevText = SetTextColor( pDI->hDC, GetSysColor( COLOR_GRAYTEXT ) );
4917 else
4918 clrPrevText = SetTextColor( pDI->hDC, GetSysColor( fSelected ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT ) );
4920 DWORD colBackground = GetSysColor( fSelected ? COLOR_HIGHLIGHT : COLOR_MENU );
4921 if ( fSelected )
4922 clrPrevBkgnd = SetBkColor( pDI->hDC, colBackground );
4923 else
4924 clrPrevBkgnd = SetBkColor( pDI->hDC, colBackground );
4926 hbrOld = (HBRUSH)SelectObject( pDI->hDC, CreateSolidBrush( GetBkColor( pDI->hDC ) ) );
4928 // Fill background
4929 if(!PatBlt( pDI->hDC, aRect.left, aRect.top, aRect.right-aRect.left, aRect.bottom-aRect.top, PATCOPY ))
4930 err = GetLastError();
4932 int lineHeight = aRect.bottom-aRect.top;
4934 int x = aRect.left;
4935 int y = aRect.top;
4937 int checkWidth = GetSystemMetrics( SM_CXMENUCHECK );
4938 int checkHeight = GetSystemMetrics( SM_CYMENUCHECK );
4939 if( fChecked )
4941 RECT r;
4942 r.left = 0;
4943 r.top = 0;
4944 r.right = checkWidth;
4945 r.bottom = checkWidth;
4946 HDC memDC = CreateCompatibleDC( pDI->hDC );
4947 HBITMAP memBmp = CreateCompatibleBitmap( pDI->hDC, checkWidth, checkHeight );
4948 HBITMAP hOldBmp = (HBITMAP) SelectObject( memDC, memBmp );
4949 DrawFrameControl( memDC, &r, DFC_MENU, DFCS_MENUCHECK );
4950 BitBlt( pDI->hDC, x, y+(lineHeight-checkHeight)/2, checkWidth, checkHeight, memDC, 0, 0, SRCAND );
4951 DeleteObject( SelectObject( memDC, hOldBmp ) );
4952 DeleteDC( memDC );
4954 x += checkWidth+3;
4956 //Size bmpSize = aBitmap.GetSizePixel();
4957 Size bmpSize(16, 16);
4958 if( !!pSalMenuItem->maBitmap )
4960 Bitmap aBitmap( pSalMenuItem->maBitmap );
4962 // set transparent pixels to background color
4963 if( fDisabled )
4964 colBackground = RGB(255,255,255);
4965 aBitmap.Replace( Color( COL_LIGHTMAGENTA ),
4966 Color( GetRValue(colBackground),GetGValue(colBackground),GetBValue(colBackground) ), 0);
4968 WinSalBitmap* pSalBmp = static_cast<WinSalBitmap*>(aBitmap.ImplGetImpBitmap()->ImplGetSalBitmap());
4969 HGLOBAL hDrawDIB = pSalBmp->ImplGethDIB();
4971 if( hDrawDIB )
4973 PBITMAPINFO pBI = (PBITMAPINFO) GlobalLock( hDrawDIB );
4974 PBITMAPINFOHEADER pBIH = (PBITMAPINFOHEADER) pBI;
4975 PBYTE pBits = (PBYTE) pBI + *(DWORD*) pBI +
4976 pSalBmp->ImplGetDIBColorCount( hDrawDIB ) * sizeof( RGBQUAD );
4978 HBITMAP hBmp = CreateDIBitmap( pDI->hDC, pBIH, CBM_INIT, pBits, pBI, DIB_RGB_COLORS );
4979 GlobalUnlock( hDrawDIB );
4981 HBRUSH hbrIcon = CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT ) );
4982 DrawStateW( pDI->hDC, (HBRUSH)hbrIcon, (DRAWSTATEPROC)NULL, (LPARAM)hBmp, (WPARAM)0,
4983 x, y+(lineHeight-bmpSize.Height())/2, bmpSize.Width(), bmpSize.Height(),
4984 DST_BITMAP | (fDisabled ? (fSelected ? DSS_MONO : DSS_DISABLED) : DSS_NORMAL) );
4986 DeleteObject( hbrIcon );
4987 DeleteObject( hBmp );
4991 x += bmpSize.Width() + 3;
4992 aRect.left = x;
4994 NONCLIENTMETRICS ncm;
4995 memset( &ncm, 0, sizeof(ncm) );
4996 ncm.cbSize = sizeof( ncm );
4997 SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, (PVOID) &ncm, 0 );
4999 // Print default menu entry with bold font
5000 //if ( pDI->itemState & ODS_DEFAULT )
5001 // ncm.lfMenuFont.lfWeight = FW_BOLD;
5003 hfntOld = (HFONT) SelectObject(pDI->hDC, (HFONT) CreateFontIndirect( &ncm.lfMenuFont ));
5005 SIZE strSize;
5006 String aStr( pSalMenuItem->mText.GetBuffer() );
5007 GetTextExtentPoint32W( pDI->hDC, (LPWSTR) aStr.GetBuffer(),
5008 aStr.Len(), &strSize );
5010 if(!DrawStateW( pDI->hDC, (HBRUSH)NULL, (DRAWSTATEPROC)NULL,
5011 (LPARAM)(LPWSTR) aStr.GetBuffer(),
5012 (WPARAM)0, aRect.left, aRect.top + (lineHeight - strSize.cy)/2, 0, 0,
5013 DST_PREFIXTEXT | (fDisabled && !fSelected ? DSS_DISABLED : DSS_NORMAL) ) )
5014 err = GetLastError();
5016 if( pSalMenuItem->mAccelText.Len() )
5018 SIZE strSizeA;
5019 aStr = pSalMenuItem->mAccelText;
5020 GetTextExtentPoint32W( pDI->hDC, (LPWSTR) aStr.GetBuffer(),
5021 aStr.Len(), &strSizeA );
5022 TEXTMETRIC tm;
5023 GetTextMetrics( pDI->hDC, &tm );
5025 // position the accelerator string to the right but leave space for the
5026 // (potential) submenu arrow (tm.tmMaxCharWidth)
5027 if(!DrawStateW( pDI->hDC, (HBRUSH)NULL, (DRAWSTATEPROC)NULL,
5028 (LPARAM)(LPWSTR) aStr.GetBuffer(),
5029 (WPARAM)0, aRect.right-strSizeA.cx-tm.tmMaxCharWidth, aRect.top + (lineHeight - strSizeA.cy)/2, 0, 0,
5030 DST_TEXT | (fDisabled && !fSelected ? DSS_DISABLED : DSS_NORMAL) ) )
5031 err = GetLastError();
5034 // Restore the original font and colors.
5035 DeleteObject( SelectObject( pDI->hDC, hbrOld ) );
5036 DeleteObject( SelectObject( pDI->hDC, hfntOld) );
5037 SetTextColor(pDI->hDC, clrPrevText);
5038 SetBkColor(pDI->hDC, clrPrevBkgnd);
5040 return nRet;
5043 static int ImplHandleMenuActivate( HWND hWnd, WPARAM wParam, LPARAM )
5045 // Menu activation
5046 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5047 if ( !pFrame )
5048 return 0;
5050 HMENU hMenu = (HMENU) wParam;
5051 // WORD nPos = LOWORD (lParam);
5052 // sal_Bool bWindowMenu = (sal_Bool) HIWORD(lParam);
5054 // Send activate and deactivate together, so we have not keep track of opened menues
5055 // this will be enough to have the menues updated correctly
5056 SalMenuEvent aMenuEvt;
5057 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, 0 );
5058 if( pSalMenuItem )
5059 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
5060 else
5061 aMenuEvt.mpMenu = NULL;
5063 long nRet = pFrame->CallCallback( SALEVENT_MENUACTIVATE, &aMenuEvt );
5064 if( nRet )
5065 nRet = pFrame->CallCallback( SALEVENT_MENUDEACTIVATE, &aMenuEvt );
5066 if( nRet )
5067 pFrame->mLastActivatedhMenu = hMenu;
5069 return (nRet!=0);
5072 static int ImplHandleMenuSelect( HWND hWnd, WPARAM wParam, LPARAM lParam )
5074 // Menu selection
5075 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5076 if ( !pFrame )
5077 return 0;
5079 WORD nId = LOWORD(wParam); // menu item or submenu index
5080 WORD nFlags = HIWORD(wParam);
5081 HMENU hMenu = (HMENU) lParam;
5083 // check if we have to process the message
5084 if( !GetSalData()->IsKnownMenuHandle( hMenu ) )
5085 return 0;
5087 sal_Bool bByPosition = FALSE;
5088 if( nFlags & MF_POPUP )
5089 bByPosition = TRUE;
5091 long nRet = 0;
5092 if ( hMenu && !pFrame->mLastActivatedhMenu )
5094 // we never activated a menu (ie, no WM_INITMENUPOPUP has occured yet)
5095 // which means this must be the menubar -> send activation/deactivation
5096 SalMenuEvent aMenuEvt;
5097 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, nId, bByPosition );
5098 if( pSalMenuItem )
5099 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
5100 else
5101 aMenuEvt.mpMenu = NULL;
5103 nRet = pFrame->CallCallback( SALEVENT_MENUACTIVATE, &aMenuEvt );
5104 if( nRet )
5105 nRet = pFrame->CallCallback( SALEVENT_MENUDEACTIVATE, &aMenuEvt );
5106 if( nRet )
5107 pFrame->mLastActivatedhMenu = hMenu;
5110 if( !hMenu && nFlags == 0xFFFF )
5112 // all menus are closed, reset activation logic
5113 pFrame->mLastActivatedhMenu = NULL;
5116 if( hMenu )
5118 // hMenu must be saved, as it is not passed in WM_COMMAND which always occurs after a selection
5119 // if a menu is closed due to a command selection then hMenu is NULL, but WM_COMMAND comes later
5120 // so we must not overwrite it in this case
5121 pFrame->mSelectedhMenu = hMenu;
5123 // send highlight event
5124 if( nFlags & MF_POPUP )
5126 // submenu selected
5127 // wParam now carries an index instead of an id -> retrieve id
5128 MENUITEMINFOW mi;
5129 memset(&mi, 0, sizeof(mi));
5130 mi.cbSize = sizeof( mi );
5131 mi.fMask = MIIM_ID;
5132 if( GetMenuItemInfoW( hMenu, LOWORD(wParam), TRUE, &mi) )
5133 nId = sal::static_int_cast<WORD>(mi.wID);
5136 SalMenuEvent aMenuEvt;
5137 aMenuEvt.mnId = nId;
5138 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, nId, FALSE );
5139 if( pSalMenuItem )
5140 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
5141 else
5142 aMenuEvt.mpMenu = NULL;
5144 nRet = pFrame->CallCallback( SALEVENT_MENUHIGHLIGHT, &aMenuEvt );
5147 return (nRet != 0);
5150 static int ImplHandleCommand( HWND hWnd, WPARAM wParam, LPARAM )
5152 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5153 if ( !pFrame )
5154 return 0;
5156 long nRet = 0;
5157 if( !HIWORD(wParam) )
5159 // Menu command
5160 WORD nId = LOWORD(wParam);
5161 if( nId ) // zero for separators
5163 SalMenuEvent aMenuEvt;
5164 aMenuEvt.mnId = nId;
5165 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( pFrame->mSelectedhMenu, nId, FALSE );
5166 if( pSalMenuItem )
5167 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
5168 else
5169 aMenuEvt.mpMenu = NULL;
5171 nRet = pFrame->CallCallback( SALEVENT_MENUCOMMAND, &aMenuEvt );
5174 return (nRet != 0);
5177 static int ImplHandleSysCommand( HWND hWnd, WPARAM wParam, LPARAM lParam )
5179 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5180 if ( !pFrame )
5181 return 0;
5183 WPARAM nCommand = wParam & 0xFFF0;
5185 if ( pFrame->mbFullScreen )
5187 BOOL bMaximize = IsZoomed( pFrame->mhWnd );
5188 BOOL bMinimize = IsIconic( pFrame->mhWnd );
5189 if ( (nCommand == SC_SIZE) ||
5190 (!bMinimize && (nCommand == SC_MOVE)) ||
5191 (!bMaximize && (nCommand == SC_MAXIMIZE)) ||
5192 (bMaximize && (nCommand == SC_RESTORE)) )
5194 MessageBeep( 0 );
5195 return TRUE;
5199 if ( nCommand == SC_KEYMENU )
5201 // do not process SC_KEYMENU if we have a native menu
5202 // Windows should handle this
5203 if( GetMenu( hWnd ) )
5204 return FALSE;
5206 // Hier verarbeiten wir nur KeyMenu-Events fuer Alt um
5207 // den MenuBar zu aktivieren, oder wenn ein SysChild-Fenster
5208 // den Focus hat, da diese Alt+Tasten-Kombinationen nur
5209 // ueber diesen Event verarbeitet werden
5210 if ( !LOWORD( lParam ) )
5212 // Nur ausloesen, wenn keine weitere Taste gedrueckt ist. Im
5213 // Gegensatz zur Doku wird in der X-Koordinaate der CharCode
5214 // geliefert, der zusaetzlich gedrueckt ist
5215 // Also 32 fuer Space, 99 fuer c, 100 fuer d, ...
5216 // Da dies nicht dokumentiert ist, fragen wir vorsichtshalber
5217 // auch den Status der Space-Taste ab
5218 if ( GetKeyState( VK_SPACE ) & 0x8000 )
5219 return 0;
5221 // Damit nicht bei Alt+Maustaste auch der MenuBar aktiviert wird
5222 if ( (GetKeyState( VK_LBUTTON ) & 0x8000) ||
5223 (GetKeyState( VK_RBUTTON ) & 0x8000) ||
5224 (GetKeyState( VK_MBUTTON ) & 0x8000) ||
5225 (GetKeyState( VK_SHIFT ) & 0x8000) )
5226 return 1;
5228 SalKeyEvent aKeyEvt;
5229 aKeyEvt.mnTime = GetMessageTime();
5230 aKeyEvt.mnCode = KEY_MENU;
5231 aKeyEvt.mnCharCode = 0;
5232 aKeyEvt.mnRepeat = 0;
5233 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
5234 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
5235 return (nRet != 0);
5237 else
5239 // Testen, ob ein SysChild den Focus hat
5240 HWND hFocusWnd = ::GetFocus();
5241 if ( hFocusWnd && ImplFindSalObject( hFocusWnd ) )
5243 char cKeyCode = (char)(unsigned char)LOWORD( lParam );
5244 // LowerCase
5245 if ( (cKeyCode >= 65) && (cKeyCode <= 90) )
5246 cKeyCode += 32;
5247 // Wir nehmen nur 0-9 und A-Z, alle anderen Tasten muessen durch
5248 // den Hook vom SalObj verarbeitet werden
5249 if ( ((cKeyCode >= 48) && (cKeyCode <= 57)) ||
5250 ((cKeyCode >= 97) && (cKeyCode <= 122)) )
5252 sal_uInt16 nModCode = 0;
5253 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
5254 nModCode |= KEY_SHIFT;
5255 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
5256 nModCode |= KEY_MOD1;
5257 nModCode |= KEY_MOD2;
5259 SalKeyEvent aKeyEvt;
5260 aKeyEvt.mnTime = GetMessageTime();
5261 if ( (cKeyCode >= 48) && (cKeyCode <= 57) )
5262 aKeyEvt.mnCode = KEY_0+(cKeyCode-48);
5263 else
5264 aKeyEvt.mnCode = KEY_A+(cKeyCode-97);
5265 aKeyEvt.mnCode |= nModCode;
5266 aKeyEvt.mnCharCode = cKeyCode;
5267 aKeyEvt.mnRepeat = 0;
5268 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
5269 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
5270 return (nRet != 0);
5276 return FALSE;
5279 // -----------------------------------------------------------------------
5281 static void ImplHandleInputLangChange( HWND hWnd, WPARAM, LPARAM lParam )
5283 ImplSalYieldMutexAcquireWithWait();
5285 // Feststellen, ob wir IME unterstuetzen
5286 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5287 if ( pFrame && pFrame->mbIME && pFrame->mhDefIMEContext )
5289 HKL hKL = (HKL)lParam;
5290 UINT nImeProps = ImmGetProperty( hKL, IGP_PROPERTY );
5292 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
5293 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
5294 pFrame->mbHandleIME = !pFrame->mbSpezIME;
5297 // trigger input language and codepage update
5298 UINT nLang = pFrame->mnInputLang;
5299 ImplUpdateInputLang( pFrame );
5301 // notify change
5302 if( nLang != pFrame->mnInputLang )
5303 pFrame->CallCallback( SALEVENT_INPUTLANGUAGECHANGE, 0 );
5305 ImplSalYieldMutexRelease();
5308 // -----------------------------------------------------------------------
5310 static void ImplUpdateIMECursorPos( WinSalFrame* pFrame, HIMC hIMC )
5312 COMPOSITIONFORM aForm;
5313 memset( &aForm, 0, sizeof( aForm ) );
5315 // Cursor-Position ermitteln und aus der die Default-Position fuer
5316 // das Composition-Fenster berechnen
5317 SalExtTextInputPosEvent aPosEvt;
5318 pFrame->CallCallback( SALEVENT_EXTTEXTINPUTPOS, (void*)&aPosEvt );
5319 if ( (aPosEvt.mnX == -1) && (aPosEvt.mnY == -1) )
5320 aForm.dwStyle |= CFS_DEFAULT;
5321 else
5323 aForm.dwStyle |= CFS_POINT;
5324 aForm.ptCurrentPos.x = aPosEvt.mnX;
5325 aForm.ptCurrentPos.y = aPosEvt.mnY;
5327 ImmSetCompositionWindow( hIMC, &aForm );
5329 // Because not all IME's use this values, we create
5330 // a Windows caret to force the Position from the IME
5331 if ( GetFocus() == pFrame->mhWnd )
5333 CreateCaret( pFrame->mhWnd, 0,
5334 aPosEvt.mnWidth, aPosEvt.mnHeight );
5335 SetCaretPos( aPosEvt.mnX, aPosEvt.mnY );
5339 // -----------------------------------------------------------------------
5341 static sal_Bool ImplHandleIMEStartComposition( HWND hWnd )
5343 sal_Bool bDef = TRUE;
5345 ImplSalYieldMutexAcquireWithWait();
5347 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5348 if ( pFrame )
5350 HIMC hIMC = ImmGetContext( hWnd );
5351 if ( hIMC )
5353 ImplUpdateIMECursorPos( pFrame, hIMC );
5354 ImmReleaseContext( hWnd, hIMC );
5357 if ( pFrame->mbHandleIME )
5359 if ( pFrame->mbAtCursorIME )
5360 bDef = FALSE;
5364 ImplSalYieldMutexRelease();
5366 return bDef;
5369 // -----------------------------------------------------------------------
5371 static sal_Bool ImplHandleIMECompositionInput( WinSalFrame* pFrame,
5372 HIMC hIMC, LPARAM lParam )
5374 sal_Bool bDef = TRUE;
5376 // Init Event
5377 SalExtTextInputEvent aEvt;
5378 aEvt.mnTime = GetMessageTime();
5379 aEvt.mpTextAttr = NULL;
5380 aEvt.mnCursorPos = 0;
5381 aEvt.mnDeltaStart = 0;
5382 aEvt.mbOnlyCursor = FALSE;
5383 aEvt.mnCursorFlags = 0;
5385 // If we get a result string, then we handle this input
5386 if ( lParam & GCS_RESULTSTR )
5388 bDef = FALSE;
5390 LONG nTextLen = ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, 0, 0 ) / sizeof( WCHAR );
5391 if ( nTextLen >= 0 )
5393 WCHAR* pTextBuf = new WCHAR[nTextLen];
5394 ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, pTextBuf, nTextLen*sizeof( WCHAR ) );
5395 aEvt.maText = XubString( reinterpret_cast<const xub_Unicode*>(pTextBuf), (xub_StrLen)nTextLen );
5396 delete [] pTextBuf;
5399 aEvt.mnCursorPos = aEvt.maText.Len();
5400 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
5401 pFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, (void*)NULL );
5402 ImplUpdateIMECursorPos( pFrame, hIMC );
5405 // If the IME doesn't support OnSpot input, then there is nothing to do
5406 if ( !pFrame->mbAtCursorIME )
5407 return !bDef;
5409 // If we get new Composition data, then we handle this new input
5410 if ( (lParam & (GCS_COMPSTR | GCS_COMPATTR)) ||
5411 ((lParam & GCS_CURSORPOS) && !(lParam & GCS_RESULTSTR)) )
5413 bDef = FALSE;
5415 sal_uInt16* pSalAttrAry = NULL;
5416 LONG nTextLen = ImmGetCompositionStringW( hIMC, GCS_COMPSTR, 0, 0 ) / sizeof( WCHAR );
5417 if ( nTextLen > 0 )
5419 WCHAR* pTextBuf = new WCHAR[nTextLen];
5420 ImmGetCompositionStringW( hIMC, GCS_COMPSTR, pTextBuf, nTextLen*sizeof( WCHAR ) );
5421 aEvt.maText = XubString( reinterpret_cast<const xub_Unicode*>(pTextBuf), (xub_StrLen)nTextLen );
5422 delete [] pTextBuf;
5424 BYTE* pAttrBuf = NULL;
5425 LONG nAttrLen = ImmGetCompositionStringW( hIMC, GCS_COMPATTR, 0, 0 );
5426 if ( nAttrLen > 0 )
5428 pAttrBuf = new BYTE[nAttrLen];
5429 ImmGetCompositionStringW( hIMC, GCS_COMPATTR, pAttrBuf, nAttrLen );
5432 if ( pAttrBuf )
5434 xub_StrLen nTextLen = aEvt.maText.Len();
5435 pSalAttrAry = new sal_uInt16[nTextLen];
5436 memset( pSalAttrAry, 0, nTextLen*sizeof( sal_uInt16 ) );
5437 for ( xub_StrLen i = 0; (i < nTextLen) && (i < nAttrLen); i++ )
5439 BYTE nWinAttr = pAttrBuf[i];
5440 sal_uInt16 nSalAttr;
5441 if ( nWinAttr == ATTR_TARGET_CONVERTED )
5443 nSalAttr = SAL_EXTTEXTINPUT_ATTR_BOLDUNDERLINE;
5444 aEvt.mnCursorFlags |= SAL_EXTTEXTINPUT_CURSOR_INVISIBLE;
5446 else if ( nWinAttr == ATTR_CONVERTED )
5447 nSalAttr = SAL_EXTTEXTINPUT_ATTR_DASHDOTUNDERLINE;
5448 else if ( nWinAttr == ATTR_TARGET_NOTCONVERTED )
5449 nSalAttr = SAL_EXTTEXTINPUT_ATTR_HIGHLIGHT;
5450 else if ( nWinAttr == ATTR_INPUT_ERROR )
5451 nSalAttr = SAL_EXTTEXTINPUT_ATTR_REDTEXT | SAL_EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE;
5452 else /* ( nWinAttr == ATTR_INPUT ) */
5453 nSalAttr = SAL_EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE;
5454 pSalAttrAry[i] = nSalAttr;
5457 aEvt.mpTextAttr = pSalAttrAry;
5458 delete [] pAttrBuf;
5462 // Only when we get new composition data, we must send this event
5463 if ( (nTextLen > 0) || !(lParam & GCS_RESULTSTR) )
5465 // End the mode, if the last character is deleted
5466 if ( !nTextLen && !pFrame->mbCandidateMode )
5468 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
5469 pFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, (void*)NULL );
5471 else
5473 // Because Cursor-Position and DeltaStart never updated
5474 // from the korean input engine, we must handle this here
5475 if ( lParam & CS_INSERTCHAR )
5477 aEvt.mnCursorPos = nTextLen;
5478 if ( aEvt.mnCursorPos && (lParam & CS_NOMOVECARET) )
5479 aEvt.mnCursorPos--;
5481 else
5482 aEvt.mnCursorPos = LOWORD( ImmGetCompositionStringW( hIMC, GCS_CURSORPOS, 0, 0 ) );
5484 if ( pFrame->mbCandidateMode )
5485 aEvt.mnCursorFlags |= SAL_EXTTEXTINPUT_CURSOR_INVISIBLE;
5486 if ( lParam & CS_NOMOVECARET )
5487 aEvt.mnCursorFlags |= SAL_EXTTEXTINPUT_CURSOR_OVERWRITE;
5489 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
5491 ImplUpdateIMECursorPos( pFrame, hIMC );
5494 if ( pSalAttrAry )
5495 delete [] pSalAttrAry;
5498 return !bDef;
5501 // -----------------------------------------------------------------------
5503 static sal_Bool ImplHandleIMEComposition( HWND hWnd, LPARAM lParam )
5505 sal_Bool bDef = TRUE;
5506 ImplSalYieldMutexAcquireWithWait();
5508 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5509 if ( pFrame && (!lParam || (lParam & GCS_RESULTSTR)) )
5511 // Wir restaurieren den Background-Modus bei jeder Texteingabe,
5512 // da einige Tools wie RichWin uns diesen hin- und wieder umsetzen
5513 if ( pFrame->mpGraphics &&
5514 pFrame->mpGraphics->mhDC )
5515 SetBkMode( pFrame->mpGraphics->mhDC, TRANSPARENT );
5518 if ( pFrame && pFrame->mbHandleIME )
5520 if ( !lParam )
5522 SalExtTextInputEvent aEvt;
5523 aEvt.mnTime = GetMessageTime();
5524 aEvt.mpTextAttr = NULL;
5525 aEvt.mnCursorPos = 0;
5526 aEvt.mnDeltaStart = 0;
5527 aEvt.mbOnlyCursor = FALSE;
5528 aEvt.mnCursorFlags = 0;
5529 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
5530 pFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, (void*)NULL );
5532 else if ( lParam & (GCS_RESULTSTR | GCS_COMPSTR | GCS_COMPATTR | GCS_CURSORPOS) )
5534 HIMC hIMC = ImmGetContext( hWnd );
5535 if ( hIMC )
5537 if ( ImplHandleIMECompositionInput( pFrame, hIMC, lParam ) )
5538 bDef = FALSE;
5540 ImmReleaseContext( hWnd, hIMC );
5545 ImplSalYieldMutexRelease();
5546 return bDef;
5549 // -----------------------------------------------------------------------
5551 static sal_Bool ImplHandleIMEEndComposition( HWND hWnd )
5553 sal_Bool bDef = TRUE;
5555 ImplSalYieldMutexAcquireWithWait();
5557 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5558 if ( pFrame && pFrame->mbHandleIME )
5560 if ( pFrame->mbAtCursorIME )
5561 bDef = FALSE;
5564 ImplSalYieldMutexRelease();
5566 return bDef;
5569 // -----------------------------------------------------------------------
5571 static boolean ImplHandleAppCommand( HWND hWnd, LPARAM lParam )
5573 sal_Int16 nCommand = 0;
5574 switch( GET_APPCOMMAND_LPARAM(lParam) )
5576 case APPCOMMAND_MEDIA_CHANNEL_DOWN: nCommand = MEDIA_COMMAND_CHANNEL_DOWN; break;
5577 case APPCOMMAND_MEDIA_CHANNEL_UP: nCommand = MEDIA_COMMAND_CHANNEL_UP; break;
5578 case APPCOMMAND_MEDIA_NEXTTRACK: nCommand = MEDIA_COMMAND_NEXTTRACK; break;
5579 case APPCOMMAND_MEDIA_PAUSE: nCommand = MEDIA_COMMAND_PAUSE; break;
5580 case APPCOMMAND_MEDIA_PLAY: nCommand = MEDIA_COMMAND_PLAY; break;
5581 case APPCOMMAND_MEDIA_PLAY_PAUSE: nCommand = MEDIA_COMMAND_PLAY_PAUSE; break;
5582 case APPCOMMAND_MEDIA_PREVIOUSTRACK: nCommand = MEDIA_COMMAND_PREVIOUSTRACK; break;
5583 case APPCOMMAND_MEDIA_RECORD: nCommand = MEDIA_COMMAND_RECORD; break;
5584 case APPCOMMAND_MEDIA_REWIND: nCommand = MEDIA_COMMAND_REWIND; break;
5585 case APPCOMMAND_MEDIA_STOP: nCommand = MEDIA_COMMAND_STOP; break;
5586 case APPCOMMAND_MIC_ON_OFF_TOGGLE: nCommand = MEDIA_COMMAND_MIC_ON_OFF_TOGGLE; break;
5587 case APPCOMMAND_MICROPHONE_VOLUME_DOWN: nCommand = MEDIA_COMMAND_MICROPHONE_VOLUME_DOWN; break;
5588 case APPCOMMAND_MICROPHONE_VOLUME_MUTE: nCommand = MEDIA_COMMAND_MICROPHONE_VOLUME_MUTE; break;
5589 case APPCOMMAND_MICROPHONE_VOLUME_UP: nCommand = MEDIA_COMMAND_MICROPHONE_VOLUME_UP; break;
5590 case APPCOMMAND_VOLUME_DOWN: nCommand = MEDIA_COMMAND_VOLUME_DOWN; break;
5591 case APPCOMMAND_VOLUME_MUTE: nCommand = MEDIA_COMMAND_VOLUME_MUTE; break;
5592 case APPCOMMAND_VOLUME_UP: nCommand = MEDIA_COMMAND_VOLUME_UP; break;
5593 break;
5594 default:
5595 return false;
5598 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5599 Window *pWindow = pFrame ? pFrame->GetWindow() : NULL;
5601 if( pWindow )
5603 const Point aPoint;
5604 CommandEvent aCEvt( aPoint, COMMAND_MEDIA, FALSE, &nCommand );
5605 NotifyEvent aNCmdEvt( EVENT_COMMAND, pWindow, &aCEvt );
5607 if ( !ImplCallPreNotify( aNCmdEvt ) )
5609 pWindow->Command( aCEvt );
5610 return true;
5614 return false;
5618 static void ImplHandleIMENotify( HWND hWnd, WPARAM wParam )
5620 if ( wParam == (WPARAM)IMN_OPENCANDIDATE )
5622 ImplSalYieldMutexAcquireWithWait();
5624 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5625 if ( pFrame && pFrame->mbHandleIME &&
5626 pFrame->mbAtCursorIME )
5628 // Wir wollen den Cursor hiden
5629 pFrame->mbCandidateMode = TRUE;
5630 ImplHandleIMEComposition( hWnd, GCS_CURSORPOS );
5632 HWND hWnd = pFrame->mhWnd;
5633 HIMC hIMC = ImmGetContext( hWnd );
5634 if ( hIMC )
5636 LONG nBufLen = ImmGetCompositionStringW( hIMC, GCS_COMPSTR, 0, 0 );
5637 if ( nBufLen >= 1 )
5639 SalExtTextInputPosEvent aPosEvt;
5640 pFrame->CallCallback( SALEVENT_EXTTEXTINPUTPOS, (void*)&aPosEvt );
5642 // Vertical !!!
5643 CANDIDATEFORM aForm;
5644 aForm.dwIndex = 0;
5645 aForm.dwStyle = CFS_EXCLUDE;
5646 aForm.ptCurrentPos.x = aPosEvt.mnX;
5647 aForm.ptCurrentPos.y = aPosEvt.mnY+1;
5648 aForm.rcArea.left = aPosEvt.mnX;
5649 aForm.rcArea.top = aPosEvt.mnY;
5650 aForm.rcArea.right = aForm.rcArea.left+aPosEvt.mnExtWidth+1;
5651 aForm.rcArea.bottom = aForm.rcArea.top+aPosEvt.mnHeight+1;
5652 ImmSetCandidateWindow( hIMC, &aForm );
5655 ImmReleaseContext( hWnd, hIMC );
5659 ImplSalYieldMutexRelease();
5661 else if ( wParam == (WPARAM)IMN_CLOSECANDIDATE )
5663 ImplSalYieldMutexAcquireWithWait();
5664 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5665 if ( pFrame )
5666 pFrame->mbCandidateMode = FALSE;
5667 ImplSalYieldMutexRelease();
5671 // -----------------------------------------------------------------------
5672 #if WINVER >= 0x0500
5674 static LRESULT ImplHandleIMEReconvertString( HWND hWnd, LPARAM lParam )
5676 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5677 LPRECONVERTSTRING pReconvertString = (LPRECONVERTSTRING) lParam;
5678 LRESULT nRet = 0;
5679 SalSurroundingTextRequestEvent aEvt;
5680 aEvt.maText = UniString();
5681 aEvt.mnStart = aEvt.mnEnd = 0;
5683 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_SETCOMPSTR );
5684 if( (nImeProps & SCS_CAP_SETRECONVERTSTRING) == 0 )
5686 // This IME does not support reconversion.
5687 return 0;
5690 if( !pReconvertString )
5692 // The first call for reconversion.
5693 pFrame->CallCallback( SALEVENT_STARTRECONVERSION, (void*)NULL );
5695 // Retrieve the surrounding text from the focused control.
5696 pFrame->CallCallback( SALEVENT_SURROUNDINGTEXTREQUEST, (void*)&aEvt );
5698 if( aEvt.maText.Len() == 0 )
5700 return 0;
5703 nRet = sizeof(RECONVERTSTRING) + (aEvt.maText.Len() + 1) * sizeof(WCHAR);
5705 else
5707 // The second call for reconversion.
5709 // Retrieve the surrounding text from the focused control.
5710 pFrame->CallCallback( SALEVENT_SURROUNDINGTEXTREQUEST, (void*)&aEvt );
5711 nRet = sizeof(RECONVERTSTRING) + (aEvt.maText.Len() + 1) * sizeof(WCHAR);
5713 pReconvertString->dwStrOffset = sizeof(RECONVERTSTRING);
5714 pReconvertString->dwStrLen = aEvt.maText.Len();
5715 pReconvertString->dwCompStrOffset = aEvt.mnStart * sizeof(WCHAR);
5716 pReconvertString->dwCompStrLen = aEvt.mnEnd - aEvt.mnStart;
5717 pReconvertString->dwTargetStrOffset = pReconvertString->dwCompStrOffset;
5718 pReconvertString->dwTargetStrLen = pReconvertString->dwCompStrLen;
5720 memcpy( (LPWSTR)(pReconvertString + 1), aEvt.maText.GetBuffer(), (aEvt.maText.Len() + 1) * sizeof(WCHAR) );
5723 // just return the required size of buffer to reconvert.
5724 return nRet;
5727 // -----------------------------------------------------------------------
5729 static LRESULT ImplHandleIMEConfirmReconvertString( HWND hWnd, LPARAM lParam )
5731 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5732 LPRECONVERTSTRING pReconvertString = (LPRECONVERTSTRING) lParam;
5733 SalSurroundingTextRequestEvent aEvt;
5734 aEvt.maText = UniString();
5735 aEvt.mnStart = aEvt.mnEnd = 0;
5737 pFrame->CallCallback( SALEVENT_SURROUNDINGTEXTREQUEST, (void*)&aEvt );
5739 sal_uLong nTmpStart = pReconvertString->dwCompStrOffset / sizeof(WCHAR);
5740 sal_uLong nTmpEnd = nTmpStart + pReconvertString->dwCompStrLen;
5742 if( nTmpStart != aEvt.mnStart || nTmpEnd != aEvt.mnEnd )
5744 SalSurroundingTextSelectionChangeEvent aSelEvt;
5745 aSelEvt.mnStart = nTmpStart;
5746 aSelEvt.mnEnd = nTmpEnd;
5748 pFrame->CallCallback( SALEVENT_SURROUNDINGTEXTSELECTIONCHANGE, (void*)&aSelEvt );
5751 return TRUE;
5754 #endif // WINVER >= 0x0500
5756 // -----------------------------------------------------------------------
5758 void SalTestMouseLeave()
5760 SalData* pSalData = GetSalData();
5762 if ( pSalData->mhWantLeaveMsg && !::GetCapture() )
5764 POINT aPt;
5765 GetCursorPos( &aPt );
5766 if ( pSalData->mhWantLeaveMsg != WindowFromPoint( aPt ) )
5767 ImplSendMessage( pSalData->mhWantLeaveMsg, SAL_MSG_MOUSELEAVE, 0, MAKELPARAM( aPt.x, aPt.y ) );
5771 // -----------------------------------------------------------------------
5773 static int ImplSalWheelMousePos( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam ,
5774 LRESULT& rResult )
5776 POINT aPt;
5777 POINT aScreenPt;
5778 aScreenPt.x = (short)LOWORD( lParam );
5779 aScreenPt.y = (short)HIWORD( lParam );
5780 // Child-Fenster suchen, welches an der entsprechenden
5781 // Position liegt
5782 HWND hChildWnd;
5783 HWND hWheelWnd = hWnd;
5786 hChildWnd = hWheelWnd;
5787 aPt = aScreenPt;
5788 ScreenToClient( hChildWnd, &aPt );
5789 hWheelWnd = ChildWindowFromPointEx( hChildWnd, aPt, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT );
5791 while ( hWheelWnd && (hWheelWnd != hChildWnd) );
5792 if ( hWheelWnd && (hWheelWnd != hWnd) &&
5793 (hWheelWnd != ::GetFocus()) && IsWindowEnabled( hWheelWnd ) )
5795 rResult = ImplSendMessage( hWheelWnd, nMsg, wParam, lParam );
5796 return FALSE;
5799 return TRUE;
5802 // -----------------------------------------------------------------------
5804 LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef )
5806 LRESULT nRet = 0;
5807 static int bInWheelMsg = FALSE;
5808 static int bInQueryEnd = FALSE;
5810 // By WM_CRETAE we connect the frame with the window handle
5811 if ( nMsg == WM_CREATE )
5813 // Window-Instanz am Windowhandle speichern
5814 // Can also be used for the W-Version, because the struct
5815 // to access lpCreateParams is the same structure
5816 CREATESTRUCTA* pStruct = (CREATESTRUCTA*)lParam;
5817 WinSalFrame* pFrame = (WinSalFrame*)pStruct->lpCreateParams;
5818 if ( pFrame != 0 )
5820 SetWindowPtr( hWnd, pFrame );
5821 // HWND schon hier setzen, da schon auf den Instanzdaten
5822 // gearbeitet werden kann, wenn Messages waehrend
5823 // CreateWindow() gesendet werden
5824 pFrame->mhWnd = hWnd;
5825 pFrame->maSysData.hWnd = hWnd;
5827 return 0;
5830 ImplSVData* pSVData = ImplGetSVData();
5831 // #i72707# TODO: the mbDeInit check will not be needed
5832 // once all windows that are not properly closed on exit got fixed
5833 if( pSVData->mbDeInit )
5834 return 0;
5836 if ( WM_USER_SYSTEM_WINDOW_ACTIVATED == nMsg )
5838 if (pSVData->mpIntroWindow)
5839 pSVData->mpIntroWindow->Hide();
5841 return 0;
5844 bool bCheckTimers = false;
5846 switch( nMsg )
5848 case WM_MOUSEMOVE:
5849 case WM_LBUTTONDOWN:
5850 case WM_MBUTTONDOWN:
5851 case WM_RBUTTONDOWN:
5852 case WM_LBUTTONUP:
5853 case WM_MBUTTONUP:
5854 case WM_RBUTTONUP:
5855 case WM_NCMOUSEMOVE:
5856 case SAL_MSG_MOUSELEAVE:
5857 ImplSalYieldMutexAcquireWithWait();
5858 rDef = !ImplHandleMouseMsg( hWnd, nMsg, wParam, lParam );
5859 ImplSalYieldMutexRelease();
5860 break;
5862 case WM_NCLBUTTONDOWN:
5863 case WM_NCMBUTTONDOWN:
5864 case WM_NCRBUTTONDOWN:
5865 ImplSalYieldMutexAcquireWithWait();
5866 ImplCallClosePopupsHdl( hWnd ); // close popups...
5867 ImplSalYieldMutexRelease();
5868 break;
5870 case WM_MOUSEACTIVATE:
5871 if ( LOWORD( lParam ) == HTCLIENT )
5873 ImplSalYieldMutexAcquireWithWait();
5874 nRet = ImplHandleMouseActivateMsg( hWnd );
5875 ImplSalYieldMutexRelease();
5876 if ( nRet )
5878 nRet = MA_NOACTIVATE;
5879 rDef = FALSE;
5882 break;
5884 case WM_KEYDOWN:
5885 case WM_KEYUP:
5886 case WM_DEADCHAR:
5887 case WM_CHAR:
5888 case WM_UNICHAR: // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0
5889 case WM_SYSKEYDOWN:
5890 case WM_SYSKEYUP:
5891 case WM_SYSCHAR:
5892 ImplSalYieldMutexAcquireWithWait();
5893 rDef = !ImplHandleKeyMsg( hWnd, nMsg, wParam, lParam, nRet );
5894 ImplSalYieldMutexRelease();
5895 break;
5897 case WM_MOUSEWHEEL:
5898 // FALLTHROUGH intended
5899 case WM_MOUSEHWHEEL:
5900 // Gegen Rekursion absichern, falls wir vom IE oder dem externen
5901 // Fenster die Message wieder zurueckbekommen
5902 if ( !bInWheelMsg )
5904 bInWheelMsg++;
5905 rDef = !ImplHandleWheelMsg( hWnd, nMsg, wParam, lParam );
5906 // Wenn wir die Message nicht ausgewertet haben, schauen wir
5907 // noch einmal nach, ob dort ein geplugtes Fenster steht,
5908 // welches wir dann benachrichtigen
5909 if ( rDef )
5910 rDef = ImplSalWheelMousePos( hWnd, nMsg, wParam, lParam, nRet );
5911 bInWheelMsg--;
5913 break;
5915 case WM_COMMAND:
5916 ImplSalYieldMutexAcquireWithWait();
5917 rDef = !ImplHandleCommand( hWnd, wParam, lParam );
5918 ImplSalYieldMutexRelease();
5919 break;
5921 case WM_INITMENUPOPUP:
5922 ImplSalYieldMutexAcquireWithWait();
5923 rDef = !ImplHandleMenuActivate( hWnd, wParam, lParam );
5924 ImplSalYieldMutexRelease();
5925 break;
5927 case WM_MENUSELECT:
5928 ImplSalYieldMutexAcquireWithWait();
5929 rDef = !ImplHandleMenuSelect( hWnd, wParam, lParam );
5930 ImplSalYieldMutexRelease();
5931 break;
5933 case WM_SYSCOMMAND:
5934 ImplSalYieldMutexAcquireWithWait();
5935 nRet = ImplHandleSysCommand( hWnd, wParam, lParam );
5936 ImplSalYieldMutexRelease();
5937 if ( nRet )
5938 rDef = FALSE;
5939 break;
5941 case WM_MENUCHAR:
5942 nRet = ImplMenuChar( hWnd, wParam, lParam );
5943 if( nRet )
5944 rDef = FALSE;
5945 break;
5947 case WM_MEASUREITEM:
5948 nRet = ImplMeasureItem(hWnd, wParam, lParam);
5949 if( nRet )
5950 rDef = FALSE;
5951 break;
5953 case WM_DRAWITEM:
5954 nRet = ImplDrawItem(hWnd, wParam, lParam);
5955 if( nRet )
5956 rDef = FALSE;
5957 break;
5959 case WM_MOVE:
5960 case SAL_MSG_POSTMOVE:
5961 ImplHandleMoveMsg( hWnd );
5962 rDef = FALSE;
5963 break;
5964 case WM_SIZE:
5965 ImplHandleSizeMsg( hWnd, wParam, lParam );
5966 rDef = FALSE;
5967 break;
5968 case SAL_MSG_POSTCALLSIZE:
5969 ImplCallSizeHdl( hWnd );
5970 rDef = FALSE;
5971 break;
5973 case WM_GETMINMAXINFO:
5974 if ( ImplHandleMinMax( hWnd, lParam ) )
5975 rDef = FALSE;
5976 break;
5978 case WM_ERASEBKGND:
5979 nRet = 1;
5980 rDef = FALSE;
5981 break;
5982 case WM_PAINT:
5983 bCheckTimers = ImplHandlePaintMsg( hWnd );
5984 rDef = FALSE;
5985 break;
5986 case SAL_MSG_POSTPAINT:
5987 ImplHandlePaintMsg2( hWnd, (RECT*)wParam );
5988 bCheckTimers = true;
5989 rDef = FALSE;
5990 break;
5992 case SAL_MSG_FORCEPALETTE:
5993 ImplHandleForcePalette( hWnd );
5994 rDef = FALSE;
5995 break;
5997 case WM_QUERYNEWPALETTE:
5998 case SAL_MSG_POSTQUERYNEWPAL:
5999 nRet = ImplHandlePalette( TRUE, hWnd, nMsg, wParam, lParam, rDef );
6000 break;
6002 case WM_ACTIVATE:
6003 // Wenn wir aktiviert werden, dann wollen wir auch unsere
6004 // Palette setzen. Wir machen dieses in Activate,
6005 // damit andere externe Child-Fenster auch unsere Palette
6006 // ueberschreiben koennen. So wird unsere jedenfalls nur einmal
6007 // gesetzt und nicht immer rekursiv, da an allen anderen Stellen
6008 // diese nur als Background-Palette gesetzt wird
6009 if ( LOWORD( wParam ) != WA_INACTIVE )
6010 ImplSendMessage( hWnd, SAL_MSG_FORCEPALETTE, 0, 0 );
6011 break;
6013 case WM_ENABLE:
6014 // #95133# a system dialog is opened/closed, using our app window as parent
6016 WinSalFrame* pFrame = GetWindowPtr( hWnd );
6017 Window *pWin = NULL;
6018 if( pFrame )
6019 pWin = pFrame->GetWindow();
6021 if( !wParam )
6023 ImplSVData* pSVData = ImplGetSVData();
6024 pSVData->maAppData.mnModalMode++;
6026 // #106431#, hide SplashScreen
6027 if( pSVData->mpIntroWindow )
6028 pSVData->mpIntroWindow->Hide();
6030 if( pWin )
6032 pWin->EnableInput( FALSE, TRUE, TRUE, NULL );
6033 pWin->ImplIncModalCount(); // #106303# support frame based modal count
6036 else
6038 ImplGetSVData()->maAppData.mnModalMode--;
6039 if( pWin )
6041 pWin->EnableInput( TRUE, TRUE, TRUE, NULL );
6042 pWin->ImplDecModalCount(); // #106303# support frame based modal count
6046 break;
6048 case WM_KILLFOCUS:
6049 DestroyCaret();
6050 case WM_SETFOCUS:
6051 case SAL_MSG_POSTFOCUS:
6052 ImplHandleFocusMsg( hWnd );
6053 rDef = FALSE;
6054 break;
6056 case WM_CLOSE:
6057 ImplHandleCloseMsg( hWnd );
6058 rDef = FALSE;
6059 break;
6061 case WM_QUERYENDSESSION:
6062 if( !bInQueryEnd )
6064 // handle queryendsession only once
6065 bInQueryEnd = TRUE;
6066 nRet = !ImplHandleShutDownMsg( hWnd );
6067 rDef = FALSE;
6069 // Issue #16314#: ImplHandleShutDownMsg causes a PostMessage in case of allowing shutdown.
6070 // This posted message was never processed and cause Windows XP to hang after log off
6071 // if there are multiple sessions and the current session wasn't the first one started.
6072 // So if shutdown is allowed we assume that a post message was done and retrieve all
6073 // messages in the message queue and dispatch them before we return control to the system.
6075 if ( nRet )
6077 MSG msg;
6079 while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
6081 DispatchMessage( &msg );
6085 else
6087 ImplSalYieldMutexAcquireWithWait();
6088 ImplSalYieldMutexRelease();
6089 rDef = TRUE;
6091 break;
6093 case WM_ENDSESSION:
6094 if( !wParam )
6095 bInQueryEnd = FALSE; // no shutdown: allow query again
6096 nRet = FALSE;
6097 rDef = FALSE;
6098 break;
6100 case WM_DISPLAYCHANGE:
6101 case WM_SETTINGCHANGE:
6102 case WM_DEVMODECHANGE:
6103 case WM_FONTCHANGE:
6104 case WM_SYSCOLORCHANGE:
6105 case WM_TIMECHANGE:
6106 ImplHandleSettingsChangeMsg( hWnd, nMsg, wParam, lParam );
6107 break;
6109 case WM_THEMECHANGED:
6110 GetSalData()->mbThemeChanged = TRUE;
6111 break;
6113 case SAL_MSG_USEREVENT:
6114 ImplHandleUserEvent( hWnd, lParam );
6115 rDef = FALSE;
6116 break;
6118 case SAL_MSG_CAPTUREMOUSE:
6119 SetCapture( hWnd );
6120 rDef = FALSE;
6121 break;
6122 case SAL_MSG_RELEASEMOUSE:
6123 if ( ::GetCapture() == hWnd )
6124 ReleaseCapture();
6125 rDef = FALSE;
6126 break;
6127 case SAL_MSG_TOTOP:
6128 ImplSalToTop( hWnd, (sal_uInt16)wParam );
6129 rDef = FALSE;
6130 break;
6131 case SAL_MSG_SHOW:
6132 ImplSalShow( hWnd, (sal_Bool)wParam, (sal_Bool)lParam );
6133 rDef = FALSE;
6134 break;
6135 case SAL_MSG_SETINPUTCONTEXT:
6136 ImplSalFrameSetInputContext( hWnd, (const SalInputContext*)(void*)lParam );
6137 rDef = FALSE;
6138 break;
6139 case SAL_MSG_ENDEXTTEXTINPUT:
6140 ImplSalFrameEndExtTextInput( hWnd, (sal_uInt16)(sal_uLong)(void*)wParam );
6141 rDef = FALSE;
6142 break;
6144 case WM_INPUTLANGCHANGE:
6145 ImplHandleInputLangChange( hWnd, wParam, lParam );
6146 break;
6148 case WM_IME_CHAR:
6149 // #103487#, some IMEs (eg, those that do not work onspot)
6150 // may send WM_IME_CHAR instead of WM_IME_COMPOSITION
6151 // we just handle it like a WM_CHAR message - seems to work fine
6152 ImplSalYieldMutexAcquireWithWait();
6153 rDef = !ImplHandleKeyMsg( hWnd, WM_CHAR, wParam, lParam, nRet );
6154 ImplSalYieldMutexRelease();
6155 break;
6157 case WM_IME_STARTCOMPOSITION:
6158 rDef = ImplHandleIMEStartComposition( hWnd );
6159 break;
6161 case WM_IME_COMPOSITION:
6162 rDef = ImplHandleIMEComposition( hWnd, lParam );
6163 break;
6165 case WM_IME_ENDCOMPOSITION:
6166 rDef = ImplHandleIMEEndComposition( hWnd );
6167 break;
6169 case WM_IME_NOTIFY:
6170 ImplHandleIMENotify( hWnd, wParam );
6171 break;
6172 case WM_APPCOMMAND:
6173 if( ImplHandleAppCommand( hWnd, lParam ) )
6175 rDef = false;
6176 nRet = 1;
6178 break;
6179 #if WINVER >= 0x0500
6180 case WM_IME_REQUEST:
6181 if ( PtrToInt( wParam ) == IMR_RECONVERTSTRING )
6183 nRet = ImplHandleIMEReconvertString( hWnd, lParam );
6184 rDef = FALSE;
6186 else if( PtrToInt( wParam ) == IMR_CONFIRMRECONVERTSTRING )
6188 nRet = ImplHandleIMEConfirmReconvertString( hWnd, lParam );
6189 rDef = FALSE;
6191 break;
6192 #endif // WINVER >= 0x0500
6195 // WheelMouse-Message abfangen
6196 if ( rDef && (nMsg == aSalShlData.mnWheelMsgId) && aSalShlData.mnWheelMsgId )
6198 // Gegen Rekursion absichern, falls wir vom IE oder dem externen
6199 // Fenster die Message wieder zurueckbekommen
6200 if ( !bInWheelMsg )
6202 bInWheelMsg++;
6203 // Zuerst wollen wir die Message dispatchen und dann darf auch
6204 // das SystemWindow drankommen
6205 WORD nKeyState = 0;
6206 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
6207 nKeyState |= MK_SHIFT;
6208 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
6209 nKeyState |= MK_CONTROL;
6210 // Mutex handling is inside from this call
6211 rDef = !ImplHandleWheelMsg( hWnd,
6212 WM_MOUSEWHEEL,
6213 MAKEWPARAM( nKeyState, (WORD)wParam ),
6214 lParam );
6215 if ( rDef )
6217 HWND hWheelWnd = ::GetFocus();
6218 if ( hWheelWnd && (hWheelWnd != hWnd) )
6220 nRet = ImplSendMessage( hWheelWnd, nMsg, wParam, lParam );
6221 rDef = FALSE;
6223 else
6224 rDef = ImplSalWheelMousePos( hWnd, nMsg, wParam, lParam, nRet );
6226 bInWheelMsg--;
6230 if( bCheckTimers )
6232 SalData* pSalData = GetSalData();
6233 if( pSalData->mnNextTimerTime )
6235 DWORD nCurTime = GetTickCount();
6236 if( pSalData->mnNextTimerTime < nCurTime )
6238 MSG aMsg;
6239 if( ! ImplPeekMessage( &aMsg, 0, WM_PAINT, WM_PAINT, PM_NOREMOVE | PM_NOYIELD ) )
6240 ImplPostMessage( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_POSTTIMER, 0, nCurTime );
6245 return nRet;
6248 LRESULT CALLBACK SalFrameWndProcA( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
6250 int bDef = TRUE;
6251 LRESULT nRet = 0;
6252 #ifdef __MINGW32__
6253 jmp_buf jmpbuf;
6254 __SEHandler han;
6255 if (__builtin_setjmp(jmpbuf) == 0)
6257 han.Set(jmpbuf, NULL, (__SEHandler::PF)EXCEPTION_EXECUTE_HANDLER);
6258 #else
6259 __try
6261 #endif
6262 nRet = SalFrameWndProc( hWnd, nMsg, wParam, lParam, bDef );
6264 #ifdef __MINGW32__
6265 han.Reset();
6266 #else
6267 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
6270 #endif
6271 if ( bDef )
6272 nRet = DefWindowProcA( hWnd, nMsg, wParam, lParam );
6273 return nRet;
6276 LRESULT CALLBACK SalFrameWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
6278 int bDef = TRUE;
6279 LRESULT nRet = 0;
6280 #ifdef __MINGW32__
6281 jmp_buf jmpbuf;
6282 __SEHandler han;
6283 if (__builtin_setjmp(jmpbuf) == 0)
6285 han.Set(jmpbuf, NULL, (__SEHandler::PF)EXCEPTION_EXECUTE_HANDLER);
6286 #else
6287 __try
6289 #endif
6290 nRet = SalFrameWndProc( hWnd, nMsg, wParam, lParam, bDef );
6292 #ifdef __MINGW32__
6293 han.Reset();
6294 #else
6295 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
6298 #endif
6300 if ( bDef )
6301 nRet = DefWindowProcW( hWnd, nMsg, wParam, lParam );
6302 return nRet;
6305 // -----------------------------------------------------------------------
6307 sal_Bool ImplHandleGlobalMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT& rlResult )
6309 // handle all messages concerning all frames so they get processed only once
6310 // Must work for Unicode and none Unicode
6311 sal_Bool bResult = FALSE;
6312 if ( (nMsg == WM_PALETTECHANGED) || (nMsg == SAL_MSG_POSTPALCHANGED) )
6314 int bDef = TRUE;
6315 rlResult = ImplHandlePalette( FALSE, hWnd, nMsg, wParam, lParam, bDef );
6316 bResult = (bDef != 0);
6318 else if( nMsg == WM_DISPLAYCHANGE )
6320 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
6321 if( pSys )
6322 pSys->clearMonitors();
6323 bResult = (pSys != NULL);
6325 return bResult;
6328 // -----------------------------------------------------------------------
6330 sal_Bool ImplWriteLastError( DWORD lastError, const char *szApiCall )
6332 static int first=1;
6333 // if VCL_LOGFILE_ENABLED is set, Win32 API error messages can be written
6334 // to %TMP%/vcl.log or %TEMP%/vcl.log
6335 static char *logEnabled = getenv("VCL_LOGFILE_ENABLED");
6336 if( logEnabled )
6338 sal_Bool bSuccess = FALSE;
6339 static char *szTmp = getenv("TMP");
6340 if( !szTmp || !*szTmp )
6341 szTmp = getenv("TEMP");
6342 if( szTmp && *szTmp )
6344 char fname[5000];
6345 strcpy( fname, szTmp );
6346 if( fname[strlen(fname) - 1] != '\\' )
6347 strcat( fname, "\\");
6348 strcat( fname, "vcl.log" );
6349 FILE *fp = fopen( fname, "a" ); // always append
6350 if( fp )
6352 if( first )
6354 first = 0;
6355 fprintf( fp, "Process ID: %d (0x%x)\n", GetCurrentProcessId(), GetCurrentProcessId() );
6357 time_t aclock;
6358 time( &aclock ); // Get time in seconds
6359 struct tm *newtime = localtime( &aclock ); // Convert time to struct tm form
6360 fprintf( fp, asctime( newtime ) ); // print time stamp
6362 fprintf( fp, "%s returned %u (0x%x)\n", szApiCall, lastError, lastError );
6363 bSuccess = TRUE; // may be FormatMessage fails but we wrote at least the error code
6365 LPVOID lpMsgBuf;
6366 if (FormatMessageA(
6367 FORMAT_MESSAGE_ALLOCATE_BUFFER |
6368 FORMAT_MESSAGE_FROM_SYSTEM |
6369 FORMAT_MESSAGE_IGNORE_INSERTS,
6370 NULL,
6371 lastError,
6372 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
6373 (LPSTR) &lpMsgBuf,
6375 NULL ))
6377 fprintf( fp, " %s\n", (LPSTR)lpMsgBuf );
6378 LocalFree( lpMsgBuf );
6381 fclose( fp );
6384 return bSuccess;
6386 else
6387 return TRUE;
6390 // -----------------------------------------------------------------------