Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / doc / objmisc.cxx
blob3bcc77e5ced3a75aa5171f42e097f27cc0421657
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <svl/inetmsg.hxx>
31 #include <tools/diagnose_ex.h>
32 #include <svl/eitem.hxx>
33 #include <svl/stritem.hxx>
34 #include <svl/intitem.hxx>
35 #include <svtools/svparser.hxx> // SvKeyValue
36 #include <osl/mutex.hxx>
37 #include <cppuhelper/exc_hlp.hxx>
39 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
40 #include <com/sun/star/document/XDocumentProperties.hpp>
41 #include <com/sun/star/document/UpdateDocMode.hpp>
42 #include <com/sun/star/script/XTypeConverter.hpp>
43 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
44 #include <com/sun/star/script/FinishEngineEvent.hpp>
45 #include <com/sun/star/script/InterruptReason.hpp>
46 #include <com/sun/star/script/XEngineListener.hpp>
47 #include <com/sun/star/script/XDebugging.hpp>
48 #include <com/sun/star/script/XInvocation.hpp>
49 #include <com/sun/star/script/ContextInformation.hpp>
50 #include <com/sun/star/script/FinishReason.hpp>
51 #include <com/sun/star/script/XEngine.hpp>
52 #include <com/sun/star/script/InterruptEngineEvent.hpp>
53 #include <com/sun/star/script/XLibraryAccess.hpp>
54 #include <com/sun/star/document/MacroExecMode.hpp>
55 #include <com/sun/star/document/XScriptInvocationContext.hpp>
56 #include <com/sun/star/embed/EmbedStates.hpp>
57 #include <com/sun/star/embed/XEmbedPersist.hpp>
58 #include <com/sun/star/util/XModifiable.hpp>
59 #include <com/sun/star/container/XChild.hpp>
60 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
61 #include <com/sun/star/script/provider/XScript.hpp>
62 #include <com/sun/star/script/provider/XScriptProvider.hpp>
63 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
65 #include <toolkit/unohlp.hxx>
67 #include <com/sun/star/uno/Reference.h>
68 #include <com/sun/star/uno/Any.h>
69 #include <com/sun/star/ucb/XContent.hpp>
70 #include <com/sun/star/task/ErrorCodeRequest.hpp>
71 #include <unotools/securityoptions.hxx>
73 #include <comphelper/processfactory.hxx>
74 #include <comphelper/componentcontext.hxx>
75 #include <comphelper/configurationhelper.hxx>
77 #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
78 #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
79 #include <com/sun/star/task/InteractionClassification.hpp>
80 #include <com/sun/star/frame/XModel.hpp>
82 using namespace ::com::sun::star;
83 using namespace ::com::sun::star::uno;
84 using namespace ::com::sun::star::ucb;
85 using namespace ::com::sun::star::document;
86 using namespace ::com::sun::star::frame;
87 using namespace ::com::sun::star::script;
88 using namespace ::com::sun::star::script::provider;
89 using namespace ::com::sun::star::container;
90 #include <basic/sbuno.hxx>
91 #include <basic/sbstar.hxx>
92 #include <basic/basmgr.hxx>
93 #include <vcl/msgbox.hxx>
94 #include <basic/sbx.hxx>
95 #include <svtools/sfxecode.hxx>
96 #include <svtools/ehdl.hxx>
98 #include <unotools/pathoptions.hxx>
99 #include <unotools/ucbhelper.hxx>
100 #include <tools/inetmime.hxx>
101 #include <tools/urlobj.hxx>
102 #include <svl/inettype.hxx>
103 #include <svl/sharecontrolfile.hxx>
104 #include <osl/file.hxx>
105 #include <rtl/bootstrap.hxx>
106 #include <vcl/svapp.hxx>
107 #include <framework/interaction.hxx>
108 #include <framework/documentundoguard.hxx>
109 #include <comphelper/interaction.hxx>
110 #include <comphelper/storagehelper.hxx>
111 #include <comphelper/documentconstants.hxx>
113 #include <sfx2/signaturestate.hxx>
114 #include <sfx2/app.hxx>
115 #include "appdata.hxx"
116 #include <sfx2/request.hxx>
117 #include <sfx2/bindings.hxx>
118 #include "sfx2/sfxresid.hxx"
119 #include <sfx2/docfile.hxx>
120 #include <sfx2/docfilt.hxx>
121 #include <sfx2/objsh.hxx>
122 #include "objshimp.hxx"
123 #include <sfx2/event.hxx>
124 #include "fltfnc.hxx"
125 #include <sfx2/sfx.hrc>
126 #include <sfx2/dispatch.hxx>
127 #include <sfx2/viewfrm.hxx>
128 #include <sfx2/viewsh.hxx>
129 #include <sfx2/ctrlitem.hxx>
130 #include "arrdecl.hxx"
131 #include <sfx2/module.hxx>
132 #include <sfx2/docfac.hxx>
133 #include "helper.hxx"
134 #include "doc.hrc"
135 #include "workwin.hxx"
136 #include "helpid.hrc"
137 #include "../appl/app.hrc"
138 #include <sfx2/sfxdlg.hxx>
139 #include "appbaslib.hxx"
140 #include <openflag.hxx> // SFX_STREAM_READWRITE
142 using namespace ::com::sun::star;
144 // class SfxHeaderAttributes_Impl ----------------------------------------
146 class SfxHeaderAttributes_Impl : public SvKeyValueIterator
148 private:
149 SfxObjectShell* pDoc;
150 SvKeyValueIteratorRef xIter;
151 sal_Bool bAlert;
153 public:
154 SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) :
155 SvKeyValueIterator(), pDoc( pSh ),
156 xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ),
157 bAlert( sal_False ) {}
159 virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); }
160 virtual sal_Bool GetNext( SvKeyValue& rKV ) { return xIter->GetNext( rKV ); }
161 virtual void Append( const SvKeyValue& rKV );
163 void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = sal_False; }
164 void SetAttributes();
165 void SetAttribute( const SvKeyValue& rKV );
168 //=========================================================================
170 sal_uInt16 const aTitleMap_Impl[3][2] =
172 // local remote
173 /* SFX_TITLE_CAPTION */ { SFX_TITLE_FILENAME, SFX_TITLE_TITLE },
174 /* SFX_TITLE_PICKLIST */ { 32, SFX_TITLE_FULLNAME },
175 /* SFX_TITLE_HISTORY */ { 32, SFX_TITLE_FULLNAME }
178 //=========================================================================
180 void SfxObjectShell::AbortImport()
182 pImp->bIsAbortingImport = sal_True;
185 //-------------------------------------------------------------------------
187 sal_Bool SfxObjectShell::IsAbortingImport() const
189 return pImp->bIsAbortingImport;
192 //-------------------------------------------------------------------------
194 uno::Reference<document::XDocumentProperties>
195 SfxObjectShell::getDocProperties()
197 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
198 GetModel(), uno::UNO_QUERY_THROW);
199 uno::Reference<document::XDocumentProperties> xDocProps(
200 xDPS->getDocumentProperties());
201 DBG_ASSERT(xDocProps.is(),
202 "SfxObjectShell: model has no DocumentProperties");
203 return xDocProps;
206 //-------------------------------------------------------------------------
208 void SfxObjectShell::DoFlushDocInfo()
212 //-------------------------------------------------------------------------
214 // Note: the only thing that calls this is the modification event handler
215 // that is installed at the XDocumentProperties
216 void SfxObjectShell::FlushDocInfo()
218 if ( IsLoading() )
219 return;
221 SetModified(sal_True);
222 uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
223 DoFlushDocInfo(); // call template method
224 ::rtl::OUString url(xDocProps->getAutoloadURL());
225 sal_Int32 delay(xDocProps->getAutoloadSecs());
226 SetAutoLoad( INetURLObject(url), delay * 1000,
227 (delay > 0) || !url.isEmpty() );
230 //-------------------------------------------------------------------------
232 void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage )
234 if(pImp->lErr==ERRCODE_NONE)
236 pImp->lErr=lErr;
238 if( lErr != ERRCODE_NONE && !aLogMessage.isEmpty() )
239 AddLog( aLogMessage );
243 //-------------------------------------------------------------------------
245 sal_uInt32 SfxObjectShell::GetError() const
247 return ERRCODE_TOERROR(GetErrorCode());
250 //-------------------------------------------------------------------------
252 sal_uInt32 SfxObjectShell::GetErrorCode() const
254 sal_uInt32 lError=pImp->lErr;
255 if(!lError && GetMedium())
256 lError=GetMedium()->GetErrorCode();
257 return lError;
260 //-------------------------------------------------------------------------
262 void SfxObjectShell::ResetError()
264 if( pImp->lErr != ERRCODE_NONE )
265 AddLog( ::rtl::OUString( OSL_LOG_PREFIX "Resetting Error." ) );
267 pImp->lErr=0;
268 SfxMedium * pMed = GetMedium();
269 if( pMed )
270 pMed->ResetError();
273 //-------------------------------------------------------------------------
275 sal_Bool SfxObjectShell::IsTemplate() const
277 return pImp->bIsTemplate;
280 //-------------------------------------------------------------------------
282 void SfxObjectShell::EnableSetModified( sal_Bool bEnable )
284 #ifdef DBG_UTIL
285 if ( bEnable == pImp->m_bEnableSetModified )
286 DBG_WARNING( "SFX_PERSIST: EnableSetModified 2x called with the same value" );
287 #endif
288 pImp->m_bEnableSetModified = bEnable;
291 //-------------------------------------------------------------------------
293 sal_Bool SfxObjectShell::IsEnableSetModified() const
295 return pImp->m_bEnableSetModified && !IsReadOnly();
298 //-------------------------------------------------------------------------
300 sal_Bool SfxObjectShell::IsModified()
302 if ( pImp->m_bIsModified )
303 return sal_True;
305 if ( !pImp->m_xDocStorage.is() || IsReadOnly() )
307 // if the document still has no storage and is not set to be modified explicitly it is not modified
308 // a readonly document is also not modified
310 return sal_False;
313 uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
314 for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
316 uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
317 OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
318 if ( xObj.is() )
322 sal_Int32 nState = xObj->getCurrentState();
323 if ( nState != embed::EmbedStates::LOADED )
325 uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
326 if ( xModifiable.is() && xModifiable->isModified() )
327 return sal_True;
330 catch( uno::Exception& )
335 return sal_False;
338 //-------------------------------------------------------------------------
340 void SfxObjectShell::SetModified( sal_Bool bModifiedP )
342 #ifdef DBG_UTIL
343 if ( !bModifiedP && !IsEnableSetModified() )
344 DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), although IsEnableSetModified() == sal_False" );
345 #endif
347 if( !IsEnableSetModified() )
348 return;
350 if( pImp->m_bIsModified != bModifiedP )
352 pImp->m_bIsModified = bModifiedP;
353 ModifyChanged();
357 //-------------------------------------------------------------------------
359 void SfxObjectShell::ModifyChanged()
361 if ( pImp->bClosing )
362 // SetModified dispose of the models!
363 return;
365 {DBG_CHKTHIS(SfxObjectShell, 0);}
367 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
368 if ( pViewFrame )
369 pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS );
371 Invalidate( SID_SIGNATURE );
372 Invalidate( SID_MACRO_SIGNATURE );
373 Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) ); // xmlsec05, signed state might change in title...
375 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) );
378 //-------------------------------------------------------------------------
380 sal_Bool SfxObjectShell::IsReadOnlyUI() const
382 /* [Description]
384 Returns sal_True if the document for the UI is treated as r/o. This is
385 regardless of the actual r/o, which can be checked with <IsReadOnly()>.
389 return pImp->bReadOnlyUI;
392 //-------------------------------------------------------------------------
394 sal_Bool SfxObjectShell::IsReadOnlyMedium() const
396 /* [Description]
398 Returns sal_True when the medium is r/o, for instance when opened as r/o.
402 if ( !pMedium )
403 return sal_True;
404 return pMedium->IsReadOnly();
407 bool SfxObjectShell::IsOriginallyReadOnlyMedium() const
409 return pMedium == 0 || pMedium->IsOriginallyReadOnly();
412 //-------------------------------------------------------------------------
414 void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly )
416 /* [Description]
418 Turns the document in an r/o and r/w state respectively without reloading
419 it and without changing the open mode of the medium.
423 if ( bReadOnly != pImp->bReadOnlyUI )
425 pImp->bReadOnlyUI = bReadOnly;
426 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
430 //-------------------------------------------------------------------------
432 void SfxObjectShell::SetReadOnly()
434 // Let the document be completely readonly, means that the
435 // medium open mode is adjusted accordingly, and the write lock
436 // on the file is removed.
438 if ( pMedium && !IsReadOnlyMedium() )
440 sal_Bool bWasROUI = IsReadOnly();
442 pMedium->UnlockFile( sal_False );
444 // the storage-based mediums are already based on the temporary file
445 // so UnlockFile has already closed the locking stream
446 if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() )
447 pMedium->CloseInStream();
449 pMedium->SetOpenMode( SFX_STREAM_READONLY, sal_True );
450 pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
452 if ( !bWasROUI )
453 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
456 //-------------------------------------------------------------------------
458 sal_Bool SfxObjectShell::IsReadOnly() const
460 return pImp->bReadOnlyUI || pMedium == 0;
463 //-------------------------------------------------------------------------
465 sal_Bool SfxObjectShell::IsInModalMode() const
467 return pImp->bModalMode || pImp->bRunningMacro;
470 sal_Bool SfxObjectShell::AcceptStateUpdate() const
472 return !IsInModalMode();
475 //-------------------------------------------------------------------------
477 void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal )
479 if ( !pImp->bRunningMacro != !bModal )
481 pImp->bRunningMacro = bModal;
482 Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
486 //-------------------------------------------------------------------------
488 void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal )
490 // Broadcast only if modified, or otherwise it will possibly go into
491 // an endless loop
492 if ( !pImp->bModalMode != !bModal )
494 // Central count
495 sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode;
496 if ( bModal )
497 ++rDocModalCount;
498 else
499 --rDocModalCount;
501 // Switch
502 pImp->bModalMode = bModal;
503 Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
507 //--------------------------------------------------------------------
508 sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave )
510 sal_Bool bResult = sal_True;
512 if ( bShared != IsDocShared() )
514 ::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
516 if ( aOrigURL.isEmpty() && bSave )
518 // this is a new document, let it be stored before switching to the shared mode;
519 // the storing should be done without shared flag, since it is possible that the
520 // target location does not allow to create sharing control file;
521 // the shared flag will be set later after creation of sharing control file
522 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
524 if ( pViewFrame )
526 // TODO/LATER: currently the application guards against the reentrance problem
527 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
528 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
529 bResult = ( pResult && pResult->GetValue() );
530 if ( bResult )
531 aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
535 sal_Bool bOldValue = HasSharedXMLFlagSet();
536 SetSharedXMLFlag( bShared );
538 sal_Bool bRemoveEntryOnError = sal_False;
539 if ( bResult && bShared )
543 ::svt::ShareControlFile aControlFile( aOrigURL );
544 aControlFile.InsertOwnEntry();
545 bRemoveEntryOnError = sal_True;
547 catch( uno::Exception& )
549 bResult = sal_False;
553 if ( bResult && bSave )
555 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
557 if ( pViewFrame )
559 // TODO/LATER: currently the application guards against the reentrance problem
560 SetModified( sal_True ); // the modified flag has to be set to let the document be stored with the shared flag
561 const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
562 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
563 bResult = ( pResult && pResult->GetValue() );
567 if ( bResult )
569 // TODO/LATER: Is it possible that the following calls fail?
570 if ( bShared )
572 pImp->m_aSharedFileURL = aOrigURL;
573 GetMedium()->SwitchDocumentToTempFile();
575 else
577 ::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
578 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
579 pImp->m_aSharedFileURL = ::rtl::OUString();
581 // now remove the temporary file the document was based on
582 ::utl::UCBContentHelper::Kill( aTempFileURL );
586 // aOrigURL can not be used since it contains an old value
587 ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
588 aControlFile.RemoveFile();
590 catch( uno::Exception& )
595 else
597 // the saving has failed!
598 if ( bRemoveEntryOnError )
602 ::svt::ShareControlFile aControlFile( aOrigURL );
603 aControlFile.RemoveEntry();
605 catch( uno::Exception& )
609 SetSharedXMLFlag( bOldValue );
612 else
613 bResult = sal_False; // the second switch to the same mode
615 if ( bResult )
616 SetTitle( String() );
618 return bResult;
621 //--------------------------------------------------------------------
623 void SfxObjectShell::FreeSharedFile()
625 if ( pMedium )
626 FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
629 //--------------------------------------------------------------------
630 void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL )
632 SetSharedXMLFlag( sal_False );
634 if ( IsDocShared() && !aTempFileURL.isEmpty()
635 && !::utl::UCBContentHelper::EqualURLs( aTempFileURL, GetSharedFileURL() ) )
637 if ( pImp->m_bAllowShareControlFileClean )
641 ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
642 aControlFile.RemoveEntry();
644 catch( uno::Exception& )
649 // the cleaning is forbidden only once
650 pImp->m_bAllowShareControlFileClean = sal_True;
652 // now remove the temporary file the document is based currently on
653 ::utl::UCBContentHelper::Kill( aTempFileURL );
655 pImp->m_aSharedFileURL = ::rtl::OUString();
659 //--------------------------------------------------------------------
660 void SfxObjectShell::DoNotCleanShareControlFile()
662 pImp->m_bAllowShareControlFileClean = sal_False;
665 //--------------------------------------------------------------------
666 void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const
668 pImp->m_bSharedXMLFlag = bFlag;
671 //--------------------------------------------------------------------
672 sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const
674 return pImp->m_bSharedXMLFlag;
677 //--------------------------------------------------------------------
679 sal_Bool SfxObjectShell::IsDocShared() const
681 return ( !pImp->m_aSharedFileURL.isEmpty() );
684 //--------------------------------------------------------------------
686 ::rtl::OUString SfxObjectShell::GetSharedFileURL() const
688 return pImp->m_aSharedFileURL;
691 //--------------------------------------------------------------------
693 Size SfxObjectShell::GetFirstPageSize()
695 return GetVisArea(ASPECT_THUMBNAIL).GetSize();
699 //--------------------------------------------------------------------
701 IndexBitSet& SfxObjectShell::GetNoSet_Impl()
703 return pImp->aBitSet;
706 //--------------------------------------------------------------------
707 // changes the title of the document
709 void SfxObjectShell::SetTitle
711 const String& rTitle // the new Document Title
714 /* [Description]
716 With this method, the title of the document can be set.
717 This corresponds initially to the full file name. A setting of the
718 title does not affect the file name, but it will be shown in the
719 Caption-Bars of the MDI-window.
723 DBG_CHKTHIS(SfxObjectShell, 0);
725 // Nothing to do?
726 if ( ( ( HasName() && pImp->aTitle == rTitle )
727 || ( !HasName() && GetTitle() == rTitle ) )
728 && !IsDocShared() )
729 return;
731 SfxApplication *pSfxApp = SFX_APP();
733 // If possible relase the unnamed number.
734 if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber )
736 pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
737 pImp->bIsNamedVisible = 0;
740 // Set Title
741 pImp->aTitle = rTitle;
743 // Notification
744 if ( GetMedium() )
746 SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
747 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
751 //--------------------------------------------------------------------
753 #if OSL_DEBUG_LEVEL > 1
754 String X(const String &rRet)
756 if ( !rRet.Len() )
757 return DEFINE_CONST_UNICODE( "-empty-" );
758 return rRet;
760 #else
761 #define X(ret) ret
762 #endif
764 //--------------------------------------------------------------------
765 String SfxObjectShell::GetTitle
767 sal_uInt16 nMaxLength /* 0 (default)
768 the title itself, as it is
770 1 (==SFX_TITLE_FILENAME)
771 provides the logical file name without path
772 (under WNT depending on the system settings
773 without extension)
775 2 (==SFX_TITLE_FULLNAME)
776 provides the logical file names with full path
777 (remote =>:: com:: sun:: star:: util:: URL)
779 3 (==SFX_TITLE_APINAME)
780 provides the logical filname without path
781 and extension
783 4 (==SFX_TITLE_DETECT)
784 provides the complete title, if not set yet
785 it will be created from DocInfo or the name of
786 the medium.
788 5 (==SFX_TITLE_CAPTION)
789 provides the Title just like MB now in the
790 CaptionBar view
792 6 (==SFX_TITLE_PICKLIST)
793 returns the Title, just like MB now would
794 display it in the in the PickList
796 7 (==SFX_TITLE_HISTORY)
797 returns the Title just like MB now would
798 display it in the in the History
800 10 bis USHRT_MAX
801 provides the 'nMaxLength' of the logical
802 file name including the path
803 (remote => ::com::sun::star::util::URL)
805 ) const
807 /* [Description]
809 Returns the title or logical file name of the document, depending on the
810 'nMaxLength'.
812 If the file name with path is used, the Name shortened by replacing one or
813 more directory names with "...", URLs are currently always returned
814 in complete form.
818 SfxMedium *pMed = GetMedium();
819 if ( IsLoading() )
820 return String();
822 // Create Title?
823 if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() )
825 static sal_Bool bRecur = sal_False;
826 if ( bRecur )
827 return DEFINE_CONST_UNICODE( "-not available-" );
828 bRecur = sal_True;
830 String aTitle;
831 SfxObjectShell *pThis = (SfxObjectShell*) this;
833 if ( pMed )
835 SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
836 if ( pNameItem )
837 aTitle = pNameItem->GetValue();
840 if ( !aTitle.Len() )
841 aTitle = GetTitle( SFX_TITLE_FILENAME );
843 if ( IsTemplate() )
844 pThis->SetTitle( aTitle );
845 bRecur = sal_False;
846 return X(aTitle);
848 else if (SFX_TITLE_APINAME == nMaxLength )
849 return X(GetAPIName());
851 // Special case templates:
852 if( IsTemplate() && pImp->aTitle.Len() &&
853 ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
854 return X(pImp->aTitle);
856 // Picklist/Caption is mapped
857 if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
859 // If a specific title was given at open:
860 // important for URLs: use INET_PROT_FILE for which the set title is not
861 // considered. (See below, analysis of aTitleMap_Impl)
862 SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
863 if ( pNameItem )
864 return X( pNameItem->GetValue() );
867 // Still unnamed?
868 DBG_ASSERT( !HasName() || pMed, "HasName() but no Medium?!?" );
869 if ( !HasName() || !pMed )
871 // Title already set?
872 if ( pImp->aTitle.Len() )
873 return X(pImp->aTitle);
875 // must it be numbered?
876 rtl::OUString aNoName(SFX2_RESSTR(STR_NONAME));
877 if (pImp->bIsNamedVisible)
879 // Append number
880 aNoName += rtl::OUString::valueOf(static_cast<sal_Int32>(pImp->nVisualDocumentNumber));
883 // Document called "noname" for the time being
884 return X(aNoName);
887 const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
888 if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
890 sal_uInt16 nRemote;
891 if( !pMed || aURL.GetProtocol() == INET_PROT_FILE )
892 nRemote = 0;
893 else
894 nRemote = 1;
895 nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote];
898 // Local file?
899 if ( aURL.GetProtocol() == INET_PROT_FILE )
901 String aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() );
902 if ( nMaxLength == SFX_TITLE_FULLNAME )
903 return X( aName );
904 else if ( nMaxLength == SFX_TITLE_FILENAME )
905 return X( aURL.getName( INetURLObject::LAST_SEGMENT,
906 true, INetURLObject::DECODE_WITH_CHARSET ) );
907 else if ( !pImp->aTitle.Len() )
908 pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT,
909 true, INetURLObject::DECODE_WITH_CHARSET );
911 else
913 // ::com::sun::star::util::URL-Versions
914 if ( nMaxLength >= SFX_TITLE_MAXLEN )
916 String aComplete( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
917 if( aComplete.Len() > nMaxLength )
919 String aRet( DEFINE_CONST_UNICODE( "..." ) );
920 aRet += aComplete.Copy( aComplete.Len() - nMaxLength + 3, nMaxLength - 3 );
921 return X( aRet );
923 else
924 return X( aComplete );
926 else if ( nMaxLength == SFX_TITLE_FILENAME )
928 String aName( aURL.GetBase() );
929 aName = INetURLObject::decode( aName, INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET );
930 if( !aName.Len() )
931 aName = aURL.GetURLNoPass();
932 return X(aName);
934 else if ( nMaxLength == SFX_TITLE_FULLNAME )
935 return X(aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ));
937 // Generate Title from file name if possible
938 if ( !pImp->aTitle.Len() )
939 pImp->aTitle = aURL.GetBase();
941 // workaround for the case when the name can not be retrieved from URL by INetURLObject
942 if ( !pImp->aTitle.Len() )
943 pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
946 // Complete Title
947 return X(pImp->aTitle);
950 //--------------------------------------------------------------------
952 void SfxObjectShell::InvalidateName()
954 /* [Description]
956 Returns the title of the new document, DocInfo-Title or
957 File name. Is required for loading from template or SaveAs.
961 pImp->aTitle.Erase();
962 SetName( GetTitle( SFX_TITLE_APINAME ) );
964 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
967 //--------------------------------------------------------------------
969 void SfxObjectShell::SetNamedVisibility_Impl()
971 if ( !pImp->bIsNamedVisible )
973 pImp->bIsNamedVisible = sal_True;
974 if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && !pImp->aTitle.Len() )
976 pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex();
977 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
981 SetName( GetTitle(SFX_TITLE_APINAME) );
984 void SfxObjectShell::SetNoName()
986 bHasName = 0;
987 bIsTmp = sal_True;
988 GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() );
991 //--------------------------------------------------------------------
993 void SfxObjectShell::MemoryError()
997 //--------------------------------------------------------------------
999 SfxProgress* SfxObjectShell::GetProgress() const
1001 return pImp->pProgress;
1004 //--------------------------------------------------------------------
1006 void SfxObjectShell::SetProgress_Impl
1008 SfxProgress *pProgress /* to started <SfxProgress> or 0,
1009 if the progress is to be reset */
1012 /* [Description]
1014 Internal method to set or reset the Progress modes for
1015 SfxObjectShell.
1019 DBG_ASSERT( ( !pImp->pProgress && pProgress ) ||
1020 ( pImp->pProgress && !pProgress ),
1021 "Progress activation/deacitivation mismatch" );
1022 pImp->pProgress = pProgress;
1025 //--------------------------------------------------------------------
1027 void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
1029 SfxApplication* pSfxApp = SFX_APP();
1030 if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame().IsClosing_Impl() )
1032 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
1033 if ( !pHiddenItem || !pHiddenItem->GetValue() )
1035 sal_uInt16 nId = pImp->nEventId;
1036 pImp->nEventId = 0;
1037 if ( nId == SFX_EVENT_OPENDOC )
1038 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC), this, pFrame->GetFrame().GetController() ), sal_False);
1039 else if (nId == SFX_EVENT_CREATEDOC )
1040 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC), this, pFrame->GetFrame().GetController() ), sal_False);
1045 //--------------------------------------------------------------------
1047 void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId )
1049 if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC )
1050 pImp->nEventId = nId;
1053 //--------------------------------------------------------------------
1055 void SfxObjectShell::RegisterTransfer( SfxMedium& rMedium )
1056 /* [Description]
1058 All media, which are placed in order to load parts of a document must be
1059 registered by a related SfxObjectShell. Thus documents can be canceled.
1062 rMedium.SetReferer( GetMedium()->GetName() );
1065 //-------------------------------------------------------------------------
1067 void SfxObjectShell::PrepareReload( )
1068 /* [Description]
1070 Is called before the Reload and gives the opportunity to clear any caches.
1075 // Can be moved to frame.cxx, when 358+36x-State have been merged
1077 sal_Bool SfxFrame::IsAutoLoadLocked_Impl() const
1079 // Its own Docucument is locked?
1080 const SfxObjectShell* pObjSh = GetCurrentDocument();
1081 if ( !pObjSh || !pObjSh->IsAutoLoadLocked() )
1082 return sal_False;
1084 // Its children are locked?
1085 for ( sal_uInt16 n = GetChildFrameCount(); n--; )
1086 if ( !GetChildFrame(n)->IsAutoLoadLocked_Impl() )
1087 return sal_False;
1089 // otherwise allow AutoLoad
1090 return sal_True;
1093 //-------------------------------------------------------------------------
1095 sal_Bool SfxObjectShell::IsAutoLoadLocked() const
1097 /* Returns whether an Autoload is allowed to be executed. Before the
1098 surrounding FrameSet of the AutoLoad is also taken into account as well.
1102 return !IsReadOnly() || pImp->nAutoLoadLocks > 0;
1105 //-------------------------------------------------------------------------
1106 void SfxObjectShell::BreakMacroSign_Impl( sal_Bool bBreakMacroSign )
1108 pImp->m_bMacroSignBroken = bBreakMacroSign;
1111 //-------------------------------------------------------------------------
1112 void SfxObjectShell::CheckSecurityOnLoading_Impl()
1114 uno::Reference< task::XInteractionHandler > xInteraction;
1115 if ( GetMedium() )
1116 xInteraction = GetMedium()->GetInteractionHandler();
1118 // check if there is a broken signature...
1119 CheckForBrokenDocSignatures_Impl( xInteraction );
1121 CheckEncryption_Impl( xInteraction );
1123 // check macro security
1124 pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
1127 //-------------------------------------------------------------------------
1128 void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
1130 ::rtl::OUString aVersion;
1131 sal_Bool bIsEncrypted = sal_False;
1132 sal_Bool bHasNonEncrypted = sal_False;
1136 uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
1137 xPropSet->getPropertyValue( ::rtl::OUString( "Version" ) ) >>= aVersion;
1138 xPropSet->getPropertyValue( ::rtl::OUString( "HasEncryptedEntries" ) ) >>= bIsEncrypted;
1139 xPropSet->getPropertyValue( ::rtl::OUString( "HasNonEncryptedEntries" ) ) >>= bHasNonEncrypted;
1141 catch( uno::Exception& )
1145 if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
1147 // this is ODF1.2 or later
1148 if ( bIsEncrypted && bHasNonEncrypted )
1150 if ( !pImp->m_bIncomplEncrWarnShown )
1152 // this is an encrypted document with nonencrypted streams inside, show the warning
1153 ::com::sun::star::task::ErrorCodeRequest aErrorCode;
1154 aErrorCode.ErrCode = ERRCODE_SFX_INCOMPLETE_ENCRYPTION;
1156 SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
1157 pImp->m_bIncomplEncrWarnShown = sal_True;
1160 // broken signatures imply no macro execution at all
1161 pImp->aMacroMode.disallowMacroExecution();
1166 //-------------------------------------------------------------------------
1167 void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
1169 sal_Int16 nSignatureState = GetDocumentSignatureState();
1170 bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN );
1171 if ( !bSignatureBroken )
1172 return;
1174 pImp->showBrokenSignatureWarning( xHandler );
1176 // broken signatures imply no macro execution at all
1177 pImp->aMacroMode.disallowMacroExecution();
1180 //-------------------------------------------------------------------------
1181 void SfxObjectShell::SetAutoLoad(
1182 const INetURLObject& rUrl, sal_uInt32 nTime, sal_Bool bReload )
1184 if ( pImp->pReloadTimer )
1185 DELETEZ(pImp->pReloadTimer);
1186 if ( bReload )
1188 pImp->pReloadTimer = new AutoReloadTimer_Impl(
1189 rUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ),
1190 nTime, bReload, this );
1191 pImp->pReloadTimer->Start();
1195 sal_Bool SfxObjectShell::IsLoadingFinished() const
1197 return ( pImp->nLoadedFlags == SFX_LOADED_ALL );
1200 void impl_addToModelCollection(const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel);
1201 void SfxObjectShell::InitOwnModel_Impl()
1203 if ( !pImp->bModelInitialized )
1205 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
1206 if ( pSalvageItem )
1208 pImp->aTempName = pMedium->GetPhysicalName();
1209 pMedium->GetItemSet()->ClearItem( SID_DOC_SALVAGE );
1210 pMedium->GetItemSet()->ClearItem( SID_FILE_NAME );
1211 pMedium->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetOrigURL() ) );
1213 else
1215 pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
1216 pMedium->GetItemSet()->ClearItem( SID_DOCUMENT );
1219 pMedium->GetItemSet()->ClearItem( SID_REFERER );
1220 uno::Reference< frame::XModel > xModel ( GetModel(), uno::UNO_QUERY );
1221 if ( xModel.is() )
1223 ::rtl::OUString aURL = GetMedium()->GetOrigURL();
1224 SfxItemSet *pSet = GetMedium()->GetItemSet();
1225 if ( !GetMedium()->IsReadOnly() )
1226 pSet->ClearItem( SID_INPUTSTREAM );
1227 uno::Sequence< beans::PropertyValue > aArgs;
1228 TransformItems( SID_OPENDOC, *pSet, aArgs );
1229 xModel->attachResource( aURL, aArgs );
1230 impl_addToModelCollection(xModel);
1233 pImp->bModelInitialized = sal_True;
1237 void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags )
1239 sal_Bool bSetModifiedTRUE = sal_False;
1240 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1241 if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
1242 && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ))
1244 pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT;
1245 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes();
1246 pImp->bImportDone = sal_True;
1247 if( !IsAbortingImport() )
1248 PositionView_Impl();
1250 if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() )
1251 SetReadOnly();
1253 // Salvage
1254 if ( pSalvageItem )
1255 bSetModifiedTRUE = sal_True;
1257 if ( !IsEnableSetModified() )
1258 EnableSetModified( sal_True );
1260 if( !bSetModifiedTRUE && IsEnableSetModified() )
1261 SetModified( sal_False );
1263 CheckSecurityOnLoading_Impl();
1265 bHasName = sal_True; // the document is loaded, so the name should already available
1266 GetTitle( SFX_TITLE_DETECT );
1267 InitOwnModel_Impl();
1268 pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT;
1271 if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES )
1272 && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES ))
1274 pImp->nFlagsInProgress |= SFX_LOADED_IMAGES;
1275 uno::Reference<document::XDocumentProperties> xDocProps(
1276 getDocProperties());
1277 ::rtl::OUString url(xDocProps->getAutoloadURL());
1278 sal_Int32 delay(xDocProps->getAutoloadSecs());
1279 SetAutoLoad( INetURLObject(url), delay * 1000,
1280 (delay > 0) || !url.isEmpty() );
1281 if( !bSetModifiedTRUE && IsEnableSetModified() )
1282 SetModified( sal_False );
1283 Invalidate( SID_SAVEASDOC );
1284 pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES;
1287 pImp->nLoadedFlags |= nFlags;
1289 if ( !pImp->nFlagsInProgress )
1291 // in case of reentrance calls the first called FinishedLoading() call on the stack
1292 // should do the notification, in result the notification is done when all the FinishedLoading() calls are finished
1294 if ( bSetModifiedTRUE )
1295 SetModified( sal_True );
1296 else
1297 SetModified( sal_False );
1299 if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) )
1301 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
1302 sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
1304 // closing the streams on loading should be under control of SFX!
1305 DBG_ASSERT( pMedium->IsOpen(), "Don't close the medium when loading documents!" );
1307 if ( bTemplate )
1309 TemplateDisconnectionAfterLoad();
1311 else
1313 // if a readonly medium has storage then it's stream is already based on temporary file
1314 if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() )
1315 // don't lock file opened read only
1316 pMedium->CloseInStream();
1320 SetInitialized_Impl( false );
1322 // Title is not available until loading has finished
1323 Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );
1324 if ( pImp->nEventId )
1325 PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
1329 //-------------------------------------------------------------------------
1330 extern void SetTemplate_Impl( const String&, const String&, SfxObjectShell* );
1332 void SfxObjectShell::TemplateDisconnectionAfterLoad()
1334 // document is created from a template
1335 //TODO/LATER: should the templates always be XML docs!
1337 SfxMedium* pTmpMedium = pMedium;
1338 if ( pTmpMedium )
1340 String aName( pTmpMedium->GetName() );
1341 SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
1342 String aTemplateName;
1343 if ( pTemplNamItem )
1344 aTemplateName = pTemplNamItem->GetValue();
1345 else
1347 // !TODO/LATER: what's this?!
1348 // Interactiv ( DClick, Contextmenu ) no long name is included
1349 aTemplateName = getDocProperties()->getTitle();
1350 if ( !aTemplateName.Len() )
1352 INetURLObject aURL( aName );
1353 aURL.CutExtension();
1354 aTemplateName = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1358 // set medium to noname
1359 pTmpMedium->SetName( String(), sal_True );
1360 pTmpMedium->Init_Impl();
1362 // drop resource
1363 SetNoName();
1364 InvalidateName();
1366 if( IsPackageStorageFormat_Impl( *pTmpMedium ) )
1368 // untitled document must be based on temporary storage
1369 // the medium should not dispose the storage in this case
1370 uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1371 GetStorage()->copyToStorage( xTmpStor );
1373 // the medium should disconnect from the original location
1374 // the storage should not be disposed since the document is still
1375 // based on it, but in DoSaveCompleted it will be disposed
1376 pTmpMedium->CanDisposeStorage_Impl( sal_False );
1377 pTmpMedium->Close();
1379 // setting the new storage the medium will be based on
1380 pTmpMedium->SetStorage_Impl( xTmpStor );
1382 ForgetMedium();
1383 if( !DoSaveCompleted( pTmpMedium ) )
1384 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( OSL_LOG_PREFIX ) );
1385 else
1387 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1388 sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
1390 if ( !bSalvage )
1392 // some further initializations for templates
1393 SetTemplate_Impl( aName, aTemplateName, this );
1396 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
1397 pTmpMedium->CanDisposeStorage_Impl( sal_False );
1400 else
1402 // some further initializations for templates
1403 SetTemplate_Impl( aName, aTemplateName, this );
1404 pTmpMedium->CreateTempFile( sal_True );
1407 // templates are never readonly
1408 pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
1409 pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True );
1411 // notifications about possible changes in readonly state and document info
1412 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
1414 // created untitled document can't be modified
1415 SetModified( sal_False );
1419 //-------------------------------------------------------------------------
1421 void SfxObjectShell::PositionView_Impl()
1423 MarkData_Impl *pMark = Get_Impl()->pMarkData;
1424 if( pMark )
1426 SfxViewShell* pSh = pMark->pFrame->GetViewShell();
1427 if( pMark->aUserData.Len() )
1428 pSh->ReadUserData( pMark->aUserData, sal_True );
1429 else if( pMark->aMark.Len() )
1430 pSh->JumpToMark( pMark->aMark );
1431 DELETEZ( Get_Impl()->pMarkData );
1435 //-------------------------------------------------------------------------
1437 sal_Bool SfxObjectShell::IsLoading() const
1438 /* [Description]
1440 Has FinishedLoading been called?
1443 return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT );
1446 //-------------------------------------------------------------------------
1448 void SfxObjectShell::CancelTransfers()
1449 /* [Description]
1451 Here can Transfers get canceled, which were not regestered
1452 by RegisterTransfer.
1455 if( ( pImp->nLoadedFlags & SFX_LOADED_ALL ) != SFX_LOADED_ALL )
1457 AbortImport();
1458 if( IsLoading() )
1459 FinishedLoading( SFX_LOADED_ALL );
1463 //-------------------------------------------------------------------------
1465 AutoReloadTimer_Impl::AutoReloadTimer_Impl(
1466 const String& rURL, sal_uInt32 nTime, sal_Bool bReloadP, SfxObjectShell* pSh )
1467 : aUrl( rURL ), bReload( bReloadP ), pObjSh( pSh )
1469 SetTimeout( nTime );
1472 //-------------------------------------------------------------------------
1474 void AutoReloadTimer_Impl::Timeout()
1476 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjSh );
1478 if ( pFrame )
1480 // Not possible/meanigfull at the moment?
1481 if ( !pObjSh->CanReload_Impl() || pObjSh->IsAutoLoadLocked() || Application::IsUICaptured() )
1483 // Allow a retry
1484 Start();
1485 return;
1488 SfxAllItemSet aSet( SFX_APP()->GetPool() );
1489 aSet.Put( SfxBoolItem( SID_AUTOLOAD, sal_True ) );
1490 if ( aUrl.Len() )
1491 aSet.Put( SfxStringItem( SID_FILE_NAME, aUrl ) );
1492 SfxRequest aReq( SID_RELOAD, 0, aSet );
1493 pObjSh->Get_Impl()->pReloadTimer = 0;
1494 delete this;
1495 pFrame->ExecReload_Impl( aReq );
1496 return;
1499 pObjSh->Get_Impl()->pReloadTimer = 0;
1500 delete this;
1503 SfxModule* SfxObjectShell::GetModule() const
1505 return GetFactory().GetModule();
1508 ErrCode SfxObjectShell::CallBasic( const String& rMacro,
1509 const String& rBasic, SbxArray* pArgs,
1510 SbxValue* pRet )
1512 SfxApplication* pApp = SFX_APP();
1513 if( pApp->GetName() != rBasic )
1515 if ( !AdjustMacroMode( String() ) )
1516 return ERRCODE_IO_ACCESSDENIED;
1519 BasicManager *pMgr = GetBasicManager();
1520 if( pApp->GetName() == rBasic )
1521 pMgr = pApp->GetBasicManager();
1522 ErrCode nRet = SfxApplication::CallBasic( rMacro, pMgr, pArgs, pRet );
1523 return nRet;
1526 namespace
1528 static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext )
1532 Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY );
1533 if ( !xScripts.is() )
1535 Reference< XScriptInvocationContext > xContext( _rxScriptContext, UNO_QUERY_THROW );
1536 xScripts.set( xContext->getScriptContainer(), UNO_SET_THROW );
1539 return xScripts->getAllowMacroExecution();
1541 catch( const Exception& )
1543 DBG_UNHANDLED_EXCEPTION();
1545 return false;
1549 ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL,
1550 const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError, const ::com::sun::star::uno::Any* pCaller )
1552 OSL_TRACE( "in CallXScript" );
1553 ErrCode nErr = ERRCODE_NONE;
1555 bool bIsDocumentScript = ( _rScriptURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "location=document" ) ) >= 0 );
1556 // TODO: we should parse the URL, and check whether there is a parameter with this name.
1557 // Otherwise, we might find too much.
1558 if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
1559 return ERRCODE_IO_ACCESSDENIED;
1561 bool bCaughtException = false;
1562 Any aException;
1565 // obtain/create a script provider
1566 Reference< provider::XScriptProvider > xScriptProvider;
1567 Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );
1568 if ( xSPS.is() )
1569 xScriptProvider.set( xSPS->getScriptProvider() );
1571 if ( !xScriptProvider.is() )
1573 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
1574 Reference< provider::XScriptProviderFactory > xScriptProviderFactory(
1575 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
1576 xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW );
1579 // ry to protect the invocation context's undo manager (if present), just in case the script tampers with it
1580 ::framework::DocumentUndoGuard aUndoGuard( _rxScriptContext.get() );
1582 // obtain the script, and execute it
1583 Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW );
1584 if ( pCaller && pCaller->hasValue() )
1586 Reference< beans::XPropertySet > xProps( xScript, uno::UNO_QUERY );
1587 if ( xProps.is() )
1589 Sequence< uno::Any > aArgs( 1 );
1590 aArgs[ 0 ] = *pCaller;
1591 xProps->setPropertyValue( rtl::OUString("Caller"), uno::makeAny( aArgs ) );
1594 aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam );
1596 catch ( const uno::Exception& )
1598 aException = ::cppu::getCaughtException();
1599 bCaughtException = sal_True;
1600 nErr = ERRCODE_BASIC_INTERNAL_ERROR;
1603 if ( bCaughtException && bRaiseError )
1605 ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg;
1606 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1607 if ( pFact )
1608 pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) );
1609 OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" );
1611 if ( pScriptErrDlg.get() )
1612 pScriptErrDlg->Execute();
1615 OSL_TRACE( "leaving CallXScript" );
1616 return nErr;
1619 // perhaps rename to CallScript once we get rid of the existing CallScript
1620 // and Call, CallBasic, CallStarBasic methods
1621 ErrCode SfxObjectShell::CallXScript( const String& rScriptURL,
1622 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
1623 aParams,
1624 ::com::sun::star::uno::Any& aRet,
1625 ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
1626 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
1627 aOutParam, bool bRaiseError, const ::com::sun::star::uno::Any* pCaller )
1629 return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError, pCaller );
1632 //-------------------------------------------------------------------------
1633 SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
1635 return pSelf;
1638 SfxObjectShellFlags SfxObjectShell::GetFlags() const
1640 if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED )
1641 pImp->eFlags = GetFactory().GetFlags();
1642 return pImp->eFlags;
1645 void SfxHeaderAttributes_Impl::SetAttributes()
1647 bAlert = sal_True;
1648 SvKeyValue aPair;
1649 for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont;
1650 bCont = xIter->GetNext( aPair ) )
1651 SetAttribute( aPair );
1654 void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV )
1656 String aValue = rKV.GetValue();
1657 if( rKV.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL && rKV.GetValue().Len() )
1659 sal_uInt32 nTime = aValue.GetToken( 0, ';' ).ToInt32() ;
1660 String aURL = aValue.GetToken( 1, ';' );
1661 aURL.EraseTrailingChars().EraseLeadingChars();
1662 uno::Reference<document::XDocumentProperties> xDocProps(
1663 pDoc->getDocProperties());
1664 if( aURL.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL )
1666 INetURLObject aObj;
1667 INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.Copy( 4 ), &aObj );
1668 xDocProps->setAutoloadURL(
1669 aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1673 xDocProps->setAutoloadSecs( nTime );
1675 catch (lang::IllegalArgumentException &)
1677 // ignore
1680 else if( rKV.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL )
1682 DateTime aDateTime( DateTime::EMPTY );
1683 if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) )
1685 aDateTime.ConvertToLocalTime();
1686 pDoc->GetMedium()->SetExpired_Impl( aDateTime );
1688 else
1690 pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) );
1693 else if( rKV.GetKey().CompareIgnoreCaseToAscii( "content-type" ) == COMPARE_EQUAL )
1695 String sType, sSubType;
1696 INetContentTypeParameterList aParameters;
1698 if (INetContentTypes::parse(aValue, sType, sSubType, &aParameters))
1700 const INetContentTypeParameter * pCharset = aParameters.find("charset");
1701 if (pCharset != 0)
1702 pDoc->GetMedium()->SetCharset( pCharset->m_sValue );
1707 void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV )
1709 xIter->Append( rKV );
1710 if( bAlert ) SetAttribute( rKV );
1713 SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes()
1715 if( !pImp->xHeaderAttributes.Is() )
1717 DBG_ASSERT( pMedium, "No Medium" );
1718 pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this );
1720 return ( SvKeyValueIterator*) &pImp->xHeaderAttributes;
1723 void SfxObjectShell::ClearHeaderAttributesForSourceViewHack()
1725 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
1726 ->ClearForSourceView();
1730 void SfxObjectShell::SetHeaderAttributesForSourceViewHack()
1732 ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
1733 ->SetAttributes();
1736 sal_Bool SfxObjectShell::IsPreview() const
1738 if ( !pMedium )
1739 return sal_False;
1741 sal_Bool bPreview = sal_False;
1742 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False);
1743 if ( pFlags )
1745 // Distributed values among individual items
1746 String aFileFlags = pFlags->GetValue();
1747 aFileFlags.ToUpperAscii();
1748 if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) )
1749 bPreview = sal_True;
1752 if ( !bPreview )
1754 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False);
1755 if ( pItem )
1756 bPreview = pItem->GetValue();
1759 return bPreview;
1762 void SfxObjectShell::SetWaitCursor( sal_Bool bSet ) const
1764 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
1766 if ( bSet )
1767 pFrame->GetFrame().GetWindow().EnterWait();
1768 else
1769 pFrame->GetFrame().GetWindow().LeaveWait();
1773 String SfxObjectShell::GetAPIName() const
1775 INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
1776 String aName( aURL.GetBase() );
1777 if( !aName.Len() )
1778 aName = aURL.GetURLNoPass();
1779 if ( !aName.Len() )
1780 aName = GetTitle( SFX_TITLE_DETECT );
1781 return aName;
1784 void SfxObjectShell::Invalidate( sal_uInt16 nId )
1786 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
1787 Invalidate_Impl( pFrame->GetBindings(), nId );
1790 bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI )
1792 uno::Reference< task::XInteractionHandler > xInteraction;
1793 if ( pMedium && !bSuppressUI )
1794 xInteraction = pMedium->GetInteractionHandler();
1796 CheckForBrokenDocSignatures_Impl( xInteraction );
1798 CheckEncryption_Impl( xInteraction );
1800 return pImp->aMacroMode.adjustMacroMode( xInteraction );
1803 Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium )
1805 Window* pWindow = 0;
1806 SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet();
1807 SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
1808 if ( pUnoItem )
1810 uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() );
1811 pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
1814 if ( !pWindow )
1816 SfxFrame* pFrame = 0;
1817 SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False );
1818 if( pFrameItem && pFrameItem->GetFrame() )
1819 // get target frame from ItemSet
1820 pFrame = pFrameItem->GetFrame();
1821 else
1823 // try the current frame
1824 SfxViewFrame* pView = SfxViewFrame::Current();
1825 if ( !pView || pView->GetObjectShell() != this )
1826 // get any visible frame
1827 pView = SfxViewFrame::GetFirst(this);
1828 if ( pView )
1829 pFrame = &pView->GetFrame();
1832 if ( pFrame )
1833 // get topmost window
1834 pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() );
1837 if ( pWindow )
1839 // this frame may be invisible, show it if it is allowed
1840 SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
1841 if ( !pHiddenItem || !pHiddenItem->GetValue() )
1843 pWindow->Show();
1844 pWindow->ToTop();
1848 return pWindow;
1851 void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode )
1853 eCreateMode = nMode;
1856 sal_Bool SfxObjectShell::IsInPlaceActive()
1858 if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
1859 return sal_False;
1861 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
1862 return pFrame && pFrame->GetFrame().IsInPlace();
1865 sal_Bool SfxObjectShell::IsUIActive()
1867 if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
1868 return sal_False;
1870 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
1871 return pFrame && pFrame->GetFrame().IsInPlace() && pFrame->GetFrame().GetWorkWindow_Impl()->IsVisible_Impl();
1874 void SfxObjectShell::UIActivate( sal_Bool )
1878 void SfxObjectShell::InPlaceActivate( sal_Bool )
1882 sal_Bool SfxObjectShell::UseInteractionToHandleError(
1883 const uno::Reference< task::XInteractionHandler >& xHandler,
1884 sal_uInt32 nError )
1886 sal_Bool bResult = sal_False;
1888 if ( xHandler.is() )
1892 uno::Any aInteraction;
1893 uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2);
1894 ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort();
1895 ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
1896 lContinuations[0] = uno::Reference< task::XInteractionContinuation >(
1897 static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY );
1898 lContinuations[1] = uno::Reference< task::XInteractionContinuation >(
1899 static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY );
1901 task::ErrorCodeRequest aErrorCode;
1902 aErrorCode.ErrCode = nError;
1903 aInteraction <<= aErrorCode;
1904 xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations));
1905 bResult = pAbort->wasSelected();
1907 catch( uno::Exception& )
1911 return bResult;
1914 sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const
1916 sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE );
1918 const SfxMedium* pMedium( rDocShell.GetMedium() );
1919 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
1920 if ( pMedium )
1922 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False);
1923 if ( pMacroModeItem )
1924 nImposedExecMode = pMacroModeItem->GetValue();
1926 return nImposedExecMode;
1929 sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
1931 const SfxMedium* pMedium( rDocShell.GetMedium() );
1932 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
1933 if ( pMedium )
1935 pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) );
1936 return sal_True;
1939 return sal_False;
1942 ::rtl::OUString SfxObjectShell_Impl::getDocumentLocation() const
1944 ::rtl::OUString sLocation;
1946 const SfxMedium* pMedium( rDocShell.GetMedium() );
1947 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" );
1948 if ( pMedium )
1950 sLocation = pMedium->GetName();
1951 if ( sLocation.isEmpty() )
1953 // for documents made from a template: get the name of the template
1954 sLocation = rDocShell.getDocProperties()->getTemplateURL();
1957 return sLocation;
1960 uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign()
1962 Reference < embed::XStorage > xStore;
1964 SfxMedium* pMedium( rDocShell.GetMedium() );
1965 OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" );
1966 if ( pMedium )
1967 xStore = pMedium->GetZipStorageToSign_Impl();
1969 return xStore;
1972 sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const
1974 return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage );
1977 Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const
1979 return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY );
1982 sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState()
1984 sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() );
1986 if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken )
1988 // if there is a macro signature it must be handled as broken
1989 nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN;
1992 return nSignatureState;
1995 sal_Bool SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor )
1997 sal_Bool bResult = sal_False;
2001 ::rtl::OUString aVersion;
2004 uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW );
2005 xPropSet->getPropertyValue( ::rtl::OUString( "Version" ) ) >>= aVersion;
2007 catch( uno::Exception& )
2010 uno::Sequence< uno::Any > aArgs( 1 );
2011 aArgs[0] <<= aVersion;
2013 uno::Reference< security::XDocumentDigitalSignatures > xSigner( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( "com.sun.star.security.DocumentDigitalSignatures" ), aArgs ), uno::UNO_QUERY_THROW );
2015 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN
2016 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
2017 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
2019 uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( sal_True, xSigner );
2021 if ( aInfo.getLength() )
2023 if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN )
2024 nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo );
2026 if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
2027 || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
2029 for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ )
2031 bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer );
2034 if ( !bResult && bAllowUIToAddAuthor )
2036 uno::Reference< task::XInteractionHandler > xInteraction;
2037 if ( rDocShell.GetMedium() )
2038 xInteraction = rDocShell.GetMedium()->GetInteractionHandler();
2040 if ( xInteraction.is() )
2042 task::DocumentMacroConfirmationRequest aRequest;
2043 aRequest.DocumentURL = getDocumentLocation();
2044 aRequest.DocumentStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl();
2045 aRequest.DocumentSignatureInformation = aInfo;
2046 aRequest.DocumentVersion = aVersion;
2047 aRequest.Classification = task::InteractionClassification_QUERY;
2048 bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), sal_True );
2055 catch( uno::Exception& )
2058 return bResult;
2061 void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const
2063 if ( !bSignatureErrorIsShown )
2065 SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE );
2066 const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = sal_True;
2070 void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage )
2072 if ( !pImp->m_xLogRing.is() )
2076 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
2077 if ( aContext.is() )
2078 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
2080 catch( uno::Exception& )
2084 if ( pImp->m_xLogRing.is() )
2085 pImp->m_xLogRing->logString( aMessage );
2088 namespace {
2090 void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const ::rtl::OUString& aString )
2092 if ( xOutStream.is() )
2094 ::rtl::OString aStrLog = ::rtl::OUStringToOString( aString, RTL_TEXTENCODING_UTF8 );
2095 uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() );
2096 xOutStream->writeBytes( aLogData );
2098 aLogData.realloc( 1 );
2099 aLogData[0] = '\n';
2100 xOutStream->writeBytes( aLogData );
2106 void SfxObjectShell::StoreLog()
2108 if ( !pImp->m_xLogRing.is() )
2112 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
2113 if ( aContext.is() )
2114 pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
2116 catch( uno::Exception& )
2120 if ( pImp->m_xLogRing.is() )
2122 #ifdef WNT
2123 ::rtl::OUString aFileURL = ::rtl::OUString( "${$BRAND_BASE_DIR/program/bootstrap.ini:UserInstallation}" );
2124 #else
2125 ::rtl::OUString aFileURL = ::rtl::OUString( "${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}" );
2126 #endif
2128 ::rtl::Bootstrap::expandMacros( aFileURL );
2130 #ifdef WNT
2131 ::rtl::OUString aBuildID = ::rtl::OUString( "${$BRAND_BASE_DIR/program/setup.ini:buildid}" );
2132 #else
2133 ::rtl::OUString aBuildID = ::rtl::OUString( "${$BRAND_BASE_DIR/program/setuprc:buildid}" );
2134 #endif
2136 ::rtl::Bootstrap::expandMacros( aBuildID );
2138 if ( !aFileURL.isEmpty() )
2140 aFileURL += ::rtl::OUString( "/user/temp/document_io_logring.txt" );
2143 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
2144 uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( xFactory->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW );
2145 uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW );
2146 uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW );
2147 uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW );
2148 xTruncate->truncate();
2150 if ( !aBuildID.isEmpty() )
2151 WriteStringInStream( xOutStream, aBuildID );
2153 uno::Sequence< ::rtl::OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog();
2154 for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ )
2155 WriteStringInStream( xOutStream, aLogSeq[nInd] );
2157 catch( uno::Exception& )
2163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */