Files
wmaker/WINGs/Extras/test.c
T

135 lines
2.8 KiB
C
Raw Normal View History

2000-12-21 04:46:20 +00:00
#include <WINGs/WINGs.h>
#include <stdio.h>
2000-12-21 04:46:20 +00:00
#include "wtableview.h"
2001-01-06 17:20:46 +00:00
#include "wtabledelegates.h"
2000-12-21 04:46:20 +00:00
static char *col1[20] = {0};
static int col2[20];
static char *options[] = {
"Option1",
"Option2",
"Option3",
"Option4",
"Option5"
};
2000-12-21 04:46:20 +00:00
int numberOfRows(WMTableViewDelegate *self, WMTableView *table)
{
return 20;
}
void *valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row)
{
/*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column);*/
int i;
if (col1[0] == 0) {
for (i = 0; i < 20; i++) {
2001-05-17 22:30:38 +00:00
char buf[128];
sprintf(buf, "Test row %i", i);
2001-05-17 22:30:38 +00:00
col1[i] = wstrdup(buf);
col2[i] = 0;
}
}
2001-01-06 01:52:27 +00:00
if ((int)WMGetTableColumnId(column) == 1)
return col1[row];
else
2001-01-06 01:52:27 +00:00
return (void*)col2[row];
}
void setValueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row,
void *data)
{
2001-01-06 16:42:16 +00:00
if ((int)WMGetTableColumnId(column) == 1)
col1[row] = data;
else
2001-01-06 01:52:27 +00:00
col2[row] = (int)data;
2000-12-21 04:46:20 +00:00
}
static WMTableViewDelegate delegate = {
NULL,
numberOfRows,
valueForCell,
setValueForCell
2000-12-21 04:46:20 +00:00
};
2001-01-02 14:17:26 +00:00
void clickedTable(WMWidget *w, void *self)
{
2001-01-02 14:17:26 +00:00
int row = WMGetTableViewClickedRow((WMTableView*)self);
WMEditTableViewRow(self, row);
}
int
2000-12-21 04:46:20 +00:00
main(int argc, char **argv)
{
WMScreen *scr;
WMWindow *win;
WMTableView *table;
WMTableColumn *col;
WMTableColumnDelegate *colDeleg;
WMInitializeApplication("test", &argc, argv);
2001-03-14 04:19:06 +00:00
scr = WMOpenScreen(NULL);
2000-12-21 04:46:20 +00:00
2001-05-17 22:30:38 +00:00
XSynchronize(WMScreenDisplay(scr), 1);
2000-12-21 04:46:20 +00:00
win = WMCreateWindow(scr, "eweq");
WMResizeWidget(win, 400, 200);
WMMapWidget(win);
table = WMCreateTableView(win);
2001-05-17 22:30:38 +00:00
WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
2000-12-21 04:46:20 +00:00
WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
/*WMSetTableViewGridColor(table, WMGrayColor(scr));*/
2000-12-21 04:46:20 +00:00
WMSetTableViewHeaderHeight(table, 20);
WMSetTableViewDelegate(table, &delegate);
2001-01-02 14:17:26 +00:00
WMSetTableViewAction(table, clickedTable, table);
2000-12-21 04:46:20 +00:00
colDeleg = WTCreateStringEditorDelegate(table);
2000-12-21 04:46:20 +00:00
col = WMCreateTableColumn("Group");
WMSetTableColumnWidth(col, 180);
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void*)1);
colDeleg = WTCreateEnumSelectorDelegate(table);
WTSetEnumSelectorOptions(colDeleg, options, 5);
2000-12-21 04:46:20 +00:00
col = WMCreateTableColumn("Package");
WMSetTableColumnWidth(col, 140);
2000-12-21 04:46:20 +00:00
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void*)2);
2001-01-02 14:17:26 +00:00
colDeleg = WTCreateBooleanSwitchDelegate(table);
col = WMCreateTableColumn("Bool");
WMSetTableColumnWidth(col, 50);
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void*)2);
2000-12-21 04:46:20 +00:00
WMMapWidget(table);
WMRealizeWidget(win);
WMScreenMainLoop(scr);
return 0;
2000-12-21 04:46:20 +00:00
}