--- a/ui/gtk/menu.c Sun Jun 09 16:43:40 2024 +0200 +++ b/ui/gtk/menu.c Sun Jun 09 17:00:22 2024 +0200 @@ -243,6 +243,7 @@ ls->menu = GTK_MENU_SHELL(p); ls->index = index; ls->oldcount = 0; + ls->getvalue = il->getvalue; UiVar* var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST); ls->list = var->value; @@ -274,26 +275,29 @@ } } - char *str = ui_list_first(list->list); - if(str) { + void* elm = ui_list_first(list->list); + if(elm) { GtkWidget *widget = gtk_separator_menu_item_new(); gtk_menu_shell_insert(list->menu, widget, list->index); gtk_widget_show(widget); } + + ui_getvaluefunc getvalue = list->getvalue; int i = 1; - while(str) { - GtkWidget *widget = gtk_menu_item_new_with_label(str); + while(elm) { + char *label = (char*) (getvalue ? getvalue(elm, 0) : elm); + + GtkWidget *widget = gtk_menu_item_new_with_label(label); gtk_menu_shell_insert(list->menu, widget, list->index + i); gtk_widget_show(widget); if(list->callback) { - // TODO: use mempool UiEventData *event = malloc(sizeof(UiEventData)); event->obj = list->object; event->userdata = list->userdata; event->callback = list->callback; event->value = i - 1; - event->customdata = NULL; + event->customdata = elm; g_signal_connect( widget, @@ -307,7 +311,7 @@ event); } - str = ui_list_next(list->list); + elm = ui_list_next(list->list); i++; } @@ -319,7 +323,7 @@ evt.obj = event->obj; evt.window = event->obj->window; evt.document = event->obj->ctx->document; - evt.eventdata = NULL; + evt.eventdata = event->customdata; evt.intval = event->value; event->callback(&evt, event->userdata); }