implement pathbar action (WinUI3) newapi

Thu, 19 Oct 2023 20:38:16 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 19 Oct 2023 20:38:16 +0200
branch
newapi
changeset 222
1121b61f8828
parent 221
a82d9beaa94a
child 223
8d7ca1b320e2

implement pathbar action (WinUI3)

ui/winui/list.cpp file | annotate | diff | comparison | revisions
ui/winui/list.h file | annotate | diff | comparison | revisions
--- a/ui/winui/list.cpp	Thu Oct 19 18:30:19 2023 +0200
+++ b/ui/winui/list.cpp	Thu Oct 19 20:38:16 2023 +0200
@@ -283,6 +283,7 @@
     uipathbar->grid = content;
     uipathbar->buttons = buttons;
     uipathbar->textbox = pathTextBox;
+    uipathbar->obj = obj;
     uipathbar->enabledrag = args.enabledrag;
     uipathbar->enabledrop = args.enabledrop;
     uipathbar->getvalue = args.getvalue;
@@ -415,6 +416,7 @@
 
     // add new buttons
     void* elm = list->first(list);
+    int j = 0;
     while (elm) {
         char* value = (char*)getvalue(elm, 0);
         wchar_t* wstr = str2wstr(value, nullptr);
@@ -422,6 +424,18 @@
         button.Content(box_value(wstr));
         free(wstr);
 
+        if (pb->onactivate) {
+            button.Click([pb, j](IInspectable const& sender, RoutedEventArgs) {
+                UiEvent evt;
+                evt.obj = pb->obj;
+                evt.window = evt.obj->window;
+                evt.document = evt.obj->ctx->document;
+                evt.eventdata = nullptr;
+                evt.intval = j;
+                pb->onactivate(&evt, pb->onactivatedata);
+                });
+        }
+
         Thickness t = { 0, 0, 1, 0 };
         CornerRadius c = { 0 ,0, 0, 0 };
         button.BorderThickness(t);
@@ -429,6 +443,7 @@
 
         pb->buttons.Children().Append(button);
 
+        j++;
         elm = list->next(list);
     }
 }
--- a/ui/winui/list.h	Thu Oct 19 18:30:19 2023 +0200
+++ b/ui/winui/list.h	Thu Oct 19 20:38:16 2023 +0200
@@ -38,6 +38,7 @@
     winrt::Microsoft::UI::Xaml::Controls::StackPanel buttons = { nullptr };
     winrt::Microsoft::UI::Xaml::Controls::TextBox textbox = { nullptr };
 
+    UiObject* obj;
     UiModel* model;
     ui_getvaluefunc getvalue;
     ui_callback onactivate;

mercurial