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.TreeSortableT;
26 
27 public  import gobject.Signals;
28 public  import gtkc.gdktypes;
29 public  import gtkc.gtk;
30 public  import gtkc.gtktypes;
31 
32 
33 /**
34  * #GtkTreeSortable is an interface to be implemented by tree models which
35  * support sorting. The #GtkTreeView uses the methods provided by this interface
36  * to sort the model.
37  */
38 public template TreeSortableT(TStruct)
39 {
40 	/** Get the main Gtk struct */
41 	public GtkTreeSortable* getTreeSortableStruct()
42 	{
43 		return cast(GtkTreeSortable*)getStruct();
44 	}
45 
46 
47 	/**
48 	 * Fills in @sort_column_id and @order with the current sort column and the
49 	 * order. It returns %TRUE unless the @sort_column_id is
50 	 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or
51 	 * %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID.
52 	 *
53 	 * Params:
54 	 *     sortColumnId = The sort column id to be filled in
55 	 *     order = The #GtkSortType to be filled in
56 	 *
57 	 * Return: %TRUE if the sort column is not one of the special sort
58 	 *     column ids.
59 	 */
60 	public bool getSortColumnId(out int sortColumnId, out GtkSortType order)
61 	{
62 		return gtk_tree_sortable_get_sort_column_id(getTreeSortableStruct(), &sortColumnId, &order) != 0;
63 	}
64 
65 	/**
66 	 * Returns %TRUE if the model has a default sort function. This is used
67 	 * primarily by GtkTreeViewColumns in order to determine if a model can
68 	 * go back to the default state, or not.
69 	 *
70 	 * Return: %TRUE, if the model has a default sort function
71 	 */
72 	public bool hasDefaultSortFunc()
73 	{
74 		return gtk_tree_sortable_has_default_sort_func(getTreeSortableStruct()) != 0;
75 	}
76 
77 	/**
78 	 * Sets the default comparison function used when sorting to be @sort_func.
79 	 * If the current sort column id of @sortable is
80 	 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using
81 	 * this function.
82 	 *
83 	 * If @sort_func is %NULL, then there will be no default comparison function.
84 	 * This means that once the model  has been sorted, it can’t go back to the
85 	 * default state. In this case, when the current sort column id of @sortable
86 	 * is %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted.
87 	 *
88 	 * Params:
89 	 *     sortFunc = The comparison function
90 	 *     userData = User data to pass to @sort_func, or %NULL
91 	 *     destroy = Destroy notifier of @user_data, or %NULL
92 	 */
93 	public void setDefaultSortFunc(GtkTreeIterCompareFunc sortFunc, void* userData, GDestroyNotify destroy)
94 	{
95 		gtk_tree_sortable_set_default_sort_func(getTreeSortableStruct(), sortFunc, userData, destroy);
96 	}
97 
98 	/**
99 	 * Sets the current sort column to be @sort_column_id. The @sortable will
100 	 * resort itself to reflect this change, after emitting a
101 	 * #GtkTreeSortable::sort-column-changed signal. @sort_column_id may either be
102 	 * a regular column id, or one of the following special values:
103 	 *
104 	 * - %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID: the default sort function
105 	 * will be used, if it is set
106 	 *
107 	 * - %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID: no sorting will occur
108 	 *
109 	 * Params:
110 	 *     sortColumnId = the sort column id to set
111 	 *     order = The sort order of the column
112 	 */
113 	public void setSortColumnId(int sortColumnId, GtkSortType order)
114 	{
115 		gtk_tree_sortable_set_sort_column_id(getTreeSortableStruct(), sortColumnId, order);
116 	}
117 
118 	/**
119 	 * Sets the comparison function used when sorting to be @sort_func. If the
120 	 * current sort column id of @sortable is the same as @sort_column_id, then
121 	 * the model will sort using this function.
122 	 *
123 	 * Params:
124 	 *     sortColumnId = the sort column id to set the function for
125 	 *     sortFunc = The comparison function
126 	 *     userData = User data to pass to @sort_func, or %NULL
127 	 *     destroy = Destroy notifier of @user_data, or %NULL
128 	 */
129 	public void setSortFunc(int sortColumnId, GtkTreeIterCompareFunc sortFunc, void* userData, GDestroyNotify destroy)
130 	{
131 		gtk_tree_sortable_set_sort_func(getTreeSortableStruct(), sortColumnId, sortFunc, userData, destroy);
132 	}
133 
134 	/**
135 	 * Emits a #GtkTreeSortable::sort-column-changed signal on @sortable.
136 	 */
137 	public void sortColumnChanged()
138 	{
139 		gtk_tree_sortable_sort_column_changed(getTreeSortableStruct());
140 	}
141 
142 	int[string] connectedSignals;
143 
144 	void delegate(TreeSortableIF)[] _onSortColumnChangedListeners;
145 	@property void delegate(TreeSortableIF)[] onSortColumnChangedListeners()
146 	{
147 		return _onSortColumnChangedListeners;
148 	}
149 	/**
150 	 * The ::sort-column-changed signal is emitted when the sort column
151 	 * or sort order of @sortable is changed. The signal is emitted before
152 	 * the contents of @sortable are resorted.
153 	 */
154 	void addOnSortColumnChanged(void delegate(TreeSortableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
155 	{
156 		if ( "sort-column-changed" !in connectedSignals )
157 		{
158 			Signals.connectData(
159 				this,
160 				"sort-column-changed",
161 				cast(GCallback)&callBackSortColumnChanged,
162 				cast(void*)cast(TreeSortableIF)this,
163 				null,
164 				connectFlags);
165 			connectedSignals["sort-column-changed"] = 1;
166 		}
167 		_onSortColumnChangedListeners ~= dlg;
168 	}
169 	extern(C) static void callBackSortColumnChanged(GtkTreeSortable* treesortableStruct, TreeSortableIF _treesortable)
170 	{
171 		foreach ( void delegate(TreeSortableIF) dlg; _treesortable.onSortColumnChangedListeners )
172 		{
173 			dlg(_treesortable);
174 		}
175 	}
176 }