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