Sun, 10 Nov 2024 15:30:46 +0100
update toolkit
--- a/application/config.c Sun Nov 10 09:12:30 2024 +0100 +++ b/application/config.c Sun Nov 10 15:30:46 2024 +0100 @@ -36,7 +36,6 @@ #include <libxml/tree.h> #include "config.h" -#include "pwd.h" #include "system.h" #include <libidav/utils.h>
--- a/application/main.c Sun Nov 10 09:12:30 2024 +0100 +++ b/application/main.c Sun Nov 10 15:30:46 2024 +0100 @@ -38,6 +38,7 @@ #include "application.h" #include "system.h" + int idav_main(int argc, char **argv) { sys_init(); ui_init("idav", argc, argv);
--- a/application/settings.c Sun Nov 10 09:12:30 2024 +0100 +++ b/application/settings.c Sun Nov 10 15:30:46 2024 +0100 @@ -636,7 +636,7 @@ wdata->obj = obj; settings_init(obj, wdata); - ui_tabview(obj) { + ui_tabview(obj, .tabview = UI_TABVIEW_NAVIGATION_TOP) { ui_tab(obj, "General") { ui_grid(obj, .margin = 10) { ui_label(obj, .label = "TODO"); @@ -768,6 +768,7 @@ ui_passwordfield(obj, .value = wdata->credentials_password, .hexpand = TRUE, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); ui_newline(obj); + ui_label(obj, .label = " "); ui_newline(obj); @@ -777,7 +778,12 @@ ui_newline(obj); ui_hbox(obj, .colspan = 2, .vexpand = TRUE, .hexpand = TRUE, .spacing = 10) { - ui_listview(obj, .list = wdata->credentials_locations, .onactivate = credentials_location_edit, .onselection = credentials_location_onselect, .colspan = 2, .fill = UI_ON, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); +#ifndef UI_WINUI + ui_callback credentials_activate_callback = credentials_location_edit; +#else + ui_callback credentials_activate_callback = NULL; +#endif + ui_listview(obj, .list = wdata->credentials_locations, .onactivate = credentials_activate_callback, .onselection = credentials_location_onselect, .colspan = 2, .fill = UI_ON, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); ui_vbox(obj, .fill = UI_OFF, .spacing = 4) { ui_button(obj, .label = "Add", .onclick = credentials_location_add, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED)); ui_button(obj, .label = "Edit", .onclick = credentials_location_edit, .groups = UI_GROUPS(SETTINGS_STATE_CREDENTIALS_SELECTED, SETTINGS_STATE_CREDENTIALS_LOCATION_SELECTED));
--- a/ui/common/properties.c Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/common/properties.c Sun Nov 10 15:30:46 2024 +0100 @@ -32,6 +32,9 @@ #include <sys/stat.h> #include <errno.h> +#include "../ui/toolkit.h" + + #include "properties.h" #include <cx/string.h> #include <cx/buffer.h> @@ -48,11 +51,12 @@ #endif -char* ui_getappdir() { + +char* ui_getappdir(void) { if(ui_appname() == NULL) { return NULL; } - + return ui_configfile(NULL); } @@ -296,4 +300,3 @@ } return cxMapGet(language, name); } -
--- a/ui/common/toolbar.c Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/common/toolbar.c Sun Nov 10 15:30:46 2024 +0100 @@ -37,6 +37,7 @@ static UiToolbarMenuItem* ui_appmenu; + void uic_toolbar_init(void) { toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); toolbar_defaults[0] = cxLinkedListCreateSimple(CX_STORE_POINTERS);
--- a/ui/common/types.c Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/common/types.c Sun Nov 10 15:30:46 2024 +0100 @@ -37,6 +37,8 @@ #include "types.h" #include "context.h" + + UiObserver* ui_observer_new(ui_callback f, void *data) { UiObserver *observer = malloc(sizeof(UiObserver)); observer->callback = f;
--- a/ui/ui/image.h Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/ui/image.h Sun Nov 10 15:30:46 2024 +0100 @@ -58,7 +58,7 @@ UIEXPORT UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args); -int ui_image_load_file(UiGeneric *obj, const char *path); +UIEXPORT int ui_image_load_file(UiGeneric *obj, const char *path); #ifdef __cplusplus }
--- a/ui/ui/text.h Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/ui/text.h Sun Nov 10 15:30:46 2024 +0100 @@ -116,12 +116,12 @@ #define ui_textarea(obj, ...) ui_textarea_create(obj, (UiTextAreaArgs) { __VA_ARGS__ }) -UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args); +UIEXPORT UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args); -UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea); +UIEXPORT UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea); -void ui_text_undo(UiText *value); -void ui_text_redo(UiText *value); +UIEXPORT void ui_text_undo(UiText *value); +UIEXPORT void ui_text_redo(UiText *value); #define ui_textfield(obj, ...) ui_textfield_create(obj, (UiTextFieldArgs) { __VA_ARGS__ }) #define ui_frameless_textfield(obj, ...) ui_frameless_field_create(obj, (UiTextFieldArgs) { __VA_ARGS__ })
--- a/ui/ui/toolkit.h Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/ui/toolkit.h Sun Nov 10 15:30:46 2024 +0100 @@ -543,7 +543,7 @@ UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v)); -UIEXPORT char* ui_getappdir(); +UIEXPORT char* ui_getappdir(void); UIEXPORT char* ui_configfile(char *name); UIEXPORT UiCondVar* ui_condvar_create(void);
--- a/ui/winui/button.cpp Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/button.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -56,12 +56,17 @@ icon = NULL; } - if (label && icon) { + IconElement icon_elm = { nullptr }; + if (icon) { + icon_elm = ui_get_icon(icon); + } + + if (label && icon_elm) { StackPanel panel = StackPanel(); panel.Orientation(Orientation::Horizontal); panel.Spacing(5); - panel.Children().Append(ui_get_icon(icon)); + panel.Children().Append(icon_elm); wchar_t* wlabel = str2wstr(label, nullptr); TextBlock label = TextBlock(); @@ -76,7 +81,7 @@ button.Content(box_value(wlabel)); free(wlabel); } - else if (icon) { + else if (icon_elm) { button.Content(ui_get_icon(icon)); } } @@ -287,7 +292,7 @@ // get or create the group name static int groupCount = 0; winrt::hstring groupName; - if (radioButtons->size == 0) { + if (cxListSize(radioButtons) == 0) { groupName = winrt::to_hstring(groupCount++); } else { UiWidget* firstButtonWidget = (UiWidget*)cxListAt(radioButtons, 0);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/condvar.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -0,0 +1,65 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2024 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "pch.h" +#include "condvar.h" + + + +UiCondVar* ui_condvar_create(void) { + UiWinCondVar *var = new UiWinCondVar(); + var->var.data = NULL; + var->var.intdata = 0; + var->set = 0; + return (UiCondVar*)var; +} + +void ui_condvar_wait(UiCondVar *var) { + UiWinCondVar *p = (UiWinCondVar*)var; + std::unique_lock<std::mutex> lock(p->mutex); + + if(!p->set) { + p->cond.wait(lock); + } + p->set = 0; +} + +void ui_condvar_signal(UiCondVar *var, void *data, int intdata) { + UiWinCondVar *p = (UiWinCondVar*)var; + std::unique_lock<std::mutex> lock(p->mutex); + p->var.data = data; + p->var.intdata = intdata; + p->set = 1; + lock.unlock(); + p->cond.notify_one(); +} + +void ui_condvar_destroy(UiCondVar *var) { + UiWinCondVar *p = (UiWinCondVar*)var; + delete p; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/condvar.h Sun Nov 10 15:30:46 2024 +0100 @@ -0,0 +1,55 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2024 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UI_WIN_CONDVAR_H +#define UI_WIN_CONDVAR_H + +#include "toolkit.h" + +#include <queue> +#include <mutex> +#include <condition_variable> + +#ifdef __cplusplus +extern "C" { +#endif + +struct UiWinCondVar { + UiCondVar var; + int set; + std::mutex mutex; + std::condition_variable cond; +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* UI_WIN_CONDVAR_H */ +
--- a/ui/winui/container.cpp Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/container.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -1,30 +1,30 @@ /* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2023 Olaf Wintermann. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +* +* Copyright 2023 Olaf Wintermann. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ #include "pch.h" @@ -122,7 +122,7 @@ gl.Value = 0; gl.GridUnitType = GridUnitType::Auto; } - + control.HorizontalAlignment(HorizontalAlignment::Stretch); control.VerticalAlignment(VerticalAlignment::Stretch); @@ -179,13 +179,24 @@ void UiGridContainer::Add(FrameworkElement control, UiBool fill) { GridLength gl; - int hexpand = FALSE; - int vexpand = FALSE; + bool hexpand = false; + bool vexpand = false; + bool hfill = false; + bool vfill = false; + if(layout.fill != UI_LAYOUT_UNDEFINED) { + fill = ui_lb2bool(layout.fill); + } if (layout.hexpand != UI_LAYOUT_UNDEFINED) { hexpand = layout.hexpand; + hfill = true; } if (layout.vexpand != UI_LAYOUT_UNDEFINED) { vexpand = layout.vexpand; + vfill = true; + } + if (fill) { + hfill = true; + vfill = true; } // create new RowDefinition for the new line @@ -203,6 +214,11 @@ } rowdef.Height(gl); grid.RowDefinitions().Append(rowdef); + } else if (vexpand) { + // adjust row + gl.GridUnitType = GridUnitType::Star; + gl.Value = 1; + grid.RowDefinitions().GetAt(y).Height(gl); } // create new columndefinition, if a new column is added @@ -219,11 +235,42 @@ coldef.Width(gl); grid.ColumnDefinitions().Append(coldef); cols++; + } else if(hexpand) { + // adjust column + if (layout.colspan == 0) { + gl.GridUnitType = GridUnitType::Star; + gl.Value = 1; + grid.ColumnDefinitions().GetAt(x).Width(gl); + } else { + int adjust_col = x; + bool adjust = true; + for (int i = 0; i < layout.colspan; i++) { + if (grid.ColumnDefinitions().Size() == x + i) { + break; + } + adjust_col = x + i; + GridLength w = grid.ColumnDefinitions().GetAt(adjust_col).Width(); + if (w.GridUnitType == GridUnitType::Star) { + adjust = false; + break; + } + } + + if (adjust) { + gl.GridUnitType = GridUnitType::Star; + gl.Value = 1; + grid.ColumnDefinitions().GetAt(adjust_col).Width(gl); + } + } } // add control - control.HorizontalAlignment(HorizontalAlignment::Stretch); - control.VerticalAlignment(VerticalAlignment::Stretch); + if (hfill) { + control.HorizontalAlignment(HorizontalAlignment::Stretch); + } + if (vfill) { + control.VerticalAlignment(VerticalAlignment::Stretch); + } if (layout.colspan > 0) { grid.SetColumnSpan(control, layout.colspan); @@ -277,7 +324,7 @@ frame.SetColumn(label, 0); frame.Children().Append(label); } - + // workarea frame frame.RowDefinitions().Append(rowdefFrame); @@ -460,16 +507,24 @@ return newobj; } +static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) { + Pivot pivot = Pivot(); + UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args); + + return tabview; +} + UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) { this->current = obj; this->pivot = pivot; + this->subcontainer = args.subcontainer; this->margin = args.margin; this->spacing = args.spacing; this->columnspacing = args.columnspacing; this->rowspacing = args.rowspacing; } -UiObject* UiPivotTabView::AddTab(const char* label) { +UiObject* UiPivotTabView::AddTab(const char* label, int index) { TextBlock text = TextBlock(); wchar_t* wlabel = str2wstr(label, nullptr); winrt::hstring hstr(wlabel); @@ -487,27 +542,110 @@ return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); } +void UiPivotTabView::Remove(int index) { + pivot.Items().RemoveAt(index); +} + +void UiPivotTabView::Select(int index) { + +} + FrameworkElement UiPivotTabView::GetFrameworkElement() { return pivot; } -static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) { - Pivot pivot = Pivot(); - UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args); + +static UiTabView* tabview_invisible_create(UiObject *obj, UiTabViewArgs args) { + Grid container = Grid(); + container.HorizontalAlignment(HorizontalAlignment::Stretch); + container.VerticalAlignment(VerticalAlignment::Stretch); + UiInvisibleTabView *tabview = new UiInvisibleTabView(obj, container, args); + return tabview; +} + +UiInvisibleTabView::UiInvisibleTabView(UiObject* obj, Grid container, UiTabViewArgs args) { + this->current = obj; + this->container = container; + this->subcontainer = args.subcontainer; + this->margin = args.margin; + this->spacing = args.spacing; + this->columnspacing = args.columnspacing; + this->rowspacing = args.rowspacing; + this->currentIndex = -1; + + GridLength gl; + gl.GridUnitType = GridUnitType::Star; + gl.Value = 1; + + ColumnDefinition coldef = ColumnDefinition(); + coldef.Width(gl); + container.ColumnDefinitions().Append(coldef); + + RowDefinition rowdef = RowDefinition(); + rowdef.Height(gl); + container.RowDefinitions().Append(rowdef); +} - return tabview; +UiObject* UiInvisibleTabView::AddTab(const char* label, int index) { + Grid subcontainer = Grid(); + subcontainer.HorizontalAlignment(HorizontalAlignment::Stretch); + subcontainer.VerticalAlignment(VerticalAlignment::Stretch); + + if (pages.size() == 0) { + container.Children().Append(subcontainer); + currentIndex = 0; + } + + if (index < 0) { + pages.push_back(subcontainer); + } else { + pages.insert(pages.begin() + index, subcontainer); + } + + // sub container + return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); +} + +void UiInvisibleTabView::Remove(int index) { + +} + +void UiInvisibleTabView::Select(int index) { + if (index >= 0 && index < pages.size()) { + if (currentIndex != -1) { + container.Children().RemoveAt(0); + } + + container.Children().Append(pages.at(index)); + } +} + +FrameworkElement UiInvisibleTabView::GetFrameworkElement() { + return container; +} + + +static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { + TabView tabview = TabView(); + tabview.IsAddTabButtonVisible(false); + //tabview.CanDragTabs(false); + //tabview.CanReorderTabs(false); + UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); + + return uitabview; } UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) { this->current = obj; this->tabview = tabview; + this->subcontainer = args.subcontainer; this->margin = args.margin; this->spacing = args.spacing; this->columnspacing = args.columnspacing; this->rowspacing = args.rowspacing; } -UiObject* UiMainTabView::AddTab(const char* label) { +UiObject* UiMainTabView::AddTab(const char* label, int index) { TextBlock text = TextBlock(); wchar_t* wlabel = str2wstr(label, nullptr); winrt::hstring hstr(wlabel); @@ -527,18 +665,26 @@ return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); } +void UiMainTabView::Remove(int index) { + this->tabview.TabItems().RemoveAt(index); +} + +void UiMainTabView::Select(int index) { + +} + FrameworkElement UiMainTabView::GetFrameworkElement() { return tabview; } -static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { - TabView tabview = TabView(); - tabview.IsAddTabButtonVisible(false); - //tabview.CanDragTabs(false); - //tabview.CanReorderTabs(false); - UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); - return uitabview; +static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { + NavigationView navigationview = NavigationView(); + UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); + navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); + navigationview.IsSettingsVisible(false); + + return tabview; } UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) { @@ -557,7 +703,7 @@ navigationview.SelectionChanged({ this, &UiNavigationTabView::SelectionChanged }); } -UiObject* UiNavigationTabView::AddTab(const char* label) { +UiObject* UiNavigationTabView::AddTab(const char* label, int index1) { TextBlock text = TextBlock(); wchar_t* wlabel = str2wstr(label, nullptr); winrt::hstring hstr(wlabel); @@ -581,6 +727,15 @@ return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); } +void UiNavigationTabView::Remove(int index) { + navigationview.MenuItems().RemoveAt(index); + pages.erase(pages.begin() + index); +} + +void UiNavigationTabView::Select(int index) { + +} + FrameworkElement UiNavigationTabView::GetFrameworkElement() { return navigationview; } @@ -596,13 +751,13 @@ } } -static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { - NavigationView navigationview = NavigationView(); - UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); - navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); - navigationview.IsSettingsVisible(false); +static int64_t ui_tabview_get(UiInteger *i) { + return 0; +} - return tabview; +static void ui_tabview_set(UiInteger *i, int64_t value) { + UiTabView *tabview = (UiTabView*)i->obj; + tabview->Select(value); } UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) { @@ -629,6 +784,10 @@ tabview = tabview_pivot_create(obj, args); break; } + case UI_TABVIEW_INVISIBLE: { + tabview = tabview_invisible_create(obj, args); + break; + } } UiTabViewContainer* ctn = new UiTabViewContainer(tabview); @@ -642,6 +801,17 @@ ui_context_add_widget_destructor(current->ctx, widget); widget->data1 = tabview; + // TODO: add tabview destructor + + // bind variable + UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); + if (var) { + UiInteger *i = (UiInteger*)var->value; + i->obj = tabview; + i->get = ui_tabview_get; + i->set = ui_tabview_set; + } + UiObject* newobj = uic_object_new(obj, widget); newobj->container = ctn; uic_obj_add(obj, newobj); @@ -656,12 +826,59 @@ uic_obj_add(current, newobj); } +UIEXPORT void ui_tabview_select(UIWIDGET tabview, int tab) { + UiTabView* t = (UiTabView*)tabview->data1; + t->Select(tab); +} + +UIEXPORT void ui_tabview_remove(UIWIDGET tabview, int tab) { + UiTabView* t = (UiTabView*)tabview->data1; + t->Remove(tab); +} + +UIEXPORT UiObject* ui_tabview_add(UIWIDGET tabview, const char *name, int tab_index) { + UiTabView* t = (UiTabView*)tabview->data1; + UiObject* newobj = t->AddTab(name, tab_index); + return newobj; +} + + + +// --------------------- UI Headerbar --------------------- + +// TODO: replace placeholder implementation + +UIEXPORT UIWIDGET ui_headerbar_create(UiObject *obj, UiHeaderbarArgs args) { + UiContainerArgs boxargs = { }; + boxargs.fill = UI_OFF; + return ui_hbox_create(obj, boxargs); +} + +UIEXPORT void ui_headerbar_start_create(UiObject *obj) { + UiContainerArgs boxargs = { }; + boxargs.fill = UI_OFF; + ui_hbox_create(obj, boxargs); +} + +UIEXPORT void ui_headerbar_center_create(UiObject *obj) { + UiContainerArgs boxargs = { }; + boxargs.fill = UI_OFF; + ui_hbox_create(obj, boxargs); +} + +UIEXPORT void ui_headerbar_end_create(UiObject *obj) { + UiContainerArgs boxargs = { }; + boxargs.fill = UI_OFF; + ui_hbox_create(obj, boxargs); +} + + /* - * -------------------- Layout Functions -------------------- - * - * functions for setting layout attributes for the current container - * - */ +* -------------------- Layout Functions -------------------- +* +* functions for setting layout attributes for the current container +* +*/ void ui_layout_fill(UiObject* obj, UiBool fill) { UiContainer* ct = uic_get_current_container(obj); @@ -678,14 +895,14 @@ ct->layout.vexpand = expand; } -void ui_layout_hfill(UiObject *obj, UiBool fill) { - UiContainer *ct = uic_get_current_container(obj); - ct->layout.hfill = fill; +void ui_layout_hfill(UiObject* obj, UiBool fill) { + UiContainer* ct = uic_get_current_container(obj); + ct->layout.hfill = fill; } -void ui_layout_vfill(UiObject *obj, UiBool fill) { - UiContainer *ct = uic_get_current_container(obj); - ct->layout.vfill = fill; +void ui_layout_vfill(UiObject* obj, UiBool fill) { + UiContainer* ct = uic_get_current_container(obj); + ct->layout.vfill = fill; } void ui_layout_width(UiObject* obj, int width) {
--- a/ui/winui/container.h Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/container.h Sun Nov 10 15:30:46 2024 +0100 @@ -67,6 +67,8 @@ char* label; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int width; int height; int colspan; @@ -120,8 +122,9 @@ int columnspacing; int rowspacing; - virtual UiObject* AddTab(const char* label) = 0; - + virtual UiObject* AddTab(const char* label, int index = -1) = 0; + virtual void Remove(int index) = 0; + virtual void Select(int index) = 0; virtual FrameworkElement GetFrameworkElement() = 0; }; @@ -138,7 +141,9 @@ UiPivotTabView(UiObject *obj, Pivot pivot, UiTabViewArgs args); - UiObject* AddTab(const char* label); + UiObject* AddTab(const char* label, int index = -1); + void Remove(int index); + void Select(int index); FrameworkElement GetFrameworkElement(); }; @@ -147,7 +152,9 @@ UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args); - UiObject* AddTab(const char* label); + UiObject* AddTab(const char* label, int index = -1); + void Remove(int index); + void Select(int index); FrameworkElement GetFrameworkElement(); }; @@ -158,8 +165,23 @@ UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type); - UiObject* AddTab(const char* label); + UiObject* AddTab(const char* label, int index = -1); + void Remove(int index); + void Select(int index); FrameworkElement GetFrameworkElement(); void SelectionChanged(NavigationView const& sender, NavigationViewSelectionChangedEventArgs const& args); }; + +struct UiInvisibleTabView : UiTabView { + Grid container; + std::vector<FrameworkElement> pages; + int currentIndex; + + UiInvisibleTabView(UiObject *obj, Grid container, UiTabViewArgs args); + + UiObject* AddTab(const char* label, int index = -1); + void Remove(int index); + void Select(int index); + FrameworkElement GetFrameworkElement(); +}; \ No newline at end of file
--- a/ui/winui/icons.cpp Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/icons.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -29,6 +29,7 @@ #include "pch.h" #include "icons.h" +#include "../ui/icons.h" #include <stdlib.h> #include <string.h>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/image.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -0,0 +1,124 @@ +/* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +* +* Copyright 2024 Olaf Wintermann. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "pch.h" + +#include "image.h" + +#include "toolkit.h" +#include "container.h" +#include "../common/object.h" +#include "../common/context.h" +#include "util.h" + +using namespace winrt; +using namespace Microsoft::UI::Xaml; +using namespace Microsoft::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Interop; +using namespace winrt::Windows::Foundation; +using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; +using namespace winrt::Microsoft::UI::Xaml::Media::Imaging; +using namespace winrt::Microsoft::UI::Xaml::Media; + +UiImageSource::UiImageSource(winrt::Microsoft::UI::Xaml::Media::ImageSource& src) : imgsrc(src) {} + +UIEXPORT UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args) { + UiObject* current = uic_current_obj(obj); + + Image image = Image(); + FrameworkElement elm = image; + if (args.scrollarea) { + ScrollViewer scroll = ScrollViewer(); + scroll.Content(image); + elm = scroll; + } + + // create toolkit wrapper object and register destructor + UIElement uielm = image; + UiWidget* widget = new UiWidget(uielm); + ui_context_add_widget_destructor(current->ctx, widget); + + // bind variable + UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_GENERIC); + if (var) { + UiGeneric *value = (UiGeneric*)var->value; + value->obj = widget; + value->get = ui_image_get; + value->set = ui_image_set; + } + + // add button to current container + UI_APPLY_LAYOUT1(current, args); + + current->container->Add(elm, true); + + return widget; +} + +extern "C" void* ui_image_get(UiGeneric *g) { + + + return NULL; +} + +extern "C" int ui_image_set(UiGeneric *g, void *data, const char *type) { + if(!type || strcmp(type, UI_IMAGE_OBJECT_TYPE)) { + return 1; + } + + UiImageSource *imgdata = (UiImageSource*)data; + if (g->value) { + UiImageSource *prevData = (UiImageSource*)g->value; + delete prevData; + } + g->value = imgdata; + + UiWidget* widget = (UiWidget*)g->obj; + Image image = widget->uielement.as<Image>(); + image.Source(imgdata->imgsrc); + + return 0; +} + +UIEXPORT int ui_image_load_file(UiGeneric *obj, const char *path) { + wchar_t* wpath = str2wstr(path, nullptr); + std::wstring wPath = wpath; + std::wstring uriPath = L"file:///" + wPath; + Uri uri{ uriPath }; + + BitmapImage bitmapImage = BitmapImage(); + bitmapImage.UriSource(uri); + ImageSource src = bitmapImage; + + UiImageSource *imgdata = new UiImageSource(src); + obj->set(obj, imgdata, UI_IMAGE_OBJECT_TYPE); + + free(wpath); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/image.h Sun Nov 10 15:30:46 2024 +0100 @@ -0,0 +1,43 @@ +/* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +* +* Copyright 2024 Olaf Wintermann. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include "../ui/toolkit.h" +#include "../ui/image.h" + +class UiImageSource { +public: + winrt::Microsoft::UI::Xaml::Media::ImageSource imgsrc { nullptr }; + + UiImageSource(winrt::Microsoft::UI::Xaml::Media::ImageSource& src); +}; + + +extern "C" void* ui_image_get(UiGeneric *g); +extern "C" int ui_image_set(UiGeneric *g, void *data, const char *type);
--- a/ui/winui/list.cpp Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/list.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -70,7 +70,10 @@ if (var) { UiList* list = (UiList*)var->value; list->update = ui_simple_list_update; + list->getselection = ui_listview_getselection; + list->setselection = ui_listview_setselection; list->obj = widget; + ui_simple_list_update(list, 0); } @@ -138,6 +141,8 @@ if (var) { UiList* list = (UiList*)var->value; list->update = ui_simple_list_update; + list->getselection = ui_dropdown_getselection; + list->setselection = ui_dropdown_setselection; list->obj = widget; ui_simple_list_update(list, 0); } @@ -169,6 +174,51 @@ return widget; } +UiListSelection ui_listview_getselection(UiList *list) { + UiWidget *widget = (UiWidget*)list->obj; + ListView listview = widget->uielement.as<ListView>(); + std::vector<int> selectedRows = ui_create_listview_selection(listview); + + UiListSelection selection = { NULL, 0 }; + if (selectedRows.size() > 0) { + selection.count = selectedRows.size(); + int *data = selectedRows.data(); + selection.rows = (int*)calloc(selection.count, sizeof(int)); + memcpy(selection.rows, data, selection.count); + } + + return selection; +} + +void ui_listview_setselection(UiList *list, UiListSelection selection) { + UiWidget* widget = (UiWidget*)list->obj; + if (selection.count > 0) { + ListView listview = widget->uielement.as<ListView>(); + listview.SelectedIndex(selection.rows[0]); + } +} + +UiListSelection ui_dropdown_getselection(UiList *list) { + UiWidget* widget = (UiWidget*)list->obj; + ComboBox cb = widget->uielement.as<ComboBox>(); + int index = cb.SelectedIndex(); + UiListSelection selection = { NULL, 0 }; + if (index >= 0) { + selection.rows = (int*)calloc(1, sizeof(int)); + selection.count = 1; + selection.rows[0] = index; + } + return selection; +} + +void ui_dropdown_setselection(UiList *list, UiListSelection selection) { + UiWidget* widget = (UiWidget*)list->obj; + if (selection.count > 0) { + ComboBox cb = widget->uielement.as<ComboBox>(); + cb.SelectedIndex(selection.rows[0]); + } +} + UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args) { UiObject* current = uic_current_obj(obj);
--- a/ui/winui/list.h Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/list.h Sun Nov 10 15:30:46 2024 +0100 @@ -40,3 +40,8 @@ std::vector<int> ui_create_listview_selection(winrt::Microsoft::UI::Xaml::Controls::ListView listview); +extern "C" UiListSelection ui_listview_getselection(UiList *list); +extern "C" void ui_listview_setselection(UiList *list, UiListSelection selection); + +extern "C" UiListSelection ui_dropdown_getselection(UiList *list); +extern "C" void ui_dropdown_setselection(UiList *list, UiListSelection selection);
--- a/ui/winui/packages.config Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/packages.config Sun Nov 10 15:30:46 2024 +0100 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Microsoft.Windows.CppWinRT" version="2.0.220929.3" targetFramework="native" /> - <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220914.1" targetFramework="native" /> - <package id="Microsoft.Windows.SDK.BuildTools" version="10.0.22621.755" targetFramework="native" /> - <package id="Microsoft.WindowsAppSDK" version="1.3.230602002" targetFramework="native" /> + <package id="Microsoft.Windows.CppWinRT" version="2.0.240405.15" targetFramework="native" /> + <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240803.1" targetFramework="native" /> + <package id="Microsoft.Windows.SDK.BuildTools" version="10.0.26100.1742" targetFramework="native" /> + <package id="Microsoft.WindowsAppSDK" version="1.5.241001000" targetFramework="native" /> </packages> \ No newline at end of file
--- a/ui/winui/text.cpp Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/text.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -51,6 +51,93 @@ using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; using namespace winrt::Windows::UI::Xaml::Input; + +UIEXPORT UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) { + UiObject* current = uic_current_obj(obj); + + // create textarea and toolkit wrapper + RichEditBox textarea = RichEditBox(); + UIElement elm = textarea; + UiWidget* widget = new UiWidget(elm); + ui_context_add_widget_destructor(current->ctx, widget); + + UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_TEXT); + if (var) { + UiText* value = (UiText*)var->value; + value->obj = widget; + value->undomgr = NULL; + value->set = ui_textarea_set; + value->get = ui_textarea_get; + value->getsubstr = ui_textarea_getsubstr; + value->insert = ui_textarea_insert; + value->setposition = ui_textarea_setposition; + value->position = ui_textarea_position; + value->selection = ui_textarea_selection; + value->length = ui_textarea_length; + value->remove = ui_textarea_remove; + } + + // add textarea to current container + UI_APPLY_LAYOUT1(current, args); + + current->container->Add(textarea, true); + + return widget; +} + +UIEXPORT UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { + return textarea; +} + +UIEXPORT void ui_text_undo(UiText *value) { + +} + +UIEXPORT void ui_text_redo(UiText *value) { + +} + + + +extern "C" char* ui_textarea_get(UiText *text) { + return NULL; +} + +extern "C" void ui_textarea_set(UiText *text, const char *newvalue) { + +} + +extern "C" char* ui_textarea_getsubstr(UiText *text, int begin, int end) { + return NULL; +} + +extern "C" void ui_textarea_insert(UiText *text, int pos, char *str) { + +} + +extern "C" void ui_textarea_setposition(UiText *text, int pos) { + +} + +extern "C" int ui_textarea_position(UiText *text) { + return 0; +} + +extern "C" void ui_textarea_selection(UiText *text, int *begin, int *end) { + +} + +extern "C" int ui_textarea_length(UiText *text) { + return 0; +} + +extern "C" void ui_textarea_remove(UiText *text, int begin, int end) { + +} + + + + UIWIDGET ui_textfield_create(UiObject* obj, UiTextFieldArgs args) { UiObject* current = uic_current_obj(obj); @@ -71,7 +158,7 @@ // TODO: } - // add button to current container + // add textfield to current container UI_APPLY_LAYOUT1(current, args); current->container->Add(textfield, false); @@ -103,7 +190,7 @@ // TODO: } - // add button to current container + // add textfield to current container UI_APPLY_LAYOUT1(current, args); current->container->Add(textfield, false);
--- a/ui/winui/text.h Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/text.h Sun Nov 10 15:30:46 2024 +0100 @@ -63,6 +63,16 @@ char* ui_wstring_get(UiString* str, std::wstring& value); std::wstring ui_wstring_set(UiString* str, const char* value); +extern "C" char* ui_textarea_get(UiText *text); +extern "C" void ui_textarea_set(UiText *text, const char *newvalue); +extern "C" char* ui_textarea_getsubstr(UiText*, int, int); +extern "C" void ui_textarea_insert(UiText*, int, char*); +extern "C" void ui_textarea_setposition(UiText*,int); +extern "C" int ui_textarea_position(UiText*); +extern "C" void ui_textarea_selection(UiText*, int*, int*); +extern "C" int ui_textarea_length(UiText*); +extern "C" void ui_textarea_remove(UiText*, int, int); + extern "C" char* ui_textfield_get(UiString *str); extern "C" void ui_textfield_set(UiString *str, const char *newvalue);
--- a/ui/winui/toolkit.cpp Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/toolkit.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -235,17 +235,9 @@ } void ui_close(UiObject* obj) { - -} - -static void ui_job_finished(UiJob *job) { - UiEvent event; - event.obj = job->obj; - event.window = job->obj->window; - event.document = job->obj->ctx->document; - event.intval = 0; - event.eventdata = NULL; - job->finish_callback(&event, job->finish_data); + if (obj->wobj) { + obj->wobj->window.Close(); + } } static void ui_job_thread(UiJob* job) {
--- a/ui/winui/window.cpp Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/window.cpp Sun Nov 10 15:30:46 2024 +0100 @@ -65,12 +65,14 @@ UiObject* ui_window(const char* title, void* window_data) { UiObject* obj = ui_simple_window(title, window_data); + /* if (uic_get_menu_list()) { // create/add menubar MenuBar mb = ui_create_menubar(obj); mb.VerticalAlignment(VerticalAlignment::Top); obj->container->Add(mb, false); } + */ if (uic_toolbar_isenabled()) { // create a grid for the toolbar: ColumnDefinitions="Auto, *, Auto" @@ -109,14 +111,14 @@ CxList* def_r = uic_get_toolbar_defaults(UI_TOOLBAR_RIGHT); bool addappmenu = true; - if (def_r->size > 0) { + if (cxListSize(def_r) > 0) { CommandBar toolbar_r = ui_create_toolbar(obj, def_r, addappmenu); toolbar_grid.SetColumn(toolbar_r, 2); toolbar_grid.SetRow(toolbar_r, 0); toolbar_grid.Children().Append(toolbar_r); addappmenu = false; } - if (def_c->size > 0) { + if (cxListSize(def_c) > 0) { CommandBar toolbar_c = ui_create_toolbar(obj, def_c, addappmenu); toolbar_c.HorizontalAlignment(HorizontalAlignment::Center); toolbar_grid.SetColumn(toolbar_c, 1); @@ -124,7 +126,7 @@ toolbar_grid.Children().Append(toolbar_c); addappmenu = false; } - if (def_l->size > 0) { + if (cxListSize(def_l) > 0) { CommandBar toolbar_l = ui_create_toolbar(obj, def_l, addappmenu); toolbar_grid.SetColumn(toolbar_l, 0); toolbar_grid.SetRow(toolbar_l, 0); @@ -199,6 +201,10 @@ return obj; } +UIEXPORT UiObject* ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs args) { + return NULL; +} + void ui_window_size(UiObject *obj, int width, int height) { UIWINDOW win = obj->wobj; if (win) { @@ -226,7 +232,8 @@ } TextBox textfield{ nullptr }; - if (args.input) { + PasswordBox password{ nullptr }; + if(args.input || args.password) { StackPanel panel = StackPanel(); panel.Orientation(Orientation::Vertical); if (args.content) { @@ -237,13 +244,19 @@ free(str); } - textfield = TextBox(); Thickness margin = { 0, 5, 0, 0 }; - textfield.Margin(margin); + if (args.password) { + password = PasswordBox(); + password.Margin(margin); + panel.Children().Append(password); + } else { + textfield = TextBox(); + textfield.Margin(margin); + panel.Children().Append(textfield); + } + panel.Margin(margin); - panel.Children().Append(textfield); - dialog.Content(panel); } else { @@ -286,7 +299,11 @@ evt.intval = 2; } - if (args.input) { + if (args.password) { + std::wstring wstr(password.Password()); + char *text = wchar2utf8(wstr.c_str(), wstr.length()); + evt.eventdata = text; + } else if (args.input) { std::wstring wstr(textfield.Text()); char *text = wchar2utf8(wstr.c_str(), wstr.length()); evt.eventdata = text;
--- a/ui/winui/winui.vcxproj Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/winui.vcxproj Sun Nov 10 15:30:46 2024 +0100 @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230602002\build\native\Microsoft.WindowsAppSDK.props" Condition="Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230602002\build\native\Microsoft.WindowsAppSDK.props')" /> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.props" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.props')" /> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.props')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.props" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.props')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props')" /> + <Import Project="..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.props" Condition="Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.props')" /> <PropertyGroup Label="Globals"> <CppWinRTOptimized>true</CppWinRTOptimized> <CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge> @@ -119,6 +119,7 @@ <ClInclude Include="..\ui\dnd.h" /> <ClInclude Include="..\ui\entry.h" /> <ClInclude Include="..\ui\graphics.h" /> + <ClInclude Include="..\ui\icons.h" /> <ClInclude Include="..\ui\image.h" /> <ClInclude Include="..\ui\menu.h" /> <ClInclude Include="..\ui\properties.h" /> @@ -133,9 +134,11 @@ <ClInclude Include="appmenu.h" /> <ClInclude Include="button.h" /> <ClInclude Include="commandbar.h" /> + <ClInclude Include="condvar.h" /> <ClInclude Include="container.h" /> <ClInclude Include="dnd.h" /> <ClInclude Include="icons.h" /> + <ClInclude Include="image.h" /> <ClInclude Include="label.h" /> <ClInclude Include="list.h" /> <ClInclude Include="pch.h" /> @@ -160,9 +163,11 @@ <ClCompile Include="appmenu.cpp" /> <ClCompile Include="button.cpp" /> <ClCompile Include="commandbar.cpp" /> + <ClCompile Include="condvar.cpp" /> <ClCompile Include="container.cpp" /> <ClCompile Include="dnd.cpp" /> <ClCompile Include="icons.cpp" /> + <ClCompile Include="image.cpp" /> <ClCompile Include="label.cpp" /> <ClCompile Include="list.cpp" /> <ClCompile Include="pch.cpp"> @@ -239,21 +244,21 @@ </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.targets')" /> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.targets')" /> - <Import Project="..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230602002\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230602002\build\native\Microsoft.WindowsAppSDK.targets')" /> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" /> + <Import Project="..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.targets')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.targets')" /> </ImportGroup> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <PropertyGroup> <ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText> </PropertyGroup> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.props'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.targets'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.props'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.targets'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230602002\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230602002\build\native\Microsoft.WindowsAppSDK.props'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230602002\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.3.230602002\build\native\Microsoft.WindowsAppSDK.targets'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.props'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.targets'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.props'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.targets'))" /> </Target> </Project> \ No newline at end of file
--- a/ui/winui/winui.vcxproj.filters Sun Nov 10 09:12:30 2024 +0100 +++ b/ui/winui/winui.vcxproj.filters Sun Nov 10 15:30:46 2024 +0100 @@ -27,6 +27,8 @@ <ClCompile Include="icons.cpp" /> <ClCompile Include="label.cpp" /> <ClCompile Include="dnd.cpp" /> + <ClCompile Include="condvar.cpp" /> + <ClCompile Include="image.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="pch.h" /> @@ -95,6 +97,11 @@ <ClInclude Include="icons.h" /> <ClInclude Include="label.h" /> <ClInclude Include="dnd.h" /> + <ClInclude Include="condvar.h" /> + <ClInclude Include="image.h" /> + <ClInclude Include="..\ui\icons.h"> + <Filter>public</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Image Include="Assets\Wide310x150Logo.scale-200.png">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/winui.vcxproj.user Sun Nov 10 15:30:46 2024 +0100 @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup /> +</Project> \ No newline at end of file