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 	 * Looks up the given @item in the list store by looping over the items until
126 	 * the first occurrence of @item. If @item was not found, then @position will
127 	 * not be set, and this method will return %FALSE.
128 	 *
129 	 * If you need to compare the two items with a custom comparison function, use
130 	 * g_list_store_find_with_equal_func() with a custom #GEqualFunc instead.
131 	 *
132 	 * Params:
133 	 *     item = an item
134 	 *     position = the first position of @item, if it was found.
135 	 *
136 	 * Returns: Whether @store contains @item. If it was found, @position will be
137 	 *     set to the position where @item occurred for the first time.
138 	 *
139 	 * Since: 2.64
140 	 */
141 	public bool find(ObjectG item, out uint position)
142 	{
143 		return g_list_store_find(gListStore, (item is null) ? null : item.getObjectGStruct(), &position) != 0;
144 	}
145 
146 	/**
147 	 * Looks up the given @item in the list store by looping over the items and
148 	 * comparing them with @compare_func until the first occurrence of @item which
149 	 * matches. If @item was not found, then @position will not be set, and this
150 	 * method will return %FALSE.
151 	 *
152 	 * Params:
153 	 *     item = an item
154 	 *     equalFunc = A custom equality check function
155 	 *     position = the first position of @item, if it was found.
156 	 *
157 	 * Returns: Whether @store contains @item. If it was found, @position will be
158 	 *     set to the position where @item occurred for the first time.
159 	 *
160 	 * Since: 2.64
161 	 */
162 	public bool findWithEqualFunc(ObjectG item, GEqualFunc equalFunc, out uint position)
163 	{
164 		return g_list_store_find_with_equal_func(gListStore, (item is null) ? null : item.getObjectGStruct(), equalFunc, &position) != 0;
165 	}
166 
167 	/**
168 	 * Inserts @item into @store at @position. @item must be of type
169 	 * #GListStore:item-type or derived from it. @position must be smaller
170 	 * than the length of the list, or equal to it to append.
171 	 *
172 	 * This function takes a ref on @item.
173 	 *
174 	 * Use g_list_store_splice() to insert multiple items at the same time
175 	 * efficiently.
176 	 *
177 	 * Params:
178 	 *     position = the position at which to insert the new item
179 	 *     item = the new item
180 	 *
181 	 * Since: 2.44
182 	 */
183 	public void insert(uint position, ObjectG item)
184 	{
185 		g_list_store_insert(gListStore, position, (item is null) ? null : item.getObjectGStruct());
186 	}
187 
188 	/**
189 	 * Inserts @item into @store at a position to be determined by the
190 	 * @compare_func.
191 	 *
192 	 * The list must already be sorted before calling this function or the
193 	 * result is undefined.  Usually you would approach this by only ever
194 	 * inserting items by way of this function.
195 	 *
196 	 * This function takes a ref on @item.
197 	 *
198 	 * Params:
199 	 *     item = the new item
200 	 *     compareFunc = pairwise comparison function for sorting
201 	 *     userData = user data for @compare_func
202 	 *
203 	 * Returns: the position at which @item was inserted
204 	 *
205 	 * Since: 2.44
206 	 */
207 	public uint insertSorted(ObjectG item, GCompareDataFunc compareFunc, void* userData)
208 	{
209 		return g_list_store_insert_sorted(gListStore, (item is null) ? null : item.getObjectGStruct(), compareFunc, userData);
210 	}
211 
212 	/**
213 	 * Removes the item from @store that is at @position. @position must be
214 	 * smaller than the current length of the list.
215 	 *
216 	 * Use g_list_store_splice() to remove multiple items at the same time
217 	 * efficiently.
218 	 *
219 	 * Params:
220 	 *     position = the position of the item that is to be removed
221 	 *
222 	 * Since: 2.44
223 	 */
224 	public void remove(uint position)
225 	{
226 		g_list_store_remove(gListStore, position);
227 	}
228 
229 	/**
230 	 * Removes all items from @store.
231 	 *
232 	 * Since: 2.44
233 	 */
234 	public void removeAll()
235 	{
236 		g_list_store_remove_all(gListStore);
237 	}
238 
239 	/**
240 	 * Sort the items in @store according to @compare_func.
241 	 *
242 	 * Params:
243 	 *     compareFunc = pairwise comparison function for sorting
244 	 *     userData = user data for @compare_func
245 	 *
246 	 * Since: 2.46
247 	 */
248 	public void sort(GCompareDataFunc compareFunc, void* userData)
249 	{
250 		g_list_store_sort(gListStore, compareFunc, userData);
251 	}
252 
253 	/**
254 	 * Changes @store by removing @n_removals items and adding @n_additions
255 	 * items to it. @additions must contain @n_additions items of type
256 	 * #GListStore:item-type.  %NULL is not permitted.
257 	 *
258 	 * This function is more efficient than g_list_store_insert() and
259 	 * g_list_store_remove(), because it only emits
260 	 * #GListModel::items-changed once for the change.
261 	 *
262 	 * This function takes a ref on each item in @additions.
263 	 *
264 	 * The parameters @position and @n_removals must be correct (ie:
265 	 * @position + @n_removals must be less than or equal to the length of
266 	 * the list at the time this function is called).
267 	 *
268 	 * Params:
269 	 *     position = the position at which to make the change
270 	 *     nRemovals = the number of items to remove
271 	 *     additions = the items to add
272 	 *
273 	 * Since: 2.44
274 	 */
275 	public void splice(uint position, uint nRemovals, ObjectG[] additions)
276 	{
277 		void*[] additionsArray = new void*[additions.length];
278 		for ( int i = 0; i < additions.length; i++ )
279 		{
280 			additionsArray[i] = additions[i].getObjectGStruct();
281 		}
282 
283 		g_list_store_splice(gListStore, position, nRemovals, additionsArray.ptr, cast(uint)additions.length);
284 	}
285 }