Cleaned up color access across platforms.
This commit is contained in:
parent
acb40964f3
commit
f3882d6124
|
@ -13,6 +13,7 @@ extern uiTableValue *uiprivTableModelCellValue(uiTableModel *m, int row, int col
|
||||||
extern void uiprivTableModelSetCellValue(uiTableModel *m, int row, int column, const uiTableValue *value);
|
extern void uiprivTableModelSetCellValue(uiTableModel *m, int row, int column, const uiTableValue *value);
|
||||||
extern const uiTableTextColumnOptionalParams uiprivDefaultTextColumnOptionalParams;
|
extern const uiTableTextColumnOptionalParams uiprivDefaultTextColumnOptionalParams;
|
||||||
extern int uiprivTableModelCellEditable(uiTableModel *m, int row, int column);
|
extern int uiprivTableModelCellEditable(uiTableModel *m, int row, int column);
|
||||||
|
extern int uiprivTableModelColorIfProvided(uiTableModel *m, int row, int column, double *r, double *g, double *b, double *a);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,3 +63,17 @@ int uiprivTableModelCellEditable(uiTableModel *m, int row, int column)
|
||||||
uiFreeTableValue(value);
|
uiFreeTableValue(value);
|
||||||
return editable;
|
return editable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int uiprivTableModelColorIfProvided(uiTableModel *m, int row, int column, double *r, double *g, double *b, double *a)
|
||||||
|
{
|
||||||
|
uiTableValue *value;
|
||||||
|
|
||||||
|
if (column == -1)
|
||||||
|
return 0;
|
||||||
|
value = uiprivTableModelCellValue(m, row, column);
|
||||||
|
if (value == NULL)
|
||||||
|
return 0;
|
||||||
|
uiTableValueColor(value, r, g, b, a);
|
||||||
|
uiFreeTableValue(value);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
@ -31,18 +31,14 @@
|
||||||
// TODO is this correct for overflow scrolling?
|
// TODO is this correct for overflow scrolling?
|
||||||
static void setBackgroundColor(uiprivTableView *t, NSTableRowView *rv, NSInteger row)
|
static void setBackgroundColor(uiprivTableView *t, NSTableRowView *rv, NSInteger row)
|
||||||
{
|
{
|
||||||
uiTableValue *value;
|
|
||||||
NSColor *color;
|
NSColor *color;
|
||||||
double r, g, b, a;
|
double r, g, b, a;
|
||||||
|
|
||||||
if (t->uiprivT->backgroundColumn == -1)
|
if (t->uiprivT->backgroundColumn == -1)
|
||||||
return;
|
return; // let Cocoa do its default thing
|
||||||
value = uiprivTableModelCellValue(t->uiprivM, row, t->uiprivT->backgroundColumn);
|
if (uiprivTableModelColorIfProvided(t->uiprivM, row, t->uiprivT->backgroundColumn, &r, &g, &b, &a))
|
||||||
if (value != NULL) {
|
|
||||||
uiTableValueColor(value, &r, &g, &b, &a);
|
|
||||||
uiFreeTableValue(value);
|
|
||||||
color = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a];
|
color = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a];
|
||||||
} else {
|
else {
|
||||||
NSArray *colors;
|
NSArray *colors;
|
||||||
NSInteger index;
|
NSInteger index;
|
||||||
|
|
||||||
|
|
|
@ -249,6 +249,7 @@ struct textColumnCreateParams {
|
||||||
if (self->tf != nil) {
|
if (self->tf != nil) {
|
||||||
NSString *str;
|
NSString *str;
|
||||||
NSColor *color;
|
NSColor *color;
|
||||||
|
double r, g, b, a;
|
||||||
|
|
||||||
value = uiprivTableModelCellValue(self->m, row, self->textModelColumn);
|
value = uiprivTableModelCellValue(self->m, row, self->textModelColumn);
|
||||||
str = uiprivToNSString(uiTableValueString(value));
|
str = uiprivToNSString(uiTableValueString(value));
|
||||||
|
@ -257,20 +258,9 @@ struct textColumnCreateParams {
|
||||||
|
|
||||||
[self->tf setEditable:uiprivTableModelCellEditable(self->m, row, self->textEditableModelColumn)];
|
[self->tf setEditable:uiprivTableModelCellEditable(self->m, row, self->textEditableModelColumn)];
|
||||||
|
|
||||||
color = nil;
|
|
||||||
if (self->textParams.ColorModelColumn != -1) {
|
|
||||||
double r, g, b, a;
|
|
||||||
|
|
||||||
value = uiprivTableModelCellValue(self->m, row, self->textParams.ColorModelColumn);
|
|
||||||
// TODO document this is allowed
|
|
||||||
if (value != NULL) {
|
|
||||||
uiTableValueColor(value, &r, &g, &b, &a);
|
|
||||||
uiFreeTableValue(value);
|
|
||||||
color = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (color == nil)
|
|
||||||
color = [NSColor controlTextColor];
|
color = [NSColor controlTextColor];
|
||||||
|
if (uiprivTableModelColorIfProvided(self->m, row, self->textParams.ColorModelColumn, &r, &g, &b, &a))
|
||||||
|
color = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a];
|
||||||
[self->tf setTextColor:color];
|
[self->tf setTextColor:color];
|
||||||
// we don't own color in ether case; don't release
|
// we don't own color in ether case; don't release
|
||||||
}
|
}
|
||||||
|
|
|
@ -549,16 +549,11 @@ static HRESULT fillDrawState(struct drawState *s, uiTable *t, NMLVCUSTOMDRAW *nm
|
||||||
s->textColor = GetSysColor(COLOR_HIGHLIGHTTEXT);
|
s->textColor = GetSysColor(COLOR_HIGHLIGHTTEXT);
|
||||||
s->textBrush = GetSysColorBrush(COLOR_HIGHLIGHTTEXT);
|
s->textBrush = GetSysColorBrush(COLOR_HIGHLIGHTTEXT);
|
||||||
} else {
|
} else {
|
||||||
uiTableValue *value;
|
|
||||||
double r, g, b, a;
|
double r, g, b, a;
|
||||||
|
|
||||||
s->bgColor = GetSysColor(COLOR_WINDOW);
|
s->bgColor = GetSysColor(COLOR_WINDOW);
|
||||||
s->bgBrush = GetSysColorBrush(COLOR_WINDOW);
|
s->bgBrush = GetSysColorBrush(COLOR_WINDOW);
|
||||||
if (t->backgroundColumn != -1) {
|
if (uiprivTableModelColorIfProvided(s->model, s->iItem, t->backgroundColumn, &r, &g, &b, &a)) {
|
||||||
value = uiprivTableModelCellValue(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->bgColor = blend(s->bgColor, r, g, b, a);
|
||||||
s->bgBrush = CreateSolidBrush(s->bgColor);
|
s->bgBrush = CreateSolidBrush(s->bgColor);
|
||||||
if (s->bgBrush == NULL) {
|
if (s->bgBrush == NULL) {
|
||||||
|
@ -568,14 +563,9 @@ static HRESULT fillDrawState(struct drawState *s, uiTable *t, NMLVCUSTOMDRAW *nm
|
||||||
}
|
}
|
||||||
s->freeBgBrush = TRUE;
|
s->freeBgBrush = TRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
s->textColor = GetSysColor(COLOR_WINDOWTEXT);
|
s->textColor = GetSysColor(COLOR_WINDOWTEXT);
|
||||||
s->textBrush = GetSysColorBrush(COLOR_WINDOWTEXT);
|
s->textBrush = GetSysColorBrush(COLOR_WINDOWTEXT);
|
||||||
if (p->textParams.ColorModelColumn != -1) {
|
if (uiprivTableModelColorIfProvided(s->model, s->iItem, p->textParams.ColorModelColumn, &r, &g, &b, &a)) {
|
||||||
value = uiprivTableModelCellValue(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->textColor = blend(s->bgColor, r, g, b, a);
|
||||||
s->textBrush = CreateSolidBrush(s->textColor);
|
s->textBrush = CreateSolidBrush(s->textColor);
|
||||||
if (s->textBrush == NULL) {
|
if (s->textBrush == NULL) {
|
||||||
|
@ -586,7 +576,6 @@ static HRESULT fillDrawState(struct drawState *s, uiTable *t, NMLVCUSTOMDRAW *nm
|
||||||
s->freeTextBrush = TRUE;
|
s->freeTextBrush = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
fail:
|
fail:
|
||||||
|
|
Loading…
Reference in New Issue