GTK+ Reference Manual
<<< Prev | Home | Up | Next >>>

# GtkTreeSortable

GtkTreeSortable —

##

# Synopsis

    #include <gtk/gtk.h>

    struct      GtkTreeSortable;
    struct      GtkTreeSortableIface;
    gint        (*GtkTreeIterCompareFunc)       (GtkTreeModel *model,
                                                 GtkTreeIter *a,
                                                 GtkTreeIter *b,
                                                 gpointer user_data);
    void        gtk_tree_sortable_sort_column_changed
                                                (GtkTreeSortable *sortable);
    gboolean    gtk_tree_sortable_get_sort_column_id
                                                (GtkTreeSortable *sortable,
                                                 gint *sort_column_id,
                                                 GtkSortType *order);
    void        gtk_tree_sortable_set_sort_column_id
                                                (GtkTreeSortable *sortable,
                                                 gint sort_column_id,
                                                 GtkSortType order);
    void        gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
                                                 gint sort_column_id,
                                                 GtkTreeIterCompareFunc sort_func,
                                                 gpointer user_data,
                                                 GtkDestroyNotify destroy);
    void        gtk_tree_sortable_set_default_sort_func
                                                (GtkTreeSortable *sortable,
                                                 GtkTreeIterCompareFunc sort_func,
                                                 gpointer user_data,
                                                 GtkDestroyNotify destroy);
    gboolean    gtk_tree_sortable_has_default_sort_func
                                                (GtkTreeSortable *sortable);

## Signal Prototypes

    "sort-column-changed"
                void        user_function      (GtkTreeSortable *treesortable,
                                                gpointer user_data);

## Description

## Details

### struct GtkTreeSortable

    struct GtkTreeSortable;

### struct GtkTreeSortableIface

    struct GtkTreeSortableIface
    {
      GTypeInterface g_iface;

      /* signals */
      void     (* sort_column_changed)   (GtkTreeSortable        *sortable);

      /* virtual table */
      gboolean (* get_sort_column_id)    (GtkTreeSortable        *sortable,
    				      gint                   *sort_column_id,
    				      GtkSortType            *order);
      void     (* set_sort_column_id)    (GtkTreeSortable        *sortable,
    				      gint                    sort_column_id,
    				      GtkSortType             order);
      void     (* set_sort_func)         (GtkTreeSortable        *sortable,
    				      gint                    sort_column_id,
    				      GtkTreeIterCompareFunc  func,
    				      gpointer                data,
    				      GtkDestroyNotify        destroy);
      void     (* set_default_sort_func) (GtkTreeSortable        *sortable,
    				      GtkTreeIterCompareFunc  func,
    				      gpointer                data,
    				      GtkDestroyNotify        destroy);
      gboolean (* has_default_sort_func) (GtkTreeSortable        *sortable);
    };

### GtkTreeIterCompareFunc ()

    gint        (*GtkTreeIterCompareFunc)       (GtkTreeModel *model,
                                                 GtkTreeIter *a,
                                                 GtkTreeIter *b,
                                                 gpointer user_data);

`model` : |
`a` : |
`b` : |
`user_data` : |
Returns : |

### gtk_tree_sortable_sort_column_changed ()

    void        gtk_tree_sortable_sort_column_changed
                                                (GtkTreeSortable *sortable);

Emits a GtkTreeSortable::sort_column_changed signal on

`sortable` : | A GtkTreeSortable

### gtk_tree_sortable_get_sort_column_id ()

    gboolean    gtk_tree_sortable_get_sort_column_id
                                                (GtkTreeSortable *sortable,
                                                 gint *sort_column_id,
                                                 GtkSortType *order);

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.

`sortable` : | A GtkTreeSortable
`sort_column_id` : | The sort column id to be filled in
`order` : | The GtkSortType to be filled in
Returns : | `TRUE`, if the sort column has been set

### gtk_tree_sortable_set_sort_column_id ()

    void        gtk_tree_sortable_set_sort_column_id
                                                (GtkTreeSortable *sortable,
                                                 gint sort_column_id,
                                                 GtkSortType order);

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 `GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID`, then the default sort function will be used, if it is set.

`sortable` : | A GtkTreeSortable
`sort_column_id` : | the sort column id to set
`order` : | The sort order of the column

### gtk_tree_sortable_set_sort_func ()

    void        gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
                                                 gint sort_column_id,
                                                 GtkTreeIterCompareFunc sort_func,
                                                 gpointer user_data,
                                                 GtkDestroyNotify destroy);

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.

`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`

### gtk_tree_sortable_set_default_sort_func ()

    void        gtk_tree_sortable_set_default_sort_func
                                                (GtkTreeSortable *sortable,
                                                 GtkTreeIterCompareFunc sort_func,
                                                 gpointer user_data,
                                                 GtkDestroyNotify destroy);

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. If `sort_func` is `NULL`, then the default sort_func, and there will be no default sort_func. In this case, the model is unsorted.

`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`

### gtk_tree_sortable_has_default_sort_func ()

    gboolean    gtk_tree_sortable_has_default_sort_func
                                                (GtkTreeSortable *sortable);

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.

`sortable` : | A GtkTreeSortable
Returns : | `TRUE`, if the model has a default sort function

## Signals

### The "sort-column-changed" signal

    void        user_function                  (GtkTreeSortable *treesortable,
                                                gpointer user_data);

`treesortable` : | the object which received the signal.
`user_data` : | user data set when the signal handler was connected.

<<< Prev | Home | Up | Next >>>
GtkTreeView drag-and-drop | GtkTreeModelSort