Started converting the test program. First column works fine, second segfaults.

This commit is contained in:
Pietro Gagliardi 2018-06-03 23:23:48 -04:00
parent 2b428d50f6
commit 3bb050777b
3 changed files with 177 additions and 38 deletions

143
test/OLD_page16.c Normal file
View File

@ -0,0 +1,143 @@
// 21 june 2016
#include "test.h"
static uiTableModelHandler mh;
static int modelNumColumns(uiTableModelHandler *mh, uiTableModel *m)
{
return 9;
}
static uiTableModelColumnType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column)
{
if (column == 3 || column == 4)
return uiTableModelColumnColor;
if (column == 5)
return uiTableModelColumnImage;
if (column == 7 || column == 8)
return uiTableModelColumnInt;
return uiTableModelColumnString;
}
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];
static void *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col)
{
char buf[256];
if (col == 3) {
if (row == yellowRow)
return uiTableModelGiveColor(1, 1, 0, 1);
if (row == 3)
return uiTableModelGiveColor(1, 0, 0, 1);
if (row == 11)
return uiTableModelGiveColor(0, 0.5, 1, 0.5);
return NULL;
}
if (col == 4) {
if ((row % 2) == 1)
return uiTableModelGiveColor(0.5, 0, 0.75, 1);
return NULL;
}
if (col == 5) {
if (row < 8)
return img[0];
return img[1];
}
if (col == 7)
return uiTableModelGiveInt(checkStates[row]);
if (col == 8) {
if (row == 0)
return uiTableModelGiveInt(0);
if (row == 13)
return uiTableModelGiveInt(100);
if (row == 14)
return uiTableModelGiveInt(-1);
return uiTableModelGiveInt(50);
}
switch (col) {
case 0:
sprintf(buf, "Row %d", row);
break;
case 2:
if (row == 9)
return uiTableModelStrdup(row9text);
// fall through
case 1:
strcpy(buf, "Part");
break;
case 6:
strcpy(buf, "Make Yellow");
break;
}
return uiTableModelStrdup(buf);
}
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col, const void *val)
{
if (row == 9 && col == 2)
strcpy(row9text, (const char *) val);
if (col == 6)
yellowRow = row;
if (col == 7)
checkStates[row] = uiTableModelTakeInt(val);
}
uiBox *makePage16(void)
{
uiBox *page16;
uiTableModel *m;
uiTable *t;
uiTableColumn *tc;
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);
t = uiNewTable(m);
uiBoxAppend(page16, uiControl(t), 1);
uiTableAppendTextColumn(t, "Column 1", 0);
tc = uiTableAppendColumn(t, "Column 2");
uiTableColumnAppendImagePart(tc, 5, 0);
uiTableColumnAppendTextPart(tc, 1, 0);
uiTableColumnAppendTextPart(tc, 2, 1);
uiTableColumnPartSetTextColor(tc, 1, 4);
uiTableColumnPartSetEditable(tc, 2, 1);
uiTableSetRowBackgroundColorModelColumn(t, 3);
tc = uiTableAppendColumn(t, "Buttons");
uiTableColumnAppendCheckboxPart(tc, 7, 0);
uiTableColumnAppendButtonPart(tc, 6, 1);
tc = uiTableAppendColumn(t, "Progress Bar");
uiTableColumnAppendProgressBarPart(tc, 8, 0);
return page16;
}

View File

@ -8,15 +8,15 @@ static int modelNumColumns(uiTableModelHandler *mh, uiTableModel *m)
return 9;
}
static uiTableModelColumnType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column)
static uiTableDataType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column)
{
if (column == 3 || column == 4)
return uiTableModelColumnColor;
return uiTableDataTypeColor;
if (column == 5)
return uiTableModelColumnImage;
return uiTableDataTypeImage;
if (column == 7 || column == 8)
return uiTableModelColumnInt;
return uiTableModelColumnString;
return uiTableDataTypeInt;
return uiTableDataTypeString;
}
static int modelNumRows(uiTableModelHandler *mh, uiTableModel *m)
@ -29,39 +29,39 @@ static char row9text[1024];
static int yellowRow = -1;
static int checkStates[15];
static void *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col)
static uiTableData *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col)
{
char buf[256];
if (col == 3) {
if (row == yellowRow)
return uiTableModelGiveColor(1, 1, 0, 1);
return uiNewTableDataColor(1, 1, 0, 1);
if (row == 3)
return uiTableModelGiveColor(1, 0, 0, 1);
return uiNewTableDataColor(1, 0, 0, 1);
if (row == 11)
return uiTableModelGiveColor(0, 0.5, 1, 0.5);
return uiNewTableDataColor(0, 0.5, 1, 0.5);
return NULL;
}
if (col == 4) {
if ((row % 2) == 1)
return uiTableModelGiveColor(0.5, 0, 0.75, 1);
return uiNewTableDataColor(0.5, 0, 0.75, 1);
return NULL;
}
if (col == 5) {
if (row < 8)
return img[0];
return img[1];
return uiNewTableDataImage(img[0]);
return uiNewTableDataImage(img[1]);
}
if (col == 7)
return uiTableModelGiveInt(checkStates[row]);
return uiNewTableDataInt(checkStates[row]);
if (col == 8) {
if (row == 0)
return uiTableModelGiveInt(0);
return uiNewTableDataInt(0);
if (row == 13)
return uiTableModelGiveInt(100);
return uiNewTableDataInt(100);
if (row == 14)
return uiTableModelGiveInt(-1);
return uiTableModelGiveInt(50);
return uiNewTableDataInt(-1);
return uiNewTableDataInt(50);
}
switch (col) {
case 0:
@ -69,7 +69,7 @@ static void *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, i
break;
case 2:
if (row == 9)
return uiTableModelStrdup(row9text);
return uiNewTableDataString(row9text);
// fall through
case 1:
strcpy(buf, "Part");
@ -78,17 +78,17 @@ static void *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, i
strcpy(buf, "Make Yellow");
break;
}
return uiTableModelStrdup(buf);
return uiNewTableDataString(buf);
}
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col, const void *val)
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col, const uiTableData *val)
{
if (row == 9 && col == 2)
strcpy(row9text, (const char *) val);
strcpy(row9text, uiTableDataString(val));
if (col == 6)
yellowRow = row;
if (col == 7)
checkStates[row] = uiTableModelTakeInt(val);
checkStates[row] = uiTableDataInt(val);
}
uiBox *makePage16(void)
@ -96,7 +96,7 @@ uiBox *makePage16(void)
uiBox *page16;
uiTableModel *m;
uiTable *t;
uiTableColumn *tc;
uiTableTextColumnOptionalParams p;
img[0] = uiNewImage(16, 16);
appendImageNamed(img[0], "andlabs_16x16test_24june2016.png");
@ -121,15 +121,18 @@ uiBox *makePage16(void)
t = uiNewTable(m);
uiBoxAppend(page16, uiControl(t), 1);
uiTableAppendTextColumn(t, "Column 1", 0);
uiTableAppendTextColumn(t, "Column 1",
0, uiTableModelColumnNeverEditable, NULL);
tc = uiTableAppendColumn(t, "Column 2");
uiTableColumnAppendImagePart(tc, 5, 0);
uiTableColumnAppendTextPart(tc, 1, 0);
uiTableColumnAppendTextPart(tc, 2, 1);
uiTableColumnPartSetTextColor(tc, 1, 4);
uiTableColumnPartSetEditable(tc, 2, 1);
memset(&p, 0, sizeof (uiTableTextColumnOptionalParams));
p.ColorModelColumn = 4;
uiTableAppendImageTextColumn(t, "Column 2",
5,
1, uiTableModelColumnNeverEditable, &p);
uiTableAppendTextColumn(t, "Editable",
2, uiTableModelColumnAlwaysEditable, NULL);
#if 0
uiTableSetRowBackgroundColorModelColumn(t, 3);
tc = uiTableAppendColumn(t, "Buttons");
@ -138,6 +141,7 @@ uiBox *makePage16(void)
tc = uiTableAppendColumn(t, "Progress Bar");
uiTableColumnAppendProgressBarPart(tc, 8, 0);
#endif
return page16;
}

View File

@ -47,14 +47,6 @@ struct uiTableModelHandler {
void (*SetCellValue)(uiTableModelHandler *, uiTableModel *, int, int, const uiTableData *);
};
_UI_EXTERN void *uiTableModelStrdup(const char *str);
// TODO rename the strdup one to this too
_UI_EXTERN void *uiTableModelGiveColor(double r, double g, double b, double a);
_UI_EXTERN void *uiTableModelGiveInt(int i);
// TODO TakeString
// TODO add const
_UI_EXTERN int uiTableModelTakeInt(void *v);
_UI_EXTERN uiTableModel *uiNewTableModel(uiTableModelHandler *mh);
_UI_EXTERN void uiFreeTableModel(uiTableModel *m);
_UI_EXTERN void uiTableModelRowInserted(uiTableModel *m, int newIndex);