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