ui/motif/text.c

changeset 63
46a42f0c4f93
parent 60
7cd1b8890302
child 90
2019fdbaadfd
equal deleted inserted replaced
62:70d2aee84432 63:46a42f0c4f93
42 XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); 42 XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT);
43 n++; 43 n++;
44 44
45 Widget parent = ct->prepare(ct, args, &n, TRUE); 45 Widget parent = ct->prepare(ct, args, &n, TRUE);
46 Widget text_area = XmCreateScrolledText(parent, "text_area", args, n); 46 Widget text_area = XmCreateScrolledText(parent, "text_area", args, n);
47 ct->add(ct, text_area); 47 ct->add(ct, XtParent(text_area));
48 XtManageChild(text_area); 48 XtManageChild(text_area);
49 49
50 UiTextArea *uitext = ucx_mempool_malloc( 50 UiTextArea *uitext = ucx_mempool_malloc(
51 obj->ctx->mempool, 51 obj->ctx->mempool,
52 sizeof(UiTextArea)); 52 sizeof(UiTextArea));
60 60
61 // bind value 61 // bind value
62 if(value) { 62 if(value) {
63 if(value->value) { 63 if(value->value) {
64 XmTextSetString(text_area, value->value); 64 XmTextSetString(text_area, value->value);
65 XtFree(value->value);
65 } 66 }
66 67
67 value->set = ui_textarea_set; 68 value->set = ui_textarea_set;
68 value->get = ui_textarea_get; 69 value->get = ui_textarea_get;
69 value->getsubstr = ui_textarea_getsubstr; 70 value->getsubstr = ui_textarea_getsubstr;
323 } 324 }
324 mgr->event = 1; 325 mgr->event = 1;
325 mgr->cur = elm; 326 mgr->cur = elm;
326 } 327 }
327 } 328 }
329
330
331 /* ------------------------- textfield ------------------------- */
332
333 UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
334 UiContainer *ct = uic_get_current_container(obj);
335 int n = 0;
336 Arg args[16];
337 XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT);
338 n++;
339
340 Widget parent = ct->prepare(ct, args, &n, FALSE);
341 Widget textfield = XmCreateText(parent, "text_field", args, n);
342 ct->add(ct, textfield);
343 XtManageChild(textfield);
344
345 // bind value
346 if(value) {
347 if(value->value) {
348 XmTextSetString(textfield, value->value);
349 XtFree(value->value);
350 }
351
352 value->set = ui_textfield_set;
353 value->get = ui_textfield_get;
354 value->value = NULL;
355 value->obj = textfield;
356 }
357
358 return textfield;
359 }
360
361 UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
362 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING);
363 if(var) {
364 UiString *value = var->value;
365 return ui_textfield(obj, value);
366 } else {
367 // TODO: error
368 }
369 return NULL;
370 }
371
372 char* ui_textfield_get(UiString *str) {
373 if(str->value) {
374 XtFree(str->value);
375 }
376 char *value = XmTextGetString(str->obj);
377 str->value = value;
378 return value;
379 }
380
381 void ui_textfield_set(UiString *str, char *value) {
382 if(str->value) {
383 XtFree(str->value);
384 }
385 str->value = NULL;
386 XmTextSetString(str->obj, value);
387 }
388

mercurial