96 |
96 |
97 // create toolkit wrapper object and register destructor |
97 // create toolkit wrapper object and register destructor |
98 UIElement elm = button; |
98 UIElement elm = button; |
99 UiWidget* widget = new UiWidget(elm); |
99 UiWidget* widget = new UiWidget(elm); |
100 ui_context_add_widget_destructor(current->ctx, widget); |
100 ui_context_add_widget_destructor(current->ctx, widget); |
|
101 ui_set_widget_groups(current->ctx, widget, args.groups); |
101 |
102 |
102 // register callback |
103 // register callback |
103 if (args.onclick) { |
104 if (args.onclick) { |
104 ui_callback cbfunc = args.onclick; |
105 ui_callback cbfunc = args.onclick; |
105 void* cbdata = args.onclickdata; |
106 void* cbdata = args.onclickdata; |
173 callback(&evt, cbdata); |
174 callback(&evt, cbdata); |
174 }); |
175 }); |
175 } |
176 } |
176 } |
177 } |
177 |
178 |
|
179 static void togglebutton_changed(UiObject *obj, bool checked, ui_callback onchange, void *onchangedata, int enable_state) { |
|
180 if (onchange) { |
|
181 UiEvent evt; |
|
182 evt.obj = obj; |
|
183 evt.window = obj->window; |
|
184 evt.document = obj->ctx->document; |
|
185 evt.eventdata = nullptr; |
|
186 evt.intval = checked; |
|
187 onchange(&evt, onchangedata); |
|
188 } |
|
189 if (enable_state > 0) { |
|
190 if (checked) { |
|
191 ui_set_group(obj->ctx, enable_state); |
|
192 } else { |
|
193 ui_unset_group(obj->ctx, enable_state); |
|
194 } |
|
195 } |
|
196 } |
178 |
197 |
179 static UIWIDGET create_togglebutton(UiObject *obj, ToggleButton button, UiToggleArgs args) { |
198 static UIWIDGET create_togglebutton(UiObject *obj, ToggleButton button, UiToggleArgs args) { |
180 UiObject* current = uic_current_obj(obj); |
199 UiObject* current = uic_current_obj(obj); |
181 |
200 |
182 // set label |
201 // set label |
185 |
204 |
186 // create toolkit wrapper object and register destructor |
205 // create toolkit wrapper object and register destructor |
187 UIElement elm = button; |
206 UIElement elm = button; |
188 UiWidget* widget = new UiWidget(elm); |
207 UiWidget* widget = new UiWidget(elm); |
189 ui_context_add_widget_destructor(current->ctx, widget); |
208 ui_context_add_widget_destructor(current->ctx, widget); |
|
209 ui_set_widget_groups(current->ctx, widget, args.groups); |
190 |
210 |
191 // bind variable |
211 // bind variable |
192 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); |
212 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); |
193 if (var) { |
213 if (var) { |
194 UiInteger* value = (UiInteger*)var->value; |
214 UiInteger* value = (UiInteger*)var->value; |
199 // listener for notifying observers |
219 // listener for notifying observers |
200 togglebutton_register_checked_observers(button, obj, var); |
220 togglebutton_register_checked_observers(button, obj, var); |
201 togglebutton_register_unchecked_observers(button, obj, var); |
221 togglebutton_register_unchecked_observers(button, obj, var); |
202 } |
222 } |
203 |
223 |
|
224 if (args.enable_group > 0 || args.onchange) { |
|
225 button.Checked([obj, args](IInspectable const& sender, RoutedEventArgs) { |
|
226 togglebutton_changed(obj, true, args.onchange, args.onchangedata, args.enable_group); |
|
227 }); |
|
228 button.Unchecked([obj, args](IInspectable const& sender, RoutedEventArgs) { |
|
229 togglebutton_changed(obj, false, args.onchange, args.onchangedata, args.enable_group); |
|
230 }); |
|
231 } |
|
232 |
204 // add button to current container |
233 // add button to current container |
205 UI_APPLY_LAYOUT1(current, args); |
234 UI_APPLY_LAYOUT1(current, args); |
206 |
235 |
207 current->container->Add(button, false); |
236 current->container->Add(button, false); |
208 |
237 |
232 |
261 |
233 // create toolkit wrapper object and register destructor |
262 // create toolkit wrapper object and register destructor |
234 UIElement elm = button; |
263 UIElement elm = button; |
235 UiWidget* widget = new UiWidget(elm); |
264 UiWidget* widget = new UiWidget(elm); |
236 ui_context_add_widget_destructor(current->ctx, widget); |
265 ui_context_add_widget_destructor(current->ctx, widget); |
|
266 ui_set_widget_groups(current->ctx, widget, args.groups); |
237 |
267 |
238 // bind variable |
268 // bind variable |
239 UiVar* var = nullptr; |
269 UiVar* var = nullptr; |
240 if (args.value) { |
270 if (args.value) { |
241 var = uic_create_value_var(current->ctx, args.value); |
271 var = uic_create_value_var(current->ctx, args.value); |
272 |
302 |
273 // create toolkit wrapper object and register destructor |
303 // create toolkit wrapper object and register destructor |
274 UIElement elm = button; |
304 UIElement elm = button; |
275 UiWidget* widget = new UiWidget(elm); |
305 UiWidget* widget = new UiWidget(elm); |
276 ui_context_add_widget_destructor(current->ctx, widget); |
306 ui_context_add_widget_destructor(current->ctx, widget); |
|
307 ui_set_widget_groups(current->ctx, widget, args.groups); |
277 |
308 |
278 UiVar* var = nullptr; |
309 UiVar* var = nullptr; |
279 if (args.value) { |
310 if (args.value) { |
280 var = uic_create_value_var(current->ctx, args.value); |
311 var = uic_create_value_var(current->ctx, args.value); |
281 } |
312 } |