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