ui/gtk/list.c

Mon, 13 Jan 2025 22:55:37 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 13 Jan 2025 22:55:37 +0100
changeset 446
535089a269c8
parent 445
5059f2435775
permissions
-rw-r--r--

implement table columnsize (GTK4)

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
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
204 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
205 UiObject* current = uic_current_obj(obj);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
206
439
bf7084544cb1 fix missing selection init in gtk3 listview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
207 // 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
208 // use a UiModel for the listview
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
209 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
210 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
211 args.model = model;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
212
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
213 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
214 UiListView *listview = create_listview(obj, args);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
215
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
216 listview->columns = malloc(sizeof(UiColData));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
217 listview->columns->listview = listview;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
218 listview->columns->data_column = 0;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
219 listview->columns->model_column = 0;
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 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
222 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
223 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
224
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
225 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
226 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
227
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
228 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
229
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
230 // init listview
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
231 listview->widget = view;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
232 listview->var = var;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
233 listview->liststore = ls;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
234 listview->selectionmodel = selection_model;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
235 g_signal_connect(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
236 view,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
237 "destroy",
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
238 G_CALLBACK(ui_listview_destroy),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
239 listview);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
240
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
241 // bind listview to list
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
242 if(var && var->value) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
243 UiList *list = var->value;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
244
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
245 list->obj = listview;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
246 list->update = ui_listview_update2;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
247 list->getselection = ui_listview_getselection2;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
248 list->setselection = ui_listview_setselection2;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
249
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
250 ui_update_liststore(ls, list);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
251 }
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 // event handling
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
254 if(args.onactivate) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
255 // 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
256 // 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
257 // is ignored
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
258 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
259 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
260
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
261 // add widget to parent
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
262 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
263 gtk_scrolled_window_set_policy(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
264 GTK_SCROLLED_WINDOW(scroll_area),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
265 GTK_POLICY_AUTOMATIC,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
266 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
267 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
268
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
269 UI_APPLY_LAYOUT1(current, args);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
270 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
271
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
272 // 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
273 // to add a context menu
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
274 current->container->current = view;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
275
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
276 return scroll_area;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
277 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
278
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
279 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
280 UiObject* current = uic_current_obj(obj);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
281
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
282 // 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
283 // use a UiModel for the listview
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
284 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
285 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
286 args.model = model;
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 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
289 UiListView *listview = create_listview(obj, args);
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 listview->columns = malloc(sizeof(UiColData));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
292 listview->columns->listview = listview;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
293 listview->columns->data_column = 0;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
294 listview->columns->model_column = 0;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
295
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
296 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
297 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
298 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
299
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
300 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
301 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
302
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
303 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
304
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
305 // init listview
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
306 listview->widget = view;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
307 listview->var = var;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
308 listview->liststore = ls;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
309 listview->selectionmodel = NULL;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
310 g_signal_connect(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
311 view,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
312 "destroy",
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
313 G_CALLBACK(ui_listview_destroy),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
314 listview);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
315
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
316 // bind listview to list
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
317 if(var && var->value) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
318 UiList *list = var->value;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
319
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
320 list->obj = listview;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
321 list->update = ui_listview_update2;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
322 list->getselection = ui_combobox_getselection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
323 list->setselection = ui_combobox_setselection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
324
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
325 ui_update_liststore(ls, list);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
326 }
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 // event handling
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
329 if(args.onactivate) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
330 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
331 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
332
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
333 // add widget to parent
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
334 UI_APPLY_LAYOUT1(current, args);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
335 current->container->add(current->container, view, FALSE);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
336 return view;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
337 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
338
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
339 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
340 UiObject* current = uic_current_obj(obj);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
341
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
342 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
343 //g_list_store_append(ls, v1);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
344
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
345 // 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
346 // and list updates
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
347 UiListView *tableview = create_listview(obj, args);
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 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
350 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
351
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
352 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
353
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
354 // init tableview
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
355 tableview->widget = view;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
356 tableview->var = var;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
357 tableview->liststore = ls;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
358 tableview->selectionmodel = selection_model;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
359 g_signal_connect(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
360 view,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
361 "destroy",
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
362 G_CALLBACK(ui_listview_destroy),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
363 tableview);
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
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
366 // create columns from UiModel
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
367 UiModel *model = args.model;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
368 int columns = model ? model->columns : 0;
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 tableview->columns = calloc(columns, sizeof(UiColData));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
371
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
372 int addi = 0;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
373 for(int i=0;i<columns;i++) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
374 tableview->columns[i].listview = tableview;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
375 tableview->columns[i].model_column = i;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
376 tableview->columns[i].data_column = i+addi;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
377
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
378 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
379 // icon+text has 2 data columns
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
380 addi++;
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
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
383 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
384 UiColData *col = &tableview->columns[i];
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
385 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
386 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
387
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
388 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
389 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
390 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
391
535089a269c8 implement table columnsize (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 445
diff changeset
392 int size = model->columnsize[i];
535089a269c8 implement table columnsize (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 445
diff changeset
393 if(size > 0) {
535089a269c8 implement table columnsize (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 445
diff changeset
394 gtk_column_view_column_set_fixed_width(column, size);
535089a269c8 implement table columnsize (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 445
diff changeset
395 } else if(size < 0) {
535089a269c8 implement table columnsize (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 445
diff changeset
396 gtk_column_view_column_set_expand(column, TRUE);
535089a269c8 implement table columnsize (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 445
diff changeset
397 }
438
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
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
400 // bind listview to list
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
401 if(var && var->value) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
402 UiList *list = var->value;
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 list->obj = tableview;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
405 list->update = ui_listview_update2;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
406 list->getselection = ui_listview_getselection2;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
407 list->setselection = ui_listview_setselection2;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
408
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
409 ui_update_liststore(ls, list);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
410 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
411
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
412 // event handling
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
413 if(args.onactivate) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
414 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
415 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
416
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
417 // add widget to parent
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
418 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
419 gtk_scrolled_window_set_policy(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
420 GTK_SCROLLED_WINDOW(scroll_area),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
421 GTK_POLICY_AUTOMATIC,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
422 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
423 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
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_APPLY_LAYOUT1(current, args);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
426 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
427
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
428 // 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
429 // to add a context menu
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
430 current->container->current = view;
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 return scroll_area;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
433 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
434
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
435 static UiListSelection selectionmodel_get_selection(GtkSelectionModel *model) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
436 UiListSelection sel = { 0, NULL };
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
437 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
438 int n = gtk_bitset_get_size(bitset);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
439 printf("bitset %d\n", n);
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 gtk_bitset_unref(bitset);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
442 return sel;
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
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
445 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
446 UiEvent event;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
447 event.obj = view->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
448 event.document = event.obj->ctx->document;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
449 event.window = event.obj->window;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
450 event.intval = view->selection.count;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
451 event.eventdata = &view->selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
452 if(cb) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
453 cb(&event, cbdata);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
454 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
455 }
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 void ui_columnview_activate(void *ignore, guint position, gpointer userdata) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
458 UiListView *view = userdata;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
459 listview_event(view->onactivate, view->onactivatedata, view);
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
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
462 void ui_listview_selection_changed(GtkSelectionModel* self, guint position, guint n_items, gpointer userdata) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
463 UiListView *view = userdata;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
464 free(view->selection.rows);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
465 view->selection.count = 0;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
466 view->selection.rows = NULL;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
467
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
468 CX_ARRAY_DECLARE(int, newselection);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
469 cx_array_initialize(newselection, 8);
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 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
472
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
473 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
474 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
475 int s = (int)i;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
476 cx_array_simple_add(newselection, s);
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 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
479
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
480 if(newselection_size > 0) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
481 view->selection.count = newselection_size;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
482 view->selection.rows = newselection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
483 } else {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
484 free(newselection);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
485 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
486
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
487 listview_event(view->onselection, view->onselectiondata, view);
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 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
491 UiListView *view = userdata;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
492 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
493 UiListSelection sel = { 0, NULL };
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
494 int sel2 = (int)selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
495 if(selection != GTK_INVALID_LIST_POSITION) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
496 sel.count = 1;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
497 sel.rows = &sel2;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
498 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
499
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
500 if(view->onactivate) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
501 UiEvent event;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
502 event.obj = view->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
503 event.document = event.obj->ctx->document;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
504 event.window = event.obj->window;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
505 event.intval = view->selection.count;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
506 event.eventdata = &view->selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
507 view->onactivate(&event, view->onactivatedata);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
508 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
509 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
510
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
511 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
512 g_list_store_remove_all(liststore);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
513 void *elm = list->first(list);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
514 while(elm) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
515 ObjWrapper *obj = obj_wrapper_new(elm);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
516 g_list_store_append(liststore, obj);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
517 elm = list->next(list);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
518 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
519 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
520
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
521 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
522 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
523 ui_update_liststore(view->liststore, view->var->value);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
524 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
525
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
526 UiListSelection ui_listview_getselection2(UiList *list) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
527 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
528 UiListSelection selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
529 selection.count = view->selection.count;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
530 selection.rows = calloc(selection.count, sizeof(int));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
531 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
532 return selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
533 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
534
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
535 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
536 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
537 UiListSelection newselection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
538 newselection.count = view->selection.count;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
539 if(selection.count > 0) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
540 newselection.rows = calloc(newselection.count, sizeof(int));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
541 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
542 } else {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
543 newselection.rows = NULL;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
544 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
545 free(view->selection.rows);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
546 view->selection = newselection;
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 gtk_selection_model_unselect_all(view->selectionmodel);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
549 if(selection.count > 0) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
550 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
551 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
552 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
553 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
554 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
555
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
556 UiListSelection ui_combobox_getselection(UiList *list) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
557 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
558 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
559 UiListSelection sel = { 0, NULL };
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
560 if(selection != GTK_INVALID_LIST_POSITION) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
561 sel.count = 1;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
562 sel.rows = malloc(sizeof(int));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
563 sel.rows[0] = (int)selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
564 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
565 return sel;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
566 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
567
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
568 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
569 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
570 if(selection.count > 0) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
571 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
572 } else {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
573 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
574 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
575 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
576
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
577 #else
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
578
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
579 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
580 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
581 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
582 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
583 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
584 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
585 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
586 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
587 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
588 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
589 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
590 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
591 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
592 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
593 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
594 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
595 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
596
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
597 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
598
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
599 if(list) {
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
600 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
601 while(elm) {
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
602 // 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
603 GtkTreeIter iter;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
604 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
605
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
606 // 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
607 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
608 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
609 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
610
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
611 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
612 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
613 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
614 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
615 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
616 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
617 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
618 free(data);
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
619 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
620 break;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
621 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
622 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
623 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
624 intptr_t intptr = (intptr_t)data;
5059f2435775 fix int columns in gtk3 tables
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
625 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
626 break;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
627 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
628 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
629 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
630 UiIcon *icon = data;
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
631 #if GTK_MAJOR_VERSION >= 4
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
632 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
633 #else
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
634 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
635 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
636 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
637 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
638 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
639
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
640 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
641 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
642 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
643 #endif
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
644 break;
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 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
647 case UI_ICON_TEXT_FREE: {
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
648 UiIcon *icon = data;
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
649 #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
650 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
651 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
652 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
653 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
654 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
655 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
656 #else
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
657 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
658 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
659 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
660 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
661 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
662 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
663 }
216d8912714c fix file icon and fix crash if a list icon is NULL
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
664 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
665 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
666 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
667 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
668 #endif
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
669 c++;
312
3f2b3d15668b fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
670
3f2b3d15668b fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
671 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
672 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
673 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
674 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
675 free(str);
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
676 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
677 break;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
678 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
679 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
680
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
681 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
682 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
683
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
684 // next row
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
685 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
686 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
687 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
688
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
689 return store;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
690 }
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
691
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
692
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
693 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) {
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
694 UiObject* current = uic_current_obj(obj);
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
695
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
696 // create treeview
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
697 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
698 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
699 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
700 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
701 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
702 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
703
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
704 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
705 #ifdef UI_GTK3
123
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
706 #if GTK_MINOR_VERSION >= 8
369
f16a1cde664e disable gtk3 single click list activation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 363
diff changeset
707 //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
708 #else
123
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
709 // TODO: implement for older gtk3
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
710 #endif
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
711 #else
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
712 // TODO: implement for gtk2
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
713 #endif
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
714
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
715 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
716 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
717
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
718 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
719
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
720 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
721 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
722 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
723 g_object_unref(listmodel);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
724
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
725 UiListView *listview = malloc(sizeof(UiListView));
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
726 listview->obj = obj;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
727 listview->widget = view;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
728 listview->var = var;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
729 listview->model = model;
439
bf7084544cb1 fix missing selection init in gtk3 listview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
730 listview->selection.count = 0;
bf7084544cb1 fix missing selection init in gtk3 listview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
731 listview->selection.rows = NULL;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
732 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
733 view,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
734 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
735 G_CALLBACK(ui_listview_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
736 listview);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
737
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
738 // bind var
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
739 list->update = ui_listview_update;
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
740 list->getselection = ui_listview_getselection;
363
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
741 list->setselection = ui_listview_setselection;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
742 list->obj = listview;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
743
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
744 // add callback
362
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
745 UiTreeEventData *event = malloc(sizeof(UiTreeEventData));
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
746 event->obj = obj;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
747 event->activate = args.onactivate;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
748 event->activatedata = args.onactivatedata;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
749 event->selection = args.onselection;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
750 event->selectiondata = args.onselectiondata;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
751 g_signal_connect(
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
752 view,
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
753 "destroy",
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
754 G_CALLBACK(ui_destroy_userdata),
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
755 event);
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
756
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
757 if(args.onactivate) {
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
758 g_signal_connect(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
759 view,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
760 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
761 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
762 event);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
763 }
362
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
764 if(args.onselection) {
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
765 GtkTreeSelection *selection = gtk_tree_view_get_selection(
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
766 GTK_TREE_VIEW(view));
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
767 g_signal_connect(
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
768 selection,
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
769 "changed",
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
770 G_CALLBACK(ui_listview_selection_event),
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
771 event);
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
772 }
390
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
773 if(args.contextmenu) {
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
774 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
775 ui_widget_set_contextmenu(view, menu);
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
776 }
362
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
777
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
778
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
779 // add widget to the current container
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
780 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
781 gtk_scrolled_window_set_policy(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
782 GTK_SCROLLED_WINDOW(scroll_area),
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
783 GTK_POLICY_AUTOMATIC,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
784 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
785 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
786
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
787 UI_APPLY_LAYOUT1(current, args);
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
788 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
789
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
790 // 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
791 // to add a context menu
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
792 current->container->current = view;
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
793
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
794 return scroll_area;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
795 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
796
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
797 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
798 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
799
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
800 // create treeview
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
801 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
802
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
803 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
804 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
805
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
806 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
807 for(int i=0;i<columns;i++) {
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
808 GtkTreeViewColumn *column = NULL;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
809 if(model->types[i] == UI_ICON_TEXT) {
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
810 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
811 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
812
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
813 GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
814 GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
815
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
816 gtk_tree_view_column_pack_end(column, textrenderer, TRUE);
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
817 gtk_tree_view_column_pack_start(column, iconrenderer, FALSE);
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
818
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
819
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
820 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
821 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
822
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
823 addi++;
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
824 } 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
825 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
826 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
827 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
828 iconrenderer,
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
829 "pixbuf",
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
830 i + addi,
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
831 NULL);
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
832 } else {
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
833 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
834 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
835 model->titles[i],
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
836 renderer,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
837 "text",
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
838 i + addi,
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
839 NULL);
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
840 }
380
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
841
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
842 int colsz = model->columnsize[i];
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
843 if(colsz > 0) {
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
844 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
845 } else if(colsz < 0) {
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
846 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
847 }
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
848
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
849 gtk_tree_view_column_set_resizable(column, TRUE);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
850 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
851 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
852
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
853 //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
854 #ifdef UI_GTK3
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
855 //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
856 #else
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
857
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
858 #endif
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
859
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
860 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
861
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
862 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
863 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
864 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
865 g_object_unref(listmodel);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
866
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
867 //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
868 //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
869
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
870 // 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
871 // data changes
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
872 UiListView *tableview = malloc(sizeof(UiListView));
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
873 tableview->obj = obj;
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
874 tableview->widget = view;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
875 tableview->var = var;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
876 tableview->model = model;
394
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
877 tableview->ondragstart = args.ondragstart;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
878 tableview->ondragstartdata = args.ondragstartdata;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
879 tableview->ondragcomplete = args.ondragcomplete;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
880 tableview->ondragcompletedata = args.ondragcompletedata;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
881 tableview->ondrop = args.ondrop;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
882 tableview->ondropdata = args.ondropsdata;
436
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
883 tableview->selection.count = 0;
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
884 tableview->selection.rows = NULL;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
885 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
886 view,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
887 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
888 G_CALLBACK(ui_listview_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
889 tableview);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
890
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
891 // bind var
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
892 list->update = ui_listview_update;
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
893 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
894 list->setselection = ui_listview_setselection;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
895 list->obj = tableview;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
896
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
897 // add callback
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
898 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
899 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
900 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
901 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
902 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
903 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
904 if(args.onactivate) {
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
905 g_signal_connect(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
906 view,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
907 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
908 G_CALLBACK(ui_listview_activate_event),
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
909 event);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
910 }
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
911 if(args.onselection) {
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
912 GtkTreeSelection *selection = gtk_tree_view_get_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
913 GTK_TREE_VIEW(view));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
914 g_signal_connect(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
915 selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
916 "changed",
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
917 G_CALLBACK(ui_listview_selection_event),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
918 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
919 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
920 // TODO: destroy callback
390
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
921
394
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
922
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
923 if(args.ondragstart) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
924 ui_listview_add_dnd(tableview, &args);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
925 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
926 if(args.ondrop) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
927 ui_listview_enable_drop(tableview, &args);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
928 }
391
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
929
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
930 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
931 if(args.multiselection) {
70305d427f25 fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
932 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
70305d427f25 fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
933 }
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
934
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
935 // add widget to the current container
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
936 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
937 gtk_scrolled_window_set_policy(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
938 GTK_SCROLLED_WINDOW(scroll_area),
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
939 GTK_POLICY_AUTOMATIC,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
940 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
941 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
942
391
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
943 if(args.contextmenu) {
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
944 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
945 #if GTK_MAJOR_VERSION >= 4
391
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
946 ui_widget_set_contextmenu(scroll_area, menu);
401
55fb6bad549d fix gtk3 tableview contextmenu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 394
diff changeset
947 #else
55fb6bad549d fix gtk3 tableview contextmenu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 394
diff changeset
948 ui_widget_set_contextmenu(view, menu);
55fb6bad549d fix gtk3 tableview contextmenu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 394
diff changeset
949 #endif
391
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
950 }
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
951
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
952 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
953 current->container->add(current->container, scroll_area, FALSE);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
954
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
955 // 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
956 // 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
957 current->container->current = view;
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
958
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
959 return scroll_area;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
960 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
961
436
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
962
438
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
963
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
964 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
965 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
966 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
967 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
968 g_object_unref(G_OBJECT(store));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
969 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
970
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
971 UiListSelection ui_listview_getselection(UiList *list) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
972 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
973 UiListSelection selection = ui_listview_selection(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
974 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
975 NULL);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
976 return selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
977 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
978
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
979 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
980 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
981 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
982 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
983 gtk_tree_selection_select_path(sel, path);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
984 //g_object_unref(path);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
985 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
986
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
987
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
988
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
989 /* --------------------------- ComboBox --------------------------- */
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
990
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
991 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
992 UiObject* current = uic_current_obj(obj);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
993
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
994 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
995 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
996
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
997 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
998
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
999 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
1000 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
1001 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
1002 UI_APPLY_LAYOUT1(current, args);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1003 current->container->add(current->container, combobox, FALSE);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1004 current->container->current = combobox;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1005 return combobox;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1006 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1007
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1008 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
1009 GtkWidget *combobox = gtk_combo_box_new();
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 UiListView *uicbox = malloc(sizeof(UiListView));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1012 uicbox->obj = obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1013 uicbox->widget = combobox;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1014
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1015 UiList *list = var ? var->value : NULL;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1016 GtkListStore *listmodel = create_list_store(list, model);
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 if(listmodel) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1019 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
1020 g_object_unref(listmodel);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1021 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1022
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1023 uicbox->var = var;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1024 uicbox->model = model;
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 g_signal_connect(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1027 combobox,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1028 "destroy",
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1029 G_CALLBACK(ui_combobox_destroy),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1030 uicbox);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1031
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1032 // bind var
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1033 if(list) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1034 list->update = ui_combobox_modelupdate;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1035 list->getselection = ui_combobox_getselection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1036 list->setselection = ui_combobox_setselection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1037 list->obj = uicbox;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1038 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1039
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1040 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1041 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
1042 gtk_cell_layout_set_attributes(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1043 GTK_CELL_LAYOUT(combobox),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1044 renderer,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1045 "text",
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1046 0,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1047 NULL);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1048 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
1049
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1050 // add callback
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1051 if(f) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1052 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
1053 event->obj = obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1054 event->userdata = udata;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1055 event->callback = f;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1056 event->value = 0;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1057 event->customdata = NULL;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1058
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1059 g_signal_connect(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1060 combobox,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1061 "changed",
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1062 G_CALLBACK(ui_combobox_change_event),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1063 event);
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
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1066 return combobox;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1067 }
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 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
1070 UiEvent event;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1071 event.obj = e->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1072 event.window = event.obj->window;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1073 event.document = event.obj->ctx->document;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1074 event.eventdata = NULL;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1075 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
1076 e->callback(&event, e->userdata);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1077 }
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 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
1080 UiListView *view = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1081 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
1082 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
1083 g_object_unref(store);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1084 }
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 UiListSelection ui_combobox_getselection(UiList *list) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1087 UiListView *combobox = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1088 UiListSelection ret;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1089 ret.rows = malloc(sizeof(int*));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1090 ret.count = 1;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1091 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
1092 return ret;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1093 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1094
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1095 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
1096 UiListView *combobox = list->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1097 if(selection.count > 0) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1098 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
1099 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1100 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1101
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1102
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1103
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1104
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1105 void ui_listview_activate_event(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1106 GtkTreeView *treeview,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1107 GtkTreePath *path,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1108 GtkTreeViewColumn *column,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1109 UiTreeEventData *event)
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1110 {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1111 UiListSelection selection = ui_listview_selection(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1112 gtk_tree_view_get_selection(treeview),
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1113 event);
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 UiEvent e;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1116 e.obj = event->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1117 e.window = event->obj->window;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1118 e.document = event->obj->ctx->document;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1119 e.eventdata = &selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1120 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
1121 event->activate(&e, event->activatedata);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1122
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1123 if(selection.count > 0) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1124 free(selection.rows);
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 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1127
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1128 void ui_listview_selection_event(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1129 GtkTreeSelection *treeselection,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1130 UiTreeEventData *event)
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 UiListSelection selection = ui_listview_selection(treeselection, event);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1133
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1134 UiEvent e;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1135 e.obj = event->obj;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1136 e.window = event->obj->window;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1137 e.document = event->obj->ctx->document;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1138 e.eventdata = &selection;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1139 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
1140 event->selection(&e, event->selectiondata);
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 if(selection.count > 0) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1143 free(selection.rows);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1144 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1145 }
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 UiListSelection ui_listview_selection(
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1148 GtkTreeSelection *selection,
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1149 UiTreeEventData *event)
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 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
1152
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1153 UiListSelection ls;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1154 ls.count = g_list_length(rows);
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1155 ls.rows = calloc(ls.count, sizeof(int));
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1156 GList *r = rows;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1157 int i = 0;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1158 while(r) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1159 GtkTreePath *path = r->data;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1160 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
1161 r = r->next;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1162 i++;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1163 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1164 return ls;
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1165 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1166
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1167 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
1168 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
1169 if(depth == 0) {
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1170 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
1171 return -1;
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 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
1174 return indices[depth - 1];
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1175 }
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1176
7b1d715e5c11 add new gtk4 listview/combobox implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
1177
436
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
1178 #endif
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
1179
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
1180
394
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1181 #if GTK_MAJOR_VERSION >= 4
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1182
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1183 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
1184 //printf("drag prepare\n");
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1185 UiListView *listview = data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1186
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1187 UiDnD *dnd = ui_create_dnd();
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1188 GdkContentProvider *provider = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1189
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1190
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1191 if(listview->ondragstart) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1192 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1193 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1194 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1195 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1196 event.eventdata = dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1197 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1198 listview->ondragstart(&event, listview->ondragstartdata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1199 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1200
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1201 size_t numproviders = cxListSize(dnd->providers);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1202 if(numproviders > 0) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1203 GdkContentProvider **providers = (GdkContentProvider**)cxListAt(dnd->providers, 0);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1204 provider = gdk_content_provider_new_union(providers, numproviders);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1205 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1206 ui_dnd_free(dnd);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1207
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1208 return provider;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1209 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1210
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1211 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
1212 //printf("drag begin\n");
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1213 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1214
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1215 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
1216 //printf("drag end\n");
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1217 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1218 if(listview->ondragcomplete) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1219 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1220 dnd.target = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1221 dnd.value = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1222 dnd.providers = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1223 dnd.selected_action = gdk_drag_get_selected_action(drag);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1224 dnd.delete = delete_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1225 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1226
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1227 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1228 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1229 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1230 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1231 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1232 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1233 listview->ondragcomplete(&event, listview->ondragcompletedata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1234 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1235 }
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 static gboolean ui_listview_drop(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1238 GtkDropTarget *target,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1239 const GValue* value,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1240 gdouble x,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1241 gdouble y,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1242 gpointer user_data)
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1243 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1244 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1245 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1246 dnd.providers = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1247 dnd.target = target;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1248 dnd.value = value;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1249 dnd.selected_action = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1250 dnd.delete = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1251 dnd.accept = FALSE;
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 if(listview->ondrop) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1254 dnd.accept = TRUE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1255 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1256 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1257 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1258 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1259 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1260 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1261 listview->ondrop(&event, listview->ondropdata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1262 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1263
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1264 return dnd.accept;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1265 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1266
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1267 void ui_listview_add_dnd(UiListView *listview, UiListArgs *args) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1268 GtkDragSource *dragsource = gtk_drag_source_new();
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1269 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
1270 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
1271 g_signal_connect(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1272 dragsource,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1273 "drag-begin",
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1274 G_CALLBACK(ui_listview_drag_begin),
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1275 listview);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1276 g_signal_connect(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1277 dragsource,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1278 "drag-end",
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1279 G_CALLBACK(ui_listview_drag_end),
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1280 listview);
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 void ui_listview_enable_drop(UiListView *listview, UiListArgs *args) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1284 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
1285 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
1286 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
1287 gtk_drop_target_set_gtypes(target, default_types, 2);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1288 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
1289 }
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 #else
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1292
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1293 static GtkTargetEntry targetentries[] =
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1294 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1295 { "STRING", 0, 0 },
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1296 { "text/plain", 0, 1 },
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1297 { "text/uri-list", 0, 2 },
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1298 };
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 static void ui_listview_drag_getdata(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1301 GtkWidget* self,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1302 GdkDragContext* context,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1303 GtkSelectionData* data,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1304 guint info,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1305 guint time,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1306 gpointer user_data)
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1307 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1308 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1309 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1310 dnd.context = context;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1311 dnd.data = data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1312 dnd.selected_action = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1313 dnd.delete = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1314 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1315
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1316 if(listview->ondragstart) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1317 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1318 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1319 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1320 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1321 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1322 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1323 listview->ondragstart(&event, listview->ondragstartdata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1324 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1325 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1326
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1327 static void ui_listview_drag_end(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1328 GtkWidget *widget,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1329 GdkDragContext *context,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1330 guint time,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1331 gpointer user_data)
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1332 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1333 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1334 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1335 dnd.context = context;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1336 dnd.data = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1337 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
1338 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
1339 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1340 if(listview->ondragcomplete) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1341 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1342 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1343 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1344 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1345 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1346 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1347 listview->ondragcomplete(&event, listview->ondragcompletedata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1348 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1349 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1350
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1351 void ui_listview_add_dnd(UiListView *listview, UiListArgs *args) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1352 gtk_tree_view_enable_model_drag_source(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1353 GTK_TREE_VIEW(listview->widget),
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1354 GDK_BUTTON1_MASK,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1355 targetentries,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1356 2,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1357 GDK_ACTION_COPY);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1358
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1359 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
1360 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
1361 }
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
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1364
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1365
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1366 static void ui_listview_drag_data_received(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1367 GtkWidget *self,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1368 GdkDragContext *context,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1369 gint x,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1370 gint y,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1371 GtkSelectionData *data,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1372 guint info,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1373 guint time,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1374 gpointer user_data)
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1375 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1376 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1377 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1378 dnd.context = context;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1379 dnd.data = data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1380 dnd.selected_action = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1381 dnd.delete = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1382 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1383
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1384 if(listview->ondrop) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1385 dnd.accept = TRUE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1386 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1387 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1388 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1389 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1390 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1391 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1392 listview->ondrop(&event, listview->ondropdata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1393 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1394 }
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 void ui_listview_enable_drop(UiListView *listview, UiListArgs *args) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1397 gtk_tree_view_enable_model_drag_dest(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1398 GTK_TREE_VIEW(listview->widget),
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1399 targetentries,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1400 3,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1401 GDK_ACTION_COPY);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1402 if(listview->ondrop) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1403 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
1404 }
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
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1407 #endif
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
1408
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
1409
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1410 GtkWidget* ui_get_tree_widget(UIWIDGET widget) {
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
1411 return SCROLLEDWINDOW_GET_CHILD(widget);
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1412 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1413
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1414 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
1415 int al = 16;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1416 char **targets = calloc(16, sizeof(char*));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1417 targets[0] = target0;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1418
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1419 int i = 1;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1420 char *target;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1421 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
1422 if(i >= al) {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1423 al *= 2;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1424 targets = realloc(targets, al*sizeof(char*));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1425 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1426 targets[i] = target;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1427 i++;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1428 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1429
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1430 *nelm = i;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1431 return targets;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1432 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1433
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
1434 /*
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1435 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
1436 GtkTargetEntry *targets = calloc(nelm, sizeof(GtkTargetEntry));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1437 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
1438 targets[i].target = str[i];
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1439 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1440 return targets;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1441 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
1442 */
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1443
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1444 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
1445 va_list ap;
150
5cee4cb5ad79 fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
1446 va_start(ap, target0);
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1447 int nelm;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1448 char **targets = targets2array(target0, ap, &nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1449 va_end(ap);
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
1450
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
1451 // disabled
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
1452 //ui_table_dragsource_a(tablewidget, actions, targets, nelm);
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
1453
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1454 free(targets);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1455 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1456
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
1457 /*
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1458 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
1459 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1460 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
1461 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
1462 GDK_BUTTON1_MASK,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1463 t,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1464 nelm,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1465 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
1466 free(t);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1467 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1468
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
1469
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1470 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
1471 va_list ap;
150
5cee4cb5ad79 fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
1472 va_start(ap, target0);
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1473 int nelm;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1474 char **targets = targets2array(target0, ap, &nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1475 va_end(ap);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1476 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
1477 free(targets);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1478 }
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 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
1481 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1482 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
1483 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
1484 t,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1485 nelm,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1486 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
1487 free(t);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
1488 }
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
1489 */
363
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
1490
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
1491 void ui_listview_destroy(GtkWidget *w, UiListView *v) {
370
822fcb83bdf1 improve window close handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
1492 //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL);
152
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
1493 ui_destroy_boundvar(v->obj->ctx, v->var);
436
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
1494 #if GTK_CHECK_VERSION(4, 10, 0)
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
1495 free(v->columns);
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
1496 #endif
222205801430 add new gtk4 tableview implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 413
diff changeset
1497 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
1498 free(v);
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
1499 }
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
1500
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
1501 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
1502 ui_destroy_boundvar(v->obj->ctx, v->var);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
1503 free(v);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
1504 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
1505
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
1506
411
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1507 /* ------------------------------ Source List ------------------------------ */
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1508
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1509 static void ui_destroy_sourcelist(GtkWidget *w, UiListBox *v) {
440
7c4b9cba09ca update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 439
diff changeset
1510 cxListFree(v->sublists);
411
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1511 free(v);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1512 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1513
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1514 static void sublist_destroy(UiObject *obj, UiListBoxSubList *sublist) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1515 free(sublist->header);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1516 ui_destroy_boundvar(obj->ctx, sublist->var);
440
7c4b9cba09ca update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 439
diff changeset
1517 cxListFree(sublist->widgets);
411
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1518 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1519
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1520 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
1521 // first rows in sublists have the ui_listbox property
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1522 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
1523 if(!listbox) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1524 return;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1525 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1526
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1527 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
1528 if(!sublist) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1529 return;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1530 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1531
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1532 if(sublist->separator) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1533 GtkWidget *separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1534 gtk_list_box_row_set_header(row, separator);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1535 } else if(sublist->header) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1536 GtkWidget *header = gtk_label_new(sublist->header);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1537 gtk_widget_set_halign(header, GTK_ALIGN_START);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1538 if(row == listbox->first_row) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1539 WIDGET_ADD_CSS_CLASS(header, "ui-listbox-header-first");
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1540 } else {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1541 WIDGET_ADD_CSS_CLASS(header, "ui-listbox-header");
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1542 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1543 gtk_list_box_row_set_header(row, header);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1544 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1545 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1546
413
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1547 #ifdef UI_GTK3
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1548 typedef struct _UiSidebarListBoxClass {
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1549 GtkListBoxClass parent_class;
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1550 } UiSidebarListBoxClass;
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1551
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1552 typedef struct _UiSidebarListBox {
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1553 GtkListBox parent_instance;
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1554 } UiSidebarListBox;
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1555
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1556 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
1557
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1558 /* Initialize the instance */
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1559 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
1560 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1561 gtk_widget_class_set_css_name (widget_class, "placessidebar");
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1562 }
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1563
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1564 static void ui_sidebar_list_box_init(UiSidebarListBox *self) {
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1565
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1566 }
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1567 #endif
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1568
411
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1569 UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs args) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1570 UiObject* current = uic_current_obj(obj);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1571
413
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1572 #ifdef UI_GTK3
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1573 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
1574 #else
411
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1575 GtkWidget *listbox = gtk_list_box_new();
413
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1576 #endif
411
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1577 if(!args.style_class) {
413
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1578 #if GTK_MAJOR_VERSION >= 4
411
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1579 WIDGET_ADD_CSS_CLASS(listbox, "navigation-sidebar");
413
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1580 #else
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1581 WIDGET_ADD_CSS_CLASS(listbox, "sidebar");
b8e41d42f400 fix gtk3 sourcelist styling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1582 #endif
411
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1583 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1584 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
1585 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1586 SCROLLEDWINDOW_SET_CHILD(scroll_area, listbox);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1587
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1588 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
1589 ui_set_widget_groups(obj->ctx, listbox, args.groups);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1590 UI_APPLY_LAYOUT1(current, args);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1591 current->container->add(current->container, scroll_area, TRUE);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1592
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1593 UiListBox *uilistbox = malloc(sizeof(UiListBox));
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1594 uilistbox->obj = obj;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1595 uilistbox->listbox = GTK_LIST_BOX(listbox);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1596 uilistbox->getvalue = args.getvalue;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1597 uilistbox->onactivate = args.onactivate;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1598 uilistbox->onactivatedata = args.onactivatedata;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1599 uilistbox->onbuttonclick = args.onbuttonclick;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1600 uilistbox->onbuttonclickdata = args.onbuttonclickdata;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1601 uilistbox->sublists = cxArrayListCreateSimple(sizeof(UiListBoxSubList), 4);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1602 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
1603 uilistbox->sublists->collection.destructor_data = obj;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1604 uilistbox->first_row = NULL;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1605
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1606 if(args.numsublists == 0 && args.sublists) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1607 args.numsublists = INT_MAX;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1608 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1609 for(int i=0;i<args.numsublists;i++) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1610 UiSubList sublist = args.sublists[i];
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1611 if(!sublist.varname && !sublist.value) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1612 break;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1613 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1614
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1615 UiListBoxSubList uisublist;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1616 uisublist.var = uic_widget_var(
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1617 obj->ctx,
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1618 current->ctx,
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1619 sublist.value,
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1620 sublist.varname,
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1621 UI_VAR_LIST);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1622 uisublist.numitems = 0;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1623 uisublist.header = sublist.header ? strdup(sublist.header) : NULL;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1624 uisublist.separator = sublist.separator;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1625 uisublist.widgets = cxLinkedListCreateSimple(CX_STORE_POINTERS);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1626 uisublist.listbox = uilistbox;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1627 uisublist.userdata = sublist.userdata;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1628 uisublist.index = i;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1629
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1630 cxListAdd(uilistbox->sublists, &uisublist);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1631
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1632 // bind UiList
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1633 UiListBoxSubList *sublist_ptr = cxListAt(uilistbox->sublists, cxListSize(uilistbox->sublists)-1);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1634 UiList *list = uisublist.var->value;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1635 if(list) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1636 list->obj = sublist_ptr;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1637 list->update = ui_listbox_list_update;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1638 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1639 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1640 // fill items
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1641 ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists));
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1642
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1643 // 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
1644 // widget is used later
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1645 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
1646 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
1647
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1648 // signals
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1649 g_signal_connect(
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1650 listbox,
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1651 "destroy",
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1652 G_CALLBACK(ui_destroy_sourcelist),
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1653 uilistbox);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1654
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1655 if(args.onactivate) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1656 g_signal_connect(
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1657 listbox,
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1658 "row-activated",
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1659 G_CALLBACK(ui_listbox_row_activate),
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1660 NULL);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1661 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1662
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1663 return scroll_area;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1664 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1665
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1666 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
1667 CxIterator i = cxListIterator(listbox->sublists);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1668 size_t pos = 0;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1669 cx_foreach(UiListBoxSubList *, sublist, i) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1670 if(i.index < from) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1671 pos += sublist->numitems;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1672 continue;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1673 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1674 if(i.index > to) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1675 break;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1676 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1677
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1678 // reload sublist
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1679 ui_listbox_update_sublist(listbox, sublist, pos);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1680 pos += sublist->numitems;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1681 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1682 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1683
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1684 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
1685 GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1686 if(item->icon) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1687 GtkWidget *icon = ICON_IMAGE(item->icon);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1688 BOX_ADD(hbox, icon);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1689 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1690 GtkWidget *label = gtk_label_new(item->label);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1691 gtk_widget_set_halign(label, GTK_ALIGN_START);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1692 BOX_ADD_EXPAND(hbox, label);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1693 // TODO: badge, button
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1694 GtkWidget *row = gtk_list_box_row_new();
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1695 LISTBOX_ROW_SET_CHILD(row, hbox);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1696
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1697 // signals
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1698 UiEventDataExt *event = malloc(sizeof(UiEventDataExt));
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1699 memset(event, 0, sizeof(UiEventDataExt));
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1700 event->obj = listbox->obj;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1701 event->customdata0 = sublist;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1702 event->customdata1 = sublist->var;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1703 event->customdata2 = item->eventdata;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1704 event->callback = listbox->onactivate;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1705 event->userdata = listbox->onactivatedata;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1706 event->callback2 = listbox->onbuttonclick;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1707 event->userdata2 = listbox->onbuttonclickdata;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1708 event->value0 = index;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1709
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1710 g_signal_connect(
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1711 row,
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1712 "destroy",
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1713 G_CALLBACK(ui_destroy_userdata),
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1714 event);
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 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
1717
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1718 return row;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1719 }
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 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
1722 // clear sublist
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1723 CxIterator r = cxListIterator(sublist->widgets);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1724 cx_foreach(GtkWidget*, widget, r) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1725 LISTBOX_REMOVE(listbox->listbox, widget);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1726 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1727 cxListClear(sublist->widgets);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1728
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1729 sublist->numitems = 0;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1730
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1731 // create items for each UiList element
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1732 UiList *list = sublist->var->value;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1733 if(!list) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1734 return;
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
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1737 size_t index = 0;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1738 void *elm = list->first(list);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1739 while(elm) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1740 UiSubListItem item = { NULL, NULL, NULL, NULL, NULL, NULL };
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1741 listbox->getvalue(sublist->userdata, elm, index, &item);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1742
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1743 // create listbox item
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1744 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
1745 if(index == 0) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1746 // 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
1747 // which is then used by the headerfunc
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1748 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
1749 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
1750
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1751 if(listbox_insert_index == 0) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1752 // first row in the GtkListBox
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1753 listbox->first_row = GTK_LIST_BOX_ROW(row);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1754 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1755 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1756 intptr_t rowindex = listbox_insert_index + index;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1757 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
1758 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
1759 cxListAdd(sublist->widgets, row);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1760
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1761 // cleanup
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1762 free(item.label);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1763 free(item.icon);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1764 free(item.button_label);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1765 free(item.button_icon);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1766 free(item.badge);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1767
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1768 // next row
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1769 elm = list->next(list);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1770 index++;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1771 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1772
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1773 sublist->numitems = cxListSize(sublist->widgets);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1774 }
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 void ui_listbox_list_update(UiList *list, int i) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1777 UiListBoxSubList *sublist = list->obj;
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 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
1781 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
1782 if(!data) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1783 return;
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 UiListBoxSubList *sublist = data->customdata0;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1786
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1787 UiEvent event;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1788 event.obj = data->obj;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1789 event.window = event.obj->window;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1790 event.document = event.obj->ctx->document;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1791 event.eventdata = data->customdata2;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1792 event.intval = data->value0;
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1793
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1794 if(data->callback) {
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1795 data->callback(&event, data->userdata);
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1796 }
3e91b7aff6a1 add sourcelist widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 401
diff changeset
1797 }

mercurial