Sun, 19 Nov 2017 09:00:16 +0100
adds simple drag and drop support (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" |
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
34 | #include "toolkit.h" |
35 | 35 | |
36 | #define IS_UI_LIST_MODEL(obj) \ | |
37 | (G_TYPE_CHECK_INSTANCE_TYPE((obj), list_model_type)) | |
38 | #define UI_LIST_MODEL(obj) \ | |
39 | (G_TYPE_CHECK_INSTANCE_CAST((obj), list_model_type, UiListModel)) | |
40 | ||
41 | static void list_model_class_init(GObjectClass *cl, gpointer data); | |
42 | static void list_model_interface_init(GtkTreeModelIface *i, gpointer data); | |
43 | static void list_model_init(UiListModel *instance, GObjectClass *cl); | |
44 | ||
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
45 | static void list_model_dnd_dest_interface_init(GtkTreeDragDestIface *i, gpointer data); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
46 | static void list_model_dnd_src_interface_init(GtkTreeDragSourceIface *i, gpointer data); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
47 | |
35 | 48 | static GObjectClass list_model_class; |
49 | static const GTypeInfo list_model_info = { | |
50 | sizeof(GObjectClass), | |
51 | NULL, | |
52 | NULL, | |
53 | (GClassInitFunc)list_model_class_init, | |
54 | NULL, | |
55 | NULL, | |
56 | sizeof(UiListModel), | |
57 | 0, | |
58 | (GInstanceInitFunc)list_model_init | |
59 | }; | |
60 | static const GInterfaceInfo list_model_interface_info = { | |
61 | (GInterfaceInitFunc)list_model_interface_init, | |
62 | NULL, | |
63 | NULL | |
64 | }; | |
65 | static GType list_model_type; | |
66 | ||
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
67 | static const GInterfaceInfo list_model_dnd_dest_interface_info = { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
68 | (GInterfaceInitFunc)list_model_dnd_dest_interface_init, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
69 | NULL, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
70 | NULL |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
71 | }; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
72 | static const GInterfaceInfo list_model_dnd_src_interface_info = { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
73 | (GInterfaceInitFunc)list_model_dnd_src_interface_init, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
74 | NULL, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
75 | NULL |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
76 | }; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
77 | |
35 | 78 | void ui_list_init() { |
79 | list_model_type = g_type_register_static( | |
80 | G_TYPE_OBJECT, | |
81 | "UiListModel", | |
82 | &list_model_info, | |
83 | (GTypeFlags)0); | |
84 | g_type_add_interface_static( | |
85 | list_model_type, | |
86 | GTK_TYPE_TREE_MODEL, | |
87 | &list_model_interface_info); | |
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
88 | g_type_add_interface_static( |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
89 | list_model_type, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
90 | GTK_TYPE_TREE_DRAG_DEST, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
91 | &list_model_dnd_dest_interface_info); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
92 | g_type_add_interface_static( |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
93 | list_model_type, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
94 | GTK_TYPE_TREE_DRAG_SOURCE, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
95 | &list_model_dnd_src_interface_info); |
35 | 96 | } |
97 | ||
98 | static void list_model_class_init(GObjectClass *cl, gpointer data) { | |
99 | //cl->finalize = ...; // TODO | |
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
100 | |
35 | 101 | } |
102 | ||
103 | static void list_model_interface_init(GtkTreeModelIface *i, gpointer data) { | |
104 | i->get_flags = ui_list_model_get_flags; | |
105 | i->get_n_columns = ui_list_model_get_n_columns; | |
106 | i->get_column_type = ui_list_model_get_column_type; | |
107 | i->get_iter = ui_list_model_get_iter; | |
108 | i->get_path = ui_list_model_get_path; | |
109 | i->get_value = ui_list_model_get_value; | |
110 | i->iter_next = ui_list_model_iter_next; | |
111 | i->iter_children = ui_list_model_iter_children; | |
112 | i->iter_has_child = ui_list_model_iter_has_child; | |
113 | i->iter_n_children = ui_list_model_iter_n_children; | |
114 | i->iter_nth_child = ui_list_model_iter_nth_child; | |
115 | i->iter_parent = ui_list_model_iter_parent; | |
116 | } | |
117 | ||
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
118 | static void list_model_dnd_dest_interface_init(GtkTreeDragDestIface *i, gpointer data) { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
119 | i->drag_data_received = ui_list_model_drag_data_received; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
120 | i->row_drop_possible = ui_list_model_row_drop_possible; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
121 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
122 | |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
123 | static void list_model_dnd_src_interface_init(GtkTreeDragSourceIface *i, gpointer data) { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
124 | i->drag_data_delete = ui_list_model_drag_data_delete; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
125 | i->drag_data_get = ui_list_model_drag_data_get; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
126 | i->row_draggable = ui_list_model_row_draggable; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
127 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
128 | |
35 | 129 | static void list_model_init(UiListModel *instance, GObjectClass *cl) { |
130 | instance->columntypes = NULL; | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
131 | instance->var = NULL; |
35 | 132 | instance->numcolumns = 0; |
133 | instance->stamp = g_random_int(); | |
134 | } | |
135 | ||
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
136 | static GType ui_gtk_type(UiModelType type) { |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
137 | switch(type) { |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
138 | case UI_STRING: return G_TYPE_STRING; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
139 | case UI_INTEGER: return G_TYPE_INT; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
140 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
141 | return G_TYPE_INVALID; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
142 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
143 | |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
144 | 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
|
145 | switch(type) { |
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | return; |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
150 | } |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
151 | case G_TYPE_STRING: { |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
152 | value->g_type = G_TYPE_STRING; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
153 | g_value_set_string(value, data); |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
154 | return; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
155 | } |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
156 | case G_TYPE_INT: { |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
157 | value->g_type = G_TYPE_INT; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
158 | int *i = data; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
159 | g_value_set_int(value, *i); |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
160 | return; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
161 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
162 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
163 | value->g_type = G_TYPE_INVALID; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
164 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
165 | |
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
166 | UiListModel* ui_list_model_new(UiObject *obj, UiVar *var, UiModel *info) { |
35 | 167 | UiListModel *model = g_object_new(list_model_type, NULL); |
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
168 | model->obj = obj; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
169 | model->model = info; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
170 | model->var = var; |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
171 | model->columntypes = calloc(sizeof(GType), 2 * info->columns); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
172 | int ncol = 0; |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
173 | for(int i=0;i<info->columns;i++) { |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
174 | UiModelType type = info->types[i]; |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
175 | 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
|
176 | model->columntypes[ncol] = G_TYPE_OBJECT; |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
177 | ncol++; |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
178 | model->columntypes[ncol] = G_TYPE_STRING; |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
179 | } else { |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
180 | model->columntypes[ncol] = ui_gtk_type(info->types[i]); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
181 | } |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
182 | ncol++; |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
183 | } |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
184 | model->numcolumns = ncol; |
35 | 185 | return model; |
186 | } | |
187 | ||
188 | ||
189 | GtkTreeModelFlags ui_list_model_get_flags(GtkTreeModel *tree_model) { | |
190 | return (GTK_TREE_MODEL_LIST_ONLY | GTK_TREE_MODEL_ITERS_PERSIST); | |
191 | } | |
192 | ||
193 | gint ui_list_model_get_n_columns(GtkTreeModel *tree_model) { | |
194 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), 0); | |
195 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
196 | return model->numcolumns; | |
197 | } | |
198 | ||
199 | GType ui_list_model_get_column_type(GtkTreeModel *tree_model, gint index) { | |
200 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), G_TYPE_INVALID); | |
201 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
202 | g_return_val_if_fail(index < model->numcolumns, G_TYPE_INVALID); | |
203 | return model->columntypes[index]; | |
204 | } | |
205 | ||
206 | gboolean ui_list_model_get_iter( | |
207 | GtkTreeModel *tree_model, | |
208 | GtkTreeIter *iter, | |
209 | GtkTreePath *path) | |
210 | { | |
211 | g_assert(IS_UI_LIST_MODEL(tree_model)); | |
212 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
213 | UiList *list = model->var->value; |
35 | 214 | |
215 | // check the depth of the path | |
216 | // a list must have a depth of 1 | |
217 | gint depth = gtk_tree_path_get_depth(path); | |
218 | g_assert(depth == 1); | |
219 | ||
220 | // get row | |
221 | gint *indices = gtk_tree_path_get_indices(path); | |
222 | gint row = indices[0]; | |
223 | ||
224 | // check row | |
225 | if(row == 0) { | |
226 | // we don't need to count if the first element is requested | |
227 | if(list->first(list) == NULL) { | |
228 | return FALSE; | |
229 | } | |
230 | } else if(row >= list->count(list)) { | |
231 | return FALSE; | |
232 | } | |
233 | ||
234 | // the UiList has an integrated iterator | |
235 | // we only get a value to adjust it | |
236 | void *val = NULL; | |
237 | if(row == 0) { | |
238 | val = list->first(list); | |
239 | } else { | |
240 | val = list->get(list, row); | |
241 | } | |
242 | ||
243 | iter->stamp = model->stamp; | |
244 | iter->user_data = list->iter; | |
245 | iter->user_data2 = (gpointer)(intptr_t)row; // list->index | |
246 | iter->user_data3 = val; | |
247 | ||
248 | return val ? TRUE : FALSE; | |
249 | } | |
250 | ||
251 | GtkTreePath* ui_list_model_get_path( | |
252 | GtkTreeModel *tree_model, | |
253 | GtkTreeIter *iter) | |
254 | { | |
255 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), NULL); | |
256 | g_return_val_if_fail(iter != NULL, NULL); | |
257 | g_return_val_if_fail(iter->user_data != NULL, NULL); | |
258 | ||
259 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
260 | ||
261 | GtkTreePath *path = gtk_tree_path_new(); | |
262 | gtk_tree_path_append_index(path, (int)(intptr_t)iter->user_data2); // list->index | |
263 | ||
264 | return path; | |
265 | } | |
266 | ||
267 | void ui_list_model_get_value( | |
268 | GtkTreeModel *tree_model, | |
269 | GtkTreeIter *iter, | |
270 | gint column, | |
271 | GValue *value) | |
272 | { | |
273 | g_return_if_fail(IS_UI_LIST_MODEL(tree_model)); | |
274 | g_return_if_fail(iter != NULL); | |
275 | g_return_if_fail(iter->user_data != NULL); | |
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 | |
280 | g_return_if_fail(column < model->numcolumns); | |
281 | ||
282 | // TODO: return correct value from column | |
283 | ||
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
284 | //value->g_type = G_TYPE_STRING; |
35 | 285 | list->iter = iter->user_data; |
286 | //list->index = (int)(intptr_t)iter->user_data2; | |
287 | //list->current = iter->user_data3; | |
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
288 | if(model->model->getvalue) { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
289 | void *data = model->model->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
|
290 | 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
|
291 | UiImage *img = data; |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
292 | 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
|
293 | } else { |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
294 | 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
|
295 | } |
35 | 296 | } else { |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
297 | value->g_type = G_TYPE_INVALID; |
35 | 298 | } |
299 | } | |
300 | ||
301 | gboolean ui_list_model_iter_next( | |
302 | GtkTreeModel *tree_model, | |
303 | GtkTreeIter *iter) | |
304 | { | |
305 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); | |
306 | 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
|
307 | //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
|
308 | |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
309 | 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
|
310 | return FALSE; |
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
311 | } |
35 | 312 | |
313 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
314 | UiList *list = model->var->value; |
35 | 315 | list->iter = iter->user_data; |
316 | //list->index = (int)(intptr_t)iter->user_data2; | |
317 | void *val = list->next(list); | |
318 | iter->user_data = list->iter; | |
319 | intptr_t index = (intptr_t)iter->user_data2; | |
320 | index++; | |
321 | //iter->user_data2 = (gpointer)(intptr_t)list->index; | |
322 | iter->user_data2 = (gpointer)index; | |
323 | iter->user_data3 = val; | |
324 | return val ? TRUE : FALSE; | |
325 | } | |
326 | ||
327 | gboolean ui_list_model_iter_children( | |
328 | GtkTreeModel *tree_model, | |
329 | GtkTreeIter *iter, | |
330 | GtkTreeIter *parent) | |
331 | { | |
332 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); | |
333 | ||
334 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
335 | UiList *list = model->var->value; |
35 | 336 | |
337 | if(parent) { | |
338 | return FALSE; | |
339 | } | |
340 | ||
341 | /* | |
342 | * a list element has no children | |
343 | * we set the iter to the first element | |
344 | */ | |
345 | void *val = list->first(list); | |
346 | iter->stamp = model->stamp; | |
347 | iter->user_data = list->iter; | |
348 | iter->user_data2 = (gpointer)0; | |
349 | iter->user_data3 = val; | |
350 | ||
351 | return val ? TRUE : FALSE; | |
352 | } | |
353 | ||
354 | gboolean ui_list_model_iter_has_child( | |
355 | GtkTreeModel *tree_model, | |
356 | GtkTreeIter *iter) | |
357 | { | |
358 | return FALSE; | |
359 | } | |
360 | ||
361 | gint ui_list_model_iter_n_children( | |
362 | GtkTreeModel *tree_model, | |
363 | GtkTreeIter *iter) | |
364 | { | |
365 | g_assert(IS_UI_LIST_MODEL(tree_model)); | |
366 | ||
367 | if(!iter) { | |
368 | // return number of rows | |
369 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
370 | UiList *list = model->var->value; |
35 | 371 | return list->count(list); |
372 | } | |
373 | ||
374 | return 0; | |
375 | } | |
376 | ||
377 | gboolean ui_list_model_iter_nth_child( | |
378 | GtkTreeModel *tree_model, | |
379 | GtkTreeIter *iter, | |
380 | GtkTreeIter *parent, | |
381 | gint n) | |
382 | { | |
383 | g_return_val_if_fail(IS_UI_LIST_MODEL(tree_model), FALSE); | |
384 | ||
385 | if(parent) { | |
386 | return FALSE; | |
387 | } | |
388 | ||
389 | UiListModel *model = UI_LIST_MODEL(tree_model); | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
390 | UiList *list = model->var->value; |
35 | 391 | |
392 | // check n | |
393 | if(n == 0) { | |
394 | // we don't need to count if the first element is requested | |
395 | if(list->first(list) == NULL) { | |
396 | return FALSE; | |
397 | } | |
398 | } else if(n >= list->count(list)) { | |
399 | return FALSE; | |
400 | } | |
401 | ||
402 | void *val = list->get(list, n); | |
403 | iter->stamp = model->stamp; | |
404 | iter->user_data = list->iter; | |
405 | iter->user_data2 = (gpointer)(intptr_t)n; // list->index | |
406 | iter->user_data3 = val; | |
407 | ||
408 | return val ? TRUE : FALSE; | |
409 | } | |
410 | ||
411 | gboolean ui_list_model_iter_parent( | |
412 | GtkTreeModel *tree_model, | |
413 | GtkTreeIter *iter, | |
414 | GtkTreeIter *child) | |
415 | { | |
416 | return FALSE; | |
417 | } | |
147
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
418 | |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
419 | // ****** dnd ****** |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
420 | |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
421 | gboolean ui_list_model_drag_data_received( |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
422 | GtkTreeDragDest *drag_dest, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
423 | GtkTreePath *dest_path, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
424 | GtkSelectionData *selection_data) |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
425 | { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
426 | //printf("drag received\n"); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
427 | UiListModel *model = UI_LIST_MODEL(drag_dest); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
428 | if(model->model->drop) { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
429 | gint *indices = gtk_tree_path_get_indices(dest_path); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
430 | gint row = indices[0]; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
431 | UiEvent e; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
432 | e.obj = model->obj; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
433 | e.window = e.obj->window; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
434 | e.document = e.obj->ctx->document; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
435 | e.eventdata = NULL; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
436 | e.intval = 0; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
437 | UiSelection s; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
438 | s.data = selection_data; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
439 | model->model->drop(&e, &s, model->var->value, row); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
440 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
441 | return TRUE; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
442 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
443 | |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
444 | gboolean ui_list_model_row_drop_possible( |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
445 | GtkTreeDragDest *drag_dest, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
446 | GtkTreePath *dest_path, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
447 | GtkSelectionData *selection_data) |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
448 | { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
449 | //printf("row_drop_possible\n"); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
450 | UiListModel *model = UI_LIST_MODEL(drag_dest); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
451 | if(model->model->candrop) { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
452 | gint *indices = gtk_tree_path_get_indices(dest_path); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
453 | gint row = indices[0]; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
454 | UiEvent e; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
455 | e.obj = model->obj; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
456 | e.window = e.obj->window; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
457 | e.document = e.obj->ctx->document; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
458 | e.eventdata = NULL; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
459 | e.intval = 0; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
460 | UiSelection s; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
461 | s.data = selection_data; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
462 | return model->model->candrop(&e, &s, model->var->value, row); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
463 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
464 | return TRUE; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
465 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
466 | |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
467 | gboolean ui_list_model_row_draggable( |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
468 | GtkTreeDragSource *drag_source, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
469 | GtkTreePath *path) |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
470 | { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
471 | //printf("row_draggable\n"); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
472 | UiListModel *model = UI_LIST_MODEL(drag_source); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
473 | if(model->model->candrag) { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
474 | gint *indices = gtk_tree_path_get_indices(path); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
475 | gint row = indices[0]; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
476 | UiEvent e; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
477 | e.obj = model->obj; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
478 | e.window = e.obj->window; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
479 | e.document = e.obj->ctx->document; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
480 | e.eventdata = NULL; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
481 | e.intval = 0; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
482 | return model->model->candrag(&e, model->var->value, row); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
483 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
484 | return TRUE; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
485 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
486 | |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
487 | gboolean ui_list_model_drag_data_get( |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
488 | GtkTreeDragSource *drag_source, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
489 | GtkTreePath *path, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
490 | GtkSelectionData *selection_data) |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
491 | { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
492 | //printf("drag_data_get\n"); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
493 | UiListModel *model = UI_LIST_MODEL(drag_source); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
494 | if(model->model->data_get) { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
495 | gint *indices = gtk_tree_path_get_indices(path); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
496 | gint row = indices[0]; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
497 | UiEvent e; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
498 | e.obj = model->obj; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
499 | e.window = e.obj->window; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
500 | e.document = e.obj->ctx->document; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
501 | e.eventdata = NULL; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
502 | e.intval = 0; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
503 | UiSelection s; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
504 | s.data = selection_data; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
505 | model->model->data_get(&e, &s, model->var->value, row); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
506 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
507 | return TRUE; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
508 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
509 | |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
510 | gboolean ui_list_model_drag_data_delete( |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
511 | GtkTreeDragSource *drag_source, |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
512 | GtkTreePath *path) |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
513 | { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
514 | //printf("drag_data_delete\n"); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
515 | UiListModel *model = UI_LIST_MODEL(drag_source); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
516 | if(model->model->data_get) { |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
517 | gint *indices = gtk_tree_path_get_indices(path); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
518 | gint row = indices[0]; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
519 | UiEvent e; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
520 | e.obj = model->obj; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
521 | e.window = e.obj->window; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
522 | e.document = e.obj->ctx->document; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
523 | e.eventdata = NULL; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
524 | e.intval = 0; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
525 | model->model->data_delete(&e, model->var->value, row); |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
526 | } |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
527 | return TRUE; |
2e384acc89a6
adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
528 | } |