add textfield onactivate event (GTK) newapi

Sat, 30 Nov 2024 20:13:09 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 30 Nov 2024 20:13:09 +0100
branch
newapi
changeset 402
96a055be7f0b
parent 401
55fb6bad549d
child 403
b59935b2de79

add textfield onactivate event (GTK)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/text.c file | annotate | diff | comparison | revisions
ui/gtk/text.h file | annotate | diff | comparison | revisions
ui/ui/text.h file | annotate | diff | comparison | revisions
--- 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);
--- 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) {
--- 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);
--- 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;

mercurial