xref: /aoo42x/main/sd/source/ui/inc/DrawController.hxx (revision c45d927a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_DRAW_CONTROLLER_HXX
25 #define SD_DRAW_CONTROLLER_HXX
26 
27 #include "ViewShell.hxx"
28 
29 #include <osl/mutex.hxx>
30 #include <cppuhelper/propshlp.hxx>
31 #include <sfx2/sfxbasecontroller.hxx>
32 #include <com/sun/star/view/XSelectionSupplier.hpp>
33 #include <com/sun/star/view/XFormLayerAccess.hpp>
34 #include <com/sun/star/drawing/XDrawSubController.hpp>
35 #include <com/sun/star/drawing/XDrawView.hpp>
36 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
37 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
38 #include <com/sun/star/drawing/framework/ModuleController.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <comphelper/uno3.hxx>
42 #include <cppuhelper/implbase7.hxx>
43 #include <tools/weakbase.hxx>
44 #include <memory>
45 #include <vector>
46 #include <boost/scoped_ptr.hpp>
47 
48 class SfxViewShell;
49 class SdXImpressDocument;
50 
51 namespace css = ::com::sun::star;
52 
53 namespace sd {
54 
55 typedef ::cppu::ImplInheritanceHelper7 <
56     SfxBaseController,
57     ::com::sun::star::view::XSelectionSupplier,
58     ::com::sun::star::lang::XServiceInfo,
59     ::com::sun::star::drawing::XDrawView,
60     ::com::sun::star::view::XSelectionChangeListener,
61     ::com::sun::star::view::XFormLayerAccess,
62     ::com::sun::star::drawing::framework::XControllerManager,
63     ::com::sun::star::lang::XUnoTunnel
64     > DrawControllerInterfaceBase;
65 
66 class BroadcastHelperOwner
67 {
68 public:
69     BroadcastHelperOwner (::osl::Mutex& rMutex) : maBroadcastHelper(rMutex) {};
70     ::cppu::OBroadcastHelper maBroadcastHelper;
71 };
72 
73 class DrawSubController;
74 class ViewShellBase;
75 class ViewShell;
76 class View;
77 
78 
79 /** The DrawController is the UNO controller for Impress and Draw.  It
80     relies objects that implement the DrawSubController interface for view
81     specific behaviour.  The life time of the DrawController is roughly that
82     of ViewShellBase but note that the DrawController can (in the case of a
83     reload) outlive the ViewShellBase.
84 
85     The implementation of the XControllerManager interface is not yet in its
86     final form.
87 */
88 class DrawController
89     : public DrawControllerInterfaceBase,
90       private BroadcastHelperOwner,
91       public ::cppu::OPropertySetHelper
92 {
93 public:
94     enum PropertyHandle {
95         PROPERTY_WORKAREA = 0,
96         PROPERTY_SUB_CONTROLLER = 1,
97         PROPERTY_CURRENTPAGE = 2,
98         PROPERTY_MASTERPAGEMODE = 3,
99         PROPERTY_LAYERMODE = 4,
100         PROPERTY_ACTIVE_LAYER = 5,
101         PROPERTY_ZOOMTYPE = 6,
102         PROPERTY_ZOOMVALUE = 7,
103         PROPERTY_VIEWOFFSET = 8,
104 		PROPERTY_DRAWVIEWMODE = 9
105     };
106 
107     /** Create a new DrawController object for the given ViewShellBase.
108     */
109 	DrawController (ViewShellBase& rBase) throw();
110 
111 	virtual ~DrawController (void) throw();
112 
113     /** Replace the currently used sub controller with the given one.  This
114         new sub controller is used from now on for the view (that is the
115         main view shell to be precise) specific tasks.  Call this method
116         with a suitable sub controller whenever the view shell in the center
117         pane is exchanged.
118         @param pSubController
119             The ViewShell specific sub controller or NULL when (temporarily
120             while switching to another one) there is no ViewShell displayed
121             in the center pane.
122     */
123     void SetSubController (
124         const css::uno::Reference<css::drawing::XDrawSubController>& rxSubController);
125 
126     /** Call this method when the VisArea has changed.
127     */
128     void FireVisAreaChanged (const Rectangle& rVisArea) throw();
129 
130     /** Call this method when the selection has changed.
131     */
132 	void FireSelectionChangeListener (void) throw();
133 
134     /** Call this method when the edit mode has changed.
135     */
136     void FireChangeEditMode (bool bMasterPageMode) throw();
137 
138     /** Call this method when the layer mode has changed.
139     */
140 	void FireChangeLayerMode (bool bLayerMode) throw();
141 
142     /** Call this method when there is a new current page.
143     */
144 	void FireSwitchCurrentPage (SdPage* pCurrentPage) throw();
145 
146     /** Return a pointer to the ViewShellBase object that the DrawController
147         is connected to.
148         @return
149             The returned pointer is <NULL/> after a call to
150             ReleaseViewShellBase().
151     */
152     ViewShellBase* GetViewShellBase (void);
153 
154     /** This method is typically called from the destructor of ViewShellBase
155         to tell the DrawController that it and its members must not access
156         the ViewShellBase anymore.
157         After this call the DrawController is semi-disposed.
158     */
159     void ReleaseViewShellBase (void);
160 
161     static const ::com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId (void);
162 
163     DECLARE_XINTERFACE()
164 	DECLARE_XTYPEPROVIDER()
165 
166 	// XComponent
167 	virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException );
168     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
169     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
170 
171 	// XController
172     virtual ::sal_Bool SAL_CALL suspend( ::sal_Bool Suspend ) throw (::com::sun::star::uno::RuntimeException);
173 
174 	// XServiceInfo
175     virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
176     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
177     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
178 
179 	// XSelectionSupplier
180     virtual sal_Bool SAL_CALL select( const ::com::sun::star::uno::Any& aSelection ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
181     virtual ::com::sun::star::uno::Any SAL_CALL getSelection(  ) throw(::com::sun::star::uno::RuntimeException);
182     virtual void SAL_CALL addSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
183     virtual void SAL_CALL removeSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
184 
185 	// XPropertySet
186 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
187 
188     // XFormLayerAccess
189     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);
190     virtual ::sal_Bool SAL_CALL isFormDesignMode(  ) throw (::com::sun::star::uno::RuntimeException);
191     virtual void SAL_CALL setFormDesignMode( ::sal_Bool DesignMode ) throw (::com::sun::star::uno::RuntimeException);
192 
193     // XControlAccess
194     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);
195 
196 	// XDrawView
197     virtual void SAL_CALL
198         setCurrentPage (
199             const ::com::sun::star::uno::Reference<
200             ::com::sun::star::drawing::XDrawPage >& xPage)
201         throw(::com::sun::star::uno::RuntimeException);
202 
203     virtual ::com::sun::star::uno::Reference<
204         ::com::sun::star::drawing::XDrawPage > SAL_CALL
205         getCurrentPage (void)
206         throw(::com::sun::star::uno::RuntimeException);
207 
208 
209     // lang::XEventListener
210     virtual void SAL_CALL
211         disposing (const ::com::sun::star::lang::EventObject& rEventObject)
212         throw (::com::sun::star::uno::RuntimeException);
213 
214 
215     // view::XSelectionChangeListener
216     virtual void  SAL_CALL
217         selectionChanged (const ::com::sun::star::lang::EventObject& rEvent)
218         throw (::com::sun::star::uno::RuntimeException);
219 
220 
221     // XControllerManager
222 
223     virtual css::uno::Reference<css::drawing::framework::XConfigurationController> SAL_CALL
224         getConfigurationController (void)
225         throw (::com::sun::star::uno::RuntimeException);
226 
227     virtual css::uno::Reference<css::drawing::framework::XModuleController> SAL_CALL
228         getModuleController (void)
229         throw (::com::sun::star::uno::RuntimeException);
230 
231 
232     // XUnoTunnel
233 
234     virtual sal_Int64 SAL_CALL getSomething (const com::sun::star::uno::Sequence<sal_Int8>& rId)
235         throw (com::sun::star::uno::RuntimeException);
236 
237 protected:
238 	/** This method must return the name to index table. This table
239 	    contains all property names and types of this object.
240 	 */
241 	virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
242 
243     virtual void FillPropertyTable (
244         ::std::vector< ::com::sun::star::beans::Property>& rProperties);
245 
246 	/**
247 	 * The same as getFastProperyValue, but return the value through
248 	 * rValue and nHandle is always valid.
249 	 */
250 	virtual void SAL_CALL getFastPropertyValue(
251 		::com::sun::star::uno::Any& rValue,
252 		sal_Int32 nHandle ) const;
253 
254 	/** Convert the value rValue and return the result in rConvertedValue and the
255         old value in rOldValue.
256         After this call the vetoable listeners are notified.
257 
258         @param rConvertedValue
259             The converted value. Only set if return is true.
260         @param rOldValue
261             The old value. Only set if return is true.
262         @param nHandle
263             The handle of the proberty.
264         @return
265             <TRUE/> if the value is converted successfully.
266         @throws IllegalArgumentException
267 	 */
268 	virtual sal_Bool SAL_CALL convertFastPropertyValue(
269 		::com::sun::star::uno::Any & rConvertedValue,
270 		::com::sun::star::uno::Any & rOldValue,
271 		sal_Int32 nHandle,
272 		const ::com::sun::star::uno::Any& rValue )
273 		throw (::com::sun::star::lang::IllegalArgumentException);
274 
275 	/** The same as setFastProperyValue, but no exception is thrown and nHandle
276         is always valid. You must not broadcast the changes in this method.
277 	 */
278 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
279 		sal_Int32 nHandle,
280 		const ::com::sun::star::uno::Any& rValue )
281 		throw (::com::sun::star::uno::Exception);
282 
283     /** When the called object has been disposed already this method throws
284         a Disposed exception and does not return.
285     */
286     void ThrowIfDisposed (void) const
287         throw (::com::sun::star::lang::DisposedException);
288 
289 	using cppu::OPropertySetHelper::disposing;
290 	using cppu::OPropertySetHelper::getFastPropertyValue;
291 
292 private:
293     /** This pointer to the ViewShellBase can be NULL (after a call to
294         ReleaseViewShellBase()).
295     */
296     ViewShellBase* mpBase;
297 
298 	Rectangle maLastVisArea;
299     ::tools::WeakReference<SdrPage> mpCurrentPage;
300 	bool mbMasterPageMode;
301 	bool mbLayerMode;
302 
303     /** This flag indicates whether the called DrawController is being
304         disposed or already has been disposed.
305     */
306     bool mbDisposing;
307 
308     ::std::auto_ptr< ::cppu::IPropertyArrayHelper> mpPropertyArrayHelper;
309 
310     /** The current sub controller.  May be NULL.
311     */
312     css::uno::Reference<css::drawing::XDrawSubController> mxSubController;
313 
314     css::uno::Reference<
315         css::drawing::framework::XConfigurationController> mxConfigurationController;
316     css::uno::Reference<
317         css::drawing::framework::XModuleController> mxModuleController;
318 
319     /** Send an event to all relevant property listeners that a
320         property has changed its value.  The fire() method of the
321         OPropertySetHelper is wrapped by this method to handle
322         exceptions thrown by called listeners.
323     */
324     void FirePropertyChange (
325         sal_Int32 nHandle,
326         const ::com::sun::star::uno::Any& rNewValue,
327         const ::com::sun::star::uno::Any& rOldValue);
328 
329     void ProvideFrameworkControllers (void);
330     void DisposeFrameworkControllers (void);
331 };
332 
333 } // end of namespace sd
334 
335 #endif
336