Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / Extras / test.c
Commit [+]AuthorDateLineData
f912d9f3 kojima2000-12-21 04:46:20 +00001
a20aebde dan2001-01-18 19:21:56 +00002#include <WINGs/WINGs.h>
33cc542e dan2001-10-04 03:07:34 +00003#include <stdio.h>
06f59b99 Carlos R. Mafra2008-11-06 01:37:44 +01004#include <stdint.h>
f912d9f3 kojima2000-12-21 04:46:20 +00005#include "wtableview.h"
c6c09547 kojima2001-01-06 17:20:46 +00006#include "wtabledelegates.h"
f912d9f3 kojima2000-12-21 04:46:20 +00007
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02008static char *col1[20] = { 0 };
f912d9f3 kojima2000-12-21 04:46:20 +00009
4c60cd5b kojima2000-12-21 21:06:00 +000010static int col2[20];
11
4c60cd5b kojima2000-12-21 21:06:00 +000012static char *options[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020013 "Option1",
14 "Option2",
15 "Option3",
16 "Option4",
17 "Option5"
4c60cd5b kojima2000-12-21 21:06:00 +000018};
19
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020020int numberOfRows(WMTableViewDelegate * self, WMTableView * table)
f912d9f3 kojima2000-12-21 04:46:20 +000021{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020022 return 20;
f912d9f3 kojima2000-12-21 04:46:20 +000023}
24
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020025void *valueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row)
f912d9f3 kojima2000-12-21 04:46:20 +000026{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020027 /*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];
4c60cd5b kojima2000-12-21 21:06:00 +000043}
44
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020045void setValueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row, void *data)
4c60cd5b kojima2000-12-21 21:06:00 +000046{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020047 if ((int)(uintptr_t) WMGetTableColumnId(column) == 1)
48 col1[row] = data;
49 else
50 col2[row] = (int)(uintptr_t) data;
f912d9f3 kojima2000-12-21 04:46:20 +000051}
52
f912d9f3 kojima2000-12-21 04:46:20 +000053static WMTableViewDelegate delegate = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020054 NULL,
55 numberOfRows,
56 valueForCell,
57 setValueForCell
f912d9f3 kojima2000-12-21 04:46:20 +000058};
59
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020060void clickedTable(WMWidget * w, void *self)
6830b057 dan2004-10-12 21:28:27 +000061{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020062 int row = WMGetTableViewClickedRow((WMTableView *) self);
e99511b0 kojima2001-01-02 14:17:26 +000063
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020064 WMEditTableViewRow(self, row);
4c60cd5b kojima2000-12-21 21:06:00 +000065}
66
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020067int main(int argc, char **argv)
f912d9f3 kojima2000-12-21 04:46:20 +000068{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020069 WMScreen *scr;
70 WMWindow *win;
71 WMTableView *table;
72 WMTableColumn *col;
73 WMTableColumnDelegate *colDeleg;
6830b057 dan2004-10-12 21:28:27 +000074
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020075 WMInitializeApplication("test", &argc, argv);
6830b057 dan2004-10-12 21:28:27 +000076
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020077 scr = WMOpenScreen(NULL);
f912d9f3 kojima2000-12-21 04:46:20 +000078
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020079 XSynchronize(WMScreenDisplay(scr), 1);
6830b057 dan2004-10-12 21:28:27 +000080
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020081 win = WMCreateWindow(scr, "eweq");
82 WMResizeWidget(win, 400, 200);
83 WMMapWidget(win);
6830b057 dan2004-10-12 21:28:27 +000084
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020085 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);
6830b057 dan2004-10-12 21:28:27 +000093
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020094 colDeleg = WTCreateStringEditorDelegate(table);
6830b057 dan2004-10-12 21:28:27 +000095
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020096 col = WMCreateTableColumn("Group");
97 WMSetTableColumnWidth(col, 180);
98 WMAddTableViewColumn(table, col);
99 WMSetTableColumnDelegate(col, colDeleg);
100 WMSetTableColumnId(col, (void *)1);
f912d9f3 kojima2000-12-21 04:46:20 +0000101
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200102 colDeleg = WTCreateEnumSelectorDelegate(table);
103 WTSetEnumSelectorOptions(colDeleg, options, 5);
4c60cd5b kojima2000-12-21 21:06:00 +0000104
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200105 col = WMCreateTableColumn("Package");
106 WMSetTableColumnWidth(col, 140);
107 WMAddTableViewColumn(table, col);
108 WMSetTableColumnDelegate(col, colDeleg);
109 WMSetTableColumnId(col, (void *)2);
f912d9f3 kojima2000-12-21 04:46:20 +0000110
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200111 colDeleg = WTCreateBooleanSwitchDelegate(table);
e99511b0 kojima2001-01-02 14:17:26 +0000112
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200113 col = WMCreateTableColumn("Bool");
114 WMSetTableColumnWidth(col, 50);
115 WMAddTableViewColumn(table, col);
116 WMSetTableColumnDelegate(col, colDeleg);
117 WMSetTableColumnId(col, (void *)2);
f912d9f3 kojima2000-12-21 04:46:20 +0000118
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200119 WMMapWidget(table);
120 WMRealizeWidget(win);
121 WMScreenMainLoop(scr);
33cc542e dan2001-10-04 03:07:34 +0000122
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200123 return 0;
f912d9f3 kojima2000-12-21 04:46:20 +0000124}