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 #ifndef _DBA_COREDATAACCESS_DATABASEDOCUMENT_HXX_ 24 #define _DBA_COREDATAACCESS_DATABASEDOCUMENT_HXX_ 25 26 #include "ModelImpl.hxx" 27 #include "documenteventnotifier.hxx" 28 29 /** === begin UNO includes === **/ 30 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> 31 #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp> 32 #include <com/sun/star/frame/XModel2.hpp> 33 #include <com/sun/star/frame/XTitle.hpp> 34 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp> 35 #include <com/sun/star/frame/XUntitledNumbers.hpp> 36 #include <com/sun/star/util/XModifiable.hpp> 37 #include <com/sun/star/frame/XStorable.hpp> 38 #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> 39 #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> 40 #include <com/sun/star/util/XCloseable.hpp> 41 #include <com/sun/star/view/XPrintable.hpp> 42 #include <com/sun/star/frame/XModuleManager.hpp> 43 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 44 #include <com/sun/star/lang/XServiceInfo.hpp> 45 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> 46 #include <com/sun/star/embed/XTransactionListener.hpp> 47 #include <com/sun/star/document/XStorageBasedDocument.hpp> 48 #include <com/sun/star/document/XEmbeddedScripts.hpp> 49 #include <com/sun/star/document/XEventsSupplier.hpp> 50 #include <com/sun/star/document/XScriptInvocationContext.hpp> 51 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp> 52 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp> 53 #include <com/sun/star/frame/XLoadable.hpp> 54 #include <com/sun/star/document/XEventBroadcaster.hpp> 55 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> 56 #include <com/sun/star/document/XDocumentRecovery.hpp> 57 /** === end UNO includes === **/ 58 59 #if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_17) 60 #define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_17 61 #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 17 62 #include <comphelper/implbase_var.hxx> 63 #endif 64 65 #include <cppuhelper/compbase10.hxx> 66 #include <cppuhelper/implbase3.hxx> 67 #include <rtl/ref.hxx> 68 69 #include <boost/shared_ptr.hpp> 70 #include <boost/noncopyable.hpp> 71 72 namespace comphelper { 73 class NamedValueCollection; 74 } 75 76 //........................................................................ 77 namespace dbaccess 78 { 79 //........................................................................ 80 81 class DocumentEvents; 82 class DocumentEventExecutor; 83 class DocumentGuard; 84 85 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > > Controllers; 86 87 //============================================================ 88 //= ViewMonitor 89 //============================================================ 90 /** helper class monitoring the views of a document, and firing appropriate events 91 when views are attached / detached 92 */ 93 class ViewMonitor : public boost::noncopyable 94 { 95 public: ViewMonitor(DocumentEventNotifier & _rEventNotifier)96 ViewMonitor( DocumentEventNotifier& _rEventNotifier ) 97 :m_rEventNotifier( _rEventNotifier ) 98 ,m_bIsNewDocument( true ) 99 ,m_bEverHadController( false ) 100 ,m_bLastIsFirstEverController( false ) 101 ,m_xLastConnectedController() 102 { 103 } 104 reset()105 void reset() 106 { 107 m_bEverHadController = false; 108 m_bLastIsFirstEverController = false; 109 m_xLastConnectedController.clear(); 110 } 111 112 /** to be called when a view (aka controller) has been connected to the document 113 @return 114 <TRUE/> if and only if this was the first-ever controller connected to the document 115 */ 116 bool onControllerConnected( 117 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController 118 ); 119 120 /** to be called when a controller is set as current controller 121 @return <TRUE/> 122 if and only if the controller connection indicates that loading the document is finished. This 123 is the case if the given controller has previously been connected, and it was the first controller 124 ever for which this happened. 125 */ 126 bool onSetCurrentController( 127 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController 128 ); 129 onLoadedDocument()130 void onLoadedDocument() { m_bIsNewDocument = false; } 131 132 private: 133 DocumentEventNotifier& m_rEventNotifier; 134 bool m_bIsNewDocument; 135 bool m_bEverHadController; 136 bool m_bLastIsFirstEverController; 137 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > 138 m_xLastConnectedController; 139 }; 140 141 //============================================================ 142 //= ODatabaseDocument 143 //============================================================ 144 typedef ::comphelper::WeakComponentImplHelper17 < ::com::sun::star::frame::XModel2 145 , ::com::sun::star::util::XModifiable 146 , ::com::sun::star::frame::XStorable 147 , ::com::sun::star::document::XEventBroadcaster 148 , ::com::sun::star::document::XDocumentEventBroadcaster 149 , ::com::sun::star::view::XPrintable 150 , ::com::sun::star::util::XCloseable 151 , ::com::sun::star::lang::XServiceInfo 152 , ::com::sun::star::sdb::XOfficeDatabaseDocument 153 , ::com::sun::star::ui::XUIConfigurationManagerSupplier 154 , ::com::sun::star::document::XStorageBasedDocument 155 , ::com::sun::star::document::XEmbeddedScripts 156 , ::com::sun::star::document::XScriptInvocationContext 157 , ::com::sun::star::script::provider::XScriptProviderSupplier 158 , ::com::sun::star::document::XEventsSupplier 159 , ::com::sun::star::frame::XLoadable 160 , ::com::sun::star::document::XDocumentRecovery 161 > ODatabaseDocument_OfficeDocument; 162 163 typedef ::cppu::ImplHelper3< ::com::sun::star::frame::XTitle 164 , ::com::sun::star::frame::XTitleChangeBroadcaster 165 , ::com::sun::star::frame::XUntitledNumbers 166 > ODatabaseDocument_Title; 167 168 class ODatabaseDocument :public ModelDependentComponent // ModelDependentComponent must be first! 169 ,public ODatabaseDocument_OfficeDocument 170 ,public ODatabaseDocument_Title 171 { 172 enum InitState 173 { 174 NotInitialized, 175 Initializing, 176 Initialized 177 }; 178 179 DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::frame::XUntitledNumbers >,TNumberedController); 180 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager> m_xUIConfigurationManager; 181 182 ::cppu::OInterfaceContainerHelper m_aModifyListeners; 183 ::cppu::OInterfaceContainerHelper m_aCloseListener; 184 ::cppu::OInterfaceContainerHelper m_aStorageListeners; 185 186 DocumentEvents* m_pEventContainer; 187 ::rtl::Reference< DocumentEventExecutor > m_pEventExecutor; 188 DocumentEventNotifier m_aEventNotifier; 189 190 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > m_xCurrentController; 191 Controllers m_aControllers; 192 ViewMonitor m_aViewMonitor; 193 194 ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xForms; 195 ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xReports; 196 ::com::sun::star::uno::WeakReference< ::com::sun::star::script::provider::XScriptProvider > m_xScriptProvider; 197 198 /** @short such module manager is used to classify new opened documents. */ 199 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > m_xModuleManager; 200 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitle > m_xTitleHelper; 201 TNumberedController m_aNumberedControllers; 202 203 /** true if and only if the DatabaseDocument's "initNew" or "load" have been called (or, well, 204 the document has be initialized implicitly - see storeAsURL 205 */ 206 InitState m_eInitState; 207 bool m_bClosing; 208 bool m_bAllowDocumentScripting; 209 bool m_bHasBeenRecovered; 210 211 enum StoreType { SAVE, SAVE_AS }; 212 /** stores the document to the given URL, rebases it to the respective new storage, if necessary, resets 213 the modified flag, and notifies any listeners as required 214 215 @param _rURL 216 the URL to store the document to 217 @param _rArguments 218 arguments for storing the document (MediaDescriptor) 219 @param _eType 220 the type of the store process (Save or SaveAs). The method will automatically 221 notify the proper events for this type. 222 @param _rGuard 223 the instance lock to be released before doing synchronous notifications 224 */ 225 void impl_storeAs_throw( 226 const ::rtl::OUString& _rURL, 227 const ::comphelper::NamedValueCollection& _rArguments, 228 const StoreType _eType, 229 DocumentGuard& _rGuard 230 ); 231 232 /** notifies our storage change listeners that our underlying storage changed 233 234 @param _rxNewRootStorage 235 the new root storage to be notified. If <NULL/>, it is assumed that no storage change actually 236 happened, and the listeners are not notified. 237 */ 238 void impl_notifyStorageChange_nolck_nothrow( 239 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage 240 ); 241 242 /// write a single XML stream into the package 243 void WriteThroughComponent( 244 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > & xComponent, /// the component we export 245 const sal_Char* pStreamName, /// the stream name 246 const sal_Char* pServiceName, /// service name of the component 247 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> & rArguments, /// the argument (XInitialization) 248 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> & rMediaDesc,/// output descriptor 249 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _xStorageToSaveTo 250 ) const; 251 252 253 /// write a single output stream 254 /// (to be called either directly or by WriteThroughComponent(...)) 255 void WriteThroughComponent( 256 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream, 257 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xComponent, 258 const sal_Char* pServiceName, 259 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rArguments, 260 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> & rMediaDesc 261 ) const; 262 263 /** writes the content and settings 264 @param sURL 265 The URL 266 @param lArguments 267 The media descriptor 268 @param _xStorageToSaveTo 269 The storage which should be used for saving 270 */ 271 void impl_writeStorage_throw( 272 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxTargetStorage, 273 const ::comphelper::NamedValueCollection& _rMediaDescriptor 274 ) const; 275 276 // ModelDependentComponent overridables 277 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() const; 278 279 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitle > impl_getTitleHelper_throw(); 280 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XUntitledNumbers > impl_getUntitledHelper_throw( 281 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xComponent = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >()); 282 283 private: 284 ODatabaseDocument(const ::rtl::Reference<ODatabaseModelImpl>& _pImpl); 285 // Do NOT create those documents directly, always use ODatabaseModelImpl::getModel. Reason is that 286 // ODatabaseDocument requires clear ownership, and in turn lifetime synchronisation with the ModelImpl. 287 // If you create a ODatabaseDocument directly, you might easily create a leak. 288 // #i50905# / 2005-06-20 / frank.schonheit@sun.com 289 290 protected: 291 virtual void SAL_CALL disposing(); 292 293 virtual ~ODatabaseDocument(); 294 295 public: FactoryAccessdbaccess::ODatabaseDocument::FactoryAccess296 struct FactoryAccess { friend class ODatabaseModelImpl; private: FactoryAccess() { } }; createDatabaseDocument(const::rtl::Reference<ODatabaseModelImpl> & _pImpl,FactoryAccess)297 static ODatabaseDocument* createDatabaseDocument( const ::rtl::Reference<ODatabaseModelImpl>& _pImpl, FactoryAccess /*accessControl*/ ) 298 { 299 return new ODatabaseDocument( _pImpl ); 300 } 301 302 // XServiceInfo 303 virtual ::rtl::OUString SAL_CALL getImplementationName( ); 304 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 305 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ); 306 307 // ::com::sun::star::lang::XServiceInfo - static methods 308 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void); 309 static ::rtl::OUString getImplementationName_static(void); 310 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 311 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&); 312 313 // XInterface 314 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType); 315 virtual void SAL_CALL acquire( ) throw (); 316 virtual void SAL_CALL release( ) throw (); 317 318 // XTypeProvider 319 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ); 320 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ); 321 322 // XEventListener 323 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ); 324 325 // XComponent 326 virtual void SAL_CALL dispose( ); 327 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ); 328 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ); 329 330 // XModel 331 virtual sal_Bool SAL_CALL attachResource( const ::rtl::OUString& URL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) ; 332 virtual ::rtl::OUString SAL_CALL getURL( ) ; 333 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getArgs( ) ; 334 virtual void SAL_CALL connectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& Controller ) ; 335 virtual void SAL_CALL disconnectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& Controller ) ; 336 virtual void SAL_CALL lockControllers( ) ; 337 virtual void SAL_CALL unlockControllers( ) ; 338 virtual sal_Bool SAL_CALL hasControllersLocked( ) ; 339 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL getCurrentController( ) ; 340 virtual void SAL_CALL setCurrentController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& Controller ) ; 341 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getCurrentSelection( ) ; 342 343 // XModel2 344 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL getControllers( ) ; 345 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableViewControllerNames( ) ; 346 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 > SAL_CALL createDefaultViewController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& Frame ) ; 347 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 > SAL_CALL createViewController( const ::rtl::OUString& ViewName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& Frame ) ; 348 349 // XStorable 350 virtual sal_Bool SAL_CALL hasLocation( ) ; 351 virtual ::rtl::OUString SAL_CALL getLocation( ) ; 352 virtual sal_Bool SAL_CALL isReadonly( ) ; 353 virtual void SAL_CALL store( ) ; 354 virtual void SAL_CALL storeAsURL( const ::rtl::OUString& sURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) ; 355 virtual void SAL_CALL storeToURL( const ::rtl::OUString& sURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) ; 356 357 // XModifyBroadcaster 358 virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ); 359 virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ); 360 361 // ::com::sun::star::util::XModifiable 362 virtual sal_Bool SAL_CALL isModified( ) ; 363 virtual void SAL_CALL setModified( sal_Bool bModified ) ; 364 365 // XEventBroadcaster 366 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& aListener ); 367 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& aListener ); 368 369 // XDocumentEventBroadcaster 370 virtual void SAL_CALL addDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ); 371 virtual void SAL_CALL removeDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ); 372 virtual void SAL_CALL notifyDocumentEvent( const ::rtl::OUString& _EventName, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _ViewController, const ::com::sun::star::uno::Any& _Supplement ); 373 374 // XPrintable 375 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPrinter( ) ; 376 virtual void SAL_CALL setPrinter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aPrinter ) ; 377 virtual void SAL_CALL print( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& xOptions ) ; 378 379 // XFormDocumentsSupplier 380 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getFormDocuments( ); 381 382 // XReportDocumentsSupplier 383 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getReportDocuments( ); 384 385 // XCloseable 386 virtual void SAL_CALL close( sal_Bool DeliverOwnership ); 387 virtual void SAL_CALL addCloseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ); 388 virtual void SAL_CALL removeCloseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ); 389 390 // XUIConfigurationManagerSupplier 391 virtual ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > SAL_CALL getUIConfigurationManager( ); 392 393 // XDocumentSubStorageSupplier 394 virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode ); 395 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getDocumentSubStoragesNames( ); 396 397 // XOfficeDatabaseDocument 398 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource > SAL_CALL getDataSource(); 399 400 // XStorageBasedDocument 401 virtual void SAL_CALL loadFromStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescriptor ); 402 virtual void SAL_CALL storeToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescriptor ); 403 virtual void SAL_CALL switchToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); 404 virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL getDocumentStorage( ); 405 virtual void SAL_CALL addStorageChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XStorageChangeListener >& xListener ); 406 virtual void SAL_CALL removeStorageChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XStorageChangeListener >& xListener ); 407 408 // XEmbeddedScripts 409 virtual ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > SAL_CALL getBasicLibraries(); 410 virtual ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > SAL_CALL getDialogLibraries(); 411 virtual ::sal_Bool SAL_CALL getAllowMacroExecution(); 412 413 // XScriptInvocationContext 414 virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > SAL_CALL getScriptContainer(); 415 416 // XScriptProviderSupplier 417 virtual ::com::sun::star::uno::Reference< ::com::sun::star::script::provider::XScriptProvider > SAL_CALL getScriptProvider( ); 418 419 // XEventsSupplier 420 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ); 421 422 // XLoadable 423 virtual void SAL_CALL initNew( ); 424 virtual void SAL_CALL load( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ); 425 426 // css.document.XDocumentRecovery 427 virtual ::sal_Bool SAL_CALL wasModifiedSinceLastSave(); 428 virtual void SAL_CALL storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ); 429 virtual void SAL_CALL recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ); 430 431 // XTitle 432 virtual ::rtl::OUString SAL_CALL getTitle( ); 433 virtual void SAL_CALL setTitle( const ::rtl::OUString& sTitle ); 434 435 // XTitleChangeBroadcaster 436 virtual void SAL_CALL addTitleChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitleChangeListener >& xListener ); 437 virtual void SAL_CALL removeTitleChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitleChangeListener >& xListener ); 438 439 // XUntitledNumbers 440 virtual ::sal_Int32 SAL_CALL leaseNumber( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xComponent ); 441 virtual void SAL_CALL releaseNumber( ::sal_Int32 nNumber ); 442 virtual void SAL_CALL releaseNumberForComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xComponent ); 443 virtual ::rtl::OUString SAL_CALL getUntitledPrefix( ); 444 445 /** clears the given object container 446 447 Clearing is done via disposal - the method calls XComponent::dispose at the given object, 448 which must be one of our impl's or our object containers (m_xForms, m_xReports, 449 m_xTableDefinitions, m_xCommandDefinitions) 450 451 @param _rxContainer 452 the container to clear 453 */ 454 static void clearObjectContainer( 455 ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess >& _rxContainer); 456 457 /** checks whether the component is already initialized, throws a NotInitializedException if not 458 */ checkInitialized() const459 inline void checkInitialized() const 460 { 461 if ( !impl_isInitialized() ) 462 throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); 463 } 464 465 /** checks the document is currently in the initialization phase, or already initialized. 466 Throws NotInitializedException if not so. 467 */ checkNotUninitilized() const468 inline void checkNotUninitilized() const 469 { 470 if ( impl_isInitialized() || impl_isInitializing() ) 471 // fine 472 return; 473 474 throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); 475 } 476 477 /** checks whether the document is currently being initialized, or already initialized, 478 throws a DoubleInitializationException if so 479 */ checkNotInitialized() const480 inline void checkNotInitialized() const 481 { 482 if ( impl_isInitializing() || impl_isInitialized() ) 483 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), getThis() ); 484 } 485 486 private: 487 /** returns whether the model is currently being initialized 488 */ impl_isInitializing() const489 bool impl_isInitializing() const { return m_eInitState == Initializing; } 490 491 /** returns whether the model is already initialized, i.e. the XModel's "initNew" or "load" methods have been called 492 */ impl_isInitialized() const493 bool impl_isInitialized() const { return m_eInitState == Initialized; } 494 495 /// tells the model it is being initialized now impl_setInitializing()496 void impl_setInitializing() { m_eInitState = Initializing; } 497 498 /// tells the model its initialization is done 499 void impl_setInitialized(); 500 501 /** closes the frames of all connected controllers 502 503 @param _bDeliverOwnership 504 determines if the ownership should be transferred to the component which 505 possibly vetos the closing 506 507 @raises ::com::sun::star::util::CloseVetoException 508 if the closing was vetoed by any instance 509 */ 510 void impl_closeControllerFrames_nolck_throw( sal_Bool _bDeliverOwnership ); 511 512 /** disposes the frames of all controllers which are still left in m_aControllers. 513 */ 514 void impl_disposeControllerFrames_nothrow(); 515 516 /** does a reparenting at the given object container to ourself 517 518 Calls XChild::setParent at the given object, which must be one of our impl's or our 519 object containers (m_xForms, m_xReports, m_xTableDefinitions, m_xCommandDefinitions) 520 */ 521 void impl_reparent_nothrow( const ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess >& _rxContainer ); 522 523 /** retrieves the forms or reports contained, creates and initializes it, if necessary 524 525 @raises DisposedException 526 if the instance is already disposed 527 @raises IllegalArgumentException 528 if <arg>_eType</arg> is not ODatabaseModelImpl::E_FORM and not ODatabaseModelImpl::E_REPORT 529 */ 530 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 531 impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType _eType ); 532 533 /** resets everything 534 535 @precond 536 m_pImpl is not <NULL/> 537 */ 538 void 539 impl_reset_nothrow(); 540 541 /** imports the document from the given resource. 542 */ 543 static void 544 impl_import_nolck_throw( 545 const ::comphelper::ComponentContext _rContext, 546 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxTargetComponent, 547 const ::comphelper::NamedValueCollection& _rResource 548 ); 549 550 /** creates a storage for the given URL, truncating it if a file with this name already exists 551 552 @throws Exception 553 if creating the storage failed 554 555 @return 556 the newly created storage for the file at the given URL 557 */ 558 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 559 impl_createStorageFor_throw( 560 const ::rtl::OUString& _rURL 561 ) const; 562 563 /** sets our "modified" flag 564 565 will notify all our respective listeners, if the "modified" state actually changed 566 567 @param _bModified 568 the (new) flag indicating whether the document is currently modified or not 569 @param _rGuard 570 the guard for our instance. At method entry, the guard must hold the lock. At the moment 571 of method leave, the lock will be released. 572 @precond 573 our mutex is locked 574 @postcond 575 our mutex is not locked 576 */ 577 void impl_setModified_nothrow( sal_Bool _bModified, DocumentGuard& _rGuard ); 578 579 /** stores the document to the given storage 580 581 Note that the document is actually not rebased to this storage, it just stores a copy of itself 582 to the given target storage. 583 584 @param _rxTargetStorage 585 denotes the storage to store the document into 586 @param _rMediaDescriptor 587 contains additional parameters for storing the document 588 @param _rDocGuard 589 a guard which holds the (only) lock to the document, and which will be temporarily 590 released where necessary (e.g. for notifications, or calling into other components) 591 592 @throws ::com::sun::star::uno::IllegalArgumentException 593 if the given storage is <NULL/>. 594 595 @throws ::com::sun::star::uno::RuntimeException 596 when any of the used operations throws it 597 598 @throws ::com::sun::star::io::IOException 599 when any of the used operations throws it, or any other exception occurs which is no 600 RuntimeException and no IOException 601 */ 602 void impl_storeToStorage_throw( 603 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxTargetStorage, 604 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, 605 DocumentGuard& _rDocGuard 606 ) const; 607 608 609 /** impl-version of attachResource 610 611 @param i_rLogicalDocumentURL 612 denotes the logical URL of the document, to be reported by getURL/getLocation 613 @param i_rMediaDescriptor 614 denotes additional document parameters 615 @param _rDocGuard 616 is the guard which currently protects the document instance 617 618 */ 619 sal_Bool impl_attachResource( 620 const ::rtl::OUString& i_rLogicalDocumentURL, 621 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rMediaDescriptor, 622 DocumentGuard& _rDocGuard 623 ); 624 625 /** throws an IOException with the message as defined in the RID_STR_ERROR_WHILE_SAVING resource, wrapping 626 the given caught non-IOException error 627 */ 628 void impl_throwIOExceptionCausedBySave_throw( 629 const ::com::sun::star::uno::Any& i_rError, 630 const ::rtl::OUString& i_rTargetURL 631 ) const; 632 }; 633 634 /** an extended version of the ModelMethodGuard, which also cares for the initialization state 635 of the document 636 */ 637 class DocumentGuard : private ModelMethodGuard 638 { 639 public: 640 enum MethodType 641 { 642 // a method which is to initialize the document 643 InitMethod, 644 // a default method 645 DefaultMethod, 646 // a method which is used (externally) during the initialization phase 647 MethodUsedDuringInit, 648 // a method which does not need initialization - use with care! 649 MethodWithoutInit 650 }; 651 652 /** constructs the guard 653 654 @param _document 655 the ODatabaseDocument instance 656 657 @throws ::com::sun::star::lang::DisposedException 658 If the given component is already disposed 659 660 @throws ::com::sun::star::frame::DoubleInitializationException 661 if _eType is InitMethod, and the given component is already initialized, or currently being initialized. 662 663 @throws ::com::sun::star::lang::NotInitializedException 664 if _eType is DefaultMethod, and the given component is not yet initialized; or if _eType 665 is MethodUsedDuringInit, and the component is still uninitialized, and not in the initialization 666 phase currently. 667 */ DocumentGuard(const ODatabaseDocument & _document,MethodType _eType=DefaultMethod)668 DocumentGuard( const ODatabaseDocument& _document, MethodType _eType = DefaultMethod ) 669 :ModelMethodGuard( _document ) 670 ,m_document( _document ) 671 { 672 switch ( _eType ) 673 { 674 case InitMethod: m_document.checkNotInitialized(); break; 675 case DefaultMethod: m_document.checkInitialized(); break; 676 case MethodUsedDuringInit: m_document.checkNotUninitilized(); break; 677 case MethodWithoutInit: break; 678 } 679 } 680 ~DocumentGuard()681 ~DocumentGuard() 682 { 683 } 684 clear()685 void clear() 686 { 687 ModelMethodGuard::clear(); 688 } reset()689 void reset() 690 { 691 ModelMethodGuard::reset(); 692 m_document.checkDisposed(); 693 } 694 695 private: 696 697 const ODatabaseDocument& m_document; 698 }; 699 700 //........................................................................ 701 } // namespace dbaccess 702 //........................................................................ 703 #endif // _DBA_COREDATAACCESS_DATABASEDOCUMENT_HXX_ 704