xref: /trunk/main/vcl/source/window/window.cxx (revision adad3ae8)
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 #include "tools/time.hxx"
32 #include "tools/debug.hxx"
33 #include "tools/rc.h"
34 
35 #include "unotools/fontcfg.hxx"
36 #include "unotools/confignode.hxx"
37 
38 #include "vcl/unohelp.hxx"
39 #include "vcl/salgtype.hxx"
40 #include "vcl/event.hxx"
41 #include "vcl/help.hxx"
42 #include "vcl/cursor.hxx"
43 #include "vcl/svapp.hxx"
44 #include "vcl/window.hxx"
45 #include "vcl/syswin.hxx"
46 #include "vcl/syschild.hxx"
47 #include "vcl/dockwin.hxx"
48 #include "vcl/menu.hxx"
49 #include "vcl/wrkwin.hxx"
50 #include "vcl/wall.hxx"
51 #include "vcl/gradient.hxx"
52 #include "vcl/salctype.hxx"
53 #include "vcl/button.hxx"
54 #include "vcl/taskpanelist.hxx"
55 #include "vcl/dialog.hxx"
56 #include "vcl/unowrap.hxx"
57 #include "vcl/gdimtf.hxx"
58 #include "vcl/pdfextoutdevdata.hxx"
59 #include "vcl/lazydelete.hxx"
60 
61 // declare system types in sysdata.hxx
62 #include "svsys.h"
63 #include "vcl/sysdata.hxx"
64 
65 #include "salframe.hxx"
66 #include "salobj.hxx"
67 #include "salinst.hxx"
68 #include "salgdi.hxx"
69 #include "svdata.hxx"
70 #include "dbggui.hxx"
71 #include "outfont.hxx"
72 #include "window.h"
73 #include "toolbox.h"
74 #include "outdev.h"
75 #include "region.h"
76 #include "brdwin.hxx"
77 #include "helpwin.hxx"
78 #include "sallayout.hxx"
79 #include "dndlcon.hxx"
80 #include "dndevdis.hxx"
81 
82 #include "com/sun/star/awt/XWindowPeer.hpp"
83 #include "com/sun/star/rendering/XCanvas.hpp"
84 #include "com/sun/star/rendering/XSpriteCanvas.hpp"
85 #include "com/sun/star/awt/XWindow.hpp"
86 #include "comphelper/processfactory.hxx"
87 #include "com/sun/star/datatransfer/dnd/XDragSource.hpp"
88 #include "com/sun/star/datatransfer/dnd/XDropTarget.hpp"
89 #include "com/sun/star/datatransfer/clipboard/XClipboard.hpp"
90 #include "com/sun/star/awt/XTopWindow.hpp"
91 #include "com/sun/star/awt/XDisplayConnection.hpp"
92 #include "com/sun/star/lang/XInitialization.hpp"
93 #include "com/sun/star/lang/XComponent.hpp"
94 #include "com/sun/star/lang/XServiceName.hpp"
95 #include "com/sun/star/accessibility/XAccessible.hpp"
96 #include "com/sun/star/accessibility/AccessibleRole.hpp"
97 
98 #include <set>
99 #include <typeinfo>
100 
101 using namespace rtl;
102 using namespace ::com::sun::star::uno;
103 using namespace ::com::sun::star::lang;
104 using namespace ::com::sun::star::datatransfer::clipboard;
105 using namespace ::com::sun::star::datatransfer::dnd;
106 using namespace ::com::sun::star;
107 using namespace com::sun;
108 
109 using ::com::sun::star::awt::XTopWindow;
110 
111 // =======================================================================
112 
113 DBG_NAME( Window )
114 
115 // =======================================================================
116 
117 #define IMPL_PAINT_PAINT            ((sal_uInt16)0x0001)
118 #define IMPL_PAINT_PAINTALL         ((sal_uInt16)0x0002)
119 #define IMPL_PAINT_PAINTALLCHILDS   ((sal_uInt16)0x0004)
120 #define IMPL_PAINT_PAINTCHILDS      ((sal_uInt16)0x0008)
121 #define IMPL_PAINT_ERASE            ((sal_uInt16)0x0010)
122 #define IMPL_PAINT_CHECKRTL         ((sal_uInt16)0x0020)
123 
124 // -----------------------------------------------------------------------
125 
126 typedef Window* PWINDOW;
127 
128 // -----------------------------------------------------------------------
129 
130 struct ImplCalcToTopData
131 {
132     ImplCalcToTopData*  mpNext;
133     Window*             mpWindow;
134     Region*             mpInvalidateRegion;
135 };
136 
137 ImplAccessibleInfos::ImplAccessibleInfos()
138 {
139     nAccessibleRole = 0xFFFF;
140     pAccessibleName = NULL;
141     pAccessibleDescription = NULL;
142 	pLabeledByWindow = NULL;
143 	pLabelForWindow = NULL;
144 	pMemberOfWindow = NULL;
145 }
146 
147 ImplAccessibleInfos::~ImplAccessibleInfos()
148 {
149     delete pAccessibleName;
150     delete pAccessibleDescription;
151 }
152 
153 // -----------------------------------------------------------------------
154 
155 WindowImpl::WindowImpl()
156 {
157 }
158 
159 WindowImpl::~WindowImpl()
160 {
161 }
162 
163 
164 // -----------------------------------------------------------------------
165 
166 // helper method to allow inline constructor even for pWindow!=NULL case
167 void ImplDelData::AttachToWindow( const Window* pWindow )
168 {
169     if( pWindow )
170         const_cast<Window*>(pWindow)->ImplAddDel( this );
171 }
172 
173 // -----------------------------------------------------------------------
174 
175 // define dtor for ImplDelData
176 ImplDelData::~ImplDelData()
177 {
178     // #112873# auto remove of ImplDelData
179     // due to this code actively calling ImplRemoveDel() is not mandatory anymore
180     if( !mbDel && mpWindow )
181     {
182         // the window still exists but we were not removed
183         const_cast<Window*>(mpWindow)->ImplRemoveDel( this );
184         mpWindow = NULL;
185     }
186 }
187 
188 // -----------------------------------------------------------------------
189 
190 #ifdef DBG_UTIL
191 const char* ImplDbgCheckWindow( const void* pObj )
192 {
193     DBG_TESTSOLARMUTEX();
194 
195     const Window* pWindow = (Window*)pObj;
196 
197     if ( (pWindow->GetType() < WINDOW_FIRST) || (pWindow->GetType() > WINDOW_LAST) )
198         return "Window data overwrite";
199 
200     // Fenster-Verkettung ueberpruefen
201     Window* pChild = pWindow->mpWindowImpl->mpFirstChild;
202     while ( pChild )
203     {
204         if ( pChild->mpWindowImpl->mpParent != pWindow )
205             return "Child-Window-Parent wrong";
206         pChild = pChild->mpWindowImpl->mpNext;
207     }
208 
209     return NULL;
210 }
211 #endif
212 
213 // =======================================================================
214 
215 void Window::ImplInitAppFontData( Window* pWindow )
216 {
217     ImplSVData* pSVData = ImplGetSVData();
218     long nTextHeight = pWindow->GetTextHeight();
219     long nTextWidth = pWindow->GetTextWidth( XubString( RTL_CONSTASCII_USTRINGPARAM( "aemnnxEM" ) ) );
220     long nSymHeight = nTextHeight*4;
221     // Falls Font zu schmal ist, machen wir die Basis breiter,
222     // damit die Dialoge symetrisch aussehen und nicht zu schmal
223     // werden. Wenn der Dialog die gleiche breite hat, geben wir
224     // noch etwas Spielraum dazu, da etwas mehr Platz besser ist.
225     if ( nSymHeight > nTextWidth )
226         nTextWidth = nSymHeight;
227     else if ( nSymHeight+5 > nTextWidth )
228         nTextWidth = nSymHeight+5;
229     pSVData->maGDIData.mnAppFontX = nTextWidth * 10 / 8;
230     pSVData->maGDIData.mnAppFontY = nTextHeight * 10;
231 
232     // FIXME: this is currently only on aqua, check with other
233     // platforms
234     if( pSVData->maNWFData.mbNoFocusRects )
235     {
236         // try to find out wether there is a large correction
237         // of control sizes, if yes, make app font scalings larger
238         // so dialog positioning is not completely off
239         ImplControlValue aControlValue;
240         Rectangle aCtrlRegion( Point(), Size( nTextWidth < 10 ? 10 : nTextWidth, nTextHeight < 10 ? 10 : nTextHeight ) );
241         Rectangle aBoundingRgn( aCtrlRegion );
242         Rectangle aContentRgn( aCtrlRegion );
243         if( pWindow->GetNativeControlRegion( CTRL_EDITBOX, PART_ENTIRE_CONTROL, aCtrlRegion,
244                                              CTRL_STATE_ENABLED, aControlValue, rtl::OUString(),
245                                              aBoundingRgn, aContentRgn ) )
246         {
247             // comment: the magical +6 is for the extra border in bordered
248             // (which is the standard) edit fields
249             if( aContentRgn.GetHeight() - nTextHeight > (nTextHeight+4)/4 )
250                 pSVData->maGDIData.mnAppFontY = (aContentRgn.GetHeight()-4) * 10;
251         }
252     }
253 
254 
255     pSVData->maGDIData.mnRealAppFontX = pSVData->maGDIData.mnAppFontX;
256     if ( pSVData->maAppData.mnDialogScaleX )
257         pSVData->maGDIData.mnAppFontX += (pSVData->maGDIData.mnAppFontX*pSVData->maAppData.mnDialogScaleX)/100;
258 }
259 
260 // -----------------------------------------------------------------------
261 
262 bool Window::ImplCheckUIFont( const Font& rFont )
263 {
264     if( ImplGetSVData()->maGDIData.mbNativeFontConfig )
265         return true;
266 
267 	// create a text string using the localized text of important buttons
268 	String aTestText;
269 	static const StandardButtonType aTestButtons[] =
270 	{
271 		BUTTON_OK, BUTTON_CANCEL, BUTTON_CLOSE, BUTTON_ABORT,
272 		BUTTON_YES, BUTTON_NO, BUTTON_MORE, BUTTON_IGNORE,
273 		BUTTON_RETRY, BUTTON_HELP
274 	};
275 
276 	const int nTestButtonCount = sizeof(aTestButtons)/sizeof(*aTestButtons);
277 	for( int n = 0; n < nTestButtonCount; ++n )
278 	{
279 		String aButtonStr = Button::GetStandardText( aTestButtons[n] );
280 		// #i115432# ignore mnemonic+accelerator part of each string
281 		// TODO: use a string filtering method when it becomes available
282 		const int nLen = aButtonStr.Len();
283 		bool bInside = false;
284 		for( int i = 0; i < nLen; ++i ) {
285 			const sal_Unicode c = aButtonStr.GetChar( i );
286 			if( (c == '('))
287 				bInside = true;
288 			if( (c == ')'))
289 				bInside = false;
290 			if( (c == '~')
291 			||  (c == '(') || (c == ')')
292 			|| ((c >= 'A') && (c <= 'Z') && bInside) )
293 				aButtonStr.SetChar( i, ' ' );
294 		}
295 		// append sanitized button text to test string
296 		aTestText.Append( aButtonStr );
297 	}
298 
299 	const int nFirstChar = HasGlyphs( rFont, aTestText );
300 	const bool bUIFontOk = (nFirstChar >= aTestText.Len());
301 	return bUIFontOk;
302 }
303 
304 // -----------------------------------------------------------------------
305 
306 void Window::ImplUpdateGlobalSettings( AllSettings& rSettings, sal_Bool bCallHdl )
307 {
308     // reset high contrast to false, so the system can either update it
309     // or AutoDetectSystemHC can kick in (see below)
310     StyleSettings aTmpSt( rSettings.GetStyleSettings() );
311     aTmpSt.SetHighContrastMode( sal_False );
312     rSettings.SetStyleSettings( aTmpSt );
313     ImplGetFrame()->UpdateSettings( rSettings );
314     // reset default border width for layouters
315     ImplGetSVData()->maAppData.mnDefaultLayoutBorder = -1;
316 
317     // Verify availability of the configured UI font, otherwise choose "Andale Sans UI"
318     String aUserInterfaceFont;
319     bool bUseSystemFont = rSettings.GetStyleSettings().GetUseSystemUIFonts();
320 
321     // check whether system UI font can display a typical UI text
322     if( bUseSystemFont )
323         bUseSystemFont = ImplCheckUIFont( rSettings.GetStyleSettings().GetAppFont() );
324 
325     if ( !bUseSystemFont )
326     {
327         ImplInitFontList();
328         String aConfigFont = utl::DefaultFontConfiguration::get()->getUserInterfaceFont( rSettings.GetUILocale() );
329         xub_StrLen nIndex = 0;
330         while( nIndex != STRING_NOTFOUND )
331         {
332             String aName( aConfigFont.GetToken( 0, ';', nIndex ) );
333             if ( aName.Len() && mpWindowImpl->mpFrameData->mpFontList->FindFontFamily( aName ) )
334             {
335                 aUserInterfaceFont = aConfigFont;
336                 break;
337             }
338         }
339 
340         if ( ! aUserInterfaceFont.Len() )
341         {
342             String aFallbackFont (RTL_CONSTASCII_USTRINGPARAM( "Andale Sans UI" ));
343             if ( mpWindowImpl->mpFrameData->mpFontList->FindFontFamily( aFallbackFont ) )
344                 aUserInterfaceFont = aFallbackFont;
345         }
346     }
347 
348     if ( !bUseSystemFont && aUserInterfaceFont.Len() )
349     {
350         StyleSettings aStyleSettings = rSettings.GetStyleSettings();
351         Font aFont = aStyleSettings.GetAppFont();
352         aFont.SetName( aUserInterfaceFont );
353         aStyleSettings.SetAppFont( aFont );
354         aFont = aStyleSettings.GetHelpFont();
355         aFont.SetName( aUserInterfaceFont );
356         aStyleSettings.SetHelpFont( aFont );
357         aFont = aStyleSettings.GetTitleFont();
358         aFont.SetName( aUserInterfaceFont );
359         aStyleSettings.SetTitleFont( aFont );
360         aFont = aStyleSettings.GetFloatTitleFont();
361         aFont.SetName( aUserInterfaceFont );
362         aStyleSettings.SetFloatTitleFont( aFont );
363         aFont = aStyleSettings.GetMenuFont();
364         aFont.SetName( aUserInterfaceFont );
365         aStyleSettings.SetMenuFont( aFont );
366         aFont = aStyleSettings.GetToolFont();
367         aFont.SetName( aUserInterfaceFont );
368         aStyleSettings.SetToolFont( aFont );
369         aFont = aStyleSettings.GetLabelFont();
370         aFont.SetName( aUserInterfaceFont );
371         aStyleSettings.SetLabelFont( aFont );
372         aFont = aStyleSettings.GetInfoFont();
373         aFont.SetName( aUserInterfaceFont );
374         aStyleSettings.SetInfoFont( aFont );
375         aFont = aStyleSettings.GetRadioCheckFont();
376         aFont.SetName( aUserInterfaceFont );
377         aStyleSettings.SetRadioCheckFont( aFont );
378         aFont = aStyleSettings.GetPushButtonFont();
379         aFont.SetName( aUserInterfaceFont );
380         aStyleSettings.SetPushButtonFont( aFont );
381         aFont = aStyleSettings.GetFieldFont();
382         aFont.SetName( aUserInterfaceFont );
383         aStyleSettings.SetFieldFont( aFont );
384         aFont = aStyleSettings.GetIconFont();
385         aFont.SetName( aUserInterfaceFont );
386         aStyleSettings.SetIconFont( aFont );
387         aFont = aStyleSettings.GetGroupFont();
388         aFont.SetName( aUserInterfaceFont );
389         aStyleSettings.SetGroupFont( aFont );
390         rSettings.SetStyleSettings( aStyleSettings );
391     }
392 
393     StyleSettings aStyleSettings = rSettings.GetStyleSettings();
394     // #97047: Force all fonts except Menu and Help to a fixed height
395     // to avoid UI scaling due to large fonts
396     // - but allow bigger fonts on bigger screens (i16682, i21238)
397     //   dialogs were designed to fit 800x600 with an 8pt font, so scale accordingly
398     int maxFontheight = 9; // #107886#: 9 is default for some asian systems, so always allow if requested
399     if( GetDesktopRectPixel().getHeight() > 600 )
400         maxFontheight = (int) ((( 8.0 * (double) GetDesktopRectPixel().getHeight()) / 600.0) + 1.5);
401 
402     Font aFont = aStyleSettings.GetMenuFont();
403     int defFontheight = aFont.GetHeight();
404     if( defFontheight > maxFontheight )
405         defFontheight = maxFontheight;
406 
407     // if the UI is korean, chinese or another locale
408     // where the system font size is kown to be often too small to
409     // generate readable fonts enforce a minimum font size of 9 points
410     bool bBrokenLangFontHeight = false;
411     static const LanguageType eBrokenSystemFontSizeLanguages[] =
412     { LANGUAGE_KOREAN, LANGUAGE_KOREAN_JOHAB,
413       LANGUAGE_CHINESE_HONGKONG, LANGUAGE_CHINESE_MACAU, LANGUAGE_CHINESE_SIMPLIFIED, LANGUAGE_CHINESE_SINGAPORE, LANGUAGE_CHINESE_TRADITIONAL
414     };
415     static std::set< LanguageType > aBrokenSystemFontSizeLanguagesSet(
416         eBrokenSystemFontSizeLanguages,
417         eBrokenSystemFontSizeLanguages +
418         (sizeof(eBrokenSystemFontSizeLanguages)/sizeof(eBrokenSystemFontSizeLanguages[0]))
419         );
420     LanguageType aLang = Application::GetSettings().GetUILanguage();
421     if( aBrokenSystemFontSizeLanguagesSet.find( aLang ) != aBrokenSystemFontSizeLanguagesSet.end() )
422     {
423         defFontheight = Max(9, defFontheight);
424         bBrokenLangFontHeight = true;
425     }
426 
427     // i22098, toolfont will be scaled differently to avoid bloated rulers and status bars for big fonts
428     int toolfontheight = defFontheight;
429     if( toolfontheight > 9 )
430         toolfontheight = (defFontheight+8) / 2;
431 
432     aFont = aStyleSettings.GetAppFont();
433     aFont.SetHeight( defFontheight );
434     aStyleSettings.SetAppFont( aFont );
435     aFont = aStyleSettings.GetTitleFont();
436     aFont.SetHeight( defFontheight );
437     aStyleSettings.SetTitleFont( aFont );
438     aFont = aStyleSettings.GetFloatTitleFont();
439     aFont.SetHeight( defFontheight );
440     aStyleSettings.SetFloatTitleFont( aFont );
441     // keep menu and help font size from system unless in broken locale size
442     if( bBrokenLangFontHeight )
443     {
444         aFont = aStyleSettings.GetMenuFont();
445         if( aFont.GetHeight() < defFontheight )
446         {
447             aFont.SetHeight( defFontheight );
448             aStyleSettings.SetMenuFont( aFont );
449         }
450         aFont = aStyleSettings.GetHelpFont();
451         if( aFont.GetHeight() < defFontheight )
452         {
453             aFont.SetHeight( defFontheight );
454             aStyleSettings.SetHelpFont( aFont );
455         }
456     }
457 
458     // use different height for toolfont
459     aFont = aStyleSettings.GetToolFont();
460     aFont.SetHeight( toolfontheight );
461     aStyleSettings.SetToolFont( aFont );
462 
463     aFont = aStyleSettings.GetLabelFont();
464     aFont.SetHeight( defFontheight );
465     aStyleSettings.SetLabelFont( aFont );
466     aFont = aStyleSettings.GetInfoFont();
467     aFont.SetHeight( defFontheight );
468     aStyleSettings.SetInfoFont( aFont );
469     aFont = aStyleSettings.GetRadioCheckFont();
470     aFont.SetHeight( defFontheight );
471     aStyleSettings.SetRadioCheckFont( aFont );
472     aFont = aStyleSettings.GetPushButtonFont();
473     aFont.SetHeight( defFontheight );
474     aStyleSettings.SetPushButtonFont( aFont );
475     aFont = aStyleSettings.GetFieldFont();
476     aFont.SetHeight( defFontheight );
477     aStyleSettings.SetFieldFont( aFont );
478     aFont = aStyleSettings.GetIconFont();
479     aFont.SetHeight( defFontheight );
480     aStyleSettings.SetIconFont( aFont );
481     aFont = aStyleSettings.GetGroupFont();
482     aFont.SetHeight( defFontheight );
483     aStyleSettings.SetGroupFont( aFont );
484 
485     // set workspace gradient to black in dark themes
486     if( aStyleSettings.GetWindowColor().IsDark() )
487         aStyleSettings.SetWorkspaceGradient( Wallpaper( Color( COL_BLACK ) ) );
488     else
489     {
490         Gradient aGrad( GRADIENT_LINEAR, DEFAULT_WORKSPACE_GRADIENT_START_COLOR, DEFAULT_WORKSPACE_GRADIENT_END_COLOR );
491         aStyleSettings.SetWorkspaceGradient( Wallpaper( aGrad ) );
492     }
493 
494     rSettings.SetStyleSettings( aStyleSettings );
495 
496 
497     // auto detect HC mode; if the system already set it to "yes"
498     // (see above) then accept that
499     if( !rSettings.GetStyleSettings().GetHighContrastMode() )
500     {
501         sal_Bool bTmp = sal_False, bAutoHCMode = sal_True;
502         utl::OConfigurationNode aNode = utl::OConfigurationTreeRoot::tryCreateWithServiceFactory(
503             vcl::unohelper::GetMultiServiceFactory(),
504             OUString::createFromAscii( "org.openoffice.Office.Common/Accessibility" ) );    // note: case sensisitive !
505         if ( aNode.isValid() )
506         {
507             ::com::sun::star::uno::Any aValue = aNode.getNodeValue( OUString::createFromAscii( "AutoDetectSystemHC" ) );
508             if( aValue >>= bTmp )
509                 bAutoHCMode = bTmp;
510         }
511         if( bAutoHCMode )
512         {
513             if( rSettings.GetStyleSettings().GetFaceColor().IsDark()
514              || rSettings.GetStyleSettings().GetWindowColor().IsDark() )
515             {
516                 aStyleSettings = rSettings.GetStyleSettings();
517                 aStyleSettings.SetHighContrastMode( sal_True );
518                 rSettings.SetStyleSettings( aStyleSettings );
519             }
520         }
521     }
522 
523     static const char* pEnvHC = getenv( "SAL_FORCE_HC" );
524     if( pEnvHC && *pEnvHC )
525     {
526         aStyleSettings.SetHighContrastMode( sal_True );
527         rSettings.SetStyleSettings( aStyleSettings );
528     }
529 
530 #ifdef DBG_UTIL
531     // Evt. AppFont auf Fett schalten, damit man feststellen kann,
532     // ob fuer die Texte auf anderen Systemen genuegend Platz
533     // vorhanden ist
534     if ( DbgIsBoldAppFont() )
535     {
536         aStyleSettings = rSettings.GetStyleSettings();
537         aFont = aStyleSettings.GetAppFont();
538         aFont.SetWeight( WEIGHT_BOLD );
539         aStyleSettings.SetAppFont( aFont );
540         aFont = aStyleSettings.GetGroupFont();
541         aFont.SetWeight( WEIGHT_BOLD );
542         aStyleSettings.SetGroupFont( aFont );
543         aFont = aStyleSettings.GetLabelFont();
544         aFont.SetWeight( WEIGHT_BOLD );
545         aStyleSettings.SetLabelFont( aFont );
546         aFont = aStyleSettings.GetRadioCheckFont();
547         aFont.SetWeight( WEIGHT_BOLD );
548         aStyleSettings.SetRadioCheckFont( aFont );
549         aFont = aStyleSettings.GetPushButtonFont();
550         aFont.SetWeight( WEIGHT_BOLD );
551         aStyleSettings.SetPushButtonFont( aFont );
552         aFont = aStyleSettings.GetFieldFont();
553         aFont.SetWeight( WEIGHT_BOLD );
554         aStyleSettings.SetFieldFont( aFont );
555         aFont = aStyleSettings.GetIconFont();
556         aFont.SetWeight( WEIGHT_BOLD );
557         aStyleSettings.SetIconFont( aFont );
558         rSettings.SetStyleSettings( aStyleSettings );
559     }
560 #endif
561 
562     if ( bCallHdl )
563         GetpApp()->SystemSettingsChanging( rSettings, this );
564 }
565 
566 // -----------------------------------------------------------------------
567 
568 MouseEvent ImplTranslateMouseEvent( const MouseEvent& rE, Window* pSource, Window* pDest )
569 {
570     Point aPos = pSource->OutputToScreenPixel( rE.GetPosPixel() );
571     aPos = pDest->ScreenToOutputPixel( aPos );
572     return MouseEvent( aPos, rE.GetClicks(), rE.GetMode(), rE.GetButtons(), rE.GetModifier() );
573 }
574 
575 // -----------------------------------------------------------------------
576 
577 CommandEvent ImplTranslateCommandEvent( const CommandEvent& rCEvt, Window* pSource, Window* pDest )
578 {
579     if ( !rCEvt.IsMouseEvent() )
580         return rCEvt;
581 
582     Point aPos = pSource->OutputToScreenPixel( rCEvt.GetMousePosPixel() );
583     aPos = pDest->ScreenToOutputPixel( aPos );
584     return CommandEvent( aPos, rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetData() );
585 }
586 
587 // =======================================================================
588 
589 void Window::ImplInitWindowData( WindowType nType )
590 {
591     mpWindowImpl = new WindowImpl;
592 
593     meOutDevType        = OUTDEV_WINDOW;
594 
595     mpWindowImpl->maZoom              = Fraction( 1, 1 );
596     mpWindowImpl->maWinRegion         = Region( REGION_NULL );
597     mpWindowImpl->maWinClipRegion                   = Region( REGION_NULL );
598     mpWindowImpl->mpWinData           = NULL;         // Extra Window Data, that we dont need for all windows
599     mpWindowImpl->mpOverlapData       = NULL;         // Overlap Data
600     mpWindowImpl->mpFrameData         = NULL;         // Frame Data
601     mpWindowImpl->mpFrame             = NULL;         // Pointer to frame window
602     mpWindowImpl->mpSysObj            = NULL;
603     mpWindowImpl->mpFrameWindow       = NULL;         // window to top level parent (same as frame window)
604     mpWindowImpl->mpOverlapWindow     = NULL;         // first overlap parent
605     mpWindowImpl->mpBorderWindow      = NULL;         // Border-Window
606     mpWindowImpl->mpClientWindow      = NULL;         // Client-Window of a FrameWindow
607     mpWindowImpl->mpParent            = NULL;         // parent (inkl. BorderWindow)
608     mpWindowImpl->mpRealParent        = NULL;         // real parent (exkl. BorderWindow)
609     mpWindowImpl->mpFirstChild        = NULL;         // first child window
610     mpWindowImpl->mpLastChild         = NULL;         // last child window
611     mpWindowImpl->mpFirstOverlap      = NULL;         // first overlap window (only set in overlap windows)
612     mpWindowImpl->mpLastOverlap       = NULL;         // last overlap window (only set in overlap windows)
613     mpWindowImpl->mpPrev              = NULL;         // prev window
614     mpWindowImpl->mpNext              = NULL;         // next window
615     mpWindowImpl->mpNextOverlap       = NULL;         // next overlap window of frame
616     mpWindowImpl->mpLastFocusWindow   = NULL;         // window for focus restore
617     mpWindowImpl->mpDlgCtrlDownWindow = NULL;         // window for dialog control
618     mpWindowImpl->mpFirstDel          = NULL;         // Dtor notification list
619     mpWindowImpl->mpUserData          = NULL;         // user data
620     mpWindowImpl->mpExtImpl           = NULL;         // extended implementation data
621     mpWindowImpl->mpCursor            = NULL;         // cursor
622     mpWindowImpl->mpControlFont       = NULL;         // font propertie
623     mpWindowImpl->mpVCLXWindow        = NULL;
624     mpWindowImpl->mpAccessibleInfos   = NULL;
625     mpWindowImpl->maControlForeground = Color( COL_TRANSPARENT );     // kein Foreground gesetzt
626     mpWindowImpl->maControlBackground = Color( COL_TRANSPARENT );     // kein Background gesetzt
627     mpWindowImpl->mnLeftBorder        = 0;            // left border
628     mpWindowImpl->mnTopBorder         = 0;            // top border
629     mpWindowImpl->mnRightBorder       = 0;            // right border
630     mpWindowImpl->mnBottomBorder      = 0;            // bottom border
631     mpWindowImpl->mnX                 = 0;            // X-Position to Parent
632     mpWindowImpl->mnY                 = 0;            // Y-Position to Parent
633 	mpWindowImpl->mnAbsScreenX        = 0;            // absolute X-position on screen, used for RTL window positioning
634     mpWindowImpl->mpChildClipRegion   = NULL;         // Child-Clip-Region when ClipChildren
635     mpWindowImpl->mpPaintRegion       = NULL;         // Paint-ClipRegion
636     mpWindowImpl->mnStyle             = 0;            // style (init in ImplInitWindow)
637     mpWindowImpl->mnPrevStyle         = 0;            // prevstyle (set in SetStyle)
638     mpWindowImpl->mnExtendedStyle     = 0;            // extended style (init in ImplInitWindow)
639     mpWindowImpl->mnPrevExtendedStyle = 0;            // prevstyle (set in SetExtendedStyle)
640     mpWindowImpl->mnType              = nType;        // type
641     mpWindowImpl->mnGetFocusFlags     = 0;            // Flags fuer GetFocus()-Aufruf
642     mpWindowImpl->mnWaitCount         = 0;            // Wait-Count (>1 == Warte-MousePointer)
643     mpWindowImpl->mnPaintFlags        = 0;            // Flags for ImplCallPaint
644     mpWindowImpl->mnParentClipMode    = 0;            // Flags for Parent-ClipChildren-Mode
645     mpWindowImpl->mnActivateMode      = 0;            // Wird bei System/Overlap-Windows umgesetzt
646     mpWindowImpl->mnDlgCtrlFlags      = 0;            // DialogControl-Flags
647     mpWindowImpl->mnLockCount         = 0;            // LockCount
648     mpWindowImpl->meAlwaysInputMode   = AlwaysInputNone; // neither AlwaysEnableInput nor AlwaysDisableInput called
649     mpWindowImpl->mbFrame             = sal_False;        // sal_True: Window is a frame window
650     mpWindowImpl->mbBorderWin         = sal_False;        // sal_True: Window is a border window
651     mpWindowImpl->mbOverlapWin        = sal_False;        // sal_True: Window is a overlap window
652     mpWindowImpl->mbSysWin            = sal_False;        // sal_True: SystemWindow is the base class
653     mpWindowImpl->mbDialog            = sal_False;        // sal_True: Dialog is the base class
654     mpWindowImpl->mbDockWin           = sal_False;        // sal_True: DockingWindow is the base class
655     mpWindowImpl->mbFloatWin          = sal_False;        // sal_True: FloatingWindow is the base class
656     mpWindowImpl->mbPushButton        = sal_False;        // sal_True: PushButton is the base class
657     mpWindowImpl->mbToolBox			= sal_False;		// sal_True: ToolBox is the base class
658     mpWindowImpl->mbMenuFloatingWindow= sal_False;		// sal_True: MenuFloatingWindow is the base class
659     mpWindowImpl->mbToolbarFloatingWindow= sal_False;		// sal_True: ImplPopupFloatWin is the base class, used for subtoolbars
660     mpWindowImpl->mbSplitter			= sal_False;		// sal_True: Splitter is the base class
661     mpWindowImpl->mbVisible           = sal_False;        // sal_True: Show( sal_True ) called
662     mpWindowImpl->mbOverlapVisible    = sal_False;        // sal_True: Hide called for visible window from ImplHideAllOverlapWindow()
663     mpWindowImpl->mbDisabled          = sal_False;        // sal_True: Enable( sal_False ) called
664     mpWindowImpl->mbInputDisabled     = sal_False;        // sal_True: EnableInput( sal_False ) called
665     mpWindowImpl->mbDropDisabled      = sal_False;        // sal_True: Drop is enabled
666     mpWindowImpl->mbNoUpdate          = sal_False;        // sal_True: SetUpdateMode( sal_False ) called
667     mpWindowImpl->mbNoParentUpdate    = sal_False;        // sal_True: SetParentUpdateMode( sal_False ) called
668     mpWindowImpl->mbActive            = sal_False;        // sal_True: Window Active
669     mpWindowImpl->mbParentActive      = sal_False;        // sal_True: OverlapActive from Parent
670     mpWindowImpl->mbReallyVisible     = sal_False;        // sal_True: this and all parents to an overlaped window are visible
671     mpWindowImpl->mbReallyShown       = sal_False;        // sal_True: this and all parents to an overlaped window are shown
672     mpWindowImpl->mbInInitShow        = sal_False;        // sal_True: we are in InitShow
673     mpWindowImpl->mbChildNotify       = sal_False;        // sal_True: ChildNotify
674     mpWindowImpl->mbChildPtrOverwrite = sal_False;        // sal_True: PointerStyle overwrites Child-Pointer
675     mpWindowImpl->mbNoPtrVisible      = sal_False;        // sal_True: ShowPointer( sal_False ) called
676     mpWindowImpl->mbMouseMove         = sal_False;        // sal_True: BaseMouseMove called
677     mpWindowImpl->mbPaintFrame        = sal_False;        // sal_True: Paint is visible, but not painted
678     mpWindowImpl->mbInPaint           = sal_False;        // sal_True: Inside PaintHdl
679     mpWindowImpl->mbMouseButtonDown   = sal_False;        // sal_True: BaseMouseButtonDown called
680     mpWindowImpl->mbMouseButtonUp     = sal_False;        // sal_True: BaseMouseButtonUp called
681     mpWindowImpl->mbKeyInput          = sal_False;        // sal_True: BaseKeyInput called
682     mpWindowImpl->mbKeyUp             = sal_False;        // sal_True: BaseKeyUp called
683     mpWindowImpl->mbCommand           = sal_False;        // sal_True: BaseCommand called
684     mpWindowImpl->mbDefPos            = sal_True;         // sal_True: Position is not Set
685     mpWindowImpl->mbDefSize           = sal_True;         // sal_True: Size is not Set
686     mpWindowImpl->mbCallMove          = sal_True;         // sal_True: Move must be called by Show
687     mpWindowImpl->mbCallResize        = sal_True;         // sal_True: Resize must be called by Show
688     mpWindowImpl->mbWaitSystemResize  = sal_True;         // sal_True: Wait for System-Resize
689     mpWindowImpl->mbInitWinClipRegion = sal_True;         // sal_True: Calc Window Clip Region
690     mpWindowImpl->mbInitChildRegion   = sal_False;        // sal_True: InitChildClipRegion
691     mpWindowImpl->mbWinRegion         = sal_False;        // sal_True: Window Region
692     mpWindowImpl->mbClipChildren      = sal_False;        // sal_True: Child-Fenster muessen evt. geclippt werden
693     mpWindowImpl->mbClipSiblings      = sal_False;        // sal_True: Nebeneinanderliegende Child-Fenster muessen evt. geclippt werden
694     mpWindowImpl->mbChildTransparent  = sal_False;        // sal_True: Child-Fenster duerfen transparent einschalten (inkl. Parent-CLIPCHILDREN)
695     mpWindowImpl->mbPaintTransparent  = sal_False;        // sal_True: Paints muessen auf Parent ausgeloest werden
696     mpWindowImpl->mbMouseTransparent  = sal_False;        // sal_True: Window is transparent for Mouse
697     mpWindowImpl->mbDlgCtrlStart      = sal_False;        // sal_True: Ab hier eigenes Dialog-Control
698     mpWindowImpl->mbFocusVisible      = sal_False;        // sal_True: Focus Visible
699     mpWindowImpl->mbUseNativeFocus    = sal_False;
700     mpWindowImpl->mbNativeFocusVisible= sal_False;        // sal_True: native Focus Visible
701     mpWindowImpl->mbInShowFocus       = sal_False;        // prevent recursion
702     mpWindowImpl->mbInHideFocus       = sal_False;        // prevent recursion
703     mpWindowImpl->mbTrackVisible      = sal_False;        // sal_True: Tracking Visible
704     mpWindowImpl->mbControlForeground = sal_False;        // sal_True: Foreground-Property set
705     mpWindowImpl->mbControlBackground = sal_False;        // sal_True: Background-Property set
706     mpWindowImpl->mbAlwaysOnTop       = sal_False;        // sal_True: immer vor allen anderen normalen Fenstern sichtbar
707     mpWindowImpl->mbCompoundControl   = sal_False;        // sal_True: Zusammengesetztes Control => Listener...
708     mpWindowImpl->mbCompoundControlHasFocus = sal_False;  // sal_True: Zusammengesetztes Control hat irgendwo den Focus
709     mpWindowImpl->mbPaintDisabled     = sal_False;        // sal_True: Paint soll nicht ausgefuehrt werden
710     mpWindowImpl->mbAllResize         = sal_False;        // sal_True: Auch ResizeEvents mit 0,0 schicken
711     mpWindowImpl->mbInDtor            = sal_False;        // sal_True: Wir befinden uns im Window-Dtor
712     mpWindowImpl->mbExtTextInput      = sal_False;        // sal_True: ExtTextInput-Mode is active
713     mpWindowImpl->mbInFocusHdl        = sal_False;        // sal_True: Innerhalb vom GetFocus-Handler
714     mpWindowImpl->mbCreatedWithToolkit = sal_False;
715     mpWindowImpl->mbSuppressAccessibilityEvents = sal_False; // sal_True: do not send any accessibility events
716     mpWindowImpl->mbDrawSelectionBackground = sal_False;    // sal_True: draws transparent window background to indicate (toolbox) selection
717     mpWindowImpl->mbIsInTaskPaneList = sal_False;           // sal_True: window was added to the taskpanelist in the topmost system window
718     mpWindowImpl->mnNativeBackground  = 0;              // initialize later, depends on type
719     mpWindowImpl->mbCallHandlersDuringInputDisabled = sal_False; // sal_True: call event handlers even if input is disabled
720     mpWindowImpl->mbDisableAccessibleLabelForRelation = sal_False; // sal_True: do not set LabelFor relation on accessible objects
721     mpWindowImpl->mbDisableAccessibleLabeledByRelation = sal_False; // sal_True: do not set LabeledBy relation on accessible objects
722     mpWindowImpl->mbHelpTextDynamic = sal_False;          // sal_True: append help id in HELP_DEBUG case
723     mpWindowImpl->mbFakeFocusSet = sal_False; // sal_True: pretend as if the window has focus.
724 
725     mbEnableRTL         = Application::GetSettings().GetLayoutRTL();         // sal_True: this outdev will be mirrored if RTL window layout (UI mirroring) is globally active
726 }
727 
728 // -----------------------------------------------------------------------
729 
730 void Window::ImplInit( Window* pParent, WinBits nStyle, const ::com::sun::star::uno::Any& /*aSystemWorkWindowToken*/ )
731 {
732     ImplInit( pParent, nStyle, NULL );
733 }
734 
735 // -----------------------------------------------------------------------
736 
737 void Window::ImplInit( Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData )
738 {
739     DBG_ASSERT( mpWindowImpl->mbFrame || pParent, "Window::Window(): pParent == NULL" );
740 
741     ImplSVData* pSVData = ImplGetSVData();
742     Window*     pRealParent = pParent;
743 
744     // 3D-Look vererben
745     if ( !mpWindowImpl->mbOverlapWin && pParent && (pParent->GetStyle() & WB_3DLOOK) )
746         nStyle |= WB_3DLOOK;
747 
748     // create border window if necessary
749     if ( !mpWindowImpl->mbFrame && !mpWindowImpl->mbBorderWin && !mpWindowImpl->mpBorderWindow
750          && (nStyle & (WB_BORDER | WB_SYSTEMCHILDWINDOW) ) )
751     {
752         sal_uInt16 nBorderTypeStyle = 0;
753         if( (nStyle & WB_SYSTEMCHILDWINDOW) )
754         {
755             // handle WB_SYSTEMCHILDWINDOW
756             // these should be analogous to a top level frame; meaning they
757             // should have a border window with style BORDERWINDOW_STYLE_FRAME
758             // which controls their size
759             nBorderTypeStyle |= BORDERWINDOW_STYLE_FRAME;
760             nStyle |= WB_BORDER;
761         }
762         ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, nStyle & (WB_BORDER | WB_DIALOGCONTROL | WB_NODIALOGCONTROL | WB_NEEDSFOCUS), nBorderTypeStyle );
763         ((Window*)pBorderWin)->mpWindowImpl->mpClientWindow = this;
764         pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
765         mpWindowImpl->mpBorderWindow  = pBorderWin;
766         pParent = mpWindowImpl->mpBorderWindow;
767     }
768     else if( !mpWindowImpl->mbFrame && ! pParent )
769     {
770         mpWindowImpl->mbOverlapWin  = sal_True;
771         mpWindowImpl->mbFrame = sal_True;
772     }
773 
774     // insert window in list
775     ImplInsertWindow( pParent );
776     mpWindowImpl->mnStyle = nStyle;
777 
778     // Overlap-Window-Daten
779     if ( mpWindowImpl->mbOverlapWin )
780     {
781         mpWindowImpl->mpOverlapData                   = new ImplOverlapData;
782         mpWindowImpl->mpOverlapData->mpSaveBackDev    = NULL;
783         mpWindowImpl->mpOverlapData->mpSaveBackRgn    = NULL;
784         mpWindowImpl->mpOverlapData->mpNextBackWin    = NULL;
785         mpWindowImpl->mpOverlapData->mnSaveBackSize   = 0;
786         mpWindowImpl->mpOverlapData->mbSaveBack       = sal_False;
787         mpWindowImpl->mpOverlapData->mnTopLevel       = 1;
788     }
789 
790     if( pParent && ! mpWindowImpl->mbFrame )
791         mbEnableRTL = pParent->mbEnableRTL;
792 
793     // test for frame creation
794     if ( mpWindowImpl->mbFrame )
795     {
796         // create frame
797         sal_uLong nFrameStyle = 0;
798 
799         if ( nStyle & WB_MOVEABLE )
800             nFrameStyle |= SAL_FRAME_STYLE_MOVEABLE;
801         if ( nStyle & WB_SIZEABLE )
802             nFrameStyle |= SAL_FRAME_STYLE_SIZEABLE;
803         if ( nStyle & WB_CLOSEABLE )
804             nFrameStyle |= SAL_FRAME_STYLE_CLOSEABLE;
805         if ( nStyle & WB_APP )
806             nFrameStyle |= SAL_FRAME_STYLE_DEFAULT;
807         // check for undecorated floating window
808         if( // 1. floating windows that are not moveable/sizeable (only closeable allowed)
809             ( !(nFrameStyle & ~SAL_FRAME_STYLE_CLOSEABLE) &&
810             ( mpWindowImpl->mbFloatWin || ((GetType() == WINDOW_BORDERWINDOW) && ((ImplBorderWindow*)this)->mbFloatWindow) || (nStyle & WB_SYSTEMFLOATWIN) ) ) ||
811             // 2. borderwindows of floaters with ownerdraw decoration
812             ( ((GetType() == WINDOW_BORDERWINDOW) && ((ImplBorderWindow*)this)->mbFloatWindow && (nStyle & WB_OWNERDRAWDECORATION) ) ) )
813         {
814             nFrameStyle = SAL_FRAME_STYLE_FLOAT;
815             if( nStyle & WB_OWNERDRAWDECORATION )
816                 nFrameStyle |= (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_NOSHADOW);
817             if( nStyle & WB_NEEDSFOCUS )
818                 nFrameStyle |= SAL_FRAME_STYLE_FLOAT_FOCUSABLE;
819         }
820         else if( mpWindowImpl->mbFloatWin )
821             nFrameStyle |= SAL_FRAME_STYLE_TOOLWINDOW;
822 
823         if( nStyle & WB_INTROWIN )
824             nFrameStyle |= SAL_FRAME_STYLE_INTRO;
825         if( nStyle & WB_TOOLTIPWIN )
826             nFrameStyle |= SAL_FRAME_STYLE_TOOLTIP;
827 
828         if( nStyle & WB_NOSHADOW )
829             nFrameStyle |= SAL_FRAME_STYLE_NOSHADOW;
830 
831         if( nStyle & WB_SYSTEMCHILDWINDOW )
832             nFrameStyle |= SAL_FRAME_STYLE_SYSTEMCHILD;
833 
834         switch (mpWindowImpl->mnType)
835         {
836             case WINDOW_DIALOG:
837             case WINDOW_TABDIALOG:
838             case WINDOW_MODALDIALOG:
839             case WINDOW_MODELESSDIALOG:
840             case WINDOW_MESSBOX:
841             case WINDOW_INFOBOX:
842             case WINDOW_WARNINGBOX:
843             case WINDOW_ERRORBOX:
844             case WINDOW_QUERYBOX:
845                 nFrameStyle |= SAL_FRAME_STYLE_DIALOG;
846             default:
847                 break;
848         }
849 
850         SalFrame* pParentFrame = NULL;
851         if ( pParent )
852             pParentFrame = pParent->mpWindowImpl->mpFrame;
853         SalFrame* pFrame;
854         if ( pSystemParentData )
855             pFrame = pSVData->mpDefInst->CreateChildFrame( pSystemParentData, nFrameStyle | SAL_FRAME_STYLE_PLUG );
856         else
857             pFrame = pSVData->mpDefInst->CreateFrame( pParentFrame, nFrameStyle );
858         if ( !pFrame )
859         {
860             // do not abort but throw an exception, may be the current thread terminates anyway (plugin-scenario)
861             throw ::com::sun::star::uno::RuntimeException(
862                 OUString( RTL_CONSTASCII_USTRINGPARAM( "Could not create system window!" ) ),
863                 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
864             //GetpApp()->Exception( EXC_SYSOBJNOTCREATED );
865         }
866 
867         pFrame->SetCallback( this, ImplWindowFrameProc );
868 
869         // set window frame data
870         mpWindowImpl->mpFrameData     = new ImplFrameData;
871         mpWindowImpl->mpFrame         = pFrame;
872         mpWindowImpl->mpFrameWindow   = this;
873         mpWindowImpl->mpOverlapWindow = this;
874 
875         // set frame data
876         mpWindowImpl->mpFrameData->mpNextFrame        = pSVData->maWinData.mpFirstFrame;
877         pSVData->maWinData.mpFirstFrame = this;
878         mpWindowImpl->mpFrameData->mpFirstOverlap     = NULL;
879         mpWindowImpl->mpFrameData->mpFocusWin         = NULL;
880         mpWindowImpl->mpFrameData->mpMouseMoveWin     = NULL;
881         mpWindowImpl->mpFrameData->mpMouseDownWin     = NULL;
882         mpWindowImpl->mpFrameData->mpFirstBackWin     = NULL;
883         mpWindowImpl->mpFrameData->mpFontList         = pSVData->maGDIData.mpScreenFontList;
884         mpWindowImpl->mpFrameData->mpFontCache        = pSVData->maGDIData.mpScreenFontCache;
885         mpWindowImpl->mpFrameData->mnAllSaveBackSize  = 0;
886         mpWindowImpl->mpFrameData->mnFocusId          = 0;
887         mpWindowImpl->mpFrameData->mnMouseMoveId      = 0;
888         mpWindowImpl->mpFrameData->mnLastMouseX       = -1;
889         mpWindowImpl->mpFrameData->mnLastMouseY       = -1;
890         mpWindowImpl->mpFrameData->mnBeforeLastMouseX = -1;
891         mpWindowImpl->mpFrameData->mnBeforeLastMouseY = -1;
892         mpWindowImpl->mpFrameData->mnFirstMouseX      = -1;
893         mpWindowImpl->mpFrameData->mnFirstMouseY      = -1;
894         mpWindowImpl->mpFrameData->mnLastMouseWinX    = -1;
895         mpWindowImpl->mpFrameData->mnLastMouseWinY    = -1;
896         mpWindowImpl->mpFrameData->mnModalMode        = 0;
897         mpWindowImpl->mpFrameData->mnMouseDownTime    = 0;
898         mpWindowImpl->mpFrameData->mnClickCount       = 0;
899         mpWindowImpl->mpFrameData->mnFirstMouseCode   = 0;
900         mpWindowImpl->mpFrameData->mnMouseCode        = 0;
901         mpWindowImpl->mpFrameData->mnMouseMode        = 0;
902         mpWindowImpl->mpFrameData->meMapUnit          = MAP_PIXEL;
903         mpWindowImpl->mpFrameData->mbHasFocus         = sal_False;
904         mpWindowImpl->mpFrameData->mbInMouseMove      = sal_False;
905         mpWindowImpl->mpFrameData->mbMouseIn          = sal_False;
906         mpWindowImpl->mpFrameData->mbStartDragCalled  = sal_False;
907         mpWindowImpl->mpFrameData->mbNeedSysWindow    = sal_False;
908         mpWindowImpl->mpFrameData->mbMinimized        = sal_False;
909         mpWindowImpl->mpFrameData->mbStartFocusState  = sal_False;
910         mpWindowImpl->mpFrameData->mbInSysObjFocusHdl = sal_False;
911         mpWindowImpl->mpFrameData->mbInSysObjToTopHdl = sal_False;
912         mpWindowImpl->mpFrameData->mbSysObjFocus      = sal_False;
913         mpWindowImpl->mpFrameData->maPaintTimer.SetTimeout( 30 );
914         mpWindowImpl->mpFrameData->maPaintTimer.SetTimeoutHdl( LINK( this, Window, ImplHandlePaintHdl ) );
915         mpWindowImpl->mpFrameData->maResizeTimer.SetTimeout( 50 );
916         mpWindowImpl->mpFrameData->maResizeTimer.SetTimeoutHdl( LINK( this, Window, ImplHandleResizeTimerHdl ) );
917         mpWindowImpl->mpFrameData->mbInternalDragGestureRecognizer = sal_False;
918 
919         if ( pRealParent && IsTopWindow() )
920         {
921             ImplWinData* pParentWinData = pRealParent->ImplGetWinData();
922             pParentWinData->maTopWindowChildren.push_back( this );
923         }
924     }
925 
926     // init data
927     mpWindowImpl->mpRealParent = pRealParent;
928 
929     // #99318: make sure fontcache and list is available before call to SetSettings
930     mpFontList      = mpWindowImpl->mpFrameData->mpFontList;
931     mpFontCache     = mpWindowImpl->mpFrameData->mpFontCache;
932 
933     if ( mpWindowImpl->mbFrame )
934     {
935         if ( pParent )
936         {
937             mpWindowImpl->mpFrameData->mnDPIX     = pParent->mpWindowImpl->mpFrameData->mnDPIX;
938             mpWindowImpl->mpFrameData->mnDPIY     = pParent->mpWindowImpl->mpFrameData->mnDPIY;
939         }
940         else
941         {
942             if ( ImplGetGraphics() )
943             {
944                 mpGraphics->GetResolution( mpWindowImpl->mpFrameData->mnDPIX, mpWindowImpl->mpFrameData->mnDPIY );
945             }
946         }
947 
948         // add ownerdraw decorated frame windows to list in the top-most frame window
949         // so they can be hidden on lose focus
950         if( nStyle & WB_OWNERDRAWDECORATION )
951             ImplGetOwnerDrawList().push_back( this );
952 
953         // delay settings initialization until first "real" frame
954         // this relies on the IntroWindow not needing any system settings
955         if ( !pSVData->maAppData.mbSettingsInit &&
956              ! (nStyle & (WB_INTROWIN|WB_DEFAULTWIN))
957              )
958         {
959             // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
960             ImplUpdateGlobalSettings( *pSVData->maAppData.mpSettings );
961             OutputDevice::SetSettings( *pSVData->maAppData.mpSettings );
962             pSVData->maAppData.mbSettingsInit = sal_True;
963         }
964 
965         // If we create a Window with default size, query this
966         // size directly, because we want resize all Controls to
967         // the correct size before we display the window
968         if ( nStyle & (WB_MOVEABLE | WB_SIZEABLE | WB_APP) )
969             mpWindowImpl->mpFrame->GetClientSize( mnOutWidth, mnOutHeight );
970     }
971     else
972     {
973         if ( pParent )
974         {
975             if ( !ImplIsOverlapWindow() )
976             {
977                 mpWindowImpl->mbDisabled          = pParent->mpWindowImpl->mbDisabled;
978                 mpWindowImpl->mbInputDisabled     = pParent->mpWindowImpl->mbInputDisabled;
979                 mpWindowImpl->meAlwaysInputMode   = pParent->mpWindowImpl->meAlwaysInputMode;
980             }
981 
982             OutputDevice::SetSettings( pParent->GetSettings() );
983         }
984 
985     }
986 
987     const StyleSettings& rStyleSettings = maSettings.GetStyleSettings();
988     sal_uInt16 nScreenZoom = rStyleSettings.GetScreenZoom();
989     mnDPIX          = (mpWindowImpl->mpFrameData->mnDPIX*nScreenZoom)/100;
990     mnDPIY          = (mpWindowImpl->mpFrameData->mnDPIY*nScreenZoom)/100;
991     maFont          = rStyleSettings.GetAppFont();
992     ImplPointToLogic( maFont );
993 
994     if ( nStyle & WB_3DLOOK )
995     {
996         SetTextColor( rStyleSettings.GetButtonTextColor() );
997         SetBackground( Wallpaper( rStyleSettings.GetFaceColor() ) );
998     }
999     else
1000     {
1001         SetTextColor( rStyleSettings.GetWindowTextColor() );
1002         SetBackground( Wallpaper( rStyleSettings.GetWindowColor() ) );
1003     }
1004 
1005     ImplUpdatePos();
1006 
1007     // calculate app font res (except for the Intro Window or the default window)
1008     if ( mpWindowImpl->mbFrame && !pSVData->maGDIData.mnAppFontX && ! (nStyle & (WB_INTROWIN|WB_DEFAULTWIN)) )
1009         ImplInitAppFontData( this );
1010 
1011     if ( GetAccessibleParentWindow()  && GetParent() != Application::GetDefDialogParent() )
1012         GetAccessibleParentWindow()->ImplCallEventListeners( VCLEVENT_WINDOW_CHILDCREATED, this );
1013 }
1014 
1015 // -----------------------------------------------------------------------
1016 
1017 void Window::ImplSetFrameParent( const Window* pParent )
1018 {
1019     Window* pFrameWindow = ImplGetSVData()->maWinData.mpFirstFrame;
1020     while( pFrameWindow )
1021     {
1022         // search all frames that are children of this window
1023         // and reparent them
1024         if( ImplIsRealParentPath( pFrameWindow ) )
1025         {
1026             DBG_ASSERT( mpWindowImpl->mpFrame != pFrameWindow->mpWindowImpl->mpFrame, "SetFrameParent to own" );
1027             DBG_ASSERT( mpWindowImpl->mpFrame, "no frame" );
1028             SalFrame* pParentFrame = pParent ? pParent->mpWindowImpl->mpFrame : NULL;
1029             pFrameWindow->mpWindowImpl->mpFrame->SetParent( pParentFrame );
1030         }
1031         pFrameWindow = pFrameWindow->mpWindowImpl->mpFrameData->mpNextFrame;
1032     }
1033 }
1034 
1035 // -----------------------------------------------------------------------
1036 
1037 void Window::ImplInsertWindow( Window* pParent )
1038 {
1039     mpWindowImpl->mpParent            = pParent;
1040     mpWindowImpl->mpRealParent        = pParent;
1041 
1042     if ( pParent && !mpWindowImpl->mbFrame )
1043     {
1044         // search frame window and set window frame data
1045         Window* pFrameParent = pParent->mpWindowImpl->mpFrameWindow;
1046         mpWindowImpl->mpFrameData     = pFrameParent->mpWindowImpl->mpFrameData;
1047         mpWindowImpl->mpFrame         = pFrameParent->mpWindowImpl->mpFrame;
1048         mpWindowImpl->mpFrameWindow   = pFrameParent;
1049         mpWindowImpl->mbFrame         = sal_False;
1050 
1051         // search overlap window and insert window in list
1052         if ( ImplIsOverlapWindow() )
1053         {
1054             Window* pFirstOverlapParent = pParent;
1055             while ( !pFirstOverlapParent->ImplIsOverlapWindow() )
1056                 pFirstOverlapParent = pFirstOverlapParent->ImplGetParent();
1057             mpWindowImpl->mpOverlapWindow = pFirstOverlapParent;
1058 
1059             mpWindowImpl->mpNextOverlap = mpWindowImpl->mpFrameData->mpFirstOverlap;
1060             mpWindowImpl->mpFrameData->mpFirstOverlap = this;
1061 
1062             // Overlap-Windows sind per default die obersten
1063             mpWindowImpl->mpNext = pFirstOverlapParent->mpWindowImpl->mpFirstOverlap;
1064             pFirstOverlapParent->mpWindowImpl->mpFirstOverlap = this;
1065             if ( !pFirstOverlapParent->mpWindowImpl->mpLastOverlap )
1066                 pFirstOverlapParent->mpWindowImpl->mpLastOverlap = this;
1067             else
1068                 mpWindowImpl->mpNext->mpWindowImpl->mpPrev = this;
1069         }
1070         else
1071         {
1072             if ( pParent->ImplIsOverlapWindow() )
1073                 mpWindowImpl->mpOverlapWindow = pParent;
1074             else
1075                 mpWindowImpl->mpOverlapWindow = pParent->mpWindowImpl->mpOverlapWindow;
1076             mpWindowImpl->mpPrev = pParent->mpWindowImpl->mpLastChild;
1077             pParent->mpWindowImpl->mpLastChild = this;
1078             if ( !pParent->mpWindowImpl->mpFirstChild )
1079                 pParent->mpWindowImpl->mpFirstChild = this;
1080             else
1081                 mpWindowImpl->mpPrev->mpWindowImpl->mpNext = this;
1082         }
1083     }
1084 }
1085 
1086 // -----------------------------------------------------------------------
1087 
1088 void Window::ImplRemoveWindow( sal_Bool bRemoveFrameData )
1089 {
1090     // Fenster aus den Listen austragen
1091     if ( !mpWindowImpl->mbFrame )
1092     {
1093         if ( ImplIsOverlapWindow() )
1094         {
1095             if ( mpWindowImpl->mpFrameData->mpFirstOverlap == this )
1096                 mpWindowImpl->mpFrameData->mpFirstOverlap = mpWindowImpl->mpNextOverlap;
1097             else
1098             {
1099                 Window* pTempWin = mpWindowImpl->mpFrameData->mpFirstOverlap;
1100                 while ( pTempWin->mpWindowImpl->mpNextOverlap != this )
1101                     pTempWin = pTempWin->mpWindowImpl->mpNextOverlap;
1102                 pTempWin->mpWindowImpl->mpNextOverlap = mpWindowImpl->mpNextOverlap;
1103             }
1104 
1105             if ( mpWindowImpl->mpPrev )
1106                 mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext;
1107             else
1108                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap = mpWindowImpl->mpNext;
1109             if ( mpWindowImpl->mpNext )
1110                 mpWindowImpl->mpNext->mpWindowImpl->mpPrev = mpWindowImpl->mpPrev;
1111             else
1112                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpLastOverlap = mpWindowImpl->mpPrev;
1113         }
1114         else
1115         {
1116             if ( mpWindowImpl->mpPrev )
1117                 mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext;
1118             else
1119                 mpWindowImpl->mpParent->mpWindowImpl->mpFirstChild = mpWindowImpl->mpNext;
1120             if ( mpWindowImpl->mpNext )
1121                 mpWindowImpl->mpNext->mpWindowImpl->mpPrev = mpWindowImpl->mpPrev;
1122             else
1123                 mpWindowImpl->mpParent->mpWindowImpl->mpLastChild = mpWindowImpl->mpPrev;
1124         }
1125 
1126         mpWindowImpl->mpPrev = NULL;
1127         mpWindowImpl->mpNext = NULL;
1128     }
1129 
1130     if ( bRemoveFrameData )
1131     {
1132         // Graphic freigeben
1133         ImplReleaseGraphics();
1134     }
1135 }
1136 
1137 // -----------------------------------------------------------------------
1138 
1139 void Window::ImplCallResize()
1140 {
1141     mpWindowImpl->mbCallResize = sal_False;
1142 
1143     if( GetBackground().IsGradient() )
1144         Invalidate();
1145 
1146     Resize();
1147 
1148     // #88419# Most classes don't call the base class in Resize() and Move(),
1149     // => Call ImpleResize/Move instead of Resize/Move directly...
1150     ImplCallEventListeners( VCLEVENT_WINDOW_RESIZE );
1151 
1152     ImplExtResize();
1153 }
1154 
1155 // -----------------------------------------------------------------------
1156 
1157 void Window::ImplCallMove()
1158 {
1159     mpWindowImpl->mbCallMove = sal_False;
1160 
1161     if( mpWindowImpl->mbFrame )
1162     {
1163         // update frame position
1164         SalFrame *pParentFrame = NULL;
1165         Window *pParent = ImplGetParent();
1166         while( pParent )
1167         {
1168             if( pParent->mpWindowImpl->mpFrame != mpWindowImpl->mpFrame )
1169             {
1170                 pParentFrame = pParent->mpWindowImpl->mpFrame;
1171                 break;
1172             }
1173             pParent = pParent->GetParent();
1174         }
1175 
1176         SalFrameGeometry g = mpWindowImpl->mpFrame->GetGeometry();
1177         mpWindowImpl->maPos = Point( g.nX, g.nY );
1178         if( pParentFrame )
1179         {
1180             g = pParentFrame->GetGeometry();
1181             mpWindowImpl->maPos -= Point( g.nX, g.nY );
1182         }
1183         // the client window and and all its subclients have the same position as the borderframe
1184         // this is important for floating toolbars where the borderwindow is a floating window
1185         // which has another borderwindow (ie the system floating window)
1186         Window *pClientWin = mpWindowImpl->mpClientWindow;
1187         while( pClientWin )
1188         {
1189             pClientWin->mpWindowImpl->maPos = mpWindowImpl->maPos;
1190             pClientWin = pClientWin->mpWindowImpl->mpClientWindow;
1191         }
1192     }
1193 
1194     Move();
1195 
1196     ImplCallEventListeners( VCLEVENT_WINDOW_MOVE );
1197 }
1198 
1199 // -----------------------------------------------------------------------
1200 
1201 static rtl::OString ImplAutoHelpID( ResMgr* pResMgr )
1202 {
1203     rtl::OString aRet;
1204 
1205     if( pResMgr && Application::IsAutoHelpIdEnabled() )
1206         aRet = pResMgr->GetAutoHelpId();
1207 
1208     return aRet;
1209 }
1210 
1211 // -----------------------------------------------------------------------
1212 
1213 WinBits Window::ImplInitRes( const ResId& rResId )
1214 {
1215     GetRes( rResId );
1216 
1217     char* pRes = (char*)GetClassRes();
1218     pRes += 8;
1219     sal_uInt32 nStyle = (sal_uInt32)GetLongRes( (void*)pRes );
1220     rResId.SetWinBits( nStyle );
1221     return nStyle;
1222 }
1223 
1224 // -----------------------------------------------------------------------
1225 
1226 void Window::ImplLoadRes( const ResId& rResId )
1227 {
1228     sal_uLong nObjMask = ReadLongRes();
1229 
1230     // we need to calculate auto helpids before the resource gets closed
1231     // if the resource  only contains flags, it will be closed before we try to read a help id
1232     // so we always create an auto help id that might be overwritten later
1233     // HelpId
1234     rtl::OString aHelpId = ImplAutoHelpID( rResId.GetResMgr() );
1235 
1236     // ResourceStyle
1237     sal_uLong nRSStyle = ReadLongRes();
1238     // WinBits
1239     ReadLongRes();
1240 
1241     if( nObjMask & WINDOW_HELPID )
1242         aHelpId = ReadByteStringRes();
1243 
1244     SetHelpId( aHelpId );
1245 
1246     sal_Bool  bPos  = sal_False;
1247     sal_Bool  bSize = sal_False;
1248     Point aPos;
1249     Size  aSize;
1250 
1251     if ( nObjMask & (WINDOW_XYMAPMODE | WINDOW_X | WINDOW_Y) )
1252     {
1253         // Groessenangabe aus der Resource verwenden
1254         MapUnit ePosMap = MAP_PIXEL;
1255 
1256         bPos = sal_True;
1257 
1258         if ( nObjMask & WINDOW_XYMAPMODE )
1259             ePosMap = (MapUnit)ReadLongRes();
1260         if ( nObjMask & WINDOW_X )
1261             aPos.X() = ImplLogicUnitToPixelX( ReadLongRes(), ePosMap );
1262         if ( nObjMask & WINDOW_Y )
1263             aPos.Y() = ImplLogicUnitToPixelY( ReadLongRes(), ePosMap );
1264     }
1265 
1266     if ( nObjMask & (WINDOW_WHMAPMODE | WINDOW_WIDTH | WINDOW_HEIGHT) )
1267     {
1268         // Groessenangabe aus der Resource verwenden
1269         MapUnit eSizeMap = MAP_PIXEL;
1270 
1271         bSize = sal_True;
1272 
1273         if ( nObjMask & WINDOW_WHMAPMODE )
1274             eSizeMap = (MapUnit)ReadLongRes();
1275         if ( nObjMask & WINDOW_WIDTH )
1276             aSize.Width() = ImplLogicUnitToPixelX( ReadLongRes(), eSizeMap );
1277         if ( nObjMask & WINDOW_HEIGHT )
1278             aSize.Height() = ImplLogicUnitToPixelY( ReadLongRes(), eSizeMap );
1279     }
1280 
1281     // Wegen Optimierung so schlimm aussehend
1282     if ( nRSStyle & RSWND_CLIENTSIZE )
1283     {
1284         if ( bPos )
1285             SetPosPixel( aPos );
1286         if ( bSize )
1287             SetOutputSizePixel( aSize );
1288     }
1289     else if ( bPos && bSize )
1290         SetPosSizePixel( aPos, aSize );
1291     else if ( bPos )
1292         SetPosPixel( aPos );
1293     else if ( bSize )
1294         SetSizePixel( aSize );
1295 
1296     if ( nRSStyle & RSWND_DISABLED )
1297         Enable( sal_False );
1298 
1299     if ( nObjMask & WINDOW_TEXT )
1300         SetText( ReadStringRes() );
1301     if ( nObjMask & WINDOW_HELPTEXT )
1302     {
1303         SetHelpText( ReadStringRes() );
1304         mpWindowImpl->mbHelpTextDynamic = sal_True;
1305     }
1306     if ( nObjMask & WINDOW_QUICKTEXT )
1307         SetQuickHelpText( ReadStringRes() );
1308     if ( nObjMask & WINDOW_EXTRALONG )
1309         SetData( (void*)ReadLongRes() );
1310     if ( nObjMask & WINDOW_UNIQUEID )
1311         SetUniqueId( ReadByteStringRes() );
1312 
1313     if ( nObjMask & WINDOW_BORDER_STYLE )
1314     {
1315         sal_uInt16 nBorderStyle = (sal_uInt16)ReadLongRes();
1316         SetBorderStyle( nBorderStyle );
1317     }
1318 }
1319 
1320 // -----------------------------------------------------------------------
1321 
1322 ImplWinData* Window::ImplGetWinData() const
1323 {
1324     if ( !mpWindowImpl->mpWinData )
1325     {
1326         static const char* pNoNWF = getenv( "SAL_NO_NWF" );
1327 
1328         ((Window*)this)->mpWindowImpl->mpWinData = new ImplWinData;
1329         mpWindowImpl->mpWinData->mpExtOldText     = NULL;
1330         mpWindowImpl->mpWinData->mpExtOldAttrAry  = NULL;
1331         mpWindowImpl->mpWinData->mpCursorRect     = 0;
1332         mpWindowImpl->mpWinData->mnCursorExtWidth = 0;
1333         mpWindowImpl->mpWinData->mpFocusRect      = NULL;
1334         mpWindowImpl->mpWinData->mpTrackRect      = NULL;
1335         mpWindowImpl->mpWinData->mnTrackFlags     = 0;
1336         mpWindowImpl->mpWinData->mnIsTopWindow	= (sal_uInt16) ~0;  // not initialized yet, 0/1 will indicate TopWindow (see IsTopWindow())
1337         mpWindowImpl->mpWinData->mbMouseOver      = sal_False;
1338         mpWindowImpl->mpWinData->mbEnableNativeWidget = (pNoNWF && *pNoNWF) ? sal_False : sal_True; // sal_True: try to draw this control with native theme API
1339    }
1340 
1341     return mpWindowImpl->mpWinData;
1342 }
1343 
1344 // -----------------------------------------------------------------------
1345 
1346 SalGraphics* Window::ImplGetFrameGraphics() const
1347 {
1348     if ( mpWindowImpl->mpFrameWindow->mpGraphics )
1349         mpWindowImpl->mpFrameWindow->mbInitClipRegion = sal_True;
1350     else
1351         mpWindowImpl->mpFrameWindow->ImplGetGraphics();
1352     mpWindowImpl->mpFrameWindow->mpGraphics->ResetClipRegion();
1353     return mpWindowImpl->mpFrameWindow->mpGraphics;
1354 }
1355 
1356 // -----------------------------------------------------------------------
1357 
1358 Window* Window::ImplFindWindow( const Point& rFramePos )
1359 {
1360     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
1361 
1362     Window* pTempWindow;
1363     Window* pFindWindow;
1364 
1365     // Zuerst alle ueberlappenden Fenster ueberpruefen
1366     pTempWindow = mpWindowImpl->mpFirstOverlap;
1367     while ( pTempWindow )
1368     {
1369         pFindWindow = pTempWindow->ImplFindWindow( rFramePos );
1370         if ( pFindWindow )
1371             return pFindWindow;
1372         pTempWindow = pTempWindow->mpWindowImpl->mpNext;
1373     }
1374 
1375     // dann testen wir unser Fenster
1376     if ( !mpWindowImpl->mbVisible )
1377         return NULL;
1378 
1379     sal_uInt16 nHitTest = ImplHitTest( rFramePos );
1380     if ( nHitTest & WINDOW_HITTEST_INSIDE )
1381     {
1382         // und danach gehen wir noch alle Child-Fenster durch
1383         pTempWindow = mpWindowImpl->mpFirstChild;
1384         while ( pTempWindow )
1385         {
1386             pFindWindow = pTempWindow->ImplFindWindow( rFramePos );
1387             if ( pFindWindow )
1388                 return pFindWindow;
1389             pTempWindow = pTempWindow->mpWindowImpl->mpNext;
1390         }
1391 
1392         if ( nHitTest & WINDOW_HITTEST_TRANSPARENT )
1393             return NULL;
1394         else
1395             return this;
1396     }
1397 
1398     return NULL;
1399 }
1400 
1401 // -----------------------------------------------------------------------
1402 
1403 sal_uInt16 Window::ImplHitTest( const Point& rFramePos )
1404 {
1405     Point aFramePos( rFramePos );
1406     if( ImplIsAntiparallel() )
1407     {
1408         // - RTL - re-mirror frame pos at this window
1409         ImplReMirror( aFramePos );
1410     }
1411     Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
1412     if ( !aRect.IsInside( aFramePos ) )
1413         return 0;
1414     if ( mpWindowImpl->mbWinRegion )
1415     {
1416         Point aTempPos = aFramePos;
1417         aTempPos.X() -= mnOutOffX;
1418         aTempPos.Y() -= mnOutOffY;
1419         if ( !mpWindowImpl->maWinRegion.IsInside( aTempPos ) )
1420             return 0;
1421     }
1422 
1423     sal_uInt16 nHitTest = WINDOW_HITTEST_INSIDE;
1424     if ( mpWindowImpl->mbMouseTransparent )
1425         nHitTest |= WINDOW_HITTEST_TRANSPARENT;
1426     return nHitTest;
1427 }
1428 
1429 // -----------------------------------------------------------------------
1430 
1431 sal_Bool Window::ImplIsRealParentPath( const Window* pWindow ) const
1432 {
1433     pWindow = pWindow->GetParent();
1434     while ( pWindow )
1435     {
1436         if ( pWindow == this )
1437             return sal_True;
1438         pWindow = pWindow->GetParent();
1439     }
1440 
1441     return sal_False;
1442 }
1443 
1444 // -----------------------------------------------------------------------
1445 
1446 sal_Bool Window::ImplIsChild( const Window* pWindow, sal_Bool bSystemWindow ) const
1447 {
1448     do
1449     {
1450         if ( !bSystemWindow && pWindow->ImplIsOverlapWindow() )
1451             break;
1452 
1453         pWindow = pWindow->ImplGetParent();
1454 
1455         if ( pWindow == this )
1456             return sal_True;
1457     }
1458     while ( pWindow );
1459 
1460     return sal_False;
1461 }
1462 
1463 // -----------------------------------------------------------------------
1464 
1465 sal_Bool Window::ImplIsWindowOrChild( const Window* pWindow, sal_Bool bSystemWindow ) const
1466 {
1467     if ( this == pWindow )
1468         return sal_True;
1469     return ImplIsChild( pWindow, bSystemWindow );
1470 }
1471 
1472 // -----------------------------------------------------------------------
1473 
1474 Window* Window::ImplGetSameParent( const Window* pWindow ) const
1475 {
1476     if ( mpWindowImpl->mpFrameWindow != pWindow->mpWindowImpl->mpFrameWindow )
1477         return NULL;
1478     else
1479     {
1480         if ( pWindow->ImplIsChild( this ) )
1481             return (Window*)pWindow;
1482         else
1483         {
1484             Window* pTestWindow = (Window*)this;
1485             while ( (pTestWindow == pWindow) || pTestWindow->ImplIsChild( pWindow ) )
1486                 pTestWindow = pTestWindow->ImplGetParent();
1487             return pTestWindow;
1488         }
1489     }
1490 }
1491 
1492 // -----------------------------------------------------------------------
1493 
1494 int Window::ImplTestMousePointerSet()
1495 {
1496     // Wenn Mouse gecaptured ist, dann soll MousePointer umgeschaltet werden
1497     if ( IsMouseCaptured() )
1498         return sal_True;
1499 
1500     // Wenn sich Mouse ueber dem Fenster befindet, dann soll MousePointer
1501     // umgeschaltet werden
1502     Rectangle aClientRect( Point( 0, 0 ), GetOutputSizePixel() );
1503     if ( aClientRect.IsInside( GetPointerPosPixel() ) )
1504         return sal_True;
1505 
1506     return sal_False;
1507 }
1508 
1509 // -----------------------------------------------------------------------
1510 
1511 PointerStyle Window::ImplGetMousePointer() const
1512 {
1513     PointerStyle    ePointerStyle;
1514     sal_Bool            bWait = sal_False;
1515 
1516     if ( IsEnabled() && IsInputEnabled() && ! IsInModalMode() )
1517         ePointerStyle = GetPointer().GetStyle();
1518     else
1519         ePointerStyle = POINTER_ARROW;
1520 
1521     const Window* pWindow = this;
1522     do
1523     {
1524         // Wenn Pointer nicht sichtbar, dann wird suche abgebrochen, da
1525         // dieser Status nicht ueberschrieben werden darf
1526         if ( pWindow->mpWindowImpl->mbNoPtrVisible )
1527             return POINTER_NULL;
1528 
1529         if ( !bWait )
1530         {
1531             if ( pWindow->mpWindowImpl->mnWaitCount )
1532             {
1533                 ePointerStyle = POINTER_WAIT;
1534                 bWait = sal_True;
1535             }
1536             else
1537             {
1538                 if ( pWindow->mpWindowImpl->mbChildPtrOverwrite )
1539                     ePointerStyle = pWindow->GetPointer().GetStyle();
1540             }
1541         }
1542 
1543         if ( pWindow->ImplIsOverlapWindow() )
1544             break;
1545 
1546         pWindow = pWindow->ImplGetParent();
1547     }
1548     while ( pWindow );
1549 
1550     return ePointerStyle;
1551 }
1552 
1553 // -----------------------------------------------------------------------
1554 
1555 void Window::ImplResetReallyVisible()
1556 {
1557     sal_Bool bBecameReallyInvisible = mpWindowImpl->mbReallyVisible;
1558 
1559     mbDevOutput     = sal_False;
1560     mpWindowImpl->mbReallyVisible = sal_False;
1561     mpWindowImpl->mbReallyShown   = sal_False;
1562 
1563     // the SHOW/HIDE events serve as indicators to send child creation/destroy events to the access bridge.
1564     // For this, the data member of the event must not be NULL.
1565     // Previously, we did this in Window::Show, but there some events got lost in certain situations.
1566     // #104887# - 2004-08-10 - fs@openoffice.org
1567 	if( bBecameReallyInvisible && ImplIsAccessibleCandidate() )
1568         ImplCallEventListeners( VCLEVENT_WINDOW_HIDE, this );
1569         // TODO. It's kind of a hack that we're re-using the VCLEVENT_WINDOW_HIDE. Normally, we should
1570         // introduce another event which explicitly triggers the Accessibility implementations.
1571 
1572     Window* pWindow = mpWindowImpl->mpFirstOverlap;
1573     while ( pWindow )
1574     {
1575         if ( pWindow->mpWindowImpl->mbReallyVisible )
1576             pWindow->ImplResetReallyVisible();
1577         pWindow = pWindow->mpWindowImpl->mpNext;
1578     }
1579 
1580     pWindow = mpWindowImpl->mpFirstChild;
1581     while ( pWindow )
1582     {
1583         if ( pWindow->mpWindowImpl->mbReallyVisible )
1584             pWindow->ImplResetReallyVisible();
1585         pWindow = pWindow->mpWindowImpl->mpNext;
1586     }
1587 }
1588 
1589 // -----------------------------------------------------------------------
1590 
1591 void Window::ImplSetReallyVisible()
1592 {
1593     // #i43594# it is possible that INITSHOW was never send, because the visibility state changed between
1594     // ImplCallInitShow() and ImplSetReallyVisible() when called from Show()
1595     // mbReallyShown is a useful indicator
1596     if( !mpWindowImpl->mbReallyShown )
1597         ImplCallInitShow();
1598 
1599     sal_Bool bBecameReallyVisible = !mpWindowImpl->mbReallyVisible;
1600 
1601     mbDevOutput     = sal_True;
1602     mpWindowImpl->mbReallyVisible = sal_True;
1603     mpWindowImpl->mbReallyShown   = sal_True;
1604 
1605     // the SHOW/HIDE events serve as indicators to send child creation/destroy events to the access bridge.
1606     // For this, the data member of the event must not be NULL.
1607     // Previously, we did this in Window::Show, but there some events got lost in certain situations. Now
1608     // we're doing it when the visibility really changes
1609     // #104887# - 2004-08-10 - fs@openoffice.org
1610 	if( bBecameReallyVisible && ImplIsAccessibleCandidate() )
1611         ImplCallEventListeners( VCLEVENT_WINDOW_SHOW, this );
1612         // TODO. It's kind of a hack that we're re-using the VCLEVENT_WINDOW_SHOW. Normally, we should
1613         // introduce another event which explicitly triggers the Accessibility implementations.
1614 
1615     Window* pWindow = mpWindowImpl->mpFirstOverlap;
1616     while ( pWindow )
1617     {
1618         if ( pWindow->mpWindowImpl->mbVisible )
1619             pWindow->ImplSetReallyVisible();
1620         pWindow = pWindow->mpWindowImpl->mpNext;
1621     }
1622 
1623     pWindow = mpWindowImpl->mpFirstChild;
1624     while ( pWindow )
1625     {
1626         if ( pWindow->mpWindowImpl->mbVisible )
1627             pWindow->ImplSetReallyVisible();
1628         pWindow = pWindow->mpWindowImpl->mpNext;
1629     }
1630 }
1631 
1632 // -----------------------------------------------------------------------
1633 
1634 void Window::ImplCallInitShow()
1635 {
1636     mpWindowImpl->mbReallyShown   = sal_True;
1637     mpWindowImpl->mbInInitShow    = sal_True;
1638     StateChanged( STATE_CHANGE_INITSHOW );
1639     mpWindowImpl->mbInInitShow    = sal_False;
1640 
1641     Window* pWindow = mpWindowImpl->mpFirstOverlap;
1642     while ( pWindow )
1643     {
1644         if ( pWindow->mpWindowImpl->mbVisible )
1645             pWindow->ImplCallInitShow();
1646         pWindow = pWindow->mpWindowImpl->mpNext;
1647     }
1648 
1649     pWindow = mpWindowImpl->mpFirstChild;
1650     while ( pWindow )
1651     {
1652         if ( pWindow->mpWindowImpl->mbVisible )
1653             pWindow->ImplCallInitShow();
1654         pWindow = pWindow->mpWindowImpl->mpNext;
1655     }
1656 }
1657 
1658 // -----------------------------------------------------------------------
1659 
1660 void Window::ImplAddDel( ImplDelData* pDel ) // TODO: make "const" when incompatiblity ok
1661 {
1662     DBG_ASSERT( !pDel->mpWindow, "Window::ImplAddDel(): cannot add ImplDelData twice !" );
1663     if( !pDel->mpWindow )
1664     {
1665         pDel->mpWindow = this;  // #112873# store ref to this window, so pDel can remove itself
1666         pDel->mpNext = mpWindowImpl->mpFirstDel;
1667         mpWindowImpl->mpFirstDel = pDel;
1668     }
1669 }
1670 
1671 // -----------------------------------------------------------------------
1672 
1673 void Window::ImplRemoveDel( ImplDelData* pDel ) // TODO: make "const" when incompatiblity ok
1674 {
1675     pDel->mpWindow = NULL;      // #112873# pDel is not associated with a Window anymore
1676     if ( mpWindowImpl->mpFirstDel == pDel )
1677         mpWindowImpl->mpFirstDel = pDel->mpNext;
1678     else
1679     {
1680         ImplDelData* pData = mpWindowImpl->mpFirstDel;
1681         while ( pData->mpNext != pDel )
1682             pData = pData->mpNext;
1683         pData->mpNext = pDel->mpNext;
1684     }
1685 }
1686 
1687 // -----------------------------------------------------------------------
1688 
1689 void Window::ImplInitResolutionSettings()
1690 {
1691     // AppFont-Aufloesung und DPI-Aufloesung neu berechnen
1692     if ( mpWindowImpl->mbFrame )
1693     {
1694         const StyleSettings& rStyleSettings = maSettings.GetStyleSettings();
1695         sal_uInt16 nScreenZoom = rStyleSettings.GetScreenZoom();
1696         mnDPIX = (mpWindowImpl->mpFrameData->mnDPIX*nScreenZoom)/100;
1697         mnDPIY = (mpWindowImpl->mpFrameData->mnDPIY*nScreenZoom)/100;
1698         SetPointFont( rStyleSettings.GetAppFont() );
1699     }
1700     else if ( mpWindowImpl->mpParent )
1701     {
1702         mnDPIX  = mpWindowImpl->mpParent->mnDPIX;
1703         mnDPIY  = mpWindowImpl->mpParent->mnDPIY;
1704     }
1705 
1706     // Vorberechnete Werte fuer logische Einheiten updaten und auch
1707     // die entsprechenden Tools dazu
1708     if ( IsMapMode() )
1709     {
1710         MapMode aMapMode = GetMapMode();
1711         SetMapMode();
1712         SetMapMode( aMapMode );
1713     }
1714 }
1715 
1716 // -----------------------------------------------------------------------
1717 
1718 void Window::ImplPointToLogic( Font& rFont ) const
1719 {
1720     Size    aSize = rFont.GetSize();
1721     sal_uInt16  nScreenFontZoom = maSettings.GetStyleSettings().GetScreenFontZoom();
1722 
1723     if ( aSize.Width() )
1724     {
1725         aSize.Width() *= mpWindowImpl->mpFrameData->mnDPIX;
1726         aSize.Width() += 72/2;
1727         aSize.Width() /= 72;
1728         aSize.Width() *= nScreenFontZoom;
1729         aSize.Width() /= 100;
1730     }
1731     aSize.Height() *= mpWindowImpl->mpFrameData->mnDPIY;
1732     aSize.Height() += 72/2;
1733     aSize.Height() /= 72;
1734     aSize.Height() *= nScreenFontZoom;
1735     aSize.Height() /= 100;
1736 
1737     if ( IsMapModeEnabled() )
1738         aSize = PixelToLogic( aSize );
1739 
1740     rFont.SetSize( aSize );
1741 }
1742 
1743 // -----------------------------------------------------------------------
1744 
1745 void Window::ImplLogicToPoint( Font& rFont ) const
1746 {
1747     Size    aSize = rFont.GetSize();
1748     sal_uInt16  nScreenFontZoom = maSettings.GetStyleSettings().GetScreenFontZoom();
1749 
1750     if ( IsMapModeEnabled() )
1751         aSize = LogicToPixel( aSize );
1752 
1753     if ( aSize.Width() )
1754     {
1755         aSize.Width() *= 100;
1756         aSize.Width() /= nScreenFontZoom;
1757         aSize.Width() *= 72;
1758         aSize.Width() += mpWindowImpl->mpFrameData->mnDPIX/2;
1759         aSize.Width() /= mpWindowImpl->mpFrameData->mnDPIX;
1760     }
1761     aSize.Height() *= 100;
1762     aSize.Height() /= nScreenFontZoom;
1763     aSize.Height() *= 72;
1764     aSize.Height() += mpWindowImpl->mpFrameData->mnDPIY/2;
1765     aSize.Height() /= mpWindowImpl->mpFrameData->mnDPIY;
1766 
1767     rFont.SetSize( aSize );
1768 }
1769 
1770 // -----------------------------------------------------------------------
1771 
1772 sal_Bool Window::ImplSysObjClip( const Region* pOldRegion )
1773 {
1774     sal_Bool bUpdate = sal_True;
1775 
1776     if ( mpWindowImpl->mpSysObj )
1777     {
1778         sal_Bool bVisibleState = mpWindowImpl->mbReallyVisible;
1779 
1780         if ( bVisibleState )
1781         {
1782             Region* pWinChildClipRegion = ImplGetWinChildClipRegion();
1783 
1784             if ( !pWinChildClipRegion->IsEmpty() )
1785             {
1786                 if ( pOldRegion )
1787                 {
1788                     Region aNewRegion = *pWinChildClipRegion;
1789                     pWinChildClipRegion->Intersect( *pOldRegion );
1790                     bUpdate = aNewRegion == *pWinChildClipRegion;
1791                 }
1792 
1793                 if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
1794                     ImplInvalidateAllOverlapBackgrounds();
1795 
1796                 Region      aRegion = *pWinChildClipRegion;
1797                 Rectangle   aWinRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
1798                 Region      aWinRectRegion( aWinRect );
1799                 sal_uInt16      nClipFlags = mpWindowImpl->mpSysObj->GetClipRegionType();
1800 
1801                 if ( aRegion == aWinRectRegion )
1802                     mpWindowImpl->mpSysObj->ResetClipRegion();
1803                 else
1804                 {
1805                     if ( nClipFlags & SAL_OBJECT_CLIP_EXCLUDERECTS )
1806                     {
1807                         aWinRectRegion.Exclude( aRegion );
1808                         aRegion = aWinRectRegion;
1809                     }
1810                     if ( !(nClipFlags & SAL_OBJECT_CLIP_ABSOLUTE) )
1811                         aRegion.Move( -mnOutOffX, -mnOutOffY );
1812 
1813                     // ClipRegion setzen/updaten
1814                     long                nX;
1815                     long                nY;
1816                     long                nWidth;
1817                     long                nHeight;
1818                     sal_uLong               nRectCount;
1819                     ImplRegionInfo      aInfo;
1820                     sal_Bool                bRegionRect;
1821 
1822                     nRectCount = aRegion.GetRectCount();
1823                     mpWindowImpl->mpSysObj->BeginSetClipRegion( nRectCount );
1824                     bRegionRect = aRegion.ImplGetFirstRect( aInfo, nX, nY, nWidth, nHeight );
1825                     while ( bRegionRect )
1826                     {
1827                         mpWindowImpl->mpSysObj->UnionClipRegion( nX, nY, nWidth, nHeight );
1828                         bRegionRect = aRegion.ImplGetNextRect( aInfo, nX, nY, nWidth, nHeight );
1829                     }
1830                     mpWindowImpl->mpSysObj->EndSetClipRegion();
1831                 }
1832             }
1833             else
1834                 bVisibleState = sal_False;
1835         }
1836 
1837         // Visible-Status updaten
1838         mpWindowImpl->mpSysObj->Show( bVisibleState );
1839     }
1840 
1841     return bUpdate;
1842 }
1843 
1844 // -----------------------------------------------------------------------
1845 
1846 void Window::ImplUpdateSysObjChildsClip()
1847 {
1848     if ( mpWindowImpl->mpSysObj && mpWindowImpl->mbInitWinClipRegion )
1849         ImplSysObjClip( NULL );
1850 
1851     Window* pWindow = mpWindowImpl->mpFirstChild;
1852     while ( pWindow )
1853     {
1854         pWindow->ImplUpdateSysObjChildsClip();
1855         pWindow = pWindow->mpWindowImpl->mpNext;
1856     }
1857 }
1858 
1859 // -----------------------------------------------------------------------
1860 
1861 void Window::ImplUpdateSysObjOverlapsClip()
1862 {
1863     ImplUpdateSysObjChildsClip();
1864 
1865     Window* pWindow = mpWindowImpl->mpFirstOverlap;
1866     while ( pWindow )
1867     {
1868         pWindow->ImplUpdateSysObjOverlapsClip();
1869         pWindow = pWindow->mpWindowImpl->mpNext;
1870     }
1871 }
1872 
1873 // -----------------------------------------------------------------------
1874 
1875 void Window::ImplUpdateSysObjClip()
1876 {
1877     if ( !ImplIsOverlapWindow() )
1878     {
1879         ImplUpdateSysObjChildsClip();
1880 
1881         // Schwestern muessen ihre ClipRegion auch neu berechnen
1882         if ( mpWindowImpl->mbClipSiblings )
1883         {
1884             Window* pWindow = mpWindowImpl->mpNext;
1885             while ( pWindow )
1886             {
1887                 pWindow->ImplUpdateSysObjChildsClip();
1888                 pWindow = pWindow->mpWindowImpl->mpNext;
1889             }
1890         }
1891     }
1892     else
1893         mpWindowImpl->mpFrameWindow->ImplUpdateSysObjOverlapsClip();
1894 }
1895 
1896 // -----------------------------------------------------------------------
1897 
1898 sal_Bool Window::ImplSetClipFlagChilds( sal_Bool bSysObjOnlySmaller )
1899 {
1900     sal_Bool bUpdate = sal_True;
1901     if ( mpWindowImpl->mpSysObj )
1902     {
1903         Region* pOldRegion = NULL;
1904         if ( bSysObjOnlySmaller && !mpWindowImpl->mbInitWinClipRegion )
1905             pOldRegion = new Region( mpWindowImpl->maWinClipRegion );
1906 
1907         mbInitClipRegion = sal_True;
1908         mpWindowImpl->mbInitWinClipRegion = sal_True;
1909 
1910         Window* pWindow = mpWindowImpl->mpFirstChild;
1911         while ( pWindow )
1912         {
1913             if ( !pWindow->ImplSetClipFlagChilds( bSysObjOnlySmaller ) )
1914                 bUpdate = sal_False;
1915             pWindow = pWindow->mpWindowImpl->mpNext;
1916         }
1917 
1918         if ( !ImplSysObjClip( pOldRegion ) )
1919         {
1920             mbInitClipRegion = sal_True;
1921             mpWindowImpl->mbInitWinClipRegion = sal_True;
1922             bUpdate = sal_False;
1923         }
1924 
1925         if ( pOldRegion )
1926             delete pOldRegion;
1927     }
1928     else
1929     {
1930     mbInitClipRegion = sal_True;
1931     mpWindowImpl->mbInitWinClipRegion = sal_True;
1932 
1933     Window* pWindow = mpWindowImpl->mpFirstChild;
1934     while ( pWindow )
1935     {
1936         if ( !pWindow->ImplSetClipFlagChilds( bSysObjOnlySmaller ) )
1937             bUpdate = sal_False;
1938         pWindow = pWindow->mpWindowImpl->mpNext;
1939     }
1940     }
1941     return bUpdate;
1942 }
1943 
1944 // -----------------------------------------------------------------------
1945 
1946 sal_Bool Window::ImplSetClipFlagOverlapWindows( sal_Bool bSysObjOnlySmaller )
1947 {
1948     sal_Bool bUpdate = ImplSetClipFlagChilds( bSysObjOnlySmaller );
1949 
1950     Window* pWindow = mpWindowImpl->mpFirstOverlap;
1951     while ( pWindow )
1952     {
1953         if ( !pWindow->ImplSetClipFlagOverlapWindows( bSysObjOnlySmaller ) )
1954             bUpdate = sal_False;
1955         pWindow = pWindow->mpWindowImpl->mpNext;
1956     }
1957 
1958     return bUpdate;
1959 }
1960 
1961 // -----------------------------------------------------------------------
1962 
1963 sal_Bool Window::ImplSetClipFlag( sal_Bool bSysObjOnlySmaller )
1964 {
1965     if ( !ImplIsOverlapWindow() )
1966     {
1967         sal_Bool bUpdate = ImplSetClipFlagChilds( bSysObjOnlySmaller );
1968 
1969         Window* pParent = ImplGetParent();
1970         if ( pParent &&
1971              ((pParent->GetStyle() & WB_CLIPCHILDREN) || (mpWindowImpl->mnParentClipMode & PARENTCLIPMODE_CLIP)) )
1972         {
1973             pParent->mbInitClipRegion = sal_True;
1974             pParent->mpWindowImpl->mbInitChildRegion = sal_True;
1975         }
1976 
1977         // Schwestern muessen ihre ClipRegion auch neu berechnen
1978         if ( mpWindowImpl->mbClipSiblings )
1979         {
1980             Window* pWindow = mpWindowImpl->mpNext;
1981             while ( pWindow )
1982             {
1983                 if ( !pWindow->ImplSetClipFlagChilds( bSysObjOnlySmaller ) )
1984                     bUpdate = sal_False;
1985                 pWindow = pWindow->mpWindowImpl->mpNext;
1986             }
1987         }
1988 
1989         return bUpdate;
1990     }
1991     else
1992         return mpWindowImpl->mpFrameWindow->ImplSetClipFlagOverlapWindows( bSysObjOnlySmaller );
1993 }
1994 
1995 // -----------------------------------------------------------------------
1996 
1997 void Window::ImplIntersectWindowClipRegion( Region& rRegion )
1998 {
1999     if ( mpWindowImpl->mbInitWinClipRegion )
2000         ImplInitWinClipRegion();
2001 
2002     rRegion.Intersect( mpWindowImpl->maWinClipRegion );
2003 }
2004 
2005 // -----------------------------------------------------------------------
2006 
2007 void Window::ImplIntersectWindowRegion( Region& rRegion )
2008 {
2009     rRegion.Intersect( Rectangle( Point( mnOutOffX, mnOutOffY ),
2010                                   Size( mnOutWidth, mnOutHeight ) ) );
2011     if ( mpWindowImpl->mbWinRegion )
2012         rRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
2013 }
2014 
2015 // -----------------------------------------------------------------------
2016 
2017 void Window::ImplExcludeWindowRegion( Region& rRegion )
2018 {
2019     if ( mpWindowImpl->mbWinRegion )
2020     {
2021         Point aPoint( mnOutOffX, mnOutOffY );
2022         Region aRegion( Rectangle( aPoint,
2023                                    Size( mnOutWidth, mnOutHeight ) ) );
2024         aRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
2025         rRegion.Exclude( aRegion );
2026     }
2027     else
2028     {
2029         Point aPoint( mnOutOffX, mnOutOffY );
2030         rRegion.Exclude( Rectangle( aPoint,
2031                                     Size( mnOutWidth, mnOutHeight ) ) );
2032     }
2033 }
2034 
2035 // -----------------------------------------------------------------------
2036 
2037 void Window::ImplExcludeOverlapWindows( Region& rRegion )
2038 {
2039     Window* pWindow = mpWindowImpl->mpFirstOverlap;
2040     while ( pWindow )
2041     {
2042         if ( pWindow->mpWindowImpl->mbReallyVisible )
2043         {
2044             pWindow->ImplExcludeWindowRegion( rRegion );
2045             pWindow->ImplExcludeOverlapWindows( rRegion );
2046         }
2047 
2048         pWindow = pWindow->mpWindowImpl->mpNext;
2049     }
2050 }
2051 
2052 // -----------------------------------------------------------------------
2053 
2054 void Window::ImplExcludeOverlapWindows2( Region& rRegion )
2055 {
2056     if ( mpWindowImpl->mbReallyVisible )
2057         ImplExcludeWindowRegion( rRegion );
2058 
2059     ImplExcludeOverlapWindows( rRegion );
2060 }
2061 
2062 // -----------------------------------------------------------------------
2063 
2064 void Window::ImplClipBoundaries( Region& rRegion, sal_Bool bThis, sal_Bool bOverlaps )
2065 {
2066     if ( bThis )
2067         ImplIntersectWindowClipRegion( rRegion );
2068     else if ( ImplIsOverlapWindow() )
2069     {
2070         // Evt. noch am Frame clippen
2071         if ( !mpWindowImpl->mbFrame )
2072             rRegion.Intersect( Rectangle( Point( 0, 0 ), Size( mpWindowImpl->mpFrameWindow->mnOutWidth, mpWindowImpl->mpFrameWindow->mnOutHeight ) ) );
2073 
2074         if ( bOverlaps && !rRegion.IsEmpty() )
2075         {
2076             // Clip Overlap Siblings
2077             Window* pStartOverlapWindow = this;
2078             while ( !pStartOverlapWindow->mpWindowImpl->mbFrame )
2079             {
2080                 Window* pOverlapWindow = pStartOverlapWindow->mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap;
2081                 while ( pOverlapWindow && (pOverlapWindow != pStartOverlapWindow) )
2082                 {
2083                     pOverlapWindow->ImplExcludeOverlapWindows2( rRegion );
2084                     pOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
2085                 }
2086                 pStartOverlapWindow = pStartOverlapWindow->mpWindowImpl->mpOverlapWindow;
2087             }
2088 
2089             // Clip Child Overlap Windows
2090             ImplExcludeOverlapWindows( rRegion );
2091         }
2092     }
2093     else
2094         ImplGetParent()->ImplIntersectWindowClipRegion( rRegion );
2095 }
2096 
2097 // -----------------------------------------------------------------------
2098 
2099 sal_Bool Window::ImplClipChilds( Region& rRegion )
2100 {
2101     sal_Bool    bOtherClip = sal_False;
2102     Window* pWindow = mpWindowImpl->mpFirstChild;
2103     while ( pWindow )
2104     {
2105         if ( pWindow->mpWindowImpl->mbReallyVisible )
2106         {
2107             // ParentClipMode-Flags auswerten
2108             sal_uInt16 nClipMode = pWindow->GetParentClipMode();
2109             if ( !(nClipMode & PARENTCLIPMODE_NOCLIP) &&
2110                  ((nClipMode & PARENTCLIPMODE_CLIP) || (GetStyle() & WB_CLIPCHILDREN)) )
2111                 pWindow->ImplExcludeWindowRegion( rRegion );
2112             else
2113                 bOtherClip = sal_True;
2114         }
2115 
2116         pWindow = pWindow->mpWindowImpl->mpNext;
2117     }
2118 
2119     return bOtherClip;
2120 }
2121 
2122 // -----------------------------------------------------------------------
2123 
2124 void Window::ImplClipAllChilds( Region& rRegion )
2125 {
2126     Window* pWindow = mpWindowImpl->mpFirstChild;
2127     while ( pWindow )
2128     {
2129         if ( pWindow->mpWindowImpl->mbReallyVisible )
2130             pWindow->ImplExcludeWindowRegion( rRegion );
2131         pWindow = pWindow->mpWindowImpl->mpNext;
2132     }
2133 }
2134 
2135 // -----------------------------------------------------------------------
2136 
2137 void Window::ImplClipSiblings( Region& rRegion )
2138 {
2139     Window* pWindow = ImplGetParent()->mpWindowImpl->mpFirstChild;
2140     while ( pWindow )
2141     {
2142         if ( pWindow == this )
2143             break;
2144 
2145         if ( pWindow->mpWindowImpl->mbReallyVisible )
2146             pWindow->ImplExcludeWindowRegion( rRegion );
2147 
2148         pWindow = pWindow->mpWindowImpl->mpNext;
2149     }
2150 }
2151 
2152 // -----------------------------------------------------------------------
2153 
2154 void Window::ImplInitWinClipRegion()
2155 {
2156     // Build Window Region
2157     mpWindowImpl->maWinClipRegion = Rectangle( Point( mnOutOffX, mnOutOffY ),
2158                                  Size( mnOutWidth, mnOutHeight ) );
2159     if ( mpWindowImpl->mbWinRegion )
2160         mpWindowImpl->maWinClipRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
2161 
2162     // ClipSiblings
2163     if ( mpWindowImpl->mbClipSiblings && !ImplIsOverlapWindow() )
2164         ImplClipSiblings( mpWindowImpl->maWinClipRegion );
2165 
2166     // Clip Parent Boundaries
2167     ImplClipBoundaries( mpWindowImpl->maWinClipRegion, sal_False, sal_True );
2168 
2169     // Clip Children
2170     if ( (GetStyle() & WB_CLIPCHILDREN) || mpWindowImpl->mbClipChildren )
2171         mpWindowImpl->mbInitChildRegion = sal_True;
2172 
2173     mpWindowImpl->mbInitWinClipRegion = sal_False;
2174 }
2175 
2176 // -----------------------------------------------------------------------
2177 
2178 void Window::ImplInitWinChildClipRegion()
2179 {
2180     if ( !mpWindowImpl->mpFirstChild )
2181     {
2182         if ( mpWindowImpl->mpChildClipRegion )
2183         {
2184             delete mpWindowImpl->mpChildClipRegion;
2185             mpWindowImpl->mpChildClipRegion = NULL;
2186         }
2187     }
2188     else
2189     {
2190         if ( !mpWindowImpl->mpChildClipRegion )
2191             mpWindowImpl->mpChildClipRegion = new Region( mpWindowImpl->maWinClipRegion );
2192         else
2193             *mpWindowImpl->mpChildClipRegion = mpWindowImpl->maWinClipRegion;
2194 
2195         ImplClipChilds( *mpWindowImpl->mpChildClipRegion );
2196     }
2197 
2198     mpWindowImpl->mbInitChildRegion = sal_False;
2199 }
2200 
2201 // -----------------------------------------------------------------------
2202 
2203 Region* Window::ImplGetWinChildClipRegion()
2204 {
2205     if ( mpWindowImpl->mbInitWinClipRegion )
2206         ImplInitWinClipRegion();
2207     if ( mpWindowImpl->mbInitChildRegion )
2208         ImplInitWinChildClipRegion();
2209     if ( mpWindowImpl->mpChildClipRegion )
2210         return mpWindowImpl->mpChildClipRegion;
2211     else
2212         return &mpWindowImpl->maWinClipRegion;
2213 }
2214 
2215 // -----------------------------------------------------------------------
2216 
2217 void Window::ImplIntersectAndUnionOverlapWindows( const Region& rInterRegion, Region& rRegion )
2218 {
2219     Window* pWindow = mpWindowImpl->mpFirstOverlap;
2220     while ( pWindow )
2221     {
2222         if ( pWindow->mpWindowImpl->mbReallyVisible )
2223         {
2224             Region aTempRegion( rInterRegion );
2225             pWindow->ImplIntersectWindowRegion( aTempRegion );
2226             rRegion.Union( aTempRegion );
2227             pWindow->ImplIntersectAndUnionOverlapWindows( rInterRegion, rRegion );
2228         }
2229 
2230         pWindow = pWindow->mpWindowImpl->mpNext;
2231     }
2232 }
2233 
2234 // -----------------------------------------------------------------------
2235 
2236 void Window::ImplIntersectAndUnionOverlapWindows2( const Region& rInterRegion, Region& rRegion )
2237 {
2238     if ( mpWindowImpl->mbReallyVisible )
2239     {
2240         Region aTempRegion( rInterRegion );
2241         ImplIntersectWindowRegion( aTempRegion );
2242         rRegion.Union( aTempRegion );
2243     }
2244 
2245     ImplIntersectAndUnionOverlapWindows( rInterRegion, rRegion );
2246 }
2247 
2248 // -----------------------------------------------------------------------
2249 
2250 void Window::ImplCalcOverlapRegionOverlaps( const Region& rInterRegion, Region& rRegion )
2251 {
2252     // Clip Overlap Siblings
2253     Window* pStartOverlapWindow;
2254     if ( !ImplIsOverlapWindow() )
2255         pStartOverlapWindow = mpWindowImpl->mpOverlapWindow;
2256     else
2257         pStartOverlapWindow = this;
2258     while ( !pStartOverlapWindow->mpWindowImpl->mbFrame )
2259     {
2260         Window* pOverlapWindow = pStartOverlapWindow->mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap;
2261         while ( pOverlapWindow && (pOverlapWindow != pStartOverlapWindow) )
2262         {
2263             pOverlapWindow->ImplIntersectAndUnionOverlapWindows2( rInterRegion, rRegion );
2264             pOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
2265         }
2266         pStartOverlapWindow = pStartOverlapWindow->mpWindowImpl->mpOverlapWindow;
2267     }
2268 
2269     // Clip Child Overlap Windows
2270     if ( !ImplIsOverlapWindow() )
2271         mpWindowImpl->mpOverlapWindow->ImplIntersectAndUnionOverlapWindows( rInterRegion, rRegion );
2272     else
2273         ImplIntersectAndUnionOverlapWindows( rInterRegion, rRegion );
2274 }
2275 
2276 // -----------------------------------------------------------------------
2277 
2278 void Window::ImplCalcOverlapRegion( const Rectangle& rSourceRect, Region& rRegion,
2279                                     sal_Bool bChilds, sal_Bool bParent, sal_Bool bSiblings )
2280 {
2281     Region  aRegion( rSourceRect );
2282     if ( mpWindowImpl->mbWinRegion )
2283         rRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
2284     Region  aTempRegion;
2285     Window* pWindow;
2286 
2287     ImplCalcOverlapRegionOverlaps( aRegion, rRegion );
2288 
2289     // Parent-Boundaries
2290     if ( bParent )
2291     {
2292         pWindow = this;
2293         if ( !ImplIsOverlapWindow() )
2294         {
2295             pWindow = ImplGetParent();
2296             do
2297             {
2298                 aTempRegion = aRegion;
2299                 pWindow->ImplExcludeWindowRegion( aTempRegion );
2300                 rRegion.Union( aTempRegion );
2301                 if ( pWindow->ImplIsOverlapWindow() )
2302                     break;
2303                 pWindow = pWindow->ImplGetParent();
2304             }
2305             while ( pWindow );
2306         }
2307         if ( !pWindow->mpWindowImpl->mbFrame )
2308         {
2309             aTempRegion = aRegion;
2310             aTempRegion.Exclude( Rectangle( Point( 0, 0 ), Size( mpWindowImpl->mpFrameWindow->mnOutWidth, mpWindowImpl->mpFrameWindow->mnOutHeight ) ) );
2311             rRegion.Union( aTempRegion );
2312         }
2313     }
2314 
2315     // Siblings
2316     if ( bSiblings && !ImplIsOverlapWindow() )
2317     {
2318         pWindow = mpWindowImpl->mpParent->mpWindowImpl->mpFirstChild;
2319         do
2320         {
2321             if ( pWindow->mpWindowImpl->mbReallyVisible && (pWindow != this) )
2322             {
2323                 aTempRegion = aRegion;
2324                 pWindow->ImplIntersectWindowRegion( aTempRegion );
2325                 rRegion.Union( aTempRegion );
2326             }
2327             pWindow = pWindow->mpWindowImpl->mpNext;
2328         }
2329         while ( pWindow );
2330     }
2331 
2332     // Childs
2333     if ( bChilds )
2334     {
2335         pWindow = mpWindowImpl->mpFirstChild;
2336         while ( pWindow )
2337         {
2338             if ( pWindow->mpWindowImpl->mbReallyVisible )
2339             {
2340                 aTempRegion = aRegion;
2341                 pWindow->ImplIntersectWindowRegion( aTempRegion );
2342                 rRegion.Union( aTempRegion );
2343             }
2344             pWindow = pWindow->mpWindowImpl->mpNext;
2345         }
2346     }
2347 }
2348 
2349 // -----------------------------------------------------------------------
2350 
2351 void Window::ImplCallPaint( const Region* pRegion, sal_uInt16 nPaintFlags )
2352 {
2353     // call PrePaint. PrePaint may add to the invalidate region as well as
2354     // other parameters used below.
2355     PrePaint();
2356 
2357     mpWindowImpl->mbPaintFrame = sal_False;
2358 
2359     if ( nPaintFlags & IMPL_PAINT_PAINTALLCHILDS )
2360         mpWindowImpl->mnPaintFlags |= IMPL_PAINT_PAINT | IMPL_PAINT_PAINTALLCHILDS | (nPaintFlags & IMPL_PAINT_PAINTALL);
2361     if ( nPaintFlags & IMPL_PAINT_PAINTCHILDS )
2362         mpWindowImpl->mnPaintFlags |= IMPL_PAINT_PAINTCHILDS;
2363     if ( nPaintFlags & IMPL_PAINT_ERASE )
2364         mpWindowImpl->mnPaintFlags |= IMPL_PAINT_ERASE;
2365     if ( nPaintFlags & IMPL_PAINT_CHECKRTL )
2366         mpWindowImpl->mnPaintFlags |= IMPL_PAINT_CHECKRTL;
2367     if ( !mpWindowImpl->mpFirstChild )
2368         mpWindowImpl->mnPaintFlags &= ~IMPL_PAINT_PAINTALLCHILDS;
2369 
2370     if ( mpWindowImpl->mbPaintDisabled )
2371     {
2372         if ( mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALL )
2373             Invalidate( INVALIDATE_NOCHILDREN | INVALIDATE_NOERASE | INVALIDATE_NOTRANSPARENT | INVALIDATE_NOCLIPCHILDREN );
2374         else if ( pRegion )
2375             Invalidate( *pRegion, INVALIDATE_NOCHILDREN | INVALIDATE_NOERASE | INVALIDATE_NOTRANSPARENT | INVALIDATE_NOCLIPCHILDREN );
2376         return;
2377     }
2378 
2379     nPaintFlags = mpWindowImpl->mnPaintFlags & ~(IMPL_PAINT_PAINT);
2380 
2381     Region* pChildRegion = NULL;
2382     Rectangle aSelectionRect;
2383     if ( mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINT )
2384     {
2385         Region* pWinChildClipRegion = ImplGetWinChildClipRegion();
2386         if ( mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALL )
2387             mpWindowImpl->maInvalidateRegion = *pWinChildClipRegion;
2388         else
2389         {
2390             if ( pRegion )
2391                 mpWindowImpl->maInvalidateRegion.Union( *pRegion );
2392 
2393             if( mpWindowImpl->mpWinData && mpWindowImpl->mbTrackVisible )
2394                 /* #98602# need to repaint all children within the
2395                * tracking rectangle, so the following invert
2396                * operation takes places without traces of the previous
2397                * one.
2398                */
2399                 mpWindowImpl->maInvalidateRegion.Union( *mpWindowImpl->mpWinData->mpTrackRect );
2400 
2401             if ( mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALLCHILDS )
2402                 pChildRegion = new Region( mpWindowImpl->maInvalidateRegion );
2403             mpWindowImpl->maInvalidateRegion.Intersect( *pWinChildClipRegion );
2404         }
2405         mpWindowImpl->mnPaintFlags = 0;
2406         if ( !mpWindowImpl->maInvalidateRegion.IsEmpty() )
2407         {
2408             bool bRestoreCursor = false;
2409             if ( mpWindowImpl->mpCursor )
2410                 bRestoreCursor = mpWindowImpl->mpCursor->ImplHide( false );
2411 
2412             mbInitClipRegion = sal_True;
2413             mpWindowImpl->mbInPaint = sal_True;
2414 
2415             // Paint-Region zuruecksetzen
2416             Region      aPaintRegion( mpWindowImpl->maInvalidateRegion );
2417             Rectangle   aPaintRect = aPaintRegion.GetBoundRect();
2418 
2419             // - RTL - re-mirror paint rect and region at this window
2420 		    if( ImplIsAntiparallel() )
2421             {
2422                 ImplReMirror( aPaintRect );
2423                 ImplReMirror( aPaintRegion );
2424             }
2425             aPaintRect = ImplDevicePixelToLogic( aPaintRect);
2426             mpWindowImpl->mpPaintRegion = &aPaintRegion;
2427             mpWindowImpl->maInvalidateRegion.SetEmpty();
2428 
2429             if ( (nPaintFlags & IMPL_PAINT_ERASE) && IsBackground() )
2430             {
2431                 if ( IsClipRegion() )
2432                 {
2433                     Region aOldRegion = GetClipRegion();
2434                     SetClipRegion();
2435                     Erase();
2436                     SetClipRegion( aOldRegion );
2437                 }
2438                 else
2439                     Erase();
2440             }
2441 
2442             // #98943# trigger drawing of toolbox selection after all childern are painted
2443             if( mpWindowImpl->mbDrawSelectionBackground )
2444                 aSelectionRect = aPaintRect;
2445 
2446             Paint( aPaintRect );
2447 
2448             if ( mpWindowImpl->mpWinData )
2449             {
2450                 if ( mpWindowImpl->mbFocusVisible )
2451                     ImplInvertFocus( *(mpWindowImpl->mpWinData->mpFocusRect) );
2452             }
2453             mpWindowImpl->mbInPaint = sal_False;
2454             mbInitClipRegion = sal_True;
2455             mpWindowImpl->mpPaintRegion = NULL;
2456             if ( mpWindowImpl->mpCursor )
2457                 mpWindowImpl->mpCursor->ImplShow( false, bRestoreCursor );
2458         }
2459     }
2460     else
2461         mpWindowImpl->mnPaintFlags = 0;
2462 
2463     if ( nPaintFlags & (IMPL_PAINT_PAINTALLCHILDS | IMPL_PAINT_PAINTCHILDS) )
2464     {
2465         // die Childfenster ausgeben
2466         Window* pTempWindow = mpWindowImpl->mpFirstChild;
2467         while ( pTempWindow )
2468         {
2469             if ( pTempWindow->mpWindowImpl->mbVisible )
2470                 pTempWindow->ImplCallPaint( pChildRegion, nPaintFlags );
2471             pTempWindow = pTempWindow->mpWindowImpl->mpNext;
2472         }
2473     }
2474 
2475     if ( mpWindowImpl->mpWinData && mpWindowImpl->mbTrackVisible && (mpWindowImpl->mpWinData->mnTrackFlags & SHOWTRACK_WINDOW) )
2476         /* #98602# need to invert the tracking rect AFTER
2477         * the children have painted
2478         */
2479         InvertTracking( *(mpWindowImpl->mpWinData->mpTrackRect), mpWindowImpl->mpWinData->mnTrackFlags );
2480 
2481     // #98943# draw toolbox selection
2482     if( !aSelectionRect.IsEmpty() )
2483         DrawSelectionBackground( aSelectionRect, 3, sal_False, sal_True, sal_False );
2484 
2485     if ( pChildRegion )
2486         delete pChildRegion;
2487 }
2488 
2489 // -----------------------------------------------------------------------
2490 
2491 void Window::ImplCallOverlapPaint()
2492 {
2493     // Zuerst geben wir die ueberlappenden Fenster aus
2494     Window* pTempWindow = mpWindowImpl->mpFirstOverlap;
2495     while ( pTempWindow )
2496     {
2497         if ( pTempWindow->mpWindowImpl->mbReallyVisible )
2498             pTempWindow->ImplCallOverlapPaint();
2499         pTempWindow = pTempWindow->mpWindowImpl->mpNext;
2500     }
2501 
2502     // und dann erst uns selber
2503     if ( mpWindowImpl->mnPaintFlags & (IMPL_PAINT_PAINT | IMPL_PAINT_PAINTCHILDS) )
2504     {
2505         // - RTL - notify ImplCallPaint to check for re-mirroring (CHECKRTL)
2506         //         because we were called from the Sal layer
2507         ImplCallPaint( NULL, mpWindowImpl->mnPaintFlags /*| IMPL_PAINT_CHECKRTL */);
2508     }
2509 }
2510 
2511 // -----------------------------------------------------------------------
2512 
2513 void Window::ImplPostPaint()
2514 {
2515 	if ( !mpWindowImpl->mpFrameData->maPaintTimer.IsActive() )
2516 		mpWindowImpl->mpFrameData->maPaintTimer.Start();
2517 }
2518 
2519 // -----------------------------------------------------------------------
2520 
2521 IMPL_LINK( Window, ImplHandlePaintHdl, void*, EMPTYARG )
2522 {
2523     // save paint events until resizing is done
2524     if( mpWindowImpl->mbFrame && mpWindowImpl->mpFrameData->maResizeTimer.IsActive() )
2525         mpWindowImpl->mpFrameData->maPaintTimer.Start();
2526     else if ( mpWindowImpl->mbReallyVisible )
2527         ImplCallOverlapPaint();
2528     return 0;
2529 }
2530 
2531 // -----------------------------------------------------------------------
2532 
2533 IMPL_LINK( Window, ImplHandleResizeTimerHdl, void*, EMPTYARG )
2534 {
2535     if( mpWindowImpl->mbReallyVisible )
2536     {
2537         ImplCallResize();
2538         if( mpWindowImpl->mpFrameData->maPaintTimer.IsActive() )
2539         {
2540             mpWindowImpl->mpFrameData->maPaintTimer.Stop();
2541             mpWindowImpl->mpFrameData->maPaintTimer.GetTimeoutHdl().Call( NULL );
2542         }
2543     }
2544 
2545     return 0;
2546 }
2547 
2548 // -----------------------------------------------------------------------
2549 
2550 void Window::ImplInvalidateFrameRegion( const Region* pRegion, sal_uInt16 nFlags )
2551 {
2552     // PAINTCHILDS bei allen Parent-Fenster bis zum ersten OverlapWindow
2553     // setzen
2554     if ( !ImplIsOverlapWindow() )
2555     {
2556         Window* pTempWindow = this;
2557         sal_uInt16 nTranspPaint = IsPaintTransparent() ? IMPL_PAINT_PAINT : 0;
2558         do
2559         {
2560             pTempWindow = pTempWindow->ImplGetParent();
2561             if ( pTempWindow->mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTCHILDS )
2562                 break;
2563             pTempWindow->mpWindowImpl->mnPaintFlags |= IMPL_PAINT_PAINTCHILDS | nTranspPaint;
2564             if( ! pTempWindow->IsPaintTransparent() )
2565                 nTranspPaint = 0;
2566         }
2567         while ( !pTempWindow->ImplIsOverlapWindow() );
2568     }
2569 
2570     // Paint-Flags setzen
2571     mpWindowImpl->mnPaintFlags |= IMPL_PAINT_PAINT;
2572     if ( nFlags & INVALIDATE_CHILDREN )
2573         mpWindowImpl->mnPaintFlags |= IMPL_PAINT_PAINTALLCHILDS;
2574     if ( !(nFlags & INVALIDATE_NOERASE) )
2575         mpWindowImpl->mnPaintFlags |= IMPL_PAINT_ERASE;
2576     if ( !pRegion )
2577         mpWindowImpl->mnPaintFlags |= IMPL_PAINT_PAINTALL;
2578 
2579     // Wenn nicht alles neu ausgegeben werden muss, dann die Region
2580     // dazupacken
2581     if ( !(mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALL) )
2582         mpWindowImpl->maInvalidateRegion.Union( *pRegion );
2583 
2584     // Handle transparent windows correctly: invalidate must be done on the first opaque parent
2585     if( ((IsPaintTransparent() && !(nFlags & INVALIDATE_NOTRANSPARENT)) || (nFlags & INVALIDATE_TRANSPARENT) )
2586             && ImplGetParent() )
2587     {
2588         Window *pParent = ImplGetParent();
2589         while( pParent && pParent->IsPaintTransparent() )
2590             pParent = pParent->ImplGetParent();
2591         if( pParent )
2592         {
2593             Region *pChildRegion;
2594             if ( mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALL )
2595                 // invalidate the whole child window region in the parent
2596                 pChildRegion = ImplGetWinChildClipRegion();
2597             else
2598                 // invalidate the same region in the parent that has to be repainted in the child
2599                 pChildRegion = &mpWindowImpl->maInvalidateRegion;
2600 
2601             nFlags |= INVALIDATE_CHILDREN;  // paint should also be done on all children
2602             nFlags &= ~INVALIDATE_NOERASE;  // parent should paint and erase to create proper background
2603             pParent->ImplInvalidateFrameRegion( pChildRegion, nFlags );
2604         }
2605     }
2606     ImplPostPaint();
2607 }
2608 
2609 // -----------------------------------------------------------------------
2610 
2611 void Window::ImplInvalidateOverlapFrameRegion( const Region& rRegion )
2612 {
2613     Region aRegion = rRegion;
2614 
2615     ImplClipBoundaries( aRegion, sal_True, sal_True );
2616     if ( !aRegion.IsEmpty() )
2617         ImplInvalidateFrameRegion( &aRegion, INVALIDATE_CHILDREN );
2618 
2619     // Dann invalidieren wir die ueberlappenden Fenster
2620     Window* pTempWindow = mpWindowImpl->mpFirstOverlap;
2621     while ( pTempWindow )
2622     {
2623         if ( pTempWindow->IsVisible() )
2624             pTempWindow->ImplInvalidateOverlapFrameRegion( rRegion );
2625 
2626         pTempWindow = pTempWindow->mpWindowImpl->mpNext;
2627     }
2628 }
2629 
2630 // -----------------------------------------------------------------------
2631 
2632 void Window::ImplInvalidateParentFrameRegion( Region& rRegion )
2633 {
2634     if ( mpWindowImpl->mbOverlapWin )
2635         mpWindowImpl->mpFrameWindow->ImplInvalidateOverlapFrameRegion( rRegion );
2636     else
2637     {
2638         if( ImplGetParent() )
2639             ImplGetParent()->ImplInvalidateFrameRegion( &rRegion, INVALIDATE_CHILDREN );
2640     }
2641 }
2642 
2643 // -----------------------------------------------------------------------
2644 
2645 void Window::ImplInvalidate( const Region* pRegion, sal_uInt16 nFlags )
2646 {
2647 
2648     // Hintergrund-Sicherung zuruecksetzen
2649     if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
2650         ImplInvalidateAllOverlapBackgrounds();
2651 
2652     // Feststellen, was neu ausgegeben werden muss
2653     sal_Bool bInvalidateAll = !pRegion;
2654 
2655     // Transparent-Invalidate beruecksichtigen
2656     Window* pOpaqueWindow = this;
2657     if ( (mpWindowImpl->mbPaintTransparent && !(nFlags & INVALIDATE_NOTRANSPARENT)) || (nFlags & INVALIDATE_TRANSPARENT) )
2658     {
2659         Window* pTempWindow = pOpaqueWindow->ImplGetParent();
2660         while ( pTempWindow )
2661         {
2662             if ( !pTempWindow->IsPaintTransparent() )
2663             {
2664                 pOpaqueWindow = pTempWindow;
2665                 nFlags |= INVALIDATE_CHILDREN;
2666                 bInvalidateAll = sal_False;
2667                 break;
2668             }
2669 
2670             if ( pTempWindow->ImplIsOverlapWindow() )
2671                 break;
2672 
2673             pTempWindow = pTempWindow->ImplGetParent();
2674         }
2675     }
2676 
2677     // Region zusammenbauen
2678     sal_uInt16 nOrgFlags = nFlags;
2679     if ( !(nFlags & (INVALIDATE_CHILDREN | INVALIDATE_NOCHILDREN)) )
2680     {
2681         if ( GetStyle() & WB_CLIPCHILDREN )
2682             nFlags |= INVALIDATE_NOCHILDREN;
2683         else
2684             nFlags |= INVALIDATE_CHILDREN;
2685     }
2686     if ( (nFlags & INVALIDATE_NOCHILDREN) && mpWindowImpl->mpFirstChild )
2687         bInvalidateAll = sal_False;
2688     if ( bInvalidateAll )
2689         ImplInvalidateFrameRegion( NULL, nFlags );
2690     else
2691     {
2692         Rectangle   aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
2693         Region      aRegion( aRect );
2694         if ( pRegion )
2695         {
2696             // --- RTL --- remirror region before intersecting it
2697             if ( ImplIsAntiparallel() )
2698             {
2699                 Region aRgn( *pRegion );
2700                 ImplReMirror( aRgn );
2701                 aRegion.Intersect( aRgn );
2702             }
2703             else
2704                 aRegion.Intersect( *pRegion );
2705         }
2706         ImplClipBoundaries( aRegion, sal_True, sal_True );
2707         if ( nFlags & INVALIDATE_NOCHILDREN )
2708         {
2709             nFlags &= ~INVALIDATE_CHILDREN;
2710             if ( !(nFlags & INVALIDATE_NOCLIPCHILDREN) )
2711             {
2712                 if ( nOrgFlags & INVALIDATE_NOCHILDREN )
2713                     ImplClipAllChilds( aRegion );
2714                 else
2715                 {
2716                     if ( ImplClipChilds( aRegion ) )
2717                         nFlags |= INVALIDATE_CHILDREN;
2718                 }
2719             }
2720         }
2721         if ( !aRegion.IsEmpty() )
2722             ImplInvalidateFrameRegion( &aRegion, nFlags );  // transparency is handled here, pOpaqueWindow not required
2723     }
2724 
2725     if ( nFlags & INVALIDATE_UPDATE )
2726         pOpaqueWindow->Update();        // start painting at the opaque parent
2727 }
2728 
2729 // -----------------------------------------------------------------------
2730 
2731 void Window::ImplMoveInvalidateRegion( const Rectangle& rRect,
2732                                        long nHorzScroll, long nVertScroll,
2733                                        sal_Bool bChilds )
2734 {
2735     if ( (mpWindowImpl->mnPaintFlags & (IMPL_PAINT_PAINT | IMPL_PAINT_PAINTALL)) == IMPL_PAINT_PAINT )
2736     {
2737         Region aTempRegion = mpWindowImpl->maInvalidateRegion;
2738         aTempRegion.Intersect( rRect );
2739         aTempRegion.Move( nHorzScroll, nVertScroll );
2740         mpWindowImpl->maInvalidateRegion.Union( aTempRegion );
2741     }
2742 
2743     if ( bChilds && (mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTCHILDS) )
2744     {
2745         Window* pWindow = mpWindowImpl->mpFirstChild;
2746         while ( pWindow )
2747         {
2748             pWindow->ImplMoveInvalidateRegion( rRect, nHorzScroll, nVertScroll, sal_True );
2749             pWindow = pWindow->mpWindowImpl->mpNext;
2750         }
2751     }
2752 }
2753 
2754 // -----------------------------------------------------------------------
2755 
2756 void Window::ImplMoveAllInvalidateRegions( const Rectangle& rRect,
2757                                            long nHorzScroll, long nVertScroll,
2758                                            sal_Bool bChilds )
2759 {
2760     // Paint-Region auch verschieben, wenn noch Paints anstehen
2761     ImplMoveInvalidateRegion( rRect, nHorzScroll, nVertScroll, bChilds );
2762     // Paint-Region muss bei uns verschoben gesetzt werden, die durch
2763     // die Parents gezeichnet werden
2764     if ( !ImplIsOverlapWindow() )
2765     {
2766         Region  aPaintAllRegion;
2767         Window* pPaintAllWindow = this;
2768         do
2769         {
2770             pPaintAllWindow = pPaintAllWindow->ImplGetParent();
2771             if ( pPaintAllWindow->mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALLCHILDS )
2772             {
2773                 if ( pPaintAllWindow->mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALL )
2774                 {
2775                     aPaintAllRegion.SetEmpty();
2776                     break;
2777                 }
2778                 else
2779                     aPaintAllRegion.Union( pPaintAllWindow->mpWindowImpl->maInvalidateRegion );
2780             }
2781         }
2782         while ( !pPaintAllWindow->ImplIsOverlapWindow() );
2783         if ( !aPaintAllRegion.IsEmpty() )
2784         {
2785             aPaintAllRegion.Move( nHorzScroll, nVertScroll );
2786             sal_uInt16 nPaintFlags = 0;
2787             if ( bChilds )
2788                 mpWindowImpl->mnPaintFlags |= INVALIDATE_CHILDREN;
2789             ImplInvalidateFrameRegion( &aPaintAllRegion, nPaintFlags );
2790         }
2791     }
2792 }
2793 
2794 // -----------------------------------------------------------------------
2795 
2796 void Window::ImplValidateFrameRegion( const Region* pRegion, sal_uInt16 nFlags )
2797 {
2798     if ( !pRegion )
2799         mpWindowImpl->maInvalidateRegion.SetEmpty();
2800     else
2801     {
2802         // Wenn alle Childfenster neu ausgegeben werden muessen,
2803         // dann invalidieren wir diese vorher
2804         if ( (mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALLCHILDS) && mpWindowImpl->mpFirstChild )
2805         {
2806             Region aChildRegion = mpWindowImpl->maInvalidateRegion;
2807             if ( mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALL )
2808             {
2809                 Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
2810                 aChildRegion = aRect;
2811             }
2812             Window* pChild = mpWindowImpl->mpFirstChild;
2813             while ( pChild )
2814             {
2815                 pChild->Invalidate( aChildRegion, INVALIDATE_CHILDREN | INVALIDATE_NOTRANSPARENT );
2816                 pChild = pChild->mpWindowImpl->mpNext;
2817             }
2818         }
2819         if ( mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALL )
2820         {
2821             Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
2822             mpWindowImpl->maInvalidateRegion = aRect;
2823         }
2824         mpWindowImpl->maInvalidateRegion.Exclude( *pRegion );
2825     }
2826     mpWindowImpl->mnPaintFlags &= ~IMPL_PAINT_PAINTALL;
2827 
2828     if ( nFlags & VALIDATE_CHILDREN )
2829     {
2830         Window* pChild = mpWindowImpl->mpFirstChild;
2831         while ( pChild )
2832         {
2833             pChild->ImplValidateFrameRegion( pRegion, nFlags );
2834             pChild = pChild->mpWindowImpl->mpNext;
2835         }
2836     }
2837 }
2838 
2839 // -----------------------------------------------------------------------
2840 
2841 void Window::ImplValidate( const Region* pRegion, sal_uInt16 nFlags )
2842 {
2843     // Region zusammenbauen
2844     sal_Bool    bValidateAll = !pRegion;
2845     sal_uInt16  nOrgFlags = nFlags;
2846     if ( !(nFlags & (VALIDATE_CHILDREN | VALIDATE_NOCHILDREN)) )
2847     {
2848         if ( GetStyle() & WB_CLIPCHILDREN )
2849             nFlags |= VALIDATE_NOCHILDREN;
2850         else
2851             nFlags |= VALIDATE_CHILDREN;
2852     }
2853     if ( (nFlags & VALIDATE_NOCHILDREN) && mpWindowImpl->mpFirstChild )
2854         bValidateAll = sal_False;
2855     if ( bValidateAll )
2856         ImplValidateFrameRegion( NULL, nFlags );
2857     else
2858     {
2859         Rectangle   aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
2860         Region      aRegion( aRect );
2861         if ( pRegion )
2862             aRegion.Intersect( *pRegion );
2863         ImplClipBoundaries( aRegion, sal_True, sal_True );
2864         if ( nFlags & VALIDATE_NOCHILDREN )
2865         {
2866             nFlags &= ~VALIDATE_CHILDREN;
2867             if ( nOrgFlags & VALIDATE_NOCHILDREN )
2868                 ImplClipAllChilds( aRegion );
2869             else
2870             {
2871                 if ( ImplClipChilds( aRegion ) )
2872                     nFlags |= VALIDATE_CHILDREN;
2873             }
2874         }
2875         if ( !aRegion.IsEmpty() )
2876             ImplValidateFrameRegion( &aRegion, nFlags );
2877     }
2878 }
2879 
2880 // -----------------------------------------------------------------------
2881 
2882 void Window::ImplScroll( const Rectangle& rRect,
2883                          long nHorzScroll, long nVertScroll, sal_uInt16 nFlags )
2884 {
2885     if ( !IsDeviceOutputNecessary() )
2886         return;
2887 
2888     nHorzScroll = ImplLogicWidthToDevicePixel( nHorzScroll );
2889     nVertScroll = ImplLogicHeightToDevicePixel( nVertScroll );
2890 
2891     if ( !nHorzScroll && !nVertScroll )
2892         return;
2893 
2894     // Hintergrund-Sicherung zuruecksetzen
2895     if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
2896         ImplInvalidateAllOverlapBackgrounds();
2897 
2898     if ( mpWindowImpl->mpCursor )
2899         mpWindowImpl->mpCursor->ImplHide( false );
2900 
2901     sal_uInt16 nOrgFlags = nFlags;
2902     if ( !(nFlags & (SCROLL_CHILDREN | SCROLL_NOCHILDREN)) )
2903     {
2904         if ( GetStyle() & WB_CLIPCHILDREN )
2905             nFlags |= SCROLL_NOCHILDREN;
2906         else
2907             nFlags |= SCROLL_CHILDREN;
2908     }
2909 
2910     Region  aInvalidateRegion;
2911     sal_Bool    bScrollChilds = (nFlags & SCROLL_CHILDREN) != 0;
2912     sal_Bool    bErase = (nFlags & SCROLL_NOERASE) == 0;
2913 
2914     if ( !mpWindowImpl->mpFirstChild )
2915         bScrollChilds = sal_False;
2916 
2917     // --- RTL --- check if this window requires special action
2918     sal_Bool bReMirror = ( ImplIsAntiparallel() );
2919 
2920     Rectangle aRectMirror( rRect );
2921     if( bReMirror )
2922     {
2923         // --- RTL --- make sure the invalidate region of this window is
2924         // computed in the same coordinate space as the one from the overlap windows
2925         ImplReMirror( aRectMirror );
2926     }
2927 
2928     // Paint-Bereiche anpassen
2929     ImplMoveAllInvalidateRegions( aRectMirror, nHorzScroll, nVertScroll, bScrollChilds );
2930 
2931     if ( !(nFlags & SCROLL_NOINVALIDATE) )
2932     {
2933         ImplCalcOverlapRegion( aRectMirror, aInvalidateRegion, !bScrollChilds, sal_True, sal_False );
2934 
2935         // --- RTL ---
2936         // if the scrolling on the device is performed in the opposite direction
2937         // then move the overlaps in that direction to compute the invalidate region
2938         // on the correct side, i.e., revert nHorzScroll
2939 
2940         if ( !aInvalidateRegion.IsEmpty() )
2941         {
2942             aInvalidateRegion.Move( bReMirror ? -nHorzScroll : nHorzScroll, nVertScroll );
2943             bErase = sal_True;
2944         }
2945         if ( !(nFlags & SCROLL_NOWINDOWINVALIDATE) )
2946         {
2947             Rectangle aDestRect( aRectMirror );
2948             aDestRect.Move( bReMirror ? -nHorzScroll : nHorzScroll, nVertScroll );
2949             Region aWinInvalidateRegion( aRectMirror );
2950             aWinInvalidateRegion.Exclude( aDestRect );
2951 
2952             aInvalidateRegion.Union( aWinInvalidateRegion );
2953         }
2954     }
2955 
2956     Point aPoint( mnOutOffX, mnOutOffY );
2957     Region aRegion( Rectangle( aPoint, Size( mnOutWidth, mnOutHeight ) ) );
2958     if ( nFlags & SCROLL_CLIP )
2959         aRegion.Intersect( rRect );
2960     if ( mpWindowImpl->mbWinRegion )
2961         aRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
2962 
2963     aRegion.Exclude( aInvalidateRegion );
2964 
2965     ImplClipBoundaries( aRegion, sal_False, sal_True );
2966     if ( !bScrollChilds )
2967     {
2968         if ( nOrgFlags & SCROLL_NOCHILDREN )
2969             ImplClipAllChilds( aRegion );
2970         else
2971             ImplClipChilds( aRegion );
2972     }
2973     if ( mbClipRegion && (nFlags & SCROLL_USECLIPREGION) )
2974         aRegion.Intersect( maRegion );
2975     if ( !aRegion.IsEmpty() )
2976     {
2977         if ( mpWindowImpl->mpWinData )
2978         {
2979             if ( mpWindowImpl->mbFocusVisible )
2980                 ImplInvertFocus( *(mpWindowImpl->mpWinData->mpFocusRect) );
2981             if ( mpWindowImpl->mbTrackVisible && (mpWindowImpl->mpWinData->mnTrackFlags & SHOWTRACK_WINDOW) )
2982                 InvertTracking( *(mpWindowImpl->mpWinData->mpTrackRect), mpWindowImpl->mpWinData->mnTrackFlags );
2983         }
2984 
2985         SalGraphics* pGraphics = ImplGetFrameGraphics();
2986         if ( pGraphics )
2987         {
2988             if( bReMirror )
2989             {
2990                 // --- RTL --- frame coordinates require re-mirroring
2991                 ImplReMirror( aRegion );
2992             }
2993 
2994             ImplSelectClipRegion( aRegion, pGraphics );
2995             pGraphics->CopyArea( rRect.Left()+nHorzScroll, rRect.Top()+nVertScroll,
2996                                  rRect.Left(), rRect.Top(),
2997                                  rRect.GetWidth(), rRect.GetHeight(),
2998                                  SAL_COPYAREA_WINDOWINVALIDATE, this );
2999         }
3000 
3001         if ( mpWindowImpl->mpWinData )
3002         {
3003             if ( mpWindowImpl->mbFocusVisible )
3004                 ImplInvertFocus( *(mpWindowImpl->mpWinData->mpFocusRect) );
3005             if ( mpWindowImpl->mbTrackVisible && (mpWindowImpl->mpWinData->mnTrackFlags & SHOWTRACK_WINDOW) )
3006                 InvertTracking( *(mpWindowImpl->mpWinData->mpTrackRect), mpWindowImpl->mpWinData->mnTrackFlags );
3007         }
3008     }
3009 
3010     if ( !aInvalidateRegion.IsEmpty() )
3011     {
3012         // --- RTL --- the invalidate region for this windows is already computed in frame coordinates
3013         // so it has to be re-mirrored before calling the Paint-handler
3014         mpWindowImpl->mnPaintFlags |= IMPL_PAINT_CHECKRTL;
3015 
3016         sal_uInt16 nPaintFlags = INVALIDATE_CHILDREN;
3017         if ( !bErase )
3018             nPaintFlags |= INVALIDATE_NOERASE;
3019         if ( !bScrollChilds )
3020         {
3021             if ( nOrgFlags & SCROLL_NOCHILDREN )
3022                 ImplClipAllChilds( aInvalidateRegion );
3023             else
3024                 ImplClipChilds( aInvalidateRegion );
3025         }
3026         ImplInvalidateFrameRegion( &aInvalidateRegion, nPaintFlags );
3027     }
3028 
3029     if ( bScrollChilds )
3030     {
3031         Window* pWindow = mpWindowImpl->mpFirstChild;
3032         while ( pWindow )
3033         {
3034             Point aPos = pWindow->GetPosPixel();
3035             aPos += Point( nHorzScroll, nVertScroll );
3036             pWindow->SetPosPixel( aPos );
3037 
3038             pWindow = pWindow->mpWindowImpl->mpNext;
3039         }
3040     }
3041 
3042     if ( nFlags & SCROLL_UPDATE )
3043         Update();
3044 
3045     if ( mpWindowImpl->mpCursor )
3046         mpWindowImpl->mpCursor->ImplShow( false );
3047 }
3048 
3049 // -----------------------------------------------------------------------
3050 
3051 void Window::ImplUpdateAll( sal_Bool bOverlapWindows )
3052 {
3053     if ( !mpWindowImpl->mbReallyVisible )
3054         return;
3055 
3056     sal_Bool bFlush = sal_False;
3057     if ( mpWindowImpl->mpFrameWindow->mpWindowImpl->mbPaintFrame )
3058     {
3059         Point aPoint( 0, 0 );
3060         Region aRegion( Rectangle( aPoint, Size( mnOutWidth, mnOutHeight ) ) );
3061         ImplInvalidateOverlapFrameRegion( aRegion );
3062         if ( mpWindowImpl->mbFrame || (mpWindowImpl->mpBorderWindow && mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame) )
3063             bFlush = sal_True;
3064     }
3065 
3066     // Ein Update wirkt immer auf das OverlapWindow, damit bei spaeteren
3067     // Paints nicht zuviel gemalt wird, wenn dort ALLCHILDREN usw. gesetzt
3068     // ist
3069     Window* pWindow = ImplGetFirstOverlapWindow();
3070     if ( bOverlapWindows )
3071         pWindow->ImplCallOverlapPaint();
3072     else
3073     {
3074         if ( pWindow->mpWindowImpl->mnPaintFlags & (IMPL_PAINT_PAINT | IMPL_PAINT_PAINTCHILDS) )
3075             pWindow->ImplCallPaint( NULL, pWindow->mpWindowImpl->mnPaintFlags );
3076     }
3077 
3078     if ( bFlush )
3079         Flush();
3080 }
3081 
3082 // -----------------------------------------------------------------------
3083 
3084 void Window::ImplUpdateWindowPtr( Window* pWindow )
3085 {
3086     if ( mpWindowImpl->mpFrameWindow != pWindow->mpWindowImpl->mpFrameWindow )
3087     {
3088         // Graphic freigeben
3089         ImplReleaseGraphics();
3090     }
3091 
3092     mpWindowImpl->mpFrameData     = pWindow->mpWindowImpl->mpFrameData;
3093     mpWindowImpl->mpFrame         = pWindow->mpWindowImpl->mpFrame;
3094     mpWindowImpl->mpFrameWindow   = pWindow->mpWindowImpl->mpFrameWindow;
3095     if ( pWindow->ImplIsOverlapWindow() )
3096         mpWindowImpl->mpOverlapWindow = pWindow;
3097     else
3098         mpWindowImpl->mpOverlapWindow = pWindow->mpWindowImpl->mpOverlapWindow;
3099 
3100     Window* pChild = mpWindowImpl->mpFirstChild;
3101     while ( pChild )
3102     {
3103         pChild->ImplUpdateWindowPtr( pWindow );
3104         pChild = pChild->mpWindowImpl->mpNext;
3105     }
3106 }
3107 
3108 // -----------------------------------------------------------------------
3109 
3110 void Window::ImplUpdateWindowPtr()
3111 {
3112     Window* pChild = mpWindowImpl->mpFirstChild;
3113     while ( pChild )
3114     {
3115         pChild->ImplUpdateWindowPtr( this );
3116         pChild = pChild->mpWindowImpl->mpNext;
3117     }
3118 }
3119 
3120 // -----------------------------------------------------------------------
3121 
3122 void Window::ImplUpdateOverlapWindowPtr( sal_Bool bNewFrame )
3123 {
3124     sal_Bool bVisible = IsVisible();
3125     Show( sal_False );
3126     ImplRemoveWindow( bNewFrame );
3127     Window* pRealParent = mpWindowImpl->mpRealParent;
3128     ImplInsertWindow( ImplGetParent() );
3129     mpWindowImpl->mpRealParent = pRealParent;
3130     ImplUpdateWindowPtr();
3131     if ( ImplUpdatePos() )
3132         ImplUpdateSysObjPos();
3133 
3134     if ( bNewFrame )
3135     {
3136         Window* pOverlapWindow = mpWindowImpl->mpFirstOverlap;
3137         while ( pOverlapWindow )
3138         {
3139             Window* pNextOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
3140             pOverlapWindow->ImplUpdateOverlapWindowPtr( bNewFrame );
3141             pOverlapWindow = pNextOverlapWindow;
3142         }
3143     }
3144 
3145     if ( bVisible )
3146         Show( sal_True );
3147 }
3148 
3149 // -----------------------------------------------------------------------
3150 
3151 sal_Bool Window::ImplUpdatePos()
3152 {
3153     sal_Bool bSysChild = sal_False;
3154 
3155     if ( ImplIsOverlapWindow() )
3156     {
3157         mnOutOffX  = mpWindowImpl->mnX;
3158         mnOutOffY  = mpWindowImpl->mnY;
3159     }
3160     else
3161     {
3162         Window* pParent = ImplGetParent();
3163 
3164         mnOutOffX  = mpWindowImpl->mnX + pParent->mnOutOffX;
3165         mnOutOffY  = mpWindowImpl->mnY + pParent->mnOutOffY;
3166     }
3167 
3168     Window* pChild = mpWindowImpl->mpFirstChild;
3169     while ( pChild )
3170     {
3171         if ( pChild->ImplUpdatePos() )
3172             bSysChild = sal_True;
3173         pChild = pChild->mpWindowImpl->mpNext;
3174     }
3175 
3176     if ( mpWindowImpl->mpSysObj )
3177         bSysChild = sal_True;
3178 
3179     return bSysChild;
3180 }
3181 
3182 // -----------------------------------------------------------------------
3183 
3184 void Window::ImplUpdateSysObjPos()
3185 {
3186     if ( mpWindowImpl->mpSysObj )
3187         mpWindowImpl->mpSysObj->SetPosSize( mnOutOffX, mnOutOffY, mnOutWidth, mnOutHeight );
3188 
3189     Window* pChild = mpWindowImpl->mpFirstChild;
3190     while ( pChild )
3191     {
3192         pChild->ImplUpdateSysObjPos();
3193         pChild = pChild->mpWindowImpl->mpNext;
3194     }
3195 }
3196 // -----------------------------------------------------------------------
3197 
3198 void Window::ImplPosSizeWindow( long nX, long nY,
3199                                 long nWidth, long nHeight, sal_uInt16 nFlags )
3200 {
3201     sal_Bool    bNewPos         = sal_False;
3202     sal_Bool    bNewSize        = sal_False;
3203     sal_Bool    bNewWidth       = sal_False;
3204     sal_Bool    bCopyBits       = sal_False;
3205     long    nOldOutOffX     = mnOutOffX;
3206     long    nOldOutOffY     = mnOutOffY;
3207     long    nOldOutWidth    = mnOutWidth;
3208     long    nOldOutHeight   = mnOutHeight;
3209     Region* pOverlapRegion  = NULL;
3210     Region* pOldRegion      = NULL;
3211 
3212     if ( IsReallyVisible() )
3213     {
3214         if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
3215             ImplInvalidateAllOverlapBackgrounds();
3216 
3217         Rectangle aOldWinRect( Point( nOldOutOffX, nOldOutOffY ),
3218                                Size( nOldOutWidth, nOldOutHeight ) );
3219         pOldRegion = new Region( aOldWinRect );
3220         if ( mpWindowImpl->mbWinRegion )
3221             pOldRegion->Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
3222 
3223         if ( mnOutWidth && mnOutHeight && !mpWindowImpl->mbPaintTransparent &&
3224              !mpWindowImpl->mbInitWinClipRegion && !mpWindowImpl->maWinClipRegion.IsEmpty() &&
3225              !HasPaintEvent() )
3226             bCopyBits = sal_True;
3227     }
3228 
3229     sal_Bool bnXRecycled = sal_False; // avoid duplicate mirroring in RTL case
3230     if ( nFlags & WINDOW_POSSIZE_WIDTH )
3231     {
3232         if(!( nFlags & WINDOW_POSSIZE_X ))
3233         {
3234             nX = mpWindowImpl->mnX;
3235             nFlags |= WINDOW_POSSIZE_X;
3236             bnXRecycled = sal_True; // we're using a mnX which was already mirrored in RTL case
3237         }
3238 
3239         if ( nWidth < 0 )
3240             nWidth = 0;
3241         if ( nWidth != mnOutWidth )
3242         {
3243             mnOutWidth = nWidth;
3244             bNewSize = sal_True;
3245             bCopyBits = sal_False;
3246             bNewWidth = sal_True;
3247         }
3248     }
3249     if ( nFlags & WINDOW_POSSIZE_HEIGHT )
3250     {
3251         if ( nHeight < 0 )
3252             nHeight = 0;
3253         if ( nHeight != mnOutHeight )
3254         {
3255             mnOutHeight = nHeight;
3256             bNewSize = sal_True;
3257             bCopyBits = sal_False;
3258         }
3259     }
3260 
3261     if ( nFlags & WINDOW_POSSIZE_X )
3262     {
3263         long nOrgX = nX;
3264 		// --- RTL ---  (compare the screen coordinates)
3265 		Point aPtDev( Point( nX+mnOutOffX, 0 ) );
3266 		if( ImplHasMirroredGraphics() )
3267         {
3268             mpGraphics->mirror( aPtDev.X(), this );
3269 
3270             // #106948# always mirror our pos if our parent is not mirroring, even
3271             // if we are also not mirroring
3272             // --- RTL --- check if parent is in different coordinates
3273             if( !bnXRecycled && mpWindowImpl->mpParent && !mpWindowImpl->mpParent->mpWindowImpl->mbFrame && mpWindowImpl->mpParent->ImplIsAntiparallel() )
3274             {
3275                 // --- RTL --- (re-mirror at parent window)
3276                 nX = mpWindowImpl->mpParent->mnOutWidth - mnOutWidth - nX;
3277             }
3278             /* #i99166# An LTR window in RTL UI that gets sized only would be
3279                expected to not moved its upper left point
3280             */
3281             if( bnXRecycled )
3282             {
3283                 if( ImplIsAntiparallel() )
3284                 {
3285                     aPtDev.X() = mpWindowImpl->mnAbsScreenX;
3286                     nOrgX = mpWindowImpl->maPos.X();
3287                 }
3288             }
3289         }
3290         else if( !bnXRecycled && mpWindowImpl->mpParent && !mpWindowImpl->mpParent->mpWindowImpl->mbFrame && mpWindowImpl->mpParent->ImplIsAntiparallel() )
3291         {
3292             // mirrored window in LTR UI
3293             {
3294                 // --- RTL --- (re-mirror at parent window)
3295                 nX = mpWindowImpl->mpParent->mnOutWidth - mnOutWidth - nX;
3296             }
3297         }
3298 
3299         // check maPos as well, as it could have been changed for client windows (ImplCallMove())
3300         if ( mpWindowImpl->mnAbsScreenX != aPtDev.X() || nX != mpWindowImpl->mnX || nOrgX != mpWindowImpl->maPos.X() )
3301         {
3302             if ( bCopyBits && !pOverlapRegion )
3303             {
3304                 pOverlapRegion = new Region();
3305                 ImplCalcOverlapRegion( Rectangle( Point( mnOutOffX, mnOutOffY ),
3306                                                   Size( mnOutWidth, mnOutHeight ) ),
3307                                        *pOverlapRegion, sal_False, sal_True, sal_True );
3308             }
3309             mpWindowImpl->mnX = nX;
3310             mpWindowImpl->maPos.X() = nOrgX;
3311 			mpWindowImpl->mnAbsScreenX = aPtDev.X();	// --- RTL --- (store real screen pos)
3312             bNewPos = sal_True;
3313         }
3314     }
3315     if ( nFlags & WINDOW_POSSIZE_Y )
3316     {
3317         // check maPos as well, as it could have been changed for client windows (ImplCallMove())
3318         if ( nY != mpWindowImpl->mnY || nY != mpWindowImpl->maPos.Y() )
3319         {
3320             if ( bCopyBits && !pOverlapRegion )
3321             {
3322                 pOverlapRegion = new Region();
3323                 ImplCalcOverlapRegion( Rectangle( Point( mnOutOffX, mnOutOffY ),
3324                                                   Size( mnOutWidth, mnOutHeight ) ),
3325                                        *pOverlapRegion, sal_False, sal_True, sal_True );
3326             }
3327             mpWindowImpl->mnY = nY;
3328             mpWindowImpl->maPos.Y() = nY;
3329             bNewPos = sal_True;
3330         }
3331     }
3332 
3333 /*    if ( nFlags & (WINDOW_POSSIZE_X|WINDOW_POSSIZE_Y) )
3334     {
3335         POINT aPt;
3336         aPt.x = mpWindowImpl->maPos.X();
3337         aPt.y = mpWindowImpl->maPos.Y();
3338         ClientToScreen( mpWindowImpl->mpFrame->maFrameData.mhWnd , &aPt );
3339         mpWindowImpl->maPos.X() = aPt.x;
3340         mpWindowImpl->maPos.Y() = aPt.y;
3341     }
3342 */
3343     if ( bNewPos || bNewSize )
3344     {
3345         sal_Bool bUpdateSysObjPos = sal_False;
3346         if ( bNewPos )
3347             bUpdateSysObjPos = ImplUpdatePos();
3348 
3349         // the borderwindow always specifies the position for its client window
3350         if ( mpWindowImpl->mpBorderWindow )
3351             mpWindowImpl->maPos = mpWindowImpl->mpBorderWindow->mpWindowImpl->maPos;
3352 
3353         if ( mpWindowImpl->mpClientWindow )
3354         {
3355             mpWindowImpl->mpClientWindow->ImplPosSizeWindow( mpWindowImpl->mpClientWindow->mpWindowImpl->mnLeftBorder,
3356                                                mpWindowImpl->mpClientWindow->mpWindowImpl->mnTopBorder,
3357                                                mnOutWidth-mpWindowImpl->mpClientWindow->mpWindowImpl->mnLeftBorder-mpWindowImpl->mpClientWindow->mpWindowImpl->mnRightBorder,
3358                                                mnOutHeight-mpWindowImpl->mpClientWindow->mpWindowImpl->mnTopBorder-mpWindowImpl->mpClientWindow->mpWindowImpl->mnBottomBorder,
3359                                                WINDOW_POSSIZE_X | WINDOW_POSSIZE_Y |
3360                                                WINDOW_POSSIZE_WIDTH | WINDOW_POSSIZE_HEIGHT );
3361             // Wenn wir ein ClientWindow haben, dann hat dieses fuer die
3362             // Applikation auch die Position des FloatingWindows
3363             mpWindowImpl->mpClientWindow->mpWindowImpl->maPos = mpWindowImpl->maPos;
3364             if ( bNewPos )
3365             {
3366                 if ( mpWindowImpl->mpClientWindow->IsVisible() )
3367                 {
3368                     mpWindowImpl->mpClientWindow->ImplCallMove();
3369                 }
3370                 else
3371                 {
3372                     mpWindowImpl->mpClientWindow->mpWindowImpl->mbCallMove = sal_True;
3373                 }
3374             }
3375         }
3376 //        else
3377 //        {
3378 //            if ( mpWindowImpl->mpBorderWindow )
3379 //                mpWindowImpl->maPos = mpWindowImpl->mpBorderWindow->mpWindowImpl->maPos;
3380 //        }
3381 
3382         // Move()/Resize() werden erst bei Show() gerufen, damit min. eins vor
3383         // einem Show() kommt
3384         if ( IsVisible() )
3385         {
3386             if ( bNewPos )
3387             {
3388                 ImplCallMove();
3389             }
3390             if ( bNewSize )
3391             {
3392                 ImplCallResize();
3393             }
3394         }
3395         else
3396         {
3397             if ( bNewPos )
3398                 mpWindowImpl->mbCallMove = sal_True;
3399             if ( bNewSize )
3400                 mpWindowImpl->mbCallResize = sal_True;
3401         }
3402 
3403         sal_Bool bUpdateSysObjClip = sal_False;
3404         if ( IsReallyVisible() )
3405         {
3406             if ( bNewPos || bNewSize )
3407             {
3408                 // Hintergrund-Sicherung zuruecksetzen
3409                 if ( mpWindowImpl->mpOverlapData && mpWindowImpl->mpOverlapData->mpSaveBackDev )
3410                     ImplDeleteOverlapBackground();
3411                 if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
3412                     ImplInvalidateAllOverlapBackgrounds();
3413                 // Clip-Flag neu setzen
3414                 bUpdateSysObjClip = !ImplSetClipFlag( sal_True );
3415             }
3416 
3417             // Fensterinhalt invalidieren ?
3418             if ( bNewPos || (mnOutWidth > nOldOutWidth) || (mnOutHeight > nOldOutHeight) )
3419             {
3420                 if ( bNewPos )
3421                 {
3422                     sal_Bool bInvalidate = sal_False;
3423                     sal_Bool bParentPaint = sal_True;
3424                     if ( !ImplIsOverlapWindow() )
3425                         bParentPaint = mpWindowImpl->mpParent->IsPaintEnabled();
3426                     if ( bCopyBits && bParentPaint && !HasPaintEvent() )
3427                     {
3428                         Point aPoint( mnOutOffX, mnOutOffY );
3429                         Region aRegion( Rectangle( aPoint,
3430                                                    Size( mnOutWidth, mnOutHeight ) ) );
3431                         if ( mpWindowImpl->mbWinRegion )
3432                             aRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
3433                         ImplClipBoundaries( aRegion, sal_False, sal_True );
3434                         if ( !pOverlapRegion->IsEmpty() )
3435                         {
3436                             pOverlapRegion->Move( mnOutOffX-nOldOutOffX, mnOutOffY-nOldOutOffY );
3437                             aRegion.Exclude( *pOverlapRegion );
3438                         }
3439                         if ( !aRegion.IsEmpty() )
3440                         {
3441                             // Paint-Bereiche anpassen
3442                             ImplMoveAllInvalidateRegions( Rectangle( Point( nOldOutOffX, nOldOutOffY ),
3443                                                                      Size( nOldOutWidth, nOldOutHeight ) ),
3444                                                           mnOutOffX-nOldOutOffX, mnOutOffY-nOldOutOffY,
3445                                                           sal_True );
3446                             SalGraphics* pGraphics = ImplGetFrameGraphics();
3447                             if ( pGraphics )
3448                             {
3449                                 const bool bSelectClipRegion = ImplSelectClipRegion( aRegion, pGraphics );
3450                                 if ( bSelectClipRegion )
3451                                 {
3452                                     pGraphics->CopyArea( mnOutOffX, mnOutOffY,
3453                                                          nOldOutOffX, nOldOutOffY,
3454                                                          nOldOutWidth, nOldOutHeight,
3455                                                          SAL_COPYAREA_WINDOWINVALIDATE, this );
3456                                 }
3457                                 else
3458                                     bInvalidate = sal_True;
3459                             }
3460                             else
3461                                 bInvalidate = sal_True;
3462                             if ( !bInvalidate )
3463                             {
3464                                 if ( !pOverlapRegion->IsEmpty() )
3465                                     ImplInvalidateFrameRegion( pOverlapRegion, INVALIDATE_CHILDREN );
3466                             }
3467                         }
3468                         else
3469                             bInvalidate = sal_True;
3470                     }
3471                     else
3472                         bInvalidate = sal_True;
3473                     if ( bInvalidate )
3474                         ImplInvalidateFrameRegion( NULL, INVALIDATE_CHILDREN );
3475                 }
3476                 else
3477                 {
3478                     Point aPoint( mnOutOffX, mnOutOffY );
3479                     Region aRegion( Rectangle( aPoint,
3480                                                Size( mnOutWidth, mnOutHeight ) ) );
3481                     aRegion.Exclude( *pOldRegion );
3482                     if ( mpWindowImpl->mbWinRegion )
3483                         aRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
3484                     ImplClipBoundaries( aRegion, sal_False, sal_True );
3485                     if ( !aRegion.IsEmpty() )
3486                         ImplInvalidateFrameRegion( &aRegion, INVALIDATE_CHILDREN );
3487                 }
3488             }
3489 
3490             // Parent oder Overlaps invalidieren
3491             if ( bNewPos ||
3492                  (mnOutWidth < nOldOutWidth) || (mnOutHeight < nOldOutHeight) )
3493             {
3494                 Region aRegion( *pOldRegion );
3495                 if ( !mpWindowImpl->mbPaintTransparent )
3496                     ImplExcludeWindowRegion( aRegion );
3497                 ImplClipBoundaries( aRegion, sal_False, sal_True );
3498                 if ( !aRegion.IsEmpty() && !mpWindowImpl->mpBorderWindow )
3499                     ImplInvalidateParentFrameRegion( aRegion );
3500             }
3501         }
3502 
3503         // System-Objekte anpassen
3504         if ( bUpdateSysObjClip )
3505             ImplUpdateSysObjClip();
3506         if ( bUpdateSysObjPos )
3507             ImplUpdateSysObjPos();
3508         if ( bNewSize && mpWindowImpl->mpSysObj )
3509             mpWindowImpl->mpSysObj->SetPosSize( mnOutOffX, mnOutOffY, mnOutWidth, mnOutHeight );
3510     }
3511 
3512     if ( pOverlapRegion )
3513         delete pOverlapRegion;
3514     if ( pOldRegion )
3515         delete pOldRegion;
3516 }
3517 
3518 // -----------------------------------------------------------------------
3519 
3520 void Window::ImplToBottomChild()
3521 {
3522     if ( !ImplIsOverlapWindow() && !mpWindowImpl->mbReallyVisible && (mpWindowImpl->mpParent->mpWindowImpl->mpLastChild != this) )
3523     {
3524         // Fenster an das Ende der Liste setzen
3525         if ( mpWindowImpl->mpPrev )
3526             mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext;
3527         else
3528             mpWindowImpl->mpParent->mpWindowImpl->mpFirstChild = mpWindowImpl->mpNext;
3529         mpWindowImpl->mpNext->mpWindowImpl->mpPrev = mpWindowImpl->mpPrev;
3530         mpWindowImpl->mpPrev = mpWindowImpl->mpParent->mpWindowImpl->mpLastChild;
3531         mpWindowImpl->mpParent->mpWindowImpl->mpLastChild = this;
3532         mpWindowImpl->mpPrev->mpWindowImpl->mpNext = this;
3533         mpWindowImpl->mpNext = NULL;
3534     }
3535 }
3536 
3537 // -----------------------------------------------------------------------
3538 
3539 void Window::ImplCalcToTop( ImplCalcToTopData* pPrevData )
3540 {
3541     DBG_ASSERT( ImplIsOverlapWindow(), "Window::ImplCalcToTop(): Is not a OverlapWindow" );
3542 
3543     if ( !mpWindowImpl->mbFrame )
3544     {
3545         if ( IsReallyVisible() )
3546         {
3547             // Region berechnen, wo das Fenster mit anderen Fenstern ueberlappt
3548             Point aPoint( mnOutOffX, mnOutOffY );
3549             Region  aRegion( Rectangle( aPoint,
3550                                         Size( mnOutWidth, mnOutHeight ) ) );
3551             Region  aInvalidateRegion;
3552             ImplCalcOverlapRegionOverlaps( aRegion, aInvalidateRegion );
3553 
3554             if ( !aInvalidateRegion.IsEmpty() )
3555             {
3556                 ImplCalcToTopData* pData    = new ImplCalcToTopData;
3557                 pPrevData->mpNext           = pData;
3558                 pData->mpNext               = NULL;
3559                 pData->mpWindow             = this;
3560                 pData->mpInvalidateRegion   = new Region( aInvalidateRegion );
3561             }
3562         }
3563     }
3564 }
3565 
3566 // -----------------------------------------------------------------------
3567 
3568 void Window::ImplCalcChildOverlapToTop( ImplCalcToTopData* pPrevData )
3569 {
3570     DBG_ASSERT( ImplIsOverlapWindow(), "Window::ImplCalcChildOverlapToTop(): Is not a OverlapWindow" );
3571 
3572     ImplCalcToTop( pPrevData );
3573     if ( pPrevData->mpNext )
3574         pPrevData = pPrevData->mpNext;
3575 
3576     Window* pOverlap = mpWindowImpl->mpFirstOverlap;
3577     while ( pOverlap )
3578     {
3579         pOverlap->ImplCalcToTop( pPrevData );
3580         if ( pPrevData->mpNext )
3581             pPrevData = pPrevData->mpNext;
3582         pOverlap = pOverlap->mpWindowImpl->mpNext;
3583     }
3584 }
3585 
3586 // -----------------------------------------------------------------------
3587 
3588 void Window::ImplToTop( sal_uInt16 nFlags )
3589 {
3590     DBG_ASSERT( ImplIsOverlapWindow(), "Window::ImplToTop(): Is not a OverlapWindow" );
3591 
3592     if ( mpWindowImpl->mbFrame )
3593     {
3594         // Wenn in das externe Fenster geklickt wird, ist dieses
3595         // dafuer zustaendig dafuer zu sorgen, das unser Frame
3596         // nach vorne kommt
3597         if ( !mpWindowImpl->mpFrameData->mbHasFocus &&
3598              !mpWindowImpl->mpFrameData->mbSysObjFocus &&
3599              !mpWindowImpl->mpFrameData->mbInSysObjFocusHdl &&
3600              !mpWindowImpl->mpFrameData->mbInSysObjToTopHdl )
3601         {
3602 			// do not bring floating windows on the client to top
3603 			if( !ImplGetClientWindow() || !(ImplGetClientWindow()->GetStyle() & WB_SYSTEMFLOATWIN) )
3604 			{
3605 				sal_uInt16 nSysFlags = 0;
3606 				if ( nFlags & TOTOP_RESTOREWHENMIN )
3607 					nSysFlags |= SAL_FRAME_TOTOP_RESTOREWHENMIN;
3608 				if ( nFlags & TOTOP_FOREGROUNDTASK )
3609 					nSysFlags |= SAL_FRAME_TOTOP_FOREGROUNDTASK;
3610                 if ( nFlags & TOTOP_GRABFOCUSONLY )
3611                     nSysFlags |= SAL_FRAME_TOTOP_GRABFOCUS_ONLY;
3612 				mpWindowImpl->mpFrame->ToTop( nSysFlags );
3613 			}
3614         }
3615     }
3616     else
3617     {
3618         if ( mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap != this )
3619         {
3620             // Fenster aus der Liste entfernen
3621             mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext;
3622             if ( mpWindowImpl->mpNext )
3623                 mpWindowImpl->mpNext->mpWindowImpl->mpPrev = mpWindowImpl->mpPrev;
3624             else
3625                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpLastOverlap = mpWindowImpl->mpPrev;
3626 
3627             // AlwaysOnTop beruecksichtigen
3628             sal_Bool    bOnTop = IsAlwaysOnTopEnabled();
3629             Window* pNextWin = mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap;
3630             if ( !bOnTop )
3631             {
3632                 while ( pNextWin )
3633                 {
3634                     if ( !pNextWin->IsAlwaysOnTopEnabled() )
3635                         break;
3636                     pNextWin = pNextWin->mpWindowImpl->mpNext;
3637                 }
3638             }
3639 
3640             // TopLevel abpruefen
3641             sal_uInt8 nTopLevel = mpWindowImpl->mpOverlapData->mnTopLevel;
3642             while ( pNextWin )
3643             {
3644                 if ( (bOnTop != pNextWin->IsAlwaysOnTopEnabled()) ||
3645                      (nTopLevel <= pNextWin->mpWindowImpl->mpOverlapData->mnTopLevel) )
3646                     break;
3647                 pNextWin = pNextWin->mpWindowImpl->mpNext;
3648             }
3649 
3650             // Fenster in die Liste wieder eintragen
3651             mpWindowImpl->mpNext = pNextWin;
3652             if ( pNextWin )
3653             {
3654                 mpWindowImpl->mpPrev = pNextWin->mpWindowImpl->mpPrev;
3655                 pNextWin->mpWindowImpl->mpPrev = this;
3656             }
3657             else
3658             {
3659                 mpWindowImpl->mpPrev = mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpLastOverlap;
3660                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpLastOverlap = this;
3661             }
3662             if ( mpWindowImpl->mpPrev )
3663                 mpWindowImpl->mpPrev->mpWindowImpl->mpNext = this;
3664             else
3665                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap = this;
3666 
3667             // ClipRegion muss von diesem Fenster und allen weiteren
3668             // ueberlappenden Fenstern neu berechnet werden.
3669             if ( IsReallyVisible() )
3670             {
3671                 // Hintergrund-Sicherung zuruecksetzen
3672                 if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
3673                     ImplInvalidateAllOverlapBackgrounds();
3674                 mpWindowImpl->mpOverlapWindow->ImplSetClipFlagOverlapWindows();
3675             }
3676         }
3677     }
3678 }
3679 
3680 // -----------------------------------------------------------------------
3681 
3682 void Window::ImplStartToTop( sal_uInt16 nFlags )
3683 {
3684     ImplCalcToTopData   aStartData;
3685     ImplCalcToTopData*  pCurData;
3686     ImplCalcToTopData*  pNextData;
3687     Window* pOverlapWindow;
3688     if ( ImplIsOverlapWindow() )
3689         pOverlapWindow = this;
3690     else
3691         pOverlapWindow = mpWindowImpl->mpOverlapWindow;
3692 
3693     // Zuerst die Paint-Bereiche berechnen
3694     Window* pTempOverlapWindow = pOverlapWindow;
3695     aStartData.mpNext = NULL;
3696     pCurData = &aStartData;
3697     do
3698     {
3699         pTempOverlapWindow->ImplCalcToTop( pCurData );
3700         if ( pCurData->mpNext )
3701             pCurData = pCurData->mpNext;
3702         pTempOverlapWindow = pTempOverlapWindow->mpWindowImpl->mpOverlapWindow;
3703     }
3704     while ( !pTempOverlapWindow->mpWindowImpl->mbFrame );
3705     // Dann die Paint-Bereiche der ChildOverlap-Windows berechnen
3706     pTempOverlapWindow = mpWindowImpl->mpFirstOverlap;
3707     while ( pTempOverlapWindow )
3708     {
3709         pTempOverlapWindow->ImplCalcToTop( pCurData );
3710         if ( pCurData->mpNext )
3711             pCurData = pCurData->mpNext;
3712         pTempOverlapWindow = pTempOverlapWindow->mpWindowImpl->mpNext;
3713     }
3714 
3715     // Dann die Fenster-Verkettung aendern
3716     pTempOverlapWindow = pOverlapWindow;
3717     do
3718     {
3719         pTempOverlapWindow->ImplToTop( nFlags );
3720         pTempOverlapWindow = pTempOverlapWindow->mpWindowImpl->mpOverlapWindow;
3721     }
3722     while ( !pTempOverlapWindow->mpWindowImpl->mbFrame );
3723     // Und zum Schluss invalidieren wir die ungueltigen Bereiche
3724     pCurData = aStartData.mpNext;
3725     while ( pCurData )
3726     {
3727         pCurData->mpWindow->ImplInvalidateFrameRegion( pCurData->mpInvalidateRegion, INVALIDATE_CHILDREN );
3728         pNextData = pCurData->mpNext;
3729         delete pCurData->mpInvalidateRegion;
3730         delete pCurData;
3731         pCurData = pNextData;
3732     }
3733 }
3734 
3735 // -----------------------------------------------------------------------
3736 
3737 void Window::ImplFocusToTop( sal_uInt16 nFlags, sal_Bool bReallyVisible )
3738 {
3739     // Soll Focus auch geholt werden?
3740     if ( !(nFlags & TOTOP_NOGRABFOCUS) )
3741     {
3742         // Erstes Fenster mit GrabFocus-Activate bekommt den Focus
3743         Window* pFocusWindow = this;
3744         while ( !pFocusWindow->ImplIsOverlapWindow() )
3745         {
3746             // Nur wenn Fenster kein Border-Fenster hat, da wir
3747             // immer das dazugehoerende BorderFenster finden wollen
3748             if ( !pFocusWindow->mpWindowImpl->mpBorderWindow )
3749             {
3750                 if ( pFocusWindow->mpWindowImpl->mnActivateMode & ACTIVATE_MODE_GRABFOCUS )
3751                     break;
3752             }
3753             pFocusWindow = pFocusWindow->ImplGetParent();
3754         }
3755         if ( (pFocusWindow->mpWindowImpl->mnActivateMode & ACTIVATE_MODE_GRABFOCUS) &&
3756              !pFocusWindow->HasChildPathFocus( sal_True ) )
3757             pFocusWindow->GrabFocus();
3758     }
3759 
3760     if ( bReallyVisible )
3761         ImplGenerateMouseMove();
3762 }
3763 
3764 // -----------------------------------------------------------------------
3765 
3766 void Window::ImplShowAllOverlaps()
3767 {
3768     Window* pOverlapWindow = mpWindowImpl->mpFirstOverlap;
3769     while ( pOverlapWindow )
3770     {
3771         if ( pOverlapWindow->mpWindowImpl->mbOverlapVisible )
3772         {
3773             pOverlapWindow->Show( sal_True, SHOW_NOACTIVATE );
3774             pOverlapWindow->mpWindowImpl->mbOverlapVisible = sal_False;
3775         }
3776 
3777         pOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
3778     }
3779 }
3780 
3781 // -----------------------------------------------------------------------
3782 
3783 void Window::ImplHideAllOverlaps()
3784 {
3785     Window* pOverlapWindow = mpWindowImpl->mpFirstOverlap;
3786     while ( pOverlapWindow )
3787     {
3788         if ( pOverlapWindow->IsVisible() )
3789         {
3790             pOverlapWindow->mpWindowImpl->mbOverlapVisible = sal_True;
3791             pOverlapWindow->Show( sal_False );
3792         }
3793 
3794         pOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
3795     }
3796 }
3797 
3798 // -----------------------------------------------------------------------
3799 
3800 void Window::ImplCallMouseMove( sal_uInt16 nMouseCode, sal_Bool bModChanged )
3801 {
3802     if ( mpWindowImpl->mpFrameData->mbMouseIn && mpWindowImpl->mpFrameWindow->mpWindowImpl->mbReallyVisible )
3803     {
3804         sal_uLong   nTime   = Time::GetSystemTicks();
3805         long    nX      = mpWindowImpl->mpFrameData->mnLastMouseX;
3806         long    nY      = mpWindowImpl->mpFrameData->mnLastMouseY;
3807         sal_uInt16  nCode   = nMouseCode;
3808         sal_uInt16  nMode   = mpWindowImpl->mpFrameData->mnMouseMode;
3809         sal_Bool    bLeave;
3810         // Auf MouseLeave testen
3811         if ( ((nX < 0) || (nY < 0) ||
3812               (nX >= mpWindowImpl->mpFrameWindow->mnOutWidth) ||
3813               (nY >= mpWindowImpl->mpFrameWindow->mnOutHeight)) &&
3814              !ImplGetSVData()->maWinData.mpCaptureWin )
3815             bLeave = sal_True;
3816         else
3817             bLeave = sal_False;
3818         nMode |= MOUSE_SYNTHETIC;
3819         if ( bModChanged )
3820             nMode |= MOUSE_MODIFIERCHANGED;
3821         ImplHandleMouseEvent( mpWindowImpl->mpFrameWindow, EVENT_MOUSEMOVE, bLeave, nX, nY, nTime, nCode, nMode );
3822     }
3823 }
3824 
3825 // -----------------------------------------------------------------------
3826 
3827 void Window::ImplGenerateMouseMove()
3828 {
3829     if ( !mpWindowImpl->mpFrameData->mnMouseMoveId )
3830         Application::PostUserEvent( mpWindowImpl->mpFrameData->mnMouseMoveId, LINK( mpWindowImpl->mpFrameWindow, Window, ImplGenerateMouseMoveHdl ) );
3831 }
3832 
3833 // -----------------------------------------------------------------------
3834 
3835 IMPL_LINK( Window, ImplGenerateMouseMoveHdl, void*, EMPTYARG )
3836 {
3837     mpWindowImpl->mpFrameData->mnMouseMoveId = 0;
3838     Window* pCaptureWin = ImplGetSVData()->maWinData.mpCaptureWin;
3839     if( ! pCaptureWin ||
3840         (pCaptureWin->mpWindowImpl && pCaptureWin->mpWindowImpl->mpFrame == mpWindowImpl->mpFrame)
3841     )
3842     {
3843         ImplCallMouseMove( mpWindowImpl->mpFrameData->mnMouseCode );
3844     }
3845     return 0;
3846 }
3847 
3848 // -----------------------------------------------------------------------
3849 
3850 void Window::ImplInvertFocus( const Rectangle& rRect )
3851 {
3852     InvertTracking( rRect, SHOWTRACK_SMALL | SHOWTRACK_WINDOW );
3853 }
3854 
3855 // -----------------------------------------------------------------------
3856 
3857 void Window::ImplCallFocusChangeActivate( Window* pNewOverlapWindow,
3858                                           Window* pOldOverlapWindow )
3859 {
3860     ImplSVData* pSVData = ImplGetSVData();
3861     Window*     pNewRealWindow;
3862     Window*     pOldRealWindow;
3863     Window*     pLastRealWindow;
3864     sal_Bool        bCallActivate = sal_True;
3865     sal_Bool        bCallDeactivate = sal_True;
3866 
3867     pOldRealWindow = pOldOverlapWindow->ImplGetWindow();
3868     pNewRealWindow = pNewOverlapWindow->ImplGetWindow();
3869     if ( (pOldRealWindow->GetType() != WINDOW_FLOATINGWINDOW) ||
3870          pOldRealWindow->GetActivateMode() )
3871     {
3872         if ( (pNewRealWindow->GetType() == WINDOW_FLOATINGWINDOW) &&
3873              !pNewRealWindow->GetActivateMode() )
3874         {
3875             pSVData->maWinData.mpLastDeacWin = pOldOverlapWindow;
3876             bCallDeactivate = sal_False;
3877         }
3878     }
3879     else if ( (pNewRealWindow->GetType() != WINDOW_FLOATINGWINDOW) ||
3880               pNewRealWindow->GetActivateMode() )
3881     {
3882         if ( pSVData->maWinData.mpLastDeacWin )
3883         {
3884             if ( pSVData->maWinData.mpLastDeacWin == pNewOverlapWindow )
3885                 bCallActivate = sal_False;
3886             else
3887             {
3888                 pLastRealWindow = pSVData->maWinData.mpLastDeacWin->ImplGetWindow();
3889                 pSVData->maWinData.mpLastDeacWin->mpWindowImpl->mbActive = sal_False;
3890                 pSVData->maWinData.mpLastDeacWin->Deactivate();
3891                 if ( pLastRealWindow != pSVData->maWinData.mpLastDeacWin )
3892                 {
3893                     pLastRealWindow->mpWindowImpl->mbActive = sal_True;
3894                     pLastRealWindow->Activate();
3895                 }
3896             }
3897             pSVData->maWinData.mpLastDeacWin = NULL;
3898         }
3899     }
3900 
3901     if ( bCallDeactivate )
3902     {
3903         if( pOldOverlapWindow->mpWindowImpl->mbActive )
3904         {
3905             pOldOverlapWindow->mpWindowImpl->mbActive = sal_False;
3906             pOldOverlapWindow->Deactivate();
3907         }
3908         if ( pOldRealWindow != pOldOverlapWindow )
3909         {
3910             if( pOldRealWindow->mpWindowImpl->mbActive )
3911             {
3912                 pOldRealWindow->mpWindowImpl->mbActive = sal_False;
3913                 pOldRealWindow->Deactivate();
3914             }
3915         }
3916     }
3917     if ( bCallActivate && ! pNewOverlapWindow->mpWindowImpl->mbActive )
3918     {
3919         if( ! pNewOverlapWindow->mpWindowImpl->mbActive )
3920         {
3921             pNewOverlapWindow->mpWindowImpl->mbActive = sal_True;
3922             pNewOverlapWindow->Activate();
3923         }
3924         if ( pNewRealWindow != pNewOverlapWindow )
3925         {
3926             if( ! pNewRealWindow->mpWindowImpl->mbActive )
3927             {
3928                 pNewRealWindow->mpWindowImpl->mbActive = sal_True;
3929                 pNewRealWindow->Activate();
3930             }
3931         }
3932     }
3933 }
3934 
3935 static bool IsWindowFocused(const WindowImpl& rWinImpl)
3936 {
3937     if (rWinImpl.mpSysObj)
3938         return true;
3939 
3940     if (rWinImpl.mpFrameData->mbHasFocus)
3941         return true;
3942 
3943     if (rWinImpl.mbFakeFocusSet)
3944         return true;
3945 
3946     return false;
3947 }
3948 
3949 // -----------------------------------------------------------------------
3950 void Window::ImplGrabFocus( sal_uInt16 nFlags )
3951 {
3952     // #143570# no focus for destructing windows
3953     if( mpWindowImpl->mbInDtor )
3954         return;
3955 
3956     // some event listeners do really bad stuff
3957     // => prepare for the worst
3958     ImplDelData aDogTag( this );
3959 
3960     // Currently the client window should always get the focus
3961     // Should the border window at some point be focusable
3962     // we need to change all GrabFocus() instances in VCL,
3963     // e.g. in ToTop()
3964 
3965     if ( mpWindowImpl->mpClientWindow )
3966     {
3967         // For a lack of design we need a little hack here to
3968         // ensure that dialogs on close pass the focus back to
3969         // the correct window
3970         if ( mpWindowImpl->mpLastFocusWindow && (mpWindowImpl->mpLastFocusWindow != this) &&
3971              !(mpWindowImpl->mnDlgCtrlFlags & WINDOW_DLGCTRL_WANTFOCUS) &&
3972              mpWindowImpl->mpLastFocusWindow->IsEnabled() &&
3973              mpWindowImpl->mpLastFocusWindow->IsInputEnabled() &&
3974              ! mpWindowImpl->mpLastFocusWindow->IsInModalMode()
3975              )
3976             mpWindowImpl->mpLastFocusWindow->GrabFocus();
3977         else
3978             mpWindowImpl->mpClientWindow->GrabFocus();
3979         return;
3980     }
3981     else if ( mpWindowImpl->mbFrame )
3982     {
3983         // For a lack of design we need a little hack here to
3984         // ensure that dialogs on close pass the focus back to
3985         // the correct window
3986         if ( mpWindowImpl->mpLastFocusWindow && (mpWindowImpl->mpLastFocusWindow != this) &&
3987              !(mpWindowImpl->mnDlgCtrlFlags & WINDOW_DLGCTRL_WANTFOCUS) &&
3988              mpWindowImpl->mpLastFocusWindow->IsEnabled() &&
3989              mpWindowImpl->mpLastFocusWindow->IsInputEnabled() &&
3990              ! mpWindowImpl->mpLastFocusWindow->IsInModalMode()
3991              )
3992         {
3993             mpWindowImpl->mpLastFocusWindow->GrabFocus();
3994             return;
3995         }
3996     }
3997 
3998     // If the Window is disabled, then we don't change the focus
3999     if ( !IsEnabled() || !IsInputEnabled() || IsInModalMode() )
4000         return;
4001 
4002     // we only need to set the focus if it is not already set
4003     // note: if some other frame is waiting for an asynchrounous focus event
4004     // we also have to post an asynchronous focus event for this frame
4005     // which is done using ToTop
4006     ImplSVData* pSVData = ImplGetSVData();
4007 
4008     sal_Bool bAsyncFocusWaiting = sal_False;
4009     Window *pFrame = pSVData->maWinData.mpFirstFrame;
4010     while( pFrame  )
4011     {
4012         if( pFrame != mpWindowImpl->mpFrameWindow && pFrame->mpWindowImpl->mpFrameData->mnFocusId )
4013         {
4014             bAsyncFocusWaiting = sal_True;
4015             break;
4016         }
4017         pFrame = pFrame->mpWindowImpl->mpFrameData->mpNextFrame;
4018     }
4019 
4020     bool bHasFocus = IsWindowFocused(*mpWindowImpl);
4021 
4022     sal_Bool bMustNotGrabFocus = sal_False;
4023     // #100242#, check parent hierarchy if some floater prohibits grab focus
4024 
4025     Window *pParent = this;
4026     while( pParent )
4027     {
4028         // #102158#, ignore grabfocus only if the floating parent grabs keyboard focus by itself (GrabsFocus())
4029         // otherwise we cannot set the focus in a floating toolbox
4030         if( ( (pParent->mpWindowImpl->mbFloatWin && ((FloatingWindow*)pParent)->GrabsFocus()) || ( pParent->GetStyle() & WB_SYSTEMFLOATWIN ) ) && !( pParent->GetStyle() & WB_MOVEABLE ) )
4031         {
4032             bMustNotGrabFocus = sal_True;
4033             break;
4034         }
4035         pParent = pParent->mpWindowImpl->mpParent;
4036     }
4037 
4038 
4039     if ( ( pSVData->maWinData.mpFocusWin != this && ! mpWindowImpl->mbInDtor ) || ( bAsyncFocusWaiting && !bHasFocus && !bMustNotGrabFocus ) )
4040     {
4041         // EndExtTextInput if it is not the same window
4042         if ( pSVData->maWinData.mpExtTextInputWin &&
4043              (pSVData->maWinData.mpExtTextInputWin != this) )
4044             pSVData->maWinData.mpExtTextInputWin->EndExtTextInput( EXTTEXTINPUT_END_COMPLETE );
4045 
4046         // Dieses Fenster als letztes FocusWindow merken
4047         Window* pOverlapWindow = ImplGetFirstOverlapWindow();
4048         pOverlapWindow->mpWindowImpl->mpLastFocusWindow = this;
4049         mpWindowImpl->mpFrameData->mpFocusWin = this;
4050 
4051         if( !bHasFocus )
4052         {
4053             // menue windows never get the system focus
4054             // the application will keep the focus
4055             if( bMustNotGrabFocus )
4056                 return;
4057             else
4058             {
4059                 // Hier setzen wir schon den Focus um, da ToTop() den Focus
4060                 // nicht auf ein anderes Fenster setzen darf
4061                 //DBG_WARNING( "Window::GrabFocus() - Frame doesn't have the focus" );
4062 				mpWindowImpl->mpFrame->ToTop( SAL_FRAME_TOTOP_GRABFOCUS | SAL_FRAME_TOTOP_GRABFOCUS_ONLY );
4063                 return;
4064             }
4065         }
4066 
4067         Window* pOldFocusWindow = pSVData->maWinData.mpFocusWin;
4068         ImplDelData aOldFocusDel( pOldFocusWindow );
4069 
4070         pSVData->maWinData.mpFocusWin = this;
4071 
4072         if ( pOldFocusWindow )
4073         {
4074             // Cursor hiden
4075             if ( pOldFocusWindow->mpWindowImpl->mpCursor )
4076                 pOldFocusWindow->mpWindowImpl->mpCursor->ImplHide( true );
4077         }
4078 
4079         // !!!!! Wegen altem SV-Office Activate/Deavtivate Handling
4080         // !!!!! erstmal so wie frueher
4081         if ( pOldFocusWindow )
4082         {
4083             // Focus merken
4084             Window* pOldOverlapWindow = pOldFocusWindow->ImplGetFirstOverlapWindow();
4085             Window* pNewOverlapWindow = ImplGetFirstOverlapWindow();
4086             if ( pOldOverlapWindow != pNewOverlapWindow )
4087                 ImplCallFocusChangeActivate( pNewOverlapWindow, pOldOverlapWindow );
4088         }
4089         else
4090         {
4091             Window* pNewOverlapWindow = ImplGetFirstOverlapWindow();
4092             Window* pNewRealWindow = pNewOverlapWindow->ImplGetWindow();
4093             pNewOverlapWindow->mpWindowImpl->mbActive = sal_True;
4094             pNewOverlapWindow->Activate();
4095             if ( pNewRealWindow != pNewOverlapWindow )
4096             {
4097                 pNewRealWindow->mpWindowImpl->mbActive = sal_True;
4098                 pNewRealWindow->Activate();
4099             }
4100         }
4101 /*
4102         // call Deactivate and Activate
4103         Window* pDeactivateParent;
4104         Window* pActivateParent;
4105         Window* pParent;
4106         Window* pLastParent;
4107         pDeactivateParent = pOldFocusWindow;
4108         while ( pDeactivateParent )
4109         {
4110             pParent = pDeactivateParent;
4111             if ( pParent->ImplIsChild( this ) )
4112                 break;
4113 
4114             if ( pDeactivateParent->ImplIsOverlapWindow() )
4115             {
4116                 if ( !pDeactivateParent->mpWindowImpl->mbParentActive )
4117                     break;
4118             }
4119 
4120             pDeactivateParent = pDeactivateParent->ImplGetParent();
4121         }
4122         if ( pOldFocusWindow )
4123         {
4124             pActivateParent = this;
4125             while ( pActivateParent )
4126             {
4127                 pParent = pActivateParent;
4128                 if ( pParent->ImplIsChild( pOldFocusWindow ) )
4129                     break;
4130 
4131                 if ( pActivateParent->ImplIsOverlapWindow() )
4132                 {
4133                     if ( !pActivateParent->mpWindowImpl->mbParentActive )
4134                         break;
4135                 }
4136 
4137                 pActivateParent = pActivateParent->ImplGetParent();
4138             }
4139         }
4140         else
4141         {
4142             if ( ImplIsOverlapWindow() )
4143                 pActivateParent = this;
4144             else
4145                 pActivateParent = mpWindowImpl->mpOverlapWindow;
4146             while ( pActivateParent )
4147             {
4148                 if ( pActivateParent->ImplIsOverlapWindow() )
4149                 {
4150                     if ( !pActivateParent->mpWindowImpl->mbParentActive )
4151                         break;
4152                 }
4153 
4154                 pActivateParent = pActivateParent->ImplGetParent();
4155             }
4156         }
4157         if ( pDeactivateParent )
4158         {
4159             do
4160             {
4161                 pLastParent = pOldFocusWindow;
4162                 if ( pLastParent != pDeactivateParent )
4163                 {
4164                     pParent = pLastParent->ImplGetParent();
4165                     while ( pParent )
4166                     {
4167                         if ( pParent == pDeactivateParent )
4168                             break;
4169                         pLastParent = pParent;
4170                         pParent = pParent->ImplGetParent();
4171                     }
4172                 }
4173                 else
4174                     pParent = pLastParent;
4175 
4176                 pParent->mpWindowImpl->mbActive = sal_False;
4177                 pParent->Deactivate();
4178                 pDeactivateParent = pLastParent;
4179             }
4180             while ( pDeactivateParent != pOldFocusWindow );
4181         }
4182         do
4183         {
4184             pLastParent = this;
4185             if ( pLastParent != pActivateParent )
4186             {
4187                 pParent = pLastParent->ImplGetParent();
4188                 while ( pParent )
4189                 {
4190                     if ( pParent == pActivateParent )
4191                         break;
4192                     pLastParent = pParent;
4193                     pParent = pParent->ImplGetParent();
4194                 }
4195             }
4196             else
4197                 pParent = pLastParent;
4198 
4199             pParent->mpWindowImpl->mbActive = sal_True;
4200             pParent->Activate();
4201             pActivateParent = pLastParent;
4202         }
4203         while ( pActivateParent != this );
4204 */
4205         // call Get- and LoseFocus
4206         if ( pOldFocusWindow && ! aOldFocusDel.IsDelete() )
4207         {
4208             if ( pOldFocusWindow->IsTracking() &&
4209                  (pSVData->maWinData.mnTrackFlags & STARTTRACK_FOCUSCANCEL) )
4210                 pOldFocusWindow->EndTracking( ENDTRACK_CANCEL | ENDTRACK_FOCUS );
4211             NotifyEvent aNEvt( EVENT_LOSEFOCUS, pOldFocusWindow );
4212             if ( !ImplCallPreNotify( aNEvt ) )
4213                 pOldFocusWindow->LoseFocus();
4214             pOldFocusWindow->ImplCallDeactivateListeners( this );
4215         }
4216 
4217         if ( pSVData->maWinData.mpFocusWin == this )
4218         {
4219             if ( mpWindowImpl->mpSysObj )
4220             {
4221                 mpWindowImpl->mpFrameData->mpFocusWin = this;
4222                 if ( !mpWindowImpl->mpFrameData->mbInSysObjFocusHdl )
4223                     mpWindowImpl->mpSysObj->GrabFocus();
4224             }
4225 
4226             if ( pSVData->maWinData.mpFocusWin == this )
4227             {
4228                 if ( mpWindowImpl->mpCursor )
4229                     mpWindowImpl->mpCursor->ImplShow();
4230                 mpWindowImpl->mbInFocusHdl = sal_True;
4231                 mpWindowImpl->mnGetFocusFlags = nFlags;
4232                 // if we're changing focus due to closing a popup floating window
4233                 // notify the new focus window so it can restore the inner focus
4234                 // eg, toolboxes can select their recent active item
4235                 if( pOldFocusWindow &&
4236                     ! aOldFocusDel.IsDelete() &&
4237                     ( pOldFocusWindow->GetDialogControlFlags() & WINDOW_DLGCTRL_FLOATWIN_POPUPMODEEND_CANCEL ) )
4238                     mpWindowImpl->mnGetFocusFlags |= GETFOCUS_FLOATWIN_POPUPMODEEND_CANCEL;
4239                 NotifyEvent aNEvt( EVENT_GETFOCUS, this );
4240                 if ( !ImplCallPreNotify( aNEvt ) && !aDogTag.IsDelete() )
4241                     GetFocus();
4242                 if( !aDogTag.IsDelete() )
4243                     ImplCallActivateListeners( (pOldFocusWindow && ! aOldFocusDel.IsDelete()) ? pOldFocusWindow : NULL );
4244                 if( !aDogTag.IsDelete() )
4245                 {
4246                     mpWindowImpl->mnGetFocusFlags = 0;
4247                     mpWindowImpl->mbInFocusHdl = sal_False;
4248                 }
4249             }
4250         }
4251 
4252         GetpApp()->FocusChanged();
4253         ImplNewInputContext();
4254     }
4255 }
4256 
4257 // -----------------------------------------------------------------------
4258 
4259 void Window::ImplNewInputContext()
4260 {
4261     ImplSVData* pSVData = ImplGetSVData();
4262     Window*     pFocusWin = pSVData->maWinData.mpFocusWin;
4263     if ( !pFocusWin )
4264         return;
4265 
4266     // Is InputContext changed?
4267     const InputContext& rInputContext = pFocusWin->GetInputContext();
4268     if ( rInputContext == pFocusWin->mpWindowImpl->mpFrameData->maOldInputContext )
4269         return;
4270 
4271     pFocusWin->mpWindowImpl->mpFrameData->maOldInputContext = rInputContext;
4272 
4273     SalInputContext         aNewContext;
4274     const Font&             rFont = rInputContext.GetFont();
4275     const XubString&        rFontName = rFont.GetName();
4276     ImplFontEntry*          pFontEntry = NULL;
4277     aNewContext.mpFont = NULL;
4278     if ( rFontName.Len() )
4279     {
4280         Size aSize = pFocusWin->ImplLogicToDevicePixel( rFont.GetSize() );
4281         if ( !aSize.Height() )
4282         {
4283             // Nur dann Defaultgroesse setzen, wenn Fonthoehe auch in logischen
4284             // Koordinaaten 0 ist
4285             if ( rFont.GetSize().Height() )
4286                 aSize.Height() = 1;
4287             else
4288                 aSize.Height() = (12*pFocusWin->mnDPIY)/72;
4289         }
4290         // TODO: No display device uses ImplDirectFontSubstitution thingy, right? => remove it
4291         ImplDirectFontSubstitution* pFontSubst = NULL;
4292         //if( pFocusWin->mpOutDevData )
4293         //    pFontSubst = &pFocusWin->mpOutDevData->maDevFontSubst;
4294         pFontEntry = pFocusWin->mpFontCache->GetFontEntry( pFocusWin->mpFontList,
4295                          rFont, aSize, static_cast<float>(aSize.Height()), pFontSubst );
4296         if ( pFontEntry )
4297             aNewContext.mpFont = &pFontEntry->maFontSelData;
4298     }
4299     aNewContext.meLanguage  = rFont.GetLanguage();
4300     aNewContext.mnOptions   = rInputContext.GetOptions();
4301     pFocusWin->ImplGetFrame()->SetInputContext( &aNewContext );
4302 
4303     if ( pFontEntry )
4304         pFocusWin->mpFontCache->Release( pFontEntry );
4305 }
4306 
4307 // -----------------------------------------------------------------------
4308 
4309 Window::Window( WindowType nType )
4310 {
4311     DBG_CTOR( Window, ImplDbgCheckWindow );
4312 
4313     ImplInitWindowData( nType );
4314 }
4315 
4316 // -----------------------------------------------------------------------
4317 
4318 Window::Window( Window* pParent, WinBits nStyle )
4319 {
4320     DBG_CTOR( Window, ImplDbgCheckWindow );
4321 
4322     ImplInitWindowData( WINDOW_WINDOW );
4323     ImplInit( pParent, nStyle, NULL );
4324 }
4325 
4326 // -----------------------------------------------------------------------
4327 
4328 Window::Window( Window* pParent, const ResId& rResId )
4329 {
4330     DBG_CTOR( Window, ImplDbgCheckWindow );
4331 
4332     ImplInitWindowData( WINDOW_WINDOW );
4333     rResId.SetRT( RSC_WINDOW );
4334     WinBits nStyle = ImplInitRes( rResId );
4335     ImplInit( pParent, nStyle, NULL );
4336     ImplLoadRes( rResId );
4337 
4338     if ( !(nStyle & WB_HIDE) )
4339         Show();
4340 }
4341 
4342 // -----------------------------------------------------------------------
4343 #if OSL_DEBUG_LEVEL > 0
4344 namespace
4345 {
4346     void lcl_appendWindowInfo( ByteString& io_rErrorString, const Window& i_rWindow )
4347     {
4348         // skip border windows, they don't carry information which helps diagnosing the problem
4349         const Window* pWindow( &i_rWindow );
4350         while ( pWindow && ( pWindow->GetType() == WINDOW_BORDERWINDOW ) )
4351             pWindow = pWindow->GetWindow( WINDOW_FIRSTCHILD );
4352         if ( !pWindow )
4353             pWindow = &i_rWindow;
4354 
4355         io_rErrorString += char(13);
4356         io_rErrorString += typeid( *pWindow ).name();
4357         io_rErrorString += " (window text: '";
4358         io_rErrorString += ByteString( pWindow->GetText(), RTL_TEXTENCODING_UTF8 );
4359         io_rErrorString += "')";
4360     }
4361 }
4362 #endif
4363 // -----------------------------------------------------------------------
4364 
4365 Window::~Window()
4366 {
4367     ImplFreeExtWindowImpl();
4368 
4369     vcl::LazyDeletor<Window>::Undelete( this );
4370 
4371     DBG_DTOR( Window, ImplDbgCheckWindow );
4372     DBG_ASSERT( !mpWindowImpl->mbInDtor, "~Window - already in DTOR!" );
4373 
4374 
4375     // remove Key and Mouse events issued by Application::PostKey/MouseEvent
4376     Application::RemoveMouseAndKeyEvents( this );
4377 
4378     // Dispose of the canvas implementation (which, currently, has an
4379     // own wrapper window as a child to this one.
4380     uno::Reference< rendering::XCanvas > xCanvas( mpWindowImpl->mxCanvas );
4381     if( xCanvas.is() )
4382     {
4383         uno::Reference < lang::XComponent > xCanvasComponent( xCanvas,
4384                                                               uno::UNO_QUERY );
4385         if( xCanvasComponent.is() )
4386             xCanvasComponent->dispose();
4387     }
4388 
4389     mpWindowImpl->mbInDtor = sal_True;
4390 
4391     ImplCallEventListeners( VCLEVENT_OBJECT_DYING );
4392 
4393     // do not send child events for frames that were registered as native frames
4394     if( !ImplIsAccessibleNativeFrame() && mpWindowImpl->mbReallyVisible )
4395         if ( ImplIsAccessibleCandidate() && GetAccessibleParentWindow() )
4396             GetAccessibleParentWindow()->ImplCallEventListeners( VCLEVENT_WINDOW_CHILDDESTROYED, this );
4397 
4398     // remove associated data structures from dockingmanager
4399     ImplGetDockingManager()->RemoveWindow( this );
4400 
4401 
4402     // remove ownerdraw decorated windows from list in the top-most frame window
4403     if( (GetStyle() & WB_OWNERDRAWDECORATION) && mpWindowImpl->mbFrame )
4404     {
4405         ::std::vector< Window* >& rList = ImplGetOwnerDrawList();
4406 	    ::std::vector< Window* >::iterator p;
4407         p = ::std::find( rList.begin(), rList.end(), this );
4408         if( p != rList.end() )
4409 	        rList.erase( p );
4410     }
4411 
4412     // shutdown drag and drop
4413     ::com::sun::star::uno::Reference < ::com::sun::star::lang::XComponent > xDnDComponent( mpWindowImpl->mxDNDListenerContainer, ::com::sun::star::uno::UNO_QUERY );
4414 
4415     if( xDnDComponent.is() )
4416         xDnDComponent->dispose();
4417 
4418     if( mpWindowImpl->mbFrame && mpWindowImpl->mpFrameData )
4419     {
4420         try
4421         {
4422             // deregister drop target listener
4423             if( mpWindowImpl->mpFrameData->mxDropTargetListener.is() )
4424             {
4425                 uno::Reference< XDragGestureRecognizer > xDragGestureRecognizer =
4426                     uno::Reference< XDragGestureRecognizer > (mpWindowImpl->mpFrameData->mxDragSource, UNO_QUERY);
4427                 if( xDragGestureRecognizer.is() )
4428                 {
4429                     xDragGestureRecognizer->removeDragGestureListener(
4430                         uno::Reference< XDragGestureListener > (mpWindowImpl->mpFrameData->mxDropTargetListener, UNO_QUERY));
4431                 }
4432 
4433                 mpWindowImpl->mpFrameData->mxDropTarget->removeDropTargetListener( mpWindowImpl->mpFrameData->mxDropTargetListener );
4434                 mpWindowImpl->mpFrameData->mxDropTargetListener.clear();
4435             }
4436 
4437             // shutdown drag and drop for this frame window
4438             uno::Reference< XComponent > xComponent( mpWindowImpl->mpFrameData->mxDropTarget, UNO_QUERY );
4439 
4440             // DNDEventDispatcher does not hold a reference of the DropTarget,
4441             // so it's ok if it does not support XComponent
4442             if( xComponent.is() )
4443                 xComponent->dispose();
4444         }
4445 
4446         catch ( Exception&)
4447         {
4448             // can be safely ignored here.
4449         }
4450     }
4451 
4452     UnoWrapperBase* pWrapper = Application::GetUnoWrapper( sal_False );
4453     if ( pWrapper )
4454         pWrapper->WindowDestroyed( this );
4455 
4456     // MT: Must be called after WindowDestroyed!
4457     // Otherwise, if the accessible is a VCLXWindow, it will try to destroy this window again!
4458     // But accessibility implementations from applications need this dispose.
4459     if ( mpWindowImpl->mxAccessible.is() )
4460     {
4461         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent> xC( mpWindowImpl->mxAccessible, ::com::sun::star::uno::UNO_QUERY );
4462         if ( xC.is() )
4463             xC->dispose();
4464     }
4465 
4466     ImplSVData* pSVData = ImplGetSVData();
4467 
4468     if ( pSVData->maHelpData.mpHelpWin && (pSVData->maHelpData.mpHelpWin->GetParent() == this) )
4469         ImplDestroyHelpWindow( true );
4470 
4471     DBG_ASSERT( pSVData->maWinData.mpTrackWin != this,
4472                 "Window::~Window(): Window is in TrackingMode" );
4473     DBG_ASSERT( pSVData->maWinData.mpCaptureWin != this,
4474                 "Window::~Window(): Window has the mouse captured" );
4475     // #103442# DefModalDialogParent is now determined on-the-fly, so this pointer is unimportant now
4476     //DBG_ASSERT( pSVData->maWinData.mpDefDialogParent != this,
4477     //            "Window::~Window(): Window is DefModalDialogParent" );
4478 
4479     // Wegen alter kompatibilitaet
4480     if ( pSVData->maWinData.mpTrackWin == this )
4481         EndTracking();
4482     if ( pSVData->maWinData.mpCaptureWin == this )
4483         ReleaseMouse();
4484     if ( pSVData->maWinData.mpDefDialogParent == this )
4485         pSVData->maWinData.mpDefDialogParent = NULL;
4486 
4487 #ifdef DBG_UTIL
4488     if ( sal_True ) // always perform these tests in non-pro versions
4489     {
4490         ByteString  aErrorStr;
4491         sal_Bool        bError = sal_False;
4492         Window*     pTempWin = mpWindowImpl->mpFrameData->mpFirstOverlap;
4493         while ( pTempWin )
4494         {
4495             if ( ImplIsRealParentPath( pTempWin ) )
4496             {
4497                 bError = sal_True;
4498                 lcl_appendWindowInfo( aErrorStr, *pTempWin );
4499             }
4500             pTempWin = pTempWin->mpWindowImpl->mpNextOverlap;
4501         }
4502         if ( bError )
4503         {
4504             ByteString aTempStr( "Window (" );
4505             aTempStr += ByteString( GetText(), RTL_TEXTENCODING_UTF8 );
4506             aTempStr += ") with living SystemWindow(s) destroyed: ";
4507             aTempStr += aErrorStr;
4508             DBG_ERROR( aTempStr.GetBuffer() );
4509 		    GetpApp()->Abort( String( aTempStr, RTL_TEXTENCODING_UTF8 ) );   // abort in non-pro version, this must be fixed!
4510         }
4511 
4512         bError = sal_False;
4513         pTempWin = pSVData->maWinData.mpFirstFrame;
4514         while ( pTempWin )
4515         {
4516             if ( ImplIsRealParentPath( pTempWin ) )
4517             {
4518                 bError = sal_True;
4519                 lcl_appendWindowInfo( aErrorStr, *pTempWin );
4520             }
4521             pTempWin = pTempWin->mpWindowImpl->mpFrameData->mpNextFrame;
4522         }
4523         if ( bError )
4524         {
4525             ByteString aTempStr( "Window (" );
4526             aTempStr += ByteString( GetText(), RTL_TEXTENCODING_UTF8 );
4527             aTempStr += ") with living SystemWindow(s) destroyed: ";
4528             aTempStr += aErrorStr;
4529             DBG_ERROR( aTempStr.GetBuffer() );
4530 		    GetpApp()->Abort( String( aTempStr, RTL_TEXTENCODING_UTF8 ) );   // abort in non-pro version, this must be fixed!
4531         }
4532 
4533         if ( mpWindowImpl->mpFirstChild )
4534         {
4535             ByteString aTempStr( "Window (" );
4536             aTempStr += ByteString( GetText(), RTL_TEXTENCODING_UTF8 );
4537             aTempStr += ") with living Child(s) destroyed: ";
4538             pTempWin = mpWindowImpl->mpFirstChild;
4539             while ( pTempWin )
4540             {
4541                 lcl_appendWindowInfo( aTempStr, *pTempWin );
4542                 pTempWin = pTempWin->mpWindowImpl->mpNext;
4543             }
4544             DBG_ERROR( aTempStr.GetBuffer() );
4545 		    GetpApp()->Abort( String( aTempStr, RTL_TEXTENCODING_UTF8 ) );   // abort in non-pro version, this must be fixed!
4546         }
4547 
4548         if ( mpWindowImpl->mpFirstOverlap )
4549         {
4550             ByteString aTempStr( "Window (" );
4551             aTempStr += ByteString( GetText(), RTL_TEXTENCODING_UTF8 );
4552             aTempStr += ") with living SystemWindow(s) destroyed: ";
4553             pTempWin = mpWindowImpl->mpFirstOverlap;
4554             while ( pTempWin )
4555             {
4556                 lcl_appendWindowInfo( aTempStr, *pTempWin );
4557                 pTempWin = pTempWin->mpWindowImpl->mpNext;
4558             }
4559             DBG_ERROR( aTempStr.GetBuffer() );
4560 		    GetpApp()->Abort( String( aTempStr, RTL_TEXTENCODING_UTF8 ) );   // abort in non-pro version, this must be fixed!
4561         }
4562 
4563         Window* pMyParent = this;
4564         SystemWindow* pMySysWin = NULL;
4565 
4566         while ( pMyParent )
4567         {
4568             if ( pMyParent->IsSystemWindow() )
4569                 pMySysWin = (SystemWindow*)pMyParent;
4570             pMyParent = pMyParent->GetParent();
4571         }
4572         if ( pMySysWin && pMySysWin->ImplIsInTaskPaneList( this ) )
4573         {
4574             ByteString aTempStr( "Window (" );
4575             aTempStr += ByteString( GetText(), RTL_TEXTENCODING_UTF8 );
4576             aTempStr += ") still in TaskPanelList!";
4577             DBG_ERROR( aTempStr.GetBuffer() );
4578 		    GetpApp()->Abort( String( aTempStr, RTL_TEXTENCODING_UTF8 ) );   // abort in non-pro version, this must be fixed!
4579         }
4580     }
4581 #endif
4582 
4583     if( mpWindowImpl->mbIsInTaskPaneList )
4584     {
4585         Window* pMyParent = this;
4586         SystemWindow* pMySysWin = NULL;
4587 
4588         while ( pMyParent )
4589         {
4590             if ( pMyParent->IsSystemWindow() )
4591                 pMySysWin = (SystemWindow*)pMyParent;
4592             pMyParent = pMyParent->GetParent();
4593         }
4594         if ( pMySysWin && pMySysWin->ImplIsInTaskPaneList( this ) )
4595         {
4596             pMySysWin->GetTaskPaneList()->RemoveWindow( this );
4597         }
4598         else
4599         {
4600             ByteString aTempStr( "Window (" );
4601             aTempStr += ByteString( GetText(), RTL_TEXTENCODING_UTF8 );
4602             aTempStr += ") not found in TaskPanelList!";
4603             DBG_ERROR( aTempStr.GetBuffer() );
4604         }
4605     }
4606 
4607     // Fenster hiden, um das entsprechende Paint-Handling auszuloesen
4608     Hide();
4609 
4610     // Mitteilen, das Fenster zerstoert wird
4611     {
4612     NotifyEvent aNEvt( EVENT_DESTROY, this );
4613     Notify( aNEvt );
4614     }
4615 
4616     // EndExtTextInputMode
4617     if ( pSVData->maWinData.mpExtTextInputWin == this )
4618     {
4619         EndExtTextInput( EXTTEXTINPUT_END_COMPLETE );
4620         if ( pSVData->maWinData.mpExtTextInputWin == this )
4621             pSVData->maWinData.mpExtTextInputWin = NULL;
4622     }
4623 
4624     // check if the focus window is our child
4625     sal_Bool bHasFocussedChild = sal_False;
4626     if( pSVData->maWinData.mpFocusWin && ImplIsRealParentPath( pSVData->maWinData.mpFocusWin ) )
4627     {
4628         // #122232#, this must not happen and is an application bug ! but we try some cleanup to hopefully avoid crashes, see below
4629         bHasFocussedChild = sal_True;
4630 #ifdef DBG_UTIL
4631         ByteString aTempStr( "Window (" );
4632         aTempStr += ByteString( GetText(), RTL_TEXTENCODING_UTF8 );
4633         aTempStr += ") with focussed child window destroyed ! THIS WILL LEAD TO CRASHES AND MUST BE FIXED !";
4634         DBG_ERROR( aTempStr.GetBuffer() );
4635         GetpApp()->Abort( String( aTempStr, RTL_TEXTENCODING_UTF8 ) );   // abort in non-pro version, this must be fixed!
4636 #endif
4637     }
4638 
4639     // Wenn wir den Focus haben, dann den Focus auf ein anderes Fenster setzen
4640     Window* pOverlapWindow = ImplGetFirstOverlapWindow();
4641     if ( pSVData->maWinData.mpFocusWin == this
4642         || bHasFocussedChild )  // #122232#, see above, try some cleanup
4643     {
4644         if ( mpWindowImpl->mbFrame )
4645         {
4646             pSVData->maWinData.mpFocusWin = NULL;
4647             pOverlapWindow->mpWindowImpl->mpLastFocusWindow = NULL;
4648             GetpApp()->FocusChanged();
4649         }
4650         else
4651         {
4652             Window* pParent = GetParent();
4653             Window* pBorderWindow = mpWindowImpl->mpBorderWindow;
4654             // Bei ueberlappenden Fenstern wird der Focus auf den
4655             // Parent vom naechsten FrameWindow gesetzt
4656             if ( pBorderWindow )
4657             {
4658                 if ( pBorderWindow->ImplIsOverlapWindow() )
4659                     pParent = pBorderWindow->mpWindowImpl->mpOverlapWindow;
4660             }
4661             else if ( ImplIsOverlapWindow() )
4662                 pParent = mpWindowImpl->mpOverlapWindow;
4663 
4664             if ( pParent && pParent->IsEnabled() && pParent->IsInputEnabled() && ! pParent->IsInModalMode() )
4665                 pParent->GrabFocus();
4666             else
4667                 mpWindowImpl->mpFrameWindow->GrabFocus();
4668 
4669             // If the focus was set back to 'this' set it to nothing
4670             if ( pSVData->maWinData.mpFocusWin == this )
4671             {
4672                 pSVData->maWinData.mpFocusWin = NULL;
4673                 pOverlapWindow->mpWindowImpl->mpLastFocusWindow = NULL;
4674                 GetpApp()->FocusChanged();
4675             }
4676         }
4677     }
4678 
4679 
4680     if ( pOverlapWindow->mpWindowImpl->mpLastFocusWindow == this )
4681         pOverlapWindow->mpWindowImpl->mpLastFocusWindow = NULL;
4682 
4683     // reset hint for DefModalDialogParent
4684     if( pSVData->maWinData.mpActiveApplicationFrame == this )
4685         pSVData->maWinData.mpActiveApplicationFrame = NULL;
4686 
4687     // gemerkte Fenster zuruecksetzen
4688     if ( mpWindowImpl->mpFrameData->mpFocusWin == this )
4689         mpWindowImpl->mpFrameData->mpFocusWin = NULL;
4690     if ( mpWindowImpl->mpFrameData->mpMouseMoveWin == this )
4691         mpWindowImpl->mpFrameData->mpMouseMoveWin = NULL;
4692     if ( mpWindowImpl->mpFrameData->mpMouseDownWin == this )
4693         mpWindowImpl->mpFrameData->mpMouseDownWin = NULL;
4694 
4695     // Deactivate-Window zuruecksetzen
4696     if ( pSVData->maWinData.mpLastDeacWin == this )
4697         pSVData->maWinData.mpLastDeacWin = NULL;
4698 
4699     if ( mpWindowImpl->mbFrame )
4700     {
4701         if ( mpWindowImpl->mpFrameData->mnFocusId )
4702             Application::RemoveUserEvent( mpWindowImpl->mpFrameData->mnFocusId );
4703         if ( mpWindowImpl->mpFrameData->mnMouseMoveId )
4704             Application::RemoveUserEvent( mpWindowImpl->mpFrameData->mnMouseMoveId );
4705     }
4706 
4707     // Graphic freigeben
4708     ImplReleaseGraphics();
4709 
4710     // Evt. anderen Funktion mitteilen, das das Fenster geloescht
4711     // wurde
4712     ImplDelData* pDelData = mpWindowImpl->mpFirstDel;
4713     while ( pDelData )
4714     {
4715         pDelData->mbDel = sal_True;
4716         pDelData->mpWindow = NULL;  // #112873# pDel is not associated with a Window anymore
4717         pDelData = pDelData->mpNext;
4718     }
4719 
4720     // Fenster aus den Listen austragen
4721     ImplRemoveWindow( sal_True );
4722 
4723     // de-register as "top window child" at our parent, if necessary
4724     if ( mpWindowImpl->mbFrame )
4725     {
4726         sal_Bool bIsTopWindow = mpWindowImpl->mpWinData && ( mpWindowImpl->mpWinData->mnIsTopWindow == 1 );
4727         if ( mpWindowImpl->mpRealParent && bIsTopWindow )
4728         {
4729             ImplWinData* pParentWinData = mpWindowImpl->mpRealParent->ImplGetWinData();
4730 
4731             ::std::list< Window* >::iterator myPos = ::std::find( pParentWinData->maTopWindowChildren.begin(),
4732                 pParentWinData->maTopWindowChildren.end(), this );
4733             DBG_ASSERT( myPos != pParentWinData->maTopWindowChildren.end(), "Window::~Window: inconsistency in top window chain!" );
4734             if ( myPos != pParentWinData->maTopWindowChildren.end() )
4735                 pParentWinData->maTopWindowChildren.erase( myPos );
4736         }
4737     }
4738 
4739     // Extra Window Daten loeschen
4740     if ( mpWindowImpl->mpWinData )
4741     {
4742         if ( mpWindowImpl->mpWinData->mpExtOldText )
4743             delete mpWindowImpl->mpWinData->mpExtOldText;
4744         if ( mpWindowImpl->mpWinData->mpExtOldAttrAry )
4745             delete mpWindowImpl->mpWinData->mpExtOldAttrAry;
4746         if ( mpWindowImpl->mpWinData->mpCursorRect )
4747             delete mpWindowImpl->mpWinData->mpCursorRect;
4748         if ( mpWindowImpl->mpWinData->mpFocusRect )
4749             delete mpWindowImpl->mpWinData->mpFocusRect;
4750         if ( mpWindowImpl->mpWinData->mpTrackRect )
4751             delete mpWindowImpl->mpWinData->mpTrackRect;
4752 
4753         delete mpWindowImpl->mpWinData;
4754     }
4755 
4756 
4757     // Overlap-Window-Daten loeschen
4758     if ( mpWindowImpl->mpOverlapData )
4759     {
4760         delete mpWindowImpl->mpOverlapData;
4761     }
4762 
4763     // Evt. noch BorderWindow oder Frame zerstoeren
4764     if ( mpWindowImpl->mpBorderWindow )
4765         delete mpWindowImpl->mpBorderWindow;
4766     else if ( mpWindowImpl->mbFrame )
4767     {
4768         if ( pSVData->maWinData.mpFirstFrame == this )
4769             pSVData->maWinData.mpFirstFrame = mpWindowImpl->mpFrameData->mpNextFrame;
4770         else
4771         {
4772             Window* pSysWin = pSVData->maWinData.mpFirstFrame;
4773             while ( pSysWin->mpWindowImpl->mpFrameData->mpNextFrame != this )
4774                 pSysWin = pSysWin->mpWindowImpl->mpFrameData->mpNextFrame;
4775             pSysWin->mpWindowImpl->mpFrameData->mpNextFrame = mpWindowImpl->mpFrameData->mpNextFrame;
4776         }
4777         mpWindowImpl->mpFrame->SetCallback( NULL, NULL );
4778         pSVData->mpDefInst->DestroyFrame( mpWindowImpl->mpFrame );
4779         delete mpWindowImpl->mpFrameData;
4780     }
4781 
4782     if ( mpWindowImpl->mpChildClipRegion )
4783         delete mpWindowImpl->mpChildClipRegion;
4784 
4785     delete mpWindowImpl->mpAccessibleInfos;
4786     delete mpWindowImpl->mpControlFont;
4787 
4788     // should be the last statements
4789     delete mpWindowImpl; mpWindowImpl = NULL;
4790 }
4791 
4792 // -----------------------------------------------------------------------
4793 void Window::doLazyDelete()
4794 {
4795     SystemWindow* pSysWin = dynamic_cast<SystemWindow*>(this);
4796     DockingWindow* pDockWin = dynamic_cast<DockingWindow*>(this);
4797     if( pSysWin || ( pDockWin && pDockWin->IsFloatingMode() ) )
4798     {
4799         Show( sal_False );
4800         SetParent( ImplGetDefaultWindow() );
4801     }
4802     vcl::LazyDeletor<Window>::Delete( this );
4803 }
4804 
4805 // -----------------------------------------------------------------------
4806 void Window::InterceptChildWindowKeyDown( sal_Bool bIntercept )
4807 {
4808     if( mpWindowImpl->mpSysObj )
4809         mpWindowImpl->mpSysObj->InterceptChildWindowKeyDown( bIntercept );
4810 }
4811 
4812 // -----------------------------------------------------------------------
4813 
4814 void Window::MouseMove( const MouseEvent& rMEvt )
4815 {
4816     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4817     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4818     }
4819 
4820     NotifyEvent aNEvt( EVENT_MOUSEMOVE, this, &rMEvt );
4821     if ( !Notify( aNEvt ) )
4822         mpWindowImpl->mbMouseMove = sal_True;
4823 }
4824 
4825 // -----------------------------------------------------------------------
4826 
4827 void Window::MouseButtonDown( const MouseEvent& rMEvt )
4828 {
4829     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4830     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4831     }
4832 
4833     NotifyEvent aNEvt( EVENT_MOUSEBUTTONDOWN, this, &rMEvt );
4834     if ( !Notify( aNEvt ) )
4835         mpWindowImpl->mbMouseButtonDown = sal_True;
4836 }
4837 
4838 // -----------------------------------------------------------------------
4839 
4840 void Window::MouseButtonUp( const MouseEvent& rMEvt )
4841 {
4842     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4843     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4844     }
4845 
4846     NotifyEvent aNEvt( EVENT_MOUSEBUTTONUP, this, &rMEvt );
4847     if ( !Notify( aNEvt ) )
4848         mpWindowImpl->mbMouseButtonUp = sal_True;
4849 }
4850 
4851 // -----------------------------------------------------------------------
4852 
4853 void Window::KeyInput( const KeyEvent& rKEvt )
4854 {
4855     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4856     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4857     }
4858 
4859     NotifyEvent aNEvt( EVENT_KEYINPUT, this, &rKEvt );
4860     if ( !Notify( aNEvt ) )
4861         mpWindowImpl->mbKeyInput = sal_True;
4862 }
4863 
4864 // -----------------------------------------------------------------------
4865 
4866 void Window::KeyUp( const KeyEvent& rKEvt )
4867 {
4868     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4869     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4870     }
4871 
4872     NotifyEvent aNEvt( EVENT_KEYUP, this, &rKEvt );
4873     if ( !Notify( aNEvt ) )
4874         mpWindowImpl->mbKeyUp = sal_True;
4875 }
4876 
4877 // -----------------------------------------------------------------------
4878 
4879 void Window::PrePaint()
4880 {
4881 }
4882 
4883 // -----------------------------------------------------------------------
4884 
4885 void Window::Paint( const Rectangle& rRect )
4886 {
4887     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4888     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4889     }
4890 
4891     ImplCallEventListeners( VCLEVENT_WINDOW_PAINT, (void*)&rRect );
4892 }
4893 
4894 // -----------------------------------------------------------------------
4895 
4896 void Window::PostPaint()
4897 {
4898 }
4899 
4900 // -----------------------------------------------------------------------
4901 
4902 void Window::Draw( OutputDevice*, const Point&, const Size&, sal_uLong )
4903 {
4904     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4905 }
4906 
4907 // -----------------------------------------------------------------------
4908 
4909 void Window::Move()
4910 {
4911     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4912 }
4913 
4914 // -----------------------------------------------------------------------
4915 
4916 void Window::Resize()
4917 {
4918     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4919 }
4920 
4921 // -----------------------------------------------------------------------
4922 
4923 void Window::Activate()
4924 {
4925     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4926 }
4927 
4928 // -----------------------------------------------------------------------
4929 
4930 void Window::Deactivate()
4931 {
4932     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4933 }
4934 
4935 // -----------------------------------------------------------------------
4936 
4937 void Window::GetFocus()
4938 {
4939     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4940     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4941     }
4942 
4943     if ( HasFocus() && mpWindowImpl->mpLastFocusWindow && !(mpWindowImpl->mnDlgCtrlFlags & WINDOW_DLGCTRL_WANTFOCUS) )
4944     {
4945         ImplDelData aDogtag( this );
4946         mpWindowImpl->mpLastFocusWindow->GrabFocus();
4947         if( aDogtag.IsDelete() )
4948             return;
4949     }
4950 
4951     NotifyEvent aNEvt( EVENT_GETFOCUS, this );
4952     Notify( aNEvt );
4953 }
4954 
4955 // -----------------------------------------------------------------------
4956 
4957 void Window::LoseFocus()
4958 {
4959     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4960     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4961     }
4962 
4963     NotifyEvent aNEvt( EVENT_LOSEFOCUS, this );
4964     Notify( aNEvt );
4965 }
4966 
4967 // -----------------------------------------------------------------------
4968 
4969 void Window::RequestHelp( const HelpEvent& rHEvt )
4970 {
4971     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
4972     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
4973     }
4974 
4975     // Wenn Balloon-Help angefordert wird, dann den Balloon mit dem
4976     // gesetzten Hilfetext anzeigen
4977     if ( rHEvt.GetMode() & HELPMODE_BALLOON )
4978     {
4979         const XubString* pStr = &(GetHelpText());
4980         if ( !pStr->Len() )
4981             pStr = &(GetQuickHelpText());
4982         if ( !pStr->Len() && ImplGetParent() && !ImplIsOverlapWindow() )
4983             ImplGetParent()->RequestHelp( rHEvt );
4984         else
4985             Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), *pStr );
4986     }
4987     else if ( rHEvt.GetMode() & HELPMODE_QUICK )
4988     {
4989         const XubString* pStr = &(GetQuickHelpText());
4990         if ( !pStr->Len() && ImplGetParent() && !ImplIsOverlapWindow() )
4991             ImplGetParent()->RequestHelp( rHEvt );
4992         else
4993         {
4994             Point aPos = GetPosPixel();
4995             if ( ImplGetParent() && !ImplIsOverlapWindow() )
4996                 aPos = ImplGetParent()->OutputToScreenPixel( aPos );
4997             Rectangle   aRect( aPos, GetSizePixel() );
4998             String      aHelpText;
4999             if ( pStr->Len() )
5000                 aHelpText = GetHelpText();
5001             Help::ShowQuickHelp( this, aRect, *pStr, aHelpText, QUICKHELP_CTRLTEXT );
5002         }
5003     }
5004     else
5005     {
5006 		String aStrHelpId( rtl::OStringToOUString( GetHelpId(), RTL_TEXTENCODING_UTF8 ) );
5007         if ( aStrHelpId.Len() == 0 && ImplGetParent() )
5008             ImplGetParent()->RequestHelp( rHEvt );
5009         else
5010         {
5011             Help* pHelp = Application::GetHelp();
5012             if ( pHelp )
5013 			{
5014 				if( aStrHelpId.Len() > 0 )
5015 					pHelp->Start( aStrHelpId, this );
5016 				else
5017 					pHelp->Start( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OOO_HELP_INDEX ) ), this );
5018 			}
5019         }
5020     }
5021 }
5022 
5023 // -----------------------------------------------------------------------
5024 
5025 void Window::Command( const CommandEvent& rCEvt )
5026 {
5027     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
5028     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5029     }
5030 
5031     ImplCallEventListeners( VCLEVENT_WINDOW_COMMAND, (void*)&rCEvt );
5032 
5033     NotifyEvent aNEvt( EVENT_COMMAND, this, &rCEvt );
5034     if ( !Notify( aNEvt ) )
5035         mpWindowImpl->mbCommand = sal_True;
5036 }
5037 
5038 // -----------------------------------------------------------------------
5039 
5040 void Window::Tracking( const TrackingEvent& rTEvt )
5041 {
5042     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5043 
5044     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
5045     if( pWrapper )
5046         pWrapper->Tracking( rTEvt );
5047 }
5048 
5049 // -----------------------------------------------------------------------
5050 
5051 void Window::UserEvent( sal_uLong, void* )
5052 {
5053     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5054 }
5055 
5056 // -----------------------------------------------------------------------
5057 
5058 void Window::StateChanged( StateChangedType )
5059 {
5060     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5061 }
5062 
5063 // -----------------------------------------------------------------------
5064 
5065 void Window::DataChanged( const DataChangedEvent& )
5066 {
5067     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5068 }
5069 
5070 // -----------------------------------------------------------------------
5071 
5072 void Window::ImplNotifyKeyMouseCommandEventListeners( NotifyEvent& rNEvt )
5073 {
5074     if( rNEvt.GetType() == EVENT_COMMAND )
5075     {
5076         const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
5077         if ( pCEvt->GetCommand() != COMMAND_CONTEXTMENU )
5078             // non context menu events are not to be notified up the chain
5079             // so we return immediately
5080             return;
5081 
5082         if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5083         {
5084             if ( rNEvt.GetWindow() == this )
5085                 // not interested in: The event listeners are already called in ::Command,
5086                 // and calling them here a second time doesn't make sense
5087                 ;
5088             else
5089             {
5090                 CommandEvent aCommandEvent = ImplTranslateCommandEvent( *pCEvt, rNEvt.GetWindow(), this );
5091                 ImplCallEventListeners( VCLEVENT_WINDOW_COMMAND, &aCommandEvent );
5092             }
5093         }
5094     }
5095 
5096     // #82968# notify event listeners for mouse and key events seperately and
5097     // not in PreNotify ( as for focus listeners )
5098     // this allows for procesing those events internally first and pass it to
5099     // the toolkit later
5100 
5101     ImplDelData aDelData;
5102     ImplAddDel( &aDelData );
5103 
5104     if( rNEvt.GetType() == EVENT_MOUSEMOVE )
5105     {
5106         if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5107         {
5108             if ( rNEvt.GetWindow() == this )
5109                 ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEMOVE, (void*)rNEvt.GetMouseEvent() );
5110             else
5111             {
5112                 MouseEvent aMouseEvent = ImplTranslateMouseEvent( *rNEvt.GetMouseEvent(), rNEvt.GetWindow(), this );
5113                 ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEMOVE, &aMouseEvent );
5114             }
5115         }
5116     }
5117     else if( rNEvt.GetType() == EVENT_MOUSEBUTTONUP )
5118     {
5119         if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5120         {
5121             if ( rNEvt.GetWindow() == this )
5122                 ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONUP, (void*)rNEvt.GetMouseEvent() );
5123             else
5124             {
5125                 MouseEvent aMouseEvent = ImplTranslateMouseEvent( *rNEvt.GetMouseEvent(), rNEvt.GetWindow(), this );
5126                 ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONUP, &aMouseEvent );
5127             }
5128         }
5129     }
5130     else if( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
5131     {
5132         if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5133         {
5134             if ( rNEvt.GetWindow() == this )
5135                 ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, (void*)rNEvt.GetMouseEvent() );
5136             else
5137             {
5138                 MouseEvent aMouseEvent = ImplTranslateMouseEvent( *rNEvt.GetMouseEvent(), rNEvt.GetWindow(), this );
5139                 ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, &aMouseEvent );
5140             }
5141         }
5142     }
5143     else if( rNEvt.GetType() == EVENT_KEYINPUT )
5144     {
5145         if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5146             ImplCallEventListeners( VCLEVENT_WINDOW_KEYINPUT, (void*)rNEvt.GetKeyEvent() );
5147     }
5148     else if( rNEvt.GetType() == EVENT_KEYUP )
5149     {
5150         if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5151             ImplCallEventListeners( VCLEVENT_WINDOW_KEYUP, (void*)rNEvt.GetKeyEvent() );
5152     }
5153 
5154     if ( aDelData.IsDelete() )
5155         return;
5156     ImplRemoveDel( &aDelData );
5157 
5158     // #106721# check if we're part of a compound control and notify
5159     Window *pParent = ImplGetParent();
5160     while( pParent )
5161     {
5162         if( pParent->IsCompoundControl() )
5163         {
5164             pParent->ImplNotifyKeyMouseCommandEventListeners( rNEvt );
5165             break;
5166         }
5167         pParent = pParent->ImplGetParent();
5168     }
5169 }
5170 
5171 // -----------------------------------------------------------------------
5172 
5173 long Window::PreNotify( NotifyEvent& rNEvt )
5174 {
5175     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
5176     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5177     }
5178 
5179     long bDone = sal_False;
5180     if ( mpWindowImpl->mpParent && !ImplIsOverlapWindow() )
5181         bDone = mpWindowImpl->mpParent->PreNotify( rNEvt );
5182 
5183     if ( !bDone )
5184     {
5185         if( rNEvt.GetType() == EVENT_GETFOCUS )
5186         {
5187             sal_Bool bCompoundFocusChanged = sal_False;
5188             if ( mpWindowImpl->mbCompoundControl && !mpWindowImpl->mbCompoundControlHasFocus && HasChildPathFocus() )
5189             {
5190                 mpWindowImpl->mbCompoundControlHasFocus = sal_True;
5191                 bCompoundFocusChanged = sal_True;
5192             }
5193 
5194             if ( bCompoundFocusChanged || ( rNEvt.GetWindow() == this ) )
5195                 ImplCallEventListeners( VCLEVENT_WINDOW_GETFOCUS );
5196         }
5197         else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
5198         {
5199             sal_Bool bCompoundFocusChanged = sal_False;
5200             if ( mpWindowImpl->mbCompoundControl && mpWindowImpl->mbCompoundControlHasFocus && !HasChildPathFocus() )
5201             {
5202                 mpWindowImpl->mbCompoundControlHasFocus = sal_False ;
5203                 bCompoundFocusChanged = sal_True;
5204             }
5205 
5206             if ( bCompoundFocusChanged || ( rNEvt.GetWindow() == this ) )
5207                 ImplCallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS );
5208         }
5209 
5210         // #82968# mouse and key events will be notified after processing ( in ImplNotifyKeyMouseCommandEventListeners() )!
5211         //    see also ImplHandleMouseEvent(), ImplHandleKey()
5212 
5213         /*
5214         else if( rNEvt.GetType() == EVENT_MOUSEMOVE )
5215         {
5216             if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5217             {
5218                 if ( rNEvt.GetWindow() == this )
5219                     ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEMOVE, (void*)rNEvt.GetMouseEvent() );
5220                 else
5221                     ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEMOVE, &ImplTranslateMouseEvent( *rNEvt.GetMouseEvent(), rNEvt.GetWindow(), this ) );
5222             }
5223         }
5224         else if( rNEvt.GetType() == EVENT_MOUSEBUTTONUP )
5225         {
5226             if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5227             {
5228                 if ( rNEvt.GetWindow() == this )
5229                     ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONUP, (void*)rNEvt.GetMouseEvent() );
5230                 else
5231                     ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONUP, &ImplTranslateMouseEvent( *rNEvt.GetMouseEvent(), rNEvt.GetWindow(), this ) );
5232             }
5233         }
5234         else if( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
5235         {
5236             if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5237             {
5238                 if ( rNEvt.GetWindow() == this )
5239                     ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, (void*)rNEvt.GetMouseEvent() );
5240                 else
5241                     ImplCallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, &ImplTranslateMouseEvent( *rNEvt.GetMouseEvent(), rNEvt.GetWindow(), this ) );
5242             }
5243         }
5244         else if( rNEvt.GetType() == EVENT_KEYINPUT )
5245         {
5246             if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5247                 ImplCallEventListeners( VCLEVENT_WINDOW_KEYINPUT, (void*)rNEvt.GetKeyEvent() );
5248         }
5249         else if( rNEvt.GetType() == EVENT_KEYUP )
5250         {
5251             if ( mpWindowImpl->mbCompoundControl || ( rNEvt.GetWindow() == this ) )
5252                 ImplCallEventListeners( VCLEVENT_WINDOW_KEYUP, (void*)rNEvt.GetKeyEvent() );
5253         }
5254         */
5255     }
5256 
5257     return bDone;
5258 }
5259 
5260 // -----------------------------------------------------------------------
5261 
5262 long Window::Notify( NotifyEvent& rNEvt )
5263 {
5264     { // Klammerung, da in diesem Handler das Window zerstoert werden darf
5265     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5266     }
5267 
5268     long nRet = sal_False;
5269 
5270     // check for docking window
5271     // but do nothing if window is docked and locked
5272     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
5273     if( pWrapper && !( !pWrapper->IsFloatingMode() && pWrapper->IsLocked() ) )
5274     {
5275         if ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
5276         {
5277             const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
5278             sal_Bool bHit = pWrapper->GetDragArea().IsInside( pMEvt->GetPosPixel() );
5279             if ( pMEvt->IsLeft() )
5280             {
5281                 if ( pMEvt->IsMod1() && (pMEvt->GetClicks() == 2) )
5282                 {
5283                     // ctrl double click toggles floating mode
5284                     pWrapper->SetFloatingMode( !pWrapper->IsFloatingMode() );
5285                     return sal_True;
5286                 }
5287                 else if ( pMEvt->GetClicks() == 1 && bHit)
5288                 {
5289                     // allow start docking during mouse move
5290                     pWrapper->ImplEnableStartDocking();
5291                     return sal_True;
5292                 }
5293             }
5294         }
5295         else if ( rNEvt.GetType() == EVENT_MOUSEMOVE )
5296         {
5297             const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
5298             sal_Bool bHit = pWrapper->GetDragArea().IsInside( pMEvt->GetPosPixel() );
5299             if ( pMEvt->IsLeft() )
5300             {
5301                 // check if a single click initiated this sequence ( ImplStartDockingEnabled() )
5302                 // check if window is docked and
5303                 if( pWrapper->ImplStartDockingEnabled() && !pWrapper->IsFloatingMode() &&
5304                     !pWrapper->IsDocking() && bHit )
5305                 {
5306                     Point   aPos = pMEvt->GetPosPixel();
5307                     Window* pWindow = rNEvt.GetWindow();
5308                     if ( pWindow != this )
5309                     {
5310                         aPos = pWindow->OutputToScreenPixel( aPos );
5311                         aPos = ScreenToOutputPixel( aPos );
5312                     }
5313                     pWrapper->ImplStartDocking( aPos );
5314                 }
5315                 return sal_True;
5316             }
5317         }
5318         else if( rNEvt.GetType() == EVENT_KEYINPUT )
5319         {
5320             const KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode();
5321             if( rKey.GetCode() == KEY_F10 && rKey.GetModifier() &&
5322                 rKey.IsShift() && rKey.IsMod1() )
5323             {
5324                 pWrapper->SetFloatingMode( !pWrapper->IsFloatingMode() );
5325                 /* At this point the floating toolbar frame does not have the
5326                  * input focus since these frames don't get the focus per default
5327                  * To enable keyboard handling of this toolbar set the input focus
5328                  * to the frame. This needs to be done with ToTop since GrabFocus
5329                  * would not notice any change since "this" already has the focus.
5330                  */
5331                 if( pWrapper->IsFloatingMode() )
5332                     ToTop( TOTOP_GRABFOCUSONLY );
5333                 return sal_True;
5334             }
5335         }
5336     }
5337 
5338     // Dialog-Steuerung
5339     if ( (GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL )
5340     {
5341         // Wenn Parent auch DialogSteuerung aktiviert hat, uebernimmt dieser die Steuerung
5342         if ( (rNEvt.GetType() == EVENT_KEYINPUT) || (rNEvt.GetType() == EVENT_KEYUP) )
5343         {
5344             if ( ImplIsOverlapWindow() ||
5345                  ((ImplGetParent()->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) != WB_DIALOGCONTROL) )
5346             {
5347                 nRet = ImplDlgCtrl( *rNEvt.GetKeyEvent(), rNEvt.GetType() == EVENT_KEYINPUT );
5348             }
5349         }
5350         else if ( (rNEvt.GetType() == EVENT_GETFOCUS) || (rNEvt.GetType() == EVENT_LOSEFOCUS) )
5351         {
5352             ImplDlgCtrlFocusChanged( rNEvt.GetWindow(), rNEvt.GetType() == EVENT_GETFOCUS );
5353             if ( (rNEvt.GetWindow() == this) && (rNEvt.GetType() == EVENT_GETFOCUS) &&
5354                  !(GetStyle() & WB_TABSTOP) && !(mpWindowImpl->mnDlgCtrlFlags & WINDOW_DLGCTRL_WANTFOCUS) )
5355             {
5356                 sal_uInt16 n = 0;
5357                 Window* pFirstChild = ImplGetDlgWindow( n, DLGWINDOW_FIRST );
5358                 if ( pFirstChild )
5359                     pFirstChild->ImplControlFocus();
5360             }
5361         }
5362     }
5363 
5364     if ( !nRet )
5365     {
5366         if ( mpWindowImpl->mpParent && !ImplIsOverlapWindow() )
5367             nRet = mpWindowImpl->mpParent->Notify( rNEvt );
5368     }
5369 
5370     return nRet;
5371 }
5372 
5373 // -----------------------------------------------------------------------
5374 
5375 void Window::ImplCallEventListeners( sal_uLong nEvent, void* pData )
5376 {
5377 	// The implementation was moved to CallEventListeners(),
5378 	// because derived classes in svtools must be able to
5379 	// call the event listeners and ImplCallEventListeners()
5380 	// is not exported.
5381 	// TODO: replace ImplCallEventListeners() by CallEventListeners() in vcl
5382 
5383 	CallEventListeners( nEvent, pData );
5384 }
5385 
5386 // -----------------------------------------------------------------------
5387 
5388 void Window::CallEventListeners( sal_uLong nEvent, void* pData )
5389 {
5390     VclWindowEvent aEvent( this, nEvent, pData );
5391 
5392     ImplDelData aDelData;
5393     ImplAddDel( &aDelData );
5394 
5395     ImplGetSVData()->mpApp->ImplCallEventListeners( &aEvent );
5396 
5397     if ( aDelData.IsDelete() )
5398         return;
5399 
5400     if ( !mpWindowImpl->maEventListeners.empty() )
5401         mpWindowImpl->maEventListeners.Call( &aEvent );
5402 
5403     if ( aDelData.IsDelete() )
5404         return;
5405 
5406     ImplRemoveDel( &aDelData );
5407 
5408     Window* pWindow = this;
5409     while ( pWindow )
5410     {
5411         pWindow->ImplAddDel( &aDelData );
5412 
5413         if ( !pWindow->mpWindowImpl->maChildEventListeners.empty() )
5414             pWindow->mpWindowImpl->maChildEventListeners.Call( &aEvent );
5415 
5416         if ( aDelData.IsDelete() )
5417             return;
5418 
5419         pWindow->ImplRemoveDel( &aDelData );
5420 
5421         pWindow = pWindow->GetParent();
5422     }
5423 }
5424 
5425 void Window::FireVclEvent( VclSimpleEvent* pEvent )
5426 {
5427     ImplGetSVData()->mpApp->ImplCallEventListeners(pEvent);
5428 }
5429 
5430 // -----------------------------------------------------------------------
5431 
5432 void Window::AddEventListener( const Link& rEventListener )
5433 {
5434     mpWindowImpl->maEventListeners.push_back( rEventListener );
5435 }
5436 
5437 // -----------------------------------------------------------------------
5438 
5439 void Window::RemoveEventListener( const Link& rEventListener )
5440 {
5441     mpWindowImpl->maEventListeners.remove( rEventListener );
5442 }
5443 
5444 // -----------------------------------------------------------------------
5445 
5446 void Window::AddChildEventListener( const Link& rEventListener )
5447 {
5448     mpWindowImpl->maChildEventListeners.push_back( rEventListener );
5449 }
5450 
5451 // -----------------------------------------------------------------------
5452 
5453 void Window::RemoveChildEventListener( const Link& rEventListener )
5454 {
5455     mpWindowImpl->maChildEventListeners.remove( rEventListener );
5456 }
5457 
5458 // -----------------------------------------------------------------------
5459 
5460 sal_uLong Window::PostUserEvent( sal_uLong nEvent, void* pEventData )
5461 {
5462     sal_uLong nEventId;
5463     PostUserEvent( nEventId, nEvent, pEventData );
5464     return nEventId;
5465 }
5466 
5467 // -----------------------------------------------------------------------
5468 
5469 sal_uLong Window::PostUserEvent( const Link& rLink, void* pCaller )
5470 {
5471     sal_uLong nEventId;
5472     PostUserEvent( nEventId, rLink, pCaller );
5473     return nEventId;
5474 }
5475 
5476 // -----------------------------------------------------------------------
5477 
5478 sal_Bool Window::PostUserEvent( sal_uLong& rEventId, sal_uLong nEvent, void* pEventData )
5479 {
5480     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5481 
5482     ImplSVEvent* pSVEvent = new ImplSVEvent;
5483     pSVEvent->mnEvent   = nEvent;
5484     pSVEvent->mpData    = pEventData;
5485     pSVEvent->mpLink    = NULL;
5486     pSVEvent->mpWindow  = this;
5487     pSVEvent->mbCall    = sal_True;
5488     ImplAddDel( &(pSVEvent->maDelData) );
5489     rEventId = (sal_uLong)pSVEvent;
5490     if ( mpWindowImpl->mpFrame->PostEvent( pSVEvent ) )
5491         return sal_True;
5492     else
5493     {
5494         rEventId = 0;
5495         ImplRemoveDel( &(pSVEvent->maDelData) );
5496         delete pSVEvent;
5497         return sal_False;
5498     }
5499 }
5500 
5501 // -----------------------------------------------------------------------
5502 
5503 sal_Bool Window::PostUserEvent( sal_uLong& rEventId, const Link& rLink, void* pCaller )
5504 {
5505     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5506 
5507     ImplSVEvent* pSVEvent = new ImplSVEvent;
5508     pSVEvent->mnEvent   = 0;
5509     pSVEvent->mpData    = pCaller;
5510     pSVEvent->mpLink    = new Link( rLink );
5511     pSVEvent->mpWindow  = this;
5512     pSVEvent->mbCall    = sal_True;
5513     ImplAddDel( &(pSVEvent->maDelData) );
5514     rEventId = (sal_uLong)pSVEvent;
5515     if ( mpWindowImpl->mpFrame->PostEvent( pSVEvent ) )
5516         return sal_True;
5517     else
5518     {
5519         rEventId = 0;
5520         ImplRemoveDel( &(pSVEvent->maDelData) );
5521         delete pSVEvent;
5522         return sal_False;
5523     }
5524 }
5525 
5526 // -----------------------------------------------------------------------
5527 
5528 void Window::RemoveUserEvent( sal_uLong nUserEvent )
5529 {
5530     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5531 
5532     ImplSVEvent* pSVEvent = (ImplSVEvent*)nUserEvent;
5533 
5534     DBG_ASSERT( pSVEvent->mpWindow == this,
5535                 "Window::RemoveUserEvent(): Event doesn't send to this window or is already removed" );
5536     DBG_ASSERT( pSVEvent->mbCall,
5537                 "Window::RemoveUserEvent(): Event is already removed" );
5538 
5539     if ( pSVEvent->mpWindow )
5540     {
5541         pSVEvent->mpWindow->ImplRemoveDel( &(pSVEvent->maDelData) );
5542         pSVEvent->mpWindow = NULL;
5543     }
5544 
5545     pSVEvent->mbCall = sal_False;
5546 }
5547 
5548 // -----------------------------------------------------------------------
5549 
5550 IMPL_LINK( Window, ImplAsyncStateChangedHdl, void*, pState )
5551 {
5552     StateChanged( (StateChangedType)(sal_uLong)pState );
5553     return 0;
5554 }
5555 
5556 // -----------------------------------------------------------------------
5557 
5558 void Window::PostStateChanged( StateChangedType nState )
5559 {
5560     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5561 
5562     PostUserEvent( LINK( this, Window, ImplAsyncStateChangedHdl ), (void*)(sal_uLong)nState );
5563 }
5564 
5565 // -----------------------------------------------------------------------
5566 
5567 sal_Bool Window::IsLocked( sal_Bool bChilds ) const
5568 {
5569     if ( mpWindowImpl->mnLockCount != 0 )
5570         return sal_True;
5571 
5572     if ( bChilds || mpWindowImpl->mbChildNotify )
5573     {
5574         Window* pChild = mpWindowImpl->mpFirstChild;
5575         while ( pChild )
5576         {
5577             if ( pChild->IsLocked( sal_True ) )
5578                 return sal_True;
5579             pChild = pChild->mpWindowImpl->mpNext;
5580         }
5581     }
5582 
5583     return sal_False;
5584 }
5585 
5586 // -----------------------------------------------------------------------
5587 
5588 void Window::SetStyle( WinBits nStyle )
5589 {
5590     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5591 
5592     if ( mpWindowImpl->mnStyle != nStyle )
5593     {
5594         mpWindowImpl->mnPrevStyle = mpWindowImpl->mnStyle;
5595         mpWindowImpl->mnStyle = nStyle;
5596         StateChanged( STATE_CHANGE_STYLE );
5597     }
5598 }
5599 
5600 // -----------------------------------------------------------------------
5601 
5602 void Window::SetExtendedStyle( WinBits nExtendedStyle )
5603 {
5604     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5605 
5606     if ( mpWindowImpl->mnExtendedStyle != nExtendedStyle )
5607     {
5608         Window* pWindow = ImplGetBorderWindow();
5609         if( ! pWindow )
5610             pWindow = this;
5611         if( pWindow->mpWindowImpl->mbFrame )
5612         {
5613             SalExtStyle nExt = 0;
5614             if( (nExtendedStyle & WB_EXT_DOCUMENT) )
5615                 nExt |= SAL_FRAME_EXT_STYLE_DOCUMENT;
5616             if( (nExtendedStyle & WB_EXT_DOCMODIFIED) )
5617                 nExt |= SAL_FRAME_EXT_STYLE_DOCMODIFIED;
5618 
5619             pWindow->ImplGetFrame()->SetExtendedFrameStyle( nExt );
5620         }
5621         mpWindowImpl->mnPrevExtendedStyle = mpWindowImpl->mnExtendedStyle;
5622         mpWindowImpl->mnExtendedStyle = nExtendedStyle;
5623         StateChanged( STATE_CHANGE_EXTENDEDSTYLE );
5624     }
5625 }
5626 
5627 // -----------------------------------------------------------------------
5628 
5629 SystemWindow* Window::GetSystemWindow() const
5630 {
5631     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5632 
5633     const Window* pWin = this;
5634     while ( pWin && !pWin->IsSystemWindow() )
5635         pWin  = pWin->GetParent();
5636     return (SystemWindow*)pWin;
5637 }
5638 
5639 // -----------------------------------------------------------------------
5640 
5641 void Window::SetBorderStyle( sal_uInt16 nBorderStyle )
5642 {
5643     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5644 
5645     if ( mpWindowImpl->mpBorderWindow )
5646     {
5647         if( nBorderStyle == WINDOW_BORDER_REMOVEBORDER &&
5648             ! mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame &&
5649             mpWindowImpl->mpBorderWindow->mpWindowImpl->mpParent
5650             )
5651         {
5652             // this is a little awkward: some controls (e.g. svtools ProgressBar)
5653             // cannot avoid getting constructed with WB_BORDER but want to disable
5654             // borders in case of NWF drawing. So they need a method to remove their border window
5655             Window* pBorderWin = mpWindowImpl->mpBorderWindow;
5656             // remove us as border window's client
5657             pBorderWin->mpWindowImpl->mpClientWindow = NULL;
5658             mpWindowImpl->mpBorderWindow = NULL;
5659             mpWindowImpl->mpRealParent = pBorderWin->mpWindowImpl->mpParent;
5660             // reparent us above the border window
5661             SetParent( pBorderWin->mpWindowImpl->mpParent );
5662             // set us to the position and size of our previous border
5663             Point aBorderPos( pBorderWin->GetPosPixel() );
5664             Size aBorderSize( pBorderWin->GetSizePixel() );
5665             SetPosSizePixel( aBorderPos.X(), aBorderPos.Y(), aBorderSize.Width(), aBorderSize.Height() );
5666             // release border window
5667             delete pBorderWin;
5668 
5669             // set new style bits
5670             SetStyle( GetStyle() & (~WB_BORDER) );
5671         }
5672         else
5673         {
5674             if ( mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW )
5675                  ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->SetBorderStyle( nBorderStyle );
5676             else
5677                 mpWindowImpl->mpBorderWindow->SetBorderStyle( nBorderStyle );
5678         }
5679     }
5680 }
5681 
5682 // -----------------------------------------------------------------------
5683 
5684 sal_uInt16 Window::GetBorderStyle() const
5685 {
5686     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5687 
5688     if ( mpWindowImpl->mpBorderWindow )
5689     {
5690         if ( mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW )
5691             return ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->GetBorderStyle();
5692         else
5693             return mpWindowImpl->mpBorderWindow->GetBorderStyle();
5694     }
5695 
5696     return 0;
5697 }
5698 
5699 // -----------------------------------------------------------------------
5700 
5701 long Window::CalcTitleWidth() const
5702 {
5703     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5704 
5705     if ( mpWindowImpl->mpBorderWindow )
5706     {
5707         if ( mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW )
5708             return ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->CalcTitleWidth();
5709         else
5710             return mpWindowImpl->mpBorderWindow->CalcTitleWidth();
5711     }
5712     else if ( mpWindowImpl->mbFrame && (mpWindowImpl->mnStyle & WB_MOVEABLE) )
5713     {
5714         // Fuer Frame-Fenster raten wir die Breite, da wir den Border fuer
5715         // externe Dialoge nicht kennen
5716         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
5717         Font aFont = GetFont();
5718         ((Window*)this)->SetPointFont( rStyleSettings.GetTitleFont() );
5719         long nTitleWidth = GetTextWidth( GetText() );
5720         ((Window*)this)->SetFont( aFont );
5721         nTitleWidth += rStyleSettings.GetTitleHeight() * 3;
5722         nTitleWidth += rStyleSettings.GetBorderSize() * 2;
5723         nTitleWidth += 10;
5724         return nTitleWidth;
5725     }
5726 
5727     return 0;
5728 }
5729 
5730 // -----------------------------------------------------------------------
5731 
5732 void Window::EnableClipSiblings( sal_Bool bClipSiblings )
5733 {
5734     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5735 
5736     if ( mpWindowImpl->mpBorderWindow )
5737         mpWindowImpl->mpBorderWindow->EnableClipSiblings( bClipSiblings );
5738 
5739     mpWindowImpl->mbClipSiblings = bClipSiblings;
5740 }
5741 
5742 // -----------------------------------------------------------------------
5743 
5744 void Window::SetMouseTransparent( sal_Bool bTransparent )
5745 {
5746     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5747 
5748     if ( mpWindowImpl->mpBorderWindow )
5749         mpWindowImpl->mpBorderWindow->SetMouseTransparent( bTransparent );
5750 
5751     if( mpWindowImpl->mpSysObj )
5752         mpWindowImpl->mpSysObj->SetMouseTransparent( bTransparent );
5753 
5754     mpWindowImpl->mbMouseTransparent = bTransparent;
5755 }
5756 
5757 // -----------------------------------------------------------------------
5758 
5759 void Window::SetPaintTransparent( sal_Bool bTransparent )
5760 {
5761     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5762 
5763     // transparency is not useful for frames as the background would have to be provided by a different frame
5764     if( bTransparent && mpWindowImpl->mbFrame )
5765         return;
5766 
5767     if ( mpWindowImpl->mpBorderWindow )
5768         mpWindowImpl->mpBorderWindow->SetPaintTransparent( bTransparent );
5769 
5770     mpWindowImpl->mbPaintTransparent = bTransparent;
5771 }
5772 
5773 // -----------------------------------------------------------------------
5774 
5775 void Window::SetInputContext( const InputContext& rInputContext )
5776 {
5777     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5778 
5779     mpWindowImpl->maInputContext = rInputContext;
5780     if ( !mpWindowImpl->mbInFocusHdl && HasFocus() )
5781         ImplNewInputContext();
5782 }
5783 
5784 // -----------------------------------------------------------------------
5785 
5786 void Window::EndExtTextInput( sal_uInt16 nFlags )
5787 {
5788     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5789 
5790     if ( mpWindowImpl->mbExtTextInput )
5791         ImplGetFrame()->EndExtTextInput( nFlags );
5792 }
5793 
5794 // -----------------------------------------------------------------------
5795 
5796 void Window::SetCursorRect( const Rectangle* pRect, long nExtTextInputWidth )
5797 {
5798     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5799 
5800     ImplWinData* pWinData = ImplGetWinData();
5801     if ( pWinData->mpCursorRect )
5802     {
5803         if ( pRect )
5804             *pWinData->mpCursorRect = *pRect;
5805         else
5806         {
5807             delete pWinData->mpCursorRect;
5808             pWinData->mpCursorRect = NULL;
5809         }
5810     }
5811     else
5812     {
5813         if ( pRect )
5814             pWinData->mpCursorRect = new Rectangle( *pRect );
5815     }
5816 
5817     pWinData->mnCursorExtWidth = nExtTextInputWidth;
5818 
5819 }
5820 
5821 // -----------------------------------------------------------------------
5822 
5823 const Rectangle* Window::GetCursorRect() const
5824 {
5825     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5826 
5827     ImplWinData* pWinData = ImplGetWinData();
5828     return pWinData->mpCursorRect;
5829 }
5830 
5831 // -----------------------------------------------------------------------
5832 
5833 long Window::GetCursorExtTextInputWidth() const
5834 {
5835     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5836 
5837     ImplWinData* pWinData = ImplGetWinData();
5838     return pWinData->mnCursorExtWidth;
5839 }
5840 
5841 // -----------------------------------------------------------------------
5842 void Window::SetSettings( const AllSettings& rSettings )
5843 {
5844     SetSettings( rSettings, sal_False );
5845 }
5846 
5847 void Window::SetSettings( const AllSettings& rSettings, sal_Bool bChild )
5848 {
5849     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5850 
5851     if ( mpWindowImpl->mpBorderWindow )
5852     {
5853         mpWindowImpl->mpBorderWindow->SetSettings( rSettings, sal_False );
5854         if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) &&
5855              ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->mpMenuBarWindow )
5856             ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->mpMenuBarWindow->SetSettings( rSettings, sal_True );
5857     }
5858 
5859     AllSettings aOldSettings = maSettings;
5860     OutputDevice::SetSettings( rSettings );
5861     sal_uLong nChangeFlags = aOldSettings.GetChangeFlags( rSettings );
5862 
5863     // AppFont-Aufloesung und DPI-Aufloesung neu berechnen
5864     ImplInitResolutionSettings();
5865 
5866     if ( nChangeFlags )
5867     {
5868         DataChangedEvent aDCEvt( DATACHANGED_SETTINGS, &aOldSettings, nChangeFlags );
5869         DataChanged( aDCEvt );
5870     }
5871 
5872     if ( bChild || mpWindowImpl->mbChildNotify )
5873     {
5874         Window* pChild = mpWindowImpl->mpFirstChild;
5875         while ( pChild )
5876         {
5877             pChild->SetSettings( rSettings, bChild );
5878             pChild = pChild->mpWindowImpl->mpNext;
5879         }
5880     }
5881 }
5882 
5883 // -----------------------------------------------------------------------
5884 
5885 void Window::UpdateSettings( const AllSettings& rSettings, sal_Bool bChild )
5886 {
5887     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5888 
5889     if ( mpWindowImpl->mpBorderWindow )
5890     {
5891         mpWindowImpl->mpBorderWindow->UpdateSettings( rSettings, sal_False );
5892         if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) &&
5893              ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->mpMenuBarWindow )
5894             ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->mpMenuBarWindow->UpdateSettings( rSettings, sal_True );
5895     }
5896 
5897     AllSettings aOldSettings = maSettings;
5898     sal_uLong nChangeFlags = maSettings.Update( maSettings.GetWindowUpdate(), rSettings );
5899 	nChangeFlags |= SETTINGS_IN_UPDATE_SETTINGS; // Set this flag so the receiver of the data changed
5900                                                  // event can distinguish between the changing of global
5901                                                  // setting and a local change ( with SetSettings )
5902 
5903     // AppFont-Aufloesung und DPI-Aufloesung neu berechnen
5904     ImplInitResolutionSettings();
5905 
5906     /* #i73785#
5907     *  do not overwrite a WheelBehavior with false
5908     *  this looks kind of a hack, but WheelBehavior
5909     *  is always a local change, not a system property,
5910     *  so we can spare all our users the hassle of reacting on
5911     *  this in their respective DataChanged.
5912     */
5913     MouseSettings aSet( maSettings.GetMouseSettings() );
5914     aSet.SetWheelBehavior( aOldSettings.GetMouseSettings().GetWheelBehavior() );
5915     maSettings.SetMouseSettings( aSet );
5916 
5917     if( (nChangeFlags & SETTINGS_STYLE) && IsBackground() )
5918     {
5919         Wallpaper aWallpaper = GetBackground();
5920         if( !aWallpaper.IsBitmap() && !aWallpaper.IsGradient() )
5921         {
5922             if ( mpWindowImpl->mnStyle & WB_3DLOOK )
5923                 SetBackground( Wallpaper( rSettings.GetStyleSettings().GetFaceColor() ) );
5924             else
5925                 SetBackground( Wallpaper( rSettings.GetStyleSettings().GetWindowColor() ) );
5926         }
5927     }
5928 
5929     if ( nChangeFlags )
5930     {
5931         DataChangedEvent aDCEvt( DATACHANGED_SETTINGS, &aOldSettings, nChangeFlags );
5932         DataChanged( aDCEvt );
5933         // notify data change handler
5934         ImplCallEventListeners( VCLEVENT_WINDOW_DATACHANGED, &aDCEvt);
5935     }
5936 
5937     if ( bChild || mpWindowImpl->mbChildNotify )
5938     {
5939         Window* pChild = mpWindowImpl->mpFirstChild;
5940         while ( pChild )
5941         {
5942             pChild->UpdateSettings( rSettings, bChild );
5943             pChild = pChild->mpWindowImpl->mpNext;
5944         }
5945     }
5946 }
5947 
5948 // -----------------------------------------------------------------------
5949 
5950 void Window::NotifyAllChilds( DataChangedEvent& rDCEvt )
5951 {
5952     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5953 
5954     DataChanged( rDCEvt );
5955 
5956     Window* pChild = mpWindowImpl->mpFirstChild;
5957     while ( pChild )
5958     {
5959         pChild->NotifyAllChilds( rDCEvt );
5960         pChild = pChild->mpWindowImpl->mpNext;
5961     }
5962 }
5963 
5964 // -----------------------------------------------------------------------
5965 
5966 void Window::SetPointFont( const Font& rFont )
5967 {
5968     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5969 
5970     Font aFont = rFont;
5971     ImplPointToLogic( aFont );
5972     SetFont( aFont );
5973 }
5974 
5975 // -----------------------------------------------------------------------
5976 
5977 Font Window::GetPointFont() const
5978 {
5979     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5980 
5981     Font aFont = GetFont();
5982     ImplLogicToPoint( aFont );
5983     return aFont;
5984 }
5985 
5986 // -----------------------------------------------------------------------
5987 
5988 // TODO: remove in next incompatible build
5989 void Window::GetFontResolution( sal_Int32& nDPIX, sal_Int32& nDPIY ) const
5990 {
5991     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
5992 
5993     nDPIX = mpWindowImpl->mpFrameData->mnDPIX;
5994     nDPIY = mpWindowImpl->mpFrameData->mnDPIY;
5995 }
5996 
5997 // -----------------------------------------------------------------------
5998 
5999 void Window::SetParentClipMode( sal_uInt16 nMode )
6000 {
6001     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6002 
6003     if ( mpWindowImpl->mpBorderWindow )
6004         mpWindowImpl->mpBorderWindow->SetParentClipMode( nMode );
6005     else
6006     {
6007         if ( !ImplIsOverlapWindow() )
6008         {
6009             mpWindowImpl->mnParentClipMode = nMode;
6010             if ( nMode & PARENTCLIPMODE_CLIP )
6011                 mpWindowImpl->mpParent->mpWindowImpl->mbClipChildren = sal_True;
6012         }
6013     }
6014 }
6015 
6016 // -----------------------------------------------------------------------
6017 
6018 sal_uInt16 Window::GetParentClipMode() const
6019 {
6020     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6021 
6022     if ( mpWindowImpl->mpBorderWindow )
6023         return mpWindowImpl->mpBorderWindow->GetParentClipMode();
6024     else
6025         return mpWindowImpl->mnParentClipMode;
6026 }
6027 
6028 // -----------------------------------------------------------------------
6029 
6030 void Window::SetWindowRegionPixel()
6031 {
6032     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6033 
6034     if ( mpWindowImpl->mpBorderWindow )
6035         mpWindowImpl->mpBorderWindow->SetWindowRegionPixel();
6036     else if( mpWindowImpl->mbFrame )
6037     {
6038         mpWindowImpl->maWinRegion = Region( REGION_NULL);
6039         mpWindowImpl->mbWinRegion = sal_False;
6040         mpWindowImpl->mpFrame->ResetClipRegion();
6041     }
6042     else
6043     {
6044         if ( mpWindowImpl->mbWinRegion )
6045         {
6046             mpWindowImpl->maWinRegion = Region( REGION_NULL );
6047             mpWindowImpl->mbWinRegion = sal_False;
6048             ImplSetClipFlag();
6049 
6050             if ( IsReallyVisible() )
6051             {
6052                 // Hintergrund-Sicherung zuruecksetzen
6053                 if ( mpWindowImpl->mpOverlapData && mpWindowImpl->mpOverlapData->mpSaveBackDev )
6054                     ImplDeleteOverlapBackground();
6055                 if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
6056                     ImplInvalidateAllOverlapBackgrounds();
6057                 Rectangle   aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
6058                 Region      aRegion( aRect );
6059                 ImplInvalidateParentFrameRegion( aRegion );
6060             }
6061         }
6062     }
6063 }
6064 
6065 // -----------------------------------------------------------------------
6066 
6067 void Window::SetWindowRegionPixel( const Region& rRegion )
6068 {
6069     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6070 
6071     if ( mpWindowImpl->mpBorderWindow )
6072         mpWindowImpl->mpBorderWindow->SetWindowRegionPixel( rRegion );
6073     else if( mpWindowImpl->mbFrame )
6074     {
6075         if( rRegion.GetType() != REGION_NULL )
6076         {
6077             mpWindowImpl->maWinRegion = rRegion;
6078             mpWindowImpl->mbWinRegion = ! rRegion.IsEmpty();
6079             if( mpWindowImpl->mbWinRegion )
6080             {
6081                 // ClipRegion setzen/updaten
6082                 long                nX;
6083                 long                nY;
6084                 long                nWidth;
6085                 long                nHeight;
6086                 sal_uLong               nRectCount;
6087                 ImplRegionInfo      aInfo;
6088                 sal_Bool                bRegionRect;
6089 
6090                 nRectCount = mpWindowImpl->maWinRegion.GetRectCount();
6091                 mpWindowImpl->mpFrame->BeginSetClipRegion( nRectCount );
6092                 bRegionRect = mpWindowImpl->maWinRegion.ImplGetFirstRect( aInfo, nX, nY, nWidth, nHeight );
6093                 while ( bRegionRect )
6094                 {
6095                     mpWindowImpl->mpFrame->UnionClipRegion( nX, nY, nWidth, nHeight );
6096                     bRegionRect = mpWindowImpl->maWinRegion.ImplGetNextRect( aInfo, nX, nY, nWidth, nHeight );
6097                 }
6098                 mpWindowImpl->mpFrame->EndSetClipRegion();
6099             }
6100             else
6101                 SetWindowRegionPixel();
6102         }
6103         else
6104             SetWindowRegionPixel();
6105     }
6106     else
6107     {
6108         sal_Bool bInvalidate = sal_False;
6109 
6110         if ( rRegion.GetType() == REGION_NULL )
6111         {
6112             if ( mpWindowImpl->mbWinRegion )
6113             {
6114                 mpWindowImpl->maWinRegion = Region( REGION_NULL );
6115                 mpWindowImpl->mbWinRegion = sal_False;
6116                 ImplSetClipFlag();
6117                 bInvalidate = sal_True;
6118             }
6119         }
6120         else
6121         {
6122             mpWindowImpl->maWinRegion = rRegion;
6123             mpWindowImpl->mbWinRegion = sal_True;
6124             ImplSetClipFlag();
6125             bInvalidate = sal_True;
6126         }
6127 
6128         if ( IsReallyVisible() )
6129         {
6130             // Hintergrund-Sicherung zuruecksetzen
6131             if ( mpWindowImpl->mpOverlapData && mpWindowImpl->mpOverlapData->mpSaveBackDev )
6132                 ImplDeleteOverlapBackground();
6133             if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
6134                 ImplInvalidateAllOverlapBackgrounds();
6135             Rectangle   aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
6136             Region      aRegion( aRect );
6137             ImplInvalidateParentFrameRegion( aRegion );
6138         }
6139     }
6140 }
6141 
6142 // -----------------------------------------------------------------------
6143 
6144 const Region& Window::GetWindowRegionPixel() const
6145 {
6146     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6147 
6148     if ( mpWindowImpl->mpBorderWindow )
6149         return mpWindowImpl->mpBorderWindow->GetWindowRegionPixel();
6150     else
6151         return mpWindowImpl->maWinRegion;
6152 }
6153 
6154 // -----------------------------------------------------------------------
6155 
6156 sal_Bool Window::IsWindowRegionPixel() const
6157 {
6158     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6159 
6160     if ( mpWindowImpl->mpBorderWindow )
6161         return mpWindowImpl->mpBorderWindow->IsWindowRegionPixel();
6162     else
6163         return mpWindowImpl->mbWinRegion;
6164 }
6165 
6166 // -----------------------------------------------------------------------
6167 
6168 Region Window::GetWindowClipRegionPixel( sal_uInt16 nFlags ) const
6169 {
6170     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6171 
6172     Region aWinClipRegion;
6173 
6174     if ( nFlags & WINDOW_GETCLIPREGION_NOCHILDREN )
6175     {
6176         if ( mpWindowImpl->mbInitWinClipRegion )
6177             ((Window*)this)->ImplInitWinClipRegion();
6178         aWinClipRegion = mpWindowImpl->maWinClipRegion;
6179     }
6180     else
6181     {
6182         Region* pWinChildClipRegion = ((Window*)this)->ImplGetWinChildClipRegion();
6183         aWinClipRegion = *pWinChildClipRegion;
6184         // --- RTL --- remirror clip region before passing it to somebody
6185         if( ImplIsAntiparallel() )
6186             ImplReMirror( aWinClipRegion );
6187     }
6188 
6189     if ( nFlags & WINDOW_GETCLIPREGION_NULL )
6190     {
6191         Rectangle   aWinRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
6192         Region      aWinRegion( aWinRect );
6193 
6194         if ( aWinRegion == aWinClipRegion )
6195             aWinClipRegion.SetNull();
6196     }
6197 
6198     aWinClipRegion.Move( -mnOutOffX, -mnOutOffY );
6199 
6200     return aWinClipRegion;
6201 }
6202 
6203 // -----------------------------------------------------------------------
6204 
6205 Region Window::GetPaintRegion() const
6206 {
6207     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6208 
6209     if ( mpWindowImpl->mpPaintRegion )
6210     {
6211         Region aRegion = *mpWindowImpl->mpPaintRegion;
6212         aRegion.Move( -mnOutOffX, -mnOutOffY );
6213         return PixelToLogic( aRegion );
6214     }
6215     else
6216     {
6217         Region aPaintRegion( REGION_NULL );
6218         return aPaintRegion;
6219     }
6220 }
6221 
6222 // -----------------------------------------------------------------------
6223 
6224 void Window::ExpandPaintClipRegion( const Region& rRegion )
6225 {
6226     if( mpWindowImpl->mpPaintRegion )
6227     {
6228         Region aPixRegion = LogicToPixel( rRegion );
6229         Region aDevPixRegion = ImplPixelToDevicePixel( aPixRegion );
6230 
6231         Region aWinChildRegion = *ImplGetWinChildClipRegion();
6232         // --- RTL -- only this region is in frame coordinates, so re-mirror it
6233         if( ImplIsAntiparallel() )
6234             ImplReMirror( aWinChildRegion );
6235         aDevPixRegion.Intersect( aWinChildRegion );
6236         if( ! aDevPixRegion.IsEmpty() )
6237         {
6238             mpWindowImpl->mpPaintRegion->Union( aDevPixRegion );
6239             mbInitClipRegion = sal_True;
6240         }
6241     }
6242 }
6243 
6244 // -----------------------------------------------------------------------
6245 
6246 static SystemWindow *ImplGetLastSystemWindow( Window *pWin )
6247 {
6248     // get the most top-level system window, the one that contains the taskpanelist
6249     SystemWindow *pSysWin = NULL;
6250     if( !pWin )
6251         return pSysWin;
6252     Window *pMyParent = pWin;
6253     while ( pMyParent )
6254     {
6255         if ( pMyParent->IsSystemWindow() )
6256             pSysWin = (SystemWindow*)pMyParent;
6257         pMyParent = pMyParent->GetParent();
6258     }
6259     return pSysWin;
6260 }
6261 
6262 void Window::SetParent( Window* pNewParent )
6263 {
6264     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6265     DBG_ASSERT( pNewParent, "Window::SetParent(): pParent == NULL" );
6266     DBG_ASSERT( pNewParent != this, "someone tried to reparent a window to itself" );
6267 
6268     if( pNewParent == this )
6269         return;
6270 
6271     // check if the taskpanelist would change and move the window pointer accordingly
6272     SystemWindow *pSysWin = ImplGetLastSystemWindow(this);
6273     SystemWindow *pNewSysWin = NULL;
6274     sal_Bool bChangeTaskPaneList = sal_False;
6275     if( pSysWin && pSysWin->ImplIsInTaskPaneList( this ) )
6276     {
6277         pNewSysWin = ImplGetLastSystemWindow( pNewParent );
6278         if( pNewSysWin && pNewSysWin != pSysWin )
6279         {
6280             bChangeTaskPaneList = sal_True;
6281             pSysWin->GetTaskPaneList()->RemoveWindow( this );
6282         }
6283     }
6284     // remove ownerdraw decorated windows from list in the top-most frame window
6285     if( (GetStyle() & WB_OWNERDRAWDECORATION) && mpWindowImpl->mbFrame )
6286     {
6287         ::std::vector< Window* >& rList = ImplGetOwnerDrawList();
6288 	    ::std::vector< Window* >::iterator p;
6289         p = ::std::find( rList.begin(), rList.end(), this );
6290         if( p != rList.end() )
6291 	        rList.erase( p );
6292     }
6293 
6294     ImplSetFrameParent( pNewParent );
6295 
6296     if ( mpWindowImpl->mpBorderWindow )
6297     {
6298         mpWindowImpl->mpRealParent = pNewParent;
6299         mpWindowImpl->mpBorderWindow->SetParent( pNewParent );
6300         return;
6301     }
6302 
6303     if ( mpWindowImpl->mpParent == pNewParent )
6304         return;
6305 
6306     if ( mpWindowImpl->mbFrame )
6307         mpWindowImpl->mpFrame->SetParent( pNewParent->mpWindowImpl->mpFrame );
6308 
6309     sal_Bool bVisible = IsVisible();
6310     Show( sal_False, SHOW_NOFOCUSCHANGE );
6311 
6312     // Testen, ob sich das Overlap-Window aendert
6313     Window* pOldOverlapWindow;
6314     Window* pNewOverlapWindow = NULL;
6315     if ( ImplIsOverlapWindow() )
6316         pOldOverlapWindow = NULL;
6317     else
6318     {
6319         pNewOverlapWindow = pNewParent->ImplGetFirstOverlapWindow();
6320         if ( mpWindowImpl->mpOverlapWindow != pNewOverlapWindow )
6321             pOldOverlapWindow = mpWindowImpl->mpOverlapWindow;
6322         else
6323             pOldOverlapWindow = NULL;
6324     }
6325 
6326     // Fenster in der Hirachie umsetzen
6327     sal_Bool bFocusOverlapWin = HasChildPathFocus( sal_True );
6328     sal_Bool bFocusWin = HasChildPathFocus();
6329     sal_Bool bNewFrame = pNewParent->mpWindowImpl->mpFrameWindow != mpWindowImpl->mpFrameWindow;
6330     if ( bNewFrame )
6331     {
6332         if ( mpWindowImpl->mpFrameData->mpFocusWin )
6333         {
6334             if ( IsWindowOrChild( mpWindowImpl->mpFrameData->mpFocusWin ) )
6335                 mpWindowImpl->mpFrameData->mpFocusWin = NULL;
6336         }
6337         if ( mpWindowImpl->mpFrameData->mpMouseMoveWin )
6338         {
6339             if ( IsWindowOrChild( mpWindowImpl->mpFrameData->mpMouseMoveWin ) )
6340                 mpWindowImpl->mpFrameData->mpMouseMoveWin = NULL;
6341         }
6342         if ( mpWindowImpl->mpFrameData->mpMouseDownWin )
6343         {
6344             if ( IsWindowOrChild( mpWindowImpl->mpFrameData->mpMouseDownWin ) )
6345                 mpWindowImpl->mpFrameData->mpMouseDownWin = NULL;
6346         }
6347     }
6348     ImplRemoveWindow( bNewFrame );
6349     ImplInsertWindow( pNewParent );
6350     if ( mpWindowImpl->mnParentClipMode & PARENTCLIPMODE_CLIP )
6351         pNewParent->mpWindowImpl->mbClipChildren = sal_True;
6352     ImplUpdateWindowPtr();
6353     if ( ImplUpdatePos() )
6354         ImplUpdateSysObjPos();
6355 
6356     // Wenn sich das Overlap-Window geaendert hat, dann muss getestet werden,
6357     // ob auch OverlapWindow die das Child-Fenster als Parent gehabt haben
6358     // in der Window-Hirachie umgesetzt werden muessen
6359     if ( ImplIsOverlapWindow() )
6360     {
6361         if ( bNewFrame )
6362         {
6363             Window* pOverlapWindow = mpWindowImpl->mpFirstOverlap;
6364             while ( pOverlapWindow )
6365             {
6366                 Window* pNextOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
6367                 pOverlapWindow->ImplUpdateOverlapWindowPtr( bNewFrame );
6368                 pOverlapWindow = pNextOverlapWindow;
6369             }
6370         }
6371     }
6372     else if ( pOldOverlapWindow )
6373     {
6374         // Focus-Save zuruecksetzen
6375         if ( bFocusWin ||
6376              (pOldOverlapWindow->mpWindowImpl->mpLastFocusWindow &&
6377               IsWindowOrChild( pOldOverlapWindow->mpWindowImpl->mpLastFocusWindow )) )
6378             pOldOverlapWindow->mpWindowImpl->mpLastFocusWindow = NULL;
6379 
6380         Window* pOverlapWindow = pOldOverlapWindow->mpWindowImpl->mpFirstOverlap;
6381         while ( pOverlapWindow )
6382         {
6383             Window* pNextOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
6384             if ( ImplIsRealParentPath( pOverlapWindow->ImplGetWindow() ) )
6385                 pOverlapWindow->ImplUpdateOverlapWindowPtr( bNewFrame );
6386             pOverlapWindow = pNextOverlapWindow;
6387         }
6388 
6389         // Activate-Status beim naechsten Overlap-Window updaten
6390         if ( HasChildPathFocus( sal_True ) )
6391             ImplCallFocusChangeActivate( pNewOverlapWindow, pOldOverlapWindow );
6392     }
6393 
6394     // Activate-Status mit umsetzen
6395     if ( bNewFrame )
6396     {
6397         if ( (GetType() == WINDOW_BORDERWINDOW) &&
6398              (ImplGetWindow()->GetType() == WINDOW_FLOATINGWINDOW) )
6399             ((ImplBorderWindow*)this)->SetDisplayActive( mpWindowImpl->mpFrameData->mbHasFocus );
6400     }
6401 
6402     // Focus evtl. auf den neuen Frame umsetzen, wenn FocusWindow mit
6403     // SetParent() umgesetzt wird
6404     if ( bFocusOverlapWin )
6405     {
6406         mpWindowImpl->mpFrameData->mpFocusWin = Application::GetFocusWindow();
6407         if ( !mpWindowImpl->mpFrameData->mbHasFocus )
6408         {
6409             mpWindowImpl->mpFrame->ToTop( 0 );
6410         }
6411     }
6412 
6413     // Assure DragSource and DropTarget members are created
6414     if ( bNewFrame )
6415     {
6416             GetDropTarget();
6417     }
6418 
6419     if( bChangeTaskPaneList )
6420         pNewSysWin->GetTaskPaneList()->AddWindow( this );
6421 
6422 	if( (GetStyle() & WB_OWNERDRAWDECORATION) && mpWindowImpl->mbFrame )
6423         ImplGetOwnerDrawList().push_back( this );
6424 
6425     if ( bVisible )
6426         Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
6427 }
6428 
6429 // -----------------------------------------------------------------------
6430 
6431 void Window::Show( sal_Bool bVisible, sal_uInt16 nFlags )
6432 {
6433     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6434 
6435     if ( mpWindowImpl->mbVisible == bVisible )
6436         return;
6437 
6438     ImplDelData aDogTag( this );
6439 
6440     sal_Bool bRealVisibilityChanged = sal_False;
6441     mpWindowImpl->mbVisible = (bVisible != 0);
6442 
6443     if ( !bVisible )
6444     {
6445         ImplHideAllOverlaps();
6446         if( aDogTag.IsDelete() )
6447             return;
6448 
6449         if ( mpWindowImpl->mpBorderWindow )
6450         {
6451             sal_Bool bOldUpdate = mpWindowImpl->mpBorderWindow->mpWindowImpl->mbNoParentUpdate;
6452             if ( mpWindowImpl->mbNoParentUpdate )
6453                 mpWindowImpl->mpBorderWindow->mpWindowImpl->mbNoParentUpdate = sal_True;
6454             mpWindowImpl->mpBorderWindow->Show( sal_False, nFlags );
6455             mpWindowImpl->mpBorderWindow->mpWindowImpl->mbNoParentUpdate = bOldUpdate;
6456         }
6457         else if ( mpWindowImpl->mbFrame )
6458         {
6459             mpWindowImpl->mbSuppressAccessibilityEvents = sal_True;
6460             mpWindowImpl->mpFrame->Show( sal_False, sal_False );
6461         }
6462 
6463         StateChanged( STATE_CHANGE_VISIBLE );
6464 
6465         if ( mpWindowImpl->mbReallyVisible )
6466         {
6467             Region  aInvRegion( REGION_EMPTY );
6468             sal_Bool    bSaveBack = sal_False;
6469 
6470             if ( ImplIsOverlapWindow() && !mpWindowImpl->mbFrame )
6471             {
6472                 if ( ImplRestoreOverlapBackground( aInvRegion ) )
6473                     bSaveBack = sal_True;
6474             }
6475 
6476             if ( !bSaveBack )
6477             {
6478                 if ( mpWindowImpl->mbInitWinClipRegion )
6479                     ImplInitWinClipRegion();
6480                 aInvRegion = mpWindowImpl->maWinClipRegion;
6481             }
6482 
6483             if( aDogTag.IsDelete() )
6484                 return;
6485 
6486             bRealVisibilityChanged = mpWindowImpl->mbReallyVisible;
6487             ImplResetReallyVisible();
6488             ImplSetClipFlag();
6489 
6490             if ( ImplIsOverlapWindow() && !mpWindowImpl->mbFrame )
6491             {
6492                 // Focus umsetzen
6493                 if ( !(nFlags & SHOW_NOFOCUSCHANGE) && HasChildPathFocus() )
6494                 {
6495                     if ( mpWindowImpl->mpOverlapWindow->IsEnabled() &&
6496                          mpWindowImpl->mpOverlapWindow->IsInputEnabled() &&
6497                          ! mpWindowImpl->mpOverlapWindow->IsInModalMode()
6498                          )
6499                         mpWindowImpl->mpOverlapWindow->GrabFocus();
6500                 }
6501             }
6502 
6503             if ( !mpWindowImpl->mbFrame )
6504             {
6505                 if( mpWindowImpl->mpWinData && mpWindowImpl->mpWinData->mbEnableNativeWidget )
6506                 {
6507                     /*
6508                     * #i48371# native theming: some themes draw outside the control
6509                     * area we tell them to (bad thing, but we cannot do much about it ).
6510                     * On hiding these controls they get invalidated with their window rectangle
6511                     * which leads to the parts outside the control area being left and not
6512                     * invalidated. Workaround: invalidate an area on the parent, too
6513                     */
6514                     const int workaround_border = 5;
6515                     Rectangle aBounds( aInvRegion.GetBoundRect() );
6516                     aBounds.Left()      -= workaround_border;
6517                     aBounds.Top()       -= workaround_border;
6518                     aBounds.Right()     += workaround_border;
6519                     aBounds.Bottom()    += workaround_border;
6520                     aInvRegion = aBounds;
6521                 }
6522                 if ( !mpWindowImpl->mbNoParentUpdate && !(nFlags & SHOW_NOPARENTUPDATE) )
6523                 {
6524                     if ( !aInvRegion.IsEmpty() )
6525                         ImplInvalidateParentFrameRegion( aInvRegion );
6526                 }
6527                 ImplGenerateMouseMove();
6528             }
6529         }
6530     }
6531     else
6532     {
6533         // inherit native widget flag for form controls
6534         // required here, because frames never show up in the child hierarchy - which should be fixed....
6535         // eg, the drop down of a combobox which is a system floating window
6536         if( mpWindowImpl->mbFrame && GetParent() && GetParent()->IsCompoundControl() &&
6537             GetParent()->IsNativeWidgetEnabled() != IsNativeWidgetEnabled() )
6538             EnableNativeWidget( GetParent()->IsNativeWidgetEnabled() );
6539 
6540         if ( mpWindowImpl->mbCallMove )
6541         {
6542             ImplCallMove();
6543         }
6544         if ( mpWindowImpl->mbCallResize )
6545         {
6546             ImplCallResize();
6547         }
6548 
6549         StateChanged( STATE_CHANGE_VISIBLE );
6550 
6551         Window* pTestParent;
6552         if ( ImplIsOverlapWindow() )
6553             pTestParent = mpWindowImpl->mpOverlapWindow;
6554         else
6555             pTestParent = ImplGetParent();
6556         if ( mpWindowImpl->mbFrame || pTestParent->mpWindowImpl->mbReallyVisible )
6557         {
6558             // Wenn ein Window gerade sichtbar wird, schicken wir allen
6559             // Child-Fenstern ein StateChanged, damit diese sich
6560             // initialisieren koennen
6561             ImplCallInitShow();
6562 
6563             // Wenn es ein SystemWindow ist, dann kommt es auch automatisch
6564             // nach vorne, wenn es gewuenscht ist
6565             if ( ImplIsOverlapWindow() && !(nFlags & SHOW_NOACTIVATE) )
6566             {
6567                 ImplStartToTop(( nFlags & SHOW_FOREGROUNDTASK ) ? TOTOP_FOREGROUNDTASK : 0 );
6568                 ImplFocusToTop( 0, sal_False );
6569             }
6570 
6571             // Hintergrund sichern
6572             if ( mpWindowImpl->mpOverlapData && mpWindowImpl->mpOverlapData->mbSaveBack )
6573                 ImplSaveOverlapBackground();
6574             // adjust mpWindowImpl->mbReallyVisible
6575             bRealVisibilityChanged = !mpWindowImpl->mbReallyVisible;
6576             ImplSetReallyVisible();
6577 
6578             // Dafuer sorgen, das Clip-Rechtecke neu berechnet werden
6579             ImplSetClipFlag();
6580 
6581             if ( !mpWindowImpl->mbFrame )
6582             {
6583                 sal_uInt16 nInvalidateFlags = INVALIDATE_CHILDREN;
6584                 if( ! IsPaintTransparent() )
6585                     nInvalidateFlags |= INVALIDATE_NOTRANSPARENT;
6586                 ImplInvalidate( NULL, nInvalidateFlags );
6587                 ImplGenerateMouseMove();
6588             }
6589         }
6590 
6591         if ( mpWindowImpl->mpBorderWindow )
6592             mpWindowImpl->mpBorderWindow->Show( sal_True, nFlags );
6593         else if ( mpWindowImpl->mbFrame )
6594         {
6595             ImplSVData* pSVData = ImplGetSVData();
6596             // #106431#, hide SplashScreen
6597             if( pSVData->mpIntroWindow && !ImplIsWindowOrChild( pSVData->mpIntroWindow ) )
6598                 pSVData->mpIntroWindow->Hide();
6599 
6600             //DBG_ASSERT( !mpWindowImpl->mbSuppressAccessibilityEvents, "Window::Show() - Frame reactivated");
6601             mpWindowImpl->mbSuppressAccessibilityEvents = sal_False;
6602 
6603             mpWindowImpl->mbPaintFrame = sal_True;
6604             sal_Bool bNoActivate = (nFlags & (SHOW_NOACTIVATE|SHOW_NOFOCUSCHANGE)) ? sal_True : sal_False;
6605             mpWindowImpl->mpFrame->Show( sal_True, bNoActivate );
6606             if( aDogTag.IsDelete() )
6607                 return;
6608 
6609             // Query the correct size of the window, if we are waiting for
6610             // a system resize
6611             if ( mpWindowImpl->mbWaitSystemResize )
6612             {
6613                 long nOutWidth;
6614                 long nOutHeight;
6615                 mpWindowImpl->mpFrame->GetClientSize( nOutWidth, nOutHeight );
6616                 ImplHandleResize( this, nOutWidth, nOutHeight );
6617             }
6618         }
6619 
6620         if( aDogTag.IsDelete() )
6621             return;
6622 
6623 #ifdef DBG_UTIL
6624         if ( IsDialog() || (GetType() == WINDOW_TABPAGE) || (GetType() == WINDOW_DOCKINGWINDOW) )
6625         {
6626             DBG_DIALOGTEST( this );
6627         }
6628 #endif
6629 
6630         ImplShowAllOverlaps();
6631     }
6632 
6633     if( aDogTag.IsDelete() )
6634         return;
6635     // invalidate all saved backgrounds
6636     if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
6637         ImplInvalidateAllOverlapBackgrounds();
6638 
6639     // the SHOW/HIDE events also serve as indicators to send child creation/destroy events to the access bridge
6640     // However, the access bridge only uses this event if the data member is not NULL (it's kind of a hack that
6641     // we re-use the SHOW/HIDE events this way, with this particular semantics).
6642     // Since #104887#, the notifications for the access bridge are done in Impl(Set|Reset)ReallyVisible. Here, we
6643     // now only notify with a NULL data pointer, for all other clients except the access bridge.
6644     if ( !bRealVisibilityChanged )
6645         ImplCallEventListeners( mpWindowImpl->mbVisible ? VCLEVENT_WINDOW_SHOW : VCLEVENT_WINDOW_HIDE, NULL );
6646     if( aDogTag.IsDelete() )
6647         return;
6648 
6649     // #107575#, if a floating windows is shown that grabs the focus, we have to notify the toolkit about it
6650     // ImplGrabFocus() is not called in this case
6651     // Because this might lead to problems the task will be shifted to 6.y
6652     // Note: top-level context menues are registered at the access bridge after being shown,
6653     // so this will probably not help here....
6654     /*
6655     if( mpWindowImpl->mbFloatWin && ((FloatingWindow*) this )->GrabsFocus() )
6656     {
6657         ImplSVData* pSVData = ImplGetSVData();
6658         if( !mpWindowImpl->mbVisible )
6659         {
6660             ImplCallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS );
6661             if( pSVData->maWinData.mpFocusWin )
6662                 pSVData->maWinData.mpFocusWin->ImplCallEventListeners( VCLEVENT_WINDOW_GETFOCUS );
6663         }
6664         else
6665         {
6666             if( pSVData->maWinData.mpFocusWin )
6667                 pSVData->maWinData.mpFocusWin->ImplCallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS );
6668             ImplCallEventListeners( VCLEVENT_WINDOW_GETFOCUS );
6669         }
6670     }
6671     */
6672 }
6673 
6674 // -----------------------------------------------------------------------
6675 
6676 Size Window::GetSizePixel() const
6677 {
6678     // #i43257# trigger pending resize handler to assure correct window sizes
6679     if( mpWindowImpl->mpFrameData->maResizeTimer.IsActive() )
6680     {
6681         ImplDelData aDogtag( this );
6682         mpWindowImpl->mpFrameData->maResizeTimer.Stop();
6683         mpWindowImpl->mpFrameData->maResizeTimer.GetTimeoutHdl().Call( NULL );
6684         if( aDogtag.IsDelete() )
6685             return Size(0,0);
6686     }
6687 
6688     return Size( mnOutWidth+mpWindowImpl->mnLeftBorder+mpWindowImpl->mnRightBorder,
6689                  mnOutHeight+mpWindowImpl->mnTopBorder+mpWindowImpl->mnBottomBorder );
6690 }
6691 
6692 void Window::GetBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder,
6693                                sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const
6694 {
6695     rLeftBorder     = mpWindowImpl->mnLeftBorder;
6696     rTopBorder      = mpWindowImpl->mnTopBorder;
6697     rRightBorder    = mpWindowImpl->mnRightBorder;
6698     rBottomBorder   = mpWindowImpl->mnBottomBorder;
6699 }
6700 
6701 
6702 // -----------------------------------------------------------------------
6703 
6704 void Window::Enable( bool bEnable, bool bChild )
6705 {
6706     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6707 
6708     if ( !bEnable )
6709     {
6710         // Wenn ein Fenster disablte wird, wird automatisch der Tracking-Modus
6711         // beendet oder der Capture geklaut
6712         if ( IsTracking() )
6713             EndTracking( ENDTRACK_CANCEL );
6714         if ( IsMouseCaptured() )
6715             ReleaseMouse();
6716         // Wenn Fenster den Focus hat und in der Dialog-Steuerung enthalten,
6717         // wird versucht, den Focus auf das naechste Control weiterzuschalten
6718         // mpWindowImpl->mbDisabled darf erst nach Aufruf von ImplDlgCtrlNextWindow() gesetzt
6719         // werden. Ansonsten muss ImplDlgCtrlNextWindow() umgestellt werden
6720         if ( HasFocus() )
6721             ImplDlgCtrlNextWindow();
6722     }
6723 
6724     if ( mpWindowImpl->mpBorderWindow )
6725     {
6726         mpWindowImpl->mpBorderWindow->Enable( bEnable, sal_False );
6727         if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) &&
6728              ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->mpMenuBarWindow )
6729             ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->mpMenuBarWindow->Enable( bEnable, sal_True );
6730     }
6731 
6732     // #i56102# restore app focus win in case the
6733     // window was disabled when the frame focus changed
6734     ImplSVData* pSVData = ImplGetSVData();
6735     if( bEnable &&
6736         pSVData->maWinData.mpFocusWin == NULL &&
6737         mpWindowImpl->mpFrameData->mbHasFocus &&
6738         mpWindowImpl->mpFrameData->mpFocusWin == this )
6739         pSVData->maWinData.mpFocusWin = this;
6740 
6741     if ( mpWindowImpl->mbDisabled != !bEnable )
6742     {
6743         mpWindowImpl->mbDisabled = !bEnable;
6744         if ( mpWindowImpl->mpSysObj )
6745             mpWindowImpl->mpSysObj->Enable( bEnable && !mpWindowImpl->mbInputDisabled );
6746 //      if ( mpWindowImpl->mbFrame )
6747 //          mpWindowImpl->mpFrame->Enable( bEnable && !mpWindowImpl->mbInputDisabled );
6748         StateChanged( STATE_CHANGE_ENABLE );
6749 
6750         ImplCallEventListeners( bEnable ? VCLEVENT_WINDOW_ENABLED : VCLEVENT_WINDOW_DISABLED );
6751     }
6752 
6753     if ( bChild || mpWindowImpl->mbChildNotify )
6754     {
6755         Window* pChild = mpWindowImpl->mpFirstChild;
6756         while ( pChild )
6757         {
6758             pChild->Enable( bEnable, bChild );
6759             pChild = pChild->mpWindowImpl->mpNext;
6760         }
6761     }
6762 
6763     if ( IsReallyVisible() )
6764         ImplGenerateMouseMove();
6765 }
6766 
6767 // -----------------------------------------------------------------------
6768 
6769 void Window::SetCallHandlersOnInputDisabled( bool bCall )
6770 {
6771     mpWindowImpl->mbCallHandlersDuringInputDisabled = bCall ? sal_True : sal_False;
6772 
6773     Window* pChild = mpWindowImpl->mpFirstChild;
6774     while ( pChild )
6775     {
6776         pChild->SetCallHandlersOnInputDisabled( bCall );
6777         pChild = pChild->mpWindowImpl->mpNext;
6778     }
6779 }
6780 
6781 // -----------------------------------------------------------------------
6782 
6783 bool Window::IsCallHandlersOnInputDisabled() const
6784 {
6785     return mpWindowImpl->mbCallHandlersDuringInputDisabled ? true : false;
6786 }
6787 
6788 // -----------------------------------------------------------------------
6789 
6790 void Window::EnableInput( sal_Bool bEnable, sal_Bool bChild )
6791 {
6792     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6793 
6794     sal_Bool bNotify = (bEnable != mpWindowImpl->mbInputDisabled);
6795     if ( mpWindowImpl->mpBorderWindow )
6796     {
6797         mpWindowImpl->mpBorderWindow->EnableInput( bEnable, sal_False );
6798         if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) &&
6799              ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->mpMenuBarWindow )
6800             ((ImplBorderWindow*)mpWindowImpl->mpBorderWindow)->mpMenuBarWindow->EnableInput( bEnable, sal_True );
6801     }
6802 
6803     if ( (! bEnable && mpWindowImpl->meAlwaysInputMode != AlwaysInputEnabled) ||
6804          (  bEnable && mpWindowImpl->meAlwaysInputMode != AlwaysInputDisabled) )
6805     {
6806         // Wenn ein Fenster disablte wird, wird automatisch der
6807         // Tracking-Modus beendet oder der Capture geklaut
6808         if ( !bEnable )
6809         {
6810             if ( IsTracking() )
6811                 EndTracking( ENDTRACK_CANCEL );
6812             if ( IsMouseCaptured() )
6813                 ReleaseMouse();
6814         }
6815 
6816         if ( mpWindowImpl->mbInputDisabled != !bEnable )
6817         {
6818             mpWindowImpl->mbInputDisabled = !bEnable;
6819             if ( mpWindowImpl->mpSysObj )
6820                 mpWindowImpl->mpSysObj->Enable( !mpWindowImpl->mbDisabled && bEnable );
6821 //          if ( mpWindowImpl->mbFrame )
6822 //              mpWindowImpl->mpFrame->Enable( !mpWindowImpl->mbDisabled && bEnable );
6823         }
6824     }
6825 
6826     // #i56102# restore app focus win in case the
6827     // window was disabled when the frame focus changed
6828     ImplSVData* pSVData = ImplGetSVData();
6829     if( bEnable &&
6830         pSVData->maWinData.mpFocusWin == NULL &&
6831         mpWindowImpl->mpFrameData->mbHasFocus &&
6832         mpWindowImpl->mpFrameData->mpFocusWin == this )
6833         pSVData->maWinData.mpFocusWin = this;
6834 
6835     if ( bChild || mpWindowImpl->mbChildNotify )
6836     {
6837         Window* pChild = mpWindowImpl->mpFirstChild;
6838         while ( pChild )
6839         {
6840             pChild->EnableInput( bEnable, bChild );
6841             pChild = pChild->mpWindowImpl->mpNext;
6842         }
6843     }
6844 
6845     if ( IsReallyVisible() )
6846         ImplGenerateMouseMove();
6847 
6848     // #104827# notify parent
6849     if ( bNotify )
6850     {
6851         NotifyEvent aNEvt( bEnable ? EVENT_INPUTENABLE : EVENT_INPUTDISABLE, this );
6852         Notify( aNEvt );
6853     }
6854 }
6855 
6856 // -----------------------------------------------------------------------
6857 
6858 void Window::EnableInput( sal_Bool bEnable, sal_Bool bChild, sal_Bool bSysWin,
6859                           const Window* pExcludeWindow )
6860 {
6861     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6862 
6863     EnableInput( bEnable, bChild );
6864     if ( bSysWin )
6865     {
6866         // pExculeWindow is the first Overlap-Frame --> if this
6867         // shouldn't be the case, than this must be changed in dialog.cxx
6868         if( pExcludeWindow )
6869             pExcludeWindow = pExcludeWindow->ImplGetFirstOverlapWindow();
6870         Window* pSysWin = mpWindowImpl->mpFrameWindow->mpWindowImpl->mpFrameData->mpFirstOverlap;
6871         while ( pSysWin )
6872         {
6873             // Is Window in the path from this window
6874             if ( ImplGetFirstOverlapWindow()->ImplIsWindowOrChild( pSysWin, sal_True ) )
6875             {
6876                 // Is Window not in the exclude window path or not the
6877                 // exclude window, than change the status
6878                 if ( !pExcludeWindow || !pExcludeWindow->ImplIsWindowOrChild( pSysWin, sal_True ) )
6879                     pSysWin->EnableInput( bEnable, bChild );
6880             }
6881             pSysWin = pSysWin->mpWindowImpl->mpNextOverlap;
6882         }
6883 
6884         // enable/disable floating system windows as well
6885         Window* pFrameWin = ImplGetSVData()->maWinData.mpFirstFrame;
6886         while ( pFrameWin )
6887         {
6888             if( pFrameWin->ImplIsFloatingWindow() )
6889             {
6890                 // Is Window in the path from this window
6891                 if ( ImplGetFirstOverlapWindow()->ImplIsWindowOrChild( pFrameWin, sal_True ) )
6892                 {
6893                     // Is Window not in the exclude window path or not the
6894                     // exclude window, than change the status
6895                     if ( !pExcludeWindow || !pExcludeWindow->ImplIsWindowOrChild( pFrameWin, sal_True ) )
6896                         pFrameWin->EnableInput( bEnable, bChild );
6897                 }
6898             }
6899             pFrameWin = pFrameWin->mpWindowImpl->mpFrameData->mpNextFrame;
6900         }
6901 
6902         // the same for ownerdraw floating windows
6903         if( mpWindowImpl->mbFrame )
6904         {
6905             ::std::vector< Window* >& rList = mpWindowImpl->mpFrameData->maOwnerDrawList;
6906             ::std::vector< Window* >::iterator p = rList.begin();
6907             while( p != rList.end() )
6908             {
6909                 // Is Window in the path from this window
6910                 if ( ImplGetFirstOverlapWindow()->ImplIsWindowOrChild( (*p), sal_True ) )
6911                 {
6912                     // Is Window not in the exclude window path or not the
6913                     // exclude window, than change the status
6914                     if ( !pExcludeWindow || !pExcludeWindow->ImplIsWindowOrChild( (*p), sal_True ) )
6915                         (*p)->EnableInput( bEnable, bChild );
6916                 }
6917                 p++;
6918             }
6919         }
6920     }
6921 }
6922 
6923 // -----------------------------------------------------------------------
6924 
6925 void Window::AlwaysEnableInput( sal_Bool bAlways, sal_Bool bChild )
6926 {
6927     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6928 
6929     if ( mpWindowImpl->mpBorderWindow )
6930         mpWindowImpl->mpBorderWindow->AlwaysEnableInput( bAlways, sal_False );
6931 
6932     if( bAlways && mpWindowImpl->meAlwaysInputMode != AlwaysInputEnabled )
6933     {
6934         mpWindowImpl->meAlwaysInputMode = AlwaysInputEnabled;
6935 
6936         if ( bAlways )
6937             EnableInput( sal_True, sal_False );
6938     }
6939     else if( ! bAlways && mpWindowImpl->meAlwaysInputMode == AlwaysInputEnabled )
6940     {
6941         mpWindowImpl->meAlwaysInputMode = AlwaysInputNone;
6942     }
6943 
6944     if ( bChild || mpWindowImpl->mbChildNotify )
6945     {
6946         Window* pChild = mpWindowImpl->mpFirstChild;
6947         while ( pChild )
6948         {
6949             pChild->AlwaysEnableInput( bAlways, bChild );
6950             pChild = pChild->mpWindowImpl->mpNext;
6951         }
6952     }
6953 }
6954 
6955 // -----------------------------------------------------------------------
6956 
6957 void Window::AlwaysDisableInput( sal_Bool bAlways, sal_Bool bChild )
6958 {
6959     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6960 
6961     if ( mpWindowImpl->mpBorderWindow )
6962         mpWindowImpl->mpBorderWindow->AlwaysDisableInput( bAlways, sal_False );
6963 
6964     if( bAlways && mpWindowImpl->meAlwaysInputMode != AlwaysInputDisabled )
6965     {
6966         mpWindowImpl->meAlwaysInputMode = AlwaysInputDisabled;
6967 
6968         if ( bAlways )
6969             EnableInput( sal_False, sal_False );
6970     }
6971     else if( ! bAlways && mpWindowImpl->meAlwaysInputMode == AlwaysInputDisabled )
6972     {
6973         mpWindowImpl->meAlwaysInputMode = AlwaysInputNone;
6974     }
6975 
6976     if ( bChild || mpWindowImpl->mbChildNotify )
6977     {
6978         Window* pChild = mpWindowImpl->mpFirstChild;
6979         while ( pChild )
6980         {
6981             pChild->AlwaysDisableInput( bAlways, bChild );
6982             pChild = pChild->mpWindowImpl->mpNext;
6983         }
6984     }
6985 }
6986 
6987 // -----------------------------------------------------------------------
6988 
6989 void Window::SetActivateMode( sal_uInt16 nMode )
6990 {
6991     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
6992 
6993     if ( mpWindowImpl->mpBorderWindow )
6994         mpWindowImpl->mpBorderWindow->SetActivateMode( nMode );
6995 
6996     if ( mpWindowImpl->mnActivateMode != nMode )
6997     {
6998         mpWindowImpl->mnActivateMode = nMode;
6999 
7000         // Evtl. ein Decativate/Activate ausloesen
7001         if ( mpWindowImpl->mnActivateMode )
7002         {
7003             if ( (mpWindowImpl->mbActive || (GetType() == WINDOW_BORDERWINDOW)) &&
7004                  !HasChildPathFocus( sal_True ) )
7005             {
7006                 mpWindowImpl->mbActive = sal_False;
7007                 Deactivate();
7008             }
7009         }
7010         else
7011         {
7012             if ( !mpWindowImpl->mbActive || (GetType() == WINDOW_BORDERWINDOW) )
7013             {
7014                 mpWindowImpl->mbActive = sal_True;
7015                 Activate();
7016             }
7017         }
7018     }
7019 }
7020 
7021 // -----------------------------------------------------------------------
7022 
7023 void Window::ToTop( sal_uInt16 nFlags )
7024 {
7025     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7026 
7027     ImplStartToTop( nFlags );
7028     ImplFocusToTop( nFlags, IsReallyVisible() );
7029 }
7030 
7031 // -----------------------------------------------------------------------
7032 
7033 void Window::SetZOrder( Window* pRefWindow, sal_uInt16 nFlags )
7034 {
7035     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7036 
7037     if ( mpWindowImpl->mpBorderWindow )
7038     {
7039         mpWindowImpl->mpBorderWindow->SetZOrder( pRefWindow, nFlags );
7040         return;
7041     }
7042 
7043     if ( nFlags & WINDOW_ZORDER_FIRST )
7044     {
7045         if ( ImplIsOverlapWindow() )
7046             pRefWindow = mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap;
7047         else
7048             pRefWindow = mpWindowImpl->mpParent->mpWindowImpl->mpFirstChild;
7049         nFlags |= WINDOW_ZORDER_BEFOR;
7050     }
7051     else if ( nFlags & WINDOW_ZORDER_LAST )
7052     {
7053         if ( ImplIsOverlapWindow() )
7054             pRefWindow = mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpLastOverlap;
7055         else
7056             pRefWindow = mpWindowImpl->mpParent->mpWindowImpl->mpLastChild;
7057         nFlags |= WINDOW_ZORDER_BEHIND;
7058     }
7059 
7060     while ( pRefWindow->mpWindowImpl->mpBorderWindow )
7061         pRefWindow = pRefWindow->mpWindowImpl->mpBorderWindow;
7062     if ( (pRefWindow == this) || mpWindowImpl->mbFrame )
7063         return;
7064 
7065     DBG_ASSERT( pRefWindow->mpWindowImpl->mpParent == mpWindowImpl->mpParent, "Window::SetZOrder() - pRefWindow has other parent" );
7066     if ( nFlags & WINDOW_ZORDER_BEFOR )
7067     {
7068         if ( pRefWindow->mpWindowImpl->mpPrev == this )
7069             return;
7070 
7071         if ( ImplIsOverlapWindow() )
7072         {
7073             if ( mpWindowImpl->mpPrev )
7074                 mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext;
7075             else
7076                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap = mpWindowImpl->mpNext;
7077             if ( mpWindowImpl->mpNext )
7078                 mpWindowImpl->mpNext->mpWindowImpl->mpPrev = mpWindowImpl->mpPrev;
7079             else
7080                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpLastOverlap = mpWindowImpl->mpPrev;
7081             if ( !pRefWindow->mpWindowImpl->mpPrev )
7082                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap = this;
7083         }
7084         else
7085         {
7086             if ( mpWindowImpl->mpPrev )
7087                 mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext;
7088             else
7089                 mpWindowImpl->mpParent->mpWindowImpl->mpFirstChild = mpWindowImpl->mpNext;
7090             if ( mpWindowImpl->mpNext )
7091                 mpWindowImpl->mpNext->mpWindowImpl->mpPrev = mpWindowImpl->mpPrev;
7092             else
7093                 mpWindowImpl->mpParent->mpWindowImpl->mpLastChild = mpWindowImpl->mpPrev;
7094             if ( !pRefWindow->mpWindowImpl->mpPrev )
7095                 mpWindowImpl->mpParent->mpWindowImpl->mpFirstChild = this;
7096         }
7097 
7098         mpWindowImpl->mpPrev = pRefWindow->mpWindowImpl->mpPrev;
7099         mpWindowImpl->mpNext = pRefWindow;
7100         if ( mpWindowImpl->mpPrev )
7101             mpWindowImpl->mpPrev->mpWindowImpl->mpNext = this;
7102         mpWindowImpl->mpNext->mpWindowImpl->mpPrev = this;
7103     }
7104     else if ( nFlags & WINDOW_ZORDER_BEHIND )
7105     {
7106         if ( pRefWindow->mpWindowImpl->mpNext == this )
7107             return;
7108 
7109         if ( ImplIsOverlapWindow() )
7110         {
7111             if ( mpWindowImpl->mpPrev )
7112                 mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext;
7113             else
7114                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap = mpWindowImpl->mpNext;
7115             if ( mpWindowImpl->mpNext )
7116                 mpWindowImpl->mpNext->mpWindowImpl->mpPrev = mpWindowImpl->mpPrev;
7117             else
7118                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpLastOverlap = mpWindowImpl->mpPrev;
7119             if ( !pRefWindow->mpWindowImpl->mpNext )
7120                 mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpLastOverlap = this;
7121         }
7122         else
7123         {
7124             if ( mpWindowImpl->mpPrev )
7125                 mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext;
7126             else
7127                 mpWindowImpl->mpParent->mpWindowImpl->mpFirstChild = mpWindowImpl->mpNext;
7128             if ( mpWindowImpl->mpNext )
7129                 mpWindowImpl->mpNext->mpWindowImpl->mpPrev = mpWindowImpl->mpPrev;
7130             else
7131                 mpWindowImpl->mpParent->mpWindowImpl->mpLastChild = mpWindowImpl->mpPrev;
7132             if ( !pRefWindow->mpWindowImpl->mpNext )
7133                 mpWindowImpl->mpParent->mpWindowImpl->mpLastChild = this;
7134         }
7135 
7136         mpWindowImpl->mpPrev = pRefWindow;
7137         mpWindowImpl->mpNext = pRefWindow->mpWindowImpl->mpNext;
7138         if ( mpWindowImpl->mpNext )
7139             mpWindowImpl->mpNext->mpWindowImpl->mpPrev = this;
7140         mpWindowImpl->mpPrev->mpWindowImpl->mpNext = this;
7141     }
7142 
7143     if ( IsReallyVisible() )
7144     {
7145         // Hintergrund-Sicherung zuruecksetzen
7146         if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
7147             ImplInvalidateAllOverlapBackgrounds();
7148 
7149         if ( mpWindowImpl->mbInitWinClipRegion || !mpWindowImpl->maWinClipRegion.IsEmpty() )
7150         {
7151             sal_Bool bInitWinClipRegion = mpWindowImpl->mbInitWinClipRegion;
7152             ImplSetClipFlag();
7153 
7154             // Wenn ClipRegion noch nicht initalisiert wurde, dann
7155             // gehen wir davon aus, das das Fenster noch nicht
7156             // ausgegeben wurde und loesen somit auch keine
7157             // Invalidates aus. Dies ist eine Optimierung fuer
7158             // HTML-Dokumenten mit vielen Controls. Wenn es mal
7159             // Probleme mit dieser Abfrage gibt, sollte man ein
7160             // Flag einfuehren, ob das Fenster nach Show schon
7161             // einmal ausgegeben wurde.
7162             if ( !bInitWinClipRegion )
7163             {
7164                 // Alle nebeneinanderliegen Fenster invalidieren
7165                 // Noch nicht komplett implementiert !!!
7166                 Rectangle   aWinRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
7167                 Window*     pWindow = NULL;
7168                 if ( ImplIsOverlapWindow() )
7169                 {
7170                     if ( mpWindowImpl->mpOverlapWindow )
7171                         pWindow = mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap;
7172                 }
7173                 else
7174                     pWindow = ImplGetParent()->mpWindowImpl->mpFirstChild;
7175                 // Alle Fenster, die vor uns liegen und von uns verdeckt wurden,
7176                 // invalidieren
7177                 while ( pWindow )
7178                 {
7179                     if ( pWindow == this )
7180                         break;
7181                     Rectangle aCompRect( Point( pWindow->mnOutOffX, pWindow->mnOutOffY ),
7182                                          Size( pWindow->mnOutWidth, pWindow->mnOutHeight ) );
7183                     if ( aWinRect.IsOver( aCompRect ) )
7184                         pWindow->Invalidate( INVALIDATE_CHILDREN | INVALIDATE_NOTRANSPARENT );
7185                     pWindow = pWindow->mpWindowImpl->mpNext;
7186                 }
7187                 // Wenn uns ein Fenster welches im Hinterund liegt verdeckt hat,
7188                 // dann muessen wir uns neu ausgeben
7189                 while ( pWindow )
7190                 {
7191                     if ( pWindow != this )
7192                     {
7193                         Rectangle aCompRect( Point( pWindow->mnOutOffX, pWindow->mnOutOffY ),
7194                                              Size( pWindow->mnOutWidth, pWindow->mnOutHeight ) );
7195                         if ( aWinRect.IsOver( aCompRect ) )
7196                         {
7197                             Invalidate( INVALIDATE_CHILDREN | INVALIDATE_NOTRANSPARENT );
7198                             break;
7199                         }
7200                     }
7201                     pWindow = pWindow->mpWindowImpl->mpNext;
7202                 }
7203             }
7204         }
7205     }
7206 }
7207 
7208 // -----------------------------------------------------------------------
7209 
7210 void Window::EnableAlwaysOnTop( sal_Bool bEnable )
7211 {
7212     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7213 
7214     mpWindowImpl->mbAlwaysOnTop = bEnable;
7215 
7216     if ( mpWindowImpl->mpBorderWindow )
7217         mpWindowImpl->mpBorderWindow->EnableAlwaysOnTop( bEnable );
7218     else if ( bEnable && IsReallyVisible() )
7219         ToTop();
7220 
7221     if ( mpWindowImpl->mbFrame )
7222         mpWindowImpl->mpFrame->SetAlwaysOnTop( bEnable );
7223 }
7224 
7225 // -----------------------------------------------------------------------
7226 
7227 void Window::SetPosSizePixel( long nX, long nY,
7228                               long nWidth, long nHeight, sal_uInt16 nFlags )
7229 {
7230     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7231 
7232     sal_Bool bHasValidSize = !mpWindowImpl->mbDefSize;
7233 
7234     if ( nFlags & WINDOW_POSSIZE_POS )
7235         mpWindowImpl->mbDefPos = sal_False;
7236     if ( nFlags & WINDOW_POSSIZE_SIZE )
7237         mpWindowImpl->mbDefSize = sal_False;
7238 
7239     // Oberstes BorderWindow ist das Window, welches positioniert werden soll
7240     Window* pWindow = this;
7241     while ( pWindow->mpWindowImpl->mpBorderWindow )
7242         pWindow = pWindow->mpWindowImpl->mpBorderWindow;
7243 
7244     if ( pWindow->mpWindowImpl->mbFrame )
7245     {
7246         // Note: if we're positioning a frame, the coordinates are interpreted
7247         // as being the top-left corner of the window's client area and NOT
7248         // as the position of the border ! (due to limitations of several UNIX window managers)
7249         long nOldWidth  = pWindow->mnOutWidth;
7250 
7251         if ( !(nFlags & WINDOW_POSSIZE_WIDTH) )
7252             nWidth = pWindow->mnOutWidth;
7253         if ( !(nFlags & WINDOW_POSSIZE_HEIGHT) )
7254             nHeight = pWindow->mnOutHeight;
7255 
7256 
7257         sal_uInt16 nSysFlags=0;
7258         if( nFlags & WINDOW_POSSIZE_WIDTH )
7259             nSysFlags |= SAL_FRAME_POSSIZE_WIDTH;
7260         if( nFlags & WINDOW_POSSIZE_HEIGHT )
7261             nSysFlags |= SAL_FRAME_POSSIZE_HEIGHT;
7262         if( nFlags & WINDOW_POSSIZE_X )
7263         {
7264             nSysFlags |= SAL_FRAME_POSSIZE_X;
7265             if( pWindow->GetParent() && (pWindow->GetStyle() & WB_SYSTEMCHILDWINDOW) )
7266 			{
7267                 Window* pParent = pWindow->GetParent();
7268                 nX += pParent->mnOutOffX;
7269 			}
7270             if( GetParent() && GetParent()->ImplIsAntiparallel() )
7271             {
7272                 // --- RTL --- (re-mirror at parent window)
7273                 Rectangle aRect( Point ( nX, nY ), Size( nWidth, nHeight ) );
7274                 GetParent()->ImplReMirror( aRect );
7275                 nX = aRect.nLeft;
7276             }
7277         }
7278         if( !(nFlags & WINDOW_POSSIZE_X) && bHasValidSize && pWindow->mpWindowImpl->mpFrame->maGeometry.nWidth )
7279         {
7280             // --- RTL ---  make sure the old right aligned position is not changed
7281             //              system windows will always grow to the right
7282             if( pWindow->GetParent() && pWindow->GetParent()->ImplHasMirroredGraphics() )
7283             {
7284                 long myWidth = nOldWidth;
7285                 if( !myWidth )
7286                     myWidth = mpWindowImpl->mpFrame->GetUnmirroredGeometry().nWidth;
7287                 if( !myWidth )
7288                     myWidth = nWidth;
7289                 nFlags |= WINDOW_POSSIZE_X;
7290                 nSysFlags |= SAL_FRAME_POSSIZE_X;
7291                 nX = mpWindowImpl->mpFrame->GetUnmirroredGeometry().nX - pWindow->GetParent()->mpWindowImpl->mpFrame->GetUnmirroredGeometry().nX -
7292                     mpWindowImpl->mpFrame->GetUnmirroredGeometry().nLeftDecoration;
7293                 nX = pWindow->GetParent()->mpWindowImpl->mpFrame->GetUnmirroredGeometry().nX - mpWindowImpl->mpFrame->GetUnmirroredGeometry().nLeftDecoration +
7294                     pWindow->GetParent()->mpWindowImpl->mpFrame->GetUnmirroredGeometry().nWidth - myWidth - 1 - mpWindowImpl->mpFrame->GetUnmirroredGeometry().nX;
7295                 if(!(nFlags & WINDOW_POSSIZE_Y))
7296                 {
7297                     nFlags |= WINDOW_POSSIZE_Y;
7298                     nSysFlags |= SAL_FRAME_POSSIZE_Y;
7299                     nY = mpWindowImpl->mpFrame->GetUnmirroredGeometry().nY - pWindow->GetParent()->mpWindowImpl->mpFrame->GetUnmirroredGeometry().nY -
7300                         mpWindowImpl->mpFrame->GetUnmirroredGeometry().nTopDecoration;
7301                 }
7302             }
7303         }
7304         if( nFlags & WINDOW_POSSIZE_Y )
7305 		{
7306             nSysFlags |= SAL_FRAME_POSSIZE_Y;
7307             if( pWindow->GetParent() && (pWindow->GetStyle() & WB_SYSTEMCHILDWINDOW) )
7308 			{
7309                 Window* pParent = pWindow->GetParent();
7310                 nY += pParent->mnOutOffY;
7311 			}
7312 		}
7313 
7314         if( nSysFlags & (SAL_FRAME_POSSIZE_WIDTH|SAL_FRAME_POSSIZE_HEIGHT) )
7315         {
7316             // check for min/max client size and adjust size accordingly
7317             // otherwise it may happen that the resize event is ignored, i.e. the old size remains
7318             // unchanged but ImplHandleResize() is called with the wrong size
7319             SystemWindow *pSystemWindow = dynamic_cast< SystemWindow* >( pWindow );
7320             if( pSystemWindow )
7321             {
7322                 Size aMinSize = pSystemWindow->GetMinOutputSizePixel();
7323                 Size aMaxSize = pSystemWindow->GetMaxOutputSizePixel();
7324                 if( nWidth < aMinSize.Width() )
7325                     nWidth = aMinSize.Width();
7326                 if( nHeight < aMinSize.Height() )
7327                     nHeight = aMinSize.Height();
7328 
7329                 if( nWidth > aMaxSize.Width() )
7330                     nWidth = aMaxSize.Width();
7331                 if( nHeight > aMaxSize.Height() )
7332                     nHeight = aMaxSize.Height();
7333             }
7334         }
7335 
7336         pWindow->mpWindowImpl->mpFrame->SetPosSize( nX, nY, nWidth, nHeight, nSysFlags );
7337 
7338         // Resize should be called directly. If we havn't
7339         // set the correct size, we get a second resize from
7340         // the system with the correct size. This can be happend
7341         // if the size is to small or to large.
7342         ImplHandleResize( pWindow, nWidth, nHeight );
7343     }
7344     else
7345     {
7346         pWindow->ImplPosSizeWindow( nX, nY, nWidth, nHeight, nFlags );
7347         if ( IsReallyVisible() )
7348             ImplGenerateMouseMove();
7349     }
7350 }
7351 
7352 // -----------------------------------------------------------------------
7353 
7354 Point Window::GetPosPixel() const
7355 {
7356 	return mpWindowImpl->maPos;
7357 }
7358 
7359 // -----------------------------------------------------------------------
7360 
7361 Rectangle Window::GetDesktopRectPixel() const
7362 {
7363     Rectangle rRect;
7364     mpWindowImpl->mpFrameWindow->mpWindowImpl->mpFrame->GetWorkArea( rRect );
7365     return rRect;
7366 }
7367 
7368 // -----------------------------------------------------------------------
7369 
7370 Point Window::OutputToScreenPixel( const Point& rPos ) const
7371 {
7372     // relative to top level parent
7373     return Point( rPos.X()+mnOutOffX, rPos.Y()+mnOutOffY );
7374 }
7375 
7376 // -----------------------------------------------------------------------
7377 
7378 Point Window::ScreenToOutputPixel( const Point& rPos ) const
7379 {
7380     // relative to top level parent
7381     return Point( rPos.X()-mnOutOffX, rPos.Y()-mnOutOffY );
7382 }
7383 
7384 // -----------------------------------------------------------------------
7385 
7386 long Window::ImplGetUnmirroredOutOffX()
7387 {
7388     // revert mnOutOffX changes that were potentially made in ImplPosSizeWindow
7389     long offx = mnOutOffX;
7390     if( ImplHasMirroredGraphics() )
7391     {
7392         if( mpWindowImpl->mpParent && !mpWindowImpl->mpParent->mpWindowImpl->mbFrame && mpWindowImpl->mpParent->ImplIsAntiparallel() )
7393         {
7394             if ( !ImplIsOverlapWindow() )
7395                 offx -= mpWindowImpl->mpParent->mnOutOffX;
7396 
7397             offx = mpWindowImpl->mpParent->mnOutWidth - mnOutWidth - offx;
7398 
7399             if ( !ImplIsOverlapWindow() )
7400                 offx += mpWindowImpl->mpParent->mnOutOffX;
7401 
7402         }
7403     }
7404     return offx;
7405 }
7406 
7407 // normalized screen pixel are independent of mirroring
7408 Point Window::OutputToNormalizedScreenPixel( const Point& rPos ) const
7409 {
7410     // relative to top level parent
7411     long offx = ((Window*) this)->ImplGetUnmirroredOutOffX();
7412     return Point( rPos.X()+offx, rPos.Y()+mnOutOffY );
7413 }
7414 
7415 Point Window::NormalizedScreenToOutputPixel( const Point& rPos ) const
7416 {
7417     // relative to top level parent
7418     long offx = ((Window*) this)->ImplGetUnmirroredOutOffX();
7419     return Point( rPos.X()-offx, rPos.Y()-mnOutOffY );
7420 }
7421 
7422 // -----------------------------------------------------------------------
7423 
7424 Point Window::OutputToAbsoluteScreenPixel( const Point& rPos ) const
7425 {
7426     // relative to the screen
7427     Point p = OutputToScreenPixel( rPos );
7428     SalFrameGeometry g = mpWindowImpl->mpFrame->GetGeometry();
7429     p.X() += g.nX;
7430     p.Y() += g.nY;
7431     return p;
7432 }
7433 
7434 // -----------------------------------------------------------------------
7435 
7436 Point Window::AbsoluteScreenToOutputPixel( const Point& rPos ) const
7437 {
7438     // relative to the screen
7439     Point p = ScreenToOutputPixel( rPos );
7440     SalFrameGeometry g = mpWindowImpl->mpFrame->GetGeometry();
7441     p.X() -= g.nX;
7442     p.Y() -= g.nY;
7443     return p;
7444 }
7445 
7446 // -----------------------------------------------------------------------
7447 
7448 Rectangle Window::ImplOutputToUnmirroredAbsoluteScreenPixel( const Rectangle &rRect ) const
7449 {
7450     // this method creates unmirrored screen coordinates to be compared with the desktop
7451     // and is used for positioning of RTL popup windows correctly on the screen
7452     SalFrameGeometry g = mpWindowImpl->mpFrame->GetUnmirroredGeometry();
7453 
7454     Point p1 = OutputToScreenPixel( rRect.TopRight() );
7455     p1.X() = g.nX+g.nWidth-p1.X();
7456     p1.Y() += g.nY;
7457 
7458     Point p2 = OutputToScreenPixel( rRect.BottomLeft() );
7459     p2.X() = g.nX+g.nWidth-p2.X();
7460     p2.Y() += g.nY;
7461 
7462     return Rectangle( p1, p2 );
7463 }
7464 
7465 
7466 // -----------------------------------------------------------------------
7467 
7468 Rectangle Window::GetWindowExtentsRelative( Window *pRelativeWindow ) const
7469 {
7470     // with decoration
7471     return ImplGetWindowExtentsRelative( pRelativeWindow, sal_False );
7472 }
7473 
7474 Rectangle Window::GetClientWindowExtentsRelative( Window *pRelativeWindow ) const
7475 {
7476     // without decoration
7477     return ImplGetWindowExtentsRelative( pRelativeWindow, sal_True );
7478 }
7479 
7480 // -----------------------------------------------------------------------
7481 
7482 Rectangle Window::ImplGetWindowExtentsRelative( Window *pRelativeWindow, sal_Bool bClientOnly ) const
7483 {
7484     SalFrameGeometry g = mpWindowImpl->mpFrame->GetGeometry();
7485     // make sure we use the extent of our border window,
7486     // otherwise we miss a few pixels
7487     const Window *pWin = (!bClientOnly && mpWindowImpl->mpBorderWindow) ? mpWindowImpl->mpBorderWindow : this;
7488 
7489     Point aPos( pWin->OutputToScreenPixel( Point(0,0) ) );
7490     aPos.X() += g.nX;
7491     aPos.Y() += g.nY;
7492     Size aSize ( pWin->GetSizePixel() );
7493     // #104088# do not add decoration to the workwindow to be compatible to java accessibility api
7494 	if( !bClientOnly && (mpWindowImpl->mbFrame || (mpWindowImpl->mpBorderWindow && mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame && GetType() != WINDOW_WORKWINDOW)) )
7495 	{
7496 		aPos.X() -= g.nLeftDecoration;
7497 		aPos.Y() -= g.nTopDecoration;
7498 		aSize.Width() += g.nLeftDecoration + g.nRightDecoration;
7499 		aSize.Height() += g.nTopDecoration + g.nBottomDecoration;
7500 	}
7501     if( pRelativeWindow )
7502     {
7503         // #106399# express coordinates relative to borderwindow
7504         Window *pRelWin = (!bClientOnly && pRelativeWindow->mpWindowImpl->mpBorderWindow) ? pRelativeWindow->mpWindowImpl->mpBorderWindow : pRelativeWindow;
7505         aPos = pRelWin->AbsoluteScreenToOutputPixel( aPos );
7506     }
7507     return Rectangle( aPos, aSize );
7508 }
7509 
7510 // -----------------------------------------------------------------------
7511 
7512 void Window::Scroll( long nHorzScroll, long nVertScroll, sal_uInt16 nFlags )
7513 {
7514     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7515 
7516     ImplScroll( Rectangle( Point( mnOutOffX, mnOutOffY ),
7517                            Size( mnOutWidth, mnOutHeight ) ),
7518                 nHorzScroll, nVertScroll, nFlags & ~SCROLL_CLIP );
7519 }
7520 
7521 // -----------------------------------------------------------------------
7522 
7523 void Window::Scroll( long nHorzScroll, long nVertScroll,
7524                      const Rectangle& rRect, sal_uInt16 nFlags )
7525 {
7526     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7527 
7528     Rectangle aRect = ImplLogicToDevicePixel( rRect );
7529     aRect.Intersection( Rectangle( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) ) );
7530     if ( !aRect.IsEmpty() )
7531         ImplScroll( aRect, nHorzScroll, nVertScroll, nFlags );
7532 }
7533 
7534 // -----------------------------------------------------------------------
7535 
7536 void Window::Invalidate( sal_uInt16 nFlags )
7537 {
7538     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7539 
7540     if ( !IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight )
7541         return;
7542 
7543     ImplInvalidate( NULL, nFlags );
7544 }
7545 
7546 // -----------------------------------------------------------------------
7547 
7548 void Window::Invalidate( const Rectangle& rRect, sal_uInt16 nFlags )
7549 {
7550     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7551 
7552     if ( !IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight )
7553         return;
7554 
7555     Rectangle aRect = ImplLogicToDevicePixel( rRect );
7556     if ( !aRect.IsEmpty() )
7557     {
7558         Region aRegion( aRect );
7559         ImplInvalidate( &aRegion, nFlags );
7560     }
7561 }
7562 
7563 // -----------------------------------------------------------------------
7564 
7565 void Window::Invalidate( const Region& rRegion, sal_uInt16 nFlags )
7566 {
7567     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7568 
7569     if ( !IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight )
7570         return;
7571 
7572     if ( rRegion.IsNull() )
7573         ImplInvalidate( NULL, nFlags );
7574     else
7575     {
7576         Region aRegion = ImplPixelToDevicePixel( LogicToPixel( rRegion ) );
7577         if ( !aRegion.IsEmpty() )
7578             ImplInvalidate( &aRegion, nFlags );
7579     }
7580 }
7581 
7582 // -----------------------------------------------------------------------
7583 
7584 void Window::Validate( sal_uInt16 nFlags )
7585 {
7586     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7587 
7588     if ( !IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight )
7589         return;
7590 
7591     ImplValidate( NULL, nFlags );
7592 }
7593 
7594 // -----------------------------------------------------------------------
7595 
7596 void Window::Validate( const Rectangle& rRect, sal_uInt16 nFlags )
7597 {
7598     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7599 
7600     if ( !IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight )
7601         return;
7602 
7603     Rectangle aRect = ImplLogicToDevicePixel( rRect );
7604     if ( !aRect.IsEmpty() )
7605     {
7606         Region aRegion( aRect );
7607         ImplValidate( &aRegion, nFlags );
7608     }
7609 }
7610 
7611 // -----------------------------------------------------------------------
7612 
7613 void Window::Validate( const Region& rRegion, sal_uInt16 nFlags )
7614 {
7615     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7616 
7617     if ( !IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight )
7618         return;
7619 
7620     if ( rRegion.IsNull() )
7621         ImplValidate( NULL, nFlags );
7622     else
7623     {
7624         Region aRegion = ImplPixelToDevicePixel( LogicToPixel( rRegion ) );
7625         if ( !aRegion.IsEmpty() )
7626             ImplValidate( &aRegion, nFlags );
7627     }
7628 }
7629 
7630 // -----------------------------------------------------------------------
7631 
7632 sal_Bool Window::HasPaintEvent() const
7633 {
7634     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7635 
7636     if ( !mpWindowImpl->mbReallyVisible )
7637         return sal_False;
7638 
7639     if ( mpWindowImpl->mpFrameWindow->mpWindowImpl->mbPaintFrame )
7640         return sal_True;
7641 
7642     if ( mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINT )
7643         return sal_True;
7644 
7645     if ( !ImplIsOverlapWindow() )
7646     {
7647         const Window* pTempWindow = this;
7648         do
7649         {
7650             pTempWindow = pTempWindow->ImplGetParent();
7651             if ( pTempWindow->mpWindowImpl->mnPaintFlags & (IMPL_PAINT_PAINTCHILDS | IMPL_PAINT_PAINTALLCHILDS) )
7652                 return sal_True;
7653         }
7654         while ( !pTempWindow->ImplIsOverlapWindow() );
7655     }
7656 
7657     return sal_False;
7658 }
7659 
7660 // -----------------------------------------------------------------------
7661 
7662 void Window::Update()
7663 {
7664     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7665 
7666     if ( mpWindowImpl->mpBorderWindow )
7667     {
7668         mpWindowImpl->mpBorderWindow->Update();
7669         return;
7670     }
7671 
7672     if ( !mpWindowImpl->mbReallyVisible )
7673         return;
7674 
7675     sal_Bool bFlush = sal_False;
7676     if ( mpWindowImpl->mpFrameWindow->mpWindowImpl->mbPaintFrame )
7677     {
7678         Point aPoint( 0, 0 );
7679         Region aRegion( Rectangle( aPoint, Size( mnOutWidth, mnOutHeight ) ) );
7680         ImplInvalidateOverlapFrameRegion( aRegion );
7681         if ( mpWindowImpl->mbFrame || (mpWindowImpl->mpBorderWindow && mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame) )
7682             bFlush = sal_True;
7683     }
7684 
7685     // Zuerst muessen wir alle Fenster ueberspringen, die Paint-Transparent
7686     // sind
7687     Window* pUpdateWindow = this;
7688     Window* pWindow = pUpdateWindow;
7689     while ( !pWindow->ImplIsOverlapWindow() )
7690     {
7691         if ( !pWindow->mpWindowImpl->mbPaintTransparent )
7692         {
7693             pUpdateWindow = pWindow;
7694             break;
7695         }
7696         pWindow = pWindow->ImplGetParent();
7697     }
7698     // Ein Update wirkt immer auf das Window, wo PAINTALLCHILDS gesetzt
7699     // ist, damit nicht zuviel gemalt wird
7700     pWindow = pUpdateWindow;
7701     do
7702     {
7703         if ( pWindow->mpWindowImpl->mnPaintFlags & IMPL_PAINT_PAINTALLCHILDS )
7704             pUpdateWindow = pWindow;
7705         if ( pWindow->ImplIsOverlapWindow() )
7706             break;
7707         pWindow = pWindow->ImplGetParent();
7708     }
7709     while ( pWindow );
7710 
7711     // Wenn es etwas zu malen gibt, dann ein Paint ausloesen
7712     if ( pUpdateWindow->mpWindowImpl->mnPaintFlags & (IMPL_PAINT_PAINT | IMPL_PAINT_PAINTCHILDS) )
7713     {
7714          // und fuer alle ueber uns stehende System-Fenster auch ein Update
7715          // ausloesen, damit nicht die ganze Zeit luecken stehen bleiben
7716          Window* pUpdateOverlapWindow = ImplGetFirstOverlapWindow()->mpWindowImpl->mpFirstOverlap;
7717          while ( pUpdateOverlapWindow )
7718          {
7719              pUpdateOverlapWindow->Update();
7720              pUpdateOverlapWindow = pUpdateOverlapWindow->mpWindowImpl->mpNext;
7721          }
7722 
7723         pUpdateWindow->ImplCallPaint( NULL, pUpdateWindow->mpWindowImpl->mnPaintFlags );
7724     }
7725 
7726     if ( bFlush )
7727         Flush();
7728 }
7729 
7730 // -----------------------------------------------------------------------
7731 
7732 void Window::Flush()
7733 {
7734     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7735 
7736     const Rectangle aWinRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
7737     mpWindowImpl->mpFrame->Flush( aWinRect );
7738 }
7739 
7740 // -----------------------------------------------------------------------
7741 
7742 void Window::Sync()
7743 {
7744     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7745 
7746     mpWindowImpl->mpFrame->Sync();
7747 }
7748 
7749 // -----------------------------------------------------------------------
7750 
7751 void Window::SetUpdateMode( sal_Bool bUpdate )
7752 {
7753     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7754 
7755     mpWindowImpl->mbNoUpdate = !bUpdate;
7756     StateChanged( STATE_CHANGE_UPDATEMODE );
7757 }
7758 
7759 // -----------------------------------------------------------------------
7760 
7761 void Window::GrabFocus()
7762 {
7763     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7764 
7765     ImplGrabFocus( 0 );
7766 }
7767 
7768 // -----------------------------------------------------------------------
7769 
7770 sal_Bool Window::HasFocus() const
7771 {
7772     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7773 
7774     // #107575# the first floating window always has the keyboard focus, see also winproc.cxx: ImplGetKeyInputWindow()
7775     //  task was shifted to 6.y, so its commented out
7776     /*
7777     Window* pFocusWin = ImplGetSVData()->maWinData.mpFirstFloat;
7778     if( pFocusWin && pFocusWin->mpWindowImpl->mbFloatWin && ((FloatingWindow *)pFocusWin)->GrabsFocus() )
7779         pFocusWin = pFocusWin->GetPreferredKeyInputWindow();
7780     else
7781         pFocusWin = ImplGetSVData()->maWinData.mpFocusWin;
7782 
7783     return (this == pFocusWin);
7784     */
7785 
7786     return (this == ImplGetSVData()->maWinData.mpFocusWin);
7787 }
7788 
7789 // -----------------------------------------------------------------------
7790 
7791 void Window::GrabFocusToDocument()
7792 {
7793 	Window *pWin = this;
7794 	while( pWin )
7795 	{
7796 		if( !pWin->GetParent() )
7797 		{
7798 			pWin->ImplGetFrameWindow()->GetWindow( WINDOW_CLIENT )->GrabFocus();
7799 			return;
7800 		}
7801 		pWin = pWin->GetParent();
7802 	}
7803 }
7804 
7805 void Window::SetFakeFocus( bool bFocus )
7806 {
7807     ImplGetWindowImpl()->mbFakeFocusSet = bFocus;
7808 }
7809 
7810 // -----------------------------------------------------------------------
7811 
7812 sal_Bool Window::HasChildPathFocus( sal_Bool bSystemWindow ) const
7813 {
7814     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7815 
7816     // #107575#, the first floating window always has the keyboard focus, see also winproc.cxx: ImplGetKeyInputWindow()
7817     //  task was shifted to 6.y, so its commented out
7818     /*
7819     Window* pFocusWin = ImplGetSVData()->maWinData.mpFirstFloat;
7820     if( pFocusWin && pFocusWin->mpWindowImpl->mbFloatWin && ((FloatingWindow *)pFocusWin)->GrabsFocus() )
7821         pFocusWin = pFocusWin->GetPreferredKeyInputWindow();
7822     else
7823         pFocusWin = ImplGetSVData()->maWinData.mpFocusWin;
7824     */
7825     Window* pFocusWin = ImplGetSVData()->maWinData.mpFocusWin;
7826     if ( pFocusWin )
7827         return ImplIsWindowOrChild( pFocusWin, bSystemWindow );
7828     return sal_False;
7829 }
7830 
7831 // -----------------------------------------------------------------------
7832 
7833 void Window::CaptureMouse()
7834 {
7835     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7836 
7837     ImplSVData* pSVData = ImplGetSVData();
7838 
7839     // Tracking evt. beenden
7840     if ( pSVData->maWinData.mpTrackWin != this )
7841     {
7842         if ( pSVData->maWinData.mpTrackWin )
7843             pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL );
7844     }
7845 
7846     if ( pSVData->maWinData.mpCaptureWin != this )
7847     {
7848         pSVData->maWinData.mpCaptureWin = this;
7849         mpWindowImpl->mpFrame->CaptureMouse( sal_True );
7850     }
7851 }
7852 
7853 // -----------------------------------------------------------------------
7854 
7855 void Window::ReleaseMouse()
7856 {
7857     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7858 
7859     ImplSVData* pSVData = ImplGetSVData();
7860 
7861     DBG_ASSERTWARNING( pSVData->maWinData.mpCaptureWin == this,
7862                        "Window::ReleaseMouse(): window doesn't have the mouse capture" );
7863 
7864     if ( pSVData->maWinData.mpCaptureWin == this )
7865     {
7866         pSVData->maWinData.mpCaptureWin = NULL;
7867         mpWindowImpl->mpFrame->CaptureMouse( sal_False );
7868         ImplGenerateMouseMove();
7869     }
7870 }
7871 
7872 // -----------------------------------------------------------------------
7873 
7874 sal_Bool Window::IsMouseCaptured() const
7875 {
7876     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7877 
7878     return (this == ImplGetSVData()->maWinData.mpCaptureWin);
7879 }
7880 
7881 // -----------------------------------------------------------------------
7882 
7883 void Window::SetPointer( const Pointer& rPointer )
7884 {
7885     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7886 
7887     if ( mpWindowImpl->maPointer == rPointer )
7888         return;
7889 
7890     mpWindowImpl->maPointer   = rPointer;
7891 
7892     // Pointer evt. direkt umsetzen
7893     if ( !mpWindowImpl->mpFrameData->mbInMouseMove && ImplTestMousePointerSet() )
7894         mpWindowImpl->mpFrame->SetPointer( ImplGetMousePointer() );
7895 }
7896 
7897 // -----------------------------------------------------------------------
7898 
7899 void Window::EnableChildPointerOverwrite( sal_Bool bOverwrite )
7900 {
7901     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7902 
7903     if ( mpWindowImpl->mbChildPtrOverwrite == bOverwrite )
7904         return;
7905 
7906     mpWindowImpl->mbChildPtrOverwrite  = bOverwrite;
7907 
7908     // Pointer evt. direkt umsetzen
7909     if ( !mpWindowImpl->mpFrameData->mbInMouseMove && ImplTestMousePointerSet() )
7910         mpWindowImpl->mpFrame->SetPointer( ImplGetMousePointer() );
7911 }
7912 
7913 // -----------------------------------------------------------------------
7914 
7915 void Window::SetPointerPosPixel( const Point& rPos )
7916 {
7917     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7918 
7919     Point aPos = ImplOutputToFrame( rPos );
7920     if( ImplHasMirroredGraphics() )
7921     {
7922         if( !IsRTLEnabled() )
7923         {
7924             // --- RTL --- (re-mirror mouse pos at this window)
7925             ImplReMirror( aPos );
7926         }
7927         // mirroring is required here, SetPointerPos bypasses SalGraphics
7928         mpGraphics->mirror( aPos.X(), this );
7929     }
7930     else if( ImplIsAntiparallel() )
7931     {
7932         ImplReMirror( aPos );
7933     }
7934     mpWindowImpl->mpFrame->SetPointerPos( aPos.X(), aPos.Y() );
7935 }
7936 
7937 // -----------------------------------------------------------------------
7938 
7939 Point Window::GetPointerPosPixel()
7940 {
7941     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7942 
7943     Point aPos( mpWindowImpl->mpFrameData->mnLastMouseX, mpWindowImpl->mpFrameData->mnLastMouseY );
7944     if( ImplIsAntiparallel() )
7945     {
7946         // --- RTL --- (re-mirror mouse pos at this window)
7947         ImplReMirror( aPos );
7948     }
7949     return ImplFrameToOutput( aPos );
7950 }
7951 
7952 // -----------------------------------------------------------------------
7953 
7954 Point Window::GetLastPointerPosPixel()
7955 {
7956     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7957 
7958     Point aPos( mpWindowImpl->mpFrameData->mnBeforeLastMouseX, mpWindowImpl->mpFrameData->mnBeforeLastMouseY );
7959     if( ImplIsAntiparallel() )
7960     {
7961         // --- RTL --- (re-mirror mouse pos at this window)
7962         ImplReMirror( aPos );
7963     }
7964     return ImplFrameToOutput( aPos );
7965 }
7966 
7967 // -----------------------------------------------------------------------
7968 
7969 void Window::ShowPointer( sal_Bool bVisible )
7970 {
7971     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
7972 
7973     if ( mpWindowImpl->mbNoPtrVisible != !bVisible )
7974     {
7975         mpWindowImpl->mbNoPtrVisible = !bVisible;
7976 
7977         // Pointer evt. direkt umsetzen
7978         if ( !mpWindowImpl->mpFrameData->mbInMouseMove && ImplTestMousePointerSet() )
7979             mpWindowImpl->mpFrame->SetPointer( ImplGetMousePointer() );
7980     }
7981 }
7982 
7983 // -----------------------------------------------------------------------
7984 
7985 Window::PointerState Window::GetPointerState()
7986 {
7987     PointerState aState;
7988     aState.mnState = 0;
7989 
7990     if (mpWindowImpl->mpFrame)
7991     {
7992         SalFrame::SalPointerState aSalPointerState;
7993 
7994         aSalPointerState = mpWindowImpl->mpFrame->GetPointerState();
7995         if( ImplIsAntiparallel() )
7996         {
7997             // --- RTL --- (re-mirror mouse pos at this window)
7998             ImplReMirror( aSalPointerState.maPos );
7999         }
8000         aState.maPos = ImplFrameToOutput( aSalPointerState.maPos );
8001         aState.mnState = aSalPointerState.mnState;
8002     }
8003     return aState;
8004 }
8005 
8006 // -----------------------------------------------------------------------
8007 
8008 sal_Bool Window::IsMouseOver()
8009 {
8010     return ImplGetWinData()->mbMouseOver;
8011 }
8012 
8013 // -----------------------------------------------------------------------
8014 
8015 void Window::EnterWait()
8016 {
8017     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8018 
8019     mpWindowImpl->mnWaitCount++;
8020 
8021     if ( mpWindowImpl->mnWaitCount == 1 )
8022     {
8023         // Pointer evt. direkt umsetzen
8024         if ( !mpWindowImpl->mpFrameData->mbInMouseMove && ImplTestMousePointerSet() )
8025             mpWindowImpl->mpFrame->SetPointer( ImplGetMousePointer() );
8026     }
8027 }
8028 
8029 // -----------------------------------------------------------------------
8030 
8031 void Window::LeaveWait()
8032 {
8033     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8034 
8035     if ( mpWindowImpl->mnWaitCount )
8036     {
8037         mpWindowImpl->mnWaitCount--;
8038 
8039         if ( !mpWindowImpl->mnWaitCount )
8040         {
8041             // Pointer evt. direkt umsetzen
8042             if ( !mpWindowImpl->mpFrameData->mbInMouseMove && ImplTestMousePointerSet() )
8043                 mpWindowImpl->mpFrame->SetPointer( ImplGetMousePointer() );
8044         }
8045     }
8046 }
8047 
8048 // -----------------------------------------------------------------------
8049 
8050 void Window::SetCursor( Cursor* pCursor )
8051 {
8052     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8053 
8054     if ( mpWindowImpl->mpCursor != pCursor )
8055     {
8056         if ( mpWindowImpl->mpCursor )
8057             mpWindowImpl->mpCursor->ImplHide( true );
8058         mpWindowImpl->mpCursor = pCursor;
8059         if ( pCursor )
8060             pCursor->ImplShow();
8061     }
8062 }
8063 
8064 // -----------------------------------------------------------------------
8065 
8066 void Window::SetText( const XubString& rStr )
8067 {
8068     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8069 
8070     String oldTitle( mpWindowImpl->maText );
8071     mpWindowImpl->maText = rStr;
8072 
8073     if ( mpWindowImpl->mpBorderWindow )
8074         mpWindowImpl->mpBorderWindow->SetText( rStr );
8075     else if ( mpWindowImpl->mbFrame )
8076         mpWindowImpl->mpFrame->SetTitle( rStr );
8077 
8078     ImplCallEventListeners( VCLEVENT_WINDOW_FRAMETITLECHANGED, &oldTitle );
8079 
8080 	// #107247# needed for accessibility
8081 	// The VCLEVENT_WINDOW_FRAMETITLECHANGED is (mis)used to notify accessible name changes.
8082 	// Therefore a window, which is labeled by this window, must also notify an accessible
8083 	// name change.
8084 	if ( IsReallyVisible() )
8085 	{
8086 		Window* pWindow = GetAccessibleRelationLabelFor();
8087 		if ( pWindow && pWindow != this )
8088 			pWindow->ImplCallEventListeners( VCLEVENT_WINDOW_FRAMETITLECHANGED, &oldTitle );
8089 	}
8090 
8091     StateChanged( STATE_CHANGE_TEXT );
8092 }
8093 
8094 // -----------------------------------------------------------------------
8095 
8096 String Window::GetText() const
8097 {
8098     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8099 
8100     return mpWindowImpl->maText;
8101 }
8102 
8103 // -----------------------------------------------------------------------
8104 
8105 String Window::GetDisplayText() const
8106 {
8107     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8108 
8109     return GetText();
8110 }
8111 
8112 // -----------------------------------------------------------------------
8113 
8114 const Wallpaper& Window::GetDisplayBackground() const
8115 {
8116     // FIXME: fix issue 52349, need to fix this really in
8117     // all NWF enabled controls
8118     const ToolBox* pTB = dynamic_cast<const ToolBox*>(this);
8119     if( pTB )
8120     {
8121         if( IsNativeWidgetEnabled() )
8122             return pTB->ImplGetToolBoxPrivateData()->maDisplayBackground;
8123     }
8124 
8125     if( !IsBackground() )
8126     {
8127         if( mpWindowImpl->mpParent )
8128             return mpWindowImpl->mpParent->GetDisplayBackground();
8129     }
8130 
8131     const Wallpaper& rBack = GetBackground();
8132     if( ! rBack.IsBitmap() &&
8133         ! rBack.IsGradient() &&
8134         rBack.GetColor().GetColor() == COL_TRANSPARENT &&
8135         mpWindowImpl->mpParent )
8136             return mpWindowImpl->mpParent->GetDisplayBackground();
8137     return rBack;
8138 }
8139 
8140 // -----------------------------------------------------------------------
8141 
8142 const XubString& Window::GetHelpText() const
8143 {
8144     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8145 
8146 	String aStrHelpId( rtl::OStringToOUString( GetHelpId(), RTL_TEXTENCODING_UTF8 ) );
8147 	bool bStrHelpId = (aStrHelpId.Len() > 0);
8148 
8149     if ( !mpWindowImpl->maHelpText.Len() && bStrHelpId )
8150     {
8151         if ( !IsDialog() && (mpWindowImpl->mnType != WINDOW_TABPAGE) && (mpWindowImpl->mnType != WINDOW_FLOATINGWINDOW) )
8152         {
8153             Help* pHelp = Application::GetHelp();
8154             if ( pHelp )
8155 			{
8156 			    ((Window*)this)->mpWindowImpl->maHelpText = pHelp->GetHelpText( aStrHelpId, this );
8157                 mpWindowImpl->mbHelpTextDynamic = sal_False;
8158 			}
8159         }
8160     }
8161     else if( mpWindowImpl->mbHelpTextDynamic && bStrHelpId )
8162     {
8163         static const char* pEnv = getenv( "HELP_DEBUG" );
8164         if( pEnv && *pEnv )
8165         {
8166             rtl::OUStringBuffer aTxt( 64+mpWindowImpl->maHelpText.Len() );
8167             aTxt.append( mpWindowImpl->maHelpText );
8168             aTxt.appendAscii( "\n------------------\n" );
8169             aTxt.append( rtl::OUString( aStrHelpId ) );
8170             mpWindowImpl->maHelpText = aTxt.makeStringAndClear();
8171         }
8172         mpWindowImpl->mbHelpTextDynamic = sal_False;
8173     }
8174 
8175     return mpWindowImpl->maHelpText;
8176 }
8177 
8178 // -----------------------------------------------------------------------
8179 
8180 Window* Window::FindWindow( const Point& rPos ) const
8181 {
8182     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8183 
8184     Point aPos = OutputToScreenPixel( rPos );
8185     return ((Window*)this)->ImplFindWindow( aPos );
8186 }
8187 
8188 // -----------------------------------------------------------------------
8189 
8190 sal_uInt16 Window::GetChildCount() const
8191 {
8192     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8193 
8194     sal_uInt16  nChildCount = 0;
8195     Window* pChild = mpWindowImpl->mpFirstChild;
8196     while ( pChild )
8197     {
8198         nChildCount++;
8199         pChild = pChild->mpWindowImpl->mpNext;
8200     }
8201 
8202     return nChildCount;
8203 }
8204 
8205 // -----------------------------------------------------------------------
8206 
8207 Window* Window::GetChild( sal_uInt16 nChild ) const
8208 {
8209     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8210 
8211     sal_uInt16  nChildCount = 0;
8212     Window* pChild = mpWindowImpl->mpFirstChild;
8213     while ( pChild )
8214     {
8215         if ( nChild == nChildCount )
8216             return pChild;
8217         pChild = pChild->mpWindowImpl->mpNext;
8218         nChildCount++;
8219     }
8220 
8221     return NULL;
8222 }
8223 
8224 // -----------------------------------------------------------------------
8225 
8226 Window* Window::GetWindow( sal_uInt16 nType ) const
8227 {
8228     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8229 
8230     switch ( nType )
8231     {
8232         case WINDOW_PARENT:
8233             return mpWindowImpl->mpRealParent;
8234 
8235         case WINDOW_FIRSTCHILD:
8236             return mpWindowImpl->mpFirstChild;
8237 
8238         case WINDOW_LASTCHILD:
8239             return mpWindowImpl->mpLastChild;
8240 
8241         case WINDOW_PREV:
8242             return mpWindowImpl->mpPrev;
8243 
8244         case WINDOW_NEXT:
8245             return mpWindowImpl->mpNext;
8246 
8247         case WINDOW_FIRSTOVERLAP:
8248             return mpWindowImpl->mpFirstOverlap;
8249 
8250         case WINDOW_LASTOVERLAP:
8251             return mpWindowImpl->mpLastOverlap;
8252 
8253         case WINDOW_OVERLAP:
8254             if ( ImplIsOverlapWindow() )
8255                 return (Window*)this;
8256             else
8257                 return mpWindowImpl->mpOverlapWindow;
8258 
8259         case WINDOW_PARENTOVERLAP:
8260             if ( ImplIsOverlapWindow() )
8261                 return mpWindowImpl->mpOverlapWindow;
8262             else
8263                 return mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpOverlapWindow;
8264 
8265         case WINDOW_CLIENT:
8266             return ((Window*)this)->ImplGetWindow();
8267 
8268         case WINDOW_REALPARENT:
8269             return ImplGetParent();
8270 
8271         case WINDOW_FRAME:
8272             return mpWindowImpl->mpFrameWindow;
8273 
8274         case WINDOW_BORDER:
8275             if ( mpWindowImpl->mpBorderWindow )
8276                 return mpWindowImpl->mpBorderWindow->GetWindow( WINDOW_BORDER );
8277             return (Window*)this;
8278 
8279         case WINDOW_FIRSTTOPWINDOWCHILD:
8280             return ImplGetWinData()->maTopWindowChildren.empty() ? NULL : *ImplGetWinData()->maTopWindowChildren.begin();
8281 
8282         case WINDOW_LASTTOPWINDOWCHILD:
8283             return ImplGetWinData()->maTopWindowChildren.empty() ? NULL : *ImplGetWinData()->maTopWindowChildren.rbegin();
8284 
8285         case WINDOW_PREVTOPWINDOWSIBLING:
8286         {
8287             if ( !mpWindowImpl->mpRealParent )
8288                 return NULL;
8289             const ::std::list< Window* >& rTopWindows( mpWindowImpl->mpRealParent->ImplGetWinData()->maTopWindowChildren );
8290             ::std::list< Window* >::const_iterator myPos =
8291                 ::std::find( rTopWindows.begin(), rTopWindows.end(), this );
8292             if ( myPos == rTopWindows.end() )
8293                 return NULL;
8294             if ( myPos == rTopWindows.begin() )
8295                 return NULL;
8296             return *--myPos;
8297         }
8298 
8299         case WINDOW_NEXTTOPWINDOWSIBLING:
8300         {
8301             if ( !mpWindowImpl->mpRealParent )
8302                 return NULL;
8303             const ::std::list< Window* >& rTopWindows( mpWindowImpl->mpRealParent->ImplGetWinData()->maTopWindowChildren );
8304             ::std::list< Window* >::const_iterator myPos =
8305                 ::std::find( rTopWindows.begin(), rTopWindows.end(), this );
8306             if ( ( myPos == rTopWindows.end() ) || ( ++myPos == rTopWindows.end() ) )
8307                 return NULL;
8308             return *myPos;
8309         }
8310 
8311     }
8312 
8313     return NULL;
8314 }
8315 
8316 // -----------------------------------------------------------------------
8317 
8318 sal_Bool Window::IsChild( const Window* pWindow, sal_Bool bSystemWindow ) const
8319 {
8320     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8321     DBG_CHKOBJ( pWindow, Window, ImplDbgCheckWindow );
8322 
8323     do
8324     {
8325         if ( !bSystemWindow && pWindow->ImplIsOverlapWindow() )
8326             break;
8327 
8328         pWindow = pWindow->ImplGetParent();
8329 
8330         if ( pWindow == this )
8331             return sal_True;
8332     }
8333     while ( pWindow );
8334 
8335     return sal_False;
8336 }
8337 
8338 // -----------------------------------------------------------------------
8339 
8340 sal_Bool Window::IsWindowOrChild( const Window* pWindow, sal_Bool bSystemWindow ) const
8341 {
8342     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8343     DBG_CHKOBJ( pWindow, Window, ImplDbgCheckWindow );
8344 
8345     if ( this == pWindow )
8346         return sal_True;
8347     return ImplIsChild( pWindow, bSystemWindow );
8348 }
8349 
8350 // -----------------------------------------------------------------------
8351 
8352 const SystemEnvData* Window::GetSystemData() const
8353 {
8354     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8355 
8356     return mpWindowImpl->mpFrame ? mpWindowImpl->mpFrame->GetSystemData() : NULL;
8357 }
8358 
8359 ::com::sun::star::uno::Any Window::GetSystemDataAny() const
8360 {
8361     ::com::sun::star::uno::Any aRet;
8362     const SystemEnvData* pSysData = GetSystemData();
8363     if( pSysData )
8364     {
8365         ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( (sal_Int8*)pSysData, pSysData->nSize );
8366         aRet <<= aSeq;
8367     }
8368     return aRet;
8369 }
8370 
8371 // -----------------------------------------------------------------------
8372 
8373 void Window::SetWindowPeer( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer, VCLXWindow* pVCLXWindow  )
8374 {
8375     // be safe against re-entrance: first clear the old ref, then assign the new one
8376     // #133706# / 2006-03-30 / frank.schoenheit@sun.com
8377     mpWindowImpl->mxWindowPeer.clear();
8378     mpWindowImpl->mxWindowPeer = xPeer;
8379 
8380     mpWindowImpl->mpVCLXWindow = pVCLXWindow;
8381 }
8382 
8383 // -----------------------------------------------------------------------
8384 
8385 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > Window::GetComponentInterface( sal_Bool bCreate )
8386 {
8387     if ( !mpWindowImpl->mxWindowPeer.is() && bCreate )
8388     {
8389         UnoWrapperBase* pWrapper = Application::GetUnoWrapper();
8390         if ( pWrapper )
8391             mpWindowImpl->mxWindowPeer = pWrapper->GetWindowInterface( this, sal_True );
8392     }
8393     return mpWindowImpl->mxWindowPeer;
8394 }
8395 
8396 // -----------------------------------------------------------------------
8397 
8398 void Window::SetComponentInterface( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xIFace )
8399 {
8400     UnoWrapperBase* pWrapper = Application::GetUnoWrapper();
8401     DBG_ASSERT( pWrapper, "SetComponentInterface: No Wrapper!" );
8402     if ( pWrapper )
8403         pWrapper->SetWindowInterface( this, xIFace );
8404 }
8405 
8406 // -----------------------------------------------------------------------
8407 
8408 void Window::ImplCallDeactivateListeners( Window *pNew )
8409 {
8410     // no deactivation if the the newly activated window is my child
8411     if ( !pNew || !ImplIsChild( pNew ) )
8412     {
8413         ImplDelData aDogtag( this );
8414         ImplCallEventListeners( VCLEVENT_WINDOW_DEACTIVATE );
8415         if( aDogtag.IsDelete() )
8416             return;
8417 
8418         // #100759#, avoid walking the wrong frame's hierarchy
8419         //           eg, undocked docking windows (ImplDockFloatWin)
8420         if ( ImplGetParent() && mpWindowImpl->mpFrameWindow == ImplGetParent()->mpWindowImpl->mpFrameWindow )
8421             ImplGetParent()->ImplCallDeactivateListeners( pNew );
8422     }
8423 }
8424 
8425 // -----------------------------------------------------------------------
8426 
8427 void Window::ImplCallActivateListeners( Window *pOld )
8428 {
8429     // no activation if the the old active window is my child
8430     if ( !pOld || !ImplIsChild( pOld ) )
8431     {
8432         ImplDelData aDogtag( this );
8433         ImplCallEventListeners( VCLEVENT_WINDOW_ACTIVATE, pOld );
8434         if( aDogtag.IsDelete() )
8435             return;
8436 
8437 		// #106298# revoke the change for 105369, because this change
8438 		//          disabled the activate event for the parent,
8439 		//          if the parent is a compound control
8440 		//if( !GetParent() || !GetParent()->IsCompoundControl() )
8441 		//{
8442 			// #100759#, avoid walking the wrong frame's hierarchy
8443 			//           eg, undocked docking windows (ImplDockFloatWin)
8444             // #104714#, revert the changes for 100759 because it has a side effect when pOld is a dialog
8445             //           additionally the gallery is not dockable anymore, so 100759 canot occur
8446 			if ( ImplGetParent() ) /* && mpWindowImpl->mpFrameWindow == ImplGetParent()->mpWindowImpl->mpFrameWindow ) */
8447 				ImplGetParent()->ImplCallActivateListeners( pOld );
8448             else if( (mpWindowImpl->mnStyle & WB_INTROWIN) == 0 )
8449             {
8450                 // top level frame reached: store hint for DefModalDialogParent
8451                 ImplGetSVData()->maWinData.mpActiveApplicationFrame = mpWindowImpl->mpFrameWindow;
8452             }
8453         //}
8454     }
8455 }
8456 
8457 // -----------------------------------------------------------------------
8458 
8459 bool Window::ImplStopDnd()
8460 {
8461     bool bRet = false;
8462     if( mpWindowImpl->mpFrameData && mpWindowImpl->mpFrameData->mxDropTargetListener.is() )
8463     {
8464         bRet = true;
8465         mpWindowImpl->mpFrameData->mxDropTarget.clear();
8466         mpWindowImpl->mpFrameData->mxDragSource.clear();
8467         mpWindowImpl->mpFrameData->mxDropTargetListener.clear();
8468     }
8469 
8470     return bRet;
8471 }
8472 
8473 // -----------------------------------------------------------------------
8474 
8475 void Window::ImplStartDnd()
8476 {
8477     GetDropTarget();
8478 }
8479 
8480 // -----------------------------------------------------------------------
8481 
8482 uno::Reference< XDropTarget > Window::GetDropTarget()
8483 {
8484     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8485 
8486     if( ! mpWindowImpl->mxDNDListenerContainer.is() )
8487     {
8488         sal_Int8 nDefaultActions = 0;
8489 
8490         if( mpWindowImpl->mpFrameData )
8491         {
8492             if( ! mpWindowImpl->mpFrameData->mxDropTarget.is() )
8493             {
8494                 // initialization is done in GetDragSource
8495                 uno::Reference< XDragSource > xDragSource = GetDragSource();
8496             }
8497 
8498             if( mpWindowImpl->mpFrameData->mxDropTarget.is() )
8499             {
8500                 nDefaultActions = mpWindowImpl->mpFrameData->mxDropTarget->getDefaultActions();
8501 
8502                 if( ! mpWindowImpl->mpFrameData->mxDropTargetListener.is() )
8503                 {
8504                     mpWindowImpl->mpFrameData->mxDropTargetListener = new DNDEventDispatcher( mpWindowImpl->mpFrameWindow );
8505 
8506                     try
8507                     {
8508                         mpWindowImpl->mpFrameData->mxDropTarget->addDropTargetListener( mpWindowImpl->mpFrameData->mxDropTargetListener );
8509 
8510                         // register also as drag gesture listener if directly supported by drag source
8511                         uno::Reference< XDragGestureRecognizer > xDragGestureRecognizer =
8512                             uno::Reference< XDragGestureRecognizer > (mpWindowImpl->mpFrameData->mxDragSource, UNO_QUERY);
8513 
8514                         if( xDragGestureRecognizer.is() )
8515                         {
8516                             xDragGestureRecognizer->addDragGestureListener(
8517                                 uno::Reference< XDragGestureListener > (mpWindowImpl->mpFrameData->mxDropTargetListener, UNO_QUERY));
8518                         }
8519                         else
8520                             mpWindowImpl->mpFrameData->mbInternalDragGestureRecognizer = sal_True;
8521 
8522                     }
8523 
8524                     catch( RuntimeException&)
8525                     {
8526                         // release all instances
8527                         mpWindowImpl->mpFrameData->mxDropTarget.clear();
8528                         mpWindowImpl->mpFrameData->mxDragSource.clear();
8529                     }
8530                 }
8531             }
8532 
8533         }
8534 
8535         mpWindowImpl->mxDNDListenerContainer = static_cast < XDropTarget * > ( new DNDListenerContainer( nDefaultActions ) );
8536     }
8537 
8538     // this object is located in the same process, so there will be no runtime exception
8539     return uno::Reference< XDropTarget > ( mpWindowImpl->mxDNDListenerContainer, UNO_QUERY );
8540 }
8541 
8542 // -----------------------------------------------------------------------
8543 
8544 uno::Reference< XDragSource > Window::GetDragSource()
8545 {
8546     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8547 
8548     if( mpWindowImpl->mpFrameData )
8549     {
8550         if( ! mpWindowImpl->mpFrameData->mxDragSource.is() )
8551         {
8552             try
8553             {
8554                 uno::Reference< XMultiServiceFactory > xFactory = vcl::unohelper::GetMultiServiceFactory();
8555                 if ( xFactory.is() )
8556                 {
8557                     const SystemEnvData * pEnvData = GetSystemData();
8558 
8559                     if( pEnvData )
8560                     {
8561                         Sequence< Any > aDragSourceAL( 2 ), aDropTargetAL( 2 );
8562                         OUString aDragSourceSN, aDropTargetSN;
8563 #if defined WNT
8564                         aDragSourceSN = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.OleDragSource" );
8565                         aDropTargetSN = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.OleDropTarget" );
8566                         aDragSourceAL[ 1 ] = makeAny( (sal_uInt32) pEnvData->hWnd );
8567                         aDropTargetAL[ 0 ] = makeAny( (sal_uInt32) pEnvData->hWnd );
8568 #elif defined QUARTZ
8569 			/* FIXME: Mac OS X specific dnd interface does not exist! *
8570 			 * Using Windows based dnd as a temporary solution        */
8571                         aDragSourceSN = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.OleDragSource" );
8572                         aDropTargetSN = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.OleDropTarget" );
8573                         aDragSourceAL[ 1 ] = makeAny( static_cast<sal_uInt64>( reinterpret_cast<sal_IntPtr>(pEnvData->pView) ) );
8574                         aDropTargetAL[ 0 ] = makeAny( static_cast<sal_uInt64>( reinterpret_cast<sal_IntPtr>(pEnvData->pView) ) );
8575 #elif defined UNX
8576                         aDropTargetAL.realloc( 3 );
8577                         aDragSourceAL.realloc( 3 );
8578                         aDragSourceSN = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.X11DragSource" );
8579                         aDropTargetSN = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.X11DropTarget" );
8580 
8581                         aDragSourceAL[ 0 ] = makeAny( Application::GetDisplayConnection() );
8582                         aDragSourceAL[ 2 ] = makeAny( vcl::createBmpConverter() );
8583                         aDropTargetAL[ 0 ] = makeAny( Application::GetDisplayConnection() );
8584                         aDropTargetAL[ 1 ] = makeAny( (sal_Size)(pEnvData->aShellWindow) );
8585                         aDropTargetAL[ 2 ] = makeAny( vcl::createBmpConverter() );
8586 #endif
8587                         if( aDragSourceSN.getLength() )
8588                             mpWindowImpl->mpFrameData->mxDragSource = uno::Reference< XDragSource > ( xFactory->createInstanceWithArguments( aDragSourceSN, aDragSourceAL ), UNO_QUERY );
8589 
8590                         if( aDropTargetSN.getLength() )
8591                             mpWindowImpl->mpFrameData->mxDropTarget = uno::Reference< XDropTarget > ( xFactory->createInstanceWithArguments( aDropTargetSN, aDropTargetAL ), UNO_QUERY );
8592                     }
8593                 }
8594             }
8595 
8596             // createInstance can throw any exception
8597             catch( Exception&)
8598             {
8599                 // release all instances
8600                 mpWindowImpl->mpFrameData->mxDropTarget.clear();
8601                 mpWindowImpl->mpFrameData->mxDragSource.clear();
8602             }
8603         }
8604 
8605         return mpWindowImpl->mpFrameData->mxDragSource;
8606     }
8607 
8608     return uno::Reference< XDragSource > ();
8609 }
8610 
8611 // -----------------------------------------------------------------------
8612 
8613 void Window::GetDragSourceDropTarget(uno::Reference< XDragSource >& xDragSource, uno::Reference< XDropTarget > &xDropTarget )
8614 // only for RVP transmission
8615 {
8616     if( mpWindowImpl->mpFrameData )
8617     {
8618         // initialization is done in GetDragSource
8619         xDragSource = GetDragSource();
8620         xDropTarget = mpWindowImpl->mpFrameData->mxDropTarget;
8621     }
8622     else
8623     {
8624         xDragSource.clear();
8625         xDropTarget.clear();
8626     }
8627 }
8628 
8629 // -----------------------------------------------------------------------
8630 
8631 uno::Reference< XDragGestureRecognizer > Window::GetDragGestureRecognizer()
8632 {
8633     return uno::Reference< XDragGestureRecognizer > ( GetDropTarget(), UNO_QUERY );
8634 }
8635 
8636 // -----------------------------------------------------------------------
8637 
8638 uno::Reference< XClipboard > Window::GetClipboard()
8639 {
8640     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8641 
8642     if( mpWindowImpl->mpFrameData )
8643     {
8644         if( ! mpWindowImpl->mpFrameData->mxClipboard.is() )
8645         {
8646             try
8647             {
8648                 uno::Reference< XMultiServiceFactory > xFactory( vcl::unohelper::GetMultiServiceFactory() );
8649 
8650                 if( xFactory.is() )
8651                 {
8652                     mpWindowImpl->mpFrameData->mxClipboard = uno::Reference< XClipboard >( xFactory->createInstance( OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.SystemClipboardExt" ) ), UNO_QUERY );
8653 
8654                     if( !mpWindowImpl->mpFrameData->mxClipboard.is() )
8655                         mpWindowImpl->mpFrameData->mxClipboard = uno::Reference< XClipboard >( xFactory->createInstance( OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.SystemClipboard" ) ), UNO_QUERY );
8656 
8657 #if defined(UNX) && !defined(QUARTZ)          // unix clipboard needs to be initialized
8658                     if( mpWindowImpl->mpFrameData->mxClipboard.is() )
8659                     {
8660                         uno::Reference< XInitialization > xInit = uno::Reference< XInitialization >( mpWindowImpl->mpFrameData->mxClipboard, UNO_QUERY );
8661 
8662                         if( xInit.is() )
8663                         {
8664                             Sequence< Any > aArgumentList( 3 );
8665                             aArgumentList[ 0 ] = makeAny( Application::GetDisplayConnection() );
8666                             aArgumentList[ 1 ] = makeAny( OUString::createFromAscii( "CLIPBOARD" ) );
8667                             aArgumentList[ 2 ] = makeAny( vcl::createBmpConverter() );
8668 
8669                             xInit->initialize( aArgumentList );
8670                         }
8671                     }
8672 #endif
8673                 }
8674             }
8675 
8676             // createInstance can throw any exception
8677             catch( Exception&)
8678             {
8679                 // release all instances
8680                 mpWindowImpl->mpFrameData->mxClipboard.clear();
8681             }
8682         }
8683 
8684         return mpWindowImpl->mpFrameData->mxClipboard;
8685     }
8686 
8687     return static_cast < XClipboard * > (0);
8688 }
8689 
8690 // -----------------------------------------------------------------------
8691 
8692 uno::Reference< XClipboard > Window::GetPrimarySelection()
8693 {
8694     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8695 
8696     if( mpWindowImpl->mpFrameData )
8697     {
8698         if( ! mpWindowImpl->mpFrameData->mxSelection.is() )
8699         {
8700             try
8701             {
8702                 uno::Reference< XMultiServiceFactory > xFactory( vcl::unohelper::GetMultiServiceFactory() );
8703 
8704                 if( xFactory.is() )
8705                 {
8706 #if defined(UNX) && !defined(QUARTZ)
8707                     Sequence< Any > aArgumentList( 3 );
8708                   	aArgumentList[ 0 ] = makeAny( Application::GetDisplayConnection() );
8709                     aArgumentList[ 1 ] = makeAny( OUString::createFromAscii( "PRIMARY" ) );
8710                     aArgumentList[ 2 ] = makeAny( vcl::createBmpConverter() );
8711 
8712                     mpWindowImpl->mpFrameData->mxSelection = uno::Reference< XClipboard >( xFactory->createInstanceWithArguments(
8713 					OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.SystemClipboard" ), aArgumentList ), UNO_QUERY );
8714 #	else
8715 					static uno::Reference< XClipboard >	s_xSelection;
8716 
8717 					if ( !s_xSelection.is() )
8718  						s_xSelection = uno::Reference< XClipboard >( xFactory->createInstance( OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.GenericClipboardExt" ) ), UNO_QUERY );
8719 
8720 					if ( !s_xSelection.is() )
8721  						s_xSelection = uno::Reference< XClipboard >( xFactory->createInstance( OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.GenericClipboard" ) ), UNO_QUERY );
8722 
8723                     mpWindowImpl->mpFrameData->mxSelection = s_xSelection;
8724 #	endif
8725                 }
8726             }
8727 
8728             // createInstance can throw any exception
8729             catch( Exception&)
8730             {
8731                 // release all instances
8732                 mpWindowImpl->mpFrameData->mxSelection.clear();
8733             }
8734         }
8735 
8736         return mpWindowImpl->mpFrameData->mxSelection;
8737     }
8738 
8739     return static_cast < XClipboard * > (0);
8740 }
8741 
8742 // -----------------------------------------------------------------------
8743 // Accessibility
8744 // -----------------------------------------------------------------------
8745 
8746 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > Window::GetAccessible( sal_Bool bCreate )
8747 {
8748     // do not optimize hierarchy for the top level border win (ie, when there is no parent)
8749     /* // do not optimize accessible hierarchy at all to better reflect real VCL hierarchy
8750 	if ( GetParent() && ( GetType() == WINDOW_BORDERWINDOW ) && ( GetChildCount() == 1 ) )
8751     //if( !ImplIsAccessibleCandidate() )
8752 	{
8753 		Window* pChild = GetAccessibleChildWindow( 0 );
8754 		if ( pChild )
8755 			return pChild->GetAccessible();
8756 	}
8757     */
8758     if ( !mpWindowImpl->mxAccessible.is() && bCreate )
8759         mpWindowImpl->mxAccessible = CreateAccessible();
8760 
8761 	return mpWindowImpl->mxAccessible;
8762 }
8763 
8764 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > Window::CreateAccessible()
8765 {
8766     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc( GetComponentInterface( sal_True ), ::com::sun::star::uno::UNO_QUERY );
8767     return xAcc;
8768 }
8769 
8770 void Window::SetAccessible( ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > x )
8771 {
8772     mpWindowImpl->mxAccessible = x;
8773 }
8774 
8775 // skip all border windows that are no top level frames
8776 sal_Bool Window::ImplIsAccessibleCandidate() const
8777 {
8778     if( !mpWindowImpl->mbBorderWin )
8779         return sal_True;
8780     else
8781         // #101741 do not check for WB_CLOSEABLE because undecorated floaters (like menues!) are closeable
8782         if( mpWindowImpl->mbFrame && mpWindowImpl->mnStyle & (WB_MOVEABLE | WB_SIZEABLE) )
8783             return sal_True;
8784         else
8785             return sal_False;
8786 }
8787 
8788 sal_Bool Window::ImplIsAccessibleNativeFrame() const
8789 {
8790     if( mpWindowImpl->mbFrame )
8791         // #101741 do not check for WB_CLOSEABLE because undecorated floaters (like menues!) are closeable
8792         if( (mpWindowImpl->mnStyle & (WB_MOVEABLE | WB_SIZEABLE)) )
8793             return sal_True;
8794         else
8795             return sal_False;
8796     else
8797         return sal_False;
8798 }
8799 
8800 sal_uInt16 Window::ImplGetAccessibleCandidateChildWindowCount( sal_uInt16 nFirstWindowType ) const
8801 {
8802     sal_uInt16  nChildren = 0;
8803     Window* pChild = GetWindow( nFirstWindowType );
8804     while ( pChild )
8805     {
8806         if( pChild->ImplIsAccessibleCandidate() )
8807             nChildren++;
8808         else
8809             nChildren = sal::static_int_cast<sal_uInt16>(nChildren + pChild->ImplGetAccessibleCandidateChildWindowCount( WINDOW_FIRSTCHILD ));
8810         pChild = pChild->mpWindowImpl->mpNext;
8811     }
8812     return nChildren;
8813 }
8814 
8815 Window* Window::ImplGetAccessibleCandidateChild( sal_uInt16 nChild, sal_uInt16& rChildCount, sal_uInt16 nFirstWindowType, sal_Bool bTopLevel ) const
8816 {
8817     DBG_CHKTHIS( Window, ImplDbgCheckWindow );
8818 
8819     if( bTopLevel )
8820         rChildCount = 0;
8821 
8822     Window* pChild = GetWindow( nFirstWindowType );
8823     while ( pChild )
8824     {
8825         Window *pTmpChild = pChild;
8826 
8827         if( !pChild->ImplIsAccessibleCandidate() )
8828             pTmpChild = pChild->ImplGetAccessibleCandidateChild( nChild, rChildCount, WINDOW_FIRSTCHILD, sal_False );
8829 
8830         if ( nChild == rChildCount )
8831             return pTmpChild;
8832         pChild = pChild->mpWindowImpl->mpNext;
8833         rChildCount++;
8834     }
8835 
8836     return NULL;
8837 }
8838 
8839 /*
8840 Window* Window::GetAccessibleParentWindow() const
8841 {
8842     Window* pParent = GetParent();
8843     while ( pParent )
8844         if( pParent->ImplIsAccessibleCandidate() )
8845             break;
8846         else
8847             pParent = pParent->GetParent();
8848     return pParent;
8849 }
8850 */
8851 
8852 Window* Window::GetAccessibleParentWindow() const
8853 {
8854 	if ( ImplIsAccessibleNativeFrame() )
8855 		return NULL;
8856 
8857     Window* pParent = mpWindowImpl->mpParent;
8858     if( GetType() == WINDOW_MENUBARWINDOW )
8859     {
8860         // report the menubar as a child of THE workwindow
8861         Window *pWorkWin = GetParent()->mpWindowImpl->mpFirstChild;
8862         while( pWorkWin && (pWorkWin == this) )
8863             pWorkWin = pWorkWin->mpWindowImpl->mpNext;
8864         pParent = pWorkWin;
8865     }
8866     // If this a floating window which has a native boarder window, this one should be reported as
8867     // accessible parent
8868     else if( GetType() == WINDOW_FLOATINGWINDOW &&
8869 		mpWindowImpl->mpBorderWindow && mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame)
8870     {
8871         pParent = mpWindowImpl->mpBorderWindow;
8872     }
8873     else if( pParent && !pParent->ImplIsAccessibleCandidate() )
8874     {
8875         pParent = pParent->mpWindowImpl->mpParent;
8876     }
8877     return pParent;
8878 }
8879 
8880 /*
8881 sal_uInt16 Window::GetAccessibleChildWindowCount()
8882 {
8883     sal_uInt16 nChildren = ImplGetAccessibleCandidateChildWindowCount( WINDOW_FIRSTCHILD );
8884 
8885     // Search also for SystemWindows.
8886 	Window* pOverlap = GetWindow( WINDOW_OVERLAP );
8887     nChildren += pOverlap->ImplGetAccessibleCandidateChildWindowCount( WINDOW_FIRSTOVERLAP );
8888 
8889     return nChildren;
8890 }
8891 */
8892 
8893 sal_uInt16 Window::GetAccessibleChildWindowCount()
8894 {
8895     sal_uInt16 nChildren = 0;
8896     Window* pChild = mpWindowImpl->mpFirstChild;
8897     while( pChild )
8898     {
8899         if( pChild->IsVisible() )
8900             nChildren++;
8901         pChild = pChild->mpWindowImpl->mpNext;
8902     }
8903 
8904     // #107176# ignore overlapwindows
8905     // this only affects non-system floating windows
8906     // which are either not accessible (like the HelpAgent) or should be changed to system windows anyway
8907     /*
8908     if( ImplIsOverlapWindow() )
8909     {
8910 	    Window* pOverlap = GetWindow( WINDOW_FIRSTOVERLAP );
8911 	    while ( pOverlap )
8912 	    {
8913             if( pOverlap->IsVisible() )
8914                 nChildren++;
8915 		    pOverlap = pOverlap->GetWindow( WINDOW_NEXT );
8916 	    }
8917     }
8918     */
8919 
8920     // report the menubarwindow as a child of THE workwindow
8921     if( GetType() == WINDOW_BORDERWINDOW )
8922     {
8923         if( ((ImplBorderWindow *) this)->mpMenuBarWindow &&
8924             ((ImplBorderWindow *) this)->mpMenuBarWindow->IsVisible()
8925             )
8926             --nChildren;
8927     }
8928     else if( GetType() == WINDOW_WORKWINDOW )
8929     {
8930         if( ((WorkWindow *) this)->GetMenuBar() &&
8931             ((WorkWindow *) this)->GetMenuBar()->GetWindow() &&
8932             ((WorkWindow *) this)->GetMenuBar()->GetWindow()->IsVisible()
8933             )
8934             ++nChildren;
8935     }
8936 
8937     return nChildren;
8938 }
8939 
8940 /*
8941 Window* Window::GetAccessibleChildWindow( sal_uInt16 n )
8942 {
8943     sal_uInt16 nChildCount; // will be set in ImplGetAccessibleCandidateChild(...)
8944 	Window* pChild = ImplGetAccessibleCandidateChild( n, nChildCount, WINDOW_FIRSTCHILD, sal_True );
8945     if ( !pChild && ( n >= nChildCount ) )
8946     {
8947 	    Window* pOverlap = GetWindow( WINDOW_OVERLAP );
8948         pChild = pOverlap->ImplGetAccessibleCandidateChild( n, nChildCount, WINDOW_FIRSTOVERLAP, sal_False );
8949     }
8950 
8951     return pChild;
8952 }
8953 */
8954 
8955 Window* Window::GetAccessibleChildWindow( sal_uInt16 n )
8956 {
8957     // report the menubarwindow as a the first child of THE workwindow
8958     if( GetType() == WINDOW_WORKWINDOW && ((WorkWindow *) this)->GetMenuBar() )
8959     {
8960         if( n == 0 )
8961         {
8962             MenuBar *pMenuBar = ((WorkWindow *) this)->GetMenuBar();
8963             if( pMenuBar->GetWindow() && pMenuBar->GetWindow()->IsVisible() )
8964                 return pMenuBar->GetWindow();
8965         }
8966         else
8967             --n;
8968     }
8969 
8970     // transform n to child number including invisible children
8971     sal_uInt16 nChildren = n;
8972     Window* pChild = mpWindowImpl->mpFirstChild;
8973     while( pChild )
8974     {
8975         if( pChild->IsVisible() )
8976         {
8977             if( ! nChildren )
8978                 break;
8979             nChildren--;
8980         }
8981         pChild = pChild->mpWindowImpl->mpNext;
8982     }
8983 
8984     if( GetType() == WINDOW_BORDERWINDOW && pChild && pChild->GetType() == WINDOW_MENUBARWINDOW )
8985     {
8986         do pChild = pChild->mpWindowImpl->mpNext; while( pChild && ! pChild->IsVisible() );
8987         DBG_ASSERT( pChild, "GetAccessibleChildWindow(): wrong index in border window");
8988     }
8989     if ( !pChild )
8990     {
8991         // #107176# ignore overlapwindows
8992         /*
8993         if( ImplIsOverlapWindow() )
8994         {
8995 	        Window* pOverlap = GetWindow( WINDOW_FIRSTOVERLAP );
8996 	        while ( !pChild && pOverlap )
8997 	        {
8998                 if ( !nChildren && pOverlap->IsVisible() )
8999                 {
9000                     pChild = pOverlap;
9001                     break;
9002                 }
9003                 pOverlap = pOverlap->GetWindow( WINDOW_NEXT );
9004                 if( pOverlap && pOverlap->IsVisible() )
9005                     nChildren--;
9006 	        }
9007         }
9008         */
9009 
9010     }
9011 	if ( pChild && ( pChild->GetType() == WINDOW_BORDERWINDOW ) && ( pChild->GetChildCount() == 1 ) )
9012     {
9013         pChild = pChild->GetChild( 0 );
9014     }
9015     return pChild;
9016 }
9017 
9018 
9019 void Window::SetAccessibleRole( sal_uInt16 nRole )
9020 {
9021     if ( !mpWindowImpl->mpAccessibleInfos )
9022         mpWindowImpl->mpAccessibleInfos = new ImplAccessibleInfos;
9023 
9024     DBG_ASSERT( mpWindowImpl->mpAccessibleInfos->nAccessibleRole == 0xFFFF, "AccessibleRole already set!" );
9025     mpWindowImpl->mpAccessibleInfos->nAccessibleRole = nRole;
9026 }
9027 
9028 sal_uInt16 Window::GetAccessibleRole() const
9029 {
9030     using namespace ::com::sun::star;
9031 
9032     sal_uInt16 nRole = mpWindowImpl->mpAccessibleInfos ? mpWindowImpl->mpAccessibleInfos->nAccessibleRole : 0xFFFF;
9033     if ( nRole == 0xFFFF )
9034     {
9035         switch ( GetType() )
9036         {
9037             case WINDOW_MESSBOX:    // MT: Would be nice to have special roles!
9038             case WINDOW_INFOBOX:
9039             case WINDOW_WARNINGBOX:
9040             case WINDOW_ERRORBOX:
9041             case WINDOW_QUERYBOX: nRole = accessibility::AccessibleRole::ALERT; break;
9042 
9043             case WINDOW_MODELESSDIALOG:
9044             case WINDOW_MODALDIALOG:
9045             case WINDOW_SYSTEMDIALOG:
9046             case WINDOW_PRINTERSETUPDIALOG:
9047             case WINDOW_PRINTDIALOG:
9048             case WINDOW_TABDIALOG:
9049             case WINDOW_BUTTONDIALOG:
9050             case WINDOW_DIALOG: nRole = accessibility::AccessibleRole::DIALOG; break;
9051 
9052             case WINDOW_PUSHBUTTON:
9053             case WINDOW_OKBUTTON:
9054             case WINDOW_CANCELBUTTON:
9055             case WINDOW_HELPBUTTON:
9056             case WINDOW_IMAGEBUTTON:
9057             case WINDOW_MENUBUTTON:
9058             case WINDOW_MOREBUTTON:
9059             case WINDOW_SPINBUTTON:
9060             case WINDOW_BUTTON: nRole = accessibility::AccessibleRole::PUSH_BUTTON; break;
9061 
9062             case WINDOW_PATHDIALOG: nRole = accessibility::AccessibleRole::DIRECTORY_PANE; break;
9063             case WINDOW_FILEDIALOG: nRole = accessibility::AccessibleRole::FILE_CHOOSER; break;
9064             case WINDOW_COLORDIALOG: nRole = accessibility::AccessibleRole::COLOR_CHOOSER; break;
9065             case WINDOW_FONTDIALOG: nRole = accessibility::AccessibleRole::FONT_CHOOSER; break;
9066 
9067             case WINDOW_IMAGERADIOBUTTON:
9068             case WINDOW_RADIOBUTTON: nRole = accessibility::AccessibleRole::RADIO_BUTTON; break;
9069             case WINDOW_TRISTATEBOX:
9070             case WINDOW_CHECKBOX: nRole = accessibility::AccessibleRole::CHECK_BOX; break;
9071 
9072             case WINDOW_MULTILINEEDIT: nRole = accessibility::AccessibleRole::SCROLL_PANE; break;
9073 
9074             case WINDOW_PATTERNFIELD:
9075             case WINDOW_NUMERICFIELD:
9076             case WINDOW_METRICFIELD:
9077             case WINDOW_CURRENCYFIELD:
9078             case WINDOW_LONGCURRENCYFIELD:
9079             case WINDOW_EDIT: nRole = ( GetStyle() & WB_PASSWORD ) ? (accessibility::AccessibleRole::PASSWORD_TEXT) : (accessibility::AccessibleRole::TEXT); break;
9080 
9081             case WINDOW_PATTERNBOX:
9082             case WINDOW_NUMERICBOX:
9083             case WINDOW_METRICBOX:
9084             case WINDOW_CURRENCYBOX:
9085             case WINDOW_LONGCURRENCYBOX:
9086             case WINDOW_COMBOBOX: nRole = accessibility::AccessibleRole::COMBO_BOX; break;
9087 
9088             case WINDOW_LISTBOX:
9089             case WINDOW_MULTILISTBOX: nRole = accessibility::AccessibleRole::LIST; break;
9090 
9091 			case WINDOW_TREELISTBOX: nRole = accessibility::AccessibleRole::TREE; break;
9092 
9093             case WINDOW_FIXEDTEXT: nRole = accessibility::AccessibleRole::LABEL; break;
9094             case WINDOW_FIXEDBORDER:
9095             case WINDOW_FIXEDLINE: nRole = accessibility::AccessibleRole::SEPARATOR; break;
9096             case WINDOW_FIXEDBITMAP:
9097             case WINDOW_FIXEDIMAGE: nRole = accessibility::AccessibleRole::ICON; break;
9098             case WINDOW_GROUPBOX: nRole = accessibility::AccessibleRole::GROUP_BOX; break;
9099             case WINDOW_SCROLLBAR: nRole = accessibility::AccessibleRole::SCROLL_BAR; break;
9100 
9101             case WINDOW_SLIDER:
9102             case WINDOW_SPLITTER:
9103             case WINDOW_SPLITWINDOW: nRole = accessibility::AccessibleRole::SPLIT_PANE; break;
9104 
9105             case WINDOW_DATEBOX:
9106             case WINDOW_TIMEBOX:
9107             case WINDOW_DATEFIELD:
9108             case WINDOW_TIMEFIELD: nRole = accessibility::AccessibleRole::DATE_EDITOR; break;
9109 
9110             case WINDOW_SPINFIELD: nRole = accessibility::AccessibleRole::SPIN_BOX; break;
9111 
9112             case WINDOW_TOOLBOX: nRole = accessibility::AccessibleRole::TOOL_BAR; break;
9113             case WINDOW_STATUSBAR: nRole = accessibility::AccessibleRole::STATUS_BAR; break;
9114 
9115             case WINDOW_TABPAGE: nRole = accessibility::AccessibleRole::PANEL; break;
9116             case WINDOW_TABCONTROL: nRole = accessibility::AccessibleRole::PAGE_TAB_LIST; break;
9117 
9118             case WINDOW_DOCKINGWINDOW:
9119             case WINDOW_SYSWINDOW:      nRole = (mpWindowImpl->mbFrame) ? accessibility::AccessibleRole::FRAME :
9120                                                                           accessibility::AccessibleRole::PANEL; break;
9121 
9122             case WINDOW_FLOATINGWINDOW: nRole = ( mpWindowImpl->mbFrame ||
9123                                                  (mpWindowImpl->mpBorderWindow && mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame) ||
9124                                                  (GetStyle() & WB_OWNERDRAWDECORATION) ) ? accessibility::AccessibleRole::FRAME :
9125                                                                                            accessibility::AccessibleRole::WINDOW; break;
9126 
9127             case WINDOW_WORKWINDOW: nRole = accessibility::AccessibleRole::ROOT_PANE; break;
9128 
9129 
9130             case WINDOW_SCROLLBARBOX: nRole = accessibility::AccessibleRole::FILLER; break;
9131 
9132             case WINDOW_HELPTEXTWINDOW: nRole = accessibility::AccessibleRole::TOOL_TIP; break;
9133 
9134 			case WINDOW_RULER:			nRole = accessibility::AccessibleRole::RULER; break;
9135             case WINDOW_WINDOW:
9136             case WINDOW_CONTROL:
9137             case WINDOW_BORDERWINDOW:
9138             case WINDOW_SYSTEMCHILDWINDOW:
9139             default:
9140                 if (ImplIsAccessibleNativeFrame() )
9141                     nRole = accessibility::AccessibleRole::FRAME;
9142                 else if( IsScrollable() )
9143                     nRole = accessibility::AccessibleRole::SCROLL_PANE;
9144                 else if( ((Window*)this)->ImplGetWindow()->IsMenuFloatingWindow() )
9145                     nRole = accessibility::AccessibleRole::WINDOW;      // #106002#, contextmenues are windows (i.e. toplevel)
9146                 else
9147                     // #104051# WINDOW seems to be a bad default role, use LAYEREDPANE instead
9148                     // a WINDOW is interpreted as a top-level window, which is typically not the case
9149                     //nRole = accessibility::AccessibleRole::WINDOW;
9150                     nRole = accessibility::AccessibleRole::PANEL;
9151         }
9152     }
9153     return nRole;
9154 }
9155 
9156 void Window::SetAccessibleName( const String& rName )
9157 {
9158    if ( !mpWindowImpl->mpAccessibleInfos )
9159         mpWindowImpl->mpAccessibleInfos = new ImplAccessibleInfos;
9160 
9161     delete mpWindowImpl->mpAccessibleInfos->pAccessibleName;
9162     mpWindowImpl->mpAccessibleInfos->pAccessibleName = new String( rName );
9163 }
9164 
9165 String Window::GetAccessibleName() const
9166 {
9167 	String aAccessibleName;
9168 	if ( mpWindowImpl->mpAccessibleInfos && mpWindowImpl->mpAccessibleInfos->pAccessibleName )
9169 	{
9170 		aAccessibleName = *mpWindowImpl->mpAccessibleInfos->pAccessibleName;
9171 	}
9172 	else
9173 	{
9174         switch ( GetType() )
9175         {
9176 //            case WINDOW_IMAGERADIOBUTTON:
9177 //            case WINDOW_RADIOBUTTON:
9178 //            case WINDOW_TRISTATEBOX:
9179 //            case WINDOW_CHECKBOX:
9180 
9181             case WINDOW_MULTILINEEDIT:
9182             case WINDOW_PATTERNFIELD:
9183             case WINDOW_NUMERICFIELD:
9184             case WINDOW_METRICFIELD:
9185             case WINDOW_CURRENCYFIELD:
9186             case WINDOW_LONGCURRENCYFIELD:
9187             case WINDOW_EDIT:
9188 
9189             case WINDOW_DATEBOX:
9190             case WINDOW_TIMEBOX:
9191             case WINDOW_CURRENCYBOX:
9192             case WINDOW_LONGCURRENCYBOX:
9193             case WINDOW_DATEFIELD:
9194             case WINDOW_TIMEFIELD:
9195             case WINDOW_SPINFIELD:
9196 
9197             case WINDOW_COMBOBOX:
9198             case WINDOW_LISTBOX:
9199             case WINDOW_MULTILISTBOX:
9200 			case WINDOW_TREELISTBOX:
9201 			case WINDOW_METRICBOX:
9202             {
9203                 Window *pLabel = GetAccessibleRelationLabeledBy();
9204                 if ( pLabel && pLabel != this )
9205                     aAccessibleName = pLabel->GetText();
9206             }
9207             break;
9208 
9209             case WINDOW_IMAGEBUTTON:
9210             case WINDOW_PUSHBUTTON:
9211                 aAccessibleName = GetText();
9212                 if ( !aAccessibleName.Len() )
9213                 {
9214                     aAccessibleName = GetQuickHelpText();
9215                     if ( !aAccessibleName.Len() )
9216                         aAccessibleName = GetHelpText();
9217                 }
9218             break;
9219 
9220             default:
9221                 aAccessibleName = GetText();
9222                 break;
9223         }
9224 
9225 		aAccessibleName = GetNonMnemonicString( aAccessibleName );
9226 	}
9227 
9228 	return aAccessibleName;
9229 }
9230 
9231 void Window::SetAccessibleDescription( const String& rDescription )
9232 {
9233    if ( ! mpWindowImpl->mpAccessibleInfos )
9234         mpWindowImpl->mpAccessibleInfos = new ImplAccessibleInfos;
9235 
9236     DBG_ASSERT( !mpWindowImpl->mpAccessibleInfos->pAccessibleDescription, "AccessibleDescription already set!" );
9237     delete mpWindowImpl->mpAccessibleInfos->pAccessibleDescription;
9238     mpWindowImpl->mpAccessibleInfos->pAccessibleDescription = new String( rDescription );
9239 }
9240 
9241 String Window::GetAccessibleDescription() const
9242 {
9243 	String aAccessibleDescription;
9244 	if ( mpWindowImpl->mpAccessibleInfos && mpWindowImpl->mpAccessibleInfos->pAccessibleDescription )
9245 	{
9246 		aAccessibleDescription = *mpWindowImpl->mpAccessibleInfos->pAccessibleDescription;
9247 	}
9248 	else
9249 	{
9250 		// Special code for help text windows. ZT asks the border window for the
9251 		// description so we have to forward this request to our inner window.
9252 		const Window* pWin = ((Window *)this)->ImplGetWindow();
9253 		if ( pWin->GetType() == WINDOW_HELPTEXTWINDOW )
9254 			aAccessibleDescription = pWin->GetHelpText();
9255 		else
9256 			aAccessibleDescription = GetHelpText();
9257 	}
9258 
9259 	return aAccessibleDescription;
9260 }
9261 
9262 void Window::SetAccessibleRelationLabeledBy( Window* pLabeledBy )
9263 {
9264 	if ( !mpWindowImpl->mpAccessibleInfos )
9265 		mpWindowImpl->mpAccessibleInfos = new ImplAccessibleInfos;
9266 	mpWindowImpl->mpAccessibleInfos->pLabeledByWindow = pLabeledBy;
9267 }
9268 
9269 void Window::SetAccessibleRelationLabelFor( Window* pLabelFor )
9270 {
9271 	if ( !mpWindowImpl->mpAccessibleInfos )
9272 		mpWindowImpl->mpAccessibleInfos = new ImplAccessibleInfos;
9273 	mpWindowImpl->mpAccessibleInfos->pLabelForWindow = pLabelFor;
9274 }
9275 
9276 void Window::SetAccessibleRelationMemberOf( Window* pMemberOfWin )
9277 {
9278 	if ( !mpWindowImpl->mpAccessibleInfos )
9279 		mpWindowImpl->mpAccessibleInfos = new ImplAccessibleInfos;
9280 	mpWindowImpl->mpAccessibleInfos->pMemberOfWindow = pMemberOfWin;
9281 }
9282 
9283 sal_Bool Window::IsAccessibilityEventsSuppressed( sal_Bool bTraverseParentPath )
9284 {
9285     if( !bTraverseParentPath )
9286         return mpWindowImpl->mbSuppressAccessibilityEvents;
9287     else
9288     {
9289         Window *pParent = this;
9290         while ( pParent && pParent->mpWindowImpl)
9291         {
9292             if( pParent->mpWindowImpl->mbSuppressAccessibilityEvents )
9293                 return sal_True;
9294             else
9295                 pParent = pParent->mpWindowImpl->mpParent; // do not use GetParent() to find borderwindows that are frames
9296         }
9297         return sal_False;
9298     }
9299 }
9300 
9301 void Window::SetAccessibilityEventsSuppressed(sal_Bool bSuppressed)
9302 {
9303 	mpWindowImpl->mbSuppressAccessibilityEvents = bSuppressed;
9304 }
9305 
9306 void Window::RecordLayoutData( vcl::ControlLayoutData* pLayout, const Rectangle& rRect )
9307 {
9308     if( ! mpOutDevData )
9309         ImplInitOutDevData();
9310 	mpOutDevData->mpRecordLayout = pLayout;
9311 	mpOutDevData->maRecordRect = rRect;
9312     Paint( rRect );
9313     mpOutDevData->mpRecordLayout = NULL;
9314 }
9315 
9316 // -----------------------------------------------------------------------
9317 // -----------------------------------------------------------------------
9318 
9319 
9320 // returns background color used in this control
9321 // false: could not determine color
9322 sal_Bool Window::ImplGetCurrentBackgroundColor( Color& rCol )
9323 {
9324 	sal_Bool bRet = sal_True;
9325 
9326     switch ( GetType() )
9327     {
9328 		// peform special handling here
9329         case WINDOW_PUSHBUTTON:
9330         case WINDOW_OKBUTTON:
9331         case WINDOW_CANCELBUTTON:
9332 		// etc.
9333         default:
9334 			if( IsControlBackground() )
9335 				rCol = GetControlBackground();
9336 			else if( IsBackground() )
9337 				{
9338 					Wallpaper aWall = GetBackground();
9339 					if( !aWall.IsGradient() && !aWall.IsBitmap() )
9340 						rCol = aWall.GetColor();
9341 					else
9342 						bRet = sal_False;
9343 				}
9344 			else
9345 				rCol = GetSettings().GetStyleSettings().GetFaceColor();
9346 			break;
9347     }
9348 	return bRet;
9349 }
9350 
9351 void Window::DrawSelectionBackground( const Rectangle& rRect, sal_uInt16 highlight, sal_Bool bChecked, sal_Bool bDrawBorder, sal_Bool bDrawExtBorderOnly )
9352 {
9353     DrawSelectionBackground( rRect, highlight, bChecked, bDrawBorder, bDrawExtBorderOnly, 0, NULL, NULL );
9354 }
9355 
9356 void Window::DrawSelectionBackground( const Rectangle& rRect, sal_uInt16 highlight, sal_Bool bChecked, sal_Bool bDrawBorder, sal_Bool bDrawExtBorderOnly, Color* pSelectionTextColor )
9357 {
9358     DrawSelectionBackground( rRect, highlight, bChecked, bDrawBorder, bDrawExtBorderOnly, 0, pSelectionTextColor, NULL );
9359 }
9360 
9361 void Window::DrawSelectionBackground( const Rectangle& rRect,
9362                                       sal_uInt16 highlight,
9363                                       sal_Bool bChecked,
9364                                       sal_Bool bDrawBorder,
9365                                       sal_Bool bDrawExtBorderOnly,
9366                                       long nCornerRadius,
9367                                       Color* pSelectionTextColor,
9368                                       Color* pPaintColor
9369                                       )
9370 {
9371     if( rRect.IsEmpty() )
9372         return;
9373 
9374     bool bRoundEdges = nCornerRadius > 0;
9375 
9376     const StyleSettings& rStyles = GetSettings().GetStyleSettings();
9377 
9378 
9379     // colors used for item highlighting
9380     Color aSelectionBorderCol( pPaintColor ? *pPaintColor : rStyles.GetHighlightColor() );
9381     Color aSelectionFillCol( aSelectionBorderCol );
9382 
9383 	sal_Bool bDark = rStyles.GetFaceColor().IsDark();
9384 	sal_Bool bBright = ( rStyles.GetFaceColor() == Color( COL_WHITE ) );
9385 
9386     int c1 = aSelectionBorderCol.GetLuminance();
9387     int c2 = GetDisplayBackground().GetColor().GetLuminance();
9388 
9389     if( !bDark && !bBright && abs( c2-c1 ) < (pPaintColor ? 40 : 75) )
9390     {
9391         // constrast too low
9392         sal_uInt16 h,s,b;
9393         aSelectionFillCol.RGBtoHSB( h, s, b );
9394         if( b > 50 )    b -= 40;
9395         else            b += 40;
9396         aSelectionFillCol.SetColor( Color::HSBtoRGB( h, s, b ) );
9397         aSelectionBorderCol = aSelectionFillCol;
9398     }
9399 
9400     if( bRoundEdges )
9401     {
9402         if( aSelectionBorderCol.IsDark() )
9403             aSelectionBorderCol.IncreaseLuminance( 128 );
9404         else
9405             aSelectionBorderCol.DecreaseLuminance( 128 );
9406     }
9407 
9408     Rectangle aRect( rRect );
9409     if( bDrawExtBorderOnly )
9410     {
9411         aRect.nLeft     -= 1;
9412         aRect.nTop      -= 1;
9413         aRect.nRight    += 1;
9414         aRect.nBottom   += 1;
9415     }
9416     Color oldFillCol = GetFillColor();
9417     Color oldLineCol = GetLineColor();
9418 
9419     if( bDrawBorder )
9420         SetLineColor( bDark ? Color(COL_WHITE) : ( bBright ? Color(COL_BLACK) : aSelectionBorderCol ) );
9421     else
9422         SetLineColor();
9423 
9424     sal_uInt16 nPercent = 0;
9425     if( !highlight )
9426 	{
9427 		if( bDark )
9428 			aSelectionFillCol = COL_BLACK;
9429 		else
9430 			nPercent = 80;  // just checked (light)
9431 	}
9432     else
9433     {
9434         if( bChecked && highlight == 2 )
9435 		{
9436 			if( bDark )
9437 			    aSelectionFillCol = COL_LIGHTGRAY;
9438             else if ( bBright )
9439             {
9440 			    aSelectionFillCol = COL_BLACK;
9441                 SetLineColor( COL_BLACK );
9442                 nPercent = 0;
9443             }
9444             else
9445                 nPercent = bRoundEdges ? 40 : 20;          // selected, pressed or checked ( very dark )
9446 		}
9447         else if( bChecked || highlight == 1 )
9448 		{
9449 			if( bDark )
9450 			    aSelectionFillCol = COL_GRAY;
9451             else if ( bBright )
9452             {
9453 			    aSelectionFillCol = COL_BLACK;
9454                 SetLineColor( COL_BLACK );
9455                 nPercent = 0;
9456             }
9457             else
9458                 nPercent = bRoundEdges ? 60 : 35;          // selected, pressed or checked ( very dark )
9459 		}
9460         else
9461 		{
9462 			if( bDark )
9463 			    aSelectionFillCol = COL_LIGHTGRAY;
9464             else if ( bBright )
9465             {
9466 			    aSelectionFillCol = COL_BLACK;
9467                 SetLineColor( COL_BLACK );
9468                 if( highlight == 3 )
9469                     nPercent = 80;
9470                 else
9471                     nPercent = 0;
9472             }
9473             else
9474                 nPercent = 70;          // selected ( dark )
9475 		}
9476     }
9477 
9478     if( bDark && bDrawExtBorderOnly )
9479     {
9480         SetFillColor();
9481         if( pSelectionTextColor )
9482             *pSelectionTextColor = rStyles.GetHighlightTextColor();
9483     }
9484     else
9485     {
9486         SetFillColor( aSelectionFillCol );
9487         if( pSelectionTextColor )
9488         {
9489             Color aTextColor = IsControlBackground() ? GetControlForeground() : rStyles.GetButtonTextColor();
9490             Color aHLTextColor = rStyles.GetHighlightTextColor();
9491             int nTextDiff = abs(aSelectionFillCol.GetLuminance() - aTextColor.GetLuminance());
9492             int nHLDiff = abs(aSelectionFillCol.GetLuminance() - aHLTextColor.GetLuminance());
9493             *pSelectionTextColor = (nHLDiff >= nTextDiff) ? aHLTextColor : aTextColor;
9494         }
9495     }
9496 
9497 
9498 	if( bDark )
9499 	{
9500 		DrawRect( aRect );
9501 	}
9502 	else
9503 	{
9504         if( bRoundEdges )
9505         {
9506             Polygon aPoly( aRect, nCornerRadius, nCornerRadius );
9507             PolyPolygon aPolyPoly( aPoly );
9508             DrawTransparent( aPolyPoly, nPercent );
9509         }
9510         else
9511         {
9512             Polygon aPoly( aRect );
9513             PolyPolygon aPolyPoly( aPoly );
9514             DrawTransparent( aPolyPoly, nPercent );
9515         }
9516 	}
9517 
9518     SetFillColor( oldFillCol );
9519     SetLineColor( oldLineCol );
9520 }
9521 
9522 /*
9523 void Window::DbgAssertNoEventListeners()
9524 {
9525     VclWindowEvent aEvent( this, 0, NULL );
9526     DBG_ASSERT( mpWindowImpl->maEventListeners.empty(), "Eventlistener: Who is still listening???" )
9527     if ( !mpWindowImpl->maEventListeners.empty() )
9528         mpWindowImpl->maEventListeners.Call( &aEvent );
9529 
9530     DBG_ASSERT( mpWindowImpl->maChildEventListeners.empty(), "ChildEventlistener: Who is still listening???" )
9531     if ( !mpWindowImpl->maChildEventListeners.empty() )
9532         mpWindowImpl->maChildEventListeners.Call( &aEvent );
9533 }
9534 */
9535 
9536 // controls should return the window that gets the
9537 // focus by default, so keyevents can be sent to that window directly
9538 Window* Window::GetPreferredKeyInputWindow()
9539 {
9540     return this;
9541 }
9542 
9543 
9544 sal_Bool Window::IsScrollable() const
9545 {
9546     // check for scrollbars
9547     Window *pChild = mpWindowImpl->mpFirstChild;
9548     while( pChild )
9549     {
9550         if( pChild->GetType() == WINDOW_SCROLLBAR )
9551             return true;
9552         else
9553             pChild = pChild->mpWindowImpl->mpNext;
9554     }
9555     return false;
9556 }
9557 
9558 sal_Bool Window::IsTopWindow() const
9559 {
9560     if ( mpWindowImpl->mbInDtor )
9561         return sal_False;
9562 
9563     // topwindows must be frames or they must have a borderwindow which is a frame
9564     if( !mpWindowImpl->mbFrame && (!mpWindowImpl->mpBorderWindow || (mpWindowImpl->mpBorderWindow && !mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame) ) )
9565         return sal_False;
9566 
9567     ImplGetWinData();
9568     if( mpWindowImpl->mpWinData->mnIsTopWindow == (sal_uInt16)~0)    // still uninitialized
9569     {
9570         // #113722#, cache result of expensive queryInterface call
9571         Window *pThisWin = (Window*)this;
9572         uno::Reference< XTopWindow > xTopWindow( pThisWin->GetComponentInterface(), UNO_QUERY );
9573         pThisWin->mpWindowImpl->mpWinData->mnIsTopWindow = xTopWindow.is() ? 1 : 0;
9574     }
9575     return mpWindowImpl->mpWinData->mnIsTopWindow == 1 ? sal_True : sal_False;
9576 }
9577 
9578 void Window::ImplMirrorFramePos( Point &pt ) const
9579 {
9580     pt.X() = mpWindowImpl->mpFrame->maGeometry.nWidth-1-pt.X();
9581 }
9582 
9583 // frame based modal counter (dialogs are not modal to the whole application anymore)
9584 sal_Bool Window::IsInModalMode() const
9585 {
9586     return (mpWindowImpl->mpFrameWindow->mpWindowImpl->mpFrameData->mnModalMode != 0);
9587 }
9588 void Window::ImplIncModalCount()
9589 {
9590     Window* pFrameWindow = mpWindowImpl->mpFrameWindow;
9591     Window* pParent = pFrameWindow;
9592     while( pFrameWindow )
9593     {
9594         pFrameWindow->mpWindowImpl->mpFrameData->mnModalMode++;
9595         while( pParent && pParent->mpWindowImpl->mpFrameWindow == pFrameWindow )
9596         {
9597             pParent = pParent->GetParent();
9598         }
9599         pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow : NULL;
9600     }
9601 }
9602 void Window::ImplDecModalCount()
9603 {
9604     Window* pFrameWindow = mpWindowImpl->mpFrameWindow;
9605     Window* pParent = pFrameWindow;
9606     while( pFrameWindow )
9607     {
9608         pFrameWindow->mpWindowImpl->mpFrameData->mnModalMode--;
9609         while( pParent && pParent->mpWindowImpl->mpFrameWindow == pFrameWindow )
9610         {
9611             pParent = pParent->GetParent();
9612         }
9613         pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow : NULL;
9614     }
9615 }
9616 sal_Bool Window::ImplIsInTaskPaneList()
9617 {
9618     return mpWindowImpl->mbIsInTaskPaneList;
9619 }
9620 void Window::ImplIsInTaskPaneList( sal_Bool mbIsInTaskList )
9621 {
9622     mpWindowImpl->mbIsInTaskPaneList = mbIsInTaskList;
9623 }
9624 
9625 void Window::ImplNotifyIconifiedState( sal_Bool bIconified )
9626 {
9627     mpWindowImpl->mpFrameWindow->ImplCallEventListeners( bIconified ? VCLEVENT_WINDOW_MINIMIZE : VCLEVENT_WINDOW_NORMALIZE );
9628     // #109206# notify client window as well to have toolkit topwindow listeners notified
9629     if( mpWindowImpl->mpFrameWindow->mpWindowImpl->mpClientWindow && mpWindowImpl->mpFrameWindow != mpWindowImpl->mpFrameWindow->mpWindowImpl->mpClientWindow )
9630         mpWindowImpl->mpFrameWindow->mpWindowImpl->mpClientWindow->ImplCallEventListeners( bIconified ? VCLEVENT_WINDOW_MINIMIZE : VCLEVENT_WINDOW_NORMALIZE );
9631 }
9632 
9633 sal_Bool Window::HasActiveChildFrame()
9634 {
9635     sal_Bool bRet = sal_False;
9636     Window *pFrameWin = ImplGetSVData()->maWinData.mpFirstFrame;
9637     while( pFrameWin )
9638     {
9639         if( pFrameWin != mpWindowImpl->mpFrameWindow )
9640         {
9641             sal_Bool bDecorated = sal_False;
9642             Window *pChildFrame = pFrameWin->ImplGetWindow();
9643             // #i15285# unfortunately WB_MOVEABLE is the same as WB_TABSTOP which can
9644             // be removed for ToolBoxes to influence the keyboard accessibility
9645             // thus WB_MOVEABLE is no indicator for decoration anymore
9646             // but FloatingWindows carry this information in their TitleType...
9647             // TODO: avoid duplicate WinBits !!!
9648             if( pChildFrame && pChildFrame->ImplIsFloatingWindow() )
9649                 bDecorated = ((FloatingWindow*) pChildFrame)->GetTitleType() != FLOATWIN_TITLE_NONE;
9650             if( bDecorated || (pFrameWin->mpWindowImpl->mnStyle & (WB_MOVEABLE | WB_SIZEABLE) ) )
9651                 if( pChildFrame && pChildFrame->IsVisible() && pChildFrame->IsActive() )
9652                 {
9653                     if( ImplIsChild( pChildFrame, sal_True ) )
9654                     {
9655                         bRet = sal_True;
9656                         break;
9657                     }
9658                 }
9659         }
9660         pFrameWin = pFrameWin->mpWindowImpl->mpFrameData->mpNextFrame;
9661     }
9662     return bRet;
9663 }
9664 
9665 LanguageType Window::GetInputLanguage() const
9666 {
9667     return mpWindowImpl->mpFrame->GetInputLanguage();
9668 }
9669 
9670 void Window::EnableNativeWidget( sal_Bool bEnable )
9671 {
9672     static const char* pNoNWF = getenv( "SAL_NO_NWF" );
9673     if( pNoNWF && *pNoNWF )
9674         bEnable = sal_False;
9675 
9676     if( bEnable != ImplGetWinData()->mbEnableNativeWidget )
9677     {
9678         ImplGetWinData()->mbEnableNativeWidget = bEnable;
9679 
9680         // send datachanged event to allow for internal changes required for NWF
9681         // like clipmode, transparency, etc.
9682         DataChangedEvent aDCEvt( DATACHANGED_SETTINGS, &maSettings, SETTINGS_STYLE );
9683         DataChanged( aDCEvt );
9684 
9685         // sometimes the borderwindow is queried, so keep it in sync
9686         if( mpWindowImpl->mpBorderWindow )
9687             mpWindowImpl->mpBorderWindow->ImplGetWinData()->mbEnableNativeWidget = bEnable;
9688     }
9689 
9690     // push down, useful for compound controls
9691     Window *pChild = mpWindowImpl->mpFirstChild;
9692     while( pChild )
9693     {
9694         pChild->EnableNativeWidget( bEnable );
9695         pChild = pChild->mpWindowImpl->mpNext;
9696     }
9697 }
9698 
9699 sal_Bool Window::IsNativeWidgetEnabled() const
9700 {
9701     return ImplGetWinData()->mbEnableNativeWidget;
9702 }
9703 
9704 #ifdef WNT // see #140456#
9705 #include <win/salframe.h>
9706 #endif
9707 
9708 uno::Reference< rendering::XCanvas > Window::ImplGetCanvas( const Size& rFullscreenSize,
9709                                                        bool        bFullscreen,
9710                                                        bool        bSpriteCanvas ) const
9711 {
9712     // try to retrieve hard reference from weak member
9713     uno::Reference< rendering::XCanvas > xCanvas( mpWindowImpl->mxCanvas );
9714 
9715     // canvas still valid? Then we're done.
9716     if( xCanvas.is() )
9717         return xCanvas;
9718 
9719     Sequence< Any > aArg(6);
9720 
9721     // Feed any with operating system's window handle
9722     // ==============================================
9723 
9724     // common: first any is VCL pointer to window (for VCL canvas)
9725     aArg[ 0 ] = makeAny( reinterpret_cast<sal_Int64>(this) );
9726 
9727     // TODO(Q1): Make GetSystemData method virtual
9728 
9729     // check whether we're a SysChild: have to fetch system data
9730     // directly from SystemChildWindow, because the GetSystemData
9731     // method is unfortunately not virtual
9732     const SystemChildWindow* pSysChild = dynamic_cast< const SystemChildWindow* >( this );
9733     if( pSysChild )
9734     {
9735         aArg[ 1 ] = pSysChild->GetSystemDataAny();
9736         aArg[ 5 ] = pSysChild->GetSystemGfxDataAny();
9737     }
9738     else
9739     {
9740         aArg[ 1 ] = GetSystemDataAny();
9741         aArg[ 5 ] = GetSystemGfxDataAny();
9742     }
9743 
9744     if( bFullscreen )
9745         aArg[ 2 ] = makeAny( ::com::sun::star::awt::Rectangle( 0, 0,
9746                                                                rFullscreenSize.Width(),
9747                                                                rFullscreenSize.Height() ) );
9748     else
9749         aArg[ 2 ] = makeAny( ::com::sun::star::awt::Rectangle( mnOutOffX, mnOutOffY, mnOutWidth, mnOutHeight ) );
9750 
9751     aArg[ 3 ] = makeAny( mpWindowImpl->mbAlwaysOnTop ? sal_True : sal_False );
9752     aArg[ 4 ] = makeAny( uno::Reference< awt::XWindow >(
9753                              const_cast<Window*>(this)->GetComponentInterface(),
9754                              uno::UNO_QUERY ));
9755 
9756     uno::Reference< XMultiServiceFactory > xFactory = vcl::unohelper::GetMultiServiceFactory();
9757 
9758     // Create canvas instance with window handle
9759     // =========================================
9760     if ( xFactory.is() )
9761     {
9762         static ::vcl::DeleteUnoReferenceOnDeinit<lang::XMultiServiceFactory> xStaticCanvasFactory(
9763             uno::Reference<lang::XMultiServiceFactory>(
9764                 xFactory->createInstance(
9765                     OUString( RTL_CONSTASCII_USTRINGPARAM(
9766                             "com.sun.star.rendering.CanvasFactory") ) ),
9767                 UNO_QUERY ));
9768         uno::Reference<lang::XMultiServiceFactory> xCanvasFactory(xStaticCanvasFactory.get());
9769 
9770         if(xCanvasFactory.is())
9771         {
9772 #ifdef WNT
9773             // see #140456# - if we're running on a multiscreen setup,
9774             // request special, multi-screen safe sprite canvas
9775             // implementation (not DX5 canvas, as it cannot cope with
9776             // surfaces spanning multiple displays). Note: canvas
9777             // (without sprite) stays the same)
9778 			const sal_uInt32 nDisplay = static_cast< WinSalFrame* >( mpWindowImpl->mpFrame )->mnDisplay;
9779 			if( (nDisplay >= Application::GetScreenCount()) )
9780             {
9781                 xCanvas.set( xCanvasFactory->createInstanceWithArguments(
9782                                  bSpriteCanvas ?
9783                                  OUString( RTL_CONSTASCII_USTRINGPARAM(
9784                                                "com.sun.star.rendering.SpriteCanvas.MultiScreen" )) :
9785                                  OUString( RTL_CONSTASCII_USTRINGPARAM(
9786                                                "com.sun.star.rendering.Canvas.MultiScreen" )),
9787                                  aArg ),
9788                              UNO_QUERY );
9789 
9790             }
9791             else
9792             {
9793 #endif
9794                 xCanvas.set( xCanvasFactory->createInstanceWithArguments(
9795                                  bSpriteCanvas ?
9796                                  OUString( RTL_CONSTASCII_USTRINGPARAM(
9797                                                "com.sun.star.rendering.SpriteCanvas" )) :
9798                                  OUString( RTL_CONSTASCII_USTRINGPARAM(
9799                                                "com.sun.star.rendering.Canvas" )),
9800                                  aArg ),
9801                              UNO_QUERY );
9802 
9803 #ifdef WNT
9804             }
9805 #endif
9806 
9807             mpWindowImpl->mxCanvas = xCanvas;
9808         }
9809     }
9810 
9811     // no factory??? Empty reference, then.
9812     return xCanvas;
9813 }
9814 
9815 uno::Reference< rendering::XCanvas > Window::GetCanvas() const
9816 {
9817     return ImplGetCanvas( Size(), false, false );
9818 }
9819 
9820 uno::Reference< rendering::XSpriteCanvas > Window::GetSpriteCanvas() const
9821 {
9822     uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas(
9823         ImplGetCanvas( Size(), false, true ), uno::UNO_QUERY );
9824     return xSpriteCanvas;
9825 }
9826 
9827 uno::Reference< ::com::sun::star::rendering::XSpriteCanvas > Window::GetFullscreenSpriteCanvas( const Size& rFullscreenSize ) const
9828 {
9829     uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas(
9830         ImplGetCanvas( rFullscreenSize, true, true ), uno::UNO_QUERY );
9831     return xSpriteCanvas;
9832 }
9833 
9834 void Window::ImplPaintToDevice( OutputDevice* i_pTargetOutDev, const Point& i_rPos )
9835 {
9836     sal_Bool bRVisible = mpWindowImpl->mbReallyVisible;
9837     mpWindowImpl->mbReallyVisible = mpWindowImpl->mbVisible;
9838     sal_Bool bDevOutput = mbDevOutput;
9839     mbDevOutput = sal_True;
9840 
9841     long nOldDPIX = ImplGetDPIX();
9842     long nOldDPIY = ImplGetDPIY();
9843     mnDPIX = i_pTargetOutDev->ImplGetDPIX();
9844     mnDPIY = i_pTargetOutDev->ImplGetDPIY();
9845     sal_Bool bOutput = IsOutputEnabled();
9846     EnableOutput();
9847 
9848     DBG_ASSERT( GetMapMode().GetMapUnit() == MAP_PIXEL, "MapMode must be PIXEL based" );
9849     if ( GetMapMode().GetMapUnit() != MAP_PIXEL )
9850         return;
9851 
9852     // preserve graphicsstate
9853     Push();
9854     Region aClipRegion( GetClipRegion() );
9855     SetClipRegion();
9856 
9857     GDIMetaFile* pOldMtf = GetConnectMetaFile();
9858     GDIMetaFile aMtf;
9859     SetConnectMetaFile( &aMtf );
9860 
9861     // put a push action to metafile
9862     Push();
9863     // copy graphics state to metafile
9864     Font aCopyFont = GetFont();
9865     if( nOldDPIX != mnDPIX || nOldDPIY != mnDPIY )
9866     {
9867         aCopyFont.SetHeight( aCopyFont.GetHeight() * mnDPIY / nOldDPIY );
9868         aCopyFont.SetWidth( aCopyFont.GetWidth() * mnDPIX / nOldDPIX );
9869     }
9870     SetFont( aCopyFont );
9871     SetTextColor( GetTextColor() );
9872     if( IsLineColor() )
9873         SetLineColor( GetLineColor() );
9874     else
9875         SetLineColor();
9876     if( IsFillColor() )
9877         SetFillColor( GetFillColor() );
9878     else
9879         SetFillColor();
9880     if( IsTextLineColor() )
9881         SetTextLineColor( GetTextLineColor() );
9882     else
9883         SetTextLineColor();
9884     if( IsOverlineColor() )
9885         SetOverlineColor( GetOverlineColor() );
9886     else
9887         SetOverlineColor();
9888     if( IsTextFillColor() )
9889         SetTextFillColor( GetTextFillColor() );
9890     else
9891         SetTextFillColor();
9892     SetTextAlign( GetTextAlign() );
9893     SetRasterOp( GetRasterOp() );
9894     if( IsRefPoint() )
9895         SetRefPoint( GetRefPoint() );
9896     else
9897         SetRefPoint();
9898     SetLayoutMode( GetLayoutMode() );
9899     SetDigitLanguage( GetDigitLanguage() );
9900     Rectangle aPaintRect( Point( 0, 0 ), GetOutputSizePixel() );
9901     aClipRegion.Intersect( aPaintRect );
9902     SetClipRegion( aClipRegion );
9903 
9904     // do the actual paint
9905 
9906     // background
9907     if( ! IsPaintTransparent() && IsBackground() && ! (GetParentClipMode() & PARENTCLIPMODE_NOCLIP ) )
9908         Erase();
9909     // foreground
9910     Paint( aPaintRect );
9911     // put a pop action to metafile
9912     Pop();
9913 
9914     SetConnectMetaFile( pOldMtf );
9915     EnableOutput( bOutput );
9916     mpWindowImpl->mbReallyVisible = bRVisible;
9917 
9918     // paint metafile to VDev
9919     VirtualDevice* pMaskedDevice = new VirtualDevice( *i_pTargetOutDev, 0, 0 );
9920     pMaskedDevice->SetOutputSizePixel( GetOutputSizePixel() );
9921     pMaskedDevice->EnableRTL( IsRTLEnabled() );
9922     aMtf.WindStart();
9923     aMtf.Play( pMaskedDevice );
9924     BitmapEx aBmpEx( pMaskedDevice->GetBitmapEx( Point( 0, 0 ), pMaskedDevice->GetOutputSizePixel() ) );
9925     i_pTargetOutDev->DrawBitmapEx( i_rPos, aBmpEx );
9926     // get rid of virtual device now so they don't pile up during recursive calls
9927     delete pMaskedDevice, pMaskedDevice = NULL;
9928 
9929 
9930     for( Window* pChild = mpWindowImpl->mpFirstChild; pChild; pChild = pChild->mpWindowImpl->mpNext )
9931     {
9932         if( pChild->mpWindowImpl->mpFrame == mpWindowImpl->mpFrame && pChild->IsVisible() )
9933         {
9934             long nDeltaX = pChild->mnOutOffX - mnOutOffX;
9935             if( ImplHasMirroredGraphics() )
9936                 nDeltaX = mnOutWidth - nDeltaX - pChild->mnOutWidth;
9937             long nDeltaY = pChild->GetOutOffYPixel() - GetOutOffYPixel();
9938             Point aPos( i_rPos );
9939             Point aDelta( nDeltaX, nDeltaY );
9940             aPos += aDelta;
9941             pChild->ImplPaintToDevice( i_pTargetOutDev, aPos );
9942         }
9943     }
9944 
9945     // restore graphics state
9946     Pop();
9947 
9948     EnableOutput( bOutput );
9949     mpWindowImpl->mbReallyVisible = bRVisible;
9950     mbDevOutput = bDevOutput;
9951     mnDPIX = nOldDPIX;
9952     mnDPIY = nOldDPIY;
9953 }
9954 
9955 void Window::PaintToDevice( OutputDevice* pDev, const Point& rPos, const Size& /*rSize*/ )
9956 {
9957     // FIXME: scaling: currently this is for pixel copying only
9958 
9959     DBG_ASSERT( ! pDev->ImplHasMirroredGraphics(), "PaintToDevice to mirroring graphics" );
9960     DBG_ASSERT( ! pDev->IsRTLEnabled(), "PaintToDevice to mirroring device" );
9961 
9962 
9963     Point       aPos  = pDev->LogicToPixel( rPos );
9964 
9965     Window* pRealParent = NULL;
9966     if( ! mpWindowImpl->mbVisible )
9967     {
9968         Window* pTempParent = ImplGetDefaultWindow();
9969         if( pTempParent )
9970             pTempParent->EnableChildTransparentMode();
9971         pRealParent = GetParent();
9972         SetParent( pTempParent );
9973         // trigger correct visibility flags for children
9974         Show();
9975         Hide();
9976     }
9977 
9978     sal_Bool bVisible = mpWindowImpl->mbVisible;
9979     mpWindowImpl->mbVisible = sal_True;
9980 
9981     if( mpWindowImpl->mpBorderWindow )
9982         mpWindowImpl->mpBorderWindow->ImplPaintToDevice( pDev, rPos );
9983     else
9984         ImplPaintToDevice( pDev, rPos );
9985 
9986     mpWindowImpl->mbVisible = bVisible;
9987 
9988     if( pRealParent )
9989         SetParent( pRealParent );
9990 }
9991 
9992 XubString Window::GetSurroundingText() const
9993 {
9994   return XubString::EmptyString();
9995 }
9996 
9997 Selection Window::GetSurroundingTextSelection() const
9998 {
9999   return Selection( 0, 0 );
10000 }
10001 
10002