Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / vcl / win / source / window / salframe.cxx
blob411d87a1094374e54a5ceb77f3c3142b7412a2d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // i72022: ad-hoc to forcibly enable reconversion
22 #if WINVER < 0x0500
23 #undef WINVER
24 #define WINVER 0x0500
25 #endif
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/container/XIndexAccess.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/awt/Rectangle.hpp>
31 #include <comphelper/processfactory.hxx>
32 #include <unotools/misccfg.hxx>
34 #include <string.h>
35 #include <limits.h>
37 #include <stdio.h>
39 #include <svsys.h>
41 #include <rtl/string.h>
42 #include <rtl/ustring.h>
44 #include <osl/module.h>
46 #include <tools/debug.hxx>
48 #include <vcl/sysdata.hxx>
49 #include <vcl/timer.hxx>
50 #include <vcl/settings.hxx>
51 #include <vcl/keycodes.hxx>
52 #include <vcl/window.hxx>
53 #include <vcl/wrkwin.hxx>
54 #include <vcl/svapp.hxx>
56 // Warning in SDK header
57 #ifdef _MSC_VER
58 #pragma warning( disable: 4242 4244 )
59 #endif
60 #include <win/wincomp.hxx>
61 #include <win/salids.hrc>
62 #include <win/saldata.hxx>
63 #include <win/salinst.h>
64 #include <win/salbmp.h>
65 #include <win/salgdi.h>
66 #include <win/salsys.h>
67 #include <win/salframe.h>
68 #include <win/salvd.h>
69 #include <win/salmenu.h>
70 #include <win/salobj.h>
71 #include <win/saltimer.h>
73 #include <impbmp.hxx>
74 #include <window.h>
75 #include <sallayout.hxx>
77 #define COMPILE_MULTIMON_STUBS
78 #include <multimon.h>
79 #include <vector>
80 #ifdef __MINGW32__
81 #include <algorithm>
82 using ::std::max;
83 #endif
85 #include <com/sun/star/uno/Exception.hpp>
87 #include <time.h>
89 #ifdef __MINGW32__
90 #include <sehandler.hxx>
91 #endif
93 using ::rtl::OUString;
94 using namespace ::com::sun::star;
95 using namespace ::com::sun::star::uno;
96 using namespace ::com::sun::star::lang;
97 using namespace ::com::sun::star::container;
98 using namespace ::com::sun::star::beans;
100 #ifndef SPI_GETWHEELSCROLLCHARS
101 # define SPI_GETWHEELSCROLLCHARS 0x006C
102 #endif
103 #ifndef SPI_SETWHEELSCROLLCHARS
104 # define SPI_SETWHEELSCROLLCHARS 0x006D
105 #endif
106 #ifndef WM_MOUSEHWHEEL
107 # define WM_MOUSEHWHEEL 0x020E
108 #endif
110 #if OSL_DEBUG_LEVEL > 1
111 void MyOutputDebugString( char *s) { OutputDebugString( s ); }
112 #endif
114 // =======================================================================
116 const unsigned int WM_USER_SYSTEM_WINDOW_ACTIVATED = RegisterWindowMessageA("SYSTEM_WINDOW_ACTIVATED");
118 sal_Bool WinSalFrame::mbInReparent = FALSE;
120 // =======================================================================
122 // Macros for support of WM_UNICHAR & Keyman 6.0
123 #define Uni_UTF32ToSurrogate1(ch) (((unsigned long) (ch) - 0x10000) / 0x400 + 0xD800)
124 #define Uni_UTF32ToSurrogate2(ch) (((unsigned long) (ch) - 0x10000) % 0x400 + 0xDC00)
125 #define Uni_SupplementaryPlanesStart 0x10000
127 // =======================================================================
129 static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame );
130 static void SetMaximizedFrameGeometry( HWND hWnd, WinSalFrame* pFrame, RECT* pParentRect = NULL );
132 static void ImplSaveFrameState( WinSalFrame* pFrame )
134 // Position, Groesse und Status fuer GetWindowState() merken
135 if ( !pFrame->mbFullScreen )
137 sal_Bool bVisible = (GetWindowStyle( pFrame->mhWnd ) & WS_VISIBLE) != 0;
138 if ( IsIconic( pFrame->mhWnd ) )
140 pFrame->maState.mnState |= SAL_FRAMESTATE_MINIMIZED;
141 if ( bVisible )
142 pFrame->mnShowState = SW_SHOWMAXIMIZED;
144 else if ( IsZoomed( pFrame->mhWnd ) )
146 pFrame->maState.mnState &= ~SAL_FRAMESTATE_MINIMIZED;
147 pFrame->maState.mnState |= SAL_FRAMESTATE_MAXIMIZED;
148 if ( bVisible )
149 pFrame->mnShowState = SW_SHOWMAXIMIZED;
150 pFrame->mbRestoreMaximize = TRUE;
152 WINDOWPLACEMENT aPlacement;
153 aPlacement.length = sizeof(aPlacement);
154 if( GetWindowPlacement( pFrame->mhWnd, &aPlacement ) )
156 RECT aRect = aPlacement.rcNormalPosition;
157 RECT aRect2 = aRect;
158 AdjustWindowRectEx( &aRect2, GetWindowStyle( pFrame->mhWnd ),
159 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
160 long nTopDeco = abs( aRect.top - aRect2.top );
161 long nLeftDeco = abs( aRect.left - aRect2.left );
162 long nBottomDeco = abs( aRect.bottom - aRect2.bottom );
163 long nRightDeco = abs( aRect.right - aRect2.right );
165 pFrame->maState.mnX = aRect.left + nLeftDeco;
166 pFrame->maState.mnY = aRect.top + nTopDeco;
167 pFrame->maState.mnWidth = aRect.right - aRect.left - nLeftDeco - nRightDeco;
168 pFrame->maState.mnHeight = aRect.bottom - aRect.top - nTopDeco - nBottomDeco;
171 else
173 RECT aRect;
174 GetWindowRect( pFrame->mhWnd, &aRect );
176 // to be consistent with Unix, the frame state is without(!) decoration
177 RECT aRect2 = aRect;
178 AdjustWindowRectEx( &aRect2, GetWindowStyle( pFrame->mhWnd ),
179 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
180 long nTopDeco = abs( aRect.top - aRect2.top );
181 long nLeftDeco = abs( aRect.left - aRect2.left );
182 long nBottomDeco = abs( aRect.bottom - aRect2.bottom );
183 long nRightDeco = abs( aRect.right - aRect2.right );
185 pFrame->maState.mnState &= ~(SAL_FRAMESTATE_MINIMIZED | SAL_FRAMESTATE_MAXIMIZED);
186 // subtract decoration
187 pFrame->maState.mnX = aRect.left+nLeftDeco;
188 pFrame->maState.mnY = aRect.top+nTopDeco;
189 pFrame->maState.mnWidth = aRect.right-aRect.left-nLeftDeco-nRightDeco;
190 pFrame->maState.mnHeight = aRect.bottom-aRect.top-nTopDeco-nBottomDeco;
191 if ( bVisible )
192 pFrame->mnShowState = SW_SHOWNORMAL;
193 pFrame->mbRestoreMaximize = FALSE;
198 // -----------------------------------------------------------------------
200 // if pParentRect is set, the workarea of the monitor that contains pParentRect is returned
201 void ImplSalGetWorkArea( HWND hWnd, RECT *pRect, const RECT *pParentRect )
203 // check if we or our parent is fullscreen, then the taskbar should be ignored
204 bool bIgnoreTaskbar = false;
205 WinSalFrame* pFrame = GetWindowPtr( hWnd );
206 if( pFrame )
208 Window *pWin = pFrame->GetWindow();
209 while( pWin )
211 WorkWindow *pWorkWin = (pWin->GetType() == WINDOW_WORKWINDOW) ? (WorkWindow *) pWin : NULL;
212 if( pWorkWin && pWorkWin->ImplGetWindowImpl()->mbReallyVisible && pWorkWin->IsFullScreenMode() )
214 bIgnoreTaskbar = true;
215 break;
217 else
218 pWin = pWin->ImplGetWindowImpl()->mpParent;
222 // calculates the work area taking multiple monitors into account
223 static int nMonitors = GetSystemMetrics( SM_CMONITORS );
224 if( nMonitors == 1 )
226 if( bIgnoreTaskbar )
228 pRect->left = pRect->top = 0;
229 pRect->right = GetSystemMetrics( SM_CXSCREEN );
230 pRect->bottom = GetSystemMetrics( SM_CYSCREEN );
232 else
233 SystemParametersInfo( SPI_GETWORKAREA, 0, pRect, 0 );
235 else
237 if( pParentRect != NULL )
239 // return the size of the monitor where pParentRect lives
240 HMONITOR hMonitor;
241 MONITORINFO mi;
243 // get the nearest monitor to the passed rect.
244 hMonitor = MonitorFromRect(pParentRect, MONITOR_DEFAULTTONEAREST);
246 // get the work area or entire monitor rect.
247 mi.cbSize = sizeof(mi);
248 GetMonitorInfo(hMonitor, &mi);
249 if( !bIgnoreTaskbar )
250 *pRect = mi.rcWork;
251 else
252 *pRect = mi.rcMonitor;
254 else
256 // return the union of all monitors
257 pRect->left = GetSystemMetrics( SM_XVIRTUALSCREEN );
258 pRect->top = GetSystemMetrics( SM_YVIRTUALSCREEN );
259 pRect->right = pRect->left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
260 pRect->bottom = pRect->top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
262 // virtualscreen does not take taskbar into account, so use the corresponding
263 // diffs between screen and workarea from the default screen
264 // however, this is still not perfect: the taskbar might not be on the primary screen
265 if( !bIgnoreTaskbar )
267 RECT wRect, scrRect;
268 SystemParametersInfo( SPI_GETWORKAREA, 0, &wRect, 0 );
269 scrRect.left = 0;
270 scrRect.top = 0;
271 scrRect.right = GetSystemMetrics( SM_CXSCREEN );
272 scrRect.bottom = GetSystemMetrics( SM_CYSCREEN );
274 pRect->left += wRect.left;
275 pRect->top += wRect.top;
276 pRect->right -= scrRect.right - wRect.right;
277 pRect->bottom -= scrRect.bottom - wRect.bottom;
283 // =======================================================================
285 SalFrame* ImplSalCreateFrame( WinSalInstance* pInst,
286 HWND hWndParent, sal_uLong nSalFrameStyle )
288 WinSalFrame* pFrame = new WinSalFrame;
289 HWND hWnd;
290 DWORD nSysStyle = 0;
291 DWORD nExSysStyle = 0;
292 sal_Bool bSubFrame = FALSE;
294 if( getenv( "SAL_SYNCHRONIZE" ) ) // no buffering of drawing commands
295 GdiSetBatchLimit( 1 );
297 static const char* pEnvTransparentFloats = getenv("SAL_TRANSPARENT_FLOATS" );
299 // determine creation data
300 if ( nSalFrameStyle & (SAL_FRAME_STYLE_PLUG | SAL_FRAME_STYLE_SYSTEMCHILD) )
302 nSysStyle |= WS_CHILD;
303 if( nSalFrameStyle & SAL_FRAME_STYLE_SYSTEMCHILD )
304 nSysStyle |= WS_CLIPSIBLINGS;
306 else
308 // #i87402# commenting out WS_CLIPCHILDREN
309 // this breaks SAL_FRAME_STYLE_SYSTEMCHILD handling, which is not
310 // used currently. Probably SAL_FRAME_STYLE_SYSTEMCHILD should be
311 // removed again.
313 // nSysStyle |= WS_CLIPCHILDREN;
314 if ( hWndParent )
316 nSysStyle |= WS_POPUP;
317 bSubFrame = TRUE;
318 pFrame->mbNoIcon = TRUE;
320 else
322 // Only with WS_OVRLAPPED we get a useful default position/size
323 if ( (nSalFrameStyle & (SAL_FRAME_STYLE_SIZEABLE | SAL_FRAME_STYLE_MOVEABLE)) ==
324 (SAL_FRAME_STYLE_SIZEABLE | SAL_FRAME_STYLE_MOVEABLE) )
325 nSysStyle |= WS_OVERLAPPED;
326 else
328 nSysStyle |= WS_POPUP;
329 if ( !(nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE) )
330 nExSysStyle |= WS_EX_TOOLWINDOW; // avoid taskbar appearance, for eg splash screen
334 if ( nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE )
336 pFrame->mbCaption = TRUE;
337 nSysStyle |= WS_SYSMENU | WS_CAPTION;
338 if ( !hWndParent )
339 nSysStyle |= WS_SYSMENU | WS_MINIMIZEBOX;
340 else
341 nExSysStyle |= WS_EX_DLGMODALFRAME;
343 if ( nSalFrameStyle & SAL_FRAME_STYLE_SIZEABLE )
345 pFrame->mbSizeBorder = TRUE;
346 nSysStyle |= WS_THICKFRAME;
347 if ( !hWndParent )
348 nSysStyle |= WS_MAXIMIZEBOX;
350 else
351 pFrame->mbFixBorder = TRUE;
353 if ( nSalFrameStyle & SAL_FRAME_STYLE_DEFAULT )
354 nExSysStyle |= WS_EX_APPWINDOW;
356 if( nSalFrameStyle & SAL_FRAME_STYLE_TOOLWINDOW
357 // #100656# toolwindows lead to bad alt-tab behaviour, if they have the focus
358 // you must press it twice to leave the application
359 // so toolwindows are only used for non sizeable windows
360 // which are typically small, so a small caption makes sense
362 // #103578# looked too bad - above changes reverted
363 /* && !(nSalFrameStyle & SAL_FRAME_STYLE_SIZEABLE) */ )
365 pFrame->mbNoIcon = TRUE;
366 nExSysStyle |= WS_EX_TOOLWINDOW;
367 if ( pEnvTransparentFloats /*&& !(nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE) */)
368 nExSysStyle |= WS_EX_LAYERED;
371 if ( nSalFrameStyle & SAL_FRAME_STYLE_FLOAT )
373 nExSysStyle |= WS_EX_TOOLWINDOW;
374 pFrame->mbFloatWin = TRUE;
376 if ( (pEnvTransparentFloats /* does not work remote! || (nSalFrameStyle & SAL_FRAME_STYLE_FLOAT_FOCUSABLE) */ ) )
377 nExSysStyle |= WS_EX_LAYERED;
380 if( (nSalFrameStyle & SAL_FRAME_STYLE_TOOLTIP) || (nSalFrameStyle & SAL_FRAME_STYLE_FLOAT_FOCUSABLE) )
381 nExSysStyle |= WS_EX_TOPMOST;
383 // init frame data
384 pFrame->mnStyle = nSalFrameStyle;
386 // determine show style
387 pFrame->mnShowState = SW_SHOWNORMAL;
388 if ( (nSysStyle & (WS_POPUP | WS_MAXIMIZEBOX | WS_THICKFRAME)) == (WS_MAXIMIZEBOX | WS_THICKFRAME) )
390 if ( GetSystemMetrics( SM_CXSCREEN ) <= 1024 )
391 pFrame->mnShowState = SW_SHOWMAXIMIZED;
392 else
394 if ( nSalFrameStyle & SAL_FRAME_STYLE_DEFAULT )
396 SalData* pSalData = GetSalData();
397 pFrame->mnShowState = pSalData->mnCmdShow;
398 if ( (pFrame->mnShowState != SW_SHOWMINIMIZED) &&
399 (pFrame->mnShowState != SW_MINIMIZE) &&
400 (pFrame->mnShowState != SW_SHOWMINNOACTIVE) )
402 if ( (pFrame->mnShowState == SW_SHOWMAXIMIZED) ||
403 (pFrame->mnShowState == SW_MAXIMIZE) )
404 pFrame->mbOverwriteState = FALSE;
405 pFrame->mnShowState = SW_SHOWMAXIMIZED;
407 else
408 pFrame->mbOverwriteState = FALSE;
410 else
412 // Document Windows are also maximized, if the current Document Window
413 // is also maximized
414 HWND hWnd2 = GetForegroundWindow();
415 if ( hWnd2 && IsMaximized( hWnd2 ) &&
416 (GetWindowInstance( hWnd2 ) == pInst->mhInst) &&
417 ((GetWindowStyle( hWnd2 ) & (WS_POPUP | WS_MAXIMIZEBOX | WS_THICKFRAME)) == (WS_MAXIMIZEBOX | WS_THICKFRAME)) )
418 pFrame->mnShowState = SW_SHOWMAXIMIZED;
423 // create frame
424 LPCWSTR pClassName;
425 if ( bSubFrame )
427 if ( nSalFrameStyle & (SAL_FRAME_STYLE_MOVEABLE|SAL_FRAME_STYLE_NOSHADOW) ) // check if shadow not wanted
428 pClassName = SAL_SUBFRAME_CLASSNAMEW;
429 else
430 pClassName = SAL_TMPSUBFRAME_CLASSNAMEW; // undecorated floaters will get shadow on XP
432 else
434 if ( nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE )
435 pClassName = SAL_FRAME_CLASSNAMEW;
436 else
437 pClassName = SAL_TMPSUBFRAME_CLASSNAMEW;
439 hWnd = CreateWindowExW( nExSysStyle, pClassName, L"", nSysStyle,
440 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
441 hWndParent, 0, pInst->mhInst, (void*)pFrame );
442 if( !hWnd )
443 ImplWriteLastError( GetLastError(), "CreateWindowEx" );
444 #if OSL_DEBUG_LEVEL > 1
445 // set transparency value
446 if( GetWindowExStyle( hWnd ) & WS_EX_LAYERED )
447 SetLayeredWindowAttributes( hWnd, 0, 230, 0x00000002 /*LWA_ALPHA*/ );
448 #endif
449 if ( !hWnd )
451 delete pFrame;
452 return NULL;
455 // If we have an Window with an Caption Bar and without
456 // an MaximizeBox, we change the SystemMenu
457 if ( (nSysStyle & (WS_CAPTION | WS_MAXIMIZEBOX)) == (WS_CAPTION) )
459 HMENU hSysMenu = GetSystemMenu( hWnd, FALSE );
460 if ( hSysMenu )
462 if ( !(nSysStyle & (WS_MINIMIZEBOX | WS_MAXIMIZEBOX)) )
463 DeleteMenu( hSysMenu, SC_RESTORE, MF_BYCOMMAND );
464 else
465 EnableMenuItem( hSysMenu, SC_RESTORE, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED );
466 if ( !(nSysStyle & WS_MINIMIZEBOX) )
467 DeleteMenu( hSysMenu, SC_MINIMIZE, MF_BYCOMMAND );
468 if ( !(nSysStyle & WS_MAXIMIZEBOX) )
469 DeleteMenu( hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND );
470 if ( !(nSysStyle & WS_THICKFRAME) )
471 DeleteMenu( hSysMenu, SC_SIZE, MF_BYCOMMAND );
474 if ( (nSysStyle & WS_SYSMENU) && !(nSalFrameStyle & SAL_FRAME_STYLE_CLOSEABLE) )
476 HMENU hSysMenu = GetSystemMenu( hWnd, FALSE );
477 if ( hSysMenu )
478 EnableMenuItem( hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED );
481 // reset input context
482 pFrame->mhDefIMEContext = ImmAssociateContext( hWnd, 0 );
484 // determine output size and state
485 RECT aRect;
486 GetClientRect( hWnd, &aRect );
487 pFrame->mnWidth = aRect.right;
488 pFrame->mnHeight = aRect.bottom;
489 ImplSaveFrameState( pFrame );
490 pFrame->mbDefPos = TRUE;
492 UpdateFrameGeometry( hWnd, pFrame );
494 if( pFrame->mnShowState == SW_SHOWMAXIMIZED )
496 // #96084 set a useful internal window size because
497 // the window will not be maximized (and the size updated) before show()
499 SetMaximizedFrameGeometry( hWnd, pFrame );
502 return pFrame;
505 // helper that only creates the HWND
506 // to allow for easy reparenting of system windows, (i.e. destroy and create new)
507 HWND ImplSalReCreateHWND( HWND hWndParent, HWND oldhWnd, sal_Bool bAsChild )
509 HINSTANCE hInstance = GetSalData()->mhInst;
510 sal_uLong nSysStyle = GetWindowLong( oldhWnd, GWL_STYLE );
511 sal_uLong nExSysStyle = GetWindowLong( oldhWnd, GWL_EXSTYLE );
513 if( bAsChild )
515 nSysStyle = WS_CHILD;
516 nExSysStyle = 0;
519 LPCWSTR pClassName = SAL_SUBFRAME_CLASSNAMEW;
520 return CreateWindowExW( nExSysStyle, pClassName, L"", nSysStyle,
521 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
522 hWndParent, 0, hInstance, (void*)GetWindowPtr( oldhWnd ) );
525 // =======================================================================
527 // Uebersetzungstabelle von System-Keycodes in StarView-Keycodes
528 #define KEY_TAB_SIZE 146
530 static sal_uInt16 aImplTranslateKeyTab[KEY_TAB_SIZE] =
532 // StarView-Code System-Code Index
533 0, // 0
534 0, // VK_LBUTTON 1
535 0, // VK_RBUTTON 2
536 0, // VK_CANCEL 3
537 0, // VK_MBUTTON 4
538 0, // 5
539 0, // 6
540 0, // 7
541 KEY_BACKSPACE, // VK_BACK 8
542 KEY_TAB, // VK_TAB 9
543 0, // 10
544 0, // 11
545 0, // VK_CLEAR 12
546 KEY_RETURN, // VK_RETURN 13
547 0, // 14
548 0, // 15
549 0, // VK_SHIFT 16
550 0, // VK_CONTROL 17
551 0, // VK_MENU 18
552 0, // VK_PAUSE 19
553 0, // VK_CAPITAL 20
554 0, // VK_HANGUL 21
555 0, // 22
556 0, // 23
557 0, // 24
558 KEY_HANGUL_HANJA, // VK_HANJA 25
559 0, // 26
560 KEY_ESCAPE, // VK_ESCAPE 27
561 0, // 28
562 0, // 29
563 0, // 30
564 0, // 31
565 KEY_SPACE, // VK_SPACE 32
566 KEY_PAGEUP, // VK_PRIOR 33
567 KEY_PAGEDOWN, // VK_NEXT 34
568 KEY_END, // VK_END 35
569 KEY_HOME, // VK_HOME 36
570 KEY_LEFT, // VK_LEFT 37
571 KEY_UP, // VK_UP 38
572 KEY_RIGHT, // VK_RIGHT 39
573 KEY_DOWN, // VK_DOWN 40
574 0, // VK_SELECT 41
575 0, // VK_PRINT 42
576 0, // VK_EXECUTE 43
577 0, // VK_SNAPSHOT 44
578 KEY_INSERT, // VK_INSERT 45
579 KEY_DELETE, // VK_DELETE 46
580 KEY_HELP, // VK_HELP 47
581 KEY_0, // 48
582 KEY_1, // 49
583 KEY_2, // 50
584 KEY_3, // 51
585 KEY_4, // 52
586 KEY_5, // 53
587 KEY_6, // 54
588 KEY_7, // 55
589 KEY_8, // 56
590 KEY_9, // 57
591 0, // 58
592 0, // 59
593 0, // 60
594 0, // 61
595 0, // 62
596 0, // 63
597 0, // 64
598 KEY_A, // 65
599 KEY_B, // 66
600 KEY_C, // 67
601 KEY_D, // 68
602 KEY_E, // 69
603 KEY_F, // 70
604 KEY_G, // 71
605 KEY_H, // 72
606 KEY_I, // 73
607 KEY_J, // 74
608 KEY_K, // 75
609 KEY_L, // 76
610 KEY_M, // 77
611 KEY_N, // 78
612 KEY_O, // 79
613 KEY_P, // 80
614 KEY_Q, // 81
615 KEY_R, // 82
616 KEY_S, // 83
617 KEY_T, // 84
618 KEY_U, // 85
619 KEY_V, // 86
620 KEY_W, // 87
621 KEY_X, // 88
622 KEY_Y, // 89
623 KEY_Z, // 90
624 0, // VK_LWIN 91
625 0, // VK_RWIN 92
626 KEY_CONTEXTMENU, // VK_APPS 93
627 0, // 94
628 0, // 95
629 KEY_0, // VK_NUMPAD0 96
630 KEY_1, // VK_NUMPAD1 97
631 KEY_2, // VK_NUMPAD2 98
632 KEY_3, // VK_NUMPAD3 99
633 KEY_4, // VK_NUMPAD4 100
634 KEY_5, // VK_NUMPAD5 101
635 KEY_6, // VK_NUMPAD6 102
636 KEY_7, // VK_NUMPAD7 103
637 KEY_8, // VK_NUMPAD8 104
638 KEY_9, // VK_NUMPAD9 105
639 KEY_MULTIPLY, // VK_MULTIPLY 106
640 KEY_ADD, // VK_ADD 107
641 KEY_DECIMAL, // VK_SEPARATOR 108
642 KEY_SUBTRACT, // VK_SUBTRACT 109
643 KEY_DECIMAL, // VK_DECIMAL 110
644 KEY_DIVIDE, // VK_DIVIDE 111
645 KEY_F1, // VK_F1 112
646 KEY_F2, // VK_F2 113
647 KEY_F3, // VK_F3 114
648 KEY_F4, // VK_F4 115
649 KEY_F5, // VK_F5 116
650 KEY_F6, // VK_F6 117
651 KEY_F7, // VK_F7 118
652 KEY_F8, // VK_F8 119
653 KEY_F9, // VK_F9 120
654 KEY_F10, // VK_F10 121
655 KEY_F11, // VK_F11 122
656 KEY_F12, // VK_F12 123
657 KEY_F13, // VK_F13 124
658 KEY_F14, // VK_F14 125
659 KEY_F15, // VK_F15 126
660 KEY_F16, // VK_F16 127
661 KEY_F17, // VK_F17 128
662 KEY_F18, // VK_F18 129
663 KEY_F19, // VK_F19 130
664 KEY_F20, // VK_F20 131
665 KEY_F21, // VK_F21 132
666 KEY_F22, // VK_F22 133
667 KEY_F23, // VK_F23 134
668 KEY_F24, // VK_F24 135
669 0, // 136
670 0, // 137
671 0, // 138
672 0, // 139
673 0, // 140
674 0, // 141
675 0, // 142
676 0, // 143
677 0, // NUMLOCK 144
678 0 // SCROLLLOCK 145
681 // =======================================================================
683 static UINT ImplSalGetWheelScrollLines()
685 UINT nScrLines = 0;
686 HWND hWndMsWheel = WIN_FindWindow( MSH_WHEELMODULE_CLASS, MSH_WHEELMODULE_TITLE );
687 if ( hWndMsWheel )
689 UINT nGetScrollLinesMsgId = RegisterWindowMessage( MSH_SCROLL_LINES );
690 nScrLines = (UINT)ImplSendMessage( hWndMsWheel, nGetScrollLinesMsgId, 0, 0 );
693 if ( !nScrLines )
694 if( !SystemParametersInfo( SPI_GETWHEELSCROLLLINES, 0, &nScrLines, 0 ) )
695 nScrLines = 0 ;
697 if ( !nScrLines )
698 nScrLines = 3;
700 return nScrLines;
703 // -----------------------------------------------------------------------
705 static UINT ImplSalGetWheelScrollChars()
707 UINT nScrChars = 0;
708 if( !SystemParametersInfo( SPI_GETWHEELSCROLLCHARS, 0, &nScrChars, 0 ) )
710 // Depending on Windows version, use proper default or 1 (when
711 // driver emulates hscroll)
712 if( aSalShlData.maVersionInfo.dwMajorVersion < 6 )
714 // Windows 2000 & WinXP : emulating driver, use step size
715 // of 1
716 return 1;
718 else
720 // Longhorn or above: use proper default value of 3
721 return 3;
725 // system settings successfully read
726 return nScrChars;
729 // -----------------------------------------------------------------------
731 static void ImplSalAddBorder( const WinSalFrame* pFrame, int& width, int& height )
733 // transform client size into window size
734 RECT aWinRect;
735 aWinRect.left = 0;
736 aWinRect.right = width-1;
737 aWinRect.top = 0;
738 aWinRect.bottom = height-1;
739 AdjustWindowRectEx( &aWinRect, GetWindowStyle( pFrame->mhWnd ),
740 FALSE, GetWindowExStyle( pFrame->mhWnd ) );
741 width = aWinRect.right - aWinRect.left + 1;
742 height = aWinRect.bottom - aWinRect.top + 1;
745 // -----------------------------------------------------------------------
747 static void ImplSalCalcFullScreenSize( const WinSalFrame* pFrame,
748 int& rX, int& rY, int& rDX, int& rDY )
750 // set window to screen size
751 int nFrameX;
752 int nFrameY;
753 int nCaptionY;
754 int nScreenX = 0;
755 int nScreenY = 0;
756 int nScreenDX = 0;
757 int nScreenDY = 0;
759 if ( pFrame->mbSizeBorder )
761 nFrameX = GetSystemMetrics( SM_CXSIZEFRAME );
762 nFrameY = GetSystemMetrics( SM_CYSIZEFRAME );
764 else if ( pFrame->mbFixBorder )
766 nFrameX = GetSystemMetrics( SM_CXFIXEDFRAME );
767 nFrameY = GetSystemMetrics( SM_CYFIXEDFRAME );
769 else if ( pFrame->mbBorder )
771 nFrameX = GetSystemMetrics( SM_CXBORDER );
772 nFrameY = GetSystemMetrics( SM_CYBORDER );
774 else
776 nFrameX = 0;
777 nFrameY = 0;
779 if ( pFrame->mbCaption )
780 nCaptionY = GetSystemMetrics( SM_CYCAPTION );
781 else
782 nCaptionY = 0;
786 uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
787 uno::Reference< XIndexAccess > xMultiMon( xFactory->createInstance( "com.sun.star.awt.DisplayAccess" ), UNO_QUERY_THROW );
788 sal_Int32 nMonitors = xMultiMon->getCount();
789 if( (pFrame->mnDisplay >= 0) && (pFrame->mnDisplay < nMonitors) )
791 uno::Reference< XPropertySet > xMonitor( xMultiMon->getByIndex( pFrame->mnDisplay ), UNO_QUERY_THROW );
792 com::sun::star::awt::Rectangle aRect;
793 if( xMonitor->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "ScreenArea" ) ) ) >>= aRect )
795 nScreenX = aRect.X;
796 nScreenY = aRect.Y;
797 nScreenDX = aRect.Width+1; // difference between java/awt convention and vcl
798 nScreenDY = aRect.Height+1; // difference between java/awt convention and vcl
801 else
803 Rectangle aCombined;
804 uno::Reference< XPropertySet > xMonitor( xMultiMon->getByIndex( 0 ), UNO_QUERY_THROW );
805 com::sun::star::awt::Rectangle aRect;
806 if( xMonitor->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "ScreenArea" ) ) ) >>= aRect )
808 aCombined.Left() = aRect.X;
809 aCombined.Top() = aRect.Y;
810 aCombined.Right() = aRect.X + aRect.Width;
811 aCombined.Bottom() = aRect.Y + aRect.Height;
812 for( sal_Int32 i = 1 ; i < nMonitors ; i++ )
814 xMonitor = uno::Reference< XPropertySet >( xMultiMon->getByIndex(i), UNO_QUERY_THROW );
815 if( xMonitor->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "ScreenArea" ) ) ) >>= aRect )
817 aCombined.Union( Rectangle( aRect.X, aRect.Y, aRect.X+aRect.Width, aRect.Y+aRect.Height ) );
821 nScreenX = aCombined.Left();
822 nScreenY = aCombined.Top();
823 nScreenDX = aCombined.GetWidth();
824 nScreenDY = aCombined.GetHeight();
827 catch( Exception& )
831 if( !nScreenDX || !nScreenDY )
833 nScreenDX = GetSystemMetrics( SM_CXSCREEN );
834 nScreenDY = GetSystemMetrics( SM_CYSCREEN );
837 rX = nScreenX -nFrameX;
838 rY = nScreenY -(nFrameY+nCaptionY);
839 rDX = nScreenDX+(nFrameX*2);
840 rDY = nScreenDY+(nFrameY*2)+nCaptionY;
843 // -----------------------------------------------------------------------
845 static void ImplSalFrameFullScreenPos( WinSalFrame* pFrame, sal_Bool bAlways = FALSE )
847 if ( bAlways || !IsIconic( pFrame->mhWnd ) )
849 // set window to screen size
850 int nX;
851 int nY;
852 int nWidth;
853 int nHeight;
854 ImplSalCalcFullScreenSize( pFrame, nX, nY, nWidth, nHeight );
855 SetWindowPos( pFrame->mhWnd, 0,
856 nX, nY, nWidth, nHeight,
857 SWP_NOZORDER | SWP_NOACTIVATE );
861 // -----------------------------------------------------------------------
863 WinSalFrame::WinSalFrame()
865 SalData* pSalData = GetSalData();
867 mhWnd = 0;
868 mhCursor = LoadCursor( 0, IDC_ARROW );
869 mhDefIMEContext = 0;
870 mpGraphics = NULL;
871 mpGraphics2 = NULL;
872 mnShowState = SW_SHOWNORMAL;
873 mnWidth = 0;
874 mnHeight = 0;
875 mnMinWidth = 0;
876 mnMinHeight = 0;
877 mnMaxWidth = SHRT_MAX;
878 mnMaxHeight = SHRT_MAX;
879 mnInputLang = 0;
880 mnInputCodePage = 0;
881 mbGraphics = FALSE;
882 mbCaption = FALSE;
883 mbBorder = FALSE;
884 mbFixBorder = FALSE;
885 mbSizeBorder = FALSE;
886 mbFullScreen = FALSE;
887 mbPresentation = FALSE;
888 mbInShow = FALSE;
889 mbRestoreMaximize = FALSE;
890 mbInMoveMsg = FALSE;
891 mbInSizeMsg = FALSE;
892 mbFullScreenToolWin = FALSE;
893 mbDefPos = TRUE;
894 mbOverwriteState = TRUE;
895 mbIME = FALSE;
896 mbHandleIME = FALSE;
897 mbSpezIME = FALSE;
898 mbAtCursorIME = FALSE;
899 mbCandidateMode = FALSE;
900 mbFloatWin = FALSE;
901 mbNoIcon = FALSE;
902 mSelectedhMenu = 0;
903 mLastActivatedhMenu = 0;
904 mpClipRgnData = NULL;
905 mbFirstClipRect = TRUE;
906 mpNextClipRect = NULL;
907 mnDisplay = 0;
909 memset( &maState, 0, sizeof( SalFrameState ) );
910 maSysData.nSize = sizeof( SystemEnvData );
912 memset( &maGeometry, 0, sizeof( maGeometry ) );
914 // Daten ermitteln, wenn erster Frame angelegt wird
915 if ( !pSalData->mpFirstFrame )
917 if ( !aSalShlData.mnWheelMsgId )
918 aSalShlData.mnWheelMsgId = RegisterWindowMessage( MSH_MOUSEWHEEL );
919 if ( !aSalShlData.mnWheelScrollLines )
920 aSalShlData.mnWheelScrollLines = ImplSalGetWheelScrollLines();
921 if ( !aSalShlData.mnWheelScrollChars )
922 aSalShlData.mnWheelScrollChars = ImplSalGetWheelScrollChars();
925 // insert frame in framelist
926 mpNextFrame = pSalData->mpFirstFrame;
927 pSalData->mpFirstFrame = this;
930 // -----------------------------------------------------------------------
931 void WinSalFrame::updateScreenNumber()
933 if( mnDisplay == -1 ) // spans all monitors
934 return;
935 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
936 if( pSys )
938 const std::vector<WinSalSystem::DisplayMonitor>& rMonitors =
939 pSys->getMonitors();
940 Point aPoint( maGeometry.nX, maGeometry.nY );
941 size_t nMon = rMonitors.size();
942 for( size_t i = 0; i < nMon; i++ )
944 if( rMonitors[i].m_aArea.IsInside( aPoint ) )
946 mnDisplay = static_cast<sal_Int32>(i);
947 maGeometry.nDisplayScreenNumber = static_cast<unsigned int>(i);
953 // -----------------------------------------------------------------------
955 WinSalFrame::~WinSalFrame()
957 SalData* pSalData = GetSalData();
959 if( mpClipRgnData )
960 delete [] (BYTE*)mpClipRgnData;
962 // remove frame from framelist
963 WinSalFrame** ppFrame = &pSalData->mpFirstFrame;
964 for(; (*ppFrame != this) && *ppFrame; ppFrame = &(*ppFrame)->mpNextFrame );
965 if( *ppFrame )
966 *ppFrame = mpNextFrame;
967 mpNextFrame = NULL;
969 // Release Cache DC
970 if ( mpGraphics2 &&
971 mpGraphics2->mhDC )
972 ReleaseGraphics( mpGraphics2 );
974 // destroy saved DC
975 if ( mpGraphics )
977 if ( mpGraphics->mhDefPal )
978 SelectPalette( mpGraphics->mhDC, mpGraphics->mhDefPal, TRUE );
979 ImplSalDeInitGraphics( mpGraphics );
980 ReleaseDC( mhWnd, mpGraphics->mhDC );
981 delete mpGraphics;
982 mpGraphics = NULL;
985 if ( mhWnd )
987 // reset mouse leave data
988 if ( pSalData->mhWantLeaveMsg == mhWnd )
990 pSalData->mhWantLeaveMsg = 0;
991 if ( pSalData->mpMouseLeaveTimer )
993 delete pSalData->mpMouseLeaveTimer;
994 pSalData->mpMouseLeaveTimer = NULL;
998 // destroy system frame
999 if ( !DestroyWindow( mhWnd ) )
1000 SetWindowPtr( mhWnd, 0 );
1002 mhWnd = 0;
1006 // -----------------------------------------------------------------------
1008 SalGraphics* WinSalFrame::GetGraphics()
1010 if ( mbGraphics )
1011 return NULL;
1013 // Other threads get an own DC, because Windows modify in the
1014 // other case our DC (changing clip region), when they send a
1015 // WM_ERASEBACKGROUND message
1016 SalData* pSalData = GetSalData();
1017 if ( pSalData->mnAppThreadId != GetCurrentThreadId() )
1019 // We use only three CacheDC's for all threads, because W9x is limited
1020 // to max. 5 Cache DC's per thread
1021 if ( pSalData->mnCacheDCInUse >= 3 )
1022 return NULL;
1024 if ( !mpGraphics2 )
1026 mpGraphics2 = new WinSalGraphics;
1027 mpGraphics2->mhDC = 0;
1028 mpGraphics2->mhWnd = mhWnd;
1029 mpGraphics2->mbPrinter = FALSE;
1030 mpGraphics2->mbVirDev = FALSE;
1031 mpGraphics2->mbWindow = TRUE;
1032 mpGraphics2->mbScreen = TRUE;
1035 HDC hDC = (HDC)ImplSendMessage( pSalData->mpFirstInstance->mhComWnd,
1036 SAL_MSG_GETDC,
1037 (WPARAM)mhWnd, 0 );
1038 if ( hDC )
1040 mpGraphics2->mhDC = hDC;
1041 if ( pSalData->mhDitherPal )
1043 mpGraphics2->mhDefPal = SelectPalette( hDC, pSalData->mhDitherPal, TRUE );
1044 RealizePalette( hDC );
1046 ImplSalInitGraphics( mpGraphics2 );
1047 mbGraphics = TRUE;
1049 pSalData->mnCacheDCInUse++;
1050 return mpGraphics2;
1052 else
1053 return NULL;
1055 else
1057 if ( !mpGraphics )
1059 HDC hDC = GetDC( mhWnd );
1060 if ( hDC )
1062 mpGraphics = new WinSalGraphics;
1063 mpGraphics->mhDC = hDC;
1064 mpGraphics->mhWnd = mhWnd;
1065 mpGraphics->mbPrinter = FALSE;
1066 mpGraphics->mbVirDev = FALSE;
1067 mpGraphics->mbWindow = TRUE;
1068 mpGraphics->mbScreen = TRUE;
1069 if ( pSalData->mhDitherPal )
1071 mpGraphics->mhDefPal = SelectPalette( hDC, pSalData->mhDitherPal, TRUE );
1072 RealizePalette( hDC );
1074 ImplSalInitGraphics( mpGraphics );
1075 mbGraphics = TRUE;
1078 else
1079 mbGraphics = TRUE;
1081 return mpGraphics;
1085 // -----------------------------------------------------------------------
1087 void WinSalFrame::ReleaseGraphics( SalGraphics* pGraphics )
1089 if ( mpGraphics2 == pGraphics )
1091 if ( mpGraphics2->mhDC )
1093 SalData* pSalData = GetSalData();
1094 if ( mpGraphics2->mhDefPal )
1095 SelectPalette( mpGraphics2->mhDC, mpGraphics2->mhDefPal, TRUE );
1096 ImplSalDeInitGraphics( mpGraphics2 );
1097 ImplSendMessage( pSalData->mpFirstInstance->mhComWnd,
1098 SAL_MSG_RELEASEDC,
1099 (WPARAM)mhWnd,
1100 (LPARAM)mpGraphics2->mhDC );
1101 mpGraphics2->mhDC = 0;
1102 pSalData->mnCacheDCInUse--;
1106 mbGraphics = FALSE;
1109 // -----------------------------------------------------------------------
1111 sal_Bool WinSalFrame::PostEvent( void* pData )
1113 return (sal_Bool)ImplPostMessage( mhWnd, SAL_MSG_USEREVENT, 0, (LPARAM)pData );
1116 // -----------------------------------------------------------------------
1118 void WinSalFrame::SetTitle( const rtl::OUString& rTitle )
1120 DBG_ASSERT( sizeof( WCHAR ) == sizeof( sal_Unicode ), "WinSalFrame::SetTitle(): WCHAR != sal_Unicode" );
1122 SetWindowTextW( mhWnd, reinterpret_cast<LPCWSTR>(rTitle.getStr()) );
1125 // -----------------------------------------------------------------------
1127 void WinSalFrame::SetIcon( sal_uInt16 nIcon )
1129 // If we have a window without an Icon (for example a dialog), ignore this call
1130 if ( mbNoIcon )
1131 return;
1133 // 0 means default (class) icon
1134 HICON hIcon = NULL, hSmIcon = NULL;
1135 if ( !nIcon )
1136 nIcon = 1;
1138 ImplLoadSalIcon( nIcon, hIcon, hSmIcon );
1140 DBG_ASSERT( hIcon , "WinSalFrame::SetIcon(): Could not load large icon !" );
1141 DBG_ASSERT( hSmIcon , "WinSalFrame::SetIcon(): Could not load small icon !" );
1143 ImplSendMessage( mhWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon );
1144 ImplSendMessage( mhWnd, WM_SETICON, ICON_SMALL, (LPARAM)hSmIcon );
1147 // -----------------------------------------------------------------------
1149 void WinSalFrame::SetMenu( SalMenu* pSalMenu )
1151 WinSalMenu* pWMenu = static_cast<WinSalMenu*>(pSalMenu);
1152 if( pSalMenu && pWMenu->mbMenuBar )
1153 ::SetMenu( mhWnd, pWMenu->mhMenu );
1156 void WinSalFrame::DrawMenuBar()
1158 ::DrawMenuBar( mhWnd );
1161 // -----------------------------------------------------------------------
1162 HWND ImplGetParentHwnd( HWND hWnd )
1164 WinSalFrame* pFrame = GetWindowPtr( hWnd );
1165 if( !pFrame || !pFrame->GetWindow())
1166 return ::GetParent( hWnd );
1167 Window *pRealParent = pFrame->GetWindow()->ImplGetWindowImpl()->mpRealParent;
1168 if( pRealParent )
1169 return static_cast<WinSalFrame*>(pRealParent->ImplGetWindowImpl()->mpFrame)->mhWnd;
1170 else
1171 return ::GetParent( hWnd );
1175 // -----------------------------------------------------------------------
1177 SalFrame* WinSalFrame::GetParent() const
1179 return GetWindowPtr( ImplGetParentHwnd( mhWnd ) );
1182 // -----------------------------------------------------------------------
1184 static void ImplSalShow( HWND hWnd, sal_Bool bVisible, sal_Bool bNoActivate )
1186 WinSalFrame* pFrame = GetWindowPtr( hWnd );
1187 if ( !pFrame )
1188 return;
1190 if ( bVisible )
1192 pFrame->mbDefPos = FALSE;
1193 pFrame->mbOverwriteState = TRUE;
1194 pFrame->mbInShow = TRUE;
1196 // #i4715, save position
1197 RECT aRectPreMatrox, aRectPostMatrox;
1198 GetWindowRect( hWnd, &aRectPreMatrox );
1200 vcl::DeletionListener aDogTag( pFrame );
1201 if( bNoActivate )
1202 ShowWindow( hWnd, SW_SHOWNOACTIVATE );
1203 else
1204 ShowWindow( hWnd, pFrame->mnShowState );
1205 if( aDogTag.isDeleted() )
1206 return;
1208 if ( aSalShlData.mbWXP && pFrame->mbFloatWin && !(pFrame->mnStyle & SAL_FRAME_STYLE_NOSHADOW))
1210 // erase the window immediately to improve XP shadow effect
1211 // otherwise the shadow may appears long time before the rest of the window
1212 // especially when accessibility is on
1213 HDC dc = GetDC( hWnd );
1214 RECT aRect;
1215 GetClientRect( hWnd, &aRect );
1216 FillRect( dc, &aRect, (HBRUSH) (COLOR_MENU+1) ); // choose the menucolor, because its mostly noticeable for menus
1217 ReleaseDC( hWnd, dc );
1220 // #i4715, matrox centerpopup might have changed our position
1221 // reposition popups without caption (menus, dropdowns, tooltips)
1222 GetWindowRect( hWnd, &aRectPostMatrox );
1223 if( (GetWindowStyle( hWnd ) & WS_POPUP) &&
1224 !pFrame->mbCaption &&
1225 (aRectPreMatrox.left != aRectPostMatrox.left || aRectPreMatrox.top != aRectPostMatrox.top) )
1226 SetWindowPos( hWnd, 0, aRectPreMatrox.left, aRectPreMatrox.top, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE );
1228 if( aDogTag.isDeleted() )
1229 return;
1230 Window *pClientWin = pFrame->GetWindow()->ImplGetClientWindow();
1231 if ( pFrame->mbFloatWin || ( pClientWin && (pClientWin->GetStyle() & WB_SYSTEMFLOATWIN) ) )
1232 pFrame->mnShowState = SW_SHOWNOACTIVATE;
1233 else
1234 pFrame->mnShowState = SW_SHOW;
1235 // Damit Taskleiste unter W98 auch gleich ausgeblendet wird
1236 if ( pFrame->mbPresentation )
1238 HWND hWndParent = ::GetParent( hWnd );
1239 if ( hWndParent )
1240 SetForegroundWindow( hWndParent );
1241 SetForegroundWindow( hWnd );
1244 pFrame->mbInShow = FALSE;
1245 pFrame->updateScreenNumber();
1247 // Direct Paint only, if we get the SolarMutx
1248 if ( ImplSalYieldMutexTryToAcquire() )
1250 UpdateWindow( hWnd );
1251 ImplSalYieldMutexRelease();
1254 else
1256 ShowWindow( hWnd, SW_HIDE );
1260 // -----------------------------------------------------------------------
1263 void WinSalFrame::SetExtendedFrameStyle( SalExtStyle )
1267 // -----------------------------------------------------------------------
1269 void WinSalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
1271 // Post this Message to the window, because this only works
1272 // in the thread of the window, which has create this window.
1273 // We post this message to avoid deadlocks
1274 if ( GetSalData()->mnAppThreadId != GetCurrentThreadId() )
1275 ImplPostMessage( mhWnd, SAL_MSG_SHOW, bVisible, bNoActivate );
1276 else
1277 ImplSalShow( mhWnd, bVisible, bNoActivate );
1280 // -----------------------------------------------------------------------
1282 void WinSalFrame::Enable( sal_Bool bEnable )
1284 EnableWindow( mhWnd, bEnable );
1287 // -----------------------------------------------------------------------
1289 void WinSalFrame::SetMinClientSize( long nWidth, long nHeight )
1291 mnMinWidth = nWidth;
1292 mnMinHeight = nHeight;
1295 void WinSalFrame::SetMaxClientSize( long nWidth, long nHeight )
1297 mnMaxWidth = nWidth;
1298 mnMaxHeight = nHeight;
1301 // -----------------------------------------------------------------------
1303 void WinSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight,
1304 sal_uInt16 nFlags )
1306 sal_Bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
1307 if ( !bVisible )
1309 Window *pClientWin = GetWindow()->ImplGetClientWindow();
1310 if ( mbFloatWin || ( pClientWin && (pClientWin->GetStyle() & WB_SYSTEMFLOATWIN) ) )
1311 mnShowState = SW_SHOWNOACTIVATE;
1312 else
1313 mnShowState = SW_SHOWNORMAL;
1315 else
1317 if ( IsIconic( mhWnd ) || IsZoomed( mhWnd ) )
1318 ShowWindow( mhWnd, SW_RESTORE );
1321 sal_uInt16 nEvent = 0;
1322 UINT nPosSize = 0;
1323 RECT aClientRect, aWindowRect;
1324 GetClientRect( mhWnd, &aClientRect ); // x,y always 0,0, but width and height without border
1325 GetWindowRect( mhWnd, &aWindowRect ); // x,y in screen coordinates, width and height with border
1327 if ( !(nFlags & (SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y)) )
1328 nPosSize |= SWP_NOMOVE;
1329 else
1331 //DBG_ASSERT( nX && nY, " Windowposition of (0,0) requested!" );
1332 nEvent = SALEVENT_MOVE;
1334 if ( !(nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) )
1335 nPosSize |= SWP_NOSIZE;
1336 else
1337 nEvent = (nEvent == SALEVENT_MOVE) ? SALEVENT_MOVERESIZE : SALEVENT_RESIZE;
1339 if ( !(nFlags & SAL_FRAME_POSSIZE_X) )
1340 nX = aWindowRect.left;
1341 if ( !(nFlags & SAL_FRAME_POSSIZE_Y) )
1342 nY = aWindowRect.top;
1343 if ( !(nFlags & SAL_FRAME_POSSIZE_WIDTH) )
1344 nWidth = aClientRect.right-aClientRect.left;
1345 if ( !(nFlags & SAL_FRAME_POSSIZE_HEIGHT) )
1346 nHeight = aClientRect.bottom-aClientRect.top;
1348 // Calculate window size including the border
1349 RECT aWinRect;
1350 aWinRect.left = 0;
1351 aWinRect.right = (int)nWidth-1;
1352 aWinRect.top = 0;
1353 aWinRect.bottom = (int)nHeight-1;
1354 AdjustWindowRectEx( &aWinRect, GetWindowStyle( mhWnd ),
1355 FALSE, GetWindowExStyle( mhWnd ) );
1356 nWidth = aWinRect.right - aWinRect.left + 1;
1357 nHeight = aWinRect.bottom - aWinRect.top + 1;
1359 if ( !(nPosSize & SWP_NOMOVE) && ::GetParent( mhWnd ) )
1361 // --- RTL --- (mirror window pos)
1362 RECT aParentRect;
1363 GetClientRect( ImplGetParentHwnd( mhWnd ), &aParentRect );
1364 if( Application::GetSettings().GetLayoutRTL() )
1365 nX = (aParentRect.right - aParentRect.left) - nWidth-1 - nX;
1367 //#110386#, do not transform coordinates for system child windows
1368 if( !(GetWindowStyle( mhWnd ) & WS_CHILD) )
1370 POINT aPt;
1371 aPt.x = nX;
1372 aPt.y = nY;
1374 HWND parentHwnd = ImplGetParentHwnd( mhWnd );
1375 WinSalFrame* pParentFrame = GetWindowPtr( parentHwnd );
1376 if ( pParentFrame && pParentFrame->mnShowState == SW_SHOWMAXIMIZED )
1378 // #i42485#: parent will be shown maximized in which case
1379 // a ClientToScreen uses the wrong coordinates (i.e. those from the restore pos)
1380 // so use the (already updated) frame geometry for the transformation
1381 aPt.x += pParentFrame->maGeometry.nX;
1382 aPt.y += pParentFrame->maGeometry.nY;
1384 else
1385 ClientToScreen( parentHwnd, &aPt );
1387 nX = aPt.x;
1388 nY = aPt.y;
1392 // #i3338# to be conformant to UNIX we must position the client window, ie without the decoration
1393 // #i43250# if the position was read from the system (GetWindowRect(), see above), it must not be modified
1394 if ( nFlags & SAL_FRAME_POSSIZE_X )
1395 nX += aWinRect.left;
1396 if ( nFlags & SAL_FRAME_POSSIZE_Y )
1397 nY += aWinRect.top;
1399 int nScreenX;
1400 int nScreenY;
1401 int nScreenWidth;
1402 int nScreenHeight;
1405 RECT aRect;
1406 ImplSalGetWorkArea( mhWnd, &aRect, NULL );
1407 nScreenX = aRect.left;
1408 nScreenY = aRect.top;
1409 nScreenWidth = aRect.right-aRect.left;
1410 nScreenHeight = aRect.bottom-aRect.top;
1412 if ( mbDefPos && (nPosSize & SWP_NOMOVE)) // we got no positioning request, so choose default position
1414 // center window
1416 HWND hWndParent = ::GetParent( mhWnd );
1417 // Search for TopLevel Frame
1418 while ( hWndParent && (GetWindowStyle( hWndParent ) & WS_CHILD) )
1419 hWndParent = ::GetParent( hWndParent );
1420 // if the Window has a Parent, than center the window to
1421 // the parent, in the other case to the screen
1422 if ( hWndParent && !IsIconic( hWndParent ) &&
1423 (GetWindowStyle( hWndParent ) & WS_VISIBLE) )
1425 RECT aParentRect;
1426 GetWindowRect( hWndParent, &aParentRect );
1427 int nParentWidth = aParentRect.right-aParentRect.left;
1428 int nParentHeight = aParentRect.bottom-aParentRect.top;
1430 // We don't center, when Parent is smaller than our window
1431 if ( (nParentWidth-GetSystemMetrics( SM_CXFIXEDFRAME ) <= nWidth) &&
1432 (nParentHeight-GetSystemMetrics( SM_CYFIXEDFRAME ) <= nHeight) )
1434 int nOff = GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION );
1435 nX = aParentRect.left+nOff;
1436 nY = aParentRect.top+nOff;
1438 else
1440 nX = (nParentWidth-nWidth)/2 + aParentRect.left;
1441 nY = (nParentHeight-nHeight)/2 + aParentRect.top;
1444 else
1446 POINT pt;
1447 GetCursorPos( &pt );
1448 RECT aRect2;
1449 aRect2.left = pt.x;
1450 aRect2.top = pt.y;
1451 aRect2.right = pt.x+2;
1452 aRect2.bottom = pt.y+2;
1454 // dualmonitor support:
1455 // Get screensize of the monitor whith the mouse pointer
1456 ImplSalGetWorkArea( mhWnd, &aRect2, &aRect2 );
1458 nX = ((aRect2.right-aRect2.left)-nWidth)/2 + aRect2.left;
1459 nY = ((aRect2.bottom-aRect2.top)-nHeight)/2 + aRect2.top;
1463 //if ( bVisible )
1464 // mbDefPos = FALSE;
1466 mbDefPos = FALSE; // center only once
1467 nPosSize &= ~SWP_NOMOVE; // activate positioning
1468 nEvent = SALEVENT_MOVERESIZE;
1472 // Adjust Window in the screen
1473 sal_Bool bCheckOffScreen = TRUE;
1475 // but don't do this for floaters or ownerdraw windows that are currently moved interactively
1476 if( (mnStyle & SAL_FRAME_STYLE_FLOAT) && !(mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
1477 bCheckOffScreen = FALSE;
1479 if( mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION )
1481 // may be the window is currently being moved (mouse is captured), then no check is required
1482 if( mhWnd == ::GetCapture() )
1483 bCheckOffScreen = FALSE;
1484 else
1485 bCheckOffScreen = TRUE;
1488 if( bCheckOffScreen )
1490 if ( nX+nWidth > nScreenX+nScreenWidth )
1491 nX = (nScreenX+nScreenWidth) - nWidth;
1492 if ( nY+nHeight > nScreenY+nScreenHeight )
1493 nY = (nScreenY+nScreenHeight) - nHeight;
1494 if ( nX < nScreenX )
1495 nX = nScreenX;
1496 if ( nY < nScreenY )
1497 nY = nScreenY;
1500 UINT nPosFlags = SWP_NOACTIVATE | SWP_NOOWNERZORDER | nPosSize;
1501 // bring floating windows always to top
1502 if( !(mnStyle & SAL_FRAME_STYLE_FLOAT) )
1503 nPosFlags |= SWP_NOZORDER; // do not change z-order
1505 SetWindowPos( mhWnd, HWND_TOP, nX, nY, (int)nWidth, (int)nHeight, nPosFlags );
1507 UpdateFrameGeometry( mhWnd, this );
1509 // Notification -- really ???
1510 if( nEvent )
1511 CallCallback( nEvent, NULL );
1514 // -----------------------------------------------------------------------
1516 static void ImplSetParentFrame( WinSalFrame* pThis, HWND hNewParentWnd, sal_Bool bAsChild )
1518 // save hwnd, will be overwritten in WM_CREATE during createwindow
1519 HWND hWndOld = pThis->mhWnd;
1520 HWND hWndOldParent = ::GetParent( hWndOld );
1521 SalData* pSalData = GetSalData();
1523 if( hNewParentWnd == hWndOldParent )
1524 return;
1526 ::std::vector< WinSalFrame* > children;
1527 ::std::vector< WinSalObject* > systemChildren;
1529 // search child windows
1530 WinSalFrame *pFrame = pSalData->mpFirstFrame;
1531 while( pFrame )
1533 HWND hWndParent = ::GetParent( pFrame->mhWnd );
1534 if( pThis->mhWnd == hWndParent )
1535 children.push_back( pFrame );
1536 pFrame = pFrame->mpNextFrame;
1539 // search system child windows (plugins etc.)
1540 WinSalObject *pObject = pSalData->mpFirstObject;
1541 while( pObject )
1543 HWND hWndParent = ::GetParent( pObject->mhWnd );
1544 if( pThis->mhWnd == hWndParent )
1545 systemChildren.push_back( pObject );
1546 pObject = pObject->mpNextObject;
1549 sal_Bool bNeedGraphics = pThis->mbGraphics;
1550 sal_Bool bNeedCacheDC = FALSE;
1552 HFONT hFont = NULL;
1553 HPEN hPen = NULL;
1554 HBRUSH hBrush = NULL;
1556 #if OSL_DEBUG_LEVEL > 0
1557 int oldCount = pSalData->mnCacheDCInUse;
1558 (void)oldCount;
1559 #endif
1561 // Release Cache DC
1562 if ( pThis->mpGraphics2 &&
1563 pThis->mpGraphics2->mhDC )
1565 // save current gdi objects before hdc is gone
1566 hFont = (HFONT) GetCurrentObject( pThis->mpGraphics2->mhDC, OBJ_FONT);
1567 hPen = (HPEN) GetCurrentObject( pThis->mpGraphics2->mhDC, OBJ_PEN);
1568 hBrush = (HBRUSH) GetCurrentObject( pThis->mpGraphics2->mhDC, OBJ_BRUSH);
1569 pThis->ReleaseGraphics( pThis->mpGraphics2 );
1571 // recreate cache dc only if it was destroyed
1572 bNeedCacheDC = TRUE;
1575 // destroy saved DC
1576 if ( pThis->mpGraphics )
1578 if ( pThis->mpGraphics->mhDefPal )
1579 SelectPalette( pThis->mpGraphics->mhDC, pThis->mpGraphics->mhDefPal, TRUE );
1580 ImplSalDeInitGraphics( pThis->mpGraphics );
1581 ReleaseDC( pThis->mhWnd, pThis->mpGraphics->mhDC );
1584 // create a new hwnd with the same styles
1585 HWND hWndParent = hNewParentWnd;
1586 // forward to main thread
1587 HWND hWnd = (HWND) ImplSendMessage( pSalData->mpFirstInstance->mhComWnd,
1588 bAsChild ? SAL_MSG_RECREATECHILDHWND : SAL_MSG_RECREATEHWND,
1589 (WPARAM) hWndParent, (LPARAM)pThis->mhWnd );
1591 // succeeded ?
1592 DBG_ASSERT( IsWindow( hWnd ), "WinSalFrame::SetParent not successful");
1594 // recreate DCs
1595 if( bNeedGraphics )
1597 if( pThis->mpGraphics2 )
1599 pThis->mpGraphics2->mhWnd = hWnd;
1601 if( bNeedCacheDC )
1603 // re-create cached DC
1604 HDC hDC = (HDC)ImplSendMessage( pSalData->mpFirstInstance->mhComWnd,
1605 SAL_MSG_GETDC,
1606 (WPARAM) hWnd, 0 );
1607 if ( hDC )
1609 pThis->mpGraphics2->mhDC = hDC;
1610 if ( pSalData->mhDitherPal )
1612 pThis->mpGraphics2->mhDefPal = SelectPalette( hDC, pSalData->mhDitherPal, TRUE );
1613 RealizePalette( hDC );
1615 ImplSalInitGraphics( pThis->mpGraphics2 );
1617 // re-select saved gdi objects
1618 if( hFont )
1619 SelectObject( hDC, hFont );
1620 if( hPen )
1621 SelectObject( hDC, hPen );
1622 if( hBrush )
1623 SelectObject( hDC, hBrush );
1625 pThis->mbGraphics = TRUE;
1627 pSalData->mnCacheDCInUse++;
1629 DBG_ASSERT( oldCount == pSalData->mnCacheDCInUse, "WinSalFrame::SetParent() hDC count corrupted");
1634 if( pThis->mpGraphics )
1636 // re-create DC
1637 pThis->mpGraphics->mhWnd = hWnd;
1638 pThis->mpGraphics->mhDC = GetDC( hWnd );
1639 if ( GetSalData()->mhDitherPal )
1641 pThis->mpGraphics->mhDefPal = SelectPalette( pThis->mpGraphics->mhDC, GetSalData()->mhDitherPal, TRUE );
1642 RealizePalette( pThis->mpGraphics->mhDC );
1644 ImplSalInitGraphics( pThis->mpGraphics );
1645 pThis->mbGraphics = TRUE;
1650 // TODO: add SetParent() call for SalObjects
1651 DBG_ASSERT( systemChildren.empty(), "WinSalFrame::SetParent() parent of living system child window will be destroyed!");
1653 // reparent children before old parent is destroyed
1654 for( ::std::vector< WinSalFrame* >::iterator iChild = children.begin(); iChild != children.end(); ++iChild )
1655 ImplSetParentFrame( *iChild, hWnd, FALSE );
1657 children.clear();
1658 systemChildren.clear();
1660 // Now destroy original HWND in the thread where it was created.
1661 ImplSendMessage( GetSalData()->mpFirstInstance->mhComWnd,
1662 SAL_MSG_DESTROYHWND, (WPARAM) 0, (LPARAM)hWndOld);
1665 // -----------------------------------------------------------------------
1667 void WinSalFrame::SetParent( SalFrame* pNewParent )
1669 WinSalFrame::mbInReparent = TRUE;
1670 ImplSetParentFrame( this, static_cast<WinSalFrame*>(pNewParent)->mhWnd, FALSE );
1671 WinSalFrame::mbInReparent = FALSE;
1674 bool WinSalFrame::SetPluginParent( SystemParentData* pNewParent )
1676 if ( pNewParent->hWnd == 0 )
1678 pNewParent->hWnd = GetDesktopWindow();
1681 WinSalFrame::mbInReparent = TRUE;
1682 ImplSetParentFrame( this, pNewParent->hWnd, TRUE );
1683 WinSalFrame::mbInReparent = FALSE;
1684 return true;
1688 // -----------------------------------------------------------------------
1690 void WinSalFrame::GetWorkArea( Rectangle &rRect )
1692 RECT aRect;
1693 ImplSalGetWorkArea( mhWnd, &aRect, NULL );
1694 rRect.Left() = aRect.left;
1695 rRect.Right() = aRect.right-1;
1696 rRect.Top() = aRect.top;
1697 rRect.Bottom() = aRect.bottom-1;
1700 // -----------------------------------------------------------------------
1702 void WinSalFrame::GetClientSize( long& rWidth, long& rHeight )
1704 rWidth = maGeometry.nWidth;
1705 rHeight = maGeometry.nHeight;
1708 // -----------------------------------------------------------------------
1710 void WinSalFrame::SetWindowState( const SalFrameState* pState )
1712 // Wir testen, ob das Fenster ueberhaupt auf den Bildschirm passt, damit
1713 // nicht wenn die Bildschirm-Aufloesung geaendert wurde, das Fenster aus
1714 // diesem herausragt
1715 int nX;
1716 int nY;
1717 int nWidth;
1718 int nHeight;
1719 int nScreenX;
1720 int nScreenY;
1721 int nScreenWidth;
1722 int nScreenHeight;
1724 RECT aRect;
1725 ImplSalGetWorkArea( mhWnd, &aRect, NULL );
1726 // #102500# allow some overlap, the window could have been made a little larger than the physical screen
1727 nScreenX = aRect.left-10;
1728 nScreenY = aRect.top-10;
1729 nScreenWidth = aRect.right-aRect.left+20;
1730 nScreenHeight = aRect.bottom-aRect.top+20;
1732 UINT nPosSize = 0;
1733 RECT aWinRect;
1734 GetWindowRect( mhWnd, &aWinRect );
1736 // to be consistent with Unix, the frame state is without(!) decoration
1737 // ->add the decoration
1738 RECT aRect2 = aWinRect;
1739 AdjustWindowRectEx( &aRect2, GetWindowStyle( mhWnd ),
1740 FALSE, GetWindowExStyle( mhWnd ) );
1741 long nTopDeco = abs( aWinRect.top - aRect2.top );
1742 long nLeftDeco = abs( aWinRect.left - aRect2.left );
1743 long nBottomDeco = abs( aWinRect.bottom - aRect2.bottom );
1744 long nRightDeco = abs( aWinRect.right - aRect2.right );
1746 // Fenster-Position/Groesse in den Bildschirm einpassen
1747 if ( !(pState->mnMask & (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_Y)) )
1748 nPosSize |= SWP_NOMOVE;
1749 if ( !(pState->mnMask & (SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT)) )
1750 nPosSize |= SWP_NOSIZE;
1751 if ( pState->mnMask & SAL_FRAMESTATE_MASK_X )
1752 nX = (int)pState->mnX - nLeftDeco;
1753 else
1754 nX = aWinRect.left;
1755 if ( pState->mnMask & SAL_FRAMESTATE_MASK_Y )
1756 nY = (int)pState->mnY - nTopDeco;
1757 else
1758 nY = aWinRect.top;
1759 if ( pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH )
1760 nWidth = (int)pState->mnWidth + nLeftDeco + nRightDeco;
1761 else
1762 nWidth = aWinRect.right-aWinRect.left;
1763 if ( pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT )
1764 nHeight = (int)pState->mnHeight + nTopDeco + nBottomDeco;
1765 else
1766 nHeight = aWinRect.bottom-aWinRect.top;
1768 // Adjust Window in the screen:
1769 // if it does not fit into the screen do nothing, ie default pos/size will be used
1770 // if there is an overlap with the screen border move the window while keeping its size
1772 if( nWidth > nScreenWidth || nHeight > nScreenHeight )
1773 nPosSize |= (SWP_NOMOVE | SWP_NOSIZE);
1775 if ( nX+nWidth > nScreenX+nScreenWidth )
1776 nX = (nScreenX+nScreenWidth) - nWidth;
1777 if ( nY+nHeight > nScreenY+nScreenHeight )
1778 nY = (nScreenY+nScreenHeight) - nHeight;
1779 if ( nX < nScreenX )
1780 nX = nScreenX;
1781 if ( nY < nScreenY )
1782 nY = nScreenY;
1784 // Restore-Position setzen
1785 WINDOWPLACEMENT aPlacement;
1786 aPlacement.length = sizeof( aPlacement );
1787 GetWindowPlacement( mhWnd, &aPlacement );
1789 // Status setzen
1790 sal_Bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
1791 sal_Bool bUpdateHiddenFramePos = FALSE;
1792 if ( !bVisible )
1794 aPlacement.showCmd = SW_HIDE;
1796 if ( mbOverwriteState )
1798 if ( pState->mnMask & SAL_FRAMESTATE_MASK_STATE )
1800 if ( pState->mnState & SAL_FRAMESTATE_MINIMIZED )
1801 mnShowState = SW_SHOWMINIMIZED;
1802 else if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1804 mnShowState = SW_SHOWMAXIMIZED;
1805 bUpdateHiddenFramePos = TRUE;
1807 else if ( pState->mnState & SAL_FRAMESTATE_NORMAL )
1808 mnShowState = SW_SHOWNORMAL;
1812 else
1814 if ( pState->mnMask & SAL_FRAMESTATE_MASK_STATE )
1816 if ( pState->mnState & SAL_FRAMESTATE_MINIMIZED )
1818 if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1819 aPlacement.flags |= WPF_RESTORETOMAXIMIZED;
1820 aPlacement.showCmd = SW_SHOWMINIMIZED;
1822 else if ( pState->mnState & SAL_FRAMESTATE_MAXIMIZED )
1823 aPlacement.showCmd = SW_SHOWMAXIMIZED;
1824 else if ( pState->mnState & SAL_FRAMESTATE_NORMAL )
1825 aPlacement.showCmd = SW_RESTORE;
1829 // if a window is neither minimized nor maximized or need not be
1830 // positioned visibly (that is in visible state), do not use
1831 // SetWindowPlacement since it calculates including the TaskBar
1832 if ( !IsIconic( mhWnd ) && !IsZoomed( mhWnd ) &&
1833 (!bVisible || (aPlacement.showCmd == SW_RESTORE)) )
1835 if( bUpdateHiddenFramePos )
1837 RECT aStateRect;
1838 aStateRect.left = nX;
1839 aStateRect.top = nY;
1840 aStateRect.right = nX+nWidth;
1841 aStateRect.bottom = nY+nHeight;
1842 // #96084 set a useful internal window size because
1843 // the window will not be maximized (and the size updated) before show()
1844 SetMaximizedFrameGeometry( mhWnd, this, &aStateRect );
1845 SetWindowPos( mhWnd, 0,
1846 maGeometry.nX, maGeometry.nY, maGeometry.nWidth, maGeometry.nHeight,
1847 SWP_NOZORDER | SWP_NOACTIVATE | nPosSize );
1849 else
1850 SetWindowPos( mhWnd, 0,
1851 nX, nY, nWidth, nHeight,
1852 SWP_NOZORDER | SWP_NOACTIVATE | nPosSize );
1854 else
1856 if( !(nPosSize & (SWP_NOMOVE|SWP_NOSIZE)) )
1858 aPlacement.rcNormalPosition.left = nX-nScreenX;
1859 aPlacement.rcNormalPosition.top = nY-nScreenY;
1860 aPlacement.rcNormalPosition.right = nX+nWidth-nScreenX;
1861 aPlacement.rcNormalPosition.bottom = nY+nHeight-nScreenY;
1863 SetWindowPlacement( mhWnd, &aPlacement );
1866 if( !(nPosSize & SWP_NOMOVE) )
1867 mbDefPos = FALSE; // window was positioned
1870 // -----------------------------------------------------------------------
1872 sal_Bool WinSalFrame::GetWindowState( SalFrameState* pState )
1874 if ( maState.mnWidth && maState.mnHeight )
1876 *pState = maState;
1877 // #94144# allow Minimize again, should be masked out when read from configuration
1878 // 91625 - Don't save minimize
1879 //if ( !(pState->mnState & SAL_FRAMESTATE_MAXIMIZED) )
1880 if ( !(pState->mnState & (SAL_FRAMESTATE_MINIMIZED | SAL_FRAMESTATE_MAXIMIZED)) )
1881 pState->mnState |= SAL_FRAMESTATE_NORMAL;
1882 return TRUE;
1885 return FALSE;
1888 // -----------------------------------------------------------------------
1890 void WinSalFrame::SetScreenNumber( unsigned int nNewScreen )
1892 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
1893 if( pSys )
1895 const std::vector<WinSalSystem::DisplayMonitor>& rMonitors =
1896 pSys->getMonitors();
1897 size_t nMon = rMonitors.size();
1898 if( nNewScreen < nMon )
1900 Point aOldMonPos, aNewMonPos( rMonitors[nNewScreen].m_aArea.TopLeft() );
1901 Point aCurPos( maGeometry.nX, maGeometry.nY );
1902 for( size_t i = 0; i < nMon; i++ )
1904 if( rMonitors[i].m_aArea.IsInside( aCurPos ) )
1906 aOldMonPos = rMonitors[i].m_aArea.TopLeft();
1907 break;
1910 mnDisplay = nNewScreen;
1911 maGeometry.nDisplayScreenNumber = nNewScreen;
1912 SetPosSize( aNewMonPos.X() + (maGeometry.nX - aOldMonPos.X()),
1913 aNewMonPos.Y() + (maGeometry.nY - aOldMonPos.Y()),
1914 0, 0,
1915 SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y );
1920 void WinSalFrame::SetApplicationID( const rtl::OUString &/*rApplicationID*/ )
1924 // -----------------------------------------------------------------------
1926 void WinSalFrame::ShowFullScreen( sal_Bool bFullScreen, sal_Int32 nDisplay )
1928 if ( (mbFullScreen == bFullScreen) && (!bFullScreen || (mnDisplay == nDisplay)) )
1929 return;
1931 mbFullScreen = bFullScreen;
1932 mnDisplay = nDisplay;
1934 if ( bFullScreen )
1936 // Damit Taskleiste von Windows ausgeblendet wird
1937 DWORD nExStyle = GetWindowExStyle( mhWnd );
1938 if ( nExStyle & WS_EX_TOOLWINDOW )
1940 mbFullScreenToolWin = TRUE;
1941 nExStyle &= ~WS_EX_TOOLWINDOW;
1942 SetWindowExStyle( mhWnd, nExStyle );
1944 // save old position
1945 GetWindowRect( mhWnd, &maFullScreenRect );
1947 // save show state
1948 mnFullScreenShowState = mnShowState;
1949 if ( !(GetWindowStyle( mhWnd ) & WS_VISIBLE) )
1950 mnShowState = SW_SHOW;
1952 // set window to screen size
1953 ImplSalFrameFullScreenPos( this, TRUE );
1955 else
1957 // wenn ShowState wieder hergestellt werden muss, hiden wir zuerst
1958 // das Fenster, damit es nicht so sehr flackert
1959 sal_Bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
1960 if ( bVisible && (mnShowState != mnFullScreenShowState) )
1961 ShowWindow( mhWnd, SW_HIDE );
1963 if ( mbFullScreenToolWin )
1964 SetWindowExStyle( mhWnd, GetWindowExStyle( mhWnd ) | WS_EX_TOOLWINDOW );
1965 mbFullScreenToolWin = FALSE;
1967 SetWindowPos( mhWnd, 0,
1968 maFullScreenRect.left,
1969 maFullScreenRect.top,
1970 maFullScreenRect.right-maFullScreenRect.left,
1971 maFullScreenRect.bottom-maFullScreenRect.top,
1972 SWP_NOZORDER | SWP_NOACTIVATE );
1974 // restore show state
1975 if ( mnShowState != mnFullScreenShowState )
1977 mnShowState = mnFullScreenShowState;
1978 if ( bVisible )
1980 mbInShow = TRUE;
1981 ShowWindow( mhWnd, mnShowState );
1982 mbInShow = FALSE;
1983 UpdateWindow( mhWnd );
1989 // -----------------------------------------------------------------------
1991 void WinSalFrame::StartPresentation( sal_Bool bStart )
1993 if ( mbPresentation == bStart )
1994 return;
1996 mbPresentation = bStart;
1998 SalData* pSalData = GetSalData();
1999 if ( bStart )
2001 if ( !pSalData->mpSageEnableProc )
2003 if ( pSalData->mnSageStatus != DISABLE_AGENT )
2005 OFSTRUCT aOS;
2006 OpenFile( "SAGE.DLL", &aOS, OF_EXIST );
2008 if ( !aOS.nErrCode )
2010 OUString aLibraryName( OUString::createFromAscii( aOS.szPathName ) );
2011 oslModule mhSageInst = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT );
2012 pSalData->mpSageEnableProc = (SysAgt_Enable_PROC)osl_getAsciiFunctionSymbol( mhSageInst, "System_Agent_Enable" );
2014 else
2015 pSalData->mnSageStatus = DISABLE_AGENT;
2019 if ( pSalData->mpSageEnableProc )
2021 pSalData->mnSageStatus = pSalData->mpSageEnableProc( GET_AGENT_STATUS );
2022 if ( pSalData->mnSageStatus == ENABLE_AGENT )
2023 pSalData->mpSageEnableProc( DISABLE_AGENT );
2026 // Bildschirmschoner ausschalten, wenn Praesentation laueft
2027 SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 0,
2028 &(pSalData->mbScrSvrEnabled), 0 );
2029 if ( pSalData->mbScrSvrEnabled )
2030 SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, FALSE, 0, 0 );
2032 else
2034 // Bildschirmschoner wieder einschalten
2035 if ( pSalData->mbScrSvrEnabled )
2036 SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, pSalData->mbScrSvrEnabled, 0, 0 );
2038 // Systemagenten wieder aktivieren
2039 if ( pSalData->mnSageStatus == ENABLE_AGENT )
2040 pSalData->mpSageEnableProc( pSalData->mnSageStatus );
2044 // -----------------------------------------------------------------------
2046 void WinSalFrame::SetAlwaysOnTop( sal_Bool bOnTop )
2048 HWND hWnd;
2049 if ( bOnTop )
2050 hWnd = HWND_TOPMOST;
2051 else
2052 hWnd = HWND_NOTOPMOST;
2053 SetWindowPos( mhWnd, hWnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
2056 // -----------------------------------------------------------------------
2058 static void ImplSalToTop( HWND hWnd, sal_uInt16 nFlags )
2060 WinSalFrame* pToTopFrame = GetWindowPtr( hWnd );
2061 if( pToTopFrame && (pToTopFrame->mnStyle & SAL_FRAME_STYLE_SYSTEMCHILD) != 0 )
2062 BringWindowToTop( hWnd );
2064 if ( nFlags & SAL_FRAME_TOTOP_FOREGROUNDTASK )
2066 // This magic code is necessary to connect the input focus of the
2067 // current window thread and the thread which owns the window that
2068 // should be the new foreground window.
2069 HWND hCurrWnd = GetForegroundWindow();
2070 DWORD myThreadID = GetCurrentThreadId();
2071 DWORD currThreadID = GetWindowThreadProcessId(hCurrWnd,NULL);
2072 AttachThreadInput(myThreadID, currThreadID,TRUE);
2073 SetForegroundWindow(hWnd);
2074 AttachThreadInput(myThreadID,currThreadID,FALSE);
2077 if ( nFlags & SAL_FRAME_TOTOP_RESTOREWHENMIN )
2079 HWND hIconicWnd = hWnd;
2080 while ( hIconicWnd )
2082 if ( IsIconic( hIconicWnd ) )
2084 WinSalFrame* pFrame = GetWindowPtr( hIconicWnd );
2085 if ( pFrame )
2087 if ( GetWindowPtr( hWnd )->mbRestoreMaximize )
2088 ShowWindow( hIconicWnd, SW_MAXIMIZE );
2089 else
2090 ShowWindow( hIconicWnd, SW_RESTORE );
2092 else
2093 ShowWindow( hIconicWnd, SW_RESTORE );
2096 hIconicWnd = ::GetParent( hIconicWnd );
2100 if ( !IsIconic( hWnd ) && IsWindowVisible( hWnd ) )
2102 SetFocus( hWnd );
2104 // Windows behauptet oefters mal, das man den Focus hat, obwohl
2105 // man diesen nicht hat. Wenn dies der Fall ist, dann versuchen
2106 // wir diesen auch ganz richtig zu bekommen.
2107 if ( ::GetFocus() == hWnd )
2108 SetForegroundWindow( hWnd );
2112 // -----------------------------------------------------------------------
2114 void WinSalFrame::ToTop( sal_uInt16 nFlags )
2116 nFlags &= ~SAL_FRAME_TOTOP_GRABFOCUS; // this flag is not needed on win32
2117 // Post this Message to the window, because this only works
2118 // in the thread of the window, which has create this window.
2119 // We post this message to avoid deadlocks
2120 if ( GetSalData()->mnAppThreadId != GetCurrentThreadId() )
2121 ImplPostMessage( mhWnd, SAL_MSG_TOTOP, nFlags, 0 );
2122 else
2123 ImplSalToTop( mhWnd, nFlags );
2126 // -----------------------------------------------------------------------
2128 void WinSalFrame::SetPointer( PointerStyle ePointerStyle )
2130 struct ImplPtrData
2132 HCURSOR mhCursor;
2133 LPCSTR mnSysId;
2134 UINT mnOwnId;
2137 static ImplPtrData aImplPtrTab[POINTER_COUNT] =
2139 { 0, IDC_ARROW, 0 }, // POINTER_ARROW
2140 { 0, 0, SAL_RESID_POINTER_NULL }, // POINTER_NULL
2141 { 0, IDC_WAIT, 0 }, // POINTER_WAIT
2142 { 0, IDC_IBEAM, 0 }, // POINTER_TEXT
2143 { 0, IDC_HELP, 0 }, // POINTER_HELP
2144 { 0, 0, SAL_RESID_POINTER_CROSS }, // POINTER_CROSS
2145 { 0, 0, SAL_RESID_POINTER_MOVE }, // POINTER_MOVE
2146 { 0, IDC_SIZENS, 0 }, // POINTER_NSIZE
2147 { 0, IDC_SIZENS, 0 }, // POINTER_SSIZE
2148 { 0, IDC_SIZEWE, 0 }, // POINTER_WSIZE
2149 { 0, IDC_SIZEWE, 0 }, // POINTER_ESIZE
2150 { 0, IDC_SIZENWSE, 0 }, // POINTER_NWSIZE
2151 { 0, IDC_SIZENESW, 0 }, // POINTER_NESIZE
2152 { 0, IDC_SIZENESW, 0 }, // POINTER_SWSIZE
2153 { 0, IDC_SIZENWSE, 0 }, // POINTER_SESIZE
2154 { 0, IDC_SIZENS, 0 }, // POINTER_WINDOW_NSIZE
2155 { 0, IDC_SIZENS, 0 }, // POINTER_WINDOW_SSIZE
2156 { 0, IDC_SIZEWE, 0 }, // POINTER_WINDOW_WSIZE
2157 { 0, IDC_SIZEWE, 0 }, // POINTER_WINDOW_ESIZE
2158 { 0, IDC_SIZENWSE, 0 }, // POINTER_WINDOW_NWSIZE
2159 { 0, IDC_SIZENESW, 0 }, // POINTER_WINDOW_NESIZE
2160 { 0, IDC_SIZENESW, 0 }, // POINTER_WINDOW_SWSIZE
2161 { 0, IDC_SIZENWSE, 0 }, // POINTER_WINDOW_SESIZE
2162 { 0, 0, SAL_RESID_POINTER_HSPLIT }, // POINTER_HSPLIT
2163 { 0, 0, SAL_RESID_POINTER_VSPLIT }, // POINTER_VSPLIT
2164 { 0, 0, SAL_RESID_POINTER_HSIZEBAR }, // POINTER_HSIZEBAR
2165 { 0, 0, SAL_RESID_POINTER_VSIZEBAR }, // POINTER_VSIZEBAR
2166 { 0, 0, SAL_RESID_POINTER_HAND }, // POINTER_HAND
2167 { 0, 0, SAL_RESID_POINTER_REFHAND }, // POINTER_REFHAND
2168 { 0, 0, SAL_RESID_POINTER_PEN }, // POINTER_PEN
2169 { 0, 0, SAL_RESID_POINTER_MAGNIFY }, // POINTER_MAGNIFY
2170 { 0, 0, SAL_RESID_POINTER_FILL }, // POINTER_FILL
2171 { 0, 0, SAL_RESID_POINTER_ROTATE }, // POINTER_ROTATE
2172 { 0, 0, SAL_RESID_POINTER_HSHEAR }, // POINTER_HSHEAR
2173 { 0, 0, SAL_RESID_POINTER_VSHEAR }, // POINTER_VSHEAR
2174 { 0, 0, SAL_RESID_POINTER_MIRROR }, // POINTER_MIRROR
2175 { 0, 0, SAL_RESID_POINTER_CROOK }, // POINTER_CROOK
2176 { 0, 0, SAL_RESID_POINTER_CROP }, // POINTER_CROP
2177 { 0, 0, SAL_RESID_POINTER_MOVEPOINT }, // POINTER_MOVEPOINT
2178 { 0, 0, SAL_RESID_POINTER_MOVEBEZIERWEIGHT }, // POINTER_MOVEBEZIERWEIGHT
2179 { 0, 0, SAL_RESID_POINTER_MOVEDATA }, // POINTER_MOVEDATA
2180 { 0, 0, SAL_RESID_POINTER_COPYDATA }, // POINTER_COPYDATA
2181 { 0, 0, SAL_RESID_POINTER_LINKDATA }, // POINTER_LINKDATA
2182 { 0, 0, SAL_RESID_POINTER_MOVEDATALINK }, // POINTER_MOVEDATALINK
2183 { 0, 0, SAL_RESID_POINTER_COPYDATALINK }, // POINTER_COPYDATALINK
2184 { 0, 0, SAL_RESID_POINTER_MOVEFILE }, // POINTER_MOVEFILE
2185 { 0, 0, SAL_RESID_POINTER_COPYFILE }, // POINTER_COPYFILE
2186 { 0, 0, SAL_RESID_POINTER_LINKFILE }, // POINTER_LINKFILE
2187 { 0, 0, SAL_RESID_POINTER_MOVEFILELINK }, // POINTER_MOVEFILELINK
2188 { 0, 0, SAL_RESID_POINTER_COPYFILELINK }, // POINTER_COPYFILELINK
2189 { 0, 0, SAL_RESID_POINTER_MOVEFILES }, // POINTER_MOVEFILES
2190 { 0, 0, SAL_RESID_POINTER_COPYFILES }, // POINTER_COPYFILES
2191 { 0, 0, SAL_RESID_POINTER_NOTALLOWED }, // POINTER_NOTALLOWED
2192 { 0, 0, SAL_RESID_POINTER_DRAW_LINE }, // POINTER_DRAW_LINE
2193 { 0, 0, SAL_RESID_POINTER_DRAW_RECT }, // POINTER_DRAW_RECT
2194 { 0, 0, SAL_RESID_POINTER_DRAW_POLYGON }, // POINTER_DRAW_POLYGON
2195 { 0, 0, SAL_RESID_POINTER_DRAW_BEZIER }, // POINTER_DRAW_BEZIER
2196 { 0, 0, SAL_RESID_POINTER_DRAW_ARC }, // POINTER_DRAW_ARC
2197 { 0, 0, SAL_RESID_POINTER_DRAW_PIE }, // POINTER_DRAW_PIE
2198 { 0, 0, SAL_RESID_POINTER_DRAW_CIRCLECUT }, // POINTER_DRAW_CIRCLECUT
2199 { 0, 0, SAL_RESID_POINTER_DRAW_ELLIPSE }, // POINTER_DRAW_ELLIPSE
2200 { 0, 0, SAL_RESID_POINTER_DRAW_FREEHAND }, // POINTER_DRAW_FREEHAND
2201 { 0, 0, SAL_RESID_POINTER_DRAW_CONNECT }, // POINTER_DRAW_CONNECT
2202 { 0, 0, SAL_RESID_POINTER_DRAW_TEXT }, // POINTER_DRAW_TEXT
2203 { 0, 0, SAL_RESID_POINTER_DRAW_CAPTION }, // POINTER_DRAW_CAPTION
2204 { 0, 0, SAL_RESID_POINTER_CHART }, // POINTER_CHART
2205 { 0, 0, SAL_RESID_POINTER_DETECTIVE }, // POINTER_DETECTIVE
2206 { 0, 0, SAL_RESID_POINTER_PIVOT_COL }, // POINTER_PIVOT_COL
2207 { 0, 0, SAL_RESID_POINTER_PIVOT_ROW }, // POINTER_PIVOT_ROW
2208 { 0, 0, SAL_RESID_POINTER_PIVOT_FIELD }, // POINTER_PIVOT_FIELD
2209 { 0, 0, SAL_RESID_POINTER_CHAIN }, // POINTER_CHAIN
2210 { 0, 0, SAL_RESID_POINTER_CHAIN_NOTALLOWED }, // POINTER_CHAIN_NOTALLOWED
2211 { 0, 0, SAL_RESID_POINTER_TIMEEVENT_MOVE }, // POINTER_TIMEEVENT_MOVE
2212 { 0, 0, SAL_RESID_POINTER_TIMEEVENT_SIZE }, // POINTER_TIMEEVENT_SIZE
2213 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_N }, // POINTER_AUTOSCROLL_N
2214 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_S }, // POINTER_AUTOSCROLL_S
2215 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_W }, // POINTER_AUTOSCROLL_W
2216 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_E }, // POINTER_AUTOSCROLL_E
2217 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NW }, // POINTER_AUTOSCROLL_NW
2218 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NE }, // POINTER_AUTOSCROLL_NE
2219 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_SW }, // POINTER_AUTOSCROLL_SW
2220 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_SE }, // POINTER_AUTOSCROLL_SE
2221 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NS }, // POINTER_AUTOSCROLL_NS
2222 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_WE }, // POINTER_AUTOSCROLL_WE
2223 { 0, 0, SAL_RESID_POINTER_AUTOSCROLL_NSWE }, // POINTER_AUTOSCROLL_NSWE
2224 { 0, 0, SAL_RESID_POINTER_AIRBRUSH }, // POINTER_AIRBRUSH
2225 { 0, 0, SAL_RESID_POINTER_TEXT_VERTICAL }, // POINTER_TEXT_VERTICAL
2226 { 0, 0, SAL_RESID_POINTER_PIVOT_DELETE }, // POINTER_PIVOT_DELETE
2228 // #i32329#
2229 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_S }, // POINTER_TAB_SELECT_S
2230 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_E }, // POINTER_TAB_SELECT_E
2231 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_SE }, // POINTER_TAB_SELECT_SE
2232 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_W }, // POINTER_TAB_SELECT_W
2233 { 0, 0, SAL_RESID_POINTER_TAB_SELECT_SW }, // POINTER_TAB_SELECT_SW
2235 // #i20119#
2236 { 0, 0, SAL_RESID_POINTER_PAINTBRUSH } // POINTER_PAINTBRUSH
2240 #if POINTER_COUNT != 94
2241 #error New Pointer must be defined!
2242 #endif
2244 // Mousepointer loaded ?
2245 if ( !aImplPtrTab[ePointerStyle].mhCursor )
2247 if ( aImplPtrTab[ePointerStyle].mnOwnId )
2248 aImplPtrTab[ePointerStyle].mhCursor = ImplLoadSalCursor( aImplPtrTab[ePointerStyle].mnOwnId );
2249 else
2250 aImplPtrTab[ePointerStyle].mhCursor = LoadCursor( 0, aImplPtrTab[ePointerStyle].mnSysId );
2253 // Unterscheidet sich der Mauspointer, dann den neuen setzen
2254 if ( mhCursor != aImplPtrTab[ePointerStyle].mhCursor )
2256 mhCursor = aImplPtrTab[ePointerStyle].mhCursor;
2257 SetCursor( mhCursor );
2261 // -----------------------------------------------------------------------
2263 void WinSalFrame::CaptureMouse( sal_Bool bCapture )
2265 // Send this Message to the window, because CaptureMouse() only work
2266 // in the thread of the window, which has create this window
2267 int nMsg;
2268 if ( bCapture )
2269 nMsg = SAL_MSG_CAPTUREMOUSE;
2270 else
2271 nMsg = SAL_MSG_RELEASEMOUSE;
2272 ImplSendMessage( mhWnd, nMsg, 0, 0 );
2275 // -----------------------------------------------------------------------
2277 void WinSalFrame::SetPointerPos( long nX, long nY )
2279 POINT aPt;
2280 aPt.x = (int)nX;
2281 aPt.y = (int)nY;
2282 ClientToScreen( mhWnd, &aPt );
2283 SetCursorPos( aPt.x, aPt.y );
2286 // -----------------------------------------------------------------------
2288 void WinSalFrame::Flush()
2290 GdiFlush();
2293 // -----------------------------------------------------------------------
2295 void WinSalFrame::Sync()
2297 GdiFlush();
2300 // -----------------------------------------------------------------------
2302 static void ImplSalFrameSetInputContext( HWND hWnd, const SalInputContext* pContext )
2304 WinSalFrame* pFrame = GetWindowPtr( hWnd );
2305 sal_Bool bIME = (pContext->mnOptions & SAL_INPUTCONTEXT_TEXT) != 0;
2306 if ( bIME )
2308 if ( !pFrame->mbIME )
2310 pFrame->mbIME = TRUE;
2312 if ( pFrame->mhDefIMEContext )
2314 ImmAssociateContext( pFrame->mhWnd, pFrame->mhDefIMEContext );
2315 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY );
2316 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
2317 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
2318 pFrame->mbHandleIME = !pFrame->mbSpezIME;
2322 // When the application can't handle IME messages, then the
2323 // System should handle the IME handling
2324 if ( !(pContext->mnOptions & SAL_INPUTCONTEXT_EXTTEXTINPUT) )
2325 pFrame->mbHandleIME = FALSE;
2327 // Set the Font for IME Handling
2328 if ( pContext->mpFont )
2330 HIMC hIMC = ImmGetContext( pFrame->mhWnd );
2331 if ( hIMC )
2333 LOGFONTW aLogFont;
2334 HDC hDC = GetDC( pFrame->mhWnd );
2335 // In case of vertical writing, always append a '@' to the
2336 // Windows font name, not only if such a Windows font really is
2337 // available (bTestVerticalAvail == false in the below call):
2338 // The Windows IME's candidates window seems to always use a
2339 // font that has all necessary glyphs, not necessarily the one
2340 // specified by this font name; but it seems to decide whether
2341 // to use that font's horizontal or vertical variant based on a
2342 // '@' in front of this font name.
2343 ImplGetLogFontFromFontSelect( hDC, pContext->mpFont, aLogFont,
2344 false );
2345 ReleaseDC( pFrame->mhWnd, hDC );
2346 ImmSetCompositionFontW( hIMC, &aLogFont );
2347 ImmReleaseContext( pFrame->mhWnd, hIMC );
2351 else
2353 if ( pFrame->mbIME )
2355 pFrame->mbIME = FALSE;
2356 pFrame->mbHandleIME = FALSE;
2357 ImmAssociateContext( pFrame->mhWnd, 0 );
2362 // -----------------------------------------------------------------------
2364 void WinSalFrame::SetInputContext( SalInputContext* pContext )
2366 // Must be called in the main thread!
2367 ImplSendMessage( mhWnd, SAL_MSG_SETINPUTCONTEXT, 0, (LPARAM)(void*)pContext );
2370 // -----------------------------------------------------------------------
2372 static void ImplSalFrameEndExtTextInput( HWND hWnd, sal_uInt16 nFlags )
2374 HIMC hIMC = ImmGetContext( hWnd );
2375 if ( hIMC )
2377 DWORD nIndex;
2378 if ( nFlags & SAL_FRAME_ENDEXTTEXTINPUT_COMPLETE )
2379 nIndex = CPS_COMPLETE;
2380 else
2381 nIndex = CPS_CANCEL;
2383 ImmNotifyIME( hIMC, NI_COMPOSITIONSTR, nIndex, 0 );
2384 ImmReleaseContext( hWnd, hIMC );
2388 // -----------------------------------------------------------------------
2390 void WinSalFrame::EndExtTextInput( sal_uInt16 nFlags )
2392 // Must be called in the main thread!
2393 ImplSendMessage( mhWnd, SAL_MSG_ENDEXTTEXTINPUT, (WPARAM)nFlags, 0 );
2396 // -----------------------------------------------------------------------
2398 static void ImplGetKeyNameText( LONG lParam, sal_Unicode* pBuf,
2399 UINT& rCount, UINT nMaxSize,
2400 const sal_Char* pReplace )
2402 DBG_ASSERT( sizeof( WCHAR ) == sizeof( sal_Unicode ), "WinSalFrame::ImplGetKeyNameTextW(): WCHAR != sal_Unicode" );
2404 static const int nMaxKeyLen = 350;
2405 WCHAR aKeyBuf[ nMaxKeyLen ];
2406 int nKeyLen = 0;
2407 if ( lParam )
2409 rtl::OUString aLang = Application::GetSettings().GetUILanguageTag().getLanguage();
2410 rtl::OUString aRet;
2412 aRet = ::vcl_sal::getKeysReplacementName( aLang, lParam );
2413 if( aRet.isEmpty() )
2415 nKeyLen = GetKeyNameTextW( lParam, aKeyBuf, nMaxKeyLen );
2416 DBG_ASSERT( nKeyLen <= nMaxKeyLen, "Invalid key name length!" );
2417 if( nKeyLen > nMaxKeyLen )
2418 nKeyLen = 0;
2419 else if( nKeyLen > 0 )
2421 // Capitalize just the first letter of key names
2422 CharLowerBuffW( aKeyBuf, nKeyLen );
2424 bool bUpper = true;
2425 for( WCHAR *pW=aKeyBuf, *pE=pW+nKeyLen; pW < pE; ++pW )
2427 if( bUpper )
2428 CharUpperBuffW( pW, 1 );
2429 bUpper = (*pW=='+') || (*pW=='-') || (*pW==' ') || (*pW=='.');
2433 else
2435 nKeyLen = aRet.getLength();
2436 wcscpy_s( aKeyBuf, nMaxKeyLen, aRet.getStr() );
2440 if ( (nKeyLen > 0) || pReplace )
2442 if( (rCount > 0) && (rCount < nMaxSize) )
2444 pBuf[rCount] = '+';
2445 rCount++;
2448 if( nKeyLen > 0 )
2450 WCHAR *pW = aKeyBuf, *pE = aKeyBuf + nKeyLen;
2451 while( *pW && (pW < pE) && (rCount < nMaxSize) )
2452 pBuf[rCount++] = *pW++;
2454 else // fall back to provided default name
2456 while( *pReplace && (rCount < nMaxSize) )
2458 pBuf[rCount] = *pReplace;
2459 rCount++;
2460 pReplace++;
2464 else
2465 rCount = 0;
2468 // -----------------------------------------------------------------------
2470 rtl::OUString WinSalFrame::GetKeyName( sal_uInt16 nKeyCode )
2472 static const UINT nMaxKeyLen = 350;
2473 sal_Unicode aKeyBuf[ nMaxKeyLen ];
2474 UINT nKeyBufLen = 0;
2475 UINT nSysCode = 0;
2477 if ( nKeyCode & KEY_MOD1 )
2479 nSysCode = MapVirtualKey( VK_CONTROL, 0 );
2480 nSysCode = (nSysCode << 16) | (((sal_uLong)1) << 25);
2481 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Ctrl" );
2484 if ( nKeyCode & KEY_MOD2 )
2486 nSysCode = MapVirtualKey( VK_MENU, 0 );
2487 nSysCode = (nSysCode << 16) | (((sal_uLong)1) << 25);
2488 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Alt" );
2491 if ( nKeyCode & KEY_SHIFT )
2493 nSysCode = MapVirtualKey( VK_SHIFT, 0 );
2494 nSysCode = (nSysCode << 16) | (((sal_uLong)1) << 25);
2495 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, "Shift" );
2498 sal_uInt16 nCode = nKeyCode & 0x0FFF;
2499 sal_uLong nSysCode2 = 0;
2500 const sal_Char* pReplace = NULL;
2501 sal_Unicode cSVCode = 0;
2502 sal_Char aFBuf[4];
2503 nSysCode = 0;
2505 if ( (nCode >= KEY_0) && (nCode <= KEY_9) )
2506 cSVCode = '0' + (nCode - KEY_0);
2507 else if ( (nCode >= KEY_A) && (nCode <= KEY_Z) )
2508 cSVCode = 'A' + (nCode - KEY_A);
2509 else if ( (nCode >= KEY_F1) && (nCode <= KEY_F26) )
2511 nSysCode = VK_F1 + (nCode - KEY_F1);
2512 aFBuf[0] = 'F';
2513 if ( (nCode >= KEY_F1) && (nCode <= KEY_F9) )
2515 aFBuf[1] = sal::static_int_cast<sal_Char>('1' + (nCode - KEY_F1));
2516 aFBuf[2] = 0;
2518 else if ( (nCode >= KEY_F10) && (nCode <= KEY_F19) )
2520 aFBuf[1] = '1';
2521 aFBuf[2] = sal::static_int_cast<sal_Char>('0' + (nCode - KEY_F10));
2522 aFBuf[3] = 0;
2524 else
2526 aFBuf[1] = '2';
2527 aFBuf[2] = sal::static_int_cast<sal_Char>('0' + (nCode - KEY_F20));
2528 aFBuf[3] = 0;
2530 pReplace = aFBuf;
2532 else
2534 switch ( nCode )
2536 case KEY_DOWN:
2537 nSysCode = VK_DOWN;
2538 nSysCode2 = (((sal_uLong)1) << 24);
2539 pReplace = "Down";
2540 break;
2541 case KEY_UP:
2542 nSysCode = VK_UP;
2543 nSysCode2 = (((sal_uLong)1) << 24);
2544 pReplace = "Up";
2545 break;
2546 case KEY_LEFT:
2547 nSysCode = VK_LEFT;
2548 nSysCode2 = (((sal_uLong)1) << 24);
2549 pReplace = "Left";
2550 break;
2551 case KEY_RIGHT:
2552 nSysCode = VK_RIGHT;
2553 nSysCode2 = (((sal_uLong)1) << 24);
2554 pReplace = "Right";
2555 break;
2556 case KEY_HOME:
2557 nSysCode = VK_HOME;
2558 nSysCode2 = (((sal_uLong)1) << 24);
2559 pReplace = "Home";
2560 break;
2561 case KEY_END:
2562 nSysCode = VK_END;
2563 nSysCode2 = (((sal_uLong)1) << 24);
2564 pReplace = "End";
2565 break;
2566 case KEY_PAGEUP:
2567 nSysCode = VK_PRIOR;
2568 nSysCode2 = (((sal_uLong)1) << 24);
2569 pReplace = "Page Up";
2570 break;
2571 case KEY_PAGEDOWN:
2572 nSysCode = VK_NEXT;
2573 nSysCode2 = (((sal_uLong)1) << 24);
2574 pReplace = "Page Down";
2575 break;
2576 case KEY_RETURN:
2577 nSysCode = VK_RETURN;
2578 pReplace = "Enter";
2579 break;
2580 case KEY_ESCAPE:
2581 nSysCode = VK_ESCAPE;
2582 pReplace = "Escape";
2583 break;
2584 case KEY_TAB:
2585 nSysCode = VK_TAB;
2586 pReplace = "Tab";
2587 break;
2588 case KEY_BACKSPACE:
2589 nSysCode = VK_BACK;
2590 pReplace = "Backspace";
2591 break;
2592 case KEY_SPACE:
2593 nSysCode = VK_SPACE;
2594 pReplace = "Space";
2595 break;
2596 case KEY_INSERT:
2597 nSysCode = VK_INSERT;
2598 nSysCode2 = (((sal_uLong)1) << 24);
2599 pReplace = "Insert";
2600 break;
2601 case KEY_DELETE:
2602 nSysCode = VK_DELETE;
2603 nSysCode2 = (((sal_uLong)1) << 24);
2604 pReplace = "Delete";
2605 break;
2607 case KEY_ADD:
2608 cSVCode = '+';
2609 break;
2610 case KEY_SUBTRACT:
2611 cSVCode = '-';
2612 break;
2613 case KEY_MULTIPLY:
2614 cSVCode = '*';
2615 break;
2616 case KEY_DIVIDE:
2617 cSVCode = '/';
2618 break;
2619 case KEY_POINT:
2620 cSVCode = '.';
2621 break;
2622 case KEY_COMMA:
2623 cSVCode = ',';
2624 break;
2625 case KEY_LESS:
2626 cSVCode = '<';
2627 break;
2628 case KEY_GREATER:
2629 cSVCode = '>';
2630 break;
2631 case KEY_EQUAL:
2632 cSVCode = '=';
2633 break;
2634 case KEY_SEMICOLON:
2635 cSVCode = ';';
2636 break;
2637 case KEY_BRACKETLEFT:
2638 cSVCode = '[';
2639 break;
2640 case KEY_BRACKETRIGHT:
2641 cSVCode = ']';
2642 break;
2646 if ( nSysCode )
2648 nSysCode = MapVirtualKey( (UINT)nSysCode, 0 );
2649 if ( nSysCode )
2650 nSysCode = (nSysCode << 16) | nSysCode2;
2651 ImplGetKeyNameText( nSysCode, aKeyBuf, nKeyBufLen, nMaxKeyLen, pReplace );
2653 else
2655 if ( cSVCode )
2657 if ( nKeyBufLen > 0 )
2658 aKeyBuf[ nKeyBufLen++ ] = '+';
2659 if( nKeyBufLen < nMaxKeyLen )
2660 aKeyBuf[ nKeyBufLen++ ] = cSVCode;
2664 if( !nKeyBufLen )
2665 return rtl::OUString();
2667 return rtl::OUString( aKeyBuf, sal::static_int_cast< sal_uInt16 >(nKeyBufLen) );
2670 // -----------------------------------------------------------------------
2672 inline Color ImplWinColorToSal( COLORREF nColor )
2674 return Color( GetRValue( nColor ), GetGValue( nColor ), GetBValue( nColor ) );
2677 // -----------------------------------------------------------------------
2679 static void ImplSalUpdateStyleFontW( HDC hDC, const LOGFONTW& rLogFont, Font& rFont )
2681 ImplSalLogFontToFontW( hDC, rLogFont, rFont );
2683 // On Windows 9x, Windows NT we get sometimes very small sizes
2684 // (for example for the small Caption height).
2685 // So if it is MS Sans Serif, a none scalable font we use
2686 // 8 Point as the minimum control height, in all other cases
2687 // 6 Point is the smallest one
2688 if ( rFont.GetHeight() < 8 )
2690 if ( rtl_ustr_compareIgnoreAsciiCase( reinterpret_cast<const sal_Unicode*>(rLogFont.lfFaceName), reinterpret_cast<const sal_Unicode*>(L"MS Sans Serif") ) == 0 )
2691 rFont.SetHeight( 8 );
2692 else if ( rFont.GetHeight() < 6 )
2693 rFont.SetHeight( 6 );
2697 // -----------------------------------------------------------------------
2699 static long ImplA2I( const BYTE* pStr )
2701 long n = 0;
2702 int nSign = 1;
2704 if ( *pStr == '-' )
2706 nSign = -1;
2707 pStr++;
2710 while( (*pStr >= 48) && (*pStr <= 57) )
2712 n *= 10;
2713 n += ((*pStr) - 48);
2714 pStr++;
2717 n *= nSign;
2719 return n;
2722 // -----------------------------------------------------------------------
2724 void WinSalFrame::UpdateSettings( AllSettings& rSettings )
2726 MouseSettings aMouseSettings = rSettings.GetMouseSettings();
2727 aMouseSettings.SetDoubleClickTime( GetDoubleClickTime() );
2728 aMouseSettings.SetDoubleClickWidth( GetSystemMetrics( SM_CXDOUBLECLK ) );
2729 aMouseSettings.SetDoubleClickHeight( GetSystemMetrics( SM_CYDOUBLECLK ) );
2730 long nDragWidth = GetSystemMetrics( SM_CXDRAG );
2731 long nDragHeight = GetSystemMetrics( SM_CYDRAG );
2732 if ( nDragWidth )
2733 aMouseSettings.SetStartDragWidth( nDragWidth );
2734 if ( nDragHeight )
2735 aMouseSettings.SetStartDragHeight( nDragHeight );
2736 HKEY hRegKey;
2737 if ( RegOpenKey( HKEY_CURRENT_USER,
2738 "Control Panel\\Desktop",
2739 &hRegKey ) == ERROR_SUCCESS )
2741 BYTE aValueBuf[10];
2742 DWORD nValueSize = sizeof( aValueBuf );
2743 DWORD nType;
2744 if ( RegQueryValueEx( hRegKey, "MenuShowDelay", 0,
2745 &nType, aValueBuf, &nValueSize ) == ERROR_SUCCESS )
2747 if ( nType == REG_SZ )
2748 aMouseSettings.SetMenuDelay( (sal_uLong)ImplA2I( aValueBuf ) );
2751 RegCloseKey( hRegKey );
2754 StyleSettings aStyleSettings = rSettings.GetStyleSettings();
2756 aStyleSettings.SetScrollBarSize( GetSystemMetrics( SM_CXVSCROLL ) );
2757 aStyleSettings.SetSpinSize( GetSystemMetrics( SM_CXVSCROLL ) );
2758 aStyleSettings.SetCursorBlinkTime( GetCaretBlinkTime() );
2759 aStyleSettings.SetFloatTitleHeight( GetSystemMetrics( SM_CYSMCAPTION ) );
2760 aStyleSettings.SetTitleHeight( GetSystemMetrics( SM_CYCAPTION ) );
2761 aStyleSettings.SetActiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVEBORDER ) ) );
2762 aStyleSettings.SetDeactiveBorderColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVEBORDER ) ) );
2763 aStyleSettings.SetActiveColor2( ImplWinColorToSal( GetSysColor( COLOR_GRADIENTACTIVECAPTION ) ) );
2764 aStyleSettings.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_GRADIENTINACTIVECAPTION ) ) );
2765 aStyleSettings.SetFaceColor( ImplWinColorToSal( GetSysColor( COLOR_3DFACE ) ) );
2766 aStyleSettings.SetInactiveTabColor( aStyleSettings.GetFaceColor() );
2767 aStyleSettings.SetLightColor( ImplWinColorToSal( GetSysColor( COLOR_3DHILIGHT ) ) );
2768 aStyleSettings.SetLightBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DLIGHT ) ) );
2769 aStyleSettings.SetShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW ) ) );
2770 aStyleSettings.SetDarkShadowColor( ImplWinColorToSal( GetSysColor( COLOR_3DDKSHADOW ) ) );
2771 aStyleSettings.SetHelpColor( ImplWinColorToSal( GetSysColor( COLOR_INFOBK ) ) );
2772 aStyleSettings.SetHelpTextColor( ImplWinColorToSal( GetSysColor( COLOR_INFOTEXT ) ) );
2773 aStyleSettings.SetDialogColor( aStyleSettings.GetFaceColor() );
2774 aStyleSettings.SetDialogTextColor( aStyleSettings.GetButtonTextColor() );
2775 aStyleSettings.SetButtonTextColor( ImplWinColorToSal( GetSysColor( COLOR_BTNTEXT ) ) );
2776 aStyleSettings.SetButtonRolloverTextColor( aStyleSettings.GetButtonTextColor() );
2777 aStyleSettings.SetRadioCheckTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT ) ) );
2778 aStyleSettings.SetGroupTextColor( aStyleSettings.GetRadioCheckTextColor() );
2779 aStyleSettings.SetLabelTextColor( aStyleSettings.GetRadioCheckTextColor() );
2780 aStyleSettings.SetInfoTextColor( aStyleSettings.GetRadioCheckTextColor() );
2781 aStyleSettings.SetWindowColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOW ) ) );
2782 aStyleSettings.SetActiveTabColor( aStyleSettings.GetWindowColor() );
2783 aStyleSettings.SetWindowTextColor( ImplWinColorToSal( GetSysColor( COLOR_WINDOWTEXT ) ) );
2784 aStyleSettings.SetFieldColor( aStyleSettings.GetWindowColor() );
2785 aStyleSettings.SetFieldTextColor( aStyleSettings.GetWindowTextColor() );
2786 aStyleSettings.SetFieldRolloverTextColor( aStyleSettings.GetFieldTextColor() );
2787 aStyleSettings.SetHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHT ) ) );
2788 aStyleSettings.SetHighlightTextColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHTTEXT ) ) );
2789 aStyleSettings.SetMenuHighlightColor( aStyleSettings.GetHighlightColor() );
2790 aStyleSettings.SetMenuHighlightTextColor( aStyleSettings.GetHighlightTextColor() );
2792 ImplSVData* pSVData = ImplGetSVData();
2793 pSVData->maNWFData.mnMenuFormatBorderX = 0;
2794 pSVData->maNWFData.mnMenuFormatBorderY = 0;
2795 pSVData->maNWFData.maMenuBarHighlightTextColor = Color( COL_TRANSPARENT );
2796 GetSalData()->mbThemeMenuSupport = FALSE;
2797 aStyleSettings.SetMenuColor( ImplWinColorToSal( GetSysColor( COLOR_MENU ) ) );
2798 aStyleSettings.SetMenuBarColor( aStyleSettings.GetMenuColor() );
2799 aStyleSettings.SetMenuBorderColor( aStyleSettings.GetLightBorderColor() ); // overriden below for flat menus
2800 aStyleSettings.SetUseFlatBorders( FALSE );
2801 aStyleSettings.SetUseFlatMenues( FALSE );
2802 aStyleSettings.SetMenuTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT ) ) );
2803 aStyleSettings.SetMenuBarTextColor( ImplWinColorToSal( GetSysColor( COLOR_MENUTEXT ) ) );
2804 aStyleSettings.SetActiveColor( ImplWinColorToSal( GetSysColor( COLOR_ACTIVECAPTION ) ) );
2805 aStyleSettings.SetActiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_CAPTIONTEXT ) ) );
2806 aStyleSettings.SetDeactiveColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTION ) ) );
2807 aStyleSettings.SetDeactiveTextColor( ImplWinColorToSal( GetSysColor( COLOR_INACTIVECAPTIONTEXT ) ) );
2808 if ( aSalShlData.mbWXP )
2810 // only xp supports a different menu bar color
2811 long bFlatMenues = 0;
2812 SystemParametersInfo( SPI_GETFLATMENU, 0, &bFlatMenues, 0);
2813 if( bFlatMenues )
2815 aStyleSettings.SetUseFlatMenues( TRUE );
2816 aStyleSettings.SetMenuBarColor( ImplWinColorToSal( GetSysColor( COLOR_MENUBAR ) ) );
2817 aStyleSettings.SetMenuHighlightColor( ImplWinColorToSal( GetSysColor( COLOR_MENUHILIGHT ) ) );
2818 aStyleSettings.SetMenuBorderColor( ImplWinColorToSal( GetSysColor( COLOR_3DSHADOW ) ) );
2820 // flat borders for our controls etc. as well in this mode (ie, no 3d borders)
2821 // this is not active in the classic style appearance
2822 aStyleSettings.SetUseFlatBorders( TRUE );
2825 aStyleSettings.SetCheckedColorSpecialCase( );
2827 // caret width
2828 DWORD nCaretWidth = 2;
2829 if( SystemParametersInfo( SPI_GETCARETWIDTH, 0, &nCaretWidth, 0 ) )
2830 aStyleSettings.SetCursorSize( nCaretWidth );
2832 // High contrast
2833 HIGHCONTRAST hc;
2834 hc.cbSize = sizeof( HIGHCONTRAST );
2835 if( SystemParametersInfo( SPI_GETHIGHCONTRAST, hc.cbSize, &hc, 0)
2836 && (hc.dwFlags & HCF_HIGHCONTRASTON)
2838 aStyleSettings.SetHighContrastMode( 1 );
2839 aStyleSettings.SetSymbolsStyle( STYLE_SYMBOLS_HICONTRAST );
2840 } else {
2841 aStyleSettings.SetHighContrastMode( 0 );
2844 // Query Fonts
2845 Font aMenuFont = aStyleSettings.GetMenuFont();
2846 Font aTitleFont = aStyleSettings.GetTitleFont();
2847 Font aFloatTitleFont = aStyleSettings.GetFloatTitleFont();
2848 Font aHelpFont = aStyleSettings.GetHelpFont();
2849 Font aAppFont = aStyleSettings.GetAppFont();
2850 Font aIconFont = aStyleSettings.GetIconFont();
2851 HDC hDC = GetDC( 0 );
2852 NONCLIENTMETRICSW aNonClientMetrics;
2853 aNonClientMetrics.cbSize = sizeof( aNonClientMetrics );
2854 if ( SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, sizeof( aNonClientMetrics ), &aNonClientMetrics, 0 ) )
2856 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfMenuFont, aMenuFont );
2857 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfCaptionFont, aTitleFont );
2858 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfSmCaptionFont, aFloatTitleFont );
2859 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfStatusFont, aHelpFont );
2860 ImplSalUpdateStyleFontW( hDC, aNonClientMetrics.lfMessageFont, aAppFont );
2862 LOGFONTW aLogFont;
2863 if ( SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &aLogFont, 0 ) )
2864 ImplSalUpdateStyleFontW( hDC, aLogFont, aIconFont );
2867 // get screen font resolution to calculate toolbox item size
2868 long nDPIY = GetDeviceCaps( hDC, LOGPIXELSY );
2870 ReleaseDC( 0, hDC );
2872 long nHeightPx = aMenuFont.GetHeight() * nDPIY / 72;
2873 aStyleSettings.SetToolbarIconSize( (((nHeightPx-1)*2) >= 28) ? STYLE_TOOLBAR_ICONSIZE_LARGE : STYLE_TOOLBAR_ICONSIZE_SMALL );
2875 aStyleSettings.SetMenuFont( aMenuFont );
2876 aStyleSettings.SetTitleFont( aTitleFont );
2877 aStyleSettings.SetFloatTitleFont( aFloatTitleFont );
2878 aStyleSettings.SetHelpFont( aHelpFont );
2879 aStyleSettings.SetIconFont( aIconFont );
2880 // We prefer Arial in the russian version, because MS Sans Serif
2881 // is to wide for the dialogs
2882 if ( rSettings.GetLanguageTag().getLanguageType() == LANGUAGE_RUSSIAN )
2884 XubString aFontName = aAppFont.GetName();
2885 XubString aFirstName = aFontName.GetToken( 0, ';' );
2886 if ( aFirstName.EqualsIgnoreCaseAscii( "MS Sans Serif" ) )
2888 aFontName.InsertAscii( "Arial;", 0 );
2889 aAppFont.SetName( aFontName );
2892 aStyleSettings.SetAppFont( aAppFont );
2893 aStyleSettings.SetGroupFont( aAppFont );
2894 aStyleSettings.SetLabelFont( aAppFont );
2895 aStyleSettings.SetRadioCheckFont( aAppFont );
2896 aStyleSettings.SetPushButtonFont( aAppFont );
2897 aStyleSettings.SetFieldFont( aAppFont );
2898 if ( aAppFont.GetWeight() > WEIGHT_NORMAL )
2899 aAppFont.SetWeight( WEIGHT_NORMAL );
2900 aStyleSettings.SetInfoFont( aAppFont );
2901 aStyleSettings.SetToolFont( aAppFont );
2903 BOOL bDragFull;
2904 if ( SystemParametersInfo( SPI_GETDRAGFULLWINDOWS, 0, &bDragFull, 0 ) )
2906 sal_uLong nDragFullOptions = aStyleSettings.GetDragFullOptions();
2907 if ( bDragFull )
2908 nDragFullOptions |= DRAGFULL_OPTION_WINDOWMOVE | DRAGFULL_OPTION_WINDOWSIZE | DRAGFULL_OPTION_DOCKING | DRAGFULL_OPTION_SPLIT;
2909 else
2910 nDragFullOptions &= ~(DRAGFULL_OPTION_WINDOWMOVE | DRAGFULL_OPTION_WINDOWSIZE | DRAGFULL_OPTION_DOCKING | DRAGFULL_OPTION_SPLIT);
2911 aStyleSettings.SetDragFullOptions( nDragFullOptions );
2914 aStyleSettings.SetIconHorzSpace( GetSystemMetrics( SM_CXICONSPACING ) );
2915 aStyleSettings.SetIconVertSpace( GetSystemMetrics( SM_CYICONSPACING ) );
2916 if ( RegOpenKey( HKEY_CURRENT_USER,
2917 "Control Panel\\International\\Calendars\\TwoDigitYearMax",
2918 &hRegKey ) == ERROR_SUCCESS )
2920 BYTE aValueBuf[10];
2921 DWORD nValue;
2922 DWORD nValueSize = sizeof( aValueBuf );
2923 DWORD nType;
2924 if ( RegQueryValueEx( hRegKey, "1", 0,
2925 &nType, aValueBuf, &nValueSize ) == ERROR_SUCCESS )
2927 if ( nType == REG_SZ )
2929 nValue = (sal_uLong)ImplA2I( aValueBuf );
2930 if ( (nValue > 1000) && (nValue < 10000) )
2932 MiscSettings aMiscSettings = rSettings.GetMiscSettings();
2933 utl::MiscCfg().SetYear2000( (sal_Int32)(nValue-99) );
2934 rSettings.SetMiscSettings( aMiscSettings );
2939 RegCloseKey( hRegKey );
2942 rSettings.SetMouseSettings( aMouseSettings );
2943 rSettings.SetStyleSettings( aStyleSettings );
2945 // now apply the values from theming, if available
2946 WinSalGraphics::updateSettingsNative( rSettings );
2949 // -----------------------------------------------------------------------
2951 const SystemEnvData* WinSalFrame::GetSystemData() const
2953 return &maSysData;
2956 // -----------------------------------------------------------------------
2958 SalFrame::SalPointerState WinSalFrame::GetPointerState()
2960 SalPointerState aState;
2961 aState.mnState = 0;
2963 if ( GetKeyState( VK_LBUTTON ) & 0x8000 )
2964 aState.mnState |= MOUSE_LEFT;
2965 if ( GetKeyState( VK_MBUTTON ) & 0x8000 )
2966 aState.mnState |= MOUSE_MIDDLE;
2967 if ( GetKeyState( VK_RBUTTON ) & 0x8000 )
2968 aState.mnState |= MOUSE_RIGHT;
2969 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
2970 aState.mnState |= KEY_SHIFT;
2971 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
2972 aState.mnState |= KEY_MOD1;
2973 if ( GetKeyState( VK_MENU ) & 0x8000 )
2974 aState.mnState |= KEY_MOD2;
2976 POINT pt;
2977 GetCursorPos( &pt );
2979 aState.maPos = Point( pt.x - maGeometry.nX, pt.y - maGeometry.nY );
2980 return aState;
2983 // -----------------------------------------------------------------------
2985 SalFrame::SalIndicatorState WinSalFrame::GetIndicatorState()
2987 SalIndicatorState aState;
2988 aState.mnState = 0;
2989 if (::GetKeyState(VK_CAPITAL))
2990 aState.mnState |= INDICATOR_CAPSLOCK;
2992 if (::GetKeyState(VK_NUMLOCK))
2993 aState.mnState |= INDICATOR_NUMLOCK;
2995 if (::GetKeyState(VK_SCROLL))
2996 aState.mnState |= INDICATOR_SCROLLLOCK;
2998 return aState;
3001 void WinSalFrame::SimulateKeyPress( sal_uInt16 nKeyCode )
3003 BYTE nVKey = 0;
3004 switch (nKeyCode)
3006 case KEY_CAPSLOCK:
3007 nVKey = VK_CAPITAL;
3008 break;
3011 if (nVKey > 0 && nVKey < 255)
3013 ::keybd_event(nVKey, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
3014 ::keybd_event(nVKey, 0x45, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0);
3018 // -----------------------------------------------------------------------
3020 void WinSalFrame::ResetClipRegion()
3022 SetWindowRgn( mhWnd, 0, TRUE );
3025 // -----------------------------------------------------------------------
3027 void WinSalFrame::BeginSetClipRegion( sal_uLong nRects )
3029 if( mpClipRgnData )
3030 delete [] (BYTE*)mpClipRgnData;
3031 sal_uLong nRectBufSize = sizeof(RECT)*nRects;
3032 mpClipRgnData = (RGNDATA*)new BYTE[sizeof(RGNDATA)-1+nRectBufSize];
3033 mpClipRgnData->rdh.dwSize = sizeof( RGNDATAHEADER );
3034 mpClipRgnData->rdh.iType = RDH_RECTANGLES;
3035 mpClipRgnData->rdh.nCount = nRects;
3036 mpClipRgnData->rdh.nRgnSize = nRectBufSize;
3037 SetRectEmpty( &(mpClipRgnData->rdh.rcBound) );
3038 mpNextClipRect = (RECT*)(&(mpClipRgnData->Buffer));
3039 mbFirstClipRect = TRUE;
3042 // -----------------------------------------------------------------------
3044 void WinSalFrame::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
3046 if( ! mpClipRgnData )
3047 return;
3049 RECT* pRect = mpNextClipRect;
3050 RECT* pBoundRect = &(mpClipRgnData->rdh.rcBound);
3051 long nRight = nX + nWidth;
3052 long nBottom = nY + nHeight;
3054 if ( mbFirstClipRect )
3056 pBoundRect->left = nX;
3057 pBoundRect->top = nY;
3058 pBoundRect->right = nRight;
3059 pBoundRect->bottom = nBottom;
3060 mbFirstClipRect = FALSE;
3062 else
3064 if ( nX < pBoundRect->left )
3065 pBoundRect->left = (int)nX;
3067 if ( nY < pBoundRect->top )
3068 pBoundRect->top = (int)nY;
3070 if ( nRight > pBoundRect->right )
3071 pBoundRect->right = (int)nRight;
3073 if ( nBottom > pBoundRect->bottom )
3074 pBoundRect->bottom = (int)nBottom;
3077 pRect->left = (int)nX;
3078 pRect->top = (int)nY;
3079 pRect->right = (int)nRight;
3080 pRect->bottom = (int)nBottom;
3081 if( (mpNextClipRect - (RECT*)(&mpClipRgnData->Buffer)) < (int)mpClipRgnData->rdh.nCount )
3082 mpNextClipRect++;
3085 // -----------------------------------------------------------------------
3087 void WinSalFrame::EndSetClipRegion()
3089 if( ! mpClipRgnData )
3090 return;
3092 HRGN hRegion;
3094 // create region from accumulated rectangles
3095 if ( mpClipRgnData->rdh.nCount == 1 )
3097 RECT* pRect = &(mpClipRgnData->rdh.rcBound);
3098 hRegion = CreateRectRgn( pRect->left, pRect->top,
3099 pRect->right, pRect->bottom );
3101 else
3103 sal_uLong nSize = mpClipRgnData->rdh.nRgnSize+sizeof(RGNDATAHEADER);
3104 hRegion = ExtCreateRegion( NULL, nSize, mpClipRgnData );
3106 delete [] (BYTE*)mpClipRgnData;
3107 mpClipRgnData = NULL;
3109 DBG_ASSERT( hRegion, "WinSalFrame::EndSetClipRegion() - Can't create ClipRegion" );
3110 if( hRegion )
3112 RECT aWindowRect;
3113 GetWindowRect( mhWnd, &aWindowRect );
3114 POINT aPt;
3115 aPt.x=0;
3116 aPt.y=0;
3117 ClientToScreen( mhWnd, &aPt );
3118 OffsetRgn( hRegion, aPt.x - aWindowRect.left, aPt.y - aWindowRect.top );
3120 if( SetWindowRgn( mhWnd, hRegion, TRUE ) == 0 )
3121 DeleteObject( hRegion );
3125 // -----------------------------------------------------------------------
3127 static long ImplHandleMouseMsg( HWND hWnd, UINT nMsg,
3128 WPARAM wParam, LPARAM lParam )
3130 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3131 if ( !pFrame )
3132 return 0;
3134 if( nMsg == WM_LBUTTONDOWN || nMsg == WM_MBUTTONDOWN || nMsg == WM_RBUTTONDOWN )
3136 // #103168# post again if async focus has not arrived yet
3137 // hopefully we will not receive the corresponding button up before this
3138 // button down arrives again
3139 Window *pWin = pFrame->GetWindow();
3140 if( pWin && pWin->ImplGetWindowImpl()->mpFrameData->mnFocusId )
3142 ImplPostMessage( hWnd, nMsg, wParam, lParam );
3143 return 1;
3146 SalMouseEvent aMouseEvt;
3147 long nRet;
3148 sal_uInt16 nEvent = 0;
3149 sal_Bool bCall = TRUE;
3151 aMouseEvt.mnX = (short)LOWORD( lParam );
3152 aMouseEvt.mnY = (short)HIWORD( lParam );
3153 aMouseEvt.mnCode = 0;
3154 aMouseEvt.mnTime = GetMessageTime();
3156 // Wegen (Logitech-)MouseTreiber ueber GetKeyState() gehen, die auf
3157 // mittlerer Maustaste Doppelklick simulieren und den KeyStatus nicht
3158 // beruecksichtigen
3160 if ( GetKeyState( VK_LBUTTON ) & 0x8000 )
3161 aMouseEvt.mnCode |= MOUSE_LEFT;
3162 if ( GetKeyState( VK_MBUTTON ) & 0x8000 )
3163 aMouseEvt.mnCode |= MOUSE_MIDDLE;
3164 if ( GetKeyState( VK_RBUTTON ) & 0x8000 )
3165 aMouseEvt.mnCode |= MOUSE_RIGHT;
3166 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3167 aMouseEvt.mnCode |= KEY_SHIFT;
3168 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3169 aMouseEvt.mnCode |= KEY_MOD1;
3170 if ( GetKeyState( VK_MENU ) & 0x8000 )
3171 aMouseEvt.mnCode |= KEY_MOD2;
3173 switch ( nMsg )
3175 case WM_MOUSEMOVE:
3177 // Da bei Druecken von Modifier-Tasten die MouseEvents
3178 // nicht zusammengefast werden (da diese durch KeyEvents
3179 // unterbrochen werden), machen wir dieses hier selber
3180 if ( aMouseEvt.mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2) )
3182 MSG aTempMsg;
3183 if ( ImplPeekMessage( &aTempMsg, hWnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE | PM_NOYIELD ) )
3185 if ( (aTempMsg.message == WM_MOUSEMOVE) &&
3186 (aTempMsg.wParam == wParam) )
3187 return 1;
3191 SalData* pSalData = GetSalData();
3192 // Test for MouseLeave
3193 if ( pSalData->mhWantLeaveMsg && (pSalData->mhWantLeaveMsg != hWnd) )
3194 ImplSendMessage( pSalData->mhWantLeaveMsg, SAL_MSG_MOUSELEAVE, 0, GetMessagePos() );
3196 pSalData->mhWantLeaveMsg = hWnd;
3197 // Start MouseLeave-Timer
3198 if ( !pSalData->mpMouseLeaveTimer )
3200 pSalData->mpMouseLeaveTimer = new AutoTimer;
3201 pSalData->mpMouseLeaveTimer->SetTimeout( SAL_MOUSELEAVE_TIMEOUT );
3202 pSalData->mpMouseLeaveTimer->Start();
3203 // We dont need to set a timeout handler, because we test
3204 // for mouseleave in the timeout callback
3206 aMouseEvt.mnButton = 0;
3207 nEvent = SALEVENT_MOUSEMOVE;
3209 break;
3211 case WM_NCMOUSEMOVE:
3212 case SAL_MSG_MOUSELEAVE:
3214 SalData* pSalData = GetSalData();
3215 if ( pSalData->mhWantLeaveMsg == hWnd )
3217 pSalData->mhWantLeaveMsg = 0;
3218 if ( pSalData->mpMouseLeaveTimer )
3220 delete pSalData->mpMouseLeaveTimer;
3221 pSalData->mpMouseLeaveTimer = NULL;
3223 // Mouse-Coordinaates are relativ to the screen
3224 POINT aPt;
3225 aPt.x = (short)LOWORD( lParam );
3226 aPt.y = (short)HIWORD( lParam );
3227 ScreenToClient( hWnd, &aPt );
3228 aMouseEvt.mnX = aPt.x;
3229 aMouseEvt.mnY = aPt.y;
3230 aMouseEvt.mnButton = 0;
3231 nEvent = SALEVENT_MOUSELEAVE;
3233 else
3234 bCall = FALSE;
3236 break;
3238 case WM_LBUTTONDOWN:
3239 aMouseEvt.mnButton = MOUSE_LEFT;
3240 nEvent = SALEVENT_MOUSEBUTTONDOWN;
3241 break;
3243 case WM_MBUTTONDOWN:
3244 aMouseEvt.mnButton = MOUSE_MIDDLE;
3245 nEvent = SALEVENT_MOUSEBUTTONDOWN;
3246 break;
3248 case WM_RBUTTONDOWN:
3249 aMouseEvt.mnButton = MOUSE_RIGHT;
3250 nEvent = SALEVENT_MOUSEBUTTONDOWN;
3251 break;
3253 case WM_LBUTTONUP:
3254 aMouseEvt.mnButton = MOUSE_LEFT;
3255 nEvent = SALEVENT_MOUSEBUTTONUP;
3256 break;
3258 case WM_MBUTTONUP:
3259 aMouseEvt.mnButton = MOUSE_MIDDLE;
3260 nEvent = SALEVENT_MOUSEBUTTONUP;
3261 break;
3263 case WM_RBUTTONUP:
3264 aMouseEvt.mnButton = MOUSE_RIGHT;
3265 nEvent = SALEVENT_MOUSEBUTTONUP;
3266 break;
3269 // check if this window was destroyed - this might happen if we are the help window
3270 // and sent a mouse leave message to the application which killed the help window, ie ourself
3271 if( !IsWindow( hWnd ) )
3272 return 0;
3274 if ( bCall )
3276 if ( nEvent == SALEVENT_MOUSEBUTTONDOWN )
3277 UpdateWindow( hWnd );
3279 // --- RTL --- (mirror mouse pos)
3280 if( Application::GetSettings().GetLayoutRTL() )
3281 aMouseEvt.mnX = pFrame->maGeometry.nWidth-1-aMouseEvt.mnX;
3283 nRet = pFrame->CallCallback( nEvent, &aMouseEvt );
3284 if ( nMsg == WM_MOUSEMOVE )
3285 SetCursor( pFrame->mhCursor );
3287 else
3288 nRet = 0;
3290 return nRet;
3293 // -----------------------------------------------------------------------
3295 static long ImplHandleMouseActivateMsg( HWND hWnd )
3297 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3298 if ( !pFrame )
3299 return 0;
3301 if ( pFrame->mbFloatWin )
3302 return TRUE;
3304 SalMouseActivateEvent aMouseActivateEvt;
3305 POINT aPt;
3306 GetCursorPos( &aPt );
3307 ScreenToClient( hWnd, &aPt );
3308 aMouseActivateEvt.mnX = aPt.x;
3309 aMouseActivateEvt.mnY = aPt.y;
3310 return pFrame->CallCallback( SALEVENT_MOUSEACTIVATE, &aMouseActivateEvt );
3313 // -----------------------------------------------------------------------
3315 static long ImplHandleWheelMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
3317 DBG_ASSERT( nMsg == WM_MOUSEWHEEL ||
3318 nMsg == WM_MOUSEHWHEEL,
3319 "ImplHandleWheelMsg() called with no wheel mouse event" );
3321 ImplSalYieldMutexAcquireWithWait();
3323 long nRet = 0;
3324 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3325 if ( pFrame )
3327 WORD nWinModCode = LOWORD( wParam );
3328 POINT aWinPt;
3329 aWinPt.x = (short)LOWORD( lParam );
3330 aWinPt.y = (short)HIWORD( lParam );
3331 ScreenToClient( hWnd, &aWinPt );
3333 SalWheelMouseEvent aWheelEvt;
3334 aWheelEvt.mnTime = GetMessageTime();
3335 aWheelEvt.mnX = aWinPt.x;
3336 aWheelEvt.mnY = aWinPt.y;
3337 aWheelEvt.mnCode = 0;
3338 aWheelEvt.mnDelta = (short)HIWORD( wParam );
3339 aWheelEvt.mnNotchDelta = aWheelEvt.mnDelta/WHEEL_DELTA;
3340 if( aWheelEvt.mnNotchDelta == 0 )
3342 if( aWheelEvt.mnDelta > 0 )
3343 aWheelEvt.mnNotchDelta = 1;
3344 else if( aWheelEvt.mnDelta < 0 )
3345 aWheelEvt.mnNotchDelta = -1;
3348 if( nMsg == WM_MOUSEWHEEL )
3350 if ( aSalShlData.mnWheelScrollLines == WHEEL_PAGESCROLL )
3351 aWheelEvt.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
3352 else
3353 aWheelEvt.mnScrollLines = aSalShlData.mnWheelScrollLines;
3354 aWheelEvt.mbHorz = FALSE;
3356 else
3358 aWheelEvt.mnScrollLines = aSalShlData.mnWheelScrollChars;
3359 aWheelEvt.mbHorz = TRUE;
3361 // fdo#36380 - seems horiz scrolling has swapped direction
3362 aWheelEvt.mnDelta *= -1;
3363 aWheelEvt.mnNotchDelta *= -1;
3366 if ( nWinModCode & MK_SHIFT )
3367 aWheelEvt.mnCode |= KEY_SHIFT;
3368 if ( nWinModCode & MK_CONTROL )
3369 aWheelEvt.mnCode |= KEY_MOD1;
3370 if ( GetKeyState( VK_MENU ) & 0x8000 )
3371 aWheelEvt.mnCode |= KEY_MOD2;
3373 // --- RTL --- (mirror mouse pos)
3374 if( Application::GetSettings().GetLayoutRTL() )
3375 aWheelEvt.mnX = pFrame->maGeometry.nWidth-1-aWheelEvt.mnX;
3377 nRet = pFrame->CallCallback( SALEVENT_WHEELMOUSE, &aWheelEvt );
3380 ImplSalYieldMutexRelease();
3382 return nRet;
3385 // -----------------------------------------------------------------------
3387 static sal_uInt16 ImplSalGetKeyCode( WPARAM wParam )
3389 sal_uInt16 nKeyCode;
3391 // convert KeyCode
3392 if ( wParam < KEY_TAB_SIZE )
3393 nKeyCode = aImplTranslateKeyTab[wParam];
3394 else
3396 SalData* pSalData = GetSalData();
3397 std::map< UINT, sal_uInt16 >::const_iterator it = pSalData->maVKMap.find( (UINT)wParam );
3398 if( it != pSalData->maVKMap.end() )
3399 nKeyCode = it->second;
3400 else
3401 nKeyCode = 0;
3404 return nKeyCode;
3407 // -----------------------------------------------------------------------
3409 static void ImplUpdateInputLang( WinSalFrame* pFrame )
3411 UINT nLang = LOWORD( GetKeyboardLayout( 0 ) );
3412 if ( nLang && nLang != pFrame->mnInputLang )
3414 // keep input lang up-to-date
3415 pFrame->mnInputLang = nLang;
3418 // We are on Windows NT so we use Unicode FrameProcs and get
3419 // Unicode charcodes directly from Windows no need to set up a
3420 // code page
3421 return;
3425 static sal_Unicode ImplGetCharCode( WinSalFrame* pFrame, WPARAM nCharCode )
3427 ImplUpdateInputLang( pFrame );
3429 // We are on Windows NT so we use Unicode FrameProcs and we
3430 // get Unicode charcodes directly from Windows
3431 return (sal_Unicode)nCharCode;
3434 // -----------------------------------------------------------------------
3436 LanguageType WinSalFrame::GetInputLanguage()
3438 if( !mnInputLang )
3439 ImplUpdateInputLang( this );
3441 if( !mnInputLang )
3442 return LANGUAGE_DONTKNOW;
3443 else
3444 return (LanguageType) mnInputLang;
3447 // -----------------------------------------------------------------------
3449 sal_Bool WinSalFrame::MapUnicodeToKeyCode( sal_Unicode aUnicode, LanguageType aLangType, KeyCode& rKeyCode )
3451 sal_Bool bRet = FALSE;
3452 sal_IntPtr nLangType = aLangType;
3453 // just use the passed language identifier, do not try to load additional keyboard support
3454 HKL hkl = (HKL) nLangType;
3456 if( hkl )
3458 SHORT scan = VkKeyScanExW( aUnicode, hkl );
3459 if( LOWORD(scan) == 0xFFFF )
3460 // keyboard not loaded or key cannot be mapped
3461 bRet = FALSE;
3462 else
3464 BYTE vkeycode = LOBYTE(scan);
3465 BYTE shiftstate = HIBYTE(scan);
3467 // Last argument is set to FALSE, because there's no decission made
3468 // yet which key should be assigned to MOD3 modifier on Windows.
3469 // Windows key - user's can be confused, because it should display
3470 // Windows menu (applies to both left/right key)
3471 // Menu key - this key is used to display context menu
3472 // AltGr key - probably it has no sense
3473 rKeyCode = KeyCode( ImplSalGetKeyCode( vkeycode ),
3474 (shiftstate & 0x01) ? TRUE : FALSE, // shift
3475 (shiftstate & 0x02) ? TRUE : FALSE, // ctrl
3476 (shiftstate & 0x04) ? TRUE : FALSE, // alt
3477 FALSE );
3478 bRet = TRUE;
3482 return bRet;
3485 // -----------------------------------------------------------------------
3487 static long ImplHandleKeyMsg( HWND hWnd, UINT nMsg,
3488 WPARAM wParam, LPARAM lParam, LRESULT& rResult )
3490 static sal_Bool bIgnoreCharMsg = FALSE;
3491 static WPARAM nDeadChar = 0;
3492 static WPARAM nLastVKChar = 0;
3493 static sal_uInt16 nLastChar = 0;
3494 static sal_uInt16 nLastModKeyCode = 0;
3495 static bool bWaitForModKeyRelease = false;
3496 sal_uInt16 nRepeat = LOWORD( lParam )-1;
3497 sal_uInt16 nModCode = 0;
3499 // Key wurde evtl. durch SysChild an uns weitergeleitet und
3500 // darf somit dann nicht doppelt verarbeitet werden
3501 GetSalData()->mnSalObjWantKeyEvt = 0;
3503 if ( nMsg == WM_DEADCHAR )
3505 nDeadChar = wParam;
3506 return 0;
3509 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3510 if ( !pFrame )
3511 return 0;
3513 // Wir restaurieren den Background-Modus bei jeder Texteingabe,
3514 // da einige Tools wie RichWin uns diesen hin- und wieder umsetzen
3515 if ( pFrame->mpGraphics &&
3516 pFrame->mpGraphics->mhDC )
3517 SetBkMode( pFrame->mpGraphics->mhDC, TRANSPARENT );
3519 // determine modifiers
3520 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3521 nModCode |= KEY_SHIFT;
3522 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3523 nModCode |= KEY_MOD1;
3524 if ( GetKeyState( VK_MENU ) & 0x8000 )
3525 nModCode |= KEY_MOD2;
3527 if ( (nMsg == WM_CHAR) || (nMsg == WM_SYSCHAR) )
3529 nDeadChar = 0;
3531 if ( bIgnoreCharMsg )
3533 bIgnoreCharMsg = FALSE;
3534 // #101635# if zero is returned here for WM_SYSCHAR (ALT+<key>) Windows will beep
3535 // becaus this 'hotkey' was not processed -> better return 1
3536 // except for Alt-SPACE which should always open the sysmenu (#104616#)
3538 // also return zero if a system menubar is available that might process this hotkey
3539 // this also applies to the OLE inplace embedding where we are a child window
3540 if( (GetWindowStyle( hWnd ) & WS_CHILD) || GetMenu( hWnd ) || (wParam == 0x20) )
3541 return 0;
3542 else
3543 return 1;
3546 // Backspace ignorieren wir als eigenstaendige Taste,
3547 // damit wir keine Probleme in Kombination mit einem
3548 // DeadKey bekommen
3549 if ( wParam == 0x08 ) // BACKSPACE
3550 return 0;
3552 // Hier kommen nur "freifliegende" WM_CHAR Message an, die durch
3553 // eintippen einer ALT-NUMPAD Kombination erzeugt wurden
3554 SalKeyEvent aKeyEvt;
3556 if ( (wParam >= '0') && (wParam <= '9') )
3557 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_NUM + wParam - '0');
3558 else if ( (wParam >= 'A') && (wParam <= 'Z') )
3559 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_ALPHA + wParam - 'A');
3560 else if ( (wParam >= 'a') && (wParam <= 'z') )
3561 aKeyEvt.mnCode = sal::static_int_cast<sal_uInt16>(KEYGROUP_ALPHA + wParam - 'a');
3562 else if ( wParam == 0x0D ) // RETURN
3563 aKeyEvt.mnCode = KEY_RETURN;
3564 else if ( wParam == 0x1B ) // ESCAPE
3565 aKeyEvt.mnCode = KEY_ESCAPE;
3566 else if ( wParam == 0x09 ) // TAB
3567 aKeyEvt.mnCode = KEY_TAB;
3568 else if ( wParam == 0x20 ) // SPACE
3569 aKeyEvt.mnCode = KEY_SPACE;
3570 else
3571 aKeyEvt.mnCode = 0;
3573 aKeyEvt.mnTime = GetMessageTime();
3574 aKeyEvt.mnCode |= nModCode;
3575 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, wParam );
3576 aKeyEvt.mnRepeat = nRepeat;
3577 nLastChar = 0;
3578 nLastVKChar = 0;
3579 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
3580 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3581 return nRet;
3583 // #i11583#, MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition begins
3584 else if( nMsg == WM_UNICHAR )
3586 // If Windows is asking if we accept WM_UNICHAR, return TRUE
3587 if(wParam == UNICODE_NOCHAR)
3589 rResult = TRUE; // ssa: this will actually return TRUE to windows
3590 return 1; // ...but this will only avoid calling the defwindowproc
3593 SalKeyEvent aKeyEvt;
3594 aKeyEvt.mnCode = nModCode; // Or should it be 0? - as this is always a character returned
3595 aKeyEvt.mnTime = GetMessageTime();
3596 aKeyEvt.mnRepeat = 0;
3598 if( wParam >= Uni_SupplementaryPlanesStart )
3600 // character is supplementary char in UTF-32 format - must be converted to UTF-16 supplementary pair
3601 // sal_Unicode ch = (sal_Unicode) Uni_UTF32ToSurrogate1(wParam);
3602 nLastChar = 0;
3603 nLastVKChar = 0;
3604 pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
3605 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3606 wParam = (sal_Unicode) Uni_UTF32ToSurrogate2( wParam );
3609 aKeyEvt.mnCharCode = (sal_Unicode) wParam;
3611 nLastChar = 0;
3612 nLastVKChar = 0;
3613 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
3614 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3616 return nRet;
3618 // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0; addition ends
3619 else
3621 // Bei Shift, Control und Menu schicken wir einen KeyModChange-Event
3622 if ( (wParam == VK_SHIFT) || (wParam == VK_CONTROL) || (wParam == VK_MENU) )
3624 SalKeyModEvent aModEvt;
3625 aModEvt.mnTime = GetMessageTime();
3626 aModEvt.mnCode = nModCode;
3627 aModEvt.mnModKeyCode = 0; // no command events will be sent if this member is 0
3629 sal_uInt16 tmpCode = 0;
3630 if( GetKeyState( VK_LSHIFT ) & 0x8000 )
3631 tmpCode |= MODKEY_LSHIFT;
3632 if( GetKeyState( VK_RSHIFT ) & 0x8000 )
3633 tmpCode |= MODKEY_RSHIFT;
3634 if( GetKeyState( VK_LCONTROL ) & 0x8000 )
3635 tmpCode |= MODKEY_LMOD1;
3636 if( GetKeyState( VK_RCONTROL ) & 0x8000 )
3637 tmpCode |= MODKEY_RMOD1;
3638 if( GetKeyState( VK_LMENU ) & 0x8000 )
3639 tmpCode |= MODKEY_LMOD2;
3640 if( GetKeyState( VK_RMENU ) & 0x8000 )
3641 tmpCode |= MODKEY_RMOD2;
3643 if( tmpCode < nLastModKeyCode )
3645 aModEvt.mnModKeyCode = nLastModKeyCode;
3646 nLastModKeyCode = 0;
3647 bWaitForModKeyRelease = true;
3649 else
3651 if( !bWaitForModKeyRelease )
3652 nLastModKeyCode = tmpCode;
3655 if( !tmpCode )
3656 bWaitForModKeyRelease = false;
3658 return pFrame->CallCallback( SALEVENT_KEYMODCHANGE, &aModEvt );
3660 else
3662 SalKeyEvent aKeyEvt;
3663 sal_uInt16 nEvent;
3664 MSG aCharMsg;
3665 BOOL bCharPeek = FALSE;
3666 UINT nCharMsg = WM_CHAR;
3667 sal_Bool bKeyUp = (nMsg == WM_KEYUP) || (nMsg == WM_SYSKEYUP);
3669 nLastModKeyCode = 0; // make sure no modkey messages are sent if they belong to a hotkey (see above)
3670 aKeyEvt.mnCharCode = 0;
3671 aKeyEvt.mnCode = 0;
3673 aKeyEvt.mnCode = ImplSalGetKeyCode( wParam );
3674 if ( !bKeyUp )
3676 // check for charcode
3677 // Mit Hilfe von PeekMessage holen wir uns jetzt die
3678 // zugehoerige WM_CHAR Message, wenn vorhanden.
3679 // Diese WM_CHAR Message steht immer am Anfang der
3680 // Messagequeue. Ausserdem ist sichergestellt, dass immer
3681 // nur eine WM_CHAR Message in der Queue steht.
3682 bCharPeek = ImplPeekMessage( &aCharMsg, hWnd,
3683 WM_CHAR, WM_CHAR, PM_NOREMOVE | PM_NOYIELD );
3684 if ( bCharPeek && (nDeadChar == aCharMsg.wParam) )
3686 bCharPeek = FALSE;
3687 nDeadChar = 0;
3689 if ( wParam == VK_BACK )
3691 ImplPeekMessage( &aCharMsg, hWnd,
3692 nCharMsg, nCharMsg, PM_REMOVE | PM_NOYIELD );
3693 return 0;
3696 else
3698 if ( !bCharPeek )
3700 bCharPeek = ImplPeekMessage( &aCharMsg, hWnd,
3701 WM_SYSCHAR, WM_SYSCHAR, PM_NOREMOVE | PM_NOYIELD );
3702 nCharMsg = WM_SYSCHAR;
3705 if ( bCharPeek )
3706 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, aCharMsg.wParam );
3707 else
3708 aKeyEvt.mnCharCode = 0;
3710 nLastChar = aKeyEvt.mnCharCode;
3711 nLastVKChar = wParam;
3713 else
3715 if ( wParam == nLastVKChar )
3717 aKeyEvt.mnCharCode = nLastChar;
3718 nLastChar = 0;
3719 nLastVKChar = 0;
3723 if ( aKeyEvt.mnCode || aKeyEvt.mnCharCode )
3725 if ( bKeyUp )
3726 nEvent = SALEVENT_KEYUP;
3727 else
3728 nEvent = SALEVENT_KEYINPUT;
3730 aKeyEvt.mnTime = GetMessageTime();
3731 aKeyEvt.mnCode |= nModCode;
3732 aKeyEvt.mnRepeat = nRepeat;
3734 if( (nModCode & (KEY_MOD1|KEY_MOD2)) == (KEY_MOD1|KEY_MOD2) &&
3735 aKeyEvt.mnCharCode )
3737 // this is actually AltGr and should not be handled as Alt
3738 aKeyEvt.mnCode &= ~(KEY_MOD1|KEY_MOD2);
3741 bIgnoreCharMsg = bCharPeek ? TRUE : FALSE;
3742 long nRet = pFrame->CallCallback( nEvent, &aKeyEvt );
3743 // independent part only reacts on keyup but Windows does not send
3744 // keyup for VK_HANJA
3745 if( aKeyEvt.mnCode == KEY_HANGUL_HANJA )
3746 nRet = pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3748 bIgnoreCharMsg = FALSE;
3750 // char-message, than remove or ignore
3751 if ( bCharPeek )
3753 nDeadChar = 0;
3754 if ( nRet )
3756 ImplPeekMessage( &aCharMsg, hWnd,
3757 nCharMsg, nCharMsg, PM_REMOVE | PM_NOYIELD );
3759 else
3760 bIgnoreCharMsg = TRUE;
3763 return nRet;
3765 else
3766 return 0;
3771 // -----------------------------------------------------------------------
3773 long ImplHandleSalObjKeyMsg( HWND hWnd, UINT nMsg,
3774 WPARAM wParam, LPARAM lParam )
3776 if ( (nMsg == WM_KEYDOWN) || (nMsg == WM_KEYUP) )
3778 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3779 if ( !pFrame )
3780 return 0;
3782 sal_uInt16 nRepeat = LOWORD( lParam )-1;
3783 sal_uInt16 nModCode = 0;
3785 // determine modifiers
3786 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3787 nModCode |= KEY_SHIFT;
3788 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3789 nModCode |= KEY_MOD1;
3790 if ( GetKeyState( VK_MENU ) & 0x8000 )
3791 nModCode |= KEY_MOD2;
3793 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) && (wParam != VK_MENU) )
3795 SalKeyEvent aKeyEvt;
3796 sal_uInt16 nEvent;
3797 sal_Bool bKeyUp = (nMsg == WM_KEYUP) || (nMsg == WM_SYSKEYUP);
3799 // convert KeyCode
3800 aKeyEvt.mnCode = ImplSalGetKeyCode( wParam );
3801 aKeyEvt.mnCharCode = 0;
3803 if ( aKeyEvt.mnCode )
3805 if ( bKeyUp )
3806 nEvent = SALEVENT_KEYUP;
3807 else
3808 nEvent = SALEVENT_KEYINPUT;
3810 aKeyEvt.mnTime = GetMessageTime();
3811 aKeyEvt.mnCode |= nModCode;
3812 aKeyEvt.mnRepeat = nRepeat;
3813 long nRet = pFrame->CallCallback( nEvent, &aKeyEvt );
3814 return nRet;
3816 else
3817 return 0;
3821 return 0;
3824 // -----------------------------------------------------------------------
3826 long ImplHandleSalObjSysCharMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
3828 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3829 if ( !pFrame )
3830 return 0;
3832 sal_uInt16 nRepeat = LOWORD( lParam )-1;
3833 sal_uInt16 nModCode = 0;
3834 sal_uInt16 cKeyCode = (sal_uInt16)wParam;
3836 // determine modifiers
3837 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
3838 nModCode |= KEY_SHIFT;
3839 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
3840 nModCode |= KEY_MOD1;
3841 nModCode |= KEY_MOD2;
3843 // KeyEvent zusammenbauen
3844 SalKeyEvent aKeyEvt;
3845 aKeyEvt.mnTime = GetMessageTime();
3846 if ( (cKeyCode >= 48) && (cKeyCode <= 57) )
3847 aKeyEvt.mnCode = KEY_0+(cKeyCode-48);
3848 else if ( (cKeyCode >= 65) && (cKeyCode <= 90) )
3849 aKeyEvt.mnCode = KEY_A+(cKeyCode-65);
3850 else if ( (cKeyCode >= 97) && (cKeyCode <= 122) )
3851 aKeyEvt.mnCode = KEY_A+(cKeyCode-97);
3852 else
3853 aKeyEvt.mnCode = 0;
3854 aKeyEvt.mnCode |= nModCode;
3855 aKeyEvt.mnCharCode = ImplGetCharCode( pFrame, cKeyCode );
3856 aKeyEvt.mnRepeat = nRepeat;
3857 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
3858 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
3859 return nRet;
3862 // -----------------------------------------------------------------------
3864 static bool ImplHandlePaintMsg( HWND hWnd )
3866 sal_Bool bMutex = FALSE;
3867 if ( ImplSalYieldMutexTryToAcquire() )
3868 bMutex = TRUE;
3870 // if we don't get the mutex, we can also change the clip region,
3871 // because other threads doesn't use the mutex from the main
3872 // thread --> see GetGraphics()
3874 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3875 if ( pFrame )
3877 // Clip-Region muss zurueckgesetzt werden, da wir sonst kein
3878 // ordentliches Bounding-Rectangle bekommen
3879 if ( pFrame->mpGraphics && pFrame->mpGraphics->mhRegion )
3880 SelectClipRgn( pFrame->mpGraphics->mhDC, 0 );
3882 // Laut Window-Doku soll man erst abfragen, ob ueberhaupt eine
3883 // Paint-Region anliegt
3884 if ( GetUpdateRect( hWnd, NULL, FALSE ) )
3886 // Call BeginPaint/EndPaint to query the rect and send
3887 // this Notofication to rect
3888 RECT aUpdateRect;
3889 PAINTSTRUCT aPs;
3890 BeginPaint( hWnd, &aPs );
3891 CopyRect( &aUpdateRect, &aPs.rcPaint );
3893 // Paint
3894 // ClipRegion wieder herstellen
3895 if ( pFrame->mpGraphics && pFrame->mpGraphics->mhRegion )
3897 SelectClipRgn( pFrame->mpGraphics->mhDC,
3898 pFrame->mpGraphics->mhRegion );
3901 if ( bMutex )
3903 SalPaintEvent aPEvt( aUpdateRect.left, aUpdateRect.top, aUpdateRect.right-aUpdateRect.left, aUpdateRect.bottom-aUpdateRect.top, pFrame->mbPresentation );
3904 pFrame->CallCallback( SALEVENT_PAINT, &aPEvt );
3906 else
3908 RECT* pRect = new RECT;
3909 CopyRect( pRect, &aUpdateRect );
3910 ImplPostMessage( hWnd, SAL_MSG_POSTPAINT, (WPARAM)pRect, 0 );
3912 EndPaint( hWnd, &aPs );
3914 else
3916 // ClipRegion wieder herstellen
3917 if ( pFrame->mpGraphics && pFrame->mpGraphics->mhRegion )
3919 SelectClipRgn( pFrame->mpGraphics->mhDC,
3920 pFrame->mpGraphics->mhRegion );
3925 if ( bMutex )
3926 ImplSalYieldMutexRelease();
3928 return bMutex ? true : false;
3931 // -----------------------------------------------------------------------
3933 static void ImplHandlePaintMsg2( HWND hWnd, RECT* pRect )
3935 // Paint
3936 if ( ImplSalYieldMutexTryToAcquire() )
3938 WinSalFrame* pFrame = GetWindowPtr( hWnd );
3939 if ( pFrame )
3941 SalPaintEvent aPEvt( pRect->left, pRect->top, pRect->right-pRect->left, pRect->bottom-pRect->top );
3942 pFrame->CallCallback( SALEVENT_PAINT, &aPEvt );
3944 ImplSalYieldMutexRelease();
3945 delete pRect;
3947 else
3948 ImplPostMessage( hWnd, SAL_MSG_POSTPAINT, (WPARAM)pRect, 0 );
3951 // -----------------------------------------------------------------------
3953 static void SetMaximizedFrameGeometry( HWND hWnd, WinSalFrame* pFrame, RECT* pParentRect )
3955 // calculate and set frame geometry of a maximized window - useful if the window is still hidden
3957 // dualmonitor support:
3958 // Get screensize of the monitor whith the mouse pointer
3960 RECT aRectMouse;
3961 if( ! pParentRect )
3963 POINT pt;
3964 GetCursorPos( &pt );
3965 aRectMouse.left = pt.x;
3966 aRectMouse.top = pt.y;
3967 aRectMouse.right = pt.x+2;
3968 aRectMouse.bottom = pt.y+2;
3969 pParentRect = &aRectMouse;
3972 RECT aRect;
3973 ImplSalGetWorkArea( hWnd, &aRect, pParentRect );
3975 // a maximized window has no other borders than the caption
3976 pFrame->maGeometry.nLeftDecoration = pFrame->maGeometry.nRightDecoration = pFrame->maGeometry.nBottomDecoration = 0;
3977 pFrame->maGeometry.nTopDecoration = pFrame->mbCaption ? GetSystemMetrics( SM_CYCAPTION ) : 0;
3979 aRect.top += pFrame->maGeometry.nTopDecoration;
3980 pFrame->maGeometry.nX = aRect.left;
3981 pFrame->maGeometry.nY = aRect.top;
3982 pFrame->maGeometry.nWidth = aRect.right - aRect.left;
3983 pFrame->maGeometry.nHeight = aRect.bottom - aRect.top;
3986 static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame )
3988 if( !pFrame )
3989 return;
3991 RECT aRect;
3992 GetWindowRect( hWnd, &aRect );
3993 memset(&pFrame->maGeometry, 0, sizeof(SalFrameGeometry) );
3995 if ( IsIconic( hWnd ) )
3996 return;
3998 POINT aPt;
3999 aPt.x=0;
4000 aPt.y=0;
4001 ClientToScreen(hWnd, &aPt);
4002 int cx = aPt.x - aRect.left;
4003 pFrame->maGeometry.nTopDecoration = aPt.y - aRect.top;
4005 pFrame->maGeometry.nLeftDecoration = cx;
4006 pFrame->maGeometry.nRightDecoration = cx;
4008 pFrame->maGeometry.nX = aPt.x;
4009 pFrame->maGeometry.nY = aPt.y;
4011 RECT aInnerRect;
4012 GetClientRect( hWnd, &aInnerRect );
4013 if( aInnerRect.right )
4015 // improve right decoration
4016 aPt.x=aInnerRect.right;
4017 aPt.y=aInnerRect.top;
4018 ClientToScreen(hWnd, &aPt);
4019 pFrame->maGeometry.nRightDecoration = aRect.right - aPt.x;
4021 if( aInnerRect.bottom ) // may be zero if window was not shown yet
4022 pFrame->maGeometry.nBottomDecoration += aRect.bottom - aPt.y - aInnerRect.bottom;
4023 else
4024 // bottom border is typically the same as left/right
4025 pFrame->maGeometry.nBottomDecoration = pFrame->maGeometry.nLeftDecoration;
4027 int nWidth = aRect.right - aRect.left
4028 - pFrame->maGeometry.nRightDecoration - pFrame->maGeometry.nLeftDecoration;
4029 int nHeight = aRect.bottom - aRect.top
4030 - pFrame->maGeometry.nBottomDecoration - pFrame->maGeometry.nTopDecoration;
4031 // clamp to zero
4032 pFrame->maGeometry.nHeight = nHeight < 0 ? 0 : nHeight;
4033 pFrame->maGeometry.nWidth = nWidth < 0 ? 0 : nWidth;
4034 pFrame->updateScreenNumber();
4037 // -----------------------------------------------------------------------
4039 static void ImplCallMoveHdl( HWND hWnd )
4041 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4042 if ( pFrame )
4044 pFrame->CallCallback( SALEVENT_MOVE, 0 );
4045 // Um doppelte Paints von VCL und SAL zu vermeiden
4046 //if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
4047 // UpdateWindow( hWnd );
4051 // -----------------------------------------------------------------------
4053 static void ImplCallClosePopupsHdl( HWND hWnd )
4055 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4056 if ( pFrame )
4058 pFrame->CallCallback( SALEVENT_CLOSEPOPUPS, 0 );
4062 // -----------------------------------------------------------------------
4064 static void ImplHandleMoveMsg( HWND hWnd )
4066 if ( ImplSalYieldMutexTryToAcquire() )
4068 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4069 if ( pFrame )
4071 UpdateFrameGeometry( hWnd, pFrame );
4073 if ( GetWindowStyle( hWnd ) & WS_VISIBLE )
4074 pFrame->mbDefPos = FALSE;
4076 // Gegen moegliche Rekursionen sichern
4077 if ( !pFrame->mbInMoveMsg )
4079 // Fenster im FullScreenModus wieder einpassen
4080 pFrame->mbInMoveMsg = TRUE;
4081 if ( pFrame->mbFullScreen )
4082 ImplSalFrameFullScreenPos( pFrame );
4083 pFrame->mbInMoveMsg = FALSE;
4086 // Status merken
4087 ImplSaveFrameState( pFrame );
4089 // Call Hdl
4090 //#93851 if we call this handler, VCL floating windows are not updated correctly
4091 ImplCallMoveHdl( hWnd );
4095 ImplSalYieldMutexRelease();
4097 else
4098 ImplPostMessage( hWnd, SAL_MSG_POSTMOVE, 0, 0 );
4101 // -----------------------------------------------------------------------
4103 static void ImplCallSizeHdl( HWND hWnd )
4105 // Da Windows diese Messages auch senden kann, muss hier auch die
4106 // Solar-Semaphore beruecksichtigt werden
4107 if ( ImplSalYieldMutexTryToAcquire() )
4109 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4110 if ( pFrame )
4112 pFrame->CallCallback( SALEVENT_RESIZE, 0 );
4113 // Um doppelte Paints von VCL und SAL zu vermeiden
4114 if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
4115 UpdateWindow( hWnd );
4118 ImplSalYieldMutexRelease();
4120 else
4121 ImplPostMessage( hWnd, SAL_MSG_POSTCALLSIZE, 0, 0 );
4124 // -----------------------------------------------------------------------
4126 static void ImplHandleSizeMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
4128 if ( (wParam != SIZE_MAXSHOW) && (wParam != SIZE_MAXHIDE) )
4130 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4131 if ( pFrame )
4133 UpdateFrameGeometry( hWnd, pFrame );
4135 pFrame->mnWidth = (int)LOWORD(lParam);
4136 pFrame->mnHeight = (int)HIWORD(lParam);
4137 // Status merken
4138 ImplSaveFrameState( pFrame );
4139 // Call Hdl
4140 ImplCallSizeHdl( hWnd );
4145 // -----------------------------------------------------------------------
4147 static void ImplHandleFocusMsg( HWND hWnd )
4149 if ( ImplSalYieldMutexTryToAcquire() )
4151 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4152 if ( pFrame && !WinSalFrame::mbInReparent )
4154 // Query the actual status
4155 if ( ::GetFocus() == hWnd )
4157 if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
4158 UpdateWindow( hWnd );
4160 // Feststellen, ob wir IME unterstuetzen
4161 if ( pFrame->mbIME && pFrame->mhDefIMEContext )
4163 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY );
4165 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
4166 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
4167 pFrame->mbHandleIME = !pFrame->mbSpezIME;
4170 pFrame->CallCallback( SALEVENT_GETFOCUS, 0 );
4172 else
4174 pFrame->CallCallback( SALEVENT_LOSEFOCUS, 0 );
4178 ImplSalYieldMutexRelease();
4180 else
4181 ImplPostMessage( hWnd, SAL_MSG_POSTFOCUS, 0, 0 );
4184 // -----------------------------------------------------------------------
4186 static void ImplHandleCloseMsg( HWND hWnd )
4188 if ( ImplSalYieldMutexTryToAcquire() )
4190 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4191 if ( pFrame )
4193 pFrame->CallCallback( SALEVENT_CLOSE, 0 );
4196 ImplSalYieldMutexRelease();
4198 else
4199 ImplPostMessage( hWnd, WM_CLOSE, 0, 0 );
4202 // -----------------------------------------------------------------------
4204 static long ImplHandleShutDownMsg( HWND hWnd )
4206 ImplSalYieldMutexAcquireWithWait();
4207 long nRet = 0;
4208 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4209 if ( pFrame )
4211 nRet = pFrame->CallCallback( SALEVENT_SHUTDOWN, 0 );
4213 ImplSalYieldMutexRelease();
4214 return nRet;
4217 // -----------------------------------------------------------------------
4219 static void ImplHandleSettingsChangeMsg( HWND hWnd, UINT nMsg,
4220 WPARAM wParam, LPARAM lParam )
4222 sal_uInt16 nSalEvent = SALEVENT_SETTINGSCHANGED;
4224 if ( nMsg == WM_DEVMODECHANGE )
4225 nSalEvent = SALEVENT_PRINTERCHANGED;
4226 else if ( nMsg == WM_DISPLAYCHANGE )
4227 nSalEvent = SALEVENT_DISPLAYCHANGED;
4228 else if ( nMsg == WM_FONTCHANGE )
4229 nSalEvent = SALEVENT_FONTCHANGED;
4230 else if ( nMsg == WM_TIMECHANGE )
4231 nSalEvent = SALEVENT_DATETIMECHANGED;
4232 else if ( nMsg == WM_WININICHANGE )
4234 if ( lParam )
4236 if ( ImplSalWICompareAscii( (const wchar_t*)lParam, "devices" ) == 0 )
4237 nSalEvent = SALEVENT_PRINTERCHANGED;
4241 if ( nMsg == WM_SETTINGCHANGE )
4243 if ( wParam == SPI_SETWHEELSCROLLLINES )
4244 aSalShlData.mnWheelScrollLines = ImplSalGetWheelScrollLines();
4245 else if( wParam == SPI_SETWHEELSCROLLCHARS )
4246 aSalShlData.mnWheelScrollChars = ImplSalGetWheelScrollChars();
4249 if ( WM_SYSCOLORCHANGE == nMsg && GetSalData()->mhDitherPal )
4250 ImplUpdateSysColorEntries();
4252 ImplSalYieldMutexAcquireWithWait();
4254 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4255 if ( pFrame )
4257 if ( (nMsg == WM_DISPLAYCHANGE) || (nMsg == WM_WININICHANGE) )
4259 if ( pFrame->mbFullScreen )
4260 ImplSalFrameFullScreenPos( pFrame );
4263 pFrame->CallCallback( nSalEvent, 0 );
4266 ImplSalYieldMutexRelease();
4269 // -----------------------------------------------------------------------
4271 static void ImplHandleUserEvent( HWND hWnd, LPARAM lParam )
4273 ImplSalYieldMutexAcquireWithWait();
4274 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4275 if ( pFrame )
4277 pFrame->CallCallback( SALEVENT_USEREVENT, (void*)lParam );
4279 ImplSalYieldMutexRelease();
4282 // -----------------------------------------------------------------------
4284 static void ImplHandleForcePalette( HWND hWnd )
4286 SalData* pSalData = GetSalData();
4287 HPALETTE hPal = pSalData->mhDitherPal;
4288 if ( hPal )
4290 if ( !ImplSalYieldMutexTryToAcquire() )
4292 ImplPostMessage( hWnd, SAL_MSG_FORCEPALETTE, 0, 0 );
4293 return;
4296 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4297 if ( pFrame && pFrame->mpGraphics )
4299 WinSalGraphics* pGraphics = pFrame->mpGraphics;
4300 if ( pGraphics && pGraphics->mhDefPal )
4302 SelectPalette( pGraphics->mhDC, hPal, FALSE );
4303 if ( RealizePalette( pGraphics->mhDC ) )
4305 InvalidateRect( hWnd, NULL, FALSE );
4306 UpdateWindow( hWnd );
4307 pFrame->CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
4312 ImplSalYieldMutexRelease();
4316 // -----------------------------------------------------------------------
4318 static LRESULT ImplHandlePalette( sal_Bool bFrame, HWND hWnd, UINT nMsg,
4319 WPARAM wParam, LPARAM lParam, int& rDef )
4321 SalData* pSalData = GetSalData();
4322 HPALETTE hPal = pSalData->mhDitherPal;
4323 if ( !hPal )
4324 return 0;
4326 rDef = FALSE;
4327 if ( pSalData->mbInPalChange )
4328 return 0;
4330 if ( (nMsg == WM_PALETTECHANGED) || (nMsg == SAL_MSG_POSTPALCHANGED) )
4332 if ( (HWND)wParam == hWnd )
4333 return 0;
4336 sal_Bool bReleaseMutex = FALSE;
4337 if ( (nMsg == WM_QUERYNEWPALETTE) || (nMsg == WM_PALETTECHANGED) )
4339 // Da Windows diese Messages auch sendet, muss hier auch die
4340 // Solar-Semaphore beruecksichtigt werden
4341 if ( ImplSalYieldMutexTryToAcquire() )
4342 bReleaseMutex = TRUE;
4343 else if ( nMsg == WM_QUERYNEWPALETTE )
4344 ImplPostMessage( hWnd, SAL_MSG_POSTQUERYNEWPAL, wParam, lParam );
4345 else /* ( nMsg == WM_PALETTECHANGED ) */
4346 ImplPostMessage( hWnd, SAL_MSG_POSTPALCHANGED, wParam, lParam );
4349 WinSalVirtualDevice*pTempVD;
4350 WinSalFrame* pTempFrame;
4351 WinSalGraphics* pGraphics;
4352 HDC hDC;
4353 HPALETTE hOldPal;
4354 UINT nCols;
4355 sal_Bool bStdDC;
4356 sal_Bool bUpdate;
4358 pSalData->mbInPalChange = TRUE;
4360 // Alle Paletten in VirDevs und Frames zuruecksetzen
4361 pTempVD = pSalData->mpFirstVD;
4362 while ( pTempVD )
4364 pGraphics = pTempVD->mpGraphics;
4365 if ( pGraphics->mhDefPal )
4367 SelectPalette( pGraphics->mhDC,
4368 pGraphics->mhDefPal,
4369 TRUE );
4371 pTempVD = pTempVD->mpNext;
4373 pTempFrame = pSalData->mpFirstFrame;
4374 while ( pTempFrame )
4376 pGraphics = pTempFrame->mpGraphics;
4377 if ( pGraphics && pGraphics->mhDefPal )
4379 SelectPalette( pGraphics->mhDC,
4380 pGraphics->mhDefPal,
4381 TRUE );
4383 pTempFrame = pTempFrame->mpNextFrame;
4386 // Palette neu realizen
4387 WinSalFrame* pFrame = NULL;
4388 if ( bFrame )
4389 pFrame = GetWindowPtr( hWnd );
4390 if ( pFrame && pFrame->mpGraphics )
4392 hDC = pFrame->mpGraphics->mhDC;
4393 bStdDC = TRUE;
4395 else
4397 hDC = GetDC( hWnd );
4398 bStdDC = FALSE;
4400 UnrealizeObject( hPal );
4401 hOldPal = SelectPalette( hDC, hPal, TRUE );
4402 nCols = RealizePalette( hDC );
4403 bUpdate = nCols != 0;
4404 if ( !bStdDC )
4406 SelectPalette( hDC, hOldPal, TRUE );
4407 ReleaseDC( hWnd, hDC );
4410 // Alle Paletten in VirDevs und Frames neu setzen
4411 pTempVD = pSalData->mpFirstVD;
4412 while ( pTempVD )
4414 pGraphics = pTempVD->mpGraphics;
4415 if ( pGraphics->mhDefPal )
4417 SelectPalette( pGraphics->mhDC, hPal, TRUE );
4418 RealizePalette( pGraphics->mhDC );
4420 pTempVD = pTempVD->mpNext;
4422 pTempFrame = pSalData->mpFirstFrame;
4423 while ( pTempFrame )
4425 if ( pTempFrame != pFrame )
4427 pGraphics = pTempFrame->mpGraphics;
4428 if ( pGraphics && pGraphics->mhDefPal )
4430 SelectPalette( pGraphics->mhDC, hPal, TRUE );
4431 if ( RealizePalette( pGraphics->mhDC ) )
4432 bUpdate = TRUE;
4435 pTempFrame = pTempFrame->mpNextFrame;
4438 // Wenn sich Farben geaendert haben, dann die Fenster updaten
4439 if ( bUpdate )
4441 pTempFrame = pSalData->mpFirstFrame;
4442 while ( pTempFrame )
4444 pGraphics = pTempFrame->mpGraphics;
4445 if ( pGraphics && pGraphics->mhDefPal )
4447 InvalidateRect( pTempFrame->mhWnd, NULL, FALSE );
4448 UpdateWindow( pTempFrame->mhWnd );
4449 pTempFrame->CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
4451 pTempFrame = pTempFrame->mpNextFrame;
4455 pSalData->mbInPalChange = FALSE;
4457 if ( bReleaseMutex )
4458 ImplSalYieldMutexRelease();
4460 if ( nMsg == WM_PALETTECHANGED )
4461 return 0;
4462 else
4463 return nCols;
4466 // -----------------------------------------------------------------------
4468 static int ImplHandleMinMax( HWND hWnd, LPARAM lParam )
4470 int bRet = FALSE;
4472 if ( ImplSalYieldMutexTryToAcquire() )
4474 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4475 if ( pFrame )
4477 MINMAXINFO* pMinMax = (MINMAXINFO*)lParam;
4479 if ( pFrame->mbFullScreen )
4481 int nX;
4482 int nY;
4483 int nDX;
4484 int nDY;
4485 ImplSalCalcFullScreenSize( pFrame, nX, nY, nDX, nDY );
4487 if ( pMinMax->ptMaxPosition.x > nX )
4488 pMinMax->ptMaxPosition.x = nX;
4489 if ( pMinMax->ptMaxPosition.y > nY )
4490 pMinMax->ptMaxPosition.y = nY;
4492 if ( pMinMax->ptMaxSize.x < nDX )
4493 pMinMax->ptMaxSize.x = nDX;
4494 if ( pMinMax->ptMaxSize.y < nDY )
4495 pMinMax->ptMaxSize.y = nDY;
4496 if ( pMinMax->ptMaxTrackSize.x < nDX )
4497 pMinMax->ptMaxTrackSize.x = nDX;
4498 if ( pMinMax->ptMaxTrackSize.y < nDY )
4499 pMinMax->ptMaxTrackSize.y = nDY;
4501 pMinMax->ptMinTrackSize.x = nDX;
4502 pMinMax->ptMinTrackSize.y = nDY;
4504 bRet = TRUE;
4507 if ( pFrame->mnMinWidth || pFrame->mnMinHeight )
4509 int nWidth = pFrame->mnMinWidth;
4510 int nHeight = pFrame->mnMinHeight;
4512 ImplSalAddBorder( pFrame, nWidth, nHeight );
4514 if ( pMinMax->ptMinTrackSize.x < nWidth )
4515 pMinMax->ptMinTrackSize.x = nWidth;
4516 if ( pMinMax->ptMinTrackSize.y < nHeight )
4517 pMinMax->ptMinTrackSize.y = nHeight;
4520 if ( pFrame->mnMaxWidth || pFrame->mnMaxHeight )
4522 int nWidth = pFrame->mnMaxWidth;
4523 int nHeight = pFrame->mnMaxHeight;
4525 ImplSalAddBorder( pFrame, nWidth, nHeight );
4527 if( nWidth > 0 && nHeight > 0 ) // protect against int overflow due to INT_MAX initialisation
4529 if ( pMinMax->ptMaxTrackSize.x > nWidth )
4530 pMinMax->ptMaxTrackSize.x = nWidth;
4531 if ( pMinMax->ptMaxTrackSize.y > nHeight )
4532 pMinMax->ptMaxTrackSize.y = nHeight;
4537 ImplSalYieldMutexRelease();
4540 return bRet;
4543 // -----------------------------------------------------------------------
4545 // retrieves the SalMenuItem pointer from a hMenu
4546 // the pointer is stored in every item, so if no position
4547 // is specified we just use the first item (ie, pos=0)
4548 // if bByPosition is FALSE then nPos denotes a menu id instead of a position
4549 static WinSalMenuItem* ImplGetSalMenuItem( HMENU hMenu, UINT nPos, sal_Bool bByPosition=TRUE )
4551 MENUITEMINFOW mi;
4552 memset(&mi, 0, sizeof(mi));
4553 mi.cbSize = sizeof( mi );
4554 mi.fMask = MIIM_DATA;
4555 if( !GetMenuItemInfoW( hMenu, nPos, bByPosition, &mi) )
4556 ImplWriteLastError( GetLastError(), "ImplGetSalMenuItem" );
4558 return (WinSalMenuItem *) mi.dwItemData;
4561 // returns the index of the currently selected item if any or -1
4562 static int ImplGetSelectedIndex( HMENU hMenu )
4564 MENUITEMINFOW mi;
4565 memset(&mi, 0, sizeof(mi));
4566 mi.cbSize = sizeof( mi );
4567 mi.fMask = MIIM_STATE;
4568 int n = GetMenuItemCount( hMenu );
4569 if( n != -1 )
4571 for(int i=0; i<n; i++ )
4573 if( !GetMenuItemInfoW( hMenu, i, TRUE, &mi) )
4574 ImplWriteLastError( GetLastError(), "ImplGetSelectedIndex" );
4575 else
4577 if( mi.fState & MFS_HILITE )
4578 return i;
4582 return -1;
4585 static int ImplMenuChar( HWND, WPARAM wParam, LPARAM lParam )
4587 int nRet = MNC_IGNORE;
4588 HMENU hMenu = (HMENU) lParam;
4589 String aMnemonic;
4590 aMnemonic.AssignAscii("&");
4591 aMnemonic.Append( (sal_Unicode) LOWORD(wParam) );
4592 aMnemonic.ToLowerAscii(); // we only have ascii mnemonics
4594 // search the mnemonic in the current menu
4595 int nItemCount = GetMenuItemCount( hMenu );
4596 int nFound = 0;
4597 int idxFound = -1;
4598 int idxSelected = ImplGetSelectedIndex( hMenu );
4599 int idx = idxSelected != -1 ? idxSelected+1 : 0; // if duplicate mnemonics cycle through menu
4600 for( int i=0; i< nItemCount; i++, idx++ )
4602 WinSalMenuItem* pSalMenuItem = ImplGetSalMenuItem( hMenu, idx % nItemCount );
4603 if( !pSalMenuItem )
4604 continue;
4605 String aStr = pSalMenuItem->mText;
4606 aStr.ToLowerAscii();
4607 if( aStr.Search( aMnemonic ) != STRING_NOTFOUND)
4609 if( idxFound == -1 )
4610 idxFound = idx % nItemCount;
4611 if( nFound++ )
4612 break; // duplicate found
4615 if( nFound == 1 )
4616 nRet = MAKELRESULT( idxFound, MNC_EXECUTE );
4617 else
4618 // duplicate mnemonics, just select the next occurrence
4619 nRet = MAKELRESULT( idxFound, MNC_SELECT );
4621 return nRet;
4624 static int ImplMeasureItem( HWND hWnd, WPARAM wParam, LPARAM lParam )
4626 int nRet = 0;
4627 if( !wParam )
4629 // request was sent by a menu
4630 nRet = 1;
4631 MEASUREITEMSTRUCT *pMI = (LPMEASUREITEMSTRUCT) lParam;
4632 if( pMI->CtlType != ODT_MENU )
4633 return 0;
4635 WinSalMenuItem *pSalMenuItem = (WinSalMenuItem *) pMI->itemData;
4636 if( !pSalMenuItem )
4637 return 0;
4639 HDC hdc = GetDC( hWnd );
4640 SIZE strSize;
4642 NONCLIENTMETRICS ncm;
4643 memset( &ncm, 0, sizeof(ncm) );
4644 ncm.cbSize = sizeof( ncm );
4645 SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, (PVOID) &ncm, 0 );
4647 // Assume every menu item can be default and printed bold
4648 //ncm.lfMenuFont.lfWeight = FW_BOLD;
4650 HFONT hfntOld = (HFONT) SelectObject(hdc, (HFONT) CreateFontIndirect( &ncm.lfMenuFont ));
4652 // menu text and accelerator
4653 String aStr(pSalMenuItem->mText);
4654 if( pSalMenuItem->mAccelText.Len() )
4656 aStr.AppendAscii(" ");
4657 aStr.Append( pSalMenuItem->mAccelText );
4659 GetTextExtentPoint32W( hdc, (LPWSTR) aStr.GetBuffer(),
4660 aStr.Len(), &strSize );
4662 // image
4663 Size bmpSize( 16, 16 );
4664 //if( !!pSalMenuItem->maBitmap )
4665 // bmpSize = pSalMenuItem->maBitmap.GetSizePixel();
4667 // checkmark
4668 Size checkSize( GetSystemMetrics( SM_CXMENUCHECK ), GetSystemMetrics( SM_CYMENUCHECK ) );
4670 pMI->itemWidth = checkSize.Width() + 3 + bmpSize.Width() + 3 + strSize.cx;
4671 pMI->itemHeight = Max( Max( checkSize.Height(), bmpSize.Height() ), strSize.cy );
4672 pMI->itemHeight += 4;
4674 DeleteObject( SelectObject(hdc, hfntOld) );
4675 ReleaseDC( hWnd, hdc );
4678 return nRet;
4681 static int ImplDrawItem(HWND, WPARAM wParam, LPARAM lParam )
4683 int nRet = 0;
4684 if( !wParam )
4686 // request was sent by a menu
4687 nRet = 1;
4688 DRAWITEMSTRUCT *pDI = (LPDRAWITEMSTRUCT) lParam;
4689 if( pDI->CtlType != ODT_MENU )
4690 return 0;
4692 WinSalMenuItem *pSalMenuItem = (WinSalMenuItem *) pDI->itemData;
4693 if( !pSalMenuItem )
4694 return 0;
4696 COLORREF clrPrevText, clrPrevBkgnd;
4697 HFONT hfntOld;
4698 HBRUSH hbrOld;
4699 sal_Bool fChecked = (pDI->itemState & ODS_CHECKED) ? TRUE : FALSE;
4700 sal_Bool fSelected = (pDI->itemState & ODS_SELECTED) ? TRUE : FALSE;
4701 sal_Bool fDisabled = (pDI->itemState & (ODS_DISABLED | ODS_GRAYED)) ? TRUE : FALSE;
4703 // Set the appropriate foreground and background colors.
4704 RECT aRect = pDI->rcItem;
4706 clrPrevBkgnd = SetBkColor( pDI->hDC, GetSysColor( COLOR_MENU ) );
4708 if ( fDisabled )
4709 clrPrevText = SetTextColor( pDI->hDC, GetSysColor( COLOR_GRAYTEXT ) );
4710 else
4711 clrPrevText = SetTextColor( pDI->hDC, GetSysColor( fSelected ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT ) );
4713 DWORD colBackground = GetSysColor( fSelected ? COLOR_HIGHLIGHT : COLOR_MENU );
4714 clrPrevBkgnd = SetBkColor( pDI->hDC, colBackground );
4716 hbrOld = (HBRUSH)SelectObject( pDI->hDC, CreateSolidBrush( GetBkColor( pDI->hDC ) ) );
4718 // Fill background
4719 if(!PatBlt( pDI->hDC, aRect.left, aRect.top, aRect.right-aRect.left, aRect.bottom-aRect.top, PATCOPY ))
4720 ImplWriteLastError(GetLastError(), "ImplDrawItem");
4722 int lineHeight = aRect.bottom-aRect.top;
4724 int x = aRect.left;
4725 int y = aRect.top;
4727 int checkWidth = GetSystemMetrics( SM_CXMENUCHECK );
4728 int checkHeight = GetSystemMetrics( SM_CYMENUCHECK );
4729 if( fChecked )
4731 RECT r;
4732 r.left = 0;
4733 r.top = 0;
4734 r.right = checkWidth;
4735 r.bottom = checkWidth;
4736 HDC memDC = CreateCompatibleDC( pDI->hDC );
4737 HBITMAP memBmp = CreateCompatibleBitmap( pDI->hDC, checkWidth, checkHeight );
4738 HBITMAP hOldBmp = (HBITMAP) SelectObject( memDC, memBmp );
4739 DrawFrameControl( memDC, &r, DFC_MENU, DFCS_MENUCHECK );
4740 BitBlt( pDI->hDC, x, y+(lineHeight-checkHeight)/2, checkWidth, checkHeight, memDC, 0, 0, SRCAND );
4741 DeleteObject( SelectObject( memDC, hOldBmp ) );
4742 DeleteDC( memDC );
4744 x += checkWidth+3;
4746 //Size bmpSize = aBitmap.GetSizePixel();
4747 Size bmpSize(16, 16);
4748 if( !!pSalMenuItem->maBitmap )
4750 Bitmap aBitmap( pSalMenuItem->maBitmap );
4752 // set transparent pixels to background color
4753 if( fDisabled )
4754 colBackground = RGB(255,255,255);
4755 aBitmap.Replace( Color( COL_LIGHTMAGENTA ),
4756 Color( GetRValue(colBackground),GetGValue(colBackground),GetBValue(colBackground) ), 0);
4758 WinSalBitmap* pSalBmp = static_cast<WinSalBitmap*>(aBitmap.ImplGetImpBitmap()->ImplGetSalBitmap());
4759 HGLOBAL hDrawDIB = pSalBmp->ImplGethDIB();
4761 if( hDrawDIB )
4763 PBITMAPINFO pBI = (PBITMAPINFO) GlobalLock( hDrawDIB );
4764 PBITMAPINFOHEADER pBIH = (PBITMAPINFOHEADER) pBI;
4765 PBYTE pBits = (PBYTE) pBI + *(DWORD*) pBI +
4766 pSalBmp->ImplGetDIBColorCount( hDrawDIB ) * sizeof( RGBQUAD );
4768 HBITMAP hBmp = CreateDIBitmap( pDI->hDC, pBIH, CBM_INIT, pBits, pBI, DIB_RGB_COLORS );
4769 GlobalUnlock( hDrawDIB );
4771 HBRUSH hbrIcon = CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT ) );
4772 DrawStateW( pDI->hDC, (HBRUSH)hbrIcon, (DRAWSTATEPROC)NULL, (LPARAM)hBmp, (WPARAM)0,
4773 x, y+(lineHeight-bmpSize.Height())/2, bmpSize.Width(), bmpSize.Height(),
4774 DST_BITMAP | (fDisabled ? (fSelected ? DSS_MONO : DSS_DISABLED) : DSS_NORMAL) );
4776 DeleteObject( hbrIcon );
4777 DeleteObject( hBmp );
4781 x += bmpSize.Width() + 3;
4782 aRect.left = x;
4784 NONCLIENTMETRICS ncm;
4785 memset( &ncm, 0, sizeof(ncm) );
4786 ncm.cbSize = sizeof( ncm );
4787 SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, (PVOID) &ncm, 0 );
4789 // Print default menu entry with bold font
4790 //if ( pDI->itemState & ODS_DEFAULT )
4791 // ncm.lfMenuFont.lfWeight = FW_BOLD;
4793 hfntOld = (HFONT) SelectObject(pDI->hDC, (HFONT) CreateFontIndirect( &ncm.lfMenuFont ));
4795 SIZE strSize;
4796 String aStr( pSalMenuItem->mText );
4797 GetTextExtentPoint32W( pDI->hDC, (LPWSTR) aStr.GetBuffer(),
4798 aStr.Len(), &strSize );
4800 if(!DrawStateW( pDI->hDC, (HBRUSH)NULL, (DRAWSTATEPROC)NULL,
4801 (LPARAM)(LPWSTR) aStr.GetBuffer(),
4802 (WPARAM)0, aRect.left, aRect.top + (lineHeight - strSize.cy)/2, 0, 0,
4803 DST_PREFIXTEXT | (fDisabled && !fSelected ? DSS_DISABLED : DSS_NORMAL) ) )
4804 ImplWriteLastError(GetLastError(), "ImplDrawItem");
4806 if( pSalMenuItem->mAccelText.Len() )
4808 SIZE strSizeA;
4809 aStr = pSalMenuItem->mAccelText;
4810 GetTextExtentPoint32W( pDI->hDC, (LPWSTR) aStr.GetBuffer(),
4811 aStr.Len(), &strSizeA );
4812 TEXTMETRIC tm;
4813 GetTextMetrics( pDI->hDC, &tm );
4815 // position the accelerator string to the right but leave space for the
4816 // (potential) submenu arrow (tm.tmMaxCharWidth)
4817 if(!DrawStateW( pDI->hDC, (HBRUSH)NULL, (DRAWSTATEPROC)NULL,
4818 (LPARAM)(LPWSTR) aStr.GetBuffer(),
4819 (WPARAM)0, aRect.right-strSizeA.cx-tm.tmMaxCharWidth, aRect.top + (lineHeight - strSizeA.cy)/2, 0, 0,
4820 DST_TEXT | (fDisabled && !fSelected ? DSS_DISABLED : DSS_NORMAL) ) )
4821 ImplWriteLastError(GetLastError(), "ImplDrawItem");
4824 // Restore the original font and colors.
4825 DeleteObject( SelectObject( pDI->hDC, hbrOld ) );
4826 DeleteObject( SelectObject( pDI->hDC, hfntOld) );
4827 SetTextColor(pDI->hDC, clrPrevText);
4828 SetBkColor(pDI->hDC, clrPrevBkgnd);
4830 return nRet;
4833 static int ImplHandleMenuActivate( HWND hWnd, WPARAM wParam, LPARAM )
4835 // Menu activation
4836 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4837 if ( !pFrame )
4838 return 0;
4840 HMENU hMenu = (HMENU) wParam;
4841 // WORD nPos = LOWORD (lParam);
4842 // sal_Bool bWindowMenu = (sal_Bool) HIWORD(lParam);
4844 // Send activate and deactivate together, so we have not keep track of opened menus
4845 // this will be enough to have the menus updated correctly
4846 SalMenuEvent aMenuEvt;
4847 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, 0 );
4848 if( pSalMenuItem )
4849 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
4850 else
4851 aMenuEvt.mpMenu = NULL;
4853 long nRet = pFrame->CallCallback( SALEVENT_MENUACTIVATE, &aMenuEvt );
4854 if( nRet )
4855 nRet = pFrame->CallCallback( SALEVENT_MENUDEACTIVATE, &aMenuEvt );
4856 if( nRet )
4857 pFrame->mLastActivatedhMenu = hMenu;
4859 return (nRet!=0);
4862 static int ImplHandleMenuSelect( HWND hWnd, WPARAM wParam, LPARAM lParam )
4864 // Menu selection
4865 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4866 if ( !pFrame )
4867 return 0;
4869 WORD nId = LOWORD(wParam); // menu item or submenu index
4870 WORD nFlags = HIWORD(wParam);
4871 HMENU hMenu = (HMENU) lParam;
4873 // check if we have to process the message
4874 if( !GetSalData()->IsKnownMenuHandle( hMenu ) )
4875 return 0;
4877 sal_Bool bByPosition = FALSE;
4878 if( nFlags & MF_POPUP )
4879 bByPosition = TRUE;
4881 long nRet = 0;
4882 if ( hMenu && !pFrame->mLastActivatedhMenu )
4884 // we never activated a menu (ie, no WM_INITMENUPOPUP has occurred yet)
4885 // which means this must be the menubar -> send activation/deactivation
4886 SalMenuEvent aMenuEvt;
4887 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, nId, bByPosition );
4888 if( pSalMenuItem )
4889 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
4890 else
4891 aMenuEvt.mpMenu = NULL;
4893 nRet = pFrame->CallCallback( SALEVENT_MENUACTIVATE, &aMenuEvt );
4894 if( nRet )
4895 nRet = pFrame->CallCallback( SALEVENT_MENUDEACTIVATE, &aMenuEvt );
4896 if( nRet )
4897 pFrame->mLastActivatedhMenu = hMenu;
4900 if( !hMenu && nFlags == 0xFFFF )
4902 // all menus are closed, reset activation logic
4903 pFrame->mLastActivatedhMenu = NULL;
4906 if( hMenu )
4908 // hMenu must be saved, as it is not passed in WM_COMMAND which always occurs after a selection
4909 // if a menu is closed due to a command selection then hMenu is NULL, but WM_COMMAND comes later
4910 // so we must not overwrite it in this case
4911 pFrame->mSelectedhMenu = hMenu;
4913 // send highlight event
4914 if( nFlags & MF_POPUP )
4916 // submenu selected
4917 // wParam now carries an index instead of an id -> retrieve id
4918 MENUITEMINFOW mi;
4919 memset(&mi, 0, sizeof(mi));
4920 mi.cbSize = sizeof( mi );
4921 mi.fMask = MIIM_ID;
4922 if( GetMenuItemInfoW( hMenu, LOWORD(wParam), TRUE, &mi) )
4923 nId = sal::static_int_cast<WORD>(mi.wID);
4926 SalMenuEvent aMenuEvt;
4927 aMenuEvt.mnId = nId;
4928 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( hMenu, nId, FALSE );
4929 if( pSalMenuItem )
4930 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
4931 else
4932 aMenuEvt.mpMenu = NULL;
4934 nRet = pFrame->CallCallback( SALEVENT_MENUHIGHLIGHT, &aMenuEvt );
4937 return (nRet != 0);
4940 static int ImplHandleCommand( HWND hWnd, WPARAM wParam, LPARAM )
4942 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4943 if ( !pFrame )
4944 return 0;
4946 long nRet = 0;
4947 if( !HIWORD(wParam) )
4949 // Menu command
4950 WORD nId = LOWORD(wParam);
4951 if( nId ) // zero for separators
4953 SalMenuEvent aMenuEvt;
4954 aMenuEvt.mnId = nId;
4955 WinSalMenuItem *pSalMenuItem = ImplGetSalMenuItem( pFrame->mSelectedhMenu, nId, FALSE );
4956 if( pSalMenuItem )
4957 aMenuEvt.mpMenu = pSalMenuItem->mpMenu;
4958 else
4959 aMenuEvt.mpMenu = NULL;
4961 nRet = pFrame->CallCallback( SALEVENT_MENUCOMMAND, &aMenuEvt );
4964 return (nRet != 0);
4967 static int ImplHandleSysCommand( HWND hWnd, WPARAM wParam, LPARAM lParam )
4969 WinSalFrame* pFrame = GetWindowPtr( hWnd );
4970 if ( !pFrame )
4971 return 0;
4973 WPARAM nCommand = wParam & 0xFFF0;
4975 if ( pFrame->mbFullScreen )
4977 BOOL bMaximize = IsZoomed( pFrame->mhWnd );
4978 BOOL bMinimize = IsIconic( pFrame->mhWnd );
4979 if ( (nCommand == SC_SIZE) ||
4980 (!bMinimize && (nCommand == SC_MOVE)) ||
4981 (!bMaximize && (nCommand == SC_MAXIMIZE)) ||
4982 (bMaximize && (nCommand == SC_RESTORE)) )
4984 return TRUE;
4988 if ( nCommand == SC_KEYMENU )
4990 // do not process SC_KEYMENU if we have a native menu
4991 // Windows should handle this
4992 if( GetMenu( hWnd ) )
4993 return FALSE;
4995 // Hier verarbeiten wir nur KeyMenu-Events fuer Alt um
4996 // den MenuBar zu aktivieren, oder wenn ein SysChild-Fenster
4997 // den Focus hat, da diese Alt+Tasten-Kombinationen nur
4998 // ueber diesen Event verarbeitet werden
4999 if ( !LOWORD( lParam ) )
5001 // Nur ausloesen, wenn keine weitere Taste gedrueckt ist. Im
5002 // Gegensatz zur Doku wird in der X-Koordinaate der CharCode
5003 // geliefert, der zusaetzlich gedrueckt ist
5004 // Also 32 fuer Space, 99 fuer c, 100 fuer d, ...
5005 // Da dies nicht dokumentiert ist, fragen wir vorsichtshalber
5006 // auch den Status der Space-Taste ab
5007 if ( GetKeyState( VK_SPACE ) & 0x8000 )
5008 return 0;
5010 // Damit nicht bei Alt+Maustaste auch der MenuBar aktiviert wird
5011 if ( (GetKeyState( VK_LBUTTON ) & 0x8000) ||
5012 (GetKeyState( VK_RBUTTON ) & 0x8000) ||
5013 (GetKeyState( VK_MBUTTON ) & 0x8000) ||
5014 (GetKeyState( VK_SHIFT ) & 0x8000) )
5015 return 1;
5017 SalKeyEvent aKeyEvt;
5018 aKeyEvt.mnTime = GetMessageTime();
5019 aKeyEvt.mnCode = KEY_MENU;
5020 aKeyEvt.mnCharCode = 0;
5021 aKeyEvt.mnRepeat = 0;
5022 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
5023 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
5024 return (nRet != 0);
5026 else
5028 // Testen, ob ein SysChild den Focus hat
5029 HWND hFocusWnd = ::GetFocus();
5030 if ( hFocusWnd && ImplFindSalObject( hFocusWnd ) )
5032 char cKeyCode = (char)(unsigned char)LOWORD( lParam );
5033 // LowerCase
5034 if ( (cKeyCode >= 65) && (cKeyCode <= 90) )
5035 cKeyCode += 32;
5036 // Wir nehmen nur 0-9 und A-Z, alle anderen Tasten muessen durch
5037 // den Hook vom SalObj verarbeitet werden
5038 if ( ((cKeyCode >= 48) && (cKeyCode <= 57)) ||
5039 ((cKeyCode >= 97) && (cKeyCode <= 122)) )
5041 sal_uInt16 nModCode = 0;
5042 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
5043 nModCode |= KEY_SHIFT;
5044 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
5045 nModCode |= KEY_MOD1;
5046 nModCode |= KEY_MOD2;
5048 SalKeyEvent aKeyEvt;
5049 aKeyEvt.mnTime = GetMessageTime();
5050 if ( (cKeyCode >= 48) && (cKeyCode <= 57) )
5051 aKeyEvt.mnCode = KEY_0+(cKeyCode-48);
5052 else
5053 aKeyEvt.mnCode = KEY_A+(cKeyCode-97);
5054 aKeyEvt.mnCode |= nModCode;
5055 aKeyEvt.mnCharCode = cKeyCode;
5056 aKeyEvt.mnRepeat = 0;
5057 long nRet = pFrame->CallCallback( SALEVENT_KEYINPUT, &aKeyEvt );
5058 pFrame->CallCallback( SALEVENT_KEYUP, &aKeyEvt );
5059 return (nRet != 0);
5065 return FALSE;
5068 // -----------------------------------------------------------------------
5070 static void ImplHandleInputLangChange( HWND hWnd, WPARAM, LPARAM lParam )
5072 ImplSalYieldMutexAcquireWithWait();
5074 // Feststellen, ob wir IME unterstuetzen
5075 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5077 if ( !pFrame )
5078 return;
5080 if ( pFrame->mbIME && pFrame->mhDefIMEContext )
5082 HKL hKL = (HKL)lParam;
5083 UINT nImeProps = ImmGetProperty( hKL, IGP_PROPERTY );
5085 pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
5086 pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
5087 pFrame->mbHandleIME = !pFrame->mbSpezIME;
5090 // trigger input language and codepage update
5091 UINT nLang = pFrame->mnInputLang;
5092 ImplUpdateInputLang( pFrame );
5094 // notify change
5095 if( nLang != pFrame->mnInputLang )
5096 pFrame->CallCallback( SALEVENT_INPUTLANGUAGECHANGE, 0 );
5098 ImplSalYieldMutexRelease();
5101 // -----------------------------------------------------------------------
5103 static void ImplUpdateIMECursorPos( WinSalFrame* pFrame, HIMC hIMC )
5105 COMPOSITIONFORM aForm;
5106 memset( &aForm, 0, sizeof( aForm ) );
5108 // Cursor-Position ermitteln und aus der die Default-Position fuer
5109 // das Composition-Fenster berechnen
5110 SalExtTextInputPosEvent aPosEvt;
5111 pFrame->CallCallback( SALEVENT_EXTTEXTINPUTPOS, (void*)&aPosEvt );
5112 if ( (aPosEvt.mnX == -1) && (aPosEvt.mnY == -1) )
5113 aForm.dwStyle |= CFS_DEFAULT;
5114 else
5116 aForm.dwStyle |= CFS_POINT;
5117 aForm.ptCurrentPos.x = aPosEvt.mnX;
5118 aForm.ptCurrentPos.y = aPosEvt.mnY;
5120 ImmSetCompositionWindow( hIMC, &aForm );
5122 // Because not all IME's use this values, we create
5123 // a Windows caret to force the Position from the IME
5124 if ( GetFocus() == pFrame->mhWnd )
5126 CreateCaret( pFrame->mhWnd, 0,
5127 aPosEvt.mnWidth, aPosEvt.mnHeight );
5128 SetCaretPos( aPosEvt.mnX, aPosEvt.mnY );
5132 // -----------------------------------------------------------------------
5134 static sal_Bool ImplHandleIMEStartComposition( HWND hWnd )
5136 sal_Bool bDef = TRUE;
5138 ImplSalYieldMutexAcquireWithWait();
5140 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5141 if ( pFrame )
5143 HIMC hIMC = ImmGetContext( hWnd );
5144 if ( hIMC )
5146 ImplUpdateIMECursorPos( pFrame, hIMC );
5147 ImmReleaseContext( hWnd, hIMC );
5150 if ( pFrame->mbHandleIME )
5152 if ( pFrame->mbAtCursorIME )
5153 bDef = FALSE;
5157 ImplSalYieldMutexRelease();
5159 return bDef;
5162 // -----------------------------------------------------------------------
5164 static sal_Bool ImplHandleIMECompositionInput( WinSalFrame* pFrame,
5165 HIMC hIMC, LPARAM lParam )
5167 sal_Bool bDef = TRUE;
5169 // Init Event
5170 SalExtTextInputEvent aEvt;
5171 aEvt.mnTime = GetMessageTime();
5172 aEvt.mpTextAttr = NULL;
5173 aEvt.mnCursorPos = 0;
5174 aEvt.mnDeltaStart = 0;
5175 aEvt.mbOnlyCursor = FALSE;
5176 aEvt.mnCursorFlags = 0;
5178 // If we get a result string, then we handle this input
5179 if ( lParam & GCS_RESULTSTR )
5181 bDef = FALSE;
5183 LONG nTextLen = ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, 0, 0 ) / sizeof( WCHAR );
5184 if ( nTextLen >= 0 )
5186 WCHAR* pTextBuf = new WCHAR[nTextLen];
5187 ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, pTextBuf, nTextLen*sizeof( WCHAR ) );
5188 aEvt.maText = rtl::OUString( reinterpret_cast<const sal_Unicode*>(pTextBuf), (sal_Int32)nTextLen );
5189 delete [] pTextBuf;
5192 aEvt.mnCursorPos = aEvt.maText.Len();
5193 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
5194 pFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, (void*)NULL );
5195 ImplUpdateIMECursorPos( pFrame, hIMC );
5198 // If the IME doesn't support OnSpot input, then there is nothing to do
5199 if ( !pFrame->mbAtCursorIME )
5200 return !bDef;
5202 // If we get new Composition data, then we handle this new input
5203 if ( (lParam & (GCS_COMPSTR | GCS_COMPATTR)) ||
5204 ((lParam & GCS_CURSORPOS) && !(lParam & GCS_RESULTSTR)) )
5206 bDef = FALSE;
5208 sal_uInt16* pSalAttrAry = NULL;
5209 LONG nTextLen = ImmGetCompositionStringW( hIMC, GCS_COMPSTR, 0, 0 ) / sizeof( WCHAR );
5210 if ( nTextLen > 0 )
5212 WCHAR* pTextBuf = new WCHAR[nTextLen];
5213 ImmGetCompositionStringW( hIMC, GCS_COMPSTR, pTextBuf, nTextLen*sizeof( WCHAR ) );
5214 aEvt.maText = rtl::OUString( reinterpret_cast<const sal_Unicode*>(pTextBuf), (sal_Int32)nTextLen );
5215 delete [] pTextBuf;
5217 BYTE* pAttrBuf = NULL;
5218 LONG nAttrLen = ImmGetCompositionStringW( hIMC, GCS_COMPATTR, 0, 0 );
5219 if ( nAttrLen > 0 )
5221 pAttrBuf = new BYTE[nAttrLen];
5222 ImmGetCompositionStringW( hIMC, GCS_COMPATTR, pAttrBuf, nAttrLen );
5225 if ( pAttrBuf )
5227 xub_StrLen nTextLen2 = aEvt.maText.Len();
5228 pSalAttrAry = new sal_uInt16[nTextLen2];
5229 memset( pSalAttrAry, 0, nTextLen2*sizeof( sal_uInt16 ) );
5230 for ( xub_StrLen i = 0; (i < nTextLen2) && (i < nAttrLen); i++ )
5232 BYTE nWinAttr = pAttrBuf[i];
5233 sal_uInt16 nSalAttr;
5234 if ( nWinAttr == ATTR_TARGET_CONVERTED )
5236 nSalAttr = SAL_EXTTEXTINPUT_ATTR_BOLDUNDERLINE;
5237 aEvt.mnCursorFlags |= SAL_EXTTEXTINPUT_CURSOR_INVISIBLE;
5239 else if ( nWinAttr == ATTR_CONVERTED )
5240 nSalAttr = SAL_EXTTEXTINPUT_ATTR_DASHDOTUNDERLINE;
5241 else if ( nWinAttr == ATTR_TARGET_NOTCONVERTED )
5242 nSalAttr = SAL_EXTTEXTINPUT_ATTR_HIGHLIGHT;
5243 else if ( nWinAttr == ATTR_INPUT_ERROR )
5244 nSalAttr = SAL_EXTTEXTINPUT_ATTR_REDTEXT | SAL_EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE;
5245 else /* ( nWinAttr == ATTR_INPUT ) */
5246 nSalAttr = SAL_EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE;
5247 pSalAttrAry[i] = nSalAttr;
5250 aEvt.mpTextAttr = pSalAttrAry;
5251 delete [] pAttrBuf;
5255 // Only when we get new composition data, we must send this event
5256 if ( (nTextLen > 0) || !(lParam & GCS_RESULTSTR) )
5258 // End the mode, if the last character is deleted
5259 if ( !nTextLen && !pFrame->mbCandidateMode )
5261 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
5262 pFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, (void*)NULL );
5264 else
5266 // Because Cursor-Position and DeltaStart never updated
5267 // from the korean input engine, we must handle this here
5268 if ( lParam & CS_INSERTCHAR )
5270 aEvt.mnCursorPos = nTextLen;
5271 if ( aEvt.mnCursorPos && (lParam & CS_NOMOVECARET) )
5272 aEvt.mnCursorPos--;
5274 else
5275 aEvt.mnCursorPos = LOWORD( ImmGetCompositionStringW( hIMC, GCS_CURSORPOS, 0, 0 ) );
5277 if ( pFrame->mbCandidateMode )
5278 aEvt.mnCursorFlags |= SAL_EXTTEXTINPUT_CURSOR_INVISIBLE;
5279 if ( lParam & CS_NOMOVECARET )
5280 aEvt.mnCursorFlags |= SAL_EXTTEXTINPUT_CURSOR_OVERWRITE;
5282 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
5284 ImplUpdateIMECursorPos( pFrame, hIMC );
5287 if ( pSalAttrAry )
5288 delete [] pSalAttrAry;
5291 return !bDef;
5294 // -----------------------------------------------------------------------
5296 static sal_Bool ImplHandleIMEComposition( HWND hWnd, LPARAM lParam )
5298 sal_Bool bDef = TRUE;
5299 ImplSalYieldMutexAcquireWithWait();
5301 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5302 if ( pFrame && (!lParam || (lParam & GCS_RESULTSTR)) )
5304 // Wir restaurieren den Background-Modus bei jeder Texteingabe,
5305 // da einige Tools wie RichWin uns diesen hin- und wieder umsetzen
5306 if ( pFrame->mpGraphics &&
5307 pFrame->mpGraphics->mhDC )
5308 SetBkMode( pFrame->mpGraphics->mhDC, TRANSPARENT );
5311 if ( pFrame && pFrame->mbHandleIME )
5313 if ( !lParam )
5315 SalExtTextInputEvent aEvt;
5316 aEvt.mnTime = GetMessageTime();
5317 aEvt.mpTextAttr = NULL;
5318 aEvt.mnCursorPos = 0;
5319 aEvt.mnDeltaStart = 0;
5320 aEvt.mbOnlyCursor = FALSE;
5321 aEvt.mnCursorFlags = 0;
5322 pFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void*)&aEvt );
5323 pFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, (void*)NULL );
5325 else if ( lParam & (GCS_RESULTSTR | GCS_COMPSTR | GCS_COMPATTR | GCS_CURSORPOS) )
5327 HIMC hIMC = ImmGetContext( hWnd );
5328 if ( hIMC )
5330 if ( ImplHandleIMECompositionInput( pFrame, hIMC, lParam ) )
5331 bDef = FALSE;
5333 ImmReleaseContext( hWnd, hIMC );
5338 ImplSalYieldMutexRelease();
5339 return bDef;
5342 // -----------------------------------------------------------------------
5344 static sal_Bool ImplHandleIMEEndComposition( HWND hWnd )
5346 sal_Bool bDef = TRUE;
5348 ImplSalYieldMutexAcquireWithWait();
5350 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5351 if ( pFrame && pFrame->mbHandleIME )
5353 if ( pFrame->mbAtCursorIME )
5354 bDef = FALSE;
5357 ImplSalYieldMutexRelease();
5359 return bDef;
5362 // -----------------------------------------------------------------------
5364 static boolean ImplHandleAppCommand( HWND hWnd, LPARAM lParam )
5366 sal_Int16 nCommand = 0;
5367 switch( GET_APPCOMMAND_LPARAM(lParam) )
5369 case APPCOMMAND_MEDIA_CHANNEL_DOWN: nCommand = MEDIA_COMMAND_CHANNEL_DOWN; break;
5370 case APPCOMMAND_MEDIA_CHANNEL_UP: nCommand = MEDIA_COMMAND_CHANNEL_UP; break;
5371 case APPCOMMAND_MEDIA_NEXTTRACK: nCommand = MEDIA_COMMAND_NEXTTRACK; break;
5372 case APPCOMMAND_MEDIA_PAUSE: nCommand = MEDIA_COMMAND_PAUSE; break;
5373 case APPCOMMAND_MEDIA_PLAY: nCommand = MEDIA_COMMAND_PLAY; break;
5374 case APPCOMMAND_MEDIA_PLAY_PAUSE: nCommand = MEDIA_COMMAND_PLAY_PAUSE; break;
5375 case APPCOMMAND_MEDIA_PREVIOUSTRACK: nCommand = MEDIA_COMMAND_PREVIOUSTRACK; break;
5376 case APPCOMMAND_MEDIA_RECORD: nCommand = MEDIA_COMMAND_RECORD; break;
5377 case APPCOMMAND_MEDIA_REWIND: nCommand = MEDIA_COMMAND_REWIND; break;
5378 case APPCOMMAND_MEDIA_STOP: nCommand = MEDIA_COMMAND_STOP; break;
5379 case APPCOMMAND_MIC_ON_OFF_TOGGLE: nCommand = MEDIA_COMMAND_MIC_ON_OFF_TOGGLE; break;
5380 case APPCOMMAND_MICROPHONE_VOLUME_DOWN: nCommand = MEDIA_COMMAND_MICROPHONE_VOLUME_DOWN; break;
5381 case APPCOMMAND_MICROPHONE_VOLUME_MUTE: nCommand = MEDIA_COMMAND_MICROPHONE_VOLUME_MUTE; break;
5382 case APPCOMMAND_MICROPHONE_VOLUME_UP: nCommand = MEDIA_COMMAND_MICROPHONE_VOLUME_UP; break;
5383 case APPCOMMAND_VOLUME_DOWN: nCommand = MEDIA_COMMAND_VOLUME_DOWN; break;
5384 case APPCOMMAND_VOLUME_MUTE: nCommand = MEDIA_COMMAND_VOLUME_MUTE; break;
5385 case APPCOMMAND_VOLUME_UP: nCommand = MEDIA_COMMAND_VOLUME_UP; break;
5386 default:
5387 return false;
5390 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5391 Window *pWindow = pFrame ? pFrame->GetWindow() : NULL;
5393 if( pWindow )
5395 const Point aPoint;
5396 CommandEvent aCEvt( aPoint, COMMAND_MEDIA, FALSE, &nCommand );
5397 NotifyEvent aNCmdEvt( EVENT_COMMAND, pWindow, &aCEvt );
5399 if ( !ImplCallPreNotify( aNCmdEvt ) )
5401 pWindow->Command( aCEvt );
5402 return true;
5406 return false;
5410 static void ImplHandleIMENotify( HWND hWnd, WPARAM wParam )
5412 if ( wParam == (WPARAM)IMN_OPENCANDIDATE )
5414 ImplSalYieldMutexAcquireWithWait();
5416 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5417 if ( pFrame && pFrame->mbHandleIME &&
5418 pFrame->mbAtCursorIME )
5420 // Wir wollen den Cursor hiden
5421 pFrame->mbCandidateMode = TRUE;
5422 ImplHandleIMEComposition( hWnd, GCS_CURSORPOS );
5424 HWND hWnd2 = pFrame->mhWnd;
5425 HIMC hIMC = ImmGetContext( hWnd2 );
5426 if ( hIMC )
5428 LONG nBufLen = ImmGetCompositionStringW( hIMC, GCS_COMPSTR, 0, 0 );
5429 if ( nBufLen >= 1 )
5431 SalExtTextInputPosEvent aPosEvt;
5432 pFrame->CallCallback( SALEVENT_EXTTEXTINPUTPOS, (void*)&aPosEvt );
5434 // Vertical !!!
5435 CANDIDATEFORM aForm;
5436 aForm.dwIndex = 0;
5437 aForm.dwStyle = CFS_EXCLUDE;
5438 aForm.ptCurrentPos.x = aPosEvt.mnX;
5439 aForm.ptCurrentPos.y = aPosEvt.mnY+1;
5440 aForm.rcArea.left = aPosEvt.mnX;
5441 aForm.rcArea.top = aPosEvt.mnY;
5442 aForm.rcArea.right = aForm.rcArea.left+aPosEvt.mnExtWidth+1;
5443 aForm.rcArea.bottom = aForm.rcArea.top+aPosEvt.mnHeight+1;
5444 ImmSetCandidateWindow( hIMC, &aForm );
5447 ImmReleaseContext( hWnd2, hIMC );
5451 ImplSalYieldMutexRelease();
5453 else if ( wParam == (WPARAM)IMN_CLOSECANDIDATE )
5455 ImplSalYieldMutexAcquireWithWait();
5456 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5457 if ( pFrame )
5458 pFrame->mbCandidateMode = FALSE;
5459 ImplSalYieldMutexRelease();
5463 // -----------------------------------------------------------------------
5464 #if WINVER >= 0x0500
5466 static LRESULT ImplHandleIMEReconvertString( HWND hWnd, LPARAM lParam )
5468 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5469 LPRECONVERTSTRING pReconvertString = (LPRECONVERTSTRING) lParam;
5470 LRESULT nRet = 0;
5471 SalSurroundingTextRequestEvent aEvt;
5472 aEvt.maText = rtl::OUString();
5473 aEvt.mnStart = aEvt.mnEnd = 0;
5475 UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_SETCOMPSTR );
5476 if( (nImeProps & SCS_CAP_SETRECONVERTSTRING) == 0 )
5478 // This IME does not support reconversion.
5479 return 0;
5482 if( !pReconvertString )
5484 // The first call for reconversion.
5485 pFrame->CallCallback( SALEVENT_STARTRECONVERSION, (void*)NULL );
5487 // Retrieve the surrounding text from the focused control.
5488 pFrame->CallCallback( SALEVENT_SURROUNDINGTEXTREQUEST, (void*)&aEvt );
5490 if( aEvt.maText.Len() == 0 )
5492 return 0;
5495 nRet = sizeof(RECONVERTSTRING) + (aEvt.maText.Len() + 1) * sizeof(WCHAR);
5497 else
5499 // The second call for reconversion.
5501 // Retrieve the surrounding text from the focused control.
5502 pFrame->CallCallback( SALEVENT_SURROUNDINGTEXTREQUEST, (void*)&aEvt );
5503 nRet = sizeof(RECONVERTSTRING) + (aEvt.maText.Len() + 1) * sizeof(WCHAR);
5505 pReconvertString->dwStrOffset = sizeof(RECONVERTSTRING);
5506 pReconvertString->dwStrLen = aEvt.maText.Len();
5507 pReconvertString->dwCompStrOffset = aEvt.mnStart * sizeof(WCHAR);
5508 pReconvertString->dwCompStrLen = aEvt.mnEnd - aEvt.mnStart;
5509 pReconvertString->dwTargetStrOffset = pReconvertString->dwCompStrOffset;
5510 pReconvertString->dwTargetStrLen = pReconvertString->dwCompStrLen;
5512 memcpy( (LPWSTR)(pReconvertString + 1), aEvt.maText.GetBuffer(), (aEvt.maText.Len() + 1) * sizeof(WCHAR) );
5515 // just return the required size of buffer to reconvert.
5516 return nRet;
5519 // -----------------------------------------------------------------------
5521 static LRESULT ImplHandleIMEConfirmReconvertString( HWND hWnd, LPARAM lParam )
5523 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5524 LPRECONVERTSTRING pReconvertString = (LPRECONVERTSTRING) lParam;
5525 SalSurroundingTextRequestEvent aEvt;
5526 aEvt.maText = rtl::OUString();
5527 aEvt.mnStart = aEvt.mnEnd = 0;
5529 pFrame->CallCallback( SALEVENT_SURROUNDINGTEXTREQUEST, (void*)&aEvt );
5531 sal_uLong nTmpStart = pReconvertString->dwCompStrOffset / sizeof(WCHAR);
5532 sal_uLong nTmpEnd = nTmpStart + pReconvertString->dwCompStrLen;
5534 if( nTmpStart != aEvt.mnStart || nTmpEnd != aEvt.mnEnd )
5536 SalSurroundingTextSelectionChangeEvent aSelEvt;
5537 aSelEvt.mnStart = nTmpStart;
5538 aSelEvt.mnEnd = nTmpEnd;
5540 pFrame->CallCallback( SALEVENT_SURROUNDINGTEXTSELECTIONCHANGE, (void*)&aSelEvt );
5543 return TRUE;
5546 #endif // WINVER >= 0x0500
5548 // -----------------------------------------------------------------------
5550 void SalTestMouseLeave()
5552 SalData* pSalData = GetSalData();
5554 if ( pSalData->mhWantLeaveMsg && !::GetCapture() )
5556 POINT aPt;
5557 GetCursorPos( &aPt );
5558 if ( pSalData->mhWantLeaveMsg != WindowFromPoint( aPt ) )
5559 ImplSendMessage( pSalData->mhWantLeaveMsg, SAL_MSG_MOUSELEAVE, 0, MAKELPARAM( aPt.x, aPt.y ) );
5563 // -----------------------------------------------------------------------
5565 static int ImplSalWheelMousePos( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam ,
5566 LRESULT& rResult )
5568 POINT aPt;
5569 POINT aScreenPt;
5570 aScreenPt.x = (short)LOWORD( lParam );
5571 aScreenPt.y = (short)HIWORD( lParam );
5572 // Child-Fenster suchen, welches an der entsprechenden
5573 // Position liegt
5574 HWND hChildWnd;
5575 HWND hWheelWnd = hWnd;
5578 hChildWnd = hWheelWnd;
5579 aPt = aScreenPt;
5580 ScreenToClient( hChildWnd, &aPt );
5581 hWheelWnd = ChildWindowFromPointEx( hChildWnd, aPt, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT );
5583 while ( hWheelWnd && (hWheelWnd != hChildWnd) );
5584 if ( hWheelWnd && (hWheelWnd != hWnd) &&
5585 (hWheelWnd != ::GetFocus()) && IsWindowEnabled( hWheelWnd ) )
5587 rResult = ImplSendMessage( hWheelWnd, nMsg, wParam, lParam );
5588 return FALSE;
5591 return TRUE;
5594 // -----------------------------------------------------------------------
5596 LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef )
5598 LRESULT nRet = 0;
5599 static int bInWheelMsg = FALSE;
5600 static int bInQueryEnd = FALSE;
5602 // By WM_CRETAE we connect the frame with the window handle
5603 if ( nMsg == WM_CREATE )
5605 // Window-Instanz am Windowhandle speichern
5606 // Can also be used for the W-Version, because the struct
5607 // to access lpCreateParams is the same structure
5608 CREATESTRUCTA* pStruct = (CREATESTRUCTA*)lParam;
5609 WinSalFrame* pFrame = (WinSalFrame*)pStruct->lpCreateParams;
5610 if ( pFrame != 0 )
5612 SetWindowPtr( hWnd, pFrame );
5613 // HWND schon hier setzen, da schon auf den Instanzdaten
5614 // gearbeitet werden kann, wenn Messages waehrend
5615 // CreateWindow() gesendet werden
5616 pFrame->mhWnd = hWnd;
5617 pFrame->maSysData.hWnd = hWnd;
5619 return 0;
5622 ImplSVData* pSVData = ImplGetSVData();
5623 // #i72707# TODO: the mbDeInit check will not be needed
5624 // once all windows that are not properly closed on exit got fixed
5625 if( pSVData->mbDeInit )
5626 return 0;
5628 if ( WM_USER_SYSTEM_WINDOW_ACTIVATED == nMsg )
5630 ImplHideSplash();
5631 return 0;
5634 bool bCheckTimers = false;
5636 switch( nMsg )
5638 case WM_MOUSEMOVE:
5639 case WM_LBUTTONDOWN:
5640 case WM_MBUTTONDOWN:
5641 case WM_RBUTTONDOWN:
5642 case WM_LBUTTONUP:
5643 case WM_MBUTTONUP:
5644 case WM_RBUTTONUP:
5645 case WM_NCMOUSEMOVE:
5646 case SAL_MSG_MOUSELEAVE:
5647 ImplSalYieldMutexAcquireWithWait();
5648 rDef = !ImplHandleMouseMsg( hWnd, nMsg, wParam, lParam );
5649 ImplSalYieldMutexRelease();
5650 break;
5652 case WM_NCLBUTTONDOWN:
5653 case WM_NCMBUTTONDOWN:
5654 case WM_NCRBUTTONDOWN:
5655 ImplSalYieldMutexAcquireWithWait();
5656 ImplCallClosePopupsHdl( hWnd ); // close popups...
5657 ImplSalYieldMutexRelease();
5658 break;
5660 case WM_MOUSEACTIVATE:
5661 if ( LOWORD( lParam ) == HTCLIENT )
5663 ImplSalYieldMutexAcquireWithWait();
5664 nRet = ImplHandleMouseActivateMsg( hWnd );
5665 ImplSalYieldMutexRelease();
5666 if ( nRet )
5668 nRet = MA_NOACTIVATE;
5669 rDef = FALSE;
5672 break;
5674 case WM_KEYDOWN:
5675 case WM_KEYUP:
5676 case WM_DEADCHAR:
5677 case WM_CHAR:
5678 case WM_UNICHAR: // MCD, 2003-01-13, Support for WM_UNICHAR & Keyman 6.0
5679 case WM_SYSKEYDOWN:
5680 case WM_SYSKEYUP:
5681 case WM_SYSCHAR:
5682 ImplSalYieldMutexAcquireWithWait();
5683 rDef = !ImplHandleKeyMsg( hWnd, nMsg, wParam, lParam, nRet );
5684 ImplSalYieldMutexRelease();
5685 break;
5687 case WM_MOUSEWHEEL:
5688 // FALLTHROUGH intended
5689 case WM_MOUSEHWHEEL:
5690 // Gegen Rekursion absichern, falls wir vom IE oder dem externen
5691 // Fenster die Message wieder zurueckbekommen
5692 if ( !bInWheelMsg )
5694 bInWheelMsg++;
5695 rDef = !ImplHandleWheelMsg( hWnd, nMsg, wParam, lParam );
5696 // Wenn wir die Message nicht ausgewertet haben, schauen wir
5697 // noch einmal nach, ob dort ein geplugtes Fenster steht,
5698 // welches wir dann benachrichtigen
5699 if ( rDef )
5700 rDef = ImplSalWheelMousePos( hWnd, nMsg, wParam, lParam, nRet );
5701 bInWheelMsg--;
5703 break;
5705 case WM_COMMAND:
5706 ImplSalYieldMutexAcquireWithWait();
5707 rDef = !ImplHandleCommand( hWnd, wParam, lParam );
5708 ImplSalYieldMutexRelease();
5709 break;
5711 case WM_INITMENUPOPUP:
5712 ImplSalYieldMutexAcquireWithWait();
5713 rDef = !ImplHandleMenuActivate( hWnd, wParam, lParam );
5714 ImplSalYieldMutexRelease();
5715 break;
5717 case WM_MENUSELECT:
5718 ImplSalYieldMutexAcquireWithWait();
5719 rDef = !ImplHandleMenuSelect( hWnd, wParam, lParam );
5720 ImplSalYieldMutexRelease();
5721 break;
5723 case WM_SYSCOMMAND:
5724 ImplSalYieldMutexAcquireWithWait();
5725 nRet = ImplHandleSysCommand( hWnd, wParam, lParam );
5726 ImplSalYieldMutexRelease();
5727 if ( nRet )
5728 rDef = FALSE;
5729 break;
5731 case WM_MENUCHAR:
5732 nRet = ImplMenuChar( hWnd, wParam, lParam );
5733 if( nRet )
5734 rDef = FALSE;
5735 break;
5737 case WM_MEASUREITEM:
5738 nRet = ImplMeasureItem(hWnd, wParam, lParam);
5739 if( nRet )
5740 rDef = FALSE;
5741 break;
5743 case WM_DRAWITEM:
5744 nRet = ImplDrawItem(hWnd, wParam, lParam);
5745 if( nRet )
5746 rDef = FALSE;
5747 break;
5749 case WM_MOVE:
5750 case SAL_MSG_POSTMOVE:
5751 ImplHandleMoveMsg( hWnd );
5752 rDef = FALSE;
5753 break;
5754 case WM_SIZE:
5755 ImplHandleSizeMsg( hWnd, wParam, lParam );
5756 rDef = FALSE;
5757 break;
5758 case SAL_MSG_POSTCALLSIZE:
5759 ImplCallSizeHdl( hWnd );
5760 rDef = FALSE;
5761 break;
5763 case WM_GETMINMAXINFO:
5764 if ( ImplHandleMinMax( hWnd, lParam ) )
5765 rDef = FALSE;
5766 break;
5768 case WM_ERASEBKGND:
5769 nRet = 1;
5770 rDef = FALSE;
5771 break;
5772 case WM_PAINT:
5773 bCheckTimers = ImplHandlePaintMsg( hWnd );
5774 rDef = FALSE;
5775 break;
5776 case SAL_MSG_POSTPAINT:
5777 ImplHandlePaintMsg2( hWnd, (RECT*)wParam );
5778 bCheckTimers = true;
5779 rDef = FALSE;
5780 break;
5782 case SAL_MSG_FORCEPALETTE:
5783 ImplHandleForcePalette( hWnd );
5784 rDef = FALSE;
5785 break;
5787 case WM_QUERYNEWPALETTE:
5788 case SAL_MSG_POSTQUERYNEWPAL:
5789 nRet = ImplHandlePalette( TRUE, hWnd, nMsg, wParam, lParam, rDef );
5790 break;
5792 case WM_ACTIVATE:
5793 // Wenn wir aktiviert werden, dann wollen wir auch unsere
5794 // Palette setzen. Wir machen dieses in Activate,
5795 // damit andere externe Child-Fenster auch unsere Palette
5796 // ueberschreiben koennen. So wird unsere jedenfalls nur einmal
5797 // gesetzt und nicht immer rekursiv, da an allen anderen Stellen
5798 // diese nur als Background-Palette gesetzt wird
5799 if ( LOWORD( wParam ) != WA_INACTIVE )
5800 ImplSendMessage( hWnd, SAL_MSG_FORCEPALETTE, 0, 0 );
5801 break;
5803 case WM_ENABLE:
5804 // #95133# a system dialog is opened/closed, using our app window as parent
5806 WinSalFrame* pFrame = GetWindowPtr( hWnd );
5807 Window *pWin = NULL;
5808 if( pFrame )
5809 pWin = pFrame->GetWindow();
5811 if( !wParam )
5813 pSVData->maAppData.mnModalMode++;
5815 ImplHideSplash();
5816 if( pWin )
5818 pWin->EnableInput( FALSE, TRUE, TRUE, NULL );
5819 pWin->ImplIncModalCount(); // #106303# support frame based modal count
5822 else
5824 ImplGetSVData()->maAppData.mnModalMode--;
5825 if( pWin )
5827 pWin->EnableInput( TRUE, TRUE, TRUE, NULL );
5828 pWin->ImplDecModalCount(); // #106303# support frame based modal count
5832 break;
5834 case WM_KILLFOCUS:
5835 DestroyCaret();
5836 case WM_SETFOCUS:
5837 case SAL_MSG_POSTFOCUS:
5838 ImplHandleFocusMsg( hWnd );
5839 rDef = FALSE;
5840 break;
5842 case WM_CLOSE:
5843 ImplHandleCloseMsg( hWnd );
5844 rDef = FALSE;
5845 break;
5847 case WM_QUERYENDSESSION:
5848 if( !bInQueryEnd )
5850 // handle queryendsession only once
5851 bInQueryEnd = TRUE;
5852 nRet = !ImplHandleShutDownMsg( hWnd );
5853 rDef = FALSE;
5855 // Issue #16314#: ImplHandleShutDownMsg causes a PostMessage in case of allowing shutdown.
5856 // This posted message was never processed and cause Windows XP to hang after log off
5857 // if there are multiple sessions and the current session wasn't the first one started.
5858 // So if shutdown is allowed we assume that a post message was done and retrieve all
5859 // messages in the message queue and dispatch them before we return control to the system.
5861 if ( nRet )
5863 MSG msg;
5865 while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
5867 DispatchMessage( &msg );
5871 else
5873 ImplSalYieldMutexAcquireWithWait();
5874 ImplSalYieldMutexRelease();
5875 rDef = TRUE;
5877 break;
5879 case WM_ENDSESSION:
5880 if( !wParam )
5881 bInQueryEnd = FALSE; // no shutdown: allow query again
5882 nRet = FALSE;
5883 rDef = FALSE;
5884 break;
5886 case WM_DISPLAYCHANGE:
5887 case WM_SETTINGCHANGE:
5888 case WM_DEVMODECHANGE:
5889 case WM_FONTCHANGE:
5890 case WM_SYSCOLORCHANGE:
5891 case WM_TIMECHANGE:
5892 ImplHandleSettingsChangeMsg( hWnd, nMsg, wParam, lParam );
5893 break;
5895 case WM_THEMECHANGED:
5896 GetSalData()->mbThemeChanged = TRUE;
5897 break;
5899 case SAL_MSG_USEREVENT:
5900 ImplHandleUserEvent( hWnd, lParam );
5901 rDef = FALSE;
5902 break;
5904 case SAL_MSG_CAPTUREMOUSE:
5905 SetCapture( hWnd );
5906 rDef = FALSE;
5907 break;
5908 case SAL_MSG_RELEASEMOUSE:
5909 if ( ::GetCapture() == hWnd )
5910 ReleaseCapture();
5911 rDef = FALSE;
5912 break;
5913 case SAL_MSG_TOTOP:
5914 ImplSalToTop( hWnd, (sal_uInt16)wParam );
5915 rDef = FALSE;
5916 break;
5917 case SAL_MSG_SHOW:
5918 ImplSalShow( hWnd, (sal_Bool)wParam, (sal_Bool)lParam );
5919 rDef = FALSE;
5920 break;
5921 case SAL_MSG_SETINPUTCONTEXT:
5922 ImplSalFrameSetInputContext( hWnd, (const SalInputContext*)(void*)lParam );
5923 rDef = FALSE;
5924 break;
5925 case SAL_MSG_ENDEXTTEXTINPUT:
5926 ImplSalFrameEndExtTextInput( hWnd, (sal_uInt16)(sal_uLong)(void*)wParam );
5927 rDef = FALSE;
5928 break;
5930 case WM_INPUTLANGCHANGE:
5931 ImplHandleInputLangChange( hWnd, wParam, lParam );
5932 break;
5934 case WM_IME_CHAR:
5935 // #103487#, some IMEs (eg, those that do not work onspot)
5936 // may send WM_IME_CHAR instead of WM_IME_COMPOSITION
5937 // we just handle it like a WM_CHAR message - seems to work fine
5938 ImplSalYieldMutexAcquireWithWait();
5939 rDef = !ImplHandleKeyMsg( hWnd, WM_CHAR, wParam, lParam, nRet );
5940 ImplSalYieldMutexRelease();
5941 break;
5943 case WM_IME_STARTCOMPOSITION:
5944 rDef = ImplHandleIMEStartComposition( hWnd );
5945 break;
5947 case WM_IME_COMPOSITION:
5948 rDef = ImplHandleIMEComposition( hWnd, lParam );
5949 break;
5951 case WM_IME_ENDCOMPOSITION:
5952 rDef = ImplHandleIMEEndComposition( hWnd );
5953 break;
5955 case WM_IME_NOTIFY:
5956 ImplHandleIMENotify( hWnd, wParam );
5957 break;
5958 case WM_APPCOMMAND:
5959 if( ImplHandleAppCommand( hWnd, lParam ) )
5961 rDef = false;
5962 nRet = 1;
5964 break;
5965 #if WINVER >= 0x0500
5966 case WM_IME_REQUEST:
5967 if ( (sal_uIntPtr)( wParam ) == IMR_RECONVERTSTRING )
5969 nRet = ImplHandleIMEReconvertString( hWnd, lParam );
5970 rDef = FALSE;
5972 else if( (sal_uIntPtr)( wParam ) == IMR_CONFIRMRECONVERTSTRING )
5974 nRet = ImplHandleIMEConfirmReconvertString( hWnd, lParam );
5975 rDef = FALSE;
5977 break;
5978 #endif // WINVER >= 0x0500
5981 // WheelMouse-Message abfangen
5982 if ( rDef && (nMsg == aSalShlData.mnWheelMsgId) && aSalShlData.mnWheelMsgId )
5984 // Gegen Rekursion absichern, falls wir vom IE oder dem externen
5985 // Fenster die Message wieder zurueckbekommen
5986 if ( !bInWheelMsg )
5988 bInWheelMsg++;
5989 // Zuerst wollen wir die Message dispatchen und dann darf auch
5990 // das SystemWindow drankommen
5991 WORD nKeyState = 0;
5992 if ( GetKeyState( VK_SHIFT ) & 0x8000 )
5993 nKeyState |= MK_SHIFT;
5994 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
5995 nKeyState |= MK_CONTROL;
5996 // Mutex handling is inside from this call
5997 rDef = !ImplHandleWheelMsg( hWnd,
5998 WM_MOUSEWHEEL,
5999 MAKEWPARAM( nKeyState, (WORD)wParam ),
6000 lParam );
6001 if ( rDef )
6003 HWND hWheelWnd = ::GetFocus();
6004 if ( hWheelWnd && (hWheelWnd != hWnd) )
6006 nRet = ImplSendMessage( hWheelWnd, nMsg, wParam, lParam );
6007 rDef = FALSE;
6009 else
6010 rDef = ImplSalWheelMousePos( hWnd, nMsg, wParam, lParam, nRet );
6012 bInWheelMsg--;
6016 if( bCheckTimers )
6018 SalData* pSalData = GetSalData();
6019 if( pSalData->mnNextTimerTime )
6021 DWORD nCurTime = GetTickCount();
6022 if( pSalData->mnNextTimerTime < nCurTime )
6024 MSG aMsg;
6025 if( ! ImplPeekMessage( &aMsg, 0, WM_PAINT, WM_PAINT, PM_NOREMOVE | PM_NOYIELD ) )
6026 ImplPostMessage( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_POSTTIMER, 0, nCurTime );
6031 return nRet;
6034 LRESULT CALLBACK SalFrameWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
6036 int bDef = TRUE;
6037 LRESULT nRet = 0;
6038 #ifdef __MINGW32__
6039 jmp_buf jmpbuf;
6040 __SEHandler han;
6041 if (__builtin_setjmp(jmpbuf) == 0)
6043 han.Set(jmpbuf, NULL, (__SEHandler::PF)EXCEPTION_EXECUTE_HANDLER);
6044 #else
6045 __try
6047 #endif
6048 nRet = SalFrameWndProc( hWnd, nMsg, wParam, lParam, bDef );
6050 #ifdef __MINGW32__
6051 han.Reset();
6052 #else
6053 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
6056 #endif
6058 if ( bDef )
6059 nRet = DefWindowProcW( hWnd, nMsg, wParam, lParam );
6060 return nRet;
6063 // -----------------------------------------------------------------------
6065 sal_Bool ImplHandleGlobalMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT& rlResult )
6067 // handle all messages concerning all frames so they get processed only once
6068 // Must work for Unicode and none Unicode
6069 sal_Bool bResult = FALSE;
6070 if ( (nMsg == WM_PALETTECHANGED) || (nMsg == SAL_MSG_POSTPALCHANGED) )
6072 int bDef = TRUE;
6073 rlResult = ImplHandlePalette( FALSE, hWnd, nMsg, wParam, lParam, bDef );
6074 bResult = (bDef != 0);
6076 else if( nMsg == WM_DISPLAYCHANGE )
6078 WinSalSystem* pSys = static_cast<WinSalSystem*>(ImplGetSalSystem());
6079 if( pSys )
6080 pSys->clearMonitors();
6081 bResult = (pSys != NULL);
6083 return bResult;
6086 // -----------------------------------------------------------------------
6088 sal_Bool ImplWriteLastError( DWORD lastError, const char *szApiCall )
6090 static int first=1;
6091 // if VCL_LOGFILE_ENABLED is set, Win32 API error messages can be written
6092 // to %TMP%/vcl.log or %TEMP%/vcl.log
6093 static char *logEnabled = getenv("VCL_LOGFILE_ENABLED");
6094 if( logEnabled )
6096 sal_Bool bSuccess = FALSE;
6097 static char *szTmp = getenv("TMP");
6098 if( !szTmp || !*szTmp )
6099 szTmp = getenv("TEMP");
6100 if( szTmp && *szTmp )
6102 char fname[5000];
6103 strcpy( fname, szTmp );
6104 if( fname[strlen(fname) - 1] != '\\' )
6105 strcat( fname, "\\");
6106 strcat( fname, "vcl.log" );
6107 FILE *fp = fopen( fname, "a" ); // always append
6108 if( fp )
6110 if( first )
6112 first = 0;
6113 fprintf( fp, "Process ID: %ld (0x%lx)\n", GetCurrentProcessId(), GetCurrentProcessId() );
6115 time_t aclock;
6116 time( &aclock ); // Get time in seconds
6117 struct tm *newtime = localtime( &aclock ); // Convert time to struct tm form
6118 fprintf( fp, asctime( newtime ) ); // print time stamp
6120 fprintf( fp, "%s returned %lu (0x%lx)\n", szApiCall, lastError, lastError );
6121 bSuccess = TRUE; // may be FormatMessage fails but we wrote at least the error code
6123 LPVOID lpMsgBuf;
6124 if (FormatMessageA(
6125 FORMAT_MESSAGE_ALLOCATE_BUFFER |
6126 FORMAT_MESSAGE_FROM_SYSTEM |
6127 FORMAT_MESSAGE_IGNORE_INSERTS,
6128 NULL,
6129 lastError,
6130 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
6131 (LPSTR) &lpMsgBuf,
6133 NULL ))
6135 fprintf( fp, " %s\n", (LPSTR)lpMsgBuf );
6136 LocalFree( lpMsgBuf );
6139 fclose( fp );
6142 return bSuccess;
6144 else
6145 return TRUE;
6148 // -----------------------------------------------------------------------
6150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */