{
g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), 0);
- return GTK_TREE_MODEL_ITERS_PERSIST | GTK_TREE_MODEL_LIST_ONLY;
+ // GTK+ list store uses a linked list for storing the
+ // items and a pointer to a child is used as the member
+ // field of a GtkTreeIter. This means that the iter is
+ // valid in the GtkListStore as long as the child exists.
+ // We use the index of the row and since the index of a
+ // specific row will change if a row above is deleted,
+ // the iter does not persist
+ return /* GTK_TREE_MODEL_ITERS_PERSIST | */ GTK_TREE_MODEL_LIST_ONLY;
}
static gint
wxgtk_list_store_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
- GtkWxListStore *list_store = (GtkListStore *) tree_model;
g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), FALSE);
+ GtkWxListStore *list_store = (GtkListStore *) tree_model;
-#if 0
- g_return_val_if_fail (GTK_LIST_STORE (tree_model)->stamp == iter->stamp, FALSE);
+ g_return_val_if_fail (list_store->stamp == iter->stamp, FALSE);
- iter->user_data = G_SLIST (iter->user_data)->next;
-
- return (iter->user_data != NULL);
-#endif
+ int n = (int) iter->user_data;
+
+ if (n == -1)
+ return FALSE;
+
+ if (n >= (int) list_store->model->GetRowCount())
+ return FALSE;
+
+ iter->user_data = (gpointer) n++;
- return NULL;
+ return TRUE;
}
static gboolean
GtkTreeIter *iter,
GtkTreeIter *parent)
{
- /* this is a list, nodes have no children */
+ g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), FALSE);
+ GtkWxListStore *list_store = (GtkListStore *) tree_model;
+
+ // this is a list, nodes have no children
if (parent)
return FALSE;
- /* but if parent == NULL we return the list itself */
- if (GTK_WX_LIST_STORE (tree_model)->root)
- {
- iter->stamp = GTK_WX_LIST_STORE (tree_model)->stamp;
- iter->user_data = GTK_WX_LIST_STORE (tree_model)->root;
- return TRUE;
- }
- else
- {
- return FALSE;
- }
+ iter->stamp = list_store->stamp;
+ iter->user_data = (gpointer) -1;
+
+ return TRUE;
}
static gboolean
GtkTreeIter *iter)
{
g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), -1);
+ GtkWxListStore *list_store = (GtkListStore *) tree_model;
if (iter == NULL)
- return GTK_WX_LIST_STORE (tree_model)->model->GetLength();
+ return (gint) list_store->model->GetRowCount();
- g_return_val_if_fail (GTK_WX_LIST_STORE (tree_model)->stamp == iter->stamp, -1);
+ g_return_val_if_fail (list_store->stamp == iter->stamp, -1);
return 0;
}
GtkTreeIter *parent,
gint n)
{
-#if 0
- GSList *child;
-
- g_return_val_if_fail (GTK_IS_LIST_STORE (tree_model), FALSE);
-
- if (parent)
- return FALSE;
+ g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), FALSE);
+ GtkWxListStore *list_store = (GtkListStore *) tree_model;
+
+ if (parent)
+ return FALSE;
- child = g_slist_nth (G_SLIST (GTK_LIST_STORE (tree_model)->root), n);
+ if (n < 0)
+ return FALSE;
+
+ if (n >= (gint) list_store->model->GetRowCount())
+ return FALSE;
- if (child)
- {
- iter->stamp = GTK_LIST_STORE (tree_model)->stamp;
- iter->user_data = child;
- return TRUE;
- }
- else
-#endif
- return FALSE;
+ iter->stamp = list_store->stamp;
+ iter->user_data = (gpointer) n;
+
+ return TRUE;
}
static gboolean