ui/winui/appmenu.cpp

changeset 8
726b24766437
parent 3
f154867f54dc
equal deleted inserted replaced
7:905ac52c910f 8:726b24766437
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;
174 ui_getvaluefunc getvalue = nullptr;
173 ui_callback callback = nullptr; 175 ui_callback callback = nullptr;
174 void* userdata = nullptr; 176 void* userdata = nullptr;
175 177
176 UiMenuList() { 178 UiMenuList() {
177 179
187 189
188 // insert new items 190 // insert new items
189 int count = 0; 191 int count = 0;
190 void* elm = list->first(list); 192 void* elm = list->first(list);
191 while (elm) { 193 while (elm) {
194 char *menuItemLabel = (char*) (getvalue ? getvalue(elm, 0) : elm);
192 195
193 MenuFlyoutItem mi = MenuFlyoutItem(); 196 MenuFlyoutItem mi = MenuFlyoutItem();
194 wchar_t* wlabel = str2wstr((char*)elm, NULL); 197 wchar_t* wlabel = str2wstr(menuItemLabel ? menuItemLabel : "", NULL);
195 mi.Text(wlabel); 198 mi.Text(wlabel);
196 free(wlabel); 199 free(wlabel);
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 }
197 213
198 parent.InsertAt(insertPos + count, mi); 214 parent.InsertAt(insertPos + count, mi);
199 215
200 elm = list->next(list); 216 elm = list->next(list);
201 count++; 217 count++;
233 uint32_t size = parent.Size(); 249 uint32_t size = parent.Size();
234 250
235 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);
236 252
237 UiMenuList* mlist = new UiMenuList(); 253 UiMenuList* mlist = new UiMenuList();
254 mlist->obj = obj;
238 mlist->parent = parent; 255 mlist->parent = parent;
256 mlist->getvalue = it->getvalue;
239 mlist->callback = it->callback; 257 mlist->callback = it->callback;
240 mlist->userdata = it->userdata; 258 mlist->userdata = it->userdata;
241 mlist->prevSize = 0; 259 mlist->prevSize = 0;
242 mlist->insertPos = size; 260 mlist->insertPos = size;
243 mlist->type = item->type; 261 mlist->type = item->type;

mercurial