ui/gtk/list.c

Sat, 30 Nov 2024 20:33:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 30 Nov 2024 20:33:16 +0100
branch
newapi
changeset 403
b59935b2de79
parent 401
55fb6bad549d
child 411
3e91b7aff6a1
permissions
-rw-r--r--

fix radiobutton destroy callback (GTK)

33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
32 #include <stdarg.h>
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/context.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/object.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "container.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
394
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
38 #include <cx/array_list.h>
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
39
321
8d63b7cd3d98 rename tree.c to list.c (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 312
diff changeset
40 #include "list.h"
339
b68b5f984074 add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 327
diff changeset
41 #include "icon.h"
390
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
42 #include "menu.h"
394
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
43 #include "dnd.h"
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
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 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
47 return column == 0 ? elm : NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 }
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 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
69
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
70 if(list) {
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
71 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
72 while(elm) {
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
73 // 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
74 GtkTreeIter iter;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
75 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
76
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
77 // 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
78 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
79 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
80 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
81
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 free(data);
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
90 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
91 break;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
92 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
93 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
94 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
95 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
96 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
97 break;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
98 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
99 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
100 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
101 UiIcon *icon = data;
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
102 #if GTK_MAJOR_VERSION >= 4
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
103 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
104 #else
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
105 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
106 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
107 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
108 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
109 }
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 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
112 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
113 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
114 #endif
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
115 break;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
116 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
117 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
118 case UI_ICON_TEXT_FREE: {
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
119 UiIcon *icon = data;
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
120 #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
121 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
122 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
123 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
124 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
125 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
126 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
127 #else
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
128 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
129 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
130 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
131 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
132 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
133 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
134 }
216d8912714c fix file icon and fix crash if a list icon is NULL
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
135 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
136 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
137 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
138 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
139 #endif
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
140 c++;
312
3f2b3d15668b fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
141
3f2b3d15668b fix treeview icons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
142 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
143 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
144 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
145 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
146 free(str);
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
147 }
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
148 break;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
149 }
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 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
153 }
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 // next row
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
156 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
157 }
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 return store;
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
161 }
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
162
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
164 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) {
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
165 UiObject* current = uic_current_obj(obj);
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
166
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 // create treeview
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 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
169 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
170 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
171 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
172 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
173 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
174
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 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
176 #ifdef UI_GTK3
123
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
177 #if GTK_MINOR_VERSION >= 8
369
f16a1cde664e disable gtk3 single click list activation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 363
diff changeset
178 //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
179 #else
123
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
180 // TODO: implement for older gtk3
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
181 #endif
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
182 #else
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
183 // TODO: implement for gtk2
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 #endif
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
186 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
187 model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
188
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
189 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
190
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
191 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
192 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
193 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
194 g_object_unref(listmodel);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
196 UiListView *listview = malloc(sizeof(UiListView));
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
197 listview->obj = obj;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 listview->widget = view;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
199 listview->var = var;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
200 listview->model = model;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
201 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
202 view,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
203 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
204 G_CALLBACK(ui_listview_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
205 listview);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
206
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
207 // bind var
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
208 list->update = ui_listview_update;
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
209 list->getselection = ui_listview_getselection;
363
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
210 list->setselection = ui_listview_setselection;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
211 list->obj = listview;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 // add callback
362
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
214 UiTreeEventData *event = malloc(sizeof(UiTreeEventData));
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
215 event->obj = obj;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
216 event->activate = args.onactivate;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
217 event->activatedata = args.onactivatedata;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
218 event->selection = args.onselection;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
219 event->selectiondata = args.onselectiondata;
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
220 g_signal_connect(
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
221 view,
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
222 "destroy",
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
223 G_CALLBACK(ui_destroy_userdata),
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
224 event);
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
225
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
226 if(args.onactivate) {
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 g_signal_connect(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 view,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
230 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
231 event);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 }
362
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
233 if(args.onselection) {
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
234 GtkTreeSelection *selection = gtk_tree_view_get_selection(
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
235 GTK_TREE_VIEW(view));
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
236 g_signal_connect(
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
237 selection,
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
238 "changed",
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
239 G_CALLBACK(ui_listview_selection_event),
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
240 event);
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
241 }
390
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
242 if(args.contextmenu) {
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
243 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
244 ui_widget_set_contextmenu(view, menu);
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
245 }
362
59e94e97ba68 implement listview selection event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 360
diff changeset
246
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 // add widget to the current container
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
249 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 gtk_scrolled_window_set_policy(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 GTK_SCROLLED_WINDOW(scroll_area),
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 GTK_POLICY_AUTOMATIC,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
254 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
255
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
256 UI_APPLY_LAYOUT1(current, args);
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
257 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
258
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
259 // 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
260 // to add a context menu
269
3380100e20f5 implement listview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 268
diff changeset
261 current->container->current = view;
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
262
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 return scroll_area;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
266 /*
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
267 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
268 printf("drag begin\n");
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
269
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 static void drag_end(
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
273 GtkWidget *widget,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
274 GdkDragContext *context,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
275 guint time,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
276 gpointer udata)
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
277 {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
278 printf("drag end\n");
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
279
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
280 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
281 */
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
282
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
283 /*
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
284 static GtkTargetEntry targetentries[] =
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
285 {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
286 { "STRING", 0, 0 },
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
287 { "text/plain", 0, 1 },
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
288 { "text/uri-list", 0, 2 },
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
289 };
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
290 */
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
292 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
293 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
294
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
295 // create treeview
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
296 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
297
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
298 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
299 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
300
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
301 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
302 for(int i=0;i<columns;i++) {
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
303 GtkTreeViewColumn *column = NULL;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
304 if(model->types[i] == UI_ICON_TEXT) {
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
305 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
306 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
307
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
308 GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
309 GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
310
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
311 gtk_tree_view_column_pack_end(column, textrenderer, TRUE);
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
312 gtk_tree_view_column_pack_start(column, iconrenderer, FALSE);
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
313
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
314
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
315 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
316 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
317
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
318 addi++;
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
319 } 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
320 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
321 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
322 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
323 iconrenderer,
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
324 "pixbuf",
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
325 i + addi,
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
326 NULL);
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
327 } else {
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
328 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
329 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
330 model->titles[i],
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
331 renderer,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
332 "text",
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
333 i + addi,
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
334 NULL);
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
335 }
380
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
336
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
337 int colsz = model->columnsize[i];
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
338 if(colsz > 0) {
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
339 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
340 } else if(colsz < 0) {
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
341 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
342 }
aad99285865c make table column sizes adjustable (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
343
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
344 gtk_tree_view_column_set_resizable(column, TRUE);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
345 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
346 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
347
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
348 //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
349 #ifdef UI_GTK3
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
350 //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
351 #else
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
352
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
353 #endif
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
354
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
355 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
356
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
357 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
358 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
359 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
360 g_object_unref(listmodel);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
361
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
362 //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
363 //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
364
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
365 // 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
366 // data changes
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
367 UiListView *tableview = malloc(sizeof(UiListView));
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
368 tableview->obj = obj;
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
369 tableview->widget = view;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
370 tableview->var = var;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
371 tableview->model = model;
394
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
372 tableview->ondragstart = args.ondragstart;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
373 tableview->ondragstartdata = args.ondragstartdata;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
374 tableview->ondragcomplete = args.ondragcomplete;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
375 tableview->ondragcompletedata = args.ondragcompletedata;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
376 tableview->ondrop = args.ondrop;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
377 tableview->ondropdata = args.ondropsdata;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
378 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
379 view,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
380 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
381 G_CALLBACK(ui_listview_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
382 tableview);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
383
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
384 // bind var
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
385 list->update = ui_listview_update;
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
386 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
387 list->setselection = ui_listview_setselection;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
388 list->obj = tableview;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
390 // add callback
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
391 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
392 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
393 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
394 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
395 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
396 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
397 if(args.onactivate) {
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
398 g_signal_connect(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
399 view,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
400 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
401 G_CALLBACK(ui_listview_activate_event),
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
402 event);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
403 }
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
404 if(args.onselection) {
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
405 GtkTreeSelection *selection = gtk_tree_view_get_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
406 GTK_TREE_VIEW(view));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
407 g_signal_connect(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
408 selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
409 "changed",
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
410 G_CALLBACK(ui_listview_selection_event),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
411 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
412 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
413 // TODO: destroy callback
390
b130f80ec7f9 implement list/table contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
414
394
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
415
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
416 if(args.ondragstart) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
417 ui_listview_add_dnd(tableview, &args);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
418 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
419 if(args.ondrop) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
420 ui_listview_enable_drop(tableview, &args);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
421 }
391
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
422
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
423 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
424 if(args.multiselection) {
70305d427f25 fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
425 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
70305d427f25 fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
426 }
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
427
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
428 // add widget to the current container
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
429 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
430 gtk_scrolled_window_set_policy(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
431 GTK_SCROLLED_WINDOW(scroll_area),
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
432 GTK_POLICY_AUTOMATIC,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
433 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
434 SCROLLEDWINDOW_SET_CHILD(scroll_area, view);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
435
391
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
436 if(args.contextmenu) {
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
437 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
438 #if GTK_MAJOR_VERSION >= 4
391
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
439 ui_widget_set_contextmenu(scroll_area, menu);
401
55fb6bad549d fix gtk3 tableview contextmenu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 394
diff changeset
440 #else
55fb6bad549d fix gtk3 tableview contextmenu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 394
diff changeset
441 ui_widget_set_contextmenu(view, menu);
55fb6bad549d fix gtk3 tableview contextmenu
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 394
diff changeset
442 #endif
391
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
443 }
fc0df448dfbc fix treeview contextmenu (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 390
diff changeset
444
268
1b321a0c624f port table to new API, replace custom tree model with GtkListStore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
445 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
446 current->container->add(current->container, scroll_area, FALSE);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
447
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
448 // 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
449 // 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
450 current->container->current = view;
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
451
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
452 return scroll_area;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
453 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
454
394
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
455 #if GTK_MAJOR_VERSION >= 4
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
456
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
457 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
458 //printf("drag prepare\n");
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
459 UiListView *listview = data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
460
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
461 UiDnD *dnd = ui_create_dnd();
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
462 GdkContentProvider *provider = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
463
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
464
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
465 if(listview->ondragstart) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
466 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
467 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
468 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
469 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
470 event.eventdata = dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
471 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
472 listview->ondragstart(&event, listview->ondragstartdata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
473 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
474
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
475 size_t numproviders = cxListSize(dnd->providers);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
476 if(numproviders > 0) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
477 GdkContentProvider **providers = (GdkContentProvider**)cxListAt(dnd->providers, 0);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
478 provider = gdk_content_provider_new_union(providers, numproviders);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
479 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
480 ui_dnd_free(dnd);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
481
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
482 return provider;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
483 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
484
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
485 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
486 //printf("drag begin\n");
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
487 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
488
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
489 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
490 //printf("drag end\n");
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
491 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
492 if(listview->ondragcomplete) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
493 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
494 dnd.target = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
495 dnd.value = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
496 dnd.providers = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
497 dnd.selected_action = gdk_drag_get_selected_action(drag);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
498 dnd.delete = delete_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
499 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
500
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
501 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
502 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
503 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
504 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
505 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
506 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
507 listview->ondragcomplete(&event, listview->ondragcompletedata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
508 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
509 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
510
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
511 static gboolean ui_listview_drop(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
512 GtkDropTarget *target,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
513 const GValue* value,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
514 gdouble x,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
515 gdouble y,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
516 gpointer user_data)
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
517 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
518 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
519 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
520 dnd.providers = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
521 dnd.target = target;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
522 dnd.value = value;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
523 dnd.selected_action = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
524 dnd.delete = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
525 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
526
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
527 if(listview->ondrop) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
528 dnd.accept = TRUE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
529 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
530 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
531 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
532 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
533 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
534 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
535 listview->ondrop(&event, listview->ondropdata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
536 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
537
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
538 return dnd.accept;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
539 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
540
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
541 void ui_listview_add_dnd(UiListView *listview, UiListArgs *args) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
542 GtkDragSource *dragsource = gtk_drag_source_new();
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
543 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
544 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
545 g_signal_connect(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
546 dragsource,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
547 "drag-begin",
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
548 G_CALLBACK(ui_listview_drag_begin),
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
549 listview);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
550 g_signal_connect(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
551 dragsource,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
552 "drag-end",
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
553 G_CALLBACK(ui_listview_drag_end),
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
554 listview);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
555 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
556
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
557 void ui_listview_enable_drop(UiListView *listview, UiListArgs *args) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
558 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
559 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
560 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
561 gtk_drop_target_set_gtypes(target, default_types, 2);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
562 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
563 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
564
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
565 #else
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
566
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
567 static GtkTargetEntry targetentries[] =
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
568 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
569 { "STRING", 0, 0 },
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
570 { "text/plain", 0, 1 },
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
571 { "text/uri-list", 0, 2 },
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
572 };
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
573
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
574 static void ui_listview_drag_getdata(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
575 GtkWidget* self,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
576 GdkDragContext* context,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
577 GtkSelectionData* data,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
578 guint info,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
579 guint time,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
580 gpointer user_data)
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
581 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
582 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
583 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
584 dnd.context = context;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
585 dnd.data = data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
586 dnd.selected_action = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
587 dnd.delete = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
588 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
589
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
590 if(listview->ondragstart) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
591 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
592 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
593 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
594 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
595 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
596 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
597 listview->ondragstart(&event, listview->ondragstartdata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
598 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
599 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
600
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
601 static void ui_listview_drag_end(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
602 GtkWidget *widget,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
603 GdkDragContext *context,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
604 guint time,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
605 gpointer user_data)
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
606 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
607 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
608 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
609 dnd.context = context;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
610 dnd.data = NULL;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
611 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
612 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
613 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
614 if(listview->ondragcomplete) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
615 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
616 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
617 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
618 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
619 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
620 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
621 listview->ondragcomplete(&event, listview->ondragcompletedata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
622 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
623 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
624
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
625 void ui_listview_add_dnd(UiListView *listview, UiListArgs *args) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
626 gtk_tree_view_enable_model_drag_source(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
627 GTK_TREE_VIEW(listview->widget),
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
628 GDK_BUTTON1_MASK,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
629 targetentries,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
630 2,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
631 GDK_ACTION_COPY);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
632
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
633 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
634 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
635 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
636
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
637
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
638
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
639
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
640 static void ui_listview_drag_data_received(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
641 GtkWidget *self,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
642 GdkDragContext *context,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
643 gint x,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
644 gint y,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
645 GtkSelectionData *data,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
646 guint info,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
647 guint time,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
648 gpointer user_data)
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
649 {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
650 UiListView *listview = user_data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
651 UiDnD dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
652 dnd.context = context;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
653 dnd.data = data;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
654 dnd.selected_action = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
655 dnd.delete = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
656 dnd.accept = FALSE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
657
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
658 if(listview->ondrop) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
659 dnd.accept = TRUE;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
660 UiEvent event;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
661 event.obj = listview->obj;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
662 event.window = event.obj->window;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
663 event.document = event.obj->ctx->document;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
664 event.eventdata = &dnd;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
665 event.intval = 0;
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
666 listview->ondrop(&event, listview->ondropdata);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
667 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
668 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
669
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
670 void ui_listview_enable_drop(UiListView *listview, UiListArgs *args) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
671 gtk_tree_view_enable_model_drag_dest(
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
672 GTK_TREE_VIEW(listview->widget),
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
673 targetentries,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
674 3,
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
675 GDK_ACTION_COPY);
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
676 if(listview->ondrop) {
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
677 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
678 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
679 }
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
680
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
681 #endif
bedd499b640d implement table dnd (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 392
diff changeset
682
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
683
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
684 GtkWidget* ui_get_tree_widget(UIWIDGET widget) {
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
685 return SCROLLEDWINDOW_GET_CHILD(widget);
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
686 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
687
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
688 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
689 int al = 16;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
690 char **targets = calloc(16, sizeof(char*));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
691 targets[0] = target0;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
692
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
693 int i = 1;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
694 char *target;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
695 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
696 if(i >= al) {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
697 al *= 2;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
698 targets = realloc(targets, al*sizeof(char*));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
699 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
700 targets[i] = target;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
701 i++;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
702 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
703
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
704 *nelm = i;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
705 return targets;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
706 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
707
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
708 /*
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
709 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
710 GtkTargetEntry *targets = calloc(nelm, sizeof(GtkTargetEntry));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
711 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
712 targets[i].target = str[i];
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
713 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
714 return targets;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
715 }
299
48763a9d19a7 make gtk4 port compilable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 291
diff changeset
716 */
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
717
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
718 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
719 va_list ap;
150
5cee4cb5ad79 fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
720 va_start(ap, target0);
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
721 int nelm;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
722 char **targets = targets2array(target0, ap, &nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
723 va_end(ap);
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
724
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
725 // disabled
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
726 //ui_table_dragsource_a(tablewidget, actions, targets, nelm);
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
727
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
728 free(targets);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
729 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
730
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
731 /*
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
732 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
733 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
734 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
735 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
736 GDK_BUTTON1_MASK,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
737 t,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
738 nelm,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
739 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
740 free(t);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
741 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
742
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
743
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
744 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
745 va_list ap;
150
5cee4cb5ad79 fixes uic_copy_binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
746 va_start(ap, target0);
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
747 int nelm;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
748 char **targets = targets2array(target0, ap, &nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
749 va_end(ap);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
750 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
751 free(targets);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
752 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
753
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
754 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
755 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
756 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
757 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
758 t,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
759 nelm,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
760 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
761 free(t);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
762 }
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
763 */
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 163
diff changeset
764
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
765 void ui_listview_update(UiList *list, int i) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
766 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
767 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
768 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
769 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
770 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
771
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
772 UiListSelection ui_listview_getselection(UiList *list) {
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
773 UiListView *view = list->obj;
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
774 UiListSelection selection = ui_listview_selection(
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
775 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
776 NULL);
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
777 return selection;
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
778 }
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
779
363
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
780 void ui_listview_setselection(UiList *list, UiListSelection selection) {
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
781 UiListView *view = list->obj;
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
782 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
783 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
784 gtk_tree_selection_select_path(sel, path);
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
785 //g_object_unref(path);
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
786 }
cd221f1e9ff6 implement listview onselection callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 362
diff changeset
787
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
788 void ui_listview_destroy(GtkWidget *w, UiListView *v) {
370
822fcb83bdf1 improve window close handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
789 //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
790 ui_destroy_boundvar(v->obj->ctx, v->var);
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
791 free(v);
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
792 }
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
793
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
794 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
795 ui_destroy_boundvar(v->obj->ctx, v->var);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
796 free(v);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
797 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
798
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
799
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
800 void ui_listview_activate_event(
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
801 GtkTreeView *treeview,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
802 GtkTreePath *path,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
803 GtkTreeViewColumn *column,
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
804 UiTreeEventData *event)
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
805 {
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
806 UiListSelection selection = ui_listview_selection(
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
807 gtk_tree_view_get_selection(treeview),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
808 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
809
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
810 UiEvent e;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
811 e.obj = event->obj;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
812 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
813 e.document = event->obj->ctx->document;
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
814 e.eventdata = &selection;
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
815 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
816 event->activate(&e, event->activatedata);
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
817
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
818 if(selection.count > 0) {
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
819 free(selection.rows);
69
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
820 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
821 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
822
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
823 void ui_listview_selection_event(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
824 GtkTreeSelection *treeselection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
825 UiTreeEventData *event)
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
826 {
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
827 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
828
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
829 UiEvent e;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
830 e.obj = event->obj;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
831 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
832 e.document = event->obj->ctx->document;
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
833 e.eventdata = &selection;
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
834 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
835 event->selection(&e, event->selectiondata);
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
836
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
837 if(selection.count > 0) {
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
838 free(selection.rows);
69
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
839 }
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
840 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
841
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
842 UiListSelection ui_listview_selection(
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
843 GtkTreeSelection *selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
844 UiTreeEventData *event)
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
845 {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
846 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
847
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
848 UiListSelection ls;
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
849 ls.count = g_list_length(rows);
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
850 ls.rows = calloc(ls.count, sizeof(int));
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
851 GList *r = rows;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
852 int i = 0;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
853 while(r) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
854 GtkTreePath *path = r->data;
291
302a150ff5e4 implement ui_list_getselection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 278
diff changeset
855 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
856 r = r->next;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
857 i++;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
858 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
859 return ls;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
860 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
861
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
862 int ui_tree_path_list_index(GtkTreePath *path) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
863 int depth = gtk_tree_path_get_depth(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
864 if(depth == 0) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
865 fprintf(stderr, "UiError: treeview selection: depth == 0\n");
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
866 return -1;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
867 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
868 int *indices = gtk_tree_path_get_indices(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
869 return indices[depth - 1];
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
870 }
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
871
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
872
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
873 /* --------------------------- ComboBox --------------------------- */
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
874
270
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
875 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
876 UiObject* current = uic_current_obj(obj);
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
877
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
878 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
879 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
880
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
881 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
882
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
883 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
884 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
885 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
886 UI_APPLY_LAYOUT1(current, args);
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
887 current->container->add(current->container, combobox, FALSE);
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
888 current->container->current = combobox;
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
889 return combobox;
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
890 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
891
270
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
892 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
893 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
894
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
895 UiListView *uicbox = malloc(sizeof(UiListView));
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
896 uicbox->obj = obj;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
897 uicbox->widget = combobox;
270
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
898
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
899 UiList *list = var ? var->value : NULL;
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
900 GtkListStore *listmodel = create_list_store(list, model);
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
901
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
902 if(listmodel) {
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
903 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
904 g_object_unref(listmodel);
270
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
905 }
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
906
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
907 uicbox->var = var;
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
908 uicbox->model = model;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
909
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
910 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
911 combobox,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
912 "destroy",
152
62921b370c60 fixes use after free when a GtkTreeView was destroyed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 151
diff changeset
913 G_CALLBACK(ui_combobox_destroy),
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
914 uicbox);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
915
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
916 // bind var
270
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
917 if(list) {
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
918 list->update = ui_combobox_modelupdate;
360
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
919 list->getselection = ui_combobox_getselection;
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
920 list->setselection = ui_combobox_setselection;
270
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
921 list->obj = uicbox;
9389313ac00f port combobox to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
922 }
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
923
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
924 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
925 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
926 gtk_cell_layout_set_attributes(
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
927 GTK_CELL_LAYOUT(combobox),
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
928 renderer,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
929 "text",
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
930 0,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
931 NULL);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
932 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
933
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
934 // add callback
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
935 if(f) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
936 UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
937 event->obj = obj;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
938 event->userdata = udata;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
939 event->callback = f;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
940 event->value = 0;
278
a8faf8757450 implement ui_dialog_create (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
941 event->customdata = NULL;
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
942
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
943 g_signal_connect(
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
944 combobox,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
945 "changed",
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
946 G_CALLBACK(ui_combobox_change_event),
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
947 event);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
948 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
949
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
950 return combobox;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
951 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
952
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
953 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
954 UiEvent event;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
955 event.obj = e->obj;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
956 event.window = event.obj->window;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
957 event.document = event.obj->ctx->document;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
958 event.eventdata = NULL;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
959 event.intval = gtk_combo_box_get_active(widget);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
960 e->callback(&event, e->userdata);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
961 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
962
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
963 void ui_combobox_modelupdate(UiList *list, int i) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
964 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
965 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
966 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
967 g_object_unref(store);
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
968 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
969
360
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
970 UiListSelection ui_combobox_getselection(UiList *list) {
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
971 UiListView *combobox = list->obj;
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
972 UiListSelection ret;
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
973 ret.rows = malloc(sizeof(int*));
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
974 ret.count = 1;
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
975 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
976 return ret;
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
977 }
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
978
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
979 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
980 UiListView *combobox = list->obj;
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
981 if(selection.count > 0) {
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
982 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
983 }
681b930abe84 implement combobox get/set selection (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
984 }

mercurial