Deduplicated editable logic across platforms.

This commit is contained in:
Pietro Gagliardi 2018-06-24 11:41:19 -04:00
parent fb67c429d8
commit acb40964f3
6 changed files with 30 additions and 68 deletions

View File

@ -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
}

View File

@ -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;
}

View File

@ -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

View File

@ -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);
}

View File

@ -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");

View File

@ -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);