summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-03-31 14:27:40 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-03-31 15:59:46 +0200
commit9caf6e4a3ac05a9d2e9d695e59d4ae048bf078b2 (patch)
treede039fdd89d7a250a269825269fee82c74ac3c55 /sw
parentbfb6c4c65781a610d21409d974227d73f264f41a (diff)
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
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/cmdid.h1
-rw-r--r--sw/inc/frmfmt.hxx6
-rw-r--r--sw/qa/core/unocore/unocore.cxx25
-rw-r--r--sw/source/core/draw/dpage.cxx11
-rw-r--r--sw/source/core/layout/atrfrm.cxx10
-rw-r--r--sw/source/core/unocore/unoframe.cxx12
-rw-r--r--sw/source/core/unocore/unomapproperties.hxx1
7 files changed, 64 insertions, 2 deletions
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index c42818d25fa5..4add360583bb 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 59aee54a2f4a..12795bf10428 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 f7181a22b2b1..3d5bb93f2600 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 bd62ee33e4be..fc1c1ebb7524 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 46176999e6d1..e3f193470367 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 44b329d1d55c..fd5989a77606 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 b859aadaa025..e2e1ce136553 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 }, \