xref: /aoo4110/main/sfx2/source/doc/sfxbasemodel.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 //________________________________________________________________________________________________________
28 //	my own includes
29 //________________________________________________________________________________________________________
30 
31 #include <sfx2/sfxbasemodel.hxx>
32 
33 //________________________________________________________________________________________________________
34 //	include of other projects
35 //________________________________________________________________________________________________________
36 
37 #include <com/sun/star/task/XInteractionHandler.hpp>
38 #include <com/sun/star/task/ErrorCodeRequest.hpp>
39 #include <com/sun/star/view/XSelectionSupplier.hpp>
40 #include <com/sun/star/view/XPrintJobListener.hpp>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 #include <com/sun/star/lang/IllegalArgumentException.hpp>
43 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
44 #include <com/sun/star/frame/IllegalArgumentIOException.hpp>
45 #include <com/sun/star/frame/XUntitledNumbers.hpp>
46 #include <com/sun/star/frame/UntitledNumbersConst.hpp>
47 #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
48 #include <com/sun/star/embed/XStorage.hpp>
49 #include <com/sun/star/embed/EmbedMapUnits.hpp>
50 #include <com/sun/star/document/XStorageChangeListener.hpp>
51 #include <com/sun/star/document/XActionLockable.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <com/sun/star/container/XIndexContainer.hpp>
54 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
55 #include <com/sun/star/script/provider/XScriptProvider.hpp>
56 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
57 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
58 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
59 #include <com/sun/star/embed/ElementModes.hpp>
60 #include <com/sun/star/embed/Aspects.hpp>
61 #include <com/sun/star/document/XDocumentProperties.hpp>
62 #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
63 #include <comphelper/enumhelper.hxx>  // can be removed when this is a "real" service
64 
65 #include <cppuhelper/interfacecontainer.hxx>
66 #include <cppuhelper/exc_hlp.hxx>
67 #include <comphelper/processfactory.hxx>  // can be removed when this is a "real" service
68 #include <comphelper/componentcontext.hxx>
69 #include <comphelper/namedvaluecollection.hxx>
70 #include <svl/itemset.hxx>
71 #include <svl/stritem.hxx>
72 #include <svl/eitem.hxx>
73 #include <svl/intitem.hxx>
74 #include <basic/sbx.hxx>
75 #include <basic/sbuno.hxx>
76 #include <tools/urlobj.hxx>
77 #include <tools/diagnose_ex.h>
78 #include <unotools/tempfile.hxx>
79 #include <vos/mutex.hxx>
80 #include <vcl/salctype.hxx>
81 #include <sot/clsids.hxx>
82 #include <sot/storinfo.hxx>
83 #include <comphelper/storagehelper.hxx>
84 #include <toolkit/helper/vclunohelper.hxx>
85 #include <svtools/transfer.hxx>
86 #include <svtools/ehdl.hxx>
87 #include <svtools/sfxecode.hxx>
88 #include <rtl/logfile.hxx>
89 #include <framework/configimporter.hxx>
90 #include <framework/interaction.hxx>
91 #include <framework/titlehelper.hxx>
92 #include <comphelper/numberedcollection.hxx>
93 #include <unotools/ucbstreamhelper.hxx>
94 #include <unotools/ucbhelper.hxx>
95 
96 //________________________________________________________________________________________________________
97 //	includes of my own project
98 //________________________________________________________________________________________________________
99 
100 #include <sfx2/sfxbasecontroller.hxx>
101 #include "sfx2/viewfac.hxx"
102 #include "workwin.hxx"
103 #include <sfx2/signaturestate.hxx>
104 #include <sfx2/sfxuno.hxx>
105 #include <objshimp.hxx>
106 #include <sfx2/viewfrm.hxx>
107 #include <sfx2/viewsh.hxx>
108 #include <sfx2/docfile.hxx>
109 #include <sfx2/dispatch.hxx>
110 #include <sfx2/request.hxx>
111 #include <sfx2/objuno.hxx>
112 #include <sfx2/printer.hxx>
113 #include <sfx2/basmgr.hxx>
114 #include <sfx2/event.hxx>
115 #include <eventsupplier.hxx>
116 #include <sfx2/evntconf.hxx>
117 #include <sfx2/sfx.hrc>
118 #include <sfx2/app.hxx>
119 #include <sfx2/viewfrm.hxx>
120 #include "appdata.hxx"
121 #include <sfx2/docfac.hxx>
122 #include <sfx2/fcontnr.hxx>
123 #include "sfx2/docstoragemodifylistener.hxx"
124 #include "sfx2/brokenpackageint.hxx"
125 #include "graphhelp.hxx"
126 #include "docundomanager.hxx"
127 #include <sfx2/msgpool.hxx>
128 #include <sfx2/DocumentMetadataAccess.hxx>
129 
130 #include <sfx2/sfxresid.hxx>
131 
132 //________________________________________________________________________________________________________
133 // const
134 static const ::rtl::OUString SERVICENAME_DESKTOP = ::rtl::OUString::createFromAscii ("com.sun.star.frame.Desktop");
135 
136 //________________________________________________________________________________________________________
137 //	namespaces
138 //________________________________________________________________________________________________________
139 
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;
157 
158 /** This Listener is used to get notified when the XDocumentProperties of the
159     XModel change.
160  */
161 class SfxDocInfoListener_Impl : public ::cppu::WeakImplHelper1<
162     ::com::sun::star::util::XModifyListener >
163 {
164 
165 public:
166     SfxObjectShell& m_rShell;
167 
SfxDocInfoListener_Impl(SfxObjectShell & i_rDoc)168     SfxDocInfoListener_Impl( SfxObjectShell& i_rDoc )
169         : m_rShell(i_rDoc)
170     { };
171 
172     ~SfxDocInfoListener_Impl();
173 
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 );
178 };
~SfxDocInfoListener_Impl()179 SfxDocInfoListener_Impl::~SfxDocInfoListener_Impl()
180 {
181 }
modified(const lang::EventObject &)182 void SAL_CALL SfxDocInfoListener_Impl::modified( const lang::EventObject& )
183         throw ( uno::RuntimeException )
184 {
185     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
186 
187     // notify changes to the SfxObjectShell
188     m_rShell.FlushDocInfo();
189 }
190 
disposing(const lang::EventObject &)191 void SAL_CALL SfxDocInfoListener_Impl::disposing( const lang::EventObject& )
192     throw ( uno::RuntimeException )
193 {
194 }
195 
196 //________________________________________________________________________________________________________
197 //	impl. declarations
198 //________________________________________________________________________________________________________
199 
200 
201 struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
202 {
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;
236 
237 
IMPL_SfxBaseModel_DataContainerIMPL_SfxBaseModel_DataContainer238     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  ()
254 	{
255         // increase global instance counter.
256         ++g_nInstanceCounter;
257         // set own Runtime UID
258         m_sRuntimeUID = rtl::OUString::valueOf( g_nInstanceCounter );
259 	}
260 
~IMPL_SfxBaseModel_DataContainerIMPL_SfxBaseModel_DataContainer261     virtual ~IMPL_SfxBaseModel_DataContainer()
262     {
263     }
264 
265     // ::sfx2::IModifiableDocument
storageIsModifiedIMPL_SfxBaseModel_DataContainer266     virtual void storageIsModified()
267     {
268 	    if ( m_pObjectShell.Is() && !m_pObjectShell->IsModified() )
269 		    m_pObjectShell->SetModified( sal_True );
270     }
271 
GetDMAIMPL_SfxBaseModel_DataContainer272     uno::Reference<rdf::XDocumentMetadataAccess> GetDMA()
273     {
274         if (!m_xDocumentMetadata.is())
275         {
276             OSL_ENSURE(m_pObjectShell, "GetDMA: no object shell?");
277             if (!m_pObjectShell)
278             {
279                 return 0;
280             }
281 
282             const uno::Reference<uno::XComponentContext> xContext(
283                 ::comphelper::getProcessComponentContext());
284             ::rtl::OUString uri;
285             const uno::Reference<frame::XModel> xModel(
286                 m_pObjectShell->GetModel());
287             const uno::Reference<lang::XMultiComponentFactory> xMsf(
288                 xContext->getServiceManager());
289             const uno::Reference<frame::
290                 XTransientDocumentsDocumentContentFactory> xTDDCF(
291                     xMsf->createInstanceWithContext(
292                         ::rtl::OUString::createFromAscii( "com.sun.star.frame."
293                             "TransientDocumentsDocumentContentFactory"),
294                     xContext),
295                 uno::UNO_QUERY_THROW);
296             const uno::Reference<ucb::XContent> xContent(
297                 xTDDCF->createDocumentContent(xModel) );
298             OSL_ENSURE(xContent.is(), "GetDMA: cannot create DocumentContent");
299             if (!xContent.is())
300             {
301                 return 0;
302             }
303             uri = xContent->getIdentifier()->getContentIdentifier();
304             OSL_ENSURE(uri.getLength(), "GetDMA: empty uri?");
305             if (uri.getLength() && !uri.endsWithAsciiL("/", 1))
306             {
307                 uri = uri + ::rtl::OUString::createFromAscii("/");
308             }
309 
310             m_xDocumentMetadata = new ::sfx2::DocumentMetadataAccess(
311                 xContext, *m_pObjectShell, uri);
312         }
313         return m_xDocumentMetadata;
314     }
315 
CreateDMAUninitializedIMPL_SfxBaseModel_DataContainer316     uno::Reference<rdf::XDocumentMetadataAccess> CreateDMAUninitialized()
317     {
318         return (m_pObjectShell)
319             ? new ::sfx2::DocumentMetadataAccess(
320                 ::comphelper::getProcessComponentContext(), *m_pObjectShell)
321             : 0;
322     }
323 };
324 
325 // static member initialization.
326 sal_Int64 IMPL_SfxBaseModel_DataContainer::g_nInstanceCounter = 0;
327 
328 // =======================================================================================================
329 
330 // Listener that forwards notifications from the PrintHelper to the "real" listeners
331 class SfxPrintHelperListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::view::XPrintJobListener >
332 {
333 public:
334     IMPL_SfxBaseModel_DataContainer* m_pData;
SfxPrintHelperListener_Impl(IMPL_SfxBaseModel_DataContainer * pData)335     SfxPrintHelperListener_Impl( IMPL_SfxBaseModel_DataContainer* pData )
336         : m_pData( pData )
337     {}
338 
339     virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
340     virtual void SAL_CALL printJobEvent( const view::PrintJobEvent& rEvent ) throw ( uno::RuntimeException);
341 };
342 
disposing(const lang::EventObject &)343 void SAL_CALL SfxPrintHelperListener_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException )
344 {
345     m_pData->m_xPrintable = 0;
346 }
347 
printJobEvent(const view::PrintJobEvent & rEvent)348 void SAL_CALL SfxPrintHelperListener_Impl::printJobEvent( const view::PrintJobEvent& rEvent ) throw (uno::RuntimeException)
349 {
350     ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< view::XPrintJobListener >*) NULL ) );
351     if ( pContainer!=NULL )
352     {
353         ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
354         while (pIterator.hasMoreElements())
355             ((view::XPrintJobListener*)pIterator.next())->printJobEvent( rEvent );
356     }
357 }
358 
359 // SfxOwnFramesLocker ====================================================================================
360 // allows to lock all the frames related to the provided SfxObjectShell
361 class SfxOwnFramesLocker
362 {
363 	uno::Sequence< uno::Reference< frame::XFrame > > m_aLockedFrames;
364 
365 	Window* GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame );
366 public:
367 	SfxOwnFramesLocker( SfxObjectShell* ObjechShell );
368 	~SfxOwnFramesLocker();
369 	void UnlockFrames();
370 };
371 
SfxOwnFramesLocker(SfxObjectShell * pObjectShell)372 SfxOwnFramesLocker::SfxOwnFramesLocker( SfxObjectShell* pObjectShell )
373 {
374 	if ( !pObjectShell )
375 		return;
376 
377 	for (   SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjectShell );
378             pFrame;
379 			pFrame = SfxViewFrame::GetNext( *pFrame, pObjectShell )
380         )
381 	{
382 		SfxFrame& rSfxFrame = pFrame->GetFrame();
383 		try
384 		{
385 			// get vcl window related to the frame and lock it if it is still not locked
386 			uno::Reference< frame::XFrame > xFrame = rSfxFrame.GetFrameInterface();
387 			Window* pWindow = GetVCLWindow( xFrame );
388 			if ( !pWindow )
389 				throw uno::RuntimeException();
390 
391 			if ( pWindow->IsEnabled() )
392 			{
393 				pWindow->Disable();
394 
395 				try
396 				{
397 					sal_Int32 nLen = m_aLockedFrames.getLength();
398 					m_aLockedFrames.realloc( nLen + 1 );
399 					m_aLockedFrames[nLen] = xFrame;
400 				}
401 				catch( uno::Exception& )
402 				{
403 					pWindow->Enable();
404 					throw;
405 				}
406 			}
407 		}
408 		catch( uno::Exception& )
409 		{
410 			OSL_ENSURE( sal_False, "Not possible to lock the frame window!\n" );
411 		}
412 	}
413 }
414 
~SfxOwnFramesLocker()415 SfxOwnFramesLocker::~SfxOwnFramesLocker()
416 {
417 	UnlockFrames();
418 }
419 
GetVCLWindow(const uno::Reference<frame::XFrame> & xFrame)420 Window* SfxOwnFramesLocker::GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame )
421 {
422 	Window* pWindow = NULL;
423 
424 	if ( xFrame.is() )
425 	{
426 		uno::Reference< awt::XWindow > xWindow = xFrame->getContainerWindow();
427 		if ( xWindow.is() )
428    			pWindow = VCLUnoHelper::GetWindow( xWindow );
429 	}
430 
431 	return pWindow;
432 }
433 
UnlockFrames()434 void SfxOwnFramesLocker::UnlockFrames()
435 {
436 	for ( sal_Int32 nInd = 0; nInd < m_aLockedFrames.getLength(); nInd++ )
437 	{
438 		try
439 		{
440 			if ( m_aLockedFrames[nInd].is() )
441 			{
442 				// get vcl window related to the frame and unlock it
443 				Window* pWindow = GetVCLWindow( m_aLockedFrames[nInd] );
444 				if ( !pWindow )
445 					throw uno::RuntimeException();
446 
447 				pWindow->Enable();
448 
449 				m_aLockedFrames[nInd] = uno::Reference< frame::XFrame >();
450 			}
451 		}
452 		catch( uno::Exception& )
453 		{
454 			OSL_ENSURE( sal_False, "Can't unlock the frame window!\n" );
455 		}
456 	}
457 }
458 
459 // SfxSaveGuard ====================================================================================
460 class SfxSaveGuard
461 {
462     private:
463         uno::Reference< frame::XModel > m_xModel;
464         IMPL_SfxBaseModel_DataContainer* m_pData;
465         SfxOwnFramesLocker* m_pFramesLock;
466 
467     public:
468         SfxSaveGuard(const uno::Reference< frame::XModel >&             xModel                      ,
469                            IMPL_SfxBaseModel_DataContainer* pData                       ,
470                            sal_Bool                         bRejectConcurrentSaveRequest);
471         ~SfxSaveGuard();
472 };
473 
SfxSaveGuard(const uno::Reference<frame::XModel> & xModel,IMPL_SfxBaseModel_DataContainer * pData,sal_Bool bRejectConcurrentSaveRequest)474 SfxSaveGuard::SfxSaveGuard(const uno::Reference< frame::XModel >&             xModel                      ,
475                                  IMPL_SfxBaseModel_DataContainer* pData                       ,
476                                  sal_Bool                         bRejectConcurrentSaveRequest)
477     : m_xModel     (xModel)
478     , m_pData      (pData )
479     , m_pFramesLock(0     )
480 {
481     static ::rtl::OUString MSG_1 = ::rtl::OUString::createFromAscii("Object already disposed."                                       );
482     static ::rtl::OUString MSG_2 = ::rtl::OUString::createFromAscii("Concurrent save requests on the same document are not possible.");
483 
484     if ( m_pData->m_bClosed )
485         throw ::com::sun::star::lang::DisposedException(
486                 MSG_1,
487                 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
488 
489     if (
490         bRejectConcurrentSaveRequest &&
491         m_pData->m_bSaving
492        )
493         throw ::com::sun::star::io::IOException(
494                 MSG_2,
495                 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
496 
497     m_pData->m_bSaving = sal_True;
498     m_pFramesLock = new SfxOwnFramesLocker(m_pData->m_pObjectShell);
499 }
500 
~SfxSaveGuard()501 SfxSaveGuard::~SfxSaveGuard()
502 {
503     SfxOwnFramesLocker* pFramesLock = m_pFramesLock;
504     m_pFramesLock = 0;
505     delete pFramesLock;
506 
507     m_pData->m_bSaving = sal_False;
508 
509     // m_bSuicide was set e.g. in case somewhere tried to close a document, while it was used for
510     // storing at the same time. Further m_bSuicide was set to sal_True only if close(sal_True) was called.
511     // So the owner ship was delegated to the place where a veto exception was thrown.
512     // Now we have to call close() again and delegate the owner ship to the next one, which
513     // cant accept that. Close(sal_False) cant work in this case. Because then the document will may be never closed ...
514 
515     if ( m_pData->m_bSuicide )
516     {
517         // Reset this state. In case the new close() request is not accepted by somehwere else ...
518         // it's not a good idea to have two "owners" for close .-)
519         m_pData->m_bSuicide = sal_False;
520         try
521         {
522             uno::Reference< util::XCloseable > xClose(m_xModel, uno::UNO_QUERY);
523             if (xClose.is())
524                 xClose->close(sal_True);
525         }
526         catch(const util::CloseVetoException&)
527         {}
528     }
529 }
530 
531 // =======================================================================================================
532 
533 //________________________________________________________________________________________________________
534 //	constructor
535 //________________________________________________________________________________________________________
DBG_NAME(sfx2_SfxBaseModel)536 DBG_NAME(sfx2_SfxBaseModel)
537 SfxBaseModel::SfxBaseModel( SfxObjectShell *pObjectShell )
538 : BaseMutex()
539 , m_pData( new IMPL_SfxBaseModel_DataContainer( m_aMutex, pObjectShell ) )
540 , m_bSupportEmbeddedScripts( pObjectShell && pObjectShell->Get_Impl() ? !pObjectShell->Get_Impl()->m_bNoBasicCapabilities : false )
541 , m_bSupportDocRecovery( pObjectShell && pObjectShell->Get_Impl() ? pObjectShell->Get_Impl()->m_bDocRecoverySupport : false )
542 {
543     DBG_CTOR(sfx2_SfxBaseModel,NULL);
544 	if ( pObjectShell != NULL )
545 	{
546 		StartListening( *pObjectShell ) ;
547 	}
548 }
549 
550 //________________________________________________________________________________________________________
551 //	destructor
552 //________________________________________________________________________________________________________
553 
~SfxBaseModel()554 SfxBaseModel::~SfxBaseModel()
555 {
556     DBG_DTOR(sfx2_SfxBaseModel,NULL);
557 }
558 
559 //________________________________________________________________________________________________________
560 //	XInterface
561 //________________________________________________________________________________________________________
562 
queryInterface(const UNOTYPE & rType)563 uno::Any SAL_CALL SfxBaseModel::queryInterface( const UNOTYPE& rType ) throw( uno::RuntimeException )
564 {
565     if  (   ( !m_bSupportEmbeddedScripts && rType.equals( XEMBEDDEDSCRIPTS::static_type() ) )
566         ||  ( !m_bSupportDocRecovery && rType.equals( XDocumentRecovery::static_type() ) )
567         )
568         return Any();
569 
570     return SfxBaseModel_Base::queryInterface( rType );
571 }
572 
573 //________________________________________________________________________________________________________
574 //	XInterface
575 //________________________________________________________________________________________________________
576 
acquire()577 void SAL_CALL SfxBaseModel::acquire() throw( )
578 {
579 	// Attention:
580 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
581 
582 	// Forward to baseclass
583 	OWeakObject::acquire() ;
584 }
585 
586 //________________________________________________________________________________________________________
587 //	XInterface
588 //________________________________________________________________________________________________________
589 
release()590 void SAL_CALL SfxBaseModel::release() throw( )
591 {
592 	// Attention:
593 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
594 
595 	// Forward to baseclass
596 	OWeakObject::release() ;
597 }
598 
599 //________________________________________________________________________________________________________
600 //	XTypeProvider
601 //________________________________________________________________________________________________________
602 
603 namespace
604 {
lcl_stripType(Sequence<Type> & io_rTypes,const Type & i_rTypeToStrip)605     void lcl_stripType( Sequence< Type >& io_rTypes, const Type& i_rTypeToStrip )
606     {
607         Sequence< UNOTYPE > aStrippedTypes( io_rTypes.getLength() - 1 );
608         ::std::remove_copy_if(
609             io_rTypes.getConstArray(),
610             io_rTypes.getConstArray() + io_rTypes.getLength(),
611             aStrippedTypes.getArray(),
612             ::std::bind2nd( ::std::equal_to< Type >(), i_rTypeToStrip )
613         );
614         io_rTypes = aStrippedTypes;
615     }
616 }
617 
getTypes()618 uno::Sequence< UNOTYPE > SAL_CALL SfxBaseModel::getTypes() throw( uno::RuntimeException )
619 {
620     uno::Sequence< UNOTYPE > aTypes( SfxBaseModel_Base::getTypes() );
621 
622     if ( !m_bSupportEmbeddedScripts )
623         lcl_stripType( aTypes, XEMBEDDEDSCRIPTS::static_type() );
624 
625     if ( !m_bSupportDocRecovery )
626         lcl_stripType( aTypes, XDocumentRecovery::static_type() );
627 
628 	return aTypes;
629 }
630 
631 //________________________________________________________________________________________________________
632 //	XTypeProvider
633 //________________________________________________________________________________________________________
634 
getImplementationId()635 uno::Sequence< sal_Int8 > SAL_CALL SfxBaseModel::getImplementationId() throw( uno::RuntimeException )
636 {
637 	// Create one Id for all instances of this class.
638 	// Use ethernet address to do this! (sal_True)
639 
640 	// Optimize this method
641 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
642 	// For the first call; pID is NULL - for the second call pID is different from NULL!
643     static ::cppu::OImplementationId* pID = NULL ;
644 
645 	if ( pID == NULL )
646 	{
647 		// Ready for multithreading; get global mutex for first call of this method only! see before
648         ::osl::MutexGuard aGuard( MUTEX::getGlobalMutex() ) ;
649 
650 		// Control these pointer again ... it can be, that another instance will be faster then these!
651 		if ( pID == NULL )
652 		{
653 			// Create a new static ID ...
654             static ::cppu::OImplementationId aID( sal_False ) ;
655 			// ... and set his address to static pointer!
656 			pID = &aID ;
657 		}
658 	}
659 
660 	return pID->getImplementationId() ;
661 }
662 
663 //________________________________________________________________________________________________________
664 //	XStarBasicAccess
665 //________________________________________________________________________________________________________
666 
implGetStarBasicAccess(SfxObjectShell * pObjectShell)667 uno::Reference< script::XStarBasicAccess > implGetStarBasicAccess( SfxObjectShell* pObjectShell )
668 {
669     uno::Reference< script::XStarBasicAccess > xRet;
670 	if( pObjectShell )
671 	{
672 		BasicManager* pMgr = pObjectShell->GetBasicManager();
673 		xRet = getStarBasicAccess( pMgr );
674 	}
675 	return xRet;
676 }
677 
getLibraryContainer()678 uno::Reference< XNAMECONTAINER > SAL_CALL SfxBaseModel::getLibraryContainer() throw( uno::RuntimeException )
679 {
680     SfxModelGuard aGuard( *this );
681 
682     uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
683 	if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
684 		rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
685 
686     uno::Reference< XNAMECONTAINER > xRet;
687 	if( rxAccess.is() )
688 		xRet = rxAccess->getLibraryContainer();
689 	return xRet;
690 }
691 
692 /**___________________________________________________________________________________________________
693 	@seealso	XStarBasicAccess
694 */
createLibrary(const::rtl::OUString & LibName,const::rtl::OUString & Password,const::rtl::OUString & ExternalSourceURL,const::rtl::OUString & LinkTargetURL)695 void SAL_CALL SfxBaseModel::createLibrary( const ::rtl::OUString& LibName, const ::rtl::OUString& Password,
696     const ::rtl::OUString& ExternalSourceURL, const ::rtl::OUString& LinkTargetURL )
697         throw(ELEMENTEXISTEXCEPTION, uno::RuntimeException)
698 {
699     SfxModelGuard aGuard( *this );
700 
701     uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
702 	if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
703 		rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
704 
705 	if( rxAccess.is() )
706 		rxAccess->createLibrary( LibName, Password, ExternalSourceURL, LinkTargetURL );
707 }
708 
709 /**___________________________________________________________________________________________________
710 	@seealso	XStarBasicAccess
711 */
addModule(const::rtl::OUString & LibraryName,const::rtl::OUString & ModuleName,const::rtl::OUString & Language,const::rtl::OUString & Source)712 void SAL_CALL SfxBaseModel::addModule( const ::rtl::OUString& LibraryName, const ::rtl::OUString& ModuleName,
713     const ::rtl::OUString& Language, const ::rtl::OUString& Source )
714         throw( NOSUCHELEMENTEXCEPTION, uno::RuntimeException)
715 {
716     SfxModelGuard aGuard( *this );
717 
718     uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
719 	if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
720 		rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
721 
722 	if( rxAccess.is() )
723 		rxAccess->addModule( LibraryName, ModuleName, Language, Source );
724 }
725 
726 /**___________________________________________________________________________________________________
727 	@seealso	XStarBasicAccess
728 */
addDialog(const::rtl::OUString & LibraryName,const::rtl::OUString & DialogName,const::com::sun::star::uno::Sequence<sal_Int8> & Data)729 void SAL_CALL SfxBaseModel::addDialog( const ::rtl::OUString& LibraryName, const ::rtl::OUString& DialogName,
730 	const ::com::sun::star::uno::Sequence< sal_Int8 >& Data )
731         throw(NOSUCHELEMENTEXCEPTION, uno::RuntimeException)
732 {
733     SfxModelGuard aGuard( *this );
734 
735     uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
736 	if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
737 		rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
738 
739 	if( rxAccess.is() )
740 		rxAccess->addDialog( LibraryName, DialogName, Data );
741 }
742 
743 
744 //________________________________________________________________________________________________________
745 //	XChild
746 //________________________________________________________________________________________________________
747 
getParent()748 uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getParent() throw( uno::RuntimeException )
749 {
750     SfxModelGuard aGuard( *this );
751 
752 	return m_pData->m_xParent;
753 }
754 
755 //________________________________________________________________________________________________________
756 //	XChild
757 //________________________________________________________________________________________________________
758 
setParent(const uno::Reference<uno::XInterface> & Parent)759 void SAL_CALL SfxBaseModel::setParent(const uno::Reference< uno::XInterface >& Parent) throw(NOSUPPORTEXCEPTION, uno::RuntimeException)
760 {
761     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
762 	m_pData->m_xParent = Parent;
763 }
764 
765 //________________________________________________________________________________________________________
766 //	XChild
767 //________________________________________________________________________________________________________
768 
dispose()769 void SAL_CALL SfxBaseModel::dispose() throw(::com::sun::star::uno::RuntimeException)
770 {
771     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
772 
773 	if  ( !m_pData->m_bClosed )
774 	{
775 		// gracefully accept wrong dispose calls instead of close call
776 		// and try to make it work (may be really disposed later!)
777 		try
778 		{
779 			close( sal_True );
780 		}
781 		catch ( com::sun::star::util::CloseVetoException& )
782 		{
783 		}
784 
785 		return;
786 	}
787 
788 	if ( m_pData->m_pStorageModifyListen.is() )
789 	{
790 		m_pData->m_pStorageModifyListen->dispose();
791 		m_pData->m_pStorageModifyListen = NULL;
792 	}
793 
794     if ( m_pData->m_pDocumentUndoManager.is() )
795 	{
796 		m_pData->m_pDocumentUndoManager->disposing();
797 		m_pData->m_pDocumentUndoManager = NULL;
798 	}
799 
800     lang::EventObject aEvent( (frame::XModel *)this );
801 	m_pData->m_aInterfaceContainer.disposeAndClear( aEvent );
802 
803     if ( m_pData->m_xDocumentInfo.is() )
804     {
805         // as long as an SfxObjectShell is assigned to an SfxBaseModel it is still existing here
806         // so we can't dispose the shared DocumentInfoObject here
807         // uno::Reference < lang::XComponent > xComp( m_pData->m_xDocumentInfo, uno::UNO_QUERY );
808         // xComp->dispose();
809         m_pData->m_xDocumentInfo = 0;
810     }
811 
812     m_pData->m_xDocumentProperties.clear();
813 
814     m_pData->m_xDocumentMetadata.clear();
815 
816     EndListening( *m_pData->m_pObjectShell );
817 
818     m_pData->m_xCurrent = uno::Reference< frame::XController > ();
819     m_pData->m_seqControllers = uno::Sequence< uno::Reference< frame::XController > > () ;
820 
821     // m_pData member must be set to zero before 0delete is called to
822     // force disposed exception whenever someone tries to access our
823     // instance while in the dtor.
824     IMPL_SfxBaseModel_DataContainer* pData = m_pData;
825     m_pData = 0;
826     delete pData;
827 }
828 
829 //________________________________________________________________________________________________________
830 //	XChild
831 //________________________________________________________________________________________________________
832 
addEventListener(const uno::Reference<XEVENTLISTENER> & aListener)833 void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XEVENTLISTENER >& aListener )
834     throw(::com::sun::star::uno::RuntimeException)
835 {
836     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
837     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener );
838 }
839 
840 //________________________________________________________________________________________________________
841 //	XChild
842 //________________________________________________________________________________________________________
843 
removeEventListener(const uno::Reference<XEVENTLISTENER> & aListener)844 void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XEVENTLISTENER >& aListener )
845     throw(::com::sun::star::uno::RuntimeException)
846 {
847     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
848     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener );
849 }
850 
851 //________________________________________________________________________________________________________
852 //  document::XDocumentInfoSupplier
853 //________________________________________________________________________________________________________
854 
getDocumentInfo()855 uno::Reference< document::XDocumentInfo > SAL_CALL SfxBaseModel::getDocumentInfo() throw(::com::sun::star::uno::RuntimeException)
856 {
857     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
858     if ( !m_pData->m_xDocumentInfo.is() )
859     {
860         // WARNING: this will only work if (when loading a document) the
861         // document meta-data has already been read and completely written
862         // into the XDocumentProperties at this point
863         // ==> DO NOT call getDocumentInfo before document info has been read!
864         uno::Reference< document::XDocumentInfo > xDocInfo =
865             new SfxDocumentInfoObject;
866         uno::Reference< document::XDocumentProperties > xDocProps =
867             getDocumentProperties();
868         uno::Sequence< uno::Any > args(1);
869         args[0] <<= xDocProps;
870         uno::Reference< lang::XInitialization > xInit(
871             xDocInfo, uno::UNO_QUERY_THROW);
872         try {
873             xInit->initialize(args);
874             ((SfxBaseModel*)this)->m_pData->m_xDocumentInfo = xDocInfo;
875         } catch (uno::RuntimeException &) {
876             throw;
877         } catch (uno::Exception & e) {
878             throw lang::WrappedTargetRuntimeException(::rtl::OUString::createFromAscii(
879                 "SfxBaseModel::getDocumentInfo: cannot initialize"), *this,
880                 uno::makeAny(e));
881         }
882         try {
883             rtl::OUString aName = rtl::OUString::createFromAscii("MediaType");
884             uno::Reference < beans::XPropertySet > xSet(
885                 getDocumentStorage(), uno::UNO_QUERY );
886             uno::Any aMediaType = xSet->getPropertyValue( aName );
887             uno::Reference < beans::XPropertySet > xDocSet(
888                 m_pData->m_xDocumentInfo, uno::UNO_QUERY );
889             xDocSet->setPropertyValue( aName, aMediaType );
890         } catch (uno::Exception &) {
891             //ignore
892         }
893     }
894 
895 	return m_pData->m_xDocumentInfo;
896 }
897 
898 // document::XDocumentPropertiesSupplier:
899 uno::Reference< document::XDocumentProperties > SAL_CALL
getDocumentProperties()900 SfxBaseModel::getDocumentProperties()
901     throw(::com::sun::star::uno::RuntimeException)
902 {
903     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
904     if ( !m_pData->m_xDocumentProperties.is() )
905     {
906         uno::Reference< lang::XInitialization > xDocProps(
907             ::comphelper::getProcessServiceFactory()->createInstance(
908                 DEFINE_CONST_UNICODE("com.sun.star.document.DocumentProperties") ),
909             uno::UNO_QUERY_THROW);
910 //        xDocProps->initialize(uno::Sequence<uno::Any>());
911         m_pData->m_xDocumentProperties.set(xDocProps, uno::UNO_QUERY_THROW);
912         uno::Reference<util::XModifyBroadcaster> xMB(m_pData->m_xDocumentProperties, uno::UNO_QUERY_THROW);
913         xMB->addModifyListener(new SfxDocInfoListener_Impl(*m_pData->m_pObjectShell));
914     }
915 
916 	return m_pData->m_xDocumentProperties;
917 }
918 
919 
920 //________________________________________________________________________________________________________
921 //	XEVENTLISTENER
922 //________________________________________________________________________________________________________
923 
disposing(const lang::EventObject & aObject)924 void SAL_CALL SfxBaseModel::disposing( const lang::EventObject& aObject )
925     throw(::com::sun::star::uno::RuntimeException)
926 {
927     ::vos::OGuard aGuard( Application::GetSolarMutex() );
928 	if ( impl_isDisposed() )
929 		return;
930 
931     uno::Reference< XMODIFYLISTENER >  xMod( aObject.Source, uno::UNO_QUERY );
932     uno::Reference< XEVENTLISTENER >  xListener( aObject.Source, uno::UNO_QUERY );
933     uno::Reference< XDOCEVENTLISTENER >  xDocListener( aObject.Source, uno::UNO_QUERY );
934 
935     if ( xMod.is() )
936         m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xMod );
937     else if ( xListener.is() )
938         m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), xListener );
939     else if ( xDocListener.is() )
940         m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), xListener );
941 }
942 
943 //________________________________________________________________________________________________________
944 //  frame::XModel
945 //________________________________________________________________________________________________________
946 
attachResource(const::rtl::OUString & rURL,const uno::Sequence<beans::PropertyValue> & rArgs)947 sal_Bool SAL_CALL SfxBaseModel::attachResource( const   ::rtl::OUString&                   rURL    ,
948                                                 const   uno::Sequence< beans::PropertyValue >&  rArgs   )
949     throw(::com::sun::star::uno::RuntimeException)
950 {
951     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
952 	if ( rURL.getLength() == 0 && rArgs.getLength() == 1 && rArgs[0].Name.equalsAscii( "SetEmbedded" ) )
953 	{
954 		// allows to set a windowless document to EMBEDDED state
955 		// but _only_ before load() or initNew() methods
956 		if ( m_pData->m_pObjectShell.Is() && !m_pData->m_pObjectShell->GetMedium() )
957 		{
958 			sal_Bool bEmb = sal_Bool();
959 			if ( ( rArgs[0].Value >>= bEmb ) && bEmb )
960 				m_pData->m_pObjectShell->SetCreateMode_Impl( SFX_CREATE_MODE_EMBEDDED );
961 		}
962 
963 		return sal_True;
964 	}
965 
966 	if ( m_pData->m_pObjectShell.Is() )
967 	{
968 		m_pData->m_sURL = rURL;
969 
970         SfxObjectShell* pObjectShell = m_pData->m_pObjectShell;
971 
972         ::comphelper::NamedValueCollection aArgs( rArgs );
973 
974         Sequence< sal_Int32 > aWinExtent;
975         if ( ( aArgs.get( "WinExtent" ) >>= aWinExtent )&& ( aWinExtent.getLength() == 4 ) )
976         {
977             Rectangle aVisArea( aWinExtent[0], aWinExtent[1], aWinExtent[2], aWinExtent[3] );
978             aVisArea = OutputDevice::LogicToLogic( aVisArea, MAP_100TH_MM, pObjectShell->GetMapUnit() );
979             pObjectShell->SetVisArea( aVisArea );
980         }
981 
982 		sal_Bool bBreakMacroSign = sal_False;
983         if ( aArgs.get( "BreakMacroSignature" ) >>= bBreakMacroSign )
984 		{
985 			pObjectShell->BreakMacroSign_Impl( bBreakMacroSign );
986 		}
987 
988         aArgs.remove( "WinExtent" );
989         aArgs.remove( "BreakMacroSignature" );
990         aArgs.remove( "Stream" );
991         aArgs.remove( "InputStream" );
992         aArgs.remove( "URL" );
993         aArgs.remove( "Frame" );
994         aArgs.remove( "Password" );
995         aArgs.remove( "EncryptionData" );
996 
997 		// TODO/LATER: all the parameters that are accepted by ItemSet of the DocShell must be removed here
998 
999 		m_pData->m_seqArguments = aArgs.getPropertyValues();
1000 
1001         SfxMedium* pMedium = pObjectShell->GetMedium();
1002 		if ( pMedium )
1003 		{
1004 			SfxAllItemSet aSet( pObjectShell->GetPool() );
1005 			TransformParameters( SID_OPENDOC, rArgs, aSet );
1006 
1007             // the arguments are not allowed to reach the medium
1008             aSet.ClearItem( SID_FILE_NAME );
1009             aSet.ClearItem( SID_FILLFRAME );
1010 
1011 			pMedium->GetItemSet()->Put( aSet );
1012 			SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1013 			if ( pItem )
1014 				pMedium->SetFilter(
1015 					pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( pItem->GetValue() ) );
1016 
1017 			SFX_ITEMSET_ARG( &aSet, pTitleItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
1018 			if ( pTitleItem )
1019 			{
1020 				SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjectShell );
1021 				if ( pFrame )
1022 					pFrame->UpdateTitle();
1023 			}
1024 		}
1025 	}
1026 
1027 	return sal_True ;
1028 }
1029 
1030 //________________________________________________________________________________________________________
1031 //  frame::XModel
1032 //________________________________________________________________________________________________________
1033 
getURL()1034 ::rtl::OUString SAL_CALL SfxBaseModel::getURL() throw(::com::sun::star::uno::RuntimeException)
1035 {
1036     SfxModelGuard aGuard( *this );
1037 	return m_pData->m_sURL ;
1038 }
1039 
1040 //________________________________________________________________________________________________________
1041 //  frame::XModel
1042 //________________________________________________________________________________________________________
1043 
getArgs()1044 uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getArgs() throw(::com::sun::star::uno::RuntimeException)
1045 {
1046     SfxModelGuard aGuard( *this );
1047 	if ( m_pData->m_pObjectShell.Is() )
1048 	{
1049         uno::Sequence< beans::PropertyValue > seqArgsNew;
1050         uno::Sequence< beans::PropertyValue > seqArgsOld;
1051 		SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
1052 
1053 		// we need to know which properties are supported by the transformer
1054 		// hopefully it is a temporary solution, I guess nonconvertable properties
1055 		// should not be supported so then there will be only ItemSet from medium
1056 
1057 		TransformItems( SID_OPENDOC, *(m_pData->m_pObjectShell->GetMedium()->GetItemSet()), seqArgsNew );
1058 		TransformParameters( SID_OPENDOC, m_pData->m_seqArguments, aSet );
1059 		TransformItems( SID_OPENDOC, aSet, seqArgsOld );
1060 
1061 		sal_Int32 nOrgLength = m_pData->m_seqArguments.getLength();
1062 		sal_Int32 nOldLength = seqArgsOld.getLength();
1063 		sal_Int32 nNewLength = seqArgsNew.getLength();
1064 
1065 		// "WinExtent" property should be updated always.
1066 		// We can store it now to overwrite an old value
1067 		// since it is not from ItemSet
1068         Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
1069         aTmpRect = OutputDevice::LogicToLogic( aTmpRect, m_pData->m_pObjectShell->GetMapUnit(), MAP_100TH_MM );
1070 
1071         Sequence< sal_Int32 > aRectSeq(4);
1072         aRectSeq[0] = aTmpRect.Left();
1073         aRectSeq[1] = aTmpRect.Top();
1074         aRectSeq[2] = aTmpRect.Right();
1075         aRectSeq[3] = aTmpRect.Bottom();
1076 
1077         seqArgsNew.realloc( ++nNewLength );
1078         seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "WinExtent" );
1079         seqArgsNew[ nNewLength - 1 ].Value <<= aRectSeq;
1080 
1081 		if ( m_pData->m_aPreusedFilterName.getLength() )
1082 		{
1083 			seqArgsNew.realloc( ++nNewLength );
1084 			seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "PreusedFilterName" );
1085 			seqArgsNew[ nNewLength - 1 ].Value <<= m_pData->m_aPreusedFilterName;
1086 		}
1087 
1088         SfxViewFrame* pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
1089         if ( pFrame )
1090         {
1091             SvBorder aBorder = pFrame->GetBorderPixelImpl( pFrame->GetViewShell() );
1092 
1093 			Sequence< sal_Int32 > aBorderSeq(4);
1094             aBorderSeq[0] = aBorder.Left();
1095             aBorderSeq[1] = aBorder.Top();
1096             aBorderSeq[2] = aBorder.Right();
1097             aBorderSeq[3] = aBorder.Bottom();
1098 
1099 			seqArgsNew.realloc( ++nNewLength );
1100             seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "DocumentBorder" );
1101 			seqArgsNew[ nNewLength - 1 ].Value <<= aBorderSeq;
1102 		}
1103 
1104 		// only the values that are not supported by the ItemSet must be cached here
1105 		uno::Sequence< beans::PropertyValue > aFinalCache;
1106 		sal_Int32 nFinalLength = 0;
1107 
1108 		for ( sal_Int32 nOrg = 0; nOrg < nOrgLength; nOrg++ )
1109 		{
1110  			sal_Int32 nOldInd = 0;
1111 			while ( nOldInd < nOldLength )
1112 			{
1113 				if ( m_pData->m_seqArguments[nOrg].Name.equals( seqArgsOld[nOldInd].Name ) )
1114 					break;
1115 				nOldInd++;
1116 			}
1117 
1118 			if ( nOldInd == nOldLength )
1119 			{
1120 				// the entity with this name should be new for seqArgsNew
1121 				// since it is not supported by transformer
1122 
1123 				seqArgsNew.realloc( ++nNewLength );
1124 				seqArgsNew[ nNewLength - 1 ] = m_pData->m_seqArguments[nOrg];
1125 
1126 				aFinalCache.realloc( ++nFinalLength );
1127 				aFinalCache[ nFinalLength - 1 ] = m_pData->m_seqArguments[nOrg];
1128 			}
1129 		}
1130 
1131 		m_pData->m_seqArguments = aFinalCache;
1132 
1133 		return seqArgsNew;
1134 	}
1135 
1136 	return m_pData->m_seqArguments;
1137 }
1138 
1139 //________________________________________________________________________________________________________
1140 //  frame::XModel
1141 //________________________________________________________________________________________________________
1142 
connectController(const uno::Reference<frame::XController> & xController)1143 void SAL_CALL SfxBaseModel::connectController( const uno::Reference< frame::XController >& xController )
1144     throw(::com::sun::star::uno::RuntimeException)
1145 {
1146     SfxModelGuard aGuard( *this );
1147     OSL_PRECOND( xController.is(), "SfxBaseModel::connectController: invalid controller!" );
1148     if ( !xController.is() )
1149         return;
1150 
1151 	sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength();
1152     uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount + 1 );
1153 	for ( sal_uInt32 n = 0; n < nOldCount; n++ )
1154 		aNewSeq.getArray()[n] = m_pData->m_seqControllers.getConstArray()[n];
1155 	aNewSeq.getArray()[nOldCount] = xController;
1156 	m_pData->m_seqControllers = aNewSeq;
1157 
1158     if ( m_pData->m_seqControllers.getLength() == 1 )
1159     {
1160         SfxViewFrame* pViewFrame = SfxViewFrame::Get( xController, GetObjectShell() );
1161         ENSURE_OR_THROW( pViewFrame, "SFX document without SFX view!?" );
1162         pViewFrame->UpdateDocument_Impl();
1163 	    const String sDocumentURL = GetObjectShell()->GetMedium()->GetName();
1164         if ( sDocumentURL.Len() )
1165 	        SFX_APP()->Broadcast( SfxStringHint( SID_OPENURL, sDocumentURL ) );
1166     }
1167 }
1168 
1169 //________________________________________________________________________________________________________
1170 //  frame::XModel
1171 //________________________________________________________________________________________________________
1172 
disconnectController(const uno::Reference<frame::XController> & xController)1173 void SAL_CALL SfxBaseModel::disconnectController( const uno::Reference< frame::XController >& xController ) throw(::com::sun::star::uno::RuntimeException)
1174 {
1175     SfxModelGuard aGuard( *this );
1176 
1177     sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength();
1178     if ( !nOldCount )
1179         return;
1180 
1181     uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount - 1 );
1182 	for ( sal_uInt32 nOld = 0, nNew = 0; nOld < nOldCount; ++nOld )
1183     {
1184 		if ( xController != m_pData->m_seqControllers.getConstArray()[nOld] )
1185 		{
1186 			aNewSeq.getArray()[nNew] = m_pData->m_seqControllers.getConstArray()[nOld];
1187 			++nNew;
1188 		}
1189     }
1190 
1191 	m_pData->m_seqControllers = aNewSeq;
1192 
1193 	if ( xController == m_pData->m_xCurrent )
1194         m_pData->m_xCurrent = uno::Reference< frame::XController > ();
1195 }
1196 
1197 namespace
1198 {
1199     typedef ::cppu::WeakImplHelper1< XUndoAction > ControllerLockUndoAction_Base;
1200     class ControllerLockUndoAction : public ControllerLockUndoAction_Base
1201     {
1202     public:
ControllerLockUndoAction(const Reference<XModel> & i_model,const bool i_undoIsUnlock)1203         ControllerLockUndoAction( const Reference< XModel >& i_model, const bool i_undoIsUnlock )
1204             :m_xModel( i_model )
1205             ,m_bUndoIsUnlock( i_undoIsUnlock )
1206         {
1207         }
1208 
1209         // XUndoAction
1210         virtual ::rtl::OUString SAL_CALL getTitle() throw (RuntimeException);
1211         virtual void SAL_CALL undo(  ) throw (UndoFailedException, RuntimeException);
1212         virtual void SAL_CALL redo(  ) throw (UndoFailedException, RuntimeException);
1213 
1214     private:
1215         const Reference< XModel >   m_xModel;
1216         const bool                  m_bUndoIsUnlock;
1217     };
1218 
getTitle()1219     ::rtl::OUString SAL_CALL ControllerLockUndoAction::getTitle() throw (RuntimeException)
1220     {
1221         // this action is intended to be used within an UndoContext only, so nobody will ever see this title ...
1222         return ::rtl::OUString();
1223     }
1224 
undo()1225     void SAL_CALL ControllerLockUndoAction::undo(  ) throw (UndoFailedException, RuntimeException)
1226     {
1227         if ( m_bUndoIsUnlock )
1228             m_xModel->unlockControllers();
1229         else
1230             m_xModel->lockControllers();
1231     }
1232 
redo()1233     void SAL_CALL ControllerLockUndoAction::redo(  ) throw (UndoFailedException, RuntimeException)
1234     {
1235         if ( m_bUndoIsUnlock )
1236             m_xModel->lockControllers();
1237         else
1238             m_xModel->unlockControllers();
1239     }
1240 }
1241 
1242 //________________________________________________________________________________________________________
1243 //  frame::XModel
1244 //________________________________________________________________________________________________________
1245 
lockControllers()1246 void SAL_CALL SfxBaseModel::lockControllers() throw(::com::sun::star::uno::RuntimeException)
1247 {
1248     SfxModelGuard aGuard( *this );
1249 
1250     ++m_pData->m_nControllerLockCount ;
1251 
1252     if  (   m_pData->m_pDocumentUndoManager.is()
1253         &&  m_pData->m_pDocumentUndoManager->isInContext()
1254         &&  !m_pData->m_pDocumentUndoManager->isLocked()
1255         )
1256     {
1257         m_pData->m_pDocumentUndoManager->addUndoAction( new ControllerLockUndoAction( this, true ) );
1258     }
1259 }
1260 
1261 //________________________________________________________________________________________________________
1262 //  frame::XModel
1263 //________________________________________________________________________________________________________
1264 
unlockControllers()1265 void SAL_CALL SfxBaseModel::unlockControllers() throw(::com::sun::star::uno::RuntimeException)
1266 {
1267     SfxModelGuard aGuard( *this );
1268 
1269     --m_pData->m_nControllerLockCount ;
1270 
1271     if  (   m_pData->m_pDocumentUndoManager.is()
1272         &&  m_pData->m_pDocumentUndoManager->isInContext()
1273         &&  !m_pData->m_pDocumentUndoManager->isLocked()
1274         )
1275     {
1276         m_pData->m_pDocumentUndoManager->addUndoAction( new ControllerLockUndoAction( this, false ) );
1277     }
1278 }
1279 
1280 //________________________________________________________________________________________________________
1281 //  frame::XModel
1282 //________________________________________________________________________________________________________
1283 
hasControllersLocked()1284 sal_Bool SAL_CALL SfxBaseModel::hasControllersLocked() throw(::com::sun::star::uno::RuntimeException)
1285 {
1286     SfxModelGuard aGuard( *this );
1287 	return ( m_pData->m_nControllerLockCount != 0 ) ;
1288 }
1289 
1290 //________________________________________________________________________________________________________
1291 //  frame::XModel
1292 //________________________________________________________________________________________________________
1293 
getCurrentController()1294 uno::Reference< frame::XController > SAL_CALL SfxBaseModel::getCurrentController() throw(::com::sun::star::uno::RuntimeException)
1295 {
1296     SfxModelGuard aGuard( *this );
1297 
1298     // get the last active controller of this model
1299 	if ( m_pData->m_xCurrent.is() )
1300 		return m_pData->m_xCurrent;
1301 
1302 	// get the first controller of this model
1303 	return m_pData->m_seqControllers.getLength() ? m_pData->m_seqControllers.getConstArray()[0] : m_pData->m_xCurrent;
1304 }
1305 
1306 //________________________________________________________________________________________________________
1307 //  frame::XModel
1308 //________________________________________________________________________________________________________
1309 
setCurrentController(const uno::Reference<frame::XController> & xCurrentController)1310 void SAL_CALL SfxBaseModel::setCurrentController( const uno::Reference< frame::XController >& xCurrentController )
1311         throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
1312 {
1313     SfxModelGuard aGuard( *this );
1314 
1315 	m_pData->m_xCurrent = xCurrentController;
1316 }
1317 
1318 //________________________________________________________________________________________________________
1319 //  frame::XModel
1320 //________________________________________________________________________________________________________
1321 
getCurrentSelection()1322 uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getCurrentSelection() throw(::com::sun::star::uno::RuntimeException)
1323 {
1324     SfxModelGuard aGuard( *this );
1325 
1326     uno::Reference< uno::XInterface >     xReturn;
1327     uno::Reference< frame::XController >    xController =   getCurrentController()      ;
1328 
1329 	if ( xController.is() )
1330 	{
1331         uno::Reference< view::XSelectionSupplier >  xDocView( xController, uno::UNO_QUERY );
1332 		if ( xDocView.is() )
1333 		{
1334             uno::Any xSel = xDocView->getSelection();
1335 			xSel >>= xReturn ;
1336 		}
1337 	}
1338 
1339 	return xReturn ;
1340 }
1341 
1342 //________________________________________________________________________________________________________
1343 //	XModifiable2
1344 //________________________________________________________________________________________________________
1345 
disableSetModified()1346 sal_Bool SAL_CALL SfxBaseModel::disableSetModified() throw (::com::sun::star::uno::RuntimeException)
1347 {
1348     SfxModelGuard aGuard( *this );
1349 
1350 	if ( !m_pData->m_pObjectShell.Is() )
1351 		throw uno::RuntimeException();
1352 
1353 	sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified();
1354 	m_pData->m_pObjectShell->EnableSetModified( sal_False );
1355 
1356 	return bResult;
1357 }
1358 
enableSetModified()1359 sal_Bool SAL_CALL SfxBaseModel::enableSetModified() throw (::com::sun::star::uno::RuntimeException)
1360 {
1361     SfxModelGuard aGuard( *this );
1362 
1363 	if ( !m_pData->m_pObjectShell.Is() )
1364 		throw uno::RuntimeException();
1365 
1366 	sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified();
1367 	m_pData->m_pObjectShell->EnableSetModified( sal_True );
1368 
1369 	return bResult;
1370 }
1371 
isSetModifiedEnabled()1372 sal_Bool SAL_CALL SfxBaseModel::isSetModifiedEnabled() throw (::com::sun::star::uno::RuntimeException)
1373 {
1374     SfxModelGuard aGuard( *this );
1375 
1376 	if ( !m_pData->m_pObjectShell.Is() )
1377 		throw uno::RuntimeException();
1378 
1379 	return m_pData->m_pObjectShell->IsEnableSetModified();
1380 }
1381 
1382 //________________________________________________________________________________________________________
1383 //	XModifiable
1384 //________________________________________________________________________________________________________
1385 
isModified()1386 sal_Bool SAL_CALL SfxBaseModel::isModified() throw(::com::sun::star::uno::RuntimeException)
1387 {
1388     SfxModelGuard aGuard( *this );
1389 
1390 	return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsModified() : sal_False;
1391 }
1392 
1393 //________________________________________________________________________________________________________
1394 //	XModifiable
1395 //________________________________________________________________________________________________________
1396 
setModified(sal_Bool bModified)1397 void SAL_CALL SfxBaseModel::setModified( sal_Bool bModified )
1398         throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException)
1399 {
1400     SfxModelGuard aGuard( *this );
1401 
1402 	if ( m_pData->m_pObjectShell.Is() )
1403 		m_pData->m_pObjectShell->SetModified(bModified);
1404 }
1405 
1406 //________________________________________________________________________________________________________
1407 //	XModifiable
1408 //________________________________________________________________________________________________________
1409 
addModifyListener(const uno::Reference<XMODIFYLISTENER> & xListener)1410 void SAL_CALL SfxBaseModel::addModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException )
1411 {
1412     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1413 
1414     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0),xListener );
1415 }
1416 
1417 //________________________________________________________________________________________________________
1418 //	XModifiable
1419 //________________________________________________________________________________________________________
1420 
removeModifyListener(const uno::Reference<XMODIFYLISTENER> & xListener)1421 void SAL_CALL SfxBaseModel::removeModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException )
1422 {
1423     SfxModelGuard aGuard( *this );
1424 
1425     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xListener );
1426 }
1427 
1428 //____________________________________________________________________________________________________
1429 //  XCloseable
1430 //____________________________________________________________________________________________________
1431 
close(sal_Bool bDeliverOwnership)1432 void SAL_CALL SfxBaseModel::close( sal_Bool bDeliverOwnership ) throw (util::CloseVetoException, uno::RuntimeException)
1433 {
1434     static ::rtl::OUString MSG_1 = ::rtl::OUString::createFromAscii("Cant close while saving.");
1435 
1436     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1437 	if ( impl_isDisposed() || m_pData->m_bClosed || m_pData->m_bClosing )
1438 		return;
1439 
1440     uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
1441     lang::EventObject             aSource    (static_cast< ::cppu::OWeakObject*>(this));
1442     ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
1443     if (pContainer!=NULL)
1444 	{
1445         ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
1446         while (pIterator.hasMoreElements())
1447         {
1448             try
1449             {
1450                 ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership );
1451             }
1452             catch( uno::RuntimeException& )
1453             {
1454                 pIterator.remove();
1455             }
1456         }
1457 	}
1458 
1459     if ( m_pData->m_bSaving )
1460     {
1461         if (bDeliverOwnership)
1462             m_pData->m_bSuicide = sal_True;
1463         throw util::CloseVetoException(
1464                 MSG_1,
1465                 static_cast< ::com::sun::star::util::XCloseable* >(this));
1466     }
1467 
1468 	// no own objections against closing!
1469 	m_pData->m_bClosing = sal_True;
1470     pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
1471     if (pContainer!=NULL)
1472 	{
1473         ::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer);
1474         while (pCloseIterator.hasMoreElements())
1475         {
1476             try
1477             {
1478                 ((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource );
1479             }
1480             catch( uno::RuntimeException& )
1481             {
1482                 pCloseIterator.remove();
1483             }
1484         }
1485 	}
1486 
1487 	m_pData->m_bClosed = sal_True;
1488 	m_pData->m_bClosing = sal_False;
1489 
1490     dispose();
1491 }
1492 
1493 //____________________________________________________________________________________________________
1494 //  XCloseBroadcaster
1495 //____________________________________________________________________________________________________
1496 
addCloseListener(const uno::Reference<XCLOSELISTENER> & xListener)1497 void SAL_CALL SfxBaseModel::addCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException)
1498 {
1499     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1500 
1501     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener );
1502 }
1503 
1504 //____________________________________________________________________________________________________
1505 //  XCloseBroadcaster
1506 //____________________________________________________________________________________________________
1507 
removeCloseListener(const uno::Reference<XCLOSELISTENER> & xListener)1508 void SAL_CALL SfxBaseModel::removeCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException)
1509 {
1510     SfxModelGuard aGuard( *this );
1511 
1512     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener );
1513 }
1514 
1515 //________________________________________________________________________________________________________
1516 //	XPrintable
1517 //________________________________________________________________________________________________________
1518 
getPrinter()1519 uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getPrinter() throw(::com::sun::star::uno::RuntimeException)
1520 {
1521     SfxModelGuard aGuard( *this );
1522 
1523     if ( impl_getPrintHelper() )
1524         return m_pData->m_xPrintable->getPrinter();
1525     else
1526         return uno::Sequence< beans::PropertyValue >();
1527 }
1528 
setPrinter(const uno::Sequence<beans::PropertyValue> & rPrinter)1529 void SAL_CALL SfxBaseModel::setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter)
1530         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1531 {
1532     SfxModelGuard aGuard( *this );
1533 
1534     if ( impl_getPrintHelper() )
1535         m_pData->m_xPrintable->setPrinter( rPrinter );
1536 }
1537 
print(const uno::Sequence<beans::PropertyValue> & rOptions)1538 void SAL_CALL SfxBaseModel::print(const uno::Sequence< beans::PropertyValue >& rOptions)
1539         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1540 {
1541     SfxModelGuard aGuard( *this );
1542 
1543     if ( impl_getPrintHelper() )
1544         m_pData->m_xPrintable->print( rOptions );
1545 }
1546 
1547 //________________________________________________________________________________________________________
1548 //	XStorable
1549 //________________________________________________________________________________________________________
1550 
hasLocation()1551 sal_Bool SAL_CALL SfxBaseModel::hasLocation() throw(::com::sun::star::uno::RuntimeException)
1552 {
1553     SfxModelGuard aGuard( *this );
1554 
1555 	return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->HasName() : sal_False;
1556 }
1557 
1558 //________________________________________________________________________________________________________
1559 //	XStorable
1560 //________________________________________________________________________________________________________
1561 
getLocation()1562 ::rtl::OUString SAL_CALL SfxBaseModel::getLocation() throw(::com::sun::star::uno::RuntimeException)
1563 {
1564     SfxModelGuard aGuard( *this );
1565 
1566     if ( m_pData->m_pObjectShell.Is() )
1567     {
1568         // TODO/LATER: is it correct that the shared document returns shared file location?
1569         if ( m_pData->m_pObjectShell->IsDocShared() )
1570             return m_pData->m_pObjectShell->GetSharedFileURL();
1571         else
1572             return ::rtl::OUString(m_pData->m_pObjectShell->GetMedium()->GetName());
1573     }
1574 
1575     return m_pData->m_sURL;
1576 }
1577 
1578 //________________________________________________________________________________________________________
1579 //	XStorable
1580 //________________________________________________________________________________________________________
1581 
isReadonly()1582 sal_Bool SAL_CALL SfxBaseModel::isReadonly() throw(::com::sun::star::uno::RuntimeException)
1583 {
1584     SfxModelGuard aGuard( *this );
1585 
1586 	return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsReadOnly() : sal_True;
1587 }
1588 
1589 //________________________________________________________________________________________________________
1590 //	XStorable2
1591 //________________________________________________________________________________________________________
1592 
storeSelf(const uno::Sequence<beans::PropertyValue> & aSeqArgs)1593 void SAL_CALL SfxBaseModel::storeSelf( const    uno::Sequence< beans::PropertyValue >&  aSeqArgs )
1594 		throw ( ::com::sun::star::lang::IllegalArgumentException,
1595 				::com::sun::star::io::IOException,
1596 				::com::sun::star::uno::RuntimeException )
1597 {
1598 	RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeSelf" );
1599 
1600     SfxModelGuard aGuard( *this );
1601 
1602 	if ( m_pData->m_pObjectShell.Is() )
1603     {
1604         m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeSelf" ) ) );
1605 		SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1606 
1607 		for ( sal_Int32 nInd = 0; nInd < aSeqArgs.getLength(); nInd++ )
1608 		{
1609 			// check that only acceptable parameters are provided here
1610 			if ( !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VersionComment" ) ) )
1611 			  && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Author" ) ) )
1612 			  && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) ) )
1613 			  && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ) )
1614 			  && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FailOnWarning" ) ) ) )
1615 			{
1616                 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected parameter for storeSelf, might be no problem if SaveAs is executed." ) ) );
1617                 m_pData->m_pObjectShell->StoreLog();
1618 
1619 				::rtl::OUString aMessage( RTL_CONSTASCII_USTRINGPARAM( "Unexpected MediaDescriptor parameter: " ) );
1620 				aMessage += aSeqArgs[nInd].Name;
1621 				throw lang::IllegalArgumentException( aMessage, uno::Reference< uno::XInterface >(), 1 );
1622 			}
1623 		}
1624 
1625     	SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() );
1626     	TransformParameters( SID_SAVEDOC, aSeqArgs, *pParams );
1627 
1628 		SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOC, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOC), m_pData->m_pObjectShell ) );
1629 
1630 		sal_Bool bRet = sal_False;
1631 
1632 		// TODO/LATER: let the embedded case of saving be handled more careful
1633 		if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1634 		{
1635 			// If this is an embedded object that has no URL based location it should be stored to own storage.
1636 			// An embedded object can have a location based on URL in case it is a link, then it should be
1637 			// stored in normal way.
1638 			if ( !hasLocation() || getLocation().compareToAscii( "private:", 8 ) == 0 )
1639 			{
1640 				// actually in this very rare case only UI parameters have sence
1641 				// TODO/LATER: should be done later, after integration of sb19
1642                 bRet = m_pData->m_pObjectShell->DoSave()
1643                     && m_pData->m_pObjectShell->DoSaveCompleted();
1644 			}
1645 			else
1646 			{
1647 				bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
1648 			}
1649 		}
1650 		else
1651 			bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
1652 
1653 		DELETEZ( pParams );
1654 
1655 		sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ? m_pData->m_pObjectShell->GetError()
1656 																	: ERRCODE_IO_CANTWRITE;
1657 		m_pData->m_pObjectShell->ResetError();
1658 
1659 		if ( bRet )
1660 		{
1661             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "successful saving." ) ) );
1662 			m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
1663 
1664 			SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCDONE), m_pData->m_pObjectShell ) );
1665 		}
1666 		else
1667 		{
1668             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
1669             m_pData->m_pObjectShell->StoreLog();
1670 
1671             // write the contents of the logger to the file
1672 			SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCFAILED, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCFAILED), m_pData->m_pObjectShell ) );
1673 
1674 			throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
1675 		}
1676     }
1677 
1678 }
1679 
1680 //________________________________________________________________________________________________________
1681 //	XStorable
1682 //________________________________________________________________________________________________________
1683 
store()1684 void SAL_CALL SfxBaseModel::store() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1685 {
1686 	storeSelf( uno::Sequence< beans::PropertyValue >() );
1687 }
1688 
1689 //________________________________________________________________________________________________________
1690 //	XStorable
1691 //________________________________________________________________________________________________________
1692 
storeAsURL(const::rtl::OUString & rURL,const uno::Sequence<beans::PropertyValue> & rArgs)1693 void SAL_CALL SfxBaseModel::storeAsURL( const   ::rtl::OUString&                   rURL    ,
1694                                         const   uno::Sequence< beans::PropertyValue >&  rArgs   )
1695         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1696 {
1697 	RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeAsURL" );
1698 
1699     SfxModelGuard aGuard( *this );
1700 
1701 	if ( m_pData->m_pObjectShell.Is() )
1702 	{
1703         m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeAsURL" ) ) );
1704 		SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1705 
1706 		impl_store( rURL, rArgs, sal_False );
1707 
1708         uno::Sequence< beans::PropertyValue > aSequence ;
1709 		TransformItems( SID_OPENDOC, *m_pData->m_pObjectShell->GetMedium()->GetItemSet(), aSequence );
1710 		attachResource( rURL, aSequence );
1711 
1712 #if OSL_DEBUG_LEVEL > 0
1713 		SFX_ITEMSET_ARG( m_pData->m_pObjectShell->GetMedium()->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
1714         OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
1715 #endif
1716 	}
1717 }
1718 
1719 //________________________________________________________________________________________________________
1720 //	XUndoManagerSupplier
1721 //________________________________________________________________________________________________________
getUndoManager()1722 Reference< XUndoManager > SAL_CALL SfxBaseModel::getUndoManager(  ) throw (RuntimeException)
1723 {
1724     SfxModelGuard aGuard( *this );
1725     if ( !m_pData->m_pDocumentUndoManager.is() )
1726         m_pData->m_pDocumentUndoManager.set( new ::sfx2::DocumentUndoManager( *this ) );
1727     return m_pData->m_pDocumentUndoManager.get();
1728 }
1729 
1730 //________________________________________________________________________________________________________
1731 //	XStorable
1732 //________________________________________________________________________________________________________
1733 
storeToURL(const::rtl::OUString & rURL,const uno::Sequence<beans::PropertyValue> & rArgs)1734 void SAL_CALL SfxBaseModel::storeToURL( const   ::rtl::OUString&                   rURL    ,
1735                                         const   uno::Sequence< beans::PropertyValue >&  rArgs   )
1736         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1737 {
1738     SfxModelGuard aGuard( *this );
1739 
1740 	if ( m_pData->m_pObjectShell.Is() )
1741     {
1742         m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeToURL" ) ) );
1743 		SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
1744 		impl_store( rURL, rArgs, sal_True );
1745     }
1746 }
1747 
wasModifiedSinceLastSave()1748 ::sal_Bool SAL_CALL SfxBaseModel::wasModifiedSinceLastSave() throw ( RuntimeException )
1749 {
1750     SfxModelGuard aGuard( *this );
1751     return m_pData->m_bModifiedSinceLastSave;
1752 }
1753 
storeToRecoveryFile(const::rtl::OUString & i_TargetLocation,const Sequence<PropertyValue> & i_MediaDescriptor)1754 void SAL_CALL SfxBaseModel::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
1755 {
1756     SfxModelGuard aGuard( *this );
1757 
1758     // delegate
1759 	SfxSaveGuard aSaveGuard( this, m_pData, sal_False );
1760 	impl_store( i_TargetLocation, i_MediaDescriptor, sal_True );
1761 
1762     // no need for subsequent calls to storeToRecoveryFile, unless we're modified, again
1763     m_pData->m_bModifiedSinceLastSave = sal_False;
1764 }
1765 
recoverFromFile(const::rtl::OUString & i_SourceLocation,const::rtl::OUString & i_SalvagedFile,const Sequence<PropertyValue> & i_MediaDescriptor)1766 void SAL_CALL SfxBaseModel::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
1767 {
1768     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1769 
1770     // delegate to our "load" method
1771     ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor );
1772 
1773     // our load implementation expects the SalvagedFile to be in the media descriptor
1774     OSL_ENSURE( !aMediaDescriptor.has( "SalvagedFile" ) || ( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) == i_SalvagedFile ),
1775         "SfxBaseModel::recoverFromFile: inconsistent information!" );
1776     aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile );
1777 
1778     // similar for the to-be-loaded file
1779     OSL_ENSURE( !aMediaDescriptor.has( "URL" ) || ( aMediaDescriptor.getOrDefault( "URL", ::rtl::OUString() ) == i_SourceLocation ),
1780         "SfxBaseModel::recoverFromFile: inconsistent information!" );
1781     aMediaDescriptor.put( "URL", i_SourceLocation );
1782 
1783     load( aMediaDescriptor.getPropertyValues() );
1784 
1785     // Note: The XDocumentRecovery interface specification requires us to do an attachResource after loading.
1786     // However, we will not do this here, as we know that our load implementation (respectively some method
1787     // called from there) already did so.
1788     // In particular, the load process might already have modified some elements of the media
1789     // descriptor, for instance the MacroExecMode (in case the user was involved to decide about it), and we do
1790     // not want to overwrite it with the "old" elements passed to this method here.
1791 }
1792 
1793 //________________________________________________________________________________________________________
1794 // XLoadable
1795 //________________________________________________________________________________________________________
1796 
initNew()1797 void SAL_CALL SfxBaseModel::initNew()
1798 		throw (::com::sun::star::frame::DoubleInitializationException,
1799 			   ::com::sun::star::io::IOException,
1800 			   ::com::sun::star::uno::RuntimeException,
1801 			   ::com::sun::star::uno::Exception)
1802 {
1803     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1804     if ( IsInitialized() )
1805         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
1806 
1807 	// the object shell should exist always
1808 	DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
1809 	if ( m_pData->m_pObjectShell.Is() )
1810 	{
1811 		if( m_pData->m_pObjectShell->GetMedium() )
1812 			throw DOUBLEINITIALIZATIONEXCEPTION();
1813 
1814 		sal_Bool bRes = m_pData->m_pObjectShell->DoInitNew( NULL );
1815 		sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ?
1816 									m_pData->m_pObjectShell->GetError() : ERRCODE_IO_CANTCREATE;
1817 		m_pData->m_pObjectShell->ResetError();
1818 
1819 		if ( !bRes )
1820 			throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
1821 	}
1822 }
1823 
1824 //________________________________________________________________________________________________________
1825 // XLoadable
1826 //________________________________________________________________________________________________________
1827 
load(const uno::Sequence<beans::PropertyValue> & seqArguments)1828 void SAL_CALL SfxBaseModel::load(   const uno::Sequence< beans::PropertyValue >& seqArguments )
1829 		throw (::com::sun::star::frame::DoubleInitializationException,
1830                ::com::sun::star::io::IOException,
1831 			   ::com::sun::star::uno::RuntimeException,
1832 			   ::com::sun::star::uno::Exception)
1833 {
1834     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
1835     if ( IsInitialized() )
1836         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
1837 
1838 	// the object shell should exist always
1839 	DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
1840 
1841 	if ( m_pData->m_pObjectShell.Is() )
1842 	{
1843 		if( m_pData->m_pObjectShell->GetMedium() )
1844 			// if a Medium is present, the document is already initialized
1845 			throw DOUBLEINITIALIZATIONEXCEPTION();
1846 
1847         SfxMedium* pMedium = new SfxMedium( seqArguments );
1848         String aFilterName;
1849         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1850 		if( pFilterNameItem )
1851 			aFilterName = pFilterNameItem->GetValue();
1852 		if( !m_pData->m_pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) )
1853 		{
1854 			// filtername is not valid
1855             delete pMedium;
1856             throw frame::IllegalArgumentIOException();
1857 		}
1858 
1859 		// !TODO: currently not working
1860 		//SFX_ITEMSET_ARG( pParams, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False );
1861 		//if( pFrameItem && pFrameItem->GetFrame() )
1862 		//{
1863 		//	SfxFrame* pFrame = pFrameItem->GetFrame();
1864 		//	pMedium->SetLoadTargetFrame( pFrame );
1865 		//}
1866 
1867         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1868         sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
1869 
1870         // SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
1871         // sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
1872         //
1873         // does already happen in DoLoad call
1874         //m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
1875 
1876 		// load document
1877 		sal_uInt32 nError = ERRCODE_NONE;
1878 		if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
1879 			nError=ERRCODE_IO_GENERAL;
1880 
1881         // QUESTION: if the following happens outside of DoLoad, something important is missing there!
1882 		::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler = pMedium->GetInteractionHandler();
1883 		if( m_pData->m_pObjectShell->GetErrorCode() )
1884 		{
1885 			nError = m_pData->m_pObjectShell->GetErrorCode();
1886 			if ( nError == ERRCODE_IO_BROKENPACKAGE && xHandler.is() )
1887 			{
1888         		::rtl::OUString aDocName = pMedium->GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1889                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
1890     			if ( !pRepairItem || !pRepairItem->GetValue() )
1891 				{
1892                     RequestPackageReparation aRequest( aDocName );
1893                     xHandler->handle( aRequest.GetRequest() );
1894                     if( aRequest.isApproved() )
1895 					{
1896 						// broken package: try second loading and allow repair
1897     					pMedium->GetItemSet()->Put( SfxBoolItem( SID_REPAIRPACKAGE, sal_True ) );
1898                 		pMedium->GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
1899 						pMedium->GetItemSet()->Put( SfxStringItem( SID_DOCINFO_TITLE, aDocName ) );
1900 
1901 						// the error must be reset and the storage must be reopened in new mode
1902 						pMedium->ResetError();
1903 						pMedium->CloseStorage();
1904 						m_pData->m_pObjectShell->PrepareSecondTryLoad_Impl();
1905 						if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
1906 							nError=ERRCODE_IO_GENERAL;
1907 						nError = m_pData->m_pObjectShell->GetErrorCode();
1908 					}
1909 				}
1910 
1911 				if ( nError == ERRCODE_IO_BROKENPACKAGE )
1912 				{
1913 					// repair either not allowed or not successful
1914                     NotifyBrokenPackage aRequest( aDocName );
1915                     xHandler->handle( aRequest.GetRequest() );
1916 				}
1917 			}
1918 		}
1919 
1920 		if( m_pData->m_pObjectShell->IsAbortingImport() )
1921 			nError = ERRCODE_ABORT;
1922 
1923         if( bSalvage )
1924         {
1925             // file recovery: restore original filter
1926             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1927             SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
1928             const SfxFilter* pSetFilter = rMatcher.GetFilter4FilterName( pFilterItem->GetValue() );
1929             pMedium->SetFilter( pSetFilter );
1930             m_pData->m_pObjectShell->SetModified(sal_True);
1931         }
1932 
1933         // TODO/LATER: may be the mode should be retrieved from outside and the preused filter should not be set
1934         if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1935         {
1936             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
1937             if ( pFilterItem )
1938                 m_pData->m_aPreusedFilterName = pFilterItem->GetValue();
1939         }
1940 
1941         if ( !nError )
1942             nError = pMedium->GetError();
1943 
1944         m_pData->m_pObjectShell->ResetError();
1945 
1946     	if ( nError )
1947 		{
1948 			sal_Bool bSilent = sal_False;
1949 			SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
1950 			if( pSilentItem )
1951 				bSilent = pSilentItem->GetValue();
1952 
1953           	sal_Bool bWarning = ((nError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK);
1954         	if ( nError != ERRCODE_IO_BROKENPACKAGE && !bSilent )
1955         	{
1956 				// broken package was handled already
1957             	if ( SfxObjectShell::UseInteractionToHandleError( xHandler, nError ) && !bWarning )
1958 				{
1959 					// abort loading (except for warnings)
1960                    	nError = ERRCODE_IO_ABORT;
1961             	}
1962         	}
1963 
1964 			if ( m_pData->m_pObjectShell->GetMedium() != pMedium )
1965 			{
1966 				// for whatever reason document now has another medium
1967 				DBG_ERROR("Document has rejected the medium?!");
1968 				delete pMedium;
1969 			}
1970 
1971             if ( !bWarning )    // #i30711# don't abort loading if it's only a warning
1972             {
1973                 throw task::ErrorCodeIOException( ::rtl::OUString(),
1974                                                     uno::Reference< uno::XInterface >(),
1975                                                     nError ? nError : ERRCODE_IO_CANTREAD );
1976             }
1977 		}
1978 
1979 		sal_Bool bHidden = sal_False;
1980 		SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False);
1981 		if ( pHidItem )
1982 			bHidden = pHidItem->GetValue();
1983 
1984 #if OSL_DEBUG_LEVEL > 0
1985 		SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
1986         OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
1987 #endif
1988 		// !TODO: will be done by Framework!
1989     	pMedium->SetUpdatePickList( !bHidden );
1990 	}
1991 }
1992 
1993 //________________________________________________________________________________________________________
1994 // XTransferable
1995 //________________________________________________________________________________________________________
1996 
getTransferData(const DATAFLAVOR & aFlavor)1997 uno::Any SAL_CALL SfxBaseModel::getTransferData( const DATAFLAVOR& aFlavor )
1998 		throw (::com::sun::star::datatransfer::UnsupportedFlavorException,
1999 			   ::com::sun::star::io::IOException,
2000 			   ::com::sun::star::uno::RuntimeException)
2001 {
2002     SfxModelGuard aGuard( *this );
2003 
2004     uno::Any aAny;
2005 
2006 	if ( m_pData->m_pObjectShell.Is() )
2007 	{
2008         if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
2009 		{
2010 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2011 			{
2012                 TransferableObjectDescriptor aDesc;
2013 
2014                 aDesc.maClassName = m_pData->m_pObjectShell->GetClassName();
2015                 aDesc.maTypeName = aFlavor.HumanPresentableName;
2016 
2017                 // TODO/LATER: ViewAspect needs to be sal_Int64
2018                 aDesc.mnViewAspect = sal::static_int_cast< sal_uInt16 >( embed::Aspects::MSOLE_CONTENT );
2019 
2020                 //TODO/LATER: status needs to become sal_Int64
2021                 aDesc.mnOle2Misc = m_pData->m_pObjectShell->GetMiscStatus();
2022                 Size aSize = m_pData->m_pObjectShell->GetVisArea().GetSize();
2023 
2024                 MapUnit aMapUnit = m_pData->m_pObjectShell->GetMapUnit();
2025                 aDesc.maSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
2026                 aDesc.maDragStartPos = Point();
2027                 aDesc.maDisplayName = String();
2028                 aDesc.mbCanLink = sal_False;
2029 
2030                 SvMemoryStream aMemStm( 1024, 1024 );
2031                 aMemStm << aDesc;
2032                 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() );
2033 			}
2034 			else
2035                 throw datatransfer::UnsupportedFlavorException();
2036 		}
2037         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
2038 		{
2039 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2040 			{
2041                 try
2042                 {
2043                     utl::TempFile aTmp;
2044                     aTmp.EnableKillingFile( sal_True );
2045                     storeToURL( aTmp.GetURL(), uno::Sequence < beans::PropertyValue >() );
2046                     SvStream* pStream = aTmp.GetStream( STREAM_READ );
2047                     const sal_uInt32 nLen = pStream->Seek( STREAM_SEEK_TO_END );
2048                     ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
2049                     pStream->Seek( STREAM_SEEK_TO_BEGIN );
2050                     pStream->Read( aSeq.getArray(),  nLen );
2051                     delete pStream;
2052                     if( aSeq.getLength() )
2053                         aAny <<= aSeq;
2054                 }
2055                 catch ( uno::Exception& )
2056                 {
2057                 }
2058 			}
2059 			else
2060                 throw datatransfer::UnsupportedFlavorException();
2061 		}
2062         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2063 		{
2064 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2065 			{
2066 
2067                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2068                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2069 
2070 				if ( pMetaFile )
2071 				{
2072 					SvMemoryStream aMemStm( 65535, 65535 );
2073                     aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2074 
2075 					pMetaFile->Write( aMemStm );
2076 					aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
2077 													aMemStm.Seek( STREAM_SEEK_TO_END ) );
2078 				}
2079 			}
2080 			else
2081                 throw datatransfer::UnsupportedFlavorException();
2082 		}
2083         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2084 		{
2085 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2086 			{
2087                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2088                     m_pData->m_pObjectShell->CreatePreviewMetaFile_Impl( sal_True, sal_True );
2089 
2090 				if ( pMetaFile )
2091 				{
2092 					SvMemoryStream aMemStm( 65535, 65535 );
2093                     aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2094 
2095 					pMetaFile->Write( aMemStm );
2096 					aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
2097 													aMemStm.Seek( STREAM_SEEK_TO_END ) );
2098 				}
2099 			}
2100 			else
2101                 throw datatransfer::UnsupportedFlavorException();
2102 		}
2103         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2104 		{
2105 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2106 			{
2107                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2108                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2109 
2110 				if ( pMetaFile )
2111 				{
2112                     ::boost::shared_ptr<SvMemoryStream> pStream(
2113                         GraphicHelper::getFormatStrFromGDI_Impl(
2114                             pMetaFile.get(), CVT_EMF ) );
2115 					if ( pStream )
2116 					{
2117                     	pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2118 						aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2119 														pStream->Seek( STREAM_SEEK_TO_END ) );
2120 					}
2121 				}
2122 			}
2123 			else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2124 			  && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2125 			{
2126                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2127                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2128 
2129 				if ( pMetaFile )
2130 				{
2131 					aAny <<= reinterpret_cast< const sal_uInt64 >(
2132                         GraphicHelper::getEnhMetaFileFromGDI_Impl( pMetaFile.get() ) );
2133 				}
2134 			}
2135 			else
2136                 throw datatransfer::UnsupportedFlavorException();
2137 		}
2138         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2139 		{
2140 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2141 			{
2142                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2143                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2144 
2145 				if ( pMetaFile )
2146 				{
2147                     ::boost::shared_ptr<SvMemoryStream> pStream(
2148                         GraphicHelper::getFormatStrFromGDI_Impl(
2149                             pMetaFile.get(), CVT_WMF ) );
2150 
2151 					if ( pStream )
2152 					{
2153                     	pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2154 						aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2155 														pStream->Seek( STREAM_SEEK_TO_END ) );
2156 					}
2157 				}
2158 			}
2159 			else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2160 			  && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2161 			{
2162 				// means HGLOBAL handler to memory storage containing METAFILEPICT structure
2163 
2164                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2165                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2166 
2167 				if ( pMetaFile )
2168 				{
2169 					Size aMetaSize = pMetaFile->GetPrefSize();
2170 					aAny <<= reinterpret_cast< const sal_uInt64 >(
2171                         GraphicHelper::getWinMetaFileFromGDI_Impl(
2172                             pMetaFile.get(), aMetaSize ) );
2173 				}
2174 			}
2175 			else
2176                 throw datatransfer::UnsupportedFlavorException();
2177 		}
2178         else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2179 		{
2180 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2181 			{
2182                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2183                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2184 
2185 				if ( pMetaFile )
2186 				{
2187                     ::boost::shared_ptr<SvMemoryStream> pStream(
2188                         GraphicHelper::getFormatStrFromGDI_Impl(
2189                             pMetaFile.get(), CVT_BMP ) );
2190 
2191 					if ( pStream )
2192 					{
2193                     	pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2194 						aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2195 														pStream->Seek( STREAM_SEEK_TO_END ) );
2196 					}
2197 				}
2198 			}
2199 			else
2200                 throw datatransfer::UnsupportedFlavorException();
2201 		}
2202 		else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
2203 		{
2204 			if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2205 			{
2206                 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2207                     m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2208 
2209 				if ( pMetaFile )
2210 				{
2211                     ::boost::shared_ptr<SvMemoryStream> pStream(
2212                         GraphicHelper::getFormatStrFromGDI_Impl(
2213                             pMetaFile.get(), CVT_PNG ) );
2214 
2215 					if ( pStream )
2216 					{
2217                     	pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2218 						aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2219 														pStream->Seek( STREAM_SEEK_TO_END ) );
2220 					}
2221 				}
2222 			}
2223 			else
2224                 throw datatransfer::UnsupportedFlavorException();
2225 		}
2226         else
2227             throw datatransfer::UnsupportedFlavorException();
2228 	}
2229 
2230 	return aAny;
2231 }
2232 
2233 //________________________________________________________________________________________________________
2234 // XTransferable
2235 //________________________________________________________________________________________________________
2236 
2237 
getTransferDataFlavors()2238 uno::Sequence< DATAFLAVOR > SAL_CALL SfxBaseModel::getTransferDataFlavors()
2239 		throw (::com::sun::star::uno::RuntimeException)
2240 {
2241     SfxModelGuard aGuard( *this );
2242 
2243     sal_Int32 nSuppFlavors = GraphicHelper::supportsMetaFileHandle_Impl() ? 10 : 8;
2244     uno::Sequence< DATAFLAVOR > aFlavorSeq( nSuppFlavors );
2245 
2246 	aFlavorSeq[0].MimeType =
2247         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2248 	aFlavorSeq[0].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2249 	aFlavorSeq[0].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2250 
2251 	aFlavorSeq[1].MimeType =
2252         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2253 	aFlavorSeq[1].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2254 	aFlavorSeq[1].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2255 
2256 	aFlavorSeq[2].MimeType =
2257         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2258 	aFlavorSeq[2].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2259 	aFlavorSeq[2].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2260 
2261 	aFlavorSeq[3].MimeType =
2262         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2263 	aFlavorSeq[3].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2264 	aFlavorSeq[3].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2265 
2266     aFlavorSeq[4].MimeType =
2267         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) );
2268     aFlavorSeq[4].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Object Descriptor (XML)" ) );
2269     aFlavorSeq[4].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2270 
2271     aFlavorSeq[5].MimeType =
2272         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"" ) );
2273     aFlavorSeq[5].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Embed Source (XML)" ) );
2274     aFlavorSeq[5].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2275 
2276     aFlavorSeq[6].MimeType =
2277         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) );
2278     aFlavorSeq[6].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ) );
2279     aFlavorSeq[6].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2280 
2281     aFlavorSeq[7].MimeType =
2282         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) );
2283     aFlavorSeq[7].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PNG" ) );
2284     aFlavorSeq[7].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2285 
2286     if ( nSuppFlavors == 10 )
2287 	{
2288         aFlavorSeq[8].MimeType =
2289             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2290         aFlavorSeq[8].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2291         aFlavorSeq[8].DataType = getCppuType( (const sal_uInt64*) 0 );
2292 
2293         aFlavorSeq[9].MimeType =
2294             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2295         aFlavorSeq[9].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2296         aFlavorSeq[9].DataType = getCppuType( (const sal_uInt64*) 0 );
2297 	}
2298 
2299 	return aFlavorSeq;
2300 }
2301 
2302 //________________________________________________________________________________________________________
2303 // XTransferable
2304 //________________________________________________________________________________________________________
2305 
2306 
isDataFlavorSupported(const DATAFLAVOR & aFlavor)2307 sal_Bool SAL_CALL SfxBaseModel::isDataFlavorSupported( const DATAFLAVOR& aFlavor )
2308 		throw (::com::sun::star::uno::RuntimeException)
2309 {
2310     SfxModelGuard aGuard( *this );
2311 
2312     if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2313 	{
2314 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2315 			return sal_True;
2316 	}
2317     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2318 	{
2319 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2320 			return sal_True;
2321 	}
2322     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2323 	{
2324 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2325 			return sal_True;
2326 		else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2327 		  && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2328 			return sal_True;
2329 	}
2330     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2331 	{
2332 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2333 			return sal_True;
2334 		else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2335 		  && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2336 			return sal_True;
2337 	}
2338     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
2339     {
2340         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2341 			return sal_True;
2342     }
2343     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
2344     {
2345         if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2346 			return sal_True;
2347     }
2348     else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2349 	{
2350 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2351 			return sal_True;
2352 	}
2353 	else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
2354 	{
2355 		if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2356 			return sal_True;
2357 	}
2358 
2359 	return sal_False;
2360 }
2361 
2362 
2363 //--------------------------------------------------------------------------------------------------------
2364 //	XEventsSupplier
2365 //--------------------------------------------------------------------------------------------------------
2366 
getEvents()2367 uno::Reference< container::XNameReplace > SAL_CALL SfxBaseModel::getEvents() throw( uno::RuntimeException )
2368 {
2369     SfxModelGuard aGuard( *this );
2370 
2371 	if ( ! m_pData->m_xEvents.is() )
2372 	{
2373 		m_pData->m_xEvents = new SfxEvents_Impl( m_pData->m_pObjectShell, this );
2374 	}
2375 
2376 	return m_pData->m_xEvents;
2377 }
2378 
2379 //--------------------------------------------------------------------------------------------------------
2380 //	XEmbeddedScripts
2381 //--------------------------------------------------------------------------------------------------------
2382 
getBasicLibraries()2383 uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getBasicLibraries() throw (RuntimeException)
2384 {
2385     SfxModelGuard aGuard( *this );
2386 
2387     uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries;
2388     if ( m_pData->m_pObjectShell )
2389         xBasicLibraries.set( m_pData->m_pObjectShell->GetBasicContainer(), UNO_QUERY_THROW );
2390     return xBasicLibraries;
2391 }
2392 
getDialogLibraries()2393 uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getDialogLibraries() throw (RuntimeException)
2394 {
2395     SfxModelGuard aGuard( *this );
2396 
2397     uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries;
2398     if ( m_pData->m_pObjectShell )
2399         xDialogLibraries.set( m_pData->m_pObjectShell->GetDialogContainer(), UNO_QUERY_THROW );
2400     return xDialogLibraries;
2401 }
2402 
getAllowMacroExecution()2403 ::sal_Bool SAL_CALL SfxBaseModel::getAllowMacroExecution() throw (RuntimeException)
2404 {
2405     SfxModelGuard aGuard( *this );
2406 
2407     if ( m_pData->m_pObjectShell )
2408         return m_pData->m_pObjectShell->AdjustMacroMode( String(), false );
2409     return sal_False;
2410 }
2411 
2412 //--------------------------------------------------------------------------------------------------------
2413 //	XScriptInvocationContext
2414 //--------------------------------------------------------------------------------------------------------
2415 
getScriptContainer()2416 Reference< document::XEmbeddedScripts > SAL_CALL SfxBaseModel::getScriptContainer() throw (RuntimeException)
2417 {
2418     SfxModelGuard aGuard( *this );
2419 
2420     Reference< document::XEmbeddedScripts > xDocumentScripts;
2421 
2422     try
2423     {
2424         Reference< frame::XModel > xDocument( this );
2425         xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2426         while ( !xDocumentScripts.is() && xDocument.is() )
2427         {
2428             Reference< container::XChild > xDocAsChild( xDocument, uno::UNO_QUERY );
2429             if ( !xDocAsChild.is() )
2430             {
2431                 xDocument = NULL;
2432                 break;
2433             }
2434 
2435             xDocument.set( xDocAsChild->getParent(), uno::UNO_QUERY );
2436             xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2437         }
2438     }
2439     catch( const Exception& )
2440     {
2441         DBG_UNHANDLED_EXCEPTION();
2442         xDocumentScripts = NULL;
2443     }
2444 
2445     return xDocumentScripts;
2446 }
2447 
2448 //--------------------------------------------------------------------------------------------------------
2449 //	XEventBroadcaster
2450 //--------------------------------------------------------------------------------------------------------
2451 
addEventListener(const uno::Reference<XDOCEVENTLISTENER> & aListener)2452 void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2453 {
2454     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2455 
2456     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2457 }
2458 
2459 //--------------------------------------------------------------------------------------------------------
2460 //	XEventBroadcaster
2461 //--------------------------------------------------------------------------------------------------------
2462 
removeEventListener(const uno::Reference<XDOCEVENTLISTENER> & aListener)2463 void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2464 {
2465     SfxModelGuard aGuard( *this );
2466 
2467     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2468 }
2469 
2470 //--------------------------------------------------------------------------------------------------------
2471 //	XDocumentEventBroadcaster
2472 //--------------------------------------------------------------------------------------------------------
2473 // ---------------------------------
addDocumentEventListener(const uno::Reference<document::XDocumentEventListener> & aListener)2474 void SAL_CALL SfxBaseModel::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2475     throw ( uno::RuntimeException )
2476 {
2477     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2478     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2479 }
2480 
2481 // ---------------------------------
removeDocumentEventListener(const uno::Reference<document::XDocumentEventListener> & aListener)2482 void SAL_CALL SfxBaseModel::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2483     throw ( uno::RuntimeException )
2484 {
2485     SfxModelGuard aGuard( *this );
2486     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2487 }
2488 
2489 // ---------------------------------
notifyDocumentEvent(const::rtl::OUString &,const uno::Reference<frame::XController2> &,const uno::Any &)2490 void SAL_CALL SfxBaseModel::notifyDocumentEvent( const ::rtl::OUString&, const uno::Reference< frame::XController2 >&, const uno::Any& )
2491     throw ( lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException )
2492 {
2493     throw lang::NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SfxBaseModel controlls all the sent notifications itself!" ) ), uno::Reference< uno::XInterface >() );
2494 }
2495 
2496 //________________________________________________________________________________________________________
2497 //	SfxListener
2498 //________________________________________________________________________________________________________
2499 
addTitle_Impl(Sequence<::com::sun::star::beans::PropertyValue> & rSeq,const::rtl::OUString & rTitle)2500 void addTitle_Impl( Sequence < ::com::sun::star::beans::PropertyValue >& rSeq, const ::rtl::OUString& rTitle )
2501 {
2502     sal_Int32 nCount = rSeq.getLength();
2503     sal_Int32 nArg;
2504 
2505     for ( nArg = 0; nArg < nCount; nArg++ )
2506     {
2507         ::com::sun::star::beans::PropertyValue& rProp = rSeq[nArg];
2508         if ( rProp.Name.equalsAscii("Title") )
2509         {
2510             rProp.Value <<= rTitle;
2511             break;
2512         }
2513     }
2514 
2515     if ( nArg == nCount )
2516     {
2517         rSeq.realloc( nCount+1 );
2518         rSeq[nCount].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") );
2519         rSeq[nCount].Value <<= rTitle;
2520     }
2521 }
2522 
NotifyStorageListeners_Impl()2523 void SfxBaseModel::NotifyStorageListeners_Impl()
2524 {
2525 	uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
2526 
2527 	if ( m_pData->m_pObjectShell )
2528 	{
2529     	::cppu::OInterfaceContainerHelper* pContainer =
2530 			m_pData->m_aInterfaceContainer.getContainer(
2531 				::getCppuType( ( const uno::Reference< document::XStorageChangeListener >*) NULL ) );
2532     	if ( pContainer != NULL )
2533 		{
2534 			uno::Reference< embed::XStorage > xNewStorage = m_pData->m_pObjectShell->GetStorage();
2535         	::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
2536         	while ( pIterator.hasMoreElements() )
2537         	{
2538             	try
2539             	{
2540                 	((document::XStorageChangeListener*)pIterator.next())->notifyStorageChange(
2541 																			xSelfHold,
2542 																			xNewStorage );
2543             	}
2544             	catch( uno::RuntimeException& )
2545             	{
2546                 	pIterator.remove();
2547             	}
2548         	}
2549 		}
2550 	}
2551 }
2552 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)2553 void SfxBaseModel::Notify(			SfxBroadcaster&	rBC		,
2554 	 						const	SfxHint&		rHint	)
2555 {
2556 	if ( !m_pData )
2557 		return;
2558 
2559     if ( &rBC == m_pData->m_pObjectShell )
2560 	{
2561 		SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
2562 		if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DOCCHANGED )
2563 			changing();
2564 
2565 		SfxEventHint* pNamedHint = PTR_CAST( SfxEventHint, &rHint );
2566 		if ( pNamedHint )
2567 		{
2568 
2569             switch ( pNamedHint->GetEventId() )
2570             {
2571             case SFX_EVENT_STORAGECHANGED:
2572 			{
2573 				// for now this event is sent only on creation of a new storage for new document
2574 				// and in case of reload of medium without document reload
2575 				// other events are used to detect storage change
2576 				// NotifyStorageListeners_Impl();
2577 
2578                 if ( m_pData->m_xUIConfigurationManager.is()
2579 				  && m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
2580                 {
2581                     uno::Reference< XSTORAGE > xConfigStorage;
2582                     rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
2583 
2584                     xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READWRITE );
2585                     if ( !xConfigStorage.is() )
2586                         xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READ );
2587 
2588 					if ( xConfigStorage.is() || !m_pData->m_pObjectShell->GetStorage()->hasByName( aUIConfigFolderName ) )
2589 					{
2590 						// the storage is different, since otherwise it could not be opened, so it must be exchanged
2591                         Reference< ui::XUIConfigurationStorage > xUIConfigStorage( m_pData->m_xUIConfigurationManager, uno::UNO_QUERY );
2592                     	xUIConfigStorage->setStorage( xConfigStorage );
2593 					}
2594 					else
2595 					{
2596 						OSL_ENSURE( sal_False, "Unexpected scenario!\n" );
2597 					}
2598                 }
2599 
2600 				ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2601 			}
2602             break;
2603 
2604             case SFX_EVENT_LOADFINISHED:
2605 			{
2606                 impl_getPrintHelper();
2607 				ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2608                 m_pData->m_bModifiedSinceLastSave = sal_False;
2609 			}
2610             break;
2611 
2612             case SFX_EVENT_SAVEASDOCDONE:
2613             {
2614 				m_pData->m_sURL = m_pData->m_pObjectShell->GetMedium()->GetName();
2615 
2616                 SfxItemSet *pSet = m_pData->m_pObjectShell->GetMedium()->GetItemSet();
2617                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
2618                 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2619                 TransformItems( SID_SAVEASDOC, *pSet, aArgs );
2620                 addTitle_Impl( aArgs, aTitle );
2621                 attachResource( m_pData->m_pObjectShell->GetMedium()->GetName(), aArgs );
2622             }
2623             break;
2624 
2625             case SFX_EVENT_DOCCREATED:
2626             {
2627                 impl_getPrintHelper();
2628                 m_pData->m_bModifiedSinceLastSave = sal_False;
2629             }
2630             break;
2631 
2632             case SFX_EVENT_MODIFYCHANGED:
2633             {
2634                 m_pData->m_bModifiedSinceLastSave = isModified();
2635             }
2636             break;
2637             }
2638 
2639 
2640             SfxViewEventHint* pViewHint = PTR_CAST( SfxViewEventHint, &rHint );
2641 			postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? pViewHint->GetController() : uno::Reference< frame::XController2 >() );
2642 		}
2643 
2644         if ( pSimpleHint )
2645 		{
2646 			if ( pSimpleHint->GetId() == SFX_HINT_TITLECHANGED )
2647         	{
2648             	::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2649             	addTitle_Impl( m_pData->m_seqArguments, aTitle );
2650 				postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_TITLECHANGED ) );
2651         	}
2652 			if ( pSimpleHint->GetId() == SFX_HINT_MODECHANGED )
2653         	{
2654 				postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_MODECHANGED ) );
2655         	}
2656 /*
2657 			else if ( pSimpleHint->GetId() == SFX_HINT_DYING
2658 				|| pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
2659 			{
2660         		SfxObjectShellLock pShellLock = m_pData->m_pObjectShellLock;
2661         		m_pData->m_pObjectShellLock = SfxObjectShellLock();
2662 			}
2663 */
2664 		}
2665 	}
2666 }
2667 
2668 //________________________________________________________________________________________________________
2669 //	public impl.
2670 //________________________________________________________________________________________________________
2671 
NotifyModifyListeners_Impl() const2672 void SfxBaseModel::NotifyModifyListeners_Impl() const
2673 {
2674     ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0) );
2675 	if ( pIC )
2676 	{
2677         lang::EventObject aEvent( (frame::XModel *)this );
2678         pIC->notifyEach( &util::XModifyListener::modified, aEvent );
2679 	}
2680 
2681     // this notification here is done too generously, we cannot simply assume that we're really modified
2682     // now, but we need to check it ...
2683     m_pData->m_bModifiedSinceLastSave = const_cast< SfxBaseModel* >( this )->isModified();
2684 }
2685 
changing()2686 void SfxBaseModel::changing()
2687 {
2688     SfxModelGuard aGuard( *this );
2689 
2690     // the notification should not be sent if the document can not be modified
2691     if ( !m_pData->m_pObjectShell.Is() || !m_pData->m_pObjectShell->IsEnableSetModified() )
2692         return;
2693 
2694     NotifyModifyListeners_Impl();
2695 }
2696 
impl_change()2697 void SfxBaseModel::impl_change()
2698 {
2699 	// object already disposed?
2700 	if ( impl_isDisposed() )
2701 		return;
2702 
2703     NotifyModifyListeners_Impl();
2704 }
2705 
2706 //________________________________________________________________________________________________________
2707 //	public impl.
2708 //________________________________________________________________________________________________________
2709 
GetObjectShell() const2710 SfxObjectShell* SfxBaseModel::GetObjectShell() const
2711 {
2712 	return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2713 }
2714 
impl_getObjectShell() const2715 SfxObjectShell* SfxBaseModel::impl_getObjectShell() const
2716 {
2717 	return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2718 }
2719 
2720 //________________________________________________________________________________________________________
2721 //	public impl.
2722 //________________________________________________________________________________________________________
2723 
IsInitialized() const2724 sal_Bool SfxBaseModel::IsInitialized() const
2725 {
2726 	if ( !m_pData || !m_pData->m_pObjectShell )
2727     {
2728         OSL_ENSURE( false, "SfxBaseModel::IsInitialized: this should have been caught earlier!" );
2729         return sal_False;
2730     }
2731 
2732     return m_pData->m_pObjectShell->GetMedium() != NULL;
2733 }
2734 
MethodEntryCheck(const bool i_mustBeInitialized) const2735 void SfxBaseModel::MethodEntryCheck( const bool i_mustBeInitialized ) const
2736 {
2737     if ( impl_isDisposed() )
2738         throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2739     if ( i_mustBeInitialized && !IsInitialized() )
2740         throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2741 }
2742 
impl_isDisposed() const2743 sal_Bool SfxBaseModel::impl_isDisposed() const
2744 {
2745 	return ( m_pData == NULL ) ;
2746 }
2747 
2748 //________________________________________________________________________________________________________
2749 //	private impl.
2750 //________________________________________________________________________________________________________
2751 
GetMediumFilterName_Impl()2752 ::rtl::OUString SfxBaseModel::GetMediumFilterName_Impl()
2753 {
2754 	const SfxFilter* pFilter = NULL;
2755 	SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2756 	if ( pMedium )
2757 		pFilter = pMedium->GetFilter();
2758 
2759 	if ( pFilter )
2760 		return pFilter->GetName();
2761 
2762 	return ::rtl::OUString();
2763 }
2764 
impl_store(const::rtl::OUString & sURL,const uno::Sequence<beans::PropertyValue> & seqArguments,sal_Bool bSaveTo)2765 void SfxBaseModel::impl_store(  const   ::rtl::OUString&                   sURL            ,
2766                                 const   uno::Sequence< beans::PropertyValue >&  seqArguments    ,
2767 										sal_Bool					bSaveTo			)
2768 {
2769 	if( !sURL.getLength() )
2770         throw frame::IllegalArgumentIOException();
2771 
2772 	//sal_Bool aSaveAsTemplate = sal_False;
2773 
2774     sal_Bool bSaved = sal_False;
2775     if ( !bSaveTo && m_pData->m_pObjectShell && sURL.getLength()
2776       && sURL.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL
2777 	  && ::utl::UCBContentHelper::EqualURLs( getLocation(), sURL ) )
2778     {
2779         // this is the same file URL as the current document location, try to use storeOwn if possible
2780 
2781         ::comphelper::SequenceAsHashMap aArgHash( seqArguments );
2782         ::rtl::OUString aFilterString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
2783         ::rtl::OUString aFilterName = aArgHash.getUnpackedValueOrDefault( aFilterString, ::rtl::OUString() );
2784         if ( aFilterName.getLength() )
2785         {
2786             SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2787             if ( pMedium )
2788             {
2789                 const SfxFilter* pFilter = pMedium->GetFilter();
2790                 if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) )
2791                 {
2792                     // 119366 - If the former file saving with password, do not trying in StoreSelf anyway...
2793                     bool bFormerPassword = false;
2794                     {
2795                         uno::Sequence< beans::NamedValue > aOldEncryptionData;
2796                         if (GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ))
2797                         {
2798                             bFormerPassword = true;
2799                         }
2800                     }
2801                     if ( !bFormerPassword )
2802                     {
2803                         aArgHash.erase( aFilterString );
2804                         aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
2805 
2806                         try
2807                         {
2808                             storeSelf( aArgHash.getAsConstPropertyValueList() );
2809                             bSaved = sal_True;
2810                         }
2811                         catch( const lang::IllegalArgumentException& )
2812                         {
2813                             // some additional arguments do not allow to use saving, SaveAs should be done
2814                             // but only for normal documents, the shared documents would be overwritten in this case
2815                             // that would mean an information loss
2816                             // TODO/LATER: need a new interaction for this case
2817                             if ( m_pData->m_pObjectShell->IsDocShared() )
2818                             {
2819                                 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) );
2820                                 m_pData->m_pObjectShell->StoreLog();
2821 
2822                                 uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() );
2823                                 if ( !aNewEncryptionData.getLength() )
2824                                 {
2825                                     ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() );
2826                                     aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword );
2827                                 }
2828 
2829                                 uno::Sequence< beans::NamedValue > aOldEncryptionData;
2830                                 GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData );
2831 
2832                                 if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() )
2833                                     throw;
2834                                 else
2835                                 {
2836                                     // if the password is changed a special error should be used in case of shared document
2837                                     throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE );
2838                                 }
2839                             }
2840                         }
2841                     }
2842                 }
2843             }
2844         }
2845     }
2846 
2847 	if ( !bSaved && m_pData->m_pObjectShell )
2848 	{
2849 		SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOC : STR_EVENT_SAVEASDOC ),
2850 												m_pData->m_pObjectShell ) );
2851 
2852     	SfxAllItemSet *aParams = new SfxAllItemSet( SFX_APP()->GetPool() );
2853 		aParams->Put( SfxStringItem( SID_FILE_NAME, String(sURL) ) );
2854 		if ( bSaveTo )
2855 			aParams->Put( SfxBoolItem( SID_SAVETO, sal_True ) );
2856 
2857     	TransformParameters( SID_SAVEASDOC, seqArguments, *aParams );
2858 
2859     	SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
2860 
2861 		if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo )
2862         {
2863             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Misuse of CopyStreamIfPossible!" ) ) );
2864             m_pData->m_pObjectShell->StoreLog();
2865 
2866             throw frame::IllegalArgumentIOException(
2867 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!") ),
2868 					uno::Reference< uno::XInterface >() );
2869         }
2870 
2871         sal_uInt32 nModifyPasswordHash = 0;
2872         uno::Sequence< beans::PropertyValue > aModifyPasswordInfo;
2873     	SFX_ITEMSET_ARG( aParams, pModifyPasswordInfoItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
2874         if ( pModifyPasswordInfoItem )
2875         {
2876             // it contains either a simple hash or a set of PropertyValues
2877             // TODO/LATER: the sequence of PropertyValue should replace the hash completely in future
2878             sal_Int32 nMPHTmp = 0;
2879             pModifyPasswordInfoItem->GetValue() >>= nMPHTmp;
2880             nModifyPasswordHash = (sal_uInt32)nMPHTmp;
2881             pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo;
2882         }
2883         aParams->ClearItem( SID_MODIFYPASSWORDINFO );
2884         sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash();
2885         m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash );
2886         uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo();
2887         m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo );
2888 
2889         // since saving a document modifies its DocumentInfo, the current
2890         // DocumentInfo must be saved on "SaveTo", so it can be restored
2891         // after saving
2892         sal_Bool bCopyTo =  bSaveTo ||
2893             m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
2894         uno::Reference<document::XDocumentProperties> xOldDocProps;
2895         uno::Reference<document::XDocumentInfo> xOldDocInfo;
2896         if ( bCopyTo )
2897         {
2898             xOldDocProps = getDocumentProperties();
2899             if (m_pData->m_xDocumentInfo.is())
2900             {
2901                 xOldDocInfo = getDocumentInfo();
2902                 const Reference<util::XCloneable> xCloneable(xOldDocInfo,
2903                     UNO_QUERY_THROW);
2904                 const Reference<document::XDocumentInfo> xNewDocInfo(
2905                     xCloneable->createClone(), UNO_QUERY_THROW);
2906                 const Reference<document::XDocumentPropertiesSupplier> xDPS(
2907                     xNewDocInfo, UNO_QUERY_THROW);
2908                 const Reference<document::XDocumentProperties> xNewDocProps(
2909                     xDPS->getDocumentProperties());
2910                 m_pData->m_xDocumentProperties = xNewDocProps;
2911                 m_pData->m_xDocumentInfo = xNewDocInfo;
2912             }
2913             else // try not to create DocumentInfo if it does not exist...
2914             {
2915                 const Reference<util::XCloneable> xCloneable(xOldDocProps,
2916                     UNO_QUERY_THROW);
2917                 const Reference<document::XDocumentProperties> xNewDocProps(
2918                     xCloneable->createClone(), UNO_QUERY_THROW);
2919                 m_pData->m_xDocumentProperties = xNewDocProps;
2920             }
2921         }
2922 
2923 		sal_Bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams );
2924 
2925         if ( bCopyTo )
2926         {
2927             // restore DocumentInfo if a copy was created
2928             m_pData->m_xDocumentProperties = xOldDocProps;
2929             m_pData->m_xDocumentInfo = xOldDocInfo;
2930         }
2931 
2932 		uno::Reference < task::XInteractionHandler > xHandler;
2933 		SFX_ITEMSET_ARG( aParams, pItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
2934 		if ( pItem )
2935 			pItem->GetValue() >>= xHandler;
2936 
2937 		DELETEZ( aParams );
2938 
2939 		sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetErrorCode();
2940 		if ( !bRet && !nErrCode )
2941         {
2942             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing has failed, no error is set!" ) ) );
2943 			nErrCode = ERRCODE_IO_CANTWRITE;
2944         }
2945 		m_pData->m_pObjectShell->ResetError();
2946 
2947 		if ( bRet )
2948 		{
2949 			if ( nErrCode )
2950 			{
2951 				// must be a warning - use Interactionhandler if possible or abandone
2952                 if ( xHandler.is() )
2953                 {
2954 					// TODO/LATER: a general way to set the error context should be available
2955 					SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, m_pData->m_pObjectShell->GetTitle() );
2956 
2957 					::com::sun::star::task::ErrorCodeRequest aErrorCode;
2958 		            aErrorCode.ErrCode = nErrCode;
2959                     SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
2960 				}
2961 			}
2962 
2963             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing succeeded!" ) ) );
2964 			if ( !bSaveTo )
2965             {
2966                 m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
2967                 m_pData->m_pObjectShell->SetModifyPasswordEntered();
2968 
2969 				SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) );
2970             }
2971             else
2972             {
2973                 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
2974                 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
2975 
2976 				SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) );
2977             }
2978 		}
2979 		else
2980 		{
2981             // let the logring be stored to the related file
2982             m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
2983             m_pData->m_pObjectShell->StoreLog();
2984 
2985             m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
2986             m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
2987 
2988 
2989 			SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED),
2990 													m_pData->m_pObjectShell ) );
2991 
2992 			throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
2993 		}
2994 	}
2995 }
2996 
2997 //********************************************************************************************************
2998 namespace {
2999 template< typename ListenerT, typename EventT >
3000 class NotifySingleListenerIgnoreRE
3001 {
3002 private:
3003     typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& );
3004     NotificationMethod  m_pMethod;
3005     const EventT&       m_rEvent;
3006 public:
NotifySingleListenerIgnoreRE(NotificationMethod method,const EventT & event)3007     NotifySingleListenerIgnoreRE( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
3008 
operator ()(const uno::Reference<ListenerT> & listener) const3009     void operator()( const uno::Reference<ListenerT>& listener ) const
3010     {
3011         try
3012         {
3013             (listener.get()->*m_pMethod)( m_rEvent );
3014         }
3015         catch( uno::RuntimeException& )
3016         {
3017             // this exception is ignored to avoid problems with invalid listeners, the listener should be probably thrown away in future
3018         }
3019     }
3020 };
3021 } // anonymous namespace
3022 
postEvent_Impl(const::rtl::OUString & aName,const uno::Reference<frame::XController2> & xController)3023 void SfxBaseModel::postEvent_Impl( const ::rtl::OUString& aName, const uno::Reference< frame::XController2 >& xController )
3024 {
3025 	// object already disposed?
3026 	if ( impl_isDisposed() )
3027 		return;
3028 
3029 	DBG_ASSERT( aName.getLength(), "Empty event name!" );
3030 	if (!aName.getLength())
3031 		return;
3032 
3033     ::cppu::OInterfaceContainerHelper* pIC =
3034         m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XDocumentEventListener >*)0 ) );
3035     if ( pIC )
3036     {
3037 #ifdef DBG_UTIL
3038         ByteString aTmp( "SfxDocumentEvent: " );
3039         aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
3040         DBG_TRACE( aTmp.GetBuffer() );
3041 #endif
3042 
3043         document::DocumentEvent aDocumentEvent( (frame::XModel*)this, aName, xController, uno::Any() );
3044 
3045         pIC->forEach< document::XDocumentEventListener, NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent > >(
3046             NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent >(
3047                 &document::XDocumentEventListener::documentEventOccured,
3048                 aDocumentEvent ) );
3049     }
3050 
3051     pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ) );
3052     if ( pIC )
3053     {
3054 #ifdef DBG_UTIL
3055         ByteString aTmp( "SfxEvent: " );
3056         aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
3057         DBG_TRACE( aTmp.GetBuffer() );
3058 #endif
3059 
3060         document::EventObject aEvent( (frame::XModel*)this, aName );
3061 
3062         pIC->forEach< document::XEventListener, NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject > >(
3063             NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject >(
3064                 &document::XEventListener::notifyEvent,
3065                 aEvent ) );
3066     }
3067 
3068 }
3069 
getViewData()3070 uno::Reference < container::XIndexAccess > SAL_CALL SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException)
3071 {
3072     SfxModelGuard aGuard( *this );
3073 
3074 	if ( m_pData->m_pObjectShell.Is() && !m_pData->m_contViewData.is() )
3075 	{
3076     	SfxViewFrame *pActFrame = SfxViewFrame::Current();
3077     	if ( !pActFrame || pActFrame->GetObjectShell() != m_pData->m_pObjectShell )
3078         	pActFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
3079 
3080         if ( !pActFrame || !pActFrame->GetViewShell() )
3081             // currently no frame for this document at all or View is under construction
3082             return uno::Reference < container::XIndexAccess >();
3083 
3084         m_pData->m_contViewData = Reference < container::XIndexAccess >(
3085 				::comphelper::getProcessServiceFactory()->createInstance(
3086 				DEFINE_CONST_UNICODE("com.sun.star.document.IndexedPropertyValues") ),
3087                 uno::UNO_QUERY );
3088 
3089 		if ( !m_pData->m_contViewData.is() )
3090 		{
3091 			// error: no container class available!
3092             return uno::Reference < container::XIndexAccess >();
3093 		}
3094 
3095         uno::Reference < container::XIndexContainer > xCont( m_pData->m_contViewData, uno::UNO_QUERY );
3096 		sal_Int32 nCount = 0;
3097         uno::Sequence < beans::PropertyValue > aSeq;
3098 		::com::sun::star::uno::Any aAny;
3099     	for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); pFrame;
3100             	pFrame = SfxViewFrame::GetNext( *pFrame, m_pData->m_pObjectShell ) )
3101     	{
3102 			sal_Bool bIsActive = ( pFrame == pActFrame );
3103 			pFrame->GetViewShell()->WriteUserDataSequence( aSeq );
3104 			aAny <<= aSeq;
3105 			xCont->insertByIndex( bIsActive ? 0 : nCount, aAny );
3106 			nCount++;
3107 		}
3108 	}
3109 
3110 	return m_pData->m_contViewData;
3111 }
3112 
setViewData(const uno::Reference<container::XIndexAccess> & aData)3113 void SAL_CALL SfxBaseModel::setViewData( const uno::Reference < container::XIndexAccess >& aData ) throw(::com::sun::star::uno::RuntimeException)
3114 {
3115     SfxModelGuard aGuard( *this );
3116 
3117 	m_pData->m_contViewData = aData;
3118 }
3119 
3120 /** calls all XEventListeners */
notifyEvent(const::com::sun::star::document::EventObject & aEvent) const3121 void SfxBaseModel::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) const
3122 {
3123     // object already disposed?
3124     if ( impl_isDisposed() )
3125         return;
3126 
3127     ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer(
3128                                         ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) );
3129 	if( pIC )
3130 
3131 	{
3132         ::cppu::OInterfaceIteratorHelper aIt( *pIC );
3133 		while( aIt.hasMoreElements() )
3134         {
3135             try
3136             {
3137                 ((XDOCEVENTLISTENER *)aIt.next())->notifyEvent( aEvent );
3138             }
3139             catch( uno::RuntimeException& )
3140             {
3141                 aIt.remove();
3142             }
3143         }
3144 	}
3145 }
3146 
3147 /** returns true if someone added a XEventListener to this XEventBroadcaster */
hasEventListeners() const3148 sal_Bool SfxBaseModel::hasEventListeners() const
3149 {
3150     return !impl_isDisposed() && (NULL != m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ) );
3151 }
3152 
addPrintJobListener(const uno::Reference<view::XPrintJobListener> & xListener)3153 void SAL_CALL SfxBaseModel::addPrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3154 {
3155     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3156 
3157     if ( impl_getPrintHelper() )
3158 	{
3159 		uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3160 		if ( xPJB.is() )
3161 			xPJB->addPrintJobListener( xListener );
3162 	}
3163 //	else
3164 //		m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3165 }
3166 
removePrintJobListener(const uno::Reference<view::XPrintJobListener> & xListener)3167 void SAL_CALL SfxBaseModel::removePrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3168 {
3169     SfxModelGuard aGuard( *this );
3170 
3171     if ( impl_getPrintHelper() )
3172 	{
3173 		uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3174 		if ( xPJB.is() )
3175             xPJB->removePrintJobListener( xListener );
3176 	}
3177 //	else
3178 //		m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3179 }
3180 
3181 // simple declaration of class SvObject is enough
3182 // the corresponding <so3/iface.hxx> cannon be included because it provides
3183 // declaration of class SvBorder that conflicts with ../../inc/viewfrm.hxx
3184 class SvObject;
getSomething(const::com::sun::star::uno::Sequence<sal_Int8> & aIdentifier)3185 sal_Int64 SAL_CALL SfxBaseModel::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
3186 {
3187     ::vos::OGuard aGuard( Application::GetSolarMutex() );
3188 	if ( GetObjectShell() )
3189 	{
3190         SvGlobalName aName( aIdentifier );
3191 		if ( aName == SvGlobalName( SO3_GLOBAL_CLASSID ) )
3192 	 		return (sal_Int64)(sal_IntPtr)(SvObject*)GetObjectShell();
3193 		else if ( aName == SvGlobalName( SFX_GLOBAL_CLASSID ) )
3194 	 		return (sal_Int64)(sal_IntPtr)(SfxObjectShell*)GetObjectShell();
3195 	}
3196 
3197 	return 0;
3198 }
3199 
3200 //____________________________________________________________________________________________________
3201 //	XDocumentSubStorageSupplier
3202 //____________________________________________________________________________________________________
3203 
ListenForStorage_Impl(const uno::Reference<embed::XStorage> & xStorage)3204 void SfxBaseModel::ListenForStorage_Impl( const uno::Reference< embed::XStorage >& xStorage )
3205 {
3206 	uno::Reference< util::XModifiable > xModifiable( xStorage, uno::UNO_QUERY );
3207 	if ( xModifiable.is() )
3208 	{
3209 		if ( !m_pData->m_pStorageModifyListen.is() )
3210 		{
3211             m_pData->m_pStorageModifyListen = new ::sfx2::DocumentStorageModifyListener( *m_pData, Application::GetSolarMutex() );
3212 		}
3213 
3214 		// no need to deregister the listening for old storage since it should be disposed automatically
3215 		xModifiable->addModifyListener( m_pData->m_pStorageModifyListen.get() );
3216 	}
3217 }
3218 
getDocumentSubStorage(const::rtl::OUString & aStorageName,sal_Int32 nMode)3219 uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode )
3220     throw ( uno::RuntimeException)
3221 {
3222     SfxModelGuard aGuard( *this );
3223 
3224     uno::Reference< XSTORAGE > xResult;
3225     if ( m_pData->m_pObjectShell.Is() )
3226     {
3227 		uno::Reference< embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3228 		if ( xStorage.is() )
3229 		{
3230             try
3231             {
3232                 xResult = xStorage->openStorageElement( aStorageName, nMode );
3233             }
3234             catch ( uno::Exception& )
3235             {
3236             }
3237 		}
3238 	}
3239 
3240 	return xResult;
3241 }
3242 
getDocumentSubStoragesNames()3243 Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getDocumentSubStoragesNames()
3244 	throw ( io::IOException,
3245 			RuntimeException )
3246 {
3247     SfxModelGuard aGuard( *this );
3248 
3249 	Sequence< ::rtl::OUString > aResult;
3250 	sal_Int32 nResultSize = 0;
3251 	sal_Bool bSuccess = sal_False;
3252     if ( m_pData->m_pObjectShell.Is() )
3253     {
3254         uno::Reference < embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3255         uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
3256         if ( xAccess.is() )
3257 		{
3258             Sequence< ::rtl::OUString > aTemp = xAccess->getElementNames();
3259             for ( sal_Int32 n = 0; n < aTemp.getLength(); n++ )
3260 			{
3261                 if ( xStorage->isStorageElement( aTemp[n] ) )
3262 				{
3263 					aResult.realloc( ++nResultSize );
3264                     aResult[ nResultSize - 1 ] = aTemp[n];
3265 				}
3266 			}
3267 
3268 			bSuccess = sal_True;
3269 		}
3270 	}
3271 
3272 	if ( !bSuccess )
3273 		throw io::IOException();
3274 
3275        return aResult;
3276 }
3277 
3278 //____________________________________________________________________________________________________
3279 //	XScriptProviderSupplier
3280 //____________________________________________________________________________________________________
3281 
3282 
getScriptProvider()3283 uno::Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getScriptProvider()
3284     throw ( uno::RuntimeException )
3285 {
3286     SfxModelGuard aGuard( *this );
3287 
3288     uno::Reference< script::provider::XScriptProvider > xScriptProvider;
3289 
3290     ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
3291     Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory(
3292         aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW );
3293 
3294     try
3295     {
3296         Reference< XScriptInvocationContext > xScriptContext( this );
3297         xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), uno::UNO_SET_THROW );
3298     }
3299     catch( const uno::RuntimeException& )
3300     {
3301         throw;
3302     }
3303     catch( const lang::IllegalArgumentException& )
3304     {
3305         throw lang::WrappedTargetRuntimeException(
3306             ::rtl::OUString(),
3307             *this,
3308             ::cppu::getCaughtException()
3309         );
3310     }
3311 
3312     return xScriptProvider;
3313 }
3314 
3315 //____________________________________________________________________________________________________
3316 //	XUIConfigurationManagerSupplier
3317 //____________________________________________________________________________________________________
3318 
getRuntimeUID() const3319 rtl::OUString SfxBaseModel::getRuntimeUID() const
3320 {
3321     OSL_ENSURE( m_pData->m_sRuntimeUID.getLength() > 0,
3322                 "SfxBaseModel::getRuntimeUID - ID is empty!" );
3323     return m_pData->m_sRuntimeUID;
3324 }
3325 
hasValidSignatures() const3326 sal_Bool SfxBaseModel::hasValidSignatures() const
3327 {
3328     ::vos::OGuard aGuard( Application::GetSolarMutex() );
3329     if ( m_pData->m_pObjectShell.Is() )
3330         return ( m_pData->m_pObjectShell->ImplGetSignatureState( sal_False ) == SIGNATURESTATE_SIGNATURES_OK );
3331     return sal_False;
3332 }
3333 
GetCommandFromSequence(rtl::OUString & rCommand,sal_Int32 & nIndex,const uno::Sequence<beans::PropertyValue> & rSeqPropValue)3334 static void GetCommandFromSequence( rtl::OUString& rCommand, sal_Int32& nIndex, const uno::Sequence< beans::PropertyValue >& rSeqPropValue )
3335 {
3336     rtl::OUString aCommand;
3337     nIndex = -1;
3338 
3339     for ( sal_Int32 i = 0; i < rSeqPropValue.getLength(); i++ )
3340     {
3341         if ( rSeqPropValue[i].Name.equalsAsciiL( "Command", 7 ))
3342         {
3343             rSeqPropValue[i].Value >>= rCommand;
3344             nIndex = i;
3345             return;
3346         }
3347     }
3348 }
3349 
ConvertSlotsToCommands(SfxObjectShell * pDoc,uno::Reference<container::XIndexContainer> & rToolbarDefinition)3350 static void ConvertSlotsToCommands( SfxObjectShell* pDoc, uno::Reference< container::XIndexContainer >& rToolbarDefinition )
3351 {
3352     if ( pDoc )
3353     {
3354         Any           aAny;
3355         SfxModule*    pModule( pDoc->GetFactory().GetModule() );
3356         rtl::OUString aSlotCmd( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
3357         rtl::OUString aUnoCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
3358         uno::Sequence< beans::PropertyValue > aSeqPropValue;
3359 
3360         for ( sal_Int32 i = 0; i < rToolbarDefinition->getCount(); i++ )
3361         {
3362             sal_Int32 nIndex( -1 );
3363             rtl::OUString aCommand;
3364 
3365             if ( rToolbarDefinition->getByIndex( i ) >>= aSeqPropValue )
3366             {
3367                 GetCommandFromSequence( aCommand, nIndex, aSeqPropValue );
3368                 if ( nIndex >= 0 && ( aCommand.indexOf( aSlotCmd ) == 0 ))
3369                 {
3370                     rtl::OUString aSlot( aCommand.copy( 5 ));
3371 
3372                     // We have to replace the old "slot-Command" with our new ".uno:-Command"
3373                     const SfxSlot* pSlot = pModule->GetSlotPool()->GetSlot( sal_uInt16( aSlot.toInt32() ));
3374                     if ( pSlot )
3375                     {
3376                         rtl::OUStringBuffer aStrBuf( aUnoCmd );
3377                         aStrBuf.appendAscii( pSlot->GetUnoName() );
3378 
3379                         aCommand = aStrBuf.makeStringAndClear();
3380                         aSeqPropValue[nIndex].Value <<= aCommand;
3381                         rToolbarDefinition->replaceByIndex( i, Any( aSeqPropValue ));
3382                     }
3383                 }
3384             }
3385         }
3386     }
3387 }
3388 
getUIConfigurationManager()3389 uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfigurationManager()
3390         throw ( uno::RuntimeException )
3391 {
3392     SfxModelGuard aGuard( *this );
3393 
3394     if ( !m_pData->m_xUIConfigurationManager.is() )
3395     {
3396         uno::Reference< ui::XUIConfigurationManager > xNewUIConfMan(
3397             ::comphelper::getProcessServiceFactory()->createInstance(
3398                 ::rtl::OUString::createFromAscii( "com.sun.star.ui.UIConfigurationManager" )),
3399                 uno::UNO_QUERY );
3400 
3401         Reference< ui::XUIConfigurationStorage > xUIConfigStorage( xNewUIConfMan, uno::UNO_QUERY );
3402 		if ( xUIConfigStorage.is() )
3403 		{
3404             uno::Reference< XSTORAGE > xConfigStorage;
3405 
3406 			rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
3407 			// First try to open with READWRITE and then READ
3408 			xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE );
3409 			if ( xConfigStorage.is() )
3410 			{
3411 				rtl::OUString aMediaTypeProp( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ));
3412 				rtl::OUString aUIConfigMediaType(
3413 						RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ) );
3414 				rtl::OUString aMediaType;
3415                 uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY );
3416 				Any a = xPropSet->getPropertyValue( aMediaTypeProp );
3417 				if ( !( a >>= aMediaType ) || ( aMediaType.getLength() == 0 ))
3418 				{
3419 					a <<= aUIConfigMediaType;
3420 					xPropSet->setPropertyValue( aMediaTypeProp, a );
3421 				}
3422 			}
3423 			else
3424 				xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ );
3425 
3426 			// initialize ui configuration manager with document substorage
3427 			xUIConfigStorage->setStorage( xConfigStorage );
3428 
3429             // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to
3430             // migrate
3431             if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
3432             {
3433                 // Import old UI configuration from OOo 1.x
3434                 uno::Reference< XSTORAGE > xOOo1ConfigStorage;
3435                 rtl::OUString         aOOo1UIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations" ));
3436 
3437                 // Try to open with READ
3438 				xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ );
3439                 if ( xOOo1ConfigStorage.is() )
3440                 {
3441                     uno::Reference< lang::XMultiServiceFactory > xServiceMgr( ::comphelper::getProcessServiceFactory() );
3442                     uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars;
3443 
3444                     sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars(
3445                                             xNewUIConfMan, rToolbars, xServiceMgr, xOOo1ConfigStorage );
3446                     if ( bImported )
3447                     {
3448                         SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell();
3449 
3450                         char aNum[]   = "private:resource/toolbar/custom_OOo1x_0";
3451                         char aTitle[] = "Toolbar 0";
3452                         sal_Int32 nNumIndex = strlen( aNum )-1;
3453                         sal_Int32 nTitleIndex = strlen( aTitle )-1;
3454                         for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ )
3455                         {
3456                             aNum[nNumIndex]++;
3457                             aTitle[nTitleIndex]++;
3458 
3459                             rtl::OUString aCustomTbxName( RTL_CONSTASCII_USTRINGPARAM( aNum ));
3460                             rtl::OUString aCustomTbxTitle( RTL_CONSTASCII_USTRINGPARAM( aTitle ));
3461 
3462                             uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i];
3463                             ConvertSlotsToCommands( pObjShell, xToolbar );
3464                             if ( !xNewUIConfMan->hasSettings( aCustomTbxName ))
3465                             {
3466                                 // Set UIName for the toolbar with container property
3467                                 uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY );
3468                                 if ( xPropSet.is() )
3469                                 {
3470                                     try
3471                                     {
3472                                         rtl::OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( "UIName" ));
3473                                         Any           aAny( aCustomTbxTitle );
3474                                         xPropSet->setPropertyValue( aPropName, aAny );
3475                                     }
3476                                     catch ( beans::UnknownPropertyException& )
3477                                     {
3478                                     }
3479                                 }
3480 
3481                                 uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY );
3482                                 xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData );
3483                                 uno::Reference< ui::XUIConfigurationPersistence > xPersist( xNewUIConfMan, uno::UNO_QUERY );
3484                                 xPersist->store();
3485                             }
3486                         }
3487                     }
3488                 }
3489             }
3490         }
3491 
3492 		m_pData->m_xUIConfigurationManager = xNewUIConfMan;
3493 	}
3494 
3495     return m_pData->m_xUIConfigurationManager;
3496 }
3497 
3498 //____________________________________________________________________________________________________
3499 //	XVisualObject
3500 //____________________________________________________________________________________________________
3501 
setVisualAreaSize(sal_Int64 nAspect,const awt::Size & aSize)3502 void SAL_CALL SfxBaseModel::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
3503 		throw ( lang::IllegalArgumentException,
3504 				embed::WrongStateException,
3505 				uno::Exception,
3506 				uno::RuntimeException )
3507 {
3508     SfxModelGuard aGuard( *this );
3509 
3510 	if ( !m_pData->m_pObjectShell.Is() )
3511 		throw uno::Exception(); // TODO: error handling
3512 
3513     SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False );
3514     if ( pViewFrm && m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !pViewFrm->GetFrame().IsInPlace() )
3515 	{
3516         Window* pWindow = VCLUnoHelper::GetWindow( pViewFrm->GetFrame().GetFrameInterface()->getContainerWindow() );
3517         Size aWinSize = pWindow->GetSizePixel();
3518         awt::Size aCurrent = getVisualAreaSize( nAspect );
3519         Size aDiff( aSize.Width-aCurrent.Width, aSize.Height-aCurrent.Height );
3520         Size aWrongDiff = OutputDevice::LogicToLogic( aDiff , m_pData->m_pObjectShell->GetMapUnit(), pWindow->GetMapMode() );
3521         aDiff = pViewFrm->GetViewShell()->GetWindow()->LogicToPixel( aDiff );
3522         aWinSize.Width() += aDiff.Width();
3523         aWinSize.Height() += aDiff.Height();
3524         pWindow->SetSizePixel( aWinSize );
3525 	}
3526 	else
3527     {
3528         Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3529 		aTmpRect.SetSize( Size( aSize.Width, aSize.Height ) );
3530         m_pData->m_pObjectShell->SetVisArea( aTmpRect );
3531     }
3532 }
3533 
getVisualAreaSize(sal_Int64)3534 awt::Size SAL_CALL SfxBaseModel::getVisualAreaSize( sal_Int64 /*nAspect*/ )
3535 		throw ( lang::IllegalArgumentException,
3536 				embed::WrongStateException,
3537 				uno::Exception,
3538 				uno::RuntimeException)
3539 {
3540     SfxModelGuard aGuard( *this );
3541 
3542 	if ( !m_pData->m_pObjectShell.Is() )
3543 		throw uno::Exception(); // TODO: error handling
3544 
3545 	Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3546 
3547 #if 0
3548 	Window* pWindow = NULL;
3549 	SfxViewFrame* pViewFrm = m_pData->m_pObjectShell.Is() ?
3550 								SfxViewFrame::GetFirst( m_pData->m_pObjectShell, 0, sal_False ) : 0;
3551 
3552 	if ( pWindow )
3553 	{
3554 		MapMode aInternalMapMode( pViewFrm->GetWindow().GetMapMode() );
3555 		MapMode aExternalMapMode( m_pData->m_pObjectShell->GetMapUnit() );
3556 
3557     	aTmpRect = OutputDevice::LogicToLogic( aTmpRect, aInternalMapMode, aExternalMapMode );
3558 	}
3559 #endif
3560 
3561 	return awt::Size( aTmpRect.GetWidth(), aTmpRect.GetHeight() );
3562 }
3563 
3564 
getMapUnit(sal_Int64)3565 sal_Int32 SAL_CALL SfxBaseModel::getMapUnit( sal_Int64 /*nAspect*/ )
3566 		throw ( uno::Exception,
3567 				uno::RuntimeException)
3568 {
3569     SfxModelGuard aGuard( *this );
3570 
3571 	if ( !m_pData->m_pObjectShell.Is() )
3572 		throw uno::Exception(); // TODO: error handling
3573 
3574     return VCLUnoHelper::VCL2UnoEmbedMapUnit( m_pData->m_pObjectShell->GetMapUnit() );
3575 }
3576 
getPreferredVisualRepresentation(::sal_Int64)3577 embed::VisualRepresentation SAL_CALL SfxBaseModel::getPreferredVisualRepresentation( ::sal_Int64 /*nAspect*/ )
3578 		throw ( lang::IllegalArgumentException,
3579 				embed::WrongStateException,
3580 				uno::Exception,
3581 				uno::RuntimeException )
3582 {
3583     SfxModelGuard aGuard( *this );
3584 
3585 	datatransfer::DataFlavor aDataFlavor(
3586             ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
3587 			::rtl::OUString::createFromAscii( "GDIMetaFile" ),
3588 			::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
3589 
3590 	embed::VisualRepresentation aVisualRepresentation;
3591 	aVisualRepresentation.Data = getTransferData( aDataFlavor );
3592 	aVisualRepresentation.Flavor = aDataFlavor;
3593 
3594 	return aVisualRepresentation;
3595 }
3596 
3597 //____________________________________________________________________________________________________
3598 //	XStorageBasedDocument
3599 //____________________________________________________________________________________________________
3600 
loadFromStorage(const uno::Reference<XSTORAGE> & xStorage,const uno::Sequence<beans::PropertyValue> & aMediaDescriptor)3601 void SAL_CALL SfxBaseModel::loadFromStorage( const uno::Reference< XSTORAGE >& xStorage,
3602                                              const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3603     throw ( lang::IllegalArgumentException,
3604 			DOUBLEINITIALIZATIONEXCEPTION,
3605 			IOEXCEPTION,
3606 			EXCEPTION,
3607             uno::RuntimeException )
3608 {
3609     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3610     if ( IsInitialized() )
3611         throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
3612 
3613 	// after i36090 is fixed the pool from object shell can be used
3614 	// SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3615     SfxAllItemSet aSet( SFX_APP()->GetPool() );
3616 
3617     // the BaseURL is part of the ItemSet
3618     SfxMedium* pMedium = new SfxMedium( xStorage, String() );
3619 	TransformParameters( SID_OPENDOC, aMediaDescriptor, aSet );
3620 	pMedium->GetItemSet()->Put( aSet );
3621 
3622 	// allow to use an interactionhandler (if there is one)
3623 	pMedium->UseInteractionHandler( sal_True );
3624 
3625 	SFX_ITEMSET_ARG( &aSet, pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
3626 	sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
3627     m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
3628     m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3629 
3630 	// load document
3631 	if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
3632 	{
3633 		sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3634 		throw task::ErrorCodeIOException( ::rtl::OUString(),
3635 											uno::Reference< uno::XInterface >(),
3636 											nError ? nError : ERRCODE_IO_CANTREAD );
3637 	}
3638 }
3639 
storeToStorage(const uno::Reference<XSTORAGE> & xStorage,const uno::Sequence<beans::PropertyValue> & aMediaDescriptor)3640 void SAL_CALL SfxBaseModel::storeToStorage( const uno::Reference< XSTORAGE >& xStorage,
3641                                 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3642     throw ( lang::IllegalArgumentException,
3643 			IOEXCEPTION,
3644 			EXCEPTION,
3645             uno::RuntimeException )
3646 {
3647     SfxModelGuard aGuard( *this );
3648 
3649     uno::Reference< XSTORAGE > xResult;
3650     if ( !m_pData->m_pObjectShell.Is() )
3651 		throw IOEXCEPTION(); // TODO:
3652 
3653 	SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3654 	TransformParameters( SID_SAVEASDOC, aMediaDescriptor, aSet );
3655 
3656 	// TODO/LATER: may be a special URL "private:storage" should be used
3657     SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
3658     sal_Int32 nVersion = SOFFICE_FILEFORMAT_CURRENT;
3659     if( pItem )
3660     {
3661         String aFilterName = pItem->GetValue();
3662         const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName );
3663         if ( pFilter && pFilter->UsesStorage() )
3664             nVersion = pFilter->GetVersion();
3665     }
3666 
3667 	sal_Bool bSuccess = sal_False;
3668 	if ( xStorage == m_pData->m_pObjectShell->GetStorage() )
3669 	{
3670 		// storing to the own storage
3671 		bSuccess = m_pData->m_pObjectShell->DoSave();
3672 	}
3673 	else
3674 	{
3675 		// TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated
3676 		// TODO/LATER: is it possible to have a template here?
3677     	m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False );
3678 
3679     	// BaseURL is part of the ItemSet
3680     	SfxMedium aMedium( xStorage, String(), &aSet );
3681     	aMedium.CanDisposeStorage_Impl( sal_False );
3682         if ( aMedium.GetFilter() )
3683         {
3684             // storing without a valid filter will often crash
3685             bSuccess = m_pData->m_pObjectShell->DoSaveObjectAs( aMedium, sal_True );
3686             m_pData->m_pObjectShell->DoSaveCompleted( NULL );
3687         }
3688 	}
3689 
3690     sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3691     m_pData->m_pObjectShell->ResetError();
3692 
3693     // the warnings are currently not transported
3694 	if ( !bSuccess )
3695 	{
3696 		throw task::ErrorCodeIOException( ::rtl::OUString(),
3697 											uno::Reference< uno::XInterface >(),
3698 											nError ? nError : ERRCODE_IO_GENERAL );
3699 	}
3700 }
3701 
switchToStorage(const uno::Reference<XSTORAGE> & xStorage)3702 void SAL_CALL SfxBaseModel::switchToStorage( const uno::Reference< XSTORAGE >& xStorage )
3703         throw ( lang::IllegalArgumentException,
3704 				IOEXCEPTION,
3705 				EXCEPTION,
3706                 uno::RuntimeException )
3707 {
3708     SfxModelGuard aGuard( *this );
3709 
3710     uno::Reference< XSTORAGE > xResult;
3711     if ( !m_pData->m_pObjectShell.Is() )
3712 		throw IOEXCEPTION(); // TODO:
3713 
3714 	// the persistence should be switched only if the storage is different
3715 	if ( xStorage != m_pData->m_pObjectShell->GetStorage()
3716 	  && !m_pData->m_pObjectShell->SwitchPersistance( xStorage ) )
3717 	{
3718 		sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3719 		throw task::ErrorCodeIOException( ::rtl::OUString(),
3720 											uno::Reference< uno::XInterface >(),
3721 											nError ? nError : ERRCODE_IO_GENERAL );
3722 	}
3723 
3724     m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3725 }
3726 
getDocumentStorage()3727 uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentStorage()
3728 		throw ( IOEXCEPTION,
3729 				EXCEPTION,
3730                 uno::RuntimeException )
3731 {
3732     SfxModelGuard aGuard( *this );
3733 
3734     uno::Reference< XSTORAGE > xResult;
3735     if ( !m_pData->m_pObjectShell.Is() )
3736 		throw IOEXCEPTION(); // TODO
3737 
3738 	return m_pData->m_pObjectShell->GetStorage();
3739 }
3740 
addStorageChangeListener(const uno::Reference<document::XStorageChangeListener> & xListener)3741 void SAL_CALL SfxBaseModel::addStorageChangeListener(
3742             const uno::Reference< document::XStorageChangeListener >& xListener )
3743         throw ( uno::RuntimeException )
3744 {
3745     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3746 
3747 	m_pData->m_aInterfaceContainer.addInterface(
3748                                     ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3749 }
3750 
removeStorageChangeListener(const uno::Reference<document::XStorageChangeListener> & xListener)3751 void SAL_CALL SfxBaseModel::removeStorageChangeListener(
3752             const uno::Reference< document::XStorageChangeListener >& xListener )
3753         throw ( uno::RuntimeException )
3754 {
3755     SfxModelGuard aGuard( *this );
3756 
3757 	m_pData->m_aInterfaceContainer.removeInterface(
3758                                     ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3759 }
3760 
3761 #include "printhelper.hxx"
impl_getPrintHelper()3762 bool SfxBaseModel::impl_getPrintHelper()
3763 {
3764     if ( m_pData->m_xPrintable.is() )
3765         return true;
3766     m_pData->m_xPrintable = new SfxPrintHelper();
3767     uno::Reference < lang::XInitialization > xInit( m_pData->m_xPrintable, uno::UNO_QUERY );
3768     uno::Sequence < uno::Any > aValues(1);
3769     aValues[0] <<= uno::Reference < frame::XModel > (static_cast< frame::XModel* >(this), uno::UNO_QUERY );
3770     xInit->initialize( aValues );
3771     uno::Reference < view::XPrintJobBroadcaster > xBrd( m_pData->m_xPrintable, uno::UNO_QUERY );
3772     xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData ) );
3773     return true;
3774 }
3775 
3776 //=============================================================================
3777 // css.frame.XModule
setIdentifier(const::rtl::OUString & Identifier)3778  void SAL_CALL SfxBaseModel::setIdentifier(const ::rtl::OUString& Identifier)
3779     throw (css::uno::RuntimeException)
3780 {
3781     SfxModelGuard aGuard( *this );
3782     m_pData->m_sModuleIdentifier = Identifier;
3783 }
3784 
3785 //=============================================================================
3786 // css.frame.XModule
getIdentifier()3787  ::rtl::OUString SAL_CALL SfxBaseModel::getIdentifier()
3788     throw (css::uno::RuntimeException)
3789 {
3790     SfxModelGuard aGuard( *this );
3791     if (m_pData->m_sModuleIdentifier.getLength() > 0)
3792         return m_pData->m_sModuleIdentifier;
3793     if (m_pData->m_pObjectShell)
3794         return m_pData->m_pObjectShell->GetFactory().GetDocumentServiceName();
3795     return ::rtl::OUString();
3796 }
3797 
3798 //=============================================================================
impl_getTitleHelper()3799 css::uno::Reference< css::frame::XTitle > SfxBaseModel::impl_getTitleHelper ()
3800 {
3801     SfxModelGuard aGuard( *this );
3802 
3803     if ( ! m_pData->m_xTitleHelper.is ())
3804     {
3805         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR   = ::comphelper::getProcessServiceFactory ();
3806         css::uno::Reference< css::frame::XUntitledNumbers >    xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
3807         css::uno::Reference< css::frame::XModel >              xThis   (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3808 
3809         ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(xSMGR);
3810         m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3811         pHelper->setOwner                   (xThis   );
3812         pHelper->connectWithUntitledNumbers (xDesktop);
3813     }
3814 
3815     return m_pData->m_xTitleHelper;
3816 }
3817 
3818 //=============================================================================
impl_getUntitledHelper()3819 css::uno::Reference< css::frame::XUntitledNumbers > SfxBaseModel::impl_getUntitledHelper ()
3820 {
3821     SfxModelGuard aGuard( *this );
3822 
3823     if ( ! m_pData->m_xNumberedControllers.is ())
3824     {
3825         css::uno::Reference< css::frame::XModel > xThis   (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3826         ::comphelper::NumberedCollection*         pHelper = new ::comphelper::NumberedCollection();
3827 
3828         m_pData->m_xNumberedControllers = css::uno::Reference< css::frame::XUntitledNumbers >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3829 
3830         pHelper->setOwner          (xThis);
3831         pHelper->setUntitledPrefix (::rtl::OUString::createFromAscii(" : "));
3832     }
3833 
3834     return m_pData->m_xNumberedControllers;
3835 }
3836 
3837 //=============================================================================
3838 // css.frame.XTitle
getTitle()3839 ::rtl::OUString SAL_CALL SfxBaseModel::getTitle()
3840     throw (css::uno::RuntimeException)
3841 {
3842     // SYNCHRONIZED ->
3843     SfxModelGuard aGuard( *this );
3844 
3845     ::rtl::OUString aResult = impl_getTitleHelper()->getTitle ();
3846     if ( !m_pData->m_bExternalTitle && m_pData->m_pObjectShell )
3847     {
3848         SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
3849         if ( pMedium )
3850         {
3851             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
3852             if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
3853                 aResult += String( SfxResId(STR_REPAIREDDOCUMENT) );
3854         }
3855 
3856         if ( m_pData->m_pObjectShell->IsReadOnlyUI() || (pMedium && pMedium->IsReadOnly()) )
3857             aResult += ::rtl::OUString( String( SfxResId(STR_READONLY) ) );
3858         else if ( m_pData->m_pObjectShell->IsDocShared() )
3859             aResult += ::rtl::OUString( String( SfxResId(STR_SHARED) ) );
3860 
3861         if ( m_pData->m_pObjectShell->GetDocumentSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
3862             aResult += String( SfxResId( RID_XMLSEC_DOCUMENTSIGNED ) );
3863     }
3864 
3865     return aResult;
3866 }
3867 
3868 //=============================================================================
3869 // css.frame.XTitle
setTitle(const::rtl::OUString & sTitle)3870 void SAL_CALL SfxBaseModel::setTitle( const ::rtl::OUString& sTitle )
3871     throw (css::uno::RuntimeException)
3872 {
3873     // SYNCHRONIZED ->
3874     SfxModelGuard aGuard( *this );
3875 
3876     impl_getTitleHelper()->setTitle (sTitle);
3877     m_pData->m_bExternalTitle = sal_True;
3878 }
3879 
3880 //=============================================================================
3881 // css.frame.XTitleChangeBroadcaster
addTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)3882 void SAL_CALL SfxBaseModel::addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3883     throw (css::uno::RuntimeException)
3884 {
3885     // SYNCHRONIZED ->
3886     SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3887 
3888     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3889     if (xBroadcaster.is ())
3890         xBroadcaster->addTitleChangeListener (xListener);
3891 }
3892 
3893 //=============================================================================
3894 // css.frame.XTitleChangeBroadcaster
removeTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)3895 void SAL_CALL SfxBaseModel::removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3896     throw (css::uno::RuntimeException)
3897 {
3898     // SYNCHRONIZED ->
3899     SfxModelGuard aGuard( *this );
3900 
3901     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3902     if (xBroadcaster.is ())
3903         xBroadcaster->removeTitleChangeListener (xListener);
3904 }
3905 
3906 //=============================================================================
3907 // css.frame.XUntitledNumbers
leaseNumber(const css::uno::Reference<css::uno::XInterface> & xComponent)3908 ::sal_Int32 SAL_CALL SfxBaseModel::leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent )
3909     throw (css::lang::IllegalArgumentException,
3910            css::uno::RuntimeException         )
3911 {
3912     SfxModelGuard aGuard( *this );
3913 
3914     return impl_getUntitledHelper ()->leaseNumber (xComponent);
3915 }
3916 
3917 //=============================================================================
3918 // css.frame.XUntitledNumbers
releaseNumber(::sal_Int32 nNumber)3919 void SAL_CALL SfxBaseModel::releaseNumber( ::sal_Int32 nNumber )
3920     throw (css::lang::IllegalArgumentException,
3921            css::uno::RuntimeException         )
3922 {
3923     SfxModelGuard aGuard( *this );
3924     impl_getUntitledHelper ()->releaseNumber (nNumber);
3925 }
3926 
3927 //=============================================================================
3928 // css.frame.XUntitledNumbers
releaseNumberForComponent(const css::uno::Reference<css::uno::XInterface> & xComponent)3929 void SAL_CALL SfxBaseModel::releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent )
3930     throw (css::lang::IllegalArgumentException,
3931            css::uno::RuntimeException         )
3932 {
3933     SfxModelGuard aGuard( *this );
3934     impl_getUntitledHelper ()->releaseNumberForComponent (xComponent);
3935 }
3936 
3937 //=============================================================================
3938 // css.frame.XUntitledNumbers
getUntitledPrefix()3939 ::rtl::OUString SAL_CALL SfxBaseModel::getUntitledPrefix()
3940     throw (css::uno::RuntimeException)
3941 {
3942     SfxModelGuard aGuard( *this );
3943     return impl_getUntitledHelper ()->getUntitledPrefix ();
3944 }
3945 
3946 //=============================================================================
3947 // css::frame::XModel2
getControllers()3948 css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxBaseModel::getControllers()
3949     throw (css::uno::RuntimeException)
3950 {
3951     SfxModelGuard aGuard( *this );
3952 
3953     sal_Int32 c = m_pData->m_seqControllers.getLength();
3954     sal_Int32 i = 0;
3955     css::uno::Sequence< css::uno::Any > lEnum(c);
3956     for (i=0; i<c; ++i)
3957         lEnum[i] <<= m_pData->m_seqControllers[i];
3958 
3959     ::comphelper::OAnyEnumeration*                      pEnum = new ::comphelper::OAnyEnumeration(lEnum);
3960     css::uno::Reference< css::container::XEnumeration > xEnum(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY_THROW);
3961     return xEnum;
3962 }
3963 
3964 //=============================================================================
3965 // css::frame::XModel2
getAvailableViewControllerNames()3966 css::uno::Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getAvailableViewControllerNames()
3967     throw (css::uno::RuntimeException)
3968 {
3969     SfxModelGuard aGuard( *this );
3970 
3971     const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
3972     const sal_Int32 nViewFactoryCount = rDocumentFactory.GetViewFactoryCount();
3973 
3974     Sequence< ::rtl::OUString > aViewNames( nViewFactoryCount );
3975     for ( sal_Int32 nViewNo = 0; nViewNo < nViewFactoryCount; ++nViewNo )
3976         aViewNames[nViewNo] = rDocumentFactory.GetViewFactory( nViewNo ).GetAPIViewName();
3977     return aViewNames;
3978 }
3979 
3980 //=============================================================================
3981 // css::frame::XModel2
createDefaultViewController(const css::uno::Reference<css::frame::XFrame> & i_rFrame)3982 css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createDefaultViewController( const css::uno::Reference< css::frame::XFrame >& i_rFrame )
3983     throw (css::uno::RuntimeException         ,
3984            css::lang::IllegalArgumentException,
3985            css::uno::Exception                )
3986 {
3987     SfxModelGuard aGuard( *this );
3988 
3989     const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
3990     const ::rtl::OUString sDefaultViewName = rDocumentFactory.GetViewFactory( 0 ).GetAPIViewName();
3991 
3992     aGuard.clear();
3993 
3994     return createViewController( sDefaultViewName, Sequence< PropertyValue >(), i_rFrame );
3995 }
3996 
3997 //=============================================================================
3998 namespace sfx { namespace intern {
3999 
4000     /** a class which, in its dtor, cleans up variuos objects (well, at the moment only the frame) collected during
4001         the creation of a document view, unless the creation was successful.
4002     */
4003     class SAL_DLLPRIVATE ViewCreationGuard
4004     {
4005     public:
ViewCreationGuard()4006         ViewCreationGuard()
4007             :m_bSuccess( false )
4008         {
4009         }
4010 
~ViewCreationGuard()4011         ~ViewCreationGuard()
4012         {
4013             if ( !m_bSuccess )
4014                 impl_closeAll();
4015         }
4016 
takeFrameOwnership(SfxFrame * i_pFrame)4017         void takeFrameOwnership( SfxFrame* i_pFrame )
4018         {
4019             OSL_PRECOND( !m_aWeakFrame, "ViewCreationGuard::takeFrameOwnership: already have a frame!" );
4020             OSL_PRECOND( i_pFrame != NULL, "ViewCreationGuard::takeFrameOwnership: invalid frame!" );
4021             m_aWeakFrame = i_pFrame;
4022         }
4023 
releaseAll()4024         void    releaseAll()
4025         {
4026             m_bSuccess = true;
4027         }
4028 
4029     private:
impl_closeAll()4030         void impl_closeAll()
4031         {
4032             if ( m_aWeakFrame && !m_aWeakFrame->GetCurrentDocument() )
4033             {
4034                 m_aWeakFrame->SetFrameInterface_Impl( NULL );
4035                 m_aWeakFrame->DoClose();
4036             }
4037         }
4038 
4039     private:
4040         bool            m_bSuccess;
4041         SfxFrameWeak    m_aWeakFrame;
4042     };
4043 } }
4044 
4045 //=============================================================================
FindOrCreateViewFrame_Impl(const Reference<XFrame> & i_rFrame,::sfx::intern::ViewCreationGuard & i_rGuard) const4046 SfxViewFrame* SfxBaseModel::FindOrCreateViewFrame_Impl( const Reference< XFrame >& i_rFrame, ::sfx::intern::ViewCreationGuard& i_rGuard ) const
4047 {
4048     SfxViewFrame* pViewFrame = NULL;
4049     for (   pViewFrame = SfxViewFrame::GetFirst( GetObjectShell(), sal_False );
4050             pViewFrame;
4051             pViewFrame= SfxViewFrame::GetNext( *pViewFrame, GetObjectShell(), sal_False )
4052         )
4053     {
4054         if ( pViewFrame->GetFrame().GetFrameInterface() == i_rFrame )
4055             break;
4056     }
4057     if ( !pViewFrame )
4058     {
4059     #if OSL_DEBUG_LEVEL > 0
4060         for (   SfxFrame* pCheckFrame = SfxFrame::GetFirst();
4061                 pCheckFrame;
4062                 pCheckFrame = SfxFrame::GetNext( *pCheckFrame )
4063              )
4064         {
4065             if ( pCheckFrame->GetFrameInterface() == i_rFrame )
4066             {
4067                 if  (   ( pCheckFrame->GetCurrentViewFrame() != NULL )
4068                     ||  ( pCheckFrame->GetCurrentDocument() != NULL )
4069                     )
4070                     // Note that it is perfectly letgitimate that during loading into an XFrame which already contains
4071                     // a document, there exist two SfxFrame instances bound to this XFrame - the old one, which will be
4072                     // destroyed later, and the new one, which we're going to create
4073                     continue;
4074 
4075                 OSL_ENSURE( false, "SfxBaseModel::FindOrCreateViewFrame_Impl: there already is an SfxFrame for the given XFrame, but no view in it!" );
4076                     // nowadays, we're the only instance allowed to create an SfxFrame for an XFrame, so this case here should not happen
4077                 break;
4078             }
4079         }
4080     #endif
4081 
4082         SfxFrame* pTargetFrame = SfxFrame::Create( i_rFrame );
4083         ENSURE_OR_THROW( pTargetFrame, "could not create an SfxFrame" );
4084         i_rGuard.takeFrameOwnership( pTargetFrame );
4085 
4086         // prepare it
4087         pTargetFrame->PrepareForDoc_Impl( *GetObjectShell() );
4088 
4089         // create view frame
4090         pViewFrame = new SfxViewFrame( *pTargetFrame, GetObjectShell() );
4091     }
4092     return pViewFrame;
4093 }
4094 
4095 //=============================================================================
4096 // css::frame::XModel2
createViewController(const::rtl::OUString & i_rViewName,const Sequence<PropertyValue> & i_rArguments,const Reference<XFrame> & i_rFrame)4097 css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createViewController(
4098         const ::rtl::OUString& i_rViewName, const Sequence< PropertyValue >& i_rArguments, const Reference< XFrame >& i_rFrame )
4099     throw (css::uno::RuntimeException         ,
4100            css::lang::IllegalArgumentException,
4101            css::uno::Exception                )
4102 {
4103     SfxModelGuard aGuard( *this );
4104 
4105     if ( !i_rFrame.is() )
4106         throw css::lang::IllegalArgumentException( ::rtl::OUString(), *this, 3 );
4107 
4108     // find the proper SFX view factory
4109     SfxViewFactory* pViewFactory = GetObjectShell()->GetFactory().GetViewFactoryByViewName( i_rViewName );
4110     if ( !pViewFactory )
4111         throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
4112 
4113     // determine previous shell (used in some special cases)
4114     Reference< XController > xPreviousController( i_rFrame->getController() );
4115     const Reference< XModel > xMe( this );
4116     if  (   ( xPreviousController.is() )
4117         &&  ( xMe != xPreviousController->getModel() )
4118         )
4119     {
4120         xPreviousController.clear();
4121     }
4122     SfxViewShell* pOldViewShell = SfxViewShell::Get( xPreviousController );
4123     OSL_ENSURE( !xPreviousController.is() || ( pOldViewShell != NULL ),
4124         "SfxBaseModel::createViewController: invalid old controller!" );
4125 
4126     // a guard which will clean up in case of failure
4127     ::sfx::intern::ViewCreationGuard aViewCreationGuard;
4128 
4129     // determine the ViewFrame belonging to the given XFrame
4130     SfxViewFrame* pViewFrame = FindOrCreateViewFrame_Impl( i_rFrame, aViewCreationGuard );
4131     OSL_POSTCOND( pViewFrame, "SfxBaseModel::createViewController: no frame?" );
4132 
4133     // delegate to SFX' view factory
4134     pViewFrame->GetBindings().ENTERREGISTRATIONS();
4135     SfxViewShell* pViewShell = pViewFactory->CreateInstance( pViewFrame, pOldViewShell );
4136     pViewFrame->GetBindings().LEAVEREGISTRATIONS();
4137     ENSURE_OR_THROW( pViewShell, "invalid view shell provided by factory" );
4138 
4139     // by setting the ViewShell it is prevented that disposing the Controller will destroy this ViewFrame also
4140     pViewFrame->GetDispatcher()->SetDisableFlags( 0 );
4141     pViewFrame->SetViewShell_Impl( pViewShell );
4142 
4143     // remember ViewID
4144     pViewFrame->SetCurViewId_Impl( pViewFactory->GetOrdinal() );
4145 
4146     // ensure a default controller, if the view shell did not provide an own implementation
4147     if ( !pViewShell->GetController().is() )
4148         pViewShell->SetController( new SfxBaseController( pViewShell ) );
4149 
4150     // pass the creation arguments to the controller
4151     SfxBaseController* pBaseController = pViewShell->GetBaseController_Impl();
4152     ENSURE_OR_THROW( pBaseController, "invalid controller implementation!" );
4153     pBaseController->SetCreationArguments_Impl( i_rArguments );
4154 
4155     // some initial view settings, coming from our most recent attachResource call
4156     ::comphelper::NamedValueCollection aDocumentLoadArgs( getArgs() );
4157     if ( aDocumentLoadArgs.getOrDefault( "ViewOnly", false ) )
4158 	    pViewFrame->GetFrame().SetMenuBarOn_Impl( sal_False );
4159 
4160     const sal_Int16 nPluginMode = aDocumentLoadArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
4161     if ( nPluginMode == 1 )
4162     {
4163         pViewFrame->ForceOuterResize_Impl( sal_False );
4164         pViewFrame->GetBindings().HidePopups( sal_True );
4165 
4166         SfxFrame& rFrame = pViewFrame->GetFrame();
4167         // MBA: layoutmanager of inplace frame starts locked and invisible
4168         rFrame.GetWorkWindow_Impl()->MakeVisible_Impl( sal_False );
4169         rFrame.GetWorkWindow_Impl()->Lock_Impl( sal_True );
4170 
4171         rFrame.GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4172         pViewFrame->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4173     }
4174 
4175     // tell the guard we were successful
4176     aViewCreationGuard.releaseAll();
4177 
4178     // outta gere
4179     return pBaseController;
4180 }
4181 
4182 //=============================================================================
4183 // RDF DocumentMetadataAccess
4184 
4185 // ::com::sun::star::rdf::XRepositorySupplier:
4186 uno::Reference< rdf::XRepository > SAL_CALL
getRDFRepository()4187 SfxBaseModel::getRDFRepository() throw (uno::RuntimeException)
4188 {
4189     SfxModelGuard aGuard( *this );
4190 
4191     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4192     if (!xDMA.is()) {
4193         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4194             "model has no document metadata"), *this );
4195     }
4196 
4197     return xDMA->getRDFRepository();
4198 }
4199 
4200 // ::com::sun::star::rdf::XNode:
4201 ::rtl::OUString SAL_CALL
getStringValue()4202 SfxBaseModel::getStringValue() throw (uno::RuntimeException)
4203 {
4204     SfxModelGuard aGuard( *this );
4205 
4206     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4207     if (!xDMA.is()) {
4208         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4209             "model has no document metadata"), *this );
4210     }
4211 
4212     return xDMA->getStringValue();
4213 }
4214 
4215 // ::com::sun::star::rdf::XURI:
4216 ::rtl::OUString SAL_CALL
getNamespace()4217 SfxBaseModel::getNamespace() throw (uno::RuntimeException)
4218 {
4219     SfxModelGuard aGuard( *this );
4220 
4221     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4222     if (!xDMA.is()) {
4223         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4224             "model has no document metadata"), *this );
4225     }
4226 
4227     return xDMA->getNamespace();
4228 }
4229 
4230 ::rtl::OUString SAL_CALL
getLocalName()4231 SfxBaseModel::getLocalName() throw (uno::RuntimeException)
4232 {
4233     SfxModelGuard aGuard( *this );
4234 
4235     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4236     if (!xDMA.is()) {
4237         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4238             "model has no document metadata"), *this );
4239     }
4240 
4241     return xDMA->getLocalName();
4242 }
4243 
4244 // ::com::sun::star::rdf::XDocumentMetadataAccess:
4245 uno::Reference< rdf::XMetadatable > SAL_CALL
getElementByMetadataReference(const::com::sun::star::beans::StringPair & i_rReference)4246 SfxBaseModel::getElementByMetadataReference(
4247     const ::com::sun::star::beans::StringPair & i_rReference)
4248 throw (uno::RuntimeException)
4249 {
4250     SfxModelGuard aGuard( *this );
4251 
4252     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4253     if (!xDMA.is()) {
4254         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4255             "model has no document metadata"), *this );
4256     }
4257 
4258     return xDMA->getElementByMetadataReference(i_rReference);
4259 }
4260 
4261 uno::Reference< rdf::XMetadatable > SAL_CALL
getElementByURI(const uno::Reference<rdf::XURI> & i_xURI)4262 SfxBaseModel::getElementByURI(const uno::Reference< rdf::XURI > & i_xURI)
4263 throw (uno::RuntimeException, lang::IllegalArgumentException)
4264 {
4265     SfxModelGuard aGuard( *this );
4266 
4267     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4268     if (!xDMA.is()) {
4269         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4270             "model has no document metadata"), *this );
4271     }
4272 
4273     return xDMA->getElementByURI(i_xURI);
4274 }
4275 
4276 uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
getMetadataGraphsWithType(const uno::Reference<rdf::XURI> & i_xType)4277 SfxBaseModel::getMetadataGraphsWithType(
4278     const uno::Reference<rdf::XURI> & i_xType)
4279 throw (uno::RuntimeException, lang::IllegalArgumentException)
4280 {
4281     SfxModelGuard aGuard( *this );
4282 
4283     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4284     if (!xDMA.is()) {
4285         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4286             "model has no document metadata"), *this );
4287     }
4288 
4289     return xDMA->getMetadataGraphsWithType(i_xType);
4290 }
4291 
4292 uno::Reference<rdf::XURI> SAL_CALL
addMetadataFile(const::rtl::OUString & i_rFileName,const uno::Sequence<uno::Reference<rdf::XURI>> & i_rTypes)4293 SfxBaseModel::addMetadataFile(const ::rtl::OUString & i_rFileName,
4294     const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4295 throw (uno::RuntimeException, lang::IllegalArgumentException,
4296     container::ElementExistException)
4297 {
4298     SfxModelGuard aGuard( *this );
4299 
4300     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4301     if (!xDMA.is()) {
4302         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4303             "model has no document metadata"), *this );
4304     }
4305 
4306     return xDMA->addMetadataFile(i_rFileName, i_rTypes);
4307 }
4308 
4309 uno::Reference<rdf::XURI> SAL_CALL
importMetadataFile(::sal_Int16 i_Format,const uno::Reference<io::XInputStream> & i_xInStream,const::rtl::OUString & i_rFileName,const uno::Reference<rdf::XURI> & i_xBaseURI,const uno::Sequence<uno::Reference<rdf::XURI>> & i_rTypes)4310 SfxBaseModel::importMetadataFile(::sal_Int16 i_Format,
4311     const uno::Reference< io::XInputStream > & i_xInStream,
4312     const ::rtl::OUString & i_rFileName,
4313     const uno::Reference< rdf::XURI > & i_xBaseURI,
4314     const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4315 throw (uno::RuntimeException, lang::IllegalArgumentException,
4316     datatransfer::UnsupportedFlavorException,
4317     container::ElementExistException, rdf::ParseException, io::IOException)
4318 {
4319     SfxModelGuard aGuard( *this );
4320 
4321     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4322     if (!xDMA.is()) {
4323         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4324             "model has no document metadata"), *this );
4325     }
4326 
4327     return xDMA->importMetadataFile(i_Format,
4328         i_xInStream, i_rFileName, i_xBaseURI, i_rTypes);
4329 }
4330 
4331 void SAL_CALL
removeMetadataFile(const uno::Reference<rdf::XURI> & i_xGraphName)4332 SfxBaseModel::removeMetadataFile(
4333     const uno::Reference< rdf::XURI > & i_xGraphName)
4334 throw (uno::RuntimeException, lang::IllegalArgumentException,
4335     container::NoSuchElementException)
4336 {
4337     SfxModelGuard aGuard( *this );
4338 
4339     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4340     if (!xDMA.is()) {
4341         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4342             "model has no document metadata"), *this );
4343     }
4344 
4345     return xDMA->removeMetadataFile(i_xGraphName);
4346 }
4347 
4348 void SAL_CALL
addContentOrStylesFile(const::rtl::OUString & i_rFileName)4349 SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4350 throw (uno::RuntimeException, lang::IllegalArgumentException,
4351     container::ElementExistException)
4352 {
4353     SfxModelGuard aGuard( *this );
4354 
4355     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4356     if (!xDMA.is()) {
4357         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4358             "model has no document metadata"), *this );
4359     }
4360 
4361     return xDMA->addContentOrStylesFile(i_rFileName);
4362 }
4363 
4364 void SAL_CALL
removeContentOrStylesFile(const::rtl::OUString & i_rFileName)4365 SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4366 throw (uno::RuntimeException, lang::IllegalArgumentException,
4367     container::NoSuchElementException)
4368 {
4369     SfxModelGuard aGuard( *this );
4370 
4371     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4372     if (!xDMA.is()) {
4373         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4374             "model has no document metadata"), *this );
4375     }
4376 
4377     return xDMA->removeContentOrStylesFile(i_rFileName);
4378 }
4379 
4380 void SAL_CALL
loadMetadataFromStorage(uno::Reference<embed::XStorage> const & i_xStorage,uno::Reference<rdf::XURI> const & i_xBaseURI,uno::Reference<task::XInteractionHandler> const & i_xHandler)4381 SfxBaseModel::loadMetadataFromStorage(
4382     uno::Reference< embed::XStorage > const & i_xStorage,
4383     uno::Reference<rdf::XURI> const & i_xBaseURI,
4384     uno::Reference<task::XInteractionHandler> const & i_xHandler)
4385 throw (uno::RuntimeException, lang::IllegalArgumentException,
4386     lang::WrappedTargetException)
4387 {
4388     SfxModelGuard aGuard( *this );
4389 
4390     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4391         m_pData->CreateDMAUninitialized());
4392     if (!xDMA.is()) {
4393         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4394             "model has no document metadata"), *this );
4395     }
4396 
4397     try {
4398         xDMA->loadMetadataFromStorage(i_xStorage, i_xBaseURI, i_xHandler);
4399     } catch (lang::IllegalArgumentException &) {
4400         throw; // not initialized
4401     } catch (uno::Exception &) {
4402         // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4403         m_pData->m_xDocumentMetadata = xDMA;
4404         throw;
4405     }
4406     m_pData->m_xDocumentMetadata = xDMA;
4407 
4408 }
4409 
4410 void SAL_CALL
storeMetadataToStorage(uno::Reference<embed::XStorage> const & i_xStorage)4411 SfxBaseModel::storeMetadataToStorage(
4412     uno::Reference< embed::XStorage > const & i_xStorage)
4413 throw (uno::RuntimeException, lang::IllegalArgumentException,
4414     lang::WrappedTargetException)
4415 {
4416     SfxModelGuard aGuard( *this );
4417 
4418     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4419     if (!xDMA.is()) {
4420         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4421             "model has no document metadata"), *this );
4422     }
4423 
4424     return xDMA->storeMetadataToStorage(i_xStorage);
4425 }
4426 
4427 void SAL_CALL
loadMetadataFromMedium(const uno::Sequence<beans::PropertyValue> & i_rMedium)4428 SfxBaseModel::loadMetadataFromMedium(
4429     const uno::Sequence< beans::PropertyValue > & i_rMedium)
4430 throw (uno::RuntimeException, lang::IllegalArgumentException,
4431     lang::WrappedTargetException)
4432 {
4433     SfxModelGuard aGuard( *this );
4434 
4435     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4436         m_pData->CreateDMAUninitialized());
4437     if (!xDMA.is()) {
4438         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4439             "model has no document metadata"), *this );
4440     }
4441 
4442     try {
4443         xDMA->loadMetadataFromMedium(i_rMedium);
4444     } catch (lang::IllegalArgumentException &) {
4445         throw; // not initialized
4446     } catch (uno::Exception &) {
4447         // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4448         m_pData->m_xDocumentMetadata = xDMA;
4449         throw;
4450     }
4451     m_pData->m_xDocumentMetadata = xDMA;
4452 }
4453 
4454 void SAL_CALL
storeMetadataToMedium(const uno::Sequence<beans::PropertyValue> & i_rMedium)4455 SfxBaseModel::storeMetadataToMedium(
4456     const uno::Sequence< beans::PropertyValue > & i_rMedium)
4457 throw (uno::RuntimeException, lang::IllegalArgumentException,
4458     lang::WrappedTargetException)
4459 {
4460     SfxModelGuard aGuard( *this );
4461 
4462     const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4463     if (!xDMA.is()) {
4464         throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4465             "model has no document metadata"), *this );
4466     }
4467 
4468     return xDMA->storeMetadataToMedium(i_rMedium);
4469 }
4470 
4471 // =====================================================================================================================
4472 // = SfxModelSubComponent
4473 // =====================================================================================================================
4474 
~SfxModelSubComponent()4475 SfxModelSubComponent::~SfxModelSubComponent()
4476 {
4477 }
4478 
disposing()4479 void SfxModelSubComponent::disposing()
4480 {
4481     // nothing to do here
4482 }
4483 
4484