2020-09-12 16:01:04 +00:00
|
|
|
/* testtooltips.c: Test application for GTK >= 2.12 tooltips code
|
2007-02-06 10:25:21 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2007 Imendio AB
|
|
|
|
* Contact: Kristian Rietveld <kris@imendio.com>
|
|
|
|
*
|
|
|
|
* This work is provided "as is"; redistribution and modification
|
|
|
|
* in whole or in part, in any medium, physical or electronic is
|
|
|
|
* permitted without restriction.
|
|
|
|
*
|
|
|
|
* This work is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* In no event shall the authors or contributors be liable for any
|
|
|
|
* direct, indirect, incidental, special, exemplary, or consequential
|
|
|
|
* damages (including, but not limited to, procurement of substitute
|
|
|
|
* goods or services; loss of use, data, or profits; or business
|
|
|
|
* interruption) however caused and on any theory of liability, whether
|
|
|
|
* in contract, strict liability, or tort (including negligence or
|
|
|
|
* otherwise) arising in any way out of the use of this software, even
|
|
|
|
* if advised of the possibility of such damage.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2017-05-24 08:24:13 +00:00
|
|
|
typedef struct _MyTooltip MyTooltip;
|
|
|
|
typedef struct _MyTooltipClass MyTooltipClass;
|
|
|
|
|
|
|
|
|
|
|
|
struct _MyTooltip
|
|
|
|
{
|
2020-05-04 00:20:08 +00:00
|
|
|
GtkWidget parent_instance;
|
2017-05-24 08:24:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MyTooltipClass
|
|
|
|
{
|
2020-05-04 00:20:08 +00:00
|
|
|
GtkWidgetClass parent_class;
|
2017-05-24 08:24:13 +00:00
|
|
|
};
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static GType my_tooltip_get_type (void);
|
2020-05-04 00:20:08 +00:00
|
|
|
G_DEFINE_TYPE (MyTooltip, my_tooltip, GTK_TYPE_WIDGET)
|
2017-05-24 08:24:13 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
my_tooltip_init (MyTooltip *tt)
|
|
|
|
{
|
|
|
|
GtkWidget *label = gtk_label_new ("Some text in a tooltip");
|
|
|
|
|
2020-05-04 00:20:08 +00:00
|
|
|
gtk_widget_set_parent (label, GTK_WIDGET (tt));
|
2017-05-24 08:24:13 +00:00
|
|
|
|
2020-04-10 16:08:16 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (tt), "background");
|
2017-05-24 08:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
my_tooltip_class_init (MyTooltipClass *tt_class)
|
|
|
|
{
|
2020-05-04 00:20:08 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (GTK_WIDGET_CLASS (tt_class), GTK_TYPE_BIN_LAYOUT);
|
2017-05-24 08:24:13 +00:00
|
|
|
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (tt_class), "tooltip");
|
|
|
|
}
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
static gboolean
|
|
|
|
query_tooltip_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
2007-02-06 10:25:21 +00:00
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gtk_tooltip_set_markup (tooltip, gtk_button_get_label (GTK_BUTTON (widget)));
|
2017-01-20 01:02:44 +00:00
|
|
|
gtk_tooltip_set_icon_from_icon_name (tooltip, "edit-delete");
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
query_tooltip_text_view_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
2007-02-06 10:25:21 +00:00
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkTextTag *tag = data;
|
|
|
|
GtkTextIter iter;
|
|
|
|
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
|
2010-07-11 09:55:44 +00:00
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2007-02-16 20:10:48 +00:00
|
|
|
if (keyboard_tip)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int offset;
|
2007-02-16 20:10:48 +00:00
|
|
|
|
2010-07-11 09:55:44 +00:00
|
|
|
g_object_get (buffer, "cursor-position", &offset, NULL);
|
|
|
|
gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
|
2007-02-16 20:10:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int bx, by, trailing;
|
2007-02-16 20:10:48 +00:00
|
|
|
|
|
|
|
gtk_text_view_window_to_buffer_coords (text_view, GTK_TEXT_WINDOW_TEXT,
|
|
|
|
x, y, &bx, &by);
|
|
|
|
gtk_text_view_get_iter_at_position (text_view, &iter, &trailing, bx, by);
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
if (gtk_text_iter_has_tag (&iter, tag))
|
2007-06-15 18:24:55 +00:00
|
|
|
gtk_tooltip_set_text (tooltip, "Tooltip on text tag");
|
2007-02-06 10:25:21 +00:00
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
query_tooltip_tree_view_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
2007-02-06 10:25:21 +00:00
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
|
|
|
GtkTreePath *path = NULL;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *tmp;
|
|
|
|
char *pathstring;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
char buffer[512];
|
|
|
|
|
2007-07-19 13:21:09 +00:00
|
|
|
if (!gtk_tree_view_get_tooltip_context (tree_view, &x, &y,
|
|
|
|
keyboard_tip,
|
|
|
|
&model, &path, &iter))
|
|
|
|
return FALSE;
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
gtk_tree_model_get (model, &iter, 0, &tmp, -1);
|
|
|
|
pathstring = gtk_tree_path_to_string (path);
|
|
|
|
|
2007-02-06 13:13:19 +00:00
|
|
|
g_snprintf (buffer, 511, "<b>Path %s:</b> %s", pathstring, tmp);
|
2007-02-06 10:25:21 +00:00
|
|
|
gtk_tooltip_set_markup (tooltip, buffer);
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
g_free (pathstring);
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
|
|
|
create_model (void)
|
|
|
|
{
|
|
|
|
GtkTreeStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
store = gtk_tree_store_new (1, G_TYPE_STRING);
|
|
|
|
|
|
|
|
/* A tree store with some random words ... */
|
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
|
|
|
|
0, "File Manager", -1);
|
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
|
|
|
|
0, "Gossip", -1);
|
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
|
|
|
|
0, "System Settings", -1);
|
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
|
|
|
|
0, "The GIMP", -1);
|
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
|
|
|
|
0, "Terminal", -1);
|
|
|
|
gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
|
|
|
|
0, "Word Processor", -1);
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL (store);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selection_changed_cb (GtkTreeSelection *selection,
|
|
|
|
GtkWidget *tree_view)
|
|
|
|
{
|
|
|
|
gtk_widget_trigger_tooltip_query (tree_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct Rectangle
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
2020-07-24 20:25:56 +00:00
|
|
|
float r;
|
|
|
|
float g;
|
|
|
|
float b;
|
2007-02-06 10:25:21 +00:00
|
|
|
const char *tooltip;
|
|
|
|
}
|
|
|
|
rectangles[] =
|
|
|
|
{
|
|
|
|
{ 10, 10, 0.0, 0.0, 0.9, "Blue box!" },
|
|
|
|
{ 200, 170, 1.0, 0.0, 0.0, "Red thing" },
|
|
|
|
{ 100, 50, 0.8, 0.8, 0.0, "Yellow thing" }
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
query_tooltip_drawing_area_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
2007-02-06 10:25:21 +00:00
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
if (keyboard_tip)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (rectangles); i++)
|
|
|
|
{
|
|
|
|
struct Rectangle *r = &rectangles[i];
|
|
|
|
|
|
|
|
if (r->x < x && x < r->x + 50
|
|
|
|
&& r->y < y && y < r->y + 50)
|
|
|
|
{
|
|
|
|
gtk_tooltip_set_markup (tooltip, r->tooltip);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-18 06:22:02 +00:00
|
|
|
static void
|
|
|
|
drawing_area_draw (GtkDrawingArea *drawing_area,
|
|
|
|
cairo_t *cr,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
gpointer data)
|
2007-02-06 10:25:21 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
|
2010-09-08 22:33:57 +00:00
|
|
|
cairo_paint (cr);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (rectangles); i++)
|
|
|
|
{
|
|
|
|
struct Rectangle *r = &rectangles[i];
|
|
|
|
|
|
|
|
cairo_rectangle (cr, r->x, r->y, 50, 50);
|
|
|
|
cairo_set_source_rgb (cr, r->r, r->g, r->b);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
cairo_rectangle (cr, r->x, r->y, 50, 50);
|
|
|
|
cairo_set_source_rgba (cr, r->r, r->g, r->b, 0.5);
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-24 03:50:49 +00:00
|
|
|
static gboolean
|
|
|
|
query_tooltip_label_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
2007-07-24 03:50:49 +00:00
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *custom = data;
|
|
|
|
|
|
|
|
gtk_tooltip_set_custom (tooltip, custom);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *drawing_area;
|
|
|
|
GtkWidget *button;
|
2017-05-24 08:24:13 +00:00
|
|
|
GtkWidget *tooltip;
|
2019-12-29 04:16:57 +00:00
|
|
|
GtkWidget *popover;
|
|
|
|
GtkWidget *box2;
|
|
|
|
GtkWidget *custom;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
GtkWidget *tree_view;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
|
|
|
|
GtkWidget *text_view;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter iter;
|
|
|
|
GtkTextTag *tag;
|
|
|
|
|
2020-04-22 18:32:17 +00:00
|
|
|
const char *text, *markup;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2007-06-15 18:25:11 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2007-02-06 10:25:21 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Tooltips test");
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2017-05-24 08:24:13 +00:00
|
|
|
tooltip = g_object_new (my_tooltip_get_type (), NULL);
|
|
|
|
gtk_widget_set_margin_top (tooltip, 20);
|
|
|
|
gtk_widget_set_margin_bottom (tooltip, 20);
|
|
|
|
gtk_widget_set_halign (tooltip, GTK_ALIGN_CENTER);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), tooltip);
|
2017-05-24 08:24:13 +00:00
|
|
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
/* A check button using the tooltip-markup property */
|
|
|
|
button = gtk_check_button_new_with_label ("This one uses the tooltip-markup property");
|
2007-06-15 18:24:55 +00:00
|
|
|
gtk_widget_set_tooltip_text (button, "Hello, I am a static tooltip.");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2007-06-15 18:25:11 +00:00
|
|
|
text = gtk_widget_get_tooltip_text (button);
|
|
|
|
markup = gtk_widget_get_tooltip_markup (button);
|
2020-04-22 18:32:17 +00:00
|
|
|
g_assert_true (g_str_equal ("Hello, I am a static tooltip.", text));
|
|
|
|
g_assert_true (g_str_equal ("Hello, I am a static tooltip.", markup));
|
2007-06-15 18:25:11 +00:00
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
/* A check button using the query-tooltip signal */
|
|
|
|
button = gtk_check_button_new_with_label ("I use the query-tooltip signal");
|
|
|
|
g_object_set (button, "has-tooltip", TRUE, NULL);
|
|
|
|
g_signal_connect (button, "query-tooltip",
|
|
|
|
G_CALLBACK (query_tooltip_cb), NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
/* A label */
|
|
|
|
button = gtk_label_new ("I am just a label");
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (button), FALSE);
|
2007-06-15 18:24:55 +00:00
|
|
|
gtk_widget_set_tooltip_text (button, "Label & and tooltip");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2007-06-15 18:25:11 +00:00
|
|
|
text = gtk_widget_get_tooltip_text (button);
|
|
|
|
markup = gtk_widget_get_tooltip_markup (button);
|
2020-04-22 18:32:17 +00:00
|
|
|
g_assert_true (g_str_equal ("Label & and tooltip", text));
|
|
|
|
g_assert_true (g_str_equal ("Label & and tooltip", markup));
|
2007-06-15 18:25:11 +00:00
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
/* A selectable label */
|
|
|
|
button = gtk_label_new ("I am a selectable label");
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (button), TRUE);
|
2007-06-15 18:24:55 +00:00
|
|
|
gtk_widget_set_tooltip_markup (button, "<b>Another</b> Label tooltip");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2007-06-15 18:25:11 +00:00
|
|
|
text = gtk_widget_get_tooltip_text (button);
|
|
|
|
markup = gtk_widget_get_tooltip_markup (button);
|
2020-04-22 18:32:17 +00:00
|
|
|
g_assert_true (g_str_equal ("Another Label tooltip", text));
|
|
|
|
g_assert_true (g_str_equal ("<b>Another</b> Label tooltip", markup));
|
2007-06-15 18:25:11 +00:00
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
/* An insensitive button */
|
|
|
|
button = gtk_button_new_with_label ("This one is insensitive");
|
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
2007-06-15 18:24:55 +00:00
|
|
|
g_object_set (button, "tooltip-text", "Insensitive!", NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
/* Testcases from Kris without a tree view don't exist. */
|
|
|
|
tree_view = gtk_tree_view_new_with_model (create_model ());
|
|
|
|
gtk_widget_set_size_request (tree_view, 200, 240);
|
|
|
|
|
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
|
|
|
|
0, "Test",
|
|
|
|
gtk_cell_renderer_text_new (),
|
|
|
|
"text", 0,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_set (tree_view, "has-tooltip", TRUE, NULL);
|
|
|
|
g_signal_connect (tree_view, "query-tooltip",
|
|
|
|
G_CALLBACK (query_tooltip_tree_view_cb), NULL);
|
|
|
|
g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
|
|
|
"changed", G_CALLBACK (selection_changed_cb), tree_view);
|
|
|
|
|
|
|
|
/* Set a tooltip on the column */
|
|
|
|
column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), 0);
|
|
|
|
gtk_tree_view_column_set_clickable (column, TRUE);
|
2010-11-30 05:29:45 +00:00
|
|
|
g_object_set (gtk_tree_view_column_get_button (column), "tooltip-text", "Header", NULL);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), tree_view);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
/* And a text view for Matthias */
|
|
|
|
buffer = gtk_text_buffer_new (NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &iter);
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, "Hello, the text ", -1);
|
|
|
|
|
|
|
|
tag = gtk_text_buffer_create_tag (buffer, "bold", NULL);
|
|
|
|
g_object_set (tag, "weight", PANGO_WEIGHT_BOLD, NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &iter);
|
|
|
|
gtk_text_buffer_insert_with_tags (buffer, &iter, "in bold", -1, tag, NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &iter);
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, " has a tooltip!", -1);
|
|
|
|
|
|
|
|
text_view = gtk_text_view_new_with_buffer (buffer);
|
|
|
|
gtk_widget_set_size_request (text_view, 200, 50);
|
|
|
|
|
|
|
|
g_object_set (text_view, "has-tooltip", TRUE, NULL);
|
|
|
|
g_signal_connect (text_view, "query-tooltip",
|
|
|
|
G_CALLBACK (query_tooltip_text_view_cb), tag);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), text_view);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
/* Drawing area */
|
|
|
|
drawing_area = gtk_drawing_area_new ();
|
2016-11-18 06:22:02 +00:00
|
|
|
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (drawing_area), 320);
|
|
|
|
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (drawing_area), 240);
|
|
|
|
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area),
|
|
|
|
drawing_area_draw, NULL, NULL);
|
2007-02-06 10:25:21 +00:00
|
|
|
g_object_set (drawing_area, "has-tooltip", TRUE, NULL);
|
|
|
|
g_signal_connect (drawing_area, "query-tooltip",
|
|
|
|
G_CALLBACK (query_tooltip_drawing_area_cb), NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), drawing_area);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2019-12-29 04:16:57 +00:00
|
|
|
button = gtk_menu_button_new ();
|
|
|
|
gtk_widget_set_halign (button, GTK_ALIGN_CENTER);
|
|
|
|
gtk_menu_button_set_label (GTK_MENU_BUTTON (button), "Custom tooltip I");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2020-02-24 12:21:46 +00:00
|
|
|
popover = gtk_popover_new ();
|
2019-12-29 04:16:57 +00:00
|
|
|
gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), popover);
|
|
|
|
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-05-02 02:22:20 +00:00
|
|
|
gtk_popover_set_child (GTK_POPOVER (popover), box2);
|
2019-12-29 04:16:57 +00:00
|
|
|
|
|
|
|
button = gtk_label_new ("Hidden here");
|
|
|
|
custom = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (custom), gtk_label_new ("See, custom"));
|
|
|
|
gtk_box_append (GTK_BOX (custom), g_object_new (GTK_TYPE_SPINNER, "spinning", TRUE, NULL));
|
2019-12-29 04:16:57 +00:00
|
|
|
g_object_ref_sink (custom);
|
2007-07-24 03:50:49 +00:00
|
|
|
g_object_set (button, "has-tooltip", TRUE, NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box2), button);
|
2007-07-24 03:50:49 +00:00
|
|
|
g_signal_connect (button, "query-tooltip",
|
2019-12-29 04:16:57 +00:00
|
|
|
G_CALLBACK (query_tooltip_label_cb), custom);
|
2007-07-24 03:50:49 +00:00
|
|
|
|
|
|
|
button = gtk_label_new ("Custom tooltip II");
|
2019-12-29 04:16:57 +00:00
|
|
|
custom = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (custom), gtk_label_new ("See, custom too"));
|
|
|
|
gtk_box_append (GTK_BOX (custom), g_object_new (GTK_TYPE_SPINNER, "spinning", TRUE, NULL));
|
2019-12-29 04:16:57 +00:00
|
|
|
g_object_ref_sink (custom);
|
2007-07-24 03:50:49 +00:00
|
|
|
g_object_set (button, "has-tooltip", TRUE, NULL);
|
|
|
|
g_signal_connect (button, "query-tooltip",
|
2019-12-29 04:16:57 +00:00
|
|
|
G_CALLBACK (query_tooltip_label_cb), custom);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2007-07-24 03:50:49 +00:00
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
/* Done! */
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|