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