desktop/source/lib/init.cxx | 2 +- include/sfx2/objsh.hxx | 3 ++- include/svl/cryptosign.hxx | 3 +++ sd/qa/unit/tiledrendering/tiledrendering2.cxx | 24 ++++++++++++++++++++++++ sd/source/ui/func/fusel.cxx | 3 ++- sfx2/qa/cppunit/doc.cxx | 1 + sfx2/source/doc/objserv.cxx | 19 ++++++++++++++----- sfx2/source/view/viewfrm.cxx | 3 ++- svl/source/crypto/cryptosign.cxx | 5 +++++ svx/source/svdraw/svddrgv.cxx | 3 ++- svx/source/svdraw/svdedtv1.cxx | 3 ++- svx/source/svdraw/svdmrkv.cxx | 3 ++- 12 files changed, 60 insertions(+), 12 deletions(-)
New commits: commit 9dd225ee8c45d6c944b9ce5578780d89612e9ffb Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jan 15 09:32:30 2025 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jan 15 18:22:25 2025 +0100 cool#10630 doc electronic sign: fix no graphic selection for the signature line Insert a signature line in "extern" mode, the shape gets selected but there is no graphic selection at a LOK API level. This is because GetSignPDFCertificate() returned an XCertificate, which is empty in the external signing case, so we can't differentiate between no signing and external signing. Fix this by changing the return type to svl::crypto::CertificateOrName, this way SdrMarkView::SetMarkHandlesForLOKit() can annotate the signature line correctly even in the external signing case. The tracking of the signature line selection is still in the model (not in the view), that's not yet fixed here. Change-Id: I4ef9c1fa0a88af0c0fcd55156b973a3705f985c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180296 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 614a054cb58d..edac3ef9e0b9 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5393,7 +5393,7 @@ static bool isCommandAllowed(OUString& command) { { // If the just added signature line shape is selected, allow moving it. SfxObjectShell* pDocShell = pViewShell->GetObjectShell(); - bRet = pDocShell->GetSignPDFCertificate().is(); + bRet = pDocShell->GetSignPDFCertificate().Is(); } return bRet; } diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index bac056f0a5d1..88a766a9a3cc 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -110,6 +110,7 @@ namespace com::sun::star::security { struct DocumentSignatureInformation; } namespace com::sun::star::task { class XInteractionHandler; } namespace com::sun::star::lang { class XComponent; } namespace com::sun::star::text { class XTextRange; } +namespace svl::crypto { class CertificateOrName; } #define SFX_TITLE_TITLE 0 #define SFX_TITLE_FILENAME 1 @@ -812,7 +813,7 @@ public: bool IsSignPDF() const; /// Gets the certificate that is already picked by the user but not yet used for signing. - css::uno::Reference<css::security::XCertificate> GetSignPDFCertificate() const; + svl::crypto::CertificateOrName GetSignPDFCertificate() const; void ResetSignPDFCertificate(); diff --git a/include/svl/cryptosign.hxx b/include/svl/cryptosign.hxx index bad7a5a16e62..0e02a2173860 100644 --- a/include/svl/cryptosign.hxx +++ b/include/svl/cryptosign.hxx @@ -127,6 +127,9 @@ public: /// Otherwise we don't have a certificate but have a name to be featured on the visual /// signature. OUString m_aName; + + /// Returns if a certificate or a name is set. + bool Is(); }; } diff --git a/sd/qa/unit/tiledrendering/tiledrendering2.cxx b/sd/qa/unit/tiledrendering/tiledrendering2.cxx index e6b846769988..53b174a8684e 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering2.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering2.cxx @@ -48,9 +48,11 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testInsertSignatureLineExternal) createTempCopy(u"empty.pdf"); loadWithParams(maTempFile.GetURL(), aArgs); SdXImpressDocument* pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get()); + pImpressDocument->initializeForTiledRendering({}); sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell(); sd::View* pView = pViewShell->GetView(); pView->SetAuthor("myauthor"); + ViewCallback aView; // When inserting a signature line for electronic (external) signing: aArgs = { @@ -67,6 +69,28 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testInsertSignatureLineExternal) aMarkedObjects[0]->GetGrabBagItem(aAny); comphelper::SequenceAsHashMap aMap(aAny); CPPUNIT_ASSERT(aMap.contains("SignatureCertificate")); + // Also verify that this is exposed at a LOK level: + OString aShapeSelection = "[" + aView.m_ShapeSelection + "]"; + const char* pShapeSelectionStr = aShapeSelection.getStr(); + std::stringstream aStream(pShapeSelectionStr); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + int nCount = 0; + bool bSignature = false; + for (const auto& i : aTree) + { + ++nCount; + if (nCount <= 5) + { + // x, y, w, h, part + continue; + } + boost::property_tree::ptree aProps = i.second; + // Without the accompanying fix in place, this test would have failed with: + // - No such node (isSignature) + bSignature = aProps.get<bool>("isSignature"); + } + CPPUNIT_ASSERT(bSignature); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/source/ui/func/fusel.cxx b/sd/source/ui/func/fusel.cxx index aa43a76ee91b..8624c784fca5 100644 --- a/sd/source/ui/func/fusel.cxx +++ b/sd/source/ui/func/fusel.cxx @@ -61,6 +61,7 @@ #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/lok.hxx> +#include <svl/cryptosign.hxx> using namespace ::com::sun::star; @@ -204,7 +205,7 @@ bool FuSelection::MouseButtonDown(const MouseEvent& rMEvt) bTextEdit = true; bool bPreventModify = mpDocSh->IsReadOnly(); - if (bPreventModify && mpDocSh->GetSignPDFCertificate().is()) + if (bPreventModify && mpDocSh->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 87b9d13a1ed4..22545fd42501 100644 --- a/sfx2/qa/cppunit/doc.cxx +++ b/sfx2/qa/cppunit/doc.cxx @@ -21,6 +21,7 @@ #include <comphelper/sequenceashashmap.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/sequence.hxx> +#include <svl/cryptosign.hxx> using namespace com::sun::star; diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index c5930ee99869..0aee136c7ea9 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -450,22 +450,31 @@ uno::Reference<beans::XPropertySet> GetSelectedShapeOfModel(const uno::Reference } } -uno::Reference<security::XCertificate> SfxObjectShell::GetSignPDFCertificate() const +svl::crypto::CertificateOrName SfxObjectShell::GetSignPDFCertificate() const { uno::Reference<beans::XPropertySet> xShapeProps = GetSelectedShapeOfModel(GetBaseModel()); if (!xShapeProps.is() || !xShapeProps->getPropertySetInfo()->hasPropertyByName(u"InteropGrabBag"_ustr)) { - return uno::Reference<security::XCertificate>(); + return {}; } comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue(u"InteropGrabBag"_ustr)); auto it = aMap.find(u"SignatureCertificate"_ustr); if (it == aMap.end()) { - return uno::Reference<security::XCertificate>(); + return {}; } - return uno::Reference<security::XCertificate>(it->second, uno::UNO_QUERY); + 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() @@ -601,7 +610,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) if (SID_SIGNATURE == nId) { - uno::Reference<security::XCertificate> xCertificate = GetSignPDFCertificate(); + uno::Reference<security::XCertificate> xCertificate = GetSignPDFCertificate().m_xCertificate; if (xCertificate.is()) { diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 2d150615bf2a..fd90f150f0c6 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -132,6 +132,7 @@ #include "impviewframe.hxx" #include <vcl/commandinfoprovider.hxx> #include <vcl/svapp.hxx> +#include <svl/cryptosign.hxx> #define ShellClass_SfxViewFrame #include <sfxslots.hxx> @@ -1274,7 +1275,7 @@ void SfxViewFrame::AppendReadOnlyInfobar() if (bSignPDF) { SfxObjectShell* pObjectShell = GetObjectShell(); - uno::Reference<security::XCertificate> xCertificate = pObjectShell->GetSignPDFCertificate(); + uno::Reference<security::XCertificate> xCertificate = pObjectShell->GetSignPDFCertificate().m_xCertificate; bSignWithCert = xCertificate.is(); } diff --git a/svl/source/crypto/cryptosign.cxx b/svl/source/crypto/cryptosign.cxx index daa668c9e0f4..90664e03caaf 100644 --- a/svl/source/crypto/cryptosign.cxx +++ b/svl/source/crypto/cryptosign.cxx @@ -2404,6 +2404,11 @@ void Signing::appendHex(sal_Int8 nInt, OStringBuffer& rBuffer) rBuffer.append( pHexDigits[ (nInt >> 4) & 15 ] ); rBuffer.append( pHexDigits[ nInt & 15 ] ); } + +bool CertificateOrName::Is() +{ + return m_xCertificate.is() || !m_aName.isEmpty(); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svddrgv.cxx b/svx/source/svdraw/svddrgv.cxx index 9b05f0206539..02cfc5ee38c8 100644 --- a/svx/source/svdraw/svddrgv.cxx +++ b/svx/source/svdraw/svddrgv.cxx @@ -40,6 +40,7 @@ #include <officecfg/Office/Common.hxx> #include <sfx2/objsh.hxx> #include <sfx2/viewsh.hxx> +#include <svl/cryptosign.hxx> using namespace sdr; @@ -415,7 +416,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 && pObjectShell && pObjectShell->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 c62f7c05d80c..d8b5162c70f6 100644 --- a/svx/source/svdraw/svdedtv1.cxx +++ b/svx/source/svdraw/svdedtv1.cxx @@ -70,6 +70,7 @@ #include <comphelper/lok.hxx> #include <osl/diagnose.h> #include <sfx2/objsh.hxx> +#include <svl/cryptosign.hxx> // EditView @@ -1829,7 +1830,7 @@ void SdrEditView::SetGeoAttrToMarked(const SfxItemSet& rAttr, bool addPageMargin bool bMoveAllowed = m_bMoveAllowed; SfxViewShell* pViewShell = GetSfxViewShell(); SfxObjectShell* pObjectShell = pViewShell ? pViewShell->GetObjectShell() : nullptr; - if (!bMoveAllowed && pObjectShell && pObjectShell->GetSignPDFCertificate().is()) + if (!bMoveAllowed && pObjectShell && pObjectShell->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 8ba5583853a1..c4f096dd04a8 100644 --- a/svx/source/svdraw/svdmrkv.cxx +++ b/svx/source/svdraw/svdmrkv.cxx @@ -65,6 +65,7 @@ #include <svtools/optionsdrawinglayer.hxx> #include <drawinglayer/processor2d/textextractor2d.hxx> +#include <svl/cryptosign.hxx> #include <array> @@ -1115,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() && pObjectShell->GetSignPDFCertificate().Is()) { // Expose the info that this is the special signature widget that is OK to // move/resize.