1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.Sorter;
26 
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gtk.c.functions;
30 public  import gtk.c.types;
31 private import std.algorithm;
32 
33 
34 /**
35  * `GtkSorter` is an object to describe sorting criteria.
36  * 
37  * Its primary user is [class@Gtk.SortListModel]
38  * 
39  * The model will use a sorter to determine the order in which
40  * its items should appear by calling [method@Gtk.Sorter.compare]
41  * for pairs of items.
42  * 
43  * Sorters may change their sorting behavior through their lifetime.
44  * In that case, they will emit the [signal@Gtk.Sorter::changed] signal
45  * to notify that the sort order is no longer valid and should be updated
46  * by calling gtk_sorter_compare() again.
47  * 
48  * GTK provides various pre-made sorter implementations for common sorting
49  * operations. [class@Gtk.ColumnView] has built-in support for sorting lists
50  * via the [property@Gtk.ColumnViewColumn:sorter] property, where the user can
51  * change the sorting by clicking on list headers.
52  * 
53  * Of course, in particular for large lists, it is also possible to subclass
54  * `GtkSorter` and provide one's own sorter.
55  */
56 public class Sorter : ObjectG
57 {
58 	/** the main Gtk struct */
59 	protected GtkSorter* gtkSorter;
60 
61 	/** Get the main Gtk struct */
62 	public GtkSorter* getSorterStruct(bool transferOwnership = false)
63 	{
64 		if (transferOwnership)
65 			ownedRef = false;
66 		return gtkSorter;
67 	}
68 
69 	/** the main Gtk struct as a void* */
70 	protected override void* getStruct()
71 	{
72 		return cast(void*)gtkSorter;
73 	}
74 
75 	/**
76 	 * Sets our main struct and passes it to the parent class.
77 	 */
78 	public this (GtkSorter* gtkSorter, bool ownedRef = false)
79 	{
80 		this.gtkSorter = gtkSorter;
81 		super(cast(GObject*)gtkSorter, ownedRef);
82 	}
83 
84 
85 	/** */
86 	public static GType getType()
87 	{
88 		return gtk_sorter_get_type();
89 	}
90 
91 	/**
92 	 * Emits the [signal@Gtk.Sorter::changed] signal to notify all users
93 	 * of the sorter that it has changed.
94 	 *
95 	 * Users of the sorter should then update the sort order via
96 	 * gtk_sorter_compare().
97 	 *
98 	 * Depending on the @change parameter, it may be possible to update
99 	 * the sort order without a full resorting. Refer to the
100 	 * [enum@Gtk.SorterChange] documentation for details.
101 	 *
102 	 * This function is intended for implementors of `GtkSorter`
103 	 * subclasses and should not be called from other functions.
104 	 *
105 	 * Params:
106 	 *     change = How the sorter changed
107 	 */
108 	public void changed(GtkSorterChange change)
109 	{
110 		gtk_sorter_changed(gtkSorter, change);
111 	}
112 
113 	/**
114 	 * Compares two given items according to the sort order implemented
115 	 * by the sorter.
116 	 *
117 	 * Sorters implement a partial order:
118 	 *
119 	 * * It is reflexive, ie a = a
120 	 * * It is antisymmetric, ie if a < b and b < a, then a = b
121 	 * * It is transitive, ie given any 3 items with a ≤ b and b ≤ c,
122 	 * then a ≤ c
123 	 *
124 	 * The sorter may signal it conforms to additional constraints
125 	 * via the return value of [method@Gtk.Sorter.get_order].
126 	 *
127 	 * Params:
128 	 *     item1 = first item to compare
129 	 *     item2 = second item to compare
130 	 *
131 	 * Returns: %GTK_ORDERING_EQUAL if @item1 == @item2,
132 	 *     %GTK_ORDERING_SMALLER if @item1 < @item2,
133 	 *     %GTK_ORDERING_LARGER if @item1 > @item2
134 	 */
135 	public GtkOrdering compare(ObjectG item1, ObjectG item2)
136 	{
137 		return gtk_sorter_compare(gtkSorter, (item1 is null) ? null : item1.getObjectGStruct(), (item2 is null) ? null : item2.getObjectGStruct());
138 	}
139 
140 	/**
141 	 * Gets the order that @self conforms to.
142 	 *
143 	 * See [enum@Gtk.SorterOrder] for details
144 	 * of the possible return values.
145 	 *
146 	 * This function is intended to allow optimizations.
147 	 *
148 	 * Returns: The order
149 	 */
150 	public GtkSorterOrder getOrder()
151 	{
152 		return gtk_sorter_get_order(gtkSorter);
153 	}
154 
155 	/**
156 	 * Emitted whenever the sorter changed.
157 	 *
158 	 * Users of the sorter should then update the sort order
159 	 * again via gtk_sorter_compare().
160 	 *
161 	 * [class@Gtk.SortListModel] handles this signal automatically.
162 	 *
163 	 * Depending on the @change parameter, it may be possible to update
164 	 * the sort order without a full resorting. Refer to the
165 	 * [enum@Gtk.SorterChange] documentation for details.
166 	 *
167 	 * Params:
168 	 *     change = how the sorter changed
169 	 */
170 	gulong addOnChanged(void delegate(GtkSorterChange, Sorter) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
171 	{
172 		return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
173 	}
174 }