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.gtk; 29 public import gtkc.gtktypes; 30 public import std.algorithm; 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(bool transferOwnership = false) 42 { 43 if (transferOwnership) 44 ownedRef = false; 45 return cast(GtkTreeSortable*)getStruct(); 46 } 47 48 49 /** 50 * Fills in @sort_column_id and @order with the current sort column and the 51 * order. It returns %TRUE unless the @sort_column_id is 52 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or 53 * %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID. 54 * 55 * Params: 56 * sortColumnId = The sort column id to be filled in 57 * order = The #GtkSortType to be filled in 58 * 59 * Returns: %TRUE if the sort column is not one of the special sort 60 * column ids. 61 */ 62 public bool getSortColumnId(out int sortColumnId, out GtkSortType order) 63 { 64 return gtk_tree_sortable_get_sort_column_id(getTreeSortableStruct(), &sortColumnId, &order) != 0; 65 } 66 67 /** 68 * Returns %TRUE if the model has a default sort function. This is used 69 * primarily by GtkTreeViewColumns in order to determine if a model can 70 * go back to the default state, or not. 71 * 72 * Returns: %TRUE, if the model has a default sort function 73 */ 74 public bool hasDefaultSortFunc() 75 { 76 return gtk_tree_sortable_has_default_sort_func(getTreeSortableStruct()) != 0; 77 } 78 79 /** 80 * Sets the default comparison function used when sorting to be @sort_func. 81 * If the current sort column id of @sortable is 82 * %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using 83 * this function. 84 * 85 * If @sort_func is %NULL, then there will be no default comparison function. 86 * This means that once the model has been sorted, it can’t go back to the 87 * default state. In this case, when the current sort column id of @sortable 88 * is %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted. 89 * 90 * Params: 91 * sortFunc = The comparison function 92 * userData = User data to pass to @sort_func, or %NULL 93 * destroy = Destroy notifier of @user_data, or %NULL 94 */ 95 public void setDefaultSortFunc(GtkTreeIterCompareFunc sortFunc, void* userData, GDestroyNotify destroy) 96 { 97 gtk_tree_sortable_set_default_sort_func(getTreeSortableStruct(), sortFunc, userData, destroy); 98 } 99 100 /** 101 * Sets the current sort column to be @sort_column_id. The @sortable will 102 * resort itself to reflect this change, after emitting a 103 * #GtkTreeSortable::sort-column-changed signal. @sort_column_id may either be 104 * a regular column id, or one of the following special values: 105 * 106 * - %GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID: the default sort function 107 * will be used, if it is set 108 * 109 * - %GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID: no sorting will occur 110 * 111 * Params: 112 * sortColumnId = the sort column id to set 113 * order = The sort order of the column 114 */ 115 public void setSortColumnId(int sortColumnId, GtkSortType order) 116 { 117 gtk_tree_sortable_set_sort_column_id(getTreeSortableStruct(), sortColumnId, order); 118 } 119 120 /** 121 * Sets the comparison function used when sorting to be @sort_func. If the 122 * current sort column id of @sortable is the same as @sort_column_id, then 123 * the model will sort using this function. 124 * 125 * Params: 126 * sortColumnId = the sort column id to set the function for 127 * sortFunc = The comparison function 128 * userData = User data to pass to @sort_func, or %NULL 129 * destroy = Destroy notifier of @user_data, or %NULL 130 */ 131 public void setSortFunc(int sortColumnId, GtkTreeIterCompareFunc sortFunc, void* userData, GDestroyNotify destroy) 132 { 133 gtk_tree_sortable_set_sort_func(getTreeSortableStruct(), sortColumnId, sortFunc, userData, destroy); 134 } 135 136 /** 137 * Emits a #GtkTreeSortable::sort-column-changed signal on @sortable. 138 */ 139 public void sortColumnChanged() 140 { 141 gtk_tree_sortable_sort_column_changed(getTreeSortableStruct()); 142 } 143 144 protected class OnSortColumnChangedDelegateWrapper 145 { 146 static OnSortColumnChangedDelegateWrapper[] listeners; 147 void delegate(TreeSortableIF) dlg; 148 gulong handlerId; 149 150 this(void delegate(TreeSortableIF) dlg) 151 { 152 this.dlg = dlg; 153 this.listeners ~= this; 154 } 155 156 void remove(OnSortColumnChangedDelegateWrapper source) 157 { 158 foreach(index, wrapper; listeners) 159 { 160 if (wrapper.handlerId == source.handlerId) 161 { 162 listeners[index] = null; 163 listeners = std.algorithm.remove(listeners, index); 164 break; 165 } 166 } 167 } 168 } 169 170 /** 171 * The ::sort-column-changed signal is emitted when the sort column 172 * or sort order of @sortable is changed. The signal is emitted before 173 * the contents of @sortable are resorted. 174 */ 175 gulong addOnSortColumnChanged(void delegate(TreeSortableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 176 { 177 auto wrapper = new OnSortColumnChangedDelegateWrapper(dlg); 178 wrapper.handlerId = Signals.connectData( 179 this, 180 "sort-column-changed", 181 cast(GCallback)&callBackSortColumnChanged, 182 cast(void*)wrapper, 183 cast(GClosureNotify)&callBackSortColumnChangedDestroy, 184 connectFlags); 185 return wrapper.handlerId; 186 } 187 188 extern(C) static void callBackSortColumnChanged(GtkTreeSortable* treesortableStruct, OnSortColumnChangedDelegateWrapper wrapper) 189 { 190 wrapper.dlg(wrapper.outer); 191 } 192 193 extern(C) static void callBackSortColumnChangedDestroy(OnSortColumnChangedDelegateWrapper wrapper, GClosure* closure) 194 { 195 wrapper.remove(wrapper); 196 } 197 }