From 4dbf1994a63d3c7a8e9ca90237b1bbcf08fd01bd Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 24 Jun 2018 00:45:54 -0400 Subject: [PATCH] Deduplicated the default text column parameters across platforms. --- common/table.h | 1 + common/tablemodel.c | 4 ++++ darwin/tablecolumn.m | 25 ++++++++++++------------- unix/table.c | 7 +------ windows/table.cpp | 6 +----- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/common/table.h b/common/table.h index 3c603674..21ce2d11 100644 --- a/common/table.h +++ b/common/table.h @@ -11,6 +11,7 @@ extern uiTableValueType uiprivTableModelColumnType(uiTableModel *m, int column); extern int uiprivTableModelNumRows(uiTableModel *m); extern uiTableValue *uiprivTableModelCellValue(uiTableModel *m, int row, int column); extern void uiprivTableModelSetCellValue(uiTableModel *m, int row, int column, const uiTableValue *value); +extern const uiTableTextColumnOptionalParams uiprivDefaultTextColumnOptionalParams; #ifdef __cplusplus } diff --git a/common/tablemodel.c b/common/tablemodel.c index c7c52a3f..b1cd1e89 100644 --- a/common/tablemodel.c +++ b/common/tablemodel.c @@ -42,3 +42,7 @@ void uiprivTableModelSetCellValue(uiTableModel *m, int row, int column, const ui mh = uiprivTableModelHandler(m); (*(mh->SetCellValue))(mh, m, row, column, value); } + +const uiTableTextColumnOptionalParams uiprivDefaultTextColumnOptionalParams = { + .ColorModelColumn = -1, +}; diff --git a/darwin/tablecolumn.m b/darwin/tablecolumn.m index d37daf8a..5547336d 100644 --- a/darwin/tablecolumn.m +++ b/darwin/tablecolumn.m @@ -51,10 +51,6 @@ static BOOL isCellEditable(uiTableModel *m, NSInteger row, int modelColumn) return editable != 0; } -static uiTableTextColumnOptionalParams defaultTextColumnOptionalParams = { - .ColorModelColumn = -1, -}; - struct textColumnCreateParams { uiTable *t; uiTableModel *m; @@ -623,9 +619,10 @@ void uiTableAppendTextColumn(uiTable *t, const char *name, int textModelColumn, p.makeTextField = YES; p.textModelColumn = textModelColumn; p.textEditableColumn = textEditableModelColumn; - if (params == NULL) - params = &defaultTextColumnOptionalParams; - p.textParams = *params; + if (params != NULL) + p.textParams = *params; + else + p.textParams = uiprivDefaultTextColumnOptionalParams; str = [NSString stringWithUTF8String:name]; col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p]; @@ -665,9 +662,10 @@ void uiTableAppendImageTextColumn(uiTable *t, const char *name, int imageModelCo p.makeTextField = YES; p.textModelColumn = textModelColumn; p.textEditableColumn = textEditableModelColumn; - if (textParams == NULL) - textParams = &defaultTextColumnOptionalParams; - p.textParams = *textParams; + if (textParams != NULL) + p.textParams = *textParams; + else + p.textParams = uiprivDefaultTextColumnOptionalParams; p.makeImage = YES; p.imageModelColumn = imageModelColumn; @@ -711,9 +709,10 @@ void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxM p.makeTextField = YES; p.textModelColumn = textModelColumn; p.textEditableColumn = textEditableModelColumn; - if (textParams == NULL) - textParams = &defaultTextColumnOptionalParams; - p.textParams = *textParams; + if (textParams != NULL) + p.textParams = *textParams; + else + p.textParams = uiprivDefaultTextColumnOptionalParams; p.makeCheckbox = YES; p.checkboxModelColumn = checkboxModelColumn; diff --git a/unix/table.c b/unix/table.c index cd9734d3..8fae7960 100644 --- a/unix/table.c +++ b/unix/table.c @@ -87,11 +87,6 @@ static void onEdited(uiTableModel *m, int column, const char *pathstr, const uiT uiprivTableModelSetCellValue(m, row, column, tvalue); } -// TODO deduplicate this between platforms -static uiTableTextColumnOptionalParams defaultTextColumnOptionalParams = { - .ColorModelColumn = -1, -}; - struct textColumnParams { uiTable *t; uiTableModel *m; @@ -282,7 +277,7 @@ static void addTextColumn(uiTable *t, GtkTreeViewColumn *c, int textModelColumn, if (params != NULL) p->params = *params; else - p->params = defaultTextColumnOptionalParams; + p->params = uiprivDefaultTextColumnOptionalParams; r = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(c, r, TRUE); diff --git a/windows/table.cpp b/windows/table.cpp index 372a699b..801f65d0 100644 --- a/windows/table.cpp +++ b/windows/table.cpp @@ -7,10 +7,6 @@ // - implement keyboard accessibility // - implement accessibility in general (Dynamic Annotations maybe?) -static uiTableTextColumnOptionalParams defaultTextColumnOptionalParams = { - /*TODO.ColorModelColumn = */-1, -}; - uiTableModel *uiNewTableModel(uiTableModelHandler *mh) { uiTableModel *m; @@ -401,7 +397,7 @@ static uiprivTableColumnParams *appendColumn(uiTable *t, const char *name, int c p = uiprivNew(uiprivTableColumnParams); p->textModelColumn = -1; p->textEditableColumn = -1; - p->textParams = defaultTextColumnOptionalParams; + p->textParams = uiprivDefaultTextColumnOptionalParams; p->imageModelColumn = -1; p->checkboxModelColumn = -1; p->checkboxEditableColumn = -1;