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