Thu, 16 Nov 2017 12:04:10 +0100
new icon/image api and pixbuf support in treeview (GTK)
35 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
35 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | ||
32 | #include "model.h" | |
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
33 | #include "image.h" |
35 | 34 | |
35 | #define IS_UI_LIST_MODEL(obj) \ | |
36 | (G_TYPE_CHECK_INSTANCE_TYPE((obj), list_model_type)) | |
37 | #define UI_LIST_MODEL(obj) \ | |
38 | (G_TYPE_CHECK_INSTANCE_CAST((obj), list_model_type, UiListModel)) | |
39 | ||
40 | static void list_model_class_init(GObjectClass *cl, gpointer data); | |
41 | static void list_model_interface_init(GtkTreeModelIface *i, gpointer data); | |
42 | static void list_model_init(UiListModel *instance, GObjectClass *cl); | |
43 | ||
44 | static GObjectClass list_model_class; | |
45 | static const GTypeInfo list_model_info = { | |
46 | sizeof(GObjectClass), | |
47 | NULL, | |
48 | NULL, | |
49 | (GClassInitFunc)list_model_class_init, | |
50 | NULL, | |
51 | NULL, | |
52 | sizeof(UiListModel), | |
53 | 0, | |
54 | (GInstanceInitFunc)list_model_init | |
55 | }; | |
56 | static const GInterfaceInfo list_model_interface_info = { | |
57 | (GInterfaceInitFunc)list_model_interface_init, | |
58 | NULL, | |
59 | NULL | |
60 | }; | |
61 | static GType list_model_type; | |
62 | ||
63 | void ui_list_init() { | |
64 | list_model_type = g_type_register_static( | |
65 | G_TYPE_OBJECT, | |
66 | "UiListModel", | |
67 | &list_model_info, | |
68 | (GTypeFlags)0); | |
69 | g_type_add_interface_static( | |
70 | list_model_type, | |
71 | GTK_TYPE_TREE_MODEL, | |
72 | &list_model_interface_info); | |
73 | } | |
74 | ||
75 | static void list_model_class_init(GObjectClass *cl, gpointer data) { | |
76 | //cl->finalize = ...; // TODO | |
77 | } | |
78 | ||
79 | static void list_model_interface_init(GtkTreeModelIface *i, gpointer data) { | |
80 | i->get_flags = ui_list_model_get_flags; | |
81 | i->get_n_columns = ui_list_model_get_n_columns; | |
82 | i->get_column_type = ui_list_model_get_column_type; | |
83 | i->get_iter = ui_list_model_get_iter; | |
84 | i->get_path = ui_list_model_get_path; | |
85 | i->get_value = ui_list_model_get_value; | |
86 | i->iter_next = ui_list_model_iter_next; | |
87 | i->iter_children = ui_list_model_iter_children; | |
88 | i->iter_has_child = ui_list_model_iter_has_child; | |
89 | i->iter_n_children = ui_list_model_iter_n_children; | |
90 | i->iter_nth_child = ui_list_model_iter_nth_child; | |
91 | i->iter_parent = ui_list_model_iter_parent; | |
92 | } | |
93 | ||
94 | static void list_model_init(UiListModel *instance, GObjectClass *cl) { | |
95 | instance->columntypes = NULL; | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
96 | instance->var = NULL; |
35 | 97 | instance->numcolumns = 0; |
98 | instance->stamp = g_random_int(); | |
99 | } | |
100 | ||
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
101 | static GType ui_gtk_type(UiModelType type) { |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
102 | switch(type) { |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
103 | case UI_STRING: return G_TYPE_STRING; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
104 | case UI_INTEGER: return G_TYPE_INT; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
105 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
106 | return G_TYPE_INVALID; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
107 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
108 | |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
109 | static void ui_model_set_value(GType type, void *data, GValue *value) { |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
110 | switch(type) { |
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
111 | case G_TYPE_OBJECT: { |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
112 | value->g_type = G_TYPE_OBJECT; |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
113 | g_value_set_object(value, data); |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
114 | return; |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
115 | } |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
116 | case G_TYPE_STRING: { |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
117 | value->g_type = G_TYPE_STRING; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
118 | g_value_set_string(value, data); |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
119 | return; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
120 | } |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
121 | case G_TYPE_INT: { |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
122 | value->g_type = G_TYPE_INT; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
123 | int *i = data; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
124 | g_value_set_int(value, *i); |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
125 | return; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
126 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
127 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
128 | value->g_type = G_TYPE_INVALID; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
129 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
130 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
131 | UiListModel* ui_list_model_new(UiVar *var, UiModel *info) { |
35 | 132 | UiListModel *model = g_object_new(list_model_type, NULL); |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
133 | model->info = info; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
134 | model->var = var; |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
135 | model->columntypes = calloc(sizeof(GType), 2 * info->columns); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
136 | int ncol = 0; |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
137 | for(int i=0;i<info->columns;i++) { |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
138 | UiModelType type = info->types[i]; |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
139 | if(type == UI_ICON_TEXT) { |
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
140 | model->columntypes[ncol] = G_TYPE_OBJECT; |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
141 | ncol++; |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
142 | model->columntypes[ncol] = G_TYPE_STRING; |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
143 | } else { |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
144 | model->columntypes[ncol] = ui_gtk_type(info->types[i]); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
145 | } |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
146 | ncol++; |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
147 | } |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
148 | model->numcolumns = ncol; |
35 | 149 | return model; |
150 | } | |
151 | ||
152 | ||
153 | GtkTreeModelFlags ui_list_model_get_flags(GtkTreeModel *tree_model) { | |
154 | return (GTK_TREE_MODEL_LIST_ONLY | GTK_TREE_MODEL_ITERS_PERSIST); | |
155 | } | |
156 | ||
157 | gint ui_list_model_get_n_columns(GtkTreeModel *tree_model) { | |
158 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), 0); | |
159 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
160 | return model->numcolumns; | |
161 | } | |
162 | ||
163 | GType ui_list_model_get_column_type(GtkTreeModel *tree_model, gint index) { | |
164 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), G_TYPE_INVALID); | |
165 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
166 | g_return_val_if_fail(index < model->numcolumns, G_TYPE_INVALID); | |
167 | return model->columntypes[index]; | |
168 | } | |
169 | ||
170 | gboolean ui_list_model_get_iter( | |
171 | GtkTreeModel *tree_model, | |
172 | GtkTreeIter *iter, | |
173 | GtkTreePath *path) | |
174 | { | |
175 | g_assert(IS_UI_LIST_MODEL(tree_model)); | |
176 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
177 | UiList *list = model->var->value; |
35 | 178 | |
179 | // check the depth of the path | |
180 | // a list must have a depth of 1 | |
181 | gint depth = gtk_tree_path_get_depth(path); | |
182 | g_assert(depth == 1); | |
183 | ||
184 | // get row | |
185 | gint *indices = gtk_tree_path_get_indices(path); | |
186 | gint row = indices[0]; | |
187 | ||
188 | // check row | |
189 | if(row == 0) { | |
190 | // we don't need to count if the first element is requested | |
191 | if(list->first(list) == NULL) { | |
192 | return FALSE; | |
193 | } | |
194 | } else if(row >= list->count(list)) { | |
195 | return FALSE; | |
196 | } | |
197 | ||
198 | // the UiList has an integrated iterator | |
199 | // we only get a value to adjust it | |
200 | void *val = NULL; | |
201 | if(row == 0) { | |
202 | val = list->first(list); | |
203 | } else { | |
204 | val = list->get(list, row); | |
205 | } | |
206 | ||
207 | iter->stamp = model->stamp; | |
208 | iter->user_data = list->iter; | |
209 | iter->user_data2 = (gpointer)(intptr_t)row; // list->index | |
210 | iter->user_data3 = val; | |
211 | ||
212 | return val ? TRUE : FALSE; | |
213 | } | |
214 | ||
215 | GtkTreePath* ui_list_model_get_path( | |
216 | GtkTreeModel *tree_model, | |
217 | GtkTreeIter *iter) | |
218 | { | |
219 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), NULL); | |
220 | g_return_val_if_fail(iter != NULL, NULL); | |
221 | g_return_val_if_fail(iter->user_data != NULL, NULL); | |
222 | ||
223 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
224 | ||
225 | GtkTreePath *path = gtk_tree_path_new(); | |
226 | gtk_tree_path_append_index(path, (int)(intptr_t)iter->user_data2); // list->index | |
227 | ||
228 | return path; | |
229 | } | |
230 | ||
231 | void ui_list_model_get_value( | |
232 | GtkTreeModel *tree_model, | |
233 | GtkTreeIter *iter, | |
234 | gint column, | |
235 | GValue *value) | |
236 | { | |
237 | g_return_if_fail(IS_UI_LIST_MODEL(tree_model)); | |
238 | g_return_if_fail(iter != NULL); | |
239 | g_return_if_fail(iter->user_data != NULL); | |
240 | ||
241 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
242 | UiList *list = model->var->value; |
35 | 243 | |
244 | g_return_if_fail(column < model->numcolumns); | |
245 | ||
246 | // TODO: return correct value from column | |
247 | ||
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
248 | //value->g_type = G_TYPE_STRING; |
35 | 249 | list->iter = iter->user_data; |
250 | //list->index = (int)(intptr_t)iter->user_data2; | |
251 | //list->current = iter->user_data3; | |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
252 | if(model->info->getvalue) { |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
253 | void *data = model->info->getvalue(iter->user_data3, column); |
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
254 | if(model->columntypes[column] == G_TYPE_OBJECT) { |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
255 | UiImage *img = data; |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
256 | ui_model_set_value(model->columntypes[column], img->pixbuf, value); |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
257 | } else { |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
258 | ui_model_set_value(model->columntypes[column], data, value); |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
259 | } |
35 | 260 | } else { |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
261 | value->g_type = G_TYPE_INVALID; |
35 | 262 | } |
263 | } | |
264 | ||
265 | gboolean ui_list_model_iter_next( | |
266 | GtkTreeModel *tree_model, | |
267 | GtkTreeIter *iter) | |
268 | { | |
269 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); | |
270 | g_return_val_if_fail(iter != NULL, FALSE); | |
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
271 | //g_return_val_if_fail(iter->user_data != NULL, FALSE); |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
272 | |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
273 | if(!iter->user_data) { |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
274 | return FALSE; |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
275 | } |
35 | 276 | |
277 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
278 | UiList *list = model->var->value; |
35 | 279 | list->iter = iter->user_data; |
280 | //list->index = (int)(intptr_t)iter->user_data2; | |
281 | void *val = list->next(list); | |
282 | iter->user_data = list->iter; | |
283 | intptr_t index = (intptr_t)iter->user_data2; | |
284 | index++; | |
285 | //iter->user_data2 = (gpointer)(intptr_t)list->index; | |
286 | iter->user_data2 = (gpointer)index; | |
287 | iter->user_data3 = val; | |
288 | return val ? TRUE : FALSE; | |
289 | } | |
290 | ||
291 | gboolean ui_list_model_iter_children( | |
292 | GtkTreeModel *tree_model, | |
293 | GtkTreeIter *iter, | |
294 | GtkTreeIter *parent) | |
295 | { | |
296 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); | |
297 | ||
298 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
299 | UiList *list = model->var->value; |
35 | 300 | |
301 | if(parent) { | |
302 | return FALSE; | |
303 | } | |
304 | ||
305 | /* | |
306 | * a list element has no children | |
307 | * we set the iter to the first element | |
308 | */ | |
309 | void *val = list->first(list); | |
310 | iter->stamp = model->stamp; | |
311 | iter->user_data = list->iter; | |
312 | iter->user_data2 = (gpointer)0; | |
313 | iter->user_data3 = val; | |
314 | ||
315 | return val ? TRUE : FALSE; | |
316 | } | |
317 | ||
318 | gboolean ui_list_model_iter_has_child( | |
319 | GtkTreeModel *tree_model, | |
320 | GtkTreeIter *iter) | |
321 | { | |
322 | return FALSE; | |
323 | } | |
324 | ||
325 | gint ui_list_model_iter_n_children( | |
326 | GtkTreeModel *tree_model, | |
327 | GtkTreeIter *iter) | |
328 | { | |
329 | g_assert(IS_UI_LIST_MODEL(tree_model)); | |
330 | ||
331 | if(!iter) { | |
332 | // return number of rows | |
333 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
334 | UiList *list = model->var->value; |
35 | 335 | return list->count(list); |
336 | } | |
337 | ||
338 | return 0; | |
339 | } | |
340 | ||
341 | gboolean ui_list_model_iter_nth_child( | |
342 | GtkTreeModel *tree_model, | |
343 | GtkTreeIter *iter, | |
344 | GtkTreeIter *parent, | |
345 | gint n) | |
346 | { | |
347 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); | |
348 | ||
349 | if(parent) { | |
350 | return FALSE; | |
351 | } | |
352 | ||
353 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
354 | UiList *list = model->var->value; |
35 | 355 | |
356 | // check n | |
357 | if(n == 0) { | |
358 | // we don't need to count if the first element is requested | |
359 | if(list->first(list) == NULL) { | |
360 | return FALSE; | |
361 | } | |
362 | } else if(n >= list->count(list)) { | |
363 | return FALSE; | |
364 | } | |
365 | ||
366 | void *val = list->get(list, n); | |
367 | iter->stamp = model->stamp; | |
368 | iter->user_data = list->iter; | |
369 | iter->user_data2 = (gpointer)(intptr_t)n; // list->index | |
370 | iter->user_data3 = val; | |
371 | ||
372 | return val ? TRUE : FALSE; | |
373 | } | |
374 | ||
375 | gboolean ui_list_model_iter_parent( | |
376 | GtkTreeModel *tree_model, | |
377 | GtkTreeIter *iter, | |
378 | GtkTreeIter *child) | |
379 | { | |
380 | return FALSE; | |
381 | } |