LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/doc - objmisc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 490 872 56.2 %
Date: 2012-12-27 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         318 : class SfxHeaderAttributes_Impl : public SvKeyValueIterator
     139             : {
     140             : private:
     141             :     SfxObjectShell* pDoc;
     142             :     SvKeyValueIteratorRef xIter;
     143             :     sal_Bool bAlert;
     144             : 
     145             : public:
     146         340 :     SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) :
     147             :         SvKeyValueIterator(), pDoc( pSh ),
     148             :         xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ),
     149         340 :         bAlert( sal_False ) {}
     150             : 
     151           1 :     virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); }
     152           1 :     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         576 : sal_Bool SfxObjectShell::IsAbortingImport() const
     180             : {
     181         576 :     return pImp->bIsAbortingImport;
     182             : }
     183             : 
     184             : //-------------------------------------------------------------------------
     185             : 
     186             : uno::Reference<document::XDocumentProperties>
     187         872 : SfxObjectShell::getDocProperties()
     188             : {
     189             :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     190         872 :         GetModel(), uno::UNO_QUERY_THROW);
     191             :     uno::Reference<document::XDocumentProperties> xDocProps(
     192         872 :         xDPS->getDocumentProperties());
     193             :     DBG_ASSERT(xDocProps.is(),
     194             :         "SfxObjectShell: model has no DocumentProperties");
     195         872 :     return xDocProps;
     196             : }
     197             : 
     198             : //-------------------------------------------------------------------------
     199             : 
     200         147 : void SfxObjectShell::DoFlushDocInfo()
     201             : {
     202         147 : }
     203             : 
     204             : //-------------------------------------------------------------------------
     205             : 
     206             : // Note: the only thing that calls this is the modification event handler
     207             : // that is installed at the XDocumentProperties
     208        1748 : void SfxObjectShell::FlushDocInfo()
     209             : {
     210        1748 :     if ( IsLoading() )
     211        1748 :         return;
     212             : 
     213         154 :     SetModified(sal_True);
     214         154 :     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     215         154 :     DoFlushDocInfo(); // call template method
     216         154 :     ::rtl::OUString url(xDocProps->getAutoloadURL());
     217         154 :     sal_Int32 delay(xDocProps->getAutoloadSecs());
     218             :     SetAutoLoad( INetURLObject(url), delay * 1000,
     219         154 :                  (delay > 0) || !url.isEmpty() );
     220             : }
     221             : 
     222             : //-------------------------------------------------------------------------
     223             : 
     224         693 : void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage )
     225             : {
     226         693 :     if(pImp->lErr==ERRCODE_NONE)
     227             :     {
     228         404 :         pImp->lErr=lErr;
     229             : 
     230         404 :         if( lErr != ERRCODE_NONE && !aLogMessage.isEmpty() )
     231         312 :             AddLog( aLogMessage );
     232             :     }
     233         693 : }
     234             : 
     235             : //-------------------------------------------------------------------------
     236             : 
     237        1143 : sal_uInt32 SfxObjectShell::GetError() const
     238             : {
     239        1143 :     return ERRCODE_TOERROR(GetErrorCode());
     240             : }
     241             : 
     242             : //-------------------------------------------------------------------------
     243             : 
     244        1854 : sal_uInt32 SfxObjectShell::GetErrorCode() const
     245             : {
     246        1854 :     sal_uInt32 lError=pImp->lErr;
     247        1854 :     if(!lError && GetMedium())
     248        1534 :         lError=GetMedium()->GetErrorCode();
     249        1854 :     return lError;
     250             : }
     251             : 
     252             : //-------------------------------------------------------------------------
     253             : 
     254         720 : void SfxObjectShell::ResetError()
     255             : {
     256         720 :     if( pImp->lErr != ERRCODE_NONE )
     257         304 :         AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Resetting Error."  ) );
     258             : 
     259         720 :     pImp->lErr=0;
     260         720 :     SfxMedium * pMed = GetMedium();
     261         720 :     if( pMed )
     262         720 :         pMed->ResetError();
     263         720 : }
     264             : 
     265             : //-------------------------------------------------------------------------
     266             : 
     267        2055 : sal_Bool SfxObjectShell::IsTemplate() const
     268             : {
     269        2055 :     return pImp->bIsTemplate;
     270             : }
     271             : 
     272             : //-------------------------------------------------------------------------
     273             : 
     274        5623 : 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        5623 :     pImp->m_bEnableSetModified = bEnable;
     281        5623 : }
     282             : 
     283             : //-------------------------------------------------------------------------
     284             : 
     285       55118 : sal_Bool SfxObjectShell::IsEnableSetModified() const
     286             : {
     287       55118 :     return pImp->m_bEnableSetModified && !IsReadOnly();
     288             : }
     289             : 
     290             : //-------------------------------------------------------------------------
     291             : 
     292        7324 : sal_Bool SfxObjectShell::IsModified()
     293             : {
     294        7324 :     if ( pImp->m_bIsModified )
     295        3694 :         return sal_True;
     296             : 
     297        3630 :     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         267 :         return sal_False;
     303             :     }
     304             : 
     305        3363 :     uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
     306        4248 :     for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
     307             :     {
     308         894 :         uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
     309             :         OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
     310         894 :         if ( xObj.is() )
     311             :         {
     312             :             try
     313             :             {
     314         894 :                 sal_Int32 nState = xObj->getCurrentState();
     315         894 :                 if ( nState != embed::EmbedStates::LOADED )
     316             :                 {
     317         867 :                     uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
     318         867 :                     if ( xModifiable.is() && xModifiable->isModified() )
     319           9 :                         return sal_True;
     320             :                 }
     321             :             }
     322           0 :             catch( uno::Exception& )
     323             :             {}
     324             :         }
     325         894 :     }
     326             : 
     327        3354 :     return sal_False;
     328             : }
     329             : 
     330             : //-------------------------------------------------------------------------
     331             : 
     332        5436 : 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        5436 :     if( !IsEnableSetModified() )
     340        5464 :         return;
     341             : 
     342        5408 :     if( pImp->m_bIsModified != bModifiedP )
     343             :     {
     344         925 :         pImp->m_bIsModified = bModifiedP;
     345         925 :         ModifyChanged();
     346             :     }
     347             : }
     348             : 
     349             : //-------------------------------------------------------------------------
     350             : 
     351         925 : void SfxObjectShell::ModifyChanged()
     352             : {
     353         925 :     if ( pImp->bClosing )
     354             :         // SetModified dispose of the models!
     355         925 :         return;
     356             : 
     357             :     {DBG_CHKTHIS(SfxObjectShell, 0);}
     358             : 
     359         925 :     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
     360         925 :     if ( pViewFrame )
     361         442 :         pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS );
     362             : 
     363         925 :     Invalidate( SID_SIGNATURE );
     364         925 :     Invalidate( SID_MACRO_SIGNATURE );
     365         925 :     Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );    // xmlsec05, signed state might change in title...
     366             : 
     367         925 :     SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) );
     368             : }
     369             : 
     370             : //-------------------------------------------------------------------------
     371             : 
     372        3079 : 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        3079 :     return pImp->bReadOnlyUI;
     382             : }
     383             : 
     384             : //-------------------------------------------------------------------------
     385             : 
     386         337 : 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         337 :     if ( !pMedium )
     395           0 :         return sal_True;
     396         337 :     return pMedium->IsReadOnly();
     397             : }
     398             : 
     399           0 : bool SfxObjectShell::IsOriginallyReadOnlyMedium() const
     400             : {
     401           0 :     return pMedium == 0 || pMedium->IsOriginallyReadOnly();
     402             : }
     403             : 
     404             : //-------------------------------------------------------------------------
     405             : 
     406          98 : 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          98 :     if ( bReadOnly != pImp->bReadOnlyUI )
     416             :     {
     417          98 :         pImp->bReadOnlyUI = bReadOnly;
     418          98 :         Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
     419             :     }
     420          98 : }
     421             : 
     422             : //-------------------------------------------------------------------------
     423             : 
     424           1 : 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           1 :      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           1 : }
     448             : //-------------------------------------------------------------------------
     449             : 
     450       29716 : sal_Bool SfxObjectShell::IsReadOnly() const
     451             : {
     452       29716 :     return pImp->bReadOnlyUI || pMedium == 0;
     453             : }
     454             : 
     455             : //-------------------------------------------------------------------------
     456             : 
     457         211 : sal_Bool SfxObjectShell::IsInModalMode() const
     458             : {
     459         211 :     return pImp->bModalMode || pImp->bRunningMacro;
     460             : }
     461             : 
     462         211 : sal_Bool SfxObjectShell::AcceptStateUpdate() const
     463             : {
     464         211 :     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          22 : void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const
     659             : {
     660          22 :     pImp->m_bSharedXMLFlag = bFlag;
     661          22 : }
     662             : 
     663             : //--------------------------------------------------------------------
     664          67 : sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const
     665             : {
     666          67 :     return pImp->m_bSharedXMLFlag;
     667             : }
     668             : 
     669             : //--------------------------------------------------------------------
     670             : 
     671        3975 : sal_Bool SfxObjectShell::IsDocShared() const
     672             : {
     673        3975 :     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           3 : Size SfxObjectShell::GetFirstPageSize()
     686             : {
     687           3 :     return GetVisArea(ASPECT_THUMBNAIL).GetSize();
     688             : }
     689             : 
     690             : 
     691             : //--------------------------------------------------------------------
     692             : 
     693         299 : IndexBitSet& SfxObjectShell::GetNoSet_Impl()
     694             : {
     695         299 :     return pImp->aBitSet;
     696             : }
     697             : 
     698             : //--------------------------------------------------------------------
     699             : // changes the title of the document
     700             : 
     701         154 : 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         924 :     if ( ( ( HasName() && pImp->aTitle == rTitle )
     719         616 :         || ( !HasName() && GetTitle() == rTitle ) )
     720         154 :       && !IsDocShared() )
     721         308 :         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        2701 : 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        2701 :     SfxMedium *pMed = GetMedium();
     811        2701 :     if ( IsLoading() )
     812         409 :         return String();
     813             : 
     814             :     // Create Title?
     815        2292 :     if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() )
     816             :     {
     817             :         static sal_Bool bRecur = sal_False;
     818         163 :         if ( bRecur )
     819           0 :             return DEFINE_CONST_UNICODE( "-not available-" );
     820         163 :         bRecur = sal_True;
     821             : 
     822         163 :         String aTitle;
     823         163 :         SfxObjectShell *pThis = (SfxObjectShell*) this;
     824             : 
     825         163 :         if ( pMed )
     826             :         {
     827         163 :             SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
     828         163 :             if ( pNameItem )
     829           0 :                 aTitle = pNameItem->GetValue();
     830             :         }
     831             : 
     832         163 :         if ( !aTitle.Len() )
     833         163 :             aTitle = GetTitle( SFX_TITLE_FILENAME );
     834             : 
     835         163 :         if ( IsTemplate() )
     836           0 :             pThis->SetTitle( aTitle );
     837         163 :         bRecur = sal_False;
     838         163 :         return X(aTitle);
     839             :     }
     840        2129 :     else if (SFX_TITLE_APINAME == nMaxLength )
     841         237 :         return X(GetAPIName());
     842             : 
     843             :     // Special case templates:
     844        1892 :     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        1892 :     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         241 :         SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
     855         241 :         if ( pNameItem )
     856           0 :             return X( pNameItem->GetValue() );
     857             :     }
     858             : 
     859             :     // Still unnamed?
     860             :     DBG_ASSERT( !HasName() || pMed, "HasName() but no Medium?!?" );
     861        1892 :     if ( !HasName() || !pMed )
     862             :     {
     863             :         // Title already set?
     864        1233 :         if ( pImp->aTitle.Len() )
     865           0 :             return X(pImp->aTitle);
     866             : 
     867             :         // must it be numbered?
     868        1233 :         rtl::OUString aNoName(SFX2_RESSTR(STR_NONAME));
     869        1233 :         if (pImp->bIsNamedVisible)
     870             :         {
     871             :             // Append number
     872           3 :             aNoName += rtl::OUString::valueOf(static_cast<sal_Int32>(pImp->nVisualDocumentNumber));
     873             :         }
     874             : 
     875             :         // Document called "noname" for the time being
     876        1233 :         return X(aNoName);
     877             :     }
     878             : 
     879         659 :     const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
     880         659 :     if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
     881             :     {
     882             :         sal_uInt16 nRemote;
     883         241 :         if( !pMed || aURL.GetProtocol() == INET_PROT_FILE )
     884         241 :             nRemote = 0;
     885             :         else
     886           0 :             nRemote = 1;
     887         241 :         nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote];
     888             :     }
     889             : 
     890             :     // Local file?
     891         659 :     if ( aURL.GetProtocol() == INET_PROT_FILE )
     892             :     {
     893         658 :         String aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() );
     894         658 :         if ( nMaxLength == SFX_TITLE_FULLNAME )
     895           0 :             return X( aName );
     896         658 :         else if ( nMaxLength == SFX_TITLE_FILENAME )
     897           0 :             return X( aURL.getName( INetURLObject::LAST_SEGMENT,
     898             :                 true, INetURLObject::DECODE_WITH_CHARSET ) );
     899         658 :         else if ( !pImp->aTitle.Len() )
     900             :             pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT,
     901         340 :                                          true, INetURLObject::DECODE_WITH_CHARSET );
     902             :     }
     903             :     else
     904             :     {
     905             :         // ::com::sun::star::util::URL-Versions
     906           1 :         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           1 :         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           1 :         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           1 :         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           1 :         if ( !pImp->aTitle.Len() )
     935           0 :             pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     936             :     }
     937             : 
     938             :     // Complete Title
     939         659 :     return X(pImp->aTitle);
     940             : }
     941             : 
     942             : //--------------------------------------------------------------------
     943             : 
     944           1 : 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           1 :     pImp->aTitle.Erase();
     954           1 :     SetName( GetTitle( SFX_TITLE_APINAME ) );
     955             : 
     956           1 :     Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
     957           1 : }
     958             : 
     959             : //--------------------------------------------------------------------
     960             : 
     961         236 : void SfxObjectShell::SetNamedVisibility_Impl()
     962             : {
     963         236 :     if ( !pImp->bIsNamedVisible )
     964             :     {
     965         236 :         pImp->bIsNamedVisible = sal_True;
     966         236 :         if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && !pImp->aTitle.Len() )
     967             :         {
     968           1 :             pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex();
     969           1 :             Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
     970             :         }
     971             :     }
     972             : 
     973         236 :     SetName( GetTitle(SFX_TITLE_APINAME) );
     974         236 : }
     975             : 
     976           1 : void SfxObjectShell::SetNoName()
     977             : {
     978           1 :     bHasName = 0;
     979           1 :     bIsTmp = sal_True;
     980           1 :     GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() );
     981           1 : }
     982             : 
     983             : //--------------------------------------------------------------------
     984             : 
     985        1404 : SfxProgress* SfxObjectShell::GetProgress() const
     986             : {
     987        1404 :     return pImp->pProgress;
     988             : }
     989             : 
     990             : //--------------------------------------------------------------------
     991             : 
     992         132 : 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         132 :     pImp->pProgress = pProgress;
    1009         132 : }
    1010             : 
    1011             : //--------------------------------------------------------------------
    1012             : 
    1013         576 : void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
    1014             : {
    1015         576 :     SfxApplication* pSfxApp = SFX_APP();
    1016         576 :     if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame().IsClosing_Impl() )
    1017             :     {
    1018         236 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
    1019         236 :         if ( !pHiddenItem || !pHiddenItem->GetValue() )
    1020             :         {
    1021         236 :             sal_uInt16 nId = pImp->nEventId;
    1022         236 :             pImp->nEventId = 0;
    1023         236 :             if ( nId == SFX_EVENT_OPENDOC )
    1024         235 :                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC), this, pFrame->GetFrame().GetController() ), sal_False);
    1025           1 :             else if (nId == SFX_EVENT_CREATEDOC )
    1026           1 :                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC), this, pFrame->GetFrame().GetController() ), sal_False);
    1027             :         }
    1028             :     }
    1029         576 : }
    1030             : 
    1031             : //--------------------------------------------------------------------
    1032             : 
    1033         505 : void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId )
    1034             : {
    1035         505 :     if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC )
    1036         505 :         pImp->nEventId = nId;
    1037         505 : }
    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         580 : void SfxObjectShell::CheckSecurityOnLoading_Impl()
    1085             : {
    1086         580 :     uno::Reference< task::XInteractionHandler > xInteraction;
    1087         580 :     if ( GetMedium() )
    1088         580 :         xInteraction = GetMedium()->GetInteractionHandler();
    1089             : 
    1090             :     // check if there is a broken signature...
    1091         580 :     CheckForBrokenDocSignatures_Impl( xInteraction );
    1092             : 
    1093         580 :     CheckEncryption_Impl( xInteraction );
    1094             : 
    1095             :     // check macro security
    1096         580 :     pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
    1097         580 : }
    1098             : 
    1099             : //-------------------------------------------------------------------------
    1100         581 : void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
    1101             : {
    1102         581 :     ::rtl::OUString aVersion;
    1103         581 :     sal_Bool bIsEncrypted = sal_False;
    1104         581 :     sal_Bool bHasNonEncrypted = sal_False;
    1105             : 
    1106             :     try
    1107             :     {
    1108         621 :         uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
    1109         541 :         xPropSet->getPropertyValue( ::rtl::OUString( "Version"  ) ) >>= aVersion;
    1110         541 :         xPropSet->getPropertyValue( ::rtl::OUString( "HasEncryptedEntries"  ) ) >>= bIsEncrypted;
    1111         541 :         xPropSet->getPropertyValue( ::rtl::OUString( "HasNonEncryptedEntries"  ) ) >>= bHasNonEncrypted;
    1112             :     }
    1113          40 :     catch( uno::Exception& )
    1114             :     {
    1115             :     }
    1116             : 
    1117         581 :     if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
    1118             :     {
    1119             :         // this is ODF1.2 or later
    1120         541 :         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         581 :     }
    1136         581 : }
    1137             : 
    1138             : //-------------------------------------------------------------------------
    1139         581 : void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
    1140             : {
    1141         581 :     sal_Int16 nSignatureState = GetDocumentSignatureState();
    1142         581 :     bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN );
    1143         581 :     if ( !bSignatureBroken )
    1144        1162 :         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         494 : void SfxObjectShell::SetAutoLoad(
    1154             :     const INetURLObject& rUrl, sal_uInt32 nTime, sal_Bool bReload )
    1155             : {
    1156         494 :     if ( pImp->pReloadTimer )
    1157           0 :         DELETEZ(pImp->pReloadTimer);
    1158         494 :     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         494 : }
    1166             : 
    1167         240 : sal_Bool SfxObjectShell::IsLoadingFinished() const
    1168             : {
    1169         240 :     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         416 : void SfxObjectShell::InitOwnModel_Impl()
    1174             : {
    1175         416 :     if ( !pImp->bModelInitialized )
    1176             :     {
    1177         343 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
    1178         343 :         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         343 :             pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
    1188         343 :             pMedium->GetItemSet()->ClearItem( SID_DOCUMENT );
    1189             :         }
    1190             : 
    1191         343 :         pMedium->GetItemSet()->ClearItem( SID_REFERER );
    1192         343 :         uno::Reference< frame::XModel >  xModel ( GetModel(), uno::UNO_QUERY );
    1193         343 :         if ( xModel.is() )
    1194             :         {
    1195         343 :             ::rtl::OUString aURL = GetMedium()->GetOrigURL();
    1196         343 :             SfxItemSet *pSet = GetMedium()->GetItemSet();
    1197         343 :             if ( !GetMedium()->IsReadOnly() )
    1198         238 :                 pSet->ClearItem( SID_INPUTSTREAM );
    1199         343 :             uno::Sequence< beans::PropertyValue > aArgs;
    1200         343 :             TransformItems( SID_OPENDOC, *pSet, aArgs );
    1201         343 :             xModel->attachResource( aURL, aArgs );
    1202         343 :             impl_addToModelCollection(xModel);
    1203             :         }
    1204             : 
    1205         343 :         pImp->bModelInitialized = sal_True;
    1206             :     }
    1207         416 : }
    1208             : 
    1209         340 : void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags )
    1210             : {
    1211         340 :     sal_Bool bSetModifiedTRUE = sal_False;
    1212         340 :     SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
    1213         680 :     if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
    1214         340 :         && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ))
    1215             :     {
    1216         340 :         pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT;
    1217         340 :         ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes();
    1218         340 :         pImp->bImportDone = sal_True;
    1219         340 :         if( !IsAbortingImport() )
    1220         340 :             PositionView_Impl();
    1221             : 
    1222         340 :         if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() )
    1223           1 :             SetReadOnly();
    1224             : 
    1225             :         // Salvage
    1226         340 :         if ( pSalvageItem )
    1227           0 :             bSetModifiedTRUE = sal_True;
    1228             : 
    1229         340 :         if ( !IsEnableSetModified() )
    1230         340 :             EnableSetModified( sal_True );
    1231             : 
    1232         340 :         if( !bSetModifiedTRUE && IsEnableSetModified() )
    1233         339 :             SetModified( sal_False );
    1234             : 
    1235         340 :         CheckSecurityOnLoading_Impl();
    1236             : 
    1237         340 :         bHasName = sal_True; // the document is loaded, so the name should already available
    1238         340 :         GetTitle( SFX_TITLE_DETECT );
    1239         340 :         InitOwnModel_Impl();
    1240         340 :         pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT;
    1241             :     }
    1242             : 
    1243         679 :     if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES )
    1244         339 :         && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES ))
    1245             :     {
    1246         339 :         pImp->nFlagsInProgress |= SFX_LOADED_IMAGES;
    1247             :         uno::Reference<document::XDocumentProperties> xDocProps(
    1248         339 :             getDocProperties());
    1249         339 :         ::rtl::OUString url(xDocProps->getAutoloadURL());
    1250         339 :         sal_Int32 delay(xDocProps->getAutoloadSecs());
    1251             :         SetAutoLoad( INetURLObject(url), delay * 1000,
    1252         339 :                      (delay > 0) || !url.isEmpty() );
    1253         339 :         if( !bSetModifiedTRUE && IsEnableSetModified() )
    1254         339 :             SetModified( sal_False );
    1255         339 :         Invalidate( SID_SAVEASDOC );
    1256         339 :         pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES;
    1257             :     }
    1258             : 
    1259         340 :     pImp->nLoadedFlags |= nFlags;
    1260             : 
    1261         340 :     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         340 :         if ( bSetModifiedTRUE )
    1267           0 :             SetModified( sal_True );
    1268             :         else
    1269         340 :             SetModified( sal_False );
    1270             : 
    1271         340 :         if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) )
    1272             :         {
    1273         339 :             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
    1274         339 :             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         339 :             if ( bTemplate )
    1280             :             {
    1281           1 :                 TemplateDisconnectionAfterLoad();
    1282             :             }
    1283             :             else
    1284             :             {
    1285             :                 // if a readonly medium has storage then it's stream is already based on temporary file
    1286         338 :                 if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() )
    1287             :                     // don't lock file opened read only
    1288          64 :                     pMedium->CloseInStream();
    1289             :             }
    1290             :         }
    1291             : 
    1292         340 :         SetInitialized_Impl( false );
    1293             : 
    1294             :         // Title is not available until loading has finished
    1295         340 :         Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );
    1296         340 :         if ( pImp->nEventId )
    1297         340 :             PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
    1298             :     }
    1299         340 : }
    1300             : 
    1301             : //-------------------------------------------------------------------------
    1302             : extern void SetTemplate_Impl( const String&, const String&, SfxObjectShell* );
    1303             : 
    1304           1 : void SfxObjectShell::TemplateDisconnectionAfterLoad()
    1305             : {
    1306             :     // document is created from a template
    1307             :     //TODO/LATER: should the templates always be XML docs!
    1308             : 
    1309           1 :     SfxMedium* pTmpMedium = pMedium;
    1310           1 :     if ( pTmpMedium )
    1311             :     {
    1312           1 :         String aName( pTmpMedium->GetName() );
    1313           1 :         SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
    1314           1 :         String aTemplateName;
    1315           1 :         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           1 :             aTemplateName = getDocProperties()->getTitle();
    1322           1 :             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           1 :         pTmpMedium->SetName( String(), sal_True );
    1332           1 :         pTmpMedium->Init_Impl();
    1333             : 
    1334             :         // drop resource
    1335           1 :         SetNoName();
    1336           1 :         InvalidateName();
    1337             : 
    1338           1 :         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           1 :             uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
    1343           1 :             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           1 :             pTmpMedium->CanDisposeStorage_Impl( sal_False );
    1349           1 :             pTmpMedium->Close();
    1350             : 
    1351             :             // setting the new storage the medium will be based on
    1352           1 :             pTmpMedium->SetStorage_Impl( xTmpStor );
    1353             : 
    1354           1 :             ForgetMedium();
    1355           1 :             if( !DoSaveCompleted( pTmpMedium ) )
    1356           0 :                 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( OSL_LOG_PREFIX  ) );
    1357             :             else
    1358             :             {
    1359           1 :                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
    1360           1 :                 sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
    1361             : 
    1362           1 :                 if ( !bSalvage )
    1363             :                 {
    1364             :                     // some further initializations for templates
    1365           1 :                     SetTemplate_Impl( aName, aTemplateName, this );
    1366             :                 }
    1367             : 
    1368             :                 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
    1369           1 :                 pTmpMedium->CanDisposeStorage_Impl( sal_False );
    1370           1 :             }
    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           1 :         pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
    1381           1 :         pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True );
    1382             : 
    1383             :         // notifications about possible changes in readonly state and document info
    1384           1 :         Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
    1385             : 
    1386             :         // created untitled document can't be modified
    1387           1 :         SetModified( sal_False );
    1388             :     }
    1389           1 : }
    1390             : 
    1391             : //-------------------------------------------------------------------------
    1392             : 
    1393         340 : void SfxObjectShell::PositionView_Impl()
    1394             : {
    1395         340 :     MarkData_Impl *pMark = Get_Impl()->pMarkData;
    1396         340 :     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         340 : }
    1406             : 
    1407             : //-------------------------------------------------------------------------
    1408             : 
    1409        6377 : sal_Bool SfxObjectShell::IsLoading() const
    1410             : /*  [Description]
    1411             : 
    1412             :     Has FinishedLoading been called?
    1413             : */
    1414             : {
    1415        6377 :     return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT );
    1416             : }
    1417             : 
    1418             : //-------------------------------------------------------------------------
    1419             : 
    1420          63 : void SfxObjectShell::CancelTransfers()
    1421             : /*  [Description]
    1422             : 
    1423             :     Here can Transfers get canceled, which were not regestered
    1424             :     by RegisterTransfer.
    1425             : */
    1426             : {
    1427          63 :     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          63 : }
    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       10709 : SfxModule* SfxObjectShell::GetModule() const
    1476             : {
    1477       10709 :     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           1 :     static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext )
    1501             :     {
    1502             :         try
    1503             :         {
    1504           1 :             Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY );
    1505           1 :             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           1 :             return xScripts->getAllowMacroExecution();
    1512             :         }
    1513           0 :         catch( const Exception& )
    1514             :         {
    1515             :             DBG_UNHANDLED_EXCEPTION();
    1516             :         }
    1517           0 :         return false;
    1518             :     }
    1519             : }
    1520             : 
    1521           1 : 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           1 :     ErrCode nErr = ERRCODE_NONE;
    1526             : 
    1527           1 :     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           1 :     if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
    1531           0 :         return ERRCODE_IO_ACCESSDENIED;
    1532             : 
    1533           1 :     bool bCaughtException = false;
    1534           1 :     Any aException;
    1535             :     try
    1536             :     {
    1537             :         // obtain/create a script provider
    1538           1 :         Reference< provider::XScriptProvider > xScriptProvider;
    1539           1 :         Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );
    1540           1 :         if ( xSPS.is() )
    1541           1 :             xScriptProvider.set( xSPS->getScriptProvider() );
    1542             : 
    1543           1 :         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           1 :         ::framework::DocumentUndoGuard aUndoGuard( _rxScriptContext.get() );
    1553             : 
    1554             :         // obtain the script, and execute it
    1555           1 :         Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW );
    1556           0 :         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           0 :         aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam );
    1567             :     }
    1568           1 :     catch ( const uno::Exception& )
    1569             :     {
    1570           1 :         aException = ::cppu::getCaughtException();
    1571           1 :         bCaughtException = sal_True;
    1572           1 :         nErr = ERRCODE_BASIC_INTERNAL_ERROR;
    1573             :     }
    1574             : 
    1575           1 :     if ( bCaughtException && bRaiseError )
    1576             :     {
    1577           1 :         ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg;
    1578           1 :         SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
    1579           1 :         if ( pFact )
    1580           1 :             pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) );
    1581             :         OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" );
    1582             : 
    1583           1 :         if ( pScriptErrDlg.get() )
    1584           1 :             pScriptErrDlg->Execute();
    1585             :     }
    1586             : 
    1587             :     OSL_TRACE( "leaving CallXScript" );
    1588           1 :     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         340 : void SfxHeaderAttributes_Impl::SetAttributes()
    1618             : {
    1619         340 :     bAlert = sal_True;
    1620         340 :     SvKeyValue aPair;
    1621         680 :     for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont;
    1622         340 :          bCont = xIter->GetNext( aPair ) )
    1623         680 :         SetAttribute( aPair );
    1624         340 : }
    1625             : 
    1626         340 : void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV )
    1627             : {
    1628         340 :     String aValue = rKV.GetValue();
    1629         340 :     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         340 :     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         340 :     }
    1664         340 : }
    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         341 : SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes()
    1673             : {
    1674         341 :     if( !pImp->xHeaderAttributes.Is() )
    1675             :     {
    1676             :         DBG_ASSERT( pMedium, "No Medium" );
    1677         340 :         pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this );
    1678             :     }
    1679         341 :     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        7505 : sal_Bool SfxObjectShell::IsPreview() const
    1696             : {
    1697        7505 :     if ( !pMedium )
    1698          63 :         return sal_False;
    1699             : 
    1700        7442 :     sal_Bool bPreview = sal_False;
    1701        7442 :     SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False);
    1702        7442 :     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        7442 :     if ( !bPreview )
    1712             :     {
    1713        7442 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False);
    1714        7442 :         if ( pItem )
    1715           0 :             bPreview = pItem->GetValue();
    1716             :     }
    1717             : 
    1718        7442 :     return bPreview;
    1719             : }
    1720             : 
    1721          26 : void SfxObjectShell::SetWaitCursor( sal_Bool bSet ) const
    1722             : {
    1723          26 :     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          26 : }
    1731             : 
    1732         237 : String SfxObjectShell::GetAPIName() const
    1733             : {
    1734         237 :     INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
    1735         237 :     String aName( aURL.GetBase() );
    1736         237 :     if( !aName.Len() )
    1737           2 :         aName = aURL.GetURLNoPass();
    1738         237 :     if ( !aName.Len() )
    1739           2 :         aName = GetTitle( SFX_TITLE_DETECT );
    1740         237 :     return aName;
    1741             : }
    1742             : 
    1743        2189 : void SfxObjectShell::Invalidate( sal_uInt16 nId )
    1744             : {
    1745        2193 :     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
    1746           4 :         Invalidate_Impl( pFrame->GetBindings(), nId );
    1747        2189 : }
    1748             : 
    1749           1 : bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI )
    1750             : {
    1751           1 :     uno::Reference< task::XInteractionHandler > xInteraction;
    1752           1 :     if ( pMedium && !bSuppressUI )
    1753           1 :         xInteraction = pMedium->GetInteractionHandler();
    1754             : 
    1755           1 :     CheckForBrokenDocSignatures_Impl( xInteraction );
    1756             : 
    1757           1 :     CheckEncryption_Impl( xInteraction );
    1758             : 
    1759           1 :     return pImp->aMacroMode.adjustMacroMode( xInteraction );
    1760             : }
    1761             : 
    1762           3 : Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium )
    1763             : {
    1764           3 :     Window* pWindow = 0;
    1765           3 :     SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet();
    1766           3 :     SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
    1767           3 :     if ( pUnoItem )
    1768             :     {
    1769           0 :         uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() );
    1770           0 :         pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
    1771             :     }
    1772             : 
    1773           3 :     if ( !pWindow )
    1774             :     {
    1775           3 :         SfxFrame* pFrame = 0;
    1776           3 :         SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False );
    1777           3 :         if( pFrameItem && pFrameItem->GetFrame() )
    1778             :             // get target frame from ItemSet
    1779           0 :             pFrame = pFrameItem->GetFrame();
    1780             :         else
    1781             :         {
    1782             :             // try the current frame
    1783           3 :             SfxViewFrame* pView = SfxViewFrame::Current();
    1784           3 :             if ( !pView || pView->GetObjectShell() != this )
    1785             :                 // get any visible frame
    1786           3 :                 pView = SfxViewFrame::GetFirst(this);
    1787           3 :             if ( pView )
    1788           0 :                 pFrame = &pView->GetFrame();
    1789             :         }
    1790             : 
    1791           3 :         if ( pFrame )
    1792             :             // get topmost window
    1793           0 :             pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() );
    1794             :     }
    1795             : 
    1796           3 :     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           3 :     return pWindow;
    1808             : }
    1809             : 
    1810         143 : void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode )
    1811             : {
    1812         143 :     eCreateMode = nMode;
    1813         143 : }
    1814             : 
    1815        3562 : sal_Bool SfxObjectShell::IsInPlaceActive()
    1816             : {
    1817        3562 :     if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
    1818        2974 :         return sal_False;
    1819             : 
    1820         588 :     SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
    1821         588 :     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          16 : sal_Bool SfxObjectShell::UseInteractionToHandleError(
    1842             :                     const uno::Reference< task::XInteractionHandler >& xHandler,
    1843             :                     sal_uInt32 nError )
    1844             : {
    1845          16 :     sal_Bool bResult = sal_False;
    1846             : 
    1847          16 :     if ( xHandler.is() )
    1848             :     {
    1849             :         try
    1850             :         {
    1851          16 :             uno::Any aInteraction;
    1852          16 :             uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2);
    1853          16 :             ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort();
    1854          16 :             ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
    1855          16 :             lContinuations[0] = uno::Reference< task::XInteractionContinuation >(
    1856          32 :                                  static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY );
    1857          16 :             lContinuations[1] = uno::Reference< task::XInteractionContinuation >(
    1858          32 :                                  static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY );
    1859             : 
    1860          16 :             task::ErrorCodeRequest aErrorCode;
    1861          16 :             aErrorCode.ErrCode = nError;
    1862          16 :             aInteraction <<= aErrorCode;
    1863          16 :             xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations));
    1864          16 :             bResult = pAbort->wasSelected();
    1865             :         }
    1866           0 :         catch( uno::Exception& )
    1867             :         {}
    1868             :     }
    1869             : 
    1870          16 :     return bResult;
    1871             : }
    1872             : 
    1873         581 : sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const
    1874             : {
    1875         581 :     sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE );
    1876             : 
    1877         581 :     const SfxMedium* pMedium( rDocShell.GetMedium() );
    1878             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
    1879         581 :     if ( pMedium )
    1880             :     {
    1881         581 :         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False);
    1882         581 :         if ( pMacroModeItem )
    1883         477 :             nImposedExecMode = pMacroModeItem->GetValue();
    1884             :     }
    1885         581 :     return nImposedExecMode;
    1886             : }
    1887             : 
    1888         637 : sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
    1889             : {
    1890         637 :     const SfxMedium* pMedium( rDocShell.GetMedium() );
    1891             :     OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
    1892         637 :     if ( pMedium )
    1893             :     {
    1894         637 :         pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) );
    1895         637 :         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         580 : sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const
    1932             : {
    1933         580 :     return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage );
    1934             : }
    1935             : 
    1936         580 : Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const
    1937             : {
    1938         580 :     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        1091 : void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage )
    2028             : {
    2029        1091 :     if ( !pImp->m_xLogRing.is() )
    2030             :     {
    2031             :         try
    2032             :         {
    2033         216 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
    2034         216 :             if ( aContext.is() )
    2035         216 :                 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
    2036             :         }
    2037           0 :         catch( uno::Exception& )
    2038             :         {}
    2039             :     }
    2040             : 
    2041        1091 :     if ( pImp->m_xLogRing.is() )
    2042        1091 :         pImp->m_xLogRing->logString( aMessage );
    2043        1091 : }
    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          66 : }
    2119             : 
    2120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10