Tue, 11 Jun 2024 21:47:43 +0200
fix gtk executing ui_job_finished even if no finish callback was set
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
2483f517c562
add existing toolkit code
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 |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include "button.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "container.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <cx/allocator.h> |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "../common/context.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "../common/object.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
32 | 38 | void ui_button_set_icon_name(GtkWidget *button, const char *icon) { |
39 | if(!icon) { | |
40 | return; | |
41 | } | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
32 | 43 | #ifdef UI_GTK4 |
44 | gtk_button_set_icon_name(GTK_BUTTON(button), icon); | |
45 | #else | |
46 | #if GTK_CHECK_VERSION(2, 6, 0) | |
47 | GtkWidget *image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON); | |
48 | if(image) { | |
49 | gtk_button_set_image(GTK_BUTTON(button), image); | |
50 | } | |
51 | #else | |
52 | // TODO | |
53 | #endif | |
54 | #endif | |
55 | } | |
56 | ||
57 | UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) { | |
58 | UiObject* current = uic_current_obj(obj); | |
59 | GtkWidget *button = gtk_button_new(); | |
60 | if(args.label) { | |
61 | gtk_button_set_label(GTK_BUTTON(button), args.label); | |
62 | } | |
63 | ui_button_set_icon_name(button, args.icon); | |
64 | ||
65 | ||
66 | if(args.onclick) { | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | UiEventData *event = malloc(sizeof(UiEventData)); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | event->obj = obj; |
32 | 69 | event->userdata = args.onclickdata; |
70 | event->callback = args.onclick; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | event->value = 0; |
32 | 72 | event->customdata = NULL; |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | g_signal_connect( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | button, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | "clicked", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | G_CALLBACK(ui_button_clicked), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | event); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | g_signal_connect( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | button, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | "destroy", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | G_CALLBACK(ui_destroy_userdata), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | event); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | |
32 | 86 | UI_APPLY_LAYOUT1(current, args); |
87 | current->container->add(current->container, button, FALSE); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | return button; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | void ui_button_clicked(GtkWidget *widget, UiEventData *event) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | UiEvent e; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | e.obj = event->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | e.window = event->obj->window; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | e.document = event->obj->ctx->document; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | e.eventdata = NULL; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | e.intval = event->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | event->callback(&e, event->userdata); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | int64_t ui_toggle_button_get(UiInteger *integer) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | GtkToggleButton *button = integer->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | integer->value = (int)gtk_toggle_button_get_active(button); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | return integer->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | void ui_toggle_button_set(UiInteger *integer, int64_t value) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | GtkToggleButton *button = integer->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | integer->value = value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | gtk_toggle_button_set_active(button, value != 0 ? TRUE : FALSE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | void ui_toggled_obs(GtkToggleToolButton *widget, UiVarEventData *event) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | UiEvent e; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | e.obj = event->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | e.window = event->obj->window; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | e.document = event->obj->ctx->document; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | e.eventdata = event->var->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | e.intval = gtk_toggle_tool_button_get_active(widget); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | UiInteger *i = event->var->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | ui_notify_evt(i->observers, &e); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | |
32 | 127 | static UIWIDGET togglebutton_create(UiObject *obj, GtkWidget *widget, UiToggleArgs args) { |
128 | UiObject* current = uic_current_obj(obj); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | |
32 | 130 | if(args.label) { |
131 | gtk_button_set_label(GTK_BUTTON(widget), args.label); | |
132 | } | |
133 | ui_button_set_icon_name(widget, args.icon); | |
134 | ||
135 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); | |
136 | if (var) { | |
137 | UiInteger* value = (UiInteger*)var->value; | |
138 | value->obj = widget; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | value->get = ui_toggle_button_get; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | value->set = ui_toggle_button_set; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | event->obj = obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | event->var = var; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | event->observers = NULL; |
32 | 146 | event->callback = NULL; |
147 | event->userdata = NULL; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | g_signal_connect( |
32 | 150 | widget, |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | "clicked", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | G_CALLBACK(ui_toggled_obs), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | event); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | g_signal_connect( |
32 | 155 | widget, |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | "destroy", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | G_CALLBACK(ui_destroy_vardata), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | event); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
32 | 161 | UI_APPLY_LAYOUT1(current, args); |
162 | current->container->add(current->container, widget, FALSE); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
32 | 164 | return widget; |
165 | } | |
166 | ||
167 | UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { | |
168 | return togglebutton_create(obj, gtk_toggle_button_new(), args); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | |
32 | 171 | UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
172 | return togglebutton_create(obj, gtk_check_button_new(), args); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | |
32 | 175 | UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs args) { |
176 | #ifdef UI_GTK3 | |
177 | return NULL; // TODO | |
178 | #else | |
179 | return ui_checkbox_create(obj, args); | |
180 | #endif | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | |
32 | 184 | |
185 | ||
186 | ||
187 | ||
188 | UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) { | |
189 | UiObject* current = uic_current_obj(obj); | |
190 | ||
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | GSList *rg = NULL; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | UiInteger *rgroup; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | |
32 | 194 | UiVar* var = NULL; |
195 | if (args.value) { | |
196 | var = uic_create_value_var(current->ctx, args.value); | |
197 | } else if (args.varname) { | |
198 | var = uic_create_var(obj->ctx, args.varname, UI_VAR_INTEGER); | |
199 | } | |
200 | ||
201 | UiBool first = FALSE; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | if(var) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | rgroup = var->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | rg = rgroup->obj; |
32 | 205 | if(!rg) { |
206 | first = TRUE; | |
207 | } | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | |
32 | 210 | GtkWidget *rbutton = gtk_radio_button_new_with_label(rg, args.label ? args.label : ""); |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | rg = gtk_radio_button_get_group(GTK_RADIO_BUTTON(rbutton)); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | if(rgroup) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | rgroup->obj = rg; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | rgroup->get = ui_radiobutton_get; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | rgroup->set = ui_radiobutton_set; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | ui_radiobutton_set(rgroup, rgroup->value); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | event->obj = obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | event->var = var; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | event->observers = NULL; |
32 | 224 | event->callback = NULL; |
225 | event->userdata = NULL; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | g_signal_connect( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | rbutton, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | "clicked", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | G_CALLBACK(ui_radio_obs), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | event); |
32 | 232 | if(first) { |
233 | g_signal_connect( | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | rbutton, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | "destroy", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | G_CALLBACK(ui_destroy_vardata), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | event); |
32 | 238 | } |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | UiContainer *ct = uic_get_current_container(obj); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | ct->add(ct, rbutton, FALSE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | return rbutton; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | void ui_radio_obs(GtkToggleToolButton *widget, UiVarEventData *event) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | UiInteger *i = event->var->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | UiEvent e; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | e.obj = event->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | e.window = event->obj->window; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | e.document = event->obj->ctx->document; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | e.eventdata = NULL; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | e.intval = i->get(i); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | ui_notify_evt(i->observers, &e); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | int64_t ui_radiobutton_get(UiInteger *value) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | int selection = 0; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | GSList *ls = value->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | int i = 0; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | guint len = g_slist_length(ls); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | while(ls) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ls->data))) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | selection = len - i - 1; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | break; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | ls = ls->next; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | i++; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | value->value = selection; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | return selection; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | void ui_radiobutton_set(UiInteger *value, int64_t i) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | GSList *ls = value->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | int s = g_slist_length(ls) - 1 - i; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | int j = 0; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | while(ls) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | if(j == s) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ls->data), TRUE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | break; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | ls = ls->next; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | j++; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | value->value = i; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 |