ui/gtk/tree.c

Sun, 09 Jun 2024 17:00:22 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 09 Jun 2024 17:00:22 +0200
changeset 35
834d9c15a69f
parent 32
e5f4d8af567e
child 41
7ada3db4cfa8
permissions
-rw-r--r--

some toolkit fixes

0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2483f517c562 add existing toolkit code
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
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdarg.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/context.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/object.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "container.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "tree.h"
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
39 #include "image.h"
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 void* ui_strmodel_getvalue(void *elm, int column) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 return column == 0 ? elm : NULL;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
46 static GtkListStore* create_list_store(UiList *list, UiModel *model) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
47 int columns = model->columns;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
48 GType types[2*columns];
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
49 int c = 0;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
50 for(int i=0;i<columns;i++,c++) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
51 switch(model->types[i]) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
52 case UI_STRING:
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
53 case UI_STRING_FREE: types[c] = G_TYPE_STRING; break;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
54 case UI_INTEGER: types[c] = G_TYPE_INT; break;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
55 case UI_ICON: types[c] = G_TYPE_OBJECT; break;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
56 case UI_ICON_TEXT:
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
57 case UI_ICON_TEXT_FREE: {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
58 types[c] = G_TYPE_OBJECT;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
59 types[++c] = G_TYPE_STRING;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
60 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
61 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
62 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
63
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
64 GtkListStore *store = gtk_list_store_newv(c, types);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
65
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
66 if(list) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
67 void *elm = list->first(list);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
68 while(elm) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
69 // insert new row
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
70 GtkTreeIter iter;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
71 gtk_list_store_insert (store, &iter, -1);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
72
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
73 // set column values
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
74 int c = 0;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
75 for(int i=0;i<columns;i++,c++) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
76 void *data = model->getvalue(elm, c);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
77
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
78 GValue value = G_VALUE_INIT;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
79 switch(model->types[i]) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
80 case UI_STRING:
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
81 case UI_STRING_FREE: {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
82 g_value_init(&value, G_TYPE_STRING);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
83 g_value_set_string(&value, data);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
84 if(model->types[i] == UI_STRING_FREE) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
85 free(data);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
86 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
87 break;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
88 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
89 case UI_INTEGER: {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
90 g_value_init(&value, G_TYPE_INT);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
91 int *intptr = data;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
92 g_value_set_int(&value, *intptr);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
93 break;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
94 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
95 case UI_ICON: {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
96 g_value_init(&value, G_TYPE_OBJECT);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
97 UiIcon *icon = data;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
98 if(!icon->pixbuf && icon->info) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
99 GError *error = NULL;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
100 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
101 icon->pixbuf = pixbuf;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
102 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
103
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
104 if(icon->pixbuf) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
105 g_value_set_object(&value, icon->pixbuf);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
106 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
107
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
108
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
109 break;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
110 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
111 case UI_ICON_TEXT:
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
112 case UI_ICON_TEXT_FREE: {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
113 GValue pixbufvalue = G_VALUE_INIT;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
114 UiIcon *icon = data;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
115 if(!icon->pixbuf && icon->info) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
116 GError *error = NULL;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
117 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
118 icon->pixbuf = pixbuf;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
119 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
120 g_value_init(&pixbufvalue, G_TYPE_OBJECT);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
121 g_value_set_object(&pixbufvalue, icon->pixbuf);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
122 gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
123 c++;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
124
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
125 char *str = model->getvalue(elm, c);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
126 g_value_init(&value, G_TYPE_STRING);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
127 g_value_set_string(&value, str);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
128 if(model->types[i] == UI_ICON_TEXT_FREE) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
129 free(str);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
130 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
131 break;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
132 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
133 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
134
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
135 gtk_list_store_set_value(store, &iter, c, &value);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
136 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
137
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
138 // next row
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
139 elm = list->next(list);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
140 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
141 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
142
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
143 return store;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
144 }
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
146
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
147 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
148 UiObject* current = uic_current_obj(obj);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
149
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 // create treeview
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 GtkWidget *view = gtk_tree_view_new();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 0, NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 #ifdef UI_GTK3
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 #if GTK_MINOR_VERSION >= 8
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 #else
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 // TODO: implement for older gtk3
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 #endif
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 #else
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 // TODO: implement for gtk2
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 #endif
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
168 model->getvalue = args.getvalue;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
169
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
170 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
171
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
172 UiList *list = var ? var->value : NULL;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
173 GtkListStore *listmodel = create_list_store(list, model);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 UiListView *listview = malloc(sizeof(UiListView));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 listview->obj = obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 listview->widget = view;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 listview->var = var;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 listview->model = model;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 g_signal_connect(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 view,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 "destroy",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 G_CALLBACK(ui_listview_destroy),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 listview);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 // bind var
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 list->update = ui_listview_update;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 list->obj = listview;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 // add callback
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
192 if(args.onactivate) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 event->obj = obj;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
195 event->activatedata = args.onactivatedata;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
196 event->activate = args.onactivate;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 event->selection = NULL;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 g_signal_connect(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 view,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 "row-activated",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 G_CALLBACK(ui_listview_activate_event),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 event);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 // add widget to the current container
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 gtk_scrolled_window_set_policy(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 GTK_SCROLLED_WINDOW(scroll_area),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 GTK_POLICY_AUTOMATIC,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 gtk_container_add(GTK_CONTAINER(scroll_area), view);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
214 UI_APPLY_LAYOUT1(current, args);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
215 current->container->add(current->container, scroll_area, FALSE);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 // ct->current should point to view, not scroll_area, to make it possible
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 // to add a context menu
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
219 current->container->current = view;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 return scroll_area;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer udata) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 printf("drag begin\n");
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 static void drag_end(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 GtkWidget *widget,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 GdkDragContext *context,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 guint time,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 gpointer udata)
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 printf("drag end\n");
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 static GtkTargetEntry targetentries[] =
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 { "STRING", 0, 0 },
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 { "text/plain", 0, 1 },
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 { "text/uri-list", 0, 2 },
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 };
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
246 UIWIDGET ui_table_create(UiObject *obj, UiListArgs args) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
247 UiObject* current = uic_current_obj(obj);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
248
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 // create treeview
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 GtkWidget *view = gtk_tree_view_new();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
252 UiModel *model = args.model;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
253 int columns = model ? model->columns : 0;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
254
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 int addi = 0;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
256 for(int i=0;i<columns;i++) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 GtkTreeViewColumn *column = NULL;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 if(model->types[i] == UI_ICON_TEXT) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 column = gtk_tree_view_column_new();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 gtk_tree_view_column_set_title(column, model->titles[i]);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 gtk_tree_view_column_pack_end(column, textrenderer, TRUE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 gtk_tree_view_column_pack_start(column, iconrenderer, FALSE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 gtk_tree_view_column_add_attribute(column, iconrenderer, "pixbuf", i);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 gtk_tree_view_column_add_attribute(column, textrenderer, "text", i+1);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 addi++;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
273 } else if (model->types[i] == UI_ICON) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
274 GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
275 column = gtk_tree_view_column_new_with_attributes(
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
276 model->titles[i],
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
277 iconrenderer,
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
278 "pixbuf",
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
279 i + addi,
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
280 NULL);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 } else {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 column = gtk_tree_view_column_new_with_attributes(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 model->titles[i],
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 renderer,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 "text",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 i + addi,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 gtk_tree_view_column_set_resizable(column, TRUE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 //gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 #ifdef UI_GTK3
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 #else
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 #endif
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
301 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
302
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
303 UiList *list = var ? var->value : NULL;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
304 GtkListStore *listmodel = create_list_store(list, model);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 //g_signal_connect(view, "drag-begin", G_CALLBACK(drag_begin), NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 // add TreeView as observer to the UiList to update the TreeView if the
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 // data changes
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 UiListView *tableview = malloc(sizeof(UiListView));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 tableview->obj = obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 tableview->widget = view;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 tableview->var = var;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 tableview->model = model;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 g_signal_connect(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 view,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 "destroy",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 G_CALLBACK(ui_listview_destroy),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 tableview);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 // bind var
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 list->update = ui_listview_update;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 list->obj = tableview;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 // add callback
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 event->obj = obj;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
330 event->activate = args.onactivate;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
331 event->selection = args.onselection;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
332 event->activatedata = args.onactivatedata;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
333 event->selectiondata = args.onselectiondata;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
334 if(args.onactivate) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 g_signal_connect(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 view,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 "row-activated",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 G_CALLBACK(ui_listview_activate_event),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 event);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 }
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
341 if(args.onselection) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 GtkTreeSelection *selection = gtk_tree_view_get_selection(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 GTK_TREE_VIEW(view));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 g_signal_connect(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 selection,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 "changed",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 G_CALLBACK(ui_listview_selection_event),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 event);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 // TODO: destroy callback
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 // add widget to the current container
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 gtk_scrolled_window_set_policy(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 GTK_SCROLLED_WINDOW(scroll_area),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 GTK_POLICY_AUTOMATIC,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 gtk_container_add(GTK_CONTAINER(scroll_area), view);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
364 UI_APPLY_LAYOUT1(current, args);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
365 current->container->add(current->container, scroll_area, FALSE);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 // ct->current should point to view, not scroll_area, to make it possible
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 // to add a context menu
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
369 current->container->current = view;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 return scroll_area;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 GtkWidget* ui_get_tree_widget(UIWIDGET widget) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 GList *c = gtk_container_get_children(GTK_CONTAINER(widget));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 if(c) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 return c->data;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 return NULL;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 static char** targets2array(char *target0, va_list ap, int *nelm) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 int al = 16;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
385 char **targets = calloc(16, sizeof(char*));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
386 targets[0] = target0;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388 int i = 1;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389 char *target;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390 while((target = va_arg(ap, char*)) != NULL) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 if(i >= al) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 al *= 2;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 targets = realloc(targets, al*sizeof(char*));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
395 targets[i] = target;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396 i++;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 *nelm = i;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400 return targets;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 static GtkTargetEntry* targetstr2gtktargets(char **str, int nelm) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 GtkTargetEntry *targets = calloc(nelm, sizeof(GtkTargetEntry));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405 for(int i=0;i<nelm;i++) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 targets[i].target = str[i];
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408 return targets;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
412 va_list ap;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 va_start(ap, target0);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
414 int nelm;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415 char **targets = targets2array(target0, ap, &nelm);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416 va_end(ap);
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
417
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
418 // disabled
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
419 //ui_table_dragsource_a(tablewidget, actions, targets, nelm);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
420
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 free(targets);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
422 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
424 /*
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
425 void ui_table_dragsource_a(UIWIDGET tablewidget, int actions, char **targets, int nelm) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427 gtk_tree_view_enable_model_drag_source(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
428 GTK_TREE_VIEW(ui_get_tree_widget(tablewidget)),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
429 GDK_BUTTON1_MASK,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
430 t,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
431 nelm,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
432 GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_LINK);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433 free(t);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
435
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
436
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
438 va_list ap;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 va_start(ap, target0);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440 int nelm;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 char **targets = targets2array(target0, ap, &nelm);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 va_end(ap);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443 ui_table_dragdest_a(tablewidget, actions, targets, nelm);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
444 free(targets);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447 void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
448 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 gtk_tree_view_enable_model_drag_dest(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
450 GTK_TREE_VIEW(ui_get_tree_widget(tablewidget)),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
451 t,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452 nelm,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
453 GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_LINK);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
454 free(t);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455 }
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
456 */
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
457
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
458 void ui_listview_update(UiList *list, int i) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
459 UiListView *view = list->obj;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
460 GtkListStore *store = create_list_store(list, view->model);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
461 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store));
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
462 g_object_unref(G_OBJECT(store));
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
463 // TODO: free old model
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
466 void ui_listview_destroy(GtkWidget *w, UiListView *v) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468 ui_destroy_boundvar(v->obj->ctx, v->var);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
469 // TODO: destroy model?
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470 free(v);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
471 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
472
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 void ui_combobox_destroy(GtkWidget *w, UiListView *v) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474 gtk_combo_box_set_model(GTK_COMBO_BOX(w), NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
475 ui_destroy_boundvar(v->obj->ctx, v->var);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 // TODO: destroy model?
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477 free(v);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
481 void ui_listview_activate_event(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 GtkTreeView *treeview,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 GtkTreePath *path,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484 GtkTreeViewColumn *column,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485 UiTreeEventData *event)
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 UiListSelection *selection = ui_listview_selection(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488 gtk_tree_view_get_selection(treeview),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489 event);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491 UiEvent e;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
492 e.obj = event->obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
493 e.window = event->obj->window;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494 e.document = event->obj->ctx->document;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495 e.eventdata = selection;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496 e.intval = selection->count > 0 ? selection->rows[0] : -1;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
497 event->activate(&e, event->activatedata);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
499 if(selection->count > 0) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
500 free(selection->rows);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502 free(selection);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
503 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
504
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
505 void ui_listview_selection_event(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
506 GtkTreeSelection *treeselection,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
507 UiTreeEventData *event)
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
508 {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
509 UiListSelection *selection = ui_listview_selection(treeselection, event);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
510
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
511 UiEvent e;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512 e.obj = event->obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513 e.window = event->obj->window;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514 e.document = event->obj->ctx->document;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515 e.eventdata = selection;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 e.intval = selection->count > 0 ? selection->rows[0] : -1;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
517 event->selection(&e, event->selectiondata);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
519 if(selection->count > 0) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
520 free(selection->rows);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
521 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
522 free(selection);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
523 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
524
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
525 UiListSelection* ui_listview_selection(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
526 GtkTreeSelection *selection,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
527 UiTreeEventData *event)
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
528 {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
529 GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
530
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
531 UiListSelection *ls = malloc(sizeof(UiListSelection));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
532 ls->count = g_list_length(rows);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
533 ls->rows = calloc(ls->count, sizeof(int));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
534 GList *r = rows;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
535 int i = 0;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
536 while(r) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
537 GtkTreePath *path = r->data;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
538 ls->rows[i] = ui_tree_path_list_index(path);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
539 r = r->next;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
540 i++;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
541 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
542 return ls;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
543 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
544
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
545 int ui_tree_path_list_index(GtkTreePath *path) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
546 int depth = gtk_tree_path_get_depth(path);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
547 if(depth == 0) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
548 fprintf(stderr, "UiError: treeview selection: depth == 0\n");
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
549 return -1;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
550 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
551 int *indices = gtk_tree_path_get_indices(path);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
552 return indices[depth - 1];
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
553 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
554
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
555
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556 /* --------------------------- ComboBox --------------------------- */
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
557
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
558 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
559 UiObject* current = uic_current_obj(obj);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
560
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
561 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
562 model->getvalue = args.getvalue;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
563
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
564 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
565
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
566 GtkWidget *combobox = ui_create_combobox(obj, model, var, args.onactivate, args.onactivatedata);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
567 UI_APPLY_LAYOUT1(current, args);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
568 current->container->add(current->container, combobox, FALSE);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
569 current->container->current = combobox;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
570 return combobox;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
571 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
572
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
573 GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, ui_callback f, void *udata) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
574 GtkWidget *combobox = gtk_combo_box_new();
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
575
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
576 UiListView *uicbox = malloc(sizeof(UiListView));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
577 uicbox->obj = obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
578 uicbox->widget = combobox;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
579
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
580 UiList *list = var ? var->value : NULL;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
581 GtkListStore *listmodel = create_list_store(list, model);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
582
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
583 if(listmodel) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
584 gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel));
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
585 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
586
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
587 uicbox->var = var;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
588 uicbox->model = model;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
589
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
590 g_signal_connect(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
591 combobox,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
592 "destroy",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
593 G_CALLBACK(ui_combobox_destroy),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
594 uicbox);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
595
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
596 // bind var
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
597 if(list) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
598 list->update = ui_combobox_modelupdate;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
599 list->obj = uicbox;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
600 }
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
601
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
602 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
603 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
604 gtk_cell_layout_set_attributes(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
605 GTK_CELL_LAYOUT(combobox),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
606 renderer,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
607 "text",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
608 0,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
609 NULL);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
610 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
611
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
612 // add callback
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
613 if(f) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
614 UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
615 event->obj = obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
616 event->userdata = udata;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
617 event->callback = f;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
618 event->value = 0;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
619 event->customdata = NULL;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
620
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
621 g_signal_connect(
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
622 combobox,
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
623 "changed",
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
624 G_CALLBACK(ui_combobox_change_event),
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
625 event);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
626 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
627
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
628 return combobox;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
629 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
630
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
631 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
632 UiEvent event;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
633 event.obj = e->obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
634 event.window = event.obj->window;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
635 event.document = event.obj->ctx->document;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
636 event.eventdata = NULL;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
637 event.intval = gtk_combo_box_get_active(widget);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
638 e->callback(&event, e->userdata);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
639 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
640
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
641 void ui_combobox_modelupdate(UiList *list, int i) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
642 UiListView *view = list->obj;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
643 GtkListStore *store = create_list_store(view->var->value, view->model);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
644 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store));
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
645 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
646

mercurial