Contiki-Inga 3.x
ctk.h
Go to the documentation of this file.
1 /**
2  * \addtogroup ctk
3  * @{
4  */
5 
6 /**
7  * \file
8  * CTK header file.
9  * \author Adam Dunkels <adam@dunkels.com>
10  *
11  * The CTK header file contains functioin declarations and definitions
12  * of CTK structures and macros.
13  */
14 
15 /*
16  * Copyright (c) 2002-2003, Adam Dunkels.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  * 1. Redistributions of source code must retain the above copyright
23  * notice, this list of conditions and the following disclaimer.
24  * 2. Redistributions in binary form must reproduce the above
25  * copyright notice, this list of conditions and the following
26  * disclaimer in the documentation and/or other materials provided
27  * with the distribution.
28  * 3. The name of the author may not be used to endorse or promote
29  * products derived from this software without specific prior
30  * written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
33  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
36  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43  *
44  * This file is part of the Contiki desktop OS.
45  *
46  *
47  */
48 
49 #ifndef CTK_H_
50 #define CTK_H_
51 
52 
53 #include "contiki-conf.h"
54 #include "contiki.h"
55 
56 /* Defintions for the CTK widget types. */
57 
58 /**
59  * \addtogroup ctkdraw
60  * @{
61  */
62 
63 /** Widget number: The CTK separator widget. */
64 #define CTK_WIDGET_SEPARATOR 1
65 /** Widget number: The CTK label widget. */
66 #define CTK_WIDGET_LABEL 2
67 /** Widget number: The CTK button widget. */
68 #define CTK_WIDGET_BUTTON 3
69 /** Widget number: The CTK hyperlink widget. */
70 #define CTK_WIDGET_HYPERLINK 4
71 /** Widget number: The CTK textentry widget. */
72 #define CTK_WIDGET_TEXTENTRY 5
73 /** Widget number: The CTK bitmap widget. */
74 #define CTK_WIDGET_BITMAP 6
75 /** Widget number: The CTK icon widget. */
76 #define CTK_WIDGET_ICON 7
77 
78 /** @} */
79 
80 struct ctk_widget;
81 
82 #if CTK_CONF_WIDGET_FLAGS
83 #define CTK_WIDGET_FLAG_INITIALIZER(x) x,
84 #else
85 #define CTK_WIDGET_FLAG_INITIALIZER(x)
86 #endif
87 
88 /**
89  * \defgroup ctkappfunc CTK application functions
90  *
91  * The CTK functions used by an application program.
92  *
93  * @{
94  */
95 
96 /**
97  * Instantiating macro for the ctk_separator widget.
98  *
99  * This macro is used when instantiating a ctk_separator widget and is
100  * intended to be used together with a struct assignment like this:
101  \code
102  struct ctk_separator sep =
103  {CTK_SEPARATOR(0, 0, 23)};
104  \endcode
105  * \param x The x position of the widget, relative to the widget's
106  * window.
107  * \param y The y position of the widget, relative to the widget's
108  * window.
109  * \param w The widget's width.
110  */
111 #define CTK_SEPARATOR(x, y, w) \
112  NULL, NULL, x, y, CTK_WIDGET_SEPARATOR, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0)
113 struct ctk_separator {
114  struct ctk_widget *next;
115  struct ctk_window *window;
116  unsigned char x, y;
117  unsigned char type;
118  unsigned char w, h;
119 #if CTK_CONF_WIDGET_FLAGS
120  unsigned char flags;
121 #endif /* CTK_CONF_WIDGET_FLAGS */
122 };
123 
124 /**
125  * Instantiating macro for the ctk_button widget.
126  *
127  * This macro is used when instantiating a ctk_button widget and is
128  * intended to be used together with a struct assignment like this:
129  \code
130  struct ctk_button but =
131  {CTK_BUTTON(0, 0, 2, "Ok")};
132  \endcode
133  * \param x The x position of the widget, relative to the widget's
134  * window.
135  * \param y The y position of the widget, relative to the widget's
136  * window.
137  * \param w The widget's width.
138  * \param text The button text.
139  */
140 #define CTK_BUTTON(x, y, w, text) \
141  NULL, NULL, x, y, CTK_WIDGET_BUTTON, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text
142 struct ctk_button {
143  struct ctk_widget *next;
144  struct ctk_window *window;
145  unsigned char x, y;
146  unsigned char type;
147  unsigned char w, h;
148 #if CTK_CONF_WIDGET_FLAGS
149  unsigned char flags;
150 #endif /* CTK_CONF_WIDGET_FLAGS */
151  char *text;
152 };
153 
154 /**
155  * Instantiating macro for the ctk_label widget.
156  *
157  * This macro is used when instantiating a ctk_label widget and is
158  * intended to be used together with a struct assignment like this:
159  \code
160  struct ctk_label lab =
161  {CTK_LABEL(0, 0, 5, 1, "Label")};
162  \endcode
163  * \param x The x position of the widget, relative to the widget's
164  * window.
165  * \param y The y position of the widget, relative to the widget's
166  * window.
167  * \param w The widget's width.
168  * \param h The height of the label.
169  * \param text The label text.
170  */
171 #define CTK_LABEL(x, y, w, h, text) \
172  NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text,
173 struct ctk_label {
174  struct ctk_widget *next;
175  struct ctk_window *window;
176  unsigned char x, y;
177  unsigned char type;
178  unsigned char w, h;
179 #if CTK_CONF_WIDGET_FLAGS
180  unsigned char flags;
181 #endif /* CTK_CONF_WIDGET_FLAGS */
182  char *text;
183 };
184 
185 /**
186  * Instantiating macro for the ctk_hyperlink widget.
187  *
188  * This macro is used when instantiating a ctk_hyperlink widget and is
189  * intended to be used together with a struct assignment like this:
190  \code
191  struct ctk_hyperlink hlink =
192  {CTK_HYPERLINK(0, 0, 7, "Contiki", "http://dunkels.com/adam/contiki/")};
193  \endcode
194  * \param x The x position of the widget, relative to the widget's
195  * window.
196  * \param y The y position of the widget, relative to the widget's
197  * window.
198  * \param w The widget's width.
199  * \param text The hyperlink text.
200  * \param url The hyperlink URL.
201  */
202 #define CTK_HYPERLINK(x, y, w, text, url) \
203  NULL, NULL, x, y, CTK_WIDGET_HYPERLINK, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, url
204 struct ctk_hyperlink {
205  struct ctk_widget *next;
206  struct ctk_window *window;
207  unsigned char x, y;
208  unsigned char type;
209  unsigned char w, h;
210 #if CTK_CONF_WIDGET_FLAGS
211  unsigned char flags;
212 #endif /* CTK_CONF_WIDGET_FLAGS */
213  char *text;
214  char *url;
215 };
216 
217 /* Editing modes of the CTK textentry widget. */
218 #define CTK_TEXTENTRY_NORMAL 0 /**< \internal Textentry state: not
219  edited. */
220 #define CTK_TEXTENTRY_EDIT 1 /**< \internal Textentry state:
221  currenly being edited. */
222 
223 /**
224  * Clears a text entry widget and sets the cursor to the start of the
225  * text line.
226  *
227  * \param e The text entry widget to be cleared.
228  */
229 #define CTK_TEXTENTRY_CLEAR(e) \
230  do { memset((e)->text, 0, (e)->h * ((e)->len + 1)); \
231  (e)->xpos = 0; (e)->ypos = 0; } while(0)
232 
233 #ifdef CTK_ARCH_KEY_T
234 typedef CTK_ARCH_KEY_T ctk_arch_key_t;
235 #else /* CTK_ARCH_KEY_T */
236 typedef char ctk_arch_key_t;
237 #endif /* CTK_ARCH_KEY_T */
238 
239 #ifndef CH_ENTER
240 #define CH_ENTER '\n'
241 #endif /* CH_ENTER */
242 
243 struct ctk_textentry;
244 typedef unsigned char (* ctk_textentry_input)(ctk_arch_key_t c,
245  struct ctk_textentry *t);
246 
247 /**
248  * Instantiating macro for the ctk_textentry widget.
249  *
250  * This macro is used when instantiating a ctk_textentry widget and is
251  * intended to be used together with a struct assignment like this:
252  \code
253  struct ctk_textentry tentry =
254  {CTK_TEXTENTRY(0, 0, 30, 1, textbuffer, 50)};
255  \endcode
256  * \note The height of the text entry widget is obsolete and not
257  * intended to be used.
258  *
259  * \param x The x position of the widget, relative to the widget's
260  * window.
261  * \param y The y position of the widget, relative to the widget's
262  * window.
263  * \param w The widget's width.
264  * \param h The text entry height (obsolete).
265  * \param text A pointer to the buffer that should be edited.
266  * \param len The length of the text buffer
267  */
268 #ifdef SDCC
269 #define CTK_TEXTENTRY(x, y, w, h, text, len) \
270  NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
271  CTK_TEXTENTRY_NORMAL, 0, 0, ctk_textentry_input_null
272 #else /* SDCC */
273 #define CTK_TEXTENTRY(x, y, w, h, text, len) \
274  NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
275  CTK_TEXTENTRY_NORMAL, 0, 0, NULL
276 #endif /* SDCC */
277 #define CTK_TEXTENTRY_INPUT(x, y, w, h, text, len, input) \
278  NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
279  CTK_TEXTENTRY_NORMAL, 0, 0, input
280 struct ctk_textentry {
281  struct ctk_widget *next;
282  struct ctk_window *window;
283  unsigned char x, y;
284  unsigned char type;
285  unsigned char w, h;
286 #if CTK_CONF_WIDGET_FLAGS
287  unsigned char flags;
288 #endif /* CTK_CONF_WIDGET_FLAGS */
289  char *text;
290  unsigned char len;
291  unsigned char state;
292  unsigned char xpos, ypos;
293  ctk_textentry_input input;
294 };
295 
296 #ifdef SDCC
297 /* Dummy function that we define to keep sdcc happy - with sdcc,
298  function pointers cannot be NULL.*/
299 unsigned char ctk_textentry_input_null(ctk_arch_key_t c, struct ctk_textentry *t);
300 #endif /* SDCC */
301 
302 #if CTK_CONF_ICON_BITMAPS
303 #define CTK_ICON_BITMAP(bitmap) bitmap
304 #else
305 #define CTK_ICON_BITMAP(bitmap) NULL
306 #endif
307 
308 #if CTK_CONF_ICON_TEXTMAPS
309 #define CTK_ICON_TEXTMAP(textmap) textmap
310 #else
311 #define CTK_ICON_TEXTMAP(textmap) NULL
312 #endif
313 
314 /**
315  * Instantiating macro for the ctk_icon widget.
316  *
317  * This macro is used when instantiating a ctk_icon widget and is
318  * intended to be used together with a struct assignment like this:
319  \code
320  struct ctk_icon icon =
321  {CTK_ICON("An icon", bitmapptr, textmapptr)};
322  \endcode
323  * \param title The icon's text.
324  * \param bitmap A pointer to the icon's bitmap image.
325  * \param textmap A pointer to the icon's text version of the bitmap.
326  */
327 #if CTK_CONF_ICONS
328 #define CTK_ICON(title, bitmap, textmap) \
329  NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, 4, CTK_WIDGET_FLAG_INITIALIZER(0) \
330  title, PROCESS_NONE, \
331  CTK_ICON_BITMAP(bitmap), CTK_ICON_TEXTMAP(textmap)
332 struct ctk_icon {
333  struct ctk_widget *next;
334  struct ctk_window *window;
335  unsigned char x, y;
336  unsigned char type;
337  unsigned char w, h;
338 #if CTK_CONF_WIDGET_FLAGS
339  unsigned char flags;
340 #endif /* CTK_CONF_WIDGET_FLAGS */
341  char *title;
342  struct process *owner;
343  unsigned char *bitmap;
344  char *textmap;
345 };
346 
347 #define CTK_BITMAP(x, y, w, h, bitmap, bitmap_width, bitmap_height) \
348  NULL, NULL, x, y, CTK_WIDGET_BITMAP, w, h, \
349  CTK_WIDGET_FLAG_INITIALIZER(0) bitmap, bitmap_width, bitmap_height
350 struct ctk_bitmap {
351  struct ctk_widget *next;
352  struct ctk_window *window;
353  unsigned char x, y;
354  unsigned char type;
355  unsigned char w, h;
356 #if CTK_CONF_WIDGET_FLAGS
357  unsigned char flags;
358 #endif /* CTK_CONF_WIDGET_FLAGS */
359  unsigned char *bitmap;
360  unsigned short bw, bh;
361 };
362 
363 #define CTK_TEXTMAP_NORMAL 0
364 #define CTK_TEXTMAP_ACTIVE 1
365 
366 #define CTK_TEXTMAP(x, y, w, h, textmap) \
367  NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, CTK_TEXTMAP_NORMAL
368 struct ctk_textmap {
369  struct ctk_widget *next;
370  struct ctk_window *window;
371  unsigned char x, y;
372  unsigned char type;
373  unsigned char w, h;
374 #if CTK_CONF_WIDGET_FLAGS
375  unsigned char flags;
376 #endif /* CTK_CONF_WIDGET_FLAGS */
377  char *textmap;
378  unsigned char state;
379 };
380 #endif /* CTK_CONF_ICONS */
381 
382 /**
383  * \internal The CTK button widget structure.
384  */
385 struct ctk_widget_button {
386  char *text; /**< The button text. */
387 };
389 /**
390  * \internal The CTK label widget structure.
391  */
392 struct ctk_widget_label {
393  char *text; /**< The label text. */
394 };
395 
396 /**
397  * \internal The CTK hyperlink widget structure.
398  */
399 struct ctk_widget_hyperlink {
400  char *text; /**< The text of the hyperlink. */
401  char *url; /**< The hyperlink's URL. */
402 };
403 
404 struct ctk_widget_textentry {
405  char *text;
406  unsigned char len;
407  unsigned char state;
408  unsigned char xpos, ypos;
409  ctk_textentry_input input;
410 };
411 
412 struct ctk_widget_icon {
413  char *title;
414  struct process *owner;
415  unsigned char *bitmap;
416  char *textmap;
417 };
418 
419 struct ctk_widget_bitmap {
420  unsigned char *bitmap;
421  unsigned short bw, bh;
422 };
423 /** @} */
424 
425 /**
426  * \addtogroup ctkdraw
427  * @{
428  */
429 
430 /**
431  * The generic CTK widget structure that contains all other widget
432  * structures.
433  *
434  * Since the widgets of a window are arranged on a linked list, the
435  * widget structure contains a next pointer which is used for this
436  * purpose. The widget structure also contains the placement and the
437  * size of the widget.
438  *
439  * Finally, the actual per-widget structure is contained in this
440  * top-level widget structure.
441  */
442 struct ctk_widget {
443  struct ctk_widget *next; /**< The next widget in the linked list
444  of widgets that is contained in the
445  ctk_window structure. */
446  struct ctk_window *window; /**< The window in which the widget is
447  contained. */
448  unsigned char x, /**< The x position of the widget within
449  the containing window, in character
450  coordinates. */
451  y; /**< The y position of the widget within
452  the containing window, in character
453  coordinates. */
454  unsigned char type; /**< The type of the widget:
455  CTK_WIDGET_SEPARATOR,
456  CTK_WIDGET_LABEL, CTK_WIDGET_BUTTON,
457  CTK_WIDGET_HYPERLINK,
458  CTK_WIDGET_TEXTENTRY,
459  CTK_WIDGET_BITMAP or
460  CTK_WIDGET_ICON. */
461  unsigned char w, /**< The width of the widget in character
462  coordinates. */
463  h; /**< The height of the widget in
464  character coordinates. */
465 #if CTK_CONF_WIDGET_FLAGS
466  unsigned char flags;
467 #endif /* CTK_CONF_WIDGET_FLAGS */
468 
469  union {
470  struct ctk_widget_label label;
471  struct ctk_widget_button button;
472  struct ctk_widget_hyperlink hyperlink;
473  struct ctk_widget_textentry textentry;
474  struct ctk_widget_icon icon;
475  struct ctk_widget_bitmap bitmap;
476  } widget; /**< The union which contains the actual
477  widget structure, as determined by the
478  type field. */
479 };
480 
481 
482 struct ctk_desktop;
483 
484 #define CTK_WIDGET_FLAG_NONE 0
485 #define CTK_WIDGET_FLAG_MONOSPACE 1
486 #define CTK_WIDGET_FLAG_CENTER 2
487 
488 #if CTK_CONF_WIDGET_FLAGS
489 #define CTK_WIDGET_SET_FLAG(w, f) ((struct ctk_widget *)(w))->flags = (f)
490 #else /* CTK_CONF_WIDGET_FLAGS */
491 #define CTK_WIDGET_SET_FLAG(w, f)
492 #endif /* CTK_CONF_WIDGET_FLAGS */
493 
494 /**
495  * Representation of a CTK window.
496  *
497  * For the CTK, each window is repessented by a ctk_window
498  * structure. All open windows are kept on a doubly linked list,
499  * linked by the next and prev fields in the ctk_window struct. The
500  * window structure holds all widgets that is contained in the window
501  * as well as a pointer to the currently selected widget.
502  *
503  */
504 struct ctk_window {
505  struct ctk_window *next, /**< The next window in the doubly linked
506  list of open windows. */
508  *prev; /**< The previous window in the doubly
509  linked list of open windows. */
510  struct ctk_desktop *desktop;/**< The desktop on which this window is
511  open. */
512 
513  struct process *owner; /**< The process that owns the
514  window. This process will be the
515  receiver of all CTK signals that
516  pertain to this window. */
517 
518  char *title; /**< The title of the window. Used for
519  constructing the "Dekstop" menu. */
520  unsigned char titlelen; /**< The length of the title, cached for
521  speed reasons. */
523 #if CTK_CONF_WINDOWCLOSE
524  struct ctk_button closebutton; /**< The closebutton. This is also
525  present in the list of active
526  widgets. */
527 #else /* CTK_CONF_WINDOWCLOSE */
528  struct ctk_label closebutton;
529 #endif /* CTK_CONF_WINDOWCLOSE */
530 
531 #if CTK_CONF_WINDOWMOVE
532  struct ctk_button titlebutton;/**< The titlebutton which is used for
533  moving the window. This is also
534  present in the list of active
535  widgets. */
536 #else /* CTK_CONF_WINDOWMOVE */
537  struct ctk_label titlebutton;
538 #endif /* CTK_CONF_WINDOWMOVE */
539 
540 #if CTK_CONF_WINDOWS
541  unsigned char x, /**< The x coordinate of the window, in
542  characters. */
543  y; /**< The y coordinate of the window, in
544  characters. */
545 #endif /* CTK_CONF_WINDOWS */
546  unsigned char w, /**< The width of the window, excluding
547  window borders. */
548  h; /**< The height of the window,
549  excluding window borders. */
550 
551 
552  struct ctk_widget *inactive; /**< The list if widgets that cannot be
553  selected by the user. Labels and
554  separator widgets are placed on this
555  list. */
556  struct ctk_widget *active; /**< The list of widgets that can be
557  selected by the user. Buttons,
558  hyperlinks, text entry fields, etc.,
559  are placed on this list. */
560  struct ctk_widget *focused; /**< A pointer to the widget on the
561  active list that is currently
562  selected, or NULL if no widget is
563  selected. */
564 };
565 
566 /**
567  * Representation of an individual menu item.
568  */
569 struct ctk_menuitem {
570  char *title; /**< The menu items text. */
571  unsigned char titlelen;/**< The length of the item text, cached for
572  speed. */
573 };
574 
575 #ifdef CTK_CONF_MAXMENUITEMS
576 #define CTK_MAXMENUITEMS CTK_CONF_MAXMENUITEMS
577 #else
578 #define CTK_MAXMENUITEMS 8
579 #endif
580 
581 /**
582  * Representation of an individual menu.
583  */
584 struct ctk_menu {
585  struct ctk_menu *next; /**< Apointer to the next menu, or is NULL if
586  this is the last menu, and should be used
587  by the ctk-draw module when stepping
588  through the menus when drawing them on
589  screen. */
590  char *title; /**< The menu title. */
591  unsigned char titlelen;/**< The length of the title in
592  characters. Cached for speed reasons. */
593 #if CC_UNSIGNED_CHAR_BUGS
594  unsigned int nitems;
595  unsigned int active;
596 #else /* CC_UNSIGNED_CHAR_BUGS */
597  unsigned char nitems; /**< The total number of menu items in the
598  menu. */
599  unsigned char active; /**< The currently active menu item. */
600 #endif /* CC_UNSIGNED_CHAR_BUGS */
601  struct ctk_menuitem items[CTK_MAXMENUITEMS];
602  /**< The array which contains all the menu
603  items. */
604 };
605 
606 /**
607  * Representation of the menu bar.
608  */
609 struct ctk_menus {
610  struct ctk_menu *menus; /**< A pointer to a linked list of all
611  menus, including the open menu and
612  the desktop menu.*/
613  struct ctk_menu *open; /**< The currently open menu, if
614  any. If all menus are closed, this
615  item is NULL: */
616  struct ctk_menu *desktopmenu; /**< A pointer to the "Desktop" menu
617  that can be used for drawing the
618  desktop menu in a special way (such
619  as drawing it at the rightmost
620  position). */
621 };
622 
623 /** @} */
624 
625 
626 /**
627  * \internal The structure describing a Contiki desktop.
628  */
629 struct ctk_desktop {
630  char *name; /**< The name of the desktop. */
631 
632  struct ctk_window desktop_window; /**< The background window which
633  contains tha desktop icons. */
634  struct ctk_window *windows; /**< The list of open windows. */
635  struct ctk_window *dialog; /**< A pointer to the open dialog, or
636  NULL if no dialog is open. */
637 
638 #if CTK_CONF_MENUS
639  struct ctk_menus menus; /**< The list of desktop menus. */
640  struct ctk_menu *lastmenu; /**< Pointer to the menu that was last open. */
641  struct ctk_menu desktopmenu;/**< The desktop menu. */
642 #endif /* CTK_CONF_MENUS */
643 
644  unsigned char height, /**< The height of the desktop, in characters. */
645  width; /**< The width of the desktop, in characters. */
646 
647 
648 #define CTK_REDRAW_NONE 0 /**< \internal Redraw flag: nothing
649  to be redrawn. */
650 #define CTK_REDRAW_ALL 1 /**< \internal Redraw flag:
651  everything should be redrawn. */
652 #define CTK_REDRAW_WINDOWS 2 /**< \internal Redraw flag: redraw
653  windows in queue.*/
654 #define CTK_REDRAW_WIDGETS 4 /**< \internal Redraw flag: redraw
655  widgets in queue. */
656 #define CTK_REDRAW_MENUS 8 /**< \internal Redraw flag: redraw
657  menus. */
658 #define CTK_REDRAW_PART 16 /**< \internal Redraw flag: redraw
659  parts of the desktop. */
660 
661 #ifndef CTK_CONF_MAX_REDRAWWIDGETS
662 #define CTK_CONF_MAX_REDRAWWIDGETS 8
663 #endif /* CTK_CONF_MAX_REDRAWWIDGETS */
664 #ifndef CTK_CONF_MAX_REDRAWWINDOWS
665 #define CTK_CONF_MAX_REDRAWWINDOWS 8
666 #endif /* CTK_CONF_MAX_REDRAWWINDOWS */
667 
668  unsigned char redraw; /**< The redraw flag. */
669 
670  struct ctk_widget *redraw_widgets[CTK_CONF_MAX_REDRAWWIDGETS]; /**< The list of widgets to be redrawn. */
671  unsigned char redraw_widgetptr; /**< Pointer to the last widget on the redraw_widgets list. */
672 
673  struct ctk_window *redraw_windows[CTK_CONF_MAX_REDRAWWINDOWS]; /**< The list of windows to be redrawn. */
674  unsigned char redraw_windowptr; /**< Pointer to the last window on the redraw_windows list. */
675 
676  unsigned char redraw_y1, /**< The lower y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
677  redraw_y2; /**< The upper y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
678 };
679 
680 
681 /* Global CTK modes. */
682 #define CTK_MODE_NORMAL 0
683 #define CTK_MODE_WINDOWMOVE 1
684 #define CTK_MODE_SCREENSAVER 2
685 #define CTK_MODE_EXTERNAL 3
686 
687 /* General ctk functions. */
688 PROCESS_NAME(ctk_process);
689 void ctk_init(void);
690 void ctk_restore(void);
691 
692 void ctk_mode_set(unsigned char mode);
693 unsigned char ctk_mode_get(void);
694 /*void ctk_redraw(void);*/
695 
696 /* Functions for manipulating windows. */
697 CCIF void ctk_window_new(struct ctk_window *window,
698  unsigned char w, unsigned char h,
699  char *title);
700 CCIF void ctk_window_clear(struct ctk_window *w);
701 CCIF void ctk_window_open(struct ctk_window *w);
702 #define ctk_window_move(w,xpos,ypos) do { (w)->x=xpos; (w)->y=ypos; } while(0)
703 CCIF void ctk_window_close(struct ctk_window *w);
704 CCIF void ctk_window_redraw(struct ctk_window *w);
705 #define ctk_window_isopen(w) ((w)->next != NULL)
706 
707 
708 /* Functions for manipulating dialogs. */
709 CCIF void ctk_dialog_new(struct ctk_window *window,
710  unsigned char w, unsigned char h);
711 CCIF void ctk_dialog_open(struct ctk_window *d);
712 CCIF void ctk_dialog_close(void);
713 
714 /* Functions for manipulating menus. */
715 CCIF void ctk_menu_new(struct ctk_menu *menu, char *title);
716 CCIF void ctk_menu_add(struct ctk_menu *menu);
717 CCIF void ctk_menu_remove(struct ctk_menu *menu);
718 CCIF unsigned char ctk_menuitem_add(struct ctk_menu *menu, char *name);
719 
720 /* Functions for icons. */
721 
722 /**
723  * \addtogroup ctkappfunc
724  * @{
725  */
726 /**
727  * Add an icon to the desktop.
728  *
729  * \param icon The icon to be added.
730  *
731  * \param p The process ID of the process that owns the icon.
732  */
733 #define CTK_ICON_ADD(icon, p) ctk_icon_add((struct ctk_widget *)icon, p)
734 void ctk_icon_add(struct ctk_widget *icon, struct process *p);
735 
736 /* Functions for manipulating widgets. */
737 
738 /**
739  * Add a widget to a window.
740  *
741  * \param win The window to which the widget should be added.
742  * \param widg The widget to be added.
743  */
744 #define CTK_WIDGET_ADD(win, widg) \
745  ctk_widget_add(win, (struct ctk_widget *)widg)
746 CCIF void CC_FASTCALL ctk_widget_add(struct ctk_window *window,
747  struct ctk_widget *widget);
748 
749 /**
750  * Set focus to a widget.
751  *
752  * \param win The widget's window.
753  * \param widg The widget
754  */
755 #define CTK_WIDGET_FOCUS(win, widg) \
756  (win)->focused = (struct ctk_widget *)(widg)
757 
758 /**
759  * Add a widget to the redraw queue.
760  *
761  * \param widg The widget to be redrawn.
762  */
763 #define CTK_WIDGET_REDRAW(widg) \
764  ctk_widget_redraw((struct ctk_widget *)widg)
765 CCIF void ctk_widget_redraw(struct ctk_widget *w);
766 
767 /**
768  * Obtain the type of a widget.
769  *
770  * \param w The widget.
771  */
772 #define CTK_WIDGET_TYPE(w) ((w)->type)
773 
774 
775 /**
776  * Sets the width of a widget.
777  *
778  * \param widget The widget.
779  * \param width The width of the widget, in characters.
780  */
781 #define CTK_WIDGET_SET_WIDTH(widget, width) do { \
782  ((struct ctk_widget *)(widget))->w = (width); } while(0)
783 
784 /**
785  * Retrieves the x position of a widget, relative to the window in
786  * which the widget is contained.
787  *
788  * \param w The widget.
789  * \return The x position of the widget.
790  */
791 #define CTK_WIDGET_XPOS(w) (((struct ctk_widget *)(w))->x)
792 
793 /**
794  * Sets the x position of a widget, relative to the window in
795  * which the widget is contained.
796  *
797  * \param w The widget.
798  * \param xpos The x position of the widget.
799  */
800 #define CTK_WIDGET_SET_XPOS(w, xpos) \
801  ((struct ctk_widget *)(w))->x = (xpos)
802 /**
803  * Retrieves the y position of a widget, relative to the window in
804  * which the widget is contained.
805  *
806  * \param w The widget.
807  * \return The y position of the widget.
808  */
809 #define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
810 
811 /**
812  * Sets the y position of a widget, relative to the window in
813  * which the widget is contained.
814  *
815  * \param w The widget.
816  * \param ypos The y position of the widget.
817  */
818 #define CTK_WIDGET_SET_YPOS(w, ypos) \
819  ((struct ctk_widget *)(w))->y = (ypos)
820 
821 /* XXX: should be removed.
822 #define ctk_textentry_set_height(w, height) \
823  (w)->widget.textentry.h = (height)
824 */
825 
826 /** \def ctk_label_set_height(w, height)
827  * \brief Set the height of a label.
828  *
829  * \param w The CTK label widget.
830  * \param height The new height of the label.
831  */
832 #define ctk_label_set_height(w, height) \
833  (w)->widget.label.h = (height)
834 
835 /**
836  * Set the text of a label.
837  *
838  * \param l The CTK label widget.
839  * \param t The new text of the label.
840  */
841 #define ctk_label_set_text(l, t) (l)->text = (t)
842 
843 /**
844  * Set the text of a button.
845  *
846  * \param b The CTK button widget.
847  * \param t The new text of the button.
848  */
849 #define ctk_button_set_text(b, t) (b)->text = (t)
850 
851 #define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m)
852 
853 #define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
854  do { (widg)->window = NULL; \
855  (widg)->next = NULL; \
856  (widg)->type = CTK_WIDGET_BUTTON; \
857  (widg)->x = (xpos); \
858  (widg)->y = (ypos); \
859  (widg)->w = (width); \
860  (widg)->h = 1; \
861  (widg)->text = (buttontext); \
862  } while(0)
863 
864 #define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
865  do { (widg)->window = NULL; \
866  (widg)->next = NULL; \
867  (widg)->type = CTK_WIDGET_LABEL; \
868  (widg)->x = (xpos); \
869  (widg)->y = (ypos); \
870  (widg)->w = (width); \
871  (widg)->h = (height); \
872  (widg)->text = (labeltext); \
873  } while(0)
874 
875 #define CTK_BITMAP_NEW(widg, xpos, ypos, width, height, bmap) \
876  do { (widg)->window = NULL; \
877  (widg)->next = NULL; \
878  (widg)->type = CTK_WIDGET_BITMAP; \
879  (widg)->x = (xpos); \
880  (widg)->y = (ypos); \
881  (widg)->w = (width); \
882  (widg)->h = (height); \
883  (widg)->bitmap = (bmap); \
884  } while(0)
885 
886 #define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
887  do { (widg)->window = NULL; \
888  (widg)->next = NULL; \
889  (widg)->type = CTK_WIDGET_TEXTENTRY; \
890  (widg)->x = (xxpos); \
891  (widg)->y = (yypos); \
892  (widg)->w = (width); \
893  (widg)->h = 1; \
894  (widg)->text = (textptr); \
895  (widg)->len = (textlen); \
896  (widg)->state = CTK_TEXTENTRY_NORMAL; \
897  (widg)->xpos = 0; \
898  (widg)->ypos = 0; \
899  (widg)->input = NULL; \
900  } while(0)
901 
902 #define CTK_TEXTENTRY_INPUT_NEW(widg, xxpos, yypos, width, height, textptr, textlen, iinput) \
903  do { (widg)->window = NULL; \
904  (widg)->next = NULL; \
905  (widg)->type = CTK_WIDGET_TEXTENTRY; \
906  (widg)->x = (xxpos); \
907  (widg)->y = (yypos); \
908  (widg)->w = (width); \
909  (widg)->h = (height); \
910  (widg)->text = (textptr); \
911  (widg)->len = (textlen); \
912  (widg)->state = CTK_TEXTENTRY_NORMAL; \
913  (widg)->xpos = 0; \
914  (widg)->ypos = 0; \
915  (widg)->input = (ctk_textentry_input)(iinput); \
916  } while(0)
917 
918 #define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
919  do { (widg)->window = NULL; \
920  (widg)->next = NULL; \
921  (widg)->type = CTK_WIDGET_HYPERLINK; \
922  (widg)->x = (xpos); \
923  (widg)->y = (ypos); \
924  (widg)->w = (width); \
925  (widg)->h = 1; \
926  (widg)->text = (linktext); \
927  (widg)->url = (linkurl); \
928  } while(0)
929 
930 /* Desktop interface. */
931 void ctk_desktop_redraw(struct ctk_desktop *d);
932 CCIF unsigned char ctk_desktop_width(struct ctk_desktop *d);
933 unsigned char ctk_desktop_height(struct ctk_desktop *d);
934 
935 /* Signals. */
936 CCIF extern process_event_t ctk_signal_keypress,
939  ctk_signal_timer,
942  ctk_signal_pointer_move,
943  ctk_signal_pointer_button;
944 
945 #if CTK_CONF_SCREENSAVER
946 extern process_event_t ctk_signal_screensaver_stop,
947  ctk_signal_screensaver_start;
948 
949 extern unsigned short ctk_screensaver_timeout;
950 /**
951  * Set the screensaver timeout, in seconds.
952  *
953  * \param t The timeout in seconds.
954  */
955 #define CTK_SCREENSAVER_SET_TIMEOUT(t) ctk_screensaver_timeout = (t)
956 /**
957  * Obtain the screensaver timeout, in seconds.
958  *
959  * \raturn The timeout in seconds.
960  */
961 #define CTK_SCREENSAVER_TIMEOUT() ctk_screensaver_timeout
962 #endif /* CTK_CONF_SCREENSAVER */
963 
964 /* These should no longer be used: */
965 CCIF extern process_event_t ctk_signal_button_activate,
969 /** @} */
970 
971 /**
972  * \addtogroup ctkdraw
973  * @{
974  */
975 
976 /* Focus flags */
977 /** Widget focus flag: no focus. */
978 #define CTK_FOCUS_NONE 0
979 /** Widget focus flag: widget has focus. */
980 #define CTK_FOCUS_WIDGET 1
981 /** Widget focus flag: widget's window is the foremost one. */
982 #define CTK_FOCUS_WINDOW 2
983 /** Widget focus flag: widget is in a dialog. */
984 #define CTK_FOCUS_DIALOG 4
985 
986 /** @} */
987 /** @} */
988 /** @} */
989 #endif /* CTK_H_ */