Update ooo320-m1
[ooovba.git] / dbaccess / source / core / dataaccess / databasedocument.cxx
blob3deda0791c273f4cf9d989cab00e17187f55ac4b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: databasedocument.cxx,v $
10 * $Revision: 1.40.6.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "core_resource.hxx"
35 #include "core_resource.hrc"
36 #include "datasource.hxx"
37 #include "databasedocument.hxx"
38 #include "dbastrings.hrc"
39 #include "module_dba.hxx"
40 #include "documenteventexecutor.hxx"
41 #include "databasecontext.hxx"
42 #include "documentcontainer.hxx"
44 #include <comphelper/documentconstants.hxx>
45 #include <comphelper/namedvaluecollection.hxx>
46 #include <comphelper/enumhelper.hxx>
47 #include <comphelper/numberedcollection.hxx>
48 #include <comphelper/genericpropertyset.hxx>
49 #include <comphelper/property.hxx>
50 #include <svtools/saveopt.hxx>
52 #include <framework/titlehelper.hxx>
54 /** === begin UNO includes === **/
55 #include <com/sun/star/document/XExporter.hpp>
56 #include <com/sun/star/document/XFilter.hpp>
57 #include <com/sun/star/document/XImporter.hpp>
58 #include <com/sun/star/embed/EntryInitModes.hpp>
59 #include <com/sun/star/embed/XEmbedPersist.hpp>
60 #include <com/sun/star/embed/XTransactedObject.hpp>
61 #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
62 #include <com/sun/star/io/XActiveDataSource.hpp>
63 #include <com/sun/star/io/XSeekable.hpp>
64 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
65 #include <com/sun/star/task/ErrorCodeIOException.hpp>
66 #include <com/sun/star/task/XStatusIndicator.hpp>
67 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
68 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
69 #include <com/sun/star/view/XSelectionSupplier.hpp>
70 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
71 /** === end UNO includes === **/
73 #include <comphelper/documentconstants.hxx>
74 #include <comphelper/interaction.hxx>
75 #include <comphelper/enumhelper.hxx>
76 #include <comphelper/mediadescriptor.hxx>
77 #include <comphelper/namedvaluecollection.hxx>
78 #include <comphelper/numberedcollection.hxx>
79 #include <comphelper/storagehelper.hxx>
80 #include <cppuhelper/exc_hlp.hxx>
81 #include <framework/titlehelper.hxx>
82 #include <tools/debug.hxx>
83 #include <tools/diagnose_ex.h>
84 #include <tools/errcode.hxx>
85 #include <tools/urlobj.hxx>
87 #include <boost/bind.hpp>
89 #include <algorithm>
90 #include <functional>
91 #include <list>
93 #define MAP_LEN(x) x, sizeof(x) - 1
95 #define MAP_LEN(x) x, sizeof(x) - 1
97 using namespace ::com::sun::star::uno;
98 using namespace ::com::sun::star::beans;
99 using namespace ::com::sun::star::frame;
100 using namespace ::com::sun::star::lang;
101 using namespace ::com::sun::star::container;
102 using namespace ::com::sun::star::document;
103 using namespace ::com::sun::star::io;
104 using namespace ::com::sun::star::util;
105 using namespace ::com::sun::star::embed;
106 using namespace ::com::sun::star::task;
107 using namespace ::com::sun::star::view;
108 using namespace ::com::sun::star::sdbc;
109 using namespace ::com::sun::star;
110 using namespace ::com::sun::star::xml::sax;
111 using namespace ::com::sun::star::script;
112 using namespace ::com::sun::star::script::provider;
113 using namespace ::com::sun::star::ui;
114 using namespace ::cppu;
115 using namespace ::osl;
117 using ::com::sun::star::awt::XWindow;
119 //........................................................................
120 namespace dbaccess
122 //........................................................................
124 //============================================================
125 //= ViewMonitor
126 //============================================================
127 //--------------------------------------------------------------------------
128 bool ViewMonitor::onControllerConnected( const Reference< XController >& _rxController )
130 bool bFirstControllerEver = ( m_bEverHadController == false );
131 m_bEverHadController = true;
133 m_xLastConnectedController = _rxController;
134 m_bLastIsFirstEverController = bFirstControllerEver;
136 return bFirstControllerEver;
139 //--------------------------------------------------------------------------
140 void ViewMonitor::onSetCurrentController( const Reference< XController >& _rxController )
142 // we interpret this as "loading the document (including UI) is finished",
143 // if and only if this is the controller which was last connected, and it was the
144 // first controller ever connected
145 bool bLoadFinished = ( _rxController == m_xLastConnectedController ) && m_bLastIsFirstEverController;
147 // notify the respective events
148 if ( bLoadFinished )
149 m_rEventNotifier.notifyDocumentEventAsync( m_bIsNewDocument ? "OnNew" : "OnLoad" );
152 //============================================================
153 //= ODatabaseDocument
154 //============================================================
155 DBG_NAME(ODatabaseDocument)
156 //--------------------------------------------------------------------------
157 extern "C" void SAL_CALL createRegistryInfo_ODatabaseDocument()
159 static ::dba::OAutoRegistration< ODatabaseDocument > aAutoRegistration;
162 //--------------------------------------------------------------------------
163 ODatabaseDocument::ODatabaseDocument(const ::rtl::Reference<ODatabaseModelImpl>& _pImpl )
164 :ModelDependentComponent( _pImpl )
165 ,ODatabaseDocument_OfficeDocument( getMutex() )
166 ,m_aModifyListeners( getMutex() )
167 ,m_aCloseListener( getMutex() )
168 ,m_aStorageListeners( getMutex() )
169 ,m_pEventContainer( new DocumentEvents( *this, getMutex(), _pImpl->getDocumentEvents() ) )
170 ,m_pEventExecutor( NULL ) // initialized below, ref-count-protected
171 ,m_aEventNotifier( *this, getMutex() )
172 ,m_aViewMonitor( m_aEventNotifier )
173 ,m_eInitState( NotInitialized )
174 ,m_bClosing( false )
175 ,m_bAllowDocumentScripting( false )
177 DBG_CTOR(ODatabaseDocument,NULL);
179 osl_incrementInterlockedCount( &m_refCount );
181 impl_reparent_nothrow( m_xForms );
182 impl_reparent_nothrow( m_xReports );
183 impl_reparent_nothrow( m_pImpl->m_xTableDefinitions );
184 impl_reparent_nothrow( m_pImpl->m_xCommandDefinitions );
186 m_pEventExecutor = new DocumentEventExecutor( m_pImpl->m_aContext, this );
188 osl_decrementInterlockedCount( &m_refCount );
190 // if there previously was a document instance for the same Impl which was already initialized,
191 // then consider ourself initialized, too.
192 // #i94840#
193 if ( m_pImpl->hadInitializedDocument() )
195 impl_setInitialized();
196 m_bAllowDocumentScripting = ( m_pImpl->determineEmbeddedMacros() != ODatabaseModelImpl::eSubDocumentMacros );
200 //--------------------------------------------------------------------------
201 ODatabaseDocument::~ODatabaseDocument()
203 DBG_DTOR(ODatabaseDocument,NULL);
204 if ( !ODatabaseDocument_OfficeDocument::rBHelper.bInDispose && !ODatabaseDocument_OfficeDocument::rBHelper.bDisposed )
206 acquire();
207 dispose();
210 delete m_pEventContainer, m_pEventContainer = NULL;
212 // -----------------------------------------------------------------------------
213 Any SAL_CALL ODatabaseDocument::queryInterface( const Type& _rType ) throw (RuntimeException)
215 // strip XEmbeddedScripts and XScriptInvocationContext if we have any form/report
216 // which already contains macros. In this case, the database document itself is not
217 // allowed to contain macros, too.
218 if ( !m_bAllowDocumentScripting
219 && ( _rType.equals( XEmbeddedScripts::static_type() )
220 || _rType.equals( XScriptInvocationContext::static_type() )
223 return Any();
225 Any aReturn = ODatabaseDocument_OfficeDocument::queryInterface(_rType);
226 if (!aReturn.hasValue())
227 aReturn = ODatabaseDocument_Title::queryInterface(_rType);
228 return aReturn;
230 //------------------------------------------------------------------------------
231 void SAL_CALL ODatabaseDocument::acquire( ) throw ()
233 ODatabaseDocument_OfficeDocument::acquire();
236 //------------------------------------------------------------------------------
237 void SAL_CALL ODatabaseDocument::release( ) throw ()
239 ODatabaseDocument_OfficeDocument::release();
241 //------------------------------------------------------------------------------
242 Sequence< Type > SAL_CALL ODatabaseDocument::getTypes( ) throw (RuntimeException)
244 Sequence< Type > aTypes = ::comphelper::concatSequences(
245 ODatabaseDocument_OfficeDocument::getTypes(),
246 ODatabaseDocument_Title::getTypes()
249 // strip XEmbeddedScripts and XScriptInvocationContext if we have any form/report
250 // which already contains macros. In this case, the database document itself is not
251 // allowed to contain macros, too.
252 if ( !m_bAllowDocumentScripting )
254 Sequence< Type > aStrippedTypes( aTypes.getLength() );
255 Type* pStripTo( aStrippedTypes.getArray() );
257 // strip XEmbeddedScripts, and immediately re-assign to aTypes
258 aTypes = Sequence< Type >(
259 pStripTo,
260 ::std::remove_copy_if(
261 aTypes.getConstArray(),
262 aTypes.getConstArray() + aTypes.getLength(),
263 pStripTo,
264 ::std::bind2nd( ::std::equal_to< Type >(), XEmbeddedScripts::static_type() )
265 ) - pStripTo
268 // strip XScriptInvocationContext, and immediately re-assign to aTypes
269 aTypes = Sequence< Type >(
270 pStripTo,
271 ::std::remove_copy_if(
272 aTypes.getConstArray(),
273 aTypes.getConstArray() + aTypes.getLength(),
274 pStripTo,
275 ::std::bind2nd( ::std::equal_to< Type >(), XScriptInvocationContext::static_type() )
276 ) - pStripTo
280 return aTypes;
282 //------------------------------------------------------------------------------
283 Sequence< sal_Int8 > SAL_CALL ODatabaseDocument::getImplementationId( ) throw (RuntimeException)
285 static ::cppu::OImplementationId * pId = 0;
286 if (! pId)
288 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
289 if (! pId)
291 static ::cppu::OImplementationId aId;
292 pId = &aId;
295 return pId->getImplementationId();
298 // -----------------------------------------------------------------------------
299 // local functions
300 // -----------------------------------------------------------------------------
301 namespace
303 // -----------------------------------------------------------------------------
304 Reference< XStatusIndicator > lcl_extractStatusIndicator( const ::comphelper::NamedValueCollection& _rArguments )
306 Reference< XStatusIndicator > xStatusIndicator;
307 return _rArguments.getOrDefault( "StatusIndicator", xStatusIndicator );
310 // -----------------------------------------------------------------------------
311 static void lcl_triggerStatusIndicator_throw( const ::comphelper::NamedValueCollection& _rArguments, DocumentGuard& _rGuard, const bool _bStart )
313 Reference< XStatusIndicator > xStatusIndicator( lcl_extractStatusIndicator( _rArguments ) );
314 if ( !xStatusIndicator.is() )
315 return;
317 _rGuard.clear();
320 if ( _bStart )
321 xStatusIndicator->start( ::rtl::OUString(), (sal_Int32)1000000 );
322 else
323 xStatusIndicator->end();
325 catch( const Exception& )
327 DBG_UNHANDLED_EXCEPTION();
329 _rGuard.reset();
330 // note that |reset| can throw a DisposedException
333 // -----------------------------------------------------------------------------
334 static void lcl_extractStatusIndicator( const ::comphelper::NamedValueCollection& _rArguments, Sequence< Any >& _rCallArgs )
336 Reference< XStatusIndicator > xStatusIndicator( lcl_extractStatusIndicator( _rArguments ) );
337 if ( !xStatusIndicator.is() )
338 return;
340 sal_Int32 nLength = _rCallArgs.getLength();
341 _rCallArgs.realloc( nLength + 1 );
342 _rCallArgs[ nLength ] <<= xStatusIndicator;
345 // -----------------------------------------------------------------------------
346 static void lcl_extractAndStartStatusIndicator( const ::comphelper::NamedValueCollection& _rArguments, Reference< XStatusIndicator >& _rxStatusIndicator,
347 Sequence< Any >& _rCallArgs )
349 _rxStatusIndicator = lcl_extractStatusIndicator( _rArguments );
350 if ( !_rxStatusIndicator.is() )
351 return;
355 _rxStatusIndicator->start( ::rtl::OUString(), (sal_Int32)1000000 );
357 sal_Int32 nLength = _rCallArgs.getLength();
358 _rCallArgs.realloc( nLength + 1 );
359 _rCallArgs[ nLength ] <<= _rxStatusIndicator;
361 catch( const Exception& )
363 DBG_UNHANDLED_EXCEPTION();
367 // -----------------------------------------------------------------------------
368 static Sequence< PropertyValue > lcl_appendFileNameToDescriptor( const Sequence< PropertyValue >& _rDescriptor, const ::rtl::OUString _rURL )
370 ::comphelper::NamedValueCollection aMediaDescriptor( _rDescriptor );
371 if ( _rURL.getLength() )
373 aMediaDescriptor.put( "FileName", _rURL );
374 aMediaDescriptor.put( "URL", _rURL );
376 return aMediaDescriptor.getPropertyValues();
380 // -----------------------------------------------------------------------------
381 void ODatabaseDocument::impl_setInitialized()
383 m_eInitState = Initialized;
385 // start event notifications
386 m_aEventNotifier.onDocumentInitialized();
389 // -----------------------------------------------------------------------------
390 void ODatabaseDocument::impl_reset_nothrow()
394 m_pImpl->clearConnections();
395 m_pImpl->disposeStorages();
396 m_pImpl->resetRootStroage();
398 clearObjectContainer( m_xForms );
399 clearObjectContainer( m_xReports );
400 clearObjectContainer( m_pImpl->m_xTableDefinitions );
401 clearObjectContainer( m_pImpl->m_xCommandDefinitions );
403 m_eInitState = NotInitialized;
405 m_pImpl->reset();
407 catch(const Exception&)
409 DBG_UNHANDLED_EXCEPTION();
411 m_pImpl->m_bDocumentReadOnly = sal_False;
414 // -----------------------------------------------------------------------------
415 void ODatabaseDocument::impl_import_nolck_throw( const ::comphelper::ComponentContext _rContext, const Reference< XInterface >& _rxTargetComponent,
416 const ::comphelper::NamedValueCollection& _rResource )
418 Sequence< Any > aFilterArgs;
419 Reference< XStatusIndicator > xStatusIndicator;
420 lcl_extractAndStartStatusIndicator( _rResource, xStatusIndicator, aFilterArgs );
422 /** property map for import info set */
423 comphelper::PropertyMapEntry aExportInfoMap[] =
425 { MAP_LEN( "BaseURI"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
426 { MAP_LEN( "StreamName"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
427 { NULL, 0, 0, NULL, 0, 0 }
429 uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
430 xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rResource.getOrDefault("URL",::rtl::OUString())));
431 xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml"))));
433 const sal_Int32 nCount = aFilterArgs.getLength();
434 aFilterArgs.realloc(nCount + 1);
435 aFilterArgs[nCount] <<= xInfoSet;
437 Reference< XImporter > xImporter(
438 _rContext.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterArgs ),
439 UNO_QUERY_THROW );
441 Reference< XComponent > xComponent( _rxTargetComponent, UNO_QUERY_THROW );
442 xImporter->setTargetDocument( xComponent );
444 Reference< XFilter > xFilter( xImporter, UNO_QUERY_THROW );
445 xFilter->filter( ODatabaseModelImpl::stripLoadArguments( _rResource ) );
447 if ( xStatusIndicator.is() )
448 xStatusIndicator->end();
451 // -----------------------------------------------------------------------------
452 void SAL_CALL ODatabaseDocument::initNew( ) throw (DoubleInitializationException, IOException, Exception, RuntimeException)
454 // SYNCHRONIZED ->
455 DocumentGuard aGuard( *this, DocumentGuard::InitMethod );
457 impl_reset_nothrow();
459 impl_setInitializing();
461 // create a temporary storage
462 Reference< XStorage > xTempStor( ::comphelper::OStorageHelper::GetTemporaryStorage(
463 m_pImpl->m_aContext.getLegacyServiceFactory() ) );
465 // store therein
466 impl_storeToStorage_throw( xTempStor, Sequence< PropertyValue >(), aGuard );
468 // let the impl know we're now based on this storage
469 m_pImpl->switchToStorage( xTempStor );
471 // for the newly created document, allow document-wide scripting
472 m_bAllowDocumentScripting = true;
474 impl_setInitialized();
476 m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" );
478 impl_setModified_nothrow( sal_False, aGuard );
479 // <- SYNCHRONIZED
481 m_aEventNotifier.notifyDocumentEvent( "OnCreate" );
483 impl_notifyStorageChange_nolck_nothrow( xTempStor );
486 // -----------------------------------------------------------------------------
487 void SAL_CALL ODatabaseDocument::load( const Sequence< PropertyValue >& _Arguments ) throw (DoubleInitializationException, IOException, Exception, RuntimeException)
489 // SYNCHRONIZED ->
490 DocumentGuard aGuard( *this, DocumentGuard::InitMethod );
492 impl_reset_nothrow();
494 ::comphelper::NamedValueCollection aResource( _Arguments );
495 if ( aResource.has( "FileName" ) && !aResource.has( "URL" ) )
496 // FileName is the compatibility name for URL, so we might have clients passing
497 // a FileName only. However, some of our code works with the URL only, so ensure
498 // we have one.
499 aResource.put( "URL", aResource.get( "FileName" ) );
500 if ( aResource.has( "URL" ) && !aResource.has( "FileName" ) )
501 // similar ... just in case there is legacy code which expects a FileName only
502 aResource.put( "FileName", aResource.get( "URL" ) );
504 // now that somebody (perhaps) told us an macro execution mode, remember it as
505 // ImposedMacroExecMode
506 m_pImpl->setImposedMacroExecMode(
507 aResource.getOrDefault( "MacroExecutionMode", m_pImpl->getImposedMacroExecMode() ) );
509 impl_setInitializing();
512 aGuard.clear();
513 impl_import_nolck_throw( m_pImpl->m_aContext, *this, aResource );
514 aGuard.reset();
516 catch( const Exception& )
518 impl_reset_nothrow();
519 throw;
521 // tell our view monitor that the document has been loaded - this way it will fire the proper
522 // event (OnLoad instead of OnCreate) later on
523 m_aViewMonitor.onLoadedDocument();
525 // note that we do *not* call impl_setInitialized() here: The initialization is only complete
526 // when the XModel::attachResource has been called, not sooner.
528 impl_setModified_nothrow( sal_False, aGuard );
529 // <- SYNCHRONIZED
532 // -----------------------------------------------------------------------------
533 // XModel
534 sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException)
536 DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
538 if ( ( _rURL == getURL() )
539 && ( _rArguments.getLength() == 1 )
540 && ( _rArguments[0].Name.compareToAscii( "BreakMacroSignature" ) == 0 )
543 // this is a BAD hack of the Basic importer code ... there should be a dedicated API for this,
544 // not this bad mis-using of existing interfaces
545 return sal_False;
546 // (we do not support macro signatures, so we can ignore this call)
549 m_pImpl->attachResource( _rURL, _rArguments );
551 if ( impl_isInitializing() )
552 { // this means we've just been loaded, and this is the attachResource call which follows
553 // the load call.
554 impl_setInitialized();
556 // determine whether the document as a whole, or sub documents, have macros. Especially the latter
557 // controls the availability of our XEmbeddedScripts and XScriptInvocationContext interfaces, and we
558 // should know this before anybody actually uses the object.
559 m_bAllowDocumentScripting = ( m_pImpl->determineEmbeddedMacros() != ODatabaseModelImpl::eSubDocumentMacros );
561 m_aEventNotifier.notifyDocumentEvent( "OnLoadFinished" );
564 return sal_True;
567 // -----------------------------------------------------------------------------
568 ::rtl::OUString SAL_CALL ODatabaseDocument::getURL( ) throw (RuntimeException)
570 DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
571 return m_pImpl->getURL();
574 // -----------------------------------------------------------------------------
575 Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs( ) throw (RuntimeException)
577 DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
578 return m_pImpl->getResource();
581 // -----------------------------------------------------------------------------
582 void SAL_CALL ODatabaseDocument::connectController( const Reference< XController >& _xController ) throw (RuntimeException)
584 DocumentGuard aGuard( *this );
586 m_aControllers.push_back( _xController );
588 m_aEventNotifier.notifyDocumentEventAsync( "OnViewCreated", Reference< XController2 >( _xController, UNO_QUERY ) );
590 bool bFirstControllerEver = m_aViewMonitor.onControllerConnected( _xController );
591 if ( !bFirstControllerEver )
592 return;
594 // check/adjust our macro mode.
595 m_pImpl->checkMacrosOnLoading();
598 // -----------------------------------------------------------------------------
599 void SAL_CALL ODatabaseDocument::disconnectController( const Reference< XController >& _xController ) throw (RuntimeException)
601 bool bNotifyViewClosed = false;
602 bool bLastControllerGone = false;
603 bool bIsClosing = false;
605 // SYNCHRONIZED ->
607 DocumentGuard aGuard( *this );
609 Controllers::iterator pos = ::std::find( m_aControllers.begin(), m_aControllers.end(), _xController );
610 OSL_ENSURE( pos != m_aControllers.end(), "ODatabaseDocument::disconnectController: don't know this controller!" );
611 if ( pos != m_aControllers.end() )
613 m_aControllers.erase( pos );
614 bNotifyViewClosed = true;
617 if ( m_xCurrentController == _xController )
618 m_xCurrentController = NULL;
620 bLastControllerGone = m_aControllers.empty();
621 bIsClosing = m_bClosing;
623 // <- SYNCHRONIZED
625 if ( bNotifyViewClosed )
626 m_aEventNotifier.notifyDocumentEvent( "OnViewClosed", Reference< XController2 >( _xController, UNO_QUERY ) );
628 if ( bLastControllerGone && !bIsClosing )
630 // if this was the last view, close the document as a whole
631 // #i51157# / 2006-03-16 / frank.schoenheit@sun.com
634 close( sal_True );
636 catch( const CloseVetoException& )
638 // okay, somebody vetoed and took ownership
643 // -----------------------------------------------------------------------------
644 void SAL_CALL ODatabaseDocument::lockControllers( ) throw (RuntimeException)
646 DocumentGuard aGuard( *this );
648 ++m_pImpl->m_nControllerLockCount;
651 // -----------------------------------------------------------------------------
652 void SAL_CALL ODatabaseDocument::unlockControllers( ) throw (RuntimeException)
654 DocumentGuard aGuard( *this );
656 --m_pImpl->m_nControllerLockCount;
659 // -----------------------------------------------------------------------------
660 sal_Bool SAL_CALL ODatabaseDocument::hasControllersLocked( ) throw (RuntimeException)
662 DocumentGuard aGuard( *this );
664 return m_pImpl->m_nControllerLockCount != 0;
667 // -----------------------------------------------------------------------------
668 Reference< XController > SAL_CALL ODatabaseDocument::getCurrentController() throw (RuntimeException)
670 DocumentGuard aGuard( *this );
672 return m_xCurrentController.is() ? m_xCurrentController : ( m_aControllers.empty() ? Reference< XController >() : *m_aControllers.begin() );
675 // -----------------------------------------------------------------------------
676 void SAL_CALL ODatabaseDocument::setCurrentController( const Reference< XController >& _xController ) throw (NoSuchElementException, RuntimeException)
678 DocumentGuard aGuard( *this );
680 m_xCurrentController = _xController;
682 m_aViewMonitor.onSetCurrentController( _xController );
684 // -----------------------------------------------------------------------------
685 Reference< XInterface > SAL_CALL ODatabaseDocument::getCurrentSelection( ) throw (RuntimeException)
687 DocumentGuard aGuard( *this );
689 Reference< XInterface > xRet;
690 Reference< XSelectionSupplier > xDocView( getCurrentController(), UNO_QUERY );
691 if ( xDocView.is() )
692 xRet.set(xDocView->getSelection(),UNO_QUERY);
694 return xRet;
696 // -----------------------------------------------------------------------------
698 // XStorable
699 sal_Bool SAL_CALL ODatabaseDocument::hasLocation( ) throw (RuntimeException)
701 return getLocation().getLength() > 0;
703 // -----------------------------------------------------------------------------
704 ::rtl::OUString SAL_CALL ODatabaseDocument::getLocation( ) throw (RuntimeException)
706 DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
707 return m_pImpl->getURL();
709 // -----------------------------------------------------------------------------
710 sal_Bool SAL_CALL ODatabaseDocument::isReadonly( ) throw (RuntimeException)
712 DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
713 return m_pImpl->m_bDocumentReadOnly;
715 // -----------------------------------------------------------------------------
716 void SAL_CALL ODatabaseDocument::store( ) throw (IOException, RuntimeException)
718 DocumentGuard aGuard( *this );
720 if ( m_pImpl->getDocFileLocation() == m_pImpl->getURL() )
721 if ( m_pImpl->m_bDocumentReadOnly )
722 throw IOException();
724 impl_storeAs_throw( m_pImpl->getURL(), m_pImpl->getResource(), SAVE, aGuard );
727 // -----------------------------------------------------------------------------
728 void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const Sequence< PropertyValue>& _rArguments,
729 const StoreType _eType, DocumentGuard& _rGuard ) throw ( IOException, RuntimeException )
731 OSL_PRECOND( ( _eType == SAVE ) || ( _eType == SAVE_AS ),
732 "ODatabaseDocument::impl_storeAs_throw: you introduced a new type which cannot be handled here!" );
734 // if we're in the process of initializing the document (which effectively means it is an implicit
735 // initialization triggered in storeAsURL), the we do not notify events, since to an observer, the SaveAs
736 // should not be noticable
737 bool bIsInitializationProcess = impl_isInitializing();
739 if ( !bIsInitializationProcess )
741 _rGuard.clear();
742 m_aEventNotifier.notifyDocumentEvent( _eType == SAVE ? "OnSave" : "OnSaveAs", NULL, makeAny( _rURL ) );
743 _rGuard.reset();
746 Reference< XStorage > xNewRootStorage;
747 // will be non-NULL if our storage changed
751 ModifyLock aLock( *this );
752 // ignore all changes of our "modified" state during storing
754 sal_Bool bLocationChanged = ( _rURL != m_pImpl->getDocFileLocation() );
755 if ( bLocationChanged )
757 // create storage for target URL
758 Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( _rURL ) );
760 if ( m_pImpl->isEmbeddedDatabase() )
761 m_pImpl->clearConnections();
763 // commit everything
764 m_pImpl->commitEmbeddedStorage();
765 m_pImpl->commitStorages();
767 // copy own storage to target storage
768 Reference< XStorage > xCurrentStorage( m_pImpl->getRootStorage() );
769 if ( xCurrentStorage.is() )
770 xCurrentStorage->copyToStorage( xTargetStorage );
772 m_pImpl->disposeStorages();
774 xNewRootStorage = m_pImpl->switchToStorage( xTargetStorage );
776 m_pImpl->m_bDocumentReadOnly = sal_False;
779 // store to current storage
780 Reference< XStorage > xCurrentStorage( m_pImpl->getOrCreateRootStorage(), UNO_QUERY_THROW );
781 Sequence< PropertyValue > aMediaDescriptor( lcl_appendFileNameToDescriptor( _rArguments, _rURL ) );
782 impl_storeToStorage_throw( xCurrentStorage, aMediaDescriptor, _rGuard );
784 // success - tell our impl
785 m_pImpl->attachResource( _rURL, aMediaDescriptor );
787 // if we are in an initialization process, then this is finished, now that we stored the document
788 if ( bIsInitializationProcess )
789 impl_setInitialized();
791 catch( const Exception& )
793 Any aError = ::cppu::getCaughtException();
795 // notify the failure
796 if ( !bIsInitializationProcess )
797 m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed", NULL, makeAny( _rURL ) );
799 if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() )
800 || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() )
803 // allowed to leave
804 throw;
807 Exception aExcept;
808 aError >>= aExcept;
810 ::rtl::OUString sErrorMessage = ResourceManager::loadString(
811 RID_STR_ERROR_WHILE_SAVING,
812 "$except$", aError.getValueTypeName(),
813 "$message$", aExcept.Message
815 throw IOException( sErrorMessage, *this );
818 // notify the document event
819 if ( !bIsInitializationProcess )
820 m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveDone" : "OnSaveAsDone", NULL, makeAny( _rURL ) );
822 // reset our "modified" flag, and clear the guard
823 impl_setModified_nothrow( sal_False, _rGuard );
824 // <- SYNCHRONIZED
826 // notify storage listeners
827 if ( xNewRootStorage.is() )
828 impl_notifyStorageChange_nolck_nothrow( xNewRootStorage );
831 // -----------------------------------------------------------------------------
832 Reference< XStorage > ODatabaseDocument::impl_createStorageFor_throw( const ::rtl::OUString& _rURL ) const
834 Sequence<Any> aParam(2);
835 aParam[0] <<= _rURL;
836 aParam[1] <<= ElementModes::READWRITE | ElementModes::TRUNCATE;
838 Reference< XSingleServiceFactory > xStorageFactory( m_pImpl->createStorageFactory(), UNO_SET_THROW );
839 return Reference< XStorage >( xStorageFactory->createInstanceWithArguments( aParam ), UNO_QUERY_THROW );
842 // -----------------------------------------------------------------------------
843 void SAL_CALL ODatabaseDocument::storeAsURL( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (IOException, RuntimeException)
845 // SYNCHRONIZED ->
846 DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
848 // Normally, a document initialization is done via XLoadable::load or XLoadable::initNew. For convenience
849 // reasons, and to not break existing API clients, it's allowed to call storeAsURL without having initialized
850 // the document, in which case the initialization will be done implicitly.
851 bool bImplicitInitialization = !impl_isInitialized();
852 // implicit initialization while another initialization is just running is not possible
853 if ( bImplicitInitialization && impl_isInitializing() )
854 throw DoubleInitializationException();
856 if ( bImplicitInitialization )
857 impl_setInitializing();
861 impl_storeAs_throw( _rURL, _rArguments, SAVE_AS, aGuard );
862 // <- SYNCHRONIZED
864 // impl_storeAs_throw cleared the lock on our mutex, but the below lines need this lock
865 // SYNCHRONIZED ->
866 aGuard.reset();
868 // our title might have changed, potentially at least
869 // Sadly, we cannot check this: Calling getTitle here and now would not deliver
870 // an up-to-date result, as the call is delegated to our TitleHelper instance, which itself
871 // updates its title only if it gets the OnSaveAsDone event (which was sent asynchronously
872 // by impl_storeAs_throw). So, we simply notify always, and also asynchronously
873 m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" );
875 catch( const Exception& )
877 impl_reset_nothrow();
878 throw;
881 if ( bImplicitInitialization )
882 m_bAllowDocumentScripting = true;
884 aGuard.clear();
885 // <- SYNCHRONIZED
887 if ( bImplicitInitialization )
888 m_aEventNotifier.notifyDocumentEvent( "OnCreate" );
891 // -----------------------------------------------------------------------------
892 void ODatabaseDocument::impl_storeToStorage_throw( const Reference< XStorage >& _rxTargetStorage, const Sequence< PropertyValue >& _rMediaDescriptor,
893 DocumentGuard& _rDocGuard ) const
895 if ( !_rxTargetStorage.is() )
896 throw IllegalArgumentException( ::rtl::OUString(), *const_cast< ODatabaseDocument* >( this ), 1 );
898 if ( !m_pImpl.is() )
899 throw DisposedException( ::rtl::OUString(), *const_cast< ODatabaseDocument* >( this ) );
903 // commit everything
904 m_pImpl->commitEmbeddedStorage();
905 m_pImpl->commitStorages();
907 // copy own storage to target storage
908 if ( impl_isInitialized() )
910 Reference< XStorage > xCurrentStorage( m_pImpl->getOrCreateRootStorage(), UNO_QUERY_THROW );
911 if ( xCurrentStorage != _rxTargetStorage )
912 xCurrentStorage->copyToStorage( _rxTargetStorage );
915 // write into target storage
916 ::comphelper::NamedValueCollection aWriteArgs( _rMediaDescriptor );
917 lcl_triggerStatusIndicator_throw( aWriteArgs, _rDocGuard, true );
918 impl_writeStorage_throw( _rxTargetStorage, aWriteArgs );
919 lcl_triggerStatusIndicator_throw( aWriteArgs, _rDocGuard, false );
921 // commit target storage
922 OSL_VERIFY( ODatabaseModelImpl::commitStorageIfWriteable( _rxTargetStorage ) );
924 catch( const IOException& ) { throw; }
925 catch( const RuntimeException& ) { throw; }
926 catch ( const Exception& e )
928 throw IOException( e.Message, *const_cast< ODatabaseDocument* >( this ) );
932 // -----------------------------------------------------------------------------
933 void SAL_CALL ODatabaseDocument::storeToURL( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (IOException, RuntimeException)
935 DocumentGuard aGuard( *this );
936 ModifyLock aLock( *this );
939 aGuard.clear();
940 m_aEventNotifier.notifyDocumentEvent( "OnSaveTo", NULL, makeAny( _rURL ) );
941 aGuard.reset();
946 // create storage for target URL
947 Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( _rURL ) );
949 // extend media descriptor with URL
950 Sequence< PropertyValue > aMediaDescriptor( lcl_appendFileNameToDescriptor( _rArguments, _rURL ) );
952 // store to this storage
953 impl_storeToStorage_throw( xTargetStorage, aMediaDescriptor, aGuard );
955 catch( const Exception& )
957 Any aError = ::cppu::getCaughtException();
958 m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToFailed", NULL, aError );
960 if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() )
961 || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() )
964 // allowed to leave
965 throw;
968 Exception aExcept;
969 aError >>= aExcept;
971 ::rtl::OUString sErrorMessage = ResourceManager::loadString(
972 RID_STR_ERROR_WHILE_SAVING,
973 "$except$", aError.getValueTypeName(),
974 "$message$", aExcept.Message
976 throw IOException( sErrorMessage, *this );
979 m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToDone", NULL, makeAny( _rURL ) );
982 // -----------------------------------------------------------------------------
983 // XModifyBroadcaster
984 void SAL_CALL ODatabaseDocument::addModifyListener( const Reference< XModifyListener >& _xListener ) throw (RuntimeException)
986 DocumentGuard aGuard( *this );
987 m_aModifyListeners.addInterface(_xListener);
990 // -----------------------------------------------------------------------------
991 void SAL_CALL ODatabaseDocument::removeModifyListener( const Reference< XModifyListener >& _xListener ) throw (RuntimeException)
993 DocumentGuard aGuard( *this );
994 m_aModifyListeners.removeInterface(_xListener);
997 // -----------------------------------------------------------------------------
998 // XModifiable
999 sal_Bool SAL_CALL ODatabaseDocument::isModified( ) throw (RuntimeException)
1001 DocumentGuard aGuard( *this );
1003 return m_pImpl->m_bModified;
1006 // -----------------------------------------------------------------------------
1007 void SAL_CALL ODatabaseDocument::setModified( sal_Bool _bModified ) throw (PropertyVetoException, RuntimeException)
1009 DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
1010 if ( impl_isInitialized() )
1011 impl_setModified_nothrow( _bModified, aGuard );
1012 // it's allowed to call setModified without the document being initialized already. In this case,
1013 // we simply ignore the call - when the initialization is finished, the respective code will set
1014 // a proper "modified" flag
1017 // -----------------------------------------------------------------------------
1018 void ODatabaseDocument::impl_setModified_nothrow( sal_Bool _bModified, DocumentGuard& _rGuard )
1020 // SYNCHRONIZED ->
1021 bool bModifiedChanged = ( m_pImpl->m_bModified != _bModified ) && ( !m_pImpl->isModifyLocked() );
1023 if ( bModifiedChanged )
1025 m_pImpl->m_bModified = _bModified;
1026 m_aEventNotifier.notifyDocumentEventAsync( "OnModifyChanged" );
1028 _rGuard.clear();
1029 // <- SYNCHRONIZED
1031 if ( bModifiedChanged )
1033 lang::EventObject aEvent( *this );
1034 m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvent );
1038 // -----------------------------------------------------------------------------
1039 // ::com::sun::star::document::XEventBroadcaster
1040 void SAL_CALL ODatabaseDocument::addEventListener(const uno::Reference< document::XEventListener >& _Listener ) throw (uno::RuntimeException)
1042 m_aEventNotifier.addLegacyEventListener( _Listener );
1045 // -----------------------------------------------------------------------------
1046 void SAL_CALL ODatabaseDocument::removeEventListener( const uno::Reference< document::XEventListener >& _Listener ) throw (uno::RuntimeException)
1048 m_aEventNotifier.removeLegacyEventListener( _Listener );
1051 // -----------------------------------------------------------------------------
1052 void SAL_CALL ODatabaseDocument::addDocumentEventListener( const Reference< XDocumentEventListener >& _Listener ) throw (RuntimeException)
1054 m_aEventNotifier.addDocumentEventListener( _Listener );
1057 // -----------------------------------------------------------------------------
1058 void SAL_CALL ODatabaseDocument::removeDocumentEventListener( const Reference< XDocumentEventListener >& _Listener ) throw (RuntimeException)
1060 m_aEventNotifier.removeDocumentEventListener( _Listener );
1063 // -----------------------------------------------------------------------------
1064 void SAL_CALL ODatabaseDocument::notifyDocumentEvent( const ::rtl::OUString& _EventName, const Reference< XController2 >& _ViewController, const Any& _Supplement ) throw (IllegalArgumentException, NoSupportException, RuntimeException)
1066 if ( !_EventName.getLength() )
1067 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
1069 // SYNCHRONIZED ->
1070 DocumentGuard aGuard( *this );
1072 if ( !DocumentEvents::needsSynchronousNotification( _EventName ) )
1074 m_aEventNotifier.notifyDocumentEventAsync( _EventName, _ViewController, _Supplement );
1075 return;
1077 aGuard.clear();
1078 // <- SYNCHRONIZED
1080 m_aEventNotifier.notifyDocumentEvent( _EventName, _ViewController, _Supplement );
1083 // -----------------------------------------------------------------------------
1084 Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getPrinter( ) throw (RuntimeException)
1086 DBG_ERROR( "ODatabaseDocument::getPrinter: not supported!" );
1087 return Sequence< PropertyValue >();
1090 // -----------------------------------------------------------------------------
1091 void SAL_CALL ODatabaseDocument::setPrinter( const Sequence< PropertyValue >& /*aPrinter*/ ) throw (IllegalArgumentException, RuntimeException)
1093 DBG_ERROR( "ODatabaseDocument::setPrinter: not supported!" );
1096 // -----------------------------------------------------------------------------
1097 void SAL_CALL ODatabaseDocument::print( const Sequence< PropertyValue >& /*xOptions*/ ) throw (IllegalArgumentException, RuntimeException)
1099 DBG_ERROR( "ODatabaseDocument::print: not supported!" );
1102 // -----------------------------------------------------------------------------
1103 void ODatabaseDocument::impl_reparent_nothrow( const WeakReference< XNameAccess >& _rxContainer )
1105 Reference< XChild > xChild( _rxContainer.get(), UNO_QUERY );
1106 if ( xChild.is() )
1107 xChild->setParent( *this );
1109 // -----------------------------------------------------------------------------
1110 void ODatabaseDocument::clearObjectContainer( WeakReference< XNameAccess >& _rxContainer)
1112 Reference< XNameAccess > xContainer = _rxContainer;
1113 ::comphelper::disposeComponent( xContainer );
1115 Reference< XChild > xChild( _rxContainer.get(),UNO_QUERY );
1116 if ( xChild.is() )
1117 xChild->setParent( NULL );
1118 _rxContainer = Reference< XNameAccess >();
1120 // -----------------------------------------------------------------------------
1121 Reference< XNameAccess > ODatabaseDocument::impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType _eType )
1123 if ( ( _eType != ODatabaseModelImpl::E_FORM ) && ( _eType != ODatabaseModelImpl::E_REPORT ) )
1124 throw IllegalArgumentException();
1126 bool bFormsContainer = _eType == ODatabaseModelImpl::E_FORM;
1128 WeakReference< XNameAccess >& rContainerRef( bFormsContainer ? m_xForms : m_xReports );
1129 Reference< XNameAccess > xContainer = rContainerRef;
1130 if ( !xContainer.is() )
1132 TContentPtr& rContainerData( m_pImpl->getObjectContainer( _eType ) );
1133 rContainerRef = xContainer = new ODocumentContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, bFormsContainer );
1134 impl_reparent_nothrow( xContainer );
1136 return xContainer;
1139 // -----------------------------------------------------------------------------
1140 void ODatabaseDocument::impl_closeControllerFrames_nolck_throw( sal_Bool _bDeliverOwnership )
1142 Controllers aCopy = m_aControllers;
1144 Controllers::iterator aEnd = aCopy.end();
1145 for ( Controllers::iterator aIter = aCopy.begin(); aIter != aEnd ; ++aIter )
1147 if ( !aIter->is() )
1148 continue;
1152 Reference< XCloseable> xFrame( (*aIter)->getFrame(), UNO_QUERY );
1153 if ( xFrame.is() )
1154 xFrame->close( _bDeliverOwnership );
1156 catch( const CloseVetoException& ) { throw; }
1157 catch( const Exception& )
1159 DBG_UNHANDLED_EXCEPTION();
1164 // -----------------------------------------------------------------------------
1165 struct DisposeControllerFrame : public ::std::unary_function< Reference< XController >, void >
1167 void operator()( const Reference< XController >& _rxController ) const
1171 if ( !_rxController.is() )
1172 return;
1174 Reference< XFrame > xFrame( _rxController->getFrame() );
1175 ::comphelper::disposeComponent( xFrame );
1177 catch( const Exception& )
1179 DBG_UNHANDLED_EXCEPTION();
1184 // -----------------------------------------------------------------------------
1185 void ODatabaseDocument::impl_disposeControllerFrames_nothrow()
1187 Controllers aCopy;
1188 aCopy.swap( m_aControllers ); // ensure m_aControllers is empty afterwards
1189 ::std::for_each( aCopy.begin(), aCopy.end(), DisposeControllerFrame() );
1192 // -----------------------------------------------------------------------------
1193 void SAL_CALL ODatabaseDocument::close( sal_Bool _bDeliverOwnership ) throw (CloseVetoException, RuntimeException)
1195 // nearly everything below can/must be done without our mutex locked, the below is just for
1196 // the checks for being disposed and the like
1197 // SYNCHRONIZED ->
1199 DocumentGuard aGuard( *this );
1200 m_bClosing = true;
1202 // <- SYNCHRONIZED
1206 // allow listeners to veto
1207 lang::EventObject aEvent( *this );
1208 m_aCloseListener.forEach< XCloseListener >(
1209 boost::bind( &XCloseListener::queryClosing, _1, boost::cref( aEvent ), boost::cref( _bDeliverOwnership ) ) );
1211 // notify that we're going to unload
1212 m_aEventNotifier.notifyDocumentEvent( "OnPrepareUnload" );
1214 impl_closeControllerFrames_nolck_throw( _bDeliverOwnership );
1216 m_aCloseListener.notifyEach( &XCloseListener::notifyClosing, (const lang::EventObject&)aEvent );
1218 dispose();
1220 catch ( const Exception& )
1222 ::osl::MutexGuard aGuard( m_aMutex );
1223 m_bClosing = false;
1224 throw;
1227 // SYNCHRONIZED ->
1228 ::osl::MutexGuard aGuard( m_aMutex );
1229 m_bClosing = false;
1230 // <- SYNCHRONIZED
1232 // -----------------------------------------------------------------------------
1233 void SAL_CALL ODatabaseDocument::addCloseListener( const Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (RuntimeException)
1235 DocumentGuard aGuard( *this );
1236 m_aCloseListener.addInterface(Listener);
1238 // -----------------------------------------------------------------------------
1239 void SAL_CALL ODatabaseDocument::removeCloseListener( const Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (RuntimeException)
1241 DocumentGuard aGuard( *this );
1242 m_aCloseListener.removeInterface(Listener);
1244 // -----------------------------------------------------------------------------
1245 Reference< XNameAccess > SAL_CALL ODatabaseDocument::getFormDocuments( ) throw (RuntimeException)
1247 DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1248 return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_FORM );
1250 // -----------------------------------------------------------------------------
1251 Reference< XNameAccess > SAL_CALL ODatabaseDocument::getReportDocuments( ) throw (RuntimeException)
1253 DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1254 return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_REPORT );
1257 // -----------------------------------------------------------------------------
1258 void ODatabaseDocument::WriteThroughComponent( const Reference< XComponent >& xComponent, const sal_Char* pStreamName,
1259 const sal_Char* pServiceName, const Sequence< Any >& _rArguments, const Sequence< PropertyValue >& rMediaDesc,
1260 const Reference<XStorage>& _xStorageToSaveTo ) const
1262 OSL_ENSURE( pStreamName, "Need stream name!" );
1263 OSL_ENSURE( pServiceName, "Need service name!" );
1265 // open stream
1266 ::rtl::OUString sStreamName = ::rtl::OUString::createFromAscii( pStreamName );
1267 Reference< XStream > xStream = _xStorageToSaveTo->openStreamElement( sStreamName, ElementModes::READWRITE | ElementModes::TRUNCATE );
1268 if ( !xStream.is() )
1269 return;
1271 Reference< XOutputStream > xOutputStream( xStream->getOutputStream() );
1272 OSL_ENSURE( xOutputStream.is(), "Can't create output stream in package!" );
1273 if ( !xOutputStream.is() )
1274 return;
1276 Reference< XSeekable > xSeek( xOutputStream, UNO_QUERY );
1277 if ( xSeek.is() )
1278 xSeek->seek(0);
1280 Reference< XPropertySet > xStreamProp( xOutputStream, UNO_QUERY_THROW );
1281 xStreamProp->setPropertyValue( INFO_MEDIATYPE, makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/xml" ) ) ) );
1282 xStreamProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), makeAny( (sal_Bool)sal_True ) );
1284 // write the stuff
1285 WriteThroughComponent( xOutputStream, xComponent, pServiceName, _rArguments, rMediaDesc );
1288 void ODatabaseDocument::WriteThroughComponent( const Reference< XOutputStream >& xOutputStream,
1289 const Reference< XComponent >& xComponent, const sal_Char* pServiceName, const Sequence< Any >& _rArguments,
1290 const Sequence< PropertyValue >& rMediaDesc ) const
1292 OSL_ENSURE( xOutputStream.is(), "I really need an output stream!" );
1293 OSL_ENSURE( xComponent.is(), "Need component!" );
1294 OSL_ENSURE( NULL != pServiceName, "Need component name!" );
1296 // get component
1297 Reference< XActiveDataSource > xSaxWriter;
1298 OSL_VERIFY( m_pImpl->m_aContext.createComponent( "com.sun.star.xml.sax.Writer", xSaxWriter ) );
1299 if ( !xSaxWriter.is() )
1300 return;
1302 // connect XML writer to output stream
1303 xSaxWriter->setOutputStream( xOutputStream );
1305 // prepare arguments (prepend doc handler to given arguments)
1306 Reference< XDocumentHandler > xDocHandler( xSaxWriter,UNO_QUERY);
1307 Sequence<Any> aArgs( 1 + _rArguments.getLength() );
1308 aArgs[0] <<= xDocHandler;
1309 for ( sal_Int32 i = 0; i < _rArguments.getLength(); ++i )
1310 aArgs[ i+1 ] = _rArguments[i];
1312 // get filter component
1313 Reference< XExporter > xExporter;
1314 OSL_VERIFY( m_pImpl->m_aContext.createComponentWithArguments( pServiceName, aArgs, xExporter ) );
1315 if ( !xExporter.is() )
1316 return;
1318 // connect model and filter
1319 xExporter->setSourceDocument( xComponent );
1321 // filter
1322 Reference< XFilter > xFilter( xExporter, UNO_QUERY_THROW );
1323 xFilter->filter( rMediaDesc );
1326 // -----------------------------------------------------------------------------
1327 void ODatabaseDocument::impl_writeStorage_throw( const Reference< XStorage >& _rxTargetStorage, const ::comphelper::NamedValueCollection& _rMediaDescriptor ) const
1329 // extract status indicator
1330 Sequence< Any > aDelegatorArguments;
1331 lcl_extractStatusIndicator( _rMediaDescriptor, aDelegatorArguments );
1333 /** property map for export info set */
1334 comphelper::PropertyMapEntry aExportInfoMap[] =
1336 { MAP_LEN( "BaseURI"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
1337 { MAP_LEN( "StreamName"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
1338 { MAP_LEN( "UsePrettyPrinting" ), 0, &::getCppuType((sal_Bool*)0), beans::PropertyAttribute::MAYBEVOID, 0},
1339 { NULL, 0, 0, NULL, 0, 0 }
1341 uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
1343 SvtSaveOptions aSaveOpt;
1344 xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UsePrettyPrinting")), uno::makeAny(aSaveOpt.IsPrettyPrinting()));
1345 if ( aSaveOpt.IsSaveRelFSys() )
1346 xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rMediaDescriptor.getOrDefault("URL",::rtl::OUString())));
1348 sal_Int32 nArgsLen = aDelegatorArguments.getLength();
1349 aDelegatorArguments.realloc(nArgsLen+1);
1350 aDelegatorArguments[nArgsLen++] <<= xInfoSet;
1352 Reference< XPropertySet > xProp( _rxTargetStorage, UNO_QUERY_THROW );
1353 xProp->setPropertyValue( INFO_MEDIATYPE, makeAny( (rtl::OUString)MIMETYPE_OASIS_OPENDOCUMENT_DATABASE ) );
1355 Reference< XComponent > xComponent( *const_cast< ODatabaseDocument* >( this ), UNO_QUERY_THROW );
1357 Sequence< PropertyValue > aMediaDescriptor;
1358 _rMediaDescriptor >>= aMediaDescriptor;
1360 xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("settings.xml"))));
1361 WriteThroughComponent( xComponent, "settings.xml", "com.sun.star.comp.sdb.XMLSettingsExporter",
1362 aDelegatorArguments, aMediaDescriptor, _rxTargetStorage );
1364 xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml"))));
1365 WriteThroughComponent( xComponent, "content.xml", "com.sun.star.comp.sdb.DBExportFilter",
1366 aDelegatorArguments, aMediaDescriptor, _rxTargetStorage );
1368 m_pImpl->storeLibraryContainersTo( _rxTargetStorage );
1371 // -----------------------------------------------------------------------------
1372 Reference< XUIConfigurationManager > SAL_CALL ODatabaseDocument::getUIConfigurationManager( ) throw (RuntimeException)
1374 DocumentGuard aGuard( *this );
1376 if ( !m_xUIConfigurationManager.is() )
1378 m_pImpl->m_aContext.createComponent( "com.sun.star.ui.UIConfigurationManager", m_xUIConfigurationManager );
1379 Reference< XUIConfigurationStorage > xUIConfigStorage( m_xUIConfigurationManager, UNO_QUERY );
1380 if ( xUIConfigStorage.is() )
1382 rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
1383 Reference< XStorage > xConfigStorage;
1385 // First try to open with READWRITE and then READ
1386 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, ElementModes::READWRITE );
1387 if ( xConfigStorage.is() )
1389 rtl::OUString aUIConfigMediaType( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ));
1390 rtl::OUString aMediaType;
1391 Reference< XPropertySet > xPropSet( xConfigStorage, UNO_QUERY );
1392 Any a = xPropSet->getPropertyValue( INFO_MEDIATYPE );
1393 if ( !( a >>= aMediaType ) || ( aMediaType.getLength() == 0 ))
1395 a <<= aUIConfigMediaType;
1396 xPropSet->setPropertyValue( INFO_MEDIATYPE, a );
1399 else
1400 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, ElementModes::READ );
1402 // initialize ui configuration manager with document substorage
1403 xUIConfigStorage->setStorage( xConfigStorage );
1407 return m_xUIConfigurationManager;
1409 // -----------------------------------------------------------------------------
1410 Reference< XStorage > SAL_CALL ODatabaseDocument::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode ) throw (RuntimeException)
1412 DocumentGuard aGuard( *this );
1414 Reference< XDocumentSubStorageSupplier > xStorageAccess( m_pImpl->getDocumentSubStorageSupplier() );
1415 return xStorageAccess->getDocumentSubStorage( aStorageName, nMode );
1417 // -----------------------------------------------------------------------------
1418 Sequence< ::rtl::OUString > SAL_CALL ODatabaseDocument::getDocumentSubStoragesNames( ) throw (::com::sun::star::io::IOException, RuntimeException)
1420 Reference< XDocumentSubStorageSupplier > xStorageAccess( m_pImpl->getDocumentSubStorageSupplier() );
1421 return xStorageAccess->getDocumentSubStoragesNames();
1424 //------------------------------------------------------------------------------
1425 void ODatabaseDocument::impl_notifyStorageChange_nolck_nothrow( const Reference< XStorage >& _rxNewRootStorage )
1427 Reference< XInterface > xMe( *const_cast< ODatabaseDocument* >( this ) );
1429 m_aStorageListeners.forEach< XStorageChangeListener >(
1430 boost::bind( &XStorageChangeListener::notifyStorageChange, _1, boost::cref( xMe ), boost::cref( _rxNewRootStorage ) ) );
1433 //------------------------------------------------------------------------------
1434 void ODatabaseDocument::disposing()
1436 if ( !m_pImpl.is() )
1438 // this means that we're already disposed
1439 DBG_ASSERT( ODatabaseDocument_OfficeDocument::rBHelper.bDisposed, "ODatabaseDocument::disposing: no impl anymore, but not yet disposed!" );
1440 return;
1443 if ( impl_isInitialized() )
1444 m_aEventNotifier.notifyDocumentEvent( "OnUnload" );
1446 Reference< XModel > xHoldAlive( this );
1448 m_aEventNotifier.disposing();
1450 lang::EventObject aDisposeEvent(static_cast<XWeak*>(this));
1451 m_aModifyListeners.disposeAndClear( aDisposeEvent );
1452 m_aCloseListener.disposeAndClear( aDisposeEvent );
1453 m_aStorageListeners.disposeAndClear( aDisposeEvent );
1455 // this is the list of objects which we currently hold as member. Upon resetting
1456 // those members, we can (potentially) release the last reference to them, in which
1457 // case they will be deleted - if they're C++ implementations, that is :).
1458 // Some of those implementations are offending enough to require the SolarMutex, which
1459 // means we should not release the last reference while our own mutex is locked ...
1460 ::std::list< Reference< XInterface > > aKeepAlive;
1462 // SYNCHRONIZED ->
1463 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1465 DBG_ASSERT( m_aControllers.empty(), "ODatabaseDocument::disposing: there still are controllers!" );
1466 // normally, nobody should explicitly dispose, but only XCloseable::close the document. And upon
1467 // closing, our controllers are closed, too
1469 aKeepAlive.push_back( m_xUIConfigurationManager );
1470 m_xUIConfigurationManager = NULL;
1472 clearObjectContainer( m_xForms );
1473 clearObjectContainer( m_xReports );
1475 // reset the macro mode: in case the our impl struct stays alive (e.g. because our DataSource
1476 // object still exists), and somebody subsequently re-opens the document, we want to have
1477 // the security warning, again.
1478 m_pImpl->resetMacroExecutionMode();
1480 // similar argueing for our ViewMonitor
1481 m_aViewMonitor.reset();
1483 // tell our Impl to forget us
1484 m_pImpl->modelIsDisposing( impl_isInitialized(), ODatabaseModelImpl::ResetModelAccess() );
1486 // now, at the latest, the controller array should be empty. Controllers are
1487 // expected to listen for our disposal, and disconnect then
1488 DBG_ASSERT( m_aControllers.empty(), "ODatabaseDocument::disposing: there still are controllers!" );
1489 impl_disposeControllerFrames_nothrow();
1491 aKeepAlive.push_back( m_xModuleManager );
1492 m_xModuleManager.clear();
1494 aKeepAlive.push_back( m_xTitleHelper );
1495 m_xTitleHelper.clear();
1497 m_pImpl.clear();
1499 aGuard.clear();
1500 // <- SYNCHRONIZED
1502 aKeepAlive.clear();
1504 // -----------------------------------------------------------------------------
1505 // XComponent
1506 void SAL_CALL ODatabaseDocument::dispose( ) throw (RuntimeException)
1508 ::cppu::WeakComponentImplHelperBase::dispose();
1510 // -----------------------------------------------------------------------------
1511 void SAL_CALL ODatabaseDocument::addEventListener( const Reference< lang::XEventListener >& _xListener ) throw (RuntimeException)
1513 ::cppu::WeakComponentImplHelperBase::addEventListener( _xListener );
1515 // -----------------------------------------------------------------------------
1516 void SAL_CALL ODatabaseDocument::removeEventListener( const Reference< lang::XEventListener >& _xListener ) throw (RuntimeException)
1518 ::cppu::WeakComponentImplHelperBase::removeEventListener( _xListener );
1520 // XServiceInfo
1521 //------------------------------------------------------------------------------
1522 rtl::OUString ODatabaseDocument::getImplementationName( ) throw(RuntimeException)
1524 return getImplementationName_static();
1527 //------------------------------------------------------------------------------
1528 rtl::OUString ODatabaseDocument::getImplementationName_static( ) throw(RuntimeException)
1530 return rtl::OUString::createFromAscii("com.sun.star.comp.dba.ODatabaseDocument");
1533 //------------------------------------------------------------------------------
1534 Sequence< ::rtl::OUString > ODatabaseDocument::getSupportedServiceNames( ) throw (RuntimeException)
1536 return getSupportedServiceNames_static();
1539 //------------------------------------------------------------------------------
1540 Reference< XInterface > ODatabaseDocument::Create( const Reference< XComponentContext >& _rxContext )
1542 ::comphelper::ComponentContext aContext( _rxContext );
1543 Reference< XUnoTunnel > xDBContextTunnel( aContext.createComponent( (::rtl::OUString)SERVICE_SDB_DATABASECONTEXT ), UNO_QUERY_THROW );
1544 ODatabaseContext* pContext = reinterpret_cast< ODatabaseContext* >( xDBContextTunnel->getSomething( ODatabaseContext::getUnoTunnelImplementationId() ) );
1546 ::rtl::Reference<ODatabaseModelImpl> pImpl( new ODatabaseModelImpl( aContext.getLegacyServiceFactory(), *pContext ) );
1547 Reference< XModel > xModel( pImpl->createNewModel_deliverOwnership( false ) );
1548 return xModel.get();
1551 //------------------------------------------------------------------------------
1552 Sequence< ::rtl::OUString > ODatabaseDocument::getSupportedServiceNames_static( ) throw (RuntimeException)
1554 Sequence< ::rtl::OUString > aSNS( 2 );
1555 aSNS[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.OfficeDatabaseDocument"));
1556 aSNS[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.OfficeDocument"));
1557 return aSNS;
1560 //------------------------------------------------------------------------------
1561 sal_Bool ODatabaseDocument::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
1563 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
1565 // -----------------------------------------------------------------------------
1566 Reference< XDataSource > SAL_CALL ODatabaseDocument::getDataSource() throw (RuntimeException)
1568 DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
1569 return m_pImpl->getOrCreateDataSource();
1572 // -----------------------------------------------------------------------------
1573 void SAL_CALL ODatabaseDocument::loadFromStorage( const Reference< XStorage >& /*xStorage*/, const Sequence< PropertyValue >& /*aMediaDescriptor*/ ) throw (IllegalArgumentException, DoubleInitializationException, IOException, Exception, RuntimeException)
1575 DocumentGuard aGuard( *this );
1577 throw Exception(
1578 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Embedding of database documents is not supported." ) ),
1579 // TODO: resource
1580 *this
1584 // -----------------------------------------------------------------------------
1585 void SAL_CALL ODatabaseDocument::storeToStorage( const Reference< XStorage >& _rxStorage, const Sequence< PropertyValue >& _rMediaDescriptor ) throw (IllegalArgumentException, IOException, Exception, RuntimeException)
1587 DocumentGuard aGuard( *this );
1588 impl_storeToStorage_throw( _rxStorage, _rMediaDescriptor, aGuard );
1591 // -----------------------------------------------------------------------------
1592 void SAL_CALL ODatabaseDocument::switchToStorage( const Reference< XStorage >& _rxNewRootStorage ) throw (IllegalArgumentException, IOException, Exception, RuntimeException)
1594 DocumentGuard aGuard( *this );
1596 Reference< XStorage > xNewRootStorage( m_pImpl->switchToStorage( _rxNewRootStorage ) );
1598 aGuard.clear();
1599 impl_notifyStorageChange_nolck_nothrow( xNewRootStorage );
1602 // -----------------------------------------------------------------------------
1603 Reference< XStorage > SAL_CALL ODatabaseDocument::getDocumentStorage( ) throw (IOException, Exception, RuntimeException)
1605 DocumentGuard aGuard( *this );
1606 return m_pImpl->getOrCreateRootStorage();
1609 // -----------------------------------------------------------------------------
1610 void SAL_CALL ODatabaseDocument::addStorageChangeListener( const Reference< XStorageChangeListener >& _Listener ) throw (RuntimeException)
1612 DocumentGuard aGuard( *this );
1613 m_aStorageListeners.addInterface( _Listener );
1616 // -----------------------------------------------------------------------------
1617 void SAL_CALL ODatabaseDocument::removeStorageChangeListener( const Reference< XStorageChangeListener >& _Listener ) throw (RuntimeException)
1619 DocumentGuard aGuard( *this );
1620 m_aStorageListeners.addInterface( _Listener );
1623 // -----------------------------------------------------------------------------
1624 Reference< XStorageBasedLibraryContainer > SAL_CALL ODatabaseDocument::getBasicLibraries() throw (RuntimeException)
1626 DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1627 return m_pImpl->getLibraryContainer( true );
1630 // -----------------------------------------------------------------------------
1631 Reference< XStorageBasedLibraryContainer > SAL_CALL ODatabaseDocument::getDialogLibraries() throw (RuntimeException)
1633 DocumentGuard aGuard( *this );
1634 return m_pImpl->getLibraryContainer( false );
1637 // -----------------------------------------------------------------------------
1638 ::sal_Bool SAL_CALL ODatabaseDocument::getAllowMacroExecution() throw (RuntimeException)
1640 DocumentGuard aGuard( *this );
1641 return m_pImpl->adjustMacroMode_AutoReject();
1644 // -----------------------------------------------------------------------------
1645 Reference< XEmbeddedScripts > SAL_CALL ODatabaseDocument::getScriptContainer() throw (RuntimeException)
1647 DocumentGuard aGuard( *this );
1648 return this;
1651 // -----------------------------------------------------------------------------
1652 Reference< provider::XScriptProvider > SAL_CALL ODatabaseDocument::getScriptProvider( ) throw (RuntimeException)
1654 DocumentGuard aGuard( *this );
1656 Reference< XScriptProvider > xScriptProvider( m_xScriptProvider );
1657 if ( !xScriptProvider.is() )
1659 Reference < XScriptProviderFactory > xFactory(
1660 m_pImpl->m_aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
1662 Any aScriptProviderContext;
1663 if ( m_bAllowDocumentScripting )
1664 aScriptProviderContext <<= Reference< XModel >( this );
1666 xScriptProvider.set( xFactory->createScriptProvider( aScriptProviderContext ), UNO_SET_THROW );
1667 m_xScriptProvider = xScriptProvider;
1670 return xScriptProvider;
1673 // -----------------------------------------------------------------------------
1674 Reference< XNameReplace > SAL_CALL ODatabaseDocument::getEvents( ) throw (RuntimeException)
1676 DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1677 return m_pEventContainer;
1680 // -----------------------------------------------------------------------------
1681 void SAL_CALL ODatabaseDocument::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
1683 if ( m_pImpl.is() )
1684 m_pImpl->disposing(Source);
1687 //------------------------------------------------------------------
1688 Reference< XInterface > ODatabaseDocument::getThis() const
1690 return *const_cast< ODatabaseDocument* >( this );
1692 // -----------------------------------------------------------------------------
1693 struct CreateAny : public ::std::unary_function< Reference<XController>, Any>
1695 Any operator() (const Reference<XController>& lhs) const
1697 return makeAny(lhs);
1701 // XModel2
1702 Reference< XEnumeration > SAL_CALL ODatabaseDocument::getControllers( ) throw (RuntimeException)
1704 DocumentGuard aGuard( *this );
1705 uno::Sequence< Any> aController( m_aControllers.size() );
1706 ::std::transform( m_aControllers.begin(), m_aControllers.end(), aController.getArray(), CreateAny() );
1707 return new ::comphelper::OAnyEnumeration(aController);
1709 // -----------------------------------------------------------------------------
1710 Sequence< ::rtl::OUString > SAL_CALL ODatabaseDocument::getAvailableViewControllerNames( ) throw (RuntimeException)
1712 Sequence< ::rtl::OUString > aNames(1);
1713 aNames[0] = SERVICE_SDB_APPLICATIONCONTROLLER;
1714 return aNames;
1716 // -----------------------------------------------------------------------------
1717 Reference< XController2 > SAL_CALL ODatabaseDocument::createDefaultViewController( const Reference< XFrame >& _Frame ) throw (IllegalArgumentException, Exception, RuntimeException)
1719 return createViewController(
1720 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ),
1721 Sequence< PropertyValue >(),
1722 _Frame
1726 // -----------------------------------------------------------------------------
1727 Reference< XController2 > SAL_CALL ODatabaseDocument::createViewController( const ::rtl::OUString& _ViewName, const Sequence< PropertyValue >& _Arguments, const Reference< XFrame >& _Frame ) throw (IllegalArgumentException, Exception, RuntimeException)
1729 if ( !_ViewName.equalsAscii( "Default" ) && !_ViewName.equalsAscii( "Preview" ) )
1730 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
1731 if ( !_Frame.is() )
1732 throw IllegalArgumentException( ::rtl::OUString(), *this, 3 );
1734 DocumentGuard aGuard( *this );
1735 ::comphelper::ComponentContext aContext( m_pImpl->m_aContext );
1736 aGuard.clear();
1738 Reference< XController2 > xController;
1739 aContext.createComponent( "org.openoffice.comp.dbu.OApplicationController", xController );
1741 ::comphelper::NamedValueCollection aInitArgs( _Arguments );
1742 aInitArgs.put( "Frame", _Frame );
1743 if ( _ViewName.equalsAscii( "Preview" ) )
1744 aInitArgs.put( "Preview", sal_Bool( sal_True ) );
1745 Reference< XInitialization > xInitController( xController, UNO_QUERY_THROW );
1746 xInitController->initialize( aInitArgs.getWrappedPropertyValues() );
1748 return xController;
1751 // -----------------------------------------------------------------------------
1752 //=============================================================================
1753 Reference< XTitle > ODatabaseDocument::impl_getTitleHelper_throw()
1755 if ( ! m_xTitleHelper.is ())
1757 Reference< XUntitledNumbers > xDesktop(
1758 m_pImpl->m_aContext.createComponent( "com.sun.star.frame.Desktop" ),
1759 UNO_QUERY_THROW );
1760 uno::Reference< frame::XModel > xThis (getThis(), uno::UNO_QUERY_THROW);
1762 ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(m_pImpl->m_aContext.getLegacyServiceFactory());
1763 m_xTitleHelper.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW);
1764 pHelper->setOwner (xThis );
1765 pHelper->connectWithUntitledNumbers (xDesktop);
1768 return m_xTitleHelper;
1771 //=============================================================================
1772 uno::Reference< frame::XUntitledNumbers > ODatabaseDocument::impl_getUntitledHelper_throw(const uno::Reference< uno::XInterface >& _xComponent)
1774 if ( !m_xModuleManager.is() )
1775 m_xModuleManager.set( m_pImpl->m_aContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
1777 ::rtl::OUString sModuleId;
1780 sModuleId = m_xModuleManager->identify( _xComponent );
1782 catch(uno::Exception)
1784 // ni
1786 uno::Reference< frame::XUntitledNumbers > xNumberedControllers;
1788 TNumberedController::iterator aFind = m_aNumberedControllers.find(sModuleId);
1789 if ( aFind == m_aNumberedControllers.end() )
1791 uno::Reference< frame::XModel > xThis(static_cast< frame::XModel* >(this), uno::UNO_QUERY_THROW);
1792 ::comphelper::NumberedCollection* pHelper = new ::comphelper::NumberedCollection();
1793 xNumberedControllers.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW);
1795 pHelper->setOwner (xThis);
1796 //pHelper->setUntitledPrefix (::rtl::OUString::createFromAscii(" : "));
1798 m_aNumberedControllers.insert(TNumberedController::value_type(sModuleId,xNumberedControllers));
1800 else
1801 xNumberedControllers = aFind->second;
1803 return xNumberedControllers;
1806 //=============================================================================
1807 // css.frame.XTitle
1808 ::rtl::OUString SAL_CALL ODatabaseDocument::getTitle()
1809 throw (uno::RuntimeException)
1811 // SYNCHRONIZED ->
1812 DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1813 return impl_getTitleHelper_throw()->getTitle();
1816 //=============================================================================
1817 // css.frame.XTitle
1818 void SAL_CALL ODatabaseDocument::setTitle( const ::rtl::OUString& sTitle )
1819 throw (uno::RuntimeException)
1821 // SYNCHRONIZED ->
1822 DocumentGuard aGuard( *this );
1823 impl_getTitleHelper_throw()->setTitle( sTitle );
1824 m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" );
1825 // <- SYNCHRONIZED
1828 //=============================================================================
1829 // css.frame.XTitleChangeBroadcaster
1830 void SAL_CALL ODatabaseDocument::addTitleChangeListener( const uno::Reference< frame::XTitleChangeListener >& xListener )
1831 throw (uno::RuntimeException)
1833 // SYNCHRONIZED ->
1834 DocumentGuard aGuard( *this );
1836 uno::Reference< frame::XTitleChangeBroadcaster > xBroadcaster( impl_getTitleHelper_throw(), uno::UNO_QUERY_THROW );
1837 xBroadcaster->addTitleChangeListener( xListener );
1840 //=============================================================================
1841 // css.frame.XTitleChangeBroadcaster
1842 void SAL_CALL ODatabaseDocument::removeTitleChangeListener( const uno::Reference< frame::XTitleChangeListener >& xListener )
1843 throw (uno::RuntimeException)
1845 // SYNCHRONIZED ->
1846 DocumentGuard aGuard( *this );
1848 uno::Reference< frame::XTitleChangeBroadcaster > xBroadcaster( impl_getTitleHelper_throw(), uno::UNO_QUERY_THROW );
1849 xBroadcaster->removeTitleChangeListener( xListener );
1852 //=============================================================================
1853 // css.frame.XUntitledNumbers
1854 ::sal_Int32 SAL_CALL ODatabaseDocument::leaseNumber( const uno::Reference< uno::XInterface >& xComponent )
1855 throw (lang::IllegalArgumentException,
1856 uno::RuntimeException )
1858 DocumentGuard aGuard( *this );
1859 return impl_getUntitledHelper_throw(xComponent)->leaseNumber (xComponent);
1862 //=============================================================================
1863 // css.frame.XUntitledNumbers
1864 void SAL_CALL ODatabaseDocument::releaseNumber( ::sal_Int32 nNumber )
1865 throw (lang::IllegalArgumentException,
1866 uno::RuntimeException )
1868 DocumentGuard aGuard( *this );
1869 impl_getUntitledHelper_throw()->releaseNumber (nNumber);
1872 //=============================================================================
1873 // css.frame.XUntitledNumbers
1874 void SAL_CALL ODatabaseDocument::releaseNumberForComponent( const uno::Reference< uno::XInterface >& xComponent )
1875 throw (lang::IllegalArgumentException,
1876 uno::RuntimeException )
1878 DocumentGuard aGuard( *this );
1879 impl_getUntitledHelper_throw(xComponent)->releaseNumberForComponent (xComponent);
1882 //=============================================================================
1883 // css.frame.XUntitledNumbers
1884 ::rtl::OUString SAL_CALL ODatabaseDocument::getUntitledPrefix() throw (uno::RuntimeException)
1886 return ::rtl::OUString();/*RTL_CONSTASCII_USTRINGPARAM(" : "));*/
1889 //------------------------------------------------------------------
1890 //........................................................................
1891 } // namespace dbaccess
1892 //........................................................................