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