set textview delegate (Cocoa)

Sat, 06 Jun 2026 18:47:45 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 06 Jun 2026 18:47:45 +0200
changeset 1177
e5e5c1779294
parent 1176
87a906a990e3
child 1178
2889dd61cfb3
child 1179
2f4c73ff962f

set textview delegate (Cocoa)

make/xcode/toolkit/toolkit/main.m file | annotate | diff | comparison | revisions
ui/cocoa/text.m file | annotate | diff | comparison | revisions
--- a/make/xcode/toolkit/toolkit/main.m	Sat Jun 06 18:37:04 2026 +0200
+++ b/make/xcode/toolkit/toolkit/main.m	Sat Jun 06 18:47:45 2026 +0200
@@ -188,8 +188,18 @@
     ui_var_set_int(event->obj->ctx, "tabview", 1);
 }
 
+static void text_change(UiEvent *event, void *data) {
+    printf("text change\n");
+}
+
+static void text_changed(UiEvent *event, void *data) {
+    printf("text changed\n");
+}
+
 void application_startup(UiEvent *event, void *data) {
     UiObject *obj = ui_splitview_window("My Window", TRUE);
+    ui_add_action(obj->ctx, "text_change", text_change, NULL);
+    ui_add_action(obj->ctx, "text_changed", text_changed, NULL);
     
     //WindowData *wdata = ui_malloc(obj->ctx, sizeof(WindowData));
     //wdata->tbtoggle = ui_int_new(obj->ctx, "tbtoggle");
@@ -241,7 +251,7 @@
         ui_tabview(obj, .padding = 20, .spacing = 10, .margin_left = 10, .margin_right = 10, .margin_bottom = 10, .fill = TRUE, .varname = "tabview") {
             ui_tab(obj, "Tab 1") {
                 ui_button(obj, .label = "Next Tab", .onclick = next_tab);
-                ui_textarea(obj, .fill = TRUE);
+                ui_textarea(obj, .fill = TRUE, .onchange_action = "text_change", .ontextchanged_action = "text_changed");
             }
             ui_tab(obj, "Tab 2") {
                 //ui_button(obj, .label = "Tab 2 Content");
--- a/ui/cocoa/text.m	Sat Jun 06 18:37:04 2026 +0200
+++ b/ui/cocoa/text.m	Sat Jun 06 18:47:45 2026 +0200
@@ -73,7 +73,9 @@
     }
     
     if(args->onchange || args->ontextchanged || args->onchange_action || args->ontextchanged_action) {
-        
+        TextAreaDelegate * tad = [[TextAreaDelegate alloc] init:obj var:var args:args];
+        textview.delegate = tad;
+        objc_setAssociatedObject(textview, "delegate", tad, OBJC_ASSOCIATION_RETAIN);
     }
     
     return (__bridge void*)scrollview;

mercurial