ui/gtk/list.c

11 days ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 06 Mar 2025 19:51:26 +0100 (11 days ago)
changeset 489
073a5e893050
parent 473
5fde0356b66a
child 490
0206161e92d5
permissions
-rw-r--r--

add option for static listview/dropdown (GTK)

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

mercurial