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

Generated by: LCOV version 1.10