39 using namespace winrt; |
39 using namespace winrt; |
40 using namespace Microsoft::UI::Xaml; |
40 using namespace Microsoft::UI::Xaml; |
41 using namespace Microsoft::UI::Xaml::Controls; |
41 using namespace Microsoft::UI::Xaml::Controls; |
42 using namespace Windows::UI::Xaml::Interop; |
42 using namespace Windows::UI::Xaml::Interop; |
43 using namespace winrt::Windows::Foundation; |
43 using namespace winrt::Windows::Foundation; |
|
44 using namespace Microsoft::UI::Xaml::Markup; |
|
45 using namespace Microsoft::UI::Xaml::Media; |
44 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; |
46 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; |
45 |
47 |
46 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args) { |
48 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args) { |
47 UiObject* current = uic_current_obj(obj); |
49 UiObject* current = uic_current_obj(obj); |
48 |
50 |
207 current->container->Add(bcbar, false); |
209 current->container->Add(bcbar, false); |
208 |
210 |
209 return widget; |
211 return widget; |
210 } |
212 } |
211 |
213 |
|
214 |
|
215 extern "C" static void destroy_ui_pathbar(void* ptr) { |
|
216 UiPathBar* pb = (UiPathBar*)ptr; |
|
217 delete pb; |
|
218 } |
|
219 |
|
220 static void ui_context_add_pathbar_destructor(UiContext* ctx, UiPathBar* pb) { |
|
221 cxMempoolRegister(ctx->mp, pb, destroy_ui_pathbar); |
|
222 } |
|
223 |
|
224 UIEXPORT UIWIDGET ui_pathbar_create(UiObject* obj, UiPathBarArgs args) { |
|
225 UiObject* current = uic_current_obj(obj); |
|
226 |
|
227 // create view and toolkit wrapper |
|
228 Border pathbar = Border(); |
|
229 |
|
230 IInspectable bgRes = Application::Current().Resources().Lookup(box_value(L"TextControlBackground")); |
|
231 IInspectable borderThicknessRes = Application::Current().Resources().Lookup(box_value(L"TextControlBorderThemeThickness")); |
|
232 IInspectable borderBrushRes = Application::Current().Resources().Lookup(box_value(L"TextControlBorderBrush")); |
|
233 // IInspectable cornerRes = Application::Current().Resources().Lookup(box_value(L"TextControlCornerRadius")); |
|
234 |
|
235 Brush bgBrush = unbox_value<Brush>(bgRes); |
|
236 Thickness border = unbox_value<Thickness>(borderThicknessRes); |
|
237 Brush borderBrush = unbox_value<Brush>(borderBrushRes); |
|
238 CornerRadius cornerRadius = { 4, 4, 4, 4 }; //unbox_value<CornerRadius>(cornerRes); |
|
239 |
|
240 pathbar.Background(bgBrush); |
|
241 pathbar.BorderBrush(borderBrush); |
|
242 pathbar.BorderThickness(border); |
|
243 pathbar.CornerRadius(cornerRadius); |
|
244 |
|
245 Grid content = Grid(); |
|
246 pathbar.Child(content); |
|
247 |
|
248 GridLength gl; |
|
249 gl.Value = 1; |
|
250 gl.GridUnitType = GridUnitType::Star; |
|
251 |
|
252 ColumnDefinition coldef = ColumnDefinition(); |
|
253 coldef.Width(gl); |
|
254 content.ColumnDefinitions().Append(coldef); |
|
255 |
|
256 TextBox pathTextBox = TextBox(); |
|
257 Thickness t = { 0, 0, 0, 0 }; |
|
258 CornerRadius c = { 0 ,0, 0, 0 }; |
|
259 pathTextBox.BorderThickness(t); |
|
260 //pathTextBox.CornerRadius(c); |
|
261 |
|
262 |
|
263 pathTextBox.HorizontalAlignment(HorizontalAlignment::Stretch); |
|
264 content.SetColumn(pathTextBox, 0); |
|
265 |
|
266 content.Children().Append(pathTextBox); |
|
267 |
|
268 // stackpanel for buttons |
|
269 StackPanel buttons = StackPanel(); |
|
270 buttons.Orientation(Orientation::Horizontal); |
|
271 buttons.Visibility(Visibility::Collapsed); |
|
272 content.SetColumn(buttons, 0); |
|
273 content.Children().Append(buttons); |
|
274 |
|
275 if (args.ontextinput) { |
|
276 // TODO |
|
277 } |
|
278 |
|
279 //pathTextBox.Visibility(Visibility::Collapsed); |
|
280 |
|
281 UiPathBar* uipathbar = new UiPathBar; |
|
282 ui_context_add_pathbar_destructor(current->ctx, uipathbar); |
|
283 uipathbar->grid = content; |
|
284 uipathbar->buttons = buttons; |
|
285 uipathbar->textbox = pathTextBox; |
|
286 uipathbar->enabledrag = args.enabledrag; |
|
287 uipathbar->enabledrop = args.enabledrop; |
|
288 uipathbar->getvalue = args.getvalue; |
|
289 uipathbar->model = args.model; |
|
290 uipathbar->onactivate = args.onactivate; |
|
291 uipathbar->onactivatedata = args.onactivatedata; |
|
292 uipathbar->ondragstart = args.ondragstart; |
|
293 uipathbar->ondragstartdata = args.ondragstartdata; |
|
294 uipathbar->ondragcomplete = args.ondragcomplete; |
|
295 uipathbar->ondragcompletedata = args.ondragcompletedata; |
|
296 uipathbar->ondrop = args.ondrop; |
|
297 uipathbar->ondropdata = args.ondropsdata; |
|
298 |
|
299 UIElement elm = pathbar; |
|
300 UiWidget* widget = new UiWidget(elm); |
|
301 widget->data1 = uipathbar; |
|
302 ui_context_add_widget_destructor(current->ctx, widget); |
|
303 |
|
304 // bind var |
|
305 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
|
306 if (var) { |
|
307 UiList* list = (UiList*)var->value; |
|
308 list->update = ui_pathbar_update; |
|
309 list->obj = widget; |
|
310 ui_pathbar_update(list, 0); |
|
311 } |
|
312 |
|
313 // add listview to current container |
|
314 UI_APPLY_LAYOUT1(current, args); |
|
315 |
|
316 current->container->Add(pathbar, false); |
|
317 |
|
318 return widget; |
|
319 } |
|
320 |
212 static void* getstrvalue(void* elm, int ignore) { |
321 static void* getstrvalue(void* elm, int ignore) { |
213 return elm; |
322 return elm; |
214 } |
323 } |
215 |
324 |
216 void ui_simple_list_update(UiList* list, int i) { |
325 void ui_simple_list_update(UiList* list, int i) { |
271 } |
380 } |
272 |
381 |
273 bar.ItemsSource(items); |
382 bar.ItemsSource(items); |
274 } |
383 } |
275 |
384 |
|
385 static void ui_pathbar_clear(StackPanel &buttons) { |
|
386 for (int i = buttons.Children().Size() - 1; i >= 0; i--) { |
|
387 buttons.Children().RemoveAt(i); |
|
388 } |
|
389 } |
|
390 |
|
391 extern "C" void ui_pathbar_update(UiList * list, int i) { |
|
392 UiWidget* widget = (UiWidget*)list->obj; |
|
393 UiPathBar* pb = (UiPathBar*)widget->data1; |
|
394 Grid grid = pb->grid; |
|
395 |
|
396 UiModel* model = pb->model; |
|
397 ui_getvaluefunc getvalue = pb->getvalue; |
|
398 |
|
399 // priority: getvalue, model.getvalue, getstrvalue (fallback) |
|
400 if (getvalue == nullptr) { |
|
401 if (model && model->getvalue) { |
|
402 getvalue = model->getvalue; |
|
403 } |
|
404 else { |
|
405 getvalue = getstrvalue; |
|
406 } |
|
407 } |
|
408 |
|
409 // hide textbox, show button panel |
|
410 pb->textbox.Visibility(Visibility::Collapsed); |
|
411 pb->buttons.Visibility(Visibility::Visible); |
|
412 |
|
413 // clear old buttons |
|
414 ui_pathbar_clear(pb->buttons); |
|
415 |
|
416 // add new buttons |
|
417 void* elm = list->first(list); |
|
418 while (elm) { |
|
419 char* value = (char*)getvalue(elm, 0); |
|
420 wchar_t* wstr = str2wstr(value, nullptr); |
|
421 Button button = Button(); |
|
422 button.Content(box_value(wstr)); |
|
423 free(wstr); |
|
424 |
|
425 Thickness t = { 0, 0, 1, 0 }; |
|
426 CornerRadius c = { 0 ,0, 0, 0 }; |
|
427 button.BorderThickness(t); |
|
428 button.CornerRadius(c); |
|
429 |
|
430 pb->buttons.Children().Append(button); |
|
431 |
|
432 elm = list->next(list); |
|
433 } |
|
434 } |
|
435 |
|
436 |
276 std::vector<int> ui_create_listview_selection(ListView listview) { |
437 std::vector<int> ui_create_listview_selection(ListView listview) { |
277 std::vector<int> selection; |
438 std::vector<int> selection; |
278 int p = 0; |
439 int p = 0; |
279 auto ranges = listview.SelectedRanges(); |
440 auto ranges = listview.SelectedRanges(); |
280 for (auto range : ranges) { |
441 for (auto range : ranges) { |