fix UiList binding copy and missing GTK table setselection method newapi

Tue, 26 Nov 2024 10:40:03 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 26 Nov 2024 10:40:03 +0100
branch
newapi
changeset 392
df62b7205bd3
parent 391
fc0df448dfbc
child 393
3099bf907e21

fix UiList binding copy and missing GTK table setselection method

ui/common/context.c file | annotate | diff | comparison | revisions
ui/common/context.h file | annotate | diff | comparison | revisions
ui/gtk/list.c file | annotate | diff | comparison | revisions
ui/gtk/menu.c file | annotate | diff | comparison | revisions
--- a/ui/common/context.c	Tue Nov 26 10:02:04 2024 +0100
+++ b/ui/common/context.c	Tue Nov 26 10:40:03 2024 +0100
@@ -62,7 +62,7 @@
     ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16);
     
     ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_intptr, CX_STORE_POINTERS);
-    ctx->group_widgets = cxLinkedListCreate(mp->allocator, NULL, sizeof(UiGroupWidget));
+    ctx->group_widgets = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, sizeof(UiGroupWidget));
     ctx->groups = cxArrayListCreate(mp->allocator, cx_cmp_int, sizeof(int), 32);
     
     ctx->attach_document = uic_context_attach_document;
@@ -331,6 +331,7 @@
                 t->obj = f->obj;
                 t->update = f->update;
                 t->getselection = f->getselection;
+                t->setselection = f->setselection;
             }
 
             UiVar tmp = *from;
@@ -556,6 +557,10 @@
     cxListAdd(ctx->group_widgets, &gw);
 }
 
+void uic_remove_group_widget(UiContext *ctx, void *widget) {
+    (void)cxListFindRemove(ctx->group_widgets, widget);
+}
+
 UIEXPORT void *ui_allocator(UiContext *ctx) {
     return (void*)ctx->allocator;
 }
--- a/ui/common/context.h	Tue Nov 26 10:02:04 2024 +0100
+++ b/ui/common/context.h	Tue Nov 26 10:40:03 2024 +0100
@@ -140,7 +140,7 @@
 void uic_check_group_widgets(UiContext *ctx);
 void uic_add_group_widget(UiContext *ctx, void *widget, ui_enablefunc enable, CxList *groups);
 void uic_add_group_widget_i(UiContext *ctx, void *widget, ui_enablefunc enable, const int *groups, size_t numgroups);
-
+void uic_remove_group_widget(UiContext *ctx, void *widget);
 
 #ifdef	__cplusplus
 }
--- a/ui/gtk/list.c	Tue Nov 26 10:02:04 2024 +0100
+++ b/ui/gtk/list.c	Tue Nov 26 10:40:03 2024 +0100
@@ -375,6 +375,7 @@
     // bind var
     list->update = ui_listview_update;
     list->getselection = ui_listview_getselection;
+    list->setselection = ui_listview_setselection;
     list->obj = tableview;
     
     // add callback
--- a/ui/gtk/menu.c	Tue Nov 26 10:02:04 2024 +0100
+++ b/ui/gtk/menu.c	Tue Nov 26 10:40:03 2024 +0100
@@ -432,12 +432,23 @@
     g_menu_append_submenu(parent, mi->label, G_MENU_MODEL(menu));
 }
 
+static void action_enable(GSimpleAction *action, int enabled) {
+    g_simple_action_set_enabled(action, enabled);
+}
+
 void ui_gmenu_add_menuitem(GMenu *parent, int index, UiMenuItemI *item, UiObject *obj) {
     UiMenuItem *i = (UiMenuItem*)item;
-
+     
     GSimpleAction *action = g_simple_action_new(item->id, NULL);
     g_action_map_add_action(obj->ctx->action_map, G_ACTION(action));
     
+    if(i->groups) {
+        CxList *groups = cxArrayListCreateSimple(sizeof(int), i->ngroups);
+        cxListAddArray(groups, i->groups, i->ngroups);
+        uic_add_group_widget(obj->ctx, action, (ui_enablefunc)action_enable, groups);
+        cxListDestroy(groups);
+    }
+    
     if(i->callback != NULL) {
         UiEventData *event = malloc(sizeof(UiEventData));
         event->obj = obj;

mercurial