00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef __CTK_H__
00051 #define __CTK_H__
00052
00053
00054 #include "contiki-conf.h"
00055 #include "contiki.h"
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #define CTK_WIDGET_SEPARATOR 1
00066
00067 #define CTK_WIDGET_LABEL 2
00068
00069 #define CTK_WIDGET_BUTTON 3
00070
00071 #define CTK_WIDGET_HYPERLINK 4
00072
00073 #define CTK_WIDGET_TEXTENTRY 5
00074
00075 #define CTK_WIDGET_BITMAP 6
00076
00077 #define CTK_WIDGET_ICON 7
00078
00079
00080
00081 struct ctk_widget;
00082
00083 #if CTK_CONF_WIDGET_FLAGS
00084 #define CTK_WIDGET_FLAG_INITIALIZER(x) x,
00085 #else
00086 #define CTK_WIDGET_FLAG_INITIALIZER(x)
00087 #endif
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 #define CTK_SEPARATOR(x, y, w) \
00113 NULL, NULL, x, y, CTK_WIDGET_SEPARATOR, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0)
00114 struct ctk_separator {
00115 struct ctk_widget *next;
00116 struct ctk_window *window;
00117 unsigned char x, y;
00118 unsigned char type;
00119 unsigned char w, h;
00120 #if CTK_CONF_WIDGET_FLAGS
00121 unsigned char flags;
00122 #endif
00123 };
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 #define CTK_BUTTON(x, y, w, text) \
00142 NULL, NULL, x, y, CTK_WIDGET_BUTTON, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text
00143 struct ctk_button {
00144 struct ctk_widget *next;
00145 struct ctk_window *window;
00146 unsigned char x, y;
00147 unsigned char type;
00148 unsigned char w, h;
00149 #if CTK_CONF_WIDGET_FLAGS
00150 unsigned char flags;
00151 #endif
00152 char *text;
00153 };
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 #define CTK_LABEL(x, y, w, h, text) \
00173 NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text,
00174 struct ctk_label {
00175 struct ctk_widget *next;
00176 struct ctk_window *window;
00177 unsigned char x, y;
00178 unsigned char type;
00179 unsigned char w, h;
00180 #if CTK_CONF_WIDGET_FLAGS
00181 unsigned char flags;
00182 #endif
00183 char *text;
00184 };
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 #define CTK_HYPERLINK(x, y, w, text, url) \
00204 NULL, NULL, x, y, CTK_WIDGET_HYPERLINK, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, url
00205 struct ctk_hyperlink {
00206 struct ctk_widget *next;
00207 struct ctk_window *window;
00208 unsigned char x, y;
00209 unsigned char type;
00210 unsigned char w, h;
00211 #if CTK_CONF_WIDGET_FLAGS
00212 unsigned char flags;
00213 #endif
00214 char *text;
00215 char *url;
00216 };
00217
00218
00219 #define CTK_TEXTENTRY_NORMAL 0
00220
00221 #define CTK_TEXTENTRY_EDIT 1
00222
00223
00224
00225
00226
00227
00228
00229
00230 #define CTK_TEXTENTRY_CLEAR(e) \
00231 do { memset((e)->text, 0, (e)->h * ((e)->len + 1)); \
00232 (e)->xpos = 0; (e)->ypos = 0; } while(0)
00233
00234 #ifdef CTK_ARCH_KEY_T
00235 typedef CTK_ARCH_KEY_T ctk_arch_key_t;
00236 #else
00237 typedef char ctk_arch_key_t;
00238 #endif
00239
00240 struct ctk_textentry;
00241 typedef unsigned char (* ctk_textentry_input)(ctk_arch_key_t c,
00242 struct ctk_textentry *t);
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 #define CTK_TEXTENTRY(x, y, w, h, text, len) \
00266 NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
00267 CTK_TEXTENTRY_NORMAL, 0, 0, NULL
00268 #define CTK_TEXTENTRY_INPUT(x, y, w, h, text, len, input) \
00269 NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
00270 CTK_TEXTENTRY_NORMAL, 0, 0, (ctk_textentry_input)input
00271 struct ctk_textentry {
00272 struct ctk_widget *next;
00273 struct ctk_window *window;
00274 unsigned char x, y;
00275 unsigned char type;
00276 unsigned char w, h;
00277 #if CTK_CONF_WIDGET_FLAGS
00278 unsigned char flags;
00279 #endif
00280 char *text;
00281 unsigned char len;
00282 unsigned char state;
00283 unsigned char xpos, ypos;
00284 ctk_textentry_input input;
00285 };
00286
00287
00288 #if CTK_CONF_ICON_BITMAPS
00289 #define CTK_ICON_BITMAP(bitmap) bitmap
00290 #else
00291 #define CTK_ICON_BITMAP(bitmap) NULL
00292 #endif
00293
00294 #if CTK_CONF_ICON_TEXTMAPS
00295 #define CTK_ICON_TEXTMAP(textmap) textmap
00296 #else
00297 #define CTK_ICON_TEXTMAP(textmap) NULL
00298 #endif
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 #define CTK_ICON(title, bitmap, textmap) \
00314 NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, 4, CTK_WIDGET_FLAG_INITIALIZER(0) \
00315 title, PROCESS_NONE, \
00316 CTK_ICON_BITMAP(bitmap), CTK_ICON_TEXTMAP(textmap)
00317 struct ctk_icon {
00318 struct ctk_widget *next;
00319 struct ctk_window *window;
00320 unsigned char x, y;
00321 unsigned char type;
00322 unsigned char w, h;
00323 #if CTK_CONF_WIDGET_FLAGS
00324 unsigned char flags;
00325 #endif
00326 char *title;
00327 struct process *owner;
00328 unsigned char *bitmap;
00329 char *textmap;
00330 };
00331
00332 #define CTK_BITMAP(x, y, w, h, bitmap, bitmap_width, bitmap_height) \
00333 NULL, NULL, x, y, CTK_WIDGET_BITMAP, w, h, \
00334 CTK_WIDGET_FLAG_INITIALIZER(0) bitmap, bitmap_width, bitmap_height
00335 struct ctk_bitmap {
00336 struct ctk_widget *next;
00337 struct ctk_window *window;
00338 unsigned char x, y;
00339 unsigned char type;
00340 unsigned char w, h;
00341 #if CTK_CONF_WIDGET_FLAGS
00342 unsigned char flags;
00343 #endif
00344 unsigned char *bitmap;
00345 unsigned short bw, bh;
00346 };
00347
00348 #define CTK_TEXTMAP_NORMAL 0
00349 #define CTK_TEXTMAP_ACTIVE 1
00350
00351 #define CTK_TEXTMAP(x, y, w, h, textmap) \
00352 NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, CTK_TEXTMAP_NORMAL
00353 struct ctk_textmap {
00354 struct ctk_widget *next;
00355 struct ctk_window *window;
00356 unsigned char x, y;
00357 unsigned char type;
00358 unsigned char w, h;
00359 #if CTK_CONF_WIDGET_FLAGS
00360 unsigned char flags;
00361 #endif
00362 char *textmap;
00363 unsigned char state;
00364 };
00365
00366
00367
00368
00369
00370 struct ctk_widget_button {
00371 char *text;
00372 };
00373
00374
00375
00376
00377 struct ctk_widget_label {
00378 char *text;
00379 };
00380
00381
00382
00383
00384 struct ctk_widget_hyperlink {
00385 char *text;
00386 char *url;
00387 };
00388
00389 struct ctk_widget_textentry {
00390 char *text;
00391 unsigned char len;
00392 unsigned char state;
00393 unsigned char xpos, ypos;
00394 ctk_textentry_input input;
00395 };
00396
00397 struct ctk_widget_icon {
00398 char *title;
00399 struct process *owner;
00400 unsigned char *bitmap;
00401 char *textmap;
00402 };
00403
00404 struct ctk_widget_bitmap {
00405 unsigned char *bitmap;
00406 unsigned short bw, bh;
00407 };
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 struct ctk_widget {
00428 struct ctk_widget *next;
00429
00430
00431 struct ctk_window *window;
00432
00433 unsigned char x,
00434
00435
00436 y;
00437
00438
00439 unsigned char type;
00440
00441
00442
00443
00444
00445
00446 unsigned char w,
00447
00448 h;
00449
00450 #if CTK_CONF_WIDGET_FLAGS
00451 unsigned char flags;
00452 #endif
00453
00454 union {
00455 struct ctk_widget_label label;
00456 struct ctk_widget_button button;
00457 struct ctk_widget_hyperlink hyperlink;
00458 struct ctk_widget_textentry textentry;
00459 struct ctk_widget_icon icon;
00460 struct ctk_widget_bitmap bitmap;
00461 } widget;
00462
00463
00464 };
00465
00466
00467 struct ctk_desktop;
00468
00469 #define CTK_WIDGET_FLAG_NONE 0
00470 #define CTK_WIDGET_FLAG_MONOSPACE 1
00471 #define CTK_WIDGET_FLAG_CENTER 2
00472
00473 #if CTK_CONF_WIDGET_FLAGS
00474 #define CTK_WIDGET_SET_FLAG(w, f) ((struct ctk_widget *)(w))->flags = (f)
00475 #else
00476 #define CTK_WIDGET_SET_FLAG(w, f)
00477 #endif
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 struct ctk_window {
00490 struct ctk_window *next,
00491
00492
00493 *prev;
00494
00495 struct ctk_desktop *desktop;
00496
00497
00498 struct process *owner;
00499
00500
00501
00502
00503 char *title;
00504
00505 unsigned char titlelen;
00506
00507
00508 #if CTK_CONF_WINDOWCLOSE
00509 struct ctk_button closebutton;
00510
00511
00512 #else
00513 struct ctk_label closebutton;
00514 #endif
00515
00516 #if CTK_CONF_WINDOWMOVE
00517 struct ctk_button titlebutton;
00518
00519
00520
00521 #else
00522 struct ctk_label titlebutton;
00523 #endif
00524
00525 unsigned char x,
00526
00527 y;
00528
00529 unsigned char w,
00530
00531 h;
00532
00533
00534
00535 struct ctk_widget *inactive;
00536
00537
00538
00539 struct ctk_widget *active;
00540
00541
00542
00543 struct ctk_widget *focused;
00544
00545
00546
00547 };
00548
00549
00550
00551
00552 struct ctk_menuitem {
00553 char *title;
00554 unsigned char titlelen;
00555
00556 };
00557
00558 #ifdef CTK_CONF_MAXMENUITEMS
00559 #define CTK_MAXMENUITEMS CTK_CONF_MAXMENUITEMS
00560 #else
00561 #define CTK_MAXMENUITEMS 8
00562 #endif
00563
00564
00565
00566
00567 struct ctk_menu {
00568 struct ctk_menu *next;
00569
00570
00571
00572
00573 char *title;
00574 unsigned char titlelen;
00575
00576 #if CC_UNSIGNED_CHAR_BUGS
00577 unsigned int nitems;
00578 unsigned int active;
00579 #else
00580 unsigned char nitems;
00581
00582 unsigned char active;
00583 #endif
00584 struct ctk_menuitem items[CTK_MAXMENUITEMS];
00585
00586
00587 };
00588
00589
00590
00591
00592 struct ctk_menus {
00593 struct ctk_menu *menus;
00594
00595
00596 struct ctk_menu *open;
00597
00598
00599 struct ctk_menu *desktopmenu;
00600
00601
00602
00603
00604 };
00605
00606
00607
00608
00609
00610
00611
00612 struct ctk_desktop {
00613 char *name;
00614
00615 struct ctk_window desktop_window;
00616
00617 struct ctk_window *windows;
00618 struct ctk_window *dialog;
00619
00620
00621 #if CTK_CONF_MENUS
00622 struct ctk_menus menus;
00623 struct ctk_menu *lastmenu;
00624 struct ctk_menu desktopmenu;
00625 #endif
00626
00627 unsigned char height,
00628 width;
00629
00630
00631 #define CTK_REDRAW_NONE 0
00632
00633 #define CTK_REDRAW_ALL 1
00634
00635 #define CTK_REDRAW_WINDOWS 2
00636
00637 #define CTK_REDRAW_WIDGETS 4
00638
00639 #define CTK_REDRAW_MENUS 8
00640
00641 #define CTK_REDRAW_PART 16
00642
00643
00644 #ifndef CTK_CONF_MAX_REDRAWWIDGETS
00645 #define CTK_CONF_MAX_REDRAWWIDGETS 8
00646 #endif
00647 #ifndef CTK_CONF_MAX_REDRAWWINDOWS
00648 #define CTK_CONF_MAX_REDRAWWINDOWS 8
00649 #endif
00650
00651 unsigned char redraw;
00652
00653 struct ctk_widget *redraw_widgets[CTK_CONF_MAX_REDRAWWIDGETS];
00654 unsigned char redraw_widgetptr;
00655
00656 struct ctk_window *redraw_windows[CTK_CONF_MAX_REDRAWWINDOWS];
00657 unsigned char redraw_windowptr;
00658
00659 unsigned char redraw_y1,
00660 redraw_y2;
00661 };
00662
00663
00664
00665 #define CTK_MODE_NORMAL 0
00666 #define CTK_MODE_WINDOWMOVE 1
00667 #define CTK_MODE_SCREENSAVER 2
00668 #define CTK_MODE_EXTERNAL 3
00669
00670
00671 PROCESS_NAME(ctk_process);
00672 void ctk_init(void);
00673 void ctk_restore(void);
00674
00675 void ctk_mode_set(unsigned char mode);
00676 unsigned char ctk_mode_get(void);
00677
00678
00679
00680 void ctk_window_new(struct ctk_window *window,
00681 unsigned char w, unsigned char h,
00682 char *title);
00683 void ctk_window_clear(struct ctk_window *w);
00684 void ctk_window_open(struct ctk_window *w);
00685 #define ctk_window_move(w,xpos,ypos) do { (w)->x=xpos; (w)->y=ypos; } while(0)
00686 void ctk_window_close(struct ctk_window *w);
00687 void ctk_window_redraw(struct ctk_window *w);
00688 #define ctk_window_isopen(w) ((w)->next != NULL)
00689
00690
00691
00692 void ctk_dialog_new(struct ctk_window *window,
00693 unsigned char w, unsigned char h);
00694 void ctk_dialog_open(struct ctk_window *d);
00695 void ctk_dialog_close(void);
00696
00697
00698 void ctk_menu_new(struct ctk_menu *menu, char *title);
00699 void ctk_menu_add(struct ctk_menu *menu);
00700 void ctk_menu_remove(struct ctk_menu *menu);
00701 unsigned char ctk_menuitem_add(struct ctk_menu *menu, char *name);
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716 #define CTK_ICON_ADD(icon, p) ctk_icon_add((struct ctk_widget *)icon, p)
00717 void ctk_icon_add(struct ctk_widget *icon, struct process *p);
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727 #define CTK_WIDGET_ADD(win, widg) \
00728 ctk_widget_add(win, (struct ctk_widget *)widg)
00729 void CC_FASTCALL ctk_widget_add(struct ctk_window *window,
00730 struct ctk_widget *widget);
00731
00732
00733
00734
00735
00736
00737
00738 #define CTK_WIDGET_FOCUS(win, widg) \
00739 (win)->focused = (struct ctk_widget *)(widg)
00740
00741
00742
00743
00744
00745
00746 #define CTK_WIDGET_REDRAW(widg) \
00747 ctk_widget_redraw((struct ctk_widget *)widg)
00748 void ctk_widget_redraw(struct ctk_widget *w);
00749
00750
00751
00752
00753
00754
00755 #define CTK_WIDGET_TYPE(w) ((w)->type)
00756
00757
00758
00759
00760
00761
00762
00763
00764 #define CTK_WIDGET_SET_WIDTH(widget, width) do { \
00765 ((struct ctk_widget *)(widget))->w = (width); } while(0)
00766
00767
00768
00769
00770
00771
00772
00773
00774 #define CTK_WIDGET_XPOS(w) (((struct ctk_widget *)(w))->x)
00775
00776
00777
00778
00779
00780
00781
00782
00783 #define CTK_WIDGET_SET_XPOS(w, xpos) \
00784 ((struct ctk_widget *)(w))->x = (xpos)
00785
00786
00787
00788
00789
00790
00791
00792 #define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
00793
00794
00795
00796
00797
00798
00799
00800
00801 #define CTK_WIDGET_SET_YPOS(w, ypos) \
00802 ((struct ctk_widget *)(w))->y = (ypos)
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815 #define ctk_label_set_height(w, height) \
00816 (w)->widget.label.h = (height)
00817
00818
00819
00820
00821
00822
00823
00824 #define ctk_label_set_text(l, t) (l)->text = (t)
00825
00826
00827
00828
00829
00830
00831
00832 #define ctk_button_set_text(b, t) (b)->text = (t)
00833
00834 #define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m)
00835
00836 #define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
00837 do { (widg)->window = NULL; \
00838 (widg)->next = NULL; \
00839 (widg)->type = CTK_WIDGET_BUTTON; \
00840 (widg)->x = (xpos); \
00841 (widg)->y = (ypos); \
00842 (widg)->w = (width); \
00843 (widg)->h = 1; \
00844 (widg)->text = (buttontext); \
00845 } while(0)
00846
00847 #define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
00848 do { (widg)->window = NULL; \
00849 (widg)->next = NULL; \
00850 (widg)->type = CTK_WIDGET_LABEL; \
00851 (widg)->x = (xpos); \
00852 (widg)->y = (ypos); \
00853 (widg)->w = (width); \
00854 (widg)->h = (height); \
00855 (widg)->text = (labeltext); \
00856 } while(0)
00857
00858 #define CTK_BITMAP_NEW(widg, xpos, ypos, width, height, bmap) \
00859 do { (widg)->window = NULL; \
00860 (widg)->next = NULL; \
00861 (widg)->type = CTK_WIDGET_BITMAP; \
00862 (widg)->x = (xpos); \
00863 (widg)->y = (ypos); \
00864 (widg)->w = (width); \
00865 (widg)->h = (height); \
00866 (widg)->bitmap = (bmap); \
00867 } while(0)
00868
00869 #define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
00870 do { (widg)->window = NULL; \
00871 (widg)->next = NULL; \
00872 (widg)->type = CTK_WIDGET_TEXTENTRY; \
00873 (widg)->x = (xxpos); \
00874 (widg)->y = (yypos); \
00875 (widg)->w = (width); \
00876 (widg)->h = 1; \
00877 (widg)->text = (textptr); \
00878 (widg)->len = (textlen); \
00879 (widg)->state = CTK_TEXTENTRY_NORMAL; \
00880 (widg)->xpos = 0; \
00881 (widg)->ypos = 0; \
00882 (widg)->input = NULL; \
00883 } while(0)
00884
00885 #define CTK_TEXTENTRY_INPUT_NEW(widg, xxpos, yypos, width, height, textptr, textlen, iinput) \
00886 do { (widg)->window = NULL; \
00887 (widg)->next = NULL; \
00888 (widg)->type = CTK_WIDGET_TEXTENTRY; \
00889 (widg)->x = (xxpos); \
00890 (widg)->y = (yypos); \
00891 (widg)->w = (width); \
00892 (widg)->h = (height); \
00893 (widg)->text = (textptr); \
00894 (widg)->len = (textlen); \
00895 (widg)->state = CTK_TEXTENTRY_NORMAL; \
00896 (widg)->xpos = 0; \
00897 (widg)->ypos = 0; \
00898 (widg)->input = (ctk_textentry_input)(iinput); \
00899 } while(0)
00900
00901 #define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
00902 do { (widg)->window = NULL; \
00903 (widg)->next = NULL; \
00904 (widg)->type = CTK_WIDGET_HYPERLINK; \
00905 (widg)->x = (xpos); \
00906 (widg)->y = (ypos); \
00907 (widg)->w = (width); \
00908 (widg)->h = 1; \
00909 (widg)->text = (linktext); \
00910 (widg)->url = (linkurl); \
00911 } while(0)
00912
00913
00914 void ctk_desktop_redraw(struct ctk_desktop *d);
00915 unsigned char ctk_desktop_width(struct ctk_desktop *d);
00916 unsigned char ctk_desktop_height(struct ctk_desktop *d);
00917
00918
00919 extern process_event_t ctk_signal_keypress,
00920 ctk_signal_widget_activate,
00921 ctk_signal_widget_select,
00922 ctk_signal_timer,
00923 ctk_signal_menu_activate,
00924 ctk_signal_window_close,
00925 ctk_signal_pointer_move,
00926 ctk_signal_pointer_button;
00927
00928 #if CTK_CONF_SCREENSAVER
00929 extern process_event_t ctk_signal_screensaver_stop,
00930 ctk_signal_screensaver_start;
00931
00932 extern unsigned short ctk_screensaver_timeout;
00933
00934
00935
00936
00937
00938 #define CTK_SCREENSAVER_SET_TIMEOUT(t) ctk_screensaver_timeout = (t)
00939
00940
00941
00942
00943
00944 #define CTK_SCREENSAVER_TIMEOUT() ctk_screensaver_timeout
00945 #endif
00946
00947
00948 extern process_event_t ctk_signal_button_activate,
00949 ctk_signal_button_hover,
00950 ctk_signal_hyperlink_activate,
00951 ctk_signal_hyperlink_hover;
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961 #define CTK_FOCUS_NONE 0
00962
00963 #define CTK_FOCUS_WIDGET 1
00964
00965 #define CTK_FOCUS_WINDOW 2
00966
00967 #define CTK_FOCUS_DIALOG 4
00968
00969
00970
00971
00972 #endif