fix list binding not copied correctly when attaching a document newapi

Sun, 28 Jan 2024 11:42:42 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 28 Jan 2024 11:42:42 +0100
branch
newapi
changeset 232
e2b33055113f
parent 231
e160bb392148
child 233
84665f0a9ab2

fix list binding not copied correctly when attaching a document

ui/common/context.c file | annotate | diff | comparison | revisions
ui/common/document.c file | annotate | diff | comparison | revisions
ui/common/menu.c file | annotate | diff | comparison | revisions
ui/winui/toolkit.cpp file | annotate | diff | comparison | revisions
--- a/ui/common/context.c	Sun Jan 28 10:06:54 2024 +0100
+++ b/ui/common/context.c	Sun Jan 28 11:42:42 2024 +0100
@@ -314,11 +314,15 @@
             break;
         }
         case UI_VAR_LIST: {
-            UiList *f = fromvalue;
-            UiList *t = to->value;
-            if(!f->obj) break;
-            uic_list_copy(f, t);
-            t->update(t, -1);
+            // TODO: not sure how correct this is
+
+            UiVar tmp = *from;
+            *from = *to;
+            *to = tmp;
+
+            UiList* t = to->value;
+            ui_notify(t->observers, NULL);
+            
             break;
         }
         case UI_VAR_RANGE: {
--- a/ui/common/document.c	Sun Jan 28 10:06:54 2024 +0100
+++ b/ui/common/document.c	Sun Jan 28 11:42:42 2024 +0100
@@ -38,7 +38,9 @@
 static CxMap *documents;
 
 void uic_docmgr_init() {
-    documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
+    if (!documents) {
+        documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
+    }
 }
 
 void ui_set_document(UiObject *obj, void *document) {
@@ -80,7 +82,7 @@
 }
 
 void* ui_document_new(size_t size) {
-    CxMempool *mp = cxBasicMempoolCreate(256);
+    CxMempool *mp = cxMempoolCreate(256, NULL);
     const CxAllocator *a = mp->allocator;
     UiContext *ctx = cxCalloc(a, 1, sizeof(UiContext));
     ctx->attach_document = uic_context_attach_document;
--- a/ui/common/menu.c	Sun Jan 28 10:06:54 2024 +0100
+++ b/ui/common/menu.c	Sun Jan 28 11:42:42 2024 +0100
@@ -237,6 +237,10 @@
 
 
 void uic_add_menu_to_stack(UiMenu* menu) {
+    if (!current) {
+        current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS);
+    }
+
     cxListInsert(current, 0, menu);
 }
 
--- a/ui/winui/toolkit.cpp	Sun Jan 28 10:06:54 2024 +0100
+++ b/ui/winui/toolkit.cpp	Sun Jan 28 11:42:42 2024 +0100
@@ -34,6 +34,7 @@
 #include <cx/mempool.h>
 
 #include "../common/context.h"
+#include "../common/document.h"
 #include "../common/toolbar.h"
 
 #include "icons.h"
@@ -158,6 +159,7 @@
 	//ui_appsdk_bootstrap();
 
 	uic_init_global_context();
+	uic_docmgr_init();
 	uic_toolbar_init();
 }
 

mercurial