From baa18e85220c3b7f77dbe6d8622265bc80a7c1e7 Mon Sep 17 00:00:00 2001 From: gambas Date: Fri, 24 May 2019 01:58:28 +0200 Subject: [PATCH] Tooltips now support rich text, like in the QT components. [GB.GTK] * BUG: Tooltips now support rich text, like in the QT components. [GB.GTK3] * BUG: Tooltips now support rich text, like in the QT components. --- gb.gtk/src/CWidget.cpp | 2 +- gb.gtk/src/gcontrol.cpp | 30 ++++++++++++++++++++---------- gb.gtk/src/gcontrol.h | 4 +++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/gb.gtk/src/CWidget.cpp b/gb.gtk/src/CWidget.cpp index 0e41b5aee..ec17ac016 100644 --- a/gb.gtk/src/CWidget.cpp +++ b/gb.gtk/src/CWidget.cpp @@ -831,7 +831,7 @@ BEGIN_PROPERTY(CWIDGET_tooltip) return; } - CONTROL->setToolTip(GB.ToZeroString(PROP(GB_STRING))); + CONTROL->setTooltip(GB.ToZeroString(PROP(GB_STRING))); END_PROPERTY diff --git a/gb.gtk/src/gcontrol.cpp b/gb.gtk/src/gcontrol.cpp index c6711e042..870ea712f 100644 --- a/gb.gtk/src/gcontrol.cpp +++ b/gb.gtk/src/gcontrol.cpp @@ -314,6 +314,7 @@ void gControl::initAll(gContainer *parent) _use_wheel = false; _scrollbar = SCROLL_NONE; _input_method = NULL; + _tooltip = NULL; onFinish = NULL; onFocusEvent = NULL; @@ -389,7 +390,10 @@ gControl::~gControl() //fprintf(stderr, "~gControl: %s\n", name()); - setName(NULL); + if (_name) + g_free(_name); + if (_tooltip) + g_free(_tooltip); controls = g_list_remove(controls, this); controls_destroyed = g_list_remove(controls_destroyed, this); @@ -724,16 +728,22 @@ void gControl::setIgnore (bool vl) if (pr) pr->performArrange(); } -char* gControl::toolTip() +void gControl::setTooltip(char *vl) { - char *text = gtk_widget_get_tooltip_text(border); - gt_free_later(text); - return text; -} - -void gControl::setToolTip(char* vl) -{ - gtk_widget_set_tooltip_text(border, vl ? vl : ""); + char *pango; + + if (_tooltip) g_free(_tooltip); + _tooltip = NULL; + if (vl) _tooltip = g_strdup(vl); + + if (_tooltip) + { + pango = gt_html_to_pango_string(_tooltip, -1, false); + gtk_widget_set_tooltip_markup(border, pango); + g_free(pango); + } + else + gtk_widget_set_tooltip_markup(border, NULL); } gFont* gControl::font() diff --git a/gb.gtk/src/gcontrol.h b/gb.gtk/src/gcontrol.h index 7c7999ffe..eaea77aa2 100644 --- a/gb.gtk/src/gcontrol.h +++ b/gb.gtk/src/gcontrol.h @@ -92,7 +92,8 @@ public: void setLeft(int l); void setMouse(int m); virtual void updateCursor(GdkCursor *cursor); - void setToolTip(char *vl); + char *tooltip() { return _tooltip; } + void setTooltip(char *vl); void setTop(int t); virtual void setVisible(bool v); virtual void setWidth(int w); @@ -215,6 +216,7 @@ public: short _mouse; gControl *_proxy, *_proxy_for; gColor _bg, _fg; + char *_tooltip; #ifdef GTK3 GtkStyleProvider *_css; const char *_bg_name;