Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / doc / sfxbasemodel.cxx
blob5bddcfe7ce9a7cb3efe4ca05361faab52a57fde5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 //________________________________________________________________________________________________________
31 // my own includes
32 //________________________________________________________________________________________________________
34 #include <sfx2/sfxbasemodel.hxx>
36 //________________________________________________________________________________________________________
37 // include of other projects
38 //________________________________________________________________________________________________________
40 #include <com/sun/star/task/XInteractionHandler.hpp>
41 #include <com/sun/star/task/ErrorCodeRequest.hpp>
42 #include <com/sun/star/view/XSelectionSupplier.hpp>
43 #include <com/sun/star/view/XPrintJobListener.hpp>
44 #include <com/sun/star/lang/DisposedException.hpp>
45 #include <com/sun/star/lang/IllegalArgumentException.hpp>
46 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
47 #include <com/sun/star/frame/IllegalArgumentIOException.hpp>
48 #include <com/sun/star/frame/XUntitledNumbers.hpp>
49 #include <com/sun/star/frame/UntitledNumbersConst.hpp>
50 #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
51 #include <com/sun/star/embed/XStorage.hpp>
52 #include <com/sun/star/embed/EmbedMapUnits.hpp>
53 #include <com/sun/star/document/XStorageChangeListener.hpp>
54 #include <com/sun/star/document/XActionLockable.hpp>
55 #include <com/sun/star/beans/XPropertySet.hpp>
56 #include <com/sun/star/beans/XPropertySetInfo.hpp>
57 #include <com/sun/star/container/XIndexContainer.hpp>
58 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
59 #include <com/sun/star/script/provider/XScriptProvider.hpp>
60 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
61 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
62 #include <com/sun/star/embed/ElementModes.hpp>
63 #include <com/sun/star/embed/Aspects.hpp>
64 #include <com/sun/star/document/XDocumentProperties.hpp>
65 #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
66 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
67 #include <comphelper/enumhelper.hxx> // can be removed when this is a "real" service
69 #include <cppuhelper/interfacecontainer.hxx>
70 #include <cppuhelper/exc_hlp.hxx>
71 #include <comphelper/processfactory.hxx> // can be removed when this is a "real" service
72 #include <comphelper/componentcontext.hxx>
73 #include <comphelper/namedvaluecollection.hxx>
74 #include <svl/itemset.hxx>
75 #include <svl/stritem.hxx>
76 #include <svl/eitem.hxx>
77 #include <svl/intitem.hxx>
78 #include <basic/sbx.hxx>
79 #include <basic/sbuno.hxx>
80 #include <tools/urlobj.hxx>
81 #include <tools/diagnose_ex.h>
82 #include <unotools/tempfile.hxx>
83 #include <osl/mutex.hxx>
84 #include <vcl/salctype.hxx>
85 #include <sot/clsids.hxx>
86 #include <sot/storinfo.hxx>
87 #include <comphelper/storagehelper.hxx>
88 #include <toolkit/helper/vclunohelper.hxx>
89 #include <svtools/transfer.hxx>
90 #include <svtools/ehdl.hxx>
91 #include <svtools/sfxecode.hxx>
92 #include <rtl/logfile.hxx>
93 #include <rtl/strbuf.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>
99 #include <unotools/ucbhelper.hxx>
101 //________________________________________________________________________________________________________
102 // includes of my own project
103 //________________________________________________________________________________________________________
105 #include <sfx2/sfxbasecontroller.hxx>
106 #include "sfx2/viewfac.hxx"
107 #include "workwin.hxx"
108 #include <sfx2/signaturestate.hxx>
109 #include <sfx2/sfxuno.hxx>
110 #include <objshimp.hxx>
111 #include <sfx2/viewfrm.hxx>
112 #include <sfx2/viewsh.hxx>
113 #include <sfx2/docfile.hxx>
114 #include <sfx2/dispatch.hxx>
115 #include <sfx2/request.hxx>
116 #include <sfx2/objuno.hxx>
117 #include <sfx2/printer.hxx>
118 #include <sfx2/basmgr.hxx>
119 #include <sfx2/event.hxx>
120 #include <eventsupplier.hxx>
121 #include <sfx2/evntconf.hxx>
122 #include <sfx2/sfx.hrc>
123 #include <sfx2/app.hxx>
124 #include "appdata.hxx"
125 #include <sfx2/docfac.hxx>
126 #include <sfx2/fcontnr.hxx>
127 #include "sfx2/docstoragemodifylistener.hxx"
128 #include "sfx2/brokenpackageint.hxx"
129 #include "graphhelp.hxx"
130 #include "docundomanager.hxx"
131 #include <sfx2/msgpool.hxx>
132 #include <sfx2/DocumentMetadataAccess.hxx>
134 #include <sfx2/sfxresid.hxx>
136 //________________________________________________________________________________________________________
137 // namespaces
138 //________________________________________________________________________________________________________
140 namespace css = ::com::sun::star;
141 using namespace ::com::sun::star;
142 using namespace ::com::sun::star::uno;
143 using ::com::sun::star::beans::PropertyValue;
144 using ::com::sun::star::frame::XFrame;
145 using ::com::sun::star::frame::XController;
146 using ::com::sun::star::frame::XController2;
147 using ::com::sun::star::lang::IllegalArgumentException;
148 using ::com::sun::star::io::IOException;
149 using ::com::sun::star::lang::WrappedTargetException;
150 using ::com::sun::star::uno::Type;
151 using ::com::sun::star::uno::Sequence;
152 using ::com::sun::star::document::XDocumentRecovery;
153 using ::com::sun::star::document::XUndoManager;
154 using ::com::sun::star::document::XUndoAction;
155 using ::com::sun::star::document::UndoFailedException;
156 using ::com::sun::star::frame::XModel;
158 /** This Listener is used to get notified when the XDocumentProperties of the
159 XModel change.
161 class SfxDocInfoListener_Impl : public ::cppu::WeakImplHelper1<
162 ::com::sun::star::util::XModifyListener >
165 public:
166 SfxObjectShell& m_rShell;
168 SfxDocInfoListener_Impl( SfxObjectShell& i_rDoc )
169 : m_rShell(i_rDoc)
170 { };
172 ~SfxDocInfoListener_Impl();
174 virtual void SAL_CALL disposing( const lang::EventObject& )
175 throw ( uno::RuntimeException );
176 virtual void SAL_CALL modified( const lang::EventObject& )
177 throw ( uno::RuntimeException );
179 SfxDocInfoListener_Impl::~SfxDocInfoListener_Impl()
182 void SAL_CALL SfxDocInfoListener_Impl::modified( const lang::EventObject& )
183 throw ( uno::RuntimeException )
185 SolarMutexGuard aSolarGuard;
187 // notify changes to the SfxObjectShell
188 m_rShell.FlushDocInfo();
191 void SAL_CALL SfxDocInfoListener_Impl::disposing( const lang::EventObject& )
192 throw ( uno::RuntimeException )
196 //________________________________________________________________________________________________________
197 // impl. declarations
198 //________________________________________________________________________________________________________
201 struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
203 // counter for SfxBaseModel instances created.
204 static sal_Int64 g_nInstanceCounter ;
205 SfxObjectShellRef m_pObjectShell ;
206 ::rtl::OUString m_sURL ;
207 ::rtl::OUString m_sRuntimeUID ;
208 ::rtl::OUString m_aPreusedFilterName;
209 ::cppu::OMultiTypeInterfaceContainerHelper m_aInterfaceContainer ;
210 uno::Reference< uno::XInterface > m_xParent ;
211 uno::Reference< frame::XController > m_xCurrent ;
212 uno::Reference< document::XDocumentInfo > m_xDocumentInfo ;
213 uno::Reference< document::XDocumentProperties > m_xDocumentProperties;
214 uno::Reference< script::XStarBasicAccess > m_xStarBasicAccess ;
215 uno::Reference< container::XNameReplace > m_xEvents ;
216 uno::Sequence< beans::PropertyValue> m_seqArguments ;
217 uno::Sequence< uno::Reference< frame::XController > > m_seqControllers ;
218 uno::Reference< container::XIndexAccess > m_contViewData ;
219 sal_uInt16 m_nControllerLockCount ;
220 sal_Bool m_bClosed ;
221 sal_Bool m_bClosing ;
222 sal_Bool m_bSaving ;
223 sal_Bool m_bSuicide ;
224 sal_Bool m_bInitialized ;
225 sal_Bool m_bExternalTitle ;
226 sal_Bool m_bModifiedSinceLastSave;
227 uno::Reference< com::sun::star::view::XPrintable> m_xPrintable ;
228 uno::Reference< script::provider::XScriptProvider > m_xScriptProvider;
229 uno::Reference< ui::XUIConfigurationManager > m_xUIConfigurationManager;
230 ::rtl::Reference< ::sfx2::DocumentStorageModifyListener > m_pStorageModifyListen;
231 ::rtl::OUString m_sModuleIdentifier;
232 css::uno::Reference< css::frame::XTitle > m_xTitleHelper;
233 css::uno::Reference< css::frame::XUntitledNumbers > m_xNumberedControllers;
234 uno::Reference< rdf::XDocumentMetadataAccess> m_xDocumentMetadata;
235 ::rtl::Reference< ::sfx2::DocumentUndoManager > m_pDocumentUndoManager;
238 IMPL_SfxBaseModel_DataContainer( ::osl::Mutex& rMutex, SfxObjectShell* pObjectShell )
239 : m_pObjectShell ( pObjectShell )
240 , m_aInterfaceContainer ( rMutex )
241 , m_nControllerLockCount ( 0 )
242 , m_bClosed ( sal_False )
243 , m_bClosing ( sal_False )
244 , m_bSaving ( sal_False )
245 , m_bSuicide ( sal_False )
246 , m_bInitialized ( sal_False )
247 , m_bExternalTitle ( sal_False )
248 , m_bModifiedSinceLastSave( sal_False )
249 , m_pStorageModifyListen ( NULL )
250 , m_xTitleHelper ()
251 , m_xNumberedControllers ()
252 , m_xDocumentMetadata () // lazy
253 , m_pDocumentUndoManager ()
255 // increase global instance counter.
256 ++g_nInstanceCounter;
257 // set own Runtime UID
258 m_sRuntimeUID = rtl::OUString::valueOf( g_nInstanceCounter );
261 virtual ~IMPL_SfxBaseModel_DataContainer()
265 // ::sfx2::IModifiableDocument
266 virtual void storageIsModified()
268 if ( m_pObjectShell.Is() && !m_pObjectShell->IsModified() )
269 m_pObjectShell->SetModified( sal_True );
272 void impl_setDocumentProperties(
273 const uno::Reference< document::XDocumentProperties >& );
275 uno::Reference<rdf::XDocumentMetadataAccess> GetDMA()
277 if (!m_xDocumentMetadata.is())
279 OSL_ENSURE(m_pObjectShell, "GetDMA: no object shell?");
280 if (!m_pObjectShell)
282 return 0;
285 const uno::Reference<uno::XComponentContext> xContext(
286 ::comphelper::getProcessComponentContext());
287 ::rtl::OUString uri;
288 const uno::Reference<frame::XModel> xModel(
289 m_pObjectShell->GetModel());
290 const uno::Reference<lang::XMultiComponentFactory> xMsf(
291 xContext->getServiceManager());
292 const uno::Reference<frame::
293 XTransientDocumentsDocumentContentFactory> xTDDCF(
294 xMsf->createInstanceWithContext(
295 ::rtl::OUString("com.sun.star.frame."
296 "TransientDocumentsDocumentContentFactory"),
297 xContext),
298 uno::UNO_QUERY_THROW);
299 const uno::Reference<ucb::XContent> xContent(
300 xTDDCF->createDocumentContent(xModel) );
301 OSL_ENSURE(xContent.is(), "GetDMA: cannot create DocumentContent");
302 if (!xContent.is())
304 return 0;
306 uri = xContent->getIdentifier()->getContentIdentifier();
307 OSL_ENSURE(!uri.isEmpty(), "GetDMA: empty uri?");
308 if (!uri.isEmpty() && !uri.endsWithAsciiL("/", 1))
310 uri = uri + ::rtl::OUString("/");
313 m_xDocumentMetadata = new ::sfx2::DocumentMetadataAccess(
314 xContext, *m_pObjectShell, uri);
316 return m_xDocumentMetadata;
319 uno::Reference<rdf::XDocumentMetadataAccess> CreateDMAUninitialized()
321 return (m_pObjectShell)
322 ? new ::sfx2::DocumentMetadataAccess(
323 ::comphelper::getProcessComponentContext(), *m_pObjectShell)
324 : 0;
328 // static member initialization.
329 sal_Int64 IMPL_SfxBaseModel_DataContainer::g_nInstanceCounter = 0;
331 // =======================================================================================================
333 // Listener that forwards notifications from the PrintHelper to the "real" listeners
334 class SfxPrintHelperListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::view::XPrintJobListener >
336 public:
337 IMPL_SfxBaseModel_DataContainer* m_pData;
338 SfxPrintHelperListener_Impl( IMPL_SfxBaseModel_DataContainer* pData )
339 : m_pData( pData )
342 virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
343 virtual void SAL_CALL printJobEvent( const view::PrintJobEvent& rEvent ) throw ( uno::RuntimeException);
346 void SAL_CALL SfxPrintHelperListener_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException )
348 m_pData->m_xPrintable = 0;
351 void SAL_CALL SfxPrintHelperListener_Impl::printJobEvent( const view::PrintJobEvent& rEvent ) throw (uno::RuntimeException)
353 ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< view::XPrintJobListener >*) NULL ) );
354 if ( pContainer!=NULL )
356 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
357 while (pIterator.hasMoreElements())
358 ((view::XPrintJobListener*)pIterator.next())->printJobEvent( rEvent );
362 // SfxOwnFramesLocker ====================================================================================
363 // allows to lock all the frames related to the provided SfxObjectShell
364 class SfxOwnFramesLocker
366 uno::Sequence< uno::Reference< frame::XFrame > > m_aLockedFrames;
368 Window* GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame );
369 public:
370 SfxOwnFramesLocker( SfxObjectShell* ObjechShell );
371 ~SfxOwnFramesLocker();
372 void UnlockFrames();
375 SfxOwnFramesLocker::SfxOwnFramesLocker( SfxObjectShell* pObjectShell )
377 if ( !pObjectShell )
378 return;
380 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjectShell );
381 pFrame;
382 pFrame = SfxViewFrame::GetNext( *pFrame, pObjectShell )
385 SfxFrame& rSfxFrame = pFrame->GetFrame();
388 // get vcl window related to the frame and lock it if it is still not locked
389 uno::Reference< frame::XFrame > xFrame = rSfxFrame.GetFrameInterface();
390 Window* pWindow = GetVCLWindow( xFrame );
391 if ( !pWindow )
392 throw uno::RuntimeException();
394 if ( pWindow->IsEnabled() )
396 pWindow->Disable();
400 sal_Int32 nLen = m_aLockedFrames.getLength();
401 m_aLockedFrames.realloc( nLen + 1 );
402 m_aLockedFrames[nLen] = xFrame;
404 catch( uno::Exception& )
406 pWindow->Enable();
407 throw;
411 catch( uno::Exception& )
413 OSL_FAIL( "Not possible to lock the frame window!\n" );
418 SfxOwnFramesLocker::~SfxOwnFramesLocker()
420 UnlockFrames();
423 Window* SfxOwnFramesLocker::GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame )
425 Window* pWindow = NULL;
427 if ( xFrame.is() )
429 uno::Reference< awt::XWindow > xWindow = xFrame->getContainerWindow();
430 if ( xWindow.is() )
431 pWindow = VCLUnoHelper::GetWindow( xWindow );
434 return pWindow;
437 void SfxOwnFramesLocker::UnlockFrames()
439 for ( sal_Int32 nInd = 0; nInd < m_aLockedFrames.getLength(); nInd++ )
443 if ( m_aLockedFrames[nInd].is() )
445 // get vcl window related to the frame and unlock it
446 Window* pWindow = GetVCLWindow( m_aLockedFrames[nInd] );
447 if ( !pWindow )
448 throw uno::RuntimeException();
450 pWindow->Enable();
452 m_aLockedFrames[nInd] = uno::Reference< frame::XFrame >();
455 catch( uno::Exception& )
457 OSL_FAIL( "Can't unlock the frame window!\n" );
462 // SfxSaveGuard ====================================================================================
463 class SfxSaveGuard
465 private:
466 uno::Reference< frame::XModel > m_xModel;
467 IMPL_SfxBaseModel_DataContainer* m_pData;
468 SfxOwnFramesLocker* m_pFramesLock;
470 public:
471 SfxSaveGuard(const uno::Reference< frame::XModel >& xModel ,
472 IMPL_SfxBaseModel_DataContainer* pData ,
473 sal_Bool bRejectConcurrentSaveRequest);
474 ~SfxSaveGuard();
477 SfxSaveGuard::SfxSaveGuard(const uno::Reference< frame::XModel >& xModel ,
478 IMPL_SfxBaseModel_DataContainer* pData ,
479 sal_Bool bRejectConcurrentSaveRequest)
480 : m_xModel (xModel)
481 , m_pData (pData )
482 , m_pFramesLock(0 )
484 static ::rtl::OUString MSG_1("Object already disposed.");
485 static ::rtl::OUString MSG_2("Concurrent save requests on the same document are not possible.");
487 if ( m_pData->m_bClosed )
488 throw ::com::sun::star::lang::DisposedException(
489 MSG_1,
490 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
492 if (
493 bRejectConcurrentSaveRequest &&
494 m_pData->m_bSaving
496 throw ::com::sun::star::io::IOException(
497 MSG_2,
498 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
500 m_pData->m_bSaving = sal_True;
501 m_pFramesLock = new SfxOwnFramesLocker(m_pData->m_pObjectShell);
504 SfxSaveGuard::~SfxSaveGuard()
506 SfxOwnFramesLocker* pFramesLock = m_pFramesLock;
507 m_pFramesLock = 0;
508 delete pFramesLock;
510 m_pData->m_bSaving = sal_False;
512 // m_bSuicide was set e.g. in case somewhere tried to close a document, while it was used for
513 // storing at the same time. Further m_bSuicide was set to sal_True only if close(sal_True) was called.
514 // So the owner ship was delegated to the place where a veto exception was thrown.
515 // Now we have to call close() again and delegate the owner ship to the next one, which
516 // cant accept that. Close(sal_False) cant work in this case. Because then the document will may be never closed ...
518 if ( m_pData->m_bSuicide )
520 // Reset this state. In case the new close() request is not accepted by somehwere else ...
521 // it's not a good idea to have two "owners" for close .-)
522 m_pData->m_bSuicide = sal_False;
525 uno::Reference< util::XCloseable > xClose(m_xModel, uno::UNO_QUERY);
526 if (xClose.is())
527 xClose->close(sal_True);
529 catch(const util::CloseVetoException&)
534 // =======================================================================================================
536 //________________________________________________________________________________________________________
537 // constructor
538 //________________________________________________________________________________________________________
539 DBG_NAME(sfx2_SfxBaseModel)
540 SfxBaseModel::SfxBaseModel( SfxObjectShell *pObjectShell )
541 : BaseMutex()
542 , m_pData( new IMPL_SfxBaseModel_DataContainer( m_aMutex, pObjectShell ) )
543 , m_bSupportEmbeddedScripts( pObjectShell && pObjectShell->Get_Impl() ? !pObjectShell->Get_Impl()->m_bNoBasicCapabilities : false )
544 , m_bSupportDocRecovery( pObjectShell && pObjectShell->Get_Impl() ? pObjectShell->Get_Impl()->m_bDocRecoverySupport : false )
546 DBG_CTOR(sfx2_SfxBaseModel,NULL);
547 if ( pObjectShell != NULL )
549 StartListening( *pObjectShell ) ;
553 //________________________________________________________________________________________________________
554 // destructor
555 //________________________________________________________________________________________________________
557 SfxBaseModel::~SfxBaseModel()
559 DBG_DTOR(sfx2_SfxBaseModel,NULL);
562 //________________________________________________________________________________________________________
563 // XInterface
564 //________________________________________________________________________________________________________
566 uno::Any SAL_CALL SfxBaseModel::queryInterface( const UNOTYPE& rType ) throw( uno::RuntimeException )
568 if ( ( !m_bSupportEmbeddedScripts && rType.equals( XEMBEDDEDSCRIPTS::static_type() ) )
569 || ( !m_bSupportDocRecovery && rType.equals( XDocumentRecovery::static_type() ) )
571 return Any();
573 return SfxBaseModel_Base::queryInterface( rType );
576 //________________________________________________________________________________________________________
577 // XInterface
578 //________________________________________________________________________________________________________
580 void SAL_CALL SfxBaseModel::acquire() throw( )
582 // Attention:
583 // Don't use mutex or guard in this method!!! Is a method of XInterface.
585 // Forward to baseclass
586 OWeakObject::acquire() ;
589 //________________________________________________________________________________________________________
590 // XInterface
591 //________________________________________________________________________________________________________
593 void SAL_CALL SfxBaseModel::release() throw( )
595 // Attention:
596 // Don't use mutex or guard in this method!!! Is a method of XInterface.
598 // Forward to baseclass
599 OWeakObject::release() ;
602 //________________________________________________________________________________________________________
603 // XTypeProvider
604 //________________________________________________________________________________________________________
606 namespace
608 void lcl_stripType( Sequence< Type >& io_rTypes, const Type& i_rTypeToStrip )
610 Sequence< UNOTYPE > aStrippedTypes( io_rTypes.getLength() - 1 );
611 ::std::remove_copy_if(
612 io_rTypes.getConstArray(),
613 io_rTypes.getConstArray() + io_rTypes.getLength(),
614 aStrippedTypes.getArray(),
615 ::std::bind2nd( ::std::equal_to< Type >(), i_rTypeToStrip )
617 io_rTypes = aStrippedTypes;
621 uno::Sequence< UNOTYPE > SAL_CALL SfxBaseModel::getTypes() throw( uno::RuntimeException )
623 uno::Sequence< UNOTYPE > aTypes( SfxBaseModel_Base::getTypes() );
625 if ( !m_bSupportEmbeddedScripts )
626 lcl_stripType( aTypes, XEMBEDDEDSCRIPTS::static_type() );
628 if ( !m_bSupportDocRecovery )
629 lcl_stripType( aTypes, XDocumentRecovery::static_type() );
631 return aTypes;
634 //________________________________________________________________________________________________________
635 // XTypeProvider
636 //________________________________________________________________________________________________________
638 uno::Sequence< sal_Int8 > SAL_CALL SfxBaseModel::getImplementationId() throw( uno::RuntimeException )
640 // Create one Id for all instances of this class.
641 // Use ethernet address to do this! (sal_True)
643 // Optimize this method
644 // We initialize a static variable only one time. And we don't must use a mutex at every call!
645 // For the first call; pID is NULL - for the second call pID is different from NULL!
646 static ::cppu::OImplementationId* pID = NULL ;
648 if ( pID == NULL )
650 // Ready for multithreading; get global mutex for first call of this method only! see before
651 ::osl::MutexGuard aGuard( MUTEX::getGlobalMutex() ) ;
653 // Control these pointer again ... it can be, that another instance will be faster then these!
654 if ( pID == NULL )
656 // Create a new static ID ...
657 static ::cppu::OImplementationId aID( sal_False ) ;
658 // ... and set his address to static pointer!
659 pID = &aID ;
663 return pID->getImplementationId() ;
666 //________________________________________________________________________________________________________
667 // XStarBasicAccess
668 //________________________________________________________________________________________________________
670 uno::Reference< script::XStarBasicAccess > implGetStarBasicAccess( SfxObjectShell* pObjectShell )
672 uno::Reference< script::XStarBasicAccess > xRet;
674 #ifdef DISABLE_SCRIPTING
675 (void) pObjectShell;
676 #else
677 if( pObjectShell )
679 BasicManager* pMgr = pObjectShell->GetBasicManager();
680 xRet = getStarBasicAccess( pMgr );
682 #endif
683 return xRet;
686 uno::Reference< XNAMECONTAINER > SAL_CALL SfxBaseModel::getLibraryContainer() throw( uno::RuntimeException )
688 #ifdef DISABLE_SCRIPTING
689 uno::Reference< XNAMECONTAINER > dummy;
691 return dummy;
692 #else
693 SfxModelGuard aGuard( *this );
695 uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
696 if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
697 rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
699 uno::Reference< XNAMECONTAINER > xRet;
700 if( rxAccess.is() )
701 xRet = rxAccess->getLibraryContainer();
702 return xRet;
703 #endif
706 /**___________________________________________________________________________________________________
707 @seealso XStarBasicAccess
709 void SAL_CALL SfxBaseModel::createLibrary( const ::rtl::OUString& LibName, const ::rtl::OUString& Password,
710 const ::rtl::OUString& ExternalSourceURL, const ::rtl::OUString& LinkTargetURL )
711 throw(ELEMENTEXISTEXCEPTION, uno::RuntimeException)
713 #ifdef DISABLE_SCRIPTING
714 (void) LibName;
715 (void) Password;
716 (void) ExternalSourceURL;
717 (void) LinkTargetURL;
718 #else
719 SfxModelGuard aGuard( *this );
721 uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
722 if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
723 rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
725 if( rxAccess.is() )
726 rxAccess->createLibrary( LibName, Password, ExternalSourceURL, LinkTargetURL );
727 #endif
730 /**___________________________________________________________________________________________________
731 @seealso XStarBasicAccess
733 void SAL_CALL SfxBaseModel::addModule( const ::rtl::OUString& LibraryName, const ::rtl::OUString& ModuleName,
734 const ::rtl::OUString& Language, const ::rtl::OUString& Source )
735 throw( NOSUCHELEMENTEXCEPTION, uno::RuntimeException)
737 #ifdef DISABLE_SCRIPTING
738 (void) LibraryName;
739 (void) ModuleName;
740 (void) Language;
741 (void) Source;
742 #else
743 SfxModelGuard aGuard( *this );
745 uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
746 if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
747 rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
749 if( rxAccess.is() )
750 rxAccess->addModule( LibraryName, ModuleName, Language, Source );
751 #endif
754 /**___________________________________________________________________________________________________
755 @seealso XStarBasicAccess
757 void SAL_CALL SfxBaseModel::addDialog( const ::rtl::OUString& LibraryName, const ::rtl::OUString& DialogName,
758 const ::com::sun::star::uno::Sequence< sal_Int8 >& Data )
759 throw(NOSUCHELEMENTEXCEPTION, uno::RuntimeException)
761 #ifdef DISABLE_SCRIPTING
762 (void) LibraryName;
763 (void) DialogName;
764 (void) Data;
765 #else
766 SfxModelGuard aGuard( *this );
768 uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
769 if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
770 rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
772 if( rxAccess.is() )
773 rxAccess->addDialog( LibraryName, DialogName, Data );
774 #endif
778 //________________________________________________________________________________________________________
779 // XChild
780 //________________________________________________________________________________________________________
782 uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getParent() throw( uno::RuntimeException )
784 SfxModelGuard aGuard( *this );
786 return m_pData->m_xParent;
789 //________________________________________________________________________________________________________
790 // XChild
791 //________________________________________________________________________________________________________
793 void SAL_CALL SfxBaseModel::setParent(const uno::Reference< uno::XInterface >& Parent) throw(NOSUPPORTEXCEPTION, uno::RuntimeException)
795 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
796 m_pData->m_xParent = Parent;
799 //________________________________________________________________________________________________________
800 // XChild
801 //________________________________________________________________________________________________________
803 void SAL_CALL SfxBaseModel::dispose() throw(::com::sun::star::uno::RuntimeException)
805 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
807 if ( !m_pData->m_bClosed )
809 // gracefully accept wrong dispose calls instead of close call
810 // and try to make it work (may be really disposed later!)
813 close( sal_True );
815 catch ( com::sun::star::util::CloseVetoException& )
819 return;
822 if ( m_pData->m_pStorageModifyListen.is() )
824 m_pData->m_pStorageModifyListen->dispose();
825 m_pData->m_pStorageModifyListen = NULL;
828 if ( m_pData->m_pDocumentUndoManager.is() )
830 m_pData->m_pDocumentUndoManager->disposing();
831 m_pData->m_pDocumentUndoManager = NULL;
834 lang::EventObject aEvent( (frame::XModel *)this );
835 m_pData->m_aInterfaceContainer.disposeAndClear( aEvent );
837 if ( m_pData->m_xDocumentInfo.is() )
839 // as long as an SfxObjectShell is assigned to an SfxBaseModel it is still existing here
840 // so we can't dispose the shared DocumentInfoObject here
841 m_pData->m_xDocumentInfo = 0;
844 m_pData->m_xDocumentProperties.clear();
846 m_pData->m_xDocumentMetadata.clear();
848 EndListening( *m_pData->m_pObjectShell );
850 m_pData->m_xCurrent = uno::Reference< frame::XController > ();
851 m_pData->m_seqControllers = uno::Sequence< uno::Reference< frame::XController > > () ;
853 // m_pData member must be set to zero before 0delete is called to
854 // force disposed exception whenever someone tries to access our
855 // instance while in the dtor.
856 IMPL_SfxBaseModel_DataContainer* pData = m_pData;
857 m_pData = 0;
858 delete pData;
861 //________________________________________________________________________________________________________
862 // XChild
863 //________________________________________________________________________________________________________
865 void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XEVENTLISTENER >& aListener )
866 throw(::com::sun::star::uno::RuntimeException)
868 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
869 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener );
872 //________________________________________________________________________________________________________
873 // XChild
874 //________________________________________________________________________________________________________
876 void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XEVENTLISTENER >& aListener )
877 throw(::com::sun::star::uno::RuntimeException)
879 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
880 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener );
883 //________________________________________________________________________________________________________
884 // document::XDocumentInfoSupplier
885 //________________________________________________________________________________________________________
887 uno::Reference< document::XDocumentInfo > SAL_CALL SfxBaseModel::getDocumentInfo() throw(::com::sun::star::uno::RuntimeException)
889 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
890 if ( !m_pData->m_xDocumentInfo.is() )
892 // WARNING: this will only work if (when loading a document) the
893 // document meta-data has already been read and completely written
894 // into the XDocumentProperties at this point
895 // ==> DO NOT call getDocumentInfo before document info has been read!
896 uno::Reference< document::XDocumentInfo > xDocInfo =
897 new SfxDocumentInfoObject;
898 uno::Reference< document::XDocumentProperties > xDocProps =
899 getDocumentProperties();
900 uno::Sequence< uno::Any > args(1);
901 args[0] <<= xDocProps;
902 uno::Reference< lang::XInitialization > xInit(
903 xDocInfo, uno::UNO_QUERY_THROW);
904 try {
905 xInit->initialize(args);
906 ((SfxBaseModel*)this)->m_pData->m_xDocumentInfo = xDocInfo;
907 } catch (uno::RuntimeException &) {
908 throw;
909 } catch (const uno::Exception & e) {
910 throw lang::WrappedTargetRuntimeException(::rtl::OUString(
911 "SfxBaseModel::getDocumentInfo: cannot initialize"), *this,
912 uno::makeAny(e));
914 try {
915 rtl::OUString aName("MediaType");
916 uno::Reference < beans::XPropertySet > xSet(
917 getDocumentStorage(), uno::UNO_QUERY_THROW );
918 uno::Any aMediaType = xSet->getPropertyValue( aName );
919 uno::Reference < beans::XPropertySet > xDocSet(
920 m_pData->m_xDocumentInfo, uno::UNO_QUERY_THROW );
921 xDocSet->setPropertyValue( aName, aMediaType );
922 } catch (uno::Exception &) {
923 //ignore
927 return m_pData->m_xDocumentInfo;
930 void
931 IMPL_SfxBaseModel_DataContainer::impl_setDocumentProperties(
932 const uno::Reference< document::XDocumentProperties >& rxNewDocProps)
934 m_xDocumentProperties.set(rxNewDocProps, uno::UNO_QUERY_THROW);
935 uno::Reference<util::XModifyBroadcaster> const xMB(m_xDocumentProperties,
936 uno::UNO_QUERY_THROW);
937 xMB->addModifyListener(new SfxDocInfoListener_Impl(*m_pObjectShell));
940 // document::XDocumentPropertiesSupplier:
941 uno::Reference< document::XDocumentProperties > SAL_CALL
942 SfxBaseModel::getDocumentProperties()
943 throw(::com::sun::star::uno::RuntimeException)
945 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
946 if ( !m_pData->m_xDocumentProperties.is() )
948 uno::Reference< document::XDocumentProperties > xDocProps(
949 ::comphelper::getProcessServiceFactory()->createInstance(
950 DEFINE_CONST_UNICODE("com.sun.star.document.DocumentProperties") ),
951 uno::UNO_QUERY_THROW);
952 m_pData->impl_setDocumentProperties(xDocProps);
955 return m_pData->m_xDocumentProperties;
959 //________________________________________________________________________________________________________
960 // XEVENTLISTENER
961 //________________________________________________________________________________________________________
963 void SAL_CALL SfxBaseModel::disposing( const lang::EventObject& aObject )
964 throw(::com::sun::star::uno::RuntimeException)
966 SolarMutexGuard aGuard;
967 if ( impl_isDisposed() )
968 return;
970 uno::Reference< XMODIFYLISTENER > xMod( aObject.Source, uno::UNO_QUERY );
971 uno::Reference< XEVENTLISTENER > xListener( aObject.Source, uno::UNO_QUERY );
972 uno::Reference< XDOCEVENTLISTENER > xDocListener( aObject.Source, uno::UNO_QUERY );
974 if ( xMod.is() )
975 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xMod );
976 else if ( xListener.is() )
977 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), xListener );
978 else if ( xDocListener.is() )
979 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), xListener );
982 //________________________________________________________________________________________________________
983 // frame::XModel
984 //________________________________________________________________________________________________________
986 sal_Bool SAL_CALL SfxBaseModel::attachResource( const ::rtl::OUString& rURL ,
987 const uno::Sequence< beans::PropertyValue >& rArgs )
988 throw(::com::sun::star::uno::RuntimeException)
990 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
991 if ( rURL.isEmpty() && rArgs.getLength() == 1 && rArgs[0].Name == "SetEmbedded" )
993 // allows to set a windowless document to EMBEDDED state
994 // but _only_ before load() or initNew() methods
995 if ( m_pData->m_pObjectShell.Is() && !m_pData->m_pObjectShell->GetMedium() )
997 sal_Bool bEmb = sal_Bool();
998 if ( ( rArgs[0].Value >>= bEmb ) && bEmb )
999 m_pData->m_pObjectShell->SetCreateMode_Impl( SFX_CREATE_MODE_EMBEDDED );
1002 return sal_True;
1005 if ( m_pData->m_pObjectShell.Is() )
1007 m_pData->m_sURL = rURL;
1009 SfxObjectShell* pObjectShell = m_pData->m_pObjectShell;
1011 ::comphelper::NamedValueCollection aArgs( rArgs );
1013 Sequence< sal_Int32 > aWinExtent;
1014 if ( ( aArgs.get( "WinExtent" ) >>= aWinExtent )&& ( aWinExtent.getLength() == 4 ) )
1016 Rectangle aVisArea( aWinExtent[0], aWinExtent[1], aWinExtent[2], aWinExtent[3] );
1017 aVisArea = OutputDevice::LogicToLogic( aVisArea, MAP_100TH_MM, pObjectShell->GetMapUnit() );
1018 pObjectShell->SetVisArea( aVisArea );
1021 sal_Bool bBreakMacroSign = sal_False;
1022 if ( aArgs.get( "BreakMacroSignature" ) >>= bBreakMacroSign )
1024 pObjectShell->BreakMacroSign_Impl( bBreakMacroSign );
1027 aArgs.remove( "WinExtent" );
1028 aArgs.remove( "BreakMacroSignature" );
1029 aArgs.remove( "Stream" );
1030 aArgs.remove( "InputStream" );
1031 aArgs.remove( "URL" );
1032 aArgs.remove( "Frame" );
1033 aArgs.remove( "Password" );
1034 aArgs.remove( "EncryptionData" );
1036 // TODO/LATER: all the parameters that are accepted by ItemSet of the DocShell must be removed here
1038 m_pData->m_seqArguments = aArgs.getPropertyValues();
1040 SfxMedium* pMedium = pObjectShell->GetMedium();
1041 if ( pMedium )
1043 SfxAllItemSet aSet( pObjectShell->GetPool() );
1044 TransformParameters( SID_OPENDOC, rArgs, aSet );
1046 // the arguments are not allowed to reach the medium
1047 aSet.ClearItem( SID_FILE_NAME );
1048 aSet.ClearItem( SID_FILLFRAME );
1050 pMedium->GetItemSet()->Put( aSet );
1051 SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1052 if ( pItem )
1053 pMedium->SetFilter(
1054 pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( pItem->GetValue() ) );
1056 SFX_ITEMSET_ARG( &aSet, pTitleItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
1057 if ( pTitleItem )
1059 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjectShell );
1060 if ( pFrame )
1061 pFrame->UpdateTitle();
1066 return sal_True ;
1069 //________________________________________________________________________________________________________
1070 // frame::XModel
1071 //________________________________________________________________________________________________________
1073 ::rtl::OUString SAL_CALL SfxBaseModel::getURL() throw(::com::sun::star::uno::RuntimeException)
1075 SfxModelGuard aGuard( *this );
1076 return m_pData->m_sURL ;
1079 //________________________________________________________________________________________________________
1080 // frame::XModel
1081 //________________________________________________________________________________________________________
1083 uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getArgs() throw(::com::sun::star::uno::RuntimeException)
1085 SfxModelGuard aGuard( *this );
1086 if ( m_pData->m_pObjectShell.Is() )
1088 uno::Sequence< beans::PropertyValue > seqArgsNew;
1089 uno::Sequence< beans::PropertyValue > seqArgsOld;
1090 SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
1092 // we need to know which properties are supported by the transformer
1093 // hopefully it is a temporary solution, I guess nonconvertable properties
1094 // should not be supported so then there will be only ItemSet from medium
1096 TransformItems( SID_OPENDOC, *(m_pData->m_pObjectShell->GetMedium()->GetItemSet()), seqArgsNew );
1097 TransformParameters( SID_OPENDOC, m_pData->m_seqArguments, aSet );
1098 TransformItems( SID_OPENDOC, aSet, seqArgsOld );
1100 sal_Int32 nOrgLength = m_pData->m_seqArguments.getLength();
1101 sal_Int32 nOldLength = seqArgsOld.getLength();
1102 sal_Int32 nNewLength = seqArgsNew.getLength();
1104 // "WinExtent" property should be updated always.
1105 // We can store it now to overwrite an old value
1106 // since it is not from ItemSet
1107 Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
1108 aTmpRect = OutputDevice::LogicToLogic( aTmpRect, m_pData->m_pObjectShell->GetMapUnit(), MAP_100TH_MM );
1110 Sequence< sal_Int32 > aRectSeq(4);
1111 aRectSeq[0] = aTmpRect.Left();
1112 aRectSeq[1] = aTmpRect.Top();
1113 aRectSeq[2] = aTmpRect.Right();
1114 aRectSeq[3] = aTmpRect.Bottom();
1116 seqArgsNew.realloc( ++nNewLength );
1117 seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString("WinExtent");
1118 seqArgsNew[ nNewLength - 1 ].Value <<= aRectSeq;
1120 if ( !m_pData->m_aPreusedFilterName.isEmpty() )
1122 seqArgsNew.realloc( ++nNewLength );
1123 seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString("PreusedFilterName");
1124 seqArgsNew[ nNewLength - 1 ].Value <<= m_pData->m_aPreusedFilterName;
1127 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
1128 if ( pFrame )
1130 SvBorder aBorder = pFrame->GetBorderPixelImpl( pFrame->GetViewShell() );
1132 Sequence< sal_Int32 > aBorderSeq(4);
1133 aBorderSeq[0] = aBorder.Left();
1134 aBorderSeq[1] = aBorder.Top();
1135 aBorderSeq[2] = aBorder.Right();
1136 aBorderSeq[3] = aBorder.Bottom();
1138 seqArgsNew.realloc( ++nNewLength );
1139 seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString("DocumentBorder");
1140 seqArgsNew[ nNewLength - 1 ].Value <<= aBorderSeq;
1143 // only the values that are not supported by the ItemSet must be cached here
1144 uno::Sequence< beans::PropertyValue > aFinalCache;
1145 sal_Int32 nFinalLength = 0;
1147 for ( sal_Int32 nOrg = 0; nOrg < nOrgLength; nOrg++ )
1149 sal_Int32 nOldInd = 0;
1150 while ( nOldInd < nOldLength )
1152 if ( m_pData->m_seqArguments[nOrg].Name.equals( seqArgsOld[nOldInd].Name ) )
1153 break;
1154 nOldInd++;
1157 if ( nOldInd == nOldLength )
1159 // the entity with this name should be new for seqArgsNew
1160 // since it is not supported by transformer
1162 seqArgsNew.realloc( ++nNewLength );
1163 seqArgsNew[ nNewLength - 1 ] = m_pData->m_seqArguments[nOrg];
1165 aFinalCache.realloc( ++nFinalLength );
1166 aFinalCache[ nFinalLength - 1 ] = m_pData->m_seqArguments[nOrg];
1170 m_pData->m_seqArguments = aFinalCache;
1172 return seqArgsNew;
1175 return m_pData->m_seqArguments;
1178 //________________________________________________________________________________________________________
1179 // frame::XModel
1180 //________________________________________________________________________________________________________
1182 void SAL_CALL SfxBaseModel::connectController( const uno::Reference< frame::XController >& xController )
1183 throw(::com::sun::star::uno::RuntimeException)
1185 SfxModelGuard aGuard( *this );
1186 OSL_PRECOND( xController.is(), "SfxBaseModel::connectController: invalid controller!" );
1187 if ( !xController.is() )
1188 return;
1190 sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength();
1191 uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount + 1 );
1192 for ( sal_uInt32 n = 0; n < nOldCount; n++ )
1193 aNewSeq.getArray()[n] = m_pData->m_seqControllers.getConstArray()[n];
1194 aNewSeq.getArray()[nOldCount] = xController;
1195 m_pData->m_seqControllers = aNewSeq;
1197 if ( m_pData->m_seqControllers.getLength() == 1 )
1199 SfxViewFrame* pViewFrame = SfxViewFrame::Get( xController, GetObjectShell() );
1200 ENSURE_OR_THROW( pViewFrame, "SFX document without SFX view!?" );
1201 bool bOldLock = pViewFrame->GetDispatcher()->IsLocked();
1202 pViewFrame->GetDispatcher()->Lock(sal_True);
1203 pViewFrame->UpdateDocument_Impl();
1204 pViewFrame->GetDispatcher()->Lock(bOldLock);
1205 const String sDocumentURL = GetObjectShell()->GetMedium()->GetName();
1206 if ( sDocumentURL.Len() )
1207 SFX_APP()->Broadcast( SfxStringHint( SID_OPENURL, sDocumentURL ) );
1211 //________________________________________________________________________________________________________
1212 // frame::XModel
1213 //________________________________________________________________________________________________________
1215 void SAL_CALL SfxBaseModel::disconnectController( const uno::Reference< frame::XController >& xController ) throw(::com::sun::star::uno::RuntimeException)
1217 SfxModelGuard aGuard( *this );
1219 sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength();
1220 if ( !nOldCount )
1221 return;
1223 uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount - 1 );
1224 for ( sal_uInt32 nOld = 0, nNew = 0; nOld < nOldCount; ++nOld )
1226 if ( xController != m_pData->m_seqControllers.getConstArray()[nOld] )
1228 aNewSeq.getArray()[nNew] = m_pData->m_seqControllers.getConstArray()[nOld];
1229 ++nNew;
1233 m_pData->m_seqControllers = aNewSeq;
1235 if ( xController == m_pData->m_xCurrent )
1236 m_pData->m_xCurrent = uno::Reference< frame::XController > ();
1239 namespace
1241 typedef ::cppu::WeakImplHelper1< XUndoAction > ControllerLockUndoAction_Base;
1242 class ControllerLockUndoAction : public ControllerLockUndoAction_Base
1244 public:
1245 ControllerLockUndoAction( const Reference< XModel >& i_model, const bool i_undoIsUnlock )
1246 :m_xModel( i_model )
1247 ,m_bUndoIsUnlock( i_undoIsUnlock )
1251 // XUndoAction
1252 virtual ::rtl::OUString SAL_CALL getTitle() throw (RuntimeException);
1253 virtual void SAL_CALL undo( ) throw (UndoFailedException, RuntimeException);
1254 virtual void SAL_CALL redo( ) throw (UndoFailedException, RuntimeException);
1256 private:
1257 const Reference< XModel > m_xModel;
1258 const bool m_bUndoIsUnlock;
1261 ::rtl::OUString SAL_CALL ControllerLockUndoAction::getTitle() throw (RuntimeException)
1263 // this action is intended to be used within an UndoContext only, so nobody will ever see this title ...
1264 return ::rtl::OUString();
1267 void SAL_CALL ControllerLockUndoAction::undo( ) throw (UndoFailedException, RuntimeException)
1269 if ( m_bUndoIsUnlock )
1270 m_xModel->unlockControllers();
1271 else
1272 m_xModel->lockControllers();
1275 void SAL_CALL ControllerLockUndoAction::redo( ) throw (UndoFailedException, RuntimeException)
1277 if ( m_bUndoIsUnlock )
1278 m_xModel->lockControllers();
1279 else
1280 m_xModel->unlockControllers();
1284 //________________________________________________________________________________________________________
1285 // frame::XModel
1286 //________________________________________________________________________________________________________
1288 void SAL_CALL SfxBaseModel::lockControllers() throw(::com::sun::star::uno::RuntimeException)
1290 SfxModelGuard aGuard( *this );
1292 ++m_pData->m_nControllerLockCount ;
1294 if ( m_pData->m_pDocumentUndoManager.is()
1295 && m_pData->m_pDocumentUndoManager->isInContext()
1296 && !m_pData->m_pDocumentUndoManager->isLocked()
1299 m_pData->m_pDocumentUndoManager->addUndoAction( new ControllerLockUndoAction( this, true ) );
1303 //________________________________________________________________________________________________________
1304 // frame::XModel
1305 //________________________________________________________________________________________________________
1307 void SAL_CALL SfxBaseModel::unlockControllers() throw(::com::sun::star::uno::RuntimeException)
1309 SfxModelGuard aGuard( *this );
1311 --m_pData->m_nControllerLockCount ;
1313 if ( m_pData->m_pDocumentUndoManager.is()
1314 && m_pData->m_pDocumentUndoManager->isInContext()
1315 && !m_pData->m_pDocumentUndoManager->isLocked()
1318 m_pData->m_pDocumentUndoManager->addUndoAction( new ControllerLockUndoAction( this, false ) );
1322 //________________________________________________________________________________________________________
1323 // frame::XModel
1324 //________________________________________________________________________________________________________
1326 sal_Bool SAL_CALL SfxBaseModel::hasControllersLocked() throw(::com::sun::star::uno::RuntimeException)
1328 SfxModelGuard aGuard( *this );
1329 return ( m_pData->m_nControllerLockCount != 0 ) ;
1332 //________________________________________________________________________________________________________
1333 // frame::XModel
1334 //________________________________________________________________________________________________________
1336 uno::Reference< frame::XController > SAL_CALL SfxBaseModel::getCurrentController() throw(::com::sun::star::uno::RuntimeException)
1338 SfxModelGuard aGuard( *this );
1340 // get the last active controller of this model
1341 if ( m_pData->m_xCurrent.is() )
1342 return m_pData->m_xCurrent;
1344 // get the first controller of this model
1345 return m_pData->m_seqControllers.getLength() ? m_pData->m_seqControllers.getConstArray()[0] : m_pData->m_xCurrent;
1348 //________________________________________________________________________________________________________
1349 // frame::XModel
1350 //________________________________________________________________________________________________________
1352 void SAL_CALL SfxBaseModel::setCurrentController( const uno::Reference< frame::XController >& xCurrentController )
1353 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
1355 SfxModelGuard aGuard( *this );
1357 m_pData->m_xCurrent = xCurrentController;
1360 //________________________________________________________________________________________________________
1361 // frame::XModel
1362 //________________________________________________________________________________________________________
1364 uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getCurrentSelection() throw(::com::sun::star::uno::RuntimeException)
1366 SfxModelGuard aGuard( *this );
1368 uno::Reference< uno::XInterface > xReturn;
1369 uno::Reference< frame::XController > xController = getCurrentController() ;
1371 if ( xController.is() )
1373 uno::Reference< view::XSelectionSupplier > xDocView( xController, uno::UNO_QUERY );
1374 if ( xDocView.is() )
1376 uno::Any xSel = xDocView->getSelection();
1377 xSel >>= xReturn ;
1381 return xReturn ;
1384 //________________________________________________________________________________________________________
1385 // XModifiable2
1386 //________________________________________________________________________________________________________
1388 sal_Bool SAL_CALL SfxBaseModel::disableSetModified() throw (::com::sun::star::uno::RuntimeException)
1390 SfxModelGuard aGuard( *this );
1392 if ( !m_pData->m_pObjectShell.Is() )
1393 throw uno::RuntimeException();
1395 sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified();
1396 m_pData->m_pObjectShell->EnableSetModified( sal_False );
1398 return bResult;
1401 sal_Bool SAL_CALL SfxBaseModel::enableSetModified() throw (::com::sun::star::uno::RuntimeException)
1403 SfxModelGuard aGuard( *this );
1405 if ( !m_pData->m_pObjectShell.Is() )
1406 throw uno::RuntimeException();
1408 sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified();
1409 m_pData->m_pObjectShell->EnableSetModified( sal_True );
1411 return bResult;
1414 sal_Bool SAL_CALL SfxBaseModel::isSetModifiedEnabled() throw (::com::sun::star::uno::RuntimeException)
1416 SfxModelGuard aGuard( *this );
1418 if ( !m_pData->m_pObjectShell.Is() )
1419 throw uno::RuntimeException();
1421 return m_pData->m_pObjectShell->IsEnableSetModified();
1424 //________________________________________________________________________________________________________
1425 // XModifiable
1426 //________________________________________________________________________________________________________
1428 sal_Bool SAL_CALL SfxBaseModel::isModified() throw(::com::sun::star::uno::RuntimeException)
1430 SfxModelGuard aGuard( *this );
1432 return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsModified() : sal_False;
1435 //________________________________________________________________________________________________________
1436 // XModifiable
1437 //________________________________________________________________________________________________________
1439 void SAL_CALL SfxBaseModel::setModified( sal_Bool bModified )
1440 throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException)
1442 SfxModelGuard aGuard( *this );
1444 if ( m_pData->m_pObjectShell.Is() )
1445 m_pData->m_pObjectShell->SetModified(bModified);
1448 //________________________________________________________________________________________________________
1449 // XModifiable
1450 //________________________________________________________________________________________________________
1452 void SAL_CALL SfxBaseModel::addModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException )
1454 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1456 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0),xListener );
1459 //________________________________________________________________________________________________________
1460 // XModifiable
1461 //________________________________________________________________________________________________________
1463 void SAL_CALL SfxBaseModel::removeModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException )
1465 SfxModelGuard aGuard( *this );
1467 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xListener );
1470 //____________________________________________________________________________________________________
1471 // XCloseable
1472 //____________________________________________________________________________________________________
1474 void SAL_CALL SfxBaseModel::close( sal_Bool bDeliverOwnership ) throw (util::CloseVetoException, uno::RuntimeException)
1476 static ::rtl::OUString MSG_1("Cant close while saving.");
1478 SolarMutexGuard aGuard;
1479 if ( impl_isDisposed() || m_pData->m_bClosed || m_pData->m_bClosing )
1480 return;
1482 uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
1483 lang::EventObject aSource (static_cast< ::cppu::OWeakObject*>(this));
1484 ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
1485 if (pContainer!=NULL)
1487 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
1488 while (pIterator.hasMoreElements())
1492 ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership );
1494 catch( uno::RuntimeException& )
1496 pIterator.remove();
1501 if ( m_pData->m_bSaving )
1503 if (bDeliverOwnership)
1504 m_pData->m_bSuicide = sal_True;
1505 throw util::CloseVetoException(
1506 MSG_1,
1507 static_cast< ::com::sun::star::util::XCloseable* >(this));
1510 // no own objections against closing!
1511 m_pData->m_bClosing = sal_True;
1512 pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
1513 if (pContainer!=NULL)
1515 ::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer);
1516 while (pCloseIterator.hasMoreElements())
1520 ((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource );
1522 catch( uno::RuntimeException& )
1524 pCloseIterator.remove();
1529 m_pData->m_bClosed = sal_True;
1530 m_pData->m_bClosing = sal_False;
1532 dispose();
1535 //____________________________________________________________________________________________________
1536 // XCloseBroadcaster
1537 //____________________________________________________________________________________________________
1539 void SAL_CALL SfxBaseModel::addCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException)
1541 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1543 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener );
1546 //____________________________________________________________________________________________________
1547 // XCloseBroadcaster
1548 //____________________________________________________________________________________________________
1550 void SAL_CALL SfxBaseModel::removeCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException)
1552 SfxModelGuard aGuard( *this );
1554 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener );
1557 //________________________________________________________________________________________________________
1558 // XPrintable
1559 //________________________________________________________________________________________________________
1561 uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getPrinter() throw(::com::sun::star::uno::RuntimeException)
1563 SfxModelGuard aGuard( *this );
1565 if ( impl_getPrintHelper() )
1566 return m_pData->m_xPrintable->getPrinter();
1567 else
1568 return uno::Sequence< beans::PropertyValue >();
1571 void SAL_CALL SfxBaseModel::setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter)
1572 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1574 SfxModelGuard aGuard( *this );
1576 if ( impl_getPrintHelper() )
1577 m_pData->m_xPrintable->setPrinter( rPrinter );
1580 void SAL_CALL SfxBaseModel::print(const uno::Sequence< beans::PropertyValue >& rOptions)
1581 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1583 SfxModelGuard aGuard( *this );
1585 if ( impl_getPrintHelper() )
1586 m_pData->m_xPrintable->print( rOptions );
1589 //________________________________________________________________________________________________________
1590 // XStorable
1591 //________________________________________________________________________________________________________
1593 sal_Bool SAL_CALL SfxBaseModel::hasLocation() throw(::com::sun::star::uno::RuntimeException)
1595 SfxModelGuard aGuard( *this );
1597 return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->HasName() : sal_False;
1600 //________________________________________________________________________________________________________
1601 // XStorable
1602 //________________________________________________________________________________________________________
1604 ::rtl::OUString SAL_CALL SfxBaseModel::getLocation() throw(::com::sun::star::uno::RuntimeException)
1606 SfxModelGuard aGuard( *this );
1608 if ( m_pData->m_pObjectShell.Is() )
1610 // TODO/LATER: is it correct that the shared document returns shared file location?
1611 if ( m_pData->m_pObjectShell->IsDocShared() )
1612 return m_pData->m_pObjectShell->GetSharedFileURL();
1613 else
1614 return ::rtl::OUString(m_pData->m_pObjectShell->GetMedium()->GetName());
1617 return m_pData->m_sURL;
1620 //________________________________________________________________________________________________________
1621 // XStorable
1622 //________________________________________________________________________________________________________
1624 sal_Bool SAL_CALL SfxBaseModel::isReadonly() throw(::com::sun::star::uno::RuntimeException)
1626 SfxModelGuard aGuard( *this );
1628 return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsReadOnly() : sal_True;
1631 //________________________________________________________________________________________________________
1632 // XStorable2
1633 //________________________________________________________________________________________________________
1635 void SAL_CALL SfxBaseModel::storeSelf( const uno::Sequence< beans::PropertyValue >& aSeqArgs )
1636 throw ( ::com::sun::star::lang::IllegalArgumentException,
1637 ::com::sun::star::io::IOException,
1638 ::com::sun::star::uno::RuntimeException )
1640 RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeSelf" );
1642 SfxModelGuard aGuard( *this );
1644 if ( m_pData->m_pObjectShell.Is() )
1646 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "storeSelf" ) );
1647 SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1649 for ( sal_Int32 nInd = 0; nInd < aSeqArgs.getLength(); nInd++ )
1651 // check that only acceptable parameters are provided here
1652 if ( aSeqArgs[nInd].Name != "VersionComment" && aSeqArgs[nInd].Name != "Author"
1653 && aSeqArgs[nInd].Name != "InteractionHandler" && aSeqArgs[nInd].Name != "StatusIndicator" )
1655 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "unexpected parameter for storeSelf, might be no problem if SaveAs is executed." ) );
1656 m_pData->m_pObjectShell->StoreLog();
1658 ::rtl::OUString aMessage( "Unexpected MediaDescriptor parameter: " );
1659 aMessage += aSeqArgs[nInd].Name;
1660 throw lang::IllegalArgumentException( aMessage, uno::Reference< uno::XInterface >(), 1 );
1664 SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() );
1665 TransformParameters( SID_SAVEDOC, aSeqArgs, *pParams );
1667 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOC, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOC), m_pData->m_pObjectShell ) );
1669 sal_Bool bRet = sal_False;
1671 // TODO/LATER: let the embedded case of saving be handled more careful
1672 if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1674 // If this is an embedded object that has no URL based location it should be stored to own storage.
1675 // An embedded object can have a location based on URL in case it is a link, then it should be
1676 // stored in normal way.
1677 if ( !hasLocation() || getLocation().compareToAscii( "private:", 8 ) == 0 )
1679 // actually in this very rare case only UI parameters have sence
1680 // TODO/LATER: should be done later, after integration of sb19
1681 bRet = m_pData->m_pObjectShell->DoSave()
1682 && m_pData->m_pObjectShell->DoSaveCompleted();
1684 else
1686 bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
1689 else
1690 bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
1692 DELETEZ( pParams );
1694 sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ? m_pData->m_pObjectShell->GetError()
1695 : ERRCODE_IO_CANTWRITE;
1696 m_pData->m_pObjectShell->ResetError();
1698 if ( bRet )
1700 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "successful saving." ) );
1701 m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
1703 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCDONE), m_pData->m_pObjectShell ) );
1705 else
1707 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Storing failed!" ) );
1708 m_pData->m_pObjectShell->StoreLog();
1710 // write the contents of the logger to the file
1711 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCFAILED, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCFAILED), m_pData->m_pObjectShell ) );
1713 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
1719 //________________________________________________________________________________________________________
1720 // XStorable
1721 //________________________________________________________________________________________________________
1723 void SAL_CALL SfxBaseModel::store() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1725 storeSelf( uno::Sequence< beans::PropertyValue >() );
1728 //________________________________________________________________________________________________________
1729 // XStorable
1730 //________________________________________________________________________________________________________
1732 void SAL_CALL SfxBaseModel::storeAsURL( const ::rtl::OUString& rURL ,
1733 const uno::Sequence< beans::PropertyValue >& rArgs )
1734 throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1736 RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeAsURL" );
1738 SfxModelGuard aGuard( *this );
1740 if ( m_pData->m_pObjectShell.Is() )
1742 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "storeAsURL" ) );
1743 SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1745 impl_store( rURL, rArgs, sal_False );
1747 uno::Sequence< beans::PropertyValue > aSequence ;
1748 TransformItems( SID_OPENDOC, *m_pData->m_pObjectShell->GetMedium()->GetItemSet(), aSequence );
1749 attachResource( rURL, aSequence );
1751 #if OSL_DEBUG_LEVEL > 0
1752 SFX_ITEMSET_ARG( m_pData->m_pObjectShell->GetMedium()->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
1753 OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
1754 #endif
1758 //________________________________________________________________________________________________________
1759 // XUndoManagerSupplier
1760 //________________________________________________________________________________________________________
1761 Reference< XUndoManager > SAL_CALL SfxBaseModel::getUndoManager( ) throw (RuntimeException)
1763 SfxModelGuard aGuard( *this );
1764 if ( !m_pData->m_pDocumentUndoManager.is() )
1765 m_pData->m_pDocumentUndoManager.set( new ::sfx2::DocumentUndoManager( *this ) );
1766 return m_pData->m_pDocumentUndoManager.get();
1769 //________________________________________________________________________________________________________
1770 // XStorable
1771 //________________________________________________________________________________________________________
1773 void SAL_CALL SfxBaseModel::storeToURL( const ::rtl::OUString& rURL ,
1774 const uno::Sequence< beans::PropertyValue >& rArgs )
1775 throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1777 SfxModelGuard aGuard( *this );
1779 if ( m_pData->m_pObjectShell.Is() )
1781 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "storeToURL" ) );
1782 SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1783 impl_store( rURL, rArgs, sal_True );
1787 ::sal_Bool SAL_CALL SfxBaseModel::wasModifiedSinceLastSave() throw ( RuntimeException )
1789 SfxModelGuard aGuard( *this );
1790 return m_pData->m_bModifiedSinceLastSave;
1793 void SAL_CALL SfxBaseModel::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
1795 SfxModelGuard aGuard( *this );
1797 // delegate
1798 SfxSaveGuard aSaveGuard( this, m_pData, sal_False );
1799 impl_store( i_TargetLocation, i_MediaDescriptor, sal_True );
1801 // no need for subsequent calls to storeToRecoveryFile, unless we're modified, again
1802 m_pData->m_bModifiedSinceLastSave = sal_False;
1805 void SAL_CALL SfxBaseModel::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
1807 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1809 // delegate to our "load" method
1810 ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor );
1812 // our load implementation expects the SalvagedFile to be in the media descriptor
1813 OSL_ENSURE( !aMediaDescriptor.has( "SalvagedFile" ) || ( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) == i_SalvagedFile ),
1814 "SfxBaseModel::recoverFromFile: inconsistent information!" );
1815 aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile );
1817 // similar for the to-be-loaded file
1818 OSL_ENSURE( !aMediaDescriptor.has( "URL" ) || ( aMediaDescriptor.getOrDefault( "URL", ::rtl::OUString() ) == i_SourceLocation ),
1819 "SfxBaseModel::recoverFromFile: inconsistent information!" );
1820 aMediaDescriptor.put( "URL", i_SourceLocation );
1822 load( aMediaDescriptor.getPropertyValues() );
1824 // Note: The XDocumentRecovery interface specification requires us to do an attachResource after loading.
1825 // However, we will not do this here, as we know that our load implementation (respectively some method
1826 // called from there) already did so.
1827 // In particular, the load process might already have modified some elements of the media
1828 // descriptor, for instance the MacroExecMode (in case the user was involved to decide about it), and we do
1829 // not want to overwrite it with the "old" elements passed to this method here.
1832 //________________________________________________________________________________________________________
1833 // XLoadable
1834 //________________________________________________________________________________________________________
1836 void SAL_CALL SfxBaseModel::initNew()
1837 throw (::com::sun::star::frame::DoubleInitializationException,
1838 ::com::sun::star::io::IOException,
1839 ::com::sun::star::uno::RuntimeException,
1840 ::com::sun::star::uno::Exception)
1842 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1843 if ( IsInitialized() )
1844 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
1846 // the object shell should exist always
1847 DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
1848 if ( m_pData->m_pObjectShell.Is() )
1850 if( m_pData->m_pObjectShell->GetMedium() )
1851 throw DOUBLEINITIALIZATIONEXCEPTION();
1853 sal_Bool bRes = m_pData->m_pObjectShell->DoInitNew( NULL );
1854 sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ?
1855 m_pData->m_pObjectShell->GetError() : ERRCODE_IO_CANTCREATE;
1856 m_pData->m_pObjectShell->ResetError();
1858 if ( !bRes )
1859 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
1863 //________________________________________________________________________________________________________
1864 // XLoadable
1865 //________________________________________________________________________________________________________
1867 void SAL_CALL SfxBaseModel::load( const uno::Sequence< beans::PropertyValue >& seqArguments )
1868 throw (::com::sun::star::frame::DoubleInitializationException,
1869 ::com::sun::star::io::IOException,
1870 ::com::sun::star::uno::RuntimeException,
1871 ::com::sun::star::uno::Exception)
1873 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1874 if ( IsInitialized() )
1875 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
1877 // the object shell should exist always
1878 DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
1880 if ( m_pData->m_pObjectShell.Is() )
1882 if( m_pData->m_pObjectShell->GetMedium() )
1883 // if a Medium is present, the document is already initialized
1884 throw DOUBLEINITIALIZATIONEXCEPTION();
1886 SfxMedium* pMedium = new SfxMedium( seqArguments );
1887 String aFilterName;
1888 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1889 if( pFilterNameItem )
1890 aFilterName = pFilterNameItem->GetValue();
1891 if( !m_pData->m_pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) )
1893 // filtername is not valid
1894 delete pMedium;
1895 throw frame::IllegalArgumentIOException();
1898 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1899 sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
1901 // load document
1902 sal_uInt32 nError = ERRCODE_NONE;
1903 if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
1904 nError=ERRCODE_IO_GENERAL;
1906 // QUESTION: if the following happens outside of DoLoad, something important is missing there!
1907 ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler = pMedium->GetInteractionHandler();
1908 if( m_pData->m_pObjectShell->GetErrorCode() )
1910 nError = m_pData->m_pObjectShell->GetErrorCode();
1911 if ( nError == ERRCODE_IO_BROKENPACKAGE && xHandler.is() )
1913 ::rtl::OUString aDocName = pMedium->GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1914 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
1915 if ( !pRepairItem || !pRepairItem->GetValue() )
1917 RequestPackageReparation aRequest( aDocName );
1918 xHandler->handle( aRequest.GetRequest() );
1919 if( aRequest.isApproved() )
1921 // broken package: try second loading and allow repair
1922 pMedium->GetItemSet()->Put( SfxBoolItem( SID_REPAIRPACKAGE, sal_True ) );
1923 pMedium->GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
1924 pMedium->GetItemSet()->Put( SfxStringItem( SID_DOCINFO_TITLE, aDocName ) );
1926 // the error must be reset and the storage must be reopened in new mode
1927 pMedium->ResetError();
1928 pMedium->CloseStorage();
1929 m_pData->m_pObjectShell->PrepareSecondTryLoad_Impl();
1930 if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
1931 nError=ERRCODE_IO_GENERAL;
1932 nError = m_pData->m_pObjectShell->GetErrorCode();
1936 if ( nError == ERRCODE_IO_BROKENPACKAGE )
1938 // repair either not allowed or not successful
1939 NotifyBrokenPackage aRequest( aDocName );
1940 xHandler->handle( aRequest.GetRequest() );
1945 if( m_pData->m_pObjectShell->IsAbortingImport() )
1946 nError = ERRCODE_ABORT;
1948 if( bSalvage )
1950 // file recovery: restore original filter
1951 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1952 SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
1953 const SfxFilter* pSetFilter = rMatcher.GetFilter4FilterName( pFilterItem->GetValue() );
1954 pMedium->SetFilter( pSetFilter );
1955 m_pData->m_pObjectShell->SetModified(sal_True);
1958 // TODO/LATER: may be the mode should be retrieved from outside and the preused filter should not be set
1959 if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1961 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1962 if ( pFilterItem )
1963 m_pData->m_aPreusedFilterName = pFilterItem->GetValue();
1966 if ( !nError )
1967 nError = pMedium->GetError();
1969 m_pData->m_pObjectShell->ResetError();
1971 if ( nError )
1973 sal_Bool bSilent = sal_False;
1974 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
1975 if( pSilentItem )
1976 bSilent = pSilentItem->GetValue();
1978 sal_Bool bWarning = ((nError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK);
1979 if ( nError != ERRCODE_IO_BROKENPACKAGE && !bSilent )
1981 // broken package was handled already
1982 if ( SfxObjectShell::UseInteractionToHandleError( xHandler, nError ) && !bWarning )
1984 // abort loading (except for warnings)
1985 nError = ERRCODE_IO_ABORT;
1989 if ( m_pData->m_pObjectShell->GetMedium() != pMedium )
1991 // for whatever reason document now has another medium
1992 OSL_FAIL("Document has rejected the medium?!");
1993 delete pMedium;
1996 if ( !bWarning ) // #i30711# don't abort loading if it's only a warning
1998 throw task::ErrorCodeIOException( ::rtl::OUString(),
1999 uno::Reference< uno::XInterface >(),
2000 nError ? nError : ERRCODE_IO_CANTREAD );
2004 sal_Bool bHidden = sal_False;
2005 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False);
2006 if ( pHidItem )
2007 bHidden = pHidItem->GetValue();
2009 #if OSL_DEBUG_LEVEL > 0
2010 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
2011 OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
2012 #endif
2013 // !TODO: will be done by Framework!
2014 pMedium->SetUpdatePickList( !bHidden );
2018 //________________________________________________________________________________________________________
2019 // XTransferable
2020 //________________________________________________________________________________________________________
2022 uno::Any SAL_CALL SfxBaseModel::getTransferData( const DATAFLAVOR& aFlavor )
2023 throw (::com::sun::star::datatransfer::UnsupportedFlavorException,
2024 ::com::sun::star::io::IOException,
2025 ::com::sun::star::uno::RuntimeException)
2027 SfxModelGuard aGuard( *this );
2029 uno::Any aAny;
2031 if ( m_pData->m_pObjectShell.Is() )
2033 if ( aFlavor.MimeType == "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" )
2035 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2037 TransferableObjectDescriptor aDesc;
2039 aDesc.maClassName = m_pData->m_pObjectShell->GetClassName();
2040 aDesc.maTypeName = aFlavor.HumanPresentableName;
2042 // TODO/LATER: ViewAspect needs to be sal_Int64
2043 aDesc.mnViewAspect = sal::static_int_cast< sal_uInt16 >( embed::Aspects::MSOLE_CONTENT );
2045 //TODO/LATER: status needs to become sal_Int64
2046 aDesc.mnOle2Misc = m_pData->m_pObjectShell->GetMiscStatus();
2047 Size aSize = m_pData->m_pObjectShell->GetVisArea().GetSize();
2049 MapUnit aMapUnit = m_pData->m_pObjectShell->GetMapUnit();
2050 aDesc.maSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
2051 aDesc.maDragStartPos = Point();
2052 aDesc.maDisplayName = String();
2053 aDesc.mbCanLink = sal_False;
2055 SvMemoryStream aMemStm( 1024, 1024 );
2056 aMemStm << aDesc;
2057 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() );
2059 else
2060 throw datatransfer::UnsupportedFlavorException();
2062 else if ( aFlavor.MimeType == "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" )
2064 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2068 utl::TempFile aTmp;
2069 aTmp.EnableKillingFile( sal_True );
2070 storeToURL( aTmp.GetURL(), uno::Sequence < beans::PropertyValue >() );
2071 SvStream* pStream = aTmp.GetStream( STREAM_READ );
2072 const sal_uInt32 nLen = pStream->Seek( STREAM_SEEK_TO_END );
2073 ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
2074 pStream->Seek( STREAM_SEEK_TO_BEGIN );
2075 pStream->Read( aSeq.getArray(), nLen );
2076 delete pStream;
2077 if( aSeq.getLength() )
2078 aAny <<= aSeq;
2080 catch ( uno::Exception& )
2084 else
2085 throw datatransfer::UnsupportedFlavorException();
2087 else if ( aFlavor.MimeType == "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" )
2089 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2092 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2093 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2095 if ( pMetaFile )
2097 SvMemoryStream aMemStm( 65535, 65535 );
2098 aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2100 pMetaFile->Write( aMemStm );
2101 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
2102 aMemStm.Seek( STREAM_SEEK_TO_END ) );
2105 else
2106 throw datatransfer::UnsupportedFlavorException();
2108 else if ( aFlavor.MimeType == "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" )
2110 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2112 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2113 m_pData->m_pObjectShell->CreatePreviewMetaFile_Impl( sal_True );
2115 if ( pMetaFile )
2117 SvMemoryStream aMemStm( 65535, 65535 );
2118 aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2120 pMetaFile->Write( aMemStm );
2121 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
2122 aMemStm.Seek( STREAM_SEEK_TO_END ) );
2125 else
2126 throw datatransfer::UnsupportedFlavorException();
2128 else if ( aFlavor.MimeType == "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" )
2130 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2132 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2133 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2135 if ( pMetaFile )
2137 ::boost::shared_ptr<SvMemoryStream> pStream(
2138 GraphicHelper::getFormatStrFromGDI_Impl(
2139 pMetaFile.get(), CVT_EMF ) );
2140 if ( pStream )
2142 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2143 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2144 pStream->Seek( STREAM_SEEK_TO_END ) );
2148 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2149 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2151 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2152 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2154 if ( pMetaFile )
2156 aAny <<= reinterpret_cast< const sal_uInt64 >(
2157 GraphicHelper::getEnhMetaFileFromGDI_Impl( pMetaFile.get() ) );
2160 else
2161 throw datatransfer::UnsupportedFlavorException();
2163 else if ( aFlavor.MimeType == "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" )
2165 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2167 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2168 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2170 if ( pMetaFile )
2172 ::boost::shared_ptr<SvMemoryStream> pStream(
2173 GraphicHelper::getFormatStrFromGDI_Impl(
2174 pMetaFile.get(), CVT_WMF ) );
2176 if ( pStream )
2178 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2179 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2180 pStream->Seek( STREAM_SEEK_TO_END ) );
2184 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2185 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2187 // means HGLOBAL handler to memory storage containing METAFILEPICT structure
2189 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2190 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2192 if ( pMetaFile )
2194 Size aMetaSize = pMetaFile->GetPrefSize();
2195 aAny <<= reinterpret_cast< const sal_uInt64 >(
2196 GraphicHelper::getWinMetaFileFromGDI_Impl(
2197 pMetaFile.get(), aMetaSize ) );
2200 else
2201 throw datatransfer::UnsupportedFlavorException();
2203 else if ( aFlavor.MimeType == "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" )
2205 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2207 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2208 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2210 if ( pMetaFile )
2212 ::boost::shared_ptr<SvMemoryStream> pStream(
2213 GraphicHelper::getFormatStrFromGDI_Impl(
2214 pMetaFile.get(), CVT_BMP ) );
2216 if ( pStream )
2218 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2219 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2220 pStream->Seek( STREAM_SEEK_TO_END ) );
2224 else
2225 throw datatransfer::UnsupportedFlavorException();
2227 else if ( aFlavor.MimeType == "image/png" )
2229 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2231 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2232 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2234 if ( pMetaFile )
2236 ::boost::shared_ptr<SvMemoryStream> pStream(
2237 GraphicHelper::getFormatStrFromGDI_Impl(
2238 pMetaFile.get(), CVT_PNG ) );
2240 if ( pStream )
2242 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2243 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2244 pStream->Seek( STREAM_SEEK_TO_END ) );
2248 else
2249 throw datatransfer::UnsupportedFlavorException();
2251 else
2252 throw datatransfer::UnsupportedFlavorException();
2255 return aAny;
2258 //________________________________________________________________________________________________________
2259 // XTransferable
2260 //________________________________________________________________________________________________________
2263 uno::Sequence< DATAFLAVOR > SAL_CALL SfxBaseModel::getTransferDataFlavors()
2264 throw (::com::sun::star::uno::RuntimeException)
2266 SfxModelGuard aGuard( *this );
2268 sal_Int32 nSuppFlavors = GraphicHelper::supportsMetaFileHandle_Impl() ? 10 : 8;
2269 uno::Sequence< DATAFLAVOR > aFlavorSeq( nSuppFlavors );
2271 aFlavorSeq[0].MimeType =
2272 ::rtl::OUString( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" );
2273 aFlavorSeq[0].HumanPresentableName = ::rtl::OUString( "GDIMetaFile" );
2274 aFlavorSeq[0].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2276 aFlavorSeq[1].MimeType =
2277 ::rtl::OUString( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" );
2278 aFlavorSeq[1].HumanPresentableName = ::rtl::OUString( "GDIMetaFile" );
2279 aFlavorSeq[1].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2281 aFlavorSeq[2].MimeType =
2282 ::rtl::OUString( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" );
2283 aFlavorSeq[2].HumanPresentableName = ::rtl::OUString( "Enhanced Windows MetaFile" );
2284 aFlavorSeq[2].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2286 aFlavorSeq[3].MimeType =
2287 ::rtl::OUString( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" );
2288 aFlavorSeq[3].HumanPresentableName = ::rtl::OUString( "Windows MetaFile" );
2289 aFlavorSeq[3].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2291 aFlavorSeq[4].MimeType =
2292 ::rtl::OUString( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" );
2293 aFlavorSeq[4].HumanPresentableName = ::rtl::OUString( "Star Object Descriptor (XML)" );
2294 aFlavorSeq[4].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2296 aFlavorSeq[5].MimeType =
2297 ::rtl::OUString( "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"" );
2298 aFlavorSeq[5].HumanPresentableName = ::rtl::OUString( "Star Embed Source (XML)" );
2299 aFlavorSeq[5].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2301 aFlavorSeq[6].MimeType =
2302 ::rtl::OUString( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" );
2303 aFlavorSeq[6].HumanPresentableName = ::rtl::OUString( "Bitmap" );
2304 aFlavorSeq[6].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2306 aFlavorSeq[7].MimeType =
2307 ::rtl::OUString( "image/png" );
2308 aFlavorSeq[7].HumanPresentableName = ::rtl::OUString( "PNG" );
2309 aFlavorSeq[7].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2311 if ( nSuppFlavors == 10 )
2313 aFlavorSeq[8].MimeType =
2314 ::rtl::OUString( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" );
2315 aFlavorSeq[8].HumanPresentableName = ::rtl::OUString( "Enhanced Windows MetaFile" );
2316 aFlavorSeq[8].DataType = getCppuType( (const sal_uInt64*) 0 );
2318 aFlavorSeq[9].MimeType =
2319 ::rtl::OUString( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" );
2320 aFlavorSeq[9].HumanPresentableName = ::rtl::OUString( "Windows MetaFile" );
2321 aFlavorSeq[9].DataType = getCppuType( (const sal_uInt64*) 0 );
2324 return aFlavorSeq;
2327 //________________________________________________________________________________________________________
2328 // XTransferable
2329 //________________________________________________________________________________________________________
2332 sal_Bool SAL_CALL SfxBaseModel::isDataFlavorSupported( const DATAFLAVOR& aFlavor )
2333 throw (::com::sun::star::uno::RuntimeException)
2335 SfxModelGuard aGuard( *this );
2337 if ( aFlavor.MimeType == "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" )
2339 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2340 return sal_True;
2342 else if ( aFlavor.MimeType == "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" )
2344 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2345 return sal_True;
2347 else if ( aFlavor.MimeType == "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" )
2349 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2350 return sal_True;
2351 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2352 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2353 return sal_True;
2355 else if ( aFlavor.MimeType == "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" )
2357 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2358 return sal_True;
2359 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2360 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2361 return sal_True;
2363 else if ( aFlavor.MimeType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"")) )
2365 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2366 return sal_True;
2368 else if ( aFlavor.MimeType == "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" )
2370 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2371 return sal_True;
2373 else if ( aFlavor.MimeType == "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" )
2375 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2376 return sal_True;
2378 else if ( aFlavor.MimeType == "image/png" )
2380 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2381 return sal_True;
2384 return sal_False;
2388 //--------------------------------------------------------------------------------------------------------
2389 // XEventsSupplier
2390 //--------------------------------------------------------------------------------------------------------
2392 uno::Reference< container::XNameReplace > SAL_CALL SfxBaseModel::getEvents() throw( uno::RuntimeException )
2394 SfxModelGuard aGuard( *this );
2396 if ( ! m_pData->m_xEvents.is() )
2398 m_pData->m_xEvents = new SfxEvents_Impl( m_pData->m_pObjectShell, this );
2401 return m_pData->m_xEvents;
2404 //--------------------------------------------------------------------------------------------------------
2405 // XEmbeddedScripts
2406 //--------------------------------------------------------------------------------------------------------
2408 uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getBasicLibraries() throw (RuntimeException)
2410 SfxModelGuard aGuard( *this );
2412 uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries;
2413 if ( m_pData->m_pObjectShell )
2414 xBasicLibraries.set( m_pData->m_pObjectShell->GetBasicContainer(), UNO_QUERY_THROW );
2415 return xBasicLibraries;
2418 uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getDialogLibraries() throw (RuntimeException)
2420 SfxModelGuard aGuard( *this );
2422 uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries;
2423 if ( m_pData->m_pObjectShell )
2424 xDialogLibraries.set( m_pData->m_pObjectShell->GetDialogContainer(), UNO_QUERY_THROW );
2425 return xDialogLibraries;
2428 ::sal_Bool SAL_CALL SfxBaseModel::getAllowMacroExecution() throw (RuntimeException)
2430 SfxModelGuard aGuard( *this );
2432 if ( m_pData->m_pObjectShell )
2433 return m_pData->m_pObjectShell->AdjustMacroMode( String(), false );
2434 return sal_False;
2437 //--------------------------------------------------------------------------------------------------------
2438 // XScriptInvocationContext
2439 //--------------------------------------------------------------------------------------------------------
2441 Reference< document::XEmbeddedScripts > SAL_CALL SfxBaseModel::getScriptContainer() throw (RuntimeException)
2443 SfxModelGuard aGuard( *this );
2445 Reference< document::XEmbeddedScripts > xDocumentScripts;
2449 Reference< frame::XModel > xDocument( this );
2450 xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2451 while ( !xDocumentScripts.is() && xDocument.is() )
2453 Reference< container::XChild > xDocAsChild( xDocument, uno::UNO_QUERY );
2454 if ( !xDocAsChild.is() )
2456 xDocument = NULL;
2457 break;
2460 xDocument.set( xDocAsChild->getParent(), uno::UNO_QUERY );
2461 xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2464 catch( const Exception& )
2466 DBG_UNHANDLED_EXCEPTION();
2467 xDocumentScripts = NULL;
2470 return xDocumentScripts;
2473 //--------------------------------------------------------------------------------------------------------
2474 // XEventBroadcaster
2475 //--------------------------------------------------------------------------------------------------------
2477 void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2479 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2481 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2484 //--------------------------------------------------------------------------------------------------------
2485 // XEventBroadcaster
2486 //--------------------------------------------------------------------------------------------------------
2488 void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2490 SfxModelGuard aGuard( *this );
2492 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2495 //--------------------------------------------------------------------------------------------------------
2496 // XDocumentEventBroadcaster
2497 //--------------------------------------------------------------------------------------------------------
2498 // ---------------------------------
2499 void SAL_CALL SfxBaseModel::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2500 throw ( uno::RuntimeException )
2502 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2503 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2506 // ---------------------------------
2507 void SAL_CALL SfxBaseModel::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2508 throw ( uno::RuntimeException )
2510 SfxModelGuard aGuard( *this );
2511 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2514 // ---------------------------------
2515 void SAL_CALL SfxBaseModel::notifyDocumentEvent( const ::rtl::OUString&, const uno::Reference< frame::XController2 >&, const uno::Any& )
2516 throw ( lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException )
2518 throw lang::NoSupportException( ::rtl::OUString( "SfxBaseModel controlls all the sent notifications itself!" ), uno::Reference< uno::XInterface >() );
2521 //________________________________________________________________________________________________________
2522 // SfxListener
2523 //________________________________________________________________________________________________________
2525 void addTitle_Impl( Sequence < ::com::sun::star::beans::PropertyValue >& rSeq, const ::rtl::OUString& rTitle )
2527 sal_Int32 nCount = rSeq.getLength();
2528 sal_Int32 nArg;
2530 for ( nArg = 0; nArg < nCount; nArg++ )
2532 ::com::sun::star::beans::PropertyValue& rProp = rSeq[nArg];
2533 if ( rProp.Name == "Title" )
2535 rProp.Value <<= rTitle;
2536 break;
2540 if ( nArg == nCount )
2542 rSeq.realloc( nCount+1 );
2543 rSeq[nCount].Name = ::rtl::OUString( "Title" );
2544 rSeq[nCount].Value <<= rTitle;
2548 void SfxBaseModel::Notify( SfxBroadcaster& rBC ,
2549 const SfxHint& rHint )
2551 if ( !m_pData )
2552 return;
2554 if ( &rBC == m_pData->m_pObjectShell )
2556 SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
2557 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DOCCHANGED )
2558 changing();
2560 SfxEventHint* pNamedHint = PTR_CAST( SfxEventHint, &rHint );
2561 if ( pNamedHint )
2564 switch ( pNamedHint->GetEventId() )
2566 case SFX_EVENT_STORAGECHANGED:
2568 if ( m_pData->m_xUIConfigurationManager.is()
2569 && m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
2571 uno::Reference< XSTORAGE > xConfigStorage;
2572 rtl::OUString aUIConfigFolderName( "Configurations2" );
2574 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READWRITE );
2575 if ( !xConfigStorage.is() )
2576 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READ );
2578 if ( xConfigStorage.is() || !m_pData->m_pObjectShell->GetStorage()->hasByName( aUIConfigFolderName ) )
2580 // the storage is different, since otherwise it could not be opened, so it must be exchanged
2581 Reference< ui::XUIConfigurationStorage > xUIConfigStorage( m_pData->m_xUIConfigurationManager, uno::UNO_QUERY );
2582 xUIConfigStorage->setStorage( xConfigStorage );
2584 else
2586 OSL_FAIL( "Unexpected scenario!\n" );
2590 ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2592 break;
2594 case SFX_EVENT_LOADFINISHED:
2596 impl_getPrintHelper();
2597 ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2598 m_pData->m_bModifiedSinceLastSave = sal_False;
2600 break;
2602 case SFX_EVENT_SAVEASDOCDONE:
2604 m_pData->m_sURL = m_pData->m_pObjectShell->GetMedium()->GetName();
2606 SfxItemSet *pSet = m_pData->m_pObjectShell->GetMedium()->GetItemSet();
2607 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
2608 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2609 TransformItems( SID_SAVEASDOC, *pSet, aArgs );
2610 addTitle_Impl( aArgs, aTitle );
2611 attachResource( m_pData->m_pObjectShell->GetMedium()->GetName(), aArgs );
2613 break;
2615 case SFX_EVENT_DOCCREATED:
2617 impl_getPrintHelper();
2618 m_pData->m_bModifiedSinceLastSave = sal_False;
2620 break;
2622 case SFX_EVENT_MODIFYCHANGED:
2624 m_pData->m_bModifiedSinceLastSave = isModified();
2626 break;
2630 SfxViewEventHint* pViewHint = PTR_CAST( SfxViewEventHint, &rHint );
2631 postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? pViewHint->GetController() : uno::Reference< frame::XController2 >() );
2634 if ( pSimpleHint )
2636 if ( pSimpleHint->GetId() == SFX_HINT_TITLECHANGED )
2638 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2639 addTitle_Impl( m_pData->m_seqArguments, aTitle );
2640 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_TITLECHANGED ) );
2642 if ( pSimpleHint->GetId() == SFX_HINT_MODECHANGED )
2644 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_MODECHANGED ) );
2650 //________________________________________________________________________________________________________
2651 // public impl.
2652 //________________________________________________________________________________________________________
2654 void SfxBaseModel::NotifyModifyListeners_Impl() const
2656 ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0) );
2657 if ( pIC )
2659 lang::EventObject aEvent( (frame::XModel *)this );
2660 pIC->notifyEach( &util::XModifyListener::modified, aEvent );
2663 // this notification here is done too generously, we cannot simply assume that we're really modified
2664 // now, but we need to check it ...
2665 m_pData->m_bModifiedSinceLastSave = const_cast< SfxBaseModel* >( this )->isModified();
2668 void SfxBaseModel::changing()
2670 SfxModelGuard aGuard( *this );
2672 // the notification should not be sent if the document can not be modified
2673 if ( !m_pData->m_pObjectShell.Is() || !m_pData->m_pObjectShell->IsEnableSetModified() )
2674 return;
2676 NotifyModifyListeners_Impl();
2679 //________________________________________________________________________________________________________
2680 // public impl.
2681 //________________________________________________________________________________________________________
2683 SfxObjectShell* SfxBaseModel::GetObjectShell() const
2685 return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2688 //________________________________________________________________________________________________________
2689 // public impl.
2690 //________________________________________________________________________________________________________
2692 sal_Bool SfxBaseModel::IsInitialized() const
2694 if ( !m_pData || !m_pData->m_pObjectShell )
2696 OSL_FAIL( "SfxBaseModel::IsInitialized: this should have been caught earlier!" );
2697 return sal_False;
2700 return m_pData->m_pObjectShell->GetMedium() != NULL;
2703 void SfxBaseModel::MethodEntryCheck( const bool i_mustBeInitialized ) const
2705 if ( impl_isDisposed() )
2706 throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2707 if ( i_mustBeInitialized && !IsInitialized() )
2708 throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2711 sal_Bool SfxBaseModel::impl_isDisposed() const
2713 return ( m_pData == NULL ) ;
2716 //________________________________________________________________________________________________________
2717 // private impl.
2718 //________________________________________________________________________________________________________
2720 ::rtl::OUString SfxBaseModel::GetMediumFilterName_Impl()
2722 const SfxFilter* pFilter = NULL;
2723 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2724 if ( pMedium )
2725 pFilter = pMedium->GetFilter();
2727 if ( pFilter )
2728 return pFilter->GetName();
2730 return ::rtl::OUString();
2733 void SfxBaseModel::impl_store( const ::rtl::OUString& sURL ,
2734 const uno::Sequence< beans::PropertyValue >& seqArguments ,
2735 sal_Bool bSaveTo )
2737 if( sURL.isEmpty() )
2738 throw frame::IllegalArgumentIOException();
2740 sal_Bool bSaved = sal_False;
2741 if ( !bSaveTo && m_pData->m_pObjectShell && !sURL.isEmpty()
2742 && sURL.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL
2743 && ::utl::UCBContentHelper::EqualURLs( getLocation(), sURL ) )
2745 // this is the same file URL as the current document location, try to use storeOwn if possible
2747 ::comphelper::SequenceAsHashMap aArgHash( seqArguments );
2748 ::rtl::OUString aFilterString( "FilterName" );
2749 ::rtl::OUString aFilterName = aArgHash.getUnpackedValueOrDefault( aFilterString, ::rtl::OUString() );
2750 if ( !aFilterName.isEmpty() )
2752 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2753 if ( pMedium )
2755 const SfxFilter* pFilter = pMedium->GetFilter();
2756 if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) )
2758 aArgHash.erase( aFilterString );
2759 aArgHash.erase( ::rtl::OUString( "URL" ) );
2763 storeSelf( aArgHash.getAsConstPropertyValueList() );
2764 bSaved = sal_True;
2766 catch( const lang::IllegalArgumentException& )
2768 // some additional arguments do not allow to use saving, SaveAs should be done
2769 // but only for normal documents, the shared documents would be overwritten in this case
2770 // that would mean an information loss
2771 // TODO/LATER: need a new interaction for this case
2772 if ( m_pData->m_pObjectShell->IsDocShared() )
2774 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Can't store shared document!" ) );
2775 m_pData->m_pObjectShell->StoreLog();
2777 uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( "EncryptionData" ), uno::Sequence< beans::NamedValue >() );
2778 if ( !aNewEncryptionData.getLength() )
2780 ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( "Password" ), ::rtl::OUString() );
2781 aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword );
2784 uno::Sequence< beans::NamedValue > aOldEncryptionData;
2785 GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData );
2787 if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() )
2788 throw;
2789 else
2791 // if the password is changed a special error should be used in case of shared document
2792 throw task::ErrorCodeIOException( ::rtl::OUString( "Cant change password for shared document." ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE );
2801 if ( !bSaved && m_pData->m_pObjectShell )
2803 SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOC : STR_EVENT_SAVEASDOC ),
2804 m_pData->m_pObjectShell ) );
2806 SfxAllItemSet *aParams = new SfxAllItemSet( SFX_APP()->GetPool() );
2807 aParams->Put( SfxStringItem( SID_FILE_NAME, String(sURL) ) );
2808 if ( bSaveTo )
2809 aParams->Put( SfxBoolItem( SID_SAVETO, sal_True ) );
2811 TransformParameters( SID_SAVEASDOC, seqArguments, *aParams );
2813 SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
2815 if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo )
2817 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Misuse of CopyStreamIfPossible!" ) );
2818 m_pData->m_pObjectShell->StoreLog();
2820 throw frame::IllegalArgumentIOException(
2821 ::rtl::OUString( "CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!"),
2822 uno::Reference< uno::XInterface >() );
2825 sal_uInt32 nModifyPasswordHash = 0;
2826 uno::Sequence< beans::PropertyValue > aModifyPasswordInfo;
2827 SFX_ITEMSET_ARG( aParams, pModifyPasswordInfoItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
2828 if ( pModifyPasswordInfoItem )
2830 // it contains either a simple hash or a set of PropertyValues
2831 // TODO/LATER: the sequence of PropertyValue should replace the hash completely in future
2832 sal_Int32 nMPHTmp = 0;
2833 pModifyPasswordInfoItem->GetValue() >>= nMPHTmp;
2834 nModifyPasswordHash = (sal_uInt32)nMPHTmp;
2835 pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo;
2837 aParams->ClearItem( SID_MODIFYPASSWORDINFO );
2838 sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash();
2839 m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash );
2840 uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo();
2841 m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo );
2843 // since saving a document modifies its DocumentInfo, the current
2844 // DocumentInfo must be saved on "SaveTo", so it can be restored
2845 // after saving
2846 sal_Bool bCopyTo = bSaveTo ||
2847 m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
2848 uno::Reference<document::XDocumentProperties> xOldDocProps;
2849 uno::Reference<document::XDocumentInfo> xOldDocInfo;
2850 if ( bCopyTo )
2852 xOldDocProps = getDocumentProperties();
2853 if (m_pData->m_xDocumentInfo.is())
2855 xOldDocInfo = getDocumentInfo();
2856 const Reference<util::XCloneable> xCloneable(xOldDocInfo,
2857 UNO_QUERY_THROW);
2858 const Reference<document::XDocumentInfo> xNewDocInfo(
2859 xCloneable->createClone(), UNO_QUERY_THROW);
2860 const Reference<document::XDocumentPropertiesSupplier> xDPS(
2861 xNewDocInfo, UNO_QUERY_THROW);
2862 const Reference<document::XDocumentProperties> xNewDocProps(
2863 xDPS->getDocumentProperties());
2864 m_pData->m_xDocumentProperties = xNewDocProps;
2865 m_pData->m_xDocumentInfo = xNewDocInfo;
2867 else // try not to create DocumentInfo if it does not exist...
2869 const Reference<util::XCloneable> xCloneable(xOldDocProps,
2870 UNO_QUERY_THROW);
2871 const Reference<document::XDocumentProperties> xNewDocProps(
2872 xCloneable->createClone(), UNO_QUERY_THROW);
2873 m_pData->m_xDocumentProperties = xNewDocProps;
2877 sal_Bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams );
2879 if ( bCopyTo )
2881 // restore DocumentInfo if a copy was created
2882 m_pData->m_xDocumentProperties = xOldDocProps;
2883 m_pData->m_xDocumentInfo = xOldDocInfo;
2886 uno::Reference < task::XInteractionHandler > xHandler;
2887 SFX_ITEMSET_ARG( aParams, pItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
2888 if ( pItem )
2889 pItem->GetValue() >>= xHandler;
2891 DELETEZ( aParams );
2893 sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetErrorCode();
2894 if ( !bRet && !nErrCode )
2896 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Storing has failed, no error is set!" ) );
2897 nErrCode = ERRCODE_IO_CANTWRITE;
2899 m_pData->m_pObjectShell->ResetError();
2901 if ( bRet )
2903 if ( nErrCode )
2905 // must be a warning - use Interactionhandler if possible or abandone
2906 if ( xHandler.is() )
2908 // TODO/LATER: a general way to set the error context should be available
2909 SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, m_pData->m_pObjectShell->GetTitle() );
2911 ::com::sun::star::task::ErrorCodeRequest aErrorCode;
2912 aErrorCode.ErrCode = nErrCode;
2913 SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
2917 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Storing succeeded!" ) );
2918 if ( !bSaveTo )
2920 m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
2921 m_pData->m_pObjectShell->SetModifyPasswordEntered();
2923 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) );
2925 else
2927 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
2928 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
2930 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) );
2933 else
2935 // let the logring be stored to the related file
2936 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Storing failed!" ) );
2937 m_pData->m_pObjectShell->StoreLog();
2939 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
2940 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
2943 SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED),
2944 m_pData->m_pObjectShell ) );
2946 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
2951 //********************************************************************************************************
2952 namespace {
2953 template< typename ListenerT, typename EventT >
2954 class NotifySingleListenerIgnoreRE
2956 private:
2957 typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& );
2958 NotificationMethod m_pMethod;
2959 const EventT& m_rEvent;
2960 public:
2961 NotifySingleListenerIgnoreRE( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
2963 void operator()( const uno::Reference<ListenerT>& listener ) const
2967 (listener.get()->*m_pMethod)( m_rEvent );
2969 catch( uno::RuntimeException& )
2971 // this exception is ignored to avoid problems with invalid listeners, the listener should be probably thrown away in future
2975 } // anonymous namespace
2977 void SfxBaseModel::postEvent_Impl( const ::rtl::OUString& aName, const uno::Reference< frame::XController2 >& xController )
2979 // object already disposed?
2980 if ( impl_isDisposed() )
2981 return;
2983 DBG_ASSERT( !aName.isEmpty(), "Empty event name!" );
2984 if (aName.isEmpty())
2985 return;
2987 ::cppu::OInterfaceContainerHelper* pIC =
2988 m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XDocumentEventListener >*)0 ) );
2989 if ( pIC )
2991 SAL_INFO("sfx2", "SfxDocumentEvent: " + aName);
2993 document::DocumentEvent aDocumentEvent( (frame::XModel*)this, aName, xController, uno::Any() );
2995 pIC->forEach< document::XDocumentEventListener, NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent > >(
2996 NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent >(
2997 &document::XDocumentEventListener::documentEventOccured,
2998 aDocumentEvent ) );
3001 pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ) );
3002 if ( pIC )
3004 SAL_INFO("sfx2", "SfxEvent: " + aName);
3006 document::EventObject aEvent( (frame::XModel*)this, aName );
3008 pIC->forEach< document::XEventListener, NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject > >(
3009 NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject >(
3010 &document::XEventListener::notifyEvent,
3011 aEvent ) );
3016 uno::Reference < container::XIndexAccess > SAL_CALL SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException)
3018 SfxModelGuard aGuard( *this );
3020 if ( m_pData->m_pObjectShell.Is() && !m_pData->m_contViewData.is() )
3022 SfxViewFrame *pActFrame = SfxViewFrame::Current();
3023 if ( !pActFrame || pActFrame->GetObjectShell() != m_pData->m_pObjectShell )
3024 pActFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
3026 if ( !pActFrame || !pActFrame->GetViewShell() )
3027 // currently no frame for this document at all or View is under construction
3028 return uno::Reference < container::XIndexAccess >();
3030 m_pData->m_contViewData = Reference < container::XIndexAccess >(
3031 ::comphelper::getProcessServiceFactory()->createInstance(
3032 DEFINE_CONST_UNICODE("com.sun.star.document.IndexedPropertyValues") ),
3033 uno::UNO_QUERY );
3035 if ( !m_pData->m_contViewData.is() )
3037 // error: no container class available!
3038 return uno::Reference < container::XIndexAccess >();
3041 uno::Reference < container::XIndexContainer > xCont( m_pData->m_contViewData, uno::UNO_QUERY );
3042 sal_Int32 nCount = 0;
3043 uno::Sequence < beans::PropertyValue > aSeq;
3044 ::com::sun::star::uno::Any aAny;
3045 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); pFrame;
3046 pFrame = SfxViewFrame::GetNext( *pFrame, m_pData->m_pObjectShell ) )
3048 sal_Bool bIsActive = ( pFrame == pActFrame );
3049 pFrame->GetViewShell()->WriteUserDataSequence( aSeq );
3050 aAny <<= aSeq;
3051 xCont->insertByIndex( bIsActive ? 0 : nCount, aAny );
3052 nCount++;
3056 return m_pData->m_contViewData;
3059 void SAL_CALL SfxBaseModel::setViewData( const uno::Reference < container::XIndexAccess >& aData ) throw(::com::sun::star::uno::RuntimeException)
3061 SfxModelGuard aGuard( *this );
3063 m_pData->m_contViewData = aData;
3066 /** calls all XEventListeners */
3067 void SfxBaseModel::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) const
3069 // object already disposed?
3070 if ( impl_isDisposed() )
3071 return;
3073 ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer(
3074 ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) );
3075 if( pIC )
3078 ::cppu::OInterfaceIteratorHelper aIt( *pIC );
3079 while( aIt.hasMoreElements() )
3083 ((XDOCEVENTLISTENER *)aIt.next())->notifyEvent( aEvent );
3085 catch( uno::RuntimeException& )
3087 aIt.remove();
3093 /** returns true if someone added a XEventListener to this XEventBroadcaster */
3094 sal_Bool SfxBaseModel::hasEventListeners() const
3096 return !impl_isDisposed() && (NULL != m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ) );
3099 void SAL_CALL SfxBaseModel::addPrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3101 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3103 if ( impl_getPrintHelper() )
3105 uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3106 if ( xPJB.is() )
3107 xPJB->addPrintJobListener( xListener );
3111 void SAL_CALL SfxBaseModel::removePrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3113 SfxModelGuard aGuard( *this );
3115 if ( impl_getPrintHelper() )
3117 uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3118 if ( xPJB.is() )
3119 xPJB->removePrintJobListener( xListener );
3123 // simple declaration of class SvObject is enough
3124 // the corresponding <so3/iface.hxx> cannon be included because it provides
3125 // declaration of class SvBorder that conflicts with ../../inc/viewfrm.hxx
3126 class SvObject;
3127 sal_Int64 SAL_CALL SfxBaseModel::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
3129 SvGlobalName aName( aIdentifier );
3130 if ((aName == SvGlobalName( SO3_GLOBAL_CLASSID )) ||
3131 (aName == SvGlobalName( SFX_GLOBAL_CLASSID )))
3133 SolarMutexGuard aGuard;
3134 SfxObjectShell *const pObjectShell(GetObjectShell());
3135 if (pObjectShell)
3137 // SO3_GLOBAL_CLASSID is apparently used by binfilter :(
3138 if ( aName == SvGlobalName( SO3_GLOBAL_CLASSID ) )
3139 return (sal_Int64)(sal_IntPtr)(SvObject*) pObjectShell;
3140 else if ( aName == SvGlobalName( SFX_GLOBAL_CLASSID ) )
3141 return (sal_Int64)(sal_IntPtr)(SfxObjectShell*) pObjectShell;
3145 return 0;
3148 //____________________________________________________________________________________________________
3149 // XDocumentSubStorageSupplier
3150 //____________________________________________________________________________________________________
3152 void SfxBaseModel::ListenForStorage_Impl( const uno::Reference< embed::XStorage >& xStorage )
3154 uno::Reference< util::XModifiable > xModifiable( xStorage, uno::UNO_QUERY );
3155 if ( xModifiable.is() )
3157 if ( !m_pData->m_pStorageModifyListen.is() )
3159 m_pData->m_pStorageModifyListen = new ::sfx2::DocumentStorageModifyListener( *m_pData, Application::GetSolarMutex() );
3162 // no need to deregister the listening for old storage since it should be disposed automatically
3163 xModifiable->addModifyListener( m_pData->m_pStorageModifyListen.get() );
3167 uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode )
3168 throw ( uno::RuntimeException)
3170 SfxModelGuard aGuard( *this );
3172 uno::Reference< XSTORAGE > xResult;
3173 if ( m_pData->m_pObjectShell.Is() )
3175 uno::Reference< embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3176 if ( xStorage.is() )
3180 xResult = xStorage->openStorageElement( aStorageName, nMode );
3182 catch ( uno::Exception& )
3188 return xResult;
3191 Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getDocumentSubStoragesNames()
3192 throw ( io::IOException,
3193 RuntimeException )
3195 SfxModelGuard aGuard( *this );
3197 Sequence< ::rtl::OUString > aResult;
3198 sal_Bool bSuccess = sal_False;
3199 if ( m_pData->m_pObjectShell.Is() )
3201 uno::Reference < embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3202 uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
3203 if ( xAccess.is() )
3205 Sequence< ::rtl::OUString > aTemp = xAccess->getElementNames();
3206 sal_Int32 nResultSize = 0;
3207 for ( sal_Int32 n = 0; n < aTemp.getLength(); n++ )
3209 if ( xStorage->isStorageElement( aTemp[n] ) )
3211 aResult.realloc( ++nResultSize );
3212 aResult[ nResultSize - 1 ] = aTemp[n];
3216 bSuccess = sal_True;
3220 if ( !bSuccess )
3221 throw io::IOException();
3223 return aResult;
3226 //____________________________________________________________________________________________________
3227 // XScriptProviderSupplier
3228 //____________________________________________________________________________________________________
3231 uno::Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getScriptProvider()
3232 throw ( uno::RuntimeException )
3234 SfxModelGuard aGuard( *this );
3236 uno::Reference< script::provider::XScriptProvider > xScriptProvider;
3238 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
3239 Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory(
3240 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW );
3244 Reference< XScriptInvocationContext > xScriptContext( this );
3245 xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), uno::UNO_SET_THROW );
3247 catch( const uno::RuntimeException& )
3249 throw;
3251 catch( const lang::IllegalArgumentException& )
3253 throw lang::WrappedTargetRuntimeException(
3254 ::rtl::OUString(),
3255 *this,
3256 ::cppu::getCaughtException()
3260 return xScriptProvider;
3263 //____________________________________________________________________________________________________
3264 // XUIConfigurationManagerSupplier
3265 //____________________________________________________________________________________________________
3267 rtl::OUString SfxBaseModel::getRuntimeUID() const
3269 OSL_ENSURE( !m_pData->m_sRuntimeUID.isEmpty(),
3270 "SfxBaseModel::getRuntimeUID - ID is empty!" );
3271 return m_pData->m_sRuntimeUID;
3274 sal_Bool SfxBaseModel::hasValidSignatures() const
3276 SolarMutexGuard aGuard;
3277 if ( m_pData->m_pObjectShell.Is() )
3278 return ( m_pData->m_pObjectShell->ImplGetSignatureState( sal_False ) == SIGNATURESTATE_SIGNATURES_OK );
3279 return sal_False;
3282 static void GetCommandFromSequence( rtl::OUString& rCommand, sal_Int32& nIndex, const uno::Sequence< beans::PropertyValue >& rSeqPropValue )
3284 rtl::OUString aCommand;
3285 nIndex = -1;
3287 for ( sal_Int32 i = 0; i < rSeqPropValue.getLength(); i++ )
3289 if ( rSeqPropValue[i].Name == "Command" )
3291 rSeqPropValue[i].Value >>= rCommand;
3292 nIndex = i;
3293 return;
3298 static void ConvertSlotsToCommands( SfxObjectShell* pDoc, uno::Reference< container::XIndexContainer >& rToolbarDefinition )
3300 if ( pDoc )
3302 Any aAny;
3303 SfxModule* pModule( pDoc->GetFactory().GetModule() );
3304 rtl::OUString aSlotCmd( "slot:" );
3305 rtl::OUString aUnoCmd( ".uno:" );
3306 uno::Sequence< beans::PropertyValue > aSeqPropValue;
3308 for ( sal_Int32 i = 0; i < rToolbarDefinition->getCount(); i++ )
3310 sal_Int32 nIndex( -1 );
3311 rtl::OUString aCommand;
3313 if ( rToolbarDefinition->getByIndex( i ) >>= aSeqPropValue )
3315 GetCommandFromSequence( aCommand, nIndex, aSeqPropValue );
3316 if ( nIndex >= 0 && ( aCommand.indexOf( aSlotCmd ) == 0 ))
3318 rtl::OUString aSlot( aCommand.copy( 5 ));
3320 // We have to replace the old "slot-Command" with our new ".uno:-Command"
3321 const SfxSlot* pSlot = pModule->GetSlotPool()->GetSlot( sal_uInt16( aSlot.toInt32() ));
3322 if ( pSlot )
3324 rtl::OUStringBuffer aStrBuf( aUnoCmd );
3325 aStrBuf.appendAscii( pSlot->GetUnoName() );
3327 aCommand = aStrBuf.makeStringAndClear();
3328 aSeqPropValue[nIndex].Value <<= aCommand;
3329 rToolbarDefinition->replaceByIndex( i, Any( aSeqPropValue ));
3337 uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfigurationManager()
3338 throw ( uno::RuntimeException )
3340 SfxModelGuard aGuard( *this );
3342 if ( !m_pData->m_xUIConfigurationManager.is() )
3344 uno::Reference< ui::XUIConfigurationManager > xNewUIConfMan(
3345 ::comphelper::getProcessServiceFactory()->createInstance(
3346 ::rtl::OUString("com.sun.star.ui.UIConfigurationManager")),
3347 uno::UNO_QUERY );
3349 Reference< ui::XUIConfigurationStorage > xUIConfigStorage( xNewUIConfMan, uno::UNO_QUERY );
3350 if ( xUIConfigStorage.is() )
3352 uno::Reference< XSTORAGE > xConfigStorage;
3354 rtl::OUString aUIConfigFolderName( "Configurations2" );
3355 // First try to open with READWRITE and then READ
3356 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE );
3357 if ( xConfigStorage.is() )
3359 rtl::OUString aMediaTypeProp( "MediaType" );
3360 rtl::OUString aUIConfigMediaType(
3361 "application/vnd.sun.xml.ui.configuration" );
3362 rtl::OUString aMediaType;
3363 uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY );
3364 Any a = xPropSet->getPropertyValue( aMediaTypeProp );
3365 if ( !( a >>= aMediaType ) || aMediaType.isEmpty())
3367 a <<= aUIConfigMediaType;
3368 xPropSet->setPropertyValue( aMediaTypeProp, a );
3371 else
3372 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ );
3374 // initialize ui configuration manager with document substorage
3375 xUIConfigStorage->setStorage( xConfigStorage );
3377 // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to
3378 // migrate
3379 if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
3381 // Import old UI configuration from OOo 1.x
3382 uno::Reference< XSTORAGE > xOOo1ConfigStorage;
3383 rtl::OUString aOOo1UIConfigFolderName( "Configurations" );
3385 // Try to open with READ
3386 xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ );
3387 if ( xOOo1ConfigStorage.is() )
3389 uno::Reference< lang::XMultiServiceFactory > xServiceMgr( ::comphelper::getProcessServiceFactory() );
3390 uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars;
3392 sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars(
3393 xNewUIConfMan, rToolbars, xServiceMgr, xOOo1ConfigStorage );
3394 if ( bImported )
3396 SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell();
3398 rtl::OUString aNum( "private:resource/toolbar/custom_OOo1x_" );
3399 rtl::OUString aTitle( "Toolbar " );
3400 for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ )
3402 rtl::OUString aCustomTbxName = aNum + rtl::OUString::valueOf( i + 1 );
3403 rtl::OUString aCustomTbxTitle = aTitle + rtl::OUString::valueOf( i + 1 );
3405 uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i];
3406 ConvertSlotsToCommands( pObjShell, xToolbar );
3407 if ( !xNewUIConfMan->hasSettings( aCustomTbxName ))
3409 // Set UIName for the toolbar with container property
3410 uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY );
3411 if ( xPropSet.is() )
3415 rtl::OUString aPropName( "UIName" );
3416 Any aAny( aCustomTbxTitle );
3417 xPropSet->setPropertyValue( aPropName, aAny );
3419 catch ( beans::UnknownPropertyException& )
3424 uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY );
3425 xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData );
3426 uno::Reference< ui::XUIConfigurationPersistence > xPersist( xNewUIConfMan, uno::UNO_QUERY );
3427 xPersist->store();
3435 m_pData->m_xUIConfigurationManager = xNewUIConfMan;
3438 return m_pData->m_xUIConfigurationManager;
3441 //____________________________________________________________________________________________________
3442 // XVisualObject
3443 //____________________________________________________________________________________________________
3445 void SAL_CALL SfxBaseModel::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
3446 throw ( lang::IllegalArgumentException,
3447 embed::WrongStateException,
3448 uno::Exception,
3449 uno::RuntimeException )
3451 SfxModelGuard aGuard( *this );
3453 if ( !m_pData->m_pObjectShell.Is() )
3454 throw uno::Exception(); // TODO: error handling
3456 SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False );
3457 if ( pViewFrm && m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !pViewFrm->GetFrame().IsInPlace() )
3459 Window* pWindow = VCLUnoHelper::GetWindow( pViewFrm->GetFrame().GetFrameInterface()->getContainerWindow() );
3460 Size aWinSize = pWindow->GetSizePixel();
3461 awt::Size aCurrent = getVisualAreaSize( nAspect );
3462 Size aDiff( aSize.Width-aCurrent.Width, aSize.Height-aCurrent.Height );
3463 aDiff = pViewFrm->GetViewShell()->GetWindow()->LogicToPixel( aDiff );
3464 aWinSize.Width() += aDiff.Width();
3465 aWinSize.Height() += aDiff.Height();
3466 pWindow->SetSizePixel( aWinSize );
3468 else
3470 Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3471 aTmpRect.SetSize( Size( aSize.Width, aSize.Height ) );
3472 m_pData->m_pObjectShell->SetVisArea( aTmpRect );
3476 awt::Size SAL_CALL SfxBaseModel::getVisualAreaSize( sal_Int64 /*nAspect*/ )
3477 throw ( lang::IllegalArgumentException,
3478 embed::WrongStateException,
3479 uno::Exception,
3480 uno::RuntimeException)
3482 SfxModelGuard aGuard( *this );
3484 if ( !m_pData->m_pObjectShell.Is() )
3485 throw uno::Exception(); // TODO: error handling
3487 Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3489 return awt::Size( aTmpRect.GetWidth(), aTmpRect.GetHeight() );
3493 sal_Int32 SAL_CALL SfxBaseModel::getMapUnit( sal_Int64 /*nAspect*/ )
3494 throw ( uno::Exception,
3495 uno::RuntimeException)
3497 SfxModelGuard aGuard( *this );
3499 if ( !m_pData->m_pObjectShell.Is() )
3500 throw uno::Exception(); // TODO: error handling
3502 return VCLUnoHelper::VCL2UnoEmbedMapUnit( m_pData->m_pObjectShell->GetMapUnit() );
3505 embed::VisualRepresentation SAL_CALL SfxBaseModel::getPreferredVisualRepresentation( ::sal_Int64 /*nAspect*/ )
3506 throw ( lang::IllegalArgumentException,
3507 embed::WrongStateException,
3508 uno::Exception,
3509 uno::RuntimeException )
3511 SfxModelGuard aGuard( *this );
3513 datatransfer::DataFlavor aDataFlavor(
3514 ::rtl::OUString("application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
3515 ::rtl::OUString("GDIMetaFile"),
3516 ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
3518 embed::VisualRepresentation aVisualRepresentation;
3519 aVisualRepresentation.Data = getTransferData( aDataFlavor );
3520 aVisualRepresentation.Flavor = aDataFlavor;
3522 return aVisualRepresentation;
3525 //____________________________________________________________________________________________________
3526 // XStorageBasedDocument
3527 //____________________________________________________________________________________________________
3529 void SAL_CALL SfxBaseModel::loadFromStorage( const uno::Reference< XSTORAGE >& xStorage,
3530 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3531 throw ( lang::IllegalArgumentException,
3532 DOUBLEINITIALIZATIONEXCEPTION,
3533 IOEXCEPTION,
3534 EXCEPTION,
3535 uno::RuntimeException )
3537 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3538 if ( IsInitialized() )
3539 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
3541 // after i36090 is fixed the pool from object shell can be used
3542 // SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3543 SfxAllItemSet aSet( SFX_APP()->GetPool() );
3545 // the BaseURL is part of the ItemSet
3546 SfxMedium* pMedium = new SfxMedium( xStorage, String() );
3547 TransformParameters( SID_OPENDOC, aMediaDescriptor, aSet );
3548 pMedium->GetItemSet()->Put( aSet );
3550 // allow to use an interactionhandler (if there is one)
3551 pMedium->UseInteractionHandler( sal_True );
3553 SFX_ITEMSET_ARG( &aSet, pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
3554 sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
3555 m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
3556 m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3558 // load document
3559 if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
3561 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3562 throw task::ErrorCodeIOException( ::rtl::OUString(),
3563 uno::Reference< uno::XInterface >(),
3564 nError ? nError : ERRCODE_IO_CANTREAD );
3568 void SAL_CALL SfxBaseModel::storeToStorage( const uno::Reference< XSTORAGE >& xStorage,
3569 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3570 throw ( lang::IllegalArgumentException,
3571 IOEXCEPTION,
3572 EXCEPTION,
3573 uno::RuntimeException )
3575 SfxModelGuard aGuard( *this );
3577 uno::Reference< XSTORAGE > xResult;
3578 if ( !m_pData->m_pObjectShell.Is() )
3579 throw IOEXCEPTION(); // TODO:
3581 SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3582 TransformParameters( SID_SAVEASDOC, aMediaDescriptor, aSet );
3584 // TODO/LATER: may be a special URL "private:storage" should be used
3585 SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
3586 sal_Int32 nVersion = SOFFICE_FILEFORMAT_CURRENT;
3587 if( pItem )
3589 String aFilterName = pItem->GetValue();
3590 const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName );
3591 if ( pFilter && pFilter->UsesStorage() )
3592 nVersion = pFilter->GetVersion();
3595 sal_Bool bSuccess = sal_False;
3596 if ( xStorage == m_pData->m_pObjectShell->GetStorage() )
3598 // storing to the own storage
3599 bSuccess = m_pData->m_pObjectShell->DoSave();
3601 else
3603 // TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated
3604 // TODO/LATER: is it possible to have a template here?
3605 m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False );
3607 // BaseURL is part of the ItemSet
3608 SfxMedium aMedium( xStorage, String(), &aSet );
3609 aMedium.CanDisposeStorage_Impl( sal_False );
3610 if ( aMedium.GetFilter() )
3612 // storing without a valid filter will often crash
3613 bSuccess = m_pData->m_pObjectShell->DoSaveObjectAs( aMedium, sal_True );
3614 m_pData->m_pObjectShell->DoSaveCompleted( NULL );
3618 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3619 m_pData->m_pObjectShell->ResetError();
3621 // the warnings are currently not transported
3622 if ( !bSuccess )
3624 throw task::ErrorCodeIOException( ::rtl::OUString(),
3625 uno::Reference< uno::XInterface >(),
3626 nError ? nError : ERRCODE_IO_GENERAL );
3630 void SAL_CALL SfxBaseModel::switchToStorage( const uno::Reference< XSTORAGE >& xStorage )
3631 throw ( lang::IllegalArgumentException,
3632 IOEXCEPTION,
3633 EXCEPTION,
3634 uno::RuntimeException )
3636 SfxModelGuard aGuard( *this );
3638 uno::Reference< XSTORAGE > xResult;
3639 if ( !m_pData->m_pObjectShell.Is() )
3640 throw IOEXCEPTION(); // TODO:
3642 // the persistence should be switched only if the storage is different
3643 if ( xStorage != m_pData->m_pObjectShell->GetStorage() )
3645 if ( !m_pData->m_pObjectShell->SwitchPersistance( xStorage ) )
3647 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3648 throw task::ErrorCodeIOException( ::rtl::OUString(),
3649 uno::Reference< uno::XInterface >(),
3650 nError ? nError : ERRCODE_IO_GENERAL );
3652 else
3654 // UICfgMgr has a reference to the old storage, update it
3655 uno::Reference< ui::XUIConfigurationStorage > xUICfgMgrStorage( getUIConfigurationManager(), uno::UNO_QUERY );
3656 if ( xUICfgMgrStorage.is() )
3657 xUICfgMgrStorage->setStorage( xStorage );
3660 m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3663 uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentStorage()
3664 throw ( IOEXCEPTION,
3665 EXCEPTION,
3666 uno::RuntimeException )
3668 SfxModelGuard aGuard( *this );
3670 uno::Reference< XSTORAGE > xResult;
3671 if ( !m_pData->m_pObjectShell.Is() )
3672 throw IOEXCEPTION(); // TODO
3674 return m_pData->m_pObjectShell->GetStorage();
3677 void SAL_CALL SfxBaseModel::addStorageChangeListener(
3678 const uno::Reference< document::XStorageChangeListener >& xListener )
3679 throw ( uno::RuntimeException )
3681 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3683 m_pData->m_aInterfaceContainer.addInterface(
3684 ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3687 void SAL_CALL SfxBaseModel::removeStorageChangeListener(
3688 const uno::Reference< document::XStorageChangeListener >& xListener )
3689 throw ( uno::RuntimeException )
3691 SfxModelGuard aGuard( *this );
3693 m_pData->m_aInterfaceContainer.removeInterface(
3694 ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3697 #include "printhelper.hxx"
3698 bool SfxBaseModel::impl_getPrintHelper()
3700 if ( m_pData->m_xPrintable.is() )
3701 return true;
3702 m_pData->m_xPrintable = new SfxPrintHelper();
3703 uno::Reference < lang::XInitialization > xInit( m_pData->m_xPrintable, uno::UNO_QUERY );
3704 uno::Sequence < uno::Any > aValues(1);
3705 aValues[0] <<= uno::Reference < frame::XModel > (static_cast< frame::XModel* >(this), uno::UNO_QUERY );
3706 xInit->initialize( aValues );
3707 uno::Reference < view::XPrintJobBroadcaster > xBrd( m_pData->m_xPrintable, uno::UNO_QUERY );
3708 xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData ) );
3709 return true;
3712 //=============================================================================
3713 // css.frame.XModule
3714 void SAL_CALL SfxBaseModel::setIdentifier(const ::rtl::OUString& Identifier)
3715 throw (css::uno::RuntimeException)
3717 SfxModelGuard aGuard( *this );
3718 m_pData->m_sModuleIdentifier = Identifier;
3721 //=============================================================================
3722 // css.frame.XModule
3723 ::rtl::OUString SAL_CALL SfxBaseModel::getIdentifier()
3724 throw (css::uno::RuntimeException)
3726 SfxModelGuard aGuard( *this );
3727 if (!m_pData->m_sModuleIdentifier.isEmpty())
3728 return m_pData->m_sModuleIdentifier;
3729 if (m_pData->m_pObjectShell)
3730 return m_pData->m_pObjectShell->GetFactory().GetDocumentServiceName();
3731 return ::rtl::OUString();
3734 //=============================================================================
3735 css::uno::Reference< css::frame::XTitle > SfxBaseModel::impl_getTitleHelper ()
3737 SfxModelGuard aGuard( *this );
3739 if ( ! m_pData->m_xTitleHelper.is ())
3741 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory ();
3742 static const ::rtl::OUString SERVICENAME_DESKTOP("com.sun.star.frame.Desktop");
3743 css::uno::Reference< css::frame::XUntitledNumbers > xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
3744 css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3746 ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(xSMGR);
3747 m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3748 pHelper->setOwner (xThis );
3749 pHelper->connectWithUntitledNumbers (xDesktop);
3752 return m_pData->m_xTitleHelper;
3755 //=============================================================================
3756 css::uno::Reference< css::frame::XUntitledNumbers > SfxBaseModel::impl_getUntitledHelper ()
3758 SfxModelGuard aGuard( *this );
3760 if ( ! m_pData->m_xNumberedControllers.is ())
3762 css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3763 ::comphelper::NumberedCollection* pHelper = new ::comphelper::NumberedCollection();
3765 m_pData->m_xNumberedControllers = css::uno::Reference< css::frame::XUntitledNumbers >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3767 pHelper->setOwner (xThis);
3768 pHelper->setUntitledPrefix (::rtl::OUString(" : "));
3771 return m_pData->m_xNumberedControllers;
3774 //=============================================================================
3775 // css.frame.XTitle
3776 ::rtl::OUString SAL_CALL SfxBaseModel::getTitle()
3777 throw (css::uno::RuntimeException)
3779 // SYNCHRONIZED ->
3780 SfxModelGuard aGuard( *this );
3782 ::rtl::OUString aResult = impl_getTitleHelper()->getTitle ();
3783 if ( !m_pData->m_bExternalTitle && m_pData->m_pObjectShell )
3785 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
3786 if ( pMedium )
3788 try {
3789 ::ucbhelper::Content aContent( pMedium->GetName(),
3790 uno::Reference<ucb::XCommandEnvironment>() );
3791 const uno::Reference < beans::XPropertySetInfo > xProps
3792 = aContent.getProperties();
3793 if ( xProps.is() )
3795 ::rtl::OUString aServerTitle( "TitleOnServer" );
3796 if ( xProps->hasPropertyByName( aServerTitle ) )
3798 uno::Any aAny = aContent.getPropertyValue( aServerTitle );
3799 aAny >>= aResult;
3803 catch (ucb::ContentCreationException &)
3806 catch (ucb::CommandAbortedException &)
3809 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
3810 if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
3811 aResult += String( SfxResId(STR_REPAIREDDOCUMENT) );
3814 if ( m_pData->m_pObjectShell->IsReadOnlyUI() || (pMedium && pMedium->IsReadOnly()) )
3815 aResult += ::rtl::OUString( String( SfxResId(STR_READONLY) ) );
3816 else if ( m_pData->m_pObjectShell->IsDocShared() )
3817 aResult += ::rtl::OUString( String( SfxResId(STR_SHARED) ) );
3819 if ( m_pData->m_pObjectShell->GetDocumentSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
3820 aResult += String( SfxResId( RID_XMLSEC_DOCUMENTSIGNED ) );
3823 return aResult;
3826 //=============================================================================
3827 // css.frame.XTitle
3828 void SAL_CALL SfxBaseModel::setTitle( const ::rtl::OUString& sTitle )
3829 throw (css::uno::RuntimeException)
3831 // SYNCHRONIZED ->
3832 SfxModelGuard aGuard( *this );
3834 impl_getTitleHelper()->setTitle (sTitle);
3835 m_pData->m_bExternalTitle = sal_True;
3838 //=============================================================================
3839 // css.frame.XTitleChangeBroadcaster
3840 void SAL_CALL SfxBaseModel::addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3841 throw (css::uno::RuntimeException)
3843 // SYNCHRONIZED ->
3844 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3846 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3847 if (xBroadcaster.is ())
3848 xBroadcaster->addTitleChangeListener (xListener);
3851 //=============================================================================
3852 // css.frame.XTitleChangeBroadcaster
3853 void SAL_CALL SfxBaseModel::removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3854 throw (css::uno::RuntimeException)
3856 // SYNCHRONIZED ->
3857 SfxModelGuard aGuard( *this );
3859 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3860 if (xBroadcaster.is ())
3861 xBroadcaster->removeTitleChangeListener (xListener);
3864 //=============================================================================
3865 // css.frame.XUntitledNumbers
3866 ::sal_Int32 SAL_CALL SfxBaseModel::leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent )
3867 throw (css::lang::IllegalArgumentException,
3868 css::uno::RuntimeException )
3870 SfxModelGuard aGuard( *this );
3872 return impl_getUntitledHelper ()->leaseNumber (xComponent);
3875 //=============================================================================
3876 // css.frame.XUntitledNumbers
3877 void SAL_CALL SfxBaseModel::releaseNumber( ::sal_Int32 nNumber )
3878 throw (css::lang::IllegalArgumentException,
3879 css::uno::RuntimeException )
3881 SfxModelGuard aGuard( *this );
3882 impl_getUntitledHelper ()->releaseNumber (nNumber);
3885 //=============================================================================
3886 // css.frame.XUntitledNumbers
3887 void SAL_CALL SfxBaseModel::releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent )
3888 throw (css::lang::IllegalArgumentException,
3889 css::uno::RuntimeException )
3891 SfxModelGuard aGuard( *this );
3892 impl_getUntitledHelper ()->releaseNumberForComponent (xComponent);
3895 //=============================================================================
3896 // css.frame.XUntitledNumbers
3897 ::rtl::OUString SAL_CALL SfxBaseModel::getUntitledPrefix()
3898 throw (css::uno::RuntimeException)
3900 SfxModelGuard aGuard( *this );
3901 return impl_getUntitledHelper ()->getUntitledPrefix ();
3904 //=============================================================================
3905 // css::frame::XModel2
3906 css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxBaseModel::getControllers()
3907 throw (css::uno::RuntimeException)
3909 SfxModelGuard aGuard( *this );
3911 sal_Int32 c = m_pData->m_seqControllers.getLength();
3912 sal_Int32 i = 0;
3913 css::uno::Sequence< css::uno::Any > lEnum(c);
3914 for (i=0; i<c; ++i)
3915 lEnum[i] <<= m_pData->m_seqControllers[i];
3917 ::comphelper::OAnyEnumeration* pEnum = new ::comphelper::OAnyEnumeration(lEnum);
3918 css::uno::Reference< css::container::XEnumeration > xEnum(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY_THROW);
3919 return xEnum;
3922 //=============================================================================
3923 // css::frame::XModel2
3924 css::uno::Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getAvailableViewControllerNames()
3925 throw (css::uno::RuntimeException)
3927 SfxModelGuard aGuard( *this );
3929 const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
3930 const sal_Int16 nViewFactoryCount = rDocumentFactory.GetViewFactoryCount();
3932 Sequence< ::rtl::OUString > aViewNames( nViewFactoryCount );
3933 for ( sal_Int16 nViewNo = 0; nViewNo < nViewFactoryCount; ++nViewNo )
3934 aViewNames[nViewNo] = rDocumentFactory.GetViewFactory( nViewNo ).GetAPIViewName();
3935 return aViewNames;
3938 //=============================================================================
3939 // css::frame::XModel2
3940 css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createDefaultViewController( const css::uno::Reference< css::frame::XFrame >& i_rFrame )
3941 throw (css::uno::RuntimeException ,
3942 css::lang::IllegalArgumentException,
3943 css::uno::Exception )
3945 SfxModelGuard aGuard( *this );
3947 const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
3948 const ::rtl::OUString sDefaultViewName = rDocumentFactory.GetViewFactory( 0 ).GetAPIViewName();
3950 aGuard.clear();
3952 return createViewController( sDefaultViewName, Sequence< PropertyValue >(), i_rFrame );
3955 //=============================================================================
3956 namespace sfx { namespace intern {
3958 /** a class which, in its dtor, cleans up variuos objects (well, at the moment only the frame) collected during
3959 the creation of a document view, unless the creation was successful.
3961 class SAL_DLLPRIVATE ViewCreationGuard
3963 public:
3964 ViewCreationGuard()
3965 :m_bSuccess( false )
3969 ~ViewCreationGuard()
3971 if ( !m_bSuccess )
3972 impl_closeAll();
3975 void takeFrameOwnership( SfxFrame* i_pFrame )
3977 OSL_PRECOND( !m_aWeakFrame, "ViewCreationGuard::takeFrameOwnership: already have a frame!" );
3978 OSL_PRECOND( i_pFrame != NULL, "ViewCreationGuard::takeFrameOwnership: invalid frame!" );
3979 m_aWeakFrame = i_pFrame;
3982 void releaseAll()
3984 m_bSuccess = true;
3987 private:
3988 void impl_closeAll()
3990 if ( m_aWeakFrame && !m_aWeakFrame->GetCurrentDocument() )
3992 m_aWeakFrame->SetFrameInterface_Impl( NULL );
3993 m_aWeakFrame->DoClose();
3997 private:
3998 bool m_bSuccess;
3999 SfxFrameWeak m_aWeakFrame;
4003 //=============================================================================
4004 SfxViewFrame* SfxBaseModel::FindOrCreateViewFrame_Impl( const Reference< XFrame >& i_rFrame, ::sfx::intern::ViewCreationGuard& i_rGuard ) const
4006 SfxViewFrame* pViewFrame = NULL;
4007 for ( pViewFrame = SfxViewFrame::GetFirst( GetObjectShell(), sal_False );
4008 pViewFrame;
4009 pViewFrame= SfxViewFrame::GetNext( *pViewFrame, GetObjectShell(), sal_False )
4012 if ( pViewFrame->GetFrame().GetFrameInterface() == i_rFrame )
4013 break;
4015 if ( !pViewFrame )
4017 #if OSL_DEBUG_LEVEL > 0
4018 for ( SfxFrame* pCheckFrame = SfxFrame::GetFirst();
4019 pCheckFrame;
4020 pCheckFrame = SfxFrame::GetNext( *pCheckFrame )
4023 if ( pCheckFrame->GetFrameInterface() == i_rFrame )
4025 if ( ( pCheckFrame->GetCurrentViewFrame() != NULL )
4026 || ( pCheckFrame->GetCurrentDocument() != NULL )
4028 // Note that it is perfectly letgitimate that during loading into an XFrame which already contains
4029 // a document, there exist two SfxFrame instances bound to this XFrame - the old one, which will be
4030 // destroyed later, and the new one, which we're going to create
4031 continue;
4033 OSL_FAIL( "SfxBaseModel::FindOrCreateViewFrame_Impl: there already is an SfxFrame for the given XFrame, but no view in it!" );
4034 // nowadays, we're the only instance allowed to create an SfxFrame for an XFrame, so this case here should not happen
4035 break;
4038 #endif
4040 SfxFrame* pTargetFrame = SfxFrame::Create( i_rFrame );
4041 ENSURE_OR_THROW( pTargetFrame, "could not create an SfxFrame" );
4042 i_rGuard.takeFrameOwnership( pTargetFrame );
4044 // prepare it
4045 pTargetFrame->PrepareForDoc_Impl( *GetObjectShell() );
4047 // create view frame
4048 pViewFrame = new SfxViewFrame( *pTargetFrame, GetObjectShell() );
4050 return pViewFrame;
4053 //=============================================================================
4054 // css::frame::XModel2
4055 css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createViewController(
4056 const ::rtl::OUString& i_rViewName, const Sequence< PropertyValue >& i_rArguments, const Reference< XFrame >& i_rFrame )
4057 throw (css::uno::RuntimeException ,
4058 css::lang::IllegalArgumentException,
4059 css::uno::Exception )
4061 SfxModelGuard aGuard( *this );
4063 if ( !i_rFrame.is() )
4064 throw css::lang::IllegalArgumentException( ::rtl::OUString(), *this, 3 );
4066 // find the proper SFX view factory
4067 SfxViewFactory* pViewFactory = GetObjectShell()->GetFactory().GetViewFactoryByViewName( i_rViewName );
4068 if ( !pViewFactory )
4069 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
4071 // determine previous shell (used in some special cases)
4072 Reference< XController > xPreviousController( i_rFrame->getController() );
4073 const Reference< XModel > xMe( this );
4074 if ( ( xPreviousController.is() )
4075 && ( xMe != xPreviousController->getModel() )
4078 xPreviousController.clear();
4080 SfxViewShell* pOldViewShell = SfxViewShell::Get( xPreviousController );
4081 OSL_ENSURE( !xPreviousController.is() || ( pOldViewShell != NULL ),
4082 "SfxBaseModel::createViewController: invalid old controller!" );
4084 // a guard which will clean up in case of failure
4085 ::sfx::intern::ViewCreationGuard aViewCreationGuard;
4087 // determine the ViewFrame belonging to the given XFrame
4088 SfxViewFrame* pViewFrame = FindOrCreateViewFrame_Impl( i_rFrame, aViewCreationGuard );
4089 OSL_POSTCOND( pViewFrame, "SfxBaseModel::createViewController: no frame?" );
4091 // delegate to SFX' view factory
4092 pViewFrame->GetBindings().ENTERREGISTRATIONS();
4093 SfxViewShell* pViewShell = pViewFactory->CreateInstance( pViewFrame, pOldViewShell );
4094 pViewFrame->GetBindings().LEAVEREGISTRATIONS();
4095 ENSURE_OR_THROW( pViewShell, "invalid view shell provided by factory" );
4097 // by setting the ViewShell it is prevented that disposing the Controller will destroy this ViewFrame also
4098 pViewFrame->GetDispatcher()->SetDisableFlags( 0 );
4099 pViewFrame->SetViewShell_Impl( pViewShell );
4101 // remember ViewID
4102 pViewFrame->SetCurViewId_Impl( pViewFactory->GetOrdinal() );
4104 // ensure a default controller, if the view shell did not provide an own implementation
4105 if ( !pViewShell->GetController().is() )
4106 pViewShell->SetController( new SfxBaseController( pViewShell ) );
4108 // pass the creation arguments to the controller
4109 SfxBaseController* pBaseController = pViewShell->GetBaseController_Impl();
4110 ENSURE_OR_THROW( pBaseController, "invalid controller implementation!" );
4111 pBaseController->SetCreationArguments_Impl( i_rArguments );
4113 // some initial view settings, coming from our most recent attachResource call
4114 ::comphelper::NamedValueCollection aDocumentLoadArgs( getArgs() );
4115 if ( aDocumentLoadArgs.getOrDefault( "ViewOnly", false ) )
4116 pViewFrame->GetFrame().SetMenuBarOn_Impl( sal_False );
4118 const sal_Int16 nPluginMode = aDocumentLoadArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
4119 if ( nPluginMode == 1 )
4121 pViewFrame->ForceOuterResize_Impl( sal_False );
4122 pViewFrame->GetBindings().HidePopups( sal_True );
4124 SfxFrame& rFrame = pViewFrame->GetFrame();
4125 // MBA: layoutmanager of inplace frame starts locked and invisible
4126 rFrame.GetWorkWindow_Impl()->MakeVisible_Impl( sal_False );
4127 rFrame.GetWorkWindow_Impl()->Lock_Impl( sal_True );
4129 rFrame.GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4130 pViewFrame->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4133 // tell the guard we were successful
4134 aViewCreationGuard.releaseAll();
4136 // outta gere
4137 return pBaseController;
4140 //=============================================================================
4141 // RDF DocumentMetadataAccess
4143 // ::com::sun::star::rdf::XRepositorySupplier:
4144 uno::Reference< rdf::XRepository > SAL_CALL
4145 SfxBaseModel::getRDFRepository() throw (uno::RuntimeException)
4147 SfxModelGuard aGuard( *this );
4149 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4150 if (!xDMA.is()) {
4151 throw uno::RuntimeException( ::rtl::OUString(
4152 "model has no document metadata"), *this );
4155 return xDMA->getRDFRepository();
4158 // ::com::sun::star::rdf::XNode:
4159 ::rtl::OUString SAL_CALL
4160 SfxBaseModel::getStringValue() throw (uno::RuntimeException)
4162 SfxModelGuard aGuard( *this );
4164 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4165 if (!xDMA.is()) {
4166 throw uno::RuntimeException( ::rtl::OUString(
4167 "model has no document metadata"), *this );
4170 return xDMA->getStringValue();
4173 // ::com::sun::star::rdf::XURI:
4174 ::rtl::OUString SAL_CALL
4175 SfxBaseModel::getNamespace() throw (uno::RuntimeException)
4177 SfxModelGuard aGuard( *this );
4179 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4180 if (!xDMA.is()) {
4181 throw uno::RuntimeException( ::rtl::OUString(
4182 "model has no document metadata"), *this );
4185 return xDMA->getNamespace();
4188 ::rtl::OUString SAL_CALL
4189 SfxBaseModel::getLocalName() throw (uno::RuntimeException)
4191 SfxModelGuard aGuard( *this );
4193 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4194 if (!xDMA.is()) {
4195 throw uno::RuntimeException( ::rtl::OUString(
4196 "model has no document metadata"), *this );
4199 return xDMA->getLocalName();
4202 // ::com::sun::star::rdf::XDocumentMetadataAccess:
4203 uno::Reference< rdf::XMetadatable > SAL_CALL
4204 SfxBaseModel::getElementByMetadataReference(
4205 const ::com::sun::star::beans::StringPair & i_rReference)
4206 throw (uno::RuntimeException)
4208 SfxModelGuard aGuard( *this );
4210 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4211 if (!xDMA.is()) {
4212 throw uno::RuntimeException( ::rtl::OUString(
4213 "model has no document metadata"), *this );
4216 return xDMA->getElementByMetadataReference(i_rReference);
4219 uno::Reference< rdf::XMetadatable > SAL_CALL
4220 SfxBaseModel::getElementByURI(const uno::Reference< rdf::XURI > & i_xURI)
4221 throw (uno::RuntimeException, lang::IllegalArgumentException)
4223 SfxModelGuard aGuard( *this );
4225 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4226 if (!xDMA.is()) {
4227 throw uno::RuntimeException( ::rtl::OUString(
4228 "model has no document metadata"), *this );
4231 return xDMA->getElementByURI(i_xURI);
4234 uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
4235 SfxBaseModel::getMetadataGraphsWithType(
4236 const uno::Reference<rdf::XURI> & i_xType)
4237 throw (uno::RuntimeException, lang::IllegalArgumentException)
4239 SfxModelGuard aGuard( *this );
4241 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4242 if (!xDMA.is()) {
4243 throw uno::RuntimeException( ::rtl::OUString(
4244 "model has no document metadata"), *this );
4247 return xDMA->getMetadataGraphsWithType(i_xType);
4250 uno::Reference<rdf::XURI> SAL_CALL
4251 SfxBaseModel::addMetadataFile(const ::rtl::OUString & i_rFileName,
4252 const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4253 throw (uno::RuntimeException, lang::IllegalArgumentException,
4254 container::ElementExistException)
4256 SfxModelGuard aGuard( *this );
4258 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4259 if (!xDMA.is()) {
4260 throw uno::RuntimeException( ::rtl::OUString(
4261 "model has no document metadata"), *this );
4264 return xDMA->addMetadataFile(i_rFileName, i_rTypes);
4267 uno::Reference<rdf::XURI> SAL_CALL
4268 SfxBaseModel::importMetadataFile(::sal_Int16 i_Format,
4269 const uno::Reference< io::XInputStream > & i_xInStream,
4270 const ::rtl::OUString & i_rFileName,
4271 const uno::Reference< rdf::XURI > & i_xBaseURI,
4272 const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4273 throw (uno::RuntimeException, lang::IllegalArgumentException,
4274 datatransfer::UnsupportedFlavorException,
4275 container::ElementExistException, rdf::ParseException, io::IOException)
4277 SfxModelGuard aGuard( *this );
4279 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4280 if (!xDMA.is()) {
4281 throw uno::RuntimeException( ::rtl::OUString(
4282 "model has no document metadata"), *this );
4285 return xDMA->importMetadataFile(i_Format,
4286 i_xInStream, i_rFileName, i_xBaseURI, i_rTypes);
4289 void SAL_CALL
4290 SfxBaseModel::removeMetadataFile(
4291 const uno::Reference< rdf::XURI > & i_xGraphName)
4292 throw (uno::RuntimeException, lang::IllegalArgumentException,
4293 container::NoSuchElementException)
4295 SfxModelGuard aGuard( *this );
4297 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4298 if (!xDMA.is()) {
4299 throw uno::RuntimeException( ::rtl::OUString(
4300 "model has no document metadata"), *this );
4303 return xDMA->removeMetadataFile(i_xGraphName);
4306 void SAL_CALL
4307 SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4308 throw (uno::RuntimeException, lang::IllegalArgumentException,
4309 container::ElementExistException)
4311 SfxModelGuard aGuard( *this );
4313 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4314 if (!xDMA.is()) {
4315 throw uno::RuntimeException( ::rtl::OUString(
4316 "model has no document metadata"), *this );
4319 return xDMA->addContentOrStylesFile(i_rFileName);
4322 void SAL_CALL
4323 SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4324 throw (uno::RuntimeException, lang::IllegalArgumentException,
4325 container::NoSuchElementException)
4327 SfxModelGuard aGuard( *this );
4329 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4330 if (!xDMA.is()) {
4331 throw uno::RuntimeException( ::rtl::OUString(
4332 "model has no document metadata"), *this );
4335 return xDMA->removeContentOrStylesFile(i_rFileName);
4338 void SAL_CALL
4339 SfxBaseModel::loadMetadataFromStorage(
4340 uno::Reference< embed::XStorage > const & i_xStorage,
4341 uno::Reference<rdf::XURI> const & i_xBaseURI,
4342 uno::Reference<task::XInteractionHandler> const & i_xHandler)
4343 throw (uno::RuntimeException, lang::IllegalArgumentException,
4344 lang::WrappedTargetException)
4346 SfxModelGuard aGuard( *this );
4348 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4349 m_pData->CreateDMAUninitialized());
4350 if (!xDMA.is()) {
4351 throw uno::RuntimeException( ::rtl::OUString(
4352 "model has no document metadata"), *this );
4355 try {
4356 xDMA->loadMetadataFromStorage(i_xStorage, i_xBaseURI, i_xHandler);
4357 } catch (lang::IllegalArgumentException &) {
4358 throw; // not initialized
4359 } catch (uno::Exception &) {
4360 // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4361 m_pData->m_xDocumentMetadata = xDMA;
4362 throw;
4364 m_pData->m_xDocumentMetadata = xDMA;
4368 void SAL_CALL
4369 SfxBaseModel::storeMetadataToStorage(
4370 uno::Reference< embed::XStorage > const & i_xStorage)
4371 throw (uno::RuntimeException, lang::IllegalArgumentException,
4372 lang::WrappedTargetException)
4374 SfxModelGuard aGuard( *this );
4376 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4377 if (!xDMA.is()) {
4378 throw uno::RuntimeException( ::rtl::OUString(
4379 "model has no document metadata"), *this );
4382 return xDMA->storeMetadataToStorage(i_xStorage);
4385 void SAL_CALL
4386 SfxBaseModel::loadMetadataFromMedium(
4387 const uno::Sequence< beans::PropertyValue > & i_rMedium)
4388 throw (uno::RuntimeException, lang::IllegalArgumentException,
4389 lang::WrappedTargetException)
4391 SfxModelGuard aGuard( *this );
4393 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4394 m_pData->CreateDMAUninitialized());
4395 if (!xDMA.is()) {
4396 throw uno::RuntimeException( ::rtl::OUString(
4397 "model has no document metadata"), *this );
4400 try {
4401 xDMA->loadMetadataFromMedium(i_rMedium);
4402 } catch (lang::IllegalArgumentException &) {
4403 throw; // not initialized
4404 } catch (uno::Exception &) {
4405 // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4406 m_pData->m_xDocumentMetadata = xDMA;
4407 throw;
4409 m_pData->m_xDocumentMetadata = xDMA;
4412 void SAL_CALL
4413 SfxBaseModel::storeMetadataToMedium(
4414 const uno::Sequence< beans::PropertyValue > & i_rMedium)
4415 throw (uno::RuntimeException, lang::IllegalArgumentException,
4416 lang::WrappedTargetException)
4418 SfxModelGuard aGuard( *this );
4420 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4421 if (!xDMA.is()) {
4422 throw uno::RuntimeException( ::rtl::OUString(
4423 "model has no document metadata"), *this );
4426 return xDMA->storeMetadataToMedium(i_rMedium);
4429 // =====================================================================================================================
4430 // = SfxModelSubComponent
4431 // =====================================================================================================================
4433 SfxModelSubComponent::~SfxModelSubComponent()
4437 void SfxModelSubComponent::disposing()
4439 // nothing to do here
4442 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */