Blame gtk/gtktreesortable.c

Packit Service fb6fa5
/* gtktreesortable.c
Packit Service fb6fa5
 * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Library General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Library General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Library General Public
Packit Service fb6fa5
 * License along with this library; if not, write to the
Packit Service fb6fa5
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service fb6fa5
 * Boston, MA 02111-1307, USA.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
#include "config.h"
Packit Service fb6fa5
#include "gtktreesortable.h"
Packit Service fb6fa5
#include "gtkmarshalers.h"
Packit Service fb6fa5
#include "gtkintl.h"
Packit Service fb6fa5
#include "gtkalias.h"
Packit Service fb6fa5
Packit Service fb6fa5
static void gtk_tree_sortable_base_init (gpointer g_class);
Packit Service fb6fa5
Packit Service fb6fa5
GType
Packit Service fb6fa5
gtk_tree_sortable_get_type (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  static GType tree_sortable_type = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  if (! tree_sortable_type)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      const GTypeInfo tree_sortable_info =
Packit Service fb6fa5
      {
Packit Service fb6fa5
	sizeof (GtkTreeSortableIface), /* class_size */
Packit Service fb6fa5
	gtk_tree_sortable_base_init,   /* base_init */
Packit Service fb6fa5
	NULL,		/* base_finalize */
Packit Service fb6fa5
	NULL,
Packit Service fb6fa5
	NULL,		/* class_finalize */
Packit Service fb6fa5
	NULL,		/* class_data */
Packit Service fb6fa5
	0,
Packit Service fb6fa5
	0,
Packit Service fb6fa5
	NULL
Packit Service fb6fa5
      };
Packit Service fb6fa5
Packit Service fb6fa5
      tree_sortable_type =
Packit Service fb6fa5
	g_type_register_static (G_TYPE_INTERFACE, I_("GtkTreeSortable"),
Packit Service fb6fa5
				&tree_sortable_info, 0);
Packit Service fb6fa5
Packit Service fb6fa5
      g_type_interface_add_prerequisite (tree_sortable_type, GTK_TYPE_TREE_MODEL);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return tree_sortable_type;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_tree_sortable_base_init (gpointer g_class)
Packit Service fb6fa5
{
Packit Service fb6fa5
  static gboolean initialized = FALSE;
Packit Service fb6fa5
Packit Service fb6fa5
  if (! initialized)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      /**
Packit Service fb6fa5
       * GtkTreeSortable::sort-column-changed:
Packit Service fb6fa5
       * @sortable: the object on which the signal is emitted
Packit Service fb6fa5
       *
Packit Service fb6fa5
       * The ::sort-column-changed signal is emitted when the sort column
Packit Service fb6fa5
       * or sort order of @sortable is changed. The signal is emitted before
Packit Service fb6fa5
       * the contents of @sortable are resorted.
Packit Service fb6fa5
       */
Packit Service fb6fa5
      g_signal_new (I_("sort-column-changed"),
Packit Service fb6fa5
                    GTK_TYPE_TREE_SORTABLE,
Packit Service fb6fa5
                    G_SIGNAL_RUN_LAST,
Packit Service fb6fa5
                    G_STRUCT_OFFSET (GtkTreeSortableIface, sort_column_changed),
Packit Service fb6fa5
                    NULL, NULL,
Packit Service fb6fa5
                    _gtk_marshal_VOID__VOID,
Packit Service fb6fa5
                    G_TYPE_NONE, 0);
Packit Service fb6fa5
      initialized = TRUE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_tree_sortable_sort_column_changed:
Packit Service fb6fa5
 * @sortable: A #GtkTreeSortable
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Emits a #GtkTreeSortable::sort-column-changed signal on @sortable.
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_emit_by_name (sortable, "sort-column-changed");
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_tree_sortable_get_sort_column_id:
Packit Service fb6fa5
 * @sortable: A #GtkTreeSortable
Packit Service fb6fa5
 * @sort_column_id: The sort column id to be filled in
Packit Service fb6fa5
 * @order: The #GtkSortType to be filled in
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Fills in @sort_column_id and @order with the current sort column and the
Packit Service fb6fa5
 * order. It returns %TRUE unless the @sort_column_id is 
Packit Service fb6fa5
 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or 
Packit Service fb6fa5
 * %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: %TRUE if the sort column is not one of the special sort
Packit Service fb6fa5
 *   column ids.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_tree_sortable_get_sort_column_id (GtkTreeSortable  *sortable,
Packit Service fb6fa5
				      gint             *sort_column_id,
Packit Service fb6fa5
				      GtkSortType      *order)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkTreeSortableIface *iface;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (iface != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (iface->get_sort_column_id != NULL, FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  return (* iface->get_sort_column_id) (sortable, sort_column_id, order);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_tree_sortable_set_sort_column_id:
Packit Service fb6fa5
 * @sortable: A #GtkTreeSortable
Packit Service fb6fa5
 * @sort_column_id: the sort column id to set
Packit Service fb6fa5
 * @order: The sort order of the column
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Sets the current sort column to be @sort_column_id. The @sortable will
Packit Service fb6fa5
 * resort itself to reflect this change, after emitting a
Packit Service fb6fa5
 * #GtkTreeSortable::sort-column-changed signal. @sort_column_id may either be
Packit Service fb6fa5
 * a regular column id, or one of the following special values:
Packit Service fb6fa5
 * <variablelist>
Packit Service fb6fa5
 * <varlistentry>
Packit Service fb6fa5
 *   <term>%GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID</term>
Packit Service fb6fa5
 *   <listitem>the default sort function will be used, if it is set</listitem>
Packit Service fb6fa5
 * </varlistentry>
Packit Service fb6fa5
 * <varlistentry>
Packit Service fb6fa5
 *   <term>%GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID</term>
Packit Service fb6fa5
 *   <listitem>no sorting will occur</listitem>
Packit Service fb6fa5
 * </varlistentry>
Packit Service fb6fa5
 * </variablelist>
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_tree_sortable_set_sort_column_id (GtkTreeSortable  *sortable,
Packit Service fb6fa5
				      gint              sort_column_id,
Packit Service fb6fa5
				      GtkSortType       order)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkTreeSortableIface *iface;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
Packit Service fb6fa5
Packit Service fb6fa5
  iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (iface != NULL);
Packit Service fb6fa5
  g_return_if_fail (iface->set_sort_column_id != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  (* iface->set_sort_column_id) (sortable, sort_column_id, order);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_tree_sortable_set_sort_func:
Packit Service fb6fa5
 * @sortable: A #GtkTreeSortable
Packit Service fb6fa5
 * @sort_column_id: the sort column id to set the function for
Packit Service fb6fa5
 * @sort_func: The comparison function
Packit Service fb6fa5
 * @user_data: (allow-none): User data to pass to @sort_func, or %NULL
Packit Service fb6fa5
 * @destroy: (allow-none): Destroy notifier of @user_data, or %NULL
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Sets the comparison function used when sorting to be @sort_func. If the
Packit Service fb6fa5
 * current sort column id of @sortable is the same as @sort_column_id, then 
Packit Service fb6fa5
 * the model will sort using this function.
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_tree_sortable_set_sort_func (GtkTreeSortable        *sortable,
Packit Service fb6fa5
				 gint                    sort_column_id,
Packit Service fb6fa5
				 GtkTreeIterCompareFunc  sort_func,
Packit Service fb6fa5
				 gpointer                user_data,
Packit Service fb6fa5
				 GDestroyNotify          destroy)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkTreeSortableIface *iface;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
Packit Service fb6fa5
  g_return_if_fail (sort_func != NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (iface != NULL);
Packit Service fb6fa5
  g_return_if_fail (iface->set_sort_func != NULL);
Packit Service fb6fa5
  g_return_if_fail (sort_column_id >= 0);
Packit Service fb6fa5
Packit Service fb6fa5
  (* iface->set_sort_func) (sortable, sort_column_id, sort_func, user_data, destroy);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_tree_sortable_set_default_sort_func:
Packit Service fb6fa5
 * @sortable: A #GtkTreeSortable
Packit Service fb6fa5
 * @sort_func: The comparison function
Packit Service fb6fa5
 * @user_data: (allow-none): User data to pass to @sort_func, or %NULL
Packit Service fb6fa5
 * @destroy: (allow-none): Destroy notifier of @user_data, or %NULL
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Sets the default comparison function used when sorting to be @sort_func.  
Packit Service fb6fa5
 * If the current sort column id of @sortable is
Packit Service fb6fa5
 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using 
Packit Service fb6fa5
 * this function.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * If @sort_func is %NULL, then there will be no default comparison function.
Packit Service fb6fa5
 * This means that once the model  has been sorted, it can't go back to the
Packit Service fb6fa5
 * default state. In this case, when the current sort column id of @sortable 
Packit Service fb6fa5
 * is %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_tree_sortable_set_default_sort_func (GtkTreeSortable        *sortable,
Packit Service fb6fa5
					 GtkTreeIterCompareFunc  sort_func,
Packit Service fb6fa5
					 gpointer                user_data,
Packit Service fb6fa5
					 GDestroyNotify          destroy)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkTreeSortableIface *iface;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
Packit Service fb6fa5
Packit Service fb6fa5
  iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (iface != NULL);
Packit Service fb6fa5
  g_return_if_fail (iface->set_default_sort_func != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  (* iface->set_default_sort_func) (sortable, sort_func, user_data, destroy);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_tree_sortable_has_default_sort_func:
Packit Service fb6fa5
 * @sortable: A #GtkTreeSortable
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Returns %TRUE if the model has a default sort function. This is used
Packit Service fb6fa5
 * primarily by GtkTreeViewColumns in order to determine if a model can 
Packit Service fb6fa5
 * go back to the default state, or not.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: %TRUE, if the model has a default sort function
Packit Service fb6fa5
 */
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkTreeSortableIface *iface;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_TREE_SORTABLE (sortable), FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (iface != NULL, FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (iface->has_default_sort_func != NULL, FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return (* iface->has_default_sort_func) (sortable);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
#define __GTK_TREE_SORTABLE_C__
Packit Service fb6fa5
#include "gtkaliasdef.c"