ui/motif/list.c

changeset 462
9e499276136a
parent 427
7ead63398a50
equal deleted inserted replaced
461:b480e133b576 462:9e499276136a
194 } 194 }
195 195
196 void* ui_strmodel_getvalue(void *elm, int column) { 196 void* ui_strmodel_getvalue(void *elm, int column) {
197 return column == 0 ? elm : NULL; 197 return column == 0 ? elm : NULL;
198 } 198 }
199
200 /* ------------------------------- Drop Down ------------------------------- */
201
202 static void ui_dropdown_selection(
203 Widget w,
204 UiListView *listview,
205 XmComboBoxCallbackStruct *cb)
206 {
207 UiListSelection sel = { 0, NULL };
208 if(cb->item_position > 0) {
209 sel.count = 1;
210 sel.rows = malloc(sizeof(int));
211 sel.rows[0] = cb->item_position-1;
212 }
213 UiEvent event;
214 event.obj = listview->obj;
215 event.window = event.obj->window;
216 event.document = event.obj->ctx->document;
217 event.eventdata = &sel;
218 event.intval = 0;
219 if(listview->onactivate) {
220 listview->onactivate(&event, listview->onactivatedata);
221 }
222 if(listview->onselection) {
223 listview->onselection(&event, listview->onselectiondata);
224 }
225 }
226
227 UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs args) {
228 Arg xargs[16];
229 int n = 0;
230
231 UiContainerPrivate *ctn = ui_obj_container(obj);
232 UI_APPLY_LAYOUT(ctn->layout, args);
233
234 char *name = args.name ? (char*)args.name : "dropdown";
235 Widget parent = ctn->prepare(ctn, xargs, &n);
236 Widget widget = XmCreateDropDownList(parent, name, xargs, n);
237 XtManageChild(widget);
238
239 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.list, args.varname, UI_VAR_LIST);
240
241 UiListView *listview = malloc(sizeof(UiListView));
242 memset(listview, 0, sizeof(UiListView));
243 listview->obj = obj;
244 listview->widget = widget;
245 listview->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue;
246 listview->var = var;
247 listview->onactivate = args.onactivate;
248 listview->onactivatedata = args.onactivatedata;
249 listview->onselection = args.onselection;
250 listview->onselectiondata = args.onselectiondata;
251
252 if(var) {
253 UiList *list = var->value;
254 list->obj = listview;
255 list->update = ui_listview_update;
256 list->getselection = ui_listview_getselection;
257 list->setselection = ui_listview_setselection;
258 ui_listview_update(list, 0);
259 }
260
261 XtAddCallback(
262 widget,
263 XmNdestroyCallback,
264 (XtCallbackProc)ui_listview_destroy,
265 listview);
266 XtAddCallback(
267 widget,
268 XmNselectionCallback,
269 (XtCallbackProc)ui_dropdown_selection,
270 listview);
271
272 return widget;
273 }

mercurial