GtkTooltip *tooltip,
gpointer data)
{
- GdkColor color = { 0, 0, 65535 };
+ GdkRGBA color = { 0, 0, 1, 1 };
GtkWindow *window = gtk_widget_get_tooltip_window (widget);
- gtk_widget_modify_bg (GTK_WIDGET (window), GTK_STATE_NORMAL, &color);
+ gtk_widget_override_background_color (GTK_WIDGET (window), 0, &color);
return TRUE;
}
GtkTextTag *tag = data;
GtkTextIter iter;
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
if (keyboard_tip)
{
gint offset;
- g_object_get (text_view->buffer, "cursor-position", &offset, NULL);
- gtk_text_buffer_get_iter_at_offset (text_view->buffer, &iter, offset);
+ g_object_get (buffer, "cursor-position", &offset, NULL);
+ gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
}
else
{
}
if (gtk_text_iter_has_tag (&iter, tag))
- gtk_tooltip_set_markup (tooltip, "Tooltip on text tag");
+ gtk_tooltip_set_text (tooltip, "Tooltip on text tag");
else
return FALSE;
char buffer[512];
- if (keyboard_tip)
- {
- /* Keyboard mode */
- gtk_tree_view_get_cursor (tree_view, &path, NULL);
-
- if (!path)
- return FALSE;
- }
- else
- {
- /* Mouse mode */
- if (!gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, NULL, NULL, NULL))
- return FALSE;
- }
+ if (!gtk_tree_view_get_tooltip_context (tree_view, &x, &y,
+ keyboard_tip,
+ &model, &path, &iter))
+ return FALSE;
- gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, 0, &tmp, -1);
pathstring = gtk_tree_path_to_string (path);
g_snprintf (buffer, 511, "<b>Path %s:</b> %s", pathstring, tmp);
gtk_tooltip_set_markup (tooltip, buffer);
+ gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
+
gtk_tree_path_free (path);
g_free (pathstring);
g_free (tmp);
}
static gboolean
-drawing_area_expose (GtkWidget *drawing_area,
- GdkEventExpose *event,
- gpointer data)
+drawing_area_draw (GtkWidget *drawing_area,
+ cairo_t *cr,
+ gpointer data)
{
gint i;
- cairo_t *cr;
-
- gdk_window_get_pointer (drawing_area->window, NULL, NULL, NULL);
- cr = gdk_cairo_create (drawing_area->window);
-
- cairo_rectangle (cr, 0, 0,
- drawing_area->allocation.width,
- drawing_area->allocation.height);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
- cairo_fill (cr);
+ cairo_paint (cr);
for (i = 0; i < G_N_ELEMENTS (rectangles); i++)
{
cairo_fill (cr);
}
- cairo_destroy (cr);
-
return FALSE;
}
+static gboolean
+query_tooltip_label_cb (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_tip,
+ GtkTooltip *tooltip,
+ gpointer data)
+{
+ GtkWidget *custom = data;
+
+ gtk_tooltip_set_custom (tooltip, custom);
+
+ return TRUE;
+}
+
int
main (int argc, char *argv[])
{
GtkWidget *box;
GtkWidget *drawing_area;
GtkWidget *button;
+ GtkWidget *label;
GtkWidget *tooltip_window;
GtkWidget *tooltip_button;
GtkTextIter iter;
GtkTextTag *tag;
+ gchar *text, *markup;
+
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete_event",
G_CALLBACK (gtk_main_quit), NULL);
- box = gtk_vbox_new (FALSE, 3);
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
gtk_container_add (GTK_CONTAINER (window), box);
/* A check button using the tooltip-markup property */
button = gtk_check_button_new_with_label ("This one uses the tooltip-markup property");
- g_object_set (button, "tooltip-markup", "Hello, I am a static tooltip.", NULL);
+ gtk_widget_set_tooltip_text (button, "Hello, I am a static tooltip.");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ text = gtk_widget_get_tooltip_text (button);
+ markup = gtk_widget_get_tooltip_markup (button);
+ g_assert (g_str_equal ("Hello, I am a static tooltip.", text));
+ g_assert (g_str_equal ("Hello, I am a static tooltip.", markup));
+ g_free (text); g_free (markup);
+
/* 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);
/* A label */
button = gtk_label_new ("I am just a label");
gtk_label_set_selectable (GTK_LABEL (button), FALSE);
- g_object_set (button, "tooltip-markup", "Label tooltip", NULL);
+ gtk_widget_set_tooltip_text (button, "Label & and tooltip");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ text = gtk_widget_get_tooltip_text (button);
+ markup = gtk_widget_get_tooltip_markup (button);
+ g_assert (g_str_equal ("Label & and tooltip", text));
+ g_assert (g_str_equal ("Label & and tooltip", markup));
+ g_free (text); g_free (markup);
+
/* A selectable label */
button = gtk_label_new ("I am a selectable label");
gtk_label_set_selectable (GTK_LABEL (button), TRUE);
- g_object_set (button, "tooltip-markup", "Another Label tooltip", NULL);
+ gtk_widget_set_tooltip_markup (button, "<b>Another</b> Label tooltip");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ text = gtk_widget_get_tooltip_text (button);
+ markup = gtk_widget_get_tooltip_markup (button);
+ g_assert (g_str_equal ("Another Label tooltip", text));
+ g_assert (g_str_equal ("<b>Another</b> Label tooltip", markup));
+ g_free (text); g_free (markup);
+
/* Another one, with a custom tooltip window */
button = gtk_check_button_new_with_label ("This one has a custom tooltip window!");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
/* An insensitive button */
button = gtk_button_new_with_label ("This one is insensitive");
gtk_widget_set_sensitive (button, FALSE);
- g_object_set (button, "tooltip-markup", "Insensitive!", NULL);
+ g_object_set (button, "tooltip-text", "Insensitive!", NULL);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
/* Testcases from Kris without a tree view don't exist. */
/* 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);
- g_object_set (column->button, "tooltip-markup", "Header", NULL);
+ g_object_set (gtk_tree_view_column_get_button (column), "tooltip-text", "Header", NULL);
gtk_box_pack_start (GTK_BOX (box), tree_view, FALSE, FALSE, 2);
drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, 320, 240);
g_object_set (drawing_area, "has-tooltip", TRUE, NULL);
- g_signal_connect (drawing_area, "expose_event",
- G_CALLBACK (drawing_area_expose), NULL);
+ g_signal_connect (drawing_area, "draw",
+ G_CALLBACK (drawing_area_draw), NULL);
g_signal_connect (drawing_area, "query-tooltip",
G_CALLBACK (query_tooltip_drawing_area_cb), NULL);
gtk_box_pack_start (GTK_BOX (box), drawing_area, FALSE, FALSE, 2);
+ button = gtk_label_new ("Custom tooltip I");
+ label = gtk_label_new ("See, custom");
+ g_object_ref_sink (label);
+ g_object_set (button, "has-tooltip", TRUE, NULL);
+ g_signal_connect (button, "query-tooltip",
+ G_CALLBACK (query_tooltip_label_cb), label);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
+
+ button = gtk_label_new ("Custom tooltip II");
+ label = gtk_label_new ("See, custom, too");
+ g_object_ref_sink (label);
+ g_object_set (button, "has-tooltip", TRUE, NULL);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
+ g_signal_connect (button, "query-tooltip",
+ G_CALLBACK (query_tooltip_label_cb), label);
+
/* Done! */
gtk_widget_show_all (window);