diff -r 905ac52c910f -r 726b24766437 ui/winui/appmenu.cpp --- a/ui/winui/appmenu.cpp Mon Jan 29 12:09:24 2024 +0100 +++ b/ui/winui/appmenu.cpp Mon Jan 29 18:50:04 2024 +0100 @@ -165,11 +165,13 @@ class UiMenuList { public: + UiObject *obj = nullptr; winrt::Windows::Foundation::Collections::IVector parent = { nullptr }; UiMenuItemType type; int prevSize = 0; int insertPos = 0; UiVar* var = nullptr; + ui_getvaluefunc getvalue = nullptr; ui_callback callback = nullptr; void* userdata = nullptr; @@ -189,12 +191,26 @@ int count = 0; void* elm = list->first(list); while (elm) { + char *menuItemLabel = (char*) (getvalue ? getvalue(elm, 0) : elm); MenuFlyoutItem mi = MenuFlyoutItem(); - wchar_t* wlabel = str2wstr((char*)elm, NULL); + wchar_t* wlabel = str2wstr(menuItemLabel ? menuItemLabel : "", NULL); mi.Text(wlabel); free(wlabel); + if (callback) { + mi.Click([this, elm, count](Windows::Foundation::IInspectable const& sender, RoutedEventArgs const& e) + { + UiEvent evt; + evt.obj = obj; + evt.window = obj->window; + evt.document = obj->ctx->document; + evt.eventdata = elm; + evt.intval = count; + callback(&evt, userdata); + }); + } + parent.InsertAt(insertPos + count, mi); elm = list->next(list); @@ -235,7 +251,9 @@ UiVar* var = uic_create_var(ui_global_context(), it->varname, UI_VAR_LIST); UiMenuList* mlist = new UiMenuList(); + mlist->obj = obj; mlist->parent = parent; + mlist->getvalue = it->getvalue; mlist->callback = it->callback; mlist->userdata = it->userdata; mlist->prevSize = 0;