Sat, 13 Dec 2025 12:52:38 +0100
merge
--- a/application/main.c Sat Dec 13 12:51:57 2025 +0100 +++ b/application/main.c Sat Dec 13 12:52:38 2025 +0100 @@ -1254,7 +1254,14 @@ //UiModel *model = ui_model(obj->ctx, UI_STRING, "Name", UI_STRING, "Email", -1); //ui_table(obj, .fill = TRUE, .varname = "persons", .model = model, .getvalue = person_getvalue, .onselection = list_onselection); //ui_model_free(obj->ctx, model); - ui_dropdown(obj, .varname = "persons", .getvalue = person_getvalue, .onactivate = list_onselection, .hexpand = TRUE, .hfill = TRUE); + //ui_dropdown(obj, .varname = "persons", .getvalue = person_getvalue, .onactivate = list_onselection, .hexpand = TRUE, .hfill = TRUE); + char *list[] = { + "test 1", + "test 2", + "test 3", + "test 4" + }; + ui_dropdown(obj, .static_elements = list, .static_nelm = 4); ui_button(obj, .label = "Test 1"); ui_newline(obj);
--- a/ui/common/properties.c Sat Dec 13 12:51:57 2025 +0100 +++ b/ui/common/properties.c Sat Dec 13 12:52:38 2025 +0100 @@ -234,7 +234,7 @@ // try creating the parent int err = ui_mkdir(parent); if(err) { - fprintf(stderr, "Error: Cannot create directory %s: %s\n", strerror(errno)); + fprintf(stderr, "Error: Cannot create directory %s: %s\n", parent, strerror(errno)); free(parent); free(dir); return; @@ -290,7 +290,7 @@ int ret = 0; CxMapIterator i = cxMapIterator(application_properties); cx_foreach(CxMapEntry *, entry, i) { - fprintf(file, "%.*s = %s\n", (int)entry->key->len, entry->key->data, entry->value); + fprintf(file, "%.*s = %s\n", (int)entry->key->len, (char*)entry->key->data, (char*)entry->value); } cxMapRehash(application_properties);
--- a/ui/ui/list.h Sat Dec 13 12:51:57 2025 +0100 +++ b/ui/ui/list.h Sat Dec 13 12:52:38 2025 +0100 @@ -332,7 +332,9 @@ UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject *obj, UiListArgs *args); UIEXPORT void ui_listview_select(UIWIDGET listview, int index); +UIEXPORT int ui_listview_selection(UIWIDGET listview); UIEXPORT void ui_dropdown_select(UIWIDGET dropdown, int index); +UIEXPORT int ui_dropdown_selection(UIWIDGET dropdown); UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args);
--- a/ui/win32/list.c Sat Dec 13 12:51:57 2025 +0100 +++ b/ui/win32/list.c Sat Dec 13 12:52:38 2025 +0100 @@ -166,18 +166,30 @@ UiList *list = listview->var->value; list->obj = listview; list->update = ui_listview_update; - list->getselection = ui_listview_getselection; - list->setselection = ui_listview_setselection; + list->getselection = ui_listview_getselection_impl; + list->setselection = ui_listview_setselection_impl; ui_listview_update(list, -1); + } else if (!table && args->static_elements && args->static_nelm > 0) { + char **static_elements = args->static_elements; + size_t static_nelm = args->static_nelm; + LVITEM item; + item.mask = LVIF_TEXT; + item.iSubItem = 0; + for (int i=0;i<static_nelm;i++) { + item.iItem = i; + item.pszText = static_elements[i]; + ListView_InsertItem(hwnd, &item); + } + listview->getvalue = strmodel_getvalue; + listview->getvaluedata = NULL; } return (W32Widget*)listview; } -static UiListSelection listview_get_selection(UiListView *listview) { +static UiListSelection listview_get_selection2(HWND hwnd) { UiListSelection sel = { 0, NULL }; - HWND hwnd = listview->widget.hwnd; CX_ARRAY_DECLARE(int, indices); cx_array_initialize(indices, 8); @@ -195,6 +207,11 @@ return sel; } +static UiListSelection listview_get_selection(UiListView *listview) { + HWND hwnd = listview->widget.hwnd; + return listview_get_selection2(hwnd); +} + // listview class event proc int ui_listview_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { UiListView *listview = (UiListView*)widget; @@ -327,12 +344,12 @@ } } -UiListSelection ui_listview_getselection(UiList *list) { +UiListSelection ui_listview_getselection_impl(UiList *list) { UiListView *listview = (UiListView*)list->obj; return listview_get_selection(listview); } -void ui_listview_setselection(UiList *list, UiListSelection selection) { +void ui_listview_setselection_impl(UiList *list, UiListSelection selection) { } @@ -346,6 +363,20 @@ return listview_create(obj, args, TRUE); } +void ui_listview_select(UIWIDGET listview, int index) { + +} + +int ui_listview_selection(UIWIDGET listview) { + W32Widget *w = (W32Widget*)listview; + UiListSelection sel = listview_get_selection2(w->hwnd); + int index = -1; + if (sel.count > 0) { + index = sel.rows[0]; + } + free(sel.rows); + return index; +} /* ------------------------------------ DropDown ------------------------------------*/ @@ -383,13 +414,20 @@ UiList *list = dropdown->var->value; list->obj = dropdown; list->update = ui_dropdown_update; - list->getselection = ui_dropdown_getselection; - list->setselection = ui_dropdown_setselection; + list->getselection = ui_dropdown_getselection_impl; + list->setselection = ui_dropdown_setselection_impl; ui_dropdown_update(list, -1); + } else if (args->static_elements && args->static_nelm > 0) { + char **static_elements = args->static_elements; + size_t static_nelm = args->static_nelm; + for (int i=0;i<static_nelm;i++) { + SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)static_elements[i]); + } + dropdown->getvalue = strmodel_getvalue; + dropdown->getvaluedata = NULL; } - return (W32Widget*)dropdown; } @@ -437,7 +475,7 @@ } } -UiListSelection ui_dropdown_getselection(UiList *list) { +UiListSelection ui_dropdown_getselection_impl(UiList *list) { UiListSelection sel = { 0, NULL }; UiListView *listview = (UiListView*)list->obj; int index = (int)SendMessage(listview->widget.hwnd, CB_GETCURSEL, 0, 0); @@ -449,7 +487,15 @@ return sel; } -void ui_dropdown_setselection(UiList *list, UiListSelection selection) { +void ui_dropdown_setselection_impl(UiList *list, UiListSelection selection) { UiListView *listview = (UiListView*)list->obj; SendMessage(listview->widget.hwnd, CB_SETCURSEL, 0, 0); } + +void ui_dropdown_select(UIWIDGET dropdown, int index) { + SendMessage(dropdown->hwnd, CB_SETCURSEL, 0, 0); +} + +int ui_dropdown_selection(UIWIDGET dropdown) { + return SendMessage(dropdown->hwnd, CB_GETCURSEL, 0, 0); +}
--- a/ui/win32/list.h Sat Dec 13 12:51:57 2025 +0100 +++ b/ui/win32/list.h Sat Dec 13 12:52:38 2025 +0100 @@ -66,15 +66,15 @@ W32Size ui_listview_get_preferred_size(W32Widget *widget); void ui_listview_update(UiList *list, int row); -UiListSelection ui_listview_getselection(UiList *list); -void ui_listview_setselection(UiList *list, UiListSelection selection); +UiListSelection ui_listview_getselection_impl(UiList *list); +void ui_listview_setselection_impl(UiList *list, UiListSelection selection); int ui_dropdown_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); W32Size ui_dropdown_get_preferred_size(W32Widget *widget); void ui_dropdown_update(UiList *list, int row); -UiListSelection ui_dropdown_getselection(UiList *list); -void ui_dropdown_setselection(UiList *list, UiListSelection selection); +UiListSelection ui_dropdown_getselection_impl(UiList *list); +void ui_dropdown_setselection_impl(UiList *list, UiListSelection selection); #ifdef __cplusplus }
--- a/ui/win32/window.c Sat Dec 13 12:51:57 2025 +0100 +++ b/ui/win32/window.c Sat Dec 13 12:52:38 2025 +0100 @@ -111,11 +111,11 @@ } UiObject *ui_window(const char *title) { - return create_window(title, window_data, FALSE); + return create_window(title, FALSE); } UiObject *ui_simple_window(const char *title) { - return create_window(title, window_data, TRUE); + return create_window(title, TRUE); } int ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {