wmaker: Fix compiler warnings about pointer <--> integer conversion
[wmaker-crm.git] / WINGs / Extras / test.c
blobe37b11e78f8c0ab0482912e80f1576f51dbabc46
3 #include <WINGs/WINGs.h>
4 #include <stdio.h>
5 #include <stdint.h>
6 #include "wtableview.h"
7 #include "wtabledelegates.h"
10 static char *col1[20] = {0};
11 static int col2[20];
14 static char *options[] = {
15 "Option1",
16 "Option2",
17 "Option3",
18 "Option4",
19 "Option5"
23 int
24 numberOfRows(WMTableViewDelegate *self, WMTableView *table)
26 return 20;
30 void*
31 valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row)
33 /*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column);*/
34 int i;
35 if (col1[0] == 0) {
36 for (i = 0; i < 20; i++) {
37 char buf[128];
39 sprintf(buf, "Test row %i", i);
41 col1[i] = wstrdup(buf);
42 col2[i] = 0;
45 if ((int)(uintptr_t)WMGetTableColumnId(column) == 1)
46 return col1[row];
47 else
48 return (void*)(uintptr_t)col2[row];
52 void
53 setValueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row,
54 void *data)
56 if ((int)(uintptr_t)WMGetTableColumnId(column) == 1)
57 col1[row] = data;
58 else
59 col2[row] = (int)(uintptr_t)data;
63 static WMTableViewDelegate delegate = {
64 NULL,
65 numberOfRows,
66 valueForCell,
67 setValueForCell
72 void
73 clickedTable(WMWidget *w, void *self)
75 int row = WMGetTableViewClickedRow((WMTableView*)self);
77 WMEditTableViewRow(self, row);
82 int
83 main(int argc, char **argv)
85 WMScreen *scr;
86 WMWindow *win;
87 WMTableView *table;
88 WMTableColumn *col;
89 WMTableColumnDelegate *colDeleg;
91 WMInitializeApplication("test", &argc, argv);
93 scr = WMOpenScreen(NULL);
95 XSynchronize(WMScreenDisplay(scr), 1);
97 win = WMCreateWindow(scr, "eweq");
98 WMResizeWidget(win, 400, 200);
99 WMMapWidget(win);
101 table = WMCreateTableView(win);
102 WMSetTableViewHasHorizontalScroller(table, 0);
103 WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
104 WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
105 /*WMSetTableViewGridColor(table, WMGrayColor(scr));*/
106 WMSetTableViewHeaderHeight(table, 20);
107 WMSetTableViewDelegate(table, &delegate);
108 WMSetTableViewAction(table, clickedTable, table);
110 colDeleg = WTCreateStringEditorDelegate(table);
112 col = WMCreateTableColumn("Group");
113 WMSetTableColumnWidth(col, 180);
114 WMAddTableViewColumn(table, col);
115 WMSetTableColumnDelegate(col, colDeleg);
116 WMSetTableColumnId(col, (void*)1);
118 colDeleg = WTCreateEnumSelectorDelegate(table);
119 WTSetEnumSelectorOptions(colDeleg, options, 5);
121 col = WMCreateTableColumn("Package");
122 WMSetTableColumnWidth(col, 140);
123 WMAddTableViewColumn(table, col);
124 WMSetTableColumnDelegate(col, colDeleg);
125 WMSetTableColumnId(col, (void*)2);
127 colDeleg = WTCreateBooleanSwitchDelegate(table);
129 col = WMCreateTableColumn("Bool");
130 WMSetTableColumnWidth(col, 50);
131 WMAddTableViewColumn(table, col);
132 WMSetTableColumnDelegate(col, colDeleg);
133 WMSetTableColumnId(col, (void*)2);
135 WMMapWidget(table);
136 WMRealizeWidget(win);
137 WMScreenMainLoop(scr);
139 return 0;