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