LCOV - code coverage report
Current view: top level - sfx2/source/doc - objxtor.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 2 394 0.5 %
Date: 2014-04-14 Functions: 2 65 3.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10