forked from AuroraMiddleware/gtk
6b096e5c5b
The tooltip handling in GtkWidget is "special": - the string is stored inside the qdata instead of the private instance data - the accessors call g_object_set() and g_object_get(), and the logic is all inside the property implementation, instead of being the other way around - the getters return a copy of the string - the setters don't really notify all the involved properties The GtkWidgetAccessible uses the (escaped) tooltip text as a source for the accessible object description, which means it has to store the tooltip inside the object qdata, and update its copy at construction and property notification time. We can simplify this whole circus by making the tooltip properties (text and markup) more idiomatic: - notify all side-effect properties - return a constant string from the getter - if tooltip-text is set: - store the text as is - escape the markup and store it separately for the markup getter - if tooltip-markup is set: - store the markup as is - parse the markup and store it separately for the text getter The part of the testtooltips interactive test that checks that the getters are doing the right thing is now part of the gtk testsuite, so we ensure we don't regress in behaviour.
60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
/* tooltips.c: Unit test for GtkWidget tooltip accessors
|
|
*
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
* Copyright 2020 GNOME Foundation
|
|
*/
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
static void
|
|
test_tooltips_widget_accessors (void)
|
|
{
|
|
GtkWidget *w;
|
|
const char *text, *markup;
|
|
|
|
g_test_message ("A button using tooltip-markup");
|
|
w = gtk_check_button_new_with_label ("This one uses the tooltip-markup property");
|
|
g_object_ref_sink (w);
|
|
gtk_widget_set_tooltip_text (w, "Hello, I am a static tooltip.");
|
|
|
|
text = gtk_widget_get_tooltip_text (w);
|
|
markup = gtk_widget_get_tooltip_markup (w);
|
|
g_assert_cmpstr (text, ==, "Hello, I am a static tooltip.");
|
|
g_assert_cmpstr (markup, ==, "Hello, I am a static tooltip.");
|
|
g_object_unref (w);
|
|
|
|
g_test_message ("A label using tooltip-text");
|
|
w = gtk_label_new ("I am just a label");
|
|
g_object_ref_sink (w);
|
|
gtk_widget_set_tooltip_text (w, "Label & and tooltip");
|
|
|
|
text = gtk_widget_get_tooltip_text (w);
|
|
markup = gtk_widget_get_tooltip_markup (w);
|
|
g_assert_cmpstr (text, ==, "Label & and tooltip");
|
|
g_assert_cmpstr (markup, ==, "Label & and tooltip");
|
|
g_object_unref (w);
|
|
|
|
g_test_message ("A label using tooltip-markup");
|
|
w = gtk_label_new ("I am a selectable label");
|
|
g_object_ref_sink (w);
|
|
gtk_label_set_selectable (GTK_LABEL (w), TRUE);
|
|
gtk_widget_set_tooltip_markup (w, "<b>Another</b> Label tooltip");
|
|
|
|
text = gtk_widget_get_tooltip_text (w);
|
|
markup = gtk_widget_get_tooltip_markup (w);
|
|
g_assert_cmpstr (text, ==, "Another Label tooltip");
|
|
g_assert_cmpstr (markup, ==,"<b>Another</b> Label tooltip");
|
|
g_object_unref (w);
|
|
}
|
|
|
|
int
|
|
main (int argc,
|
|
char *argv[])
|
|
{
|
|
gtk_test_init (&argc, &argv);
|
|
|
|
g_test_add_func ("/tooltips/widget-accessors", test_tooltips_widget_accessors);
|
|
|
|
return g_test_run ();
|
|
}
|