ui/gtk/list.c

Sun, 05 Jan 2025 16:56:05 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 05 Jan 2025 16:56:05 +0100
changeset 437
f02a62de0328
parent 436
222205801430
child 438
7b1d715e5c11
permissions
-rw-r--r--

fix gtk4 tableview label alignment

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

mercurial