ui/gtk/entry.c

Thu, 03 Oct 2024 18:08:29 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 03 Oct 2024 18:08:29 +0200
changeset 46
31bc86844659
parent 45
ab71409644b0
child 60
ee4e4742391e
permissions
-rw-r--r--

implement action_newfile

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 "../common/context.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../common/object.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "container.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "entry.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
38 UIWIDGET ui_spinner_create(UiObject *obj, UiSpinnerArgs args) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 double min = 0;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 double max = 1000;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
41
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
42 UiObject* current = uic_current_obj(obj);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
43
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
44 UiVar *var = NULL;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
45 if(args.varname) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
46 var = uic_get_var(obj->ctx, args.varname);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
47 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
48
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
49 if(!var) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
50 if(args.intvalue) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
51 var = uic_widget_var(obj->ctx, current->ctx, args.intvalue, NULL, UI_VAR_INTEGER);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
52 } else if(args.doublevalue) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
53 var = uic_widget_var(obj->ctx, current->ctx, args.doublevalue, NULL, UI_VAR_DOUBLE);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
54 } else if(args.rangevalue) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
55 var = uic_widget_var(obj->ctx, current->ctx, args.rangevalue, NULL, UI_VAR_RANGE);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
56 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
57 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
58
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
59 if(var && var->type == UI_VAR_RANGE) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 UiRange *r = var->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 min = r->min;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 max = r->max;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 }
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
64 if(args.step == 0) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
65 args.step = 1;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 #ifdef UI_GTK2LEGACY
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 if(min == max) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 max = min + 1;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 #endif
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
72 GtkWidget *spin = gtk_spin_button_new_with_range(min, max, args.step);
45
ab71409644b0 update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
73 ui_set_name_and_style(spin, args.name, args.style_class);
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
74 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), args.digits);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
75 UiObserver **obs = NULL;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 if(var) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 double value = 0;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
78 switch(var->type) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 default: break;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 case UI_VAR_INTEGER: {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 UiInteger *i = var->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 i->get = ui_spinbutton_getint;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 i->set = ui_spinbutton_setint;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 i->obj = spin;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 value = (double)i->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 obs = &i->observers;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 break;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 case UI_VAR_DOUBLE: {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 UiDouble *d = var->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 d->get = ui_spinbutton_getdouble;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 d->set = ui_spinbutton_setdouble;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 d->obj = spin;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 value = d->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 obs = &d->observers;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 break;
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 case UI_VAR_RANGE: {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 UiRange *r = var->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 r->get = ui_spinbutton_getrangeval;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 r->set = ui_spinbutton_setrangeval;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 r->setrange = ui_spinbutton_setrange;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 r->setextent = ui_spinbutton_setextent;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 r->obj = spin;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 value = r->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 obs = &r->observers;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 break;
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 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), value);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
113 UiVarEventData *event = malloc(sizeof(UiVarEventData));
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
114 event->obj = obj;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
115 event->var = var;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
116 event->observers = obs;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
117 event->callback = args.onchange;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
118 event->userdata = args.onchangedata;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
119
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
120 g_signal_connect(
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
121 spin,
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
122 "value-changed",
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
123 G_CALLBACK(ui_spinner_changed),
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
124 event);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
125 g_signal_connect(
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
126 spin,
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
127 "destroy",
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
128 G_CALLBACK(ui_destroy_vardata),
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
129 event);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
130
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
131 UI_APPLY_LAYOUT1(current, args);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
132 current->container->add(current->container, spin, FALSE);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 return spin;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 void ui_spinner_setrange(UIWIDGET spinner, double min, double max) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 gtk_spin_button_set_range(GTK_SPIN_BUTTON(spinner), min, max);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 void ui_spinner_setdigits(UIWIDGET spinner, int digits) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinner), digits);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 void ui_spinner_changed(GtkSpinButton *spinner, UiVarEventData *event) {
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
147 gdouble value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinner));
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 UiEvent e;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 e.obj = event->obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 e.window = event->obj->window;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 e.document = event->obj->ctx->document;
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
152 e.eventdata = &value;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
153 e.intval = (int64_t)value;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154
32
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
155 if(event->callback) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
156 event->callback(&e, event->userdata);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
157 }
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
158
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
159 if(event->observers) {
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
160 UiObserver *observer = *event->observers;
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
161 ui_notify_evt(observer, &e);
e5f4d8af567e update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
162 }
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 int64_t ui_spinbutton_getint(UiInteger *i) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 i->value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(i->obj));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 return i->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 void ui_spinbutton_setint(UiInteger *i, int64_t val) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->obj), (double)val);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 i->value = val;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 double ui_spinbutton_getdouble(UiDouble *d) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 d->value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(d->obj));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 return d->value;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 void ui_spinbutton_setdouble(UiDouble *d, double val) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 gtk_spin_button_set_value(GTK_SPIN_BUTTON(d->obj), val);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 d->value = val;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 double ui_spinbutton_getrangeval(UiRange *r) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 r->value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(r->obj));
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 return r->value;
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
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 void ui_spinbutton_setrangeval(UiRange *r, double val) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->obj), val);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 r->value = val;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 void ui_spinbutton_setrange(UiRange *r, double min, double max) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 gtk_spin_button_set_range(GTK_SPIN_BUTTON(r->obj), min, max);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 r->min = min;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 r->max = max;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 void ui_spinbutton_setextent(UiRange *r, double extent) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 gtk_spin_button_set_increments(GTK_SPIN_BUTTON(r->obj), extent, extent*10);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 r->extent = extent;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 }

mercurial