LibreOffice Module sfx2 (master) 1
objserv.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <config_features.h>
21
22#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
23#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
24#include <com/sun/star/util/CloseVetoException.hpp>
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/beans/PropertyValue.hpp>
27#include <com/sun/star/beans/PropertyAttribute.hpp>
28#include <com/sun/star/document/XCmisDocument.hpp>
29#include <com/sun/star/drawing/LineStyle.hpp>
30#include <com/sun/star/lang/XServiceInfo.hpp>
31#include <com/sun/star/security/XCertificate.hpp>
32#include <com/sun/star/task/ErrorCodeIOException.hpp>
33#include <com/sun/star/task/InteractionHandler.hpp>
34#include <com/sun/star/task/XStatusIndicator.hpp>
35#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
38#include <com/sun/star/drawing/XDrawView.hpp>
39
40#include <com/sun/star/security/DocumentSignatureInformation.hpp>
41#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
43#include <tools/urlobj.hxx>
44#include <svl/whiter.hxx>
45#include <svl/intitem.hxx>
46#include <svl/eitem.hxx>
47#include <svl/visitem.hxx>
48#include <svtools/sfxecode.hxx>
49#include <svtools/ehdl.hxx>
50#include <sal/log.hxx>
51#include <sfx2/app.hxx>
52
53#include <comphelper/string.hxx>
54#include <basic/sbxcore.hxx>
55#include <basic/sberrors.hxx>
57#include <unotools/saveopt.hxx>
59#include <vcl/gdimtf.hxx>
60#include <vcl/svapp.hxx>
61#include <vcl/weld.hxx>
64#include <comphelper/lok.hxx>
65#include <LibreOfficeKit/LibreOfficeKitEnums.h>
66#include <tools/link.hxx>
67
69#include <sfx2/sfxresid.hxx>
70#include <sfx2/request.hxx>
71#include <sfx2/printer.hxx>
72#include <sfx2/viewsh.hxx>
73#include <sfx2/dinfdlg.hxx>
74#include <sfx2/docfilt.hxx>
75#include <sfx2/docfile.hxx>
76#include <sfx2/dispatch.hxx>
77#include <sfx2/objitem.hxx>
78#include <sfx2/objsh.hxx>
79#include <objshimp.hxx>
80#include <sfx2/module.hxx>
81#include <sfx2/viewfrm.hxx>
82#include <versdlg.hxx>
83#include <sfx2/strings.hrc>
84#include <sfx2/docfac.hxx>
85#include <sfx2/fcontnr.hxx>
86#include <sfx2/msgpool.hxx>
87#include <sfx2/objface.hxx>
88#include <checkin.hxx>
89#include <sfx2/infobar.hxx>
90#include <sfx2/sfxuno.hxx>
91#include <sfx2/sfxsids.hrc>
93
94#include <com/sun/star/util/XCloseable.hpp>
95#include <com/sun/star/document/XDocumentProperties.hpp>
96
97#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
98#include <com/sun/star/frame/XDesktop2.hpp>
99#include <com/sun/star/frame/Desktop.hpp>
100
101#include <guisaveas.hxx>
102#include <saveastemplatedlg.hxx>
103#include <memory>
108#include <editeng/unoprnms.hxx>
109
110#include <autoredactdialog.hxx>
111
112#include <boost/property_tree/json_parser.hpp>
113
114using namespace ::com::sun::star;
115using namespace ::com::sun::star::lang;
116using namespace ::com::sun::star::uno;
117using namespace ::com::sun::star::ui::dialogs;
118using namespace ::com::sun::star::awt;
119using namespace ::com::sun::star::container;
120using namespace ::com::sun::star::beans;
121using namespace ::com::sun::star::document;
122using namespace ::com::sun::star::security;
123using namespace ::com::sun::star::task;
124using namespace ::com::sun::star::graphic;
125
126#define ShellClass_SfxObjectShell
127#include <sfxslots.hxx>
128
130
131void SfxObjectShell::InitInterface_Impl()
132{
133}
134
135namespace {
136
137class SfxClosePreventer_Impl : public ::cppu::WeakImplHelper< css::util::XCloseListener >
138{
139 bool m_bGotOwnership;
140 bool m_bPreventClose;
141
142public:
143 SfxClosePreventer_Impl();
144
145 bool HasOwnership() const { return m_bGotOwnership; }
146
147 void SetPreventClose( bool bPrevent ) { m_bPreventClose = bPrevent; }
148
149 virtual void SAL_CALL queryClosing( const lang::EventObject& aEvent, sal_Bool bDeliverOwnership ) override;
150
151 virtual void SAL_CALL notifyClosing( const lang::EventObject& aEvent ) override ;
152
153 virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) override ;
154
155} ;
156
157}
158
159SfxClosePreventer_Impl::SfxClosePreventer_Impl()
160: m_bGotOwnership( false )
161, m_bPreventClose( true )
162{
163}
164
165void SAL_CALL SfxClosePreventer_Impl::queryClosing( const lang::EventObject&, sal_Bool bDeliverOwnership )
166{
167 if ( m_bPreventClose )
168 {
169 if ( !m_bGotOwnership )
170 m_bGotOwnership = bDeliverOwnership;
171
172 throw util::CloseVetoException();
173 }
174}
175
176void SAL_CALL SfxClosePreventer_Impl::notifyClosing( const lang::EventObject& )
177{}
178
179void SAL_CALL SfxClosePreventer_Impl::disposing( const lang::EventObject& )
180{}
181
182namespace {
183
184class SfxInstanceCloseGuard_Impl
185{
187 uno::Reference< util::XCloseable > m_xCloseable;
188
189public:
190 SfxInstanceCloseGuard_Impl() {}
191
192 ~SfxInstanceCloseGuard_Impl();
193
194 bool Init_Impl( const uno::Reference< util::XCloseable >& xCloseable );
195};
196
197}
198
199bool SfxInstanceCloseGuard_Impl::Init_Impl( const uno::Reference< util::XCloseable >& xCloseable )
200{
201 bool bResult = false;
202
203 // do not allow reinit after the successful init
204 if ( xCloseable.is() && !m_xCloseable.is() )
205 {
206 try
207 {
208 m_xPreventer = new SfxClosePreventer_Impl();
209 xCloseable->addCloseListener( m_xPreventer );
210 m_xCloseable = xCloseable;
211 bResult = true;
212 }
213 catch( uno::Exception& )
214 {
215 OSL_FAIL( "Could not register close listener!" );
216 }
217 }
218
219 return bResult;
220}
221
222SfxInstanceCloseGuard_Impl::~SfxInstanceCloseGuard_Impl()
223{
224 if ( !m_xCloseable.is() || !m_xPreventer.is() )
225 return;
226
227 try
228 {
229 m_xCloseable->removeCloseListener( m_xPreventer );
230 }
231 catch( uno::Exception& )
232 {
233 }
234
235 try
236 {
237 if ( m_xPreventer.is() )
238 {
239 m_xPreventer->SetPreventClose( false );
240
241 if ( m_xPreventer->HasOwnership() )
242 m_xCloseable->close( true ); // TODO: do it asynchronously
243 }
244 }
245 catch( uno::Exception& )
246 {
247 }
248}
249
250
252{
253 SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this);
254 if ( pFrame )
255 {
256 rReq.SetSlot( SID_PRINTDOC );
257 pFrame->GetViewShell()->ExecuteSlot(rReq);
258 }
259}
260
261
263{
264 bool bPrinting = false;
265 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
266 if ( pFrame )
267 {
268 SfxPrinter *pPrinter = pFrame->GetViewShell()->GetPrinter();
269 bPrinting = pPrinter && pPrinter->IsPrinting();
270 }
271 rSet.Put( SfxBoolItem( SID_PRINTOUT, bPrinting ) );
272}
273
274bool SfxObjectShell::APISaveAs_Impl(std::u16string_view aFileName, SfxItemSet& rItemSet,
275 const css::uno::Sequence<css::beans::PropertyValue>& rArgs)
276{
277 bool bOk = false;
278
279 if ( GetMedium() )
280 {
281 OUString aFilterName;
282 const SfxStringItem* pFilterNameItem = rItemSet.GetItem<SfxStringItem>(SID_FILTER_NAME, false);
283 if( pFilterNameItem )
284 {
285 aFilterName = pFilterNameItem->GetValue();
286 }
287 else
288 {
289 const SfxStringItem* pContentTypeItem = rItemSet.GetItem<SfxStringItem>(SID_CONTENTTYPE, false);
290 if ( pContentTypeItem )
291 {
292 std::shared_ptr<const SfxFilter> pFilter = SfxFilterMatcher( GetFactory().GetFactoryName() ).GetFilter4Mime( pContentTypeItem->GetValue(), SfxFilterFlags::EXPORT );
293 if ( pFilter )
294 aFilterName = pFilter->GetName();
295 }
296 }
297
298 // in case no filter defined use default one
299 if( aFilterName.isEmpty() )
300 {
301 std::shared_ptr<const SfxFilter> pFilt = SfxFilter::GetDefaultFilterFromFactory(GetFactory().GetFactoryName());
302
303 DBG_ASSERT( pFilt, "No default filter!\n" );
304 if( pFilt )
305 aFilterName = pFilt->GetFilterName();
306
307 rItemSet.Put(SfxStringItem(SID_FILTER_NAME, aFilterName));
308 }
309
310
311 {
312 SfxObjectShellRef xLock( this ); // ???
313
314 // use the title that is provided in the media descriptor
315 const SfxStringItem* pDocTitleItem = rItemSet.GetItem<SfxStringItem>(SID_DOCINFO_TITLE, false);
316 if ( pDocTitleItem )
317 getDocProperties()->setTitle( pDocTitleItem->GetValue() );
318
319 bOk = CommonSaveAs_Impl(INetURLObject(aFileName), aFilterName, rItemSet, rArgs);
320 }
321 }
322
323 return bOk;
324}
325
327{
328 try
329 {
330 uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY_THROW );
331 xCmisDoc->checkOut( );
332
333 // Remove the info bar
334 SfxViewFrame* pViewFrame = GetFrame();
335 pViewFrame->RemoveInfoBar( u"checkout" );
336 }
337 catch ( const uno::RuntimeException& e )
338 {
339 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrame()->GetFrameWeld(),
340 VclMessageType::Warning, VclButtonsType::Ok, e.Message));
341 xBox->run();
342 }
343}
344
346{
347 try
348 {
349 uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY_THROW );
350 xCmisDoc->cancelCheckOut( );
351
352 uno::Reference< util::XModifiable > xModifiable( GetModel( ), uno::UNO_QUERY );
353 if ( xModifiable.is( ) )
354 xModifiable->setModified( false );
355 }
356 catch ( const uno::RuntimeException& e )
357 {
358 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrame()->GetFrameWeld(),
359 VclMessageType::Warning, VclButtonsType::Ok, e.Message));
360 xBox->run();
361 }
362}
363
365{
366 try
367 {
368 uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY_THROW );
369 // Pop up dialog to ask for comment and major
370 SfxCheckinDialog checkinDlg(GetFrame()->GetFrameWeld());
371 if (checkinDlg.run() == RET_OK)
372 {
373 xCmisDoc->checkIn(checkinDlg.IsMajor(), checkinDlg.GetComment());
374 uno::Reference< util::XModifiable > xModifiable( GetModel( ), uno::UNO_QUERY );
375 if ( xModifiable.is( ) )
376 xModifiable->setModified( false );
377 }
378 }
379 catch ( const uno::RuntimeException& e )
380 {
381 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrame()->GetFrameWeld(),
382 VclMessageType::Warning, VclButtonsType::Ok, e.Message));
383 xBox->run();
384 }
385}
386
387uno::Sequence< document::CmisVersion > SfxObjectShell::GetCmisVersions( ) const
388{
389 try
390 {
391 uno::Reference< document::XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY_THROW );
392 return xCmisDoc->getAllVersions( );
393 }
394 catch ( const uno::RuntimeException& e )
395 {
396 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrame()->GetFrameWeld(),
397 VclMessageType::Warning, VclButtonsType::Ok, e.Message));
398 xBox->run();
399 }
400 return uno::Sequence< document::CmisVersion > ( );
401}
402
404{
406 {
407 const std::shared_ptr<const SfxFilter>& pFilter = pMedium->GetFilter();
408 if (pFilter && pFilter->GetName() == "draw_pdf_import")
409 return true;
410 }
411
412 return false;
413}
414
415uno::Reference<security::XCertificate> SfxObjectShell::GetSignPDFCertificate() const
416{
417 uno::Reference<frame::XModel> xModel = GetBaseModel();
418 if (!xModel.is())
419 {
420 return uno::Reference<security::XCertificate>();
421 }
422
423 uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY);
424 if (!xShapes.is() || xShapes->getCount() < 1)
425 {
426 return uno::Reference<security::XCertificate>();
427 }
428
429 uno::Reference<beans::XPropertySet> xShapeProps(xShapes->getByIndex(0), uno::UNO_QUERY);
430 if (!xShapeProps.is())
431 {
432 return uno::Reference<security::XCertificate>();
433 }
434
435 if (!xShapeProps->getPropertySetInfo()->hasPropertyByName("InteropGrabBag"))
436 {
437 return uno::Reference<security::XCertificate>();
438 }
439
440 comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag"));
441 auto it = aMap.find("SignatureCertificate");
442 if (it == aMap.end())
443 {
444 return uno::Reference<security::XCertificate>();
445 }
446
447 return uno::Reference<security::XCertificate>(it->second, uno::UNO_QUERY);
448}
449
450static void sendErrorToLOK(ErrCode error)
451{
452 if (error.GetClass() == ErrCodeClass::NONE)
453 return;
454
455 boost::property_tree::ptree aTree;
456 aTree.put("code", error);
457 aTree.put("kind", "");
458 aTree.put("cmd", "");
459
460 std::unique_ptr<ErrorInfo> pInfo = ErrorInfo::GetErrorInfo(error);
461 OUString aErr;
462 if (ErrorStringFactory::CreateString(pInfo.get(), aErr))
463 aTree.put("message", aErr.toUtf8());
464
465 std::stringstream aStream;
466 boost::property_tree::write_json(aStream, aTree);
467
468 SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, OString(aStream.str()));
469}
470
471namespace
472{
473void SetDocProperties(const uno::Reference<document::XDocumentProperties>& xDP,
474 const uno::Sequence<beans::PropertyValue>& rUpdatedProperties)
475{
476 comphelper::SequenceAsHashMap aMap(rUpdatedProperties);
477 OUString aNamePrefix;
478 auto it = aMap.find("NamePrefix");
479 if (it != aMap.end())
480 {
481 it->second >>= aNamePrefix;
482 }
483
484 uno::Sequence<beans::PropertyValue> aUserDefinedProperties;
485 it = aMap.find("UserDefinedProperties");
486 if (it != aMap.end())
487 {
488 it->second >>= aUserDefinedProperties;
489 }
490
491 uno::Reference<beans::XPropertyContainer> xUDP = xDP->getUserDefinedProperties();
492 if (!aNamePrefix.isEmpty())
493 {
494 uno::Reference<beans::XPropertySet> xSet(xUDP, UNO_QUERY);
495 uno::Reference<beans::XPropertySetInfo> xSetInfo = xSet->getPropertySetInfo();
496 const uno::Sequence<beans::Property> aProperties = xSetInfo->getProperties();
497 for (const auto& rProperty : aProperties)
498 {
499 if (!rProperty.Name.startsWith(aNamePrefix))
500 {
501 continue;
502 }
503
504 if (!(rProperty.Attributes & beans::PropertyAttribute::REMOVABLE))
505 {
506 continue;
507 }
508
509 xUDP->removeProperty(rProperty.Name);
510 }
511 }
512
513 for (const auto& rUserDefinedProperty : aUserDefinedProperties)
514 {
515 xUDP->addProperty(rUserDefinedProperty.Name, beans::PropertyAttribute::REMOVABLE,
516 rUserDefinedProperty.Value);
517 }
518}
519}
520
522{
523 weld::Window* pDialogParent = rReq.GetFrameWeld();
524 if (!pDialogParent)
525 {
526 SfxViewFrame* pFrame = GetFrame();
527 if (!pFrame)
528 pFrame = SfxViewFrame::GetFirst(this);
529 if (pFrame)
530 pDialogParent = pFrame->GetFrameWeld();
531 }
532
533 sal_uInt16 nId = rReq.GetSlot();
534
535 bool bHaveWeSigned = false;
536
537 if( SID_SIGNATURE == nId || SID_MACRO_SIGNATURE == nId )
538 {
540 {
541 if (SID_SIGNATURE == nId)
542 {
543 uno::Reference<security::XCertificate> xCertificate = GetSignPDFCertificate();
544 if (xCertificate.is())
545 {
546
547 bHaveWeSigned |= SignDocumentContentUsingCertificate(xCertificate);
548
549 // Reload to show how the PDF actually looks like after signing. This also
550 // changes "finish signing" on the infobar back to "sign document" as a side
551 // effect.
552 SfxViewFrame* pFrame = GetFrame();
553 if (pFrame)
554 {
555 // Store current page before reload.
557 uno::Reference<drawing::XDrawView> xController(
558 GetBaseModel()->getCurrentController(), uno::UNO_QUERY);
559 uno::Reference<beans::XPropertySet> xPage(xController->getCurrentPage(),
560 uno::UNO_QUERY);
561 sal_Int32 nPage{};
562 xPage->getPropertyValue("Number") >>= nPage;
563 if (nPage > 0)
564 {
565 // nPage is 1-based.
566 aSet.Put(SfxInt32Item(SID_PAGE_NUMBER, nPage - 1));
567 }
568 SfxRequest aReq(SID_RELOAD, SfxCallMode::SLOT, aSet);
569 pFrame->ExecReload_Impl(aReq);
570 }
571 }
572 else
573 {
574 bHaveWeSigned |= SignDocumentContent(pDialogParent);
575 }
576 }
577 else
578 {
579 bHaveWeSigned |= SignScriptingContent(pDialogParent);
580 }
581 }
582
583 if ( bHaveWeSigned && HasValidSignatures() )
584 {
585 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( pDialogParent,
586 VclMessageType::Question, VclButtonsType::YesNo, SfxResId(STR_QUERY_REMEMBERSIGNATURE)));
587 if (xBox->run() == RET_YES)
588 {
590 bRememberSignature = true;
591 }
592 else
593 {
594 rSignatureInfosRemembered = uno::Sequence< security::DocumentSignatureInformation >();
595 bRememberSignature = false;
596 }
597 }
598
599 return;
600 }
601
602 if ( !GetMedium() && nId != SID_CLOSEDOC )
603 {
604 rReq.Ignore();
605 return;
606 }
607
608 // this guard is created here to have it destruction at the end of the method
609 SfxInstanceCloseGuard_Impl aModelGuard;
610
611 bool bIsPDFExport = false;
612 bool bIsAutoRedact = false;
613 bool bIsAsync = false;
614 std::vector<std::pair<RedactionTarget, OUString>> aRedactionTargets;
615 switch(nId)
616 {
617 case SID_VERSION:
618 {
619 SfxViewFrame* pFrame = GetFrame();
620 if ( !pFrame )
621 pFrame = SfxViewFrame::GetFirst( this );
622 if ( !pFrame )
623 return;
624
625 if ( !IsOwnStorageFormat( *GetMedium() ) )
626 return;
627
628 SfxVersionDialog aDlg(pDialogParent, pFrame, IsSaveVersionOnClose());
629 aDlg.run();
631 rReq.Done();
632 return;
633 }
634
635 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
636 case SID_DOCINFO:
637 {
638 const SfxDocumentInfoItem* pDocInfItem = rReq.GetArg<SfxDocumentInfoItem>(SID_DOCINFO);
639 if ( pDocInfItem )
640 {
641 // parameter, e.g. from replayed macro
642 pDocInfItem->UpdateDocumentInfo(getDocProperties(), true);
643 SetUseUserData( pDocInfItem->IsUseUserData() );
644 SetUseThumbnailSave( pDocInfItem->IsUseThumbnailSave() );
645 }
646 else if (const SfxUnoAnyItem* pItem = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_1))
647 {
648 uno::Sequence<beans::PropertyValue> aUpdatedProperties;
649 pItem->GetValue() >>= aUpdatedProperties;
650 SetDocProperties(getDocProperties(), aUpdatedProperties);
651 }
652 else
653 {
654 // no argument containing DocInfo; check optional arguments
655 bool bReadOnly = IsReadOnly();
656 const SfxBoolItem* pROItem = rReq.GetArg<SfxBoolItem>(SID_DOC_READONLY);
657 if ( pROItem )
658 // override readonly attribute of document
659 // e.g. if a readonly document is saved elsewhere and user asks for editing DocInfo before
660 bReadOnly = pROItem->GetValue();
661
662 // URL for dialog
663 const OUString aURL( HasName() ? GetMedium()->GetName() : GetFactory().GetFactoryURL() );
664
665 Reference< XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY );
666 uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties();
667
668 SfxDocumentInfoItem aDocInfoItem( aURL, getDocProperties(), aCmisProperties,
670 if ( !GetSlotState( SID_DOCTEMPLATE ) )
671 // templates not supported
672 aDocInfoItem.SetTemplate(false);
673
674 SfxItemSetFixed<SID_DOCINFO, SID_DOCINFO, SID_DOC_READONLY, SID_DOC_READONLY,
675 SID_EXPLORER_PROPS_START, SID_EXPLORER_PROPS_START, SID_BASEURL, SID_BASEURL>
676 aSet(GetPool());
677 aSet.Put( aDocInfoItem );
678 aSet.Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
679 aSet.Put( SfxStringItem( SID_EXPLORER_PROPS_START, GetTitle() ) );
680 aSet.Put( SfxStringItem( SID_BASEURL, GetMedium()->GetBaseURL() ) );
681
682 // creating dialog is done via virtual method; application will
683 // add its own statistics page
684 std::shared_ptr<SfxDocumentInfoDialog> xDlg(CreateDocumentInfoDialog(rReq.GetFrameWeld(), aSet));
685 auto aFunc = [this, xDlg, xCmisDoc](sal_Int32 nResult, SfxRequest& rRequest)
686 {
687 if (RET_OK == nResult)
688 {
689 const SfxDocumentInfoItem* pDocInfoItem = SfxItemSet::GetItem(xDlg->GetOutputItemSet(), SID_DOCINFO, false);
690 if ( pDocInfoItem )
691 {
692 // user has done some changes to DocumentInfo
693 pDocInfoItem->UpdateDocumentInfo(getDocProperties());
694 const uno::Sequence< document::CmisProperty >& aNewCmisProperties =
695 pDocInfoItem->GetCmisProperties( );
696 if ( aNewCmisProperties.hasElements( ) )
697 xCmisDoc->updateCmisProperties( aNewCmisProperties );
698 SetUseUserData( pDocInfoItem->IsUseUserData() );
699 SetUseThumbnailSave( pDocInfoItem-> IsUseThumbnailSave() );
700 // add data from dialog for possible recording purpose
701 rRequest.AppendItem( SfxDocumentInfoItem( GetTitle(),
702 getDocProperties(), aNewCmisProperties, IsUseUserData(), IsUseThumbnailSave() ) );
703 }
704 rRequest.Done();
705 }
706 else
707 {
708 // nothing done; no recording
709 rRequest.Ignore();
710 }
711 };
712
713 if (!rReq.IsSynchronCall())
714 {
715 std::shared_ptr<SfxRequest> pReq = std::make_shared<SfxRequest>(rReq);
716 SfxTabDialogController::runAsync(xDlg, [pReq, aFunc](sal_Int32 nResult)
717 {
718 aFunc(nResult, *pReq);
719 });
720 rReq.Ignore();
721 }
722 else
723 {
724 aFunc(xDlg->run(), rReq);
725 }
726 }
727
728 return;
729 }
730
731 case SID_AUTOREDACTDOC:
732 {
733 // Actual redaction takes place on a newly generated Draw document
734 if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DRAW))
735 {
736 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
737 pDialogParent, VclMessageType::Warning, VclButtonsType::Ok,
738 SfxResId(STR_REDACTION_NO_DRAW_WARNING)));
739
740 xBox->run();
741
742 return;
743 }
744
745 SfxAutoRedactDialog aDlg(pDialogParent);
746 sal_Int16 nResult = aDlg.run();
747
748 if (nResult != RET_OK || !aDlg.hasTargets() || !aDlg.isValidState())
749 {
750 //Do nothing
751 return;
752 }
753
754 // else continue with normal redaction
755 bIsAutoRedact = true;
756 aDlg.getTargets(aRedactionTargets);
757
758 [[fallthrough]];
759 }
760
761 case SID_REDACTDOC:
762 {
763 css::uno::Reference<css::frame::XModel> xModel = GetModel();
764 if(!xModel.is())
765 return;
766
767 uno::Reference< lang::XComponent > xSourceDoc( xModel );
768
769 // Actual redaction takes place on a newly generated Draw document
770 if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DRAW))
771 {
772 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
773 pDialogParent, VclMessageType::Warning, VclButtonsType::Ok,
774 SfxResId(STR_REDACTION_NO_DRAW_WARNING)));
775
776 xBox->run();
777
778 return;
779 }
780
781 DocumentToGraphicRenderer aRenderer(xSourceDoc, false);
782
783 // Get the page margins of the original doc
784 PageMargins aPageMargins = {-1, -1, -1, -1};
785 if (aRenderer.isWriter())
787 else if (aRenderer.isCalc())
789
790 sal_Int32 nPages = aRenderer.getPageCount();
791 std::vector< GDIMetaFile > aMetaFiles;
792 std::vector< ::Size > aPageSizes;
793
794 // Convert the pages of the document to gdimetafiles
795 SfxRedactionHelper::getPageMetaFilesFromDoc(aMetaFiles, aPageSizes, nPages, aRenderer);
796
797 // Create an empty Draw component.
798 uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext());
799 uno::Reference<lang::XComponent> xComponent = xDesktop->loadComponentFromURL("private:factory/sdraw", "_default", 0, {});
800
801 if (!xComponent.is())
802 {
803 SAL_WARN("sfx.doc", "SID_REDACTDOC: Failed to load new draw component. loadComponentFromURL returned an empty reference.");
804
805 return;
806 }
807
808 // Add the doc pages to the new draw document
809 SfxRedactionHelper::addPagesToDraw(xComponent, nPages, aMetaFiles, aPageSizes, aPageMargins, aRedactionTargets, bIsAutoRedact);
810
811 // Show the Redaction toolbar
812 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
813 if (!pViewFrame)
814 return;
816
817 return;
818 }
819
820 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
821 case SID_DIRECTEXPORTDOCASPDF:
822 {
823 uno::Reference< lang::XComponent > xComponent( GetCurrentComponent(), uno::UNO_QUERY );
824 if (!xComponent.is())
825 return;
826
827 uno::Reference< lang::XServiceInfo > xServiceInfo( xComponent, uno::UNO_QUERY);
828
829 // Redaction finalization takes place in Draw
830 if ( xServiceInfo.is() && xServiceInfo->supportsService("com.sun.star.drawing.DrawingDocument")
832 {
833 OUString sRedactionStyle(SfxRedactionHelper::getStringParam(rReq, SID_REDACTION_STYLE));
834
835 // Access the draw pages
836 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
837 uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
838
839 sal_Int32 nPageCount = xDrawPages->getCount();
840 for (sal_Int32 nPageNum = 0; nPageNum < nPageCount; ++nPageNum)
841 {
842 // Get the page
843 uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( nPageNum ), uno::UNO_QUERY );
844
845 if (!xPage.is())
846 continue;
847
848 // Go through all shapes
849 sal_Int32 nShapeCount = xPage->getCount();
850 for (sal_Int32 nShapeNum = 0; nShapeNum < nShapeCount; ++nShapeNum)
851 {
852 uno::Reference< drawing::XShape > xCurrShape(xPage->getByIndex(nShapeNum), uno::UNO_QUERY);
853 if (!xCurrShape.is())
854 continue;
855
856 uno::Reference< beans::XPropertySet > xPropSet(xCurrShape, uno::UNO_QUERY);
857 if (!xPropSet.is())
858 continue;
859
860 uno::Reference< beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
861 if (!xInfo.is())
862 continue;
863
864 OUString sShapeName;
865 if (xInfo->hasPropertyByName("Name"))
866 {
867 uno::Any aAnyShapeName = xPropSet->getPropertyValue("Name");
868 aAnyShapeName >>= sShapeName;
869 }
870 else
871 continue;
872
873 // Rectangle redaction
874 if (sShapeName == "RectangleRedactionShape"
875 && xInfo->hasPropertyByName("FillTransparence") && xInfo->hasPropertyByName("FillColor"))
876 {
877 xPropSet->setPropertyValue("FillTransparence", css::uno::Any(static_cast<sal_Int16>(0)));
878 if (sRedactionStyle == "White")
879 {
880 xPropSet->setPropertyValue("FillColor", css::uno::Any(COL_WHITE));
881 xPropSet->setPropertyValue("LineStyle", css::uno::Any(css::drawing::LineStyle::LineStyle_SOLID));
882 xPropSet->setPropertyValue("LineColor", css::uno::Any(COL_BLACK));
883 }
884 else
885 {
886 xPropSet->setPropertyValue("FillColor", css::uno::Any(COL_BLACK));
887 xPropSet->setPropertyValue("LineStyle", css::uno::Any(css::drawing::LineStyle::LineStyle_NONE));
888 }
889 }
890 // Freeform redaction
891 else if (sShapeName == "FreeformRedactionShape"
892 && xInfo->hasPropertyByName("LineTransparence") && xInfo->hasPropertyByName("LineColor"))
893 {
894 xPropSet->setPropertyValue("LineTransparence", css::uno::Any(static_cast<sal_Int16>(0)));
895
896 if (sRedactionStyle == "White")
897 {
898 xPropSet->setPropertyValue("LineColor", css::uno::Any(COL_WHITE));
899 }
900 else
901 {
902 xPropSet->setPropertyValue("LineColor", css::uno::Any(COL_BLACK));
903 }
904 }
905 }
906 }
907 }
908 }
909 [[fallthrough]];
910 case SID_EXPORTDOCASPDF:
911 bIsPDFExport = true;
912 [[fallthrough]];
913 case SID_EXPORTDOCASEPUB:
914 case SID_DIRECTEXPORTDOCASEPUB:
915 case SID_EXPORTDOC:
916 case SID_SAVEASDOC:
917 case SID_SAVEASREMOTE:
918 case SID_SAVEDOC:
919 {
920 // so far only pdf and epub support Async interface
922 && (nId == SID_EXPORTDOCASEPUB || nId == SID_EXPORTDOCASPDF))
923 bIsAsync = true;
924
925 // derived class may decide to abort this
926 if( !QuerySlotExecutable( nId ) )
927 {
928 rReq.SetReturnValue( SfxBoolItem( 0, false ) );
929 return;
930 }
931
933 SfxObjectShellRef xLock( this );
934
935 // the model can not be closed till the end of this method
936 // if somebody tries to close it during this time the model will be closed
937 // at the end of the method
938 aModelGuard.Init_Impl( uno::Reference< util::XCloseable >( GetModel(), uno::UNO_QUERY ) );
939
940 ErrCode nErrorCode = ERRCODE_NONE;
941
942 // by default versions should be preserved always except in case of an explicit
943 // SaveAs via GUI, so the flag must be set accordingly
944 pImpl->bPreserveVersions = (nId == SID_SAVEDOC);
945 try
946 {
948
949 if ( nId == SID_SAVEASDOC || nId == SID_SAVEASREMOTE )
950 {
951 // in case of plugin mode the SaveAs operation means SaveTo
952 const SfxBoolItem* pViewOnlyItem = GetMedium()->GetItemSet().GetItem(SID_VIEWONLY, false);
953 if ( pViewOnlyItem && pViewOnlyItem->GetValue() )
954 rReq.AppendItem( SfxBoolItem( SID_SAVETO, true ) );
955 }
956
957 // TODO/LATER: do the following GUI related actions in standalone method
958
959 // Introduce a status indicator for GUI operation
960 const SfxUnoAnyItem* pStatusIndicatorItem = rReq.GetArg<SfxUnoAnyItem>(SID_PROGRESS_STATUSBAR_CONTROL);
961 if ( !pStatusIndicatorItem )
962 {
963 // get statusindicator
964 uno::Reference< task::XStatusIndicator > xStatusIndicator;
965 uno::Reference < frame::XController > xCtrl( GetModel()->getCurrentController() );
966 if ( xCtrl.is() )
967 {
968 uno::Reference< task::XStatusIndicatorFactory > xStatFactory( xCtrl->getFrame(), uno::UNO_QUERY );
969 if( xStatFactory.is() )
970 xStatusIndicator = xStatFactory->createStatusIndicator();
971 }
972
973 OSL_ENSURE( xStatusIndicator.is(), "Can not retrieve default status indicator!" );
974
975 if ( xStatusIndicator.is() )
976 {
977 SfxUnoAnyItem aStatIndItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::Any( xStatusIndicator ) );
978
979 if ( nId == SID_SAVEDOC )
980 {
981 // in case of saving it is not possible to transport the parameters from here
982 // but it is not clear here whether the saving will be done or saveAs operation
983 GetMedium()->GetItemSet().Put( aStatIndItem );
984 }
985
986 rReq.AppendItem( aStatIndItem );
987 }
988 }
989 else if ( nId == SID_SAVEDOC )
990 {
991 // in case of saving it is not possible to transport the parameters from here
992 // but it is not clear here whether the saving will be done or saveAs operation
993 GetMedium()->GetItemSet().Put( *pStatusIndicatorItem );
994 }
995
996 // Introduce an interaction handler for GUI operation
997 const SfxUnoAnyItem* pInteractionHandlerItem = rReq.GetArg<SfxUnoAnyItem>(SID_INTERACTIONHANDLER);
998 if ( !pInteractionHandlerItem )
999 {
1000 uno::Reference<css::awt::XWindow> xParentWindow;
1001 uno::Reference<frame::XController> xCtrl(GetModel()->getCurrentController());
1002 if (xCtrl.is())
1003 xParentWindow = xCtrl->getFrame()->getContainerWindow();
1004
1005 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1006
1007 uno::Reference< task::XInteractionHandler2 > xInteract(
1008 task::InteractionHandler::createWithParent(xContext, xParentWindow) );
1009
1010 SfxUnoAnyItem aInteractionItem( SID_INTERACTIONHANDLER, uno::Any( xInteract ) );
1011 if ( nId == SID_SAVEDOC )
1012 {
1013 // in case of saving it is not possible to transport the parameters from here
1014 // but it is not clear here whether the saving will be done or saveAs operation
1015 GetMedium()->GetItemSet().Put( aInteractionItem );
1016 }
1017
1018 rReq.AppendItem( aInteractionItem );
1019 }
1020 else if ( nId == SID_SAVEDOC )
1021 {
1022 // in case of saving it is not possible to transport the parameters from here
1023 // but it is not clear here whether the saving will be done or saveAs operation
1024 GetMedium()->GetItemSet().Put( *pInteractionHandlerItem );
1025 }
1026
1027
1028 const SfxStringItem* pOldPasswordItem = GetMedium()->GetItemSet().GetItem(SID_PASSWORD, false);
1029 const SfxUnoAnyItem* pOldEncryptionDataItem = GetMedium()->GetItemSet().GetItem(SID_ENCRYPTIONDATA, false);
1030 const bool bPreselectPassword
1031 = pOldPasswordItem || pOldEncryptionDataItem
1032 || (IsLoadReadonly()
1033 && (GetModifyPasswordHash() || GetModifyPasswordInfo().hasElements()));
1034
1035 uno::Sequence< beans::PropertyValue > aDispatchArgs;
1036 if ( rReq.GetArgs() )
1038 *rReq.GetArgs(),
1039 aDispatchArgs );
1040
1041 bool bForceSaveAs = nId == SID_SAVEDOC && IsReadOnlyMedium();
1042 const SfxSlot* pSlot = GetModule()->GetSlotPool()->GetSlot( bForceSaveAs ? SID_SAVEASDOC : nId );
1043 if ( !pSlot )
1044 throw uno::Exception("no slot", nullptr);
1045
1046 std::shared_ptr<SfxStoringHelper> xHelper = std::make_shared<SfxStoringHelper>();
1047 if (bIsAsync && SfxViewShell::Current())
1049
1051 {
1052 // the user has decided not to store the document
1053 throw task::ErrorCodeIOException(
1054 "SfxObjectShell::ExecFile_Impl: ERRCODE_IO_ABORT",
1055 uno::Reference< uno::XInterface >(), sal_uInt32(ERRCODE_IO_ABORT));
1056 }
1057
1058 const SfxBoolItem *pItem = nId != SID_DIRECTEXPORTDOCASPDF ? nullptr :
1059 dynamic_cast<const SfxBoolItem*>( GetSlotState(SID_MAIL_PREPAREEXPORT) );
1060 // Fetch value from the pool item early, because GUIStoreModel() can free the pool
1061 // item as part of spinning the main loop if a dialog is opened.
1062 bool bMailPrepareExport = pItem && pItem->GetValue();
1063 if (bMailPrepareExport)
1064 {
1065 SfxRequest aRequest(SID_MAIL_PREPAREEXPORT, SfxCallMode::SYNCHRON, GetPool());
1066 aRequest.AppendItem(SfxBoolItem(FN_NOUPDATE, true));
1067 ExecuteSlot(aRequest);
1068 }
1069
1070 xHelper->GUIStoreModel( GetModel(),
1071 pSlot->GetUnoName(),
1072 aDispatchArgs,
1073 bPreselectPassword,
1075 bIsAsync );
1076
1077 if (bMailPrepareExport)
1078 {
1079 SfxRequest aRequest(SID_MAIL_EXPORT_FINISHED, SfxCallMode::SYNCHRON, GetPool());
1080 ExecuteSlot(aRequest);
1081 }
1082
1083 // merge aDispatchArgs to the request
1084 SfxAllItemSet aResultParams( GetPool() );
1086 aDispatchArgs,
1087 aResultParams );
1088 rReq.SetArgs( aResultParams );
1089
1090 // the StoreAsURL/StoreToURL method have called this method with false
1091 // so it has to be restored to true here since it is a call from GUI
1092 GetMedium()->SetUpdatePickList( true );
1093
1094 // TODO: in future it must be done in following way
1095 // if document is opened from GUI, it immediately appears in the picklist
1096 // if the document is a new one then it appears in the picklist immediately
1097 // after SaveAs operation triggered from GUI
1098 }
1099 catch( const task::ErrorCodeIOException& aErrorEx )
1100 {
1101 TOOLS_WARN_EXCEPTION_IF(ErrCode(aErrorEx.ErrCode) != ERRCODE_IO_ABORT, "sfx.doc", "Fatal IO error during save");
1102 nErrorCode = ErrCode(aErrorEx.ErrCode);
1103 }
1104 catch( Exception& )
1105 {
1106 nErrorCode = ERRCODE_IO_GENERAL;
1107 }
1108
1109 // by default versions should be preserved always except in case of an explicit
1110 // SaveAs via GUI, so the flag must be reset to guarantee this
1111 pImpl->bPreserveVersions = true;
1112 ErrCode lErr=GetErrorCode();
1113
1114 if ( !lErr && nErrorCode )
1115 lErr = nErrorCode;
1116
1117 if ( lErr && nErrorCode == ERRCODE_NONE )
1118 {
1119 const SfxBoolItem* pWarnItem = rReq.GetArg<SfxBoolItem>(SID_FAIL_ON_WARNING);
1120 if ( pWarnItem && pWarnItem->GetValue() )
1121 nErrorCode = lErr;
1122 }
1123
1124 // may be nErrorCode should be shown in future
1125 if ( lErr != ERRCODE_IO_ABORT )
1126 {
1128 sendErrorToLOK(lErr);
1129 else if (!(lErr == ERRCODE_IO_GENERAL && bIsPDFExport))
1130 {
1132 ErrorHandler::HandleError(lErr, pDialogParent);
1133 }
1134 }
1135
1136 if (nId == SID_DIRECTEXPORTDOCASPDF &&
1138 {
1139 // Return the finalized redaction shapes back to normal (gray & transparent)
1140 uno::Reference< lang::XComponent > xComponent( GetCurrentComponent(), uno::UNO_QUERY );
1141 if (!xComponent.is())
1142 return;
1143
1144 uno::Reference< lang::XServiceInfo > xServiceInfo( xComponent, uno::UNO_QUERY);
1145
1146 // Redaction finalization takes place in Draw
1147 if ( xServiceInfo.is() && xServiceInfo->supportsService("com.sun.star.drawing.DrawingDocument") )
1148 {
1149 // Access the draw pages
1150 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
1151 uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
1152
1153 sal_Int32 nPageCount = xDrawPages->getCount();
1154 for (sal_Int32 nPageNum = 0; nPageNum < nPageCount; ++nPageNum)
1155 {
1156 // Get the page
1157 uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( nPageNum ), uno::UNO_QUERY );
1158
1159 if (!xPage.is())
1160 continue;
1161
1162 // Go through all shapes
1163 sal_Int32 nShapeCount = xPage->getCount();
1164 for (sal_Int32 nShapeNum = 0; nShapeNum < nShapeCount; ++nShapeNum)
1165 {
1166 uno::Reference< drawing::XShape > xCurrShape(xPage->getByIndex(nShapeNum), uno::UNO_QUERY);
1167 if (!xCurrShape.is())
1168 continue;
1169
1170 uno::Reference< beans::XPropertySet > xPropSet(xCurrShape, uno::UNO_QUERY);
1171 if (!xPropSet.is())
1172 continue;
1173
1174 uno::Reference< beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
1175 if (!xInfo.is())
1176 continue;
1177
1178 // Not a shape we converted?
1179 if (!xInfo->hasPropertyByName("Name"))
1180 continue;
1181
1182 OUString sShapeName;
1183 if (xInfo->hasPropertyByName("Name"))
1184 {
1185 uno::Any aAnyShapeName = xPropSet->getPropertyValue("Name");
1186 aAnyShapeName >>= sShapeName;
1187 }
1188 else
1189 continue;
1190
1191 // Rectangle redaction
1192 if (sShapeName == "RectangleRedactionShape"
1193 && xInfo->hasPropertyByName("FillTransparence") && xInfo->hasPropertyByName("FillColor"))
1194 {
1195 xPropSet->setPropertyValue("FillTransparence", css::uno::Any(static_cast<sal_Int16>(50)));
1196 xPropSet->setPropertyValue("FillColor", css::uno::Any(COL_GRAY7));
1197 xPropSet->setPropertyValue("LineStyle", css::uno::Any(css::drawing::LineStyle::LineStyle_NONE));
1198
1199 }
1200 // Freeform redaction
1201 else if (sShapeName == "FreeformRedactionShape")
1202 {
1203 xPropSet->setPropertyValue("LineTransparence", css::uno::Any(static_cast<sal_Int16>(50)));
1204 xPropSet->setPropertyValue("LineColor", css::uno::Any(COL_GRAY7));
1205 }
1206 }
1207 }
1208
1209
1210 }
1211 }
1212
1213 if ( nId == SID_EXPORTDOCASPDF )
1214 {
1215 // This function is used by the SendMail function that needs information if an export
1216 // file was written or not. This could be due to cancellation of the export
1217 // or due to an error. So IO abort must be handled like an error!
1218 nErrorCode = ( lErr != ERRCODE_IO_ABORT ) && ( nErrorCode == ERRCODE_NONE ) ? nErrorCode : lErr;
1219 }
1220
1221 if ( ( nId == SID_SAVEASDOC || nId == SID_SAVEASREMOTE ) && nErrorCode == ERRCODE_NONE )
1222 {
1223 const SfxBoolItem* saveTo = rReq.GetArg<SfxBoolItem>(SID_SAVETO);
1224 if (saveTo == nullptr || !saveTo->GetValue())
1225 {
1226 SfxViewFrame *pFrame = GetFrame();
1227 if (pFrame)
1228 pFrame->RemoveInfoBar(u"readonly");
1229 SetReadOnlyUI(false);
1230 }
1231 }
1232
1233 if (nId == SID_SAVEDOC && bRememberSignature && rSignatureInfosRemembered.hasElements())
1235
1236 rReq.SetReturnValue( SfxBoolItem(0, nErrorCode == ERRCODE_NONE ) );
1237
1238 ResetError();
1239
1240 Invalidate();
1241 break;
1242 }
1243
1244 case SID_SAVEACOPY:
1245 {
1246 SfxAllItemSet aArgs( GetPool() );
1247 aArgs.Put( SfxBoolItem( SID_SAVEACOPYITEM, true ) );
1248 SfxRequest aSaveACopyReq( SID_EXPORTDOC, SfxCallMode::API, aArgs );
1249 ExecFile_Impl( aSaveACopyReq );
1250 if ( !aSaveACopyReq.IsDone() )
1251 {
1252 rReq.Ignore();
1253 return;
1254 }
1255 break;
1256 }
1257
1258 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1259
1260 case SID_CLOSEDOC:
1261 {
1262 // Evaluate Parameter
1263 const SfxBoolItem* pSaveItem = rReq.GetArg<SfxBoolItem>(SID_CLOSEDOC_SAVE);
1264 const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_CLOSEDOC_FILENAME);
1265 if ( pSaveItem )
1266 {
1267 if ( pSaveItem->GetValue() )
1268 {
1269 if ( !pNameItem )
1270 {
1271#if HAVE_FEATURE_SCRIPTING
1273#endif
1274 rReq.Ignore();
1275 return;
1276 }
1277 SfxAllItemSet aArgs( GetPool() );
1278 SfxStringItem aTmpItem( SID_FILE_NAME, pNameItem->GetValue() );
1279 aArgs.Put( aTmpItem, aTmpItem.Which() );
1280 SfxRequest aSaveAsReq( SID_SAVEASDOC, SfxCallMode::API, aArgs );
1281 ExecFile_Impl( aSaveAsReq );
1282 if ( !aSaveAsReq.IsDone() )
1283 {
1284 rReq.Ignore();
1285 return;
1286 }
1287 }
1288 else
1289 SetModified(false);
1290 }
1291
1292 // Cancelled by the user?
1293 if (!PrepareClose())
1294 {
1295 rReq.SetReturnValue( SfxBoolItem(0, false) );
1296 rReq.Done();
1297 return;
1298 }
1299
1300 SetModified( false );
1301 ErrCode lErr = GetErrorCode();
1302
1304 sendErrorToLOK(lErr);
1305 else
1306 ErrorHandler::HandleError(lErr, pDialogParent);
1307
1308 rReq.SetReturnValue( SfxBoolItem(0, true) );
1309 rReq.Done();
1310 rReq.ReleaseArgs(); // because the pool is destroyed in Close
1311 DoClose();
1312 return;
1313 }
1314
1315 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1316 case SID_DOCTEMPLATE:
1317 {
1318 // save as document templates
1319 SfxSaveAsTemplateDialog aDlg(pDialogParent, GetModel());
1320 (void)aDlg.run();
1321 break;
1322 }
1323
1324 case SID_CHECKOUT:
1325 {
1326 CheckOut( );
1327 break;
1328 }
1329 case SID_CANCELCHECKOUT:
1330 {
1331 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
1332 VclMessageType::Question, VclButtonsType::YesNo, SfxResId(STR_QUERY_CANCELCHECKOUT)));
1333 if (xBox->run() == RET_YES)
1334 {
1335 CancelCheckOut( );
1336
1337 // Reload the document as we may still have local changes
1338 SfxViewFrame *pFrame = GetFrame();
1339 if ( pFrame )
1340 pFrame->GetDispatcher()->Execute(SID_RELOAD);
1341 }
1342 break;
1343 }
1344 case SID_CHECKIN:
1345 {
1346 CheckIn( );
1347 break;
1348 }
1349 }
1350
1351 // Prevent entry in the Pick-lists
1352 if ( rReq.IsAPI() )
1353 GetMedium()->SetUpdatePickList( false );
1354
1355 // Ignore()-branches have already returned
1356 rReq.Done();
1357}
1358
1359
1361{
1362 SfxWhichIter aIter( rSet );
1363
1364 for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
1365 {
1366 switch ( nWhich )
1367 {
1368 case SID_DOCTEMPLATE :
1369 {
1370 if ( isExportLocked())
1371 rSet.DisableItem( nWhich );
1372 break;
1373 }
1374
1375 case SID_CHECKOUT:
1376 {
1377 bool bShow = false;
1378 Reference< XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY );
1379 const uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties();
1380
1381 if ( xCmisDoc->isVersionable( ) && aCmisProperties.hasElements( ) )
1382 {
1383 // Loop over the CMIS Properties to find cmis:isVersionSeriesCheckedOut
1384 bool bIsGoogleFile = false;
1385 bool bCheckedOut = false;
1386 for ( const auto& rCmisProperty : aCmisProperties )
1387 {
1388 if ( rCmisProperty.Id == "cmis:isVersionSeriesCheckedOut" )
1389 {
1390 uno::Sequence< sal_Bool > bTmp;
1391 rCmisProperty.Value >>= bTmp;
1392 bCheckedOut = bTmp[0];
1393 }
1394 // using title to know if it's a Google Drive file
1395 // maybe there's a safer way.
1396 if ( rCmisProperty.Name == "title" )
1397 bIsGoogleFile = true;
1398 }
1399 bShow = !bCheckedOut && !bIsGoogleFile;
1400 }
1401
1402 if ( !bShow )
1403 {
1404 rSet.DisableItem( nWhich );
1405 rSet.Put( SfxVisibilityItem( nWhich, false ) );
1406 }
1407 }
1408 break;
1409
1410 case SID_CANCELCHECKOUT:
1411 case SID_CHECKIN:
1412 {
1413 bool bShow = false;
1414 Reference< XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY );
1415 const uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties( );
1416
1417 if ( xCmisDoc->isVersionable( ) && aCmisProperties.hasElements( ) )
1418 {
1419 // Loop over the CMIS Properties to find cmis:isVersionSeriesCheckedOut
1420 bool bCheckedOut = false;
1421 auto pProp = std::find_if(aCmisProperties.begin(), aCmisProperties.end(),
1422 [](const document::CmisProperty& rProp) { return rProp.Id == "cmis:isVersionSeriesCheckedOut"; });
1423 if (pProp != aCmisProperties.end())
1424 {
1425 uno::Sequence< sal_Bool > bTmp;
1426 pProp->Value >>= bTmp;
1427 bCheckedOut = bTmp[0];
1428 }
1429 bShow = bCheckedOut;
1430 }
1431
1432 if ( !bShow )
1433 {
1434 rSet.DisableItem( nWhich );
1435 rSet.Put( SfxVisibilityItem( nWhich, false ) );
1436 }
1437 }
1438 break;
1439
1440 case SID_VERSION:
1441 {
1442 SfxObjectShell *pDoc = this;
1443 SfxViewFrame* pFrame = GetFrame();
1444 if ( !pFrame )
1445 pFrame = SfxViewFrame::GetFirst( this );
1446
1447 if ( !pFrame || !pDoc->HasName() ||
1448 !IsOwnStorageFormat( *pDoc->GetMedium() ) )
1449 rSet.DisableItem( nWhich );
1450 break;
1451 }
1452 case SID_SAVEDOC:
1453 {
1454 if ( IsReadOnly() || isSaveLocked())
1455 {
1456 rSet.DisableItem(nWhich);
1457 break;
1458 }
1459 rSet.Put(SfxStringItem(nWhich, SfxResId(STR_SAVEDOC)));
1460 }
1461 break;
1462
1463 case SID_DOCINFO:
1464 break;
1465
1466 case SID_CLOSEDOC:
1467 {
1468 rSet.Put(SfxStringItem(nWhich, SfxResId(STR_CLOSEDOC)));
1469 break;
1470 }
1471
1472 case SID_SAVEASDOC:
1473 {
1474 if (!(pImpl->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT)
1475 || isExportLocked())
1476 {
1477 rSet.DisableItem( nWhich );
1478 break;
1479 }
1480 if ( !GetMedium() )
1481 rSet.DisableItem( nWhich );
1482 else
1483 rSet.Put( SfxStringItem( nWhich, SfxResId(STR_SAVEASDOC) ) );
1484 break;
1485 }
1486
1487 case SID_SAVEACOPY:
1488 {
1489 if (!(pImpl->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT) || isExportLocked())
1490 {
1491 rSet.DisableItem( nWhich );
1492 break;
1493 }
1494 if ( !GetMedium() )
1495 rSet.DisableItem( nWhich );
1496 else
1497 rSet.Put( SfxStringItem( nWhich, SfxResId(STR_SAVEACOPY) ) );
1498 break;
1499 }
1500
1501 case SID_EXPORTDOC:
1502 case SID_EXPORTDOCASPDF:
1503 case SID_DIRECTEXPORTDOCASPDF:
1504 case SID_EXPORTDOCASEPUB:
1505 case SID_DIRECTEXPORTDOCASEPUB:
1506 case SID_REDACTDOC:
1507 case SID_AUTOREDACTDOC:
1508 case SID_SAVEASREMOTE:
1509 {
1510 if (isExportLocked())
1511 rSet.DisableItem( nWhich );
1512 break;
1513 }
1514
1515 case SID_DOC_MODIFIED:
1516 {
1517 rSet.Put( SfxBoolItem( SID_DOC_MODIFIED, IsModified() ) );
1518 break;
1519 }
1520
1521 case SID_MODIFIED:
1522 {
1523 rSet.Put( SfxBoolItem( SID_MODIFIED, IsModified() ) );
1524 break;
1525 }
1526
1527 case SID_DOCINFO_TITLE:
1528 {
1530 SID_DOCINFO_TITLE, getDocProperties()->getTitle() ) );
1531 break;
1532 }
1533 case SID_FILE_NAME:
1534 {
1535 if( GetMedium() && HasName() )
1537 SID_FILE_NAME, GetMedium()->GetName() ) );
1538 break;
1539 }
1540 case SID_SIGNATURE:
1541 {
1542 SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this);
1543 if ( pFrame )
1544 {
1546 InfobarType aInfobarType(InfobarType::INFO);
1547 OUString sMessage("");
1548
1549 switch (eState)
1550 {
1552 sMessage = SfxResId(STR_SIGNATURE_BROKEN);
1553 aInfobarType = InfobarType::DANGER;
1554 break;
1556 // If we are remembering the certificates, it should be kept as valid
1557 sMessage = SfxResId(bRememberSignature ? STR_SIGNATURE_OK : STR_SIGNATURE_INVALID);
1558 // Warning only, I've tried Danger and it looked too scary
1560 break;
1562 sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED);
1563 aInfobarType = InfobarType::WARNING;
1564 break;
1566 sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK);
1567 aInfobarType = InfobarType::WARNING;
1568 break;
1569 case SignatureState::OK:
1570 sMessage = SfxResId(STR_SIGNATURE_OK);
1571 aInfobarType = InfobarType::INFO;
1572 break;
1574 sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED_PARTIAL_OK);
1575 aInfobarType = InfobarType::WARNING;
1576 break;
1577 //FIXME SignatureState::Unknown, own message?
1578 default:
1579 break;
1580 }
1581
1582 // new info bar
1583 if ( !pFrame->HasInfoBarWithID(u"signature") )
1584 {
1585 if ( !sMessage.isEmpty() )
1586 {
1587 auto pInfoBar = pFrame->AppendInfoBar("signature", "", sMessage, aInfobarType);
1588 if (pInfoBar == nullptr || pInfoBar->isDisposed())
1589 return;
1590 weld::Button& rBtn = pInfoBar->addButton();
1591 rBtn.set_label(SfxResId(STR_SIGNATURE_SHOW));
1592 rBtn.connect_clicked(LINK(this, SfxObjectShell, SignDocumentHandler));
1593 }
1594 }
1595 else // info bar exists already
1596 {
1597 if ( eState == SignatureState::NOSIGNATURES )
1598 pFrame->RemoveInfoBar(u"signature");
1599 else
1600 pFrame->UpdateInfoBar(u"signature", "", sMessage, aInfobarType);
1601 }
1602 }
1603
1604 rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast<sal_uInt16>(GetDocumentSignatureState()) ) );
1605 break;
1606 }
1607 case SID_MACRO_SIGNATURE:
1608 {
1609 // the slot makes sense only if there is a macro in the document
1610 if ( pImpl->documentStorageHasMacros() || pImpl->aMacroMode.hasMacroLibrary() )
1611 rSet.Put( SfxUInt16Item( SID_MACRO_SIGNATURE, static_cast<sal_uInt16>(GetScriptingSignatureState()) ) );
1612 else
1613 rSet.DisableItem( nWhich );
1614 break;
1615 }
1616 case SID_DOC_REPAIR:
1617 {
1618 SfxUndoManager* pIUndoMgr = GetUndoManager();
1619 if (pIUndoMgr)
1620 rSet.Put( SfxBoolItem(nWhich, pIUndoMgr->IsEmptyActions()) );
1621 else
1622 rSet.DisableItem( nWhich );
1623 break;
1624 }
1625 }
1626 }
1627}
1628
1629IMPL_LINK_NOARG(SfxObjectShell, SignDocumentHandler, weld::Button&, void)
1630{
1631 SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst(this);
1632 if (!pViewFrm)
1633 {
1634 SAL_WARN("sfx.appl", "There should be some SfxViewFrame associated here");
1635 return;
1636 }
1637 SfxUnoFrameItem aDocFrame(SID_FILLFRAME, pViewFrm->GetFrame().GetFrameInterface());
1638 pViewFrm->GetDispatcher()->ExecuteList(SID_SIGNATURE, SfxCallMode::SLOT, {}, { &aDocFrame });
1639}
1640
1642{
1643 switch ( rReq.GetSlot() )
1644 {
1645 case SID_MODIFIED:
1646 {
1647 SetModified( rReq.GetArgs()->Get(SID_MODIFIED).GetValue() );
1648 rReq.Done();
1649 break;
1650 }
1651
1652 case SID_DOCTITLE:
1653 SetTitle( rReq.GetArgs()->Get(SID_DOCTITLE).GetValue() );
1654 rReq.Done();
1655 break;
1656
1657 case SID_DOCINFO_AUTHOR :
1658 getDocProperties()->setAuthor( static_cast<const SfxStringItem&>(rReq.GetArgs()->Get(rReq.GetSlot())).GetValue() );
1659 break;
1660
1661 case SID_DOCINFO_COMMENTS :
1662 getDocProperties()->setDescription( static_cast<const SfxStringItem&>(rReq.GetArgs()->Get(rReq.GetSlot())).GetValue() );
1663 break;
1664
1665 case SID_DOCINFO_KEYWORDS :
1666 {
1667 const OUString aStr = static_cast<const SfxStringItem&>(rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
1668 getDocProperties()->setKeywords(
1669 ::comphelper::string::convertCommaSeparated(aStr) );
1670 break;
1671 }
1672 }
1673}
1674
1675
1677{
1678 SfxWhichIter aIter(rSet);
1679 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
1680 {
1681 switch ( nSID )
1682 {
1683 case SID_DOCINFO_AUTHOR :
1684 {
1685 rSet.Put( SfxStringItem( nSID,
1686 getDocProperties()->getAuthor() ) );
1687 break;
1688 }
1689
1690 case SID_DOCINFO_COMMENTS :
1691 {
1692 rSet.Put( SfxStringItem( nSID,
1693 getDocProperties()->getDescription()) );
1694 break;
1695 }
1696
1697 case SID_DOCINFO_KEYWORDS :
1698 {
1699 rSet.Put( SfxStringItem( nSID, ::comphelper::string::
1700 convertCommaSeparated(getDocProperties()->getKeywords())) );
1701 break;
1702 }
1703
1704 case SID_DOCPATH:
1705 {
1706 OSL_FAIL( "Not supported anymore!" );
1707 break;
1708 }
1709
1710 case SID_DOCFULLNAME:
1711 {
1712 rSet.Put( SfxStringItem( SID_DOCFULLNAME, GetTitle(SFX_TITLE_FULLNAME) ) );
1713 break;
1714 }
1715
1716 case SID_DOCTITLE:
1717 {
1718 rSet.Put( SfxStringItem( SID_DOCTITLE, GetTitle() ) );
1719 break;
1720 }
1721
1722 case SID_DOC_READONLY:
1723 {
1724 rSet.Put( SfxBoolItem( SID_DOC_READONLY, IsReadOnly() ) );
1725 break;
1726 }
1727
1728 case SID_DOC_SAVED:
1729 {
1730 rSet.Put( SfxBoolItem( SID_DOC_SAVED, !IsModified() ) );
1731 break;
1732 }
1733
1734 case SID_CLOSING:
1735 {
1736 rSet.Put( SfxBoolItem( SID_CLOSING, false ) );
1737 break;
1738 }
1739
1740 case SID_DOC_LOADING:
1741 rSet.Put( SfxBoolItem( nSID, ! ( pImpl->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT ) ) );
1742 break;
1743
1744 case SID_IMG_LOADING:
1745 rSet.Put( SfxBoolItem( nSID, ! ( pImpl->nLoadedFlags & SfxLoadedFlags::IMAGES ) ) );
1746 break;
1747 }
1748 }
1749}
1750
1751
1753{
1754 switch ( rReq.GetSlot() )
1755 {
1756 case SID_ACTIVATE:
1757 {
1758 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this );
1759 if ( pFrame )
1760 pFrame->GetFrame().Appear();
1761 rReq.SetReturnValue( SfxObjectItem( 0, pFrame ) );
1762 rReq.Done();
1763 break;
1764 }
1765 }
1766}
1767
1768
1770{
1771}
1772
1774static bool HasSignatureStream(const uno::Reference<embed::XStorage>& xStorage)
1775{
1776 if (!xStorage.is())
1777 return false;
1778
1779 if (xStorage->hasByName("META-INF"))
1780 {
1781 // ODF case.
1782 try
1783 {
1784 uno::Reference<embed::XStorage> xMetaInf
1785 = xStorage->openStorageElement("META-INF", embed::ElementModes::READ);
1786 if (xMetaInf.is())
1787 {
1788 return xMetaInf->hasByName("documentsignatures.xml")
1789 || xMetaInf->hasByName("macrosignatures.xml")
1790 || xMetaInf->hasByName("packagesignatures.xml");
1791 }
1792 }
1793 catch (const css::io::IOException&)
1794 {
1795 TOOLS_WARN_EXCEPTION("sfx.doc", "HasSignatureStream: failed to open META-INF");
1796 }
1797 }
1798
1799 // OOXML case.
1800 return xStorage->hasByName("_xmlsignatures");
1801}
1802
1803uno::Sequence< security::DocumentSignatureInformation > SfxObjectShell::GetDocumentSignatureInformation( bool bScriptingContent, const uno::Reference< security::XDocumentDigitalSignatures >& xSigner )
1804{
1805 uno::Sequence< security::DocumentSignatureInformation > aResult;
1806 uno::Reference< security::XDocumentDigitalSignatures > xLocSigner = xSigner;
1807
1808 bool bSupportsSigning = GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->GetSupportsSigning();
1809 if (GetMedium() && !GetMedium()->GetName().isEmpty() && ((IsOwnStorageFormat(*GetMedium()) && GetMedium()->GetStorage().is()) || bSupportsSigning))
1810 {
1811 try
1812 {
1813 if ( !xLocSigner.is() )
1814 {
1815 OUString aVersion;
1816 try
1817 {
1818 uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
1819 xPropSet->getPropertyValue("Version") >>= aVersion;
1820 }
1821 catch( uno::Exception& )
1822 {
1823 }
1824
1825 xLocSigner.set( security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), aVersion) );
1826
1827 }
1828
1829 if ( bScriptingContent )
1830 aResult = xLocSigner->verifyScriptingContentSignatures( GetMedium()->GetZipStorageToSign_Impl(),
1831 uno::Reference< io::XInputStream >() );
1832 else
1833 {
1834 if (GetMedium()->GetStorage(false).is())
1835 {
1836 // Something ZIP-based.
1837 // Only call into xmlsecurity if we see a signature stream,
1838 // as libxmlsec init is expensive.
1839 if (HasSignatureStream(GetMedium()->GetZipStorageToSign_Impl()))
1840 aResult = xLocSigner->verifyDocumentContentSignatures( GetMedium()->GetZipStorageToSign_Impl(),
1841 uno::Reference< io::XInputStream >() );
1842 }
1843 else
1844 {
1845 // Not ZIP-based, e.g. PDF.
1846
1847 // Create temp file if needed.
1848 GetMedium()->CreateTempFile(/*bReplace=*/false);
1849
1850 std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(GetMedium()->GetName(), StreamMode::READ));
1851 uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pStream));
1852 uno::Reference<io::XInputStream> xInputStream(xStream, uno::UNO_QUERY);
1853 aResult = xLocSigner->verifyDocumentContentSignatures(uno::Reference<embed::XStorage>(), xInputStream);
1854 }
1855 }
1856 }
1857 catch( css::uno::Exception& )
1858 {
1859 TOOLS_WARN_EXCEPTION("sfx.doc", "Failed to get document signature information");
1860 }
1861 }
1862
1863 return aResult;
1864}
1865
1867{
1868 SignatureState* pState = bScriptingContent ? &pImpl->nScriptingSignatureState : &pImpl->nDocumentSignatureState;
1869
1870 if ( *pState == SignatureState::UNKNOWN )
1871 {
1873
1874 uno::Sequence< security::DocumentSignatureInformation > aInfos = GetDocumentSignatureInformation( bScriptingContent );
1876 }
1877
1878 if ( *pState == SignatureState::OK || *pState == SignatureState::NOTVALIDATED
1879 || *pState == SignatureState::PARTIAL_OK)
1880 {
1881 if ( IsModified() )
1882 *pState = SignatureState::INVALID;
1883 }
1884
1885 return *pState;
1886}
1887
1889{
1890 // check whether the document is signed
1891 ImplGetSignatureState(); // document signature
1892 if (GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->IsOwnFormat())
1893 ImplGetSignatureState( true ); // script signature
1894 bool bHasSign = ( pImpl->nScriptingSignatureState != SignatureState::NOSIGNATURES || pImpl->nDocumentSignatureState != SignatureState::NOSIGNATURES );
1895
1896 // the target ODF version on saving (only valid when signing ODF of course)
1898
1899 // the document is not new and is not modified
1901
1902 if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty()
1903 || (GetMedium()->GetFilter()->IsOwnFormat() && aODFVersion.compareTo(ODFVER_012_TEXT) < 0 && !bHasSign))
1904 {
1905 // the document might need saving ( new, modified or in ODF1.1 format without signature )
1906
1908 {
1909 OUString sQuestion(bHasSign ? SfxResId(STR_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN) : SfxResId(RID_SVXSTR_XMLSEC_QUERY_SAVEBEFORESIGN));
1910 std::unique_ptr<weld::MessageDialog> xQuestion;
1911
1912 if (!bRememberSignature)
1913 {
1914 xQuestion = std::unique_ptr<weld::MessageDialog>(Application::CreateMessageDialog(pDialogParent,
1915 VclMessageType::Question, VclButtonsType::YesNo, sQuestion));
1916 }
1917
1918 if ( bRememberSignature || ( xQuestion != nullptr && xQuestion->run() == RET_YES ) )
1919 {
1920 sal_uInt16 nId = SID_SAVEDOC;
1921 if ( !GetMedium() || GetMedium()->GetName().isEmpty() )
1922 nId = SID_SAVEASDOC;
1923 SfxRequest aSaveRequest( nId, SfxCallMode::SLOT, GetPool() );
1924 //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved.
1925 SetModified();
1926 ExecFile_Impl( aSaveRequest );
1927
1928 // Check if it is stored a format which supports signing
1929 if (GetMedium() && GetMedium()->GetFilter() && !GetMedium()->GetName().isEmpty()
1930 && ((!GetMedium()->GetFilter()->IsOwnFormat()
1931 && !GetMedium()->GetFilter()->GetSupportsSigning())
1932 || (GetMedium()->GetFilter()->IsOwnFormat()
1933 && !GetMedium()->HasStorage_Impl())))
1934 {
1935 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
1936 pDialogParent, VclMessageType::Info, VclButtonsType::Ok,
1937 SfxResId(STR_INFO_WRONGDOCFORMAT)));
1938
1939 xBox->run();
1940 return false;
1941 }
1942 }
1943 else
1944 {
1945 // When the document is modified then we must not show the
1946 // digital signatures dialog
1947 // If we have come here then the user denied to save.
1948 if (!bHasSign)
1949 return false;
1950 }
1951 }
1952 else
1953 {
1954 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pDialogParent,
1955 VclMessageType::Warning, VclButtonsType::Ok, SfxResId(STR_XMLSEC_ODF12_EXPECTED)));
1956 xBox->run();
1957 return false;
1958 }
1959
1960 if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() )
1961 return false;
1962 }
1963
1964 // the document is not modified currently, so it can not become modified after signing
1965 pImpl->m_bAllowModifiedBackAfterSigning = false;
1966 if ( IsEnableSetModified() || /*bRememberSignature == */true )
1967 {
1968 EnableSetModified( false );
1969 pImpl->m_bAllowModifiedBackAfterSigning = true;
1970 }
1971
1972 // we have to store to the original document, the original medium should be closed for this time
1974 {
1976 return true;
1977 }
1978 return false;
1979}
1980
1981void SfxObjectShell::RecheckSignature(bool bAlsoRecheckScriptingSignature)
1982{
1983 if (bAlsoRecheckScriptingSignature)
1984 pImpl->nScriptingSignatureState = SignatureState::UNKNOWN; // Re-Check
1985
1986 pImpl->nDocumentSignatureState = SignatureState::UNKNOWN; // Re-Check
1987
1988 Invalidate(SID_SIGNATURE);
1989 Invalidate(SID_MACRO_SIGNATURE);
1990 Broadcast(SfxHint(SfxHintId::TitleChanged));
1991}
1992
1993void SfxObjectShell::AfterSigning(bool bSignSuccess, bool bSignScriptingContent)
1994{
1995 pImpl->m_bSavingForSigning = true;
1997 pImpl->m_bSavingForSigning = false;
1998
1999 if ( bSignSuccess )
2000 RecheckSignature(bSignScriptingContent);
2001
2002 if ( pImpl->m_bAllowModifiedBackAfterSigning || /* bRememberSignature ==*/ true )
2004}
2005
2006bool SfxObjectShell::CheckIsReadonly(bool bSignScriptingContent, weld::Window* pDialogParent)
2007{
2008 // in LOK case we support only viewer / readonly mode so far
2009 if (GetMedium()->IsOriginallyReadOnly() || comphelper::LibreOfficeKit::isActive())
2010 {
2011 // If the file is physically read-only, we just show the existing signatures
2012 try
2013 {
2014 OUString aODFVersion(
2016 uno::Reference<security::XDocumentDigitalSignatures> xSigner(
2017 security::DocumentDigitalSignatures::createWithVersionAndValidSignature(
2019
2020 if (pDialogParent)
2021 xSigner->setParentWindow(pDialogParent->GetXWindow());
2022
2023 if (bSignScriptingContent)
2024 xSigner->showScriptingContentSignatures(GetMedium()->GetZipStorageToSign_Impl(),
2025 uno::Reference<io::XInputStream>());
2026 else
2027 {
2028 uno::Reference<embed::XStorage> xStorage = GetMedium()->GetZipStorageToSign_Impl();
2029 if (xStorage.is())
2030 xSigner->showDocumentContentSignatures(xStorage,
2031 uno::Reference<io::XInputStream>());
2032 else
2033 {
2034 std::unique_ptr<SvStream> pStream(
2035 utl::UcbStreamHelper::CreateStream(GetName(), StreamMode::READ));
2036
2037 if (!pStream)
2038 {
2039 pStream = utl::UcbStreamHelper::CreateStream(GetMedium()->GetName(), StreamMode::READ);
2040
2041 if (!pStream)
2042 {
2043 SAL_WARN( "sfx.doc", "Couldn't use signing functionality!" );
2044 return true;
2045 }
2046 }
2047
2048 uno::Reference<io::XInputStream> xStream(new utl::OStreamWrapper(*pStream));
2049 xSigner->showDocumentContentSignatures(uno::Reference<embed::XStorage>(),
2050 xStream);
2051 }
2052 }
2053 }
2054 catch (const uno::Exception&)
2055 {
2056 SAL_WARN("sfx.doc", "Couldn't use signing functionality!");
2057 }
2058 return true;
2059 }
2060 return false;
2061}
2062
2064{
2065 return pImpl->nDocumentSignatureState == SignatureState::OK
2066 || pImpl->nDocumentSignatureState == SignatureState::NOTVALIDATED
2067 || pImpl->nDocumentSignatureState == SignatureState::PARTIAL_OK;
2068}
2069
2071{
2072 return ImplGetSignatureState();
2073}
2074
2076{
2077 if (!PrepareForSigning(pDialogParent))
2078 return false;
2079
2080 if (CheckIsReadonly(false, pDialogParent))
2081 return false;
2082
2083 bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures());
2084
2085 AfterSigning(bSignSuccess, false);
2086
2087 return bSignSuccess;
2088}
2089
2090bool SfxObjectShell::ResignDocument(uno::Sequence< security::DocumentSignatureInformation >& rSignaturesInfo)
2091{
2092 bool bSignSuccess = true;
2093
2094 // This should be at most one element, automatic iteration to avoid pointing issues in case no signs
2095 for (auto & rInfo : rSignaturesInfo)
2096 {
2097 auto xCert = rInfo.Signer;
2098 if (xCert.is())
2099 {
2100 bSignSuccess &= SignDocumentContentUsingCertificate(xCert);
2101 }
2102 }
2103
2104 return bSignSuccess;
2105}
2106
2107bool SfxObjectShell::SignDocumentContentUsingCertificate(const Reference<XCertificate>& xCertificate)
2108{
2109 // 1. PrepareForSigning
2110
2111 // check whether the document is signed
2112 ImplGetSignatureState(false); // document signature
2113 if (GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->IsOwnFormat())
2114 ImplGetSignatureState( true ); // script signature
2115 bool bHasSign = ( pImpl->nScriptingSignatureState != SignatureState::NOSIGNATURES || pImpl->nDocumentSignatureState != SignatureState::NOSIGNATURES );
2116
2117 // the target ODF version on saving (only valid when signing ODF of course)
2119
2120 // the document is not new and is not modified
2122
2123 if (IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty()
2124 || (GetMedium()->GetFilter()->IsOwnFormat() && aODFVersion.compareTo(ODFVER_012_TEXT) < 0 && !bHasSign))
2125 {
2127 {
2128 sal_uInt16 nId = SID_SAVEDOC;
2129 if ( !GetMedium() || GetMedium()->GetName().isEmpty() )
2130 nId = SID_SAVEASDOC;
2131 SfxRequest aSaveRequest( nId, SfxCallMode::SLOT, GetPool() );
2132 //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved.
2133 SetModified();
2134 ExecFile_Impl( aSaveRequest );
2135
2136 // Check if it is stored a format which supports signing
2137 if (GetMedium() && GetMedium()->GetFilter() && !GetMedium()->GetName().isEmpty()
2138 && ((!GetMedium()->GetFilter()->IsOwnFormat()
2139 && !GetMedium()->GetFilter()->GetSupportsSigning())
2140 || (GetMedium()->GetFilter()->IsOwnFormat()
2141 && !GetMedium()->HasStorage_Impl())))
2142 {
2143 return false;
2144 }
2145 }
2146 else
2147 {
2148 return false;
2149 }
2150
2151 if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() )
2152 return false;
2153 }
2154
2155 // the document is not modified currently, so it can not become modified after signing
2156 pImpl->m_bAllowModifiedBackAfterSigning = false;
2157 if ( IsEnableSetModified() )
2158 {
2159 EnableSetModified( false );
2160 pImpl->m_bAllowModifiedBackAfterSigning = true;
2161 }
2162
2163 // we have to store to the original document, the original medium should be closed for this time
2164 bool bResult = ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium);
2165
2166 if (!bResult)
2167 return false;
2168
2170
2171 // 2. Check Read-Only
2172 if (GetMedium()->IsOriginallyReadOnly())
2173 return false;
2174
2175 // 3. Sign
2176 bool bSignSuccess = GetMedium()->SignDocumentContentUsingCertificate(
2177 GetBaseModel(), HasValidSignatures(), xCertificate);
2178
2179 // 4. AfterSigning
2180 AfterSigning(bSignSuccess, false);
2181
2182 return true;
2183}
2184
2186 const OUString& aSignatureLineId,
2187 const Reference<XCertificate>& xCert,
2188 const Reference<XGraphic>& xValidGraphic,
2189 const Reference<XGraphic>& xInvalidGraphic,
2190 const OUString& aComment)
2191{
2192 if (!PrepareForSigning(pDialogParent))
2193 return;
2194
2195 if (CheckIsReadonly(false, pDialogParent))
2196 return;
2197
2198 bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent,
2199 false, HasValidSignatures(), aSignatureLineId, xCert, xValidGraphic, xInvalidGraphic, aComment);
2200
2201 AfterSigning(bSignSuccess, false);
2202
2203 // Reload the document to get the updated graphic
2204 // FIXME: Update just the signature line graphic instead of reloading the document
2205 SfxViewFrame *pFrame = GetFrame();
2206 if (pFrame)
2207 pFrame->GetDispatcher()->Execute(SID_RELOAD);
2208}
2209
2211{
2212 return ImplGetSignatureState( true );
2213}
2214
2216{
2217 if (!PrepareForSigning(pDialogParent))
2218 return false;
2219
2220 if (CheckIsReadonly(true, pDialogParent))
2221 return false;
2222
2223 bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures());
2224
2225 AfterSigning(bSignSuccess, true);
2226
2227 return bSignSuccess;
2228}
2229
2230const uno::Sequence<sal_Int8>& SfxObjectShell::getUnoTunnelId()
2231{
2232 static const comphelper::UnoIdInit theSfxObjectShellUnoTunnelId;
2233 return theSfxObjectShellUnoTunnelId.getSeq();
2234}
2235
2236uno::Sequence< beans::PropertyValue > SfxObjectShell::GetDocumentProtectionFromGrabBag() const
2237{
2238 uno::Reference<frame::XModel> xModel = GetBaseModel();
2239
2240 if (!xModel.is())
2241 {
2242 return uno::Sequence< beans::PropertyValue>();
2243 }
2244
2245 uno::Reference< beans::XPropertySet > xPropSet( xModel, uno::UNO_QUERY_THROW );
2246 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
2247 const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
2248 if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) )
2249 {
2250 uno::Sequence< beans::PropertyValue > propList;
2251 xPropSet->getPropertyValue( aGrabBagName ) >>= propList;
2252 for( const auto& rProp : std::as_const(propList) )
2253 {
2254 if (rProp.Name == "DocumentProtection")
2255 {
2256 uno::Sequence< beans::PropertyValue > rAttributeList;
2257 rProp.Value >>= rAttributeList;
2258 return rAttributeList;
2259 }
2260 }
2261 }
2262
2263 return uno::Sequence< beans::PropertyValue>();
2264}
2265
2266/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
Reference< XInputStream > xStream
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
void TransformItems(sal_uInt16 nSlotId, const SfxItemSet &rSet, uno::Sequence< beans::PropertyValue > &rArgs, const SfxSlot *pSlot)
Definition: appuno.cxx:908
void TransformParameters(sal_uInt16 nSlotId, const uno::Sequence< beans::PropertyValue > &rArgs, SfxAllItemSet &rSet, const SfxSlot *pSlot)
Definition: appuno.cxx:170
const sal_uInt16 nVersion
Definition: childwin.cxx:43
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
const OUString & GetValue() const
constexpr ErrCodeClass GetClass() const
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
static std::unique_ptr< ErrorInfo > GetErrorInfo(ErrCode)
static bool CreateString(const ErrorInfo *, OUString &)
bool IsPrinting() const
static void SetError(ErrCode)
bool hasTargets() const
Check if the dialog has any valid redaction targets.
bool getTargets(std::vector< std::pair< RedactionTarget, OUString > > &r_aTargets)
Copies targets vector Does a shallow copy.
bool isValidState() const
Check if the dialog is in a valid state.
bool GetValue() const
void Broadcast(const SfxHint &rHint)
bool IsMajor() const
Definition: checkin.cxx:30
OUString GetComment() const
Definition: checkin.cxx:25
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
Method to execute a <SfxSlot>s over the Slot-Id.
Definition: dispatch.cxx:833
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
Method to execute a <SfxSlot>s over the Slot-Id.
Definition: dispatch.cxx:931
std::shared_ptr< const SfxFilter > GetFilter4Mime(const OUString &rMime, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
Definition: fltfnc.cxx:619
static std::shared_ptr< const SfxFilter > GetDefaultFilterFromFactory(const OUString &rServiceName)
Definition: docfilt.cxx:110
void Appear()
Definition: frame.cxx:528
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
Definition: frame.cxx:515
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void DisableItem(sal_uInt16 nWhich)
const std::shared_ptr< const SfxFilter > & GetFilter() const
Definition: docfile.cxx:3111
void CloseAndRelease()
Definition: docfile.cxx:3149
SfxItemSet & GetItemSet() const
Definition: docfile.cxx:3647
SAL_DLLPRIVATE void SetUpdatePickList(bool)
Definition: docfile.cxx:2919
bool IsOriginallyReadOnly() const
Definition: docfile.cxx:3819
SAL_DLLPRIVATE bool SignDocumentContentUsingCertificate(const css::uno::Reference< css::frame::XModel > &xModel, bool bHasValidDocumentSignature, const css::uno::Reference< css::security::XCertificate > &xCertificate)
Definition: docfile.cxx:4014
void CreateTempFile(bool bReplace=true)
Definition: docfile.cxx:3893
css::uno::Reference< css::embed::XStorage > GetStorage(bool bCreateTempFile=true)
Definition: docfile.cxx:1703
SAL_DLLPRIVATE css::uno::Reference< css::embed::XStorage > const & GetZipStorageToSign_Impl(bool bReadOnly=true)
Definition: docfile.cxx:1878
SAL_DLLPRIVATE bool SignContents_Impl(weld::Window *pDialogParent, bool bSignScriptingContent, bool bHasValidDocumentSignature, const OUString &aSignatureLineId=OUString(), const css::uno::Reference< css::security::XCertificate > &xCert=css::uno::Reference< css::security::XCertificate >(), const css::uno::Reference< css::graphic::XGraphic > &xValidGraphic=css::uno::Reference< css::graphic::XGraphic >(), const css::uno::Reference< css::graphic::XGraphic > &xInvalidGraphic=css::uno::Reference< css::graphic::XGraphic >(), const OUString &aComment=OUString())
Definition: docfile.cxx:4140
SfxSlotPool * GetSlotPool() const
Definition: module.cxx:102
void RecheckSignature(bool bAlsoRecheckScriptingSignature)
Definition: objserv.cxx:1981
bool DoClose()
Definition: objxtor.cxx:818
virtual bool PrepareClose(bool bUI=true)
Definition: objxtor.cxx:506
SAL_DLLPRIVATE bool CommonSaveAs_Impl(const INetURLObject &aURL, const OUString &aFilterName, SfxItemSet &rItemSet, const css::uno::Sequence< css::beans::PropertyValue > &rArgs)
Definition: objstor.cxx:2704
SAL_DLLPRIVATE void ExecProps_Impl(SfxRequest &)
Definition: objserv.cxx:1641
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
Definition: objmisc.cxx:161
SAL_DLLPRIVATE void PrintExec_Impl(SfxRequest &)
Definition: objserv.cxx:251
static SAL_DLLPRIVATE void StateView_Impl(SfxItemSet &)
Definition: objserv.cxx:1769
void SetTitle(const OUString &rTitle)
Definition: objmisc.cxx:668
void AfterSigning(bool bSignSuccess, bool bSignScriptingContent)
Definition: objserv.cxx:1993
void SignSignatureLine(weld::Window *pDialogParent, const OUString &aSignatureLineId, const css::uno::Reference< css::security::XCertificate > &xCert, const css::uno::Reference< css::graphic::XGraphic > &xValidGraphic, const css::uno::Reference< css::graphic::XGraphic > &xInvalidGraphic, const OUString &aComment)
Definition: objserv.cxx:2185
SAL_DLLPRIVATE SignatureState ImplGetSignatureState(bool bScriptingContent=false)
Definition: objserv.cxx:1866
virtual bool DoSaveCompleted(SfxMedium *pNewStor=nullptr, bool bRegisterRecent=true)
Definition: objstor.cxx:1945
ErrCode GetErrorCode() const
Definition: objmisc.cxx:225
bool IsLoadReadonly() const
Definition: objcont.cxx:654
bool SignDocumentContentUsingCertificate(const css::uno::Reference< css::security::XCertificate > &xCertificate)
Definition: objserv.cxx:2107
bool HasValidSignatures() const
Definition: objserv.cxx:2063
bool isSaveLocked() const
Definition: objmisc.cxx:1918
bool IsReadOnlyMedium() const
Definition: objmisc.cxx:349
sal_uInt32 GetModifyPasswordHash() const
Definition: objcont.cxx:678
virtual std::shared_ptr< SfxDocumentInfoDialog > CreateDocumentInfoDialog(weld::Window *pParent, const SfxItemSet &rItemSet)
Definition: objcont.cxx:311
bool SignDocumentContent(weld::Window *pDialogParent)
Definition: objserv.cxx:2075
static bool IsOwnStorageFormat(const SfxMedium &)
Definition: objstor.cxx:953
bool PrepareForSigning(weld::Window *pDialogParent)
Returns true if preparing was successful, else false.
Definition: objserv.cxx:1888
SAL_DLLPRIVATE void CheckIn()
Definition: objserv.cxx:364
bool HasName() const
Definition: objsh.hxx:266
bool IsEnableSetModified() const
Definition: objmisc.cxx:248
SAL_DLLPRIVATE void CancelCheckOut()
Definition: objserv.cxx:345
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: objserv.cxx:2230
SAL_DLLPRIVATE void StateProps_Impl(SfxItemSet &)
Definition: objserv.cxx:1676
css::uno::Sequence< css::security::DocumentSignatureInformation > rSignatureInfosRemembered
Definition: objsh.hxx:204
bool bRememberSignature
Definition: objsh.hxx:194
sal_Int16 QueryHiddenInformation(HiddenWarningFact eFact, weld::Window *pParent)
Definition: objstor.cxx:3084
virtual SfxObjectFactory & GetFactory() const =0
bool isExportLocked() const
Definition: objmisc.cxx:1902
bool ResignDocument(css::uno::Sequence< css::security::DocumentSignatureInformation > &rSignaturesInfo)
Definition: objserv.cxx:2090
virtual void Invalidate(sal_uInt16 nId=0) override
With this method can the slots of the subclasses be invalidated through the slot Id or alternatively ...
Definition: objmisc.cxx:1599
bool IsUseUserData() const
Definition: objcont.cxx:623
bool IsReadOnly() const
Definition: objmisc.cxx:416
bool CheckIsReadonly(bool bSignScriptingContent, weld::Window *pDialogParent=nullptr)
Definition: objserv.cxx:2006
SfxModule * GetModule() const
Definition: objmisc.cxx:1321
bool IsSignPDF() const
Is this read-only object shell opened via .uno:SignPDF?
Definition: objserv.cxx:403
SAL_DLLPRIVATE void ExecFile_Impl(SfxRequest &)
Definition: objserv.cxx:521
SAL_DLLPRIVATE void PrintState_Impl(SfxItemSet &)
Definition: objserv.cxx:262
bool IsModified() const
Definition: objmisc.cxx:259
SfxMedium * pMedium
Definition: objsh.hxx:187
virtual bool QuerySlotExecutable(sal_uInt16 nSlotId)
Definition: objstor.cxx:164
SfxMedium * GetMedium() const
Definition: objsh.hxx:261
void SetReadOnlyUI(bool bReadOnly=true)
Definition: objmisc.cxx:373
SAL_DLLPRIVATE bool APISaveAs_Impl(std::u16string_view aFileName, SfxItemSet &rItemSet, const css::uno::Sequence< css::beans::PropertyValue > &rArgs)
Definition: objserv.cxx:274
css::uno::Reference< css::frame::XModel3 > GetModel() const
Definition: objxtor.cxx:838
OUString GetTitle(sal_uInt16 nMaxLen=0) const
Definition: objmisc.cxx:710
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
Definition: objxtor.cxx:854
std::unique_ptr< struct SfxObjectShell_Impl > pImpl
Definition: objsh.hxx:185
css::uno::Reference< css::embed::XStorage > const & GetStorage()
Definition: objstor.cxx:3260
static css::uno::Reference< css::uno::XInterface > GetCurrentComponent()
Definition: objxtor.cxx:915
void SetSaveVersionOnClose(bool bSet)
Definition: objcont.cxx:671
void EnableSetModified(bool bEnable=true)
Definition: objmisc.cxx:241
void SetUseThumbnailSave(bool _bNew)
Definition: objcont.cxx:647
void SetUseUserData(bool bNew)
Definition: objcont.cxx:640
bool IsUseThumbnailSave() const
Definition: objcont.cxx:628
css::uno::Reference< css::security::XCertificate > GetSignPDFCertificate() const
Gets the certificate that is already picked by the user but not yet used for signing.
Definition: objserv.cxx:415
bool IsSaveVersionOnClose() const
Definition: objcont.cxx:659
SAL_DLLPRIVATE void CheckOut()
Definition: objserv.cxx:326
css::uno::Sequence< css::security::DocumentSignatureInformation > GetDocumentSignatureInformation(bool bScriptingContent, const css::uno::Reference< css::security::XDocumentDigitalSignatures > &xSigner=css::uno::Reference< css::security::XDocumentDigitalSignatures >())
Definition: objserv.cxx:1803
SignatureState GetScriptingSignatureState()
Definition: objserv.cxx:2210
bool SignScriptingContent(weld::Window *pDialogParent)
Definition: objserv.cxx:2215
const css::uno::Sequence< css::beans::PropertyValue > & GetModifyPasswordInfo() const
Definition: objcont.cxx:697
SignatureState GetDocumentSignatureState()
Definition: objserv.cxx:2070
SAL_DLLPRIVATE void ExecView_Impl(SfxRequest &)
Definition: objserv.cxx:1752
SAL_DLLPRIVATE bool ConnectTmpStorage_Impl(const css::uno::Reference< css::embed::XStorage > &xStorage, SfxMedium *pMedium)
Definition: objstor.cxx:1801
SAL_DLLPRIVATE css::uno::Sequence< css::document::CmisVersion > GetCmisVersions() const
Definition: objserv.cxx:387
void ResetError()
Definition: objmisc.cxx:233
SAL_DLLPRIVATE void GetState_Impl(SfxItemSet &)
Definition: objserv.cxx:1360
virtual void SetModified(bool bModified=true)
Definition: objmisc.cxx:301
css::uno::Sequence< css::beans::PropertyValue > GetDocumentProtectionFromGrabBag() const
Gets grab-bagged password info to unprotect change tracking with verification.
Definition: objserv.cxx:2236
sal_uInt16 Which() const
static void addPagesToDraw(const uno::Reference< XComponent > &xComponent, sal_Int32 nPages, const std::vector< GDIMetaFile > &aMetaFiles, const std::vector<::Size > &aPageSizes, const PageMargins &aPageMargins, const std::vector< std::pair< RedactionTarget, OUString > > &r_aTableTargets, bool bIsAutoRedact)
static PageMargins getPageMarginsForCalc(const css::uno::Reference< css::frame::XModel > &xModel)
static OUString getStringParam(const SfxRequest &rReq, sal_uInt16 nParamId)
static PageMargins getPageMarginsForWriter(const css::uno::Reference< css::frame::XModel > &xModel)
static void showRedactionToolbar(const SfxViewFrame *pViewFrame)
static bool isRedactMode(const SfxRequest &rReq)
Checks to see if the request has a parameter of IsRedactMode:bool=true.
static void getPageMetaFilesFromDoc(std::vector< GDIMetaFile > &aMetaFiles, std::vector<::Size > &aPageSizes, sal_Int32 nPages, DocumentToGraphicRenderer &aRenderer)
sal_uInt16 GetSlot() const
Definition: request.hxx:68
void Ignore()
Definition: request.cxx:521
void ReleaseArgs()
Definition: request.cxx:744
const SfxItemSet * GetArgs() const
Definition: request.hxx:75
void SetSlot(sal_uInt16 nNewSlot)
Definition: request.hxx:69
const T * GetArg(sal_uInt16 nSlotId) const
Templatized access to the individual parameters of the SfxRequest.
Definition: request.hxx:84
void AppendItem(const SfxPoolItem &)
Definition: request.cxx:404
void SetReturnValue(const SfxPoolItem &)
Definition: request.cxx:422
SfxCallMode GetCallMode() const
Definition: request.cxx:289
bool IsSynchronCall() const
Definition: request.cxx:295
bool IsDone() const
Definition: request.cxx:648
weld::Window * GetFrameWeld() const
Return the window that should be used as the parent for any dialogs this request creates.
Definition: appserv.cxx:299
void SetArgs(const SfxAllItemSet &rArgs)
Definition: request.cxx:397
bool IsAPI() const
Definition: request.cxx:705
void Done(bool bRemove=false)
Definition: request.cxx:484
The class SfxShell is the base class for all classes, which provide the functionality of the form <Sl...
Definition: shell.hxx:128
const SfxPoolItem * GetSlotState(sal_uInt16 nSlotId, const SfxInterface *pIF=nullptr, SfxItemSet *pStateSet=nullptr)
This method returns the status of the slot with the specified slot ID on the specified interface.
Definition: shell.cxx:462
SfxItemPool & GetPool() const
Each Subclass of SfxShell must reference a pool.
Definition: shell.hxx:511
const OUString & GetName() const
Returns the name of the Shell object.
Definition: shell.cxx:119
SfxViewFrame * GetFrame() const
This method returns a pointer to the <SfxViewFrame> to which this SfxShell instance is associated or ...
Definition: shell.cxx:134
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
This method allows you to forward a <SfxRequest> to the specified base <SfxShell>.
Definition: shell.cxx:438
virtual SfxUndoManager * GetUndoManager()
Each Subclass of SfxShell can have a <SfxUndoManager>.
Definition: shell.cxx:203
SfxViewShell * GetViewShell() const
Returns the SfxViewShell in which they are located in the subshells.
Definition: shell.cxx:129
friend class SfxObjectItem
Definition: shell.hxx:129
const SfxSlot * GetSlot(sal_uInt16 nId) const
Definition: msgpool.cxx:155
Definition: msg.hxx:184
const OUString & GetUnoName() const
Definition: msg.hxx:237
static bool runAsync(const std::shared_ptr< SfxTabDialogController > &rController, const std::function< void(sal_Int32)> &)
bool IsEmptyActions() const
bool IsSaveVersionOnClose() const
Definition: versdlg.hxx:54
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
Definition: viewfrm.cxx:1975
void RemoveInfoBar(std::u16string_view sId)
Definition: viewfrm.cxx:3632
void ExecReload_Impl(SfxRequest &rReq)
Definition: viewfrm.cxx:275
SfxDispatcher * GetDispatcher()
Definition: viewfrm.hxx:109
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
Definition: viewfrm.cxx:1983
SfxFrame & GetFrame() const
Definition: viewfrm.cxx:2782
weld::Window * GetFrameWeld() const
Definition: viewfrm.cxx:2797
bool HasInfoBarWithID(std::u16string_view sId)
Definition: viewfrm.cxx:3650
VclPtr< SfxInfoBarWindow > AppendInfoBar(const OUString &sId, const OUString &sPrimaryMessage, const OUString &sSecondaryMessage, InfobarType aInfobarType, bool bShowCloseButton=true)
Append a new InfoBar (see https://wiki.documentfoundation.org/Design/Whiteboards/Infobar).
Definition: viewfrm.cxx:3593
void UpdateInfoBar(std::u16string_view sId, const OUString &sPrimaryMessage, const OUString &sSecondaryMessage, InfobarType eType)
Definition: viewfrm.cxx:3612
virtual SfxPrinter * GetPrinter(bool bCreate=false)
Definition: viewprn.cxx:904
virtual void libreOfficeKitViewCallback(int nType, const OString &pPayload) const override
Invokes the registered callback, if there are any.
Definition: viewsh.cxx:2244
void SetStoringHelper(std::shared_ptr< SfxStoringHelper > xHelper)
Definition: viewsh.hxx:478
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
Definition: viewsh.cxx:1848
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
static OUString GetODFVersionFromStorage(const css::uno::Reference< css::embed::XStorage > &xStorage)
const css::uno::Sequence< sal_Int8 > & getSeq() const
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
virtual void set_label(const OUString &rText)=0
void connect_clicked(const Link< Button &, void > &rLink)
virtual short run()
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_GRAY7(0x66, 0x66, 0x66)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define TOOLS_WARN_EXCEPTION_IF(cond, area, stream)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
URL aURL
constexpr OUStringLiteral ODFVER_012_TEXT
float u
#define ERRCODE_IO_ABORT
#define ERRCODE_IO_GENERAL
#define ERRCODE_NONE
bool bReadOnly
InfobarType
Definition: infobar.hxx:22
#define SAL_WARN(area, stream)
aStr
Definition: mgetempl.cxx:407
SignatureState getSignatureState(const uno::Sequence< security::DocumentSignatureInformation > &aSigInfo)
@ Exception
OUString convertCommaSeparated(uno::Sequence< OUString > const &i_rSeq)
Reference< XComponentContext > getProcessComponentContext()
std::u16string_view getTitle(std::u16string_view aPath)
HashMap_OWString_Interface aMap
static void sendErrorToLOK(ErrCode error)
Definition: objserv.cxx:450
IMPL_LINK_NOARG(SfxObjectShell, SignDocumentHandler, weld::Button &, void)
Definition: objserv.cxx:1629
static bool HasSignatureStream(const uno::Reference< embed::XStorage > &xStorage)
Does this ZIP storage have a signature stream?
Definition: objserv.cxx:1774
#define SFX_TITLE_FULLNAME
Definition: objsh.hxx:114
sal_Int16 nId
const char GetValue[]
Sequence< Property > aInfos
UNOTOOLS_DLLPUBLIC SvtSaveOptions::ODFSaneDefaultVersion GetODFSaneDefaultVersion()
#define ERRCODE_BASIC_WRONG_ARGS
#define ERRCTX_SFX_SAVEASDOC
OUString SfxResId(TranslateId aId)
Definition: sfxresid.cxx:22
static SfxItemSet & rSet
Definition: shell.cxx:534
#define SFX_IMPL_SUPERCLASS_INTERFACE(Class, SuperClass)
Definition: shell.hxx:570
SignatureState
@ NOTVALIDATED_PARTIAL_OK
Certificate could not be validated and the document is only partially signed.
OUString sMessage
Reference< XController > xController
Reference< XModel > xModel
unsigned char sal_Bool
constexpr OUStringLiteral UNO_NAME_MISC_OBJ_INTEROPGRABBAG
RET_OK
RET_YES