Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Examples

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.1 2006/06/17 22:41:16 adamdunkels 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 struct ctk_textentry;
00241 typedef unsigned char (* ctk_textentry_input)(ctk_arch_key_t c,
00242                                               struct ctk_textentry *t);
00243 
00244 /**
00245  * Instantiating macro for the ctk_textentry widget.
00246  *
00247  * This macro is used when instantiating a ctk_textentry widget and is
00248  * intended to be used together with a struct assignment like this:
00249  \code
00250   struct ctk_textentry tentry =
00251          {CTK_TEXTENTRY(0, 0, 30, 1, textbuffer, 50)};
00252  \endcode
00253  * \note The height of the text entry widget is obsolete and not
00254  * intended to be used.
00255  *
00256  * \param x The x position of the widget, relative to the widget's
00257  * window.
00258  * \param y The y position of the widget, relative to the widget's
00259  * window.
00260  * \param w The widget's width.
00261  * \param h The text entry height (obsolete).
00262  * \param text A pointer to the buffer that should be edited.
00263  * \param len The length of the text buffer
00264  */
00265 #define CTK_TEXTENTRY(x, y, w, h, text, len) \
00266   NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
00267   CTK_TEXTENTRY_NORMAL, 0, 0, NULL
00268 #define CTK_TEXTENTRY_INPUT(x, y, w, h, text, len, input) \
00269   NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
00270   CTK_TEXTENTRY_NORMAL, 0, 0, (ctk_textentry_input)input
00271 struct ctk_textentry {
00272   struct ctk_widget *next;
00273   struct ctk_window *window;
00274   unsigned char x, y;
00275   unsigned char type;
00276   unsigned char w, h;
00277 #if CTK_CONF_WIDGET_FLAGS
00278   unsigned char flags;
00279 #endif /* CTK_CONF_WIDGET_FLAGS */
00280   char *text;
00281   unsigned char len;
00282   unsigned char state;
00283   unsigned char xpos, ypos;
00284   ctk_textentry_input input;
00285 };
00286 
00287 
00288 #if CTK_CONF_ICON_BITMAPS
00289 #define CTK_ICON_BITMAP(bitmap)   bitmap
00290 #else
00291 #define CTK_ICON_BITMAP(bitmap)   NULL
00292 #endif
00293 
00294 #if CTK_CONF_ICON_TEXTMAPS
00295 #define CTK_ICON_TEXTMAP(textmap) textmap
00296 #else
00297 #define CTK_ICON_TEXTMAP(textmap) NULL
00298 #endif
00299 
00300 /**
00301  * Instantiating macro for the ctk_icon widget.
00302  *
00303  * This macro is used when instantiating a ctk_icon widget and is
00304  * intended to be used together with a struct assignment like this:
00305  \code
00306   struct ctk_icon icon =
00307          {CTK_ICON("An icon", bitmapptr, textmapptr)};
00308  \endcode
00309  * \param title The icon's text.
00310  * \param bitmap A pointer to the icon's bitmap image.
00311  * \param textmap A pointer to the icon's text version of the bitmap.
00312  */
00313 #define CTK_ICON(title, bitmap, textmap) \
00314  NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, 4, CTK_WIDGET_FLAG_INITIALIZER(0) \
00315  title, PROCESS_NONE, \
00316  CTK_ICON_BITMAP(bitmap), CTK_ICON_TEXTMAP(textmap)
00317 struct ctk_icon {
00318   struct ctk_widget *next;
00319   struct ctk_window *window;
00320   unsigned char x, y;
00321   unsigned char type;
00322   unsigned char w, h;
00323 #if CTK_CONF_WIDGET_FLAGS
00324   unsigned char flags;
00325 #endif /* CTK_CONF_WIDGET_FLAGS */
00326   char *title;
00327   struct process *owner;
00328   unsigned char *bitmap;
00329   char *textmap;
00330 };
00331 
00332 #define CTK_BITMAP(x, y, w, h, bitmap, bitmap_width, bitmap_height) \
00333   NULL, NULL, x, y, CTK_WIDGET_BITMAP, w, h, \
00334   CTK_WIDGET_FLAG_INITIALIZER(0) bitmap, bitmap_width, bitmap_height
00335 struct ctk_bitmap {
00336   struct ctk_widget *next;
00337   struct ctk_window *window;
00338   unsigned char x, y;
00339   unsigned char type;
00340   unsigned char w, h;
00341 #if CTK_CONF_WIDGET_FLAGS
00342   unsigned char flags;
00343 #endif /* CTK_CONF_WIDGET_FLAGS */
00344   unsigned char *bitmap;
00345   unsigned short bw, bh;
00346 };
00347 
00348 #define CTK_TEXTMAP_NORMAL 0
00349 #define CTK_TEXTMAP_ACTIVE 1
00350 
00351 #define CTK_TEXTMAP(x, y, w, h, textmap) \
00352  NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, CTK_TEXTMAP_NORMAL
00353 struct ctk_textmap {
00354   struct ctk_widget *next;
00355   struct ctk_window *window;
00356   unsigned char x, y;
00357   unsigned char type;
00358   unsigned char w, h;
00359 #if CTK_CONF_WIDGET_FLAGS
00360   unsigned char flags;
00361 #endif /* CTK_CONF_WIDGET_FLAGS */
00362   char *textmap;
00363   unsigned char state;
00364 };
00365 
00366 
00367 /**
00368  * \internal The CTK button widget structure.
00369  */
00370 struct ctk_widget_button {
00371   char *text;  /**< The button text. */
00372 };
00373 
00374 /**
00375  * \internal The CTK label widget structure.
00376  */
00377 struct ctk_widget_label {
00378   char *text; /**< The label text. */
00379 };
00380 
00381 /**
00382  * \internal The CTK hyperlink widget structure.
00383  */
00384 struct ctk_widget_hyperlink {
00385   char *text; /**< The text of the hyperlink. */
00386   char *url;  /**< The hyperlink's URL. */
00387 };
00388 
00389 struct ctk_widget_textentry {
00390   char *text;
00391   unsigned char len;
00392   unsigned char state;
00393   unsigned char xpos, ypos;
00394   ctk_textentry_input input;
00395 };
00396 
00397 struct ctk_widget_icon {
00398   char *title;
00399   struct process *owner;
00400   unsigned char *bitmap;
00401   char *textmap;
00402 };
00403 
00404 struct ctk_widget_bitmap {
00405   unsigned char *bitmap;
00406   unsigned short bw, bh;
00407 };
00408 /** @} */
00409 
00410 /**
00411  * \addtogroup ctkdraw
00412  * @{
00413  */
00414 
00415 /**
00416  * The generic CTK widget structure that contains all other widget
00417  * structures.
00418  *
00419  * Since the widgets of a window are arranged on a linked list, the
00420  * widget structure contains a next pointer which is used for this
00421  * purpose. The widget structure also contains the placement and the
00422  * size of the widget.
00423  *
00424  * Finally, the actual per-widget structure is contained in this
00425  * top-level widget structure.
00426  */
00427 struct ctk_widget {
00428   struct ctk_widget *next;   /**< The next widget in the linked list
00429                                 of widgets that is contained in the
00430                                 ctk_window structure. */
00431   struct ctk_window *window; /**< The window in which the widget is
00432                                 contained. */
00433   unsigned char x,           /**< The x position of the widget within
00434                                 the containing window, in character
00435                                 coordinates. */
00436     y;                       /**< The y position of the widget within
00437                                 the containing window, in character
00438                                 coordinates. */
00439   unsigned char type;        /**< The type of the widget:
00440                                 CTK_WIDGET_SEPARATOR,
00441                                 CTK_WIDGET_LABEL, CTK_WIDGET_BUTTON,
00442                                 CTK_WIDGET_HYPERLINK,
00443                                 CTK_WIDGET_TEXTENTRY,
00444                                 CTK_WIDGET_BITMAP or
00445                                 CTK_WIDGET_ICON. */
00446   unsigned char w,           /**< The width of the widget in character
00447                                 coordinates. */
00448     h;                       /**< The height of the widget in
00449                                 character coordinates. */
00450 #if CTK_CONF_WIDGET_FLAGS
00451   unsigned char flags;
00452 #endif /* CTK_CONF_WIDGET_FLAGS */
00453   
00454   union {
00455     struct ctk_widget_label label;
00456     struct ctk_widget_button button;
00457     struct ctk_widget_hyperlink hyperlink;
00458     struct ctk_widget_textentry textentry;
00459     struct ctk_widget_icon icon;
00460     struct ctk_widget_bitmap bitmap;
00461   } widget;                  /**< The union which contains the actual
00462                                 widget structure, as determined by the
00463                                 type field. */
00464 };
00465 
00466 
00467 struct ctk_desktop;
00468 
00469 #define CTK_WIDGET_FLAG_NONE      0
00470 #define CTK_WIDGET_FLAG_MONOSPACE 1
00471 #define CTK_WIDGET_FLAG_CENTER    2
00472 
00473 #if CTK_CONF_WIDGET_FLAGS
00474 #define CTK_WIDGET_SET_FLAG(w, f) ((struct ctk_widget *)(w))->flags = (f)
00475 #else /* CTK_CONF_WIDGET_FLAGS */
00476 #define CTK_WIDGET_SET_FLAG(w, f)
00477 #endif /* CTK_CONF_WIDGET_FLAGS */
00478 
00479 /**
00480  * Representation of a CTK window.
00481  *
00482  * For the CTK, each window is repessented by a ctk_window
00483  * structure. All open windows are kept on a doubly linked list,
00484  * linked by the next and prev fields in the ctk_window struct. The
00485  * window structure holds all widgets that is contained in the window
00486  * as well as a pointer to the currently selected widget.
00487  *
00488  */
00489 struct ctk_window {
00490   struct ctk_window *next,  /**< The next window in the doubly linked
00491                                list of open windows. */
00492 
00493     *prev;                  /**< The previous window in the doubly
00494                                linked list of open windows. */
00495   struct ctk_desktop *desktop;/**< The desktop on which this window is
00496                                  open. */
00497   
00498   struct process *owner;            /**< The process that owns the
00499                                window. This process will be the
00500                                receiver of all CTK signals that
00501                                pertain to this window. */
00502   
00503   char *title;              /**< The title of the window. Used for
00504                                constructing the "Dekstop" menu. */
00505   unsigned char titlelen;   /**< The length of the title, cached for
00506                                speed reasons. */
00507 
00508 #if CTK_CONF_WINDOWCLOSE
00509   struct ctk_button closebutton; /**< The closebutton. This is also
00510                                     present in the list of active
00511                                     widgets. */
00512 #else /* CTK_CONF_WINDOWCLOSE */
00513   struct ctk_label closebutton;
00514 #endif /* CTK_CONF_WINDOWCLOSE */
00515   
00516 #if CTK_CONF_WINDOWMOVE
00517   struct ctk_button titlebutton;/**< The titlebutton which is used for
00518                                      moving the window. This is also
00519                                      present in the list of active
00520                                      widgets. */
00521 #else /* CTK_CONF_WINDOWMOVE */
00522   struct ctk_label titlebutton;
00523 #endif /* CTK_CONF_WINDOWMOVE */
00524 
00525   unsigned char x,             /**< The x coordinate of the window, in
00526                                   characters. */
00527     y;                         /**< The y coordinate of the window, in
00528                                   characters. */
00529   unsigned char w,             /**< The width of the window, excluding
00530                                   window borders. */
00531     h;                         /**< The height of the window,
00532                                   excluding window borders. */
00533 
00534 
00535   struct ctk_widget *inactive; /**< The list if widgets that cannot be
00536                                   selected by the user. Labels and
00537                                   separator widgets are placed on this
00538                                   list. */
00539   struct ctk_widget *active;   /**< The list of widgets that can be
00540                                   selected by the user. Buttons,
00541                                   hyperlinks, text entry fields, etc.,
00542                                   are placed on this list. */
00543   struct ctk_widget *focused;  /**< A pointer to the widget on the
00544                                   active list that is currently
00545                                   selected, or NULL if no widget is
00546                                   selected. */
00547 };
00548 
00549 /**
00550  * Representation of an individual menu item.
00551  */
00552 struct ctk_menuitem {
00553   char *title;           /**< The menu items text. */
00554   unsigned char titlelen;/**< The length of the item text, cached for
00555                             speed. */
00556 };
00557 
00558 #ifdef CTK_CONF_MAXMENUITEMS
00559 #define CTK_MAXMENUITEMS CTK_CONF_MAXMENUITEMS
00560 #else
00561 #define CTK_MAXMENUITEMS 8
00562 #endif
00563 
00564 /**
00565  * Representation of an individual menu.
00566  */
00567 struct ctk_menu {
00568   struct ctk_menu *next; /**< Apointer to the next menu, or is NULL if
00569                             this is the last menu, and should be used
00570                             by the ctk-draw module when stepping
00571                             through the menus when drawing them on
00572                             screen. */
00573   char *title;           /**< The menu title. */
00574   unsigned char titlelen;/**< The length of the title in
00575                             characters. Cached for speed reasons. */
00576 #if CC_UNSIGNED_CHAR_BUGS
00577   unsigned int nitems;
00578   unsigned int active;
00579 #else /* CC_UNSIGNED_CHAR_BUGS */
00580   unsigned char nitems;  /**< The total number of menu items in the
00581                             menu. */
00582   unsigned char active;  /**< The currently active menu item. */
00583 #endif /* CC_UNSIGNED_CHAR_BUGS */
00584   struct ctk_menuitem items[CTK_MAXMENUITEMS];
00585                          /**< The array which contains all the menu
00586                             items. */
00587 };
00588 
00589 /**
00590  * Representation of the menu bar.
00591  */
00592 struct ctk_menus {
00593   struct ctk_menu *menus;       /**< A pointer to a linked list of all
00594                                    menus, including the open menu and
00595                                    the desktop menu.*/
00596   struct ctk_menu *open;        /**< The currently open menu, if
00597                                    any. If all menus are closed, this
00598                                    item is NULL: */
00599   struct ctk_menu *desktopmenu; /**< A pointer to the "Desktop" menu
00600                                    that can be used for drawing the
00601                                    desktop menu in a special way (such
00602                                    as drawing it at the rightmost
00603                                    position). */
00604 };
00605 
00606 /** @} */
00607 
00608 
00609 /**
00610  * \internal The structure describing a Contiki desktop.
00611  */
00612 struct ctk_desktop {
00613   char *name; /**< The name of the desktop. */
00614    
00615   struct ctk_window desktop_window; /**< The background window which
00616                                        contains tha desktop icons. */
00617   struct ctk_window *windows; /**< The list of open windows. */
00618   struct ctk_window *dialog;  /**< A pointer to the open dialog, or
00619                                  NULL if no dialog is open. */
00620   
00621 #if CTK_CONF_MENUS
00622   struct ctk_menus menus;     /**< The list of desktop menus. */
00623   struct ctk_menu *lastmenu;  /**< Pointer to the menu that was last open. */
00624   struct ctk_menu desktopmenu;/**< The desktop menu. */
00625 #endif /* CTK_CONF_MENUS */
00626 
00627   unsigned char height, /**< The height of the desktop, in characters. */
00628     width; /**< The width of the desktop, in characters. */
00629 
00630   
00631 #define CTK_REDRAW_NONE         0 /**< \internal Redraw flag: nothing
00632                                      to be redrawn. */
00633 #define CTK_REDRAW_ALL          1 /**< \internal Redraw flag:
00634                                      everything should be redrawn. */
00635 #define CTK_REDRAW_WINDOWS      2 /**< \internal Redraw flag: redraw
00636                                      windows in queue.*/
00637 #define CTK_REDRAW_WIDGETS      4 /**< \internal Redraw flag: redraw
00638                                      widgets in queue. */
00639 #define CTK_REDRAW_MENUS        8 /**< \internal Redraw flag: redraw
00640                                      menus. */
00641 #define CTK_REDRAW_PART        16 /**< \internal Redraw flag: redraw
00642                                      parts of the desktop. */
00643 
00644 #ifndef CTK_CONF_MAX_REDRAWWIDGETS
00645 #define CTK_CONF_MAX_REDRAWWIDGETS 8
00646 #endif /* CTK_CONF_MAX_REDRAWWIDGETS */
00647 #ifndef CTK_CONF_MAX_REDRAWWINDOWS
00648 #define CTK_CONF_MAX_REDRAWWINDOWS 8
00649 #endif /* CTK_CONF_MAX_REDRAWWINDOWS */
00650   
00651   unsigned char redraw; /**< The redraw flag. */
00652   
00653   struct ctk_widget *redraw_widgets[CTK_CONF_MAX_REDRAWWIDGETS]; /**< The list of widgets to be redrawn. */
00654   unsigned char redraw_widgetptr; /**< Pointer to the last widget on the redraw_widgets list. */
00655 
00656   struct ctk_window *redraw_windows[CTK_CONF_MAX_REDRAWWINDOWS]; /**< The list of windows to be redrawn. */
00657   unsigned char redraw_windowptr; /**< Pointer to the last window on the redraw_windows list. */
00658 
00659    unsigned char redraw_y1, /**< The lower y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
00660     redraw_y2; /**< The upper y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
00661 };
00662 
00663 
00664 /* Global CTK modes. */
00665 #define CTK_MODE_NORMAL      0
00666 #define CTK_MODE_WINDOWMOVE  1
00667 #define CTK_MODE_SCREENSAVER 2
00668 #define CTK_MODE_EXTERNAL    3
00669 
00670 /* General ctk functions. */
00671 PROCESS_NAME(ctk_process);
00672 void ctk_init(void);
00673 void ctk_restore(void);
00674 
00675 void ctk_mode_set(unsigned char mode);
00676 unsigned char ctk_mode_get(void);
00677 /*void ctk_redraw(void);*/
00678 
00679 /* Functions for manipulating windows. */
00680 void ctk_window_new(struct ctk_window *window,
00681                     unsigned char w, unsigned char h,
00682                     char *title);
00683 void ctk_window_clear(struct ctk_window *w);
00684 void ctk_window_open(struct ctk_window *w);
00685 #define ctk_window_move(w,xpos,ypos) do { (w)->x=xpos; (w)->y=ypos; } while(0)
00686 void ctk_window_close(struct ctk_window *w);
00687 void ctk_window_redraw(struct ctk_window *w);
00688 #define ctk_window_isopen(w) ((w)->next != NULL)
00689 
00690 
00691 /* Functions for manipulating dialogs. */
00692 void ctk_dialog_new(struct ctk_window *window,
00693                     unsigned char w, unsigned char h);
00694 void ctk_dialog_open(struct ctk_window *d);
00695 void ctk_dialog_close(void);
00696 
00697 /* Functions for manipulating menus. */
00698 void ctk_menu_new(struct ctk_menu *menu, char *title);
00699 void ctk_menu_add(struct ctk_menu *menu);
00700 void ctk_menu_remove(struct ctk_menu *menu);
00701 unsigned char ctk_menuitem_add(struct ctk_menu *menu, char *name);
00702 
00703 /* Functions for icons. */
00704 
00705 /**
00706  * \addtogroup ctkappfunc
00707  * @{
00708  */
00709 /**
00710  * Add an icon to the desktop.
00711  *
00712  * \param icon The icon to be added.
00713  *
00714  * \param p The process ID of the process that owns the icon.
00715  */
00716 #define CTK_ICON_ADD(icon, p) ctk_icon_add((struct ctk_widget *)icon, p)
00717 void ctk_icon_add(struct ctk_widget *icon, struct process *p);
00718 
00719 /* Functions for manipulating widgets. */
00720 
00721 /**
00722  * Add a widget to a window.
00723  *
00724  * \param win The window to which the widget should be added.
00725  * \param widg The widget to be added.
00726  */
00727 #define CTK_WIDGET_ADD(win, widg) \
00728  ctk_widget_add(win, (struct ctk_widget *)widg)
00729 void CC_FASTCALL ctk_widget_add(struct ctk_window *window,
00730                                 struct ctk_widget *widget);
00731 
00732 /**
00733  * Set focus to a widget.
00734  *
00735  * \param win The widget's window.
00736  * \param widg The widget
00737  */
00738 #define CTK_WIDGET_FOCUS(win, widg) \
00739   (win)->focused = (struct ctk_widget *)(widg)
00740 
00741 /**
00742  * Add a widget to the redraw queue.
00743  *
00744  * \param widg The widget to be redrawn.
00745  */
00746 #define CTK_WIDGET_REDRAW(widg) \
00747  ctk_widget_redraw((struct ctk_widget *)widg)
00748 void ctk_widget_redraw(struct ctk_widget *w);
00749 
00750 /**
00751  * Obtain the type of a widget.
00752  *
00753  * \param w The widget.
00754  */
00755 #define CTK_WIDGET_TYPE(w) ((w)->type)
00756 
00757 
00758 /**
00759  * Sets the width of a widget.
00760  *
00761  * \param widget The widget.
00762  * \param width The width of the widget, in characters.
00763  */
00764 #define CTK_WIDGET_SET_WIDTH(widget, width) do { \
00765     ((struct ctk_widget *)(widget))->w = (width); } while(0)
00766 
00767 /**
00768  * Retrieves the x position of a widget, relative to the window in
00769  * which the widget is contained.
00770  *
00771  * \param w The widget.
00772  * \return The x position of the widget.
00773  */
00774 #define CTK_WIDGET_XPOS(w) (((struct ctk_widget *)(w))->x)
00775 
00776 /**
00777  * Sets the x position of a widget, relative to the window in
00778  * which the widget is contained.
00779  *
00780  * \param w The widget.
00781  * \param xpos The x position of the widget.
00782  */
00783 #define CTK_WIDGET_SET_XPOS(w, xpos) \
00784         ((struct ctk_widget *)(w))->x = (xpos)
00785 /**
00786  * Retrieves the y position of a widget, relative to the window in
00787  * which the widget is contained.
00788  *
00789  * \param w The widget.
00790  * \return The y position of the widget.
00791  */
00792 #define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
00793 
00794 /**
00795  * Sets the y position of a widget, relative to the window in
00796  * which the widget is contained.
00797  *
00798  * \param w The widget.
00799  * \param ypos The y position of the widget.
00800  */
00801 #define CTK_WIDGET_SET_YPOS(w, ypos) \
00802         ((struct ctk_widget *)(w))->y = (ypos)
00803 
00804 /* XXX: should be removed.
00805 #define ctk_textentry_set_height(w, height) \
00806                            (w)->widget.textentry.h = (height)
00807 */
00808 
00809 /** \def ctk_label_set_height(w, height)
00810  * \brief Set the height of a label.
00811  *
00812  * \param w The CTK label widget.
00813  * \param height The new height of the label.
00814  */
00815 #define ctk_label_set_height(w, height) \
00816                            (w)->widget.label.h = (height)
00817 
00818 /**
00819  * Set the text of a label.
00820  *
00821  * \param l The CTK label widget.
00822  * \param t The new text of the label.
00823  */
00824 #define ctk_label_set_text(l, t) (l)->text = (t)
00825 
00826 /**
00827  * Set the text of a button.
00828  *
00829  * \param b The CTK button widget.
00830  * \param t The new text of the button.
00831  */
00832 #define ctk_button_set_text(b, t) (b)->text = (t)
00833 
00834 #define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m)
00835 
00836 #define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
00837  do { (widg)->window = NULL; \
00838  (widg)->next = NULL; \
00839  (widg)->type = CTK_WIDGET_BUTTON; \
00840  (widg)->x = (xpos); \
00841  (widg)->y = (ypos); \
00842  (widg)->w = (width); \
00843  (widg)->h = 1; \
00844  (widg)->text = (buttontext); \
00845  } while(0)
00846 
00847 #define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
00848  do { (widg)->window = NULL; \
00849  (widg)->next = NULL; \
00850  (widg)->type = CTK_WIDGET_LABEL; \
00851  (widg)->x = (xpos); \
00852  (widg)->y = (ypos); \
00853  (widg)->w = (width); \
00854  (widg)->h = (height); \
00855  (widg)->text = (labeltext); \
00856  } while(0)
00857 
00858 #define CTK_BITMAP_NEW(widg, xpos, ypos, width, height, bmap) \
00859  do { (widg)->window = NULL; \
00860  (widg)->next = NULL; \
00861  (widg)->type = CTK_WIDGET_BITMAP; \
00862  (widg)->x = (xpos); \
00863  (widg)->y = (ypos); \
00864  (widg)->w = (width); \
00865  (widg)->h = (height); \
00866  (widg)->bitmap = (bmap); \
00867  } while(0)
00868 
00869 #define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
00870  do { (widg)->window = NULL; \
00871  (widg)->next = NULL; \
00872  (widg)->type = CTK_WIDGET_TEXTENTRY; \
00873  (widg)->x = (xxpos); \
00874  (widg)->y = (yypos); \
00875  (widg)->w = (width); \
00876  (widg)->h = 1; \
00877  (widg)->text = (textptr); \
00878  (widg)->len = (textlen); \
00879  (widg)->state = CTK_TEXTENTRY_NORMAL; \
00880  (widg)->xpos = 0; \
00881  (widg)->ypos = 0; \
00882  (widg)->input = NULL; \
00883  } while(0)
00884 
00885 #define CTK_TEXTENTRY_INPUT_NEW(widg, xxpos, yypos, width, height, textptr, textlen, iinput) \
00886  do { (widg)->window = NULL; \
00887  (widg)->next = NULL; \
00888  (widg)->type = CTK_WIDGET_TEXTENTRY; \
00889  (widg)->x = (xxpos); \
00890  (widg)->y = (yypos); \
00891  (widg)->w = (width); \
00892  (widg)->h = (height); \
00893  (widg)->text = (textptr); \
00894  (widg)->len = (textlen); \
00895  (widg)->state = CTK_TEXTENTRY_NORMAL; \
00896  (widg)->xpos = 0; \
00897  (widg)->ypos = 0; \
00898  (widg)->input = (ctk_textentry_input)(iinput); \
00899  } while(0)
00900 
00901 #define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
00902  do { (widg)->window = NULL; \
00903  (widg)->next = NULL; \
00904  (widg)->type = CTK_WIDGET_HYPERLINK; \
00905  (widg)->x = (xpos); \
00906  (widg)->y = (ypos); \
00907  (widg)->w = (width); \
00908  (widg)->h = 1; \
00909  (widg)->text = (linktext); \
00910  (widg)->url = (linkurl); \
00911  } while(0)
00912 
00913 /* Desktop interface. */
00914 void ctk_desktop_redraw(struct ctk_desktop *d);
00915 unsigned char ctk_desktop_width(struct ctk_desktop *d);
00916 unsigned char ctk_desktop_height(struct ctk_desktop *d);
00917 
00918 /* Signals. */
00919 extern process_event_t ctk_signal_keypress,
00920   ctk_signal_widget_activate,
00921   ctk_signal_widget_select,
00922   ctk_signal_timer,
00923   ctk_signal_menu_activate,
00924   ctk_signal_window_close,
00925   ctk_signal_pointer_move,
00926   ctk_signal_pointer_button;
00927 
00928 #if CTK_CONF_SCREENSAVER
00929 extern process_event_t ctk_signal_screensaver_stop,
00930   ctk_signal_screensaver_start;
00931 
00932 extern unsigned short ctk_screensaver_timeout;
00933 /**
00934  * Set the screensaver timeout, in seconds.
00935  *
00936  * \param t The timeout in seconds.
00937  */
00938 #define CTK_SCREENSAVER_SET_TIMEOUT(t) ctk_screensaver_timeout = (t)
00939 /**
00940  * Obtain the screensaver timeout, in seconds.
00941  *
00942  * \raturn The timeout in seconds.
00943  */
00944 #define CTK_SCREENSAVER_TIMEOUT() ctk_screensaver_timeout
00945 #endif /* CTK_CONF_SCREENSAVER */
00946 
00947 /* These should no longer be used: */
00948 extern process_event_t ctk_signal_button_activate,
00949   ctk_signal_button_hover,
00950   ctk_signal_hyperlink_activate,
00951   ctk_signal_hyperlink_hover;
00952 /** @} */
00953 
00954 /**
00955  * \addtogroup ctkdraw
00956  * @{
00957  */
00958 
00959 /* Focus flags */
00960 /** Widget focus flag: no focus. */
00961 #define CTK_FOCUS_NONE     0
00962 /** Widget focus flag: widget has focus. */
00963 #define CTK_FOCUS_WIDGET   1
00964 /** Widget focus flag: widget's window is the foremost one. */
00965 #define CTK_FOCUS_WINDOW   2
00966 /** Widget focus flag: widget is in a dialog. */
00967 #define CTK_FOCUS_DIALOG   4
00968 
00969 /** @} */
00970 /** @} */
00971 /** @} */
00972 #endif /* __CTK_H__ */

Generated on Thu Jun 22 17:45:42 2006 for Contiki 2.x by  doxygen 1.4.4