# HG changeset patch # User Olaf Wintermann # Date 1707489902 -3600 # Node ID 22257f5f40193a2985724e0a3110c28a31ed4a90 # Parent 4b21af9d8c5a6d309fe86c355c469014d73ecaae add getter for list selections (Common, WinUI3) diff -r 4b21af9d8c5a -r 22257f5f4019 ui/common/types.c --- a/ui/common/types.c Thu Feb 08 10:17:59 2024 +0100 +++ b/ui/common/types.c Fri Feb 09 15:45:02 2024 +0100 @@ -104,6 +104,7 @@ list->iter = NULL; list->update = NULL; + list->getselection = NULL; list->obj = NULL; if(name) { @@ -458,6 +459,18 @@ } +UIEXPORT UiListSelection ui_list_getselection(UiList *list) { + if (list->getselection) { + return list->getselection(list); + } + return (UiListSelection){ 0, NULL }; +} + +UIEXPORT void ui_listselection_free(UiListSelection selection) { + if (selection.rows) { + free(selection.rows); + } +} UIEXPORT UiStr ui_str(char *cstr) { return (UiStr) { cstr, NULL }; diff -r 4b21af9d8c5a -r 22257f5f4019 ui/ui/toolkit.h --- a/ui/ui/toolkit.h Thu Feb 08 10:17:59 2024 +0100 +++ b/ui/ui/toolkit.h Fri Feb 09 15:45:02 2024 +0100 @@ -157,6 +157,8 @@ typedef struct UiFileList UiFileList; +typedef struct UiListSelection UiListSelection; + /* begin opaque types */ typedef struct UiContext UiContext; typedef struct UiContainer UiContainer; @@ -329,8 +331,9 @@ /* private - implementation dependent */ void *data; - /* binding function */ + /* binding functions */ void (*update)(UiList *list, int i); + UiListSelection (*getselection)(UiList *list); /* binding object */ void *obj; @@ -338,6 +341,19 @@ UiObserver *observers; }; + +struct UiListSelection { + /* + * number of selected items + */ + int count; + + /* + * indices of selected rows + */ + int *rows; +}; + struct UiRange { double (*get)(UiRange *range); void (*set)(UiRange *range, double value); @@ -462,6 +478,8 @@ UIEXPORT void ui_list_addobsv(UiList *list, ui_callback f, void *data); UIEXPORT void ui_list_notify(UiList *list); +UIEXPORT UiListSelection ui_list_getselection(UiList *list); + UIEXPORT UiFileList ui_filelist_copy(UiFileList list); UIEXPORT void ui_filelist_free(UiFileList list); @@ -477,7 +495,7 @@ - +UIEXPORT void ui_listselection_free(UiListSelection *selection); UIEXPORT UiIcon* ui_icon(const char* name, size_t size); UIEXPORT UiIcon* ui_imageicon(const char* file); diff -r 4b21af9d8c5a -r 22257f5f4019 ui/ui/tree.h --- a/ui/ui/tree.h Thu Feb 08 10:17:59 2024 +0100 +++ b/ui/ui/tree.h Fri Feb 09 15:45:02 2024 +0100 @@ -37,7 +37,6 @@ typedef struct UiModel UiModel; typedef struct UiListCallbacks UiListCallbacks; -typedef struct UiListSelection UiListSelection; typedef struct UiListDnd UiListDnd; typedef struct UiListArgs UiListArgs; @@ -95,18 +94,6 @@ void *userdata; }; -struct UiListSelection { - /* - * number of selected items - */ - int count; - - /* - * indices of selected rows - */ - int *rows; -}; - struct UiListDnd { UiListSelection selection; UiDnD *dnd; @@ -150,11 +137,10 @@ UIEXPORT UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs args); UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args); - -void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...); -void ui_table_dragsource_a(UIWIDGET tablewidget, int actions, char **targets, int nelm); -void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...); -void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm); +void ui_table_dragsource_deprecated(UIWIDGET tablewidget, int actions, char *target0, ...); +void ui_table_dragsource_a_deprecated(UIWIDGET tablewidget, int actions, char **targets, int nelm); +void ui_table_dragdest_deprecated(UIWIDGET tablewidget, int actions, char *target0, ...); +void ui_table_dragdest_a_deprecated(UIWIDGET tablewidget, int actions, char **targets, int nelm); #ifdef __cplusplus diff -r 4b21af9d8c5a -r 22257f5f4019 ui/winui/table.cpp --- a/ui/winui/table.cpp Thu Feb 08 10:17:59 2024 +0100 +++ b/ui/winui/table.cpp Fri Feb 09 15:45:02 2024 +0100 @@ -111,6 +111,7 @@ if (var) { UiList* list = (UiList*)var->value; list->update = ui_table_update; + list->getselection = ui_table_selection; list->obj = uitable; uitable->update(list, 0); } @@ -134,6 +135,11 @@ table->update(list, i); } +extern "C" UiListSelection ui_table_selection(UiList * list) { + UiTable* table = (UiTable*)list->obj; + return table->uiselection(); +} + UiTable::UiTable(UiObject *obj, winrt::Microsoft::UI::Xaml::Controls::ScrollViewer scrollW, winrt::Microsoft::UI::Xaml::Controls::Grid grid) { this->obj = obj; diff -r 4b21af9d8c5a -r 22257f5f4019 ui/winui/table.h --- a/ui/winui/table.h Thu Feb 08 10:17:59 2024 +0100 +++ b/ui/winui/table.h Fri Feb 09 15:45:02 2024 +0100 @@ -95,3 +95,4 @@ extern "C" void ui_table_update(UiList * list, int i); +extern "C" UiListSelection ui_table_selection(UiList * list);