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
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2001-03-23 00:35:19 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2001-03-23 00:35:19 +00:00
|
|
|
|
#include "gtktreesortable.h"
|
2001-11-17 23:28:51 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
2005-09-01 05:11:46 +00:00
|
|
|
|
#include "gtkintl.h"
|
2010-07-09 17:22:23 +00:00
|
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
|
|
2010-10-22 20:10:03 +00:00
|
|
|
|
/**
|
2021-03-02 03:51:03 +00:00
|
|
|
|
* GtkTreeSortable:
|
|
|
|
|
*
|
|
|
|
|
* The interface for sortable models used by GtkTreeView
|
2010-10-22 20:10:03 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* `GtkTreeSortable` is an interface to be implemented by tree models which
|
|
|
|
|
* support sorting. The `GtkTreeView` uses the methods provided by this interface
|
2010-10-22 20:10:03 +00:00
|
|
|
|
* to sort the model.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
|
static void gtk_tree_sortable_base_init (gpointer g_class);
|
|
|
|
|
|
2002-10-07 19:10:39 +00:00
|
|
|
|
GType
|
2001-03-23 00:35:19 +00:00
|
|
|
|
gtk_tree_sortable_get_type (void)
|
|
|
|
|
{
|
2002-10-07 19:10:39 +00:00
|
|
|
|
static GType tree_sortable_type = 0;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
|
|
|
|
|
if (! tree_sortable_type)
|
|
|
|
|
{
|
2006-10-03 15:54:52 +00:00
|
|
|
|
const GTypeInfo tree_sortable_info =
|
2001-03-23 00:35:19 +00:00
|
|
|
|
{
|
|
|
|
|
sizeof (GtkTreeSortableIface), /* class_size */
|
|
|
|
|
gtk_tree_sortable_base_init, /* base_init */
|
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
|
NULL,
|
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
|
NULL, /* class_data */
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
2002-10-07 19:10:39 +00:00
|
|
|
|
|
|
|
|
|
tree_sortable_type =
|
2005-09-01 05:11:46 +00:00
|
|
|
|
g_type_register_static (G_TYPE_INTERFACE, I_("GtkTreeSortable"),
|
2002-10-07 19:10:39 +00:00
|
|
|
|
&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)
|
|
|
|
|
{
|
2009-01-03 06:57:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkTreeSortable::sort-column-changed:
|
|
|
|
|
* @sortable: the object on which the signal is emitted
|
|
|
|
|
*
|
|
|
|
|
* The ::sort-column-changed signal is emitted when the sort column
|
|
|
|
|
* or sort order of @sortable is changed. The signal is emitted before
|
|
|
|
|
* the contents of @sortable are resorted.
|
|
|
|
|
*/
|
2008-08-08 13:53:05 +00:00
|
|
|
|
g_signal_new (I_("sort-column-changed"),
|
2001-06-29 16:30:25 +00:00
|
|
|
|
GTK_TYPE_TREE_SORTABLE,
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2001-06-29 16:30:25 +00:00
|
|
|
|
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:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @sortable: A `GtkTreeSortable`
|
2001-09-04 22:15:18 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* Emits a `GtkTreeSortable::sort-column-changed` signal on @sortable.
|
2009-01-03 06:57:10 +00:00
|
|
|
|
*/
|
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));
|
|
|
|
|
|
2008-08-08 13:53:05 +00:00
|
|
|
|
g_signal_emit_by_name (sortable, "sort-column-changed");
|
2001-03-29 21:30:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-04 22:15:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_sortable_get_sort_column_id:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @sortable: A `GtkTreeSortable`
|
2010-11-15 17:13:32 +00:00
|
|
|
|
* @sort_column_id: (out): The sort column id to be filled in
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @order: (out): The `GtkSortType` to be filled in
|
2001-09-04 22:15:18 +00:00
|
|
|
|
*
|
|
|
|
|
* Fills in @sort_column_id and @order with the current sort column and the
|
2009-01-03 06:57:10 +00:00
|
|
|
|
* order. It returns %TRUE unless the @sort_column_id is
|
2004-11-30 21:45:26 +00:00
|
|
|
|
* %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or
|
|
|
|
|
* %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the sort column is not one of the special sort
|
2004-11-30 21:45:26 +00:00
|
|
|
|
* column ids.
|
2001-09-04 22:15:18 +00:00
|
|
|
|
**/
|
2001-03-23 00:35:19 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *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:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @sortable: A `GtkTreeSortable`
|
2001-09-04 22:15:18 +00:00
|
|
|
|
* @sort_column_id: the sort column id to set
|
|
|
|
|
* @order: The sort order of the column
|
|
|
|
|
*
|
2009-01-03 06:57:10 +00:00
|
|
|
|
* Sets the current sort column to be @sort_column_id. The @sortable will
|
2001-09-04 22:15:18 +00:00
|
|
|
|
* resort itself to reflect this change, after emitting a
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* `GtkTreeSortable::sort-column-changed` signal. @sort_column_id may either be
|
2009-01-03 06:57:10 +00:00
|
|
|
|
* a regular column id, or one of the following special values:
|
2014-02-02 06:07:39 +00:00
|
|
|
|
*
|
|
|
|
|
* - %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID: the default sort function
|
|
|
|
|
* will be used, if it is set
|
|
|
|
|
*
|
|
|
|
|
* - %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID: no sorting will occur
|
2009-01-03 06:57:10 +00:00
|
|
|
|
*/
|
2001-03-23 00:35:19 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int 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:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @sortable: A `GtkTreeSortable`
|
2001-09-04 22:15:18 +00:00
|
|
|
|
* @sort_column_id: the sort column id to set the function for
|
2005-07-25 13:55:31 +00:00
|
|
|
|
* @sort_func: The comparison function
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* @user_data: (closure): User data to pass to @sort_func
|
|
|
|
|
* @destroy: (nullable): Destroy notifier of @user_data
|
2001-09-04 22:15:18 +00:00
|
|
|
|
*
|
2009-01-03 06:57:10 +00:00
|
|
|
|
* 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 using this function.
|
|
|
|
|
*/
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column_id,
|
2001-09-04 22:15:18 +00:00
|
|
|
|
GtkTreeIterCompareFunc sort_func,
|
|
|
|
|
gpointer user_data,
|
2008-06-18 09:12:32 +00:00
|
|
|
|
GDestroyNotify destroy)
|
2001-03-23 00:35:19 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSortableIface *iface;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
|
2006-01-04 07:06:12 +00:00
|
|
|
|
g_return_if_fail (sort_func != NULL);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2002-01-02 23:51:03 +00:00
|
|
|
|
g_return_if_fail (sort_column_id >= 0);
|
2001-10-15 18:06:50 +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:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @sortable: A `GtkTreeSortable`
|
2005-07-25 13:55:31 +00:00
|
|
|
|
* @sort_func: The comparison function
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* @user_data: (closure): User data to pass to @sort_func
|
|
|
|
|
* @destroy: (nullable): Destroy notifier of @user_data
|
2001-09-04 22:15:18 +00:00
|
|
|
|
*
|
2005-07-25 13:55:31 +00:00
|
|
|
|
* Sets the default comparison function used when sorting to be @sort_func.
|
|
|
|
|
* If the current sort column id of @sortable is
|
|
|
|
|
* %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using
|
|
|
|
|
* this function.
|
2002-09-01 12:34:21 +00:00
|
|
|
|
*
|
|
|
|
|
* If @sort_func is %NULL, then there will be no default comparison function.
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* This means that once the model has been sorted, it can’t go back to the
|
2009-01-03 06:57:10 +00:00
|
|
|
|
* default state. In this case, when the current sort column id of @sortable
|
|
|
|
|
* is %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
|
|
|
|
|
*/
|
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,
|
2008-06-18 09:12:32 +00:00
|
|
|
|
GDestroyNotify destroy)
|
2001-09-03 23:37:39 +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_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:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @sortable: A `GtkTreeSortable`
|
2001-09-04 22:15:18 +00:00
|
|
|
|
*
|
2009-01-03 06:57:10 +00:00
|
|
|
|
* 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.
|
2001-09-04 22:15:18 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE, if the model has a default sort function
|
2009-01-03 06:57:10 +00:00
|
|
|
|
*/
|
2001-09-03 23:37:39 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeSortableIface *iface;
|
|
|
|
|
|
2001-09-18 22:49:02 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
|
2001-09-03 23:37:39 +00:00
|
|
|
|
|
|
|
|
|
iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
|
|
|
|
|
|
2001-09-18 22:49:02 +00:00
|
|
|
|
g_return_val_if_fail (iface != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (iface->has_default_sort_func != NULL, FALSE);
|
2001-09-03 23:37:39 +00:00
|
|
|
|
|
2001-09-18 22:49:02 +00:00
|
|
|
|
return (* iface->has_default_sort_func) (sortable);
|
2001-09-03 23:37:39 +00:00
|
|
|
|
}
|