add UiText replace function (GTK) default tip

Mon, 02 Feb 2026 20:59:13 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 02 Feb 2026 20:59:13 +0100
changeset 1068
1c79dbd248f4
parent 1067
4243fcc0aa5c

add UiText replace function (GTK)

ui/cocoa/text.h file | annotate | diff | comparison | revisions
ui/cocoa/text.m file | annotate | diff | comparison | revisions
ui/common/types.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/motif/text.c file | annotate | diff | comparison | revisions
ui/motif/text.h file | annotate | diff | comparison | revisions
ui/qt/text.cpp file | annotate | diff | comparison | revisions
ui/qt/text.h file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/ui/cocoa/text.h	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/cocoa/text.h	Mon Feb 02 20:59:13 2026 +0100
@@ -37,7 +37,7 @@
 void  ui_textarea_set(UiText *text, const char *str);
 char* ui_textarea_get(UiText *text);
 char* ui_textarea_getsubstr(UiText *text, int begin, int end);
-void  ui_textarea_insert(UiText *text, int pos, char *str);
+void  ui_textarea_insert(UiText *text, int pos, const char *str);
 void  ui_textarea_setposition(UiText *text, int pos);
 int   ui_textarea_position(UiText *text);
 void  ui_textarea_setselection(UiText *text, int begin, int end);
--- a/ui/cocoa/text.m	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/cocoa/text.m	Mon Feb 02 20:59:13 2026 +0100
@@ -120,7 +120,7 @@
     return strdup(sub.UTF8String);
 }
 
-void ui_textarea_insert(UiText *text, int pos, char *str) {
+void ui_textarea_insert(UiText *text, int pos, const char *str) {
     NSTextView *textview = (__bridge NSTextView*)text->obj;
     NSString *s = [[NSString alloc] initWithUTF8String:str];
     NSAttributedString *attributedStr = [[NSAttributedString alloc] initWithString:s];
--- a/ui/common/types.c	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/common/types.c	Mon Feb 02 20:59:13 2026 +0100
@@ -676,6 +676,7 @@
     to->set = from->set;
     to->getsubstr = from->getsubstr;
     to->insert = from->insert;
+    to->replace = from->replace;
     to->setposition = from->setposition;
     to->position = from->position;
     to->showposition = from->showposition;
@@ -768,9 +769,11 @@
     t->get = NULL;
     t->getsubstr = NULL;
     t->insert = NULL;
+    t->replace = NULL;
     t->setposition = NULL;
     t->position = NULL;
     t->selection = NULL;
+    t->setselection = NULL;
     t->length = NULL;
     t->remove = NULL;
     t->obj = NULL;
--- a/ui/gtk/text.c	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/gtk/text.c	Mon Feb 02 20:59:13 2026 +0100
@@ -186,6 +186,7 @@
         value->set = ui_textarea_set;
         value->getsubstr = ui_textarea_getsubstr;
         value->insert = ui_textarea_insert;
+        value->replace = ui_textarea_replace;
         value->setposition = ui_textarea_setposition;
         value->position = ui_textarea_position;
         value->showposition = ui_textarea_showposition;
@@ -287,7 +288,7 @@
     return str;
 }
 
-void ui_textarea_insert(UiText *text, int pos, char *str) {
+void ui_textarea_insert(UiText *text, int pos, const char *str) {
     GtkTextIter offset;
     gtk_text_buffer_get_iter_at_offset(text->data1, &offset, pos);
     gtk_text_buffer_insert(text->data1, &offset, str, -1);
@@ -298,6 +299,20 @@
     text->value.free = NULL;
 }
 
+void ui_textarea_replace(UiText *text, int begin, int end, const char *replacement) {
+    GtkTextBuffer *buffer = text->data1;
+    GtkTextIter begin_offset;
+    GtkTextIter end_offset;
+    gtk_text_buffer_get_iter_at_offset(buffer, &begin_offset, begin);
+    gtk_text_buffer_get_iter_at_offset(buffer, &end_offset, end);
+    gtk_text_buffer_begin_user_action(buffer);
+    gtk_text_buffer_delete(buffer, &begin_offset, &end_offset);
+    if(replacement) {
+        gtk_text_buffer_insert(buffer, &begin_offset, replacement, -1);
+    }
+    gtk_text_buffer_end_user_action(buffer);
+}
+
 void ui_textarea_setposition(UiText *text, int pos) {
     GtkTextIter iter;
     gtk_text_buffer_get_iter_at_offset(text->data1, &iter, pos);
--- a/ui/gtk/text.h	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/gtk/text.h	Mon Feb 02 20:59:13 2026 +0100
@@ -117,7 +117,8 @@
 char* ui_textarea_get(UiText *text);
 void ui_textarea_set(UiText *text, const char *str);
 char* ui_textarea_getsubstr(UiText *text, int begin, int end);
-void ui_textarea_insert(UiText *text, int pos, char *str);
+void ui_textarea_insert(UiText *text, int pos, const char *str);
+void ui_textarea_replace(UiText *text, int begin, int end, const char *replacement);
 void ui_textarea_setposition(UiText *text, int pos);
 int ui_textarea_position(UiText *text);
 void ui_textarea_showposition(UiText *text, int pos);
--- a/ui/motif/text.c	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/motif/text.c	Mon Feb 02 20:59:13 2026 +0100
@@ -150,9 +150,9 @@
     return str;
 }
 
-void ui_textarea_insert(UiText *text, int pos, char *str) {
+void ui_textarea_insert(UiText *text, int pos, const char *str) {
     text->value.ptr = NULL;
-    XmTextInsert(text->obj, pos, str);
+    XmTextInsert(text->obj, pos, (char*)str);
     if(text->value.ptr) {
         text->value.free(text->value.ptr);
     }
--- a/ui/motif/text.h	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/motif/text.h	Mon Feb 02 20:59:13 2026 +0100
@@ -70,7 +70,7 @@
 char* ui_textarea_get(UiText *text);
 void ui_textarea_set(UiText *text, const char *str);
 char* ui_textarea_getsubstr(UiText *text, int begin, int end);
-void ui_textarea_insert(UiText *text, int pos, char *str);
+void ui_textarea_insert(UiText *text, int pos, const char *str);
 void ui_textarea_setposition(UiText *text, int pos);
 int ui_textarea_position(UiText *text);
 void ui_textarea_selection(UiText *text, int *begin, int *end);
--- a/ui/qt/text.cpp	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/qt/text.cpp	Mon Feb 02 20:59:13 2026 +0100
@@ -154,7 +154,7 @@
     return cstr ? strdup(cstr) : NULL;
 }
 
-void ui_textarea_insert(UiText *text, int pos, char *str) {
+void ui_textarea_insert(UiText *text, int pos, const char *str) {
     QTextDocument *doc = (QTextDocument*)text->data1;
     QTextCursor cursor(doc);
     cursor.setPosition(pos);
--- a/ui/qt/text.h	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/qt/text.h	Mon Feb 02 20:59:13 2026 +0100
@@ -43,7 +43,7 @@
 char* ui_textarea_get(UiText *text);
 void ui_textarea_set(UiText *text, const char *str);
 char* ui_textarea_getsubstr(UiText *text, int begin, int end);
-void ui_textarea_insert(UiText *text, int pos, char *str);
+void ui_textarea_insert(UiText *text, int pos, const char *str);
 void ui_textarea_setposition(UiText *text, int pos);
 int ui_textarea_position(UiText *text);
 void ui_textarea_setselection(UiText *text, int begin, int end);
--- a/ui/ui/toolkit.h	Sun Feb 01 18:38:06 2026 +0100
+++ b/ui/ui/toolkit.h	Mon Feb 02 20:59:13 2026 +0100
@@ -392,7 +392,8 @@
     void  (*set)(UiText*, const char*);
     char* (*get)(UiText*);
     char* (*getsubstr)(UiText*, int, int); /* text, begin, end */
-    void  (*insert)(UiText*, int, char*);
+    void  (*insert)(UiText*, int, const char*);
+    void  (*replace)(UiText*, int, int, const char*);
     void  (*setposition)(UiText*,int);
     int   (*position)(UiText*);
     void  (*showposition)(UiText*, int);

mercurial