ui/gtk/toolbar.c

branch
newapi
changeset 174
0358f1d9c506
parent 168
1b99acacc5bb
child 253
087cc9216f28
--- a/ui/gtk/toolbar.c	Sat Apr 15 21:06:45 2023 +0200
+++ b/ui/gtk/toolbar.c	Mon May 22 16:17:26 2023 +0200
@@ -34,14 +34,18 @@
 #include "button.h"
 #include "image.h"
 #include "tree.h"
-#include <ucx/mempool.h>
+#include <cx/basic_mempool.h>
+#include <cx/hash_map.h>
+#include <cx/linked_list.h>
+#include <cx/array_list.h>
 #include "../common/context.h"
 
-static UcxMap *toolbar_items;
-static UcxList *defaults;
+static CxMap *toolbar_items;
+static CxList *defaults;
 
 void ui_toolbar_init() {
-    toolbar_items = ucx_map_new(16);
+    toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
+    defaults = cxLinkedListCreateSimple(CX_STORE_POINTERS);
 }
 
 void ui_toolitem(char *name, char *label, ui_callback f, void *udata) {
@@ -80,7 +84,7 @@
     item->isimportant = 0;
     item->groups = NULL;
     
-    ucx_map_cstr_put(toolbar_items, name, item);
+    cxMapPut(toolbar_items, name, item);
 }
 
 void ui_toolitem_vstgr(
@@ -102,10 +106,13 @@
     // add groups
     int group;
     while((group = va_arg(ap, int)) != -1) {
-        item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group);
+        if(!item->groups) {
+            item->groups = cxArrayListCreateSimple(sizeof(int), 16);
+        }
+        cxListAdd(item->groups, &group);
     }
     
-    ucx_map_cstr_put(toolbar_items, name, item);
+    cxMapPut(toolbar_items, name, item);
 }
 
 void ui_toolitem_toggle(const char *name, const char *label, const char *img, UiInteger *i) {
@@ -119,7 +126,7 @@
     item->value = i;
     item->var = NULL;
     
-    ucx_map_cstr_put(toolbar_items, name, item);
+    cxMapPut(toolbar_items, name, item);
 }
 
 void ui_toolitem_toggle_st(const char *name, const char *stockid, UiInteger *i) {
@@ -133,7 +140,7 @@
     item->value = i;
     item->var = NULL;
     
-    ucx_map_cstr_put(toolbar_items, name, item);
+    cxMapPut(toolbar_items, name, item);
 }
 
 void ui_toolitem_toggle_nv(const char *name, const char *label, const char *img, const char *intvar) {
@@ -147,7 +154,7 @@
     item->value = NULL;
     item->var = intvar;
     
-    ucx_map_cstr_put(toolbar_items, name, item);
+    cxMapPut(toolbar_items, name, item);
 }
 
 void ui_toolitem_toggle_stnv(const char *name, const char *stockid, const char *intvar) {
@@ -161,7 +168,7 @@
     item->value = NULL;
     item->var = intvar;
     
-    ucx_map_cstr_put(toolbar_items, name, item);
+    cxMapPut(toolbar_items, name, item);
 }
 
 
@@ -184,7 +191,7 @@
     cb->callback = f;
     cb->userdata = udata;
     
-    ucx_map_cstr_put(toolbar_items, name, cb);
+    cxMapPut(toolbar_items, name, cb);
 }
 
 void ui_toolbar_combobox_str(
@@ -210,13 +217,13 @@
     cb->callback = f;
     cb->userdata = udata;
     
-    ucx_map_cstr_put(toolbar_items, name, cb);
+    cxMapPut(toolbar_items, name, cb);
 }
 
 
 void ui_toolbar_add_default(char *name) {
     char *s = strdup(name);
-    defaults = ucx_list_append(defaults, s);
+    cxListAdd(defaults, s);
 }
 
 GtkWidget* ui_create_toolbar(UiObject *obj) {
@@ -232,14 +239,15 @@
 #endif
     
     GtkToolbar *tb = GTK_TOOLBAR(toolbar);
-    UCX_FOREACH(elm, defaults) {
-        UiToolItemI *item = ucx_map_cstr_get(toolbar_items, elm->data);
+    CxIterator i = cxListIterator(defaults);
+    cx_foreach(char *, def, i) {
+        UiToolItemI *item = cxMapGet(toolbar_items, def);
         if(item) {
             item->add_to(tb, item, obj);
-        } else if(!strcmp(elm->data, "@separator")) {
+        } else if(!strcmp(def, "@separator")) {
             gtk_toolbar_insert(tb, gtk_separator_tool_item_new(), -1);
         } else {
-            fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", elm->data);
+            fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", def);
         }
     }
     
@@ -258,8 +266,8 @@
     }
     
     if(item->callback) {
-        UiEventData *event = ucx_mempool_malloc(
-                obj->ctx->mempool,
+        UiEventData *event = cxMalloc(
+                obj->ctx->allocator,
                 sizeof(UiEventData));
         event->obj = obj;
         event->userdata = item->userdata;
@@ -287,8 +295,8 @@
     }
     
     if(item->callback) {
-        UiEventData *event = ucx_mempool_malloc(
-                obj->ctx->mempool,
+        UiEventData *event = cxMalloc(
+                obj->ctx->allocator,
                 sizeof(UiEventData));
         event->obj = obj;
         event->userdata = item->userdata;
@@ -349,8 +357,8 @@
     
     // register event
     // the event func will call the UiInteger observer callbacks
-    UiEventData *event = ucx_mempool_malloc(
-            obj->ctx->mempool,
+    UiEventData *event = cxMalloc(
+            obj->ctx->allocator,
             sizeof(UiEventData));
     event->obj = obj;
     event->userdata = var;

mercurial