Re: Tooltips for Gtk::TreeView rows
- From: Simon Fuhrmann <NightSlayer gmx de>
- To: Murray Cumming <murrayc murrayc com>
- Cc: gtkmm-list gnome org
- Subject: Re: Tooltips for Gtk::TreeView rows
- Date: Sat, 14 Jun 2008 18:41:22 +0200
> It sounds like it. It would need a simple test case in C though, to be
> filed as a bug.
Attached, but very dirty. Copied an example and modified it.
gcc treeview_get_path_at_pos.c `pkg-config --cflags --libs gtk+-2.0`
Simon
/*
* Compile with:
* gcc -o helloworld helloworld.c `pkg-config --cflags --libs gtk+-2.0`
*
*/
#include <gtk/gtk.h>
enum
{
COL_NAME = 0,
COL_AGE,
NUM_COLS
} ;
static GtkTreeModel *
create_and_fill_model (void)
{
GtkListStore *store;
GtkTreeIter iter;
store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_UINT);
/* Append a row and fill in some data */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_NAME, "Heinz El-Mann",
COL_AGE, 51,
-1);
/* append another row and fill in some data */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_NAME, "Jane Doe",
COL_AGE, 23,
-1);
/* ... and a third row */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_NAME, "Joe Bungop",
COL_AGE, 91,
-1);
return GTK_TREE_MODEL (store);
}
static GtkWidget *
create_view_and_model (void)
{
GtkCellRenderer *renderer;
GtkTreeModel *model;
GtkWidget *view;
view = gtk_tree_view_new ();
/* --- Column #1 --- */
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
-1,
"Name",
renderer,
"text", COL_NAME,
NULL);
/* --- Column #2 --- */
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
-1,
"Age",
renderer,
"text", COL_AGE,
NULL);
model = create_and_fill_model ();
gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
/* The tree view has acquired its own reference to the
* model, so we can drop ours. That way the model will
* be freed automatically when the tree view is destroyed */
g_object_unref (model);
return view;
}
gboolean
query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode,
GtkTooltip *tooltip, gpointer user_data)
{
GtkTreePath* path;
GtkTreePath* path2;
GtkTreeViewDropPosition pos;
GtkTreeViewColumn* col;
gint cx, cy;
gtk_tree_view_get_path_at_pos((GtkTreeView*)widget, x, y, &path,
&col, &cx, &cy);
gtk_tree_view_get_dest_row_at_pos((GtkTreeView*)widget, x, y, &path2, &pos);
printf("INFO: get_path_at_pos: %s -- get_dest_row_at_pos: %s\n",
(path == NULL ? "NULL" : gtk_tree_path_to_string(path)),
(path2 == NULL ? "NULL" : gtk_tree_path_to_string(path2)));
gtk_tooltip_set_text(tooltip, "Testing");
return TRUE;
}
int
main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *view;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete_event", gtk_main_quit, NULL); /* dirty */
view = create_view_and_model ();
/* TESTING CODE */
gtk_widget_set_has_tooltip(view, TRUE);
g_signal_connect (view, "query-tooltip", query_tooltip, NULL);
gtk_container_add (GTK_CONTAINER (window), view);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]