return ret;
}
+static GtkTreeIter
+*solipa_gtktreemodel_get_iter_child (GtkTreeIter *iter, GPtrArray *models)
+{
+ GtkTreeModel *model;
+ GtkTreeIter *iter_parent;
+ GtkTreeIter *iter_child;
+
+ guint n;
+
+ iter_parent = iter;
+ iter_child = (GtkTreeIter *)g_malloc0 (sizeof (GtkTreeIter));
+
+ for (n = 0; n < (models->len - 1); n++)
+ {
+ model = (GtkTreeModel *)g_ptr_array_index (models, n);
+ if (GTK_IS_TREE_MODEL_SORT (model))
+ {
+ gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (model),
+ iter_child, iter_parent);
+ iter_parent = iter_child;
+ iter_child = (GtkTreeIter *)g_malloc0 (sizeof (GtkTreeIter));
+ }
+ else if (GTK_IS_TREE_MODEL_FILTER (model))
+ {
+ gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
+ iter_child, iter_parent);
+ iter_parent = iter_child;
+ iter_child = (GtkTreeIter *)g_malloc0 (sizeof (GtkTreeIter));
+ }
+ }
+ g_free (iter_child);
+
+ return iter_parent;
+}
+
static void
solipa_gtktreemodel_copy_iter (GtkTreeModel *ret,
GtkTreeModel *model,
- GtkTreeModel *model_child,
+ GPtrArray *models,
gboolean is_list_store,
guint cols,
GtkTreeIter *iter,
GtkTreeIter *iter_parent)
{
GtkTreeIter iter_new;
- GtkTreeIter iter_child;
+ GtkTreeIter *iter_child;
guint col;
gtk_tree_store_append (GTK_TREE_STORE (ret), &iter_new, iter_parent);
}
+ iter_child = solipa_gtktreemodel_get_iter_child (iter, models);
for (col = 0; col < cols; col++)
{
GValue gval = {0};
- if (model_child != NULL)
- {
- gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &iter_child, iter);
- gtk_tree_model_get_value (model_child, &iter_child, col, &gval);
- }
- else
- {
- gtk_tree_model_get_value (model, iter, col, &gval);
- }
+ gtk_tree_model_get_value ((GtkTreeModel *)g_ptr_array_index (models, models->len - 1),
+ iter_child,
+ col, &gval);
if (is_list_store)
{
if (!is_list_store)
{
/* is_tree_store */
- if (gtk_tree_model_iter_children (model, &iter_child, iter))
+ GtkTreeIter iter_children;
+
+ if (gtk_tree_model_iter_children (model, &iter_children, iter_child))
{
- solipa_gtktreemodel_copy_iter (ret, model, model_child, is_list_store, cols, &iter_child, &iter_new);
+ solipa_gtktreemodel_copy_iter (ret, model, models, is_list_store, cols, &iter_children, &iter_new);
}
}
} while (gtk_tree_model_iter_next (model, iter));
}
+static void
+solipa_gtktreemodel_get_models_chain (GtkTreeModel *model, GPtrArray *models)
+{
+ GtkTreeModel *my_model;
+
+ if (GTK_IS_TREE_MODEL_SORT (model))
+ {
+ my_model = (gpointer)gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model));
+ g_ptr_array_add (models, my_model);
+
+ solipa_gtktreemodel_get_models_chain (my_model, models);
+ }
+ else if (GTK_IS_TREE_MODEL_FILTER (model))
+ {
+ my_model = (gpointer)gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
+ g_ptr_array_add (models, my_model);
+
+ solipa_gtktreemodel_get_models_chain (my_model, models);
+ }
+}
+
GtkTreeModel
*solipa_gtktreemodel_copy (GtkTreeModel *model, gboolean only_schema)
{
GType *gtypes;
guint cols;
- guint col;
- GtkTreeModel *model_child;
+ GPtrArray *models; /* GtkTreeModel */
GtkTreeIter iter;
ret = NULL;
gtypes = solipa_gtktreemodel_get_gtypes (model, &cols);
- if (gtypes != NULL)
+ if (gtypes != NULL && cols > 0)
{
- if (GTK_IS_TREE_MODEL_FILTER (model))
- {
- model_child = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
- }
- else
+ models = g_ptr_array_new ();
+ g_ptr_array_add (models, (gpointer)model);
+
+ if (GTK_IS_TREE_MODEL_SORT (model) ||
+ GTK_IS_TREE_MODEL_FILTER (model))
{
- model_child = NULL;
+ solipa_gtktreemodel_get_models_chain (model, models);
}
- if (GTK_IS_LIST_STORE (model)
- || (model_child != NULL && GTK_IS_LIST_STORE (model_child)))
+ if (GTK_IS_LIST_STORE ((GtkTreeModel *)g_ptr_array_index (models, models->len - 1)))
{
ret = GTK_TREE_MODEL (gtk_list_store_newv (cols, gtypes));
{
if (gtk_tree_model_get_iter_first (model, &iter))
{
- solipa_gtktreemodel_copy_iter (ret, model, model_child, TRUE, cols, &iter, NULL);
+ solipa_gtktreemodel_copy_iter (ret, model, models, TRUE, cols, &iter, NULL);
}
}
}
- else if (GTK_IS_TREE_STORE (model)
- || (model_child != NULL && GTK_IS_TREE_STORE (model_child)))
+ else if (GTK_IS_TREE_STORE ((GtkTreeModel *)g_ptr_array_index (models, models->len - 1)))
{
ret = GTK_TREE_MODEL (gtk_tree_store_newv (cols, gtypes));
{
if (gtk_tree_model_get_iter_first (model, &iter))
{
- solipa_gtktreemodel_copy_iter (ret, model, model_child, FALSE, cols, &iter, NULL);
+ solipa_gtktreemodel_copy_iter (ret, model, models, FALSE, cols, &iter, NULL);
}
}
}
{
g_warning ("GtkTreeModel type not expected.");
}
+
+ g_ptr_array_free (models, TRUE);
}
return ret;