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