add event handler for menu item lists newapi

Mon, 29 Jan 2024 14:02:00 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 29 Jan 2024 14:02:00 +0100
branch
newapi
changeset 238
56621137b8e1
parent 237
8649c6a29e6d
child 239
5dd24929f9f6

add event handler for menu item lists

ui/winui/appmenu.cpp file | annotate | diff | comparison | revisions
--- a/ui/winui/appmenu.cpp	Mon Jan 29 12:19:21 2024 +0100
+++ b/ui/winui/appmenu.cpp	Mon Jan 29 14:02:00 2024 +0100
@@ -165,6 +165,7 @@
 
 class UiMenuList {
 public:
+    UiObject *obj = nullptr;
     winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent = { nullptr };
     UiMenuItemType type;
     int prevSize = 0;
@@ -197,6 +198,19 @@
             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);
@@ -237,6 +251,7 @@
     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;

mercurial