Made background color columns only settable at creation time; added a uiTableParams struct for the purpose. This should end edits to uitable.h for now (until we're ready to document it). Now to just clean up all the implementations.

This commit is contained in:
Pietro Gagliardi 2018-06-24 10:28:41 -04:00
parent 72c7c05f04
commit fb67c429d8
5 changed files with 40 additions and 54 deletions

View File

@ -171,26 +171,21 @@ static void uiTableDestroy(uiControl *c)
uiFreeControl(uiControl(t));
}
void uiTableSetRowBackgroundColorModelColumn(uiTable *t, int modelColumn)
{
t->backgroundColumn = modelColumn;
// TODO update all rows
}
uiTable *uiNewTable(uiTableModel *model)
uiTable *uiNewTable(uiTableParams *p)
{
uiTable *t;
uiprivScrollViewCreateParams p;
uiprivScrollViewCreateParams sp;
uiDarwinNewControl(uiTable, t);
t->m = model;
t->m = p->Model;
t->backgroundColumn = p->RowBackgroundColorModelColumn;
t->tv = [[uiprivTableView alloc] initWithFrame:NSZeroRect uiprivT:t uiprivM:t->m];
[t->tv setDataSource:model->m];
[t->tv setDelegate:model->m];
[t->tv setDataSource:t->m->m];
[t->tv setDelegate:t->m->m];
[t->tv reloadData];
[model->tables addObject:t->tv];
[t->m->tables addObject:t->tv];
// TODO is this sufficient?
[t->tv setAllowsColumnReordering:NO];
@ -204,23 +199,21 @@ uiTable *uiNewTable(uiTableModel *model)
[t->tv setAllowsTypeSelect:YES];
// TODO floatsGroupRows do we even allow group rows?
memset(&p, 0, sizeof (uiprivScrollViewCreateParams));
p.DocumentView = t->tv;
memset(&sp, 0, sizeof (uiprivScrollViewCreateParams));
sp.DocumentView = t->tv;
// this is what Interface Builder sets it to
// TODO verify
p.BackgroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0];
p.DrawsBackground = YES;
p.Bordered = YES;
p.HScroll = YES;
p.VScroll = YES;
t->sv = uiprivMkScrollView(&p, &(t->d));
sp.BackgroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0];
sp.DrawsBackground = YES;
sp.Bordered = YES;
sp.HScroll = YES;
sp.VScroll = YES;
t->sv = uiprivMkScrollView(&sp, &(t->d));
// TODO WHY DOES THIS REMOVE ALL GRAPHICAL GLITCHES?
// I got the idea from http://jwilling.com/blog/optimized-nstableview-scrolling/ but that was on an unrelated problem I didn't seem to have (although I have small-ish tables to start with)
// I don't get layer-backing... am I supposed to layer-back EVERYTHING manually? I need to check Interface Builder again...
[t->sv setWantsLayer:YES];
t->backgroundColumn = -1;
return t;
}

View File

@ -103,7 +103,8 @@ uiBox *makePage16(void)
uiBox *page16;
uiTableModel *m;
uiTable *t;
uiTableTextColumnOptionalParams p;
uiTableParams p;
uiTableTextColumnOptionalParams tp;
img[0] = uiNewImage(16, 16);
appendImageNamed(img[0], "andlabs_16x16test_24june2016.png");
@ -125,22 +126,23 @@ uiBox *makePage16(void)
mh.SetCellValue = modelSetCellValue;
m = uiNewTableModel(&mh);
t = uiNewTable(m);
memset(&p, 0, sizeof (uiTableParams));
p.Model = m;
p.RowBackgroundColorModelColumn = 3;
t = uiNewTable(&p);
uiBoxAppend(page16, uiControl(t), 1);
uiTableAppendTextColumn(t, "Column 1",
0, uiTableModelColumnNeverEditable, NULL);
memset(&p, 0, sizeof (uiTableTextColumnOptionalParams));
p.ColorModelColumn = 4;
memset(&tp, 0, sizeof (uiTableTextColumnOptionalParams));
tp.ColorModelColumn = 4;
uiTableAppendImageTextColumn(t, "Column 2",
5,
1, uiTableModelColumnNeverEditable, &p);
1, uiTableModelColumnNeverEditable, &tp);
uiTableAppendTextColumn(t, "Editable",
2, uiTableModelColumnAlwaysEditable, NULL);
uiTableSetRowBackgroundColorModelColumn(t, 3);
uiTableAppendCheckboxColumn(t, "Checkboxes",
7, uiTableModelColumnAlwaysEditable);
uiTableAppendButtonColumn(t, "Buttons",

View File

@ -58,11 +58,17 @@ _UI_EXTERN void uiTableModelRowDeleted(uiTableModel *m, int oldIndex);
#define uiTableModelColumnAlwaysEditable (-2)
typedef struct uiTableTextColumnOptionalParams uiTableTextColumnOptionalParams;
typedef struct uiTableParams uiTableParams;
struct uiTableTextColumnOptionalParams {
int ColorModelColumn;
};
struct uiTableParams {
uiTableModel *Model;
int RowBackgroundColorModelColumn;
};
typedef struct uiTable uiTable;
#define uiTable(this) ((uiTable *) (this))
_UI_EXTERN void uiTableAppendTextColumn(uiTable *t,
@ -97,6 +103,4 @@ _UI_EXTERN void uiTableAppendButtonColumn(uiTable *t,
const char *name,
int buttonModelColumn,
int buttonClickableModelColumn);
// TODO getter?
_UI_EXTERN void uiTableSetRowBackgroundColorModelColumn(uiTable *t, int modelColumn);
_UI_EXTERN uiTable *uiNewTable(uiTableModel *model);
_UI_EXTERN uiTable *uiNewTable(uiTableParams *params);

View File

@ -413,21 +413,15 @@ static void uiTableDestroy(uiControl *c)
uiFreeControl(uiControl(t));
}
void uiTableSetRowBackgroundColorModelColumn(uiTable *t, int modelColumn)
{
t->backgroundColumn = modelColumn;
// TODO refresh table
}
uiTable *uiNewTable(uiTableModel *model)
uiTable *uiNewTable(uiTableParams *p)
{
uiTable *t;
uiUnixNewControl(uiTable, t);
t->model = model;
t->model = p->Model;
t->columnParams = g_ptr_array_new();
t->backgroundColumn = -1;
t->backgroundColumn = p->RowBackgroundColorModelColumn;
t->widget = gtk_scrolled_window_new(NULL, NULL);
t->scontainer = GTK_CONTAINER(t->widget);

View File

@ -478,14 +478,7 @@ void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonModelColu
p->buttonClickableModelColumn = buttonClickableModelColumn;
}
void uiTableSetRowBackgroundColorModelColumn(uiTable *t, int modelColumn)
{
// TODO make the names consistent
t->backgroundColumn = modelColumn;
// TODO redraw?
}
uiTable *uiNewTable(uiTableModel *model)
uiTable *uiNewTable(uiTableParams *p)
{
uiTable *t;
int n;
@ -494,14 +487,16 @@ uiTable *uiNewTable(uiTableModel *model)
uiWindowsNewControl(uiTable, t);
t->columns = new std::vector<uiprivTableColumnParams *>;
t->model = model;
t->model = p->Model;
t->backgroundColumn = p->RowBackgroundColorModelColumn;
// WS_CLIPCHILDREN is here to prevent drawing over the edit box used for editing text
t->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE,
WC_LISTVIEW, L"",
LVS_REPORT | LVS_OWNERDATA | LVS_SINGLESEL | WS_CLIPCHILDREN | WS_TABSTOP | WS_HSCROLL | WS_VSCROLL,
hInstance, NULL,
TRUE);
model->tables->push_back(t);
t->model->tables->push_back(t);
uiWindowsRegisterWM_NOTIFYHandler(t->hwnd, onWM_NOTIFY, uiControl(t));
// TODO: try LVS_EX_AUTOSIZECOLUMNS
@ -509,12 +504,10 @@ uiTable *uiNewTable(uiTableModel *model)
SendMessageW(t->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
(WPARAM) (LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP | LVS_EX_SUBITEMIMAGES),
(LPARAM) (LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP | LVS_EX_SUBITEMIMAGES));
n = uiprivTableModelNumRows(model);
n = uiprivTableModelNumRows(t->model);
if (SendMessageW(t->hwnd, LVM_SETITEMCOUNT, (WPARAM) n, 0) == 0)
logLastError(L"error calling LVM_SETITEMCOUNT in uiNewTable()");
t->backgroundColumn = -1;
hr = uiprivUpdateImageListSize(t);
if (hr != S_OK) {
// TODO