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