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              |    3 
 xmlsecurity/qa/unit/signing/signing.cxx          |    3 
 xmlsecurity/source/helper/pdfsignaturehelper.cxx |   16 +---
 20 files changed, 122 insertions(+), 125 deletions(-)

New commits:
commit 62dd6274c71bc840f5c5abcd4b1fa536238aa25d
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Jan 16 08:58:27 2025 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Jan 16 22:37:23 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/+/180355
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index edac3ef9e0b9..9b6f387c37f2 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -5392,8 +5392,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 88a766a9a3cc..39c4e588c8fa 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -812,11 +812,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 082890c6b200..3680a515e8cc 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -495,6 +495,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 0e02a2173860..503463686cf1 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 2e4e7a9cfcb2..af031550258f 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 8624c784fca5..bb6abf7dd8a3 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 22545fd42501..138e10d3a2bf 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 0aee136c7ea9..2990405e63d0 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -430,74 +430,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(u"InteropGrabBag"_ustr))
-    {
-        return {};
-    }
-
-    comphelper::SequenceAsHashMap 
aMap(xShapeProps->getPropertyValue(u"InteropGrabBag"_ustr));
-    auto it = aMap.find(u"SignatureCertificate"_ustr);
-    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(const ErrCodeMsg& error)
 {
     if (error.GetCode().GetClass() == ErrCodeClass::NONE)
@@ -610,7 +542,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())
             {
 
@@ -621,9 +555,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();
@@ -670,8 +604,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 fd90f150f0c6..28ac21bb02dd 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -1274,8 +1274,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 e42a69ea27aa..10dcb366eefc 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>
@@ -2817,6 +2818,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 90664e03caaf..6945c420a2b8 100644
--- a/svl/source/crypto/cryptosign.cxx
+++ b/svl/source/crypto/cryptosign.cxx
@@ -2405,7 +2405,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 e2c6b58a9dac..b3262e588e94 100644
--- a/svx/qa/unit/svdraw.cxx
+++ b/svx/qa/unit/svdraw.cxx
@@ -862,10 +862,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 d8a41e8d3cc7..d4f286995f2b 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;
 
@@ -135,9 +136,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)
     {
@@ -154,16 +156,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(u"InteropGrabBag"_ustr));
-    if (rCertificateOrName.m_xCertificate.is())
-    {
-        aMap[u"SignatureCertificate"_ustr] <<= 
rCertificateOrName.m_xCertificate;
-    }
-    else
-    {
-        aMap[u"SignatureCertificate"_ustr] <<= rCertificateOrName.m_aName;
-    }
-    xShapeProps->setPropertyValue("InteropGrabBag", 
uno::Any(aMap.getAsConstPropertyValueList()));
+    pViewShell->SetSignPDFCertificate(rCertificateOrName);
 
     // Read svg and replace placeholder texts.
     OUString aSvgImage(
diff --git a/svx/source/svdraw/svddrgv.cxx b/svx/source/svdraw/svddrgv.cxx
index 02cfc5ee38c8..645cb8fd2bef 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 d8b5162c70f6..693d5f3c0f7c 100644
--- a/svx/source/svdraw/svdedtv1.cxx
+++ b/svx/source/svdraw/svdedtv1.cxx
@@ -1829,8 +1829,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 c4f096dd04a8..0e24fe898e3f 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -1116,7 +1116,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 9964ec88dfb2..243687dad00b 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -102,10 +102,9 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, 
testPDFAddVisibleSignatureLastPage)
     }
     SfxViewShell* pCurrent = SfxViewShell::Current();
     CPPUNIT_ASSERT(pCurrent);
-    SdrView* pView = pCurrent->GetDrawView();
     svl::crypto::CertificateOrName aCertificateOrName;
     aCertificateOrName.m_xCertificate = xCert;
-    svx::SignatureLineHelper::setShapeCertificate(pView, aCertificateOrName);
+    svx::SignatureLineHelper::setShapeCertificate(pCurrent, 
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 82a7d2a1ae73..bb2c4d5df992 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -773,10 +773,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, 
testPDFAddVisibleSignature)
     }
     SfxViewShell* pCurrent = SfxViewShell::Current();
     CPPUNIT_ASSERT(pCurrent);
-    SdrView* pView = pCurrent->GetDrawView();
     svl::crypto::CertificateOrName aCertificateOrName;
     aCertificateOrName.m_xCertificate = xCert;
-    svx::SignatureLineHelper::setShapeCertificate(pView, aCertificateOrName);
+    svx::SignatureLineHelper::setShapeCertificate(pCurrent, 
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 79ee45c0e3c3..8d316bcffd91 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(u"InteropGrabBag"_ustr));
-    auto it = aMap.find(u"SignatureCertificate"_ustr);
-    if (it == aMap.end())
+    uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), 
uno::UNO_QUERY);
+    if (!xShapes.is() || xShapes->getCount() < 1)
     {
         return;
     }

Reply via email to