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 const uiTableTextColumnOptionalParams uiprivDefaultTextColumnOptionalParams;
|
||||
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
|
||||
}
|
||||
|
|
|
@ -63,3 +63,17 @@ int uiprivTableModelCellEditable(uiTableModel *m, int row, int column)
|
|||
uiFreeTableValue(value);
|
||||
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?
|
||||
static void setBackgroundColor(uiprivTableView *t, NSTableRowView *rv, NSInteger row)
|
||||
{
|
||||
uiTableValue *value;
|
||||
NSColor *color;
|
||||
double r, g, b, a;
|
||||
|
||||
if (t->uiprivT->backgroundColumn == -1)
|
||||
return;
|
||||
value = uiprivTableModelCellValue(t->uiprivM, row, t->uiprivT->backgroundColumn);
|
||||
if (value != NULL) {
|
||||
uiTableValueColor(value, &r, &g, &b, &a);
|
||||
uiFreeTableValue(value);
|
||||
return; // let Cocoa do its default thing
|
||||
if (uiprivTableModelColorIfProvided(t->uiprivM, row, t->uiprivT->backgroundColumn, &r, &g, &b, &a))
|
||||
color = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a];
|
||||
} else {
|
||||
else {
|
||||
NSArray *colors;
|
||||
NSInteger index;
|
||||
|
||||
|
|
|
@ -249,6 +249,7 @@ struct textColumnCreateParams {
|
|||
if (self->tf != nil) {
|
||||
NSString *str;
|
||||
NSColor *color;
|
||||
double r, g, b, a;
|
||||
|
||||
value = uiprivTableModelCellValue(self->m, row, self->textModelColumn);
|
||||
str = uiprivToNSString(uiTableValueString(value));
|
||||
|
@ -257,20 +258,9 @@ struct textColumnCreateParams {
|
|||
|
||||
[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];
|
||||
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];
|
||||
// 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->textBrush = GetSysColorBrush(COLOR_HIGHLIGHTTEXT);
|
||||
} else {
|
||||
uiTableValue *value;
|
||||
double r, g, b, a;
|
||||
|
||||
s->bgColor = GetSysColor(COLOR_WINDOW);
|
||||
s->bgBrush = GetSysColorBrush(COLOR_WINDOW);
|
||||
if (t->backgroundColumn != -1) {
|
||||
value = uiprivTableModelCellValue(s->model, s->iItem, t->backgroundColumn);
|
||||
if (value != NULL) {
|
||||
uiTableValueColor(value, &r, &g, &b, &a);
|
||||
uiFreeTableValue(value);
|
||||
if (uiprivTableModelColorIfProvided(s->model, s->iItem, t->backgroundColumn, &r, &g, &b, &a)) {
|
||||
s->bgColor = blend(s->bgColor, r, g, b, a);
|
||||
s->bgBrush = CreateSolidBrush(s->bgColor);
|
||||
if (s->bgBrush == NULL) {
|
||||
|
@ -568,14 +563,9 @@ static HRESULT fillDrawState(struct drawState *s, uiTable *t, NMLVCUSTOMDRAW *nm
|
|||
}
|
||||
s->freeBgBrush = TRUE;
|
||||
}
|
||||
}
|
||||
s->textColor = GetSysColor(COLOR_WINDOWTEXT);
|
||||
s->textBrush = GetSysColorBrush(COLOR_WINDOWTEXT);
|
||||
if (p->textParams.ColorModelColumn != -1) {
|
||||
value = uiprivTableModelCellValue(s->model, s->iItem, p->textParams.ColorModelColumn);
|
||||
if (value != NULL) {
|
||||
uiTableValueColor(value, &r, &g, &b, &a);
|
||||
uiFreeTableValue(value);
|
||||
if (uiprivTableModelColorIfProvided(s->model, s->iItem, p->textParams.ColorModelColumn, &r, &g, &b, &a)) {
|
||||
s->textColor = blend(s->bgColor, r, g, b, a);
|
||||
s->textBrush = CreateSolidBrush(s->textColor);
|
||||
if (s->textBrush == NULL) {
|
||||
|
@ -586,7 +576,6 @@ static HRESULT fillDrawState(struct drawState *s, uiTable *t, NMLVCUSTOMDRAW *nm
|
|||
s->freeTextBrush = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
fail:
|
||||
|
|
Loading…
Reference in New Issue