# HG changeset patch # User Olaf Wintermann # Date 1732993989 -3600 # Node ID 96a055be7f0b24e07f44d77f1acdb073ba1119b4 # Parent 55fb6bad549d84b412bec1e8cd61b5eac2d6e509 add textfield onactivate event (GTK) diff -r 55fb6bad549d -r 96a055be7f0b application/main.c --- a/application/main.c Fri Nov 29 22:02:38 2024 +0100 +++ b/application/main.c Sat Nov 30 20:13:09 2024 +0100 @@ -113,13 +113,18 @@ ui_close(event->obj); } +void action_dialog_onactivate(UiEvent *event, void *userdata) { + printf("textfield activate\n"); + ui_close(event->obj); +} + void action_toolbar_dialog(UiEvent *event, void *userdata) { UiObject *dialog = ui_dialog_window(event->obj, .title = "Dialog Window", .lbutton1 = "Cancel 1", .lbutton2 = "Btn2", .rbutton3 = "Btn3", .rbutton4 = "Login 4", .onclick = action_dialog_button, .default_button = 4, .show_closebutton = UI_OFF); ui_vbox(dialog, .margin = 10, .spacing = 10) { ui_label(dialog, .label = "Enter password:"); - ui_passwordfield(dialog, .varname = "password"); + ui_passwordfield(dialog, .varname = "password", .onactivate = action_dialog_onactivate); } ui_show(dialog); diff -r 55fb6bad549d -r 96a055be7f0b ui/gtk/text.c --- a/ui/gtk/text.c Fri Nov 29 22:02:38 2024 +0100 +++ b/ui/gtk/text.c Sat Nov 30 20:13:09 2024 +0100 @@ -551,6 +551,8 @@ uitext->var = var; uitext->onchange = args.onchange; uitext->onchangedata = args.onchangedata; + uitext->onactivate = args.onactivate; + uitext->onactivatedata = args.onactivatedata; g_signal_connect( textfield, @@ -599,6 +601,14 @@ uitext); } + if(args.onactivate) { + g_signal_connect( + textfield, + "activate", + G_CALLBACK(ui_textfield_activate), + uitext); + } + return textfield; } @@ -638,6 +648,17 @@ } } +void ui_textfield_activate(GtkEntry* self, UiTextField *textfield) { + if(textfield->onactivate) { + UiEvent e; + e.obj = textfield->obj; + e.window = e.obj->window; + e.document = textfield->obj->ctx->document; + e.eventdata = NULL; + e.intval = 0; + textfield->onactivate(&e, textfield->onactivatedata); + } +} char* ui_textfield_get(UiString *str) { if(str->value.ptr) { diff -r 55fb6bad549d -r 96a055be7f0b ui/gtk/text.h --- a/ui/gtk/text.h Fri Nov 29 22:02:38 2024 +0100 +++ b/ui/gtk/text.h Sat Nov 30 20:13:09 2024 +0100 @@ -74,6 +74,8 @@ UiVar *var; ui_callback onchange; void *onchangedata; + ui_callback onactivate; + void *onactivatedata; } UiTextField; typedef struct UiPathTextField { @@ -140,6 +142,7 @@ void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield); void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield); +void ui_textfield_activate(GtkEntry* self, UiTextField *textfield); char* ui_textfield_get(UiString *str); void ui_textfield_set(UiString *str, const char *value); diff -r 55fb6bad549d -r 96a055be7f0b ui/ui/text.h --- a/ui/ui/text.h Fri Nov 29 22:02:38 2024 +0100 +++ b/ui/ui/text.h Sat Nov 30 20:13:09 2024 +0100 @@ -71,6 +71,8 @@ const char *varname; ui_callback onchange; void *onchangedata; + ui_callback onactivate; + void *onactivatedata; const int *groups; } UiTextFieldArgs;