| 32 #include "container.h" |
32 #include "container.h" |
| 33 |
33 |
| 34 #include "list.h" |
34 #include "list.h" |
| 35 #include "../common/object.h" |
35 #include "../common/object.h" |
| 36 |
36 |
| |
37 static void* getvalue_wrapper(UiList *list, void *elm, int row, int col, void *userdata, UiBool *freeResult) { |
| |
38 ui_getvaluefunc getvalue = (ui_getvaluefunc)userdata; |
| |
39 return getvalue(elm, col); |
| |
40 } |
| |
41 |
| |
42 /* |
| |
43 static void* model_getvalue(UiModel *model, UiList *list, void *elm, int row, int col, UiBool *freeResult) { |
| |
44 if(model->getvalue2) { |
| |
45 return model->getvalue2(list, elm, row, col, model->getvalue2data, freeResult); |
| |
46 } else if(model->getvalue) { |
| |
47 return model->getvalue(elm, col); |
| |
48 } |
| |
49 return NULL; |
| |
50 } |
| |
51 */ |
| |
52 |
| 37 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs *args) { |
53 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs *args) { |
| 38 Arg xargs[16]; |
54 Arg xargs[16]; |
| 39 int n = 0; |
55 int n = 0; |
| 40 |
56 |
| 41 UiContainerPrivate *ctn = ui_obj_container(obj); |
57 UiContainerPrivate *ctn = ui_obj_container(obj); |
| 56 |
72 |
| 57 UiListView *listview = malloc(sizeof(UiListView)); |
73 UiListView *listview = malloc(sizeof(UiListView)); |
| 58 memset(listview, 0, sizeof(UiListView)); |
74 memset(listview, 0, sizeof(UiListView)); |
| 59 listview->obj = obj; |
75 listview->obj = obj; |
| 60 listview->widget = widget; |
76 listview->widget = widget; |
| 61 listview->getvalue = args->getvalue ? args->getvalue : ui_strmodel_getvalue; |
77 if(args->getvalue2) { |
| |
78 listview->getvalue = args->getvalue2; |
| |
79 listview->getvaluedata = args->getvalue2data; |
| |
80 } else if(args->getvalue) { |
| |
81 listview->getvalue = getvalue_wrapper; |
| |
82 listview->getvaluedata = args->getvalue; |
| |
83 } else { |
| |
84 listview->getvalue = getvalue_wrapper; |
| |
85 listview->getvaluedata = ui_strmodel_getvalue; |
| |
86 } |
| 62 listview->var = var; |
87 listview->var = var; |
| 63 listview->onactivate = args->onactivate; |
88 listview->onactivate = args->onactivate; |
| 64 listview->onactivatedata = args->onactivatedata; |
89 listview->onactivatedata = args->onactivatedata; |
| 65 listview->onselection = args->onselection; |
90 listview->onselection = args->onselection; |
| 66 listview->onselectiondata = args->onselectiondata; |
91 listview->onselectiondata = args->onselectiondata; |
| 137 if(listview->onselection) { |
162 if(listview->onselection) { |
| 138 list_callback(listview->obj, listview->current_selection, listview->onselection, listview->onselectiondata); |
163 list_callback(listview->obj, listview->current_selection, listview->onselection, listview->onselectiondata); |
| 139 } |
164 } |
| 140 } |
165 } |
| 141 |
166 |
| 142 static XmStringTable create_stringlist(UiList *list, ui_getvaluefunc getvalue, int *count) { |
167 static XmStringTable create_stringlist(UiList *list, ui_getvaluefunc2 getvalue, void *getvaluedata, int *count) { |
| 143 int num = list->count(list); |
168 int num = list->count(list); |
| 144 XmStringTable items = (XmStringTable)XtMalloc(num * sizeof(XmString)); |
169 XmStringTable items = (XmStringTable)XtMalloc(num * sizeof(XmString)); |
| 145 void *data = list->first(list); |
170 void *data = list->first(list); |
| 146 for(int i=0;i<num;i++) { |
171 for(int i=0;i<num;i++) { |
| 147 char *s = getvalue(data, 0); |
172 UiBool freevalue = FALSE; |
| |
173 char *s = getvalue(list, data, i, 0, getvaluedata, &freevalue); |
| 148 items[i] = XmStringCreateLocalized(s ? s : ""); |
174 items[i] = XmStringCreateLocalized(s ? s : ""); |
| |
175 if(freevalue) { |
| |
176 free(s); |
| |
177 } |
| 149 data = list->next(list); |
178 data = list->next(list); |
| 150 } |
179 } |
| 151 |
180 |
| 152 *count = num; |
181 *count = num; |
| 153 return items; |
182 return items; |
| 243 |
273 |
| 244 UiListView *listview = malloc(sizeof(UiListView)); |
274 UiListView *listview = malloc(sizeof(UiListView)); |
| 245 memset(listview, 0, sizeof(UiListView)); |
275 memset(listview, 0, sizeof(UiListView)); |
| 246 listview->obj = obj; |
276 listview->obj = obj; |
| 247 listview->widget = widget; |
277 listview->widget = widget; |
| 248 listview->getvalue = args->getvalue ? args->getvalue : ui_strmodel_getvalue; |
278 if(args->getvalue2) { |
| |
279 listview->getvalue = args->getvalue2; |
| |
280 listview->getvaluedata = args->getvalue2data; |
| |
281 } else if(args->getvalue) { |
| |
282 listview->getvalue = getvalue_wrapper; |
| |
283 listview->getvaluedata = args->getvalue; |
| |
284 } else { |
| |
285 listview->getvalue = getvalue_wrapper; |
| |
286 listview->getvaluedata = ui_strmodel_getvalue; |
| |
287 } |
| 249 listview->var = var; |
288 listview->var = var; |
| 250 listview->onactivate = args->onactivate; |
289 listview->onactivate = args->onactivate; |
| 251 listview->onactivatedata = args->onactivatedata; |
290 listview->onactivatedata = args->onactivatedata; |
| 252 listview->onselection = args->onselection; |
291 listview->onselection = args->onselection; |
| 253 listview->onselectiondata = args->onselectiondata; |
292 listview->onselectiondata = args->onselectiondata; |