LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/doc - objmisc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 491 872 56.3 %
Date: 2012-12-17 Functions: 73 106 68.9 %
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 <svl/inetmsg.hxx>
      22             : #include <tools/diagnose_ex.h>
      23             : #include <svl/eitem.hxx>
      24             : #include <svl/stritem.hxx>
      25             : #include <svl/intitem.hxx>
      26             : #include <svtools/svparser.hxx> // SvKeyValue
      27             : #include <osl/mutex.hxx>
      28             : #include <cppuhelper/exc_hlp.hxx>
      29             : 
      30             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      31             : #include <com/sun/star/document/XDocumentProperties.hpp>
      32             : #include <com/sun/star/document/UpdateDocMode.hpp>
      33             : #include <com/sun/star/script/XTypeConverter.hpp>
      34             : #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
      35             : #include <com/sun/star/script/FinishEngineEvent.hpp>
      36             : #include <com/sun/star/script/InterruptReason.hpp>
      37             : #include <com/sun/star/script/XEngineListener.hpp>
      38             : #include <com/sun/star/script/XDebugging.hpp>
      39             : #include <com/sun/star/script/XInvocation.hpp>
      40             : #include <com/sun/star/script/ContextInformation.hpp>
      41             : #include <com/sun/star/script/FinishReason.hpp>
      42             : #include <com/sun/star/script/XEngine.hpp>
      43             : #include <com/sun/star/script/InterruptEngineEvent.hpp>
      44             : #include <com/sun/star/script/XLibraryAccess.hpp>
      45             : #include <com/sun/star/document/MacroExecMode.hpp>
      46             : #include <com/sun/star/document/XScriptInvocationContext.hpp>
      47             : #include <com/sun/star/embed/EmbedStates.hpp>
      48             : #include <com/sun/star/embed/XEmbedPersist.hpp>
      49             : #include <com/sun/star/util/XModifiable.hpp>
      50             : #include <com/sun/star/container/XChild.hpp>
      51             : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      52             : #include <com/sun/star/script/provider/XScript.hpp>
      53             : #include <com/sun/star/script/provider/XScriptProvider.hpp>
      54             : #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
      55             : 
      56             : #include <toolkit/unohlp.hxx>
      57             : 
      58             : #include <com/sun/star/uno/Reference.h>
      59             : #include <com/sun/star/uno/Any.h>
      60             : #include <com/sun/star/ucb/XContent.hpp>
      61             : #include <com/sun/star/task/ErrorCodeRequest.hpp>
      62             : #include <unotools/securityoptions.hxx>
      63             : 
      64             : #include <comphelper/componentcontext.hxx>
      65             : #include <comphelper/configurationhelper.hxx>
      66             : #include <comphelper/processfactory.hxx>
      67             : #include <comphelper/string.hxx>
      68             : 
      69             : #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
      70             : #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
      71             : #include <com/sun/star/task/InteractionClassification.hpp>
      72             : #include <com/sun/star/frame/XModel.hpp>
      73             : 
      74             : using namespace ::com::sun::star;
      75             : using namespace ::com::sun::star::uno;
      76             : using namespace ::com::sun::star::ucb;
      77             : using namespace ::com::sun::star::document;
      78             : using namespace ::com::sun::star::frame;
      79             : using namespace ::com::sun::star::script;
      80             : using namespace ::com::sun::star::script::provider;
      81             : using namespace ::com::sun::star::container;
      82             : #include <basic/sbuno.hxx>
      83             : #include <basic/sbstar.hxx>
      84             : #include <basic/basmgr.hxx>
      85             : #include <vcl/msgbox.hxx>
      86             : #include <basic/sbx.hxx>
      87             : #include <svtools/sfxecode.hxx>
      88             : #include <svtools/ehdl.hxx>
      89             : 
      90             : #include <unotools/pathoptions.hxx>
      91             : #include <unotools/ucbhelper.hxx>
      92             : #include <tools/inetmime.hxx>
      93             : #include <tools/urlobj.hxx>
      94             : #include <svl/inettype.hxx>
      95             : #include <svl/sharecontrolfile.hxx>
      96             : #include <osl/file.hxx>
      97             : #include <rtl/bootstrap.hxx>
      98             : #include <vcl/svapp.hxx>
      99             : #include <framework/interaction.hxx>
     100             : #include <framework/documentundoguard.hxx>
     101             : #include <comphelper/interaction.hxx>
     102             : #include <comphelper/storagehelper.hxx>
     103             : #include <comphelper/documentconstants.hxx>
     104             : 
     105             : #include <sfx2/signaturestate.hxx>
     106             : #include <sfx2/app.hxx>
     107             : #include "appdata.hxx"
     108             : #include <sfx2/request.hxx>
     109             : #include <sfx2/bindings.hxx>
     110             : #include "sfx2/sfxresid.hxx"
     111             : #include <sfx2/docfile.hxx>
     112             : #include <sfx2/docfilt.hxx>
     113             : #include <sfx2/objsh.hxx>
     114             : #include "objshimp.hxx"
     115             : #include <sfx2/event.hxx>
     116             : #include "fltfnc.hxx"
     117             : #include <sfx2/sfx.hrc>
     118             : #include <sfx2/dispatch.hxx>
     119             : #include <sfx2/viewfrm.hxx>
     120             : #include <sfx2/viewsh.hxx>
     121             : #include <sfx2/ctrlitem.hxx>
     122             : #include "arrdecl.hxx"
     123             : #include <sfx2/module.hxx>
     124             : #include <sfx2/docfac.hxx>
     125             : #include "helper.hxx"
     126             : #include "doc.hrc"
     127             : #include "workwin.hxx"
     128             : #include "helpid.hrc"
     129             : #include "../appl/app.hrc"
     130             : #include <sfx2/sfxdlg.hxx>
     131             : #include "appbaslib.hxx"
     132             : #include <openflag.hxx>                 // SFX_STREAM_READWRITE
     133             : 
     134             : using namespace ::com::sun::star;
     135             : 
     136             : // class SfxHeaderAttributes_Impl ----------------------------------------
     137             : 
     138         570 : class SfxHeaderAttributes_Impl : public SvKeyValueIterator
     139             : {
     140             : private:
     141             :     SfxObjectShell* pDoc;
     142             :     SvKeyValueIteratorRef xIter;
     143             :     sal_Bool bAlert;
     144             : 
     145             : public:
     146         711 :     SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) :
     147             :         SvKeyValueIterator(), pDoc( pSh ),
     148             :         xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ),
     149         711 :         bAlert( sal_False ) {}
     150             : 
     151           2 :     virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); }
     152           2 :     virtual sal_Bool GetNext( SvKeyValue& rKV ) { return xIter->GetNext( rKV ); }
     153             :     virtual void Append( const SvKeyValue& rKV );
     154             : 
     155           0 :     void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = sal_False; }
     156             :     void SetAttributes();
     157             :     void SetAttribute( const SvKeyValue& rKV );
     158             : };
     159             : 
     160             : //=========================================================================
     161             : 
     162             : sal_uInt16 const aTitleMap_Impl[3][2] =
     163             : {
     164             :                                 //  local               remote
     165             :     /*  SFX_TITLE_CAPTION   */  {   SFX_TITLE_FILENAME, SFX_TITLE_TITLE },
     166             :     /*  SFX_TITLE_PICKLIST  */  {   32,                 SFX_TITLE_FULLNAME },
     167             :     /*  SFX_TITLE_HISTORY   */  {   32,                 SFX_TITLE_FULLNAME }
     168             : };
     169             : 
     170             : //=========================================================================
     171             : 
     172           0 : void SfxObjectShell::AbortImport()
     173             : {
     174           0 :     pImp->bIsAbortingImport = sal_True;
     175           0 : }
     176             : 
     177             : //-------------------------------------------------------------------------
     178             : 
     179        1214 : sal_Bool SfxObjectShell::IsAbortingImport() const
     180             : {
     181        1214 :     return pImp->bIsAbortingImport;
     182             : }
     183             : 
     184             : //-------------------------------------------------------------------------
     185             : 
     186             : uno::Reference<document::XDocumentProperties>
     187        1867 : SfxObjectShell::getDocProperties()
     188             : {
     189             :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     190        1867 :         GetModel(), uno::UNO_QUERY_THROW);
     191             :     uno::Reference<document::XDocumentProperties> xDocProps(
     192        1867 :         xDPS->getDocumentProperties());
     193             :     DBG_ASSERT(xDocProps.is(),
     194             :         "SfxObjectShell: model has no DocumentProperties");
     195        1867 :     return xDocProps;
     196             : }
     197             : 
     198             : //-------------------------------------------------------------------------
     199             : 
     200         292 : void SfxObjectShell::DoFlushDocInfo()
     201             : {
     202         292 : }
     203             : 
     204             : //-------------------------------------------------------------------------
     205             : 
     206             : // Note: the only thing that calls this is the modification event handler
     207             : // that is installed at the XDocumentProperties
     208        3588 : void SfxObjectShell::FlushDocInfo()
     209             : {
     210        3588 :     if ( IsLoading() )
     211        3588 :         return;
     212             : 
     213         332 :     SetModified(sal_True);
     214         332 :     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     215         332 :     DoFlushDocInfo(); // call template method
     216         332 :     ::rtl::OUString url(xDocProps->getAutoloadURL());
     217         332 :     sal_Int32 delay(xDocProps->getAutoloadSecs());
     218             :     SetAutoLoad( INetURLObject(url), delay * 1000,
     219         332 :                  (delay > 0) || !url.isEmpty() );
     220             : }
     221             : 
     222             : //-------------------------------------------------------------------------
     223             : 
     224        1405 : void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage )
     225             : {
     226        1405 :     if(pImp->lErr==ERRCODE_NONE)
     227             :     {
     228         831 :         pImp->lErr=lErr;
     229             : 
     230         831 :         if( lErr != ERRCODE_NONE && !aLogMessage.isEmpty() )
     231         620 :             AddLog( aLogMessage );
     232             :     }
     233        1405 : }
     234             : 
     235             : //-------------------------------------------------------------------------
     236             : 
     237        2359 : sal_uInt32 SfxObjectShell::GetError() const
     238             : {
     239        2359 :     return ERRCODE_TOERROR(GetErrorCode());
     240             : }
     241             : 
     242             : //-------------------------------------------------------------------------
     243             : 
     244        3826 : sal_uInt32 SfxObjectShell::GetErrorCode() const
     245             : {
     246        3826 :     sal_uInt32 lError=pImp->lErr;
     247        3826 :     if(!lError && GetMedium())
     248        3190 :         lError=GetMedium()->GetErrorCode();
     249        3826 :     return lError;
     250             : }
     251             : 
     252             : //-------------------------------------------------------------------------
     253             : 
     254        1476 : void SfxObjectShell::ResetError()
     255             : {
     256        1476 :     if( pImp->lErr != ERRCODE_NONE )
     257         604 :         AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Resetting Error."  ) );
     258             : 
     259        1476 :     pImp->lErr=0;
     260        1476 :     SfxMedium * pMed = GetMedium();
     261        1476 :     if( pMed )
     262        1476 :         pMed->ResetError();
     263        1476 : }
     264             : 
     265             : //-------------------------------------------------------------------------
     266             : 
     267        4206 : sal_Bool SfxObjectShell::IsTemplate() const
     268             : {
     269        4206 :     return pImp->bIsTemplate;
     270             : }
     271             : 
     272             : //-------------------------------------------------------------------------
     273             : 
     274       11372 : void SfxObjectShell::EnableSetModified( sal_Bool bEnable )
     275             : {
     276             : #ifdef DBG_UTIL
     277             :     if ( bEnable == pImp->m_bEnableSetModified )
     278             :         DBG_WARNING( "SFX_PERSIST: EnableSetModified 2x called with the same value" );
     279             : #endif
     280       11372 :     pImp->m_bEnableSetModified = bEnable;
     281       11372 : }
     282             : 
     283             : //-------------------------------------------------------------------------
     284             : 
     285      112284 : sal_Bool SfxObjectShell::IsEnableSetModified() const
     286             : {
     287      112284 :     return pImp->m_bEnableSetModified && !IsReadOnly();
     288             : }
     289             : 
     290             : //-------------------------------------------------------------------------
     291             : 
     292       15522 : sal_Bool SfxObjectShell::IsModified()
     293             : {
     294       15522 :     if ( pImp->m_bIsModified )
     295        8057 :         return sal_True;
     296             : 
     297        7465 :     if ( !pImp->m_xDocStorage.is() || IsReadOnly() )
     298             :     {
     299             :         // if the document still has no storage and is not set to be modified explicitly it is not modified
     300             :         // a readonly document is also not modified
     301             : 
     302         792 :         return sal_False;
     303             :     }
     304             : 
     305        6673 :     uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
     306        8677 :     for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
     307             :     {
     308        2004 :         uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
     309             :         OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
     310        2004 :         if ( xObj.is() )
     311             :         {
     312             :             try
     313             :             {
     314        2004 :                 sal_Int32 nState = xObj->getCurrentState();
     315        2004 :                 if ( nState != embed::EmbedStates::LOADED )
     316             :                 {
     317        1950 :                     uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
     318        1950 :                     if ( xModifiable.is() && xModifiable->isModified() )
     319           0 :                         return sal_True;
     320             :                 }
     321             :             }
     322           0 :             catch( uno::Exception& )
     323             :             {}
     324             :         }
     325        2004 :     }
     326             : 
     327        6673 :     return sal_False;
     328             : }
     329             : 
     330             : //-------------------------------------------------------------------------
     331             : 
     332       11286 : void SfxObjectShell::SetModified( sal_Bool bModifiedP )
     333             : {
     334             : #ifdef DBG_UTIL
     335             :     if ( !bModifiedP && !IsEnableSetModified() )
     336             :         DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), although IsEnableSetModified() == sal_False" );
     337             : #endif
     338             : 
     339       11286 :     if( !IsEnableSetModified() )
     340       11373 :         return;
     341             : 
     342       11199 :     if( pImp->m_bIsModified != bModifiedP )
     343             :     {
     344        1862 :         pImp->m_bIsModified = bModifiedP;
     345        1862 :         ModifyChanged();
     346             :     }
     347             : }
     348             : 
     349             : //-------------------------------------------------------------------------
     350             : 
     351        1862 : void SfxObjectShell::ModifyChanged()
     352             : {
     353        1862 :     if ( pImp->bClosing )
     354             :         // SetModified dispose of the models!
     355        1862 :         return;
     356             : 
     357             :     {DBG_CHKTHIS(SfxObjectShell, 0);}
     358             : 
     359        1862 :     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
     360        1862 :     if ( pViewFrame )
     361        1256 :         pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS );
     362             : 
     363        1862 :     Invalidate( SID_SIGNATURE );
     364        1862 :     Invalidate( SID_MACRO_SIGNATURE );
     365        1862 :     Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );    // xmlsec05, signed state might change in title...
     366             : 
     367        1862 :     SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) );
     368             : }
     369             : 
     370             : //-------------------------------------------------------------------------
     371             : 
     372        6677 : sal_Bool SfxObjectShell::IsReadOnlyUI() const
     373             : 
     374             : /*  [Description]
     375             : 
     376             :     Returns sal_True if the document for the UI is treated as r/o. This is
     377             :     regardless of the actual r/o, which can be checked with <IsReadOnly()>.
     378             : */
     379             : 
     380             : {
     381        6677 :     return pImp->bReadOnlyUI;
     382             : }
     383             : 
     384             : //-------------------------------------------------------------------------
     385             : 
     386         712 : sal_Bool SfxObjectShell::IsReadOnlyMedium() const
     387             : 
     388             : /*  [Description]
     389             : 
     390             :     Returns sal_True when the medium is r/o, for instance when opened as r/o.
     391             : */
     392             : 
     393             : {
     394         712 :     if ( !pMedium )
     395           0 :         return sal_True;
     396         712 :     return pMedium->IsReadOnly();
     397             : }
     398             : 
     399           0 : bool SfxObjectShell::IsOriginallyReadOnlyMedium() const
     400             : {
     401           0 :     return pMedium == 0 || pMedium->IsOriginallyReadOnly();
     402             : }
     403             : 
     404             : //-------------------------------------------------------------------------
     405             : 
     406         196 : void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly )
     407             : 
     408             : /*  [Description]
     409             : 
     410             :     Turns the document in an r/o and r/w state respectively without reloading
     411             :     it and without changing the open mode of the medium.
     412             : */
     413             : 
     414             : {
     415         196 :     if ( bReadOnly != pImp->bReadOnlyUI )
     416             :     {
     417         196 :         pImp->bReadOnlyUI = bReadOnly;
     418         196 :         Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
     419             :     }
     420         196 : }
     421             : 
     422             : //-------------------------------------------------------------------------
     423             : 
     424           2 : void SfxObjectShell::SetReadOnly()
     425             : {
     426             :     // Let the document be completely readonly, means that the
     427             :     // medium open mode is adjusted accordingly, and the write lock
     428             :     // on the file is removed.
     429             : 
     430           2 :      if ( pMedium && !IsReadOnlyMedium() )
     431             :     {
     432           0 :         sal_Bool bWasROUI = IsReadOnly();
     433             : 
     434           0 :         pMedium->UnlockFile( sal_False );
     435             : 
     436             :         // the storage-based mediums are already based on the temporary file
     437             :         // so UnlockFile has already closed the locking stream
     438           0 :         if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() )
     439           0 :             pMedium->CloseInStream();
     440             : 
     441           0 :         pMedium->SetOpenMode( SFX_STREAM_READONLY, sal_True );
     442           0 :         pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
     443             : 
     444           0 :         if ( !bWasROUI )
     445           0 :             Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
     446             :     }
     447           2 : }
     448             : //-------------------------------------------------------------------------
     449             : 
     450       62091 : sal_Bool SfxObjectShell::IsReadOnly() const
     451             : {
     452       62091 :     return pImp->bReadOnlyUI || pMedium == 0;
     453             : }
     454             : 
     455             : //-------------------------------------------------------------------------
     456             : 
     457         548 : sal_Bool SfxObjectShell::IsInModalMode() const
     458             : {
     459         548 :     return pImp->bModalMode || pImp->bRunningMacro;
     460             : }
     461             : 
     462         548 : sal_Bool SfxObjectShell::AcceptStateUpdate() const
     463             : {
     464         548 :     return !IsInModalMode();
     465             : }
     466             : 
     467             : //-------------------------------------------------------------------------
     468             : 
     469           0 : void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal )
     470             : {
     471           0 :     if ( !pImp->bRunningMacro != !bModal )
     472             :     {
     473           0 :         pImp->bRunningMacro = bModal;
     474           0 :         Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
     475             :     }
     476           0 : }
     477             : 
     478             : //-------------------------------------------------------------------------
     479             : 
     480           0 : void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal )
     481             : {
     482             :     // Broadcast only if modified, or otherwise it will possibly go into
     483             :     // an endless loop
     484           0 :     if ( !pImp->bModalMode != !bModal )
     485             :     {
     486             :         // Central count
     487           0 :         sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode;
     488           0 :         if ( bModal )
     489           0 :             ++rDocModalCount;
     490             :         else
     491           0 :             --rDocModalCount;
     492             : 
     493             :         // Switch
     494           0 :         pImp->bModalMode = bModal;
     495           0 :         Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
     496             :     }
     497           0 : }
     498             : 
     499             : //--------------------------------------------------------------------
     500           0 : sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave )
     501             : {
     502           0 :     sal_Bool bResult = sal_True;
     503             : 
     504           0 :     if ( bShared != IsDocShared() )
     505             :     {
     506           0 :         ::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
     507             : 
     508           0 :         if ( aOrigURL.isEmpty() && bSave )
     509             :         {
     510             :             // this is a new document, let it be stored before switching to the shared mode;
     511             :             // the storing should be done without shared flag, since it is possible that the
     512             :             // target location does not allow to create sharing control file;
     513             :             // the shared flag will be set later after creation of sharing control file
     514           0 :             SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
     515             : 
     516           0 :             if ( pViewFrame )
     517             :             {
     518             :                 // TODO/LATER: currently the application guards against the reentrance problem
     519           0 :                 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
     520           0 :                 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
     521           0 :                 bResult = ( pResult && pResult->GetValue() );
     522           0 :                 if ( bResult )
     523           0 :                     aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
     524             :             }
     525             :         }
     526             : 
     527           0 :         sal_Bool bOldValue = HasSharedXMLFlagSet();
     528           0 :         SetSharedXMLFlag( bShared );
     529             : 
     530           0 :         sal_Bool bRemoveEntryOnError = sal_False;
     531           0 :         if ( bResult && bShared )
     532             :         {
     533             :             try
     534             :             {
     535           0 :                 ::svt::ShareControlFile aControlFile( aOrigURL );
     536           0 :                 aControlFile.InsertOwnEntry();
     537           0 :                 bRemoveEntryOnError = sal_True;
     538             :             }
     539           0 :             catch( uno::Exception& )
     540             :             {
     541           0 :                 bResult = sal_False;
     542             :             }
     543             :         }
     544             : 
     545           0 :         if ( bResult && bSave )
     546             :         {
     547           0 :             SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
     548             : 
     549           0 :             if ( pViewFrame )
     550             :             {
     551             :                 // TODO/LATER: currently the application guards against the reentrance problem
     552           0 :                 SetModified( sal_True ); // the modified flag has to be set to let the document be stored with the shared flag
     553           0 :                 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
     554           0 :                 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
     555           0 :                 bResult = ( pResult && pResult->GetValue() );
     556             :             }
     557             :         }
     558             : 
     559           0 :         if ( bResult )
     560             :         {
     561             :             // TODO/LATER: Is it possible that the following calls fail?
     562           0 :             if ( bShared )
     563             :             {
     564           0 :                 pImp->m_aSharedFileURL = aOrigURL;
     565           0 :                 GetMedium()->SwitchDocumentToTempFile();
     566             :             }
     567             :             else
     568             :             {
     569           0 :                 ::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
     570           0 :                 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
     571           0 :                 pImp->m_aSharedFileURL = ::rtl::OUString();
     572             : 
     573             :                 // now remove the temporary file the document was based on
     574           0 :                 ::utl::UCBContentHelper::Kill( aTempFileURL );
     575             : 
     576             :                 try
     577             :                 {
     578             :                     // aOrigURL can not be used since it contains an old value
     579           0 :                     ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
     580           0 :                     aControlFile.RemoveFile();
     581             :                 }
     582           0 :                 catch( uno::Exception& )
     583             :                 {
     584           0 :                 }
     585             :             }
     586             :         }
     587             :         else
     588             :         {
     589             :             // the saving has failed!
     590           0 :             if ( bRemoveEntryOnError )
     591             :             {
     592             :                 try
     593             :                 {
     594           0 :                     ::svt::ShareControlFile aControlFile( aOrigURL );
     595           0 :                     aControlFile.RemoveEntry();
     596             :                 }
     597           0 :                 catch( uno::Exception& )
     598             :                 {}
     599             :             }
     600             : 
     601           0 :             SetSharedXMLFlag( bOldValue );
     602           0 :         }
     603             :     }
     604             :     else
     605           0 :         bResult = sal_False; // the second switch to the same mode
     606             : 
     607           0 :     if ( bResult )
     608           0 :         SetTitle( String() );
     609             : 
     610           0 :     return bResult;
     611             : }
     612             : 
     613             : //--------------------------------------------------------------------
     614             : 
     615           0 : void SfxObjectShell::FreeSharedFile()
     616             : {
     617           0 :     if ( pMedium )
     618           0 :         FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
     619           0 : }
     620             : 
     621             : //--------------------------------------------------------------------
     622           0 : void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL )
     623             : {
     624           0 :     SetSharedXMLFlag( sal_False );
     625             : 
     626           0 :     if ( IsDocShared() && !aTempFileURL.isEmpty()
     627           0 :       && !::utl::UCBContentHelper::EqualURLs( aTempFileURL, GetSharedFileURL() ) )
     628             :     {
     629           0 :         if ( pImp->m_bAllowShareControlFileClean )
     630             :         {
     631             :             try
     632             :             {
     633           0 :                 ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
     634           0 :                 aControlFile.RemoveEntry();
     635             :             }
     636           0 :             catch( uno::Exception& )
     637             :             {
     638             :             }
     639             :         }
     640             : 
     641             :         // the cleaning is forbidden only once
     642           0 :         pImp->m_bAllowShareControlFileClean = sal_True;
     643             : 
     644             :         // now remove the temporary file the document is based currently on
     645           0 :         ::utl::UCBContentHelper::Kill( aTempFileURL );
     646             : 
     647           0 :         pImp->m_aSharedFileURL = ::rtl::OUString();
     648             :     }
     649           0 : }
     650             : 
     651             : //--------------------------------------------------------------------
     652           0 : void SfxObjectShell::DoNotCleanShareControlFile()
     653             : {
     654           0 :     pImp->m_bAllowShareControlFileClean = sal_False;
     655           0 : }
     656             : 
     657             : //--------------------------------------------------------------------
     658          66 : void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const
     659             : {
     660          66 :     pImp->m_bSharedXMLFlag = bFlag;
     661          66 : }
     662             : 
     663             : //--------------------------------------------------------------------
     664         160 : sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const
     665             : {
     666         160 :     return pImp->m_bSharedXMLFlag;
     667             : }
     668             : 
     669             : //--------------------------------------------------------------------
     670             : 
     671        8330 : sal_Bool SfxObjectShell::IsDocShared() const
     672             : {
     673        8330 :     return ( !pImp->m_aSharedFileURL.isEmpty() );
     674             : }
     675             : 
     676             : //--------------------------------------------------------------------
     677             : 
     678           0 : ::rtl::OUString SfxObjectShell::GetSharedFileURL() const
     679             : {
     680           0 :     return pImp->m_aSharedFileURL;
     681             : }
     682             : 
     683             : //--------------------------------------------------------------------
     684             : 
     685           6 : Size SfxObjectShell::GetFirstPageSize()
     686             : {
     687           6 :     return GetVisArea(ASPECT_THUMBNAIL).GetSize();
     688             : }
     689             : 
     690             : 
     691             : //--------------------------------------------------------------------
     692             : 
     693         606 : IndexBitSet& SfxObjectShell::GetNoSet_Impl()
     694             : {
     695         606 :     return pImp->aBitSet;
     696             : }
     697             : 
     698             : //--------------------------------------------------------------------
     699             : // changes the title of the document
     700             : 
     701         306 : void SfxObjectShell::SetTitle
     702             : (
     703             :     const String& rTitle                // the new Document Title
     704             : )
     705             : 
     706             : /*  [Description]
     707             : 
     708             :     With this method, the title of the document can be set.
     709             :     This corresponds initially to the full file name. A setting of the
     710             :     title does not affect the file name, but it will be shown in the
     711             :     Caption-Bars of the MDI-window.
     712             : */
     713             : 
     714             : {
     715             :     DBG_CHKTHIS(SfxObjectShell, 0);
     716             : 
     717             :     // Nothing to do?
     718        1836 :     if ( ( ( HasName() && pImp->aTitle == rTitle )
     719        1224 :         || ( !HasName() && GetTitle() == rTitle ) )
     720         306 :       && !IsDocShared() )
     721         612 :         return;
     722             : 
     723           0 :     SfxApplication *pSfxApp = SFX_APP();
     724             : 
     725             :     // If possible relase the unnamed number.
     726           0 :     if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber )
     727             :     {
     728           0 :         pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
     729           0 :         pImp->bIsNamedVisible = 0;
     730             :     }
     731             : 
     732             :     // Set Title
     733           0 :     pImp->aTitle = rTitle;
     734             : 
     735             :     // Notification
     736           0 :     if ( GetMedium() )
     737             :     {
     738           0 :         SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
     739           0 :         Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
     740             :     }
     741             : }
     742             : 
     743             : //--------------------------------------------------------------------
     744             : 
     745             : #if OSL_DEBUG_LEVEL > 1
     746             : String X(const String &rRet)
     747             : {
     748             :     if ( !rRet.Len() )
     749             :         return DEFINE_CONST_UNICODE( "-empty-" );
     750             :     return rRet;
     751             : }
     752             : #else
     753             : #define X(ret) ret
     754             : #endif
     755             : 
     756             : //--------------------------------------------------------------------
     757        5609 : String SfxObjectShell::GetTitle
     758             : (
     759             :     sal_uInt16  nMaxLength      /*  0 (default)
     760             :                                 the title itself, as it is
     761             : 
     762             :                                 1 (==SFX_TITLE_FILENAME)
     763             :                                 provides the logical file name without path
     764             :                                 (under WNT depending on the system settings
     765             :                                 without extension)
     766             : 
     767             :                                 2 (==SFX_TITLE_FULLNAME)
     768             :                                 provides the logical file names with full path
     769             :                                 (remote =>:: com:: sun:: star:: util:: URL)
     770             : 
     771             :                                 3 (==SFX_TITLE_APINAME)
     772             :                                 provides the logical filname without path
     773             :                                 and extension
     774             : 
     775             :                                 4 (==SFX_TITLE_DETECT)
     776             :                                 provides the complete title, if not set yet
     777             :                                 it will be created from DocInfo or the name of
     778             :                                 the medium.
     779             : 
     780             :                                 5 (==SFX_TITLE_CAPTION)
     781             :                                 provides the Title just like MB now in the
     782             :                                 CaptionBar view
     783             : 
     784             :                                 6 (==SFX_TITLE_PICKLIST)
     785             :                                 returns the Title, just like MB now would
     786             :                                 display it in the in the PickList
     787             : 
     788             :                                 7 (==SFX_TITLE_HISTORY)
     789             :                                 returns the Title just like MB now would
     790             :                                 display it in the in the History
     791             : 
     792             :                                 10 bis USHRT_MAX
     793             :                                 provides the 'nMaxLength' of the logical
     794             :                                 file name including the path
     795             :                                 (remote => ::com::sun::star::util::URL)
     796             :                                 */
     797             : ) const
     798             : 
     799             : /*  [Description]
     800             : 
     801             :     Returns the title or logical file name of the document, depending on the
     802             :     'nMaxLength'.
     803             : 
     804             :     If the file name with path is used, the Name shortened by replacing one or
     805             :     more directory names with "...", URLs are currently always returned
     806             :     in complete form.
     807             : */
     808             : 
     809             : {
     810        5609 :     SfxMedium *pMed = GetMedium();
     811        5609 :     if ( IsLoading() )
     812         893 :         return String();
     813             : 
     814             :     // Create Title?
     815        4716 :     if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() )
     816             :     {
     817             :         static sal_Bool bRecur = sal_False;
     818         334 :         if ( bRecur )
     819           0 :             return DEFINE_CONST_UNICODE( "-not available-" );
     820         334 :         bRecur = sal_True;
     821             : 
     822         334 :         String aTitle;
     823         334 :         SfxObjectShell *pThis = (SfxObjectShell*) this;
     824             : 
     825         334 :         if ( pMed )
     826             :         {
     827         334 :             SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
     828         334 :             if ( pNameItem )
     829           0 :                 aTitle = pNameItem->GetValue();
     830             :         }
     831             : 
     832         334 :         if ( !aTitle.Len() )
     833         334 :             aTitle = GetTitle( SFX_TITLE_FILENAME );
     834             : 
     835         334 :         if ( IsTemplate() )
     836           0 :             pThis->SetTitle( aTitle );
     837         334 :         bRecur = sal_False;
     838         334 :         return X(aTitle);
     839             :     }
     840        4382 :     else if (SFX_TITLE_APINAME == nMaxLength )
     841         510 :         return X(GetAPIName());
     842             : 
     843             :     // Special case templates:
     844        3872 :     if( IsTemplate() && pImp->aTitle.Len() &&
     845             :          ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
     846           0 :         return X(pImp->aTitle);
     847             : 
     848             :     // Picklist/Caption is mapped
     849        3872 :     if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
     850             :     {
     851             :         // If a specific title was given at open:
     852             :         // important for URLs: use INET_PROT_FILE for which the set title is not
     853             :         // considered. (See below, analysis of aTitleMap_Impl)
     854         526 :         SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
     855         526 :         if ( pNameItem )
     856           0 :             return X( pNameItem->GetValue() );
     857             :     }
     858             : 
     859             :     // Still unnamed?
     860             :     DBG_ASSERT( !HasName() || pMed, "HasName() but no Medium?!?" );
     861        3872 :     if ( !HasName() || !pMed )
     862             :     {
     863             :         // Title already set?
     864        2484 :         if ( pImp->aTitle.Len() )
     865           0 :             return X(pImp->aTitle);
     866             : 
     867             :         // must it be numbered?
     868        2484 :         rtl::OUString aNoName(SFX2_RESSTR(STR_NONAME));
     869        2484 :         if (pImp->bIsNamedVisible)
     870             :         {
     871             :             // Append number
     872          27 :             aNoName += rtl::OUString::valueOf(static_cast<sal_Int32>(pImp->nVisualDocumentNumber));
     873             :         }
     874             : 
     875             :         // Document called "noname" for the time being
     876        2484 :         return X(aNoName);
     877             :     }
     878             : 
     879        1388 :     const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
     880        1388 :     if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
     881             :     {
     882             :         sal_uInt16 nRemote;
     883         526 :         if( !pMed || aURL.GetProtocol() == INET_PROT_FILE )
     884         526 :             nRemote = 0;
     885             :         else
     886           0 :             nRemote = 1;
     887         526 :         nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote];
     888             :     }
     889             : 
     890             :     // Local file?
     891        1388 :     if ( aURL.GetProtocol() == INET_PROT_FILE )
     892             :     {
     893        1386 :         String aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() );
     894        1386 :         if ( nMaxLength == SFX_TITLE_FULLNAME )
     895           0 :             return X( aName );
     896        1386 :         else if ( nMaxLength == SFX_TITLE_FILENAME )
     897           0 :             return X( aURL.getName( INetURLObject::LAST_SEGMENT,
     898             :                 true, INetURLObject::DECODE_WITH_CHARSET ) );
     899        1386 :         else if ( !pImp->aTitle.Len() )
     900             :             pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT,
     901         711 :                                          true, INetURLObject::DECODE_WITH_CHARSET );
     902             :     }
     903             :     else
     904             :     {
     905             :         // ::com::sun::star::util::URL-Versions
     906           2 :         if ( nMaxLength >= SFX_TITLE_MAXLEN )
     907             :         {
     908           0 :             String aComplete( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     909           0 :             if( aComplete.Len() > nMaxLength )
     910             :             {
     911           0 :                 String aRet( DEFINE_CONST_UNICODE( "..." ) );
     912           0 :                 aRet += aComplete.Copy( aComplete.Len() - nMaxLength + 3, nMaxLength - 3 );
     913           0 :                 return X( aRet );
     914             :             }
     915             :             else
     916           0 :                 return X( aComplete );
     917             :         }
     918           2 :         else if ( nMaxLength == SFX_TITLE_FILENAME )
     919             :         {
     920           0 :             String aName( aURL.GetBase() );
     921           0 :             aName = INetURLObject::decode( aName, INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET );
     922           0 :             if( !aName.Len() )
     923           0 :                 aName = aURL.GetURLNoPass();
     924           0 :             return X(aName);
     925             :         }
     926           2 :         else if ( nMaxLength == SFX_TITLE_FULLNAME )
     927           0 :             return X(aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ));
     928             : 
     929             :         // Generate Title from file name if possible
     930           2 :         if ( !pImp->aTitle.Len() )
     931           0 :             pImp->aTitle = aURL.GetBase();
     932             : 
     933             :         // workaround for the case when the name can not be retrieved from URL by INetURLObject
     934           2 :         if ( !pImp->aTitle.Len() )
     935           0 :             pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     936             :     }
     937             : 
     938             :     // Complete Title
     939        1388 :     return X(pImp->aTitle);
     940             : }
     941             : 
     942             : //--------------------------------------------------------------------
     943             : 
     944           2 : void SfxObjectShell::InvalidateName()
     945             : 
     946             : /*  [Description]
     947             : 
     948             :     Returns the title of the new document, DocInfo-Title or
     949             :     File name. Is required for loading from template or SaveAs.
     950             : */
     951             : 
     952             : {
     953           2 :     pImp->aTitle.Erase();
     954           2 :     SetName( GetTitle( SFX_TITLE_APINAME ) );
     955             : 
     956           2 :     Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
     957           2 : }
     958             : 
     959             : //--------------------------------------------------------------------
     960             : 
     961         508 : void SfxObjectShell::SetNamedVisibility_Impl()
     962             : {
     963         508 :     if ( !pImp->bIsNamedVisible )
     964             :     {
     965         508 :         pImp->bIsNamedVisible = sal_True;
     966         508 :         if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && !pImp->aTitle.Len() )
     967             :         {
     968           7 :             pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex();
     969           7 :             Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
     970             :         }
     971             :     }
     972             : 
     973         508 :     SetName( GetTitle(SFX_TITLE_APINAME) );
     974         508 : }
     975             : 
     976           2 : void SfxObjectShell::SetNoName()
     977             : {
     978           2 :     bHasName = 0;
     979           2 :     bIsTmp = sal_True;
     980           2 :     GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() );
     981           2 : }
     982             : 
     983             : //--------------------------------------------------------------------
     984             : 
     985       10857 : SfxProgress* SfxObjectShell::GetProgress() const
     986             : {
     987       10857 :     return pImp->pProgress;
     988             : }
     989             : 
     990             : //--------------------------------------------------------------------
     991             : 
     992         372 : void SfxObjectShell::SetProgress_Impl
     993             : (
     994             :     SfxProgress *pProgress      /* to started <SfxProgress> or 0,
     995             :                                    if the progress is to be reset */
     996             : )
     997             : 
     998             : /*  [Description]
     999             : 
    1000             :     Internal method to set or reset the Progress modes for
    1001             :     SfxObjectShell.
    1002             : */
    1003             : 
    1004             : {
    1005             :     DBG_ASSERT( ( !pImp->pProgress && pProgress ) ||
    1006             :                 ( pImp->pProgress && !pProgress ),
    1007             :                 "Progress activation/deacitivation mismatch" );
    1008         372 :     pImp->pProgress = pProgress;
    1009         372 : }
    1010             : 
    1011             : //--------------------------------------------------------------------
    1012             : 
    1013        1219 : void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
    1014             : {
    1015        1219 :     SfxApplication* pSfxApp = SFX_APP();
    1016        1219 :     if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame().IsClosing_Impl() )
    1017             :     {
    1018         508 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
    1019         508 :         if ( !pHiddenItem || !pHiddenItem->GetValue() )
    1020             :         {
    1021         508 :             sal_uInt16 nId = pImp->nEventId;
    1022         508 :             pImp->nEventId = 0;
    1023         508 :             if ( nId == SFX_EVENT_OPENDOC )
    1024         501 :                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC), this, pFrame->GetFrame().GetController() ), sal_False);
    1025           7 :             else if (nId == SFX_EVENT_CREATEDOC )
    1026           7 :                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC), this, pFrame->GetFrame().GetController() ), sal_False);
    1027             :         }
    1028             :     }
    1029        1219 : }
    1030             : 
    1031             : //--------------------------------------------------------------------
    1032             : 
    1033        1044 : void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId )
    1034             : {
    1035        1044 :     if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC )
    1036        1044 :         pImp->nEventId = nId;
    1037        1044 : }
    1038             : 
    1039           0 : void SfxObjectShell::PrepareReload( )
    1040             : /*  [Description]
    1041             : 
    1042             :     Is called before the Reload and gives the opportunity to clear any caches.
    1043             : */
    1044             : {
    1045           0 : }
    1046             : 
    1047             : // Can be moved to frame.cxx, when 358+36x-State have been merged
    1048             : 
    1049           0 : sal_Bool SfxFrame::IsAutoLoadLocked_Impl() const
    1050             : {
    1051             :     // Its own Docucument is locked?
    1052           0 :     const SfxObjectShell* pObjSh = GetCurrentDocument();
    1053           0 :     if ( !pObjSh || !pObjSh->IsAutoLoadLocked() )
    1054           0 :         return sal_False;
    1055             : 
    1056             :     // Its children are locked?
    1057           0 :     for ( sal_uInt16 n = GetChildFrameCount(); n--; )
    1058           0 :         if ( !GetChildFrame(n)->IsAutoLoadLocked_Impl() )
    1059           0 :             return sal_False;
    1060             : 
    1061             :     // otherwise allow AutoLoad
    1062           0 :     return sal_True;
    1063             : }
    1064             : 
    1065             : //-------------------------------------------------------------------------
    1066             : 
    1067           0 : sal_Bool SfxObjectShell::IsAutoLoadLocked() const
    1068             : 
    1069             : /* Returns whether an Autoload is allowed to be executed. Before the
    1070             :    surrounding FrameSet of the AutoLoad is also taken into account as well.
    1071             : */
    1072             : 
    1073             : {
    1074           0 :     return !IsReadOnly() || pImp->nAutoLoadLocks > 0;
    1075             : }
    1076             : 
    1077             : //-------------------------------------------------------------------------
    1078           0 : void SfxObjectShell::BreakMacroSign_Impl( sal_Bool bBreakMacroSign )
    1079             : {
    1080           0 :     pImp->m_bMacroSignBroken = bBreakMacroSign;
    1081           0 : }
    1082             : 
    1083             : //-------------------------------------------------------------------------
    1084        1227 : void SfxObjectShell::CheckSecurityOnLoading_Impl()
    1085             : {
    1086        1227 :     uno::Reference< task::XInteractionHandler > xInteraction;
    1087        1227 :     if ( GetMedium() )
    1088        1227 :         xInteraction = GetMedium()->GetInteractionHandler();
    1089             : 
    1090             :     // check if there is a broken signature...
    1091        1227 :     CheckForBrokenDocSignatures_Impl( xInteraction );
    1092             : 
    1093        1227 :     CheckEncryption_Impl( xInteraction );
    1094             : 
    1095             :     // check macro security
    1096        1227 :     pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
    1097        1227 : }
    1098             : 
    1099             : //-------------------------------------------------------------------------
    1100        1235 : void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
    1101             : {
    1102        1235 :     ::rtl::OUString aVersion;
    1103        1235 :     sal_Bool bIsEncrypted = sal_False;
    1104        1235 :     sal_Bool bHasNonEncrypted = sal_False;
    1105             : 
    1106             :     try
    1107             :     {
    1108        1567 :         uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
    1109         903 :         xPropSet->getPropertyValue( ::rtl::OUString( "Version"  ) ) >>= aVersion;
    1110         903 :         xPropSet->getPropertyValue( ::rtl::OUString( "HasEncryptedEntries"  ) ) >>= bIsEncrypted;
    1111         903 :         xPropSet->getPropertyValue( ::rtl::OUString( "HasNonEncryptedEntries"  ) ) >>= bHasNonEncrypted;
    1112             :     }
    1113         332 :     catch( uno::Exception& )
    1114             :     {
    1115             :     }
    1116             : 
    1117        1235 :     if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
    1118             :     {
    1119             :         // this is ODF1.2 or later
    1120         901 :         if ( bIsEncrypted && bHasNonEncrypted )
    1121             :         {
    1122           0 :             if ( !pImp->m_bIncomplEncrWarnShown )
    1123             :             {
    1124             :                 // this is an encrypted document with nonencrypted streams inside, show the warning
    1125           0 :                 ::com::sun::star::task::ErrorCodeRequest aErrorCode;
    1126           0 :                 aErrorCode.ErrCode = ERRCODE_SFX_INCOMPLETE_ENCRYPTION;
    1127             : 
    1128           0 :                 SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
    1129           0 :                 pImp->m_bIncomplEncrWarnShown = sal_True;
    1130             :             }
    1131             : 
    1132             :             // broken signatures imply no macro execution at all
    1133           0 :             pImp->aMacroMode.disallowMacroExecution();
    1134             :         }
    1135        1235 :     }
    1136        1235 : }
    1137             : 
    1138             : //-------------------------------------------------------------------------
    1139        1235 : void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
    1140             : {
    1141        1235 :     sal_Int16 nSignatureState = GetDocumentSignatureState();
    1142        1235 :     bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN );
    1143        1235 :     if ( !bSignatureBroken )
    1144        2470 :         return;
    1145             : 
    1146           0 :     pImp->showBrokenSignatureWarning( xHandler );
    1147             : 
    1148             :     // broken signatures imply no macro execution at all
    1149           0 :     pImp->aMacroMode.disallowMacroExecution();
    1150             : }
    1151             : 
    1152             : //-------------------------------------------------------------------------
    1153        1043 : void SfxObjectShell::SetAutoLoad(
    1154             :     const INetURLObject& rUrl, sal_uInt32 nTime, sal_Bool bReload )
    1155             : {
    1156        1043 :     if ( pImp->pReloadTimer )
    1157           0 :         DELETEZ(pImp->pReloadTimer);
    1158        1043 :     if ( bReload )
    1159             :     {
    1160             :         pImp->pReloadTimer = new AutoReloadTimer_Impl(
    1161             :                                 rUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ),
    1162           0 :                                 nTime, this );
    1163           0 :         pImp->pReloadTimer->Start();
    1164             :     }
    1165        1043 : }
    1166             : 
    1167         516 : sal_Bool SfxObjectShell::IsLoadingFinished() const
    1168             : {
    1169         516 :     return ( pImp->nLoadedFlags == SFX_LOADED_ALL );
    1170             : }
    1171             : 
    1172             : void impl_addToModelCollection(const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel);
    1173         879 : void SfxObjectShell::InitOwnModel_Impl()
    1174             : {
    1175         879 :     if ( !pImp->bModelInitialized )
    1176             :     {
    1177         717 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
    1178         717 :         if ( pSalvageItem )
    1179             :         {
    1180           0 :             pImp->aTempName = pMedium->GetPhysicalName();
    1181           0 :             pMedium->GetItemSet()->ClearItem( SID_DOC_SALVAGE );
    1182           0 :             pMedium->GetItemSet()->ClearItem( SID_FILE_NAME );
    1183           0 :             pMedium->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetOrigURL() ) );
    1184             :         }
    1185             :         else
    1186             :         {
    1187         717 :             pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
    1188         717 :             pMedium->GetItemSet()->ClearItem( SID_DOCUMENT );
    1189             :         }
    1190             : 
    1191         717 :         pMedium->GetItemSet()->ClearItem( SID_REFERER );
    1192         717 :         uno::Reference< frame::XModel >  xModel ( GetModel(), uno::UNO_QUERY );
    1193         717 :         if ( xModel.is() )
    1194             :         {
    1195         717 :             ::rtl::OUString aURL = GetMedium()->GetOrigURL();
    1196         717 :             SfxItemSet *pSet = GetMedium()->GetItemSet();
    1197         717 :             if ( !GetMedium()->IsReadOnly() )
    1198         507 :                 pSet->ClearItem( SID_INPUTSTREAM );
    1199         717 :             uno::Sequence< beans::PropertyValue > aArgs;
    1200         717 :             TransformItems( SID_OPENDOC, *pSet, aArgs );
    1201         717 :             xModel->attachResource( aURL, aArgs );
    1202         717 :             impl_addToModelCollection(xModel);
    1203             :         }
    1204             : 
    1205         717 :         pImp->bModelInitialized = sal_True;
    1206             :     }
    1207         879 : }
    1208             : 
    1209         711 : void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags )
    1210             : {
    1211         711 :     sal_Bool bSetModifiedTRUE = sal_False;
    1212         711 :     SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
    1213        1422 :     if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
    1214         711 :         && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ))
    1215             :     {
    1216         711 :         pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT;
    1217         711 :         ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes();
    1218         711 :         pImp->bImportDone = sal_True;
    1219         711 :         if( !IsAbortingImport() )
    1220         711 :             PositionView_Impl();
    1221             : 
    1222         711 :         if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() )
    1223           2 :             SetReadOnly();
    1224             : 
    1225             :         // Salvage
    1226         711 :         if ( pSalvageItem )
    1227           0 :             bSetModifiedTRUE = sal_True;
    1228             : 
    1229         711 :         if ( !IsEnableSetModified() )
    1230         711 :             EnableSetModified( sal_True );
    1231             : 
    1232         711 :         if( !bSetModifiedTRUE && IsEnableSetModified() )
    1233         709 :             SetModified( sal_False );
    1234             : 
    1235         711 :         CheckSecurityOnLoading_Impl();
    1236             : 
    1237         711 :         bHasName = sal_True; // the document is loaded, so the name should already available
    1238         711 :         GetTitle( SFX_TITLE_DETECT );
    1239         711 :         InitOwnModel_Impl();
    1240         711 :         pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT;
    1241             :     }
    1242             : 
    1243        1420 :     if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES )
    1244         709 :         && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES ))
    1245             :     {
    1246         709 :         pImp->nFlagsInProgress |= SFX_LOADED_IMAGES;
    1247             :         uno::Reference<document::XDocumentProperties> xDocProps(
    1248         709 :             getDocProperties());
    1249         709 :         ::rtl::OUString url(xDocProps->getAutoloadURL());
    1250         709 :         sal_Int32 delay(xDocProps->getAutoloadSecs());
    1251             :         SetAutoLoad( INetURLObject(url), delay * 1000,
    1252         709 :                      (delay > 0) || !url.isEmpty() );
    1253         709 :         if( !bSetModifiedTRUE && IsEnableSetModified() )
    1254         709 :             SetModified( sal_False );
    1255         709 :         Invalidate( SID_SAVEASDOC );
    1256         709 :         pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES;
    1257             :     }
    1258             : 
    1259         711 :     pImp->nLoadedFlags |= nFlags;
    1260             : 
    1261         711 :     if ( !pImp->nFlagsInProgress )
    1262             :     {
    1263             :         // in case of reentrance calls the first called FinishedLoading() call on the stack
    1264             :         // should do the notification, in result the notification is done when all the FinishedLoading() calls are finished
    1265             : 
    1266         711 :         if ( bSetModifiedTRUE )
    1267           0 :             SetModified( sal_True );
    1268             :         else
    1269         711 :             SetModified( sal_False );
    1270             : 
    1271         711 :         if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) )
    1272             :         {
    1273         709 :             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
    1274         709 :             sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
    1275             : 
    1276             :             // closing the streams on loading should be under control of SFX!
    1277             :             DBG_ASSERT( pMedium->IsOpen(), "Don't close the medium when loading documents!" );
    1278             : 
    1279         709 :             if ( bTemplate )
    1280             :             {
    1281           2 :                 TemplateDisconnectionAfterLoad();
    1282             :             }
    1283             :             else
    1284             :             {
    1285             :                 // if a readonly medium has storage then it's stream is already based on temporary file
    1286         707 :                 if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() )
    1287             :                     // don't lock file opened read only
    1288         128 :                     pMedium->CloseInStream();
    1289             :             }
    1290             :         }
    1291             : 
    1292         711 :         SetInitialized_Impl( false );
    1293             : 
    1294             :         // Title is not available until loading has finished
    1295         711 :         Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );
    1296         711 :         if ( pImp->nEventId )
    1297         711 :             PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
    1298             :     }
    1299         711 : }
    1300             : 
    1301             : //-------------------------------------------------------------------------
    1302             : extern void SetTemplate_Impl( const String&, const String&, SfxObjectShell* );
    1303             : 
    1304           2 : void SfxObjectShell::TemplateDisconnectionAfterLoad()
    1305             : {
    1306             :     // document is created from a template
    1307             :     //TODO/LATER: should the templates always be XML docs!
    1308             : 
    1309           2 :     SfxMedium* pTmpMedium = pMedium;
    1310           2 :     if ( pTmpMedium )
    1311             :     {
    1312           2 :         String aName( pTmpMedium->GetName() );
    1313           2 :         SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
    1314           2 :         String aTemplateName;
    1315           2 :         if ( pTemplNamItem )
    1316           0 :             aTemplateName = pTemplNamItem->GetValue();
    1317             :         else
    1318             :         {
    1319             :             // !TODO/LATER: what's this?!
    1320             :             // Interactiv ( DClick, Contextmenu ) no long name is included
    1321           2 :             aTemplateName = getDocProperties()->getTitle();
    1322           2 :             if ( !aTemplateName.Len() )
    1323             :             {
    1324           0 :                 INetURLObject aURL( aName );
    1325           0 :                 aURL.CutExtension();
    1326           0 :                 aTemplateName = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
    1327             :             }
    1328             :         }
    1329             : 
    1330             :         // set medium to noname
    1331           2 :         pTmpMedium->SetName( String(), sal_True );
    1332           2 :         pTmpMedium->Init_Impl();
    1333             : 
    1334             :         // drop resource
    1335           2 :         SetNoName();
    1336           2 :         InvalidateName();
    1337             : 
    1338           2 :         if( IsPackageStorageFormat_Impl( *pTmpMedium ) )
    1339             :         {
    1340             :             // untitled document must be based on temporary storage
    1341             :             // the medium should not dispose the storage in this case
    1342           2 :             uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
    1343           2 :             GetStorage()->copyToStorage( xTmpStor );
    1344             : 
    1345             :             // the medium should disconnect from the original location
    1346             :             // the storage should not be disposed since the document is still
    1347             :             // based on it, but in DoSaveCompleted it will be disposed
    1348           2 :             pTmpMedium->CanDisposeStorage_Impl( sal_False );
    1349           2 :             pTmpMedium->Close();
    1350             : 
    1351             :             // setting the new storage the medium will be based on
    1352           2 :             pTmpMedium->SetStorage_Impl( xTmpStor );
    1353             : 
    1354           2 :             ForgetMedium();
    1355           2 :             if( !DoSaveCompleted( pTmpMedium ) )
    1356           0 :                 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( OSL_LOG_PREFIX  ) );
    1357             :             else
    1358             :             {
    1359           2 :                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
    1360           2 :                 sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
    1361             : 
    1362           2 :                 if ( !bSalvage )
    1363             :                 {
    1364             :                     // some further initializations for templates
    1365           2 :                     SetTemplate_Impl( aName, aTemplateName, this );
    1366             :                 }
    1367             : 
    1368             :                 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
    1369           2 :                 pTmpMedium->CanDisposeStorage_Impl( sal_False );
    1370           2 :             }
    1371             :         }
    1372             :         else
    1373             :         {
    1374             :             // some further initializations for templates
    1375           0 :             SetTemplate_Impl( aName, aTemplateName, this );
    1376           0 :             pTmpMedium->CreateTempFile( sal_True );
    1377             :         }
    1378             : 
    1379             :         // templates are never readonly
    1380           2 :         pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
    1381           2 :         pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True );
    1382             : 
    1383             :         // notifications about possible changes in readonly state and document info
    1384           2 :         Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
    1385             : 
    1386             :         // created untitled document can't be modified
    1387           2 :         SetModified( sal_False );
    1388             :     }
    1389           2 : }
    1390             : 
    1391             : //-------------------------------------------------------------------------
    1392             : 
    1393         711 : void SfxObjectShell::PositionView_Impl()
    1394             : {
    1395         711 :     MarkData_Impl *pMark = Get_Impl()->pMarkData;
    1396         711 :     if( pMark )
    1397             :     {
    1398           0 :         SfxViewShell* pSh = pMark->pFrame->GetViewShell();
    1399           0 :         if( pMark->aUserData.Len() )
    1400           0 :             pSh->ReadUserData( pMark->aUserData, sal_True );
    1401           0 :         else if( pMark->aMark.Len() )
    1402           0 :             pSh->JumpToMark( pMark->aMark );
    1403           0 :         DELETEZ( Get_Impl()->pMarkData );
    1404             :     }
    1405         711 : }
    1406             : 
    1407             : //-------------------------------------------------------------------------
    1408             : 
    1409       13758 : sal_Bool SfxObjectShell::IsLoading() const
    1410             : /*  [Description]
    1411             : 
    1412             :     Has FinishedLoading been called?
    1413             : */
    1414             : {
    1415       13758 :     return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT );
    1416             : }
    1417             : 
    1418             : //-------------------------------------------------------------------------
    1419             : 
    1420          98 : void SfxObjectShell::CancelTransfers()
    1421             : /*  [Description]
    1422             : 
    1423             :     Here can Transfers get canceled, which were not regestered
    1424             :     by RegisterTransfer.
    1425             : */
    1426             : {
    1427          98 :     if( ( pImp->nLoadedFlags & SFX_LOADED_ALL ) != SFX_LOADED_ALL )
    1428             :     {
    1429           0 :         AbortImport();
    1430           0 :         if( IsLoading() )
    1431           0 :             FinishedLoading( SFX_LOADED_ALL );
    1432             :     }
    1433          98 : }
    1434             : 
    1435             : //-------------------------------------------------------------------------
    1436             : 
    1437           0 : AutoReloadTimer_Impl::AutoReloadTimer_Impl(
    1438             :     const String& rURL, sal_uInt32 nTime, SfxObjectShell* pSh )
    1439           0 :     : aUrl( rURL ), pObjSh( pSh )
    1440             : {
    1441           0 :     SetTimeout( nTime );
    1442           0 : }
    1443             : 
    1444             : //-------------------------------------------------------------------------
    1445             : 
    1446           0 : void AutoReloadTimer_Impl::Timeout()
    1447             : {
    1448           0 :     SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjSh );
    1449             : 
    1450           0 :     if ( pFrame )
    1451             :     {
    1452             :         // Not possible/meanigfull at the moment?
    1453           0 :         if ( !pObjSh->CanReload_Impl() || pObjSh->IsAutoLoadLocked() || Application::IsUICaptured() )
    1454             :         {
    1455             :             // Allow a retry
    1456           0 :             Start();
    1457             :             return;
    1458             :         }
    1459             : 
    1460           0 :         SfxAllItemSet aSet( SFX_APP()->GetPool() );
    1461           0 :         aSet.Put( SfxBoolItem( SID_AUTOLOAD, sal_True ) );
    1462           0 :         if ( aUrl.Len() )
    1463           0 :             aSet.Put(  SfxStringItem( SID_FILE_NAME, aUrl ) );
    1464           0 :         SfxRequest aReq( SID_RELOAD, 0, aSet );
    1465           0 :         pObjSh->Get_Impl()->pReloadTimer = 0;
    1466           0 :         delete this;
    1467           0 :         pFrame->ExecReload_Impl( aReq );
    1468           0 :         return;
    1469             :     }
    1470             : 
    1471           0 :     pObjSh->Get_Impl()->pReloadTimer = 0;
    1472           0 :     delete this;
    1473             : }
    1474             : 
    1475       25997 : SfxModule* SfxObjectShell::GetModule() const
    1476             : {
    1477       25997 :     return GetFactory().GetModule();
    1478             : }
    1479             : 
    1480           0 : ErrCode SfxObjectShell::CallBasic( const String& rMacro,
    1481             :     const String& rBasic, SbxArray* pArgs,
    1482             :     SbxValue* pRet )
    1483             : {
    1484           0 :     SfxApplication* pApp = SFX_APP();
    1485           0 :     if( pApp->GetName() != rBasic )
    1486             :     {
    1487           0 :         if ( !AdjustMacroMode( String() ) )
    1488           0 :             return ERRCODE_IO_ACCESSDENIED;
    1489             :     }
    1490             : 
    1491           0 :     BasicManager *pMgr = GetBasicManager();
    1492           0 :     if( pApp->GetName() == rBasic )
    1493           0 :         pMgr = pApp->GetBasicManager();
    1494           0 :     ErrCode nRet = SfxApplication::CallBasic( rMacro, pMgr, pArgs, pRet );
    1495           0 :     return nRet;
    1496             : }
    1497             : 
    1498             : namespace
    1499             : {
    1500           8 :     static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext )
    1501             :     {
    1502             :         try
    1503             :         {
    1504           8 :             Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY );
    1505           8 :             if ( !xScripts.is() )
    1506             :             {
    1507           0 :                 Reference< XScriptInvocationContext > xContext( _rxScriptContext, UNO_QUERY_THROW );
    1508           0 :                 xScripts.set( xContext->getScriptContainer(), UNO_SET_THROW );
    1509             :             }
    1510             : 
    1511           8 :             return xScripts->getAllowMacroExecution();
    1512             :         }
    1513           0 :         catch( const Exception& )
    1514             :         {
    1515             :             DBG_UNHANDLED_EXCEPTION();
    1516             :         }
    1517           0 :         return false;
    1518             :     }
    1519             : }
    1520             : 
    1521           8 : ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL,
    1522             :     const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError, const ::com::sun::star::uno::Any* pCaller )
    1523             : {
    1524             :     OSL_TRACE( "in CallXScript" );
    1525           8 :     ErrCode nErr = ERRCODE_NONE;
    1526             : 
    1527           8 :     bool bIsDocumentScript = ( _rScriptURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "location=document" ) ) >= 0 );
    1528             :         // TODO: we should parse the URL, and check whether there is a parameter with this name.
    1529             :         // Otherwise, we might find too much.
    1530           8 :     if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
    1531           0 :         return ERRCODE_IO_ACCESSDENIED;
    1532             : 
    1533           8 :     bool bCaughtException = false;
    1534           8 :     Any aException;
    1535             :     try
    1536             :     {
    1537             :         // obtain/create a script provider
    1538           8 :         Reference< provider::XScriptProvider > xScriptProvider;
    1539           8 :         Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );
    1540           8 :         if ( xSPS.is() )
    1541           8 :             xScriptProvider.set( xSPS->getScriptProvider() );
    1542             : 
    1543           8 :         if ( !xScriptProvider.is() )
    1544             :         {
    1545           0 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
    1546             :             Reference< provider::XScriptProviderFactory > xScriptProviderFactory(
    1547           0 :                 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
    1548           0 :             xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW );
    1549             :         }
    1550             : 
    1551             :         // ry to protect the invocation context's undo manager (if present), just in case the script tampers with it
    1552           8 :         ::framework::DocumentUndoGuard aUndoGuard( _rxScriptContext.get() );
    1553             : 
    1554             :         // obtain the script, and execute it
    1555           8 :         Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW );
    1556           6 :         if ( pCaller && pCaller->hasValue() )
    1557             :         {
    1558           0 :             Reference< beans::XPropertySet > xProps( xScript, uno::UNO_QUERY );
    1559           0 :             if ( xProps.is() )
    1560             :             {
    1561           0 :                 Sequence< uno::Any > aArgs( 1 );
    1562           0 :                 aArgs[ 0 ] = *pCaller;
    1563           0 :                 xProps->setPropertyValue( rtl::OUString("Caller"), uno::makeAny( aArgs ) );
    1564           0 :             }
    1565             :         }
    1566           6 :         aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam );
    1567             :     }
    1568           2 :     catch ( const uno::Exception& )
    1569             :     {
    1570           2 :         aException = ::cppu::getCaughtException();
    1571           2 :         bCaughtException = sal_True;
    1572           2 :         nErr = ERRCODE_BASIC_INTERNAL_ERROR;
    1573             :     }
    1574             : 
    1575           8 :     if ( bCaughtException && bRaiseError )
    1576             :     {
    1577           2 :         ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg;
    1578           2 :         SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
    1579           2 :         if ( pFact )
    1580           2 :             pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) );
    1581             :         OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" );
    1582             : 
    1583           2 :         if ( pScriptErrDlg.get() )
    1584           2 :             pScriptErrDlg->Execute();
    1585             :     }
    1586             : 
    1587             :     OSL_TRACE( "leaving CallXScript" );
    1588           8 :     return nErr;
    1589             : }
    1590             : 
    1591             : // perhaps rename to CallScript once we get rid of the existing CallScript
    1592             : // and Call, CallBasic, CallStarBasic methods
    1593           0 : ErrCode SfxObjectShell::CallXScript( const String& rScriptURL,
    1594             :         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
    1595             :             aParams,
    1596             :         ::com::sun::star::uno::Any& aRet,
    1597             :         ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
    1598             :         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
    1599             :             aOutParam, bool bRaiseError, const ::com::sun::star::uno::Any* pCaller )
    1600             : {
    1601           0 :     return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError, pCaller );
    1602             : }
    1603             : 
    1604             : //-------------------------------------------------------------------------
    1605           0 : SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
    1606             : {
    1607           0 :     return pSelf;
    1608             : }
    1609             : 
    1610           0 : SfxObjectShellFlags SfxObjectShell::GetFlags() const
    1611             : {
    1612           0 :     if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED )
    1613           0 :         pImp->eFlags = GetFactory().GetFlags();
    1614           0 :     return pImp->eFlags;
    1615             : }
    1616             : 
    1617         711 : void SfxHeaderAttributes_Impl::SetAttributes()
    1618             : {
    1619         711 :     bAlert = sal_True;
    1620         711 :     SvKeyValue aPair;
    1621        1422 :     for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont;
    1622         711 :          bCont = xIter->GetNext( aPair ) )
    1623        1422 :         SetAttribute( aPair );
    1624         711 : }
    1625             : 
    1626         711 : void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV )
    1627             : {
    1628         711 :     String aValue = rKV.GetValue();
    1629         711 :     if( rKV.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL && rKV.GetValue().Len() )
    1630             :     {
    1631           0 :         sal_uInt32 nTime = aValue.GetToken(  0, ';' ).ToInt32() ;
    1632           0 :         String aURL = comphelper::string::strip(aValue.GetToken( 1, ';' ), ' ');
    1633             :         uno::Reference<document::XDocumentProperties> xDocProps(
    1634           0 :             pDoc->getDocProperties());
    1635           0 :         if( aURL.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL )
    1636             :         {
    1637           0 :             INetURLObject aObj;
    1638           0 :             INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.Copy( 4 ), &aObj );
    1639           0 :             xDocProps->setAutoloadURL(
    1640           0 :                 aObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1641             :         }
    1642             :         try
    1643             :         {
    1644           0 :             xDocProps->setAutoloadSecs( nTime );
    1645             :         }
    1646           0 :         catch (lang::IllegalArgumentException &)
    1647             :         {
    1648             :             // ignore
    1649           0 :         }
    1650             :     }
    1651         711 :     else if( rKV.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL )
    1652             :     {
    1653           0 :         DateTime aDateTime( DateTime::EMPTY );
    1654           0 :         if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) )
    1655             :         {
    1656           0 :             aDateTime.ConvertToLocalTime();
    1657           0 :             pDoc->GetMedium()->SetExpired_Impl( aDateTime );
    1658             :         }
    1659             :         else
    1660             :         {
    1661           0 :             pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) );
    1662             :         }
    1663         711 :     }
    1664         711 : }
    1665             : 
    1666           0 : void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV )
    1667             : {
    1668           0 :     xIter->Append( rKV );
    1669           0 :     if( bAlert ) SetAttribute( rKV );
    1670           0 : }
    1671             : 
    1672         713 : SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes()
    1673             : {
    1674         713 :     if( !pImp->xHeaderAttributes.Is() )
    1675             :     {
    1676             :         DBG_ASSERT( pMedium, "No Medium" );
    1677         711 :         pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this );
    1678             :     }
    1679         713 :     return ( SvKeyValueIterator*) &pImp->xHeaderAttributes;
    1680             : }
    1681             : 
    1682           0 : void SfxObjectShell::ClearHeaderAttributesForSourceViewHack()
    1683             : {
    1684           0 :     ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
    1685           0 :         ->ClearForSourceView();
    1686           0 : }
    1687             : 
    1688             : 
    1689           0 : void SfxObjectShell::SetHeaderAttributesForSourceViewHack()
    1690             : {
    1691           0 :     ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
    1692           0 :         ->SetAttributes();
    1693           0 : }
    1694             : 
    1695       16518 : sal_Bool SfxObjectShell::IsPreview() const
    1696             : {
    1697       16518 :     if ( !pMedium )
    1698         126 :         return sal_False;
    1699             : 
    1700       16392 :     sal_Bool bPreview = sal_False;
    1701       16392 :     SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False);
    1702       16392 :     if ( pFlags )
    1703             :     {
    1704             :         // Distributed values among individual items
    1705           0 :         String aFileFlags = pFlags->GetValue();
    1706           0 :         aFileFlags.ToUpperAscii();
    1707           0 :         if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) )
    1708           0 :             bPreview = sal_True;
    1709             :     }
    1710             : 
    1711       16392 :     if ( !bPreview )
    1712             :     {
    1713       16392 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False);
    1714       16392 :         if ( pItem )
    1715           0 :             bPreview = pItem->GetValue();
    1716             :     }
    1717             : 
    1718       16392 :     return bPreview;
    1719             : }
    1720             : 
    1721          52 : void SfxObjectShell::SetWaitCursor( sal_Bool bSet ) const
    1722             : {
    1723          52 :     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
    1724             :     {
    1725           0 :         if ( bSet )
    1726           0 :             pFrame->GetFrame().GetWindow().EnterWait();
    1727             :         else
    1728           0 :             pFrame->GetFrame().GetWindow().LeaveWait();
    1729             :     }
    1730          52 : }
    1731             : 
    1732         510 : String SfxObjectShell::GetAPIName() const
    1733             : {
    1734         510 :     INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
    1735         510 :     String aName( aURL.GetBase() );
    1736         510 :     if( !aName.Len() )
    1737           9 :         aName = aURL.GetURLNoPass();
    1738         510 :     if ( !aName.Len() )
    1739           9 :         aName = GetTitle( SFX_TITLE_DETECT );
    1740         510 :     return aName;
    1741             : }
    1742             : 
    1743        4433 : void SfxObjectShell::Invalidate( sal_uInt16 nId )
    1744             : {
    1745        4497 :     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
    1746          64 :         Invalidate_Impl( pFrame->GetBindings(), nId );
    1747        4433 : }
    1748             : 
    1749           8 : bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI )
    1750             : {
    1751           8 :     uno::Reference< task::XInteractionHandler > xInteraction;
    1752           8 :     if ( pMedium && !bSuppressUI )
    1753           8 :         xInteraction = pMedium->GetInteractionHandler();
    1754             : 
    1755           8 :     CheckForBrokenDocSignatures_Impl( xInteraction );
    1756             : 
    1757           8 :     CheckEncryption_Impl( xInteraction );
    1758             : 
    1759           8 :     return pImp->aMacroMode.adjustMacroMode( xInteraction );
    1760             : }
    1761             : 
    1762           6 : Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium )
    1763             : {
    1764           6 :     Window* pWindow = 0;
    1765           6 :     SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet();
    1766           6 :     SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
    1767           6 :     if ( pUnoItem )
    1768             :     {
    1769           0 :         uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() );
    1770           0 :         pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
    1771             :     }
    1772             : 
    1773           6 :     if ( !pWindow )
    1774             :     {
    1775           6 :         SfxFrame* pFrame = 0;
    1776           6 :         SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False );
    1777           6 :         if( pFrameItem && pFrameItem->GetFrame() )
    1778             :             // get target frame from ItemSet
    1779           0 :             pFrame = pFrameItem->GetFrame();
    1780             :         else
    1781             :         {
    1782             :             // try the current frame
    1783           6 :             SfxViewFrame* pView = SfxViewFrame::Current();
    1784           6 :             if ( !pView || pView->GetObjectShell() != this )
    1785             :                 // get any visible frame
    1786           6 :                 pView = SfxViewFrame::GetFirst(this);
    1787           6 :             if ( pView )
    1788           0 :                 pFrame = &pView->GetFrame();
    1789             :         }
    1790             : 
    1791           6 :         if ( pFrame )
    1792             :             // get topmost window
    1793           0 :             pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() );
    1794             :     }
    1795             : 
    1796           6 :     if ( pWindow )
    1797             :     {
    1798             :         // this frame may be invisible, show it if it is allowed
    1799           0 :         SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
    1800           0 :         if ( !pHiddenItem || !pHiddenItem->GetValue() )
    1801             :         {
    1802           0 :             pWindow->Show();
    1803           0 :             pWindow->ToTop();
    1804             :         }
    1805             :     }
    1806             : 
    1807           6 :     return pWindow;
    1808             : }
    1809             : 
    1810         284 : void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode )
    1811             : {
    1812         284 :     eCreateMode = nMode;
    1813         284 : }
    1814             : 
    1815        8602 : sal_Bool SfxObjectShell::IsInPlaceActive()
    1816             : {
    1817        8602 :     if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
    1818        7434 :         return sal_False;
    1819             : 
    1820        1168 :     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
    1821        1168 :     return pFrame && pFrame->GetFrame().IsInPlace();
    1822             : }
    1823             : 
    1824           0 : sal_Bool SfxObjectShell::IsUIActive()
    1825             : {
    1826           0 :     if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
    1827           0 :         return sal_False;
    1828             : 
    1829           0 :     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
    1830           0 :     return pFrame && pFrame->GetFrame().IsInPlace() && pFrame->GetFrame().GetWorkWindow_Impl()->IsVisible_Impl();
    1831             : }
    1832             : 
    1833           0 : void SfxObjectShell::UIActivate( sal_Bool )
    1834             : {
    1835           0 : }
    1836             : 
    1837           0 : void SfxObjectShell::InPlaceActivate( sal_Bool )
    1838             : {
    1839           0 : }
    1840             : 
    1841          32 : sal_Bool SfxObjectShell::UseInteractionToHandleError(
    1842             :                     const uno::Reference< task::XInteractionHandler >& xHandler,
    1843             :                     sal_uInt32 nError )
    1844             : {
    1845          32 :     sal_Bool bResult = sal_False;
    1846             : 
    1847          32 :     if ( xHandler.is() )
    1848             :     {
    1849             :         try
    1850             :         {
    1851          32 :             uno::Any aInteraction;
    1852          32 :             uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2);
    1853          32 :             ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort();
    1854          32 :             ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
    1855          32 :             lContinuations[0] = uno::Reference< task::XInteractionContinuation >(
    1856          64 :                                  static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY );
    1857          32 :             lContinuations[1] = uno::Reference< task::XInteractionContinuation >(
    1858          64 :                                  static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY );
    1859             : 
    1860          32 :             task::ErrorCodeRequest aErrorCode;
    1861          32 :             aErrorCode.ErrCode = nError;
    1862          32 :             aInteraction <<= aErrorCode;
    1863          32 :             xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations));
    1864          32 :             bResult = pAbort->wasSelected();
    1865             :         }
    1866           0 :         catch( uno::Exception& )
    1867             :         {}
    1868             :     }
    1869             : 
    1870          32 :     return bResult;
    1871             : }
    1872             : 
    1873        1235 : sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const
    1874             : {
    1875        1235 :     sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE );
    1876             : 
    1877        1235 :     const SfxMedium* pMedium( rDocShell.GetMedium() );
    1878             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
    1879        1235 :     if ( pMedium )
    1880             :     {
    1881        1235 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False);
    1882        1235 :         if ( pMacroModeItem )
    1883        1027 :             nImposedExecMode = pMacroModeItem->GetValue();
    1884             :     }
    1885        1235 :     return nImposedExecMode;
    1886             : }
    1887             : 
    1888        1325 : sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
    1889             : {
    1890        1325 :     const SfxMedium* pMedium( rDocShell.GetMedium() );
    1891             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
    1892        1325 :     if ( pMedium )
    1893             :     {
    1894        1325 :         pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) );
    1895        1325 :         return sal_True;
    1896             :     }
    1897             : 
    1898           0 :     return sal_False;
    1899             : }
    1900             : 
    1901           0 : ::rtl::OUString SfxObjectShell_Impl::getDocumentLocation() const
    1902             : {
    1903           0 :     ::rtl::OUString sLocation;
    1904             : 
    1905           0 :     const SfxMedium* pMedium( rDocShell.GetMedium() );
    1906             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" );
    1907           0 :     if ( pMedium )
    1908             :     {
    1909           0 :         sLocation = pMedium->GetName();
    1910           0 :         if ( sLocation.isEmpty() )
    1911             :         {
    1912             :             // for documents made from a template: get the name of the template
    1913           0 :             sLocation = rDocShell.getDocProperties()->getTemplateURL();
    1914             :         }
    1915             :     }
    1916           0 :     return sLocation;
    1917             : }
    1918             : 
    1919           0 : uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign()
    1920             : {
    1921           0 :     Reference < embed::XStorage > xStore;
    1922             : 
    1923           0 :     SfxMedium* pMedium( rDocShell.GetMedium() );
    1924             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" );
    1925           0 :     if ( pMedium )
    1926           0 :         xStore = pMedium->GetZipStorageToSign_Impl();
    1927             : 
    1928           0 :     return xStore;
    1929             : }
    1930             : 
    1931        1227 : sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const
    1932             : {
    1933        1227 :     return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage );
    1934             : }
    1935             : 
    1936        1217 : Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const
    1937             : {
    1938        1217 :     return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY );
    1939             : }
    1940             : 
    1941           0 : sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState()
    1942             : {
    1943           0 :     sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() );
    1944             : 
    1945           0 :     if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken )
    1946             :     {
    1947             :         // if there is a macro signature it must be handled as broken
    1948           0 :         nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN;
    1949             :     }
    1950             : 
    1951           0 :     return nSignatureState;
    1952             : }
    1953             : 
    1954           0 : sal_Bool SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor )
    1955             : {
    1956           0 :     sal_Bool bResult = sal_False;
    1957             : 
    1958             :     try
    1959             :     {
    1960           0 :         ::rtl::OUString aVersion;
    1961             :         try
    1962             :         {
    1963           0 :             uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW );
    1964           0 :             xPropSet->getPropertyValue( ::rtl::OUString( "Version"  ) ) >>= aVersion;
    1965             :         }
    1966           0 :         catch( uno::Exception& )
    1967             :         {
    1968             :         }
    1969             : 
    1970           0 :         uno::Reference< security::XDocumentDigitalSignatures > xSigner( security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), aVersion) );
    1971             : 
    1972           0 :         if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN
    1973             :           || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
    1974             :           || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
    1975             :         {
    1976           0 :             uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( sal_True, xSigner );
    1977             : 
    1978           0 :             if ( aInfo.getLength() )
    1979             :             {
    1980           0 :                 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN )
    1981           0 :                     nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo );
    1982             : 
    1983           0 :                 if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
    1984             :                   || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
    1985             :                 {
    1986           0 :                     for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ )
    1987             :                     {
    1988           0 :                         bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer );
    1989             :                     }
    1990             : 
    1991           0 :                     if ( !bResult && bAllowUIToAddAuthor )
    1992             :                     {
    1993           0 :                         uno::Reference< task::XInteractionHandler > xInteraction;
    1994           0 :                         if ( rDocShell.GetMedium() )
    1995           0 :                             xInteraction = rDocShell.GetMedium()->GetInteractionHandler();
    1996             : 
    1997           0 :                         if ( xInteraction.is() )
    1998             :                         {
    1999           0 :                             task::DocumentMacroConfirmationRequest aRequest;
    2000           0 :                             aRequest.DocumentURL = getDocumentLocation();
    2001           0 :                             aRequest.DocumentStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl();
    2002           0 :                             aRequest.DocumentSignatureInformation = aInfo;
    2003           0 :                             aRequest.DocumentVersion = aVersion;
    2004           0 :                             aRequest.Classification = task::InteractionClassification_QUERY;
    2005           0 :                             bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), sal_True );
    2006           0 :                         }
    2007             :                     }
    2008             :                 }
    2009           0 :             }
    2010           0 :         }
    2011             :     }
    2012           0 :     catch( uno::Exception& )
    2013             :     {}
    2014             : 
    2015           0 :     return bResult;
    2016             : }
    2017             : 
    2018           0 : void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const
    2019             : {
    2020           0 :     if  ( !bSignatureErrorIsShown )
    2021             :     {
    2022           0 :         SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE );
    2023           0 :         const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = sal_True;
    2024             :     }
    2025           0 : }
    2026             : 
    2027        2222 : void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage )
    2028             : {
    2029        2222 :     if ( !pImp->m_xLogRing.is() )
    2030             :     {
    2031             :         try
    2032             :         {
    2033         434 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
    2034         434 :             if ( aContext.is() )
    2035         434 :                 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
    2036             :         }
    2037           0 :         catch( uno::Exception& )
    2038             :         {}
    2039             :     }
    2040             : 
    2041        2222 :     if ( pImp->m_xLogRing.is() )
    2042        2222 :         pImp->m_xLogRing->logString( aMessage );
    2043        2222 : }
    2044             : 
    2045             : namespace {
    2046             : 
    2047           0 : void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const ::rtl::OUString& aString )
    2048             : {
    2049           0 :     if ( xOutStream.is() )
    2050             :     {
    2051           0 :         ::rtl::OString aStrLog = ::rtl::OUStringToOString( aString, RTL_TEXTENCODING_UTF8 );
    2052           0 :         uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() );
    2053           0 :         xOutStream->writeBytes( aLogData );
    2054             : 
    2055           0 :         aLogData.realloc( 1 );
    2056           0 :         aLogData[0] = '\n';
    2057           0 :         xOutStream->writeBytes( aLogData );
    2058             :     }
    2059           0 : }
    2060             : 
    2061             : }
    2062             : 
    2063           0 : void SfxObjectShell::StoreLog()
    2064             : {
    2065           0 :     if ( !pImp->m_xLogRing.is() )
    2066             :     {
    2067             :         try
    2068             :         {
    2069           0 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
    2070           0 :             if ( aContext.is() )
    2071           0 :                 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
    2072             :         }
    2073           0 :         catch( uno::Exception& )
    2074             :         {}
    2075             :     }
    2076             : 
    2077           0 :     if ( pImp->m_xLogRing.is() )
    2078             :     {
    2079             : #ifdef WNT
    2080             :         ::rtl::OUString aFileURL = ::rtl::OUString( "${$BRAND_BASE_DIR/program/bootstrap.ini:UserInstallation}"  );
    2081             : #else
    2082           0 :         ::rtl::OUString aFileURL = ::rtl::OUString( "${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}"  );
    2083             : #endif
    2084             : 
    2085           0 :         ::rtl::Bootstrap::expandMacros( aFileURL );
    2086             : 
    2087             : #ifdef WNT
    2088             :         ::rtl::OUString aBuildID = ::rtl::OUString( "${$BRAND_BASE_DIR/program/setup.ini:buildid}"  );
    2089             : #else
    2090           0 :         ::rtl::OUString aBuildID = ::rtl::OUString( "${$BRAND_BASE_DIR/program/setuprc:buildid}"  );
    2091             : #endif
    2092             : 
    2093           0 :         ::rtl::Bootstrap::expandMacros( aBuildID );
    2094             : 
    2095           0 :         if ( !aFileURL.isEmpty() )
    2096             :         {
    2097           0 :             aFileURL += ::rtl::OUString( "/user/temp/document_io_logring.txt"  );
    2098             :             try
    2099             :             {
    2100           0 :                 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
    2101           0 :                 uno::Reference< ucb::XSimpleFileAccess3 > xSimpleFileAccess(ucb::SimpleFileAccess::create(xContext));
    2102           0 :                 uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW );
    2103           0 :                 uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW );
    2104           0 :                 uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW );
    2105           0 :                 xTruncate->truncate();
    2106             : 
    2107           0 :                 if ( !aBuildID.isEmpty() )
    2108           0 :                     WriteStringInStream( xOutStream, aBuildID );
    2109             : 
    2110           0 :                 uno::Sequence< ::rtl::OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog();
    2111           0 :                 for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ )
    2112           0 :                     WriteStringInStream( xOutStream, aLogSeq[nInd] );
    2113             :             }
    2114           0 :             catch( uno::Exception& )
    2115             :             {}
    2116           0 :         }
    2117             :     }
    2118         234 : }
    2119             : 
    2120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10