update dev300-m58
[ooovba.git] / sfx2 / source / doc / objmisc.cxx
blobb08faf40f668c10972eb0a5aa739e04b68e6fc64
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objmisc.cxx,v $
10 * $Revision: 1.102.104.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #ifndef _INETMSG_HXX //autogen
35 #include <svtools/inetmsg.hxx>
36 #endif
37 #include <tools/diagnose_ex.h>
38 #include <svtools/eitem.hxx>
39 #include <svtools/stritem.hxx>
40 #include <svtools/intitem.hxx>
41 #include <svtools/svparser.hxx> // SvKeyValue
42 #include <vos/mutex.hxx>
43 #include <cppuhelper/exc_hlp.hxx>
45 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
46 #include <com/sun/star/document/XDocumentProperties.hpp>
47 #include <com/sun/star/document/UpdateDocMode.hpp>
48 #include <com/sun/star/script/XTypeConverter.hpp>
49 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
50 #include <com/sun/star/script/FinishEngineEvent.hpp>
51 #include <com/sun/star/script/InterruptReason.hpp>
52 #include <com/sun/star/script/XEngineListener.hpp>
53 #include <com/sun/star/script/XDebugging.hpp>
54 #ifndef _COM_SUN_STAR_SCRIPT_XINVOKATION_HPP_
55 #include <com/sun/star/script/XInvocation.hpp>
56 #endif
57 #include <com/sun/star/script/ContextInformation.hpp>
58 #include <com/sun/star/script/FinishReason.hpp>
59 #include <com/sun/star/script/XEngine.hpp>
60 #include <com/sun/star/script/InterruptEngineEvent.hpp>
61 #include <com/sun/star/script/XLibraryAccess.hpp>
62 #include <com/sun/star/document/MacroExecMode.hpp>
63 #include <com/sun/star/document/XScriptInvocationContext.hpp>
64 #include <com/sun/star/embed/EmbedStates.hpp>
65 #include <com/sun/star/embed/XEmbedPersist.hpp>
66 #include <com/sun/star/util/XModifiable.hpp>
67 #include <com/sun/star/container/XChild.hpp>
68 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
71 #include <com/sun/star/script/provider/XScript.hpp>
72 #include <com/sun/star/script/provider/XScriptProvider.hpp>
73 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
75 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
76 #include <toolkit/unohlp.hxx>
77 #endif
79 #include <com/sun/star/uno/Reference.h>
80 #include <com/sun/star/uno/Any.h>
81 #include <com/sun/star/ucb/XContent.hpp>
82 #include <com/sun/star/task/ErrorCodeRequest.hpp>
83 #include <svtools/securityoptions.hxx>
85 #include <comphelper/processfactory.hxx>
86 #include <comphelper/componentcontext.hxx>
87 #include <comphelper/configurationhelper.hxx>
89 #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
90 #include <com/sun/star/frame/XModel.hpp>
92 using namespace ::com::sun::star;
93 using namespace ::com::sun::star::uno;
94 using namespace ::com::sun::star::ucb;
95 using namespace ::com::sun::star::document;
96 using namespace ::com::sun::star::frame;
97 using namespace ::com::sun::star::script;
98 using namespace ::com::sun::star::script::provider;
99 using namespace ::com::sun::star::container;
100 #include <basic/sbuno.hxx>
101 #include <basic/sbstar.hxx>
102 #ifndef _SB_BASMGR_HXX
103 #include <basic/basmgr.hxx>
104 #endif
105 #ifndef _VCL_MSGBOX_HXX
106 #include <vcl/msgbox.hxx>
107 #endif
108 #include <basic/sbx.hxx>
109 #include <svtools/sfxecode.hxx>
110 #include <svtools/ehdl.hxx>
112 #include <svtools/pathoptions.hxx>
113 #include <unotools/ucbhelper.hxx>
114 #include <tools/inetmime.hxx>
115 #include <tools/urlobj.hxx>
116 #include <svtools/inettype.hxx>
117 #include <svtools/sharecontrolfile.hxx>
118 #include <osl/file.hxx>
119 #include <rtl/bootstrap.hxx>
120 #include <vcl/svapp.hxx>
121 #include <framework/interaction.hxx>
122 #include <comphelper/storagehelper.hxx>
124 #include <sfx2/signaturestate.hxx>
125 #include <sfx2/app.hxx>
126 #include "appdata.hxx"
127 #include <sfx2/request.hxx>
128 #include <sfx2/bindings.hxx>
129 #include "sfxresid.hxx"
130 #include <sfx2/docfile.hxx>
131 #include <sfx2/docfilt.hxx>
132 #include <sfx2/objsh.hxx>
133 #include "objshimp.hxx"
134 #include <sfx2/event.hxx>
135 #include "fltfnc.hxx"
136 #include <sfx2/sfx.hrc>
137 #include <sfx2/dispatch.hxx>
138 #include <sfx2/viewfrm.hxx>
139 #include <sfx2/viewsh.hxx>
140 #include <sfx2/ctrlitem.hxx>
141 #include "arrdecl.hxx"
142 #include <sfx2/module.hxx>
143 #include <sfx2/macrconf.hxx>
144 #include <sfx2/docfac.hxx>
145 #include "helper.hxx"
146 #include "doc.hrc"
147 #include "workwin.hxx"
148 #include "helpid.hrc"
149 #include "../appl/app.hrc"
150 #include <sfx2/sfxdlg.hxx>
151 #include "appbaslib.hxx"
152 #include <openflag.hxx> // SFX_STREAM_READWRITE
154 using namespace ::com::sun::star;
156 // class SfxHeaderAttributes_Impl ----------------------------------------
158 class SfxHeaderAttributes_Impl : public SvKeyValueIterator
160 private:
161 SfxObjectShell* pDoc;
162 SvKeyValueIteratorRef xIter;
163 sal_Bool bAlert;
165 public:
166 SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) :
167 SvKeyValueIterator(), pDoc( pSh ),
168 xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ),
169 bAlert( sal_False ) {}
171 virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); }
172 virtual sal_Bool GetNext( SvKeyValue& rKV ) { return xIter->GetNext( rKV ); }
173 virtual void Append( const SvKeyValue& rKV );
175 void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = sal_False; }
176 void SetAttributes();
177 void SetAttribute( const SvKeyValue& rKV );
180 //=========================================================================
182 sal_uInt16 __READONLY_DATA aTitleMap_Impl[3][2] =
184 // local remote
185 /* SFX_TITLE_CAPTION */ { SFX_TITLE_FILENAME, SFX_TITLE_TITLE },
186 /* SFX_TITLE_PICKLIST */ { 32, SFX_TITLE_FULLNAME },
187 /* SFX_TITLE_HISTORY */ { 32, SFX_TITLE_FULLNAME }
190 //=========================================================================
192 void SfxObjectShell::AbortImport()
194 pImp->bIsAbortingImport = sal_True;
197 //-------------------------------------------------------------------------
199 sal_Bool SfxObjectShell::IsAbortingImport() const
201 return pImp->bIsAbortingImport;
204 //-------------------------------------------------------------------------
206 uno::Reference<document::XDocumentProperties>
207 SfxObjectShell::getDocProperties()
209 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
210 GetModel(), uno::UNO_QUERY_THROW);
211 uno::Reference<document::XDocumentProperties> xDocProps(
212 xDPS->getDocumentProperties());
213 DBG_ASSERT(xDocProps.is(),
214 "SfxObjectShell: model has no DocumentProperties");
215 return xDocProps;
218 //-------------------------------------------------------------------------
220 void SfxObjectShell::DoFlushDocInfo()
224 //-------------------------------------------------------------------------
226 // Note: the only thing that calls this is the modification event handler
227 // that is installed at the XDocumentProperties
228 void SfxObjectShell::FlushDocInfo()
230 if ( IsLoading() )
231 return;
233 SetModified(sal_True);
234 uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
235 DoFlushDocInfo(); // call template method
236 ::rtl::OUString url(xDocProps->getAutoloadURL());
237 sal_Int32 delay(xDocProps->getAutoloadSecs());
238 SetAutoLoad( INetURLObject(url), delay * 1000,
239 (delay > 0) || url.getLength() );
241 // bitte beachten:
242 // 1. Titel in DocInfo aber nicht am Doc (nach HTML-Import)
243 // => auch am Doc setzen
244 // 2. Titel in DocInfo leer (Briefumschlagsdruck)
245 // => nicht am Doc setzen, da sonst "unbenanntX" daraus wird
246 String aDocInfoTitle = GetDocInfo().GetTitle();
247 if ( aDocInfoTitle.Len() )
248 SetTitle( aDocInfoTitle );
249 else
251 pImp->aTitle.Erase();
252 SetNamedVisibility_Impl();
253 if ( GetMedium() )
255 SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
256 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
261 //-------------------------------------------------------------------------
263 void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage )
265 if(pImp->lErr==ERRCODE_NONE)
267 pImp->lErr=lErr;
269 if( lErr != ERRCODE_NONE && aLogMessage.getLength() )
270 AddLog( aLogMessage );
274 //-------------------------------------------------------------------------
276 sal_uInt32 SfxObjectShell::GetError() const
278 return ERRCODE_TOERROR(GetErrorCode());
281 //-------------------------------------------------------------------------
283 sal_uInt32 SfxObjectShell::GetErrorCode() const
285 sal_uInt32 lError=pImp->lErr;
286 if(!lError && GetMedium())
287 lError=GetMedium()->GetErrorCode();
288 //REMOVE if(!lError && HasStorage())
289 //REMOVE lError= GetStorage()->GetErrorCode();
290 return lError;
293 //-------------------------------------------------------------------------
295 void SfxObjectShell::ResetError()
297 if( pImp->lErr != ERRCODE_NONE )
298 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Resetting Error." ) ) );
300 pImp->lErr=0;
301 SfxMedium * pMed = GetMedium();
302 if( pMed )
303 pMed->ResetError();
304 //REMOVE SvStorage *pStor= HasStorage() ? GetStorage() : 0;
305 //REMOVE if( pStor )
306 //REMOVE pStor->ResetError();
309 //-------------------------------------------------------------------------
311 sal_Bool SfxObjectShell::IsTemplate() const
313 return pImp->bIsTemplate;
316 //-------------------------------------------------------------------------
318 void SfxObjectShell::SetTemplate(sal_Bool bIs)
320 pImp->bIsTemplate=bIs;
321 SfxFilterMatcher aMatcher( GetFactory().GetFactoryName() );
322 SfxFilterMatcherIter aIter( &aMatcher, SFX_FILTER_TEMPLATEPATH );
323 SfxMedium* pMed = GetMedium();
324 if( pMed ) pMed->SetFilter( aIter.First() );
327 //-------------------------------------------------------------------------
329 void SfxObjectShell::EnableSetModified( sal_Bool bEnable )
331 #ifdef DBG_UTIL
332 if ( bEnable == pImp->m_bEnableSetModified )
333 DBG_WARNING( "SFX_PERSIST: EnableSetModified 2x mit dem gleichen Wert gerufen" );
334 #endif
335 pImp->m_bEnableSetModified = bEnable;
338 //-------------------------------------------------------------------------
340 sal_Bool SfxObjectShell::IsEnableSetModified() const
342 return pImp->m_bEnableSetModified && !IsReadOnly();
345 //-------------------------------------------------------------------------
347 sal_Bool SfxObjectShell::IsModified()
349 if ( pImp->m_bIsModified )
350 return sal_True;
352 if ( !pImp->m_xDocStorage.is() || IsReadOnly() )
354 // if the document still has no storage and is not set to be modified explicitly it is not modified
355 // a readonly document is also not modified
357 return sal_False;
360 uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
361 for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
363 uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
364 OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
365 if ( xObj.is() )
369 sal_Int32 nState = xObj->getCurrentState();
370 if ( nState != embed::EmbedStates::LOADED )
372 uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
373 if ( xModifiable.is() && xModifiable->isModified() )
374 return sal_True;
377 catch( uno::Exception& )
382 return sal_False;
385 //-------------------------------------------------------------------------
387 void SfxObjectShell::SetModified( sal_Bool bModifiedP )
389 #ifdef DBG_UTIL
390 if ( !bModifiedP && !IsEnableSetModified() )
391 DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), obwohl IsEnableSetModified() == sal_False" );
392 #endif
394 if( !IsEnableSetModified() )
395 return;
397 if( pImp->m_bIsModified != bModifiedP )
399 pImp->m_bIsModified = bModifiedP;
400 ModifyChanged();
404 //-------------------------------------------------------------------------
406 void SfxObjectShell::ModifyChanged()
408 if ( pImp->bClosing )
409 // SetModified aus dem dispose des Models!
410 return;
412 {DBG_CHKTHIS(SfxObjectShell, 0);}
413 SfxObjectShell *pDoc;
414 for ( pDoc = SfxObjectShell::GetFirst(); pDoc;
415 pDoc = SfxObjectShell::GetNext(*pDoc) )
416 if( pDoc->IsModified() )
417 break;
419 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
420 if ( pViewFrame )
421 pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS );
424 Invalidate( SID_SIGNATURE );
425 Invalidate( SID_MACRO_SIGNATURE );
426 Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) ); // xmlsec05, signed state might change in title...
428 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, this ) );
431 //-------------------------------------------------------------------------
433 sal_Bool SfxObjectShell::IsReadOnlyUI() const
435 /* [Beschreibung]
437 Liefert sal_True, wenn das Dokument fuer die UI wie r/o behandelt werden
438 soll. Dieses ist unabhaengig vom tatsaechlichen r/o, welches per
439 <IsReadOnly()> erfragbar ist.
443 return pImp->bReadOnlyUI;
446 //-------------------------------------------------------------------------
448 sal_Bool SfxObjectShell::IsReadOnlyMedium() const
450 /* [Beschreibung]
452 Liefert sal_True, wenn das Medium r/o ist bzw. r/o geoeffnet wurde.
456 if ( !pMedium )
457 return sal_True;
458 return pMedium->IsReadOnly();
461 //-------------------------------------------------------------------------
463 void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly )
465 /* [Beschreibung]
467 Schaltet das Dokument in einen r/o bzw. r/w Zustand ohne es neu
468 zu laden und ohne die Open-Modi des Mediums zu aendern.
472 sal_Bool bWasRO = IsReadOnly();
473 pImp->bReadOnlyUI = bReadOnly;
474 if ( bWasRO != IsReadOnly() )
476 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
477 //if ( pImp->pDocInfo )
478 // pImp->pDocInfo->SetReadOnly( IsReadOnly() );
482 //-------------------------------------------------------------------------
484 sal_Bool SfxObjectShell::IsReadOnly() const
486 return pImp->bReadOnlyUI || IsReadOnlyMedium();
489 //-------------------------------------------------------------------------
491 sal_Bool SfxObjectShell::IsInModalMode() const
493 return pImp->bModalMode || pImp->bRunningMacro;
496 //-------------------------------------------------------------------------
498 sal_Bool SfxObjectShell::HasModalViews() const
500 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
501 while( pFrame )
503 if ( pFrame->IsInModalMode() )
504 return sal_True;
506 pFrame = SfxViewFrame::GetNext( *pFrame, this );
509 return sal_False;
512 //-------------------------------------------------------------------------
514 void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal )
516 if ( !pImp->bRunningMacro != !bModal )
518 pImp->bRunningMacro = bModal;
519 Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
523 //-------------------------------------------------------------------------
525 void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal )
527 // nur Broadcasten wenn modifiziert, sonst ggf. Endlosrekursion
528 if ( !pImp->bModalMode != !bModal )
530 // zentral mitz"ahlen
531 sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode;
532 if ( bModal )
533 ++rDocModalCount;
534 else
535 --rDocModalCount;
537 // umschalten
538 pImp->bModalMode = bModal;
539 Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
543 //--------------------------------------------------------------------
544 sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave )
546 sal_Bool bResult = sal_True;
548 if ( bShared != IsDocShared() )
550 ::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
552 if ( !aOrigURL.getLength() && bSave )
554 // this is a new document, let it be stored before switching to the shared mode;
555 // the storing should be done without shared flag, since it is possible that the
556 // target location does not allow to create sharing control file;
557 // the shared flag will be set later after creation of sharing control file
558 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
560 if ( pViewFrame )
562 // TODO/LATER: currently the application guards against the reentrance problem
563 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
564 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
565 bResult = ( pResult && pResult->GetValue() );
566 if ( bResult )
567 aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
571 sal_Bool bOldValue = HasSharedXMLFlagSet();
572 SetSharedXMLFlag( bShared );
574 sal_Bool bRemoveEntryOnError = sal_False;
575 if ( bResult && bShared )
579 ::svt::ShareControlFile aControlFile( aOrigURL );
580 aControlFile.InsertOwnEntry();
581 bRemoveEntryOnError = sal_True;
583 catch( uno::Exception& )
585 bResult = sal_False;
589 if ( bResult && bSave )
591 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
593 if ( pViewFrame )
595 // TODO/LATER: currently the application guards against the reentrance problem
596 SetModified( sal_True ); // the modified flag has to be set to let the document be stored with the shared flag
597 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
598 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
599 bResult = ( pResult && pResult->GetValue() );
603 if ( bResult )
605 // TODO/LATER: Is it possible that the following calls fail?
606 if ( bShared )
608 pImp->m_aSharedFileURL = aOrigURL;
609 GetMedium()->SwitchDocumentToTempFile();
611 else
613 ::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
614 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
615 pImp->m_aSharedFileURL = ::rtl::OUString();
617 // now remove the temporary file the document was based on
618 ::utl::UCBContentHelper::Kill( aTempFileURL );
622 // aOrigURL can not be used since it contains an old value
623 ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
624 aControlFile.RemoveFile();
626 catch( uno::Exception& )
631 else
633 // the saving has failed!
634 if ( bRemoveEntryOnError )
638 ::svt::ShareControlFile aControlFile( aOrigURL );
639 aControlFile.RemoveEntry();
641 catch( uno::Exception& )
645 SetSharedXMLFlag( bOldValue );
648 else
649 bResult = sal_False; // the second switch to the same mode
651 if ( bResult )
652 SetTitle( String() );
654 return bResult;
657 //--------------------------------------------------------------------
659 void SfxObjectShell::DisconnectFromShared()
661 if ( IsDocShared() )
663 if ( pMedium && pMedium->GetStorage().is() )
665 // set medium to noname
666 pMedium->SetName( String(), sal_True );
667 pMedium->Init_Impl();
669 // drop resource
670 SetNoName();
671 InvalidateName();
673 // untitled document must be based on temporary storage
674 // the medium should not dispose the storage in this case
675 if ( pMedium->GetStorage() == GetStorage() )
676 ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium );
678 pMedium->Close();
679 FreeSharedFile();
681 SfxMedium* pTmpMedium = pMedium;
682 ForgetMedium();
683 if( !DoSaveCompleted( pTmpMedium ) )
684 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
685 else
687 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
688 pMedium->CanDisposeStorage_Impl( sal_False );
691 pMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
692 pMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
694 SetTitle( String() );
699 //--------------------------------------------------------------------
701 void SfxObjectShell::FreeSharedFile()
703 if ( pMedium )
704 FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
707 //--------------------------------------------------------------------
708 void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL )
710 SetSharedXMLFlag( sal_False );
712 if ( IsDocShared() && aTempFileURL.getLength()
713 && !SfxMedium::EqualURLs( aTempFileURL, GetSharedFileURL() ) )
715 if ( pImp->m_bAllowShareControlFileClean )
719 ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
720 aControlFile.RemoveEntry();
722 catch( uno::Exception& )
727 // the cleaning is forbidden only once
728 pImp->m_bAllowShareControlFileClean = sal_True;
730 // now remove the temporary file the document is based currently on
731 ::utl::UCBContentHelper::Kill( aTempFileURL );
733 pImp->m_aSharedFileURL = ::rtl::OUString();
737 //--------------------------------------------------------------------
738 void SfxObjectShell::DoNotCleanShareControlFile()
740 pImp->m_bAllowShareControlFileClean = sal_False;
743 //--------------------------------------------------------------------
744 void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const
746 pImp->m_bSharedXMLFlag = bFlag;
749 //--------------------------------------------------------------------
750 sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const
752 return pImp->m_bSharedXMLFlag;
755 //--------------------------------------------------------------------
757 sal_Bool SfxObjectShell::IsDocShared() const
759 return ( pImp->m_aSharedFileURL.getLength() > 0 );
762 //--------------------------------------------------------------------
764 ::rtl::OUString SfxObjectShell::GetSharedFileURL() const
766 return pImp->m_aSharedFileURL;
769 //--------------------------------------------------------------------
771 Size SfxObjectShell::GetFirstPageSize()
773 return GetVisArea(ASPECT_THUMBNAIL).GetSize();
777 //--------------------------------------------------------------------
779 IndexBitSet& SfxObjectShell::GetNoSet_Impl()
781 return pImp->aBitSet;
784 //--------------------------------------------------------------------
785 // changes the title of the document
787 void SfxObjectShell::SetTitle
789 const String& rTitle // der neue Titel des Dokuments
792 /* [Beschreibung]
794 Mit dieser Methode kann der Titel des Dokuments gesetzt werden.
795 Dieser entspricht initial dem kompletten Dateinamen. Ein Setzen
796 des Titels wirkt jedoch nicht zu"uck auf den Dateinamen; er wird
797 jedoch in den Caption-Bars der MDI-Fenster angezeigt.
801 DBG_CHKTHIS(SfxObjectShell, 0);
803 // nix zu tun?
804 if ( ( ( HasName() && pImp->aTitle == rTitle )
805 || ( !HasName() && GetTitle() == rTitle ) )
806 && !IsDocShared() )
807 return;
809 SfxApplication *pSfxApp = SFX_APP();
810 #if 0
811 // wird 'unbenannt#' als Titel gesetzt
812 String aNoName(SfxResId(STR_NONAME));
813 if ( rTitle.Match(aNoName) <= aNoName.Len() )
815 // er ist es selbst => ignorieren
816 pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
817 pImp->bIsNamedVisible=0;
819 #endif
821 // ggf. die unbenannt-Nummer freigeben
822 if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber )
824 pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
825 pImp->bIsNamedVisible = 0;
828 // Title setzen
829 pImp->aTitle = rTitle;
830 // Wieso denn in der DocInfo?
831 // GetDocInfo().SetTitle( rTitle );
832 // FlushDocInfo();
834 // Benachrichtigungen
835 if ( GetMedium() )
837 SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
838 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
842 //--------------------------------------------------------------------
844 #if OSL_DEBUG_LEVEL > 1
845 String X(const String &rRet)
847 if ( !rRet.Len() )
848 return DEFINE_CONST_UNICODE( "-empty-" );
849 return rRet;
851 #else
852 #define X(ret) ret
853 #endif
855 //--------------------------------------------------------------------
856 //--------------------------------------------------------------------
857 String SfxObjectShell::GetTitle
859 sal_uInt16 nMaxLength /* 0 (default)
860 der Titel selbst, so wie er ist
862 1 (==SFX_TITLE_FILENAME)
863 liefert den logischen Dateinamen ohne Pfad
864 (unter WNT je nach Systemeinstellung ohne
865 Extension)
867 2 (==SFX_TITLE_FULLNAME)
868 liefert den mit komplettem logischen Dateinamen
869 mit Pfad (remote => ::com::sun::star::util::URL)
871 3 (==SFX_TITLE_APINAME)
872 liefert den logischen Dateinamen ohne Pfad
873 und Extension
875 4 (==SFX_TITLE_DETECT)
876 liefert den kompletten Titel, falls noch
877 nicht gesetzt wird aber aus DocInfo oder
878 dem Namen des Medium erzeugt
880 5 (==SFX_TITLE_CAPTION)
881 liefert den Titel so, wie MB ihn heute in
882 der CaptionBar anzeigen m"ochte
884 6 (==SFX_TITLE_PICKLIST)
885 liefert den Titel so, wie MB ihn heute in
886 der PickList anzeigen m"ochte
888 7 (==SFX_TITLE_HISTORY)
889 liefert den Titel so, wie MB ihn heute in
890 der History anzeigen m"ochte
892 10 bis USHRT_MAX
893 liefert maximal 'nMaxLength' Zeichen vom logischen
894 Dateinamen inkl. Pfad (remote => ::com::sun::star::util::URL)
896 ) const
898 /* [Beschreibung]
900 Liefert den Titel bzw. logischen Dateinamen des Dokuments, je nach
901 'nMaxLength'.
903 Falls der Dateiname mit Pfad verwendet wird, wird die Namensk"urzung durch
904 Ersetzung eines oder mehrerer Directory-Namen durch "..." durchgef"uhrt,
905 URLs werden z.Zt. immer komplett geliefert.
909 // if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
910 // return String();
911 SfxMedium *pMed = GetMedium();
912 if ( IsLoading() )
913 return String();
915 /* if ( !nMaxLength && pImp->pDocInfo )
917 String aTitle = pImp->pDocInfo->GetTitle();
918 if ( aTitle.Len() )
919 return aTitle;
920 } */
922 // Titel erzeugen?
923 if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() )
925 static sal_Bool bRecur = sal_False;
926 if ( bRecur )
927 return DEFINE_CONST_UNICODE( "-not available-" );
928 bRecur = sal_True;
930 String aTitle;
931 SfxObjectShell *pThis = (SfxObjectShell*) this;
933 if ( pMed )
935 SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
936 if ( pNameItem )
937 aTitle = pNameItem->GetValue();
940 if ( !aTitle.Len() )
941 aTitle = GetTitle( SFX_TITLE_FILENAME );
943 if ( IsTemplate() )
944 pThis->SetTitle( aTitle );
945 bRecur = sal_False;
946 return X(aTitle);
948 else if (SFX_TITLE_APINAME == nMaxLength )
949 return X(GetAPIName());
951 // Sonderfall Vorlagen:
952 if( IsTemplate() && pImp->aTitle.Len() &&
953 ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
954 return X(pImp->aTitle);
956 // Picklist/Caption wird gemappt
957 if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
959 // Wenn ein spezieller Titel beim "Offnen mitgegeben wurde;
960 // wichtig bei URLs, die INET_PROT_FILE verwenden, denn bei denen
961 // wird der gesetzte Titel nicht beachtet.
962 // (s.u., Auswertung von aTitleMap_Impl)
963 SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
964 if ( pNameItem )
965 return X( pNameItem->GetValue() );
968 // noch unbenannt?
969 DBG_ASSERT( !HasName() || pMed, "HasName() aber kein Medium?!?" );
970 if ( !HasName() || !pMed )
972 // schon Titel gesezt?
973 if ( pImp->aTitle.Len() )
974 return X(pImp->aTitle);
976 // mu\s es durchnumeriert werden?
977 String aNoName( SfxResId( STR_NONAME ) );
978 if ( pImp->bIsNamedVisible )
979 // Nummer hintenanh"angen
980 aNoName += String::CreateFromInt32( pImp->nVisualDocumentNumber );
982 // Dokument hei\st vorerst 'unbenannt#'
983 return X(aNoName);
986 const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
987 if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
989 sal_uInt16 nRemote;
990 if( !pMed || aURL.GetProtocol() == INET_PROT_FILE )
991 nRemote = 0;
992 else
993 nRemote = 1;
994 nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote];
997 // lokale Datei?
998 if ( aURL.GetProtocol() == INET_PROT_FILE )
1000 String aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() );
1001 if ( nMaxLength == SFX_TITLE_FULLNAME )
1002 return X( aName );
1003 else if ( nMaxLength == SFX_TITLE_FILENAME )
1004 return X( aURL.getName( INetURLObject::LAST_SEGMENT,
1005 true, INetURLObject::DECODE_WITH_CHARSET ) );
1006 else if ( !pImp->aTitle.Len() )
1007 pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT,
1008 true, INetURLObject::DECODE_WITH_CHARSET );
1010 else
1012 // ::com::sun::star::util::URL-Versionen
1013 if ( nMaxLength >= SFX_TITLE_MAXLEN )
1015 String aComplete( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1016 if( aComplete.Len() > nMaxLength )
1018 String aRet( DEFINE_CONST_UNICODE( "..." ) );
1019 aRet += aComplete.Copy( aComplete.Len() - nMaxLength + 3, nMaxLength - 3 );
1020 return X( aRet );
1022 else
1023 return X( aComplete );
1025 else if ( nMaxLength == SFX_TITLE_FILENAME )
1027 String aName( aURL.GetBase() );
1028 aName = INetURLObject::decode( aName, INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET );
1029 if( !aName.Len() )
1030 aName = aURL.GetURLNoPass();
1031 return X(aName);
1033 else if ( nMaxLength == SFX_TITLE_FULLNAME )
1034 return X(aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ));
1036 // ggf. Titel aus Dateiname generieren
1037 if ( !pImp->aTitle.Len() )
1038 pImp->aTitle = aURL.GetBase();
1040 // workaround for the case when the name can not be retrieved from URL by INetURLObject
1041 if ( !pImp->aTitle.Len() )
1042 pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
1045 // ganzer Titel
1046 return X(pImp->aTitle);
1049 //--------------------------------------------------------------------
1051 void SfxObjectShell::InvalidateName()
1053 /* [Beschreibung]
1055 Ermittelt den Titel des Dokuments neu aus 'unbenannt', DocInfo-Titel
1056 bzw. Dateinamen. Wird nach Laden aus Template oder SaveAs ben"otigt.
1060 // Title neu erzeugen
1061 pImp->aTitle.Erase();
1062 // pImp->nVisualDocumentNumber = USHRT_MAX;
1063 //GetTitle( SFX_TITLE_DETECT );
1064 SetName( GetTitle( SFX_TITLE_APINAME ) );
1066 // Benachrichtigungen
1067 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1070 //--------------------------------------------------------------------
1072 void SfxObjectShell::SetNamedVisibility_Impl()
1074 if ( !pImp->bIsNamedVisible )
1076 // Nummer verpassen
1077 pImp->bIsNamedVisible = sal_True;
1078 // ggf. neue Nummer verpassen
1079 if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && !pImp->aTitle.Len() )
1081 pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex();
1082 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1086 SetName( GetTitle(SFX_TITLE_APINAME) );
1089 void SfxObjectShell::SetNoName()
1091 bHasName = 0;
1092 bIsTmp = sal_True;
1093 GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() );
1096 //--------------------------------------------------------------------
1098 void SfxObjectShell::MemoryError()
1102 //--------------------------------------------------------------------
1104 SfxProgress* SfxObjectShell::GetProgress() const
1106 return pImp->pProgress;
1109 //--------------------------------------------------------------------
1111 void SfxObjectShell::SetProgress_Impl
1113 SfxProgress *pProgress /* zu startender <SfxProgress> oder 0, falls
1114 der Progress zur"uckgesetzt werden soll */
1117 /* [Beschreibung]
1119 Interne Methode zum setzen oder zur"ucksetzen des Progress-Modes
1120 f"ur diese SfxObjectShell.
1124 DBG_ASSERT( ( !pImp->pProgress && pProgress ) ||
1125 ( pImp->pProgress && !pProgress ),
1126 "Progress activation/deacitivation mismatch" );
1127 pImp->pProgress = pProgress;
1130 //--------------------------------------------------------------------
1132 void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
1134 SfxApplication* pSfxApp = SFX_APP();
1135 if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame()->IsClosing_Impl() )
1137 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
1138 if ( !pHiddenItem || !pHiddenItem->GetValue() )
1140 sal_uInt16 nId = pImp->nEventId;
1141 pImp->nEventId = 0;
1142 if ( nId )
1143 pSfxApp->NotifyEvent(SfxEventHint( nId, this ), sal_False);
1148 //--------------------------------------------------------------------
1150 void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId )
1152 if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC )
1153 pImp->nEventId = nId;
1156 //--------------------------------------------------------------------
1158 void SfxObjectShell::RegisterTransfer( SfxMedium& rMedium )
1159 /* [Beschreibung ]
1160 Alle Medien, die aufgesetzt werden, um Teile eines Dokumentes zu
1161 laden, muessen an der zugehoerigen SfxObjectShell angemeldet
1162 werden. So kann dokumentweise abgebrochen werden. */
1164 rMedium.SetCancelManager_Impl( GetMedium()->GetCancelManager_Impl() );
1165 rMedium.SetReferer( GetMedium()->GetName() );
1168 //-------------------------------------------------------------------------
1170 void SfxObjectShell::PrepareReload( )
1171 /* [Beschreibung ]
1172 Wird vor dem Reload gerufen und gibt die Moeglichkeit,
1173 etwaige Caches zu leeren. */
1177 //-------------------------------------------------------------------------
1179 void SfxObjectShell::LockAutoLoad( sal_Bool bLock )
1181 /* Verhindert ein evtl. eintreffendes AutoLoad. Wird auch vor AutoLoad
1182 eines umgebenden FrameSet beruecksichtigt.
1186 if ( bLock )
1187 ++pImp->nAutoLoadLocks;
1188 else
1189 --pImp->nAutoLoadLocks;
1192 //-------------------------------------------------------------------------
1194 // kann nach frame.cxx gemoved werden, wenn 358+36x-Stand gemerged sind
1196 sal_Bool SfxFrame::IsAutoLoadLocked_Impl() const
1198 // sein einges Doc gelockt?
1199 const SfxObjectShell* pObjSh = GetCurrentDocument();
1200 if ( !pObjSh || !pObjSh->IsAutoLoadLocked() )
1201 return sal_False;
1203 // seine Childs gelockt?
1204 for ( sal_uInt16 n = GetChildFrameCount(); n--; )
1205 if ( !GetChildFrame(n)->IsAutoLoadLocked_Impl() )
1206 return sal_False;
1208 // sonst ist AutoLoad erlaubt
1209 return sal_True;
1212 //-------------------------------------------------------------------------
1214 sal_Bool SfxObjectShell::IsAutoLoadLocked() const
1216 /* Liefert, ob ein eintreffendes AutoLoad ausgefuehrt werden darf. Wird auch
1217 vor AutoLoad eines umgebenden FrameSet beruecksichtigt.
1221 return !IsReadOnly() || pImp->nAutoLoadLocks > 0;
1224 //-------------------------------------------------------------------------
1225 void SfxObjectShell::BreakMacroSign_Impl( sal_Bool bBreakMacroSign )
1227 pImp->m_bMacroSignBroken = bBreakMacroSign;
1230 //-------------------------------------------------------------------------
1231 void SfxObjectShell::CheckSecurityOnLoading_Impl()
1233 uno::Reference< task::XInteractionHandler > xInteraction;
1234 if ( GetMedium() )
1235 xInteraction = GetMedium()->GetInteractionHandler();
1237 // check macro security
1238 pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
1239 // check if there is a broken signature...
1240 CheckForBrokenDocSignatures_Impl( xInteraction );
1243 //-------------------------------------------------------------------------
1244 void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
1246 sal_Int16 nSignatureState = GetDocumentSignatureState();
1247 bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN );
1248 if ( !bSignatureBroken )
1249 return;
1251 pImp->showBrokenSignatureWarning( xHandler );
1253 // broken signatures imply no macro execution at all
1254 pImp->aMacroMode.disallowMacroExecution();
1257 //-------------------------------------------------------------------------
1258 void SfxObjectShell::SetAutoLoad(
1259 const INetURLObject& rUrl, sal_uInt32 nTime, sal_Bool bReload )
1261 if ( pImp->pReloadTimer )
1262 DELETEZ(pImp->pReloadTimer);
1263 if ( bReload )
1265 pImp->pReloadTimer = new AutoReloadTimer_Impl(
1266 rUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ),
1267 nTime, bReload, this );
1268 pImp->pReloadTimer->Start();
1272 sal_Bool SfxObjectShell::IsLoadingFinished() const
1274 return ( pImp->nLoadedFlags == SFX_LOADED_ALL );
1277 void impl_addToModelCollection(const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel);
1278 void SfxObjectShell::InitOwnModel_Impl()
1280 if ( !pImp->bModelInitialized )
1282 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
1283 if ( pSalvageItem )
1285 pImp->aTempName = pMedium->GetPhysicalName();
1286 pMedium->GetItemSet()->ClearItem( SID_DOC_SALVAGE );
1287 pMedium->GetItemSet()->ClearItem( SID_FILE_NAME );
1288 pMedium->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetOrigURL() ) );
1290 else
1292 pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
1293 pMedium->GetItemSet()->ClearItem( SID_DOCUMENT );
1296 pMedium->GetItemSet()->ClearItem( SID_REFERER );
1297 uno::Reference< frame::XModel > xModel ( GetModel(), uno::UNO_QUERY );
1298 if ( xModel.is() )
1300 ::rtl::OUString aURL = GetMedium()->GetOrigURL();
1301 SfxItemSet *pSet = GetMedium()->GetItemSet();
1302 if ( !GetMedium()->IsReadOnly() )
1303 pSet->ClearItem( SID_INPUTSTREAM );
1304 uno::Sequence< beans::PropertyValue > aArgs;
1305 TransformItems( SID_OPENDOC, *pSet, aArgs );
1306 xModel->attachResource( aURL, aArgs );
1307 impl_addToModelCollection(xModel);
1310 pImp->bModelInitialized = sal_True;
1314 void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags )
1316 sal_Bool bSetModifiedTRUE = sal_False;
1317 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1318 if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
1319 && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ))
1321 pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT;
1322 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes();
1323 pImp->bImportDone = sal_True;
1324 if( !IsAbortingImport() )
1325 PositionView_Impl();
1327 // Salvage
1328 if ( pSalvageItem )
1329 bSetModifiedTRUE = sal_True;
1331 if ( !IsEnableSetModified() )
1332 EnableSetModified( sal_True );
1334 if( !bSetModifiedTRUE && IsEnableSetModified() )
1335 SetModified( sal_False );
1337 CheckSecurityOnLoading_Impl();
1339 bHasName = sal_True; // the document is loaded, so the name should already available
1340 GetTitle( SFX_TITLE_DETECT );
1341 InitOwnModel_Impl();
1342 pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT;
1345 if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES )
1346 && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES ))
1348 pImp->nFlagsInProgress |= SFX_LOADED_IMAGES;
1349 uno::Reference<document::XDocumentProperties> xDocProps(
1350 getDocProperties());
1351 ::rtl::OUString url(xDocProps->getAutoloadURL());
1352 sal_Int32 delay(xDocProps->getAutoloadSecs());
1353 SetAutoLoad( INetURLObject(url), delay * 1000,
1354 (delay > 0) || url.getLength() );
1355 if( !bSetModifiedTRUE && IsEnableSetModified() )
1356 SetModified( sal_False );
1357 Invalidate( SID_SAVEASDOC );
1358 pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES;
1361 pImp->nLoadedFlags |= nFlags;
1363 if ( !pImp->nFlagsInProgress )
1365 // in case of reentrance calls the first called FinishedLoading() call on the stack
1366 // should do the notification, in result the notification is done when all the FinishedLoading() calls are finished
1368 if ( bSetModifiedTRUE )
1369 SetModified( sal_True );
1370 else
1371 SetModified( sal_False );
1373 if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) )
1375 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
1376 sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
1378 // closing the streams on loading should be under control of SFX!
1379 DBG_ASSERT( pMedium->IsOpen(), "Don't close the medium when loading documents!" );
1381 if ( bTemplate )
1383 TemplateDisconnectionAfterLoad();
1385 else
1387 // if a readonly medium has storage then it's stream is already based on temporary file
1388 if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() )
1389 // don't lock file opened read only
1390 pMedium->CloseInStream();
1394 pImp->bInitialized = sal_True;
1395 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_LOADFINISHED, this ) );
1397 // Title is not available until loading has finished
1398 Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );
1399 if ( pImp->nEventId )
1400 PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
1404 //-------------------------------------------------------------------------
1405 extern void SetTemplate_Impl( const String&, const String&, SfxObjectShell* );
1407 void SfxObjectShell::TemplateDisconnectionAfterLoad()
1409 // document is created from a template
1410 //TODO/LATER: should the templates always be XML docs!
1412 SfxMedium* pTmpMedium = pMedium;
1413 if ( pTmpMedium )
1415 String aName( pTmpMedium->GetName() );
1416 SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
1417 String aTemplateName;
1418 if ( pTemplNamItem )
1419 aTemplateName = pTemplNamItem->GetValue();
1420 else
1422 // !TODO/LATER: what's this?!
1423 // Interaktiv ( DClick, Contextmenu ) kommt kein Langname mit
1424 aTemplateName = getDocProperties()->getTitle();
1425 if ( !aTemplateName.Len() )
1427 INetURLObject aURL( aName );
1428 aURL.CutExtension();
1429 aTemplateName = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1433 // set medium to noname
1434 pTmpMedium->SetName( String(), sal_True );
1435 pTmpMedium->Init_Impl();
1437 // drop resource
1438 SetNoName();
1439 InvalidateName();
1441 if( IsPackageStorageFormat_Impl( *pTmpMedium ) )
1443 // untitled document must be based on temporary storage
1444 // the medium should not dispose the storage in this case
1445 uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1446 GetStorage()->copyToStorage( xTmpStor );
1448 // the medium should disconnect from the original location
1449 // the storage should not be disposed since the document is still
1450 // based on it, but in DoSaveCompleted it will be disposed
1451 pTmpMedium->CanDisposeStorage_Impl( sal_False );
1452 pTmpMedium->Close();
1454 // setting the new storage the medium will be based on
1455 pTmpMedium->SetStorage_Impl( xTmpStor );
1457 ForgetMedium();
1458 if( !DoSaveCompleted( pTmpMedium ) )
1459 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1460 else
1462 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1463 sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
1465 if ( !bSalvage )
1467 // some further initializations for templates
1468 SetTemplate_Impl( aName, aTemplateName, this );
1471 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
1472 pTmpMedium->CanDisposeStorage_Impl( sal_False );
1475 else
1477 // some further initializations for templates
1478 SetTemplate_Impl( aName, aTemplateName, this );
1479 pTmpMedium->CreateTempFile();
1482 // templates are never readonly
1483 pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
1484 pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
1486 // notifications about possible changes in readonly state and document info
1487 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
1489 // created untitled document can't be modified
1490 SetModified( sal_False );
1494 //-------------------------------------------------------------------------
1496 void SfxObjectShell::PositionView_Impl()
1498 MarkData_Impl *pMark = Get_Impl()->pMarkData;
1499 if( pMark )
1501 SfxViewShell* pSh = pMark->pFrame->GetViewShell();
1502 if( pMark->aUserData.Len() )
1503 pSh->ReadUserData( pMark->aUserData, sal_True );
1504 else if( pMark->aMark.Len() )
1505 pSh->JumpToMark( pMark->aMark );
1506 DELETEZ( Get_Impl()->pMarkData );
1510 //-------------------------------------------------------------------------
1512 sal_Bool SfxObjectShell::IsLoading() const
1513 /* [Beschreibung ]
1514 Wurde bereits FinishedLoading aufgerufeb? */
1516 return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT );
1519 //-------------------------------------------------------------------------
1521 void SfxObjectShell::CancelTransfers()
1522 /* [Beschreibung ]
1523 Hier koennen Transfers gecanceled werden, die nicht mit
1524 RegisterTransfer registiert wurden */
1526 GetMedium()->CancelTransfers();
1527 if( ( pImp->nLoadedFlags & SFX_LOADED_ALL ) != SFX_LOADED_ALL )
1529 AbortImport();
1530 if( IsLoading() )
1531 FinishedLoading( SFX_LOADED_ALL );
1534 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
1535 while( pFrame )
1537 pFrame->CancelTransfers();
1538 pFrame = SfxViewFrame::GetNext( *pFrame, this );
1543 //-------------------------------------------------------------------------
1545 AutoReloadTimer_Impl::AutoReloadTimer_Impl(
1546 const String& rURL, sal_uInt32 nTime, sal_Bool bReloadP, SfxObjectShell* pSh )
1547 : aUrl( rURL ), bReload( bReloadP ), pObjSh( pSh )
1549 SetTimeout( nTime );
1552 //-------------------------------------------------------------------------
1554 void AutoReloadTimer_Impl::Timeout()
1556 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjSh );
1558 if ( pFrame )
1560 // momentan nicht m"oglich/sinnvoll?
1561 if ( !pObjSh->CanReload_Impl() || pObjSh->IsAutoLoadLocked() || Application::IsUICaptured() )
1563 // erneuten Versuch erlauben
1564 Start();
1565 return;
1568 SfxAllItemSet aSet( SFX_APP()->GetPool() );
1569 aSet.Put( SfxBoolItem( SID_AUTOLOAD, sal_True ) );
1570 if ( aUrl.Len() )
1571 aSet.Put( SfxStringItem( SID_FILE_NAME, aUrl ) );
1572 SfxRequest aReq( SID_RELOAD, 0, aSet );
1573 pObjSh->Get_Impl()->pReloadTimer = 0;
1574 delete this;
1575 pFrame->ExecReload_Impl( aReq );
1576 return;
1579 pObjSh->Get_Impl()->pReloadTimer = 0;
1580 delete this;
1583 SfxModule* SfxObjectShell::GetModule() const
1585 return GetFactory().GetModule();
1588 sal_Bool SfxObjectShell::IsBasic(
1589 const String & rCode, SbxObject * pVCtrl )
1591 if( !rCode.Len() ) return sal_False;
1592 return SfxMacroConfig::IsBasic( pVCtrl, rCode, GetBasicManager() );
1595 ErrCode SfxObjectShell::CallBasic( const String& rMacro,
1596 const String& rBasic, SbxObject* pVCtrl, SbxArray* pArgs,
1597 SbxValue* pRet )
1599 SfxApplication* pApp = SFX_APP();
1600 if( pApp->GetName() != rBasic )
1602 if ( !AdjustMacroMode( String() ) )
1603 return ERRCODE_IO_ACCESSDENIED;
1606 pApp->EnterBasicCall();
1607 BasicManager *pMgr = GetBasicManager();
1608 if( pApp->GetName() == rBasic )
1609 pMgr = pApp->GetBasicManager();
1610 ErrCode nRet = SfxMacroConfig::Call( pVCtrl, rMacro, pMgr, pArgs, pRet );
1611 pApp->LeaveBasicCall();
1612 return nRet;
1615 ErrCode SfxObjectShell::Call( const String & rCode, sal_Bool bIsBasicReturn, SbxObject * pVCtrl )
1617 ErrCode nErr = ERRCODE_NONE;
1618 if ( bIsBasicReturn )
1619 CallBasic( rCode, String(), pVCtrl );
1620 return nErr;
1623 namespace
1625 static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext )
1629 Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY );
1630 if ( !xScripts.is() )
1632 Reference< XScriptInvocationContext > xContext( _rxScriptContext, UNO_QUERY_THROW );
1633 xScripts.set( xContext->getScriptContainer(), UNO_SET_THROW );
1636 return xScripts->getAllowMacroExecution();
1638 catch( const Exception& )
1640 DBG_UNHANDLED_EXCEPTION();
1642 return false;
1646 ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL,
1647 const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError, ::com::sun::star::uno::Any* pCaller )
1649 OSL_TRACE( "in CallXScript" );
1650 ErrCode nErr = ERRCODE_NONE;
1652 bool bIsDocumentScript = ( _rScriptURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "location=document" ) ) >= 0 );
1653 // TODO: we should parse the URL, and check whether there is a parameter with this name.
1654 // Otherwise, we might find too much.
1655 if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
1656 return ERRCODE_IO_ACCESSDENIED;
1658 bool bCaughtException = false;
1659 Any aException;
1662 // obtain/create a script provider
1663 Reference< provider::XScriptProvider > xScriptProvider;
1664 Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );
1665 if ( xSPS.is() )
1666 xScriptProvider.set( xSPS->getScriptProvider() );
1668 if ( !xScriptProvider.is() )
1670 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
1671 Reference< provider::XScriptProviderFactory > xScriptProviderFactory(
1672 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
1673 xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW );
1676 // obtain the script, and execute it
1677 Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW );
1678 if ( pCaller && pCaller->hasValue() )
1680 Reference< beans::XPropertySet > xProps( xScript, uno::UNO_QUERY );
1681 if ( xProps.is() )
1683 Sequence< uno::Any > aArgs( 1 );
1684 aArgs[ 0 ] = *pCaller;
1685 xProps->setPropertyValue( rtl::OUString::createFromAscii("Caller"), uno::makeAny( aArgs ) );
1688 aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam );
1690 catch ( const uno::Exception& )
1692 aException = ::cppu::getCaughtException();
1693 bCaughtException = TRUE;
1694 nErr = ERRCODE_BASIC_INTERNAL_ERROR;
1697 if ( bCaughtException && bRaiseError )
1699 ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg;
1700 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1701 if ( pFact )
1702 pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) );
1703 OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" );
1705 if ( pScriptErrDlg.get() )
1706 pScriptErrDlg->Execute();
1709 OSL_TRACE( "leaving CallXScript" );
1710 return nErr;
1713 // perhaps rename to CallScript once we get rid of the existing CallScript
1714 // and Call, CallBasic, CallStarBasic methods
1715 ErrCode SfxObjectShell::CallXScript( const String& rScriptURL,
1716 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
1717 aParams,
1718 ::com::sun::star::uno::Any& aRet,
1719 ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
1720 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
1721 aOutParam, bool bRaiseError, ::com::sun::star::uno::Any* pCaller )
1723 return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError, pCaller );
1726 //-------------------------------------------------------------------------
1727 namespace {
1728 using namespace ::com::sun::star::uno;
1730 //.....................................................................
1731 static SbxArrayRef lcl_translateUno2Basic( const void* _pAnySequence )
1733 SbxArrayRef xReturn;
1734 if ( _pAnySequence )
1736 // in real it's a sequence of Any (by convention)
1737 const Sequence< Any >* pArguments = static_cast< const Sequence< Any >* >( _pAnySequence );
1739 // do we have arguments ?
1740 if ( pArguments->getLength() )
1742 // yep
1743 xReturn = new SbxArray;
1744 String sEmptyName;
1746 // loop through the sequence
1747 const Any* pArg = pArguments->getConstArray();
1748 const Any* pArgEnd = pArg + pArguments->getLength();
1750 for ( sal_uInt16 nArgPos=1; pArg != pArgEnd; ++pArg, ++nArgPos )
1751 // and create a Sb object for every Any
1752 xReturn->Put( GetSbUnoObject( sEmptyName, *pArg ), nArgPos );
1755 return xReturn;
1757 //.....................................................................
1758 void lcl_translateBasic2Uno( const SbxVariableRef& _rBasicValue, void* _pAny )
1760 if ( _pAny )
1761 *static_cast< Any* >( _pAny ) = sbxToUnoValue( _rBasicValue );
1764 //-------------------------------------------------------------------------
1765 ErrCode SfxObjectShell::CallStarBasicScript( const String& _rMacroName, const String& _rLocation,
1766 const void* _pArguments, void* _pReturn )
1768 OSL_TRACE("in CallSBS");
1769 ::vos::OClearableGuard aGuard( Application::GetSolarMutex() );
1771 // the arguments for the call
1772 SbxArrayRef xMacroArguments = lcl_translateUno2Basic( _pArguments );
1774 // the return value
1775 SbxVariableRef xReturn = _pReturn ? new SbxVariable : NULL;
1777 // the location (document or application)
1778 String sMacroLocation;
1779 if ( _rLocation.EqualsAscii( "application" ) )
1780 sMacroLocation = SFX_APP()->GetName();
1781 #ifdef DBG_UTIL
1782 else
1783 DBG_ASSERT( _rLocation.EqualsAscii( "document" ),
1784 "SfxObjectShell::CallStarBasicScript: invalid (unknown) location!" );
1785 #endif
1787 // call the script
1788 ErrCode eError = CallBasic( _rMacroName, sMacroLocation, NULL, xMacroArguments, xReturn );
1790 // translate the return value
1791 lcl_translateBasic2Uno( xReturn, _pReturn );
1793 // outta here
1794 return eError;
1797 //-------------------------------------------------------------------------
1798 ErrCode SfxObjectShell::CallScript(
1799 const String & rScriptType,
1800 const String & rCode,
1801 const void *pArgs,
1802 void *pRet
1805 ::vos::OClearableGuard aGuard( Application::GetSolarMutex() );
1806 ErrCode nErr = ERRCODE_NONE;
1807 if( rScriptType.EqualsAscii( "StarBasic" ) )
1809 // the arguments for the call
1810 SbxArrayRef xMacroArguments = lcl_translateUno2Basic( pArgs );
1812 // the return value
1813 SbxVariableRef xReturn = pRet ? new SbxVariable : NULL;
1815 // call the script
1816 nErr = CallBasic( rCode, String(), NULL, xMacroArguments, xReturn );
1818 // translate the return value
1819 lcl_translateBasic2Uno( xReturn, pRet );
1821 // did this fail because the method was not found?
1822 if ( nErr == ERRCODE_BASIC_PROC_UNDEFINED )
1823 { // yep-> look in the application BASIC module
1824 nErr = CallBasic( rCode, SFX_APP()->GetName(), NULL, xMacroArguments, xReturn );
1827 else if( rScriptType.EqualsAscii( "JavaScript" ) )
1829 DBG_ERROR( "JavaScript not allowed" );
1830 return 0;
1832 else
1834 DBG_ERROR( "StarScript not allowed" );
1836 return nErr;
1839 SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
1841 return pSelf;
1844 SfxObjectShellFlags SfxObjectShell::GetFlags() const
1846 if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED )
1847 pImp->eFlags = GetFactory().GetFlags();
1848 return pImp->eFlags;
1851 void SfxObjectShell::SetFlags( SfxObjectShellFlags eFlags )
1853 pImp->eFlags = eFlags;
1857 void SfxObjectShell::SetBaseURL( const String& rURL )
1859 pImp->aBaseURL = rURL;
1860 pImp->bNoBaseURL = FALSE;
1863 const String& SfxObjectShell::GetBaseURLForSaving() const
1865 if ( pImp->bNoBaseURL )
1866 return String();
1867 return GetBaseURL();
1870 const String& SfxObjectShell::GetBaseURL() const
1872 if ( pImp->aBaseURL.Len() )
1873 return pImp->aBaseURL;
1874 return pMedium->GetBaseURL();
1877 void SfxObjectShell::SetEmptyBaseURL()
1879 pImp->bNoBaseURL = TRUE;
1882 String SfxObjectShell::QueryTitle( SfxTitleQuery eType ) const
1884 String aRet;
1886 switch( eType )
1888 case SFX_TITLE_QUERY_SAVE_NAME_PROPOSAL:
1890 SfxMedium* pMed = GetMedium();
1891 const INetURLObject aObj( pMed->GetName() );
1892 aRet = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
1893 if ( !aRet.Len() )
1894 aRet = GetTitle( SFX_TITLE_CAPTION );
1895 break;
1898 return aRet;
1901 void SfxHeaderAttributes_Impl::SetAttributes()
1903 bAlert = sal_True;
1904 SvKeyValue aPair;
1905 for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont;
1906 bCont = xIter->GetNext( aPair ) )
1907 SetAttribute( aPair );
1910 void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV )
1912 String aValue = rKV.GetValue();
1913 if( rKV.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL && rKV.GetValue().Len() )
1915 sal_uInt32 nTime = aValue.GetToken( 0, ';' ).ToInt32() ;
1916 String aURL = aValue.GetToken( 1, ';' );
1917 aURL.EraseTrailingChars().EraseLeadingChars();
1918 uno::Reference<document::XDocumentProperties> xDocProps(
1919 pDoc->getDocProperties());
1920 if( aURL.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL )
1922 INetURLObject aObj;
1923 INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.Copy( 4 ), &aObj );
1924 xDocProps->setAutoloadURL(
1925 aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1929 xDocProps->setAutoloadSecs( nTime );
1931 catch (lang::IllegalArgumentException &)
1933 // ignore
1936 else if( rKV.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL )
1938 DateTime aDateTime;
1939 if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) )
1941 aDateTime.ConvertToLocalTime();
1942 pDoc->GetMedium()->SetExpired_Impl( aDateTime );
1944 else
1946 // DBG_ERROR( "Schlechtes ::com::sun::star::util::DateTime fuer Expired" );
1947 pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) );
1950 else if( rKV.GetKey().CompareIgnoreCaseToAscii( "content-type" ) == COMPARE_EQUAL )
1952 ::rtl::OString sContent = ::rtl::OUStringToOString( aValue, RTL_TEXTENCODING_ASCII_US );
1953 ByteString sType, sSubType;
1954 INetContentTypeParameterList aParameters;
1956 if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) )
1958 const INetContentTypeParameter * pCharset = aParameters.find("charset");
1959 if (pCharset != 0)
1960 pDoc->GetMedium()->SetCharset( pCharset->m_sValue );
1965 void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV )
1967 xIter->Append( rKV );
1968 if( bAlert ) SetAttribute( rKV );
1971 SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes()
1973 if( !pImp->xHeaderAttributes.Is() )
1975 DBG_ASSERT( pMedium, "Kein Medium" );
1976 pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this );
1978 return ( SvKeyValueIterator*) &pImp->xHeaderAttributes;
1981 void SfxObjectShell::ClearHeaderAttributesForSourceViewHack()
1983 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
1984 ->ClearForSourceView();
1988 void SfxObjectShell::SetHeaderAttributesForSourceViewHack()
1990 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
1991 ->SetAttributes();
1994 void SfxObjectShell::StartLoading_Impl()
1996 pImp->nLoadedFlags = 0;
1997 pImp->bModelInitialized = sal_False;
2000 sal_Bool SfxObjectShell::IsPreview() const
2002 if ( !pMedium )
2003 return sal_False;
2005 sal_Bool bPreview = sal_False;
2006 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False);
2007 if ( pFlags )
2009 // Werte auf einzelne Items verteilen
2010 String aFileFlags = pFlags->GetValue();
2011 aFileFlags.ToUpperAscii();
2012 if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) )
2013 bPreview = sal_True;
2016 if ( !bPreview )
2018 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False);
2019 if ( pItem )
2020 bPreview = pItem->GetValue();
2023 return bPreview;
2026 sal_Bool SfxObjectShell::IsSecure()
2028 // Wenn globale Warnung an ist, nach Secure-Referer-Liste gehen
2029 String aReferer = GetMedium()->GetName();
2030 if ( !aReferer.Len() )
2032 // bei neuen Dokumenten das Template als Referer nehmen
2033 ::rtl::OUString aTempl( getDocProperties()->getTemplateURL() );
2034 if ( aTempl.getLength() )
2035 aReferer = INetURLObject( aTempl ).GetMainURL( INetURLObject::NO_DECODE );
2038 INetURLObject aURL( "macro:" );
2039 if ( !aReferer.Len() )
2040 // empty new or embedded document
2041 return sal_True;
2043 SvtSecurityOptions aOpt;
2045 if( aOpt.GetBasicMode() == eALWAYS_EXECUTE )
2046 return sal_True;
2048 if( aOpt.GetBasicMode() == eNEVER_EXECUTE )
2049 return sal_False;
2051 if ( aOpt.IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) )
2052 //if ( SvtSecurityOptions().IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) )
2054 if ( GetMedium()->GetContent().is() )
2056 Any aAny( ::utl::UCBContentHelper::GetProperty( aURL.GetMainURL( INetURLObject::NO_DECODE ), String( RTL_CONSTASCII_USTRINGPARAM("IsProtected")) ) );
2057 sal_Bool bIsProtected = FALSE;
2058 if ( ( aAny >>= bIsProtected ) && bIsProtected )
2059 return sal_False;
2060 else
2061 return sal_True;
2063 else
2064 return sal_True;
2066 else
2067 return sal_False;
2070 void SfxObjectShell::SetWaitCursor( BOOL bSet ) const
2072 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
2074 if ( bSet )
2075 pFrame->GetFrame()->GetWindow().EnterWait();
2076 else
2077 pFrame->GetFrame()->GetWindow().LeaveWait();
2081 String SfxObjectShell::GetAPIName() const
2083 INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
2084 String aName( aURL.GetBase() );
2085 if( !aName.Len() )
2086 aName = aURL.GetURLNoPass();
2087 if ( !aName.Len() )
2088 aName = GetTitle( SFX_TITLE_DETECT );
2089 return aName;
2092 void SfxObjectShell::Invalidate( USHORT nId )
2094 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
2095 Invalidate_Impl( pFrame->GetBindings(), nId );
2098 bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool _bSuppressUI )
2100 uno::Reference< task::XInteractionHandler > xInteraction;
2101 if ( pMedium && !_bSuppressUI )
2102 xInteraction = pMedium->GetInteractionHandler();
2104 CheckForBrokenDocSignatures_Impl( xInteraction );
2106 return pImp->aMacroMode.adjustMacroMode( xInteraction );
2109 Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium )
2111 Window* pWindow = 0;
2112 SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet();
2113 SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoAnyItem, SID_FILLFRAME, FALSE );
2114 if ( pUnoItem )
2116 uno::Reference < frame::XFrame > xFrame;
2117 pUnoItem->GetValue() >>= xFrame;
2118 if ( xFrame.is() )
2119 pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
2122 if ( !pWindow )
2124 SfxFrame* pFrame = 0;
2125 SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, FALSE );
2126 if( pFrameItem && pFrameItem->GetFrame() )
2127 // get target frame from ItemSet
2128 pFrame = pFrameItem->GetFrame();
2129 else
2131 // try the current frame
2132 SfxViewFrame* pView = SfxViewFrame::Current();
2133 if ( !pView || pView->GetObjectShell() != this )
2134 // get any visible frame
2135 pView = SfxViewFrame::GetFirst(this);
2136 if ( pView )
2137 pFrame = pView->GetFrame();
2140 if ( pFrame )
2141 // get topmost window
2142 pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() );
2145 if ( pWindow )
2147 // this frame may be invisible, show it if it is allowed
2148 SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
2149 if ( !pHiddenItem || !pHiddenItem->GetValue() )
2151 pWindow->Show();
2152 pWindow->ToTop();
2156 return pWindow;
2159 String SfxObjectShell::UpdateTitle( SfxMedium* pMed, USHORT nDocViewNumber )
2161 // Titel des Fensters
2162 String aTitle;
2163 if ( pMed )
2165 INetURLObject aTmp( pMed->GetName() );
2166 aTitle = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
2168 else
2170 pMed = GetMedium();
2171 aTitle = GetTitle(SFX_TITLE_CAPTION);
2172 String aName(aTitle);
2173 if ( nDocViewNumber )
2175 aName += ':';
2176 aName += String::CreateFromInt32( nDocViewNumber );
2180 if ( pMed )
2182 SFX_ITEMSET_ARG( pMed->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
2183 if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
2184 aTitle += String( SfxResId(STR_REPAIREDDOCUMENT) );
2187 if ( IsReadOnlyUI() || (pMed && pMed->IsReadOnly()) )
2188 aTitle += String( SfxResId(STR_READONLY) );
2189 else if ( IsDocShared() )
2190 aTitle += String( SfxResId(STR_SHARED) );
2192 return aTitle;
2195 void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode )
2197 eCreateMode = nMode;
2200 BOOL SfxObjectShell::IsInPlaceActive()
2202 if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
2203 return FALSE;
2205 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
2206 return pFrame && pFrame->GetFrame()->IsInPlace();
2209 BOOL SfxObjectShell::IsUIActive()
2211 if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
2212 return FALSE;
2214 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
2215 return pFrame && pFrame->GetFrame()->IsInPlace() && pFrame->GetFrame()->GetWorkWindow_Impl()->IsVisible_Impl();
2218 void SfxObjectShell::UIActivate( BOOL )
2222 void SfxObjectShell::InPlaceActivate( BOOL )
2226 sal_Bool SfxObjectShell::UseInteractionToHandleError(
2227 const uno::Reference< task::XInteractionHandler >& xHandler,
2228 sal_uInt32 nError )
2230 sal_Bool bResult = sal_False;
2232 if ( xHandler.is() )
2236 uno::Any aInteraction;
2237 uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2);
2238 ::framework::ContinuationAbort* pAbort = new ::framework::ContinuationAbort();
2239 ::framework::ContinuationApprove* pApprove = new ::framework::ContinuationApprove();
2240 lContinuations[0] = uno::Reference< task::XInteractionContinuation >(
2241 static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY );
2242 lContinuations[1] = uno::Reference< task::XInteractionContinuation >(
2243 static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY );
2245 task::ErrorCodeRequest aErrorCode;
2246 aErrorCode.ErrCode = nError;
2247 aInteraction <<= aErrorCode;
2249 ::framework::InteractionRequest* pRequest = new ::framework::InteractionRequest(aInteraction,lContinuations);
2250 uno::Reference< task::XInteractionRequest > xRequest(
2251 static_cast< task::XInteractionRequest* >( pRequest ),
2252 uno::UNO_QUERY);
2254 xHandler->handle(xRequest);
2255 bResult = pAbort->isSelected();
2257 catch( uno::Exception& )
2261 return bResult;
2264 sal_Bool SfxObjectShell_Impl::NeedsOfficeUpdateDialog()
2266 // if the configuration is not available for any reason, the default behavior is to show the message
2267 sal_Bool bResult = sal_True;
2271 uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
2272 uno::Reference< uno::XInterface > xCommonConfig(
2273 ::comphelper::ConfigurationHelper::openConfig(
2274 xServiceManager,
2275 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
2276 ::comphelper::ConfigurationHelper::E_STANDARD ),
2277 uno::UNO_SET_THROW );
2279 ::comphelper::ConfigurationHelper::readRelativeKey(
2280 xCommonConfig,
2281 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Load/" ) ),
2282 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowOfficeUpdateDialog" ) ) ) >>= bResult;
2284 catch( uno::Exception& )
2288 return bResult;
2291 sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const
2293 sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE );
2295 const SfxMedium* pMedium( rDocShell.GetMedium() );
2296 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
2297 if ( pMedium )
2299 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False);
2300 if ( pMacroModeItem )
2301 nImposedExecMode = pMacroModeItem->GetValue();
2303 return nImposedExecMode;
2306 sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
2308 const SfxMedium* pMedium( rDocShell.GetMedium() );
2309 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
2310 if ( pMedium )
2312 pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) );
2313 return sal_True;
2316 return sal_False;
2319 ::rtl::OUString SfxObjectShell_Impl::getDocumentLocation() const
2321 ::rtl::OUString sLocation;
2323 const SfxMedium* pMedium( rDocShell.GetMedium() );
2324 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" );
2325 if ( pMedium )
2327 sLocation = pMedium->GetName();
2328 if ( !sLocation.getLength() )
2330 // for documents made from a template: get the name of the template
2331 sLocation = rDocShell.getDocProperties()->getTemplateURL();
2334 return sLocation;
2337 uno::Reference< embed::XStorage > SfxObjectShell_Impl::getLastCommitDocumentStorage()
2339 Reference < embed::XStorage > xStore;
2341 SfxMedium* pMedium( rDocShell.GetMedium() );
2342 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" );
2343 if ( pMedium )
2345 xStore = pMedium->GetLastCommitReadStorage_Impl();
2347 return xStore;
2350 sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const
2352 return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage );
2355 Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const
2357 return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY );
2360 sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState() const
2362 sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() );
2364 if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken )
2366 // if there is a macro signature it must be handled as broken
2367 nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN;
2370 return nSignatureState;
2373 void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const
2375 if ( !bSignatureErrorIsShown )
2377 SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE );
2378 const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = sal_True;
2382 void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage )
2384 if ( !pImp->m_xLogRing.is() )
2388 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
2389 if ( aContext.is() )
2390 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
2392 catch( uno::Exception& )
2396 if ( pImp->m_xLogRing.is() )
2397 pImp->m_xLogRing->logString( aMessage );
2400 namespace {
2402 void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const ::rtl::OUString& aString )
2404 if ( xOutStream.is() )
2406 ::rtl::OString aStrLog = ::rtl::OUStringToOString( aString, RTL_TEXTENCODING_UTF8 );
2407 uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() );
2408 xOutStream->writeBytes( aLogData );
2410 aLogData.realloc( 1 );
2411 aLogData[0] = '\n';
2412 xOutStream->writeBytes( aLogData );
2418 void SfxObjectShell::StoreLog()
2420 if ( !pImp->m_xLogRing.is() )
2424 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
2425 if ( aContext.is() )
2426 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
2428 catch( uno::Exception& )
2432 if ( pImp->m_xLogRing.is() )
2434 ::rtl::OUString aFileURL =
2435 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$BRAND_BASE_DIR/program/bootstrap.ini:UserInstallation}" ) );
2436 ::rtl::Bootstrap::expandMacros( aFileURL );
2438 ::rtl::OUString aBuildID =
2439 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$BRAND_BASE_DIR/program/setup.ini:buildid}" ) );
2440 ::rtl::Bootstrap::expandMacros( aBuildID );
2442 if ( aFileURL.getLength() )
2444 aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/temp/document_io_logring.txt" ) );
2447 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
2448 uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( xFactory->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW );
2449 uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW );
2450 uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW );
2451 uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW );
2452 xTruncate->truncate();
2454 if ( aBuildID.getLength() )
2455 WriteStringInStream( xOutStream, aBuildID );
2457 uno::Sequence< ::rtl::OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog();
2458 for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ )
2459 WriteStringInStream( xOutStream, aLogSeq[nInd] );
2461 catch( uno::Exception& )