# HG changeset patch # User Olaf Wintermann # Date 1706616616 -3600 # Node ID c51dd0e9ecb7e613400f6328ab561b8e1faa308d # Parent 9335e9bbc1677476278faab3dc32c836e27d1eda add support for table string values, that need to be freed diff -r 9335e9bbc167 -r c51dd0e9ecb7 ui/common/types.c --- a/ui/common/types.c Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/common/types.c Tue Jan 30 13:10:16 2024 +0100 @@ -456,3 +456,13 @@ l->update = NULL; l->obj = NULL; } + + + +UiStr ui_str(char *cstr) { + return (UiStr) { cstr, NULL }; +} + +UiStr ui_str_free(char *str, void (*freefunc)(void *v)) { + return (UiStr) { str, freefunc }; +} diff -r 9335e9bbc167 -r c51dd0e9ecb7 ui/ui/toolkit.h --- a/ui/ui/toolkit.h Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/ui/toolkit.h Tue Jan 30 13:10:16 2024 +0100 @@ -474,6 +474,10 @@ UIEXPORT UiIcon* ui_foldericon(size_t size); UIEXPORT UiIcon* ui_fileicon(size_t size); + +UiStr ui_str(char *cstr); +UiStr ui_str_free(char *str, void (*free)(void *v)); + #ifdef __cplusplus } #endif diff -r 9335e9bbc167 -r c51dd0e9ecb7 ui/ui/tree.h --- a/ui/ui/tree.h Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/ui/tree.h Tue Jan 30 13:10:16 2024 +0100 @@ -44,9 +44,11 @@ typedef enum UiModelType { UI_STRING = 0, + UI_STRING_FREE, UI_INTEGER, UI_ICON, UI_ICON_TEXT, + UI_ICON_TEXT_FREE } UiModelType; struct UiModel { @@ -154,6 +156,7 @@ void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...); void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm); + #ifdef __cplusplus } #endif diff -r 9335e9bbc167 -r c51dd0e9ecb7 ui/ui/window.h --- a/ui/ui/window.h Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/ui/window.h Tue Jan 30 13:10:16 2024 +0100 @@ -38,6 +38,8 @@ UIEXPORT UiObject* ui_window(const char *title, void *window_data); UIEXPORT UiObject* ui_simplewindow(char *title, void *window_data); +UIEXPORT void ui_window_size(UiObject *obj, int width, int height); + char* ui_openfiledialog(UiObject *obj); char* ui_savefiledialog(UiObject *obj); diff -r 9335e9bbc167 -r c51dd0e9ecb7 ui/winui/pch.h --- a/ui/winui/pch.h Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/winui/pch.h Tue Jan 30 13:10:16 2024 +0100 @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -35,5 +36,4 @@ #include #include - #include diff -r 9335e9bbc167 -r c51dd0e9ecb7 ui/winui/table.cpp --- a/ui/winui/table.cpp Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/winui/table.cpp Tue Jan 30 13:10:16 2024 +0100 @@ -410,12 +410,17 @@ // depending on the type, we create different cell controls UiModelType type = model->types[col]; switch (type) { + case UI_STRING_FREE: case UI_STRING: { TextBlock cell = TextBlock(); cell.Padding(cellpadding); cell.VerticalAlignment(VerticalAlignment::Stretch); - textblock_set_str(cell, (char*)getvalue(elm, model_col)); + char *val = (char*)getvalue(elm, model_col); + textblock_set_str(cell, val); cellBorder.Child(cell); + if (type == UI_STRING_FREE && val) { + free(val); + } break; } @@ -438,6 +443,7 @@ } break; } + case UI_ICON_TEXT_FREE: case UI_ICON_TEXT: { StackPanel cellPanel = StackPanel(); cellPanel.Spacing(2); @@ -455,6 +461,9 @@ textblock_set_str(cell, str); cellPanel.Children().Append(cell); cellBorder.Child(cellPanel); + if (type == UI_ICON_TEXT_FREE && str) { + free(str); + } break; } } diff -r 9335e9bbc167 -r c51dd0e9ecb7 ui/winui/window.cpp --- a/ui/winui/window.cpp Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/winui/window.cpp Tue Jan 30 13:10:16 2024 +0100 @@ -175,3 +175,13 @@ return obj; } + +void ui_window_size(UiObject *obj, int width, int height) { + UIWINDOW win = obj->wobj; + if (win) { + winrt::Windows::Graphics::SizeInt32 wsize; + wsize.Width = width; + wsize.Height = height; + win->window.AppWindow().Resize(wsize); + } +}