ui/motif/button.c

branch
newapi
changeset 176
bc63cb601f6d
parent 157
0b33b9396851
equal deleted inserted replaced
175:2cb06c231057 176:bc63cb601f6d
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include "button.h" 32 #include "button.h"
33 #include "container.h" 33 #include "container.h"
34 #include "../common/context.h" 34 #include "../common/context.h"
35 #include <ucx/mempool.h> 35 #include <cx/mempool.h>
36
37 #include <cx/linked_list.h>
38 #include <cx/array_list.h>
39 #include <cx/compare.h>
36 40
37 41
38 UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data) { 42 UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data) {
39 UiContainer *ct = uic_get_current_container(obj); 43 UiContainer *ct = uic_get_current_container(obj);
40 XmString str = XmStringCreateLocalized(label); 44 XmString str = XmStringCreateLocalized(label);
48 Widget parent = ct->prepare(ct, args, &n, FALSE); 52 Widget parent = ct->prepare(ct, args, &n, FALSE);
49 Widget button = XmCreatePushButton(parent, "button", args, n); 53 Widget button = XmCreatePushButton(parent, "button", args, n);
50 ct->add(ct, button); 54 ct->add(ct, button);
51 55
52 if(f) { 56 if(f) {
53 UiEventData *event = ucx_mempool_malloc( 57 UiEventData *event = cxMalloc(
54 obj->ctx->mempool, 58 obj->ctx->allocator,
55 sizeof(UiEventData)); 59 sizeof(UiEventData));
56 event->obj = obj; 60 event->obj = obj;
57 event->userdata = data; 61 event->userdata = data;
58 event->callback = f; 62 event->callback = f;
59 event->value = 0; 63 event->value = 0;
141 145
142 if(rgroup) { 146 if(rgroup) {
143 RadioButtonGroup *group; 147 RadioButtonGroup *group;
144 if(rgroup->obj) { 148 if(rgroup->obj) {
145 group = rgroup->obj; 149 group = rgroup->obj;
146 group->buttons = ucx_list_append(group->buttons, button); 150 if(!group->buttons) {
151 group->buttons = cxArrayListCreate(cxDefaultAllocator, cx_cmp_uintptr, CX_STORE_POINTERS, 8);
152 }
153 cxListAdd(group->buttons, button);
147 group->ref++; 154 group->ref++;
148 } else { 155 } else {
149 group = malloc(sizeof(RadioButtonGroup)); 156 group = malloc(sizeof(RadioButtonGroup));
150 group->buttons = ucx_list_append(NULL, button); 157 group->buttons = cxArrayListCreate(cxDefaultAllocator, cx_cmp_uintptr, CX_STORE_POINTERS, 8);
158 cxListAdd(group->buttons, button);
151 group->current = button; 159 group->current = button;
152 // this is the first button in the radiobutton group 160 // this is the first button in the radiobutton group
153 // so we should enable it 161 // so we should enable it
154 Arg arg; 162 Arg arg;
155 XtSetArg(arg, XmNset, TRUE); 163 XtSetArg(arg, XmNset, TRUE);
179 } 187 }
180 188
181 int64_t ui_radiobutton_get(UiInteger *value) { 189 int64_t ui_radiobutton_get(UiInteger *value) {
182 RadioButtonGroup *group = value->obj; 190 RadioButtonGroup *group = value->obj;
183 191
184 int i = ucx_list_find(group->buttons, group->current, NULL, NULL); 192 int i = cxListFind(group->buttons, group->current);
185 if (i >= 0) { 193 if (i >= 0) {
186 value->value = i; 194 value->value = i;
187 return i; 195 return i;
188 } else { 196 } else {
189 return 0; 197 return 0;
195 Arg arg; 203 Arg arg;
196 204
197 XtSetArg(arg, XmNset, FALSE); 205 XtSetArg(arg, XmNset, FALSE);
198 XtSetValues(group->current, &arg, 1); 206 XtSetValues(group->current, &arg, 1);
199 207
200 UcxList *elm = ucx_list_get(group->buttons, i); 208 Widget button = cxListAt(group->buttons, i);
201 if(elm) { 209 if(button) {
202 Widget button = elm->data;
203 XtSetArg(arg, XmNset, TRUE); 210 XtSetArg(arg, XmNset, TRUE);
204 XtSetValues(button, &arg, 1); 211 XtSetValues(button, &arg, 1);
205 group->current = button; 212 group->current = button;
206 } 213 }
207 } 214 }

mercurial