Line data Source code
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_SD_SOURCE_UI_INC_DRAWCONTROLLER_HXX
21 : #define INCLUDED_SD_SOURCE_UI_INC_DRAWCONTROLLER_HXX
22 :
23 : #include "ViewShell.hxx"
24 :
25 : #include <osl/mutex.hxx>
26 : #include <cppuhelper/propshlp.hxx>
27 : #include <sfx2/sfxbasecontroller.hxx>
28 : #include <com/sun/star/view/XSelectionSupplier.hpp>
29 : #include <com/sun/star/view/XFormLayerAccess.hpp>
30 : #include <com/sun/star/drawing/XDrawSubController.hpp>
31 : #include <com/sun/star/drawing/XDrawView.hpp>
32 : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
33 : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
34 : #include <com/sun/star/drawing/framework/ModuleController.hpp>
35 : #include <com/sun/star/lang/XServiceInfo.hpp>
36 : #include <com/sun/star/lang/DisposedException.hpp>
37 : #include <comphelper/uno3.hxx>
38 : #include <cppuhelper/implbase7.hxx>
39 : #include <tools/weakbase.hxx>
40 : #include <memory>
41 : #include <vector>
42 : #include <com/sun/star/drawing/XLayer.hpp>
43 :
44 : namespace sd {
45 :
46 : typedef ::cppu::ImplInheritanceHelper7 <
47 : SfxBaseController,
48 : ::com::sun::star::view::XSelectionSupplier,
49 : ::com::sun::star::lang::XServiceInfo,
50 : ::com::sun::star::drawing::XDrawView,
51 : ::com::sun::star::view::XSelectionChangeListener,
52 : ::com::sun::star::view::XFormLayerAccess,
53 : ::com::sun::star::drawing::framework::XControllerManager,
54 : ::com::sun::star::lang::XUnoTunnel
55 : > DrawControllerInterfaceBase;
56 :
57 84 : class BroadcastHelperOwner
58 : {
59 : public:
60 127 : BroadcastHelperOwner (::osl::Mutex& rMutex) : maBroadcastHelper(rMutex) {};
61 : ::cppu::OBroadcastHelper maBroadcastHelper;
62 : };
63 :
64 : class DrawSubController;
65 : class ViewShellBase;
66 : class ViewShell;
67 :
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.
73 :
74 : The implementation of the XControllerManager interface is not yet in its
75 : final form.
76 : */
77 : class DrawController
78 : : public DrawControllerInterfaceBase,
79 : private BroadcastHelperOwner,
80 : public ::cppu::OPropertySetHelper
81 : {
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
96 : };
97 :
98 : /** Create a new DrawController object for the given ViewShellBase.
99 : */
100 : DrawController (ViewShellBase& rBase) throw();
101 :
102 : virtual ~DrawController() throw();
103 :
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.
113 : */
114 : void SetSubController (
115 : const css::uno::Reference<css::drawing::XDrawSubController>& rxSubController);
116 :
117 : /** Call this method when the VisArea has changed.
118 : */
119 : void FireVisAreaChanged (const Rectangle& rVisArea) throw();
120 :
121 : /** Call this method when the selection has changed.
122 : */
123 : void FireSelectionChangeListener() throw();
124 :
125 : /** Call this method when the edit mode has changed.
126 : */
127 : void FireChangeEditMode (bool bMasterPageMode) throw();
128 :
129 : /** Call this method when the layer mode has changed.
130 : */
131 : void FireChangeLayerMode (bool bLayerMode) throw();
132 :
133 : /** Call this method when there is a new current page.
134 : */
135 : void FireSwitchCurrentPage (SdPage* pCurrentPage) throw();
136 :
137 : /** Broadcast a sidebar context change that is caused by a view
138 : switch.
139 : */
140 : void BroadcastContextChange() const;
141 : void NotifyAccUpdate();
142 : void fireChangeLayer( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XLayer>* pCurrentLayer ) throw();
143 : // change the parameter to int
144 : //void fireSwitchCurrentPage( String pageName) throw();
145 : void fireSwitchCurrentPage( sal_Int32 pageIndex) throw();
146 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XLayer>* mpCurrentLayer;
147 0 : bool IsDisposing() const { return mbDisposing; }
148 :
149 : /** Return a pointer to the ViewShellBase object that the DrawController
150 : is connected to.
151 : @return
152 : The returned pointer is <NULL/> after a call to
153 : ReleaseViewShellBase().
154 : */
155 682 : ViewShellBase* GetViewShellBase() { return mpBase;}
156 :
157 : /** This method is typically called from the destructor of ViewShellBase
158 : to tell the DrawController that it and its members must not access
159 : the ViewShellBase anymore.
160 : After this call the DrawController is semi-disposed.
161 : */
162 : void ReleaseViewShellBase();
163 :
164 : static const ::com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
165 :
166 : DECLARE_XINTERFACE()
167 : DECLARE_XTYPEPROVIDER()
168 :
169 : // XComponent
170 : virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
171 : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
172 : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 :
174 : // XController
175 : virtual sal_Bool SAL_CALL suspend( sal_Bool Suspend ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 :
177 : // XServiceInfo
178 : virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
179 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
180 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
181 :
182 : // XSelectionSupplier
183 : virtual sal_Bool SAL_CALL select( const ::com::sun::star::uno::Any& aSelection ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
184 : virtual ::com::sun::star::uno::Any SAL_CALL getSelection( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
185 : virtual void SAL_CALL addSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
186 : virtual void SAL_CALL removeSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
187 :
188 : // XPropertySet
189 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
190 :
191 : // XFormLayerAccess
192 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > SAL_CALL getFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& Form ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
193 : virtual sal_Bool SAL_CALL isFormDesignMode( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
194 : virtual void SAL_CALL setFormDesignMode( sal_Bool DesignMode ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
195 :
196 : // XControlAccess
197 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > SAL_CALL getControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& xModel ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
198 :
199 : // XDrawView
200 : virtual void SAL_CALL
201 : setCurrentPage (
202 : const ::com::sun::star::uno::Reference<
203 : ::com::sun::star::drawing::XDrawPage >& xPage)
204 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
205 :
206 : virtual ::com::sun::star::uno::Reference<
207 : ::com::sun::star::drawing::XDrawPage > SAL_CALL
208 : getCurrentPage()
209 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
210 :
211 : // lang::XEventListener
212 : virtual void SAL_CALL
213 : disposing (const ::com::sun::star::lang::EventObject& rEventObject)
214 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
215 :
216 : // view::XSelectionChangeListener
217 : virtual void SAL_CALL
218 : selectionChanged (const ::com::sun::star::lang::EventObject& rEvent)
219 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
220 :
221 : // XControllerManager
222 :
223 : virtual css::uno::Reference<css::drawing::framework::XConfigurationController> SAL_CALL
224 : getConfigurationController()
225 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
226 :
227 : virtual css::uno::Reference<css::drawing::framework::XModuleController> SAL_CALL
228 : getModuleController()
229 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
230 :
231 : // XUnoTunnel
232 :
233 : virtual sal_Int64 SAL_CALL getSomething (const com::sun::star::uno::Sequence<sal_Int8>& rId)
234 : throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
235 :
236 : protected:
237 : /** This method must return the name to index table. This table
238 : contains all property names and types of this object.
239 : */
240 : virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() SAL_OVERRIDE;
241 :
242 : static void FillPropertyTable (
243 : ::std::vector< ::com::sun::star::beans::Property>& rProperties);
244 :
245 : /**
246 : * The same as getFastProperyValue, but return the value through
247 : * rValue and nHandle is always valid.
248 : */
249 : virtual void SAL_CALL getFastPropertyValue(
250 : ::com::sun::star::uno::Any& rValue,
251 : sal_Int32 nHandle ) const SAL_OVERRIDE;
252 :
253 : /** Convert the value rValue and return the result in rConvertedValue and the
254 : old value in rOldValue.
255 : After this call the vetoable listeners are notified.
256 :
257 : @param rConvertedValue
258 : The converted value. Only set if return is true.
259 : @param rOldValue
260 : The old value. Only set if return is true.
261 : @param nHandle
262 : The handle of the proberty.
263 : @return
264 : <TRUE/> if the value is converted successfully.
265 : @throws IllegalArgumentException
266 : */
267 : virtual sal_Bool SAL_CALL convertFastPropertyValue(
268 : ::com::sun::star::uno::Any & rConvertedValue,
269 : ::com::sun::star::uno::Any & rOldValue,
270 : sal_Int32 nHandle,
271 : const ::com::sun::star::uno::Any& rValue )
272 : throw (::com::sun::star::lang::IllegalArgumentException) SAL_OVERRIDE;
273 :
274 : /** The same as setFastProperyValue, but no exception is thrown and nHandle
275 : is always valid. You must not broadcast the changes in this method.
276 : */
277 : virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
278 : sal_Int32 nHandle,
279 : const ::com::sun::star::uno::Any& rValue )
280 : throw (::com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
281 :
282 : /** When the called object has been disposed already this method throws
283 : a Disposed exception and does not return.
284 : */
285 : void ThrowIfDisposed() const
286 : throw (::com::sun::star::lang::DisposedException);
287 :
288 : using cppu::OPropertySetHelper::disposing;
289 : using cppu::OPropertySetHelper::getFastPropertyValue;
290 :
291 : private:
292 : const ::com::sun::star::uno::Type m_aSelectionTypeIdentifier;
293 :
294 : /** This pointer to the ViewShellBase can be NULL (after a call to
295 : ReleaseViewShellBase()).
296 : */
297 : ViewShellBase* mpBase;
298 :
299 : Rectangle maLastVisArea;
300 : ::tools::WeakReference<SdrPage> mpCurrentPage;
301 : bool mbMasterPageMode;
302 : bool mbLayerMode;
303 :
304 : /** This flag indicates whether the called DrawController is being
305 : disposed or already has been disposed.
306 : */
307 : bool mbDisposing;
308 :
309 : ::std::unique_ptr< ::cppu::IPropertyArrayHelper> mpPropertyArrayHelper;
310 :
311 : /** The current sub controller. May be NULL.
312 : */
313 : css::uno::Reference<css::drawing::XDrawSubController> mxSubController;
314 :
315 : css::uno::Reference<
316 : css::drawing::framework::XConfigurationController> mxConfigurationController;
317 : css::uno::Reference<
318 : css::drawing::framework::XModuleController> mxModuleController;
319 :
320 : /** Send an event to all relevant property listeners that a
321 : property has changed its value. The fire() method of the
322 : OPropertySetHelper is wrapped by this method to handle
323 : exceptions thrown by called listeners.
324 : */
325 : void FirePropertyChange (
326 : sal_Int32 nHandle,
327 : const ::com::sun::star::uno::Any& rNewValue,
328 : const ::com::sun::star::uno::Any& rOldValue);
329 :
330 : void ProvideFrameworkControllers();
331 : void DisposeFrameworkControllers();
332 : };
333 :
334 : } // end of namespace sd
335 :
336 : #endif
337 :
338 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|