Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / vcl / win / source / window / salobj.cxx
blob0324a350078577f914808954e0edf329e5949fa2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <string.h>
23 #include <svsys.h>
24 #include <tools/debug.hxx>
26 #include <vcl/svapp.hxx>
28 #include <win/wincomp.hxx>
29 #include <win/saldata.hxx>
30 #include <win/salinst.h>
31 #include <win/salframe.h>
32 #include <win/salobj.h>
34 // =======================================================================
36 static sal_Bool ImplIsSysWindowOrChild( HWND hWndParent, HWND hWndChild )
38 if ( hWndParent == hWndChild )
39 return TRUE;
41 HWND hTempWnd = ::GetParent( hWndChild );
42 while ( hTempWnd )
44 // Ab nicht Child-Fenstern hoeren wir auf zu suchen
45 if ( !(GetWindowStyle( hTempWnd ) & WS_CHILD) )
46 return FALSE;
47 if ( hTempWnd == hWndParent )
48 return TRUE;
49 hTempWnd = ::GetParent( hTempWnd );
52 return FALSE;
55 // -----------------------------------------------------------------------
57 WinSalObject* ImplFindSalObject( HWND hWndChild )
59 SalData* pSalData = GetSalData();
60 WinSalObject* pObject = pSalData->mpFirstObject;
61 while ( pObject )
63 if ( ImplIsSysWindowOrChild( pObject->mhWndChild, hWndChild ) )
64 return pObject;
66 pObject = pObject->mpNextObject;
69 return NULL;
72 // -----------------------------------------------------------------------
74 WinSalFrame* ImplFindSalObjectFrame( HWND hWnd )
76 WinSalFrame* pFrame = NULL;
77 WinSalObject* pObject = ImplFindSalObject( hWnd );
78 if ( pObject )
80 // Dazugehoerenden Frame suchen
81 HWND hWnd2 = ::GetParent( pObject->mhWnd );
82 pFrame = GetSalData()->mpFirstFrame;
83 while ( pFrame )
85 if ( pFrame->mhWnd == hWnd2 )
86 break;
88 pFrame = pFrame->mpNextFrame;
92 return pFrame;
95 // -----------------------------------------------------------------------
97 LRESULT CALLBACK SalSysMsgProc( int nCode, WPARAM wParam, LPARAM lParam )
99 // Used for Unicode and none Unicode
100 SalData* pSalData = GetSalData();
102 if ( (nCode >= 0) && lParam )
104 CWPSTRUCT* pData = (CWPSTRUCT*)lParam;
105 if ( (pData->message != WM_KEYDOWN) &&
106 (pData->message != WM_KEYUP) )
107 pSalData->mnSalObjWantKeyEvt = 0;
109 // Testen, ob wir Daten fuer ein SalObject-Fenster behandeln
110 // muessen
111 WinSalObject* pObject;
112 if ( pData->message == WM_SETFOCUS )
114 pObject = ImplFindSalObject( pData->hwnd );
115 if ( pObject )
117 pObject->mhLastFocusWnd = pData->hwnd;
118 if ( ImplSalYieldMutexTryToAcquire() )
120 pObject->CallCallback( SALOBJ_EVENT_GETFOCUS, 0 );
121 ImplSalYieldMutexRelease();
123 else
124 ImplPostMessage( pObject->mhWnd, SALOBJ_MSG_POSTFOCUS, 0, 0 );
127 else if ( pData->message == WM_KILLFOCUS )
129 pObject = ImplFindSalObject( pData->hwnd );
130 if ( pObject && !ImplFindSalObject( (HWND)pData->wParam ) )
132 // LoseFocus nur rufen, wenn wirklich kein ChildFenster
133 // den Focus bekommt
134 if ( !pData->wParam || !ImplFindSalObject( (HWND)pData->wParam ) )
136 if ( ImplSalYieldMutexTryToAcquire() )
138 pObject->CallCallback( SALOBJ_EVENT_LOSEFOCUS, 0 );
139 ImplSalYieldMutexRelease();
141 else
142 ImplPostMessage( pObject->mhWnd, SALOBJ_MSG_POSTFOCUS, 0, 0 );
144 else
145 pObject->mhLastFocusWnd = (HWND)pData->wParam;
150 return CallNextHookEx( pSalData->mhSalObjMsgHook, nCode, wParam, lParam );
153 // -----------------------------------------------------------------------
155 sal_Bool ImplSalPreDispatchMsg( MSG* pMsg )
157 // Used for Unicode and none Unicode
158 SalData* pSalData = GetSalData();
159 WinSalObject* pObject;
161 if ( (pMsg->message == WM_LBUTTONDOWN) ||
162 (pMsg->message == WM_RBUTTONDOWN) ||
163 (pMsg->message == WM_MBUTTONDOWN) )
165 ImplSalYieldMutexAcquireWithWait();
166 pObject = ImplFindSalObject( pMsg->hwnd );
167 if ( pObject && !pObject->IsMouseTransparent() )
168 ImplPostMessage( pObject->mhWnd, SALOBJ_MSG_TOTOP, 0, 0 );
169 ImplSalYieldMutexRelease();
172 if ( (pMsg->message == WM_KEYDOWN) ||
173 (pMsg->message == WM_KEYUP) )
175 // KeyEvents wollen wir nach Moeglichkeit auch abarbeiten,
176 // wenn das Control diese nicht selber auswertet
177 // SysKeys werden als WM_SYSCOMMAND verarbeitet
178 // Char-Events verarbeiten wir nicht, da wir nur
179 // Accelerator relevante Keys verarbeiten wollen
180 sal_Bool bWantedKeyCode = FALSE;
181 // A-Z, 0-9 nur in Verbindung mit Control-Taste
182 if ( ((pMsg->wParam >= 65) && (pMsg->wParam <= 90)) ||
183 ((pMsg->wParam >= 48) && (pMsg->wParam <= 57)) )
185 if ( GetKeyState( VK_CONTROL ) & 0x8000 )
186 bWantedKeyCode = TRUE;
188 else if ( ((pMsg->wParam >= VK_F1) && (pMsg->wParam <= VK_F24)) ||
189 ((pMsg->wParam >= VK_SPACE) && (pMsg->wParam <= VK_HELP)) ||
190 (pMsg->wParam == VK_BACK) || (pMsg->wParam == VK_TAB) ||
191 (pMsg->wParam == VK_CLEAR) || (pMsg->wParam == VK_RETURN) ||
192 (pMsg->wParam == VK_ESCAPE) )
193 bWantedKeyCode = TRUE;
194 if ( bWantedKeyCode )
196 ImplSalYieldMutexAcquireWithWait();
197 pObject = ImplFindSalObject( pMsg->hwnd );
198 if ( pObject )
199 pSalData->mnSalObjWantKeyEvt = pMsg->wParam;
200 ImplSalYieldMutexRelease();
203 // Hier WM_SYSCHAR abfangen, um mit Alt+Taste evtl. Menu zu aktivieren
204 else if ( pMsg->message == WM_SYSCHAR )
206 pSalData->mnSalObjWantKeyEvt = 0;
208 sal_uInt16 nKeyCode = LOWORD( pMsg->wParam );
209 // Nur 0-9 und A-Z
210 if ( ((nKeyCode >= 48) && (nKeyCode <= 57)) ||
211 ((nKeyCode >= 65) && (nKeyCode <= 90)) ||
212 ((nKeyCode >= 97) && (nKeyCode <= 122)) )
214 sal_Bool bRet = FALSE;
215 ImplSalYieldMutexAcquireWithWait();
216 pObject = ImplFindSalObject( pMsg->hwnd );
217 if ( pObject )
219 if ( pMsg->hwnd == ::GetFocus() )
221 WinSalFrame* pFrame = ImplFindSalObjectFrame( pMsg->hwnd );
222 if ( pFrame )
224 if ( ImplHandleSalObjSysCharMsg( pFrame->mhWnd, pMsg->wParam, pMsg->lParam ) )
225 bRet = TRUE;
229 ImplSalYieldMutexRelease();
230 if ( bRet )
231 return TRUE;
234 else
235 pSalData->mnSalObjWantKeyEvt = 0;
237 return FALSE;
240 // -----------------------------------------------------------------------
242 void ImplSalPostDispatchMsg( MSG* pMsg, LRESULT /* nDispatchResult */ )
244 // Used for Unicode and none Unicode
245 SalData* pSalData = GetSalData();
246 WinSalFrame* pFrame;
248 if ( (pMsg->message == WM_KEYDOWN) || (pMsg->message == WM_KEYUP) )
250 if ( pSalData->mnSalObjWantKeyEvt == pMsg->wParam )
252 pSalData->mnSalObjWantKeyEvt = 0;
253 if ( pMsg->hwnd == ::GetFocus() )
255 ImplSalYieldMutexAcquireWithWait();
256 pFrame = ImplFindSalObjectFrame( pMsg->hwnd );
257 if ( pFrame )
258 ImplHandleSalObjKeyMsg( pFrame->mhWnd, pMsg->message, pMsg->wParam, pMsg->lParam );
259 ImplSalYieldMutexRelease();
264 pSalData->mnSalObjWantKeyEvt = 0;
267 // =======================================================================
269 LRESULT CALLBACK SalSysObjWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef )
271 WinSalObject* pSysObj;
272 LRESULT nRet = 0;
274 switch( nMsg )
276 case WM_ERASEBKGND:
277 nRet = 1;
278 rDef = FALSE;
279 break;
280 case WM_PAINT:
282 PAINTSTRUCT aPs;
283 BeginPaint( hWnd, &aPs );
284 EndPaint( hWnd, &aPs );
285 rDef = FALSE;
287 break;
289 case WM_PARENTNOTIFY:
291 UINT nNotifyMsg = LOWORD( wParam );
292 if ( (nNotifyMsg == WM_LBUTTONDOWN) ||
293 (nNotifyMsg == WM_RBUTTONDOWN) ||
294 (nNotifyMsg == WM_MBUTTONDOWN) )
296 ImplSalYieldMutexAcquireWithWait();
297 pSysObj = GetSalObjWindowPtr( hWnd );
298 if ( pSysObj && !pSysObj->IsMouseTransparent() )
299 pSysObj->CallCallback( SALOBJ_EVENT_TOTOP, 0 );
300 ImplSalYieldMutexRelease();
303 break;
305 case WM_MOUSEACTIVATE:
307 ImplSalYieldMutexAcquireWithWait();
308 pSysObj = GetSalObjWindowPtr( hWnd );
309 if ( pSysObj && !pSysObj->IsMouseTransparent() )
310 ImplPostMessage( hWnd, SALOBJ_MSG_TOTOP, 0, 0 );
311 ImplSalYieldMutexRelease();
313 break;
315 case SALOBJ_MSG_TOTOP:
316 if ( ImplSalYieldMutexTryToAcquire() )
318 pSysObj = GetSalObjWindowPtr( hWnd );
319 pSysObj->CallCallback( SALOBJ_EVENT_TOTOP, 0 );
320 ImplSalYieldMutexRelease();
321 rDef = FALSE;
323 else
324 ImplPostMessage( hWnd, SALOBJ_MSG_TOTOP, 0, 0 );
325 break;
327 case SALOBJ_MSG_POSTFOCUS:
328 if ( ImplSalYieldMutexTryToAcquire() )
330 pSysObj = GetSalObjWindowPtr( hWnd );
331 HWND hFocusWnd = ::GetFocus();
332 sal_uInt16 nEvent;
333 if ( hFocusWnd && ImplIsSysWindowOrChild( hWnd, hFocusWnd ) )
334 nEvent = SALOBJ_EVENT_GETFOCUS;
335 else
336 nEvent = SALOBJ_EVENT_LOSEFOCUS;
337 pSysObj->CallCallback( nEvent, 0 );
338 ImplSalYieldMutexRelease();
340 else
341 ImplPostMessage( hWnd, SALOBJ_MSG_POSTFOCUS, 0, 0 );
342 rDef = FALSE;
343 break;
345 case WM_SIZE:
347 HWND hWndChild = GetWindow( hWnd, GW_CHILD );
348 if ( hWndChild )
350 SetWindowPos( hWndChild,
351 0, 0, 0, (int)LOWORD( lParam ), (int)HIWORD( lParam ),
352 SWP_NOZORDER | SWP_NOACTIVATE );
355 rDef = FALSE;
356 break;
358 case WM_CREATE:
360 // Window-Instanz am Windowhandle speichern
361 // Can also be used for the W-Version, because the struct
362 // to access lpCreateParams is the same structure
363 CREATESTRUCTA* pStruct = (CREATESTRUCTA*)lParam;
364 pSysObj = (WinSalObject*)pStruct->lpCreateParams;
365 SetSalObjWindowPtr( hWnd, pSysObj );
366 // HWND schon hier setzen, da schon auf den Instanzdaten
367 // gearbeitet werden kann, wenn Messages waehrend
368 // CreateWindow() gesendet werden
369 pSysObj->mhWnd = hWnd;
370 rDef = FALSE;
372 break;
375 return nRet;
378 LRESULT CALLBACK SalSysObjWndProcA( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
380 int bDef = TRUE;
381 LRESULT nRet = SalSysObjWndProc( hWnd, nMsg, wParam, lParam, bDef );
382 if ( bDef )
383 nRet = DefWindowProcA( hWnd, nMsg, wParam, lParam );
384 return nRet;
387 LRESULT CALLBACK SalSysObjWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
389 int bDef = TRUE;
390 LRESULT nRet = SalSysObjWndProc( hWnd, nMsg, wParam, lParam, bDef );
391 if ( bDef )
392 nRet = DefWindowProcW( hWnd, nMsg, wParam, lParam );
393 return nRet;
396 // -----------------------------------------------------------------------
398 LRESULT CALLBACK SalSysObjChildWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef )
400 LRESULT nRet = 0;
402 switch( nMsg )
404 // Wegen PlugIn's loeschen wir erstmal den Hintergrund
405 case WM_ERASEBKGND:
407 WinSalObject* pSysObj = GetSalObjWindowPtr( ::GetParent( hWnd ) );
409 if( pSysObj && !pSysObj->IsEraseBackgroundEnabled() )
411 // do not erase background
412 nRet = 1;
413 rDef = FALSE;
416 break;
418 case WM_PAINT:
420 PAINTSTRUCT aPs;
421 BeginPaint( hWnd, &aPs );
422 EndPaint( hWnd, &aPs );
423 rDef = FALSE;
425 break;
427 case WM_MOUSEMOVE:
428 case WM_LBUTTONDOWN:
429 case WM_MBUTTONDOWN:
430 case WM_RBUTTONDOWN:
431 case WM_LBUTTONUP:
432 case WM_MBUTTONUP:
433 case WM_RBUTTONUP:
435 WinSalObject* pSysObj;
436 pSysObj = GetSalObjWindowPtr( ::GetParent( hWnd ) );
438 if( pSysObj && pSysObj->IsMouseTransparent() )
440 // forward mouse events to parent frame
441 HWND hWndParent = ::GetParent( pSysObj->mhWnd );
443 // transform coordinates
444 POINT pt;
445 pt.x = (long) LOWORD( lParam );
446 pt.y = (long) HIWORD( lParam );
447 MapWindowPoints( hWnd, hWndParent, &pt, 1 );
448 lParam = MAKELPARAM( (WORD) pt.x, (WORD) pt.y );
450 nRet = ImplSendMessage( hWndParent, nMsg, wParam, lParam );
451 rDef = FALSE;
454 break;
457 return nRet;
460 LRESULT CALLBACK SalSysObjChildWndProcA( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
462 int bDef = TRUE;
463 LRESULT nRet = SalSysObjChildWndProc( hWnd, nMsg, wParam, lParam, bDef );
464 if ( bDef )
465 nRet = DefWindowProcA( hWnd, nMsg, wParam, lParam );
466 return nRet;
469 LRESULT CALLBACK SalSysObjChildWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
471 int bDef = TRUE;
472 LRESULT nRet = SalSysObjChildWndProc( hWnd, nMsg, wParam, lParam, bDef );
473 if ( bDef )
474 nRet = DefWindowProcW( hWnd, nMsg, wParam, lParam );
475 return nRet;
478 // =======================================================================
480 SalObject* ImplSalCreateObject( WinSalInstance* pInst, WinSalFrame* pParent )
482 SalData* pSalData = GetSalData();
484 // Hook installieren, wenn es das erste SalObject ist
485 if ( !pSalData->mpFirstObject )
487 pSalData->mhSalObjMsgHook = SetWindowsHookExW( WH_CALLWNDPROC,
488 SalSysMsgProc,
489 pSalData->mhInst,
490 pSalData->mnAppThreadId );
493 if ( !pSalData->mbObjClassInit )
495 WNDCLASSEXA aWndClassEx;
496 aWndClassEx.cbSize = sizeof( aWndClassEx );
497 aWndClassEx.style = 0;
498 aWndClassEx.lpfnWndProc = SalSysObjWndProcA;
499 aWndClassEx.cbClsExtra = 0;
500 aWndClassEx.cbWndExtra = SAL_OBJECT_WNDEXTRA;
501 aWndClassEx.hInstance = pSalData->mhInst;
502 aWndClassEx.hIcon = 0;
503 aWndClassEx.hIconSm = 0;
504 aWndClassEx.hCursor = LoadCursor( 0, IDC_ARROW );
505 aWndClassEx.hbrBackground = 0;
506 aWndClassEx.lpszMenuName = 0;
507 aWndClassEx.lpszClassName = SAL_OBJECT_CLASSNAMEA;
508 if ( RegisterClassExA( &aWndClassEx ) )
510 // Clean background first because of plugins.
511 aWndClassEx.cbWndExtra = 0;
512 aWndClassEx.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
513 aWndClassEx.lpfnWndProc = SalSysObjChildWndProcA;
514 aWndClassEx.lpszClassName = SAL_OBJECT_CHILDCLASSNAMEA;
515 if ( RegisterClassExA( &aWndClassEx ) )
516 pSalData->mbObjClassInit = TRUE;
520 if ( pSalData->mbObjClassInit )
522 WinSalObject* pObject = new WinSalObject;
524 // #135235# Clip siblings of this
525 // SystemChildWindow. Otherwise, DXCanvas (using a hidden
526 // SystemChildWindow) clobbers applets/plugins during
527 // animations .
528 HWND hWnd = CreateWindowExA( 0, SAL_OBJECT_CLASSNAMEA, "",
529 WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 0, 0,
530 pParent->mhWnd, 0,
531 pInst->mhInst, (void*)pObject );
533 HWND hWndChild = 0;
534 if ( hWnd )
536 // #135235# Explicitely stack SystemChildWindows in
537 // the order they're created - since there's no notion
538 // of zorder.
539 SetWindowPos(hWnd,HWND_TOP,0,0,0,0,
540 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOSIZE);
541 hWndChild = CreateWindowExA( 0, SAL_OBJECT_CHILDCLASSNAMEA, "",
542 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE,
543 0, 0, 0, 0,
544 hWnd, 0,
545 pInst->mhInst, NULL );
548 if ( !hWndChild )
550 #if OSL_DEBUG_LEVEL > 1
551 char *msg = NULL;
552 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
553 |FORMAT_MESSAGE_IGNORE_INSERTS
554 |FORMAT_MESSAGE_FROM_SYSTEM,
555 NULL, GetLastError(), 0,
556 (LPSTR) &msg, 0, NULL);
557 MessageBoxA(NULL, msg, "CreateWindowExA failed", MB_OK);
558 #endif
559 delete pObject;
560 return NULL;
563 if ( hWnd )
565 pObject->mhWnd = hWnd;
566 pObject->mhWndChild = hWndChild;
567 pObject->maSysData.hWnd = hWndChild;
568 return pObject;
572 return NULL;
575 // =======================================================================
577 WinSalObject::WinSalObject()
579 SalData* pSalData = GetSalData();
581 mhWnd = 0;
582 mhWndChild = 0;
583 mhLastFocusWnd = 0;
584 maSysData.nSize = sizeof( SystemEnvData );
585 mpStdClipRgnData = NULL;
587 // Insert object in objectlist
588 mpNextObject = pSalData->mpFirstObject;
589 pSalData->mpFirstObject = this;
592 // -----------------------------------------------------------------------
594 WinSalObject::~WinSalObject()
596 SalData* pSalData = GetSalData();
598 // remove frame from framelist
599 if ( this == pSalData->mpFirstObject )
601 pSalData->mpFirstObject = mpNextObject;
603 // Wenn letztes SalObject, dann Hook wieder entfernen
604 if ( !pSalData->mpFirstObject )
605 UnhookWindowsHookEx( pSalData->mhSalObjMsgHook );
607 else
609 WinSalObject* pTempObject = pSalData->mpFirstObject;
610 while ( pTempObject->mpNextObject != this )
611 pTempObject = pTempObject->mpNextObject;
613 pTempObject->mpNextObject = mpNextObject;
616 // Cache-Daten zerstoeren
617 delete mpStdClipRgnData;
619 HWND hWndParent = ::GetParent( mhWnd );
621 if ( mhWndChild )
622 DestroyWindow( mhWndChild );
623 if ( mhWnd )
624 DestroyWindow( mhWnd );
626 // Palette wieder zuruecksetzen, wenn kein externes Child-Fenster
627 // mehr vorhanden ist, da diese unsere Palette ueberschrieben haben
628 // koennen
629 if ( hWndParent &&
630 ::GetActiveWindow() == hWndParent &&
631 !GetWindow( hWndParent, GW_CHILD ) )
632 ImplSendMessage( hWndParent, SAL_MSG_FORCEPALETTE, 0, 0 );
635 // -----------------------------------------------------------------------
637 void WinSalObject::ResetClipRegion()
639 SetWindowRgn( mhWnd, 0, TRUE );
642 // -----------------------------------------------------------------------
644 sal_uInt16 WinSalObject::GetClipRegionType()
646 return SAL_OBJECT_CLIP_INCLUDERECTS;
649 // -----------------------------------------------------------------------
651 void WinSalObject::BeginSetClipRegion( sal_uLong nRectCount )
653 sal_uLong nRectBufSize = sizeof(RECT)*nRectCount;
654 if ( nRectCount < SAL_CLIPRECT_COUNT )
656 if ( !mpStdClipRgnData )
657 mpStdClipRgnData = (RGNDATA*)new BYTE[sizeof(RGNDATA)-1+(SAL_CLIPRECT_COUNT*sizeof(RECT))];
658 mpClipRgnData = mpStdClipRgnData;
660 else
661 mpClipRgnData = (RGNDATA*)new BYTE[sizeof(RGNDATA)-1+nRectBufSize];
662 mpClipRgnData->rdh.dwSize = sizeof( RGNDATAHEADER );
663 mpClipRgnData->rdh.iType = RDH_RECTANGLES;
664 mpClipRgnData->rdh.nCount = nRectCount;
665 mpClipRgnData->rdh.nRgnSize = nRectBufSize;
666 SetRectEmpty( &(mpClipRgnData->rdh.rcBound) );
667 mpNextClipRect = (RECT*)(&(mpClipRgnData->Buffer));
668 mbFirstClipRect = TRUE;
671 // -----------------------------------------------------------------------
673 void WinSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
675 RECT* pRect = mpNextClipRect;
676 RECT* pBoundRect = &(mpClipRgnData->rdh.rcBound);
677 long nRight = nX + nWidth;
678 long nBottom = nY + nHeight;
680 if ( mbFirstClipRect )
682 pBoundRect->left = nX;
683 pBoundRect->top = nY;
684 pBoundRect->right = nRight;
685 pBoundRect->bottom = nBottom;
686 mbFirstClipRect = FALSE;
688 else
690 if ( nX < pBoundRect->left )
691 pBoundRect->left = (int)nX;
693 if ( nY < pBoundRect->top )
694 pBoundRect->top = (int)nY;
696 if ( nRight > pBoundRect->right )
697 pBoundRect->right = (int)nRight;
699 if ( nBottom > pBoundRect->bottom )
700 pBoundRect->bottom = (int)nBottom;
703 pRect->left = (int)nX;
704 pRect->top = (int)nY;
705 pRect->right = (int)nRight;
706 pRect->bottom = (int)nBottom;
707 mpNextClipRect++;
710 // -----------------------------------------------------------------------
712 void WinSalObject::EndSetClipRegion()
714 HRGN hRegion;
716 // Aus den Region-Daten muessen wir jetzt eine ClipRegion erzeugen
717 if ( mpClipRgnData->rdh.nCount == 1 )
719 RECT* pRect = &(mpClipRgnData->rdh.rcBound);
720 hRegion = CreateRectRgn( pRect->left, pRect->top,
721 pRect->right, pRect->bottom );
723 else
725 sal_uLong nSize = mpClipRgnData->rdh.nRgnSize+sizeof(RGNDATAHEADER);
726 hRegion = ExtCreateRegion( NULL, nSize, mpClipRgnData );
727 if ( mpClipRgnData != mpStdClipRgnData )
728 delete [] (BYTE*)mpClipRgnData;
731 DBG_ASSERT( hRegion, "SalObject::EndSetClipRegion() - Can't create ClipRegion" );
732 SetWindowRgn( mhWnd, hRegion, TRUE );
735 // -----------------------------------------------------------------------
737 void WinSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
739 sal_uLong nStyle = 0;
740 sal_Bool bVisible = (GetWindowStyle( mhWnd ) & WS_VISIBLE) != 0;
741 if ( bVisible )
743 ShowWindow( mhWnd, SW_HIDE );
744 nStyle |= SWP_SHOWWINDOW;
746 SetWindowPos( mhWnd, 0,
747 (int)nX, (int)nY, (int)nWidth, (int)nHeight,
748 SWP_NOZORDER | SWP_NOACTIVATE | nStyle );
751 // -----------------------------------------------------------------------
753 void WinSalObject::Show( sal_Bool bVisible )
755 if ( bVisible )
756 ShowWindow( mhWnd, SW_SHOWNORMAL );
757 else
758 ShowWindow( mhWnd, SW_HIDE );
761 // -----------------------------------------------------------------------
763 void WinSalObject::Enable( sal_Bool bEnable )
765 EnableWindow( mhWnd, bEnable );
768 // -----------------------------------------------------------------------
770 void WinSalObject::GrabFocus()
772 if ( mhLastFocusWnd &&
773 IsWindow( mhLastFocusWnd ) &&
774 ImplIsSysWindowOrChild( mhWndChild, mhLastFocusWnd ) )
775 ::SetFocus( mhLastFocusWnd );
776 else
777 ::SetFocus( mhWndChild );
780 const SystemEnvData* WinSalObject::GetSystemData() const
782 return &maSysData;
785 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */