1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 "datasource.hxx"
35 #include "databasedocument.hxx"
36 #include "dbastrings.hrc"
37 #include "module_dba.hxx"
38 #include "documenteventexecutor.hxx"
39 #include "databasecontext.hxx"
40 #include "documentcontainer.hxx"
42 #include <comphelper/documentconstants.hxx>
43 #include <comphelper/namedvaluecollection.hxx>
44 #include <comphelper/enumhelper.hxx>
45 #include <comphelper/numberedcollection.hxx>
46 #include <comphelper/genericpropertyset.hxx>
47 #include <comphelper/property.hxx>
48 #include <svtools/saveopt.hxx>
50 #include <framework/titlehelper.hxx>
52 /** === begin UNO includes === **/
53 #include <com/sun/star/document/XExporter.hpp>
54 #include <com/sun/star/document/XFilter.hpp>
55 #include <com/sun/star/document/XImporter.hpp>
56 #include <com/sun/star/embed/EntryInitModes.hpp>
57 #include <com/sun/star/embed/XEmbedPersist.hpp>
58 #include <com/sun/star/embed/XTransactedObject.hpp>
59 #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
60 #include <com/sun/star/io/XActiveDataSource.hpp>
61 #include <com/sun/star/io/XSeekable.hpp>
62 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
63 #include <com/sun/star/task/ErrorCodeIOException.hpp>
64 #include <com/sun/star/task/XStatusIndicator.hpp>
65 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
66 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
67 #include <com/sun/star/view/XSelectionSupplier.hpp>
68 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
69 /** === end UNO includes === **/
71 #include <comphelper/documentconstants.hxx>
72 #include <comphelper/interaction.hxx>
73 #include <comphelper/enumhelper.hxx>
74 #include <comphelper/mediadescriptor.hxx>
75 #include <comphelper/namedvaluecollection.hxx>
76 #include <comphelper/numberedcollection.hxx>
77 #include <comphelper/storagehelper.hxx>
78 #include <cppuhelper/exc_hlp.hxx>
79 #include <framework/titlehelper.hxx>
80 #include <tools/debug.hxx>
81 #include <tools/diagnose_ex.h>
82 #include <tools/errcode.hxx>
83 #include <tools/urlobj.hxx>
85 #include <boost/bind.hpp>
91 #define MAP_LEN(x) x, sizeof(x) - 1
93 #define MAP_LEN(x) x, sizeof(x) - 1
95 using namespace ::com::sun::star::uno
;
96 using namespace ::com::sun::star::beans
;
97 using namespace ::com::sun::star::frame
;
98 using namespace ::com::sun::star::lang
;
99 using namespace ::com::sun::star::container
;
100 using namespace ::com::sun::star::document
;
101 using namespace ::com::sun::star::io
;
102 using namespace ::com::sun::star::util
;
103 using namespace ::com::sun::star::embed
;
104 using namespace ::com::sun::star::task
;
105 using namespace ::com::sun::star::view
;
106 using namespace ::com::sun::star::sdbc
;
107 using namespace ::com::sun::star
;
108 using namespace ::com::sun::star::xml::sax
;
109 using namespace ::com::sun::star::script
;
110 using namespace ::com::sun::star::script::provider
;
111 using namespace ::com::sun::star::ui
;
112 using namespace ::cppu
;
113 using namespace ::osl
;
115 using ::com::sun::star::awt::XWindow
;
117 //........................................................................
120 //........................................................................
122 //============================================================
124 //============================================================
125 //--------------------------------------------------------------------------
126 bool ViewMonitor::onControllerConnected( const Reference
< XController
>& _rxController
)
128 bool bFirstControllerEver
= ( m_bEverHadController
== false );
129 m_bEverHadController
= true;
131 m_xLastConnectedController
= _rxController
;
132 m_bLastIsFirstEverController
= bFirstControllerEver
;
134 return bFirstControllerEver
;
137 //--------------------------------------------------------------------------
138 void ViewMonitor::onSetCurrentController( const Reference
< XController
>& _rxController
)
140 // we interpret this as "loading the document (including UI) is finished",
141 // if and only if this is the controller which was last connected, and it was the
142 // first controller ever connected
143 bool bLoadFinished
= ( _rxController
== m_xLastConnectedController
) && m_bLastIsFirstEverController
;
145 // notify the respective events
147 m_rEventNotifier
.notifyDocumentEventAsync( m_bIsNewDocument
? "OnNew" : "OnLoad" );
150 //============================================================
151 //= ODatabaseDocument
152 //============================================================
153 DBG_NAME(ODatabaseDocument
)
154 //--------------------------------------------------------------------------
155 extern "C" void SAL_CALL
createRegistryInfo_ODatabaseDocument()
157 static ::dba::OAutoRegistration
< ODatabaseDocument
> aAutoRegistration
;
160 //--------------------------------------------------------------------------
161 ODatabaseDocument::ODatabaseDocument(const ::rtl::Reference
<ODatabaseModelImpl
>& _pImpl
)
162 :ModelDependentComponent( _pImpl
)
163 ,ODatabaseDocument_OfficeDocument( getMutex() )
164 ,m_aModifyListeners( getMutex() )
165 ,m_aCloseListener( getMutex() )
166 ,m_aStorageListeners( getMutex() )
167 ,m_pEventContainer( new DocumentEvents( *this, getMutex(), _pImpl
->getDocumentEvents() ) )
168 ,m_pEventExecutor( NULL
) // initialized below, ref-count-protected
169 ,m_aEventNotifier( *this, getMutex() )
170 ,m_aViewMonitor( m_aEventNotifier
)
171 ,m_eInitState( NotInitialized
)
173 ,m_bAllowDocumentScripting( false )
175 DBG_CTOR(ODatabaseDocument
,NULL
);
177 osl_incrementInterlockedCount( &m_refCount
);
179 impl_reparent_nothrow( m_xForms
);
180 impl_reparent_nothrow( m_xReports
);
181 impl_reparent_nothrow( m_pImpl
->m_xTableDefinitions
);
182 impl_reparent_nothrow( m_pImpl
->m_xCommandDefinitions
);
184 m_pEventExecutor
= new DocumentEventExecutor( m_pImpl
->m_aContext
, this );
186 osl_decrementInterlockedCount( &m_refCount
);
188 // if there previously was a document instance for the same Impl which was already initialized,
189 // then consider ourself initialized, too.
191 if ( m_pImpl
->hadInitializedDocument() )
193 impl_setInitialized();
194 m_bAllowDocumentScripting
= ( m_pImpl
->determineEmbeddedMacros() != ODatabaseModelImpl::eSubDocumentMacros
);
198 //--------------------------------------------------------------------------
199 ODatabaseDocument::~ODatabaseDocument()
201 DBG_DTOR(ODatabaseDocument
,NULL
);
202 if ( !ODatabaseDocument_OfficeDocument::rBHelper
.bInDispose
&& !ODatabaseDocument_OfficeDocument::rBHelper
.bDisposed
)
208 delete m_pEventContainer
, m_pEventContainer
= NULL
;
210 // -----------------------------------------------------------------------------
211 Any SAL_CALL
ODatabaseDocument::queryInterface( const Type
& _rType
) throw (RuntimeException
)
213 // strip XEmbeddedScripts and XScriptInvocationContext if we have any form/report
214 // which already contains macros. In this case, the database document itself is not
215 // allowed to contain macros, too.
216 if ( !m_bAllowDocumentScripting
217 && ( _rType
.equals( XEmbeddedScripts::static_type() )
218 || _rType
.equals( XScriptInvocationContext::static_type() )
223 Any aReturn
= ODatabaseDocument_OfficeDocument::queryInterface(_rType
);
224 if (!aReturn
.hasValue())
225 aReturn
= ODatabaseDocument_Title::queryInterface(_rType
);
228 //------------------------------------------------------------------------------
229 void SAL_CALL
ODatabaseDocument::acquire( ) throw ()
231 ODatabaseDocument_OfficeDocument::acquire();
234 //------------------------------------------------------------------------------
235 void SAL_CALL
ODatabaseDocument::release( ) throw ()
237 ODatabaseDocument_OfficeDocument::release();
239 //------------------------------------------------------------------------------
240 Sequence
< Type
> SAL_CALL
ODatabaseDocument::getTypes( ) throw (RuntimeException
)
242 Sequence
< Type
> aTypes
= ::comphelper::concatSequences(
243 ODatabaseDocument_OfficeDocument::getTypes(),
244 ODatabaseDocument_Title::getTypes()
247 // strip XEmbeddedScripts and XScriptInvocationContext if we have any form/report
248 // which already contains macros. In this case, the database document itself is not
249 // allowed to contain macros, too.
250 if ( !m_bAllowDocumentScripting
)
252 Sequence
< Type
> aStrippedTypes( aTypes
.getLength() );
253 Type
* pStripTo( aStrippedTypes
.getArray() );
255 // strip XEmbeddedScripts, and immediately re-assign to aTypes
256 aTypes
= Sequence
< Type
>(
258 ::std::remove_copy_if(
259 aTypes
.getConstArray(),
260 aTypes
.getConstArray() + aTypes
.getLength(),
262 ::std::bind2nd( ::std::equal_to
< Type
>(), XEmbeddedScripts::static_type() )
266 // strip XScriptInvocationContext, and immediately re-assign to aTypes
267 aTypes
= Sequence
< Type
>(
269 ::std::remove_copy_if(
270 aTypes
.getConstArray(),
271 aTypes
.getConstArray() + aTypes
.getLength(),
273 ::std::bind2nd( ::std::equal_to
< Type
>(), XScriptInvocationContext::static_type() )
280 //------------------------------------------------------------------------------
281 Sequence
< sal_Int8
> SAL_CALL
ODatabaseDocument::getImplementationId( ) throw (RuntimeException
)
283 static ::cppu::OImplementationId
* pId
= 0;
286 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
289 static ::cppu::OImplementationId aId
;
293 return pId
->getImplementationId();
296 // -----------------------------------------------------------------------------
298 // -----------------------------------------------------------------------------
301 // -----------------------------------------------------------------------------
302 Reference
< XStatusIndicator
> lcl_extractStatusIndicator( const ::comphelper::NamedValueCollection
& _rArguments
)
304 Reference
< XStatusIndicator
> xStatusIndicator
;
305 return _rArguments
.getOrDefault( "StatusIndicator", xStatusIndicator
);
308 // -----------------------------------------------------------------------------
309 static void lcl_triggerStatusIndicator_throw( const ::comphelper::NamedValueCollection
& _rArguments
, DocumentGuard
& _rGuard
, const bool _bStart
)
311 Reference
< XStatusIndicator
> xStatusIndicator( lcl_extractStatusIndicator( _rArguments
) );
312 if ( !xStatusIndicator
.is() )
319 xStatusIndicator
->start( ::rtl::OUString(), (sal_Int32
)1000000 );
321 xStatusIndicator
->end();
323 catch( const Exception
& )
325 DBG_UNHANDLED_EXCEPTION();
328 // note that |reset| can throw a DisposedException
331 // -----------------------------------------------------------------------------
332 static void lcl_extractStatusIndicator( const ::comphelper::NamedValueCollection
& _rArguments
, Sequence
< Any
>& _rCallArgs
)
334 Reference
< XStatusIndicator
> xStatusIndicator( lcl_extractStatusIndicator( _rArguments
) );
335 if ( !xStatusIndicator
.is() )
338 sal_Int32 nLength
= _rCallArgs
.getLength();
339 _rCallArgs
.realloc( nLength
+ 1 );
340 _rCallArgs
[ nLength
] <<= xStatusIndicator
;
343 // -----------------------------------------------------------------------------
344 static void lcl_extractAndStartStatusIndicator( const ::comphelper::NamedValueCollection
& _rArguments
, Reference
< XStatusIndicator
>& _rxStatusIndicator
,
345 Sequence
< Any
>& _rCallArgs
)
347 _rxStatusIndicator
= lcl_extractStatusIndicator( _rArguments
);
348 if ( !_rxStatusIndicator
.is() )
353 _rxStatusIndicator
->start( ::rtl::OUString(), (sal_Int32
)1000000 );
355 sal_Int32 nLength
= _rCallArgs
.getLength();
356 _rCallArgs
.realloc( nLength
+ 1 );
357 _rCallArgs
[ nLength
] <<= _rxStatusIndicator
;
359 catch( const Exception
& )
361 DBG_UNHANDLED_EXCEPTION();
365 // -----------------------------------------------------------------------------
366 static Sequence
< PropertyValue
> lcl_appendFileNameToDescriptor( const Sequence
< PropertyValue
>& _rDescriptor
, const ::rtl::OUString _rURL
)
368 ::comphelper::NamedValueCollection
aMediaDescriptor( _rDescriptor
);
369 if ( _rURL
.getLength() )
371 aMediaDescriptor
.put( "FileName", _rURL
);
372 aMediaDescriptor
.put( "URL", _rURL
);
374 return aMediaDescriptor
.getPropertyValues();
378 // -----------------------------------------------------------------------------
379 void ODatabaseDocument::impl_setInitialized()
381 m_eInitState
= Initialized
;
383 // start event notifications
384 m_aEventNotifier
.onDocumentInitialized();
387 // -----------------------------------------------------------------------------
388 void ODatabaseDocument::impl_reset_nothrow()
392 m_pImpl
->clearConnections();
393 m_pImpl
->disposeStorages();
394 m_pImpl
->resetRootStroage();
396 clearObjectContainer( m_xForms
);
397 clearObjectContainer( m_xReports
);
398 clearObjectContainer( m_pImpl
->m_xTableDefinitions
);
399 clearObjectContainer( m_pImpl
->m_xCommandDefinitions
);
401 m_eInitState
= NotInitialized
;
405 catch(const Exception
&)
407 DBG_UNHANDLED_EXCEPTION();
409 m_pImpl
->m_bDocumentReadOnly
= sal_False
;
412 // -----------------------------------------------------------------------------
413 void ODatabaseDocument::impl_import_nolck_throw( const ::comphelper::ComponentContext _rContext
, const Reference
< XInterface
>& _rxTargetComponent
,
414 const ::comphelper::NamedValueCollection
& _rResource
)
416 Sequence
< Any
> aFilterArgs
;
417 Reference
< XStatusIndicator
> xStatusIndicator
;
418 lcl_extractAndStartStatusIndicator( _rResource
, xStatusIndicator
, aFilterArgs
);
420 /** property map for import info set */
421 comphelper::PropertyMapEntry aExportInfoMap
[] =
423 { MAP_LEN( "BaseURI"), 0,&::getCppuType( (::rtl::OUString
*)0 ),beans::PropertyAttribute::MAYBEVOID
, 0 },
424 { MAP_LEN( "StreamName"), 0,&::getCppuType( (::rtl::OUString
*)0 ),beans::PropertyAttribute::MAYBEVOID
, 0 },
425 { NULL
, 0, 0, NULL
, 0, 0 }
427 uno::Reference
< beans::XPropertySet
> xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap
) ) );
428 xInfoSet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rResource
.getOrDefault("URL",::rtl::OUString())));
429 xInfoSet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml"))));
431 const sal_Int32 nCount
= aFilterArgs
.getLength();
432 aFilterArgs
.realloc(nCount
+ 1);
433 aFilterArgs
[nCount
] <<= xInfoSet
;
435 Reference
< XImporter
> xImporter(
436 _rContext
.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterArgs
),
439 Reference
< XComponent
> xComponent( _rxTargetComponent
, UNO_QUERY_THROW
);
440 xImporter
->setTargetDocument( xComponent
);
442 Reference
< XFilter
> xFilter( xImporter
, UNO_QUERY_THROW
);
443 xFilter
->filter( ODatabaseModelImpl::stripLoadArguments( _rResource
) );
445 if ( xStatusIndicator
.is() )
446 xStatusIndicator
->end();
449 // -----------------------------------------------------------------------------
450 void SAL_CALL
ODatabaseDocument::initNew( ) throw (DoubleInitializationException
, IOException
, Exception
, RuntimeException
)
453 DocumentGuard
aGuard( *this, DocumentGuard::InitMethod
);
455 impl_reset_nothrow();
457 impl_setInitializing();
459 // create a temporary storage
460 Reference
< XStorage
> xTempStor( ::comphelper::OStorageHelper::GetTemporaryStorage(
461 m_pImpl
->m_aContext
.getLegacyServiceFactory() ) );
464 impl_storeToStorage_throw( xTempStor
, Sequence
< PropertyValue
>(), aGuard
);
466 // let the impl know we're now based on this storage
467 m_pImpl
->switchToStorage( xTempStor
);
469 // for the newly created document, allow document-wide scripting
470 m_bAllowDocumentScripting
= true;
472 impl_setInitialized();
474 m_aEventNotifier
.notifyDocumentEventAsync( "OnTitleChanged" );
476 impl_setModified_nothrow( sal_False
, aGuard
);
479 m_aEventNotifier
.notifyDocumentEvent( "OnCreate" );
481 impl_notifyStorageChange_nolck_nothrow( xTempStor
);
484 // -----------------------------------------------------------------------------
485 void SAL_CALL
ODatabaseDocument::load( const Sequence
< PropertyValue
>& _Arguments
) throw (DoubleInitializationException
, IOException
, Exception
, RuntimeException
)
488 DocumentGuard
aGuard( *this, DocumentGuard::InitMethod
);
490 impl_reset_nothrow();
492 ::comphelper::NamedValueCollection
aResource( _Arguments
);
493 if ( aResource
.has( "FileName" ) && !aResource
.has( "URL" ) )
494 // FileName is the compatibility name for URL, so we might have clients passing
495 // a FileName only. However, some of our code works with the URL only, so ensure
497 aResource
.put( "URL", aResource
.get( "FileName" ) );
498 if ( aResource
.has( "URL" ) && !aResource
.has( "FileName" ) )
499 // similar ... just in case there is legacy code which expects a FileName only
500 aResource
.put( "FileName", aResource
.get( "URL" ) );
502 // now that somebody (perhaps) told us an macro execution mode, remember it as
503 // ImposedMacroExecMode
504 m_pImpl
->setImposedMacroExecMode(
505 aResource
.getOrDefault( "MacroExecutionMode", m_pImpl
->getImposedMacroExecMode() ) );
507 impl_setInitializing();
511 impl_import_nolck_throw( m_pImpl
->m_aContext
, *this, aResource
);
514 catch( const Exception
& )
516 impl_reset_nothrow();
519 // tell our view monitor that the document has been loaded - this way it will fire the proper
520 // event (OnLoad instead of OnCreate) later on
521 m_aViewMonitor
.onLoadedDocument();
523 // note that we do *not* call impl_setInitialized() here: The initialization is only complete
524 // when the XModel::attachResource has been called, not sooner.
526 impl_setModified_nothrow( sal_False
, aGuard
);
530 // -----------------------------------------------------------------------------
532 sal_Bool SAL_CALL
ODatabaseDocument::attachResource( const ::rtl::OUString
& _rURL
, const Sequence
< PropertyValue
>& _rArguments
) throw (RuntimeException
)
534 DocumentGuard
aGuard( *this, DocumentGuard::MethodUsedDuringInit
);
536 if ( ( _rURL
== getURL() )
537 && ( _rArguments
.getLength() == 1 )
538 && ( _rArguments
[0].Name
.compareToAscii( "BreakMacroSignature" ) == 0 )
541 // this is a BAD hack of the Basic importer code ... there should be a dedicated API for this,
542 // not this bad mis-using of existing interfaces
544 // (we do not support macro signatures, so we can ignore this call)
547 m_pImpl
->attachResource( _rURL
, _rArguments
);
549 if ( impl_isInitializing() )
550 { // this means we've just been loaded, and this is the attachResource call which follows
552 impl_setInitialized();
554 // determine whether the document as a whole, or sub documents, have macros. Especially the latter
555 // controls the availability of our XEmbeddedScripts and XScriptInvocationContext interfaces, and we
556 // should know this before anybody actually uses the object.
557 m_bAllowDocumentScripting
= ( m_pImpl
->determineEmbeddedMacros() != ODatabaseModelImpl::eSubDocumentMacros
);
559 m_aEventNotifier
.notifyDocumentEvent( "OnLoadFinished" );
565 // -----------------------------------------------------------------------------
566 ::rtl::OUString SAL_CALL
ODatabaseDocument::getURL( ) throw (RuntimeException
)
568 DocumentGuard
aGuard( *this, DocumentGuard::MethodWithoutInit
);
569 return m_pImpl
->getURL();
572 // -----------------------------------------------------------------------------
573 Sequence
< PropertyValue
> SAL_CALL
ODatabaseDocument::getArgs( ) throw (RuntimeException
)
575 DocumentGuard
aGuard( *this, DocumentGuard::MethodWithoutInit
);
576 return m_pImpl
->getResource();
579 // -----------------------------------------------------------------------------
580 void SAL_CALL
ODatabaseDocument::connectController( const Reference
< XController
>& _xController
) throw (RuntimeException
)
582 DocumentGuard
aGuard( *this );
584 m_aControllers
.push_back( _xController
);
586 m_aEventNotifier
.notifyDocumentEventAsync( "OnViewCreated", Reference
< XController2
>( _xController
, UNO_QUERY
) );
588 bool bFirstControllerEver
= m_aViewMonitor
.onControllerConnected( _xController
);
589 if ( !bFirstControllerEver
)
592 // check/adjust our macro mode.
593 m_pImpl
->checkMacrosOnLoading();
596 // -----------------------------------------------------------------------------
597 void SAL_CALL
ODatabaseDocument::disconnectController( const Reference
< XController
>& _xController
) throw (RuntimeException
)
599 bool bNotifyViewClosed
= false;
600 bool bLastControllerGone
= false;
601 bool bIsClosing
= false;
605 DocumentGuard
aGuard( *this );
607 Controllers::iterator pos
= ::std::find( m_aControllers
.begin(), m_aControllers
.end(), _xController
);
608 OSL_ENSURE( pos
!= m_aControllers
.end(), "ODatabaseDocument::disconnectController: don't know this controller!" );
609 if ( pos
!= m_aControllers
.end() )
611 m_aControllers
.erase( pos
);
612 bNotifyViewClosed
= true;
615 if ( m_xCurrentController
== _xController
)
616 m_xCurrentController
= NULL
;
618 bLastControllerGone
= m_aControllers
.empty();
619 bIsClosing
= m_bClosing
;
623 if ( bNotifyViewClosed
)
624 m_aEventNotifier
.notifyDocumentEvent( "OnViewClosed", Reference
< XController2
>( _xController
, UNO_QUERY
) );
626 if ( bLastControllerGone
&& !bIsClosing
)
628 // if this was the last view, close the document as a whole
629 // #i51157# / 2006-03-16 / frank.schoenheit@sun.com
634 catch( const CloseVetoException
& )
636 // okay, somebody vetoed and took ownership
641 // -----------------------------------------------------------------------------
642 void SAL_CALL
ODatabaseDocument::lockControllers( ) throw (RuntimeException
)
644 DocumentGuard
aGuard( *this );
646 ++m_pImpl
->m_nControllerLockCount
;
649 // -----------------------------------------------------------------------------
650 void SAL_CALL
ODatabaseDocument::unlockControllers( ) throw (RuntimeException
)
652 DocumentGuard
aGuard( *this );
654 --m_pImpl
->m_nControllerLockCount
;
657 // -----------------------------------------------------------------------------
658 sal_Bool SAL_CALL
ODatabaseDocument::hasControllersLocked( ) throw (RuntimeException
)
660 DocumentGuard
aGuard( *this );
662 return m_pImpl
->m_nControllerLockCount
!= 0;
665 // -----------------------------------------------------------------------------
666 Reference
< XController
> SAL_CALL
ODatabaseDocument::getCurrentController() throw (RuntimeException
)
668 DocumentGuard
aGuard( *this );
670 return m_xCurrentController
.is() ? m_xCurrentController
: ( m_aControllers
.empty() ? Reference
< XController
>() : *m_aControllers
.begin() );
673 // -----------------------------------------------------------------------------
674 void SAL_CALL
ODatabaseDocument::setCurrentController( const Reference
< XController
>& _xController
) throw (NoSuchElementException
, RuntimeException
)
676 DocumentGuard
aGuard( *this );
678 m_xCurrentController
= _xController
;
680 m_aViewMonitor
.onSetCurrentController( _xController
);
682 // -----------------------------------------------------------------------------
683 Reference
< XInterface
> SAL_CALL
ODatabaseDocument::getCurrentSelection( ) throw (RuntimeException
)
685 DocumentGuard
aGuard( *this );
687 Reference
< XInterface
> xRet
;
688 Reference
< XSelectionSupplier
> xDocView( getCurrentController(), UNO_QUERY
);
690 xRet
.set(xDocView
->getSelection(),UNO_QUERY
);
694 // -----------------------------------------------------------------------------
697 sal_Bool SAL_CALL
ODatabaseDocument::hasLocation( ) throw (RuntimeException
)
699 return getLocation().getLength() > 0;
701 // -----------------------------------------------------------------------------
702 ::rtl::OUString SAL_CALL
ODatabaseDocument::getLocation( ) throw (RuntimeException
)
704 DocumentGuard
aGuard( *this, DocumentGuard::MethodWithoutInit
);
705 return m_pImpl
->getURL();
707 // -----------------------------------------------------------------------------
708 sal_Bool SAL_CALL
ODatabaseDocument::isReadonly( ) throw (RuntimeException
)
710 DocumentGuard
aGuard( *this, DocumentGuard::MethodWithoutInit
);
711 return m_pImpl
->m_bDocumentReadOnly
;
713 // -----------------------------------------------------------------------------
714 void SAL_CALL
ODatabaseDocument::store( ) throw (IOException
, RuntimeException
)
716 DocumentGuard
aGuard( *this );
718 if ( m_pImpl
->getDocFileLocation() == m_pImpl
->getURL() )
719 if ( m_pImpl
->m_bDocumentReadOnly
)
722 impl_storeAs_throw( m_pImpl
->getURL(), m_pImpl
->getResource(), SAVE
, aGuard
);
725 // -----------------------------------------------------------------------------
726 void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString
& _rURL
, const Sequence
< PropertyValue
>& _rArguments
,
727 const StoreType _eType
, DocumentGuard
& _rGuard
)
729 OSL_PRECOND( ( _eType
== SAVE
) || ( _eType
== SAVE_AS
),
730 "ODatabaseDocument::impl_storeAs_throw: you introduced a new type which cannot be handled here!" );
732 // if we're in the process of initializing the document (which effectively means it is an implicit
733 // initialization triggered in storeAsURL), the we do not notify events, since to an observer, the SaveAs
734 // should not be noticable
735 bool bIsInitializationProcess
= impl_isInitializing();
737 if ( !bIsInitializationProcess
)
740 m_aEventNotifier
.notifyDocumentEvent( _eType
== SAVE
? "OnSave" : "OnSaveAs", NULL
, makeAny( _rURL
) );
744 Reference
< XStorage
> xNewRootStorage
;
745 // will be non-NULL if our storage changed
749 ModifyLock
aLock( *this );
750 // ignore all changes of our "modified" state during storing
752 sal_Bool bLocationChanged
= ( _rURL
!= m_pImpl
->getDocFileLocation() );
753 if ( bLocationChanged
)
755 // create storage for target URL
756 Reference
< XStorage
> xTargetStorage( impl_createStorageFor_throw( _rURL
) );
758 if ( m_pImpl
->isEmbeddedDatabase() )
759 m_pImpl
->clearConnections();
762 m_pImpl
->commitEmbeddedStorage();
763 m_pImpl
->commitStorages();
765 // copy own storage to target storage
766 Reference
< XStorage
> xCurrentStorage( m_pImpl
->getRootStorage() );
767 if ( xCurrentStorage
.is() )
768 xCurrentStorage
->copyToStorage( xTargetStorage
);
770 m_pImpl
->disposeStorages();
772 xNewRootStorage
= m_pImpl
->switchToStorage( xTargetStorage
);
774 m_pImpl
->m_bDocumentReadOnly
= sal_False
;
777 // store to current storage
778 Reference
< XStorage
> xCurrentStorage( m_pImpl
->getOrCreateRootStorage(), UNO_QUERY_THROW
);
779 Sequence
< PropertyValue
> aMediaDescriptor( lcl_appendFileNameToDescriptor( _rArguments
, _rURL
) );
780 impl_storeToStorage_throw( xCurrentStorage
, aMediaDescriptor
, _rGuard
);
782 // success - tell our impl
783 m_pImpl
->attachResource( _rURL
, aMediaDescriptor
);
785 // if we are in an initialization process, then this is finished, now that we stored the document
786 if ( bIsInitializationProcess
)
787 impl_setInitialized();
789 catch( const Exception
& )
791 // notify the failure
792 if ( !bIsInitializationProcess
)
793 m_aEventNotifier
.notifyDocumentEventAsync( _eType
== SAVE
? "OnSaveFailed" : "OnSaveAsFailed", NULL
, makeAny( _rURL
) );
797 // notify the document event
798 if ( !bIsInitializationProcess
)
799 m_aEventNotifier
.notifyDocumentEventAsync( _eType
== SAVE
? "OnSaveDone" : "OnSaveAsDone", NULL
, makeAny( _rURL
) );
801 // reset our "modified" flag, and clear the guard
802 impl_setModified_nothrow( sal_False
, _rGuard
);
805 // notify storage listeners
806 if ( xNewRootStorage
.is() )
807 impl_notifyStorageChange_nolck_nothrow( xNewRootStorage
);
810 // -----------------------------------------------------------------------------
811 Reference
< XStorage
> ODatabaseDocument::impl_createStorageFor_throw( const ::rtl::OUString
& _rURL
) const
813 Sequence
<Any
> aParam(2);
815 aParam
[1] <<= ElementModes::READWRITE
| ElementModes::TRUNCATE
;
817 Reference
< XSingleServiceFactory
> xStorageFactory( m_pImpl
->createStorageFactory(), UNO_SET_THROW
);
818 return Reference
< XStorage
>( xStorageFactory
->createInstanceWithArguments( aParam
), UNO_QUERY_THROW
);
821 // -----------------------------------------------------------------------------
822 void SAL_CALL
ODatabaseDocument::storeAsURL( const ::rtl::OUString
& _rURL
, const Sequence
< PropertyValue
>& _rArguments
) throw (IOException
, RuntimeException
)
825 DocumentGuard
aGuard( *this, DocumentGuard::MethodWithoutInit
);
827 // Normally, a document initialization is done via XLoadable::load or XLoadable::initNew. For convenience
828 // reasons, and to not break existing API clients, it's allowed to call storeAsURL without having initialized
829 // the document, in which case the initialization will be done implicitly.
830 bool bImplicitInitialization
= !impl_isInitialized();
831 // implicit initialization while another initialization is just running is not possible
832 if ( bImplicitInitialization
&& impl_isInitializing() )
833 throw DoubleInitializationException();
835 if ( bImplicitInitialization
)
836 impl_setInitializing();
840 impl_storeAs_throw( _rURL
, _rArguments
, SAVE_AS
, aGuard
);
843 // impl_storeAs_throw cleared the lock on our mutex, but the below lines need this lock
847 // our title might have changed, potentially at least
848 // Sadly, we cannot check this: Calling getTitle here and now would not deliver
849 // an up-to-date result, as the call is delegated to our TitleHelper instance, which itself
850 // updates its title only if it gets the OnSaveAsDone event (which was sent asynchronously
851 // by impl_storeAs_throw). So, we simply notify always, and also asynchronously
852 m_aEventNotifier
.notifyDocumentEventAsync( "OnTitleChanged" );
854 catch( const Exception
& )
856 impl_reset_nothrow();
860 if ( bImplicitInitialization
)
861 m_bAllowDocumentScripting
= true;
866 if ( bImplicitInitialization
)
867 m_aEventNotifier
.notifyDocumentEvent( "OnCreate" );
870 // -----------------------------------------------------------------------------
871 void ODatabaseDocument::impl_storeToStorage_throw( const Reference
< XStorage
>& _rxTargetStorage
, const Sequence
< PropertyValue
>& _rMediaDescriptor
,
872 DocumentGuard
& _rDocGuard
) const
874 if ( !_rxTargetStorage
.is() )
875 throw IllegalArgumentException( ::rtl::OUString(), *const_cast< ODatabaseDocument
* >( this ), 1 );
878 throw DisposedException( ::rtl::OUString(), *const_cast< ODatabaseDocument
* >( this ) );
883 m_pImpl
->commitEmbeddedStorage();
884 m_pImpl
->commitStorages();
886 // copy own storage to target storage
887 if ( impl_isInitialized() )
889 Reference
< XStorage
> xCurrentStorage( m_pImpl
->getOrCreateRootStorage(), UNO_QUERY_THROW
);
890 if ( xCurrentStorage
!= _rxTargetStorage
)
891 xCurrentStorage
->copyToStorage( _rxTargetStorage
);
894 // write into target storage
895 ::comphelper::NamedValueCollection
aWriteArgs( _rMediaDescriptor
);
896 lcl_triggerStatusIndicator_throw( aWriteArgs
, _rDocGuard
, true );
897 impl_writeStorage_throw( _rxTargetStorage
, aWriteArgs
);
898 lcl_triggerStatusIndicator_throw( aWriteArgs
, _rDocGuard
, false );
900 // commit target storage
901 OSL_VERIFY( ODatabaseModelImpl::commitStorageIfWriteable( _rxTargetStorage
) );
903 catch( const IOException
& ) { throw; }
904 catch( const RuntimeException
& ) { throw; }
905 catch ( const Exception
& e
)
907 throw IOException( e
.Message
, *const_cast< ODatabaseDocument
* >( this ) );
911 // -----------------------------------------------------------------------------
912 void SAL_CALL
ODatabaseDocument::storeToURL( const ::rtl::OUString
& _rURL
, const Sequence
< PropertyValue
>& _rArguments
) throw (IOException
, RuntimeException
)
914 DocumentGuard
aGuard( *this );
915 ModifyLock
aLock( *this );
919 m_aEventNotifier
.notifyDocumentEvent( "OnSaveTo", NULL
, makeAny( _rURL
) );
925 // create storage for target URL
926 Reference
< XStorage
> xTargetStorage( impl_createStorageFor_throw( _rURL
) );
928 // extend media descriptor with URL
929 Sequence
< PropertyValue
> aMediaDescriptor( lcl_appendFileNameToDescriptor( _rArguments
, _rURL
) );
931 // store to this storage
932 impl_storeToStorage_throw( xTargetStorage
, aMediaDescriptor
, aGuard
);
934 catch( const Exception
& )
936 m_aEventNotifier
.notifyDocumentEventAsync( "OnSaveToFailed", NULL
, makeAny( _rURL
) );
940 m_aEventNotifier
.notifyDocumentEventAsync( "OnSaveToDone", NULL
, makeAny( _rURL
) );
943 // -----------------------------------------------------------------------------
944 // XModifyBroadcaster
945 void SAL_CALL
ODatabaseDocument::addModifyListener( const Reference
< XModifyListener
>& _xListener
) throw (RuntimeException
)
947 DocumentGuard
aGuard( *this );
948 m_aModifyListeners
.addInterface(_xListener
);
951 // -----------------------------------------------------------------------------
952 void SAL_CALL
ODatabaseDocument::removeModifyListener( const Reference
< XModifyListener
>& _xListener
) throw (RuntimeException
)
954 DocumentGuard
aGuard( *this );
955 m_aModifyListeners
.removeInterface(_xListener
);
958 // -----------------------------------------------------------------------------
960 sal_Bool SAL_CALL
ODatabaseDocument::isModified( ) throw (RuntimeException
)
962 DocumentGuard
aGuard( *this );
964 return m_pImpl
->m_bModified
;
967 // -----------------------------------------------------------------------------
968 void SAL_CALL
ODatabaseDocument::setModified( sal_Bool _bModified
) throw (PropertyVetoException
, RuntimeException
)
970 DocumentGuard
aGuard( *this, DocumentGuard::MethodWithoutInit
);
971 if ( impl_isInitialized() )
972 impl_setModified_nothrow( _bModified
, aGuard
);
973 // it's allowed to call setModified without the document being initialized already. In this case,
974 // we simply ignore the call - when the initialization is finished, the respective code will set
975 // a proper "modified" flag
978 // -----------------------------------------------------------------------------
979 void ODatabaseDocument::impl_setModified_nothrow( sal_Bool _bModified
, DocumentGuard
& _rGuard
)
982 bool bModifiedChanged
= ( m_pImpl
->m_bModified
!= _bModified
) && ( !m_pImpl
->isModifyLocked() );
984 if ( bModifiedChanged
)
986 m_pImpl
->m_bModified
= _bModified
;
987 m_aEventNotifier
.notifyDocumentEventAsync( "OnModifyChanged" );
992 if ( bModifiedChanged
)
994 lang::EventObject
aEvent( *this );
995 m_aModifyListeners
.notifyEach( &XModifyListener::modified
, aEvent
);
999 // -----------------------------------------------------------------------------
1000 // ::com::sun::star::document::XEventBroadcaster
1001 void SAL_CALL
ODatabaseDocument::addEventListener(const uno::Reference
< document::XEventListener
>& _Listener
) throw (uno::RuntimeException
)
1003 m_aEventNotifier
.addLegacyEventListener( _Listener
);
1006 // -----------------------------------------------------------------------------
1007 void SAL_CALL
ODatabaseDocument::removeEventListener( const uno::Reference
< document::XEventListener
>& _Listener
) throw (uno::RuntimeException
)
1009 m_aEventNotifier
.removeLegacyEventListener( _Listener
);
1012 // -----------------------------------------------------------------------------
1013 void SAL_CALL
ODatabaseDocument::addDocumentEventListener( const Reference
< XDocumentEventListener
>& _Listener
) throw (RuntimeException
)
1015 m_aEventNotifier
.addDocumentEventListener( _Listener
);
1018 // -----------------------------------------------------------------------------
1019 void SAL_CALL
ODatabaseDocument::removeDocumentEventListener( const Reference
< XDocumentEventListener
>& _Listener
) throw (RuntimeException
)
1021 m_aEventNotifier
.removeDocumentEventListener( _Listener
);
1024 // -----------------------------------------------------------------------------
1025 void SAL_CALL
ODatabaseDocument::notifyDocumentEvent( const ::rtl::OUString
& _EventName
, const Reference
< XController2
>& _ViewController
, const Any
& _Supplement
) throw (IllegalArgumentException
, NoSupportException
, RuntimeException
)
1027 if ( !_EventName
.getLength() )
1028 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
1031 DocumentGuard
aGuard( *this );
1033 if ( !DocumentEvents::needsSynchronousNotification( _EventName
) )
1035 m_aEventNotifier
.notifyDocumentEventAsync( _EventName
, _ViewController
, _Supplement
);
1041 m_aEventNotifier
.notifyDocumentEvent( _EventName
, _ViewController
, _Supplement
);
1044 // -----------------------------------------------------------------------------
1045 Sequence
< PropertyValue
> SAL_CALL
ODatabaseDocument::getPrinter( ) throw (RuntimeException
)
1047 DBG_ERROR( "ODatabaseDocument::getPrinter: not supported!" );
1048 return Sequence
< PropertyValue
>();
1051 // -----------------------------------------------------------------------------
1052 void SAL_CALL
ODatabaseDocument::setPrinter( const Sequence
< PropertyValue
>& /*aPrinter*/ ) throw (IllegalArgumentException
, RuntimeException
)
1054 DBG_ERROR( "ODatabaseDocument::setPrinter: not supported!" );
1057 // -----------------------------------------------------------------------------
1058 void SAL_CALL
ODatabaseDocument::print( const Sequence
< PropertyValue
>& /*xOptions*/ ) throw (IllegalArgumentException
, RuntimeException
)
1060 DBG_ERROR( "ODatabaseDocument::print: not supported!" );
1063 // -----------------------------------------------------------------------------
1064 void ODatabaseDocument::impl_reparent_nothrow( const WeakReference
< XNameAccess
>& _rxContainer
)
1066 Reference
< XChild
> xChild( _rxContainer
.get(), UNO_QUERY
);
1068 xChild
->setParent( *this );
1070 // -----------------------------------------------------------------------------
1071 void ODatabaseDocument::clearObjectContainer( WeakReference
< XNameAccess
>& _rxContainer
)
1073 Reference
< XNameAccess
> xContainer
= _rxContainer
;
1074 ::comphelper::disposeComponent( xContainer
);
1076 Reference
< XChild
> xChild( _rxContainer
.get(),UNO_QUERY
);
1078 xChild
->setParent( NULL
);
1079 _rxContainer
= Reference
< XNameAccess
>();
1081 // -----------------------------------------------------------------------------
1082 Reference
< XNameAccess
> ODatabaseDocument::impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType _eType
)
1084 if ( ( _eType
!= ODatabaseModelImpl::E_FORM
) && ( _eType
!= ODatabaseModelImpl::E_REPORT
) )
1085 throw IllegalArgumentException();
1087 bool bFormsContainer
= _eType
== ODatabaseModelImpl::E_FORM
;
1089 WeakReference
< XNameAccess
>& rContainerRef( bFormsContainer
? m_xForms
: m_xReports
);
1090 Reference
< XNameAccess
> xContainer
= rContainerRef
;
1091 if ( !xContainer
.is() )
1093 TContentPtr
& rContainerData( m_pImpl
->getObjectContainer( _eType
) );
1094 rContainerRef
= xContainer
= new ODocumentContainer( m_pImpl
->m_aContext
.getLegacyServiceFactory(), *this, rContainerData
, bFormsContainer
);
1095 impl_reparent_nothrow( xContainer
);
1100 // -----------------------------------------------------------------------------
1101 void ODatabaseDocument::impl_closeControllerFrames_nolck_throw( sal_Bool _bDeliverOwnership
)
1103 Controllers aCopy
= m_aControllers
;
1105 Controllers::iterator aEnd
= aCopy
.end();
1106 for ( Controllers::iterator aIter
= aCopy
.begin(); aIter
!= aEnd
; ++aIter
)
1113 Reference
< XCloseable
> xFrame( (*aIter
)->getFrame(), UNO_QUERY
);
1115 xFrame
->close( _bDeliverOwnership
);
1117 catch( const CloseVetoException
& ) { throw; }
1118 catch( const Exception
& )
1120 DBG_UNHANDLED_EXCEPTION();
1125 // -----------------------------------------------------------------------------
1126 struct DisposeControllerFrame
: public ::std::unary_function
< Reference
< XController
>, void >
1128 void operator()( const Reference
< XController
>& _rxController
) const
1132 if ( !_rxController
.is() )
1135 Reference
< XFrame
> xFrame( _rxController
->getFrame() );
1136 ::comphelper::disposeComponent( xFrame
);
1138 catch( const Exception
& )
1140 DBG_UNHANDLED_EXCEPTION();
1145 // -----------------------------------------------------------------------------
1146 void ODatabaseDocument::impl_disposeControllerFrames_nothrow()
1149 aCopy
.swap( m_aControllers
); // ensure m_aControllers is empty afterwards
1150 ::std::for_each( aCopy
.begin(), aCopy
.end(), DisposeControllerFrame() );
1153 // -----------------------------------------------------------------------------
1154 void SAL_CALL
ODatabaseDocument::close( sal_Bool _bDeliverOwnership
) throw (CloseVetoException
, RuntimeException
)
1156 // nearly everything below can/must be done without our mutex locked, the below is just for
1157 // the checks for being disposed and the like
1160 DocumentGuard
aGuard( *this );
1167 // allow listeners to veto
1168 lang::EventObject
aEvent( *this );
1169 m_aCloseListener
.forEach
< XCloseListener
>(
1170 boost::bind( &XCloseListener::queryClosing
, _1
, boost::cref( aEvent
), boost::cref( _bDeliverOwnership
) ) );
1172 // notify that we're going to unload
1173 m_aEventNotifier
.notifyDocumentEvent( "OnPrepareUnload" );
1175 impl_closeControllerFrames_nolck_throw( _bDeliverOwnership
);
1177 m_aCloseListener
.notifyEach( &XCloseListener::notifyClosing
, (const lang::EventObject
&)aEvent
);
1181 catch ( const Exception
& )
1183 ::osl::MutexGuard
aGuard( m_aMutex
);
1189 ::osl::MutexGuard
aGuard( m_aMutex
);
1193 // -----------------------------------------------------------------------------
1194 void SAL_CALL
ODatabaseDocument::addCloseListener( const Reference
< ::com::sun::star::util::XCloseListener
>& Listener
) throw (RuntimeException
)
1196 DocumentGuard
aGuard( *this );
1197 m_aCloseListener
.addInterface(Listener
);
1199 // -----------------------------------------------------------------------------
1200 void SAL_CALL
ODatabaseDocument::removeCloseListener( const Reference
< ::com::sun::star::util::XCloseListener
>& Listener
) throw (RuntimeException
)
1202 DocumentGuard
aGuard( *this );
1203 m_aCloseListener
.removeInterface(Listener
);
1205 // -----------------------------------------------------------------------------
1206 Reference
< XNameAccess
> SAL_CALL
ODatabaseDocument::getFormDocuments( ) throw (RuntimeException
)
1208 DocumentGuard
aGuard( *this, DocumentGuard::MethodUsedDuringInit
);
1209 return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_FORM
);
1211 // -----------------------------------------------------------------------------
1212 Reference
< XNameAccess
> SAL_CALL
ODatabaseDocument::getReportDocuments( ) throw (RuntimeException
)
1214 DocumentGuard
aGuard( *this, DocumentGuard::MethodUsedDuringInit
);
1215 return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_REPORT
);
1218 // -----------------------------------------------------------------------------
1219 void ODatabaseDocument::WriteThroughComponent( const Reference
< XComponent
>& xComponent
, const sal_Char
* pStreamName
,
1220 const sal_Char
* pServiceName
, const Sequence
< Any
>& _rArguments
, const Sequence
< PropertyValue
>& rMediaDesc
,
1221 const Reference
<XStorage
>& _xStorageToSaveTo
) const
1223 OSL_ENSURE( pStreamName
, "Need stream name!" );
1224 OSL_ENSURE( pServiceName
, "Need service name!" );
1227 ::rtl::OUString sStreamName
= ::rtl::OUString::createFromAscii( pStreamName
);
1228 Reference
< XStream
> xStream
= _xStorageToSaveTo
->openStreamElement( sStreamName
, ElementModes::READWRITE
| ElementModes::TRUNCATE
);
1229 if ( !xStream
.is() )
1232 Reference
< XOutputStream
> xOutputStream( xStream
->getOutputStream() );
1233 OSL_ENSURE( xOutputStream
.is(), "Can't create output stream in package!" );
1234 if ( !xOutputStream
.is() )
1237 Reference
< XSeekable
> xSeek( xOutputStream
, UNO_QUERY
);
1241 Reference
< XPropertySet
> xStreamProp( xOutputStream
, UNO_QUERY_THROW
);
1242 xStreamProp
->setPropertyValue( INFO_MEDIATYPE
, makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/xml" ) ) ) );
1243 xStreamProp
->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), makeAny( (sal_Bool
)sal_True
) );
1246 WriteThroughComponent( xOutputStream
, xComponent
, pServiceName
, _rArguments
, rMediaDesc
);
1249 void ODatabaseDocument::WriteThroughComponent( const Reference
< XOutputStream
>& xOutputStream
,
1250 const Reference
< XComponent
>& xComponent
, const sal_Char
* pServiceName
, const Sequence
< Any
>& _rArguments
,
1251 const Sequence
< PropertyValue
>& rMediaDesc
) const
1253 OSL_ENSURE( xOutputStream
.is(), "I really need an output stream!" );
1254 OSL_ENSURE( xComponent
.is(), "Need component!" );
1255 OSL_ENSURE( NULL
!= pServiceName
, "Need component name!" );
1258 Reference
< XActiveDataSource
> xSaxWriter
;
1259 OSL_VERIFY( m_pImpl
->m_aContext
.createComponent( "com.sun.star.xml.sax.Writer", xSaxWriter
) );
1260 if ( !xSaxWriter
.is() )
1263 // connect XML writer to output stream
1264 xSaxWriter
->setOutputStream( xOutputStream
);
1266 // prepare arguments (prepend doc handler to given arguments)
1267 Reference
< XDocumentHandler
> xDocHandler( xSaxWriter
,UNO_QUERY
);
1268 Sequence
<Any
> aArgs( 1 + _rArguments
.getLength() );
1269 aArgs
[0] <<= xDocHandler
;
1270 for ( sal_Int32 i
= 0; i
< _rArguments
.getLength(); ++i
)
1271 aArgs
[ i
+1 ] = _rArguments
[i
];
1273 // get filter component
1274 Reference
< XExporter
> xExporter
;
1275 OSL_VERIFY( m_pImpl
->m_aContext
.createComponentWithArguments( pServiceName
, aArgs
, xExporter
) );
1276 if ( !xExporter
.is() )
1279 // connect model and filter
1280 xExporter
->setSourceDocument( xComponent
);
1283 Reference
< XFilter
> xFilter( xExporter
, UNO_QUERY_THROW
);
1284 xFilter
->filter( rMediaDesc
);
1287 // -----------------------------------------------------------------------------
1288 void ODatabaseDocument::impl_writeStorage_throw( const Reference
< XStorage
>& _rxTargetStorage
, const ::comphelper::NamedValueCollection
& _rMediaDescriptor
) const
1290 // extract status indicator
1291 Sequence
< Any
> aDelegatorArguments
;
1292 lcl_extractStatusIndicator( _rMediaDescriptor
, aDelegatorArguments
);
1294 /** property map for export info set */
1295 comphelper::PropertyMapEntry aExportInfoMap
[] =
1297 { MAP_LEN( "BaseURI"), 0,&::getCppuType( (::rtl::OUString
*)0 ),beans::PropertyAttribute::MAYBEVOID
, 0 },
1298 { MAP_LEN( "StreamName"), 0,&::getCppuType( (::rtl::OUString
*)0 ),beans::PropertyAttribute::MAYBEVOID
, 0 },
1299 { MAP_LEN( "UsePrettyPrinting" ), 0, &::getCppuType((sal_Bool
*)0), beans::PropertyAttribute::MAYBEVOID
, 0},
1300 { NULL
, 0, 0, NULL
, 0, 0 }
1302 uno::Reference
< beans::XPropertySet
> xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap
) ) );
1304 SvtSaveOptions aSaveOpt
;
1305 xInfoSet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UsePrettyPrinting")), uno::makeAny(aSaveOpt
.IsPrettyPrinting()));
1306 if ( aSaveOpt
.IsSaveRelFSys() )
1307 xInfoSet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rMediaDescriptor
.getOrDefault("URL",::rtl::OUString())));
1309 sal_Int32 nArgsLen
= aDelegatorArguments
.getLength();
1310 aDelegatorArguments
.realloc(nArgsLen
+1);
1311 aDelegatorArguments
[nArgsLen
++] <<= xInfoSet
;
1313 Reference
< XPropertySet
> xProp( _rxTargetStorage
, UNO_QUERY_THROW
);
1314 xProp
->setPropertyValue( INFO_MEDIATYPE
, makeAny( (rtl::OUString
)MIMETYPE_OASIS_OPENDOCUMENT_DATABASE
) );
1316 Reference
< XComponent
> xComponent( *const_cast< ODatabaseDocument
* >( this ), UNO_QUERY_THROW
);
1318 Sequence
< PropertyValue
> aMediaDescriptor
;
1319 _rMediaDescriptor
>>= aMediaDescriptor
;
1321 xInfoSet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("settings.xml"))));
1322 WriteThroughComponent( xComponent
, "settings.xml", "com.sun.star.comp.sdb.XMLSettingsExporter",
1323 aDelegatorArguments
, aMediaDescriptor
, _rxTargetStorage
);
1325 xInfoSet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml"))));
1326 WriteThroughComponent( xComponent
, "content.xml", "com.sun.star.comp.sdb.DBExportFilter",
1327 aDelegatorArguments
, aMediaDescriptor
, _rxTargetStorage
);
1329 m_pImpl
->storeLibraryContainersTo( _rxTargetStorage
);
1332 // -----------------------------------------------------------------------------
1333 Reference
< XUIConfigurationManager
> SAL_CALL
ODatabaseDocument::getUIConfigurationManager( ) throw (RuntimeException
)
1335 DocumentGuard
aGuard( *this );
1337 if ( !m_xUIConfigurationManager
.is() )
1339 m_pImpl
->m_aContext
.createComponent( "com.sun.star.ui.UIConfigurationManager", m_xUIConfigurationManager
);
1340 Reference
< XUIConfigurationStorage
> xUIConfigStorage( m_xUIConfigurationManager
, UNO_QUERY
);
1341 if ( xUIConfigStorage
.is() )
1343 rtl::OUString
aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
1344 Reference
< XStorage
> xConfigStorage
;
1346 // First try to open with READWRITE and then READ
1347 xConfigStorage
= getDocumentSubStorage( aUIConfigFolderName
, ElementModes::READWRITE
);
1348 if ( xConfigStorage
.is() )
1350 rtl::OUString
aUIConfigMediaType( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ));
1351 rtl::OUString aMediaType
;
1352 Reference
< XPropertySet
> xPropSet( xConfigStorage
, UNO_QUERY
);
1353 Any a
= xPropSet
->getPropertyValue( INFO_MEDIATYPE
);
1354 if ( !( a
>>= aMediaType
) || ( aMediaType
.getLength() == 0 ))
1356 a
<<= aUIConfigMediaType
;
1357 xPropSet
->setPropertyValue( INFO_MEDIATYPE
, a
);
1361 xConfigStorage
= getDocumentSubStorage( aUIConfigFolderName
, ElementModes::READ
);
1363 // initialize ui configuration manager with document substorage
1364 xUIConfigStorage
->setStorage( xConfigStorage
);
1368 return m_xUIConfigurationManager
;
1370 // -----------------------------------------------------------------------------
1371 Reference
< XStorage
> SAL_CALL
ODatabaseDocument::getDocumentSubStorage( const ::rtl::OUString
& aStorageName
, sal_Int32 nMode
) throw (RuntimeException
)
1373 DocumentGuard
aGuard( *this );
1375 Reference
< XDocumentSubStorageSupplier
> xStorageAccess( m_pImpl
->getDocumentSubStorageSupplier() );
1376 return xStorageAccess
->getDocumentSubStorage( aStorageName
, nMode
);
1378 // -----------------------------------------------------------------------------
1379 Sequence
< ::rtl::OUString
> SAL_CALL
ODatabaseDocument::getDocumentSubStoragesNames( ) throw (::com::sun::star::io::IOException
, RuntimeException
)
1381 Reference
< XDocumentSubStorageSupplier
> xStorageAccess( m_pImpl
->getDocumentSubStorageSupplier() );
1382 return xStorageAccess
->getDocumentSubStoragesNames();
1385 //------------------------------------------------------------------------------
1386 void ODatabaseDocument::impl_notifyStorageChange_nolck_nothrow( const Reference
< XStorage
>& _rxNewRootStorage
)
1388 Reference
< XInterface
> xMe( *const_cast< ODatabaseDocument
* >( this ) );
1390 m_aStorageListeners
.forEach
< XStorageChangeListener
>(
1391 boost::bind( &XStorageChangeListener::notifyStorageChange
, _1
, boost::cref( xMe
), boost::cref( _rxNewRootStorage
) ) );
1394 //------------------------------------------------------------------------------
1395 void ODatabaseDocument::disposing()
1397 if ( !m_pImpl
.is() )
1399 // this means that we're already disposed
1400 DBG_ASSERT( ODatabaseDocument_OfficeDocument::rBHelper
.bDisposed
, "ODatabaseDocument::disposing: no impl anymore, but not yet disposed!" );
1404 if ( impl_isInitialized() )
1405 m_aEventNotifier
.notifyDocumentEvent( "OnUnload" );
1407 Reference
< XModel
> xHoldAlive( this );
1409 m_aEventNotifier
.disposing();
1411 lang::EventObject
aDisposeEvent(static_cast<XWeak
*>(this));
1412 m_aModifyListeners
.disposeAndClear( aDisposeEvent
);
1413 m_aCloseListener
.disposeAndClear( aDisposeEvent
);
1414 m_aStorageListeners
.disposeAndClear( aDisposeEvent
);
1416 // this is the list of objects which we currently hold as member. Upon resetting
1417 // those members, we can (potentially) release the last reference to them, in which
1418 // case they will be deleted - if they're C++ implementations, that is :).
1419 // Some of those implementations are offending enough to require the SolarMutex, which
1420 // means we should not release the last reference while our own mutex is locked ...
1421 ::std::list
< Reference
< XInterface
> > aKeepAlive
;
1424 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
1426 DBG_ASSERT( m_aControllers
.empty(), "ODatabaseDocument::disposing: there still are controllers!" );
1427 // normally, nobody should explicitly dispose, but only XCloseable::close the document. And upon
1428 // closing, our controllers are closed, too
1430 aKeepAlive
.push_back( m_xUIConfigurationManager
);
1431 m_xUIConfigurationManager
= NULL
;
1433 clearObjectContainer( m_xForms
);
1434 clearObjectContainer( m_xReports
);
1436 // reset the macro mode: in case the our impl struct stays alive (e.g. because our DataSource
1437 // object still exists), and somebody subsequently re-opens the document, we want to have
1438 // the security warning, again.
1439 m_pImpl
->resetMacroExecutionMode();
1441 // similar argueing for our ViewMonitor
1442 m_aViewMonitor
.reset();
1444 // tell our Impl to forget us
1445 m_pImpl
->modelIsDisposing( impl_isInitialized(), ODatabaseModelImpl::ResetModelAccess() );
1447 // now, at the latest, the controller array should be empty. Controllers are
1448 // expected to listen for our disposal, and disconnect then
1449 DBG_ASSERT( m_aControllers
.empty(), "ODatabaseDocument::disposing: there still are controllers!" );
1450 impl_disposeControllerFrames_nothrow();
1452 aKeepAlive
.push_back( m_xModuleManager
);
1453 m_xModuleManager
.clear();
1455 aKeepAlive
.push_back( m_xTitleHelper
);
1456 m_xTitleHelper
.clear();
1465 // -----------------------------------------------------------------------------
1467 void SAL_CALL
ODatabaseDocument::dispose( ) throw (RuntimeException
)
1469 ::cppu::WeakComponentImplHelperBase::dispose();
1471 // -----------------------------------------------------------------------------
1472 void SAL_CALL
ODatabaseDocument::addEventListener( const Reference
< lang::XEventListener
>& _xListener
) throw (RuntimeException
)
1474 ::cppu::WeakComponentImplHelperBase::addEventListener( _xListener
);
1476 // -----------------------------------------------------------------------------
1477 void SAL_CALL
ODatabaseDocument::removeEventListener( const Reference
< lang::XEventListener
>& _xListener
) throw (RuntimeException
)
1479 ::cppu::WeakComponentImplHelperBase::removeEventListener( _xListener
);
1482 //------------------------------------------------------------------------------
1483 rtl::OUString
ODatabaseDocument::getImplementationName( ) throw(RuntimeException
)
1485 return getImplementationName_static();
1488 //------------------------------------------------------------------------------
1489 rtl::OUString
ODatabaseDocument::getImplementationName_static( ) throw(RuntimeException
)
1491 return rtl::OUString::createFromAscii("com.sun.star.comp.dba.ODatabaseDocument");
1494 //------------------------------------------------------------------------------
1495 Sequence
< ::rtl::OUString
> ODatabaseDocument::getSupportedServiceNames( ) throw (RuntimeException
)
1497 return getSupportedServiceNames_static();
1500 //------------------------------------------------------------------------------
1501 Reference
< XInterface
> ODatabaseDocument::Create( const Reference
< XComponentContext
>& _rxContext
)
1503 ::comphelper::ComponentContext
aContext( _rxContext
);
1504 Reference
< XUnoTunnel
> xDBContextTunnel( aContext
.createComponent( (::rtl::OUString
)SERVICE_SDB_DATABASECONTEXT
), UNO_QUERY_THROW
);
1505 ODatabaseContext
* pContext
= reinterpret_cast< ODatabaseContext
* >( xDBContextTunnel
->getSomething( ODatabaseContext::getUnoTunnelImplementationId() ) );
1507 ::rtl::Reference
<ODatabaseModelImpl
> pImpl( new ODatabaseModelImpl( aContext
.getLegacyServiceFactory(), *pContext
) );
1508 Reference
< XModel
> xModel( pImpl
->createNewModel_deliverOwnership( false ) );
1509 return xModel
.get();
1512 //------------------------------------------------------------------------------
1513 Sequence
< ::rtl::OUString
> ODatabaseDocument::getSupportedServiceNames_static( ) throw (RuntimeException
)
1515 Sequence
< ::rtl::OUString
> aSNS( 2 );
1516 aSNS
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.OfficeDatabaseDocument"));
1517 aSNS
[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.OfficeDocument"));
1521 //------------------------------------------------------------------------------
1522 sal_Bool
ODatabaseDocument::supportsService( const ::rtl::OUString
& _rServiceName
) throw (RuntimeException
)
1524 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName
, sal_True
).getLength() != 0;
1526 // -----------------------------------------------------------------------------
1527 Reference
< XDataSource
> SAL_CALL
ODatabaseDocument::getDataSource() throw (RuntimeException
)
1529 DocumentGuard
aGuard( *this, DocumentGuard::MethodWithoutInit
);
1530 return m_pImpl
->getOrCreateDataSource();
1533 // -----------------------------------------------------------------------------
1534 void SAL_CALL
ODatabaseDocument::loadFromStorage( const Reference
< XStorage
>& /*xStorage*/, const Sequence
< PropertyValue
>& /*aMediaDescriptor*/ ) throw (IllegalArgumentException
, DoubleInitializationException
, IOException
, Exception
, RuntimeException
)
1536 DocumentGuard
aGuard( *this );
1539 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Embedding of database documents is not supported." ) ),
1545 // -----------------------------------------------------------------------------
1546 void SAL_CALL
ODatabaseDocument::storeToStorage( const Reference
< XStorage
>& _rxStorage
, const Sequence
< PropertyValue
>& _rMediaDescriptor
) throw (IllegalArgumentException
, IOException
, Exception
, RuntimeException
)
1548 DocumentGuard
aGuard( *this );
1549 impl_storeToStorage_throw( _rxStorage
, _rMediaDescriptor
, aGuard
);
1552 // -----------------------------------------------------------------------------
1553 void SAL_CALL
ODatabaseDocument::switchToStorage( const Reference
< XStorage
>& _rxNewRootStorage
) throw (IllegalArgumentException
, IOException
, Exception
, RuntimeException
)
1555 DocumentGuard
aGuard( *this );
1557 Reference
< XStorage
> xNewRootStorage( m_pImpl
->switchToStorage( _rxNewRootStorage
) );
1560 impl_notifyStorageChange_nolck_nothrow( xNewRootStorage
);
1563 // -----------------------------------------------------------------------------
1564 Reference
< XStorage
> SAL_CALL
ODatabaseDocument::getDocumentStorage( ) throw (IOException
, Exception
, RuntimeException
)
1566 DocumentGuard
aGuard( *this );
1567 return m_pImpl
->getOrCreateRootStorage();
1570 // -----------------------------------------------------------------------------
1571 void SAL_CALL
ODatabaseDocument::addStorageChangeListener( const Reference
< XStorageChangeListener
>& _Listener
) throw (RuntimeException
)
1573 DocumentGuard
aGuard( *this );
1574 m_aStorageListeners
.addInterface( _Listener
);
1577 // -----------------------------------------------------------------------------
1578 void SAL_CALL
ODatabaseDocument::removeStorageChangeListener( const Reference
< XStorageChangeListener
>& _Listener
) throw (RuntimeException
)
1580 DocumentGuard
aGuard( *this );
1581 m_aStorageListeners
.addInterface( _Listener
);
1584 // -----------------------------------------------------------------------------
1585 Reference
< XStorageBasedLibraryContainer
> SAL_CALL
ODatabaseDocument::getBasicLibraries() throw (RuntimeException
)
1587 DocumentGuard
aGuard( *this, DocumentGuard::MethodUsedDuringInit
);
1588 return m_pImpl
->getLibraryContainer( true );
1591 // -----------------------------------------------------------------------------
1592 Reference
< XStorageBasedLibraryContainer
> SAL_CALL
ODatabaseDocument::getDialogLibraries() throw (RuntimeException
)
1594 DocumentGuard
aGuard( *this );
1595 return m_pImpl
->getLibraryContainer( false );
1598 // -----------------------------------------------------------------------------
1599 ::sal_Bool SAL_CALL
ODatabaseDocument::getAllowMacroExecution() throw (RuntimeException
)
1601 DocumentGuard
aGuard( *this );
1602 return m_pImpl
->adjustMacroMode_AutoReject();
1605 // -----------------------------------------------------------------------------
1606 Reference
< XEmbeddedScripts
> SAL_CALL
ODatabaseDocument::getScriptContainer() throw (RuntimeException
)
1608 DocumentGuard
aGuard( *this );
1612 // -----------------------------------------------------------------------------
1613 Reference
< provider::XScriptProvider
> SAL_CALL
ODatabaseDocument::getScriptProvider( ) throw (RuntimeException
)
1615 DocumentGuard
aGuard( *this );
1617 Reference
< XScriptProvider
> xScriptProvider( m_xScriptProvider
);
1618 if ( !xScriptProvider
.is() )
1620 Reference
< XScriptProviderFactory
> xFactory(
1621 m_pImpl
->m_aContext
.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW
);
1623 Any aScriptProviderContext
;
1624 if ( m_bAllowDocumentScripting
)
1625 aScriptProviderContext
<<= Reference
< XModel
>( this );
1627 xScriptProvider
.set( xFactory
->createScriptProvider( aScriptProviderContext
), UNO_SET_THROW
);
1628 m_xScriptProvider
= xScriptProvider
;
1631 return xScriptProvider
;
1634 // -----------------------------------------------------------------------------
1635 Reference
< XNameReplace
> SAL_CALL
ODatabaseDocument::getEvents( ) throw (RuntimeException
)
1637 DocumentGuard
aGuard( *this, DocumentGuard::MethodUsedDuringInit
);
1638 return m_pEventContainer
;
1641 // -----------------------------------------------------------------------------
1642 void SAL_CALL
ODatabaseDocument::disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(RuntimeException
)
1645 m_pImpl
->disposing(Source
);
1648 //------------------------------------------------------------------
1649 Reference
< XInterface
> ODatabaseDocument::getThis() const
1651 return *const_cast< ODatabaseDocument
* >( this );
1653 // -----------------------------------------------------------------------------
1654 struct CreateAny
: public ::std::unary_function
< Reference
<XController
>, Any
>
1656 Any
operator() (const Reference
<XController
>& lhs
) const
1658 return makeAny(lhs
);
1663 Reference
< XEnumeration
> SAL_CALL
ODatabaseDocument::getControllers( ) throw (RuntimeException
)
1665 DocumentGuard
aGuard( *this );
1666 uno::Sequence
< Any
> aController( m_aControllers
.size() );
1667 ::std::transform( m_aControllers
.begin(), m_aControllers
.end(), aController
.getArray(), CreateAny() );
1668 return new ::comphelper::OAnyEnumeration(aController
);
1670 // -----------------------------------------------------------------------------
1671 Sequence
< ::rtl::OUString
> SAL_CALL
ODatabaseDocument::getAvailableViewControllerNames( ) throw (RuntimeException
)
1673 Sequence
< ::rtl::OUString
> aNames(1);
1674 aNames
[0] = SERVICE_SDB_APPLICATIONCONTROLLER
;
1677 // -----------------------------------------------------------------------------
1678 Reference
< XController2
> SAL_CALL
ODatabaseDocument::createDefaultViewController( const Reference
< XFrame
>& _Frame
) throw (IllegalArgumentException
, Exception
, RuntimeException
)
1680 return createViewController(
1681 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ),
1682 Sequence
< PropertyValue
>(),
1687 // -----------------------------------------------------------------------------
1688 Reference
< XController2
> SAL_CALL
ODatabaseDocument::createViewController( const ::rtl::OUString
& _ViewName
, const Sequence
< PropertyValue
>& _Arguments
, const Reference
< XFrame
>& _Frame
) throw (IllegalArgumentException
, Exception
, RuntimeException
)
1690 if ( !_ViewName
.equalsAscii( "Default" ) && !_ViewName
.equalsAscii( "Preview" ) )
1691 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
1693 throw IllegalArgumentException( ::rtl::OUString(), *this, 3 );
1695 DocumentGuard
aGuard( *this );
1696 ::comphelper::ComponentContext
aContext( m_pImpl
->m_aContext
);
1699 Reference
< XController2
> xController
;
1700 aContext
.createComponent( "org.openoffice.comp.dbu.OApplicationController", xController
);
1702 ::comphelper::NamedValueCollection
aInitArgs( _Arguments
);
1703 aInitArgs
.put( "Frame", _Frame
);
1704 if ( _ViewName
.equalsAscii( "Preview" ) )
1705 aInitArgs
.put( "Preview", sal_Bool( sal_True
) );
1706 Reference
< XInitialization
> xInitController( xController
, UNO_QUERY_THROW
);
1707 xInitController
->initialize( aInitArgs
.getWrappedPropertyValues() );
1712 // -----------------------------------------------------------------------------
1713 //=============================================================================
1714 Reference
< XTitle
> ODatabaseDocument::impl_getTitleHelper_throw()
1716 if ( ! m_xTitleHelper
.is ())
1718 Reference
< XUntitledNumbers
> xDesktop(
1719 m_pImpl
->m_aContext
.createComponent( "com.sun.star.frame.Desktop" ),
1721 uno::Reference
< frame::XModel
> xThis (getThis(), uno::UNO_QUERY_THROW
);
1723 ::framework::TitleHelper
* pHelper
= new ::framework::TitleHelper(m_pImpl
->m_aContext
.getLegacyServiceFactory());
1724 m_xTitleHelper
.set(static_cast< ::cppu::OWeakObject
* >(pHelper
), uno::UNO_QUERY_THROW
);
1725 pHelper
->setOwner (xThis
);
1726 pHelper
->connectWithUntitledNumbers (xDesktop
);
1729 return m_xTitleHelper
;
1732 //=============================================================================
1733 uno::Reference
< frame::XUntitledNumbers
> ODatabaseDocument::impl_getUntitledHelper_throw(const uno::Reference
< uno::XInterface
>& _xComponent
)
1735 if ( !m_xModuleManager
.is() )
1736 m_xModuleManager
.set( m_pImpl
->m_aContext
.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW
);
1738 ::rtl::OUString sModuleId
;
1741 sModuleId
= m_xModuleManager
->identify( _xComponent
);
1743 catch(uno::Exception
)
1747 uno::Reference
< frame::XUntitledNumbers
> xNumberedControllers
;
1749 TNumberedController::iterator aFind
= m_aNumberedControllers
.find(sModuleId
);
1750 if ( aFind
== m_aNumberedControllers
.end() )
1752 uno::Reference
< frame::XModel
> xThis(static_cast< frame::XModel
* >(this), uno::UNO_QUERY_THROW
);
1753 ::comphelper::NumberedCollection
* pHelper
= new ::comphelper::NumberedCollection();
1754 xNumberedControllers
.set(static_cast< ::cppu::OWeakObject
* >(pHelper
), uno::UNO_QUERY_THROW
);
1756 pHelper
->setOwner (xThis
);
1757 //pHelper->setUntitledPrefix (::rtl::OUString::createFromAscii(" : "));
1759 m_aNumberedControllers
.insert(TNumberedController::value_type(sModuleId
,xNumberedControllers
));
1762 xNumberedControllers
= aFind
->second
;
1764 return xNumberedControllers
;
1767 //=============================================================================
1769 ::rtl::OUString SAL_CALL
ODatabaseDocument::getTitle()
1770 throw (uno::RuntimeException
)
1773 DocumentGuard
aGuard( *this, DocumentGuard::MethodUsedDuringInit
);
1774 return impl_getTitleHelper_throw()->getTitle();
1777 //=============================================================================
1779 void SAL_CALL
ODatabaseDocument::setTitle( const ::rtl::OUString
& sTitle
)
1780 throw (uno::RuntimeException
)
1783 DocumentGuard
aGuard( *this );
1784 impl_getTitleHelper_throw()->setTitle( sTitle
);
1785 m_aEventNotifier
.notifyDocumentEventAsync( "OnTitleChanged" );
1789 //=============================================================================
1790 // css.frame.XTitleChangeBroadcaster
1791 void SAL_CALL
ODatabaseDocument::addTitleChangeListener( const uno::Reference
< frame::XTitleChangeListener
>& xListener
)
1792 throw (uno::RuntimeException
)
1795 DocumentGuard
aGuard( *this );
1797 uno::Reference
< frame::XTitleChangeBroadcaster
> xBroadcaster( impl_getTitleHelper_throw(), uno::UNO_QUERY_THROW
);
1798 xBroadcaster
->addTitleChangeListener( xListener
);
1801 //=============================================================================
1802 // css.frame.XTitleChangeBroadcaster
1803 void SAL_CALL
ODatabaseDocument::removeTitleChangeListener( const uno::Reference
< frame::XTitleChangeListener
>& xListener
)
1804 throw (uno::RuntimeException
)
1807 DocumentGuard
aGuard( *this );
1809 uno::Reference
< frame::XTitleChangeBroadcaster
> xBroadcaster( impl_getTitleHelper_throw(), uno::UNO_QUERY_THROW
);
1810 xBroadcaster
->removeTitleChangeListener( xListener
);
1813 //=============================================================================
1814 // css.frame.XUntitledNumbers
1815 ::sal_Int32 SAL_CALL
ODatabaseDocument::leaseNumber( const uno::Reference
< uno::XInterface
>& xComponent
)
1816 throw (lang::IllegalArgumentException
,
1817 uno::RuntimeException
)
1819 DocumentGuard
aGuard( *this );
1820 return impl_getUntitledHelper_throw(xComponent
)->leaseNumber (xComponent
);
1823 //=============================================================================
1824 // css.frame.XUntitledNumbers
1825 void SAL_CALL
ODatabaseDocument::releaseNumber( ::sal_Int32 nNumber
)
1826 throw (lang::IllegalArgumentException
,
1827 uno::RuntimeException
)
1829 DocumentGuard
aGuard( *this );
1830 impl_getUntitledHelper_throw()->releaseNumber (nNumber
);
1833 //=============================================================================
1834 // css.frame.XUntitledNumbers
1835 void SAL_CALL
ODatabaseDocument::releaseNumberForComponent( const uno::Reference
< uno::XInterface
>& xComponent
)
1836 throw (lang::IllegalArgumentException
,
1837 uno::RuntimeException
)
1839 DocumentGuard
aGuard( *this );
1840 impl_getUntitledHelper_throw(xComponent
)->releaseNumberForComponent (xComponent
);
1843 //=============================================================================
1844 // css.frame.XUntitledNumbers
1845 ::rtl::OUString SAL_CALL
ODatabaseDocument::getUntitledPrefix() throw (uno::RuntimeException
)
1847 return ::rtl::OUString();/*RTL_CONSTASCII_USTRINGPARAM(" : "));*/
1850 //------------------------------------------------------------------
1851 //........................................................................
1852 } // namespace dbaccess
1853 //........................................................................