implement new text functions (Motif)

7 days ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 Apr 2025 13:45:18 +0200 (7 days ago)
changeset 554
28e490aa15e3
parent 553
90e38db0c755
child 555
0b1bb5687dca

implement new text functions (Motif)

application/main.c file | annotate | diff | comparison | revisions
ui/motif/text.c file | annotate | diff | comparison | revisions
ui/motif/text.h file | annotate | diff | comparison | revisions
ui/motif/widget.c file | annotate | diff | comparison | revisions
--- a/application/main.c	Sun Apr 06 13:28:35 2025 +0200
+++ b/application/main.c	Sun Apr 06 13:45:18 2025 +0200
@@ -763,7 +763,7 @@
 
 #endif
 
-#if defined(UI_COCOA) || defined(UI_MOTIF)
+#if (defined(UI_COCOA) || defined(UI_MOTIF)) && !defined(UI_TEST)
 
 static UiList *menulist;
 int items = 4;
--- a/ui/motif/text.c	Sun Apr 06 13:28:35 2025 +0200
+++ b/ui/motif/text.c	Sun Apr 06 13:45:18 2025 +0200
@@ -68,6 +68,9 @@
             value->value.ptr = NULL;
         }
         
+        value->save = ui_textarea_save;
+        value->restore = ui_textarea_restore;
+        value->destroy = ui_textarea_text_destroy;
         value->set = ui_textarea_set;
         value->get = ui_textarea_get;
         value->getsubstr = ui_textarea_getsubstr;
@@ -79,8 +82,8 @@
         value->value.ptr = NULL;
         value->obj = widget;
         
-        if(!value->undomgr) {
-            value->undomgr = ui_create_undomgr();
+        if(!value->data2) {
+            value->data2 = ui_create_undomgr();
         }
         
         XtAddCallback(
@@ -103,6 +106,25 @@
     return str;
 }
 
+void ui_textarea_save(UiText *text) {
+    (void)ui_textarea_get(text);
+}
+
+void ui_textarea_restore(UiText *text) {
+    if(text->value.ptr) {
+        ui_textarea_set(text, text->value.ptr);
+    }
+}
+
+void ui_textarea_text_destroy(UiText *text) {
+    if(text->value.free) {
+        text->value.free(text->value.ptr);
+    }
+    if(text->data2) {
+        ui_destroy_undomgr(text->data2);
+    }
+}
+
 void ui_textarea_set(UiText *text, const char *str) {
     XmTextSetString(text->obj, (char*)str);
     if(text->value.ptr) {
@@ -201,13 +223,13 @@
         // TODO: bug, fix
         return;
     }
-    if(!value->undomgr) {
-        value->undomgr = ui_create_undomgr();
+    if(!value->data2) {
+        value->data2 = ui_create_undomgr();
     }
     
     XmTextVerifyCallbackStruct *txv = (XmTextVerifyCallbackStruct*)data;
     int type = txv->text->length > 0 ? UI_TEXTBUF_INSERT : UI_TEXTBUF_DELETE;
-    UiUndoMgr *mgr = value->undomgr;
+    UiUndoMgr *mgr = value->data2;
     if(!mgr->event) {
         return;
     }
@@ -307,7 +329,7 @@
 
 
 void ui_text_undo(UiText *value) {
-    UiUndoMgr *mgr = value->undomgr;
+    UiUndoMgr *mgr = value->data2;
     
     if(mgr->cur) {
         UiTextBufOp *op = mgr->cur;
@@ -328,7 +350,7 @@
 }
 
 void ui_text_redo(UiText *value) {
-    UiUndoMgr *mgr = value->undomgr;
+    UiUndoMgr *mgr = value->data2;
     
     UiTextBufOp *elm = NULL;
     if(mgr->cur) {
--- a/ui/motif/text.h	Sun Apr 06 13:28:35 2025 +0200
+++ b/ui/motif/text.h	Sun Apr 06 13:45:18 2025 +0200
@@ -64,6 +64,9 @@
     int last_selection_state;
 } UiTextArea;
 
+void ui_textarea_save(UiText *text);
+void ui_textarea_restore(UiText *text);
+void ui_textarea_text_destroy(UiText *text);
 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);
--- a/ui/motif/widget.c	Sun Apr 06 13:28:35 2025 +0200
+++ b/ui/motif/widget.c	Sun Apr 06 13:45:18 2025 +0200
@@ -69,3 +69,11 @@
     
     return widget;
 }
+
+void ui_widget_set_size(UIWIDGET w, int width, int height) {
+    
+}
+
+void ui_widget_redraw(UIWIDGET w) {
+    
+}

mercurial