# HG changeset patch # User Olaf Wintermann # Date 1730220726 -3600 # Node ID 8c028965410aa5ec50a01f0d5e84911af0a4a60c # Parent 822fcb83bdf1ce94b531c79b0585fddf1db163af implement textfield onchange event (GTK) diff -r 822fcb83bdf1 -r 8c028965410a ui/gtk/text.c --- a/ui/gtk/text.c Tue Oct 29 11:52:01 2024 +0100 +++ b/ui/gtk/text.c Tue Oct 29 17:52:06 2024 +0100 @@ -536,8 +536,10 @@ UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); UiTextField *uitext = malloc(sizeof(UiTextField)); - uitext->ctx = obj->ctx; + uitext->obj = obj; uitext->var = var; + uitext->onchange = args.onchange; + uitext->onchangedata = args.onchangedata; g_signal_connect( textfield, @@ -576,7 +578,9 @@ value->value.ptr = NULL; value->value.free = NULL; value->obj = GTK_ENTRY(textfield); - + } + + if(args.onchange || var) { g_signal_connect( textfield, "changed", @@ -605,15 +609,20 @@ } void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { - // changed event is only registered, if the textfield->var != NULL UiString *value = textfield->var->value; - if(value->observers) { - UiEvent e; - e.obj = textfield->ctx->obj; - e.window = e.obj->window; - e.document = textfield->ctx->document; - e.eventdata = value; - e.intval = 0; + + UiEvent e; + e.obj = textfield->obj; + e.window = e.obj->window; + e.document = textfield->obj->ctx->document; + e.eventdata = value; + e.intval = 0; + + if(textfield->onchange) { + textfield->onchange(&e, textfield->onchangedata); + } + + if(textfield->var) { ui_notify_evt(value->observers, &e); } } diff -r 822fcb83bdf1 -r 8c028965410a ui/gtk/text.h --- a/ui/gtk/text.h Tue Oct 29 11:52:01 2024 +0100 +++ b/ui/gtk/text.h Tue Oct 29 17:52:06 2024 +0100 @@ -67,9 +67,10 @@ } UiTextArea; typedef struct UiTextField { - UiContext *ctx; - UiVar *var; - // TODO: validatefunc + UiObject *obj; + UiVar *var; + ui_callback onchange; + void *onchangedata; } UiTextField; typedef struct UiPathTextField { diff -r 822fcb83bdf1 -r 8c028965410a ui/gtk/window.c --- a/ui/gtk/window.c Tue Oct 29 11:52:01 2024 +0100 +++ b/ui/gtk/window.c Tue Oct 29 17:52:06 2024 +0100 @@ -659,13 +659,21 @@ #define DEFAULT_BUTTON(window, button) gtk_window_set_default_widget(GTK_WINDOW(window), button) #else #define HEADERBAR_SHOW_CLOSEBUTTON(headerbar, set) gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(headerbar), set) -#define DEFAULT_BUTTON(window, button) gtk_window_set_default(GTK_WINDOW(window), button) +#define DEFAULT_BUTTON(window, button) gtk_widget_set_can_default(button, TRUE); gtk_window_set_default(GTK_WINDOW(window), button) #endif UiObject* ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs args) { GtkWidget *dialog = DIALOG_NEW(); + if(args.width > 0 || args.height > 0) { + gtk_window_set_default_size( + GTK_WINDOW(dialog), + args.width, + args.height); + } + + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent->widget)); if(args.modal != UI_OFF) { gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);