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