Fri, 09 Feb 2024 15:45:02 +0100
add getter for list selections (Common, WinUI3)
ui/common/types.c | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/ui/tree.h | file | annotate | diff | comparison | revisions | |
ui/winui/table.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/table.h | file | annotate | diff | comparison | revisions |
--- 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 };
--- 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);
--- 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
--- 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;