Sun, 15 Dec 2024 22:13:05 +0100
implement menu item callbacks (Motif)
3 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
3 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | ||
32 | #include "button.h" | |
4
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
33 | #include "container.h" |
174 | 34 | #include <cx/allocator.h> |
4
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
35 | #include "../common/context.h" |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
36 | #include "../common/object.h" |
3 | 37 | |
276
376921880a7f
add initial support for headerbars (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
274
diff
changeset
|
38 | void ui_button_set_icon_name(GtkWidget *button, const char *icon) { |
259
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
39 | if(!icon) { |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
40 | return; |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
41 | } |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
42 | |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
43 | #ifdef UI_GTK4 |
276
376921880a7f
add initial support for headerbars (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
274
diff
changeset
|
44 | gtk_button_set_icon_name(GTK_BUTTON(button), icon); |
259
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
45 | #else |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
46 | #if GTK_CHECK_VERSION(2, 6, 0) |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
47 | GtkWidget *image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON); |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
48 | if(image) { |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
49 | gtk_button_set_image(GTK_BUTTON(button), image); |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
50 | } |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
51 | #else |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
52 | // TODO |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
53 | #endif |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
54 | #endif |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
55 | } |
8cce275d2847
implement button icon parameter (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
258
diff
changeset
|
56 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
57 | GtkWidget* ui_create_button( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
58 | UiObject *obj, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
59 | const char *label, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
60 | const char *icon, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
61 | ui_callback onclick, |
344
870dd3d41d83
add dialog window (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
343
diff
changeset
|
62 | void *userdata, |
350
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
63 | int event_value, |
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
64 | bool activate_event) |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
65 | { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
66 | GtkWidget *button = gtk_button_new_with_label(label); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
67 | ui_button_set_icon_name(button, icon); |
4
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
68 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
69 | if(onclick) { |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
70 | UiEventData *event = malloc(sizeof(UiEventData)); |
4
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
71 | event->obj = obj; |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
72 | event->userdata = userdata; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
73 | event->callback = onclick; |
344
870dd3d41d83
add dialog window (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
343
diff
changeset
|
74 | event->value = event_value; |
278
a8faf8757450
implement ui_dialog_create (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
75 | event->customdata = NULL; |
4
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
76 | |
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
77 | g_signal_connect( |
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
78 | button, |
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
79 | "clicked", |
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
80 | G_CALLBACK(ui_button_clicked), |
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
81 | event); |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
82 | g_signal_connect( |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
83 | button, |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
84 | "destroy", |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
85 | G_CALLBACK(ui_destroy_userdata), |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
86 | event); |
350
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
87 | if(activate_event) { |
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
88 | g_signal_connect( |
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
89 | button, |
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
90 | "activate", |
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
91 | G_CALLBACK(ui_button_clicked), |
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
92 | event); |
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
93 | } |
4
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
94 | } |
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
95 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
96 | return button; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
97 | } |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
98 | |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
99 | UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
100 | UiObject* current = uic_current_obj(obj); |
350
70305d427f25
fix ui_scrolledwindow (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
344
diff
changeset
|
101 | GtkWidget *button = ui_create_button(obj, args.label, args.icon, args.onclick, args.onclickdata, 0, FALSE); |
313
b679cc6059ab
add option to name widgets and add css classes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
102 | ui_set_name_and_style(button, args.name, args.style_class); |
343
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
103 | ui_set_widget_groups(obj->ctx, button, args.groups); |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
104 | UI_APPLY_LAYOUT1(current, args); |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
105 | current->container->add(current->container, button, FALSE); |
4
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
106 | return button; |
39b9b86ec452
added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
107 | } |
3 | 108 | |
109 | ||
110 | void ui_button_clicked(GtkWidget *widget, UiEventData *event) { | |
111 | UiEvent e; | |
112 | e.obj = event->obj; | |
113 | e.window = event->obj->window; | |
52
25e5390cce41
added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
42
diff
changeset
|
114 | e.document = event->obj->ctx->document; |
16
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
115 | e.eventdata = NULL; |
a499c8a72c15
added menu item lists (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
116 | e.intval = event->value; |
42
29b2821d1262
added table view events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
117 | event->callback(&e, event->userdata); |
3 | 118 | } |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
119 | |
144
29d98cff4f56
UiInteger uses int64 now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
120 | int64_t ui_toggle_button_get(UiInteger *integer) { |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
121 | GtkToggleButton *button = integer->obj; |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
122 | integer->value = (int)gtk_toggle_button_get_active(button); |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
123 | return integer->value; |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
124 | } |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
125 | |
144
29d98cff4f56
UiInteger uses int64 now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
126 | void ui_toggle_button_set(UiInteger *integer, int64_t value) { |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
127 | GtkToggleButton *button = integer->obj; |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
128 | integer->value = value; |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
129 | gtk_toggle_button_set_active(button, value != 0 ? TRUE : FALSE); |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
130 | } |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
131 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
132 | void ui_toggled_obs(void *widget, UiVarEventData *event) { |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
133 | UiInteger *i = event->var->value; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
134 | UiEvent e; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
135 | e.obj = event->obj; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
136 | e.window = event->obj->window; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
137 | e.document = event->obj->ctx->document; |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
138 | e.eventdata = event->var->value; |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
139 | e.intval = i->get(i); |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
140 | |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
141 | ui_notify_evt(i->observers, &e); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
142 | } |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
143 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
144 | static void ui_toggled_callback(GtkToggleButton *widget, UiEventData *event) { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
145 | UiEvent e; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
146 | e.obj = event->obj; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
147 | e.window = event->obj->window; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
148 | e.document = event->obj->ctx->document; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
149 | e.eventdata = NULL; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
150 | e.intval = gtk_toggle_button_get_active(widget); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
151 | event->callback(&e, event->userdata); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
152 | } |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
153 | |
359
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
154 | static void ui_togglebutton_enable_state_callback(GtkToggleButton *widget, UiEventData *event) { |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
155 | if(gtk_toggle_button_get_active(widget)) { |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
156 | ui_set_group(event->obj->ctx, event->value); |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
157 | } else { |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
158 | ui_unset_group(event->obj->ctx, event->value); |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
159 | } |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
160 | } |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
161 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
162 | void ui_setup_togglebutton( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
163 | UiObject *obj, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
164 | GtkWidget *togglebutton, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
165 | const char *label, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
166 | const char *icon, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
167 | const char *varname, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
168 | UiInteger *value, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
169 | ui_callback onchange, |
359
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
170 | void *onchangedata, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
171 | int enable_state) |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
172 | { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
173 | if(label) { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
174 | gtk_button_set_label(GTK_BUTTON(togglebutton), label); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
175 | } |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
176 | ui_button_set_icon_name(togglebutton, icon); |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
177 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
178 | ui_bind_togglebutton( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
179 | obj, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
180 | togglebutton, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
181 | ui_toggle_button_get, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
182 | ui_toggle_button_set, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
183 | varname, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
184 | value, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
185 | (ui_toggled_func)ui_toggled_callback, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
186 | onchange, |
359
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
187 | onchangedata, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
188 | (ui_toggled_func)ui_togglebutton_enable_state_callback, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
189 | enable_state |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
190 | ); |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
191 | } |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
192 | |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
193 | void ui_bind_togglebutton( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
194 | UiObject *obj, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
195 | GtkWidget *widget, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
196 | int64_t (*getfunc)(UiInteger*), |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
197 | void (*setfunc)(UiInteger*, int64_t), |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
198 | const char *varname, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
199 | UiInteger *value, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
200 | void (*toggled_callback)(void*, void*), |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
201 | ui_callback onchange, |
359
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
202 | void *onchangedata, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
203 | void (*enable_state_func)(void*, void*), |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
204 | int enable_state) |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
205 | { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
206 | UiObject* current = uic_current_obj(obj); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
207 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, value, varname, UI_VAR_INTEGER); |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
208 | if (var) { |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
209 | UiInteger* value = (UiInteger*)var->value; |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
210 | value->obj = widget; |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
211 | value->get = getfunc; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
212 | value->set = setfunc; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
213 | |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
214 | UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
215 | event->obj = obj; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
216 | event->var = var; |
145
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
217 | event->observers = NULL; |
264
24d9a92fd048
update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
261
diff
changeset
|
218 | event->callback = NULL; |
24d9a92fd048
update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
261
diff
changeset
|
219 | event->userdata = NULL; |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
220 | |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
221 | g_signal_connect( |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
222 | widget, |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
223 | "toggled", |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
224 | G_CALLBACK(ui_toggled_obs), |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
225 | event); |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
226 | g_signal_connect( |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
227 | widget, |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
228 | "destroy", |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
229 | G_CALLBACK(ui_destroy_vardata), |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
230 | event); |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
231 | } |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
232 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
233 | if(onchange) { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
234 | UiEventData *event = malloc(sizeof(UiEventData)); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
235 | event->obj = obj; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
236 | event->userdata = onchangedata; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
237 | event->callback = onchange; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
238 | event->value = 0; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
239 | event->customdata = NULL; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
240 | |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
241 | g_signal_connect( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
242 | widget, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
243 | "toggled", |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
244 | G_CALLBACK(toggled_callback), |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
245 | event); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
246 | g_signal_connect( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
247 | widget, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
248 | "destroy", |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
249 | G_CALLBACK(ui_destroy_userdata), |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
250 | event); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
251 | } |
359
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
252 | |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
253 | if(enable_state > 0) { |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
254 | UiEventData *event = malloc(sizeof(UiEventData)); |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
255 | event->obj = obj; |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
256 | event->userdata = NULL; |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
257 | event->callback = NULL; |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
258 | event->value = enable_state; |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
259 | event->customdata = NULL; |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
260 | |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
261 | g_signal_connect( |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
262 | widget, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
263 | "toggled", |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
264 | G_CALLBACK(enable_state_func), |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
265 | event); |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
266 | g_signal_connect( |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
267 | widget, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
268 | "destroy", |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
269 | G_CALLBACK(ui_destroy_userdata), |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
270 | event); |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
271 | } |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
272 | } |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
273 | |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
274 | static UIWIDGET togglebutton_create(UiObject *obj, GtkWidget *widget, UiToggleArgs args) { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
275 | UiObject* current = uic_current_obj(obj); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
276 | |
359
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
277 | ui_setup_togglebutton( |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
278 | current, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
279 | widget, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
280 | args.label, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
281 | args.icon, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
282 | args.varname, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
283 | args.value, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
284 | args.onchange, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
285 | args.onchangedata, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
286 | args.enable_group); |
313
b679cc6059ab
add option to name widgets and add css classes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
287 | ui_set_name_and_style(widget, args.name, args.style_class); |
343
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
288 | ui_set_widget_groups(obj->ctx, widget, args.groups); |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
289 | |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
290 | UI_APPLY_LAYOUT1(current, args); |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
291 | current->container->add(current->container, widget, FALSE); |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
292 | |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
293 | return widget; |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
294 | } |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
295 | |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
296 | UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
297 | return togglebutton_create(obj, gtk_toggle_button_new(), args); |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
298 | } |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
299 | |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
300 | #if GTK_MAJOR_VERSION >= 4 |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
301 | |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
302 | int64_t ui_check_button_get(UiInteger *integer) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
303 | GtkCheckButton *button = integer->obj; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
304 | integer->value = (int)gtk_check_button_get_active(button); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
305 | return integer->value; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
306 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
307 | |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
308 | void ui_check_button_set(UiInteger *integer, int64_t value) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
309 | GtkCheckButton *button = integer->obj; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
310 | integer->value = value; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
311 | gtk_check_button_set_active(button, value != 0 ? TRUE : FALSE); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
312 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
313 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
314 | static void ui_checkbox_callback(GtkCheckButton *widget, UiEventData *event) { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
315 | UiEvent e; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
316 | e.obj = event->obj; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
317 | e.window = event->obj->window; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
318 | e.document = event->obj->ctx->document; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
319 | e.eventdata = NULL; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
320 | e.intval = gtk_check_button_get_active(widget); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
321 | event->callback(&e, event->userdata); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
322 | } |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
323 | |
359
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
324 | static void ui_checkbox_enable_state(GtkCheckButton *widget, UiEventData *event) { |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
325 | if(gtk_check_button_get_active(widget)) { |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
326 | ui_set_group(event->obj->ctx, event->value); |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
327 | } else { |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
328 | ui_unset_group(event->obj->ctx, event->value); |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
329 | } |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
330 | } |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
331 | |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
332 | UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
333 | UiObject* current = uic_current_obj(obj); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
334 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
335 | GtkWidget *widget = gtk_check_button_new_with_label(args.label); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
336 | ui_bind_togglebutton( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
337 | obj, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
338 | widget, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
339 | ui_check_button_get, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
340 | ui_check_button_set, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
341 | args.varname, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
342 | args.value, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
343 | (ui_toggled_func)ui_checkbox_callback, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
344 | args.onchange, |
359
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
345 | args.onchangedata, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
346 | (ui_toggled_func)ui_checkbox_enable_state, |
c51e58359db8
add option to automatically enable states with toggle buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
350
diff
changeset
|
347 | args.enable_group); |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
348 | |
343
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
349 | ui_set_name_and_style(widget, args.name, args.style_class); |
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
350 | ui_set_widget_groups(obj->ctx, widget, args.groups); |
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
351 | |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
352 | UI_APPLY_LAYOUT1(current, args); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
353 | current->container->add(current->container, widget, FALSE); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
354 | |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
355 | return widget; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
356 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
357 | |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
358 | #else |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
359 | UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
360 | return togglebutton_create(obj, gtk_check_button_new(), args); |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
361 | } |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
362 | #endif |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
363 | |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
364 | UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs args) { |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
365 | #ifdef UI_GTK3 |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
366 | return NULL; // TODO |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
367 | #else |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
368 | return ui_checkbox_create(obj, args); |
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
369 | #endif |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
370 | } |
107
9aff1dc3990d
improved box container and added radio button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
371 | |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
372 | #if GTK_MAJOR_VERSION >= 4 |
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
373 | #define RADIOBUTTON_NEW(group, label) gtk_check_button_new_with_label(label) |
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
374 | #define RADIOBUTTON_SET_GROUP(button, group) |
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
375 | #define RADIOBUTTON_GET_GROUP(button) GTK_CHECK_BUTTON(button) |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
376 | #define RADIOBUTTON_GET_ACTIVE(button) gtk_check_button_get_active(GTK_CHECK_BUTTON(button)) |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
377 | #else |
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
378 | #define RADIOBUTTON_NEW(group, label) gtk_radio_button_new_with_label(group, label) |
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
379 | #define RADIOBUTTON_SET_GROUP(button, group) /* noop */ |
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
380 | #define RADIOBUTTON_GET_GROUP(button) gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)) |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
381 | #define RADIOBUTTON_GET_ACTIVE(button) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
382 | #endif |
257
a334f9ebc5d0
update button, togglebutton and checkbox to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
383 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
384 | static void radiobutton_toggled(void *widget, UiEventData *event) { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
385 | UiEvent e; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
386 | e.obj = event->obj; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
387 | e.window = event->obj->window; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
388 | e.document = event->obj->ctx->document; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
389 | e.eventdata = NULL; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
390 | e.intval = RADIOBUTTON_GET_ACTIVE(widget); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
391 | event->callback(&e, event->userdata); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
392 | } |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
393 | |
399
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
394 | typedef struct UiRadioButtonData { |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
395 | UiInteger *value; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
396 | UiVarEventData *eventdata; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
397 | UiBool first; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
398 | } UiRadioButtonData; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
399 | |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
400 | static void destroy_radiobutton(GtkWidget *w, UiRadioButtonData *data) { |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
401 | if(data->first) { |
403
b59935b2de79
fix radiobutton destroy callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
399
diff
changeset
|
402 | ui_destroy_vardata(w, data->eventdata); |
399
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
403 | g_slist_free(data->value->obj); |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
404 | data->value->obj = NULL; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
405 | data->value->get = NULL; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
406 | data->value->set = NULL; |
403
b59935b2de79
fix radiobutton destroy callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
399
diff
changeset
|
407 | } else { |
b59935b2de79
fix radiobutton destroy callback (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
399
diff
changeset
|
408 | free(data->eventdata); |
399
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
409 | } |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
410 | free(data); |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
411 | } |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
412 | |
258
a252f68c665a
port radiobutton to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
257
diff
changeset
|
413 | UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) { |
a252f68c665a
port radiobutton to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
257
diff
changeset
|
414 | UiObject* current = uic_current_obj(obj); |
a252f68c665a
port radiobutton to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
257
diff
changeset
|
415 | |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
416 | GSList *rg = NULL; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
417 | UiInteger *rgroup; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
418 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
419 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); |
258
a252f68c665a
port radiobutton to the new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
257
diff
changeset
|
420 | |
274
9e2aee097b69
fix double free on radiobutton group destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
421 | UiBool first = FALSE; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
422 | if(var) { |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
423 | rgroup = var->value; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
424 | rg = rgroup->obj; |
274
9e2aee097b69
fix double free on radiobutton group destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
425 | if(!rg) { |
9e2aee097b69
fix double free on radiobutton group destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
426 | first = TRUE; |
9e2aee097b69
fix double free on radiobutton group destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
427 | } |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
428 | } |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
429 | |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
430 | GtkWidget *rbutton = RADIOBUTTON_NEW(rg, args.label); |
313
b679cc6059ab
add option to name widgets and add css classes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
431 | ui_set_name_and_style(rbutton, args.name, args.style_class); |
343
54f5d7eb1335
implement widget groups for buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
432 | ui_set_widget_groups(obj->ctx, rbutton, args.groups); |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
433 | if(rgroup) { |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
434 | #if GTK_MAJOR_VERSION >= 4 |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
435 | if(rg) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
436 | gtk_check_button_set_group(GTK_CHECK_BUTTON(rbutton), rg->data); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
437 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
438 | rg = g_slist_prepend(rg, rbutton); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
439 | #else |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
440 | gtk_radio_button_set_group(GTK_RADIO_BUTTON(rbutton), rg); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
441 | rg = gtk_radio_button_get_group(GTK_RADIO_BUTTON(rbutton)); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
442 | #endif |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
443 | |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
444 | rgroup->obj = rg; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
445 | rgroup->get = ui_radiobutton_get; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
446 | rgroup->set = ui_radiobutton_set; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
447 | |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
448 | ui_radiobutton_set(rgroup, rgroup->value); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
449 | |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
450 | UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
451 | event->obj = obj; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
452 | event->var = var; |
145
853685152c1d
adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
453 | event->observers = NULL; |
264
24d9a92fd048
update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
261
diff
changeset
|
454 | event->callback = NULL; |
24d9a92fd048
update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
261
diff
changeset
|
455 | event->userdata = NULL; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
456 | |
399
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
457 | UiRadioButtonData *rbdata = malloc(sizeof(UiRadioButtonData)); |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
458 | rbdata->value = rgroup; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
459 | rbdata->eventdata = event; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
460 | rbdata->first = first; |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
461 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
462 | g_signal_connect( |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
463 | rbutton, |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
464 | "toggled", |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
465 | G_CALLBACK(ui_radio_obs), |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
466 | event); |
399
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
467 | g_signal_connect( |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
468 | rbutton, |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
469 | "destroy", |
399
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
470 | G_CALLBACK(destroy_radiobutton), |
bb3f3fe2d5ee
safely unbind radio buttons (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
471 | rbdata); |
107
9aff1dc3990d
improved box container and added radio button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
472 | } |
9aff1dc3990d
improved box container and added radio button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
473 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
474 | if(args.onchange) { |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
475 | UiEventData *event = malloc(sizeof(UiEventData)); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
476 | event->obj = obj; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
477 | event->userdata = args.onchangedata; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
478 | event->callback = args.onchange; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
479 | event->value = 0; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
480 | event->customdata = NULL; |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
481 | |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
482 | g_signal_connect( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
483 | rbutton, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
484 | "toggled", |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
485 | G_CALLBACK(radiobutton_toggled), |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
486 | event); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
487 | g_signal_connect( |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
488 | rbutton, |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
489 | "destroy", |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
490 | G_CALLBACK(ui_destroy_userdata), |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
491 | event); |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
492 | } |
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
301
diff
changeset
|
493 | |
339
b68b5f984074
add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
313
diff
changeset
|
494 | UI_APPLY_LAYOUT1(current, args); |
b68b5f984074
add minimally working image viewer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
313
diff
changeset
|
495 | current->container->add(current->container, rbutton, FALSE); |
107
9aff1dc3990d
improved box container and added radio button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
496 | |
9aff1dc3990d
improved box container and added radio button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
497 | return rbutton; |
9aff1dc3990d
improved box container and added radio button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
498 | } |
9aff1dc3990d
improved box container and added radio button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
499 | |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
500 | void ui_radio_obs(GtkToggleButton *widget, UiVarEventData *event) { |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
501 | UiInteger *i = event->var->value; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
502 | |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
503 | UiEvent e; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
504 | e.obj = event->obj; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
505 | e.window = event->obj->window; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
506 | e.document = event->obj->ctx->document; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
507 | e.eventdata = NULL; |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
508 | e.intval = i->get(i); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
509 | |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
510 | ui_notify_evt(i->observers, &e); |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
511 | } |
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
512 | |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
513 | #if GTK_MAJOR_VERSION >= 4 |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
514 | int64_t ui_radiobutton_get(UiInteger *value) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
515 | int selection = 0; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
516 | GSList *ls = value->obj; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
517 | int i = 0; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
518 | guint len = g_slist_length(ls); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
519 | while(ls) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
520 | if(gtk_check_button_get_active(GTK_CHECK_BUTTON(ls->data))) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
521 | selection = len - i - 1; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
522 | break; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
523 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
524 | ls = ls->next; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
525 | i++; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
526 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
527 | |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
528 | value->value = selection; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
529 | return selection; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
530 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
531 | |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
532 | void ui_radiobutton_set(UiInteger *value, int64_t i) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
533 | GSList *ls = value->obj; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
534 | int s = g_slist_length(ls) - 1 - i; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
535 | int j = 0; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
536 | while(ls) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
537 | if(j == s) { |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
538 | gtk_check_button_set_active(GTK_CHECK_BUTTON(ls->data), TRUE); |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
539 | break; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
540 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
541 | ls = ls->next; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
542 | j++; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
543 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
544 | |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
545 | value->value = i; |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
546 | } |
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
547 | #else |
144
29d98cff4f56
UiInteger uses int64 now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
548 | int64_t ui_radiobutton_get(UiInteger *value) { |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
549 | int selection = 0; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
550 | GSList *ls = value->obj; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
551 | int i = 0; |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
552 | guint len = g_slist_length(ls); |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
553 | while(ls) { |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
554 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ls->data))) { |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
555 | selection = len - i - 1; |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
556 | break; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
557 | } |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
558 | ls = ls->next; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
559 | i++; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
560 | } |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
561 | |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
562 | value->value = selection; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
563 | return selection; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
564 | } |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
565 | |
144
29d98cff4f56
UiInteger uses int64 now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
566 | void ui_radiobutton_set(UiInteger *value, int64_t i) { |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
567 | GSList *ls = value->obj; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
568 | int s = g_slist_length(ls) - 1 - i; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
569 | int j = 0; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
570 | while(ls) { |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
571 | if(j == s) { |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
572 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ls->data), TRUE); |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
573 | break; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
574 | } |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
575 | ls = ls->next; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
576 | j++; |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
577 | } |
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
578 | |
142
46448d38885c
new checkbox and radionbutton features and more refactoring
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
579 | value->value = i; |
108
fcf6d5fac8f5
radio buttons bind to UiInteger now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
580 | } |
301
f9e7c57e1e2f
fix gtk4 checkbox and radiobutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
581 | #endif |