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

Generated by: LCOV version 1.10