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