Update Serbian translation from master branch
[wmaker-crm.git] / WINGs / Extras / tableview.c
blobc478369016a782bb9a8fe40c903f83b4f528acef
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 (void) self;
23 (void) table;
25 return 20;
28 void *valueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row)
30 (void) self;
31 /*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column); */
32 int i;
34 if (col1[0] == 0) {
35 for (i = 0; i < 20; i++) {
36 char buf[128];
38 sprintf(buf, "Test row %i", i);
40 col1[i] = wstrdup(buf);
41 col2[i] = 0;
44 if ((uintptr_t)WMGetTableColumnId(column) == 1)
45 return col1[row];
46 else
47 return (void *)(uintptr_t) col2[row];
50 void setValueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row, void *data)
52 (void) self;
54 if ((uintptr_t)WMGetTableColumnId(column) == 1)
55 col1[row] = data;
56 else
57 col2[row] = (uintptr_t) data;
60 static WMTableViewDelegate delegate = {
61 NULL,
62 numberOfRows,
63 valueForCell,
64 setValueForCell
67 void clickedTable(WMWidget * w, void *self)
69 (void) w;
70 int row = WMGetTableViewClickedRow((WMTableView *) self);
72 WMEditTableViewRow(self, row);
75 int main(int argc, char **argv)
77 WMScreen *scr;
78 WMWindow *win;
79 WMTableView *table;
80 WMTableColumn *col;
81 WMTableColumnDelegate *colDeleg;
83 WMInitializeApplication("test", &argc, argv);
85 scr = WMOpenScreen(NULL);
87 XSynchronize(WMScreenDisplay(scr), 1);
89 win = WMCreateWindow(scr, "eweq");
90 WMResizeWidget(win, 400, 200);
91 WMMapWidget(win);
93 table = WMCreateTableView(win);
94 WMSetTableViewHasHorizontalScroller(table, 0);
95 WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
96 WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
97 /*WMSetTableViewGridColor(table, WMGrayColor(scr)); */
98 WMSetTableViewHeaderHeight(table, 20);
99 WMSetTableViewDelegate(table, &delegate);
100 WMSetTableViewAction(table, clickedTable, table);
102 colDeleg = WTCreateStringEditorDelegate(table);
104 col = WMCreateTableColumn("Group");
105 WMSetTableColumnWidth(col, 180);
106 WMAddTableViewColumn(table, col);
107 WMSetTableColumnDelegate(col, colDeleg);
108 WMSetTableColumnId(col, (void *)1);
110 colDeleg = WTCreateEnumSelectorDelegate(table);
111 WTSetEnumSelectorOptions(colDeleg, options, 5);
113 col = WMCreateTableColumn("Package");
114 WMSetTableColumnWidth(col, 140);
115 WMAddTableViewColumn(table, col);
116 WMSetTableColumnDelegate(col, colDeleg);
117 WMSetTableColumnId(col, (void *)2);
119 colDeleg = WTCreateBooleanSwitchDelegate(table);
121 col = WMCreateTableColumn("Bool");
122 WMSetTableColumnWidth(col, 50);
123 WMAddTableViewColumn(table, col);
124 WMSetTableColumnDelegate(col, colDeleg);
125 WMSetTableColumnId(col, (void *)2);
127 WMMapWidget(table);
128 WMRealizeWidget(win);
129 WMScreenMainLoop(scr);
131 return 0;