ui/motif/text.c

changeset 122
e82b01d17a78
parent 90
2019fdbaadfd
child 131
774b741984a2
equal deleted inserted replaced
121:1cc365c34125 122:e82b01d17a78
334 } 334 }
335 335
336 336
337 /* ------------------------- textfield ------------------------- */ 337 /* ------------------------- textfield ------------------------- */
338 338
339 UIWIDGET ui_textfield(UiObject *obj, UiString *value) { 339 static UIWIDGET create_textfield(UiObject *obj, int width, UiBool frameless, UiBool password, UiString *value) {
340 UiContainer *ct = uic_get_current_container(obj); 340 UiContainer *ct = uic_get_current_container(obj);
341 int n = 0; 341 int n = 0;
342 Arg args[16]; 342 Arg args[16];
343 XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT); 343 XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT);
344 n++; 344 n++;
345 if(width > 0) {
346 XtSetArg(args[n], XmNcolumns, width / 2 + 1);
347 n++;
348 }
349 if(frameless) {
350 XtSetArg(args[n], XmNshadowThickness, 0);
351 n++;
352 }
353 if(password) {
354 // TODO
355 }
345 356
346 Widget parent = ct->prepare(ct, args, &n, FALSE); 357 Widget parent = ct->prepare(ct, args, &n, FALSE);
347 Widget textfield = XmCreateText(parent, "text_field", args, n); 358 Widget textfield = XmCreateText(parent, "text_field", args, n);
348 ct->add(ct, textfield); 359 ct->add(ct, textfield);
349 XtManageChild(textfield); 360 XtManageChild(textfield);
362 } 373 }
363 374
364 return textfield; 375 return textfield;
365 } 376 }
366 377
367 UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) { 378 static UIWIDGET create_textfield_nv(UiObject *obj, int width, UiBool frameless, UiBool password, char *varname) {
368 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING); 379 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING);
369 if(var) { 380 if(var) {
370 UiString *value = var->value; 381 UiString *value = var->value;
371 return ui_textfield(obj, value); 382 return ui_textfield(obj, value);
372 } else { 383 } else {
373 // TODO: error 384 // TODO: error
374 } 385 }
375 return NULL; 386 return NULL;
376 } 387 }
377 388
389 UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
390 return create_textfield(obj, 0, FALSE, FALSE, value);
391 }
392
393 UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
394 return create_textfield_nv(obj, 0, FALSE, FALSE, varname);
395 }
396
397 UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value) {
398 return create_textfield(obj, width, FALSE, FALSE, value);
399 }
400
401 UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname) {
402 return create_textfield_nv(obj, width, FALSE, FALSE, varname);
403 }
404
405 UIWIDGET ui_frameless_textfield(UiObject *obj, UiString *value) {
406 return create_textfield(obj, 0, TRUE, FALSE, value);
407 }
408
409 UIWIDGET ui_frameless_textfield_nv(UiObject *obj, char *varname) {
410 return create_textfield_nv(obj, 0, TRUE, FALSE, varname);
411 }
412
413 UIWIDGET ui_passwordfield(UiObject *obj, UiString *value) {
414 return create_textfield(obj, 0, FALSE, TRUE, value);
415 }
416
417 UIWIDGET ui_passwordfield_nv(UiObject *obj, char *varname) {
418 return create_textfield_nv(obj, 0, FALSE, TRUE, varname);
419 }
420
421 UIWIDGET ui_passwordfield_w(UiObject *obj, int width, UiString *value) {
422 return create_textfield(obj, width, FALSE, TRUE, value);
423 }
424
425 UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname) {
426 return create_textfield_nv(obj, width, FALSE, TRUE, varname);
427 }
428
429
378 char* ui_textfield_get(UiString *str) { 430 char* ui_textfield_get(UiString *str) {
379 if(str->value) { 431 if(str->value) {
380 XtFree(str->value); 432 XtFree(str->value);
381 } 433 }
382 char *value = XmTextGetString(str->obj); 434 char *value = XmTextGetString(str->obj);

mercurial