- Added WMSetTableViewHasHorizontalScroller()
[wmaker-crm.git] / WINGs / Extras / test.c
blob3874112df7c620f78c1f45bdb8647ad344e98aa7
3 #include <WINGs/WINGs.h>
4 #include <stdio.h>
5 #include "wtableview.h"
6 #include "wtabledelegates.h"
9 static char *col1[20] = {0};
10 static int col2[20];
13 static char *options[] = {
14 "Option1",
15 "Option2",
16 "Option3",
17 "Option4",
18 "Option5"
22 int numberOfRows(WMTableViewDelegate *self, WMTableView *table)
24 return 20;
28 void *valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row)
30 /*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column);*/
31 int i;
32 if (col1[0] == 0) {
33 for (i = 0; i < 20; i++) {
34 char buf[128];
36 sprintf(buf, "Test row %i", i);
38 col1[i] = wstrdup(buf);
39 col2[i] = 0;
42 if ((int)WMGetTableColumnId(column) == 1)
43 return col1[row];
44 else
45 return (void*)col2[row];
49 void setValueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row,
50 void *data)
52 if ((int)WMGetTableColumnId(column) == 1)
53 col1[row] = data;
54 else
55 col2[row] = (int)data;
59 static WMTableViewDelegate delegate = {
60 NULL,
61 numberOfRows,
62 valueForCell,
63 setValueForCell
68 void clickedTable(WMWidget *w, void *self)
70 int row = WMGetTableViewClickedRow((WMTableView*)self);
72 WMEditTableViewRow(self, row);
77 int
78 main(int argc, char **argv)
80 WMScreen *scr;
81 WMWindow *win;
82 WMTableView *table;
83 WMTableColumn *col;
84 WMTableColumnDelegate *colDeleg;
86 WMInitializeApplication("test", &argc, argv);
88 scr = WMOpenScreen(NULL);
90 XSynchronize(WMScreenDisplay(scr), 1);
92 win = WMCreateWindow(scr, "eweq");
93 WMResizeWidget(win, 400, 200);
94 WMMapWidget(win);
96 table = WMCreateTableView(win);
97 WMSetTableViewHasHorizontalScroller(table, 0);
98 WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
99 WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
100 /*WMSetTableViewGridColor(table, WMGrayColor(scr));*/
101 WMSetTableViewHeaderHeight(table, 20);
102 WMSetTableViewDelegate(table, &delegate);
103 WMSetTableViewAction(table, clickedTable, table);
105 colDeleg = WTCreateStringEditorDelegate(table);
107 col = WMCreateTableColumn("Group");
108 WMSetTableColumnWidth(col, 180);
109 WMAddTableViewColumn(table, col);
110 WMSetTableColumnDelegate(col, colDeleg);
111 WMSetTableColumnId(col, (void*)1);
113 colDeleg = WTCreateEnumSelectorDelegate(table);
114 WTSetEnumSelectorOptions(colDeleg, options, 5);
116 col = WMCreateTableColumn("Package");
117 WMSetTableColumnWidth(col, 140);
118 WMAddTableViewColumn(table, col);
119 WMSetTableColumnDelegate(col, colDeleg);
120 WMSetTableColumnId(col, (void*)2);
122 colDeleg = WTCreateBooleanSwitchDelegate(table);
124 col = WMCreateTableColumn("Bool");
125 WMSetTableColumnWidth(col, 50);
126 WMAddTableViewColumn(table, col);
127 WMSetTableColumnDelegate(col, colDeleg);
128 WMSetTableColumnId(col, (void*)2);
130 WMMapWidget(table);
131 WMRealizeWidget(win);
132 WMScreenMainLoop(scr);
134 return 0;