Final cleanup, first part: renamed uiTableData to uiTableValue.

This commit is contained in:
Pietro Gagliardi 2018-06-23 20:19:30 -04:00
parent ac27e24add
commit 9a79eed2ac
13 changed files with 281 additions and 284 deletions

View File

@ -7,12 +7,10 @@ list(APPEND _LIBUI_SOURCES
common/areaevents.c
common/control.c
common/debug.c
# common/drawtext.c
common/matrix.c
common/opentype.c
common/shouldquit.c
# common/table.c
common/tabledata.c
common/tablevalue.c
common/userbugs.c
common/utf.c
)

View File

@ -1,105 +0,0 @@
// 3 june 2018
#include "../ui.h"
#include "uipriv.h"
struct uiTableData {
uiTableDataType type;
union {
char *str;
uiImage *img;
int i;
struct {
double r;
double g;
double b;
double a;
} color;
} u;
};
static uiTableData *newTableData(uiTableDataType type)
{
uiTableData *d;
d = uiprivNew(uiTableData);
d->type = type;
return d;
}
void uiFreeTableData(uiTableData *d)
{
switch (d->type) {
case uiTableDataTypeString:
uiprivFree(d->u.str);
break;
}
uiprivFree(d);
}
uiTableDataType uiTableDataGetType(const uiTableData *d)
{
return d->type;
}
uiTableData *uiNewTableDataString(const char *str)
{
uiTableData *d;
d = newTableData(uiTableDataTypeString);
d->u.str = (char *) uiprivAlloc((strlen(str) + 1) * sizeof (char), "char[] (uiTableData)");
strcpy(d->u.str, str);
return d;
}
const char *uiTableDataString(const uiTableData *d)
{
return d->u.str;
}
uiTableData *uiNewTableDataImage(uiImage *img)
{
uiTableData *d;
d = newTableData(uiTableDataTypeImage);
d->u.img = img;
return d;
}
uiImage *uiTableDataImage(const uiTableData *d)
{
return d->u.img;
}
uiTableData *uiNewTableDataInt(int i)
{
uiTableData *d;
d = newTableData(uiTableDataTypeInt);
d->u.i = i;
return d;
}
int uiTableDataInt(const uiTableData *d)
{
return d->u.i;
}
uiTableData *uiNewTableDataColor(double r, double g, double b, double a)
{
uiTableData *d;
d = newTableData(uiTableDataTypeColor);
d->u.color.r = r;
d->u.color.g = g;
d->u.color.b = b;
d->u.color.a = a;
return d;
}
void uiTableDataColor(const uiTableData *d, double *r, double *g, double *b, double *a)
{
*r = d->u.color.r;
*g = d->u.color.g;
*b = d->u.color.b;
*a = d->u.color.a;
}

105
common/tablevalue.c Normal file
View File

@ -0,0 +1,105 @@
// 3 june 2018
#include "../ui.h"
#include "uipriv.h"
struct uiTableValue {
uiTableValueType type;
union {
char *str;
uiImage *img;
int i;
struct {
double r;
double g;
double b;
double a;
} color;
} u;
};
static uiTableValue *newTableValue(uiTableValueType type)
{
uiTableValue *v;
v = uiprivNew(uiTableValue);
v->type = type;
return v;
}
void uiFreeTableValue(uiTableValue *v)
{
switch (v->type) {
case uiTableValueTypeString:
uiprivFree(v->u.str);
break;
}
uiprivFree(v);
}
uiTableValueType uiTableValueGetType(const uiTableValue *v)
{
return v->type;
}
uiTableValue *uiNewTableValueString(const char *str)
{
uiTableValue *v;
v = newTableValue(uiTableValueTypeString);
v->u.str = (char *) uiprivAlloc((strlen(str) + 1) * sizeof (char), "char[] (uiTableValue)");
strcpy(v->u.str, str);
return v;
}
const char *uiTableValueString(const uiTableValue *v)
{
return v->u.str;
}
uiTableValue *uiNewTableValueImage(uiImage *img)
{
uiTableValue *v;
v = newTableValue(uiTableValueTypeImage);
v->u.img = img;
return v;
}
uiImage *uiTableValueImage(const uiTableValue *v)
{
return v->u.img;
}
uiTableValue *uiNewTableValueInt(int i)
{
uiTableValue *v;
v = newTableValue(uiTableValueTypeInt);
v->u.i = i;
return v;
}
int uiTableValueInt(const uiTableValue *v)
{
return v->u.i;
}
uiTableValue *uiNewTableValueColor(double r, double g, double b, double a)
{
uiTableValue *v;
v = newTableValue(uiTableValueTypeColor);
v->u.color.r = r;
v->u.color.g = g;
v->u.color.b = b;
v->u.color.a = a;
return v;
}
void uiTableValueColor(const uiTableValue *v, double *r, double *g, double *b, double *a)
{
*r = v->u.color.r;
*g = v->u.color.g;
*b = v->u.color.b;
*a = v->u.color.a;
}

View File

@ -31,16 +31,16 @@
// TODO is this correct for overflow scrolling?
static void setBackgroundColor(uiprivTableView *t, NSTableRowView *rv, NSInteger row)
{
uiTableData *data;
uiTableValue *value;
NSColor *color;
double r, g, b, a;
if (t->uiprivT->backgroundColumn == -1)
return;
data = (*(t->uiprivM->mh->CellValue))(t->uiprivM->mh, t->uiprivM, row, t->uiprivT->backgroundColumn);
if (data != NULL) {
uiTableDataColor(data, &r, &g, &b, &a);
uiFreeTableData(data);
value = (*(t->uiprivM->mh->CellValue))(t->uiprivM->mh, t->uiprivM, row, t->uiprivT->backgroundColumn);
if (value != NULL) {
uiTableValueColor(value, &r, &g, &b, &a);
uiFreeTableValue(value);
color = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a];
} else {
NSArray *colors;

View File

@ -36,8 +36,8 @@
static BOOL isCellEditable(uiTableModel *m, NSInteger row, int modelColumn)
{
uiTableData *data;
int value;
uiTableValue *value;
int editable;
switch (modelColumn) {
case uiTableModelColumnNeverEditable:
@ -45,11 +45,10 @@ static BOOL isCellEditable(uiTableModel *m, NSInteger row, int modelColumn)
case uiTableModelColumnAlwaysEditable:
return YES;
}
data = (*(m->mh->CellValue))(m->mh, m, row, modelColumn);
value = uiTableDataInt(data);
uiFreeTableData(data);
return value != 0;
// TODO free data
value = (*(m->mh->CellValue))(m->mh, m, row, modelColumn);
editable = uiTableValueInt(value);
uiFreeTableValue(value);
return editable != 0;
}
static uiTableTextColumnOptionalParams defaultTextColumnOptionalParams = {
@ -266,15 +265,15 @@ struct textColumnCreateParams {
- (void)uiprivUpdate:(NSInteger)row
{
uiTableData *data;
uiTableValue *value;
if (self->tf != nil) {
NSString *str;
NSColor *color;
data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->textModelColumn);
str = uiprivToNSString(uiTableDataString(data));
uiFreeTableData(data);
value = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->textModelColumn);
str = uiprivToNSString(uiTableValueString(value));
uiFreeTableValue(value);
[self->tf setStringValue:str];
[self->tf setEditable:isCellEditable(self->m, row, self->textEditableColumn)];
@ -283,11 +282,11 @@ struct textColumnCreateParams {
if (self->textParams.ColorModelColumn != -1) {
double r, g, b, a;
data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->textParams.ColorModelColumn);
value = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->textParams.ColorModelColumn);
// TODO document this is allowed
if (data != NULL) {
uiTableDataColor(data, &r, &g, &b, &a);
uiFreeTableData(data);
if (value != NULL) {
uiTableValueColor(value, &r, &g, &b, &a);
uiFreeTableValue(value);
color = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a];
}
}
@ -299,18 +298,18 @@ struct textColumnCreateParams {
if (self->iv != nil) {
uiImage *img;
data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->imageModelColumn);
img = uiTableDataImage(data);
uiFreeTableData(data);
value = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->imageModelColumn);
img = uiTableValueImage(value);
uiFreeTableValue(value);
[self->iv setImage:uiprivImageNSImage(img)];
}
if (self->cb != nil) {
data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->imageModelColumn);
if (uiTableDataInt(data) != 0)
value = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->imageModelColumn);
if (uiTableValueInt(value) != 0)
[self->cb setState:NSOnState];
else
[self->cb setState:NSOffState];
uiFreeTableData(data);
uiFreeTableValue(value);
[self->cb setEnabled:isCellEditable(self->m, row, self->checkboxEditableColumn)];
}
@ -319,13 +318,13 @@ struct textColumnCreateParams {
- (IBAction)uiprivOnTextFieldAction:(id)sender
{
NSInteger row;
uiTableData *data;
uiTableValue *value;
row = [self->t->tv rowForView:self->tf];
data = uiNewTableDataString([[self->tf stringValue] UTF8String]);
value = uiNewTableValueString([[self->tf stringValue] UTF8String]);
(*(self->m->mh->SetCellValue))(self->m->mh, self->m,
row, self->textModelColumn, data);
uiFreeTableData(data);
row, self->textModelColumn, value);
uiFreeTableValue(value);
// always refresh the value in case the model rejected it
// TODO document that we do this, but not for the whole row (or decide to do both, or do neither...)
[self uiprivUpdate:row];
@ -334,13 +333,13 @@ struct textColumnCreateParams {
- (IBAction)uiprivOnCheckboxAction:(id)sender
{
NSInteger row;
void *data;
uiTableValue *value;
row = [self->t->tv rowForView:self->cb];
data = uiNewTableDataInt([self->cb state] != NSOffState);
value = uiNewTableValueInt([self->cb state] != NSOffState);
(*(self->m->mh->SetCellValue))(self->m->mh, self->m,
row, self->checkboxModelColumn, data);
uiFreeTableData(data);
row, self->checkboxModelColumn, value);
uiFreeTableValue(value);
// always refresh the value in case the model rejected it
[self uiprivUpdate:row];
}
@ -434,16 +433,16 @@ struct textColumnCreateParams {
- (void)uiprivUpdate:(NSInteger)row
{
uiTableData *data;
int value;
uiTableValue *value;
int progress;
data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->modelColumn);
value = uiTableDataInt(data);
uiFreeTableData(data);
if (value == -1) {
value = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->modelColumn);
progress = uiTableValueInt(value);
uiFreeTableValue(value);
if (progress == -1) {
[self->p setIndeterminate:YES];
[self->p startAnimation:self->p];
} else if (value == 100) {
} else if (progress == 100) {
[self->p setIndeterminate:NO];
[self->p setMaxValue:101];
[self->p setDoubleValue:101];
@ -451,8 +450,8 @@ struct textColumnCreateParams {
[self->p setMaxValue:100];
} else {
[self->p setIndeterminate:NO];
[self->p setDoubleValue:(value + 1)];
[self->p setDoubleValue:value];
[self->p setDoubleValue:(progress + 1)];
[self->p setDoubleValue:progress];
}
}
@ -557,12 +556,12 @@ struct textColumnCreateParams {
- (void)uiprivUpdate:(NSInteger)row
{
uiTableData *data;
uiTableValue *value;
NSString *str;
data = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->modelColumn);
str = uiprivToNSString(uiTableDataString(data));
uiFreeTableData(data);
value = (*(self->m->mh->CellValue))(self->m->mh, self->m, row, self->modelColumn);
str = uiprivToNSString(uiTableValueString(value));
uiFreeTableValue(value);
[self->b setTitle:str];
[self->b setEnabled:isCellEditable(self->m, row, self->editableColumn)];

View File

@ -8,15 +8,15 @@ static int modelNumColumns(uiTableModelHandler *mh, uiTableModel *m)
return 9;
}
static uiTableDataType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column)
static uiTableValueType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column)
{
if (column == 3 || column == 4)
return uiTableDataTypeColor;
return uiTableValueTypeColor;
if (column == 5)
return uiTableDataTypeImage;
return uiTableValueTypeImage;
if (column == 7 || column == 8)
return uiTableDataTypeInt;
return uiTableDataTypeString;
return uiTableValueTypeInt;
return uiTableValueTypeString;
}
static int modelNumRows(uiTableModelHandler *mh, uiTableModel *m)
@ -29,39 +29,39 @@ static char row9text[1024];
static int yellowRow = -1;
static int checkStates[15];
static uiTableData *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col)
static uiTableValue *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col)
{
char buf[256];
if (col == 3) {
if (row == yellowRow)
return uiNewTableDataColor(1, 1, 0, 1);
return uiNewTableValueColor(1, 1, 0, 1);
if (row == 3)
return uiNewTableDataColor(1, 0, 0, 1);
return uiNewTableValueColor(1, 0, 0, 1);
if (row == 11)
return uiNewTableDataColor(0, 0.5, 1, 0.5);
return uiNewTableValueColor(0, 0.5, 1, 0.5);
return NULL;
}
if (col == 4) {
if ((row % 2) == 1)
return uiNewTableDataColor(0.5, 0, 0.75, 1);
return uiNewTableValueColor(0.5, 0, 0.75, 1);
return NULL;
}
if (col == 5) {
if (row < 8)
return uiNewTableDataImage(img[0]);
return uiNewTableDataImage(img[1]);
return uiNewTableValueImage(img[0]);
return uiNewTableValueImage(img[1]);
}
if (col == 7)
return uiNewTableDataInt(checkStates[row]);
return uiNewTableValueInt(checkStates[row]);
if (col == 8) {
if (row == 0)
return uiNewTableDataInt(0);
return uiNewTableValueInt(0);
if (row == 13)
return uiNewTableDataInt(100);
return uiNewTableValueInt(100);
if (row == 14)
return uiNewTableDataInt(-1);
return uiNewTableDataInt(50);
return uiNewTableValueInt(-1);
return uiNewTableValueInt(50);
}
switch (col) {
case 0:
@ -69,7 +69,7 @@ static uiTableData *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int
break;
case 2:
if (row == 9)
return uiNewTableDataString(row9text);
return uiNewTableValueString(row9text);
// fall through
case 1:
strcpy(buf, "Part");
@ -78,13 +78,13 @@ static uiTableData *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int
strcpy(buf, "Make Yellow");
break;
}
return uiNewTableDataString(buf);
return uiNewTableValueString(buf);
}
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col, const uiTableData *val)
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col, const uiTableValue *val)
{
if (row == 9 && col == 2)
strcpy(row9text, uiTableDataString(val));
strcpy(row9text, uiTableValueString(val));
if (col == 6) {
int prevYellowRow;
@ -95,7 +95,7 @@ static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row,
uiTableModelRowChanged(m, yellowRow);
}
if (col == 7)
checkStates[row] = uiTableDataInt(val);
checkStates[row] = uiTableValueInt(val);
}
uiBox *makePage16(void)

View File

@ -8,32 +8,32 @@ _UI_EXTERN uiImage *uiNewImage(double width, double height);
_UI_EXTERN void uiFreeImage(uiImage *i);
_UI_EXTERN void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride);
typedef struct uiTableData uiTableData;
typedef struct uiTableValue uiTableValue;
_UI_EXTERN void uiFreeTableData(uiTableData *d);
_UI_EXTERN void uiFreeTableValue(uiTableValue *v);
// TODO actually validate these
_UI_ENUM(uiTableDataType) {
uiTableDataTypeString,
uiTableDataTypeImage,
uiTableDataTypeInt,
uiTableDataTypeColor,
_UI_ENUM(uiTableValueType) {
uiTableValueTypeString,
uiTableValueTypeImage,
uiTableValueTypeInt,
uiTableValueTypeColor,
};
// TODO I don't like this name
_UI_EXTERN uiTableDataType uiTableDataGetType(const uiTableData *d);
_UI_EXTERN uiTableValueType uiTableValueGetType(const uiTableValue *v);
_UI_EXTERN uiTableData *uiNewTableDataString(const char *str);
_UI_EXTERN const char *uiTableDataString(const uiTableData *d);
_UI_EXTERN uiTableValue *uiNewTableValueString(const char *str);
_UI_EXTERN const char *uiTableValueString(const uiTableValue *v);
_UI_EXTERN uiTableData *uiNewTableDataImage(uiImage *img);
_UI_EXTERN uiImage *uiTableDataImage(const uiTableData *d);
_UI_EXTERN uiTableValue *uiNewTableValueImage(uiImage *img);
_UI_EXTERN uiImage *uiTableValueImage(const uiTableValue *v);
_UI_EXTERN uiTableData *uiNewTableDataInt(int i);
_UI_EXTERN int uiTableDataInt(const uiTableData *d);
_UI_EXTERN uiTableValue *uiNewTableValueInt(int i);
_UI_EXTERN int uiTableValueInt(const uiTableValue *v);
_UI_EXTERN uiTableData *uiNewTableDataColor(double r, double g, double b, double a);
_UI_EXTERN void uiTableDataColor(const uiTableData *d, double *r, double *g, double *b, double *a);
_UI_EXTERN uiTableValue *uiNewTableValueColor(double r, double g, double b, double a);
_UI_EXTERN void uiTableValueColor(const uiTableValue *v, double *r, double *g, double *b, double *a);
typedef struct uiTableModel uiTableModel;
typedef struct uiTableModelHandler uiTableModelHandler;
@ -41,10 +41,10 @@ typedef struct uiTableModelHandler uiTableModelHandler;
// TODO validate ranges; validate types on each getter/setter call (? table columns only?)
struct uiTableModelHandler {
int (*NumColumns)(uiTableModelHandler *, uiTableModel *);
uiTableDataType (*ColumnType)(uiTableModelHandler *, uiTableModel *, int);
uiTableValueType (*ColumnType)(uiTableModelHandler *, uiTableModel *, int);
int (*NumRows)(uiTableModelHandler *, uiTableModel *);
uiTableData *(*CellValue)(uiTableModelHandler *, uiTableModel *, int, int);
void (*SetCellValue)(uiTableModelHandler *, uiTableModel *, int, int, const uiTableData *);
uiTableValue *(*CellValue)(uiTableModelHandler *, uiTableModel *, int, int);
void (*SetCellValue)(uiTableModelHandler *, uiTableModel *, int, int, const uiTableValue *);
};
_UI_EXTERN uiTableModel *uiNewTableModel(uiTableModelHandler *mh);

View File

@ -74,7 +74,7 @@ static void applyBackgroundColor(uiTable *t, GtkTreeModel *m, GtkTreeIter *iter,
r, "cell-background-rgba", "cell-background-set");
}
static void onEdited(uiTableModel *m, int column, const char *pathstr, const uiTableData *data, GtkTreeIter *iter)
static void onEdited(uiTableModel *m, int column, const char *pathstr, const uiTableValue *tvalue, GtkTreeIter *iter)
{
GtkTreePath *path;
int row;
@ -84,7 +84,7 @@ static void onEdited(uiTableModel *m, int column, const char *pathstr, const uiT
if (iter != NULL)
gtk_tree_model_get_iter(GTK_TREE_MODEL(m), iter, path);
gtk_tree_path_free(path);
(*(m->mh->SetCellValue))(m->mh, m, row, column, data);
(*(m->mh->SetCellValue))(m->mh, m, row, column, tvalue);
}
// TODO deduplicate this between platforms
@ -123,12 +123,12 @@ static void textColumnDataFunc(GtkTreeViewColumn *c, GtkCellRenderer *r, GtkTree
static void textColumnEdited(GtkCellRendererText *r, gchar *path, gchar *newText, gpointer data)
{
struct textColumnParams *p = (struct textColumnParams *) data;
uiTableData *tdata;
uiTableValue *tvalue;
GtkTreeIter iter;
tdata = uiNewTableDataString(newText);
onEdited(p->m, p->modelColumn, path, tdata, &iter);
uiFreeTableData(tdata);
tvalue = uiNewTableValueString(newText);
onEdited(p->m, p->modelColumn, path, tvalue, &iter);
uiFreeTableValue(tvalue);
// and update the column TODO copy comment here
textColumnDataFunc(NULL, GTK_CELL_RENDERER(r), GTK_TREE_MODEL(p->m), &iter, data);
}
@ -183,7 +183,7 @@ static void checkboxColumnToggled(GtkCellRendererToggle *r, gchar *pathstr, gpoi
struct checkboxColumnParams *p = (struct checkboxColumnParams *) data;
GValue value = G_VALUE_INIT;
int v;
uiTableData *tdata;
uiTableValue *tvalue;
GtkTreePath *path;
GtkTreeIter iter;
@ -193,9 +193,9 @@ static void checkboxColumnToggled(GtkCellRendererToggle *r, gchar *pathstr, gpoi
gtk_tree_model_get_value(GTK_TREE_MODEL(p->m), &iter, p->modelColumn, &value);
v = g_value_get_int(&value);
g_value_unset(&value);
tdata = uiNewTableDataInt(!v);
onEdited(p->m, p->modelColumn, pathstr, tdata, NULL);
uiFreeTableData(tdata);
tvalue = uiNewTableValueInt(!v);
onEdited(p->m, p->modelColumn, pathstr, tvalue, NULL);
uiFreeTableValue(tvalue);
// and update the column TODO copy comment here
// TODO avoid fetching the model data twice
checkboxColumnDataFunc(NULL, GTK_CELL_RENDERER(r), GTK_TREE_MODEL(p->m), &iter, data);

View File

@ -39,13 +39,13 @@ static GType uiTableModel_get_column_type(GtkTreeModel *mm, gint index)
uiTableModel *m = uiTableModel(mm);
switch ((*(m->mh->ColumnType))(m->mh, m, index)) {
case uiTableDataTypeString:
case uiTableValueTypeString:
return G_TYPE_STRING;
case uiTableDataTypeImage:
case uiTableValueTypeImage:
return G_TYPE_POINTER;
case uiTableDataTypeInt:
case uiTableValueTypeInt:
return G_TYPE_INT;
case uiTableDataTypeColor:
case uiTableValueTypeColor:
return GDK_TYPE_RGBA;
}
// TODO
@ -91,38 +91,38 @@ static void uiTableModel_get_value(GtkTreeModel *mm, GtkTreeIter *iter, gint col
{
uiTableModel *m = uiTableModel(mm);
gint row;
uiTableData *data;
uiTableValue *tvalue;
double r, g, b, a;
GdkRGBA rgba;
if (iter->stamp != STAMP_GOOD)
return;
row = GPOINTER_TO_INT(iter->user_data);
data = (*(m->mh->CellValue))(m->mh, m, row, column);
tvalue = (*(m->mh->CellValue))(m->mh, m, row, column);
switch ((*(m->mh->ColumnType))(m->mh, m, column)) {
case uiTableDataTypeString:
case uiTableValueTypeString:
g_value_init(value, G_TYPE_STRING);
g_value_set_string(value, uiTableDataString(data));
uiFreeTableData(data);
g_value_set_string(value, uiTableValueString(tvalue));
uiFreeTableValue(tvalue);
return;
case uiTableDataTypeImage:
case uiTableValueTypeImage:
g_value_init(value, G_TYPE_POINTER);
g_value_set_pointer(value, uiTableDataImage(data));
uiFreeTableData(data);
g_value_set_pointer(value, uiTableValueImage(tvalue));
uiFreeTableValue(tvalue);
return;
case uiTableDataTypeInt:
case uiTableValueTypeInt:
g_value_init(value, G_TYPE_INT);
g_value_set_int(value, uiTableDataInt(data));
uiFreeTableData(data);
g_value_set_int(value, uiTableValueInt(tvalue));
uiFreeTableValue(tvalue);
return;
case uiTableDataTypeColor:
case uiTableValueTypeColor:
g_value_init(value, GDK_TYPE_RGBA);
if (data == NULL) {
if (tvalue == NULL) {
g_value_set_boxed(value, NULL);
return;
}
uiTableDataColor(data, &r, &g, &b, &a);
uiFreeTableData(data);
uiTableValueColor(tvalue, &r, &g, &b, &a);
uiFreeTableValue(tvalue);
rgba.red = r;
rgba.green = g;
rgba.blue = b;

View File

@ -188,16 +188,16 @@ static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
int uiprivTableProgress(uiTable *t, int item, int subitem, int modelColumn, LONG *pos)
{
uiTableData *data;
uiTableValue *value;
int progress;
std::pair<int, int> p;
std::map<std::pair<int, int>, LONG>::iterator iter;
bool startTimer = false;
bool stopTimer = false;
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, item, modelColumn);
progress = uiTableDataInt(data);
uiFreeTableData(data);
value = (*(t->model->mh->CellValue))(t->model->mh, t->model, item, modelColumn);
progress = uiTableValueInt(value);
uiFreeTableValue(value);
p.first = item;
p.second = subitem;

View File

@ -8,7 +8,7 @@
static HRESULT handleLVIF_TEXT(uiTable *t, NMLVDISPINFOW *nm, uiprivTableColumnParams *p)
{
int strcol;
uiTableData *data;
uiTableValue *value;
WCHAR *wstr;
int progress;
HRESULT hr;
@ -22,9 +22,9 @@ static HRESULT handleLVIF_TEXT(uiTable *t, NMLVDISPINFOW *nm, uiprivTableColumnP
else if (p->buttonModelColumn != -1)
strcol = p->buttonModelColumn;
if (strcol != -1) {
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, nm->item.iItem, strcol);
wstr = toUTF16(uiTableDataString(data));
uiFreeTableData(data);
value = (*(t->model->mh->CellValue))(t->model->mh, t->model, nm->item.iItem, strcol);
wstr = toUTF16(uiTableValueString(value));
uiFreeTableValue(value);
// We *could* just make pszText into a freshly allocated
// conversion and avoid the limitation of cchTextMax.
// But then, we would have to keep things around for some
@ -59,7 +59,7 @@ static HRESULT handleLVIF_TEXT(uiTable *t, NMLVDISPINFOW *nm, uiprivTableColumnP
static HRESULT handleLVIF_IMAGE(uiTable *t, NMLVDISPINFOW *nm, uiprivTableColumnParams *p)
{
uiTableData *data;
uiTableValue *value;
HRESULT hr;
if (nm->item.iSubItem == 0 && p->imageModelColumn == -1 && p->checkboxModelColumn == -1) {
@ -75,7 +75,7 @@ static HRESULT handleLVIF_IMAGE(uiTable *t, NMLVDISPINFOW *nm, uiprivTableColumn
return S_OK; // nothing to do here
// TODO see if the -1 part is correct
// TODO see if we should use state instead of images for checkbox data
// TODO see if we should use state instead of images for checkbox value
nm->item.iImage = -1;
if (p->imageModelColumn != -1 || p->checkboxModelColumn != -1)
nm->item.iImage = 0;

View File

@ -67,7 +67,7 @@ static void centerImageRect(RECT *image, RECT *space)
static HRESULT drawImagePart(HRESULT hr, struct drawState *s)
{
uiTableData *data;
uiTableValue *value;
IWICBitmap *wb;
HBITMAP b;
RECT r;
@ -78,9 +78,9 @@ static HRESULT drawImagePart(HRESULT hr, struct drawState *s)
if (s->p->imageModelColumn == -1)
return S_OK;
data = cellValue(s->model, s->iItem, s->p->imageModelColumn);
wb = uiprivImageAppropriateForDC(uiTableDataImage(data), s->dc);
uiFreeTableData(data);
value = cellValue(s->model, s->iItem, s->p->imageModelColumn);
wb = uiprivImageAppropriateForDC(uiTableValueImage(value), s->dc);
uiFreeTableValue(value);
hr = uiprivWICToGDI(wb, s->dc, s->m->cxIcon, s->m->cyIcon, &b);
if (hr != S_OK)
@ -188,7 +188,7 @@ static HRESULT drawThemedCheckbox(struct drawState *s, HTHEME theme, int checked
static HRESULT drawCheckboxPart(HRESULT hr, struct drawState *s)
{
uiTableData *data;
uiTableValue *value;
int checked, enabled;
HTHEME theme;
@ -197,9 +197,9 @@ static HRESULT drawCheckboxPart(HRESULT hr, struct drawState *s)
if (s->p->checkboxModelColumn == -1)
return S_OK;
data = cellValue(s->model, s->iItem, s->p->checkboxModelColumn);
checked = uiTableDataInt(data);
uiFreeTableData(data);
value = cellValue(s->model, s->iItem, s->p->checkboxModelColumn);
checked = uiTableValueInt(value);
uiFreeTableValue(value);
switch (s->p->checkboxEditableColumn) {
case uiTableModelColumnNeverEditable:
enabled = 0;
@ -208,9 +208,9 @@ static HRESULT drawCheckboxPart(HRESULT hr, struct drawState *s)
enabled = 1;
break;
default:
data = cellValue(s->model, s->iItem, s->p->checkboxEditableColumn);
enabled = uiTableDataInt(data);
uiFreeTableData(data);
value = cellValue(s->model, s->iItem, s->p->checkboxEditableColumn);
enabled = uiTableValueInt(value);
uiFreeTableValue(value);
}
theme = OpenThemeData(s->t->hwnd, L"button");
@ -236,7 +236,7 @@ static HRESULT drawTextPart(HRESULT hr, struct drawState *s)
COLORREF prevText;
int prevMode;
RECT r;
uiTableData *data;
uiTableValue *value;
WCHAR *wstr;
if (hr != S_OK)
@ -258,9 +258,9 @@ static HRESULT drawTextPart(HRESULT hr, struct drawState *s)
return E_FAIL;
}
data = cellValue(s->model, s->iItem, s->p->textModelColumn);
wstr = toUTF16(uiTableDataString(data));
uiFreeTableData(data);
value = cellValue(s->model, s->iItem, s->p->textModelColumn);
wstr = toUTF16(uiTableValueString(value));
uiFreeTableValue(value);
// These flags are a menagerie of flags from various sources:
// guessing, the Windows 2000 source leak, various custom
// draw examples on the web, etc.
@ -402,7 +402,7 @@ fail:
static HRESULT drawButtonPart(HRESULT hr, struct drawState *s)
{
uiTableData *data;
uiTableValue *value;
WCHAR *wstr;
bool enabled;
HTHEME theme;
@ -414,9 +414,9 @@ static HRESULT drawButtonPart(HRESULT hr, struct drawState *s)
if (s->p->buttonModelColumn == -1)
return S_OK;
data = cellValue(s->model, s->iItem, s->p->buttonModelColumn);
wstr = toUTF16(uiTableDataString(data));
uiFreeTableData(data);
value = cellValue(s->model, s->iItem, s->p->buttonModelColumn);
wstr = toUTF16(uiTableValueString(value));
uiFreeTableValue(value);
switch (s->p->buttonClickableModelColumn) {
case uiTableModelColumnNeverEditable:
enabled = 0;
@ -425,9 +425,9 @@ static HRESULT drawButtonPart(HRESULT hr, struct drawState *s)
enabled = 1;
break;
default:
data = cellValue(s->model, s->iItem, s->p->checkboxEditableColumn);
enabled = uiTableDataInt(data);
uiFreeTableData(data);
value = cellValue(s->model, s->iItem, s->p->checkboxEditableColumn);
enabled = uiTableValueInt(value);
uiFreeTableValue(value);
}
theme = OpenThemeData(s->t->hwnd, L"button");
@ -574,16 +574,16 @@ static HRESULT fillDrawState(struct drawState *s, uiTable *t, NMLVCUSTOMDRAW *nm
s->textColor = GetSysColor(COLOR_HIGHLIGHTTEXT);
s->textBrush = GetSysColorBrush(COLOR_HIGHLIGHTTEXT);
} else {
uiTableData *data;
uiTableValue *value;
double r, g, b, a;
s->bgColor = GetSysColor(COLOR_WINDOW);
s->bgBrush = GetSysColorBrush(COLOR_WINDOW);
if (t->backgroundColumn != -1) {
data = cellValue(s->model, s->iItem, t->backgroundColumn);
if (data != NULL) {
uiTableDataColor(data, &r, &g, &b, &a);
uiFreeTableData(data);
value = cellValue(s->model, s->iItem, t->backgroundColumn);
if (value != NULL) {
uiTableValueColor(value, &r, &g, &b, &a);
uiFreeTableValue(value);
s->bgColor = blend(s->bgColor, r, g, b, a);
s->bgBrush = CreateSolidBrush(s->bgColor);
if (s->bgBrush == NULL) {
@ -597,10 +597,10 @@ static HRESULT fillDrawState(struct drawState *s, uiTable *t, NMLVCUSTOMDRAW *nm
s->textColor = GetSysColor(COLOR_WINDOWTEXT);
s->textBrush = GetSysColorBrush(COLOR_WINDOWTEXT);
if (p->textParams.ColorModelColumn != -1) {
data = cellValue(s->model, s->iItem, p->textParams.ColorModelColumn);
if (data != NULL) {
uiTableDataColor(data, &r, &g, &b, &a);
uiFreeTableData(data);
value = cellValue(s->model, s->iItem, p->textParams.ColorModelColumn);
if (value != NULL) {
uiTableValueColor(value, &r, &g, &b, &a);
uiFreeTableValue(value);
s->textColor = blend(s->bgColor, r, g, b, a);
s->textBrush = CreateSolidBrush(s->textColor);
if (s->textBrush == NULL) {

View File

@ -95,7 +95,7 @@ static LRESULT CALLBACK editSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
static HRESULT openEditControl(uiTable *t, int iItem, int iSubItem, uiprivTableColumnParams *p)
{
uiTableData *data;
uiTableValue *value;
WCHAR *wstr;
HRESULT hr;
@ -105,9 +105,9 @@ static HRESULT openEditControl(uiTable *t, int iItem, int iSubItem, uiprivTableC
return hr;
// the real list view creates the edit control with the string
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, iItem, p->textModelColumn);
wstr = toUTF16(uiTableDataString(data));
uiFreeTableData(data);
value = (*(t->model->mh->CellValue))(t->model->mh, t->model, iItem, p->textModelColumn);
wstr = toUTF16(uiTableValueString(value));
uiFreeTableValue(value);
// TODO copy WS_EX_RTLREADING
t->edit = CreateWindowExW(0,
L"EDIT", wstr,
@ -157,17 +157,17 @@ HRESULT uiprivTableResizeWhileEditing(uiTable *t)
HRESULT uiprivTableFinishEditingText(uiTable *t)
{
uiprivTableColumnParams *p;
uiTableData *data;
uiTableValue *value;
char *text;
if (t->edit == NULL)
return S_OK;
text = uiWindowsWindowText(t->edit);
data = uiNewTableDataString(text);
value = uiNewTableValueString(text);
uiFreeText(text);
p = (*(t->columns))[t->editedSubitem];
(*(t->model->mh->SetCellValue))(t->model->mh, t->model, t->editedItem, p->textModelColumn, data);
uiFreeTableData(data);
(*(t->model->mh->SetCellValue))(t->model->mh, t->model, t->editedItem, p->textModelColumn, value);
uiFreeTableValue(value);
// always refresh the value in case the model rejected it
if (SendMessageW(t->hwnd, LVM_UPDATE, (WPARAM) (t->editedItem), 0) == (LRESULT) (-1)) {
logLastError(L"LVM_UPDATE");
@ -199,7 +199,7 @@ HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResu
uiprivTableColumnParams *p;
int modelColumn, editableColumn;
bool text, checkbox;
uiTableData *data;
uiTableValue *value;
int checked, editable;
HRESULT hr;
@ -238,9 +238,9 @@ HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResu
case uiTableModelColumnAlwaysEditable:
break;
default:
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, ht.iItem, editableColumn);
editable = uiTableDataInt(data);
uiFreeTableData(data);
value = (*(t->model->mh->CellValue))(t->model->mh, t->model, ht.iItem, editableColumn);
editable = uiTableValueInt(value);
uiFreeTableValue(value);
if (!editable)
goto done;
}
@ -252,12 +252,12 @@ HRESULT uiprivTableHandleNM_CLICK(uiTable *t, NMITEMACTIVATE *nm, LRESULT *lResu
} else if (checkbox) {
if ((ht.flags & LVHT_ONITEMICON) == 0)
goto done;
data = (*(t->model->mh->CellValue))(t->model->mh, t->model, ht.iItem, modelColumn);
checked = uiTableDataInt(data);
uiFreeTableData(data);
data = uiNewTableDataInt(!checked);
(*(t->model->mh->SetCellValue))(t->model->mh, t->model, ht.iItem, modelColumn, data);
uiFreeTableData(data);
value = (*(t->model->mh->CellValue))(t->model->mh, t->model, ht.iItem, modelColumn);
checked = uiTableValueInt(value);
uiFreeTableValue(value);
value = uiNewTableValueInt(!checked);
(*(t->model->mh->SetCellValue))(t->model->mh, t->model, ht.iItem, modelColumn, value);
uiFreeTableValue(value);
} else
(*(t->model->mh->SetCellValue))(t->model->mh, t->model, ht.iItem, modelColumn, NULL);
// always refresh the value in case the model rejected it