1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
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>
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>
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/task/DocumentMacroConfirmationRequest2.hpp>
91 #include <com/sun/star/task/InteractionClassification.hpp>
92 #include <com/sun/star/frame/XModel.hpp>
94 using namespace ::com::sun::star
;
95 using namespace ::com::sun::star::uno
;
96 using namespace ::com::sun::star::ucb
;
97 using namespace ::com::sun::star::document
;
98 using namespace ::com::sun::star::frame
;
99 using namespace ::com::sun::star::script
;
100 using namespace ::com::sun::star::script::provider
;
101 using namespace ::com::sun::star::container
;
102 #include <basic/sbuno.hxx>
103 #include <basic/sbstar.hxx>
104 #ifndef _SB_BASMGR_HXX
105 #include <basic/basmgr.hxx>
107 #ifndef _VCL_MSGBOX_HXX
108 #include <vcl/msgbox.hxx>
110 #include <basic/sbx.hxx>
111 #include <svtools/sfxecode.hxx>
112 #include <svtools/ehdl.hxx>
114 #include <svtools/pathoptions.hxx>
115 #include <unotools/ucbhelper.hxx>
116 #include <tools/inetmime.hxx>
117 #include <tools/urlobj.hxx>
118 #include <svtools/inettype.hxx>
119 #include <svtools/sharecontrolfile.hxx>
120 #include <osl/file.hxx>
121 #include <rtl/bootstrap.hxx>
122 #include <vcl/svapp.hxx>
123 #include <framework/interaction.hxx>
124 #include <comphelper/storagehelper.hxx>
125 #include <comphelper/documentconstants.hxx>
127 #include <sfx2/signaturestate.hxx>
128 #include <sfx2/app.hxx>
129 #include "appdata.hxx"
130 #include <sfx2/request.hxx>
131 #include <sfx2/bindings.hxx>
132 #include "sfxresid.hxx"
133 #include <sfx2/docfile.hxx>
134 #include <sfx2/docfilt.hxx>
135 #include <sfx2/objsh.hxx>
136 #include "objshimp.hxx"
137 #include <sfx2/event.hxx>
138 #include "fltfnc.hxx"
139 #include <sfx2/sfx.hrc>
140 #include <sfx2/dispatch.hxx>
141 #include <sfx2/viewfrm.hxx>
142 #include <sfx2/viewsh.hxx>
143 #include <sfx2/ctrlitem.hxx>
144 #include "arrdecl.hxx"
145 #include <sfx2/module.hxx>
146 #include <sfx2/macrconf.hxx>
147 #include <sfx2/docfac.hxx>
148 #include "helper.hxx"
150 #include "workwin.hxx"
151 #include "helpid.hrc"
152 #include "../appl/app.hrc"
153 #include <sfx2/sfxdlg.hxx>
154 #include "appbaslib.hxx"
155 #include <openflag.hxx> // SFX_STREAM_READWRITE
157 using namespace ::com::sun::star
;
159 // class SfxHeaderAttributes_Impl ----------------------------------------
161 class SfxHeaderAttributes_Impl
: public SvKeyValueIterator
164 SfxObjectShell
* pDoc
;
165 SvKeyValueIteratorRef xIter
;
169 SfxHeaderAttributes_Impl( SfxObjectShell
* pSh
) :
170 SvKeyValueIterator(), pDoc( pSh
),
171 xIter( pSh
->GetMedium()->GetHeaderAttributes_Impl() ),
172 bAlert( sal_False
) {}
174 virtual sal_Bool
GetFirst( SvKeyValue
& rKV
) { return xIter
->GetFirst( rKV
); }
175 virtual sal_Bool
GetNext( SvKeyValue
& rKV
) { return xIter
->GetNext( rKV
); }
176 virtual void Append( const SvKeyValue
& rKV
);
178 void ClearForSourceView() { xIter
= new SvKeyValueIterator
; bAlert
= sal_False
; }
179 void SetAttributes();
180 void SetAttribute( const SvKeyValue
& rKV
);
183 //=========================================================================
185 sal_uInt16 __READONLY_DATA aTitleMap_Impl
[3][2] =
188 /* SFX_TITLE_CAPTION */ { SFX_TITLE_FILENAME
, SFX_TITLE_TITLE
},
189 /* SFX_TITLE_PICKLIST */ { 32, SFX_TITLE_FULLNAME
},
190 /* SFX_TITLE_HISTORY */ { 32, SFX_TITLE_FULLNAME
}
193 //=========================================================================
195 void SfxObjectShell::AbortImport()
197 pImp
->bIsAbortingImport
= sal_True
;
200 //-------------------------------------------------------------------------
202 sal_Bool
SfxObjectShell::IsAbortingImport() const
204 return pImp
->bIsAbortingImport
;
207 //-------------------------------------------------------------------------
209 uno::Reference
<document::XDocumentProperties
>
210 SfxObjectShell::getDocProperties()
212 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
213 GetModel(), uno::UNO_QUERY_THROW
);
214 uno::Reference
<document::XDocumentProperties
> xDocProps(
215 xDPS
->getDocumentProperties());
216 DBG_ASSERT(xDocProps
.is(),
217 "SfxObjectShell: model has no DocumentProperties");
221 //-------------------------------------------------------------------------
223 void SfxObjectShell::DoFlushDocInfo()
227 //-------------------------------------------------------------------------
229 // Note: the only thing that calls this is the modification event handler
230 // that is installed at the XDocumentProperties
231 void SfxObjectShell::FlushDocInfo()
236 SetModified(sal_True
);
237 uno::Reference
<document::XDocumentProperties
> xDocProps(getDocProperties());
238 DoFlushDocInfo(); // call template method
239 ::rtl::OUString
url(xDocProps
->getAutoloadURL());
240 sal_Int32
delay(xDocProps
->getAutoloadSecs());
241 SetAutoLoad( INetURLObject(url
), delay
* 1000,
242 (delay
> 0) || url
.getLength() );
245 // 1. Titel in DocInfo aber nicht am Doc (nach HTML-Import)
246 // => auch am Doc setzen
247 // 2. Titel in DocInfo leer (Briefumschlagsdruck)
248 // => nicht am Doc setzen, da sonst "unbenanntX" daraus wird
249 String aDocInfoTitle = GetDocInfo().GetTitle();
250 if ( aDocInfoTitle.Len() )
251 SetTitle( aDocInfoTitle );
254 pImp->aTitle.Erase();
255 SetNamedVisibility_Impl();
258 SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
259 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
264 //-------------------------------------------------------------------------
266 void SfxObjectShell::SetError( sal_uInt32 lErr
, const ::rtl::OUString
& aLogMessage
)
268 if(pImp
->lErr
==ERRCODE_NONE
)
272 if( lErr
!= ERRCODE_NONE
&& aLogMessage
.getLength() )
273 AddLog( aLogMessage
);
277 //-------------------------------------------------------------------------
279 sal_uInt32
SfxObjectShell::GetError() const
281 return ERRCODE_TOERROR(GetErrorCode());
284 //-------------------------------------------------------------------------
286 sal_uInt32
SfxObjectShell::GetErrorCode() const
288 sal_uInt32 lError
=pImp
->lErr
;
289 if(!lError
&& GetMedium())
290 lError
=GetMedium()->GetErrorCode();
294 //-------------------------------------------------------------------------
296 void SfxObjectShell::ResetError()
298 if( pImp
->lErr
!= ERRCODE_NONE
)
299 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Resetting Error." ) ) );
302 SfxMedium
* pMed
= GetMedium();
307 //-------------------------------------------------------------------------
309 sal_Bool
SfxObjectShell::IsTemplate() const
311 return pImp
->bIsTemplate
;
314 //-------------------------------------------------------------------------
316 void SfxObjectShell::SetTemplate(sal_Bool bIs
)
318 pImp
->bIsTemplate
=bIs
;
319 SfxFilterMatcher
aMatcher( GetFactory().GetFactoryName() );
320 SfxFilterMatcherIter
aIter( &aMatcher
, SFX_FILTER_TEMPLATEPATH
);
321 SfxMedium
* pMed
= GetMedium();
322 if( pMed
) pMed
->SetFilter( aIter
.First() );
325 //-------------------------------------------------------------------------
327 void SfxObjectShell::EnableSetModified( sal_Bool bEnable
)
330 if ( bEnable
== pImp
->m_bEnableSetModified
)
331 DBG_WARNING( "SFX_PERSIST: EnableSetModified 2x mit dem gleichen Wert gerufen" );
333 pImp
->m_bEnableSetModified
= bEnable
;
336 //-------------------------------------------------------------------------
338 sal_Bool
SfxObjectShell::IsEnableSetModified() const
340 return pImp
->m_bEnableSetModified
&& !IsReadOnly();
343 //-------------------------------------------------------------------------
345 sal_Bool
SfxObjectShell::IsModified()
347 if ( pImp
->m_bIsModified
)
350 if ( !pImp
->m_xDocStorage
.is() || IsReadOnly() )
352 // if the document still has no storage and is not set to be modified explicitly it is not modified
353 // a readonly document is also not modified
358 uno::Sequence
< ::rtl::OUString
> aNames
= GetEmbeddedObjectContainer().GetObjectNames();
359 for ( sal_Int32 n
=0; n
<aNames
.getLength(); n
++ )
361 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetEmbeddedObjectContainer().GetEmbeddedObject( aNames
[n
] );
362 OSL_ENSURE( xObj
.is(), "An empty entry in the embedded objects list!\n" );
367 sal_Int32 nState
= xObj
->getCurrentState();
368 if ( nState
!= embed::EmbedStates::LOADED
)
370 uno::Reference
< util::XModifiable
> xModifiable( xObj
->getComponent(), uno::UNO_QUERY
);
371 if ( xModifiable
.is() && xModifiable
->isModified() )
375 catch( uno::Exception
& )
383 //-------------------------------------------------------------------------
385 void SfxObjectShell::SetModified( sal_Bool bModifiedP
)
388 if ( !bModifiedP
&& !IsEnableSetModified() )
389 DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), obwohl IsEnableSetModified() == sal_False" );
392 if( !IsEnableSetModified() )
395 if( pImp
->m_bIsModified
!= bModifiedP
)
397 pImp
->m_bIsModified
= bModifiedP
;
402 //-------------------------------------------------------------------------
404 void SfxObjectShell::ModifyChanged()
406 if ( pImp
->bClosing
)
407 // SetModified aus dem dispose des Models!
410 {DBG_CHKTHIS(SfxObjectShell
, 0);}
411 SfxObjectShell
*pDoc
;
412 for ( pDoc
= SfxObjectShell::GetFirst(); pDoc
;
413 pDoc
= SfxObjectShell::GetNext(*pDoc
) )
414 if( pDoc
->IsModified() )
417 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
419 pViewFrame
->GetBindings().Invalidate( SID_SAVEDOCS
);
422 Invalidate( SID_SIGNATURE
);
423 Invalidate( SID_MACRO_SIGNATURE
);
424 Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED
) ); // xmlsec05, signed state might change in title...
426 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED
, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED
), this ) );
429 //-------------------------------------------------------------------------
431 sal_Bool
SfxObjectShell::IsReadOnlyUI() const
435 Liefert sal_True, wenn das Dokument fuer die UI wie r/o behandelt werden
436 soll. Dieses ist unabhaengig vom tatsaechlichen r/o, welches per
437 <IsReadOnly()> erfragbar ist.
441 return pImp
->bReadOnlyUI
;
444 //-------------------------------------------------------------------------
446 sal_Bool
SfxObjectShell::IsReadOnlyMedium() const
450 Liefert sal_True, wenn das Medium r/o ist bzw. r/o geoeffnet wurde.
456 return pMedium
->IsReadOnly();
459 //-------------------------------------------------------------------------
461 void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly
)
465 Schaltet das Dokument in einen r/o bzw. r/w Zustand ohne es neu
466 zu laden und ohne die Open-Modi des Mediums zu aendern.
470 sal_Bool bWasRO
= IsReadOnly();
471 pImp
->bReadOnlyUI
= bReadOnly
;
472 if ( bWasRO
!= IsReadOnly() )
474 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED
) );
475 //if ( pImp->pDocInfo )
476 // pImp->pDocInfo->SetReadOnly( IsReadOnly() );
480 //-------------------------------------------------------------------------
482 sal_Bool
SfxObjectShell::IsReadOnly() const
484 return pImp
->bReadOnlyUI
|| IsReadOnlyMedium();
487 //-------------------------------------------------------------------------
489 sal_Bool
SfxObjectShell::IsInModalMode() const
491 return pImp
->bModalMode
|| pImp
->bRunningMacro
;
494 //-------------------------------------------------------------------------
496 sal_Bool
SfxObjectShell::HasModalViews() const
498 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( this );
501 if ( pFrame
->IsInModalMode() )
504 pFrame
= SfxViewFrame::GetNext( *pFrame
, this );
510 //-------------------------------------------------------------------------
512 void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal
)
514 if ( !pImp
->bRunningMacro
!= !bModal
)
516 pImp
->bRunningMacro
= bModal
;
517 Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED
) );
521 //-------------------------------------------------------------------------
523 void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal
)
525 // nur Broadcasten wenn modifiziert, sonst ggf. Endlosrekursion
526 if ( !pImp
->bModalMode
!= !bModal
)
528 // zentral mitz"ahlen
529 sal_uInt16
&rDocModalCount
= SFX_APP()->Get_Impl()->nDocModalMode
;
536 pImp
->bModalMode
= bModal
;
537 Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED
) );
541 //--------------------------------------------------------------------
542 sal_Bool
SfxObjectShell::SwitchToShared( sal_Bool bShared
, sal_Bool bSave
)
544 sal_Bool bResult
= sal_True
;
546 if ( bShared
!= IsDocShared() )
548 ::rtl::OUString aOrigURL
= GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE
);
550 if ( !aOrigURL
.getLength() && bSave
)
552 // this is a new document, let it be stored before switching to the shared mode;
553 // the storing should be done without shared flag, since it is possible that the
554 // target location does not allow to create sharing control file;
555 // the shared flag will be set later after creation of sharing control file
556 SfxViewFrame
* pViewFrame
= SfxViewFrame::GetFirst( this );
560 // TODO/LATER: currently the application guards against the reentrance problem
561 const SfxPoolItem
* pItem
= pViewFrame
->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC
: SID_SAVEASDOC
);
562 SfxBoolItem
* pResult
= PTR_CAST( SfxBoolItem
, pItem
);
563 bResult
= ( pResult
&& pResult
->GetValue() );
565 aOrigURL
= GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE
);
569 sal_Bool bOldValue
= HasSharedXMLFlagSet();
570 SetSharedXMLFlag( bShared
);
572 sal_Bool bRemoveEntryOnError
= sal_False
;
573 if ( bResult
&& bShared
)
577 ::svt::ShareControlFile
aControlFile( aOrigURL
);
578 aControlFile
.InsertOwnEntry();
579 bRemoveEntryOnError
= sal_True
;
581 catch( uno::Exception
& )
587 if ( bResult
&& bSave
)
589 SfxViewFrame
* pViewFrame
= SfxViewFrame::GetFirst( this );
593 // TODO/LATER: currently the application guards against the reentrance problem
594 SetModified( sal_True
); // the modified flag has to be set to let the document be stored with the shared flag
595 const SfxPoolItem
* pItem
= pViewFrame
->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC
: SID_SAVEASDOC
);
596 SfxBoolItem
* pResult
= PTR_CAST( SfxBoolItem
, pItem
);
597 bResult
= ( pResult
&& pResult
->GetValue() );
603 // TODO/LATER: Is it possible that the following calls fail?
606 pImp
->m_aSharedFileURL
= aOrigURL
;
607 GetMedium()->SwitchDocumentToTempFile();
611 ::rtl::OUString aTempFileURL
= pMedium
->GetURLObject().GetMainURL( INetURLObject::NO_DECODE
);
612 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
613 pImp
->m_aSharedFileURL
= ::rtl::OUString();
615 // now remove the temporary file the document was based on
616 ::utl::UCBContentHelper::Kill( aTempFileURL
);
620 // aOrigURL can not be used since it contains an old value
621 ::svt::ShareControlFile
aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE
) );
622 aControlFile
.RemoveFile();
624 catch( uno::Exception
& )
631 // the saving has failed!
632 if ( bRemoveEntryOnError
)
636 ::svt::ShareControlFile
aControlFile( aOrigURL
);
637 aControlFile
.RemoveEntry();
639 catch( uno::Exception
& )
643 SetSharedXMLFlag( bOldValue
);
647 bResult
= sal_False
; // the second switch to the same mode
650 SetTitle( String() );
655 //--------------------------------------------------------------------
657 void SfxObjectShell::DisconnectFromShared()
661 if ( pMedium
&& pMedium
->GetStorage().is() )
663 // set medium to noname
664 pMedium
->SetName( String(), sal_True
);
665 pMedium
->Init_Impl();
671 // untitled document must be based on temporary storage
672 // the medium should not dispose the storage in this case
673 if ( pMedium
->GetStorage() == GetStorage() )
674 ConnectTmpStorage_Impl( pMedium
->GetStorage(), pMedium
);
679 SfxMedium
* pTmpMedium
= pMedium
;
681 if( !DoSaveCompleted( pTmpMedium
) )
682 SetError( ERRCODE_IO_GENERAL
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ) );
685 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
686 pMedium
->CanDisposeStorage_Impl( sal_False
);
689 pMedium
->GetItemSet()->ClearItem( SID_DOC_READONLY
);
690 pMedium
->SetOpenMode( SFX_STREAM_READWRITE
, sal_True
, sal_True
);
692 SetTitle( String() );
697 //--------------------------------------------------------------------
699 void SfxObjectShell::FreeSharedFile()
702 FreeSharedFile( pMedium
->GetURLObject().GetMainURL( INetURLObject::NO_DECODE
) );
705 //--------------------------------------------------------------------
706 void SfxObjectShell::FreeSharedFile( const ::rtl::OUString
& aTempFileURL
)
708 SetSharedXMLFlag( sal_False
);
710 if ( IsDocShared() && aTempFileURL
.getLength()
711 && !SfxMedium::EqualURLs( aTempFileURL
, GetSharedFileURL() ) )
713 if ( pImp
->m_bAllowShareControlFileClean
)
717 ::svt::ShareControlFile
aControlFile( GetSharedFileURL() );
718 aControlFile
.RemoveEntry();
720 catch( uno::Exception
& )
725 // the cleaning is forbidden only once
726 pImp
->m_bAllowShareControlFileClean
= sal_True
;
728 // now remove the temporary file the document is based currently on
729 ::utl::UCBContentHelper::Kill( aTempFileURL
);
731 pImp
->m_aSharedFileURL
= ::rtl::OUString();
735 //--------------------------------------------------------------------
736 void SfxObjectShell::DoNotCleanShareControlFile()
738 pImp
->m_bAllowShareControlFileClean
= sal_False
;
741 //--------------------------------------------------------------------
742 void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag
) const
744 pImp
->m_bSharedXMLFlag
= bFlag
;
747 //--------------------------------------------------------------------
748 sal_Bool
SfxObjectShell::HasSharedXMLFlagSet() const
750 return pImp
->m_bSharedXMLFlag
;
753 //--------------------------------------------------------------------
755 sal_Bool
SfxObjectShell::IsDocShared() const
757 return ( pImp
->m_aSharedFileURL
.getLength() > 0 );
760 //--------------------------------------------------------------------
762 ::rtl::OUString
SfxObjectShell::GetSharedFileURL() const
764 return pImp
->m_aSharedFileURL
;
767 //--------------------------------------------------------------------
769 Size
SfxObjectShell::GetFirstPageSize()
771 return GetVisArea(ASPECT_THUMBNAIL
).GetSize();
775 //--------------------------------------------------------------------
777 IndexBitSet
& SfxObjectShell::GetNoSet_Impl()
779 return pImp
->aBitSet
;
782 //--------------------------------------------------------------------
783 // changes the title of the document
785 void SfxObjectShell::SetTitle
787 const String
& rTitle
// der neue Titel des Dokuments
792 Mit dieser Methode kann der Titel des Dokuments gesetzt werden.
793 Dieser entspricht initial dem kompletten Dateinamen. Ein Setzen
794 des Titels wirkt jedoch nicht zu"uck auf den Dateinamen; er wird
795 jedoch in den Caption-Bars der MDI-Fenster angezeigt.
799 DBG_CHKTHIS(SfxObjectShell
, 0);
802 if ( ( ( HasName() && pImp
->aTitle
== rTitle
)
803 || ( !HasName() && GetTitle() == rTitle
) )
807 SfxApplication
*pSfxApp
= SFX_APP();
809 // wird 'unbenannt#' als Titel gesetzt
810 String
aNoName(SfxResId(STR_NONAME
));
811 if ( rTitle
.Match(aNoName
) <= aNoName
.Len() )
813 // er ist es selbst => ignorieren
814 pSfxApp
->ReleaseIndex(pImp
->nVisualDocumentNumber
);
815 pImp
->bIsNamedVisible
=0;
819 // ggf. die unbenannt-Nummer freigeben
820 if ( pImp
->bIsNamedVisible
&& USHRT_MAX
!= pImp
->nVisualDocumentNumber
)
822 pSfxApp
->ReleaseIndex(pImp
->nVisualDocumentNumber
);
823 pImp
->bIsNamedVisible
= 0;
827 pImp
->aTitle
= rTitle
;
828 // Wieso denn in der DocInfo?
829 // GetDocInfo().SetTitle( rTitle );
832 // Benachrichtigungen
835 SfxShell::SetName( GetTitle(SFX_TITLE_APINAME
) );
836 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED
) );
840 //--------------------------------------------------------------------
842 #if OSL_DEBUG_LEVEL > 1
843 String
X(const String
&rRet
)
846 return DEFINE_CONST_UNICODE( "-empty-" );
853 //--------------------------------------------------------------------
854 //--------------------------------------------------------------------
855 String
SfxObjectShell::GetTitle
857 sal_uInt16 nMaxLength
/* 0 (default)
858 der Titel selbst, so wie er ist
860 1 (==SFX_TITLE_FILENAME)
861 liefert den logischen Dateinamen ohne Pfad
862 (unter WNT je nach Systemeinstellung ohne
865 2 (==SFX_TITLE_FULLNAME)
866 liefert den mit komplettem logischen Dateinamen
867 mit Pfad (remote => ::com::sun::star::util::URL)
869 3 (==SFX_TITLE_APINAME)
870 liefert den logischen Dateinamen ohne Pfad
873 4 (==SFX_TITLE_DETECT)
874 liefert den kompletten Titel, falls noch
875 nicht gesetzt wird aber aus DocInfo oder
876 dem Namen des Medium erzeugt
878 5 (==SFX_TITLE_CAPTION)
879 liefert den Titel so, wie MB ihn heute in
880 der CaptionBar anzeigen m"ochte
882 6 (==SFX_TITLE_PICKLIST)
883 liefert den Titel so, wie MB ihn heute in
884 der PickList anzeigen m"ochte
886 7 (==SFX_TITLE_HISTORY)
887 liefert den Titel so, wie MB ihn heute in
888 der History anzeigen m"ochte
891 liefert maximal 'nMaxLength' Zeichen vom logischen
892 Dateinamen inkl. Pfad (remote => ::com::sun::star::util::URL)
898 Liefert den Titel bzw. logischen Dateinamen des Dokuments, je nach
901 Falls der Dateiname mit Pfad verwendet wird, wird die Namensk"urzung durch
902 Ersetzung eines oder mehrerer Directory-Namen durch "..." durchgef"uhrt,
903 URLs werden z.Zt. immer komplett geliefert.
907 // if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
909 SfxMedium
*pMed
= GetMedium();
913 /* if ( !nMaxLength && pImp->pDocInfo )
915 String aTitle = pImp->pDocInfo->GetTitle();
921 if ( SFX_TITLE_DETECT
== nMaxLength
&& !pImp
->aTitle
.Len() )
923 static sal_Bool bRecur
= sal_False
;
925 return DEFINE_CONST_UNICODE( "-not available-" );
929 SfxObjectShell
*pThis
= (SfxObjectShell
*) this;
933 SFX_ITEMSET_ARG( pMed
->GetItemSet(), pNameItem
, SfxStringItem
, SID_DOCINFO_TITLE
, sal_False
);
935 aTitle
= pNameItem
->GetValue();
939 aTitle
= GetTitle( SFX_TITLE_FILENAME
);
942 pThis
->SetTitle( aTitle
);
946 else if (SFX_TITLE_APINAME
== nMaxLength
)
947 return X(GetAPIName());
949 // Sonderfall Vorlagen:
950 if( IsTemplate() && pImp
->aTitle
.Len() &&
951 ( nMaxLength
== SFX_TITLE_CAPTION
|| nMaxLength
== SFX_TITLE_PICKLIST
) )
952 return X(pImp
->aTitle
);
954 // Picklist/Caption wird gemappt
955 if ( pMed
&& ( nMaxLength
== SFX_TITLE_CAPTION
|| nMaxLength
== SFX_TITLE_PICKLIST
) )
957 // Wenn ein spezieller Titel beim "Offnen mitgegeben wurde;
958 // wichtig bei URLs, die INET_PROT_FILE verwenden, denn bei denen
959 // wird der gesetzte Titel nicht beachtet.
960 // (s.u., Auswertung von aTitleMap_Impl)
961 SFX_ITEMSET_ARG( pMed
->GetItemSet(), pNameItem
, SfxStringItem
, SID_DOCINFO_TITLE
, sal_False
);
963 return X( pNameItem
->GetValue() );
967 DBG_ASSERT( !HasName() || pMed
, "HasName() aber kein Medium?!?" );
968 if ( !HasName() || !pMed
)
970 // schon Titel gesezt?
971 if ( pImp
->aTitle
.Len() )
972 return X(pImp
->aTitle
);
974 // mu\s es durchnumeriert werden?
975 String
aNoName( SfxResId( STR_NONAME
) );
976 if ( pImp
->bIsNamedVisible
)
977 // Nummer hintenanh"angen
978 aNoName
+= String::CreateFromInt32( pImp
->nVisualDocumentNumber
);
980 // Dokument hei\st vorerst 'unbenannt#'
984 const INetURLObject
aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
985 if ( nMaxLength
> SFX_TITLE_CAPTION
&& nMaxLength
<= SFX_TITLE_HISTORY
)
988 if( !pMed
|| aURL
.GetProtocol() == INET_PROT_FILE
)
992 nMaxLength
= aTitleMap_Impl
[nMaxLength
-SFX_TITLE_CAPTION
][nRemote
];
996 if ( aURL
.GetProtocol() == INET_PROT_FILE
)
998 String
aName( aURL
.HasMark() ? INetURLObject( aURL
.GetURLNoMark() ).PathToFileName() : aURL
.PathToFileName() );
999 if ( nMaxLength
== SFX_TITLE_FULLNAME
)
1001 else if ( nMaxLength
== SFX_TITLE_FILENAME
)
1002 return X( aURL
.getName( INetURLObject::LAST_SEGMENT
,
1003 true, INetURLObject::DECODE_WITH_CHARSET
) );
1004 else if ( !pImp
->aTitle
.Len() )
1005 pImp
->aTitle
= aURL
.getBase( INetURLObject::LAST_SEGMENT
,
1006 true, INetURLObject::DECODE_WITH_CHARSET
);
1010 // ::com::sun::star::util::URL-Versionen
1011 if ( nMaxLength
>= SFX_TITLE_MAXLEN
)
1013 String
aComplete( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
1014 if( aComplete
.Len() > nMaxLength
)
1016 String
aRet( DEFINE_CONST_UNICODE( "..." ) );
1017 aRet
+= aComplete
.Copy( aComplete
.Len() - nMaxLength
+ 3, nMaxLength
- 3 );
1021 return X( aComplete
);
1023 else if ( nMaxLength
== SFX_TITLE_FILENAME
)
1025 String
aName( aURL
.GetBase() );
1026 aName
= INetURLObject::decode( aName
, INET_HEX_ESCAPE
, INetURLObject::DECODE_WITH_CHARSET
);
1028 aName
= aURL
.GetURLNoPass();
1031 else if ( nMaxLength
== SFX_TITLE_FULLNAME
)
1032 return X(aURL
.GetMainURL( INetURLObject::DECODE_TO_IURI
));
1034 // ggf. Titel aus Dateiname generieren
1035 if ( !pImp
->aTitle
.Len() )
1036 pImp
->aTitle
= aURL
.GetBase();
1038 // workaround for the case when the name can not be retrieved from URL by INetURLObject
1039 if ( !pImp
->aTitle
.Len() )
1040 pImp
->aTitle
= aURL
.GetMainURL( INetURLObject::DECODE_WITH_CHARSET
);
1044 return X(pImp
->aTitle
);
1047 //--------------------------------------------------------------------
1049 void SfxObjectShell::InvalidateName()
1053 Ermittelt den Titel des Dokuments neu aus 'unbenannt', DocInfo-Titel
1054 bzw. Dateinamen. Wird nach Laden aus Template oder SaveAs ben"otigt.
1058 // Title neu erzeugen
1059 pImp
->aTitle
.Erase();
1060 // pImp->nVisualDocumentNumber = USHRT_MAX;
1061 //GetTitle( SFX_TITLE_DETECT );
1062 SetName( GetTitle( SFX_TITLE_APINAME
) );
1064 // Benachrichtigungen
1065 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED
) );
1068 //--------------------------------------------------------------------
1070 void SfxObjectShell::SetNamedVisibility_Impl()
1072 if ( !pImp
->bIsNamedVisible
)
1075 pImp
->bIsNamedVisible
= sal_True
;
1076 // ggf. neue Nummer verpassen
1077 if ( !HasName() && USHRT_MAX
== pImp
->nVisualDocumentNumber
&& !pImp
->aTitle
.Len() )
1079 pImp
->nVisualDocumentNumber
= SFX_APP()->GetFreeIndex();
1080 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED
) );
1084 SetName( GetTitle(SFX_TITLE_APINAME
) );
1087 void SfxObjectShell::SetNoName()
1091 GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() );
1094 //--------------------------------------------------------------------
1096 void SfxObjectShell::MemoryError()
1100 //--------------------------------------------------------------------
1102 SfxProgress
* SfxObjectShell::GetProgress() const
1104 return pImp
->pProgress
;
1107 //--------------------------------------------------------------------
1109 void SfxObjectShell::SetProgress_Impl
1111 SfxProgress
*pProgress
/* zu startender <SfxProgress> oder 0, falls
1112 der Progress zur"uckgesetzt werden soll */
1117 Interne Methode zum setzen oder zur"ucksetzen des Progress-Modes
1118 f"ur diese SfxObjectShell.
1122 DBG_ASSERT( ( !pImp
->pProgress
&& pProgress
) ||
1123 ( pImp
->pProgress
&& !pProgress
),
1124 "Progress activation/deacitivation mismatch" );
1125 pImp
->pProgress
= pProgress
;
1128 //--------------------------------------------------------------------
1130 void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame
* pFrame
)
1132 SfxApplication
* pSfxApp
= SFX_APP();
1133 if ( !pSfxApp
->IsDowning() && !IsLoading() && pFrame
&& !pFrame
->GetFrame()->IsClosing_Impl() )
1135 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pHiddenItem
, SfxBoolItem
, SID_HIDDEN
, sal_False
);
1136 if ( !pHiddenItem
|| !pHiddenItem
->GetValue() )
1138 sal_uInt16 nId
= pImp
->nEventId
;
1140 if ( nId
== SFX_EVENT_OPENDOC
)
1141 pSfxApp
->NotifyEvent(SfxEventHint( nId
, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC
), this ), sal_False
);
1142 else if (nId
== SFX_EVENT_CREATEDOC
)
1143 pSfxApp
->NotifyEvent(SfxEventHint( nId
, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC
), 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
)
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( )
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.
1187 ++pImp
->nAutoLoadLocks
;
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() )
1203 // seine Childs gelockt?
1204 for ( sal_uInt16 n
= GetChildFrameCount(); n
--; )
1205 if ( !GetChildFrame(n
)->IsAutoLoadLocked_Impl() )
1208 // sonst ist AutoLoad erlaubt
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
;
1235 xInteraction
= GetMedium()->GetInteractionHandler();
1237 // check if there is a broken signature...
1238 CheckForBrokenDocSignatures_Impl( xInteraction
);
1240 CheckEncryption_Impl( xInteraction
);
1242 // check macro security
1243 pImp
->aMacroMode
.checkMacrosOnLoading( xInteraction
);
1246 //-------------------------------------------------------------------------
1247 void SfxObjectShell::CheckEncryption_Impl( const uno::Reference
< task::XInteractionHandler
>& xHandler
)
1249 ::rtl::OUString aVersion
;
1250 sal_Bool bIsEncrypted
= sal_False
;
1251 sal_Bool bHasNonEncrypted
= sal_False
;
1255 uno::Reference
< beans::XPropertySet
> xPropSet( GetStorage(), uno::UNO_QUERY_THROW
);
1256 xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion
;
1257 xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasEncryptedEntries" ) ) ) >>= bIsEncrypted
;
1258 xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasNonEncryptedEntries" ) ) ) >>= bHasNonEncrypted
;
1260 catch( uno::Exception
& )
1264 if ( aVersion
.compareTo( ODFVER_012_TEXT
) >= 0 )
1266 // this is ODF1.2 or later
1267 if ( bIsEncrypted
&& bHasNonEncrypted
)
1269 if ( !pImp
->m_bIncomplEncrWarnShown
)
1271 // this is an encrypted document with nonencrypted streams inside, show the warning
1272 ::com::sun::star::task::ErrorCodeRequest aErrorCode
;
1273 aErrorCode
.ErrCode
= ERRCODE_SFX_INCOMPLETE_ENCRYPTION
;
1275 SfxMedium::CallApproveHandler( xHandler
, uno::makeAny( aErrorCode
), sal_False
);
1276 pImp
->m_bIncomplEncrWarnShown
= sal_True
;
1279 // broken signatures imply no macro execution at all
1280 pImp
->aMacroMode
.disallowMacroExecution();
1285 //-------------------------------------------------------------------------
1286 void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference
< task::XInteractionHandler
>& xHandler
)
1288 sal_Int16 nSignatureState
= GetDocumentSignatureState();
1289 bool bSignatureBroken
= ( nSignatureState
== SIGNATURESTATE_SIGNATURES_BROKEN
);
1290 if ( !bSignatureBroken
)
1293 pImp
->showBrokenSignatureWarning( xHandler
);
1295 // broken signatures imply no macro execution at all
1296 pImp
->aMacroMode
.disallowMacroExecution();
1299 //-------------------------------------------------------------------------
1300 void SfxObjectShell::SetAutoLoad(
1301 const INetURLObject
& rUrl
, sal_uInt32 nTime
, sal_Bool bReload
)
1303 if ( pImp
->pReloadTimer
)
1304 DELETEZ(pImp
->pReloadTimer
);
1307 pImp
->pReloadTimer
= new AutoReloadTimer_Impl(
1308 rUrl
.GetMainURL( INetURLObject::DECODE_TO_IURI
),
1309 nTime
, bReload
, this );
1310 pImp
->pReloadTimer
->Start();
1314 sal_Bool
SfxObjectShell::IsLoadingFinished() const
1316 return ( pImp
->nLoadedFlags
== SFX_LOADED_ALL
);
1319 void impl_addToModelCollection(const com::sun::star::uno::Reference
< com::sun::star::frame::XModel
>& xModel
);
1320 void SfxObjectShell::InitOwnModel_Impl()
1322 if ( !pImp
->bModelInitialized
)
1324 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pSalvageItem
, SfxStringItem
, SID_DOC_SALVAGE
, sal_False
);
1327 pImp
->aTempName
= pMedium
->GetPhysicalName();
1328 pMedium
->GetItemSet()->ClearItem( SID_DOC_SALVAGE
);
1329 pMedium
->GetItemSet()->ClearItem( SID_FILE_NAME
);
1330 pMedium
->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME
, pMedium
->GetOrigURL() ) );
1334 pMedium
->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL
);
1335 pMedium
->GetItemSet()->ClearItem( SID_DOCUMENT
);
1338 pMedium
->GetItemSet()->ClearItem( SID_REFERER
);
1339 uno::Reference
< frame::XModel
> xModel ( GetModel(), uno::UNO_QUERY
);
1342 ::rtl::OUString aURL
= GetMedium()->GetOrigURL();
1343 SfxItemSet
*pSet
= GetMedium()->GetItemSet();
1344 if ( !GetMedium()->IsReadOnly() )
1345 pSet
->ClearItem( SID_INPUTSTREAM
);
1346 uno::Sequence
< beans::PropertyValue
> aArgs
;
1347 TransformItems( SID_OPENDOC
, *pSet
, aArgs
);
1348 xModel
->attachResource( aURL
, aArgs
);
1349 impl_addToModelCollection(xModel
);
1352 pImp
->bModelInitialized
= sal_True
;
1356 void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags
)
1358 sal_Bool bSetModifiedTRUE
= sal_False
;
1359 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pSalvageItem
, SfxStringItem
, SID_DOC_SALVAGE
, sal_False
);
1360 if( ( nFlags
& SFX_LOADED_MAINDOCUMENT
) && !(pImp
->nLoadedFlags
& SFX_LOADED_MAINDOCUMENT
)
1361 && !(pImp
->nFlagsInProgress
& SFX_LOADED_MAINDOCUMENT
))
1363 pImp
->nFlagsInProgress
|= SFX_LOADED_MAINDOCUMENT
;
1364 ((SfxHeaderAttributes_Impl
*)GetHeaderAttributes())->SetAttributes();
1365 pImp
->bImportDone
= sal_True
;
1366 if( !IsAbortingImport() )
1367 PositionView_Impl();
1371 bSetModifiedTRUE
= sal_True
;
1373 if ( !IsEnableSetModified() )
1374 EnableSetModified( sal_True
);
1376 if( !bSetModifiedTRUE
&& IsEnableSetModified() )
1377 SetModified( sal_False
);
1379 CheckSecurityOnLoading_Impl();
1381 bHasName
= sal_True
; // the document is loaded, so the name should already available
1382 GetTitle( SFX_TITLE_DETECT
);
1383 InitOwnModel_Impl();
1384 pImp
->nFlagsInProgress
&= ~SFX_LOADED_MAINDOCUMENT
;
1387 if( ( nFlags
& SFX_LOADED_IMAGES
) && !(pImp
->nLoadedFlags
& SFX_LOADED_IMAGES
)
1388 && !(pImp
->nFlagsInProgress
& SFX_LOADED_IMAGES
))
1390 pImp
->nFlagsInProgress
|= SFX_LOADED_IMAGES
;
1391 uno::Reference
<document::XDocumentProperties
> xDocProps(
1392 getDocProperties());
1393 ::rtl::OUString
url(xDocProps
->getAutoloadURL());
1394 sal_Int32
delay(xDocProps
->getAutoloadSecs());
1395 SetAutoLoad( INetURLObject(url
), delay
* 1000,
1396 (delay
> 0) || url
.getLength() );
1397 if( !bSetModifiedTRUE
&& IsEnableSetModified() )
1398 SetModified( sal_False
);
1399 Invalidate( SID_SAVEASDOC
);
1400 pImp
->nFlagsInProgress
&= ~SFX_LOADED_IMAGES
;
1403 pImp
->nLoadedFlags
|= nFlags
;
1405 if ( !pImp
->nFlagsInProgress
)
1407 // in case of reentrance calls the first called FinishedLoading() call on the stack
1408 // should do the notification, in result the notification is done when all the FinishedLoading() calls are finished
1410 if ( bSetModifiedTRUE
)
1411 SetModified( sal_True
);
1413 SetModified( sal_False
);
1415 if ( (pImp
->nLoadedFlags
& SFX_LOADED_MAINDOCUMENT
) && (pImp
->nLoadedFlags
& SFX_LOADED_IMAGES
) )
1417 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pTemplateItem
, SfxBoolItem
, SID_TEMPLATE
, sal_False
);
1418 sal_Bool bTemplate
= pTemplateItem
&& pTemplateItem
->GetValue();
1420 // closing the streams on loading should be under control of SFX!
1421 DBG_ASSERT( pMedium
->IsOpen(), "Don't close the medium when loading documents!" );
1425 TemplateDisconnectionAfterLoad();
1429 // if a readonly medium has storage then it's stream is already based on temporary file
1430 if( !(pMedium
->GetOpenMode() & STREAM_WRITE
) && !pMedium
->HasStorage_Impl() )
1431 // don't lock file opened read only
1432 pMedium
->CloseInStream();
1436 pImp
->bInitialized
= sal_True
;
1437 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_LOADFINISHED
, GlobalEventConfig::GetEventName(STR_EVENT_LOADFINISHED
), this ) );
1439 // Title is not available until loading has finished
1440 Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED
) );
1441 if ( pImp
->nEventId
)
1442 PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
1446 //-------------------------------------------------------------------------
1447 extern void SetTemplate_Impl( const String
&, const String
&, SfxObjectShell
* );
1449 void SfxObjectShell::TemplateDisconnectionAfterLoad()
1451 // document is created from a template
1452 //TODO/LATER: should the templates always be XML docs!
1454 SfxMedium
* pTmpMedium
= pMedium
;
1457 String
aName( pTmpMedium
->GetName() );
1458 SFX_ITEMSET_ARG( pTmpMedium
->GetItemSet(), pTemplNamItem
, SfxStringItem
, SID_TEMPLATE_NAME
, sal_False
);
1459 String aTemplateName
;
1460 if ( pTemplNamItem
)
1461 aTemplateName
= pTemplNamItem
->GetValue();
1464 // !TODO/LATER: what's this?!
1465 // Interaktiv ( DClick, Contextmenu ) kommt kein Langname mit
1466 aTemplateName
= getDocProperties()->getTitle();
1467 if ( !aTemplateName
.Len() )
1469 INetURLObject
aURL( aName
);
1470 aURL
.CutExtension();
1471 aTemplateName
= aURL
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
1475 // set medium to noname
1476 pTmpMedium
->SetName( String(), sal_True
);
1477 pTmpMedium
->Init_Impl();
1483 if( IsPackageStorageFormat_Impl( *pTmpMedium
) )
1485 // untitled document must be based on temporary storage
1486 // the medium should not dispose the storage in this case
1487 uno::Reference
< embed::XStorage
> xTmpStor
= ::comphelper::OStorageHelper::GetTemporaryStorage();
1488 GetStorage()->copyToStorage( xTmpStor
);
1490 // the medium should disconnect from the original location
1491 // the storage should not be disposed since the document is still
1492 // based on it, but in DoSaveCompleted it will be disposed
1493 pTmpMedium
->CanDisposeStorage_Impl( sal_False
);
1494 pTmpMedium
->Close();
1496 // setting the new storage the medium will be based on
1497 pTmpMedium
->SetStorage_Impl( xTmpStor
);
1500 if( !DoSaveCompleted( pTmpMedium
) )
1501 SetError( ERRCODE_IO_GENERAL
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ) );
1504 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pSalvageItem
, SfxStringItem
, SID_DOC_SALVAGE
, sal_False
);
1505 sal_Bool bSalvage
= pSalvageItem
? sal_True
: sal_False
;
1509 // some further initializations for templates
1510 SetTemplate_Impl( aName
, aTemplateName
, this );
1513 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
1514 pTmpMedium
->CanDisposeStorage_Impl( sal_False
);
1519 // some further initializations for templates
1520 SetTemplate_Impl( aName
, aTemplateName
, this );
1521 pTmpMedium
->CreateTempFile( sal_True
);
1524 // templates are never readonly
1525 pTmpMedium
->GetItemSet()->ClearItem( SID_DOC_READONLY
);
1526 pTmpMedium
->SetOpenMode( SFX_STREAM_READWRITE
, sal_True
, sal_True
);
1528 // notifications about possible changes in readonly state and document info
1529 Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED
) );
1531 // created untitled document can't be modified
1532 SetModified( sal_False
);
1536 //-------------------------------------------------------------------------
1538 void SfxObjectShell::PositionView_Impl()
1540 MarkData_Impl
*pMark
= Get_Impl()->pMarkData
;
1543 SfxViewShell
* pSh
= pMark
->pFrame
->GetViewShell();
1544 if( pMark
->aUserData
.Len() )
1545 pSh
->ReadUserData( pMark
->aUserData
, sal_True
);
1546 else if( pMark
->aMark
.Len() )
1547 pSh
->JumpToMark( pMark
->aMark
);
1548 DELETEZ( Get_Impl()->pMarkData
);
1552 //-------------------------------------------------------------------------
1554 sal_Bool
SfxObjectShell::IsLoading() const
1556 Wurde bereits FinishedLoading aufgerufeb? */
1558 return !( pImp
->nLoadedFlags
& SFX_LOADED_MAINDOCUMENT
);
1561 //-------------------------------------------------------------------------
1563 void SfxObjectShell::CancelTransfers()
1565 Hier koennen Transfers gecanceled werden, die nicht mit
1566 RegisterTransfer registiert wurden */
1568 GetMedium()->CancelTransfers();
1569 if( ( pImp
->nLoadedFlags
& SFX_LOADED_ALL
) != SFX_LOADED_ALL
)
1573 FinishedLoading( SFX_LOADED_ALL
);
1576 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
1579 pFrame->CancelTransfers();
1580 pFrame = SfxViewFrame::GetNext( *pFrame, this );
1585 //-------------------------------------------------------------------------
1587 AutoReloadTimer_Impl::AutoReloadTimer_Impl(
1588 const String
& rURL
, sal_uInt32 nTime
, sal_Bool bReloadP
, SfxObjectShell
* pSh
)
1589 : aUrl( rURL
), bReload( bReloadP
), pObjSh( pSh
)
1591 SetTimeout( nTime
);
1594 //-------------------------------------------------------------------------
1596 void AutoReloadTimer_Impl::Timeout()
1598 SfxViewFrame
*pFrame
= SfxViewFrame::GetFirst( pObjSh
);
1602 // momentan nicht m"oglich/sinnvoll?
1603 if ( !pObjSh
->CanReload_Impl() || pObjSh
->IsAutoLoadLocked() || Application::IsUICaptured() )
1605 // erneuten Versuch erlauben
1610 SfxAllItemSet
aSet( SFX_APP()->GetPool() );
1611 aSet
.Put( SfxBoolItem( SID_AUTOLOAD
, sal_True
) );
1613 aSet
.Put( SfxStringItem( SID_FILE_NAME
, aUrl
) );
1614 SfxRequest
aReq( SID_RELOAD
, 0, aSet
);
1615 pObjSh
->Get_Impl()->pReloadTimer
= 0;
1617 pFrame
->ExecReload_Impl( aReq
);
1621 pObjSh
->Get_Impl()->pReloadTimer
= 0;
1625 SfxModule
* SfxObjectShell::GetModule() const
1627 return GetFactory().GetModule();
1630 sal_Bool
SfxObjectShell::IsBasic(
1631 const String
& rCode
, SbxObject
* pVCtrl
)
1633 if( !rCode
.Len() ) return sal_False
;
1634 return SfxMacroConfig::IsBasic( pVCtrl
, rCode
, GetBasicManager() );
1637 ErrCode
SfxObjectShell::CallBasic( const String
& rMacro
,
1638 const String
& rBasic
, SbxObject
* pVCtrl
, SbxArray
* pArgs
,
1641 SfxApplication
* pApp
= SFX_APP();
1642 if( pApp
->GetName() != rBasic
)
1644 if ( !AdjustMacroMode( String() ) )
1645 return ERRCODE_IO_ACCESSDENIED
;
1648 pApp
->EnterBasicCall();
1649 BasicManager
*pMgr
= GetBasicManager();
1650 if( pApp
->GetName() == rBasic
)
1651 pMgr
= pApp
->GetBasicManager();
1652 ErrCode nRet
= SfxMacroConfig::Call( pVCtrl
, rMacro
, pMgr
, pArgs
, pRet
);
1653 pApp
->LeaveBasicCall();
1657 ErrCode
SfxObjectShell::Call( const String
& rCode
, sal_Bool bIsBasicReturn
, SbxObject
* pVCtrl
)
1659 ErrCode nErr
= ERRCODE_NONE
;
1660 if ( bIsBasicReturn
)
1661 CallBasic( rCode
, String(), pVCtrl
);
1667 static bool lcl_isScriptAccessAllowed_nothrow( const Reference
< XInterface
>& _rxScriptContext
)
1671 Reference
< XEmbeddedScripts
> xScripts( _rxScriptContext
, UNO_QUERY
);
1672 if ( !xScripts
.is() )
1674 Reference
< XScriptInvocationContext
> xContext( _rxScriptContext
, UNO_QUERY_THROW
);
1675 xScripts
.set( xContext
->getScriptContainer(), UNO_SET_THROW
);
1678 return xScripts
->getAllowMacroExecution();
1680 catch( const Exception
& )
1682 DBG_UNHANDLED_EXCEPTION();
1688 ErrCode
SfxObjectShell::CallXScript( const Reference
< XInterface
>& _rxScriptContext
, const ::rtl::OUString
& _rScriptURL
,
1689 const Sequence
< Any
>& aParams
, Any
& aRet
, Sequence
< sal_Int16
>& aOutParamIndex
, Sequence
< Any
>& aOutParam
, bool bRaiseError
, ::com::sun::star::uno::Any
* pCaller
)
1691 OSL_TRACE( "in CallXScript" );
1692 ErrCode nErr
= ERRCODE_NONE
;
1694 bool bIsDocumentScript
= ( _rScriptURL
.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "location=document" ) ) >= 0 );
1695 // TODO: we should parse the URL, and check whether there is a parameter with this name.
1696 // Otherwise, we might find too much.
1697 if ( bIsDocumentScript
&& !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext
) )
1698 return ERRCODE_IO_ACCESSDENIED
;
1700 bool bCaughtException
= false;
1704 // obtain/create a script provider
1705 Reference
< provider::XScriptProvider
> xScriptProvider
;
1706 Reference
< provider::XScriptProviderSupplier
> xSPS( _rxScriptContext
, UNO_QUERY
);
1708 xScriptProvider
.set( xSPS
->getScriptProvider() );
1710 if ( !xScriptProvider
.is() )
1712 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
1713 Reference
< provider::XScriptProviderFactory
> xScriptProviderFactory(
1714 aContext
.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW
);
1715 xScriptProvider
.set( xScriptProviderFactory
->createScriptProvider( makeAny( _rxScriptContext
) ), UNO_SET_THROW
);
1718 // obtain the script, and execute it
1719 Reference
< provider::XScript
> xScript( xScriptProvider
->getScript( _rScriptURL
), UNO_QUERY_THROW
);
1720 if ( pCaller
&& pCaller
->hasValue() )
1722 Reference
< beans::XPropertySet
> xProps( xScript
, uno::UNO_QUERY
);
1725 Sequence
< uno::Any
> aArgs( 1 );
1726 aArgs
[ 0 ] = *pCaller
;
1727 xProps
->setPropertyValue( rtl::OUString::createFromAscii("Caller"), uno::makeAny( aArgs
) );
1730 aRet
= xScript
->invoke( aParams
, aOutParamIndex
, aOutParam
);
1732 catch ( const uno::Exception
& )
1734 aException
= ::cppu::getCaughtException();
1735 bCaughtException
= TRUE
;
1736 nErr
= ERRCODE_BASIC_INTERNAL_ERROR
;
1739 if ( bCaughtException
&& bRaiseError
)
1741 ::std::auto_ptr
< VclAbstractDialog
> pScriptErrDlg
;
1742 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1744 pScriptErrDlg
.reset( pFact
->CreateScriptErrorDialog( NULL
, aException
) );
1745 OSL_ENSURE( pScriptErrDlg
.get(), "SfxObjectShell::CallXScript: no script error dialog!" );
1747 if ( pScriptErrDlg
.get() )
1748 pScriptErrDlg
->Execute();
1751 OSL_TRACE( "leaving CallXScript" );
1755 // perhaps rename to CallScript once we get rid of the existing CallScript
1756 // and Call, CallBasic, CallStarBasic methods
1757 ErrCode
SfxObjectShell::CallXScript( const String
& rScriptURL
,
1758 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>&
1760 ::com::sun::star::uno::Any
& aRet
,
1761 ::com::sun::star::uno::Sequence
< sal_Int16
>& aOutParamIndex
,
1762 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>&
1763 aOutParam
, bool bRaiseError
, ::com::sun::star::uno::Any
* pCaller
)
1765 return CallXScript( GetModel(), rScriptURL
, aParams
, aRet
, aOutParamIndex
, aOutParam
, bRaiseError
, pCaller
);
1768 //-------------------------------------------------------------------------
1770 using namespace ::com::sun::star::uno
;
1772 //.....................................................................
1773 static SbxArrayRef
lcl_translateUno2Basic( const void* _pAnySequence
)
1775 SbxArrayRef xReturn
;
1776 if ( _pAnySequence
)
1778 // in real it's a sequence of Any (by convention)
1779 const Sequence
< Any
>* pArguments
= static_cast< const Sequence
< Any
>* >( _pAnySequence
);
1781 // do we have arguments ?
1782 if ( pArguments
->getLength() )
1785 xReturn
= new SbxArray
;
1788 // loop through the sequence
1789 const Any
* pArg
= pArguments
->getConstArray();
1790 const Any
* pArgEnd
= pArg
+ pArguments
->getLength();
1792 for ( sal_uInt16 nArgPos
=1; pArg
!= pArgEnd
; ++pArg
, ++nArgPos
)
1793 // and create a Sb object for every Any
1794 xReturn
->Put( GetSbUnoObject( sEmptyName
, *pArg
), nArgPos
);
1799 //.....................................................................
1800 void lcl_translateBasic2Uno( const SbxVariableRef
& _rBasicValue
, void* _pAny
)
1803 *static_cast< Any
* >( _pAny
) = sbxToUnoValue( _rBasicValue
);
1806 //-------------------------------------------------------------------------
1807 ErrCode
SfxObjectShell::CallStarBasicScript( const String
& _rMacroName
, const String
& _rLocation
,
1808 const void* _pArguments
, void* _pReturn
)
1810 OSL_TRACE("in CallSBS");
1811 ::vos::OClearableGuard
aGuard( Application::GetSolarMutex() );
1813 // the arguments for the call
1814 SbxArrayRef xMacroArguments
= lcl_translateUno2Basic( _pArguments
);
1817 SbxVariableRef xReturn
= _pReturn
? new SbxVariable
: NULL
;
1819 // the location (document or application)
1820 String sMacroLocation
;
1821 if ( _rLocation
.EqualsAscii( "application" ) )
1822 sMacroLocation
= SFX_APP()->GetName();
1825 DBG_ASSERT( _rLocation
.EqualsAscii( "document" ),
1826 "SfxObjectShell::CallStarBasicScript: invalid (unknown) location!" );
1830 ErrCode eError
= CallBasic( _rMacroName
, sMacroLocation
, NULL
, xMacroArguments
, xReturn
);
1832 // translate the return value
1833 lcl_translateBasic2Uno( xReturn
, _pReturn
);
1839 //-------------------------------------------------------------------------
1840 ErrCode
SfxObjectShell::CallScript(
1841 const String
& rScriptType
,
1842 const String
& rCode
,
1847 ::vos::OClearableGuard
aGuard( Application::GetSolarMutex() );
1848 ErrCode nErr
= ERRCODE_NONE
;
1849 if( rScriptType
.EqualsAscii( "StarBasic" ) )
1851 // the arguments for the call
1852 SbxArrayRef xMacroArguments
= lcl_translateUno2Basic( pArgs
);
1855 SbxVariableRef xReturn
= pRet
? new SbxVariable
: NULL
;
1858 nErr
= CallBasic( rCode
, String(), NULL
, xMacroArguments
, xReturn
);
1860 // translate the return value
1861 lcl_translateBasic2Uno( xReturn
, pRet
);
1863 // did this fail because the method was not found?
1864 if ( nErr
== ERRCODE_BASIC_PROC_UNDEFINED
)
1865 { // yep-> look in the application BASIC module
1866 nErr
= CallBasic( rCode
, SFX_APP()->GetName(), NULL
, xMacroArguments
, xReturn
);
1869 else if( rScriptType
.EqualsAscii( "JavaScript" ) )
1871 DBG_ERROR( "JavaScript not allowed" );
1876 DBG_ERROR( "StarScript not allowed" );
1881 SfxFrame
* SfxObjectShell::GetSmartSelf( SfxFrame
* pSelf
, SfxMedium
& /*rMedium*/ )
1886 SfxObjectShellFlags
SfxObjectShell::GetFlags() const
1888 if( pImp
->eFlags
== SFXOBJECTSHELL_UNDEFINED
)
1889 pImp
->eFlags
= GetFactory().GetFlags();
1890 return pImp
->eFlags
;
1893 void SfxObjectShell::SetFlags( SfxObjectShellFlags eFlags
)
1895 pImp
->eFlags
= eFlags
;
1899 void SfxObjectShell::SetBaseURL( const String& rURL )
1901 pImp->aBaseURL = rURL;
1902 pImp->bNoBaseURL = FALSE;
1905 const String& SfxObjectShell::GetBaseURLForSaving() const
1907 if ( pImp->bNoBaseURL )
1909 return GetBaseURL();
1912 const String& SfxObjectShell::GetBaseURL() const
1914 if ( pImp->aBaseURL.Len() )
1915 return pImp->aBaseURL;
1916 return pMedium->GetBaseURL();
1919 void SfxObjectShell::SetEmptyBaseURL()
1921 pImp->bNoBaseURL = TRUE;
1924 String
SfxObjectShell::QueryTitle( SfxTitleQuery eType
) const
1930 case SFX_TITLE_QUERY_SAVE_NAME_PROPOSAL
:
1932 SfxMedium
* pMed
= GetMedium();
1933 const INetURLObject
aObj( pMed
->GetName() );
1934 aRet
= aObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
1936 aRet
= GetTitle( SFX_TITLE_CAPTION
);
1943 void SfxHeaderAttributes_Impl::SetAttributes()
1947 for( sal_Bool bCont
= xIter
->GetFirst( aPair
); bCont
;
1948 bCont
= xIter
->GetNext( aPair
) )
1949 SetAttribute( aPair
);
1952 void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue
& rKV
)
1954 String aValue
= rKV
.GetValue();
1955 if( rKV
.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL
&& rKV
.GetValue().Len() )
1957 sal_uInt32 nTime
= aValue
.GetToken( 0, ';' ).ToInt32() ;
1958 String aURL
= aValue
.GetToken( 1, ';' );
1959 aURL
.EraseTrailingChars().EraseLeadingChars();
1960 uno::Reference
<document::XDocumentProperties
> xDocProps(
1961 pDoc
->getDocProperties());
1962 if( aURL
.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL
)
1965 INetURLObject( pDoc
->GetMedium()->GetName() ).GetNewAbsURL( aURL
.Copy( 4 ), &aObj
);
1966 xDocProps
->setAutoloadURL(
1967 aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1971 xDocProps
->setAutoloadSecs( nTime
);
1973 catch (lang::IllegalArgumentException
&)
1978 else if( rKV
.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL
)
1981 if( INetRFC822Message::ParseDateField( rKV
.GetValue(), aDateTime
) )
1983 aDateTime
.ConvertToLocalTime();
1984 pDoc
->GetMedium()->SetExpired_Impl( aDateTime
);
1988 // DBG_ERROR( "Schlechtes ::com::sun::star::util::DateTime fuer Expired" );
1989 pDoc
->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) );
1992 else if( rKV
.GetKey().CompareIgnoreCaseToAscii( "content-type" ) == COMPARE_EQUAL
)
1994 ::rtl::OString sContent
= ::rtl::OUStringToOString( aValue
, RTL_TEXTENCODING_ASCII_US
);
1995 ByteString sType
, sSubType
;
1996 INetContentTypeParameterList aParameters
;
1998 if( INetContentTypes::parse( sContent
, sType
, sSubType
, &aParameters
) )
2000 const INetContentTypeParameter
* pCharset
= aParameters
.find("charset");
2002 pDoc
->GetMedium()->SetCharset( pCharset
->m_sValue
);
2007 void SfxHeaderAttributes_Impl::Append( const SvKeyValue
& rKV
)
2009 xIter
->Append( rKV
);
2010 if( bAlert
) SetAttribute( rKV
);
2013 SvKeyValueIterator
* SfxObjectShell::GetHeaderAttributes()
2015 if( !pImp
->xHeaderAttributes
.Is() )
2017 DBG_ASSERT( pMedium
, "Kein Medium" );
2018 pImp
->xHeaderAttributes
= new SfxHeaderAttributes_Impl( this );
2020 return ( SvKeyValueIterator
*) &pImp
->xHeaderAttributes
;
2023 void SfxObjectShell::ClearHeaderAttributesForSourceViewHack()
2025 ((SfxHeaderAttributes_Impl
*)GetHeaderAttributes())
2026 ->ClearForSourceView();
2030 void SfxObjectShell::SetHeaderAttributesForSourceViewHack()
2032 ((SfxHeaderAttributes_Impl
*)GetHeaderAttributes())
2036 void SfxObjectShell::StartLoading_Impl()
2038 pImp
->nLoadedFlags
= 0;
2039 pImp
->bModelInitialized
= sal_False
;
2042 sal_Bool
SfxObjectShell::IsPreview() const
2047 sal_Bool bPreview
= sal_False
;
2048 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pFlags
, SfxStringItem
, SID_OPTIONS
, sal_False
);
2051 // Werte auf einzelne Items verteilen
2052 String aFileFlags
= pFlags
->GetValue();
2053 aFileFlags
.ToUpperAscii();
2054 if ( STRING_NOTFOUND
!= aFileFlags
.Search( 'B' ) )
2055 bPreview
= sal_True
;
2060 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pItem
, SfxBoolItem
, SID_PREVIEW
, sal_False
);
2062 bPreview
= pItem
->GetValue();
2068 sal_Bool
SfxObjectShell::IsSecure()
2070 // Wenn globale Warnung an ist, nach Secure-Referer-Liste gehen
2071 String aReferer
= GetMedium()->GetName();
2072 if ( !aReferer
.Len() )
2074 // bei neuen Dokumenten das Template als Referer nehmen
2075 ::rtl::OUString
aTempl( getDocProperties()->getTemplateURL() );
2076 if ( aTempl
.getLength() )
2077 aReferer
= INetURLObject( aTempl
).GetMainURL( INetURLObject::NO_DECODE
);
2080 INetURLObject
aURL( "macro:" );
2081 if ( !aReferer
.Len() )
2082 // empty new or embedded document
2085 SvtSecurityOptions aOpt
;
2087 if( aOpt
.GetBasicMode() == eALWAYS_EXECUTE
)
2090 if( aOpt
.GetBasicMode() == eNEVER_EXECUTE
)
2093 if ( aOpt
.IsSecureURL( aURL
.GetMainURL( INetURLObject::NO_DECODE
), aReferer
) )
2094 //if ( SvtSecurityOptions().IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) )
2096 if ( GetMedium()->GetContent().is() )
2098 Any
aAny( ::utl::UCBContentHelper::GetProperty( aURL
.GetMainURL( INetURLObject::NO_DECODE
), String( RTL_CONSTASCII_USTRINGPARAM("IsProtected")) ) );
2099 sal_Bool bIsProtected
= FALSE
;
2100 if ( ( aAny
>>= bIsProtected
) && bIsProtected
)
2112 void SfxObjectShell::SetWaitCursor( BOOL bSet
) const
2114 for( SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( this ); pFrame
; pFrame
= SfxViewFrame::GetNext( *pFrame
, this ) )
2117 pFrame
->GetFrame()->GetWindow().EnterWait();
2119 pFrame
->GetFrame()->GetWindow().LeaveWait();
2123 String
SfxObjectShell::GetAPIName() const
2125 INetURLObject
aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
2126 String
aName( aURL
.GetBase() );
2128 aName
= aURL
.GetURLNoPass();
2130 aName
= GetTitle( SFX_TITLE_DETECT
);
2134 void SfxObjectShell::Invalidate( USHORT nId
)
2136 for( SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( this ); pFrame
; pFrame
= SfxViewFrame::GetNext( *pFrame
, this ) )
2137 Invalidate_Impl( pFrame
->GetBindings(), nId
);
2140 bool SfxObjectShell::AdjustMacroMode( const String
& /*rScriptType*/, bool bSuppressUI
)
2142 uno::Reference
< task::XInteractionHandler
> xInteraction
;
2143 if ( pMedium
&& !bSuppressUI
)
2144 xInteraction
= pMedium
->GetInteractionHandler();
2146 CheckForBrokenDocSignatures_Impl( xInteraction
);
2148 CheckEncryption_Impl( xInteraction
);
2150 return pImp
->aMacroMode
.adjustMacroMode( xInteraction
);
2153 Window
* SfxObjectShell::GetDialogParent( SfxMedium
* pLoadingMedium
)
2155 Window
* pWindow
= 0;
2156 SfxItemSet
* pSet
= pLoadingMedium
? pLoadingMedium
->GetItemSet() : GetMedium()->GetItemSet();
2157 SFX_ITEMSET_ARG( pSet
, pUnoItem
, SfxUnoAnyItem
, SID_FILLFRAME
, FALSE
);
2160 uno::Reference
< frame::XFrame
> xFrame
;
2161 pUnoItem
->GetValue() >>= xFrame
;
2163 pWindow
= VCLUnoHelper::GetWindow( xFrame
->getContainerWindow() );
2168 SfxFrame
* pFrame
= 0;
2169 SFX_ITEMSET_ARG( pSet
, pFrameItem
, SfxFrameItem
, SID_DOCFRAME
, FALSE
);
2170 if( pFrameItem
&& pFrameItem
->GetFrame() )
2171 // get target frame from ItemSet
2172 pFrame
= pFrameItem
->GetFrame();
2175 // try the current frame
2176 SfxViewFrame
* pView
= SfxViewFrame::Current();
2177 if ( !pView
|| pView
->GetObjectShell() != this )
2178 // get any visible frame
2179 pView
= SfxViewFrame::GetFirst(this);
2181 pFrame
= pView
->GetFrame();
2185 // get topmost window
2186 pWindow
= VCLUnoHelper::GetWindow( pFrame
->GetFrameInterface()->getContainerWindow() );
2191 // this frame may be invisible, show it if it is allowed
2192 SFX_ITEMSET_ARG( pSet
, pHiddenItem
, SfxBoolItem
, SID_HIDDEN
, sal_False
);
2193 if ( !pHiddenItem
|| !pHiddenItem
->GetValue() )
2203 String
SfxObjectShell::UpdateTitle( SfxMedium
* pMed
, USHORT nDocViewNumber
)
2205 // Titel des Fensters
2209 INetURLObject
aTmp( pMed
->GetName() );
2210 aTitle
= aTmp
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
2215 aTitle
= GetTitle(SFX_TITLE_CAPTION
);
2216 String
aName(aTitle
);
2217 if ( nDocViewNumber
)
2220 aName
+= String::CreateFromInt32( nDocViewNumber
);
2226 SFX_ITEMSET_ARG( pMed
->GetItemSet(), pRepairedDocItem
, SfxBoolItem
, SID_REPAIRPACKAGE
, sal_False
);
2227 if ( pRepairedDocItem
&& pRepairedDocItem
->GetValue() )
2228 aTitle
+= String( SfxResId(STR_REPAIREDDOCUMENT
) );
2231 if ( IsReadOnlyUI() || (pMed
&& pMed
->IsReadOnly()) )
2232 aTitle
+= String( SfxResId(STR_READONLY
) );
2233 else if ( IsDocShared() )
2234 aTitle
+= String( SfxResId(STR_SHARED
) );
2239 void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode
)
2241 eCreateMode
= nMode
;
2244 BOOL
SfxObjectShell::IsInPlaceActive()
2246 if ( eCreateMode
!= SFX_CREATE_MODE_EMBEDDED
)
2249 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( this );
2250 return pFrame
&& pFrame
->GetFrame()->IsInPlace();
2253 BOOL
SfxObjectShell::IsUIActive()
2255 if ( eCreateMode
!= SFX_CREATE_MODE_EMBEDDED
)
2258 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( this );
2259 return pFrame
&& pFrame
->GetFrame()->IsInPlace() && pFrame
->GetFrame()->GetWorkWindow_Impl()->IsVisible_Impl();
2262 void SfxObjectShell::UIActivate( BOOL
)
2266 void SfxObjectShell::InPlaceActivate( BOOL
)
2270 sal_Bool
SfxObjectShell::UseInteractionToHandleError(
2271 const uno::Reference
< task::XInteractionHandler
>& xHandler
,
2274 sal_Bool bResult
= sal_False
;
2276 if ( xHandler
.is() )
2280 uno::Any aInteraction
;
2281 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > lContinuations(2);
2282 ::framework::ContinuationAbort
* pAbort
= new ::framework::ContinuationAbort();
2283 ::framework::ContinuationApprove
* pApprove
= new ::framework::ContinuationApprove();
2284 lContinuations
[0] = uno::Reference
< task::XInteractionContinuation
>(
2285 static_cast< task::XInteractionContinuation
* >( pAbort
), uno::UNO_QUERY
);
2286 lContinuations
[1] = uno::Reference
< task::XInteractionContinuation
>(
2287 static_cast< task::XInteractionContinuation
* >( pApprove
), uno::UNO_QUERY
);
2289 task::ErrorCodeRequest aErrorCode
;
2290 aErrorCode
.ErrCode
= nError
;
2291 aInteraction
<<= aErrorCode
;
2293 ::framework::InteractionRequest
* pRequest
= new ::framework::InteractionRequest(aInteraction
,lContinuations
);
2294 uno::Reference
< task::XInteractionRequest
> xRequest(
2295 static_cast< task::XInteractionRequest
* >( pRequest
),
2298 xHandler
->handle(xRequest
);
2299 bResult
= pAbort
->isSelected();
2301 catch( uno::Exception
& )
2308 sal_Bool
SfxObjectShell_Impl::NeedsOfficeUpdateDialog()
2310 // if the configuration is not available for any reason, the default behavior is to show the message
2311 sal_Bool bResult
= sal_True
;
2315 uno::Reference
< lang::XMultiServiceFactory
> xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW
);
2316 uno::Reference
< uno::XInterface
> xCommonConfig(
2317 ::comphelper::ConfigurationHelper::openConfig(
2319 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
2320 ::comphelper::ConfigurationHelper::E_STANDARD
),
2321 uno::UNO_SET_THROW
);
2323 ::comphelper::ConfigurationHelper::readRelativeKey(
2325 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Load/" ) ),
2326 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowOfficeUpdateDialog" ) ) ) >>= bResult
;
2328 catch( uno::Exception
& )
2335 sal_Int16
SfxObjectShell_Impl::getCurrentMacroExecMode() const
2337 sal_Int16
nImposedExecMode( MacroExecMode::NEVER_EXECUTE
);
2339 const SfxMedium
* pMedium( rDocShell
.GetMedium() );
2340 OSL_PRECOND( pMedium
, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
2343 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pMacroModeItem
, SfxUInt16Item
, SID_MACROEXECMODE
, sal_False
);
2344 if ( pMacroModeItem
)
2345 nImposedExecMode
= pMacroModeItem
->GetValue();
2347 return nImposedExecMode
;
2350 sal_Bool
SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode
)
2352 const SfxMedium
* pMedium( rDocShell
.GetMedium() );
2353 OSL_PRECOND( pMedium
, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
2356 pMedium
->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE
, nMacroMode
) );
2363 ::rtl::OUString
SfxObjectShell_Impl::getDocumentLocation() const
2365 ::rtl::OUString sLocation
;
2367 const SfxMedium
* pMedium( rDocShell
.GetMedium() );
2368 OSL_PRECOND( pMedium
, "SfxObjectShell_Impl::getDocumentLocation: no medium!" );
2371 sLocation
= pMedium
->GetName();
2372 if ( !sLocation
.getLength() )
2374 // for documents made from a template: get the name of the template
2375 sLocation
= rDocShell
.getDocProperties()->getTemplateURL();
2381 uno::Reference
< embed::XStorage
> SfxObjectShell_Impl::getZipStorageToSign()
2383 Reference
< embed::XStorage
> xStore
;
2385 SfxMedium
* pMedium( rDocShell
.GetMedium() );
2386 OSL_PRECOND( pMedium
, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" );
2388 xStore
= pMedium
->GetZipStorageToSign_Impl();
2393 sal_Bool
SfxObjectShell_Impl::documentStorageHasMacros() const
2395 return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage
);
2398 Reference
< XEmbeddedScripts
> SfxObjectShell_Impl::getEmbeddedDocumentScripts() const
2400 return Reference
< XEmbeddedScripts
>( rDocShell
.GetModel(), UNO_QUERY
);
2403 sal_Int16
SfxObjectShell_Impl::getScriptingSignatureState()
2405 sal_Int16
nSignatureState( rDocShell
.GetScriptingSignatureState() );
2407 if ( nSignatureState
!= SIGNATURESTATE_NOSIGNATURES
&& m_bMacroSignBroken
)
2409 // if there is a macro signature it must be handled as broken
2410 nSignatureState
= SIGNATURESTATE_SIGNATURES_BROKEN
;
2413 return nSignatureState
;
2416 sal_Bool
SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor
)
2418 sal_Bool bResult
= sal_False
;
2422 ::rtl::OUString aVersion
;
2425 uno::Reference
< beans::XPropertySet
> xPropSet( rDocShell
.GetStorage(), uno::UNO_QUERY_THROW
);
2426 xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion
;
2428 catch( uno::Exception
& )
2431 uno::Sequence
< uno::Any
> aArgs( 1 );
2432 aArgs
[0] <<= aVersion
;
2434 uno::Reference
< security::XDocumentDigitalSignatures
> xSigner( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs
), uno::UNO_QUERY_THROW
);
2436 if ( nScriptingSignatureState
== SIGNATURESTATE_UNKNOWN
2437 || nScriptingSignatureState
== SIGNATURESTATE_SIGNATURES_OK
2438 || nScriptingSignatureState
== SIGNATURESTATE_SIGNATURES_NOTVALIDATED
)
2440 uno::Sequence
< security::DocumentSignatureInformation
> aInfo
= rDocShell
.ImplAnalyzeSignature( sal_True
, xSigner
);
2442 if ( aInfo
.getLength() )
2444 if ( nScriptingSignatureState
== SIGNATURESTATE_UNKNOWN
)
2445 nScriptingSignatureState
= rDocShell
.ImplCheckSignaturesInformation( aInfo
);
2447 if ( nScriptingSignatureState
== SIGNATURESTATE_SIGNATURES_OK
2448 || nScriptingSignatureState
== SIGNATURESTATE_SIGNATURES_NOTVALIDATED
)
2450 for ( sal_Int32 nInd
= 0; !bResult
&& nInd
< aInfo
.getLength(); nInd
++ )
2452 bResult
= xSigner
->isAuthorTrusted( aInfo
[nInd
].Signer
);
2455 if ( !bResult
&& bAllowUIToAddAuthor
)
2457 uno::Reference
< task::XInteractionHandler
> xInteraction
;
2458 if ( rDocShell
.GetMedium() )
2459 xInteraction
= rDocShell
.GetMedium()->GetInteractionHandler();
2461 if ( xInteraction
.is() )
2463 task::DocumentMacroConfirmationRequest2 aRequest
;
2464 aRequest
.DocumentURL
= getDocumentLocation();
2465 aRequest
.DocumentZipStorage
= rDocShell
.GetMedium()->GetZipStorageToSign_Impl();
2466 aRequest
.DocumentSignatureInformation
= aInfo
;
2467 aRequest
.DocumentVersion
= aVersion
;
2468 aRequest
.Classification
= task::InteractionClassification_QUERY
;
2469 bResult
= SfxMedium::CallApproveHandler( xInteraction
, uno::makeAny( aRequest
), sal_True
);
2476 catch( uno::Exception
& )
2482 void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference
< task::XInteractionHandler
>& _rxInteraction
) const
2484 if ( !bSignatureErrorIsShown
)
2486 SfxObjectShell::UseInteractionToHandleError( _rxInteraction
, ERRCODE_SFX_BROKENSIGNATURE
);
2487 const_cast< SfxObjectShell_Impl
* >( this )->bSignatureErrorIsShown
= sal_True
;
2491 void SfxObjectShell::AddLog( const ::rtl::OUString
& aMessage
)
2493 if ( !pImp
->m_xLogRing
.is() )
2497 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
2498 if ( aContext
.is() )
2499 pImp
->m_xLogRing
.set( aContext
.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW
);
2501 catch( uno::Exception
& )
2505 if ( pImp
->m_xLogRing
.is() )
2506 pImp
->m_xLogRing
->logString( aMessage
);
2511 void WriteStringInStream( const uno::Reference
< io::XOutputStream
>& xOutStream
, const ::rtl::OUString
& aString
)
2513 if ( xOutStream
.is() )
2515 ::rtl::OString aStrLog
= ::rtl::OUStringToOString( aString
, RTL_TEXTENCODING_UTF8
);
2516 uno::Sequence
< sal_Int8
> aLogData( (const sal_Int8
*)aStrLog
.getStr(), aStrLog
.getLength() );
2517 xOutStream
->writeBytes( aLogData
);
2519 aLogData
.realloc( 1 );
2521 xOutStream
->writeBytes( aLogData
);
2527 void SfxObjectShell::StoreLog()
2529 if ( !pImp
->m_xLogRing
.is() )
2533 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
2534 if ( aContext
.is() )
2535 pImp
->m_xLogRing
.set( aContext
.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW
);
2537 catch( uno::Exception
& )
2541 if ( pImp
->m_xLogRing
.is() )
2543 ::rtl::OUString aFileURL
=
2544 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$BRAND_BASE_DIR/program/bootstrap.ini:UserInstallation}" ) );
2545 ::rtl::Bootstrap::expandMacros( aFileURL
);
2547 ::rtl::OUString aBuildID
=
2548 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$BRAND_BASE_DIR/program/setup.ini:buildid}" ) );
2549 ::rtl::Bootstrap::expandMacros( aBuildID
);
2551 if ( aFileURL
.getLength() )
2553 aFileURL
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/temp/document_io_logring.txt" ) );
2556 uno::Reference
< lang::XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW
);
2557 uno::Reference
< ucb::XSimpleFileAccess
> xSimpleFileAccess( xFactory
->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW
);
2558 uno::Reference
< io::XStream
> xStream( xSimpleFileAccess
->openFileReadWrite( aFileURL
), uno::UNO_SET_THROW
);
2559 uno::Reference
< io::XOutputStream
> xOutStream( xStream
->getOutputStream(), uno::UNO_SET_THROW
);
2560 uno::Reference
< io::XTruncate
> xTruncate( xOutStream
, uno::UNO_QUERY_THROW
);
2561 xTruncate
->truncate();
2563 if ( aBuildID
.getLength() )
2564 WriteStringInStream( xOutStream
, aBuildID
);
2566 uno::Sequence
< ::rtl::OUString
> aLogSeq
= pImp
->m_xLogRing
->getCollectedLog();
2567 for ( sal_Int32 nInd
= 0; nInd
< aLogSeq
.getLength(); nInd
++ )
2568 WriteStringInStream( xOutStream
, aLogSeq
[nInd
] );
2570 catch( uno::Exception
& )