LCOV - code coverage report
Current view: top level - sfx2/source/doc - sfxbasemodel.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1211 2016 60.1 %
Date: 2015-06-13 12:38:46 Functions: 147 204 72.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11