ui/gtk/list.c

Sun, 05 Jan 2025 17:41:39 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 05 Jan 2025 17:41:39 +0100
changeset 439
bf7084544cb1
parent 438
7b1d715e5c11
child 440
7c4b9cba09ca
permissions
-rw-r--r--

fix missing selection init in gtk3 listview

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

mercurial