update dev300-m58
[ooovba.git] / sfx2 / source / doc / objserv.cxx
blobdb44c44ce515c03267177ddbe15cfcc147134bb2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objserv.cxx,v $
10 * $Revision: 1.106 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include <sot/storage.hxx>
35 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
37 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
38 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
39 #include <com/sun/star/ui/dialogs/XControlAccess.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/beans/XPropertyAccess.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/beans/PropertyValue.hpp>
44 #include <com/sun/star/container/XNameAccess.hpp>
45 #include <com/sun/star/document/XExporter.hpp>
46 #include <com/sun/star/task/XInteractionHandler.hpp>
47 #include <com/sun/star/task/XStatusIndicator.hpp>
48 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
49 #include <com/sun/star/frame/XDocumentTemplates.hpp>
50 #include <com/sun/star/frame/XStorable.hpp>
51 #include <comphelper/processfactory.hxx>
52 #include <com/sun/star/security/CertificateValidity.hpp>
54 #include <com/sun/star/security/DocumentSignatureInformation.hpp>
55 #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
56 #include <tools/urlobj.hxx>
57 #include <svtools/whiter.hxx>
58 #include <vcl/msgbox.hxx>
59 #include <svtools/intitem.hxx>
60 #include <svtools/eitem.hxx>
61 #include <vcl/wrkwin.hxx>
62 #include <svtools/sfxecode.hxx>
63 #include <svtools/ehdl.hxx>
65 #include <comphelper/string.hxx>
66 #include <basic/sbx.hxx>
67 #include <svtools/pathoptions.hxx>
68 #include <svtools/useroptions.hxx>
69 #include <svtools/asynclink.hxx>
70 #include <svtools/saveopt.hxx>
71 #include <comphelper/documentconstants.hxx>
73 #include <sfx2/app.hxx>
74 #include <sfx2/signaturestate.hxx>
75 #include "sfxresid.hxx"
76 #include <sfx2/event.hxx>
77 #include <sfx2/request.hxx>
78 #include <sfx2/printer.hxx>
79 #include <sfx2/viewsh.hxx>
80 #include <sfx2/doctdlg.hxx>
81 #include <sfx2/docfilt.hxx>
82 #include <sfx2/docfile.hxx>
83 #include <sfx2/dispatch.hxx>
84 #include <sfx2/dinfdlg.hxx>
85 #include <sfx2/objitem.hxx>
86 #include <sfx2/objsh.hxx>
87 #include "objshimp.hxx"
88 #include "sfxtypes.hxx"
89 //#include "interno.hxx"
90 #include <sfx2/module.hxx>
91 #include <sfx2/topfrm.hxx>
92 #include "versdlg.hxx"
93 #include "doc.hrc"
94 #include <sfx2/docfac.hxx>
95 #include <sfx2/fcontnr.hxx>
96 #include <sfx2/filedlghelper.hxx>
97 #include "sfxhelp.hxx"
98 #include <sfx2/msgpool.hxx>
99 #include <sfx2/objface.hxx>
101 #include "../appl/app.hrc"
102 #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
103 #include <com/sun/star/embed/XTransactedObject.hpp>
104 #include <com/sun/star/util/XCloneable.hpp>
105 #include <com/sun/star/document/XDocumentProperties.hpp>
106 #include <com/sun/star/document/XDocumentEventCompatibleHelper.hpp>
108 #include "helpid.hrc"
110 #include "guisaveas.hxx"
112 using namespace ::com::sun::star;
113 using namespace ::com::sun::star::lang;
114 using namespace ::com::sun::star::uno;
115 using namespace ::com::sun::star::ui::dialogs;
116 using namespace ::com::sun::star::awt;
117 using namespace ::com::sun::star::container;
118 using namespace ::com::sun::star::beans;
119 using namespace ::com::sun::star::document;
120 using namespace ::com::sun::star::task;
122 //====================================================================
124 class SfxSaveAsContext_Impl
126 String& _rNewNameVar;
127 String _aNewName;
129 public:
130 SfxSaveAsContext_Impl( String &rNewNameVar,
131 const String &rNewName )
132 : _rNewNameVar( rNewNameVar ),
133 _aNewName( rNewName )
134 { rNewNameVar = rNewName; }
135 ~SfxSaveAsContext_Impl()
136 { _rNewNameVar.Erase(); }
139 //====================================================================
141 #define SfxObjectShell
142 #include "sfxslots.hxx"
144 svtools::AsynchronLink* pPendingCloser = 0;
146 //=========================================================================
150 SFX_IMPL_INTERFACE(SfxObjectShell,SfxShell,SfxResId(0))
154 //=========================================================================
156 class SfxClosePreventer_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
158 sal_Bool m_bGotOwnership;
159 sal_Bool m_bPreventClose;
161 public:
162 SfxClosePreventer_Impl();
164 sal_Bool HasOwnership() { return m_bGotOwnership; }
166 void SetPreventClose( sal_Bool bPrevent ) { m_bPreventClose = bPrevent; }
168 virtual void SAL_CALL queryClosing( const lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
169 throw ( uno::RuntimeException, util::CloseVetoException );
171 virtual void SAL_CALL notifyClosing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
173 virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
177 SfxClosePreventer_Impl::SfxClosePreventer_Impl()
178 : m_bGotOwnership( sal_False )
179 , m_bPreventClose( sal_True )
183 void SAL_CALL SfxClosePreventer_Impl::queryClosing( const lang::EventObject&, sal_Bool bDeliverOwnership )
184 throw ( uno::RuntimeException, util::CloseVetoException )
186 if ( m_bPreventClose )
188 if ( !m_bGotOwnership )
189 m_bGotOwnership = bDeliverOwnership;
191 throw util::CloseVetoException();
195 void SAL_CALL SfxClosePreventer_Impl::notifyClosing( const lang::EventObject& ) throw ( uno::RuntimeException )
198 void SAL_CALL SfxClosePreventer_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException )
201 //=========================================================================
202 class SfxInstanceCloseGuard_Impl
204 SfxClosePreventer_Impl* m_pPreventer;
205 uno::Reference< util::XCloseListener > m_xPreventer;
206 uno::Reference< util::XCloseable > m_xCloseable;
208 public:
209 SfxInstanceCloseGuard_Impl()
210 : m_pPreventer( NULL )
213 ~SfxInstanceCloseGuard_Impl();
215 sal_Bool Init_Impl( const uno::Reference< util::XCloseable >& xCloseable );
218 sal_Bool SfxInstanceCloseGuard_Impl::Init_Impl( const uno::Reference< util::XCloseable >& xCloseable )
220 sal_Bool bResult = sal_False;
222 // do not allow reinit after the successful init
223 if ( xCloseable.is() && !m_xCloseable.is() )
227 m_pPreventer = new SfxClosePreventer_Impl();
228 m_xPreventer = uno::Reference< util::XCloseListener >( m_pPreventer );
229 xCloseable->addCloseListener( m_xPreventer );
230 m_xCloseable = xCloseable;
231 bResult = sal_True;
233 catch( uno::Exception& )
235 OSL_ENSURE( sal_False, "Could not register close listener!\n" );
239 return bResult;
242 SfxInstanceCloseGuard_Impl::~SfxInstanceCloseGuard_Impl()
244 if ( m_xCloseable.is() && m_xPreventer.is() )
248 m_xCloseable->removeCloseListener( m_xPreventer );
250 catch( uno::Exception& )
256 if ( m_pPreventer )
258 m_pPreventer->SetPreventClose( sal_False );
260 if ( m_pPreventer->HasOwnership() )
261 m_xCloseable->close( sal_True ); // TODO: do it asynchronously
264 catch( uno::Exception& )
270 //=========================================================================
272 void SfxObjectShell::PrintExec_Impl(SfxRequest &rReq)
274 SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this);
275 if ( pFrame )
277 rReq.SetSlot( SID_PRINTDOC );
278 pFrame->GetViewShell()->ExecuteSlot(rReq);
282 //--------------------------------------------------------------------
284 void SfxObjectShell::PrintState_Impl(SfxItemSet &rSet)
286 bool bPrinting = false;
287 SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this, TYPE(SfxTopViewFrame));
288 if ( pFrame )
290 SfxPrinter *pPrinter = pFrame->GetViewShell()->GetPrinter();
291 bPrinting = pPrinter && pPrinter->IsPrinting();
293 rSet.Put( SfxBoolItem( SID_PRINTOUT, bPrinting ) );
296 //--------------------------------------------------------------------
298 sal_Bool SfxObjectShell::APISaveAs_Impl
300 const String& aFileName,
301 SfxItemSet* aParams
304 BOOL bOk = sal_False;
306 {DBG_CHKTHIS(SfxObjectShell, 0);}
308 if ( GetMedium() )
310 String aFilterName;
311 SFX_ITEMSET_ARG( aParams, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
312 if( pFilterNameItem )
314 aFilterName = pFilterNameItem->GetValue();
316 else
318 SFX_ITEMSET_ARG( aParams, pContentTypeItem, SfxStringItem, SID_CONTENTTYPE, sal_False );
319 if ( pContentTypeItem )
321 const SfxFilter* pFilter = SfxFilterMatcher( String::CreateFromAscii(GetFactory().GetShortName()) ).GetFilter4Mime( pContentTypeItem->GetValue(), SFX_FILTER_EXPORT );
322 if ( pFilter )
323 aFilterName = pFilter->GetName();
327 // in case no filter defined use default one
328 if( !aFilterName.Len() )
330 const SfxFilter* pFilt = SfxFilter::GetDefaultFilterFromFactory(GetFactory().GetFactoryName());
332 DBG_ASSERT( pFilt, "No default filter!\n" );
333 if( pFilt )
334 aFilterName = pFilt->GetFilterName();
336 aParams->Put(SfxStringItem( SID_FILTER_NAME, aFilterName));
341 SfxObjectShellRef xLock( this ); // ???
343 // use the title that is provided in the media descriptor
344 SFX_ITEMSET_ARG( aParams, pDocTitleItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
345 if ( pDocTitleItem )
346 getDocProperties()->setTitle( pDocTitleItem->GetValue() );
348 bOk = CommonSaveAs_Impl( INetURLObject(aFileName), aFilterName,
349 aParams );
353 // prevent picklist-entry
354 GetMedium()->SetUpdatePickList( FALSE );
357 return bOk;
360 //--------------------------------------------------------------------
362 void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
364 {DBG_CHKTHIS(SfxObjectShell, 0);}
366 USHORT nId = rReq.GetSlot();
368 if( SID_SIGNATURE == nId || SID_MACRO_SIGNATURE == nId )
370 if ( QueryHiddenInformation( WhenSigning, NULL ) == RET_YES )
371 ( SID_SIGNATURE == nId ) ? SignDocumentContent() : SignScriptingContent();
372 return;
375 if ( !GetMedium() && nId != SID_CLOSEDOC )
377 rReq.Ignore();
378 return;
381 // this guard is created here to have it destruction at the end of the method
382 SfxInstanceCloseGuard_Impl aModelGuard;
384 sal_Bool bIsPDFExport = sal_False;
385 switch(nId)
387 case SID_VERSION:
389 SfxViewFrame* pFrame = GetFrame();
390 if ( !pFrame )
391 pFrame = SfxViewFrame::GetFirst( this );
392 if ( !pFrame )
393 return;
395 if ( pFrame->GetFrame()->GetParentFrame() )
397 pFrame->GetTopViewFrame()->GetObjectShell()->ExecuteSlot( rReq );
398 return;
401 if ( !IsOwnStorageFormat_Impl( *GetMedium() ) )
402 return;
404 SfxVersionDialog *pDlg = new SfxVersionDialog( pFrame, IsSaveVersionOnClose() );
405 pDlg->Execute();
406 SetSaveVersionOnClose( pDlg->IsSaveVersionOnClose() );
407 delete pDlg;
408 rReq.Done();
409 return;
412 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
413 case SID_DOCINFO:
415 SFX_REQUEST_ARG(rReq, pDocInfItem, SfxDocumentInfoItem, SID_DOCINFO, FALSE);
416 if ( pDocInfItem )
418 // parameter, e.g. from replayed macro
419 pDocInfItem->UpdateDocumentInfo(getDocProperties(), true);
420 SetUseUserData( pDocInfItem->IsUseUserData() );
422 else
424 // no argument containing DocInfo; check optional arguments
425 BOOL bReadOnly = IsReadOnly();
426 SFX_REQUEST_ARG(rReq, pROItem, SfxBoolItem, SID_DOC_READONLY, FALSE);
427 if ( pROItem )
428 // override readonly attribute of document
429 // e.g. if a readonly document is saved elsewhere and user asks for editing DocInfo before
430 bReadOnly = pROItem->GetValue();
432 // collect data for dialog
433 String aURL, aTitle;
434 if ( HasName() && !pImp->aNewName.Len() )
436 aURL = GetMedium()->GetName();
437 aTitle = GetTitle();
439 else
441 if ( !pImp->aNewName.Len() )
443 aURL = DEFINE_CONST_UNICODE( "private:factory/" );
444 aURL += String::CreateFromAscii( GetFactory().GetShortName() );
445 // aTitle = String( SfxResId( STR_NONAME ) );
447 else
449 aURL = DEFINE_CONST_UNICODE( "[private:factory/" );
450 aURL += String::CreateFromAscii( GetFactory().GetShortName() );
451 aURL += DEFINE_CONST_UNICODE( "]" );
452 INetURLObject aURLObj( pImp->aNewName );
453 aURL += String(aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI ));
454 // aTitle = aURLObj.GetBase();
457 aTitle = GetTitle();
460 SfxDocumentInfoItem aDocInfoItem( aURL, getDocProperties(),
461 IsUseUserData() );
462 if ( !GetSlotState( SID_DOCTEMPLATE ) )
463 // templates not supported
464 aDocInfoItem.SetTemplate(FALSE);
466 SfxItemSet aSet(GetPool(), SID_DOCINFO, SID_DOCINFO, SID_DOC_READONLY, SID_DOC_READONLY,
467 SID_EXPLORER_PROPS_START, SID_EXPLORER_PROPS_START, SID_BASEURL, SID_BASEURL,
468 0L );
469 aSet.Put( aDocInfoItem );
470 aSet.Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
471 aSet.Put( SfxStringItem( SID_EXPLORER_PROPS_START, aTitle ) );
472 aSet.Put( SfxStringItem( SID_BASEURL, GetMedium()->GetBaseURL() ) );
474 // creating dialog is done via virtual method; application will add its own statistics page
475 SfxDocumentInfoDialog *pDlg = CreateDocumentInfoDialog(0, aSet);
476 if ( RET_OK == pDlg->Execute() )
478 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pDocInfoItem, SfxDocumentInfoItem, SID_DOCINFO, FALSE);
479 if ( pDocInfoItem )
481 // user has done some changes to DocumentInfo
482 pDocInfoItem->UpdateDocumentInfo(getDocProperties());
483 SetUseUserData( ((const SfxDocumentInfoItem *)pDocInfoItem)->IsUseUserData() );
485 // add data from dialog for possible recording purposes
486 rReq.AppendItem( SfxDocumentInfoItem( GetTitle(),
487 getDocProperties(), IsUseUserData() ) );
490 rReq.Done();
492 else
493 // nothing done; no recording
494 rReq.Ignore();
496 delete pDlg;
499 return;
502 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
504 case SID_EXPORTDOCASPDF:
505 case SID_DIRECTEXPORTDOCASPDF:
506 bIsPDFExport = sal_True;
507 case SID_EXPORTDOC:
508 case SID_SAVEASDOC:
509 case SID_SAVEDOC:
511 if( nId == SID_SAVEDOC || nId == SID_SAVEASDOC )
513 uno::Reference< document::XDocumentEventCompatibleHelper > xVbaEventHelper( GetModel(), uno::UNO_QUERY );
514 if( xVbaEventHelper.is() )
516 if( xVbaEventHelper->processCompatibleEvent( nId ) )
518 rReq.SetReturnValue( SfxBoolItem( 0, sal_True ) );
519 return;
523 //!! detaillierte Auswertung eines Fehlercodes
524 SfxObjectShellRef xLock( this );
526 // the model can not be closed till the end of this method
527 // if somebody tries to close it during this time the model will be closed
528 // at the end of the method
529 aModelGuard.Init_Impl( uno::Reference< util::XCloseable >( GetModel(), uno::UNO_QUERY ) );
531 sal_Bool bDialogUsed = sal_False;
532 sal_uInt32 nErrorCode = ERRCODE_NONE;
534 // by default versions should be preserved always except in case of an explicit
535 // SaveAs via GUI, so the flag must be set accordingly
536 pImp->bPreserveVersions = (nId == SID_SAVEDOC);
539 SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, GetTitle() ); // ???
541 // xmlsec05, check with SFX team
542 sal_uInt16 nState = GetDocumentSignatureState();
543 if ( SIGNATURESTATE_SIGNATURES_OK == nState
544 || SIGNATURESTATE_SIGNATURES_INVALID == nState
545 || SIGNATURESTATE_SIGNATURES_NOTVALIDATED == nState )
547 if ( QueryBox( NULL, SfxResId( RID_XMLSEC_QUERY_LOSINGSIGNATURE ) ).Execute() != RET_YES )
548 return;
551 if ( nId == SID_SAVEASDOC )
553 // in case of plugin mode the SaveAs operation means SaveTo
554 SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pViewOnlyItem, SfxBoolItem, SID_VIEWONLY, FALSE );
555 if ( pViewOnlyItem && pViewOnlyItem->GetValue() )
556 rReq.AppendItem( SfxBoolItem( SID_SAVETO, sal_True ) );
559 // TODO/LATER: do the following GUI related actions in standalown method
560 // ========================================================================================================
561 // Introduce a status indicator for GUI operation
562 SFX_REQUEST_ARG( rReq, pStatusIndicatorItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, FALSE );
563 if ( !pStatusIndicatorItem )
565 // get statusindicator
566 uno::Reference< task::XStatusIndicator > xStatusIndicator;
567 SfxViewFrame *pFrame = GetFrame();
568 if ( pFrame && pFrame->GetFrame() )
570 uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
571 pFrame->GetFrame()->GetFrameInterface(),
572 uno::UNO_QUERY );
573 if( xStatFactory.is() )
574 xStatusIndicator = xStatFactory->createStatusIndicator();
578 OSL_ENSURE( xStatusIndicator.is(), "Can not retrieve default status indicator!\n" );
579 if ( xStatusIndicator.is() )
581 SfxUnoAnyItem aStatIndItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::makeAny( xStatusIndicator ) );
583 if ( nId == SID_SAVEDOC )
585 // in case of saving it is not possible to transport the parameters from here
586 // but it is not clear here whether the saving will be done or saveAs operation
587 GetMedium()->GetItemSet()->Put( aStatIndItem );
590 rReq.AppendItem( aStatIndItem );
593 else if ( nId == SID_SAVEDOC )
595 // in case of saving it is not possible to transport the parameters from here
596 // but it is not clear here whether the saving will be done or saveAs operation
597 GetMedium()->GetItemSet()->Put( *pStatusIndicatorItem );
600 // Introduce an interaction handler for GUI operation
601 SFX_REQUEST_ARG( rReq, pInteractionHandlerItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, FALSE );
602 if ( !pInteractionHandlerItem )
604 uno::Reference< task::XInteractionHandler > xInteract;
605 uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
606 if( xServiceManager.is() )
608 xInteract = Reference< XInteractionHandler >(
609 xServiceManager->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ),
610 UNO_QUERY );
613 OSL_ENSURE( xInteract.is(), "Can not retrieve default status indicator!\n" );
614 if ( xInteract.is() )
616 SfxUnoAnyItem aInteractionItem( SID_INTERACTIONHANDLER, uno::makeAny( xInteract ) );
617 if ( nId == SID_SAVEDOC )
619 // in case of saving it is not possible to transport the parameters from here
620 // but it is not clear here whether the saving will be done or saveAs operation
621 GetMedium()->GetItemSet()->Put( aInteractionItem );
624 rReq.AppendItem( aInteractionItem );
627 else if ( nId == SID_SAVEDOC )
629 // in case of saving it is not possible to transport the parameters from here
630 // but it is not clear here whether the saving will be done or saveAs operation
631 GetMedium()->GetItemSet()->Put( *pInteractionHandlerItem );
633 // ========================================================================================================
635 sal_Bool bPreselectPassword = sal_False;
636 SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pOldPasswordItem, SfxStringItem, SID_PASSWORD, FALSE );
637 if ( pOldPasswordItem )
638 bPreselectPassword = sal_True;
640 uno::Sequence< beans::PropertyValue > aDispatchArgs;
641 if ( rReq.GetArgs() )
642 TransformItems( nId,
643 *rReq.GetArgs(),
644 aDispatchArgs,
645 NULL );
647 const SfxSlot* pSlot = GetModule()->GetSlotPool()->GetSlot( nId );
648 if ( !pSlot )
649 throw uno::Exception();
651 uno::Reference< lang::XMultiServiceFactory > xEmptyFactory;
652 SfxStoringHelper aHelper( xEmptyFactory );
654 if ( QueryHiddenInformation( bIsPDFExport ? WhenCreatingPDF : WhenSaving, NULL ) == RET_YES )
656 bDialogUsed = aHelper.GUIStoreModel( GetModel(),
657 ::rtl::OUString::createFromAscii( pSlot->GetUnoName() ),
658 aDispatchArgs,
659 bPreselectPassword,
660 GetSharedFileURL() );
662 else
664 // the user has decided not to store the document
665 throw task::ErrorCodeIOException( ::rtl::OUString(),
666 uno::Reference< uno::XInterface >(),
667 ERRCODE_IO_ABORT );
670 // the scripting signature might be preserved
671 // pImp->nScriptingSignatureState = SIGNATURESTATE_NOSIGNATURES;
672 pImp->nDocumentSignatureState = SIGNATURESTATE_NOSIGNATURES;
673 pImp->bSignatureErrorIsShown = sal_False;
675 // merge aDispatchArgs to the request
676 SfxAllItemSet aResultParams( GetPool() );
677 TransformParameters( nId,
678 aDispatchArgs,
679 aResultParams,
680 NULL );
681 rReq.SetArgs( aResultParams );
683 SFX_REQUEST_ARG( rReq, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, FALSE );
684 ::rtl::OUString aFilterName = pFilterNameItem ? ::rtl::OUString( pFilterNameItem->GetValue() )
685 : ::rtl::OUString();
686 const SfxFilter* pFilt = GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
688 OSL_ENSURE( nId == SID_SAVEDOC || pFilt, "The filter can not be zero since it was used for storing!\n" );
689 if ( bDialogUsed && pFilt
690 && pFilt->IsOwnFormat()
691 && pFilt->UsesStorage()
692 && pFilt->GetVersion() >= SOFFICE_FILEFORMAT_60 )
694 SfxViewFrame* pDocViewFrame = SfxViewFrame::GetFirst( this );
695 SfxFrame* pDocFrame = pDocViewFrame ? pDocViewFrame->GetFrame() : NULL;
696 if ( pDocFrame )
697 SfxHelp::OpenHelpAgent( pDocFrame, HID_DID_SAVE_PACKED_XML );
700 // the StoreAsURL/StoreToURL method have called this method with false
701 // so it has to be restored to true here since it is a call from GUI
702 GetMedium()->SetUpdatePickList( sal_True );
704 // TODO: in future it must be done in followind way
705 // if document is opened from GUI it is immediatelly appeares in the picklist
706 // if the document is a new one then it appeares in the picklist immediatelly
707 // after SaveAs operation triggered from GUI
709 catch( task::ErrorCodeIOException& aErrorEx )
711 nErrorCode = (sal_uInt32)aErrorEx.ErrCode;
713 catch( Exception& )
715 nErrorCode = ERRCODE_IO_GENERAL;
718 // by default versions should be preserved always except in case of an explicit
719 // SaveAs via GUI, so the flag must be reset to guarantee this
720 pImp->bPreserveVersions = sal_True;
721 ULONG lErr=GetErrorCode();
723 if ( !lErr && nErrorCode )
724 lErr = nErrorCode;
726 if ( lErr && nErrorCode == ERRCODE_NONE )
728 SFX_REQUEST_ARG( rReq, pWarnItem, SfxBoolItem, SID_FAIL_ON_WARNING, FALSE );
729 if ( pWarnItem && pWarnItem->GetValue() )
730 nErrorCode = lErr;
733 // may be nErrorCode should be shown in future
734 if ( lErr != ERRCODE_IO_ABORT )
736 SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC,GetTitle());
737 ErrorHandler::HandleError( lErr );
740 if ( nId == SID_EXPORTDOCASPDF )
742 // This function is used by the SendMail function that needs information if a export
743 // file was written or not. This could be due to cancellation of the export
744 // or due to an error. So IO abort must be handled like an error!
745 nErrorCode = ( lErr != ERRCODE_IO_ABORT ) && ( nErrorCode == ERRCODE_NONE ) ? nErrorCode : lErr;
748 rReq.SetReturnValue( SfxBoolItem(0, nErrorCode == ERRCODE_NONE ) );
750 ResetError();
752 Invalidate();
753 break;
756 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
758 case SID_CLOSEDOC:
760 SfxViewFrame *pFrame = GetFrame();
761 if ( pFrame && pFrame->GetFrame()->GetParentFrame() )
763 // Wenn SID_CLOSEDOC "uber Menue etc. ausgef"uhrt wird, das
764 // aktuelle Dokument aber in einem Frame liegt, soll eigentlich
765 // das FrameSetDocument geclosed werden
766 pFrame->GetTopViewFrame()->GetObjectShell()->ExecuteSlot( rReq );
767 rReq.Done();
768 return;
771 BOOL bInFrameSet = FALSE;
772 USHORT nFrames=0;
773 pFrame = SfxViewFrame::GetFirst( this );
774 while ( pFrame )
776 if ( pFrame->GetFrame()->GetParentFrame() )
778 // Auf dieses Dokument existiert noch eine Sicht, die
779 // in einem FrameSet liegt; diese darf nat"urlich nicht
780 // geclosed werden
781 bInFrameSet = TRUE;
783 else
784 nFrames++;
786 pFrame = SfxViewFrame::GetNext( *pFrame, this );
789 if ( bInFrameSet )
791 // Alle Sichten, die nicht in einem FrameSet liegen, closen
792 pFrame = SfxViewFrame::GetFirst( this );
793 while ( pFrame )
795 if ( !pFrame->GetFrame()->GetParentFrame() )
796 pFrame->GetFrame()->DoClose();
797 pFrame = SfxViewFrame::GetNext( *pFrame, this );
801 // Parameter auswerten
802 SFX_REQUEST_ARG(rReq, pSaveItem, SfxBoolItem, SID_CLOSEDOC_SAVE, FALSE);
803 SFX_REQUEST_ARG(rReq, pNameItem, SfxStringItem, SID_CLOSEDOC_FILENAME, FALSE);
804 if ( pSaveItem )
806 if ( pSaveItem->GetValue() )
808 if ( !pNameItem )
810 SbxBase::SetError( SbxERR_WRONG_ARGS );
811 rReq.Ignore();
812 return;
814 SfxAllItemSet aArgs( GetPool() );
815 SfxStringItem aTmpItem( SID_FILE_NAME, pNameItem->GetValue() );
816 aArgs.Put( aTmpItem, aTmpItem.Which() );
817 SfxRequest aSaveAsReq( SID_SAVEASDOC, SFX_CALLMODE_API, aArgs );
818 ExecFile_Impl( aSaveAsReq );
819 if ( !aSaveAsReq.IsDone() )
821 rReq.Ignore();
822 return;
825 else
826 SetModified(FALSE);
829 // Benutzer bricht ab?
830 if ( !PrepareClose( 2 ) )
832 rReq.SetReturnValue( SfxBoolItem(0, FALSE) );
833 rReq.Done();
834 return;
837 SetModified( FALSE );
838 ULONG lErr = GetErrorCode();
839 ErrorHandler::HandleError(lErr);
841 rReq.SetReturnValue( SfxBoolItem(0, TRUE) );
842 rReq.Done();
843 rReq.ReleaseArgs(); // da der Pool in Close zerst"ort wird
844 DoClose();
845 return;
848 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
849 case SID_DOCTEMPLATE:
851 // speichern als Dokumentvorlagen
852 SfxDocumentTemplateDlg *pDlg = 0;
853 SfxErrorContext aEc(ERRCTX_SFX_DOCTEMPLATE,GetTitle());
854 SfxDocumentTemplates *pTemplates = new SfxDocumentTemplates;
856 if ( !rReq.GetArgs() )
858 pDlg = new SfxDocumentTemplateDlg(0, pTemplates);
859 if ( RET_OK == pDlg->Execute() && pDlg->GetTemplateName().Len())
861 rReq.AppendItem(SfxStringItem(
862 SID_TEMPLATE_NAME, pDlg->GetTemplateName()));
863 rReq.AppendItem(SfxStringItem(
864 SID_TEMPLATE_REGIONNAME, pDlg->GetRegionName()));
866 else
868 delete pDlg;
869 rReq.Ignore();
870 return;
874 SFX_REQUEST_ARG(rReq, pRegionItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, FALSE);
875 SFX_REQUEST_ARG(rReq, pNameItem, SfxStringItem, SID_TEMPLATE_NAME, FALSE);
876 SFX_REQUEST_ARG(rReq, pRegionNrItem, SfxUInt16Item, SID_TEMPLATE_REGION, FALSE);
877 if ( (!pRegionItem && !pRegionNrItem ) || !pNameItem )
879 DBG_ASSERT( rReq.IsAPI(), "non-API call without Arguments" );
880 SbxBase::SetError( SbxERR_WRONG_ARGS );
881 rReq.Ignore();
882 return;
885 ::rtl::OUString aTemplateName = pNameItem->GetValue();
886 ::rtl::OUString aTemplateGroup;
887 if ( pRegionItem )
888 aTemplateGroup = pRegionItem->GetValue();
889 else
890 // pRegionNrItem must not be NULL, it was just checked
891 aTemplateGroup = pTemplates->GetFullRegionName( pRegionNrItem->GetValue() );
892 // check Group and Name
893 delete pTemplates;
895 sal_Bool bOk = sal_False;
898 uno::Reference< frame::XStorable > xStorable( GetModel(), uno::UNO_QUERY_THROW );
899 ::rtl::OUString aService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.DocumentTemplates" ) );
900 uno::Reference< frame::XDocumentTemplates > xTemplates(
901 comphelper::getProcessServiceFactory()->createInstance( aService ),
902 uno::UNO_QUERY_THROW );
904 bOk = xTemplates->storeTemplate( aTemplateGroup, aTemplateName, xStorable );
906 catch( uno::Exception& )
910 DELETEX(pDlg);
912 rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
913 if ( bOk )
915 // update the Organizer runtime cache from the template component if the cache has already been created
916 // TODO/LATER: get rid of this cache duplication
917 SfxDocumentTemplates aTemplates;
918 aTemplates.ReInitFromComponent();
920 else
922 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
923 return;
926 break;
930 // Picklisten-Eintrag verhindern
931 if ( rReq.IsAPI() )
932 GetMedium()->SetUpdatePickList( FALSE );
933 else if ( rReq.GetArgs() )
935 SFX_ITEMSET_GET( *rReq.GetArgs(), pPicklistItem, SfxBoolItem, SID_PICKLIST, FALSE );
936 if ( pPicklistItem )
937 GetMedium()->SetUpdatePickList( pPicklistItem->GetValue() );
940 // Ignore()-Zweige haben schon returnt
941 rReq.Done();
944 //--------------------------------------------------------------------
946 void SfxObjectShell::GetState_Impl(SfxItemSet &rSet)
948 DBG_CHKTHIS(SfxObjectShell, 0);
949 SfxWhichIter aIter( rSet );
951 for ( USHORT nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
953 switch ( nWhich )
955 case SID_DOCTEMPLATE :
957 if ( !GetFactory().GetTemplateFilter() )
958 rSet.DisableItem( nWhich );
959 break;
962 case SID_VERSION:
964 SfxObjectShell *pDoc = this;
965 SfxViewFrame* pFrame = GetFrame();
966 if ( !pFrame )
967 pFrame = SfxViewFrame::GetFirst( this );
968 if ( pFrame )
970 if ( pFrame->GetFrame()->GetParentFrame() )
972 pFrame = pFrame->GetTopViewFrame();
973 pDoc = pFrame->GetObjectShell();
977 if ( !pFrame || !pDoc->HasName() ||
978 !IsOwnStorageFormat_Impl( *pDoc->GetMedium() ) )
979 //REMOVE || pDoc->GetMedium()->GetStorage()->GetVersion() < SOFFICE_FILEFORMAT_50 )
980 rSet.DisableItem( nWhich );
981 break;
983 case SID_SAVEDOC:
985 bool bAllowSave = (GetApplicationFlag(SFX_APPFLAG_ALWAYS_ALLOW_SAVE) || IsModified());
986 bool bMediumRO = IsReadOnlyMedium();
987 if ( !bMediumRO && GetMedium() && bAllowSave )
988 rSet.Put(SfxStringItem(
989 nWhich, String(SfxResId(STR_SAVEDOC))));
990 else
991 rSet.DisableItem(nWhich);
993 break;
995 case SID_DOCINFO:
996 if ( 0 != ( pImp->eFlags & SFXOBJECTSHELL_NODOCINFO ) )
997 rSet.DisableItem( nWhich );
998 break;
1000 case SID_CLOSEDOC:
1002 SfxObjectShell *pDoc = this;
1003 SfxViewFrame *pFrame = GetFrame();
1004 if ( pFrame && pFrame->GetFrame()->GetParentFrame() )
1006 // Wenn SID_CLOSEDOC "uber Menue etc. ausgef"uhrt wird, das
1007 // aktuelle Dokument aber in einem Frame liegt, soll eigentlich
1008 // das FrameSetDocument geclosed werden
1009 pDoc = pFrame->GetTopViewFrame()->GetObjectShell();
1012 if ( pDoc->GetFlags() & SFXOBJECTSHELL_DONTCLOSE )
1013 rSet.DisableItem(nWhich);
1014 else
1015 rSet.Put(SfxStringItem(nWhich, String(SfxResId(STR_CLOSEDOC))));
1016 break;
1019 case SID_SAVEASDOC:
1021 if( ( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) != SFX_LOADED_MAINDOCUMENT )
1023 rSet.DisableItem( nWhich );
1024 break;
1027 const SfxFilter* pCombinedFilters = NULL;
1028 SfxFilterContainer* pFilterContainer = GetFactory().GetFilterContainer();
1030 if ( pFilterContainer )
1032 SfxFilterFlags nMust = SFX_FILTER_IMPORT | SFX_FILTER_EXPORT;
1033 SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED | SFX_FILTER_INTERNAL;
1035 pCombinedFilters = pFilterContainer->GetAnyFilter( nMust, nDont );
1038 if ( /*!pCombinedFilters ||*/ !GetMedium() )
1039 rSet.DisableItem( nWhich );
1040 else
1041 rSet.Put( SfxStringItem( nWhich, String( SfxResId( STR_SAVEASDOC ) ) ) );
1042 break;
1045 case SID_EXPORTDOCASPDF:
1046 case SID_DIRECTEXPORTDOCASPDF:
1050 search for filter cant work correctly ...
1051 Because it's not clear, which export filter for which office module
1052 must be searched. On the other side it can be very expensive doing so.
1053 The best solution would be: on installation time we should know if pdf feature
1054 was installed or not!!! (e.g. by writing a bool inside cfg)
1056 SfxFilterContainer* pFilterContainer = GetFactory().GetFilterContainer();
1057 if ( pFilterContainer )
1059 String aPDFExtension = String::CreateFromAscii( "pdf" );
1060 const SfxFilter* pFilter = pFilterContainer->GetFilter4Extension( aPDFExtension, SFX_FILTER_EXPORT );
1061 if ( pFilter != NULL )
1062 break;
1065 rSet.DisableItem( nWhich );
1067 break;
1070 case SID_DOC_MODIFIED:
1072 rSet.Put( SfxBoolItem( SID_DOC_MODIFIED, IsModified() ) );
1073 break;
1076 case SID_MODIFIED:
1078 rSet.Put( SfxBoolItem( SID_MODIFIED, IsModified() ) );
1079 break;
1082 case SID_DOCINFO_TITLE:
1084 rSet.Put( SfxStringItem(
1085 SID_DOCINFO_TITLE, getDocProperties()->getTitle() ) );
1086 break;
1088 case SID_FILE_NAME:
1090 if( GetMedium() && HasName() )
1091 rSet.Put( SfxStringItem(
1092 SID_FILE_NAME, GetMedium()->GetName() ) );
1093 break;
1095 case SID_SIGNATURE:
1097 rSet.Put( SfxUInt16Item( SID_SIGNATURE, GetDocumentSignatureState() ) );
1098 break;
1100 case SID_MACRO_SIGNATURE:
1102 rSet.Put( SfxUInt16Item( SID_MACRO_SIGNATURE, GetScriptingSignatureState() ) );
1103 break;
1109 //--------------------------------------------------------------------
1111 void SfxObjectShell::ExecProps_Impl(SfxRequest &rReq)
1113 switch ( rReq.GetSlot() )
1115 case SID_MODIFIED:
1117 SetModified( ( (SfxBoolItem&) rReq.GetArgs()->Get(SID_MODIFIED)).GetValue() );
1118 rReq.Done();
1119 break;
1122 case SID_DOCTITLE:
1123 SetTitle( ( (SfxStringItem&) rReq.GetArgs()->Get(SID_DOCTITLE)).GetValue() );
1124 rReq.Done();
1125 break;
1127 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1128 case SID_PLAYMACRO:
1130 SFX_APP()->PlayMacro_Impl( rReq, GetBasic() );
1131 break;
1134 case SID_DOCINFO_AUTHOR :
1136 ::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
1137 getDocProperties()->setAuthor( aStr );
1138 break;
1141 case SID_DOCINFO_COMMENTS :
1143 ::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
1144 getDocProperties()->setDescription( aStr );
1145 break;
1148 case SID_DOCINFO_KEYWORDS :
1150 ::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
1151 getDocProperties()->setKeywords(
1152 ::comphelper::string::convertCommaSeparated(aStr) );
1153 break;
1158 //--------------------------------------------------------------------
1160 void SfxObjectShell::StateProps_Impl(SfxItemSet &rSet)
1162 SfxWhichIter aIter(rSet);
1163 for ( USHORT nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
1165 switch ( nSID )
1167 case SID_DOCINFO_AUTHOR :
1169 rSet.Put( SfxStringItem( nSID,
1170 getDocProperties()->getAuthor() ) );
1171 break;
1174 case SID_DOCINFO_COMMENTS :
1176 rSet.Put( SfxStringItem( nSID,
1177 getDocProperties()->getDescription()) );
1178 break;
1181 case SID_DOCINFO_KEYWORDS :
1183 rSet.Put( SfxStringItem( nSID, ::comphelper::string::
1184 convertCommaSeparated(getDocProperties()->getKeywords())) );
1185 break;
1188 case SID_DOCPATH:
1190 DBG_ERROR( "Not supported anymore!" );
1191 break;
1194 case SID_DOCFULLNAME:
1196 rSet.Put( SfxStringItem( SID_DOCFULLNAME, GetTitle(SFX_TITLE_FULLNAME) ) );
1197 break;
1200 case SID_DOCTITLE:
1202 rSet.Put( SfxStringItem( SID_DOCTITLE, GetTitle() ) );
1203 break;
1206 case SID_DOC_READONLY:
1208 rSet.Put( SfxBoolItem( SID_DOC_READONLY, IsReadOnly() ) );
1209 break;
1212 case SID_DOC_SAVED:
1214 rSet.Put( SfxBoolItem( SID_DOC_SAVED, !IsModified() ) );
1215 break;
1218 case SID_CLOSING:
1220 rSet.Put( SfxBoolItem( SID_CLOSING, Get_Impl()->bInCloseEvent ) );
1221 break;
1224 case SID_DOC_LOADING:
1225 rSet.Put( SfxBoolItem( nSID, SFX_LOADED_MAINDOCUMENT !=
1226 ( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) ) );
1227 break;
1229 case SID_IMG_LOADING:
1230 rSet.Put( SfxBoolItem( nSID, SFX_LOADED_IMAGES !=
1231 ( pImp->nLoadedFlags & SFX_LOADED_IMAGES ) ) );
1232 break;
1237 //--------------------------------------------------------------------
1239 void SfxObjectShell::ExecView_Impl(SfxRequest &rReq)
1241 switch ( rReq.GetSlot() )
1243 case SID_ACTIVATE:
1245 SfxViewFrame *pFrame =
1246 SfxViewFrame::GetFirst( this, TYPE(SfxTopViewFrame), TRUE );
1247 if ( pFrame )
1248 pFrame->GetFrame()->Appear();
1249 rReq.SetReturnValue( SfxObjectItem( 0, pFrame ) );
1250 rReq.Done();
1251 break;
1253 case SID_NEWWINDOWFOREDIT:
1255 SfxViewFrame* pFrame = SfxViewFrame::Current();
1256 if( pFrame->GetObjectShell() == this &&
1257 ( pFrame->GetFrameType() & SFXFRAME_HASTITLE ) )
1258 pFrame->ExecuteSlot( rReq );
1259 else
1261 String aFileName( GetObjectShell()->GetMedium()->GetName() );
1262 if ( aFileName.Len() )
1264 SfxStringItem aName( SID_FILE_NAME, aFileName );
1265 SfxBoolItem aCreateView( SID_OPEN_NEW_VIEW, TRUE );
1266 SFX_APP()->GetAppDispatcher_Impl()->Execute(
1267 SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aName,
1268 &aCreateView, 0L);
1275 //--------------------------------------------------------------------
1277 void SfxObjectShell::StateView_Impl(SfxItemSet& /*rSet*/)
1281 sal_uInt16 SfxObjectShell::ImplCheckSignaturesInformation( const uno::Sequence< security::DocumentSignatureInformation >& aInfos )
1283 sal_Bool bCertValid = sal_True;
1284 sal_uInt16 nResult = SIGNATURESTATE_NOSIGNATURES;
1285 int nInfos = aInfos.getLength();
1286 if( nInfos )
1288 //These errors of certificates are allowed
1289 sal_Int32 nNonErrors = security::CertificateValidity::VALID |
1290 security::CertificateValidity::UNKNOWN_REVOKATION;
1291 //Build a mask to filter out the allowed errors
1292 sal_Int32 nMask = ~nNonErrors;
1294 nResult = SIGNATURESTATE_SIGNATURES_OK;
1295 for ( int n = 0; n < nInfos; n++ )
1297 if ( bCertValid )
1299 sal_Int32 nCertStat = aInfos[n].CertificateStatus;
1300 // "subtract" the allowed error flags from the result
1301 sal_Int32 nErrors = ( nCertStat & nMask );
1302 bCertValid = nErrors > 0 ? sal_False : sal_True;
1305 if ( !aInfos[n].SignatureIsValid )
1307 nResult = SIGNATURESTATE_SIGNATURES_BROKEN;
1308 break; // we know enough
1313 if ( nResult == SIGNATURESTATE_SIGNATURES_OK && !bCertValid )
1314 nResult = SIGNATURESTATE_SIGNATURES_NOTVALIDATED;
1316 // this code must not check whether the document is modified
1317 // it should only check the provided info
1319 return nResult;
1322 sal_uInt16 SfxObjectShell::ImplGetSignatureState( sal_Bool bScriptingContent )
1324 sal_Int16* pState = bScriptingContent ? &pImp->nScriptingSignatureState : &pImp->nDocumentSignatureState;
1326 if ( *pState == SIGNATURESTATE_UNKNOWN )
1328 *pState = SIGNATURESTATE_NOSIGNATURES;
1330 if ( GetMedium() && GetMedium()->GetName().Len() && IsOwnStorageFormat_Impl( *GetMedium()) && GetMedium()->GetStorage().is() )
1334 uno::Reference< security::XDocumentDigitalSignatures > xD(
1335 comphelper::getProcessServiceFactory()->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ) ), uno::UNO_QUERY );
1337 if ( xD.is() )
1339 ::com::sun::star::uno::Sequence< security::DocumentSignatureInformation > aInfos;
1340 if ( bScriptingContent )
1341 aInfos = xD->verifyScriptingContentSignatures( GetMedium()->GetLastCommitReadStorage_Impl(),
1342 uno::Reference< io::XInputStream >() );
1343 else
1344 aInfos = xD->verifyDocumentContentSignatures( GetMedium()->GetLastCommitReadStorage_Impl(),
1345 uno::Reference< io::XInputStream >() );
1347 *pState = ImplCheckSignaturesInformation( aInfos );
1350 catch( com::sun::star::uno::Exception& )
1356 if ( *pState == SIGNATURESTATE_SIGNATURES_OK || *pState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
1358 if ( IsModified() )
1359 *pState = SIGNATURESTATE_SIGNATURES_INVALID;
1362 return (sal_uInt16)*pState;
1365 void SfxObjectShell::ImplSign( sal_Bool bScriptingContent )
1367 // Check if it is stored in OASIS format...
1368 if ( GetMedium() && GetMedium()->GetFilter()
1369 && ( !GetMedium()->GetFilter()->IsOwnFormat() || !GetMedium()->HasStorage_Impl() ) )
1371 // Only OASIS and OOo6.x formats will be handled further
1372 InfoBox( NULL, SfxResId( RID_XMLSEC_INFO_WRONGDOCFORMAT ) ).Execute();
1373 return;
1376 // check whether the document is signed
1377 ImplGetSignatureState( sal_False ); // document signature
1378 ImplGetSignatureState( sal_True ); // script signature
1379 sal_Bool bHasSign = ( pImp->nScriptingSignatureState != SIGNATURESTATE_NOSIGNATURES || pImp->nDocumentSignatureState != SIGNATURESTATE_NOSIGNATURES );
1381 // the target ODF version on saving
1382 SvtSaveOptions aSaveOpt;
1383 SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion();
1385 // the document is not new and is not modified
1386 ::rtl::OUString aODFVersion;
1389 // check the version of the document
1390 uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
1391 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aODFVersion;
1393 catch( uno::Exception& )
1396 bool bNoSig = false;
1398 if ( IsModified() || !GetMedium() || !GetMedium()->GetName().Len()
1399 || (!aODFVersion.equals( ODFVER_012_TEXT ) && !bHasSign) )
1401 // the document might need saving ( new, modified or in ODF1.1 format without signature )
1403 if ( nVersion == SvtSaveOptions::ODFVER_012 )
1406 if ( (bHasSign && QueryBox( NULL, SfxResId( MSG_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN ) ).Execute() == RET_YES)
1407 || (!bHasSign && QueryBox( NULL, SfxResId( RID_XMLSEC_QUERY_SAVEBEFORESIGN ) ).Execute() == RET_YES) )
1409 USHORT nId = SID_SAVEDOC;
1410 if ( !GetMedium() || !GetMedium()->GetName().Len() )
1411 nId = SID_SAVEASDOC;
1412 SfxRequest aSaveRequest( nId, 0, GetPool() );
1413 //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved.
1414 SetModified(sal_True);
1415 ExecFile_Impl( aSaveRequest );
1417 // Check if it is stored in OASIS format...
1418 if ( GetMedium() && GetMedium()->GetFilter()
1419 && ( !GetMedium()->GetFilter()->IsOwnFormat() || !GetMedium()->HasStorage_Impl()
1420 || SotStorage::GetVersion( GetMedium()->GetStorage() ) <= SOFFICE_FILEFORMAT_60 ) )
1422 // Only OASIS format will be handled further
1423 InfoBox( NULL, SfxResId( RID_XMLSEC_INFO_WRONGDOCFORMAT ) ).Execute();
1424 return;
1427 else
1429 //When the document is modified then we must not show the digital signatures dialog
1430 //If we have come here then the user denied to save.
1431 if (!bHasSign)
1433 bNoSig = true;
1436 else
1438 ErrorBox( NULL, WB_OK, SfxResId( STR_XMLSEC_ODF12_EXPECTED ) ).Execute();
1439 return;
1442 if ( IsModified() || !GetMedium() || !GetMedium()->GetName().Len() )
1443 return;
1446 // the document is not modified currently, so it can not become modified after signing
1447 sal_Bool bAllowModifiedBack = sal_False;
1448 if ( IsEnableSetModified() )
1450 EnableSetModified( sal_False );
1451 bAllowModifiedBack = sal_True;
1454 if ( ! bNoSig && GetMedium()->SignContents_Impl( bScriptingContent ) )
1456 if ( bScriptingContent )
1457 pImp->nScriptingSignatureState = SIGNATURESTATE_UNKNOWN;// Re-Check
1458 else
1459 pImp->nDocumentSignatureState = SIGNATURESTATE_UNKNOWN;// Re-Check
1461 pImp->bSignatureErrorIsShown = sal_False;
1463 Invalidate( SID_SIGNATURE );
1464 Invalidate( SID_MACRO_SIGNATURE );
1465 Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1468 if ( bAllowModifiedBack )
1469 EnableSetModified( sal_True );
1472 sal_uInt16 SfxObjectShell::GetDocumentSignatureState()
1474 return ImplGetSignatureState( FALSE );
1477 void SfxObjectShell::SignDocumentContent()
1479 ImplSign( FALSE );
1482 sal_uInt16 SfxObjectShell::GetScriptingSignatureState()
1484 return ImplGetSignatureState( TRUE );
1487 void SfxObjectShell::SignScriptingContent()
1489 ImplSign( TRUE );
1492 // static
1493 const uno::Sequence<sal_Int8>& SfxObjectShell::getUnoTunnelId()
1495 static uno::Sequence<sal_Int8> * pSeq = 0;
1496 if( !pSeq )
1498 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1499 if( !pSeq )
1501 static uno::Sequence< sal_Int8 > aSeq( 16 );
1502 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1503 pSeq = &aSeq;
1506 return *pSeq;