xref: /trunk/main/sd/source/ui/inc/DrawController.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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();
182     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener );
183     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener );
184 
185     // XController
186     virtual ::sal_Bool SAL_CALL suspend( ::sal_Bool Suspend );
187 
188     // XServiceInfo
189     virtual ::rtl::OUString SAL_CALL getImplementationName();
190     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
191     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
192 
193     // XSelectionSupplier
194     virtual sal_Bool SAL_CALL select( const ::com::sun::star::uno::Any& aSelection );
195     virtual ::com::sun::star::uno::Any SAL_CALL getSelection(  );
196     virtual void SAL_CALL addSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener );
197     virtual void SAL_CALL removeSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener );
198 
199     // XPropertySet
200     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  );
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 );
204     virtual ::sal_Bool SAL_CALL isFormDesignMode(  );
205     virtual void SAL_CALL setFormDesignMode( ::sal_Bool DesignMode );
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 );
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 
216     virtual ::com::sun::star::uno::Reference<
217         ::com::sun::star::drawing::XDrawPage > SAL_CALL
218         getCurrentPage (void);
219 
220 
221     // lang::XEventListener
222     virtual void SAL_CALL
223         disposing (const ::com::sun::star::lang::EventObject& rEventObject);
224 
225 
226     // view::XSelectionChangeListener
227     virtual void  SAL_CALL
228         selectionChanged (const ::com::sun::star::lang::EventObject& rEvent);
229 
230 
231     // XControllerManager
232 
233     virtual css::uno::Reference<css::drawing::framework::XConfigurationController> SAL_CALL
234         getConfigurationController (void);
235 
236     virtual css::uno::Reference<css::drawing::framework::XModuleController> SAL_CALL
237         getModuleController (void);
238 
239 
240     // XUnoTunnel
241 
242     virtual sal_Int64 SAL_CALL getSomething (const com::sun::star::uno::Sequence<sal_Int8>& rId);
243 
244 protected:
245     /** This method must return the name to index table. This table
246         contains all property names and types of this object.
247      */
248     virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
249 
250     virtual void FillPropertyTable (
251         ::std::vector< ::com::sun::star::beans::Property>& rProperties);
252 
253     /**
254      * The same as getFastPropertyValue, but return the value through
255      * rValue and nHandle is always valid.
256      */
257     virtual void SAL_CALL getFastPropertyValue(
258         ::com::sun::star::uno::Any& rValue,
259         sal_Int32 nHandle ) const;
260 
261     /** Convert the value rValue and return the result in rConvertedValue and the
262         old value in rOldValue.
263         After this call the vetoable listeners are notified.
264 
265         @param rConvertedValue
266             The converted value. Only set if return is true.
267         @param rOldValue
268             The old value. Only set if return is true.
269         @param nHandle
270             The handle of the proberty.
271         @return
272             <TRUE/> if the value is converted successfully.
273         @throws IllegalArgumentException
274      */
275     virtual sal_Bool SAL_CALL convertFastPropertyValue(
276         ::com::sun::star::uno::Any & rConvertedValue,
277         ::com::sun::star::uno::Any & rOldValue,
278         sal_Int32 nHandle,
279         const ::com::sun::star::uno::Any& rValue );
280 
281     /** The same as setFastPropertyValue, but no exception is thrown and nHandle
282         is always valid. You must not broadcast the changes in this method.
283      */
284     virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
285         sal_Int32 nHandle,
286         const ::com::sun::star::uno::Any& rValue );
287 
288     /** When the called object has been disposed already this method throws
289         a Disposed exception and does not return.
290     */
291     void ThrowIfDisposed (void) const;
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