desktop/source/lib/init.cxx | 3 include/sfx2/objsh.hxx | 5 - include/sfx2/viewsh.hxx | 6 + include/svl/cryptosign.hxx | 2 include/svx/signaturelinehelper.hxx | 2 sd/source/ui/func/fuconrec.cxx | 5 - sd/source/ui/func/fusel.cxx | 3 sfx2/qa/cppunit/doc.cxx | 9 +- sfx2/source/doc/objserv.cxx | 78 +---------------------- sfx2/source/view/viewfrm.cxx | 4 - sfx2/source/view/viewsh.cxx | 78 +++++++++++++++++++++++ svl/source/crypto/cryptosign.cxx | 2 svx/qa/unit/svdraw.cxx | 5 - svx/source/dialog/signaturelinehelper.cxx | 15 +--- svx/source/svdraw/svddrgv.cxx | 3 svx/source/svdraw/svdedtv1.cxx | 3 svx/source/svdraw/svdmrkv.cxx | 2 vcl/qa/cppunit/filter/ipdf/ipdf.cxx | 4 - xmlsecurity/qa/unit/signing/signing.cxx | 4 - xmlsecurity/source/helper/pdfsignaturehelper.cxx | 16 +--- 20 files changed, 124 insertions(+), 125 deletions(-)
New commits: commit 31059c18cd92929ff766b0dfa6366a0162a8573e Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Jan 16 08:58:27 2025 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Thu Jan 16 12:14:56 2025 +0100 cool#10630 doc electronic sign: move signature line tracking to the view No functional changes intended: - Replace SfxObjectShell::GetSignPDFCertificate() and SfxObjectShell::ResetSignPDFCertificate() with SfxViewShell::SetSignPDFCertificate() and SfxViewShell::GetSignPDFCertificate(), because information about shape selection belongs to the view. - Change svx::SignatureLineHelper::setShapeCertificate() to use SfxViewShell::SetSignPDFCertificate() to avoid duplication. - Change GetSignatureLineShape() in xmlsecurity/ to use SfxViewShell::GetSignPDFCertificate(), again to avoid duplication. With this, all setters/getters of the inserted signature line go via SfxViewShell and the amount of getCurrentSelection() calls on the model is reduced. Change-Id: I021bc41262b2a16d1014fbf1431a0eb6e1e86c73 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180332 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 8ced8a179714..7f09d490ba0a 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5204,8 +5204,7 @@ static bool isCommandAllowed(OUString& command) { if (pViewShell && command == u".uno:TransformDialog"_ustr) { // If the just added signature line shape is selected, allow moving it. - SfxObjectShell* pDocShell = pViewShell->GetObjectShell(); - bRet = pDocShell->GetSignPDFCertificate().Is(); + bRet = pViewShell->GetSignPDFCertificate().Is(); } return bRet; } diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 09713b266968..797fcb213f1c 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -806,11 +806,6 @@ public: /// Is this read-only object shell opened via .uno:SignPDF? bool IsSignPDF() const; - /// Gets the certificate that is already picked by the user but not yet used for signing. - svl::crypto::CertificateOrName GetSignPDFCertificate() const; - - void ResetSignPDFCertificate(); - /// Gets grab-bagged password info to unprotect change tracking with verification css::uno::Sequence< css::beans::PropertyValue > GetDocumentProtectionFromGrabBag() const; diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index 2ef2346d9ec4..ecd556073f2d 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -499,6 +499,12 @@ public: int getA11yCaretPosition() const; void SetSigningCertificate(const svl::crypto::CertificateOrName& rCertificateOrName); svl::crypto::CertificateOrName GetSigningCertificate() const; + + // These are used for visual signing: SetSignPDFCertificate() is called when the signature + // line is inserted, and GetSignPDFCertificate() is used by the signing code to get the already + // selected certificate. + void SetSignPDFCertificate(const svl::crypto::CertificateOrName& rCertificateOrName); + svl::crypto::CertificateOrName GetSignPDFCertificate() const; }; #endif // INCLUDED_SFX2_VIEWSH_HXX diff --git a/include/svl/cryptosign.hxx b/include/svl/cryptosign.hxx index 25a4428ce1ad..89740a042540 100644 --- a/include/svl/cryptosign.hxx +++ b/include/svl/cryptosign.hxx @@ -129,7 +129,7 @@ public: OUString m_aName; /// Returns if a certificate or a name is set. - bool Is(); + bool Is() const; }; } diff --git a/include/svx/signaturelinehelper.hxx b/include/svx/signaturelinehelper.hxx index 6f17f3726dd2..e17d4ce148e6 100644 --- a/include/svx/signaturelinehelper.hxx +++ b/include/svx/signaturelinehelper.hxx @@ -61,7 +61,7 @@ SVX_DLLPUBLIC css::uno::Reference<css::graphic::XGraphic> importSVG(std::u16stri /** * Sets xCertificate as the signing certificate of the selected shape on pView. */ -SVX_DLLPUBLIC void setShapeCertificate(const SdrView* pView, +SVX_DLLPUBLIC void setShapeCertificate(SfxViewShell* pViewShell, const svl::crypto::CertificateOrName& rCertificateOrName); } diff --git a/sd/source/ui/func/fuconrec.cxx b/sd/source/ui/func/fuconrec.cxx index a3e9c3665edb..61e54f52fb68 100644 --- a/sd/source/ui/func/fuconrec.cxx +++ b/sd/source/ui/func/fuconrec.cxx @@ -512,7 +512,8 @@ void FuConstructRectangle::Deactivate() return; } - svl::crypto::CertificateOrName aCertificateOrName = mpViewShell->GetViewShell()->GetSigningCertificate(); + SfxViewShell* pViewShell = mpViewShell->GetViewShell(); + svl::crypto::CertificateOrName aCertificateOrName = pViewShell->GetSigningCertificate(); if (aCertificateOrName.m_aName.isEmpty()) { aCertificateOrName.m_xCertificate = svx::SignatureLineHelper::getSignatureCertificate( @@ -524,7 +525,7 @@ void FuConstructRectangle::Deactivate() } } - svx::SignatureLineHelper::setShapeCertificate(mpView, aCertificateOrName); + svx::SignatureLineHelper::setShapeCertificate(pViewShell, aCertificateOrName); // Update infobar to offer "finish signing". SfxViewFrame* pFrame = mpViewShell->GetViewFrame(); diff --git a/sd/source/ui/func/fusel.cxx b/sd/source/ui/func/fusel.cxx index 73025bf98588..79976a961660 100644 --- a/sd/source/ui/func/fusel.cxx +++ b/sd/source/ui/func/fusel.cxx @@ -205,7 +205,8 @@ bool FuSelection::MouseButtonDown(const MouseEvent& rMEvt) bTextEdit = true; bool bPreventModify = mpDocSh->IsReadOnly(); - if (bPreventModify && mpDocSh->GetSignPDFCertificate().Is()) + SfxViewShell* pViewShell = mpViewShell->GetViewShell(); + if (bPreventModify && pViewShell && pViewShell->GetSignPDFCertificate().Is()) { // If the just added signature line shape is selected, allow moving / resizing it. bPreventModify = false; diff --git a/sfx2/qa/cppunit/doc.cxx b/sfx2/qa/cppunit/doc.cxx index 3979c89f2192..3f4f3062f168 100644 --- a/sfx2/qa/cppunit/doc.cxx +++ b/sfx2/qa/cppunit/doc.cxx @@ -22,6 +22,7 @@ #include <comphelper/propertysequence.hxx> #include <comphelper/sequence.hxx> #include <svl/cryptosign.hxx> +#include <sfx2/viewsh.hxx> using namespace com::sun::star; @@ -53,14 +54,14 @@ CPPUNIT_TEST_FIXTURE(Test, testNoGrabBagShape) xController->select(aShape); // See if it has a signing certificate associated. - auto pBaseModel = dynamic_cast<SfxBaseModel*>(xModel.get()); - CPPUNIT_ASSERT(pBaseModel); - SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + SfxViewShell* pViewShell + = SfxViewShell::Get(uno::Reference<frame::XController>(xController, uno::UNO_QUERY)); + CPPUNIT_ASSERT(pViewShell); // Without the accompanying fix in place, this test would have failed with: // An uncaught exception of type com.sun.star.beans.UnknownPropertyException // which was not caught later, resulting in a crash. - pObjectShell->GetSignPDFCertificate(); + pViewShell->GetSignPDFCertificate(); } CPPUNIT_TEST_FIXTURE(Test, testTempFilePath) diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index d4a51db0bde0..2165fe334aab 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -431,74 +431,6 @@ bool SfxObjectShell::IsSignPDF() const return false; } -namespace -{ -uno::Reference<beans::XPropertySet> GetSelectedShapeOfModel(const uno::Reference<frame::XModel>& xModel) -{ - if (!xModel.is()) - { - return uno::Reference<beans::XPropertySet>(); - } - - uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY); - if (!xShapes.is() || xShapes->getCount() < 1) - { - return uno::Reference<beans::XPropertySet>(); - } - - uno::Reference<beans::XPropertySet> xShapeProps(xShapes->getByIndex(0), uno::UNO_QUERY); - return xShapeProps; -} -} - -svl::crypto::CertificateOrName SfxObjectShell::GetSignPDFCertificate() const -{ - uno::Reference<beans::XPropertySet> xShapeProps = GetSelectedShapeOfModel(GetBaseModel()); - if (!xShapeProps.is() || !xShapeProps->getPropertySetInfo()->hasPropertyByName("InteropGrabBag")) - { - return {}; - } - - comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag")); - auto it = aMap.find("SignatureCertificate"); - if (it == aMap.end()) - { - return {}; - } - - svl::crypto::CertificateOrName aCertificateOrName; - if (it->second.has<uno::Reference<security::XCertificate>>()) - { - it->second >>= aCertificateOrName.m_xCertificate; - } - else - { - it->second >>= aCertificateOrName.m_aName; - } - return aCertificateOrName; -} - -void SfxObjectShell::ResetSignPDFCertificate() -{ - uno::Reference<beans::XPropertySet> xShapeProps = GetSelectedShapeOfModel(GetBaseModel()); - if (!xShapeProps->getPropertySetInfo()->hasPropertyByName("InteropGrabBag")) - { - return; - } - - comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag")); - auto it = aMap.find("SignatureCertificate"); - if (it == aMap.end()) - { - return; - } - - aMap.erase(it); - xShapeProps->setPropertyValue("InteropGrabBag", uno::Any(aMap.getAsConstPropertyValueList())); - // The shape's property is now reset, so the doc model is no longer modified. - SetModified(false); -} - static void sendErrorToLOK(ErrCodeMsg error) { if (error.GetCode().GetClass() == ErrCodeClass::NONE) @@ -620,7 +552,9 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) if (SID_SIGNATURE == nId) { - uno::Reference<security::XCertificate> xCertificate = GetSignPDFCertificate().m_xCertificate; + SfxViewFrame* pFrame = GetFrame(); + SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; + uno::Reference<security::XCertificate> xCertificate = pViewShell ? pViewShell->GetSignPDFCertificate().m_xCertificate : nullptr; if (xCertificate.is()) { @@ -631,9 +565,9 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) // Reset the picked certificate for PDF signing, then recheck signatures to show how // the PDF actually looks like after signing. Also change the "finish signing" on // the infobar back to "sign document". - if (SfxViewFrame* pFrame = GetFrame()) + if (pViewShell) { - ResetSignPDFCertificate(); + pViewShell->SetSignPDFCertificate({}); RecheckSignature(false); pFrame->RemoveInfoBar(u"readonly"); pFrame->AppendReadOnlyInfobar(); @@ -680,8 +614,6 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) return; } - SfxViewFrame* pFrame = GetFrame(); - SfxViewShell* pViewShell = pFrame ? pFrame->GetViewShell() : nullptr; if (pViewShell) { svl::crypto::CertificateOrName aCertificateOrName; diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 1ecce6ae7e9a..8df6100e89b4 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1271,8 +1271,8 @@ void SfxViewFrame::AppendReadOnlyInfobar() bool bSignWithCert = false; if (bSignPDF) { - SfxObjectShell* pObjectShell = GetObjectShell(); - uno::Reference<security::XCertificate> xCertificate = pObjectShell->GetSignPDFCertificate().m_xCertificate; + SfxViewShell* pViewShell = GetViewShell(); + uno::Reference<security::XCertificate> xCertificate = pViewShell->GetSignPDFCertificate().m_xCertificate; bSignWithCert = xCertificate.is(); } diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 14096d5ce221..367c5c643cb4 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -47,6 +47,7 @@ #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp> #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp> +#include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/view/XRenderable.hpp> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> @@ -2822,6 +2823,83 @@ svl::crypto::CertificateOrName SfxViewShell::GetSigningCertificate() const return pImpl->m_aSigningCertificate; } +namespace +{ +uno::Reference<beans::XPropertySet> +GetSelectedShapeOfView(const uno::Reference<frame::XController>& xController) +{ + uno::Reference<view::XSelectionSupplier> xSelectionSupplier(xController, uno::UNO_QUERY); + uno::Reference<drawing::XShapes> xShapes(xSelectionSupplier->getSelection(), uno::UNO_QUERY); + if (!xShapes.is() || xShapes->getCount() != 1) + { + return {}; + } + + return uno::Reference<beans::XPropertySet>(xShapes->getByIndex(0), uno::UNO_QUERY); +} +} + +void SfxViewShell::SetSignPDFCertificate(const svl::crypto::CertificateOrName& rCertificateOrName) +{ + uno::Reference<beans::XPropertySet> xShape = GetSelectedShapeOfView(GetController()); + if (!xShape.is() || !xShape->getPropertySetInfo()->hasPropertyByName("InteropGrabBag")) + { + return; + } + + comphelper::SequenceAsHashMap aMap(xShape->getPropertyValue("InteropGrabBag")); + + auto it = aMap.find("SignatureCertificate"); + if (rCertificateOrName.Is()) + { + if (rCertificateOrName.m_xCertificate.is()) + { + aMap["SignatureCertificate"] <<= rCertificateOrName.m_xCertificate; + } + else + { + aMap["SignatureCertificate"] <<= rCertificateOrName.m_aName; + } + } + else if (it != aMap.end()) + { + aMap.erase(it); + } + xShape->setPropertyValue("InteropGrabBag", uno::Any(aMap.getAsConstPropertyValueList())); + if (!rCertificateOrName.Is()) + { + // The shape's property is now reset, so the doc model is no longer modified. + GetObjectShell()->SetModified(false); + } +} + +svl::crypto::CertificateOrName SfxViewShell::GetSignPDFCertificate() const +{ + uno::Reference<beans::XPropertySet> xShape = GetSelectedShapeOfView(GetController()); + if (!xShape.is() || !xShape->getPropertySetInfo()->hasPropertyByName("InteropGrabBag")) + { + return {}; + } + + comphelper::SequenceAsHashMap aMap(xShape->getPropertyValue("InteropGrabBag")); + auto it = aMap.find("SignatureCertificate"); + if (it == aMap.end()) + { + return {}; + } + + svl::crypto::CertificateOrName aCertificateOrName; + if (it->second.has<uno::Reference<security::XCertificate>>()) + { + it->second >>= aCertificateOrName.m_xCertificate; + } + else + { + it->second >>= aCertificateOrName.m_aName; + } + return aCertificateOrName; +} + bool SfxViewShell::PrepareClose ( bool bUI // TRUE: Allow Dialog and so on, FALSE: silent-mode diff --git a/svl/source/crypto/cryptosign.cxx b/svl/source/crypto/cryptosign.cxx index 27bf74744234..5af0fb2e033a 100644 --- a/svl/source/crypto/cryptosign.cxx +++ b/svl/source/crypto/cryptosign.cxx @@ -2401,7 +2401,7 @@ void Signing::appendHex(sal_Int8 nInt, OStringBuffer& rBuffer) rBuffer.append( pHexDigits[ nInt & 15 ] ); } -bool CertificateOrName::Is() +bool CertificateOrName::Is() const { return m_xCertificate.is() || !m_aName.isEmpty(); } diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index 767d8f8ca1d7..407d23d1fa23 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -816,10 +816,11 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testVisualSignResize) { return; } - SdrView* pView = SfxViewShell::Current()->GetDrawView(); + SfxViewShell* pViewShell + = SfxViewShell::Get(uno::Reference<frame::XController>(xController, uno::UNO_QUERY)); svl::crypto::CertificateOrName aCertificateOrName; aCertificateOrName.m_xCertificate = xCert; - svx::SignatureLineHelper::setShapeCertificate(pView, aCertificateOrName); + svx::SignatureLineHelper::setShapeCertificate(pViewShell, aCertificateOrName); pObjectShell->SetModified(false); // When resizing the shape by moving the bottom right (last) handle towards top right: diff --git a/svx/source/dialog/signaturelinehelper.cxx b/svx/source/dialog/signaturelinehelper.cxx index 61e26ac77bf1..afc02bbe98ba 100644 --- a/svx/source/dialog/signaturelinehelper.cxx +++ b/svx/source/dialog/signaturelinehelper.cxx @@ -34,6 +34,7 @@ #include <unotools/syslocale.hxx> #include <vcl/weld.hxx> #include <sfx2/digitalsignatures.hxx> +#include <sfx2/viewsh.hxx> using namespace com::sun::star; @@ -134,9 +135,10 @@ uno::Reference<graphic::XGraphic> importSVG(std::u16string_view rSVG) return xGraphic; } -void setShapeCertificate(const SdrView* pView, +void setShapeCertificate(SfxViewShell* pViewShell, const svl::crypto::CertificateOrName& rCertificateOrName) { + const SdrView* pView = pViewShell->GetDrawView(); const SdrMarkList& rMarkList = pView->GetMarkedObjectList(); if (rMarkList.GetMarkCount() < 1) { @@ -153,16 +155,7 @@ void setShapeCertificate(const SdrView* pView, // Remember the selected certificate. uno::Reference<drawing::XShape> xShape = pSignatureLine->getUnoShape(); uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); - comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag")); - if (rCertificateOrName.m_xCertificate.is()) - { - aMap["SignatureCertificate"] <<= rCertificateOrName.m_xCertificate; - } - else - { - aMap["SignatureCertificate"] <<= rCertificateOrName.m_aName; - } - xShapeProps->setPropertyValue("InteropGrabBag", uno::Any(aMap.getAsConstPropertyValueList())); + pViewShell->SetSignPDFCertificate(rCertificateOrName); // Read svg and replace placeholder texts. OUString aSvgImage(svx::SignatureLineHelper::getSignatureImage("signature-line-draw.svg")); diff --git a/svx/source/svdraw/svddrgv.cxx b/svx/source/svdraw/svddrgv.cxx index c6a6d1e67afa..a36491bb4a19 100644 --- a/svx/source/svdraw/svddrgv.cxx +++ b/svx/source/svdraw/svddrgv.cxx @@ -415,8 +415,7 @@ bool SdrDragView::BegDragObj(const Point& rPnt, OutputDevice* pOut, SdrHdl* pHdl { bool bResizeAllowed = IsResizeAllowed(true); SfxViewShell* pViewShell = GetSfxViewShell(); - SfxObjectShell* pObjectShell = pViewShell ? pViewShell->GetObjectShell() : nullptr; - if (!bResizeAllowed && pObjectShell && pObjectShell->GetSignPDFCertificate().Is()) + if (!bResizeAllowed && pViewShell && pViewShell->GetSignPDFCertificate().Is()) { // If the just added signature line shape is selected, allow resizing it. bResizeAllowed = true; diff --git a/svx/source/svdraw/svdedtv1.cxx b/svx/source/svdraw/svdedtv1.cxx index 96f0e354b136..2e6eeaec0ffd 100644 --- a/svx/source/svdraw/svdedtv1.cxx +++ b/svx/source/svdraw/svdedtv1.cxx @@ -1788,8 +1788,7 @@ void SdrEditView::SetGeoAttrToMarked(const SfxItemSet& rAttr, bool addPageMargin // change position bool bMoveAllowed = m_bMoveAllowed; SfxViewShell* pViewShell = GetSfxViewShell(); - SfxObjectShell* pObjectShell = pViewShell ? pViewShell->GetObjectShell() : nullptr; - if (!bMoveAllowed && pObjectShell && pObjectShell->GetSignPDFCertificate().Is()) + if (!bMoveAllowed && pViewShell && pViewShell->GetSignPDFCertificate().Is()) { // If the just added signature line shape is selected, allow moving it. bMoveAllowed = true; diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx index 7247a84e299a..20a9c1948c8b 100644 --- a/svx/source/svdraw/svdmrkv.cxx +++ b/svx/source/svdraw/svdmrkv.cxx @@ -1111,7 +1111,7 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle const & rRect, const S else { SfxObjectShell* pObjectShell = pViewShell ? pViewShell->GetObjectShell() : nullptr; - if (pObjectShell && pObjectShell->IsSignPDF() && pObjectShell->GetSignPDFCertificate().Is()) + if (pObjectShell && pObjectShell->IsSignPDF() && pViewShell && pViewShell->GetSignPDFCertificate().Is()) { // Expose the info that this is the special signature widget that is OK to // move/resize. diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx index 96c64c453a1b..af5d4e875ecc 100644 --- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx +++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx @@ -100,10 +100,10 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testPDFAddVisibleSignatureLastPage) { return; } - SdrView* pView = SfxViewShell::Current()->GetDrawView(); + SfxViewShell* pViewShell = SfxViewShell::Current(); svl::crypto::CertificateOrName aCertificateOrName; aCertificateOrName.m_xCertificate = xCert; - svx::SignatureLineHelper::setShapeCertificate(pView, aCertificateOrName); + svx::SignatureLineHelper::setShapeCertificate(pViewShell, aCertificateOrName); // the document is modified now, but Sign function can't show SaveAs dialog // in unit test, so just clear the modified diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index ac03236396ed..84f60e65558f 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -769,10 +769,10 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPDFAddVisibleSignature) { return; } - SdrView* pView = SfxViewShell::Current()->GetDrawView(); + SfxViewShell* pViewShell = SfxViewShell::Current(); svl::crypto::CertificateOrName aCertificateOrName; aCertificateOrName.m_xCertificate = aCertificates[0]; - svx::SignatureLineHelper::setShapeCertificate(pView, aCertificateOrName); + svx::SignatureLineHelper::setShapeCertificate(pViewShell, aCertificateOrName); // the document is modified now, but Sign function can't show SaveAs dialog // in unit test, so just clear the modified diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx index c46313a9da9a..88f42a4b22ea 100644 --- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx +++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx @@ -33,6 +33,7 @@ #include <vcl/checksum.hxx> #include <svl/cryptosign.hxx> #include <vcl/filter/PDFiumLibrary.hxx> +#include <sfx2/viewsh.hxx> using namespace ::com::sun::star; @@ -70,21 +71,14 @@ void GetSignatureLineShape(const uno::Reference<frame::XModel>& xModel, sal_Int3 return; } - uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY); - if (!xShapes.is() || xShapes->getCount() < 1) - { - return; - } - - uno::Reference<beans::XPropertySet> xShapeProps(xShapes->getByIndex(0), uno::UNO_QUERY); - if (!xShapeProps.is()) + SfxViewShell* pViewShell = SfxViewShell::Get(xModel->getCurrentController()); + if (!pViewShell || !pViewShell->GetSignPDFCertificate().Is()) { return; } - comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag")); - auto it = aMap.find("SignatureCertificate"); - if (it == aMap.end()) + uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY); + if (!xShapes.is() || xShapes->getCount() < 1) { return; }