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

Generated by: LCOV version 1.10