Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / Extras / test.c
blobe3c4d6b86506bf96a6b1fdb603c630e6bab8cb80
2 #include <WINGs/WINGs.h>
3 #include <stdio.h>
4 #include <stdint.h>
5 #include "wtableview.h"
6 #include "wtabledelegates.h"
8 static char *col1[20] = { 0 };
10 static int col2[20];
12 static char *options[] = {
13 "Option1",
14 "Option2",
15 "Option3",
16 "Option4",
17 "Option5"
20 int numberOfRows(WMTableViewDelegate * self, WMTableView * table)
22 return 20;
25 void *valueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row)
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];
33 sprintf(buf, "Test row %i", i);
35 col1[i] = wstrdup(buf);
36 col2[i] = 0;
39 if ((int)(uintptr_t) WMGetTableColumnId(column) == 1)
40 return col1[row];
41 else
42 return (void *)(uintptr_t) col2[row];
45 void setValueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row, void *data)
47 if ((int)(uintptr_t) WMGetTableColumnId(column) == 1)
48 col1[row] = data;
49 else
50 col2[row] = (int)(uintptr_t) data;
53 static WMTableViewDelegate delegate = {
54 NULL,
55 numberOfRows,
56 valueForCell,
57 setValueForCell
60 void clickedTable(WMWidget * w, void *self)
62 int row = WMGetTableViewClickedRow((WMTableView *) self);
64 WMEditTableViewRow(self, row);
67 int main(int argc, char **argv)
69 WMScreen *scr;
70 WMWindow *win;
71 WMTableView *table;
72 WMTableColumn *col;
73 WMTableColumnDelegate *colDeleg;
75 WMInitializeApplication("test", &argc, argv);
77 scr = WMOpenScreen(NULL);
79 XSynchronize(WMScreenDisplay(scr), 1);
81 win = WMCreateWindow(scr, "eweq");
82 WMResizeWidget(win, 400, 200);
83 WMMapWidget(win);
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);
94 colDeleg = WTCreateStringEditorDelegate(table);
96 col = WMCreateTableColumn("Group");
97 WMSetTableColumnWidth(col, 180);
98 WMAddTableViewColumn(table, col);
99 WMSetTableColumnDelegate(col, colDeleg);
100 WMSetTableColumnId(col, (void *)1);
102 colDeleg = WTCreateEnumSelectorDelegate(table);
103 WTSetEnumSelectorOptions(colDeleg, options, 5);
105 col = WMCreateTableColumn("Package");
106 WMSetTableColumnWidth(col, 140);
107 WMAddTableViewColumn(table, col);
108 WMSetTableColumnDelegate(col, colDeleg);
109 WMSetTableColumnId(col, (void *)2);
111 colDeleg = WTCreateBooleanSwitchDelegate(table);
113 col = WMCreateTableColumn("Bool");
114 WMSetTableColumnWidth(col, 50);
115 WMAddTableViewColumn(table, col);
116 WMSetTableColumnDelegate(col, colDeleg);
117 WMSetTableColumnId(col, (void *)2);
119 WMMapWidget(table);
120 WMRealizeWidget(win);
121 WMScreenMainLoop(scr);
123 return 0;