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.
Change-Id: Ife34dab5e4490eb1682c55fb7c01f7509d0057fc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132361
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/offapi/com/sun/star/text/BaseFrameProperties.idl b/offapi/com/sun/star/text/BaseFrameProperties.idl
index bffa5dd..3741f0a 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 c42818d..4add360 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -862,6 +862,7 @@ class SwUINumRuleItem;
#define FN_SET_FRM_ALT_NAME TypedWhichId<SfxStringItem>(FN_FRAME + 18)
#define FN_UNO_TITLE (FN_FRAME + 19)
#define FN_UNO_DESCRIPTION TypedWhichId<SfxStringItem>(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 59aee54..12795bf 100644
--- a/sw/inc/frmfmt.hxx
+++ b/sw/inc/frmfmt.hxx
@@ -191,6 +191,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
@@ -220,6 +222,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 f7181a2..3d5bb93 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -337,6 +337,31 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlInsert)
CPPUNIT_ASSERT(pAttr);
}
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 bd62ee3..fc1c1ebb 100644
--- a/sw/source/core/draw/dpage.cxx
+++ b/sw/source/core/draw/dpage.cxx
@@ -160,6 +160,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();
@@ -167,7 +168,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 )
@@ -216,7 +223,7 @@ bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
{
// #i80029#
bool bExecHyperlinks = m_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 4617699..e3f1934 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -3201,6 +3201,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 44b329d..fd5989a 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1529,6 +1529,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 )
{
@@ -2163,6 +2170,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 b859aad..e2e1ce1 100644
--- a/sw/source/core/unocore/unomapproperties.hxx
+++ b/sw/source/core/unocore/unomapproperties.hxx
@@ -329,6 +329,7 @@
{ u"" UNO_NAME_WRAP_INFLUENCE_ON_POSITION, RES_WRAP_INFLUENCE_ON_OBJPOS, cppu::UnoType<sal_Int8>::get(), PROPERTY_NONE, MID_WRAP_INFLUENCE}, \
{ u"" UNO_NAME_ALLOW_OVERLAP, RES_WRAP_INFLUENCE_ON_OBJPOS, cppu::UnoType<bool>::get(), PROPERTY_NONE, MID_ALLOW_OVERLAP}, \
{ u"" UNO_NAME_TITLE, FN_UNO_TITLE, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0}, \
{ u"" UNO_NAME_TOOLTIP, FN_UNO_TOOLTIP, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0}, \
{ u"" UNO_NAME_DESCRIPTION, FN_UNO_DESCRIPTION, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0}, \
{ u"" UNO_NAME_LAYOUT_SIZE, WID_LAYOUT_SIZE, cppu::UnoType<css::awt::Size>::get(), PropertyAttribute::MAYBEVOID | PropertyAttribute::READONLY, 0 }, \
{ u"" UNO_NAME_LINE_STYLE, RES_BOX, cppu::UnoType<css::drawing::LineStyle>::get(), 0, LINE_STYLE }, \