desktop/source/lib/init.cxx | 2 +- include/sfx2/objsh.hxx | 3 ++- include/svl/cryptosign.hxx | 3 +++ sd/qa/unit/tiledrendering/tiledrendering.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 ca725e0e0b459dffa510bcc3663919e705f84ac6 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jan 15 09:32:30 2025 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Jan 15 10:36:45 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/+/180264 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.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 c0986b897a8d..8ced8a179714 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5205,7 +5205,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 bc173c48ad55..09713b266968 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -109,6 +109,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 @@ -806,7 +807,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 291201cd394a..25a4428ce1ad 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/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 16501acfc346..00e1f8868709 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -4766,9 +4766,11 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testInsertSignatureLineExternal) uno::Sequence<beans::PropertyValue> aArgs = { comphelper::makePropertyValue("ReadOnly", true) }; loadWithParams(createFileURL(u"empty.pdf"), 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 insrerting a signature line for electronic (extrenal) signing: aArgs = { @@ -4785,6 +4787,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 5efab0c18526..73025bf98588 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 902ac48646e5..3979c89f2192 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 d1b055711e0d..d4a51db0bde0 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -451,22 +451,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("InteropGrabBag")) { - return uno::Reference<security::XCertificate>(); + return {}; } comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag")); auto it = aMap.find("SignatureCertificate"); 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() @@ -611,7 +620,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 d9f710923081..1ecce6ae7e9a 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -129,6 +129,7 @@ #include "impviewframe.hxx" #include <vcl/commandinfoprovider.hxx> #include <vcl/svapp.hxx> +#include <svl/cryptosign.hxx> #define ShellClass_SfxViewFrame #include <sfxslots.hxx> @@ -1271,7 +1272,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 79d9fb4aaea8..27bf74744234 100644 --- a/svl/source/crypto/cryptosign.cxx +++ b/svl/source/crypto/cryptosign.cxx @@ -2400,6 +2400,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 c2c90496a327..c6a6d1e67afa 100644 --- a/svx/source/svdraw/svddrgv.cxx +++ b/svx/source/svdraw/svddrgv.cxx @@ -41,6 +41,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 e2d2aa6547ce..96f0e354b136 100644 --- a/svx/source/svdraw/svdedtv1.cxx +++ b/svx/source/svdraw/svdedtv1.cxx @@ -71,6 +71,7 @@ #include <comphelper/lok.hxx> #include <osl/diagnose.h> #include <sfx2/objsh.hxx> +#include <svl/cryptosign.hxx> // EditView @@ -1788,7 +1789,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 4f74a40433cc..7247a84e299a 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> @@ -1110,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() && pObjectShell->GetSignPDFCertificate().Is()) { // Expose the info that this is the special signature widget that is OK to // move/resize.