ui/gtk/list.c

Mon, 06 Jan 2025 22:22:55 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 06 Jan 2025 22:22:55 +0100
changeset 101
7b3a3130be44
parent 100
d2bd73d28ff1
permissions
-rw-r--r--

update ucx, toolkit

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
90
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
38 #include <cx/array_list.h>
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
39 #include <cx/linked_list.h>
90
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
40
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #include "list.h"
51
e324291ca9f8 add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
42 #include "icon.h"
88
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
43 #include "menu.h"
90
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
44 #include "dnd.h"
46
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
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 void* ui_strmodel_getvalue(void *elm, int column) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 return column == 0 ? elm : NULL;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
101
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
51 /*
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
52 static GtkTargetEntry targetentries[] =
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
53 {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
54 { "STRING", 0, 0 },
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
55 { "text/plain", 0, 1 },
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
56 { "text/uri-list", 0, 2 },
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
57 };
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
58 */
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
59
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
60 #if GTK_CHECK_VERSION(4, 10, 0)
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
61
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
62
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
63 /* BEGIN GObject wrapper for generic pointers */
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
64
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
65 typedef struct _ObjWrapper {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
66 GObject parent_instance;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
67 void *data;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
68 } ObjWrapper;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
69
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
70 typedef struct _ObjWrapperClass {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
71 GObjectClass parent_class;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
72 } ObjWrapperClass;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
73
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
74 G_DEFINE_TYPE(ObjWrapper, obj_wrapper, G_TYPE_OBJECT)
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
75
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
76 static void obj_wrapper_class_init(ObjWrapperClass *klass) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
77
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
78 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
79
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
80 static void obj_wrapper_init(ObjWrapper *self) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
81 self->data = NULL;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
82 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
83
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
84 ObjWrapper* obj_wrapper_new(void* data) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
85 ObjWrapper *obj = g_object_new(obj_wrapper_get_type(), NULL);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
86 obj->data = data;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
87 return obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
88 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
89
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
90 /* END GObject wrapper for generic pointers */
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
91
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
92 static void column_factory_setup(GtkListItemFactory *factory, GtkListItem *item, gpointer userdata) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
93 UiColData *col = userdata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
94 UiModel *model = col->listview->model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
95 UiModelType type = model->types[col->model_column];
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
96 if(type == UI_ICON_TEXT || type == UI_ICON_TEXT_FREE) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
97 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
98 GtkWidget *image = gtk_image_new();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
99 GtkWidget *label = gtk_label_new(NULL);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
100 BOX_ADD(hbox, image);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
101 BOX_ADD(hbox, label);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
102 gtk_list_item_set_child(item, hbox);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
103 g_object_set_data(G_OBJECT(hbox), "image", image);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
104 g_object_set_data(G_OBJECT(hbox), "label", label);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
105 } else if(type == UI_ICON) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
106 GtkWidget *image = gtk_image_new();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
107 gtk_list_item_set_child(item, image);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
108 } else {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
109 GtkWidget *label = gtk_label_new(NULL);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
110 gtk_label_set_xalign(GTK_LABEL(label), 0);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
111 gtk_list_item_set_child(item, label);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
112 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
113 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
114
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
115 static void column_factory_bind( GtkListItemFactory *factory, GtkListItem *item, gpointer userdata) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
116 UiColData *col = userdata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
117
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
118 ObjWrapper *obj = gtk_list_item_get_item(item);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
119 UiModel *model = col->listview->model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
120 UiModelType type = model->types[col->model_column];
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
121
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
122 void *data = model->getvalue(obj->data, col->data_column);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
123 GtkWidget *child = gtk_list_item_get_child(item);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
124
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
125 bool freevalue = TRUE;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
126 switch(type) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
127 case UI_STRING: {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
128 freevalue = FALSE;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
129 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
130 case UI_STRING_FREE: {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
131 gtk_label_set_label(GTK_LABEL(child), data);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
132 if(freevalue) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
133 free(data);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
134 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
135 break;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
136 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
137 case UI_INTEGER: {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
138 intptr_t intvalue = (intptr_t)data;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
139 char buf[32];
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
140 snprintf(buf, 32, "%d", (int)intvalue);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
141 gtk_label_set_label(GTK_LABEL(child), buf);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
142 break;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
143 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
144 case UI_ICON: {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
145 UiIcon *icon = data;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
146 if(icon) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
147 gtk_image_set_from_paintable(GTK_IMAGE(child), GDK_PAINTABLE(icon->info));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
148 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
149 break;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
150 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
151 case UI_ICON_TEXT: {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
152 freevalue = FALSE;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
153 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
154 case UI_ICON_TEXT_FREE: {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
155 void *data2 = model->getvalue(obj->data, col->data_column+1);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
156 GtkWidget *image = g_object_get_data(G_OBJECT(child), "image");
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
157 GtkWidget *label = g_object_get_data(G_OBJECT(child), "label");
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
158 if(data && image) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
159 UiIcon *icon = data;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
160 gtk_image_set_from_paintable(GTK_IMAGE(image), GDK_PAINTABLE(icon->info));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
161 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
162 if(data2 && label) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
163 gtk_label_set_label(GTK_LABEL(label), data2);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
164 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
165 if(freevalue) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
166 free(data2);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
167 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
168 break;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
169 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
170 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
171 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
172
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
173 static GtkSelectionModel* create_selection_model(UiListView *listview, GListStore *liststore, bool multiselection) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
174 GtkSelectionModel *selection_model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
175 if(multiselection) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
176 selection_model = GTK_SELECTION_MODEL(gtk_multi_selection_new(G_LIST_MODEL(liststore)));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
177 } else {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
178 selection_model = GTK_SELECTION_MODEL(gtk_single_selection_new(G_LIST_MODEL(liststore)));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
179 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
180 g_signal_connect(selection_model, "selection-changed", G_CALLBACK(ui_listview_selection_changed), listview);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
181 return selection_model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
182 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
183
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
184 static UiListView* create_listview(UiObject *obj, UiListArgs args) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
185 UiListView *tableview = malloc(sizeof(UiListView));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
186 memset(tableview, 0, sizeof(UiListView));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
187 tableview->obj = obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
188 tableview->model = args.model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
189 tableview->onactivate = args.onactivate;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
190 tableview->onactivatedata = args.onactivatedata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
191 tableview->onselection = args.onselection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
192 tableview->onselectiondata = args.onselectiondata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
193 tableview->ondragstart = args.ondragstart;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
194 tableview->ondragstartdata = args.ondragstartdata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
195 tableview->ondragcomplete = args.ondragcomplete;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
196 tableview->ondragcompletedata = args.ondragcompletedata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
197 tableview->ondrop = args.ondrop;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
198 tableview->ondropdata = args.ondropsdata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
199 tableview->selection.count = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
200 tableview->selection.rows = NULL;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
201 return tableview;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
202 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
203
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
204 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
205 UiObject* current = uic_current_obj(obj);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
206
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
207 // to simplify things and share code with ui_table_create, we also
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
208 // use a UiModel for the listview
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
209 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
210 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
211 args.model = model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
212
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
213 GListStore *ls = g_list_store_new(G_TYPE_OBJECT);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
214 UiListView *listview = create_listview(obj, args);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
215
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
216 listview->columns = malloc(sizeof(UiColData));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
217 listview->columns->listview = listview;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
218 listview->columns->data_column = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
219 listview->columns->model_column = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
220
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
221 GtkListItemFactory *factory = gtk_signal_list_item_factory_new();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
222 g_signal_connect(factory, "setup", G_CALLBACK(column_factory_setup), listview->columns);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
223 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
224
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
225 GtkSelectionModel *selection_model = create_selection_model(listview, ls, args.multiselection);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
226 GtkWidget *view = gtk_list_view_new(GTK_SELECTION_MODEL(selection_model), factory);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
227
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
228 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
229
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
230 // init listview
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
231 listview->widget = view;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
232 listview->var = var;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
233 listview->liststore = ls;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
234 listview->selectionmodel = selection_model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
235 g_signal_connect(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
236 view,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
237 "destroy",
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
238 G_CALLBACK(ui_listview_destroy),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
239 listview);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
240
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
241 // bind listview to list
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
242 if(var && var->value) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
243 UiList *list = var->value;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
244
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
245 list->obj = listview;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
246 list->update = ui_listview_update2;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
247 list->getselection = ui_listview_getselection2;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
248 list->setselection = ui_listview_setselection2;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
249
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
250 ui_update_liststore(ls, list);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
251 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
252
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
253 // event handling
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
254 if(args.onactivate) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
255 // columnview and listview can use the same callback function, because
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
256 // the first parameter (which is technically a different pointer type)
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
257 // is ignored
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
258 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), listview);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
259 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
260
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
261 // add widget to parent
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
262 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
263 gtk_scrolled_window_set_policy(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
264 GTK_SCROLLED_WINDOW(scroll_area),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
265 GTK_POLICY_AUTOMATIC,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
266 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
267 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
268
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
269 UI_APPLY_LAYOUT1(current, args);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
270 current->container->add(current->container, scroll_area, FALSE);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
271
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
272 // ct->current should point to view, not scroll_area, to make it possible
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
273 // to add a context menu
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
274 current->container->current = view;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
275
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
276 return scroll_area;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
277 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
278
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
279 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
280 UiObject* current = uic_current_obj(obj);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
281
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
282 // to simplify things and share code with ui_tableview_create, we also
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
283 // use a UiModel for the listview
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
284 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
285 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
286 args.model = model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
287
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
288 GListStore *ls = g_list_store_new(G_TYPE_OBJECT);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
289 UiListView *listview = create_listview(obj, args);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
290
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
291 listview->columns = malloc(sizeof(UiColData));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
292 listview->columns->listview = listview;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
293 listview->columns->data_column = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
294 listview->columns->model_column = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
295
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
296 GtkListItemFactory *factory = gtk_signal_list_item_factory_new();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
297 g_signal_connect(factory, "setup", G_CALLBACK(column_factory_setup), listview->columns);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
298 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), listview->columns);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
299
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
300 GtkWidget *view = gtk_drop_down_new(G_LIST_MODEL(ls), NULL);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
301 gtk_drop_down_set_factory(GTK_DROP_DOWN(view), factory);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
302
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
303 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
304
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
305 // init listview
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
306 listview->widget = view;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
307 listview->var = var;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
308 listview->liststore = ls;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
309 listview->selectionmodel = NULL;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
310 g_signal_connect(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
311 view,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
312 "destroy",
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
313 G_CALLBACK(ui_listview_destroy),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
314 listview);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
315
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
316 // bind listview to list
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
317 if(var && var->value) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
318 UiList *list = var->value;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
319
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
320 list->obj = listview;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
321 list->update = ui_listview_update2;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
322 list->getselection = ui_combobox_getselection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
323 list->setselection = ui_combobox_setselection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
324
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
325 ui_update_liststore(ls, list);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
326 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
327
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
328 // event handling
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
329 if(args.onactivate) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
330 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), listview);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
331 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
332
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
333 // add widget to parent
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
334 UI_APPLY_LAYOUT1(current, args);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
335 current->container->add(current->container, view, FALSE);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
336 return view;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
337 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
338
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
339 UIWIDGET ui_table_create(UiObject *obj, UiListArgs args) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
340 UiObject* current = uic_current_obj(obj);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
341
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
342 GListStore *ls = g_list_store_new(G_TYPE_OBJECT);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
343 //g_list_store_append(ls, v1);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
344
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
345 // create obj to store all relevant data we need for handling events
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
346 // and list updates
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
347 UiListView *tableview = create_listview(obj, args);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
348
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
349 GtkSelectionModel *selection_model = create_selection_model(tableview, ls, args.multiselection);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
350 GtkWidget *view = gtk_column_view_new(GTK_SELECTION_MODEL(selection_model));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
351
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
352 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
353
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
354 // init tableview
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
355 tableview->widget = view;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
356 tableview->var = var;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
357 tableview->liststore = ls;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
358 tableview->selectionmodel = selection_model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
359 g_signal_connect(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
360 view,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
361 "destroy",
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
362 G_CALLBACK(ui_listview_destroy),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
363 tableview);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
364
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
365
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
366 // create columns from UiModel
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
367 UiModel *model = args.model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
368 int columns = model ? model->columns : 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
369
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
370 tableview->columns = calloc(columns, sizeof(UiColData));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
371
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
372 int addi = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
373 for(int i=0;i<columns;i++) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
374 tableview->columns[i].listview = tableview;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
375 tableview->columns[i].model_column = i;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
376 tableview->columns[i].data_column = i+addi;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
377
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
378 if(model->types[i] == UI_ICON_TEXT || model->types[i] == UI_ICON_TEXT_FREE) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
379 // icon+text has 2 data columns
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
380 addi++;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
381 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
382
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
383 GtkListItemFactory *factory = gtk_signal_list_item_factory_new();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
384 UiColData *col = &tableview->columns[i];
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
385 g_signal_connect(factory, "setup", G_CALLBACK(column_factory_setup), col);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
386 g_signal_connect(factory, "bind", G_CALLBACK(column_factory_bind), col);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
387
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
388 GtkColumnViewColumn *column = gtk_column_view_column_new(model->titles[i], factory);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
389 gtk_column_view_column_set_resizable(column, true);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
390 gtk_column_view_append_column(GTK_COLUMN_VIEW(view), column);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
391 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
392
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
393 // bind listview to list
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
394 if(var && var->value) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
395 UiList *list = var->value;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
396
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
397 list->obj = tableview;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
398 list->update = ui_listview_update2;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
399 list->getselection = ui_listview_getselection2;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
400 list->setselection = ui_listview_setselection2;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
401
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
402 ui_update_liststore(ls, list);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
403 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
404
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
405 // event handling
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
406 if(args.onactivate) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
407 g_signal_connect(view, "activate", G_CALLBACK(ui_columnview_activate), tableview);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
408 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
409
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
410 // add widget to parent
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
411 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
412 gtk_scrolled_window_set_policy(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
413 GTK_SCROLLED_WINDOW(scroll_area),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
414 GTK_POLICY_AUTOMATIC,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
415 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
416 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
417
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
418 UI_APPLY_LAYOUT1(current, args);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
419 current->container->add(current->container, scroll_area, FALSE);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
420
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
421 // ct->current should point to view, not scroll_area, to make it possible
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
422 // to add a context menu
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
423 current->container->current = view;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
424
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
425 return scroll_area;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
426 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
427
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
428 static UiListSelection selectionmodel_get_selection(GtkSelectionModel *model) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
429 UiListSelection sel = { 0, NULL };
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
430 GtkBitset *bitset = gtk_selection_model_get_selection(model);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
431 int n = gtk_bitset_get_size(bitset);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
432 printf("bitset %d\n", n);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
433
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
434 gtk_bitset_unref(bitset);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
435 return sel;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
436 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
437
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
438 static void listview_event(ui_callback cb, void *cbdata, UiListView *view) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
439 UiEvent event;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
440 event.obj = view->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
441 event.document = event.obj->ctx->document;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
442 event.window = event.obj->window;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
443 event.intval = view->selection.count;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
444 event.eventdata = &view->selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
445 if(cb) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
446 cb(&event, cbdata);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
447 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
448 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
449
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
450 void ui_columnview_activate(void *ignore, guint position, gpointer userdata) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
451 UiListView *view = userdata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
452 listview_event(view->onactivate, view->onactivatedata, view);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
453 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
454
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
455 void ui_listview_selection_changed(GtkSelectionModel* self, guint position, guint n_items, gpointer userdata) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
456 UiListView *view = userdata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
457 free(view->selection.rows);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
458 view->selection.count = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
459 view->selection.rows = NULL;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
460
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
461 CX_ARRAY_DECLARE(int, newselection);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
462 cx_array_initialize(newselection, 8);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
463
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
464 size_t nitems = g_list_model_get_n_items(G_LIST_MODEL(view->liststore));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
465
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
466 for(size_t i=0;i<nitems;i++) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
467 if(gtk_selection_model_is_selected(view->selectionmodel, i)) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
468 int s = (int)i;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
469 cx_array_simple_add(newselection, s);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
470 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
471 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
472
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
473 if(newselection_size > 0) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
474 view->selection.count = newselection_size;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
475 view->selection.rows = newselection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
476 } else {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
477 free(newselection);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
478 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
479
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
480 listview_event(view->onselection, view->onselectiondata, view);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
481 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
482
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
483 void ui_dropdown_activate(GtkDropDown* self, gpointer userdata) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
484 UiListView *view = userdata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
485 guint selection = gtk_drop_down_get_selected(GTK_DROP_DOWN(view->widget));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
486 UiListSelection sel = { 0, NULL };
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
487 int sel2 = (int)selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
488 if(selection != GTK_INVALID_LIST_POSITION) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
489 sel.count = 1;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
490 sel.rows = &sel2;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
491 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
492
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
493 if(view->onactivate) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
494 UiEvent event;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
495 event.obj = view->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
496 event.document = event.obj->ctx->document;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
497 event.window = event.obj->window;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
498 event.intval = view->selection.count;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
499 event.eventdata = &view->selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
500 view->onactivate(&event, view->onactivatedata);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
501 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
502 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
503
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
504 void ui_update_liststore(GListStore *liststore, UiList *list) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
505 g_list_store_remove_all(liststore);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
506 void *elm = list->first(list);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
507 while(elm) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
508 ObjWrapper *obj = obj_wrapper_new(elm);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
509 g_list_store_append(liststore, obj);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
510 elm = list->next(list);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
511 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
512 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
513
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
514 void ui_listview_update2(UiList *list, int i) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
515 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
516 ui_update_liststore(view->liststore, view->var->value);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
517 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
518
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
519 UiListSelection ui_listview_getselection2(UiList *list) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
520 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
521 UiListSelection selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
522 selection.count = view->selection.count;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
523 selection.rows = calloc(selection.count, sizeof(int));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
524 memcpy(selection.rows, view->selection.rows, selection.count*sizeof(int));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
525 return selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
526 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
527
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
528 void ui_listview_setselection2(UiList *list, UiListSelection selection) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
529 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
530 UiListSelection newselection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
531 newselection.count = view->selection.count;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
532 if(selection.count > 0) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
533 newselection.rows = calloc(newselection.count, sizeof(int));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
534 memcpy(newselection.rows, selection.rows, selection.count*sizeof(int));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
535 } else {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
536 newselection.rows = NULL;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
537 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
538 free(view->selection.rows);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
539 view->selection = newselection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
540
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
541 gtk_selection_model_unselect_all(view->selectionmodel);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
542 if(selection.count > 0) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
543 for(int i=0;i<selection.count;i++) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
544 gtk_selection_model_select_item(view->selectionmodel, selection.rows[i], FALSE);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
545 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
546 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
547 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
548
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
549 UiListSelection ui_combobox_getselection(UiList *list) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
550 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
551 guint selection = gtk_drop_down_get_selected(GTK_DROP_DOWN(view->widget));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
552 UiListSelection sel = { 0, NULL };
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
553 if(selection != GTK_INVALID_LIST_POSITION) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
554 sel.count = 1;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
555 sel.rows = malloc(sizeof(int));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
556 sel.rows[0] = (int)selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
557 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
558 return sel;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
559 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
560
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
561 void ui_combobox_setselection(UiList *list, UiListSelection selection) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
562 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
563 if(selection.count > 0) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
564 gtk_drop_down_set_selected(GTK_DROP_DOWN(view->widget), selection.rows[0]);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
565 } else {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
566 gtk_drop_down_set_selected(GTK_DROP_DOWN(view->widget), GTK_INVALID_LIST_POSITION);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
567 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
568 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
569
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
570 #else
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
571
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
572 static GtkListStore* create_list_store(UiList *list, UiModel *model) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
573 int columns = model->columns;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
574 GType types[2*columns];
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
575 int c = 0;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
576 for(int i=0;i<columns;i++,c++) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
577 switch(model->types[i]) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
578 case UI_STRING:
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
579 case UI_STRING_FREE: types[c] = G_TYPE_STRING; break;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
580 case UI_INTEGER: types[c] = G_TYPE_INT; break;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
581 case UI_ICON: types[c] = G_TYPE_OBJECT; break;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
582 case UI_ICON_TEXT:
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
583 case UI_ICON_TEXT_FREE: {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
584 types[c] = G_TYPE_OBJECT;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
585 types[++c] = G_TYPE_STRING;
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 }
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
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
590 GtkListStore *store = gtk_list_store_newv(c, types);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
591
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
592 if(list) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
593 void *elm = list->first(list);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
594 while(elm) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
595 // insert new row
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
596 GtkTreeIter iter;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
597 gtk_list_store_insert (store, &iter, -1);
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 // set column values
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
600 int c = 0;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
601 for(int i=0;i<columns;i++,c++) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
602 void *data = model->getvalue(elm, c);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
603
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
604 GValue value = G_VALUE_INIT;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
605 switch(model->types[i]) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
606 case UI_STRING:
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
607 case UI_STRING_FREE: {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
608 g_value_init(&value, G_TYPE_STRING);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
609 g_value_set_string(&value, data);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
610 if(model->types[i] == UI_STRING_FREE) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
611 free(data);
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 break;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
614 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
615 case UI_INTEGER: {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
616 g_value_init(&value, G_TYPE_INT);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
617 int *intptr = data;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
618 g_value_set_int(&value, *intptr);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
619 break;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
620 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
621 case UI_ICON: {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
622 g_value_init(&value, G_TYPE_OBJECT);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
623 UiIcon *icon = data;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
624 #if GTK_MAJOR_VERSION >= 4
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
625 g_value_set_object(&value, icon->info); // TODO: does this work?
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
626 #else
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
627 if(!icon->pixbuf && icon->info) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
628 GError *error = NULL;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
629 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
630 icon->pixbuf = pixbuf;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
631 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
632
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
633 if(icon->pixbuf) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
634 g_value_set_object(&value, icon->pixbuf);
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 #endif
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
637 break;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
638 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
639 case UI_ICON_TEXT:
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
640 case UI_ICON_TEXT_FREE: {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
641 UiIcon *icon = data;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
642 #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
643 if(icon) {
9c25e2616bfa fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
644 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
645 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
646 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
647 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
648 }
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
649 #else
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
650 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
651 if(icon) {
9c25e2616bfa fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
652 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
653 GError *error = NULL;
9c25e2616bfa fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
654 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
655 icon->pixbuf = pixbuf;
9c25e2616bfa fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
656 }
9c25e2616bfa fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
657 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
658 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
659 gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
660 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
661 #endif
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
662 c++;
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 char *str = model->getvalue(elm, c);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
665 g_value_init(&value, G_TYPE_STRING);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
666 g_value_set_string(&value, str);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
667 if(model->types[i] == UI_ICON_TEXT_FREE) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
668 free(str);
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 break;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
671 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
672 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
673
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
674 gtk_list_store_set_value(store, &iter, c, &value);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
675 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
676
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
677 // next row
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
678 elm = list->next(list);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
679 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
680 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
681
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
682 return store;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
683 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
684
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
685
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
686 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
687 UiObject* current = uic_current_obj(obj);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
688
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
689 // create treeview
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
690 GtkWidget *view = gtk_tree_view_new();
60
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
691 ui_set_name_and_style(view, args.name, args.style_class);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
692 ui_set_widget_groups(obj->ctx, view, args.groups);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
693 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
694 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
695 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
696
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
697 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
698 #ifdef UI_GTK3
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
699 #if GTK_MINOR_VERSION >= 8
71
9e19ac687b9f fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
700 //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
701 #else
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
702 // TODO: implement for older gtk3
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
703 #endif
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
704 #else
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
705 // TODO: implement for gtk2
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
706 #endif
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
707
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
708 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
60
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
709 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
710
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
711 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
712
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
713 UiList *list = var ? var->value : NULL;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
714 GtkListStore *listmodel = create_list_store(list, model);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
715 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
71
9e19ac687b9f fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
716 g_object_unref(listmodel);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
717
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
718 UiListView *listview = malloc(sizeof(UiListView));
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
719 listview->obj = obj;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
720 listview->widget = view;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
721 listview->var = var;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
722 listview->model = model;
101
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
723 listview->selection.count = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
724 listview->selection.rows = NULL;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
725 g_signal_connect(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
726 view,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
727 "destroy",
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
728 G_CALLBACK(ui_listview_destroy),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
729 listview);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
730
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
731 // bind var
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
732 list->update = ui_listview_update;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
733 list->getselection = ui_listview_getselection;
65
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
734 list->setselection = ui_listview_setselection;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
735 list->obj = listview;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
736
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
737 // add callback
65
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
738 UiTreeEventData *event = malloc(sizeof(UiTreeEventData));
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
739 event->obj = obj;
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
740 event->activate = args.onactivate;
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
741 event->activatedata = args.onactivatedata;
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
742 event->selection = args.onselection;
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
743 event->selectiondata = args.onselectiondata;
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
744 g_signal_connect(
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
745 view,
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
746 "destroy",
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
747 G_CALLBACK(ui_destroy_userdata),
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
748 event);
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
749
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
750 if(args.onactivate) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
751 g_signal_connect(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
752 view,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
753 "row-activated",
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
754 G_CALLBACK(ui_listview_activate_event),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
755 event);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
756 }
65
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
757 if(args.onselection) {
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
758 GtkTreeSelection *selection = gtk_tree_view_get_selection(
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
759 GTK_TREE_VIEW(view));
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
760 g_signal_connect(
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
761 selection,
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
762 "changed",
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
763 G_CALLBACK(ui_listview_selection_event),
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
764 event);
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
765 }
88
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
766 if(args.contextmenu) {
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
767 UIMENU menu = ui_contextmenu_create(args.contextmenu, obj, view);
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
768 ui_widget_set_contextmenu(view, menu);
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
769 }
65
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
770
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
771
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
772 // add widget to the current container
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
773 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
774 gtk_scrolled_window_set_policy(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
775 GTK_SCROLLED_WINDOW(scroll_area),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
776 GTK_POLICY_AUTOMATIC,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
777 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
778 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
779
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
780 UI_APPLY_LAYOUT1(current, args);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
781 current->container->add(current->container, scroll_area, FALSE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
782
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
783 // 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
784 // to add a context menu
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
785 current->container->current = view;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
786
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
787 return scroll_area;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
788 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
789
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
790 UIWIDGET ui_table_create(UiObject *obj, UiListArgs args) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
791 UiObject* current = uic_current_obj(obj);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
792
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
793 // create treeview
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
794 GtkWidget *view = gtk_tree_view_new();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
795
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
796 UiModel *model = args.model;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
797 int columns = model ? model->columns : 0;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
798
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
799 int addi = 0;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
800 for(int i=0;i<columns;i++) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
801 GtkTreeViewColumn *column = NULL;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
802 if(model->types[i] == UI_ICON_TEXT) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
803 column = gtk_tree_view_column_new();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
804 gtk_tree_view_column_set_title(column, model->titles[i]);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
805
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
806 GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
807 GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
808
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
809 gtk_tree_view_column_pack_end(column, textrenderer, TRUE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
810 gtk_tree_view_column_pack_start(column, iconrenderer, FALSE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
811
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
812
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
813 gtk_tree_view_column_add_attribute(column, iconrenderer, "pixbuf", i);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
814 gtk_tree_view_column_add_attribute(column, textrenderer, "text", i+1);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
815
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
816 addi++;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
817 } else if (model->types[i] == UI_ICON) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
818 GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
819 column = gtk_tree_view_column_new_with_attributes(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
820 model->titles[i],
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
821 iconrenderer,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
822 "pixbuf",
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
823 i + addi,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
824 NULL);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
825 } else {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
826 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
827 column = gtk_tree_view_column_new_with_attributes(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
828 model->titles[i],
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
829 renderer,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
830 "text",
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
831 i + addi,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
832 NULL);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
833 }
80
1a908b060122 adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
834
1a908b060122 adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
835 int colsz = model->columnsize[i];
1a908b060122 adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
836 if(colsz > 0) {
1a908b060122 adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
837 gtk_tree_view_column_set_fixed_width(column, colsz);
1a908b060122 adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
838 } else if(colsz < 0) {
1a908b060122 adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
839 gtk_tree_view_column_set_expand(column, TRUE);
1a908b060122 adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
840 }
1a908b060122 adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
841
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
842 gtk_tree_view_column_set_resizable(column, TRUE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
843 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
844 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
845
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
846 //gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
847 #ifdef UI_GTK3
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
848 //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
849 #else
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
850
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
851 #endif
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
852
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
853 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
854
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
855 UiList *list = var ? var->value : NULL;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
856 GtkListStore *listmodel = create_list_store(list, model);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
857 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
71
9e19ac687b9f fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
858 g_object_unref(listmodel);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
859
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
860 //g_signal_connect(view, "drag-begin", G_CALLBACK(drag_begin), NULL);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
861 //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
862
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
863 // 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
864 // data changes
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
865 UiListView *tableview = malloc(sizeof(UiListView));
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
866 tableview->obj = obj;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
867 tableview->widget = view;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
868 tableview->var = var;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
869 tableview->model = model;
90
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
870 tableview->ondragstart = args.ondragstart;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
871 tableview->ondragstartdata = args.ondragstartdata;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
872 tableview->ondragcomplete = args.ondragcomplete;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
873 tableview->ondragcompletedata = args.ondragcompletedata;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
874 tableview->ondrop = args.ondrop;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
875 tableview->ondropdata = args.ondropsdata;
101
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
876 tableview->selection.count = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
877 tableview->selection.rows = NULL;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
878 g_signal_connect(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
879 view,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
880 "destroy",
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
881 G_CALLBACK(ui_listview_destroy),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
882 tableview);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
883
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
884 // bind var
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
885 list->update = ui_listview_update;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
886 list->getselection = ui_listview_getselection;
88
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
887 list->setselection = ui_listview_setselection;
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
888 list->obj = tableview;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
889
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
890 // add callback
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
891 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
892 event->obj = obj;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
893 event->activate = args.onactivate;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
894 event->selection = args.onselection;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
895 event->activatedata = args.onactivatedata;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
896 event->selectiondata = args.onselectiondata;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
897 if(args.onactivate) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
898 g_signal_connect(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
899 view,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
900 "row-activated",
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
901 G_CALLBACK(ui_listview_activate_event),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
902 event);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
903 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
904 if(args.onselection) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
905 GtkTreeSelection *selection = gtk_tree_view_get_selection(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
906 GTK_TREE_VIEW(view));
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
907 g_signal_connect(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
908 selection,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
909 "changed",
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
910 G_CALLBACK(ui_listview_selection_event),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
911 event);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
912 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
913 // TODO: destroy callback
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
914
90
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
915
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
916 if(args.ondragstart) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
917 ui_listview_add_dnd(tableview, &args);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
918 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
919 if(args.ondrop) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
920 ui_listview_enable_drop(tableview, &args);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
921 }
88
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
922
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
923 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
60
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
924 if(args.multiselection) {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
925 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
926 }
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
927
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
928 // add widget to the current container
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
929 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
930 gtk_scrolled_window_set_policy(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
931 GTK_SCROLLED_WINDOW(scroll_area),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
932 GTK_POLICY_AUTOMATIC,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
933 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
934 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
935
88
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
936 if(args.contextmenu) {
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
937 UIMENU menu = ui_contextmenu_create(args.contextmenu, obj, scroll_area);
98
16e84fac48bd in the repo list, show the stored-user if no user is configured
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
938 #if GTK_MAJOR_VERSION >= 4
88
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
939 ui_widget_set_contextmenu(scroll_area, menu);
98
16e84fac48bd in the repo list, show the stored-user if no user is configured
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
940 #else
16e84fac48bd in the repo list, show the stored-user if no user is configured
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
941 ui_widget_set_contextmenu(view, menu);
16e84fac48bd in the repo list, show the stored-user if no user is configured
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
942 #endif
88
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
943 }
e27526429d85 add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
944
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
945 UI_APPLY_LAYOUT1(current, args);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
946 current->container->add(current->container, scroll_area, FALSE);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
947
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
948 // 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
949 // to add a context menu
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
950 current->container->current = view;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
951
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
952 return scroll_area;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
953 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
954
101
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
955
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
956
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
957 void ui_listview_update(UiList *list, int i) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
958 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
959 GtkListStore *store = create_list_store(list, view->model);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
960 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
961 g_object_unref(G_OBJECT(store));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
962 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
963
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
964 UiListSelection ui_listview_getselection(UiList *list) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
965 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
966 UiListSelection selection = ui_listview_selection(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
967 gtk_tree_view_get_selection(GTK_TREE_VIEW(view->widget)),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
968 NULL);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
969 return selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
970 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
971
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
972 void ui_listview_setselection(UiList *list, UiListSelection selection) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
973 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
974 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view->widget));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
975 GtkTreePath *path = gtk_tree_path_new_from_indicesv(selection.rows, selection.count);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
976 gtk_tree_selection_select_path(sel, path);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
977 //g_object_unref(path);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
978 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
979
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
980
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
981
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
982 /* --------------------------- ComboBox --------------------------- */
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
983
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
984 UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
985 UiObject* current = uic_current_obj(obj);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
986
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
987 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
988 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
989
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
990 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
991
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
992 GtkWidget *combobox = ui_create_combobox(obj, model, var, args.onactivate, args.onactivatedata);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
993 ui_set_name_and_style(combobox, args.name, args.style_class);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
994 ui_set_widget_groups(obj->ctx, combobox, args.groups);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
995 UI_APPLY_LAYOUT1(current, args);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
996 current->container->add(current->container, combobox, FALSE);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
997 current->container->current = combobox;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
998 return combobox;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
999 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1000
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1001 GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, ui_callback f, void *udata) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1002 GtkWidget *combobox = gtk_combo_box_new();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1003
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1004 UiListView *uicbox = malloc(sizeof(UiListView));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1005 uicbox->obj = obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1006 uicbox->widget = combobox;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1007
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1008 UiList *list = var ? var->value : NULL;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1009 GtkListStore *listmodel = create_list_store(list, model);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1010
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1011 if(listmodel) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1012 gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1013 g_object_unref(listmodel);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1014 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1015
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1016 uicbox->var = var;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1017 uicbox->model = model;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1018
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1019 g_signal_connect(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1020 combobox,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1021 "destroy",
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1022 G_CALLBACK(ui_combobox_destroy),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1023 uicbox);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1024
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1025 // bind var
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1026 if(list) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1027 list->update = ui_combobox_modelupdate;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1028 list->getselection = ui_combobox_getselection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1029 list->setselection = ui_combobox_setselection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1030 list->obj = uicbox;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1031 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1032
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1033 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1034 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1035 gtk_cell_layout_set_attributes(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1036 GTK_CELL_LAYOUT(combobox),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1037 renderer,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1038 "text",
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1039 0,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1040 NULL);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1041 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1042
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1043 // add callback
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1044 if(f) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1045 UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1046 event->obj = obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1047 event->userdata = udata;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1048 event->callback = f;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1049 event->value = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1050 event->customdata = NULL;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1051
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1052 g_signal_connect(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1053 combobox,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1054 "changed",
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1055 G_CALLBACK(ui_combobox_change_event),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1056 event);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1057 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1058
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1059 return combobox;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1060 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1061
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1062 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1063 UiEvent event;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1064 event.obj = e->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1065 event.window = event.obj->window;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1066 event.document = event.obj->ctx->document;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1067 event.eventdata = NULL;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1068 event.intval = gtk_combo_box_get_active(widget);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1069 e->callback(&event, e->userdata);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1070 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1071
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1072 void ui_combobox_modelupdate(UiList *list, int i) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1073 UiListView *view = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1074 GtkListStore *store = create_list_store(view->var->value, view->model);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1075 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1076 g_object_unref(store);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1077 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1078
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1079 UiListSelection ui_combobox_getselection(UiList *list) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1080 UiListView *combobox = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1081 UiListSelection ret;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1082 ret.rows = malloc(sizeof(int*));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1083 ret.count = 1;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1084 ret.rows[0] = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox->widget));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1085 return ret;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1086 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1087
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1088 void ui_combobox_setselection(UiList *list, UiListSelection selection) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1089 UiListView *combobox = list->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1090 if(selection.count > 0) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1091 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox->widget), selection.rows[0]);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1092 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1093 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1094
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1095
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1096
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1097
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1098 void ui_listview_activate_event(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1099 GtkTreeView *treeview,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1100 GtkTreePath *path,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1101 GtkTreeViewColumn *column,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1102 UiTreeEventData *event)
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1103 {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1104 UiListSelection selection = ui_listview_selection(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1105 gtk_tree_view_get_selection(treeview),
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1106 event);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1107
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1108 UiEvent e;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1109 e.obj = event->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1110 e.window = event->obj->window;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1111 e.document = event->obj->ctx->document;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1112 e.eventdata = &selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1113 e.intval = selection.count > 0 ? selection.rows[0] : -1;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1114 event->activate(&e, event->activatedata);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1115
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1116 if(selection.count > 0) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1117 free(selection.rows);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1118 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1119 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1120
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1121 void ui_listview_selection_event(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1122 GtkTreeSelection *treeselection,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1123 UiTreeEventData *event)
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1124 {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1125 UiListSelection selection = ui_listview_selection(treeselection, event);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1126
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1127 UiEvent e;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1128 e.obj = event->obj;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1129 e.window = event->obj->window;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1130 e.document = event->obj->ctx->document;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1131 e.eventdata = &selection;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1132 e.intval = selection.count > 0 ? selection.rows[0] : -1;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1133 event->selection(&e, event->selectiondata);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1134
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1135 if(selection.count > 0) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1136 free(selection.rows);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1137 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1138 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1139
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1140 UiListSelection ui_listview_selection(
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1141 GtkTreeSelection *selection,
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1142 UiTreeEventData *event)
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1143 {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1144 GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1145
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1146 UiListSelection ls;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1147 ls.count = g_list_length(rows);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1148 ls.rows = calloc(ls.count, sizeof(int));
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1149 GList *r = rows;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1150 int i = 0;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1151 while(r) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1152 GtkTreePath *path = r->data;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1153 ls.rows[i] = ui_tree_path_list_index(path);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1154 r = r->next;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1155 i++;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1156 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1157 return ls;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1158 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1159
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1160 int ui_tree_path_list_index(GtkTreePath *path) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1161 int depth = gtk_tree_path_get_depth(path);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1162 if(depth == 0) {
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1163 fprintf(stderr, "UiError: treeview selection: depth == 0\n");
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1164 return -1;
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1165 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1166 int *indices = gtk_tree_path_get_indices(path);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1167 return indices[depth - 1];
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1168 }
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1169
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1170
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1171 #endif
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1172
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1173
90
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1174 #if GTK_MAJOR_VERSION >= 4
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1175
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1176 static GdkContentProvider *ui_listview_dnd_prepare(GtkDragSource *source, double x, double y, void *data) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1177 //printf("drag prepare\n");
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1178 UiListView *listview = data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1179
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1180 UiDnD *dnd = ui_create_dnd();
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1181 GdkContentProvider *provider = NULL;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1182
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1183
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1184 if(listview->ondragstart) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1185 UiEvent event;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1186 event.obj = listview->obj;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1187 event.window = event.obj->window;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1188 event.document = event.obj->ctx->document;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1189 event.eventdata = dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1190 event.intval = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1191 listview->ondragstart(&event, listview->ondragstartdata);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1192 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1193
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1194 size_t numproviders = cxListSize(dnd->providers);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1195 if(numproviders > 0) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1196 GdkContentProvider **providers = (GdkContentProvider**)cxListAt(dnd->providers, 0);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1197 provider = gdk_content_provider_new_union(providers, numproviders);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1198 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1199 ui_dnd_free(dnd);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1200
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1201 return provider;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1202 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1203
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1204 static void ui_listview_drag_begin(GtkDragSource *self, GdkDrag *drag, gpointer userdata) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1205 //printf("drag begin\n");
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1206 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1207
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1208 static void ui_listview_drag_end(GtkDragSource *self, GdkDrag *drag, gboolean delete_data, gpointer user_data) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1209 //printf("drag end\n");
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1210 UiListView *listview = user_data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1211 if(listview->ondragcomplete) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1212 UiDnD dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1213 dnd.target = NULL;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1214 dnd.value = NULL;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1215 dnd.providers = NULL;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1216 dnd.selected_action = gdk_drag_get_selected_action(drag);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1217 dnd.delete = delete_data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1218 dnd.accept = FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1219
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1220 UiEvent event;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1221 event.obj = listview->obj;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1222 event.window = event.obj->window;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1223 event.document = event.obj->ctx->document;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1224 event.eventdata = &dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1225 event.intval = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1226 listview->ondragcomplete(&event, listview->ondragcompletedata);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1227 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1228 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1229
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1230 static gboolean ui_listview_drop(
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1231 GtkDropTarget *target,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1232 const GValue* value,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1233 gdouble x,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1234 gdouble y,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1235 gpointer user_data)
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1236 {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1237 UiListView *listview = user_data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1238 UiDnD dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1239 dnd.providers = NULL;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1240 dnd.target = target;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1241 dnd.value = value;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1242 dnd.selected_action = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1243 dnd.delete = FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1244 dnd.accept = FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1245
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1246 if(listview->ondrop) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1247 dnd.accept = TRUE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1248 UiEvent event;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1249 event.obj = listview->obj;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1250 event.window = event.obj->window;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1251 event.document = event.obj->ctx->document;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1252 event.eventdata = &dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1253 event.intval = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1254 listview->ondrop(&event, listview->ondropdata);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1255 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1256
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1257 return dnd.accept;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1258 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1259
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1260 void ui_listview_add_dnd(UiListView *listview, UiListArgs *args) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1261 GtkDragSource *dragsource = gtk_drag_source_new();
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1262 gtk_widget_add_controller(listview->widget, GTK_EVENT_CONTROLLER(dragsource));
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1263 g_signal_connect (dragsource, "prepare", G_CALLBACK (ui_listview_dnd_prepare), listview);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1264 g_signal_connect(
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1265 dragsource,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1266 "drag-begin",
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1267 G_CALLBACK(ui_listview_drag_begin),
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1268 listview);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1269 g_signal_connect(
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1270 dragsource,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1271 "drag-end",
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1272 G_CALLBACK(ui_listview_drag_end),
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1273 listview);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1274 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1275
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1276 void ui_listview_enable_drop(UiListView *listview, UiListArgs *args) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1277 GtkDropTarget *target = gtk_drop_target_new(G_TYPE_INVALID, GDK_ACTION_COPY);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1278 gtk_widget_add_controller(listview->widget, GTK_EVENT_CONTROLLER(target));
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1279 GType default_types[2] = { GDK_TYPE_FILE_LIST, G_TYPE_STRING };
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1280 gtk_drop_target_set_gtypes(target, default_types, 2);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1281 g_signal_connect(target, "drop", G_CALLBACK(ui_listview_drop), listview);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1282 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1283
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1284 #else
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1285
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1286 static GtkTargetEntry targetentries[] =
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1287 {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1288 { "STRING", 0, 0 },
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1289 { "text/plain", 0, 1 },
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1290 { "text/uri-list", 0, 2 },
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1291 };
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1292
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1293 static void ui_listview_drag_getdata(
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1294 GtkWidget* self,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1295 GdkDragContext* context,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1296 GtkSelectionData* data,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1297 guint info,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1298 guint time,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1299 gpointer user_data)
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1300 {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1301 UiListView *listview = user_data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1302 UiDnD dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1303 dnd.context = context;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1304 dnd.data = data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1305 dnd.selected_action = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1306 dnd.delete = FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1307 dnd.accept = FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1308
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1309 if(listview->ondragstart) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1310 UiEvent event;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1311 event.obj = listview->obj;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1312 event.window = event.obj->window;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1313 event.document = event.obj->ctx->document;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1314 event.eventdata = &dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1315 event.intval = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1316 listview->ondragstart(&event, listview->ondragstartdata);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1317 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1318 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1319
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1320 static void ui_listview_drag_end(
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1321 GtkWidget *widget,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1322 GdkDragContext *context,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1323 guint time,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1324 gpointer user_data)
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1325 {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1326 UiListView *listview = user_data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1327 UiDnD dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1328 dnd.context = context;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1329 dnd.data = NULL;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1330 dnd.selected_action = gdk_drag_context_get_selected_action(context);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1331 dnd.delete = dnd.selected_action == UI_DND_ACTION_MOVE ? TRUE : FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1332 dnd.accept = FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1333 if(listview->ondragcomplete) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1334 UiEvent event;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1335 event.obj = listview->obj;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1336 event.window = event.obj->window;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1337 event.document = event.obj->ctx->document;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1338 event.eventdata = &dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1339 event.intval = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1340 listview->ondragcomplete(&event, listview->ondragcompletedata);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1341 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1342 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1343
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1344 void ui_listview_add_dnd(UiListView *listview, UiListArgs *args) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1345 gtk_tree_view_enable_model_drag_source(
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1346 GTK_TREE_VIEW(listview->widget),
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1347 GDK_BUTTON1_MASK,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1348 targetentries,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1349 2,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1350 GDK_ACTION_COPY);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1351
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1352 g_signal_connect(listview->widget, "drag-data-get", G_CALLBACK(ui_listview_drag_getdata), listview);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1353 g_signal_connect(listview->widget, "drag-end", G_CALLBACK(ui_listview_drag_end), listview);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1354 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1355
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1356
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1357
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1358
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1359 static void ui_listview_drag_data_received(
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1360 GtkWidget *self,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1361 GdkDragContext *context,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1362 gint x,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1363 gint y,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1364 GtkSelectionData *data,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1365 guint info,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1366 guint time,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1367 gpointer user_data)
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1368 {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1369 UiListView *listview = user_data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1370 UiDnD dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1371 dnd.context = context;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1372 dnd.data = data;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1373 dnd.selected_action = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1374 dnd.delete = FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1375 dnd.accept = FALSE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1376
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1377 if(listview->ondrop) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1378 dnd.accept = TRUE;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1379 UiEvent event;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1380 event.obj = listview->obj;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1381 event.window = event.obj->window;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1382 event.document = event.obj->ctx->document;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1383 event.eventdata = &dnd;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1384 event.intval = 0;
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1385 listview->ondrop(&event, listview->ondropdata);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1386 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1387 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1388
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1389 void ui_listview_enable_drop(UiListView *listview, UiListArgs *args) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1390 gtk_tree_view_enable_model_drag_dest(
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1391 GTK_TREE_VIEW(listview->widget),
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1392 targetentries,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1393 3,
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1394 GDK_ACTION_COPY);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1395 if(listview->ondrop) {
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1396 g_signal_connect(listview->widget, "drag_data_received", G_CALLBACK(ui_listview_drag_data_received), listview);
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1397 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1398 }
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1399
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1400 #endif
f501f0efc9a8 implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1401
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1402
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1403 GtkWidget* ui_get_tree_widget(UIWIDGET widget) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1404 return SCROLLEDWINDOW_GET_CHILD(widget);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1405 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1406
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1407 static char** targets2array(char *target0, va_list ap, int *nelm) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1408 int al = 16;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1409 char **targets = calloc(16, sizeof(char*));
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1410 targets[0] = target0;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1411
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1412 int i = 1;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1413 char *target;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1414 while((target = va_arg(ap, char*)) != NULL) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1415 if(i >= al) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1416 al *= 2;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1417 targets = realloc(targets, al*sizeof(char*));
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1418 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1419 targets[i] = target;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1420 i++;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1421 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1422
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1423 *nelm = i;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1424 return targets;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1425 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1426
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1427 /*
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1428 static GtkTargetEntry* targetstr2gtktargets(char **str, int nelm) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1429 GtkTargetEntry *targets = calloc(nelm, sizeof(GtkTargetEntry));
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1430 for(int i=0;i<nelm;i++) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1431 targets[i].target = str[i];
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1432 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1433 return targets;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1434 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1435 */
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1436
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1437 void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1438 va_list ap;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1439 va_start(ap, target0);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1440 int nelm;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1441 char **targets = targets2array(target0, ap, &nelm);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1442 va_end(ap);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1443
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1444 // disabled
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1445 //ui_table_dragsource_a(tablewidget, actions, targets, nelm);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1446
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1447 free(targets);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1448 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1449
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1450 /*
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1451 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
1452 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1453 gtk_tree_view_enable_model_drag_source(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1454 GTK_TREE_VIEW(ui_get_tree_widget(tablewidget)),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1455 GDK_BUTTON1_MASK,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1456 t,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1457 nelm,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1458 GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_LINK);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1459 free(t);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1460 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1461
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1462
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1463 void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1464 va_list ap;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1465 va_start(ap, target0);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1466 int nelm;
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1467 char **targets = targets2array(target0, ap, &nelm);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1468 va_end(ap);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1469 ui_table_dragdest_a(tablewidget, actions, targets, nelm);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1470 free(targets);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1471 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1472
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1473 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
1474 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1475 gtk_tree_view_enable_model_drag_dest(
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1476 GTK_TREE_VIEW(ui_get_tree_widget(tablewidget)),
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1477 t,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1478 nelm,
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1479 GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_LINK);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1480 free(t);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1481 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1482 */
65
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
1483
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1484 void ui_listview_destroy(GtkWidget *w, UiListView *v) {
71
9e19ac687b9f fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
1485 //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1486 ui_destroy_boundvar(v->obj->ctx, v->var);
101
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1487 #if GTK_CHECK_VERSION(4, 10, 0)
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1488 free(v->columns);
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1489 #endif
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1490 free(v->selection.rows);
46
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1491 free(v);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1492 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1493
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1494 void ui_combobox_destroy(GtkWidget *w, UiListView *v) {
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1495 ui_destroy_boundvar(v->obj->ctx, v->var);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1496 free(v);
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1497 }
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1498
31bc86844659 implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1499
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1500 /* ------------------------------ Source List ------------------------------ */
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1501
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1502 static void ui_destroy_sourcelist(GtkWidget *w, UiListBox *v) {
101
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1503 cxListFree(v->sublists);
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1504 free(v);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1505 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1506
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1507 static void sublist_destroy(UiObject *obj, UiListBoxSubList *sublist) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1508 free(sublist->header);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1509 ui_destroy_boundvar(obj->ctx, sublist->var);
101
7b3a3130be44 update ucx, toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 100
diff changeset
1510 cxListFree(sublist->widgets);
100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1511 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1512
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1513 static void listbox_create_header(GtkListBoxRow* row, GtkListBoxRow* before, gpointer user_data) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1514 // first rows in sublists have the ui_listbox property
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1515 UiListBox *listbox = g_object_get_data(G_OBJECT(row), "ui_listbox");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1516 if(!listbox) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1517 return;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1518 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1519
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1520 UiListBoxSubList *sublist = g_object_get_data(G_OBJECT(row), "ui_listbox_sublist");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1521 if(!sublist) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1522 return;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1523 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1524
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1525 if(sublist->separator) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1526 GtkWidget *separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1527 gtk_list_box_row_set_header(row, separator);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1528 } else if(sublist->header) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1529 GtkWidget *header = gtk_label_new(sublist->header);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1530 gtk_widget_set_halign(header, GTK_ALIGN_START);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1531 if(row == listbox->first_row) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1532 WIDGET_ADD_CSS_CLASS(header, "ui-listbox-header-first");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1533 } else {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1534 WIDGET_ADD_CSS_CLASS(header, "ui-listbox-header");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1535 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1536 gtk_list_box_row_set_header(row, header);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1537 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1538 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1539
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1540 #ifdef UI_GTK3
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1541 typedef struct _UiSidebarListBoxClass {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1542 GtkListBoxClass parent_class;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1543 } UiSidebarListBoxClass;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1544
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1545 typedef struct _UiSidebarListBox {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1546 GtkListBox parent_instance;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1547 } UiSidebarListBox;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1548
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1549 G_DEFINE_TYPE(UiSidebarListBox, ui_sidebar_list_box, GTK_TYPE_LIST_BOX)
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1550
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1551 /* Initialize the instance */
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1552 static void ui_sidebar_list_box_class_init(UiSidebarListBoxClass *klass) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1553 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1554 gtk_widget_class_set_css_name (widget_class, "placessidebar");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1555 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1556
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1557 static void ui_sidebar_list_box_init(UiSidebarListBox *self) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1558
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1559 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1560 #endif
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1561
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1562 UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs args) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1563 UiObject* current = uic_current_obj(obj);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1564
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1565 #ifdef UI_GTK3
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1566 GtkWidget *listbox = g_object_new(ui_sidebar_list_box_get_type(), NULL);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1567 #else
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1568 GtkWidget *listbox = gtk_list_box_new();
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1569 #endif
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1570 if(!args.style_class) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1571 #if GTK_MAJOR_VERSION >= 4
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1572 WIDGET_ADD_CSS_CLASS(listbox, "navigation-sidebar");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1573 #else
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1574 WIDGET_ADD_CSS_CLASS(listbox, "sidebar");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1575 #endif
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1576 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1577 gtk_list_box_set_header_func(GTK_LIST_BOX(listbox), listbox_create_header, NULL, NULL);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1578 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1579 SCROLLEDWINDOW_SET_CHILD(scroll_area, listbox);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1580
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1581 ui_set_name_and_style(listbox, args.name, args.style_class);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1582 ui_set_widget_groups(obj->ctx, listbox, args.groups);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1583 UI_APPLY_LAYOUT1(current, args);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1584 current->container->add(current->container, scroll_area, TRUE);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1585
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1586 UiListBox *uilistbox = malloc(sizeof(UiListBox));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1587 uilistbox->obj = obj;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1588 uilistbox->listbox = GTK_LIST_BOX(listbox);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1589 uilistbox->getvalue = args.getvalue;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1590 uilistbox->onactivate = args.onactivate;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1591 uilistbox->onactivatedata = args.onactivatedata;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1592 uilistbox->onbuttonclick = args.onbuttonclick;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1593 uilistbox->onbuttonclickdata = args.onbuttonclickdata;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1594 uilistbox->sublists = cxArrayListCreateSimple(sizeof(UiListBoxSubList), 4);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1595 uilistbox->sublists->collection.advanced_destructor = (cx_destructor_func2)sublist_destroy;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1596 uilistbox->sublists->collection.destructor_data = obj;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1597 uilistbox->first_row = NULL;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1598
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1599 if(args.numsublists == 0 && args.sublists) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1600 args.numsublists = INT_MAX;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1601 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1602 for(int i=0;i<args.numsublists;i++) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1603 UiSubList sublist = args.sublists[i];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1604 if(!sublist.varname && !sublist.value) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1605 break;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1606 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1607
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1608 UiListBoxSubList uisublist;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1609 uisublist.var = uic_widget_var(
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1610 obj->ctx,
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1611 current->ctx,
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1612 sublist.value,
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1613 sublist.varname,
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1614 UI_VAR_LIST);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1615 uisublist.numitems = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1616 uisublist.header = sublist.header ? strdup(sublist.header) : NULL;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1617 uisublist.separator = sublist.separator;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1618 uisublist.widgets = cxLinkedListCreateSimple(CX_STORE_POINTERS);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1619 uisublist.listbox = uilistbox;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1620 uisublist.userdata = sublist.userdata;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1621 uisublist.index = i;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1622
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1623 cxListAdd(uilistbox->sublists, &uisublist);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1624
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1625 // bind UiList
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1626 UiListBoxSubList *sublist_ptr = cxListAt(uilistbox->sublists, cxListSize(uilistbox->sublists)-1);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1627 UiList *list = uisublist.var->value;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1628 if(list) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1629 list->obj = sublist_ptr;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1630 list->update = ui_listbox_list_update;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1631 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1632 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1633 // fill items
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1634 ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1635
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1636 // register uilistbox for both widgets, so it doesn't matter which
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1637 // widget is used later
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1638 g_object_set_data(G_OBJECT(scroll_area), "ui_listbox", uilistbox);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1639 g_object_set_data(G_OBJECT(listbox), "ui_listbox", uilistbox);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1640
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1641 // signals
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1642 g_signal_connect(
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1643 listbox,
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1644 "destroy",
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1645 G_CALLBACK(ui_destroy_sourcelist),
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1646 uilistbox);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1647
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1648 if(args.onactivate) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1649 g_signal_connect(
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1650 listbox,
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1651 "row-activated",
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1652 G_CALLBACK(ui_listbox_row_activate),
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1653 NULL);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1654 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1655
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1656 return scroll_area;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1657 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1658
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1659 void ui_listbox_update(UiListBox *listbox, int from, int to) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1660 CxIterator i = cxListIterator(listbox->sublists);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1661 size_t pos = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1662 cx_foreach(UiListBoxSubList *, sublist, i) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1663 if(i.index < from) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1664 pos += sublist->numitems;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1665 continue;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1666 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1667 if(i.index > to) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1668 break;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1669 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1670
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1671 // reload sublist
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1672 ui_listbox_update_sublist(listbox, sublist, pos);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1673 pos += sublist->numitems;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1674 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1675 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1676
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1677 static GtkWidget* create_listbox_row(UiListBox *listbox, UiListBoxSubList *sublist, UiSubListItem *item, int index) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1678 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1679 if(item->icon) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1680 GtkWidget *icon = ICON_IMAGE(item->icon);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1681 BOX_ADD(hbox, icon);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1682 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1683 GtkWidget *label = gtk_label_new(item->label);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1684 gtk_widget_set_halign(label, GTK_ALIGN_START);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1685 BOX_ADD_EXPAND(hbox, label);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1686 // TODO: badge, button
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1687 GtkWidget *row = gtk_list_box_row_new();
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1688 LISTBOX_ROW_SET_CHILD(row, hbox);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1689
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1690 // signals
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1691 UiEventDataExt *event = malloc(sizeof(UiEventDataExt));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1692 memset(event, 0, sizeof(UiEventDataExt));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1693 event->obj = listbox->obj;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1694 event->customdata0 = sublist;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1695 event->customdata1 = sublist->var;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1696 event->customdata2 = item->eventdata;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1697 event->callback = listbox->onactivate;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1698 event->userdata = listbox->onactivatedata;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1699 event->callback2 = listbox->onbuttonclick;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1700 event->userdata2 = listbox->onbuttonclickdata;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1701 event->value0 = index;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1702
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1703 g_signal_connect(
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1704 row,
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1705 "destroy",
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1706 G_CALLBACK(ui_destroy_userdata),
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1707 event);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1708
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1709 g_object_set_data(G_OBJECT(row), "ui-listbox-row-eventdata", event);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1710
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1711 return row;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1712 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1713
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1714 void ui_listbox_update_sublist(UiListBox *listbox, UiListBoxSubList *sublist, size_t listbox_insert_index) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1715 // clear sublist
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1716 CxIterator r = cxListIterator(sublist->widgets);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1717 cx_foreach(GtkWidget*, widget, r) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1718 LISTBOX_REMOVE(listbox->listbox, widget);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1719 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1720 cxListClear(sublist->widgets);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1721
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1722 sublist->numitems = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1723
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1724 // create items for each UiList element
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1725 UiList *list = sublist->var->value;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1726 if(!list) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1727 return;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1728 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1729
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1730 size_t index = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1731 void *elm = list->first(list);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1732 while(elm) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1733 UiSubListItem item = { NULL, NULL, NULL, NULL, NULL, NULL };
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1734 listbox->getvalue(sublist->userdata, elm, index, &item);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1735
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1736 // create listbox item
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1737 GtkWidget *row = create_listbox_row(listbox, sublist, &item, (int)index);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1738 if(index == 0) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1739 // first row in the sublist, set ui_listbox data to the row
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1740 // which is then used by the headerfunc
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1741 g_object_set_data(G_OBJECT(row), "ui_listbox", listbox);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1742 g_object_set_data(G_OBJECT(row), "ui_listbox_sublist", sublist);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1743
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1744 if(listbox_insert_index == 0) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1745 // first row in the GtkListBox
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1746 listbox->first_row = GTK_LIST_BOX_ROW(row);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1747 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1748 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1749 intptr_t rowindex = listbox_insert_index + index;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1750 g_object_set_data(G_OBJECT(row), "ui_listbox_row_index", (gpointer)rowindex);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1751 gtk_list_box_insert(listbox->listbox, row, listbox_insert_index + index);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1752 cxListAdd(sublist->widgets, row);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1753
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1754 // cleanup
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1755 free(item.label);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1756 free(item.icon);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1757 free(item.button_label);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1758 free(item.button_icon);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1759 free(item.badge);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1760
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1761 // next row
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1762 elm = list->next(list);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1763 index++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1764 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1765
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1766 sublist->numitems = cxListSize(sublist->widgets);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1767 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1768
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1769 void ui_listbox_list_update(UiList *list, int i) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1770 UiListBoxSubList *sublist = list->obj;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1771 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1772
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1773 void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1774 UiEventDataExt *data = g_object_get_data(G_OBJECT(row), "ui-listbox-row-eventdata");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1775 if(!data) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1776 return;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1777 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1778 UiListBoxSubList *sublist = data->customdata0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1779
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1780 UiEvent event;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1781 event.obj = data->obj;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1782 event.window = event.obj->window;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1783 event.document = event.obj->ctx->document;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1784 event.eventdata = data->customdata2;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1785 event.intval = data->value0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1786
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1787 if(data->callback) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1788 data->callback(&event, data->userdata);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1789 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
1790 }

mercurial