include/vcl/weld.hxx          |   10 +++++++++
 vcl/inc/salvtables.hxx        |    6 +++++
 vcl/source/app/salvtables.cxx |   29 ++++++++++++++++++++++++++
 vcl/unx/gtk3/gtkinst.cxx      |   46 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+)

New commits:
commit 49148b925f296c22378088c8f1c01164e5599c89
Author:     Mike Kaganski <[email protected]>
AuthorDate: Tue May 24 18:43:45 2022 +0200
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Jun 5 07:54:19 2022 +0200

    Implement weld::IconView::[gs]et_item_width
    
    Change-Id: I211e3c21b4e0148c4ff6fc9931838e37ccd0cc41
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134897
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135417
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index f9684606d644..9fe575fe50ec 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1331,6 +1331,9 @@ protected:
     OUString signal_query_tooltip(const TreeIter& rIter) { return 
m_aQueryTooltipHdl.Call(rIter); }
 
 public:
+    virtual int get_item_width() const = 0;
+    virtual void set_item_width(int width) = 0;
+
     virtual void insert(int pos, const OUString* pStr, const OUString* pId,
                         const OUString* pIconName, TreeIter* pRet)
         = 0;
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index e302e59a3318..036e769d1a37 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -1754,6 +1754,9 @@ private:
 public:
     SalInstanceIconView(::IconView* pIconView, SalInstanceBuilder* pBuilder, 
bool bTakeOwnership);
 
+    virtual int get_item_width() const override;
+    virtual void set_item_width(int width) override;
+
     virtual void freeze() override;
 
     virtual void thaw() override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 830047f3a079..925bfa324a68 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5195,6 +5195,9 @@ SalInstanceIconView::SalInstanceIconView(::IconView* 
pIconView, SalInstanceBuild
     m_xIconView->SetPopupMenuHdl(LINK(this, SalInstanceIconView, CommandHdl));
 }
 
+int SalInstanceIconView::get_item_width() const { return 
m_xIconView->GetEntryWidth(); }
+void SalInstanceIconView::set_item_width(int width) { 
m_xIconView->SetEntryWidth(width); }
+
 void SalInstanceIconView::freeze()
 {
     bool bIsFirstFreeze = IsFirstFreeze();
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 7cb845d92a32..80e07031bdac 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -16066,6 +16066,16 @@ public:
         m_nIdCol = m_nTextCol + 1;
     }
 
+    virtual int get_item_width() const override
+    {
+        return gtk_icon_view_get_item_width(m_pIconView);
+    }
+
+    virtual void set_item_width(int width) override
+    {
+        gtk_icon_view_set_item_width(m_pIconView, width);
+    }
+
     virtual void insert(int pos, const OUString* pText, const OUString* pId, 
const OUString* pIconName, weld::TreeIter* pRet) override
     {
         disable_notify_events();
commit aa56360855a372fcc3329b04d8ab045b8ef09cab
Author:     Mike Kaganski <[email protected]>
AuthorDate: Mon May 23 12:48:15 2022 +0300
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Jun 5 07:54:04 2022 +0200

    Implement weld::IconView::connect_query_tooltip
    
    Change-Id: I8a8540e240d6a7046f564404c7c3b6bff8c2f04d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134806
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135416
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 5fab9b459a8b..f9684606d644 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1324,9 +1324,11 @@ protected:
     Link<IconView&, void> m_aSelectionChangeHdl;
     Link<IconView&, bool> m_aItemActivatedHdl;
     Link<const CommandEvent&, bool> m_aCommandHdl;
+    Link<const TreeIter&, OUString> m_aQueryTooltipHdl;
 
     void signal_selection_changed() { m_aSelectionChangeHdl.Call(*this); }
     bool signal_item_activated() { return m_aItemActivatedHdl.Call(*this); }
+    OUString signal_query_tooltip(const TreeIter& rIter) { return 
m_aQueryTooltipHdl.Call(rIter); }
 
 public:
     virtual void insert(int pos, const OUString* pStr, const OUString* pId,
@@ -1362,6 +1364,11 @@ public:
 
     void connect_command(const Link<const CommandEvent&, bool>& rLink) { 
m_aCommandHdl = rLink; }
 
+    virtual void connect_query_tooltip(const Link<const TreeIter&, OUString>& 
rLink)
+    {
+        m_aQueryTooltipHdl = rLink;
+    }
+
     virtual OUString get_selected_id() const = 0;
 
     virtual void clear() = 0;
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index c44fa1f96234..e302e59a3318 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -1749,6 +1749,7 @@ private:
     DECL_LINK(DeSelectHdl, SvTreeListBox*, void);
     DECL_LINK(DoubleClickHdl, SvTreeListBox*, bool);
     DECL_LINK(CommandHdl, const CommandEvent&, bool);
+    DECL_LINK(TooltipHdl, const HelpEvent&, bool);
 
 public:
     SalInstanceIconView(::IconView* pIconView, SalInstanceBuilder* pBuilder, 
bool bTakeOwnership);
@@ -1763,6 +1764,8 @@ public:
     virtual void insert(int pos, const OUString* pStr, const OUString* pId,
                         const VirtualDevice* pIcon, weld::TreeIter* pRet) 
override;
 
+    virtual void connect_query_tooltip(const Link<const weld::TreeIter&, 
OUString>& rLink) override;
+
     virtual OUString get_selected_id() const override;
 
     virtual OUString get_selected_text() const override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 96eeca4d9355..830047f3a079 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5291,6 +5291,32 @@ void SalInstanceIconView::insert(int pos, const 
OUString* pStr, const OUString*
     enable_notify_events();
 }
 
+IMPL_LINK(SalInstanceIconView, TooltipHdl, const HelpEvent&, rHEvt, bool)
+{
+    if (notify_events_disabled())
+        return false;
+    Point aPos(m_xIconView->ScreenToOutputPixel(rHEvt.GetMousePosPixel()));
+    SvTreeListEntry* pEntry = m_xIconView->GetEntry(aPos);
+    if (pEntry)
+    {
+        SalInstanceTreeIter aIter(pEntry);
+        OUString aTooltip = signal_query_tooltip(aIter);
+        if (aTooltip.isEmpty())
+            return false;
+        Size aSize(m_xIconView->GetOutputSizePixel().Width(), 
m_xIconView->GetEntryHeight());
+        tools::Rectangle aScreenRect(
+            
m_xIconView->OutputToScreenPixel(m_xIconView->GetEntryPosition(pEntry)), aSize);
+        Help::ShowQuickHelp(m_xIconView, aScreenRect, aTooltip);
+    }
+    return true;
+}
+
+void SalInstanceIconView::connect_query_tooltip(const Link<const 
weld::TreeIter&, OUString>& rLink)
+{
+    weld::IconView::connect_query_tooltip(rLink);
+    m_xIconView->SetTooltipHdl(LINK(this, SalInstanceIconView, TooltipHdl));
+}
+
 OUString SalInstanceIconView::get_selected_id() const
 {
     assert(m_xIconView->IsUpdateMode() && "don't request selection when 
frozen");
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 4008e98baf0a..7cb845d92a32 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -15913,6 +15913,7 @@ private:
 #if !GTK_CHECK_VERSION(4, 0, 0)
     gulong m_nPopupMenu;
 #endif
+    gulong m_nQueryTooltipSignalId = 0;
     ImplSVEvent* m_pSelectionChangeEvent;
 
     DECL_LINK(async_signal_selection_changed, void*, void);
@@ -15959,6 +15960,32 @@ private:
         pThis->handle_item_activated();
     }
 
+    static gboolean signalQueryTooltip(GtkWidget* /*pGtkWidget*/, gint x, gint 
y,
+        gboolean keyboard_tip, GtkTooltip* tooltip,
+        gpointer widget)
+    {
+        GtkInstanceIconView* pThis = static_cast<GtkInstanceIconView*>(widget);
+        GtkTreeIter iter;
+        GtkIconView* pIconView = pThis->m_pIconView;
+        GtkTreeModel* pModel = gtk_icon_view_get_model(pIconView);
+        GtkTreePath* pPath = nullptr;
+#if GTK_CHECK_VERSION(4, 0, 0)
+        if (!gtk_icon_view_get_tooltip_context(pIconView, x, y, keyboard_tip, 
&pModel, &pPath, &iter))
+            return false;
+#else
+        if (!gtk_icon_view_get_tooltip_context(pIconView, &x, &y, 
keyboard_tip, &pModel, &pPath, &iter))
+            return false;
+#endif
+        OUString aTooltip = 
pThis->signal_query_tooltip(GtkInstanceTreeIter(iter));
+        if (!aTooltip.isEmpty())
+        {
+            gtk_tooltip_set_text(tooltip, OUStringToOString(aTooltip, 
RTL_TEXTENCODING_UTF8).getStr());
+            gtk_icon_view_set_tooltip_item(pIconView, tooltip, pPath);
+        }
+        gtk_tree_path_free(pPath);
+        return !aTooltip.isEmpty();
+    }
+
     void insert_item(GtkTreeIter& iter, int pos, const OUString* pId, const 
OUString* pText, const OUString* pIconName)
     {
         gtk_tree_store_insert_with_values(m_pTreeStore, &iter, nullptr, pos,
@@ -16065,6 +16092,12 @@ public:
         enable_notify_events();
     }
 
+    virtual void connect_query_tooltip(const Link<const weld::TreeIter&, 
OUString>& rLink) override
+    {
+        weld::IconView::connect_query_tooltip(rLink);
+        m_nQueryTooltipSignalId = g_signal_connect(m_pIconView, 
"query-tooltip", G_CALLBACK(signalQueryTooltip), this);
+    }
+
     virtual OUString get_selected_id() const override
     {
         assert(gtk_icon_view_get_model(m_pIconView) && "don't request 
selection when frozen");
@@ -16309,6 +16342,9 @@ public:
         if (m_pSelectionChangeEvent)
             Application::RemoveUserEvent(m_pSelectionChangeEvent);
 
+        if (m_nQueryTooltipSignalId)
+            g_signal_handler_disconnect(m_pIconView, m_nQueryTooltipSignalId);
+
         g_signal_handler_disconnect(m_pIconView, m_nItemActivatedSignalId);
         g_signal_handler_disconnect(m_pIconView, m_nSelectionChangedSignalId);
 #if !GTK_CHECK_VERSION(4, 0, 0)

Reply via email to