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