diff -r 70d2aee84432 -r 46a42f0c4f93 ui/motif/text.c --- a/ui/motif/text.c Sun Jan 04 22:12:07 2015 +0100 +++ b/ui/motif/text.c Mon Jan 05 11:49:46 2015 +0100 @@ -44,7 +44,7 @@ Widget parent = ct->prepare(ct, args, &n, TRUE); Widget text_area = XmCreateScrolledText(parent, "text_area", args, n); - ct->add(ct, text_area); + ct->add(ct, XtParent(text_area)); XtManageChild(text_area); UiTextArea *uitext = ucx_mempool_malloc( @@ -62,6 +62,7 @@ if(value) { if(value->value) { XmTextSetString(text_area, value->value); + XtFree(value->value); } value->set = ui_textarea_set; @@ -325,3 +326,63 @@ mgr->cur = elm; } } + + +/* ------------------------- textfield ------------------------- */ + +UIWIDGET ui_textfield(UiObject *obj, UiString *value) { + UiContainer *ct = uic_get_current_container(obj); + int n = 0; + Arg args[16]; + XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT); + n++; + + Widget parent = ct->prepare(ct, args, &n, FALSE); + Widget textfield = XmCreateText(parent, "text_field", args, n); + ct->add(ct, textfield); + XtManageChild(textfield); + + // bind value + if(value) { + if(value->value) { + XmTextSetString(textfield, value->value); + XtFree(value->value); + } + + value->set = ui_textfield_set; + value->get = ui_textfield_get; + value->value = NULL; + value->obj = textfield; + } + + return textfield; +} + +UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) { + UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING); + if(var) { + UiString *value = var->value; + return ui_textfield(obj, value); + } else { + // TODO: error + } + return NULL; +} + +char* ui_textfield_get(UiString *str) { + if(str->value) { + XtFree(str->value); + } + char *value = XmTextGetString(str->obj); + str->value = value; + return value; +} + +void ui_textfield_set(UiString *str, char *value) { + if(str->value) { + XtFree(str->value); + } + str->value = NULL; + XmTextSetString(str->obj, value); +} +