ui/gtk/text.c

changeset 65
4697592e24ba
parent 59
eb6611be50c7
child 90
2019fdbaadfd
equal deleted inserted replaced
64:6ef2c7f73a30 65:4697592e24ba
443 } 443 }
444 mgr->event = 1; 444 mgr->event = 1;
445 mgr->cur = elm; 445 mgr->cur = elm;
446 } 446 }
447 } 447 }
448
449
450 UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
451 GtkWidget *textfield = gtk_entry_new();
452 UiContainer *ct = uic_get_current_container(obj);
453 ct->add(ct, textfield, FALSE);
454
455 if(value) {
456 if(value->value) {
457 gtk_entry_set_text(GTK_ENTRY(textfield), value->value);
458 g_free(value->value);
459 // TODO: free value
460 }
461
462 value->get = ui_textfield_get;
463 value->set = ui_textfield_set;
464 value->value = NULL;
465 value->obj = GTK_ENTRY(textfield);
466 }
467
468 return textfield;
469 }
470
471 UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
472 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING);
473 if(var) {
474 UiString *value = var->value;
475 return ui_textfield(obj, value);
476 } else {
477 // TODO: error
478 }
479 return NULL;
480 }
481
482 char* ui_textfield_get(UiString *str) {
483 if(str->value) {
484 g_free(str->value);
485 }
486 str->value = g_strdup(gtk_entry_get_text(str->obj));
487 return str->value;
488 }
489
490 void ui_textfield_set(UiString *str, char *value) {
491 if(str->value) {
492 g_free(str->value);
493 }
494 str->value = NULL;
495 gtk_entry_set_text(str->obj, value);
496 }

mercurial