LCOV - code coverage report
Current view: top level - sfx2/source/doc - sfxbasemodel.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 2013 0.0 %
Date: 2014-04-14 Functions: 0 202 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10