Sat, 11 Nov 2017 11:59:06 +0100
adds observer support for textarea and textfield (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> |
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 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
49 | 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
|
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 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
67 | UiModel *model = ui_model_info(obj->ctx, UI_STRING, "", -1); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
68 | model->getvalue = getvalue; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
69 | UiList *list = var->value; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
70 | UiListModel *listmodel = ui_list_model_new(var, model); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
71 | 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
|
72 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
73 | UiListView *listview = malloc(sizeof(UiListView)); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
74 | listview->ctx = obj->ctx; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | listview->widget = view; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
76 | listview->var = var; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
77 | listview->model = model; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
78 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
79 | view, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
80 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
81 | G_CALLBACK(ui_listview_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
82 | listview); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
83 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
84 | // bind var |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
85 | list->update = ui_listview_update; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
86 | list->obj = listview; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | // add callback |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | if(f) { |
86
3c63f57a8f77
added toolbar combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
90 | 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
|
91 | event->obj = obj; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
92 | event->userdata = udata; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
93 | event->activate = f; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
94 | event->selection = NULL; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | g_signal_connect( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | view, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | "row-activated", |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
99 | 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
|
100 | event); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | } |
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 | // add widget to the current container |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | 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
|
105 | gtk_scrolled_window_set_policy( |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | GTK_SCROLLED_WINDOW(scroll_area), |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | GTK_POLICY_AUTOMATIC, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | 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
|
110 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | UiContainer *ct = uic_get_current_container(obj); |
59
eb6611be50c7
added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
112 | 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
|
113 | |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
114 | // 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
|
115 | // to add a context menu |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
116 | ct->current = view; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
117 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | return scroll_area; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
121 | 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
|
122 | UiVar *var = malloc(sizeof(UiVar)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
123 | var->value = list; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
124 | var->type = UI_VAR_SPECIAL; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
125 | 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
|
126 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
128 | 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
|
129 | 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
|
130 | if(var) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
131 | 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
|
132 | } else { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | // TODO: error |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | return NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | } |
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 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
139 | 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
|
140 | // create treeview |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
141 | GtkWidget *view = gtk_tree_view_new(); |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
142 | int addi = 0; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
143 | for(int i=0;i<model->columns;i++) { |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
144 | GtkTreeViewColumn *column = NULL; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
145 | if(model->types[i] == UI_ICON_TEXT) { |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
146 | 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
|
147 | 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
|
148 | |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
149 | GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new(); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
150 | GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new(); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
151 | |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
152 | gtk_tree_view_column_pack_end(column, textrenderer, TRUE); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
153 | gtk_tree_view_column_pack_start(column, iconrenderer, FALSE); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
154 | |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
155 | |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
156 | gtk_tree_view_column_add_attribute(column, iconrenderer, "icon-name", i); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
157 | 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
|
158 | |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
159 | addi++; |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
160 | } else { |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
161 | GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
162 | 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
|
163 | model->titles[i], |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
164 | renderer, |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
165 | "text", |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
166 | i + addi, |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
167 | NULL); |
129
5babf09f5f19
fixes stultus commit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
128
diff
changeset
|
168 | } |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
169 | gtk_tree_view_column_set_resizable(column, TRUE); |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
170 | 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
|
171 | } |
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 | //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
|
174 | #ifdef UI_GTK3 |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
175 | //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
|
176 | #else |
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 | #endif |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
179 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
180 | UiList *list = var->value; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
181 | UiListModel *listmodel = ui_list_model_new(var, model); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
182 | 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
|
183 | |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
184 | // 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
|
185 | // data changes |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
186 | UiListView *tableview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListView)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
187 | tableview->ctx = obj->ctx; |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
188 | tableview->widget = view; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
189 | tableview->var = var; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
190 | tableview->model = model; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
191 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
192 | view, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
193 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
194 | G_CALLBACK(ui_listview_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
195 | tableview); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
196 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
197 | // bind var |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
198 | list->update = ui_listview_update; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
199 | list->obj = tableview; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
201 | // add callback |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
202 | UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData)); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
203 | event->obj = obj; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
204 | event->activate = cb.activate; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
205 | event->selection = cb.selection; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
206 | event->userdata = cb.userdata; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
207 | if(cb.activate) { |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
208 | g_signal_connect( |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
209 | view, |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
210 | "row-activated", |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
211 | G_CALLBACK(ui_listview_activate_event), |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
212 | event); |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
213 | } |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
214 | if(cb.selection) { |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
215 | GtkTreeSelection *selection = gtk_tree_view_get_selection( |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
216 | GTK_TREE_VIEW(view)); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
217 | g_signal_connect( |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
218 | selection, |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
219 | "changed", |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
220 | G_CALLBACK(ui_listview_selection_event), |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
221 | event); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
222 | } |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
223 | // TODO: destroy callback |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
224 | |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
225 | 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
|
226 | 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
|
227 | |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
228 | // add widget to the current container |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
229 | GtkWidget *scroll_area = gtk_scrolled_window_new(NULL, NULL); |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
230 | gtk_scrolled_window_set_policy( |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
231 | GTK_SCROLLED_WINDOW(scroll_area), |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
232 | GTK_POLICY_AUTOMATIC, |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
233 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
234 | gtk_container_add(GTK_CONTAINER(scroll_area), view); |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
235 | |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
236 | UiContainer *ct = uic_get_current_container(obj); |
59
eb6611be50c7
added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
237 | ct->add(ct, scroll_area, TRUE); |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
238 | |
75
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
239 | // 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
|
240 | // to add a context menu |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
241 | ct->current = view; |
efe2f65bea17
added context menus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
242 | |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
243 | return scroll_area; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
244 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
245 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
246 | 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
|
247 | UiVar *var = malloc(sizeof(UiVar)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
248 | var->value = list; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
249 | 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
|
250 | return ui_table_var(obj, var, model, cb); |
40
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 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
253 | 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
|
254 | 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
|
255 | if(var) { |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
256 | return ui_table_var(obj, var, model, cb); |
40
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
257 | } else { |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
258 | // TODO: error |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
259 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
260 | return NULL; |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
261 | } |
caa0df8ed095
added table view (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
262 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
263 | void ui_listview_update(UiList *list, int i) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
264 | UiListView *view = list->obj; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
265 | UiListModel *model = ui_list_model_new(view->var, view->model); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
266 | 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
|
267 | // TODO: free old model |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
270 | void ui_listview_destroy(GtkWidget *w, UiListView *v) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
271 | ui_destroy_boundvar(v->ctx, v->var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
272 | // TODO: destroy model? |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
273 | free(v); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
274 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
275 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
276 | |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
277 | void ui_listview_activate_event( |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | GtkTreeView *treeview, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | GtkTreePath *path, |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | GtkTreeViewColumn *column, |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
281 | UiTreeEventData *event) |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | { |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
283 | UiListSelection *selection = ui_listview_selection( |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
284 | gtk_tree_view_get_selection(treeview), |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
285 | event); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
286 | |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
287 | UiEvent e; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
288 | e.obj = event->obj; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
289 | e.window = event->obj->window; |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
290 | e.document = event->obj->ctx->document; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
291 | e.eventdata = selection; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
292 | 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
|
293 | event->activate(&e, event->userdata); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
294 | |
69
419c8c3209e8
improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
295 | if(selection->count > 0) { |
419c8c3209e8
improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
296 | free(selection->rows); |
419c8c3209e8
improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
297 | } |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
298 | free(selection); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
299 | } |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
300 | |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
301 | void ui_listview_selection_event( |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
302 | GtkTreeSelection *treeselection, |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
303 | UiTreeEventData *event) |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
304 | { |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
305 | 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
|
306 | |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | UiEvent e; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | e.obj = event->obj; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | e.window = event->obj->window; |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
310 | e.document = event->obj->ctx->document; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
311 | e.eventdata = selection; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
312 | 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
|
313 | event->selection(&e, event->userdata); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
314 | |
69
419c8c3209e8
improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
315 | if(selection->count > 0) { |
419c8c3209e8
improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
316 | free(selection->rows); |
419c8c3209e8
improved table (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
317 | } |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
318 | free(selection); |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | } |
42
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 | UiListSelection* ui_listview_selection( |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
322 | GtkTreeSelection *selection, |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
323 | UiTreeEventData *event) |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
324 | { |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
325 | 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
|
326 | |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
327 | UiListSelection *ls = malloc(sizeof(UiListSelection)); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
328 | ls->count = g_list_length(rows); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
329 | ls->rows = calloc(ls->count, sizeof(int)); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
330 | GList *r = rows; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
331 | int i = 0; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
332 | while(r) { |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
333 | GtkTreePath *path = r->data; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
334 | 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
|
335 | r = r->next; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
336 | i++; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
337 | } |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
338 | return ls; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
339 | } |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
340 | |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
341 | int ui_tree_path_list_index(GtkTreePath *path) { |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
342 | int depth = gtk_tree_path_get_depth(path); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
343 | if(depth == 0) { |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
344 | fprintf(stderr, "UiError: treeview selection: depth == 0\n"); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
345 | return -1; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
346 | } |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
347 | int *indices = gtk_tree_path_get_indices(path); |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
348 | return indices[depth - 1]; |
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
349 | } |
116
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
350 | |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
351 | |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
352 | /* --------------------------- ComboBox --------------------------- */ |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
353 | |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
354 | 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
|
355 | return ui_combobox(obj, list, ui_strmodel_getvalue, f, udata); |
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 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
358 | 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
|
359 | UiVar *var = malloc(sizeof(UiVar)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
360 | var->value = list; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
361 | var->type = UI_VAR_SPECIAL; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
362 | return ui_combobox_var(obj, var, getvalue, f, udata); |
116
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
363 | } |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
364 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
365 | 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
|
366 | 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
|
367 | if(var) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
368 | return ui_combobox_var(obj, var, getvalue, f, udata); |
116
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
369 | } else { |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
370 | // TODO: error |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
371 | } |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
372 | return NULL; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
373 | } |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
374 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
375 | UIWIDGET ui_combobox_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) { |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
376 | UiModel *model = ui_model_info(obj->ctx, UI_STRING, "", -1); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
377 | model->getvalue = getvalue; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
378 | UiListModel *listmodel = ui_list_model_new(var, model); |
116
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
379 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
380 | GtkWidget *combobox = ui_create_combobox(obj, listmodel, f, udata); |
116
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
381 | UiContainer *ct = uic_get_current_container(obj); |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
382 | ct->add(ct, combobox, FALSE); |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
383 | } |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
384 | |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
385 | 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
|
386 | 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
|
387 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
388 | UiListView *uicbox = malloc(sizeof(UiListView)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
389 | uicbox->ctx = obj->ctx; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
390 | uicbox->widget = combobox; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
391 | uicbox->var = model->var; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
392 | uicbox->model = model->info; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
393 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
394 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
395 | combobox, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
396 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
397 | G_CALLBACK(ui_listview_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
398 | uicbox); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
399 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
400 | // bind var |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
401 | UiList *list = model->var->value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
402 | list->update = ui_combobox_modelupdate; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
403 | list->obj = uicbox; |
116
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 | GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
406 | 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
|
407 | gtk_cell_layout_set_attributes( |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
408 | GTK_CELL_LAYOUT(combobox), |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
409 | renderer, |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
410 | "text", |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
411 | 0, |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
412 | NULL); |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
413 | gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0); |
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 | // add callback |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
416 | if(f) { |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
417 | UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData)); |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
418 | event->obj = obj; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
419 | event->userdata = udata; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
420 | event->callback = f; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
421 | event->value = 0; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
422 | |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
423 | g_signal_connect( |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
424 | combobox, |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
425 | "changed", |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
426 | G_CALLBACK(ui_combobox_change_event), |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
427 | event); |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
428 | } |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
429 | |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
430 | return combobox; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
431 | } |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
432 | |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
433 | void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) { |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
434 | UiEvent event; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
435 | event.obj = e->obj; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
436 | event.window = event.obj->window; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
437 | event.document = event.obj->ctx->document; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
438 | event.eventdata = NULL; |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
439 | event.intval = gtk_combo_box_get_active(widget); |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
440 | e->callback(&event, e->userdata); |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
441 | } |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
442 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
443 | void ui_combobox_modelupdate(UiList *list, int i) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
444 | UiListView *view = list->obj; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
445 | UiListModel *model = ui_list_model_new(view->var, view->model); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
446 | 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
|
447 | } |
480354705c2f
added combobox (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
86
diff
changeset
|
448 |