xref: /trunk/main/toolkit/source/awt/vclxwindow.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_toolkit.hxx"
30 
31 #include <com/sun/star/awt/WindowEvent.hpp>
32 #include <com/sun/star/awt/KeyEvent.hpp>
33 #include <com/sun/star/awt/KeyModifier.hpp>
34 #include <com/sun/star/awt/MouseEvent.hpp>
35 #include <com/sun/star/awt/MouseButton.hpp>
36 #include <com/sun/star/awt/MouseWheelBehavior.hpp>
37 #include <com/sun/star/awt/XTopWindow.hpp>
38 #include <com/sun/star/awt/Style.hpp>
39 #include <com/sun/star/accessibility/AccessibleRole.hpp>
40 #include <com/sun/star/awt/DockingEvent.hpp>
41 #include <com/sun/star/awt/EndDockingEvent.hpp>
42 #include <com/sun/star/awt/EndPopupModeEvent.hpp>
43 #include <com/sun/star/awt/XWindowListener2.hpp>
44 #include <com/sun/star/style/VerticalAlignment.hpp>
45 #include <com/sun/star/lang/DisposedException.hpp>
46 #include <com/sun/star/text/WritingMode2.hpp>
47 #include <toolkit/awt/vclxwindow.hxx>
48 #include <toolkit/awt/vclxpointer.hxx>
49 #include <toolkit/awt/vclxwindows.hxx>
50 #include <toolkit/helper/macros.hxx>
51 #include <toolkit/helper/vclunohelper.hxx>
52 #include <toolkit/helper/convert.hxx>
53 #include <toolkit/helper/macros.hxx>
54 #include <toolkit/helper/property.hxx>
55 #include <toolkit/helper/accessibilityclient.hxx>
56 #include <cppuhelper/typeprovider.hxx>
57 #include <rtl/memory.h>
58 #include <rtl/uuid.h>
59 #include <rtl/ustrbuf.hxx>
60 #include <vcl/svapp.hxx>
61 #include <vcl/window.hxx>
62 #include <tools/color.hxx>
63 #include <vcl/dockwin.hxx>
64 #include <vcl/pdfextoutdevdata.hxx>
65 #include <vcl/tabpage.hxx>
66 #include <vcl/button.hxx>
67 #include <comphelper/asyncnotification.hxx>
68 #include <comphelper/flagguard.hxx>
69 #include <toolkit/helper/solarrelease.hxx>
70 #include "stylesettings.hxx"
71 #include <tools/urlobj.hxx>
72 #include <toolkit/helper/unopropertyarrayhelper.hxx>
73 
74 #include <boost/bind.hpp>
75 
76 using namespace ::com::sun::star;
77 
78 using ::com::sun::star::uno::Reference;
79 using ::com::sun::star::uno::UNO_QUERY;
80 using ::com::sun::star::uno::RuntimeException;
81 using ::com::sun::star::lang::EventObject;
82 using ::com::sun::star::awt::XWindowListener2;
83 using ::com::sun::star::awt::XDockableWindowListener;
84 using ::com::sun::star::awt::XDevice;
85 using ::com::sun::star::awt::XStyleSettings;
86 using ::com::sun::star::lang::DisposedException;
87 using ::com::sun::star::style::VerticalAlignment;
88 using ::com::sun::star::style::VerticalAlignment_TOP;
89 using ::com::sun::star::style::VerticalAlignment_MIDDLE;
90 using ::com::sun::star::style::VerticalAlignment_BOTTOM;
91 using ::com::sun::star::style::VerticalAlignment_MAKE_FIXED_SIZE;
92 
93 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
94 namespace MouseWheelBehavior = ::com::sun::star::awt::MouseWheelBehavior;
95 
96 using ::toolkit::ReleaseSolarMutex;
97 
98 //====================================================================
99 //= VCLXWindowImpl
100 //====================================================================
101 class SAL_DLLPRIVATE VCLXWindowImpl
102 {
103 private:
104     typedef ::std::vector< VCLXWindow::Callback >                       CallbackArray;
105 
106 private:
107     VCLXWindow&                         mrAntiImpl;
108     ::vos::IMutex&                      mrMutex;
109     ::toolkit::AccessibilityClient      maAccFactory;
110     bool                                mbDisposed;
111     bool                                mbDrawingOntoParent;    // no bit mask, is passed around  by reference
112     sal_Bool                            mbEnableVisible;
113     sal_Bool                            mbDirectVisible;
114 
115     ::osl::Mutex                        maListenerContainerMutex;
116     ::cppu::OInterfaceContainerHelper   maWindow2Listeners;
117     ::cppu::OInterfaceContainerHelper   maDockableWindowListeners;
118     EventListenerMultiplexer            maEventListeners;
119     FocusListenerMultiplexer            maFocusListeners;
120     WindowListenerMultiplexer           maWindowListeners;
121     KeyListenerMultiplexer              maKeyListeners;
122     MouseListenerMultiplexer            maMouseListeners;
123     MouseMotionListenerMultiplexer      maMouseMotionListeners;
124     PaintListenerMultiplexer            maPaintListeners;
125     VclContainerListenerMultiplexer     maContainerListeners;
126     TopWindowListenerMultiplexer        maTopWindowListeners;
127 
128     CallbackArray                       maCallbackEvents;
129     sal_uLong                               mnCallbackEventId;
130 
131 public:
132     bool                                mbDisposing             : 1;
133     bool                                mbDesignMode            : 1;
134     bool                                mbSynthesizingVCLEvent  : 1;
135     bool                                mbWithDefaultProps      : 1;
136 
137     sal_uLong                               mnListenerLockLevel;
138     sal_Int16                           mnWritingMode;
139     sal_Int16                           mnContextWritingMode;
140 
141     UnoPropertyArrayHelper*             mpPropHelper;
142 
143     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer >
144                                         mxPointer;
145     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
146                                         mxAccessibleContext;
147     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >
148                                         mxViewGraphics;
149     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XStyleSettings >
150                                         mxWindowStyleSettings;
151 
152 public:
153     bool&   getDrawingOntoParent_ref()  { return mbDrawingOntoParent; }
154 
155 public:
156     /** ctor
157     @param _pAntiImpl
158         the <type>VCLXWindow</type> instance which the object belongs to. Must
159         live longer then the object just being constructed.
160     */
161     VCLXWindowImpl( VCLXWindow& _rAntiImpl, ::vos::IMutex& _rMutex, bool _bWithDefaultProps );
162 
163     /** synchronously mbEnableVisible
164     */
165     void    setEnableVisible( sal_Bool bEnableVisible ) { mbEnableVisible = bEnableVisible; }
166     sal_Bool    isEnableVisible() { return mbEnableVisible; }
167     /** synchronously mbDirectVisible;
168     */
169     void    setDirectVisible( sal_Bool bDirectVisible ) { mbDirectVisible = bDirectVisible; }
170     sal_Bool    isDirectVisible() { return mbDirectVisible; }
171 
172     /** impl-version of VCLXWindow::ImplExecuteAsyncWithoutSolarLock
173     */
174     void    callBackAsync( const VCLXWindow::Callback& i_callback );
175 
176     /** notifies the object that its VCLXWindow is being disposed
177     */
178     void    disposing();
179 
180     inline ::toolkit::AccessibilityClient& getAccessibleFactory()
181     {
182         return maAccFactory;
183     }
184 
185     Reference< XStyleSettings > getStyleSettings();
186 
187     /** returns the container of registered XWindowListener2 listeners
188     */
189     inline ::cppu::OInterfaceContainerHelper&   getWindow2Listeners()       { return maWindow2Listeners; }
190     inline ::cppu::OInterfaceContainerHelper&   getDockableWindowListeners(){ return maDockableWindowListeners; }
191     inline EventListenerMultiplexer&            getEventListeners()         { return maEventListeners; }
192     inline FocusListenerMultiplexer&            getFocusListeners()         { return maFocusListeners; }
193     inline WindowListenerMultiplexer&           getWindowListeners()        { return maWindowListeners; }
194     inline KeyListenerMultiplexer&              getKeyListeners()           { return maKeyListeners; }
195     inline MouseListenerMultiplexer&            getMouseListeners()         { return maMouseListeners; }
196     inline MouseMotionListenerMultiplexer&      getMouseMotionListeners()   { return maMouseMotionListeners; }
197     inline PaintListenerMultiplexer&            getPaintListeners()         { return maPaintListeners; }
198     inline VclContainerListenerMultiplexer&     getContainerListeners()     { return maContainerListeners; }
199     inline TopWindowListenerMultiplexer&        getTopWindowListeners()     { return maTopWindowListeners; }
200 
201     virtual ~VCLXWindowImpl();
202 
203 protected:
204     virtual void SAL_CALL acquire();
205     virtual void SAL_CALL release();
206 
207 private:
208     DECL_LINK( OnProcessCallbacks, void* );
209 
210 private:
211     VCLXWindowImpl();                                   // never implemented
212     VCLXWindowImpl( const VCLXWindowImpl& );            // never implemented
213     VCLXWindowImpl& operator=( const VCLXWindowImpl& ); // never implemented
214 };
215 
216 //--------------------------------------------------------------------
217 VCLXWindowImpl::VCLXWindowImpl( VCLXWindow& _rAntiImpl, ::vos::IMutex& _rMutex, bool _bWithDefaultProps )
218     :mrAntiImpl( _rAntiImpl )
219     ,mrMutex( _rMutex )
220     ,mbDisposed( false )
221     ,mbDrawingOntoParent( false )
222     ,mbEnableVisible(sal_True)
223     ,mbDirectVisible(sal_True)
224     ,maListenerContainerMutex( )
225     ,maWindow2Listeners( maListenerContainerMutex )
226     ,maDockableWindowListeners( maListenerContainerMutex )
227     ,maEventListeners( _rAntiImpl )
228     ,maFocusListeners( _rAntiImpl )
229     ,maWindowListeners( _rAntiImpl )
230     ,maKeyListeners( _rAntiImpl )
231     ,maMouseListeners( _rAntiImpl )
232     ,maMouseMotionListeners( _rAntiImpl )
233     ,maPaintListeners( _rAntiImpl )
234     ,maContainerListeners( _rAntiImpl )
235     ,maTopWindowListeners( _rAntiImpl )
236     ,mnCallbackEventId( 0 )
237     ,mbDisposing( false )
238     ,mbDesignMode( false )
239     ,mbSynthesizingVCLEvent( false )
240     ,mbWithDefaultProps( _bWithDefaultProps )
241     ,mnListenerLockLevel( 0 )
242     ,mnWritingMode( WritingMode2::CONTEXT )
243     ,mnContextWritingMode( WritingMode2::CONTEXT )
244     ,mpPropHelper( NULL )
245 {
246 }
247 
248 VCLXWindowImpl::~VCLXWindowImpl()
249 {
250     delete mpPropHelper;
251 }
252 
253 //--------------------------------------------------------------------
254 void VCLXWindowImpl::disposing()
255 {
256     ::vos::OGuard aGuard( mrMutex );
257     if ( mnCallbackEventId )
258         Application::RemoveUserEvent( mnCallbackEventId );
259     mnCallbackEventId = 0;
260 
261     mbDisposed= true;
262 
263     ::com::sun::star::lang::EventObject aEvent;
264     aEvent.Source = mrAntiImpl;
265 
266     maEventListeners.disposeAndClear( aEvent );
267     maFocusListeners.disposeAndClear( aEvent );
268     maWindowListeners.disposeAndClear( aEvent );
269     maKeyListeners.disposeAndClear( aEvent );
270     maMouseListeners.disposeAndClear( aEvent );
271     maMouseMotionListeners.disposeAndClear( aEvent );
272     maPaintListeners.disposeAndClear( aEvent );
273     maContainerListeners.disposeAndClear( aEvent );
274     maTopWindowListeners.disposeAndClear( aEvent );
275 
276     ::toolkit::WindowStyleSettings* pStyleSettings = static_cast< ::toolkit::WindowStyleSettings* >( mxWindowStyleSettings.get() );
277     if ( pStyleSettings != NULL )
278         pStyleSettings->dispose();
279     mxWindowStyleSettings.clear();
280 }
281 
282 //--------------------------------------------------------------------
283 void VCLXWindowImpl::callBackAsync( const VCLXWindow::Callback& i_callback )
284 {
285     DBG_TESTSOLARMUTEX();
286     maCallbackEvents.push_back( i_callback );
287     if ( !mnCallbackEventId )
288     {
289         // ensure our VCLXWindow is not destroyed while the event is underway
290         mrAntiImpl.acquire();
291         mnCallbackEventId = Application::PostUserEvent( LINK( this, VCLXWindowImpl, OnProcessCallbacks ) );
292     }
293 }
294 
295 //----------------------------------------------------------------------------------------------------------------------
296 IMPL_LINK( VCLXWindowImpl, OnProcessCallbacks, void*, EMPTYARG )
297 {
298     const Reference< uno::XInterface > xKeepAlive( mrAntiImpl );
299 
300     // work on a copy of the callback array
301     CallbackArray aCallbacksCopy;
302     {
303         ::vos::OGuard aGuard( mrMutex );
304         aCallbacksCopy = maCallbackEvents;
305         maCallbackEvents.clear();
306 
307         // we acquired our VCLXWindow once before posting the event, release this one ref now
308         mrAntiImpl.release();
309 
310         if ( !mnCallbackEventId )
311             // we were disposed while waiting for the mutex to lock
312             return 1L;
313 
314         mnCallbackEventId = 0;
315     }
316 
317     {
318         ReleaseSolarMutex aReleaseSolar( ReleaseSolarMutex::RescheduleDuringAcquire );
319         for (   CallbackArray::const_iterator loop = aCallbacksCopy.begin();
320                 loop != aCallbacksCopy.end();
321                 ++loop
322             )
323         {
324             (*loop)();
325         }
326     }
327 
328     return 0L;
329 }
330 
331 //--------------------------------------------------------------------
332 void SAL_CALL VCLXWindowImpl::acquire()
333 {
334     mrAntiImpl.acquire();
335 }
336 
337 //--------------------------------------------------------------------
338 void SAL_CALL VCLXWindowImpl::release()
339 {
340     mrAntiImpl.release();
341 }
342 
343 //--------------------------------------------------------------------
344 Reference< XStyleSettings > VCLXWindowImpl::getStyleSettings()
345 {
346     ::vos::OGuard  aGuard( mrMutex );
347     if ( mbDisposed )
348         throw DisposedException( ::rtl::OUString(), mrAntiImpl );
349     if ( !mxWindowStyleSettings.is() )
350         mxWindowStyleSettings = new ::toolkit::WindowStyleSettings( mrMutex, maListenerContainerMutex, mrAntiImpl );
351     return mxWindowStyleSettings;
352 }
353 
354 //====================================================================
355 //====================================================================
356 
357 // Mit Out-Parameter besser als Rueckgabewert, wegen Ref-Objekt...
358 
359 void ImplInitWindowEvent( ::com::sun::star::awt::WindowEvent& rEvent, Window* pWindow )
360 {
361     Point aPos = pWindow->GetPosPixel();
362     Size aSz = pWindow->GetSizePixel();
363 
364     rEvent.X = aPos.X();
365     rEvent.Y = aPos.Y();
366 
367     rEvent.Width = aSz.Width();
368     rEvent.Height = aSz.Height();
369 
370     pWindow->GetBorder( rEvent.LeftInset, rEvent.TopInset, rEvent.RightInset, rEvent.BottomInset );
371 }
372 
373 //  ----------------------------------------------------
374 //  class VCLXWindow
375 //  ----------------------------------------------------
376 
377 DBG_NAME(VCLXWindow);
378 
379 VCLXWindow::VCLXWindow( bool _bWithDefaultProps )
380     :mpImpl( NULL )
381 {
382     DBG_CTOR( VCLXWindow, 0 );
383 
384     mpImpl = new VCLXWindowImpl( *this, GetMutex(), _bWithDefaultProps );
385 }
386 
387 VCLXWindow::~VCLXWindow()
388 {
389     DBG_DTOR( VCLXWindow, 0 );
390 
391     delete mpImpl;
392 
393     if ( GetWindow() )
394     {
395         GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) );
396         GetWindow()->SetWindowPeer( NULL, NULL );
397         GetWindow()->SetAccessible( NULL );
398     }
399 }
400 
401 //----------------------------------------------------------------------------------------------------------------------
402 void VCLXWindow::ImplExecuteAsyncWithoutSolarLock( const Callback& i_callback )
403 {
404     mpImpl->callBackAsync( i_callback );
405 }
406 
407 //----------------------------------------------------------------------------------------------------------------------
408 ::toolkit::IAccessibleFactory& VCLXWindow::getAccessibleFactory()
409 {
410     return mpImpl->getAccessibleFactory().getFactory();
411 }
412 
413 void VCLXWindow::SetWindow( Window* pWindow )
414 {
415     if ( GetWindow() )
416     {
417         GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) );
418 //        GetWindow()->DbgAssertNoEventListeners();
419     }
420 
421     SetOutputDevice( pWindow );
422 
423     if ( GetWindow() )
424     {
425         GetWindow()->AddEventListener( LINK( this, VCLXWindow, WindowEventListener ) );
426         sal_Bool bDirectVisible = pWindow ? pWindow->IsVisible() : false;
427         mpImpl->setDirectVisible( bDirectVisible );
428     }
429 
430 }
431 
432 void VCLXWindow::suspendVclEventListening( )
433 {
434     ++mpImpl->mnListenerLockLevel;
435 }
436 
437 void VCLXWindow::resumeVclEventListening( )
438 {
439     DBG_ASSERT( mpImpl->mnListenerLockLevel, "VCLXWindow::resumeVclEventListening: not suspended!" );
440     --mpImpl->mnListenerLockLevel;
441 }
442 
443 void VCLXWindow::notifyWindowRemoved( Window& _rWindow )
444 {
445     if ( mpImpl->getContainerListeners().getLength() )
446     {
447         awt::VclContainerEvent aEvent;
448         aEvent.Source = *this;
449         aEvent.Child = static_cast< XWindow* >( _rWindow.GetWindowPeer() );
450         mpImpl->getContainerListeners().windowRemoved( aEvent );
451     }
452 }
453 
454 IMPL_LINK( VCLXWindow, WindowEventListener, VclSimpleEvent*, pEvent )
455 {
456     if ( mpImpl->mnListenerLockLevel )
457         return 0L;
458 
459     DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
460     if ( pEvent && pEvent->ISA( VclWindowEvent ) )
461     {
462         DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow() && GetWindow(), "Window???" );
463         ProcessWindowEvent( *(VclWindowEvent*)pEvent );
464     }
465     return 0;
466 }
467 
468 namespace
469 {
470     struct CallWindow2Listener
471     {
472         CallWindow2Listener( ::cppu::OInterfaceContainerHelper& i_rWindow2Listeners, const bool i_bEnabled, const EventObject& i_rEvent )
473             :m_rWindow2Listeners( i_rWindow2Listeners )
474             ,m_bEnabled( i_bEnabled )
475             ,m_aEvent( i_rEvent )
476         {
477         }
478 
479         void operator()()
480         {
481             m_rWindow2Listeners.notifyEach( m_bEnabled ? &XWindowListener2::windowEnabled : &XWindowListener2::windowDisabled, m_aEvent );
482         }
483 
484         ::cppu::OInterfaceContainerHelper&  m_rWindow2Listeners;
485         const bool                          m_bEnabled;
486         const EventObject                   m_aEvent;
487     };
488 }
489 
490 void VCLXWindow::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
491 {
492     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xThis( (::cppu::OWeakObject*)this );
493 
494     switch ( rVclWindowEvent.GetId() )
495     {
496         case VCLEVENT_WINDOW_ENABLED:
497         case VCLEVENT_WINDOW_DISABLED:
498         {
499             Callback aCallback = CallWindow2Listener(
500                 mpImpl->getWindow2Listeners(),
501                 ( VCLEVENT_WINDOW_ENABLED == rVclWindowEvent.GetId() ),
502                 EventObject( *this )
503             );
504             ImplExecuteAsyncWithoutSolarLock( aCallback );
505         }
506         break;
507 
508         case VCLEVENT_WINDOW_PAINT:
509         {
510             if ( mpImpl->getPaintListeners().getLength() )
511             {
512                 ::com::sun::star::awt::PaintEvent aEvent;
513                 aEvent.Source = (::cppu::OWeakObject*)this;
514                 aEvent.UpdateRect = AWTRectangle( *(Rectangle*)rVclWindowEvent.GetData() );
515                 aEvent.Count = 0;
516                 mpImpl->getPaintListeners().windowPaint( aEvent );
517             }
518         }
519         break;
520         case VCLEVENT_WINDOW_MOVE:
521         {
522             if ( mpImpl->getWindowListeners().getLength() )
523             {
524                 ::com::sun::star::awt::WindowEvent aEvent;
525                 aEvent.Source = (::cppu::OWeakObject*)this;
526                 ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() );
527                 mpImpl->getWindowListeners().windowMoved( aEvent );
528             }
529         }
530         break;
531         case VCLEVENT_WINDOW_RESIZE:
532         {
533             if ( mpImpl->getWindowListeners().getLength() )
534             {
535                 ::com::sun::star::awt::WindowEvent aEvent;
536                 aEvent.Source = (::cppu::OWeakObject*)this;
537                 ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() );
538                 mpImpl->getWindowListeners().windowResized( aEvent );
539             }
540         }
541         break;
542         case VCLEVENT_WINDOW_SHOW:
543         {
544             if ( mpImpl->getWindowListeners().getLength() )
545             {
546                 ::com::sun::star::awt::WindowEvent aEvent;
547                 aEvent.Source = (::cppu::OWeakObject*)this;
548                 ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() );
549                 mpImpl->getWindowListeners().windowShown( aEvent );
550             }
551 
552             // For TopWindows this means opened...
553             if ( mpImpl->getTopWindowListeners().getLength() )
554             {
555                 ::com::sun::star::lang::EventObject aEvent;
556                 aEvent.Source = (::cppu::OWeakObject*)this;
557                 mpImpl->getTopWindowListeners().windowOpened( aEvent );
558             }
559         }
560         break;
561         case VCLEVENT_WINDOW_HIDE:
562         {
563             if ( mpImpl->getWindowListeners().getLength() )
564             {
565                 ::com::sun::star::awt::WindowEvent aEvent;
566                 aEvent.Source = (::cppu::OWeakObject*)this;
567                 ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() );
568                 mpImpl->getWindowListeners().windowHidden( aEvent );
569             }
570 
571             // For TopWindows this means closed...
572             if ( mpImpl->getTopWindowListeners().getLength() )
573             {
574                 ::com::sun::star::lang::EventObject aEvent;
575                 aEvent.Source = (::cppu::OWeakObject*)this;
576                 mpImpl->getTopWindowListeners().windowClosed( aEvent );
577             }
578         }
579         break;
580         case VCLEVENT_WINDOW_ACTIVATE:
581         {
582             if ( mpImpl->getTopWindowListeners().getLength() )
583             {
584                 ::com::sun::star::lang::EventObject aEvent;
585                 aEvent.Source = (::cppu::OWeakObject*)this;
586                 mpImpl->getTopWindowListeners().windowActivated( aEvent );
587             }
588         }
589         break;
590         case VCLEVENT_WINDOW_DEACTIVATE:
591         {
592             if ( mpImpl->getTopWindowListeners().getLength() )
593             {
594                 ::com::sun::star::lang::EventObject aEvent;
595                 aEvent.Source = (::cppu::OWeakObject*)this;
596                 mpImpl->getTopWindowListeners().windowDeactivated( aEvent );
597             }
598         }
599         break;
600         case VCLEVENT_WINDOW_CLOSE:
601         {
602             if ( mpImpl->getDockableWindowListeners().getLength() )
603             {
604                 ::com::sun::star::lang::EventObject aEvent;
605                 aEvent.Source = (::cppu::OWeakObject*)this;
606                 mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::closed, aEvent );
607             }
608             if ( mpImpl->getTopWindowListeners().getLength() )
609             {
610                 ::com::sun::star::lang::EventObject aEvent;
611                 aEvent.Source = (::cppu::OWeakObject*)this;
612                 mpImpl->getTopWindowListeners().windowClosing( aEvent );
613             }
614         }
615         break;
616         case VCLEVENT_CONTROL_GETFOCUS:
617         case VCLEVENT_WINDOW_GETFOCUS:
618         {
619             if  (   (   rVclWindowEvent.GetWindow()->IsCompoundControl()
620                     &&  rVclWindowEvent.GetId() == VCLEVENT_CONTROL_GETFOCUS
621                     )
622                 ||  (   !rVclWindowEvent.GetWindow()->IsCompoundControl()
623                     &&  rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS
624                     )
625                 )
626             {
627                 if ( mpImpl->getFocusListeners().getLength() )
628                 {
629                     ::com::sun::star::awt::FocusEvent aEvent;
630                     aEvent.Source = (::cppu::OWeakObject*)this;
631                     aEvent.FocusFlags = rVclWindowEvent.GetWindow()->GetGetFocusFlags();
632                     aEvent.Temporary = sal_False;
633                     mpImpl->getFocusListeners().focusGained( aEvent );
634                 }
635             }
636         }
637         break;
638         case VCLEVENT_CONTROL_LOSEFOCUS:
639         case VCLEVENT_WINDOW_LOSEFOCUS:
640         {
641             if  (   (   rVclWindowEvent.GetWindow()->IsCompoundControl()
642                     &&  rVclWindowEvent.GetId() == VCLEVENT_CONTROL_LOSEFOCUS
643                     )
644                 ||  (   !rVclWindowEvent.GetWindow()->IsCompoundControl()
645                     &&  rVclWindowEvent.GetId() == VCLEVENT_WINDOW_LOSEFOCUS
646                     )
647                 )
648             {
649                 if ( mpImpl->getFocusListeners().getLength() )
650                 {
651                     ::com::sun::star::awt::FocusEvent aEvent;
652                     aEvent.Source = (::cppu::OWeakObject*)this;
653                     aEvent.FocusFlags = rVclWindowEvent.GetWindow()->GetGetFocusFlags();
654                     aEvent.Temporary = sal_False;
655 
656                     Window* pNext = Application::GetFocusWindow();
657                     if ( pNext )
658                     {
659                         // Bei zusammengesetzten Controls interessiert sich keiner fuer das Innenleben:
660                         Window* pNextC = pNext;
661                         while ( pNextC && !pNextC->IsCompoundControl() )
662                             pNextC = pNextC->GetParent();
663                         if ( pNextC )
664                             pNext = pNextC;
665 
666                         pNext->GetComponentInterface( sal_True );
667                         aEvent.NextFocus = (::cppu::OWeakObject*)pNext->GetWindowPeer();
668                     }
669                     mpImpl->getFocusListeners().focusLost( aEvent );
670                 }
671             }
672         }
673         break;
674         case VCLEVENT_WINDOW_MINIMIZE:
675         {
676             if ( mpImpl->getTopWindowListeners().getLength() )
677             {
678                 ::com::sun::star::lang::EventObject aEvent;
679                 aEvent.Source = (::cppu::OWeakObject*)this;
680                 mpImpl->getTopWindowListeners().windowMinimized( aEvent );
681             }
682         }
683         break;
684         case VCLEVENT_WINDOW_NORMALIZE:
685         {
686             if ( mpImpl->getTopWindowListeners().getLength() )
687             {
688                 ::com::sun::star::lang::EventObject aEvent;
689                 aEvent.Source = (::cppu::OWeakObject*)this;
690                 mpImpl->getTopWindowListeners().windowNormalized( aEvent );
691             }
692         }
693         break;
694         case VCLEVENT_WINDOW_KEYINPUT:
695         {
696             if ( mpImpl->getKeyListeners().getLength() )
697             {
698                 ::com::sun::star::awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent(
699                     *(KeyEvent*)rVclWindowEvent.GetData(), *this
700                 ) );
701                 mpImpl->getKeyListeners().keyPressed( aEvent );
702             }
703         }
704         break;
705         case VCLEVENT_WINDOW_KEYUP:
706         {
707             if ( mpImpl->getKeyListeners().getLength() )
708             {
709                 ::com::sun::star::awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent(
710                     *(KeyEvent*)rVclWindowEvent.GetData(), *this
711                 ) );
712                 mpImpl->getKeyListeners().keyReleased( aEvent );
713             }
714         }
715         break;
716         case VCLEVENT_WINDOW_COMMAND:
717         {
718             CommandEvent* pCmdEvt = (CommandEvent*)rVclWindowEvent.GetData();
719             if ( mpImpl->getMouseListeners().getLength() && ( pCmdEvt->GetCommand() == COMMAND_CONTEXTMENU ) )
720             {
721                 // COMMAND_CONTEXTMENU als mousePressed mit PopupTrigger = sal_True versenden...
722                 Point aWhere = static_cast< CommandEvent* >( rVclWindowEvent.GetData() )->GetMousePosPixel();
723                 if ( !pCmdEvt->IsMouseEvent() )
724                 {   // for keyboard events, we set the coordinates to -1,-1. This is a slight HACK, but the current API
725                     // handles a context menu command as special case of a mouse event, which is simply wrong.
726                     // Without extending the API, we would not have another chance to notify listeners of a
727                     // keyboard-triggered context menu request
728                     // 102205 - 16.08.2002 - fs@openoffice.org
729                     aWhere = Point( -1, -1 );
730                 }
731 
732                 MouseEvent aMEvt( aWhere, 1, MOUSE_SIMPLECLICK, MOUSE_LEFT, 0 );
733                 awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( aMEvt, *this ) );
734                 aEvent.PopupTrigger = sal_True;
735 
736                 Callback aCallback = ::boost::bind(
737                     &MouseListenerMultiplexer::mousePressed,
738                     &mpImpl->getMouseListeners(),
739                     aEvent
740                 );
741                 ImplExecuteAsyncWithoutSolarLock( aCallback );
742             }
743         }
744         break;
745         case VCLEVENT_WINDOW_MOUSEMOVE:
746         {
747             MouseEvent* pMouseEvt = (MouseEvent*)rVclWindowEvent.GetData();
748             if ( mpImpl->getMouseListeners().getLength() && ( pMouseEvt->IsEnterWindow() || pMouseEvt->IsLeaveWindow() ) )
749             {
750                 awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *pMouseEvt, *this ) );
751 
752                 Callback aCallback = ::boost::bind(
753                     pMouseEvt->IsEnterWindow() ? &MouseListenerMultiplexer::mouseEntered : &MouseListenerMultiplexer::mouseExited,
754                     &mpImpl->getMouseListeners(),
755                     aEvent
756                 );
757                 ImplExecuteAsyncWithoutSolarLock( aCallback );
758             }
759 
760             if ( mpImpl->getMouseMotionListeners().getLength() && !pMouseEvt->IsEnterWindow() && !pMouseEvt->IsLeaveWindow() )
761             {
762                 awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *pMouseEvt, *this ) );
763                 aEvent.ClickCount = 0;  // #92138#
764                 if ( pMouseEvt->GetMode() & MOUSE_SIMPLEMOVE )
765                     mpImpl->getMouseMotionListeners().mouseMoved( aEvent );
766                 else
767                     mpImpl->getMouseMotionListeners().mouseDragged( aEvent );
768             }
769         }
770         break;
771         case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
772         {
773             if ( mpImpl->getMouseListeners().getLength() )
774             {
775                 awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *(MouseEvent*)rVclWindowEvent.GetData(), *this ) );
776                 Callback aCallback = ::boost::bind(
777                     &MouseListenerMultiplexer::mousePressed,
778                     &mpImpl->getMouseListeners(),
779                     aEvent
780                 );
781                 ImplExecuteAsyncWithoutSolarLock( aCallback );
782             }
783         }
784         break;
785         case VCLEVENT_WINDOW_MOUSEBUTTONUP:
786         {
787             if ( mpImpl->getMouseListeners().getLength() )
788             {
789                 awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *(MouseEvent*)rVclWindowEvent.GetData(), *this ) );
790                 Callback aCallback = ::boost::bind(
791                     &MouseListenerMultiplexer::mouseReleased,
792                     &mpImpl->getMouseListeners(),
793                     aEvent
794                 );
795                 ImplExecuteAsyncWithoutSolarLock( aCallback );
796             }
797         }
798         break;
799         case VCLEVENT_WINDOW_STARTDOCKING:
800         {
801             if ( mpImpl->getDockableWindowListeners().getLength() )
802             {
803                 DockingData *pData = (DockingData*)rVclWindowEvent.GetData();
804 
805                 if( pData )
806                 {
807                     ::com::sun::star::awt::DockingEvent aEvent;
808                     aEvent.Source = (::cppu::OWeakObject*)this;
809                     aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect );
810                     aEvent.MousePos.X = pData->maMousePos.X();
811                     aEvent.MousePos.Y = pData->maMousePos.Y();
812                     aEvent.bLiveMode = pData->mbLivemode;
813                     aEvent.bInteractive = pData->mbInteractive;
814 
815                     mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::startDocking, aEvent );
816                 }
817             }
818         }
819         break;
820         case VCLEVENT_WINDOW_DOCKING:
821         {
822             if ( mpImpl->getDockableWindowListeners().getLength() )
823             {
824                 DockingData *pData = (DockingData*)rVclWindowEvent.GetData();
825 
826                 if( pData )
827                 {
828                     ::com::sun::star::awt::DockingEvent aEvent;
829                     aEvent.Source = (::cppu::OWeakObject*)this;
830                     aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect );
831                     aEvent.MousePos.X = pData->maMousePos.X();
832                     aEvent.MousePos.Y = pData->maMousePos.Y();
833                     aEvent.bLiveMode = pData->mbLivemode;
834                     aEvent.bInteractive = pData->mbInteractive;
835 
836                     Reference< XDockableWindowListener > xFirstListener;
837                     ::cppu::OInterfaceIteratorHelper aIter( mpImpl->getDockableWindowListeners() );
838                     while ( aIter.hasMoreElements() && !xFirstListener.is() )
839                     {
840                         xFirstListener.set( aIter.next(), UNO_QUERY );
841                     }
842 
843                     ::com::sun::star::awt::DockingData aDockingData =
844                         xFirstListener->docking( aEvent );
845                     pData->maTrackRect = VCLRectangle( aDockingData.TrackingRectangle );
846                     pData->mbFloating = aDockingData.bFloating;
847                 }
848             }
849         }
850         break;
851         case VCLEVENT_WINDOW_ENDDOCKING:
852         {
853             if ( mpImpl->getDockableWindowListeners().getLength() )
854             {
855                 EndDockingData *pData = (EndDockingData*)rVclWindowEvent.GetData();
856 
857                 if( pData )
858                 {
859                     ::com::sun::star::awt::EndDockingEvent aEvent;
860                     aEvent.Source = (::cppu::OWeakObject*)this;
861                     aEvent.WindowRectangle = AWTRectangle( pData->maWindowRect );
862                     aEvent.bFloating = pData->mbFloating;
863                     aEvent.bCancelled = pData->mbCancelled;
864                     mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endDocking, aEvent );
865                 }
866             }
867         }
868         break;
869         case VCLEVENT_WINDOW_PREPARETOGGLEFLOATING:
870         {
871             if ( mpImpl->getDockableWindowListeners().getLength() )
872             {
873                 sal_Bool *p_bFloating = (sal_Bool*)rVclWindowEvent.GetData();
874 
875                 ::com::sun::star::lang::EventObject aEvent;
876                 aEvent.Source = (::cppu::OWeakObject*)this;
877 
878                 Reference< XDockableWindowListener > xFirstListener;
879                 ::cppu::OInterfaceIteratorHelper aIter( mpImpl->getDockableWindowListeners() );
880                 while ( aIter.hasMoreElements() && !xFirstListener.is() )
881                 {
882                     xFirstListener.set( aIter.next(), UNO_QUERY );
883                 }
884 
885                 *p_bFloating = xFirstListener->prepareToggleFloatingMode( aEvent );
886             }
887         }
888         break;
889         case VCLEVENT_WINDOW_TOGGLEFLOATING:
890         {
891             if ( mpImpl->getDockableWindowListeners().getLength() )
892             {
893                 ::com::sun::star::lang::EventObject aEvent;
894                 aEvent.Source = (::cppu::OWeakObject*)this;
895                 mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::toggleFloatingMode, aEvent );
896             }
897        }
898         break;
899         case VCLEVENT_WINDOW_ENDPOPUPMODE:
900         {
901             if ( mpImpl->getDockableWindowListeners().getLength() )
902             {
903                 EndPopupModeData *pData = (EndPopupModeData*)rVclWindowEvent.GetData();
904 
905                 if( pData )
906                 {
907                     ::com::sun::star::awt::EndPopupModeEvent aEvent;
908                     aEvent.Source = (::cppu::OWeakObject*)this;
909                     aEvent.FloatingPosition.X = pData->maFloatingPos.X();
910                     aEvent.FloatingPosition.Y = pData->maFloatingPos.Y();
911                     aEvent.bTearoff = pData->mbTearoff;
912                     mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endPopupMode, aEvent );
913                 }
914             }
915         }
916         break;
917 
918     }
919 }
920 
921 uno::Reference< accessibility::XAccessibleContext > VCLXWindow::CreateAccessibleContext()
922 {
923     ::vos::OGuard aGuard( GetMutex() );
924     return getAccessibleFactory().createAccessibleContext( this );
925 }
926 
927 void VCLXWindow::SetSynthesizingVCLEvent( sal_Bool _b )
928 {
929     mpImpl->mbSynthesizingVCLEvent = _b;
930 }
931 
932 sal_Bool VCLXWindow::IsSynthesizingVCLEvent() const
933 {
934     return mpImpl->mbSynthesizingVCLEvent;
935 }
936 
937 Size VCLXWindow::ImplCalcWindowSize( const Size& rOutSz ) const
938 {
939     Size aSz = rOutSz;
940 
941     Window* pWindow = GetWindow();
942     if ( pWindow )
943     {
944         sal_Int32 nLeft, nTop, nRight, nBottom;
945         pWindow->GetBorder( nLeft, nTop, nRight, nBottom );
946         aSz.Width() += nLeft+nRight;
947         aSz.Height() += nTop+nBottom;
948     }
949     return aSz;
950 }
951 
952 
953 // ::com::sun::star::lang::XUnoTunnel
954 IMPL_XUNOTUNNEL2( VCLXWindow, VCLXDevice )
955 
956 // ::com::sun::star::lang::Component
957 void VCLXWindow::dispose(  ) throw(::com::sun::star::uno::RuntimeException)
958 {
959     ::vos::OGuard aGuard( GetMutex() );
960 
961     mpImpl->mxViewGraphics = NULL;
962 
963     if ( !mpImpl->mbDisposing )
964     {
965         mpImpl->mbDisposing = true;
966 
967         mpImpl->disposing();
968 
969         if ( GetWindow() )
970         {
971             OutputDevice* pOutDev = GetOutputDevice();
972             SetWindow( NULL );  // Damit ggf. Handler abgemeldet werden (virtuell).
973             SetOutputDevice( pOutDev );
974             DestroyOutputDevice();
975         }
976 
977         // #i14103# dispose the accessible context after the window has been destroyed,
978         // otherwise the old value in the child event fired in VCLXAccessibleComponent::ProcessWindowEvent()
979         // for VCLEVENT_WINDOW_CHILDDESTROYED contains a reference to an already disposed accessible object
980         try
981         {
982             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComponent( mpImpl->mxAccessibleContext, ::com::sun::star::uno::UNO_QUERY );
983             if ( xComponent.is() )
984                 xComponent->dispose();
985         }
986         catch ( const ::com::sun::star::uno::Exception& )
987         {
988             DBG_ERROR( "VCLXWindow::dispose: could not dispose the accessible context!" );
989         }
990         mpImpl->mxAccessibleContext.clear();
991 
992         mpImpl->mbDisposing = false;
993     }
994 }
995 
996 void VCLXWindow::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
997 {
998     ::vos::OGuard aGuard( GetMutex() );
999 
1000     mpImpl->getEventListeners().addInterface( rxListener );
1001 }
1002 
1003 void VCLXWindow::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1004 {
1005     ::vos::OGuard aGuard( GetMutex() );
1006 
1007     mpImpl->getEventListeners().removeInterface( rxListener );
1008 }
1009 
1010 
1011 // ::com::sun::star::awt::XWindow
1012 void VCLXWindow::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw(::com::sun::star::uno::RuntimeException)
1013 {
1014     ::vos::OGuard aGuard( GetMutex() );
1015 
1016     if ( GetWindow() )
1017     {
1018         if( Window::GetDockingManager()->IsDockable( GetWindow() ) )
1019             Window::GetDockingManager()->SetPosSizePixel( GetWindow() , X, Y, Width, Height, Flags );
1020         else
1021             GetWindow()->SetPosSizePixel( X, Y, Width, Height, Flags );
1022     }
1023 }
1024 
1025 ::com::sun::star::awt::Rectangle VCLXWindow::getPosSize(  ) throw(::com::sun::star::uno::RuntimeException)
1026 {
1027     ::vos::OGuard aGuard( GetMutex() );
1028 
1029     ::com::sun::star::awt::Rectangle aBounds;
1030     if ( GetWindow() )
1031     {
1032         if( Window::GetDockingManager()->IsDockable( GetWindow() ) )
1033             aBounds = AWTRectangle( Window::GetDockingManager()->GetPosSizePixel( GetWindow() ) );
1034         else
1035             aBounds = AWTRectangle( Rectangle( GetWindow()->GetPosPixel(), GetWindow()->GetSizePixel() ) );
1036     }
1037 
1038     return aBounds;
1039 }
1040 
1041 void VCLXWindow::setVisible( sal_Bool bVisible ) throw(::com::sun::star::uno::RuntimeException)
1042 {
1043     ::vos::OGuard aGuard( GetMutex() );
1044 
1045     Window* pWindow = GetWindow();
1046     if ( pWindow )
1047     {
1048 /*
1049         if ( bVisible )
1050         {
1051             // #57167# TopWindows mit unsichtbaren Parent anzeigen...
1052             ::com::sun::star::uno::Any aTest = queryInterface( ::getCppuType(  (const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindow >*)  0 ) );
1053             if ( aTest.hasValue() )
1054             {
1055                 Window* pParent = pWindow->GetWindow( WINDOW_PARENTOVERLAP );
1056                 if ( pParent && !pParent->IsReallyVisible() )
1057                     pWindow->SetParent( pWindow->GetWindow( WINDOW_FRAME ) );
1058             }
1059         }
1060 */
1061         mpImpl->setDirectVisible( bVisible );
1062         pWindow->Show( bVisible &&  mpImpl->isEnableVisible() );
1063     }
1064 }
1065 
1066 void VCLXWindow::setEnable( sal_Bool bEnable ) throw(::com::sun::star::uno::RuntimeException)
1067 {
1068     ::vos::OGuard aGuard( GetMutex() );
1069 
1070     Window* pWindow = GetWindow();
1071     if ( pWindow )
1072     {
1073         pWindow->Enable( bEnable, sal_False ); // #95824# without children!
1074         pWindow->EnableInput( bEnable );
1075     }
1076 }
1077 
1078 void VCLXWindow::setFocus(  ) throw(::com::sun::star::uno::RuntimeException)
1079 {
1080     ::vos::OGuard aGuard( GetMutex() );
1081 
1082     if ( GetWindow() )
1083         GetWindow()->GrabFocus();
1084 }
1085 
1086 void VCLXWindow::addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1087 {
1088     ::vos::OGuard aGuard( GetMutex() );
1089 
1090     mpImpl->getWindowListeners().addInterface( rxListener );
1091 
1092     Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY );
1093     if ( xListener2.is() )
1094         mpImpl->getWindow2Listeners().addInterface( xListener2 );
1095 
1096     // #100119# Get all resize events, even if height or width 0, or invisible
1097     if ( GetWindow() )
1098         GetWindow()->EnableAllResize( sal_True );
1099 }
1100 
1101 void VCLXWindow::removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1102 {
1103     ::vos::OGuard aGuard( GetMutex() );
1104 
1105     Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY );
1106     if ( xListener2.is() )
1107         mpImpl->getWindow2Listeners().removeInterface( xListener2 );
1108 
1109     mpImpl->getWindowListeners().removeInterface( rxListener );
1110 }
1111 
1112 void VCLXWindow::addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1113 {
1114     ::vos::OGuard aGuard( GetMutex() );
1115     mpImpl->getFocusListeners().addInterface( rxListener );
1116 }
1117 
1118 void VCLXWindow::removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1119 {
1120     ::vos::OGuard aGuard( GetMutex() );
1121     mpImpl->getFocusListeners().removeInterface( rxListener );
1122 }
1123 
1124 void VCLXWindow::addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1125 {
1126     ::vos::OGuard aGuard( GetMutex() );
1127     mpImpl->getKeyListeners().addInterface( rxListener );
1128 }
1129 
1130 void VCLXWindow::removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1131 {
1132     ::vos::OGuard aGuard( GetMutex() );
1133     mpImpl->getKeyListeners().removeInterface( rxListener );
1134 }
1135 
1136 void VCLXWindow::addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1137 {
1138     ::vos::OGuard aGuard( GetMutex() );
1139     mpImpl->getMouseListeners().addInterface( rxListener );
1140 }
1141 
1142 void VCLXWindow::removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1143 {
1144     ::vos::OGuard aGuard( GetMutex() );
1145     mpImpl->getMouseListeners().removeInterface( rxListener );
1146 }
1147 
1148 void VCLXWindow::addMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1149 {
1150     ::vos::OGuard aGuard( GetMutex() );
1151     mpImpl->getMouseMotionListeners().addInterface( rxListener );
1152 }
1153 
1154 void VCLXWindow::removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1155 {
1156     ::vos::OGuard aGuard( GetMutex() );
1157     mpImpl->getMouseMotionListeners().removeInterface( rxListener );
1158 }
1159 
1160 void VCLXWindow::addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1161 {
1162     ::vos::OGuard aGuard( GetMutex() );
1163     mpImpl->getPaintListeners().addInterface( rxListener );
1164 }
1165 
1166 void VCLXWindow::removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
1167 {
1168     ::vos::OGuard aGuard( GetMutex() );
1169     mpImpl->getPaintListeners().removeInterface( rxListener );
1170 }
1171 
1172 // ::com::sun::star::awt::XWindowPeer
1173 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > VCLXWindow::getToolkit(  ) throw(::com::sun::star::uno::RuntimeException)
1174 {
1175     // no guard. nothing to guard here.
1176     // 82463 - 12/21/00 - fs
1177     return Application::GetVCLToolkit();
1178 }
1179 
1180 void VCLXWindow::setPointer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer >& rxPointer ) throw(::com::sun::star::uno::RuntimeException)
1181 {
1182     ::vos::OGuard aGuard( GetMutex() );
1183 
1184     VCLXPointer* pPointer = VCLXPointer::GetImplementation( rxPointer );
1185     if ( pPointer )
1186     {
1187         mpImpl->mxPointer = rxPointer;
1188         if ( GetWindow() )
1189             GetWindow()->SetPointer( pPointer->GetPointer() );
1190     }
1191 }
1192 
1193 void VCLXWindow::setBackground( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException)
1194 {
1195     ::vos::OGuard aGuard( GetMutex() );
1196 
1197     if ( GetWindow() )
1198     {
1199         Color aColor( (sal_uInt32)nColor );
1200         GetWindow()->SetBackground( aColor );
1201         GetWindow()->SetControlBackground( aColor );
1202 
1203         WindowType eWinType = GetWindow()->GetType();
1204         if ( ( eWinType == WINDOW_WINDOW ) ||
1205              ( eWinType == WINDOW_WORKWINDOW ) ||
1206              ( eWinType == WINDOW_FLOATINGWINDOW ) )
1207         {
1208             GetWindow()->Invalidate();
1209         }
1210     }
1211 }
1212 
1213 void VCLXWindow::invalidate( sal_Int16 nInvalidateFlags ) throw(::com::sun::star::uno::RuntimeException)
1214 {
1215     ::vos::OGuard aGuard( GetMutex() );
1216 
1217     if ( GetWindow() )
1218         GetWindow()->Invalidate( (sal_uInt16) nInvalidateFlags );
1219 }
1220 
1221 void VCLXWindow::invalidateRect( const ::com::sun::star::awt::Rectangle& rRect, sal_Int16 nInvalidateFlags ) throw(::com::sun::star::uno::RuntimeException)
1222 {
1223     ::vos::OGuard aGuard( GetMutex() );
1224 
1225     if ( GetWindow() )
1226         GetWindow()->Invalidate( VCLRectangle(rRect), (sal_uInt16) nInvalidateFlags );
1227 }
1228 
1229 
1230 // ::com::sun::star::awt::XVclWindowPeer
1231 sal_Bool VCLXWindow::isChild( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& rxPeer ) throw(::com::sun::star::uno::RuntimeException)
1232 {
1233     ::vos::OGuard aGuard( GetMutex() );
1234 
1235     sal_Bool bIsChild = sal_False;
1236     Window* pWindow = GetWindow();
1237     if ( pWindow )
1238     {
1239         Window* pPeerWindow = VCLUnoHelper::GetWindow( rxPeer );
1240         bIsChild = pPeerWindow && pWindow->IsChild( pPeerWindow );
1241     }
1242 
1243     return bIsChild;
1244 }
1245 
1246 void VCLXWindow::setDesignMode( sal_Bool bOn ) throw(::com::sun::star::uno::RuntimeException)
1247 {
1248     ::vos::OGuard aGuard( GetMutex() );
1249 
1250     mpImpl->mbDesignMode = bOn;
1251 }
1252 
1253 sal_Bool VCLXWindow::isDesignMode(  ) throw(::com::sun::star::uno::RuntimeException)
1254 {
1255     ::vos::OGuard aGuard( GetMutex() );
1256     return mpImpl->mbDesignMode;
1257 }
1258 
1259 void VCLXWindow::enableClipSiblings( sal_Bool bClip ) throw(::com::sun::star::uno::RuntimeException)
1260 {
1261     ::vos::OGuard aGuard( GetMutex() );
1262 
1263     if ( GetWindow() )
1264         GetWindow()->EnableClipSiblings( bClip );
1265 }
1266 
1267 void VCLXWindow::setForeground( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException)
1268 {
1269     ::vos::OGuard aGuard( GetMutex() );
1270 
1271     if ( GetWindow() )
1272     {
1273         Color aColor( (sal_uInt32)nColor );
1274         GetWindow()->SetControlForeground( aColor );
1275     }
1276 }
1277 
1278 void VCLXWindow::setControlFont( const ::com::sun::star::awt::FontDescriptor& rFont ) throw(::com::sun::star::uno::RuntimeException)
1279 {
1280     ::vos::OGuard aGuard( GetMutex() );
1281 
1282     if ( GetWindow() )
1283         GetWindow()->SetControlFont( VCLUnoHelper::CreateFont( rFont, GetWindow()->GetControlFont() ) );
1284 }
1285 
1286 void VCLXWindow::getStyles( sal_Int16 nType, ::com::sun::star::awt::FontDescriptor& Font, sal_Int32& ForegroundColor, sal_Int32& BackgroundColor ) throw(::com::sun::star::uno::RuntimeException)
1287 {
1288     ::vos::OGuard aGuard( GetMutex() );
1289 
1290     if ( GetWindow() )
1291     {
1292         const StyleSettings& rStyleSettings = GetWindow()->GetSettings().GetStyleSettings();
1293 
1294         switch ( nType )
1295         {
1296             case ::com::sun::star::awt::Style::FRAME:
1297             {
1298                 Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() );
1299                 ForegroundColor = rStyleSettings.GetWindowTextColor().GetColor();
1300                 BackgroundColor = rStyleSettings.GetWindowColor().GetColor();
1301             }
1302             break;
1303             case ::com::sun::star::awt::Style::DIALOG:
1304             {
1305                 Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() );
1306                 ForegroundColor = rStyleSettings.GetDialogTextColor().GetColor();
1307                 BackgroundColor = rStyleSettings.GetDialogColor().GetColor();
1308             }
1309             break;
1310             default: DBG_ERROR( "VCLWindow::getStyles() - unknown Type" );
1311         }
1312 
1313     }
1314 }
1315 
1316 namespace toolkit
1317 {
1318     static void setColorSettings( Window* _pWindow, const ::com::sun::star::uno::Any& _rValue,
1319         void (StyleSettings::*pSetter)( const Color& ), const Color& (StyleSettings::*pGetter)( ) const )
1320     {
1321         sal_Int32 nColor = 0;
1322         if ( !( _rValue >>= nColor ) )
1323             nColor = (Application::GetSettings().GetStyleSettings().*pGetter)().GetColor();
1324 
1325         AllSettings aSettings = _pWindow->GetSettings();
1326         StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1327 
1328         (aStyleSettings.*pSetter)( Color( nColor ) );
1329 
1330         aSettings.SetStyleSettings( aStyleSettings );
1331         _pWindow->SetSettings( aSettings, sal_True );
1332     }
1333 }
1334 
1335 // Terminated by BASEPROPERTY_NOTFOUND (or 0)
1336 void VCLXWindow::PushPropertyIds( std::list< sal_uInt16 > &rIds,
1337                                   int nFirstId, ...)
1338 {
1339     va_list pVarArgs;
1340     va_start( pVarArgs, nFirstId );
1341 
1342     for ( int nId = nFirstId; nId != BASEPROPERTY_NOTFOUND;
1343           nId = va_arg( pVarArgs, int ) )
1344         rIds.push_back( (sal_uInt16) nId );
1345 
1346     va_end( pVarArgs );
1347 }
1348 
1349 void VCLXWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds, bool bWithDefaults )
1350 {
1351     // These are common across ~all VCLXWindow derived classes
1352     if( bWithDefaults )
1353         PushPropertyIds( rIds,
1354                          BASEPROPERTY_ALIGN,
1355                          BASEPROPERTY_BACKGROUNDCOLOR,
1356                          BASEPROPERTY_BORDER,
1357                          BASEPROPERTY_BORDERCOLOR,
1358                          BASEPROPERTY_DEFAULTCONTROL,
1359                          BASEPROPERTY_ENABLED,
1360                          BASEPROPERTY_FONTDESCRIPTOR,
1361                          BASEPROPERTY_HELPTEXT,
1362                          BASEPROPERTY_HELPURL,
1363                          BASEPROPERTY_TEXT,
1364                          BASEPROPERTY_PRINTABLE,
1365                          BASEPROPERTY_ENABLEVISIBLE, // for visibility
1366                          BASEPROPERTY_TABSTOP,
1367                          0);
1368 
1369     // lovely hack from:
1370     // void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId )
1371     std::list< sal_uInt16 >::const_iterator iter;
1372     for( iter = rIds.begin(); iter != rIds.end(); iter++) {
1373         if( *iter == BASEPROPERTY_FONTDESCRIPTOR )
1374         {
1375             // some properties are not included in the FontDescriptor, but everytime
1376             // when we have a FontDescriptor we want to have these properties too.
1377             // => Easier to register the here, istead everywhere where I register the FontDescriptor...
1378 
1379             rIds.push_back( BASEPROPERTY_TEXTCOLOR );
1380             rIds.push_back( BASEPROPERTY_TEXTLINECOLOR );
1381             rIds.push_back( BASEPROPERTY_FONTRELIEF );
1382             rIds.push_back( BASEPROPERTY_FONTEMPHASISMARK );
1383             break;
1384         }
1385     }
1386 }
1387 
1388 void VCLXWindow::GetPropertyIds( std::list< sal_uInt16 >& _out_rIds )
1389 {
1390     return ImplGetPropertyIds( _out_rIds, mpImpl->mbWithDefaultProps );
1391 }
1392 
1393 ::cppu::OInterfaceContainerHelper& VCLXWindow::GetContainerListeners()
1394 {
1395     return mpImpl->getContainerListeners();
1396 }
1397 
1398 ::cppu::OInterfaceContainerHelper& VCLXWindow::GetTopWindowListeners()
1399 {
1400     return mpImpl->getTopWindowListeners();
1401 }
1402 
1403 namespace
1404 {
1405     void    lcl_updateWritingMode( Window& _rWindow, const sal_Int16 _nWritingMode, const sal_Int16 _nContextWritingMode )
1406     {
1407         sal_Bool bEnableRTL = sal_False;
1408         switch ( _nWritingMode )
1409         {
1410         case WritingMode2::LR_TB:   bEnableRTL = sal_False; break;
1411         case WritingMode2::RL_TB:   bEnableRTL = sal_True; break;
1412         case WritingMode2::CONTEXT:
1413         {
1414             // consult our ContextWritingMode. If it has an explicit RTL/LTR value, then use
1415             // it. If it doesn't (but is CONTEXT itself), then just ask the parent window of our
1416             // own window for its RTL mode
1417             switch ( _nContextWritingMode )
1418             {
1419                 case WritingMode2::LR_TB:   bEnableRTL = sal_False; break;
1420                 case WritingMode2::RL_TB:   bEnableRTL = sal_True; break;
1421                 case WritingMode2::CONTEXT:
1422                 {
1423                     const Window* pParent = _rWindow.GetParent();
1424                     OSL_ENSURE( pParent, "lcl_updateWritingMode: cannot determine context's writing mode!" );
1425                     if ( pParent )
1426                         bEnableRTL = pParent->IsRTLEnabled();
1427                 }
1428                 break;
1429             }
1430         }
1431         break;
1432         default:
1433             OSL_ENSURE( false, "lcl_updateWritingMode: unsupported WritingMode!" );
1434         }   // switch ( nWritingMode )
1435 
1436         _rWindow.EnableRTL( bEnableRTL );
1437     }
1438 }
1439 
1440 void VCLXWindow::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException)
1441 {
1442     ::vos::OGuard aGuard( GetMutex() );
1443 
1444     Window* pWindow = GetWindow();
1445     if ( !pWindow )
1446         return;
1447 
1448     sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
1449 
1450     WindowType eWinType = pWindow->GetType();
1451     sal_uInt16 nPropType = GetPropertyId( PropertyName );
1452     switch ( nPropType )
1453     {
1454         case BASEPROPERTY_REFERENCE_DEVICE:
1455         {
1456             Control* pControl = dynamic_cast< Control* >( pWindow );
1457             OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" );
1458             if ( !pControl )
1459                 break;
1460             Reference< XDevice > xDevice( Value, UNO_QUERY );
1461             OutputDevice* pDevice = VCLUnoHelper::GetOutputDevice( xDevice );
1462             pControl->SetReferenceDevice( pDevice );
1463         }
1464         break;
1465 
1466         case BASEPROPERTY_CONTEXT_WRITING_MODE:
1467         {
1468             OSL_VERIFY( Value >>= mpImpl->mnContextWritingMode );
1469             if ( mpImpl->mnWritingMode == WritingMode2::CONTEXT )
1470                 lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode );
1471         }
1472         break;
1473 
1474         case BASEPROPERTY_WRITING_MODE:
1475         {
1476             sal_Bool bProperType = ( Value >>= mpImpl->mnWritingMode );
1477             OSL_ENSURE( bProperType, "VCLXWindow::setProperty( 'WritingMode' ): illegal value type!" );
1478             if ( bProperType )
1479                 lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode );
1480         }
1481         break;
1482 
1483         case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:
1484         {
1485             sal_uInt16 nWheelBehavior( MouseWheelBehavior::SCROLL_FOCUS_ONLY );
1486             OSL_VERIFY( Value >>= nWheelBehavior );
1487 
1488             AllSettings aSettings = pWindow->GetSettings();
1489             MouseSettings aMouseSettings = aSettings.GetMouseSettings();
1490 
1491             sal_uInt16 nVclBehavior( MOUSE_WHEEL_FOCUS_ONLY );
1492             switch ( nWheelBehavior )
1493             {
1494             case MouseWheelBehavior::SCROLL_DISABLED:   nVclBehavior = MOUSE_WHEEL_DISABLE;     break;
1495             case MouseWheelBehavior::SCROLL_FOCUS_ONLY: nVclBehavior = MOUSE_WHEEL_FOCUS_ONLY;  break;
1496             case MouseWheelBehavior::SCROLL_ALWAYS:     nVclBehavior = MOUSE_WHEEL_ALWAYS;      break;
1497             default:
1498                 OSL_ENSURE( false, "VCLXWindow::setProperty( 'MouseWheelBehavior' ): illegal property value!" );
1499             }
1500 
1501             aMouseSettings.SetWheelBehavior( nWheelBehavior );
1502             aSettings.SetMouseSettings( aMouseSettings );
1503             pWindow->SetSettings( aSettings, sal_True );
1504         }
1505         break;
1506 
1507         case BASEPROPERTY_NATIVE_WIDGET_LOOK:
1508         {
1509             sal_Bool bEnable( sal_True );
1510             OSL_VERIFY( Value >>= bEnable );
1511             pWindow->EnableNativeWidget( bEnable );
1512         }
1513         break;
1514 
1515         case BASEPROPERTY_PLUGINPARENT:
1516         {
1517             // set parent handle
1518             SetSystemParent_Impl( Value );
1519         }
1520         break;
1521 
1522         case BASEPROPERTY_ENABLED:
1523         {
1524             sal_Bool b = sal_Bool();
1525             if ( Value >>= b )
1526                 setEnable( b );
1527         }
1528         break;
1529         case BASEPROPERTY_ENABLEVISIBLE:
1530         {
1531             sal_Bool b = sal_False;
1532             if ( Value >>= b )
1533             {
1534                 if( b != mpImpl->isEnableVisible() )
1535                 {
1536                     mpImpl->setEnableVisible( b );
1537                     pWindow->Show( b && mpImpl->isDirectVisible() );
1538                 }
1539             }
1540         }
1541         break;
1542         case BASEPROPERTY_TEXT:
1543         case BASEPROPERTY_LABEL:
1544         case BASEPROPERTY_TITLE:
1545         {
1546             ::rtl::OUString aText;
1547             if ( Value >>= aText )
1548             {
1549                 switch (eWinType)
1550                 {
1551                     case WINDOW_OKBUTTON:
1552                     case WINDOW_CANCELBUTTON:
1553                     case WINDOW_HELPBUTTON:
1554                         // Standard Button: overwrite only if not empty.
1555                         if (aText.getLength())
1556                             pWindow->SetText( aText );
1557                         break;
1558 
1559                     default:
1560                         pWindow->SetText( aText );
1561                         break;
1562                 }
1563             }
1564         }
1565         break;
1566         case BASEPROPERTY_ACCESSIBLENAME:
1567         {
1568             ::rtl::OUString aText;
1569             if ( Value >>= aText )
1570                 pWindow->SetAccessibleName( aText );
1571         }
1572         break;
1573         case BASEPROPERTY_HELPURL:
1574         {
1575             ::rtl::OUString aURL;
1576             if ( Value >>= aURL )
1577             {
1578                 INetURLObject aHelpURL( aURL );
1579                 if ( aHelpURL.GetProtocol() == INET_PROT_HID )
1580                     pWindow->SetHelpId( rtl::OUStringToOString( aHelpURL.GetURLPath(), RTL_TEXTENCODING_UTF8 ) );
1581                 else
1582                     pWindow->SetHelpId( rtl::OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ) );
1583             }
1584         }
1585         break;
1586         case BASEPROPERTY_HELPTEXT:
1587         {
1588             ::rtl::OUString aHelpText;
1589             if ( Value >>= aHelpText )
1590             {
1591                 pWindow->SetQuickHelpText( aHelpText );
1592             }
1593         }
1594         break;
1595         case BASEPROPERTY_FONTDESCRIPTOR:
1596         {
1597             if ( bVoid )
1598                 pWindow->SetControlFont( Font() );
1599             else
1600             {
1601                 ::com::sun::star::awt::FontDescriptor aFont;
1602                 if ( Value >>= aFont )
1603                     pWindow->SetControlFont( VCLUnoHelper::CreateFont( aFont, pWindow->GetControlFont() ) );
1604             }
1605         }
1606         break;
1607         case BASEPROPERTY_FONTRELIEF:
1608         {
1609             sal_Int16 n = sal_Int16();
1610             if ( Value >>= n )
1611             {
1612                 Font aFont = pWindow->GetControlFont();
1613                 aFont.SetRelief( (FontRelief)n );
1614                 pWindow->SetControlFont( aFont );
1615             }
1616         }
1617         break;
1618         case BASEPROPERTY_FONTEMPHASISMARK:
1619         {
1620             sal_Int16 n = sal_Int16();
1621             if ( Value >>= n )
1622             {
1623                 Font aFont = pWindow->GetControlFont();
1624                 aFont.SetEmphasisMark( n );
1625                 pWindow->SetControlFont( aFont );
1626             }
1627         }
1628         break;
1629         case BASEPROPERTY_BACKGROUNDCOLOR:
1630             if ( bVoid )
1631             {
1632                 switch ( eWinType )
1633                 {
1634                     // set dialog color for default
1635                     case WINDOW_DIALOG:
1636                     case WINDOW_MESSBOX:
1637                     case WINDOW_INFOBOX:
1638                     case WINDOW_WARNINGBOX:
1639                     case WINDOW_ERRORBOX:
1640                     case WINDOW_QUERYBOX:
1641                     case WINDOW_TABPAGE:
1642                     {
1643                         Color aColor = pWindow->GetSettings().GetStyleSettings().GetDialogColor();
1644                         pWindow->SetBackground( aColor );
1645                         pWindow->SetControlBackground( aColor );
1646                         break;
1647                     }
1648 
1649                     case WINDOW_FIXEDTEXT:
1650                     case WINDOW_CHECKBOX:
1651                     case WINDOW_RADIOBUTTON:
1652                     case WINDOW_GROUPBOX:
1653                     case WINDOW_FIXEDLINE:
1654                     {
1655                         // support transparency only for special controls
1656                         pWindow->SetBackground();
1657                         pWindow->SetControlBackground();
1658                         pWindow->SetPaintTransparent( sal_True );
1659                         break;
1660                     }
1661 
1662                     default:
1663                     {
1664                         // default code which enables transparency for
1665                         // compound controls. It's not real transparency
1666                         // as most of these controls repaint their client
1667                         // area completely new.
1668                         if ( pWindow->IsCompoundControl() )
1669                             pWindow->SetBackground();
1670                         pWindow->SetControlBackground();
1671                         break;
1672                     }
1673                 }
1674             }
1675             else
1676             {
1677                 sal_Int32 nColor = 0;
1678                 if ( Value >>= nColor )
1679                 {
1680                     Color aColor( nColor );
1681                     pWindow->SetControlBackground( aColor );
1682                     pWindow->SetBackground( aColor );
1683                     switch ( eWinType )
1684                     {
1685                         // reset paint transparent mode
1686                         case WINDOW_FIXEDTEXT:
1687                         case WINDOW_CHECKBOX:
1688                         case WINDOW_RADIOBUTTON:
1689                         case WINDOW_GROUPBOX:
1690                         case WINDOW_FIXEDLINE:
1691                             pWindow->SetPaintTransparent( sal_False );
1692                         default: ;
1693                     }
1694                     pWindow->Invalidate();  // Falls das Control nicht drauf reagiert
1695                 }
1696             }
1697         break;
1698         case BASEPROPERTY_TEXTCOLOR:
1699             if ( bVoid )
1700             {
1701                 pWindow->SetControlForeground();
1702             }
1703             else
1704             {
1705                 sal_Int32 nColor = 0;
1706                 if ( Value >>= nColor )
1707                 {
1708                     Color aColor( nColor );
1709                     pWindow->SetTextColor( aColor );
1710                     pWindow->SetControlForeground( aColor );
1711                 }
1712             }
1713         break;
1714         case BASEPROPERTY_TEXTLINECOLOR:
1715             if ( bVoid )
1716             {
1717                 pWindow->SetTextLineColor();
1718             }
1719             else
1720             {
1721                 sal_Int32 nColor = 0;
1722                 if ( Value >>= nColor )
1723                 {
1724                     Color aColor( nColor );
1725                     pWindow->SetTextLineColor( aColor );
1726                 }
1727             }
1728         break;
1729         case BASEPROPERTY_FILLCOLOR:
1730             if ( bVoid )
1731                 pWindow->SetFillColor();
1732             else
1733             {
1734                 sal_Int32 nColor = 0;
1735                 if ( Value >>= nColor )
1736                 {
1737                     Color aColor( nColor );
1738                     pWindow->SetFillColor( aColor );
1739                 }
1740             }
1741         break;
1742         case BASEPROPERTY_LINECOLOR:
1743             if ( bVoid )
1744                 pWindow->SetLineColor();
1745             else
1746             {
1747                 sal_Int32 nColor = 0;
1748                 if ( Value >>= nColor )
1749                 {
1750                     Color aColor( nColor );
1751                     pWindow->SetLineColor( aColor );
1752                 }
1753             }
1754         break;
1755         case BASEPROPERTY_BORDER:
1756         {
1757             WinBits nStyle = pWindow->GetStyle();
1758             sal_uInt16 nBorder = 0;
1759             Value >>= nBorder;
1760             if ( !nBorder )
1761             {
1762                 pWindow->SetStyle( nStyle & ~WB_BORDER );
1763             }
1764             else
1765             {
1766                 pWindow->SetStyle( nStyle | WB_BORDER );
1767                 pWindow->SetBorderStyle( nBorder );
1768             }
1769         }
1770         break;
1771         case BASEPROPERTY_TABSTOP:
1772         {
1773             WinBits nStyle = pWindow->GetStyle() & ~WB_TABSTOP;
1774             if ( !bVoid )
1775             {
1776                 sal_Bool bTab = false;
1777                 Value >>= bTab;
1778                 if ( bTab )
1779                     nStyle |= WB_TABSTOP;
1780                 else
1781                     nStyle |= WB_NOTABSTOP;
1782             }
1783             pWindow->SetStyle( nStyle );
1784         }
1785         break;
1786         case BASEPROPERTY_VERTICALALIGN:
1787         {
1788             VerticalAlignment eAlign = VerticalAlignment_MAKE_FIXED_SIZE;
1789             WinBits nStyle = pWindow->GetStyle();
1790             nStyle &= ~(WB_TOP|WB_VCENTER|WB_BOTTOM);
1791             if ( !bVoid )
1792                 Value >>= eAlign;
1793             switch ( eAlign )
1794             {
1795             case VerticalAlignment_TOP:
1796                 nStyle |= WB_TOP;
1797                 break;
1798             case VerticalAlignment_MIDDLE:
1799                 nStyle |= WB_VCENTER;
1800                 break;
1801             case VerticalAlignment_BOTTOM:
1802                 nStyle |= WB_BOTTOM;
1803                 break;
1804             default: ; // for warning free code, MAKE_FIXED_SIZE
1805             }
1806             pWindow->SetStyle( nStyle );
1807         }
1808         break;
1809         case BASEPROPERTY_ALIGN:
1810         {
1811             sal_Int16 nAlign = PROPERTY_ALIGN_LEFT;
1812             switch ( eWinType )
1813             {
1814                 case WINDOW_COMBOBOX:
1815                 case WINDOW_BUTTON:
1816                 case WINDOW_PUSHBUTTON:
1817                 case WINDOW_OKBUTTON:
1818                 case WINDOW_CANCELBUTTON:
1819                 case WINDOW_HELPBUTTON:
1820                     nAlign = PROPERTY_ALIGN_CENTER;
1821                     // no break here!
1822                 case WINDOW_FIXEDTEXT:
1823                 case WINDOW_EDIT:
1824                 case WINDOW_MULTILINEEDIT:
1825                 case WINDOW_CHECKBOX:
1826                 case WINDOW_RADIOBUTTON:
1827                 case WINDOW_LISTBOX:
1828                 {
1829                     WinBits nStyle = pWindow->GetStyle();
1830                     nStyle &= ~(WB_LEFT|WB_CENTER|WB_RIGHT);
1831                     if ( !bVoid )
1832                         Value >>= nAlign;
1833                     if ( nAlign == PROPERTY_ALIGN_LEFT )
1834                         nStyle |= WB_LEFT;
1835                     else if ( nAlign == PROPERTY_ALIGN_CENTER )
1836                         nStyle |= WB_CENTER;
1837                     else
1838                         nStyle |= WB_RIGHT;
1839                     pWindow->SetStyle( nStyle );
1840                 }
1841                 break;
1842             }
1843         }
1844         break;
1845         case BASEPROPERTY_MULTILINE:
1846         {
1847             if  (  ( eWinType == WINDOW_FIXEDTEXT )
1848                 || ( eWinType == WINDOW_CHECKBOX )
1849                 || ( eWinType == WINDOW_RADIOBUTTON )
1850                 || ( eWinType == WINDOW_BUTTON )
1851                 || ( eWinType == WINDOW_PUSHBUTTON )
1852                 || ( eWinType == WINDOW_OKBUTTON )
1853                 || ( eWinType == WINDOW_CANCELBUTTON )
1854                 || ( eWinType == WINDOW_HELPBUTTON )
1855                 )
1856             {
1857                 WinBits nStyle = pWindow->GetStyle();
1858                 sal_Bool bMulti = false;
1859                 Value >>= bMulti;
1860                 if ( bMulti )
1861                     nStyle |= WB_WORDBREAK;
1862                 else
1863                     nStyle &= ~WB_WORDBREAK;
1864                 pWindow->SetStyle( nStyle );
1865             }
1866         }
1867         break;
1868         case BASEPROPERTY_ORIENTATION:
1869         {
1870             switch ( eWinType )
1871             {
1872                 case WINDOW_FIXEDLINE:
1873                 {
1874                     sal_Int32 nOrientation = 0;
1875                     if ( Value >>= nOrientation )
1876                     {
1877                         WinBits nStyle = pWindow->GetStyle();
1878                         nStyle &= ~(WB_HORZ|WB_VERT);
1879                         if ( nOrientation == 0 )
1880                             nStyle |= WB_HORZ;
1881                         else
1882                             nStyle |= WB_VERT;
1883 
1884                         pWindow->SetStyle( nStyle );
1885                     }
1886                 }
1887                 break;
1888             }
1889         }
1890         break;
1891         case BASEPROPERTY_AUTOMNEMONICS:
1892         {
1893             sal_Bool bAutoMnemonics = false;
1894             Value >>= bAutoMnemonics;
1895             AllSettings aSettings = pWindow->GetSettings();
1896             StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1897             if ( aStyleSettings.GetAutoMnemonic() != bAutoMnemonics )
1898             {
1899                 aStyleSettings.SetAutoMnemonic( bAutoMnemonics );
1900                 aSettings.SetStyleSettings( aStyleSettings );
1901                 pWindow->SetSettings( aSettings );
1902             }
1903         }
1904         break;
1905         case BASEPROPERTY_MOUSETRANSPARENT:
1906         {
1907             sal_Bool bMouseTransparent = false;
1908             Value >>= bMouseTransparent;
1909             pWindow->SetMouseTransparent( bMouseTransparent );
1910         }
1911         break;
1912         case BASEPROPERTY_PAINTTRANSPARENT:
1913         {
1914             sal_Bool bPaintTransparent = false;
1915             Value >>= bPaintTransparent;
1916             pWindow->SetPaintTransparent( bPaintTransparent );
1917 //                pWindow->SetBackground();
1918         }
1919         break;
1920 
1921         case BASEPROPERTY_REPEAT:
1922         {
1923             sal_Bool bRepeat( sal_False );
1924             Value >>= bRepeat;
1925 
1926             WinBits nStyle = pWindow->GetStyle();
1927             if ( bRepeat )
1928                 nStyle |= WB_REPEAT;
1929             else
1930                 nStyle &= ~WB_REPEAT;
1931             pWindow->SetStyle( nStyle );
1932         }
1933         break;
1934 
1935         case BASEPROPERTY_REPEAT_DELAY:
1936         {
1937             sal_Int32 nRepeatDelay = 0;
1938             if ( Value >>= nRepeatDelay )
1939             {
1940                 AllSettings aSettings = pWindow->GetSettings();
1941                 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
1942 
1943                 aMouseSettings.SetButtonRepeat( nRepeatDelay );
1944                 aSettings.SetMouseSettings( aMouseSettings );
1945 
1946                 pWindow->SetSettings( aSettings, sal_True );
1947             }
1948         }
1949         break;
1950 
1951         case BASEPROPERTY_SYMBOL_COLOR:
1952             ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetButtonTextColor, &StyleSettings::GetButtonTextColor );
1953             break;
1954 
1955         case BASEPROPERTY_BORDERCOLOR:
1956             ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetMonoColor, &StyleSettings::GetMonoColor);
1957             break;
1958         case BASEPROPERTY_DEFAULTCONTROL:
1959         {
1960             rtl::OUString aName;
1961             Value >>= aName;
1962             break;
1963         }
1964     }
1965 }
1966 
1967 ::com::sun::star::uno::Any VCLXWindow::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException)
1968 {
1969     ::vos::OGuard aGuard( GetMutex() );
1970 
1971     ::com::sun::star::uno::Any aProp;
1972     if ( GetWindow() )
1973     {
1974         WindowType eWinType = GetWindow()->GetType();
1975         sal_uInt16 nPropType = GetPropertyId( PropertyName );
1976         switch ( nPropType )
1977         {
1978             case BASEPROPERTY_REFERENCE_DEVICE:
1979             {
1980                 Control* pControl = dynamic_cast< Control* >( GetWindow() );
1981                 OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" );
1982                 if ( !pControl )
1983                     break;
1984 
1985                 VCLXDevice* pDevice = new VCLXDevice;
1986                 pDevice->SetOutputDevice( pControl->GetReferenceDevice() );
1987                 aProp <<= Reference< XDevice >( pDevice );
1988             }
1989             break;
1990 
1991             case BASEPROPERTY_CONTEXT_WRITING_MODE:
1992                 aProp <<= mpImpl->mnContextWritingMode;
1993                 break;
1994 
1995             case BASEPROPERTY_WRITING_MODE:
1996                 aProp <<= mpImpl->mnWritingMode;
1997                 break;
1998 
1999             case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:
2000             {
2001                 sal_uInt16 nVclBehavior = GetWindow()->GetSettings().GetMouseSettings().GetWheelBehavior();
2002                 sal_Int16 nBehavior = MouseWheelBehavior::SCROLL_FOCUS_ONLY;
2003                 switch ( nVclBehavior )
2004                 {
2005                 case MOUSE_WHEEL_DISABLE:       nBehavior = MouseWheelBehavior::SCROLL_DISABLED;    break;
2006                 case MOUSE_WHEEL_FOCUS_ONLY:    nBehavior = MouseWheelBehavior::SCROLL_FOCUS_ONLY;  break;
2007                 case MOUSE_WHEEL_ALWAYS:        nBehavior = MouseWheelBehavior::SCROLL_ALWAYS;      break;
2008                 default:
2009                     OSL_ENSURE( false, "VCLXWindow::getProperty( 'MouseWheelBehavior' ): illegal VCL value!" );
2010                 }
2011                 aProp <<= nBehavior;
2012             }
2013             break;
2014 
2015             case BASEPROPERTY_NATIVE_WIDGET_LOOK:
2016                 aProp <<= (sal_Bool) GetWindow()->IsNativeWidgetEnabled();
2017                 break;
2018 
2019             case BASEPROPERTY_ENABLED:
2020                 aProp <<= (sal_Bool) GetWindow()->IsEnabled();
2021                 break;
2022 
2023             case BASEPROPERTY_ENABLEVISIBLE:
2024                 aProp <<= (sal_Bool) mpImpl->isEnableVisible();
2025                 break;
2026 
2027             case BASEPROPERTY_HIGHCONTRASTMODE:
2028                 aProp <<= (sal_Bool) GetWindow()->GetSettings().GetStyleSettings().GetHighContrastMode();
2029                 break;
2030 
2031             case BASEPROPERTY_TEXT:
2032             case BASEPROPERTY_LABEL:
2033             case BASEPROPERTY_TITLE:
2034             {
2035                 ::rtl::OUString aText = GetWindow()->GetText();
2036                 aProp <<= aText;
2037             }
2038             break;
2039             case BASEPROPERTY_ACCESSIBLENAME:
2040             {
2041                 ::rtl::OUString aText = GetWindow()->GetAccessibleName();
2042                 aProp <<= aText;
2043             }
2044             break;
2045             case BASEPROPERTY_HELPTEXT:
2046             {
2047                 ::rtl::OUString aText = GetWindow()->GetQuickHelpText();
2048                 aProp <<= aText;
2049             }
2050             break;
2051             case BASEPROPERTY_HELPURL:
2052             {
2053                 rtl::OUString aHelpId( rtl::OStringToOUString( GetWindow()->GetHelpId(), RTL_TEXTENCODING_UTF8 ) );
2054                 aProp <<= ::rtl::OUString( aHelpId );
2055             }
2056             break;
2057             case BASEPROPERTY_FONTDESCRIPTOR:
2058             {
2059                 Font aFont = GetWindow()->GetControlFont();
2060                 ::com::sun::star::awt::FontDescriptor aFD = VCLUnoHelper::CreateFontDescriptor( aFont );
2061                 aProp <<= aFD;
2062             }
2063             break;
2064             case BASEPROPERTY_BACKGROUNDCOLOR:
2065                 aProp <<= (sal_Int32) GetWindow()->GetControlBackground().GetColor();
2066             break;
2067             case BASEPROPERTY_DISPLAYBACKGROUNDCOLOR:
2068                 aProp <<= (sal_Int32) GetWindow()->GetDisplayBackground().GetColor().GetColor();
2069             break;
2070             case BASEPROPERTY_FONTRELIEF:
2071                 aProp <<= (sal_Int16) GetWindow()->GetControlFont().GetRelief();
2072             break;
2073             case BASEPROPERTY_FONTEMPHASISMARK:
2074                 aProp <<= (sal_Int16) GetWindow()->GetControlFont().GetEmphasisMark();
2075             break;
2076             case BASEPROPERTY_TEXTCOLOR:
2077                 aProp <<= (sal_Int32) GetWindow()->GetControlForeground().GetColor();
2078             break;
2079             case BASEPROPERTY_TEXTLINECOLOR:
2080                 aProp <<= (sal_Int32) GetWindow()->GetTextLineColor().GetColor();
2081             break;
2082             case BASEPROPERTY_FILLCOLOR:
2083                 aProp <<= (sal_Int32) GetWindow()->GetFillColor().GetColor();
2084             break;
2085             case BASEPROPERTY_LINECOLOR:
2086                 aProp <<= (sal_Int32) GetWindow()->GetLineColor().GetColor();
2087             break;
2088             case BASEPROPERTY_BORDER:
2089             {
2090                 sal_Int16 nBorder = 0;
2091                 if ( GetWindow()->GetStyle() & WB_BORDER )
2092                     nBorder = GetWindow()->GetBorderStyle();
2093                 aProp <<= nBorder;
2094             }
2095             break;
2096             case BASEPROPERTY_TABSTOP:
2097                 aProp <<= (sal_Bool) ( GetWindow()->GetStyle() & WB_TABSTOP ) ? sal_True : sal_False;
2098             break;
2099             case BASEPROPERTY_VERTICALALIGN:
2100             {
2101                 WinBits nStyle = GetWindow()->GetStyle();
2102                 if ( nStyle & WB_TOP )
2103                     aProp <<= VerticalAlignment_TOP;
2104                 else if ( nStyle & WB_VCENTER )
2105                     aProp <<= VerticalAlignment_MIDDLE;
2106                 else if ( nStyle & WB_BOTTOM )
2107                     aProp <<= VerticalAlignment_BOTTOM;
2108             }
2109             break;
2110             case BASEPROPERTY_ALIGN:
2111             {
2112                 switch ( eWinType )
2113                 {
2114                     case WINDOW_FIXEDTEXT:
2115                     case WINDOW_EDIT:
2116                     case WINDOW_MULTILINEEDIT:
2117                     case WINDOW_CHECKBOX:
2118                     case WINDOW_RADIOBUTTON:
2119                     case WINDOW_LISTBOX:
2120                     case WINDOW_COMBOBOX:
2121                     case WINDOW_BUTTON:
2122                     case WINDOW_PUSHBUTTON:
2123                     case WINDOW_OKBUTTON:
2124                     case WINDOW_CANCELBUTTON:
2125                     case WINDOW_HELPBUTTON:
2126                     {
2127                         WinBits nStyle = GetWindow()->GetStyle();
2128                         if ( nStyle & WB_LEFT )
2129                             aProp <<= (sal_Int16) PROPERTY_ALIGN_LEFT;
2130                         else if ( nStyle & WB_CENTER )
2131                             aProp <<= (sal_Int16) PROPERTY_ALIGN_CENTER;
2132                         else if ( nStyle & WB_RIGHT )
2133                             aProp <<= (sal_Int16) PROPERTY_ALIGN_RIGHT;
2134                     }
2135                     break;
2136                 }
2137             }
2138             case BASEPROPERTY_MULTILINE:
2139             {
2140                 if  (  ( eWinType == WINDOW_FIXEDTEXT )
2141                     || ( eWinType == WINDOW_CHECKBOX )
2142                     || ( eWinType == WINDOW_RADIOBUTTON )
2143                     || ( eWinType == WINDOW_BUTTON )
2144                     || ( eWinType == WINDOW_PUSHBUTTON )
2145                     || ( eWinType == WINDOW_OKBUTTON )
2146                     || ( eWinType == WINDOW_CANCELBUTTON )
2147                     || ( eWinType == WINDOW_HELPBUTTON )
2148                     )
2149                     aProp <<= (sal_Bool) ( GetWindow()->GetStyle() & WB_WORDBREAK ) ? sal_True : sal_False;
2150             }
2151             break;
2152             case BASEPROPERTY_AUTOMNEMONICS:
2153             {
2154                 sal_Bool bAutoMnemonics = GetWindow()->GetSettings().GetStyleSettings().GetAutoMnemonic();
2155                 aProp <<= bAutoMnemonics;
2156             }
2157             break;
2158             case BASEPROPERTY_MOUSETRANSPARENT:
2159             {
2160                 sal_Bool bMouseTransparent = GetWindow()->IsMouseTransparent();
2161                 aProp <<= bMouseTransparent;
2162             }
2163             break;
2164             case BASEPROPERTY_PAINTTRANSPARENT:
2165             {
2166                 sal_Bool bPaintTransparent = GetWindow()->IsPaintTransparent();
2167                 aProp <<= bPaintTransparent;
2168             }
2169             break;
2170 
2171             case BASEPROPERTY_REPEAT:
2172                 aProp <<= (sal_Bool)( 0 != ( GetWindow()->GetStyle() & WB_REPEAT ) );
2173                 break;
2174 
2175             case BASEPROPERTY_REPEAT_DELAY:
2176             {
2177                 sal_Int32 nButtonRepeat = GetWindow()->GetSettings().GetMouseSettings().GetButtonRepeat();
2178                 aProp <<= (sal_Int32)nButtonRepeat;
2179             }
2180             break;
2181 
2182             case BASEPROPERTY_SYMBOL_COLOR:
2183                 aProp <<= (sal_Int32)GetWindow()->GetSettings().GetStyleSettings().GetButtonTextColor().GetColor();
2184                 break;
2185 
2186             case BASEPROPERTY_BORDERCOLOR:
2187                 aProp <<= (sal_Int32)GetWindow()->GetSettings().GetStyleSettings().GetMonoColor().GetColor();
2188                 break;
2189         }
2190     }
2191     return aProp;
2192 }
2193 
2194 
2195 // ::com::sun::star::awt::XLayoutConstrains
2196 ::com::sun::star::awt::Size VCLXWindow::getMinimumSize(  ) throw(::com::sun::star::uno::RuntimeException)
2197 {
2198     ::vos::OGuard aGuard( GetMutex() );
2199 
2200     // Diese Methode sollte nur fuer Componenten gerufen werden, die zwar
2201     // ueber das ::com::sun::star::awt::Toolkit erzeugt werden koennen, aber fuer die es
2202     // kein Interface gibt.
2203 
2204     Size aSz;
2205     if ( GetWindow() )
2206     {
2207         WindowType nWinType = GetWindow()->GetType();
2208         switch ( nWinType )
2209         {
2210             case WINDOW_CONTROL:
2211                 aSz.Width() = GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*12;
2212                 aSz.Height() = GetWindow()->GetTextHeight()+2*6;
2213             break;
2214 
2215             case WINDOW_PATTERNBOX:
2216             case WINDOW_NUMERICBOX:
2217             case WINDOW_METRICBOX:
2218             case WINDOW_CURRENCYBOX:
2219             case WINDOW_DATEBOX:
2220             case WINDOW_TIMEBOX:
2221             case WINDOW_LONGCURRENCYBOX:
2222                 aSz.Width() = GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*2;
2223                 aSz.Height() = GetWindow()->GetTextHeight()+2*2;
2224             break;
2225             case WINDOW_SCROLLBARBOX:
2226                 return VCLXScrollBar::implGetMinimumSize( GetWindow() );
2227             default:
2228                 aSz = GetWindow()->GetOptimalSize( WINDOWSIZE_MINIMUM );
2229         }
2230     }
2231 
2232     return ::com::sun::star::awt::Size( aSz.Width(), aSz.Height() );
2233 }
2234 
2235 ::com::sun::star::awt::Size VCLXWindow::getPreferredSize(  ) throw(::com::sun::star::uno::RuntimeException)
2236 {
2237     return getMinimumSize();
2238 }
2239 
2240 ::com::sun::star::awt::Size VCLXWindow::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException)
2241 {
2242     ::vos::OGuard aGuard( GetMutex() );
2243 
2244     ::com::sun::star::awt::Size aNewSize( rNewSize );
2245     ::com::sun::star::awt::Size aMinSize = getMinimumSize();
2246 
2247     if ( aNewSize.Width < aMinSize.Width )
2248         aNewSize.Width = aMinSize.Width;
2249     if ( aNewSize.Height < aMinSize.Height )
2250         aNewSize.Height = aMinSize.Height;
2251 
2252     return aNewSize;
2253 }
2254 
2255 
2256 // ::com::sun::star::awt::XView
2257 sal_Bool VCLXWindow::setGraphics( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >& rxDevice ) throw(::com::sun::star::uno::RuntimeException)
2258 {
2259     ::vos::OGuard aGuard( GetMutex() );
2260 
2261     if ( VCLUnoHelper::GetOutputDevice( rxDevice ) )
2262         mpImpl->mxViewGraphics = rxDevice;
2263     else
2264         mpImpl->mxViewGraphics = NULL;
2265 
2266     return mpImpl->mxViewGraphics.is();
2267 }
2268 
2269 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > VCLXWindow::getGraphics(  ) throw(::com::sun::star::uno::RuntimeException)
2270 {
2271     ::vos::OGuard aGuard( GetMutex() );
2272 
2273     return mpImpl->mxViewGraphics;
2274 }
2275 
2276 ::com::sun::star::awt::Size VCLXWindow::getSize(  ) throw(::com::sun::star::uno::RuntimeException)
2277 {
2278     ::vos::OGuard aGuard( GetMutex() );
2279 
2280     Size aSz;
2281     if ( GetWindow() )
2282         aSz = GetWindow()->GetSizePixel();
2283     return ::com::sun::star::awt::Size( aSz.Width(), aSz.Height() );
2284 }
2285 
2286 void VCLXWindow::draw( sal_Int32 nX, sal_Int32 nY ) throw(::com::sun::star::uno::RuntimeException)
2287 {
2288     ::vos::OGuard aGuard( GetMutex() );
2289 
2290     Window* pWindow = GetWindow();
2291     if ( !pWindow )
2292         return;
2293 
2294     if ( isDesignMode() || mpImpl->isEnableVisible() )
2295     {
2296         TabPage* pTabPage = dynamic_cast< TabPage* >( pWindow );
2297         if ( pTabPage )
2298         {
2299             Point aPos( nX, nY );
2300             Size  aSize = pWindow->GetSizePixel();
2301 
2302             OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( mpImpl->mxViewGraphics );
2303             aPos  = pDev->PixelToLogic( aPos );
2304             aSize = pDev->PixelToLogic( aSize );
2305 
2306             pTabPage->Draw( pDev, aPos, aSize, 0 );
2307             return;
2308         }
2309 
2310         OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( mpImpl->mxViewGraphics );
2311         Point aPos( nX, nY );
2312 
2313         if ( !pDev )
2314             pDev = pWindow->GetParent();
2315 
2316         if ( pWindow->GetParent() && !pWindow->IsSystemWindow() && ( pWindow->GetParent() == pDev ) )
2317         {
2318             // #i40647# don't draw here if this is a recursive call
2319             // sometimes this is called recursively, because the Update call on the parent
2320             // (strangely) triggers another paint. Prevent a stack overflow here
2321             // Yes, this is only fixing symptoms for the moment ....
2322             // #i40647# / 2005-01-18 / frank.schoenheit@sun.com
2323             if ( !mpImpl->getDrawingOntoParent_ref() )
2324             {
2325                 ::comphelper::FlagGuard aDrawingflagGuard( mpImpl->getDrawingOntoParent_ref() );
2326 
2327                 sal_Bool bWasVisible = pWindow->IsVisible();
2328                 Point aOldPos( pWindow->GetPosPixel() );
2329 
2330                 if ( bWasVisible && aOldPos == aPos )
2331                 {
2332                     pWindow->Update();
2333                     return;
2334                 }
2335 
2336                 pWindow->SetPosPixel( aPos );
2337 
2338                 // Erstmal ein Update auf den Parent, damit nicht beim Update
2339                 // auf dieses Fenster noch ein Paint vom Parent abgearbeitet wird,
2340                 // wo dann ggf. dieses Fenster sofort wieder gehidet wird.
2341                 if( pWindow->GetParent() )
2342                     pWindow->GetParent()->Update();
2343 
2344                 pWindow->Show();
2345                 pWindow->Update();
2346                 pWindow->SetParentUpdateMode( sal_False );
2347                 pWindow->Hide();
2348                 pWindow->SetParentUpdateMode( sal_True );
2349 
2350                 pWindow->SetPosPixel( aOldPos );
2351                 if ( bWasVisible )
2352                     pWindow->Show( sal_True );
2353             }
2354         }
2355         else if ( pDev )
2356         {
2357             Size aSz = pWindow->GetSizePixel();
2358             aSz = pDev->PixelToLogic( aSz );
2359             Point aP = pDev->PixelToLogic( aPos );
2360 
2361             vcl::PDFExtOutDevData* pPDFExport   = dynamic_cast<vcl::PDFExtOutDevData*>(pDev->GetExtOutDevData());
2362             bool bDrawSimple =    ( pDev->GetOutDevType() == OUTDEV_PRINTER )
2363                                || ( pDev->GetOutDevViewType() == OUTDEV_VIEWTYPE_PRINTPREVIEW )
2364                                || ( pPDFExport != NULL );
2365             if ( bDrawSimple )
2366             {
2367                 pWindow->Draw( pDev, aP, aSz, WINDOW_DRAW_NOCONTROLS );
2368             }
2369             else
2370             {
2371                 sal_Bool bOldNW =pWindow->IsNativeWidgetEnabled();
2372                 if( bOldNW )
2373                     pWindow->EnableNativeWidget(sal_False);
2374                 pWindow->PaintToDevice( pDev, aP, aSz );
2375                 if( bOldNW )
2376                     pWindow->EnableNativeWidget(sal_True);
2377             }
2378         }
2379     }
2380 }
2381 
2382 void VCLXWindow::setZoom( float fZoomX, float /*fZoomY*/ ) throw(::com::sun::star::uno::RuntimeException)
2383 {
2384     ::vos::OGuard aGuard( GetMutex() );
2385 
2386     if ( GetWindow() )
2387     {
2388         // Fraction::Fraction takes a double, but we have a float only.
2389         // The implicit conversion from float to double can result in a precision loss, i.e. 1.2 is converted to
2390         // 1.200000000047something. To prevent this, we convert explicitly to double, and round it.
2391         double nZoom( fZoomX );
2392         nZoom = ::rtl::math::round( nZoom, 4 );
2393         GetWindow()->SetZoom( Fraction( nZoom ) );
2394     }
2395 }
2396 
2397 // ::com::sun::star::lang::XEventListener
2398 void SAL_CALL VCLXWindow::disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException)
2399 {
2400     ::vos::OGuard aGuard( GetMutex() );
2401 
2402     // check if it comes from our AccessibleContext
2403     uno::Reference< uno::XInterface > aAC( mpImpl->mxAccessibleContext, uno::UNO_QUERY );
2404     uno::Reference< uno::XInterface > xSource( _rSource.Source, uno::UNO_QUERY );
2405 
2406     if ( aAC.get() == xSource.get() )
2407     {   // yep, it does
2408         mpImpl->mxAccessibleContext = uno::Reference< accessibility::XAccessibleContext >();
2409     }
2410 }
2411 
2412 // ::com::sun::star::accessibility::XAccessible
2413 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXWindow::getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException)
2414 {
2415     using namespace ::com::sun::star;
2416 
2417     ::vos::OGuard aGuard( GetMutex() );
2418 
2419     // already disposed
2420     if( ! mpImpl )
2421         return uno::Reference< accessibility::XAccessibleContext >();
2422 
2423     if ( !mpImpl->mxAccessibleContext.is() && GetWindow() )
2424     {
2425         mpImpl->mxAccessibleContext = CreateAccessibleContext();
2426 
2427         // add as event listener to this component
2428         // in case somebody disposes it, we do not want to have a (though weak) reference to a dead
2429         // object
2430         uno::Reference< lang::XComponent > xComp( mpImpl->mxAccessibleContext, uno::UNO_QUERY );
2431         if ( xComp.is() )
2432             xComp->addEventListener( this );
2433     }
2434 
2435     return mpImpl->mxAccessibleContext;
2436 }
2437 
2438 // ::com::sun::star::awt::XDockable
2439 void SAL_CALL VCLXWindow::addDockableWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDockableWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
2440 {
2441     ::vos::OGuard aGuard( GetMutex() );
2442 
2443     if ( xListener.is() )
2444         mpImpl->getDockableWindowListeners().addInterface( xListener );
2445 
2446 }
2447 
2448 void SAL_CALL VCLXWindow::removeDockableWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDockableWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
2449 {
2450     ::vos::OGuard aGuard( GetMutex() );
2451 
2452     mpImpl->getDockableWindowListeners().removeInterface( xListener );
2453 }
2454 
2455 void SAL_CALL VCLXWindow::enableDocking( sal_Bool bEnable ) throw (::com::sun::star::uno::RuntimeException)
2456 {
2457     ::vos::OGuard aGuard( GetMutex() );
2458 
2459     Window* pWindow = GetWindow();
2460     if ( pWindow )
2461         pWindow->EnableDocking( bEnable );
2462 }
2463 
2464 sal_Bool SAL_CALL VCLXWindow::isFloating(  ) throw (::com::sun::star::uno::RuntimeException)
2465 {
2466     ::vos::OGuard aGuard( GetMutex() );
2467 
2468     Window* pWindow = GetWindow();
2469     if( pWindow )
2470         return Window::GetDockingManager()->IsFloating( pWindow );
2471     else
2472         return sal_False;
2473 }
2474 
2475 void SAL_CALL VCLXWindow::setFloatingMode( sal_Bool bFloating ) throw (::com::sun::star::uno::RuntimeException)
2476 {
2477     ::vos::OGuard aGuard( GetMutex() );
2478 
2479     Window* pWindow = GetWindow();
2480     if( pWindow )
2481         Window::GetDockingManager()->SetFloatingMode( pWindow, bFloating );
2482 }
2483 
2484 sal_Bool SAL_CALL VCLXWindow::isLocked(  ) throw (::com::sun::star::uno::RuntimeException)
2485 {
2486     ::vos::OGuard aGuard( GetMutex() );
2487 
2488     Window* pWindow = GetWindow();
2489     if( pWindow )
2490         return Window::GetDockingManager()->IsLocked( pWindow );
2491     else
2492         return sal_False;
2493 }
2494 
2495 void SAL_CALL VCLXWindow::lock(  ) throw (::com::sun::star::uno::RuntimeException)
2496 {
2497     ::vos::OGuard aGuard( GetMutex() );
2498 
2499     Window* pWindow = GetWindow();
2500     if( pWindow && !Window::GetDockingManager()->IsFloating( pWindow ) )
2501         Window::GetDockingManager()->Lock( pWindow );
2502 }
2503 
2504 void SAL_CALL VCLXWindow::unlock(  ) throw (::com::sun::star::uno::RuntimeException)
2505 {
2506     ::vos::OGuard aGuard( GetMutex() );
2507 
2508     Window* pWindow = GetWindow();
2509     if( pWindow && !Window::GetDockingManager()->IsFloating( pWindow ) )
2510         Window::GetDockingManager()->Unlock( pWindow );
2511 }
2512 void SAL_CALL VCLXWindow::startPopupMode( const ::com::sun::star::awt::Rectangle& ) throw (::com::sun::star::uno::RuntimeException)
2513 {
2514     // TODO: remove interface in the next incompatible build
2515     ::vos::OGuard aGuard( GetMutex() );
2516 
2517 }
2518 
2519 sal_Bool SAL_CALL VCLXWindow::isInPopupMode(  ) throw (::com::sun::star::uno::RuntimeException)
2520 {
2521     // TODO: remove interface in the next incompatible build
2522     ::vos::OGuard aGuard( GetMutex() );
2523     return sal_False;
2524 }
2525 
2526 
2527 // ::com::sun::star::awt::XWindow2
2528 
2529 void SAL_CALL VCLXWindow::setOutputSize( const ::com::sun::star::awt::Size& aSize ) throw (::com::sun::star::uno::RuntimeException)
2530 {
2531     ::vos::OGuard aGuard( GetMutex() );
2532     Window *pWindow;
2533     if( (pWindow = GetWindow()) != NULL )
2534     {
2535         DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow);
2536         if( pDockingWindow )
2537             pDockingWindow->SetOutputSizePixel( VCLSize( aSize ) );
2538         else
2539             pWindow->SetOutputSizePixel( VCLSize( aSize ) );
2540     }
2541 }
2542 
2543 ::com::sun::star::awt::Size SAL_CALL VCLXWindow::getOutputSize(  ) throw (::com::sun::star::uno::RuntimeException)
2544 {
2545     ::vos::OGuard aGuard( GetMutex() );
2546     Window *pWindow;
2547     if( (pWindow = GetWindow()) != NULL )
2548     {
2549         DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow);
2550         if( pDockingWindow )
2551             return AWTSize( pDockingWindow->GetOutputSizePixel() );
2552         else
2553             return AWTSize( pWindow->GetOutputSizePixel() );
2554     }
2555     else
2556         return ::com::sun::star::awt::Size();
2557 }
2558 
2559 sal_Bool SAL_CALL VCLXWindow::isVisible(  ) throw (::com::sun::star::uno::RuntimeException)
2560 {
2561     ::vos::OGuard aGuard( GetMutex() );
2562     if( GetWindow() )
2563         return GetWindow()->IsVisible();
2564     else
2565         return sal_False;
2566 }
2567 
2568 sal_Bool SAL_CALL VCLXWindow::isActive(  ) throw (::com::sun::star::uno::RuntimeException)
2569 {
2570     ::vos::OGuard aGuard( GetMutex() );
2571     if( GetWindow() )
2572         return GetWindow()->IsActive();
2573     else
2574         return sal_False;
2575 
2576 }
2577 
2578 sal_Bool SAL_CALL VCLXWindow::isEnabled(  ) throw (::com::sun::star::uno::RuntimeException)
2579 {
2580     ::vos::OGuard aGuard( GetMutex() );
2581     if( GetWindow() )
2582         return GetWindow()->IsEnabled();
2583     else
2584         return sal_False;
2585 }
2586 
2587 sal_Bool SAL_CALL VCLXWindow::hasFocus(  ) throw (::com::sun::star::uno::RuntimeException)
2588 {
2589     ::vos::OGuard aGuard( GetMutex() );
2590     if( GetWindow() )
2591         return GetWindow()->HasFocus();
2592     else
2593         return sal_False;
2594 }
2595 
2596 // ::com::sun::star::beans::XPropertySetInfo
2597 
2598 UnoPropertyArrayHelper *
2599 VCLXWindow::GetPropHelper()
2600 {
2601     ::vos::OGuard aGuard( GetMutex() );
2602     if ( mpImpl->mpPropHelper == NULL )
2603     {
2604         std::list< sal_uInt16 > aIDs;
2605         GetPropertyIds( aIDs );
2606         mpImpl->mpPropHelper = new UnoPropertyArrayHelper( aIDs );
2607     }
2608     return mpImpl->mpPropHelper;
2609 }
2610 
2611 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL
2612 VCLXWindow::getProperties() throw (::com::sun::star::uno::RuntimeException)
2613 {
2614     return GetPropHelper()->getProperties();
2615 }
2616 ::com::sun::star::beans::Property SAL_CALL
2617 VCLXWindow::getPropertyByName( const ::rtl::OUString& rName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
2618 {
2619     return GetPropHelper()->getPropertyByName( rName );
2620 }
2621 
2622 ::sal_Bool SAL_CALL
2623 VCLXWindow::hasPropertyByName( const ::rtl::OUString& rName ) throw (::com::sun::star::uno::RuntimeException)
2624 {
2625     return GetPropHelper()->hasPropertyByName( rName );
2626 }
2627 
2628 Reference< XStyleSettings > SAL_CALL VCLXWindow::getStyleSettings() throw (RuntimeException)
2629 {
2630     return mpImpl->getStyleSettings();
2631 }
2632