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 gio.ListStore; 26 27 private import gio.ListModelIF; 28 private import gio.ListModelT; 29 private import gio.c.functions; 30 public import gio.c.types; 31 private import glib.ConstructionException; 32 private import gobject.ObjectG; 33 34 35 /** 36 * #GListStore is a simple implementation of #GListModel that stores all 37 * items in memory. 38 * 39 * It provides insertions, deletions, and lookups in logarithmic time 40 * with a fast path for the common case of iterating the list linearly. 41 */ 42 public class ListStore : ObjectG, ListModelIF 43 { 44 /** the main Gtk struct */ 45 protected GListStore* gListStore; 46 47 /** Get the main Gtk struct */ 48 public GListStore* getListStoreStruct(bool transferOwnership = false) 49 { 50 if (transferOwnership) 51 ownedRef = false; 52 return gListStore; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected override void* getStruct() 57 { 58 return cast(void*)gListStore; 59 } 60 61 /** 62 * Sets our main struct and passes it to the parent class. 63 */ 64 public this (GListStore* gListStore, bool ownedRef = false) 65 { 66 this.gListStore = gListStore; 67 super(cast(GObject*)gListStore, ownedRef); 68 } 69 70 // add the ListModel capabilities 71 mixin ListModelT!(GListStore); 72 73 74 /** */ 75 public static GType getType() 76 { 77 return g_list_store_get_type(); 78 } 79 80 /** 81 * Creates a new #GListStore with items of type @item_type. @item_type 82 * must be a subclass of #GObject. 83 * 84 * Params: 85 * itemType = the #GType of items in the list 86 * 87 * Returns: a new #GListStore 88 * 89 * Since: 2.44 90 * 91 * Throws: ConstructionException GTK+ fails to create the object. 92 */ 93 public this(GType itemType) 94 { 95 auto __p = g_list_store_new(itemType); 96 97 if(__p is null) 98 { 99 throw new ConstructionException("null returned by new"); 100 } 101 102 this(cast(GListStore*) __p, true); 103 } 104 105 /** 106 * Appends @item to @store. @item must be of type #GListStore:item-type. 107 * 108 * This function takes a ref on @item. 109 * 110 * Use g_list_store_splice() to append multiple items at the same time 111 * efficiently. 112 * 113 * Params: 114 * item = the new item 115 * 116 * Since: 2.44 117 */ 118 public void append(ObjectG item) 119 { 120 g_list_store_append(gListStore, (item is null) ? null : item.getObjectGStruct()); 121 } 122 123 /** 124 * Looks up the given @item in the list store by looping over the items until 125 * the first occurrence of @item. If @item was not found, then @position will 126 * not be set, and this method will return %FALSE. 127 * 128 * If you need to compare the two items with a custom comparison function, use 129 * g_list_store_find_with_equal_func() with a custom #GEqualFunc instead. 130 * 131 * Params: 132 * item = an item 133 * position = the first position of @item, if it was found. 134 * 135 * Returns: Whether @store contains @item. If it was found, @position will be 136 * set to the position where @item occurred for the first time. 137 * 138 * Since: 2.64 139 */ 140 public bool find(ObjectG item, out uint position) 141 { 142 return g_list_store_find(gListStore, (item is null) ? null : item.getObjectGStruct(), &position) != 0; 143 } 144 145 /** 146 * Looks up the given @item in the list store by looping over the items and 147 * comparing them with @compare_func until the first occurrence of @item which 148 * matches. If @item was not found, then @position will not be set, and this 149 * method will return %FALSE. 150 * 151 * Params: 152 * item = an item 153 * equalFunc = A custom equality check function 154 * position = the first position of @item, if it was found. 155 * 156 * Returns: Whether @store contains @item. If it was found, @position will be 157 * set to the position where @item occurred for the first time. 158 * 159 * Since: 2.64 160 */ 161 public bool findWithEqualFunc(ObjectG item, GEqualFunc equalFunc, out uint position) 162 { 163 return g_list_store_find_with_equal_func(gListStore, (item is null) ? null : item.getObjectGStruct(), equalFunc, &position) != 0; 164 } 165 166 /** 167 * Inserts @item into @store at @position. @item must be of type 168 * #GListStore:item-type or derived from it. @position must be smaller 169 * than the length of the list, or equal to it to append. 170 * 171 * This function takes a ref on @item. 172 * 173 * Use g_list_store_splice() to insert multiple items at the same time 174 * efficiently. 175 * 176 * Params: 177 * position = the position at which to insert the new item 178 * item = the new item 179 * 180 * Since: 2.44 181 */ 182 public void insert(uint position, ObjectG item) 183 { 184 g_list_store_insert(gListStore, position, (item is null) ? null : item.getObjectGStruct()); 185 } 186 187 /** 188 * Inserts @item into @store at a position to be determined by the 189 * @compare_func. 190 * 191 * The list must already be sorted before calling this function or the 192 * result is undefined. Usually you would approach this by only ever 193 * inserting items by way of this function. 194 * 195 * This function takes a ref on @item. 196 * 197 * Params: 198 * item = the new item 199 * compareFunc = pairwise comparison function for sorting 200 * userData = user data for @compare_func 201 * 202 * Returns: the position at which @item was inserted 203 * 204 * Since: 2.44 205 */ 206 public uint insertSorted(ObjectG item, GCompareDataFunc compareFunc, void* userData) 207 { 208 return g_list_store_insert_sorted(gListStore, (item is null) ? null : item.getObjectGStruct(), compareFunc, userData); 209 } 210 211 /** 212 * Removes the item from @store that is at @position. @position must be 213 * smaller than the current length of the list. 214 * 215 * Use g_list_store_splice() to remove multiple items at the same time 216 * efficiently. 217 * 218 * Params: 219 * position = the position of the item that is to be removed 220 * 221 * Since: 2.44 222 */ 223 public void remove(uint position) 224 { 225 g_list_store_remove(gListStore, position); 226 } 227 228 /** 229 * Removes all items from @store. 230 * 231 * Since: 2.44 232 */ 233 public void removeAll() 234 { 235 g_list_store_remove_all(gListStore); 236 } 237 238 /** 239 * Sort the items in @store according to @compare_func. 240 * 241 * Params: 242 * compareFunc = pairwise comparison function for sorting 243 * userData = user data for @compare_func 244 * 245 * Since: 2.46 246 */ 247 public void sort(GCompareDataFunc compareFunc, void* userData) 248 { 249 g_list_store_sort(gListStore, compareFunc, userData); 250 } 251 252 /** 253 * Changes @store by removing @n_removals items and adding @n_additions 254 * items to it. @additions must contain @n_additions items of type 255 * #GListStore:item-type. %NULL is not permitted. 256 * 257 * This function is more efficient than g_list_store_insert() and 258 * g_list_store_remove(), because it only emits 259 * #GListModel::items-changed once for the change. 260 * 261 * This function takes a ref on each item in @additions. 262 * 263 * The parameters @position and @n_removals must be correct (ie: 264 * @position + @n_removals must be less than or equal to the length of 265 * the list at the time this function is called). 266 * 267 * Params: 268 * position = the position at which to make the change 269 * nRemovals = the number of items to remove 270 * additions = the items to add 271 * 272 * Since: 2.44 273 */ 274 public void splice(uint position, uint nRemovals, ObjectG[] additions) 275 { 276 void*[] additionsArray = new void*[additions.length]; 277 for ( int i = 0; i < additions.length; i++ ) 278 { 279 additionsArray[i] = additions[i].getObjectGStruct(); 280 } 281 282 g_list_store_splice(gListStore, position, nRemovals, additionsArray.ptr, cast(uint)additions.length); 283 } 284 }