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 _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_ 25 #define _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_ 26 27 #ifndef _CPPUHELPER_PROPSHLP_HXX 28 #include <cppuhelper/propshlp.hxx> 29 #endif 30 #ifndef _CPPUHELPER_IMPLBASE4_HXX_ 31 #include <cppuhelper/implbase4.hxx> 32 #endif 33 #ifndef DBA_CONTENTHELPER_HXX 34 #include "ContentHelper.hxx" 35 #endif 36 #ifndef COMPHELPER_PROPERTYSTATECONTAINER_HXX 37 #include <comphelper/propertystatecontainer.hxx> 38 #endif 39 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_ 40 #include <comphelper/proparrhlp.hxx> 41 #endif 42 #ifndef _DBASHARED_APITOOLS_HXX_ 43 #include "apitools.hxx" 44 #endif 45 #ifndef _COMPHELPER_UNO3_HXX_ 46 #include <comphelper/uno3.hxx> 47 #endif 48 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ 49 #include <com/sun/star/sdbc/XConnection.hpp> 50 #endif 51 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_ 52 #include <com/sun/star/frame/XComponentLoader.hpp> 53 #endif 54 #ifndef _COM_SUN_STAR_FRAME_XCONTROLLER_HPP_ 55 #include <com/sun/star/frame/XController.hpp> 56 #endif 57 #ifndef _COM_SUN_STAR_EMBED_XSTATECHANGELISTENER_HPP_ 58 #include <com/sun/star/embed/XStateChangeListener.hpp> 59 #endif 60 #include <com/sun/star/sdb/XSubDocument.hpp> 61 #include <com/sun/star/util/XCloseListener.hpp> 62 #include <com/sun/star/container/XHierarchicalName.hpp> 63 64 namespace comphelper 65 { 66 class NamedValueCollection; 67 } 68 69 //........................................................................ 70 namespace dbaccess 71 { 72 //........................................................................ 73 74 class OInterceptor; 75 class OEmbeddedClientHelper; 76 //========================================================================== 77 //= ODocumentDefinition - a database "document" which is simply a link to a real 78 //= document 79 //========================================================================== 80 81 typedef ::cppu::ImplHelper4 < ::com::sun::star::embed::XComponentSupplier 82 , ::com::sun::star::sdb::XSubDocument 83 , ::com::sun::star::util::XCloseListener 84 , ::com::sun::star::container::XHierarchicalName 85 > ODocumentDefinition_Base; 86 87 class ODocumentDefinition 88 :public OContentHelper 89 ,public ::comphelper::OPropertyStateContainer 90 ,public ::comphelper::OPropertyArrayUsageHelper< ODocumentDefinition > 91 ,public ODocumentDefinition_Base 92 { 93 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedObject> m_xEmbeddedObject; 94 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStateChangeListener > m_xListener; 95 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xLastKnownConnection; 96 97 OInterceptor* m_pInterceptor; 98 sal_Bool m_bForm; // <TRUE/> if it is a form 99 sal_Bool m_bOpenInDesign; 100 sal_Bool m_bInExecute; 101 sal_Bool m_bRemoveListener; 102 OEmbeddedClientHelper* m_pClientHelper; 103 104 protected: 105 virtual ~ODocumentDefinition(); 106 107 public: 108 109 ODocumentDefinition( 110 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContainer, 111 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&, 112 const TContentPtr& _pImpl, 113 sal_Bool _bForm 114 ); 115 116 void initialLoad( 117 const ::com::sun::star::uno::Sequence< sal_Int8 >& i_rClassID, 118 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rCreationArgs, 119 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& i_rConnection 120 ); 121 122 // com::sun::star::lang::XTypeProvider 123 DECLARE_TYPEPROVIDER( ); 124 125 // ::com::sun::star::uno::XInterface 126 DECLARE_XINTERFACE( ) 127 128 // ::com::sun::star::lang::XServiceInfo 129 DECLARE_SERVICE_INFO_STATIC(); 130 131 // ::com::sun::star::beans::XPropertySet 132 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 133 134 // OPropertySetHelper 135 virtual void SAL_CALL getFastPropertyValue( 136 ::com::sun::star::uno::Any& o_rValue, 137 sal_Int32 i_nHandle 138 ) const; 139 140 // XComponentSupplier 141 virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > SAL_CALL getComponent( ) throw (::com::sun::star::uno::RuntimeException); 142 143 // XSubDocument 144 virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL open( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 145 virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL openDesign( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 146 virtual void SAL_CALL store( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 147 virtual ::sal_Bool SAL_CALL close( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 148 149 // XHierarchicalName 150 virtual ::rtl::OUString SAL_CALL getHierarchicalName( ) throw (::com::sun::star::uno::RuntimeException); 151 virtual ::rtl::OUString SAL_CALL composeHierarchicalName( const ::rtl::OUString& aRelativeName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); 152 153 // OPropertySetHelper 154 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 155 156 // XCommandProcessor 157 virtual ::com::sun::star::uno::Any SAL_CALL execute( const ::com::sun::star::ucb::Command& aCommand, sal_Int32 CommandId, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& Environment ) throw (::com::sun::star::uno::Exception, ::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::RuntimeException) ; 158 159 // XRename 160 virtual void SAL_CALL rename( const ::rtl::OUString& newName ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); 161 162 // XCloseListener 163 virtual void SAL_CALL queryClosing( const ::com::sun::star::lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (::com::sun::star::util::CloseVetoException, ::com::sun::star::uno::RuntimeException); 164 virtual void SAL_CALL notifyClosing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 165 166 // XEventListener 167 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 168 169 /** returns the forms/reports container storage, depending on m_bForm. Our own storage 170 inside this container storage is the one with the name as indicated by m_pImpl->m_aProps.sPersistentName. 171 */ 172 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 173 getContainerStorage() const; 174 175 sal_Bool save(sal_Bool _bApprove); 176 sal_Bool saveAs(); 177 void closeObject(); 178 sal_Bool isModified(); isNewReport() const179 inline sal_Bool isNewReport() const { return !m_bForm && !m_pImpl->m_aProps.bAsTemplate; } 180 181 static void fillReportData( 182 const ::comphelper::ComponentContext& _rContext, 183 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable >& _rxComponent, 184 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxActiveConnection 185 ); 186 187 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& getConnection() const188 getConnection() const { return m_xLastKnownConnection; } 189 190 /** prepares closing the document component 191 192 The method suspends the controller associated with the document, and saves the document 193 if necessary. 194 195 @return 196 <TRUE/> if and only if the document component can be closed 197 */ 198 bool prepareClose(); 199 200 static ::com::sun::star::uno::Sequence< sal_Int8 > getDefaultDocumentTypeClassId(); 201 202 static ::rtl::OUString GetDocumentServiceFromMediaType( 203 const ::rtl::OUString& _rMediaType, 204 const ::comphelper::ComponentContext& _rContext, 205 ::com::sun::star::uno::Sequence< sal_Int8 >& _rClassId 206 ); 207 static ::rtl::OUString GetDocumentServiceFromMediaType( 208 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxContainerStorage, 209 const ::rtl::OUString& _rEntityName, 210 const ::comphelper::ComponentContext& _rContext, 211 ::com::sun::star::uno::Sequence< sal_Int8 >& _rClassId 212 ); 213 NotifierAccessdbaccess::ODocumentDefinition::NotifierAccess214 struct NotifierAccess { friend class NameChangeNotifier; private: NotifierAccess() { } }; getCurrentName() const215 const ::rtl::OUString& getCurrentName() const { return m_pImpl->m_aProps.aTitle; } 216 void firePropertyChange( 217 sal_Int32 i_nHandle, 218 const ::com::sun::star::uno::Any& i_rNewValue, 219 const ::com::sun::star::uno::Any& i_rOldValue, 220 sal_Bool i_bVetoable, 221 const NotifierAccess 222 ); 223 224 private: 225 /** does necessary initializations after our embedded object has been switched to ACTIVE 226 */ 227 void impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated ); 228 229 /** initializes a newly created view/controller of a form which is displaying our embedded object 230 231 Has only to be called if the respective embedded object has been loaded for design (and 232 not for data entry) 233 234 @param _rxController 235 the controller which belongs to the XModel of our (active) embedded object 236 */ 237 static void impl_initFormEditView( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController ); 238 239 /** removes the given frame from the desktop's frame collection 240 @raises ::com::sun::star::uno::RuntimeException 241 */ 242 static void impl_removeFrameFromDesktop_throw( 243 const ::comphelper::ComponentContext& _rContxt, 244 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame 245 ); 246 247 /** opens the UI for this sub document 248 */ 249 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > 250 impl_openUI_nolck_throw( bool _bForEditing ); 251 252 /** stores our document, if it's already loaded 253 */ 254 void impl_store_throw(); 255 256 /** closes our document, if it's open 257 */ 258 bool impl_close_throw(); 259 260 /** returns our component, creates it if necessary 261 */ 262 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > 263 impl_getComponent_throw( const bool i_ForceCreate = true ); 264 265 /** shows or hides our component 266 267 The embedded object must exist, and be in state LOADED, at least. 268 */ 269 void impl_showOrHideComponent_throw( const bool i_bShow ); 270 271 // OPropertyArrayUsageHelper 272 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 273 274 virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _rDefault ) const; 275 276 // helper 277 virtual void SAL_CALL disposing(); 278 279 // OContentHelper overridables 280 virtual ::rtl::OUString determineContentType() const; 281 282 /** fills the load arguments 283 */ 284 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > 285 fillLoadArgs( 286 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, 287 const bool _bSuppressMacros, 288 const bool _bReadOnly, 289 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rOpenCommandArguments, 290 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _out_rEmbeddedObjectDescriptor 291 ); 292 293 /** splits the given arguments to an "open*" command into arguments for loading the document, and arguments to be 294 put into the EmbeddedObjectDescriptor 295 296 Any values already present in <code>o_rDocumentLoadArgs</code> and <code>o_rEmbeddedObjectDescriptor</code> 297 will be overwritten by values from <code>i_rOpenCommandArguments</code>, if applicable, otherwise they will 298 be preserved. 299 300 @param i_rOpenCommandArguments 301 the arguments passed to the "open*" command at the content 302 @param o_rDocumentLoadArgs 303 the arguments to be passed when actually loading the embedded document. 304 @param o_rEmbeddedObjectDescriptor 305 the EmbeddedObjectDescriptor to be passed when initializing the embedded object 306 */ 307 void separateOpenCommandArguments( 308 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rOpenCommandArguments, 309 ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, 310 ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor 311 ); 312 313 /** loads the EmbeddedObject if not already loaded 314 @param _aClassID 315 If set, it will be used to create the embedded object. 316 */ 317 void loadEmbeddedObject( 318 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, 319 const ::com::sun::star::uno::Sequence< sal_Int8 >& _aClassID, 320 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs, 321 const bool _bSuppressMacros, 322 const bool _bReadOnly 323 ); 324 325 /** loads the embedded object, if not already loaded. No new object can be created with this method. 326 */ loadEmbeddedObject(bool _bSuppressMacros=false)327 void loadEmbeddedObject( bool _bSuppressMacros = false ) 328 { 329 loadEmbeddedObject( 330 NULL, 331 ::com::sun::star::uno::Sequence< sal_Int8 >(), 332 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(), 333 _bSuppressMacros, 334 false 335 ); 336 } 337 338 /** loads the embedded object for preview. Macros will be suppressed, and the document will 339 be read-only. 340 */ loadEmbeddedObjectForPreview()341 void loadEmbeddedObjectForPreview() 342 { 343 loadEmbeddedObject( 344 NULL, 345 ::com::sun::star::uno::Sequence< sal_Int8 >(), 346 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(), 347 true, 348 true 349 ); 350 } 351 352 /** searches for read-only flag in the args of the model and sets it to the given value, 353 if the value was not found, it will be appended. 354 @param _bReadOnly 355 If <TRUE/> the document will be switched to readonly mode 356 */ 357 void updateDocumentTitle(); 358 359 void registerProperties(); 360 361 /** determines whether the document we represent supports embedded scripts and macros 362 */ 363 sal_Bool objectSupportsEmbeddedScripts() const; 364 365 //------------------------------------------------------------------------- 366 //- commands 367 //------------------------------------------------------------------------- 368 369 void onCommandGetDocumentProperties( ::com::sun::star::uno::Any& _rProps ); 370 void onCommandInsert( const ::rtl::OUString& _sURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& Environment ) throw( ::com::sun::star::uno::Exception ); 371 void onCommandPreview( ::com::sun::star::uno::Any& _rImage ); 372 ::com::sun::star::uno::Any 373 onCommandOpenSomething( 374 const ::com::sun::star::uno::Any& _rArgument, 375 const bool _bActivate, 376 const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxEnvironment 377 ); 378 private: 379 using ::cppu::OPropertySetHelper::getFastPropertyValue; 380 }; 381 382 class NameChangeNotifier 383 { 384 public: 385 NameChangeNotifier( 386 ODocumentDefinition& i_rDocumentDefinition, 387 const ::rtl::OUString& i_rNewName, 388 ::osl::ResettableMutexGuard& i_rClearForNotify 389 ); 390 ~NameChangeNotifier(); 391 392 private: 393 ODocumentDefinition& m_rDocumentDefinition; 394 const ::com::sun::star::uno::Any m_aOldValue; 395 const ::com::sun::star::uno::Any m_aNewValue; 396 ::osl::ResettableMutexGuard& m_rClearForNotify; 397 398 void impl_fireEvent_throw( const sal_Bool i_bVetoable ); 399 }; 400 401 //........................................................................ 402 } // namespace dbaccess 403 //........................................................................ 404 405 #endif // _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_ 406 407