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