diff -r 88bc21b19213 -r 097f45f9c1fa ui/winui/list.cpp --- a/ui/winui/list.cpp Fri Oct 20 16:34:33 2023 +0200 +++ b/ui/winui/list.cpp Sun Nov 26 15:44:28 2023 +0100 @@ -45,6 +45,7 @@ using namespace Microsoft::UI::Xaml::Media; using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; + UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args) { UiObject* current = uic_current_obj(obj); @@ -211,114 +212,6 @@ return widget; } - -extern "C" static void destroy_ui_pathbar(void* ptr) { - UiPathBar* pb = (UiPathBar*)ptr; - delete pb; -} - -static void ui_context_add_pathbar_destructor(UiContext* ctx, UiPathBar* pb) { - cxMempoolRegister(ctx->mp, pb, destroy_ui_pathbar); -} - -UIEXPORT UIWIDGET ui_pathbar_create(UiObject* obj, UiPathBarArgs args) { - UiObject* current = uic_current_obj(obj); - - // create view and toolkit wrapper - Border pathbar = Border(); - - IInspectable bgRes = Application::Current().Resources().Lookup(box_value(L"TextControlBackground")); - IInspectable borderThicknessRes = Application::Current().Resources().Lookup(box_value(L"TextControlBorderThemeThickness")); - IInspectable borderBrushRes = Application::Current().Resources().Lookup(box_value(L"TextControlBorderBrush")); - // IInspectable cornerRes = Application::Current().Resources().Lookup(box_value(L"TextControlCornerRadius")); - - Brush bgBrush = unbox_value(bgRes); - Thickness border = unbox_value(borderThicknessRes); - Brush borderBrush = unbox_value(borderBrushRes); - CornerRadius cornerRadius = { 4, 4, 4, 4 }; //unbox_value(cornerRes); - - pathbar.Background(bgBrush); - pathbar.BorderBrush(borderBrush); - pathbar.BorderThickness(border); - pathbar.CornerRadius(cornerRadius); - - Grid content = Grid(); - pathbar.Child(content); - - GridLength gl; - gl.Value = 1; - gl.GridUnitType = GridUnitType::Star; - - ColumnDefinition coldef = ColumnDefinition(); - coldef.Width(gl); - content.ColumnDefinitions().Append(coldef); - - TextBox pathTextBox = TextBox(); - Thickness t = { 0, 0, 0, 0 }; - CornerRadius c = { 0 ,0, 0, 0 }; - pathTextBox.BorderThickness(t); - //pathTextBox.CornerRadius(c); - - - pathTextBox.HorizontalAlignment(HorizontalAlignment::Stretch); - content.SetColumn(pathTextBox, 0); - - content.Children().Append(pathTextBox); - - // stackpanel for buttons - StackPanel buttons = StackPanel(); - buttons.Orientation(Orientation::Horizontal); - buttons.Visibility(Visibility::Collapsed); - content.SetColumn(buttons, 0); - content.Children().Append(buttons); - - if (args.ontextinput) { - // TODO - } - - //pathTextBox.Visibility(Visibility::Collapsed); - - UiPathBar* uipathbar = new UiPathBar; - ui_context_add_pathbar_destructor(current->ctx, uipathbar); - uipathbar->grid = content; - uipathbar->buttons = buttons; - uipathbar->textbox = pathTextBox; - uipathbar->obj = obj; - uipathbar->enabledrag = args.enabledrag; - uipathbar->enabledrop = args.enabledrop; - uipathbar->getvalue = args.getvalue; - uipathbar->model = args.model; - uipathbar->onactivate = args.onactivate; - uipathbar->onactivatedata = args.onactivatedata; - uipathbar->ondragstart = args.ondragstart; - uipathbar->ondragstartdata = args.ondragstartdata; - uipathbar->ondragcomplete = args.ondragcomplete; - uipathbar->ondragcompletedata = args.ondragcompletedata; - uipathbar->ondrop = args.ondrop; - uipathbar->ondropdata = args.ondropsdata; - - UIElement elm = pathbar; - UiWidget* widget = new UiWidget(elm); - widget->data1 = uipathbar; - ui_context_add_widget_destructor(current->ctx, widget); - - // bind var - UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); - if (var) { - UiList* list = (UiList*)var->value; - list->update = ui_pathbar_update; - list->obj = widget; - ui_pathbar_update(list, 0); - } - - // add listview to current container - UI_APPLY_LAYOUT1(current, args); - - current->container->Add(pathbar, false); - - return widget; -} - static void* getstrvalue(void* elm, int ignore) { return elm; } @@ -383,71 +276,6 @@ bar.ItemsSource(items); } -static void ui_pathbar_clear(StackPanel &buttons) { - for (int i = buttons.Children().Size() - 1; i >= 0; i--) { - buttons.Children().RemoveAt(i); - } -} - -extern "C" void ui_pathbar_update(UiList * list, int i) { - UiWidget* widget = (UiWidget*)list->obj; - UiPathBar* pb = (UiPathBar*)widget->data1; - Grid grid = pb->grid; - - UiModel* model = pb->model; - ui_getvaluefunc getvalue = pb->getvalue; - - // priority: getvalue, model.getvalue, getstrvalue (fallback) - if (getvalue == nullptr) { - if (model && model->getvalue) { - getvalue = model->getvalue; - } - else { - getvalue = getstrvalue; - } - } - - // hide textbox, show button panel - pb->textbox.Visibility(Visibility::Collapsed); - pb->buttons.Visibility(Visibility::Visible); - - // clear old buttons - ui_pathbar_clear(pb->buttons); - - // 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); - Button button = Button(); - 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); - button.CornerRadius(c); - - pb->buttons.Children().Append(button); - - j++; - elm = list->next(list); - } -} - std::vector ui_create_listview_selection(ListView listview) { std::vector selection;