Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / Extras / test.c
1
2 #include <WINGs/WINGs.h>
3 #include <stdio.h>
4 #include <stdint.h>
5 #include "wtableview.h"
6 #include "wtabledelegates.h"
7
8 static char *col1[20] = { 0 };
9
10 static int col2[20];
11
12 static char *options[] = {
13 "Option1",
14 "Option2",
15 "Option3",
16 "Option4",
17 "Option5"
18 };
19
20 int numberOfRows(WMTableViewDelegate * self, WMTableView * table)
21 {
22 return 20;
23 }
24
25 void *valueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row)
26 {
27 /*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column); */
28 int i;
29 if (col1[0] == 0) {
30 for (i = 0; i < 20; i++) {
31 char buf[128];
32
33 sprintf(buf, "Test row %i", i);
34
35 col1[i] = wstrdup(buf);
36 col2[i] = 0;
37 }
38 }
39 if ((int)(uintptr_t) WMGetTableColumnId(column) == 1)
40 return col1[row];
41 else
42 return (void *)(uintptr_t) col2[row];
43 }
44
45 void setValueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row, void *data)
46 {
47 if ((int)(uintptr_t) WMGetTableColumnId(column) == 1)
48 col1[row] = data;
49 else
50 col2[row] = (int)(uintptr_t) data;
51 }
52
53 static WMTableViewDelegate delegate = {
54 NULL,
55 numberOfRows,
56 valueForCell,
57 setValueForCell
58 };
59
60 void clickedTable(WMWidget * w, void *self)
61 {
62 int row = WMGetTableViewClickedRow((WMTableView *) self);
63
64 WMEditTableViewRow(self, row);
65 }
66
67 int main(int argc, char **argv)
68 {
69 WMScreen *scr;
70 WMWindow *win;
71 WMTableView *table;
72 WMTableColumn *col;
73 WMTableColumnDelegate *colDeleg;
74
75 WMInitializeApplication("test", &argc, argv);
76
77 scr = WMOpenScreen(NULL);
78
79 XSynchronize(WMScreenDisplay(scr), 1);
80
81 win = WMCreateWindow(scr, "eweq");
82 WMResizeWidget(win, 400, 200);
83 WMMapWidget(win);
84
85 table = WMCreateTableView(win);
86 WMSetTableViewHasHorizontalScroller(table, 0);
87 WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
88 WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
89 /*WMSetTableViewGridColor(table, WMGrayColor(scr)); */
90 WMSetTableViewHeaderHeight(table, 20);
91 WMSetTableViewDelegate(table, &delegate);
92 WMSetTableViewAction(table, clickedTable, table);
93
94 colDeleg = WTCreateStringEditorDelegate(table);
95
96 col = WMCreateTableColumn("Group");
97 WMSetTableColumnWidth(col, 180);
98 WMAddTableViewColumn(table, col);
99 WMSetTableColumnDelegate(col, colDeleg);
100 WMSetTableColumnId(col, (void *)1);
101
102 colDeleg = WTCreateEnumSelectorDelegate(table);
103 WTSetEnumSelectorOptions(colDeleg, options, 5);
104
105 col = WMCreateTableColumn("Package");
106 WMSetTableColumnWidth(col, 140);
107 WMAddTableViewColumn(table, col);
108 WMSetTableColumnDelegate(col, colDeleg);
109 WMSetTableColumnId(col, (void *)2);
110
111 colDeleg = WTCreateBooleanSwitchDelegate(table);
112
113 col = WMCreateTableColumn("Bool");
114 WMSetTableColumnWidth(col, 50);
115 WMAddTableViewColumn(table, col);
116 WMSetTableColumnDelegate(col, colDeleg);
117 WMSetTableColumnId(col, (void *)2);
118
119 WMMapWidget(table);
120 WMRealizeWidget(win);
121 WMScreenMainLoop(scr);
122
123 return 0;
124 }