ui/gtk/tree.c

Sun, 19 Nov 2017 09:38:23 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 19 Nov 2017 09:38:23 +0100
changeset 148
4e0b38bbd6c4
parent 147
2e384acc89a6
child 150
5cee4cb5ad79
permissions
-rw-r--r--

replaces usage of some deprecated functions (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
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "tree.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 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
42 return column == 0 ? elm : NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 }
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 UIWIDGET ui_listview_str(UiObject *obj, UiList *list, ui_callback f, void *udata) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 return ui_listview(obj, list, ui_strmodel_getvalue, f, udata);
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
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
50 UIWIDGET ui_listview_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 // create treeview
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 GtkWidget *view = gtk_tree_view_new();
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 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
54 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
55 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
56
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 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
58 #ifdef UI_GTK3
123
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
59 #if GTK_MINOR_VERSION >= 8
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 #else
123
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
62 // TODO: implement for older gtk3
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
63 #endif
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
64 #else
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
65 // TODO: implement for gtk2
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 #endif
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
68 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
69 model->getvalue = getvalue;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
70 UiList *list = var->value;
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
71 UiListModel *listmodel = ui_list_model_new(obj, var, model);
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
72 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
74 UiListView *listview = malloc(sizeof(UiListView));
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
75 listview->obj = obj;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 listview->widget = view;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
77 listview->var = var;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
78 listview->model = model;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
79 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
80 view,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
81 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
82 G_CALLBACK(ui_listview_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
83 listview);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
84
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
85 // bind var
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
86 list->update = ui_listview_update;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
87 list->obj = listview;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 // add callback
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 if(f) {
86
3c63f57a8f77 added toolbar combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
91 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 event->obj = obj;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
93 event->userdata = udata;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
94 event->activate = f;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
95 event->selection = NULL;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 g_signal_connect(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 view,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
100 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
101 event);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 // add widget to the current container
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 gtk_scrolled_window_set_policy(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 GTK_SCROLLED_WINDOW(scroll_area),
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 GTK_POLICY_AUTOMATIC,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 gtk_container_add(GTK_CONTAINER(scroll_area), view);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
113 ct->add(ct, scroll_area, TRUE);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
115 // 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
116 // to add a context menu
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
117 ct->current = view;
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
118
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 return scroll_area;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
122 UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
123 UiVar *var = malloc(sizeof(UiVar));
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
124 var->value = list;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
125 var->type = UI_VAR_SPECIAL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
126 return ui_listview_var(obj, var, getvalue, f, udata);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
129 UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
130 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 if(var) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
132 return ui_listview_var(obj, var, getvalue, f, udata);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 } else {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 // TODO: error
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 return NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
139 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
140 printf("drag begin\n");
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
141
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
142 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
143
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
144 static void drag_end(
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
145 GtkWidget *widget,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
146 GdkDragContext *context,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
147 guint time,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
148 gpointer udata)
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
149 {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
150 printf("drag end\n");
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
151
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
152 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
153
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
154 static gboolean drag_failed(
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
155 GtkWidget *widget,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
156 GdkDragContext *context,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
157 GtkDragResult result,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
158 gpointer udata)
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
159 {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
160 printf("drag failed: %d\n", result);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
161
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
162 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
163
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
164 static GtkTargetEntry targetentries[] =
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
165 {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
166 { "STRING", 0, 0 },
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
167 { "text/plain", 0, 1 },
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
168 { "text/uri-list", 0, 2 },
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
169 };
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
171 UIWIDGET ui_table_var(UiObject *obj, UiVar *var, UiModel *model, UiListCallbacks cb) {
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
172 // create treeview
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
173 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
174
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
175 int addi = 0;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
176 for(int i=0;i<model->columns;i++) {
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
177 GtkTreeViewColumn *column = NULL;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
178 if(model->types[i] == UI_ICON_TEXT) {
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
179 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
180 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
181
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
182 GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
183 GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
184
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
185 gtk_tree_view_column_pack_end(column, textrenderer, TRUE);
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
186 gtk_tree_view_column_pack_start(column, iconrenderer, FALSE);
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
187
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
188
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
189 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
190 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
191
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
192 addi++;
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
193 } else {
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
194 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
195 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
196 model->titles[i],
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
197 renderer,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
198 "text",
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
199 i + addi,
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200 NULL);
129
5babf09f5f19 fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 128
diff changeset
201 }
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
202 gtk_tree_view_column_set_resizable(column, TRUE);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203 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
204 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
205
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
206 //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
207 #ifdef UI_GTK3
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
208 //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
209 #else
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
210
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
211 #endif
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
212
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
213 UiList *list = var->value;
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
214 UiListModel *listmodel = ui_list_model_new(obj, var, model);
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
215 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel));
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
216
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
217 //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
218 //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
219 //g_signal_connect(view, "drag-failed", G_CALLBACK(drag_failed), NULL);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
220
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
221 // 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
222 // data changes
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
223 UiListView *tableview = malloc(sizeof(UiListView));
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
224 tableview->obj = obj;
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
225 tableview->widget = view;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
226 tableview->var = var;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
227 tableview->model = model;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
228 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
229 view,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
230 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
231 G_CALLBACK(ui_listview_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
232 tableview);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
233
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
234 // bind var
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
235 list->update = ui_listview_update;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
236 list->obj = tableview;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
238 // add callback
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
239 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
240 event->obj = obj;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
241 event->activate = cb.activate;
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
242 event->selection = cb.selection;
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
243 event->userdata = cb.userdata;
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
244 if(cb.activate) {
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
245 g_signal_connect(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
246 view,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
247 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
248 G_CALLBACK(ui_listview_activate_event),
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
249 event);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
250 }
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
251 if(cb.selection) {
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
252 GtkTreeSelection *selection = gtk_tree_view_get_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
253 GTK_TREE_VIEW(view));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
254 g_signal_connect(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
255 selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
256 "changed",
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
257 G_CALLBACK(ui_listview_selection_event),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
258 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
259 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
260 // TODO: destroy callback
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
261
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
262 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
263 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
264
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
265 // add widget to the current container
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
266 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
267 gtk_scrolled_window_set_policy(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
268 GTK_SCROLLED_WINDOW(scroll_area),
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
269 GTK_POLICY_AUTOMATIC,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
270 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
271 gtk_container_add(GTK_CONTAINER(scroll_area), view);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
272
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
273 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
274 ct->add(ct, scroll_area, TRUE);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
275
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
276 // 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
277 // to add a context menu
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
278 ct->current = view;
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
279
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
280 return scroll_area;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
281 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
282
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
283 UIWIDGET ui_table(UiObject *obj, UiList *list, UiModel *model, UiListCallbacks cb) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
284 UiVar *var = malloc(sizeof(UiVar));
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
285 var->value = list;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
286 var->type = UI_VAR_SPECIAL;
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
287 return ui_table_var(obj, var, model, cb);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
288 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
289
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
290 UIWIDGET ui_table_nv(UiObject *obj, char *varname, UiModel *model, UiListCallbacks cb) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
291 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
292 if(var) {
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
293 return ui_table_var(obj, var, model, cb);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
294 } else {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
295 // TODO: error
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
296 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
297 return NULL;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
298 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
299
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
300 GtkWidget* ui_get_tree_widget(UIWIDGET widget) {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
301 GList *c = gtk_container_get_children(GTK_CONTAINER(widget));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
302 if(c) {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
303 return c->data;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
304 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
305 return NULL;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
306 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
307
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
308 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
309 int al = 16;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
310 char **targets = calloc(16, sizeof(char*));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
311 targets[0] = target0;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
312
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
313 int i = 1;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
314 char *target;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
315 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
316 if(i >= al) {
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
317 al *= 2;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
318 targets = realloc(targets, al*sizeof(char*));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
319 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
320 targets[i] = target;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
321 i++;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
322 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
323
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
324 *nelm = i;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
325 return targets;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
326 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
327
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
328 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
329 GtkTargetEntry *targets = calloc(nelm, sizeof(GtkTargetEntry));
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
330 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
331 targets[i].target = str[i];
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
332 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
333 return targets;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
334 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
335
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
336 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
337 va_list ap;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
338 int nelm;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
339 char **targets = targets2array(target0, ap, &nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
340 va_end(ap);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
341 ui_table_dragsource_a(tablewidget, actions, targets, nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
342 free(targets);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
343 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
344
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
345 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
346 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
347 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
348 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
349 GDK_BUTTON1_MASK,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
350 t,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
351 nelm,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
352 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
353 free(t);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
354 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
355
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
356 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
357 va_list ap;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
358 int nelm;
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
359 char **targets = targets2array(target0, ap, &nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
360 va_end(ap);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
361 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
362 free(targets);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
363 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
364
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
365 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
366 GtkTargetEntry* t = targetstr2gtktargets(targets, nelm);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
367 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
368 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
369 t,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
370 nelm,
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
371 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
372 free(t);
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
373 }
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
374
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
375 void ui_listview_update(UiList *list, int i) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
376 UiListView *view = list->obj;
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
377 UiListModel *model = ui_list_model_new(view->obj, view->var, view->model);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
378 gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(model));
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
379 // TODO: free old model
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
382 void ui_listview_destroy(GtkWidget *w, UiListView *v) {
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
383 ui_destroy_boundvar(v->obj->ctx, v->var);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
384 // TODO: destroy model?
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
385 free(v);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
386 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
387
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
388
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
389 void ui_listview_activate_event(
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390 GtkTreeView *treeview,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 GtkTreePath *path,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 GtkTreeViewColumn *column,
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
393 UiTreeEventData *event)
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 {
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
395 UiListSelection *selection = ui_listview_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
396 gtk_tree_view_get_selection(treeview),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
397 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
398
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
399 UiEvent e;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
400 e.obj = event->obj;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
401 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
402 e.document = event->obj->ctx->document;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
403 e.eventdata = selection;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
404 e.intval = selection->count > 0 ? selection->rows[0] : -1;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
405 event->activate(&e, event->userdata);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
406
69
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
407 if(selection->count > 0) {
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
408 free(selection->rows);
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
409 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
410 free(selection);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
411 }
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 void ui_listview_selection_event(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
414 GtkTreeSelection *treeselection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
415 UiTreeEventData *event)
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
416 {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
417 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
418
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 UiEvent e;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420 e.obj = event->obj;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
422 e.document = event->obj->ctx->document;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
423 e.eventdata = selection;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
424 e.intval = selection->count > 0 ? selection->rows[0] : -1;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
425 event->selection(&e, event->userdata);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
426
69
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
427 if(selection->count > 0) {
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
428 free(selection->rows);
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
429 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
430 free(selection);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
431 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
432
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
433 UiListSelection* ui_listview_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
434 GtkTreeSelection *selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
435 UiTreeEventData *event)
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
436 {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
437 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
438
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
439 UiListSelection *ls = malloc(sizeof(UiListSelection));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
440 ls->count = g_list_length(rows);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
441 ls->rows = calloc(ls->count, sizeof(int));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
442 GList *r = rows;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
443 int i = 0;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
444 while(r) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
445 GtkTreePath *path = r->data;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
446 ls->rows[i] = ui_tree_path_list_index(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
447 r = r->next;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
448 i++;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
449 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
450 return ls;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
451 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
452
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
453 int ui_tree_path_list_index(GtkTreePath *path) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
454 int depth = gtk_tree_path_get_depth(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
455 if(depth == 0) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
456 fprintf(stderr, "UiError: treeview selection: depth == 0\n");
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
457 return -1;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
458 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
459 int *indices = gtk_tree_path_get_indices(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
460 return indices[depth - 1];
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
461 }
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
462
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
463
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
464 /* --------------------------- ComboBox --------------------------- */
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
465
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
466 UIWIDGET ui_combobox_str(UiObject *obj, UiList *list, ui_callback f, void *udata) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
467 return ui_combobox(obj, list, ui_strmodel_getvalue, f, udata);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
468 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
469
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
470 UIWIDGET ui_combobox(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
471 UiVar *var = malloc(sizeof(UiVar));
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
472 var->value = list;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
473 var->type = UI_VAR_SPECIAL;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
474 return ui_combobox_var(obj, var, getvalue, f, udata);
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
475 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
476
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
477 UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
478 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST);
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
479 if(var) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
480 return ui_combobox_var(obj, var, getvalue, f, udata);
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
481 } else {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
482 // TODO: error
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
483 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
484 return NULL;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
485 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
486
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
487 UIWIDGET ui_combobox_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
488 UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1);
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
489 model->getvalue = getvalue;
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
490 UiListModel *listmodel = ui_list_model_new(obj, var, model);
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
491
142
46448d38885c new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
492 GtkWidget *combobox = ui_create_combobox(obj, listmodel, f, udata);
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
493 UiContainer *ct = uic_get_current_container(obj);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
494 ct->add(ct, combobox, FALSE);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
495 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
496
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
497 GtkWidget* ui_create_combobox(UiObject *obj, UiListModel *model, ui_callback f, void *udata) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
498 GtkWidget *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
499
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
500 UiListView *uicbox = malloc(sizeof(UiListView));
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
501 uicbox->obj = obj;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
502 uicbox->widget = combobox;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
503 uicbox->var = model->var;
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
504 uicbox->model = model->model;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
505
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
506 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
507 combobox,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
508 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
509 G_CALLBACK(ui_listview_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
510 uicbox);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
511
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
512 // bind var
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
513 UiList *list = model->var->value;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
514 list->update = ui_combobox_modelupdate;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
515 list->obj = uicbox;
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
516
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
517 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
518 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
519 gtk_cell_layout_set_attributes(
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
520 GTK_CELL_LAYOUT(combobox),
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
521 renderer,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
522 "text",
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
523 0,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
524 NULL);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
525 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
526
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
527 // add callback
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
528 if(f) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
529 UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
530 event->obj = obj;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
531 event->userdata = udata;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
532 event->callback = f;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
533 event->value = 0;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
534
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
535 g_signal_connect(
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
536 combobox,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
537 "changed",
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
538 G_CALLBACK(ui_combobox_change_event),
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
539 event);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
540 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
541
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
542 return combobox;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
543 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
544
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
545 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
546 UiEvent event;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
547 event.obj = e->obj;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
548 event.window = event.obj->window;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
549 event.document = event.obj->ctx->document;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
550 event.eventdata = NULL;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
551 event.intval = gtk_combo_box_get_active(widget);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
552 e->callback(&event, e->userdata);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
553 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
554
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
555 void ui_combobox_modelupdate(UiList *list, int i) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
556 UiListView *view = list->obj;
147
2e384acc89a6 adds simple drag and drop support (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
557 UiListModel *model = ui_list_model_new(view->obj, view->var, view->model);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
558 gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(model));
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
559 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
560

mercurial