fixed tableview overflow bug
[wmaker-crm.git] / WINGs / Extras / test.c
blobf3e6a877bc1e4ac3cde81b6d27e41226e30a0bbe
3 #include <WINGs/WINGs.h>
4 #include "wtableview.h"
5 #include "wtabledelegates.h"
8 static char *col1[20] = {0};
9 static int col2[20];
12 static char *options[] = {
13 "Option1",
14 "Option2",
15 "Option3",
16 "Option4",
17 "Option5"
21 int numberOfRows(WMTableViewDelegate *self, WMTableView *table)
23 return 20;
27 void *valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row)
29 /*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column);*/
30 int i;
31 if (col1[0] == 0) {
32 for (i = 0; i < 20; i++) {
33 char buf[128];
35 sprintf(buf, "Test row %i", i);
37 col1[i] = wstrdup(buf);
38 col2[i] = 0;
41 if ((int)WMGetTableColumnId(column) == 1)
42 return col1[row];
43 else
44 return (void*)col2[row];
48 void setValueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row,
49 void *data)
51 if ((int)WMGetTableColumnId(column) == 1)
52 col1[row] = data;
53 else
54 col2[row] = (int)data;
58 static WMTableViewDelegate delegate = {
59 NULL,
60 numberOfRows,
61 valueForCell,
62 setValueForCell
67 void clickedTable(WMWidget *w, void *self)
69 int row = WMGetTableViewClickedRow((WMTableView*)self);
71 WMEditTableViewRow(self, row);
77 main(int argc, char **argv)
79 WMScreen *scr;
80 WMWindow *win;
81 WMTableView *table;
82 WMTableColumn *col;
83 WMTableColumnDelegate *colDeleg;
85 WMInitializeApplication("test", &argc, argv);
87 scr = WMOpenScreen(NULL);
89 XSynchronize(WMScreenDisplay(scr), 1);
91 win = WMCreateWindow(scr, "eweq");
92 WMResizeWidget(win, 400, 200);
93 WMMapWidget(win);
95 table = WMCreateTableView(win);
96 WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
97 WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
98 /*WMSetTableViewGridColor(table, WMGrayColor(scr));*/
99 WMSetTableViewHeaderHeight(table, 20);
100 WMSetTableViewDelegate(table, &delegate);
101 WMSetTableViewAction(table, clickedTable, table);
103 colDeleg = WTCreateStringEditorDelegate(table);
105 col = WMCreateTableColumn("Group");
106 WMSetTableColumnWidth(col, 180);
107 WMAddTableViewColumn(table, col);
108 WMSetTableColumnDelegate(col, colDeleg);
109 WMSetTableColumnId(col, (void*)1);
111 colDeleg = WTCreateEnumSelectorDelegate(table);
112 WTSetEnumSelectorOptions(colDeleg, options, 5);
114 col = WMCreateTableColumn("Package");
115 WMSetTableColumnWidth(col, 140);
116 WMAddTableViewColumn(table, col);
117 WMSetTableColumnDelegate(col, colDeleg);
118 WMSetTableColumnId(col, (void*)2);
120 colDeleg = WTCreateBooleanSwitchDelegate(table);
122 col = WMCreateTableColumn("Bool");
123 WMSetTableColumnWidth(col, 50);
124 WMAddTableViewColumn(table, col);
125 WMSetTableColumnDelegate(col, colDeleg);
126 WMSetTableColumnId(col, (void*)2);
128 WMMapWidget(table);
129 WMRealizeWidget(win);
130 WMScreenMainLoop(scr);