Files
wmaker/WINGs/Extras/test.c
T

125 lines
2.7 KiB
C
Raw Normal View History

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