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 // can't accept that. Close(sal_False) can't 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), xDocListener );
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("Can't 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 sense
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( "image/svg+xml" ) )
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_SVG ) );
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( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
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_BMP ) );
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 if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
2227 {
2228 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2229 {
2230 ::boost::shared_ptr<GDIMetaFile> pMetaFile =
2231 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
2232
2233 if ( pMetaFile )
2234 {
2235 ::boost::shared_ptr<SvMemoryStream> pStream(
2236 GraphicHelper::getFormatStrFromGDI_Impl(
2237 pMetaFile.get(), CVT_PNG ) );
2238
2239 if ( pStream )
2240 {
2241 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
2242 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
2243 pStream->Seek( STREAM_SEEK_TO_END ) );
2244 }
2245 }
2246 }
2247 else
2248 throw datatransfer::UnsupportedFlavorException();
2249 }
2250 else
2251 throw datatransfer::UnsupportedFlavorException();
2252 }
2253
2254 return aAny;
2255 }
2256
2257 //________________________________________________________________________________________________________
2258 // XTransferable
2259 //________________________________________________________________________________________________________
2260
2261
getTransferDataFlavors()2262 uno::Sequence< DATAFLAVOR > SAL_CALL SfxBaseModel::getTransferDataFlavors()
2263 throw (::com::sun::star::uno::RuntimeException)
2264 {
2265 SfxModelGuard aGuard( *this );
2266
2267 sal_Int32 nSuppFlavors = GraphicHelper::supportsMetaFileHandle_Impl() ? 11 : 9;
2268 uno::Sequence< DATAFLAVOR > aFlavorSeq( nSuppFlavors );
2269
2270 aFlavorSeq[0].MimeType =
2271 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2272 aFlavorSeq[0].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2273 aFlavorSeq[0].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2274
2275 aFlavorSeq[1].MimeType =
2276 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
2277 aFlavorSeq[1].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
2278 aFlavorSeq[1].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2279
2280 aFlavorSeq[2].MimeType =
2281 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2282 aFlavorSeq[2].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2283 aFlavorSeq[2].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2284
2285 aFlavorSeq[3].MimeType =
2286 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2287 aFlavorSeq[3].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2288 aFlavorSeq[3].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2289
2290 aFlavorSeq[4].MimeType =
2291 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) );
2292 aFlavorSeq[4].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Object Descriptor (XML)" ) );
2293 aFlavorSeq[4].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2294
2295 aFlavorSeq[5].MimeType =
2296 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"" ) );
2297 aFlavorSeq[5].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Embed Source (XML)" ) );
2298 aFlavorSeq[5].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2299
2300 aFlavorSeq[6].MimeType =
2301 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) );
2302 aFlavorSeq[6].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ) );
2303 aFlavorSeq[6].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2304
2305 aFlavorSeq[7].MimeType =
2306 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) );
2307 aFlavorSeq[7].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PNG" ) );
2308 aFlavorSeq[7].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2309
2310 aFlavorSeq[8].MimeType =
2311 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/svg+xml" ) );
2312 aFlavorSeq[8].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SVG" ) );
2313 aFlavorSeq[8].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
2314
2315 if ( nSuppFlavors == 11 )
2316 {
2317 aFlavorSeq[9].MimeType =
2318 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
2319 aFlavorSeq[9].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
2320 aFlavorSeq[9].DataType = getCppuType( (const sal_uInt64*) 0 );
2321
2322 aFlavorSeq[10].MimeType =
2323 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
2324 aFlavorSeq[10].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
2325 aFlavorSeq[10].DataType = getCppuType( (const sal_uInt64*) 0 );
2326 }
2327
2328 return aFlavorSeq;
2329 }
2330
2331 //________________________________________________________________________________________________________
2332 // XTransferable
2333 //________________________________________________________________________________________________________
2334
2335
isDataFlavorSupported(const DATAFLAVOR & aFlavor)2336 sal_Bool SAL_CALL SfxBaseModel::isDataFlavorSupported( const DATAFLAVOR& aFlavor )
2337 throw (::com::sun::star::uno::RuntimeException)
2338 {
2339 SfxModelGuard aGuard( *this );
2340
2341 if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2342 {
2343 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2344 return sal_True;
2345 }
2346 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
2347 {
2348 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2349 return sal_True;
2350 }
2351 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
2352 {
2353 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2354 return sal_True;
2355 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2356 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2357 return sal_True;
2358 }
2359 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
2360 {
2361 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2362 return sal_True;
2363 else if ( GraphicHelper::supportsMetaFileHandle_Impl()
2364 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
2365 return sal_True;
2366 }
2367 else if ( aFlavor.MimeType.equalsAscii( "image/svg+xml" ) )
2368 {
2369 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2370 return sal_True;
2371 }
2372 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
2373 {
2374 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2375 return sal_True;
2376 }
2377 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
2378 {
2379 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2380 return sal_True;
2381 }
2382 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
2383 {
2384 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2385 return sal_True;
2386 }
2387 else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
2388 {
2389 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
2390 return sal_True;
2391 }
2392
2393 return sal_False;
2394 }
2395
2396
2397 //--------------------------------------------------------------------------------------------------------
2398 // XEventsSupplier
2399 //--------------------------------------------------------------------------------------------------------
2400
getEvents()2401 uno::Reference< container::XNameReplace > SAL_CALL SfxBaseModel::getEvents() throw( uno::RuntimeException )
2402 {
2403 SfxModelGuard aGuard( *this );
2404
2405 if ( ! m_pData->m_xEvents.is() )
2406 {
2407 m_pData->m_xEvents = new SfxEvents_Impl( m_pData->m_pObjectShell, this );
2408 }
2409
2410 return m_pData->m_xEvents;
2411 }
2412
2413 //--------------------------------------------------------------------------------------------------------
2414 // XEmbeddedScripts
2415 //--------------------------------------------------------------------------------------------------------
2416
getBasicLibraries()2417 uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getBasicLibraries() throw (RuntimeException)
2418 {
2419 SfxModelGuard aGuard( *this );
2420
2421 uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries;
2422 if ( m_pData->m_pObjectShell )
2423 xBasicLibraries.set( m_pData->m_pObjectShell->GetBasicContainer(), UNO_QUERY_THROW );
2424 return xBasicLibraries;
2425 }
2426
getDialogLibraries()2427 uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getDialogLibraries() throw (RuntimeException)
2428 {
2429 SfxModelGuard aGuard( *this );
2430
2431 uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries;
2432 if ( m_pData->m_pObjectShell )
2433 xDialogLibraries.set( m_pData->m_pObjectShell->GetDialogContainer(), UNO_QUERY_THROW );
2434 return xDialogLibraries;
2435 }
2436
getAllowMacroExecution()2437 ::sal_Bool SAL_CALL SfxBaseModel::getAllowMacroExecution() throw (RuntimeException)
2438 {
2439 SfxModelGuard aGuard( *this );
2440
2441 if ( m_pData->m_pObjectShell )
2442 return m_pData->m_pObjectShell->AdjustMacroMode( String(), false );
2443 return sal_False;
2444 }
2445
2446 //--------------------------------------------------------------------------------------------------------
2447 // XScriptInvocationContext
2448 //--------------------------------------------------------------------------------------------------------
2449
getScriptContainer()2450 Reference< document::XEmbeddedScripts > SAL_CALL SfxBaseModel::getScriptContainer() throw (RuntimeException)
2451 {
2452 SfxModelGuard aGuard( *this );
2453
2454 Reference< document::XEmbeddedScripts > xDocumentScripts;
2455
2456 try
2457 {
2458 Reference< frame::XModel > xDocument( this );
2459 xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2460 while ( !xDocumentScripts.is() && xDocument.is() )
2461 {
2462 Reference< container::XChild > xDocAsChild( xDocument, uno::UNO_QUERY );
2463 if ( !xDocAsChild.is() )
2464 {
2465 xDocument = NULL;
2466 break;
2467 }
2468
2469 xDocument.set( xDocAsChild->getParent(), uno::UNO_QUERY );
2470 xDocumentScripts.set( xDocument, uno::UNO_QUERY );
2471 }
2472 }
2473 catch( const Exception& )
2474 {
2475 DBG_UNHANDLED_EXCEPTION();
2476 xDocumentScripts = NULL;
2477 }
2478
2479 return xDocumentScripts;
2480 }
2481
2482 //--------------------------------------------------------------------------------------------------------
2483 // XEventBroadcaster
2484 //--------------------------------------------------------------------------------------------------------
2485
addEventListener(const uno::Reference<XDOCEVENTLISTENER> & aListener)2486 void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2487 {
2488 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2489
2490 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2491 }
2492
2493 //--------------------------------------------------------------------------------------------------------
2494 // XEventBroadcaster
2495 //--------------------------------------------------------------------------------------------------------
2496
removeEventListener(const uno::Reference<XDOCEVENTLISTENER> & aListener)2497 void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
2498 {
2499 SfxModelGuard aGuard( *this );
2500
2501 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
2502 }
2503
2504 //--------------------------------------------------------------------------------------------------------
2505 // XDocumentEventBroadcaster
2506 //--------------------------------------------------------------------------------------------------------
2507 // ---------------------------------
addDocumentEventListener(const uno::Reference<document::XDocumentEventListener> & aListener)2508 void SAL_CALL SfxBaseModel::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2509 throw ( uno::RuntimeException )
2510 {
2511 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
2512 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2513 }
2514
2515 // ---------------------------------
removeDocumentEventListener(const uno::Reference<document::XDocumentEventListener> & aListener)2516 void SAL_CALL SfxBaseModel::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
2517 throw ( uno::RuntimeException )
2518 {
2519 SfxModelGuard aGuard( *this );
2520 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
2521 }
2522
2523 // ---------------------------------
notifyDocumentEvent(const::rtl::OUString &,const uno::Reference<frame::XController2> &,const uno::Any &)2524 void SAL_CALL SfxBaseModel::notifyDocumentEvent( const ::rtl::OUString&, const uno::Reference< frame::XController2 >&, const uno::Any& )
2525 throw ( lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException )
2526 {
2527 throw lang::NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SfxBaseModel controls all the sent notifications itself!" ) ), uno::Reference< uno::XInterface >() );
2528 }
2529
2530 //________________________________________________________________________________________________________
2531 // SfxListener
2532 //________________________________________________________________________________________________________
2533
addTitle_Impl(Sequence<::com::sun::star::beans::PropertyValue> & rSeq,const::rtl::OUString & rTitle)2534 void addTitle_Impl( Sequence < ::com::sun::star::beans::PropertyValue >& rSeq, const ::rtl::OUString& rTitle )
2535 {
2536 sal_Int32 nCount = rSeq.getLength();
2537 sal_Int32 nArg;
2538
2539 for ( nArg = 0; nArg < nCount; nArg++ )
2540 {
2541 ::com::sun::star::beans::PropertyValue& rProp = rSeq[nArg];
2542 if ( rProp.Name.equalsAscii("Title") )
2543 {
2544 rProp.Value <<= rTitle;
2545 break;
2546 }
2547 }
2548
2549 if ( nArg == nCount )
2550 {
2551 rSeq.realloc( nCount+1 );
2552 rSeq[nCount].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") );
2553 rSeq[nCount].Value <<= rTitle;
2554 }
2555 }
2556
NotifyStorageListeners_Impl()2557 void SfxBaseModel::NotifyStorageListeners_Impl()
2558 {
2559 uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
2560
2561 if ( m_pData->m_pObjectShell )
2562 {
2563 ::cppu::OInterfaceContainerHelper* pContainer =
2564 m_pData->m_aInterfaceContainer.getContainer(
2565 ::getCppuType( ( const uno::Reference< document::XStorageChangeListener >*) NULL ) );
2566 if ( pContainer != NULL )
2567 {
2568 uno::Reference< embed::XStorage > xNewStorage = m_pData->m_pObjectShell->GetStorage();
2569 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
2570 while ( pIterator.hasMoreElements() )
2571 {
2572 try
2573 {
2574 ((document::XStorageChangeListener*)pIterator.next())->notifyStorageChange(
2575 xSelfHold,
2576 xNewStorage );
2577 }
2578 catch( uno::RuntimeException& )
2579 {
2580 pIterator.remove();
2581 }
2582 }
2583 }
2584 }
2585 }
2586
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)2587 void SfxBaseModel::Notify( SfxBroadcaster& rBC ,
2588 const SfxHint& rHint )
2589 {
2590 if ( !m_pData )
2591 return;
2592
2593 if ( &rBC == m_pData->m_pObjectShell )
2594 {
2595 SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
2596 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DOCCHANGED )
2597 changing();
2598
2599 SfxEventHint* pNamedHint = PTR_CAST( SfxEventHint, &rHint );
2600 if ( pNamedHint )
2601 {
2602
2603 switch ( pNamedHint->GetEventId() )
2604 {
2605 case SFX_EVENT_STORAGECHANGED:
2606 {
2607 // for now this event is sent only on creation of a new storage for new document
2608 // and in case of reload of medium without document reload
2609 // other events are used to detect storage change
2610 // NotifyStorageListeners_Impl();
2611
2612 if ( m_pData->m_xUIConfigurationManager.is()
2613 && m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
2614 {
2615 uno::Reference< XSTORAGE > xConfigStorage;
2616 rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
2617
2618 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READWRITE );
2619 if ( !xConfigStorage.is() )
2620 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READ );
2621
2622 if ( xConfigStorage.is() || !m_pData->m_pObjectShell->GetStorage()->hasByName( aUIConfigFolderName ) )
2623 {
2624 // the storage is different, since otherwise it could not be opened, so it must be exchanged
2625 Reference< ui::XUIConfigurationStorage > xUIConfigStorage( m_pData->m_xUIConfigurationManager, uno::UNO_QUERY );
2626 xUIConfigStorage->setStorage( xConfigStorage );
2627 }
2628 else
2629 {
2630 OSL_ENSURE( sal_False, "Unexpected scenario!\n" );
2631 }
2632 }
2633
2634 ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2635 }
2636 break;
2637
2638 case SFX_EVENT_LOADFINISHED:
2639 {
2640 impl_getPrintHelper();
2641 ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
2642 m_pData->m_bModifiedSinceLastSave = sal_False;
2643 }
2644 break;
2645
2646 case SFX_EVENT_SAVEASDOCDONE:
2647 {
2648 m_pData->m_sURL = m_pData->m_pObjectShell->GetMedium()->GetName();
2649
2650 SfxItemSet *pSet = m_pData->m_pObjectShell->GetMedium()->GetItemSet();
2651 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
2652 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2653 TransformItems( SID_SAVEASDOC, *pSet, aArgs );
2654 addTitle_Impl( aArgs, aTitle );
2655 attachResource( m_pData->m_pObjectShell->GetMedium()->GetName(), aArgs );
2656 }
2657 break;
2658
2659 case SFX_EVENT_DOCCREATED:
2660 {
2661 impl_getPrintHelper();
2662 m_pData->m_bModifiedSinceLastSave = sal_False;
2663 }
2664 break;
2665
2666 case SFX_EVENT_MODIFYCHANGED:
2667 {
2668 m_pData->m_bModifiedSinceLastSave = isModified();
2669 }
2670 break;
2671 }
2672
2673
2674 SfxViewEventHint* pViewHint = PTR_CAST( SfxViewEventHint, &rHint );
2675 postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? pViewHint->GetController() : uno::Reference< frame::XController2 >() );
2676 }
2677
2678 if ( pSimpleHint )
2679 {
2680 if ( pSimpleHint->GetId() == SFX_HINT_TITLECHANGED )
2681 {
2682 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
2683 addTitle_Impl( m_pData->m_seqArguments, aTitle );
2684 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_TITLECHANGED ) );
2685 }
2686 if ( pSimpleHint->GetId() == SFX_HINT_MODECHANGED )
2687 {
2688 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_MODECHANGED ) );
2689 }
2690 /*
2691 else if ( pSimpleHint->GetId() == SFX_HINT_DYING
2692 || pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
2693 {
2694 SfxObjectShellLock pShellLock = m_pData->m_pObjectShellLock;
2695 m_pData->m_pObjectShellLock = SfxObjectShellLock();
2696 }
2697 */
2698 }
2699 }
2700 }
2701
2702 //________________________________________________________________________________________________________
2703 // public impl.
2704 //________________________________________________________________________________________________________
2705
NotifyModifyListeners_Impl() const2706 void SfxBaseModel::NotifyModifyListeners_Impl() const
2707 {
2708 ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0) );
2709 if ( pIC )
2710 {
2711 lang::EventObject aEvent( (frame::XModel *)this );
2712 pIC->notifyEach( &util::XModifyListener::modified, aEvent );
2713 }
2714
2715 // this notification here is done too generously, we cannot simply assume that we're really modified
2716 // now, but we need to check it ...
2717 m_pData->m_bModifiedSinceLastSave = const_cast< SfxBaseModel* >( this )->isModified();
2718 }
2719
changing()2720 void SfxBaseModel::changing()
2721 {
2722 SfxModelGuard aGuard( *this );
2723
2724 // the notification should not be sent if the document can not be modified
2725 if ( !m_pData->m_pObjectShell.Is() || !m_pData->m_pObjectShell->IsEnableSetModified() )
2726 return;
2727
2728 NotifyModifyListeners_Impl();
2729 }
2730
impl_change()2731 void SfxBaseModel::impl_change()
2732 {
2733 // object already disposed?
2734 if ( impl_isDisposed() )
2735 return;
2736
2737 NotifyModifyListeners_Impl();
2738 }
2739
2740 //________________________________________________________________________________________________________
2741 // public impl.
2742 //________________________________________________________________________________________________________
2743
GetObjectShell() const2744 SfxObjectShell* SfxBaseModel::GetObjectShell() const
2745 {
2746 return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2747 }
2748
impl_getObjectShell() const2749 SfxObjectShell* SfxBaseModel::impl_getObjectShell() const
2750 {
2751 return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
2752 }
2753
2754 //________________________________________________________________________________________________________
2755 // public impl.
2756 //________________________________________________________________________________________________________
2757
IsInitialized() const2758 sal_Bool SfxBaseModel::IsInitialized() const
2759 {
2760 if ( !m_pData || !m_pData->m_pObjectShell )
2761 {
2762 OSL_ENSURE( false, "SfxBaseModel::IsInitialized: this should have been caught earlier!" );
2763 return sal_False;
2764 }
2765
2766 return m_pData->m_pObjectShell->GetMedium() != NULL;
2767 }
2768
MethodEntryCheck(const bool i_mustBeInitialized) const2769 void SfxBaseModel::MethodEntryCheck( const bool i_mustBeInitialized ) const
2770 {
2771 if ( impl_isDisposed() )
2772 throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2773 if ( i_mustBeInitialized && !IsInitialized() )
2774 throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
2775 }
2776
impl_isDisposed() const2777 sal_Bool SfxBaseModel::impl_isDisposed() const
2778 {
2779 return ( m_pData == NULL ) ;
2780 }
2781
2782 //________________________________________________________________________________________________________
2783 // private impl.
2784 //________________________________________________________________________________________________________
2785
GetMediumFilterName_Impl()2786 ::rtl::OUString SfxBaseModel::GetMediumFilterName_Impl()
2787 {
2788 const SfxFilter* pFilter = NULL;
2789 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2790 if ( pMedium )
2791 pFilter = pMedium->GetFilter();
2792
2793 if ( pFilter )
2794 return pFilter->GetName();
2795
2796 return ::rtl::OUString();
2797 }
2798
impl_store(const::rtl::OUString & sURL,const uno::Sequence<beans::PropertyValue> & seqArguments,sal_Bool bSaveTo)2799 void SfxBaseModel::impl_store( const ::rtl::OUString& sURL ,
2800 const uno::Sequence< beans::PropertyValue >& seqArguments ,
2801 sal_Bool bSaveTo )
2802 {
2803 if( !sURL.getLength() )
2804 throw frame::IllegalArgumentIOException();
2805
2806 //sal_Bool aSaveAsTemplate = sal_False;
2807
2808 sal_Bool bSaved = sal_False;
2809 if ( !bSaveTo && m_pData->m_pObjectShell && sURL.getLength()
2810 && sURL.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL
2811 && ::utl::UCBContentHelper::EqualURLs( getLocation(), sURL ) )
2812 {
2813 // this is the same file URL as the current document location, try to use storeOwn if possible
2814
2815 ::comphelper::SequenceAsHashMap aArgHash( seqArguments );
2816 ::rtl::OUString aFilterString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
2817 ::rtl::OUString aFilterName = aArgHash.getUnpackedValueOrDefault( aFilterString, ::rtl::OUString() );
2818 if ( aFilterName.getLength() )
2819 {
2820 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
2821 if ( pMedium )
2822 {
2823 const SfxFilter* pFilter = pMedium->GetFilter();
2824 if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) )
2825 {
2826 // 119366 - If the former file saving with password, do not trying in StoreSelf anyway...
2827 bool bFormerPassword = false;
2828 {
2829 uno::Sequence< beans::NamedValue > aOldEncryptionData;
2830 if (GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ))
2831 {
2832 bFormerPassword = true;
2833 }
2834 }
2835 if ( !bFormerPassword )
2836 {
2837 aArgHash.erase( aFilterString );
2838 aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
2839
2840 try
2841 {
2842 storeSelf( aArgHash.getAsConstPropertyValueList() );
2843 bSaved = sal_True;
2844 }
2845 catch( const lang::IllegalArgumentException& )
2846 {
2847 // some additional arguments do not allow to use saving, SaveAs should be done
2848 // but only for normal documents, the shared documents would be overwritten in this case
2849 // that would mean an information loss
2850 // TODO/LATER: need a new interaction for this case
2851 if ( m_pData->m_pObjectShell->IsDocShared() )
2852 {
2853 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) );
2854 m_pData->m_pObjectShell->StoreLog();
2855
2856 uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() );
2857 if ( !aNewEncryptionData.getLength() )
2858 {
2859 ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() );
2860 aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword );
2861 }
2862
2863 uno::Sequence< beans::NamedValue > aOldEncryptionData;
2864 GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData );
2865
2866 if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() )
2867 throw;
2868 else
2869 {
2870 // if the password is changed a special error should be used in case of shared document
2871 throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE );
2872 }
2873 }
2874 }
2875 }
2876 }
2877 }
2878 }
2879 }
2880
2881 if ( !bSaved && m_pData->m_pObjectShell )
2882 {
2883 SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOC : STR_EVENT_SAVEASDOC ),
2884 m_pData->m_pObjectShell ) );
2885
2886 SfxAllItemSet *aParams = new SfxAllItemSet( SFX_APP()->GetPool() );
2887 aParams->Put( SfxStringItem( SID_FILE_NAME, String(sURL) ) );
2888 if ( bSaveTo )
2889 aParams->Put( SfxBoolItem( SID_SAVETO, sal_True ) );
2890
2891 TransformParameters( SID_SAVEASDOC, seqArguments, *aParams );
2892
2893 SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
2894
2895 if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo )
2896 {
2897 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Misuse of CopyStreamIfPossible!" ) ) );
2898 m_pData->m_pObjectShell->StoreLog();
2899
2900 throw frame::IllegalArgumentIOException(
2901 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!") ),
2902 uno::Reference< uno::XInterface >() );
2903 }
2904
2905 sal_uInt32 nModifyPasswordHash = 0;
2906 uno::Sequence< beans::PropertyValue > aModifyPasswordInfo;
2907 SFX_ITEMSET_ARG( aParams, pModifyPasswordInfoItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
2908 if ( pModifyPasswordInfoItem )
2909 {
2910 // it contains either a simple hash or a set of PropertyValues
2911 // TODO/LATER: the sequence of PropertyValue should replace the hash completely in future
2912 sal_Int32 nMPHTmp = 0;
2913 pModifyPasswordInfoItem->GetValue() >>= nMPHTmp;
2914 nModifyPasswordHash = (sal_uInt32)nMPHTmp;
2915 pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo;
2916 }
2917 aParams->ClearItem( SID_MODIFYPASSWORDINFO );
2918 sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash();
2919 m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash );
2920 uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo();
2921 m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo );
2922
2923 // since saving a document modifies its DocumentInfo, the current
2924 // DocumentInfo must be saved on "SaveTo", so it can be restored
2925 // after saving
2926 sal_Bool bCopyTo = bSaveTo ||
2927 m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
2928 uno::Reference<document::XDocumentProperties> xOldDocProps;
2929 uno::Reference<document::XDocumentInfo> xOldDocInfo;
2930 if ( bCopyTo )
2931 {
2932 xOldDocProps = getDocumentProperties();
2933 if (m_pData->m_xDocumentInfo.is())
2934 {
2935 xOldDocInfo = getDocumentInfo();
2936 const Reference<util::XCloneable> xCloneable(xOldDocInfo,
2937 UNO_QUERY_THROW);
2938 const Reference<document::XDocumentInfo> xNewDocInfo(
2939 xCloneable->createClone(), UNO_QUERY_THROW);
2940 const Reference<document::XDocumentPropertiesSupplier> xDPS(
2941 xNewDocInfo, UNO_QUERY_THROW);
2942 const Reference<document::XDocumentProperties> xNewDocProps(
2943 xDPS->getDocumentProperties());
2944 m_pData->m_xDocumentProperties = xNewDocProps;
2945 m_pData->m_xDocumentInfo = xNewDocInfo;
2946 }
2947 else // try not to create DocumentInfo if it does not exist...
2948 {
2949 const Reference<util::XCloneable> xCloneable(xOldDocProps,
2950 UNO_QUERY_THROW);
2951 const Reference<document::XDocumentProperties> xNewDocProps(
2952 xCloneable->createClone(), UNO_QUERY_THROW);
2953 m_pData->m_xDocumentProperties = xNewDocProps;
2954 }
2955 }
2956
2957 sal_Bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams );
2958
2959 if ( bCopyTo )
2960 {
2961 // restore DocumentInfo if a copy was created
2962 m_pData->m_xDocumentProperties = xOldDocProps;
2963 m_pData->m_xDocumentInfo = xOldDocInfo;
2964 }
2965
2966 uno::Reference < task::XInteractionHandler > xHandler;
2967 SFX_ITEMSET_ARG( aParams, pItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
2968 if ( pItem )
2969 pItem->GetValue() >>= xHandler;
2970
2971 DELETEZ( aParams );
2972
2973 sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetErrorCode();
2974 if ( !bRet && !nErrCode )
2975 {
2976 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing has failed, no error is set!" ) ) );
2977 nErrCode = ERRCODE_IO_CANTWRITE;
2978 }
2979 m_pData->m_pObjectShell->ResetError();
2980
2981 if ( bRet )
2982 {
2983 if ( nErrCode )
2984 {
2985 // must be a warning - use Interactionhandler if possible or abandone
2986 if ( xHandler.is() )
2987 {
2988 // TODO/LATER: a general way to set the error context should be available
2989 SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, m_pData->m_pObjectShell->GetTitle() );
2990
2991 ::com::sun::star::task::ErrorCodeRequest aErrorCode;
2992 aErrorCode.ErrCode = nErrCode;
2993 SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
2994 }
2995 }
2996
2997 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing succeeded!" ) ) );
2998 if ( !bSaveTo )
2999 {
3000 m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
3001 m_pData->m_pObjectShell->SetModifyPasswordEntered();
3002
3003 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) );
3004 }
3005 else
3006 {
3007 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
3008 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
3009
3010 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) );
3011 }
3012 }
3013 else
3014 {
3015 // let the logring be stored to the related file
3016 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
3017 m_pData->m_pObjectShell->StoreLog();
3018
3019 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
3020 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
3021
3022
3023 SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED),
3024 m_pData->m_pObjectShell ) );
3025
3026 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
3027 }
3028 }
3029 }
3030
3031 //********************************************************************************************************
3032 namespace {
3033 template< typename ListenerT, typename EventT >
3034 class NotifySingleListenerIgnoreRE
3035 {
3036 private:
3037 typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& );
3038 NotificationMethod m_pMethod;
3039 const EventT& m_rEvent;
3040 public:
NotifySingleListenerIgnoreRE(NotificationMethod method,const EventT & event)3041 NotifySingleListenerIgnoreRE( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
3042
operator ()(const uno::Reference<ListenerT> & listener) const3043 void operator()( const uno::Reference<ListenerT>& listener ) const
3044 {
3045 try
3046 {
3047 (listener.get()->*m_pMethod)( m_rEvent );
3048 }
3049 catch( uno::RuntimeException& )
3050 {
3051 // this exception is ignored to avoid problems with invalid listeners, the listener should be probably thrown away in future
3052 }
3053 }
3054 };
3055 } // anonymous namespace
3056
postEvent_Impl(const::rtl::OUString & aName,const uno::Reference<frame::XController2> & xController)3057 void SfxBaseModel::postEvent_Impl( const ::rtl::OUString& aName, const uno::Reference< frame::XController2 >& xController )
3058 {
3059 // object already disposed?
3060 if ( impl_isDisposed() )
3061 return;
3062
3063 DBG_ASSERT( aName.getLength(), "Empty event name!" );
3064 if (!aName.getLength())
3065 return;
3066
3067 ::cppu::OInterfaceContainerHelper* pIC =
3068 m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XDocumentEventListener >*)0 ) );
3069 if ( pIC )
3070 {
3071 #ifdef DBG_UTIL
3072 ByteString aTmp( "SfxDocumentEvent: " );
3073 aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
3074 DBG_TRACE( aTmp.GetBuffer() );
3075 #endif
3076
3077 document::DocumentEvent aDocumentEvent( (frame::XModel*)this, aName, xController, uno::Any() );
3078
3079 pIC->forEach< document::XDocumentEventListener, NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent > >(
3080 NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent >(
3081 &document::XDocumentEventListener::documentEventOccured,
3082 aDocumentEvent ) );
3083 }
3084
3085 pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ) );
3086 if ( pIC )
3087 {
3088 #ifdef DBG_UTIL
3089 ByteString aTmp( "SfxEvent: " );
3090 aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
3091 DBG_TRACE( aTmp.GetBuffer() );
3092 #endif
3093
3094 document::EventObject aEvent( (frame::XModel*)this, aName );
3095
3096 pIC->forEach< document::XEventListener, NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject > >(
3097 NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject >(
3098 &document::XEventListener::notifyEvent,
3099 aEvent ) );
3100 }
3101
3102 }
3103
getViewData()3104 uno::Reference < container::XIndexAccess > SAL_CALL SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException)
3105 {
3106 SfxModelGuard aGuard( *this );
3107
3108 if ( m_pData->m_pObjectShell.Is() && !m_pData->m_contViewData.is() )
3109 {
3110 SfxViewFrame *pActFrame = SfxViewFrame::Current();
3111 if ( !pActFrame || pActFrame->GetObjectShell() != m_pData->m_pObjectShell )
3112 pActFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
3113
3114 if ( !pActFrame || !pActFrame->GetViewShell() )
3115 // currently no frame for this document at all or View is under construction
3116 return uno::Reference < container::XIndexAccess >();
3117
3118 m_pData->m_contViewData = Reference < container::XIndexAccess >(
3119 ::comphelper::getProcessServiceFactory()->createInstance(
3120 DEFINE_CONST_UNICODE("com.sun.star.document.IndexedPropertyValues") ),
3121 uno::UNO_QUERY );
3122
3123 if ( !m_pData->m_contViewData.is() )
3124 {
3125 // error: no container class available!
3126 return uno::Reference < container::XIndexAccess >();
3127 }
3128
3129 uno::Reference < container::XIndexContainer > xCont( m_pData->m_contViewData, uno::UNO_QUERY );
3130 sal_Int32 nCount = 0;
3131 uno::Sequence < beans::PropertyValue > aSeq;
3132 ::com::sun::star::uno::Any aAny;
3133 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); pFrame;
3134 pFrame = SfxViewFrame::GetNext( *pFrame, m_pData->m_pObjectShell ) )
3135 {
3136 sal_Bool bIsActive = ( pFrame == pActFrame );
3137 pFrame->GetViewShell()->WriteUserDataSequence( aSeq );
3138 aAny <<= aSeq;
3139 xCont->insertByIndex( bIsActive ? 0 : nCount, aAny );
3140 nCount++;
3141 }
3142 }
3143
3144 return m_pData->m_contViewData;
3145 }
3146
setViewData(const uno::Reference<container::XIndexAccess> & aData)3147 void SAL_CALL SfxBaseModel::setViewData( const uno::Reference < container::XIndexAccess >& aData ) throw(::com::sun::star::uno::RuntimeException)
3148 {
3149 SfxModelGuard aGuard( *this );
3150
3151 m_pData->m_contViewData = aData;
3152 }
3153
3154 /** calls all XEventListeners */
notifyEvent(const::com::sun::star::document::EventObject & aEvent) const3155 void SfxBaseModel::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) const
3156 {
3157 // object already disposed?
3158 if ( impl_isDisposed() )
3159 return;
3160
3161 ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer(
3162 ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) );
3163 if( pIC )
3164
3165 {
3166 ::cppu::OInterfaceIteratorHelper aIt( *pIC );
3167 while( aIt.hasMoreElements() )
3168 {
3169 try
3170 {
3171 ((XDOCEVENTLISTENER *)aIt.next())->notifyEvent( aEvent );
3172 }
3173 catch( uno::RuntimeException& )
3174 {
3175 aIt.remove();
3176 }
3177 }
3178 }
3179 }
3180
3181 /** returns true if someone added a XEventListener to this XEventBroadcaster */
hasEventListeners() const3182 sal_Bool SfxBaseModel::hasEventListeners() const
3183 {
3184 return !impl_isDisposed() && (NULL != m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ) );
3185 }
3186
addPrintJobListener(const uno::Reference<view::XPrintJobListener> & xListener)3187 void SAL_CALL SfxBaseModel::addPrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3188 {
3189 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3190
3191 if ( impl_getPrintHelper() )
3192 {
3193 uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3194 if ( xPJB.is() )
3195 xPJB->addPrintJobListener( xListener );
3196 }
3197 // else
3198 // m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3199 }
3200
removePrintJobListener(const uno::Reference<view::XPrintJobListener> & xListener)3201 void SAL_CALL SfxBaseModel::removePrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
3202 {
3203 SfxModelGuard aGuard( *this );
3204
3205 if ( impl_getPrintHelper() )
3206 {
3207 uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
3208 if ( xPJB.is() )
3209 xPJB->removePrintJobListener( xListener );
3210 }
3211 // else
3212 // m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
3213 }
3214
3215 // simple declaration of class SvObject is enough
3216 // the corresponding <so3/iface.hxx> cannon be included because it provides
3217 // declaration of class SvBorder that conflicts with ../../inc/viewfrm.hxx
3218 class SvObject;
getSomething(const::com::sun::star::uno::Sequence<sal_Int8> & aIdentifier)3219 sal_Int64 SAL_CALL SfxBaseModel::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
3220 {
3221 ::vos::OGuard aGuard( Application::GetSolarMutex() );
3222 if ( GetObjectShell() )
3223 {
3224 SvGlobalName aName( aIdentifier );
3225 if ( aName == SvGlobalName( SO3_GLOBAL_CLASSID ) )
3226 return (sal_Int64)(sal_IntPtr)(SvObject*)GetObjectShell();
3227 else if ( aName == SvGlobalName( SFX_GLOBAL_CLASSID ) )
3228 return (sal_Int64)(sal_IntPtr)(SfxObjectShell*)GetObjectShell();
3229 }
3230
3231 return 0;
3232 }
3233
3234 //____________________________________________________________________________________________________
3235 // XDocumentSubStorageSupplier
3236 //____________________________________________________________________________________________________
3237
ListenForStorage_Impl(const uno::Reference<embed::XStorage> & xStorage)3238 void SfxBaseModel::ListenForStorage_Impl( const uno::Reference< embed::XStorage >& xStorage )
3239 {
3240 uno::Reference< util::XModifiable > xModifiable( xStorage, uno::UNO_QUERY );
3241 if ( xModifiable.is() )
3242 {
3243 if ( !m_pData->m_pStorageModifyListen.is() )
3244 {
3245 m_pData->m_pStorageModifyListen = new ::sfx2::DocumentStorageModifyListener( *m_pData, Application::GetSolarMutex() );
3246 }
3247
3248 // no need to deregister the listening for old storage since it should be disposed automatically
3249 xModifiable->addModifyListener( m_pData->m_pStorageModifyListen.get() );
3250 }
3251 }
3252
getDocumentSubStorage(const::rtl::OUString & aStorageName,sal_Int32 nMode)3253 uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode )
3254 throw ( uno::RuntimeException)
3255 {
3256 SfxModelGuard aGuard( *this );
3257
3258 uno::Reference< XSTORAGE > xResult;
3259 if ( m_pData->m_pObjectShell.Is() )
3260 {
3261 uno::Reference< embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3262 if ( xStorage.is() )
3263 {
3264 try
3265 {
3266 xResult = xStorage->openStorageElement( aStorageName, nMode );
3267 }
3268 catch ( uno::Exception& )
3269 {
3270 }
3271 }
3272 }
3273
3274 return xResult;
3275 }
3276
getDocumentSubStoragesNames()3277 Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getDocumentSubStoragesNames()
3278 throw ( io::IOException,
3279 RuntimeException )
3280 {
3281 SfxModelGuard aGuard( *this );
3282
3283 Sequence< ::rtl::OUString > aResult;
3284 sal_Int32 nResultSize = 0;
3285 sal_Bool bSuccess = sal_False;
3286 if ( m_pData->m_pObjectShell.Is() )
3287 {
3288 uno::Reference < embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
3289 uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
3290 if ( xAccess.is() )
3291 {
3292 Sequence< ::rtl::OUString > aTemp = xAccess->getElementNames();
3293 for ( sal_Int32 n = 0; n < aTemp.getLength(); n++ )
3294 {
3295 if ( xStorage->isStorageElement( aTemp[n] ) )
3296 {
3297 aResult.realloc( ++nResultSize );
3298 aResult[ nResultSize - 1 ] = aTemp[n];
3299 }
3300 }
3301
3302 bSuccess = sal_True;
3303 }
3304 }
3305
3306 if ( !bSuccess )
3307 throw io::IOException();
3308
3309 return aResult;
3310 }
3311
3312 //____________________________________________________________________________________________________
3313 // XScriptProviderSupplier
3314 //____________________________________________________________________________________________________
3315
3316
getScriptProvider()3317 uno::Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getScriptProvider()
3318 throw ( uno::RuntimeException )
3319 {
3320 SfxModelGuard aGuard( *this );
3321
3322 uno::Reference< script::provider::XScriptProvider > xScriptProvider;
3323
3324 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
3325 Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory(
3326 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW );
3327
3328 try
3329 {
3330 Reference< XScriptInvocationContext > xScriptContext( this );
3331 xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), uno::UNO_SET_THROW );
3332 }
3333 catch( const uno::RuntimeException& )
3334 {
3335 throw;
3336 }
3337 catch( const lang::IllegalArgumentException& )
3338 {
3339 throw lang::WrappedTargetRuntimeException(
3340 ::rtl::OUString(),
3341 *this,
3342 ::cppu::getCaughtException()
3343 );
3344 }
3345
3346 return xScriptProvider;
3347 }
3348
3349 //____________________________________________________________________________________________________
3350 // XUIConfigurationManagerSupplier
3351 //____________________________________________________________________________________________________
3352
getRuntimeUID() const3353 rtl::OUString SfxBaseModel::getRuntimeUID() const
3354 {
3355 OSL_ENSURE( m_pData->m_sRuntimeUID.getLength() > 0,
3356 "SfxBaseModel::getRuntimeUID - ID is empty!" );
3357 return m_pData->m_sRuntimeUID;
3358 }
3359
hasValidSignatures() const3360 sal_Bool SfxBaseModel::hasValidSignatures() const
3361 {
3362 ::vos::OGuard aGuard( Application::GetSolarMutex() );
3363 if ( m_pData->m_pObjectShell.Is() )
3364 return ( m_pData->m_pObjectShell->ImplGetSignatureState( sal_False ) == SIGNATURESTATE_SIGNATURES_OK );
3365 return sal_False;
3366 }
3367
GetCommandFromSequence(rtl::OUString & rCommand,sal_Int32 & nIndex,const uno::Sequence<beans::PropertyValue> & rSeqPropValue)3368 static void GetCommandFromSequence( rtl::OUString& rCommand, sal_Int32& nIndex, const uno::Sequence< beans::PropertyValue >& rSeqPropValue )
3369 {
3370 rtl::OUString aCommand;
3371 nIndex = -1;
3372
3373 for ( sal_Int32 i = 0; i < rSeqPropValue.getLength(); i++ )
3374 {
3375 if ( rSeqPropValue[i].Name.equalsAsciiL( "Command", 7 ))
3376 {
3377 rSeqPropValue[i].Value >>= rCommand;
3378 nIndex = i;
3379 return;
3380 }
3381 }
3382 }
3383
ConvertSlotsToCommands(SfxObjectShell * pDoc,uno::Reference<container::XIndexContainer> & rToolbarDefinition)3384 static void ConvertSlotsToCommands( SfxObjectShell* pDoc, uno::Reference< container::XIndexContainer >& rToolbarDefinition )
3385 {
3386 if ( pDoc )
3387 {
3388 Any aAny;
3389 SfxModule* pModule( pDoc->GetFactory().GetModule() );
3390 rtl::OUString aSlotCmd( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
3391 rtl::OUString aUnoCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
3392 uno::Sequence< beans::PropertyValue > aSeqPropValue;
3393
3394 for ( sal_Int32 i = 0; i < rToolbarDefinition->getCount(); i++ )
3395 {
3396 sal_Int32 nIndex( -1 );
3397 rtl::OUString aCommand;
3398
3399 if ( rToolbarDefinition->getByIndex( i ) >>= aSeqPropValue )
3400 {
3401 GetCommandFromSequence( aCommand, nIndex, aSeqPropValue );
3402 if ( nIndex >= 0 && ( aCommand.indexOf( aSlotCmd ) == 0 ))
3403 {
3404 rtl::OUString aSlot( aCommand.copy( 5 ));
3405
3406 // We have to replace the old "slot-Command" with our new ".uno:-Command"
3407 const SfxSlot* pSlot = pModule->GetSlotPool()->GetSlot( sal_uInt16( aSlot.toInt32() ));
3408 if ( pSlot )
3409 {
3410 rtl::OUStringBuffer aStrBuf( aUnoCmd );
3411 aStrBuf.appendAscii( pSlot->GetUnoName() );
3412
3413 aCommand = aStrBuf.makeStringAndClear();
3414 aSeqPropValue[nIndex].Value <<= aCommand;
3415 rToolbarDefinition->replaceByIndex( i, Any( aSeqPropValue ));
3416 }
3417 }
3418 }
3419 }
3420 }
3421 }
3422
getUIConfigurationManager()3423 uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfigurationManager()
3424 throw ( uno::RuntimeException )
3425 {
3426 SfxModelGuard aGuard( *this );
3427
3428 if ( !m_pData->m_xUIConfigurationManager.is() )
3429 {
3430 uno::Reference< ui::XUIConfigurationManager > xNewUIConfMan(
3431 ::comphelper::getProcessServiceFactory()->createInstance(
3432 ::rtl::OUString::createFromAscii( "com.sun.star.ui.UIConfigurationManager" )),
3433 uno::UNO_QUERY );
3434
3435 Reference< ui::XUIConfigurationStorage > xUIConfigStorage( xNewUIConfMan, uno::UNO_QUERY );
3436 if ( xUIConfigStorage.is() )
3437 {
3438 uno::Reference< XSTORAGE > xConfigStorage;
3439
3440 rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
3441 // First try to open with READWRITE and then READ
3442 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE );
3443 if ( xConfigStorage.is() )
3444 {
3445 rtl::OUString aMediaTypeProp( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ));
3446 rtl::OUString aUIConfigMediaType(
3447 RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ) );
3448 rtl::OUString aMediaType;
3449 uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY );
3450 Any a = xPropSet->getPropertyValue( aMediaTypeProp );
3451 if ( !( a >>= aMediaType ) || ( aMediaType.getLength() == 0 ))
3452 {
3453 a <<= aUIConfigMediaType;
3454 xPropSet->setPropertyValue( aMediaTypeProp, a );
3455 }
3456 }
3457 else
3458 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ );
3459
3460 // initialize ui configuration manager with document substorage
3461 xUIConfigStorage->setStorage( xConfigStorage );
3462
3463 // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to
3464 // migrate
3465 if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
3466 {
3467 // Import old UI configuration from OOo 1.x
3468 uno::Reference< XSTORAGE > xOOo1ConfigStorage;
3469 rtl::OUString aOOo1UIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations" ));
3470
3471 // Try to open with READ
3472 xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ );
3473 if ( xOOo1ConfigStorage.is() )
3474 {
3475 uno::Reference< lang::XMultiServiceFactory > xServiceMgr( ::comphelper::getProcessServiceFactory() );
3476 uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars;
3477
3478 sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars(
3479 xNewUIConfMan, rToolbars, xServiceMgr, xOOo1ConfigStorage );
3480 if ( bImported )
3481 {
3482 SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell();
3483
3484 char aNum[] = "private:resource/toolbar/custom_OOo1x_0";
3485 char aTitle[] = "Toolbar 0";
3486 sal_Int32 nNumIndex = strlen( aNum )-1;
3487 sal_Int32 nTitleIndex = strlen( aTitle )-1;
3488 for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ )
3489 {
3490 aNum[nNumIndex]++;
3491 aTitle[nTitleIndex]++;
3492
3493 rtl::OUString aCustomTbxName( RTL_CONSTASCII_USTRINGPARAM( aNum ));
3494 rtl::OUString aCustomTbxTitle( RTL_CONSTASCII_USTRINGPARAM( aTitle ));
3495
3496 uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i];
3497 ConvertSlotsToCommands( pObjShell, xToolbar );
3498 if ( !xNewUIConfMan->hasSettings( aCustomTbxName ))
3499 {
3500 // Set UIName for the toolbar with container property
3501 uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY );
3502 if ( xPropSet.is() )
3503 {
3504 try
3505 {
3506 rtl::OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( "UIName" ));
3507 Any aAny( aCustomTbxTitle );
3508 xPropSet->setPropertyValue( aPropName, aAny );
3509 }
3510 catch ( beans::UnknownPropertyException& )
3511 {
3512 }
3513 }
3514
3515 uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY );
3516 xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData );
3517 uno::Reference< ui::XUIConfigurationPersistence > xPersist( xNewUIConfMan, uno::UNO_QUERY );
3518 xPersist->store();
3519 }
3520 }
3521 }
3522 }
3523 }
3524 }
3525
3526 m_pData->m_xUIConfigurationManager = xNewUIConfMan;
3527 }
3528
3529 return m_pData->m_xUIConfigurationManager;
3530 }
3531
3532 //____________________________________________________________________________________________________
3533 // XVisualObject
3534 //____________________________________________________________________________________________________
3535
setVisualAreaSize(sal_Int64 nAspect,const awt::Size & aSize)3536 void SAL_CALL SfxBaseModel::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
3537 throw ( lang::IllegalArgumentException,
3538 embed::WrongStateException,
3539 uno::Exception,
3540 uno::RuntimeException )
3541 {
3542 SfxModelGuard aGuard( *this );
3543
3544 if ( !m_pData->m_pObjectShell.Is() )
3545 throw uno::Exception(); // TODO: error handling
3546
3547 SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False );
3548 if ( pViewFrm && m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !pViewFrm->GetFrame().IsInPlace() )
3549 {
3550 Window* pWindow = VCLUnoHelper::GetWindow( pViewFrm->GetFrame().GetFrameInterface()->getContainerWindow() );
3551 Size aWinSize = pWindow->GetSizePixel();
3552 awt::Size aCurrent = getVisualAreaSize( nAspect );
3553 Size aDiff( aSize.Width-aCurrent.Width, aSize.Height-aCurrent.Height );
3554 Size aWrongDiff = OutputDevice::LogicToLogic( aDiff , m_pData->m_pObjectShell->GetMapUnit(), pWindow->GetMapMode() );
3555 aDiff = pViewFrm->GetViewShell()->GetWindow()->LogicToPixel( aDiff );
3556 aWinSize.Width() += aDiff.Width();
3557 aWinSize.Height() += aDiff.Height();
3558 pWindow->SetSizePixel( aWinSize );
3559 }
3560 else
3561 {
3562 Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3563 aTmpRect.SetSize( Size( aSize.Width, aSize.Height ) );
3564 m_pData->m_pObjectShell->SetVisArea( aTmpRect );
3565 }
3566 }
3567
getVisualAreaSize(sal_Int64)3568 awt::Size SAL_CALL SfxBaseModel::getVisualAreaSize( sal_Int64 /*nAspect*/ )
3569 throw ( lang::IllegalArgumentException,
3570 embed::WrongStateException,
3571 uno::Exception,
3572 uno::RuntimeException)
3573 {
3574 SfxModelGuard aGuard( *this );
3575
3576 if ( !m_pData->m_pObjectShell.Is() )
3577 throw uno::Exception(); // TODO: error handling
3578
3579 Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
3580
3581 #if 0
3582 Window* pWindow = NULL;
3583 SfxViewFrame* pViewFrm = m_pData->m_pObjectShell.Is() ?
3584 SfxViewFrame::GetFirst( m_pData->m_pObjectShell, 0, sal_False ) : 0;
3585
3586 if ( pWindow )
3587 {
3588 MapMode aInternalMapMode( pViewFrm->GetWindow().GetMapMode() );
3589 MapMode aExternalMapMode( m_pData->m_pObjectShell->GetMapUnit() );
3590
3591 aTmpRect = OutputDevice::LogicToLogic( aTmpRect, aInternalMapMode, aExternalMapMode );
3592 }
3593 #endif
3594
3595 return awt::Size( aTmpRect.GetWidth(), aTmpRect.GetHeight() );
3596 }
3597
3598
getMapUnit(sal_Int64)3599 sal_Int32 SAL_CALL SfxBaseModel::getMapUnit( sal_Int64 /*nAspect*/ )
3600 throw ( uno::Exception,
3601 uno::RuntimeException)
3602 {
3603 SfxModelGuard aGuard( *this );
3604
3605 if ( !m_pData->m_pObjectShell.Is() )
3606 throw uno::Exception(); // TODO: error handling
3607
3608 return VCLUnoHelper::VCL2UnoEmbedMapUnit( m_pData->m_pObjectShell->GetMapUnit() );
3609 }
3610
getPreferredVisualRepresentation(::sal_Int64)3611 embed::VisualRepresentation SAL_CALL SfxBaseModel::getPreferredVisualRepresentation( ::sal_Int64 /*nAspect*/ )
3612 throw ( lang::IllegalArgumentException,
3613 embed::WrongStateException,
3614 uno::Exception,
3615 uno::RuntimeException )
3616 {
3617 SfxModelGuard aGuard( *this );
3618
3619 datatransfer::DataFlavor aDataFlavor(
3620 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
3621 ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
3622 ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
3623
3624 embed::VisualRepresentation aVisualRepresentation;
3625 aVisualRepresentation.Data = getTransferData( aDataFlavor );
3626 aVisualRepresentation.Flavor = aDataFlavor;
3627
3628 return aVisualRepresentation;
3629 }
3630
3631 //____________________________________________________________________________________________________
3632 // XStorageBasedDocument
3633 //____________________________________________________________________________________________________
3634
loadFromStorage(const uno::Reference<XSTORAGE> & xStorage,const uno::Sequence<beans::PropertyValue> & aMediaDescriptor)3635 void SAL_CALL SfxBaseModel::loadFromStorage( const uno::Reference< XSTORAGE >& xStorage,
3636 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3637 throw ( lang::IllegalArgumentException,
3638 DOUBLEINITIALIZATIONEXCEPTION,
3639 IOEXCEPTION,
3640 EXCEPTION,
3641 uno::RuntimeException )
3642 {
3643 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3644 if ( IsInitialized() )
3645 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
3646
3647 // after i36090 is fixed the pool from object shell can be used
3648 // SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3649 SfxAllItemSet aSet( SFX_APP()->GetPool() );
3650
3651 // the BaseURL is part of the ItemSet
3652 SfxMedium* pMedium = new SfxMedium( xStorage, String() );
3653 TransformParameters( SID_OPENDOC, aMediaDescriptor, aSet );
3654 pMedium->GetItemSet()->Put( aSet );
3655
3656 // allow to use an interactionhandler (if there is one)
3657 pMedium->UseInteractionHandler( sal_True );
3658
3659 SFX_ITEMSET_ARG( &aSet, pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
3660 sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
3661 m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
3662 m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3663
3664 // load document
3665 if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
3666 {
3667 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3668 throw task::ErrorCodeIOException( ::rtl::OUString(),
3669 uno::Reference< uno::XInterface >(),
3670 nError ? nError : ERRCODE_IO_CANTREAD );
3671 }
3672 }
3673
storeToStorage(const uno::Reference<XSTORAGE> & xStorage,const uno::Sequence<beans::PropertyValue> & aMediaDescriptor)3674 void SAL_CALL SfxBaseModel::storeToStorage( const uno::Reference< XSTORAGE >& xStorage,
3675 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
3676 throw ( lang::IllegalArgumentException,
3677 IOEXCEPTION,
3678 EXCEPTION,
3679 uno::RuntimeException )
3680 {
3681 SfxModelGuard aGuard( *this );
3682
3683 uno::Reference< XSTORAGE > xResult;
3684 if ( !m_pData->m_pObjectShell.Is() )
3685 throw IOEXCEPTION(); // TODO:
3686
3687 SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
3688 TransformParameters( SID_SAVEASDOC, aMediaDescriptor, aSet );
3689
3690 // TODO/LATER: may be a special URL "private:storage" should be used
3691 SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
3692 sal_Int32 nVersion = SOFFICE_FILEFORMAT_CURRENT;
3693 if( pItem )
3694 {
3695 String aFilterName = pItem->GetValue();
3696 const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName );
3697 if ( pFilter && pFilter->UsesStorage() )
3698 nVersion = pFilter->GetVersion();
3699 }
3700
3701 sal_Bool bSuccess = sal_False;
3702 if ( xStorage == m_pData->m_pObjectShell->GetStorage() )
3703 {
3704 // storing to the own storage
3705 bSuccess = m_pData->m_pObjectShell->DoSave();
3706 }
3707 else
3708 {
3709 // TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated
3710 // TODO/LATER: is it possible to have a template here?
3711 m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False );
3712
3713 // BaseURL is part of the ItemSet
3714 SfxMedium aMedium( xStorage, String(), &aSet );
3715 aMedium.CanDisposeStorage_Impl( sal_False );
3716 if ( aMedium.GetFilter() )
3717 {
3718 // storing without a valid filter will often crash
3719 bSuccess = m_pData->m_pObjectShell->DoSaveObjectAs( aMedium, sal_True );
3720 m_pData->m_pObjectShell->DoSaveCompleted( NULL );
3721 }
3722 }
3723
3724 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3725 m_pData->m_pObjectShell->ResetError();
3726
3727 // the warnings are currently not transported
3728 if ( !bSuccess )
3729 {
3730 throw task::ErrorCodeIOException( ::rtl::OUString(),
3731 uno::Reference< uno::XInterface >(),
3732 nError ? nError : ERRCODE_IO_GENERAL );
3733 }
3734 }
3735
switchToStorage(const uno::Reference<XSTORAGE> & xStorage)3736 void SAL_CALL SfxBaseModel::switchToStorage( const uno::Reference< XSTORAGE >& xStorage )
3737 throw ( lang::IllegalArgumentException,
3738 IOEXCEPTION,
3739 EXCEPTION,
3740 uno::RuntimeException )
3741 {
3742 SfxModelGuard aGuard( *this );
3743
3744 uno::Reference< XSTORAGE > xResult;
3745 if ( !m_pData->m_pObjectShell.Is() )
3746 throw IOEXCEPTION(); // TODO:
3747
3748 // the persistence should be switched only if the storage is different
3749 if ( xStorage != m_pData->m_pObjectShell->GetStorage()
3750 && !m_pData->m_pObjectShell->SwitchPersistance( xStorage ) )
3751 {
3752 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
3753 throw task::ErrorCodeIOException( ::rtl::OUString(),
3754 uno::Reference< uno::XInterface >(),
3755 nError ? nError : ERRCODE_IO_GENERAL );
3756 }
3757
3758 m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False;
3759 }
3760
getDocumentStorage()3761 uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentStorage()
3762 throw ( IOEXCEPTION,
3763 EXCEPTION,
3764 uno::RuntimeException )
3765 {
3766 SfxModelGuard aGuard( *this );
3767
3768 uno::Reference< XSTORAGE > xResult;
3769 if ( !m_pData->m_pObjectShell.Is() )
3770 throw IOEXCEPTION(); // TODO
3771
3772 return m_pData->m_pObjectShell->GetStorage();
3773 }
3774
addStorageChangeListener(const uno::Reference<document::XStorageChangeListener> & xListener)3775 void SAL_CALL SfxBaseModel::addStorageChangeListener(
3776 const uno::Reference< document::XStorageChangeListener >& xListener )
3777 throw ( uno::RuntimeException )
3778 {
3779 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3780
3781 m_pData->m_aInterfaceContainer.addInterface(
3782 ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3783 }
3784
removeStorageChangeListener(const uno::Reference<document::XStorageChangeListener> & xListener)3785 void SAL_CALL SfxBaseModel::removeStorageChangeListener(
3786 const uno::Reference< document::XStorageChangeListener >& xListener )
3787 throw ( uno::RuntimeException )
3788 {
3789 SfxModelGuard aGuard( *this );
3790
3791 m_pData->m_aInterfaceContainer.removeInterface(
3792 ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
3793 }
3794
3795 #include "printhelper.hxx"
impl_getPrintHelper()3796 bool SfxBaseModel::impl_getPrintHelper()
3797 {
3798 if ( m_pData->m_xPrintable.is() )
3799 return true;
3800 m_pData->m_xPrintable = new SfxPrintHelper();
3801 uno::Reference < lang::XInitialization > xInit( m_pData->m_xPrintable, uno::UNO_QUERY );
3802 uno::Sequence < uno::Any > aValues(1);
3803 aValues[0] <<= uno::Reference < frame::XModel > (static_cast< frame::XModel* >(this), uno::UNO_QUERY );
3804 xInit->initialize( aValues );
3805 uno::Reference < view::XPrintJobBroadcaster > xBrd( m_pData->m_xPrintable, uno::UNO_QUERY );
3806 xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData ) );
3807 return true;
3808 }
3809
3810 //=============================================================================
3811 // css.frame.XModule
setIdentifier(const::rtl::OUString & Identifier)3812 void SAL_CALL SfxBaseModel::setIdentifier(const ::rtl::OUString& Identifier)
3813 throw (css::uno::RuntimeException)
3814 {
3815 SfxModelGuard aGuard( *this );
3816 m_pData->m_sModuleIdentifier = Identifier;
3817 }
3818
3819 //=============================================================================
3820 // css.frame.XModule
getIdentifier()3821 ::rtl::OUString SAL_CALL SfxBaseModel::getIdentifier()
3822 throw (css::uno::RuntimeException)
3823 {
3824 SfxModelGuard aGuard( *this );
3825 if (m_pData->m_sModuleIdentifier.getLength() > 0)
3826 return m_pData->m_sModuleIdentifier;
3827 if (m_pData->m_pObjectShell)
3828 return m_pData->m_pObjectShell->GetFactory().GetDocumentServiceName();
3829 return ::rtl::OUString();
3830 }
3831
3832 //=============================================================================
impl_getTitleHelper()3833 css::uno::Reference< css::frame::XTitle > SfxBaseModel::impl_getTitleHelper ()
3834 {
3835 SfxModelGuard aGuard( *this );
3836
3837 if ( ! m_pData->m_xTitleHelper.is ())
3838 {
3839 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory ();
3840 css::uno::Reference< css::frame::XUntitledNumbers > xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
3841 css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3842
3843 ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(xSMGR);
3844 m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3845 pHelper->setOwner (xThis );
3846 pHelper->connectWithUntitledNumbers (xDesktop);
3847 }
3848
3849 return m_pData->m_xTitleHelper;
3850 }
3851
3852 //=============================================================================
impl_getUntitledHelper()3853 css::uno::Reference< css::frame::XUntitledNumbers > SfxBaseModel::impl_getUntitledHelper ()
3854 {
3855 SfxModelGuard aGuard( *this );
3856
3857 if ( ! m_pData->m_xNumberedControllers.is ())
3858 {
3859 css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
3860 ::comphelper::NumberedCollection* pHelper = new ::comphelper::NumberedCollection();
3861
3862 m_pData->m_xNumberedControllers = css::uno::Reference< css::frame::XUntitledNumbers >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
3863
3864 pHelper->setOwner (xThis);
3865 pHelper->setUntitledPrefix (::rtl::OUString::createFromAscii(" : "));
3866 }
3867
3868 return m_pData->m_xNumberedControllers;
3869 }
3870
3871 //=============================================================================
3872 // css.frame.XTitle
getTitle()3873 ::rtl::OUString SAL_CALL SfxBaseModel::getTitle()
3874 throw (css::uno::RuntimeException)
3875 {
3876 // SYNCHRONIZED ->
3877 SfxModelGuard aGuard( *this );
3878
3879 ::rtl::OUString aResult = impl_getTitleHelper()->getTitle ();
3880 if ( !m_pData->m_bExternalTitle && m_pData->m_pObjectShell )
3881 {
3882 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
3883 if ( pMedium )
3884 {
3885 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
3886 if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
3887 aResult += String( SfxResId(STR_REPAIREDDOCUMENT) );
3888 }
3889
3890 if ( m_pData->m_pObjectShell->IsReadOnlyUI() || (pMedium && pMedium->IsReadOnly()) )
3891 aResult += ::rtl::OUString( String( SfxResId(STR_READONLY) ) );
3892 else if ( m_pData->m_pObjectShell->IsDocShared() )
3893 aResult += ::rtl::OUString( String( SfxResId(STR_SHARED) ) );
3894
3895 if ( m_pData->m_pObjectShell->GetDocumentSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
3896 aResult += String( SfxResId( RID_XMLSEC_DOCUMENTSIGNED ) );
3897 }
3898
3899 return aResult;
3900 }
3901
3902 //=============================================================================
3903 // css.frame.XTitle
setTitle(const::rtl::OUString & sTitle)3904 void SAL_CALL SfxBaseModel::setTitle( const ::rtl::OUString& sTitle )
3905 throw (css::uno::RuntimeException)
3906 {
3907 // SYNCHRONIZED ->
3908 SfxModelGuard aGuard( *this );
3909
3910 impl_getTitleHelper()->setTitle (sTitle);
3911 m_pData->m_bExternalTitle = sal_True;
3912 }
3913
3914 //=============================================================================
3915 // css.frame.XTitleChangeBroadcaster
addTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)3916 void SAL_CALL SfxBaseModel::addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3917 throw (css::uno::RuntimeException)
3918 {
3919 // SYNCHRONIZED ->
3920 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
3921
3922 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3923 if (xBroadcaster.is ())
3924 xBroadcaster->addTitleChangeListener (xListener);
3925 }
3926
3927 //=============================================================================
3928 // css.frame.XTitleChangeBroadcaster
removeTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)3929 void SAL_CALL SfxBaseModel::removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
3930 throw (css::uno::RuntimeException)
3931 {
3932 // SYNCHRONIZED ->
3933 SfxModelGuard aGuard( *this );
3934
3935 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
3936 if (xBroadcaster.is ())
3937 xBroadcaster->removeTitleChangeListener (xListener);
3938 }
3939
3940 //=============================================================================
3941 // css.frame.XUntitledNumbers
leaseNumber(const css::uno::Reference<css::uno::XInterface> & xComponent)3942 ::sal_Int32 SAL_CALL SfxBaseModel::leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent )
3943 throw (css::lang::IllegalArgumentException,
3944 css::uno::RuntimeException )
3945 {
3946 SfxModelGuard aGuard( *this );
3947
3948 return impl_getUntitledHelper ()->leaseNumber (xComponent);
3949 }
3950
3951 //=============================================================================
3952 // css.frame.XUntitledNumbers
releaseNumber(::sal_Int32 nNumber)3953 void SAL_CALL SfxBaseModel::releaseNumber( ::sal_Int32 nNumber )
3954 throw (css::lang::IllegalArgumentException,
3955 css::uno::RuntimeException )
3956 {
3957 SfxModelGuard aGuard( *this );
3958 impl_getUntitledHelper ()->releaseNumber (nNumber);
3959 }
3960
3961 //=============================================================================
3962 // css.frame.XUntitledNumbers
releaseNumberForComponent(const css::uno::Reference<css::uno::XInterface> & xComponent)3963 void SAL_CALL SfxBaseModel::releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent )
3964 throw (css::lang::IllegalArgumentException,
3965 css::uno::RuntimeException )
3966 {
3967 SfxModelGuard aGuard( *this );
3968 impl_getUntitledHelper ()->releaseNumberForComponent (xComponent);
3969 }
3970
3971 //=============================================================================
3972 // css.frame.XUntitledNumbers
getUntitledPrefix()3973 ::rtl::OUString SAL_CALL SfxBaseModel::getUntitledPrefix()
3974 throw (css::uno::RuntimeException)
3975 {
3976 SfxModelGuard aGuard( *this );
3977 return impl_getUntitledHelper ()->getUntitledPrefix ();
3978 }
3979
3980 //=============================================================================
3981 // css::frame::XModel2
getControllers()3982 css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxBaseModel::getControllers()
3983 throw (css::uno::RuntimeException)
3984 {
3985 SfxModelGuard aGuard( *this );
3986
3987 sal_Int32 c = m_pData->m_seqControllers.getLength();
3988 sal_Int32 i = 0;
3989 css::uno::Sequence< css::uno::Any > lEnum(c);
3990 for (i=0; i<c; ++i)
3991 lEnum[i] <<= m_pData->m_seqControllers[i];
3992
3993 ::comphelper::OAnyEnumeration* pEnum = new ::comphelper::OAnyEnumeration(lEnum);
3994 css::uno::Reference< css::container::XEnumeration > xEnum(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY_THROW);
3995 return xEnum;
3996 }
3997
3998 //=============================================================================
3999 // css::frame::XModel2
getAvailableViewControllerNames()4000 css::uno::Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getAvailableViewControllerNames()
4001 throw (css::uno::RuntimeException)
4002 {
4003 SfxModelGuard aGuard( *this );
4004
4005 const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
4006 const sal_Int32 nViewFactoryCount = rDocumentFactory.GetViewFactoryCount();
4007
4008 Sequence< ::rtl::OUString > aViewNames( nViewFactoryCount );
4009 for ( sal_Int32 nViewNo = 0; nViewNo < nViewFactoryCount; ++nViewNo )
4010 aViewNames[nViewNo] = rDocumentFactory.GetViewFactory( nViewNo ).GetAPIViewName();
4011 return aViewNames;
4012 }
4013
4014 //=============================================================================
4015 // css::frame::XModel2
createDefaultViewController(const css::uno::Reference<css::frame::XFrame> & i_rFrame)4016 css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createDefaultViewController( const css::uno::Reference< css::frame::XFrame >& i_rFrame )
4017 throw (css::uno::RuntimeException ,
4018 css::lang::IllegalArgumentException,
4019 css::uno::Exception )
4020 {
4021 SfxModelGuard aGuard( *this );
4022
4023 const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
4024 const ::rtl::OUString sDefaultViewName = rDocumentFactory.GetViewFactory( 0 ).GetAPIViewName();
4025
4026 aGuard.clear();
4027
4028 return createViewController( sDefaultViewName, Sequence< PropertyValue >(), i_rFrame );
4029 }
4030
4031 //=============================================================================
4032 namespace sfx { namespace intern {
4033
4034 /** a class which, in its dtor, cleans up variuos objects (well, at the moment only the frame) collected during
4035 the creation of a document view, unless the creation was successful.
4036 */
4037 class SAL_DLLPRIVATE ViewCreationGuard
4038 {
4039 public:
ViewCreationGuard()4040 ViewCreationGuard()
4041 :m_bSuccess( false )
4042 {
4043 }
4044
~ViewCreationGuard()4045 ~ViewCreationGuard()
4046 {
4047 if ( !m_bSuccess )
4048 impl_closeAll();
4049 }
4050
takeFrameOwnership(SfxFrame * i_pFrame)4051 void takeFrameOwnership( SfxFrame* i_pFrame )
4052 {
4053 OSL_PRECOND( !m_aWeakFrame, "ViewCreationGuard::takeFrameOwnership: already have a frame!" );
4054 OSL_PRECOND( i_pFrame != NULL, "ViewCreationGuard::takeFrameOwnership: invalid frame!" );
4055 m_aWeakFrame = i_pFrame;
4056 }
4057
releaseAll()4058 void releaseAll()
4059 {
4060 m_bSuccess = true;
4061 }
4062
4063 private:
impl_closeAll()4064 void impl_closeAll()
4065 {
4066 if ( m_aWeakFrame && !m_aWeakFrame->GetCurrentDocument() )
4067 {
4068 m_aWeakFrame->SetFrameInterface_Impl( NULL );
4069 m_aWeakFrame->DoClose();
4070 }
4071 }
4072
4073 private:
4074 bool m_bSuccess;
4075 SfxFrameWeak m_aWeakFrame;
4076 };
4077 } }
4078
4079 //=============================================================================
FindOrCreateViewFrame_Impl(const Reference<XFrame> & i_rFrame,::sfx::intern::ViewCreationGuard & i_rGuard) const4080 SfxViewFrame* SfxBaseModel::FindOrCreateViewFrame_Impl( const Reference< XFrame >& i_rFrame, ::sfx::intern::ViewCreationGuard& i_rGuard ) const
4081 {
4082 SfxViewFrame* pViewFrame = NULL;
4083 for ( pViewFrame = SfxViewFrame::GetFirst( GetObjectShell(), sal_False );
4084 pViewFrame;
4085 pViewFrame= SfxViewFrame::GetNext( *pViewFrame, GetObjectShell(), sal_False )
4086 )
4087 {
4088 if ( pViewFrame->GetFrame().GetFrameInterface() == i_rFrame )
4089 break;
4090 }
4091 if ( !pViewFrame )
4092 {
4093 #if OSL_DEBUG_LEVEL > 0
4094 for ( SfxFrame* pCheckFrame = SfxFrame::GetFirst();
4095 pCheckFrame;
4096 pCheckFrame = SfxFrame::GetNext( *pCheckFrame )
4097 )
4098 {
4099 if ( pCheckFrame->GetFrameInterface() == i_rFrame )
4100 {
4101 if ( ( pCheckFrame->GetCurrentViewFrame() != NULL )
4102 || ( pCheckFrame->GetCurrentDocument() != NULL )
4103 )
4104 // Note that it is perfectly letgitimate that during loading into an XFrame which already contains
4105 // a document, there exist two SfxFrame instances bound to this XFrame - the old one, which will be
4106 // destroyed later, and the new one, which we're going to create
4107 continue;
4108
4109 OSL_ENSURE( false, "SfxBaseModel::FindOrCreateViewFrame_Impl: there already is an SfxFrame for the given XFrame, but no view in it!" );
4110 // nowadays, we're the only instance allowed to create an SfxFrame for an XFrame, so this case here should not happen
4111 break;
4112 }
4113 }
4114 #endif
4115
4116 SfxFrame* pTargetFrame = SfxFrame::Create( i_rFrame );
4117 ENSURE_OR_THROW( pTargetFrame, "could not create an SfxFrame" );
4118 i_rGuard.takeFrameOwnership( pTargetFrame );
4119
4120 // prepare it
4121 pTargetFrame->PrepareForDoc_Impl( *GetObjectShell() );
4122
4123 // create view frame
4124 pViewFrame = new SfxViewFrame( *pTargetFrame, GetObjectShell() );
4125 }
4126 return pViewFrame;
4127 }
4128
4129 //=============================================================================
4130 // css::frame::XModel2
createViewController(const::rtl::OUString & i_rViewName,const Sequence<PropertyValue> & i_rArguments,const Reference<XFrame> & i_rFrame)4131 css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createViewController(
4132 const ::rtl::OUString& i_rViewName, const Sequence< PropertyValue >& i_rArguments, const Reference< XFrame >& i_rFrame )
4133 throw (css::uno::RuntimeException ,
4134 css::lang::IllegalArgumentException,
4135 css::uno::Exception )
4136 {
4137 SfxModelGuard aGuard( *this );
4138
4139 if ( !i_rFrame.is() )
4140 throw css::lang::IllegalArgumentException( ::rtl::OUString(), *this, 3 );
4141
4142 // find the proper SFX view factory
4143 SfxViewFactory* pViewFactory = GetObjectShell()->GetFactory().GetViewFactoryByViewName( i_rViewName );
4144 if ( !pViewFactory )
4145 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
4146
4147 // determine previous shell (used in some special cases)
4148 Reference< XController > xPreviousController( i_rFrame->getController() );
4149 const Reference< XModel > xMe( this );
4150 if ( ( xPreviousController.is() )
4151 && ( xMe != xPreviousController->getModel() )
4152 )
4153 {
4154 xPreviousController.clear();
4155 }
4156 SfxViewShell* pOldViewShell = SfxViewShell::Get( xPreviousController );
4157 OSL_ENSURE( !xPreviousController.is() || ( pOldViewShell != NULL ),
4158 "SfxBaseModel::createViewController: invalid old controller!" );
4159
4160 // a guard which will clean up in case of failure
4161 ::sfx::intern::ViewCreationGuard aViewCreationGuard;
4162
4163 // determine the ViewFrame belonging to the given XFrame
4164 SfxViewFrame* pViewFrame = FindOrCreateViewFrame_Impl( i_rFrame, aViewCreationGuard );
4165 OSL_POSTCOND( pViewFrame, "SfxBaseModel::createViewController: no frame?" );
4166
4167 // delegate to SFX' view factory
4168 pViewFrame->GetBindings().ENTERREGISTRATIONS();
4169 SfxViewShell* pViewShell = pViewFactory->CreateInstance( pViewFrame, pOldViewShell );
4170 pViewFrame->GetBindings().LEAVEREGISTRATIONS();
4171 ENSURE_OR_THROW( pViewShell, "invalid view shell provided by factory" );
4172
4173 // by setting the ViewShell it is prevented that disposing the Controller will destroy this ViewFrame also
4174 pViewFrame->GetDispatcher()->SetDisableFlags( 0 );
4175 pViewFrame->SetViewShell_Impl( pViewShell );
4176
4177 // remember ViewID
4178 pViewFrame->SetCurViewId_Impl( pViewFactory->GetOrdinal() );
4179
4180 // ensure a default controller, if the view shell did not provide an own implementation
4181 if ( !pViewShell->GetController().is() )
4182 pViewShell->SetController( new SfxBaseController( pViewShell ) );
4183
4184 // pass the creation arguments to the controller
4185 SfxBaseController* pBaseController = pViewShell->GetBaseController_Impl();
4186 ENSURE_OR_THROW( pBaseController, "invalid controller implementation!" );
4187 pBaseController->SetCreationArguments_Impl( i_rArguments );
4188
4189 // some initial view settings, coming from our most recent attachResource call
4190 ::comphelper::NamedValueCollection aDocumentLoadArgs( getArgs() );
4191 if ( aDocumentLoadArgs.getOrDefault( "ViewOnly", false ) )
4192 pViewFrame->GetFrame().SetMenuBarOn_Impl( sal_False );
4193
4194 const sal_Int16 nPluginMode = aDocumentLoadArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
4195 if ( nPluginMode == 1 )
4196 {
4197 pViewFrame->ForceOuterResize_Impl( sal_False );
4198 pViewFrame->GetBindings().HidePopups( sal_True );
4199
4200 SfxFrame& rFrame = pViewFrame->GetFrame();
4201 // MBA: layoutmanager of inplace frame starts locked and invisible
4202 rFrame.GetWorkWindow_Impl()->MakeVisible_Impl( sal_False );
4203 rFrame.GetWorkWindow_Impl()->Lock_Impl( sal_True );
4204
4205 rFrame.GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4206 pViewFrame->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
4207 }
4208
4209 // tell the guard we were successful
4210 aViewCreationGuard.releaseAll();
4211
4212 // outta gere
4213 return pBaseController;
4214 }
4215
4216 //=============================================================================
4217 // RDF DocumentMetadataAccess
4218
4219 // ::com::sun::star::rdf::XRepositorySupplier:
4220 uno::Reference< rdf::XRepository > SAL_CALL
getRDFRepository()4221 SfxBaseModel::getRDFRepository() throw (uno::RuntimeException)
4222 {
4223 SfxModelGuard aGuard( *this );
4224
4225 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4226 if (!xDMA.is()) {
4227 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4228 "model has no document metadata"), *this );
4229 }
4230
4231 return xDMA->getRDFRepository();
4232 }
4233
4234 // ::com::sun::star::rdf::XNode:
4235 ::rtl::OUString SAL_CALL
getStringValue()4236 SfxBaseModel::getStringValue() throw (uno::RuntimeException)
4237 {
4238 SfxModelGuard aGuard( *this );
4239
4240 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4241 if (!xDMA.is()) {
4242 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4243 "model has no document metadata"), *this );
4244 }
4245
4246 return xDMA->getStringValue();
4247 }
4248
4249 // ::com::sun::star::rdf::XURI:
4250 ::rtl::OUString SAL_CALL
getNamespace()4251 SfxBaseModel::getNamespace() throw (uno::RuntimeException)
4252 {
4253 SfxModelGuard aGuard( *this );
4254
4255 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4256 if (!xDMA.is()) {
4257 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4258 "model has no document metadata"), *this );
4259 }
4260
4261 return xDMA->getNamespace();
4262 }
4263
4264 ::rtl::OUString SAL_CALL
getLocalName()4265 SfxBaseModel::getLocalName() throw (uno::RuntimeException)
4266 {
4267 SfxModelGuard aGuard( *this );
4268
4269 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4270 if (!xDMA.is()) {
4271 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4272 "model has no document metadata"), *this );
4273 }
4274
4275 return xDMA->getLocalName();
4276 }
4277
4278 // ::com::sun::star::rdf::XDocumentMetadataAccess:
4279 uno::Reference< rdf::XMetadatable > SAL_CALL
getElementByMetadataReference(const::com::sun::star::beans::StringPair & i_rReference)4280 SfxBaseModel::getElementByMetadataReference(
4281 const ::com::sun::star::beans::StringPair & i_rReference)
4282 throw (uno::RuntimeException)
4283 {
4284 SfxModelGuard aGuard( *this );
4285
4286 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4287 if (!xDMA.is()) {
4288 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4289 "model has no document metadata"), *this );
4290 }
4291
4292 return xDMA->getElementByMetadataReference(i_rReference);
4293 }
4294
4295 uno::Reference< rdf::XMetadatable > SAL_CALL
getElementByURI(const uno::Reference<rdf::XURI> & i_xURI)4296 SfxBaseModel::getElementByURI(const uno::Reference< rdf::XURI > & i_xURI)
4297 throw (uno::RuntimeException, lang::IllegalArgumentException)
4298 {
4299 SfxModelGuard aGuard( *this );
4300
4301 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4302 if (!xDMA.is()) {
4303 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4304 "model has no document metadata"), *this );
4305 }
4306
4307 return xDMA->getElementByURI(i_xURI);
4308 }
4309
4310 uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
getMetadataGraphsWithType(const uno::Reference<rdf::XURI> & i_xType)4311 SfxBaseModel::getMetadataGraphsWithType(
4312 const uno::Reference<rdf::XURI> & i_xType)
4313 throw (uno::RuntimeException, lang::IllegalArgumentException)
4314 {
4315 SfxModelGuard aGuard( *this );
4316
4317 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4318 if (!xDMA.is()) {
4319 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4320 "model has no document metadata"), *this );
4321 }
4322
4323 return xDMA->getMetadataGraphsWithType(i_xType);
4324 }
4325
4326 uno::Reference<rdf::XURI> SAL_CALL
addMetadataFile(const::rtl::OUString & i_rFileName,const uno::Sequence<uno::Reference<rdf::XURI>> & i_rTypes)4327 SfxBaseModel::addMetadataFile(const ::rtl::OUString & i_rFileName,
4328 const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4329 throw (uno::RuntimeException, lang::IllegalArgumentException,
4330 container::ElementExistException)
4331 {
4332 SfxModelGuard aGuard( *this );
4333
4334 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4335 if (!xDMA.is()) {
4336 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4337 "model has no document metadata"), *this );
4338 }
4339
4340 return xDMA->addMetadataFile(i_rFileName, i_rTypes);
4341 }
4342
4343 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)4344 SfxBaseModel::importMetadataFile(::sal_Int16 i_Format,
4345 const uno::Reference< io::XInputStream > & i_xInStream,
4346 const ::rtl::OUString & i_rFileName,
4347 const uno::Reference< rdf::XURI > & i_xBaseURI,
4348 const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
4349 throw (uno::RuntimeException, lang::IllegalArgumentException,
4350 datatransfer::UnsupportedFlavorException,
4351 container::ElementExistException, rdf::ParseException, io::IOException)
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->importMetadataFile(i_Format,
4362 i_xInStream, i_rFileName, i_xBaseURI, i_rTypes);
4363 }
4364
4365 void SAL_CALL
removeMetadataFile(const uno::Reference<rdf::XURI> & i_xGraphName)4366 SfxBaseModel::removeMetadataFile(
4367 const uno::Reference< rdf::XURI > & i_xGraphName)
4368 throw (uno::RuntimeException, lang::IllegalArgumentException,
4369 container::NoSuchElementException)
4370 {
4371 SfxModelGuard aGuard( *this );
4372
4373 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4374 if (!xDMA.is()) {
4375 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4376 "model has no document metadata"), *this );
4377 }
4378
4379 return xDMA->removeMetadataFile(i_xGraphName);
4380 }
4381
4382 void SAL_CALL
addContentOrStylesFile(const::rtl::OUString & i_rFileName)4383 SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4384 throw (uno::RuntimeException, lang::IllegalArgumentException,
4385 container::ElementExistException)
4386 {
4387 SfxModelGuard aGuard( *this );
4388
4389 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4390 if (!xDMA.is()) {
4391 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4392 "model has no document metadata"), *this );
4393 }
4394
4395 return xDMA->addContentOrStylesFile(i_rFileName);
4396 }
4397
4398 void SAL_CALL
removeContentOrStylesFile(const::rtl::OUString & i_rFileName)4399 SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString & i_rFileName)
4400 throw (uno::RuntimeException, lang::IllegalArgumentException,
4401 container::NoSuchElementException)
4402 {
4403 SfxModelGuard aGuard( *this );
4404
4405 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4406 if (!xDMA.is()) {
4407 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4408 "model has no document metadata"), *this );
4409 }
4410
4411 return xDMA->removeContentOrStylesFile(i_rFileName);
4412 }
4413
4414 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)4415 SfxBaseModel::loadMetadataFromStorage(
4416 uno::Reference< embed::XStorage > const & i_xStorage,
4417 uno::Reference<rdf::XURI> const & i_xBaseURI,
4418 uno::Reference<task::XInteractionHandler> const & i_xHandler)
4419 throw (uno::RuntimeException, lang::IllegalArgumentException,
4420 lang::WrappedTargetException)
4421 {
4422 SfxModelGuard aGuard( *this );
4423
4424 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4425 m_pData->CreateDMAUninitialized());
4426 if (!xDMA.is()) {
4427 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4428 "model has no document metadata"), *this );
4429 }
4430
4431 try {
4432 xDMA->loadMetadataFromStorage(i_xStorage, i_xBaseURI, i_xHandler);
4433 } catch (lang::IllegalArgumentException &) {
4434 throw; // not initialized
4435 } catch (uno::Exception &) {
4436 // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4437 m_pData->m_xDocumentMetadata = xDMA;
4438 throw;
4439 }
4440 m_pData->m_xDocumentMetadata = xDMA;
4441
4442 }
4443
4444 void SAL_CALL
storeMetadataToStorage(uno::Reference<embed::XStorage> const & i_xStorage)4445 SfxBaseModel::storeMetadataToStorage(
4446 uno::Reference< embed::XStorage > const & i_xStorage)
4447 throw (uno::RuntimeException, lang::IllegalArgumentException,
4448 lang::WrappedTargetException)
4449 {
4450 SfxModelGuard aGuard( *this );
4451
4452 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4453 if (!xDMA.is()) {
4454 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4455 "model has no document metadata"), *this );
4456 }
4457
4458 return xDMA->storeMetadataToStorage(i_xStorage);
4459 }
4460
4461 void SAL_CALL
loadMetadataFromMedium(const uno::Sequence<beans::PropertyValue> & i_rMedium)4462 SfxBaseModel::loadMetadataFromMedium(
4463 const uno::Sequence< beans::PropertyValue > & i_rMedium)
4464 throw (uno::RuntimeException, lang::IllegalArgumentException,
4465 lang::WrappedTargetException)
4466 {
4467 SfxModelGuard aGuard( *this );
4468
4469 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
4470 m_pData->CreateDMAUninitialized());
4471 if (!xDMA.is()) {
4472 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4473 "model has no document metadata"), *this );
4474 }
4475
4476 try {
4477 xDMA->loadMetadataFromMedium(i_rMedium);
4478 } catch (lang::IllegalArgumentException &) {
4479 throw; // not initialized
4480 } catch (uno::Exception &) {
4481 // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
4482 m_pData->m_xDocumentMetadata = xDMA;
4483 throw;
4484 }
4485 m_pData->m_xDocumentMetadata = xDMA;
4486 }
4487
4488 void SAL_CALL
storeMetadataToMedium(const uno::Sequence<beans::PropertyValue> & i_rMedium)4489 SfxBaseModel::storeMetadataToMedium(
4490 const uno::Sequence< beans::PropertyValue > & i_rMedium)
4491 throw (uno::RuntimeException, lang::IllegalArgumentException,
4492 lang::WrappedTargetException)
4493 {
4494 SfxModelGuard aGuard( *this );
4495
4496 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
4497 if (!xDMA.is()) {
4498 throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
4499 "model has no document metadata"), *this );
4500 }
4501
4502 return xDMA->storeMetadataToMedium(i_rMedium);
4503 }
4504
4505 // =====================================================================================================================
4506 // = SfxModelSubComponent
4507 // =====================================================================================================================
4508
~SfxModelSubComponent()4509 SfxModelSubComponent::~SfxModelSubComponent()
4510 {
4511 }
4512
disposing()4513 void SfxModelSubComponent::disposing()
4514 {
4515 // nothing to do here
4516 }
4517
4518