ui/winui/appmenu.cpp

branch
newapi
changeset 238
56621137b8e1
parent 237
8649c6a29e6d
equal deleted inserted replaced
237:8649c6a29e6d 238:56621137b8e1
163 } 163 }
164 164
165 165
166 class UiMenuList { 166 class UiMenuList {
167 public: 167 public:
168 UiObject *obj = nullptr;
168 winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent = { nullptr }; 169 winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent = { nullptr };
169 UiMenuItemType type; 170 UiMenuItemType type;
170 int prevSize = 0; 171 int prevSize = 0;
171 int insertPos = 0; 172 int insertPos = 0;
172 UiVar* var = nullptr; 173 UiVar* var = nullptr;
195 MenuFlyoutItem mi = MenuFlyoutItem(); 196 MenuFlyoutItem mi = MenuFlyoutItem();
196 wchar_t* wlabel = str2wstr(menuItemLabel ? menuItemLabel : "", NULL); 197 wchar_t* wlabel = str2wstr(menuItemLabel ? menuItemLabel : "", NULL);
197 mi.Text(wlabel); 198 mi.Text(wlabel);
198 free(wlabel); 199 free(wlabel);
199 200
201 if (callback) {
202 mi.Click([this, elm, count](Windows::Foundation::IInspectable const& sender, RoutedEventArgs const& e)
203 {
204 UiEvent evt;
205 evt.obj = obj;
206 evt.window = obj->window;
207 evt.document = obj->ctx->document;
208 evt.eventdata = elm;
209 evt.intval = count;
210 callback(&evt, userdata);
211 });
212 }
213
200 parent.InsertAt(insertPos + count, mi); 214 parent.InsertAt(insertPos + count, mi);
201 215
202 elm = list->next(list); 216 elm = list->next(list);
203 count++; 217 count++;
204 } 218 }
235 uint32_t size = parent.Size(); 249 uint32_t size = parent.Size();
236 250
237 UiVar* var = uic_create_var(ui_global_context(), it->varname, UI_VAR_LIST); 251 UiVar* var = uic_create_var(ui_global_context(), it->varname, UI_VAR_LIST);
238 252
239 UiMenuList* mlist = new UiMenuList(); 253 UiMenuList* mlist = new UiMenuList();
254 mlist->obj = obj;
240 mlist->parent = parent; 255 mlist->parent = parent;
241 mlist->getvalue = it->getvalue; 256 mlist->getvalue = it->getvalue;
242 mlist->callback = it->callback; 257 mlist->callback = it->callback;
243 mlist->userdata = it->userdata; 258 mlist->userdata = it->userdata;
244 mlist->prevSize = 0; 259 mlist->prevSize = 0;

mercurial