ui/gtk/model.c

Thu, 15 May 2014 17:17:58 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 15 May 2014 17:17:58 +0200
changeset 38
8ccdde37275b
parent 35
3e8b5c9b4033
child 40
caa0df8ed095
permissions
-rw-r--r--

added some allocation functions

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

mercurial