<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
<!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
<!ENTITY pi "&#960;">
<!ENTITY solidus "&#8260;">
]>
<refentry id="GtkSorter">
<refmeta>
<refentrytitle role="top_of_page" id="GtkSorter.top_of_page">GtkSorter</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GTK4 Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>GtkSorter</refname>
<refpurpose>Sorting items</refpurpose>
</refnamediv>

<refsect1 id="GtkSorter.functions" role="functions_proto">
<title role="functions_proto.title">Functions</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="functions_proto_type" colwidth="150px"/>
<colspec colname="functions_proto_name"/>
<tbody>
<row><entry role="function_type"><link linkend="GtkOrdering"><returnvalue>GtkOrdering</returnvalue></link>
</entry><entry role="function_name"><link linkend="gtk-sorter-compare">gtk_sorter_compare</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GtkSorterOrder"><returnvalue>GtkSorterOrder</returnvalue></link>
</entry><entry role="function_name"><link linkend="gtk-sorter-get-order">gtk_sorter_get_order</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="gtk-sorter-changed">gtk_sorter_changed</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkSorter.signals" role="signal_proto">
<title role="signal_proto.title">Signals</title>
<informaltable frame="none">
<tgroup cols="3">
<colspec colname="signal_proto_type" colwidth="150px"/>
<colspec colname="signal_proto_name" colwidth="300px"/>
<colspec colname="signal_proto_flags" colwidth="200px"/>
<tbody>
<row><entry role="signal_type"><link linkend="void"><returnvalue>void</returnvalue></link></entry><entry role="signal_name"><link linkend="GtkSorter-changed">changed</link></entry><entry role="signal_flags"><link linkend="G-SIGNAL-RUN-LAST:CAPS">Run Last</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkSorter.other" role="other_proto">
<title role="other_proto.title">Types and Values</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="other_proto_type" colwidth="150px"/>
<colspec colname="other_proto_name"/>
<tbody>
<row><entry role="datatype_keyword"></entry><entry role="function_name"><link linkend="GtkSorter-struct">GtkSorter</link></entry></row>
<row><entry role="datatype_keyword">enum</entry><entry role="function_name"><link linkend="GtkSorterOrder">GtkSorterOrder</link></entry></row>
<row><entry role="datatype_keyword">enum</entry><entry role="function_name"><link linkend="GtkSorterChange">GtkSorterChange</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkSorter.object-hierarchy" role="object_hierarchy">
<title role="object_hierarchy.title">Object Hierarchy</title>
<screen>    <link linkend="GObject">GObject</link>
    <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> GtkSorter
        <phrase role="lineart">&#9500;&#9472;&#9472;</phrase> <link linkend="GtkCustomSorter">GtkCustomSorter</link>
        <phrase role="lineart">&#9500;&#9472;&#9472;</phrase> <link linkend="GtkMultiSorter">GtkMultiSorter</link>
        <phrase role="lineart">&#9500;&#9472;&#9472;</phrase> <link linkend="GtkNumericSorter">GtkNumericSorter</link>
        <phrase role="lineart">&#9500;&#9472;&#9472;</phrase> <link linkend="GtkStringSorter">GtkStringSorter</link>
        <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GtkTreeListRowSorter">GtkTreeListRowSorter</link>
</screen>
</refsect1>

<refsect1 id="GtkSorter.includes"><title>Includes</title><synopsis>#include &lt;gtk/gtk.h&gt;
</synopsis></refsect1>

<refsect1 id="GtkSorter.description" role="desc">
<title role="desc.title">Description</title>
<para><link linkend="GtkSorter"><type>GtkSorter</type></link> is the way to describe sorting criteria.
Its primary user is <link linkend="GtkSortListModel"><type>GtkSortListModel</type></link>.</para>
<para>The model will use a sorter to determine the order in which its items should appear
by calling <link linkend="gtk-sorter-compare"><function>gtk_sorter_compare()</function></link> for pairs of items.</para>
<para>Sorters may change their sorting behavior through their lifetime. In that case,
they will emit the <link linkend="GtkSorter-changed"><type>“changed”</type></link> signal to notify that the sort order is
no longer valid and should be updated by calling <link linkend="gtk-sorter-compare"><function>gtk_sorter_compare()</function></link> again.</para>
<para>GTK provides various pre-made sorter implementations for common sorting operations.
<link linkend="GtkColumnView"><type>GtkColumnView</type></link> has built-in support for sorting lists via the <link linkend="GtkColumnViewColumn--sorter"><type>“sorter”</type></link>
property, where the user can change the sorting by clicking on list headers.</para>
<para>Of course, in particular for large lists, it is also possible to subclass <link linkend="GtkSorter"><type>GtkSorter</type></link>
and provide one's own sorter.</para>

</refsect1>
<refsect1 id="GtkSorter.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="gtk-sorter-compare" role="function">
<title>gtk_sorter_compare&#160;()</title>
<indexterm zone="gtk-sorter-compare"><primary>gtk_sorter_compare</primary></indexterm>
<programlisting language="C"><link linkend="GtkOrdering"><returnvalue>GtkOrdering</returnvalue></link>
gtk_sorter_compare (<parameter><link linkend="GtkSorter"><type>GtkSorter</type></link> *self</parameter>,
                    <parameter><link linkend="gpointer"><type>gpointer</type></link> item1</parameter>,
                    <parameter><link linkend="gpointer"><type>gpointer</type></link> item2</parameter>);</programlisting>
<para>Compares two given items according to the sort order implemented
by the sorter.</para>
<para>Sorters implement a partial order:</para>
<itemizedlist>
<listitem><para>It is reflexive, ie a = a</para></listitem>
<listitem><para>It is antisymmetric, ie if a &lt; b and b &lt; a, then a = b</para></listitem>
<listitem>
<para>It is transitive, ie given any 3 items with a ≤ b and b ≤ c,
then a ≤ c</para>
</listitem>
</itemizedlist>
<para>The sorter  may signal it conforms to additional constraints
via the return value of <link linkend="gtk-sorter-get-order"><function>gtk_sorter_get_order()</function></link>.</para>
<refsect3 id="gtk-sorter-compare.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>self</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkSorter"><type>GtkSorter</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>item1</para></entry>
<entry role="parameter_description"><para>first item to compare. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>type</acronym> GObject][<acronym>transfer none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>item2</para></entry>
<entry role="parameter_description"><para>second item to compare. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>type</acronym> GObject][<acronym>transfer none</acronym>]</emphasis></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-sorter-compare.returns" role="returns">
<title>Returns</title>
<para> <link linkend="GTK-ORDERING-EQUAL:CAPS"><literal>GTK_ORDERING_EQUAL</literal></link> if <parameter>item1</parameter>
== <parameter>item2</parameter>
,
<link linkend="GTK-ORDERING-SMALLER:CAPS"><literal>GTK_ORDERING_SMALLER</literal></link> if <parameter>item1</parameter>
&lt; <parameter>item2</parameter>
,
<link linkend="GTK-ORDERING-LARGER:CAPS"><literal>GTK_ORDERING_LARGER</literal></link> if <parameter>item1</parameter>
&gt; <parameter>item2</parameter>
</para>
</refsect3></refsect2>
<refsect2 id="gtk-sorter-get-order" role="function">
<title>gtk_sorter_get_order&#160;()</title>
<indexterm zone="gtk-sorter-get-order"><primary>gtk_sorter_get_order</primary></indexterm>
<programlisting language="C"><link linkend="GtkSorterOrder"><returnvalue>GtkSorterOrder</returnvalue></link>
gtk_sorter_get_order (<parameter><link linkend="GtkSorter"><type>GtkSorter</type></link> *self</parameter>);</programlisting>
<para>Gets the order that <parameter>self</parameter>
 conforms to. See <link linkend="GtkSorterOrder"><type>GtkSorterOrder</type></link> for details
of the possible return values.</para>
<para>This function is intended to allow optimizations.</para>
<refsect3 id="gtk-sorter-get-order.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>self</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkSorter"><type>GtkSorter</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-sorter-get-order.returns" role="returns">
<title>Returns</title>
<para> The order</para>
</refsect3></refsect2>
<refsect2 id="gtk-sorter-changed" role="function">
<title>gtk_sorter_changed&#160;()</title>
<indexterm zone="gtk-sorter-changed"><primary>gtk_sorter_changed</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
gtk_sorter_changed (<parameter><link linkend="GtkSorter"><type>GtkSorter</type></link> *self</parameter>,
                    <parameter><link linkend="GtkSorterChange"><type>GtkSorterChange</type></link> change</parameter>);</programlisting>
<para>Emits the <link linkend="GtkSorter-changed"><type>“changed”</type></link> signal to notify all users of the sorter
that it has changed. Users of the sorter should then update the sort
order via <link linkend="gtk-sorter-compare"><function>gtk_sorter_compare()</function></link>.</para>
<para>Depending on the <parameter>change</parameter>
 parameter, it may be possible to update
the sort order without a full resorting. Refer to the <link linkend="GtkSorterChange"><type>GtkSorterChange</type></link>
documentation for details.</para>
<para>This function is intended for implementors of <link linkend="GtkSorter"><type>GtkSorter</type></link> subclasses and
should not be called from other functions.</para>
<refsect3 id="gtk-sorter-changed.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>self</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkSorter"><type>GtkSorter</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>change</para></entry>
<entry role="parameter_description"><para>How the sorter changed</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>

</refsect1>
<refsect1 id="GtkSorter.other_details" role="details">
<title role="details.title">Types and Values</title>
<refsect2 id="GtkSorter-struct" role="struct">
<title>GtkSorter</title>
<indexterm zone="GtkSorter-struct"><primary>GtkSorter</primary></indexterm>
<programlisting language="C">typedef struct _GtkSorter GtkSorter;</programlisting>
</refsect2>
<refsect2 id="GtkSorterOrder" role="enum">
<title>enum GtkSorterOrder</title>
<indexterm zone="GtkSorterOrder"><primary>GtkSorterOrder</primary></indexterm>
<para>Describes the type of order that a <link linkend="GtkSorter"><type>GtkSorter</type></link> may describe.</para>
<refsect3 id="GtkSorterOrder.members" role="enum_members">
<title>Members</title>
<informaltable role="enum_members_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="enum_members_name" colwidth="300px"/>
<colspec colname="enum_members_description"/>
<colspec colname="enum_members_annotations" colwidth="200px"/>
<tbody>
<row role="constant"><entry role="enum_member_name"><para id="GTK-SORTER-ORDER-PARTIAL:CAPS">GTK_SORTER_ORDER_PARTIAL</para></entry>
<entry role="enum_member_description"><para>A partial order. Any <link linkend="GtkOrdering"><type>GtkOrdering</type></link> is possible.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="GTK-SORTER-ORDER-NONE:CAPS">GTK_SORTER_ORDER_NONE</para></entry>
<entry role="enum_member_description"><para>No order, all elements are considered equal.
<link linkend="gtk-sorter-compare"><function>gtk_sorter_compare()</function></link> will only return <link linkend="GTK-ORDERING-EQUAL:CAPS"><literal>GTK_ORDERING_EQUAL</literal></link>.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="GTK-SORTER-ORDER-TOTAL:CAPS">GTK_SORTER_ORDER_TOTAL</para></entry>
<entry role="enum_member_description"><para>A total order. <link linkend="gtk-sorter-compare"><function>gtk_sorter_compare()</function></link> will only
return <link linkend="GTK-ORDERING-EQUAL:CAPS"><literal>GTK_ORDERING_EQUAL</literal></link> if an item is compared with itself. Two
different items will never cause this value to be returned.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="GtkSorterChange" role="enum">
<title>enum GtkSorterChange</title>
<indexterm zone="GtkSorterChange"><primary>GtkSorterChange</primary></indexterm>
<para>Describes changes in a sorter in more detail and allows users
to optimize resorting.</para>
<refsect3 id="GtkSorterChange.members" role="enum_members">
<title>Members</title>
<informaltable role="enum_members_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="enum_members_name" colwidth="300px"/>
<colspec colname="enum_members_description"/>
<colspec colname="enum_members_annotations" colwidth="200px"/>
<tbody>
<row role="constant"><entry role="enum_member_name"><para id="GTK-SORTER-CHANGE-DIFFERENT:CAPS">GTK_SORTER_CHANGE_DIFFERENT</para></entry>
<entry role="enum_member_description"><para>The sorter change cannot be described
by any of the other enumeration values</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="GTK-SORTER-CHANGE-INVERTED:CAPS">GTK_SORTER_CHANGE_INVERTED</para></entry>
<entry role="enum_member_description"><para>The sort order was inverted. Comparisons
that returned <link linkend="GTK-ORDERING-SMALLER:CAPS"><literal>GTK_ORDERING_SMALLER</literal></link> now return <link linkend="GTK-ORDERING-LARGER:CAPS"><literal>GTK_ORDERING_LARGER</literal></link>
and vice versa. Other comparisons return the same values as before.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="GTK-SORTER-CHANGE-LESS-STRICT:CAPS">GTK_SORTER_CHANGE_LESS_STRICT</para></entry>
<entry role="enum_member_description"><para>The sorter is less strict: Comparisons
may now return <link linkend="GTK-ORDERING-EQUAL:CAPS"><literal>GTK_ORDERING_EQUAL</literal></link> that did not do so before.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="GTK-SORTER-CHANGE-MORE-STRICT:CAPS">GTK_SORTER_CHANGE_MORE_STRICT</para></entry>
<entry role="enum_member_description"><para>The sorter is more strict: Comparisons
that did return <link linkend="GTK-ORDERING-EQUAL:CAPS"><literal>GTK_ORDERING_EQUAL</literal></link> may not do so anymore.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>

</refsect1>
<refsect1 id="GtkSorter.signal-details" role="signals">
<title role="signals.title">Signal Details</title>
<refsect2 id="GtkSorter-changed" role="signal"><title>The <literal>“changed”</literal> signal</title>
<indexterm zone="GtkSorter-changed"><primary>GtkSorter::changed</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
user_function (<link linkend="GtkSorter"><type>GtkSorter</type></link>      *self,
               <link linkend="GtkSorterChange"><type>GtkSorterChange</type></link> change,
               <link linkend="gpointer"><type>gpointer</type></link>        user_data)</programlisting>
<para>This signal is emitted whenever the sorter changed. Users of the sorter
should then update the sort order again via <link linkend="gtk-sorter-compare"><function>gtk_sorter_compare()</function></link>.</para>
<para><link linkend="GtkSortListModel"><type>GtkSortListModel</type></link> handles this signal automatically.</para>
<para>Depending on the <parameter>change</parameter>
 parameter, it may be possible to update
the sort order without a full resorting. Refer to the <link linkend="GtkSorterChange"><type>GtkSorterChange</type></link>
documentation for details.</para>
<refsect3 id="GtkSorter-changed.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>self</para></entry>
<entry role="parameter_description"><para>The <link linkend="GtkSorter"><type>GtkSorter</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>change</para></entry>
<entry role="parameter_description"><para>how the sorter changed</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><simpara>user_data</simpara></entry>
<entry role="parameter_description"><simpara>user data set when the signal handler was connected.</simpara></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para>Flags: <link linkend="G-SIGNAL-RUN-LAST:CAPS">Run Last</link></para>
</refsect2>
</refsect1>
<refsect1 id="GtkSorter.see-also">
<title>See Also</title>
<para><link linkend="GtkSortListModel"><type>GtkSortListModel</type></link></para>

</refsect1>

</refentry>
