| 33 #include "../common/object.h" |
33 #include "../common/object.h" |
| 34 #include "container.h" |
34 #include "container.h" |
| 35 #include "entry.h" |
35 #include "entry.h" |
| 36 |
36 |
| 37 |
37 |
| 38 UIWIDGET ui_spinner_create(UiObject *obj, UiSpinnerArgs args) { |
38 UIWIDGET ui_spinner_create(UiObject *obj, UiSpinnerArgs *args) { |
| 39 double min = 0; |
39 double min = 0; |
| 40 double max = 1000; |
40 double max = 1000; |
| 41 |
41 |
| 42 UiObject* current = uic_current_obj(obj); |
42 UiObject* current = uic_current_obj(obj); |
| 43 |
43 |
| 44 UiVar *var = NULL; |
44 UiVar *var = NULL; |
| 45 if(args.varname) { |
45 if(args->varname) { |
| 46 var = uic_get_var(obj->ctx, args.varname); |
46 var = uic_get_var(obj->ctx, args->varname); |
| 47 } |
47 } |
| 48 |
48 |
| 49 if(!var) { |
49 if(!var) { |
| 50 if(args.intvalue) { |
50 if(args->intvalue) { |
| 51 var = uic_widget_var(obj->ctx, current->ctx, args.intvalue, NULL, UI_VAR_INTEGER); |
51 var = uic_widget_var(obj->ctx, current->ctx, args->intvalue, NULL, UI_VAR_INTEGER); |
| 52 } else if(args.doublevalue) { |
52 } else if(args->doublevalue) { |
| 53 var = uic_widget_var(obj->ctx, current->ctx, args.doublevalue, NULL, UI_VAR_DOUBLE); |
53 var = uic_widget_var(obj->ctx, current->ctx, args->doublevalue, NULL, UI_VAR_DOUBLE); |
| 54 } else if(args.rangevalue) { |
54 } else if(args->rangevalue) { |
| 55 var = uic_widget_var(obj->ctx, current->ctx, args.rangevalue, NULL, UI_VAR_RANGE); |
55 var = uic_widget_var(obj->ctx, current->ctx, args->rangevalue, NULL, UI_VAR_RANGE); |
| 56 } |
56 } |
| 57 } |
57 } |
| 58 |
58 |
| 59 if(var && var->type == UI_VAR_RANGE) { |
59 if(var && var->type == UI_VAR_RANGE) { |
| 60 UiRange *r = var->value; |
60 UiRange *r = var->value; |
| 61 min = r->min; |
61 min = r->min; |
| 62 max = r->max; |
62 max = r->max; |
| 63 } |
63 } |
| 64 if(args.step == 0) { |
64 if(args->step == 0) { |
| 65 args.step = 1; |
65 args->step = 1; |
| 66 } |
66 } |
| 67 #ifdef UI_GTK2LEGACY |
67 #ifdef UI_GTK2LEGACY |
| 68 if(min == max) { |
68 if(min == max) { |
| 69 max = min + 1; |
69 max = min + 1; |
| 70 } |
70 } |
| 71 #endif |
71 #endif |
| 72 GtkWidget *spin = gtk_spin_button_new_with_range(min, max, args.step); |
72 GtkWidget *spin = gtk_spin_button_new_with_range(min, max, args->step); |
| 73 ui_set_name_and_style(spin, args.name, args.style_class); |
73 ui_set_name_and_style(spin, args->name, args->style_class); |
| 74 ui_set_widget_groups(obj->ctx, spin, args.groups); |
74 ui_set_widget_groups(obj->ctx, spin, args->groups); |
| 75 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), args.digits); |
75 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), args->digits); |
| 76 UiObserver **obs = NULL; |
76 UiObserver **obs = NULL; |
| 77 if(var) { |
77 if(var) { |
| 78 double value = 0; |
78 double value = 0; |
| 79 switch(var->type) { |
79 switch(var->type) { |
| 80 default: break; |
80 default: break; |
| 127 spin, |
127 spin, |
| 128 "destroy", |
128 "destroy", |
| 129 G_CALLBACK(ui_destroy_vardata), |
129 G_CALLBACK(ui_destroy_vardata), |
| 130 event); |
130 event); |
| 131 |
131 |
| 132 UI_APPLY_LAYOUT1(current, args); |
132 UI_APPLY_LAYOUT2(current, args); |
| 133 current->container->add(current->container, spin, FALSE); |
133 current->container->add(current->container, spin); |
| 134 |
134 |
| 135 return spin; |
135 return spin; |
| 136 } |
136 } |
| 137 |
137 |
| 138 void ui_spinner_setrange(UIWIDGET spinner, double min, double max) { |
138 void ui_spinner_setrange(UIWIDGET spinner, double min, double max) { |
| 148 gdouble value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinner)); |
148 gdouble value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinner)); |
| 149 UiEvent e; |
149 UiEvent e; |
| 150 e.obj = event->obj; |
150 e.obj = event->obj; |
| 151 e.window = event->obj->window; |
151 e.window = event->obj->window; |
| 152 e.document = event->obj->ctx->document; |
152 e.document = event->obj->ctx->document; |
| 153 e.eventdata = &value; |
153 e.eventdata = NULL; |
| |
154 e.eventdatatype = 0; |
| 154 e.intval = (int64_t)value; |
155 e.intval = (int64_t)value; |
| 155 |
156 |
| 156 if(event->callback) { |
157 if(event->callback) { |
| 157 event->callback(&e, event->userdata); |
158 event->callback(&e, event->userdata); |
| 158 } |
159 } |