diff options
author | Kristian Rietveld <kris@imendio.com> | 2007-07-19 13:21:09 +0000 |
---|---|---|
committer | Kristian Rietveld <kristian@src.gnome.org> | 2007-07-19 13:21:09 +0000 |
commit | b1ec5f7556cf989f44331cde1db97ed5d4a2d2db (patch) | |
tree | 308d98eb4e3fb1355408501b6d00d1de5edb7127 /gtk/gtktreeview.c | |
parent | 6f52e073b34b109860aad957f2472f58e00d227d (diff) | |
download | gtk+-b1ec5f7556cf989f44331cde1db97ed5d4a2d2db.tar.gz |
add more convenience API.
2007-07-19 Kristian Rietveld <kris@imendio.com>
* gtk/gtk.symbols:
* gtk/gtktreeprivate.h:
* gtk/gtktreeview.[ch] (gtk_tree_view_get_tooltip_context),
(gtk_tree_view_[sg]et_tooltip_column): add more convenience API.
* tests/testtooltip.c (query_tooltip_tree_view_cb): use
gtk_tree_view_get_tooltip_context().
* demos/gtk-demo/demo.ui: add a tooltip column to the list store,
set tooltip-column on the tree view.
svn path=/trunk/; revision=18496
Diffstat (limited to 'gtk/gtktreeview.c')
-rw-r--r-- | gtk/gtktreeview.c | 189 |
1 files changed, 188 insertions, 1 deletions
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index e0591a4f48..dbf25fa2c8 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -143,7 +143,8 @@ enum { PROP_LEVEL_INDENTATION, PROP_RUBBER_BANDING, PROP_ENABLE_GRID_LINES, - PROP_ENABLE_TREE_LINES + PROP_ENABLE_TREE_LINES, + PROP_TOOLTIP_COLUMN }; /* object signals */ @@ -756,6 +757,16 @@ gtk_tree_view_class_init (GtkTreeViewClass *class) FALSE, GTK_PARAM_READWRITE)); + g_object_class_install_property (o_class, + PROP_TOOLTIP_COLUMN, + g_param_spec_int ("tooltip-column", + P_("Tooltip Column"), + P_("The column in the model containing the tooltip texts for the rows"), + -1, + G_MAXINT, + -1, + GTK_PARAM_READWRITE)); + /* Style properties */ #define _TREE_VIEW_EXPANDER_SIZE 12 #define _TREE_VIEW_VERTICAL_SEPARATOR 2 @@ -1349,6 +1360,8 @@ gtk_tree_view_init (GtkTreeView *tree_view) tree_view->priv->grid_lines = GTK_TREE_VIEW_GRID_LINES_NONE; tree_view->priv->tree_lines_enabled = FALSE; + + tree_view->priv->tooltip_column = -1; } @@ -1422,6 +1435,9 @@ gtk_tree_view_set_property (GObject *object, case PROP_ENABLE_TREE_LINES: gtk_tree_view_set_enable_tree_lines (tree_view, g_value_get_boolean (value)); break; + case PROP_TOOLTIP_COLUMN: + gtk_tree_view_set_tooltip_column (tree_view, g_value_get_int (value)); + break; default: break; } @@ -1493,6 +1509,9 @@ gtk_tree_view_get_property (GObject *object, case PROP_ENABLE_TREE_LINES: g_value_set_boolean (value, tree_view->priv->tree_lines_enabled); break; + case PROP_TOOLTIP_COLUMN: + g_value_set_boolean (value, tree_view->priv->tooltip_column); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -15279,5 +15298,173 @@ gtk_tree_view_set_tooltip_cell (GtkTreeView *tree_view, gtk_tooltip_set_tip_area (tooltip, &rect); } +/** + * gtk_tree_view_get_tooltip_contenxt: + * @tree_view: a #GtkTreeView + * @x: the x coordinate (relative to widget coordinates) + * @y: the y coordinate (relative to widget coordinates) + * @keyboard_tip: whether this is a keyboard tooltip or not + * @model: a pointer to receive a #GtkTreeModel or %NULL + * @path: a pointer to receive a #GtkTreePath or %NULL + * @iter: a pointer to receive a #GtkTreeIter or %NULL + * + * This function is supposed to be used in a GtkWidget::query-tooltip + * signal handler for #GtkTreeViews. The @x, @y and @keyboard_tip values + * which are received in the signal handler, should be passed to this + * function without modification. + * + * The return value indicates whether there is a tree view row at the given + * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard + * tooltips the row returned will be the cursor row. When %TRUE, then any of + * @model, @path and @iter which have been provided will be set to point to + * that row and the corresponding model. @x and @y will always be converted + * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE. + * + * Return value: whether or not the given tooltip context points to a row. + * + * Since: 2.12 + */ +gboolean +gtk_tree_view_get_tooltip_context (GtkTreeView *tree_view, + gint *x, + gint *y, + gboolean keyboard_tip, + GtkTreeModel **model, + GtkTreePath **path, + GtkTreeIter *iter) +{ + GtkTreePath *tmppath = NULL; + + g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), FALSE); + g_return_val_if_fail (x != NULL, FALSE); + g_return_val_if_fail (y != NULL, FALSE); + + if (keyboard_tip) + { + gtk_tree_view_get_cursor (tree_view, &tmppath, NULL); + + if (!tmppath) + return FALSE; + } + else + { + gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, *x, *y, + x, y); + + if (!gtk_tree_view_get_path_at_pos (tree_view, *x, *y, + &tmppath, NULL, NULL, NULL)) + return FALSE; + } + + if (model) + *model = gtk_tree_view_get_model (tree_view); + + if (iter) + gtk_tree_model_get_iter (gtk_tree_view_get_model (tree_view), + iter, tmppath); + + if (path) + *path = tmppath; + else + gtk_tree_path_free (tmppath); + + return TRUE; +} + +static gboolean +gtk_tree_view_set_tooltip_query_cb (GtkWidget *widget, + gint x, + gint y, + gboolean keyboard_tip, + GtkTooltip *tooltip, + gpointer data) +{ + gchar *str; + GtkTreeIter iter; + GtkTreePath *path; + GtkTreeModel *model; + GtkTreeView *tree_view = GTK_TREE_VIEW (widget); + + if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), + &x, &y, + keyboard_tip, + &model, &path, &iter)) + return FALSE; + + gtk_tree_model_get (model, &iter, tree_view->priv->tooltip_column, &str, -1); + + if (!str) + { + gtk_tree_path_free (path); + return FALSE; + } + + gtk_tooltip_set_markup (tooltip, str); + gtk_tree_view_set_tooltip_row (tree_view, tooltip, path); + + gtk_tree_path_free (path); + g_free (str); + + return TRUE; +} + +/** + * gtk_tree_view_set_tooltip_column: + * @tree_view: a #GtkTreeView + * @column: an integer, which is a valid column number for @tree_view's model + * + * If you only plan to have simple (text-only) tooltips on full rows, you + * can use this function to have #GtkTreeView handle these automatically + * for you. @column should be set to the column in @tree_view's model + * containing the tooltip texts, or %-1 to disable this feature. + * + * When enabled, GtkWidget::has-tooltip will be set to %TRUE and + * @tree_view will connect a query-tooltip signal handler. + * + * Since: 2.12 + */ +void +gtk_tree_view_set_tooltip_column (GtkTreeView *tree_view, + gint column) +{ + g_return_if_fail (GTK_IS_TREE_VIEW (tree_view)); + + if (column == -1) + { + g_signal_handlers_disconnect_by_func (tree_view, + gtk_tree_view_set_tooltip_query_cb, + NULL); + gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE); + } + else + { + g_signal_connect (tree_view, "query-tooltip", + G_CALLBACK (gtk_tree_view_set_tooltip_query_cb), NULL); + gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE); + } + + tree_view->priv->tooltip_column = column; +} + +/** + * gtk_tree_view_get_tooltip_column: + * @tree_view: a #GtkTreeView + * + * Returns the column of @tree_view's model which is being used for + * displaying tooltips on @tree_view's rows. + * + * Return value: a #gint with the tooltip column that is currently being + * used, or %-1 if this is disabled. + * + * Since 2.12 + */ +gint +gtk_tree_view_get_tooltip_column (GtkTreeView *tree_view) +{ + g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), 0); + + return tree_view->priv->tooltip_column; +} + #define __GTK_TREE_VIEW_C__ #include "gtkaliasdef.c" |