xref: /aoo41x/main/sfx2/source/doc/objserv.cxx (revision 266fe926)
1cdf0e10cSrcweir /*************************************************************************
2cdf0e10cSrcweir  *
3cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4cdf0e10cSrcweir  *
5cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6cdf0e10cSrcweir  *
7cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8cdf0e10cSrcweir  *
9cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10cdf0e10cSrcweir  *
11cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14cdf0e10cSrcweir  *
15cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20cdf0e10cSrcweir  *
21cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25cdf0e10cSrcweir  *
26cdf0e10cSrcweir  ************************************************************************/
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <sot/storage.hxx>
32cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
33cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
35cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
36cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XControlAccess.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
40cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
41cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
42cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp>
43cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
44cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicator.hpp>
45cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
46cdf0e10cSrcweir #include <com/sun/star/frame/XDocumentTemplates.hpp>
47cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
48cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
49cdf0e10cSrcweir #include <com/sun/star/security/CertificateValidity.hpp>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <com/sun/star/security/DocumentSignatureInformation.hpp>
52cdf0e10cSrcweir #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
53cdf0e10cSrcweir #include <tools/urlobj.hxx>
54cdf0e10cSrcweir #include <svl/whiter.hxx>
55cdf0e10cSrcweir #include <vcl/msgbox.hxx>
56cdf0e10cSrcweir #include <svl/intitem.hxx>
57cdf0e10cSrcweir #include <svl/eitem.hxx>
58cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
59cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
60cdf0e10cSrcweir #include <svtools/ehdl.hxx>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #include <comphelper/string.hxx>
63cdf0e10cSrcweir #include <basic/sbx.hxx>
64cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
65cdf0e10cSrcweir #include <unotools/useroptions.hxx>
66cdf0e10cSrcweir #include <svtools/asynclink.hxx>
67cdf0e10cSrcweir #include <unotools/saveopt.hxx>
68cdf0e10cSrcweir #include <comphelper/documentconstants.hxx>
69cdf0e10cSrcweir 
70cdf0e10cSrcweir #include <sfx2/app.hxx>
71cdf0e10cSrcweir #include <sfx2/signaturestate.hxx>
72cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
73cdf0e10cSrcweir #include <sfx2/event.hxx>
74cdf0e10cSrcweir #include <sfx2/request.hxx>
75cdf0e10cSrcweir #include <sfx2/printer.hxx>
76cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
77cdf0e10cSrcweir #include <sfx2/doctdlg.hxx>
78cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
79cdf0e10cSrcweir #include <sfx2/docfile.hxx>
80cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
81cdf0e10cSrcweir #include <sfx2/dinfdlg.hxx>
82cdf0e10cSrcweir #include <sfx2/objitem.hxx>
83cdf0e10cSrcweir #include <sfx2/objsh.hxx>
84cdf0e10cSrcweir #include "objshimp.hxx"
85cdf0e10cSrcweir #include "sfxtypes.hxx"
86cdf0e10cSrcweir //#include "interno.hxx"
87cdf0e10cSrcweir #include <sfx2/module.hxx>
88cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
89cdf0e10cSrcweir #include "versdlg.hxx"
90cdf0e10cSrcweir #include "doc.hrc"
91cdf0e10cSrcweir #include <sfx2/docfac.hxx>
92cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
93cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
94cdf0e10cSrcweir #include "sfx2/sfxhelp.hxx"
95cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
96cdf0e10cSrcweir #include <sfx2/objface.hxx>
97cdf0e10cSrcweir 
98cdf0e10cSrcweir #include "../appl/app.hrc"
99cdf0e10cSrcweir #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
100cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
101cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
102cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
103cdf0e10cSrcweir 
104cdf0e10cSrcweir #include "helpid.hrc"
105cdf0e10cSrcweir 
106cdf0e10cSrcweir #include "guisaveas.hxx"
107cdf0e10cSrcweir 
108cdf0e10cSrcweir using namespace ::com::sun::star;
109cdf0e10cSrcweir using namespace ::com::sun::star::lang;
110cdf0e10cSrcweir using namespace ::com::sun::star::uno;
111cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
112cdf0e10cSrcweir using namespace ::com::sun::star::awt;
113cdf0e10cSrcweir using namespace ::com::sun::star::container;
114cdf0e10cSrcweir using namespace ::com::sun::star::beans;
115cdf0e10cSrcweir using namespace ::com::sun::star::document;
116cdf0e10cSrcweir using namespace ::com::sun::star::task;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir //====================================================================
119cdf0e10cSrcweir 
120cdf0e10cSrcweir class SfxSaveAsContext_Impl
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	String&		_rNewNameVar;
123cdf0e10cSrcweir 	String 		_aNewName;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir public:
126cdf0e10cSrcweir 				SfxSaveAsContext_Impl( String &rNewNameVar,
127cdf0e10cSrcweir 									   const String &rNewName )
128cdf0e10cSrcweir 				:	_rNewNameVar( rNewNameVar ),
129cdf0e10cSrcweir 					_aNewName( rNewName )
130cdf0e10cSrcweir 				{ rNewNameVar = rNewName; }
131cdf0e10cSrcweir 				~SfxSaveAsContext_Impl()
132cdf0e10cSrcweir 				{ _rNewNameVar.Erase(); }
133cdf0e10cSrcweir };
134cdf0e10cSrcweir 
135cdf0e10cSrcweir //====================================================================
136cdf0e10cSrcweir 
137cdf0e10cSrcweir #define SfxObjectShell
138cdf0e10cSrcweir #include "sfxslots.hxx"
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //=========================================================================
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir SFX_IMPL_INTERFACE(SfxObjectShell,SfxShell,SfxResId(0))
145cdf0e10cSrcweir {
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir //=========================================================================
149cdf0e10cSrcweir 
150cdf0e10cSrcweir class SfxClosePreventer_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	sal_Bool m_bGotOwnership;
153cdf0e10cSrcweir 	sal_Bool m_bPreventClose;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir public:
156cdf0e10cSrcweir 	SfxClosePreventer_Impl();
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	sal_Bool HasOwnership() { return m_bGotOwnership; }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	void SetPreventClose( sal_Bool bPrevent ) { m_bPreventClose = bPrevent; }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     virtual void SAL_CALL queryClosing( const lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
163cdf0e10cSrcweir         throw ( uno::RuntimeException, util::CloseVetoException );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     virtual void SAL_CALL notifyClosing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir } ;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir SfxClosePreventer_Impl::SfxClosePreventer_Impl()
172cdf0e10cSrcweir : m_bGotOwnership( sal_False )
173cdf0e10cSrcweir , m_bPreventClose( sal_True )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir void SAL_CALL SfxClosePreventer_Impl::queryClosing( const lang::EventObject&, sal_Bool bDeliverOwnership )
178cdf0e10cSrcweir         throw ( uno::RuntimeException, util::CloseVetoException )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	if ( m_bPreventClose )
181cdf0e10cSrcweir 	{
182cdf0e10cSrcweir 		if ( !m_bGotOwnership )
183cdf0e10cSrcweir 			m_bGotOwnership = bDeliverOwnership;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 		throw util::CloseVetoException();
186cdf0e10cSrcweir 	}
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir void SAL_CALL SfxClosePreventer_Impl::notifyClosing( const lang::EventObject& ) throw ( uno::RuntimeException )
190cdf0e10cSrcweir {}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir void SAL_CALL SfxClosePreventer_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException )
193cdf0e10cSrcweir {}
194cdf0e10cSrcweir 
195cdf0e10cSrcweir //=========================================================================
196cdf0e10cSrcweir class SfxInstanceCloseGuard_Impl
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	SfxClosePreventer_Impl* m_pPreventer;
199cdf0e10cSrcweir 	uno::Reference< util::XCloseListener > m_xPreventer;
200cdf0e10cSrcweir 	uno::Reference< util::XCloseable > m_xCloseable;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir public:
203cdf0e10cSrcweir 	SfxInstanceCloseGuard_Impl()
204cdf0e10cSrcweir 	: m_pPreventer( NULL )
205cdf0e10cSrcweir 	{}
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	~SfxInstanceCloseGuard_Impl();
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 	sal_Bool Init_Impl( const uno::Reference< util::XCloseable >& xCloseable );
210cdf0e10cSrcweir };
211cdf0e10cSrcweir 
212cdf0e10cSrcweir sal_Bool SfxInstanceCloseGuard_Impl::Init_Impl( const uno::Reference< util::XCloseable >& xCloseable )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	sal_Bool bResult = sal_False;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	// do not allow reinit after the successful init
217cdf0e10cSrcweir 	if ( xCloseable.is() && !m_xCloseable.is() )
218cdf0e10cSrcweir 	{
219cdf0e10cSrcweir 		try
220cdf0e10cSrcweir 		{
221cdf0e10cSrcweir 			m_pPreventer = new SfxClosePreventer_Impl();
222cdf0e10cSrcweir 			m_xPreventer = uno::Reference< util::XCloseListener >( m_pPreventer );
223cdf0e10cSrcweir 			xCloseable->addCloseListener( m_xPreventer );
224cdf0e10cSrcweir 			m_xCloseable = xCloseable;
225cdf0e10cSrcweir 			bResult = sal_True;
226cdf0e10cSrcweir 		}
227cdf0e10cSrcweir 		catch( uno::Exception& )
228cdf0e10cSrcweir 		{
229cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Could not register close listener!\n" );
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 	}
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	return bResult;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir SfxInstanceCloseGuard_Impl::~SfxInstanceCloseGuard_Impl()
237cdf0e10cSrcweir {
238cdf0e10cSrcweir 	if ( m_xCloseable.is() && m_xPreventer.is() )
239cdf0e10cSrcweir 	{
240cdf0e10cSrcweir 		try
241cdf0e10cSrcweir 		{
242cdf0e10cSrcweir 			m_xCloseable->removeCloseListener( m_xPreventer );
243cdf0e10cSrcweir 		}
244cdf0e10cSrcweir 		catch( uno::Exception& )
245cdf0e10cSrcweir 		{
246cdf0e10cSrcweir 		}
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 		try
249cdf0e10cSrcweir 		{
250cdf0e10cSrcweir 			if ( m_pPreventer )
251cdf0e10cSrcweir 			{
252cdf0e10cSrcweir 				m_pPreventer->SetPreventClose( sal_False );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 				if ( m_pPreventer->HasOwnership() )
255cdf0e10cSrcweir 					m_xCloseable->close( sal_True ); // TODO: do it asynchronously
256cdf0e10cSrcweir 			}
257cdf0e10cSrcweir 		}
258cdf0e10cSrcweir 		catch( uno::Exception& )
259cdf0e10cSrcweir 		{
260cdf0e10cSrcweir 		}
261cdf0e10cSrcweir 	}
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir //=========================================================================
265cdf0e10cSrcweir 
266cdf0e10cSrcweir void SfxObjectShell::PrintExec_Impl(SfxRequest &rReq)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this);
269cdf0e10cSrcweir 	if ( pFrame )
270cdf0e10cSrcweir 	{
271cdf0e10cSrcweir 		rReq.SetSlot( SID_PRINTDOC );
272cdf0e10cSrcweir 		pFrame->GetViewShell()->ExecuteSlot(rReq);
273cdf0e10cSrcweir 	}
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir //--------------------------------------------------------------------
277cdf0e10cSrcweir 
278cdf0e10cSrcweir void SfxObjectShell::PrintState_Impl(SfxItemSet &rSet)
279cdf0e10cSrcweir {
280cdf0e10cSrcweir 	bool bPrinting = false;
281cdf0e10cSrcweir 	SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
282cdf0e10cSrcweir 	if ( pFrame )
283cdf0e10cSrcweir 	{
284cdf0e10cSrcweir 		SfxPrinter *pPrinter = pFrame->GetViewShell()->GetPrinter();
285cdf0e10cSrcweir 		bPrinting = pPrinter && pPrinter->IsPrinting();
286cdf0e10cSrcweir 	}
287cdf0e10cSrcweir 	rSet.Put( SfxBoolItem( SID_PRINTOUT, bPrinting ) );
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir //--------------------------------------------------------------------
291cdf0e10cSrcweir 
292cdf0e10cSrcweir sal_Bool SfxObjectShell::APISaveAs_Impl
293cdf0e10cSrcweir (
294cdf0e10cSrcweir 	const String& aFileName,
295cdf0e10cSrcweir 	SfxItemSet*	  aParams
296cdf0e10cSrcweir )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir     sal_Bool bOk = sal_False;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 	{DBG_CHKTHIS(SfxObjectShell, 0);}
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 	if ( GetMedium() )
303cdf0e10cSrcweir 	{
304cdf0e10cSrcweir 		String aFilterName;
305cdf0e10cSrcweir 		SFX_ITEMSET_ARG( aParams, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
306cdf0e10cSrcweir 		if( pFilterNameItem )
307cdf0e10cSrcweir         {
308cdf0e10cSrcweir 			aFilterName = pFilterNameItem->GetValue();
309cdf0e10cSrcweir         }
310cdf0e10cSrcweir         else
311cdf0e10cSrcweir         {
312cdf0e10cSrcweir             SFX_ITEMSET_ARG( aParams, pContentTypeItem, SfxStringItem, SID_CONTENTTYPE, sal_False );
313cdf0e10cSrcweir             if ( pContentTypeItem )
314cdf0e10cSrcweir             {
315cdf0e10cSrcweir                 const SfxFilter* pFilter = SfxFilterMatcher( String::CreateFromAscii(GetFactory().GetShortName()) ).GetFilter4Mime( pContentTypeItem->GetValue(), SFX_FILTER_EXPORT );
316cdf0e10cSrcweir                 if ( pFilter )
317cdf0e10cSrcweir                     aFilterName = pFilter->GetName();
318cdf0e10cSrcweir             }
319cdf0e10cSrcweir         }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 		// in case no filter defined use default one
322cdf0e10cSrcweir 		if( !aFilterName.Len() )
323cdf0e10cSrcweir 		{
324cdf0e10cSrcweir             const SfxFilter* pFilt = SfxFilter::GetDefaultFilterFromFactory(GetFactory().GetFactoryName());
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 			DBG_ASSERT( pFilt, "No default filter!\n" );
327cdf0e10cSrcweir 			if( pFilt )
328cdf0e10cSrcweir         		aFilterName = pFilt->GetFilterName();
329cdf0e10cSrcweir 
330cdf0e10cSrcweir         	aParams->Put(SfxStringItem( SID_FILTER_NAME, aFilterName));
331cdf0e10cSrcweir 		}
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 		{
335cdf0e10cSrcweir 			SfxObjectShellRef xLock( this ); // ???
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 			// use the title that is provided in the media descriptor
338cdf0e10cSrcweir 			SFX_ITEMSET_ARG( aParams, pDocTitleItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
339cdf0e10cSrcweir 			if ( pDocTitleItem )
340cdf0e10cSrcweir 				getDocProperties()->setTitle( pDocTitleItem->GetValue() );
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	        bOk = CommonSaveAs_Impl( INetURLObject(aFileName), aFilterName,
343cdf0e10cSrcweir 				aParams );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 		}
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 		// prevent picklist-entry
348cdf0e10cSrcweir 		GetMedium()->SetUpdatePickList( sal_False );
349cdf0e10cSrcweir 	}
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 	return bOk;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir //--------------------------------------------------------------------
355cdf0e10cSrcweir 
356cdf0e10cSrcweir void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
357cdf0e10cSrcweir {
358cdf0e10cSrcweir 	{DBG_CHKTHIS(SfxObjectShell, 0);}
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	sal_uInt16 nId = rReq.GetSlot();
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     if( SID_SIGNATURE == nId || SID_MACRO_SIGNATURE == nId )
363cdf0e10cSrcweir 	{
364cdf0e10cSrcweir 		if ( QueryHiddenInformation( WhenSigning, NULL ) == RET_YES )
365cdf0e10cSrcweir             ( SID_SIGNATURE == nId ) ? SignDocumentContent() : SignScriptingContent();
366cdf0e10cSrcweir 		return;
367cdf0e10cSrcweir 	}
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	if ( !GetMedium() && nId != SID_CLOSEDOC )
370cdf0e10cSrcweir     {
371cdf0e10cSrcweir         rReq.Ignore();
372cdf0e10cSrcweir 		return;
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 	// this guard is created here to have it destruction at the end of the method
376cdf0e10cSrcweir 	SfxInstanceCloseGuard_Impl aModelGuard;
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 	sal_Bool bIsPDFExport = sal_False;
379cdf0e10cSrcweir 	switch(nId)
380cdf0e10cSrcweir 	{
381cdf0e10cSrcweir 		case SID_VERSION:
382cdf0e10cSrcweir 		{
383cdf0e10cSrcweir 			SfxViewFrame* pFrame = GetFrame();
384cdf0e10cSrcweir 			if ( !pFrame )
385cdf0e10cSrcweir 				pFrame = SfxViewFrame::GetFirst( this );
386cdf0e10cSrcweir 			if ( !pFrame )
387cdf0e10cSrcweir 				return;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir             if ( pFrame->GetFrame().GetParentFrame() )
390cdf0e10cSrcweir             {
391cdf0e10cSrcweir                 pFrame->GetTopViewFrame()->GetObjectShell()->ExecuteSlot( rReq );
392cdf0e10cSrcweir                 return;
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 			if ( !IsOwnStorageFormat_Impl( *GetMedium() ) )
396cdf0e10cSrcweir 				return;
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 			SfxVersionDialog *pDlg = new SfxVersionDialog( pFrame, IsSaveVersionOnClose() );
399cdf0e10cSrcweir 			pDlg->Execute();
400cdf0e10cSrcweir 			SetSaveVersionOnClose( pDlg->IsSaveVersionOnClose() );
401cdf0e10cSrcweir 			delete pDlg;
402cdf0e10cSrcweir             rReq.Done();
403cdf0e10cSrcweir             return;
404cdf0e10cSrcweir 		}
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
407cdf0e10cSrcweir 		case SID_DOCINFO:
408cdf0e10cSrcweir 		{
409cdf0e10cSrcweir 			SFX_REQUEST_ARG(rReq, pDocInfItem, SfxDocumentInfoItem, SID_DOCINFO, sal_False);
410cdf0e10cSrcweir 			if ( pDocInfItem )
411cdf0e10cSrcweir 			{
412cdf0e10cSrcweir 				// parameter, e.g. from replayed macro
413cdf0e10cSrcweir                 pDocInfItem->UpdateDocumentInfo(getDocProperties(), true);
414cdf0e10cSrcweir 				SetUseUserData( pDocInfItem->IsUseUserData() );
415cdf0e10cSrcweir 			}
416cdf0e10cSrcweir 			else
417cdf0e10cSrcweir 			{
418cdf0e10cSrcweir 				// no argument containing DocInfo; check optional arguments
419cdf0e10cSrcweir 				sal_Bool bReadOnly = IsReadOnly();
420cdf0e10cSrcweir 				SFX_REQUEST_ARG(rReq, pROItem, SfxBoolItem, SID_DOC_READONLY, sal_False);
421cdf0e10cSrcweir 				if ( pROItem )
422cdf0e10cSrcweir 					// override readonly attribute of document
423cdf0e10cSrcweir 					// e.g. if a readonly document is saved elsewhere and user asks for editing DocInfo before
424cdf0e10cSrcweir 					bReadOnly = pROItem->GetValue();
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 				// collect data for dialog
427cdf0e10cSrcweir 				String aURL, aTitle;
428cdf0e10cSrcweir 				if ( HasName() )
429cdf0e10cSrcweir 				{
430cdf0e10cSrcweir 					aURL = GetMedium()->GetName();
431cdf0e10cSrcweir 					aTitle = GetTitle();
432cdf0e10cSrcweir 				}
433cdf0e10cSrcweir 				else
434cdf0e10cSrcweir 				{
435cdf0e10cSrcweir 					aURL = DEFINE_CONST_UNICODE( "private:factory/" );
436cdf0e10cSrcweir 					aURL += String::CreateFromAscii( GetFactory().GetShortName() );
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 					aTitle = GetTitle();
439cdf0e10cSrcweir 				}
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 				SfxDocumentInfoItem aDocInfoItem( aURL, getDocProperties(),
442cdf0e10cSrcweir                     IsUseUserData() );
443cdf0e10cSrcweir 				if ( !GetSlotState( SID_DOCTEMPLATE ) )
444cdf0e10cSrcweir 					// templates not supported
445cdf0e10cSrcweir 					aDocInfoItem.SetTemplate(sal_False);
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 				SfxItemSet aSet(GetPool(), SID_DOCINFO, SID_DOCINFO, SID_DOC_READONLY, SID_DOC_READONLY,
448cdf0e10cSrcweir 								SID_EXPLORER_PROPS_START, SID_EXPLORER_PROPS_START, SID_BASEURL, SID_BASEURL,
449cdf0e10cSrcweir 								0L );
450cdf0e10cSrcweir 				aSet.Put( aDocInfoItem );
451cdf0e10cSrcweir 				aSet.Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
452cdf0e10cSrcweir 				aSet.Put( SfxStringItem( SID_EXPLORER_PROPS_START, aTitle ) );
453cdf0e10cSrcweir 				aSet.Put( SfxStringItem( SID_BASEURL, GetMedium()->GetBaseURL() ) );
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 				// creating dialog is done via virtual method; application will add its own statistics page
456cdf0e10cSrcweir 				SfxDocumentInfoDialog *pDlg = CreateDocumentInfoDialog(0, aSet);
457cdf0e10cSrcweir 				if ( RET_OK == pDlg->Execute() )
458cdf0e10cSrcweir 				{
459cdf0e10cSrcweir 					SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pDocInfoItem, SfxDocumentInfoItem, SID_DOCINFO, sal_False);
460cdf0e10cSrcweir 					if ( pDocInfoItem )
461cdf0e10cSrcweir 					{
462cdf0e10cSrcweir 						// user has done some changes to DocumentInfo
463cdf0e10cSrcweir                         pDocInfoItem->UpdateDocumentInfo(getDocProperties());
464cdf0e10cSrcweir 						SetUseUserData( ((const SfxDocumentInfoItem *)pDocInfoItem)->IsUseUserData() );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 						// add data from dialog for possible recording purposes
467cdf0e10cSrcweir 						rReq.AppendItem( SfxDocumentInfoItem( GetTitle(),
468cdf0e10cSrcweir                             getDocProperties(), IsUseUserData() ) );
469cdf0e10cSrcweir 					}
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 					rReq.Done();
472cdf0e10cSrcweir 				}
473cdf0e10cSrcweir 				else
474cdf0e10cSrcweir 					// nothing done; no recording
475cdf0e10cSrcweir                     rReq.Ignore();
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 				delete pDlg;
478cdf0e10cSrcweir 			}
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 			return;
481cdf0e10cSrcweir         }
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 		case SID_EXPORTDOCASPDF:
486cdf0e10cSrcweir 		case SID_DIRECTEXPORTDOCASPDF:
487cdf0e10cSrcweir 			bIsPDFExport = sal_True;
488cdf0e10cSrcweir 		case SID_EXPORTDOC:
489cdf0e10cSrcweir 		case SID_SAVEASDOC:
490cdf0e10cSrcweir 		case SID_SAVEDOC:
491cdf0e10cSrcweir 		{
492cdf0e10cSrcweir             // derived class may decide to abort this
493cdf0e10cSrcweir             if( !QuerySlotExecutable( nId ) )
494cdf0e10cSrcweir             {
495cdf0e10cSrcweir                 rReq.SetReturnValue( SfxBoolItem( 0, sal_False ) );
496cdf0e10cSrcweir                 return;
497cdf0e10cSrcweir             }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 			//!! detaillierte Auswertung eines Fehlercodes
500cdf0e10cSrcweir 			SfxObjectShellRef xLock( this );
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 			// the model can not be closed till the end of this method
503cdf0e10cSrcweir 			// if somebody tries to close it during this time the model will be closed
504cdf0e10cSrcweir 			// at the end of the method
505cdf0e10cSrcweir 			aModelGuard.Init_Impl( uno::Reference< util::XCloseable >( GetModel(), uno::UNO_QUERY ) );
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 			sal_Bool bDialogUsed = sal_False;
508cdf0e10cSrcweir 			sal_uInt32 nErrorCode = ERRCODE_NONE;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir             // by default versions should be preserved always except in case of an explicit
511cdf0e10cSrcweir             // SaveAs via GUI, so the flag must be set accordingly
512cdf0e10cSrcweir             pImp->bPreserveVersions = (nId == SID_SAVEDOC);
513cdf0e10cSrcweir 			try
514cdf0e10cSrcweir 			{
515cdf0e10cSrcweir 				SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, GetTitle() ); // ???
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 				if ( nId == SID_SAVEASDOC )
518cdf0e10cSrcweir 				{
519cdf0e10cSrcweir 					// in case of plugin mode the SaveAs operation means SaveTo
520cdf0e10cSrcweir 					SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pViewOnlyItem, SfxBoolItem, SID_VIEWONLY, sal_False );
521cdf0e10cSrcweir 					if ( pViewOnlyItem && pViewOnlyItem->GetValue() )
522cdf0e10cSrcweir 						rReq.AppendItem( SfxBoolItem( SID_SAVETO, sal_True ) );
523cdf0e10cSrcweir 				}
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 				// TODO/LATER: do the following GUI related actions in standalown method
526cdf0e10cSrcweir 				// ========================================================================================================
527cdf0e10cSrcweir 				// Introduce a status indicator for GUI operation
528cdf0e10cSrcweir 				SFX_REQUEST_ARG( rReq, pStatusIndicatorItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, sal_False );
529cdf0e10cSrcweir 				if ( !pStatusIndicatorItem )
530cdf0e10cSrcweir 				{
531cdf0e10cSrcweir 					// get statusindicator
532cdf0e10cSrcweir 					uno::Reference< task::XStatusIndicator > xStatusIndicator;
533*266fe926SMathias Bauer 					uno::Reference < frame::XController > xCtrl( GetModel()->getCurrentController() );
534*266fe926SMathias Bauer 					if ( xCtrl.is() )
535cdf0e10cSrcweir 					{
536*266fe926SMathias Bauer 						uno::Reference< task::XStatusIndicatorFactory > xStatFactory( xCtrl->getFrame(), uno::UNO_QUERY );
537cdf0e10cSrcweir 						if( xStatFactory.is() )
538cdf0e10cSrcweir 							xStatusIndicator = xStatFactory->createStatusIndicator();
539cdf0e10cSrcweir 					}
540cdf0e10cSrcweir 
541cdf0e10cSrcweir 					OSL_ENSURE( xStatusIndicator.is(), "Can not retrieve default status indicator!\n" );
542*266fe926SMathias Bauer 
543cdf0e10cSrcweir 					if ( xStatusIndicator.is() )
544cdf0e10cSrcweir 					{
545cdf0e10cSrcweir 						SfxUnoAnyItem aStatIndItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::makeAny( xStatusIndicator ) );
546cdf0e10cSrcweir 
547cdf0e10cSrcweir 						if ( nId == SID_SAVEDOC )
548cdf0e10cSrcweir 						{
549cdf0e10cSrcweir 							// in case of saving it is not possible to transport the parameters from here
550cdf0e10cSrcweir 							// but it is not clear here whether the saving will be done or saveAs operation
551cdf0e10cSrcweir 							GetMedium()->GetItemSet()->Put( aStatIndItem );
552cdf0e10cSrcweir 						}
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 						rReq.AppendItem( aStatIndItem );
555cdf0e10cSrcweir 					}
556cdf0e10cSrcweir 				}
557cdf0e10cSrcweir 				else if ( nId == SID_SAVEDOC )
558cdf0e10cSrcweir 				{
559cdf0e10cSrcweir 					// in case of saving it is not possible to transport the parameters from here
560cdf0e10cSrcweir 					// but it is not clear here whether the saving will be done or saveAs operation
561cdf0e10cSrcweir 					GetMedium()->GetItemSet()->Put( *pStatusIndicatorItem );
562cdf0e10cSrcweir 				}
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 				// Introduce an interaction handler for GUI operation
565cdf0e10cSrcweir 				SFX_REQUEST_ARG( rReq, pInteractionHandlerItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False );
566cdf0e10cSrcweir 				if ( !pInteractionHandlerItem )
567cdf0e10cSrcweir 				{
568cdf0e10cSrcweir 					uno::Reference< task::XInteractionHandler > xInteract;
569cdf0e10cSrcweir 					uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
570cdf0e10cSrcweir 					if( xServiceManager.is() )
571cdf0e10cSrcweir 					{
572cdf0e10cSrcweir 						xInteract = Reference< XInteractionHandler >(
573cdf0e10cSrcweir 							xServiceManager->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ),
574cdf0e10cSrcweir 							UNO_QUERY );
575cdf0e10cSrcweir 					}
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 					OSL_ENSURE( xInteract.is(), "Can not retrieve default status indicator!\n" );
578cdf0e10cSrcweir 					if ( xInteract.is() )
579cdf0e10cSrcweir 					{
580cdf0e10cSrcweir 						SfxUnoAnyItem aInteractionItem( SID_INTERACTIONHANDLER, uno::makeAny( xInteract ) );
581cdf0e10cSrcweir 						if ( nId == SID_SAVEDOC )
582cdf0e10cSrcweir 						{
583cdf0e10cSrcweir 							// in case of saving it is not possible to transport the parameters from here
584cdf0e10cSrcweir 							// but it is not clear here whether the saving will be done or saveAs operation
585cdf0e10cSrcweir 							GetMedium()->GetItemSet()->Put( aInteractionItem );
586cdf0e10cSrcweir 						}
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 						rReq.AppendItem( aInteractionItem );
589cdf0e10cSrcweir 					}
590cdf0e10cSrcweir 				}
591cdf0e10cSrcweir 				else if ( nId == SID_SAVEDOC )
592cdf0e10cSrcweir 				{
593cdf0e10cSrcweir 					// in case of saving it is not possible to transport the parameters from here
594cdf0e10cSrcweir 					// but it is not clear here whether the saving will be done or saveAs operation
595cdf0e10cSrcweir 					GetMedium()->GetItemSet()->Put( *pInteractionHandlerItem );
596cdf0e10cSrcweir 				}
597cdf0e10cSrcweir 				// ========================================================================================================
598cdf0e10cSrcweir 
599cdf0e10cSrcweir                 sal_Bool bPreselectPassword = sal_False;
600cdf0e10cSrcweir                 SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pOldEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, sal_False );
601cdf0e10cSrcweir                 SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pOldPasswordItem, SfxStringItem, SID_PASSWORD, sal_False );
602cdf0e10cSrcweir                 if ( pOldEncryptionDataItem || pOldPasswordItem )
603cdf0e10cSrcweir                     bPreselectPassword = sal_True;
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 				uno::Sequence< beans::PropertyValue > aDispatchArgs;
606cdf0e10cSrcweir 				if ( rReq.GetArgs() )
607cdf0e10cSrcweir 					TransformItems( nId,
608cdf0e10cSrcweir 									*rReq.GetArgs(),
609cdf0e10cSrcweir 							 		aDispatchArgs,
610cdf0e10cSrcweir 							 		NULL );
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 				const SfxSlot* pSlot = GetModule()->GetSlotPool()->GetSlot( nId );
613cdf0e10cSrcweir 				if ( !pSlot )
614cdf0e10cSrcweir 					throw uno::Exception();
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 				uno::Reference< lang::XMultiServiceFactory > xEmptyFactory;
617cdf0e10cSrcweir 				SfxStoringHelper aHelper( xEmptyFactory );
618cdf0e10cSrcweir 
619cdf0e10cSrcweir                 if ( QueryHiddenInformation( bIsPDFExport ? WhenCreatingPDF : WhenSaving, NULL ) == RET_YES )
620cdf0e10cSrcweir                 {
621cdf0e10cSrcweir                     bDialogUsed = aHelper.GUIStoreModel( GetModel(),
622cdf0e10cSrcweir                                                          ::rtl::OUString::createFromAscii( pSlot->GetUnoName() ),
623cdf0e10cSrcweir                                                          aDispatchArgs,
624cdf0e10cSrcweir                                                          bPreselectPassword,
625cdf0e10cSrcweir                                                          GetSharedFileURL(),
626cdf0e10cSrcweir                                                          GetDocumentSignatureState() );
627cdf0e10cSrcweir                 }
628cdf0e10cSrcweir                 else
629cdf0e10cSrcweir                 {
630cdf0e10cSrcweir                     // the user has decided not to store the document
631cdf0e10cSrcweir                     throw task::ErrorCodeIOException( ::rtl::OUString(),
632cdf0e10cSrcweir                                                       uno::Reference< uno::XInterface >(),
633cdf0e10cSrcweir                                                       ERRCODE_IO_ABORT );
634cdf0e10cSrcweir                 }
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 				// merge aDispatchArgs to the request
637cdf0e10cSrcweir 				SfxAllItemSet aResultParams( GetPool() );
638cdf0e10cSrcweir 				TransformParameters( nId,
639cdf0e10cSrcweir 							 		aDispatchArgs,
640cdf0e10cSrcweir 							 		aResultParams,
641cdf0e10cSrcweir 							 		NULL );
642cdf0e10cSrcweir 				rReq.SetArgs( aResultParams );
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 				SFX_REQUEST_ARG( rReq, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
645cdf0e10cSrcweir 				::rtl::OUString aFilterName = pFilterNameItem ? ::rtl::OUString( pFilterNameItem->GetValue() )
646cdf0e10cSrcweir 															  : ::rtl::OUString();
647cdf0e10cSrcweir 				const SfxFilter* pFilt = GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
648cdf0e10cSrcweir 
649cdf0e10cSrcweir 				OSL_ENSURE( nId == SID_SAVEDOC || pFilt, "The filter can not be zero since it was used for storing!\n" );
650cdf0e10cSrcweir 				if  (   bDialogUsed && pFilt
651cdf0e10cSrcweir 					&&  pFilt->IsOwnFormat()
652cdf0e10cSrcweir 					&&  pFilt->UsesStorage()
653cdf0e10cSrcweir 					&&  pFilt->GetVersion() >= SOFFICE_FILEFORMAT_60 )
654cdf0e10cSrcweir 				{
655cdf0e10cSrcweir 					SfxViewFrame* pDocViewFrame = SfxViewFrame::GetFirst( this );
656cdf0e10cSrcweir                     if ( pDocViewFrame )
657cdf0e10cSrcweir 						SfxHelp::OpenHelpAgent( &pDocViewFrame->GetFrame(), HID_DID_SAVE_PACKED_XML );
658cdf0e10cSrcweir 				}
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 				// the StoreAsURL/StoreToURL method have called this method with false
661cdf0e10cSrcweir 				// so it has to be restored to true here since it is a call from GUI
662cdf0e10cSrcweir 				GetMedium()->SetUpdatePickList( sal_True );
663cdf0e10cSrcweir 
664cdf0e10cSrcweir                 // TODO: in future it must be done in followind way
665cdf0e10cSrcweir 				// if document is opened from GUI it is immediatelly appeares in the picklist
666cdf0e10cSrcweir 				// if the document is a new one then it appeares in the picklist immediatelly
667cdf0e10cSrcweir 				// after SaveAs operation triggered from GUI
668cdf0e10cSrcweir 			}
669cdf0e10cSrcweir 			catch( task::ErrorCodeIOException& aErrorEx )
670cdf0e10cSrcweir 			{
671cdf0e10cSrcweir 				nErrorCode = (sal_uInt32)aErrorEx.ErrCode;
672cdf0e10cSrcweir 			}
673cdf0e10cSrcweir 			catch( Exception& )
674cdf0e10cSrcweir 			{
675cdf0e10cSrcweir 				nErrorCode = ERRCODE_IO_GENERAL;
676cdf0e10cSrcweir 			}
677cdf0e10cSrcweir 
678cdf0e10cSrcweir             // by default versions should be preserved always except in case of an explicit
679cdf0e10cSrcweir             // SaveAs via GUI, so the flag must be reset to guarantee this
680cdf0e10cSrcweir             pImp->bPreserveVersions = sal_True;
681cdf0e10cSrcweir 			sal_uIntPtr lErr=GetErrorCode();
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 			if ( !lErr && nErrorCode )
684cdf0e10cSrcweir 				lErr = nErrorCode;
685cdf0e10cSrcweir 
686cdf0e10cSrcweir             if ( lErr && nErrorCode == ERRCODE_NONE )
687cdf0e10cSrcweir             {
688cdf0e10cSrcweir                 SFX_REQUEST_ARG( rReq, pWarnItem, SfxBoolItem, SID_FAIL_ON_WARNING, sal_False );
689cdf0e10cSrcweir                 if ( pWarnItem && pWarnItem->GetValue() )
690cdf0e10cSrcweir                     nErrorCode = lErr;
691cdf0e10cSrcweir             }
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 			// may be nErrorCode should be shown in future
694cdf0e10cSrcweir 			if ( lErr != ERRCODE_IO_ABORT )
695cdf0e10cSrcweir 			{
696cdf0e10cSrcweir 				SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC,GetTitle());
697cdf0e10cSrcweir                 ErrorHandler::HandleError( lErr );
698cdf0e10cSrcweir 			}
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 			if ( nId == SID_EXPORTDOCASPDF )
701cdf0e10cSrcweir 			{
702cdf0e10cSrcweir 				// This function is used by the SendMail function that needs information if a export
703cdf0e10cSrcweir 				// file was written or not. This could be due to cancellation of the export
704cdf0e10cSrcweir 				// or due to an error. So IO abort must be handled like an error!
705cdf0e10cSrcweir 				nErrorCode = ( lErr != ERRCODE_IO_ABORT ) && ( nErrorCode == ERRCODE_NONE ) ? nErrorCode : lErr;
706cdf0e10cSrcweir 			}
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 			rReq.SetReturnValue( SfxBoolItem(0, nErrorCode == ERRCODE_NONE ) );
709cdf0e10cSrcweir 
710cdf0e10cSrcweir 			ResetError();
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 			Invalidate();
713cdf0e10cSrcweir 			break;
714cdf0e10cSrcweir 		}
715cdf0e10cSrcweir 
716cdf0e10cSrcweir 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
717cdf0e10cSrcweir 
718cdf0e10cSrcweir 		case SID_CLOSEDOC:
719cdf0e10cSrcweir 		{
720cdf0e10cSrcweir 			SfxViewFrame *pFrame = GetFrame();
721cdf0e10cSrcweir 			if ( pFrame && pFrame->GetFrame().GetParentFrame() )
722cdf0e10cSrcweir 			{
723cdf0e10cSrcweir 				// Wenn SID_CLOSEDOC "uber Menue etc. ausgef"uhrt wird, das
724cdf0e10cSrcweir 				// aktuelle Dokument aber in einem Frame liegt, soll eigentlich
725cdf0e10cSrcweir 				// das FrameSetDocument geclosed werden
726cdf0e10cSrcweir 				pFrame->GetTopViewFrame()->GetObjectShell()->ExecuteSlot( rReq );
727cdf0e10cSrcweir                 rReq.Done();
728cdf0e10cSrcweir 				return;
729cdf0e10cSrcweir 			}
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 			sal_Bool bInFrameSet = sal_False;
732cdf0e10cSrcweir 			sal_uInt16 nFrames=0;
733cdf0e10cSrcweir 			pFrame = SfxViewFrame::GetFirst( this );
734cdf0e10cSrcweir 			while ( pFrame )
735cdf0e10cSrcweir 			{
736cdf0e10cSrcweir 				if ( pFrame->GetFrame().GetParentFrame() )
737cdf0e10cSrcweir 				{
738cdf0e10cSrcweir 					// Auf dieses Dokument existiert noch eine Sicht, die
739cdf0e10cSrcweir 					// in einem FrameSet liegt; diese darf nat"urlich nicht
740cdf0e10cSrcweir 					// geclosed werden
741cdf0e10cSrcweir 					bInFrameSet = sal_True;
742cdf0e10cSrcweir 				}
743cdf0e10cSrcweir 				else
744cdf0e10cSrcweir 					nFrames++;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 				pFrame = SfxViewFrame::GetNext( *pFrame, this );
747cdf0e10cSrcweir 			}
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 			if ( bInFrameSet )
750cdf0e10cSrcweir 			{
751cdf0e10cSrcweir 				// Alle Sichten, die nicht in einem FrameSet liegen, closen
752cdf0e10cSrcweir 				pFrame = SfxViewFrame::GetFirst( this );
753cdf0e10cSrcweir 				while ( pFrame )
754cdf0e10cSrcweir 				{
755cdf0e10cSrcweir 					if ( !pFrame->GetFrame().GetParentFrame() )
756cdf0e10cSrcweir 						pFrame->GetFrame().DoClose();
757cdf0e10cSrcweir 					pFrame = SfxViewFrame::GetNext( *pFrame, this );
758cdf0e10cSrcweir 				}
759cdf0e10cSrcweir 			}
760cdf0e10cSrcweir 
761cdf0e10cSrcweir 			// Parameter auswerten
762cdf0e10cSrcweir 			SFX_REQUEST_ARG(rReq, pSaveItem, SfxBoolItem, SID_CLOSEDOC_SAVE, sal_False);
763cdf0e10cSrcweir 			SFX_REQUEST_ARG(rReq, pNameItem, SfxStringItem, SID_CLOSEDOC_FILENAME, sal_False);
764cdf0e10cSrcweir 			if ( pSaveItem )
765cdf0e10cSrcweir 			{
766cdf0e10cSrcweir 				if ( pSaveItem->GetValue() )
767cdf0e10cSrcweir 				{
768cdf0e10cSrcweir 					if ( !pNameItem )
769cdf0e10cSrcweir 					{
770cdf0e10cSrcweir 						SbxBase::SetError( SbxERR_WRONG_ARGS );
771cdf0e10cSrcweir 						rReq.Ignore();
772cdf0e10cSrcweir 						return;
773cdf0e10cSrcweir 					}
774cdf0e10cSrcweir 					SfxAllItemSet aArgs( GetPool() );
775cdf0e10cSrcweir 					SfxStringItem aTmpItem( SID_FILE_NAME, pNameItem->GetValue() );
776cdf0e10cSrcweir 					aArgs.Put( aTmpItem, aTmpItem.Which() );
777cdf0e10cSrcweir 					SfxRequest aSaveAsReq( SID_SAVEASDOC, SFX_CALLMODE_API, aArgs );
778cdf0e10cSrcweir 					ExecFile_Impl( aSaveAsReq );
779cdf0e10cSrcweir 					if ( !aSaveAsReq.IsDone() )
780cdf0e10cSrcweir 					{
781cdf0e10cSrcweir 						rReq.Ignore();
782cdf0e10cSrcweir 						return;
783cdf0e10cSrcweir 					}
784cdf0e10cSrcweir 				}
785cdf0e10cSrcweir 				else
786cdf0e10cSrcweir 					SetModified(sal_False);
787cdf0e10cSrcweir 			}
788cdf0e10cSrcweir 
789cdf0e10cSrcweir 			// Benutzer bricht ab?
790cdf0e10cSrcweir             if ( !PrepareClose( 2 ) )
791cdf0e10cSrcweir 			{
792cdf0e10cSrcweir 				rReq.SetReturnValue( SfxBoolItem(0, sal_False) );
793cdf0e10cSrcweir 				rReq.Done();
794cdf0e10cSrcweir 				return;
795cdf0e10cSrcweir 			}
796cdf0e10cSrcweir 
797cdf0e10cSrcweir             SetModified( sal_False );
798cdf0e10cSrcweir             sal_uIntPtr lErr = GetErrorCode();
799cdf0e10cSrcweir 			ErrorHandler::HandleError(lErr);
800cdf0e10cSrcweir 
801cdf0e10cSrcweir 			rReq.SetReturnValue( SfxBoolItem(0, sal_True) );
802cdf0e10cSrcweir 			rReq.Done();
803cdf0e10cSrcweir 			rReq.ReleaseArgs(); // da der Pool in Close zerst"ort wird
804cdf0e10cSrcweir             DoClose();
805cdf0e10cSrcweir 			return;
806cdf0e10cSrcweir 		}
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
809cdf0e10cSrcweir 		case SID_DOCTEMPLATE:
810cdf0e10cSrcweir 		{
811cdf0e10cSrcweir 			// speichern als Dokumentvorlagen
812cdf0e10cSrcweir 			SfxDocumentTemplateDlg *pDlg = 0;
813cdf0e10cSrcweir 			SfxErrorContext aEc(ERRCTX_SFX_DOCTEMPLATE,GetTitle());
814cdf0e10cSrcweir 			SfxDocumentTemplates *pTemplates =  new SfxDocumentTemplates;
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 			if ( !rReq.GetArgs() )
817cdf0e10cSrcweir 			{
818cdf0e10cSrcweir 				pDlg = new SfxDocumentTemplateDlg(0, pTemplates);
819cdf0e10cSrcweir 				if ( RET_OK == pDlg->Execute() && pDlg->GetTemplateName().Len())
820cdf0e10cSrcweir 				{
821cdf0e10cSrcweir 					rReq.AppendItem(SfxStringItem(
822cdf0e10cSrcweir 						SID_TEMPLATE_NAME, pDlg->GetTemplateName()));
823cdf0e10cSrcweir 					rReq.AppendItem(SfxStringItem(
824cdf0e10cSrcweir 						SID_TEMPLATE_REGIONNAME, pDlg->GetRegionName()));
825cdf0e10cSrcweir 				}
826cdf0e10cSrcweir 				else
827cdf0e10cSrcweir 				{
828cdf0e10cSrcweir 					delete pDlg;
829cdf0e10cSrcweir 					rReq.Ignore();
830cdf0e10cSrcweir 					return;
831cdf0e10cSrcweir 				}
832cdf0e10cSrcweir 			}
833cdf0e10cSrcweir 
834cdf0e10cSrcweir 			SFX_REQUEST_ARG(rReq, pRegionItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, sal_False);
835cdf0e10cSrcweir 			SFX_REQUEST_ARG(rReq, pNameItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
836cdf0e10cSrcweir 			SFX_REQUEST_ARG(rReq, pRegionNrItem, SfxUInt16Item, SID_TEMPLATE_REGION, sal_False);
837cdf0e10cSrcweir 			if ( (!pRegionItem && !pRegionNrItem ) || !pNameItem )
838cdf0e10cSrcweir 			{
839cdf0e10cSrcweir 				DBG_ASSERT( rReq.IsAPI(), "non-API call without Arguments" );
840cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_WRONG_ARGS );
841cdf0e10cSrcweir 				rReq.Ignore();
842cdf0e10cSrcweir 				return;
843cdf0e10cSrcweir 			}
844cdf0e10cSrcweir 
845cdf0e10cSrcweir 			::rtl::OUString aTemplateName = pNameItem->GetValue();
846cdf0e10cSrcweir 			::rtl::OUString aTemplateGroup;
847cdf0e10cSrcweir 			if ( pRegionItem )
848cdf0e10cSrcweir 				aTemplateGroup = pRegionItem->GetValue();
849cdf0e10cSrcweir 			else
850cdf0e10cSrcweir 				// pRegionNrItem must not be NULL, it was just checked
851cdf0e10cSrcweir 				aTemplateGroup = pTemplates->GetFullRegionName( pRegionNrItem->GetValue() );
852cdf0e10cSrcweir 			// check Group and Name
853cdf0e10cSrcweir 			delete pTemplates;
854cdf0e10cSrcweir 
855cdf0e10cSrcweir 			sal_Bool bOk = sal_False;
856cdf0e10cSrcweir 			try
857cdf0e10cSrcweir 			{
858cdf0e10cSrcweir 				uno::Reference< frame::XStorable > xStorable( GetModel(), uno::UNO_QUERY_THROW );
859cdf0e10cSrcweir     			::rtl::OUString aService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.DocumentTemplates" ) );
860cdf0e10cSrcweir     			uno::Reference< frame::XDocumentTemplates > xTemplates(
861cdf0e10cSrcweir 								comphelper::getProcessServiceFactory()->createInstance( aService ),
862cdf0e10cSrcweir 								uno::UNO_QUERY_THROW );
863cdf0e10cSrcweir 
864cdf0e10cSrcweir 				bOk = xTemplates->storeTemplate( aTemplateGroup, aTemplateName, xStorable );
865cdf0e10cSrcweir 			}
866cdf0e10cSrcweir 			catch( uno::Exception& )
867cdf0e10cSrcweir 			{
868cdf0e10cSrcweir 			}
869cdf0e10cSrcweir 
870cdf0e10cSrcweir 			DELETEX(pDlg);
871cdf0e10cSrcweir 
872cdf0e10cSrcweir 			rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
873cdf0e10cSrcweir 			if ( bOk )
874cdf0e10cSrcweir 			{
875cdf0e10cSrcweir 				// update the Organizer runtime cache from the template component if the cache has already been created
876cdf0e10cSrcweir 				// TODO/LATER: get rid of this cache duplication
877cdf0e10cSrcweir 				SfxDocumentTemplates aTemplates;
878cdf0e10cSrcweir 				aTemplates.ReInitFromComponent();
879cdf0e10cSrcweir 			}
880cdf0e10cSrcweir 			else
881cdf0e10cSrcweir 			{
882cdf0e10cSrcweir 				ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
883cdf0e10cSrcweir 				return;
884cdf0e10cSrcweir 			}
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 			break;
887cdf0e10cSrcweir 		}
888cdf0e10cSrcweir 	}
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 	// Picklisten-Eintrag verhindern
891cdf0e10cSrcweir 	if ( rReq.IsAPI() )
892cdf0e10cSrcweir 		GetMedium()->SetUpdatePickList( sal_False );
893cdf0e10cSrcweir 	else if ( rReq.GetArgs() )
894cdf0e10cSrcweir 	{
895cdf0e10cSrcweir 		SFX_ITEMSET_GET( *rReq.GetArgs(), pPicklistItem, SfxBoolItem, SID_PICKLIST, sal_False );
896cdf0e10cSrcweir 		if ( pPicklistItem )
897cdf0e10cSrcweir 			GetMedium()->SetUpdatePickList( pPicklistItem->GetValue() );
898cdf0e10cSrcweir 	}
899cdf0e10cSrcweir 
900cdf0e10cSrcweir 	// Ignore()-Zweige haben schon returnt
901cdf0e10cSrcweir 	rReq.Done();
902cdf0e10cSrcweir }
903cdf0e10cSrcweir 
904cdf0e10cSrcweir //-------------------------------------------------------------------------
905cdf0e10cSrcweir 
906cdf0e10cSrcweir void SfxObjectShell::GetState_Impl(SfxItemSet &rSet)
907cdf0e10cSrcweir {
908cdf0e10cSrcweir 	DBG_CHKTHIS(SfxObjectShell, 0);
909cdf0e10cSrcweir 	SfxWhichIter aIter( rSet );
910cdf0e10cSrcweir 
911cdf0e10cSrcweir 	for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
912cdf0e10cSrcweir 	{
913cdf0e10cSrcweir 		switch ( nWhich )
914cdf0e10cSrcweir 		{
915cdf0e10cSrcweir 			case SID_DOCTEMPLATE :
916cdf0e10cSrcweir 			{
917cdf0e10cSrcweir 				if ( !GetFactory().GetTemplateFilter() )
918cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
919cdf0e10cSrcweir 				break;
920cdf0e10cSrcweir 			}
921cdf0e10cSrcweir 
922cdf0e10cSrcweir 			case SID_VERSION:
923cdf0e10cSrcweir 				{
924cdf0e10cSrcweir 					SfxObjectShell *pDoc = this;
925cdf0e10cSrcweir 					SfxViewFrame* pFrame = GetFrame();
926cdf0e10cSrcweir 					if ( !pFrame )
927cdf0e10cSrcweir 						pFrame = SfxViewFrame::GetFirst( this );
928cdf0e10cSrcweir                     if ( pFrame  )
929cdf0e10cSrcweir 					{
930cdf0e10cSrcweir 						if ( pFrame->GetFrame().GetParentFrame() )
931cdf0e10cSrcweir 						{
932cdf0e10cSrcweir 							pFrame = pFrame->GetTopViewFrame();
933cdf0e10cSrcweir 							pDoc = pFrame->GetObjectShell();
934cdf0e10cSrcweir 						}
935cdf0e10cSrcweir 					}
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 					if ( !pFrame || !pDoc->HasName() ||
938cdf0e10cSrcweir 						!IsOwnStorageFormat_Impl( *pDoc->GetMedium() ) )
939cdf0e10cSrcweir //REMOVE							|| pDoc->GetMedium()->GetStorage()->GetVersion() < SOFFICE_FILEFORMAT_50 )
940cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
941cdf0e10cSrcweir 					break;
942cdf0e10cSrcweir 				}
943cdf0e10cSrcweir 			case SID_SAVEDOC:
944cdf0e10cSrcweir 	            {
945cdf0e10cSrcweir 					sal_Bool bMediumRO = IsReadOnlyMedium();
946cdf0e10cSrcweir                     if ( !bMediumRO && GetMedium() && IsModified() )
947cdf0e10cSrcweir 						rSet.Put(SfxStringItem(
948cdf0e10cSrcweir 							nWhich, String(SfxResId(STR_SAVEDOC))));
949cdf0e10cSrcweir 					else
950cdf0e10cSrcweir                     	rSet.DisableItem(nWhich);
951cdf0e10cSrcweir 				}
952cdf0e10cSrcweir 				break;
953cdf0e10cSrcweir 
954cdf0e10cSrcweir 			case SID_DOCINFO:
955cdf0e10cSrcweir 				if ( 0 != ( pImp->eFlags & SFXOBJECTSHELL_NODOCINFO ) )
956cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
957cdf0e10cSrcweir 				break;
958cdf0e10cSrcweir 
959cdf0e10cSrcweir 			case SID_CLOSEDOC:
960cdf0e10cSrcweir 			{
961cdf0e10cSrcweir 				SfxObjectShell *pDoc = this;
962cdf0e10cSrcweir 				SfxViewFrame *pFrame = GetFrame();
963cdf0e10cSrcweir 				if ( pFrame && pFrame->GetFrame().GetParentFrame() )
964cdf0e10cSrcweir 				{
965cdf0e10cSrcweir 					// Wenn SID_CLOSEDOC "uber Menue etc. ausgef"uhrt wird, das
966cdf0e10cSrcweir 					// aktuelle Dokument aber in einem Frame liegt, soll eigentlich
967cdf0e10cSrcweir 					// das FrameSetDocument geclosed werden
968cdf0e10cSrcweir 					pDoc = pFrame->GetTopViewFrame()->GetObjectShell();
969cdf0e10cSrcweir 				}
970cdf0e10cSrcweir 
971cdf0e10cSrcweir 				if ( pDoc->GetFlags() & SFXOBJECTSHELL_DONTCLOSE )
972cdf0e10cSrcweir 					rSet.DisableItem(nWhich);
973cdf0e10cSrcweir                 else
974cdf0e10cSrcweir 					rSet.Put(SfxStringItem(nWhich, String(SfxResId(STR_CLOSEDOC))));
975cdf0e10cSrcweir 				break;
976cdf0e10cSrcweir 			}
977cdf0e10cSrcweir 
978cdf0e10cSrcweir 			case SID_SAVEASDOC:
979cdf0e10cSrcweir 			{
980cdf0e10cSrcweir 				if( ( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) != SFX_LOADED_MAINDOCUMENT )
981cdf0e10cSrcweir 				{
982cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
983cdf0e10cSrcweir 					break;
984cdf0e10cSrcweir 				}
985cdf0e10cSrcweir /*
986cdf0e10cSrcweir 				const SfxFilter* pCombinedFilters = NULL;
987cdf0e10cSrcweir 				SfxFilterContainer* pFilterContainer = GetFactory().GetFilterContainer();
988cdf0e10cSrcweir 
989cdf0e10cSrcweir 				if ( pFilterContainer )
990cdf0e10cSrcweir 				{
991cdf0e10cSrcweir 					SfxFilterFlags    nMust    = SFX_FILTER_IMPORT | SFX_FILTER_EXPORT;
992cdf0e10cSrcweir     				SfxFilterFlags    nDont    = SFX_FILTER_NOTINSTALLED | SFX_FILTER_INTERNAL;
993cdf0e10cSrcweir 
994cdf0e10cSrcweir 					pCombinedFilters = pFilterContainer->GetAnyFilter( nMust, nDont );
995cdf0e10cSrcweir 				}
996cdf0e10cSrcweir */
997cdf0e10cSrcweir 				if ( /*!pCombinedFilters ||*/ !GetMedium() )
998cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
999cdf0e10cSrcweir                 else
1000cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, String( SfxResId( STR_SAVEASDOC ) ) ) );
1001cdf0e10cSrcweir 				break;
1002cdf0e10cSrcweir 			}
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir 			case SID_EXPORTDOCASPDF:
1005cdf0e10cSrcweir 			case SID_DIRECTEXPORTDOCASPDF:
1006cdf0e10cSrcweir 			{
1007cdf0e10cSrcweir     			/*
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir     			 search for filter cant work correctly ...
1010cdf0e10cSrcweir     			 Because it's not clear, which export filter for which office module
1011cdf0e10cSrcweir                  must be searched. On the other side it can be very expensive doing so.
1012cdf0e10cSrcweir                  The best solution would be: on installation time we should know if pdf feature
1013cdf0e10cSrcweir                  was installed or not!!! (e.g. by writing a bool inside cfg)
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir 				SfxFilterContainer* pFilterContainer = GetFactory().GetFilterContainer();
1016cdf0e10cSrcweir 				if ( pFilterContainer )
1017cdf0e10cSrcweir 				{
1018cdf0e10cSrcweir 					String aPDFExtension = String::CreateFromAscii( "pdf" );
1019cdf0e10cSrcweir 					const SfxFilter* pFilter = pFilterContainer->GetFilter4Extension( aPDFExtension, SFX_FILTER_EXPORT );
1020cdf0e10cSrcweir 					if ( pFilter != NULL )
1021cdf0e10cSrcweir 						break;
1022cdf0e10cSrcweir 				}
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir 				rSet.DisableItem( nWhich );
1025cdf0e10cSrcweir 				*/
1026cdf0e10cSrcweir 				break;
1027cdf0e10cSrcweir 			}
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir 			case SID_DOC_MODIFIED:
1030cdf0e10cSrcweir 			{
1031cdf0e10cSrcweir 				rSet.Put( SfxStringItem( SID_DOC_MODIFIED, IsModified() ? '*' : ' ' ) );
1032cdf0e10cSrcweir 				break;
1033cdf0e10cSrcweir 			}
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 			case SID_MODIFIED:
1036cdf0e10cSrcweir 			{
1037cdf0e10cSrcweir 				rSet.Put( SfxBoolItem( SID_MODIFIED, IsModified() ) );
1038cdf0e10cSrcweir 				break;
1039cdf0e10cSrcweir 			}
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir 			case SID_DOCINFO_TITLE:
1042cdf0e10cSrcweir 			{
1043cdf0e10cSrcweir 				rSet.Put( SfxStringItem(
1044cdf0e10cSrcweir 					SID_DOCINFO_TITLE, getDocProperties()->getTitle() ) );
1045cdf0e10cSrcweir 				break;
1046cdf0e10cSrcweir 			}
1047cdf0e10cSrcweir 			case SID_FILE_NAME:
1048cdf0e10cSrcweir 			{
1049cdf0e10cSrcweir 				if( GetMedium() && HasName() )
1050cdf0e10cSrcweir 					rSet.Put( SfxStringItem(
1051cdf0e10cSrcweir 						SID_FILE_NAME, GetMedium()->GetName() ) );
1052cdf0e10cSrcweir 				break;
1053cdf0e10cSrcweir 			}
1054cdf0e10cSrcweir             case SID_SIGNATURE:
1055cdf0e10cSrcweir             {
1056cdf0e10cSrcweir                 rSet.Put( SfxUInt16Item( SID_SIGNATURE, GetDocumentSignatureState() ) );
1057cdf0e10cSrcweir                 break;
1058cdf0e10cSrcweir             }
1059cdf0e10cSrcweir             case SID_MACRO_SIGNATURE:
1060cdf0e10cSrcweir             {
1061cdf0e10cSrcweir                 // the slot makes sense only if there is a macro in the document
1062cdf0e10cSrcweir                 if ( pImp->documentStorageHasMacros() || pImp->aMacroMode.hasMacroLibrary() )
1063cdf0e10cSrcweir                     rSet.Put( SfxUInt16Item( SID_MACRO_SIGNATURE, GetScriptingSignatureState() ) );
1064cdf0e10cSrcweir                 else
1065cdf0e10cSrcweir                     rSet.DisableItem( nWhich );
1066cdf0e10cSrcweir                 break;
1067cdf0e10cSrcweir             }
1068cdf0e10cSrcweir 		}
1069cdf0e10cSrcweir 	}
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir //--------------------------------------------------------------------
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir void SfxObjectShell::ExecProps_Impl(SfxRequest &rReq)
1075cdf0e10cSrcweir {
1076cdf0e10cSrcweir 	switch ( rReq.GetSlot() )
1077cdf0e10cSrcweir 	{
1078cdf0e10cSrcweir 		case SID_MODIFIED:
1079cdf0e10cSrcweir 		{
1080cdf0e10cSrcweir 			SetModified( ( (SfxBoolItem&) rReq.GetArgs()->Get(SID_MODIFIED)).GetValue() );
1081cdf0e10cSrcweir 			rReq.Done();
1082cdf0e10cSrcweir 			break;
1083cdf0e10cSrcweir 		}
1084cdf0e10cSrcweir 
1085cdf0e10cSrcweir 		case SID_DOCTITLE:
1086cdf0e10cSrcweir 			SetTitle( ( (SfxStringItem&) rReq.GetArgs()->Get(SID_DOCTITLE)).GetValue() );
1087cdf0e10cSrcweir 			rReq.Done();
1088cdf0e10cSrcweir 			break;
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir 		case SID_DOCINFO_AUTHOR :
1091cdf0e10cSrcweir 		{
1092cdf0e10cSrcweir 			::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
1093cdf0e10cSrcweir 			getDocProperties()->setAuthor( aStr );
1094cdf0e10cSrcweir 			break;
1095cdf0e10cSrcweir 		}
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir 		case SID_DOCINFO_COMMENTS :
1098cdf0e10cSrcweir 		{
1099cdf0e10cSrcweir 			::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
1100cdf0e10cSrcweir 			getDocProperties()->setDescription( aStr );
1101cdf0e10cSrcweir 			break;
1102cdf0e10cSrcweir 		}
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 		case SID_DOCINFO_KEYWORDS :
1105cdf0e10cSrcweir 		{
1106cdf0e10cSrcweir 			::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
1107cdf0e10cSrcweir 			getDocProperties()->setKeywords(
1108cdf0e10cSrcweir                 ::comphelper::string::convertCommaSeparated(aStr) );
1109cdf0e10cSrcweir 			break;
1110cdf0e10cSrcweir 		}
1111cdf0e10cSrcweir 	}
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir //--------------------------------------------------------------------
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir void SfxObjectShell::StateProps_Impl(SfxItemSet &rSet)
1117cdf0e10cSrcweir {
1118cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
1119cdf0e10cSrcweir 	for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
1120cdf0e10cSrcweir 	{
1121cdf0e10cSrcweir 		switch ( nSID )
1122cdf0e10cSrcweir 		{
1123cdf0e10cSrcweir 			case SID_DOCINFO_AUTHOR :
1124cdf0e10cSrcweir 			{
1125cdf0e10cSrcweir 				rSet.Put( SfxStringItem( nSID,
1126cdf0e10cSrcweir                             getDocProperties()->getAuthor() ) );
1127cdf0e10cSrcweir 				break;
1128cdf0e10cSrcweir 			}
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 			case SID_DOCINFO_COMMENTS :
1131cdf0e10cSrcweir 			{
1132cdf0e10cSrcweir 				rSet.Put( SfxStringItem( nSID,
1133cdf0e10cSrcweir                             getDocProperties()->getDescription()) );
1134cdf0e10cSrcweir 				break;
1135cdf0e10cSrcweir 			}
1136cdf0e10cSrcweir 
1137cdf0e10cSrcweir 			case SID_DOCINFO_KEYWORDS :
1138cdf0e10cSrcweir 			{
1139cdf0e10cSrcweir 				rSet.Put( SfxStringItem( nSID, ::comphelper::string::
1140cdf0e10cSrcweir                     convertCommaSeparated(getDocProperties()->getKeywords())) );
1141cdf0e10cSrcweir 				break;
1142cdf0e10cSrcweir 			}
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir 			case SID_DOCPATH:
1145cdf0e10cSrcweir 			{
1146cdf0e10cSrcweir                 DBG_ERROR( "Not supported anymore!" );
1147cdf0e10cSrcweir 				break;
1148cdf0e10cSrcweir 			}
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir 			case SID_DOCFULLNAME:
1151cdf0e10cSrcweir 			{
1152cdf0e10cSrcweir 				rSet.Put( SfxStringItem( SID_DOCFULLNAME, GetTitle(SFX_TITLE_FULLNAME) ) );
1153cdf0e10cSrcweir 				break;
1154cdf0e10cSrcweir 			}
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir 			case SID_DOCTITLE:
1157cdf0e10cSrcweir 			{
1158cdf0e10cSrcweir 				rSet.Put( SfxStringItem( SID_DOCTITLE, GetTitle() ) );
1159cdf0e10cSrcweir 				break;
1160cdf0e10cSrcweir 			}
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 			case SID_DOC_READONLY:
1163cdf0e10cSrcweir 			{
1164cdf0e10cSrcweir 				rSet.Put( SfxBoolItem( SID_DOC_READONLY, IsReadOnly() ) );
1165cdf0e10cSrcweir 				break;
1166cdf0e10cSrcweir 			}
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir 			case SID_DOC_SAVED:
1169cdf0e10cSrcweir 			{
1170cdf0e10cSrcweir 				rSet.Put( SfxBoolItem( SID_DOC_SAVED, !IsModified() ) );
1171cdf0e10cSrcweir 				break;
1172cdf0e10cSrcweir 			}
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir 			case SID_CLOSING:
1175cdf0e10cSrcweir 			{
1176cdf0e10cSrcweir 				rSet.Put( SfxBoolItem( SID_CLOSING, false ) );
1177cdf0e10cSrcweir 				break;
1178cdf0e10cSrcweir 			}
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir 			case SID_DOC_LOADING:
1181cdf0e10cSrcweir 				rSet.Put( SfxBoolItem( nSID, SFX_LOADED_MAINDOCUMENT !=
1182cdf0e10cSrcweir 							( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) ) );
1183cdf0e10cSrcweir 				break;
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir 			case SID_IMG_LOADING:
1186cdf0e10cSrcweir 				rSet.Put( SfxBoolItem( nSID, SFX_LOADED_IMAGES !=
1187cdf0e10cSrcweir 							( pImp->nLoadedFlags & SFX_LOADED_IMAGES ) ) );
1188cdf0e10cSrcweir 				break;
1189cdf0e10cSrcweir 		}
1190cdf0e10cSrcweir 	}
1191cdf0e10cSrcweir }
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir //--------------------------------------------------------------------
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir void SfxObjectShell::ExecView_Impl(SfxRequest &rReq)
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir 	switch ( rReq.GetSlot() )
1198cdf0e10cSrcweir 	{
1199cdf0e10cSrcweir 		case SID_ACTIVATE:
1200cdf0e10cSrcweir 		{
1201cdf0e10cSrcweir 			SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this, sal_True );
1202cdf0e10cSrcweir 			if ( pFrame )
1203cdf0e10cSrcweir 				pFrame->GetFrame().Appear();
1204cdf0e10cSrcweir 			rReq.SetReturnValue( SfxObjectItem( 0, pFrame ) );
1205cdf0e10cSrcweir 			rReq.Done();
1206cdf0e10cSrcweir 			break;
1207cdf0e10cSrcweir 		}
1208cdf0e10cSrcweir 		case SID_NEWWINDOWFOREDIT:
1209cdf0e10cSrcweir 		{
1210cdf0e10cSrcweir 			SfxViewFrame* pFrame = SfxViewFrame::Current();
1211cdf0e10cSrcweir 			if( pFrame->GetObjectShell() == this &&
1212cdf0e10cSrcweir 				( pFrame->GetFrameType() & SFXFRAME_HASTITLE ) )
1213cdf0e10cSrcweir 				pFrame->ExecuteSlot( rReq );
1214cdf0e10cSrcweir 			else
1215cdf0e10cSrcweir 			{
1216cdf0e10cSrcweir 				String aFileName( GetObjectShell()->GetMedium()->GetName() );
1217cdf0e10cSrcweir 				if ( aFileName.Len() )
1218cdf0e10cSrcweir 				{
1219cdf0e10cSrcweir 					SfxStringItem aName( SID_FILE_NAME, aFileName );
1220cdf0e10cSrcweir 					SfxBoolItem aCreateView( SID_OPEN_NEW_VIEW, sal_True );
1221cdf0e10cSrcweir                     SFX_APP()->GetAppDispatcher_Impl()->Execute(
1222cdf0e10cSrcweir 						SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aName,
1223cdf0e10cSrcweir 						&aCreateView, 0L);
1224cdf0e10cSrcweir 				}
1225cdf0e10cSrcweir 			}
1226cdf0e10cSrcweir 		}
1227cdf0e10cSrcweir 	}
1228cdf0e10cSrcweir }
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir //--------------------------------------------------------------------
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir void SfxObjectShell::StateView_Impl(SfxItemSet& /*rSet*/)
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir sal_uInt16 SfxObjectShell::ImplCheckSignaturesInformation( const uno::Sequence< security::DocumentSignatureInformation >& aInfos )
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir 	sal_Bool bCertValid = sal_True;
1239cdf0e10cSrcweir 	sal_uInt16 nResult = SIGNATURESTATE_NOSIGNATURES;
1240cdf0e10cSrcweir 	int nInfos = aInfos.getLength();
1241cdf0e10cSrcweir     bool bCompleteSignature = true;
1242cdf0e10cSrcweir 	if( nInfos )
1243cdf0e10cSrcweir 	{
1244cdf0e10cSrcweir         nResult = SIGNATURESTATE_SIGNATURES_OK;
1245cdf0e10cSrcweir 		for ( int n = 0; n < nInfos; n++ )
1246cdf0e10cSrcweir 		{
1247cdf0e10cSrcweir             if ( bCertValid )
1248cdf0e10cSrcweir             {
1249cdf0e10cSrcweir                 sal_Int32 nCertStat = aInfos[n].CertificateStatus;
1250cdf0e10cSrcweir                 bCertValid = nCertStat == security::CertificateValidity::VALID ? sal_True : sal_False;
1251cdf0e10cSrcweir             }
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir 			if ( !aInfos[n].SignatureIsValid )
1254cdf0e10cSrcweir 			{
1255cdf0e10cSrcweir 				nResult = SIGNATURESTATE_SIGNATURES_BROKEN;
1256cdf0e10cSrcweir 				break; // we know enough
1257cdf0e10cSrcweir 			}
1258cdf0e10cSrcweir             bCompleteSignature &= !aInfos[n].PartialDocumentSignature;
1259cdf0e10cSrcweir 		}
1260cdf0e10cSrcweir 	}
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir     if ( nResult == SIGNATURESTATE_SIGNATURES_OK && !bCertValid )
1263cdf0e10cSrcweir         nResult = SIGNATURESTATE_SIGNATURES_NOTVALIDATED;
1264cdf0e10cSrcweir     else if ( nResult == SIGNATURESTATE_SIGNATURES_OK && bCertValid && !bCompleteSignature)
1265cdf0e10cSrcweir         nResult = SIGNATURESTATE_SIGNATURES_PARTIAL_OK;
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir 	// this code must not check whether the document is modified
1268cdf0e10cSrcweir 	// it should only check the provided info
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir 	return nResult;
1271cdf0e10cSrcweir }
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir uno::Sequence< security::DocumentSignatureInformation > SfxObjectShell::ImplAnalyzeSignature( sal_Bool bScriptingContent, const uno::Reference< security::XDocumentDigitalSignatures >& xSigner )
1274cdf0e10cSrcweir {
1275cdf0e10cSrcweir     uno::Sequence< security::DocumentSignatureInformation > aResult;
1276cdf0e10cSrcweir     uno::Reference< security::XDocumentDigitalSignatures > xLocSigner = xSigner;
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir     if ( GetMedium() && GetMedium()->GetName().Len() && IsOwnStorageFormat_Impl( *GetMedium())  && GetMedium()->GetStorage().is() )
1279cdf0e10cSrcweir     {
1280cdf0e10cSrcweir         try
1281cdf0e10cSrcweir         {
1282cdf0e10cSrcweir             if ( !xLocSigner.is() )
1283cdf0e10cSrcweir             {
1284cdf0e10cSrcweir                 uno::Sequence< uno::Any > aArgs( 1 );
1285cdf0e10cSrcweir                 aArgs[0] <<= ::rtl::OUString();
1286cdf0e10cSrcweir                 try
1287cdf0e10cSrcweir                 {
1288cdf0e10cSrcweir                     uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
1289cdf0e10cSrcweir                     aArgs[0] = xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) );
1290cdf0e10cSrcweir                 }
1291cdf0e10cSrcweir                 catch( uno::Exception& )
1292cdf0e10cSrcweir                 {
1293cdf0e10cSrcweir                 }
1294cdf0e10cSrcweir 
1295cdf0e10cSrcweir                 xLocSigner.set( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs ), uno::UNO_QUERY_THROW );
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir             }
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir             if ( bScriptingContent )
1300cdf0e10cSrcweir                 aResult = xLocSigner->verifyScriptingContentSignatures( GetMedium()->GetZipStorageToSign_Impl(),
1301cdf0e10cSrcweir                                                                 uno::Reference< io::XInputStream >() );
1302cdf0e10cSrcweir             else
1303cdf0e10cSrcweir                 aResult = xLocSigner->verifyDocumentContentSignatures( GetMedium()->GetZipStorageToSign_Impl(),
1304cdf0e10cSrcweir                                                                 uno::Reference< io::XInputStream >() );
1305cdf0e10cSrcweir         }
1306cdf0e10cSrcweir         catch( com::sun::star::uno::Exception& )
1307cdf0e10cSrcweir         {
1308cdf0e10cSrcweir         }
1309cdf0e10cSrcweir     }
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir     return aResult;
1312cdf0e10cSrcweir }
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir sal_uInt16 SfxObjectShell::ImplGetSignatureState( sal_Bool bScriptingContent )
1315cdf0e10cSrcweir {
1316cdf0e10cSrcweir     sal_Int16* pState = bScriptingContent ? &pImp->nScriptingSignatureState : &pImp->nDocumentSignatureState;
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir     if ( *pState == SIGNATURESTATE_UNKNOWN )
1319cdf0e10cSrcweir     {
1320cdf0e10cSrcweir         *pState = SIGNATURESTATE_NOSIGNATURES;
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir         uno::Sequence< security::DocumentSignatureInformation > aInfos = ImplAnalyzeSignature( bScriptingContent );
1323cdf0e10cSrcweir         *pState = ImplCheckSignaturesInformation( aInfos );
1324cdf0e10cSrcweir     }
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir     if ( *pState == SIGNATURESTATE_SIGNATURES_OK || *pState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
1327cdf0e10cSrcweir         || *pState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK)
1328cdf0e10cSrcweir     {
1329cdf0e10cSrcweir         if ( IsModified() )
1330cdf0e10cSrcweir             *pState = SIGNATURESTATE_SIGNATURES_INVALID;
1331cdf0e10cSrcweir     }
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir     return (sal_uInt16)*pState;
1334cdf0e10cSrcweir }
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir void SfxObjectShell::ImplSign( sal_Bool bScriptingContent )
1337cdf0e10cSrcweir {
1338cdf0e10cSrcweir     // Check if it is stored in OASIS format...
1339cdf0e10cSrcweir     if  (   GetMedium()
1340cdf0e10cSrcweir         &&  GetMedium()->GetFilter()
1341cdf0e10cSrcweir         &&  GetMedium()->GetName().Len()
1342cdf0e10cSrcweir         &&  (   !GetMedium()->GetFilter()->IsOwnFormat()
1343cdf0e10cSrcweir             ||  !GetMedium()->HasStorage_Impl()
1344cdf0e10cSrcweir             )
1345cdf0e10cSrcweir         )
1346cdf0e10cSrcweir     {
1347cdf0e10cSrcweir         // Only OASIS and OOo6.x formats will be handled further
1348cdf0e10cSrcweir         InfoBox( NULL, SfxResId( RID_XMLSEC_INFO_WRONGDOCFORMAT ) ).Execute();
1349cdf0e10cSrcweir         return;
1350cdf0e10cSrcweir     }
1351cdf0e10cSrcweir 
1352cdf0e10cSrcweir     // check whether the document is signed
1353cdf0e10cSrcweir     ImplGetSignatureState( sal_False ); // document signature
1354cdf0e10cSrcweir     ImplGetSignatureState( sal_True ); // script signature
1355cdf0e10cSrcweir     sal_Bool bHasSign = ( pImp->nScriptingSignatureState != SIGNATURESTATE_NOSIGNATURES || pImp->nDocumentSignatureState != SIGNATURESTATE_NOSIGNATURES );
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir     // the target ODF version on saving
1358cdf0e10cSrcweir     SvtSaveOptions aSaveOpt;
1359cdf0e10cSrcweir     SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion();
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir     // the document is not new and is not modified
1362cdf0e10cSrcweir     ::rtl::OUString aODFVersion;
1363cdf0e10cSrcweir     try
1364cdf0e10cSrcweir     {
1365cdf0e10cSrcweir         // check the version of the document
1366cdf0e10cSrcweir         uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
1367cdf0e10cSrcweir         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aODFVersion;
1368cdf0e10cSrcweir     }
1369cdf0e10cSrcweir     catch( uno::Exception& )
1370cdf0e10cSrcweir     {}
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir     bool bNoSig = false;
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir     if ( IsModified() || !GetMedium() || !GetMedium()->GetName().Len()
1375cdf0e10cSrcweir       || (!aODFVersion.equals( ODFVER_012_TEXT ) && !bHasSign) )
1376cdf0e10cSrcweir     {
1377cdf0e10cSrcweir         // the document might need saving ( new, modified or in ODF1.1 format without signature )
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir         if ( nVersion >= SvtSaveOptions::ODFVER_012 )
1380cdf0e10cSrcweir         {
1381cdf0e10cSrcweir 
1382cdf0e10cSrcweir             if ( (bHasSign && QueryBox( NULL, SfxResId( MSG_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN ) ).Execute() == RET_YES)
1383cdf0e10cSrcweir               || (!bHasSign && QueryBox( NULL, SfxResId( RID_XMLSEC_QUERY_SAVEBEFORESIGN ) ).Execute() == RET_YES) )
1384cdf0e10cSrcweir             {
1385cdf0e10cSrcweir                 sal_uInt16 nId = SID_SAVEDOC;
1386cdf0e10cSrcweir                 if ( !GetMedium() || !GetMedium()->GetName().Len() )
1387cdf0e10cSrcweir                     nId = SID_SAVEASDOC;
1388cdf0e10cSrcweir                 SfxRequest aSaveRequest( nId, 0, GetPool() );
1389cdf0e10cSrcweir                 //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved.
1390cdf0e10cSrcweir                 SetModified(sal_True);
1391cdf0e10cSrcweir                 ExecFile_Impl( aSaveRequest );
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir                 // Check if it is stored in OASIS format...
1394cdf0e10cSrcweir                 if ( GetMedium() && GetMedium()->GetFilter()
1395cdf0e10cSrcweir                   && ( !GetMedium()->GetFilter()->IsOwnFormat() || !GetMedium()->HasStorage_Impl()
1396cdf0e10cSrcweir                     || SotStorage::GetVersion( GetMedium()->GetStorage() ) <= SOFFICE_FILEFORMAT_60 ) )
1397cdf0e10cSrcweir                 {
1398cdf0e10cSrcweir                     // Only OASIS format will be handled further
1399cdf0e10cSrcweir                     InfoBox( NULL, SfxResId( RID_XMLSEC_INFO_WRONGDOCFORMAT ) ).Execute();
1400cdf0e10cSrcweir                     return;
1401cdf0e10cSrcweir                 }
1402cdf0e10cSrcweir             }
1403cdf0e10cSrcweir             else
1404cdf0e10cSrcweir             {
1405cdf0e10cSrcweir                 //When the document is modified then we must not show the digital signatures dialog
1406cdf0e10cSrcweir                 //If we have come here then the user denied to save.
1407cdf0e10cSrcweir                 if (!bHasSign)
1408cdf0e10cSrcweir                     bNoSig = true;
1409cdf0e10cSrcweir             }
1410cdf0e10cSrcweir         }
1411cdf0e10cSrcweir         else
1412cdf0e10cSrcweir         {
1413cdf0e10cSrcweir             ErrorBox( NULL, WB_OK, SfxResId( STR_XMLSEC_ODF12_EXPECTED ) ).Execute();
1414cdf0e10cSrcweir             return;
1415cdf0e10cSrcweir         }
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir         if ( IsModified() || !GetMedium() || !GetMedium()->GetName().Len() )
1418cdf0e10cSrcweir             return;
1419cdf0e10cSrcweir     }
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir 	// the document is not modified currently, so it can not become modified after signing
1422cdf0e10cSrcweir 	sal_Bool bAllowModifiedBack = sal_False;
1423cdf0e10cSrcweir 	if ( IsEnableSetModified() )
1424cdf0e10cSrcweir 	{
1425cdf0e10cSrcweir 		EnableSetModified( sal_False );
1426cdf0e10cSrcweir 		bAllowModifiedBack = sal_True;
1427cdf0e10cSrcweir 	}
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir     // we have to store to the original document, the original medium should be closed for this time
1430cdf0e10cSrcweir     if ( !bNoSig
1431cdf0e10cSrcweir       && ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
1432cdf0e10cSrcweir     {
1433cdf0e10cSrcweir         GetMedium()->CloseAndRelease();
1434cdf0e10cSrcweir 
1435cdf0e10cSrcweir         // We sign only ODF1.2, that means that if this point has been reached,
1436cdf0e10cSrcweir         // the ODF1.2 signing process should be used.
1437cdf0e10cSrcweir         // This code still might be called to show the signature of ODF1.1 document.
1438cdf0e10cSrcweir         sal_Bool bSigned = GetMedium()->SignContents_Impl(
1439cdf0e10cSrcweir             bScriptingContent,
1440cdf0e10cSrcweir             aODFVersion,
1441cdf0e10cSrcweir             pImp->nDocumentSignatureState == SIGNATURESTATE_SIGNATURES_OK
1442cdf0e10cSrcweir             || pImp->nDocumentSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
1443cdf0e10cSrcweir             || pImp->nDocumentSignatureState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK);
1444cdf0e10cSrcweir 
1445cdf0e10cSrcweir         DoSaveCompleted( GetMedium() );
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir         if ( bSigned )
1448cdf0e10cSrcweir         {
1449cdf0e10cSrcweir             if ( bScriptingContent )
1450cdf0e10cSrcweir             {
1451cdf0e10cSrcweir                 pImp->nScriptingSignatureState = SIGNATURESTATE_UNKNOWN;// Re-Check
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir                 // adding of scripting signature removes existing document signature
1454cdf0e10cSrcweir                 pImp->nDocumentSignatureState = SIGNATURESTATE_UNKNOWN;// Re-Check
1455cdf0e10cSrcweir             }
1456cdf0e10cSrcweir             else
1457cdf0e10cSrcweir                 pImp->nDocumentSignatureState = SIGNATURESTATE_UNKNOWN;// Re-Check
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir             pImp->bSignatureErrorIsShown = sal_False;
1460cdf0e10cSrcweir 
1461cdf0e10cSrcweir             Invalidate( SID_SIGNATURE );
1462cdf0e10cSrcweir             Invalidate( SID_MACRO_SIGNATURE );
1463cdf0e10cSrcweir             Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1464cdf0e10cSrcweir         }
1465cdf0e10cSrcweir     }
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir 	if ( bAllowModifiedBack )
1468cdf0e10cSrcweir 		EnableSetModified( sal_True );
1469cdf0e10cSrcweir }
1470cdf0e10cSrcweir 
1471cdf0e10cSrcweir sal_uInt16 SfxObjectShell::GetDocumentSignatureState()
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir     return ImplGetSignatureState( sal_False );
1474cdf0e10cSrcweir }
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir void SfxObjectShell::SignDocumentContent()
1477cdf0e10cSrcweir {
1478cdf0e10cSrcweir     ImplSign( sal_False );
1479cdf0e10cSrcweir }
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir sal_uInt16 SfxObjectShell::GetScriptingSignatureState()
1482cdf0e10cSrcweir {
1483cdf0e10cSrcweir     return ImplGetSignatureState( sal_True );
1484cdf0e10cSrcweir }
1485cdf0e10cSrcweir 
1486cdf0e10cSrcweir void SfxObjectShell::SignScriptingContent()
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir     ImplSign( sal_True );
1489cdf0e10cSrcweir }
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir // static
1492cdf0e10cSrcweir const uno::Sequence<sal_Int8>& SfxObjectShell::getUnoTunnelId()
1493cdf0e10cSrcweir {
1494cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> * pSeq = 0;
1495cdf0e10cSrcweir 	if( !pSeq )
1496cdf0e10cSrcweir 	{
1497cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1498cdf0e10cSrcweir 		if( !pSeq )
1499cdf0e10cSrcweir 		{
1500cdf0e10cSrcweir 			static uno::Sequence< sal_Int8 > aSeq( 16 );
1501cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1502cdf0e10cSrcweir 			pSeq = &aSeq;
1503cdf0e10cSrcweir 		}
1504cdf0e10cSrcweir 	}
1505cdf0e10cSrcweir 	return *pSeq;
1506cdf0e10cSrcweir }
1507