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