532 mgr->cur = elm; |
532 mgr->cur = elm; |
533 } |
533 } |
534 } |
534 } |
535 |
535 |
536 |
536 |
537 static UIWIDGET create_textfield_var(UiObject *obj, int width, UiBool frameless, UiBool password, UiVar *var) { |
537 |
|
538 |
|
539 static UIWIDGET create_textfield(UiObject *obj, UiBool frameless, UiBool password, UiTextFieldArgs args) { |
538 GtkWidget *textfield = gtk_entry_new(); |
540 GtkWidget *textfield = gtk_entry_new(); |
|
541 |
|
542 UiObject* current = uic_current_obj(obj); |
|
543 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); |
539 |
544 |
540 UiTextField *uitext = malloc(sizeof(UiTextField)); |
545 UiTextField *uitext = malloc(sizeof(UiTextField)); |
541 uitext->ctx = obj->ctx; |
546 uitext->ctx = obj->ctx; |
542 uitext->var = var; |
547 uitext->var = var; |
543 |
548 |
545 textfield, |
550 textfield, |
546 "destroy", |
551 "destroy", |
547 G_CALLBACK(ui_textfield_destroy), |
552 G_CALLBACK(ui_textfield_destroy), |
548 uitext); |
553 uitext); |
549 |
554 |
550 if(width > 0) { |
555 if(args.width > 0) { |
551 gtk_entry_set_width_chars(GTK_ENTRY(textfield), width); |
556 gtk_entry_set_width_chars(GTK_ENTRY(textfield), args.width); |
552 } |
557 } |
553 if(frameless) { |
558 if(frameless) { |
554 // TODO: gtk2legacy workaroud |
559 // TODO: gtk2legacy workaroud |
555 gtk_entry_set_has_frame(GTK_ENTRY(textfield), FALSE); |
560 gtk_entry_set_has_frame(GTK_ENTRY(textfield), FALSE); |
556 } |
561 } |
584 } |
589 } |
585 |
590 |
586 return textfield; |
591 return textfield; |
587 } |
592 } |
588 |
593 |
589 static UIWIDGET create_textfield_nv(UiObject *obj, int width, UiBool frameless, UiBool password, char *varname) { |
594 UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs args) { |
590 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_STRING); |
595 return create_textfield(obj, FALSE, FALSE, args); |
591 if(var) { |
596 } |
592 return create_textfield_var(obj, width, frameless, password, var); |
597 |
593 } else { |
598 UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs args) { |
594 // TODO: error |
599 return create_textfield(obj, TRUE, FALSE, args); |
595 } |
600 } |
596 return NULL; |
601 |
597 } |
602 UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) { |
598 |
603 return create_textfield(obj, FALSE, TRUE, args); |
599 static UIWIDGET create_textfield(UiObject *obj, int width, UiBool frameless, UiBool password, UiString *value) { |
604 } |
600 UiVar *var = NULL; |
605 |
601 if(value) { |
|
602 var = malloc(sizeof(UiVar)); |
|
603 var->value = value; |
|
604 var->type = UI_VAR_SPECIAL; |
|
605 var->from = NULL; |
|
606 var->from_ctx = NULL; |
|
607 } |
|
608 return create_textfield_var(obj, width, frameless, password, var); |
|
609 } |
|
610 |
606 |
611 void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { |
607 void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { |
612 if(textfield->var) { |
|
613 UiText *text = textfield->var->value; |
|
614 if(text->undomgr) { |
|
615 ui_destroy_undomgr(text->undomgr); |
|
616 } |
|
617 ui_destroy_boundvar(textfield->ctx, textfield->var); |
|
618 } |
|
619 free(textfield); |
608 free(textfield); |
620 } |
609 } |
621 |
610 |
622 void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { |
611 void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { |
|
612 // changed event is only registered, if the textfield->var != NULL |
623 UiString *value = textfield->var->value; |
613 UiString *value = textfield->var->value; |
624 if(value->observers) { |
614 if(value->observers) { |
625 UiEvent e; |
615 UiEvent e; |
626 e.obj = textfield->ctx->obj; |
616 e.obj = textfield->ctx->obj; |
627 e.window = e.obj->window; |
617 e.window = e.obj->window; |
630 e.intval = 0; |
620 e.intval = 0; |
631 ui_notify_evt(value->observers, &e); |
621 ui_notify_evt(value->observers, &e); |
632 } |
622 } |
633 } |
623 } |
634 |
624 |
635 UIWIDGET ui_textfield_deprecated(UiObject *obj, UiString *value) { |
|
636 return create_textfield(obj, 0, FALSE, FALSE, value); |
|
637 } |
|
638 |
|
639 UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) { |
|
640 return create_textfield_nv(obj, 0, FALSE, FALSE, varname); |
|
641 } |
|
642 |
|
643 UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value) { |
|
644 return create_textfield(obj, width, FALSE, FALSE, value); |
|
645 } |
|
646 |
|
647 UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname) { |
|
648 return create_textfield_nv(obj, width, FALSE, FALSE, varname); |
|
649 } |
|
650 |
|
651 UIWIDGET ui_frameless_textfield_deprecated(UiObject *obj, UiString *value) { |
|
652 return create_textfield(obj, 0, TRUE, FALSE, value); |
|
653 } |
|
654 |
|
655 UIWIDGET ui_frameless_textfield_nv(UiObject *obj, char *varname) { |
|
656 return create_textfield_nv(obj, 0, TRUE, FALSE, varname); |
|
657 } |
|
658 |
|
659 UIWIDGET ui_passwordfield_deprecated(UiObject *obj, UiString *value) { |
|
660 return create_textfield(obj, 0, FALSE, TRUE, value); |
|
661 } |
|
662 |
|
663 UIWIDGET ui_passwordfield_nv(UiObject *obj, char *varname) { |
|
664 return create_textfield_nv(obj, 0, FALSE, TRUE, varname); |
|
665 } |
|
666 |
|
667 UIWIDGET ui_passwordfield_w(UiObject *obj, int width, UiString *value) { |
|
668 return create_textfield(obj, width, FALSE, TRUE, value); |
|
669 } |
|
670 |
|
671 UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname) { |
|
672 return create_textfield_nv(obj, width, FALSE, TRUE, varname); |
|
673 } |
|
674 |
625 |
675 char* ui_textfield_get(UiString *str) { |
626 char* ui_textfield_get(UiString *str) { |
676 if(str->value.ptr) { |
627 if(str->value.ptr) { |
677 str->value.free(str->value.ptr); |
628 str->value.free(str->value.ptr); |
678 } |
629 } |