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