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