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