1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "iup.h"
#include "cd.h"
#include "iupcontrols.h"
static int nlines_cb(Ihandle* ih)
{
return 7;
}
static int ncols_cb(Ihandle* ih)
{
return 7;
}
static int height_cb(Ihandle* ih, int i)
{
return (int)(30 + i * 1.5);
}
static int width_cb(Ihandle* ih, int j)
{
return (int)(50 + j * 1.5);
}
static int mouseclick_cb(Ihandle* ih, int b, char* m, int i, int j, int x, int y, char* r)
{
printf("CLICK: %d: (%02d, %02d)\n", b, i, j);
return IUP_DEFAULT;
}
static int scrolling_cb(Ihandle* ih, int i, int j)
{
printf("SCROLL: (%02d, %02d)\n", i, j);
return IUP_DEFAULT;
}
static int vspan_cb(Ihandle* ih, int i, int j)
{
if (i == 1 && j == 1)
return 2;
if (i == 5 && j == 5)
return 2;
return 1;
}
static int hspan_cb(Ihandle* ih, int i, int j)
{
if (i == 1 && j == 1)
return 2;
if (i == 5 && j == 5)
return 2;
return 1;
}
static int draw_cb(Ihandle* ih, int i, int j, int xmin, int xmax, int ymin, int ymax)
{
static char buffer[64];
int xm = (xmax + xmin) / 2;
int ym = (ymax + ymin) / 2;
if (i == 1 && j == 2)
return IUP_DEFAULT;
if (i == 2 && j == 1)
return IUP_DEFAULT;
if (i == 2 && j == 2)
return IUP_DEFAULT;
if (i == 5 && j == 6)
return IUP_DEFAULT;
if (i == 6 && j == 5)
return IUP_DEFAULT;
if (i == 6 && j == 6)
return IUP_DEFAULT;
if (i == 1 && j == 1)
cdForeground(CD_WHITE);
else
cdForeground(cdEncodeColor((unsigned char)(i*20), (unsigned char)(j*100), (unsigned char)(i+100)));
cdBox(xmin, xmax, ymin, ymax);
cdTextAlignment(CD_CENTER);
cdForeground(CD_BLACK);
sprintf(buffer, "(%02d, %02d)", i, j);
cdText(xm, ym, buffer);
return IUP_DEFAULT;
}
static Ihandle* create(void)
{
Ihandle* cells = IupCells();
IupSetCallback(cells, "MOUSECLICK_CB", (Icallback)mouseclick_cb);
IupSetCallback(cells, "DRAW_CB", (Icallback)draw_cb);
IupSetCallback(cells, "WIDTH_CB", (Icallback)width_cb);
IupSetCallback(cells, "HEIGHT_CB", (Icallback)height_cb);
IupSetCallback(cells, "NLINES_CB", (Icallback)nlines_cb);
IupSetCallback(cells, "NCOLS_CB", (Icallback)ncols_cb);
IupSetCallback(cells, "HSPAN_CB", (Icallback)hspan_cb);
IupSetCallback(cells, "VSPAN_CB", (Icallback)vspan_cb);
IupSetCallback(cells, "SCROLLING_CB", (Icallback)scrolling_cb);
IupSetAttribute(cells, "BOXED", "NO");
IupSetAttribute(cells, "RASTERSIZE", "395x255");
return cells;
}
void CellsDegradeTest(void)
{
Ihandle* dlg = NULL;
Ihandle* cells = NULL;
Ihandle* box = NULL;
cells = create();
box = IupVbox(cells, NULL);
IupSetAttribute(box, "MARGIN", "10x10");
dlg = IupDialog(box);
IupSetAttribute(dlg, "TITLE", "IupCells");
IupShowXY(dlg, IUP_CENTER, IUP_CENTER) ;
IupSetAttribute(cells, "RASTERSIZE", NULL);
}
#ifndef BIG_TEST
int main(int argc, char* argv[])
{
IupOpen(&argc, &argv);
IupControlsOpen();
CellsDegradeTest();
IupMainLoop();
IupClose();
return EXIT_SUCCESS;
}
#endif
|