ui/gtk/list.c

Sun, 06 Oct 2024 18:43:06 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 Oct 2024 18:43:06 +0200
changeset 50
9c25e2616bfa
parent 46
31bc86844659
child 51
e324291ca9f8
permissions
-rw-r--r--

fix startup in case the dav config doesn't exist

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

mercurial