xref: /aoo41x/main/sfx2/source/doc/objmisc.cxx (revision 8699c4ff)
1d119d52dSAndrew Rist /**************************************************************
2*8699c4ffSmseidel  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*8699c4ffSmseidel  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*8699c4ffSmseidel  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19*8699c4ffSmseidel  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22d119d52dSAndrew 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"
149*8699c4ffSmseidel #include <openflag.hxx> // SFX_STREAM_READWRITE
150*8699c4ffSmseidel 
151*8699c4ffSmseidel #define C2S(cChar) String::CreateFromAscii( cChar )
152cdf0e10cSrcweir 
153cdf0e10cSrcweir using namespace ::com::sun::star;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir // class SfxHeaderAttributes_Impl ----------------------------------------
156cdf0e10cSrcweir 
157cdf0e10cSrcweir class SfxHeaderAttributes_Impl : public SvKeyValueIterator
158cdf0e10cSrcweir {
159cdf0e10cSrcweir private:
160cdf0e10cSrcweir 	SfxObjectShell* pDoc;
161cdf0e10cSrcweir 	SvKeyValueIteratorRef xIter;
162cdf0e10cSrcweir 	sal_Bool bAlert;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir public:
165cdf0e10cSrcweir 	SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) :
166cdf0e10cSrcweir 		SvKeyValueIterator(), pDoc( pSh ),
167cdf0e10cSrcweir 		xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ),
168cdf0e10cSrcweir 		bAlert( sal_False ) {}
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); }
171cdf0e10cSrcweir 	virtual sal_Bool GetNext( SvKeyValue& rKV ) { return xIter->GetNext( rKV ); }
172cdf0e10cSrcweir 	virtual void Append( const SvKeyValue& rKV );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = sal_False; }
175cdf0e10cSrcweir 	void SetAttributes();
176cdf0e10cSrcweir 	void SetAttribute( const SvKeyValue& rKV );
177cdf0e10cSrcweir };
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //=========================================================================
180cdf0e10cSrcweir 
181cdf0e10cSrcweir sal_uInt16 __READONLY_DATA aTitleMap_Impl[3][2] =
182cdf0e10cSrcweir {
183cdf0e10cSrcweir 								//	local				remote
184cdf0e10cSrcweir 	/*	SFX_TITLE_CAPTION	*/	{ 	SFX_TITLE_FILENAME, SFX_TITLE_TITLE },
185*8699c4ffSmseidel 	/*	SFX_TITLE_PICKLIST	*/	{ 	32,					SFX_TITLE_FULLNAME },
186cdf0e10cSrcweir 	/*	SFX_TITLE_HISTORY	*/	{ 	32,					SFX_TITLE_FULLNAME }
187cdf0e10cSrcweir };
188cdf0e10cSrcweir 
189cdf0e10cSrcweir //=========================================================================
190cdf0e10cSrcweir 
191cdf0e10cSrcweir void SfxObjectShell::AbortImport()
192cdf0e10cSrcweir {
193cdf0e10cSrcweir 	pImp->bIsAbortingImport = sal_True;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //-------------------------------------------------------------------------
197cdf0e10cSrcweir 
198cdf0e10cSrcweir sal_Bool SfxObjectShell::IsAbortingImport() const
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	return pImp->bIsAbortingImport;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir //-------------------------------------------------------------------------
204cdf0e10cSrcweir 
205cdf0e10cSrcweir uno::Reference<document::XDocumentProperties>
206cdf0e10cSrcweir SfxObjectShell::getDocProperties()
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
209cdf0e10cSrcweir         GetModel(), uno::UNO_QUERY_THROW);
210cdf0e10cSrcweir     uno::Reference<document::XDocumentProperties> xDocProps(
211cdf0e10cSrcweir         xDPS->getDocumentProperties());
212cdf0e10cSrcweir     DBG_ASSERT(xDocProps.is(),
213cdf0e10cSrcweir         "SfxObjectShell: model has no DocumentProperties");
214cdf0e10cSrcweir     return xDocProps;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir //-------------------------------------------------------------------------
218cdf0e10cSrcweir 
219cdf0e10cSrcweir void SfxObjectShell::DoFlushDocInfo()
220cdf0e10cSrcweir {
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir //-------------------------------------------------------------------------
224cdf0e10cSrcweir 
225cdf0e10cSrcweir // Note: the only thing that calls this is the modification event handler
226cdf0e10cSrcweir // that is installed at the XDocumentProperties
227cdf0e10cSrcweir void SfxObjectShell::FlushDocInfo()
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     if ( IsLoading() )
230cdf0e10cSrcweir         return;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	SetModified(sal_True);
233cdf0e10cSrcweir     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
234cdf0e10cSrcweir     DoFlushDocInfo(); // call template method
235cdf0e10cSrcweir     ::rtl::OUString url(xDocProps->getAutoloadURL());
236cdf0e10cSrcweir     sal_Int32 delay(xDocProps->getAutoloadSecs());
237cdf0e10cSrcweir     SetAutoLoad( INetURLObject(url), delay * 1000,
238cdf0e10cSrcweir                  (delay > 0) || url.getLength() );
239cdf0e10cSrcweir /*
240cdf0e10cSrcweir 	// bitte beachten:
241cdf0e10cSrcweir 	// 1. Titel in DocInfo aber nicht am Doc (nach HTML-Import)
242cdf0e10cSrcweir 	// 	=> auch am Doc setzen
243cdf0e10cSrcweir 	// 2. Titel in DocInfo leer (Briefumschlagsdruck)
244cdf0e10cSrcweir 	//	=> nicht am Doc setzen, da sonst "unbenanntX" daraus wird
245cdf0e10cSrcweir 	String aDocInfoTitle = GetDocInfo().GetTitle();
246cdf0e10cSrcweir 	if ( aDocInfoTitle.Len() )
247cdf0e10cSrcweir 		SetTitle( aDocInfoTitle );
248cdf0e10cSrcweir 	else
249cdf0e10cSrcweir 	{
250cdf0e10cSrcweir 		pImp->aTitle.Erase();
251cdf0e10cSrcweir 		SetNamedVisibility_Impl();
252cdf0e10cSrcweir     	if ( GetMedium() )
253cdf0e10cSrcweir     	{
254cdf0e10cSrcweir         	SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
255cdf0e10cSrcweir         	Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
256cdf0e10cSrcweir     	}
257cdf0e10cSrcweir     }*/
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir //-------------------------------------------------------------------------
261cdf0e10cSrcweir 
262cdf0e10cSrcweir void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir 	if(pImp->lErr==ERRCODE_NONE)
265cdf0e10cSrcweir     {
266cdf0e10cSrcweir 		pImp->lErr=lErr;
267cdf0e10cSrcweir 
268cdf0e10cSrcweir         if( lErr != ERRCODE_NONE && aLogMessage.getLength() )
269cdf0e10cSrcweir             AddLog( aLogMessage );
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir //-------------------------------------------------------------------------
274cdf0e10cSrcweir 
275cdf0e10cSrcweir sal_uInt32 SfxObjectShell::GetError() const
276cdf0e10cSrcweir {
277cdf0e10cSrcweir 	return ERRCODE_TOERROR(GetErrorCode());
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir //-------------------------------------------------------------------------
281cdf0e10cSrcweir 
282cdf0e10cSrcweir sal_uInt32 SfxObjectShell::GetErrorCode() const
283cdf0e10cSrcweir {
284cdf0e10cSrcweir 	sal_uInt32 lError=pImp->lErr;
285cdf0e10cSrcweir 	if(!lError && GetMedium())
286cdf0e10cSrcweir 		lError=GetMedium()->GetErrorCode();
287cdf0e10cSrcweir 	return lError;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir //-------------------------------------------------------------------------
291cdf0e10cSrcweir 
292cdf0e10cSrcweir void SfxObjectShell::ResetError()
293cdf0e10cSrcweir {
294cdf0e10cSrcweir     if( pImp->lErr != ERRCODE_NONE )
295cdf0e10cSrcweir         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Resetting Error." ) ) );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	pImp->lErr=0;
298cdf0e10cSrcweir 	SfxMedium * pMed = GetMedium();
299cdf0e10cSrcweir 	if( pMed )
300cdf0e10cSrcweir 		pMed->ResetError();
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir //-------------------------------------------------------------------------
304cdf0e10cSrcweir 
305cdf0e10cSrcweir sal_Bool SfxObjectShell::IsTemplate() const
306cdf0e10cSrcweir {
307cdf0e10cSrcweir 	return pImp->bIsTemplate;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir //-------------------------------------------------------------------------
311cdf0e10cSrcweir 
312cdf0e10cSrcweir void SfxObjectShell::SetTemplate(sal_Bool bIs)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir 	pImp->bIsTemplate=bIs;
315cdf0e10cSrcweir 	SfxFilterMatcher aMatcher( GetFactory().GetFactoryName() );
316cdf0e10cSrcweir 	SfxFilterMatcherIter aIter( &aMatcher, SFX_FILTER_TEMPLATEPATH );
317cdf0e10cSrcweir 	SfxMedium* pMed = GetMedium();
318cdf0e10cSrcweir 	if( pMed ) pMed->SetFilter( aIter.First() );
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir //-------------------------------------------------------------------------
322cdf0e10cSrcweir 
323cdf0e10cSrcweir void SfxObjectShell::EnableSetModified( sal_Bool bEnable )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir #ifdef DBG_UTIL
326*8699c4ffSmseidel 	if ( bEnable == pImp->m_bEnableSetModified )
327*8699c4ffSmseidel 		DBG_WARNING( "SFX_PERSIST: EnableSetModified called twice with the same value" );
328cdf0e10cSrcweir #endif
329cdf0e10cSrcweir 	pImp->m_bEnableSetModified = bEnable;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir //-------------------------------------------------------------------------
333cdf0e10cSrcweir 
334cdf0e10cSrcweir sal_Bool SfxObjectShell::IsEnableSetModified() const
335cdf0e10cSrcweir {
336cdf0e10cSrcweir     return pImp->m_bEnableSetModified && !IsReadOnly();
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir //-------------------------------------------------------------------------
340cdf0e10cSrcweir 
341cdf0e10cSrcweir sal_Bool SfxObjectShell::IsModified()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     if ( pImp->m_bIsModified )
344cdf0e10cSrcweir         return sal_True;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     if ( !pImp->m_xDocStorage.is() || IsReadOnly() )
347cdf0e10cSrcweir     {
348cdf0e10cSrcweir         // if the document still has no storage and is not set to be modified explicitly it is not modified
349cdf0e10cSrcweir         // a readonly document is also not modified
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         return sal_False;
352cdf0e10cSrcweir     }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
355cdf0e10cSrcweir     for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
356cdf0e10cSrcweir     {
357cdf0e10cSrcweir         uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
358cdf0e10cSrcweir         OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
359cdf0e10cSrcweir         if ( xObj.is() )
360cdf0e10cSrcweir         {
361cdf0e10cSrcweir             try
362cdf0e10cSrcweir             {
363cdf0e10cSrcweir                 sal_Int32 nState = xObj->getCurrentState();
364cdf0e10cSrcweir                 if ( nState != embed::EmbedStates::LOADED )
365cdf0e10cSrcweir                 {
366cdf0e10cSrcweir                     uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
367cdf0e10cSrcweir                     if ( xModifiable.is() && xModifiable->isModified() )
368cdf0e10cSrcweir                         return sal_True;
369cdf0e10cSrcweir                 }
370cdf0e10cSrcweir             }
371cdf0e10cSrcweir             catch( uno::Exception& )
372cdf0e10cSrcweir             {}
373cdf0e10cSrcweir         }
374cdf0e10cSrcweir     }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     return sal_False;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir //-------------------------------------------------------------------------
380cdf0e10cSrcweir 
381cdf0e10cSrcweir void SfxObjectShell::SetModified( sal_Bool bModifiedP )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir #ifdef DBG_UTIL
384*8699c4ffSmseidel 	if ( !bModifiedP && !IsEnableSetModified() )
385*8699c4ffSmseidel 		DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), although IsEnableSetModified() == sal_False" );
386cdf0e10cSrcweir #endif
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 	if( !IsEnableSetModified() )
389cdf0e10cSrcweir 		return;
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	if( pImp->m_bIsModified != bModifiedP )
392cdf0e10cSrcweir 	{
393cdf0e10cSrcweir 		pImp->m_bIsModified = bModifiedP;
394cdf0e10cSrcweir 		ModifyChanged();
395cdf0e10cSrcweir 	}
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir //-------------------------------------------------------------------------
399cdf0e10cSrcweir 
400cdf0e10cSrcweir void SfxObjectShell::ModifyChanged()
401cdf0e10cSrcweir {
402cdf0e10cSrcweir 	if ( pImp->bClosing )
403cdf0e10cSrcweir 		// SetModified aus dem dispose des Models!
404cdf0e10cSrcweir 		return;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 	{DBG_CHKTHIS(SfxObjectShell, 0);}
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
409cdf0e10cSrcweir     if ( pViewFrame )
410cdf0e10cSrcweir         pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS );
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     Invalidate( SID_SIGNATURE );
413cdf0e10cSrcweir     Invalidate( SID_MACRO_SIGNATURE );
414cdf0e10cSrcweir 	Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );	// xmlsec05, signed state might change in title...
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) );
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir //-------------------------------------------------------------------------
420cdf0e10cSrcweir 
421cdf0e10cSrcweir sal_Bool SfxObjectShell::IsReadOnlyUI() const
422cdf0e10cSrcweir 
423cdf0e10cSrcweir /* 	[Beschreibung]
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 	Liefert sal_True, wenn das Dokument fuer die UI wie r/o behandelt werden
426cdf0e10cSrcweir 	soll. Dieses ist unabhaengig vom tatsaechlichen r/o, welches per
427cdf0e10cSrcweir 	<IsReadOnly()> erfragbar ist.
428cdf0e10cSrcweir */
429cdf0e10cSrcweir 
430cdf0e10cSrcweir {
431cdf0e10cSrcweir 	return pImp->bReadOnlyUI;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir //-------------------------------------------------------------------------
435cdf0e10cSrcweir 
436cdf0e10cSrcweir sal_Bool SfxObjectShell::IsReadOnlyMedium() const
437cdf0e10cSrcweir 
438cdf0e10cSrcweir /* 	[Beschreibung]
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 	Liefert sal_True, wenn das Medium r/o ist bzw. r/o geoeffnet wurde.
441cdf0e10cSrcweir */
442cdf0e10cSrcweir 
443cdf0e10cSrcweir {
444cdf0e10cSrcweir 	if ( !pMedium )
445cdf0e10cSrcweir 		return sal_True;
446cdf0e10cSrcweir 	return pMedium->IsReadOnly();
447cdf0e10cSrcweir }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir //-------------------------------------------------------------------------
450cdf0e10cSrcweir 
451cdf0e10cSrcweir void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly )
452cdf0e10cSrcweir 
453cdf0e10cSrcweir /* 	[Beschreibung]
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 	Schaltet das Dokument in einen r/o bzw. r/w Zustand ohne es neu
456cdf0e10cSrcweir 	zu laden und ohne die Open-Modi des Mediums zu aendern.
457cdf0e10cSrcweir */
458cdf0e10cSrcweir 
459cdf0e10cSrcweir {
460cdf0e10cSrcweir 	sal_Bool bWasRO = IsReadOnly();
461cdf0e10cSrcweir 	pImp->bReadOnlyUI = bReadOnly;
462cdf0e10cSrcweir 	if ( bWasRO != IsReadOnly() )
463cdf0e10cSrcweir 	{
464cdf0e10cSrcweir 		Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
465cdf0e10cSrcweir 		//if ( pImp->pDocInfo )
466cdf0e10cSrcweir 		//	pImp->pDocInfo->SetReadOnly( IsReadOnly() );
467cdf0e10cSrcweir 	}
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir //-------------------------------------------------------------------------
471cdf0e10cSrcweir 
472cdf0e10cSrcweir void SfxObjectShell::SetReadOnly()
473cdf0e10cSrcweir {
474*8699c4ffSmseidel 	// Let the document be completely readonly, means that the
475*8699c4ffSmseidel 	// medium open mode is adjusted accordingly, and the write lock
476*8699c4ffSmseidel 	// on the file is removed.
477cdf0e10cSrcweir 
478cdf0e10cSrcweir  	if ( pMedium && !IsReadOnlyMedium() )
479cdf0e10cSrcweir     {
480cdf0e10cSrcweir         sal_Bool bWasROUI = IsReadOnly();
481cdf0e10cSrcweir 
482*8699c4ffSmseidel 		pMedium->UnlockFile( sal_False );
483*8699c4ffSmseidel 
484cdf0e10cSrcweir         // the storage-based mediums are already based on the temporary file
485cdf0e10cSrcweir         // so UnlockFile has already closed the locking stream
486cdf0e10cSrcweir         if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() )
487cdf0e10cSrcweir             pMedium->CloseInStream();
488cdf0e10cSrcweir 
489*8699c4ffSmseidel         pMedium->SetOpenMode( SFX_STREAM_READONLY, pMedium->IsDirect(), sal_True );
490cdf0e10cSrcweir         pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
491cdf0e10cSrcweir 
492cdf0e10cSrcweir         if ( !bWasROUI )
493cdf0e10cSrcweir             Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
494cdf0e10cSrcweir     }
495cdf0e10cSrcweir }
496cdf0e10cSrcweir //-------------------------------------------------------------------------
497cdf0e10cSrcweir 
498cdf0e10cSrcweir sal_Bool SfxObjectShell::IsReadOnly() const
499cdf0e10cSrcweir {
500cdf0e10cSrcweir 	return pImp->bReadOnlyUI || IsReadOnlyMedium();
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir //-------------------------------------------------------------------------
504cdf0e10cSrcweir 
505cdf0e10cSrcweir sal_Bool SfxObjectShell::IsInModalMode() const
506cdf0e10cSrcweir {
507cdf0e10cSrcweir     return pImp->bModalMode || pImp->bRunningMacro;
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir //<!--Added by PengYunQuan for Validity Cell Range Picker
511cdf0e10cSrcweir sal_Bool SfxObjectShell::AcceptStateUpdate() const
512cdf0e10cSrcweir {
513cdf0e10cSrcweir 	return !IsInModalMode();
514cdf0e10cSrcweir }
515cdf0e10cSrcweir //-->Added by PengYunQuan for Validity Cell Range Picker
516cdf0e10cSrcweir 
517cdf0e10cSrcweir //-------------------------------------------------------------------------
518cdf0e10cSrcweir 
519cdf0e10cSrcweir sal_Bool SfxObjectShell::HasModalViews() const
520cdf0e10cSrcweir {
521cdf0e10cSrcweir 	SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
522cdf0e10cSrcweir 	while( pFrame )
523cdf0e10cSrcweir 	{
524cdf0e10cSrcweir 		if ( pFrame->IsInModalMode() )
525cdf0e10cSrcweir 			return sal_True;
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 		pFrame = SfxViewFrame::GetNext( *pFrame, this );
528cdf0e10cSrcweir 	}
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 	return sal_False;
531cdf0e10cSrcweir }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir //-------------------------------------------------------------------------
534cdf0e10cSrcweir 
535cdf0e10cSrcweir void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     if ( !pImp->bRunningMacro != !bModal )
538cdf0e10cSrcweir 	{
539cdf0e10cSrcweir         pImp->bRunningMacro = bModal;
540cdf0e10cSrcweir 		Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
541cdf0e10cSrcweir 	}
542cdf0e10cSrcweir }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir //-------------------------------------------------------------------------
545cdf0e10cSrcweir 
546cdf0e10cSrcweir void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal )
547cdf0e10cSrcweir {
548cdf0e10cSrcweir 	// nur Broadcasten wenn modifiziert, sonst ggf. Endlosrekursion
549cdf0e10cSrcweir 	if ( !pImp->bModalMode != !bModal )
550cdf0e10cSrcweir 	{
551cdf0e10cSrcweir 		// zentral mitz"ahlen
552cdf0e10cSrcweir 		sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode;
553cdf0e10cSrcweir 		if ( bModal )
554cdf0e10cSrcweir 			++rDocModalCount;
555cdf0e10cSrcweir 		else
556cdf0e10cSrcweir 			--rDocModalCount;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 		// umschalten
559cdf0e10cSrcweir 		pImp->bModalMode = bModal;
560cdf0e10cSrcweir 		Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
561cdf0e10cSrcweir 	}
562cdf0e10cSrcweir }
563cdf0e10cSrcweir 
564cdf0e10cSrcweir //--------------------------------------------------------------------
565cdf0e10cSrcweir sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave )
566cdf0e10cSrcweir {
567cdf0e10cSrcweir     sal_Bool bResult = sal_True;
568cdf0e10cSrcweir 
569cdf0e10cSrcweir     if ( bShared != IsDocShared() )
570cdf0e10cSrcweir     {
571cdf0e10cSrcweir         ::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
572cdf0e10cSrcweir 
573cdf0e10cSrcweir         if ( !aOrigURL.getLength() && bSave )
574cdf0e10cSrcweir         {
575cdf0e10cSrcweir             // this is a new document, let it be stored before switching to the shared mode;
576cdf0e10cSrcweir             // the storing should be done without shared flag, since it is possible that the
577cdf0e10cSrcweir             // target location does not allow to create sharing control file;
578cdf0e10cSrcweir             // the shared flag will be set later after creation of sharing control file
579cdf0e10cSrcweir             SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
580cdf0e10cSrcweir 
581cdf0e10cSrcweir             if ( pViewFrame )
582cdf0e10cSrcweir             {
583cdf0e10cSrcweir                 // TODO/LATER: currently the application guards against the reentrance problem
584cdf0e10cSrcweir 				const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
585cdf0e10cSrcweir                 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
586cdf0e10cSrcweir                 bResult = ( pResult && pResult->GetValue() );
587cdf0e10cSrcweir                 if ( bResult )
588cdf0e10cSrcweir                     aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
589cdf0e10cSrcweir             }
590cdf0e10cSrcweir         }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir         sal_Bool bOldValue = HasSharedXMLFlagSet();
593cdf0e10cSrcweir         SetSharedXMLFlag( bShared );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir         sal_Bool bRemoveEntryOnError = sal_False;
596cdf0e10cSrcweir         if ( bResult && bShared )
597cdf0e10cSrcweir         {
598cdf0e10cSrcweir             try
599cdf0e10cSrcweir             {
600cdf0e10cSrcweir                 ::svt::ShareControlFile aControlFile( aOrigURL );
601cdf0e10cSrcweir                 aControlFile.InsertOwnEntry();
602cdf0e10cSrcweir                 bRemoveEntryOnError = sal_True;
603cdf0e10cSrcweir             }
604cdf0e10cSrcweir             catch( uno::Exception& )
605cdf0e10cSrcweir             {
606cdf0e10cSrcweir                 bResult = sal_False;
607cdf0e10cSrcweir             }
608cdf0e10cSrcweir         }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir         if ( bResult && bSave )
611cdf0e10cSrcweir         {
612cdf0e10cSrcweir             SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir             if ( pViewFrame )
615cdf0e10cSrcweir             {
616cdf0e10cSrcweir                 // TODO/LATER: currently the application guards against the reentrance problem
617cdf0e10cSrcweir                 SetModified( sal_True ); // the modified flag has to be set to let the document be stored with the shared flag
618cdf0e10cSrcweir 				const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
619cdf0e10cSrcweir                 SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
620cdf0e10cSrcweir                 bResult = ( pResult && pResult->GetValue() );
621cdf0e10cSrcweir             }
622cdf0e10cSrcweir         }
623cdf0e10cSrcweir 
624cdf0e10cSrcweir         if ( bResult )
625cdf0e10cSrcweir         {
626cdf0e10cSrcweir             // TODO/LATER: Is it possible that the following calls fail?
627cdf0e10cSrcweir             if ( bShared )
628cdf0e10cSrcweir             {
629cdf0e10cSrcweir                 pImp->m_aSharedFileURL = aOrigURL;
630cdf0e10cSrcweir                 GetMedium()->SwitchDocumentToTempFile();
631cdf0e10cSrcweir             }
632cdf0e10cSrcweir             else
633cdf0e10cSrcweir             {
634cdf0e10cSrcweir                 ::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
635cdf0e10cSrcweir                 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
636cdf0e10cSrcweir                 pImp->m_aSharedFileURL = ::rtl::OUString();
637cdf0e10cSrcweir 
638cdf0e10cSrcweir                 // now remove the temporary file the document was based on
639cdf0e10cSrcweir                 ::utl::UCBContentHelper::Kill( aTempFileURL );
640cdf0e10cSrcweir 
641cdf0e10cSrcweir                 try
642cdf0e10cSrcweir                 {
643cdf0e10cSrcweir                     // aOrigURL can not be used since it contains an old value
644cdf0e10cSrcweir                     ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
645cdf0e10cSrcweir                     aControlFile.RemoveFile();
646cdf0e10cSrcweir                 }
647cdf0e10cSrcweir                 catch( uno::Exception& )
648cdf0e10cSrcweir                 {
649cdf0e10cSrcweir                 }
650cdf0e10cSrcweir             }
651cdf0e10cSrcweir         }
652cdf0e10cSrcweir         else
653cdf0e10cSrcweir         {
654cdf0e10cSrcweir             // the saving has failed!
655cdf0e10cSrcweir             if ( bRemoveEntryOnError )
656cdf0e10cSrcweir             {
657cdf0e10cSrcweir                 try
658cdf0e10cSrcweir                 {
659cdf0e10cSrcweir                     ::svt::ShareControlFile aControlFile( aOrigURL );
660cdf0e10cSrcweir                     aControlFile.RemoveEntry();
661cdf0e10cSrcweir                 }
662cdf0e10cSrcweir                 catch( uno::Exception& )
663cdf0e10cSrcweir                 {}
664cdf0e10cSrcweir             }
665cdf0e10cSrcweir 
666cdf0e10cSrcweir             SetSharedXMLFlag( bOldValue );
667cdf0e10cSrcweir         }
668cdf0e10cSrcweir     }
669cdf0e10cSrcweir     else
670cdf0e10cSrcweir         bResult = sal_False; // the second switch to the same mode
671cdf0e10cSrcweir 
672cdf0e10cSrcweir     if ( bResult )
673cdf0e10cSrcweir         SetTitle( String() );
674cdf0e10cSrcweir 
675cdf0e10cSrcweir     return bResult;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir //--------------------------------------------------------------------
679cdf0e10cSrcweir 
680cdf0e10cSrcweir void SfxObjectShell::DisconnectFromShared()
681cdf0e10cSrcweir {
682cdf0e10cSrcweir     if ( IsDocShared() )
683cdf0e10cSrcweir     {
684cdf0e10cSrcweir         if ( pMedium && pMedium->GetStorage().is() )
685cdf0e10cSrcweir         {
686cdf0e10cSrcweir             // set medium to noname
687cdf0e10cSrcweir             pMedium->SetName( String(), sal_True );
688cdf0e10cSrcweir             pMedium->Init_Impl();
689cdf0e10cSrcweir 
690cdf0e10cSrcweir             // drop resource
691cdf0e10cSrcweir             SetNoName();
692cdf0e10cSrcweir             InvalidateName();
693cdf0e10cSrcweir 
694cdf0e10cSrcweir             // untitled document must be based on temporary storage
695cdf0e10cSrcweir             // the medium should not dispose the storage in this case
696cdf0e10cSrcweir             if ( pMedium->GetStorage() == GetStorage() )
697cdf0e10cSrcweir                 ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium );
698cdf0e10cSrcweir 
699cdf0e10cSrcweir             pMedium->Close();
700cdf0e10cSrcweir             FreeSharedFile();
701cdf0e10cSrcweir 
702cdf0e10cSrcweir             SfxMedium* pTmpMedium = pMedium;
703cdf0e10cSrcweir             ForgetMedium();
704cdf0e10cSrcweir             if( !DoSaveCompleted( pTmpMedium ) )
705cdf0e10cSrcweir                 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
706cdf0e10cSrcweir             else
707cdf0e10cSrcweir             {
708cdf0e10cSrcweir                 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
709cdf0e10cSrcweir                 pMedium->CanDisposeStorage_Impl( sal_False );
710cdf0e10cSrcweir             }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir             pMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
713cdf0e10cSrcweir             pMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
714cdf0e10cSrcweir 
715cdf0e10cSrcweir             SetTitle( String() );
716cdf0e10cSrcweir         }
717cdf0e10cSrcweir     }
718cdf0e10cSrcweir }
719cdf0e10cSrcweir 
720cdf0e10cSrcweir //--------------------------------------------------------------------
721cdf0e10cSrcweir 
722cdf0e10cSrcweir void SfxObjectShell::FreeSharedFile()
723cdf0e10cSrcweir {
724cdf0e10cSrcweir     if ( pMedium )
725cdf0e10cSrcweir         FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
726cdf0e10cSrcweir }
727cdf0e10cSrcweir 
728cdf0e10cSrcweir //--------------------------------------------------------------------
729cdf0e10cSrcweir void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL )
730cdf0e10cSrcweir {
731cdf0e10cSrcweir     SetSharedXMLFlag( sal_False );
732cdf0e10cSrcweir 
733cdf0e10cSrcweir     if ( IsDocShared() && aTempFileURL.getLength()
734cdf0e10cSrcweir       && !::utl::UCBContentHelper::EqualURLs( aTempFileURL, GetSharedFileURL() ) )
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         if ( pImp->m_bAllowShareControlFileClean )
737cdf0e10cSrcweir         {
738cdf0e10cSrcweir             try
739cdf0e10cSrcweir             {
740cdf0e10cSrcweir                 ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
741cdf0e10cSrcweir                 aControlFile.RemoveEntry();
742cdf0e10cSrcweir             }
743cdf0e10cSrcweir             catch( uno::Exception& )
744cdf0e10cSrcweir             {
745cdf0e10cSrcweir             }
746cdf0e10cSrcweir         }
747cdf0e10cSrcweir 
748cdf0e10cSrcweir         // the cleaning is forbidden only once
749cdf0e10cSrcweir         pImp->m_bAllowShareControlFileClean = sal_True;
750cdf0e10cSrcweir 
751cdf0e10cSrcweir         // now remove the temporary file the document is based currently on
752cdf0e10cSrcweir         ::utl::UCBContentHelper::Kill( aTempFileURL );
753cdf0e10cSrcweir 
754cdf0e10cSrcweir         pImp->m_aSharedFileURL = ::rtl::OUString();
755cdf0e10cSrcweir     }
756cdf0e10cSrcweir }
757cdf0e10cSrcweir 
758cdf0e10cSrcweir //--------------------------------------------------------------------
759cdf0e10cSrcweir void SfxObjectShell::DoNotCleanShareControlFile()
760cdf0e10cSrcweir {
761cdf0e10cSrcweir     pImp->m_bAllowShareControlFileClean = sal_False;
762cdf0e10cSrcweir }
763cdf0e10cSrcweir 
764cdf0e10cSrcweir //--------------------------------------------------------------------
765cdf0e10cSrcweir void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const
766cdf0e10cSrcweir {
767cdf0e10cSrcweir     pImp->m_bSharedXMLFlag = bFlag;
768cdf0e10cSrcweir }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir //--------------------------------------------------------------------
771cdf0e10cSrcweir sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const
772cdf0e10cSrcweir {
773cdf0e10cSrcweir     return pImp->m_bSharedXMLFlag;
774cdf0e10cSrcweir }
775cdf0e10cSrcweir 
776cdf0e10cSrcweir //--------------------------------------------------------------------
777cdf0e10cSrcweir 
778cdf0e10cSrcweir sal_Bool SfxObjectShell::IsDocShared() const
779cdf0e10cSrcweir {
780cdf0e10cSrcweir     return ( pImp->m_aSharedFileURL.getLength() > 0 );
781cdf0e10cSrcweir }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir //--------------------------------------------------------------------
784cdf0e10cSrcweir 
785cdf0e10cSrcweir ::rtl::OUString SfxObjectShell::GetSharedFileURL() const
786cdf0e10cSrcweir {
787cdf0e10cSrcweir     return pImp->m_aSharedFileURL;
788cdf0e10cSrcweir }
789cdf0e10cSrcweir 
790cdf0e10cSrcweir //--------------------------------------------------------------------
791cdf0e10cSrcweir 
792cdf0e10cSrcweir Size SfxObjectShell::GetFirstPageSize()
793cdf0e10cSrcweir {
794cdf0e10cSrcweir     return GetVisArea(ASPECT_THUMBNAIL).GetSize();
795cdf0e10cSrcweir }
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 
798cdf0e10cSrcweir //--------------------------------------------------------------------
799cdf0e10cSrcweir 
800cdf0e10cSrcweir IndexBitSet& SfxObjectShell::GetNoSet_Impl()
801cdf0e10cSrcweir {
802cdf0e10cSrcweir 	return pImp->aBitSet;
803cdf0e10cSrcweir }
804cdf0e10cSrcweir 
805cdf0e10cSrcweir //--------------------------------------------------------------------
806cdf0e10cSrcweir // changes the title of the document
807cdf0e10cSrcweir 
808cdf0e10cSrcweir void SfxObjectShell::SetTitle
809cdf0e10cSrcweir (
810cdf0e10cSrcweir 	const String& rTitle		// der neue Titel des Dokuments
811cdf0e10cSrcweir )
812cdf0e10cSrcweir 
813cdf0e10cSrcweir /*	[Beschreibung]
814cdf0e10cSrcweir 
815cdf0e10cSrcweir 	Mit dieser Methode kann der Titel des Dokuments gesetzt werden.
816cdf0e10cSrcweir 	Dieser entspricht initial dem kompletten Dateinamen. Ein Setzen
817*8699c4ffSmseidel 	des Titels wirkt jedoch nicht zurück auf den Dateinamen; er wird
818cdf0e10cSrcweir 	jedoch in den Caption-Bars der MDI-Fenster angezeigt.
819cdf0e10cSrcweir */
820cdf0e10cSrcweir 
821cdf0e10cSrcweir {
822cdf0e10cSrcweir 	DBG_CHKTHIS(SfxObjectShell, 0);
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 	// nix zu tun?
825cdf0e10cSrcweir 	if ( ( ( HasName() && pImp->aTitle == rTitle )
826cdf0e10cSrcweir 		|| ( !HasName() && GetTitle() == rTitle ) )
827cdf0e10cSrcweir 	  && !IsDocShared() )
828cdf0e10cSrcweir 		return;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 	SfxApplication *pSfxApp = SFX_APP();
831cdf0e10cSrcweir #if 0
832cdf0e10cSrcweir 	// wird 'unbenannt#' als Titel gesetzt
833cdf0e10cSrcweir 	String aNoName(SfxResId(STR_NONAME));
834cdf0e10cSrcweir 	if ( rTitle.Match(aNoName) <= aNoName.Len() )
835cdf0e10cSrcweir 	{
836cdf0e10cSrcweir 		// er ist es selbst => ignorieren
837cdf0e10cSrcweir 		pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
838cdf0e10cSrcweir 		pImp->bIsNamedVisible=0;
839cdf0e10cSrcweir 	}
840cdf0e10cSrcweir #endif
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 	// ggf. die unbenannt-Nummer freigeben
843cdf0e10cSrcweir 	if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber )
844cdf0e10cSrcweir 	{
845cdf0e10cSrcweir 		pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
846cdf0e10cSrcweir 		pImp->bIsNamedVisible = 0;
847cdf0e10cSrcweir 	}
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 	// Title setzen
850cdf0e10cSrcweir 	pImp->aTitle = rTitle;
851*8699c4ffSmseidel //	Wieso denn in der DocInfo?
852cdf0e10cSrcweir //	GetDocInfo().SetTitle( rTitle );
853cdf0e10cSrcweir //	FlushDocInfo();
854cdf0e10cSrcweir 
855cdf0e10cSrcweir 	// Benachrichtigungen
856cdf0e10cSrcweir     if ( GetMedium() )
857cdf0e10cSrcweir     {
858cdf0e10cSrcweir         SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
859cdf0e10cSrcweir         Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
860cdf0e10cSrcweir     }
861cdf0e10cSrcweir }
862cdf0e10cSrcweir 
863cdf0e10cSrcweir //--------------------------------------------------------------------
864cdf0e10cSrcweir 
865cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
866cdf0e10cSrcweir String X(const String &rRet)
867cdf0e10cSrcweir {
868cdf0e10cSrcweir 	if ( !rRet.Len() )
869cdf0e10cSrcweir 		return DEFINE_CONST_UNICODE( "-empty-" );
870cdf0e10cSrcweir 	return rRet;
871cdf0e10cSrcweir }
872cdf0e10cSrcweir #else
873cdf0e10cSrcweir #define X(ret) ret
874cdf0e10cSrcweir #endif
875cdf0e10cSrcweir 
876cdf0e10cSrcweir //--------------------------------------------------------------------
877cdf0e10cSrcweir //--------------------------------------------------------------------
878cdf0e10cSrcweir String SfxObjectShell::GetTitle
879cdf0e10cSrcweir (
880cdf0e10cSrcweir 	sal_uInt16	nMaxLength 		/*	0 (default)
881cdf0e10cSrcweir 								der Titel selbst, so wie er ist
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 								1 (==SFX_TITLE_FILENAME)
884cdf0e10cSrcweir 								liefert den logischen Dateinamen ohne Pfad
885cdf0e10cSrcweir 								(unter WNT je nach Systemeinstellung ohne
886cdf0e10cSrcweir 								Extension)
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 								2 (==SFX_TITLE_FULLNAME)
889cdf0e10cSrcweir 								liefert den mit komplettem logischen Dateinamen
890cdf0e10cSrcweir 								mit Pfad (remote => ::com::sun::star::util::URL)
891cdf0e10cSrcweir 
892cdf0e10cSrcweir 								3 (==SFX_TITLE_APINAME)
893cdf0e10cSrcweir 								liefert den logischen Dateinamen ohne Pfad
894cdf0e10cSrcweir 								und Extension
895cdf0e10cSrcweir 
896cdf0e10cSrcweir 								4 (==SFX_TITLE_DETECT)
897cdf0e10cSrcweir 								liefert den kompletten Titel, falls noch
898cdf0e10cSrcweir 								nicht gesetzt wird aber aus DocInfo oder
899cdf0e10cSrcweir 								dem Namen des Medium erzeugt
900cdf0e10cSrcweir 
901cdf0e10cSrcweir 								5 (==SFX_TITLE_CAPTION)
902cdf0e10cSrcweir 								liefert den Titel so, wie MB ihn heute in
903cdf0e10cSrcweir 								der CaptionBar anzeigen m"ochte
904cdf0e10cSrcweir 
905cdf0e10cSrcweir 								6 (==SFX_TITLE_PICKLIST)
906cdf0e10cSrcweir 								liefert den Titel so, wie MB ihn heute in
907cdf0e10cSrcweir 								der PickList anzeigen m"ochte
908cdf0e10cSrcweir 
909cdf0e10cSrcweir 								7 (==SFX_TITLE_HISTORY)
910cdf0e10cSrcweir 								liefert den Titel so, wie MB ihn heute in
911cdf0e10cSrcweir 								der History anzeigen m"ochte
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 								10 bis USHRT_MAX
914cdf0e10cSrcweir 								liefert maximal 'nMaxLength' Zeichen vom logischen
915cdf0e10cSrcweir 								Dateinamen inkl. Pfad (remote => ::com::sun::star::util::URL)
916cdf0e10cSrcweir 								*/
917cdf0e10cSrcweir ) const
918cdf0e10cSrcweir 
919cdf0e10cSrcweir /*	[Beschreibung]
920cdf0e10cSrcweir 
921cdf0e10cSrcweir 	Liefert den Titel bzw. logischen Dateinamen des Dokuments, je nach
922cdf0e10cSrcweir 	'nMaxLength'.
923cdf0e10cSrcweir 
924cdf0e10cSrcweir 	Falls der Dateiname mit Pfad verwendet wird, wird die Namensk"urzung durch
925cdf0e10cSrcweir 	Ersetzung eines oder mehrerer Directory-Namen durch "..." durchgef"uhrt,
926cdf0e10cSrcweir 	URLs werden z.Zt. immer komplett geliefert.
927cdf0e10cSrcweir */
928cdf0e10cSrcweir 
929cdf0e10cSrcweir {
930cdf0e10cSrcweir //    if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
931cdf0e10cSrcweir //        return String();
932cdf0e10cSrcweir     SfxMedium *pMed = GetMedium();
933cdf0e10cSrcweir     if ( IsLoading() )
934cdf0e10cSrcweir         return String();
935cdf0e10cSrcweir 
936cdf0e10cSrcweir /*    if ( !nMaxLength && pImp->pDocInfo )
937cdf0e10cSrcweir     {
938cdf0e10cSrcweir         String aTitle = pImp->pDocInfo->GetTitle();
939cdf0e10cSrcweir         if ( aTitle.Len() )
940cdf0e10cSrcweir             return aTitle;
941cdf0e10cSrcweir     } */
942cdf0e10cSrcweir 
943cdf0e10cSrcweir 	// Titel erzeugen?
944cdf0e10cSrcweir 	if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() )
945cdf0e10cSrcweir 	{
946cdf0e10cSrcweir 		static sal_Bool bRecur = sal_False;
947cdf0e10cSrcweir 		if ( bRecur )
948cdf0e10cSrcweir 			return DEFINE_CONST_UNICODE( "-not available-" );
949cdf0e10cSrcweir 		bRecur = sal_True;
950cdf0e10cSrcweir 
951cdf0e10cSrcweir 		String aTitle;
952cdf0e10cSrcweir 		SfxObjectShell *pThis = (SfxObjectShell*) this;
953cdf0e10cSrcweir 
954cdf0e10cSrcweir 		if ( pMed )
955cdf0e10cSrcweir 		{
956cdf0e10cSrcweir 			SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
957cdf0e10cSrcweir 			if ( pNameItem )
958cdf0e10cSrcweir 				aTitle = pNameItem->GetValue();
959cdf0e10cSrcweir 		}
960cdf0e10cSrcweir 
961cdf0e10cSrcweir 		if ( !aTitle.Len() )
962cdf0e10cSrcweir 			aTitle = GetTitle( SFX_TITLE_FILENAME );
963cdf0e10cSrcweir 
964cdf0e10cSrcweir 		if ( IsTemplate() )
965cdf0e10cSrcweir 			pThis->SetTitle( aTitle );
966cdf0e10cSrcweir 		bRecur = sal_False;
967cdf0e10cSrcweir 		return X(aTitle);
968cdf0e10cSrcweir 	}
969cdf0e10cSrcweir 	else if (SFX_TITLE_APINAME == nMaxLength )
970cdf0e10cSrcweir 		return X(GetAPIName());
971cdf0e10cSrcweir 
972cdf0e10cSrcweir 	// Sonderfall Vorlagen:
973cdf0e10cSrcweir 	if( IsTemplate() && pImp->aTitle.Len() &&
974cdf0e10cSrcweir 		 ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
975cdf0e10cSrcweir 		return X(pImp->aTitle);
976cdf0e10cSrcweir 
977cdf0e10cSrcweir 	// Picklist/Caption wird gemappt
978cdf0e10cSrcweir 	if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
979cdf0e10cSrcweir 	{
980*8699c4ffSmseidel 		// Wenn ein spezieller Titel beim Öffnen mitgegeben wurde;
981cdf0e10cSrcweir 		// wichtig bei URLs, die INET_PROT_FILE verwenden, denn bei denen
982cdf0e10cSrcweir 		// wird der gesetzte Titel nicht beachtet.
983cdf0e10cSrcweir 		// (s.u., Auswertung von aTitleMap_Impl)
984cdf0e10cSrcweir 		SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
985cdf0e10cSrcweir 		if ( pNameItem )
986cdf0e10cSrcweir 			return X( pNameItem->GetValue() );
987cdf0e10cSrcweir 	}
988cdf0e10cSrcweir 
989cdf0e10cSrcweir 	// noch unbenannt?
990*8699c4ffSmseidel 	DBG_ASSERT( !HasName() || pMed, "HasName() but no Medium?" );
991cdf0e10cSrcweir 	if ( !HasName() || !pMed )
992cdf0e10cSrcweir 	{
993*8699c4ffSmseidel 		// schon Titel gesetzt?
994cdf0e10cSrcweir 		if ( pImp->aTitle.Len() )
995cdf0e10cSrcweir 			return X(pImp->aTitle);
996cdf0e10cSrcweir 
997*8699c4ffSmseidel 		// muß es durchnumeriert werden?
998cdf0e10cSrcweir 		String aNoName( SfxResId( STR_NONAME ) );
999cdf0e10cSrcweir 		if ( pImp->bIsNamedVisible )
1000*8699c4ffSmseidel 			// Leerzeichen und Nummer hinten anhängen
1001*8699c4ffSmseidel 			aNoName += C2S(" ");
1002cdf0e10cSrcweir 			aNoName += String::CreateFromInt32( pImp->nVisualDocumentNumber );
1003cdf0e10cSrcweir 
1004*8699c4ffSmseidel 		// Dokument heißt vorerst 'Unbenannt #'
1005cdf0e10cSrcweir 		return X(aNoName);
1006cdf0e10cSrcweir 	}
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir 	const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
1009cdf0e10cSrcweir 	if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
1010cdf0e10cSrcweir 	{
1011cdf0e10cSrcweir 		sal_uInt16 nRemote;
1012cdf0e10cSrcweir 		if( !pMed || aURL.GetProtocol() == INET_PROT_FILE )
1013cdf0e10cSrcweir 			nRemote = 0;
1014cdf0e10cSrcweir 		else
1015cdf0e10cSrcweir 			nRemote = 1;
1016cdf0e10cSrcweir 		nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote];
1017cdf0e10cSrcweir 	}
1018cdf0e10cSrcweir 
1019*8699c4ffSmseidel 	// local file?
1020cdf0e10cSrcweir 	if ( aURL.GetProtocol() == INET_PROT_FILE )
1021cdf0e10cSrcweir 	{
1022cdf0e10cSrcweir         String aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() );
1023cdf0e10cSrcweir 		if ( nMaxLength == SFX_TITLE_FULLNAME )
1024cdf0e10cSrcweir 			return X( aName );
1025cdf0e10cSrcweir 		else if ( nMaxLength == SFX_TITLE_FILENAME )
1026cdf0e10cSrcweir             return X( aURL.getName( INetURLObject::LAST_SEGMENT,
1027cdf0e10cSrcweir 				true, INetURLObject::DECODE_WITH_CHARSET ) );
1028cdf0e10cSrcweir 		else if ( !pImp->aTitle.Len() )
1029cdf0e10cSrcweir             pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT,
1030cdf0e10cSrcweir 										 true, INetURLObject::DECODE_WITH_CHARSET );
1031cdf0e10cSrcweir 	}
1032cdf0e10cSrcweir 	else
1033cdf0e10cSrcweir 	{
1034cdf0e10cSrcweir 		// ::com::sun::star::util::URL-Versionen
1035cdf0e10cSrcweir 		if ( nMaxLength >= SFX_TITLE_MAXLEN )
1036cdf0e10cSrcweir 		{
1037cdf0e10cSrcweir             String aComplete( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1038cdf0e10cSrcweir 			if( aComplete.Len() > nMaxLength )
1039cdf0e10cSrcweir 			{
1040cdf0e10cSrcweir 				String aRet( DEFINE_CONST_UNICODE( "..." ) );
1041cdf0e10cSrcweir 				aRet += aComplete.Copy( aComplete.Len() - nMaxLength + 3, nMaxLength - 3 );
1042cdf0e10cSrcweir 				return X( aRet );
1043cdf0e10cSrcweir 			}
1044cdf0e10cSrcweir 			else
1045cdf0e10cSrcweir                 return X( aComplete );
1046cdf0e10cSrcweir 		}
1047cdf0e10cSrcweir 		else if ( nMaxLength == SFX_TITLE_FILENAME )
1048cdf0e10cSrcweir 		{
1049cdf0e10cSrcweir             String aName( aURL.GetBase() );
1050cdf0e10cSrcweir 			aName = INetURLObject::decode( aName, INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET );
1051cdf0e10cSrcweir 			if( !aName.Len() )
1052cdf0e10cSrcweir 				aName = aURL.GetURLNoPass();
1053cdf0e10cSrcweir 			return X(aName);
1054cdf0e10cSrcweir 		}
1055cdf0e10cSrcweir 		else if ( nMaxLength == SFX_TITLE_FULLNAME )
1056cdf0e10cSrcweir 			return X(aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ));
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir 		// ggf. Titel aus Dateiname generieren
1059cdf0e10cSrcweir 		if ( !pImp->aTitle.Len() )
1060cdf0e10cSrcweir 			pImp->aTitle = aURL.GetBase();
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir 		// workaround for the case when the name can not be retrieved from URL by INetURLObject
1063cdf0e10cSrcweir 		if ( !pImp->aTitle.Len() )
1064cdf0e10cSrcweir 			pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
1065cdf0e10cSrcweir 	}
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir 	// ganzer Titel
1068cdf0e10cSrcweir 	return X(pImp->aTitle);
1069cdf0e10cSrcweir }
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir //--------------------------------------------------------------------
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir void SfxObjectShell::InvalidateName()
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir /*	[Beschreibung]
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir 	Ermittelt den Titel des Dokuments neu aus 'unbenannt', DocInfo-Titel
1078*8699c4ffSmseidel 	bzw. Dateinamen. Wird nach Laden aus Template oder SaveAs benötigt.
1079cdf0e10cSrcweir */
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir 	// Title neu erzeugen
1083cdf0e10cSrcweir 	pImp->aTitle.Erase();
1084cdf0e10cSrcweir //	pImp->nVisualDocumentNumber = USHRT_MAX;
1085cdf0e10cSrcweir 	//GetTitle( SFX_TITLE_DETECT );
1086cdf0e10cSrcweir 	SetName( GetTitle( SFX_TITLE_APINAME ) );
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 	// Benachrichtigungen
1089cdf0e10cSrcweir 	Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1090cdf0e10cSrcweir }
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir //--------------------------------------------------------------------
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir void SfxObjectShell::SetNamedVisibility_Impl()
1095cdf0e10cSrcweir {
1096cdf0e10cSrcweir 	if ( !pImp->bIsNamedVisible )
1097cdf0e10cSrcweir 	{
1098cdf0e10cSrcweir 		// Nummer verpassen
1099cdf0e10cSrcweir 		pImp->bIsNamedVisible = sal_True;
1100cdf0e10cSrcweir 		// ggf. neue Nummer verpassen
1101cdf0e10cSrcweir 		if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && !pImp->aTitle.Len() )
1102cdf0e10cSrcweir 		{
1103cdf0e10cSrcweir 			pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex();
1104cdf0e10cSrcweir 			Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1105cdf0e10cSrcweir 		}
1106cdf0e10cSrcweir 	}
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir 	SetName( GetTitle(SFX_TITLE_APINAME) );
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir void SfxObjectShell::SetNoName()
1112cdf0e10cSrcweir {
1113cdf0e10cSrcweir     bHasName = 0;
1114cdf0e10cSrcweir     bIsTmp = sal_True;
1115cdf0e10cSrcweir     GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() );
1116cdf0e10cSrcweir }
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir //--------------------------------------------------------------------
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir void SfxObjectShell::MemoryError()
1121cdf0e10cSrcweir {
1122cdf0e10cSrcweir }
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir //--------------------------------------------------------------------
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir SfxProgress* SfxObjectShell::GetProgress() const
1127cdf0e10cSrcweir {
1128cdf0e10cSrcweir 	return pImp->pProgress;
1129cdf0e10cSrcweir }
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir //--------------------------------------------------------------------
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir void SfxObjectShell::SetProgress_Impl
1134cdf0e10cSrcweir (
1135cdf0e10cSrcweir 	SfxProgress *pProgress	/*	zu startender <SfxProgress> oder 0, falls
1136cdf0e10cSrcweir 								der Progress zur"uckgesetzt werden soll */
1137cdf0e10cSrcweir )
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir /*	[Beschreibung]
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir 	Interne Methode zum setzen oder zur"ucksetzen des Progress-Modes
1142cdf0e10cSrcweir 	f"ur diese SfxObjectShell.
1143cdf0e10cSrcweir */
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir {
1146cdf0e10cSrcweir 	DBG_ASSERT( ( !pImp->pProgress && pProgress ) ||
1147cdf0e10cSrcweir 				( pImp->pProgress && !pProgress ),
1148cdf0e10cSrcweir 				"Progress activation/deacitivation mismatch" );
1149cdf0e10cSrcweir 	pImp->pProgress = pProgress;
1150cdf0e10cSrcweir }
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir //--------------------------------------------------------------------
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
1155cdf0e10cSrcweir {
1156cdf0e10cSrcweir 	SfxApplication* pSfxApp = SFX_APP();
1157cdf0e10cSrcweir     if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame().IsClosing_Impl() )
1158cdf0e10cSrcweir 	{
1159cdf0e10cSrcweir         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
1160cdf0e10cSrcweir         if ( !pHiddenItem || !pHiddenItem->GetValue() )
1161cdf0e10cSrcweir         {
1162cdf0e10cSrcweir             sal_uInt16 nId = pImp->nEventId;
1163cdf0e10cSrcweir             pImp->nEventId = 0;
1164cdf0e10cSrcweir             if ( nId == SFX_EVENT_OPENDOC )
1165cdf0e10cSrcweir                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC), this, pFrame->GetFrame().GetController() ), sal_False);
1166cdf0e10cSrcweir 			else if (nId == SFX_EVENT_CREATEDOC )
1167cdf0e10cSrcweir                 pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC), this, pFrame->GetFrame().GetController() ), sal_False);
1168cdf0e10cSrcweir         }
1169cdf0e10cSrcweir 	}
1170cdf0e10cSrcweir }
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir //--------------------------------------------------------------------
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId )
1175cdf0e10cSrcweir {
1176cdf0e10cSrcweir 	if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC )
1177cdf0e10cSrcweir 		pImp->nEventId = nId;
1178cdf0e10cSrcweir }
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir //--------------------------------------------------------------------
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir void SfxObjectShell::RegisterTransfer( SfxMedium& rMedium )
1183cdf0e10cSrcweir /*  [Beschreibung ]
1184cdf0e10cSrcweir 	Alle Medien, die aufgesetzt werden, um Teile eines Dokumentes zu
1185cdf0e10cSrcweir 	laden, muessen an der zugehoerigen SfxObjectShell angemeldet
1186cdf0e10cSrcweir 	werden. So kann dokumentweise abgebrochen werden.  */
1187cdf0e10cSrcweir {
1188cdf0e10cSrcweir 	rMedium.SetReferer( GetMedium()->GetName() );
1189cdf0e10cSrcweir }
1190cdf0e10cSrcweir 
1191cdf0e10cSrcweir //-------------------------------------------------------------------------
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir void SfxObjectShell::PrepareReload( )
1194cdf0e10cSrcweir /*  [Beschreibung ]
1195cdf0e10cSrcweir 	Wird vor dem Reload gerufen und gibt die Moeglichkeit,
1196cdf0e10cSrcweir 	etwaige Caches zu leeren. */
1197cdf0e10cSrcweir {
1198cdf0e10cSrcweir }
1199cdf0e10cSrcweir 
1200cdf0e10cSrcweir //-------------------------------------------------------------------------
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir void SfxObjectShell::LockAutoLoad( sal_Bool bLock )
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir /* 	Verhindert ein evtl. eintreffendes AutoLoad. Wird auch vor AutoLoad
1205cdf0e10cSrcweir 	eines umgebenden FrameSet beruecksichtigt.
1206cdf0e10cSrcweir */
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir {
1209cdf0e10cSrcweir 	if ( bLock )
1210cdf0e10cSrcweir 		++pImp->nAutoLoadLocks;
1211cdf0e10cSrcweir 	else
1212cdf0e10cSrcweir 		--pImp->nAutoLoadLocks;
1213cdf0e10cSrcweir }
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir //-------------------------------------------------------------------------
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir // kann nach frame.cxx gemoved werden, wenn 358+36x-Stand gemerged sind
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir sal_Bool SfxFrame::IsAutoLoadLocked_Impl() const
1220cdf0e10cSrcweir {
1221cdf0e10cSrcweir 	// sein einges Doc gelockt?
1222cdf0e10cSrcweir 	const SfxObjectShell* pObjSh = GetCurrentDocument();
1223cdf0e10cSrcweir 	if ( !pObjSh || !pObjSh->IsAutoLoadLocked() )
1224cdf0e10cSrcweir 		return sal_False;
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir 	// seine Childs gelockt?
1227cdf0e10cSrcweir 	for ( sal_uInt16 n = GetChildFrameCount(); n--; )
1228cdf0e10cSrcweir 		if ( !GetChildFrame(n)->IsAutoLoadLocked_Impl() )
1229cdf0e10cSrcweir 			return sal_False;
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir 	// sonst ist AutoLoad erlaubt
1232cdf0e10cSrcweir 	return sal_True;
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir //-------------------------------------------------------------------------
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir sal_Bool SfxObjectShell::IsAutoLoadLocked() const
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir /* 	Liefert, ob ein eintreffendes AutoLoad ausgefuehrt werden darf. Wird auch
1240cdf0e10cSrcweir 	vor AutoLoad eines umgebenden FrameSet beruecksichtigt.
1241cdf0e10cSrcweir */
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir 	return !IsReadOnly() || pImp->nAutoLoadLocks > 0;
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir //-------------------------------------------------------------------------
1248cdf0e10cSrcweir void SfxObjectShell::BreakMacroSign_Impl( sal_Bool bBreakMacroSign )
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir 	pImp->m_bMacroSignBroken = bBreakMacroSign;
1251cdf0e10cSrcweir }
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir //-------------------------------------------------------------------------
1254cdf0e10cSrcweir void SfxObjectShell::CheckSecurityOnLoading_Impl()
1255cdf0e10cSrcweir {
1256cdf0e10cSrcweir     uno::Reference< task::XInteractionHandler > xInteraction;
1257cdf0e10cSrcweir     if ( GetMedium() )
1258cdf0e10cSrcweir         xInteraction = GetMedium()->GetInteractionHandler();
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir 	// check if there is a broken signature...
1261cdf0e10cSrcweir     CheckForBrokenDocSignatures_Impl( xInteraction );
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir     CheckEncryption_Impl( xInteraction );
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir     // check macro security
1266cdf0e10cSrcweir     pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
1267cdf0e10cSrcweir }
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir //-------------------------------------------------------------------------
1270cdf0e10cSrcweir void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
1271cdf0e10cSrcweir {
1272cdf0e10cSrcweir     ::rtl::OUString aVersion;
1273cdf0e10cSrcweir     sal_Bool bIsEncrypted = sal_False;
1274cdf0e10cSrcweir     sal_Bool bHasNonEncrypted = sal_False;
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir     try
1277cdf0e10cSrcweir     {
1278cdf0e10cSrcweir         uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
1279cdf0e10cSrcweir         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion;
1280cdf0e10cSrcweir         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasEncryptedEntries" ) ) ) >>= bIsEncrypted;
1281cdf0e10cSrcweir         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasNonEncryptedEntries" ) ) ) >>= bHasNonEncrypted;
1282cdf0e10cSrcweir     }
1283cdf0e10cSrcweir     catch( uno::Exception& )
1284cdf0e10cSrcweir     {
1285cdf0e10cSrcweir     }
1286cdf0e10cSrcweir 
1287cdf0e10cSrcweir     if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
1288cdf0e10cSrcweir     {
1289cdf0e10cSrcweir         // this is ODF1.2 or later
1290cdf0e10cSrcweir         if ( bIsEncrypted && bHasNonEncrypted )
1291cdf0e10cSrcweir         {
1292cdf0e10cSrcweir             if ( !pImp->m_bIncomplEncrWarnShown )
1293cdf0e10cSrcweir             {
1294cdf0e10cSrcweir                 // this is an encrypted document with nonencrypted streams inside, show the warning
1295cdf0e10cSrcweir                 ::com::sun::star::task::ErrorCodeRequest aErrorCode;
1296cdf0e10cSrcweir                 aErrorCode.ErrCode = ERRCODE_SFX_INCOMPLETE_ENCRYPTION;
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir                 SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
1299cdf0e10cSrcweir                 pImp->m_bIncomplEncrWarnShown = sal_True;
1300cdf0e10cSrcweir             }
1301cdf0e10cSrcweir 
1302cdf0e10cSrcweir             // broken signatures imply no macro execution at all
1303cdf0e10cSrcweir             pImp->aMacroMode.disallowMacroExecution();
1304cdf0e10cSrcweir         }
1305cdf0e10cSrcweir     }
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir //-------------------------------------------------------------------------
1309cdf0e10cSrcweir void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir     sal_Int16 nSignatureState = GetDocumentSignatureState();
1312cdf0e10cSrcweir     bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN );
1313cdf0e10cSrcweir     if ( !bSignatureBroken )
1314cdf0e10cSrcweir         return;
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir     pImp->showBrokenSignatureWarning( xHandler );
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir     // broken signatures imply no macro execution at all
1319cdf0e10cSrcweir     pImp->aMacroMode.disallowMacroExecution();
1320cdf0e10cSrcweir }
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir //-------------------------------------------------------------------------
1323cdf0e10cSrcweir void SfxObjectShell::SetAutoLoad(
1324cdf0e10cSrcweir 	const INetURLObject& rUrl, sal_uInt32 nTime, sal_Bool bReload )
1325cdf0e10cSrcweir {
1326cdf0e10cSrcweir 	if ( pImp->pReloadTimer )
1327cdf0e10cSrcweir 		DELETEZ(pImp->pReloadTimer);
1328cdf0e10cSrcweir 	if ( bReload )
1329cdf0e10cSrcweir 	{
1330cdf0e10cSrcweir 		pImp->pReloadTimer = new AutoReloadTimer_Impl(
1331cdf0e10cSrcweir 								rUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ),
1332cdf0e10cSrcweir 								nTime, bReload, this );
1333cdf0e10cSrcweir 		pImp->pReloadTimer->Start();
1334cdf0e10cSrcweir 	}
1335cdf0e10cSrcweir }
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir sal_Bool SfxObjectShell::IsLoadingFinished() const
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir 	return ( pImp->nLoadedFlags == SFX_LOADED_ALL );
1340cdf0e10cSrcweir }
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir void impl_addToModelCollection(const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel);
1343cdf0e10cSrcweir void SfxObjectShell::InitOwnModel_Impl()
1344cdf0e10cSrcweir {
1345cdf0e10cSrcweir 	if ( !pImp->bModelInitialized )
1346cdf0e10cSrcweir 	{
1347cdf0e10cSrcweir 		SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
1348cdf0e10cSrcweir 		if ( pSalvageItem )
1349cdf0e10cSrcweir 		{
1350cdf0e10cSrcweir             pImp->aTempName = pMedium->GetPhysicalName();
1351cdf0e10cSrcweir 			pMedium->GetItemSet()->ClearItem( SID_DOC_SALVAGE );
1352cdf0e10cSrcweir 			pMedium->GetItemSet()->ClearItem( SID_FILE_NAME );
1353cdf0e10cSrcweir 			pMedium->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetOrigURL() ) );
1354cdf0e10cSrcweir 		}
1355cdf0e10cSrcweir 		else
1356cdf0e10cSrcweir 		{
1357cdf0e10cSrcweir 			pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
1358cdf0e10cSrcweir 			pMedium->GetItemSet()->ClearItem( SID_DOCUMENT );
1359cdf0e10cSrcweir 		}
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 		pMedium->GetItemSet()->ClearItem( SID_REFERER );
1362*8699c4ffSmseidel 		uno::Reference< frame::XModel > xModel ( GetModel(), uno::UNO_QUERY );
1363cdf0e10cSrcweir 		if ( xModel.is() )
1364cdf0e10cSrcweir 		{
1365cdf0e10cSrcweir 			::rtl::OUString aURL = GetMedium()->GetOrigURL();
1366cdf0e10cSrcweir 			SfxItemSet *pSet = GetMedium()->GetItemSet();
1367cdf0e10cSrcweir             if ( !GetMedium()->IsReadOnly() )
1368cdf0e10cSrcweir                 pSet->ClearItem( SID_INPUTSTREAM );
1369cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aArgs;
1370cdf0e10cSrcweir 			TransformItems( SID_OPENDOC, *pSet, aArgs );
1371cdf0e10cSrcweir 			xModel->attachResource( aURL, aArgs );
1372cdf0e10cSrcweir             impl_addToModelCollection(xModel);
1373cdf0e10cSrcweir 		}
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir 		pImp->bModelInitialized = sal_True;
1376cdf0e10cSrcweir 	}
1377cdf0e10cSrcweir }
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags )
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir 	sal_Bool bSetModifiedTRUE = sal_False;
1382cdf0e10cSrcweir 	SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1383cdf0e10cSrcweir     if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
1384cdf0e10cSrcweir 	    && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ))
1385cdf0e10cSrcweir 	{
1386cdf0e10cSrcweir 		pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT;
1387cdf0e10cSrcweir 		((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes();
1388cdf0e10cSrcweir 		pImp->bImportDone = sal_True;
1389cdf0e10cSrcweir 		if( !IsAbortingImport() )
1390cdf0e10cSrcweir 			PositionView_Impl();
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir         if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() )
1393cdf0e10cSrcweir             SetReadOnly();
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir 		// Salvage
1396cdf0e10cSrcweir 		if ( pSalvageItem )
1397cdf0e10cSrcweir 			bSetModifiedTRUE = sal_True;
1398cdf0e10cSrcweir 
1399cdf0e10cSrcweir 		if ( !IsEnableSetModified() )
1400cdf0e10cSrcweir 			EnableSetModified( sal_True );
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir 		if( !bSetModifiedTRUE && IsEnableSetModified() )
1403cdf0e10cSrcweir 			SetModified( sal_False );
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir         CheckSecurityOnLoading_Impl();
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir 		bHasName = sal_True; // the document is loaded, so the name should already available
1408cdf0e10cSrcweir 		GetTitle( SFX_TITLE_DETECT );
1409cdf0e10cSrcweir 		InitOwnModel_Impl();
1410cdf0e10cSrcweir 		pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT;
1411cdf0e10cSrcweir 	}
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir     if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES )
1414cdf0e10cSrcweir 	    && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES ))
1415cdf0e10cSrcweir 	{
1416cdf0e10cSrcweir 		pImp->nFlagsInProgress |= SFX_LOADED_IMAGES;
1417cdf0e10cSrcweir         uno::Reference<document::XDocumentProperties> xDocProps(
1418cdf0e10cSrcweir             getDocProperties());
1419cdf0e10cSrcweir         ::rtl::OUString url(xDocProps->getAutoloadURL());
1420cdf0e10cSrcweir         sal_Int32 delay(xDocProps->getAutoloadSecs());
1421cdf0e10cSrcweir         SetAutoLoad( INetURLObject(url), delay * 1000,
1422cdf0e10cSrcweir                      (delay > 0) || url.getLength() );
1423cdf0e10cSrcweir 		if( !bSetModifiedTRUE && IsEnableSetModified() )
1424cdf0e10cSrcweir 			SetModified( sal_False );
1425cdf0e10cSrcweir 		Invalidate( SID_SAVEASDOC );
1426cdf0e10cSrcweir 		pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES;
1427cdf0e10cSrcweir 	}
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 	pImp->nLoadedFlags |= nFlags;
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir 	if ( !pImp->nFlagsInProgress )
1432cdf0e10cSrcweir 	{
1433cdf0e10cSrcweir 		// in case of reentrance calls the first called FinishedLoading() call on the stack
1434cdf0e10cSrcweir 		// should do the notification, in result the notification is done when all the FinishedLoading() calls are finished
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir 		if ( bSetModifiedTRUE )
1437cdf0e10cSrcweir 			SetModified( sal_True );
1438cdf0e10cSrcweir 		else
1439cdf0e10cSrcweir 			SetModified( sal_False );
1440cdf0e10cSrcweir 
1441cdf0e10cSrcweir 		if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) )
1442cdf0e10cSrcweir 		{
1443cdf0e10cSrcweir             SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
1444cdf0e10cSrcweir             sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 			// closing the streams on loading should be under control of SFX!
1447cdf0e10cSrcweir 			DBG_ASSERT( pMedium->IsOpen(), "Don't close the medium when loading documents!" );
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir             if ( bTemplate )
1450cdf0e10cSrcweir             {
1451cdf0e10cSrcweir                 TemplateDisconnectionAfterLoad();
1452cdf0e10cSrcweir             }
1453cdf0e10cSrcweir             else
1454cdf0e10cSrcweir             {
1455cdf0e10cSrcweir                 // if a readonly medium has storage then it's stream is already based on temporary file
1456cdf0e10cSrcweir                 if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() )
1457cdf0e10cSrcweir                     // don't lock file opened read only
1458cdf0e10cSrcweir                     pMedium->CloseInStream();
1459cdf0e10cSrcweir             }
1460cdf0e10cSrcweir 		}
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir         SetInitialized_Impl( false );
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir 		// Title is not available until loading has finished
1465cdf0e10cSrcweir 		Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );
1466cdf0e10cSrcweir 		if ( pImp->nEventId )
1467cdf0e10cSrcweir 			PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
1468cdf0e10cSrcweir 	}
1469cdf0e10cSrcweir }
1470cdf0e10cSrcweir 
1471cdf0e10cSrcweir //-------------------------------------------------------------------------
1472cdf0e10cSrcweir extern void SetTemplate_Impl( const String&, const String&, SfxObjectShell* );
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir void SfxObjectShell::TemplateDisconnectionAfterLoad()
1475cdf0e10cSrcweir {
1476cdf0e10cSrcweir     // document is created from a template
1477cdf0e10cSrcweir     //TODO/LATER: should the templates always be XML docs!
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir     SfxMedium* pTmpMedium = pMedium;
1480cdf0e10cSrcweir     if ( pTmpMedium )
1481cdf0e10cSrcweir     {
1482cdf0e10cSrcweir         String aName( pTmpMedium->GetName() );
1483cdf0e10cSrcweir         SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
1484cdf0e10cSrcweir         String aTemplateName;
1485cdf0e10cSrcweir         if ( pTemplNamItem )
1486cdf0e10cSrcweir             aTemplateName = pTemplNamItem->GetValue();
1487cdf0e10cSrcweir         else
1488cdf0e10cSrcweir         {
1489cdf0e10cSrcweir             // !TODO/LATER: what's this?!
1490cdf0e10cSrcweir             // Interaktiv ( DClick, Contextmenu ) kommt kein Langname mit
1491cdf0e10cSrcweir             aTemplateName = getDocProperties()->getTitle();
1492cdf0e10cSrcweir             if ( !aTemplateName.Len() )
1493cdf0e10cSrcweir             {
1494cdf0e10cSrcweir                 INetURLObject aURL( aName );
1495cdf0e10cSrcweir                 aURL.CutExtension();
1496cdf0e10cSrcweir                 aTemplateName = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1497cdf0e10cSrcweir             }
1498cdf0e10cSrcweir         }
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir         // set medium to noname
1501cdf0e10cSrcweir         pTmpMedium->SetName( String(), sal_True );
1502cdf0e10cSrcweir         pTmpMedium->Init_Impl();
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir         // drop resource
1505cdf0e10cSrcweir         SetNoName();
1506cdf0e10cSrcweir         InvalidateName();
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir         if( IsPackageStorageFormat_Impl( *pTmpMedium ) )
1509cdf0e10cSrcweir         {
1510cdf0e10cSrcweir             // untitled document must be based on temporary storage
1511cdf0e10cSrcweir             // the medium should not dispose the storage in this case
1512cdf0e10cSrcweir             uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1513cdf0e10cSrcweir             GetStorage()->copyToStorage( xTmpStor );
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir             // the medium should disconnect from the original location
1516cdf0e10cSrcweir             // the storage should not be disposed since the document is still
1517cdf0e10cSrcweir             // based on it, but in DoSaveCompleted it will be disposed
1518cdf0e10cSrcweir             pTmpMedium->CanDisposeStorage_Impl( sal_False );
1519cdf0e10cSrcweir             pTmpMedium->Close();
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir             // setting the new storage the medium will be based on
1522cdf0e10cSrcweir             pTmpMedium->SetStorage_Impl( xTmpStor );
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir             ForgetMedium();
1525cdf0e10cSrcweir             if( !DoSaveCompleted( pTmpMedium ) )
1526cdf0e10cSrcweir                 SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1527cdf0e10cSrcweir             else
1528cdf0e10cSrcweir             {
1529cdf0e10cSrcweir                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
1530cdf0e10cSrcweir                 sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir                 if ( !bSalvage )
1533cdf0e10cSrcweir                 {
1534cdf0e10cSrcweir                     // some further initializations for templates
1535cdf0e10cSrcweir                     SetTemplate_Impl( aName, aTemplateName, this );
1536cdf0e10cSrcweir                 }
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir                 // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
1539cdf0e10cSrcweir                 pTmpMedium->CanDisposeStorage_Impl( sal_False );
1540cdf0e10cSrcweir             }
1541cdf0e10cSrcweir         }
1542cdf0e10cSrcweir         else
1543cdf0e10cSrcweir         {
1544cdf0e10cSrcweir             // some further initializations for templates
1545cdf0e10cSrcweir             SetTemplate_Impl( aName, aTemplateName, this );
1546cdf0e10cSrcweir             pTmpMedium->CreateTempFile( sal_True );
1547cdf0e10cSrcweir         }
1548cdf0e10cSrcweir 
1549cdf0e10cSrcweir         // templates are never readonly
1550cdf0e10cSrcweir         pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
1551cdf0e10cSrcweir         pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir         // notifications about possible changes in readonly state and document info
1554cdf0e10cSrcweir         Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
1555cdf0e10cSrcweir 
1556cdf0e10cSrcweir         // created untitled document can't be modified
1557cdf0e10cSrcweir         SetModified( sal_False );
1558cdf0e10cSrcweir     }
1559cdf0e10cSrcweir }
1560cdf0e10cSrcweir 
1561cdf0e10cSrcweir //-------------------------------------------------------------------------
1562cdf0e10cSrcweir 
1563cdf0e10cSrcweir void SfxObjectShell::PositionView_Impl()
1564cdf0e10cSrcweir {
1565cdf0e10cSrcweir 	MarkData_Impl *pMark = Get_Impl()->pMarkData;
1566cdf0e10cSrcweir 	if( pMark )
1567cdf0e10cSrcweir 	{
1568cdf0e10cSrcweir 		SfxViewShell* pSh = pMark->pFrame->GetViewShell();
1569cdf0e10cSrcweir 		if( pMark->aUserData.Len() )
1570cdf0e10cSrcweir 			pSh->ReadUserData( pMark->aUserData, sal_True );
1571cdf0e10cSrcweir 		else if( pMark->aMark.Len() )
1572cdf0e10cSrcweir 			pSh->JumpToMark( pMark->aMark );
1573cdf0e10cSrcweir 		DELETEZ( Get_Impl()->pMarkData );
1574cdf0e10cSrcweir 	}
1575cdf0e10cSrcweir }
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir //-------------------------------------------------------------------------
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir sal_Bool SfxObjectShell::IsLoading() const
1580cdf0e10cSrcweir /*  [Beschreibung ]
1581cdf0e10cSrcweir 	Has FinishedLoading been called? */
1582cdf0e10cSrcweir {
1583cdf0e10cSrcweir 	return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT );
1584cdf0e10cSrcweir }
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir //-------------------------------------------------------------------------
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir void SfxObjectShell::CancelTransfers()
1589cdf0e10cSrcweir /*  [Beschreibung ]
1590cdf0e10cSrcweir 	Hier koennen Transfers gecanceled werden, die nicht mit
1591cdf0e10cSrcweir 	RegisterTransfer registiert wurden */
1592cdf0e10cSrcweir {
1593cdf0e10cSrcweir 	if( ( pImp->nLoadedFlags & SFX_LOADED_ALL ) != SFX_LOADED_ALL )
1594cdf0e10cSrcweir 	{
1595cdf0e10cSrcweir 		AbortImport();
1596cdf0e10cSrcweir 		if( IsLoading() )
1597cdf0e10cSrcweir 			FinishedLoading( SFX_LOADED_ALL );
1598cdf0e10cSrcweir 
1599cdf0e10cSrcweir /*
1600cdf0e10cSrcweir 		SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
1601cdf0e10cSrcweir 		while( pFrame )
1602cdf0e10cSrcweir 		{
1603cdf0e10cSrcweir 			pFrame->CancelTransfers();
1604cdf0e10cSrcweir 			pFrame = SfxViewFrame::GetNext( *pFrame, this );
1605cdf0e10cSrcweir 		}*/
1606cdf0e10cSrcweir 	}
1607cdf0e10cSrcweir }
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir //-------------------------------------------------------------------------
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir AutoReloadTimer_Impl::AutoReloadTimer_Impl(
1612cdf0e10cSrcweir 	const String& rURL, sal_uInt32 nTime, sal_Bool bReloadP, SfxObjectShell* pSh )
1613cdf0e10cSrcweir 	: aUrl( rURL ), bReload( bReloadP ), pObjSh( pSh )
1614cdf0e10cSrcweir {
1615cdf0e10cSrcweir 	SetTimeout( nTime );
1616cdf0e10cSrcweir }
1617cdf0e10cSrcweir 
1618cdf0e10cSrcweir //-------------------------------------------------------------------------
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir void AutoReloadTimer_Impl::Timeout()
1621cdf0e10cSrcweir {
1622cdf0e10cSrcweir 	SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjSh );
1623cdf0e10cSrcweir 
1624cdf0e10cSrcweir 	if ( pFrame )
1625cdf0e10cSrcweir 	{
1626cdf0e10cSrcweir 		// momentan nicht m"oglich/sinnvoll?
1627cdf0e10cSrcweir         if ( !pObjSh->CanReload_Impl() || pObjSh->IsAutoLoadLocked() || Application::IsUICaptured() )
1628cdf0e10cSrcweir 		{
1629cdf0e10cSrcweir 			// erneuten Versuch erlauben
1630cdf0e10cSrcweir 			Start();
1631cdf0e10cSrcweir 			return;
1632cdf0e10cSrcweir 		}
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir 		SfxAllItemSet aSet( SFX_APP()->GetPool() );
1635cdf0e10cSrcweir 		aSet.Put( SfxBoolItem( SID_AUTOLOAD, sal_True ) );
1636cdf0e10cSrcweir 		if ( aUrl.Len() )
1637cdf0e10cSrcweir 			aSet.Put(  SfxStringItem( SID_FILE_NAME, aUrl ) );
1638cdf0e10cSrcweir 		SfxRequest aReq( SID_RELOAD, 0, aSet );
1639cdf0e10cSrcweir 		pObjSh->Get_Impl()->pReloadTimer = 0;
1640cdf0e10cSrcweir 		delete this;
1641cdf0e10cSrcweir 		pFrame->ExecReload_Impl( aReq );
1642cdf0e10cSrcweir 		return;
1643cdf0e10cSrcweir 	}
1644cdf0e10cSrcweir 
1645cdf0e10cSrcweir 	pObjSh->Get_Impl()->pReloadTimer = 0;
1646cdf0e10cSrcweir 	delete this;
1647cdf0e10cSrcweir }
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir SfxModule* SfxObjectShell::GetModule() const
1650cdf0e10cSrcweir {
1651cdf0e10cSrcweir 	return GetFactory().GetModule();
1652cdf0e10cSrcweir }
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir ErrCode SfxObjectShell::CallBasic( const String& rMacro,
1655cdf0e10cSrcweir 	const String& rBasic, SbxArray* pArgs,
1656cdf0e10cSrcweir 	SbxValue* pRet )
1657cdf0e10cSrcweir {
1658cdf0e10cSrcweir     SfxApplication* pApp = SFX_APP();
1659cdf0e10cSrcweir     if( pApp->GetName() != rBasic )
1660cdf0e10cSrcweir     {
1661cdf0e10cSrcweir         if ( !AdjustMacroMode( String() ) )
1662cdf0e10cSrcweir             return ERRCODE_IO_ACCESSDENIED;
1663cdf0e10cSrcweir     }
1664cdf0e10cSrcweir 
1665cdf0e10cSrcweir     BasicManager *pMgr = GetBasicManager();
1666cdf0e10cSrcweir     if( pApp->GetName() == rBasic )
1667cdf0e10cSrcweir         pMgr = pApp->GetBasicManager();
1668cdf0e10cSrcweir     ErrCode nRet = SfxApplication::CallBasic( rMacro, pMgr, pArgs, pRet );
1669cdf0e10cSrcweir     return nRet;
1670cdf0e10cSrcweir }
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir namespace
1673cdf0e10cSrcweir {
1674cdf0e10cSrcweir     static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext )
1675cdf0e10cSrcweir     {
1676cdf0e10cSrcweir         try
1677cdf0e10cSrcweir         {
1678cdf0e10cSrcweir             Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY );
1679cdf0e10cSrcweir             if ( !xScripts.is() )
1680cdf0e10cSrcweir             {
1681cdf0e10cSrcweir                 Reference< XScriptInvocationContext > xContext( _rxScriptContext, UNO_QUERY_THROW );
1682cdf0e10cSrcweir                 xScripts.set( xContext->getScriptContainer(), UNO_SET_THROW );
1683cdf0e10cSrcweir             }
1684cdf0e10cSrcweir 
1685cdf0e10cSrcweir             return xScripts->getAllowMacroExecution();
1686cdf0e10cSrcweir         }
1687cdf0e10cSrcweir         catch( const Exception& )
1688cdf0e10cSrcweir         {
1689cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
1690cdf0e10cSrcweir         }
1691cdf0e10cSrcweir         return false;
1692cdf0e10cSrcweir     }
1693cdf0e10cSrcweir }
1694cdf0e10cSrcweir 
1695cdf0e10cSrcweir ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL,
1696cdf0e10cSrcweir     const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError )
1697cdf0e10cSrcweir {
1698cdf0e10cSrcweir     OSL_TRACE( "in CallXScript" );
1699cdf0e10cSrcweir 	ErrCode nErr = ERRCODE_NONE;
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir 	bool bCaughtException = false;
1702cdf0e10cSrcweir     Any aException;
1703cdf0e10cSrcweir     try
1704cdf0e10cSrcweir     {
1705417e1281SArrigo Marchiori         if ( !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
1706417e1281SArrigo Marchiori             return ERRCODE_IO_ACCESSDENIED;
1707417e1281SArrigo Marchiori 
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 	{
1797*8699c4ffSmseidel 		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     {
2369910823aeSJürgen Schmidt         ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) );
2370910823aeSJürgen Schmidt //#ifdef WNT
2371910823aeSJürgen Schmidt //        ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}" ) );
2372910823aeSJürgen Schmidt //#else
2373910823aeSJürgen Schmidt //        ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/bootstraprc:UserInstallation}" ) );
2374910823aeSJürgen Schmidt //#endif
2375cdf0e10cSrcweir         ::rtl::Bootstrap::expandMacros( aFileURL );
2376cdf0e10cSrcweir 
2377910823aeSJürgen Schmidt //#ifdef WNT
2378910823aeSJürgen Schmidt //        ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setup.ini:buildid}" ) );
2379910823aeSJürgen Schmidt //#else
2380910823aeSJürgen Schmidt //        ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/setuprc:buildid}" ) );
2381910823aeSJürgen Schmidt //#endif
2382910823aeSJürgen Schmidt         ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("setup") ":buildid}" ) );
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 }
2409