1d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5d119d52dSAndrew Rist * distributed with this work for additional information 6d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14d119d52dSAndrew Rist * software distributed under the License is distributed on an 15d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17d119d52dSAndrew Rist * specific language governing permissions and limitations 18d119d52dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20d119d52dSAndrew Rist *************************************************************/ 21d119d52dSAndrew Rist 22d119d52dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _INETMSG_HXX //autogen 28cdf0e10cSrcweir #include <svl/inetmsg.hxx> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir #include <tools/diagnose_ex.h> 31cdf0e10cSrcweir #include <svl/eitem.hxx> 32cdf0e10cSrcweir #include <svl/stritem.hxx> 33cdf0e10cSrcweir #include <svl/intitem.hxx> 34cdf0e10cSrcweir #include <svtools/svparser.hxx> // SvKeyValue 35cdf0e10cSrcweir #include <vos/mutex.hxx> 36cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 39cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp> 40cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp> 41cdf0e10cSrcweir #include <com/sun/star/script/XTypeConverter.hpp> 42cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProviderFactory.hpp> 43cdf0e10cSrcweir #include <com/sun/star/script/FinishEngineEvent.hpp> 44cdf0e10cSrcweir #include <com/sun/star/script/InterruptReason.hpp> 45cdf0e10cSrcweir #include <com/sun/star/script/XEngineListener.hpp> 46cdf0e10cSrcweir #include <com/sun/star/script/XDebugging.hpp> 47cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SCRIPT_XINVOKATION_HPP_ 48cdf0e10cSrcweir #include <com/sun/star/script/XInvocation.hpp> 49cdf0e10cSrcweir #endif 50cdf0e10cSrcweir #include <com/sun/star/script/ContextInformation.hpp> 51cdf0e10cSrcweir #include <com/sun/star/script/FinishReason.hpp> 52cdf0e10cSrcweir #include <com/sun/star/script/XEngine.hpp> 53cdf0e10cSrcweir #include <com/sun/star/script/InterruptEngineEvent.hpp> 54cdf0e10cSrcweir #include <com/sun/star/script/XLibraryAccess.hpp> 55cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp> 56cdf0e10cSrcweir #include <com/sun/star/document/XScriptInvocationContext.hpp> 57cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 58cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedPersist.hpp> 59cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 60cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 61cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 62cdf0e10cSrcweir 63cdf0e10cSrcweir 64cdf0e10cSrcweir #include <com/sun/star/script/provider/XScript.hpp> 65cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProvider.hpp> 66cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp> 67cdf0e10cSrcweir 68cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 69b63233d8Sdamjan #include <toolkit/helper/vclunohelper.hxx> 70cdf0e10cSrcweir #endif 71cdf0e10cSrcweir 72cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 73cdf0e10cSrcweir #include <com/sun/star/uno/Any.h> 74cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 75cdf0e10cSrcweir #include <com/sun/star/task/ErrorCodeRequest.hpp> 76cdf0e10cSrcweir #include <unotools/securityoptions.hxx> 77cdf0e10cSrcweir 7815daf392SDamjan Jovanovic #include "com/sun/star/uri/XUriReferenceFactory.hpp" 7915daf392SDamjan Jovanovic #include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp> 8015daf392SDamjan Jovanovic 81cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 82cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 83cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 84cdf0e10cSrcweir 85cdf0e10cSrcweir #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> 86cdf0e10cSrcweir #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp> 87cdf0e10cSrcweir #include <com/sun/star/task/InteractionClassification.hpp> 88cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 89cdf0e10cSrcweir 90cdf0e10cSrcweir using namespace ::com::sun::star; 91cdf0e10cSrcweir using namespace ::com::sun::star::uno; 92cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 93cdf0e10cSrcweir using namespace ::com::sun::star::document; 94cdf0e10cSrcweir using namespace ::com::sun::star::frame; 95cdf0e10cSrcweir using namespace ::com::sun::star::script; 96cdf0e10cSrcweir using namespace ::com::sun::star::script::provider; 97cdf0e10cSrcweir using namespace ::com::sun::star::container; 98cdf0e10cSrcweir #include <basic/sbuno.hxx> 99cdf0e10cSrcweir #include <basic/sbstar.hxx> 100cdf0e10cSrcweir #ifndef _SB_BASMGR_HXX 101cdf0e10cSrcweir #include <basic/basmgr.hxx> 102cdf0e10cSrcweir #endif 103cdf0e10cSrcweir #ifndef _VCL_MSGBOX_HXX 104cdf0e10cSrcweir #include <vcl/msgbox.hxx> 105cdf0e10cSrcweir #endif 106cdf0e10cSrcweir #include <basic/sbx.hxx> 107cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 108cdf0e10cSrcweir #include <svtools/ehdl.hxx> 109cdf0e10cSrcweir 110cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 111cdf0e10cSrcweir #include <unotools/ucbhelper.hxx> 112cdf0e10cSrcweir #include <tools/inetmime.hxx> 113cdf0e10cSrcweir #include <tools/urlobj.hxx> 114cdf0e10cSrcweir #include <svl/inettype.hxx> 115cdf0e10cSrcweir #include <svl/sharecontrolfile.hxx> 116cdf0e10cSrcweir #include <osl/file.hxx> 117cdf0e10cSrcweir #include <rtl/bootstrap.hxx> 118cdf0e10cSrcweir #include <vcl/svapp.hxx> 119cdf0e10cSrcweir #include <framework/interaction.hxx> 120cdf0e10cSrcweir #include <framework/documentundoguard.hxx> 121cdf0e10cSrcweir #include <comphelper/interaction.hxx> 122cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 123cdf0e10cSrcweir #include <comphelper/documentconstants.hxx> 124cdf0e10cSrcweir 125cdf0e10cSrcweir #include <sfx2/signaturestate.hxx> 126cdf0e10cSrcweir #include <sfx2/app.hxx> 127cdf0e10cSrcweir #include "appdata.hxx" 128cdf0e10cSrcweir #include <sfx2/request.hxx> 129cdf0e10cSrcweir #include <sfx2/bindings.hxx> 130cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 131cdf0e10cSrcweir #include <sfx2/docfile.hxx> 132cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 133cdf0e10cSrcweir #include <sfx2/objsh.hxx> 134cdf0e10cSrcweir #include "objshimp.hxx" 135cdf0e10cSrcweir #include <sfx2/event.hxx> 136cdf0e10cSrcweir #include "fltfnc.hxx" 137cdf0e10cSrcweir #include <sfx2/sfx.hrc> 138cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 139cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 140cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 141cdf0e10cSrcweir #include <sfx2/ctrlitem.hxx> 142cdf0e10cSrcweir #include "arrdecl.hxx" 143cdf0e10cSrcweir #include <sfx2/module.hxx> 144cdf0e10cSrcweir #include <sfx2/docfac.hxx> 145cdf0e10cSrcweir #include "helper.hxx" 146cdf0e10cSrcweir #include "doc.hrc" 147cdf0e10cSrcweir #include "workwin.hxx" 148cdf0e10cSrcweir #include "helpid.hrc" 149cdf0e10cSrcweir #include "../appl/app.hrc" 150cdf0e10cSrcweir #include <sfx2/sfxdlg.hxx> 151cdf0e10cSrcweir #include "appbaslib.hxx" 152cdf0e10cSrcweir #include <openflag.hxx> // SFX_STREAM_READWRITE 153cdf0e10cSrcweir 154cdf0e10cSrcweir using namespace ::com::sun::star; 155cdf0e10cSrcweir 156cdf0e10cSrcweir // class SfxHeaderAttributes_Impl ---------------------------------------- 157cdf0e10cSrcweir 158cdf0e10cSrcweir class SfxHeaderAttributes_Impl : public SvKeyValueIterator 159cdf0e10cSrcweir { 160cdf0e10cSrcweir private: 161cdf0e10cSrcweir SfxObjectShell* pDoc; 162cdf0e10cSrcweir SvKeyValueIteratorRef xIter; 163cdf0e10cSrcweir sal_Bool bAlert; 164cdf0e10cSrcweir 165cdf0e10cSrcweir public: 166cdf0e10cSrcweir SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) : 167cdf0e10cSrcweir SvKeyValueIterator(), pDoc( pSh ), 168cdf0e10cSrcweir xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ), 169cdf0e10cSrcweir bAlert( sal_False ) {} 170cdf0e10cSrcweir 171cdf0e10cSrcweir virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); } 172cdf0e10cSrcweir virtual sal_Bool GetNext( SvKeyValue& rKV ) { return xIter->GetNext( rKV ); } 173cdf0e10cSrcweir virtual void Append( const SvKeyValue& rKV ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = sal_False; } 176cdf0e10cSrcweir void SetAttributes(); 177cdf0e10cSrcweir void SetAttribute( const SvKeyValue& rKV ); 178cdf0e10cSrcweir }; 179cdf0e10cSrcweir 180cdf0e10cSrcweir //========================================================================= 181cdf0e10cSrcweir 182cdf0e10cSrcweir sal_uInt16 __READONLY_DATA aTitleMap_Impl[3][2] = 183cdf0e10cSrcweir { 184cdf0e10cSrcweir // local remote 185cdf0e10cSrcweir /* SFX_TITLE_CAPTION */ { SFX_TITLE_FILENAME, SFX_TITLE_TITLE }, 186cdf0e10cSrcweir /* SFX_TITLE_PICKLIST */ { 32, SFX_TITLE_FULLNAME }, 187cdf0e10cSrcweir /* SFX_TITLE_HISTORY */ { 32, SFX_TITLE_FULLNAME } 188cdf0e10cSrcweir }; 189cdf0e10cSrcweir 190cdf0e10cSrcweir //========================================================================= 191cdf0e10cSrcweir 192cdf0e10cSrcweir void SfxObjectShell::AbortImport() 193cdf0e10cSrcweir { 194cdf0e10cSrcweir pImp->bIsAbortingImport = sal_True; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir //------------------------------------------------------------------------- 198cdf0e10cSrcweir 199cdf0e10cSrcweir sal_Bool SfxObjectShell::IsAbortingImport() const 200cdf0e10cSrcweir { 201cdf0e10cSrcweir return pImp->bIsAbortingImport; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir //------------------------------------------------------------------------- 205cdf0e10cSrcweir 206cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> 207cdf0e10cSrcweir SfxObjectShell::getDocProperties() 208cdf0e10cSrcweir { 209cdf0e10cSrcweir uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 210cdf0e10cSrcweir GetModel(), uno::UNO_QUERY_THROW); 211cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps( 212cdf0e10cSrcweir xDPS->getDocumentProperties()); 213cdf0e10cSrcweir DBG_ASSERT(xDocProps.is(), 214cdf0e10cSrcweir "SfxObjectShell: model has no DocumentProperties"); 215cdf0e10cSrcweir return xDocProps; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir //------------------------------------------------------------------------- 219cdf0e10cSrcweir 220cdf0e10cSrcweir void SfxObjectShell::DoFlushDocInfo() 221cdf0e10cSrcweir { 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir //------------------------------------------------------------------------- 225cdf0e10cSrcweir 226cdf0e10cSrcweir // Note: the only thing that calls this is the modification event handler 227cdf0e10cSrcweir // that is installed at the XDocumentProperties 228cdf0e10cSrcweir void SfxObjectShell::FlushDocInfo() 229cdf0e10cSrcweir { 230cdf0e10cSrcweir if ( IsLoading() ) 231cdf0e10cSrcweir return; 232cdf0e10cSrcweir 233cdf0e10cSrcweir SetModified(sal_True); 234cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties()); 235cdf0e10cSrcweir DoFlushDocInfo(); // call template method 236cdf0e10cSrcweir ::rtl::OUString url(xDocProps->getAutoloadURL()); 237cdf0e10cSrcweir sal_Int32 delay(xDocProps->getAutoloadSecs()); 238cdf0e10cSrcweir SetAutoLoad( INetURLObject(url), delay * 1000, 239cdf0e10cSrcweir (delay > 0) || url.getLength() ); 240cdf0e10cSrcweir /* 241cdf0e10cSrcweir // bitte beachten: 242cdf0e10cSrcweir // 1. Titel in DocInfo aber nicht am Doc (nach HTML-Import) 243cdf0e10cSrcweir // => auch am Doc setzen 244cdf0e10cSrcweir // 2. Titel in DocInfo leer (Briefumschlagsdruck) 245cdf0e10cSrcweir // => nicht am Doc setzen, da sonst "unbenanntX" daraus wird 246cdf0e10cSrcweir String aDocInfoTitle = GetDocInfo().GetTitle(); 247cdf0e10cSrcweir if ( aDocInfoTitle.Len() ) 248cdf0e10cSrcweir SetTitle( aDocInfoTitle ); 249cdf0e10cSrcweir else 250cdf0e10cSrcweir { 251cdf0e10cSrcweir pImp->aTitle.Erase(); 252cdf0e10cSrcweir SetNamedVisibility_Impl(); 253cdf0e10cSrcweir if ( GetMedium() ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) ); 256cdf0e10cSrcweir Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir }*/ 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir //------------------------------------------------------------------------- 262cdf0e10cSrcweir 263cdf0e10cSrcweir void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir if(pImp->lErr==ERRCODE_NONE) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir pImp->lErr=lErr; 268cdf0e10cSrcweir 269cdf0e10cSrcweir if( lErr != ERRCODE_NONE && aLogMessage.getLength() ) 270cdf0e10cSrcweir AddLog( aLogMessage ); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir //------------------------------------------------------------------------- 275cdf0e10cSrcweir 276cdf0e10cSrcweir sal_uInt32 SfxObjectShell::GetError() const 277cdf0e10cSrcweir { 278cdf0e10cSrcweir return ERRCODE_TOERROR(GetErrorCode()); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir //------------------------------------------------------------------------- 282cdf0e10cSrcweir 283cdf0e10cSrcweir sal_uInt32 SfxObjectShell::GetErrorCode() const 284cdf0e10cSrcweir { 285cdf0e10cSrcweir sal_uInt32 lError=pImp->lErr; 286cdf0e10cSrcweir if(!lError && GetMedium()) 287cdf0e10cSrcweir lError=GetMedium()->GetErrorCode(); 288cdf0e10cSrcweir return lError; 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir //------------------------------------------------------------------------- 292cdf0e10cSrcweir 293cdf0e10cSrcweir void SfxObjectShell::ResetError() 294cdf0e10cSrcweir { 295cdf0e10cSrcweir if( pImp->lErr != ERRCODE_NONE ) 296cdf0e10cSrcweir AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Resetting Error." ) ) ); 297cdf0e10cSrcweir 298cdf0e10cSrcweir pImp->lErr=0; 299cdf0e10cSrcweir SfxMedium * pMed = GetMedium(); 300cdf0e10cSrcweir if( pMed ) 301cdf0e10cSrcweir pMed->ResetError(); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir //------------------------------------------------------------------------- 305cdf0e10cSrcweir 306cdf0e10cSrcweir sal_Bool SfxObjectShell::IsTemplate() const 307cdf0e10cSrcweir { 308cdf0e10cSrcweir return pImp->bIsTemplate; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir //------------------------------------------------------------------------- 312cdf0e10cSrcweir 313cdf0e10cSrcweir void SfxObjectShell::SetTemplate(sal_Bool bIs) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir pImp->bIsTemplate=bIs; 316cdf0e10cSrcweir SfxFilterMatcher aMatcher( GetFactory().GetFactoryName() ); 317cdf0e10cSrcweir SfxFilterMatcherIter aIter( &aMatcher, SFX_FILTER_TEMPLATEPATH ); 318cdf0e10cSrcweir SfxMedium* pMed = GetMedium(); 319cdf0e10cSrcweir if( pMed ) pMed->SetFilter( aIter.First() ); 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir //------------------------------------------------------------------------- 323cdf0e10cSrcweir 324cdf0e10cSrcweir void SfxObjectShell::EnableSetModified( sal_Bool bEnable ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir #ifdef DBG_UTIL 327cdf0e10cSrcweir if ( bEnable == pImp->m_bEnableSetModified ) 328cdf0e10cSrcweir DBG_WARNING( "SFX_PERSIST: EnableSetModified 2x mit dem gleichen Wert gerufen" ); 329cdf0e10cSrcweir #endif 330cdf0e10cSrcweir pImp->m_bEnableSetModified = bEnable; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir 333cdf0e10cSrcweir //------------------------------------------------------------------------- 334cdf0e10cSrcweir 335cdf0e10cSrcweir sal_Bool SfxObjectShell::IsEnableSetModified() const 336cdf0e10cSrcweir { 337cdf0e10cSrcweir return pImp->m_bEnableSetModified && !IsReadOnly(); 338cdf0e10cSrcweir } 339cdf0e10cSrcweir 340cdf0e10cSrcweir //------------------------------------------------------------------------- 341cdf0e10cSrcweir 342cdf0e10cSrcweir sal_Bool SfxObjectShell::IsModified() 343cdf0e10cSrcweir { 344cdf0e10cSrcweir if ( pImp->m_bIsModified ) 345cdf0e10cSrcweir return sal_True; 346cdf0e10cSrcweir 347cdf0e10cSrcweir if ( !pImp->m_xDocStorage.is() || IsReadOnly() ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir // if the document still has no storage and is not set to be modified explicitly it is not modified 350cdf0e10cSrcweir // a readonly document is also not modified 351cdf0e10cSrcweir 352cdf0e10cSrcweir return sal_False; 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames(); 356cdf0e10cSrcweir for ( sal_Int32 n=0; n<aNames.getLength(); n++ ) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] ); 359cdf0e10cSrcweir OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" ); 360cdf0e10cSrcweir if ( xObj.is() ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir try 363cdf0e10cSrcweir { 364cdf0e10cSrcweir sal_Int32 nState = xObj->getCurrentState(); 365cdf0e10cSrcweir if ( nState != embed::EmbedStates::LOADED ) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY ); 368cdf0e10cSrcweir if ( xModifiable.is() && xModifiable->isModified() ) 369cdf0e10cSrcweir return sal_True; 370cdf0e10cSrcweir } 371cdf0e10cSrcweir } 372cdf0e10cSrcweir catch( uno::Exception& ) 373cdf0e10cSrcweir {} 374cdf0e10cSrcweir } 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir return sal_False; 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir //------------------------------------------------------------------------- 381cdf0e10cSrcweir 382cdf0e10cSrcweir void SfxObjectShell::SetModified( sal_Bool bModifiedP ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir #ifdef DBG_UTIL 385cdf0e10cSrcweir if ( !bModifiedP && !IsEnableSetModified() ) 386cdf0e10cSrcweir DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), obwohl IsEnableSetModified() == sal_False" ); 387cdf0e10cSrcweir #endif 388cdf0e10cSrcweir 389cdf0e10cSrcweir if( !IsEnableSetModified() ) 390cdf0e10cSrcweir return; 391cdf0e10cSrcweir 392cdf0e10cSrcweir if( pImp->m_bIsModified != bModifiedP ) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir pImp->m_bIsModified = bModifiedP; 395cdf0e10cSrcweir ModifyChanged(); 396cdf0e10cSrcweir } 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir //------------------------------------------------------------------------- 400cdf0e10cSrcweir 401cdf0e10cSrcweir void SfxObjectShell::ModifyChanged() 402cdf0e10cSrcweir { 403cdf0e10cSrcweir if ( pImp->bClosing ) 404cdf0e10cSrcweir // SetModified aus dem dispose des Models! 405cdf0e10cSrcweir return; 406cdf0e10cSrcweir 407cdf0e10cSrcweir {DBG_CHKTHIS(SfxObjectShell, 0);} 408cdf0e10cSrcweir 409cdf0e10cSrcweir SfxViewFrame* pViewFrame = SfxViewFrame::Current(); 410cdf0e10cSrcweir if ( pViewFrame ) 411cdf0e10cSrcweir pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS ); 412cdf0e10cSrcweir 413cdf0e10cSrcweir Invalidate( SID_SIGNATURE ); 414cdf0e10cSrcweir Invalidate( SID_MACRO_SIGNATURE ); 415cdf0e10cSrcweir Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) ); // xmlsec05, signed state might change in title... 416cdf0e10cSrcweir 417cdf0e10cSrcweir SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) ); 418cdf0e10cSrcweir } 419cdf0e10cSrcweir 420cdf0e10cSrcweir //------------------------------------------------------------------------- 421cdf0e10cSrcweir 422cdf0e10cSrcweir sal_Bool SfxObjectShell::IsReadOnlyUI() const 423cdf0e10cSrcweir 424cdf0e10cSrcweir /* [Beschreibung] 425cdf0e10cSrcweir 426cdf0e10cSrcweir Liefert sal_True, wenn das Dokument fuer die UI wie r/o behandelt werden 427cdf0e10cSrcweir soll. Dieses ist unabhaengig vom tatsaechlichen r/o, welches per 428cdf0e10cSrcweir <IsReadOnly()> erfragbar ist. 429cdf0e10cSrcweir */ 430cdf0e10cSrcweir 431cdf0e10cSrcweir { 432cdf0e10cSrcweir return pImp->bReadOnlyUI; 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir //------------------------------------------------------------------------- 436cdf0e10cSrcweir 437cdf0e10cSrcweir sal_Bool SfxObjectShell::IsReadOnlyMedium() const 438cdf0e10cSrcweir 439cdf0e10cSrcweir /* [Beschreibung] 440cdf0e10cSrcweir 441cdf0e10cSrcweir Liefert sal_True, wenn das Medium r/o ist bzw. r/o geoeffnet wurde. 442cdf0e10cSrcweir */ 443cdf0e10cSrcweir 444cdf0e10cSrcweir { 445cdf0e10cSrcweir if ( !pMedium ) 446cdf0e10cSrcweir return sal_True; 447cdf0e10cSrcweir return pMedium->IsReadOnly(); 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir //------------------------------------------------------------------------- 451cdf0e10cSrcweir 452cdf0e10cSrcweir void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly ) 453cdf0e10cSrcweir 454cdf0e10cSrcweir /* [Beschreibung] 455cdf0e10cSrcweir 456cdf0e10cSrcweir Schaltet das Dokument in einen r/o bzw. r/w Zustand ohne es neu 457cdf0e10cSrcweir zu laden und ohne die Open-Modi des Mediums zu aendern. 458cdf0e10cSrcweir */ 459cdf0e10cSrcweir 460cdf0e10cSrcweir { 461cdf0e10cSrcweir sal_Bool bWasRO = IsReadOnly(); 462cdf0e10cSrcweir pImp->bReadOnlyUI = bReadOnly; 463cdf0e10cSrcweir if ( bWasRO != IsReadOnly() ) 464cdf0e10cSrcweir { 465cdf0e10cSrcweir Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); 466cdf0e10cSrcweir //if ( pImp->pDocInfo ) 467cdf0e10cSrcweir // pImp->pDocInfo->SetReadOnly( IsReadOnly() ); 468cdf0e10cSrcweir } 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir //------------------------------------------------------------------------- 472cdf0e10cSrcweir 473cdf0e10cSrcweir void SfxObjectShell::SetReadOnly() 474cdf0e10cSrcweir { 475cdf0e10cSrcweir // Let the document be completely readonly, means that the 476cdf0e10cSrcweir // medium open mode is adjusted accordingly, and the write lock 477cdf0e10cSrcweir // on the file is removed. 478cdf0e10cSrcweir 479cdf0e10cSrcweir if ( pMedium && !IsReadOnlyMedium() ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir sal_Bool bWasROUI = IsReadOnly(); 482cdf0e10cSrcweir 483cdf0e10cSrcweir pMedium->UnlockFile( sal_False ); 484cdf0e10cSrcweir 485cdf0e10cSrcweir // the storage-based mediums are already based on the temporary file 486cdf0e10cSrcweir // so UnlockFile has already closed the locking stream 487cdf0e10cSrcweir if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() ) 488cdf0e10cSrcweir pMedium->CloseInStream(); 489cdf0e10cSrcweir 490cdf0e10cSrcweir pMedium->SetOpenMode( SFX_STREAM_READONLY, pMedium->IsDirect(), sal_True ); 491cdf0e10cSrcweir pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 492cdf0e10cSrcweir 493cdf0e10cSrcweir if ( !bWasROUI ) 494cdf0e10cSrcweir Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); 495cdf0e10cSrcweir } 496cdf0e10cSrcweir } 497cdf0e10cSrcweir //------------------------------------------------------------------------- 498cdf0e10cSrcweir 499cdf0e10cSrcweir sal_Bool SfxObjectShell::IsReadOnly() const 500cdf0e10cSrcweir { 501cdf0e10cSrcweir return pImp->bReadOnlyUI || IsReadOnlyMedium(); 502cdf0e10cSrcweir } 503cdf0e10cSrcweir 504cdf0e10cSrcweir //------------------------------------------------------------------------- 505cdf0e10cSrcweir 506cdf0e10cSrcweir sal_Bool SfxObjectShell::IsInModalMode() const 507cdf0e10cSrcweir { 508cdf0e10cSrcweir return pImp->bModalMode || pImp->bRunningMacro; 509cdf0e10cSrcweir } 510cdf0e10cSrcweir 511cdf0e10cSrcweir //<!--Added by PengYunQuan for Validity Cell Range Picker 512cdf0e10cSrcweir sal_Bool SfxObjectShell::AcceptStateUpdate() const 513cdf0e10cSrcweir { 514cdf0e10cSrcweir return !IsInModalMode(); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir //-->Added by PengYunQuan for Validity Cell Range Picker 517cdf0e10cSrcweir 518cdf0e10cSrcweir //------------------------------------------------------------------------- 519cdf0e10cSrcweir 520cdf0e10cSrcweir sal_Bool SfxObjectShell::HasModalViews() const 521cdf0e10cSrcweir { 522cdf0e10cSrcweir SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 523cdf0e10cSrcweir while( pFrame ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir if ( pFrame->IsInModalMode() ) 526cdf0e10cSrcweir return sal_True; 527cdf0e10cSrcweir 528cdf0e10cSrcweir pFrame = SfxViewFrame::GetNext( *pFrame, this ); 529cdf0e10cSrcweir } 530cdf0e10cSrcweir 531cdf0e10cSrcweir return sal_False; 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir //------------------------------------------------------------------------- 535cdf0e10cSrcweir 536cdf0e10cSrcweir void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal ) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir if ( !pImp->bRunningMacro != !bModal ) 539cdf0e10cSrcweir { 540cdf0e10cSrcweir pImp->bRunningMacro = bModal; 541cdf0e10cSrcweir Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) ); 542cdf0e10cSrcweir } 543cdf0e10cSrcweir } 544cdf0e10cSrcweir 545cdf0e10cSrcweir //------------------------------------------------------------------------- 546cdf0e10cSrcweir 547cdf0e10cSrcweir void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal ) 548cdf0e10cSrcweir { 549cdf0e10cSrcweir // nur Broadcasten wenn modifiziert, sonst ggf. Endlosrekursion 550cdf0e10cSrcweir if ( !pImp->bModalMode != !bModal ) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir // zentral mitz"ahlen 553cdf0e10cSrcweir sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode; 554cdf0e10cSrcweir if ( bModal ) 555cdf0e10cSrcweir ++rDocModalCount; 556cdf0e10cSrcweir else 557cdf0e10cSrcweir --rDocModalCount; 558cdf0e10cSrcweir 559cdf0e10cSrcweir // umschalten 560cdf0e10cSrcweir pImp->bModalMode = bModal; 561cdf0e10cSrcweir Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) ); 562cdf0e10cSrcweir } 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir //-------------------------------------------------------------------- 566cdf0e10cSrcweir sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave ) 567cdf0e10cSrcweir { 568cdf0e10cSrcweir sal_Bool bResult = sal_True; 569cdf0e10cSrcweir 570cdf0e10cSrcweir if ( bShared != IsDocShared() ) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir ::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir if ( !aOrigURL.getLength() && bSave ) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir // this is a new document, let it be stored before switching to the shared mode; 577cdf0e10cSrcweir // the storing should be done without shared flag, since it is possible that the 578cdf0e10cSrcweir // target location does not allow to create sharing control file; 579cdf0e10cSrcweir // the shared flag will be set later after creation of sharing control file 580cdf0e10cSrcweir SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this ); 581cdf0e10cSrcweir 582cdf0e10cSrcweir if ( pViewFrame ) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir // TODO/LATER: currently the application guards against the reentrance problem 585cdf0e10cSrcweir const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC ); 586cdf0e10cSrcweir SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem ); 587cdf0e10cSrcweir bResult = ( pResult && pResult->GetValue() ); 588cdf0e10cSrcweir if ( bResult ) 589cdf0e10cSrcweir aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 590cdf0e10cSrcweir } 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir sal_Bool bOldValue = HasSharedXMLFlagSet(); 594cdf0e10cSrcweir SetSharedXMLFlag( bShared ); 595cdf0e10cSrcweir 596cdf0e10cSrcweir sal_Bool bRemoveEntryOnError = sal_False; 597cdf0e10cSrcweir if ( bResult && bShared ) 598cdf0e10cSrcweir { 599cdf0e10cSrcweir try 600cdf0e10cSrcweir { 601cdf0e10cSrcweir ::svt::ShareControlFile aControlFile( aOrigURL ); 602cdf0e10cSrcweir aControlFile.InsertOwnEntry(); 603cdf0e10cSrcweir bRemoveEntryOnError = sal_True; 604cdf0e10cSrcweir } 605cdf0e10cSrcweir catch( uno::Exception& ) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir bResult = sal_False; 608cdf0e10cSrcweir } 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir if ( bResult && bSave ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this ); 614cdf0e10cSrcweir 615cdf0e10cSrcweir if ( pViewFrame ) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir // TODO/LATER: currently the application guards against the reentrance problem 618cdf0e10cSrcweir SetModified( sal_True ); // the modified flag has to be set to let the document be stored with the shared flag 619cdf0e10cSrcweir const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC ); 620cdf0e10cSrcweir SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem ); 621cdf0e10cSrcweir bResult = ( pResult && pResult->GetValue() ); 622cdf0e10cSrcweir } 623cdf0e10cSrcweir } 624cdf0e10cSrcweir 625cdf0e10cSrcweir if ( bResult ) 626cdf0e10cSrcweir { 627cdf0e10cSrcweir // TODO/LATER: Is it possible that the following calls fail? 628cdf0e10cSrcweir if ( bShared ) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir pImp->m_aSharedFileURL = aOrigURL; 631cdf0e10cSrcweir GetMedium()->SwitchDocumentToTempFile(); 632cdf0e10cSrcweir } 633cdf0e10cSrcweir else 634cdf0e10cSrcweir { 635cdf0e10cSrcweir ::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 636cdf0e10cSrcweir GetMedium()->SwitchDocumentToFile( GetSharedFileURL() ); 637cdf0e10cSrcweir pImp->m_aSharedFileURL = ::rtl::OUString(); 638cdf0e10cSrcweir 639cdf0e10cSrcweir // now remove the temporary file the document was based on 640cdf0e10cSrcweir ::utl::UCBContentHelper::Kill( aTempFileURL ); 641cdf0e10cSrcweir 642cdf0e10cSrcweir try 643cdf0e10cSrcweir { 644cdf0e10cSrcweir // aOrigURL can not be used since it contains an old value 645cdf0e10cSrcweir ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); 646cdf0e10cSrcweir aControlFile.RemoveFile(); 647cdf0e10cSrcweir } 648cdf0e10cSrcweir catch( uno::Exception& ) 649cdf0e10cSrcweir { 650cdf0e10cSrcweir } 651cdf0e10cSrcweir } 652cdf0e10cSrcweir } 653cdf0e10cSrcweir else 654cdf0e10cSrcweir { 655cdf0e10cSrcweir // the saving has failed! 656cdf0e10cSrcweir if ( bRemoveEntryOnError ) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir try 659cdf0e10cSrcweir { 660cdf0e10cSrcweir ::svt::ShareControlFile aControlFile( aOrigURL ); 661cdf0e10cSrcweir aControlFile.RemoveEntry(); 662cdf0e10cSrcweir } 663cdf0e10cSrcweir catch( uno::Exception& ) 664cdf0e10cSrcweir {} 665cdf0e10cSrcweir } 666cdf0e10cSrcweir 667cdf0e10cSrcweir SetSharedXMLFlag( bOldValue ); 668cdf0e10cSrcweir } 669cdf0e10cSrcweir } 670cdf0e10cSrcweir else 671cdf0e10cSrcweir bResult = sal_False; // the second switch to the same mode 672cdf0e10cSrcweir 673cdf0e10cSrcweir if ( bResult ) 674cdf0e10cSrcweir SetTitle( String() ); 675cdf0e10cSrcweir 676cdf0e10cSrcweir return bResult; 677cdf0e10cSrcweir } 678cdf0e10cSrcweir 679cdf0e10cSrcweir //-------------------------------------------------------------------- 680cdf0e10cSrcweir 681cdf0e10cSrcweir void SfxObjectShell::DisconnectFromShared() 682cdf0e10cSrcweir { 683cdf0e10cSrcweir if ( IsDocShared() ) 684cdf0e10cSrcweir { 685cdf0e10cSrcweir if ( pMedium && pMedium->GetStorage().is() ) 686cdf0e10cSrcweir { 687cdf0e10cSrcweir // set medium to noname 688cdf0e10cSrcweir pMedium->SetName( String(), sal_True ); 689cdf0e10cSrcweir pMedium->Init_Impl(); 690cdf0e10cSrcweir 691cdf0e10cSrcweir // drop resource 692cdf0e10cSrcweir SetNoName(); 693cdf0e10cSrcweir InvalidateName(); 694cdf0e10cSrcweir 695cdf0e10cSrcweir // untitled document must be based on temporary storage 696cdf0e10cSrcweir // the medium should not dispose the storage in this case 697cdf0e10cSrcweir if ( pMedium->GetStorage() == GetStorage() ) 698cdf0e10cSrcweir ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ); 699cdf0e10cSrcweir 700cdf0e10cSrcweir pMedium->Close(); 701cdf0e10cSrcweir FreeSharedFile(); 702cdf0e10cSrcweir 703cdf0e10cSrcweir SfxMedium* pTmpMedium = pMedium; 704cdf0e10cSrcweir ForgetMedium(); 705cdf0e10cSrcweir if( !DoSaveCompleted( pTmpMedium ) ) 706cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 707cdf0e10cSrcweir else 708cdf0e10cSrcweir { 709cdf0e10cSrcweir // the medium should not dispose the storage, DoSaveCompleted() has let it to do so 710cdf0e10cSrcweir pMedium->CanDisposeStorage_Impl( sal_False ); 711cdf0e10cSrcweir } 712cdf0e10cSrcweir 713cdf0e10cSrcweir pMedium->GetItemSet()->ClearItem( SID_DOC_READONLY ); 714cdf0e10cSrcweir pMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True ); 715cdf0e10cSrcweir 716cdf0e10cSrcweir SetTitle( String() ); 717cdf0e10cSrcweir } 718cdf0e10cSrcweir } 719cdf0e10cSrcweir } 720cdf0e10cSrcweir 721cdf0e10cSrcweir //-------------------------------------------------------------------- 722cdf0e10cSrcweir 723cdf0e10cSrcweir void SfxObjectShell::FreeSharedFile() 724cdf0e10cSrcweir { 725cdf0e10cSrcweir if ( pMedium ) 726cdf0e10cSrcweir FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); 727cdf0e10cSrcweir } 728cdf0e10cSrcweir 729cdf0e10cSrcweir //-------------------------------------------------------------------- 730cdf0e10cSrcweir void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL ) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir SetSharedXMLFlag( sal_False ); 733cdf0e10cSrcweir 734cdf0e10cSrcweir if ( IsDocShared() && aTempFileURL.getLength() 735cdf0e10cSrcweir && !::utl::UCBContentHelper::EqualURLs( aTempFileURL, GetSharedFileURL() ) ) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir if ( pImp->m_bAllowShareControlFileClean ) 738cdf0e10cSrcweir { 739cdf0e10cSrcweir try 740cdf0e10cSrcweir { 741cdf0e10cSrcweir ::svt::ShareControlFile aControlFile( GetSharedFileURL() ); 742cdf0e10cSrcweir aControlFile.RemoveEntry(); 743cdf0e10cSrcweir } 744cdf0e10cSrcweir catch( uno::Exception& ) 745cdf0e10cSrcweir { 746cdf0e10cSrcweir } 747cdf0e10cSrcweir } 748cdf0e10cSrcweir 749cdf0e10cSrcweir // the cleaning is forbidden only once 750cdf0e10cSrcweir pImp->m_bAllowShareControlFileClean = sal_True; 751cdf0e10cSrcweir 752cdf0e10cSrcweir // now remove the temporary file the document is based currently on 753cdf0e10cSrcweir ::utl::UCBContentHelper::Kill( aTempFileURL ); 754cdf0e10cSrcweir 755cdf0e10cSrcweir pImp->m_aSharedFileURL = ::rtl::OUString(); 756cdf0e10cSrcweir } 757cdf0e10cSrcweir } 758cdf0e10cSrcweir 759cdf0e10cSrcweir //-------------------------------------------------------------------- 760cdf0e10cSrcweir void SfxObjectShell::DoNotCleanShareControlFile() 761cdf0e10cSrcweir { 762cdf0e10cSrcweir pImp->m_bAllowShareControlFileClean = sal_False; 763cdf0e10cSrcweir } 764cdf0e10cSrcweir 765cdf0e10cSrcweir //-------------------------------------------------------------------- 766cdf0e10cSrcweir void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const 767cdf0e10cSrcweir { 768cdf0e10cSrcweir pImp->m_bSharedXMLFlag = bFlag; 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir //-------------------------------------------------------------------- 772cdf0e10cSrcweir sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const 773cdf0e10cSrcweir { 774cdf0e10cSrcweir return pImp->m_bSharedXMLFlag; 775cdf0e10cSrcweir } 776cdf0e10cSrcweir 777cdf0e10cSrcweir //-------------------------------------------------------------------- 778cdf0e10cSrcweir 779cdf0e10cSrcweir sal_Bool SfxObjectShell::IsDocShared() const 780cdf0e10cSrcweir { 781cdf0e10cSrcweir return ( pImp->m_aSharedFileURL.getLength() > 0 ); 782cdf0e10cSrcweir } 783cdf0e10cSrcweir 784cdf0e10cSrcweir //-------------------------------------------------------------------- 785cdf0e10cSrcweir 786cdf0e10cSrcweir ::rtl::OUString SfxObjectShell::GetSharedFileURL() const 787cdf0e10cSrcweir { 788cdf0e10cSrcweir return pImp->m_aSharedFileURL; 789cdf0e10cSrcweir } 790cdf0e10cSrcweir 791cdf0e10cSrcweir //-------------------------------------------------------------------- 792cdf0e10cSrcweir 793cdf0e10cSrcweir Size SfxObjectShell::GetFirstPageSize() 794cdf0e10cSrcweir { 795cdf0e10cSrcweir return GetVisArea(ASPECT_THUMBNAIL).GetSize(); 796cdf0e10cSrcweir } 797cdf0e10cSrcweir 798cdf0e10cSrcweir 799cdf0e10cSrcweir //-------------------------------------------------------------------- 800cdf0e10cSrcweir 801cdf0e10cSrcweir IndexBitSet& SfxObjectShell::GetNoSet_Impl() 802cdf0e10cSrcweir { 803cdf0e10cSrcweir return pImp->aBitSet; 804cdf0e10cSrcweir } 805cdf0e10cSrcweir 806cdf0e10cSrcweir //-------------------------------------------------------------------- 807cdf0e10cSrcweir // changes the title of the document 808cdf0e10cSrcweir 809cdf0e10cSrcweir void SfxObjectShell::SetTitle 810cdf0e10cSrcweir ( 811cdf0e10cSrcweir const String& rTitle // der neue Titel des Dokuments 812cdf0e10cSrcweir ) 813cdf0e10cSrcweir 814cdf0e10cSrcweir /* [Beschreibung] 815cdf0e10cSrcweir 816cdf0e10cSrcweir Mit dieser Methode kann der Titel des Dokuments gesetzt werden. 817cdf0e10cSrcweir Dieser entspricht initial dem kompletten Dateinamen. Ein Setzen 818cdf0e10cSrcweir des Titels wirkt jedoch nicht zu"uck auf den Dateinamen; er wird 819cdf0e10cSrcweir jedoch in den Caption-Bars der MDI-Fenster angezeigt. 820cdf0e10cSrcweir */ 821cdf0e10cSrcweir 822cdf0e10cSrcweir { 823cdf0e10cSrcweir DBG_CHKTHIS(SfxObjectShell, 0); 824cdf0e10cSrcweir 825cdf0e10cSrcweir // nix zu tun? 826cdf0e10cSrcweir if ( ( ( HasName() && pImp->aTitle == rTitle ) 827cdf0e10cSrcweir || ( !HasName() && GetTitle() == rTitle ) ) 828cdf0e10cSrcweir && !IsDocShared() ) 829cdf0e10cSrcweir return; 830cdf0e10cSrcweir 831cdf0e10cSrcweir SfxApplication *pSfxApp = SFX_APP(); 832cdf0e10cSrcweir #if 0 833cdf0e10cSrcweir // wird 'unbenannt#' als Titel gesetzt 834cdf0e10cSrcweir String aNoName(SfxResId(STR_NONAME)); 835cdf0e10cSrcweir if ( rTitle.Match(aNoName) <= aNoName.Len() ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir // er ist es selbst => ignorieren 838cdf0e10cSrcweir pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber); 839cdf0e10cSrcweir pImp->bIsNamedVisible=0; 840cdf0e10cSrcweir } 841cdf0e10cSrcweir #endif 842cdf0e10cSrcweir 843cdf0e10cSrcweir // ggf. die unbenannt-Nummer freigeben 844cdf0e10cSrcweir if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber ) 845cdf0e10cSrcweir { 846cdf0e10cSrcweir pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber); 847cdf0e10cSrcweir pImp->bIsNamedVisible = 0; 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir // Title setzen 851cdf0e10cSrcweir pImp->aTitle = rTitle; 852cdf0e10cSrcweir // Wieso denn in der DocInfo? 853cdf0e10cSrcweir // GetDocInfo().SetTitle( rTitle ); 854cdf0e10cSrcweir // FlushDocInfo(); 855cdf0e10cSrcweir 856cdf0e10cSrcweir // Benachrichtigungen 857cdf0e10cSrcweir if ( GetMedium() ) 858cdf0e10cSrcweir { 859cdf0e10cSrcweir SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) ); 860cdf0e10cSrcweir Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 861cdf0e10cSrcweir } 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir //-------------------------------------------------------------------- 865cdf0e10cSrcweir 866cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 867cdf0e10cSrcweir String X(const String &rRet) 868cdf0e10cSrcweir { 869cdf0e10cSrcweir if ( !rRet.Len() ) 870cdf0e10cSrcweir return DEFINE_CONST_UNICODE( "-empty-" ); 871cdf0e10cSrcweir return rRet; 872cdf0e10cSrcweir } 873cdf0e10cSrcweir #else 874cdf0e10cSrcweir #define X(ret) ret 875cdf0e10cSrcweir #endif 876cdf0e10cSrcweir 877cdf0e10cSrcweir //-------------------------------------------------------------------- 878cdf0e10cSrcweir //-------------------------------------------------------------------- 879cdf0e10cSrcweir String SfxObjectShell::GetTitle 880cdf0e10cSrcweir ( 881cdf0e10cSrcweir sal_uInt16 nMaxLength /* 0 (default) 882cdf0e10cSrcweir der Titel selbst, so wie er ist 883cdf0e10cSrcweir 884cdf0e10cSrcweir 1 (==SFX_TITLE_FILENAME) 885cdf0e10cSrcweir liefert den logischen Dateinamen ohne Pfad 886cdf0e10cSrcweir (unter WNT je nach Systemeinstellung ohne 887cdf0e10cSrcweir Extension) 888cdf0e10cSrcweir 889cdf0e10cSrcweir 2 (==SFX_TITLE_FULLNAME) 890cdf0e10cSrcweir liefert den mit komplettem logischen Dateinamen 891cdf0e10cSrcweir mit Pfad (remote => ::com::sun::star::util::URL) 892cdf0e10cSrcweir 893cdf0e10cSrcweir 3 (==SFX_TITLE_APINAME) 894cdf0e10cSrcweir liefert den logischen Dateinamen ohne Pfad 895cdf0e10cSrcweir und Extension 896cdf0e10cSrcweir 897cdf0e10cSrcweir 4 (==SFX_TITLE_DETECT) 898cdf0e10cSrcweir liefert den kompletten Titel, falls noch 899cdf0e10cSrcweir nicht gesetzt wird aber aus DocInfo oder 900cdf0e10cSrcweir dem Namen des Medium erzeugt 901cdf0e10cSrcweir 902cdf0e10cSrcweir 5 (==SFX_TITLE_CAPTION) 903cdf0e10cSrcweir liefert den Titel so, wie MB ihn heute in 904cdf0e10cSrcweir der CaptionBar anzeigen m"ochte 905cdf0e10cSrcweir 906cdf0e10cSrcweir 6 (==SFX_TITLE_PICKLIST) 907cdf0e10cSrcweir liefert den Titel so, wie MB ihn heute in 908cdf0e10cSrcweir der PickList anzeigen m"ochte 909cdf0e10cSrcweir 910cdf0e10cSrcweir 7 (==SFX_TITLE_HISTORY) 911cdf0e10cSrcweir liefert den Titel so, wie MB ihn heute in 912cdf0e10cSrcweir der History anzeigen m"ochte 913cdf0e10cSrcweir 914cdf0e10cSrcweir 10 bis USHRT_MAX 915cdf0e10cSrcweir liefert maximal 'nMaxLength' Zeichen vom logischen 916cdf0e10cSrcweir Dateinamen inkl. Pfad (remote => ::com::sun::star::util::URL) 917cdf0e10cSrcweir */ 918cdf0e10cSrcweir ) const 919cdf0e10cSrcweir 920cdf0e10cSrcweir /* [Beschreibung] 921cdf0e10cSrcweir 922cdf0e10cSrcweir Liefert den Titel bzw. logischen Dateinamen des Dokuments, je nach 923cdf0e10cSrcweir 'nMaxLength'. 924cdf0e10cSrcweir 925cdf0e10cSrcweir Falls der Dateiname mit Pfad verwendet wird, wird die Namensk"urzung durch 926cdf0e10cSrcweir Ersetzung eines oder mehrerer Directory-Namen durch "..." durchgef"uhrt, 927cdf0e10cSrcweir URLs werden z.Zt. immer komplett geliefert. 928cdf0e10cSrcweir */ 929cdf0e10cSrcweir 930cdf0e10cSrcweir { 931cdf0e10cSrcweir // if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 932cdf0e10cSrcweir // return String(); 933cdf0e10cSrcweir SfxMedium *pMed = GetMedium(); 934cdf0e10cSrcweir if ( IsLoading() ) 935cdf0e10cSrcweir return String(); 936cdf0e10cSrcweir 937cdf0e10cSrcweir /* if ( !nMaxLength && pImp->pDocInfo ) 938cdf0e10cSrcweir { 939cdf0e10cSrcweir String aTitle = pImp->pDocInfo->GetTitle(); 940cdf0e10cSrcweir if ( aTitle.Len() ) 941cdf0e10cSrcweir return aTitle; 942cdf0e10cSrcweir } */ 943cdf0e10cSrcweir 944cdf0e10cSrcweir // Titel erzeugen? 945cdf0e10cSrcweir if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() ) 946cdf0e10cSrcweir { 947cdf0e10cSrcweir static sal_Bool bRecur = sal_False; 948cdf0e10cSrcweir if ( bRecur ) 949cdf0e10cSrcweir return DEFINE_CONST_UNICODE( "-not available-" ); 950cdf0e10cSrcweir bRecur = sal_True; 951cdf0e10cSrcweir 952cdf0e10cSrcweir String aTitle; 953cdf0e10cSrcweir SfxObjectShell *pThis = (SfxObjectShell*) this; 954cdf0e10cSrcweir 955cdf0e10cSrcweir if ( pMed ) 956cdf0e10cSrcweir { 957cdf0e10cSrcweir SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False ); 958cdf0e10cSrcweir if ( pNameItem ) 959cdf0e10cSrcweir aTitle = pNameItem->GetValue(); 960cdf0e10cSrcweir } 961cdf0e10cSrcweir 962cdf0e10cSrcweir if ( !aTitle.Len() ) 963cdf0e10cSrcweir aTitle = GetTitle( SFX_TITLE_FILENAME ); 964cdf0e10cSrcweir 965cdf0e10cSrcweir if ( IsTemplate() ) 966cdf0e10cSrcweir pThis->SetTitle( aTitle ); 967cdf0e10cSrcweir bRecur = sal_False; 968cdf0e10cSrcweir return X(aTitle); 969cdf0e10cSrcweir } 970cdf0e10cSrcweir else if (SFX_TITLE_APINAME == nMaxLength ) 971cdf0e10cSrcweir return X(GetAPIName()); 972cdf0e10cSrcweir 973cdf0e10cSrcweir // Sonderfall Vorlagen: 974cdf0e10cSrcweir if( IsTemplate() && pImp->aTitle.Len() && 975cdf0e10cSrcweir ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) ) 976cdf0e10cSrcweir return X(pImp->aTitle); 977cdf0e10cSrcweir 978cdf0e10cSrcweir // Picklist/Caption wird gemappt 979cdf0e10cSrcweir if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) ) 980cdf0e10cSrcweir { 981cdf0e10cSrcweir // Wenn ein spezieller Titel beim "Offnen mitgegeben wurde; 982cdf0e10cSrcweir // wichtig bei URLs, die INET_PROT_FILE verwenden, denn bei denen 983cdf0e10cSrcweir // wird der gesetzte Titel nicht beachtet. 984cdf0e10cSrcweir // (s.u., Auswertung von aTitleMap_Impl) 985cdf0e10cSrcweir SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False ); 986cdf0e10cSrcweir if ( pNameItem ) 987cdf0e10cSrcweir return X( pNameItem->GetValue() ); 988cdf0e10cSrcweir } 989cdf0e10cSrcweir 990cdf0e10cSrcweir // noch unbenannt? 991cdf0e10cSrcweir DBG_ASSERT( !HasName() || pMed, "HasName() aber kein Medium?!?" ); 992cdf0e10cSrcweir if ( !HasName() || !pMed ) 993cdf0e10cSrcweir { 994cdf0e10cSrcweir // schon Titel gesezt? 995cdf0e10cSrcweir if ( pImp->aTitle.Len() ) 996cdf0e10cSrcweir return X(pImp->aTitle); 997cdf0e10cSrcweir 998cdf0e10cSrcweir // mu\s es durchnumeriert werden? 999cdf0e10cSrcweir String aNoName( SfxResId( STR_NONAME ) ); 1000cdf0e10cSrcweir if ( pImp->bIsNamedVisible ) 1001cdf0e10cSrcweir // Nummer hintenanh"angen 1002cdf0e10cSrcweir aNoName += String::CreateFromInt32( pImp->nVisualDocumentNumber ); 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir // Dokument hei\st vorerst 'unbenannt#' 1005cdf0e10cSrcweir return X(aNoName); 1006cdf0e10cSrcweir } 1007cdf0e10cSrcweir 1008cdf0e10cSrcweir const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) ); 1009cdf0e10cSrcweir if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY ) 1010cdf0e10cSrcweir { 1011cdf0e10cSrcweir sal_uInt16 nRemote; 1012cdf0e10cSrcweir if( !pMed || aURL.GetProtocol() == INET_PROT_FILE ) 1013cdf0e10cSrcweir nRemote = 0; 1014cdf0e10cSrcweir else 1015cdf0e10cSrcweir nRemote = 1; 1016cdf0e10cSrcweir nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote]; 1017cdf0e10cSrcweir } 1018cdf0e10cSrcweir 1019cdf0e10cSrcweir // lokale Datei? 1020cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_FILE ) 1021cdf0e10cSrcweir { 1022cdf0e10cSrcweir String aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() ); 1023cdf0e10cSrcweir if ( nMaxLength == SFX_TITLE_FULLNAME ) 1024cdf0e10cSrcweir return X( aName ); 1025cdf0e10cSrcweir else if ( nMaxLength == SFX_TITLE_FILENAME ) 1026cdf0e10cSrcweir return X( aURL.getName( INetURLObject::LAST_SEGMENT, 1027cdf0e10cSrcweir true, INetURLObject::DECODE_WITH_CHARSET ) ); 1028cdf0e10cSrcweir else if ( !pImp->aTitle.Len() ) 1029cdf0e10cSrcweir pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, 1030cdf0e10cSrcweir true, INetURLObject::DECODE_WITH_CHARSET ); 1031cdf0e10cSrcweir } 1032cdf0e10cSrcweir else 1033cdf0e10cSrcweir { 1034cdf0e10cSrcweir // ::com::sun::star::util::URL-Versionen 1035cdf0e10cSrcweir if ( nMaxLength >= SFX_TITLE_MAXLEN ) 1036cdf0e10cSrcweir { 1037cdf0e10cSrcweir String aComplete( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); 1038cdf0e10cSrcweir if( aComplete.Len() > nMaxLength ) 1039cdf0e10cSrcweir { 1040cdf0e10cSrcweir String aRet( DEFINE_CONST_UNICODE( "..." ) ); 1041cdf0e10cSrcweir aRet += aComplete.Copy( aComplete.Len() - nMaxLength + 3, nMaxLength - 3 ); 1042cdf0e10cSrcweir return X( aRet ); 1043cdf0e10cSrcweir } 1044cdf0e10cSrcweir else 1045cdf0e10cSrcweir return X( aComplete ); 1046cdf0e10cSrcweir } 1047cdf0e10cSrcweir else if ( nMaxLength == SFX_TITLE_FILENAME ) 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir String aName( aURL.GetBase() ); 1050cdf0e10cSrcweir aName = INetURLObject::decode( aName, INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET ); 1051cdf0e10cSrcweir if( !aName.Len() ) 1052cdf0e10cSrcweir aName = aURL.GetURLNoPass(); 1053cdf0e10cSrcweir return X(aName); 1054cdf0e10cSrcweir } 1055cdf0e10cSrcweir else if ( nMaxLength == SFX_TITLE_FULLNAME ) 1056cdf0e10cSrcweir return X(aURL.GetMainURL( INetURLObject::DECODE_TO_IURI )); 1057cdf0e10cSrcweir 1058cdf0e10cSrcweir // ggf. Titel aus Dateiname generieren 1059cdf0e10cSrcweir if ( !pImp->aTitle.Len() ) 1060cdf0e10cSrcweir pImp->aTitle = aURL.GetBase(); 1061cdf0e10cSrcweir 1062cdf0e10cSrcweir // workaround for the case when the name can not be retrieved from URL by INetURLObject 1063cdf0e10cSrcweir if ( !pImp->aTitle.Len() ) 1064cdf0e10cSrcweir pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET ); 1065cdf0e10cSrcweir } 1066cdf0e10cSrcweir 1067cdf0e10cSrcweir // ganzer Titel 1068cdf0e10cSrcweir return X(pImp->aTitle); 1069cdf0e10cSrcweir } 1070cdf0e10cSrcweir 1071cdf0e10cSrcweir //-------------------------------------------------------------------- 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir void SfxObjectShell::InvalidateName() 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir /* [Beschreibung] 1076cdf0e10cSrcweir 1077cdf0e10cSrcweir Ermittelt den Titel des Dokuments neu aus 'unbenannt', DocInfo-Titel 1078cdf0e10cSrcweir bzw. Dateinamen. Wird nach Laden aus Template oder SaveAs ben"otigt. 1079cdf0e10cSrcweir */ 1080cdf0e10cSrcweir 1081cdf0e10cSrcweir { 1082cdf0e10cSrcweir // Title neu erzeugen 1083cdf0e10cSrcweir pImp->aTitle.Erase(); 1084cdf0e10cSrcweir // pImp->nVisualDocumentNumber = USHRT_MAX; 1085cdf0e10cSrcweir //GetTitle( SFX_TITLE_DETECT ); 1086cdf0e10cSrcweir SetName( GetTitle( SFX_TITLE_APINAME ) ); 1087cdf0e10cSrcweir 1088cdf0e10cSrcweir // Benachrichtigungen 1089cdf0e10cSrcweir Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir 1092cdf0e10cSrcweir //-------------------------------------------------------------------- 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir void SfxObjectShell::SetNamedVisibility_Impl() 1095cdf0e10cSrcweir { 1096cdf0e10cSrcweir if ( !pImp->bIsNamedVisible ) 1097cdf0e10cSrcweir { 1098cdf0e10cSrcweir // Nummer verpassen 1099cdf0e10cSrcweir pImp->bIsNamedVisible = sal_True; 1100cdf0e10cSrcweir // ggf. neue Nummer verpassen 1101cdf0e10cSrcweir if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && !pImp->aTitle.Len() ) 1102cdf0e10cSrcweir { 1103cdf0e10cSrcweir pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex(); 1104cdf0e10cSrcweir Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) ); 1105cdf0e10cSrcweir } 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir 1108cdf0e10cSrcweir SetName( GetTitle(SFX_TITLE_APINAME) ); 1109cdf0e10cSrcweir } 1110cdf0e10cSrcweir 1111cdf0e10cSrcweir void SfxObjectShell::SetNoName() 1112cdf0e10cSrcweir { 1113cdf0e10cSrcweir bHasName = 0; 1114cdf0e10cSrcweir bIsTmp = sal_True; 1115cdf0e10cSrcweir GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() ); 1116cdf0e10cSrcweir } 1117cdf0e10cSrcweir 1118cdf0e10cSrcweir //-------------------------------------------------------------------- 1119cdf0e10cSrcweir 1120cdf0e10cSrcweir void SfxObjectShell::MemoryError() 1121cdf0e10cSrcweir { 1122cdf0e10cSrcweir } 1123cdf0e10cSrcweir 1124cdf0e10cSrcweir //-------------------------------------------------------------------- 1125cdf0e10cSrcweir 1126cdf0e10cSrcweir SfxProgress* SfxObjectShell::GetProgress() const 1127cdf0e10cSrcweir { 1128cdf0e10cSrcweir return pImp->pProgress; 1129cdf0e10cSrcweir } 1130cdf0e10cSrcweir 1131cdf0e10cSrcweir //-------------------------------------------------------------------- 1132cdf0e10cSrcweir 1133cdf0e10cSrcweir void SfxObjectShell::SetProgress_Impl 1134cdf0e10cSrcweir ( 1135cdf0e10cSrcweir SfxProgress *pProgress /* zu startender <SfxProgress> oder 0, falls 1136cdf0e10cSrcweir der Progress zur"uckgesetzt werden soll */ 1137cdf0e10cSrcweir ) 1138cdf0e10cSrcweir 1139cdf0e10cSrcweir /* [Beschreibung] 1140cdf0e10cSrcweir 1141cdf0e10cSrcweir Interne Methode zum setzen oder zur"ucksetzen des Progress-Modes 1142cdf0e10cSrcweir f"ur diese SfxObjectShell. 1143cdf0e10cSrcweir */ 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir { 1146cdf0e10cSrcweir DBG_ASSERT( ( !pImp->pProgress && pProgress ) || 1147cdf0e10cSrcweir ( pImp->pProgress && !pProgress ), 1148cdf0e10cSrcweir "Progress activation/deacitivation mismatch" ); 1149cdf0e10cSrcweir pImp->pProgress = pProgress; 1150cdf0e10cSrcweir } 1151cdf0e10cSrcweir 1152cdf0e10cSrcweir //-------------------------------------------------------------------- 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame ) 1155cdf0e10cSrcweir { 1156cdf0e10cSrcweir SfxApplication* pSfxApp = SFX_APP(); 1157cdf0e10cSrcweir if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame().IsClosing_Impl() ) 1158cdf0e10cSrcweir { 1159cdf0e10cSrcweir SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False ); 1160cdf0e10cSrcweir if ( !pHiddenItem || !pHiddenItem->GetValue() ) 1161cdf0e10cSrcweir { 1162cdf0e10cSrcweir sal_uInt16 nId = pImp->nEventId; 1163cdf0e10cSrcweir pImp->nEventId = 0; 1164cdf0e10cSrcweir if ( nId == SFX_EVENT_OPENDOC ) 1165cdf0e10cSrcweir pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC), this, pFrame->GetFrame().GetController() ), sal_False); 1166cdf0e10cSrcweir else if (nId == SFX_EVENT_CREATEDOC ) 1167cdf0e10cSrcweir pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC), this, pFrame->GetFrame().GetController() ), sal_False); 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir } 1170cdf0e10cSrcweir } 1171cdf0e10cSrcweir 1172cdf0e10cSrcweir //-------------------------------------------------------------------- 1173cdf0e10cSrcweir 1174cdf0e10cSrcweir void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId ) 1175cdf0e10cSrcweir { 1176cdf0e10cSrcweir if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC ) 1177cdf0e10cSrcweir pImp->nEventId = nId; 1178cdf0e10cSrcweir } 1179cdf0e10cSrcweir 1180cdf0e10cSrcweir //-------------------------------------------------------------------- 1181cdf0e10cSrcweir 1182cdf0e10cSrcweir void SfxObjectShell::RegisterTransfer( SfxMedium& rMedium ) 1183cdf0e10cSrcweir /* [Beschreibung ] 1184cdf0e10cSrcweir Alle Medien, die aufgesetzt werden, um Teile eines Dokumentes zu 1185cdf0e10cSrcweir laden, muessen an der zugehoerigen SfxObjectShell angemeldet 1186cdf0e10cSrcweir werden. So kann dokumentweise abgebrochen werden. */ 1187cdf0e10cSrcweir { 1188cdf0e10cSrcweir rMedium.SetReferer( GetMedium()->GetName() ); 1189cdf0e10cSrcweir } 1190cdf0e10cSrcweir 1191cdf0e10cSrcweir //------------------------------------------------------------------------- 1192cdf0e10cSrcweir 1193cdf0e10cSrcweir void SfxObjectShell::PrepareReload( ) 1194cdf0e10cSrcweir /* [Beschreibung ] 1195cdf0e10cSrcweir Wird vor dem Reload gerufen und gibt die Moeglichkeit, 1196cdf0e10cSrcweir etwaige Caches zu leeren. */ 1197cdf0e10cSrcweir { 1198cdf0e10cSrcweir } 1199cdf0e10cSrcweir 1200cdf0e10cSrcweir //------------------------------------------------------------------------- 1201cdf0e10cSrcweir 1202cdf0e10cSrcweir void SfxObjectShell::LockAutoLoad( sal_Bool bLock ) 1203cdf0e10cSrcweir 1204cdf0e10cSrcweir /* Verhindert ein evtl. eintreffendes AutoLoad. Wird auch vor AutoLoad 1205cdf0e10cSrcweir eines umgebenden FrameSet beruecksichtigt. 1206cdf0e10cSrcweir */ 1207cdf0e10cSrcweir 1208cdf0e10cSrcweir { 1209cdf0e10cSrcweir if ( bLock ) 1210cdf0e10cSrcweir ++pImp->nAutoLoadLocks; 1211cdf0e10cSrcweir else 1212cdf0e10cSrcweir --pImp->nAutoLoadLocks; 1213cdf0e10cSrcweir } 1214cdf0e10cSrcweir 1215cdf0e10cSrcweir //------------------------------------------------------------------------- 1216cdf0e10cSrcweir 1217cdf0e10cSrcweir // kann nach frame.cxx gemoved werden, wenn 358+36x-Stand gemerged sind 1218cdf0e10cSrcweir 1219cdf0e10cSrcweir sal_Bool SfxFrame::IsAutoLoadLocked_Impl() const 1220cdf0e10cSrcweir { 1221cdf0e10cSrcweir // sein einges Doc gelockt? 1222cdf0e10cSrcweir const SfxObjectShell* pObjSh = GetCurrentDocument(); 1223cdf0e10cSrcweir if ( !pObjSh || !pObjSh->IsAutoLoadLocked() ) 1224cdf0e10cSrcweir return sal_False; 1225cdf0e10cSrcweir 1226cdf0e10cSrcweir // seine Childs gelockt? 1227cdf0e10cSrcweir for ( sal_uInt16 n = GetChildFrameCount(); n--; ) 1228cdf0e10cSrcweir if ( !GetChildFrame(n)->IsAutoLoadLocked_Impl() ) 1229cdf0e10cSrcweir return sal_False; 1230cdf0e10cSrcweir 1231cdf0e10cSrcweir // sonst ist AutoLoad erlaubt 1232cdf0e10cSrcweir return sal_True; 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir //------------------------------------------------------------------------- 1236cdf0e10cSrcweir 1237cdf0e10cSrcweir sal_Bool SfxObjectShell::IsAutoLoadLocked() const 1238cdf0e10cSrcweir 1239cdf0e10cSrcweir /* Liefert, ob ein eintreffendes AutoLoad ausgefuehrt werden darf. Wird auch 1240cdf0e10cSrcweir vor AutoLoad eines umgebenden FrameSet beruecksichtigt. 1241cdf0e10cSrcweir */ 1242cdf0e10cSrcweir 1243cdf0e10cSrcweir { 1244cdf0e10cSrcweir return !IsReadOnly() || pImp->nAutoLoadLocks > 0; 1245cdf0e10cSrcweir } 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir //------------------------------------------------------------------------- 1248cdf0e10cSrcweir void SfxObjectShell::BreakMacroSign_Impl( sal_Bool bBreakMacroSign ) 1249cdf0e10cSrcweir { 1250cdf0e10cSrcweir pImp->m_bMacroSignBroken = bBreakMacroSign; 1251cdf0e10cSrcweir } 1252cdf0e10cSrcweir 1253cdf0e10cSrcweir //------------------------------------------------------------------------- 1254cdf0e10cSrcweir void SfxObjectShell::CheckSecurityOnLoading_Impl() 1255cdf0e10cSrcweir { 1256cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xInteraction; 1257cdf0e10cSrcweir if ( GetMedium() ) 1258cdf0e10cSrcweir xInteraction = GetMedium()->GetInteractionHandler(); 1259cdf0e10cSrcweir 1260cdf0e10cSrcweir // check if there is a broken signature... 1261cdf0e10cSrcweir CheckForBrokenDocSignatures_Impl( xInteraction ); 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir CheckEncryption_Impl( xInteraction ); 1264cdf0e10cSrcweir 1265cdf0e10cSrcweir // check macro security 1266cdf0e10cSrcweir pImp->aMacroMode.checkMacrosOnLoading( xInteraction ); 1267cdf0e10cSrcweir } 1268cdf0e10cSrcweir 1269cdf0e10cSrcweir //------------------------------------------------------------------------- 1270cdf0e10cSrcweir void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler ) 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir ::rtl::OUString aVersion; 1273cdf0e10cSrcweir sal_Bool bIsEncrypted = sal_False; 1274cdf0e10cSrcweir sal_Bool bHasNonEncrypted = sal_False; 1275cdf0e10cSrcweir 1276cdf0e10cSrcweir try 1277cdf0e10cSrcweir { 1278cdf0e10cSrcweir uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW ); 1279cdf0e10cSrcweir xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion; 1280cdf0e10cSrcweir xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasEncryptedEntries" ) ) ) >>= bIsEncrypted; 1281cdf0e10cSrcweir xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasNonEncryptedEntries" ) ) ) >>= bHasNonEncrypted; 1282cdf0e10cSrcweir } 1283cdf0e10cSrcweir catch( uno::Exception& ) 1284cdf0e10cSrcweir { 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir 1287cdf0e10cSrcweir if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 ) 1288cdf0e10cSrcweir { 1289cdf0e10cSrcweir // this is ODF1.2 or later 1290cdf0e10cSrcweir if ( bIsEncrypted && bHasNonEncrypted ) 1291cdf0e10cSrcweir { 1292cdf0e10cSrcweir if ( !pImp->m_bIncomplEncrWarnShown ) 1293cdf0e10cSrcweir { 1294cdf0e10cSrcweir // this is an encrypted document with nonencrypted streams inside, show the warning 1295cdf0e10cSrcweir ::com::sun::star::task::ErrorCodeRequest aErrorCode; 1296cdf0e10cSrcweir aErrorCode.ErrCode = ERRCODE_SFX_INCOMPLETE_ENCRYPTION; 1297cdf0e10cSrcweir 1298cdf0e10cSrcweir SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False ); 1299cdf0e10cSrcweir pImp->m_bIncomplEncrWarnShown = sal_True; 1300cdf0e10cSrcweir } 1301cdf0e10cSrcweir 1302cdf0e10cSrcweir // broken signatures imply no macro execution at all 1303cdf0e10cSrcweir pImp->aMacroMode.disallowMacroExecution(); 1304cdf0e10cSrcweir } 1305cdf0e10cSrcweir } 1306cdf0e10cSrcweir } 1307cdf0e10cSrcweir 1308cdf0e10cSrcweir //------------------------------------------------------------------------- 1309cdf0e10cSrcweir void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler ) 1310cdf0e10cSrcweir { 1311cdf0e10cSrcweir sal_Int16 nSignatureState = GetDocumentSignatureState(); 1312cdf0e10cSrcweir bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN ); 1313cdf0e10cSrcweir if ( !bSignatureBroken ) 1314cdf0e10cSrcweir return; 1315cdf0e10cSrcweir 1316cdf0e10cSrcweir pImp->showBrokenSignatureWarning( xHandler ); 1317cdf0e10cSrcweir 1318cdf0e10cSrcweir // broken signatures imply no macro execution at all 1319cdf0e10cSrcweir pImp->aMacroMode.disallowMacroExecution(); 1320cdf0e10cSrcweir } 1321cdf0e10cSrcweir 1322cdf0e10cSrcweir //------------------------------------------------------------------------- 1323cdf0e10cSrcweir void SfxObjectShell::SetAutoLoad( 1324cdf0e10cSrcweir const INetURLObject& rUrl, sal_uInt32 nTime, sal_Bool bReload ) 1325cdf0e10cSrcweir { 1326cdf0e10cSrcweir if ( pImp->pReloadTimer ) 1327cdf0e10cSrcweir DELETEZ(pImp->pReloadTimer); 1328cdf0e10cSrcweir if ( bReload ) 1329cdf0e10cSrcweir { 1330cdf0e10cSrcweir pImp->pReloadTimer = new AutoReloadTimer_Impl( 1331cdf0e10cSrcweir rUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ), 1332cdf0e10cSrcweir nTime, bReload, this ); 1333cdf0e10cSrcweir pImp->pReloadTimer->Start(); 1334cdf0e10cSrcweir } 1335cdf0e10cSrcweir } 1336cdf0e10cSrcweir 1337cdf0e10cSrcweir sal_Bool SfxObjectShell::IsLoadingFinished() const 1338cdf0e10cSrcweir { 1339cdf0e10cSrcweir return ( pImp->nLoadedFlags == SFX_LOADED_ALL ); 1340cdf0e10cSrcweir } 1341cdf0e10cSrcweir 1342cdf0e10cSrcweir void impl_addToModelCollection(const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel); 1343cdf0e10cSrcweir void SfxObjectShell::InitOwnModel_Impl() 1344cdf0e10cSrcweir { 1345cdf0e10cSrcweir if ( !pImp->bModelInitialized ) 1346cdf0e10cSrcweir { 1347cdf0e10cSrcweir SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False); 1348cdf0e10cSrcweir if ( pSalvageItem ) 1349cdf0e10cSrcweir { 1350cdf0e10cSrcweir pImp->aTempName = pMedium->GetPhysicalName(); 1351cdf0e10cSrcweir pMedium->GetItemSet()->ClearItem( SID_DOC_SALVAGE ); 1352cdf0e10cSrcweir pMedium->GetItemSet()->ClearItem( SID_FILE_NAME ); 1353cdf0e10cSrcweir pMedium->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetOrigURL() ) ); 1354cdf0e10cSrcweir } 1355cdf0e10cSrcweir else 1356cdf0e10cSrcweir { 1357cdf0e10cSrcweir pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL ); 1358cdf0e10cSrcweir pMedium->GetItemSet()->ClearItem( SID_DOCUMENT ); 1359cdf0e10cSrcweir } 1360cdf0e10cSrcweir 1361cdf0e10cSrcweir pMedium->GetItemSet()->ClearItem( SID_REFERER ); 1362cdf0e10cSrcweir uno::Reference< frame::XModel > xModel ( GetModel(), uno::UNO_QUERY ); 1363cdf0e10cSrcweir if ( xModel.is() ) 1364cdf0e10cSrcweir { 1365cdf0e10cSrcweir ::rtl::OUString aURL = GetMedium()->GetOrigURL(); 1366cdf0e10cSrcweir SfxItemSet *pSet = GetMedium()->GetItemSet(); 1367cdf0e10cSrcweir if ( !GetMedium()->IsReadOnly() ) 1368cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 1369cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs; 1370cdf0e10cSrcweir TransformItems( SID_OPENDOC, *pSet, aArgs ); 1371cdf0e10cSrcweir xModel->attachResource( aURL, aArgs ); 1372cdf0e10cSrcweir impl_addToModelCollection(xModel); 1373cdf0e10cSrcweir } 1374cdf0e10cSrcweir 1375cdf0e10cSrcweir pImp->bModelInitialized = sal_True; 1376cdf0e10cSrcweir } 1377cdf0e10cSrcweir } 1378cdf0e10cSrcweir 1379cdf0e10cSrcweir void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags ) 1380cdf0e10cSrcweir { 1381cdf0e10cSrcweir sal_Bool bSetModifiedTRUE = sal_False; 1382cdf0e10cSrcweir SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False ); 1383cdf0e10cSrcweir if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) 1384cdf0e10cSrcweir && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT )) 1385cdf0e10cSrcweir { 1386cdf0e10cSrcweir pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT; 1387cdf0e10cSrcweir ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes(); 1388cdf0e10cSrcweir pImp->bImportDone = sal_True; 1389cdf0e10cSrcweir if( !IsAbortingImport() ) 1390cdf0e10cSrcweir PositionView_Impl(); 1391cdf0e10cSrcweir 1392cdf0e10cSrcweir if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() ) 1393cdf0e10cSrcweir SetReadOnly(); 1394cdf0e10cSrcweir 1395cdf0e10cSrcweir // Salvage 1396cdf0e10cSrcweir if ( pSalvageItem ) 1397cdf0e10cSrcweir bSetModifiedTRUE = sal_True; 1398cdf0e10cSrcweir 1399cdf0e10cSrcweir if ( !IsEnableSetModified() ) 1400cdf0e10cSrcweir EnableSetModified( sal_True ); 1401cdf0e10cSrcweir 1402cdf0e10cSrcweir if( !bSetModifiedTRUE && IsEnableSetModified() ) 1403cdf0e10cSrcweir SetModified( sal_False ); 1404cdf0e10cSrcweir 1405cdf0e10cSrcweir CheckSecurityOnLoading_Impl(); 1406cdf0e10cSrcweir 1407cdf0e10cSrcweir bHasName = sal_True; // the document is loaded, so the name should already available 1408cdf0e10cSrcweir GetTitle( SFX_TITLE_DETECT ); 1409cdf0e10cSrcweir InitOwnModel_Impl(); 1410cdf0e10cSrcweir pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT; 1411cdf0e10cSrcweir } 1412cdf0e10cSrcweir 1413cdf0e10cSrcweir if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES ) 1414cdf0e10cSrcweir && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES )) 1415cdf0e10cSrcweir { 1416cdf0e10cSrcweir pImp->nFlagsInProgress |= SFX_LOADED_IMAGES; 1417cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps( 1418cdf0e10cSrcweir getDocProperties()); 1419cdf0e10cSrcweir ::rtl::OUString url(xDocProps->getAutoloadURL()); 1420cdf0e10cSrcweir sal_Int32 delay(xDocProps->getAutoloadSecs()); 1421cdf0e10cSrcweir SetAutoLoad( INetURLObject(url), delay * 1000, 1422cdf0e10cSrcweir (delay > 0) || url.getLength() ); 1423cdf0e10cSrcweir if( !bSetModifiedTRUE && IsEnableSetModified() ) 1424cdf0e10cSrcweir SetModified( sal_False ); 1425cdf0e10cSrcweir Invalidate( SID_SAVEASDOC ); 1426cdf0e10cSrcweir pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES; 1427cdf0e10cSrcweir } 1428cdf0e10cSrcweir 1429cdf0e10cSrcweir pImp->nLoadedFlags |= nFlags; 1430cdf0e10cSrcweir 1431cdf0e10cSrcweir if ( !pImp->nFlagsInProgress ) 1432cdf0e10cSrcweir { 1433cdf0e10cSrcweir // in case of reentrance calls the first called FinishedLoading() call on the stack 1434cdf0e10cSrcweir // should do the notification, in result the notification is done when all the FinishedLoading() calls are finished 1435cdf0e10cSrcweir 1436cdf0e10cSrcweir if ( bSetModifiedTRUE ) 1437cdf0e10cSrcweir SetModified( sal_True ); 1438cdf0e10cSrcweir else 1439cdf0e10cSrcweir SetModified( sal_False ); 1440cdf0e10cSrcweir 1441cdf0e10cSrcweir if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) ) 1442cdf0e10cSrcweir { 1443cdf0e10cSrcweir SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False); 1444cdf0e10cSrcweir sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue(); 1445cdf0e10cSrcweir 1446cdf0e10cSrcweir // closing the streams on loading should be under control of SFX! 1447cdf0e10cSrcweir DBG_ASSERT( pMedium->IsOpen(), "Don't close the medium when loading documents!" ); 1448cdf0e10cSrcweir 1449cdf0e10cSrcweir if ( bTemplate ) 1450cdf0e10cSrcweir { 1451cdf0e10cSrcweir TemplateDisconnectionAfterLoad(); 1452cdf0e10cSrcweir } 1453cdf0e10cSrcweir else 1454cdf0e10cSrcweir { 1455cdf0e10cSrcweir // if a readonly medium has storage then it's stream is already based on temporary file 1456cdf0e10cSrcweir if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() ) 1457cdf0e10cSrcweir // don't lock file opened read only 1458cdf0e10cSrcweir pMedium->CloseInStream(); 1459cdf0e10cSrcweir } 1460cdf0e10cSrcweir } 1461cdf0e10cSrcweir 1462cdf0e10cSrcweir SetInitialized_Impl( false ); 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir // Title is not available until loading has finished 1465cdf0e10cSrcweir Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) ); 1466cdf0e10cSrcweir if ( pImp->nEventId ) 1467cdf0e10cSrcweir PostActivateEvent_Impl(SfxViewFrame::GetFirst(this)); 1468cdf0e10cSrcweir } 1469cdf0e10cSrcweir } 1470cdf0e10cSrcweir 1471cdf0e10cSrcweir //------------------------------------------------------------------------- 1472cdf0e10cSrcweir extern void SetTemplate_Impl( const String&, const String&, SfxObjectShell* ); 1473cdf0e10cSrcweir 1474cdf0e10cSrcweir void SfxObjectShell::TemplateDisconnectionAfterLoad() 1475cdf0e10cSrcweir { 1476cdf0e10cSrcweir // document is created from a template 1477cdf0e10cSrcweir //TODO/LATER: should the templates always be XML docs! 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir SfxMedium* pTmpMedium = pMedium; 1480cdf0e10cSrcweir if ( pTmpMedium ) 1481cdf0e10cSrcweir { 1482cdf0e10cSrcweir String aName( pTmpMedium->GetName() ); 1483cdf0e10cSrcweir SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False); 1484cdf0e10cSrcweir String aTemplateName; 1485cdf0e10cSrcweir if ( pTemplNamItem ) 1486cdf0e10cSrcweir aTemplateName = pTemplNamItem->GetValue(); 1487cdf0e10cSrcweir else 1488cdf0e10cSrcweir { 1489cdf0e10cSrcweir // !TODO/LATER: what's this?! 1490cdf0e10cSrcweir // Interaktiv ( DClick, Contextmenu ) kommt kein Langname mit 1491cdf0e10cSrcweir aTemplateName = getDocProperties()->getTitle(); 1492cdf0e10cSrcweir if ( !aTemplateName.Len() ) 1493cdf0e10cSrcweir { 1494cdf0e10cSrcweir INetURLObject aURL( aName ); 1495cdf0e10cSrcweir aURL.CutExtension(); 1496cdf0e10cSrcweir aTemplateName = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 1497cdf0e10cSrcweir } 1498cdf0e10cSrcweir } 1499cdf0e10cSrcweir 1500cdf0e10cSrcweir // set medium to noname 1501cdf0e10cSrcweir pTmpMedium->SetName( String(), sal_True ); 1502cdf0e10cSrcweir pTmpMedium->Init_Impl(); 1503cdf0e10cSrcweir 1504cdf0e10cSrcweir // drop resource 1505cdf0e10cSrcweir SetNoName(); 1506cdf0e10cSrcweir InvalidateName(); 1507cdf0e10cSrcweir 1508cdf0e10cSrcweir if( IsPackageStorageFormat_Impl( *pTmpMedium ) ) 1509cdf0e10cSrcweir { 1510cdf0e10cSrcweir // untitled document must be based on temporary storage 1511cdf0e10cSrcweir // the medium should not dispose the storage in this case 1512cdf0e10cSrcweir uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage(); 1513cdf0e10cSrcweir GetStorage()->copyToStorage( xTmpStor ); 1514cdf0e10cSrcweir 1515cdf0e10cSrcweir // the medium should disconnect from the original location 1516cdf0e10cSrcweir // the storage should not be disposed since the document is still 1517cdf0e10cSrcweir // based on it, but in DoSaveCompleted it will be disposed 1518cdf0e10cSrcweir pTmpMedium->CanDisposeStorage_Impl( sal_False ); 1519cdf0e10cSrcweir pTmpMedium->Close(); 1520cdf0e10cSrcweir 1521cdf0e10cSrcweir // setting the new storage the medium will be based on 1522cdf0e10cSrcweir pTmpMedium->SetStorage_Impl( xTmpStor ); 1523cdf0e10cSrcweir 1524cdf0e10cSrcweir ForgetMedium(); 1525cdf0e10cSrcweir if( !DoSaveCompleted( pTmpMedium ) ) 1526cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1527cdf0e10cSrcweir else 1528cdf0e10cSrcweir { 1529cdf0e10cSrcweir SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False ); 1530cdf0e10cSrcweir sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False; 1531cdf0e10cSrcweir 1532cdf0e10cSrcweir if ( !bSalvage ) 1533cdf0e10cSrcweir { 1534cdf0e10cSrcweir // some further initializations for templates 1535cdf0e10cSrcweir SetTemplate_Impl( aName, aTemplateName, this ); 1536cdf0e10cSrcweir } 1537cdf0e10cSrcweir 1538cdf0e10cSrcweir // the medium should not dispose the storage, DoSaveCompleted() has let it to do so 1539cdf0e10cSrcweir pTmpMedium->CanDisposeStorage_Impl( sal_False ); 1540cdf0e10cSrcweir } 1541cdf0e10cSrcweir } 1542cdf0e10cSrcweir else 1543cdf0e10cSrcweir { 1544cdf0e10cSrcweir // some further initializations for templates 1545cdf0e10cSrcweir SetTemplate_Impl( aName, aTemplateName, this ); 1546cdf0e10cSrcweir pTmpMedium->CreateTempFile( sal_True ); 1547cdf0e10cSrcweir } 1548cdf0e10cSrcweir 1549cdf0e10cSrcweir // templates are never readonly 1550cdf0e10cSrcweir pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY ); 1551cdf0e10cSrcweir pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True ); 1552cdf0e10cSrcweir 1553cdf0e10cSrcweir // notifications about possible changes in readonly state and document info 1554cdf0e10cSrcweir Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); 1555cdf0e10cSrcweir 1556cdf0e10cSrcweir // created untitled document can't be modified 1557cdf0e10cSrcweir SetModified( sal_False ); 1558cdf0e10cSrcweir } 1559cdf0e10cSrcweir } 1560cdf0e10cSrcweir 1561cdf0e10cSrcweir //------------------------------------------------------------------------- 1562cdf0e10cSrcweir 1563cdf0e10cSrcweir void SfxObjectShell::PositionView_Impl() 1564cdf0e10cSrcweir { 1565cdf0e10cSrcweir MarkData_Impl *pMark = Get_Impl()->pMarkData; 1566cdf0e10cSrcweir if( pMark ) 1567cdf0e10cSrcweir { 1568cdf0e10cSrcweir SfxViewShell* pSh = pMark->pFrame->GetViewShell(); 1569cdf0e10cSrcweir if( pMark->aUserData.Len() ) 1570cdf0e10cSrcweir pSh->ReadUserData( pMark->aUserData, sal_True ); 1571cdf0e10cSrcweir else if( pMark->aMark.Len() ) 1572cdf0e10cSrcweir pSh->JumpToMark( pMark->aMark ); 1573cdf0e10cSrcweir DELETEZ( Get_Impl()->pMarkData ); 1574cdf0e10cSrcweir } 1575cdf0e10cSrcweir } 1576cdf0e10cSrcweir 1577cdf0e10cSrcweir //------------------------------------------------------------------------- 1578cdf0e10cSrcweir 1579cdf0e10cSrcweir sal_Bool SfxObjectShell::IsLoading() const 1580cdf0e10cSrcweir /* [Beschreibung ] 1581cdf0e10cSrcweir Has FinishedLoading been called? */ 1582cdf0e10cSrcweir { 1583cdf0e10cSrcweir return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ); 1584cdf0e10cSrcweir } 1585cdf0e10cSrcweir 1586cdf0e10cSrcweir //------------------------------------------------------------------------- 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir void SfxObjectShell::CancelTransfers() 1589cdf0e10cSrcweir /* [Beschreibung ] 1590cdf0e10cSrcweir Hier koennen Transfers gecanceled werden, die nicht mit 1591cdf0e10cSrcweir RegisterTransfer registiert wurden */ 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir if( ( pImp->nLoadedFlags & SFX_LOADED_ALL ) != SFX_LOADED_ALL ) 1594cdf0e10cSrcweir { 1595cdf0e10cSrcweir AbortImport(); 1596cdf0e10cSrcweir if( IsLoading() ) 1597cdf0e10cSrcweir FinishedLoading( SFX_LOADED_ALL ); 1598cdf0e10cSrcweir 1599cdf0e10cSrcweir /* 1600cdf0e10cSrcweir SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 1601cdf0e10cSrcweir while( pFrame ) 1602cdf0e10cSrcweir { 1603cdf0e10cSrcweir pFrame->CancelTransfers(); 1604cdf0e10cSrcweir pFrame = SfxViewFrame::GetNext( *pFrame, this ); 1605cdf0e10cSrcweir }*/ 1606cdf0e10cSrcweir } 1607cdf0e10cSrcweir } 1608cdf0e10cSrcweir 1609cdf0e10cSrcweir //------------------------------------------------------------------------- 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir AutoReloadTimer_Impl::AutoReloadTimer_Impl( 1612cdf0e10cSrcweir const String& rURL, sal_uInt32 nTime, sal_Bool bReloadP, SfxObjectShell* pSh ) 1613cdf0e10cSrcweir : aUrl( rURL ), bReload( bReloadP ), pObjSh( pSh ) 1614cdf0e10cSrcweir { 1615cdf0e10cSrcweir SetTimeout( nTime ); 1616cdf0e10cSrcweir } 1617cdf0e10cSrcweir 1618cdf0e10cSrcweir //------------------------------------------------------------------------- 1619cdf0e10cSrcweir 1620cdf0e10cSrcweir void AutoReloadTimer_Impl::Timeout() 1621cdf0e10cSrcweir { 1622cdf0e10cSrcweir SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjSh ); 1623cdf0e10cSrcweir 1624cdf0e10cSrcweir if ( pFrame ) 1625cdf0e10cSrcweir { 1626cdf0e10cSrcweir // momentan nicht m"oglich/sinnvoll? 1627cdf0e10cSrcweir if ( !pObjSh->CanReload_Impl() || pObjSh->IsAutoLoadLocked() || Application::IsUICaptured() ) 1628cdf0e10cSrcweir { 1629cdf0e10cSrcweir // erneuten Versuch erlauben 1630cdf0e10cSrcweir Start(); 1631cdf0e10cSrcweir return; 1632cdf0e10cSrcweir } 1633cdf0e10cSrcweir 1634cdf0e10cSrcweir SfxAllItemSet aSet( SFX_APP()->GetPool() ); 1635cdf0e10cSrcweir aSet.Put( SfxBoolItem( SID_AUTOLOAD, sal_True ) ); 1636cdf0e10cSrcweir if ( aUrl.Len() ) 1637cdf0e10cSrcweir aSet.Put( SfxStringItem( SID_FILE_NAME, aUrl ) ); 1638cdf0e10cSrcweir SfxRequest aReq( SID_RELOAD, 0, aSet ); 1639cdf0e10cSrcweir pObjSh->Get_Impl()->pReloadTimer = 0; 1640cdf0e10cSrcweir delete this; 1641cdf0e10cSrcweir pFrame->ExecReload_Impl( aReq ); 1642cdf0e10cSrcweir return; 1643cdf0e10cSrcweir } 1644cdf0e10cSrcweir 1645cdf0e10cSrcweir pObjSh->Get_Impl()->pReloadTimer = 0; 1646cdf0e10cSrcweir delete this; 1647cdf0e10cSrcweir } 1648cdf0e10cSrcweir 1649cdf0e10cSrcweir SfxModule* SfxObjectShell::GetModule() const 1650cdf0e10cSrcweir { 1651cdf0e10cSrcweir return GetFactory().GetModule(); 1652cdf0e10cSrcweir } 1653cdf0e10cSrcweir 1654cdf0e10cSrcweir ErrCode SfxObjectShell::CallBasic( const String& rMacro, 1655cdf0e10cSrcweir const String& rBasic, SbxArray* pArgs, 1656cdf0e10cSrcweir SbxValue* pRet ) 1657cdf0e10cSrcweir { 1658cdf0e10cSrcweir SfxApplication* pApp = SFX_APP(); 1659cdf0e10cSrcweir if( pApp->GetName() != rBasic ) 1660cdf0e10cSrcweir { 1661cdf0e10cSrcweir if ( !AdjustMacroMode( String() ) ) 1662cdf0e10cSrcweir return ERRCODE_IO_ACCESSDENIED; 1663cdf0e10cSrcweir } 1664cdf0e10cSrcweir 1665cdf0e10cSrcweir BasicManager *pMgr = GetBasicManager(); 1666cdf0e10cSrcweir if( pApp->GetName() == rBasic ) 1667cdf0e10cSrcweir pMgr = pApp->GetBasicManager(); 1668cdf0e10cSrcweir ErrCode nRet = SfxApplication::CallBasic( rMacro, pMgr, pArgs, pRet ); 1669cdf0e10cSrcweir return nRet; 1670cdf0e10cSrcweir } 1671cdf0e10cSrcweir 1672cdf0e10cSrcweir namespace 1673cdf0e10cSrcweir { 1674cdf0e10cSrcweir static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext ) 1675cdf0e10cSrcweir { 1676cdf0e10cSrcweir try 1677cdf0e10cSrcweir { 1678cdf0e10cSrcweir Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY ); 1679cdf0e10cSrcweir if ( !xScripts.is() ) 1680cdf0e10cSrcweir { 1681cdf0e10cSrcweir Reference< XScriptInvocationContext > xContext( _rxScriptContext, UNO_QUERY_THROW ); 1682cdf0e10cSrcweir xScripts.set( xContext->getScriptContainer(), UNO_SET_THROW ); 1683cdf0e10cSrcweir } 1684cdf0e10cSrcweir 1685cdf0e10cSrcweir return xScripts->getAllowMacroExecution(); 1686cdf0e10cSrcweir } 1687cdf0e10cSrcweir catch( const Exception& ) 1688cdf0e10cSrcweir { 1689cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1690cdf0e10cSrcweir } 1691cdf0e10cSrcweir return false; 1692cdf0e10cSrcweir } 1693cdf0e10cSrcweir } 1694cdf0e10cSrcweir 1695cdf0e10cSrcweir ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL, 1696cdf0e10cSrcweir const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError ) 1697cdf0e10cSrcweir { 1698cdf0e10cSrcweir OSL_TRACE( "in CallXScript" ); 1699cdf0e10cSrcweir ErrCode nErr = ERRCODE_NONE; 1700cdf0e10cSrcweir 1701cdf0e10cSrcweir bool bCaughtException = false; 1702cdf0e10cSrcweir Any aException; 1703cdf0e10cSrcweir try 1704cdf0e10cSrcweir { 170515daf392SDamjan Jovanovic uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); 170615daf392SDamjan Jovanovic Reference< uri::XUriReferenceFactory > xFac ( 170715daf392SDamjan Jovanovic xServiceManager->createInstance( rtl::OUString::createFromAscii( 170815daf392SDamjan Jovanovic "com.sun.star.uri.UriReferenceFactory") ) , UNO_QUERY_THROW ); 170915daf392SDamjan Jovanovic Reference< uri::XVndSunStarScriptUrlReference > xScriptUri( xFac->parse( _rScriptURL ), UNO_QUERY_THROW ); 1710*aea52546SArrigo Marchiori if ( !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) ) 171115daf392SDamjan Jovanovic return ERRCODE_IO_ACCESSDENIED; 171215daf392SDamjan Jovanovic 1713cdf0e10cSrcweir // obtain/create a script provider 1714cdf0e10cSrcweir Reference< provider::XScriptProvider > xScriptProvider; 1715cdf0e10cSrcweir Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY ); 1716cdf0e10cSrcweir if ( xSPS.is() ) 1717cdf0e10cSrcweir xScriptProvider.set( xSPS->getScriptProvider() ); 1718cdf0e10cSrcweir 1719cdf0e10cSrcweir if ( !xScriptProvider.is() ) 1720cdf0e10cSrcweir { 1721cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 1722cdf0e10cSrcweir Reference< provider::XScriptProviderFactory > xScriptProviderFactory( 1723cdf0e10cSrcweir aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW ); 1724cdf0e10cSrcweir xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW ); 1725cdf0e10cSrcweir } 1726cdf0e10cSrcweir 1727cdf0e10cSrcweir // ry to protect the invocation context's undo manager (if present), just in case the script tampers with it 1728cdf0e10cSrcweir ::framework::DocumentUndoGuard aUndoGuard( _rxScriptContext.get() ); 1729cdf0e10cSrcweir 1730cdf0e10cSrcweir // obtain the script, and execute it 1731cdf0e10cSrcweir Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW ); 1732cdf0e10cSrcweir aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam ); 1733cdf0e10cSrcweir } 1734cdf0e10cSrcweir catch ( const uno::Exception& ) 1735cdf0e10cSrcweir { 1736cdf0e10cSrcweir aException = ::cppu::getCaughtException(); 1737cdf0e10cSrcweir bCaughtException = sal_True; 1738cdf0e10cSrcweir nErr = ERRCODE_BASIC_INTERNAL_ERROR; 1739cdf0e10cSrcweir } 1740cdf0e10cSrcweir 1741cdf0e10cSrcweir if ( bCaughtException && bRaiseError ) 1742cdf0e10cSrcweir { 1743cdf0e10cSrcweir ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg; 1744cdf0e10cSrcweir SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); 1745cdf0e10cSrcweir if ( pFact ) 1746cdf0e10cSrcweir pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) ); 1747cdf0e10cSrcweir OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" ); 1748cdf0e10cSrcweir 1749cdf0e10cSrcweir if ( pScriptErrDlg.get() ) 1750cdf0e10cSrcweir pScriptErrDlg->Execute(); 1751cdf0e10cSrcweir } 1752cdf0e10cSrcweir 1753cdf0e10cSrcweir OSL_TRACE( "leaving CallXScript" ); 1754cdf0e10cSrcweir return nErr; 1755cdf0e10cSrcweir } 1756cdf0e10cSrcweir 1757cdf0e10cSrcweir // perhaps rename to CallScript once we get rid of the existing CallScript 1758cdf0e10cSrcweir // and Call, CallBasic, CallStarBasic methods 1759cdf0e10cSrcweir ErrCode SfxObjectShell::CallXScript( const String& rScriptURL, 1760cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& 1761cdf0e10cSrcweir aParams, 1762cdf0e10cSrcweir ::com::sun::star::uno::Any& aRet, 1763cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex, 1764cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam 1765cdf0e10cSrcweir , bool bRaiseError ) 1766cdf0e10cSrcweir { 1767cdf0e10cSrcweir return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError ); 1768cdf0e10cSrcweir } 1769cdf0e10cSrcweir 1770cdf0e10cSrcweir //------------------------------------------------------------------------- 1771cdf0e10cSrcweir SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ ) 1772cdf0e10cSrcweir { 1773cdf0e10cSrcweir return pSelf; 1774cdf0e10cSrcweir } 1775cdf0e10cSrcweir 1776cdf0e10cSrcweir SfxObjectShellFlags SfxObjectShell::GetFlags() const 1777cdf0e10cSrcweir { 1778cdf0e10cSrcweir if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED ) 1779cdf0e10cSrcweir pImp->eFlags = GetFactory().GetFlags(); 1780cdf0e10cSrcweir return pImp->eFlags; 1781cdf0e10cSrcweir } 1782cdf0e10cSrcweir 1783cdf0e10cSrcweir void SfxObjectShell::SetFlags( SfxObjectShellFlags eFlags ) 1784cdf0e10cSrcweir { 1785cdf0e10cSrcweir pImp->eFlags = eFlags; 1786cdf0e10cSrcweir } 1787cdf0e10cSrcweir 1788cdf0e10cSrcweir void SfxHeaderAttributes_Impl::SetAttributes() 1789cdf0e10cSrcweir { 1790cdf0e10cSrcweir bAlert = sal_True; 1791cdf0e10cSrcweir SvKeyValue aPair; 1792cdf0e10cSrcweir for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont; 1793cdf0e10cSrcweir bCont = xIter->GetNext( aPair ) ) 1794cdf0e10cSrcweir SetAttribute( aPair ); 1795cdf0e10cSrcweir } 1796cdf0e10cSrcweir 1797cdf0e10cSrcweir void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV ) 1798cdf0e10cSrcweir { 1799cdf0e10cSrcweir String aValue = rKV.GetValue(); 1800cdf0e10cSrcweir if( rKV.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL && rKV.GetValue().Len() ) 1801cdf0e10cSrcweir { 1802cdf0e10cSrcweir sal_uInt32 nTime = aValue.GetToken( 0, ';' ).ToInt32() ; 1803cdf0e10cSrcweir String aURL = aValue.GetToken( 1, ';' ); 1804cdf0e10cSrcweir aURL.EraseTrailingChars().EraseLeadingChars(); 1805cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps( 1806cdf0e10cSrcweir pDoc->getDocProperties()); 1807cdf0e10cSrcweir if( aURL.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL ) 1808cdf0e10cSrcweir { 1809cdf0e10cSrcweir INetURLObject aObj; 1810cdf0e10cSrcweir INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.Copy( 4 ), &aObj ); 1811cdf0e10cSrcweir xDocProps->setAutoloadURL( 1812cdf0e10cSrcweir aObj.GetMainURL( INetURLObject::NO_DECODE ) ); 1813cdf0e10cSrcweir } 1814cdf0e10cSrcweir try 1815cdf0e10cSrcweir { 1816cdf0e10cSrcweir xDocProps->setAutoloadSecs( nTime ); 1817cdf0e10cSrcweir } 1818cdf0e10cSrcweir catch (lang::IllegalArgumentException &) 1819cdf0e10cSrcweir { 1820cdf0e10cSrcweir // ignore 1821cdf0e10cSrcweir } 1822cdf0e10cSrcweir } 1823cdf0e10cSrcweir else if( rKV.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL ) 1824cdf0e10cSrcweir { 1825cdf0e10cSrcweir DateTime aDateTime; 1826cdf0e10cSrcweir if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) ) 1827cdf0e10cSrcweir { 1828cdf0e10cSrcweir aDateTime.ConvertToLocalTime(); 1829cdf0e10cSrcweir pDoc->GetMedium()->SetExpired_Impl( aDateTime ); 1830cdf0e10cSrcweir } 1831cdf0e10cSrcweir else 1832cdf0e10cSrcweir { 1833cdf0e10cSrcweir // DBG_ERROR( "Schlechtes ::com::sun::star::util::DateTime fuer Expired" ); 1834cdf0e10cSrcweir pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) ); 1835cdf0e10cSrcweir } 1836cdf0e10cSrcweir } 1837cdf0e10cSrcweir else if( rKV.GetKey().CompareIgnoreCaseToAscii( "content-type" ) == COMPARE_EQUAL ) 1838cdf0e10cSrcweir { 1839cdf0e10cSrcweir ::rtl::OString sContent = ::rtl::OUStringToOString( aValue, RTL_TEXTENCODING_ASCII_US ); 1840cdf0e10cSrcweir ByteString sType, sSubType; 1841cdf0e10cSrcweir INetContentTypeParameterList aParameters; 1842cdf0e10cSrcweir 1843cdf0e10cSrcweir if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) ) 1844cdf0e10cSrcweir { 1845cdf0e10cSrcweir const INetContentTypeParameter * pCharset = aParameters.find("charset"); 1846cdf0e10cSrcweir if (pCharset != 0) 1847cdf0e10cSrcweir pDoc->GetMedium()->SetCharset( pCharset->m_sValue ); 1848cdf0e10cSrcweir } 1849cdf0e10cSrcweir } 1850cdf0e10cSrcweir } 1851cdf0e10cSrcweir 1852cdf0e10cSrcweir void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV ) 1853cdf0e10cSrcweir { 1854cdf0e10cSrcweir xIter->Append( rKV ); 1855cdf0e10cSrcweir if( bAlert ) SetAttribute( rKV ); 1856cdf0e10cSrcweir } 1857cdf0e10cSrcweir 1858cdf0e10cSrcweir SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes() 1859cdf0e10cSrcweir { 1860cdf0e10cSrcweir if( !pImp->xHeaderAttributes.Is() ) 1861cdf0e10cSrcweir { 1862cdf0e10cSrcweir DBG_ASSERT( pMedium, "Kein Medium" ); 1863cdf0e10cSrcweir pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this ); 1864cdf0e10cSrcweir } 1865cdf0e10cSrcweir return ( SvKeyValueIterator*) &pImp->xHeaderAttributes; 1866cdf0e10cSrcweir } 1867cdf0e10cSrcweir 1868cdf0e10cSrcweir void SfxObjectShell::ClearHeaderAttributesForSourceViewHack() 1869cdf0e10cSrcweir { 1870cdf0e10cSrcweir ((SfxHeaderAttributes_Impl*)GetHeaderAttributes()) 1871cdf0e10cSrcweir ->ClearForSourceView(); 1872cdf0e10cSrcweir } 1873cdf0e10cSrcweir 1874cdf0e10cSrcweir 1875cdf0e10cSrcweir void SfxObjectShell::SetHeaderAttributesForSourceViewHack() 1876cdf0e10cSrcweir { 1877cdf0e10cSrcweir ((SfxHeaderAttributes_Impl*)GetHeaderAttributes()) 1878cdf0e10cSrcweir ->SetAttributes(); 1879cdf0e10cSrcweir } 1880cdf0e10cSrcweir 1881cdf0e10cSrcweir sal_Bool SfxObjectShell::IsPreview() const 1882cdf0e10cSrcweir { 1883cdf0e10cSrcweir if ( !pMedium ) 1884cdf0e10cSrcweir return sal_False; 1885cdf0e10cSrcweir 1886cdf0e10cSrcweir sal_Bool bPreview = sal_False; 1887cdf0e10cSrcweir SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False); 1888cdf0e10cSrcweir if ( pFlags ) 1889cdf0e10cSrcweir { 1890cdf0e10cSrcweir // Werte auf einzelne Items verteilen 1891cdf0e10cSrcweir String aFileFlags = pFlags->GetValue(); 1892cdf0e10cSrcweir aFileFlags.ToUpperAscii(); 1893cdf0e10cSrcweir if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) ) 1894cdf0e10cSrcweir bPreview = sal_True; 1895cdf0e10cSrcweir } 1896cdf0e10cSrcweir 1897cdf0e10cSrcweir if ( !bPreview ) 1898cdf0e10cSrcweir { 1899cdf0e10cSrcweir SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False); 1900cdf0e10cSrcweir if ( pItem ) 1901cdf0e10cSrcweir bPreview = pItem->GetValue(); 1902cdf0e10cSrcweir } 1903cdf0e10cSrcweir 1904cdf0e10cSrcweir return bPreview; 1905cdf0e10cSrcweir } 1906cdf0e10cSrcweir 1907cdf0e10cSrcweir sal_Bool SfxObjectShell::IsSecure() 1908cdf0e10cSrcweir { 1909cdf0e10cSrcweir // Wenn globale Warnung an ist, nach Secure-Referer-Liste gehen 1910cdf0e10cSrcweir String aReferer = GetMedium()->GetName(); 1911cdf0e10cSrcweir if ( !aReferer.Len() ) 1912cdf0e10cSrcweir { 1913cdf0e10cSrcweir // bei neuen Dokumenten das Template als Referer nehmen 1914cdf0e10cSrcweir ::rtl::OUString aTempl( getDocProperties()->getTemplateURL() ); 1915cdf0e10cSrcweir if ( aTempl.getLength() ) 1916cdf0e10cSrcweir aReferer = INetURLObject( aTempl ).GetMainURL( INetURLObject::NO_DECODE ); 1917cdf0e10cSrcweir } 1918cdf0e10cSrcweir 1919cdf0e10cSrcweir INetURLObject aURL( "macro:" ); 1920cdf0e10cSrcweir if ( !aReferer.Len() ) 1921cdf0e10cSrcweir // empty new or embedded document 1922cdf0e10cSrcweir return sal_True; 1923cdf0e10cSrcweir 1924cdf0e10cSrcweir SvtSecurityOptions aOpt; 1925cdf0e10cSrcweir 1926cdf0e10cSrcweir if( aOpt.GetBasicMode() == eALWAYS_EXECUTE ) 1927cdf0e10cSrcweir return sal_True; 1928cdf0e10cSrcweir 1929cdf0e10cSrcweir if( aOpt.GetBasicMode() == eNEVER_EXECUTE ) 1930cdf0e10cSrcweir return sal_False; 1931cdf0e10cSrcweir 1932cdf0e10cSrcweir if ( aOpt.IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) ) 1933cdf0e10cSrcweir //if ( SvtSecurityOptions().IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) ) 1934cdf0e10cSrcweir { 1935cdf0e10cSrcweir if ( GetMedium()->GetContent().is() ) 1936cdf0e10cSrcweir { 1937cdf0e10cSrcweir Any aAny( ::utl::UCBContentHelper::GetProperty( aURL.GetMainURL( INetURLObject::NO_DECODE ), String( RTL_CONSTASCII_USTRINGPARAM("IsProtected")) ) ); 1938cdf0e10cSrcweir sal_Bool bIsProtected = sal_False; 1939cdf0e10cSrcweir if ( ( aAny >>= bIsProtected ) && bIsProtected ) 1940cdf0e10cSrcweir return sal_False; 1941cdf0e10cSrcweir else 1942cdf0e10cSrcweir return sal_True; 1943cdf0e10cSrcweir } 1944cdf0e10cSrcweir else 1945cdf0e10cSrcweir return sal_True; 1946cdf0e10cSrcweir } 1947cdf0e10cSrcweir else 1948cdf0e10cSrcweir return sal_False; 1949cdf0e10cSrcweir } 1950cdf0e10cSrcweir 1951cdf0e10cSrcweir void SfxObjectShell::SetWaitCursor( sal_Bool bSet ) const 1952cdf0e10cSrcweir { 1953cdf0e10cSrcweir for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) ) 1954cdf0e10cSrcweir { 1955cdf0e10cSrcweir if ( bSet ) 1956cdf0e10cSrcweir pFrame->GetFrame().GetWindow().EnterWait(); 1957cdf0e10cSrcweir else 1958cdf0e10cSrcweir pFrame->GetFrame().GetWindow().LeaveWait(); 1959cdf0e10cSrcweir } 1960cdf0e10cSrcweir } 1961cdf0e10cSrcweir 1962cdf0e10cSrcweir String SfxObjectShell::GetAPIName() const 1963cdf0e10cSrcweir { 1964cdf0e10cSrcweir INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) ); 1965cdf0e10cSrcweir String aName( aURL.GetBase() ); 1966cdf0e10cSrcweir if( !aName.Len() ) 1967cdf0e10cSrcweir aName = aURL.GetURLNoPass(); 1968cdf0e10cSrcweir if ( !aName.Len() ) 1969cdf0e10cSrcweir aName = GetTitle( SFX_TITLE_DETECT ); 1970cdf0e10cSrcweir return aName; 1971cdf0e10cSrcweir } 1972cdf0e10cSrcweir 1973cdf0e10cSrcweir void SfxObjectShell::Invalidate( sal_uInt16 nId ) 1974cdf0e10cSrcweir { 1975cdf0e10cSrcweir for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) ) 1976cdf0e10cSrcweir Invalidate_Impl( pFrame->GetBindings(), nId ); 1977cdf0e10cSrcweir } 1978cdf0e10cSrcweir 1979cdf0e10cSrcweir bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI ) 1980cdf0e10cSrcweir { 1981cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xInteraction; 1982cdf0e10cSrcweir if ( pMedium && !bSuppressUI ) 1983cdf0e10cSrcweir xInteraction = pMedium->GetInteractionHandler(); 1984cdf0e10cSrcweir 1985cdf0e10cSrcweir CheckForBrokenDocSignatures_Impl( xInteraction ); 1986cdf0e10cSrcweir 1987cdf0e10cSrcweir CheckEncryption_Impl( xInteraction ); 1988cdf0e10cSrcweir 1989cdf0e10cSrcweir return pImp->aMacroMode.adjustMacroMode( xInteraction ); 1990cdf0e10cSrcweir } 1991cdf0e10cSrcweir 1992cdf0e10cSrcweir Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium ) 1993cdf0e10cSrcweir { 1994cdf0e10cSrcweir Window* pWindow = 0; 1995cdf0e10cSrcweir SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet(); 1996cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False ); 1997cdf0e10cSrcweir if ( pUnoItem ) 1998cdf0e10cSrcweir { 1999cdf0e10cSrcweir uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() ); 2000cdf0e10cSrcweir pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 2001cdf0e10cSrcweir } 2002cdf0e10cSrcweir 2003cdf0e10cSrcweir if ( !pWindow ) 2004cdf0e10cSrcweir { 2005cdf0e10cSrcweir SfxFrame* pFrame = 0; 2006cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False ); 2007cdf0e10cSrcweir if( pFrameItem && pFrameItem->GetFrame() ) 2008cdf0e10cSrcweir // get target frame from ItemSet 2009cdf0e10cSrcweir pFrame = pFrameItem->GetFrame(); 2010cdf0e10cSrcweir else 2011cdf0e10cSrcweir { 2012cdf0e10cSrcweir // try the current frame 2013cdf0e10cSrcweir SfxViewFrame* pView = SfxViewFrame::Current(); 2014cdf0e10cSrcweir if ( !pView || pView->GetObjectShell() != this ) 2015cdf0e10cSrcweir // get any visible frame 2016cdf0e10cSrcweir pView = SfxViewFrame::GetFirst(this); 2017cdf0e10cSrcweir if ( pView ) 2018cdf0e10cSrcweir pFrame = &pView->GetFrame(); 2019cdf0e10cSrcweir } 2020cdf0e10cSrcweir 2021cdf0e10cSrcweir if ( pFrame ) 2022cdf0e10cSrcweir // get topmost window 2023cdf0e10cSrcweir pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() ); 2024cdf0e10cSrcweir } 2025cdf0e10cSrcweir 2026cdf0e10cSrcweir if ( pWindow ) 2027cdf0e10cSrcweir { 2028cdf0e10cSrcweir // this frame may be invisible, show it if it is allowed 2029cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False ); 2030cdf0e10cSrcweir if ( !pHiddenItem || !pHiddenItem->GetValue() ) 2031cdf0e10cSrcweir { 2032cdf0e10cSrcweir pWindow->Show(); 2033cdf0e10cSrcweir pWindow->ToTop(); 2034cdf0e10cSrcweir } 2035cdf0e10cSrcweir } 2036cdf0e10cSrcweir 2037cdf0e10cSrcweir return pWindow; 2038cdf0e10cSrcweir } 2039cdf0e10cSrcweir 2040cdf0e10cSrcweir String SfxObjectShell::UpdateTitle( SfxMedium* pMed, sal_uInt16 nDocViewNumber ) 2041cdf0e10cSrcweir { 2042cdf0e10cSrcweir // Titel des Fensters 2043cdf0e10cSrcweir String aTitle; 2044cdf0e10cSrcweir if ( pMed ) 2045cdf0e10cSrcweir { 2046cdf0e10cSrcweir INetURLObject aTmp( pMed->GetName() ); 2047cdf0e10cSrcweir aTitle = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 2048cdf0e10cSrcweir } 2049cdf0e10cSrcweir else 2050cdf0e10cSrcweir { 2051cdf0e10cSrcweir pMed = GetMedium(); 2052cdf0e10cSrcweir aTitle = GetTitle(SFX_TITLE_CAPTION); 2053cdf0e10cSrcweir String aName(aTitle); 2054cdf0e10cSrcweir if ( nDocViewNumber ) 2055cdf0e10cSrcweir { 2056cdf0e10cSrcweir aName += ':'; 2057cdf0e10cSrcweir aName += String::CreateFromInt32( nDocViewNumber ); 2058cdf0e10cSrcweir } 2059cdf0e10cSrcweir } 2060cdf0e10cSrcweir 2061cdf0e10cSrcweir if ( pMed ) 2062cdf0e10cSrcweir { 2063cdf0e10cSrcweir SFX_ITEMSET_ARG( pMed->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False ); 2064cdf0e10cSrcweir if ( pRepairedDocItem && pRepairedDocItem->GetValue() ) 2065cdf0e10cSrcweir aTitle += String( SfxResId(STR_REPAIREDDOCUMENT) ); 2066cdf0e10cSrcweir } 2067cdf0e10cSrcweir 2068cdf0e10cSrcweir if ( IsReadOnlyUI() || (pMed && pMed->IsReadOnly()) ) 2069cdf0e10cSrcweir aTitle += String( SfxResId(STR_READONLY) ); 2070cdf0e10cSrcweir else if ( IsDocShared() ) 2071cdf0e10cSrcweir aTitle += String( SfxResId(STR_SHARED) ); 2072cdf0e10cSrcweir 2073cdf0e10cSrcweir return aTitle; 2074cdf0e10cSrcweir } 2075cdf0e10cSrcweir 2076cdf0e10cSrcweir void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode ) 2077cdf0e10cSrcweir { 2078cdf0e10cSrcweir eCreateMode = nMode; 2079cdf0e10cSrcweir } 2080cdf0e10cSrcweir 2081cdf0e10cSrcweir sal_Bool SfxObjectShell::IsInPlaceActive() 2082cdf0e10cSrcweir { 2083cdf0e10cSrcweir if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED ) 2084cdf0e10cSrcweir return sal_False; 2085cdf0e10cSrcweir 2086cdf0e10cSrcweir SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 2087cdf0e10cSrcweir return pFrame && pFrame->GetFrame().IsInPlace(); 2088cdf0e10cSrcweir } 2089cdf0e10cSrcweir 2090cdf0e10cSrcweir sal_Bool SfxObjectShell::IsUIActive() 2091cdf0e10cSrcweir { 2092cdf0e10cSrcweir if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED ) 2093cdf0e10cSrcweir return sal_False; 2094cdf0e10cSrcweir 2095cdf0e10cSrcweir SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); 2096cdf0e10cSrcweir return pFrame && pFrame->GetFrame().IsInPlace() && pFrame->GetFrame().GetWorkWindow_Impl()->IsVisible_Impl(); 2097cdf0e10cSrcweir } 2098cdf0e10cSrcweir 2099cdf0e10cSrcweir void SfxObjectShell::UIActivate( sal_Bool ) 2100cdf0e10cSrcweir { 2101cdf0e10cSrcweir } 2102cdf0e10cSrcweir 2103cdf0e10cSrcweir void SfxObjectShell::InPlaceActivate( sal_Bool ) 2104cdf0e10cSrcweir { 2105cdf0e10cSrcweir } 2106cdf0e10cSrcweir 2107cdf0e10cSrcweir sal_Bool SfxObjectShell::UseInteractionToHandleError( 2108cdf0e10cSrcweir const uno::Reference< task::XInteractionHandler >& xHandler, 2109cdf0e10cSrcweir sal_uInt32 nError ) 2110cdf0e10cSrcweir { 2111cdf0e10cSrcweir sal_Bool bResult = sal_False; 2112cdf0e10cSrcweir 2113cdf0e10cSrcweir if ( xHandler.is() ) 2114cdf0e10cSrcweir { 2115cdf0e10cSrcweir try 2116cdf0e10cSrcweir { 2117cdf0e10cSrcweir uno::Any aInteraction; 2118cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2); 2119cdf0e10cSrcweir ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort(); 2120cdf0e10cSrcweir ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove(); 2121cdf0e10cSrcweir lContinuations[0] = uno::Reference< task::XInteractionContinuation >( 2122cdf0e10cSrcweir static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY ); 2123cdf0e10cSrcweir lContinuations[1] = uno::Reference< task::XInteractionContinuation >( 2124cdf0e10cSrcweir static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY ); 2125cdf0e10cSrcweir 2126cdf0e10cSrcweir task::ErrorCodeRequest aErrorCode; 2127cdf0e10cSrcweir aErrorCode.ErrCode = nError; 2128cdf0e10cSrcweir aInteraction <<= aErrorCode; 2129cdf0e10cSrcweir xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations)); 2130cdf0e10cSrcweir bResult = pAbort->wasSelected(); 2131cdf0e10cSrcweir } 2132cdf0e10cSrcweir catch( uno::Exception& ) 2133cdf0e10cSrcweir {} 2134cdf0e10cSrcweir } 2135cdf0e10cSrcweir 2136cdf0e10cSrcweir return bResult; 2137cdf0e10cSrcweir } 2138cdf0e10cSrcweir 2139cdf0e10cSrcweir sal_Bool SfxObjectShell_Impl::NeedsOfficeUpdateDialog() 2140cdf0e10cSrcweir { 2141cdf0e10cSrcweir // if the configuration is not available for any reason, the default behavior is to show the message 2142cdf0e10cSrcweir sal_Bool bResult = sal_True; 2143cdf0e10cSrcweir 2144cdf0e10cSrcweir try 2145cdf0e10cSrcweir { 2146cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); 2147cdf0e10cSrcweir uno::Reference< uno::XInterface > xCommonConfig( 2148cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( 2149cdf0e10cSrcweir xServiceManager, 2150cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ), 2151cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_STANDARD ), 2152cdf0e10cSrcweir uno::UNO_SET_THROW ); 2153cdf0e10cSrcweir 2154cdf0e10cSrcweir ::comphelper::ConfigurationHelper::readRelativeKey( 2155cdf0e10cSrcweir xCommonConfig, 2156cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Load/" ) ), 2157cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowOfficeUpdateDialog" ) ) ) >>= bResult; 2158cdf0e10cSrcweir } 2159cdf0e10cSrcweir catch( uno::Exception& ) 2160cdf0e10cSrcweir { 2161cdf0e10cSrcweir } 2162cdf0e10cSrcweir 2163cdf0e10cSrcweir return bResult; 2164cdf0e10cSrcweir } 2165cdf0e10cSrcweir 2166cdf0e10cSrcweir sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const 2167cdf0e10cSrcweir { 2168cdf0e10cSrcweir sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE ); 2169cdf0e10cSrcweir 2170cdf0e10cSrcweir const SfxMedium* pMedium( rDocShell.GetMedium() ); 2171cdf0e10cSrcweir OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" ); 2172cdf0e10cSrcweir if ( pMedium ) 2173cdf0e10cSrcweir { 2174cdf0e10cSrcweir SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False); 2175cdf0e10cSrcweir if ( pMacroModeItem ) 2176cdf0e10cSrcweir nImposedExecMode = pMacroModeItem->GetValue(); 2177cdf0e10cSrcweir } 2178cdf0e10cSrcweir return nImposedExecMode; 2179cdf0e10cSrcweir } 2180cdf0e10cSrcweir 2181cdf0e10cSrcweir sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode ) 2182cdf0e10cSrcweir { 2183cdf0e10cSrcweir const SfxMedium* pMedium( rDocShell.GetMedium() ); 2184cdf0e10cSrcweir OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" ); 2185cdf0e10cSrcweir if ( pMedium ) 2186cdf0e10cSrcweir { 2187cdf0e10cSrcweir pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) ); 2188cdf0e10cSrcweir return sal_True; 2189cdf0e10cSrcweir } 2190cdf0e10cSrcweir 2191cdf0e10cSrcweir return sal_False; 2192cdf0e10cSrcweir } 2193cdf0e10cSrcweir 2194cdf0e10cSrcweir ::rtl::OUString SfxObjectShell_Impl::getDocumentLocation() const 2195cdf0e10cSrcweir { 2196cdf0e10cSrcweir ::rtl::OUString sLocation; 2197cdf0e10cSrcweir 2198cdf0e10cSrcweir const SfxMedium* pMedium( rDocShell.GetMedium() ); 2199cdf0e10cSrcweir OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" ); 2200cdf0e10cSrcweir if ( pMedium ) 2201cdf0e10cSrcweir { 2202cdf0e10cSrcweir sLocation = pMedium->GetName(); 2203cdf0e10cSrcweir if ( !sLocation.getLength() ) 2204cdf0e10cSrcweir { 2205cdf0e10cSrcweir // for documents made from a template: get the name of the template 2206cdf0e10cSrcweir sLocation = rDocShell.getDocProperties()->getTemplateURL(); 2207cdf0e10cSrcweir } 2208cdf0e10cSrcweir } 2209cdf0e10cSrcweir return sLocation; 2210cdf0e10cSrcweir } 2211cdf0e10cSrcweir 2212cdf0e10cSrcweir uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign() 2213cdf0e10cSrcweir { 2214cdf0e10cSrcweir Reference < embed::XStorage > xStore; 2215cdf0e10cSrcweir 2216cdf0e10cSrcweir SfxMedium* pMedium( rDocShell.GetMedium() ); 2217cdf0e10cSrcweir OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" ); 2218cdf0e10cSrcweir if ( pMedium ) 2219cdf0e10cSrcweir xStore = pMedium->GetZipStorageToSign_Impl(); 2220cdf0e10cSrcweir 2221cdf0e10cSrcweir return xStore; 2222cdf0e10cSrcweir } 2223cdf0e10cSrcweir 2224cdf0e10cSrcweir sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const 2225cdf0e10cSrcweir { 2226cdf0e10cSrcweir return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage ); 2227cdf0e10cSrcweir } 2228cdf0e10cSrcweir 2229cdf0e10cSrcweir Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const 2230cdf0e10cSrcweir { 2231cdf0e10cSrcweir return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY ); 2232cdf0e10cSrcweir } 2233cdf0e10cSrcweir 2234cdf0e10cSrcweir sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState() 2235cdf0e10cSrcweir { 2236cdf0e10cSrcweir sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() ); 2237cdf0e10cSrcweir 2238cdf0e10cSrcweir if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken ) 2239cdf0e10cSrcweir { 2240cdf0e10cSrcweir // if there is a macro signature it must be handled as broken 2241cdf0e10cSrcweir nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN; 2242cdf0e10cSrcweir } 2243cdf0e10cSrcweir 2244cdf0e10cSrcweir return nSignatureState; 2245cdf0e10cSrcweir } 2246cdf0e10cSrcweir 2247cdf0e10cSrcweir sal_Bool SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor ) 2248cdf0e10cSrcweir { 2249cdf0e10cSrcweir sal_Bool bResult = sal_False; 2250cdf0e10cSrcweir 2251cdf0e10cSrcweir try 2252cdf0e10cSrcweir { 2253cdf0e10cSrcweir ::rtl::OUString aVersion; 2254cdf0e10cSrcweir try 2255cdf0e10cSrcweir { 2256cdf0e10cSrcweir uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW ); 2257cdf0e10cSrcweir xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion; 2258cdf0e10cSrcweir } 2259cdf0e10cSrcweir catch( uno::Exception& ) 2260cdf0e10cSrcweir { 2261cdf0e10cSrcweir } 2262cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 ); 2263cdf0e10cSrcweir aArgs[0] <<= aVersion; 2264cdf0e10cSrcweir 2265cdf0e10cSrcweir uno::Reference< security::XDocumentDigitalSignatures > xSigner( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs ), uno::UNO_QUERY_THROW ); 2266cdf0e10cSrcweir 2267cdf0e10cSrcweir if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN 2268cdf0e10cSrcweir || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK 2269cdf0e10cSrcweir || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED ) 2270cdf0e10cSrcweir { 2271cdf0e10cSrcweir uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( sal_True, xSigner ); 2272cdf0e10cSrcweir 2273cdf0e10cSrcweir if ( aInfo.getLength() ) 2274cdf0e10cSrcweir { 2275cdf0e10cSrcweir if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN ) 2276cdf0e10cSrcweir nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo ); 2277cdf0e10cSrcweir 2278cdf0e10cSrcweir if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK 2279cdf0e10cSrcweir || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED ) 2280cdf0e10cSrcweir { 2281cdf0e10cSrcweir for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ ) 2282cdf0e10cSrcweir { 2283cdf0e10cSrcweir bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer ); 2284cdf0e10cSrcweir } 2285cdf0e10cSrcweir 2286cdf0e10cSrcweir if ( !bResult && bAllowUIToAddAuthor ) 2287cdf0e10cSrcweir { 2288cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xInteraction; 2289cdf0e10cSrcweir if ( rDocShell.GetMedium() ) 2290cdf0e10cSrcweir xInteraction = rDocShell.GetMedium()->GetInteractionHandler(); 2291cdf0e10cSrcweir 2292cdf0e10cSrcweir if ( xInteraction.is() ) 2293cdf0e10cSrcweir { 2294cdf0e10cSrcweir task::DocumentMacroConfirmationRequest aRequest; 2295cdf0e10cSrcweir aRequest.DocumentURL = getDocumentLocation(); 2296cdf0e10cSrcweir aRequest.DocumentStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl(); 2297cdf0e10cSrcweir aRequest.DocumentSignatureInformation = aInfo; 2298cdf0e10cSrcweir aRequest.DocumentVersion = aVersion; 2299cdf0e10cSrcweir aRequest.Classification = task::InteractionClassification_QUERY; 2300cdf0e10cSrcweir bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), sal_True ); 2301cdf0e10cSrcweir } 2302cdf0e10cSrcweir } 2303cdf0e10cSrcweir } 2304cdf0e10cSrcweir } 2305cdf0e10cSrcweir } 2306cdf0e10cSrcweir } 2307cdf0e10cSrcweir catch( uno::Exception& ) 2308cdf0e10cSrcweir {} 2309cdf0e10cSrcweir 2310cdf0e10cSrcweir return bResult; 2311cdf0e10cSrcweir } 2312cdf0e10cSrcweir 2313cdf0e10cSrcweir void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const 2314cdf0e10cSrcweir { 2315cdf0e10cSrcweir if ( !bSignatureErrorIsShown ) 2316cdf0e10cSrcweir { 2317cdf0e10cSrcweir SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE ); 2318cdf0e10cSrcweir const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = sal_True; 2319cdf0e10cSrcweir } 2320cdf0e10cSrcweir } 2321cdf0e10cSrcweir 2322cdf0e10cSrcweir void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage ) 2323cdf0e10cSrcweir { 2324cdf0e10cSrcweir if ( !pImp->m_xLogRing.is() ) 2325cdf0e10cSrcweir { 2326cdf0e10cSrcweir try 2327cdf0e10cSrcweir { 2328cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 2329cdf0e10cSrcweir if ( aContext.is() ) 2330cdf0e10cSrcweir pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW ); 2331cdf0e10cSrcweir } 2332cdf0e10cSrcweir catch( uno::Exception& ) 2333cdf0e10cSrcweir {} 2334cdf0e10cSrcweir } 2335cdf0e10cSrcweir 2336cdf0e10cSrcweir if ( pImp->m_xLogRing.is() ) 2337cdf0e10cSrcweir pImp->m_xLogRing->logString( aMessage ); 2338cdf0e10cSrcweir } 2339cdf0e10cSrcweir 2340cdf0e10cSrcweir namespace { 2341cdf0e10cSrcweir 2342cdf0e10cSrcweir void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const ::rtl::OUString& aString ) 2343cdf0e10cSrcweir { 2344cdf0e10cSrcweir if ( xOutStream.is() ) 2345cdf0e10cSrcweir { 2346cdf0e10cSrcweir ::rtl::OString aStrLog = ::rtl::OUStringToOString( aString, RTL_TEXTENCODING_UTF8 ); 2347cdf0e10cSrcweir uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() ); 2348cdf0e10cSrcweir xOutStream->writeBytes( aLogData ); 2349cdf0e10cSrcweir 2350cdf0e10cSrcweir aLogData.realloc( 1 ); 2351cdf0e10cSrcweir aLogData[0] = '\n'; 2352cdf0e10cSrcweir xOutStream->writeBytes( aLogData ); 2353cdf0e10cSrcweir } 2354cdf0e10cSrcweir } 2355cdf0e10cSrcweir 2356cdf0e10cSrcweir } 2357cdf0e10cSrcweir 2358cdf0e10cSrcweir void SfxObjectShell::StoreLog() 2359cdf0e10cSrcweir { 2360cdf0e10cSrcweir if ( !pImp->m_xLogRing.is() ) 2361cdf0e10cSrcweir { 2362cdf0e10cSrcweir try 2363cdf0e10cSrcweir { 2364cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 2365cdf0e10cSrcweir if ( aContext.is() ) 2366cdf0e10cSrcweir pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW ); 2367cdf0e10cSrcweir } 2368cdf0e10cSrcweir catch( uno::Exception& ) 2369cdf0e10cSrcweir {} 2370cdf0e10cSrcweir } 2371cdf0e10cSrcweir 2372cdf0e10cSrcweir if ( pImp->m_xLogRing.is() ) 2373cdf0e10cSrcweir { 2374910823aeSJürgen Schmidt ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) ); 2375910823aeSJürgen Schmidt //#ifdef WNT 2376910823aeSJürgen Schmidt // ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) ); 2377910823aeSJürgen Schmidt //#else 2378910823aeSJürgen Schmidt // ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/bootstraprc:UserInstallation}" ) ); 2379910823aeSJürgen Schmidt //#endif 2380cdf0e10cSrcweir ::rtl::Bootstrap::expandMacros( aFileURL ); 2381cdf0e10cSrcweir 2382910823aeSJürgen Schmidt //#ifdef WNT 2383910823aeSJürgen Schmidt // ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setup.ini:buildid}" ) ); 2384910823aeSJürgen Schmidt //#else 2385910823aeSJürgen Schmidt // ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setuprc:buildid}" ) ); 2386910823aeSJürgen Schmidt //#endif 2387910823aeSJürgen Schmidt ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("setup") ":buildid}" ) ); 2388cdf0e10cSrcweir ::rtl::Bootstrap::expandMacros( aBuildID ); 2389cdf0e10cSrcweir 2390cdf0e10cSrcweir if ( aFileURL.getLength() ) 2391cdf0e10cSrcweir { 2392cdf0e10cSrcweir aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/temp/document_io_logring.txt" ) ); 2393cdf0e10cSrcweir try 2394cdf0e10cSrcweir { 2395cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); 2396cdf0e10cSrcweir uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( xFactory->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW ); 2397cdf0e10cSrcweir uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW ); 2398cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW ); 2399cdf0e10cSrcweir uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW ); 2400cdf0e10cSrcweir xTruncate->truncate(); 2401cdf0e10cSrcweir 2402cdf0e10cSrcweir if ( aBuildID.getLength() ) 2403cdf0e10cSrcweir WriteStringInStream( xOutStream, aBuildID ); 2404cdf0e10cSrcweir 2405cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog(); 2406cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ ) 2407cdf0e10cSrcweir WriteStringInStream( xOutStream, aLogSeq[nInd] ); 2408cdf0e10cSrcweir } 2409cdf0e10cSrcweir catch( uno::Exception& ) 2410cdf0e10cSrcweir {} 2411cdf0e10cSrcweir } 2412cdf0e10cSrcweir } 2413cdf0e10cSrcweir } 2414cdf0e10cSrcweir 2415