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