ui/motif/container.c

branch
newapi
changeset 176
bc63cb601f6d
parent 169
fe49cff3c571
child 253
087cc9216f28
--- a/ui/motif/container.c	Mon May 22 19:44:27 2023 +0200
+++ b/ui/motif/container.c	Mon May 22 21:21:20 2023 +0200
@@ -34,6 +34,10 @@
 #include "../common/context.h"
 #include "../common/object.h"
 
+#include <cx/array_list.h>
+#include <cx/linked_list.h>
+#include <cx/compare.h>
+
 #define UI_GRID_MAX_COLUMNS 512
 
 static UiBool ui_lb2bool(UiLayoutBool b) {
@@ -46,8 +50,8 @@
 
 
 UiContainer* ui_frame_container(UiObject *obj, Widget frame) {
-    UiContainer *ct = ucx_mempool_calloc(
-            obj->ctx->mempool,
+    UiContainer *ct = cxCalloc(
+            obj->ctx->allocator,
             1,
             sizeof(UiContainer));
     ct->widget = frame;
@@ -67,8 +71,8 @@
 
 
 UiContainer* ui_box_container(UiObject *obj, Widget box, int margin, int spacing, UiBoxOrientation orientation) {
-    UiBoxContainer *ct = ucx_mempool_calloc(
-            obj->ctx->mempool,
+    UiBoxContainer *ct = cxCalloc(
+            obj->ctx->allocator,
             1,
             sizeof(UiBoxContainer));
     ct->container.widget = box;
@@ -193,8 +197,8 @@
 }
 
 UiContainer* ui_grid_container(UiObject *obj, Widget form, int columnspacing, int rowspacing) {
-    UiGridContainer *ct = ucx_mempool_calloc(
-            obj->ctx->mempool,
+    UiGridContainer *ct = cxCalloc(
+            obj->ctx->allocator,
             1,
             sizeof(UiGridContainer));
     ct->container.widget = form;
@@ -202,6 +206,7 @@
     ct->container.add = ui_grid_container_add;
     ct->columnspacing = columnspacing;
     ct->rowspacing = rowspacing;
+    ct->lines = cxLinkedListCreateSimple(CX_STORE_POINTERS);
     return (UiContainer*)ct;
 }
 
@@ -224,10 +229,11 @@
     UiGridContainer *grid = (UiGridContainer*)ct;
     
     if(grid->current) {
-        grid->current = ucx_list_append(grid->current, widget);
+        cxListAdd(grid->current, widget);
     } else {
-        grid->current = ucx_list_append(grid->current, widget);
-        grid->lines = ucx_list_append(grid->lines, grid->current);
+        grid->current = cxLinkedListCreateSimple(CX_STORE_POINTERS);
+        cxListAdd(grid->current, widget);
+        cxListAdd(grid->lines, grid->current);
     }
     
     ui_reset_layout(ct->layout);
@@ -237,7 +243,7 @@
 static void ui_grid_resize(Widget widget, XtPointer udata, XtPointer cdata) {
     UiGridContainer *grid = udata;
     
-    UcxList *rowdim = NULL;
+    CxList *rowdim = cxArrayListCreateSimple(sizeof(int), grid->lines->size);
     int coldim[UI_GRID_MAX_COLUMNS];
     memset(coldim, 0, UI_GRID_MAX_COLUMNS*sizeof(int));
     int numcol = 0;
@@ -245,12 +251,13 @@
     // get the minimum size of the columns and rows
     int sumw = 0;
     int sumh = 0;
-    UCX_FOREACH(row, grid->lines) {
+    CxIterator lineIterator = cxListIterator(grid->lines);
+    cx_foreach(CxList *, row, lineIterator) {
         int rheight = 0;
         int i=0;
         int sum_width = 0;
-        UCX_FOREACH(elm, row->data) {
-            Widget w = elm->data;
+        CxIterator colIterator = cxListIterator(row);
+        cx_foreach(Widget, w, colIterator) {
             int widget_width = 0;
             int widget_height = 0;
             XtVaGetValues(
@@ -280,7 +287,7 @@
                 numcol = i;
             }
         }
-        rowdim = ucx_list_append(rowdim, (void*)(intptr_t)rheight);
+        cxListAdd(rowdim, &rheight);
         sumh += rheight;
     }
     
@@ -290,39 +297,40 @@
     XtVaGetValues(widget, XmNwidth, &gwidth, XmNheight, &gheight, NULL);
     if(gwidth < sumw || gheight < sumh) {
         XtVaSetValues(widget, XmNwidth, sumw, XmNheight, sumh, NULL);
-        ucx_list_free(rowdim);
+        cxListDestroy(rowdim);
         return;
     }
     
     
     // adjust the positions of all children
     int y = 0;
-    UCX_FOREACH(row, grid->lines) {
+    lineIterator = cxListIterator(grid->lines);
+    cx_foreach(CxList *, row, lineIterator) {
         int x = 0;       
         int i=0;
-        UCX_FOREACH(elm, row->data) {
-            Widget w = elm->data;
+        int *rowheight = cxListAt(rowdim, lineIterator.index);
+        CxIterator colIterator = cxListIterator(row);
+        cx_foreach(Widget, w, colIterator) {
             XtVaSetValues(
                     w,
                     XmNx, x,
                     XmNy, y,
                     XmNwidth, coldim[i],
-                    XmNheight, rowdim->data,
+                    XmNheight, *rowheight,
                     NULL);
             
             x += coldim[i];
             i++;
         }
-        y += (intptr_t)rowdim->data;
-        rowdim = rowdim->next;
+        y += *rowheight;
     }
     
-    ucx_list_free(rowdim);
+    cxListDestroy(rowdim);
 }
 
 UiContainer* ui_scrolledwindow_container(UiObject *obj, Widget scrolledwindow) {
-    UiContainer *ct = ucx_mempool_calloc(
-            obj->ctx->mempool,
+    UiContainer *ct = cxCalloc(
+            obj->ctx->allocator,
             1,
             sizeof(UiContainer));
     ct->widget = scrolledwindow;
@@ -342,14 +350,15 @@
 
 
 UiContainer* ui_tabview_container(UiObject *obj, Widget frame) {
-    UiTabViewContainer *ct = ucx_mempool_calloc(
-            obj->ctx->mempool,
+    UiTabViewContainer *ct = cxCalloc(
+            obj->ctx->allocator,
             1,
             sizeof(UiTabViewContainer));
     ct->context = obj->ctx;
     ct->container.widget = frame;
     ct->container.prepare = ui_tabview_container_prepare;
     ct->container.add = ui_tabview_container_add;
+    ct->tabs = cxArrayListCreate(cxDefaultAllocator, cx_cmp_uintptr, CX_STORE_POINTERS, 16);
     return (UiContainer*)ct;
 }
 
@@ -371,7 +380,7 @@
     }
 
     tabview->current = widget;
-    tabview->tabs = ucx_list_append(tabview->tabs, widget);
+    cxListAdd(tabview->tabs, widget);
     
     ui_select_tab(ct->widget, 0);
     ui_reset_layout(ct->layout);
@@ -526,10 +535,10 @@
     XtVaGetValues(tabview, XmNuserData, &ct, NULL);
     if(ct) {
         XtUnmanageChild(ct->current);
-        UcxList *elm = ucx_list_get(ct->tabs, tab);
-        if(elm) {
-            XtManageChild(elm->data);
-            ct->current = elm->data;
+        Widget w = cxListAt(ct->tabs, tab);
+        if(w) {
+            XtManageChild(w);
+            ct->current = w;
         } else {
             fprintf(stderr, "UiError: front tab index: %d\n", tab);
         }
@@ -549,8 +558,8 @@
     XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL);
     int button_width = width / 4;
     int x = 0;
-    UCX_FOREACH(elm, v->tabs) {
-        UiTab *tab = elm->data;
+    CxIterator tabIterator = cxListIterator(v->tabs);
+    cx_foreach(UiTab*, tab, tabIterator) {
         XtVaSetValues(
                 tab->tab_button,
                 XmNx, x,
@@ -631,7 +640,7 @@
     tabbedpane->view.widget = tabct;
     tabbedpane->view.document = NULL;
     tabbedpane->tabbar = tabbar;
-    tabbedpane->tabs = NULL;
+    tabbedpane->tabs = cxArrayListCreate(obj->ctx->allocator, cx_cmp_uintptr, CX_STORE_POINTERS, 16);
     tabbedpane->current = NULL;
     tabbedpane->height = 0;
     
@@ -665,7 +674,7 @@
     
     UiObject *content = ui_malloc(view->ctx, sizeof(UiObject));
     content->widget = NULL; // initialization for uic_context()
-    content->ctx = uic_context(content, view->ctx->mempool);
+    content->ctx = uic_context(content, view->ctx->allocator);
     content->ctx->parent = view->ctx;
     content->ctx->attach_document = uic_context_attach_document;
     content->ctx->detach_document2 = uic_context_detach_document2;
@@ -675,7 +684,7 @@
     content->next = NULL;
     
     // add tab button
-    v->tabs = ucx_list_append_a(view->ctx->mempool->allocator, v->tabs, tab);
+    cxListAdd(v->tabs, tab);
     
     XmString label = XmStringCreateLocalized("tab");
     XtSetArg(args[0], XmNlabelString, label);
@@ -735,7 +744,7 @@
     XtVaSetValues(tab->tab_button, XmNshadowThickness, 1, XmNbackground, pane->bg2, NULL);
     
     pane->current = tab;
-    pane->index = ucx_list_find(pane->tabs, tab, NULL, NULL);
+    pane->index = cxListFind(pane->tabs, tab);
     printf("index: %d\n", pane->index);
     
     // redraw tabbar

mercurial