33 #include "container.h" |
33 #include "container.h" |
34 #include <cx/allocator.h> |
34 #include <cx/allocator.h> |
35 #include "../common/context.h" |
35 #include "../common/context.h" |
36 #include "../common/object.h" |
36 #include "../common/object.h" |
37 |
37 |
38 UIWIDGET ui_button_deprecated(UiObject *obj, char *label, ui_callback f, void *data) { |
38 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) { |
39 GtkWidget *button = gtk_button_new_with_label(label); |
39 UiObject* current = uic_current_obj(obj); |
40 |
40 GtkWidget *button = gtk_button_new_with_label(args.label); |
41 if(f) { |
41 |
|
42 if(args.onclick) { |
42 UiEventData *event = malloc(sizeof(UiEventData)); |
43 UiEventData *event = malloc(sizeof(UiEventData)); |
43 event->obj = obj; |
44 event->obj = obj; |
44 event->userdata = data; |
45 event->userdata = args.onclickdata; |
45 event->callback = f; |
46 event->callback = args.onclick; |
46 event->value = 0; |
47 event->value = 0; |
47 |
48 |
48 g_signal_connect( |
49 g_signal_connect( |
49 button, |
50 button, |
50 "clicked", |
51 "clicked", |
96 |
97 |
97 UiInteger *i = event->var->value; |
98 UiInteger *i = event->var->value; |
98 ui_notify_evt(i->observers, &e); |
99 ui_notify_evt(i->observers, &e); |
99 } |
100 } |
100 |
101 |
101 UIWIDGET ui_checkbox_var(UiObject *obj, char *label, UiVar *var) { |
102 static UIWIDGET togglebutton_create(UiObject *obj, GtkWidget *widget, UiToggleArgs args) { |
102 GtkWidget *button = gtk_check_button_new_with_label(label); |
103 UiObject* current = uic_current_obj(obj); |
103 |
104 |
104 // bind value |
105 if(args.label) { |
105 if(var) { |
106 gtk_button_set_label(GTK_BUTTON(widget), args.label); |
106 UiInteger *value = var->value; |
107 } |
107 value->obj = GTK_TOGGLE_BUTTON(button); |
108 |
|
109 UiVar* var = NULL; |
|
110 if (args.value) { |
|
111 var = uic_create_value_var(current->ctx, args.value); |
|
112 } |
|
113 else if (args.varname) { |
|
114 var = uic_create_var(obj->ctx, args.varname, UI_VAR_INTEGER); |
|
115 } |
|
116 if (var) { |
|
117 UiInteger* value = (UiInteger*)var->value; |
|
118 value->obj = widget; |
108 value->get = ui_toggle_button_get; |
119 value->get = ui_toggle_button_get; |
109 value->set = ui_toggle_button_set; |
120 value->set = ui_toggle_button_set; |
110 gtk_toggle_button_set_active(value->obj, value->value); |
|
111 |
121 |
112 UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
122 UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
113 event->obj = obj; |
123 event->obj = obj; |
114 event->var = var; |
124 event->var = var; |
115 event->observers = NULL; |
125 event->observers = NULL; |
116 |
126 |
117 g_signal_connect( |
127 g_signal_connect( |
118 button, |
128 widget, |
119 "clicked", |
129 "clicked", |
120 G_CALLBACK(ui_toggled_obs), |
130 G_CALLBACK(ui_toggled_obs), |
121 event); |
131 event); |
122 g_signal_connect( |
132 g_signal_connect( |
123 button, |
133 widget, |
124 "destroy", |
134 "destroy", |
125 G_CALLBACK(ui_destroy_vardata), |
135 G_CALLBACK(ui_destroy_vardata), |
126 event); |
136 event); |
127 } |
137 } |
128 |
138 |
129 UiContainer *ct = uic_get_current_container(obj); |
139 UI_APPLY_LAYOUT1(current, args); |
130 ct->add(ct, button, FALSE); |
140 current->container->add(current->container, widget, FALSE); |
131 |
141 |
132 return button; |
142 return widget; |
133 } |
143 } |
134 |
144 |
135 UIWIDGET ui_checkbox_deprecated(UiObject *obj, char *label, UiInteger *value) { |
145 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { |
136 UiVar *var = NULL; |
146 return togglebutton_create(obj, gtk_toggle_button_new(), args); |
137 if(value) { |
147 } |
138 var = malloc(sizeof(UiVar)); |
148 |
139 var->value = value; |
149 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
140 var->type = UI_VAR_SPECIAL; |
150 return togglebutton_create(obj, gtk_check_button_new(), args); |
141 } |
151 } |
142 return ui_checkbox_var(obj, label, var); |
152 |
143 } |
153 UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs args) { |
144 |
154 #ifdef UI_GTK3 |
145 UIWIDGET ui_checkbox_nv(UiObject *obj, char *label, char *varname) { |
155 return NULL; // TODO |
146 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_INTEGER); |
156 #else |
147 return ui_checkbox_var(obj, label, var); |
157 return ui_checkbox_create(obj, args); |
148 } |
158 #endif |
|
159 } |
|
160 |
|
161 |
|
162 |
|
163 |
149 |
164 |
150 |
165 |
151 UIWIDGET ui_radiobutton_var(UiObject *obj, char *label, UiVar *var) { |
166 UIWIDGET ui_radiobutton_var(UiObject *obj, char *label, UiVar *var) { |
152 GSList *rg = NULL; |
167 GSList *rg = NULL; |
153 UiInteger *rgroup; |
168 UiInteger *rgroup; |