offapi/com/sun/star/text/BaseFrameProperties.idl | 6 +++++ sw/inc/cmdid.h | 1 sw/inc/frmfmt.hxx | 6 +++++ sw/qa/core/unocore/unocore.cxx | 25 +++++++++++++++++++++++ sw/source/core/draw/dpage.cxx | 11 ++++++++-- sw/source/core/layout/atrfrm.cxx | 10 +++++++++ sw/source/core/unocore/unoframe.cxx | 12 +++++++++++ sw/source/core/unocore/unomapproperties.hxx | 1 8 files changed, 70 insertions(+), 2 deletions(-)
New commits: commit 198497d535152458c33652375526bdd6d0b089c9 Author: Miklos Vajna <[email protected]> AuthorDate: Thu Mar 31 14:27:40 2022 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Apr 1 10:45:46 2022 +0200 sw fly frames: add Tooltip uno property This is somewhat similar to commit 1acf8e3cfaf1ef92008e39514a32ace0d036e552 (sw fields: add Title uno property, 2022-03-24), except that this is for images, and images already had a Title, which is persisted to ODT. So add a new Tooltip property which has priority over the tooltip generated for URLs, in case the tooltip is non-empty. This helps in case the URL is long / non-readable / confusing and a more helpful popup text can be provided instead. (cherry picked from commit 9caf6e4a3ac05a9d2e9d695e59d4ae048bf078b2) Conflicts: sw/inc/cmdid.h sw/qa/core/unocore/unocore.cxx sw/source/core/draw/dpage.cxx sw/source/core/unocore/unomapproperties.hxx Change-Id: Ife34dab5e4490eb1682c55fb7c01f7509d0057fc diff --git a/offapi/com/sun/star/text/BaseFrameProperties.idl b/offapi/com/sun/star/text/BaseFrameProperties.idl index bffa5ddf4770..3741f0af2710 100644 --- a/offapi/com/sun/star/text/BaseFrameProperties.idl +++ b/offapi/com/sun/star/text/BaseFrameProperties.idl @@ -372,6 +372,12 @@ published service BaseFrameProperties @since LibreOffice 6.4 */ [optional, property] boolean AllowOverlap; + + /** Contains popup text for the frame, used to for tooltip purposes if it's non-empty. + + @since LibreOffice 7.4 + */ + [optional, property] string Tooltip; }; diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h index 6513bf5032a8..e094fd379d0d 100644 --- a/sw/inc/cmdid.h +++ b/sw/inc/cmdid.h @@ -847,6 +847,7 @@ #define FN_SET_FRM_ALT_NAME (FN_FRAME + 18) #define FN_UNO_TITLE (FN_FRAME + 19) #define FN_UNO_DESCRIPTION (FN_FRAME + 20) +#define FN_UNO_TOOLTIP (FN_FRAME + 21) #define SID_ATTR_PAGE_COLUMN (FN_SIDEBAR + 0) #define SID_ATTR_PAGE_HEADER (FN_SIDEBAR + 3) diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx index e6c72712118e..d96e2f5ba5fa 100644 --- a/sw/inc/frmfmt.hxx +++ b/sw/inc/frmfmt.hxx @@ -187,6 +187,8 @@ class SW_DLLPUBLIC SwFlyFrameFormat final : public SwFrameFormat friend class SwDoc; OUString msTitle; OUString msDesc; + /// A tooltip has priority over an SwFormatURL and is not persisted to files. + OUString msTooltip; /** Both not existent. it stores the previous position of Prt rectangle from RequestObjectResize @@ -216,6 +218,10 @@ public: OUString GetObjTitle() const; void SetObjTitle( const OUString& rTitle, bool bBroadcast = false ); + + OUString GetObjTooltip() const; + void SetObjTooltip(const OUString& rTooltip); + OUString GetObjDescription() const; void SetObjDescription( const OUString& rDescription, bool bBroadcast = false ); diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx index d86e28fcc170..cdd1d2a8a64b 100644 --- a/sw/qa/core/unocore/unocore.cxx +++ b/sw/qa/core/unocore/unocore.cxx @@ -194,6 +194,31 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testUserFieldTooltip) CPPUNIT_ASSERT_EQUAL(aExpected, getProperty<OUString>(xFieldProps, "Title")); } +CPPUNIT_TEST_FIXTURE(SwModelTestBase, testImageTooltip) +{ + // Given a document with an image and a hyperlink on it: + loadURL("private:factory/swriter", nullptr); + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextContent> xImage( + xFactory->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xText->insertTextContent(xCursor, xImage, /*bAbsorb=*/false); + uno::Reference<beans::XPropertySet> xImageProps(xImage, uno::UNO_QUERY); + xImageProps->setPropertyValue("HyperLinkURL", uno::makeAny(OUString("http://www.example.com"))); + + // When setting a tooltip on the image: + OUString aExpected("first line\nsecond line"); + xImageProps->setPropertyValue("Tooltip", uno::makeAny(aExpected)); + + // Then make sure that the tooltip we read back matches the one previously specified: + // Without the accompanying fix in place, this test would have failed with: + // An uncaught exception of type com.sun.star.beans.UnknownPropertyException + // i.e. reading/writing of the tooltip was broken. + CPPUNIT_ASSERT_EQUAL(aExpected, getProperty<OUString>(xImageProps, "Tooltip")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/draw/dpage.cxx b/sw/source/core/draw/dpage.cxx index 39e5f93e37fe..18c40e9d97a7 100644 --- a/sw/source/core/draw/dpage.cxx +++ b/sw/source/core/draw/dpage.cxx @@ -159,6 +159,7 @@ bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView, SwVirtFlyDrawObj* pDrawObj = dynamic_cast<SwVirtFlyDrawObj*>(pObj); OUString sText; tools::Rectangle aPixRect; + bool bTooltip = false; if (pDrawObj) { SwFlyFrame *pFly = pDrawObj->GetFlyFrame(); @@ -166,7 +167,13 @@ bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView, aPixRect = pWindow->LogicToPixel(pFly->getFrameArea().SVRect()); const SwFormatURL &rURL = pFly->GetFormat()->GetURL(); - if( rURL.GetMap() ) + if (!pFly->GetFormat()->GetObjTooltip().isEmpty()) + { + // Tooltips have priority over URLs. + sText = pFly->GetFormat()->GetObjTooltip(); + bTooltip = true; + } + else if( rURL.GetMap() ) { IMapObject *pTmpObj = pFly->GetFormat()->GetIMapObject( aPos, pFly ); if( pTmpObj ) @@ -215,7 +222,7 @@ bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView, { // #i80029# bool bExecHyperlinks = pDoc->GetDocShell()->IsReadOnly(); - if (!bExecHyperlinks) + if (!bExecHyperlinks && !bTooltip) sText = SfxHelp::GetURLHelpText(sText); // then display the help: diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index d9f37a669787..b8d6b3655508 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -3165,6 +3165,16 @@ OUString SwFlyFrameFormat::GetObjTitle() const return msTitle; } +void SwFlyFrameFormat::SetObjTooltip(const OUString& rTooltip) +{ + msTooltip = rTooltip; +} + +OUString SwFlyFrameFormat::GetObjTooltip() const +{ + return msTooltip; +} + void SwFlyFrameFormat::SetObjDescription( const OUString& rDescription, bool bBroadcast ) { SdrObject* pMasterObject = FindSdrObject(); diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 58801e2fb971..4974e2786c43 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -1514,6 +1514,13 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& GetOrCreateSdrObject(rFlyFormat); rFlyFormat.GetDoc()->SetFlyFrameTitle(rFlyFormat, sTitle); } + else if (pEntry->nWID == FN_UNO_TOOLTIP) + { + SwFlyFrameFormat& rFlyFormat = dynamic_cast<SwFlyFrameFormat&>(*pFormat); + OUString sTooltip; + aValue >>= sTooltip; + rFlyFormat.SetObjTooltip(sTooltip); + } // New attribute Description else if( FN_UNO_DESCRIPTION == pEntry->nWID ) { @@ -2135,6 +2142,11 @@ uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName) GetOrCreateSdrObject(rFlyFormat); aAny <<= rFlyFormat.GetObjTitle(); } + else if (pEntry->nWID == FN_UNO_TOOLTIP) + { + SwFlyFrameFormat& rFlyFormat = dynamic_cast<SwFlyFrameFormat&>(*pFormat); + aAny <<= rFlyFormat.GetObjTooltip(); + } // New attribute Description else if( FN_UNO_DESCRIPTION == pEntry->nWID ) { diff --git a/sw/source/core/unocore/unomapproperties.hxx b/sw/source/core/unocore/unomapproperties.hxx index 0b211f392b67..74792d5854e3 100644 --- a/sw/source/core/unocore/unomapproperties.hxx +++ b/sw/source/core/unocore/unomapproperties.hxx @@ -328,6 +328,7 @@ { OUString(UNO_NAME_WRAP_INFLUENCE_ON_POSITION), RES_WRAP_INFLUENCE_ON_OBJPOS, cppu::UnoType<sal_Int8>::get(), PROPERTY_NONE, MID_WRAP_INFLUENCE}, \ { OUString(UNO_NAME_ALLOW_OVERLAP), RES_WRAP_INFLUENCE_ON_OBJPOS, cppu::UnoType<bool>::get(), PROPERTY_NONE, MID_ALLOW_OVERLAP}, \ { OUString(UNO_NAME_TITLE), FN_UNO_TITLE, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0}, \ + { OUString(UNO_NAME_TOOLTIP), FN_UNO_TOOLTIP, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0}, \ { OUString(UNO_NAME_DESCRIPTION), FN_UNO_DESCRIPTION, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0}, \ { OUString(UNO_NAME_LAYOUT_SIZE), WID_LAYOUT_SIZE, cppu::UnoType<css::awt::Size>::get(), PropertyAttribute::MAYBEVOID | PropertyAttribute::READONLY, 0 }, \ { OUString(UNO_NAME_LINE_STYLE), RES_BOX, cppu::UnoType<css::drawing::LineStyle>::get(), 0, LINE_STYLE }, \
