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

Generated by: LCOV version 1.10