# HG changeset patch # User Olaf Wintermann # Date 1453835176 -3600 # Node ID 38c53b8a61392200d1ce77baf1a5d9beec990f30 # Parent 480354705c2f9fdc02cacdc1c4164a2854334e09 added combobox (Motif) diff -r 480354705c2f -r 38c53b8a6139 application/main.c --- a/application/main.c Tue Jan 26 19:45:28 2016 +0100 +++ b/application/main.c Tue Jan 26 20:06:16 2016 +0100 @@ -135,19 +135,23 @@ */ ///* - ui_vbox_sp(obj, 8, 4); + ui_vbox_sp(obj, 0, 0); UiList *list = ui_list_new(); ui_list_append(list, "Hello"); ui_list_append(list, "World"); ui_list_append(list, "Test"); - ui_combobox_str(obj, list, NULL, NULL); - ui_button(obj, "Button", NULL, NULL); - ui_button(obj, "Button", NULL, NULL); + ui_layout_fill(obj, FALSE); + ui_hbox(obj); + ui_combobox_str(obj, list, NULL, NULL); + ui_end(obj); ui_button(obj, "Button", NULL, NULL); - ui_button(obj, "Button", NULL, NULL); + //ui_button(obj, "Button", NULL, NULL); + //ui_button(obj, "Button", NULL, NULL); + //ui_button(obj, "Button", NULL, NULL); + //ui_button(obj, "Button", NULL, NULL); ui_end(obj); //*/ diff -r 480354705c2f -r 38c53b8a6139 ui/motif/list.c --- a/ui/motif/list.c Tue Jan 26 19:45:28 2016 +0100 +++ b/ui/motif/list.c Tue Jan 26 20:06:16 2016 +0100 @@ -160,3 +160,57 @@ e.intval = cbs->item_position - 1; event->event.callback(&e, event->event.userdata); } + + +/* --------------------------- ComboBox --------------------------- */ + +UIWIDGET ui_combobox_str(UiObject *obj, UiList *list, ui_callback f, void *udata) { + return ui_combobox(obj, list, ui_strmodel_getvalue, f, udata); +} + +UIWIDGET ui_combobox(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { + UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr)); + listptr->list = list; + return ui_combobox_var(obj, listptr, getvalue, f, udata); +} + +UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { + UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST); + if(var) { + UiListVar *value = var->value; + return ui_combobox_var(obj, value->listptr, getvalue, f, udata); + } else { + // TODO: error + } + return NULL; +} + +UIWIDGET ui_combobox_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { + UiListView *listview = ucx_mempool_malloc( + obj->ctx->mempool, + sizeof(UiListView)); + + UiContainer *ct = uic_get_current_container(obj); + Arg args[16]; + int n = 0; + XtSetArg(args[n], XmNindicatorOn, XmINDICATOR_NONE); + n++; + XtSetArg(args[n], XmNtraversalOn, FALSE); + n++; + XtSetArg(args[n], XmNwidth, 160); + n++; + Widget parent = ct->prepare(ct, args, &n, FALSE); + Widget combobox = XmCreateDropDownList(parent, "combobox", args, n); + XtManageChild(combobox); + listview->widget = combobox; + listview->list = list; + listview->getvalue = getvalue; + + ui_listview_update(NULL, listview); + + list->list->observers = ui_add_observer( + list->list->observers, + (ui_callback)ui_listview_update, + listview); + +} \ No newline at end of file diff -r 480354705c2f -r 38c53b8a6139 ui/motif/list.h --- a/ui/motif/list.h Tue Jan 26 19:45:28 2016 +0100 +++ b/ui/motif/list.h Tue Jan 26 20:06:16 2016 +0100 @@ -54,6 +54,8 @@ void ui_listview_update(UiEvent *event, UiListView *view); void ui_list_selection_callback (Widget widget, UiListViewEventData *event, XtPointer data); +UIWIDGET ui_combobox_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata); + #ifdef __cplusplus } #endif diff -r 480354705c2f -r 38c53b8a6139 ui/motif/toolbar.c --- a/ui/motif/toolbar.c Tue Jan 26 19:45:28 2016 +0100 +++ b/ui/motif/toolbar.c Tue Jan 26 20:06:16 2016 +0100 @@ -180,7 +180,7 @@ void *udata) { UiToolbarComboBoxNV *cb = malloc(sizeof(UiToolbarComboBoxNV)); - cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox; + cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox_nv; cb->listname = listname; cb->getvalue = getvalue; cb->callback = f;