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: sfxbasemodel.cxx,v $
10 * $Revision: 1.139.2.5 $
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_sfx2.hxx"
34 //________________________________________________________________________________________________________
36 //________________________________________________________________________________________________________
38 #include <sfx2/sfxbasemodel.hxx>
40 //________________________________________________________________________________________________________
41 // include of other projects
42 //________________________________________________________________________________________________________
44 #include <com/sun/star/task/XInteractionHandler.hpp>
45 #include <com/sun/star/task/ErrorCodeRequest.hpp>
46 #include <com/sun/star/view/XSelectionSupplier.hpp>
47 #include <com/sun/star/view/XPrintJobListener.hpp>
48 #include <com/sun/star/lang/DisposedException.hpp>
49 #include <com/sun/star/lang/IllegalArgumentException.hpp>
50 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
51 #include <com/sun/star/frame/IllegalArgumentIOException.hpp>
52 #include <com/sun/star/frame/XUntitledNumbers.hpp>
53 #include <com/sun/star/frame/UntitledNumbersConst.hpp>
54 #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
55 #include <com/sun/star/embed/XStorage.hpp>
56 #include <com/sun/star/embed/EmbedMapUnits.hpp>
57 #include <com/sun/star/document/XStorageChangeListener.hpp>
58 #include <com/sun/star/document/XActionLockable.hpp>
59 #include <com/sun/star/beans/XPropertySet.hpp>
60 #include <com/sun/star/container/XIndexContainer.hpp>
61 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
62 #include <com/sun/star/script/provider/XScriptProvider.hpp>
63 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
64 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
65 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
66 #include <com/sun/star/embed/ElementModes.hpp>
67 #include <com/sun/star/embed/Aspects.hpp>
68 #include <com/sun/star/document/XDocumentProperties.hpp>
69 #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
70 #include <comphelper/enumhelper.hxx> // can be removed when this is a "real" service
72 #include <cppuhelper/interfacecontainer.hxx>
73 #include <cppuhelper/exc_hlp.hxx>
74 #include <comphelper/processfactory.hxx> // can be removed when this is a "real" service
75 #include <comphelper/componentcontext.hxx>
76 #include <svtools/itemset.hxx>
77 #include <svtools/stritem.hxx>
78 #include <svtools/eitem.hxx>
79 #include <basic/sbx.hxx>
80 #include <basic/sbuno.hxx>
81 #include <tools/urlobj.hxx>
82 #include <tools/diagnose_ex.h>
83 #include <unotools/tempfile.hxx>
84 #include <vos/mutex.hxx>
85 #include <vcl/salctype.hxx>
86 #include <sot/clsids.hxx>
87 #include <sot/storinfo.hxx>
88 #include <comphelper/storagehelper.hxx>
89 #include <toolkit/helper/vclunohelper.hxx>
90 #include <svtools/transfer.hxx>
91 #include <svtools/ehdl.hxx>
92 #include <svtools/sfxecode.hxx>
93 #include <rtl/logfile.hxx>
94 #include <framework/configimporter.hxx>
95 #include <framework/interaction.hxx>
96 #include <framework/titlehelper.hxx>
97 #include <comphelper/numberedcollection.hxx>
98 #include <unotools/ucbstreamhelper.hxx>
100 //________________________________________________________________________________________________________
101 // includes of my own project
102 //________________________________________________________________________________________________________
104 #include <sfx2/signaturestate.hxx>
105 #include <sfx2/sfxuno.hxx>
106 #include <objshimp.hxx>
107 #include <sfx2/viewfrm.hxx>
108 #include <sfx2/viewsh.hxx>
109 #include <sfx2/docfile.hxx>
110 #include <sfx2/dispatch.hxx>
111 #include <sfx2/request.hxx>
112 #include <sfx2/objuno.hxx>
113 #include <sfx2/printer.hxx>
114 #include <basmgr.hxx>
115 #include <sfx2/event.hxx>
116 #include <eventsupplier.hxx>
117 #include <sfx2/evntconf.hxx>
118 #include <sfx2/sfx.hrc>
119 #include <sfx2/app.hxx>
120 #include <sfx2/topfrm.hxx>
121 #include "appdata.hxx"
122 #include <sfx2/docfac.hxx>
123 #include <sfx2/fcontnr.hxx>
124 #include "sfx2/docstoragemodifylistener.hxx"
125 #include "brokenpackageint.hxx"
126 #include "graphhelp.hxx"
127 #include <sfx2/msgpool.hxx>
128 #include <sfx2/DocumentMetadataAccess.hxx>
130 #include <sfxresid.hxx>
132 //________________________________________________________________________________________________________
134 static const ::rtl::OUString SERVICENAME_DESKTOP
= ::rtl::OUString::createFromAscii ("com.sun.star.frame.Desktop");
136 //________________________________________________________________________________________________________
138 //________________________________________________________________________________________________________
140 namespace css
= ::com::sun::star
;
141 using namespace ::com::sun::star
;
142 using namespace ::com::sun::star::uno
;
144 /** This Listener is used to get notified when the XDocumentProperties of the
146 If several changes are done the "bQuiet" member can be used to
147 temporarily suppress notifications.
149 class SfxDocInfoListener_Impl
: public ::cppu::WeakImplHelper1
<
150 ::com::sun::star::util::XModifyListener
>
154 SfxObjectShell
& m_rShell
;
158 SfxDocInfoListener_Impl( SfxObjectShell
& i_rDoc
)
163 ~SfxDocInfoListener_Impl();
165 virtual void SAL_CALL
disposing( const lang::EventObject
& )
166 throw ( uno::RuntimeException
);
167 virtual void SAL_CALL
modified( const lang::EventObject
& )
168 throw ( uno::RuntimeException
);
170 SfxDocInfoListener_Impl::~SfxDocInfoListener_Impl()
173 void SAL_CALL
SfxDocInfoListener_Impl::modified( const lang::EventObject
& )
174 throw ( uno::RuntimeException
)
176 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
179 // notify changes to the SfxObjectShell
181 m_rShell
.FlushDocInfo();
185 void SAL_CALL
SfxDocInfoListener_Impl::disposing( const lang::EventObject
& )
186 throw ( uno::RuntimeException
)
190 //________________________________________________________________________________________________________
191 // impl. declarations
192 //________________________________________________________________________________________________________
195 struct IMPL_SfxBaseModel_DataContainer
: public ::sfx2::IModifiableDocument
197 // counter for SfxBaseModel instances created.
198 static sal_Int64 g_nInstanceCounter
;
199 SfxObjectShellRef m_pObjectShell
;
200 ::rtl::OUString m_sURL
;
201 ::rtl::OUString m_sRuntimeUID
;
202 ::rtl::OUString m_aPreusedFilterName
;
203 ::cppu::OMultiTypeInterfaceContainerHelper m_aInterfaceContainer
;
204 uno::Reference
< uno::XInterface
> m_xParent
;
205 uno::Reference
< frame::XController
> m_xCurrent
;
206 uno::Reference
< document::XDocumentInfo
> m_xDocumentInfo
;
207 uno::Reference
< document::XDocumentProperties
> m_xDocumentProperties
;
208 uno::Reference
< script::XStarBasicAccess
> m_xStarBasicAccess
;
209 uno::Reference
< container::XNameReplace
> m_xEvents
;
210 uno::Sequence
< beans::PropertyValue
> m_seqArguments
;
211 uno::Sequence
< uno::Reference
< frame::XController
> > m_seqControllers
;
212 uno::Reference
< container::XIndexAccess
> m_contViewData
;
213 sal_uInt16 m_nControllerLockCount
;
215 sal_Bool m_bClosing
;
217 sal_Bool m_bSuicide
;
218 uno::Reference
< com::sun::star::view::XPrintable
> m_xPrintable
;
219 uno::Reference
< script::provider::XScriptProvider
> m_xScriptProvider
;
220 uno::Reference
< ui::XUIConfigurationManager
> m_xUIConfigurationManager
;
221 ::rtl::Reference
< ::sfx2::DocumentStorageModifyListener
> m_pStorageModifyListen
;
222 ::rtl::OUString m_sModuleIdentifier
;
223 css::uno::Reference
< css::frame::XTitle
> m_xTitleHelper
;
224 css::uno::Reference
< css::frame::XUntitledNumbers
> m_xNumberedControllers
;
225 uno::Reference
< rdf::XDocumentMetadataAccess
> m_xDocumentMetadata
;
228 IMPL_SfxBaseModel_DataContainer( ::osl::Mutex
& rMutex
, SfxObjectShell
* pObjectShell
)
229 : m_pObjectShell ( pObjectShell
)
230 , m_aInterfaceContainer ( rMutex
)
231 , m_nControllerLockCount ( 0 )
232 , m_bClosed ( sal_False
)
233 , m_bClosing ( sal_False
)
234 , m_bSaving ( sal_False
)
235 , m_bSuicide ( sal_False
)
236 , m_pStorageModifyListen ( NULL
)
238 , m_xNumberedControllers ()
239 , m_xDocumentMetadata () // lazy
241 // increase global instance counter.
242 ++g_nInstanceCounter
;
243 // set own Runtime UID
244 m_sRuntimeUID
= rtl::OUString::valueOf( g_nInstanceCounter
);
247 virtual ~IMPL_SfxBaseModel_DataContainer()
251 // ::sfx2::IModifiableDocument
252 virtual void storageIsModified()
254 if ( m_pObjectShell
.Is() && !m_pObjectShell
->IsModified() )
255 m_pObjectShell
->SetModified( sal_True
);
258 uno::Reference
<rdf::XDocumentMetadataAccess
> GetDMA()
260 if (!m_xDocumentMetadata
.is())
262 OSL_ENSURE(m_pObjectShell
, "GetDMA: no object shell?");
268 const uno::Reference
<uno::XComponentContext
> xContext(
269 ::comphelper::getProcessComponentContext());
271 const uno::Reference
<frame::XModel
> xModel(
272 m_pObjectShell
->GetModel());
273 const uno::Reference
<lang::XMultiComponentFactory
> xMsf(
274 xContext
->getServiceManager());
275 const uno::Reference
<frame::
276 XTransientDocumentsDocumentContentFactory
> xTDDCF(
277 xMsf
->createInstanceWithContext(
278 ::rtl::OUString::createFromAscii( "com.sun.star.frame."
279 "TransientDocumentsDocumentContentFactory"),
281 uno::UNO_QUERY_THROW
);
282 const uno::Reference
<ucb::XContent
> xContent(
283 xTDDCF
->createDocumentContent(xModel
) );
284 OSL_ENSURE(xContent
.is(), "GetDMA: cannot create DocumentContent");
289 uri
= xContent
->getIdentifier()->getContentIdentifier();
290 OSL_ENSURE(uri
.getLength(), "GetDMA: empty uri?");
291 if (uri
.getLength() && !uri
.endsWithAsciiL("/", 1))
293 uri
= uri
+ ::rtl::OUString::createFromAscii("/");
296 m_xDocumentMetadata
= new ::sfx2::DocumentMetadataAccess(
297 xContext
, *m_pObjectShell
, uri
);
299 return m_xDocumentMetadata
;
302 uno::Reference
<rdf::XDocumentMetadataAccess
> CreateDMAUninitialized()
304 return (m_pObjectShell
)
305 ? new ::sfx2::DocumentMetadataAccess(
306 ::comphelper::getProcessComponentContext(), *m_pObjectShell
)
311 // static member initialization.
312 sal_Int64
IMPL_SfxBaseModel_DataContainer::g_nInstanceCounter
= 0;
314 // =======================================================================================================
316 // Listener that forwards notifications from the PrintHelper to the "real" listeners
317 class SfxPrintHelperListener_Impl
: public ::cppu::WeakImplHelper1
< ::com::sun::star::view::XPrintJobListener
>
320 IMPL_SfxBaseModel_DataContainer
* m_pData
;
321 SfxPrintHelperListener_Impl( IMPL_SfxBaseModel_DataContainer
* pData
)
325 virtual void SAL_CALL
disposing( const lang::EventObject
& aEvent
) throw ( uno::RuntimeException
) ;
326 virtual void SAL_CALL
printJobEvent( const view::PrintJobEvent
& rEvent
) throw ( uno::RuntimeException
);
329 void SAL_CALL
SfxPrintHelperListener_Impl::disposing( const lang::EventObject
& ) throw ( uno::RuntimeException
)
331 m_pData
->m_xPrintable
= 0;
334 void SAL_CALL
SfxPrintHelperListener_Impl::printJobEvent( const view::PrintJobEvent
& rEvent
) throw (uno::RuntimeException
)
336 ::cppu::OInterfaceContainerHelper
* pContainer
= m_pData
->m_aInterfaceContainer
.getContainer( ::getCppuType( ( const uno::Reference
< view::XPrintJobListener
>*) NULL
) );
337 if ( pContainer
!=NULL
)
339 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
340 while (pIterator
.hasMoreElements())
341 ((view::XPrintJobListener
*)pIterator
.next())->printJobEvent( rEvent
);
345 // SfxOwnFramesLocker ====================================================================================
346 // allows to lock all the frames related to the provided SfxObjectShell
347 class SfxOwnFramesLocker
349 uno::Sequence
< uno::Reference
< frame::XFrame
> > m_aLockedFrames
;
351 Window
* GetVCLWindow( const uno::Reference
< frame::XFrame
>& xFrame
);
353 SfxOwnFramesLocker( SfxObjectShell
* ObjechShell
);
354 ~SfxOwnFramesLocker();
358 SfxOwnFramesLocker::SfxOwnFramesLocker( SfxObjectShell
* pObjectShell
)
363 for ( SfxViewFrame
*pFrame
= SfxViewFrame::GetFirst(pObjectShell
, TYPE(SfxTopViewFrame
) ); pFrame
;
364 pFrame
= SfxViewFrame::GetNext(*pFrame
, pObjectShell
, TYPE(SfxTopViewFrame
) ) )
366 SfxFrame
* pSfxFrame
= pFrame
->GetFrame();
371 // get vcl window related to the frame and lock it if it is still not locked
372 uno::Reference
< frame::XFrame
> xFrame
= pSfxFrame
->GetFrameInterface();
373 Window
* pWindow
= GetVCLWindow( xFrame
);
375 throw uno::RuntimeException();
377 if ( pWindow
->IsEnabled() )
383 sal_Int32 nLen
= m_aLockedFrames
.getLength();
384 m_aLockedFrames
.realloc( nLen
+ 1 );
385 m_aLockedFrames
[nLen
] = xFrame
;
387 catch( uno::Exception
& )
394 catch( uno::Exception
& )
396 OSL_ENSURE( sal_False
, "Not possible to lock the frame window!\n" );
402 SfxOwnFramesLocker::~SfxOwnFramesLocker()
407 Window
* SfxOwnFramesLocker::GetVCLWindow( const uno::Reference
< frame::XFrame
>& xFrame
)
409 Window
* pWindow
= NULL
;
413 uno::Reference
< awt::XWindow
> xWindow
= xFrame
->getContainerWindow();
415 pWindow
= VCLUnoHelper::GetWindow( xWindow
);
421 void SfxOwnFramesLocker::UnlockFrames()
423 for ( sal_Int32 nInd
= 0; nInd
< m_aLockedFrames
.getLength(); nInd
++ )
427 if ( m_aLockedFrames
[nInd
].is() )
429 // get vcl window related to the frame and unlock it
430 Window
* pWindow
= GetVCLWindow( m_aLockedFrames
[nInd
] );
432 throw uno::RuntimeException();
436 m_aLockedFrames
[nInd
] = uno::Reference
< frame::XFrame
>();
439 catch( uno::Exception
& )
441 OSL_ENSURE( sal_False
, "Can't unlock the frame window!\n" );
446 // SfxSaveGuard ====================================================================================
450 uno::Reference
< frame::XModel
> m_xModel
;
451 IMPL_SfxBaseModel_DataContainer
* m_pData
;
452 SfxOwnFramesLocker
* m_pFramesLock
;
455 SfxSaveGuard(const uno::Reference
< frame::XModel
>& xModel
,
456 IMPL_SfxBaseModel_DataContainer
* pData
,
457 sal_Bool bRejectConcurrentSaveRequest
);
461 SfxSaveGuard::SfxSaveGuard(const uno::Reference
< frame::XModel
>& xModel
,
462 IMPL_SfxBaseModel_DataContainer
* pData
,
463 sal_Bool bRejectConcurrentSaveRequest
)
468 static ::rtl::OUString MSG_1
= ::rtl::OUString::createFromAscii("Object already disposed." );
469 static ::rtl::OUString MSG_2
= ::rtl::OUString::createFromAscii("Concurrent save requests on the same document are not possible.");
471 if ( m_pData
->m_bClosed
)
472 throw ::com::sun::star::lang::DisposedException(
474 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>());
477 bRejectConcurrentSaveRequest
&&
480 throw ::com::sun::star::io::IOException(
482 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>());
484 m_pData
->m_bSaving
= sal_True
;
485 m_pFramesLock
= new SfxOwnFramesLocker(m_pData
->m_pObjectShell
);
488 SfxSaveGuard::~SfxSaveGuard()
490 SfxOwnFramesLocker
* pFramesLock
= m_pFramesLock
;
494 m_pData
->m_bSaving
= sal_False
;
496 // m_bSuicide was set e.g. in case somewhere tried to close a document, while it was used for
497 // storing at the same time. Further m_bSuicide was set to TRUE only if close(TRUE) was called.
498 // So the owner ship was delegated to the place where a veto exception was thrown.
499 // Now we have to call close() again and delegate the owner ship to the next one, which
500 // cant accept that. Close(FALSE) cant work in this case. Because then the document will may be never closed ...
502 if ( m_pData
->m_bSuicide
)
504 // Reset this state. In case the new close() request is not accepted by somehwere else ...
505 // it's not a good idea to have two "owners" for close .-)
506 m_pData
->m_bSuicide
= sal_False
;
509 uno::Reference
< util::XCloseable
> xClose(m_xModel
, uno::UNO_QUERY
);
511 xClose
->close(sal_True
);
513 catch(const util::CloseVetoException
&)
518 // =======================================================================================================
520 //________________________________________________________________________________________________________
522 //________________________________________________________________________________________________________
523 DBG_NAME(sfx2_SfxBaseModel
)
524 SfxBaseModel::SfxBaseModel( SfxObjectShell
*pObjectShell
)
526 , m_pData( new IMPL_SfxBaseModel_DataContainer( m_aMutex
, pObjectShell
) )
527 , m_bSupportEmbeddedScripts( pObjectShell
&& pObjectShell
->Get_Impl() ? !pObjectShell
->Get_Impl()->m_bNoBasicCapabilities
: false )
529 DBG_CTOR(sfx2_SfxBaseModel
,NULL
);
530 if ( pObjectShell
!= NULL
)
532 StartListening( *pObjectShell
) ;
536 //________________________________________________________________________________________________________
538 //________________________________________________________________________________________________________
540 SfxBaseModel::~SfxBaseModel()
542 DBG_DTOR(sfx2_SfxBaseModel
,NULL
);
545 //________________________________________________________________________________________________________
547 //________________________________________________________________________________________________________
549 uno::Any SAL_CALL
SfxBaseModel::queryInterface( const UNOTYPE
& rType
) throw( uno::RuntimeException
)
551 if ( !m_bSupportEmbeddedScripts
&& rType
.equals( XEMBEDDEDSCRIPTS::static_type() ) )
554 return SfxBaseModel_Base::queryInterface( rType
);
557 //________________________________________________________________________________________________________
559 //________________________________________________________________________________________________________
561 void SAL_CALL
SfxBaseModel::acquire() throw( )
564 // Don't use mutex or guard in this method!!! Is a method of XInterface.
566 // Forward to baseclass
567 OWeakObject::acquire() ;
570 //________________________________________________________________________________________________________
572 //________________________________________________________________________________________________________
574 void SAL_CALL
SfxBaseModel::release() throw( )
577 // Don't use mutex or guard in this method!!! Is a method of XInterface.
579 // Forward to baseclass
580 OWeakObject::release() ;
583 //________________________________________________________________________________________________________
585 //________________________________________________________________________________________________________
587 uno::Sequence
< UNOTYPE
> SAL_CALL
SfxBaseModel::getTypes() throw( uno::RuntimeException
)
589 uno::Sequence
< UNOTYPE
> aTypes( SfxBaseModel_Base::getTypes() );
590 if ( !m_bSupportEmbeddedScripts
)
592 // remove XEmbeddedScripts type from the sequence
593 Sequence
< UNOTYPE
> aStrippedTypes( aTypes
.getLength() - 1 );
594 ::std::remove_copy_if(
595 aTypes
.getConstArray(),
596 aTypes
.getConstArray() + aTypes
.getLength(),
597 aStrippedTypes
.getArray(),
598 ::std::bind2nd( ::std::equal_to
< UNOTYPE
>(), XEMBEDDEDSCRIPTS::static_type() )
600 aTypes
= aStrippedTypes
;
605 //________________________________________________________________________________________________________
607 //________________________________________________________________________________________________________
609 uno::Sequence
< sal_Int8
> SAL_CALL
SfxBaseModel::getImplementationId() throw( uno::RuntimeException
)
611 // Create one Id for all instances of this class.
612 // Use ethernet address to do this! (sal_True)
614 // Optimize this method
615 // We initialize a static variable only one time. And we don't must use a mutex at every call!
616 // For the first call; pID is NULL - for the second call pID is different from NULL!
617 static ::cppu::OImplementationId
* pID
= NULL
;
621 // Ready for multithreading; get global mutex for first call of this method only! see before
622 ::osl::MutexGuard
aGuard( MUTEX::getGlobalMutex() ) ;
624 // Control these pointer again ... it can be, that another instance will be faster then these!
627 // Create a new static ID ...
628 static ::cppu::OImplementationId
aID( sal_False
) ;
629 // ... and set his address to static pointer!
634 return pID
->getImplementationId() ;
637 //________________________________________________________________________________________________________
639 //________________________________________________________________________________________________________
641 uno::Reference
< script::XStarBasicAccess
> implGetStarBasicAccess( SfxObjectShell
* pObjectShell
)
643 uno::Reference
< script::XStarBasicAccess
> xRet
;
646 BasicManager
* pMgr
= pObjectShell
->GetBasicManager();
647 xRet
= getStarBasicAccess( pMgr
);
652 uno::Reference
< XNAMECONTAINER
> SAL_CALL
SfxBaseModel::getLibraryContainer() throw( uno::RuntimeException
)
654 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
655 if ( impl_isDisposed() )
656 throw lang::DisposedException();
658 uno::Reference
< script::XStarBasicAccess
>& rxAccess
= m_pData
->m_xStarBasicAccess
;
659 if( !rxAccess
.is() && m_pData
->m_pObjectShell
.Is() )
660 rxAccess
= implGetStarBasicAccess( m_pData
->m_pObjectShell
);
662 uno::Reference
< XNAMECONTAINER
> xRet
;
664 xRet
= rxAccess
->getLibraryContainer();
668 /**___________________________________________________________________________________________________
669 @seealso XStarBasicAccess
671 void SAL_CALL
SfxBaseModel::createLibrary( const ::rtl::OUString
& LibName
, const ::rtl::OUString
& Password
,
672 const ::rtl::OUString
& ExternalSourceURL
, const ::rtl::OUString
& LinkTargetURL
)
673 throw(ELEMENTEXISTEXCEPTION
, uno::RuntimeException
)
675 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
676 if ( impl_isDisposed() )
677 throw lang::DisposedException();
679 uno::Reference
< script::XStarBasicAccess
>& rxAccess
= m_pData
->m_xStarBasicAccess
;
680 if( !rxAccess
.is() && m_pData
->m_pObjectShell
.Is() )
681 rxAccess
= implGetStarBasicAccess( m_pData
->m_pObjectShell
);
684 rxAccess
->createLibrary( LibName
, Password
, ExternalSourceURL
, LinkTargetURL
);
687 /**___________________________________________________________________________________________________
688 @seealso XStarBasicAccess
690 void SAL_CALL
SfxBaseModel::addModule( const ::rtl::OUString
& LibraryName
, const ::rtl::OUString
& ModuleName
,
691 const ::rtl::OUString
& Language
, const ::rtl::OUString
& Source
)
692 throw( NOSUCHELEMENTEXCEPTION
, uno::RuntimeException
)
694 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
695 if ( impl_isDisposed() )
696 throw lang::DisposedException();
698 uno::Reference
< script::XStarBasicAccess
>& rxAccess
= m_pData
->m_xStarBasicAccess
;
699 if( !rxAccess
.is() && m_pData
->m_pObjectShell
.Is() )
700 rxAccess
= implGetStarBasicAccess( m_pData
->m_pObjectShell
);
703 rxAccess
->addModule( LibraryName
, ModuleName
, Language
, Source
);
706 /**___________________________________________________________________________________________________
707 @seealso XStarBasicAccess
709 void SAL_CALL
SfxBaseModel::addDialog( const ::rtl::OUString
& LibraryName
, const ::rtl::OUString
& DialogName
,
710 const ::com::sun::star::uno::Sequence
< sal_Int8
>& Data
)
711 throw(NOSUCHELEMENTEXCEPTION
, uno::RuntimeException
)
713 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
714 if ( impl_isDisposed() )
715 throw lang::DisposedException();
717 uno::Reference
< script::XStarBasicAccess
>& rxAccess
= m_pData
->m_xStarBasicAccess
;
718 if( !rxAccess
.is() && m_pData
->m_pObjectShell
.Is() )
719 rxAccess
= implGetStarBasicAccess( m_pData
->m_pObjectShell
);
722 rxAccess
->addDialog( LibraryName
, DialogName
, Data
);
726 //________________________________________________________________________________________________________
728 //________________________________________________________________________________________________________
730 uno::Reference
< uno::XInterface
> SAL_CALL
SfxBaseModel::getParent() throw( uno::RuntimeException
)
732 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
733 if ( impl_isDisposed() )
734 throw lang::DisposedException();
736 return m_pData
->m_xParent
;
739 //________________________________________________________________________________________________________
741 //________________________________________________________________________________________________________
743 void SAL_CALL
SfxBaseModel::setParent(const uno::Reference
< uno::XInterface
>& Parent
) throw(NOSUPPORTEXCEPTION
, uno::RuntimeException
)
745 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
746 m_pData
->m_xParent
= Parent
;
749 //________________________________________________________________________________________________________
751 //________________________________________________________________________________________________________
753 void SAL_CALL
SfxBaseModel::dispose() throw(::com::sun::star::uno::RuntimeException
)
755 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
757 // object already disposed?
758 if ( impl_isDisposed() )
759 throw lang::DisposedException();
761 if ( !m_pData
->m_bClosed
)
763 // gracefully accept wrong dispose calls instead of close call
764 // and try to make it work (may be really disposed later!)
769 catch ( com::sun::star::util::CloseVetoException
& )
776 if ( m_pData
->m_pStorageModifyListen
.is() )
778 m_pData
->m_pStorageModifyListen
->dispose();
779 m_pData
->m_pStorageModifyListen
= NULL
;
782 lang::EventObject
aEvent( (frame::XModel
*)this );
783 m_pData
->m_aInterfaceContainer
.disposeAndClear( aEvent
);
785 if ( m_pData
->m_xDocumentInfo
.is() )
787 // as long as an SfxObjectShell is assigned to an SfxBaseModel it is still existing here
788 // so we can't dispose the shared DocumentInfoObject here
789 // uno::Reference < lang::XComponent > xComp( m_pData->m_xDocumentInfo, uno::UNO_QUERY );
791 m_pData
->m_xDocumentInfo
= 0;
794 m_pData
->m_xDocumentProperties
.clear();
796 m_pData
->m_xDocumentMetadata
.clear();
798 EndListening( *m_pData
->m_pObjectShell
);
800 m_pData
->m_xCurrent
= uno::Reference
< frame::XController
> ();
801 m_pData
->m_seqControllers
= uno::Sequence
< uno::Reference
< frame::XController
> > () ;
803 // m_pData member must be set to zero before 0delete is called to
804 // force disposed exception whenever someone tries to access our
805 // instance while in the dtor.
806 IMPL_SfxBaseModel_DataContainer
* pData
= m_pData
;
811 //________________________________________________________________________________________________________
813 //________________________________________________________________________________________________________
815 void SAL_CALL
SfxBaseModel::addEventListener( const uno::Reference
< XEVENTLISTENER
>& aListener
)
816 throw(::com::sun::star::uno::RuntimeException
)
818 // object already disposed?
819 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
820 if ( impl_isDisposed() )
823 m_pData
->m_aInterfaceContainer
.addInterface( ::getCppuType((const uno::Reference
< XEVENTLISTENER
>*)0), aListener
);
826 //________________________________________________________________________________________________________
828 //________________________________________________________________________________________________________
830 void SAL_CALL
SfxBaseModel::removeEventListener( const uno::Reference
< XEVENTLISTENER
>& aListener
)
831 throw(::com::sun::star::uno::RuntimeException
)
833 // object already disposed?
834 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
835 if ( impl_isDisposed() )
838 m_pData
->m_aInterfaceContainer
.removeInterface( ::getCppuType((const uno::Reference
< XEVENTLISTENER
>*)0), aListener
);
841 //________________________________________________________________________________________________________
842 // document::XDocumentInfoSupplier
843 //________________________________________________________________________________________________________
845 uno::Reference
< document::XDocumentInfo
> SAL_CALL
SfxBaseModel::getDocumentInfo() throw(::com::sun::star::uno::RuntimeException
)
847 // object already disposed?
848 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
849 if ( impl_isDisposed() )
850 throw lang::DisposedException();
852 if ( !m_pData
->m_xDocumentInfo
.is() )
854 // WARNING: this will only work if (when loading a document) the
855 // document meta-data has already been read and completely written
856 // into the XDocumentProperties at this point
857 // ==> DO NOT call getDocumentInfo before document info has been read!
858 uno::Reference
< document::XDocumentInfo
> xDocInfo
=
859 new SfxDocumentInfoObject
;
860 uno::Reference
< document::XDocumentProperties
> xDocProps
=
861 getDocumentProperties();
862 uno::Sequence
< uno::Any
> args(1);
863 args
[0] <<= xDocProps
;
864 uno::Reference
< lang::XInitialization
> xInit(
865 xDocInfo
, uno::UNO_QUERY_THROW
);
867 xInit
->initialize(args
);
868 ((SfxBaseModel
*)this)->m_pData
->m_xDocumentInfo
= xDocInfo
;
869 } catch (uno::RuntimeException
&) {
871 } catch (uno::Exception
& e
) {
872 throw lang::WrappedTargetRuntimeException(::rtl::OUString::createFromAscii(
873 "SfxBaseModel::getDocumentInfo: cannot initialize"), *this,
877 rtl::OUString aName
= rtl::OUString::createFromAscii("MediaType");
878 uno::Reference
< beans::XPropertySet
> xSet(
879 getDocumentStorage(), uno::UNO_QUERY
);
880 uno::Any aMediaType
= xSet
->getPropertyValue( aName
);
881 uno::Reference
< beans::XPropertySet
> xDocSet(
882 m_pData
->m_xDocumentInfo
, uno::UNO_QUERY
);
883 xDocSet
->setPropertyValue( aName
, aMediaType
);
884 } catch (uno::Exception
&) {
889 return m_pData
->m_xDocumentInfo
;
892 SfxBaseModel::setDocumentProperties( const uno::Reference
< document::XDocumentProperties
>& rxNewDocProps
)
894 // object already disposed?
895 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
896 if ( impl_isDisposed() )
897 throw lang::DisposedException();
898 m_pData
->m_xDocumentProperties
.set(rxNewDocProps
, uno::UNO_QUERY_THROW
);
900 // document::XDocumentPropertiesSupplier:
901 uno::Reference
< document::XDocumentProperties
> SAL_CALL
902 SfxBaseModel::getDocumentProperties()
903 throw(::com::sun::star::uno::RuntimeException
)
905 // object already disposed?
906 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
907 if ( impl_isDisposed() )
908 throw lang::DisposedException();
910 if ( !m_pData
->m_xDocumentProperties
.is() )
912 uno::Reference
< lang::XInitialization
> xDocProps(
913 ::comphelper::getProcessServiceFactory()->createInstance(
914 DEFINE_CONST_UNICODE("com.sun.star.document.DocumentProperties") ),
915 uno::UNO_QUERY_THROW
);
916 // xDocProps->initialize(uno::Sequence<uno::Any>());
917 m_pData
->m_xDocumentProperties
.set(xDocProps
, uno::UNO_QUERY_THROW
);
918 uno::Reference
<util::XModifyBroadcaster
> xMB(m_pData
->m_xDocumentProperties
, uno::UNO_QUERY_THROW
);
919 xMB
->addModifyListener(new SfxDocInfoListener_Impl(*m_pData
->m_pObjectShell
));
922 return m_pData
->m_xDocumentProperties
;
926 //________________________________________________________________________________________________________
928 //________________________________________________________________________________________________________
930 void SAL_CALL
SfxBaseModel::disposing( const lang::EventObject
& aObject
)
931 throw(::com::sun::star::uno::RuntimeException
)
933 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
934 if ( impl_isDisposed() )
937 uno::Reference
< XMODIFYLISTENER
> xMod( aObject
.Source
, uno::UNO_QUERY
);
938 uno::Reference
< XEVENTLISTENER
> xListener( aObject
.Source
, uno::UNO_QUERY
);
939 uno::Reference
< XDOCEVENTLISTENER
> xDocListener( aObject
.Source
, uno::UNO_QUERY
);
942 m_pData
->m_aInterfaceContainer
.removeInterface( ::getCppuType((const uno::Reference
< XMODIFYLISTENER
>*)0), xMod
);
943 else if ( xListener
.is() )
944 m_pData
->m_aInterfaceContainer
.removeInterface( ::getCppuType((const uno::Reference
< XEVENTLISTENER
>*)0), xListener
);
945 else if ( xDocListener
.is() )
946 m_pData
->m_aInterfaceContainer
.removeInterface( ::getCppuType((const uno::Reference
< XDOCEVENTLISTENER
>*)0), xListener
);
949 //________________________________________________________________________________________________________
951 //________________________________________________________________________________________________________
953 sal_Bool SAL_CALL
SfxBaseModel::attachResource( const ::rtl::OUString
& rURL
,
954 const uno::Sequence
< beans::PropertyValue
>& rArgs
)
955 throw(::com::sun::star::uno::RuntimeException
)
957 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
958 if ( impl_isDisposed() )
959 throw lang::DisposedException();
961 if ( rURL
.getLength() == 0 && rArgs
.getLength() == 1 && rArgs
[0].Name
.equalsAscii( "SetEmbedded" ) )
963 // allows to set a windowless document to EMBEDDED state
964 // but _only_ before load() or initNew() methods
965 if ( m_pData
->m_pObjectShell
.Is() && !m_pData
->m_pObjectShell
->GetMedium() )
967 sal_Bool bEmb
= sal_Bool();
968 if ( ( rArgs
[0].Value
>>= bEmb
) && bEmb
)
969 m_pData
->m_pObjectShell
->SetCreateMode_Impl( SFX_CREATE_MODE_EMBEDDED
);
975 if ( m_pData
->m_pObjectShell
.Is() )
977 m_pData
->m_sURL
= rURL
;
978 uno::Sequence
< beans::PropertyValue
> aNewSeqArgs( rArgs
.getLength() );
979 sal_Int32 nNewLen
= 0;
981 for ( sal_Int32 nInd
= 0; nInd
< rArgs
.getLength(); nInd
++ )
983 if ( rArgs
[nInd
].Name
.equalsAscii( "WinExtent" ) )
985 Sequence
< sal_Int32
> aSize
;
986 if ( ( rArgs
[nInd
].Value
>>= aSize
) && aSize
.getLength() == 4 )
988 Rectangle
aTmpRect( aSize
[0], aSize
[1], aSize
[2], aSize
[3] );
989 aTmpRect
= OutputDevice::LogicToLogic( aTmpRect
, MAP_100TH_MM
, m_pData
->m_pObjectShell
->GetMapUnit() );
990 m_pData
->m_pObjectShell
->SetVisArea( aTmpRect
);
993 else if ( rArgs
[nInd
].Name
.equalsAscii( "BreakMacroSignature" ) )
995 sal_Bool bBreakMacroSign
= sal_False
;
996 rArgs
[nInd
].Value
>>= bBreakMacroSign
;
997 m_pData
->m_pObjectShell
->BreakMacroSign_Impl( bBreakMacroSign
);
999 else if ( !rArgs
[nInd
].Name
.equalsAscii( "Stream" ) && !rArgs
[nInd
].Name
.equalsAscii( "InputStream" ) )
1001 // TODO/LATER: all the parameters that are accepted by ItemSet of the DocShell must be ignored here
1002 aNewSeqArgs
[nNewLen
++] = rArgs
[nInd
];
1006 aNewSeqArgs
.realloc( nNewLen
);
1008 m_pData
->m_seqArguments
= aNewSeqArgs
;
1010 if( m_pData
->m_pObjectShell
->GetMedium() )
1012 SfxAllItemSet
aSet( m_pData
->m_pObjectShell
->GetPool() );
1013 TransformParameters( SID_OPENDOC
, rArgs
, aSet
);
1015 m_pData
->m_pObjectShell
->GetMedium()->GetItemSet()->Put( aSet
);
1016 SFX_ITEMSET_ARG( &aSet
, pItem
, SfxStringItem
, SID_FILTER_NAME
, sal_False
);
1018 m_pData
->m_pObjectShell
->GetMedium()->SetFilter(
1019 m_pData
->m_pObjectShell
->GetFactory().GetFilterContainer()->GetFilter4FilterName( pItem
->GetValue() ) );
1021 SFX_ITEMSET_ARG( &aSet
, pTitleItem
, SfxStringItem
, SID_DOCINFO_TITLE
, sal_False
);
1024 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( m_pData
->m_pObjectShell
);
1026 pFrame
->UpdateTitle();
1034 //________________________________________________________________________________________________________
1036 //________________________________________________________________________________________________________
1038 ::rtl::OUString SAL_CALL
SfxBaseModel::getURL() throw(::com::sun::star::uno::RuntimeException
)
1040 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1041 if ( impl_isDisposed() )
1042 throw lang::DisposedException();
1044 return m_pData
->m_sURL
;
1047 //________________________________________________________________________________________________________
1049 //________________________________________________________________________________________________________
1051 uno::Sequence
< beans::PropertyValue
> SAL_CALL
SfxBaseModel::getArgs() throw(::com::sun::star::uno::RuntimeException
)
1053 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1054 if ( impl_isDisposed() )
1055 throw lang::DisposedException();
1057 if ( m_pData
->m_pObjectShell
.Is() )
1059 uno::Sequence
< beans::PropertyValue
> seqArgsNew
;
1060 uno::Sequence
< beans::PropertyValue
> seqArgsOld
;
1061 SfxAllItemSet
aSet( m_pData
->m_pObjectShell
->GetPool() );
1063 // we need to know which properties are supported by the transformer
1064 // hopefully it is a temporary solution, I guess nonconvertable properties
1065 // should not be supported so then there will be only ItemSet from medium
1067 TransformItems( SID_OPENDOC
, *(m_pData
->m_pObjectShell
->GetMedium()->GetItemSet()), seqArgsNew
);
1068 TransformParameters( SID_OPENDOC
, m_pData
->m_seqArguments
, aSet
);
1069 TransformItems( SID_OPENDOC
, aSet
, seqArgsOld
);
1071 sal_Int32 nOrgLength
= m_pData
->m_seqArguments
.getLength();
1072 sal_Int32 nOldLength
= seqArgsOld
.getLength();
1073 sal_Int32 nNewLength
= seqArgsNew
.getLength();
1075 // "WinExtent" property should be updated always.
1076 // We can store it now to overwrite an old value
1077 // since it is not from ItemSet
1078 Rectangle aTmpRect
= m_pData
->m_pObjectShell
->GetVisArea( ASPECT_CONTENT
);
1079 aTmpRect
= OutputDevice::LogicToLogic( aTmpRect
, m_pData
->m_pObjectShell
->GetMapUnit(), MAP_100TH_MM
);
1081 Sequence
< sal_Int32
> aRectSeq(4);
1082 aRectSeq
[0] = aTmpRect
.Left();
1083 aRectSeq
[1] = aTmpRect
.Top();
1084 aRectSeq
[2] = aTmpRect
.Right();
1085 aRectSeq
[3] = aTmpRect
.Bottom();
1087 seqArgsNew
.realloc( ++nNewLength
);
1088 seqArgsNew
[ nNewLength
- 1 ].Name
= ::rtl::OUString::createFromAscii( "WinExtent" );
1089 seqArgsNew
[ nNewLength
- 1 ].Value
<<= aRectSeq
;
1091 if ( m_pData
->m_aPreusedFilterName
.getLength() )
1093 seqArgsNew
.realloc( ++nNewLength
);
1094 seqArgsNew
[ nNewLength
- 1 ].Name
= ::rtl::OUString::createFromAscii( "PreusedFilterName" );
1095 seqArgsNew
[ nNewLength
- 1 ].Value
<<= m_pData
->m_aPreusedFilterName
;
1098 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( m_pData
->m_pObjectShell
);
1101 SvBorder aBorder
= pFrame
->GetBorderPixelImpl( pFrame
->GetViewShell() );
1103 Sequence
< sal_Int32
> aBorderSeq(4);
1104 aBorderSeq
[0] = aBorder
.Left();
1105 aBorderSeq
[1] = aBorder
.Top();
1106 aBorderSeq
[2] = aBorder
.Right();
1107 aBorderSeq
[3] = aBorder
.Bottom();
1109 seqArgsNew
.realloc( ++nNewLength
);
1110 seqArgsNew
[ nNewLength
- 1 ].Name
= ::rtl::OUString::createFromAscii( "DocumentBorder" );
1111 seqArgsNew
[ nNewLength
- 1 ].Value
<<= aBorderSeq
;
1114 // only the values that are not supported by the ItemSet must be cached here
1115 uno::Sequence
< beans::PropertyValue
> aFinalCache
;
1116 sal_Int32 nFinalLength
= 0;
1118 for ( sal_Int32 nOrg
= 0; nOrg
< nOrgLength
; nOrg
++ )
1120 sal_Int32 nOldInd
= 0;
1121 while ( nOldInd
< nOldLength
)
1123 if ( m_pData
->m_seqArguments
[nOrg
].Name
.equals( seqArgsOld
[nOldInd
].Name
) )
1128 if ( nOldInd
== nOldLength
)
1130 // the entity with this name should be new for seqArgsNew
1131 // since it is not supported by transformer
1133 seqArgsNew
.realloc( ++nNewLength
);
1134 seqArgsNew
[ nNewLength
- 1 ] = m_pData
->m_seqArguments
[nOrg
];
1136 aFinalCache
.realloc( ++nFinalLength
);
1137 aFinalCache
[ nFinalLength
- 1 ] = m_pData
->m_seqArguments
[nOrg
];
1141 m_pData
->m_seqArguments
= aFinalCache
;
1146 return m_pData
->m_seqArguments
;
1149 //________________________________________________________________________________________________________
1151 //________________________________________________________________________________________________________
1153 void SAL_CALL
SfxBaseModel::connectController( const uno::Reference
< frame::XController
>& xController
)
1154 throw(::com::sun::star::uno::RuntimeException
)
1156 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1157 if ( impl_isDisposed() )
1158 throw lang::DisposedException();
1160 sal_uInt32 nOldCount
= m_pData
->m_seqControllers
.getLength();
1161 uno::Sequence
< uno::Reference
< frame::XController
> > aNewSeq( nOldCount
+ 1 );
1162 for ( sal_uInt32 n
= 0; n
< nOldCount
; n
++ )
1163 aNewSeq
.getArray()[n
] = m_pData
->m_seqControllers
.getConstArray()[n
];
1164 aNewSeq
.getArray()[nOldCount
] = xController
;
1165 m_pData
->m_seqControllers
= aNewSeq
;
1168 //________________________________________________________________________________________________________
1170 //________________________________________________________________________________________________________
1172 void SAL_CALL
SfxBaseModel::disconnectController( const uno::Reference
< frame::XController
>& xController
) throw(::com::sun::star::uno::RuntimeException
)
1174 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1175 if ( impl_isDisposed() )
1176 throw lang::DisposedException();
1178 sal_uInt32 nOldCount
= m_pData
->m_seqControllers
.getLength();
1182 uno::Sequence
< uno::Reference
< frame::XController
> > aNewSeq( nOldCount
- 1 );
1183 for ( sal_uInt32 nOld
= 0, nNew
= 0; nOld
< nOldCount
; ++nOld
)
1185 if ( xController
!= m_pData
->m_seqControllers
.getConstArray()[nOld
] )
1187 aNewSeq
.getArray()[nNew
] = m_pData
->m_seqControllers
.getConstArray()[nOld
];
1192 m_pData
->m_seqControllers
= aNewSeq
;
1194 if ( xController
== m_pData
->m_xCurrent
)
1195 m_pData
->m_xCurrent
= uno::Reference
< frame::XController
> ();
1198 //________________________________________________________________________________________________________
1200 //________________________________________________________________________________________________________
1202 void SAL_CALL
SfxBaseModel::lockControllers() throw(::com::sun::star::uno::RuntimeException
)
1204 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1205 if ( impl_isDisposed() )
1206 throw lang::DisposedException();
1207 ++m_pData
->m_nControllerLockCount
;
1210 //________________________________________________________________________________________________________
1212 //________________________________________________________________________________________________________
1214 void SAL_CALL
SfxBaseModel::unlockControllers() throw(::com::sun::star::uno::RuntimeException
)
1216 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1217 if ( impl_isDisposed() )
1218 throw lang::DisposedException();
1219 --m_pData
->m_nControllerLockCount
;
1222 //________________________________________________________________________________________________________
1224 //________________________________________________________________________________________________________
1226 sal_Bool SAL_CALL
SfxBaseModel::hasControllersLocked() throw(::com::sun::star::uno::RuntimeException
)
1228 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1229 if ( impl_isDisposed() )
1230 throw lang::DisposedException();
1231 return ( m_pData
->m_nControllerLockCount
!= 0 ) ;
1234 //________________________________________________________________________________________________________
1236 //________________________________________________________________________________________________________
1238 uno::Reference
< frame::XController
> SAL_CALL
SfxBaseModel::getCurrentController() throw(::com::sun::star::uno::RuntimeException
)
1240 // object already disposed?
1241 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1242 if ( impl_isDisposed() )
1243 throw lang::DisposedException();
1245 // get the last active controller of this model
1246 if ( m_pData
->m_xCurrent
.is() )
1247 return m_pData
->m_xCurrent
;
1249 // get the first controller of this model
1250 return m_pData
->m_seqControllers
.getLength() ? m_pData
->m_seqControllers
.getConstArray()[0] : m_pData
->m_xCurrent
;
1253 //________________________________________________________________________________________________________
1255 //________________________________________________________________________________________________________
1257 void SAL_CALL
SfxBaseModel::setCurrentController( const uno::Reference
< frame::XController
>& xCurrentController
)
1258 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
)
1260 // object already disposed?
1261 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1262 if ( impl_isDisposed() )
1263 throw lang::DisposedException();
1265 m_pData
->m_xCurrent
= xCurrentController
;
1268 //________________________________________________________________________________________________________
1270 //________________________________________________________________________________________________________
1272 uno::Reference
< uno::XInterface
> SAL_CALL
SfxBaseModel::getCurrentSelection() throw(::com::sun::star::uno::RuntimeException
)
1274 // object already disposed?
1275 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1276 if ( impl_isDisposed() )
1277 throw lang::DisposedException();
1279 uno::Reference
< uno::XInterface
> xReturn
;
1280 uno::Reference
< frame::XController
> xController
= getCurrentController() ;
1282 if ( xController
.is() )
1284 uno::Reference
< view::XSelectionSupplier
> xDocView( xController
, uno::UNO_QUERY
);
1285 if ( xDocView
.is() )
1287 uno::Any xSel
= xDocView
->getSelection();
1295 //________________________________________________________________________________________________________
1297 //________________________________________________________________________________________________________
1299 sal_Bool SAL_CALL
SfxBaseModel::disableSetModified() throw (::com::sun::star::uno::RuntimeException
)
1301 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1302 if ( impl_isDisposed() )
1303 throw DISPOSEDEXCEPTION();
1305 if ( !m_pData
->m_pObjectShell
.Is() )
1306 throw uno::RuntimeException();
1308 sal_Bool bResult
= m_pData
->m_pObjectShell
->IsEnableSetModified();
1309 m_pData
->m_pObjectShell
->EnableSetModified( sal_False
);
1314 sal_Bool SAL_CALL
SfxBaseModel::enableSetModified() throw (::com::sun::star::uno::RuntimeException
)
1316 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1317 if ( impl_isDisposed() )
1318 throw DISPOSEDEXCEPTION();
1320 if ( !m_pData
->m_pObjectShell
.Is() )
1321 throw uno::RuntimeException();
1323 sal_Bool bResult
= m_pData
->m_pObjectShell
->IsEnableSetModified();
1324 m_pData
->m_pObjectShell
->EnableSetModified( sal_True
);
1329 sal_Bool SAL_CALL
SfxBaseModel::isSetModifiedEnabled() throw (::com::sun::star::uno::RuntimeException
)
1331 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1332 if ( impl_isDisposed() )
1333 throw DISPOSEDEXCEPTION();
1335 if ( !m_pData
->m_pObjectShell
.Is() )
1336 throw uno::RuntimeException();
1338 return m_pData
->m_pObjectShell
->IsEnableSetModified();
1341 //________________________________________________________________________________________________________
1343 //________________________________________________________________________________________________________
1345 sal_Bool SAL_CALL
SfxBaseModel::isModified() throw(::com::sun::star::uno::RuntimeException
)
1347 // object already disposed?
1348 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1349 if ( impl_isDisposed() )
1350 throw lang::DisposedException();
1352 return m_pData
->m_pObjectShell
.Is() ? m_pData
->m_pObjectShell
->IsModified() : sal_False
;
1355 //________________________________________________________________________________________________________
1357 //________________________________________________________________________________________________________
1359 void SAL_CALL
SfxBaseModel::setModified( sal_Bool bModified
)
1360 throw (::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::uno::RuntimeException
)
1362 // object already disposed?
1363 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1364 if ( impl_isDisposed() )
1365 throw lang::DisposedException();
1367 if ( m_pData
->m_pObjectShell
.Is() )
1368 m_pData
->m_pObjectShell
->SetModified(bModified
);
1371 //________________________________________________________________________________________________________
1373 //________________________________________________________________________________________________________
1375 void SAL_CALL
SfxBaseModel::addModifyListener(const uno::Reference
< XMODIFYLISTENER
>& xListener
) throw( uno::RuntimeException
)
1377 // object already disposed?
1378 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1379 if ( impl_isDisposed() )
1382 m_pData
->m_aInterfaceContainer
.addInterface( ::getCppuType((const uno::Reference
< XMODIFYLISTENER
>*)0),xListener
);
1385 //________________________________________________________________________________________________________
1387 //________________________________________________________________________________________________________
1389 void SAL_CALL
SfxBaseModel::removeModifyListener(const uno::Reference
< XMODIFYLISTENER
>& xListener
) throw( uno::RuntimeException
)
1391 // object already disposed?
1392 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1393 if ( impl_isDisposed() )
1396 m_pData
->m_aInterfaceContainer
.removeInterface( ::getCppuType((const uno::Reference
< XMODIFYLISTENER
>*)0), xListener
);
1399 //____________________________________________________________________________________________________
1401 //____________________________________________________________________________________________________
1403 void SAL_CALL
SfxBaseModel::close( sal_Bool bDeliverOwnership
) throw (util::CloseVetoException
, uno::RuntimeException
)
1405 static ::rtl::OUString MSG_1
= ::rtl::OUString::createFromAscii("Cant close while saving.");
1407 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1408 if ( !m_pData
|| m_pData
->m_bClosed
|| m_pData
->m_bClosing
)
1411 uno::Reference
< uno::XInterface
> xSelfHold( static_cast< ::cppu::OWeakObject
* >(this) );
1412 lang::EventObject
aSource (static_cast< ::cppu::OWeakObject
*>(this));
1413 ::cppu::OInterfaceContainerHelper
* pContainer
= m_pData
->m_aInterfaceContainer
.getContainer( ::getCppuType( ( const uno::Reference
< util::XCloseListener
>*) NULL
) );
1414 if (pContainer
!=NULL
)
1416 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
1417 while (pIterator
.hasMoreElements())
1421 ((util::XCloseListener
*)pIterator
.next())->queryClosing( aSource
, bDeliverOwnership
);
1423 catch( uno::RuntimeException
& )
1430 if ( m_pData
->m_bSaving
)
1432 if (bDeliverOwnership
)
1433 m_pData
->m_bSuicide
= sal_True
;
1434 throw util::CloseVetoException(
1436 static_cast< ::com::sun::star::util::XCloseable
* >(this));
1439 // no own objections against closing!
1440 m_pData
->m_bClosing
= sal_True
;
1441 pContainer
= m_pData
->m_aInterfaceContainer
.getContainer( ::getCppuType( ( const uno::Reference
< util::XCloseListener
>*) NULL
) );
1442 if (pContainer
!=NULL
)
1444 ::cppu::OInterfaceIteratorHelper
pCloseIterator(*pContainer
);
1445 while (pCloseIterator
.hasMoreElements())
1449 ((util::XCloseListener
*)pCloseIterator
.next())->notifyClosing( aSource
);
1451 catch( uno::RuntimeException
& )
1453 pCloseIterator
.remove();
1458 m_pData
->m_bClosed
= sal_True
;
1459 m_pData
->m_bClosing
= sal_False
;
1464 //____________________________________________________________________________________________________
1465 // XCloseBroadcaster
1466 //____________________________________________________________________________________________________
1468 void SAL_CALL
SfxBaseModel::addCloseListener( const uno::Reference
< XCLOSELISTENER
>& xListener
) throw (uno::RuntimeException
)
1470 // object already disposed?
1471 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1472 if ( impl_isDisposed() )
1475 m_pData
->m_aInterfaceContainer
.addInterface( ::getCppuType((const uno::Reference
< XCLOSELISTENER
>*)0), xListener
);
1478 //____________________________________________________________________________________________________
1479 // XCloseBroadcaster
1480 //____________________________________________________________________________________________________
1482 void SAL_CALL
SfxBaseModel::removeCloseListener( const uno::Reference
< XCLOSELISTENER
>& xListener
) throw (uno::RuntimeException
)
1484 // object already disposed?
1485 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1486 if ( impl_isDisposed() )
1489 m_pData
->m_aInterfaceContainer
.removeInterface( ::getCppuType((const uno::Reference
< XCLOSELISTENER
>*)0), xListener
);
1492 //________________________________________________________________________________________________________
1494 //________________________________________________________________________________________________________
1496 uno::Sequence
< beans::PropertyValue
> SAL_CALL
SfxBaseModel::getPrinter() throw(::com::sun::star::uno::RuntimeException
)
1498 // object already disposed?
1499 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1500 if ( impl_isDisposed() )
1501 throw lang::DisposedException();
1503 if ( impl_getPrintHelper() )
1504 return m_pData
->m_xPrintable
->getPrinter();
1506 return uno::Sequence
< beans::PropertyValue
>();
1509 void SAL_CALL
SfxBaseModel::setPrinter(const uno::Sequence
< beans::PropertyValue
>& rPrinter
)
1510 throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
1512 // object already disposed?
1513 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1514 if ( impl_isDisposed() )
1515 throw lang::DisposedException();
1517 if ( impl_getPrintHelper() )
1518 m_pData
->m_xPrintable
->setPrinter( rPrinter
);
1521 void SAL_CALL
SfxBaseModel::print(const uno::Sequence
< beans::PropertyValue
>& rOptions
)
1522 throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
1524 // object already disposed?
1525 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1526 if ( impl_isDisposed() )
1527 throw lang::DisposedException();
1529 if ( impl_getPrintHelper() )
1530 m_pData
->m_xPrintable
->print( rOptions
);
1533 //________________________________________________________________________________________________________
1535 //________________________________________________________________________________________________________
1537 sal_Bool SAL_CALL
SfxBaseModel::hasLocation() throw(::com::sun::star::uno::RuntimeException
)
1539 // object already disposed?
1540 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1541 if ( impl_isDisposed() )
1542 throw lang::DisposedException();
1544 return m_pData
->m_pObjectShell
.Is() ? m_pData
->m_pObjectShell
->HasName() : sal_False
;
1547 //________________________________________________________________________________________________________
1549 //________________________________________________________________________________________________________
1551 ::rtl::OUString SAL_CALL
SfxBaseModel::getLocation() throw(::com::sun::star::uno::RuntimeException
)
1553 // object already disposed?
1554 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1555 if ( impl_isDisposed() )
1556 throw lang::DisposedException();
1558 if ( m_pData
->m_pObjectShell
.Is() )
1560 // TODO/LATER: is it correct that the shared document returns shared file location?
1561 if ( m_pData
->m_pObjectShell
->IsDocShared() )
1562 return m_pData
->m_pObjectShell
->GetSharedFileURL();
1564 return ::rtl::OUString(m_pData
->m_pObjectShell
->GetMedium()->GetName());
1567 return m_pData
->m_sURL
;
1570 //________________________________________________________________________________________________________
1572 //________________________________________________________________________________________________________
1574 sal_Bool SAL_CALL
SfxBaseModel::isReadonly() throw(::com::sun::star::uno::RuntimeException
)
1576 // object already disposed?
1577 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1578 if ( impl_isDisposed() )
1579 throw lang::DisposedException();
1581 return m_pData
->m_pObjectShell
.Is() ? m_pData
->m_pObjectShell
->IsReadOnly() : sal_True
;
1584 //________________________________________________________________________________________________________
1586 //________________________________________________________________________________________________________
1588 void SAL_CALL
SfxBaseModel::storeSelf( const uno::Sequence
< beans::PropertyValue
>& aSeqArgs
)
1589 throw ( ::com::sun::star::lang::IllegalArgumentException
,
1590 ::com::sun::star::io::IOException
,
1591 ::com::sun::star::uno::RuntimeException
)
1593 RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog
, "PERFORMANCE - SfxBaseModel::storeSelf" );
1595 // object already disposed?
1596 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1597 if ( impl_isDisposed() )
1598 throw lang::DisposedException();
1600 if ( m_pData
->m_pObjectShell
.Is() )
1602 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"storeSelf" ) ) );
1603 SfxSaveGuard
aSaveGuard(this, m_pData
, sal_False
);
1605 for ( sal_Int32 nInd
= 0; nInd
< aSeqArgs
.getLength(); nInd
++ )
1607 // check that only acceptable parameters are provided here
1608 if ( !aSeqArgs
[nInd
].Name
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VersionComment" ) ) )
1609 && !aSeqArgs
[nInd
].Name
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Author" ) ) )
1610 && !aSeqArgs
[nInd
].Name
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) ) )
1611 && !aSeqArgs
[nInd
].Name
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ) ) )
1613 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"unexpected parameter for storeSelf, might be no problem if SaveAs is executed." ) ) );
1614 m_pData
->m_pObjectShell
->StoreLog();
1616 ::rtl::OUString
aMessage( RTL_CONSTASCII_USTRINGPARAM( "Unexpected MediaDescriptor parameter: " ) );
1617 aMessage
+= aSeqArgs
[nInd
].Name
;
1618 throw lang::IllegalArgumentException( aMessage
, uno::Reference
< uno::XInterface
>(), 1 );
1622 SfxAllItemSet
*pParams
= new SfxAllItemSet( SFX_APP()->GetPool() );
1623 TransformParameters( SID_SAVEDOC
, aSeqArgs
, *pParams
);
1625 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOC
, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOC
), m_pData
->m_pObjectShell
) );
1627 sal_Bool bRet
= sal_False
;
1629 // TODO/LATER: let the embedded case of saving be handled more careful
1630 if ( m_pData
->m_pObjectShell
->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED
)
1632 // If this is an embedded object that has no URL based location it should be stored to own storage.
1633 // An embedded object can have a location based on URL in case it is a link, then it should be
1634 // stored in normal way.
1635 if ( !hasLocation() || getLocation().compareToAscii( "private:", 8 ) == 0 )
1637 // actually in this very rare case only UI parameters have sence
1638 // TODO/LATER: should be done later, after integration of sb19
1639 bRet
= m_pData
->m_pObjectShell
->DoSave()
1640 && m_pData
->m_pObjectShell
->DoSaveCompleted();
1644 bRet
= m_pData
->m_pObjectShell
->Save_Impl( pParams
);
1648 bRet
= m_pData
->m_pObjectShell
->Save_Impl( pParams
);
1652 sal_uInt32 nErrCode
= m_pData
->m_pObjectShell
->GetError() ? m_pData
->m_pObjectShell
->GetError()
1653 : ERRCODE_IO_CANTWRITE
;
1654 m_pData
->m_pObjectShell
->ResetError();
1658 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"successful saving." ) ) );
1659 m_pData
->m_aPreusedFilterName
= GetMediumFilterName_Impl();
1661 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCDONE
, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCDONE
), m_pData
->m_pObjectShell
) );
1665 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Storing failed!" ) ) );
1666 m_pData
->m_pObjectShell
->StoreLog();
1668 // write the contents of the logger to the file
1669 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCFAILED
, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCFAILED
), m_pData
->m_pObjectShell
) );
1671 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference
< uno::XInterface
>(), nErrCode
);
1677 //________________________________________________________________________________________________________
1679 //________________________________________________________________________________________________________
1681 void SAL_CALL
SfxBaseModel::store() throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
1683 storeSelf( uno::Sequence
< beans::PropertyValue
>() );
1686 //________________________________________________________________________________________________________
1688 //________________________________________________________________________________________________________
1690 void SAL_CALL
SfxBaseModel::storeAsURL( const ::rtl::OUString
& rURL
,
1691 const uno::Sequence
< beans::PropertyValue
>& rArgs
)
1692 throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
1694 RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog
, "PERFORMANCE - SfxBaseModel::storeAsURL" );
1696 // object already disposed?
1697 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1698 if ( impl_isDisposed() )
1699 throw lang::DisposedException();
1701 if ( m_pData
->m_pObjectShell
.Is() )
1703 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"storeAsURL" ) ) );
1704 SfxSaveGuard
aSaveGuard(this, m_pData
, sal_False
);
1706 impl_store( rURL
, rArgs
, sal_False
);
1708 uno::Sequence
< beans::PropertyValue
> aSequence
;
1709 TransformItems( SID_OPENDOC
, *m_pData
->m_pObjectShell
->GetMedium()->GetItemSet(), aSequence
);
1710 attachResource( rURL
, aSequence
);
1714 //________________________________________________________________________________________________________
1716 //________________________________________________________________________________________________________
1718 void SAL_CALL
SfxBaseModel::storeToURL( const ::rtl::OUString
& rURL
,
1719 const uno::Sequence
< beans::PropertyValue
>& rArgs
)
1720 throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
1722 // object already disposed?
1723 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1724 if ( impl_isDisposed() )
1725 throw lang::DisposedException();
1727 if ( m_pData
->m_pObjectShell
.Is() )
1729 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"storeToURL" ) ) );
1730 SfxSaveGuard
aSaveGuard(this, m_pData
, sal_False
);
1731 impl_store( rURL
, rArgs
, sal_True
);
1735 //________________________________________________________________________________________________________
1737 //________________________________________________________________________________________________________
1739 void SAL_CALL
SfxBaseModel::initNew()
1740 throw (::com::sun::star::frame::DoubleInitializationException
,
1741 ::com::sun::star::io::IOException
,
1742 ::com::sun::star::uno::RuntimeException
,
1743 ::com::sun::star::uno::Exception
)
1745 // object already disposed?
1746 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1747 if ( impl_isDisposed() )
1748 throw lang::DisposedException();
1750 // the object shell should exist always
1751 DBG_ASSERT( m_pData
->m_pObjectShell
.Is(), "Model is useless without an ObjectShell" );
1752 if ( m_pData
->m_pObjectShell
.Is() )
1754 if( m_pData
->m_pObjectShell
->GetMedium() )
1755 throw DOUBLEINITIALIZATIONEXCEPTION();
1757 sal_Bool bRes
= m_pData
->m_pObjectShell
->DoInitNew( NULL
);
1758 sal_uInt32 nErrCode
= m_pData
->m_pObjectShell
->GetError() ?
1759 m_pData
->m_pObjectShell
->GetError() : ERRCODE_IO_CANTCREATE
;
1760 m_pData
->m_pObjectShell
->ResetError();
1763 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference
< uno::XInterface
>(), nErrCode
);
1767 //________________________________________________________________________________________________________
1769 //________________________________________________________________________________________________________
1771 void SAL_CALL
SfxBaseModel::load( const uno::Sequence
< beans::PropertyValue
>& seqArguments
)
1772 throw (::com::sun::star::frame::DoubleInitializationException
,
1773 ::com::sun::star::io::IOException
,
1774 ::com::sun::star::uno::RuntimeException
,
1775 ::com::sun::star::uno::Exception
)
1777 // object already disposed?
1778 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1779 if ( impl_isDisposed() )
1780 throw lang::DisposedException();
1782 // the object shell should exist always
1783 DBG_ASSERT( m_pData
->m_pObjectShell
.Is(), "Model is useless without an ObjectShell" );
1785 if ( m_pData
->m_pObjectShell
.Is() )
1787 if( m_pData
->m_pObjectShell
->GetMedium() )
1788 // if a Medium is present, the document is already initialized
1789 throw DOUBLEINITIALIZATIONEXCEPTION();
1791 SfxMedium
* pMedium
= new SfxMedium( seqArguments
);
1793 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pFilterNameItem
, SfxStringItem
, SID_FILTER_NAME
, sal_False
);
1794 if( pFilterNameItem
)
1795 aFilterName
= pFilterNameItem
->GetValue();
1796 if( !m_pData
->m_pObjectShell
->GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName
) )
1798 // filtername is not valid
1800 throw frame::IllegalArgumentIOException();
1803 // !TODO: currently not working
1804 //SFX_ITEMSET_ARG( pParams, pFrameItem, SfxFrameItem, SID_DOCFRAME, FALSE );
1805 //if( pFrameItem && pFrameItem->GetFrame() )
1807 // SfxFrame* pFrame = pFrameItem->GetFrame();
1808 // pMedium->SetLoadTargetFrame( pFrame );
1811 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pSalvageItem
, SfxStringItem
, SID_DOC_SALVAGE
, sal_False
);
1812 sal_Bool bSalvage
= pSalvageItem
? sal_True
: sal_False
;
1814 // SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
1815 // sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
1817 // does already happen in DoLoad call
1818 //m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
1821 sal_uInt32 nError
= ERRCODE_NONE
;
1822 if ( !m_pData
->m_pObjectShell
->DoLoad(pMedium
) )
1823 nError
=ERRCODE_IO_GENERAL
;
1825 // QUESTION: if the following happens outside of DoLoad, something important is missing there!
1826 ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionHandler
> xHandler
= pMedium
->GetInteractionHandler();
1827 if( m_pData
->m_pObjectShell
->GetErrorCode() )
1829 nError
= m_pData
->m_pObjectShell
->GetErrorCode();
1830 if ( nError
== ERRCODE_IO_BROKENPACKAGE
&& xHandler
.is() )
1832 ::rtl::OUString aDocName
= pMedium
->GetURLObject().getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
1833 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pRepairItem
, SfxBoolItem
, SID_REPAIRPACKAGE
, FALSE
);
1834 if ( !pRepairItem
|| !pRepairItem
->GetValue() )
1836 RequestPackageReparation
* pRequest
= new RequestPackageReparation( aDocName
);
1837 com::sun::star::uno::Reference
< com::sun::star::task::XInteractionRequest
> xRequest ( pRequest
);
1838 xHandler
->handle( xRequest
);
1839 if( pRequest
->isApproved() )
1841 // broken package: try second loading and allow repair
1842 pMedium
->GetItemSet()->Put( SfxBoolItem( SID_REPAIRPACKAGE
, sal_True
) );
1843 pMedium
->GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE
, sal_True
) );
1844 pMedium
->GetItemSet()->Put( SfxStringItem( SID_DOCINFO_TITLE
, aDocName
) );
1846 // the error must be reset and the storage must be reopened in new mode
1847 pMedium
->ResetError();
1848 pMedium
->CloseStorage();
1849 m_pData
->m_pObjectShell
->PrepareSecondTryLoad_Impl();
1850 if ( !m_pData
->m_pObjectShell
->DoLoad(pMedium
) )
1851 nError
=ERRCODE_IO_GENERAL
;
1852 nError
= m_pData
->m_pObjectShell
->GetErrorCode();
1856 if ( nError
== ERRCODE_IO_BROKENPACKAGE
)
1858 // repair either not allowed or not successful
1859 NotifyBrokenPackage
* pNotifyRequest
= new NotifyBrokenPackage( aDocName
);
1860 com::sun::star::uno::Reference
< com::sun::star::task::XInteractionRequest
> xRequest ( pNotifyRequest
);
1861 xHandler
->handle( xRequest
);
1866 if( m_pData
->m_pObjectShell
->IsAbortingImport() )
1867 nError
= ERRCODE_ABORT
;
1871 // file recovery: restore original filter
1872 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pFilterItem
, SfxStringItem
, SID_FILTER_NAME
, sal_False
);
1873 SfxFilterMatcher
& rMatcher
= SFX_APP()->GetFilterMatcher();
1874 const SfxFilter
* pSetFilter
= rMatcher
.GetFilter4FilterName( pFilterItem
->GetValue() );
1875 pMedium
->SetFilter( pSetFilter
);
1876 m_pData
->m_pObjectShell
->SetModified(sal_True
);
1879 // TODO/LATER: may be the mode should be retrieved from outside and the preused filter should not be set
1880 if ( m_pData
->m_pObjectShell
->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED
)
1882 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pFilterItem
, SfxStringItem
, SID_FILTER_NAME
, sal_False
);
1884 m_pData
->m_aPreusedFilterName
= pFilterItem
->GetValue();
1888 nError
= pMedium
->GetError();
1890 m_pData
->m_pObjectShell
->ResetError();
1894 BOOL bSilent
= FALSE
;
1895 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pSilentItem
, SfxBoolItem
, SID_SILENT
, sal_False
);
1897 bSilent
= pSilentItem
->GetValue();
1899 BOOL bWarning
= ((nError
& ERRCODE_WARNING_MASK
) == ERRCODE_WARNING_MASK
);
1900 if ( nError
!= ERRCODE_IO_BROKENPACKAGE
&& !bSilent
)
1902 // broken package was handled already
1903 if ( SfxObjectShell::UseInteractionToHandleError( xHandler
, nError
) && !bWarning
)
1905 // abort loading (except for warnings)
1906 nError
= ERRCODE_IO_ABORT
;
1910 if ( m_pData
->m_pObjectShell
->GetMedium() != pMedium
)
1912 // for whatever reason document now has another medium
1913 DBG_ERROR("Document has rejected the medium?!");
1917 if ( !bWarning
) // #i30711# don't abort loading if it's only a warning
1919 throw task::ErrorCodeIOException( ::rtl::OUString(),
1920 uno::Reference
< uno::XInterface
>(),
1921 nError
? nError
: ERRCODE_IO_CANTREAD
);
1927 //________________________________________________________________________________________________________
1929 //________________________________________________________________________________________________________
1931 uno::Any SAL_CALL
SfxBaseModel::getTransferData( const DATAFLAVOR
& aFlavor
)
1932 throw (::com::sun::star::datatransfer::UnsupportedFlavorException
,
1933 ::com::sun::star::io::IOException
,
1934 ::com::sun::star::uno::RuntimeException
)
1936 // object already disposed?
1937 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1938 if ( impl_isDisposed() )
1939 throw lang::DisposedException();
1943 if ( m_pData
->m_pObjectShell
.Is() )
1945 if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
1947 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
1949 TransferableObjectDescriptor aDesc
;
1951 aDesc
.maClassName
= m_pData
->m_pObjectShell
->GetClassName();
1952 aDesc
.maTypeName
= aFlavor
.HumanPresentableName
;
1954 // TODO/LATER: ViewAspect needs to be sal_Int64
1955 aDesc
.mnViewAspect
= sal::static_int_cast
< sal_uInt16
>( embed::Aspects::MSOLE_CONTENT
);
1957 //TODO/LATER: status needs to become sal_Int64
1958 aDesc
.mnOle2Misc
= m_pData
->m_pObjectShell
->GetMiscStatus();
1959 Size aSize
= m_pData
->m_pObjectShell
->GetVisArea().GetSize();
1961 MapUnit aMapUnit
= m_pData
->m_pObjectShell
->GetMapUnit();
1962 aDesc
.maSize
= OutputDevice::LogicToLogic( aSize
, aMapUnit
, MAP_100TH_MM
);
1963 aDesc
.maDragStartPos
= Point();
1964 aDesc
.maDisplayName
= String();
1965 aDesc
.mbCanLink
= FALSE
;
1967 SvMemoryStream
aMemStm( 1024, 1024 );
1969 aAny
<<= Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( aMemStm
.GetData() ), aMemStm
.Tell() );
1972 throw datatransfer::UnsupportedFlavorException();
1974 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
1976 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
1981 aTmp
.EnableKillingFile( TRUE
);
1982 storeToURL( aTmp
.GetURL(), uno::Sequence
< beans::PropertyValue
>() );
1983 SvStream
* pStream
= aTmp
.GetStream( STREAM_READ
);
1984 const sal_uInt32 nLen
= pStream
->Seek( STREAM_SEEK_TO_END
);
1985 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq( nLen
);
1986 pStream
->Seek( STREAM_SEEK_TO_BEGIN
);
1987 pStream
->Read( aSeq
.getArray(), nLen
);
1989 if( aSeq
.getLength() )
1992 catch ( uno::Exception
& )
1997 throw datatransfer::UnsupportedFlavorException();
1999 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2001 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2004 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
2005 m_pData
->m_pObjectShell
->GetPreviewMetaFile( sal_True
);
2009 SvMemoryStream
aMemStm( 65535, 65535 );
2010 aMemStm
.SetVersion( SOFFICE_FILEFORMAT_CURRENT
);
2012 pMetaFile
->Write( aMemStm
);
2013 aAny
<<= Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( aMemStm
.GetData() ),
2014 aMemStm
.Seek( STREAM_SEEK_TO_END
) );
2018 throw datatransfer::UnsupportedFlavorException();
2020 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2022 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2024 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
2025 m_pData
->m_pObjectShell
->CreatePreviewMetaFile_Impl( sal_True
, sal_True
);
2029 SvMemoryStream
aMemStm( 65535, 65535 );
2030 aMemStm
.SetVersion( SOFFICE_FILEFORMAT_CURRENT
);
2032 pMetaFile
->Write( aMemStm
);
2033 aAny
<<= Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( aMemStm
.GetData() ),
2034 aMemStm
.Seek( STREAM_SEEK_TO_END
) );
2038 throw datatransfer::UnsupportedFlavorException();
2040 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2042 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2044 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
2045 m_pData
->m_pObjectShell
->GetPreviewMetaFile( sal_True
);
2049 ::boost::shared_ptr
<SvMemoryStream
> pStream(
2050 GraphicHelper::getFormatStrFromGDI_Impl(
2051 pMetaFile
.get(), CVT_EMF
) );
2054 pStream
->SetVersion( SOFFICE_FILEFORMAT_CURRENT
);
2055 aAny
<<= Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( pStream
->GetData() ),
2056 pStream
->Seek( STREAM_SEEK_TO_END
) );
2060 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2061 && aFlavor
.DataType
== getCppuType( (const sal_uInt64
*) 0 ) )
2063 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
2064 m_pData
->m_pObjectShell
->GetPreviewMetaFile( sal_True
);
2068 aAny
<<= reinterpret_cast< const sal_uInt64
>(
2069 GraphicHelper::getEnhMetaFileFromGDI_Impl( pMetaFile
.get() ) );
2073 throw datatransfer::UnsupportedFlavorException();
2075 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2077 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2079 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
2080 m_pData
->m_pObjectShell
->GetPreviewMetaFile( sal_True
);
2084 ::boost::shared_ptr
<SvMemoryStream
> pStream(
2085 GraphicHelper::getFormatStrFromGDI_Impl(
2086 pMetaFile
.get(), CVT_WMF
) );
2090 pStream
->SetVersion( SOFFICE_FILEFORMAT_CURRENT
);
2091 aAny
<<= Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( pStream
->GetData() ),
2092 pStream
->Seek( STREAM_SEEK_TO_END
) );
2096 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2097 && aFlavor
.DataType
== getCppuType( (const sal_uInt64
*) 0 ) )
2099 // means HGLOBAL handler to memory storage containing METAFILEPICT structure
2101 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
2102 m_pData
->m_pObjectShell
->GetPreviewMetaFile( sal_True
);
2106 Size aMetaSize
= pMetaFile
->GetPrefSize();
2107 aAny
<<= reinterpret_cast< const sal_uInt64
>(
2108 GraphicHelper::getWinMetaFileFromGDI_Impl(
2109 pMetaFile
.get(), aMetaSize
) );
2113 throw datatransfer::UnsupportedFlavorException();
2115 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2117 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2119 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
2120 m_pData
->m_pObjectShell
->GetPreviewMetaFile( sal_True
);
2124 ::boost::shared_ptr
<SvMemoryStream
> pStream(
2125 GraphicHelper::getFormatStrFromGDI_Impl(
2126 pMetaFile
.get(), CVT_BMP
) );
2130 pStream
->SetVersion( SOFFICE_FILEFORMAT_CURRENT
);
2131 aAny
<<= Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( pStream
->GetData() ),
2132 pStream
->Seek( STREAM_SEEK_TO_END
) );
2137 throw datatransfer::UnsupportedFlavorException();
2139 else if ( aFlavor
.MimeType
.equalsAscii( "image/png" ) )
2141 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2143 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
2144 m_pData
->m_pObjectShell
->GetPreviewMetaFile( sal_True
);
2148 ::boost::shared_ptr
<SvMemoryStream
> pStream(
2149 GraphicHelper::getFormatStrFromGDI_Impl(
2150 pMetaFile
.get(), CVT_PNG
) );
2154 pStream
->SetVersion( SOFFICE_FILEFORMAT_CURRENT
);
2155 aAny
<<= Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( pStream
->GetData() ),
2156 pStream
->Seek( STREAM_SEEK_TO_END
) );
2161 throw datatransfer::UnsupportedFlavorException();
2164 throw datatransfer::UnsupportedFlavorException();
2170 //________________________________________________________________________________________________________
2172 //________________________________________________________________________________________________________
2175 uno::Sequence
< DATAFLAVOR
> SAL_CALL
SfxBaseModel::getTransferDataFlavors()
2176 throw (::com::sun::star::uno::RuntimeException
)
2178 // object already disposed?
2179 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2180 if ( impl_isDisposed() )
2181 throw lang::DisposedException();
2183 sal_Int32 nSuppFlavors
= GraphicHelper::supportsMetaFileHandle_Impl() ? 10 : 8;
2184 uno::Sequence
< DATAFLAVOR
> aFlavorSeq( nSuppFlavors
);
2186 aFlavorSeq
[0].MimeType
=
2187 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2188 aFlavorSeq
[0].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2189 aFlavorSeq
[0].DataType
= getCppuType( (const Sequence
< sal_Int8
>*) 0 );
2191 aFlavorSeq
[1].MimeType
=
2192 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2193 aFlavorSeq
[1].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2194 aFlavorSeq
[1].DataType
= getCppuType( (const Sequence
< sal_Int8
>*) 0 );
2196 aFlavorSeq
[2].MimeType
=
2197 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2198 aFlavorSeq
[2].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2199 aFlavorSeq
[2].DataType
= getCppuType( (const Sequence
< sal_Int8
>*) 0 );
2201 aFlavorSeq
[3].MimeType
=
2202 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2203 aFlavorSeq
[3].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2204 aFlavorSeq
[3].DataType
= getCppuType( (const Sequence
< sal_Int8
>*) 0 );
2206 aFlavorSeq
[4].MimeType
=
2207 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) );
2208 aFlavorSeq
[4].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Object Descriptor (XML)" ) );
2209 aFlavorSeq
[4].DataType
= getCppuType( (const Sequence
< sal_Int8
>*) 0 );
2211 aFlavorSeq
[5].MimeType
=
2212 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"" ) );
2213 aFlavorSeq
[5].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Embed Source (XML)" ) );
2214 aFlavorSeq
[5].DataType
= getCppuType( (const Sequence
< sal_Int8
>*) 0 );
2216 aFlavorSeq
[6].MimeType
=
2217 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) );
2218 aFlavorSeq
[6].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ) );
2219 aFlavorSeq
[6].DataType
= getCppuType( (const Sequence
< sal_Int8
>*) 0 );
2221 aFlavorSeq
[7].MimeType
=
2222 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) );
2223 aFlavorSeq
[7].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PNG" ) );
2224 aFlavorSeq
[7].DataType
= getCppuType( (const Sequence
< sal_Int8
>*) 0 );
2226 if ( nSuppFlavors
== 10 )
2228 aFlavorSeq
[8].MimeType
=
2229 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2230 aFlavorSeq
[8].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2231 aFlavorSeq
[8].DataType
= getCppuType( (const sal_uInt64
*) 0 );
2233 aFlavorSeq
[9].MimeType
=
2234 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2235 aFlavorSeq
[9].HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2236 aFlavorSeq
[9].DataType
= getCppuType( (const sal_uInt64
*) 0 );
2242 //________________________________________________________________________________________________________
2244 //________________________________________________________________________________________________________
2247 sal_Bool SAL_CALL
SfxBaseModel::isDataFlavorSupported( const DATAFLAVOR
& aFlavor
)
2248 throw (::com::sun::star::uno::RuntimeException
)
2250 // object already disposed?
2251 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2252 if ( impl_isDisposed() )
2253 throw lang::DisposedException();
2255 if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2257 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2260 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2262 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2265 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2267 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2269 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2270 && aFlavor
.DataType
== getCppuType( (const sal_uInt64
*) 0 ) )
2273 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2275 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2277 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2278 && aFlavor
.DataType
== getCppuType( (const sal_uInt64
*) 0 ) )
2281 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
2283 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2286 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
2288 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2291 else if ( aFlavor
.MimeType
.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2293 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2296 else if ( aFlavor
.MimeType
.equalsAscii( "image/png" ) )
2298 if ( aFlavor
.DataType
== getCppuType( (const Sequence
< sal_Int8
>*) 0 ) )
2306 //--------------------------------------------------------------------------------------------------------
2308 //--------------------------------------------------------------------------------------------------------
2310 uno::Reference
< container::XNameReplace
> SAL_CALL
SfxBaseModel::getEvents() throw( uno::RuntimeException
)
2312 // object already disposed?
2313 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2314 if ( impl_isDisposed() )
2315 throw lang::DisposedException();
2317 if ( ! m_pData
->m_xEvents
.is() )
2319 m_pData
->m_xEvents
= new SfxEvents_Impl( m_pData
->m_pObjectShell
, this );
2322 return m_pData
->m_xEvents
;
2325 //--------------------------------------------------------------------------------------------------------
2327 //--------------------------------------------------------------------------------------------------------
2329 uno::Reference
< script::XStorageBasedLibraryContainer
> SAL_CALL
SfxBaseModel::getBasicLibraries() throw (RuntimeException
)
2331 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2332 if ( impl_isDisposed() )
2333 throw lang::DisposedException();
2335 uno::Reference
< script::XStorageBasedLibraryContainer
> xBasicLibraries
;
2336 if ( m_pData
->m_pObjectShell
)
2337 xBasicLibraries
.set( m_pData
->m_pObjectShell
->GetBasicContainer(), UNO_QUERY_THROW
);
2338 return xBasicLibraries
;
2341 uno::Reference
< script::XStorageBasedLibraryContainer
> SAL_CALL
SfxBaseModel::getDialogLibraries() throw (RuntimeException
)
2343 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2344 if ( impl_isDisposed() )
2345 throw lang::DisposedException();
2347 uno::Reference
< script::XStorageBasedLibraryContainer
> xDialogLibraries
;
2348 if ( m_pData
->m_pObjectShell
)
2349 xDialogLibraries
.set( m_pData
->m_pObjectShell
->GetDialogContainer(), UNO_QUERY_THROW
);
2350 return xDialogLibraries
;
2353 ::sal_Bool SAL_CALL
SfxBaseModel::getAllowMacroExecution() throw (RuntimeException
)
2355 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2356 if ( impl_isDisposed() )
2357 throw lang::DisposedException();
2359 if ( m_pData
->m_pObjectShell
)
2360 return m_pData
->m_pObjectShell
->AdjustMacroMode( String(), false );
2364 //--------------------------------------------------------------------------------------------------------
2365 // XScriptInvocationContext
2366 //--------------------------------------------------------------------------------------------------------
2368 Reference
< document::XEmbeddedScripts
> SAL_CALL
SfxBaseModel::getScriptContainer() throw (RuntimeException
)
2370 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2371 if ( impl_isDisposed() )
2372 throw lang::DisposedException();
2374 Reference
< document::XEmbeddedScripts
> xDocumentScripts
;
2378 Reference
< frame::XModel
> xDocument( this );
2379 xDocumentScripts
.set( xDocument
, uno::UNO_QUERY
);
2380 while ( !xDocumentScripts
.is() && xDocument
.is() )
2382 Reference
< container::XChild
> xDocAsChild( xDocument
, uno::UNO_QUERY
);
2383 if ( !xDocAsChild
.is() )
2389 xDocument
.set( xDocAsChild
->getParent(), uno::UNO_QUERY
);
2390 xDocumentScripts
.set( xDocument
, uno::UNO_QUERY
);
2393 catch( const Exception
& )
2395 DBG_UNHANDLED_EXCEPTION();
2396 xDocumentScripts
= NULL
;
2399 return xDocumentScripts
;
2402 //--------------------------------------------------------------------------------------------------------
2403 // XEventBroadcaster
2404 //--------------------------------------------------------------------------------------------------------
2406 void SAL_CALL
SfxBaseModel::addEventListener( const uno::Reference
< XDOCEVENTLISTENER
>& aListener
) throw( uno::RuntimeException
)
2408 // object already disposed?
2409 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2410 if ( impl_isDisposed() )
2413 m_pData
->m_aInterfaceContainer
.addInterface( ::getCppuType((const uno::Reference
< XDOCEVENTLISTENER
>*)0), aListener
);
2416 //--------------------------------------------------------------------------------------------------------
2417 // XEventBroadcaster
2418 //--------------------------------------------------------------------------------------------------------
2420 void SAL_CALL
SfxBaseModel::removeEventListener( const uno::Reference
< XDOCEVENTLISTENER
>& aListener
) throw( uno::RuntimeException
)
2422 // object already disposed?
2423 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2424 if ( impl_isDisposed() )
2427 m_pData
->m_aInterfaceContainer
.removeInterface( ::getCppuType((const uno::Reference
< XDOCEVENTLISTENER
>*)0), aListener
);
2430 //________________________________________________________________________________________________________
2432 //________________________________________________________________________________________________________
2434 void addTitle_Impl( Sequence
< ::com::sun::star::beans::PropertyValue
>& rSeq
, const ::rtl::OUString
& rTitle
)
2436 sal_Int32 nCount
= rSeq
.getLength();
2439 for ( nArg
= 0; nArg
< nCount
; nArg
++ )
2441 ::com::sun::star::beans::PropertyValue
& rProp
= rSeq
[nArg
];
2442 if ( rProp
.Name
.equalsAscii("Title") )
2444 rProp
.Value
<<= rTitle
;
2449 if ( nArg
== nCount
)
2451 rSeq
.realloc( nCount
+1 );
2452 rSeq
[nCount
].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") );
2453 rSeq
[nCount
].Value
<<= rTitle
;
2457 void SfxBaseModel::NotifyStorageListeners_Impl()
2459 uno::Reference
< uno::XInterface
> xSelfHold( static_cast< ::cppu::OWeakObject
* >(this) );
2461 if ( m_pData
->m_pObjectShell
)
2463 ::cppu::OInterfaceContainerHelper
* pContainer
=
2464 m_pData
->m_aInterfaceContainer
.getContainer(
2465 ::getCppuType( ( const uno::Reference
< document::XStorageChangeListener
>*) NULL
) );
2466 if ( pContainer
!= NULL
)
2468 uno::Reference
< embed::XStorage
> xNewStorage
= m_pData
->m_pObjectShell
->GetStorage();
2469 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
2470 while ( pIterator
.hasMoreElements() )
2474 ((document::XStorageChangeListener
*)pIterator
.next())->notifyStorageChange(
2478 catch( uno::RuntimeException
& )
2487 void SfxBaseModel::Notify( SfxBroadcaster
& rBC
,
2488 const SfxHint
& rHint
)
2493 if ( &rBC
== m_pData
->m_pObjectShell
)
2495 SfxSimpleHint
* pSimpleHint
= PTR_CAST( SfxSimpleHint
, &rHint
);
2496 if ( pSimpleHint
&& pSimpleHint
->GetId() == SFX_HINT_DOCCHANGED
)
2499 SfxEventHint
* pNamedHint
= PTR_CAST( SfxEventHint
, &rHint
);
2503 if ( SFX_EVENT_STORAGECHANGED
== pNamedHint
->GetEventId() )
2505 // for now this event is sent only on creation of a new storage for new document
2506 // and in case of reload of medium without document reload
2507 // other events are used to detect storage change
2508 // NotifyStorageListeners_Impl();
2510 if ( m_pData
->m_xUIConfigurationManager
.is()
2511 && m_pData
->m_pObjectShell
->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED
)
2513 uno::Reference
< XSTORAGE
> xConfigStorage
;
2514 rtl::OUString
aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
2516 xConfigStorage
= getDocumentSubStorage( aUIConfigFolderName
, com::sun::star::embed::ElementModes::READWRITE
);
2517 if ( !xConfigStorage
.is() )
2518 xConfigStorage
= getDocumentSubStorage( aUIConfigFolderName
, com::sun::star::embed::ElementModes::READ
);
2520 if ( xConfigStorage
.is() || !m_pData
->m_pObjectShell
->GetStorage()->hasByName( aUIConfigFolderName
) )
2522 // the storage is different, since otherwise it could not be opened, so it must be exchanged
2523 Reference
< ui::XUIConfigurationStorage
> xUIConfigStorage( m_pData
->m_xUIConfigurationManager
, uno::UNO_QUERY
);
2524 xUIConfigStorage
->setStorage( xConfigStorage
);
2528 OSL_ENSURE( sal_False
, "Unexpected scenario!\n" );
2532 ListenForStorage_Impl( m_pData
->m_pObjectShell
->GetStorage() );
2534 else if ( SFX_EVENT_LOADFINISHED
== pNamedHint
->GetEventId() )
2536 impl_getPrintHelper();
2537 ListenForStorage_Impl( m_pData
->m_pObjectShell
->GetStorage() );
2539 else if ( SFX_EVENT_SAVEASDOCDONE
== pNamedHint
->GetEventId() )
2541 m_pData
->m_sURL
= m_pData
->m_pObjectShell
->GetMedium()->GetName();
2543 SfxItemSet
*pSet
= m_pData
->m_pObjectShell
->GetMedium()->GetItemSet();
2544 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs
;
2545 ::rtl::OUString aTitle
= m_pData
->m_pObjectShell
->GetTitle();
2546 TransformItems( SID_SAVEASDOC
, *pSet
, aArgs
);
2547 addTitle_Impl( aArgs
, aTitle
);
2548 attachResource( m_pData
->m_pObjectShell
->GetMedium()->GetName(), aArgs
);
2550 else if ( SFX_EVENT_DOCCREATED
== pNamedHint
->GetEventId() )
2552 impl_getPrintHelper();
2555 postEvent_Impl( pNamedHint
->GetEventName() );
2560 if ( pSimpleHint
->GetId() == SFX_HINT_TITLECHANGED
)
2562 ::rtl::OUString aTitle
= m_pData
->m_pObjectShell
->GetTitle();
2563 addTitle_Impl( m_pData
->m_seqArguments
, aTitle
);
2564 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_TITLECHANGED
) );
2566 if ( pSimpleHint
->GetId() == SFX_HINT_MODECHANGED
)
2568 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_MODECHANGED
) );
2571 else if ( pSimpleHint->GetId() == SFX_HINT_DYING
2572 || pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
2574 SfxObjectShellLock pShellLock = m_pData->m_pObjectShellLock;
2575 m_pData->m_pObjectShellLock = SfxObjectShellLock();
2582 //________________________________________________________________________________________________________
2584 //________________________________________________________________________________________________________
2586 void SfxBaseModel::changing()
2588 // object already disposed?
2589 // object already disposed?
2590 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2591 if ( impl_isDisposed() )
2594 // the notification should not be sent if the document can not be modified
2595 if ( !m_pData
->m_pObjectShell
.Is() || !m_pData
->m_pObjectShell
->IsEnableSetModified() )
2598 ::cppu::OInterfaceContainerHelper
* pIC
= m_pData
->m_aInterfaceContainer
.getContainer( ::getCppuType((const uno::Reference
< XMODIFYLISTENER
>*)0) );
2602 lang::EventObject
aEvent( (frame::XModel
*)this );
2603 ::cppu::OInterfaceIteratorHelper
aIt( *pIC
);
2604 while( aIt
.hasMoreElements() )
2608 ((XMODIFYLISTENER
*)aIt
.next())->modified( aEvent
);
2610 catch( uno::RuntimeException
& )
2618 void SfxBaseModel::impl_change()
2620 // object already disposed?
2621 if ( impl_isDisposed() )
2624 ::cppu::OInterfaceContainerHelper
* pIC
= m_pData
->m_aInterfaceContainer
.getContainer( ::getCppuType((const uno::Reference
< XMODIFYLISTENER
>*)0) );
2628 lang::EventObject
aEvent( (frame::XModel
*)this );
2629 ::cppu::OInterfaceIteratorHelper
aIt( *pIC
);
2630 while( aIt
.hasMoreElements() )
2634 ((XMODIFYLISTENER
*)aIt
.next())->modified( aEvent
);
2636 catch( uno::RuntimeException
& )
2644 //________________________________________________________________________________________________________
2646 //________________________________________________________________________________________________________
2648 SfxObjectShell
* SfxBaseModel::GetObjectShell() const
2650 return m_pData
? (SfxObjectShell
*) m_pData
->m_pObjectShell
: 0;
2653 SfxObjectShell
* SfxBaseModel::impl_getObjectShell() const
2655 return m_pData
? (SfxObjectShell
*) m_pData
->m_pObjectShell
: 0;
2658 //________________________________________________________________________________________________________
2660 //________________________________________________________________________________________________________
2662 sal_Bool
SfxBaseModel::IsDisposed() const
2664 return ( m_pData
== NULL
) ;
2667 sal_Bool
SfxBaseModel::impl_isDisposed() const
2669 return ( m_pData
== NULL
) ;
2672 //________________________________________________________________________________________________________
2674 //________________________________________________________________________________________________________
2676 ::rtl::OUString
SfxBaseModel::GetMediumFilterName_Impl()
2678 const SfxFilter
* pFilter
= NULL
;
2679 SfxMedium
* pMedium
= m_pData
->m_pObjectShell
->GetMedium();
2681 pFilter
= pMedium
->GetFilter();
2684 return pFilter
->GetName();
2686 return ::rtl::OUString();
2689 void SfxBaseModel::impl_store( const ::rtl::OUString
& sURL
,
2690 const uno::Sequence
< beans::PropertyValue
>& seqArguments
,
2693 if( !sURL
.getLength() )
2694 throw frame::IllegalArgumentIOException();
2696 //sal_Bool aSaveAsTemplate = sal_False;
2698 sal_Bool bSaved
= sal_False
;
2699 if ( !bSaveTo
&& m_pData
->m_pObjectShell
&& sURL
.getLength()
2700 && sURL
.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL
2701 && SfxMedium::EqualURLs( getLocation(), sURL
) )
2703 // this is the same file URL as the current document location, try to use storeOwn if possible
2705 ::comphelper::SequenceAsHashMap
aArgHash( seqArguments
);
2706 ::rtl::OUString
aFilterString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
2707 ::rtl::OUString aFilterName
= aArgHash
.getUnpackedValueOrDefault( aFilterString
, ::rtl::OUString() );
2708 if ( aFilterName
.getLength() )
2710 SfxMedium
* pMedium
= m_pData
->m_pObjectShell
->GetMedium();
2713 const SfxFilter
* pFilter
= pMedium
->GetFilter();
2714 if ( pFilter
&& aFilterName
.equals( pFilter
->GetFilterName() ) )
2716 aArgHash
.erase( aFilterString
);
2717 aArgHash
.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
2719 // if the password is changed SaveAs should be done
2720 // no password for encrypted document is also a change here
2721 sal_Bool bPassChanged
= sal_False
;
2723 ::comphelper::SequenceAsHashMap::iterator aNewPassIter
2724 = aArgHash
.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ) );
2725 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pPasswordItem
, SfxStringItem
, SID_PASSWORD
, sal_False
);
2726 if ( pPasswordItem
&& aNewPassIter
!= aArgHash
.end() )
2728 ::rtl::OUString aNewPass
;
2729 aNewPassIter
->second
>>= aNewPass
;
2730 bPassChanged
= !aNewPass
.equals( pPasswordItem
->GetValue() );
2732 else if ( pPasswordItem
|| aNewPassIter
!= aArgHash
.end() )
2733 bPassChanged
= sal_True
;
2735 if ( !bPassChanged
)
2739 storeSelf( aArgHash
.getAsConstPropertyValueList() );
2742 catch( const lang::IllegalArgumentException
& )
2744 // some additional arguments do not allow to use saving, SaveAs should be done
2745 // but only for normal documents, the shared documents would be overwritten in this case
2746 // that would mean an information loss
2747 // TODO/LATER: need a new interaction for this case
2748 if ( m_pData
->m_pObjectShell
->IsDocShared() )
2750 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Can't store shared document!" ) ) );
2751 m_pData
->m_pObjectShell
->StoreLog();
2757 else if ( m_pData
->m_pObjectShell
->IsDocShared() )
2759 // if the password is changed a special error should be used in case of shared document
2760 throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference
< uno::XInterface
>(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE
);
2767 if ( !bSaved
&& m_pData
->m_pObjectShell
)
2769 SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo
? SFX_EVENT_SAVETODOC
: SFX_EVENT_SAVEASDOC
, GlobalEventConfig::GetEventName( bSaveTo
? STR_EVENT_SAVETODOC
: STR_EVENT_SAVEASDOC
),
2770 m_pData
->m_pObjectShell
) );
2772 SfxAllItemSet
*aParams
= new SfxAllItemSet( SFX_APP()->GetPool() );
2773 aParams
->Put( SfxStringItem( SID_FILE_NAME
, String(sURL
) ) );
2775 aParams
->Put( SfxBoolItem( SID_SAVETO
, sal_True
) );
2777 TransformParameters( SID_SAVEASDOC
, seqArguments
, *aParams
);
2779 SFX_ITEMSET_ARG( aParams
, pCopyStreamItem
, SfxBoolItem
, SID_COPY_STREAM_IF_POSSIBLE
, sal_False
);
2781 if ( pCopyStreamItem
&& pCopyStreamItem
->GetValue() && !bSaveTo
)
2783 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Misuse of CopyStreamIfPossible!" ) ) );
2784 m_pData
->m_pObjectShell
->StoreLog();
2786 throw frame::IllegalArgumentIOException(
2787 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!") ),
2788 uno::Reference
< uno::XInterface
>() );
2791 // since saving a document modifies its DocumentInfo, the current
2792 // DocumentInfo must be saved on "SaveTo", so it can be restored
2794 sal_Bool bCopyTo
= bSaveTo
||
2795 m_pData
->m_pObjectShell
->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED
;
2796 uno::Reference
<document::XDocumentProperties
> xOldDocProps
;
2797 uno::Reference
<document::XDocumentInfo
> xOldDocInfo
;
2800 xOldDocProps
= getDocumentProperties();
2801 if (m_pData
->m_xDocumentInfo
.is())
2803 xOldDocInfo
= getDocumentInfo();
2804 const Reference
<util::XCloneable
> xCloneable(xOldDocInfo
,
2806 const Reference
<document::XDocumentInfo
> xNewDocInfo(
2807 xCloneable
->createClone(), UNO_QUERY_THROW
);
2808 const Reference
<document::XDocumentPropertiesSupplier
> xDPS(
2809 xNewDocInfo
, UNO_QUERY_THROW
);
2810 const Reference
<document::XDocumentProperties
> xNewDocProps(
2811 xDPS
->getDocumentProperties());
2812 m_pData
->m_xDocumentProperties
= xNewDocProps
;
2813 m_pData
->m_xDocumentInfo
= xNewDocInfo
;
2815 else // try not to create DocumentInfo if it does not exist...
2817 const Reference
<util::XCloneable
> xCloneable(xOldDocProps
,
2819 const Reference
<document::XDocumentProperties
> xNewDocProps(
2820 xCloneable
->createClone(), UNO_QUERY_THROW
);
2821 m_pData
->m_xDocumentProperties
= xNewDocProps
;
2825 sal_Bool bRet
= m_pData
->m_pObjectShell
->APISaveAs_Impl( sURL
, aParams
);
2829 // restore DocumentInfo if a copy was created
2830 m_pData
->m_xDocumentProperties
= xOldDocProps
;
2831 m_pData
->m_xDocumentInfo
= xOldDocInfo
;
2834 uno::Reference
< task::XInteractionHandler
> xHandler
;
2835 SFX_ITEMSET_ARG( aParams
, pItem
, SfxUnoAnyItem
, SID_INTERACTIONHANDLER
, sal_False
);
2837 pItem
->GetValue() >>= xHandler
;
2841 sal_uInt32 nErrCode
= m_pData
->m_pObjectShell
->GetErrorCode();
2842 if ( !bRet
&& !nErrCode
)
2844 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Storing has failed, no error is set!" ) ) );
2845 nErrCode
= ERRCODE_IO_CANTWRITE
;
2847 m_pData
->m_pObjectShell
->ResetError();
2853 // must be a warning - use Interactionhandler if possible or abandone
2854 if ( xHandler
.is() )
2856 // TODO/LATER: a general way to set the error context should be available
2857 SfxErrorContext
aEc( ERRCTX_SFX_SAVEASDOC
, m_pData
->m_pObjectShell
->GetTitle() );
2859 ::com::sun::star::task::ErrorCodeRequest aErrorCode
;
2860 aErrorCode
.ErrCode
= nErrCode
;
2861 SfxMedium::CallApproveHandler( xHandler
, uno::makeAny( aErrorCode
), sal_False
);
2865 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Storing succeeded!" ) ) );
2868 m_pData
->m_aPreusedFilterName
= GetMediumFilterName_Impl();
2869 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE
, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE
), m_pData
->m_pObjectShell
) );
2873 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE
, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE
), m_pData
->m_pObjectShell
) );
2878 // let the logring be stored to the related file
2879 m_pData
->m_pObjectShell
->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Storing failed!" ) ) );
2880 m_pData
->m_pObjectShell
->StoreLog();
2882 SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo
? SFX_EVENT_SAVETODOCFAILED
: SFX_EVENT_SAVEASDOCFAILED
, GlobalEventConfig::GetEventName( bSaveTo
? STR_EVENT_SAVETODOCFAILED
: STR_EVENT_SAVEASDOCFAILED
),
2883 m_pData
->m_pObjectShell
) );
2885 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference
< uno::XInterface
>(), nErrCode
);
2890 //********************************************************************************************************
2892 void SfxBaseModel::postEvent_Impl( ::rtl::OUString aName
)
2894 // object already disposed?
2895 if ( impl_isDisposed() )
2898 DBG_ASSERT( aName
.getLength(), "Empty event name!" );
2899 if (!aName
.getLength())
2902 ::cppu::OInterfaceContainerHelper
* pIC
= m_pData
->m_aInterfaceContainer
.getContainer(
2903 ::getCppuType((const uno::Reference
< XDOCEVENTLISTENER
>*)0) );
2908 ByteString
aTmp( "SfxEvent: ");
2909 aTmp
+= ByteString( String(aName
), RTL_TEXTENCODING_UTF8
);
2910 DBG_TRACE( aTmp
.GetBuffer() );
2912 document::EventObject
aEvent( (frame::XModel
*)this, aName
);
2913 ::cppu::OInterfaceContainerHelper
aIC( m_aMutex
);
2914 uno::Sequence
< uno::Reference
< uno::XInterface
> > aElements
= pIC
->getElements();
2915 for ( sal_Int32 nElem
=0; nElem
<aElements
.getLength(); nElem
++ )
2916 aIC
.addInterface( aElements
[nElem
] );
2917 ::cppu::OInterfaceIteratorHelper
aIt( aIC
);
2918 while( aIt
.hasMoreElements() )
2922 ((XDOCEVENTLISTENER
*)aIt
.next())->notifyEvent( aEvent
);
2924 catch( uno::RuntimeException
& )
2932 uno::Reference
< container::XIndexAccess
> SAL_CALL
SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException
)
2934 // object already disposed?
2935 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2936 if ( impl_isDisposed() )
2937 throw lang::DisposedException();
2939 if ( m_pData
->m_pObjectShell
.Is() && !m_pData
->m_contViewData
.is() )
2941 SfxViewFrame
*pActFrame
= SfxViewFrame::Current();
2942 if ( !pActFrame
|| pActFrame
->GetObjectShell() != m_pData
->m_pObjectShell
)
2943 pActFrame
= SfxViewFrame::GetFirst(m_pData
->m_pObjectShell
, TYPE(SfxTopViewFrame
));
2945 if ( !pActFrame
|| !pActFrame
->GetViewShell() )
2946 // currently no frame for this document at all or View is under construction
2947 return uno::Reference
< container::XIndexAccess
>();
2949 m_pData
->m_contViewData
= Reference
< container::XIndexAccess
>(
2950 ::comphelper::getProcessServiceFactory()->createInstance(
2951 DEFINE_CONST_UNICODE("com.sun.star.document.IndexedPropertyValues") ),
2954 if ( !m_pData
->m_contViewData
.is() )
2956 // error: no container class available!
2957 return uno::Reference
< container::XIndexAccess
>();
2960 uno::Reference
< container::XIndexContainer
> xCont( m_pData
->m_contViewData
, uno::UNO_QUERY
);
2961 sal_Int32 nCount
= 0;
2962 uno::Sequence
< beans::PropertyValue
> aSeq
;
2963 ::com::sun::star::uno::Any aAny
;
2964 for ( SfxViewFrame
*pFrame
= SfxViewFrame::GetFirst(m_pData
->m_pObjectShell
, TYPE(SfxTopViewFrame
) ); pFrame
;
2965 pFrame
= SfxViewFrame::GetNext(*pFrame
, m_pData
->m_pObjectShell
, TYPE(SfxTopViewFrame
) ) )
2967 BOOL bIsActive
= ( pFrame
== pActFrame
);
2968 pFrame
->GetViewShell()->WriteUserDataSequence( aSeq
);
2970 xCont
->insertByIndex( bIsActive
? 0 : nCount
, aAny
);
2975 return m_pData
->m_contViewData
;
2978 void SAL_CALL
SfxBaseModel::setViewData( const uno::Reference
< container::XIndexAccess
>& aData
) throw(::com::sun::star::uno::RuntimeException
)
2980 // object already disposed?
2981 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
2982 if ( impl_isDisposed() )
2983 throw lang::DisposedException();
2985 m_pData
->m_contViewData
= aData
;
2988 /** calls all XEventListeners */
2989 void SfxBaseModel::notifyEvent( const ::com::sun::star::document::EventObject
& aEvent
) const
2991 // object already disposed?
2992 if ( impl_isDisposed() )
2995 ::cppu::OInterfaceContainerHelper
* pIC
= m_pData
->m_aInterfaceContainer
.getContainer(
2996 ::getCppuType((const uno::Reference
< XDOCEVENTLISTENER
>*)0) );
3000 ::cppu::OInterfaceIteratorHelper
aIt( *pIC
);
3001 while( aIt
.hasMoreElements() )
3005 ((XDOCEVENTLISTENER
*)aIt
.next())->notifyEvent( aEvent
);
3007 catch( uno::RuntimeException
& )
3015 /** returns true if someone added a XEventListener to this XEventBroadcaster */
3016 sal_Bool
SfxBaseModel::hasEventListeners() const
3018 return !impl_isDisposed() && (NULL
!= m_pData
->m_aInterfaceContainer
.getContainer( ::getCppuType((const uno::Reference
< XDOCEVENTLISTENER
>*)0) ) );
3021 void SAL_CALL
SfxBaseModel::addPrintJobListener( const uno::Reference
< view::XPrintJobListener
>& xListener
) throw (uno::RuntimeException
)
3023 // object already disposed?
3024 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3025 if ( impl_isDisposed() )
3028 if ( impl_getPrintHelper() )
3030 uno::Reference
< view::XPrintJobBroadcaster
> xPJB( m_pData
->m_xPrintable
, uno::UNO_QUERY
);
3032 xPJB
->addPrintJobListener( xListener
);
3035 // m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3038 void SAL_CALL
SfxBaseModel::removePrintJobListener( const uno::Reference
< view::XPrintJobListener
>& xListener
) throw (uno::RuntimeException
)
3040 // object already disposed?
3041 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3042 if ( impl_isDisposed() )
3045 if ( impl_getPrintHelper() )
3047 uno::Reference
< view::XPrintJobBroadcaster
> xPJB( m_pData
->m_xPrintable
, uno::UNO_QUERY
);
3049 xPJB
->removePrintJobListener( xListener
);
3052 // m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3055 // simple declaration of class SvObject is enough
3056 // the corresponding <so3/iface.hxx> cannon be included because it provides
3057 // declaration of class SvBorder that conflicts with ../../inc/viewfrm.hxx
3059 sal_Int64 SAL_CALL
SfxBaseModel::getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
) throw(::com::sun::star::uno::RuntimeException
)
3061 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3062 if ( !impl_isDisposed() && GetObjectShell() )
3064 SvGlobalName
aName( aIdentifier
);
3065 if ( aName
== SvGlobalName( SO3_GLOBAL_CLASSID
) )
3066 return (sal_Int64
)(sal_IntPtr
)(SvObject
*)GetObjectShell();
3067 else if ( aName
== SvGlobalName( SFX_GLOBAL_CLASSID
) )
3068 return (sal_Int64
)(sal_IntPtr
)(SfxObjectShell
*)GetObjectShell();
3074 //____________________________________________________________________________________________________
3075 // XDocumentSubStorageSupplier
3076 //____________________________________________________________________________________________________
3078 void SfxBaseModel::ListenForStorage_Impl( const uno::Reference
< embed::XStorage
>& xStorage
)
3080 uno::Reference
< util::XModifiable
> xModifiable( xStorage
, uno::UNO_QUERY
);
3081 if ( xModifiable
.is() )
3083 if ( !m_pData
->m_pStorageModifyListen
.is() )
3085 m_pData
->m_pStorageModifyListen
= new ::sfx2::DocumentStorageModifyListener( *m_pData
, Application::GetSolarMutex() );
3088 // no need to deregister the listening for old storage since it should be disposed automatically
3089 xModifiable
->addModifyListener( m_pData
->m_pStorageModifyListen
.get() );
3093 uno::Reference
< XSTORAGE
> SAL_CALL
SfxBaseModel::getDocumentSubStorage( const ::rtl::OUString
& aStorageName
, sal_Int32 nMode
)
3094 throw ( uno::RuntimeException
)
3096 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3097 if ( impl_isDisposed() )
3098 throw lang::DisposedException();
3100 uno::Reference
< XSTORAGE
> xResult
;
3101 if ( m_pData
->m_pObjectShell
.Is() )
3103 uno::Reference
< embed::XStorage
> xStorage
= m_pData
->m_pObjectShell
->GetStorage();
3104 if ( xStorage
.is() )
3108 xResult
= xStorage
->openStorageElement( aStorageName
, nMode
);
3110 catch ( uno::Exception
& )
3119 Sequence
< ::rtl::OUString
> SAL_CALL
SfxBaseModel::getDocumentSubStoragesNames()
3120 throw ( io::IOException
,
3123 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3124 if ( impl_isDisposed() )
3125 throw lang::DisposedException();
3127 Sequence
< ::rtl::OUString
> aResult
;
3128 sal_Int32 nResultSize
= 0;
3129 sal_Bool bSuccess
= sal_False
;
3130 if ( m_pData
->m_pObjectShell
.Is() )
3132 uno::Reference
< embed::XStorage
> xStorage
= m_pData
->m_pObjectShell
->GetStorage();
3133 uno::Reference
< container::XNameAccess
> xAccess( xStorage
, uno::UNO_QUERY
);
3136 Sequence
< ::rtl::OUString
> aTemp
= xAccess
->getElementNames();
3137 for ( sal_Int32 n
= 0; n
< aTemp
.getLength(); n
++ )
3139 if ( xStorage
->isStorageElement( aTemp
[n
] ) )
3141 aResult
.realloc( ++nResultSize
);
3142 aResult
[ nResultSize
- 1 ] = aTemp
[n
];
3146 bSuccess
= sal_True
;
3151 throw io::IOException();
3156 //____________________________________________________________________________________________________
3157 // XScriptProviderSupplier
3158 //____________________________________________________________________________________________________
3161 uno::Reference
< script::provider::XScriptProvider
> SAL_CALL
SfxBaseModel::getScriptProvider()
3162 throw ( uno::RuntimeException
)
3164 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3165 if ( impl_isDisposed() )
3166 throw lang::DisposedException();
3168 uno::Reference
< script::provider::XScriptProvider
> xScriptProvider
;
3170 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
3171 Reference
< script::provider::XScriptProviderFactory
> xScriptProviderFactory(
3172 aContext
.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW
);
3176 Reference
< XScriptInvocationContext
> xScriptContext( this );
3177 xScriptProvider
.set( xScriptProviderFactory
->createScriptProvider( makeAny( xScriptContext
) ), uno::UNO_SET_THROW
);
3179 catch( const uno::RuntimeException
& )
3183 catch( const lang::IllegalArgumentException
& )
3185 throw lang::WrappedTargetRuntimeException(
3188 ::cppu::getCaughtException()
3192 return xScriptProvider
;
3195 //____________________________________________________________________________________________________
3196 // XUIConfigurationManagerSupplier
3197 //____________________________________________________________________________________________________
3199 rtl::OUString
SfxBaseModel::getRuntimeUID() const
3201 OSL_ENSURE( m_pData
->m_sRuntimeUID
.getLength() > 0,
3202 "SfxBaseModel::getRuntimeUID - ID is empty!" );
3203 return m_pData
->m_sRuntimeUID
;
3206 sal_Bool
SfxBaseModel::hasValidSignatures() const
3208 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3209 if ( m_pData
->m_pObjectShell
.Is() )
3210 return ( m_pData
->m_pObjectShell
->ImplGetSignatureState( sal_False
) == SIGNATURESTATE_SIGNATURES_OK
);
3214 static void GetCommandFromSequence( rtl::OUString
& rCommand
, sal_Int32
& nIndex
, const uno::Sequence
< beans::PropertyValue
>& rSeqPropValue
)
3216 rtl::OUString aCommand
;
3219 for ( sal_Int32 i
= 0; i
< rSeqPropValue
.getLength(); i
++ )
3221 if ( rSeqPropValue
[i
].Name
.equalsAsciiL( "Command", 7 ))
3223 rSeqPropValue
[i
].Value
>>= rCommand
;
3230 static void ConvertSlotsToCommands( SfxObjectShell
* pDoc
, uno::Reference
< container::XIndexContainer
>& rToolbarDefinition
)
3235 SfxModule
* pModule( pDoc
->GetFactory().GetModule() );
3236 rtl::OUString
aSlotCmd( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
3237 rtl::OUString
aUnoCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
3238 uno::Sequence
< beans::PropertyValue
> aSeqPropValue
;
3240 for ( sal_Int32 i
= 0; i
< rToolbarDefinition
->getCount(); i
++ )
3242 sal_Int32
nIndex( -1 );
3243 rtl::OUString aCommand
;
3245 if ( rToolbarDefinition
->getByIndex( i
) >>= aSeqPropValue
)
3247 GetCommandFromSequence( aCommand
, nIndex
, aSeqPropValue
);
3248 if ( nIndex
>= 0 && ( aCommand
.indexOf( aSlotCmd
) == 0 ))
3250 rtl::OUString
aSlot( aCommand
.copy( 5 ));
3252 // We have to replace the old "slot-Command" with our new ".uno:-Command"
3253 const SfxSlot
* pSlot
= pModule
->GetSlotPool()->GetSlot( USHORT( aSlot
.toInt32() ));
3256 rtl::OUStringBuffer
aStrBuf( aUnoCmd
);
3257 aStrBuf
.appendAscii( pSlot
->GetUnoName() );
3259 aCommand
= aStrBuf
.makeStringAndClear();
3260 aSeqPropValue
[nIndex
].Value
<<= aCommand
;
3261 rToolbarDefinition
->replaceByIndex( i
, Any( aSeqPropValue
));
3269 uno::Reference
< ui::XUIConfigurationManager
> SAL_CALL
SfxBaseModel::getUIConfigurationManager()
3270 throw ( uno::RuntimeException
)
3272 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3273 if ( impl_isDisposed() )
3274 throw lang::DisposedException();
3276 if ( !m_pData
->m_xUIConfigurationManager
.is() )
3278 uno::Reference
< ui::XUIConfigurationManager
> xNewUIConfMan(
3279 ::comphelper::getProcessServiceFactory()->createInstance(
3280 ::rtl::OUString::createFromAscii( "com.sun.star.ui.UIConfigurationManager" )),
3283 Reference
< ui::XUIConfigurationStorage
> xUIConfigStorage( xNewUIConfMan
, uno::UNO_QUERY
);
3284 if ( xUIConfigStorage
.is() )
3286 uno::Reference
< XSTORAGE
> xConfigStorage
;
3288 rtl::OUString
aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
3289 // First try to open with READWRITE and then READ
3290 xConfigStorage
= getDocumentSubStorage( aUIConfigFolderName
, embed::ElementModes::READWRITE
);
3291 if ( xConfigStorage
.is() )
3293 rtl::OUString
aMediaTypeProp( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ));
3294 rtl::OUString
aUIConfigMediaType(
3295 RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ) );
3296 rtl::OUString aMediaType
;
3297 uno::Reference
< beans::XPropertySet
> xPropSet( xConfigStorage
, uno::UNO_QUERY
);
3298 Any a
= xPropSet
->getPropertyValue( aMediaTypeProp
);
3299 if ( !( a
>>= aMediaType
) || ( aMediaType
.getLength() == 0 ))
3301 a
<<= aUIConfigMediaType
;
3302 xPropSet
->setPropertyValue( aMediaTypeProp
, a
);
3306 xConfigStorage
= getDocumentSubStorage( aUIConfigFolderName
, embed::ElementModes::READ
);
3308 // initialize ui configuration manager with document substorage
3309 xUIConfigStorage
->setStorage( xConfigStorage
);
3311 // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to
3313 if ( m_pData
->m_pObjectShell
->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED
)
3315 // Import old UI configuration from OOo 1.x
3316 uno::Reference
< XSTORAGE
> xOOo1ConfigStorage
;
3317 rtl::OUString
aOOo1UIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations" ));
3319 // Try to open with READ
3320 xOOo1ConfigStorage
= getDocumentSubStorage( aOOo1UIConfigFolderName
, embed::ElementModes::READ
);
3321 if ( xOOo1ConfigStorage
.is() )
3323 uno::Reference
< lang::XMultiServiceFactory
> xServiceMgr( ::comphelper::getProcessServiceFactory() );
3324 uno::Sequence
< uno::Reference
< container::XIndexContainer
> > rToolbars
;
3326 sal_Bool bImported
= UIConfigurationImporterOOo1x::ImportCustomToolbars(
3327 xNewUIConfMan
, rToolbars
, xServiceMgr
, xOOo1ConfigStorage
);
3330 SfxObjectShell
* pObjShell
= SfxBaseModel::GetObjectShell();
3332 char aNum
[] = "private:resource/toolbar/custom_OOo1x_0";
3333 char aTitle
[] = "Toolbar 0";
3334 sal_Int32 nNumIndex
= strlen( aNum
)-1;
3335 sal_Int32 nTitleIndex
= strlen( aTitle
)-1;
3336 for ( sal_Int32 i
= 0; i
< rToolbars
.getLength(); i
++ )
3339 aTitle
[nTitleIndex
]++;
3341 rtl::OUString
aCustomTbxName( RTL_CONSTASCII_USTRINGPARAM( aNum
));
3342 rtl::OUString
aCustomTbxTitle( RTL_CONSTASCII_USTRINGPARAM( aTitle
));
3344 uno::Reference
< container::XIndexContainer
> xToolbar
= rToolbars
[i
];
3345 ConvertSlotsToCommands( pObjShell
, xToolbar
);
3346 if ( !xNewUIConfMan
->hasSettings( aCustomTbxName
))
3348 // Set UIName for the toolbar with container property
3349 uno::Reference
< beans::XPropertySet
> xPropSet( xToolbar
, UNO_QUERY
);
3350 if ( xPropSet
.is() )
3354 rtl::OUString
aPropName( RTL_CONSTASCII_USTRINGPARAM( "UIName" ));
3355 Any
aAny( aCustomTbxTitle
);
3356 xPropSet
->setPropertyValue( aPropName
, aAny
);
3358 catch ( beans::UnknownPropertyException
& )
3363 uno::Reference
< container::XIndexAccess
> xToolbarData( xToolbar
, uno::UNO_QUERY
);
3364 xNewUIConfMan
->insertSettings( aCustomTbxName
, xToolbarData
);
3365 uno::Reference
< ui::XUIConfigurationPersistence
> xPersist( xNewUIConfMan
, uno::UNO_QUERY
);
3374 m_pData
->m_xUIConfigurationManager
= xNewUIConfMan
;
3377 return m_pData
->m_xUIConfigurationManager
;
3380 //____________________________________________________________________________________________________
3382 //____________________________________________________________________________________________________
3384 void SAL_CALL
SfxBaseModel::setVisualAreaSize( sal_Int64 nAspect
, const awt::Size
& aSize
)
3385 throw ( lang::IllegalArgumentException
,
3386 embed::WrongStateException
,
3388 uno::RuntimeException
)
3390 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3391 if ( impl_isDisposed() )
3392 throw lang::DisposedException();
3394 if ( !m_pData
->m_pObjectShell
.Is() )
3395 throw uno::Exception(); // TODO: error handling
3397 SfxViewFrame
* pViewFrm
= SfxViewFrame::GetFirst( m_pData
->m_pObjectShell
, 0, sal_False
);
3398 if ( pViewFrm
&& m_pData
->m_pObjectShell
->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED
&& !pViewFrm
->GetFrame()->IsInPlace() )
3400 Window
* pWindow
= VCLUnoHelper::GetWindow( pViewFrm
->GetFrame()->GetFrameInterface()->getContainerWindow() );
3401 Size aWinSize
= pWindow
->GetSizePixel();
3402 awt::Size aCurrent
= getVisualAreaSize( nAspect
);
3403 Size
aDiff( aSize
.Width
-aCurrent
.Width
, aSize
.Height
-aCurrent
.Height
);
3404 Size aWrongDiff
= OutputDevice::LogicToLogic( aDiff
, m_pData
->m_pObjectShell
->GetMapUnit(), pWindow
->GetMapMode() );
3405 aDiff
= pViewFrm
->GetViewShell()->GetWindow()->LogicToPixel( aDiff
);
3406 aWinSize
.Width() += aDiff
.Width();
3407 aWinSize
.Height() += aDiff
.Height();
3408 pWindow
->SetSizePixel( aWinSize
);
3412 Rectangle aTmpRect
= m_pData
->m_pObjectShell
->GetVisArea( ASPECT_CONTENT
);
3413 aTmpRect
.SetSize( Size( aSize
.Width
, aSize
.Height
) );
3414 m_pData
->m_pObjectShell
->SetVisArea( aTmpRect
);
3418 awt::Size SAL_CALL
SfxBaseModel::getVisualAreaSize( sal_Int64
/*nAspect*/ )
3419 throw ( lang::IllegalArgumentException
,
3420 embed::WrongStateException
,
3422 uno::RuntimeException
)
3424 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3425 if ( impl_isDisposed() )
3426 throw lang::DisposedException();
3428 if ( !m_pData
->m_pObjectShell
.Is() )
3429 throw uno::Exception(); // TODO: error handling
3431 Rectangle aTmpRect
= m_pData
->m_pObjectShell
->GetVisArea( ASPECT_CONTENT
);
3434 Window
* pWindow
= NULL
;
3435 SfxViewFrame
* pViewFrm
= m_pData
->m_pObjectShell
.Is() ?
3436 SfxViewFrame::GetFirst( m_pData
->m_pObjectShell
, 0, sal_False
) : 0;
3440 MapMode
aInternalMapMode( pViewFrm
->GetWindow().GetMapMode() );
3441 MapMode
aExternalMapMode( m_pData
->m_pObjectShell
->GetMapUnit() );
3443 aTmpRect
= OutputDevice::LogicToLogic( aTmpRect
, aInternalMapMode
, aExternalMapMode
);
3447 return awt::Size( aTmpRect
.GetWidth(), aTmpRect
.GetHeight() );
3451 sal_Int32 SAL_CALL
SfxBaseModel::getMapUnit( sal_Int64
/*nAspect*/ )
3452 throw ( uno::Exception
,
3453 uno::RuntimeException
)
3455 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3456 if ( impl_isDisposed() )
3457 throw lang::DisposedException();
3459 if ( !m_pData
->m_pObjectShell
.Is() )
3460 throw uno::Exception(); // TODO: error handling
3462 return VCLUnoHelper::VCL2UnoEmbedMapUnit( m_pData
->m_pObjectShell
->GetMapUnit() );
3465 embed::VisualRepresentation SAL_CALL
SfxBaseModel::getPreferredVisualRepresentation( ::sal_Int64
/*nAspect*/ )
3466 throw ( lang::IllegalArgumentException
,
3467 embed::WrongStateException
,
3469 uno::RuntimeException
)
3471 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3472 if ( impl_isDisposed() )
3473 throw lang::DisposedException();
3475 datatransfer::DataFlavor
aDataFlavor(
3476 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
3477 ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
3478 ::getCppuType( (const uno::Sequence
< sal_Int8
>*) NULL
) );
3480 embed::VisualRepresentation aVisualRepresentation
;
3481 aVisualRepresentation
.Data
= getTransferData( aDataFlavor
);
3482 aVisualRepresentation
.Flavor
= aDataFlavor
;
3484 return aVisualRepresentation
;
3487 //____________________________________________________________________________________________________
3488 // XStorageBasedDocument
3489 //____________________________________________________________________________________________________
3491 void SAL_CALL
SfxBaseModel::loadFromStorage( const uno::Reference
< XSTORAGE
>& xStorage
,
3492 const uno::Sequence
< beans::PropertyValue
>& aMediaDescriptor
)
3493 throw ( lang::IllegalArgumentException
,
3494 DOUBLEINITIALIZATIONEXCEPTION
,
3497 uno::RuntimeException
)
3499 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3500 if ( impl_isDisposed() )
3501 throw lang::DisposedException();
3503 if ( !m_pData
->m_pObjectShell
.Is() )
3504 throw IOEXCEPTION(); // TODO:
3506 if ( m_pData
->m_pObjectShell
.Is() )
3508 if( m_pData
->m_pObjectShell
->GetMedium() )
3509 // if a Medium is present, the document is already initialized
3510 throw DOUBLEINITIALIZATIONEXCEPTION();
3512 // after i36090 is fixed the pool from object shell can be used
3513 // SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3514 SfxAllItemSet
aSet( SFX_APP()->GetPool() );
3516 // the BaseURL is part of the ItemSet
3517 SfxMedium
* pMedium
= new SfxMedium( xStorage
, String() );
3518 TransformParameters( SID_OPENDOC
, aMediaDescriptor
, aSet
);
3519 pMedium
->GetItemSet()->Put( aSet
);
3521 // allow to use an interactionhandler (if there is one)
3522 pMedium
->UseInteractionHandler( TRUE
);
3524 SFX_ITEMSET_ARG( &aSet
, pTemplateItem
, SfxBoolItem
, SID_TEMPLATE
, sal_False
);
3525 BOOL bTemplate
= pTemplateItem
&& pTemplateItem
->GetValue();
3526 m_pData
->m_pObjectShell
->SetActivateEvent_Impl( bTemplate
? SFX_EVENT_CREATEDOC
: SFX_EVENT_OPENDOC
);
3527 m_pData
->m_pObjectShell
->Get_Impl()->bOwnsStorage
= FALSE
;
3530 if ( !m_pData
->m_pObjectShell
->DoLoad(pMedium
) )
3532 sal_uInt32 nError
= m_pData
->m_pObjectShell
->GetErrorCode();
3533 throw task::ErrorCodeIOException( ::rtl::OUString(),
3534 uno::Reference
< uno::XInterface
>(),
3535 nError
? nError
: ERRCODE_IO_CANTREAD
);
3540 void SAL_CALL
SfxBaseModel::storeToStorage( const uno::Reference
< XSTORAGE
>& xStorage
,
3541 const uno::Sequence
< beans::PropertyValue
>& aMediaDescriptor
)
3542 throw ( lang::IllegalArgumentException
,
3545 uno::RuntimeException
)
3547 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3548 if ( impl_isDisposed() )
3549 throw lang::DisposedException();
3551 uno::Reference
< XSTORAGE
> xResult
;
3552 if ( !m_pData
->m_pObjectShell
.Is() )
3553 throw IOEXCEPTION(); // TODO:
3555 SfxAllItemSet
aSet( m_pData
->m_pObjectShell
->GetPool() );
3556 TransformParameters( SID_SAVEASDOC
, aMediaDescriptor
, aSet
);
3558 // TODO/LATER: may be a special URL "private:storage" should be used
3559 SFX_ITEMSET_ARG( &aSet
, pItem
, SfxStringItem
, SID_FILTER_NAME
, sal_False
);
3560 sal_Int32 nVersion
= SOFFICE_FILEFORMAT_CURRENT
;
3563 String aFilterName
= pItem
->GetValue();
3564 const SfxFilter
* pFilter
= SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName
);
3565 if ( pFilter
&& pFilter
->UsesStorage() )
3566 nVersion
= pFilter
->GetVersion();
3569 sal_Bool bSuccess
= sal_False
;
3570 if ( xStorage
== m_pData
->m_pObjectShell
->GetStorage() )
3572 // storing to the own storage
3573 bSuccess
= m_pData
->m_pObjectShell
->DoSave();
3577 // TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated
3578 // TODO/LATER: is it possible to have a template here?
3579 m_pData
->m_pObjectShell
->SetupStorage( xStorage
, nVersion
, sal_False
);
3581 // BaseURL is part of the ItemSet
3582 SfxMedium
aMedium( xStorage
, String(), &aSet
);
3583 aMedium
.CanDisposeStorage_Impl( FALSE
);
3584 if ( aMedium
.GetFilter() )
3586 // storing without a valid filter will often crash
3587 bSuccess
= m_pData
->m_pObjectShell
->DoSaveObjectAs( aMedium
, TRUE
);
3588 m_pData
->m_pObjectShell
->DoSaveCompleted( NULL
);
3592 sal_uInt32 nError
= m_pData
->m_pObjectShell
->GetErrorCode();
3593 m_pData
->m_pObjectShell
->ResetError();
3595 // the warnings are currently not transported
3598 throw task::ErrorCodeIOException( ::rtl::OUString(),
3599 uno::Reference
< uno::XInterface
>(),
3600 nError
? nError
: ERRCODE_IO_GENERAL
);
3604 void SAL_CALL
SfxBaseModel::switchToStorage( const uno::Reference
< XSTORAGE
>& xStorage
)
3605 throw ( lang::IllegalArgumentException
,
3608 uno::RuntimeException
)
3610 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3611 if ( impl_isDisposed() )
3612 throw lang::DisposedException();
3614 uno::Reference
< XSTORAGE
> xResult
;
3615 if ( !m_pData
->m_pObjectShell
.Is() )
3616 throw IOEXCEPTION(); // TODO:
3618 // the persistence should be switched only if the storage is different
3619 if ( xStorage
!= m_pData
->m_pObjectShell
->GetStorage()
3620 && !m_pData
->m_pObjectShell
->SwitchPersistance( xStorage
) )
3622 sal_uInt32 nError
= m_pData
->m_pObjectShell
->GetErrorCode();
3623 throw task::ErrorCodeIOException( ::rtl::OUString(),
3624 uno::Reference
< uno::XInterface
>(),
3625 nError
? nError
: ERRCODE_IO_GENERAL
);
3628 m_pData
->m_pObjectShell
->Get_Impl()->bOwnsStorage
= FALSE
;
3631 uno::Reference
< XSTORAGE
> SAL_CALL
SfxBaseModel::getDocumentStorage()
3632 throw ( IOEXCEPTION
,
3634 uno::RuntimeException
)
3636 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3637 if ( impl_isDisposed() )
3638 throw lang::DisposedException();
3640 uno::Reference
< XSTORAGE
> xResult
;
3641 if ( !m_pData
->m_pObjectShell
.Is() )
3642 throw IOEXCEPTION(); // TODO
3644 return m_pData
->m_pObjectShell
->GetStorage();
3647 void SAL_CALL
SfxBaseModel::addStorageChangeListener(
3648 const uno::Reference
< document::XStorageChangeListener
>& xListener
)
3649 throw ( uno::RuntimeException
)
3651 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3652 if ( impl_isDisposed() )
3655 m_pData
->m_aInterfaceContainer
.addInterface(
3656 ::getCppuType((const uno::Reference
< document::XStorageChangeListener
>*)0), xListener
);
3659 void SAL_CALL
SfxBaseModel::removeStorageChangeListener(
3660 const uno::Reference
< document::XStorageChangeListener
>& xListener
)
3661 throw ( uno::RuntimeException
)
3663 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3664 if ( impl_isDisposed() )
3667 m_pData
->m_aInterfaceContainer
.removeInterface(
3668 ::getCppuType((const uno::Reference
< document::XStorageChangeListener
>*)0), xListener
);
3671 #include "printhelper.hxx"
3672 bool SfxBaseModel::impl_getPrintHelper()
3674 if ( m_pData
->m_xPrintable
.is() )
3676 m_pData
->m_xPrintable
= new SfxPrintHelper();
3677 uno::Reference
< lang::XInitialization
> xInit( m_pData
->m_xPrintable
, uno::UNO_QUERY
);
3678 uno::Sequence
< uno::Any
> aValues(1);
3679 aValues
[0] <<= uno::Reference
< frame::XModel
> (static_cast< frame::XModel
* >(this), uno::UNO_QUERY
);
3680 xInit
->initialize( aValues
);
3681 uno::Reference
< view::XPrintJobBroadcaster
> xBrd( m_pData
->m_xPrintable
, uno::UNO_QUERY
);
3682 xBrd
->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData
) );
3686 //=============================================================================
3687 // css.frame.XModule
3688 void SAL_CALL
SfxBaseModel::setIdentifier(const ::rtl::OUString
& Identifier
)
3689 throw (css::uno::RuntimeException
)
3691 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3692 if ( impl_isDisposed() )
3694 m_pData
->m_sModuleIdentifier
= Identifier
;
3697 //=============================================================================
3698 // css.frame.XModule
3699 ::rtl::OUString SAL_CALL
SfxBaseModel::getIdentifier()
3700 throw (css::uno::RuntimeException
)
3702 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3703 if ( impl_isDisposed() )
3704 return ::rtl::OUString();
3705 if (m_pData
->m_sModuleIdentifier
.getLength() > 0)
3706 return m_pData
->m_sModuleIdentifier
;
3707 if (m_pData
->m_pObjectShell
)
3708 return m_pData
->m_pObjectShell
->GetFactory().GetDocumentServiceName();
3709 return ::rtl::OUString();
3712 //=============================================================================
3713 css::uno::Reference
< css::frame::XTitle
> SfxBaseModel::impl_getTitleHelper ()
3715 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3717 if ( impl_isDisposed() )
3718 return css::uno::Reference
< css::frame::XTitle
>();
3720 if ( ! m_pData
->m_xTitleHelper
.is ())
3722 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= ::comphelper::getProcessServiceFactory ();
3723 css::uno::Reference
< css::frame::XUntitledNumbers
> xDesktop(xSMGR
->createInstance(SERVICENAME_DESKTOP
), css::uno::UNO_QUERY_THROW
);
3724 css::uno::Reference
< css::frame::XModel
> xThis (static_cast< css::frame::XModel
* >(this), css::uno::UNO_QUERY_THROW
);
3726 ::framework::TitleHelper
* pHelper
= new ::framework::TitleHelper(xSMGR
);
3727 m_pData
->m_xTitleHelper
= css::uno::Reference
< css::frame::XTitle
>(static_cast< ::cppu::OWeakObject
* >(pHelper
), css::uno::UNO_QUERY_THROW
);
3728 pHelper
->setOwner (xThis
);
3729 pHelper
->connectWithUntitledNumbers (xDesktop
);
3732 return m_pData
->m_xTitleHelper
;
3735 //=============================================================================
3736 css::uno::Reference
< css::frame::XUntitledNumbers
> SfxBaseModel::impl_getUntitledHelper ()
3738 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3740 if ( impl_isDisposed() )
3741 return css::uno::Reference
< css::frame::XUntitledNumbers
>();
3743 if ( ! m_pData
->m_xNumberedControllers
.is ())
3745 css::uno::Reference
< css::frame::XModel
> xThis (static_cast< css::frame::XModel
* >(this), css::uno::UNO_QUERY_THROW
);
3746 ::comphelper::NumberedCollection
* pHelper
= new ::comphelper::NumberedCollection();
3748 m_pData
->m_xNumberedControllers
= css::uno::Reference
< css::frame::XUntitledNumbers
>(static_cast< ::cppu::OWeakObject
* >(pHelper
), css::uno::UNO_QUERY_THROW
);
3750 pHelper
->setOwner (xThis
);
3751 pHelper
->setUntitledPrefix (::rtl::OUString::createFromAscii(" : "));
3754 return m_pData
->m_xNumberedControllers
;
3757 //=============================================================================
3759 ::rtl::OUString SAL_CALL
SfxBaseModel::getTitle()
3760 throw (css::uno::RuntimeException
)
3763 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3765 if ( impl_isDisposed() )
3766 return ::rtl::OUString();
3768 ::rtl::OUString aResult
= impl_getTitleHelper()->getTitle ();
3769 if ( m_pData
->m_pObjectShell
)
3771 SfxMedium
* pMedium
= m_pData
->m_pObjectShell
->GetMedium();
3774 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pRepairedDocItem
, SfxBoolItem
, SID_REPAIRPACKAGE
, sal_False
);
3775 if ( pRepairedDocItem
&& pRepairedDocItem
->GetValue() )
3776 aResult
+= String( SfxResId(STR_REPAIREDDOCUMENT
) );
3779 if ( m_pData
->m_pObjectShell
->IsReadOnlyUI() || (m_pData
->m_pObjectShell
->GetMedium() && m_pData
->m_pObjectShell
->GetMedium()->IsReadOnly()) )
3780 aResult
+= ::rtl::OUString( String( SfxResId(STR_READONLY
) ) );
3781 else if ( m_pData
->m_pObjectShell
->IsDocShared() )
3782 aResult
+= ::rtl::OUString( String( SfxResId(STR_SHARED
) ) );
3784 if ( m_pData
->m_pObjectShell
->GetDocumentSignatureState() == SIGNATURESTATE_SIGNATURES_OK
)
3785 aResult
+= String( SfxResId( RID_XMLSEC_DOCUMENTSIGNED
) );
3791 //=============================================================================
3793 void SAL_CALL
SfxBaseModel::setTitle( const ::rtl::OUString
& sTitle
)
3794 throw (css::uno::RuntimeException
)
3797 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3799 if ( impl_isDisposed() )
3802 impl_getTitleHelper()->setTitle (sTitle
);
3805 //=============================================================================
3806 // css.frame.XTitleChangeBroadcaster
3807 void SAL_CALL
SfxBaseModel::addTitleChangeListener( const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
)
3808 throw (css::uno::RuntimeException
)
3811 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3813 if ( impl_isDisposed() )
3816 css::uno::Reference
< css::frame::XTitleChangeBroadcaster
> xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY
);
3817 if (xBroadcaster
.is ())
3818 xBroadcaster
->addTitleChangeListener (xListener
);
3821 //=============================================================================
3822 // css.frame.XTitleChangeBroadcaster
3823 void SAL_CALL
SfxBaseModel::removeTitleChangeListener( const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
)
3824 throw (css::uno::RuntimeException
)
3827 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3829 if ( impl_isDisposed() )
3832 css::uno::Reference
< css::frame::XTitleChangeBroadcaster
> xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY
);
3833 if (xBroadcaster
.is ())
3834 xBroadcaster
->removeTitleChangeListener (xListener
);
3837 //=============================================================================
3838 // css.frame.XUntitledNumbers
3839 ::sal_Int32 SAL_CALL
SfxBaseModel::leaseNumber( const css::uno::Reference
< css::uno::XInterface
>& xComponent
)
3840 throw (css::lang::IllegalArgumentException
,
3841 css::uno::RuntimeException
)
3843 // object already disposed?
3844 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3845 if ( impl_isDisposed() )
3846 return css::frame::UntitledNumbersConst::INVALID_NUMBER
;
3848 return impl_getUntitledHelper ()->leaseNumber (xComponent
);
3851 //=============================================================================
3852 // css.frame.XUntitledNumbers
3853 void SAL_CALL
SfxBaseModel::releaseNumber( ::sal_Int32 nNumber
)
3854 throw (css::lang::IllegalArgumentException
,
3855 css::uno::RuntimeException
)
3857 // object already disposed?
3858 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3859 if ( impl_isDisposed() )
3862 impl_getUntitledHelper ()->releaseNumber (nNumber
);
3865 //=============================================================================
3866 // css.frame.XUntitledNumbers
3867 void SAL_CALL
SfxBaseModel::releaseNumberForComponent( const css::uno::Reference
< css::uno::XInterface
>& xComponent
)
3868 throw (css::lang::IllegalArgumentException
,
3869 css::uno::RuntimeException
)
3871 // object already disposed?
3872 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3873 if ( impl_isDisposed() )
3876 impl_getUntitledHelper ()->releaseNumberForComponent (xComponent
);
3879 //=============================================================================
3880 // css.frame.XUntitledNumbers
3881 ::rtl::OUString SAL_CALL
SfxBaseModel::getUntitledPrefix()
3882 throw (css::uno::RuntimeException
)
3884 // object already disposed?
3885 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3886 if ( impl_isDisposed() )
3887 return ::rtl::OUString ();
3889 return impl_getUntitledHelper ()->getUntitledPrefix ();
3892 //=============================================================================
3893 // css::frame::XModel2
3894 css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
SfxBaseModel::getControllers()
3895 throw (css::uno::RuntimeException
)
3897 // object already disposed?
3898 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3899 if ( impl_isDisposed() )
3900 return css::uno::Reference
< css::container::XEnumeration
>();
3902 sal_Int32 c
= m_pData
->m_seqControllers
.getLength();
3904 css::uno::Sequence
< css::uno::Any
> lEnum(c
);
3906 lEnum
[i
] <<= m_pData
->m_seqControllers
[i
];
3908 ::comphelper::OAnyEnumeration
* pEnum
= new ::comphelper::OAnyEnumeration(lEnum
);
3909 css::uno::Reference
< css::container::XEnumeration
> xEnum(static_cast< css::container::XEnumeration
* >(pEnum
), css::uno::UNO_QUERY_THROW
);
3913 //=============================================================================
3914 // css::frame::XModel2
3915 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
SfxBaseModel::getAvailableViewControllerNames()
3916 throw (css::uno::RuntimeException
)
3918 return css::uno::Sequence
< ::rtl::OUString
>();
3921 //=============================================================================
3922 // css::frame::XModel2
3923 css::uno::Reference
< css::frame::XController2
> SAL_CALL
SfxBaseModel::createDefaultViewController(const css::uno::Reference
< css::frame::XFrame
>& /*Frame*/)
3924 throw (css::uno::RuntimeException
,
3925 css::lang::IllegalArgumentException
,
3926 css::uno::Exception
)
3928 return css::uno::Reference
< css::frame::XController2
>();
3931 //=============================================================================
3932 // css::frame::XModel2
3933 css::uno::Reference
< css::frame::XController2
> SAL_CALL
SfxBaseModel::createViewController(const ::rtl::OUString
& /*ViewName*/,
3934 const css::uno::Sequence
< css::beans::PropertyValue
>& /*Arguments*/,
3935 const css::uno::Reference
< css::frame::XFrame
>& /*Frame */)
3936 throw (css::uno::RuntimeException
,
3937 css::lang::IllegalArgumentException
,
3938 css::uno::Exception
)
3940 return css::uno::Reference
< css::frame::XController2
>();
3943 //=============================================================================
3944 // RDF DocumentMetadataAccess
3946 // ::com::sun::star::rdf::XRepositorySupplier:
3947 uno::Reference
< rdf::XRepository
> SAL_CALL
3948 SfxBaseModel::getRDFRepository() throw (uno::RuntimeException
)
3950 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3951 if ( impl_isDisposed() )
3952 throw lang::DisposedException();
3954 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
3956 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
3957 "model has no document metadata"), *this );
3960 return xDMA
->getRDFRepository();
3963 // ::com::sun::star::rdf::XNode:
3964 ::rtl::OUString SAL_CALL
3965 SfxBaseModel::getStringValue() throw (uno::RuntimeException
)
3967 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3968 if ( impl_isDisposed() )
3969 throw lang::DisposedException();
3971 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
3973 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
3974 "model has no document metadata"), *this );
3977 return xDMA
->getStringValue();
3980 // ::com::sun::star::rdf::XURI:
3981 ::rtl::OUString SAL_CALL
3982 SfxBaseModel::getNamespace() throw (uno::RuntimeException
)
3984 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
3985 if ( impl_isDisposed() )
3986 throw lang::DisposedException();
3988 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
3990 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
3991 "model has no document metadata"), *this );
3994 return xDMA
->getNamespace();
3997 ::rtl::OUString SAL_CALL
3998 SfxBaseModel::getLocalName() throw (uno::RuntimeException
)
4000 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4001 if ( impl_isDisposed() )
4002 throw lang::DisposedException();
4004 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4006 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4007 "model has no document metadata"), *this );
4010 return xDMA
->getLocalName();
4013 // ::com::sun::star::rdf::XDocumentMetadataAccess:
4014 uno::Reference
< rdf::XMetadatable
> SAL_CALL
4015 SfxBaseModel::getElementByMetadataReference(
4016 const ::com::sun::star::beans::StringPair
& i_rReference
)
4017 throw (uno::RuntimeException
)
4019 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4020 if ( impl_isDisposed() )
4021 throw lang::DisposedException();
4023 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4025 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4026 "model has no document metadata"), *this );
4029 return xDMA
->getElementByMetadataReference(i_rReference
);
4032 uno::Reference
< rdf::XMetadatable
> SAL_CALL
4033 SfxBaseModel::getElementByURI(const uno::Reference
< rdf::XURI
> & i_xURI
)
4034 throw (uno::RuntimeException
, lang::IllegalArgumentException
)
4036 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4037 if ( impl_isDisposed() )
4038 throw lang::DisposedException();
4040 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4042 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4043 "model has no document metadata"), *this );
4046 return xDMA
->getElementByURI(i_xURI
);
4049 uno::Sequence
< uno::Reference
< rdf::XURI
> > SAL_CALL
4050 SfxBaseModel::getMetadataGraphsWithType(
4051 const uno::Reference
<rdf::XURI
> & i_xType
)
4052 throw (uno::RuntimeException
, lang::IllegalArgumentException
)
4054 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4055 if ( impl_isDisposed() )
4056 throw lang::DisposedException();
4058 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4060 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4061 "model has no document metadata"), *this );
4064 return xDMA
->getMetadataGraphsWithType(i_xType
);
4067 uno::Reference
<rdf::XURI
> SAL_CALL
4068 SfxBaseModel::addMetadataFile(const ::rtl::OUString
& i_rFileName
,
4069 const uno::Sequence
< uno::Reference
< rdf::XURI
> > & i_rTypes
)
4070 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4071 container::ElementExistException
)
4073 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4074 if ( impl_isDisposed() )
4075 throw lang::DisposedException();
4077 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4079 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4080 "model has no document metadata"), *this );
4083 return xDMA
->addMetadataFile(i_rFileName
, i_rTypes
);
4086 uno::Reference
<rdf::XURI
> SAL_CALL
4087 SfxBaseModel::importMetadataFile(::sal_Int16 i_Format
,
4088 const uno::Reference
< io::XInputStream
> & i_xInStream
,
4089 const ::rtl::OUString
& i_rFileName
,
4090 const uno::Reference
< rdf::XURI
> & i_xBaseURI
,
4091 const uno::Sequence
< uno::Reference
< rdf::XURI
> > & i_rTypes
)
4092 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4093 datatransfer::UnsupportedFlavorException
,
4094 container::ElementExistException
, rdf::ParseException
, io::IOException
)
4096 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4097 if ( impl_isDisposed() )
4098 throw lang::DisposedException();
4100 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4102 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4103 "model has no document metadata"), *this );
4106 return xDMA
->importMetadataFile(i_Format
,
4107 i_xInStream
, i_rFileName
, i_xBaseURI
, i_rTypes
);
4111 SfxBaseModel::removeMetadataFile(
4112 const uno::Reference
< rdf::XURI
> & i_xGraphName
)
4113 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4114 container::NoSuchElementException
)
4116 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4117 if ( impl_isDisposed() )
4118 throw lang::DisposedException();
4120 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4122 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4123 "model has no document metadata"), *this );
4126 return xDMA
->removeMetadataFile(i_xGraphName
);
4130 SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString
& i_rFileName
)
4131 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4132 container::ElementExistException
)
4134 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4135 if ( impl_isDisposed() )
4136 throw lang::DisposedException();
4138 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4140 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4141 "model has no document metadata"), *this );
4144 return xDMA
->addContentOrStylesFile(i_rFileName
);
4148 SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString
& i_rFileName
)
4149 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4150 container::NoSuchElementException
)
4152 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4153 if ( impl_isDisposed() )
4154 throw lang::DisposedException();
4156 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4158 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4159 "model has no document metadata"), *this );
4162 return xDMA
->removeContentOrStylesFile(i_rFileName
);
4166 SfxBaseModel::loadMetadataFromStorage(
4167 uno::Reference
< embed::XStorage
> const & i_xStorage
,
4168 uno::Reference
<rdf::XURI
> const & i_xBaseURI
,
4169 uno::Reference
<task::XInteractionHandler
> const & i_xHandler
)
4170 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4171 lang::WrappedTargetException
)
4173 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4174 if ( impl_isDisposed() )
4175 throw lang::DisposedException();
4177 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(
4178 m_pData
->CreateDMAUninitialized());
4180 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4181 "model has no document metadata"), *this );
4185 xDMA
->loadMetadataFromStorage(i_xStorage
, i_xBaseURI
, i_xHandler
);
4186 } catch (lang::IllegalArgumentException
&) {
4187 throw; // not initialized
4188 } catch (uno::Exception
&) {
4189 // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4190 m_pData
->m_xDocumentMetadata
= xDMA
;
4193 m_pData
->m_xDocumentMetadata
= xDMA
;
4198 SfxBaseModel::storeMetadataToStorage(
4199 uno::Reference
< embed::XStorage
> const & i_xStorage
)
4200 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4201 lang::WrappedTargetException
)
4203 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4204 if ( impl_isDisposed() )
4205 throw lang::DisposedException();
4207 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4209 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4210 "model has no document metadata"), *this );
4213 return xDMA
->storeMetadataToStorage(i_xStorage
);
4217 SfxBaseModel::loadMetadataFromMedium(
4218 const uno::Sequence
< beans::PropertyValue
> & i_rMedium
)
4219 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4220 lang::WrappedTargetException
)
4222 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4223 if ( impl_isDisposed() )
4224 throw lang::DisposedException();
4226 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(
4227 m_pData
->CreateDMAUninitialized());
4229 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4230 "model has no document metadata"), *this );
4234 xDMA
->loadMetadataFromMedium(i_rMedium
);
4235 } catch (lang::IllegalArgumentException
&) {
4236 throw; // not initialized
4237 } catch (uno::Exception
&) {
4238 // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4239 m_pData
->m_xDocumentMetadata
= xDMA
;
4242 m_pData
->m_xDocumentMetadata
= xDMA
;
4246 SfxBaseModel::storeMetadataToMedium(
4247 const uno::Sequence
< beans::PropertyValue
> & i_rMedium
)
4248 throw (uno::RuntimeException
, lang::IllegalArgumentException
,
4249 lang::WrappedTargetException
)
4251 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4252 if ( impl_isDisposed() )
4253 throw lang::DisposedException();
4255 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(m_pData
->GetDMA());
4257 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4258 "model has no document metadata"), *this );
4261 return xDMA
->storeMetadataToMedium(i_rMedium
);