2016-11-27 16:36:11 -06:00
|
|
|
// 21 june 2016
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
static uiTableModelHandler mh;
|
|
|
|
|
|
|
|
static int modelNumColumns(uiTableModelHandler *mh, uiTableModel *m)
|
|
|
|
{
|
|
|
|
return 9;
|
|
|
|
}
|
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
static uiTableValueType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column)
|
2016-11-27 16:36:11 -06:00
|
|
|
{
|
|
|
|
if (column == 3 || column == 4)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiTableValueTypeColor;
|
2016-11-27 16:36:11 -06:00
|
|
|
if (column == 5)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiTableValueTypeImage;
|
2016-11-27 16:36:11 -06:00
|
|
|
if (column == 7 || column == 8)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiTableValueTypeInt;
|
|
|
|
return uiTableValueTypeString;
|
2016-11-27 16:36:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int modelNumRows(uiTableModelHandler *mh, uiTableModel *m)
|
|
|
|
{
|
|
|
|
return 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uiImage *img[2];
|
|
|
|
static char row9text[1024];
|
|
|
|
static int yellowRow = -1;
|
|
|
|
static int checkStates[15];
|
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
static uiTableValue *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col)
|
2016-11-27 16:36:11 -06:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if (col == 3) {
|
|
|
|
if (row == yellowRow)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueColor(1, 1, 0, 1);
|
2016-11-27 16:36:11 -06:00
|
|
|
if (row == 3)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueColor(1, 0, 0, 1);
|
2016-11-27 16:36:11 -06:00
|
|
|
if (row == 11)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueColor(0, 0.5, 1, 0.5);
|
2016-11-27 16:36:11 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (col == 4) {
|
|
|
|
if ((row % 2) == 1)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueColor(0.5, 0, 0.75, 1);
|
2016-11-27 16:36:11 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (col == 5) {
|
|
|
|
if (row < 8)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueImage(img[0]);
|
|
|
|
return uiNewTableValueImage(img[1]);
|
2016-11-27 16:36:11 -06:00
|
|
|
}
|
|
|
|
if (col == 7)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueInt(checkStates[row]);
|
2016-11-27 16:36:11 -06:00
|
|
|
if (col == 8) {
|
|
|
|
if (row == 0)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueInt(0);
|
2016-11-27 16:36:11 -06:00
|
|
|
if (row == 13)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueInt(100);
|
2016-11-27 16:36:11 -06:00
|
|
|
if (row == 14)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueInt(-1);
|
|
|
|
return uiNewTableValueInt(50);
|
2016-11-27 16:36:11 -06:00
|
|
|
}
|
|
|
|
switch (col) {
|
|
|
|
case 0:
|
|
|
|
sprintf(buf, "Row %d", row);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (row == 9)
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueString(row9text);
|
2016-11-27 16:36:11 -06:00
|
|
|
// fall through
|
|
|
|
case 1:
|
|
|
|
strcpy(buf, "Part");
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
strcpy(buf, "Make Yellow");
|
|
|
|
break;
|
|
|
|
}
|
2018-06-23 19:19:30 -05:00
|
|
|
return uiNewTableValueString(buf);
|
2016-11-27 16:36:11 -06:00
|
|
|
}
|
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col, const uiTableValue *val)
|
2016-11-27 16:36:11 -06:00
|
|
|
{
|
|
|
|
if (row == 9 && col == 2)
|
2018-06-23 19:19:30 -05:00
|
|
|
strcpy(row9text, uiTableValueString(val));
|
2018-06-04 21:14:05 -05:00
|
|
|
if (col == 6) {
|
|
|
|
int prevYellowRow;
|
|
|
|
|
|
|
|
prevYellowRow = yellowRow;
|
2016-11-27 16:36:11 -06:00
|
|
|
yellowRow = row;
|
2018-06-04 21:14:05 -05:00
|
|
|
if (prevYellowRow != -1)
|
|
|
|
uiTableModelRowChanged(m, prevYellowRow);
|
|
|
|
uiTableModelRowChanged(m, yellowRow);
|
|
|
|
}
|
2016-11-27 16:36:11 -06:00
|
|
|
if (col == 7)
|
2018-06-23 19:19:30 -05:00
|
|
|
checkStates[row] = uiTableValueInt(val);
|
2016-11-27 16:36:11 -06:00
|
|
|
}
|
|
|
|
|
2018-07-08 20:20:42 -05:00
|
|
|
static uiTableModel *m;
|
|
|
|
|
2016-11-27 16:36:11 -06:00
|
|
|
uiBox *makePage16(void)
|
|
|
|
{
|
|
|
|
uiBox *page16;
|
|
|
|
uiTable *t;
|
2018-06-24 09:28:41 -05:00
|
|
|
uiTableParams p;
|
|
|
|
uiTableTextColumnOptionalParams tp;
|
2016-11-27 16:36:11 -06:00
|
|
|
|
|
|
|
img[0] = uiNewImage(16, 16);
|
|
|
|
appendImageNamed(img[0], "andlabs_16x16test_24june2016.png");
|
|
|
|
appendImageNamed(img[0], "andlabs_32x32test_24june2016.png");
|
|
|
|
img[1] = uiNewImage(16, 16);
|
|
|
|
appendImageNamed(img[1], "tango-icon-theme-0.8.90_16x16_x-office-spreadsheet.png");
|
|
|
|
appendImageNamed(img[1], "tango-icon-theme-0.8.90_32x32_x-office-spreadsheet.png");
|
|
|
|
|
|
|
|
strcpy(row9text, "Part");
|
|
|
|
|
|
|
|
memset(checkStates, 0, 15 * sizeof (int));
|
|
|
|
|
|
|
|
page16 = newVerticalBox();
|
|
|
|
|
|
|
|
mh.NumColumns = modelNumColumns;
|
|
|
|
mh.ColumnType = modelColumnType;
|
|
|
|
mh.NumRows = modelNumRows;
|
|
|
|
mh.CellValue = modelCellValue;
|
|
|
|
mh.SetCellValue = modelSetCellValue;
|
|
|
|
m = uiNewTableModel(&mh);
|
|
|
|
|
2018-06-24 09:28:41 -05:00
|
|
|
memset(&p, 0, sizeof (uiTableParams));
|
|
|
|
p.Model = m;
|
|
|
|
p.RowBackgroundColorModelColumn = 3;
|
|
|
|
t = uiNewTable(&p);
|
2016-11-27 16:36:11 -06:00
|
|
|
uiBoxAppend(page16, uiControl(t), 1);
|
|
|
|
|
2018-06-03 22:23:48 -05:00
|
|
|
uiTableAppendTextColumn(t, "Column 1",
|
|
|
|
0, uiTableModelColumnNeverEditable, NULL);
|
2016-11-27 16:36:11 -06:00
|
|
|
|
2018-06-24 09:28:41 -05:00
|
|
|
memset(&tp, 0, sizeof (uiTableTextColumnOptionalParams));
|
|
|
|
tp.ColorModelColumn = 4;
|
2018-06-03 22:23:48 -05:00
|
|
|
uiTableAppendImageTextColumn(t, "Column 2",
|
|
|
|
5,
|
2018-06-24 09:28:41 -05:00
|
|
|
1, uiTableModelColumnNeverEditable, &tp);
|
2018-06-03 22:23:48 -05:00
|
|
|
uiTableAppendTextColumn(t, "Editable",
|
|
|
|
2, uiTableModelColumnAlwaysEditable, NULL);
|
2016-11-27 16:36:11 -06:00
|
|
|
|
2018-06-04 19:13:35 -05:00
|
|
|
uiTableAppendCheckboxColumn(t, "Checkboxes",
|
|
|
|
7, uiTableModelColumnAlwaysEditable);
|
|
|
|
uiTableAppendButtonColumn(t, "Buttons",
|
|
|
|
6, uiTableModelColumnAlwaysEditable);
|
2016-11-27 16:36:11 -06:00
|
|
|
|
2018-06-04 19:13:35 -05:00
|
|
|
uiTableAppendProgressBarColumn(t, "Progress Bar",
|
|
|
|
8);
|
2016-11-27 16:36:11 -06:00
|
|
|
|
|
|
|
return page16;
|
|
|
|
}
|
2018-07-08 20:20:42 -05:00
|
|
|
|
|
|
|
void freePage16(void)
|
|
|
|
{
|
|
|
|
uiFreeTableModel(m);
|
|
|
|
uiFreeImage(img[1]);
|
|
|
|
uiFreeImage(img[0]);
|
|
|
|
}
|