ui/gtk/entry.c

Mon, 16 Sep 2024 22:09:32 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 16 Sep 2024 22:09:32 +0200
branch
newapi
changeset 298
c5e207d01ff2
parent 264
24d9a92fd048
child 313
b679cc6059ab
permissions
-rw-r--r--

port button, text to gtk4

145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "../common/context.h"
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../common/object.h"
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "container.h"
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "entry.h"
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
38 UIWIDGET ui_spinner_create(UiObject *obj, UiSpinnerArgs args) {
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 double min = 0;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 double max = 1000;
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
41
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
42 UiObject* current = uic_current_obj(obj);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
43
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
44 UiVar *var = NULL;
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
45 if(args.varname) {
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
46 var = uic_get_var(obj->ctx, args.varname);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
47 }
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
48
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
49 if(!var) {
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
50 if(args.intvalue) {
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
51 var = uic_widget_var(obj->ctx, current->ctx, args.intvalue, NULL, UI_VAR_INTEGER);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
52 } else if(args.doublevalue) {
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
53 var = uic_widget_var(obj->ctx, current->ctx, args.doublevalue, NULL, UI_VAR_DOUBLE);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
54 } else if(args.rangevalue) {
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
55 var = uic_widget_var(obj->ctx, current->ctx, args.rangevalue, NULL, UI_VAR_RANGE);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
56 }
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
57 }
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
58
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
59 if(var && var->type == UI_VAR_RANGE) {
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 UiRange *r = var->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 min = r->min;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 max = r->max;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 }
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
64 if(args.step == 0) {
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
65 args.step = 1;
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 }
151
11f3bb408051 fixes gtk2legacy build
Olaf Wintermanm <olaf.wintermann@gmail.com>
parents: 145
diff changeset
67 #ifdef UI_GTK2LEGACY
11f3bb408051 fixes gtk2legacy build
Olaf Wintermanm <olaf.wintermann@gmail.com>
parents: 145
diff changeset
68 if(min == max) {
11f3bb408051 fixes gtk2legacy build
Olaf Wintermanm <olaf.wintermann@gmail.com>
parents: 145
diff changeset
69 max = min + 1;
11f3bb408051 fixes gtk2legacy build
Olaf Wintermanm <olaf.wintermann@gmail.com>
parents: 145
diff changeset
70 }
11f3bb408051 fixes gtk2legacy build
Olaf Wintermanm <olaf.wintermann@gmail.com>
parents: 145
diff changeset
71 #endif
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
72 GtkWidget *spin = gtk_spin_button_new_with_range(min, max, args.step);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
73 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), args.digits);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
74 UiObserver **obs = NULL;
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 if(var) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 double value = 0;
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
77 switch(var->type) {
164
1d912f78fd1d fix some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
78 default: break;
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 case UI_VAR_INTEGER: {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 UiInteger *i = var->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 i->get = ui_spinbutton_getint;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 i->set = ui_spinbutton_setint;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 i->obj = spin;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 value = (double)i->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 obs = &i->observers;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 case UI_VAR_DOUBLE: {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 UiDouble *d = var->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 d->get = ui_spinbutton_getdouble;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 d->set = ui_spinbutton_setdouble;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 d->obj = spin;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 value = d->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 obs = &d->observers;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 case UI_VAR_RANGE: {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 UiRange *r = var->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 r->get = ui_spinbutton_getrangeval;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 r->set = ui_spinbutton_setrangeval;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 r->setrange = ui_spinbutton_setrange;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 r->setextent = ui_spinbutton_setextent;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 r->obj = spin;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 value = r->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 obs = &r->observers;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 break;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), value);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
112 UiVarEventData *event = malloc(sizeof(UiVarEventData));
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
113 event->obj = obj;
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
114 event->var = var;
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
115 event->observers = obs;
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
116 event->callback = args.onchange;
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
117 event->userdata = args.onchangedata;
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
118
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
119 g_signal_connect(
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
120 spin,
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
121 "value-changed",
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
122 G_CALLBACK(ui_spinner_changed),
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
123 event);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
124 g_signal_connect(
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
125 spin,
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
126 "destroy",
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
127 G_CALLBACK(ui_destroy_vardata),
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
128 event);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
129
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
130 UI_APPLY_LAYOUT1(current, args);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
131 current->container->add(current->container, spin, FALSE);
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 return spin;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 void ui_spinner_setrange(UIWIDGET spinner, double min, double max) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 gtk_spin_button_set_range(GTK_SPIN_BUTTON(spinner), min, max);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 void ui_spinner_setdigits(UIWIDGET spinner, int digits) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinner), digits);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 void ui_spinner_changed(GtkSpinButton *spinner, UiVarEventData *event) {
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
146 gdouble value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinner));
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 UiEvent e;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 e.obj = event->obj;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 e.window = event->obj->window;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 e.document = event->obj->ctx->document;
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
151 e.eventdata = &value;
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
152 e.intval = (int64_t)value;
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153
264
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
154 if(event->callback) {
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
155 event->callback(&e, event->userdata);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
156 }
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
157
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
158 if(event->observers) {
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
159 UiObserver *observer = *event->observers;
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
160 ui_notify_evt(observer, &e);
24d9a92fd048 update spinner entry widget api (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
161 }
145
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 int64_t ui_spinbutton_getint(UiInteger *i) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 i->value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(i->obj));
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 return i->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 void ui_spinbutton_setint(UiInteger *i, int64_t val) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->obj), (double)val);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 i->value = val;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 double ui_spinbutton_getdouble(UiDouble *d) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 d->value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(d->obj));
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 return d->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 void ui_spinbutton_setdouble(UiDouble *d, double val) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 gtk_spin_button_set_value(GTK_SPIN_BUTTON(d->obj), val);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 d->value = val;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 double ui_spinbutton_getrangeval(UiRange *r) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 r->value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(r->obj));
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 return r->value;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 void ui_spinbutton_setrangeval(UiRange *r, double val) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->obj), val);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 r->value = val;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 void ui_spinbutton_setrange(UiRange *r, double min, double max) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 gtk_spin_button_set_range(GTK_SPIN_BUTTON(r->obj), min, max);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 r->min = min;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 r->max = max;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 }
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 void ui_spinbutton_setextent(UiRange *r, double extent) {
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 gtk_spin_button_set_increments(GTK_SPIN_BUTTON(r->obj), extent, extent*10);
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 r->extent = extent;
853685152c1d adds spinner widget (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 }

mercurial