--- a/ui/motif/toolbar.c Sun Apr 16 10:20:21 2023 +0200 +++ b/ui/motif/toolbar.c Tue May 23 11:11:28 2023 +0200 @@ -35,14 +35,19 @@ #include "button.h" #include "stock.h" #include "list.h" -#include <ucx/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 *userdata) { @@ -55,7 +60,7 @@ item->groups = NULL; item->isimportant = FALSE; - ucx_map_cstr_put(toolbar_items, name, item); + cxMapPut(toolbar_items, name, item); } void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *userdata) { @@ -76,11 +81,14 @@ va_start(ap, userdata); 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); } va_end(ap); - ucx_map_cstr_put(toolbar_items, name, item); + cxMapPut(toolbar_items, name, item); } void ui_toolitem_img(char *name, char *label, char *img, ui_callback f, void *udata) { @@ -95,7 +103,7 @@ item->groups = NULL; item->isimportant = FALSE; - ucx_map_cstr_put(toolbar_items, name, item); + cxMapPut(toolbar_items, name, item); } @@ -115,11 +123,14 @@ va_start(ap, udata); 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); } va_end(ap); - ucx_map_cstr_put(toolbar_items, name, item); + cxMapPut(toolbar_items, name, item); } void ui_toolitem_toggle_imggr(char *name, char *label, char *img, ui_callback f, void *udata, ...) { @@ -139,11 +150,14 @@ va_start(ap, udata); 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); } va_end(ap); - ucx_map_cstr_put(toolbar_items, name, item); + cxMapPut(toolbar_items, name, item); } void ui_toolbar_combobox( @@ -160,7 +174,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( @@ -186,13 +200,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); } Widget ui_create_toolbar(UiObject *obj, Widget parent) { @@ -213,14 +227,15 @@ XtSetArg(args[2], XmNspacing, 1); Widget toolbar = XmCreateRowColumn (frame, "toolbar", args, 3); - 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(toolbar, item, obj); - } else if(!strcmp(elm->data, "@separator")) { + } else if(!strcmp(def, "@separator")) { // TODO } else { - fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", elm->data); + fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", def); } } @@ -242,8 +257,8 @@ XmStringFree(label); 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; @@ -276,8 +291,8 @@ XmStringFree(label); 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; @@ -309,8 +324,8 @@ XmStringFree(label); 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; @@ -334,11 +349,11 @@ } void add_toolbar_combobox(Widget tb, UiToolbarComboBox *item, UiObject *obj) { - UiListView *listview = ucx_mempool_malloc( - obj->ctx->mempool, + UiListView *listview = cxMalloc( + obj->ctx->allocator, sizeof(UiListView)); - UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); + UiVar *var = cxMalloc(obj->ctx->allocator, sizeof(UiVar)); var->value = item->list; var->type = UI_VAR_SPECIAL;