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