Contiki 2.6

ctk.h

Go to the documentation of this file.
00001 /**
00002  * \addtogroup ctk
00003  * @{
00004  */
00005 
00006 /**
00007  * \file
00008  * CTK header file.
00009  * \author Adam Dunkels <adam@dunkels.com>
00010  *
00011  * The CTK header file contains functioin declarations and definitions
00012  * of CTK structures and macros.
00013  */
00014 
00015 /*
00016  * Copyright (c) 2002-2003, Adam Dunkels.
00017  * All rights reserved.
00018  *
00019  * Redistribution and use in source and binary forms, with or without
00020  * modification, are permitted provided that the following conditions
00021  * are met:
00022  * 1. Redistributions of source code must retain the above copyright
00023  *    notice, this list of conditions and the following disclaimer.
00024  * 2. Redistributions in binary form must reproduce the above
00025  *    copyright notice, this list of conditions and the following
00026  *    disclaimer in the documentation and/or other materials provided
00027  *    with the distribution.
00028  * 3. The name of the author may not be used to endorse or promote
00029  *    products derived from this software without specific prior
00030  *    written permission.
00031  *
00032  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00033  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00034  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00035  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00036  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00037  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00038  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00039  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00040  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00041  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00042  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00043  *
00044  * This file is part of the Contiki desktop OS.
00045  *
00046  * $Id: ctk.h,v 1.9 2009/02/28 10:43:30 oliverschmidt Exp $
00047  *
00048  */
00049 
00050 #ifndef __CTK_H__
00051 #define __CTK_H__
00052 
00053 
00054 #include "contiki-conf.h"
00055 #include "contiki.h"
00056 
00057 /* Defintions for the CTK widget types. */
00058 
00059 /**
00060  * \addtogroup ctkdraw
00061  * @{
00062  */
00063 
00064 /** Widget number: The CTK separator widget. */
00065 #define CTK_WIDGET_SEPARATOR 1
00066 /** Widget number: The CTK label widget. */
00067 #define CTK_WIDGET_LABEL     2
00068 /** Widget number: The CTK button widget. */
00069 #define CTK_WIDGET_BUTTON    3
00070 /** Widget number: The CTK hyperlink widget. */
00071 #define CTK_WIDGET_HYPERLINK 4
00072 /** Widget number: The CTK textentry widget. */
00073 #define CTK_WIDGET_TEXTENTRY 5
00074 /** Widget number: The CTK bitmap widget. */
00075 #define CTK_WIDGET_BITMAP    6
00076 /** Widget number: The CTK icon widget. */
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  * \defgroup ctkappfunc CTK application functions
00091  *
00092  * The CTK functions used by an application program.
00093  *
00094  * @{
00095  */
00096 
00097 /**
00098  * Instantiating macro for the ctk_separator widget.
00099  *
00100  * This macro is used when instantiating a ctk_separator widget and is
00101  * intended to be used together with a struct assignment like this:
00102  \code
00103   struct ctk_separator sep =
00104          {CTK_SEPARATOR(0, 0, 23)};
00105  \endcode
00106  * \param x The x position of the widget, relative to the widget's
00107  * window.
00108  * \param y The y position of the widget, relative to the widget's
00109  * window.
00110  * \param w The widget's width.
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 /* CTK_CONF_WIDGET_FLAGS */
00123 };
00124 
00125 /**
00126  * Instantiating macro for the ctk_button widget.
00127  *
00128  * This macro is used when instantiating a ctk_button widget and is
00129  * intended to be used together with a struct assignment like this:
00130  \code
00131   struct ctk_button but =
00132          {CTK_BUTTON(0, 0, 2, "Ok")};
00133  \endcode
00134  * \param x The x position of the widget, relative to the widget's
00135  * window.
00136  * \param y The y position of the widget, relative to the widget's
00137  * window.
00138  * \param w The widget's width.
00139  * \param text The button text.
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 /* CTK_CONF_WIDGET_FLAGS */
00152   char *text;
00153 };
00154 
00155 /**
00156  * Instantiating macro for the ctk_label widget.
00157  *
00158  * This macro is used when instantiating a ctk_label widget and is
00159  * intended to be used together with a struct assignment like this:
00160  \code
00161   struct ctk_label lab =
00162          {CTK_LABEL(0, 0, 5, 1, "Label")};
00163  \endcode
00164  * \param x The x position of the widget, relative to the widget's
00165  * window.
00166  * \param y The y position of the widget, relative to the widget's
00167  * window.
00168  * \param w The widget's width.
00169  * \param h The height of the label.
00170  * \param text The label text.
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 /* CTK_CONF_WIDGET_FLAGS */
00183   char *text;
00184 };
00185 
00186 /**
00187  * Instantiating macro for the ctk_hyperlink widget.
00188  *
00189  * This macro is used when instantiating a ctk_hyperlink widget and is
00190  * intended to be used together with a struct assignment like this:
00191  \code
00192   struct ctk_hyperlink hlink =
00193          {CTK_HYPERLINK(0, 0, 7, "Contiki", "http://dunkels.com/adam/contiki/")};
00194  \endcode
00195  * \param x The x position of the widget, relative to the widget's
00196  * window.
00197  * \param y The y position of the widget, relative to the widget's
00198  * window.
00199  * \param w The widget's width.
00200  * \param text The hyperlink text.
00201  * \param url The hyperlink URL.
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 /* CTK_CONF_WIDGET_FLAGS */
00214   char *text;
00215   char *url;
00216 };
00217 
00218 /* Editing modes of the CTK textentry widget. */
00219 #define CTK_TEXTENTRY_NORMAL 0 /**< \internal Textentry state: not
00220                                   edited. */
00221 #define CTK_TEXTENTRY_EDIT   1 /**< \internal Textentry state:
00222                                   currenly being edited. */
00223 
00224 /**
00225  * Clears a text entry widget and sets the cursor to the start of the
00226  * text line.
00227  *
00228  * \param e The text entry widget to be cleared.
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 /* CTK_ARCH_KEY_T */
00237 typedef char ctk_arch_key_t;
00238 #endif /* CTK_ARCH_KEY_T */
00239 
00240 #ifndef CH_ENTER
00241 #define CH_ENTER '\n'
00242 #endif /* CH_ENTER */
00243 
00244 struct ctk_textentry;
00245 typedef unsigned char (* ctk_textentry_input)(ctk_arch_key_t c,
00246                                               struct ctk_textentry *t);
00247 
00248 /**
00249  * Instantiating macro for the ctk_textentry widget.
00250  *
00251  * This macro is used when instantiating a ctk_textentry widget and is
00252  * intended to be used together with a struct assignment like this:
00253  \code
00254   struct ctk_textentry tentry =
00255          {CTK_TEXTENTRY(0, 0, 30, 1, textbuffer, 50)};
00256  \endcode
00257  * \note The height of the text entry widget is obsolete and not
00258  * intended to be used.
00259  *
00260  * \param x The x position of the widget, relative to the widget's
00261  * window.
00262  * \param y The y position of the widget, relative to the widget's
00263  * window.
00264  * \param w The widget's width.
00265  * \param h The text entry height (obsolete).
00266  * \param text A pointer to the buffer that should be edited.
00267  * \param len The length of the text buffer
00268  */
00269 #ifdef SDCC
00270 #define CTK_TEXTENTRY(x, y, w, h, text, len) \
00271   NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
00272   CTK_TEXTENTRY_NORMAL, 0, 0, ctk_textentry_input_null
00273 #else /* SDCC */
00274 #define CTK_TEXTENTRY(x, y, w, h, text, len) \
00275   NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
00276   CTK_TEXTENTRY_NORMAL, 0, 0, NULL
00277 #endif /* SDCC */
00278 #define CTK_TEXTENTRY_INPUT(x, y, w, h, text, len, input) \
00279   NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
00280   CTK_TEXTENTRY_NORMAL, 0, 0, input
00281 struct ctk_textentry {
00282   struct ctk_widget *next;
00283   struct ctk_window *window;
00284   unsigned char x, y;
00285   unsigned char type;
00286   unsigned char w, h;
00287 #if CTK_CONF_WIDGET_FLAGS
00288   unsigned char flags;
00289 #endif /* CTK_CONF_WIDGET_FLAGS */
00290   char *text;
00291   unsigned char len;
00292   unsigned char state;
00293   unsigned char xpos, ypos;
00294   ctk_textentry_input input;
00295 };
00296 
00297 #ifdef SDCC
00298 /* Dummy function that we define to keep sdcc happy - with sdcc,
00299    function pointers cannot be NULL.*/
00300 unsigned char ctk_textentry_input_null(ctk_arch_key_t c, struct ctk_textentry *t);
00301 #endif /* SDCC */
00302 
00303 #if CTK_CONF_ICON_BITMAPS
00304 #define CTK_ICON_BITMAP(bitmap)   bitmap
00305 #else
00306 #define CTK_ICON_BITMAP(bitmap)   NULL
00307 #endif
00308 
00309 #if CTK_CONF_ICON_TEXTMAPS
00310 #define CTK_ICON_TEXTMAP(textmap) textmap
00311 #else
00312 #define CTK_ICON_TEXTMAP(textmap) NULL
00313 #endif
00314 
00315 /**
00316  * Instantiating macro for the ctk_icon widget.
00317  *
00318  * This macro is used when instantiating a ctk_icon widget and is
00319  * intended to be used together with a struct assignment like this:
00320  \code
00321   struct ctk_icon icon =
00322          {CTK_ICON("An icon", bitmapptr, textmapptr)};
00323  \endcode
00324  * \param title The icon's text.
00325  * \param bitmap A pointer to the icon's bitmap image.
00326  * \param textmap A pointer to the icon's text version of the bitmap.
00327  */
00328 #if CTK_CONF_ICONS
00329 #define CTK_ICON(title, bitmap, textmap) \
00330  NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, 4, CTK_WIDGET_FLAG_INITIALIZER(0) \
00331  title, PROCESS_NONE, \
00332  CTK_ICON_BITMAP(bitmap), CTK_ICON_TEXTMAP(textmap)
00333 struct ctk_icon {
00334   struct ctk_widget *next;
00335   struct ctk_window *window;
00336   unsigned char x, y;
00337   unsigned char type;
00338   unsigned char w, h;
00339 #if CTK_CONF_WIDGET_FLAGS
00340   unsigned char flags;
00341 #endif /* CTK_CONF_WIDGET_FLAGS */
00342   char *title;
00343   struct process *owner;
00344   unsigned char *bitmap;
00345   char *textmap;
00346 };
00347 
00348 #define CTK_BITMAP(x, y, w, h, bitmap, bitmap_width, bitmap_height) \
00349   NULL, NULL, x, y, CTK_WIDGET_BITMAP, w, h, \
00350   CTK_WIDGET_FLAG_INITIALIZER(0) bitmap, bitmap_width, bitmap_height
00351 struct ctk_bitmap {
00352   struct ctk_widget *next;
00353   struct ctk_window *window;
00354   unsigned char x, y;
00355   unsigned char type;
00356   unsigned char w, h;
00357 #if CTK_CONF_WIDGET_FLAGS
00358   unsigned char flags;
00359 #endif /* CTK_CONF_WIDGET_FLAGS */
00360   unsigned char *bitmap;
00361   unsigned short bw, bh;
00362 };
00363 
00364 #define CTK_TEXTMAP_NORMAL 0
00365 #define CTK_TEXTMAP_ACTIVE 1
00366 
00367 #define CTK_TEXTMAP(x, y, w, h, textmap) \
00368  NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, CTK_TEXTMAP_NORMAL
00369 struct ctk_textmap {
00370   struct ctk_widget *next;
00371   struct ctk_window *window;
00372   unsigned char x, y;
00373   unsigned char type;
00374   unsigned char w, h;
00375 #if CTK_CONF_WIDGET_FLAGS
00376   unsigned char flags;
00377 #endif /* CTK_CONF_WIDGET_FLAGS */
00378   char *textmap;
00379   unsigned char state;
00380 };
00381 #endif /* CTK_CONF_ICONS */
00382 
00383 /**
00384  * \internal The CTK button widget structure.
00385  */
00386 struct ctk_widget_button {
00387   char *text;  /**< The button text. */
00388 };
00389 
00390 /**
00391  * \internal The CTK label widget structure.
00392  */
00393 struct ctk_widget_label {
00394   char *text; /**< The label text. */
00395 };
00396 
00397 /**
00398  * \internal The CTK hyperlink widget structure.
00399  */
00400 struct ctk_widget_hyperlink {
00401   char *text; /**< The text of the hyperlink. */
00402   char *url;  /**< The hyperlink's URL. */
00403 };
00404 
00405 struct ctk_widget_textentry {
00406   char *text;
00407   unsigned char len;
00408   unsigned char state;
00409   unsigned char xpos, ypos;
00410   ctk_textentry_input input;
00411 };
00412 
00413 struct ctk_widget_icon {
00414   char *title;
00415   struct process *owner;
00416   unsigned char *bitmap;
00417   char *textmap;
00418 };
00419 
00420 struct ctk_widget_bitmap {
00421   unsigned char *bitmap;
00422   unsigned short bw, bh;
00423 };
00424 /** @} */
00425 
00426 /**
00427  * \addtogroup ctkdraw
00428  * @{
00429  */
00430 
00431 /**
00432  * The generic CTK widget structure that contains all other widget
00433  * structures.
00434  *
00435  * Since the widgets of a window are arranged on a linked list, the
00436  * widget structure contains a next pointer which is used for this
00437  * purpose. The widget structure also contains the placement and the
00438  * size of the widget.
00439  *
00440  * Finally, the actual per-widget structure is contained in this
00441  * top-level widget structure.
00442  */
00443 struct ctk_widget {
00444   struct ctk_widget *next;   /**< The next widget in the linked list
00445                                 of widgets that is contained in the
00446                                 ctk_window structure. */
00447   struct ctk_window *window; /**< The window in which the widget is
00448                                 contained. */
00449   unsigned char x,           /**< The x position of the widget within
00450                                 the containing window, in character
00451                                 coordinates. */
00452     y;                       /**< The y position of the widget within
00453                                 the containing window, in character
00454                                 coordinates. */
00455   unsigned char type;        /**< The type of the widget:
00456                                 CTK_WIDGET_SEPARATOR,
00457                                 CTK_WIDGET_LABEL, CTK_WIDGET_BUTTON,
00458                                 CTK_WIDGET_HYPERLINK,
00459                                 CTK_WIDGET_TEXTENTRY,
00460                                 CTK_WIDGET_BITMAP or
00461                                 CTK_WIDGET_ICON. */
00462   unsigned char w,           /**< The width of the widget in character
00463                                 coordinates. */
00464     h;                       /**< The height of the widget in
00465                                 character coordinates. */
00466 #if CTK_CONF_WIDGET_FLAGS
00467   unsigned char flags;
00468 #endif /* CTK_CONF_WIDGET_FLAGS */
00469   
00470   union {
00471     struct ctk_widget_label label;
00472     struct ctk_widget_button button;
00473     struct ctk_widget_hyperlink hyperlink;
00474     struct ctk_widget_textentry textentry;
00475     struct ctk_widget_icon icon;
00476     struct ctk_widget_bitmap bitmap;
00477   } widget;                  /**< The union which contains the actual
00478                                 widget structure, as determined by the
00479                                 type field. */
00480 };
00481 
00482 
00483 struct ctk_desktop;
00484 
00485 #define CTK_WIDGET_FLAG_NONE      0
00486 #define CTK_WIDGET_FLAG_MONOSPACE 1
00487 #define CTK_WIDGET_FLAG_CENTER    2
00488 
00489 #if CTK_CONF_WIDGET_FLAGS
00490 #define CTK_WIDGET_SET_FLAG(w, f) ((struct ctk_widget *)(w))->flags = (f)
00491 #else /* CTK_CONF_WIDGET_FLAGS */
00492 #define CTK_WIDGET_SET_FLAG(w, f)
00493 #endif /* CTK_CONF_WIDGET_FLAGS */
00494 
00495 /**
00496  * Representation of a CTK window.
00497  *
00498  * For the CTK, each window is repessented by a ctk_window
00499  * structure. All open windows are kept on a doubly linked list,
00500  * linked by the next and prev fields in the ctk_window struct. The
00501  * window structure holds all widgets that is contained in the window
00502  * as well as a pointer to the currently selected widget.
00503  *
00504  */
00505 struct ctk_window {
00506   struct ctk_window *next,  /**< The next window in the doubly linked
00507                                list of open windows. */
00508 
00509     *prev;                  /**< The previous window in the doubly
00510                                linked list of open windows. */
00511   struct ctk_desktop *desktop;/**< The desktop on which this window is
00512                                  open. */
00513   
00514   struct process *owner;            /**< The process that owns the
00515                                window. This process will be the
00516                                receiver of all CTK signals that
00517                                pertain to this window. */
00518   
00519   char *title;              /**< The title of the window. Used for
00520                                constructing the "Dekstop" menu. */
00521   unsigned char titlelen;   /**< The length of the title, cached for
00522                                speed reasons. */
00523 
00524 #if CTK_CONF_WINDOWCLOSE
00525   struct ctk_button closebutton; /**< The closebutton. This is also
00526                                     present in the list of active
00527                                     widgets. */
00528 #else /* CTK_CONF_WINDOWCLOSE */
00529   struct ctk_label closebutton;
00530 #endif /* CTK_CONF_WINDOWCLOSE */
00531   
00532 #if CTK_CONF_WINDOWMOVE
00533   struct ctk_button titlebutton;/**< The titlebutton which is used for
00534                                      moving the window. This is also
00535                                      present in the list of active
00536                                      widgets. */
00537 #else /* CTK_CONF_WINDOWMOVE */
00538   struct ctk_label titlebutton;
00539 #endif /* CTK_CONF_WINDOWMOVE */
00540 
00541 #if CTK_CONF_WINDOWS
00542   unsigned char x,             /**< The x coordinate of the window, in
00543                                   characters. */
00544     y;                         /**< The y coordinate of the window, in
00545                                   characters. */
00546 #endif /* CTK_CONF_WINDOWS */
00547   unsigned char w,             /**< The width of the window, excluding
00548                                   window borders. */
00549     h;                         /**< The height of the window,
00550                                   excluding window borders. */
00551 
00552 
00553   struct ctk_widget *inactive; /**< The list if widgets that cannot be
00554                                   selected by the user. Labels and
00555                                   separator widgets are placed on this
00556                                   list. */
00557   struct ctk_widget *active;   /**< The list of widgets that can be
00558                                   selected by the user. Buttons,
00559                                   hyperlinks, text entry fields, etc.,
00560                                   are placed on this list. */
00561   struct ctk_widget *focused;  /**< A pointer to the widget on the
00562                                   active list that is currently
00563                                   selected, or NULL if no widget is
00564                                   selected. */
00565 };
00566 
00567 /**
00568  * Representation of an individual menu item.
00569  */
00570 struct ctk_menuitem {
00571   char *title;           /**< The menu items text. */
00572   unsigned char titlelen;/**< The length of the item text, cached for
00573                             speed. */
00574 };
00575 
00576 #ifdef CTK_CONF_MAXMENUITEMS
00577 #define CTK_MAXMENUITEMS CTK_CONF_MAXMENUITEMS
00578 #else
00579 #define CTK_MAXMENUITEMS 8
00580 #endif
00581 
00582 /**
00583  * Representation of an individual menu.
00584  */
00585 struct ctk_menu {
00586   struct ctk_menu *next; /**< Apointer to the next menu, or is NULL if
00587                             this is the last menu, and should be used
00588                             by the ctk-draw module when stepping
00589                             through the menus when drawing them on
00590                             screen. */
00591   char *title;           /**< The menu title. */
00592   unsigned char titlelen;/**< The length of the title in
00593                             characters. Cached for speed reasons. */
00594 #if CC_UNSIGNED_CHAR_BUGS
00595   unsigned int nitems;
00596   unsigned int active;
00597 #else /* CC_UNSIGNED_CHAR_BUGS */
00598   unsigned char nitems;  /**< The total number of menu items in the
00599                             menu. */
00600   unsigned char active;  /**< The currently active menu item. */
00601 #endif /* CC_UNSIGNED_CHAR_BUGS */
00602   struct ctk_menuitem items[CTK_MAXMENUITEMS];
00603                          /**< The array which contains all the menu
00604                             items. */
00605 };
00606 
00607 /**
00608  * Representation of the menu bar.
00609  */
00610 struct ctk_menus {
00611   struct ctk_menu *menus;       /**< A pointer to a linked list of all
00612                                    menus, including the open menu and
00613                                    the desktop menu.*/
00614   struct ctk_menu *open;        /**< The currently open menu, if
00615                                    any. If all menus are closed, this
00616                                    item is NULL: */
00617   struct ctk_menu *desktopmenu; /**< A pointer to the "Desktop" menu
00618                                    that can be used for drawing the
00619                                    desktop menu in a special way (such
00620                                    as drawing it at the rightmost
00621                                    position). */
00622 };
00623 
00624 /** @} */
00625 
00626 
00627 /**
00628  * \internal The structure describing a Contiki desktop.
00629  */
00630 struct ctk_desktop {
00631   char *name; /**< The name of the desktop. */
00632    
00633   struct ctk_window desktop_window; /**< The background window which
00634                                        contains tha desktop icons. */
00635   struct ctk_window *windows; /**< The list of open windows. */
00636   struct ctk_window *dialog;  /**< A pointer to the open dialog, or
00637                                  NULL if no dialog is open. */
00638   
00639 #if CTK_CONF_MENUS
00640   struct ctk_menus menus;     /**< The list of desktop menus. */
00641   struct ctk_menu *lastmenu;  /**< Pointer to the menu that was last open. */
00642   struct ctk_menu desktopmenu;/**< The desktop menu. */
00643 #endif /* CTK_CONF_MENUS */
00644 
00645   unsigned char height, /**< The height of the desktop, in characters. */
00646     width; /**< The width of the desktop, in characters. */
00647 
00648   
00649 #define CTK_REDRAW_NONE         0 /**< \internal Redraw flag: nothing
00650                                      to be redrawn. */
00651 #define CTK_REDRAW_ALL          1 /**< \internal Redraw flag:
00652                                      everything should be redrawn. */
00653 #define CTK_REDRAW_WINDOWS      2 /**< \internal Redraw flag: redraw
00654                                      windows in queue.*/
00655 #define CTK_REDRAW_WIDGETS      4 /**< \internal Redraw flag: redraw
00656                                      widgets in queue. */
00657 #define CTK_REDRAW_MENUS        8 /**< \internal Redraw flag: redraw
00658                                      menus. */
00659 #define CTK_REDRAW_PART        16 /**< \internal Redraw flag: redraw
00660                                      parts of the desktop. */
00661 
00662 #ifndef CTK_CONF_MAX_REDRAWWIDGETS
00663 #define CTK_CONF_MAX_REDRAWWIDGETS 8
00664 #endif /* CTK_CONF_MAX_REDRAWWIDGETS */
00665 #ifndef CTK_CONF_MAX_REDRAWWINDOWS
00666 #define CTK_CONF_MAX_REDRAWWINDOWS 8
00667 #endif /* CTK_CONF_MAX_REDRAWWINDOWS */
00668   
00669   unsigned char redraw; /**< The redraw flag. */
00670   
00671   struct ctk_widget *redraw_widgets[CTK_CONF_MAX_REDRAWWIDGETS]; /**< The list of widgets to be redrawn. */
00672   unsigned char redraw_widgetptr; /**< Pointer to the last widget on the redraw_widgets list. */
00673 
00674   struct ctk_window *redraw_windows[CTK_CONF_MAX_REDRAWWINDOWS]; /**< The list of windows to be redrawn. */
00675   unsigned char redraw_windowptr; /**< Pointer to the last window on the redraw_windows list. */
00676 
00677    unsigned char redraw_y1, /**< The lower y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
00678     redraw_y2; /**< The upper y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
00679 };
00680 
00681 
00682 /* Global CTK modes. */
00683 #define CTK_MODE_NORMAL      0
00684 #define CTK_MODE_WINDOWMOVE  1
00685 #define CTK_MODE_SCREENSAVER 2
00686 #define CTK_MODE_EXTERNAL    3
00687 
00688 /* General ctk functions. */
00689 PROCESS_NAME(ctk_process);
00690 void ctk_init(void);
00691 void ctk_restore(void);
00692 
00693 void ctk_mode_set(unsigned char mode);
00694 unsigned char ctk_mode_get(void);
00695 /*void ctk_redraw(void);*/
00696 
00697 /* Functions for manipulating windows. */
00698 CCIF void ctk_window_new(struct ctk_window *window,
00699                          unsigned char w, unsigned char h,
00700                          char *title);
00701 CCIF void ctk_window_clear(struct ctk_window *w);
00702 CCIF void ctk_window_open(struct ctk_window *w);
00703 #define ctk_window_move(w,xpos,ypos) do { (w)->x=xpos; (w)->y=ypos; } while(0)
00704 CCIF void ctk_window_close(struct ctk_window *w);
00705 CCIF void ctk_window_redraw(struct ctk_window *w);
00706 #define ctk_window_isopen(w) ((w)->next != NULL)
00707 
00708 
00709 /* Functions for manipulating dialogs. */
00710 CCIF void ctk_dialog_new(struct ctk_window *window,
00711                         unsigned char w, unsigned char h);
00712 CCIF void ctk_dialog_open(struct ctk_window *d);
00713 CCIF void ctk_dialog_close(void);
00714 
00715 /* Functions for manipulating menus. */
00716 CCIF void ctk_menu_new(struct ctk_menu *menu, char *title);
00717 CCIF void ctk_menu_add(struct ctk_menu *menu);
00718 CCIF void ctk_menu_remove(struct ctk_menu *menu);
00719 CCIF unsigned char ctk_menuitem_add(struct ctk_menu *menu, char *name);
00720 
00721 /* Functions for icons. */
00722 
00723 /**
00724  * \addtogroup ctkappfunc
00725  * @{
00726  */
00727 /**
00728  * Add an icon to the desktop.
00729  *
00730  * \param icon The icon to be added.
00731  *
00732  * \param p The process ID of the process that owns the icon.
00733  */
00734 #define CTK_ICON_ADD(icon, p) ctk_icon_add((struct ctk_widget *)icon, p)
00735 void ctk_icon_add(struct ctk_widget *icon, struct process *p);
00736 
00737 /* Functions for manipulating widgets. */
00738 
00739 /**
00740  * Add a widget to a window.
00741  *
00742  * \param win The window to which the widget should be added.
00743  * \param widg The widget to be added.
00744  */
00745 #define CTK_WIDGET_ADD(win, widg) \
00746  ctk_widget_add(win, (struct ctk_widget *)widg)
00747 CCIF void CC_FASTCALL ctk_widget_add(struct ctk_window *window,
00748                                      struct ctk_widget *widget);
00749 
00750 /**
00751  * Set focus to a widget.
00752  *
00753  * \param win The widget's window.
00754  * \param widg The widget
00755  */
00756 #define CTK_WIDGET_FOCUS(win, widg) \
00757   (win)->focused = (struct ctk_widget *)(widg)
00758 
00759 /**
00760  * Add a widget to the redraw queue.
00761  *
00762  * \param widg The widget to be redrawn.
00763  */
00764 #define CTK_WIDGET_REDRAW(widg) \
00765  ctk_widget_redraw((struct ctk_widget *)widg)
00766 CCIF void ctk_widget_redraw(struct ctk_widget *w);
00767 
00768 /**
00769  * Obtain the type of a widget.
00770  *
00771  * \param w The widget.
00772  */
00773 #define CTK_WIDGET_TYPE(w) ((w)->type)
00774 
00775 
00776 /**
00777  * Sets the width of a widget.
00778  *
00779  * \param widget The widget.
00780  * \param width The width of the widget, in characters.
00781  */
00782 #define CTK_WIDGET_SET_WIDTH(widget, width) do { \
00783     ((struct ctk_widget *)(widget))->w = (width); } while(0)
00784 
00785 /**
00786  * Retrieves the x position of a widget, relative to the window in
00787  * which the widget is contained.
00788  *
00789  * \param w The widget.
00790  * \return The x position of the widget.
00791  */
00792 #define CTK_WIDGET_XPOS(w) (((struct ctk_widget *)(w))->x)
00793 
00794 /**
00795  * Sets the x position of a widget, relative to the window in
00796  * which the widget is contained.
00797  *
00798  * \param w The widget.
00799  * \param xpos The x position of the widget.
00800  */
00801 #define CTK_WIDGET_SET_XPOS(w, xpos) \
00802         ((struct ctk_widget *)(w))->x = (xpos)
00803 /**
00804  * Retrieves the y position of a widget, relative to the window in
00805  * which the widget is contained.
00806  *
00807  * \param w The widget.
00808  * \return The y position of the widget.
00809  */
00810 #define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
00811 
00812 /**
00813  * Sets the y position of a widget, relative to the window in
00814  * which the widget is contained.
00815  *
00816  * \param w The widget.
00817  * \param ypos The y position of the widget.
00818  */
00819 #define CTK_WIDGET_SET_YPOS(w, ypos) \
00820         ((struct ctk_widget *)(w))->y = (ypos)
00821 
00822 /* XXX: should be removed.
00823 #define ctk_textentry_set_height(w, height) \
00824                            (w)->widget.textentry.h = (height)
00825 */
00826 
00827 /** \def ctk_label_set_height(w, height)
00828  * \brief Set the height of a label.
00829  *
00830  * \param w The CTK label widget.
00831  * \param height The new height of the label.
00832  */
00833 #define ctk_label_set_height(w, height) \
00834                            (w)->widget.label.h = (height)
00835 
00836 /**
00837  * Set the text of a label.
00838  *
00839  * \param l The CTK label widget.
00840  * \param t The new text of the label.
00841  */
00842 #define ctk_label_set_text(l, t) (l)->text = (t)
00843 
00844 /**
00845  * Set the text of a button.
00846  *
00847  * \param b The CTK button widget.
00848  * \param t The new text of the button.
00849  */
00850 #define ctk_button_set_text(b, t) (b)->text = (t)
00851 
00852 #define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m)
00853 
00854 #define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
00855  do { (widg)->window = NULL; \
00856  (widg)->next = NULL; \
00857  (widg)->type = CTK_WIDGET_BUTTON; \
00858  (widg)->x = (xpos); \
00859  (widg)->y = (ypos); \
00860  (widg)->w = (width); \
00861  (widg)->h = 1; \
00862  (widg)->text = (buttontext); \
00863  } while(0)
00864 
00865 #define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
00866  do { (widg)->window = NULL; \
00867  (widg)->next = NULL; \
00868  (widg)->type = CTK_WIDGET_LABEL; \
00869  (widg)->x = (xpos); \
00870  (widg)->y = (ypos); \
00871  (widg)->w = (width); \
00872  (widg)->h = (height); \
00873  (widg)->text = (labeltext); \
00874  } while(0)
00875 
00876 #define CTK_BITMAP_NEW(widg, xpos, ypos, width, height, bmap) \
00877  do { (widg)->window = NULL; \
00878  (widg)->next = NULL; \
00879  (widg)->type = CTK_WIDGET_BITMAP; \
00880  (widg)->x = (xpos); \
00881  (widg)->y = (ypos); \
00882  (widg)->w = (width); \
00883  (widg)->h = (height); \
00884  (widg)->bitmap = (bmap); \
00885  } while(0)
00886 
00887 #define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
00888  do { (widg)->window = NULL; \
00889  (widg)->next = NULL; \
00890  (widg)->type = CTK_WIDGET_TEXTENTRY; \
00891  (widg)->x = (xxpos); \
00892  (widg)->y = (yypos); \
00893  (widg)->w = (width); \
00894  (widg)->h = 1; \
00895  (widg)->text = (textptr); \
00896  (widg)->len = (textlen); \
00897  (widg)->state = CTK_TEXTENTRY_NORMAL; \
00898  (widg)->xpos = 0; \
00899  (widg)->ypos = 0; \
00900  (widg)->input = NULL; \
00901  } while(0)
00902 
00903 #define CTK_TEXTENTRY_INPUT_NEW(widg, xxpos, yypos, width, height, textptr, textlen, iinput) \
00904  do { (widg)->window = NULL; \
00905  (widg)->next = NULL; \
00906  (widg)->type = CTK_WIDGET_TEXTENTRY; \
00907  (widg)->x = (xxpos); \
00908  (widg)->y = (yypos); \
00909  (widg)->w = (width); \
00910  (widg)->h = (height); \
00911  (widg)->text = (textptr); \
00912  (widg)->len = (textlen); \
00913  (widg)->state = CTK_TEXTENTRY_NORMAL; \
00914  (widg)->xpos = 0; \
00915  (widg)->ypos = 0; \
00916  (widg)->input = (ctk_textentry_input)(iinput); \
00917  } while(0)
00918 
00919 #define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
00920  do { (widg)->window = NULL; \
00921  (widg)->next = NULL; \
00922  (widg)->type = CTK_WIDGET_HYPERLINK; \
00923  (widg)->x = (xpos); \
00924  (widg)->y = (ypos); \
00925  (widg)->w = (width); \
00926  (widg)->h = 1; \
00927  (widg)->text = (linktext); \
00928  (widg)->url = (linkurl); \
00929  } while(0)
00930 
00931 /* Desktop interface. */
00932 void ctk_desktop_redraw(struct ctk_desktop *d);
00933 CCIF unsigned char ctk_desktop_width(struct ctk_desktop *d);
00934 unsigned char ctk_desktop_height(struct ctk_desktop *d);
00935 
00936 /* Signals. */
00937 CCIF extern process_event_t ctk_signal_keypress,
00938   ctk_signal_widget_activate,
00939   ctk_signal_widget_select,
00940   ctk_signal_timer,
00941   ctk_signal_menu_activate,
00942   ctk_signal_window_close,
00943   ctk_signal_pointer_move,
00944   ctk_signal_pointer_button;
00945 
00946 #if CTK_CONF_SCREENSAVER
00947 extern process_event_t ctk_signal_screensaver_stop,
00948   ctk_signal_screensaver_start;
00949 
00950 extern unsigned short ctk_screensaver_timeout;
00951 /**
00952  * Set the screensaver timeout, in seconds.
00953  *
00954  * \param t The timeout in seconds.
00955  */
00956 #define CTK_SCREENSAVER_SET_TIMEOUT(t) ctk_screensaver_timeout = (t)
00957 /**
00958  * Obtain the screensaver timeout, in seconds.
00959  *
00960  * \raturn The timeout in seconds.
00961  */
00962 #define CTK_SCREENSAVER_TIMEOUT() ctk_screensaver_timeout
00963 #endif /* CTK_CONF_SCREENSAVER */
00964 
00965 /* These should no longer be used: */
00966 CCIF extern process_event_t ctk_signal_button_activate,
00967   ctk_signal_button_hover,
00968   ctk_signal_hyperlink_activate,
00969   ctk_signal_hyperlink_hover;
00970 /** @} */
00971 
00972 /**
00973  * \addtogroup ctkdraw
00974  * @{
00975  */
00976 
00977 /* Focus flags */
00978 /** Widget focus flag: no focus. */
00979 #define CTK_FOCUS_NONE     0
00980 /** Widget focus flag: widget has focus. */
00981 #define CTK_FOCUS_WIDGET   1
00982 /** Widget focus flag: widget's window is the foremost one. */
00983 #define CTK_FOCUS_WINDOW   2
00984 /** Widget focus flag: widget is in a dialog. */
00985 #define CTK_FOCUS_DIALOG   4
00986 
00987 /** @} */
00988 /** @} */
00989 /** @} */
00990 #endif /* __CTK_H__ */