diff --git a/common/table.h b/common/table.h index 21ce2d11..a7e2d8ff 100644 --- a/common/table.h +++ b/common/table.h @@ -12,6 +12,7 @@ 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; +extern int uiprivTableModelCellEditable(uiTableModel *m, int row, int column); #ifdef __cplusplus } diff --git a/common/tablemodel.c b/common/tablemodel.c index b1cd1e89..e1de4896 100644 --- a/common/tablemodel.c +++ b/common/tablemodel.c @@ -46,3 +46,20 @@ void uiprivTableModelSetCellValue(uiTableModel *m, int row, int column, const ui const uiTableTextColumnOptionalParams uiprivDefaultTextColumnOptionalParams = { .ColorModelColumn = -1, }; + +int uiprivTableModelCellEditable(uiTableModel *m, int row, int column) +{ + uiTableValue *value; + int editable; + + switch (column) { + case uiTableModelColumnNeverEditable: + return 0; + case uiTableModelColumnAlwaysEditable: + return 1; + } + value = uiprivTableModelCellValue(m, row, column); + editable = uiTableValueInt(value); + uiFreeTableValue(value); + return editable; +} diff --git a/darwin/tablecolumn.m b/darwin/tablecolumn.m index 7dac3304..4b3eb11d 100644 --- a/darwin/tablecolumn.m +++ b/darwin/tablecolumn.m @@ -34,23 +34,6 @@ @end -static BOOL isCellEditable(uiTableModel *m, NSInteger row, int modelColumn) -{ - uiTableValue *value; - int editable; - - switch (modelColumn) { - case uiTableModelColumnNeverEditable: - return NO; - case uiTableModelColumnAlwaysEditable: - return YES; - } - value = uiprivTableModelCellValue(m, row, modelColumn); - editable = uiTableValueInt(value); - uiFreeTableValue(value); - return editable != 0; -} - struct textColumnCreateParams { uiTable *t; uiTableModel *m; @@ -272,7 +255,7 @@ struct textColumnCreateParams { uiFreeTableValue(value); [self->tf setStringValue:str]; - [self->tf setEditable:isCellEditable(self->m, row, self->textEditableModelColumn)]; + [self->tf setEditable:uiprivTableModelCellEditable(self->m, row, self->textEditableModelColumn)]; color = nil; if (self->textParams.ColorModelColumn != -1) { @@ -307,7 +290,7 @@ struct textColumnCreateParams { [self->cb setState:NSOffState]; uiFreeTableValue(value); - [self->cb setEnabled:isCellEditable(self->m, row, self->checkboxEditableModelColumn)]; + [self->cb setEnabled:uiprivTableModelCellEditable(self->m, row, self->checkboxEditableModelColumn)]; } } @@ -558,7 +541,7 @@ struct textColumnCreateParams { uiFreeTableValue(value); [self->b setTitle:str]; - [self->b setEnabled:isCellEditable(self->m, row, self->editableColumn)]; + [self->b setEnabled:uiprivTableModelCellEditable(self->m, row, self->editableColumn)]; } - (IBAction)uiprivOnClicked:(id)sender diff --git a/unix/table.c b/unix/table.c index 010b1b39..9e659163 100644 --- a/unix/table.c +++ b/unix/table.c @@ -49,21 +49,14 @@ static void applyColor(GtkTreeModel *m, GtkTreeIter *iter, int modelColumn, GtkC static void setEditable(uiTableModel *m, GtkTreeIter *iter, int modelColumn, GtkCellRenderer *r, const char *prop) { - GValue value = G_VALUE_INIT; + GtkTreePath *path; + int row; gboolean editable; - switch (modelColumn) { - case uiTableModelColumnNeverEditable: - editable = FALSE; - break; - case uiTableModelColumnAlwaysEditable: - editable = TRUE; - break; - default: - gtk_tree_model_get_value(GTK_TREE_MODEL(m), iter, modelColumn, &value); - editable = g_value_get_int(&value) != 0; - g_value_unset(&value); - } + // TODO avoid the need for this + path = gtk_tree_model_get_path(GTK_TREE_MODEL(m), iter); + row = gtk_tree_path_get_indices(path)[0]; + editable = uiprivTableModelCellEditable(m, row, modelColumn) != 0; g_object_set(r, prop, editable, NULL); } diff --git a/windows/tabledraw.cpp b/windows/tabledraw.cpp index d8ab07e9..33eeb700 100644 --- a/windows/tabledraw.cpp +++ b/windows/tabledraw.cpp @@ -197,18 +197,7 @@ static HRESULT drawCheckboxPart(HRESULT hr, struct drawState *s) value = uiprivTableModelCellValue(s->model, s->iItem, s->p->checkboxModelColumn); checked = uiTableValueInt(value); uiFreeTableValue(value); - switch (s->p->checkboxEditableModelColumn) { - case uiTableModelColumnNeverEditable: - enabled = 0; - break; - case uiTableModelColumnAlwaysEditable: - enabled = 1; - break; - default: - value = uiprivTableModelCellValue(s->model, s->iItem, s->p->checkboxEditableModelColumn); - enabled = uiTableValueInt(value); - uiFreeTableValue(value); - } + enabled = uiprivTableModelCellEditable(s->model, s->iItem, s->p->checkboxEditableModelColumn); theme = OpenThemeData(s->t->hwnd, L"button"); if (theme != NULL) { @@ -414,18 +403,7 @@ static HRESULT drawButtonPart(HRESULT hr, struct drawState *s) value = uiprivTableModelCellValue(s->model, s->iItem, s->p->buttonModelColumn); wstr = toUTF16(uiTableValueString(value)); uiFreeTableValue(value); - switch (s->p->buttonClickableModelColumn) { - case uiTableModelColumnNeverEditable: - enabled = 0; - break; - case uiTableModelColumnAlwaysEditable: - enabled = 1; - break; - default: - value = uiprivTableModelCellValue(s->model, s->iItem, s->p->checkboxEditableModelColumn); - enabled = uiTableValueInt(value); - uiFreeTableValue(value); - } + enabled = uiprivTableModelCellEditable(s->model, s->iItem, s->p->buttonClickableModelColumn); theme = OpenThemeData(s->t->hwnd, L"button"); diff --git a/windows/tableediting.cpp b/windows/tableediting.cpp index 00b07992..7bbb450c 100644 --- a/windows/tableediting.cpp +++ b/windows/tableediting.cpp @@ -232,18 +232,8 @@ HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResu // don't even ask for info if it's too soon to edit text goto done; - switch (editableColumn) { - case uiTableModelColumnNeverEditable: + if (!uiprivTableModelCellEditable(t->model, ht.iItem, editableColumn)) goto done; - case uiTableModelColumnAlwaysEditable: - break; - default: - value = uiprivTableModelCellValue(t->model, ht.iItem, editableColumn); - editable = uiTableValueInt(value); - uiFreeTableValue(value); - if (!editable) - goto done; - } if (text) { hr = openEditControl(t, ht.iItem, ht.iSubItem, p);