blob: 4addc72e6a5c8f07a8b13d950afeec6bf536cb94 [file] [log] [blame]
adamdunkelsb27d85a2003-09-01 22:23:26 +00001/**
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
adamdunkelsca9ddcb2003-03-19 14:13:31 +000010/*
adamdunkelsb27d85a2003-09-01 22:23:26 +000011 * Copyright (c) 2002-2003, Adam Dunkels.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000012 * 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.
adamdunkelsb27d85a2003-09-01 22:23:26 +000023 * 3. The name of the author may not be used to endorse or promote
adamdunkelsca9ddcb2003-03-19 14:13:31 +000024 * 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 *
adamdunkelsb27d85a2003-09-01 22:23:26 +000039 * This file is part of the Contiki desktop OS.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000040 *
adamdunkels0404ef12003-09-04 19:36:04 +000041 * $Id: ctk.h,v 1.17 2003/09/04 19:36:04 adamdunkels Exp $
adamdunkelsca9ddcb2003-03-19 14:13:31 +000042 *
43 */
44
45#ifndef __CTK_H__
46#define __CTK_H__
47
adamdunkelsa6557e42003-08-11 22:27:51 +000048
adamdunkelsca9ddcb2003-03-19 14:13:31 +000049#include "ctk-conf.h"
adamdunkelsa6557e42003-08-11 22:27:51 +000050#include "ctk-arch.h"
adamdunkelsca9ddcb2003-03-19 14:13:31 +000051#include "ek.h"
52
adamdunkels78c03dc2003-04-09 13:45:05 +000053#include "cc.h"
54
adamdunkelsca9ddcb2003-03-19 14:13:31 +000055/* Defintions for the CTK widget types. */
adamdunkelsb27d85a2003-09-01 22:23:26 +000056
57/** The CTK separator widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000058#define CTK_WIDGET_SEPARATOR 1
adamdunkelsb27d85a2003-09-01 22:23:26 +000059/** The CTK label widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000060#define CTK_WIDGET_LABEL 2
adamdunkelsb27d85a2003-09-01 22:23:26 +000061/** The CTK button widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000062#define CTK_WIDGET_BUTTON 3
adamdunkelsb27d85a2003-09-01 22:23:26 +000063/** The CTK hyperlink widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000064#define CTK_WIDGET_HYPERLINK 4
adamdunkelsb27d85a2003-09-01 22:23:26 +000065/** The CTK textentry widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000066#define CTK_WIDGET_TEXTENTRY 5
adamdunkelsb27d85a2003-09-01 22:23:26 +000067/** The CTK bitmap widget. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +000068#define CTK_WIDGET_BITMAP 6
adamdunkelsb27d85a2003-09-01 22:23:26 +000069/** The CTK icon widget. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +000070#define CTK_WIDGET_ICON 7
adamdunkelsca9ddcb2003-03-19 14:13:31 +000071
72struct ctk_widget;
73
adamdunkelsb27d85a2003-09-01 22:23:26 +000074/**
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000089#define CTK_SEPARATOR(x, y, w) \
adamdunkelseb9bf6c2003-06-30 20:45:50 +000090 NULL, NULL, x, y, CTK_WIDGET_SEPARATOR, w, 1
adamdunkelsca9ddcb2003-03-19 14:13:31 +000091struct ctk_separator {
92 struct ctk_widget *next;
93 struct ctk_window *window;
94 unsigned char x, y;
95 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +000096 unsigned char w, h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +000097};
98
adamdunkelsb27d85a2003-09-01 22:23:26 +000099/**
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000115#define CTK_BUTTON(x, y, w, text) \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000116 NULL, NULL, x, y, CTK_WIDGET_BUTTON, w, 1, text
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000117struct ctk_button {
118 struct ctk_widget *next;
119 struct ctk_window *window;
120 unsigned char x, y;
121 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000122 unsigned char w, h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000123 char *text;
124};
125
adamdunkelsb27d85a2003-09-01 22:23:26 +0000126/**
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000143#define CTK_LABEL(x, y, w, h, text) \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000144 NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, text,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000145struct ctk_label {
146 struct ctk_widget *next;
147 struct ctk_window *window;
148 unsigned char x, y;
149 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000150 unsigned char w, h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000151 char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000152};
153
adamdunkelsb27d85a2003-09-01 22:23:26 +0000154/**
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000171#define CTK_HYPERLINK(x, y, w, text, url) \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000172 NULL, NULL, x, y, CTK_WIDGET_HYPERLINK, w, 1, text, url
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000173struct ctk_hyperlink {
174 struct ctk_widget *next;
175 struct ctk_window *window;
176 unsigned char x, y;
177 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000178 unsigned char w, h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000179 char *text;
180 char *url;
181};
182
183/* Editing modes of the CTK textentry widget. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000184#define CTK_TEXTENTRY_NORMAL 0 /**< \internal Textentry state: not
185 edited. */
186#define CTK_TEXTENTRY_EDIT 1 /**< \internal Textentry state:
187 currenly being edited. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000188
adamdunkelsb27d85a2003-09-01 22:23:26 +0000189/**
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 */
adamdunkels6e04e1a2003-08-20 20:55:35 +0000195#define CTK_TEXTENTRY_CLEAR(e) do {memset((e)->text, 0, (e)->len); (e)->xpos = 0;} while(0);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000196
adamdunkelsb27d85a2003-09-01 22:23:26 +0000197/**
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000218#define CTK_TEXTENTRY(x, y, w, h, text, len) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000219 NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, text, len, \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000220 CTK_TEXTENTRY_NORMAL, 0, 0
221struct ctk_textentry {
222 struct ctk_widget *next;
223 struct ctk_window *window;
224 unsigned char x, y;
225 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000226 unsigned char w, h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000227 char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000228 unsigned char len;
229 unsigned char state;
230 unsigned char xpos, ypos;
231};
232
233
adamdunkelsb27d85a2003-09-01 22:23:26 +0000234/**
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000247#define CTK_ICON(title, bitmap, textmap) \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000248 NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, 4, title, 0, bitmap, textmap
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000249struct ctk_icon {
250 struct ctk_widget *next;
251 struct ctk_window *window;
252 unsigned char x, y;
253 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000254 unsigned char w, h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000255 char *title;
256 ek_id_t owner;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000257 unsigned char *bitmap;
258 char *textmap;
259};
260
261#define CTK_BITMAP(x, y, w, h, bitmap) \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000262 NULL, NULL, x, y, CTK_WIDGET_BITMAP, w, h, bitmap,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000263struct ctk_bitmap {
264 struct ctk_widget *next;
265 struct ctk_window *window;
266 unsigned char x, y;
267 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000268 unsigned char w, h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000269 unsigned char *bitmap;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000270};
271
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000272#define CTK_TEXTMAP_NORMAL 0
273#define CTK_TEXTMAP_ACTIVE 1
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000274
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000275#define CTK_TEXTMAP(x, y, w, h, textmap, flags) \
276 NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, text, flags, CTK_TEXTMAP_NORMAL
277struct 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
adamdunkelsb27d85a2003-09-01 22:23:26 +0000289/**
290 * \internal The CTK button widget structure.
291 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000292struct ctk_widget_button {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000293 char *text; /**< The button text. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000294};
295
adamdunkelsb27d85a2003-09-01 22:23:26 +0000296/**
297 * \internal The CTK label widget structure.
298 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000299struct ctk_widget_label {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000300 char *text; /**< The label text. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000301};
302
adamdunkelsb27d85a2003-09-01 22:23:26 +0000303/**
304 * \internal The CTK hyperlink widget structure.
305 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000306struct ctk_widget_hyperlink {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000307 char *text; /**< The text of the hyperlink. */
308 char *url; /**< The hyperlink's URL. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000309};
310
311struct ctk_widget_textentry {
312 char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000313 unsigned char len;
314 unsigned char state;
315 unsigned char xpos, ypos;
316};
317
318struct ctk_widget_icon {
319 char *title;
320 ek_id_t owner;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000321 unsigned char *bitmap;
322 char *textmap;
323};
324
325struct ctk_widget_bitmap {
326 unsigned char *bitmap;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000327};
328
adamdunkelsb27d85a2003-09-01 22:23:26 +0000329/**
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000341struct ctk_widget {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000342 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. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000364 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;
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000370 struct ctk_widget_bitmap bitmap;
adamdunkelsb27d85a2003-09-01 22:23:26 +0000371 } widget; /**< The union which contains the actual
372 widget structure, as determined by the
373 type field. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000374};
375
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000376struct ctk_desktop;
377
adamdunkelsb27d85a2003-09-01 22:23:26 +0000378/**
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000388struct ctk_window {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000389 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. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000396
adamdunkelsb27d85a2003-09-01 22:23:26 +0000397 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. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000401
adamdunkelsb27d85a2003-09-01 22:23:26 +0000402 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. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000406
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000407#if CTK_CONF_WINDOWCLOSE
adamdunkelsb27d85a2003-09-01 22:23:26 +0000408 struct ctk_button closebutton; /**< The closebutton. This is also
409 present in the list of active
410 widgets. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000411#else /* CTK_CONF_WINDOWCLOSE */
412 struct ctk_label closebutton;
413#endif /* CTK_CONF_WINDOWCLOSE */
414
415#if CTK_CONF_WINDOWMOVE
adamdunkelsb27d85a2003-09-01 22:23:26 +0000416 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. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000420#else /* CTK_CONF_WINDOWMOVE */
421 struct ctk_label titlebutton;
422#endif /* CTK_CONF_WINDOWMOVE */
423
adamdunkelsb27d85a2003-09-01 22:23:26 +0000424 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. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000432
433
adamdunkelsb27d85a2003-09-01 22:23:26 +0000434 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. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000446};
447
adamdunkelsb27d85a2003-09-01 22:23:26 +0000448/**
449 * Repressentation of an individual menu item.
450 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000451struct ctk_menuitem {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000452 char *title; /**< The menu items text. */
453 unsigned char titlelen;/**< The length of the item text, cached for
454 speed. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000455};
456
adamdunkelsb27d85a2003-09-01 22:23:26 +0000457/**
458 * Repressentation of an individual menu.
459 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000460struct ctk_menu {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000461 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. */
adamdunkels78c03dc2003-04-09 13:45:05 +0000469#if CC_UNSIGNED_CHAR_BUGS
adamdunkels6ccf7212003-04-10 07:04:45 +0000470 unsigned int nitems;
471 unsigned int active;
adamdunkels78c03dc2003-04-09 13:45:05 +0000472#else /* CC_UNSIGNED_CHAR_BUGS */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000473 unsigned char nitems; /**< The total number of menu items in the
474 menu. */
475 unsigned char active; /**< The currently active menu item. */
adamdunkels78c03dc2003-04-09 13:45:05 +0000476#endif /* CC_UNSIGNED_CHAR_BUGS */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000477 struct ctk_menuitem items[CTK_CONF_MAXMENUITEMS];
adamdunkelsb27d85a2003-09-01 22:23:26 +0000478 /**< The array which contains all the menu
479 items. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000480};
481
adamdunkelsb27d85a2003-09-01 22:23:26 +0000482/**
483 * Repressentation of the menu bar.
484 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000485struct ctk_menus {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000486 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). */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000497};
498
adamdunkelsb27d85a2003-09-01 22:23:26 +0000499/**
500 * \internal The structure describing a Contiki desktop.
501 */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000502struct ctk_desktop {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000503 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. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000510
511#if CTK_CONF_MENUS
adamdunkelsb27d85a2003-09-01 22:23:26 +0000512 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. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000515#endif /* CTK_CONF_MENUS */
516
adamdunkelsb27d85a2003-09-01 22:23:26 +0000517 unsigned char height, /**< The height of the desktop, in characters. */
518 width; /**< The width of the desktop, in characters. */
519
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000520
adamdunkelsb27d85a2003-09-01 22:23:26 +0000521#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. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000533
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
adamdunkelsb27d85a2003-09-01 22:23:26 +0000541 unsigned char redraw; /**< The redraw flag. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000542
adamdunkelsb27d85a2003-09-01 22:23:26 +0000543 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. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000545
adamdunkelsb27d85a2003-09-01 22:23:26 +0000546 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. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000548
adamdunkelsb27d85a2003-09-01 22:23:26 +0000549 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. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000551};
552
553
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000554/* 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. */
561void ctk_init(void);
562void ctk_mode_set(unsigned char mode);
563unsigned char ctk_mode_get(void);
adamdunkels9795b2e2003-08-09 23:32:37 +0000564/*void ctk_redraw(void);*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000565
566/* Functions for manipulating windows. */
567void ctk_window_new(struct ctk_window *window,
568 unsigned char w, unsigned char h,
569 char *title);
570void ctk_window_clear(struct ctk_window *w);
571void ctk_window_open(struct ctk_window *w);
572#define ctk_window_move(w,xpos,ypos) do {(w)->x=xpos; (w)->y=ypos;}while(0)
573void ctk_window_close(struct ctk_window *w);
574void ctk_window_redraw(struct ctk_window *w);
575#define ctk_window_isopen(w) ((w)->next != NULL)
576
577
578/* Functions for manipulating dialogs. */
579void ctk_dialog_new(struct ctk_window *window,
580 unsigned char w, unsigned char h);
581void ctk_dialog_open(struct ctk_window *d);
582void ctk_dialog_close(void);
583
584/* Functions for manipulating menus. */
585void ctk_menu_new(struct ctk_menu *menu, char *title);
586void ctk_menu_add(struct ctk_menu *menu);
587void ctk_menu_remove(struct ctk_menu *menu);
588unsigned char ctk_menuitem_add(struct ctk_menu *menu, char *name);
589
590/* Functions for icons. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000591/**
592 * Add an icon to the desktop.
593 *
594 * \param icon The icon to be added.
adamdunkels0404ef12003-09-04 19:36:04 +0000595 *
596 * \param id The process ID of the process that owns the icon.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000597 */
adamdunkels0404ef12003-09-04 19:36:04 +0000598#define CTK_ICON_ADD(icon, id) ctk_icon_add((struct ctk_widget *)icon, id)
599void ctk_icon_add(struct ctk_widget *icon, ek_id_t id);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000600
601/* Functions for manipulating widgets. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000602
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000609#define CTK_WIDGET_ADD(win, widg) \
610 ctk_widget_add(win, (struct ctk_widget *)widg)
adamdunkelsa6557e42003-08-11 22:27:51 +0000611void CC_FASTCALL ctk_widget_add(struct ctk_window *window,
612 struct ctk_widget *widget);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000613
adamdunkelsb27d85a2003-09-01 22:23:26 +0000614/**
615 * Set focus to a widget.
616 *
617 * \param win The widget's window.
618 * \param widg The widget
619 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000620#define CTK_WIDGET_FOCUS(win, widg) \
621 (win)->focused = (struct ctk_widget *)(widg)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000622
623/**
624 * Add a widget to the redraw queue.
625 *
626 * \param widg The widget to be redrawn.
627 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000628#define CTK_WIDGET_REDRAW(widg) \
629 ctk_widget_redraw((struct ctk_widget *)widg)
630void ctk_widget_redraw(struct ctk_widget *w);
631
adamdunkelsb27d85a2003-09-01 22:23:26 +0000632/**
633 * Obtain the type of a widget.
634 *
635 * \param w The widget.
636 */
adamdunkels3a08a492003-04-11 20:16:02 +0000637#define CTK_WIDGET_TYPE(w) ((w)->type)
638
adamdunkelse8b21d02003-04-24 17:18:27 +0000639
adamdunkelsb27d85a2003-09-01 22:23:26 +0000640/**
641 * Sets the width of a widget.
642 *
643 * \param widget The widget.
644 * \param width The width of the widget, in characters.
645 */
adamdunkelse8b21d02003-04-24 17:18:27 +0000646#define CTK_WIDGET_SET_WIDTH(widget, width) do { \
647 ((struct ctk_widget *)(widget))->w = (width); } while(0)
648
adamdunkelsb27d85a2003-09-01 22:23:26 +0000649/**
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 */
adamdunkelse8b21d02003-04-24 17:18:27 +0000656#define CTK_WIDGET_XPOS(w) (((struct ctk_widget *)(w))->x)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000657
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000674#define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
675
adamdunkelsb27d85a2003-09-01 22:23:26 +0000676/**
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.
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000687#define ctk_textentry_set_height(w, height) \
688 (w)->widget.textentry.h = (height)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000689*/
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000697#define ctk_label_set_height(w, height) \
698 (w)->widget.label.h = (height)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000699
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 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000706#define ctk_label_set_text(l, t) (l)->text = (t)
707
adamdunkelsb27d85a2003-09-01 22:23:26 +0000708/**
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 */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000714#define ctk_button_set_text(b, t) (b)->text = (t)
715
adamdunkels58917a82003-04-18 00:18:38 +0000716#define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m)
717
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000718#define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000719 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000720 (widg)->next = NULL; \
721 (widg)->type = CTK_WIDGET_BUTTON; \
722 (widg)->x = (xpos); \
723 (widg)->y = (ypos); \
724 (widg)->w = (width); \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000725 (widg)->h = 1; \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000726 (widg)->text = (buttontext); \
727 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000728
729#define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000730 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000731 (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); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000737 (widg)->text = (labeltext); \
738 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000739
adamdunkels58917a82003-04-18 00:18:38 +0000740#define CTK_BITMAP_NEW(widg, xpos, ypos, width, height, bmap) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000741 do { (widg)->window = NULL; \
adamdunkels58917a82003-04-18 00:18:38 +0000742 (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); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000748 (widg)->bitmap = (bmap); \
749 } while(0)
adamdunkels58917a82003-04-18 00:18:38 +0000750
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000751#define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000752 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000753 (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; \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000763 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000764
765
766#define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000767 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000768 (widg)->next = NULL; \
769 (widg)->type = CTK_WIDGET_HYPERLINK; \
770 (widg)->x = (xpos); \
771 (widg)->y = (ypos); \
772 (widg)->w = (width); \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000773 (widg)->h = 1; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000774 (widg)->text = (linktext); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000775 (widg)->url = (linkurl); \
776 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000777
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000778/* Desktop interface. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000779void ctk_desktop_redraw(struct ctk_desktop *d);
780unsigned char ctk_desktop_width(struct ctk_desktop *d);
781unsigned char ctk_desktop_height(struct ctk_desktop *d);
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000782
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000783/* Signals. */
784extern ek_signal_t ctk_signal_keypress,
adamdunkels3a08a492003-04-11 20:16:02 +0000785 ctk_signal_widget_activate,
786 ctk_signal_widget_select,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000787 ctk_signal_timer,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000788 ctk_signal_menu_activate,
adamdunkelsc4902862003-04-09 00:30:45 +0000789 ctk_signal_window_close,
790 ctk_signal_pointer_move,
adamdunkels3a08a492003-04-11 20:16:02 +0000791 ctk_signal_pointer_button;
792
adamdunkelse8b21d02003-04-24 17:18:27 +0000793#if CTK_CONF_SCREENSAVER
adamdunkels9795b2e2003-08-09 23:32:37 +0000794extern ek_signal_t ctk_signal_screensaver_stop,
795 ctk_signal_screensaver_start;
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000796
797extern unsigned short ctk_screensaver_timeout;
adamdunkelsb27d85a2003-09-01 22:23:26 +0000798/**
799 * Set the screensaver timeout, in seconds.
800 *
801 * \param t The timeout in seconds.
802 */
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000803#define CTK_SCREENSAVER_SET_TIMEOUT(t) ctk_screensaver_timeout = (t)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000804/**
805 * Obtain the screensaver timeout, in seconds.
806 *
807 * \raturn The timeout in seconds.
808 */
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000809#define CTK_SCREENSAVER_TIMEOUT() ctk_screensaver_timeout
adamdunkelse8b21d02003-04-24 17:18:27 +0000810#endif /* CTK_CONF_SCREENSAVER */
811
adamdunkels3a08a492003-04-11 20:16:02 +0000812/* These should no longer be used: */
813extern ek_signal_t ctk_signal_button_activate,
814 ctk_signal_button_hover,
815 ctk_signal_hyperlink_activate,
816 ctk_signal_hyperlink_hover;
817
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000818/* Focus flags */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000819/** Widget focus flag: no focus. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000820#define CTK_FOCUS_NONE 0
adamdunkelsb27d85a2003-09-01 22:23:26 +0000821/** Widget focus flag: widget has focus. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000822#define CTK_FOCUS_WIDGET 1
adamdunkelsb27d85a2003-09-01 22:23:26 +0000823/** Widget focus flag: widget's window is the foremost one. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000824#define CTK_FOCUS_WINDOW 2
adamdunkelsb27d85a2003-09-01 22:23:26 +0000825/** Widget focus flag: widget is in a dialog. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000826#define CTK_FOCUS_DIALOG 4
827
828
829
830#endif /* __CTK_H__ */