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