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() 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 * Returns: %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 * Returns: %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 protected class OnSortColumnChangedDelegateWrapper 143 { 144 static OnSortColumnChangedDelegateWrapper[] listeners; 145 void delegate(TreeSortableIF) dlg; 146 gulong handlerId; 147 148 this(void delegate(TreeSortableIF) dlg) 149 { 150 this.dlg = dlg; 151 this.listeners ~= this; 152 } 153 154 void remove(OnSortColumnChangedDelegateWrapper source) 155 { 156 foreach(index, wrapper; listeners) 157 { 158 if (wrapper.handlerId == source.handlerId) 159 { 160 listeners[index] = null; 161 listeners = std.algorithm.remove(listeners, index); 162 break; 163 } 164 } 165 } 166 } 167 168 /** 169 * The ::sort-column-changed signal is emitted when the sort column 170 * or sort order of @sortable is changed. The signal is emitted before 171 * the contents of @sortable are resorted. 172 */ 173 gulong addOnSortColumnChanged(void delegate(TreeSortableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 174 { 175 auto wrapper = new OnSortColumnChangedDelegateWrapper(dlg); 176 wrapper.handlerId = Signals.connectData( 177 this, 178 "sort-column-changed", 179 cast(GCallback)&callBackSortColumnChanged, 180 cast(void*)wrapper, 181 cast(GClosureNotify)&callBackSortColumnChangedDestroy, 182 connectFlags); 183 return wrapper.handlerId; 184 } 185 186 extern(C) static void callBackSortColumnChanged(GtkTreeSortable* treesortableStruct, OnSortColumnChangedDelegateWrapper wrapper) 187 { 188 wrapper.dlg(wrapper.outer); 189 } 190 191 extern(C) static void callBackSortColumnChangedDestroy(OnSortColumnChangedDelegateWrapper wrapper, GClosure* closure) 192 { 193 wrapper.remove(wrapper); 194 } 195 }