summaryrefslogtreecommitdiff
path: root/iup/test/toggle.c
blob: e504eb167fa21d1e3f85d81a1c68efc6b1463212 (plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include <stdlib.h>
#include <stdio.h>
#include "iup.h"          

#define TEST_IMAGE_SIZE 20

static unsigned char image_data_32[16*16*4] = {
  255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0,
  255,  0, 255, 0, 183, 182, 245, 255, 183, 182, 245, 255, 179, 178, 243, 255, 174, 173, 241, 255, 168, 167, 238, 255, 162, 161, 234, 255, 155, 154, 231, 255, 148, 147, 228, 255, 143, 142, 224, 255, 136, 135, 221, 255, 129, 128, 218, 255, 123, 122, 214, 255, 117, 116, 211, 255, 112, 111, 209, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 179, 178, 243, 255, 190, 189, 255, 255, 147, 146, 248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 248, 251, 255, 75, 88, 190, 255, 89, 88, 176, 255, 89, 88, 176, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 173, 172, 240, 255, 190, 189, 255, 255, 138, 137, 239, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 248, 251, 255, 234, 238, 246, 255, 63, 82, 184, 255, 51, 51, 103, 255, 86, 85, 170, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 167, 166, 237, 255, 190, 189, 255, 255, 129, 128, 230, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 248, 251, 255, 234, 238, 246, 255, 222, 229, 240, 255, 52, 77, 179, 255, 122, 121, 223, 255, 83, 82, 164, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 159, 158, 233, 255, 190, 189, 255, 255, 119, 118, 220, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 248, 251, 255, 234, 238, 246, 255, 222, 229, 240, 255, 210, 219, 234, 255, 40, 71, 173, 255, 114, 113, 215, 255, 80, 79, 159, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 152, 151, 229, 255, 190, 189, 255, 255, 110, 109, 211, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 248, 251, 255, 234, 238, 246, 255, 222, 229, 240, 255, 210, 219, 234, 255, 198, 209, 229, 255, 28, 65, 167, 255, 103, 103, 204, 255, 77, 77, 154, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 146, 145, 226, 255, 190, 189, 255, 255, 103, 102, 204, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 248, 251, 255, 234, 238, 246, 255, 222, 229, 240, 255, 210, 219, 234, 255, 198, 209, 229, 255, 189, 202, 225, 255, 17, 59, 161, 255, 92, 93, 194, 255, 74, 74, 148, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 139, 138, 223, 255, 188, 187, 255, 255, 183, 182, 255, 255, 96, 99, 201, 255, 86, 94, 196, 255, 75, 88, 190, 255, 63, 82, 184, 255, 52, 77, 179, 255, 40, 71, 173, 255, 28, 65, 167, 255, 17, 59, 161, 255, 92, 93, 193, 255, 84, 86, 186, 255, 71, 71, 143, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 132, 131, 219, 255, 180, 179, 255, 255, 174, 173, 255, 255, 164, 163, 252, 255, 143, 142, 244, 255, 135, 134, 236, 255, 129, 128, 230, 255, 122, 121, 223, 255, 114, 113, 215, 255, 108, 107, 209, 255, 92, 93, 193, 255, 84, 86, 186, 255, 76, 80, 178, 255, 68, 68, 137, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 124, 123, 215, 255, 170, 169, 255, 255, 160, 159, 251, 255, 148, 147, 245, 255, 75, 91, 113, 255, 75, 91, 113, 255, 75, 91, 113, 255, 75, 91, 113, 255, 82, 98, 118, 255, 91, 106, 125, 255, 84, 86, 186, 255, 76, 79, 178, 255, 68, 73, 170, 255, 65, 65, 131, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 118, 117, 212, 255, 160, 159, 255, 255, 145, 144, 245, 255, 135, 134, 236, 255, 75, 91, 113, 255, 0, 0, 0, 255, 52, 60, 71, 255, 206, 217, 233, 255, 212, 221, 236, 255, 103, 116, 133, 255, 67, 75, 174, 255, 68, 73, 170, 255, 60, 66, 163, 255, 62, 62, 125, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 112, 111, 209, 255, 154, 153, 255, 255, 135, 134, 236, 255, 129, 128, 230, 255, 75, 91, 113, 255, 52, 60, 71, 255, 104, 120, 141, 255, 216, 224, 237, 255, 224, 231, 241, 255, 115, 127, 143, 255, 53, 65, 163, 255, 60, 66, 162, 255, 53, 61, 156, 255, 60, 59, 120, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 108, 107, 207, 255, 143, 142, 243, 255, 129, 128, 230, 255, 36, 68, 170, 255, 33, 50, 71, 255, 171, 180, 195, 255, 179, 187, 198, 255, 188, 193, 202, 255, 196, 200, 206, 255, 72, 77, 86, 255, 51, 62, 158, 255, 54, 61, 156, 255, 49, 57, 152, 255, 57, 57, 114, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 108, 107, 207, 84, 101, 100, 195, 255, 86, 85, 170, 255, 83, 82, 164, 255, 80, 79, 159, 255, 77, 77, 154, 255, 74, 74, 148, 255, 71, 71, 143, 255, 68, 68, 137, 255, 65, 65, 131, 255, 60, 59, 120, 255, 60, 59, 120, 255, 57, 57, 114, 255, 55, 54, 110, 255, 255,  0, 255, 0,
  255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255,  0, 255, 0, 255, 0, 255, 0};

static unsigned char image_data_8 [TEST_IMAGE_SIZE*TEST_IMAGE_SIZE] = 
{
  5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
  5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
  5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
  5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
  5,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,0,0,0,5, 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,5,5,5,5,0,0,0,5, 
  5,0,0,0,5,5,5,5,5,1,5,5,5,5,5,5,0,0,0,5, 
  5,0,0,0,5,5,5,5,5,1,5,5,5,5,5,5,0,0,0,5, 
  5,0,0,0,5,5,5,5,5,1,5,5,5,5,5,5,0,0,0,5, 
  5,0,0,0,5,5,5,5,5,1,5,5,5,5,5,5,0,0,0,5, 
  5,0,0,0,5,5,1,1,1,1,1,1,1,5,5,5,0,0,0,5,
  5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
  5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
  5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,
  5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
};

static void createimgs(void)
{ 
  Ihandle *image; 

  image = IupImageRGBA(16, 16, image_data_32);
  IupSetHandle ("image2", image); 

  image = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8);
  IupSetAttribute(image, "0", "BGCOLOR");
  IupSetAttribute(image, "1", "255 0 0"); 
  IupSetAttribute(image, "2", "0 255 0");
  IupSetAttribute(image, "3", "0 0 255"); 
  IupSetAttribute(image, "4", "255 255 255"); 
  IupSetAttribute(image, "5", "0 0 0"); 
  IupSetHandle ("image1", image); 

  image = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8_inactive);
  IupSetAttribute(image, "0", "BGCOLOR");
  IupSetAttribute(image, "1", "255 0 0"); 
  IupSetAttribute(image, "2", "0 255 0");
  IupSetAttribute(image, "3", "0 0 255"); 
  IupSetAttribute(image, "4", "255 255 255"); 
  IupSetAttribute(image, "5", "0 0 0"); 
  IupSetHandle ("image1i", image); 

  image = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8_pressed);
  IupSetAttribute(image, "0", "BGCOLOR");
  IupSetAttribute(image, "1", "255 0 0"); 
  IupSetAttribute(image, "2", "0 255 0");
  IupSetAttribute(image, "3", "0 0 255"); 
  IupSetAttribute(image, "4", "255 255 255"); 
  IupSetAttribute(image, "5", "0 0 0"); 
  IupSetHandle ("image1p", image);
}

static int togglecb(Ihandle *self, int v)
{
  if (v == 1) printf("Toggle %s - ON\n", IupGetAttribute(self, "NAME")); 
  else printf("Toggle %s - OFF\n", IupGetAttribute(self, "NAME")); 
  return IUP_DEFAULT;
}

static int toggle9cb(Ihandle *self, int v)
{
  Ihandle* ih = IupGetHandle("radio test");
  if (v == 1) printf("Toggle 9 - ON\n"); 
  else if (v == -1) printf("Toggle 9 - NOTDEF\n"); 
  else printf("Toggle 9 - OFF\n"); 

  if (v == 1)
    IupSetAttribute(ih, "VALUE", "ON");
  else
    IupSetAttribute(ih, "VALUE", "OFF");

  return IUP_DEFAULT;
}

static int toggle7cb(Ihandle *ih, int v)
{
  Ihandle* dlg = IupGetDialog(ih);
  Ihandle* box = IupGetChild(dlg, 0);
  if (v)
    IupSetAttribute(box, "ACTIVE", "NO");
  else
    IupSetAttribute(box, "ACTIVE", "YES");
  IupSetAttribute(ih, "ACTIVE", "YES");
  return IUP_DEFAULT;
}

static int k_any(Ihandle *ih, int c)
{
  printf("K_ANY(%d)\n", c);
  return IUP_DEFAULT;
}

static int getfocus_cb(Ihandle *ih)
{
  printf("GETFOCUS_CB()\n");
  return IUP_DEFAULT;
}

static int help_cb(Ihandle* ih)
{
  printf("HELP_CB()\n");
  return IUP_DEFAULT;
}
     
static int killfocus_cb(Ihandle *ih)
{
  printf("KILLFOCUS_CB()\n");
  return IUP_DEFAULT;
}

static int leavewindow_cb(Ihandle *ih)
{
  printf("LEAVEWINDOW_CB()\n");
  return IUP_DEFAULT;
}

static int enterwindow_cb(Ihandle *ih)
{
  printf("ENTERWINDOW_CB()\n");
  return IUP_DEFAULT;
}

void ToggleTest(void)
{
  Ihandle *dlg, *box;
  Ihandle *toggle1, *toggle2, *toggle3, *toggle4, *toggle5, *toggle6, *toggle7, *toggle8, *toggle9;

  createimgs();

  toggle1 = IupToggle(NULL, NULL);
  toggle2 = IupToggle(NULL, NULL);
  toggle3 = IupToggle("Text Toggle", NULL);
//  toggle4 = IupToggle("blue foreground color", NULL);
  toggle4 = IupToggle("Radio &Text", NULL);
  toggle5 = IupToggle("red background color", NULL);
  toggle6 = IupToggle("multiple lines\nsecond line", NULL);
  toggle7 = IupToggle("INACTIVE", NULL);
  toggle8 = IupToggle("Courier 14 Bold font", NULL);
  toggle9 = IupToggle("3 State", NULL);
  
  IupSetHandle("radio test", toggle8);

  IupSetCallback(toggle1, "ACTION", (Icallback)togglecb);
  IupSetCallback(toggle2, "ACTION", (Icallback)togglecb);
  IupSetCallback(toggle3, "ACTION", (Icallback)togglecb);
  IupSetCallback(toggle4, "ACTION", (Icallback)togglecb);
  IupSetCallback(toggle5, "ACTION", (Icallback)togglecb);
  IupSetCallback(toggle6, "ACTION", (Icallback)togglecb);
  IupSetCallback(toggle8, "ACTION", (Icallback)togglecb);
  IupSetCallback(toggle7, "ACTION", (Icallback)toggle7cb);
  IupSetCallback(toggle9, "ACTION", (Icallback)toggle9cb);

  IupSetCallback(toggle3, "K_ANY",        (Icallback)k_any);
  IupSetCallback(toggle3, "HELP_CB",      (Icallback)help_cb);
  IupSetCallback(toggle3, "GETFOCUS_CB",  (Icallback)getfocus_cb); 
  IupSetCallback(toggle3, "KILLFOCUS_CB", (Icallback)killfocus_cb);
  IupSetCallback(toggle3, "ENTERWINDOW_CB", (Icallback)enterwindow_cb);
  IupSetCallback(toggle3, "LEAVEWINDOW_CB", (Icallback)leavewindow_cb);
  
  IupSetAttribute(toggle1, "IMAGE",   "image1");            
  IupSetAttribute(toggle1, "IMPRESS", "image1p");
  IupSetAttribute(toggle1, "IMINACTIVE", "image1i");
//  IupSetAttribute(toggle1, "PADDING",   "10x10");            
//  IupSetAttribute(toggle1, "RASTERSIZE",   "160x160");
//  IupSetAttribute(toggle2, "RASTERSIZE",   "60x60");            
//  IupSetAttribute(toggle1, "ALIGNMENT",   "ARIGHT");
//  IupSetAttribute(toggle2, "ALIGNMENT",  "ARIGHT");            
  IupSetAttribute(toggle2, "IMAGE",   "image2");
  IupSetAttribute(toggle1, "NAME", "1");
  IupSetAttribute(toggle2, "NAME", "2");
  IupSetAttribute(toggle3, "NAME", "3");
  IupSetAttribute(toggle4, "NAME", "4");
  IupSetAttribute(toggle5, "NAME", "5");
  IupSetAttribute(toggle6, "NAME", "6");
  IupSetAttribute(toggle8, "NAME", "8");
//  IupSetAttribute(toggle4, "FGCOLOR", "0 0 255");         
  IupSetAttribute(toggle5, "BGCOLOR", "255 0 0");         
  IupSetAttribute(toggle8, "FONT",    "COURIER_BOLD_14"); 
  IupSetAttribute(toggle9, "3STATE",  "YES");             
  IupSetAttribute(toggle6, "TIP", "Toggle Tip");
  IupSetAttribute(toggle7, "RIGHTBUTTON", "YES");
  IupSetAttribute(toggle5, "RIGHTBUTTON", "YES");

  /* Creating box that contains the toggles */
  box = IupHbox(
    IupVbox(
      toggle1, 
      toggle2, 
      toggle3, 
      toggle7, 
      toggle9, 
      NULL), 
    IupFrame(IupRadio(IupVbox(
      toggle4, 
      toggle5, 
      toggle6, 
      toggle8, 
      NULL))),
    NULL);

  IupSetAttribute(IupGetChild(box, 1), "TITLE", "Radio in a Frame");

//  IupSetAttribute(box, "BGCOLOR", "255 0 0");         

  /* Dialog */
  dlg = IupDialog(box);
  IupSetAttribute (dlg, "TITLE", "IupToggle Test"); 
  IupSetAttributes(dlg, "MARGIN=5x5, GAP=5"); 

  /* Associates a menu to the dlg */
  IupShowXY(dlg, IUP_CENTER, IUP_CENTER); 
}

#ifndef BIG_TEST
int main(int argc, char* argv[])
{
  IupOpen(&argc, &argv);

  ToggleTest();

  IupMainLoop();

  IupClose();

  return EXIT_SUCCESS;
}
#endif