Need help with gtk_tree_view_set_cursor
- From: "aullidolunar gmail com" <aullidolunar gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Need help with gtk_tree_view_set_cursor
- Date: Tue, 1 Apr 2014 13:53:23 -0700
Hi, I'm using GTK+2 (2.24) and I'm detecting a strange behavior
in gtk_tree_view_set_cursor.
This is my code:
// display 0-9 in the list
gint addItems(GtkListStore *model) {
gint items;
for (items = 0; items < 10; items++) {
GtkTreeIter iter;
gchar *item;
item = g_strdup_printf("%i", items);
gtk_list_store_append(model, &iter);
gtk_list_store_set(model, &iter, 0, item, -1);
g_free(item);
}
return items;
}
// grab the number of items
dat->totalItems = addItems(listStore);
// moveup function
void moveItemUP(MyData *dat) {
GtkTreePath* path;
gtk_tree_view_get_cursor(dat->tv, &path, NULL);
if (!gtk_tree_path_prev(path)) {
GtkTreeIter iter;
gtk_tree_path_free(path);
gtk_tree_model_iter_nth_child(dat->model, &iter, NULL, dat->totalItems-1);
path = gtk_tree_model_get_path(dat->model, &iter);
gtk_tree_view_set_cursor(dat->tv, path, NULL, FALSE);
}
gtk_tree_path_free(path);
}
// callback
gboolean window1_key_press_event_cb(GtkWidget *toplevel, GdkEventKey
*event, MyData *data) {
switch (event->keyval) {
case GDK_KEY_Up: {
moveItemUP(data);
break;
}
case GDK_KEY_Down: {
moveItemDown(data);
break;
}
case GDK_KEY_End: {
break;
}
}
return FALSE;
}
The strings "0" to "9" are displayed as expected on the treeview. The idea
is if I hit GDK_KEY_Up (since there's no upper level) should select the
last one; my function moveItemUP, does work in someway, because instead of
selecting the string "9", it selects the string "8".....any ideas...?
I'm attaching my sandbox project
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]