1 /*
2 ** Copyright (C) 2001-2008 Daniel Caujolle-Bert <segfault@club-internet.fr>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA.
17 **
18 */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <stdio.h>
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <X11/keysym.h>
27 #include <locale.h>
28
29 #include "xitk.h"
30 #include "xitkintl.h"
31
32 typedef struct {
33 Display *display;
34 ImlibData *imlibdata;
35
36 xitk_window_t *xwin;
37
38 /* Browser */
39 xitk_widget_t *browser;
40 char *entries[100];
41 int num_entries;
42
43 /* Sliders */
44 xitk_widget_t *hslider;
45 xitk_widget_t *vslider;
46 xitk_widget_t *rslider;
47
48 /* Button */
49 xitk_widget_t *button;
50
51 /* Label */
52 xitk_widget_t *combo;
53
54 /* Label */
55 xitk_widget_t *label;
56
57 /* Label */
58 xitk_widget_t *input;
59
60 /* Tabs */
61 xitk_widget_t *tabs;
62
63 /* Intbox */
64 xitk_widget_t *intbox;
65 int oldintvalue;
66
67 /* Doublebox */
68 xitk_widget_t *doublebox;
69 double olddoublevalue;
70
71 /* checkbox */
72 xitk_widget_t *checkbox;
73
74 /* menu */
75 xitk_widget_t *menu;
76 int checked;
77
78 xitk_widget_list_t *widget_list;
79 xitk_register_key_t kreg;
80 } test_t;
81
82
83 static test_t *test;
84 static int nlab = 0;
85 static int align = ALIGN_LEFT;
86 #define FONT_HEIGHT_MODEL "azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN&�(-�_��)=�~#{[|`\\^@]}%"
87
88 static void create_menu(void);
89 /*
90 *
91 */
init_test(void)92 static int init_test(void) {
93 ImlibInitParams imlib_init;
94 int screen;
95 int depth = 0;
96 Visual *visual = NULL;
97 XColor black, dummy;
98
99 if(!XInitThreads ()) {
100 printf ("XInitThreads() failed.\n");
101 return 0;
102 }
103
104 test = (test_t *) xitk_xmalloc(sizeof(test_t));
105
106 if((test->display = XOpenDisplay((getenv("DISPLAY")))) == NULL) {
107 fprintf(stderr, "Cannot open display\n");
108 return 0;
109 }
110
111 XLOCK (XLockDisplay, test->display);
112
113 screen = DefaultScreen(test->display);
114 depth = DefaultDepth(test->display, screen);
115 visual = DefaultVisual(test->display, screen);
116
117 imlib_init.flags = PARAMS_VISUALID;
118 imlib_init.visualid = visual->visualid;
119 test->imlibdata = Imlib_init_with_params(test->display, &imlib_init);
120 if (test->imlibdata == NULL) {
121 fprintf(stderr, "Imlib_init_with_params() failed.\n");
122 XUNLOCK (XUnlockDisplay, test->display);
123 return 0;
124 }
125
126 test->imlibdata->x.x_lock_display = XLockDisplay;
127 test->imlibdata->x.x_unlock_display = XUnlockDisplay;
128
129 XAllocNamedColor(test->display, Imlib_get_colormap(test->imlibdata), "black", &black, &dummy);
130
131 xitk_init (test->display, black, XLockDisplay, XUnlockDisplay, 1);
132
133 XUNLOCK (XUnlockDisplay, test->display);
134
135 return 1;
136 }
137
138 /*
139 *
140 */
deinit_test(void)141 static void deinit_test(void) {
142 int i = 0;
143
144 while(test->entries[i]) {
145 free(test->entries[i]);
146 i++;
147 }
148 }
149
150 /*
151 *
152 */
test_end(xitk_widget_t * w,void * data)153 static void test_end(xitk_widget_t *w, void *data) {
154 xitk_unregister_event_handler(&test->kreg);
155
156 xitk_destroy_widgets(test->widget_list);
157 xitk_window_destroy_window(test->imlibdata, test->xwin);
158
159 XFreeGC(test->display, (XITK_WIDGET_LIST_GC(test->widget_list)));
160
161 XITK_WIDGET_LIST_FREE(test->widget_list);
162
163 xitk_stop();
164 }
165
166 /*
167 *
168 */
test_handle_event(XEvent * event,void * data)169 static void test_handle_event(XEvent *event, void *data) {
170 XKeyEvent mykeyevent;
171 KeySym mykey;
172 char kbuf[256];
173 int len;
174
175 switch(event->type) {
176
177 case EnterNotify:
178 XLOCK (XLockDisplay, test->display);
179 XRaiseWindow(test->display, xitk_window_get_window(test->xwin));
180 XUNLOCK (XUnlockDisplay, test->display);
181 break;
182
183 case ButtonPress:
184 {
185 XButtonEvent *bevent = (XButtonEvent *) event;
186
187 if(bevent->button == Button3)
188 create_menu();
189 }
190 break;
191
192 case KeyPress: {
193 int modifier;
194
195 (void) xitk_get_key_modifier(event, &modifier);
196
197 mykeyevent = event->xkey;
198
199 XLOCK (XLockDisplay, test->display);
200 len = XLookupString(&mykeyevent, kbuf, sizeof(kbuf), &mykey, NULL);
201 XUNLOCK (XUnlockDisplay, test->display);
202
203 switch (mykey) {
204
205 case XK_q:
206 case XK_Q:
207 if(modifier & MODIFIER_CTRL)
208 test_end(NULL, NULL);
209 break;
210
211 }
212 }
213 break;
214
215 case MappingNotify:
216 XLOCK (XLockDisplay, test->display);
217 XRefreshKeyboardMapping((XMappingEvent *) event);
218 XUNLOCK (XUnlockDisplay, test->display);
219 break;
220
221 // case ConfigureNotify:
222 // xitk_combo_update_pos(test->combo);
223 // break;
224 }
225 }
226
227 /*
228 * Set same pos in both sliders.
229 */
move_sliders(xitk_widget_t * w,void * data,int pos)230 static void move_sliders(xitk_widget_t *w, void *data, int pos) {
231 if(w == test->vslider) {
232 xitk_slider_set_pos(test->hslider, pos);
233 xitk_slider_set_pos(test->rslider, pos);
234 }
235 else if(w == test->hslider) {
236 xitk_slider_set_pos(test->vslider, pos);
237 xitk_slider_set_pos(test->rslider, pos);
238 }
239 else if(w == test->rslider) {
240 xitk_slider_set_pos(test->vslider, pos);
241 xitk_slider_set_pos(test->hslider, pos);
242 }
243
244 }
245
246 /*
247 *
248 */
window_message_cb(xitk_widget_t * w,void * data,int btn)249 static void window_message_cb(xitk_widget_t *w, void *data, int btn) {
250
251 switch(btn) {
252 case XITK_WINDOW_ANSWER_OK:
253 printf("Button OK pressed.\n");
254 break;
255
256 case XITK_WINDOW_ANSWER_YES:
257 printf("Button YES pressed.\n");
258 break;
259
260 case XITK_WINDOW_ANSWER_NO:
261 printf("Button NO pressed.\n");
262 break;
263
264 case XITK_WINDOW_ANSWER_CANCEL:
265 printf("Button CANCEL pressed.\n");
266 break;
267
268 default:
269 printf("Button %d is unknown.\n", btn);
270 break;
271 }
272 }
273
274 /*
275 *
276 */
change_label(xitk_widget_t * w,void * data)277 static void change_label(xitk_widget_t *w, void *data) {
278 xitk_window_t *xw;
279 static char *labels[] = {
280 "A Label",
281 "Boom"
282 };
283
284 if((++align) > ALIGN_RIGHT)
285 align = ALIGN_CENTER;
286
287 nlab = !nlab;
288
289 xitk_label_change_label(test->label, labels[nlab]);
290
291 xitk_browser_set_alignment(test->browser, align);
292
293 // xitk_window_dialog_ok_with_width(test->imlibdata, "Long error message", NULL, NULL, 500, ALIGN_LEFT, "premier \n\n\nnum %d\n", nlab);
294 // xitk_window_dialog_ok_with_width(test->imlibdata, "License information", NULL, NULL, 500, ALIGN_CENTER, "** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.");
295 //xitk_window_dialog_ok_with_width(test->imlibdata, "Long error message", window_message_cb, NULL, 500, ALIGN_DEFAULT, "** This program is free software; you can redistribute it and/or modify\n** it under the terms of the GNU General Public License as published by\n** the Free Software Foundation; either version 2 of the License, or\n** (at your option) any later version.");
296 // xitk_window_dialog_yesno(test->imlibdata, NULL, NULL, NULL, NULL, ALIGN_LEFT, "Le programme <linux kernel> a provoqu� une faute de protection dans le module <unknown> � l'adresse 0x00001234.\nCitro�n dump:\nAX:0x00\t\tBX:0x00\nCX:0x00\t\tGS:0x00;-)");
297 // xitk_window_dialog_ok_with_width(test->imlibdata, "Long error message", window_message_cb, NULL, 500, ALIGN_DEFAULT, "**Thisprogramisfreesoftware;youcanredistributeitand/ormodify**itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby**TheFreeSoftwareFoundation;eitherversion2oftheLicense,or**(atyouroption)anylaterversion.");
298 xw = xitk_window_dialog_error(test->imlibdata,
299 "Stream number %d <%s.mpg> is not valid.\n", nlab, labels[nlab]);
300 }
301
302 /*
303 *
304 */
change_inputtext(xitk_widget_t * w,void * data,int selected)305 static void change_inputtext(xitk_widget_t *w, void *data, int selected) {
306
307 if(test->entries[selected] != NULL)
308 xitk_inputtext_change_text(test->input, test->entries[selected]);
309
310 }
311
312 /*
313 *
314 */
change_inputtext_dbl_click(xitk_widget_t * w,void * data,int selected)315 static void change_inputtext_dbl_click(xitk_widget_t *w, void *data, int selected) {
316
317 if(test->entries[selected] != NULL)
318 xitk_inputtext_change_text(test->input, test->entries[selected]);
319
320 }
321
322 /*
323 *
324 */
change_browser_entry(xitk_widget_t * w,void * data,char * currenttext)325 static void change_browser_entry(xitk_widget_t *w, void *data, char *currenttext) {
326 int j;
327
328 if((j = xitk_browser_get_current_selected(test->browser)) >= 0) {
329 free(test->entries[j]);
330 test->entries[j] = strdup(currenttext);
331 xitk_browser_rebuild_browser(test->browser, xitk_browser_get_current_start(test->browser));
332 }
333 }
334
335 /*
336 *
337 */
intchange_cb(xitk_widget_t * w,void * data,int btn)338 static void intchange_cb(xitk_widget_t *w, void *data, int btn) {
339
340 switch(btn) {
341 case XITK_WINDOW_ANSWER_YES:
342 test->oldintvalue = xitk_intbox_get_value(test->intbox);
343 break;
344
345 case XITK_WINDOW_ANSWER_NO:
346 case XITK_WINDOW_ANSWER_CANCEL:
347 xitk_intbox_set_value(test->intbox, test->oldintvalue);
348 break;
349 }
350 }
351
352 /*
353 *
354 */
notify_intbox_change(xitk_widget_t * w,void * data,int value)355 static void notify_intbox_change(xitk_widget_t *w, void *data, int value) {
356
357 xitk_window_dialog_yesnocancel(test->imlibdata, NULL,
358 intchange_cb,
359 intchange_cb,
360 intchange_cb,
361 NULL, ALIGN_DEFAULT,
362 "New integer value is: %d. Confirm?", value);
363 }
364
365 /*
366 *
367 */
create_intbox(void)368 static void create_intbox(void) {
369 int x = 150, y = 300;
370 xitk_intbox_widget_t ib;
371
372 XITK_WIDGET_INIT(&ib, test->imlibdata);
373
374 ib.skin_element_name = NULL;
375 ib.value = test->oldintvalue = 10;
376 ib.step = 1;
377 ib.parent_wlist = test->widget_list;
378 ib.callback = notify_intbox_change;
379 ib.userdata = NULL;
380 xitk_add_widget (test->widget_list,
381 (test->intbox =
382 xitk_noskin_intbox_create(test->widget_list, &ib, x, y, 60, 20, NULL, NULL, NULL)));
383 xitk_enable_and_show_widget(test->intbox);
384 xitk_set_widget_tips_default(test->intbox, "This is a intbox");
385 }
386
387 /*
388 *
389 */
doublechange_cb(xitk_widget_t * w,void * data,int btn)390 static void doublechange_cb(xitk_widget_t *w, void *data, int btn) {
391
392 switch(btn) {
393 case XITK_WINDOW_ANSWER_YES:
394 test->olddoublevalue = xitk_doublebox_get_value(test->doublebox);
395 break;
396
397 case XITK_WINDOW_ANSWER_NO:
398 case XITK_WINDOW_ANSWER_CANCEL:
399 xitk_doublebox_set_value(test->doublebox, test->olddoublevalue);
400 break;
401 }
402 }
403
404 /*
405 *
406 */
notify_doublebox_change(xitk_widget_t * w,void * data,double value)407 static void notify_doublebox_change(xitk_widget_t *w, void *data, double value) {
408
409 xitk_window_dialog_yesnocancel(test->imlibdata, NULL,
410 doublechange_cb,
411 doublechange_cb,
412 doublechange_cb,
413 NULL, ALIGN_DEFAULT,
414 "New double value is: %e. Confirm?", value);
415 }
416
417 /*
418 *
419 */
create_doublebox(void)420 static void create_doublebox(void) {
421 int x = 150, y = 330;
422 xitk_doublebox_widget_t ib;
423
424 XITK_WIDGET_INIT(&ib, test->imlibdata);
425
426 ib.skin_element_name = NULL;
427 ib.value = test->olddoublevalue = 1.500;
428 ib.step = .5;
429 ib.parent_wlist = test->widget_list;
430 ib.callback = notify_doublebox_change;
431 ib.userdata = NULL;
432 xitk_add_widget (test->widget_list,
433 (test->doublebox =
434 xitk_noskin_doublebox_create(test->widget_list, &ib, x, y, 60, 20, NULL, NULL, NULL)));
435 xitk_enable_and_show_widget(test->doublebox);
436 xitk_set_widget_tips_default(test->doublebox, "This is a doublebox");
437 }
438
439 /*
440 *
441 */
checkbox_cb(xitk_widget_t * w,void * data,int state)442 static void checkbox_cb(xitk_widget_t *w, void *data, int state) {
443 if(state)
444 xitk_cursors_restore_window_cursor(test->display, xitk_window_get_window(test->xwin));
445 else
446 xitk_cursors_define_window_cursor(test->display, xitk_window_get_window(test->xwin), xitk_cursor_invisible);
447 }
create_checkbox(void)448 static void create_checkbox(void) {
449 int x = 250, y = 300;
450 xitk_checkbox_widget_t cb;
451
452 XITK_WIDGET_INIT(&cb, test->imlibdata);
453
454 cb.skin_element_name = NULL;
455 cb.callback = checkbox_cb;
456 cb.userdata = NULL;
457 xitk_add_widget (test->widget_list,
458 (test->checkbox =
459 xitk_noskin_checkbox_create(test->widget_list, &cb, x, y, 20, 20)));
460 xitk_enable_and_show_widget(test->checkbox);
461
462 xitk_set_widget_tips_default(test->checkbox, "This is a checkbox");
463 }
464
465 /*
466 *
467 */
create_tabs(void)468 static void create_tabs(void) {
469 xitk_pixmap_t *bg;
470 xitk_tabs_widget_t t;
471 char *fontname = "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*";
472 int x = 150, y = 200, w = 300;
473 int width, height;
474 static char *tabs_labels[] = {
475 "Jumpin'", "Jack", "Flash", "It's", "Gas", "Gas", "Gas", ",", "Tabarnak"
476 };
477
478 XITK_WIDGET_INIT(&t, test->imlibdata);
479
480 xitk_window_get_window_size(test->xwin, &width, &height);
481 bg = xitk_image_create_xitk_pixmap(test->imlibdata, width, height);
482 XCopyArea(test->display, (xitk_window_get_background(test->xwin)), bg->pixmap,
483 bg->gc, 0, 0, width, height, 0, 0);
484
485 draw_rectangular_outter_box(test->imlibdata, bg, x, y+20, (w-1), 60);
486 xitk_window_change_background(test->imlibdata, test->xwin, bg->pixmap, width, height);
487 xitk_image_destroy_xitk_pixmap(bg);
488
489 t.skin_element_name = NULL;
490 t.num_entries = 9;
491 t.entries = tabs_labels;
492 t.parent_wlist = test->widget_list;
493 t.callback = NULL;
494 t.userdata = NULL;
495 xitk_add_widget (test->widget_list,
496 (test->tabs =
497 xitk_noskin_tabs_create(test->widget_list, &t, x, y, w, fontname)));
498 xitk_enable_and_show_widget(test->tabs);
499
500 }
501
502 /*
503 *
504 */
create_frame(void)505 static void create_frame(void) {
506 xitk_pixmap_t *bg;
507 int width, height;
508 char *fontname = "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*";
509 int x = 350, y = 50, w = 200, h = 150;
510
511 xitk_window_get_window_size(test->xwin, &width, &height);
512 bg = xitk_image_create_xitk_pixmap(test->imlibdata, width, height);
513 XCopyArea(test->display, (xitk_window_get_background(test->xwin)), bg->pixmap,
514 bg->gc, 0, 0, width, height, 0, 0);
515
516 draw_outter_frame(test->imlibdata, bg, "My Frame", fontname, x, y, w, h);
517 draw_inner_frame(test->imlibdata, bg, NULL, NULL, x+(w>>2), y+(h>>2), w>>1, h>>1);
518
519 xitk_window_change_background(test->imlibdata, test->xwin, bg->pixmap, width, height);
520 xitk_image_destroy_xitk_pixmap(bg);
521 }
522
523 /*
524 *
525 */
create_inputtext(void)526 static void create_inputtext(void) {
527 xitk_inputtext_widget_t inp;
528 char *fontname = "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*";
529
530 XITK_WIDGET_INIT(&inp, test->imlibdata);
531
532 inp.skin_element_name = NULL;
533 inp.text = NULL;
534 inp.max_length = 256;
535 inp.callback = change_browser_entry;
536 inp.userdata = NULL;
537 xitk_add_widget (test->widget_list,
538 (test->input =
539 xitk_noskin_inputtext_create(test->widget_list, &inp,
540 150, 150, 150, 20,
541 "Black", "Black", fontname)));
542 xitk_enable_and_show_widget(test->input);
543
544 xitk_set_widget_tips_default(test->input, "This is an input text.");
545 }
546
547 /*
548 *
549 */
create_label(void)550 static void create_label(void) {
551 xitk_label_widget_t lbl;
552 char *fontname = "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*";
553 int x = 150, y = 120, len = 100;
554 xitk_font_t *fs;
555 int lbear, rbear, wid, asc, des;
556 char *label = "A Label";
557
558 XITK_WIDGET_INIT(&lbl, test->imlibdata);
559
560 fs = xitk_font_load_font(test->display, fontname);
561 xitk_font_set_font(fs, XITK_WIDGET_LIST_GC(test->widget_list));
562 xitk_font_string_extent(fs, label, &lbear, &rbear, &wid, &asc, &des);
563 xitk_font_unload_font(fs);
564
565 lbl.window = xitk_window_get_window(test->xwin);
566 lbl.gc = XITK_WIDGET_LIST_GC(test->widget_list);
567 lbl.skin_element_name = NULL;
568 lbl.label = label;
569 lbl.callback = NULL;
570 xitk_add_widget (test->widget_list,
571 (test->label =
572 xitk_noskin_label_create(test->widget_list, &lbl,
573 x, y, len, (asc+des)*2, fontname)));
574 xitk_enable_and_show_widget(test->label);
575
576 xitk_set_widget_tips_default(test->label, "This is a label");
577
578 {
579 xitk_image_t *wimage = xitk_get_widget_foreground_skin(test->label);
580
581 if(wimage) {
582 draw_rectangular_inner_box(test->imlibdata,
583 wimage->image, 0, 0, wimage->width-1, wimage->height-1);
584 }
585 }
586 }
587
588 /*
589 *
590 */
create_button(void)591 static void create_button(void) {
592 xitk_button_widget_t b;
593 int width = 130, height = 40, x = 150, y = 60;
594
595 XITK_WIDGET_INIT(&b, test->imlibdata);
596
597 b.skin_element_name = NULL;
598 b.callback = change_label;
599 b.userdata = NULL;
600 xitk_add_widget (test->widget_list,
601 (test->button =
602 xitk_noskin_button_create(test->widget_list, &b,
603 x, y, width, height)));
604 xitk_enable_and_show_widget(test->button);
605
606 xitk_set_widget_tips_default(test->button, "This is a button");
607
608 { /* Draw red spot. */
609 xitk_image_t *wimage = xitk_get_widget_foreground_skin(test->button);
610
611 if(wimage) {
612 unsigned int col;
613 xitk_font_t *fs = NULL;
614 char *fontname = "-*-helvetica-bold-r-*-*-14-*-*-*-*-*-*-*";
615 int lbear, rbear, wid, asc, des;
616 char *label = "Fire!!";
617
618
619 col = xitk_get_pixel_color_from_rgb(test->imlibdata, 255, 0, 0);
620
621 XSetForeground(test->display, XITK_WIDGET_LIST_GC(test->widget_list), col);
622 XSetBackground(test->display, XITK_WIDGET_LIST_GC(test->widget_list), col);
623 XFillArc(test->display, wimage->image->pixmap, XITK_WIDGET_LIST_GC(test->widget_list),
624 10, (height >> 1) - 13, 26, 26,
625 (0 * 64), (360 * 64));
626 XFillArc(test->display, wimage->image->pixmap, XITK_WIDGET_LIST_GC(test->widget_list),
627 (width) + 10, (height >> 1) - 13, 26, 26,
628 (0 * 64), (360 * 64));
629 XFillArc(test->display, wimage->image->pixmap, XITK_WIDGET_LIST_GC(test->widget_list),
630 ((width*2) + 10) + 1, ((height >> 1) - 13) + 1, 26, 26,
631 (0 * 64), (360 * 64));
632
633
634 fs = xitk_font_load_font(test->display, fontname);
635 xitk_font_set_font(fs, XITK_WIDGET_LIST_GC(test->widget_list));
636 xitk_font_string_extent(fs, label, &lbear, &rbear, &wid, &asc, &des);
637
638 col = xitk_get_pixel_color_black(test->imlibdata);
639
640 XSetForeground(test->display, XITK_WIDGET_LIST_GC(test->widget_list), col);
641 xitk_font_draw_string(fs, wimage->image->pixmap, XITK_WIDGET_LIST_GC(test->widget_list),
642 50, ((height+asc+des) >> 1) - des, label, strlen(label));
643 xitk_font_draw_string(fs, wimage->image->pixmap, XITK_WIDGET_LIST_GC(test->widget_list),
644 (width) + 50, ((height+asc+des) >> 1) - des, label, strlen(label));
645
646 {
647 char *nlabel = "!BOOM!";
648
649 xitk_font_string_extent(fs, nlabel, &lbear, &rbear, &wid, &asc, &des);
650 xitk_font_draw_string(fs, wimage->image->pixmap, XITK_WIDGET_LIST_GC(test->widget_list),
651 ((width * 2) + 50) + 1, (((height+asc+des) >> 1) - des) + 1,
652 nlabel, strlen(nlabel));
653 }
654
655 xitk_font_unload_font(fs);
656
657 }
658
659 }
660
661 }
662
663 /*
664 *
665 */
create_sliders(void)666 static void create_sliders(void) {
667 xitk_slider_widget_t sl;
668
669 XITK_WIDGET_INIT(&sl, test->imlibdata);
670
671 sl.min = -1000;
672 sl.max = 1000;
673 sl.step = 1;
674 sl.skin_element_name = NULL;
675 sl.callback = NULL;
676 sl.userdata = NULL;
677 sl.motion_callback = move_sliders;
678 sl.motion_userdata = NULL;
679 xitk_add_widget (test->widget_list,
680 (test->hslider = xitk_noskin_slider_create(test->widget_list, &sl,
681 17, 208, 117, 20,
682 XITK_HSLIDER)));
683 xitk_enable_and_show_widget(test->hslider);
684 xitk_slider_set_pos(test->hslider, 0);
685
686 xitk_set_widget_tips_default(test->hslider, "This is an horizontal slider");
687
688 sl.min = -1000;
689 sl.max = 1000;
690 sl.step = 1;
691 sl.skin_element_name = NULL;
692 sl.callback = NULL;
693 sl.userdata = NULL;
694 sl.motion_callback = move_sliders;
695 sl.motion_userdata = NULL;
696 xitk_add_widget (test->widget_list,
697 (test->vslider = xitk_noskin_slider_create(test->widget_list, &sl,
698 17, 230, 20, 117,
699 XITK_VSLIDER)));
700 xitk_enable_and_show_widget(test->vslider);
701 xitk_slider_set_pos(test->vslider, 0);
702
703 xitk_set_widget_tips_default(test->vslider, "This is a vertical slider");
704
705 sl.min = -1000;
706 sl.max = 1000;
707 sl.step = 1;
708 sl.skin_element_name = NULL;
709 sl.callback = NULL;
710 sl.userdata = NULL;
711 sl.motion_callback = move_sliders;
712 sl.motion_userdata = NULL;
713 xitk_add_widget (test->widget_list,
714 (test->rslider = xitk_noskin_slider_create(test->widget_list, &sl,
715 50, 240, 80, 80,
716 XITK_RSLIDER)));
717 xitk_enable_and_show_widget(test->rslider);
718 xitk_slider_set_pos(test->rslider, 0);
719
720 xitk_set_widget_tips_default(test->rslider, "This is a rotate button");
721
722 }
723
combo_select(xitk_widget_t * w,void * data,int select)724 static void combo_select(xitk_widget_t *w, void *data, int select) {
725
726 /*
727 xitk_window_dialog_error(test->imlibdata, NULL, NULL, NULL, buf);
728 */
729 /*
730 xitk_window_dialog_yesnocancel(test->imlibdata, NULL,
731 window_message_cb,
732 window_message_cb,
733 window_message_cb, NULL, buf);
734 */
735 xitk_window_dialog_yesno(test->imlibdata, NULL,
736 window_message_cb,
737 window_message_cb,
738 NULL, ALIGN_DEFAULT,
739 "New entries selected in combo box is:\n%s [%d].",
740 test->entries[select], select);
741
742 }
743
744 /*
745 *
746 */
create_combo(void)747 static void create_combo(void) {
748 xitk_combo_widget_t cmb;
749 char *fontname = "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*";
750 int x = 150, y = 36, width = 100, height;
751 xitk_font_t *fs;
752
753 XITK_WIDGET_INIT(&cmb, test->imlibdata);
754 /*
755 xitk_window_get_window_size(test->xwin, &wwidth, &wheight);
756 bg = xitk_image_create_pixmap(test->imlibdata, wwidth, wheight);
757 XCopyArea(test->display, (xitk_window_get_background(test->xwin)), bg, XITK_WIDGET_LIST_GC(test->widget_list),
758 0, 0, wwidth, wheight, 0, 0);
759 */
760 fs = xitk_font_load_font(test->display, fontname);
761 xitk_font_set_font(fs, XITK_WIDGET_LIST_GC(test->widget_list));
762 height = xitk_font_get_string_height(fs, FONT_HEIGHT_MODEL);
763 xitk_font_unload_font(fs);
764 /*
765 draw_rectangular_inner_box(test->imlibdata, bg, (x - 4), (y - 4), (width + 8), (height + 7));
766 xitk_window_change_background(test->imlibdata, test->xwin, bg, wwidth, wheight);
767
768 XFreePixmap(test->display, bg);
769 */
770
771 cmb.skin_element_name = NULL;
772 cmb.parent_wlist = test->widget_list;
773 cmb.entries = (const char **)test->entries;
774 cmb.layer_above = 0;
775 cmb.parent_wkey = &test->kreg;
776 cmb.callback = combo_select;
777 cmb.userdata = NULL;
778 xitk_add_widget (test->widget_list,
779 (test->combo =
780 xitk_noskin_combo_create(test->widget_list, &cmb,
781 x, y, width, NULL, NULL)));
782 xitk_set_widget_tips_default(test->combo, "This is a combo box.");
783 xitk_enable_and_show_widget(test->combo);
784 }
785
786 /*
787 *
788 */
create_browser(void)789 static void create_browser(void) {
790 xitk_browser_widget_t browser;
791 char *fontname = "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*";
792 Pixmap bg;
793 int width, height;
794
795 XITK_WIDGET_INIT(&browser, test->imlibdata);
796
797 xitk_window_get_window_size(test->xwin, &width, &height);
798 bg = xitk_image_create_pixmap(test->imlibdata, width, height);
799 XCopyArea(test->display, (xitk_window_get_background(test->xwin)), bg, XITK_WIDGET_LIST_GC(test->widget_list),
800 0, 0, width, height, 0, 0);
801
802 XSetForeground(test->display, XITK_WIDGET_LIST_GC(test->widget_list),
803 xitk_get_pixel_color_black(test->imlibdata));
804 XDrawRectangle(test->display, bg, XITK_WIDGET_LIST_GC(test->widget_list), 17, 27, 117, 176);
805
806 xitk_window_change_background(test->imlibdata,
807 test->xwin, bg, width, height);
808 XFreePixmap(test->display, bg);
809
810 {
811 int i;
812 char buf[64];
813
814 for(i = 0; i < 25; i++) {
815 memset(&buf, 0, sizeof(buf));
816 snprintf(buf, sizeof(buf), "Entry %d", i);
817 test->entries[i] = strdup(buf);
818 }
819
820 test->entries[i] = NULL;
821 test->num_entries = i;
822 }
823
824 browser.arrow_up.skin_element_name = NULL;
825 browser.slider.skin_element_name = NULL;
826 browser.arrow_dn.skin_element_name = NULL;
827 browser.browser.skin_element_name = NULL;
828 browser.browser.max_displayed_entries = 8;
829 browser.browser.num_entries = test->num_entries;
830 browser.browser.entries = (const char *const *)test->entries;
831 browser.callback = change_inputtext;
832 browser.dbl_click_callback = change_inputtext_dbl_click;
833 browser.parent_wlist = test->widget_list;
834 browser.userdata = NULL;
835 xitk_add_widget (test->widget_list,
836 (test->browser =
837 xitk_noskin_browser_create(test->widget_list, &browser,
838 XITK_WIDGET_LIST_GC(test->widget_list), 20, 30,
839 100, 20, 12, fontname)));
840 xitk_enable_and_show_widget(test->browser);
841
842 xitk_browser_update_list(test->browser,
843 (const char *const *)test->entries, NULL, test->num_entries, 0);
844
845 }
846
menu_checked(xitk_widget_t * w,xitk_menu_entry_t * me,void * data)847 static void menu_checked(xitk_widget_t *w, xitk_menu_entry_t *me, void *data) {
848 test->checked = !test->checked;
849 }
menu_test_end(xitk_widget_t * w,xitk_menu_entry_t * me,void * data)850 static void menu_test_end(xitk_widget_t *w, xitk_menu_entry_t *me, void *data) {
851 test_end(NULL, NULL);
852 }
create_menu(void)853 static void create_menu(void) {
854 xitk_menu_widget_t menu;
855 int x = 10, y = 10;
856 xitk_menu_entry_t menu_entries[] = {
857 { "Popup menu:", NULL, "<title>", NULL, NULL },
858 { "Load a file", NULL, NULL, NULL, NULL },
859 { "Reload", NULL, NULL, NULL, NULL },
860 { "Auto save", NULL,
861 test->checked ? "<checked>" : "<check>", menu_checked, NULL },
862 { "SEP", NULL, "<separator>", NULL, NULL },
863 { "Empty", NULL, "<branch>", NULL, NULL },
864 { "Playlist", NULL, "<branch>", NULL, NULL },
865 { "Playlist/Playlist Management", NULL, "<title>", NULL, NULL },
866 { "Playlist/Load", NULL, NULL, NULL, NULL },
867 { "Playlist/Loop", NULL, "<branch>", NULL, NULL },
868 { "Playlist/Loop/no loop", NULL, "<checked>", NULL, NULL },
869 { "Playlist/Loop/simple loop", NULL, "<check>", NULL, NULL },
870 { "Playlist/Loop/SEP", NULL, "<separator>", NULL, NULL },
871 { "Playlist/Loop/repeat entry", NULL, "<check>", NULL, NULL },
872 { "Playlist/Loop/SEP", NULL, "<separator>", NULL, NULL },
873 { "Playlist/Loop/shuffle", NULL, "<check>", NULL, NULL },
874 { "Playlist/Loop/infinite shuffle", NULL, "<check>", NULL, NULL },
875 { "Playlist/Loop/Extra", NULL, "<branch>", NULL, NULL },
876 { "Playlist/Save", NULL, NULL, NULL, NULL },
877 { "Another branch", NULL, "<branch>", NULL, NULL },
878 { "Another branch/dummy", NULL, NULL, NULL, NULL },
879 { "Another branch/vice\\/versa", NULL, NULL, NULL, NULL },
880 { "SEP", NULL, "<separator>", NULL, NULL },
881 /* Testing deep sub-branches */
882 { "Deep", NULL, "<branch>", NULL, NULL },
883 { "Deep/Deep 2", NULL, "<branch>", NULL, NULL },
884 { "Deep/Deep 2/Deep 3", NULL, "<branch>", NULL, NULL },
885 { "Deep/Deep 2/Deep 3/Deep 4", NULL, "<branch>", NULL, NULL },
886 { "Deep/Deep 2/Deep 3/Deep 4/Deep 5",
887 NULL, "<branch>", NULL, NULL },
888 { "Deep/Deep 2/Deep 3/Deep 4/Deep 5/Entry number 1",
889 NULL, NULL, NULL, NULL },
890 { "Deep/Deep 2/Deep 3/Deep 4/Deep 5/SEP",
891 NULL, "<separator>", NULL, NULL },
892 { "Deep/Deep 2/Deep 3/Deep 4/Deep 5/Entry number 2",
893 NULL, NULL, NULL, NULL },
894 { "SEP", NULL, "<separator>", NULL, NULL },
895 { "Save a file", NULL, NULL, NULL, NULL },
896 { "SEP", NULL, "<separator>", NULL, NULL },
897 { "Video", NULL, "<branch>", NULL, NULL },
898 { "Video/premier", NULL, "<branch>", NULL, NULL },
899 { "Video/premier/Le Voili", NULL, NULL, NULL, NULL },
900 { "Video/second", NULL, NULL, NULL, NULL },
901 { "Video/troisieme", NULL, NULL, NULL, NULL },
902 { "Video/quatrieme", NULL, NULL, NULL, NULL },
903 { "SEP", NULL, "<separator>", NULL, NULL },
904 { "Quit", "C-q", NULL, menu_test_end, NULL },
905 { NULL, NULL, NULL, NULL, NULL }
906 };
907
908 XITK_WIDGET_INIT(&menu, test->imlibdata);
909
910 (void) xitk_get_mouse_coords(test->display,
911 (xitk_window_get_window(test->xwin)), NULL, NULL, &x, &y);
912
913 menu.menu_tree = &menu_entries[0];
914 menu.parent_wlist = test->widget_list;
915 menu.skin_element_name = NULL;
916
917 test->menu = xitk_noskin_menu_create(test->widget_list, &menu, x, y);
918
919 {
920 xitk_menu_entry_t menu_entry;
921
922 memset(&menu_entry, 0, sizeof(xitk_menu_entry_t));
923 menu_entry.menu = "Playlist/Loop/Extra/errrr?";
924 xitk_menu_add_entry(test->menu, &menu_entry);
925 }
926
927
928 xitk_menu_show_menu(test->menu);
929 }
930
test_dndcb(char * file)931 static void test_dndcb(char *file) {
932 printf("file: '%s'\n", file);
933 }
934
935 /*
936 *
937 */
main(int argc,char ** argv)938 int main(int argc, char **argv) {
939 GC gc;
940 xitk_labelbutton_widget_t lb;
941 char *fontname = "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*";
942 int windoww = 600, windowh = 400;
943 xitk_widget_t *w;
944
945 if(!init_test()) {
946 printf("init_test() failed\n");
947 exit(1);
948 }
949
950 #ifdef ENABLE_NLS
951 xitk_set_locale();
952 printf("locale: %s\n", setlocale (LC_ALL, ""));
953 #endif
954
955 printf("bindtextdomain: %s\n", bindtextdomain("xitk", XITK_LOCALE));
956 textdomain("xitk");
957
958 /* Create window */
959 test->xwin = xitk_window_create_dialog_window(test->imlibdata,
960 "My Test Window",
961 100, 100, windoww, windowh);
962
963 XLOCK (XLockDisplay, test->display);
964
965 #undef DUMP_ATOMS
966 #ifdef DUMP_ATOMS
967 {
968 int i = 1;
969 char *atom_name;
970
971 for(;;i++) {
972 if((atom_name = XGetAtomName(test->display, (Atom)i)))
973 printf("Atom %d: '%s'\n", i, atom_name);
974 else
975 break;
976 }
977 }
978 #endif
979
980
981 gc = XCreateGC(test->display,
982 (xitk_window_get_window(test->xwin)), None, None);
983
984 test->widget_list = xitk_widget_list_new();
985 xitk_widget_list_set(test->widget_list,
986 WIDGET_LIST_WINDOW, (void *) (xitk_window_get_window(test->xwin)));
987 xitk_widget_list_set(test->widget_list, WIDGET_LIST_GC, gc);
988
989 XITK_WIDGET_INIT(&lb, test->imlibdata);
990
991 lb.button_type = CLICK_BUTTON;
992 lb.label = "Quit";
993 lb.align = ALIGN_CENTER;
994 lb.callback = test_end;
995 lb.state_callback = NULL;
996 lb.userdata = NULL;
997 lb.skin_element_name = NULL;
998 xitk_add_widget (test->widget_list,
999 (w = xitk_noskin_labelbutton_create(test->widget_list, &lb,
1000 (windoww / 2) - 50, windowh - 50,
1001 100, 30,
1002 "Black", "Black", "White", fontname)));
1003 xitk_enable_and_show_widget(w);
1004 xitk_set_widget_tips_default(w, "Do you really want to leave me?");
1005
1006 create_browser();
1007 create_sliders();
1008 create_button();
1009 create_combo();
1010 create_label();
1011 create_inputtext();
1012 create_frame();
1013 create_tabs();
1014 create_intbox();
1015 create_doublebox();
1016 create_checkbox();
1017
1018 test->kreg = xitk_register_event_handler("test",
1019 (xitk_window_get_window(test->xwin)),
1020 test_handle_event,
1021 NULL,
1022 test_dndcb,
1023 test->widget_list,
1024 NULL);
1025
1026 XUNLOCK (XUnlockDisplay, test->display);
1027
1028 XMapRaised(test->display, xitk_window_get_window(test->xwin));
1029
1030 xitk_run(NULL, NULL);
1031
1032 deinit_test();
1033
1034 XCloseDisplay(test->display);
1035
1036 free(test);
1037 test = NULL;
1038
1039 return 1;
1040 }
1041