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