gtk2/gtk/gtktreemodelsort.c

1161 lines
32 KiB
C
Raw Normal View History

/* gtktreemodelsort.c
* Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* NOTE: There is a potential for confusion in this code as to whether an iter,
* path or value refers to the GtkTreeModelSort model, or the child model being
* sorted. As a convention, variables referencing the child model will have an
* s_ prefix before them (ie. s_iter, s_value, s_path);
*/
#include "gtktreemodelsort.h"
#include "gtksignal.h"
#include <string.h>
typedef struct _SortElt SortElt;
struct _SortElt
{
GtkTreeIter iter;
SortElt *parent;
GArray *children;
gint ref;
gint offset;
};
2000-11-22 05:16:37 +00:00
typedef struct _SortData SortData;
struct _SortData
{
GtkTreeModel *model;
gint sort_col;
GValueCompareFunc func;
};
#define get_array(e,t) ((GArray *)((e)->parent?(e)->parent->children:GTK_TREE_MODEL_SORT(t)->root))
2000-11-22 05:16:37 +00:00
static void gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort);
static void gtk_tree_model_sort_class_init (GtkTreeModelSortClass *tree_model_sort_class);
static void gtk_tree_model_sort_tree_model_init (GtkTreeModelIface *iface);
static void gtk_tree_model_sort_finalize (GObject *object);
static void gtk_tree_model_sort_changed (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
static void gtk_tree_model_sort_inserted (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
static void gtk_tree_model_sort_has_child_toggled (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
static void gtk_tree_model_sort_deleted (GtkTreeModel *model,
GtkTreePath *path,
gpointer data);
static gint gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model);
static GType gtk_tree_model_sort_get_column_type (GtkTreeModel *tree_model,
gint index);
static gboolean gtk_tree_model_sort_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path);
static GtkTreePath *gtk_tree_model_sort_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk_tree_model_sort_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value);
static gboolean gtk_tree_model_sort_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gtk_tree_model_sort_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent);
static gboolean gtk_tree_model_sort_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gint gtk_tree_model_sort_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n);
static gboolean gtk_tree_model_sort_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
static void gtk_tree_model_sort_ref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter);
/* Internal functions */
2000-12-20 00:37:58 +00:00
static gint gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort,
GArray *array,
GtkTreeIter *iter,
gboolean skip_sort_elt);
2000-11-22 05:16:37 +00:00
static GtkTreePath *gtk_tree_model_sort_convert_path_real (GtkTreeModelSort *tree_model_sort,
GtkTreePath *child_path,
gboolean build_children);
static void gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
SortElt *place);
static void gtk_tree_model_sort_free_level (GArray *array);
static GFunc gtk_tree_model_sort_get_func (GtkTreeModelSort *tree_model_sort);
static gint gtk_tree_model_sort_func (gconstpointer a,
gconstpointer b,
gpointer user_data);
static gint g_value_string_compare_func (const GValue *a,
const GValue *b);
static gint g_value_int_compare_func (const GValue *a,
const GValue *b);
GType
gtk_tree_model_sort_get_type (void)
{
static GType tree_model_sort_type = 0;
if (!tree_model_sort_type)
{
static const GTypeInfo tree_model_sort_info =
{
sizeof (GtkTreeModelSortClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_tree_model_sort_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkTreeModelSort),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_tree_model_sort_init
};
static const GInterfaceInfo tree_model_info =
{
(GInterfaceInitFunc) gtk_tree_model_sort_tree_model_init,
NULL,
NULL
};
tree_model_sort_type = g_type_register_static (G_TYPE_OBJECT, "GtkTreeModelSort", &tree_model_sort_info, 0);
g_type_add_interface_static (tree_model_sort_type,
GTK_TYPE_TREE_MODEL,
&tree_model_info);
}
return tree_model_sort_type;
}
static void
gtk_tree_model_sort_class_init (GtkTreeModelSortClass *tree_model_sort_class)
{
GObjectClass *object_class;
object_class = (GObjectClass *) tree_model_sort_class;
doh, this was broken beyond believe. Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org> * gtk/stock-icons/Makefile.am: doh, this was broken beyond believe. * gtk/gtkbox.c: change property types from (u)long to (u)int for ::position and ::padding. * gtk/gtkcontainer.c: make ::border_width an INT property. * gtk/gtkpacker.c: make ::position an INT property. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed): guard against NULL h/v scrollbars, since this is used at construction time. * gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented internal gtk_clist_constructor(). * gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented gtk_ctree_constructor(). * gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property ::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION. * docs/reference/Makefile.am: fun stuff, disabled docs generation again, gtk-scan.c needs to introspec paramspecs, not GtkAgs. * gtk/gtkwidget.[hc]: removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv() and gtk_widget_get(). (gtk_widget_new): use g_object_new_valist(). (gtk_widget_set): use g_object_set_valist(). * gtk/gtkobject.[hc]: removed gtk_object_arg_get_info(), gtk_object_getv(), gtk_object_query_args(), gtk_object_newv(), gtk_object_class_add_signals(), gtk_object_class_user_signal_new(), gtk_object_class_user_signal_newv(), gtk_object_arg_set(), gtk_object_arg_get(), gtk_object_args_collect(), gtk_object_default_construct(), gtk_object_constructed(), GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED(). removed nsignals, signals and n_args members from GtkObjectClass. (gtk_object_new): use g_object_new_valist(). (gtk_object_set): use g_object_set_valist(). (gtk_object_get): use g_object_get_valist(). * gtk/gtkcompat.h: define gtk_object_default_construct(). * gtk/gtktypeutils.c (gtk_type_new): create constructed objects via g_object_new(). * gtk/*.c: removed gtk_object_class_add_signals() from class_init() fucntions, cleaned up method assignments (make sure your structures are setup properly before calling out). removed all GTK_CONSTRUCTED hacks ;)
2000-12-13 01:34:41 +00:00
object_class->finalize = gtk_tree_model_sort_finalize;
}
static void
gtk_tree_model_sort_tree_model_init (GtkTreeModelIface *iface)
{
iface->get_n_columns = gtk_tree_model_sort_get_n_columns;
iface->get_column_type = gtk_tree_model_sort_get_column_type;
iface->get_iter = gtk_tree_model_sort_get_iter;
iface->get_path = gtk_tree_model_sort_get_path;
iface->get_value = gtk_tree_model_sort_get_value;
iface->iter_next = gtk_tree_model_sort_iter_next;
iface->iter_children = gtk_tree_model_sort_iter_children;
iface->iter_has_child = gtk_tree_model_sort_iter_has_child;
iface->iter_n_children = gtk_tree_model_sort_iter_n_children;
iface->iter_nth_child = gtk_tree_model_sort_iter_nth_child;
iface->iter_parent = gtk_tree_model_sort_iter_parent;
iface->ref_node = gtk_tree_model_sort_ref_node;
iface->unref_node = gtk_tree_model_sort_unref_node;
}
static void
gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort)
{
tree_model_sort->stamp = g_random_int ();
}
GtkTreeModel *
gtk_tree_model_sort_new (void)
{
return GTK_TREE_MODEL (g_object_new (gtk_tree_model_sort_get_type (), NULL));
}
GtkTreeModel *
gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model,
GValueCompareFunc func,
gint sort_col)
{
GtkTreeModel *retval;
retval = gtk_tree_model_sort_new ();
gtk_tree_model_sort_set_model (GTK_TREE_MODEL_SORT (retval), child_model);
GTK_TREE_MODEL_SORT (retval)->func = func;
GTK_TREE_MODEL_SORT (retval)->sort_col = sort_col;
return retval;
}
/**
* gtk_tree_model_sort_set_model:
* @tree_model_sort: The #GtkTreeModelSort.
* @child_model: A #GtkTreeModel, or NULL.
*
* Sets the model of @tree_model_sort to be @model. If @model is NULL, then the
* old model is unset.
**/
void
gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
GtkTreeModel *child_model)
{
g_return_if_fail (tree_model_sort != NULL);
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
if (child_model)
g_object_ref (G_OBJECT (child_model));
if (tree_model_sort->child_model)
{
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->changed_id);
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->inserted_id);
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->has_child_toggled_id);
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->deleted_id);
g_object_unref (G_OBJECT (tree_model_sort->child_model));
}
tree_model_sort->child_model = child_model;
if (child_model)
{
tree_model_sort->changed_id =
g_signal_connectc (child_model,
"changed",
gtk_tree_model_sort_changed,
tree_model_sort,
FALSE);
tree_model_sort->inserted_id =
g_signal_connectc (child_model,
"inserted",
gtk_tree_model_sort_inserted,
tree_model_sort,
FALSE);
tree_model_sort->has_child_toggled_id =
g_signal_connectc (child_model,
"has_child_toggled",
gtk_tree_model_sort_has_child_toggled,
tree_model_sort,
FALSE);
tree_model_sort->deleted_id =
g_signal_connectc (child_model,
"deleted",
gtk_tree_model_sort_deleted,
tree_model_sort,
FALSE);
tree_model_sort->flags = gtk_tree_model_get_flags (child_model);
}
}
/**
* gtk_tree_model_sort_get_model:
* @tree_model: a #GtkTreeModelSort
*
* Returns the model the #GtkTreeModelSort is sorting.
*
* Return value: the "child model" being sorted
**/
GtkTreeModel*
gtk_tree_model_sort_get_model (GtkTreeModelSort *tree_model)
{
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), NULL);
return tree_model->child_model;
}
/**
* gtk_tree_model_sort_convert_path:
* @tree_model_sort: The #GtkTreeModelSort.
* @child_path: A #GtkTreePath, relative to the child model.
*
* Converts the @child_path to a new path, relative to the sorted position. In other
* words, the value found in the @tree_model_sort ->child_model at the @child_path, is
* identical to that found in the @tree_model_sort and the return value.
*
* Return value: A new path, or NULL if @child_path does not exist in @tree_model_sort
* ->child_model.
**/
GtkTreePath *
gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
GtkTreePath *child_path)
{
2000-11-22 05:16:37 +00:00
g_return_val_if_fail (tree_model_sort != NULL, NULL);
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort), NULL);
g_return_val_if_fail (child_path != NULL, NULL);
2000-11-22 05:16:37 +00:00
return gtk_tree_model_sort_convert_path_real (tree_model_sort, child_path, TRUE);
}
static void
gtk_tree_model_sort_finalize (GObject *object)
{
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) object;
if (tree_model_sort->root)
gtk_tree_model_sort_free_level (tree_model_sort->root);
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
if (tree_model_sort->child_model)
{
g_object_unref (G_OBJECT (tree_model_sort->child_model));
tree_model_sort->child_model = NULL;
}
}
static void
gtk_tree_model_sort_changed (GtkTreeModel *s_model,
GtkTreePath *s_path,
GtkTreeIter *s_iter,
gpointer data)
{
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
GtkTreePath *path;
GtkTreeIter iter;
2000-12-20 00:37:58 +00:00
SortElt *elt;
GArray *array;
gboolean free_s_path = FALSE;
2000-12-20 00:37:58 +00:00
gint index;
g_return_if_fail (s_path != NULL || s_iter != NULL);
if (s_path == NULL)
{
free_s_path = TRUE;
s_path = gtk_tree_model_get_path (s_model, s_iter);
}
2000-11-22 05:16:37 +00:00
path = gtk_tree_model_sort_convert_path_real (tree_model_sort, s_path, FALSE);
if (path == NULL)
{
if (free_s_path)
gtk_tree_path_free (s_path);
return;
}
2000-12-20 00:37:58 +00:00
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
elt = (SortElt *) iter.user_data;
2000-12-20 00:37:58 +00:00
array = get_array (elt, tree_model_sort);
/* FIXME: as an optimization for when the column other then the one we're
* sorting is changed, we can check the prev and next element to see if
* they're different.
*/
/* Now we need to resort things. */
index = gtk_tree_model_sort_array_find_insert (tree_model_sort,
array,
(GtkTreeIter *) elt,
TRUE);
remove validation idle 2001-02-08 Havoc Pennington <hp@redhat.com> * gtk/gtktextview.c (gtk_text_view_destroy_layout): remove validation idle * demos/gtk-demo/main.c (create_tree): adjust to changes in text cell renderer * demos/pixbuf-demo.c (timeout): remove deprecated gtk_widget_draw * demos/testpixbuf-save.c (main): remove deprecated gtk_drawing_area_size * gtk/gtktreeview.c (gtk_tree_view_size_allocate): allocate buttons even if the model isn't setup. gtk_tree_view_check_dirty() at the start of the allocation. (gtk_tree_view_check_dirty): handle column->button == NULL, handle unsetup or NULL model. * gtk/gtkstyle.c (gtk_default_draw_flat_box): drawing for the even/odd/sorted cells in the tree view. * gtk/gtktreeselection.c (gtk_tree_selection_real_unselect_all): bugfixes * gtk/gtktreeview.c: assorted bugfixy stuff. Draw the row backgrounds with draw_flat_box using different detail for even/odd rows. * gtk/gtkrbtree.c, gtkrbtree.h: Keep track of the parity of each row, so we can draw the alternating colors thing * gtk/gtktexttag.c (gtk_text_tag_set_property): if we change a property from a synonym property, notify for the synonym. Also, nuke the background_gdk_set and foreground_gdk_set synonyms (gtk_text_tag_get_property): Always return the font, even if all its fields aren't set * gtk/gtkcellrenderertext.h (struct _GtkCellRendererText): don't store the attr list; it leaves us with no way to change attributes in _render according to the render flags, and no way to implement get_property. Instead store all the specific text attributes. Separate whether an attribute is enabled from its value. Sync all properties with GtkTextTag, make them all consistent, etc. * gtk/gtkcellrenderer.h: Add a flag GTK_CELL_RENDERER_SORTED so renderers can highlight the sort row/column * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_get_property): use accessor functions to get values; this has the side effect of showing up which accessor functions were missing. Added those. * gtk/gtktreeviewcolumn.h: Replace set_justification with set_alignment, to be consistent with GtkLabel, GtkMisc * gtk/gtktreeviewcolumn.c: Added code to display sort indicator arrow. * gtk/Makefile.am (gtk_public_h_sources): add gtktreesortable.h * gtk/gtktreesortable.h: updates in here
2001-02-08 23:36:53 +00:00
g_signal_emit_by_name (G_OBJECT (data), "changed", path, &iter);
gtk_tree_path_free (path);
if (free_s_path)
gtk_tree_path_free (s_path);
}
2000-11-22 05:16:37 +00:00
/* FALSE if the value was inserted, TRUE otherwise */
static gboolean
gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
GtkTreePath *s_path,
GtkTreeIter *s_iter)
{
GtkTreePath *tmp_path;
GArray *array;
2000-12-20 00:37:58 +00:00
gint index;
GtkTreeIter iter;
SortElt elt;
gint offset;
gint j;
2000-12-20 00:37:58 +00:00
SortElt *tmp_elt;
offset = gtk_tree_path_get_indices (s_path)[gtk_tree_path_get_depth (s_path) - 1];
elt.iter = *s_iter;
elt.ref = 0;
elt.children = NULL;
elt.offset = offset;
2000-11-22 05:16:37 +00:00
tmp_path = gtk_tree_path_copy (s_path);
2000-11-22 05:16:37 +00:00
if (gtk_tree_path_up (tmp_path))
{
GtkTreePath *parent_path;
2000-11-22 05:16:37 +00:00
parent_path = gtk_tree_model_sort_convert_path_real (sort, tmp_path, FALSE);
if (parent_path == NULL)
{
gtk_tree_path_free (tmp_path);
return FALSE;
}
gtk_tree_model_get_iter (GTK_TREE_MODEL (sort), &iter, parent_path);
elt.parent = ((SortElt *) iter.user_data);
array = ((SortElt *) iter.user_data)->children;
2000-11-22 05:16:37 +00:00
gtk_tree_path_free (parent_path);
if (array == NULL)
{
2000-11-22 05:16:37 +00:00
gtk_tree_path_free (tmp_path);
return FALSE;
}
}
else
{
if (sort->root == NULL)
sort->root = g_array_sized_new (FALSE, FALSE, sizeof (SortElt), 1);
array = sort->root;
elt.parent = NULL;
}
gtk_tree_path_free (tmp_path);
2000-12-20 00:37:58 +00:00
index = gtk_tree_model_sort_array_find_insert (sort, array, (GtkTreeIter *) &elt, FALSE);
2000-12-20 00:37:58 +00:00
g_array_insert_vals (array, index, &elt, 1);
/* update all the larger offsets */
tmp_elt = (SortElt *) array->data;
for (j = 0; j < array->len; j++, tmp_elt++)
{
if ((tmp_elt->offset >= offset) &&
2000-12-20 00:37:58 +00:00
j != index)
tmp_elt->offset ++;
}
2000-11-22 05:16:37 +00:00
return TRUE;
}
static void
gtk_tree_model_sort_inserted (GtkTreeModel *s_model,
GtkTreePath *s_path,
GtkTreeIter *s_iter,
gpointer data)
{
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
GtkTreePath *path;
GtkTreeIter iter;
g_return_if_fail (s_path != NULL || s_iter != NULL);
if (s_path == NULL)
s_path = gtk_tree_model_get_path (s_model, s_iter);
if (!(tree_model_sort->flags & GTK_TREE_MODEL_ITERS_PERSIST))
{
gtk_tree_model_sort_free_level ((GArray *) tree_model_sort->root);
tree_model_sort->root = NULL;
}
else
{
GtkTreeIter real_s_iter;
if (s_iter == NULL)
gtk_tree_model_get_iter (s_model, &real_s_iter, s_path);
else
real_s_iter = (* s_iter);
2000-11-22 05:16:37 +00:00
if (!gtk_tree_model_sort_insert_value (tree_model_sort, s_path, &real_s_iter))
return;
}
2000-11-22 05:16:37 +00:00
path = gtk_tree_model_sort_convert_path_real (tree_model_sort, s_path, FALSE);
if (path == NULL)
return;
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
g_signal_emit_by_name (G_OBJECT (data), "inserted", path, &iter);
gtk_tree_path_free (path);
}
static void
gtk_tree_model_sort_has_child_toggled (GtkTreeModel *s_model,
GtkTreePath *s_path,
GtkTreeIter *s_iter,
gpointer data)
{
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
GtkTreePath *path;
GtkTreeIter iter;
gboolean free_s_path = FALSE;
g_return_if_fail (s_path != NULL || s_iter != NULL);
if (!(tree_model_sort->flags & GTK_TREE_MODEL_ITERS_PERSIST))
{
gtk_tree_model_sort_free_level ((GArray *)tree_model_sort->root);
tree_model_sort->root = NULL;
}
if (s_path == NULL)
{
s_path = gtk_tree_model_get_path (s_model, s_iter);
free_s_path = TRUE;
}
2000-11-22 05:16:37 +00:00
path = gtk_tree_model_sort_convert_path_real (tree_model_sort, s_path, FALSE);
if (path == NULL)
return;
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
g_signal_emit_by_name (G_OBJECT (data),
"has_child_toggled",
path, &iter);
gtk_tree_path_free (path);
if (free_s_path)
gtk_tree_path_free (s_path);
}
static void
gtk_tree_model_sort_deleted (GtkTreeModel *s_model,
GtkTreePath *s_path,
gpointer data)
{
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
GtkTreePath *path;
g_return_if_fail (s_path != NULL);
path = gtk_tree_model_sort_convert_path (tree_model_sort, s_path);
g_return_if_fail (path != NULL);
if (!(tree_model_sort->flags & GTK_TREE_MODEL_ITERS_PERSIST))
{
gtk_tree_model_sort_free_level ((GArray *)tree_model_sort->root);
tree_model_sort->root = NULL;
}
else
{
GArray *array;
GtkTreeIter iter;
SortElt *elt;
gint offset;
gint i;
gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_model_sort), &iter, path);
elt = (SortElt *) iter.user_data;
offset = elt->offset;
array = get_array (elt, tree_model_sort);
if (array->len == 1)
{
if (((SortElt *)array->data)->parent == NULL)
tree_model_sort->root = NULL;
else
(((SortElt *)array->data)->parent)->children = NULL;
gtk_tree_model_sort_free_level (array);
}
else
{
g_array_remove_index (array, elt - ((SortElt *) array->data));
for (i = 0; i < array->len; i++)
{
elt = & (g_array_index (array, SortElt, i));
if (elt->offset > offset)
elt->offset--;
}
}
}
tree_model_sort->stamp++;
g_signal_emit_by_name (G_OBJECT (data), "deleted", path);
gtk_tree_path_free (path);
}
static gint
gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model)
{
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), 0);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, 0);
return gtk_tree_model_get_n_columns (GTK_TREE_MODEL_SORT (tree_model)->child_model);
}
static GType
gtk_tree_model_sort_get_column_type (GtkTreeModel *tree_model,
gint index)
{
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), G_TYPE_INVALID);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, G_TYPE_INVALID);
return gtk_tree_model_get_column_type (GTK_TREE_MODEL_SORT (tree_model)->child_model, index);
}
static gboolean
gtk_tree_model_sort_get_iter_helper (GtkTreeModelSort *tree_model_sort,
GArray *array,
GtkTreeIter *iter,
gint depth,
GtkTreePath *path)
{
SortElt *elt;
if (array == NULL)
return FALSE;
if (gtk_tree_path_get_indices (path)[depth] > array->len)
return FALSE;
elt = & (g_array_index (array, SortElt, gtk_tree_path_get_indices (path)[depth]));
if (depth == gtk_tree_path_get_depth (path) - 1)
{
iter->stamp = tree_model_sort->stamp;
iter->user_data = elt;
return TRUE;
}
if (elt->children != NULL)
return gtk_tree_model_sort_get_iter_helper (tree_model_sort,
elt->children,
iter,
depth + 1,
path);
if (gtk_tree_model_iter_has_child (tree_model_sort->child_model,
&(elt->iter)))
gtk_tree_model_sort_build_level (tree_model_sort, elt);
return gtk_tree_model_sort_get_iter_helper (tree_model_sort,
elt->children,
iter,
depth + 1,
path);
}
static gboolean
gtk_tree_model_sort_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path)
{
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
if (GTK_TREE_MODEL_SORT (tree_model)->root == NULL)
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), NULL);
return gtk_tree_model_sort_get_iter_helper (GTK_TREE_MODEL_SORT (tree_model),
GTK_TREE_MODEL_SORT (tree_model)->root,
iter, 0, path);
}
static GtkTreePath *
gtk_tree_model_sort_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), NULL);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, NULL);
return gtk_tree_model_get_path (GTK_TREE_MODEL_SORT (tree_model)->child_model, iter);
}
static void
gtk_tree_model_sort_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value)
{
SortElt *elt;
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model));
g_return_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL);
g_return_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp);
elt = iter->user_data;
gtk_tree_model_get_value (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *)elt, column, value);
}
static gboolean
gtk_tree_model_sort_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
GArray *array;
SortElt *elt;
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, FALSE);
elt = iter->user_data;
array = get_array (elt, tree_model);
if (elt - ((SortElt*) array->data) >= array->len - 1)
{
iter->stamp = 0;
return FALSE;
}
iter->user_data = elt + 1;
return TRUE;
}
static gboolean
gtk_tree_model_sort_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent)
{
SortElt *elt;
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
2000-11-22 05:16:37 +00:00
if (parent)
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == parent->stamp, FALSE);
if (parent)
elt = parent->user_data;
else
elt = (SortElt *) ((GArray *)GTK_TREE_MODEL_SORT (tree_model)->root)->data;
if (elt == NULL)
return FALSE;
if (elt->children == NULL &&
gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *)elt))
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), elt);
if (elt->children == NULL)
return FALSE;
iter->stamp = GTK_TREE_MODEL_SORT (tree_model)->stamp;
iter->user_data = elt->children->data;
return TRUE;
}
static gboolean
gtk_tree_model_sort_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
SortElt *elt;
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, FALSE);
elt = iter->user_data;
if (elt->children)
return TRUE;
return gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *) elt);
}
static gint
gtk_tree_model_sort_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
SortElt *elt;
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), 0);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, 0);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, 0);
elt = iter->user_data;
if (elt->children)
return elt->children->len;
return gtk_tree_model_iter_n_children (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *) elt);
}
static gboolean
gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n)
{
SortElt *elt;
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
if (parent)
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == parent->stamp, FALSE);
elt = iter->user_data;
if (elt->children == NULL)
{
if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *)elt))
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), elt);
else
return FALSE;
}
if (elt->children == NULL)
return FALSE;
if (n >= elt->children->len)
return FALSE;
iter->stamp = GTK_TREE_MODEL_SORT (tree_model)->stamp;
iter->user_data = &g_array_index (elt->children, SortElt, n);
return TRUE;
}
static gboolean
gtk_tree_model_sort_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child)
{
SortElt *elt;
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == child->stamp, FALSE);
elt = iter->user_data;
if (elt->parent)
{
iter->stamp = GTK_TREE_MODEL_SORT (tree_model)->stamp;
iter->user_data = elt->parent;
return TRUE;
}
return FALSE;
}
static void
gtk_tree_model_sort_ref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
}
static void
gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
}
/* Internal functions */
2000-12-20 00:37:58 +00:00
static gint
gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort,
GArray *array,
GtkTreeIter *iter,
gboolean skip_sort_elt)
{
gint middle;
gint cmp;
GValueCompareFunc func;
GValue value = {0, };
GValue tmp_value = {0, };
SortElt *tmp_elt;
func = (GValueCompareFunc) gtk_tree_model_sort_get_func (tree_model_sort);
g_return_val_if_fail (func != NULL, 0);
gtk_tree_model_get_value (tree_model_sort->child_model, iter, tree_model_sort->sort_col, &value);
for (middle = 0; middle < array->len; middle++)
{
tmp_elt = &(g_array_index (array, SortElt, middle));
if (!skip_sort_elt &&
(SortElt *) iter == tmp_elt)
continue;
gtk_tree_model_get_value (tree_model_sort->child_model,
(GtkTreeIter *) tmp_elt,
tree_model_sort->sort_col,
&tmp_value);
cmp = ((func) (&value, &tmp_value));
g_value_unset (&tmp_value);
if (cmp >= 0)
break;
}
return middle;
}
2000-11-22 05:16:37 +00:00
static GtkTreePath *
gtk_tree_model_sort_convert_path_real (GtkTreeModelSort *tree_model_sort,
GtkTreePath *child_path,
gboolean build_children)
{
GtkTreePath *retval;
GArray *array;
gint *indices;
gint i = 0;
if (tree_model_sort->root == NULL)
{
if (build_children)
gtk_tree_model_sort_build_level (tree_model_sort, NULL);
else
return FALSE;
}
retval = gtk_tree_path_new ();
array = (GArray *) tree_model_sort->root;
indices = gtk_tree_path_get_indices (child_path);
do
{
SortElt *elt;
gboolean found = FALSE;
gint j;
if ((array->len < indices[i]) || (array == NULL))
{
gtk_tree_path_free (retval);
return NULL;
}
elt = (SortElt *) array->data;
for (j = 0; j < array->len; j++, elt++)
{
if (elt->offset == indices[i])
{
found = TRUE;
break;
}
}
if (! found)
{
gtk_tree_path_free (retval);
return NULL;
}
gtk_tree_path_prepend_index (retval, j);
i++;
if (i == gtk_tree_path_get_depth (child_path))
break;
if (elt->children == NULL)
{
if (build_children)
{
gtk_tree_path_prepend_index (retval, j);
gtk_tree_model_sort_build_level (tree_model_sort, elt);
}
else
{
gtk_tree_path_free (retval);
return NULL;
}
}
}
while (TRUE);
return retval;
}
static void
gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
SortElt *place)
{
gint n, i = 0;
GArray *children;
GtkTreeIter *parent_iter = NULL;
GtkTreeIter iter;
SortElt elt;
2000-11-22 05:16:37 +00:00
SortData sort_data;
if (place)
parent_iter = & (place->iter);
n = gtk_tree_model_iter_n_children (tree_model_sort->child_model, parent_iter);
if (n == 0)
return;
children = g_array_sized_new (FALSE, FALSE, sizeof (SortElt), n);
if (place)
place->children = children;
else
tree_model_sort->root = children;
gtk_tree_model_iter_children (tree_model_sort->child_model,
&iter,
parent_iter);
do
{
elt.iter = iter;
elt.parent = place;
elt.children = NULL;
elt.ref = 0;
elt.offset = i;
g_array_append_vals (children, &elt, 1);
i++;
}
while (gtk_tree_model_iter_next (tree_model_sort->child_model, &iter));
2000-11-22 05:16:37 +00:00
sort_data.func = (GValueCompareFunc) gtk_tree_model_sort_get_func (tree_model_sort);
sort_data.model = tree_model_sort->child_model;
sort_data.sort_col = tree_model_sort->sort_col;
g_array_sort_with_data (children, gtk_tree_model_sort_func, &sort_data);
}
static void
gtk_tree_model_sort_free_level (GArray *array)
{
gint i;
if (array == NULL)
return;
for (i = 0; i < array->len; i++)
{
SortElt *elt;
elt = &g_array_index (array, SortElt, i);
if (elt->children)
gtk_tree_model_sort_free_level (array);
}
g_array_free (array, TRUE);
}
2000-11-22 05:16:37 +00:00
static GFunc
gtk_tree_model_sort_get_func (GtkTreeModelSort *tree_model_sort)
{
GValueCompareFunc func;
if (tree_model_sort->func)
func = tree_model_sort->func;
else
{
switch (gtk_tree_model_get_column_type (tree_model_sort->child_model,
tree_model_sort->sort_col))
{
case G_TYPE_STRING:
func = &g_value_string_compare_func;
break;
case G_TYPE_INT:
func = &g_value_int_compare_func;
break;
default:
g_warning ("No comparison function for row %d (Type %s)\n",
tree_model_sort->sort_col,
g_type_name (gtk_tree_model_get_column_type (tree_model_sort->child_model,
tree_model_sort->sort_col)));
return NULL;
}
}
return (GFunc) func;
}
static gint
gtk_tree_model_sort_func (gconstpointer a,
gconstpointer b,
gpointer user_data)
{
GValue value_a = {0, };
GValue value_b = {0, };
2000-11-22 05:16:37 +00:00
SortData *sort_data = user_data;
make this somewhat key-navigable 2001-03-23 Havoc Pennington <hp@pobox.com> * gtk/gtkhsv.c: make this somewhat key-navigable * gtk/gtkfontsel.c: mnemonics * gtk/gtkgamma.c: mnemonics * gtk/gtkcolorsel.c: add mnemonics to labels 2001-03-22 Havoc Pennington <hp@pobox.com> Applied big patch from Seth Lytle to fix event handler return values, slightly modified. * gtk/gtkcalendar.c (gtk_calendar_button_press): return TRUE if handled. (gtk_calendar_key_press): return TRUE for GDK_space triggers select_day * gtk/gtkclist.c (gtk_clist_button_press): return TRUE if handled (gtk_clist_button_release): return TRUE if handled * gtk/gtkcolorsel.c (mouse_release): (palette_activate): (palette_press): (palette_new): (mouse_press): (get_screen_color): fixed return type (void to gboolean), return TRUE, added GTK_SIGNAL_FUNC cast * gtk/gtkcombo.c (gtk_combo_popup_button_press): fixed return type (void to gboolean), and return TRUE (gtk_combo_button_release): changed return value to TRUE after gtk_grab_add on combo->popwin * gtk/gtkctree.c (gtk_ctree_button_press): return TRUE if triggers a collapse or expand * gtk/gtkcurve.c (gtk_curve_graph_events): return TRUE for button/motion * gtk/gtkdnd.c (gtk_drag_source_event_cb): return TRUE for button press/release and motion that trigger act * gtk/gtkentry.c (gtk_entry_button_release): return TRUE * gtk/gtkfontsel.c (gtk_font_selection_size_key_press): return TRUE for GDK_Return * gtk/gtklist.c (gtk_list_button_press): return TRUE mostly (gtk_list_button_release): return TRUE if selection * gtk/gtklistitem.c (gtk_list_item_button_press): return TRUE on press * gtk/gtkmenushell.c (gtk_menu_shell_button_press): (gtk_menu_shell_button_release): chain parent_menu_shell retval * gtk/gtknotebook.c (gtk_notebook_button_press): return FALSE if nothing triggered (gtk_notebook_button_release): return TRUE if we do anything * gtk/gtkspinbutton.c (gtk_spin_button_button_press): (gtk_spin_button_button_release): return TRUE or chained retval * gtk/gtktext.c (gtk_text_button_press): (gtk_text_button_release): return TRUE (gtk_text_key_press): remove redundant retval code * gtk/gtktreeitem.c (gtk_tree_item_button_press): return TRUE if button and sensitive (gtk_tree_item_subtree_button_click): changed type to gint, and return TRUE if sensitive * gtk/gtktooltips.c (gtk_tooltips_event_handler): deactivate implies return TRUE
2001-03-24 06:10:40 +00:00
gboolean retval;
2000-11-22 05:16:37 +00:00
gtk_tree_model_get_value (sort_data->model, (GtkTreeIter *) a, sort_data->sort_col, &value_a);
gtk_tree_model_get_value (sort_data->model, (GtkTreeIter *) b, sort_data->sort_col, &value_b);
retval = (sort_data->func) (&value_a, &value_b);
g_value_unset (&value_a);
g_value_unset (&value_b);
return retval;
}
static gint
g_value_string_compare_func (const GValue *a,
const GValue *b)
{
gchar *a_str = g_value_get_string (a);
gchar *b_str = g_value_get_string (b);
if (b_str == NULL)
return a_str == NULL;
if (a_str == NULL)
return -1;
return strcmp (a_str, b_str);
}
2000-11-22 05:16:37 +00:00
static gint
g_value_int_compare_func (const GValue *a,
const GValue *b)
{
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
gint a_int = g_value_get_int (a);
gint b_int = g_value_get_int (b);
if (a_int < b_int)
return -1;
else if (a_int > b_int)
return 1;
else
return 0;
}
2000-12-20 00:37:58 +00:00
/* DEAD CODE */
#if 0
/* FIXME: we can, as we are an array, do binary search to find the correct
* location to insert the element. However, I'd rather get it working. The
* below is quite wrong, but a step in the right direction.
*/
low = 0;
high = array->len;
middle = (low + high)/2;
/* Insert the value into the array */
while (low != high)
{
gint cmp;
tmp_elt = &(g_array_index (array, SortElt, middle));
gtk_tree_model_get_value (sort->child_model,
(GtkTreeIter *) tmp_elt,
sort->sort_col,
&tmp_value);
cmp = ((func) (&tmp_value, &s_value));
g_value_unset (&tmp_value);
if (cmp < 0)
high = middle;
else if (cmp > 0)
low = middle;
else if (cmp == 0)
break;
middle = (low + high)/2;
}
#endif