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