File: ListStore.d

package info (click to toggle)
gtk-d 3.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,152 kB
  • sloc: javascript: 565; sh: 71; makefile: 25
file content (285 lines) | stat: -rw-r--r-- 8,258 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
 * This file is part of gtkD.
 *
 * gtkD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version, with
 * some exceptions, please read the COPYING file.
 *
 * gtkD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with gtkD; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 */

// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage


module gio.ListStore;

private import gio.ListModelIF;
private import gio.ListModelT;
private import gio.c.functions;
public  import gio.c.types;
private import glib.ConstructionException;
private import gobject.ObjectG;
public  import gtkc.giotypes;


/**
 * #GListStore is a simple implementation of #GListModel that stores all
 * items in memory.
 * 
 * It provides insertions, deletions, and lookups in logarithmic time
 * with a fast path for the common case of iterating the list linearly.
 */
public class ListStore : ObjectG, ListModelIF
{
	/** the main Gtk struct */
	protected GListStore* gListStore;

	/** Get the main Gtk struct */
	public GListStore* getListStoreStruct(bool transferOwnership = false)
	{
		if (transferOwnership)
			ownedRef = false;
		return gListStore;
	}

	/** the main Gtk struct as a void* */
	protected override void* getStruct()
	{
		return cast(void*)gListStore;
	}

	/**
	 * Sets our main struct and passes it to the parent class.
	 */
	public this (GListStore* gListStore, bool ownedRef = false)
	{
		this.gListStore = gListStore;
		super(cast(GObject*)gListStore, ownedRef);
	}

	// add the ListModel capabilities
	mixin ListModelT!(GListStore);


	/** */
	public static GType getType()
	{
		return g_list_store_get_type();
	}

	/**
	 * Creates a new #GListStore with items of type @item_type. @item_type
	 * must be a subclass of #GObject.
	 *
	 * Params:
	 *     itemType = the #GType of items in the list
	 *
	 * Returns: a new #GListStore
	 *
	 * Since: 2.44
	 *
	 * Throws: ConstructionException GTK+ fails to create the object.
	 */
	public this(GType itemType)
	{
		auto __p = g_list_store_new(itemType);

		if(__p is null)
		{
			throw new ConstructionException("null returned by new");
		}

		this(cast(GListStore*) __p, true);
	}

	/**
	 * Appends @item to @store. @item must be of type #GListStore:item-type.
	 *
	 * This function takes a ref on @item.
	 *
	 * Use g_list_store_splice() to append multiple items at the same time
	 * efficiently.
	 *
	 * Params:
	 *     item = the new item
	 *
	 * Since: 2.44
	 */
	public void append(ObjectG item)
	{
		g_list_store_append(gListStore, (item is null) ? null : item.getObjectGStruct());
	}

	/**
	 * Looks up the given @item in the list store by looping over the items until
	 * the first occurrence of @item. If @item was not found, then @position will
	 * not be set, and this method will return %FALSE.
	 *
	 * If you need to compare the two items with a custom comparison function, use
	 * g_list_store_find_with_equal_func() with a custom #GEqualFunc instead.
	 *
	 * Params:
	 *     item = an item
	 *     position = the first position of @item, if it was found.
	 *
	 * Returns: Whether @store contains @item. If it was found, @position will be
	 *     set to the position where @item occurred for the first time.
	 *
	 * Since: 2.64
	 */
	public bool find(ObjectG item, out uint position)
	{
		return g_list_store_find(gListStore, (item is null) ? null : item.getObjectGStruct(), &position) != 0;
	}

	/**
	 * Looks up the given @item in the list store by looping over the items and
	 * comparing them with @compare_func until the first occurrence of @item which
	 * matches. If @item was not found, then @position will not be set, and this
	 * method will return %FALSE.
	 *
	 * Params:
	 *     item = an item
	 *     equalFunc = A custom equality check function
	 *     position = the first position of @item, if it was found.
	 *
	 * Returns: Whether @store contains @item. If it was found, @position will be
	 *     set to the position where @item occurred for the first time.
	 *
	 * Since: 2.64
	 */
	public bool findWithEqualFunc(ObjectG item, GEqualFunc equalFunc, out uint position)
	{
		return g_list_store_find_with_equal_func(gListStore, (item is null) ? null : item.getObjectGStruct(), equalFunc, &position) != 0;
	}

	/**
	 * Inserts @item into @store at @position. @item must be of type
	 * #GListStore:item-type or derived from it. @position must be smaller
	 * than the length of the list, or equal to it to append.
	 *
	 * This function takes a ref on @item.
	 *
	 * Use g_list_store_splice() to insert multiple items at the same time
	 * efficiently.
	 *
	 * Params:
	 *     position = the position at which to insert the new item
	 *     item = the new item
	 *
	 * Since: 2.44
	 */
	public void insert(uint position, ObjectG item)
	{
		g_list_store_insert(gListStore, position, (item is null) ? null : item.getObjectGStruct());
	}

	/**
	 * Inserts @item into @store at a position to be determined by the
	 * @compare_func.
	 *
	 * The list must already be sorted before calling this function or the
	 * result is undefined.  Usually you would approach this by only ever
	 * inserting items by way of this function.
	 *
	 * This function takes a ref on @item.
	 *
	 * Params:
	 *     item = the new item
	 *     compareFunc = pairwise comparison function for sorting
	 *     userData = user data for @compare_func
	 *
	 * Returns: the position at which @item was inserted
	 *
	 * Since: 2.44
	 */
	public uint insertSorted(ObjectG item, GCompareDataFunc compareFunc, void* userData)
	{
		return g_list_store_insert_sorted(gListStore, (item is null) ? null : item.getObjectGStruct(), compareFunc, userData);
	}

	/**
	 * Removes the item from @store that is at @position. @position must be
	 * smaller than the current length of the list.
	 *
	 * Use g_list_store_splice() to remove multiple items at the same time
	 * efficiently.
	 *
	 * Params:
	 *     position = the position of the item that is to be removed
	 *
	 * Since: 2.44
	 */
	public void remove(uint position)
	{
		g_list_store_remove(gListStore, position);
	}

	/**
	 * Removes all items from @store.
	 *
	 * Since: 2.44
	 */
	public void removeAll()
	{
		g_list_store_remove_all(gListStore);
	}

	/**
	 * Sort the items in @store according to @compare_func.
	 *
	 * Params:
	 *     compareFunc = pairwise comparison function for sorting
	 *     userData = user data for @compare_func
	 *
	 * Since: 2.46
	 */
	public void sort(GCompareDataFunc compareFunc, void* userData)
	{
		g_list_store_sort(gListStore, compareFunc, userData);
	}

	/**
	 * Changes @store by removing @n_removals items and adding @n_additions
	 * items to it. @additions must contain @n_additions items of type
	 * #GListStore:item-type.  %NULL is not permitted.
	 *
	 * This function is more efficient than g_list_store_insert() and
	 * g_list_store_remove(), because it only emits
	 * #GListModel::items-changed once for the change.
	 *
	 * This function takes a ref on each item in @additions.
	 *
	 * The parameters @position and @n_removals must be correct (ie:
	 * @position + @n_removals must be less than or equal to the length of
	 * the list at the time this function is called).
	 *
	 * Params:
	 *     position = the position at which to make the change
	 *     nRemovals = the number of items to remove
	 *     additions = the items to add
	 *
	 * Since: 2.44
	 */
	public void splice(uint position, uint nRemovals, ObjectG[] additions)
	{
		void*[] additionsArray = new void*[additions.length];
		for ( int i = 0; i < additions.length; i++ )
		{
			additionsArray[i] = additions[i].getObjectGStruct();
		}

		g_list_store_splice(gListStore, position, nRemovals, additionsArray.ptr, cast(uint)additions.length);
	}
}