2001-03-23 00:35:19 +00:00
|
|
|
/* gtktreesortable.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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "gtktreesortable.h"
|
|
|
|
#include "gtksignal.h"
|
|
|
|
|
|
|
|
static void gtk_tree_sortable_base_init (gpointer g_class);
|
|
|
|
|
|
|
|
GtkType
|
|
|
|
gtk_tree_sortable_get_type (void)
|
|
|
|
{
|
|
|
|
static GtkType tree_sortable_type = 0;
|
|
|
|
|
|
|
|
if (! tree_sortable_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo tree_sortable_info =
|
|
|
|
{
|
|
|
|
sizeof (GtkTreeSortableIface), /* class_size */
|
|
|
|
gtk_tree_sortable_base_init, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
NULL,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
tree_sortable_type = g_type_register_static (G_TYPE_INTERFACE, "GtkTreeSortable", &tree_sortable_info, 0);
|
2001-09-17 21:44:20 +00:00
|
|
|
g_type_interface_add_prerequisite (tree_sortable_type, GTK_TYPE_TREE_MODEL);
|
2001-03-23 00:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tree_sortable_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_sortable_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
static gboolean initialized = FALSE;
|
|
|
|
|
|
|
|
if (! initialized)
|
|
|
|
{
|
2001-06-29 16:30:25 +00:00
|
|
|
g_signal_new ("sort_column_changed",
|
|
|
|
GTK_TYPE_TREE_SORTABLE,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
gtk_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2001-03-23 00:35:19 +00:00
|
|
|
initialized = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_sortable_sort_column_changed:
|
|
|
|
* @sortable: A #GtkTreeSortable
|
|
|
|
*
|
|
|
|
* Emits a GtkTreeSortable::sort_column_changed signal on
|
|
|
|
**/
|
2001-03-29 21:30:05 +00:00
|
|
|
void
|
|
|
|
gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
|
|
|
|
|
|
|
|
g_signal_emit_by_name (G_OBJECT (sortable),
|
|
|
|
"sort_column_changed");
|
|
|
|
}
|
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_sortable_get_sort_column_id:
|
|
|
|
* @sortable: A #GtkTreeSortable
|
|
|
|
* @sort_column_id: The sort column id to be filled in
|
|
|
|
* @order: The #GtkSortType to be filled in
|
|
|
|
*
|
|
|
|
* Fills in @sort_column_id and @order with the current sort column and the
|
|
|
|
* order, if applicable. If the sort column is not set, then FALSE is returned,
|
|
|
|
* and the values in @sort_column_id and @order are unchanged.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE, if the sort column has been set
|
|
|
|
**/
|
2001-03-23 00:35:19 +00:00
|
|
|
gboolean
|
|
|
|
gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint *sort_column_id,
|
2001-08-23 18:33:37 +00:00
|
|
|
GtkSortType *order)
|
2001-03-23 00:35:19 +00:00
|
|
|
{
|
|
|
|
GtkTreeSortableIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
|
|
|
|
|
|
|
|
iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
|
|
|
|
|
|
|
|
g_return_val_if_fail (iface != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
|
|
|
|
|
|
|
|
return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
|
|
|
|
}
|
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_sortable_set_sort_column_id:
|
|
|
|
* @sortable: A #GtkTreeSortable
|
|
|
|
* @sort_column_id: the sort column id to set
|
|
|
|
* @order: The sort order of the column
|
|
|
|
*
|
|
|
|
* Sets the current sort column to be @sort_column_id. The @sortable will
|
|
|
|
* resort itself to reflect this change, after emitting a
|
|
|
|
* GtkTreeSortable::sort_column_changed signal. If @sort_column_id is -1, then
|
|
|
|
* the default sort function will be used, if it is set.
|
|
|
|
**/
|
2001-03-23 00:35:19 +00:00
|
|
|
void
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
2001-08-23 18:33:37 +00:00
|
|
|
GtkSortType order)
|
2001-03-23 00:35:19 +00:00
|
|
|
{
|
|
|
|
GtkTreeSortableIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
|
|
|
|
|
|
|
|
iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
|
|
|
|
|
|
|
|
g_return_if_fail (iface != NULL);
|
|
|
|
g_return_if_fail (iface->set_sort_column_id != NULL);
|
|
|
|
|
|
|
|
(* iface->set_sort_column_id) (sortable, sort_column_id, order);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_sortable_set_sort_func:
|
|
|
|
* @sortable: A #GtkTreeSortable
|
|
|
|
* @sort_column_id: the sort column id to set the function for
|
|
|
|
* @sort_func: The sorting function
|
|
|
|
* @user_data: User data to pass to the sort func, or %NULL
|
|
|
|
* @destroy: Destroy notifier of @user_data, or %NULL
|
|
|
|
*
|
|
|
|
* Sets the comparison function used when sorting to be @sort_func. If the
|
|
|
|
* current sort column id of @sortable is the same as @sort_column_id, then the
|
|
|
|
* model will sort.
|
|
|
|
**/
|
2001-03-23 00:35:19 +00:00
|
|
|
void
|
2001-06-15 23:03:27 +00:00
|
|
|
gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
2001-09-04 22:15:18 +00:00
|
|
|
GtkTreeIterCompareFunc sort_func,
|
|
|
|
gpointer user_data,
|
2001-06-15 23:03:27 +00:00
|
|
|
GtkDestroyNotify destroy)
|
2001-03-23 00:35:19 +00:00
|
|
|
{
|
|
|
|
GtkTreeSortableIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
|
|
|
|
|
|
|
|
iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
|
|
|
|
|
|
|
|
g_return_if_fail (iface != NULL);
|
2001-06-15 23:03:27 +00:00
|
|
|
g_return_if_fail (iface->set_sort_func != NULL);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
(* iface->set_sort_func) (sortable, sort_column_id, sort_func, user_data, destroy);
|
2001-03-23 00:35:19 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_sortable_set_default_sort_func:
|
|
|
|
* @sortable: A #GtkTreeSortable
|
|
|
|
* @sort_func: The sorting function
|
|
|
|
* @user_data: User data to pass to the sort func, or %NULL
|
|
|
|
* @destroy: Destroy notifier of @user_data, or %NULL
|
|
|
|
*
|
|
|
|
* Sets the default comparison function used when sorting to be @sort_func. If
|
|
|
|
* the current sort column id of @sortable is the same as @sort_column_id, then
|
|
|
|
* the model will sort.
|
|
|
|
**/
|
2001-09-03 23:37:39 +00:00
|
|
|
void
|
|
|
|
gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable,
|
2001-09-04 22:15:18 +00:00
|
|
|
GtkTreeIterCompareFunc sort_func,
|
|
|
|
gpointer user_data,
|
2001-09-03 23:37:39 +00:00
|
|
|
GtkDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
GtkTreeSortableIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
|
|
|
|
|
|
|
|
iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
|
|
|
|
|
|
|
|
g_return_if_fail (iface != NULL);
|
|
|
|
g_return_if_fail (iface->set_default_sort_func != NULL);
|
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
(* iface->set_default_sort_func) (sortable, sort_func, user_data, destroy);
|
2001-09-03 23:37:39 +00:00
|
|
|
}
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_sortable_has_default_sort_func:
|
|
|
|
* @sortable: A #GtkTreeSortable
|
|
|
|
*
|
|
|
|
* Returns %TRUE if the model has a default sort function. This is used
|
|
|
|
* primarily by GtkTreeViewColumns in order to determine if a model can go back
|
|
|
|
* to the default state, or not.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE, if the model has a default sort function
|
|
|
|
**/
|
2001-09-03 23:37:39 +00:00
|
|
|
gboolean
|
|
|
|
gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
|
|
|
|
{
|
|
|
|
GtkTreeSortableIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
|
|
|
|
|
|
|
|
iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
|
|
|
|
|
|
|
|
g_return_if_fail (iface != NULL);
|
|
|
|
g_return_if_fail (iface->has_default_sort_func != NULL);
|
|
|
|
|
|
|
|
(* iface->has_default_sort_func) (sortable);
|
|
|
|
}
|