From f02fbd2ecf95619c9ad33827c6559c520d6a45df Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 23 Jun 2016 09:56:24 -0400 Subject: [PATCH] Some more API cleanup. Don't separate table cell parts from columns. --- common/table.c | 4 +--- darwin/table.m | 37 +++++++++---------------------------- test/page16.c | 4 ++-- uitable.h | 6 +----- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/common/table.c b/common/table.c index d65c557e..c2190b3b 100644 --- a/common/table.c +++ b/common/table.c @@ -5,10 +5,8 @@ uiTableColumn *uiTableAppendTextColumn(uiTable *t, const char *name, int modelColumn) { uiTableColumn *tc; - uiTableCellPart *part; - part = uiNewTableTextPart(modelColumn); tc = uiTableAppendColumn(t, name); - uiTableColumnAppend(tc, part, 1); + uiTableColumnAppendTextPart(tc, modelColumn, 1); return tc; } diff --git a/darwin/table.m b/darwin/table.m index 08dc5e09..4e046a86 100644 --- a/darwin/table.m +++ b/darwin/table.m @@ -17,7 +17,7 @@ enum { @interface tablePart : NSObject @property int type; -@property int mainColumn; +@property int textColumn; @property int expand; - (NSView *)mkView:(uiTableModel *)m row:(int)row; @end @@ -32,12 +32,6 @@ struct uiTableModel { NSMutableArray *tables; }; -// TODO better memory management for this -// note how expand is part of this -struct uiTableCellPart { - tablePart *part; -}; - struct uiTableColumn { tableColumn *c; NSMutableArray *parts; @@ -141,7 +135,7 @@ done: NSView *view; NSTextField *tf; - data = (*(m->mh->CellValue))(m->mh, m, row, self.mainColumn); + data = (*(m->mh->CellValue))(m->mh, m, row, self.textColumn); switch (self.type) { case partText: str = toNSString((char *) data); @@ -233,28 +227,15 @@ void uiTableModelRowDeleted(uiTableModel *m, int oldIndex) // set is autoreleased } -void uiTableColumnAppend(uiTableColumn *c, uiTableCellPart *part, int expand) +void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand) { - part->part.expand = expand; - [c->parts addObject:part->part]; -} + tablePart *part; -uiTableCellPart *uiNewTableTextPart(int modelColumn) -{ - uiTableCellPart *p; - - p = uiNew(uiTableCellPart); - p->part = [tablePart new]; - p->part.type = partText; - p->part.mainColumn = modelColumn; - return p; -} - -void uiFreeTableCellPart(uiTableCellPart *p) -{ - // TODO disallow if in use - [p->part release]; - uiFree(p); + part = [tablePart new]; + part.type = partText; + part.textColumn = modelColumn; + part.expand = expand; + [c->parts addObject:part]; } uiDarwinControlAllDefaultsExceptDestroy(uiTable, sv) diff --git a/test/page16.c b/test/page16.c index 929dda91..f210f89b 100644 --- a/test/page16.c +++ b/test/page16.c @@ -61,8 +61,8 @@ uiBox *makePage16(void) uiTableAppendTextColumn(t, "Column 1", 0); tc = uiTableAppendColumn(t, "Column 2"); - uiTableColumnAppend(tc, uiNewTableTextPart(1), 0); - uiTableColumnAppend(tc, uiNewTableTextPart(2), 1); + uiTableColumnAppendTextPart(tc, 1, 0); + uiTableColumnAppendTextPart(tc, 2, 1); return page16; } diff --git a/uitable.h b/uitable.h index 4b7d5cf7..fc0e5ad5 100644 --- a/uitable.h +++ b/uitable.h @@ -26,12 +26,8 @@ _UI_EXTERN void uiTableModelRowDeleted(uiTableModel *m, int oldIndex); // TODO reordering/moving typedef struct uiTableColumn uiTableColumn; -typedef struct uiTableCellPart uiTableCellPart; -_UI_EXTERN void uiTableColumnAppend(uiTableColumn *c, uiTableCellPart *part, int expand); - -_UI_EXTERN uiTableCellPart *uiNewTableTextPart(int modelColumn); -_UI_EXTERN void uiFreeTableCellPart(uiTableCellPart *p); +_UI_EXTERN void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand); typedef struct uiTable uiTable; #define uiTable(this) ((uiTable *) (this))