ui/gtk/tree.c

Wed, 13 Jul 2016 15:14:09 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 13 Jul 2016 15:14:09 +0200
changeset 125
3335268a8073
parent 124
80609f9675f1
child 128
c284c15509a8
permissions
-rw-r--r--

implemented sub menus (Cocoa)

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 *
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
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>
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../common/context.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/object.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "container.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "tree.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
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 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
41 return column == 0 ? elm : NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 }
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 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
46 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
47 }
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 UIWIDGET ui_listview_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 // create treeview
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 GtkWidget *view = gtk_tree_view_new();
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 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
53 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
54 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
55
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 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
57 #ifdef UI_GTK3
123
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
58 #if GTK_MINOR_VERSION >= 8
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 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
60 #else
123
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
61 // TODO: implement for older gtk3
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
62 #endif
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
63 #else
55adc92e7c09 fixed build with older gtk3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
64 // TODO: implement for gtk2
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 #endif
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
67 UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, "", -1);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
68 modelinfo->getvalue = getvalue;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
69 UiListModel *model = ui_list_model_new(list, modelinfo);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(model));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 // add TreeView as observer to the UiList to update the TreeView if the
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 // data changes
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
74 UiTableView *listview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiTableView));
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 listview->widget = view;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 listview->list = list;
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
77 listview->modelinfo = modelinfo;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 list->list->observers = ui_add_observer(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 list->list->observers,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 (ui_callback)ui_listview_update,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 listview);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 // add callback
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 if(f) {
86
3c63f57a8f77 added toolbar combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
85 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
86 event->obj = obj;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
87 event->userdata = udata;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
88 event->activate = f;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
89 event->selection = NULL;
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 g_signal_connect(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 view,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
94 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
95 event);
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
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 // add widget to the current container
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 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
100 gtk_scrolled_window_set_policy(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 GTK_SCROLLED_WINDOW(scroll_area),
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 GTK_POLICY_AUTOMATIC,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 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
105
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
107 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
108
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
109 // 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
110 // to add a context menu
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
111 ct->current = view;
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
112
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 return scroll_area;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 listptr->list = list;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 return ui_listview_var(obj, listptr, getvalue, f, udata);
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
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 if(var) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 UiListVar *value = var->value;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 return ui_listview_var(obj, value->listptr, getvalue, f, udata);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 } else {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 // TODO: error
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 return NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
134 UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
135 // create treeview
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
136 GtkWidget *view = gtk_tree_view_new();
124
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
137 int addi = 0;
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
138 for(int i=0;i<modelinfo->columns;i++) {
124
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
139 GtkTreeViewColumn *column = NULL;
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
140 if(modelinfo->types[i] == UI_ICON_TEXT) {
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
141 column = gtk_tree_view_column_new();
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
142 gtk_tree_view_column_set_title(column, modelinfo->titles[i]);
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
143
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
144 GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
145 GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new();
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
146
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
147 gtk_tree_view_column_pack_end(column, textrenderer, TRUE);
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
148 gtk_tree_view_column_pack_start(column, iconrenderer, FALSE);
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
149
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
150
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
151 gtk_tree_view_column_add_attribute(column, iconrenderer, "icon-name", i);
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
152 gtk_tree_view_column_add_attribute(column, textrenderer, "text", i+1);
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
153
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
154 addi++;
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
155 } else {
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
156 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
157 column = gtk_tree_view_column_new_with_attributes(
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
158 modelinfo->titles[i],
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
159 renderer,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
160 "text",
124
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
161 i + addi,
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
162 NULL);
124
80609f9675f1 added support for icons for the table widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 123
diff changeset
163 }
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
164 gtk_tree_view_column_set_resizable(column, TRUE);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
165 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
166 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
167
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
168 //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
169 #ifdef UI_GTK3
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
170 //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
171 #else
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
172
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
173 #endif
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
174
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
175 UiListModel *model = ui_list_model_new(list, modelinfo);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
176 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(model));
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
177
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
178 // 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
179 // data changes
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
180 UiTableView *tableview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiTableView));
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
181 tableview->widget = view;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
182 tableview->list = list;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
183 tableview->modelinfo = modelinfo;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
184 list->list->observers = ui_add_observer(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
185 list->list->observers,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
186 (ui_callback)ui_listview_update,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
187 tableview);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
189 // add callback
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
190 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
191 event->obj = obj;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
192 event->activate = modelinfo->activate;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
193 event->selection = modelinfo->selection;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
194 event->userdata = modelinfo->userdata;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
195 if(modelinfo->activate) {
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
196 g_signal_connect(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
197 view,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
198 "row-activated",
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
199 G_CALLBACK(ui_listview_activate_event),
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200 event);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
201 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
202 if(modelinfo->selection) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
203 GtkTreeSelection *selection = gtk_tree_view_get_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
204 GTK_TREE_VIEW(view));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
205 g_signal_connect(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
206 selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
207 "changed",
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
208 G_CALLBACK(ui_listview_selection_event),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
209 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
210 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
211 // TODO: destroy callback
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
212
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
213 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
214 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
215
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
216 // add widget to the current container
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
217 GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
218 gtk_scrolled_window_set_policy(
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
219 GTK_SCROLLED_WINDOW(scroll_area),
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
220 GTK_POLICY_AUTOMATIC,
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
221 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
222 gtk_container_add(GTK_CONTAINER(scroll_area), view);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
223
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
224 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
225 ct->add(ct, scroll_area, TRUE);
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
226
75
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
227 // 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
228 // to add a context menu
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
229 ct->current = view;
efe2f65bea17 added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
230
40
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
231 return scroll_area;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
232 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
233
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
234 UIWIDGET ui_table(UiObject *obj, UiList *list, UiModelInfo *modelinfo) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
235 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
236 listptr->list = list;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
237 return ui_table_var(obj, listptr, modelinfo);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
238 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
239
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
240 UIWIDGET ui_table_nv(UiObject *obj, char *varname, UiModelInfo *modelinfo) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
241 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
242 if(var) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
243 UiListVar *value = var->value;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
244 return ui_table_var(obj, value->listptr, modelinfo);
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
245 } else {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
246 // TODO: error
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
247 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
248 return NULL;
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
249 }
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
250
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
251
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
252
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
253 void ui_listview_update(UiEvent *event, UiTableView *view) {
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
254 UiListModel *model = ui_list_model_new(view->list, view->modelinfo);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 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
256
caa0df8ed095 added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
257 // TODO: free old model
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
260 void ui_listview_activate_event(
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 GtkTreeView *treeview,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 GtkTreePath *path,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 GtkTreeViewColumn *column,
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
264 UiTreeEventData *event)
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 {
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
266 UiListSelection *selection = ui_listview_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
267 gtk_tree_view_get_selection(treeview),
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
268 event);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
269
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
270 UiEvent e;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
271 e.obj = event->obj;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
272 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
273 e.document = event->obj->ctx->document;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
274 e.eventdata = selection;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
275 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
276 event->activate(&e, event->userdata);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
277
69
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
278 if(selection->count > 0) {
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
279 free(selection->rows);
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
280 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
281 free(selection);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
282 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
283
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
284 void ui_listview_selection_event(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
285 GtkTreeSelection *treeselection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
286 UiTreeEventData *event)
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
287 {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
288 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
289
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 UiEvent e;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 e.obj = event->obj;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 42
diff changeset
293 e.document = event->obj->ctx->document;
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
294 e.eventdata = selection;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
295 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
296 event->selection(&e, event->userdata);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
297
69
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
298 if(selection->count > 0) {
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
299 free(selection->rows);
419c8c3209e8 improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
300 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
301 free(selection);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 }
42
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
303
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
304 UiListSelection* ui_listview_selection(
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
305 GtkTreeSelection *selection,
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
306 UiTreeEventData *event)
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
307 {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
308 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
309
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
310 UiListSelection *ls = malloc(sizeof(UiListSelection));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
311 ls->count = g_list_length(rows);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
312 ls->rows = calloc(ls->count, sizeof(int));
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
313 GList *r = rows;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
314 int i = 0;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
315 while(r) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
316 GtkTreePath *path = r->data;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
317 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
318 r = r->next;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
319 i++;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
320 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
321 return ls;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
322 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
323
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
324 int ui_tree_path_list_index(GtkTreePath *path) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
325 int depth = gtk_tree_path_get_depth(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
326 if(depth == 0) {
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
327 fprintf(stderr, "UiError: treeview selection: depth == 0\n");
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
328 return -1;
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
329 }
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
330 int *indices = gtk_tree_path_get_indices(path);
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
331 return indices[depth - 1];
29b2821d1262 added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
332 }
116
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
333
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
334
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
335 /* --------------------------- ComboBox --------------------------- */
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
336
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
337 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
338 return ui_combobox(obj, list, ui_strmodel_getvalue, f, udata);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
339 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
340
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
341 UIWIDGET ui_combobox(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
342 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
343 listptr->list = list;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
344 return ui_combobox_var(obj, listptr, getvalue, f, udata);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
345 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
346
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
347 UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
348 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
349 if(var) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
350 UiListVar *value = var->value;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
351 return ui_combobox_var(obj, value->listptr, getvalue, f, udata);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
352 } else {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
353 // TODO: error
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
354 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
355 return NULL;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
356 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
357
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
358 UIWIDGET ui_combobox_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
359 UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, "", -1);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
360 modelinfo->getvalue = getvalue;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
361 UiListModel *model = ui_list_model_new(list, modelinfo);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
362
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
363 GtkWidget *combobox = ui_create_combobox(obj, model, f, udata);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
364 UiContainer *ct = uic_get_current_container(obj);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
365 ct->add(ct, combobox, FALSE);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
366 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
367
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
368 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
369 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
370
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
371 UiList *list = model->list->list;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
372 list->observers = ui_add_observer(
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
373 list->observers,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
374 (ui_callback)ui_listview_update,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
375 combobox);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
376
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
377 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
378 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
379 gtk_cell_layout_set_attributes(
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
380 GTK_CELL_LAYOUT(combobox),
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
381 renderer,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
382 "text",
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
383 0,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
384 NULL);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
385 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
386
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
387 // add callback
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
388 if(f) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
389 UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
390 event->obj = obj;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
391 event->userdata = udata;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
392 event->callback = f;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
393 event->value = 0;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
394
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
395 g_signal_connect(
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
396 combobox,
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
397 "changed",
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
398 G_CALLBACK(ui_combobox_change_event),
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
399 event);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
400 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
401
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
402 return combobox;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
403 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
404
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
405 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
406 UiEvent event;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
407 event.obj = e->obj;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
408 event.window = event.obj->window;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
409 event.document = event.obj->ctx->document;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
410 event.eventdata = NULL;
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
411 event.intval = gtk_combo_box_get_active(widget);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
412 e->callback(&event, e->userdata);
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
413 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
414
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
415 void ui_combobox_update(UiEvent *event, void *combobox) {
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
416 printf("ui_combobox_update\n");
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
417 printf("TODO: implement\n");
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
418 }
480354705c2f added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 86
diff changeset
419

mercurial