detaching variables correctly

Sun, 18 Sep 2016 08:39:37 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 18 Sep 2016 08:39:37 +0200
changeset 131
774b741984a2
parent 130
212b63dd61be
child 132
a24465cc7262

detaching variables correctly

ui/common/context.c file | annotate | diff | comparison | revisions
ui/gtk/text.c file | annotate | diff | comparison | revisions
ui/motif/text.c file | annotate | diff | comparison | revisions
--- a/ui/common/context.c	Sun Sep 18 07:45:42 2016 +0200
+++ b/ui/common/context.c	Sun Sep 18 08:39:37 2016 +0200
@@ -61,6 +61,10 @@
 }
 
 void uic_context_set_document(UiContext *ctx, void *document) {
+    if(ctx->document == document) {
+        return;
+    }
+    
     UiContext *docctx = ui_document_context(document);
     if(!docctx) {
         return;
@@ -228,6 +232,10 @@
             } else {
                 f->value = f->get(f);
                 f->pos = f->position(f);
+                f->set = NULL;
+                f->get = NULL;
+                f->setposition = NULL;
+                f->position = NULL;
             }
             break;
         }
--- a/ui/gtk/text.c	Sun Sep 18 07:45:42 2016 +0200
+++ b/ui/gtk/text.c	Sun Sep 18 08:39:37 2016 +0200
@@ -242,6 +242,25 @@
     gtk_widget_grab_focus(widget);
 }
 
+void ui_text_set(UiText *text, char *str) {
+    if(text->set) {
+        text->set(text, str);
+    } else {
+        if(text->value) {
+            g_free(text->value);
+        }
+        text->value = g_strdup(str);
+    }
+}
+
+char* ui_text_get(UiText *text) {
+    if(text->get) {
+        return text->get(text);
+    } else {
+        return text->value;
+    }
+}
+
 
 // undo manager functions
 
--- a/ui/motif/text.c	Sun Sep 18 07:45:42 2016 +0200
+++ b/ui/motif/text.c	Sun Sep 18 08:39:37 2016 +0200
@@ -157,6 +157,27 @@
     return (int)XmTextGetLastPosition(text->obj);
 }
 
+
+void ui_text_set(UiText *text, char *str) {
+    if(text->set) {
+        text->set(text, str);
+    } else {
+        if(text->value) {
+            XtFree(text->value);
+        }
+        text->value = XtNewString(str);
+    }
+}
+
+char* ui_text_get(UiText *text) {
+    if(text->get) {
+        return text->get(text);
+    } else {
+        return text->value;
+    }
+}
+
+
 UiUndoMgr* ui_create_undomgr() {
     UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr));
     mgr->begin = NULL;

mercurial