Sun, 06 Oct 2024 18:43:06 +0200
fix startup in case the dav config doesn't exist
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 | ||
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
57 | GtkWidget* ui_create_button( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
58 | UiObject *obj, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
59 | const char *label, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
60 | const char *icon, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
61 | ui_callback onclick, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
62 | void *userdata) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
63 | { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
64 | GtkWidget *button = gtk_button_new_with_label(label); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
65 | ui_button_set_icon_name(button, icon); |
32 | 66 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
67 | if(onclick) { |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | UiEventData *event = malloc(sizeof(UiEventData)); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | event->obj = obj; |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
70 | event->userdata = userdata; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
71 | event->callback = onclick; |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | event->value = 0; |
32 | 73 | event->customdata = NULL; |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | g_signal_connect( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | button, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | "clicked", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | G_CALLBACK(ui_button_clicked), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | event); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | g_signal_connect( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | button, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | "destroy", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | G_CALLBACK(ui_destroy_userdata), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | event); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
87 | return button; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
88 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
89 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
90 | UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
91 | UiObject* current = uic_current_obj(obj); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
92 | GtkWidget *button = ui_create_button(obj, args.label, args.icon, args.onclick, args.onclickdata); |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
93 | ui_set_name_and_style(button, args.name, args.style_class); |
32 | 94 | UI_APPLY_LAYOUT1(current, args); |
95 | current->container->add(current->container, button, FALSE); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | return button; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | void ui_button_clicked(GtkWidget *widget, UiEventData *event) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | UiEvent e; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | e.obj = event->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | e.window = event->obj->window; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | e.document = event->obj->ctx->document; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | e.eventdata = NULL; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | e.intval = event->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | event->callback(&e, event->userdata); |
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 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | int64_t ui_toggle_button_get(UiInteger *integer) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | GtkToggleButton *button = integer->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | integer->value = (int)gtk_toggle_button_get_active(button); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | return integer->value; |
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 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | void ui_toggle_button_set(UiInteger *integer, int64_t value) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | GtkToggleButton *button = integer->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | integer->value = value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | gtk_toggle_button_set_active(button, value != 0 ? TRUE : FALSE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
122 | void ui_toggled_obs(void *widget, UiVarEventData *event) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
123 | UiInteger *i = event->var->value; |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | UiEvent e; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | e.obj = event->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | e.window = event->obj->window; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | e.document = event->obj->ctx->document; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | e.eventdata = event->var->value; |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
129 | e.intval = i->get(i); |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | ui_notify_evt(i->observers, &e); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
134 | static void ui_toggled_callback(GtkToggleButton *widget, UiEventData *event) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
135 | UiEvent e; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
136 | e.obj = event->obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
137 | e.window = event->obj->window; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
138 | e.document = event->obj->ctx->document; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
139 | e.eventdata = NULL; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
140 | e.intval = gtk_toggle_button_get_active(widget); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
141 | event->callback(&e, event->userdata); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
142 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
143 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
144 | void ui_setup_togglebutton( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
145 | UiObject *obj, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
146 | GtkWidget *togglebutton, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
147 | const char *label, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
148 | const char *icon, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
149 | const char *varname, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
150 | UiInteger *value, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
151 | ui_callback onchange, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
152 | void *onchangedata) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
153 | { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
154 | if(label) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
155 | gtk_button_set_label(GTK_BUTTON(togglebutton), label); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
156 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
157 | ui_button_set_icon_name(togglebutton, icon); |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
159 | ui_bind_togglebutton( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
160 | obj, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
161 | togglebutton, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
162 | ui_toggle_button_get, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
163 | ui_toggle_button_set, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
164 | varname, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
165 | value, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
166 | (ui_toggled_func)ui_toggled_callback, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
167 | onchange, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
168 | onchangedata); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
169 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
170 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
171 | void ui_bind_togglebutton( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
172 | UiObject *obj, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
173 | GtkWidget *widget, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
174 | int64_t (*getfunc)(UiInteger*), |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
175 | void (*setfunc)(UiInteger*, int64_t), |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
176 | const char *varname, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
177 | UiInteger *value, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
178 | void (*toggled_callback)(void*, void*), |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
179 | ui_callback onchange, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
180 | void *onchangedata) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
181 | { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
182 | UiObject* current = uic_current_obj(obj); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
183 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, value, varname, UI_VAR_INTEGER); |
32 | 184 | if (var) { |
185 | UiInteger* value = (UiInteger*)var->value; | |
186 | value->obj = widget; | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
187 | value->get = getfunc; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
188 | value->set = setfunc; |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | event->obj = obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | event->var = var; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | event->observers = NULL; |
32 | 194 | event->callback = NULL; |
195 | event->userdata = NULL; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | g_signal_connect( |
32 | 198 | widget, |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
199 | "toggled", |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | G_CALLBACK(ui_toggled_obs), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | event); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | g_signal_connect( |
32 | 203 | widget, |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | "destroy", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | G_CALLBACK(ui_destroy_vardata), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | event); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
209 | if(onchange) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
210 | UiEventData *event = malloc(sizeof(UiEventData)); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
211 | event->obj = obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
212 | event->userdata = onchangedata; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
213 | event->callback = onchange; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
214 | event->value = 0; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
215 | event->customdata = NULL; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
216 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
217 | g_signal_connect( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
218 | widget, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
219 | "toggled", |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
220 | G_CALLBACK(toggled_callback), |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
221 | event); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
222 | g_signal_connect( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
223 | widget, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
224 | "destroy", |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
225 | G_CALLBACK(ui_destroy_userdata), |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
226 | event); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
227 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
228 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
229 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
230 | static UIWIDGET togglebutton_create(UiObject *obj, GtkWidget *widget, UiToggleArgs args) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
231 | UiObject* current = uic_current_obj(obj); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
232 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
233 | ui_setup_togglebutton(current, widget, args.label, args.icon, args.varname, args.value, args.onchange, args.onchangedata); |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
234 | ui_set_name_and_style(widget, args.name, args.style_class); |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
235 | |
32 | 236 | UI_APPLY_LAYOUT1(current, args); |
237 | current->container->add(current->container, widget, FALSE); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | |
32 | 239 | return widget; |
240 | } | |
241 | ||
242 | UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { | |
243 | return togglebutton_create(obj, gtk_toggle_button_new(), args); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
246 | #if GTK_MAJOR_VERSION >= 4 |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
247 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
248 | int64_t ui_check_button_get(UiInteger *integer) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
249 | GtkCheckButton *button = integer->obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
250 | integer->value = (int)gtk_check_button_get_active(button); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
251 | return integer->value; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
252 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
253 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
254 | void ui_check_button_set(UiInteger *integer, int64_t value) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
255 | GtkCheckButton *button = integer->obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
256 | integer->value = value; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
257 | gtk_check_button_set_active(button, value != 0 ? TRUE : FALSE); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
258 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
259 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
260 | static void ui_checkbox_callback(GtkCheckButton *widget, UiEventData *event) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
261 | UiEvent e; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
262 | e.obj = event->obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
263 | e.window = event->obj->window; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
264 | e.document = event->obj->ctx->document; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
265 | e.eventdata = NULL; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
266 | e.intval = gtk_check_button_get_active(widget); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
267 | event->callback(&e, event->userdata); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
268 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
269 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
270 | UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
271 | UiObject* current = uic_current_obj(obj); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
272 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
273 | GtkWidget *widget = gtk_check_button_new_with_label(args.label); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
274 | ui_bind_togglebutton( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
275 | obj, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
276 | widget, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
277 | ui_check_button_get, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
278 | ui_check_button_set, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
279 | args.varname, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
280 | args.value, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
281 | (ui_toggled_func)ui_checkbox_callback, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
282 | args.onchange, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
283 | args.onchangedata); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
284 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
285 | UI_APPLY_LAYOUT1(current, args); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
286 | current->container->add(current->container, widget, FALSE); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
287 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
288 | return widget; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
289 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
290 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
291 | #else |
32 | 292 | UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
293 | return togglebutton_create(obj, gtk_check_button_new(), args); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | } |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
295 | #endif |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | |
32 | 297 | UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs args) { |
298 | #ifdef UI_GTK3 | |
299 | return NULL; // TODO | |
300 | #else | |
301 | return ui_checkbox_create(obj, args); | |
302 | #endif | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
305 | #if GTK_MAJOR_VERSION >= 4 |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
306 | #define RADIOBUTTON_NEW(group, label) gtk_check_button_new_with_label(label) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
307 | #define RADIOBUTTON_SET_GROUP(button, group) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
308 | #define RADIOBUTTON_GET_GROUP(button) GTK_CHECK_BUTTON(button) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
309 | #define RADIOBUTTON_GET_ACTIVE(button) gtk_check_button_get_active(GTK_CHECK_BUTTON(button)) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
310 | #else |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
311 | #define RADIOBUTTON_NEW(group, label) gtk_radio_button_new_with_label(group, label) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
312 | #define RADIOBUTTON_SET_GROUP(button, group) /* noop */ |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
313 | #define RADIOBUTTON_GET_GROUP(button) gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
314 | #define RADIOBUTTON_GET_ACTIVE(button) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
315 | #endif |
32 | 316 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
317 | static void radiobutton_toggled(void *widget, UiEventData *event) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
318 | UiEvent e; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
319 | e.obj = event->obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
320 | e.window = event->obj->window; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
321 | e.document = event->obj->ctx->document; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
322 | e.eventdata = NULL; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
323 | e.intval = RADIOBUTTON_GET_ACTIVE(widget); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
324 | event->callback(&e, event->userdata); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
325 | } |
32 | 326 | |
327 | UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) { | |
328 | UiObject* current = uic_current_obj(obj); | |
329 | ||
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | GSList *rg = NULL; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | UiInteger *rgroup; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
333 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); |
32 | 334 | |
335 | UiBool first = FALSE; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | if(var) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | rgroup = var->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | rg = rgroup->obj; |
32 | 339 | if(!rg) { |
340 | first = TRUE; | |
341 | } | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
344 | GtkWidget *rbutton = RADIOBUTTON_NEW(rg, args.label); |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
345 | ui_set_name_and_style(rbutton, args.name, args.style_class); |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | if(rgroup) { |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
347 | #if GTK_MAJOR_VERSION >= 4 |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
348 | if(rg) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
349 | gtk_check_button_set_group(GTK_CHECK_BUTTON(rbutton), rg->data); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
350 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
351 | rg = g_slist_prepend(rg, rbutton); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
352 | #else |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
353 | gtk_radio_button_set_group(GTK_RADIO_BUTTON(rbutton), rg); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
354 | rg = gtk_radio_button_get_group(GTK_RADIO_BUTTON(rbutton)); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
355 | #endif |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
356 | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | rgroup->obj = rg; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | rgroup->get = ui_radiobutton_get; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359 | rgroup->set = ui_radiobutton_set; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | ui_radiobutton_set(rgroup, rgroup->value); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | event->obj = obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | event->var = var; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | event->observers = NULL; |
32 | 367 | event->callback = NULL; |
368 | event->userdata = NULL; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | g_signal_connect( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | rbutton, |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
372 | "toggled", |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | G_CALLBACK(ui_radio_obs), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | event); |
32 | 375 | if(first) { |
376 | g_signal_connect( | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | rbutton, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | "destroy", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | G_CALLBACK(ui_destroy_vardata), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | event); |
32 | 381 | } |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
384 | if(args.onchange) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
385 | UiEventData *event = malloc(sizeof(UiEventData)); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
386 | event->obj = obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
387 | event->userdata = args.onchangedata; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
388 | event->callback = args.onchange; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
389 | event->value = 0; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
390 | event->customdata = NULL; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
391 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
392 | g_signal_connect( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
393 | rbutton, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
394 | "toggled", |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
395 | G_CALLBACK(radiobutton_toggled), |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
396 | event); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
397 | g_signal_connect( |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
398 | rbutton, |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
399 | "destroy", |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
400 | G_CALLBACK(ui_destroy_userdata), |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
401 | event); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
402 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
403 | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | UiContainer *ct = uic_get_current_container(obj); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | ct->add(ct, rbutton, FALSE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | return rbutton; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
410 | void ui_radio_obs(GtkToggleButton *widget, UiVarEventData *event) { |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | UiInteger *i = event->var->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | UiEvent e; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | e.obj = event->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | e.window = event->obj->window; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | e.document = event->obj->ctx->document; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | e.eventdata = NULL; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | e.intval = i->get(i); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
420 | ui_notify_evt(i->observers, &e); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
423 | #if GTK_MAJOR_VERSION >= 4 |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
424 | int64_t ui_radiobutton_get(UiInteger *value) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
425 | int selection = 0; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
426 | GSList *ls = value->obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
427 | int i = 0; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
428 | guint len = g_slist_length(ls); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
429 | while(ls) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
430 | if(gtk_check_button_get_active(GTK_CHECK_BUTTON(ls->data))) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
431 | selection = len - i - 1; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
432 | break; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
433 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
434 | ls = ls->next; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
435 | i++; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
436 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
437 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
438 | value->value = selection; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
439 | return selection; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
440 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
441 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
442 | void ui_radiobutton_set(UiInteger *value, int64_t i) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
443 | GSList *ls = value->obj; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
444 | int s = g_slist_length(ls) - 1 - i; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
445 | int j = 0; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
446 | while(ls) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
447 | if(j == s) { |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
448 | gtk_check_button_set_active(GTK_CHECK_BUTTON(ls->data), TRUE); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
449 | break; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
450 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
451 | ls = ls->next; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
452 | j++; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
453 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
454 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
455 | value->value = i; |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
456 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
457 | #else |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | int64_t ui_radiobutton_get(UiInteger *value) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | int selection = 0; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | GSList *ls = value->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | int i = 0; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | guint len = g_slist_length(ls); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | while(ls) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | 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
|
465 | selection = len - i - 1; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | break; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | ls = ls->next; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | i++; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | value->value = selection; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | return selection; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | void ui_radiobutton_set(UiInteger *value, int64_t i) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | GSList *ls = value->obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | int s = g_slist_length(ls) - 1 - i; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | int j = 0; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | while(ls) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | if(j == s) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | 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
|
483 | break; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485 | ls = ls->next; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
486 | j++; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489 | value->value = i; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
490 | } |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
491 | #endif |