Re: GtkTreeView Path Ambiguity (Header vs First Row )
- From: Tadej Borovšak <tadeboro gmail com>
- To: Paul Stuart <Paul_Stuart seektech com>
- Cc: "gtk-list gnome org" <gtk-list gnome org>
- Subject: Re: GtkTreeView Path Ambiguity (Header vs First Row )
- Date: Thu, 10 Jun 2010 23:11:36 +0200
Hello.
> The menu featuring a treeview needs to let the user select any column in the header so they can sort the rows but when they are moving through rows, I only want them to be able to focus the two leftmost columns (there are five total).
>
> So, I need to be able to test on key press if they are past the second column in a row, and prevent them from moving farther right, but if they are in the header, they can move all the way.
>
> I was trying to accomplish this by testing to see if focus is in the header or on a row, but I've been stymied at every turn.
You can test whether tree view has focus. If gtk_widget_has_focus()
returns TRUE, user is moving inside tree view area; if returned value
is FALSE, focus is somewhere else.
Have a look at this minimalistic sample code and play a bit with it.
Maybe method similar to this can solve your troubles?
----------
#include <gtk/gtk.h>
static gboolean
cb_timeout (GtkWidget *tree)
{
if (gtk_widget_has_focus (tree))
g_print ("Focus in\n");
else
g_print ("Focus out\n");
return TRUE;
}
int
main (int argc,
char **argv)
{
GtkWidget *window,
*swindow,
*tree;
GtkListStore *store;
gint i,
j;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
swindow = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (window), swindow);
store = gtk_list_store_new (5, G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
for (i = 1; i < 10; i++)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
for (j = 0; j < 5; j++)
{
gchar text[] = "( , )";
text[1] = '0' + j;
text[3] = '0' + i;
gtk_list_store_set (store, &iter, j, text, -1);
}
}
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
gtk_container_add (GTK_CONTAINER (swindow), tree);
for (i = 0; i < 5; i++)
{
gchar text[] = "Column ";
GtkCellRenderer *cell = gtk_cell_renderer_text_new();
GtkTreeViewColumn *col;
text[7] = '0' + i;
cell = gtk_cell_renderer_text_new();
g_object_set (cell, "editable", TRUE, NULL);
col = gtk_tree_view_column_new_with_attributes (text, cell,
"text", i,
NULL);
gtk_tree_view_column_set_clickable (col, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), col);
}
gtk_widget_show_all (window);
g_timeout_add (330, (GSourceFunc)cb_timeout, tree);
gtk_main();
return 0;
}
------------
Tadej
--
Tadej Borovšak
tadeboro.blogspot.com
tadeboro gmail com
tadej borovsak gmail com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]