include/svx/fontworkgallery.hxx | 3 --- include/vcl/toolkit/treelistbox.hxx | 2 +- include/vcl/toolkit/treelistentry.hxx | 5 +++++ include/vcl/weld.hxx | 1 + svx/source/tbxctrls/fontworkgallery.cxx | 20 ++++++-------------- svx/uiconfig/ui/fontworkgallerydialog.ui | 3 +++ vcl/inc/qt5/QtInstanceIconView.hxx | 1 + vcl/inc/salvtables.hxx | 2 ++ vcl/qt5/QtInstanceIconView.cxx | 10 ++++++++++ vcl/source/app/salvtables.cxx | 7 +++++++ vcl/source/treelist/treelistbox.cxx | 28 +++++++++++++++++----------- vcl/unx/gtk3/gtkinst.cxx | 12 ++++++++++++ 12 files changed, 65 insertions(+), 29 deletions(-)
New commits: commit e335712cfb6c7b5a9f28cebb778bcc7b90c9f16a Author: Michael Weghorn <[email protected]> AuthorDate: Tue Dec 16 12:53:12 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Dec 16 23:17:01 2025 +0100 tdf#130857 Set fontwork item tooltips directly Use the new API introduced in previous commit Change-Id: I56e8dde0b591073dea7f58190746ca0ba1fd8a4f Author: Michael Weghorn <[email protected]> Date: Tue Dec 16 12:10:48 2025 +0100 tdf#130857 tdf#168594 weld: Introduce weld::IconView::set_item_tooltip_text to directly set the tooltip text for each of the items, just like the accessible name (which is using the same string) is also set directly in FontWorkGalleryDialog::fillFavorites. For gtk3/gtk4, add a corresponding column in the GtkIconView model and set GtkIconView::tooltip-column accordingly, as described in the above-mentioned commit. This also gets rid of the need to remember the titles for the items in a map. Simplify the loop a bit by using the index and adding 1 once instead of using index+1 and subtracting 1 everywhere else to get the index again. The dialog can be triggered using "Insert" -> "Fontwork..." in Writer. Change-Id: I0f41a5a4fd13a3296fe9dcd84ea71e7d2d153a97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195712 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/include/svx/fontworkgallery.hxx b/include/svx/fontworkgallery.hxx index f4eb1c03f981..453206303266 100644 --- a/include/svx/fontworkgallery.hxx +++ b/include/svx/fontworkgallery.hxx @@ -55,8 +55,6 @@ class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC FontWorkGalleryDialog final : public wel SdrModel* mpDestModel; std::vector<Bitmap> maFavoritesHorizontal; - // mapping between item ID and item title - std::map<OUString, OUString> maIdToTitleMap; std::unique_ptr<weld::IconView> maCtlFavorites; std::unique_ptr<weld::Button> mxOKButton; @@ -69,7 +67,6 @@ class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC FontWorkGalleryDialog final : public wel DECL_DLLPRIVATE_LINK(DoubleClickFavoriteHdl, weld::IconView&, bool); DECL_DLLPRIVATE_LINK(ClickOKHdl, weld::Button&, void ); - DECL_DLLPRIVATE_LINK(QueryTooltipHandler, const weld::TreeIter&, OUString); public: FontWorkGalleryDialog(weld::Window* pParent, SdrView& rView, diff --git a/svx/source/tbxctrls/fontworkgallery.cxx b/svx/source/tbxctrls/fontworkgallery.cxx index 923c9b8a7f2d..c564bc17fd61 100644 --- a/svx/source/tbxctrls/fontworkgallery.cxx +++ b/svx/source/tbxctrls/fontworkgallery.cxx @@ -73,7 +73,6 @@ FontWorkGalleryDialog::FontWorkGalleryDialog(weld::Window* pParent, SdrView& rSd maCtlFavorites->set_size_request(aSize.Width(), aSize.Height()); maCtlFavorites->connect_item_activated( LINK( this, FontWorkGalleryDialog, DoubleClickFavoriteHdl ) ); - maCtlFavorites->connect_query_tooltip(LINK(this, FontWorkGalleryDialog, QueryTooltipHandler)); mxOKButton->connect_clicked(LINK(this, FontWorkGalleryDialog, ClickOKHdl)); initFavorites( GALLERY_THEME_FONTWORK ); @@ -133,18 +132,18 @@ void FontWorkGalleryDialog::fillFavorites(sal_uInt16 nThemeId) auto nFavCount = maFavoritesHorizontal.size(); maCtlFavorites->clear(); - maIdToTitleMap.clear(); std::vector<OUString> aTitles; (void)GalleryExplorer::FillObjListTitle(nThemeId, aTitles); assert(aTitles.size() == nFavCount); - for( size_t nFavorite = 1; nFavorite <= nFavCount; nFavorite++ ) + for (size_t nIndex = 0; nIndex < nFavCount; nIndex++) { - OUString sId = OUString::number(static_cast<sal_uInt16>(nFavorite)); - maIdToTitleMap.emplace(sId, aTitles.at(nFavorite - 1)); - maCtlFavorites->insert(-1, nullptr, &sId, &maFavoritesHorizontal[nFavorite - 1], nullptr); - maCtlFavorites->set_item_accessible_name(maCtlFavorites->n_children() - 1, aTitles.at(nFavorite -1)); + OUString sId = OUString::number(static_cast<sal_uInt16>(nIndex + 1)); + const OUString sTitle = aTitles.at(nIndex); + maCtlFavorites->insert(-1, nullptr, &sId, &maFavoritesHorizontal[nIndex], nullptr); + maCtlFavorites->set_item_accessible_name(nIndex, sTitle); + maCtlFavorites->set_item_tooltip_text(nIndex, sTitle); } if (maCtlFavorites->n_children()) @@ -285,13 +284,6 @@ IMPL_LINK_NOARG(FontWorkGalleryDialog, DoubleClickFavoriteHdl, weld::IconView&, return true; } -IMPL_LINK(FontWorkGalleryDialog, QueryTooltipHandler, const weld::TreeIter&, iter, OUString) -{ - const OUString id = maCtlFavorites->get_id(iter); - auto it = maIdToTitleMap.find(id); - return it != maIdToTitleMap.end() ? it->second : OUString(); -} - namespace { class FontworkAlignmentWindow final : public WeldToolbarPopup diff --git a/svx/uiconfig/ui/fontworkgallerydialog.ui b/svx/uiconfig/ui/fontworkgallerydialog.ui index 2d6a8f85285d..65a749ab4a23 100644 --- a/svx/uiconfig/ui/fontworkgallerydialog.ui +++ b/svx/uiconfig/ui/fontworkgallerydialog.ui @@ -8,6 +8,8 @@ <column type="GdkPixbuf"/> <!-- column-name id --> <column type="gchararray"/> + <!-- column-name tooltip --> + <column type="gchararray"/> </columns> </object> <object class="GtkDialog" id="FontworkGalleryDialog"> @@ -118,6 +120,7 @@ <property name="vexpand">True</property> <property name="model">liststore1</property> <property name="pixbuf-column">0</property> + <property name="tooltip-column">2</property> <child internal-child="accessible"> <object class="AtkObject" id="ctlFavoriteswin-atkobject"> <property name="AtkObject::accessible-description" translatable="yes" context="fontworkgallerydialog|extended_tip|ctlFavoriteWin">Select a Fontwork style and click OK to insert the Fontwork into your document. Double-click or Ctrl (Command) + double-click the Fontwork in your document to enter text edit mode and change the text.</property> commit 6298d4854eebd542d3be58cc7ff95053e51217b9 Author: Michael Weghorn <[email protected]> AuthorDate: Tue Dec 16 12:10:48 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Dec 16 23:16:54 2025 +0100 tdf#130857 tdf#168594 weld: Introduce weld::IconView::set_item_tooltip_text Introduce a new weld::IconView method that allows to directly set the tooltip for an item in the IconView and implement the logic for all of the weld::IconView implementations. GtkIconView has a GtkIconView::tooltip-column property [1] that is the index for the column in the underlying model that holds the tooltip text. For the gtk3/gtk4 implementation in GtkInstanceIconView, that property can and will have to be set for the GtkIconView in the .ui file - similar to what is already the case for GtkIconView::pixbuf-column [2]. Prior to this commit, a tooltip could be set by setting a handler using weld::IconView::connect_query_tooltip and implementing logic to retrieve the tooltip text in the handler. Being able to set the tooltip directly simplifies the handling where the tooltip for each item is fixed and allows to set it right away, e.g. to the same text that is already set as the item's accessible name (using weld::IconView::set_item_accessible_name). Upcoming commits will convert uses of weld::IconView::connect_query_tooltip to use the new API instead, see for example Change-Id: I0f41a5a4fd13a3296fe9dcd84ea71e7d2d153a97 Author: Michael Weghorn <[email protected]> Date: Tue Dec 16 12:37:43 2025 +0100 tdf#130857 Set fontwork item tooltips directly [1] https://docs.gtk.org/gtk3/property.IconView.tooltip-column.html [2] https://docs.gtk.org/gtk3/property.IconView.pixbuf-column.html Change-Id: I56e8dde0b591073dea7f58190746ca0ba1fd8a4f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195711 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/include/vcl/toolkit/treelistbox.hxx b/include/vcl/toolkit/treelistbox.hxx index 7e86a5aa74b1..3c826a8bf605 100644 --- a/include/vcl/toolkit/treelistbox.hxx +++ b/include/vcl/toolkit/treelistbox.hxx @@ -394,7 +394,7 @@ public: SvViewDataItem* GetViewDataItem(SvTreeListEntry const *, SvLBoxItem const *); const SvViewDataItem* GetViewDataItem(const SvTreeListEntry*, const SvLBoxItem*) const; - OUString GetEntryTooltip(SvTreeListEntry* pEntry) const { return aTooltipHdl.Call(pEntry); } + OUString GetEntryTooltip(SvTreeListEntry* pEntry) const; VclPtr<Edit> GetEditWidget() const; // for UITest bool IsInplaceEditingEnabled() const { return bool(nImpFlags & SvTreeListBoxFlags::EDT_ENABLED); } diff --git a/include/vcl/toolkit/treelistentry.hxx b/include/vcl/toolkit/treelistentry.hxx index 599a4e6a21e1..dc20bda5b240 100644 --- a/include/vcl/toolkit/treelistentry.hxx +++ b/include/vcl/toolkit/treelistentry.hxx @@ -71,6 +71,7 @@ class UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC) SvTreeListEntry SvTLEntryFlags nEntryFlags; std::optional<Color> mxTextColor; OUString m_sAccessibleName; + OUString m_sToolTip; private: void ClearChildren(); @@ -120,6 +121,10 @@ public: void SetTextColor( std::optional<Color> xColor ) { mxTextColor = xColor; } OUString GetAccessibleName() { return m_sAccessibleName; } void SetAccessibleName(const OUString& rName) { m_sAccessibleName = rName; }; + + OUString GetToolTip() { return m_sToolTip; }; + void SetToolTip(const OUString& rToolTip) { m_sToolTip = rToolTip; }; + std::optional<Color> const & GetTextColor() const { return mxTextColor; } void SetExtraIndent(sal_uInt32 nExtraIndent) { mnExtraIndent = nExtraIndent; } diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 8bc8f0be4f55..cc53e9a45416 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -1775,6 +1775,7 @@ public: virtual void set_text(int pos, const OUString& rText) = 0; virtual void set_id(int pos, const OUString& rId) = 0; virtual void set_item_accessible_name(int pos, const OUString& rName) = 0; + virtual void set_item_tooltip_text(int pos, const OUString& rToolTip) = 0; void remove(int pos) { diff --git a/vcl/inc/qt5/QtInstanceIconView.hxx b/vcl/inc/qt5/QtInstanceIconView.hxx index e5db98f36e1f..bc6dcb3e7806 100644 --- a/vcl/inc/qt5/QtInstanceIconView.hxx +++ b/vcl/inc/qt5/QtInstanceIconView.hxx @@ -51,6 +51,7 @@ public: virtual void set_text(int nPos, const OUString& rText) override; virtual void set_id(int nPos, const OUString& rId) override; virtual void set_item_accessible_name(int nPos, const OUString& rName) override; + virtual void set_item_tooltip_text(int nPos, const OUString& rToolTip) override; virtual void do_remove(int pos) override; virtual tools::Rectangle get_rect(int pos) const override; diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index da289d302845..097c7e0b758d 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -1970,6 +1970,8 @@ public: virtual void set_item_accessible_name(int pos, const OUString& rName) override; + virtual void set_item_tooltip_text(int pos, const OUString& rToolTip) override; + virtual OUString get_text(const weld::TreeIter& rIter) const override; virtual tools::Rectangle get_rect(int pos) const override; diff --git a/vcl/qt5/QtInstanceIconView.cxx b/vcl/qt5/QtInstanceIconView.cxx index ed0382439180..4a9d825f8a02 100644 --- a/vcl/qt5/QtInstanceIconView.cxx +++ b/vcl/qt5/QtInstanceIconView.cxx @@ -209,6 +209,16 @@ void QtInstanceIconView::set_item_accessible_name(int nPos, const OUString& rNam }); } +void QtInstanceIconView::set_item_tooltip_text(int nPos, const OUString& rToolTip) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + QModelIndex aIndex = modelIndex(nPos); + m_pModel->setData(aIndex, toQString(rToolTip), Qt::ToolTipRole); + }); +} + void QtInstanceIconView::do_remove(int) { assert(false && "Not implemented yet"); } tools::Rectangle QtInstanceIconView::get_rect(int) const diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 1d2d44ffbfa3..b1a1e3c2657f 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -5587,6 +5587,13 @@ void SalInstanceIconView::set_item_accessible_name(int pos, const OUString& rNam pEntry->SetAccessibleName(rName); } +void SalInstanceIconView::set_item_tooltip_text(int pos, const OUString& rToolTip) +{ + SvTreeListEntry* pEntry = m_xIconView->GetEntry(pos); + assert(pEntry); + pEntry->SetToolTip(rToolTip); +} + tools::Rectangle SalInstanceIconView::get_rect(int pos) const { SvTreeListEntry* aEntry = m_xIconView->GetEntry(nullptr, pos); diff --git a/vcl/source/treelist/treelistbox.cxx b/vcl/source/treelist/treelistbox.cxx index ec8f1edb797b..92fca3bf1519 100644 --- a/vcl/source/treelist/treelistbox.cxx +++ b/vcl/source/treelist/treelistbox.cxx @@ -832,6 +832,15 @@ const SvViewDataItem* SvTreeListBox::GetViewDataItem(const SvTreeListEntry* pEnt return &pEntryData->GetItem(nItemPos); } +OUString SvTreeListBox::GetEntryTooltip(SvTreeListEntry* pEntry) const +{ + const OUString sToolTip = aTooltipHdl.Call(pEntry); + if (!sToolTip.isEmpty()) + return sToolTip; + + return pEntry->GetToolTip(); +} + void SvTreeListBox::InitViewData( SvViewDataEntry* pData, SvTreeListEntry* pEntry ) { SvTreeListEntry* pInhEntry = pEntry; diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index ed775b97c427..297b953c3fea 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -16914,6 +16914,18 @@ private: #endif } + virtual void set_item_tooltip_text(int pos, const OUString& rToolTip) override + { + const int nToolTipCol = gtk_icon_view_get_tooltip_column(m_pIconView); + assert(nToolTipCol >= 0 + && "Invalid tooltip column. Is GtkIconView::tooltip-column set in the .ui file?"); + + GtkTreeModel* pModel = GTK_TREE_MODEL(m_pTreeStore); + GtkTreeIter iter; + if (gtk_tree_model_iter_nth_child(pModel, &iter, nullptr, pos)) + gtk_tree_store_set(m_pTreeStore, &iter, nToolTipCol, rToolTip.toUtf8().getStr(), -1); + } + virtual void do_remove(int pos) override { disable_notify_events(); commit 07b53cfb8ef4424ce73674f514a08b9c8a3a2393 Author: Michael Weghorn <[email protected]> AuthorDate: Tue Dec 16 11:51:50 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Dec 16 23:16:47 2025 +0100 tdf#130857 tdf#168594 vcl: Drop superfluous check in SvTreeListBox::RequestHelp If SvTreeListBox::aTooltipHdl isn't set, SvTreeListBox::GetEntryTooltip will (for now) simply return an empty string, so there's no need to check that here explicitly. This is in preparation for an upcoming commit that will introduce a new method weld::IconView::set_item_tooltip_text to allow setting the tooltip of an entry directly via weld::IconView API. Change-Id: I48b449f26c03d53a04f0a42771d1fa189db71f81 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195710 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/source/treelist/treelistbox.cxx b/vcl/source/treelist/treelistbox.cxx index d43e3e51f67b..ec8f1edb797b 100644 --- a/vcl/source/treelist/treelistbox.cxx +++ b/vcl/source/treelist/treelistbox.cxx @@ -3330,19 +3330,16 @@ void SvTreeListBox::GetLastTab( SvLBoxTabFlags nFlagMask, sal_uInt16& rTabPos ) void SvTreeListBox::RequestHelp( const HelpEvent& rHEvt ) { - if (aTooltipHdl.IsSet()) + const Point pos(ScreenToOutputPixel(rHEvt.GetMousePosPixel())); + if (SvTreeListEntry* entry = GetEntry(pos)) { - const Point pos(ScreenToOutputPixel(rHEvt.GetMousePosPixel())); - if (SvTreeListEntry* entry = GetEntry(pos)) + const OUString tooltip = GetEntryTooltip(entry); + if (!tooltip.isEmpty()) { - const OUString tooltip = GetEntryTooltip(entry); - if (!tooltip.isEmpty()) - { - const Size size(GetOutputSizePixel().Width(), GetEntryHeight()); - tools::Rectangle screenRect(OutputToScreenPixel(GetEntryPosition(entry)), size); - Help::ShowQuickHelp(this, screenRect, tooltip); - return; - } + const Size size(GetOutputSizePixel().Width(), GetEntryHeight()); + tools::Rectangle screenRect(OutputToScreenPixel(GetEntryPosition(entry)), size); + Help::ShowQuickHelp(this, screenRect, tooltip); + return; } }
