cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / inc / DrawController.hxx
blob4dc81feca3afc0529da100b074bb0ef2ec8fcf05
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <sddllapi.h>
23 #include <cppuhelper/propshlp.hxx>
24 #include <sfx2/sfxbasecontroller.hxx>
25 #include <com/sun/star/view/XSelectionSupplier.hpp>
26 #include <com/sun/star/view/XFormLayerAccess.hpp>
27 #include <com/sun/star/drawing/XDrawView.hpp>
28 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <comphelper/uno3.hxx>
31 #include <cppuhelper/implbase.hxx>
32 #include <unotools/weakref.hxx>
33 #include <rtl/ref.hxx>
34 #include <tools/gen.hxx>
35 #include <memory>
36 #include <vector>
38 namespace com::sun::star::drawing { class XDrawSubController; }
39 namespace com::sun::star::drawing::framework { class XConfigurationController; }
40 namespace com::sun::star::drawing::framework { class XModuleController; }
41 namespace com::sun::star::drawing { class XLayer; }
42 namespace osl { class Mutex; }
43 namespace sd::framework { class ConfigurationController; }
44 namespace sd::framework { class ModuleController; }
45 class SdPage;
47 namespace sd {
49 typedef ::cppu::ImplInheritanceHelper <
50 SfxBaseController,
51 css::view::XSelectionSupplier,
52 css::lang::XServiceInfo,
53 css::drawing::XDrawView,
54 css::view::XSelectionChangeListener,
55 css::view::XFormLayerAccess,
56 css::drawing::framework::XControllerManager
57 > DrawControllerInterfaceBase;
59 class BroadcastHelperOwner
61 public:
62 explicit BroadcastHelperOwner (::osl::Mutex& rMutex) : maBroadcastHelper(rMutex) {};
63 ::cppu::OBroadcastHelper maBroadcastHelper;
66 class ViewShellBase;
68 /** The DrawController is the UNO controller for Impress and Draw. It
69 relies objects that implement the DrawSubController interface for view
70 specific behaviour. The life time of the DrawController is roughly that
71 of ViewShellBase but note that the DrawController can (in the case of a
72 reload) outlive the ViewShellBase.
74 The implementation of the XControllerManager interface is not yet in its
75 final form.
77 class SAL_DLLPUBLIC_RTTI DrawController final
78 : public DrawControllerInterfaceBase,
79 private BroadcastHelperOwner,
80 public ::cppu::OPropertySetHelper
82 public:
83 enum PropertyHandle {
84 PROPERTY_WORKAREA = 0,
85 PROPERTY_SUB_CONTROLLER = 1,
86 PROPERTY_CURRENTPAGE = 2,
87 PROPERTY_MASTERPAGEMODE = 3,
88 PROPERTY_LAYERMODE = 4,
89 PROPERTY_ACTIVE_LAYER = 5,
90 PROPERTY_ZOOMTYPE = 6,
91 PROPERTY_ZOOMVALUE = 7,
92 PROPERTY_VIEWOFFSET = 8,
93 PROPERTY_DRAWVIEWMODE = 9
94 ,PROPERTY_UPDATEACC = 10
95 ,PROPERTY_PAGE_CHANGE = 11
98 /** Create a new DrawController object for the given ViewShellBase.
100 explicit DrawController (ViewShellBase& rBase) noexcept;
102 virtual ~DrawController() noexcept override;
104 /** Replace the currently used sub controller with the given one. This
105 new sub controller is used from now on for the view (that is the
106 main view shell to be precise) specific tasks. Call this method
107 with a suitable sub controller whenever the view shell in the center
108 pane is exchanged.
109 @param pSubController
110 The ViewShell specific sub controller or NULL when (temporarily
111 while switching to another one) there is no ViewShell displayed
112 in the center pane.
114 void SetSubController (
115 const css::uno::Reference<css::drawing::XDrawSubController>& rxSubController);
117 /** Call this method when the VisArea has changed.
119 void FireVisAreaChanged (const ::tools::Rectangle& rVisArea) noexcept;
121 /** Call this method when the selection has changed.
123 void FireSelectionChangeListener() noexcept;
125 /** Call this method when the edit mode has changed.
127 void FireChangeEditMode (bool bMasterPageMode) noexcept;
129 /** Call this method when the layer mode has changed.
131 void FireChangeLayerMode (bool bLayerMode) noexcept;
133 /** Call this method when there is a new current page.
135 void FireSwitchCurrentPage (SdPage* pCurrentPage) noexcept;
137 /** Broadcast a sidebar context change that is caused by a view
138 switch.
140 void BroadcastContextChange() const;
141 void NotifyAccUpdate();
142 void fireChangeLayer( css::uno::Reference< css::drawing::XLayer>* pCurrentLayer ) noexcept;
143 // change the parameter to int
144 //void fireSwitchCurrentPage( String pageName) throw();
145 void fireSwitchCurrentPage( sal_Int32 pageIndex) noexcept;
146 bool IsDisposing() const { return mbDisposing; }
148 /** Return a pointer to the ViewShellBase object that the DrawController
149 is connected to.
150 @return
151 The returned pointer is <NULL/> after a call to
152 ReleaseViewShellBase().
154 ViewShellBase* GetViewShellBase() { return mpBase;}
156 /** This method is typically called from the destructor of ViewShellBase
157 to tell the DrawController that it and its members must not access
158 the ViewShellBase anymore.
159 After this call the DrawController is semi-disposed.
161 void ReleaseViewShellBase();
163 // XInterface
164 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
165 SD_DLLPUBLIC virtual void SAL_CALL acquire() noexcept override;
166 SD_DLLPUBLIC virtual void SAL_CALL release() noexcept override;
168 DECLARE_XTYPEPROVIDER()
170 // XComponent
171 virtual void SAL_CALL dispose() override;
172 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
173 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
175 // XController
176 virtual sal_Bool SAL_CALL suspend( sal_Bool Suspend ) override;
178 // XServiceInfo
179 virtual OUString SAL_CALL getImplementationName() override;
180 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
181 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
183 // XSelectionSupplier
184 virtual sal_Bool SAL_CALL select( const css::uno::Any& aSelection ) override;
185 virtual css::uno::Any SAL_CALL getSelection( ) override;
186 virtual void SAL_CALL addSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) override;
187 virtual void SAL_CALL removeSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) override;
189 // XPropertySet
190 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
192 // XFormLayerAccess
193 virtual css::uno::Reference< css::form::runtime::XFormController > SAL_CALL getFormController( const css::uno::Reference< css::form::XForm >& Form ) override;
194 virtual sal_Bool SAL_CALL isFormDesignMode( ) override;
195 virtual void SAL_CALL setFormDesignMode( sal_Bool DesignMode ) override;
197 // XControlAccess
198 virtual css::uno::Reference< css::awt::XControl > SAL_CALL getControl( const css::uno::Reference< css::awt::XControlModel >& xModel ) override;
200 // XDrawView
201 virtual void SAL_CALL
202 setCurrentPage (
203 const css::uno::Reference<
204 css::drawing::XDrawPage >& xPage) override;
206 virtual css::uno::Reference<
207 css::drawing::XDrawPage > SAL_CALL
208 getCurrentPage() override;
210 // lang::XEventListener
211 virtual void SAL_CALL
212 disposing (const css::lang::EventObject& rEventObject) override;
214 // view::XSelectionChangeListener
215 virtual void SAL_CALL
216 selectionChanged (const css::lang::EventObject& rEvent) override;
218 // XControllerManager
220 SD_DLLPUBLIC virtual css::uno::Reference<css::drawing::framework::XConfigurationController> SAL_CALL
221 getConfigurationController() override;
223 virtual css::uno::Reference<css::drawing::framework::XModuleController> SAL_CALL
224 getModuleController() override;
226 SD_DLLPUBLIC const rtl::Reference<sd::framework::ConfigurationController> & getConfigurationControllerImpl();
228 private:
229 /** This method must return the name to index table. This table
230 contains all property names and types of this object.
232 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
234 static void FillPropertyTable (
235 ::std::vector< css::beans::Property>& rProperties);
238 * The same as getFastPropertyValue, but return the value through
239 * rValue and nHandle is always valid.
241 virtual void SAL_CALL getFastPropertyValue(
242 css::uno::Any& rValue,
243 sal_Int32 nHandle ) const override;
245 /** Convert the value rValue and return the result in rConvertedValue and the
246 old value in rOldValue.
247 After this call the vetoable listeners are notified.
249 @param rConvertedValue
250 The converted value. Only set if return is true.
251 @param rOldValue
252 The old value. Only set if return is true.
253 @param nHandle
254 The handle of the property.
255 @return
256 <TRUE/> if the value is converted successfully.
257 @throws IllegalArgumentException
259 virtual sal_Bool SAL_CALL convertFastPropertyValue(
260 css::uno::Any & rConvertedValue,
261 css::uno::Any & rOldValue,
262 sal_Int32 nHandle,
263 const css::uno::Any& rValue ) override;
265 /** The same as setFastPropertyValue, but no exception is thrown and nHandle
266 is always valid. You must not broadcast the changes in this method.
268 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
269 sal_Int32 nHandle,
270 const css::uno::Any& rValue ) override;
272 /** When the called object has been disposed already this method throws
273 a Disposed exception and does not return.
275 @throws css::lang::DisposedException
277 void ThrowIfDisposed() const;
279 using cppu::OPropertySetHelper::disposing;
280 using cppu::OPropertySetHelper::getFastPropertyValue;
282 css::uno::Reference< css::drawing::XLayer>* mpCurrentLayer;
284 const css::uno::Type m_aSelectionTypeIdentifier;
286 /** This pointer to the ViewShellBase can be NULL (after a call to
287 ReleaseViewShellBase()).
289 ViewShellBase* mpBase;
291 ::tools::Rectangle maLastVisArea;
292 ::unotools::WeakReference<SdPage> mpCurrentPage;
293 bool mbMasterPageMode;
294 bool mbLayerMode;
296 /** This flag indicates whether the called DrawController is being
297 disposed or already has been disposed.
299 bool mbDisposing;
301 ::std::unique_ptr< ::cppu::IPropertyArrayHelper> mpPropertyArrayHelper;
303 /** The current sub controller. May be NULL.
305 css::uno::Reference<css::drawing::XDrawSubController> mxSubController;
307 rtl::Reference<sd::framework::ConfigurationController> mxConfigurationController;
308 rtl::Reference<sd::framework::ModuleController> mxModuleController;
310 /** Send an event to all relevant property listeners that a
311 property has changed its value. The fire() method of the
312 OPropertySetHelper is wrapped by this method to handle
313 exceptions thrown by called listeners.
315 void FirePropertyChange (
316 sal_Int32 nHandle,
317 const css::uno::Any& rNewValue,
318 const css::uno::Any& rOldValue);
320 void ProvideFrameworkControllers();
321 void DisposeFrameworkControllers();
324 } // end of namespace sd
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */