bump product version to 6.3.0.0.beta1
[LibreOffice.git] / toolkit / source / awt / vclxwindow.cxx
blob27d06f564c348ecd6c68a54bb23493384ef656d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <stdarg.h>
22 #include <memory>
23 #include <com/sun/star/awt/WindowEvent.hpp>
24 #include <com/sun/star/awt/KeyEvent.hpp>
25 #include <com/sun/star/awt/KeyModifier.hpp>
26 #include <com/sun/star/awt/MouseEvent.hpp>
27 #include <com/sun/star/awt/MouseButton.hpp>
28 #include <com/sun/star/awt/MouseWheelBehavior.hpp>
29 #include <com/sun/star/awt/XTopWindow.hpp>
30 #include <com/sun/star/awt/Style.hpp>
31 #include <com/sun/star/accessibility/AccessibleRole.hpp>
32 #include <com/sun/star/awt/DockingEvent.hpp>
33 #include <com/sun/star/awt/EndDockingEvent.hpp>
34 #include <com/sun/star/awt/EndPopupModeEvent.hpp>
35 #include <com/sun/star/awt/XWindowListener2.hpp>
36 #include <com/sun/star/style/VerticalAlignment.hpp>
37 #include <com/sun/star/lang/DisposedException.hpp>
38 #include <com/sun/star/text/WritingMode2.hpp>
39 #include <toolkit/awt/vclxwindow.hxx>
40 #include <toolkit/awt/vclxpointer.hxx>
41 #include <toolkit/awt/vclxwindows.hxx>
42 #include <toolkit/helper/macros.hxx>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <toolkit/helper/convert.hxx>
45 #include <toolkit/helper/property.hxx>
46 #include <cppuhelper/typeprovider.hxx>
47 #include <rtl/uuid.h>
48 #include <rtl/ustrbuf.hxx>
49 #include <sal/log.hxx>
50 #include <vcl/svapp.hxx>
51 #include <vcl/window.hxx>
52 #include <tools/color.hxx>
53 #include <tools/fract.hxx>
54 #include <tools/debug.hxx>
55 #include <vcl/event.hxx>
56 #include <vcl/dockwin.hxx>
57 #include <vcl/pdfextoutdevdata.hxx>
58 #include <vcl/tabpage.hxx>
59 #include <vcl/button.hxx>
60 #include <vcl/settings.hxx>
61 #include <vcl/commandevent.hxx>
62 #include <comphelper/asyncnotification.hxx>
63 #include <comphelper/flagguard.hxx>
64 #include <comphelper/interfacecontainer2.hxx>
65 #include <comphelper/profilezone.hxx>
66 #include "stylesettings.hxx"
67 #include <tools/urlobj.hxx>
69 #include <helper/accessibilityclient.hxx>
70 #include <helper/unopropertyarrayhelper.hxx>
72 using namespace ::com::sun::star;
74 using ::com::sun::star::uno::Reference;
75 using ::com::sun::star::uno::UNO_QUERY;
76 using ::com::sun::star::uno::RuntimeException;
77 using ::com::sun::star::lang::EventObject;
78 using ::com::sun::star::awt::XWindowListener2;
79 using ::com::sun::star::awt::XDockableWindowListener;
80 using ::com::sun::star::awt::XDevice;
81 using ::com::sun::star::awt::XStyleSettings;
82 using ::com::sun::star::lang::DisposedException;
83 using ::com::sun::star::style::VerticalAlignment;
84 using ::com::sun::star::style::VerticalAlignment_TOP;
85 using ::com::sun::star::style::VerticalAlignment_MIDDLE;
86 using ::com::sun::star::style::VerticalAlignment_BOTTOM;
88 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
91 //= VCLXWindowImpl
93 class VCLXWindowImpl
95 private:
96 typedef ::std::vector< VCLXWindow::Callback > CallbackArray;
98 private:
99 VCLXWindow& mrAntiImpl;
100 ::toolkit::AccessibilityClient maAccFactory;
101 bool mbDisposed;
102 bool mbDrawingOntoParent; // no bit mask, is passed around by reference
103 bool mbEnableVisible;
104 bool mbDirectVisible;
106 ::osl::Mutex maListenerContainerMutex;
107 ::comphelper::OInterfaceContainerHelper2 maWindow2Listeners;
108 ::comphelper::OInterfaceContainerHelper2 maDockableWindowListeners;
109 EventListenerMultiplexer maEventListeners;
110 FocusListenerMultiplexer maFocusListeners;
111 WindowListenerMultiplexer maWindowListeners;
112 KeyListenerMultiplexer maKeyListeners;
113 MouseListenerMultiplexer maMouseListeners;
114 MouseMotionListenerMultiplexer maMouseMotionListeners;
115 PaintListenerMultiplexer maPaintListeners;
116 VclContainerListenerMultiplexer maContainerListeners;
117 TopWindowListenerMultiplexer maTopWindowListeners;
119 CallbackArray maCallbackEvents;
120 ImplSVEvent * mnCallbackEventId;
122 public:
123 bool mbDisposing : 1;
124 bool mbDesignMode : 1;
125 bool mbSynthesizingVCLEvent : 1;
126 bool const mbWithDefaultProps : 1;
128 sal_uLong mnListenerLockLevel;
129 sal_Int16 mnWritingMode;
130 sal_Int16 mnContextWritingMode;
132 std::unique_ptr<UnoPropertyArrayHelper>
133 mpPropHelper;
135 css::uno::Reference< css::accessibility::XAccessibleContext >
136 mxAccessibleContext;
137 css::uno::Reference< css::awt::XGraphics >
138 mxViewGraphics;
139 css::uno::Reference< css::awt::XStyleSettings >
140 mxWindowStyleSettings;
142 public:
143 bool& getDrawingOntoParent_ref() { return mbDrawingOntoParent; }
145 public:
146 /** ctor
147 @param _pAntiImpl
148 the <type>VCLXWindow</type> instance which the object belongs to. Must
149 live longer then the object just being constructed.
151 VCLXWindowImpl( VCLXWindow& _rAntiImpl, bool _bWithDefaultProps );
153 VCLXWindowImpl( const VCLXWindowImpl& ) = delete;
154 const VCLXWindowImpl& operator=(const VCLXWindowImpl&) = delete;
156 /** synchronously mbEnableVisible
158 void setEnableVisible( bool bEnableVisible ) { mbEnableVisible = bEnableVisible; }
159 bool isEnableVisible() { return mbEnableVisible; }
160 /** synchronously mbDirectVisible;
162 void setDirectVisible( bool bDirectVisible ) { mbDirectVisible = bDirectVisible; }
163 bool isDirectVisible() { return mbDirectVisible; }
165 /** impl-version of VCLXWindow::ImplExecuteAsyncWithoutSolarLock
167 void callBackAsync( const VCLXWindow::Callback& i_callback );
169 /** notifies the object that its VCLXWindow is being disposed
171 void disposing();
173 ::toolkit::AccessibilityClient& getAccessibleFactory()
175 return maAccFactory;
178 Reference< XStyleSettings > getStyleSettings();
180 /** returns the container of registered XWindowListener2 listeners
182 ::comphelper::OInterfaceContainerHelper2& getWindow2Listeners() { return maWindow2Listeners; }
183 ::comphelper::OInterfaceContainerHelper2& getDockableWindowListeners(){ return maDockableWindowListeners; }
184 EventListenerMultiplexer& getEventListeners() { return maEventListeners; }
185 FocusListenerMultiplexer& getFocusListeners() { return maFocusListeners; }
186 WindowListenerMultiplexer& getWindowListeners() { return maWindowListeners; }
187 KeyListenerMultiplexer& getKeyListeners() { return maKeyListeners; }
188 MouseListenerMultiplexer& getMouseListeners() { return maMouseListeners; }
189 MouseMotionListenerMultiplexer& getMouseMotionListeners() { return maMouseMotionListeners; }
190 PaintListenerMultiplexer& getPaintListeners() { return maPaintListeners; }
191 VclContainerListenerMultiplexer& getContainerListeners() { return maContainerListeners; }
192 TopWindowListenerMultiplexer& getTopWindowListeners() { return maTopWindowListeners; }
194 private:
195 DECL_LINK( OnProcessCallbacks, void*, void );
199 VCLXWindowImpl::VCLXWindowImpl( VCLXWindow& _rAntiImpl, bool _bWithDefaultProps )
200 :mrAntiImpl( _rAntiImpl )
201 ,mbDisposed( false )
202 ,mbDrawingOntoParent( false )
203 ,mbEnableVisible(true)
204 ,mbDirectVisible(true)
205 ,maListenerContainerMutex( )
206 ,maWindow2Listeners( maListenerContainerMutex )
207 ,maDockableWindowListeners( maListenerContainerMutex )
208 ,maEventListeners( _rAntiImpl )
209 ,maFocusListeners( _rAntiImpl )
210 ,maWindowListeners( _rAntiImpl )
211 ,maKeyListeners( _rAntiImpl )
212 ,maMouseListeners( _rAntiImpl )
213 ,maMouseMotionListeners( _rAntiImpl )
214 ,maPaintListeners( _rAntiImpl )
215 ,maContainerListeners( _rAntiImpl )
216 ,maTopWindowListeners( _rAntiImpl )
217 ,mnCallbackEventId( nullptr )
218 ,mbDisposing( false )
219 ,mbDesignMode( false )
220 ,mbSynthesizingVCLEvent( false )
221 ,mbWithDefaultProps( _bWithDefaultProps )
222 ,mnListenerLockLevel( 0 )
223 ,mnWritingMode( WritingMode2::CONTEXT )
224 ,mnContextWritingMode( WritingMode2::CONTEXT )
228 void VCLXWindowImpl::disposing()
230 SolarMutexGuard aGuard;
231 if ( mnCallbackEventId )
232 Application::RemoveUserEvent( mnCallbackEventId );
233 mnCallbackEventId = nullptr;
235 mbDisposed= true;
237 css::lang::EventObject aEvent;
238 aEvent.Source = mrAntiImpl;
240 maDockableWindowListeners.disposeAndClear( aEvent );
241 maEventListeners.disposeAndClear( aEvent );
242 maFocusListeners.disposeAndClear( aEvent );
243 maWindowListeners.disposeAndClear( aEvent );
244 maKeyListeners.disposeAndClear( aEvent );
245 maMouseListeners.disposeAndClear( aEvent );
246 maMouseMotionListeners.disposeAndClear( aEvent );
247 maPaintListeners.disposeAndClear( aEvent );
248 maContainerListeners.disposeAndClear( aEvent );
249 maTopWindowListeners.disposeAndClear( aEvent );
251 ::toolkit::WindowStyleSettings* pStyleSettings = static_cast< ::toolkit::WindowStyleSettings* >( mxWindowStyleSettings.get() );
252 if ( pStyleSettings != nullptr )
253 pStyleSettings->dispose();
254 mxWindowStyleSettings.clear();
258 void VCLXWindowImpl::callBackAsync( const VCLXWindow::Callback& i_callback )
260 DBG_TESTSOLARMUTEX();
261 maCallbackEvents.push_back( i_callback );
262 if ( !mnCallbackEventId )
264 // ensure our VCLXWindow is not destroyed while the event is underway
265 mrAntiImpl.acquire();
266 mnCallbackEventId = Application::PostUserEvent( LINK( this, VCLXWindowImpl, OnProcessCallbacks ) );
271 IMPL_LINK_NOARG(VCLXWindowImpl, OnProcessCallbacks, void*, void)
273 const Reference< uno::XInterface > xKeepAlive( mrAntiImpl );
275 SAL_INFO("toolkit.controls", "OnProcessCallbacks grabbing solarmutex");
277 // work on a copy of the callback array
278 CallbackArray aCallbacksCopy;
280 SolarMutexGuard aGuard;
281 aCallbacksCopy = maCallbackEvents;
282 maCallbackEvents.clear();
284 // we acquired our VCLXWindow once before posting the event, release this one ref now
285 mrAntiImpl.release();
287 if ( !mnCallbackEventId )
288 // we were disposed while waiting for the mutex to lock
289 return;
291 mnCallbackEventId = nullptr;
295 SAL_INFO("toolkit.controls", "OnProcessCallbacks relinquished solarmutex");
296 SolarMutexReleaser aReleaseSolar;
297 for (const auto& rCallback : aCallbacksCopy)
299 rCallback();
304 Reference< XStyleSettings > VCLXWindowImpl::getStyleSettings()
306 SolarMutexGuard aGuard;
307 if ( mbDisposed )
308 throw DisposedException( OUString(), mrAntiImpl );
309 if ( !mxWindowStyleSettings.is() )
310 mxWindowStyleSettings = new ::toolkit::WindowStyleSettings( maListenerContainerMutex, mrAntiImpl );
311 return mxWindowStyleSettings;
315 // Uses an out-parameter instead of return value, due to the object reference
317 static void ImplInitWindowEvent( css::awt::WindowEvent& rEvent, vcl::Window const * pWindow )
319 Point aPos = pWindow->GetPosPixel();
320 Size aSz = pWindow->GetSizePixel();
322 rEvent.X = aPos.X();
323 rEvent.Y = aPos.Y();
325 rEvent.Width = aSz.Width();
326 rEvent.Height = aSz.Height();
328 pWindow->GetBorder( rEvent.LeftInset, rEvent.TopInset, rEvent.RightInset, rEvent.BottomInset );
331 VCLXWindow::VCLXWindow( bool _bWithDefaultProps )
333 mpImpl.reset( new VCLXWindowImpl( *this, _bWithDefaultProps ) );
336 VCLXWindow::~VCLXWindow()
338 mpImpl.reset();
340 if ( GetWindow() )
342 GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) );
343 GetWindow()->SetWindowPeer( nullptr, nullptr );
344 GetWindow()->SetAccessible( nullptr );
349 void VCLXWindow::ImplExecuteAsyncWithoutSolarLock( const Callback& i_callback )
351 mpImpl->callBackAsync( i_callback );
355 ::toolkit::IAccessibleFactory& VCLXWindow::getAccessibleFactory()
357 return mpImpl->getAccessibleFactory().getFactory();
360 void VCLXWindow::SetWindow( const VclPtr<vcl::Window> &pWindow )
362 if ( GetWindow() )
364 GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) );
365 // GetWindow()->DbgAssertNoEventListeners();
368 SetOutputDevice( pWindow );
370 if ( GetWindow() )
372 GetWindow()->AddEventListener( LINK( this, VCLXWindow, WindowEventListener ) );
373 bool bDirectVisible = pWindow && pWindow->IsVisible();
374 mpImpl->setDirectVisible( bDirectVisible );
378 void VCLXWindow::suspendVclEventListening( )
380 ++mpImpl->mnListenerLockLevel;
383 void VCLXWindow::resumeVclEventListening( )
385 DBG_ASSERT( mpImpl->mnListenerLockLevel, "VCLXWindow::resumeVclEventListening: not suspended!" );
386 --mpImpl->mnListenerLockLevel;
389 void VCLXWindow::notifyWindowRemoved( vcl::Window const & _rWindow )
391 if ( mpImpl->getContainerListeners().getLength() )
393 awt::VclContainerEvent aEvent;
394 aEvent.Source = *this;
395 aEvent.Child = static_cast< XWindow* >( _rWindow.GetWindowPeer() );
396 mpImpl->getContainerListeners().windowRemoved( aEvent );
400 IMPL_LINK( VCLXWindow, WindowEventListener, VclWindowEvent&, rEvent, void )
402 if ( mpImpl->mnListenerLockLevel )
403 return;
405 DBG_ASSERT( rEvent.GetWindow() && GetWindow(), "Window???" );
406 ProcessWindowEvent( rEvent );
409 namespace
411 struct CallWindow2Listener
413 CallWindow2Listener( ::comphelper::OInterfaceContainerHelper2& i_rWindow2Listeners, const bool i_bEnabled, const EventObject& i_rEvent )
414 :m_rWindow2Listeners( i_rWindow2Listeners )
415 ,m_bEnabled( i_bEnabled )
416 ,m_aEvent( i_rEvent )
420 void operator()()
422 m_rWindow2Listeners.notifyEach( m_bEnabled ? &XWindowListener2::windowEnabled : &XWindowListener2::windowDisabled, m_aEvent );
425 ::comphelper::OInterfaceContainerHelper2& m_rWindow2Listeners;
426 const bool m_bEnabled;
427 const EventObject m_aEvent;
431 void VCLXWindow::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
433 css::uno::Reference< css::uno::XInterface > xThis( static_cast<cppu::OWeakObject*>(this) );
435 switch ( rVclWindowEvent.GetId() )
437 case VclEventId::WindowEnabled:
438 case VclEventId::WindowDisabled:
440 Callback aCallback = CallWindow2Listener(
441 mpImpl->getWindow2Listeners(),
442 ( VclEventId::WindowEnabled == rVclWindowEvent.GetId() ),
443 EventObject( *this )
445 ImplExecuteAsyncWithoutSolarLock( aCallback );
447 break;
449 case VclEventId::WindowPaint:
451 if ( mpImpl->getPaintListeners().getLength() )
453 css::awt::PaintEvent aEvent;
454 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
455 aEvent.UpdateRect = AWTRectangle( *static_cast<tools::Rectangle*>(rVclWindowEvent.GetData()) );
456 aEvent.Count = 0;
457 mpImpl->getPaintListeners().windowPaint( aEvent );
460 break;
461 case VclEventId::WindowMove:
463 if ( mpImpl->getWindowListeners().getLength() )
465 css::awt::WindowEvent aEvent;
466 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
467 ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() );
468 mpImpl->getWindowListeners().windowMoved( aEvent );
471 break;
472 case VclEventId::WindowResize:
474 if ( mpImpl->getWindowListeners().getLength() )
476 css::awt::WindowEvent aEvent;
477 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
478 ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() );
479 mpImpl->getWindowListeners().windowResized( aEvent );
482 break;
483 case VclEventId::WindowShow:
485 if ( mpImpl->getWindowListeners().getLength() )
487 css::awt::WindowEvent aEvent;
488 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
489 ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() );
490 mpImpl->getWindowListeners().windowShown( aEvent );
493 // For TopWindows this means opened...
494 if ( mpImpl->getTopWindowListeners().getLength() )
496 css::lang::EventObject aEvent;
497 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
498 mpImpl->getTopWindowListeners().windowOpened( aEvent );
501 break;
502 case VclEventId::WindowHide:
504 if ( mpImpl->getWindowListeners().getLength() )
506 css::awt::WindowEvent aEvent;
507 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
508 ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() );
509 mpImpl->getWindowListeners().windowHidden( aEvent );
512 // For TopWindows this means closed...
513 if ( mpImpl->getTopWindowListeners().getLength() )
515 css::lang::EventObject aEvent;
516 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
517 mpImpl->getTopWindowListeners().windowClosed( aEvent );
520 break;
521 case VclEventId::WindowActivate:
522 case VclEventId::WindowDeactivate:
524 if (!mpImpl->getTopWindowListeners().getLength())
525 return;
527 // Suppress events which are unlikely to be interesting to our listeners.
528 vcl::Window* pWin = static_cast<vcl::Window*>(rVclWindowEvent.GetData());
529 bool bSuppress = false;
531 while (pWin)
533 // Either the event came from the same window, from its
534 // child, or from a child of its border window (e.g.
535 // menubar or notebookbar).
536 if (pWin->GetWindow(GetWindowType::Client) == GetWindow())
537 return;
539 if (pWin->IsMenuFloatingWindow())
540 bSuppress = true;
542 if (pWin->GetType() == WindowType::FLOATINGWINDOW &&
543 static_cast<FloatingWindow*>(pWin)->IsInPopupMode())
544 bSuppress = true;
546 // Otherwise, don't suppress if the event came from a different frame.
547 if (!bSuppress && pWin->GetWindow(GetWindowType::Frame) == pWin)
548 break;
550 pWin = pWin->GetWindow(GetWindowType::RealParent);
553 css::lang::EventObject aEvent;
554 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
555 if (rVclWindowEvent.GetId() == VclEventId::WindowActivate)
556 mpImpl->getTopWindowListeners().windowActivated( aEvent );
557 else
558 mpImpl->getTopWindowListeners().windowDeactivated( aEvent );
560 break;
561 case VclEventId::WindowClose:
563 if ( mpImpl->getDockableWindowListeners().getLength() )
565 css::lang::EventObject aEvent;
566 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
567 mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::closed, aEvent );
569 if ( mpImpl->getTopWindowListeners().getLength() )
571 css::lang::EventObject aEvent;
572 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
573 mpImpl->getTopWindowListeners().windowClosing( aEvent );
576 break;
577 case VclEventId::ControlGetFocus:
578 case VclEventId::WindowGetFocus:
580 if ( ( rVclWindowEvent.GetWindow()->IsCompoundControl()
581 && rVclWindowEvent.GetId() == VclEventId::ControlGetFocus
583 || ( !rVclWindowEvent.GetWindow()->IsCompoundControl()
584 && rVclWindowEvent.GetId() == VclEventId::WindowGetFocus
588 if ( mpImpl->getFocusListeners().getLength() )
590 css::awt::FocusEvent aEvent;
591 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
592 aEvent.FocusFlags = static_cast<sal_Int16>(rVclWindowEvent.GetWindow()->GetGetFocusFlags());
593 aEvent.Temporary = false;
594 mpImpl->getFocusListeners().focusGained( aEvent );
598 break;
599 case VclEventId::ControlLoseFocus:
600 case VclEventId::WindowLoseFocus:
602 if ( ( rVclWindowEvent.GetWindow()->IsCompoundControl()
603 && rVclWindowEvent.GetId() == VclEventId::ControlLoseFocus
605 || ( !rVclWindowEvent.GetWindow()->IsCompoundControl()
606 && rVclWindowEvent.GetId() == VclEventId::WindowLoseFocus
610 if ( mpImpl->getFocusListeners().getLength() )
612 css::awt::FocusEvent aEvent;
613 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
614 aEvent.FocusFlags = static_cast<sal_Int16>(rVclWindowEvent.GetWindow()->GetGetFocusFlags());
615 aEvent.Temporary = false;
617 vcl::Window* pNext = Application::GetFocusWindow();
618 if ( pNext )
620 // Don't care about internals if this control is compound
621 vcl::Window* pNextC = pNext;
622 while ( pNextC && !pNextC->IsCompoundControl() )
623 pNextC = pNextC->GetParent();
624 if ( pNextC )
625 pNext = pNextC;
627 pNext->GetComponentInterface();
628 aEvent.NextFocus = static_cast<cppu::OWeakObject*>(pNext->GetWindowPeer());
630 mpImpl->getFocusListeners().focusLost( aEvent );
634 break;
635 case VclEventId::WindowMinimize:
637 if ( mpImpl->getTopWindowListeners().getLength() )
639 css::lang::EventObject aEvent;
640 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
641 mpImpl->getTopWindowListeners().windowMinimized( aEvent );
644 break;
645 case VclEventId::WindowNormalize:
647 if ( mpImpl->getTopWindowListeners().getLength() )
649 css::lang::EventObject aEvent;
650 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
651 mpImpl->getTopWindowListeners().windowNormalized( aEvent );
654 break;
655 case VclEventId::WindowKeyInput:
656 case VclEventId::WindowKeyUp:
658 VclPtr<vcl::Window> pWin = GetWindow();
659 while (pWin)
661 VCLXWindow* pXWindow = pWin->GetWindowPeer();
662 if (!pXWindow || pXWindow->mpImpl->getKeyListeners().getLength() == 0)
664 pWin = pWin->GetWindow(GetWindowType::RealParent);
665 continue;
668 awt::KeyEvent aEvent(VCLUnoHelper::createKeyEvent(
669 *static_cast<KeyEvent*>(rVclWindowEvent.GetData()), *this));
670 if (rVclWindowEvent.GetId() == VclEventId::WindowKeyInput)
671 pXWindow->mpImpl->getKeyListeners().keyPressed(aEvent);
672 else
673 pXWindow->mpImpl->getKeyListeners().keyReleased(aEvent);
675 // Next window (parent)
676 pWin = pWin->GetWindow(GetWindowType::RealParent);
679 break;
680 case VclEventId::WindowCommand:
682 CommandEvent* pCmdEvt = static_cast<CommandEvent*>(rVclWindowEvent.GetData());
683 if ( mpImpl->getMouseListeners().getLength() && ( pCmdEvt->GetCommand() == CommandEventId::ContextMenu ) )
685 // CommandEventId::ContextMenu: send as mousePressed with PopupTrigger = true ...
686 Point aWhere = static_cast< CommandEvent* >( rVclWindowEvent.GetData() )->GetMousePosPixel();
687 if ( !pCmdEvt->IsMouseEvent() )
688 { // for keyboard events, we set the coordinates to -1,-1. This is a slight HACK, but the current API
689 // handles a context menu command as special case of a mouse event, which is simply wrong.
690 // Without extending the API, we would not have another chance to notify listeners of a
691 // keyboard-triggered context menu request
692 aWhere = Point( -1, -1 );
695 MouseEvent aMEvt( aWhere, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT, 0 );
696 awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( aMEvt, *this ) );
697 aEvent.PopupTrigger = true;
699 Callback aCallback = [ this, aEvent ]()
700 { this->mpImpl->getMouseListeners().mousePressed( aEvent ); };
702 ImplExecuteAsyncWithoutSolarLock( aCallback );
705 break;
706 case VclEventId::WindowMouseMove:
708 MouseEvent* pMouseEvt = static_cast<MouseEvent*>(rVclWindowEvent.GetData());
709 VclPtr<vcl::Window> pWin = GetWindow();
710 while (pWin)
712 VCLXWindow* pXWindow = pWin->GetWindowPeer();
713 if (!pXWindow || pXWindow->mpImpl->getMouseListeners().getLength() == 0)
715 pWin = pWin->GetWindow(GetWindowType::RealParent);
716 continue;
718 awt::MouseEvent aEvent(VCLUnoHelper::createMouseEvent(*pMouseEvt, *pXWindow));
720 if (pMouseEvt->IsEnterWindow() || pMouseEvt->IsLeaveWindow())
722 bool const isEnter(pMouseEvt->IsEnterWindow());
723 Callback aCallback = [pXWindow, isEnter, aEvent]() {
724 isEnter ? pXWindow->mpImpl->getMouseListeners().mouseEntered(aEvent)
725 : pXWindow->mpImpl->getMouseListeners().mouseExited(aEvent);
727 ImplExecuteAsyncWithoutSolarLock(aCallback);
729 else
731 aEvent.ClickCount = 0;
732 MouseMotionListenerMultiplexer& rMouseListeners
733 = pXWindow->mpImpl->getMouseMotionListeners();
734 if (pMouseEvt->GetMode() & MouseEventModifiers::SIMPLEMOVE)
735 rMouseListeners.mouseMoved(aEvent);
736 else
737 rMouseListeners.mouseDragged(aEvent);
740 // Next window (parent)
741 pWin = pWin->GetWindow(GetWindowType::RealParent);
744 break;
745 case VclEventId::WindowMouseButtonDown:
746 case VclEventId::WindowMouseButtonUp:
748 VclPtr<vcl::Window> pWin = GetWindow();
749 while (pWin)
751 VCLXWindow* pXWindow = pWin->GetWindowPeer();
752 if (!pXWindow || pXWindow->mpImpl->getMouseListeners().getLength() == 0)
754 pWin = pWin->GetWindow(GetWindowType::RealParent);
755 continue;
757 MouseEvent* pMouseEvt = static_cast<MouseEvent*>(rVclWindowEvent.GetData());
758 awt::MouseEvent aEvent(VCLUnoHelper::createMouseEvent(*pMouseEvt, *pXWindow));
759 VclEventId eventId = rVclWindowEvent.GetId();
760 Callback aCallback = [pXWindow, aEvent, eventId]() {
761 eventId == VclEventId::WindowMouseButtonDown
762 ? pXWindow->mpImpl->getMouseListeners().mousePressed(aEvent)
763 : pXWindow->mpImpl->getMouseListeners().mouseReleased(aEvent);
765 ImplExecuteAsyncWithoutSolarLock(aCallback);
767 // Next window (parent)
768 pWin = pWin->GetWindow(GetWindowType::RealParent);
771 break;
772 case VclEventId::WindowStartDocking:
774 if ( mpImpl->getDockableWindowListeners().getLength() )
776 DockingData *pData = static_cast<DockingData*>(rVclWindowEvent.GetData());
778 if( pData )
780 css::awt::DockingEvent aEvent;
781 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
782 aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect );
783 aEvent.MousePos.X = pData->maMousePos.X();
784 aEvent.MousePos.Y = pData->maMousePos.Y();
785 aEvent.bLiveMode = false;
786 aEvent.bInteractive = true;
788 mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::startDocking, aEvent );
792 break;
793 case VclEventId::WindowDocking:
795 if ( mpImpl->getDockableWindowListeners().getLength() )
797 DockingData *pData = static_cast<DockingData*>(rVclWindowEvent.GetData());
799 if( pData )
801 css::awt::DockingEvent aEvent;
802 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
803 aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect );
804 aEvent.MousePos.X = pData->maMousePos.X();
805 aEvent.MousePos.Y = pData->maMousePos.Y();
806 aEvent.bLiveMode = false;
807 aEvent.bInteractive = true;
809 Reference< XDockableWindowListener > xFirstListener;
810 ::comphelper::OInterfaceIteratorHelper2 aIter( mpImpl->getDockableWindowListeners() );
811 while ( aIter.hasMoreElements() && !xFirstListener.is() )
813 xFirstListener.set( aIter.next(), UNO_QUERY );
816 css::awt::DockingData aDockingData =
817 xFirstListener->docking( aEvent );
818 pData->maTrackRect = VCLRectangle( aDockingData.TrackingRectangle );
819 pData->mbFloating = aDockingData.bFloating;
823 break;
824 case VclEventId::WindowEndDocking:
826 if ( mpImpl->getDockableWindowListeners().getLength() )
828 EndDockingData *pData = static_cast<EndDockingData*>(rVclWindowEvent.GetData());
830 if( pData )
832 css::awt::EndDockingEvent aEvent;
833 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
834 aEvent.WindowRectangle = AWTRectangle( pData->maWindowRect );
835 aEvent.bFloating = pData->mbFloating;
836 aEvent.bCancelled = pData->mbCancelled;
837 mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endDocking, aEvent );
841 break;
842 case VclEventId::WindowPrepareToggleFloating:
844 if ( mpImpl->getDockableWindowListeners().getLength() )
846 sal_Bool *p_bFloating = static_cast<sal_Bool*>(rVclWindowEvent.GetData());
848 css::lang::EventObject aEvent;
849 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
851 Reference< XDockableWindowListener > xFirstListener;
852 ::comphelper::OInterfaceIteratorHelper2 aIter( mpImpl->getDockableWindowListeners() );
853 while ( aIter.hasMoreElements() && !xFirstListener.is() )
855 xFirstListener.set( aIter.next(), UNO_QUERY );
858 *p_bFloating = xFirstListener->prepareToggleFloatingMode( aEvent );
861 break;
862 case VclEventId::WindowToggleFloating:
864 if ( mpImpl->getDockableWindowListeners().getLength() )
866 css::lang::EventObject aEvent;
867 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
868 mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::toggleFloatingMode, aEvent );
871 break;
872 case VclEventId::WindowEndPopupMode:
874 if ( mpImpl->getDockableWindowListeners().getLength() )
876 EndPopupModeData *pData = static_cast<EndPopupModeData*>(rVclWindowEvent.GetData());
878 if( pData )
880 css::awt::EndPopupModeEvent aEvent;
881 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
882 aEvent.FloatingPosition.X = pData->maFloatingPos.X();
883 aEvent.FloatingPosition.Y = pData->maFloatingPos.Y();
884 aEvent.bTearoff = pData->mbTearoff;
885 mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endPopupMode, aEvent );
889 break;
890 default: break;
894 uno::Reference< accessibility::XAccessibleContext > VCLXWindow::CreateAccessibleContext()
896 SolarMutexGuard aGuard;
897 return getAccessibleFactory().createAccessibleContext( this );
900 void VCLXWindow::SetSynthesizingVCLEvent( bool _b )
902 mpImpl->mbSynthesizingVCLEvent = _b;
905 bool VCLXWindow::IsSynthesizingVCLEvent() const
907 return mpImpl->mbSynthesizingVCLEvent;
910 Size VCLXWindow::ImplCalcWindowSize( const Size& rOutSz ) const
912 Size aSz = rOutSz;
914 VclPtr<vcl::Window> pWindow = GetWindow();
915 if ( pWindow )
917 sal_Int32 nLeft, nTop, nRight, nBottom;
918 pWindow->GetBorder( nLeft, nTop, nRight, nBottom );
919 aSz.AdjustWidth(nLeft+nRight );
920 aSz.AdjustHeight(nTop+nBottom );
922 return aSz;
926 // css::lang::XUnoTunnel
927 sal_Int64 VCLXWindow::getSomething( const css::uno::Sequence< sal_Int8 >& rIdentifier )
929 if( ( rIdentifier.getLength() == 16 ) && ( 0 == memcmp( VCLXWindow::GetUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 ) ) )
931 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(this));
933 return VCLXDevice::getSomething( rIdentifier );
935 namespace
937 class theVCLXWindowUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theVCLXWindowUnoTunnelId> {};
939 const css::uno::Sequence< sal_Int8 >& VCLXWindow::GetUnoTunnelId() throw()
941 return theVCLXWindowUnoTunnelId::get().getSeq();
943 VCLXWindow* VCLXWindow::GetImplementation( const css::uno::Reference< css::uno::XInterface >& rxIFace )
945 css::uno::Reference< css::lang::XUnoTunnel > xUT( rxIFace, css::uno::UNO_QUERY );
946 return xUT.is() ? reinterpret_cast<VCLXWindow*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( VCLXWindow::GetUnoTunnelId() ))) : nullptr;
950 // css::lang::Component
951 void VCLXWindow::dispose( )
953 SolarMutexGuard aGuard;
955 mpImpl->mxViewGraphics = nullptr;
957 if ( !mpImpl->mbDisposing )
959 mpImpl->mbDisposing = true;
961 mpImpl->disposing();
963 if ( GetWindow() )
965 VclPtr<OutputDevice> pOutDev = GetOutputDevice();
966 SetWindow( nullptr ); // so that handlers are logged off, if necessary (virtual)
967 SetOutputDevice( nullptr );
968 pOutDev.disposeAndClear();
971 // #i14103# dispose the accessible context after the window has been destroyed,
972 // otherwise the old value in the child event fired in VCLXAccessibleComponent::ProcessWindowEvent()
973 // for VclEventId::WindowChildDestroyed contains a reference to an already disposed accessible object
976 css::uno::Reference< css::lang::XComponent > xComponent( mpImpl->mxAccessibleContext, css::uno::UNO_QUERY );
977 if ( xComponent.is() )
978 xComponent->dispose();
980 catch ( const css::uno::Exception& )
982 OSL_FAIL( "VCLXWindow::dispose: could not dispose the accessible context!" );
984 mpImpl->mxAccessibleContext.clear();
986 mpImpl->mbDisposing = false;
990 void VCLXWindow::addEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener )
992 SolarMutexGuard aGuard;
994 mpImpl->getEventListeners().addInterface( rxListener );
997 void VCLXWindow::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener )
999 SolarMutexGuard aGuard;
1001 mpImpl->getEventListeners().removeInterface( rxListener );
1005 // css::awt::XWindow
1006 void VCLXWindow::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags )
1008 SolarMutexGuard aGuard;
1009 comphelper::ProfileZone aZone("setPosSize");
1011 if ( GetWindow() )
1013 if( vcl::Window::GetDockingManager()->IsDockable( GetWindow() ) )
1014 vcl::Window::GetDockingManager()->SetPosSizePixel( GetWindow() , X, Y, Width, Height, static_cast<PosSizeFlags>(Flags) );
1015 else
1016 GetWindow()->setPosSizePixel( X, Y, Width, Height, static_cast<PosSizeFlags>(Flags) );
1020 css::awt::Rectangle VCLXWindow::getPosSize( )
1022 SolarMutexGuard aGuard;
1024 css::awt::Rectangle aBounds;
1025 if ( GetWindow() )
1027 if( vcl::Window::GetDockingManager()->IsDockable( GetWindow() ) )
1028 aBounds = AWTRectangle( vcl::Window::GetDockingManager()->GetPosSizePixel( GetWindow() ) );
1029 else
1030 aBounds = AWTRectangle( tools::Rectangle( GetWindow()->GetPosPixel(), GetWindow()->GetSizePixel() ) );
1033 return aBounds;
1036 void VCLXWindow::setVisible( sal_Bool bVisible )
1038 SolarMutexGuard aGuard;
1040 VclPtr<vcl::Window> pWindow = GetWindow();
1041 if ( pWindow )
1043 mpImpl->setDirectVisible( bVisible );
1044 pWindow->Show( bVisible && mpImpl->isEnableVisible() );
1048 void VCLXWindow::setEnable( sal_Bool bEnable )
1050 SolarMutexGuard aGuard;
1052 VclPtr<vcl::Window> pWindow = GetWindow();
1053 if ( pWindow )
1055 pWindow->Enable( bEnable, false ); // #95824# without children!
1056 pWindow->EnableInput( bEnable );
1060 void VCLXWindow::setFocus( )
1062 SolarMutexGuard aGuard;
1064 if ( GetWindow() )
1065 GetWindow()->GrabFocus();
1068 void VCLXWindow::addWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rxListener )
1070 SolarMutexGuard aGuard;
1072 mpImpl->getWindowListeners().addInterface( rxListener );
1074 Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY );
1075 if ( xListener2.is() )
1076 mpImpl->getWindow2Listeners().addInterface( xListener2 );
1078 // #100119# Get all resize events, even if height or width 0, or invisible
1079 if ( GetWindow() )
1080 GetWindow()->EnableAllResize();
1083 void VCLXWindow::removeWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rxListener )
1085 SolarMutexGuard aGuard;
1087 Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY );
1088 if ( xListener2.is() )
1089 mpImpl->getWindow2Listeners().removeInterface( xListener2 );
1091 mpImpl->getWindowListeners().removeInterface( rxListener );
1094 void VCLXWindow::addFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rxListener )
1096 SolarMutexGuard aGuard;
1097 mpImpl->getFocusListeners().addInterface( rxListener );
1100 void VCLXWindow::removeFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rxListener )
1102 SolarMutexGuard aGuard;
1103 mpImpl->getFocusListeners().removeInterface( rxListener );
1106 void VCLXWindow::addKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rxListener )
1108 SolarMutexGuard aGuard;
1109 mpImpl->getKeyListeners().addInterface( rxListener );
1112 void VCLXWindow::removeKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rxListener )
1114 SolarMutexGuard aGuard;
1115 mpImpl->getKeyListeners().removeInterface( rxListener );
1118 void VCLXWindow::addMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rxListener )
1120 SolarMutexGuard aGuard;
1121 mpImpl->getMouseListeners().addInterface( rxListener );
1124 void VCLXWindow::removeMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rxListener )
1126 SolarMutexGuard aGuard;
1127 mpImpl->getMouseListeners().removeInterface( rxListener );
1130 void VCLXWindow::addMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rxListener )
1132 SolarMutexGuard aGuard;
1133 mpImpl->getMouseMotionListeners().addInterface( rxListener );
1136 void VCLXWindow::removeMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rxListener )
1138 SolarMutexGuard aGuard;
1139 mpImpl->getMouseMotionListeners().removeInterface( rxListener );
1142 void VCLXWindow::addPaintListener( const css::uno::Reference< css::awt::XPaintListener >& rxListener )
1144 SolarMutexGuard aGuard;
1145 mpImpl->getPaintListeners().addInterface( rxListener );
1148 void VCLXWindow::removePaintListener( const css::uno::Reference< css::awt::XPaintListener >& rxListener )
1150 SolarMutexGuard aGuard;
1151 mpImpl->getPaintListeners().removeInterface( rxListener );
1154 // css::awt::XWindowPeer
1155 css::uno::Reference< css::awt::XToolkit > VCLXWindow::getToolkit( )
1157 // no guard. nothing to guard here.
1158 // 82463 - 12/21/00 - fs
1159 return Application::GetVCLToolkit();
1162 void VCLXWindow::setPointer( const css::uno::Reference< css::awt::XPointer >& rxPointer )
1164 SolarMutexGuard aGuard;
1166 VCLXPointer* pPointer = VCLXPointer::GetImplementation( rxPointer );
1167 if ( pPointer && GetWindow() )
1168 GetWindow()->SetPointer( pPointer->GetPointer() );
1171 void VCLXWindow::setBackground( sal_Int32 nColor )
1173 SolarMutexGuard aGuard;
1175 if ( GetWindow() )
1177 Color aColor(nColor);
1178 GetWindow()->SetBackground( aColor );
1179 GetWindow()->SetControlBackground( aColor );
1181 WindowType eWinType = GetWindow()->GetType();
1182 if ( ( eWinType == WindowType::WINDOW ) ||
1183 ( eWinType == WindowType::WORKWINDOW ) ||
1184 ( eWinType == WindowType::FLOATINGWINDOW ) )
1186 GetWindow()->Invalidate();
1191 void VCLXWindow::invalidate( sal_Int16 nInvalidateFlags )
1193 SolarMutexGuard aGuard;
1195 if ( GetWindow() )
1196 GetWindow()->Invalidate( static_cast<InvalidateFlags>(nInvalidateFlags) );
1199 void VCLXWindow::invalidateRect( const css::awt::Rectangle& rRect, sal_Int16 nInvalidateFlags )
1201 SolarMutexGuard aGuard;
1203 if ( GetWindow() )
1204 GetWindow()->Invalidate( VCLRectangle(rRect), static_cast<InvalidateFlags>(nInvalidateFlags) );
1208 // css::awt::XVclWindowPeer
1209 sal_Bool VCLXWindow::isChild( const css::uno::Reference< css::awt::XWindowPeer >& rxPeer )
1211 SolarMutexGuard aGuard;
1213 bool bIsChild = false;
1214 VclPtr<vcl::Window> pWindow = GetWindow();
1215 if ( pWindow )
1217 VclPtr<vcl::Window> pPeerWindow = VCLUnoHelper::GetWindow( rxPeer );
1218 bIsChild = pPeerWindow && pWindow->IsChild( pPeerWindow );
1221 return bIsChild;
1224 void VCLXWindow::setDesignMode( sal_Bool bOn )
1226 SolarMutexGuard aGuard;
1228 mpImpl->mbDesignMode = bOn;
1231 sal_Bool VCLXWindow::isDesignMode( )
1233 SolarMutexGuard aGuard;
1234 return mpImpl->mbDesignMode;
1237 void VCLXWindow::enableClipSiblings( sal_Bool bClip )
1239 SolarMutexGuard aGuard;
1241 if ( GetWindow() )
1242 GetWindow()->EnableClipSiblings( bClip );
1245 void VCLXWindow::setForeground( sal_Int32 nColor )
1247 SolarMutexGuard aGuard;
1249 if ( GetWindow() )
1251 GetWindow()->SetControlForeground( Color(nColor) );
1255 void VCLXWindow::setControlFont( const css::awt::FontDescriptor& rFont )
1257 SolarMutexGuard aGuard;
1259 if ( GetWindow() )
1260 GetWindow()->SetControlFont( VCLUnoHelper::CreateFont( rFont, GetWindow()->GetControlFont() ) );
1263 void VCLXWindow::getStyles( sal_Int16 nType, css::awt::FontDescriptor& Font, sal_Int32& ForegroundColor, sal_Int32& BackgroundColor )
1265 SolarMutexGuard aGuard;
1267 if ( GetWindow() )
1269 const StyleSettings& rStyleSettings = GetWindow()->GetSettings().GetStyleSettings();
1271 switch ( nType )
1273 case css::awt::Style::FRAME:
1275 Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() );
1276 ForegroundColor = sal_Int32(rStyleSettings.GetWindowTextColor());
1277 BackgroundColor = sal_Int32(rStyleSettings.GetWindowColor());
1279 break;
1280 case css::awt::Style::DIALOG:
1282 Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() );
1283 ForegroundColor = sal_Int32(rStyleSettings.GetDialogTextColor());
1284 BackgroundColor = sal_Int32(rStyleSettings.GetDialogColor());
1286 break;
1287 default: OSL_FAIL( "VCLWindow::getStyles() - unknown Type" );
1293 namespace toolkit
1295 static void setColorSettings( vcl::Window* _pWindow, const css::uno::Any& _rValue,
1296 void (StyleSettings::*pSetter)( const Color& ), const Color& (StyleSettings::*pGetter)( ) const )
1298 sal_Int32 nColor = 0;
1299 if ( !( _rValue >>= nColor ) )
1300 nColor = sal_Int32((Application::GetSettings().GetStyleSettings().*pGetter)());
1302 AllSettings aSettings = _pWindow->GetSettings();
1303 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1305 (aStyleSettings.*pSetter)( Color( nColor ) );
1307 aSettings.SetStyleSettings( aStyleSettings );
1308 _pWindow->SetSettings( aSettings, true );
1312 // Terminated by BASEPROPERTY_NOTFOUND (or 0)
1313 void VCLXWindow::PushPropertyIds( std::vector< sal_uInt16 > &rIds,
1314 int nFirstId, ...)
1316 va_list pVarArgs;
1317 va_start( pVarArgs, nFirstId );
1319 for ( int nId = nFirstId; nId != BASEPROPERTY_NOTFOUND;
1320 nId = va_arg( pVarArgs, int ) )
1321 rIds.push_back( static_cast<sal_uInt16>(nId) );
1323 va_end( pVarArgs );
1326 void VCLXWindow::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds, bool bWithDefaults )
1328 // These are common across ~all VCLXWindow derived classes
1329 if( bWithDefaults )
1330 PushPropertyIds( rIds,
1331 BASEPROPERTY_ALIGN,
1332 BASEPROPERTY_BACKGROUNDCOLOR,
1333 BASEPROPERTY_BORDER,
1334 BASEPROPERTY_BORDERCOLOR,
1335 BASEPROPERTY_DEFAULTCONTROL,
1336 BASEPROPERTY_ENABLED,
1337 BASEPROPERTY_FONTDESCRIPTOR,
1338 BASEPROPERTY_HELPTEXT,
1339 BASEPROPERTY_HELPURL,
1340 BASEPROPERTY_TEXT,
1341 BASEPROPERTY_PRINTABLE,
1342 BASEPROPERTY_ENABLEVISIBLE, // for visibility
1343 BASEPROPERTY_TABSTOP,
1346 // lovely hack from:
1347 // void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId )
1348 if( std::find(rIds.begin(), rIds.end(), BASEPROPERTY_FONTDESCRIPTOR) != rIds.end() )
1350 // some properties are not included in the FontDescriptor, but every time
1351 // when we have a FontDescriptor we want to have these properties too.
1352 // => Easier to register the here, instead everywhere where I register the FontDescriptor...
1354 rIds.push_back( BASEPROPERTY_TEXTCOLOR );
1355 rIds.push_back( BASEPROPERTY_TEXTLINECOLOR );
1356 rIds.push_back( BASEPROPERTY_FONTRELIEF );
1357 rIds.push_back( BASEPROPERTY_FONTEMPHASISMARK );
1361 void VCLXWindow::GetPropertyIds( std::vector< sal_uInt16 >& _out_rIds )
1363 return ImplGetPropertyIds( _out_rIds, mpImpl->mbWithDefaultProps );
1366 ::comphelper::OInterfaceContainerHelper2& VCLXWindow::GetContainerListeners()
1368 return mpImpl->getContainerListeners();
1371 ::comphelper::OInterfaceContainerHelper2& VCLXWindow::GetTopWindowListeners()
1373 return mpImpl->getTopWindowListeners();
1376 namespace
1378 void lcl_updateWritingMode( vcl::Window& _rWindow, const sal_Int16 _nWritingMode, const sal_Int16 _nContextWritingMode )
1380 bool bEnableRTL = false;
1381 switch ( _nWritingMode )
1383 case WritingMode2::LR_TB: bEnableRTL = false; break;
1384 case WritingMode2::RL_TB: bEnableRTL = true; break;
1385 case WritingMode2::CONTEXT:
1387 // consult our ContextWritingMode. If it has an explicit RTL/LTR value, then use
1388 // it. If it doesn't (but is CONTEXT itself), then just ask the parent window of our
1389 // own window for its RTL mode
1390 switch ( _nContextWritingMode )
1392 case WritingMode2::LR_TB: bEnableRTL = false; break;
1393 case WritingMode2::RL_TB: bEnableRTL = true; break;
1394 case WritingMode2::CONTEXT:
1396 const vcl::Window* pParent = _rWindow.GetParent();
1397 OSL_ENSURE( pParent, "lcl_updateWritingMode: cannot determine context's writing mode!" );
1398 if ( pParent )
1399 bEnableRTL = pParent->IsRTLEnabled();
1401 break;
1404 break;
1405 default:
1406 OSL_FAIL( "lcl_updateWritingMode: unsupported WritingMode!" );
1407 } // switch ( nWritingMode )
1409 _rWindow.EnableRTL( bEnableRTL );
1413 void VCLXWindow::setProperty( const OUString& PropertyName, const css::uno::Any& Value )
1415 SolarMutexGuard aGuard;
1417 VclPtr<vcl::Window> pWindow = GetWindow();
1418 if ( !pWindow )
1419 return;
1421 bool bVoid = Value.getValueType().getTypeClass() == css::uno::TypeClass_VOID;
1423 WindowType eWinType = pWindow->GetType();
1424 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1425 switch ( nPropType )
1427 case BASEPROPERTY_REFERENCE_DEVICE:
1429 Control* pControl = dynamic_cast< Control* >( pWindow.get() );
1430 OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" );
1431 if ( !pControl )
1432 break;
1433 Reference< XDevice > xDevice( Value, UNO_QUERY );
1434 OutputDevice* pDevice = VCLUnoHelper::GetOutputDevice( xDevice );
1435 pControl->SetReferenceDevice( pDevice );
1437 break;
1439 case BASEPROPERTY_CONTEXT_WRITING_MODE:
1441 OSL_VERIFY( Value >>= mpImpl->mnContextWritingMode );
1442 if ( mpImpl->mnWritingMode == WritingMode2::CONTEXT )
1443 lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode );
1445 break;
1447 case BASEPROPERTY_WRITING_MODE:
1449 bool bProperType = ( Value >>= mpImpl->mnWritingMode );
1450 OSL_ENSURE( bProperType, "VCLXWindow::setProperty( 'WritingMode' ): illegal value type!" );
1451 if ( bProperType )
1452 lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode );
1454 break;
1456 case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:
1458 sal_uInt16 nWheelBehavior( css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY );
1459 OSL_VERIFY( Value >>= nWheelBehavior );
1461 AllSettings aSettings = pWindow->GetSettings();
1462 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
1464 MouseWheelBehaviour nVclBehavior( MouseWheelBehaviour::FocusOnly );
1465 switch ( nWheelBehavior )
1467 case css::awt::MouseWheelBehavior::SCROLL_DISABLED: nVclBehavior = MouseWheelBehaviour::Disable; break;
1468 case css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY: nVclBehavior = MouseWheelBehaviour::FocusOnly; break;
1469 case css::awt::MouseWheelBehavior::SCROLL_ALWAYS: nVclBehavior = MouseWheelBehaviour::ALWAYS; break;
1470 default:
1471 OSL_FAIL( "VCLXWindow::setProperty( 'MouseWheelBehavior' ): illegal property value!" );
1474 aMouseSettings.SetWheelBehavior( nVclBehavior );
1475 aSettings.SetMouseSettings( aMouseSettings );
1476 pWindow->SetSettings( aSettings, true );
1478 break;
1480 case BASEPROPERTY_NATIVE_WIDGET_LOOK:
1482 bool bEnable( true );
1483 OSL_VERIFY( Value >>= bEnable );
1484 pWindow->EnableNativeWidget( bEnable );
1486 break;
1488 case BASEPROPERTY_PLUGINPARENT:
1490 // set parent handle
1491 SetSystemParent_Impl( Value );
1493 break;
1495 case BASEPROPERTY_ENABLED:
1497 bool b = bool();
1498 if ( Value >>= b )
1499 setEnable( b );
1501 break;
1502 case BASEPROPERTY_ENABLEVISIBLE:
1504 bool b = false;
1505 if ( Value >>= b )
1507 if( b != mpImpl->isEnableVisible() )
1509 mpImpl->setEnableVisible( b );
1510 pWindow->Show( b && mpImpl->isDirectVisible() );
1514 break;
1515 case BASEPROPERTY_TEXT:
1516 case BASEPROPERTY_LABEL:
1517 case BASEPROPERTY_TITLE:
1519 OUString aText;
1520 if ( Value >>= aText )
1522 switch (eWinType)
1524 case WindowType::OKBUTTON:
1525 case WindowType::CANCELBUTTON:
1526 case WindowType::HELPBUTTON:
1527 // Standard Button: overwrite only if not empty.
1528 if (!aText.isEmpty())
1529 pWindow->SetText( aText );
1530 break;
1532 default:
1533 pWindow->SetText( aText );
1534 break;
1538 break;
1539 case BASEPROPERTY_ACCESSIBLENAME:
1541 OUString aText;
1542 if ( Value >>= aText )
1543 pWindow->SetAccessibleName( aText );
1545 break;
1546 case BASEPROPERTY_HELPURL:
1548 OUString aURL;
1549 if ( Value >>= aURL )
1551 INetURLObject aHelpURL( aURL );
1552 if ( aHelpURL.GetProtocol() == INetProtocol::Hid )
1553 pWindow->SetHelpId( OUStringToOString( aHelpURL.GetURLPath(), RTL_TEXTENCODING_UTF8 ) );
1554 else
1555 pWindow->SetHelpId( OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ) );
1558 break;
1559 case BASEPROPERTY_HELPTEXT:
1561 OUString aHelpText;
1562 if ( Value >>= aHelpText )
1564 pWindow->SetQuickHelpText( aHelpText );
1567 break;
1568 case BASEPROPERTY_FONTDESCRIPTOR:
1570 if ( bVoid )
1571 pWindow->SetControlFont( vcl::Font() );
1572 else
1574 css::awt::FontDescriptor aFont;
1575 if ( Value >>= aFont )
1576 pWindow->SetControlFont( VCLUnoHelper::CreateFont( aFont, pWindow->GetControlFont() ) );
1579 break;
1580 case BASEPROPERTY_FONTRELIEF:
1582 sal_Int16 n = sal_Int16();
1583 if ( Value >>= n )
1585 vcl::Font aFont = pWindow->GetControlFont();
1586 aFont.SetRelief( static_cast<FontRelief>(n) );
1587 pWindow->SetControlFont( aFont );
1590 break;
1591 case BASEPROPERTY_FONTEMPHASISMARK:
1593 sal_Int16 n = sal_Int16();
1594 if ( Value >>= n )
1596 vcl::Font aFont = pWindow->GetControlFont();
1597 aFont.SetEmphasisMark( static_cast<FontEmphasisMark>(n) );
1598 pWindow->SetControlFont( aFont );
1601 break;
1602 case BASEPROPERTY_BACKGROUNDCOLOR:
1603 if ( bVoid )
1605 switch ( eWinType )
1607 // set dialog color for default
1608 case WindowType::DIALOG:
1609 case WindowType::MESSBOX:
1610 case WindowType::INFOBOX:
1611 case WindowType::WARNINGBOX:
1612 case WindowType::ERRORBOX:
1613 case WindowType::QUERYBOX:
1614 case WindowType::TABPAGE:
1616 Color aColor = pWindow->GetSettings().GetStyleSettings().GetDialogColor();
1617 pWindow->SetBackground( aColor );
1618 pWindow->SetControlBackground( aColor );
1619 break;
1622 case WindowType::FIXEDTEXT:
1623 case WindowType::CHECKBOX:
1624 case WindowType::RADIOBUTTON:
1625 case WindowType::GROUPBOX:
1626 case WindowType::FIXEDLINE:
1628 // support transparency only for special controls
1629 pWindow->SetBackground();
1630 pWindow->SetControlBackground();
1631 pWindow->SetPaintTransparent( true );
1632 break;
1635 default:
1637 // default code which enables transparency for
1638 // compound controls. It's not real transparency
1639 // as most of these controls repaint their client
1640 // area completely new.
1641 if ( pWindow->IsCompoundControl() )
1642 pWindow->SetBackground();
1643 pWindow->SetControlBackground();
1644 break;
1648 else
1650 sal_Int32 nColor = 0;
1651 if ( Value >>= nColor )
1653 Color aColor( nColor );
1654 pWindow->SetControlBackground( aColor );
1655 pWindow->SetBackground( aColor );
1656 switch ( eWinType )
1658 // reset paint transparent mode
1659 case WindowType::FIXEDTEXT:
1660 case WindowType::CHECKBOX:
1661 case WindowType::RADIOBUTTON:
1662 case WindowType::GROUPBOX:
1663 case WindowType::FIXEDLINE:
1664 pWindow->SetPaintTransparent( false );
1665 break;
1666 default:
1667 break;
1669 pWindow->Invalidate(); // Invalidate if control does not respond to it
1672 break;
1673 case BASEPROPERTY_TEXTCOLOR:
1674 if ( bVoid )
1676 pWindow->SetControlForeground();
1678 else
1680 sal_Int32 nColor = 0;
1681 if ( Value >>= nColor )
1683 Color aColor( nColor );
1684 pWindow->SetTextColor( aColor );
1685 pWindow->SetControlForeground( aColor );
1688 break;
1689 case BASEPROPERTY_TEXTLINECOLOR:
1690 if ( bVoid )
1692 pWindow->SetTextLineColor();
1694 else
1696 sal_Int32 nColor = 0;
1697 if ( Value >>= nColor )
1699 Color aColor( nColor );
1700 pWindow->SetTextLineColor( aColor );
1703 break;
1704 case BASEPROPERTY_FILLCOLOR:
1705 if ( bVoid )
1706 pWindow->SetFillColor();
1707 else
1709 sal_Int32 nColor = 0;
1710 if ( Value >>= nColor )
1712 Color aColor( nColor );
1713 pWindow->SetFillColor( aColor );
1716 break;
1717 case BASEPROPERTY_LINECOLOR:
1718 if ( bVoid )
1719 pWindow->SetLineColor();
1720 else
1722 sal_Int32 nColor = 0;
1723 if ( Value >>= nColor )
1725 Color aColor( nColor );
1726 pWindow->SetLineColor( aColor );
1729 break;
1730 case BASEPROPERTY_BORDER:
1732 WinBits nStyle = pWindow->GetStyle();
1733 sal_uInt16 nTmp = 0;
1734 Value >>= nTmp;
1735 // clear any dodgy bits passed in, can come from dodgy extensions
1736 nTmp &= o3tl::typed_flags<WindowBorderStyle>::mask;
1737 WindowBorderStyle nBorder = static_cast<WindowBorderStyle>(nTmp);
1738 if ( !bool(nBorder) )
1740 pWindow->SetStyle( nStyle & ~WB_BORDER );
1742 else
1744 pWindow->SetStyle( nStyle | WB_BORDER );
1745 pWindow->SetBorderStyle( nBorder );
1748 break;
1749 case BASEPROPERTY_TABSTOP:
1751 WinBits nStyle = pWindow->GetStyle() & ~WB_TABSTOP;
1752 if ( !bVoid )
1754 bool bTab = false;
1755 Value >>= bTab;
1756 if ( bTab )
1757 nStyle |= WB_TABSTOP;
1758 else
1759 nStyle |= WB_NOTABSTOP;
1761 pWindow->SetStyle( nStyle );
1763 break;
1764 case BASEPROPERTY_VERTICALALIGN:
1766 VerticalAlignment eAlign = css::style::VerticalAlignment::VerticalAlignment_MAKE_FIXED_SIZE;
1767 WinBits nStyle = pWindow->GetStyle();
1768 nStyle &= ~(WB_TOP|WB_VCENTER|WB_BOTTOM);
1769 if ( !bVoid )
1770 Value >>= eAlign;
1771 switch ( eAlign )
1773 case VerticalAlignment_TOP:
1774 nStyle |= WB_TOP;
1775 break;
1776 case VerticalAlignment_MIDDLE:
1777 nStyle |= WB_VCENTER;
1778 break;
1779 case VerticalAlignment_BOTTOM:
1780 nStyle |= WB_BOTTOM;
1781 break;
1782 default: ; // for warning free code, MAKE_FIXED_SIZE
1784 pWindow->SetStyle( nStyle );
1786 break;
1787 case BASEPROPERTY_ALIGN:
1789 sal_Int16 nAlign = PROPERTY_ALIGN_LEFT;
1790 switch ( eWinType )
1792 case WindowType::COMBOBOX:
1793 case WindowType::PUSHBUTTON:
1794 case WindowType::OKBUTTON:
1795 case WindowType::CANCELBUTTON:
1796 case WindowType::HELPBUTTON:
1797 nAlign = PROPERTY_ALIGN_CENTER;
1798 [[fallthrough]];
1799 case WindowType::FIXEDTEXT:
1800 case WindowType::EDIT:
1801 case WindowType::MULTILINEEDIT:
1802 case WindowType::CHECKBOX:
1803 case WindowType::RADIOBUTTON:
1804 case WindowType::LISTBOX:
1806 WinBits nStyle = pWindow->GetStyle();
1807 nStyle &= ~(WB_LEFT|WB_CENTER|WB_RIGHT);
1808 if ( !bVoid )
1809 Value >>= nAlign;
1810 if ( nAlign == PROPERTY_ALIGN_LEFT )
1811 nStyle |= WB_LEFT;
1812 else if ( nAlign == PROPERTY_ALIGN_CENTER )
1813 nStyle |= WB_CENTER;
1814 else
1815 nStyle |= WB_RIGHT;
1816 pWindow->SetStyle( nStyle );
1818 break;
1819 default: break;
1822 break;
1823 case BASEPROPERTY_MULTILINE:
1825 if ( ( eWinType == WindowType::FIXEDTEXT )
1826 || ( eWinType == WindowType::CHECKBOX )
1827 || ( eWinType == WindowType::RADIOBUTTON )
1828 || ( eWinType == WindowType::PUSHBUTTON )
1829 || ( eWinType == WindowType::OKBUTTON )
1830 || ( eWinType == WindowType::CANCELBUTTON )
1831 || ( eWinType == WindowType::HELPBUTTON )
1834 WinBits nStyle = pWindow->GetStyle();
1835 bool bMulti = false;
1836 Value >>= bMulti;
1837 if ( bMulti )
1838 nStyle |= WB_WORDBREAK;
1839 else
1840 nStyle &= ~WB_WORDBREAK;
1841 pWindow->SetStyle( nStyle );
1844 break;
1845 case BASEPROPERTY_ORIENTATION:
1847 if ( eWinType == WindowType::FIXEDLINE)
1849 sal_Int32 nOrientation = 0;
1850 if ( Value >>= nOrientation )
1852 WinBits nStyle = pWindow->GetStyle();
1853 nStyle &= ~(WB_HORZ|WB_VERT);
1854 if ( nOrientation == 0 )
1855 nStyle |= WB_HORZ;
1856 else
1857 nStyle |= WB_VERT;
1859 pWindow->SetStyle( nStyle );
1863 break;
1864 case BASEPROPERTY_AUTOMNEMONICS:
1866 bool bAutoMnemonics = false;
1867 Value >>= bAutoMnemonics;
1868 AllSettings aSettings = pWindow->GetSettings();
1869 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1870 if ( aStyleSettings.GetAutoMnemonic() != bAutoMnemonics )
1872 aStyleSettings.SetAutoMnemonic( bAutoMnemonics );
1873 aSettings.SetStyleSettings( aStyleSettings );
1874 pWindow->SetSettings( aSettings );
1877 break;
1878 case BASEPROPERTY_MOUSETRANSPARENT:
1880 bool bMouseTransparent = false;
1881 Value >>= bMouseTransparent;
1882 pWindow->SetMouseTransparent( bMouseTransparent );
1884 break;
1885 case BASEPROPERTY_PAINTTRANSPARENT:
1887 bool bPaintTransparent = false;
1888 Value >>= bPaintTransparent;
1889 pWindow->SetPaintTransparent( bPaintTransparent );
1890 // pWindow->SetBackground();
1892 break;
1894 case BASEPROPERTY_REPEAT:
1896 bool bRepeat( false );
1897 Value >>= bRepeat;
1899 WinBits nStyle = pWindow->GetStyle();
1900 if ( bRepeat )
1901 nStyle |= WB_REPEAT;
1902 else
1903 nStyle &= ~WB_REPEAT;
1904 pWindow->SetStyle( nStyle );
1906 break;
1908 case BASEPROPERTY_REPEAT_DELAY:
1910 sal_Int32 nRepeatDelay = 0;
1911 if ( Value >>= nRepeatDelay )
1913 AllSettings aSettings = pWindow->GetSettings();
1914 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
1916 aMouseSettings.SetButtonRepeat( nRepeatDelay );
1917 aSettings.SetMouseSettings( aMouseSettings );
1919 pWindow->SetSettings( aSettings, true );
1922 break;
1924 case BASEPROPERTY_SYMBOL_COLOR:
1925 ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetButtonTextColor, &StyleSettings::GetButtonTextColor );
1926 break;
1928 case BASEPROPERTY_BORDERCOLOR:
1929 ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetMonoColor, &StyleSettings::GetMonoColor);
1930 break;
1934 css::uno::Any VCLXWindow::getProperty( const OUString& PropertyName )
1936 SolarMutexGuard aGuard;
1938 css::uno::Any aProp;
1939 if ( GetWindow() )
1941 WindowType eWinType = GetWindow()->GetType();
1942 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1943 switch ( nPropType )
1945 case BASEPROPERTY_REFERENCE_DEVICE:
1947 VclPtr<Control> pControl = GetAsDynamic<Control >();
1948 OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" );
1949 if ( !pControl )
1950 break;
1952 VCLXDevice* pDevice = new VCLXDevice;
1953 pDevice->SetOutputDevice( pControl->GetReferenceDevice() );
1954 aProp <<= Reference< XDevice >( pDevice );
1956 break;
1958 case BASEPROPERTY_CONTEXT_WRITING_MODE:
1959 aProp <<= mpImpl->mnContextWritingMode;
1960 break;
1962 case BASEPROPERTY_WRITING_MODE:
1963 aProp <<= mpImpl->mnWritingMode;
1964 break;
1966 case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:
1968 MouseWheelBehaviour nVclBehavior = GetWindow()->GetSettings().GetMouseSettings().GetWheelBehavior();
1969 sal_uInt16 nBehavior = css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY;
1970 switch ( nVclBehavior )
1972 case MouseWheelBehaviour::Disable: nBehavior = css::awt::MouseWheelBehavior::SCROLL_DISABLED; break;
1973 case MouseWheelBehaviour::FocusOnly: nBehavior = css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY; break;
1974 case MouseWheelBehaviour::ALWAYS: nBehavior = css::awt::MouseWheelBehavior::SCROLL_ALWAYS; break;
1975 default:
1976 OSL_FAIL( "VCLXWindow::getProperty( 'MouseWheelBehavior' ): illegal VCL value!" );
1978 aProp <<= nBehavior;
1980 break;
1982 case BASEPROPERTY_NATIVE_WIDGET_LOOK:
1983 aProp <<= GetWindow()->IsNativeWidgetEnabled();
1984 break;
1986 case BASEPROPERTY_ENABLED:
1987 aProp <<= GetWindow()->IsEnabled();
1988 break;
1990 case BASEPROPERTY_ENABLEVISIBLE:
1991 aProp <<= mpImpl->isEnableVisible();
1992 break;
1994 case BASEPROPERTY_HIGHCONTRASTMODE:
1995 aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetHighContrastMode();
1996 break;
1998 case BASEPROPERTY_TEXT:
1999 case BASEPROPERTY_LABEL:
2000 case BASEPROPERTY_TITLE:
2002 OUString aText = GetWindow()->GetText();
2003 aProp <<= aText;
2005 break;
2006 case BASEPROPERTY_ACCESSIBLENAME:
2008 OUString aText = GetWindow()->GetAccessibleName();
2009 aProp <<= aText;
2011 break;
2012 case BASEPROPERTY_HELPTEXT:
2014 OUString aText = GetWindow()->GetQuickHelpText();
2015 aProp <<= aText;
2017 break;
2018 case BASEPROPERTY_HELPURL:
2020 OUString aHelpId( OStringToOUString( GetWindow()->GetHelpId(), RTL_TEXTENCODING_UTF8 ) );
2021 aProp <<= aHelpId;
2023 break;
2024 case BASEPROPERTY_FONTDESCRIPTOR:
2026 vcl::Font aFont = GetWindow()->GetControlFont();
2027 css::awt::FontDescriptor aFD = VCLUnoHelper::CreateFontDescriptor( aFont );
2028 aProp <<= aFD;
2030 break;
2031 case BASEPROPERTY_BACKGROUNDCOLOR:
2032 aProp <<= GetWindow()->GetControlBackground();
2033 break;
2034 case BASEPROPERTY_DISPLAYBACKGROUNDCOLOR:
2035 aProp <<= GetWindow()->GetDisplayBackground().GetColor();
2036 break;
2037 case BASEPROPERTY_FONTRELIEF:
2038 aProp <<= static_cast<sal_Int16>(GetWindow()->GetControlFont().GetRelief());
2039 break;
2040 case BASEPROPERTY_FONTEMPHASISMARK:
2041 aProp <<= static_cast<sal_Int16>(GetWindow()->GetControlFont().GetEmphasisMark());
2042 break;
2043 case BASEPROPERTY_TEXTCOLOR:
2044 aProp <<= GetWindow()->GetControlForeground();
2045 break;
2046 case BASEPROPERTY_TEXTLINECOLOR:
2047 aProp <<= GetWindow()->GetTextLineColor();
2048 break;
2049 case BASEPROPERTY_FILLCOLOR:
2050 aProp <<= GetWindow()->GetFillColor();
2051 break;
2052 case BASEPROPERTY_LINECOLOR:
2053 aProp <<= GetWindow()->GetLineColor();
2054 break;
2055 case BASEPROPERTY_BORDER:
2057 WindowBorderStyle nBorder = WindowBorderStyle::NONE;
2058 if ( GetWindow()->GetStyle() & WB_BORDER )
2059 nBorder = GetWindow()->GetBorderStyle();
2060 aProp <<= static_cast<sal_uInt16>(nBorder);
2062 break;
2063 case BASEPROPERTY_TABSTOP:
2064 aProp <<= ( GetWindow()->GetStyle() & WB_TABSTOP ) != 0;
2065 break;
2066 case BASEPROPERTY_VERTICALALIGN:
2068 WinBits nStyle = GetWindow()->GetStyle();
2069 if ( nStyle & WB_TOP )
2070 aProp <<= VerticalAlignment_TOP;
2071 else if ( nStyle & WB_VCENTER )
2072 aProp <<= VerticalAlignment_MIDDLE;
2073 else if ( nStyle & WB_BOTTOM )
2074 aProp <<= VerticalAlignment_BOTTOM;
2076 break;
2077 case BASEPROPERTY_ALIGN:
2079 switch ( eWinType )
2081 case WindowType::FIXEDTEXT:
2082 case WindowType::EDIT:
2083 case WindowType::MULTILINEEDIT:
2084 case WindowType::CHECKBOX:
2085 case WindowType::RADIOBUTTON:
2086 case WindowType::LISTBOX:
2087 case WindowType::COMBOBOX:
2088 case WindowType::PUSHBUTTON:
2089 case WindowType::OKBUTTON:
2090 case WindowType::CANCELBUTTON:
2091 case WindowType::HELPBUTTON:
2093 WinBits nStyle = GetWindow()->GetStyle();
2094 if ( nStyle & WB_LEFT )
2095 aProp <<= sal_Int16(PROPERTY_ALIGN_LEFT);
2096 else if ( nStyle & WB_CENTER )
2097 aProp <<= sal_Int16(PROPERTY_ALIGN_CENTER);
2098 else if ( nStyle & WB_RIGHT )
2099 aProp <<= sal_Int16(PROPERTY_ALIGN_RIGHT);
2101 break;
2102 default: break;
2105 break;
2106 case BASEPROPERTY_MULTILINE:
2108 if ( ( eWinType == WindowType::FIXEDTEXT )
2109 || ( eWinType == WindowType::CHECKBOX )
2110 || ( eWinType == WindowType::RADIOBUTTON )
2111 || ( eWinType == WindowType::PUSHBUTTON )
2112 || ( eWinType == WindowType::OKBUTTON )
2113 || ( eWinType == WindowType::CANCELBUTTON )
2114 || ( eWinType == WindowType::HELPBUTTON )
2116 aProp <<= ( GetWindow()->GetStyle() & WB_WORDBREAK ) != 0;
2118 break;
2119 case BASEPROPERTY_AUTOMNEMONICS:
2121 bool bAutoMnemonics = GetWindow()->GetSettings().GetStyleSettings().GetAutoMnemonic();
2122 aProp <<= bAutoMnemonics;
2124 break;
2125 case BASEPROPERTY_MOUSETRANSPARENT:
2127 bool bMouseTransparent = GetWindow()->IsMouseTransparent();
2128 aProp <<= bMouseTransparent;
2130 break;
2131 case BASEPROPERTY_PAINTTRANSPARENT:
2133 bool bPaintTransparent = GetWindow()->IsPaintTransparent();
2134 aProp <<= bPaintTransparent;
2136 break;
2138 case BASEPROPERTY_REPEAT:
2139 aProp <<= ( 0 != ( GetWindow()->GetStyle() & WB_REPEAT ) );
2140 break;
2142 case BASEPROPERTY_REPEAT_DELAY:
2144 sal_Int32 nButtonRepeat = GetWindow()->GetSettings().GetMouseSettings().GetButtonRepeat();
2145 aProp <<= nButtonRepeat;
2147 break;
2149 case BASEPROPERTY_SYMBOL_COLOR:
2150 aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetButtonTextColor();
2151 break;
2153 case BASEPROPERTY_BORDERCOLOR:
2154 aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetMonoColor();
2155 break;
2158 return aProp;
2162 // css::awt::XLayoutConstrains
2163 css::awt::Size VCLXWindow::getMinimumSize( )
2165 SolarMutexGuard aGuard;
2167 // Use this method only for those components which can be created through
2168 // css::awt::Toolkit , but do not have an interface
2170 Size aSz;
2171 if ( GetWindow() )
2173 WindowType nWinType = GetWindow()->GetType();
2174 switch ( nWinType )
2176 case WindowType::CONTROL:
2177 aSz.setWidth( GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*12 );
2178 aSz.setHeight( GetWindow()->GetTextHeight()+2*6 );
2179 break;
2181 case WindowType::PATTERNBOX:
2182 case WindowType::NUMERICBOX:
2183 case WindowType::METRICBOX:
2184 case WindowType::CURRENCYBOX:
2185 case WindowType::DATEBOX:
2186 case WindowType::TIMEBOX:
2187 case WindowType::LONGCURRENCYBOX:
2188 aSz.setWidth( GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*2 );
2189 aSz.setHeight( GetWindow()->GetTextHeight()+2*2 );
2190 break;
2191 case WindowType::SCROLLBARBOX:
2192 return VCLXScrollBar::implGetMinimumSize( GetWindow() );
2193 default:
2194 aSz = GetWindow()->get_preferred_size();
2198 return css::awt::Size( aSz.Width(), aSz.Height() );
2201 css::awt::Size VCLXWindow::getPreferredSize( )
2203 return getMinimumSize();
2206 css::awt::Size VCLXWindow::calcAdjustedSize( const css::awt::Size& rNewSize )
2208 SolarMutexGuard aGuard;
2210 css::awt::Size aNewSize( rNewSize );
2211 css::awt::Size aMinSize = getMinimumSize();
2213 if ( aNewSize.Width < aMinSize.Width )
2214 aNewSize.Width = aMinSize.Width;
2215 if ( aNewSize.Height < aMinSize.Height )
2216 aNewSize.Height = aMinSize.Height;
2218 return aNewSize;
2222 // css::awt::XView
2223 sal_Bool VCLXWindow::setGraphics( const css::uno::Reference< css::awt::XGraphics >& rxDevice )
2225 SolarMutexGuard aGuard;
2227 if ( VCLUnoHelper::GetOutputDevice( rxDevice ) )
2228 mpImpl->mxViewGraphics = rxDevice;
2229 else
2230 mpImpl->mxViewGraphics = nullptr;
2232 return mpImpl->mxViewGraphics.is();
2235 css::uno::Reference< css::awt::XGraphics > VCLXWindow::getGraphics( )
2237 SolarMutexGuard aGuard;
2239 return mpImpl->mxViewGraphics;
2242 css::awt::Size VCLXWindow::getSize( )
2244 SolarMutexGuard aGuard;
2246 Size aSz;
2247 if ( GetWindow() )
2248 aSz = GetWindow()->GetSizePixel();
2249 return css::awt::Size( aSz.Width(), aSz.Height() );
2252 void VCLXWindow::draw( sal_Int32 nX, sal_Int32 nY )
2254 SolarMutexGuard aGuard;
2256 VclPtr<vcl::Window> pWindow = GetWindow();
2257 if ( !pWindow )
2258 return;
2260 if ( isDesignMode() || mpImpl->isEnableVisible() )
2262 OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( mpImpl->mxViewGraphics );
2263 if (!pDev)
2264 pDev = pWindow->GetParent();
2265 TabPage* pTabPage = dynamic_cast< TabPage* >( pWindow.get() );
2266 if ( pTabPage )
2268 Point aPos( nX, nY );
2269 Size aSize = pWindow->GetSizePixel();
2271 aPos = pDev->PixelToLogic( aPos );
2272 aSize = pDev->PixelToLogic( aSize );
2274 pTabPage->Draw( pDev, aPos, aSize, DrawFlags::NONE );
2275 return;
2278 Point aPos( nX, nY );
2280 if ( pWindow->GetParent() && !pWindow->IsSystemWindow() && ( pWindow->GetParent() == pDev ) )
2282 // #i40647# don't draw here if this is a recursive call
2283 // sometimes this is called recursively, because the Update call on the parent
2284 // (strangely) triggers another paint. Prevent a stack overflow here
2285 // Yes, this is only fixing symptoms for the moment ....
2286 // #i40647# / 2005-01-18 / frank.schoenheit@sun.com
2287 if ( !mpImpl->getDrawingOntoParent_ref() )
2289 ::comphelper::FlagGuard aDrawingflagGuard( mpImpl->getDrawingOntoParent_ref() );
2291 bool bWasVisible = pWindow->IsVisible();
2292 Point aOldPos( pWindow->GetPosPixel() );
2294 if ( bWasVisible && aOldPos == aPos )
2296 pWindow->Update();
2297 return;
2300 pWindow->SetPosPixel( aPos );
2302 // Update parent first to avoid painting the parent upon the update
2303 // of this window, as it may otherwise cause the parent
2304 // to hide this window again
2305 if( pWindow->GetParent() )
2306 pWindow->GetParent()->Update();
2308 pWindow->Show();
2309 pWindow->Update();
2310 pWindow->SetParentUpdateMode( false );
2311 pWindow->Hide();
2312 pWindow->SetParentUpdateMode( true );
2314 pWindow->SetPosPixel( aOldPos );
2315 if ( bWasVisible )
2316 pWindow->Show();
2319 else if ( pDev )
2321 Size aSz = pWindow->GetSizePixel();
2322 aSz = pDev->PixelToLogic( aSz );
2323 Point aP = pDev->PixelToLogic( aPos );
2325 vcl::PDFExtOutDevData* pPDFExport = dynamic_cast<vcl::PDFExtOutDevData*>(pDev->GetExtOutDevData());
2326 bool bDrawSimple = ( pDev->GetOutDevType() == OUTDEV_PRINTER )
2327 || ( pDev->GetOutDevViewType() == OutDevViewType::PrintPreview )
2328 || ( pPDFExport != nullptr );
2329 if ( bDrawSimple )
2331 pWindow->Draw( pDev, aP, aSz, DrawFlags::NoControls );
2333 else
2335 bool bOldNW =pWindow->IsNativeWidgetEnabled();
2336 if( bOldNW )
2337 pWindow->EnableNativeWidget(false);
2338 pWindow->PaintToDevice( pDev, aP, aSz );
2339 if( bOldNW )
2340 pWindow->EnableNativeWidget();
2346 void VCLXWindow::setZoom( float fZoomX, float /*fZoomY*/ )
2348 SolarMutexGuard aGuard;
2350 if ( GetWindow() )
2352 // Fraction::Fraction takes a double, but we have a float only.
2353 // The implicit conversion from float to double can result in a precision loss, i.e. 1.2 is converted to
2354 // 1.200000000047something. To prevent this, we convert explicitly to double, and round it.
2355 double nZoom( fZoomX );
2356 Fraction aZoom(::rtl::math::round(nZoom, 4));
2357 aZoom.ReduceInaccurate(10); // to avoid runovers and BigInt mapping
2358 GetWindow()->SetZoom(aZoom);
2362 // css::lang::XEventListener
2363 void SAL_CALL VCLXWindow::disposing( const css::lang::EventObject& _rSource )
2365 SolarMutexGuard aGuard;
2367 // check if it comes from our AccessibleContext
2368 uno::Reference< uno::XInterface > aAC( mpImpl->mxAccessibleContext, uno::UNO_QUERY );
2369 uno::Reference< uno::XInterface > xSource( _rSource.Source, uno::UNO_QUERY );
2371 if ( aAC.get() == xSource.get() )
2372 { // yep, it does
2373 mpImpl->mxAccessibleContext.clear();
2377 // css::accessibility::XAccessible
2378 css::uno::Reference< css::accessibility::XAccessibleContext > VCLXWindow::getAccessibleContext( )
2380 SolarMutexGuard aGuard;
2382 // already disposed
2383 if( ! mpImpl )
2384 return uno::Reference< accessibility::XAccessibleContext >();
2386 if ( !mpImpl->mxAccessibleContext.is() && GetWindow() )
2388 mpImpl->mxAccessibleContext = CreateAccessibleContext();
2390 // add as event listener to this component
2391 // in case somebody disposes it, we do not want to have a (though weak) reference to a dead
2392 // object
2393 uno::Reference< lang::XComponent > xComp( mpImpl->mxAccessibleContext, uno::UNO_QUERY );
2394 if ( xComp.is() )
2395 xComp->addEventListener( this );
2398 return mpImpl->mxAccessibleContext;
2401 // css::awt::XDockable
2402 void SAL_CALL VCLXWindow::addDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener )
2404 SolarMutexGuard aGuard;
2406 if ( xListener.is() )
2407 mpImpl->getDockableWindowListeners().addInterface( xListener );
2411 void SAL_CALL VCLXWindow::removeDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener )
2413 SolarMutexGuard aGuard;
2415 mpImpl->getDockableWindowListeners().removeInterface( xListener );
2418 void SAL_CALL VCLXWindow::enableDocking( sal_Bool bEnable )
2420 SolarMutexGuard aGuard;
2422 VclPtr<vcl::Window> pWindow = GetWindow();
2423 if ( pWindow )
2424 pWindow->EnableDocking( bEnable );
2427 sal_Bool SAL_CALL VCLXWindow::isFloating( )
2429 SolarMutexGuard aGuard;
2431 VclPtr<vcl::Window> pWindow = GetWindow();
2432 if( pWindow )
2433 return vcl::Window::GetDockingManager()->IsFloating( pWindow );
2434 else
2435 return false;
2438 void SAL_CALL VCLXWindow::setFloatingMode( sal_Bool bFloating )
2440 SolarMutexGuard aGuard;
2442 VclPtr<vcl::Window> pWindow = GetWindow();
2443 if( pWindow )
2444 vcl::Window::GetDockingManager()->SetFloatingMode( pWindow, bFloating );
2447 sal_Bool SAL_CALL VCLXWindow::isLocked( )
2449 SolarMutexGuard aGuard;
2451 VclPtr<vcl::Window> pWindow = GetWindow();
2452 if( pWindow )
2453 return vcl::Window::GetDockingManager()->IsLocked( pWindow );
2454 else
2455 return false;
2458 void SAL_CALL VCLXWindow::lock( )
2460 SolarMutexGuard aGuard;
2462 VclPtr<vcl::Window> pWindow = GetWindow();
2463 if( pWindow && !vcl::Window::GetDockingManager()->IsFloating( pWindow ) )
2464 vcl::Window::GetDockingManager()->Lock( pWindow );
2467 void SAL_CALL VCLXWindow::unlock( )
2469 SolarMutexGuard aGuard;
2471 VclPtr<vcl::Window> pWindow = GetWindow();
2472 if( pWindow && !vcl::Window::GetDockingManager()->IsFloating( pWindow ) )
2473 vcl::Window::GetDockingManager()->Unlock( pWindow );
2476 void SAL_CALL VCLXWindow::startPopupMode( const css::awt::Rectangle& )
2478 // TODO: remove interface in the next incompatible build
2481 sal_Bool SAL_CALL VCLXWindow::isInPopupMode( )
2483 // TODO: remove interface in the next incompatible build
2484 return false;
2488 // css::awt::XWindow2
2490 void SAL_CALL VCLXWindow::setOutputSize( const css::awt::Size& aSize )
2492 SolarMutexGuard aGuard;
2493 VclPtr<vcl::Window> pWindow;
2494 if( (pWindow = GetWindow()) != nullptr )
2496 DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow.get());
2497 if( pDockingWindow )
2498 pDockingWindow->SetOutputSizePixel( VCLSize( aSize ) );
2499 else
2500 pWindow->SetOutputSizePixel( VCLSize( aSize ) );
2504 css::awt::Size SAL_CALL VCLXWindow::getOutputSize( )
2506 SolarMutexGuard aGuard;
2507 VclPtr<vcl::Window> pWindow;
2508 if( (pWindow = GetWindow()) != nullptr )
2510 DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow.get());
2511 if( pDockingWindow )
2512 return AWTSize( pDockingWindow->GetOutputSizePixel() );
2513 else
2514 return AWTSize( pWindow->GetOutputSizePixel() );
2516 else
2517 return css::awt::Size();
2520 sal_Bool SAL_CALL VCLXWindow::isVisible( )
2522 SolarMutexGuard aGuard;
2523 if( GetWindow() )
2524 return GetWindow()->IsVisible();
2525 else
2526 return false;
2529 sal_Bool SAL_CALL VCLXWindow::isActive( )
2531 SolarMutexGuard aGuard;
2532 if( GetWindow() )
2533 return GetWindow()->IsActive();
2534 else
2535 return false;
2539 sal_Bool SAL_CALL VCLXWindow::isEnabled( )
2541 SolarMutexGuard aGuard;
2542 if( GetWindow() )
2543 return GetWindow()->IsEnabled();
2544 else
2545 return false;
2548 sal_Bool SAL_CALL VCLXWindow::hasFocus( )
2550 SolarMutexGuard aGuard;
2551 if( GetWindow() )
2552 return GetWindow()->HasFocus();
2553 else
2554 return false;
2557 // css::beans::XPropertySetInfo
2559 UnoPropertyArrayHelper *
2560 VCLXWindow::GetPropHelper()
2562 SolarMutexGuard aGuard;
2563 if ( mpImpl->mpPropHelper == nullptr )
2565 std::vector< sal_uInt16 > aIDs;
2566 GetPropertyIds( aIDs );
2567 mpImpl->mpPropHelper.reset( new UnoPropertyArrayHelper( aIDs ) );
2569 return mpImpl->mpPropHelper.get();
2572 css::uno::Sequence< css::beans::Property > SAL_CALL
2573 VCLXWindow::getProperties()
2575 return GetPropHelper()->getProperties();
2577 css::beans::Property SAL_CALL
2578 VCLXWindow::getPropertyByName( const OUString& rName )
2580 return GetPropHelper()->getPropertyByName( rName );
2583 sal_Bool SAL_CALL
2584 VCLXWindow::hasPropertyByName( const OUString& rName )
2586 return GetPropHelper()->hasPropertyByName( rName );
2589 Reference< XStyleSettings > SAL_CALL VCLXWindow::getStyleSettings()
2591 return mpImpl->getStyleSettings();
2594 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */