ui/gtk/model.c

Sat, 14 Nov 2020 21:11:35 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 14 Nov 2020 21:11:35 +0100
changeset 159
84a6e7a7b457
parent 152
62921b370c60
child 164
1d912f78fd1d
permissions
-rw-r--r--

fix configure target options

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

mercurial