+ GtkTreeItem *p = (GtkTreeItem *)item;
+ GtkWidget *parent = GTK_WIDGET(p)->parent;
+
+ if (!GTK_IS_TREE(parent))
+ return NULL;
+
+ if (g_list_index(GTK_TREE(parent)->children, p) == -1)
+ return NULL;
+
+ return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, p))->data);
+}
+
+static void gtk_treectrl_first_visible_callback(GtkWidget *widget, gpointer data) {
+ GtkTreeItem *p = (*((GtkTreeItem **)data));
+
+ GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
+
+ if (tree->children != NULL) {
+ guint len = g_list_length(tree->children);
+ for (guint i=0; i<len; i++) {
+ if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->children, i)->data)))) {
+ p = GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->children, i)->data);
+ return;
+ }
+ }
+ }
+
+ if (GTK_IS_CONTAINER(widget))
+ gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_first_visible_callback, data);