File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 113, column 13 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
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/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
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 . | |||
18 | */ | |||
19 | ||||
20 | ||||
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/MouseEvent.hpp> | |||
26 | #include <com/sun/star/awt/MouseWheelBehavior.hpp> | |||
27 | #include <com/sun/star/awt/Style.hpp> | |||
28 | #include <com/sun/star/awt/DockingEvent.hpp> | |||
29 | #include <com/sun/star/awt/EndDockingEvent.hpp> | |||
30 | #include <com/sun/star/awt/EndPopupModeEvent.hpp> | |||
31 | #include <com/sun/star/awt/XWindowListener2.hpp> | |||
32 | #include <com/sun/star/style/VerticalAlignment.hpp> | |||
33 | #include <com/sun/star/lang/DisposedException.hpp> | |||
34 | #include <com/sun/star/text/WritingMode2.hpp> | |||
35 | #include <toolkit/awt/vclxwindow.hxx> | |||
36 | #include <awt/vclxpointer.hxx> | |||
37 | #include <toolkit/awt/vclxwindows.hxx> | |||
38 | #include <toolkit/helper/vclunohelper.hxx> | |||
39 | #include <toolkit/helper/convert.hxx> | |||
40 | #include <toolkit/helper/property.hxx> | |||
41 | #include <rtl/math.hxx> | |||
42 | #include <sal/log.hxx> | |||
43 | #include <vcl/svapp.hxx> | |||
44 | #include <vcl/window.hxx> | |||
45 | #include <tools/color.hxx> | |||
46 | #include <tools/fract.hxx> | |||
47 | #include <tools/debug.hxx> | |||
48 | #include <vcl/event.hxx> | |||
49 | #include <vcl/dockwin.hxx> | |||
50 | #include <vcl/pdfextoutdevdata.hxx> | |||
51 | #include <vcl/tabpage.hxx> | |||
52 | #include <vcl/ctrl.hxx> | |||
53 | #include <vcl/settings.hxx> | |||
54 | #include <vcl/commandevent.hxx> | |||
55 | #include <comphelper/flagguard.hxx> | |||
56 | #include <comphelper/interfacecontainer2.hxx> | |||
57 | #include <comphelper/profilezone.hxx> | |||
58 | #include "stylesettings.hxx" | |||
59 | #include <tools/urlobj.hxx> | |||
60 | ||||
61 | #include <helper/accessibilityclient.hxx> | |||
62 | #include <helper/unopropertyarrayhelper.hxx> | |||
63 | ||||
64 | using namespace ::com::sun::star; | |||
65 | ||||
66 | using ::com::sun::star::uno::Reference; | |||
67 | using ::com::sun::star::uno::UNO_QUERY; | |||
68 | using ::com::sun::star::lang::EventObject; | |||
69 | using ::com::sun::star::awt::XWindowListener2; | |||
70 | using ::com::sun::star::awt::XDockableWindowListener; | |||
71 | using ::com::sun::star::awt::XDevice; | |||
72 | using ::com::sun::star::awt::XStyleSettings; | |||
73 | using ::com::sun::star::lang::DisposedException; | |||
74 | using ::com::sun::star::style::VerticalAlignment; | |||
75 | using ::com::sun::star::style::VerticalAlignment_TOP; | |||
76 | using ::com::sun::star::style::VerticalAlignment_MIDDLE; | |||
77 | using ::com::sun::star::style::VerticalAlignment_BOTTOM; | |||
78 | ||||
79 | namespace WritingMode2 = ::com::sun::star::text::WritingMode2; | |||
80 | ||||
81 | ||||
82 | //= VCLXWindowImpl | |||
83 | ||||
84 | class VCLXWindowImpl | |||
85 | { | |||
86 | private: | |||
87 | typedef ::std::vector< VCLXWindow::Callback > CallbackArray; | |||
88 | ||||
89 | private: | |||
90 | VCLXWindow& mrAntiImpl; | |||
91 | ::toolkit::AccessibilityClient maAccFactory; | |||
92 | bool mbDisposed; | |||
93 | bool mbDrawingOntoParent; // no bit mask, is passed around by reference | |||
94 | bool mbEnableVisible; | |||
95 | bool mbDirectVisible; | |||
96 | ||||
97 | ::osl::Mutex maListenerContainerMutex; | |||
98 | ::comphelper::OInterfaceContainerHelper2 maWindow2Listeners; | |||
99 | ::comphelper::OInterfaceContainerHelper2 maDockableWindowListeners; | |||
100 | EventListenerMultiplexer maEventListeners; | |||
101 | FocusListenerMultiplexer maFocusListeners; | |||
102 | WindowListenerMultiplexer maWindowListeners; | |||
103 | KeyListenerMultiplexer maKeyListeners; | |||
104 | MouseListenerMultiplexer maMouseListeners; | |||
105 | MouseMotionListenerMultiplexer maMouseMotionListeners; | |||
106 | PaintListenerMultiplexer maPaintListeners; | |||
107 | VclContainerListenerMultiplexer maContainerListeners; | |||
108 | TopWindowListenerMultiplexer maTopWindowListeners; | |||
109 | ||||
110 | CallbackArray maCallbackEvents; | |||
111 | ImplSVEvent * mnCallbackEventId; | |||
112 | ||||
113 | public: | |||
114 | bool mbDisposing : 1; | |||
115 | bool mbDesignMode : 1; | |||
116 | bool mbSynthesizingVCLEvent : 1; | |||
117 | bool mbWithDefaultProps : 1; | |||
118 | ||||
119 | sal_uLong mnListenerLockLevel; | |||
120 | sal_Int16 mnWritingMode; | |||
121 | sal_Int16 mnContextWritingMode; | |||
122 | ||||
123 | std::unique_ptr<UnoPropertyArrayHelper> | |||
124 | mpPropHelper; | |||
125 | ||||
126 | css::uno::Reference< css::accessibility::XAccessibleContext > | |||
127 | mxAccessibleContext; | |||
128 | css::uno::Reference< css::awt::XGraphics > | |||
129 | mxViewGraphics; | |||
130 | css::uno::Reference< css::awt::XStyleSettings > | |||
131 | mxWindowStyleSettings; | |||
132 | ||||
133 | public: | |||
134 | bool& getDrawingOntoParent_ref() { return mbDrawingOntoParent; } | |||
135 | ||||
136 | public: | |||
137 | /** ctor | |||
138 | @param _pAntiImpl | |||
139 | the <type>VCLXWindow</type> instance which the object belongs to. Must | |||
140 | live longer then the object just being constructed. | |||
141 | */ | |||
142 | VCLXWindowImpl( VCLXWindow& _rAntiImpl, bool _bWithDefaultProps ); | |||
143 | ||||
144 | VCLXWindowImpl( const VCLXWindowImpl& ) = delete; | |||
145 | const VCLXWindowImpl& operator=(const VCLXWindowImpl&) = delete; | |||
146 | ||||
147 | /** synchronously mbEnableVisible | |||
148 | */ | |||
149 | void setEnableVisible( bool bEnableVisible ) { mbEnableVisible = bEnableVisible; } | |||
150 | bool isEnableVisible() const { return mbEnableVisible; } | |||
151 | /** synchronously mbDirectVisible; | |||
152 | */ | |||
153 | void setDirectVisible( bool bDirectVisible ) { mbDirectVisible = bDirectVisible; } | |||
154 | bool isDirectVisible() const { return mbDirectVisible; } | |||
155 | ||||
156 | /** impl-version of VCLXWindow::ImplExecuteAsyncWithoutSolarLock | |||
157 | */ | |||
158 | void callBackAsync( const VCLXWindow::Callback& i_callback ); | |||
159 | ||||
160 | /** notifies the object that its VCLXWindow is being disposed | |||
161 | */ | |||
162 | void disposing(); | |||
163 | ||||
164 | ::toolkit::AccessibilityClient& getAccessibleFactory() | |||
165 | { | |||
166 | return maAccFactory; | |||
167 | } | |||
168 | ||||
169 | Reference< XStyleSettings > getStyleSettings(); | |||
170 | ||||
171 | /** returns the container of registered XWindowListener2 listeners | |||
172 | */ | |||
173 | ::comphelper::OInterfaceContainerHelper2& getWindow2Listeners() { return maWindow2Listeners; } | |||
174 | ::comphelper::OInterfaceContainerHelper2& getDockableWindowListeners(){ return maDockableWindowListeners; } | |||
175 | EventListenerMultiplexer& getEventListeners() { return maEventListeners; } | |||
176 | FocusListenerMultiplexer& getFocusListeners() { return maFocusListeners; } | |||
177 | WindowListenerMultiplexer& getWindowListeners() { return maWindowListeners; } | |||
178 | KeyListenerMultiplexer& getKeyListeners() { return maKeyListeners; } | |||
179 | MouseListenerMultiplexer& getMouseListeners() { return maMouseListeners; } | |||
180 | MouseMotionListenerMultiplexer& getMouseMotionListeners() { return maMouseMotionListeners; } | |||
181 | PaintListenerMultiplexer& getPaintListeners() { return maPaintListeners; } | |||
182 | VclContainerListenerMultiplexer& getContainerListeners() { return maContainerListeners; } | |||
183 | TopWindowListenerMultiplexer& getTopWindowListeners() { return maTopWindowListeners; } | |||
184 | ||||
185 | private: | |||
186 | DECL_LINK( OnProcessCallbacks, void*, void )static void LinkStubOnProcessCallbacks(void *, void*); void OnProcessCallbacks (void*); | |||
187 | }; | |||
188 | ||||
189 | ||||
190 | VCLXWindowImpl::VCLXWindowImpl( VCLXWindow& _rAntiImpl, bool _bWithDefaultProps ) | |||
191 | :mrAntiImpl( _rAntiImpl ) | |||
192 | ,mbDisposed( false ) | |||
193 | ,mbDrawingOntoParent( false ) | |||
194 | ,mbEnableVisible(true) | |||
195 | ,mbDirectVisible(true) | |||
196 | ,maListenerContainerMutex( ) | |||
197 | ,maWindow2Listeners( maListenerContainerMutex ) | |||
198 | ,maDockableWindowListeners( maListenerContainerMutex ) | |||
199 | ,maEventListeners( _rAntiImpl ) | |||
200 | ,maFocusListeners( _rAntiImpl ) | |||
201 | ,maWindowListeners( _rAntiImpl ) | |||
202 | ,maKeyListeners( _rAntiImpl ) | |||
203 | ,maMouseListeners( _rAntiImpl ) | |||
204 | ,maMouseMotionListeners( _rAntiImpl ) | |||
205 | ,maPaintListeners( _rAntiImpl ) | |||
206 | ,maContainerListeners( _rAntiImpl ) | |||
207 | ,maTopWindowListeners( _rAntiImpl ) | |||
208 | ,mnCallbackEventId( nullptr ) | |||
209 | ,mbDisposing( false ) | |||
210 | ,mbDesignMode( false ) | |||
211 | ,mbSynthesizingVCLEvent( false ) | |||
212 | ,mbWithDefaultProps( _bWithDefaultProps ) | |||
213 | ,mnListenerLockLevel( 0 ) | |||
214 | ,mnWritingMode( WritingMode2::CONTEXT ) | |||
215 | ,mnContextWritingMode( WritingMode2::CONTEXT ) | |||
216 | { | |||
217 | } | |||
218 | ||||
219 | void VCLXWindowImpl::disposing() | |||
220 | { | |||
221 | SolarMutexGuard aGuard; | |||
222 | if ( mnCallbackEventId ) | |||
223 | Application::RemoveUserEvent( mnCallbackEventId ); | |||
224 | mnCallbackEventId = nullptr; | |||
225 | ||||
226 | mbDisposed= true; | |||
227 | ||||
228 | css::lang::EventObject aEvent; | |||
229 | aEvent.Source = mrAntiImpl; | |||
230 | ||||
231 | maDockableWindowListeners.disposeAndClear( aEvent ); | |||
232 | maEventListeners.disposeAndClear( aEvent ); | |||
233 | maFocusListeners.disposeAndClear( aEvent ); | |||
234 | maWindowListeners.disposeAndClear( aEvent ); | |||
235 | maKeyListeners.disposeAndClear( aEvent ); | |||
236 | maMouseListeners.disposeAndClear( aEvent ); | |||
237 | maMouseMotionListeners.disposeAndClear( aEvent ); | |||
238 | maPaintListeners.disposeAndClear( aEvent ); | |||
239 | maContainerListeners.disposeAndClear( aEvent ); | |||
240 | maTopWindowListeners.disposeAndClear( aEvent ); | |||
241 | ||||
242 | ::toolkit::WindowStyleSettings* pStyleSettings = static_cast< ::toolkit::WindowStyleSettings* >( mxWindowStyleSettings.get() ); | |||
243 | if ( pStyleSettings != nullptr ) | |||
244 | pStyleSettings->dispose(); | |||
245 | mxWindowStyleSettings.clear(); | |||
246 | } | |||
247 | ||||
248 | ||||
249 | void VCLXWindowImpl::callBackAsync( const VCLXWindow::Callback& i_callback ) | |||
250 | { | |||
251 | DBG_TESTSOLARMUTEX()do { DbgTestSolarMutex(); } while(false); | |||
252 | maCallbackEvents.push_back( i_callback ); | |||
253 | if ( !mnCallbackEventId ) | |||
254 | { | |||
255 | // ensure our VCLXWindow is not destroyed while the event is underway | |||
256 | mrAntiImpl.acquire(); | |||
257 | mnCallbackEventId = Application::PostUserEvent( LINK( this, VCLXWindowImpl, OnProcessCallbacks )::tools::detail::makeLink( ::tools::detail::castTo<VCLXWindowImpl *>(this), &VCLXWindowImpl::LinkStubOnProcessCallbacks ) ); | |||
258 | } | |||
259 | } | |||
260 | ||||
261 | ||||
262 | IMPL_LINK_NOARG(VCLXWindowImpl, OnProcessCallbacks, void*, void)void VCLXWindowImpl::LinkStubOnProcessCallbacks(void * instance , void* data) { return static_cast<VCLXWindowImpl *>(instance )->OnProcessCallbacks(data); } void VCLXWindowImpl::OnProcessCallbacks (__attribute__ ((unused)) void*) | |||
263 | { | |||
264 | const Reference< uno::XInterface > xKeepAlive( mrAntiImpl ); | |||
265 | ||||
266 | SAL_INFO("toolkit.controls", "OnProcessCallbacks grabbing solarmutex")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "toolkit.controls")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "OnProcessCallbacks grabbing solarmutex" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit.controls" ), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "266" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "OnProcessCallbacks grabbing solarmutex" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "OnProcessCallbacks grabbing solarmutex"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit.controls"), ( "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "266" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "OnProcessCallbacks grabbing solarmutex") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit.controls" ), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "266" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "OnProcessCallbacks grabbing solarmutex" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "OnProcessCallbacks grabbing solarmutex"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit.controls"), ( "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "266" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
267 | ||||
268 | // work on a copy of the callback array | |||
269 | CallbackArray aCallbacksCopy; | |||
270 | { | |||
271 | SolarMutexGuard aGuard; | |||
272 | aCallbacksCopy.swap(maCallbackEvents); | |||
273 | ||||
274 | // we acquired our VCLXWindow once before posting the event, release this one ref now | |||
275 | mrAntiImpl.release(); | |||
276 | ||||
277 | if ( !mnCallbackEventId ) | |||
278 | // we were disposed while waiting for the mutex to lock | |||
279 | return; | |||
280 | ||||
281 | mnCallbackEventId = nullptr; | |||
282 | } | |||
283 | ||||
284 | { | |||
285 | SAL_INFO("toolkit.controls", "OnProcessCallbacks relinquished solarmutex")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "toolkit.controls")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "OnProcessCallbacks relinquished solarmutex" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit.controls" ), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "285" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "OnProcessCallbacks relinquished solarmutex" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "OnProcessCallbacks relinquished solarmutex"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit.controls" ), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "285" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "OnProcessCallbacks relinquished solarmutex") == 1 ) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit.controls" ), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "285" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "OnProcessCallbacks relinquished solarmutex" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "OnProcessCallbacks relinquished solarmutex"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit.controls" ), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "285" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
286 | SolarMutexReleaser aReleaseSolar; | |||
287 | for (const auto& rCallback : aCallbacksCopy) | |||
288 | { | |||
289 | rCallback(); | |||
290 | } | |||
291 | } | |||
292 | } | |||
293 | ||||
294 | Reference< XStyleSettings > VCLXWindowImpl::getStyleSettings() | |||
295 | { | |||
296 | SolarMutexGuard aGuard; | |||
297 | if ( mbDisposed ) | |||
298 | throw DisposedException( OUString(), mrAntiImpl ); | |||
299 | if ( !mxWindowStyleSettings.is() ) | |||
300 | mxWindowStyleSettings = new ::toolkit::WindowStyleSettings( maListenerContainerMutex, mrAntiImpl ); | |||
301 | return mxWindowStyleSettings; | |||
302 | } | |||
303 | ||||
304 | ||||
305 | // Uses an out-parameter instead of return value, due to the object reference | |||
306 | ||||
307 | static void ImplInitWindowEvent( css::awt::WindowEvent& rEvent, vcl::Window const * pWindow ) | |||
308 | { | |||
309 | Point aPos = pWindow->GetPosPixel(); | |||
310 | Size aSz = pWindow->GetSizePixel(); | |||
311 | ||||
312 | rEvent.X = aPos.X(); | |||
313 | rEvent.Y = aPos.Y(); | |||
314 | ||||
315 | rEvent.Width = aSz.Width(); | |||
316 | rEvent.Height = aSz.Height(); | |||
317 | ||||
318 | pWindow->GetBorder( rEvent.LeftInset, rEvent.TopInset, rEvent.RightInset, rEvent.BottomInset ); | |||
319 | } | |||
320 | ||||
321 | VCLXWindow::VCLXWindow( bool _bWithDefaultProps ) | |||
322 | { | |||
323 | mpImpl.reset( new VCLXWindowImpl( *this, _bWithDefaultProps ) ); | |||
324 | } | |||
325 | ||||
326 | VCLXWindow::~VCLXWindow() | |||
327 | { | |||
328 | mpImpl.reset(); | |||
329 | ||||
330 | if ( GetWindow() ) | |||
331 | { | |||
332 | GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener )::tools::detail::makeLink( ::tools::detail::castTo<VCLXWindow *>(this), &VCLXWindow::LinkStubWindowEventListener) ); | |||
333 | GetWindow()->SetWindowPeer( nullptr, nullptr ); | |||
334 | GetWindow()->SetAccessible( nullptr ); | |||
335 | } | |||
336 | } | |||
337 | ||||
338 | ||||
339 | void VCLXWindow::ImplExecuteAsyncWithoutSolarLock( const Callback& i_callback ) | |||
340 | { | |||
341 | mpImpl->callBackAsync( i_callback ); | |||
342 | } | |||
343 | ||||
344 | ||||
345 | ::toolkit::IAccessibleFactory& VCLXWindow::getAccessibleFactory() | |||
346 | { | |||
347 | return mpImpl->getAccessibleFactory().getFactory(); | |||
348 | } | |||
349 | ||||
350 | void VCLXWindow::SetWindow( const VclPtr<vcl::Window> &pWindow ) | |||
351 | { | |||
352 | if ( GetWindow() ) | |||
353 | { | |||
354 | GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener )::tools::detail::makeLink( ::tools::detail::castTo<VCLXWindow *>(this), &VCLXWindow::LinkStubWindowEventListener) ); | |||
355 | // GetWindow()->DbgAssertNoEventListeners(); | |||
356 | } | |||
357 | ||||
358 | SetOutputDevice( pWindow ); | |||
359 | ||||
360 | if ( GetWindow() ) | |||
361 | { | |||
362 | GetWindow()->AddEventListener( LINK( this, VCLXWindow, WindowEventListener )::tools::detail::makeLink( ::tools::detail::castTo<VCLXWindow *>(this), &VCLXWindow::LinkStubWindowEventListener) ); | |||
363 | bool bDirectVisible = pWindow && pWindow->IsVisible(); | |||
364 | mpImpl->setDirectVisible( bDirectVisible ); | |||
365 | } | |||
366 | } | |||
367 | ||||
368 | void VCLXWindow::suspendVclEventListening( ) | |||
369 | { | |||
370 | ++mpImpl->mnListenerLockLevel; | |||
371 | } | |||
372 | ||||
373 | void VCLXWindow::resumeVclEventListening( ) | |||
374 | { | |||
375 | DBG_ASSERT( mpImpl->mnListenerLockLevel, "VCLXWindow::resumeVclEventListening: not suspended!" )do { if (true && (!(mpImpl->mnListenerLockLevel))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "375" ": "), "%s", "VCLXWindow::resumeVclEventListening: not suspended!" ); } } while (false); | |||
376 | --mpImpl->mnListenerLockLevel; | |||
377 | } | |||
378 | ||||
379 | void VCLXWindow::notifyWindowRemoved( vcl::Window const & _rWindow ) | |||
380 | { | |||
381 | if ( mpImpl->getContainerListeners().getLength() ) | |||
382 | { | |||
383 | awt::VclContainerEvent aEvent; | |||
384 | aEvent.Source = *this; | |||
385 | aEvent.Child = static_cast< XWindow* >( _rWindow.GetWindowPeer() ); | |||
386 | mpImpl->getContainerListeners().windowRemoved( aEvent ); | |||
387 | } | |||
388 | } | |||
389 | ||||
390 | IMPL_LINK( VCLXWindow, WindowEventListener, VclWindowEvent&, rEvent, void )void VCLXWindow::LinkStubWindowEventListener(void * instance, VclWindowEvent& data) { return static_cast<VCLXWindow *>(instance)->WindowEventListener(data); } void VCLXWindow ::WindowEventListener(VclWindowEvent& rEvent) | |||
391 | { | |||
392 | if ( mpImpl->mnListenerLockLevel ) | |||
393 | return; | |||
394 | ||||
395 | DBG_ASSERT( rEvent.GetWindow() && GetWindow(), "Window???" )do { if (true && (!(rEvent.GetWindow() && GetWindow ()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "395" ": "), "%s", "Window???"); } } while (false); | |||
396 | ProcessWindowEvent( rEvent ); | |||
397 | } | |||
398 | ||||
399 | namespace | |||
400 | { | |||
401 | struct CallWindow2Listener | |||
402 | { | |||
403 | CallWindow2Listener( ::comphelper::OInterfaceContainerHelper2& i_rWindow2Listeners, const bool i_bEnabled, const EventObject& i_rEvent ) | |||
404 | :m_rWindow2Listeners( i_rWindow2Listeners ) | |||
405 | ,m_bEnabled( i_bEnabled ) | |||
406 | ,m_aEvent( i_rEvent ) | |||
407 | { | |||
408 | } | |||
409 | ||||
410 | void operator()() | |||
411 | { | |||
412 | m_rWindow2Listeners.notifyEach( m_bEnabled ? &XWindowListener2::windowEnabled : &XWindowListener2::windowDisabled, m_aEvent ); | |||
413 | } | |||
414 | ||||
415 | ::comphelper::OInterfaceContainerHelper2& m_rWindow2Listeners; | |||
416 | const bool m_bEnabled; | |||
417 | const EventObject m_aEvent; | |||
418 | }; | |||
419 | } | |||
420 | ||||
421 | void VCLXWindow::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) | |||
422 | { | |||
423 | css::uno::Reference< css::uno::XInterface > xThis( static_cast<cppu::OWeakObject*>(this) ); | |||
424 | ||||
425 | switch ( rVclWindowEvent.GetId() ) | |||
426 | { | |||
427 | case VclEventId::WindowEnabled: | |||
428 | case VclEventId::WindowDisabled: | |||
429 | { | |||
430 | Callback aCallback = CallWindow2Listener( | |||
431 | mpImpl->getWindow2Listeners(), | |||
432 | ( VclEventId::WindowEnabled == rVclWindowEvent.GetId() ), | |||
433 | EventObject( *this ) | |||
434 | ); | |||
435 | ImplExecuteAsyncWithoutSolarLock( aCallback ); | |||
436 | } | |||
437 | break; | |||
438 | ||||
439 | case VclEventId::WindowPaint: | |||
440 | { | |||
441 | if ( mpImpl->getPaintListeners().getLength() ) | |||
442 | { | |||
443 | css::awt::PaintEvent aEvent; | |||
444 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
445 | aEvent.UpdateRect = AWTRectangle( *static_cast<tools::Rectangle*>(rVclWindowEvent.GetData()) ); | |||
446 | aEvent.Count = 0; | |||
447 | mpImpl->getPaintListeners().windowPaint( aEvent ); | |||
448 | } | |||
449 | } | |||
450 | break; | |||
451 | case VclEventId::WindowMove: | |||
452 | { | |||
453 | if ( mpImpl->getWindowListeners().getLength() ) | |||
454 | { | |||
455 | css::awt::WindowEvent aEvent; | |||
456 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
457 | ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); | |||
458 | mpImpl->getWindowListeners().windowMoved( aEvent ); | |||
459 | } | |||
460 | } | |||
461 | break; | |||
462 | case VclEventId::WindowResize: | |||
463 | { | |||
464 | if ( mpImpl->getWindowListeners().getLength() ) | |||
465 | { | |||
466 | css::awt::WindowEvent aEvent; | |||
467 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
468 | ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); | |||
469 | mpImpl->getWindowListeners().windowResized( aEvent ); | |||
470 | } | |||
471 | } | |||
472 | break; | |||
473 | case VclEventId::WindowShow: | |||
474 | { | |||
475 | if ( mpImpl->getWindowListeners().getLength() ) | |||
476 | { | |||
477 | css::awt::WindowEvent aEvent; | |||
478 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
479 | ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); | |||
480 | mpImpl->getWindowListeners().windowShown( aEvent ); | |||
481 | } | |||
482 | ||||
483 | // For TopWindows this means opened... | |||
484 | if ( mpImpl->getTopWindowListeners().getLength() ) | |||
485 | { | |||
486 | css::lang::EventObject aEvent; | |||
487 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
488 | mpImpl->getTopWindowListeners().windowOpened( aEvent ); | |||
489 | } | |||
490 | } | |||
491 | break; | |||
492 | case VclEventId::WindowHide: | |||
493 | { | |||
494 | if ( mpImpl->getWindowListeners().getLength() ) | |||
495 | { | |||
496 | css::awt::WindowEvent aEvent; | |||
497 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
498 | ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); | |||
499 | mpImpl->getWindowListeners().windowHidden( aEvent ); | |||
500 | } | |||
501 | ||||
502 | // For TopWindows this means closed... | |||
503 | if ( mpImpl->getTopWindowListeners().getLength() ) | |||
504 | { | |||
505 | css::lang::EventObject aEvent; | |||
506 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
507 | mpImpl->getTopWindowListeners().windowClosed( aEvent ); | |||
508 | } | |||
509 | } | |||
510 | break; | |||
511 | case VclEventId::WindowActivate: | |||
512 | case VclEventId::WindowDeactivate: | |||
513 | { | |||
514 | if (!mpImpl->getTopWindowListeners().getLength()) | |||
515 | return; | |||
516 | ||||
517 | // Suppress events which are unlikely to be interesting to our listeners. | |||
518 | vcl::Window* pWin = static_cast<vcl::Window*>(rVclWindowEvent.GetData()); | |||
519 | bool bSuppress = false; | |||
520 | ||||
521 | while (pWin) | |||
522 | { | |||
523 | // Either the event came from the same window, from its | |||
524 | // child, or from a child of its border window (e.g. | |||
525 | // menubar or notebookbar). | |||
526 | if (pWin->GetWindow(GetWindowType::Client) == GetWindow()) | |||
527 | return; | |||
528 | ||||
529 | if (pWin->IsMenuFloatingWindow()) | |||
530 | bSuppress = true; | |||
531 | ||||
532 | if (pWin->GetType() == WindowType::FLOATINGWINDOW && | |||
533 | static_cast<FloatingWindow*>(pWin)->IsInPopupMode()) | |||
534 | bSuppress = true; | |||
535 | ||||
536 | // Otherwise, don't suppress if the event came from a different frame. | |||
537 | if (!bSuppress && pWin->GetWindow(GetWindowType::Frame) == pWin) | |||
538 | break; | |||
539 | ||||
540 | pWin = pWin->GetWindow(GetWindowType::RealParent); | |||
541 | } | |||
542 | ||||
543 | css::lang::EventObject aEvent; | |||
544 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
545 | if (rVclWindowEvent.GetId() == VclEventId::WindowActivate) | |||
546 | mpImpl->getTopWindowListeners().windowActivated( aEvent ); | |||
547 | else | |||
548 | mpImpl->getTopWindowListeners().windowDeactivated( aEvent ); | |||
549 | } | |||
550 | break; | |||
551 | case VclEventId::WindowClose: | |||
552 | { | |||
553 | if ( mpImpl->getDockableWindowListeners().getLength() ) | |||
554 | { | |||
555 | css::lang::EventObject aEvent; | |||
556 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
557 | mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::closed, aEvent ); | |||
558 | } | |||
559 | if ( mpImpl->getTopWindowListeners().getLength() ) | |||
560 | { | |||
561 | css::lang::EventObject aEvent; | |||
562 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
563 | mpImpl->getTopWindowListeners().windowClosing( aEvent ); | |||
564 | } | |||
565 | } | |||
566 | break; | |||
567 | case VclEventId::ControlGetFocus: | |||
568 | case VclEventId::WindowGetFocus: | |||
569 | { | |||
570 | if ( ( rVclWindowEvent.GetWindow()->IsCompoundControl() | |||
571 | && rVclWindowEvent.GetId() == VclEventId::ControlGetFocus | |||
572 | ) | |||
573 | || ( !rVclWindowEvent.GetWindow()->IsCompoundControl() | |||
574 | && rVclWindowEvent.GetId() == VclEventId::WindowGetFocus | |||
575 | ) | |||
576 | ) | |||
577 | { | |||
578 | if ( mpImpl->getFocusListeners().getLength() ) | |||
579 | { | |||
580 | css::awt::FocusEvent aEvent; | |||
581 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
582 | aEvent.FocusFlags = static_cast<sal_Int16>(rVclWindowEvent.GetWindow()->GetGetFocusFlags()); | |||
583 | aEvent.Temporary = false; | |||
584 | mpImpl->getFocusListeners().focusGained( aEvent ); | |||
585 | } | |||
586 | } | |||
587 | } | |||
588 | break; | |||
589 | case VclEventId::ControlLoseFocus: | |||
590 | case VclEventId::WindowLoseFocus: | |||
591 | { | |||
592 | if ( ( rVclWindowEvent.GetWindow()->IsCompoundControl() | |||
593 | && rVclWindowEvent.GetId() == VclEventId::ControlLoseFocus | |||
594 | ) | |||
595 | || ( !rVclWindowEvent.GetWindow()->IsCompoundControl() | |||
596 | && rVclWindowEvent.GetId() == VclEventId::WindowLoseFocus | |||
597 | ) | |||
598 | ) | |||
599 | { | |||
600 | if ( mpImpl->getFocusListeners().getLength() ) | |||
601 | { | |||
602 | css::awt::FocusEvent aEvent; | |||
603 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
604 | aEvent.FocusFlags = static_cast<sal_Int16>(rVclWindowEvent.GetWindow()->GetGetFocusFlags()); | |||
605 | aEvent.Temporary = false; | |||
606 | ||||
607 | vcl::Window* pNext = Application::GetFocusWindow(); | |||
608 | if ( pNext ) | |||
609 | { | |||
610 | // Don't care about internals if this control is compound | |||
611 | vcl::Window* pNextC = pNext; | |||
612 | while ( pNextC && !pNextC->IsCompoundControl() ) | |||
613 | pNextC = pNextC->GetParent(); | |||
614 | if ( pNextC ) | |||
615 | pNext = pNextC; | |||
616 | ||||
617 | pNext->GetComponentInterface(); | |||
618 | aEvent.NextFocus = static_cast<cppu::OWeakObject*>(pNext->GetWindowPeer()); | |||
619 | } | |||
620 | mpImpl->getFocusListeners().focusLost( aEvent ); | |||
621 | } | |||
622 | } | |||
623 | } | |||
624 | break; | |||
625 | case VclEventId::WindowMinimize: | |||
626 | { | |||
627 | if ( mpImpl->getTopWindowListeners().getLength() ) | |||
628 | { | |||
629 | css::lang::EventObject aEvent; | |||
630 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
631 | mpImpl->getTopWindowListeners().windowMinimized( aEvent ); | |||
632 | } | |||
633 | } | |||
634 | break; | |||
635 | case VclEventId::WindowNormalize: | |||
636 | { | |||
637 | if ( mpImpl->getTopWindowListeners().getLength() ) | |||
638 | { | |||
639 | css::lang::EventObject aEvent; | |||
640 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
641 | mpImpl->getTopWindowListeners().windowNormalized( aEvent ); | |||
642 | } | |||
643 | } | |||
644 | break; | |||
645 | case VclEventId::WindowKeyInput: | |||
646 | { | |||
647 | if ( mpImpl->getKeyListeners().getLength() ) | |||
648 | { | |||
649 | css::awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( | |||
650 | *static_cast<KeyEvent*>(rVclWindowEvent.GetData()), *this | |||
651 | ) ); | |||
652 | mpImpl->getKeyListeners().keyPressed( aEvent ); | |||
653 | } | |||
654 | } | |||
655 | break; | |||
656 | case VclEventId::WindowKeyUp: | |||
657 | { | |||
658 | if ( mpImpl->getKeyListeners().getLength() ) | |||
659 | { | |||
660 | css::awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( | |||
661 | *static_cast<KeyEvent*>(rVclWindowEvent.GetData()), *this | |||
662 | ) ); | |||
663 | mpImpl->getKeyListeners().keyReleased( aEvent ); | |||
664 | } | |||
665 | } | |||
666 | break; | |||
667 | case VclEventId::WindowCommand: | |||
668 | { | |||
669 | CommandEvent* pCmdEvt = static_cast<CommandEvent*>(rVclWindowEvent.GetData()); | |||
670 | if ( mpImpl->getMouseListeners().getLength() && ( pCmdEvt->GetCommand() == CommandEventId::ContextMenu ) ) | |||
671 | { | |||
672 | // CommandEventId::ContextMenu: send as mousePressed with PopupTrigger = true ... | |||
673 | Point aWhere = static_cast< CommandEvent* >( rVclWindowEvent.GetData() )->GetMousePosPixel(); | |||
674 | if ( !pCmdEvt->IsMouseEvent() ) | |||
675 | { // for keyboard events, we set the coordinates to -1,-1. This is a slight HACK, but the current API | |||
676 | // handles a context menu command as special case of a mouse event, which is simply wrong. | |||
677 | // Without extending the API, we would not have another chance to notify listeners of a | |||
678 | // keyboard-triggered context menu request | |||
679 | aWhere = Point( -1, -1 ); | |||
680 | } | |||
681 | ||||
682 | MouseEvent aMEvt( aWhere, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT(sal_uInt16(0x0001)), 0 ); | |||
683 | awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( aMEvt, *this ) ); | |||
684 | aEvent.PopupTrigger = true; | |||
685 | ||||
686 | Callback aCallback = [ this, aEvent ]() | |||
687 | { this->mpImpl->getMouseListeners().mousePressed( aEvent ); }; | |||
688 | ||||
689 | ImplExecuteAsyncWithoutSolarLock( aCallback ); | |||
690 | } | |||
691 | } | |||
692 | break; | |||
693 | case VclEventId::WindowMouseMove: | |||
694 | { | |||
695 | MouseEvent* pMouseEvt = static_cast<MouseEvent*>(rVclWindowEvent.GetData()); | |||
696 | if ( mpImpl->getMouseListeners().getLength() && ( pMouseEvt->IsEnterWindow() || pMouseEvt->IsLeaveWindow() ) ) | |||
697 | { | |||
698 | awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *pMouseEvt, *this ) ); | |||
699 | bool const isEnter(pMouseEvt->IsEnterWindow()); | |||
700 | Callback aCallback = [ this, isEnter, aEvent ]() | |||
701 | { MouseListenerMultiplexer& rMouseListeners = this->mpImpl->getMouseListeners(); | |||
702 | isEnter | |||
703 | ? rMouseListeners.mouseEntered(aEvent) | |||
704 | : rMouseListeners.mouseExited(aEvent); }; | |||
705 | ||||
706 | ImplExecuteAsyncWithoutSolarLock( aCallback ); | |||
707 | } | |||
708 | ||||
709 | if ( mpImpl->getMouseMotionListeners().getLength() && !pMouseEvt->IsEnterWindow() && !pMouseEvt->IsLeaveWindow() ) | |||
710 | { | |||
711 | awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *pMouseEvt, *this ) ); | |||
712 | aEvent.ClickCount = 0; | |||
713 | if ( pMouseEvt->GetMode() & MouseEventModifiers::SIMPLEMOVE ) | |||
714 | mpImpl->getMouseMotionListeners().mouseMoved( aEvent ); | |||
715 | else | |||
716 | mpImpl->getMouseMotionListeners().mouseDragged( aEvent ); | |||
717 | } | |||
718 | } | |||
719 | break; | |||
720 | case VclEventId::WindowMouseButtonDown: | |||
721 | { | |||
722 | if ( mpImpl->getMouseListeners().getLength() ) | |||
723 | { | |||
724 | awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *static_cast<MouseEvent*>(rVclWindowEvent.GetData()), *this ) ); | |||
725 | Callback aCallback = [ this, aEvent ]() | |||
726 | { this->mpImpl->getMouseListeners().mousePressed( aEvent ); }; | |||
727 | ImplExecuteAsyncWithoutSolarLock( aCallback ); | |||
728 | } | |||
729 | } | |||
730 | break; | |||
731 | case VclEventId::WindowMouseButtonUp: | |||
732 | { | |||
733 | if ( mpImpl->getMouseListeners().getLength() ) | |||
734 | { | |||
735 | awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *static_cast<MouseEvent*>(rVclWindowEvent.GetData()), *this ) ); | |||
736 | ||||
737 | Callback aCallback = [ this, aEvent ]() | |||
738 | { this->mpImpl->getMouseListeners().mouseReleased( aEvent ); }; | |||
739 | ImplExecuteAsyncWithoutSolarLock( aCallback ); | |||
740 | } | |||
741 | } | |||
742 | break; | |||
743 | case VclEventId::WindowStartDocking: | |||
744 | { | |||
745 | if ( mpImpl->getDockableWindowListeners().getLength() ) | |||
746 | { | |||
747 | DockingData *pData = static_cast<DockingData*>(rVclWindowEvent.GetData()); | |||
748 | ||||
749 | if( pData ) | |||
750 | { | |||
751 | css::awt::DockingEvent aEvent; | |||
752 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
753 | aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect ); | |||
754 | aEvent.MousePos.X = pData->maMousePos.X(); | |||
755 | aEvent.MousePos.Y = pData->maMousePos.Y(); | |||
756 | aEvent.bLiveMode = false; | |||
757 | aEvent.bInteractive = true; | |||
758 | ||||
759 | mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::startDocking, aEvent ); | |||
760 | } | |||
761 | } | |||
762 | } | |||
763 | break; | |||
764 | case VclEventId::WindowDocking: | |||
765 | { | |||
766 | if ( mpImpl->getDockableWindowListeners().getLength() ) | |||
767 | { | |||
768 | DockingData *pData = static_cast<DockingData*>(rVclWindowEvent.GetData()); | |||
769 | ||||
770 | if( pData ) | |||
771 | { | |||
772 | css::awt::DockingEvent aEvent; | |||
773 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
774 | aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect ); | |||
775 | aEvent.MousePos.X = pData->maMousePos.X(); | |||
776 | aEvent.MousePos.Y = pData->maMousePos.Y(); | |||
777 | aEvent.bLiveMode = false; | |||
778 | aEvent.bInteractive = true; | |||
779 | ||||
780 | Reference< XDockableWindowListener > xFirstListener; | |||
781 | ::comphelper::OInterfaceIteratorHelper2 aIter( mpImpl->getDockableWindowListeners() ); | |||
782 | while ( aIter.hasMoreElements() && !xFirstListener.is() ) | |||
783 | { | |||
784 | xFirstListener.set( aIter.next(), UNO_QUERY ); | |||
785 | } | |||
786 | ||||
787 | css::awt::DockingData aDockingData = | |||
788 | xFirstListener->docking( aEvent ); | |||
789 | pData->maTrackRect = VCLRectangle( aDockingData.TrackingRectangle ); | |||
790 | pData->mbFloating = aDockingData.bFloating; | |||
791 | } | |||
792 | } | |||
793 | } | |||
794 | break; | |||
795 | case VclEventId::WindowEndDocking: | |||
796 | { | |||
797 | if ( mpImpl->getDockableWindowListeners().getLength() ) | |||
798 | { | |||
799 | EndDockingData *pData = static_cast<EndDockingData*>(rVclWindowEvent.GetData()); | |||
800 | ||||
801 | if( pData ) | |||
802 | { | |||
803 | css::awt::EndDockingEvent aEvent; | |||
804 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
805 | aEvent.WindowRectangle = AWTRectangle( pData->maWindowRect ); | |||
806 | aEvent.bFloating = pData->mbFloating; | |||
807 | aEvent.bCancelled = pData->mbCancelled; | |||
808 | mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endDocking, aEvent ); | |||
809 | } | |||
810 | } | |||
811 | } | |||
812 | break; | |||
813 | case VclEventId::WindowPrepareToggleFloating: | |||
814 | { | |||
815 | if ( mpImpl->getDockableWindowListeners().getLength() ) | |||
816 | { | |||
817 | sal_Bool *p_bFloating = static_cast<sal_Bool*>(rVclWindowEvent.GetData()); | |||
818 | ||||
819 | css::lang::EventObject aEvent; | |||
820 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
821 | ||||
822 | Reference< XDockableWindowListener > xFirstListener; | |||
823 | ::comphelper::OInterfaceIteratorHelper2 aIter( mpImpl->getDockableWindowListeners() ); | |||
824 | while ( aIter.hasMoreElements() && !xFirstListener.is() ) | |||
825 | { | |||
826 | xFirstListener.set( aIter.next(), UNO_QUERY ); | |||
827 | } | |||
828 | ||||
829 | *p_bFloating = xFirstListener->prepareToggleFloatingMode( aEvent ); | |||
830 | } | |||
831 | } | |||
832 | break; | |||
833 | case VclEventId::WindowToggleFloating: | |||
834 | { | |||
835 | if ( mpImpl->getDockableWindowListeners().getLength() ) | |||
836 | { | |||
837 | css::lang::EventObject aEvent; | |||
838 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
839 | mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::toggleFloatingMode, aEvent ); | |||
840 | } | |||
841 | } | |||
842 | break; | |||
843 | case VclEventId::WindowEndPopupMode: | |||
844 | { | |||
845 | if ( mpImpl->getDockableWindowListeners().getLength() ) | |||
846 | { | |||
847 | EndPopupModeData *pData = static_cast<EndPopupModeData*>(rVclWindowEvent.GetData()); | |||
848 | ||||
849 | if( pData ) | |||
850 | { | |||
851 | css::awt::EndPopupModeEvent aEvent; | |||
852 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | |||
853 | aEvent.FloatingPosition.X = pData->maFloatingPos.X(); | |||
854 | aEvent.FloatingPosition.Y = pData->maFloatingPos.Y(); | |||
855 | aEvent.bTearoff = pData->mbTearoff; | |||
856 | mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endPopupMode, aEvent ); | |||
857 | } | |||
858 | } | |||
859 | } | |||
860 | break; | |||
861 | default: break; | |||
862 | } | |||
863 | } | |||
864 | ||||
865 | uno::Reference< accessibility::XAccessibleContext > VCLXWindow::CreateAccessibleContext() | |||
866 | { | |||
867 | SolarMutexGuard aGuard; | |||
868 | return getAccessibleFactory().createAccessibleContext( this ); | |||
869 | } | |||
870 | ||||
871 | void VCLXWindow::SetSynthesizingVCLEvent( bool _b ) | |||
872 | { | |||
873 | mpImpl->mbSynthesizingVCLEvent = _b; | |||
874 | } | |||
875 | ||||
876 | bool VCLXWindow::IsSynthesizingVCLEvent() const | |||
877 | { | |||
878 | return mpImpl->mbSynthesizingVCLEvent; | |||
879 | } | |||
880 | ||||
881 | Size VCLXWindow::ImplCalcWindowSize( const Size& rOutSz ) const | |||
882 | { | |||
883 | Size aSz = rOutSz; | |||
884 | ||||
885 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
886 | if ( pWindow ) | |||
887 | { | |||
888 | sal_Int32 nLeft, nTop, nRight, nBottom; | |||
889 | pWindow->GetBorder( nLeft, nTop, nRight, nBottom ); | |||
890 | aSz.AdjustWidth(nLeft+nRight ); | |||
891 | aSz.AdjustHeight(nTop+nBottom ); | |||
892 | } | |||
893 | return aSz; | |||
894 | } | |||
895 | ||||
896 | ||||
897 | // css::lang::XUnoTunnel | |||
898 | UNO3_GETIMPLEMENTATION2_IMPL(VCLXWindow, VCLXDevice)namespace { class theVCLXWindowUnoTunnelId : public rtl::Static < UnoTunnelIdInit, theVCLXWindowUnoTunnelId> {}; } const css::uno::Sequence< sal_Int8 > & VCLXWindow::getUnoTunnelId () throw() { return theVCLXWindowUnoTunnelId::get().getSeq(); }sal_Int64 VCLXWindow::getSomething( const css::uno::Sequence < sal_Int8 >& rId ) { if( isUnoTunnelId<VCLXWindow >(rId) ) { return sal::static_int_cast<sal_Int64>(reinterpret_cast <sal_IntPtr>(this)); } else { return VCLXDevice::getSomething ( rId ); } }; | |||
899 | ||||
900 | ||||
901 | // css::lang::Component | |||
902 | void VCLXWindow::dispose( ) | |||
903 | { | |||
904 | SolarMutexGuard aGuard; | |||
905 | ||||
906 | mpImpl->mxViewGraphics = nullptr; | |||
907 | ||||
908 | if ( mpImpl->mbDisposing ) | |||
909 | return; | |||
910 | ||||
911 | mpImpl->mbDisposing = true; | |||
912 | ||||
913 | mpImpl->disposing(); | |||
914 | ||||
915 | if ( GetWindow() ) | |||
916 | { | |||
917 | VclPtr<OutputDevice> pOutDev = GetOutputDevice(); | |||
918 | SetWindow( nullptr ); // so that handlers are logged off, if necessary (virtual) | |||
919 | SetOutputDevice( nullptr ); | |||
920 | pOutDev.disposeAndClear(); | |||
921 | } | |||
922 | ||||
923 | // #i14103# dispose the accessible context after the window has been destroyed, | |||
924 | // otherwise the old value in the child event fired in VCLXAccessibleComponent::ProcessWindowEvent() | |||
925 | // for VclEventId::WindowChildDestroyed contains a reference to an already disposed accessible object | |||
926 | try | |||
927 | { | |||
928 | css::uno::Reference< css::lang::XComponent > xComponent( mpImpl->mxAccessibleContext, css::uno::UNO_QUERY ); | |||
929 | if ( xComponent.is() ) | |||
930 | xComponent->dispose(); | |||
931 | } | |||
932 | catch ( const css::uno::Exception& ) | |||
933 | { | |||
934 | OSL_FAIL( "VCLXWindow::dispose: could not dispose the accessible context!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "934" ": "), "%s", "VCLXWindow::dispose: could not dispose the accessible context!" ); } } while (false); | |||
935 | } | |||
936 | mpImpl->mxAccessibleContext.clear(); | |||
937 | ||||
938 | mpImpl->mbDisposing = false; | |||
939 | } | |||
940 | ||||
941 | void VCLXWindow::addEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) | |||
942 | { | |||
943 | SolarMutexGuard aGuard; | |||
944 | ||||
945 | mpImpl->getEventListeners().addInterface( rxListener ); | |||
946 | } | |||
947 | ||||
948 | void VCLXWindow::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) | |||
949 | { | |||
950 | SolarMutexGuard aGuard; | |||
951 | ||||
952 | mpImpl->getEventListeners().removeInterface( rxListener ); | |||
953 | } | |||
954 | ||||
955 | ||||
956 | // css::awt::XWindow | |||
957 | void VCLXWindow::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) | |||
958 | { | |||
959 | SolarMutexGuard aGuard; | |||
960 | comphelper::ProfileZone aZone("setPosSize"); | |||
961 | ||||
962 | if ( GetWindow() ) | |||
963 | { | |||
964 | if( vcl::Window::GetDockingManager()->IsDockable( GetWindow() ) ) | |||
965 | vcl::Window::GetDockingManager()->SetPosSizePixel( GetWindow() , X, Y, Width, Height, static_cast<PosSizeFlags>(Flags) ); | |||
966 | else | |||
967 | GetWindow()->setPosSizePixel( X, Y, Width, Height, static_cast<PosSizeFlags>(Flags) ); | |||
968 | } | |||
969 | } | |||
970 | ||||
971 | css::awt::Rectangle VCLXWindow::getPosSize( ) | |||
972 | { | |||
973 | SolarMutexGuard aGuard; | |||
974 | ||||
975 | css::awt::Rectangle aBounds; | |||
976 | if ( GetWindow() ) | |||
977 | { | |||
978 | if( vcl::Window::GetDockingManager()->IsDockable( GetWindow() ) ) | |||
979 | aBounds = AWTRectangle( vcl::Window::GetDockingManager()->GetPosSizePixel( GetWindow() ) ); | |||
980 | else | |||
981 | aBounds = AWTRectangle( tools::Rectangle( GetWindow()->GetPosPixel(), GetWindow()->GetSizePixel() ) ); | |||
982 | } | |||
983 | ||||
984 | return aBounds; | |||
985 | } | |||
986 | ||||
987 | void VCLXWindow::setVisible( sal_Bool bVisible ) | |||
988 | { | |||
989 | SolarMutexGuard aGuard; | |||
990 | ||||
991 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
992 | if ( pWindow ) | |||
993 | { | |||
994 | mpImpl->setDirectVisible( bVisible ); | |||
995 | pWindow->Show( bVisible && mpImpl->isEnableVisible() ); | |||
996 | } | |||
997 | } | |||
998 | ||||
999 | void VCLXWindow::setEnable( sal_Bool bEnable ) | |||
1000 | { | |||
1001 | SolarMutexGuard aGuard; | |||
1002 | ||||
1003 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
1004 | if ( pWindow ) | |||
1005 | { | |||
1006 | pWindow->Enable( bEnable, false ); // #95824# without children! | |||
1007 | pWindow->EnableInput( bEnable ); | |||
1008 | } | |||
1009 | } | |||
1010 | ||||
1011 | void VCLXWindow::setFocus( ) | |||
1012 | { | |||
1013 | SolarMutexGuard aGuard; | |||
1014 | ||||
1015 | if ( GetWindow() ) | |||
1016 | GetWindow()->GrabFocus(); | |||
1017 | } | |||
1018 | ||||
1019 | void VCLXWindow::addWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rxListener ) | |||
1020 | { | |||
1021 | SolarMutexGuard aGuard; | |||
1022 | ||||
1023 | mpImpl->getWindowListeners().addInterface( rxListener ); | |||
1024 | ||||
1025 | Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY ); | |||
1026 | if ( xListener2.is() ) | |||
1027 | mpImpl->getWindow2Listeners().addInterface( xListener2 ); | |||
1028 | ||||
1029 | // #100119# Get all resize events, even if height or width 0, or invisible | |||
1030 | if ( GetWindow() ) | |||
1031 | GetWindow()->EnableAllResize(); | |||
1032 | } | |||
1033 | ||||
1034 | void VCLXWindow::removeWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rxListener ) | |||
1035 | { | |||
1036 | SolarMutexGuard aGuard; | |||
1037 | ||||
1038 | Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY ); | |||
1039 | if ( xListener2.is() ) | |||
1040 | mpImpl->getWindow2Listeners().removeInterface( xListener2 ); | |||
1041 | ||||
1042 | mpImpl->getWindowListeners().removeInterface( rxListener ); | |||
1043 | } | |||
1044 | ||||
1045 | void VCLXWindow::addFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rxListener ) | |||
1046 | { | |||
1047 | SolarMutexGuard aGuard; | |||
1048 | mpImpl->getFocusListeners().addInterface( rxListener ); | |||
1049 | } | |||
1050 | ||||
1051 | void VCLXWindow::removeFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rxListener ) | |||
1052 | { | |||
1053 | SolarMutexGuard aGuard; | |||
1054 | mpImpl->getFocusListeners().removeInterface( rxListener ); | |||
1055 | } | |||
1056 | ||||
1057 | void VCLXWindow::addKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rxListener ) | |||
1058 | { | |||
1059 | SolarMutexGuard aGuard; | |||
1060 | mpImpl->getKeyListeners().addInterface( rxListener ); | |||
1061 | } | |||
1062 | ||||
1063 | void VCLXWindow::removeKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rxListener ) | |||
1064 | { | |||
1065 | SolarMutexGuard aGuard; | |||
1066 | mpImpl->getKeyListeners().removeInterface( rxListener ); | |||
1067 | } | |||
1068 | ||||
1069 | void VCLXWindow::addMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rxListener ) | |||
1070 | { | |||
1071 | SolarMutexGuard aGuard; | |||
1072 | mpImpl->getMouseListeners().addInterface( rxListener ); | |||
1073 | } | |||
1074 | ||||
1075 | void VCLXWindow::removeMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rxListener ) | |||
1076 | { | |||
1077 | SolarMutexGuard aGuard; | |||
1078 | mpImpl->getMouseListeners().removeInterface( rxListener ); | |||
1079 | } | |||
1080 | ||||
1081 | void VCLXWindow::addMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rxListener ) | |||
1082 | { | |||
1083 | SolarMutexGuard aGuard; | |||
1084 | mpImpl->getMouseMotionListeners().addInterface( rxListener ); | |||
1085 | } | |||
1086 | ||||
1087 | void VCLXWindow::removeMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rxListener ) | |||
1088 | { | |||
1089 | SolarMutexGuard aGuard; | |||
1090 | mpImpl->getMouseMotionListeners().removeInterface( rxListener ); | |||
1091 | } | |||
1092 | ||||
1093 | void VCLXWindow::addPaintListener( const css::uno::Reference< css::awt::XPaintListener >& rxListener ) | |||
1094 | { | |||
1095 | SolarMutexGuard aGuard; | |||
1096 | mpImpl->getPaintListeners().addInterface( rxListener ); | |||
1097 | } | |||
1098 | ||||
1099 | void VCLXWindow::removePaintListener( const css::uno::Reference< css::awt::XPaintListener >& rxListener ) | |||
1100 | { | |||
1101 | SolarMutexGuard aGuard; | |||
1102 | mpImpl->getPaintListeners().removeInterface( rxListener ); | |||
1103 | } | |||
1104 | ||||
1105 | // css::awt::XWindowPeer | |||
1106 | css::uno::Reference< css::awt::XToolkit > VCLXWindow::getToolkit( ) | |||
1107 | { | |||
1108 | // no guard. nothing to guard here. | |||
1109 | // 82463 - 12/21/00 - fs | |||
1110 | return Application::GetVCLToolkit(); | |||
1111 | } | |||
1112 | ||||
1113 | void VCLXWindow::setPointer( const css::uno::Reference< css::awt::XPointer >& rxPointer ) | |||
1114 | { | |||
1115 | SolarMutexGuard aGuard; | |||
1116 | ||||
1117 | VCLXPointer* pPointer = comphelper::getUnoTunnelImplementation<VCLXPointer>( rxPointer ); | |||
1118 | if ( pPointer && GetWindow() ) | |||
1119 | GetWindow()->SetPointer( pPointer->GetPointer() ); | |||
1120 | } | |||
1121 | ||||
1122 | void VCLXWindow::setBackground( sal_Int32 nColor ) | |||
1123 | { | |||
1124 | SolarMutexGuard aGuard; | |||
1125 | ||||
1126 | if ( !GetWindow() ) | |||
1127 | return; | |||
1128 | ||||
1129 | Color aColor(nColor); | |||
1130 | GetWindow()->SetBackground( aColor ); | |||
1131 | GetWindow()->SetControlBackground( aColor ); | |||
1132 | ||||
1133 | WindowType eWinType = GetWindow()->GetType(); | |||
1134 | if ( ( eWinType == WindowType::WINDOW ) || | |||
1135 | ( eWinType == WindowType::WORKWINDOW ) || | |||
1136 | ( eWinType == WindowType::FLOATINGWINDOW ) ) | |||
1137 | { | |||
1138 | GetWindow()->Invalidate(); | |||
1139 | } | |||
1140 | } | |||
1141 | ||||
1142 | void VCLXWindow::invalidate( sal_Int16 nInvalidateFlags ) | |||
1143 | { | |||
1144 | SolarMutexGuard aGuard; | |||
1145 | ||||
1146 | if ( GetWindow() ) | |||
1147 | GetWindow()->Invalidate( static_cast<InvalidateFlags>(nInvalidateFlags) ); | |||
1148 | } | |||
1149 | ||||
1150 | void VCLXWindow::invalidateRect( const css::awt::Rectangle& rRect, sal_Int16 nInvalidateFlags ) | |||
1151 | { | |||
1152 | SolarMutexGuard aGuard; | |||
1153 | ||||
1154 | if ( GetWindow() ) | |||
1155 | GetWindow()->Invalidate( VCLRectangle(rRect), static_cast<InvalidateFlags>(nInvalidateFlags) ); | |||
1156 | } | |||
1157 | ||||
1158 | ||||
1159 | // css::awt::XVclWindowPeer | |||
1160 | sal_Bool VCLXWindow::isChild( const css::uno::Reference< css::awt::XWindowPeer >& rxPeer ) | |||
1161 | { | |||
1162 | SolarMutexGuard aGuard; | |||
1163 | ||||
1164 | bool bIsChild = false; | |||
1165 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
1166 | if ( pWindow ) | |||
1167 | { | |||
1168 | VclPtr<vcl::Window> pPeerWindow = VCLUnoHelper::GetWindow( rxPeer ); | |||
1169 | bIsChild = pPeerWindow && pWindow->IsChild( pPeerWindow ); | |||
1170 | } | |||
1171 | ||||
1172 | return bIsChild; | |||
1173 | } | |||
1174 | ||||
1175 | void VCLXWindow::setDesignMode( sal_Bool bOn ) | |||
1176 | { | |||
1177 | SolarMutexGuard aGuard; | |||
1178 | ||||
1179 | mpImpl->mbDesignMode = bOn; | |||
1180 | } | |||
1181 | ||||
1182 | sal_Bool VCLXWindow::isDesignMode( ) | |||
1183 | { | |||
1184 | SolarMutexGuard aGuard; | |||
1185 | return mpImpl->mbDesignMode; | |||
1186 | } | |||
1187 | ||||
1188 | void VCLXWindow::enableClipSiblings( sal_Bool bClip ) | |||
1189 | { | |||
1190 | SolarMutexGuard aGuard; | |||
1191 | ||||
1192 | if ( GetWindow() ) | |||
1193 | GetWindow()->EnableClipSiblings( bClip ); | |||
1194 | } | |||
1195 | ||||
1196 | void VCLXWindow::setForeground( sal_Int32 nColor ) | |||
1197 | { | |||
1198 | SolarMutexGuard aGuard; | |||
1199 | ||||
1200 | if ( GetWindow() ) | |||
1201 | { | |||
1202 | GetWindow()->SetControlForeground( Color(nColor) ); | |||
1203 | } | |||
1204 | } | |||
1205 | ||||
1206 | void VCLXWindow::setControlFont( const css::awt::FontDescriptor& rFont ) | |||
1207 | { | |||
1208 | SolarMutexGuard aGuard; | |||
1209 | ||||
1210 | if ( GetWindow() ) | |||
| ||||
1211 | GetWindow()->SetControlFont( VCLUnoHelper::CreateFont( rFont, GetWindow()->GetControlFont() ) ); | |||
1212 | } | |||
1213 | ||||
1214 | void VCLXWindow::getStyles( sal_Int16 nType, css::awt::FontDescriptor& Font, sal_Int32& ForegroundColor, sal_Int32& BackgroundColor ) | |||
1215 | { | |||
1216 | SolarMutexGuard aGuard; | |||
1217 | ||||
1218 | if ( !GetWindow() ) | |||
1219 | return; | |||
1220 | ||||
1221 | const StyleSettings& rStyleSettings = GetWindow()->GetSettings().GetStyleSettings(); | |||
1222 | ||||
1223 | switch ( nType ) | |||
1224 | { | |||
1225 | case css::awt::Style::FRAME: | |||
1226 | { | |||
1227 | Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() ); | |||
1228 | ForegroundColor = sal_Int32(rStyleSettings.GetWindowTextColor()); | |||
1229 | BackgroundColor = sal_Int32(rStyleSettings.GetWindowColor()); | |||
1230 | } | |||
1231 | break; | |||
1232 | case css::awt::Style::DIALOG: | |||
1233 | { | |||
1234 | Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() ); | |||
1235 | ForegroundColor = sal_Int32(rStyleSettings.GetDialogTextColor()); | |||
1236 | BackgroundColor = sal_Int32(rStyleSettings.GetDialogColor()); | |||
1237 | } | |||
1238 | break; | |||
1239 | default: OSL_FAIL( "VCLWindow::getStyles() - unknown Type" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1239" ": "), "%s", "VCLWindow::getStyles() - unknown Type" ); } } while (false); | |||
1240 | } | |||
1241 | } | |||
1242 | ||||
1243 | namespace toolkit | |||
1244 | { | |||
1245 | static void setColorSettings( vcl::Window* _pWindow, const css::uno::Any& _rValue, | |||
1246 | void (StyleSettings::*pSetter)( const Color& ), const Color& (StyleSettings::*pGetter)( ) const ) | |||
1247 | { | |||
1248 | sal_Int32 nColor = 0; | |||
1249 | if ( !( _rValue >>= nColor ) ) | |||
1250 | nColor = sal_Int32((Application::GetSettings().GetStyleSettings().*pGetter)()); | |||
1251 | ||||
1252 | AllSettings aSettings = _pWindow->GetSettings(); | |||
1253 | StyleSettings aStyleSettings = aSettings.GetStyleSettings(); | |||
1254 | ||||
1255 | (aStyleSettings.*pSetter)( Color( nColor ) ); | |||
1256 | ||||
1257 | aSettings.SetStyleSettings( aStyleSettings ); | |||
1258 | _pWindow->SetSettings( aSettings, true ); | |||
1259 | } | |||
1260 | } | |||
1261 | ||||
1262 | // Terminated by BASEPROPERTY_NOTFOUND (or 0) | |||
1263 | void VCLXWindow::PushPropertyIds( std::vector< sal_uInt16 > &rIds, | |||
1264 | int nFirstId, ...) | |||
1265 | { | |||
1266 | va_list pVarArgs; | |||
1267 | va_start( pVarArgs, nFirstId )__builtin_va_start(pVarArgs, nFirstId); | |||
1268 | ||||
1269 | for ( int nId = nFirstId; nId != BASEPROPERTY_NOTFOUND0; | |||
1270 | nId = va_arg( pVarArgs, int )__builtin_va_arg(pVarArgs, int) ) | |||
1271 | rIds.push_back( static_cast<sal_uInt16>(nId) ); | |||
1272 | ||||
1273 | va_end( pVarArgs )__builtin_va_end(pVarArgs); | |||
1274 | } | |||
1275 | ||||
1276 | void VCLXWindow::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds, bool bWithDefaults ) | |||
1277 | { | |||
1278 | // These are common across ~all VCLXWindow derived classes | |||
1279 | if( bWithDefaults ) | |||
1280 | PushPropertyIds( rIds, | |||
1281 | BASEPROPERTY_ALIGN7, | |||
1282 | BASEPROPERTY_BACKGROUNDCOLOR2, | |||
1283 | BASEPROPERTY_BORDER6, | |||
1284 | BASEPROPERTY_BORDERCOLOR112, | |||
1285 | BASEPROPERTY_DEFAULTCONTROL19, | |||
1286 | BASEPROPERTY_ENABLED44, | |||
1287 | BASEPROPERTY_FONTDESCRIPTOR8, | |||
1288 | BASEPROPERTY_HELPTEXT73, | |||
1289 | BASEPROPERTY_HELPURL58, | |||
1290 | BASEPROPERTY_TEXT1, | |||
1291 | BASEPROPERTY_PRINTABLE45, | |||
1292 | BASEPROPERTY_ENABLEVISIBLE145, // for visibility | |||
1293 | BASEPROPERTY_TABSTOP14, | |||
1294 | 0); | |||
1295 | ||||
1296 | // lovely hack from: | |||
1297 | // void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId ) | |||
1298 | if( std::find(rIds.begin(), rIds.end(), BASEPROPERTY_FONTDESCRIPTOR8) != rIds.end() ) | |||
1299 | { | |||
1300 | // some properties are not included in the FontDescriptor, but every time | |||
1301 | // when we have a FontDescriptor we want to have these properties too. | |||
1302 | // => Easier to register the here, instead everywhere where I register the FontDescriptor... | |||
1303 | ||||
1304 | rIds.push_back( BASEPROPERTY_TEXTCOLOR4 ); | |||
1305 | rIds.push_back( BASEPROPERTY_TEXTLINECOLOR85 ); | |||
1306 | rIds.push_back( BASEPROPERTY_FONTRELIEF83 ); | |||
1307 | rIds.push_back( BASEPROPERTY_FONTEMPHASISMARK84 ); | |||
1308 | } | |||
1309 | } | |||
1310 | ||||
1311 | void VCLXWindow::GetPropertyIds( std::vector< sal_uInt16 >& _out_rIds ) | |||
1312 | { | |||
1313 | return ImplGetPropertyIds( _out_rIds, mpImpl->mbWithDefaultProps ); | |||
1314 | } | |||
1315 | ||||
1316 | ::comphelper::OInterfaceContainerHelper2& VCLXWindow::GetContainerListeners() | |||
1317 | { | |||
1318 | return mpImpl->getContainerListeners(); | |||
1319 | } | |||
1320 | ||||
1321 | ::comphelper::OInterfaceContainerHelper2& VCLXWindow::GetTopWindowListeners() | |||
1322 | { | |||
1323 | return mpImpl->getTopWindowListeners(); | |||
1324 | } | |||
1325 | ||||
1326 | namespace | |||
1327 | { | |||
1328 | void lcl_updateWritingMode( vcl::Window& _rWindow, const sal_Int16 _nWritingMode, const sal_Int16 _nContextWritingMode ) | |||
1329 | { | |||
1330 | bool bEnableRTL = false; | |||
1331 | switch ( _nWritingMode ) | |||
1332 | { | |||
1333 | case WritingMode2::LR_TB: bEnableRTL = false; break; | |||
1334 | case WritingMode2::RL_TB: bEnableRTL = true; break; | |||
1335 | case WritingMode2::CONTEXT: | |||
1336 | { | |||
1337 | // consult our ContextWritingMode. If it has an explicit RTL/LTR value, then use | |||
1338 | // it. If it doesn't (but is CONTEXT itself), then just ask the parent window of our | |||
1339 | // own window for its RTL mode | |||
1340 | switch ( _nContextWritingMode ) | |||
1341 | { | |||
1342 | case WritingMode2::LR_TB: bEnableRTL = false; break; | |||
1343 | case WritingMode2::RL_TB: bEnableRTL = true; break; | |||
1344 | case WritingMode2::CONTEXT: | |||
1345 | { | |||
1346 | const vcl::Window* pParent = _rWindow.GetParent(); | |||
1347 | OSL_ENSURE( pParent, "lcl_updateWritingMode: cannot determine context's writing mode!" )do { if (true && (!(pParent))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1347" ": "), "%s", "lcl_updateWritingMode: cannot determine context's writing mode!" ); } } while (false); | |||
1348 | if ( pParent ) | |||
1349 | bEnableRTL = pParent->IsRTLEnabled(); | |||
1350 | } | |||
1351 | break; | |||
1352 | } | |||
1353 | } | |||
1354 | break; | |||
1355 | default: | |||
1356 | OSL_FAIL( "lcl_updateWritingMode: unsupported WritingMode!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1356" ": "), "%s", "lcl_updateWritingMode: unsupported WritingMode!" ); } } while (false); | |||
1357 | } // switch ( nWritingMode ) | |||
1358 | ||||
1359 | _rWindow.EnableRTL( bEnableRTL ); | |||
1360 | } | |||
1361 | } | |||
1362 | ||||
1363 | void VCLXWindow::setProperty( const OUString& PropertyName, const css::uno::Any& Value ) | |||
1364 | { | |||
1365 | SolarMutexGuard aGuard; | |||
1366 | ||||
1367 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
1368 | if ( !pWindow ) | |||
1369 | return; | |||
1370 | ||||
1371 | bool bVoid = Value.getValueType().getTypeClass() == css::uno::TypeClass_VOID; | |||
1372 | ||||
1373 | WindowType eWinType = pWindow->GetType(); | |||
1374 | sal_uInt16 nPropType = GetPropertyId( PropertyName ); | |||
1375 | switch ( nPropType ) | |||
1376 | { | |||
1377 | case BASEPROPERTY_REFERENCE_DEVICE146: | |||
1378 | { | |||
1379 | Control* pControl = dynamic_cast< Control* >( pWindow.get() ); | |||
1380 | OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" )do { if (true && (!(pControl))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1380" ": "), "%s", "VCLXWindow::setProperty( RefDevice ): need a Control for this!" ); } } while (false); | |||
1381 | if ( !pControl ) | |||
1382 | break; | |||
1383 | Reference< XDevice > xDevice( Value, UNO_QUERY ); | |||
1384 | OutputDevice* pDevice = VCLUnoHelper::GetOutputDevice( xDevice ); | |||
1385 | pControl->SetReferenceDevice( pDevice ); | |||
1386 | } | |||
1387 | break; | |||
1388 | ||||
1389 | case BASEPROPERTY_CONTEXT_WRITING_MODE139: | |||
1390 | { | |||
1391 | OSL_VERIFY( Value >>= mpImpl->mnContextWritingMode )do { if (!(Value >>= mpImpl->mnContextWritingMode)) do { if (true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1391" ": "), "OSL_ASSERT: %s", "0"); } } while (false); } while (0); | |||
1392 | if ( mpImpl->mnWritingMode == WritingMode2::CONTEXT ) | |||
1393 | lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode ); | |||
1394 | } | |||
1395 | break; | |||
1396 | ||||
1397 | case BASEPROPERTY_WRITING_MODE138: | |||
1398 | { | |||
1399 | bool bProperType = ( Value >>= mpImpl->mnWritingMode ); | |||
1400 | OSL_ENSURE( bProperType, "VCLXWindow::setProperty( 'WritingMode' ): illegal value type!" )do { if (true && (!(bProperType))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1400" ": "), "%s", "VCLXWindow::setProperty( 'WritingMode' ): illegal value type!" ); } } while (false); | |||
1401 | if ( bProperType ) | |||
1402 | lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode ); | |||
1403 | } | |||
1404 | break; | |||
1405 | ||||
1406 | case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR116: | |||
1407 | { | |||
1408 | sal_uInt16 nWheelBehavior( css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY ); | |||
1409 | OSL_VERIFY( Value >>= nWheelBehavior )do { if (!(Value >>= nWheelBehavior)) do { if (true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ( "legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1409" ": "), "OSL_ASSERT: %s", "0"); } } while (false); } while (0); | |||
1410 | ||||
1411 | AllSettings aSettings = pWindow->GetSettings(); | |||
1412 | MouseSettings aMouseSettings = aSettings.GetMouseSettings(); | |||
1413 | ||||
1414 | MouseWheelBehaviour nVclBehavior( MouseWheelBehaviour::FocusOnly ); | |||
1415 | switch ( nWheelBehavior ) | |||
1416 | { | |||
1417 | case css::awt::MouseWheelBehavior::SCROLL_DISABLED: nVclBehavior = MouseWheelBehaviour::Disable; break; | |||
1418 | case css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY: nVclBehavior = MouseWheelBehaviour::FocusOnly; break; | |||
1419 | case css::awt::MouseWheelBehavior::SCROLL_ALWAYS: nVclBehavior = MouseWheelBehaviour::ALWAYS; break; | |||
1420 | default: | |||
1421 | OSL_FAIL( "VCLXWindow::setProperty( 'MouseWheelBehavior' ): illegal property value!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1421" ": "), "%s", "VCLXWindow::setProperty( 'MouseWheelBehavior' ): illegal property value!" ); } } while (false); | |||
1422 | } | |||
1423 | ||||
1424 | aMouseSettings.SetWheelBehavior( nVclBehavior ); | |||
1425 | aSettings.SetMouseSettings( aMouseSettings ); | |||
1426 | pWindow->SetSettings( aSettings, true ); | |||
1427 | } | |||
1428 | break; | |||
1429 | ||||
1430 | case BASEPROPERTY_NATIVE_WIDGET_LOOK114: | |||
1431 | { | |||
1432 | bool bEnable( true ); | |||
1433 | OSL_VERIFY( Value >>= bEnable )do { if (!(Value >>= bEnable)) do { if (true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ( "legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1433" ": "), "OSL_ASSERT: %s", "0"); } } while (false); } while (0); | |||
1434 | pWindow->EnableNativeWidget( bEnable ); | |||
1435 | } | |||
1436 | break; | |||
1437 | ||||
1438 | case BASEPROPERTY_PLUGINPARENT93: | |||
1439 | { | |||
1440 | // set parent handle | |||
1441 | SetSystemParent_Impl( Value ); | |||
1442 | } | |||
1443 | break; | |||
1444 | ||||
1445 | case BASEPROPERTY_ENABLED44: | |||
1446 | { | |||
1447 | bool b = bool(); | |||
1448 | if ( Value >>= b ) | |||
1449 | setEnable( b ); | |||
1450 | } | |||
1451 | break; | |||
1452 | case BASEPROPERTY_ENABLEVISIBLE145: | |||
1453 | { | |||
1454 | bool b = false; | |||
1455 | if ( Value >>= b ) | |||
1456 | { | |||
1457 | if( b != mpImpl->isEnableVisible() ) | |||
1458 | { | |||
1459 | mpImpl->setEnableVisible( b ); | |||
1460 | pWindow->Show( b && mpImpl->isDirectVisible() ); | |||
1461 | } | |||
1462 | } | |||
1463 | } | |||
1464 | break; | |||
1465 | case BASEPROPERTY_TEXT1: | |||
1466 | case BASEPROPERTY_LABEL20: | |||
1467 | case BASEPROPERTY_TITLE69: | |||
1468 | { | |||
1469 | OUString aText; | |||
1470 | if ( Value >>= aText ) | |||
1471 | { | |||
1472 | switch (eWinType) | |||
1473 | { | |||
1474 | case WindowType::OKBUTTON: | |||
1475 | case WindowType::CANCELBUTTON: | |||
1476 | case WindowType::HELPBUTTON: | |||
1477 | // Standard Button: overwrite only if not empty. | |||
1478 | if (!aText.isEmpty()) | |||
1479 | pWindow->SetText( aText ); | |||
1480 | break; | |||
1481 | ||||
1482 | default: | |||
1483 | pWindow->SetText( aText ); | |||
1484 | break; | |||
1485 | } | |||
1486 | } | |||
1487 | } | |||
1488 | break; | |||
1489 | case BASEPROPERTY_ACCESSIBLENAME92: | |||
1490 | { | |||
1491 | OUString aText; | |||
1492 | if ( Value >>= aText ) | |||
1493 | pWindow->SetAccessibleName( aText ); | |||
1494 | } | |||
1495 | break; | |||
1496 | case BASEPROPERTY_HELPURL58: | |||
1497 | { | |||
1498 | OUString aURL; | |||
1499 | if ( Value >>= aURL ) | |||
1500 | { | |||
1501 | INetURLObject aHelpURL( aURL ); | |||
1502 | if ( aHelpURL.GetProtocol() == INetProtocol::Hid ) | |||
1503 | pWindow->SetHelpId( OUStringToOString( aHelpURL.GetURLPath(), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ) ); | |||
1504 | else | |||
1505 | pWindow->SetHelpId( OUStringToOString( aURL, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ) ); | |||
1506 | } | |||
1507 | } | |||
1508 | break; | |||
1509 | case BASEPROPERTY_HELPTEXT73: | |||
1510 | { | |||
1511 | OUString aHelpText; | |||
1512 | if ( Value >>= aHelpText ) | |||
1513 | { | |||
1514 | pWindow->SetQuickHelpText( aHelpText ); | |||
1515 | } | |||
1516 | } | |||
1517 | break; | |||
1518 | case BASEPROPERTY_FONTDESCRIPTOR8: | |||
1519 | { | |||
1520 | if ( bVoid ) | |||
1521 | pWindow->SetControlFont( vcl::Font() ); | |||
1522 | else | |||
1523 | { | |||
1524 | css::awt::FontDescriptor aFont; | |||
1525 | if ( Value >>= aFont ) | |||
1526 | pWindow->SetControlFont( VCLUnoHelper::CreateFont( aFont, pWindow->GetControlFont() ) ); | |||
1527 | } | |||
1528 | } | |||
1529 | break; | |||
1530 | case BASEPROPERTY_FONTRELIEF83: | |||
1531 | { | |||
1532 | sal_Int16 n = sal_Int16(); | |||
1533 | if ( Value >>= n ) | |||
1534 | { | |||
1535 | vcl::Font aFont = pWindow->GetControlFont(); | |||
1536 | aFont.SetRelief( static_cast<FontRelief>(n) ); | |||
1537 | pWindow->SetControlFont( aFont ); | |||
1538 | } | |||
1539 | } | |||
1540 | break; | |||
1541 | case BASEPROPERTY_FONTEMPHASISMARK84: | |||
1542 | { | |||
1543 | sal_Int16 n = sal_Int16(); | |||
1544 | if ( Value >>= n ) | |||
1545 | { | |||
1546 | vcl::Font aFont = pWindow->GetControlFont(); | |||
1547 | aFont.SetEmphasisMark( static_cast<FontEmphasisMark>(n) ); | |||
1548 | pWindow->SetControlFont( aFont ); | |||
1549 | } | |||
1550 | } | |||
1551 | break; | |||
1552 | case BASEPROPERTY_BACKGROUNDCOLOR2: | |||
1553 | if ( bVoid ) | |||
1554 | { | |||
1555 | switch ( eWinType ) | |||
1556 | { | |||
1557 | // set dialog color for default | |||
1558 | case WindowType::DIALOG: | |||
1559 | case WindowType::MESSBOX: | |||
1560 | case WindowType::INFOBOX: | |||
1561 | case WindowType::WARNINGBOX: | |||
1562 | case WindowType::ERRORBOX: | |||
1563 | case WindowType::QUERYBOX: | |||
1564 | case WindowType::TABPAGE: | |||
1565 | { | |||
1566 | Color aColor = pWindow->GetSettings().GetStyleSettings().GetDialogColor(); | |||
1567 | pWindow->SetBackground( aColor ); | |||
1568 | pWindow->SetControlBackground( aColor ); | |||
1569 | break; | |||
1570 | } | |||
1571 | ||||
1572 | case WindowType::FIXEDTEXT: | |||
1573 | case WindowType::CHECKBOX: | |||
1574 | case WindowType::RADIOBUTTON: | |||
1575 | case WindowType::GROUPBOX: | |||
1576 | case WindowType::FIXEDLINE: | |||
1577 | { | |||
1578 | // support transparency only for special controls | |||
1579 | pWindow->SetBackground(); | |||
1580 | pWindow->SetControlBackground(); | |||
1581 | pWindow->SetPaintTransparent( true ); | |||
1582 | break; | |||
1583 | } | |||
1584 | ||||
1585 | default: | |||
1586 | { | |||
1587 | // default code which enables transparency for | |||
1588 | // compound controls. It's not real transparency | |||
1589 | // as most of these controls repaint their client | |||
1590 | // area completely new. | |||
1591 | if ( pWindow->IsCompoundControl() ) | |||
1592 | pWindow->SetBackground(); | |||
1593 | pWindow->SetControlBackground(); | |||
1594 | break; | |||
1595 | } | |||
1596 | } | |||
1597 | } | |||
1598 | else | |||
1599 | { | |||
1600 | sal_Int32 nColor = 0; | |||
1601 | if ( Value >>= nColor ) | |||
1602 | { | |||
1603 | Color aColor( nColor ); | |||
1604 | pWindow->SetControlBackground( aColor ); | |||
1605 | pWindow->SetBackground( aColor ); | |||
1606 | switch ( eWinType ) | |||
1607 | { | |||
1608 | // reset paint transparent mode | |||
1609 | case WindowType::FIXEDTEXT: | |||
1610 | case WindowType::CHECKBOX: | |||
1611 | case WindowType::RADIOBUTTON: | |||
1612 | case WindowType::GROUPBOX: | |||
1613 | case WindowType::FIXEDLINE: | |||
1614 | pWindow->SetPaintTransparent( false ); | |||
1615 | break; | |||
1616 | default: | |||
1617 | break; | |||
1618 | } | |||
1619 | pWindow->Invalidate(); // Invalidate if control does not respond to it | |||
1620 | } | |||
1621 | } | |||
1622 | break; | |||
1623 | case BASEPROPERTY_TEXTCOLOR4: | |||
1624 | if ( bVoid ) | |||
1625 | { | |||
1626 | pWindow->SetControlForeground(); | |||
1627 | } | |||
1628 | else | |||
1629 | { | |||
1630 | sal_Int32 nColor = 0; | |||
1631 | if ( Value >>= nColor ) | |||
1632 | { | |||
1633 | Color aColor( nColor ); | |||
1634 | pWindow->SetTextColor( aColor ); | |||
1635 | pWindow->SetControlForeground( aColor ); | |||
1636 | } | |||
1637 | } | |||
1638 | break; | |||
1639 | case BASEPROPERTY_TEXTLINECOLOR85: | |||
1640 | if ( bVoid ) | |||
1641 | { | |||
1642 | pWindow->SetTextLineColor(); | |||
1643 | } | |||
1644 | else | |||
1645 | { | |||
1646 | sal_Int32 nColor = 0; | |||
1647 | if ( Value >>= nColor ) | |||
1648 | { | |||
1649 | Color aColor( nColor ); | |||
1650 | pWindow->SetTextLineColor( aColor ); | |||
1651 | } | |||
1652 | } | |||
1653 | break; | |||
1654 | case BASEPROPERTY_FILLCOLOR3: | |||
1655 | if ( bVoid ) | |||
1656 | pWindow->SetFillColor(); | |||
1657 | else | |||
1658 | { | |||
1659 | sal_Int32 nColor = 0; | |||
1660 | if ( Value >>= nColor ) | |||
1661 | { | |||
1662 | Color aColor( nColor ); | |||
1663 | pWindow->SetFillColor( aColor ); | |||
1664 | } | |||
1665 | } | |||
1666 | break; | |||
1667 | case BASEPROPERTY_LINECOLOR5: | |||
1668 | if ( bVoid ) | |||
1669 | pWindow->SetLineColor(); | |||
1670 | else | |||
1671 | { | |||
1672 | sal_Int32 nColor = 0; | |||
1673 | if ( Value >>= nColor ) | |||
1674 | { | |||
1675 | Color aColor( nColor ); | |||
1676 | pWindow->SetLineColor( aColor ); | |||
1677 | } | |||
1678 | } | |||
1679 | break; | |||
1680 | case BASEPROPERTY_BORDER6: | |||
1681 | { | |||
1682 | WinBits nStyle = pWindow->GetStyle(); | |||
1683 | sal_uInt16 nTmp = 0; | |||
1684 | Value >>= nTmp; | |||
1685 | // clear any dodgy bits passed in, can come from dodgy extensions | |||
1686 | nTmp &= o3tl::typed_flags<WindowBorderStyle>::mask; | |||
1687 | WindowBorderStyle nBorder = static_cast<WindowBorderStyle>(nTmp); | |||
1688 | if ( !bool(nBorder) ) | |||
1689 | { | |||
1690 | pWindow->SetStyle( nStyle & ~WB_BORDER ); | |||
1691 | } | |||
1692 | else | |||
1693 | { | |||
1694 | pWindow->SetStyle( nStyle | WB_BORDER ); | |||
1695 | pWindow->SetBorderStyle( nBorder ); | |||
1696 | } | |||
1697 | } | |||
1698 | break; | |||
1699 | case BASEPROPERTY_TABSTOP14: | |||
1700 | { | |||
1701 | WinBits nStyle = pWindow->GetStyle() & ~WB_TABSTOP; | |||
1702 | if ( !bVoid ) | |||
1703 | { | |||
1704 | bool bTab = false; | |||
1705 | Value >>= bTab; | |||
1706 | if ( bTab ) | |||
1707 | nStyle |= WB_TABSTOP; | |||
1708 | else | |||
1709 | nStyle |= WB_NOTABSTOP; | |||
1710 | } | |||
1711 | pWindow->SetStyle( nStyle ); | |||
1712 | } | |||
1713 | break; | |||
1714 | case BASEPROPERTY_VERTICALALIGN115: | |||
1715 | { | |||
1716 | VerticalAlignment eAlign = css::style::VerticalAlignment::VerticalAlignment_MAKE_FIXED_SIZE; | |||
1717 | WinBits nStyle = pWindow->GetStyle(); | |||
1718 | nStyle &= ~(WB_TOP|WB_VCENTER|WB_BOTTOM); | |||
1719 | if ( !bVoid ) | |||
1720 | Value >>= eAlign; | |||
1721 | switch ( eAlign ) | |||
1722 | { | |||
1723 | case VerticalAlignment_TOP: | |||
1724 | nStyle |= WB_TOP; | |||
1725 | break; | |||
1726 | case VerticalAlignment_MIDDLE: | |||
1727 | nStyle |= WB_VCENTER; | |||
1728 | break; | |||
1729 | case VerticalAlignment_BOTTOM: | |||
1730 | nStyle |= WB_BOTTOM; | |||
1731 | break; | |||
1732 | default: ; // for warning free code, MAKE_FIXED_SIZE | |||
1733 | } | |||
1734 | pWindow->SetStyle( nStyle ); | |||
1735 | } | |||
1736 | break; | |||
1737 | case BASEPROPERTY_ALIGN7: | |||
1738 | { | |||
1739 | sal_Int16 nAlign = PROPERTY_ALIGN_LEFT0; | |||
1740 | switch ( eWinType ) | |||
1741 | { | |||
1742 | case WindowType::COMBOBOX: | |||
1743 | case WindowType::PUSHBUTTON: | |||
1744 | case WindowType::OKBUTTON: | |||
1745 | case WindowType::CANCELBUTTON: | |||
1746 | case WindowType::HELPBUTTON: | |||
1747 | nAlign = PROPERTY_ALIGN_CENTER1; | |||
1748 | [[fallthrough]]; | |||
1749 | case WindowType::FIXEDTEXT: | |||
1750 | case WindowType::EDIT: | |||
1751 | case WindowType::MULTILINEEDIT: | |||
1752 | case WindowType::CHECKBOX: | |||
1753 | case WindowType::RADIOBUTTON: | |||
1754 | case WindowType::LISTBOX: | |||
1755 | { | |||
1756 | WinBits nStyle = pWindow->GetStyle(); | |||
1757 | nStyle &= ~(WB_LEFT|WB_CENTER|WB_RIGHT); | |||
1758 | if ( !bVoid ) | |||
1759 | Value >>= nAlign; | |||
1760 | if ( nAlign == PROPERTY_ALIGN_LEFT0 ) | |||
1761 | nStyle |= WB_LEFT; | |||
1762 | else if ( nAlign == PROPERTY_ALIGN_CENTER1 ) | |||
1763 | nStyle |= WB_CENTER; | |||
1764 | else | |||
1765 | nStyle |= WB_RIGHT; | |||
1766 | pWindow->SetStyle( nStyle ); | |||
1767 | } | |||
1768 | break; | |||
1769 | default: break; | |||
1770 | } | |||
1771 | } | |||
1772 | break; | |||
1773 | case BASEPROPERTY_MULTILINE10: | |||
1774 | { | |||
1775 | if ( ( eWinType == WindowType::FIXEDTEXT ) | |||
1776 | || ( eWinType == WindowType::CHECKBOX ) | |||
1777 | || ( eWinType == WindowType::RADIOBUTTON ) | |||
1778 | || ( eWinType == WindowType::PUSHBUTTON ) | |||
1779 | || ( eWinType == WindowType::OKBUTTON ) | |||
1780 | || ( eWinType == WindowType::CANCELBUTTON ) | |||
1781 | || ( eWinType == WindowType::HELPBUTTON ) | |||
1782 | ) | |||
1783 | { | |||
1784 | WinBits nStyle = pWindow->GetStyle(); | |||
1785 | bool bMulti = false; | |||
1786 | Value >>= bMulti; | |||
1787 | if ( bMulti ) | |||
1788 | nStyle |= WB_WORDBREAK; | |||
1789 | else | |||
1790 | nStyle &= ~WB_WORDBREAK; | |||
1791 | pWindow->SetStyle( nStyle ); | |||
1792 | } | |||
1793 | } | |||
1794 | break; | |||
1795 | case BASEPROPERTY_ORIENTATION82: | |||
1796 | { | |||
1797 | if ( eWinType == WindowType::FIXEDLINE) | |||
1798 | { | |||
1799 | sal_Int32 nOrientation = 0; | |||
1800 | if ( Value >>= nOrientation ) | |||
1801 | { | |||
1802 | WinBits nStyle = pWindow->GetStyle(); | |||
1803 | nStyle &= ~(WB_HORZ|WB_VERT); | |||
1804 | if ( nOrientation == 0 ) | |||
1805 | nStyle |= WB_HORZ; | |||
1806 | else | |||
1807 | nStyle |= WB_VERT; | |||
1808 | ||||
1809 | pWindow->SetStyle( nStyle ); | |||
1810 | } | |||
1811 | } | |||
1812 | } | |||
1813 | break; | |||
1814 | case BASEPROPERTY_AUTOMNEMONICS90: | |||
1815 | { | |||
1816 | bool bAutoMnemonics = false; | |||
1817 | Value >>= bAutoMnemonics; | |||
1818 | AllSettings aSettings = pWindow->GetSettings(); | |||
1819 | StyleSettings aStyleSettings = aSettings.GetStyleSettings(); | |||
1820 | if ( aStyleSettings.GetAutoMnemonic() != bAutoMnemonics ) | |||
1821 | { | |||
1822 | aStyleSettings.SetAutoMnemonic( bAutoMnemonics ); | |||
1823 | aSettings.SetStyleSettings( aStyleSettings ); | |||
1824 | pWindow->SetSettings( aSettings ); | |||
1825 | } | |||
1826 | } | |||
1827 | break; | |||
1828 | case BASEPROPERTY_MOUSETRANSPARENT91: | |||
1829 | { | |||
1830 | bool bMouseTransparent = false; | |||
1831 | Value >>= bMouseTransparent; | |||
1832 | pWindow->SetMouseTransparent( bMouseTransparent ); | |||
1833 | } | |||
1834 | break; | |||
1835 | case BASEPROPERTY_PAINTTRANSPARENT120: | |||
1836 | { | |||
1837 | bool bPaintTransparent = false; | |||
1838 | Value >>= bPaintTransparent; | |||
1839 | pWindow->SetPaintTransparent( bPaintTransparent ); | |||
1840 | // pWindow->SetBackground(); | |||
1841 | } | |||
1842 | break; | |||
1843 | ||||
1844 | case BASEPROPERTY_REPEAT101: | |||
1845 | { | |||
1846 | bool bRepeat( false ); | |||
1847 | Value >>= bRepeat; | |||
1848 | ||||
1849 | WinBits nStyle = pWindow->GetStyle(); | |||
1850 | if ( bRepeat ) | |||
1851 | nStyle |= WB_REPEAT; | |||
1852 | else | |||
1853 | nStyle &= ~WB_REPEAT; | |||
1854 | pWindow->SetStyle( nStyle ); | |||
1855 | } | |||
1856 | break; | |||
1857 | ||||
1858 | case BASEPROPERTY_REPEAT_DELAY95: | |||
1859 | { | |||
1860 | sal_Int32 nRepeatDelay = 0; | |||
1861 | if ( Value >>= nRepeatDelay ) | |||
1862 | { | |||
1863 | AllSettings aSettings = pWindow->GetSettings(); | |||
1864 | MouseSettings aMouseSettings = aSettings.GetMouseSettings(); | |||
1865 | ||||
1866 | aMouseSettings.SetButtonRepeat( nRepeatDelay ); | |||
1867 | aSettings.SetMouseSettings( aMouseSettings ); | |||
1868 | ||||
1869 | pWindow->SetSettings( aSettings, true ); | |||
1870 | } | |||
1871 | } | |||
1872 | break; | |||
1873 | ||||
1874 | case BASEPROPERTY_SYMBOL_COLOR96: | |||
1875 | ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetButtonTextColor, &StyleSettings::GetButtonTextColor ); | |||
1876 | break; | |||
1877 | ||||
1878 | case BASEPROPERTY_BORDERCOLOR112: | |||
1879 | ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetMonoColor, &StyleSettings::GetMonoColor); | |||
1880 | break; | |||
1881 | } | |||
1882 | } | |||
1883 | ||||
1884 | css::uno::Any VCLXWindow::getProperty( const OUString& PropertyName ) | |||
1885 | { | |||
1886 | SolarMutexGuard aGuard; | |||
1887 | ||||
1888 | css::uno::Any aProp; | |||
1889 | if ( GetWindow() ) | |||
1890 | { | |||
1891 | WindowType eWinType = GetWindow()->GetType(); | |||
1892 | sal_uInt16 nPropType = GetPropertyId( PropertyName ); | |||
1893 | switch ( nPropType ) | |||
1894 | { | |||
1895 | case BASEPROPERTY_REFERENCE_DEVICE146: | |||
1896 | { | |||
1897 | VclPtr<Control> pControl = GetAsDynamic<Control >(); | |||
1898 | OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" )do { if (true && (!(pControl))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1898" ": "), "%s", "VCLXWindow::setProperty( RefDevice ): need a Control for this!" ); } } while (false); | |||
1899 | if ( !pControl ) | |||
1900 | break; | |||
1901 | ||||
1902 | VCLXDevice* pDevice = new VCLXDevice; | |||
1903 | pDevice->SetOutputDevice( pControl->GetReferenceDevice() ); | |||
1904 | aProp <<= Reference< XDevice >( pDevice ); | |||
1905 | } | |||
1906 | break; | |||
1907 | ||||
1908 | case BASEPROPERTY_CONTEXT_WRITING_MODE139: | |||
1909 | aProp <<= mpImpl->mnContextWritingMode; | |||
1910 | break; | |||
1911 | ||||
1912 | case BASEPROPERTY_WRITING_MODE138: | |||
1913 | aProp <<= mpImpl->mnWritingMode; | |||
1914 | break; | |||
1915 | ||||
1916 | case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR116: | |||
1917 | { | |||
1918 | MouseWheelBehaviour nVclBehavior = GetWindow()->GetSettings().GetMouseSettings().GetWheelBehavior(); | |||
1919 | sal_uInt16 nBehavior = css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY; | |||
1920 | switch ( nVclBehavior ) | |||
1921 | { | |||
1922 | case MouseWheelBehaviour::Disable: nBehavior = css::awt::MouseWheelBehavior::SCROLL_DISABLED; break; | |||
1923 | case MouseWheelBehaviour::FocusOnly: nBehavior = css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY; break; | |||
1924 | case MouseWheelBehaviour::ALWAYS: nBehavior = css::awt::MouseWheelBehavior::SCROLL_ALWAYS; break; | |||
1925 | default: | |||
1926 | OSL_FAIL( "VCLXWindow::getProperty( 'MouseWheelBehavior' ): illegal VCL value!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxwindow.cxx" ":" "1926" ": "), "%s", "VCLXWindow::getProperty( 'MouseWheelBehavior' ): illegal VCL value!" ); } } while (false); | |||
1927 | } | |||
1928 | aProp <<= nBehavior; | |||
1929 | } | |||
1930 | break; | |||
1931 | ||||
1932 | case BASEPROPERTY_NATIVE_WIDGET_LOOK114: | |||
1933 | aProp <<= GetWindow()->IsNativeWidgetEnabled(); | |||
1934 | break; | |||
1935 | ||||
1936 | case BASEPROPERTY_ENABLED44: | |||
1937 | aProp <<= GetWindow()->IsEnabled(); | |||
1938 | break; | |||
1939 | ||||
1940 | case BASEPROPERTY_ENABLEVISIBLE145: | |||
1941 | aProp <<= mpImpl->isEnableVisible(); | |||
1942 | break; | |||
1943 | ||||
1944 | case BASEPROPERTY_HIGHCONTRASTMODE147: | |||
1945 | aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetHighContrastMode(); | |||
1946 | break; | |||
1947 | ||||
1948 | case BASEPROPERTY_TEXT1: | |||
1949 | case BASEPROPERTY_LABEL20: | |||
1950 | case BASEPROPERTY_TITLE69: | |||
1951 | { | |||
1952 | OUString aText = GetWindow()->GetText(); | |||
1953 | aProp <<= aText; | |||
1954 | } | |||
1955 | break; | |||
1956 | case BASEPROPERTY_ACCESSIBLENAME92: | |||
1957 | { | |||
1958 | OUString aText = GetWindow()->GetAccessibleName(); | |||
1959 | aProp <<= aText; | |||
1960 | } | |||
1961 | break; | |||
1962 | case BASEPROPERTY_HELPTEXT73: | |||
1963 | { | |||
1964 | OUString aText = GetWindow()->GetQuickHelpText(); | |||
1965 | aProp <<= aText; | |||
1966 | } | |||
1967 | break; | |||
1968 | case BASEPROPERTY_HELPURL58: | |||
1969 | { | |||
1970 | OUString aHelpId( OStringToOUString( GetWindow()->GetHelpId(), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ) ); | |||
1971 | aProp <<= aHelpId; | |||
1972 | } | |||
1973 | break; | |||
1974 | case BASEPROPERTY_FONTDESCRIPTOR8: | |||
1975 | { | |||
1976 | vcl::Font aFont = GetWindow()->GetControlFont(); | |||
1977 | css::awt::FontDescriptor aFD = VCLUnoHelper::CreateFontDescriptor( aFont ); | |||
1978 | aProp <<= aFD; | |||
1979 | } | |||
1980 | break; | |||
1981 | case BASEPROPERTY_BACKGROUNDCOLOR2: | |||
1982 | aProp <<= GetWindow()->GetControlBackground(); | |||
1983 | break; | |||
1984 | case BASEPROPERTY_DISPLAYBACKGROUNDCOLOR89: | |||
1985 | aProp <<= GetWindow()->GetBackgroundColor(); | |||
1986 | break; | |||
1987 | case BASEPROPERTY_FONTRELIEF83: | |||
1988 | aProp <<= static_cast<sal_Int16>(GetWindow()->GetControlFont().GetRelief()); | |||
1989 | break; | |||
1990 | case BASEPROPERTY_FONTEMPHASISMARK84: | |||
1991 | aProp <<= static_cast<sal_Int16>(GetWindow()->GetControlFont().GetEmphasisMark()); | |||
1992 | break; | |||
1993 | case BASEPROPERTY_TEXTCOLOR4: | |||
1994 | aProp <<= GetWindow()->GetControlForeground(); | |||
1995 | break; | |||
1996 | case BASEPROPERTY_TEXTLINECOLOR85: | |||
1997 | aProp <<= GetWindow()->GetTextLineColor(); | |||
1998 | break; | |||
1999 | case BASEPROPERTY_FILLCOLOR3: | |||
2000 | aProp <<= GetWindow()->GetFillColor(); | |||
2001 | break; | |||
2002 | case BASEPROPERTY_LINECOLOR5: | |||
2003 | aProp <<= GetWindow()->GetLineColor(); | |||
2004 | break; | |||
2005 | case BASEPROPERTY_BORDER6: | |||
2006 | { | |||
2007 | WindowBorderStyle nBorder = WindowBorderStyle::NONE; | |||
2008 | if ( GetWindow()->GetStyle() & WB_BORDER ) | |||
2009 | nBorder = GetWindow()->GetBorderStyle(); | |||
2010 | aProp <<= static_cast<sal_uInt16>(nBorder); | |||
2011 | } | |||
2012 | break; | |||
2013 | case BASEPROPERTY_TABSTOP14: | |||
2014 | aProp <<= ( GetWindow()->GetStyle() & WB_TABSTOP ) != 0; | |||
2015 | break; | |||
2016 | case BASEPROPERTY_VERTICALALIGN115: | |||
2017 | { | |||
2018 | WinBits nStyle = GetWindow()->GetStyle(); | |||
2019 | if ( nStyle & WB_TOP ) | |||
2020 | aProp <<= VerticalAlignment_TOP; | |||
2021 | else if ( nStyle & WB_VCENTER ) | |||
2022 | aProp <<= VerticalAlignment_MIDDLE; | |||
2023 | else if ( nStyle & WB_BOTTOM ) | |||
2024 | aProp <<= VerticalAlignment_BOTTOM; | |||
2025 | } | |||
2026 | break; | |||
2027 | case BASEPROPERTY_ALIGN7: | |||
2028 | { | |||
2029 | switch ( eWinType ) | |||
2030 | { | |||
2031 | case WindowType::FIXEDTEXT: | |||
2032 | case WindowType::EDIT: | |||
2033 | case WindowType::MULTILINEEDIT: | |||
2034 | case WindowType::CHECKBOX: | |||
2035 | case WindowType::RADIOBUTTON: | |||
2036 | case WindowType::LISTBOX: | |||
2037 | case WindowType::COMBOBOX: | |||
2038 | case WindowType::PUSHBUTTON: | |||
2039 | case WindowType::OKBUTTON: | |||
2040 | case WindowType::CANCELBUTTON: | |||
2041 | case WindowType::HELPBUTTON: | |||
2042 | { | |||
2043 | WinBits nStyle = GetWindow()->GetStyle(); | |||
2044 | if ( nStyle & WB_LEFT ) | |||
2045 | aProp <<= sal_Int16(PROPERTY_ALIGN_LEFT0); | |||
2046 | else if ( nStyle & WB_CENTER ) | |||
2047 | aProp <<= sal_Int16(PROPERTY_ALIGN_CENTER1); | |||
2048 | else if ( nStyle & WB_RIGHT ) | |||
2049 | aProp <<= sal_Int16(PROPERTY_ALIGN_RIGHT2); | |||
2050 | } | |||
2051 | break; | |||
2052 | default: break; | |||
2053 | } | |||
2054 | } | |||
2055 | break; | |||
2056 | case BASEPROPERTY_MULTILINE10: | |||
2057 | { | |||
2058 | if ( ( eWinType == WindowType::FIXEDTEXT ) | |||
2059 | || ( eWinType == WindowType::CHECKBOX ) | |||
2060 | || ( eWinType == WindowType::RADIOBUTTON ) | |||
2061 | || ( eWinType == WindowType::PUSHBUTTON ) | |||
2062 | || ( eWinType == WindowType::OKBUTTON ) | |||
2063 | || ( eWinType == WindowType::CANCELBUTTON ) | |||
2064 | || ( eWinType == WindowType::HELPBUTTON ) | |||
2065 | ) | |||
2066 | aProp <<= ( GetWindow()->GetStyle() & WB_WORDBREAK ) != 0; | |||
2067 | } | |||
2068 | break; | |||
2069 | case BASEPROPERTY_AUTOMNEMONICS90: | |||
2070 | { | |||
2071 | bool bAutoMnemonics = GetWindow()->GetSettings().GetStyleSettings().GetAutoMnemonic(); | |||
2072 | aProp <<= bAutoMnemonics; | |||
2073 | } | |||
2074 | break; | |||
2075 | case BASEPROPERTY_MOUSETRANSPARENT91: | |||
2076 | { | |||
2077 | bool bMouseTransparent = GetWindow()->IsMouseTransparent(); | |||
2078 | aProp <<= bMouseTransparent; | |||
2079 | } | |||
2080 | break; | |||
2081 | case BASEPROPERTY_PAINTTRANSPARENT120: | |||
2082 | { | |||
2083 | bool bPaintTransparent = GetWindow()->IsPaintTransparent(); | |||
2084 | aProp <<= bPaintTransparent; | |||
2085 | } | |||
2086 | break; | |||
2087 | ||||
2088 | case BASEPROPERTY_REPEAT101: | |||
2089 | aProp <<= ( 0 != ( GetWindow()->GetStyle() & WB_REPEAT ) ); | |||
2090 | break; | |||
2091 | ||||
2092 | case BASEPROPERTY_REPEAT_DELAY95: | |||
2093 | { | |||
2094 | sal_Int32 nButtonRepeat = GetWindow()->GetSettings().GetMouseSettings().GetButtonRepeat(); | |||
2095 | aProp <<= nButtonRepeat; | |||
2096 | } | |||
2097 | break; | |||
2098 | ||||
2099 | case BASEPROPERTY_SYMBOL_COLOR96: | |||
2100 | aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetButtonTextColor(); | |||
2101 | break; | |||
2102 | ||||
2103 | case BASEPROPERTY_BORDERCOLOR112: | |||
2104 | aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetMonoColor(); | |||
2105 | break; | |||
2106 | } | |||
2107 | } | |||
2108 | return aProp; | |||
2109 | } | |||
2110 | ||||
2111 | ||||
2112 | // css::awt::XLayoutConstrains | |||
2113 | css::awt::Size VCLXWindow::getMinimumSize( ) | |||
2114 | { | |||
2115 | SolarMutexGuard aGuard; | |||
2116 | ||||
2117 | // Use this method only for those components which can be created through | |||
2118 | // css::awt::Toolkit , but do not have an interface | |||
2119 | ||||
2120 | Size aSz; | |||
2121 | if ( GetWindow() ) | |||
2122 | { | |||
2123 | WindowType nWinType = GetWindow()->GetType(); | |||
2124 | switch ( nWinType ) | |||
2125 | { | |||
2126 | case WindowType::CONTROL: | |||
2127 | aSz.setWidth( GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*12 ); | |||
2128 | aSz.setHeight( GetWindow()->GetTextHeight()+2*6 ); | |||
2129 | break; | |||
2130 | ||||
2131 | case WindowType::PATTERNBOX: | |||
2132 | case WindowType::NUMERICBOX: | |||
2133 | case WindowType::METRICBOX: | |||
2134 | case WindowType::CURRENCYBOX: | |||
2135 | case WindowType::DATEBOX: | |||
2136 | case WindowType::TIMEBOX: | |||
2137 | case WindowType::LONGCURRENCYBOX: | |||
2138 | aSz.setWidth( GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*2 ); | |||
2139 | aSz.setHeight( GetWindow()->GetTextHeight()+2*2 ); | |||
2140 | break; | |||
2141 | case WindowType::SCROLLBARBOX: | |||
2142 | return VCLXScrollBar::implGetMinimumSize( GetWindow() ); | |||
2143 | default: | |||
2144 | aSz = GetWindow()->get_preferred_size(); | |||
2145 | } | |||
2146 | } | |||
2147 | ||||
2148 | return css::awt::Size( aSz.Width(), aSz.Height() ); | |||
2149 | } | |||
2150 | ||||
2151 | css::awt::Size VCLXWindow::getPreferredSize( ) | |||
2152 | { | |||
2153 | return getMinimumSize(); | |||
2154 | } | |||
2155 | ||||
2156 | css::awt::Size VCLXWindow::calcAdjustedSize( const css::awt::Size& rNewSize ) | |||
2157 | { | |||
2158 | SolarMutexGuard aGuard; | |||
2159 | ||||
2160 | css::awt::Size aNewSize( rNewSize ); | |||
2161 | css::awt::Size aMinSize = getMinimumSize(); | |||
2162 | ||||
2163 | if ( aNewSize.Width < aMinSize.Width ) | |||
2164 | aNewSize.Width = aMinSize.Width; | |||
2165 | if ( aNewSize.Height < aMinSize.Height ) | |||
2166 | aNewSize.Height = aMinSize.Height; | |||
2167 | ||||
2168 | return aNewSize; | |||
2169 | } | |||
2170 | ||||
2171 | ||||
2172 | // css::awt::XView | |||
2173 | sal_Bool VCLXWindow::setGraphics( const css::uno::Reference< css::awt::XGraphics >& rxDevice ) | |||
2174 | { | |||
2175 | SolarMutexGuard aGuard; | |||
2176 | ||||
2177 | if ( VCLUnoHelper::GetOutputDevice( rxDevice ) ) | |||
2178 | mpImpl->mxViewGraphics = rxDevice; | |||
2179 | else | |||
2180 | mpImpl->mxViewGraphics = nullptr; | |||
2181 | ||||
2182 | return mpImpl->mxViewGraphics.is(); | |||
2183 | } | |||
2184 | ||||
2185 | css::uno::Reference< css::awt::XGraphics > VCLXWindow::getGraphics( ) | |||
2186 | { | |||
2187 | SolarMutexGuard aGuard; | |||
2188 | ||||
2189 | return mpImpl->mxViewGraphics; | |||
2190 | } | |||
2191 | ||||
2192 | css::awt::Size VCLXWindow::getSize( ) | |||
2193 | { | |||
2194 | SolarMutexGuard aGuard; | |||
2195 | ||||
2196 | Size aSz; | |||
2197 | if ( GetWindow() ) | |||
2198 | aSz = GetWindow()->GetSizePixel(); | |||
2199 | return css::awt::Size( aSz.Width(), aSz.Height() ); | |||
2200 | } | |||
2201 | ||||
2202 | void VCLXWindow::draw( sal_Int32 nX, sal_Int32 nY ) | |||
2203 | { | |||
2204 | SolarMutexGuard aGuard; | |||
2205 | ||||
2206 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
2207 | if ( !pWindow ) | |||
2208 | return; | |||
2209 | ||||
2210 | if ( !(isDesignMode() || mpImpl->isEnableVisible()) ) | |||
2211 | return; | |||
2212 | ||||
2213 | OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( mpImpl->mxViewGraphics ); | |||
2214 | if (!pDev) | |||
2215 | pDev = pWindow->GetParent(); | |||
2216 | TabPage* pTabPage = dynamic_cast< TabPage* >( pWindow.get() ); | |||
2217 | if ( pTabPage ) | |||
2218 | { | |||
2219 | Point aPos( nX, nY ); | |||
2220 | aPos = pDev->PixelToLogic( aPos ); | |||
2221 | pTabPage->Draw( pDev, aPos, DrawFlags::NONE ); | |||
2222 | return; | |||
2223 | } | |||
2224 | ||||
2225 | Point aPos( nX, nY ); | |||
2226 | ||||
2227 | if ( pWindow->GetParent() && !pWindow->IsSystemWindow() && ( pWindow->GetParent() == pDev ) ) | |||
2228 | { | |||
2229 | // #i40647# don't draw here if this is a recursive call | |||
2230 | // sometimes this is called recursively, because the Update call on the parent | |||
2231 | // (strangely) triggers another paint. Prevent a stack overflow here | |||
2232 | // Yes, this is only fixing symptoms for the moment... | |||
2233 | // #i40647# / 2005-01-18 / frank.schoenheit@sun.com | |||
2234 | if ( !mpImpl->getDrawingOntoParent_ref() ) | |||
2235 | { | |||
2236 | ::comphelper::FlagGuard aDrawingflagGuard( mpImpl->getDrawingOntoParent_ref() ); | |||
2237 | ||||
2238 | bool bWasVisible = pWindow->IsVisible(); | |||
2239 | Point aOldPos( pWindow->GetPosPixel() ); | |||
2240 | ||||
2241 | if ( bWasVisible && aOldPos == aPos ) | |||
2242 | { | |||
2243 | pWindow->PaintImmediately(); | |||
2244 | return; | |||
2245 | } | |||
2246 | ||||
2247 | pWindow->SetPosPixel( aPos ); | |||
2248 | ||||
2249 | // Update parent first to avoid painting the parent upon the update | |||
2250 | // of this window, as it may otherwise cause the parent | |||
2251 | // to hide this window again | |||
2252 | if( pWindow->GetParent() ) | |||
2253 | pWindow->GetParent()->PaintImmediately(); | |||
2254 | ||||
2255 | pWindow->Show(); | |||
2256 | pWindow->PaintImmediately(); | |||
2257 | pWindow->SetParentUpdateMode( false ); | |||
2258 | pWindow->Hide(); | |||
2259 | pWindow->SetParentUpdateMode( true ); | |||
2260 | ||||
2261 | pWindow->SetPosPixel( aOldPos ); | |||
2262 | if ( bWasVisible ) | |||
2263 | pWindow->Show(); | |||
2264 | } | |||
2265 | } | |||
2266 | else if ( pDev ) | |||
2267 | { | |||
2268 | Point aP = pDev->PixelToLogic( aPos ); | |||
2269 | ||||
2270 | vcl::PDFExtOutDevData* pPDFExport = dynamic_cast<vcl::PDFExtOutDevData*>(pDev->GetExtOutDevData()); | |||
2271 | bool bDrawSimple = ( pDev->GetOutDevType() == OUTDEV_PRINTER ) | |||
2272 | || ( pDev->GetOutDevViewType() == OutDevViewType::PrintPreview ) | |||
2273 | || ( pPDFExport != nullptr ); | |||
2274 | if ( bDrawSimple ) | |||
2275 | { | |||
2276 | pWindow->Draw( pDev, aP, DrawFlags::NoControls ); | |||
2277 | } | |||
2278 | else | |||
2279 | { | |||
2280 | bool bOldNW =pWindow->IsNativeWidgetEnabled(); | |||
2281 | if( bOldNW ) | |||
2282 | pWindow->EnableNativeWidget(false); | |||
2283 | pWindow->PaintToDevice( pDev, aP ); | |||
2284 | if( bOldNW ) | |||
2285 | pWindow->EnableNativeWidget(); | |||
2286 | } | |||
2287 | } | |||
2288 | } | |||
2289 | ||||
2290 | void VCLXWindow::setZoom( float fZoomX, float /*fZoomY*/ ) | |||
2291 | { | |||
2292 | SolarMutexGuard aGuard; | |||
2293 | ||||
2294 | if ( GetWindow() ) | |||
2295 | { | |||
2296 | // Fraction::Fraction takes a double, but we have a float only. | |||
2297 | // The implicit conversion from float to double can result in a precision loss, i.e. 1.2 is converted to | |||
2298 | // 1.200000000047something. To prevent this, we convert explicitly to double, and round it. | |||
2299 | double nZoom( fZoomX ); | |||
2300 | Fraction aZoom(::rtl::math::round(nZoom, 4)); | |||
2301 | aZoom.ReduceInaccurate(10); // to avoid runovers and BigInt mapping | |||
2302 | GetWindow()->SetZoom(aZoom); | |||
2303 | } | |||
2304 | } | |||
2305 | ||||
2306 | // css::lang::XEventListener | |||
2307 | void SAL_CALL VCLXWindow::disposing( const css::lang::EventObject& _rSource ) | |||
2308 | { | |||
2309 | SolarMutexGuard aGuard; | |||
2310 | ||||
2311 | // check if it comes from our AccessibleContext | |||
2312 | uno::Reference< uno::XInterface > aAC( mpImpl->mxAccessibleContext, uno::UNO_QUERY ); | |||
2313 | uno::Reference< uno::XInterface > xSource( _rSource.Source, uno::UNO_QUERY ); | |||
2314 | ||||
2315 | if ( aAC.get() == xSource.get() ) | |||
2316 | { // yep, it does | |||
2317 | mpImpl->mxAccessibleContext.clear(); | |||
2318 | } | |||
2319 | } | |||
2320 | ||||
2321 | // css::accessibility::XAccessible | |||
2322 | css::uno::Reference< css::accessibility::XAccessibleContext > VCLXWindow::getAccessibleContext( ) | |||
2323 | { | |||
2324 | SolarMutexGuard aGuard; | |||
2325 | ||||
2326 | // already disposed | |||
2327 | if( ! mpImpl ) | |||
2328 | return uno::Reference< accessibility::XAccessibleContext >(); | |||
2329 | ||||
2330 | if ( !mpImpl->mxAccessibleContext.is() && GetWindow() ) | |||
2331 | { | |||
2332 | mpImpl->mxAccessibleContext = CreateAccessibleContext(); | |||
2333 | ||||
2334 | // add as event listener to this component | |||
2335 | // in case somebody disposes it, we do not want to have a (though weak) reference to a dead | |||
2336 | // object | |||
2337 | uno::Reference< lang::XComponent > xComp( mpImpl->mxAccessibleContext, uno::UNO_QUERY ); | |||
2338 | if ( xComp.is() ) | |||
2339 | xComp->addEventListener( this ); | |||
2340 | } | |||
2341 | ||||
2342 | return mpImpl->mxAccessibleContext; | |||
2343 | } | |||
2344 | ||||
2345 | // css::awt::XDockable | |||
2346 | void SAL_CALL VCLXWindow::addDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener ) | |||
2347 | { | |||
2348 | SolarMutexGuard aGuard; | |||
2349 | ||||
2350 | if ( xListener.is() ) | |||
2351 | mpImpl->getDockableWindowListeners().addInterface( xListener ); | |||
2352 | ||||
2353 | } | |||
2354 | ||||
2355 | void SAL_CALL VCLXWindow::removeDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener ) | |||
2356 | { | |||
2357 | SolarMutexGuard aGuard; | |||
2358 | ||||
2359 | mpImpl->getDockableWindowListeners().removeInterface( xListener ); | |||
2360 | } | |||
2361 | ||||
2362 | void SAL_CALL VCLXWindow::enableDocking( sal_Bool bEnable ) | |||
2363 | { | |||
2364 | SolarMutexGuard aGuard; | |||
2365 | ||||
2366 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
2367 | if ( pWindow ) | |||
2368 | pWindow->EnableDocking( bEnable ); | |||
2369 | } | |||
2370 | ||||
2371 | sal_Bool SAL_CALL VCLXWindow::isFloating( ) | |||
2372 | { | |||
2373 | SolarMutexGuard aGuard; | |||
2374 | ||||
2375 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
2376 | if( pWindow ) | |||
2377 | return vcl::Window::GetDockingManager()->IsFloating( pWindow ); | |||
2378 | else | |||
2379 | return false; | |||
2380 | } | |||
2381 | ||||
2382 | void SAL_CALL VCLXWindow::setFloatingMode( sal_Bool bFloating ) | |||
2383 | { | |||
2384 | SolarMutexGuard aGuard; | |||
2385 | ||||
2386 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
2387 | if( pWindow ) | |||
2388 | vcl::Window::GetDockingManager()->SetFloatingMode( pWindow, bFloating ); | |||
2389 | } | |||
2390 | ||||
2391 | sal_Bool SAL_CALL VCLXWindow::isLocked( ) | |||
2392 | { | |||
2393 | SolarMutexGuard aGuard; | |||
2394 | ||||
2395 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
2396 | if( pWindow ) | |||
2397 | return vcl::Window::GetDockingManager()->IsLocked( pWindow ); | |||
2398 | else | |||
2399 | return false; | |||
2400 | } | |||
2401 | ||||
2402 | void SAL_CALL VCLXWindow::lock( ) | |||
2403 | { | |||
2404 | SolarMutexGuard aGuard; | |||
2405 | ||||
2406 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
2407 | if( pWindow && !vcl::Window::GetDockingManager()->IsFloating( pWindow ) ) | |||
2408 | vcl::Window::GetDockingManager()->Lock( pWindow ); | |||
2409 | } | |||
2410 | ||||
2411 | void SAL_CALL VCLXWindow::unlock( ) | |||
2412 | { | |||
2413 | SolarMutexGuard aGuard; | |||
2414 | ||||
2415 | VclPtr<vcl::Window> pWindow = GetWindow(); | |||
2416 | if( pWindow && !vcl::Window::GetDockingManager()->IsFloating( pWindow ) ) | |||
2417 | vcl::Window::GetDockingManager()->Unlock( pWindow ); | |||
2418 | } | |||
2419 | ||||
2420 | void SAL_CALL VCLXWindow::startPopupMode( const css::awt::Rectangle& ) | |||
2421 | { | |||
2422 | // TODO: remove interface in the next incompatible build | |||
2423 | } | |||
2424 | ||||
2425 | sal_Bool SAL_CALL VCLXWindow::isInPopupMode( ) | |||
2426 | { | |||
2427 | // TODO: remove interface in the next incompatible build | |||
2428 | return false; | |||
2429 | } | |||
2430 | ||||
2431 | ||||
2432 | // css::awt::XWindow2 | |||
2433 | ||||
2434 | void SAL_CALL VCLXWindow::setOutputSize( const css::awt::Size& aSize ) | |||
2435 | { | |||
2436 | SolarMutexGuard aGuard; | |||
2437 | if( VclPtr<vcl::Window> pWindow = GetWindow() ) | |||
2438 | pWindow->SetOutputSizePixel( VCLSize( aSize ) ); | |||
2439 | } | |||
2440 | ||||
2441 | css::awt::Size SAL_CALL VCLXWindow::getOutputSize( ) | |||
2442 | { | |||
2443 | SolarMutexGuard aGuard; | |||
2444 | if( VclPtr<vcl::Window> pWindow = GetWindow() ) | |||
2445 | return AWTSize( pWindow->GetOutputSizePixel() ); | |||
2446 | else | |||
2447 | return css::awt::Size(); | |||
2448 | } | |||
2449 | ||||
2450 | sal_Bool SAL_CALL VCLXWindow::isVisible( ) | |||
2451 | { | |||
2452 | SolarMutexGuard aGuard; | |||
2453 | if( GetWindow() ) | |||
2454 | return GetWindow()->IsVisible(); | |||
2455 | else | |||
2456 | return false; | |||
2457 | } | |||
2458 | ||||
2459 | sal_Bool SAL_CALL VCLXWindow::isActive( ) | |||
2460 | { | |||
2461 | SolarMutexGuard aGuard; | |||
2462 | if( GetWindow() ) | |||
2463 | return GetWindow()->IsActive(); | |||
2464 | else | |||
2465 | return false; | |||
2466 | ||||
2467 | } | |||
2468 | ||||
2469 | sal_Bool SAL_CALL VCLXWindow::isEnabled( ) | |||
2470 | { | |||
2471 | SolarMutexGuard aGuard; | |||
2472 | if( GetWindow() ) | |||
2473 | return GetWindow()->IsEnabled(); | |||
2474 | else | |||
2475 | return false; | |||
2476 | } | |||
2477 | ||||
2478 | sal_Bool SAL_CALL VCLXWindow::hasFocus( ) | |||
2479 | { | |||
2480 | SolarMutexGuard aGuard; | |||
2481 | if( GetWindow() ) | |||
2482 | return GetWindow()->HasFocus(); | |||
2483 | else | |||
2484 | return false; | |||
2485 | } | |||
2486 | ||||
2487 | // css::beans::XPropertySetInfo | |||
2488 | ||||
2489 | UnoPropertyArrayHelper * | |||
2490 | VCLXWindow::GetPropHelper() | |||
2491 | { | |||
2492 | SolarMutexGuard aGuard; | |||
2493 | if ( mpImpl->mpPropHelper == nullptr ) | |||
2494 | { | |||
2495 | std::vector< sal_uInt16 > aIDs; | |||
2496 | GetPropertyIds( aIDs ); | |||
2497 | mpImpl->mpPropHelper.reset( new UnoPropertyArrayHelper( aIDs ) ); | |||
2498 | } | |||
2499 | return mpImpl->mpPropHelper.get(); | |||
2500 | } | |||
2501 | ||||
2502 | css::uno::Sequence< css::beans::Property > SAL_CALL | |||
2503 | VCLXWindow::getProperties() | |||
2504 | { | |||
2505 | return GetPropHelper()->getProperties(); | |||
2506 | } | |||
2507 | css::beans::Property SAL_CALL | |||
2508 | VCLXWindow::getPropertyByName( const OUString& rName ) | |||
2509 | { | |||
2510 | return GetPropHelper()->getPropertyByName( rName ); | |||
2511 | } | |||
2512 | ||||
2513 | sal_Bool SAL_CALL | |||
2514 | VCLXWindow::hasPropertyByName( const OUString& rName ) | |||
2515 | { | |||
2516 | return GetPropHelper()->hasPropertyByName( rName ); | |||
2517 | } | |||
2518 | ||||
2519 | Reference< XStyleSettings > SAL_CALL VCLXWindow::getStyleSettings() | |||
2520 | { | |||
2521 | return mpImpl->getStyleSettings(); | |||
2522 | } | |||
2523 | ||||
2524 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
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/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
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 . |
18 | */ |
19 | |
20 | #ifndef INCLUDED_TOOLKIT_AWT_VCLXWINDOW_HXX |
21 | #define INCLUDED_TOOLKIT_AWT_VCLXWINDOW_HXX |
22 | |
23 | #include <toolkit/dllapi.h> |
24 | #include <toolkit/awt/vclxdevice.hxx> |
25 | #include <vcl/window.hxx> |
26 | |
27 | #include <com/sun/star/awt/XWindow2.hpp> |
28 | #include <com/sun/star/awt/XVclWindowPeer.hpp> |
29 | #include <com/sun/star/awt/XLayoutConstrains.hpp> |
30 | #include <com/sun/star/awt/XView.hpp> |
31 | #include <com/sun/star/beans/XPropertySetInfo.hpp> |
32 | #include <com/sun/star/accessibility/XAccessible.hpp> |
33 | #include <com/sun/star/awt/XDockableWindow.hpp> |
34 | #include <com/sun/star/awt/XStyleSettingsSupplier.hpp> |
35 | |
36 | #include <comphelper/servicehelper.hxx> |
37 | #include <cppuhelper/implbase.hxx> |
38 | |
39 | #include <tools/gen.hxx> |
40 | #include <tools/link.hxx> |
41 | |
42 | #include <memory> |
43 | #include <vector> |
44 | #include <functional> |
45 | |
46 | namespace comphelper { class OInterfaceContainerHelper2; } |
47 | namespace com::sun::star::accessibility { class XAccessibleContext; } |
48 | |
49 | class VclWindowEvent; |
50 | |
51 | namespace toolkit |
52 | { |
53 | class IAccessibleFactory; |
54 | } |
55 | |
56 | |
57 | class UnoPropertyArrayHelper; |
58 | class VCLXWindowImpl; |
59 | typedef cppu::ImplInheritanceHelper< VCLXDevice, |
60 | css::awt::XWindow2, |
61 | css::awt::XVclWindowPeer, |
62 | css::awt::XLayoutConstrains, |
63 | css::awt::XView, |
64 | css::awt::XDockableWindow, |
65 | css::accessibility::XAccessible, |
66 | css::lang::XEventListener, |
67 | css::beans::XPropertySetInfo, |
68 | css::awt::XStyleSettingsSupplier |
69 | > VCLXWindow_Base; |
70 | |
71 | class TOOLKIT_DLLPUBLIC__attribute__ ((visibility("default"))) VCLXWindow : public VCLXWindow_Base |
72 | { |
73 | private: |
74 | std::unique_ptr<VCLXWindowImpl> mpImpl; |
75 | |
76 | UnoPropertyArrayHelper *GetPropHelper(); |
77 | |
78 | protected: |
79 | Size ImplCalcWindowSize( const Size& rOutSz ) const; |
80 | DECL_LINK(WindowEventListener, VclWindowEvent&, void )static void LinkStubWindowEventListener(void *, VclWindowEvent &); void WindowEventListener(VclWindowEvent&); |
81 | |
82 | virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ); |
83 | virtual css::uno::Reference< css::accessibility::XAccessibleContext > |
84 | CreateAccessibleContext(); |
85 | |
86 | void SetSynthesizingVCLEvent( bool b ); |
87 | bool IsSynthesizingVCLEvent() const; |
88 | |
89 | void SetSystemParent_Impl( const css::uno::Any& rHandle ); |
90 | |
91 | ::toolkit::IAccessibleFactory& getAccessibleFactory(); |
92 | |
93 | // helper ... |
94 | static void PushPropertyIds( std::vector< sal_uInt16 > &aIds, int nFirstId, ...); |
95 | // for use in controls/ |
96 | static void ImplGetPropertyIds( std::vector< sal_uInt16 > &aIds, |
97 | bool bWithDefaults = false ); |
98 | virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds ); |
99 | |
100 | ::comphelper::OInterfaceContainerHelper2& GetContainerListeners(); |
101 | ::comphelper::OInterfaceContainerHelper2& GetTopWindowListeners(); |
102 | |
103 | public: |
104 | typedef ::std::function<void ()> Callback; |
105 | |
106 | protected: |
107 | /** executes the given callback asynchronously |
108 | |
109 | At the moment the callback is called, the Solar Mutex is not locked. In particular, this implies that |
110 | you cannot rely on |this| not being disposed. However, you *can* rely on |this| being still alive (i.e. |
111 | having a ref count > 0). |
112 | |
113 | As a consequence, this can be used for doing listener notifications, using event multiplexers. Those multiplexers |
114 | care for the disposed state themself, and are alive as long as |this| is alive. |
115 | */ |
116 | void ImplExecuteAsyncWithoutSolarLock( |
117 | const Callback& i_callback |
118 | ); |
119 | |
120 | public: |
121 | VCLXWindow( bool bWithDefaultProps = false ); |
122 | virtual ~VCLXWindow() override; |
123 | |
124 | virtual void SetWindow( const VclPtr< vcl::Window > &pWindow ); |
125 | template< class derived_type > VclPtr< derived_type > GetAs() const { |
126 | return VclPtr< derived_type >( static_cast< derived_type * >( GetOutputDevice().get() ) ); } |
127 | template< class derived_type > VclPtr< derived_type > GetAsDynamic() const { |
128 | return VclPtr< derived_type >( dynamic_cast< derived_type * >( GetOutputDevice().get() ) ); } |
129 | VclPtr<vcl::Window> GetWindow() const { return GetAs<vcl::Window>(); } |
130 | |
131 | void suspendVclEventListening( ); |
132 | void resumeVclEventListening( ); |
133 | |
134 | void notifyWindowRemoved( vcl::Window const & _rWindow ); |
135 | |
136 | // css::lang::XUnoTunnel |
137 | UNO3_GETIMPLEMENTATION_DECL(VCLXWindow)static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId () throw(); virtual sal_Int64 getSomething( const css::uno::Sequence < sal_Int8 >& aIdentifier ) override; |
138 | |
139 | // css::lang::XEventListener |
140 | virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; |
141 | |
142 | // css::lang::XComponent |
143 | void SAL_CALL dispose( ) override; |
144 | void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) override; |
145 | void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) override; |
146 | |
147 | // css::awt::XWindow |
148 | void SAL_CALL setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) override; |
149 | css::awt::Rectangle SAL_CALL getPosSize( ) override; |
150 | void SAL_CALL setVisible( sal_Bool Visible ) override; |
151 | void SAL_CALL setEnable( sal_Bool Enable ) override; |
152 | void SAL_CALL setFocus( ) override; |
153 | void SAL_CALL addWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rrxListener ) override; |
154 | void SAL_CALL removeWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rrxListener ) override; |
155 | void SAL_CALL addFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rrxListener ) override; |
156 | void SAL_CALL removeFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rrxListener ) override; |
157 | void SAL_CALL addKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rrxListener ) override; |
158 | void SAL_CALL removeKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rrxListener ) override; |
159 | void SAL_CALL addMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rrxListener ) override; |
160 | void SAL_CALL removeMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rrxListener ) override; |
161 | void SAL_CALL addMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rrxListener ) override; |
162 | void SAL_CALL removeMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rrxListener ) override; |
163 | void SAL_CALL addPaintListener( const css::uno::Reference< css::awt::XPaintListener >& rrxListener ) override; |
164 | void SAL_CALL removePaintListener( const css::uno::Reference< css::awt::XPaintListener >& rrxListener ) override; |
165 | |
166 | // css::awt::XWindowPeer |
167 | css::uno::Reference< css::awt::XToolkit > SAL_CALL getToolkit( ) override; |
168 | void SAL_CALL setPointer( const css::uno::Reference< css::awt::XPointer >& Pointer ) override; |
169 | void SAL_CALL setBackground( sal_Int32 Color ) override; |
170 | void SAL_CALL invalidate( sal_Int16 Flags ) override; |
171 | void SAL_CALL invalidateRect( const css::awt::Rectangle& Rect, sal_Int16 Flags ) override; |
172 | |
173 | // css::awt::XVclWindowPeer |
174 | sal_Bool SAL_CALL isChild( const css::uno::Reference< css::awt::XWindowPeer >& Peer ) override; |
175 | void SAL_CALL setDesignMode( sal_Bool bOn ) override; |
176 | sal_Bool SAL_CALL isDesignMode( ) override; |
177 | void SAL_CALL enableClipSiblings( sal_Bool bClip ) override; |
178 | void SAL_CALL setForeground( sal_Int32 Color ) override; |
179 | void SAL_CALL setControlFont( const css::awt::FontDescriptor& aFont ) override; |
180 | void SAL_CALL getStyles( sal_Int16 nType, css::awt::FontDescriptor& Font, sal_Int32& ForegroundColor, sal_Int32& BackgroundColor ) override; |
181 | void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override; |
182 | css::uno::Any SAL_CALL getProperty( const OUString& PropertyName ) override; |
183 | |
184 | // css::awt::XLayoutConstrains |
185 | css::awt::Size SAL_CALL getMinimumSize( ) override; |
186 | css::awt::Size SAL_CALL getPreferredSize( ) override; |
187 | css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& aNewSize ) override; |
188 | |
189 | // css::awt::XView |
190 | sal_Bool SAL_CALL setGraphics( const css::uno::Reference< css::awt::XGraphics >& aDevice ) override; |
191 | css::uno::Reference< css::awt::XGraphics > SAL_CALL getGraphics( ) override; |
192 | css::awt::Size SAL_CALL getSize( ) override; |
193 | void SAL_CALL draw( sal_Int32 nX, sal_Int32 nY ) override; |
194 | void SAL_CALL setZoom( float fZoomX, float fZoomY ) override; |
195 | |
196 | // css::accessibility::XAccessible |
197 | css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override; |
198 | |
199 | // css::awt::XDockableWindow |
200 | void SAL_CALL addDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener ) override; |
201 | void SAL_CALL removeDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener ) override; |
202 | void SAL_CALL enableDocking( sal_Bool bEnable ) override; |
203 | sal_Bool SAL_CALL isFloating( ) override; |
204 | void SAL_CALL setFloatingMode( sal_Bool bFloating ) override; |
205 | void SAL_CALL lock( ) override; |
206 | void SAL_CALL unlock( ) override; |
207 | sal_Bool SAL_CALL isLocked( ) override; |
208 | void SAL_CALL startPopupMode( const css::awt::Rectangle& WindowRect ) override; |
209 | sal_Bool SAL_CALL isInPopupMode( ) override; |
210 | |
211 | // css::awt::XWindow2 |
212 | void SAL_CALL setOutputSize( const css::awt::Size& aSize ) override; |
213 | css::awt::Size SAL_CALL getOutputSize( ) override; |
214 | sal_Bool SAL_CALL isVisible( ) override; |
215 | sal_Bool SAL_CALL isActive( ) override; |
216 | sal_Bool SAL_CALL isEnabled( ) override; |
217 | sal_Bool SAL_CALL hasFocus( ) override; |
218 | |
219 | // css::beans::XPropertySetInfo |
220 | css::uno::Sequence< css::beans::Property > SAL_CALL getProperties( ) override; |
221 | css::beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override; |
222 | sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override; |
223 | |
224 | // XStyleSettingsSupplier |
225 | virtual css::uno::Reference< css::awt::XStyleSettings > SAL_CALL getStyleSettings() override; |
226 | }; |
227 | |
228 | #endif // INCLUDED_TOOLKIT_AWT_VCLXWINDOW_HXX |
229 | |
230 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
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/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
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 . |
18 | */ |
19 | |
20 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||||||||||||||||||||
2 | /* | ||||||||||||||||||||
3 | * This file is part of the LibreOffice project. | ||||||||||||||||||||
4 | * | ||||||||||||||||||||
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/. | ||||||||||||||||||||
8 | * | ||||||||||||||||||||
9 | * This file incorporates work covered by the following license notice: | ||||||||||||||||||||
10 | * | ||||||||||||||||||||
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 . | ||||||||||||||||||||
18 | */ | ||||||||||||||||||||
19 | |||||||||||||||||||||
20 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||||||||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||||||||||||||
22 | |||||||||||||||||||||
23 | #include "sal/config.h" | ||||||||||||||||||||
24 | |||||||||||||||||||||
25 | #include <cassert> | ||||||||||||||||||||
26 | #include <cstddef> | ||||||||||||||||||||
27 | #include <functional> | ||||||||||||||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
29 | #include <type_traits> | ||||||||||||||||||||
30 | #endif | ||||||||||||||||||||
31 | |||||||||||||||||||||
32 | #include "sal/types.h" | ||||||||||||||||||||
33 | |||||||||||||||||||||
34 | namespace rtl | ||||||||||||||||||||
35 | { | ||||||||||||||||||||
36 | |||||||||||||||||||||
37 | /** Template reference class for reference type. | ||||||||||||||||||||
38 | */ | ||||||||||||||||||||
39 | template <class reference_type> | ||||||||||||||||||||
40 | class Reference | ||||||||||||||||||||
41 | { | ||||||||||||||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||||||||||||||
43 | */ | ||||||||||||||||||||
44 | reference_type * m_pBody; | ||||||||||||||||||||
45 | |||||||||||||||||||||
46 | |||||||||||||||||||||
47 | public: | ||||||||||||||||||||
48 | /** Constructor... | ||||||||||||||||||||
49 | */ | ||||||||||||||||||||
50 | Reference() | ||||||||||||||||||||
51 | : m_pBody (NULL__null) | ||||||||||||||||||||
52 | {} | ||||||||||||||||||||
53 | |||||||||||||||||||||
54 | |||||||||||||||||||||
55 | /** Constructor... | ||||||||||||||||||||
56 | */ | ||||||||||||||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||||||||||||||
58 | : m_pBody (pBody) | ||||||||||||||||||||
59 | { | ||||||||||||||||||||
60 | } | ||||||||||||||||||||
61 | |||||||||||||||||||||
62 | /** Constructor... | ||||||||||||||||||||
63 | */ | ||||||||||||||||||||
64 | Reference (reference_type * pBody) | ||||||||||||||||||||
65 | : m_pBody (pBody) | ||||||||||||||||||||
66 | { | ||||||||||||||||||||
67 | if (m_pBody) | ||||||||||||||||||||
68 | m_pBody->acquire(); | ||||||||||||||||||||
69 | } | ||||||||||||||||||||
70 | |||||||||||||||||||||
71 | /** Copy constructor... | ||||||||||||||||||||
72 | */ | ||||||||||||||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||||||||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||||||||||||||
75 | { | ||||||||||||||||||||
76 | if (m_pBody) | ||||||||||||||||||||
77 | m_pBody->acquire(); | ||||||||||||||||||||
78 | } | ||||||||||||||||||||
79 | |||||||||||||||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
81 | /** Move constructor... | ||||||||||||||||||||
82 | */ | ||||||||||||||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||||||||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||||||||||||||
85 | { | ||||||||||||||||||||
86 | handle.m_pBody = nullptr; | ||||||||||||||||||||
87 | } | ||||||||||||||||||||
88 | #endif | ||||||||||||||||||||
89 | |||||||||||||||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||||||||||||||
92 | |||||||||||||||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||||||||||||||
94 | |||||||||||||||||||||
95 | @param rRef another reference | ||||||||||||||||||||
96 | */ | ||||||||||||||||||||
97 | template< class derived_type > | ||||||||||||||||||||
98 | inline Reference( | ||||||||||||||||||||
99 | const Reference< derived_type > & rRef, | ||||||||||||||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||||||||||||||
101 | : m_pBody (rRef.get()) | ||||||||||||||||||||
102 | { | ||||||||||||||||||||
103 | if (m_pBody) | ||||||||||||||||||||
104 | m_pBody->acquire(); | ||||||||||||||||||||
105 | } | ||||||||||||||||||||
106 | #endif | ||||||||||||||||||||
107 | |||||||||||||||||||||
108 | /** Destructor... | ||||||||||||||||||||
109 | */ | ||||||||||||||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||||||||||||||
111 | { | ||||||||||||||||||||
112 | if (m_pBody
| ||||||||||||||||||||
113 | m_pBody->release(); | ||||||||||||||||||||
| |||||||||||||||||||||
114 | } | ||||||||||||||||||||
115 | |||||||||||||||||||||
116 | /** Set... | ||||||||||||||||||||
117 | Similar to assignment. | ||||||||||||||||||||
118 | */ | ||||||||||||||||||||
119 | Reference<reference_type> & | ||||||||||||||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||||||||||||||
121 | { | ||||||||||||||||||||
122 | if (pBody) | ||||||||||||||||||||
123 | pBody->acquire(); | ||||||||||||||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||||||||||||||
125 | m_pBody = pBody; | ||||||||||||||||||||
126 | if (pOld) | ||||||||||||||||||||
127 | pOld->release(); | ||||||||||||||||||||
128 | return *this; | ||||||||||||||||||||
129 | } | ||||||||||||||||||||
130 | |||||||||||||||||||||
131 | /** Assignment. | ||||||||||||||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||||||||||||||
133 | bind it to the body represented by the handle. | ||||||||||||||||||||
134 | */ | ||||||||||||||||||||
135 | Reference<reference_type> & | ||||||||||||||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||||||||||||||
137 | { | ||||||||||||||||||||
138 | return set( handle.m_pBody ); | ||||||||||||||||||||
139 | } | ||||||||||||||||||||
140 | |||||||||||||||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
142 | /** Assignment. | ||||||||||||||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||||||||||||||
144 | * bind it to the body represented by the handle, and | ||||||||||||||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||||||||||||||
146 | */ | ||||||||||||||||||||
147 | Reference<reference_type> & | ||||||||||||||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||||||||||||||
149 | { | ||||||||||||||||||||
150 | // self-movement guts ourself | ||||||||||||||||||||
151 | if (m_pBody) | ||||||||||||||||||||
152 | m_pBody->release(); | ||||||||||||||||||||
153 | m_pBody = handle.m_pBody; | ||||||||||||||||||||
154 | handle.m_pBody = nullptr; | ||||||||||||||||||||
155 | return *this; | ||||||||||||||||||||
156 | } | ||||||||||||||||||||
157 | #endif | ||||||||||||||||||||
158 | |||||||||||||||||||||
159 | /** Assignment... | ||||||||||||||||||||
160 | */ | ||||||||||||||||||||
161 | Reference<reference_type> & | ||||||||||||||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||||||||||||||
163 | { | ||||||||||||||||||||
164 | return set( pBody ); | ||||||||||||||||||||
165 | } | ||||||||||||||||||||
166 | |||||||||||||||||||||
167 | /** Unbind the body from this handle. | ||||||||||||||||||||
168 | Note that for a handle representing a large body, | ||||||||||||||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||||||||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||||||||||||||
171 | since in the second case two large objects exist in memory | ||||||||||||||||||||
172 | (the old body and the new body). | ||||||||||||||||||||
173 | */ | ||||||||||||||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||||||||||||||
175 | { | ||||||||||||||||||||
176 | if (m_pBody) | ||||||||||||||||||||
177 | { | ||||||||||||||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||||||||||||||
179 | m_pBody = NULL__null; | ||||||||||||||||||||
180 | pOld->release(); | ||||||||||||||||||||
181 | } | ||||||||||||||||||||
182 | return *this; | ||||||||||||||||||||
183 | } | ||||||||||||||||||||
184 | |||||||||||||||||||||
185 | |||||||||||||||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||||||||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||||||||||||||
188 | are the same. | ||||||||||||||||||||
189 | */ | ||||||||||||||||||||
190 | reference_type * SAL_CALL get() const | ||||||||||||||||||||
191 | { | ||||||||||||||||||||
192 | return m_pBody; | ||||||||||||||||||||
193 | } | ||||||||||||||||||||
194 | |||||||||||||||||||||
195 | |||||||||||||||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||||||||||||||
197 | */ | ||||||||||||||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||||||||||||||
199 | { | ||||||||||||||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||||||||||||||
201 | return m_pBody; | ||||||||||||||||||||
202 | } | ||||||||||||||||||||
203 | |||||||||||||||||||||
204 | |||||||||||||||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||||||||||||||
206 | */ | ||||||||||||||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||||||||||||||
208 | { | ||||||||||||||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||||||||||||||
210 | return *m_pBody; | ||||||||||||||||||||
211 | } | ||||||||||||||||||||
212 | |||||||||||||||||||||
213 | |||||||||||||||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||||||||||||||
215 | */ | ||||||||||||||||||||
216 | bool SAL_CALL is() const | ||||||||||||||||||||
217 | { | ||||||||||||||||||||
218 | return (m_pBody != NULL__null); | ||||||||||||||||||||
219 | } | ||||||||||||||||||||
220 | |||||||||||||||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||||||||||||||
223 | */ | ||||||||||||||||||||
224 | explicit operator bool() const | ||||||||||||||||||||
225 | { | ||||||||||||||||||||
226 | return is(); | ||||||||||||||||||||
227 | } | ||||||||||||||||||||
228 | #endif | ||||||||||||||||||||
229 | |||||||||||||||||||||
230 | /** Returns True if this points to pBody. | ||||||||||||||||||||
231 | */ | ||||||||||||||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||||||||||||||
233 | { | ||||||||||||||||||||
234 | return (m_pBody == pBody); | ||||||||||||||||||||
235 | } | ||||||||||||||||||||
236 | |||||||||||||||||||||
237 | |||||||||||||||||||||
238 | /** Returns True if handle points to the same body. | ||||||||||||||||||||
239 | */ | ||||||||||||||||||||
240 | bool | ||||||||||||||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||||||||||||||
242 | { | ||||||||||||||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||||||||||||||
244 | } | ||||||||||||||||||||
245 | |||||||||||||||||||||
246 | |||||||||||||||||||||
247 | /** Needed to place References into STL collection. | ||||||||||||||||||||
248 | */ | ||||||||||||||||||||
249 | bool | ||||||||||||||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||||||||||||||
251 | { | ||||||||||||||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||||||||||||||
253 | } | ||||||||||||||||||||
254 | |||||||||||||||||||||
255 | |||||||||||||||||||||
256 | /** Needed to place References into STL collection. | ||||||||||||||||||||
257 | */ | ||||||||||||||||||||
258 | bool | ||||||||||||||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||||||||||||||
260 | { | ||||||||||||||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||||||||||||||
262 | } | ||||||||||||||||||||
263 | |||||||||||||||||||||
264 | |||||||||||||||||||||
265 | /** Needed to place References into STL collection. | ||||||||||||||||||||
266 | */ | ||||||||||||||||||||
267 | bool | ||||||||||||||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||||||||||||||
269 | { | ||||||||||||||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||||||||||||||
271 | } | ||||||||||||||||||||
272 | }; | ||||||||||||||||||||
273 | |||||||||||||||||||||
274 | } // namespace rtl | ||||||||||||||||||||
275 | |||||||||||||||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
277 | namespace std | ||||||||||||||||||||
278 | { | ||||||||||||||||||||
279 | |||||||||||||||||||||
280 | /// @cond INTERNAL | ||||||||||||||||||||
281 | /** | ||||||||||||||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||||||||||||||
283 | |||||||||||||||||||||
284 | @since LibreOffice 6.3 | ||||||||||||||||||||
285 | */ | ||||||||||||||||||||
286 | template<typename T> | ||||||||||||||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||||||||||||||
288 | { | ||||||||||||||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||||||||||||||
290 | { return std::size_t(s.get()); } | ||||||||||||||||||||
291 | }; | ||||||||||||||||||||
292 | /// @endcond | ||||||||||||||||||||
293 | |||||||||||||||||||||
294 | } | ||||||||||||||||||||
295 | |||||||||||||||||||||
296 | #endif | ||||||||||||||||||||
297 | |||||||||||||||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||||||||||||||
299 | |||||||||||||||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
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/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
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 . |
18 | */ |
19 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |