From 66cd3542bc8e727450c9f1ff7976e16057d74e80 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 18 Oct 2015 18:05:38 -0400 Subject: [PATCH] Reworked the table model system a bit. --- common/GNUmakeinc.mk | 1 - common/tablesubscriptions.c | 54 ------------------------------------- ui.h | 28 ++++++++----------- 3 files changed, 11 insertions(+), 72 deletions(-) delete mode 100644 common/tablesubscriptions.c diff --git a/common/GNUmakeinc.mk b/common/GNUmakeinc.mk index aea8e601..e7fb9522 100644 --- a/common/GNUmakeinc.mk +++ b/common/GNUmakeinc.mk @@ -7,7 +7,6 @@ CFILES += \ common/menu.c \ common/ptrarray.c \ common/shouldquit.c \ - common/tablesubscriptions.c \ common/types.c HFILES += \ diff --git a/common/tablesubscriptions.c b/common/tablesubscriptions.c deleted file mode 100644 index 1089890a..00000000 --- a/common/tablesubscriptions.c +++ /dev/null @@ -1,54 +0,0 @@ -// 18 october 2015 -#include "../ui.h" -#include "uipriv.h" - -struct uiTableSubscriptions { - struct ptrArray *tables; -}; - -uiTableSubscriptions *uiTableNewSubscriptions(void) -{ - uiTableSubscriptions *s; - - s = uiNew(uiTableSubscriptions); - s->tables = newPtrArray(); - return s; -} - -void uiTableFreeSubscriptions(uiTableSubscriptions *s) -{ - ptrArrayDestroy(s->tables); - uiFree(s); -} - -// TODO make more robust: complain if table already subscribed -void uiTableSubscriptionsSubscribe(uiTableSubscriptions *s, uiTable *t) -{ - ptrArrayAppend(s->tables, t); -} - -void uiTableSubscriptionsUnsubscribe(uiTableSubscriptions *s, uiTable *t) -{ - uintmax_t i; - uiTable *table; - - for (i = 0; i < s->tables->len; i++) { - table = ptrArrayIndex(s->tables, uiTable *, i); - if (table == t) { - ptrArrayDelete(s->tables, i); - return; - } - } - complain("attempt to unsubscribe table that isn't subscribed in uiTableSubscriptionsUnsubscribe()"); -} - -void uiTableSubscriptionsNotify(uiTableSubscriptions *s, uiTableNotification n, intmax_t row, intmax_t column) -{ - uintmax_t i; - uiTable *table; - - for (i = 0; i < s->tables->len; i++) { - table = ptrArrayIndex(s->tables, uiTable *, i); - tableNotify(table, n, row, column); - } -} diff --git a/ui.h b/ui.h index 0fa85840..68d79e3b 100644 --- a/ui.h +++ b/ui.h @@ -517,15 +517,15 @@ struct uiAreaKeyEvent { typedef struct uiTable uiTable; typedef struct uiTableModel uiTableModel; +typedef struct uiTableModelSpec uiTableModelSpec; typedef struct uiTableColumnParams uiTableColumnParams; typedef enum uiTableColumnType uiTableColumnType; -typedef struct uiTableSubscriptions uiTableSubscriptions; typedef enum uiTableNotification uiTableNotification; _UI_EXTERN uintmax_t uiMenuItemType(void); #define uiArea(this) ((uiArea *) uiIsA((this), uiAreaType(), 1)) -_UI_EXTERN void uiTableSetModel(uiTable *, uiTableModel *); -_UI_EXTERN void uiTableAppendColumn(uiTable *, uiTableColumnParams *); +_UI_EXTERN void uiTableSetModel(uiTable *t, uiTableModel *m); +_UI_EXTERN void uiTableAppendColumn(uiTable *t, uiTableColumnParams *p); _UI_EXTERN uiTable *uiNewTable(void); enum uiTableColumnType { @@ -534,15 +534,10 @@ enum uiTableColumnType { uiTableColumnCheckbox, }; -struct uiTableModel { - void (*Subscribe)(uiTableModel *m, uiTable *t); - void (*Unsubscribe)(uiTableModel *m, uiTable *t); - intmax_t (*NumColumns)(uiTableModel *m); - uiTableColumnType (*ColumnType)(uiTableModel *m, intmax_t column); - intmax_t (*NumRows)(uiTableModel *m); - void *(*CellValue)(uiTableModel *m, intmax_t row, intmax_t column); - int (*ColumnMutable)(uiTableModel *m, intmax_t column); - void (*SetCellValue)(uiTableModel *m, intmax_t row, intmax_t column, void *value); +struct uiTableModelSpec { + intmax_t (*NumRows)(uiTableModel *m, void *mData); + void *(*CellValue)(uiTableModel *m, void *mData, intmax_t row, intmax_t column); + void (*SetCellValue)(uiTableModel *m, void *mData, intmax_t row, intmax_t column, void *value); }; enum uiTableNotification { @@ -552,17 +547,16 @@ enum uiTableNotification { uiTableCellChanged, }; -_UI_EXTERN uiTableSubscriptions *uiTableNewSubscriptions(void); -_UI_EXTERN void uiTableFreeSubscriptions(uiTableSubscriptions *s); -_UI_EXTERN void uiTableSubscriptionsSubscribe(uiTableSubscriptions *s, uiTable *t); -_UI_EXTERN void uiTableSubscriptionsUnsubscribe(uiTableSubscriptions *s, uiTable *t); -_UI_EXTERN void uiTableSubscriptionsNotify(uiTableSubscriptions *s, uiTableNotification n, intmax_t row, intmax_t column); +_UI_EXTERN uiTableModel *uiNewTableModel(uintmax_t nCols, uiTableColumnType *types, uiTableModelSpec *spec, void *mData); +_UI_EXTERN void uiFreeTableModel(uiTableModel *m); +_UI_EXTERN void uiTableModelNotify(uiTableModel *m, uiTableNotification notification, intmax_t row, intmax_t column); #define uiTableModelFromBool(b) ((void *) (b)) _UI_EXTERN void *uiTableModelFromString(const char *str); struct uiTableColumnParams { const char *Name; + int Mutable; // TODO move to the model? intmax_t ValueColumn; // TODO background color };