LCOV - code coverage report
Current view: top level - sfx2/source/doc - objxtor.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 297 416 71.4 %
Date: 2014-11-03 Functions: 49 67 73.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : 
      22             : #include "arrdecl.hxx"
      23             : #include <map>
      24             : 
      25             : #include <cppuhelper/implbase1.hxx>
      26             : 
      27             : #include <com/sun/star/util/XCloseable.hpp>
      28             : #include <com/sun/star/frame/XComponentLoader.hpp>
      29             : #include <com/sun/star/frame/Desktop.hpp>
      30             : #include <com/sun/star/util/XCloseBroadcaster.hpp>
      31             : #include <com/sun/star/util/XCloseListener.hpp>
      32             : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : #include <com/sun/star/frame/XTitle.hpp>
      35             : #include <osl/mutex.hxx>
      36             : #include <rtl/instance.hxx>
      37             : #include <vcl/msgbox.hxx>
      38             : #include <vcl/wrkwin.hxx>
      39             : #include <vcl/svapp.hxx>
      40             : #include <svl/eitem.hxx>
      41             : #include <tools/rtti.hxx>
      42             : #include <svl/lstner.hxx>
      43             : #include <sfx2/sfxhelp.hxx>
      44             : #include <basic/sbstar.hxx>
      45             : #include <svl/stritem.hxx>
      46             : #include <basic/sbx.hxx>
      47             : #include <unotools/eventcfg.hxx>
      48             : 
      49             : #include <sfx2/objsh.hxx>
      50             : #include <sfx2/signaturestate.hxx>
      51             : #include <sfx2/sfxmodelfactory.hxx>
      52             : 
      53             : #include <basic/sbuno.hxx>
      54             : #include <svtools/sfxecode.hxx>
      55             : #include <svtools/ehdl.hxx>
      56             : #include <unotools/printwarningoptions.hxx>
      57             : #include <comphelper/processfactory.hxx>
      58             : #include <comphelper/string.hxx>
      59             : 
      60             : #include <com/sun/star/document/XStorageBasedDocument.hpp>
      61             : #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
      62             : #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
      63             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      64             : #include <com/sun/star/document/XScriptInvocationContext.hpp>
      65             : 
      66             : #include <svl/urihelper.hxx>
      67             : #include <unotools/pathoptions.hxx>
      68             : #include <svl/sharecontrolfile.hxx>
      69             : #include <unotools/localfilehelper.hxx>
      70             : #include <unotools/ucbhelper.hxx>
      71             : #include <svtools/asynclink.hxx>
      72             : #include <tools/diagnose_ex.h>
      73             : #include <comphelper/classids.hxx>
      74             : 
      75             : #include <sfx2/app.hxx>
      76             : #include <sfx2/docfac.hxx>
      77             : #include <sfx2/docfile.hxx>
      78             : #include <sfx2/event.hxx>
      79             : #include <sfx2/dispatch.hxx>
      80             : #include <sfx2/viewsh.hxx>
      81             : #include <sfx2/viewfrm.hxx>
      82             : #include <sfx2/sfxresid.hxx>
      83             : #include "objshimp.hxx"
      84             : #include "sfxtypes.hxx"
      85             : #include <sfx2/evntconf.hxx>
      86             : #include <sfx2/request.hxx>
      87             : #include "doc.hrc"
      88             : #include "sfxlocal.hrc"
      89             : #include "appdata.hxx"
      90             : #include <sfx2/sfxsids.hrc>
      91             : #include <basic/basmgr.hxx>
      92             : #include <svtools/svtools.hrc>
      93             : #include <sfx2/QuerySaveDocument.hxx>
      94             : #include "helpid.hrc"
      95             : #include <sfx2/msg.hxx>
      96             : #include "appbaslib.hxx"
      97             : #include <sfx2/sfxbasemodel.hxx>
      98             : 
      99             : #include <basic/basicmanagerrepository.hxx>
     100             : 
     101             : using namespace ::com::sun::star;
     102             : using namespace ::com::sun::star::uno;
     103             : using namespace ::com::sun::star::script;
     104             : using namespace ::com::sun::star::frame;
     105             : using namespace ::com::sun::star::document;
     106             : 
     107             : using ::basic::BasicManagerRepository;
     108             : #include <uno/mapping.hxx>
     109             : 
     110             : #include "sfxslots.hxx"
     111             : 
     112             : namespace {
     113             : 
     114             : class theCurrentComponent : public rtl::Static< WeakReference< XInterface >, theCurrentComponent > {};
     115             : 
     116             : #if HAVE_FEATURE_SCRIPTING
     117             : 
     118             : // remember all registered components for VBA compatibility, to be able to remove them on disposing the model
     119             : typedef ::std::map< XInterface*, OString > VBAConstantNameMap;
     120         317 : static VBAConstantNameMap s_aRegisteredVBAConstants;
     121             : 
     122       10854 : OString lclGetVBAGlobalConstName( const Reference< XInterface >& rxComponent )
     123             : {
     124             :     OSL_ENSURE( rxComponent.is(), "lclGetVBAGlobalConstName - missing component" );
     125             : 
     126       10854 :     VBAConstantNameMap::iterator aIt = s_aRegisteredVBAConstants.find( rxComponent.get() );
     127       10854 :     if( aIt != s_aRegisteredVBAConstants.end() )
     128           0 :         return aIt->second;
     129             : 
     130       10854 :     uno::Reference< beans::XPropertySet > xProps( rxComponent, uno::UNO_QUERY );
     131       10854 :     if( xProps.is() ) try
     132             :     {
     133       10840 :         OUString aConstName;
     134       11332 :         xProps->getPropertyValue("VBAGlobalConstantName") >>= aConstName;
     135       10840 :         return OUStringToOString( aConstName, RTL_TEXTENCODING_ASCII_US );
     136             :     }
     137         492 :     catch (const uno::Exception&) // not supported
     138             :     {
     139             :     }
     140         506 :     return OString();
     141             : }
     142             : 
     143             : #endif
     144             : 
     145             : } // namespace
     146             : 
     147             : 
     148             : 
     149       16646 : class SfxModelListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
     150             : {
     151             :     SfxObjectShell* mpDoc;
     152             : public:
     153        8410 :     SfxModelListener_Impl( SfxObjectShell* pDoc ) : mpDoc(pDoc) {};
     154             :     virtual void SAL_CALL queryClosing( const com::sun::star::lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
     155             :         throw ( com::sun::star::uno::RuntimeException, com::sun::star::util::CloseVetoException, std::exception) SAL_OVERRIDE ;
     156             :     virtual void SAL_CALL notifyClosing( const com::sun::star::lang::EventObject& aEvent ) throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE ;
     157             :     virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aEvent ) throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE ;
     158             : 
     159             : };
     160             : 
     161        8323 : void SAL_CALL SfxModelListener_Impl::queryClosing( const com::sun::star::lang::EventObject& , sal_Bool )
     162             :     throw ( com::sun::star::uno::RuntimeException, com::sun::star::util::CloseVetoException, std::exception)
     163             : {
     164        8323 : }
     165             : 
     166        8323 : void SAL_CALL SfxModelListener_Impl::notifyClosing( const com::sun::star::lang::EventObject& ) throw ( com::sun::star::uno::RuntimeException, std::exception )
     167             : {
     168        8323 :     SolarMutexGuard aSolarGuard;
     169        8323 :     mpDoc->Broadcast( SfxSimpleHint(SFX_HINT_DEINITIALIZING) );
     170        8323 : }
     171             : 
     172        8323 : void SAL_CALL SfxModelListener_Impl::disposing( const com::sun::star::lang::EventObject& _rEvent ) throw ( com::sun::star::uno::RuntimeException, std::exception )
     173             : {
     174             :     // am I ThisComponent in AppBasic?
     175        8323 :     SolarMutexGuard aSolarGuard;
     176        8323 :     if ( SfxObjectShell::GetCurrentComponent() == _rEvent.Source )
     177             :     {
     178             :         // remove ThisComponent reference from AppBasic
     179        5404 :         SfxObjectShell::SetCurrentComponent( Reference< XInterface >() );
     180             :     }
     181             : 
     182             : #if HAVE_FEATURE_SCRIPTING
     183             :     /*  Remove VBA component from AppBasic. As every application registers its
     184             :         own current component, the disposed component may not be the "current
     185             :         component" of the SfxObjectShell. */
     186        8323 :     if ( _rEvent.Source.is() )
     187             :     {
     188        8323 :         VBAConstantNameMap::iterator aIt = s_aRegisteredVBAConstants.find( _rEvent.Source.get() );
     189        8323 :         if ( aIt != s_aRegisteredVBAConstants.end() )
     190             :         {
     191        5190 :             if ( BasicManager* pAppMgr = SfxGetpApp()->GetBasicManager() )
     192        5190 :                 pAppMgr->SetGlobalUNOConstant( aIt->second.getStr(), Any( Reference< XInterface >() ) );
     193        5190 :             s_aRegisteredVBAConstants.erase( aIt );
     194             :         }
     195             :     }
     196             : #endif
     197             : 
     198        8323 :     if ( !mpDoc->Get_Impl()->bClosing )
     199             :         // GCC crashes when already in the destructor, so first query the Flag
     200        1584 :         mpDoc->DoClose();
     201        8323 : }
     202             : 
     203      270816 : TYPEINIT1(SfxObjectShell, SfxShell);
     204             : 
     205             : 
     206        8410 : SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell )
     207             :     :mpObjectContainer(0)
     208             :     ,rDocShell( _rDocShell )
     209             :     ,aMacroMode( *this )
     210             :     ,pProgress( 0)
     211             :     ,nTime( DateTime::SYSTEM )
     212             :     ,nVisualDocumentNumber( USHRT_MAX)
     213             :     ,nDocumentSignatureState( SIGNATURESTATE_UNKNOWN )
     214             :     ,nScriptingSignatureState( SIGNATURESTATE_UNKNOWN )
     215             :     ,bInList( false)
     216             :     ,bClosing( false)
     217             :     ,bIsSaving( false)
     218             :     ,bPasswd( false)
     219             :     ,bIsNamedVisible( false)
     220             :     ,bIsTemplate(false)
     221             :     ,bIsAbortingImport ( false)
     222             :     ,bImportDone ( false)
     223             :     ,bInPrepareClose( false )
     224             :     ,bPreparedForClose( false )
     225             :     ,bForbidReload( false )
     226             :     ,bBasicInitialized( false )
     227             :     ,bIsPrintJobCancelable( true )
     228             :     ,bOwnsStorage( true )
     229             :     ,bNoBaseURL( false )
     230             :     ,bInitialized( false )
     231             :     ,bSignatureErrorIsShown( false )
     232             :     ,bModelInitialized( false )
     233             :     ,bPreserveVersions( true )
     234             :     ,m_bMacroSignBroken( false )
     235             :     ,m_bNoBasicCapabilities( false )
     236             :     ,m_bDocRecoverySupport( true )
     237             :     ,bQueryLoadTemplate( true )
     238             :     ,bLoadReadonly( false )
     239             :     ,bUseUserData( true )
     240             :     ,bSaveVersionOnClose( false )
     241             :     ,m_bSharedXMLFlag( false )
     242             :     ,m_bAllowShareControlFileClean( true )
     243             :     ,m_bConfigOptionsChecked( false )
     244             :     ,lErr(ERRCODE_NONE)
     245             :     ,nEventId ( 0)
     246             :     ,pReloadTimer ( 0)
     247             :     ,pMarkData( 0 )
     248             :     ,nLoadedFlags ( SFX_LOADED_ALL )
     249             :     ,nFlagsInProgress( 0 )
     250             :     ,bModalMode( false )
     251             :     ,bRunningMacro( false )
     252             :     ,bReloadAvailable( false )
     253             :     ,nAutoLoadLocks( 0 )
     254             :     ,pModule( 0 )
     255             :     ,eFlags( SFXOBJECTSHELL_UNDEFINED )
     256             :     ,bReadOnlyUI( false )
     257             :     ,nStyleFilter( 0 )
     258             :     ,bDisposing( false )
     259             :     ,m_bEnableSetModified( true )
     260             :     ,m_bIsModified( false )
     261             :     ,m_nMapUnit( MAP_100TH_MM )
     262             :     ,m_bCreateTempStor( false )
     263             :     ,m_bIsInit( false )
     264             :     ,m_bIncomplEncrWarnShown( false )
     265             :     ,m_nModifyPasswordHash( 0 )
     266        8410 :     ,m_bModifyPasswordEntered( false )
     267             : {
     268        8410 :     SfxObjectShell* pDoc = &_rDocShell;
     269        8410 :     SfxObjectShellArr_Impl &rArr = SfxGetpApp()->GetObjectShells_Impl();
     270        8410 :     rArr.push_back( pDoc );
     271        8410 :     bInList = true;
     272        8410 : }
     273             : 
     274             : 
     275             : 
     276       16646 : SfxObjectShell_Impl::~SfxObjectShell_Impl()
     277             : {
     278       16646 : }
     279             : 
     280             : 
     281             : 
     282        7912 : SfxObjectShell::SfxObjectShell( const sal_uInt64 i_nCreationFlags )
     283        7912 :     :   pImp( new SfxObjectShell_Impl( *this ) )
     284             :     ,   pMedium(0)
     285             :     ,   pStyleSheetPool(0)
     286             :     ,   eCreateMode(SFX_CREATE_MODE_STANDARD)
     287             :     ,   bHasName( false )
     288       15824 :     ,   bIsInGenerateThumbnail ( false )
     289             : {
     290        7912 :     if (i_nCreationFlags & SFXMODEL_EMBEDDED_OBJECT)
     291        1046 :         eCreateMode = SFX_CREATE_MODE_EMBEDDED;
     292        6866 :     else if (i_nCreationFlags & SFXMODEL_EXTERNAL_LINK)
     293           0 :         eCreateMode = SFX_CREATE_MODE_INTERNAL;
     294             : 
     295        7912 :     const bool bScriptSupport = ( i_nCreationFlags & SFXMODEL_DISABLE_EMBEDDED_SCRIPTS ) == 0;
     296        7912 :     if ( !bScriptSupport )
     297         440 :         SetHasNoBasic();
     298             : 
     299        7912 :     const bool bDocRecovery = ( i_nCreationFlags & SFXMODEL_DISABLE_DOCUMENT_RECOVERY ) == 0;
     300        7912 :     if ( !bDocRecovery )
     301         426 :         pImp->m_bDocRecoverySupport = false;
     302        7912 : }
     303             : 
     304             : 
     305             : 
     306             : // initializes a document from a file-description
     307             : 
     308         498 : SfxObjectShell::SfxObjectShell
     309             : (
     310             :     SfxObjectCreateMode eMode   /*  Purpose, io which the SfxObjectShell
     311             :                                     is created:
     312             : 
     313             :                                     SFX_CREATE_MODE_EMBEDDED (default)
     314             :                                         as SO-Server from within another
     315             :                                         Document
     316             : 
     317             :                                     SFX_CREATE_MODE_STANDARD,
     318             :                                         as a normal Document open stand-alone
     319             : 
     320             :                                     SFX_CREATE_MODE_PREVIEW
     321             :                                         to enable a Preview, if possible are
     322             :                                         only little information is needed
     323             : 
     324             :                                     SFX_CREATE_MODE_ORGANIZER
     325             :                                         to be displayed in the Organizer, here
     326             :                                         notning of the contents is used  */
     327             : )
     328             : 
     329             : /*  [Description]
     330             : 
     331             :     Constructor of the class SfxObjectShell.
     332             : */
     333             : 
     334         498 : :   pImp( new SfxObjectShell_Impl( *this ) ),
     335             :     pMedium(0),
     336             :     pStyleSheetPool(0),
     337             :     eCreateMode(eMode),
     338             :     bHasName( false ),
     339         996 :     bIsInGenerateThumbnail ( false )
     340             : {
     341         498 : }
     342             : 
     343             : 
     344             : 
     345             : // virtual destructor of typical base-class SfxObjectShell
     346             : 
     347       16646 : SfxObjectShell::~SfxObjectShell()
     348             : {
     349             : 
     350        8323 :     if ( IsEnableSetModified() )
     351        6659 :         EnableSetModified( false );
     352             : 
     353             :     // Never call GetInPlaceObject(), the access to the derivative branch
     354             :     // SfxInternObject is not allowed because of a compiler bug
     355        8323 :     SfxObjectShell::CloseInternal();
     356        8323 :     pImp->pBaseModel.set( NULL );
     357             : 
     358        8323 :     DELETEX(AutoReloadTimer_Impl, pImp->pReloadTimer );
     359             : 
     360        8323 :     SfxApplication *pSfxApp = SfxGetpApp();
     361        8323 :     if ( USHRT_MAX != pImp->nVisualDocumentNumber )
     362        1468 :         pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
     363             : 
     364             :     // Destroy Basic-Manager
     365        8323 :     pImp->aBasicManager.reset( NULL );
     366             : 
     367        8323 :     if ( pSfxApp->GetDdeService() )
     368           0 :         pSfxApp->RemoveDdeTopic( this );
     369             : 
     370        8323 :     pImp->pBaseModel.set( NULL );
     371             : 
     372             :     // don't call GetStorage() here, in case of Load Failure it's possible that a storage was never assigned!
     373        8323 :     if ( pMedium && pMedium->HasStorage_Impl() && pMedium->GetStorage( false ) == pImp->m_xDocStorage )
     374        1190 :         pMedium->CanDisposeStorage_Impl( false );
     375             : 
     376        8323 :     if ( pImp->mpObjectContainer )
     377             :     {
     378        3814 :         pImp->mpObjectContainer->CloseEmbeddedObjects();
     379        3814 :         delete pImp->mpObjectContainer;
     380             :     }
     381             : 
     382        8323 :     if ( pImp->bOwnsStorage && pImp->m_xDocStorage.is() )
     383        6139 :         pImp->m_xDocStorage->dispose();
     384             : 
     385        8323 :     if ( pMedium )
     386             :     {
     387        7323 :         pMedium->CloseAndReleaseStreams_Impl();
     388             : 
     389             : #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
     390        7323 :         if ( IsDocShared() )
     391           0 :             FreeSharedFile();
     392             : #endif
     393        7323 :         DELETEX( SfxMedium, pMedium );
     394             :     }
     395             : 
     396             :     // The removing of the temporary file must be done as the latest step in the document destruction
     397        8323 :     if ( !pImp->aTempName.isEmpty() )
     398             :     {
     399           0 :         OUString aTmp;
     400           0 :         ::utl::LocalFileHelper::ConvertPhysicalNameToURL( pImp->aTempName, aTmp );
     401           0 :         ::utl::UCBContentHelper::Kill( aTmp );
     402             :     }
     403             : 
     404        8323 :     delete pImp;
     405        8323 : }
     406             : 
     407             : 
     408             : 
     409         568 : void SfxObjectShell::Stamp_SetPrintCancelState(bool bState)
     410             : {
     411         568 :     pImp->bIsPrintJobCancelable = bState;
     412         568 : }
     413             : 
     414             : 
     415             : 
     416         116 : bool SfxObjectShell::Stamp_GetPrintCancelState() const
     417             : {
     418         116 :     return pImp->bIsPrintJobCancelable;
     419             : }
     420             : 
     421             : 
     422             : 
     423        5508 : void SfxObjectShell::ViewAssigned()
     424             : 
     425             : /*  [Description]
     426             : 
     427             :     This method is called when a view is assigned.
     428             : */
     429             : 
     430             : {
     431        5508 : }
     432             : 
     433             : 
     434             : // closes the Object and all its views
     435             : 
     436        8443 : bool SfxObjectShell::Close()
     437             : {
     438        8443 :     SfxObjectShellRef aRef(this);
     439        8443 :     return CloseInternal();
     440             : }
     441             : 
     442             : // variant that does not take a reference to itself, so we can call it during object destruction
     443       16766 : bool SfxObjectShell::CloseInternal()
     444             : {
     445       16766 :     if ( !pImp->bClosing )
     446             :     {
     447             :         // Do not close if a progress is still running
     448        8323 :         if ( !pImp->bDisposing && GetProgress() )
     449           0 :             return false;
     450             : 
     451        8323 :         pImp->bClosing = true;
     452        8323 :         Reference< util::XCloseable > xCloseable( GetBaseModel(), UNO_QUERY );
     453             : 
     454        8323 :         if ( xCloseable.is() )
     455             :         {
     456             :             try
     457             :             {
     458        8323 :                 xCloseable->close( sal_True );
     459             :             }
     460           0 :             catch (const Exception&)
     461             :             {
     462           0 :                 pImp->bClosing = false;
     463             :             }
     464             :         }
     465             : 
     466        8323 :         if ( pImp->bClosing )
     467             :         {
     468             :             // remove from Document list
     469             :             // If there is no App, there is no document to remove
     470             :             // no need to call GetOrCreate here
     471        8323 :             SfxApplication *pSfxApp = SfxApplication::Get();
     472        8323 :             if(pSfxApp)
     473             :             {
     474        8323 :                 SfxObjectShellArr_Impl &rDocs = pSfxApp->GetObjectShells_Impl();
     475        8323 :                 SfxObjectShellArr_Impl::iterator it = std::find( rDocs.begin(), rDocs.end(), this );
     476        8323 :                 if ( it != rDocs.end() )
     477        8323 :                     rDocs.erase( it );
     478        8323 :                 pImp->bInList = false;
     479             :             }
     480        8323 :         }
     481             :     }
     482             : 
     483       16766 :     return true;
     484             : }
     485             : 
     486           0 : OUString SfxObjectShell::CreateShellID( const SfxObjectShell* pShell )
     487             : {
     488           0 :     if (!pShell)
     489           0 :         return OUString();
     490             : 
     491           0 :     OUString aShellID;
     492             : 
     493           0 :     SfxMedium* pMedium = pShell->GetMedium();
     494           0 :     if (pMedium)
     495           0 :         aShellID = pMedium->GetBaseURL();
     496             : 
     497           0 :     if (!aShellID.isEmpty())
     498           0 :         return aShellID;
     499             : 
     500           0 :     sal_Int64 nShellID = reinterpret_cast<sal_Int64>(pShell);
     501           0 :     aShellID = "0x" + OUString::number(nShellID, 16);
     502           0 :     return aShellID;
     503             : }
     504             : 
     505             : // returns a pointer the first SfxDocument of specified type
     506             : 
     507       11857 : SfxObjectShell* SfxObjectShell::GetFirst
     508             : (
     509             :     const TypeId* pType ,
     510             :     bool          bOnlyVisible
     511             : )
     512             : {
     513       11857 :     SfxObjectShellArr_Impl &rDocs = SfxGetpApp()->GetObjectShells_Impl();
     514             : 
     515             :     // seach for a SfxDocument of the specified type
     516       11891 :     for ( sal_uInt16 nPos = 0; nPos < rDocs.size(); ++nPos )
     517             :     {
     518       11877 :         SfxObjectShell* pSh = rDocs[ nPos ];
     519       11877 :         if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() )
     520           0 :             continue;
     521             : 
     522       35597 :         if ( ( !pType || pSh->IsA(*pType) ) &&
     523       13102 :              ( !bOnlyVisible || SfxViewFrame::GetFirst( pSh, true )))
     524       11843 :             return pSh;
     525             :     }
     526             : 
     527          14 :     return 0;
     528             : }
     529             : 
     530             : 
     531             : // returns a pointer to the next SfxDocument of specified type behind *pDoc
     532             : 
     533        8404 : SfxObjectShell* SfxObjectShell::GetNext
     534             : (
     535             :     const SfxObjectShell&   rPrev,
     536             :     const TypeId*           pType,
     537             :     bool                    bOnlyVisible
     538             : )
     539             : {
     540        8404 :     SfxObjectShellArr_Impl &rDocs = SfxGetpApp()->GetObjectShells_Impl();
     541             : 
     542             :     // refind the specified predecessor
     543             :     sal_uInt16 nPos;
     544       13092 :     for ( nPos = 0; nPos < rDocs.size(); ++nPos )
     545       13092 :         if ( rDocs[nPos] == &rPrev )
     546        8404 :             break;
     547             : 
     548             :     // search for the next SfxDocument of the specified type
     549        8618 :     for ( ++nPos; nPos < rDocs.size(); ++nPos )
     550             :     {
     551        2529 :         SfxObjectShell* pSh = rDocs[ nPos ];
     552        2529 :         if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() )
     553           0 :             continue;
     554             : 
     555        7373 :         if ( ( !pType || pSh->IsA(*pType) ) &&
     556        2755 :              ( !bOnlyVisible || SfxViewFrame::GetFirst( pSh, true )))
     557        2315 :             return pSh;
     558             :     }
     559        6089 :     return 0;
     560             : }
     561             : 
     562             : 
     563             : 
     564       23007 : SfxObjectShell* SfxObjectShell::Current()
     565             : {
     566       23007 :     SfxViewFrame *pFrame = SfxViewFrame::Current();
     567       23007 :     return pFrame ? pFrame->GetObjectShell() : 0;
     568             : }
     569             : 
     570             : 
     571             : 
     572          13 : bool SfxObjectShell::IsInPrepareClose() const
     573             : {
     574          13 :     return pImp->bInPrepareClose;
     575             : }
     576             : 
     577             : 
     578             : 
     579             : struct BoolEnv_Impl
     580             : {
     581             :     SfxObjectShell_Impl* pImp;
     582           7 :     BoolEnv_Impl( SfxObjectShell_Impl* pImpP) : pImp( pImpP )
     583           7 :     { pImpP->bInPrepareClose = true; }
     584           7 :     ~BoolEnv_Impl() { pImp->bInPrepareClose = false; }
     585             : };
     586             : 
     587             : 
     588          13 : bool SfxObjectShell::PrepareClose
     589             : (
     590             :     bool bUI   // true: Dialog and so on is allowed
     591             :                // false: silent-mode
     592             : )
     593             : {
     594          13 :     if( pImp->bInPrepareClose || pImp->bPreparedForClose )
     595           6 :         return true;
     596           7 :     BoolEnv_Impl aBoolEnv( pImp );
     597             : 
     598             :     // DocModalDialog?
     599           7 :     if ( IsInModalMode() )
     600           0 :         return false;
     601             : 
     602           7 :     SfxViewFrame* pFirst = SfxViewFrame::GetFirst( this );
     603           7 :     if( pFirst && !pFirst->GetFrame().PrepareClose_Impl( bUI ) )
     604           0 :         return false;
     605             : 
     606             :     // prepare views for closing
     607          13 :     for ( SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this );
     608             :           pFrm; pFrm = SfxViewFrame::GetNext( *pFrm, this ) )
     609             :     {
     610             :         DBG_ASSERT(pFrm->GetViewShell(),"No Shell");
     611           6 :         if ( pFrm->GetViewShell() )
     612             :         {
     613           6 :             bool nRet = pFrm->GetViewShell()->PrepareClose( bUI );
     614           6 :             if ( !nRet )
     615           0 :                 return nRet;
     616             :         }
     617             :     }
     618             : 
     619           7 :     SfxApplication *pSfxApp = SfxGetpApp();
     620           7 :     pSfxApp->NotifyEvent( SfxEventHint(SFX_EVENT_PREPARECLOSEDOC, GlobalEventConfig::GetEventName(STR_EVENT_PREPARECLOSEDOC), this) );
     621             : 
     622           7 :     if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
     623             :     {
     624           0 :         pImp->bPreparedForClose = true;
     625           0 :         return true;
     626             :     }
     627             : 
     628             :     // Ask if possible if it should be saved
     629             :     // only ask for the Document in the visable window
     630           7 :     SfxViewFrame *pFrame = SfxObjectShell::Current() == this
     631           7 :         ? SfxViewFrame::Current() : SfxViewFrame::GetFirst( this );
     632             : 
     633           7 :     if ( bUI && IsModified() && pFrame )
     634             :     {
     635             :         // restore minimized
     636           0 :         SfxFrame& rTop = pFrame->GetTopFrame();
     637           0 :         SfxViewFrame::SetViewFrame( rTop.GetCurrentViewFrame() );
     638           0 :         pFrame->GetFrame().Appear();
     639             : 
     640             :         // Ask if to save
     641           0 :         short nRet = RET_YES;
     642             :         {
     643           0 :             const Reference< XTitle > xTitle( *pImp->pBaseModel.get(), UNO_QUERY_THROW );
     644           0 :             const OUString     sTitle = xTitle->getTitle ();
     645           0 :             nRet = ExecuteQuerySaveDocument(&pFrame->GetWindow(),sTitle);
     646             :         }
     647             :         /*HACK for plugin::destroy()*/
     648             : 
     649           0 :         if ( RET_YES == nRet )
     650             :         {
     651             :             // Save by each Dispatcher
     652             :             const SfxPoolItem *pPoolItem;
     653           0 :             if ( IsSaveVersionOnClose() )
     654             :             {
     655           0 :                 SfxStringItem aItem( SID_DOCINFO_COMMENTS, SfxResId(STR_AUTOMATICVERSION).toString() );
     656           0 :                 SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
     657           0 :                 const SfxPoolItem* ppArgs[] = { &aItem, &aWarnItem, 0 };
     658           0 :                 pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs );
     659             :             }
     660             :             else
     661             :             {
     662           0 :                 SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
     663           0 :                 const SfxPoolItem* ppArgs[] = { &aWarnItem, 0 };
     664           0 :                 pPoolItem = pFrame->GetBindings().ExecuteSynchron( IsReadOnlyMedium() ? SID_SAVEASDOC : SID_SAVEDOC, ppArgs );
     665             :             }
     666             : 
     667           0 :             if ( !pPoolItem || pPoolItem->ISA(SfxVoidItem) || ( pPoolItem->ISA(SfxBoolItem) && !static_cast<const SfxBoolItem*>( pPoolItem )->GetValue() ) )
     668           0 :                 return false;
     669             :         }
     670           0 :         else if ( RET_CANCEL == nRet )
     671             :             // Cancelled
     672           0 :             return false;
     673             :     }
     674             : 
     675           7 :     pImp->bPreparedForClose = true;
     676           7 :     return true;
     677             : }
     678             : 
     679             : 
     680             : #if HAVE_FEATURE_SCRIPTING
     681             : namespace
     682             : {
     683       74014 :     static BasicManager* lcl_getBasicManagerForDocument( const SfxObjectShell& _rDocument )
     684             :     {
     685       74014 :         if ( !_rDocument.Get_Impl()->m_bNoBasicCapabilities )
     686             :         {
     687       73976 :             if ( !_rDocument.Get_Impl()->bBasicInitialized )
     688        3038 :                 const_cast< SfxObjectShell& >( _rDocument ).InitBasicManager_Impl();
     689       73974 :             return _rDocument.Get_Impl()->aBasicManager.get();
     690             :         }
     691             : 
     692             :         // assume we do not have Basic ourself, but we can refer to another
     693             :         // document which does (by our model's XScriptInvocationContext::getScriptContainer).
     694             :         // In this case, we return the BasicManager of this other document.
     695             : 
     696             :         OSL_ENSURE( !Reference< XEmbeddedScripts >( _rDocument.GetModel(), UNO_QUERY ).is(),
     697             :             "lcl_getBasicManagerForDocument: inconsistency: no Basic, but an XEmbeddedScripts?" );
     698          38 :         Reference< XModel > xForeignDocument;
     699          76 :         Reference< XScriptInvocationContext > xContext( _rDocument.GetModel(), UNO_QUERY );
     700          38 :         if ( xContext.is() )
     701             :         {
     702          38 :             xForeignDocument.set( xContext->getScriptContainer(), UNO_QUERY );
     703             :             OSL_ENSURE( xForeignDocument.is() && xForeignDocument != _rDocument.GetModel(),
     704             :                 "lcl_getBasicManagerForDocument: no Basic, but providing ourself as script container?" );
     705             :         }
     706             : 
     707          38 :         BasicManager* pBasMgr = NULL;
     708          38 :         if ( xForeignDocument.is() )
     709           0 :             pBasMgr = ::basic::BasicManagerRepository::getDocumentBasicManager( xForeignDocument );
     710             : 
     711          76 :         return pBasMgr;
     712             :     }
     713             : }
     714             : #endif
     715             : 
     716       73976 : BasicManager* SfxObjectShell::GetBasicManager() const
     717             : {
     718       73976 :     BasicManager* pBasMgr = NULL;
     719             : #if HAVE_FEATURE_SCRIPTING
     720             :     try
     721             :     {
     722       73976 :         pBasMgr = lcl_getBasicManagerForDocument( *this );
     723       73974 :         if ( !pBasMgr )
     724        1192 :             pBasMgr = SfxGetpApp()->GetBasicManager();
     725             :     }
     726           0 :     catch (const css::ucb::ContentCreationException& e)
     727             :     {
     728             :         SAL_WARN("sfx.doc", "caught exception " << e.Message);
     729             :     }
     730             : #endif
     731       73974 :     return pBasMgr;
     732             : }
     733             : 
     734         440 : void SfxObjectShell::SetHasNoBasic()
     735             : {
     736         440 :     pImp->m_bNoBasicCapabilities = true;
     737         440 : }
     738             : 
     739        1370 : bool SfxObjectShell::HasBasic() const
     740             : {
     741             : #if !HAVE_FEATURE_SCRIPTING
     742             :     return false;
     743             : #else
     744        1370 :     if ( pImp->m_bNoBasicCapabilities )
     745           8 :         return false;
     746             : 
     747        1362 :     if ( !pImp->bBasicInitialized )
     748         680 :         const_cast< SfxObjectShell* >( this )->InitBasicManager_Impl();
     749             : 
     750        1362 :     return pImp->aBasicManager.isValid();
     751             : #endif
     752             : }
     753             : 
     754             : 
     755             : #if HAVE_FEATURE_SCRIPTING
     756             : namespace
     757             : {
     758             :     const Reference< XLibraryContainer >&
     759       18576 :     lcl_getOrCreateLibraryContainer( bool _bScript, Reference< XLibraryContainer >& _rxContainer,
     760             :         const Reference< XModel >& _rxDocument )
     761             :     {
     762       18576 :         if ( !_rxContainer.is() )
     763             :         {
     764             :             try
     765             :             {
     766       10670 :                 Reference< XStorageBasedDocument > xStorageDoc( _rxDocument, UNO_QUERY );
     767             :                 const Reference< XComponentContext > xContext(
     768       21340 :                     ::comphelper::getProcessComponentContext() );
     769             :                 _rxContainer.set (   _bScript
     770             :                                 ?   DocumentScriptLibraryContainer::create(
     771             :                                         xContext, xStorageDoc )
     772             :                                 :   DocumentDialogLibraryContainer::create(
     773             :                                         xContext, xStorageDoc )
     774       21340 :                                 ,   UNO_QUERY_THROW );
     775             :             }
     776         500 :             catch (const Exception&)
     777             :             {
     778             :                 DBG_UNHANDLED_EXCEPTION();
     779             :             }
     780             :         }
     781       18576 :         return _rxContainer;
     782             :     }
     783             : }
     784             : #endif
     785             : 
     786        3650 : Reference< XLibraryContainer > SfxObjectShell::GetDialogContainer()
     787             : {
     788             : #if HAVE_FEATURE_SCRIPTING
     789             :     try
     790             :     {
     791        3650 :         if ( !pImp->m_bNoBasicCapabilities )
     792        3650 :             return lcl_getOrCreateLibraryContainer( false, pImp->xDialogLibraries, GetModel() );
     793             : 
     794           0 :         BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
     795           0 :         if ( pBasMgr )
     796           0 :             return pBasMgr->GetDialogLibraryContainer().get();
     797             :     }
     798           0 :     catch (const css::ucb::ContentCreationException& e)
     799             :     {
     800             :         SAL_WARN("sfx.doc", "caught exception " << e.Message);
     801             :     }
     802             : 
     803             :     SAL_WARN("sfx.doc", "SfxObjectShell::GetDialogContainer: falling back to the application - is this really expected here?");
     804             : #endif
     805           0 :     return SfxGetpApp()->GetDialogContainer();
     806             : }
     807             : 
     808       14964 : Reference< XLibraryContainer > SfxObjectShell::GetBasicContainer()
     809             : {
     810             : #if HAVE_FEATURE_SCRIPTING
     811             :     try
     812             :     {
     813       14964 :         if ( !pImp->m_bNoBasicCapabilities )
     814       14926 :             return lcl_getOrCreateLibraryContainer( true, pImp->xBasicLibraries, GetModel() );
     815             : 
     816          38 :         BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
     817          38 :         if ( pBasMgr )
     818           0 :             return pBasMgr->GetScriptLibraryContainer().get();
     819             :     }
     820           0 :     catch (const css::ucb::ContentCreationException& e)
     821             :     {
     822             :         SAL_WARN("sfx.doc", "caught exception " << e.Message);
     823             :     }
     824             :     SAL_WARN("sfx.doc", "SfxObjectShell::GetBasicContainer: falling back to the application - is this really expected here?");
     825             : #endif
     826          38 :     return SfxGetpApp()->GetBasicContainer();
     827             : }
     828             : 
     829           2 : StarBASIC* SfxObjectShell::GetBasic() const
     830             : {
     831             : #if !HAVE_FEATURE_SCRIPTING
     832             :     return NULL;
     833             : #else
     834           2 :     BasicManager * pMan = GetBasicManager();
     835           2 :     return pMan ? pMan->GetLib(0) : NULL;
     836             : #endif
     837             : }
     838             : 
     839        3718 : void SfxObjectShell::InitBasicManager_Impl()
     840             : /*  [Description]
     841             : 
     842             :     Creates a document's BasicManager and loads it, if we are already based on
     843             :     a storage.
     844             : 
     845             :     [Note]
     846             : 
     847             :     This method has to be called  through the overloading of
     848             :     <SvPersist::Load()> (With the PStore from the parameters of load ())
     849             :     and from the overloading of <SvPersist::InitNew()> (with PStore = 0).
     850             : */
     851             : 
     852             : {
     853             :     /*  #163556# (DR) - Handling of recursive calls while creating the Bacic
     854             :         manager.
     855             : 
     856             :         It is possible that (while creating the Basic manager) the code that
     857             :         imports the Basic storage wants to access the Basic manager again.
     858             :         Especially in VBA compatibility mode, there is code that wants to
     859             :         access the "VBA Globals" object which is stored as global UNO constant
     860             :         in the Basic manager.
     861             : 
     862             :         To achieve correct handling of the recursive calls of this function
     863             :         from lcl_getBasicManagerForDocument(), the implementation of the
     864             :         function BasicManagerRepository::getDocumentBasicManager() has been
     865             :         changed to return the Basic manager currently under construction, when
     866             :         called repeatedly.
     867             : 
     868             :         The variable pImp->bBasicInitialized will be set to sal_True after
     869             :         construction now, to ensure that the recursive call of the function
     870             :         lcl_getBasicManagerForDocument() will be routed into this function too.
     871             : 
     872             :         Calling BasicManagerHolder::reset() twice is not a big problem, as it
     873             :         does not take ownership but stores only the raw pointer. Owner of all
     874             :         Basic managers is the global BasicManagerRepository instance.
     875             :      */
     876             : #if HAVE_FEATURE_SCRIPTING
     877             :     DBG_ASSERT( !pImp->bBasicInitialized && !pImp->aBasicManager.isValid(), "Lokaler BasicManager bereits vorhanden");
     878             :     try
     879             :     {
     880        3720 :         pImp->aBasicManager.reset( BasicManagerRepository::getDocumentBasicManager( GetModel() ) );
     881             :     }
     882           0 :     catch (const css::ucb::ContentCreationException& e)
     883             :     {
     884             :         SAL_WARN("sfx.doc", "caught exception " << e.Message);
     885             :     }
     886             :     DBG_ASSERT( pImp->aBasicManager.isValid(), "SfxObjectShell::InitBasicManager_Impl: did not get a BasicManager!" );
     887        3716 :     pImp->bBasicInitialized = true;
     888             : #endif
     889        3716 : }
     890             : 
     891             : 
     892             : 
     893        2977 : bool SfxObjectShell::DoClose()
     894             : {
     895        2977 :     return Close();
     896             : }
     897             : 
     898             : 
     899             : 
     900           0 : SfxObjectShell* SfxObjectShell::GetObjectShell()
     901             : {
     902           0 :     return this;
     903             : }
     904             : 
     905             : 
     906             : 
     907         154 : uno::Sequence< OUString > SfxObjectShell::GetEventNames()
     908             : {
     909             :     static uno::Sequence< OUString >* pEventNameContainer = NULL;
     910             : 
     911         154 :     if ( !pEventNameContainer )
     912             :     {
     913          40 :         SolarMutexGuard aGuard;
     914          40 :         if ( !pEventNameContainer )
     915             :         {
     916          40 :             static uno::Sequence< OUString > aEventNameContainer = GlobalEventConfig().getElementNames();
     917          40 :             pEventNameContainer = &aEventNameContainer;
     918          40 :         }
     919             :     }
     920             : 
     921         154 :     return *pEventNameContainer;
     922             : }
     923             : 
     924             : 
     925             : 
     926     1165534 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SfxObjectShell::GetModel() const
     927             : {
     928     1165534 :     return GetBaseModel();
     929             : }
     930             : 
     931        8410 : void SfxObjectShell::SetBaseModel( SfxBaseModel* pModel )
     932             : {
     933             :     OSL_ENSURE( !pImp->pBaseModel.is() || pModel == NULL, "Model already set!" );
     934        8410 :     pImp->pBaseModel.set( pModel );
     935        8410 :     if ( pImp->pBaseModel.is() )
     936             :     {
     937        8410 :         pImp->pBaseModel->addCloseListener( new SfxModelListener_Impl(this) );
     938             :     }
     939        8410 : }
     940             : 
     941             : 
     942             : 
     943     1282797 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SfxObjectShell::GetBaseModel() const
     944             : {
     945     1282797 :     return pImp->pBaseModel.get();
     946             : }
     947             : 
     948        5056 : void SfxObjectShell::SetAutoStyleFilterIndex(sal_uInt16 nSet)
     949             : {
     950        5056 :     pImp->nStyleFilter = nSet;
     951        5056 : }
     952             : 
     953           0 : sal_uInt16 SfxObjectShell::GetAutoStyleFilterIndex()
     954             : {
     955           0 :     return pImp->nStyleFilter;
     956             : }
     957             : 
     958             : 
     959       23803 : void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComponent )
     960             : {
     961       23803 :     WeakReference< XInterface >& rTheCurrentComponent = theCurrentComponent::get();
     962             : 
     963       23803 :     Reference< XInterface > xOldCurrentComp(rTheCurrentComponent);
     964       23803 :     if ( _rxComponent == xOldCurrentComp )
     965             :         // nothing to do
     966       36752 :         return;
     967             :     // note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not
     968             :     // /required/ for "_rxComponent == s_xCurrentComponent.get()".
     969             :     // In other words, it's still possible that we here do something which is not necessary,
     970             :     // but we should have filtered quite some unnecessary calls already.
     971             : 
     972             : #if HAVE_FEATURE_SCRIPTING
     973       10854 :     BasicManager* pAppMgr = SfxGetpApp()->GetBasicManager();
     974       10854 :     rTheCurrentComponent = _rxComponent;
     975       10854 :     if ( pAppMgr )
     976             :     {
     977             :         // set "ThisComponent" for Basic
     978       10854 :         pAppMgr->SetGlobalUNOConstant( "ThisComponent", Any( _rxComponent ) );
     979             : 
     980             :         // set new current component for VBA compatibility
     981       10854 :         if ( _rxComponent.is() )
     982             :         {
     983        5450 :             OString aVBAConstName = lclGetVBAGlobalConstName( _rxComponent );
     984        5450 :             if ( !aVBAConstName.isEmpty() )
     985             :             {
     986        5190 :                 pAppMgr->SetGlobalUNOConstant( aVBAConstName.getStr(), Any( _rxComponent ) );
     987        5190 :                 s_aRegisteredVBAConstants[ _rxComponent.get() ] = aVBAConstName;
     988        5450 :             }
     989             :         }
     990             :         // no new component passed -> remove last registered VBA component
     991        5404 :         else if ( xOldCurrentComp.is() )
     992             :         {
     993        5404 :             OString aVBAConstName = lclGetVBAGlobalConstName( xOldCurrentComp );
     994        5404 :             if ( !aVBAConstName.isEmpty() )
     995             :             {
     996        5158 :                 pAppMgr->SetGlobalUNOConstant( aVBAConstName.getStr(), Any( Reference< XInterface >() ) );
     997        5158 :                 s_aRegisteredVBAConstants.erase( xOldCurrentComp.get() );
     998        5404 :             }
     999             :         }
    1000       10854 :     }
    1001             : #endif
    1002             : }
    1003             : 
    1004        8489 : Reference< XInterface > SfxObjectShell::GetCurrentComponent()
    1005             : {
    1006        8489 :     return theCurrentComponent::get();
    1007             : }
    1008             : 
    1009             : 
    1010       15632 : OUString SfxObjectShell::GetServiceNameFromFactory( const OUString& rFact )
    1011             : {
    1012             :     //! Remove everything behind name!
    1013       15632 :     OUString aFact( rFact );
    1014       31264 :     OUString aPrefix("private:factory/");
    1015       15632 :     if ( aFact.startsWith( aPrefix ) )
    1016        1442 :         aFact = aFact.copy( aPrefix.getLength() );
    1017       15632 :     sal_Int32 nPos = aFact.indexOf( '?' );
    1018       31264 :     OUString aParam;
    1019       15632 :     if ( nPos != -1 )
    1020             :     {
    1021           0 :         aParam = aFact.copy( nPos );
    1022           0 :         aFact = aFact.copy( 0, nPos );
    1023           0 :         aParam = aParam.copy(1);
    1024             :     }
    1025       15632 :     aFact = comphelper::string::remove(aFact, '4');
    1026       15632 :     aFact = aFact.toAsciiLowerCase();
    1027             : 
    1028             :     // HACK: sometimes a real document service name is given here instead of
    1029             :     // a factory short name. Set return value directly to this service name as fallback
    1030             :     // in case next lines of code does nothing ...
    1031             :     // use rFact instead of normed aFact value !
    1032       15632 :     OUString aServiceName = rFact;
    1033             : 
    1034       15632 :     if ( aFact == "swriter" )
    1035             :     {
    1036       12636 :         aServiceName = "com.sun.star.text.TextDocument";
    1037             :     }
    1038        2996 :     else if ( aFact == "sweb" || aFact == "swriter/web" )
    1039             :     {
    1040         116 :         aServiceName = "com.sun.star.text.WebDocument";
    1041             :     }
    1042        2880 :     else if ( aFact == "sglobal" || aFact == "swriter/globaldocument" )
    1043             :     {
    1044          88 :         aServiceName = "com.sun.star.text.GlobalDocument";
    1045             :     }
    1046        2792 :     else if ( aFact == "scalc" )
    1047             :     {
    1048        1786 :         aServiceName = "com.sun.star.sheet.SpreadsheetDocument";
    1049             :     }
    1050        1006 :     else if ( aFact == "sdraw" )
    1051             :     {
    1052         524 :         aServiceName = "com.sun.star.drawing.DrawingDocument";
    1053             :     }
    1054         482 :     else if ( aFact == "simpress" )
    1055             :     {
    1056         272 :         aServiceName = "com.sun.star.presentation.PresentationDocument";
    1057             :     }
    1058         210 :     else if ( aFact == "schart" )
    1059             :     {
    1060           0 :         aServiceName = "com.sun.star.chart.ChartDocument";
    1061             :     }
    1062         210 :     else if ( aFact == "smath" )
    1063             :     {
    1064         210 :         aServiceName = "com.sun.star.formula.FormulaProperties";
    1065             :     }
    1066             : #if HAVE_FEATURE_SCRIPTING
    1067           0 :     else if ( aFact == "sbasic" )
    1068             :     {
    1069           0 :         aServiceName = "com.sun.star.script.BasicIDE";
    1070             :     }
    1071             : #endif
    1072             : #if HAVE_FEATURE_DBCONNECTIVITY
    1073           0 :     else if ( aFact == "sdatabase" )
    1074             :     {
    1075           0 :         aServiceName = "com.sun.star.sdb.OfficeDatabaseDocument";
    1076             :     }
    1077             : #endif
    1078             : 
    1079       31264 :     return aServiceName;
    1080             : }
    1081             : 
    1082           0 : SfxObjectShell* SfxObjectShell::CreateObjectByFactoryName( const OUString& rFact, SfxObjectCreateMode eMode )
    1083             : {
    1084           0 :     return CreateObject( GetServiceNameFromFactory( rFact ), eMode );
    1085             : }
    1086             : 
    1087             : 
    1088           0 : SfxObjectShell* SfxObjectShell::CreateObject( const OUString& rServiceName, SfxObjectCreateMode eCreateMode )
    1089             : {
    1090           0 :     if ( !rServiceName.isEmpty() )
    1091             :     {
    1092           0 :         uno::Reference < frame::XModel > xDoc( ::comphelper::getProcessServiceFactory()->createInstance( rServiceName ), UNO_QUERY );
    1093           0 :         if ( xDoc.is() )
    1094             :         {
    1095           0 :             uno::Reference < lang::XUnoTunnel > xObj( xDoc, UNO_QUERY );
    1096           0 :             uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
    1097           0 :             sal_Int64 nHandle = xObj->getSomething( aSeq );
    1098           0 :             if ( nHandle )
    1099             :             {
    1100           0 :                 SfxObjectShell* pRet = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
    1101           0 :                 pRet->SetCreateMode_Impl( eCreateMode );
    1102           0 :                 return pRet;
    1103           0 :             }
    1104           0 :         }
    1105             :     }
    1106             : 
    1107           0 :     return 0;
    1108             : }
    1109             : 
    1110           0 : Reference<lang::XComponent> SfxObjectShell::CreateAndLoadComponent( const SfxItemSet& rSet, SfxFrame* pFrame )
    1111             : {
    1112           0 :     uno::Sequence < beans::PropertyValue > aProps;
    1113           0 :     TransformItems( SID_OPENDOC, rSet, aProps );
    1114           0 :     SFX_ITEMSET_ARG(&rSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, false);
    1115           0 :     SFX_ITEMSET_ARG(&rSet, pTargetItem, SfxStringItem, SID_TARGETNAME, false);
    1116           0 :     OUString aURL;
    1117           0 :     OUString aTarget("_blank");
    1118           0 :     if ( pFileNameItem )
    1119           0 :         aURL = pFileNameItem->GetValue();
    1120           0 :     if ( pTargetItem )
    1121           0 :         aTarget = pTargetItem->GetValue();
    1122             : 
    1123           0 :     uno::Reference < frame::XComponentLoader > xLoader;
    1124           0 :     if ( pFrame )
    1125             :     {
    1126           0 :         xLoader = uno::Reference < frame::XComponentLoader >( pFrame->GetFrameInterface(), uno::UNO_QUERY );
    1127             :     }
    1128             :     else
    1129           0 :         xLoader = uno::Reference < frame::XComponentLoader >( frame::Desktop::create(comphelper::getProcessComponentContext()), uno::UNO_QUERY );
    1130             : 
    1131           0 :     Reference <lang::XComponent> xComp;
    1132             :     try
    1133             :     {
    1134           0 :         xComp = xLoader->loadComponentFromURL(aURL, aTarget, 0, aProps);
    1135             :     }
    1136           0 :     catch (const uno::Exception&)
    1137             :     {
    1138             :     }
    1139             : 
    1140           0 :     return xComp;
    1141             : }
    1142             : 
    1143          56 : SfxObjectShell* SfxObjectShell::GetShellFromComponent( const Reference<lang::XComponent>& xComp )
    1144             : {
    1145             :     try
    1146             :     {
    1147          56 :         Reference<lang::XUnoTunnel> xTunnel(xComp, UNO_QUERY_THROW);
    1148         112 :         Sequence <sal_Int8> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
    1149          56 :         sal_Int64 nHandle = xTunnel->getSomething( aSeq );
    1150          56 :         if (!nHandle)
    1151           0 :             return NULL;
    1152             : 
    1153         112 :         return reinterpret_cast< SfxObjectShell* >(sal::static_int_cast< sal_IntPtr >(  nHandle ));
    1154             :     }
    1155           0 :     catch (const Exception&)
    1156             :     {
    1157             :     }
    1158             : 
    1159           0 :     return NULL;
    1160             : }
    1161             : 
    1162        6972 : void SfxObjectShell::SetInitialized_Impl( const bool i_fromInitNew )
    1163             : {
    1164        6972 :     pImp->bInitialized = true;
    1165        6972 :     if ( i_fromInitNew )
    1166             :     {
    1167        2210 :         SetActivateEvent_Impl( SFX_EVENT_CREATEDOC );
    1168        2210 :         SfxGetpApp()->NotifyEvent( SfxEventHint( SFX_EVENT_DOCCREATED, GlobalEventConfig::GetEventName(STR_EVENT_DOCCREATED), this ) );
    1169             :     }
    1170             :     else
    1171             :     {
    1172        4762 :         SfxGetpApp()->NotifyEvent( SfxEventHint( SFX_EVENT_LOADFINISHED, GlobalEventConfig::GetEventName(STR_EVENT_LOADFINISHED), this ) );
    1173             :     }
    1174        6972 : }
    1175             : 
    1176             : 
    1177           0 : bool SfxObjectShell::IsChangeRecording() const
    1178             : {
    1179             :     // currently this function needs to be overwritten by Writer and Calc only
    1180             :     DBG_ASSERT( false, "function not implemented" );
    1181           0 :     return false;
    1182             : }
    1183             : 
    1184             : 
    1185           0 : bool SfxObjectShell::HasChangeRecordProtection() const
    1186             : {
    1187             :     // currently this function needs to be overwritten by Writer and Calc only
    1188             :     DBG_ASSERT( false, "function not implemented" );
    1189           0 :     return false;
    1190             : }
    1191             : 
    1192             : 
    1193           0 : void SfxObjectShell::SetChangeRecording( bool /*bActivate*/ )
    1194             : {
    1195             :     // currently this function needs to be overwritten by Writer and Calc only
    1196             :     DBG_ASSERT( false, "function not implemented" );
    1197           0 : }
    1198             : 
    1199             : 
    1200           0 : bool SfxObjectShell::SetProtectionPassword( const OUString & /*rPassword*/ )
    1201             : {
    1202             :     // currently this function needs to be overwritten by Writer and Calc only
    1203             :     DBG_ASSERT( false, "function not implemented" );
    1204           0 :     return false;
    1205             : }
    1206             : 
    1207             : 
    1208           0 : bool SfxObjectShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > & /*rPasswordHash*/ )
    1209             : {
    1210             :     // currently this function needs to be overwritten by Writer and Calc only
    1211             :     DBG_ASSERT( false, "function not implemented" );
    1212           0 :     return false;
    1213         951 : }
    1214             : 
    1215             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10