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