blob: 3617a56bf6fefe64baf3779f4058ae1668d8bcb4 [file] [log] [blame]
adamdunkelsb27d85a2003-09-01 22:23:26 +00001/**
adamdunkelse937ded2003-10-01 07:53:57 +00002 * \addtogroup ctk
3 * @{
4 */
5
6/**
adamdunkelsb27d85a2003-09-01 22:23:26 +00007 * \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
adamdunkelsca9ddcb2003-03-19 14:13:31 +000015/*
adamdunkelsb27d85a2003-09-01 22:23:26 +000016 * Copyright (c) 2002-2003, Adam Dunkels.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000017 * 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.
adamdunkelsb27d85a2003-09-01 22:23:26 +000028 * 3. The name of the author may not be used to endorse or promote
adamdunkelsca9ddcb2003-03-19 14:13:31 +000029 * 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 *
adamdunkelsb27d85a2003-09-01 22:23:26 +000044 * This file is part of the Contiki desktop OS.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000045 *
oliverschmidtcd6c30b2005-05-05 20:54:16 +000046 * $Id: ctk.h,v 1.24 2005/05/05 20:54:16 oliverschmidt Exp $
adamdunkelsca9ddcb2003-03-19 14:13:31 +000047 *
48 */
49
50#ifndef __CTK_H__
51#define __CTK_H__
52
adamdunkelsa6557e42003-08-11 22:27:51 +000053
adamdunkelsca9ddcb2003-03-19 14:13:31 +000054#include "ctk-conf.h"
adamdunkelsa6557e42003-08-11 22:27:51 +000055#include "ctk-arch.h"
adamdunkelsca9ddcb2003-03-19 14:13:31 +000056#include "ek.h"
57
adamdunkels78c03dc2003-04-09 13:45:05 +000058#include "cc.h"
59
adamdunkelsca9ddcb2003-03-19 14:13:31 +000060/* Defintions for the CTK widget types. */
adamdunkelsb27d85a2003-09-01 22:23:26 +000061
adamdunkelse937ded2003-10-01 07:53:57 +000062/**
63 * \addtogroup ctkdraw
64 * @{
65 */
66
67/** Widget number: The CTK separator widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000068#define CTK_WIDGET_SEPARATOR 1
adamdunkelse937ded2003-10-01 07:53:57 +000069/** Widget number: The CTK label widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000070#define CTK_WIDGET_LABEL 2
adamdunkelse937ded2003-10-01 07:53:57 +000071/** Widget number: The CTK button widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000072#define CTK_WIDGET_BUTTON 3
adamdunkelse937ded2003-10-01 07:53:57 +000073/** Widget number: The CTK hyperlink widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000074#define CTK_WIDGET_HYPERLINK 4
adamdunkelse937ded2003-10-01 07:53:57 +000075/** Widget number: The CTK textentry widget. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +000076#define CTK_WIDGET_TEXTENTRY 5
adamdunkelse937ded2003-10-01 07:53:57 +000077/** Widget number: The CTK bitmap widget. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +000078#define CTK_WIDGET_BITMAP 6
adamdunkelse937ded2003-10-01 07:53:57 +000079/** Widget number: The CTK icon widget. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +000080#define CTK_WIDGET_ICON 7
adamdunkelsca9ddcb2003-03-19 14:13:31 +000081
adamdunkelse937ded2003-10-01 07:53:57 +000082/** @} */
83
adamdunkelsca9ddcb2003-03-19 14:13:31 +000084struct ctk_widget;
85
adamdunkels1f9a9a12004-07-04 11:42:47 +000086#if CTK_CONF_WIDGET_FLAGS
87#define CTK_WIDGET_FLAG_INITIALIZER(x) x,
88#else
89#define CTK_WIDGET_FLAG_INITIALIZER(x)
90#endif
91
adamdunkelsb27d85a2003-09-01 22:23:26 +000092/**
adamdunkelse937ded2003-10-01 07:53:57 +000093 * \defgroup ctkappfunc CTK application functions
94 * @{
95 *
96 * The CTK functions used by an application program.
97 */
98
99/**
adamdunkelsb27d85a2003-09-01 22:23:26 +0000100 * Instantiating macro for the ctk_separator widget.
101 *
102 * This macro is used when instantiating a ctk_separator widget and is
103 * intended to be used together with a struct assignment like this:
104 \code
105 struct ctk_separator sep =
106 {CTK_SEPARATOR(0, 0, 23)};
107 \endcode
adamdunkelsb27d85a2003-09-01 22:23:26 +0000108 * \param x The x position of the widget, relative to the widget's
109 * window.
110 * \param y The y position of the widget, relative to the widget's
111 * window.
adamdunkelse937ded2003-10-01 07:53:57 +0000112 * \param w The widget's width.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000113 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000114#define CTK_SEPARATOR(x, y, w) \
adamdunkels1f9a9a12004-07-04 11:42:47 +0000115 NULL, NULL, x, y, CTK_WIDGET_SEPARATOR, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000116struct ctk_separator {
117 struct ctk_widget *next;
118 struct ctk_window *window;
119 unsigned char x, y;
120 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000121 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000122#if CTK_CONF_WIDGET_FLAGS
123 unsigned char flags;
124#endif /* CTK_CONF_WIDGET_FLAGS */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000125};
126
adamdunkelsb27d85a2003-09-01 22:23:26 +0000127/**
128 * Instantiating macro for the ctk_button widget.
129 *
130 * This macro is used when instantiating a ctk_button widget and is
131 * intended to be used together with a struct assignment like this:
132 \code
133 struct ctk_button but =
134 {CTK_BUTTON(0, 0, 2, "Ok")};
135 \endcode
adamdunkelsb27d85a2003-09-01 22:23:26 +0000136 * \param x The x position of the widget, relative to the widget's
137 * window.
138 * \param y The y position of the widget, relative to the widget's
139 * window.
adamdunkelse937ded2003-10-01 07:53:57 +0000140 * \param w The widget's width.
141 * \param text The button text.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000142 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000143#define CTK_BUTTON(x, y, w, text) \
adamdunkels1f9a9a12004-07-04 11:42:47 +0000144 NULL, NULL, x, y, CTK_WIDGET_BUTTON, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000145struct ctk_button {
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;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000151#if CTK_CONF_WIDGET_FLAGS
152 unsigned char flags;
153#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200154 const char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000155};
156
adamdunkelsb27d85a2003-09-01 22:23:26 +0000157/**
158 * Instantiating macro for the ctk_label widget.
159 *
160 * This macro is used when instantiating a ctk_label widget and is
161 * intended to be used together with a struct assignment like this:
162 \code
163 struct ctk_label lab =
164 {CTK_LABEL(0, 0, 5, 1, "Label")};
165 \endcode
adamdunkelsb27d85a2003-09-01 22:23:26 +0000166 * \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.
adamdunkelse937ded2003-10-01 07:53:57 +0000170 * \param w The widget's width.
171 * \param h The height of the label.
172 * \param text The label text.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000173 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000174#define CTK_LABEL(x, y, w, h, text) \
adamdunkels1f9a9a12004-07-04 11:42:47 +0000175 NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000176struct ctk_label {
177 struct ctk_widget *next;
178 struct ctk_window *window;
179 unsigned char x, y;
180 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000181 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000182#if CTK_CONF_WIDGET_FLAGS
183 unsigned char flags;
184#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200185 const char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000186};
187
adamdunkelsb27d85a2003-09-01 22:23:26 +0000188/**
189 * Instantiating macro for the ctk_hyperlink widget.
190 *
191 * This macro is used when instantiating a ctk_hyperlink widget and is
192 * intended to be used together with a struct assignment like this:
193 \code
194 struct ctk_hyperlink hlink =
195 {CTK_HYPERLINK(0, 0, 7, "Contiki", "http://dunkels.com/adam/contiki/")};
196 \endcode
adamdunkelsb27d85a2003-09-01 22:23:26 +0000197 * \param x The x position of the widget, relative to the widget's
198 * window.
199 * \param y The y position of the widget, relative to the widget's
200 * window.
adamdunkelse937ded2003-10-01 07:53:57 +0000201 * \param w The widget's width.
202 * \param text The hyperlink text.
203 * \param url The hyperlink URL.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000204 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000205#define CTK_HYPERLINK(x, y, w, text, url) \
adamdunkels1f9a9a12004-07-04 11:42:47 +0000206 NULL, NULL, x, y, CTK_WIDGET_HYPERLINK, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, url
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000207struct ctk_hyperlink {
208 struct ctk_widget *next;
209 struct ctk_window *window;
210 unsigned char x, y;
211 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000212 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000213#if CTK_CONF_WIDGET_FLAGS
214 unsigned char flags;
215#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200216 const char *text;
217 const char *url;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000218};
219
220/* Editing modes of the CTK textentry widget. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000221#define CTK_TEXTENTRY_NORMAL 0 /**< \internal Textentry state: not
222 edited. */
223#define CTK_TEXTENTRY_EDIT 1 /**< \internal Textentry state:
224 currenly being edited. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000225
adamdunkelsb27d85a2003-09-01 22:23:26 +0000226/**
227 * Clears a text entry widget and sets the cursor to the start of the
228 * text line.
229 *
230 * \param e The text entry widget to be cleared.
231 */
oliverschmidtcd6c30b2005-05-05 20:54:16 +0000232#define CTK_TEXTENTRY_CLEAR(e) \
233 do { memset((e)->text, 0, (e)->h * ((e)->len + 1)); \
234 (e)->xpos = 0; (e)->ypos = 0; } while(0)
oliverschmidt0096f6a2005-05-04 21:50:17 +0000235
236typedef unsigned char (* ctk_textentry_input)(ctk_arch_key_t c,
237 struct ctk_textentry *t);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000238
adamdunkelsb27d85a2003-09-01 22:23:26 +0000239/**
240 * Instantiating macro for the ctk_textentry widget.
241 *
242 * This macro is used when instantiating a ctk_textentry widget and is
243 * intended to be used together with a struct assignment like this:
244 \code
245 struct ctk_textentry tentry =
246 {CTK_TEXTENTRY(0, 0, 30, 1, textbuffer, 50)};
247 \endcode
248 * \note The height of the text entry widget is obsolete and not
249 * intended to be used.
250 *
adamdunkelsb27d85a2003-09-01 22:23:26 +0000251 * \param x The x position of the widget, relative to the widget's
252 * window.
253 * \param y The y position of the widget, relative to the widget's
254 * window.
adamdunkelse937ded2003-10-01 07:53:57 +0000255 * \param w The widget's width.
256 * \param h The text entry height (obsolete).
257 * \param text A pointer to the buffer that should be edited.
258 * \param len The length of the text buffer
adamdunkelsb27d85a2003-09-01 22:23:26 +0000259 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000260#define CTK_TEXTENTRY(x, y, w, h, text, len) \
adamdunkels1f9a9a12004-07-04 11:42:47 +0000261 NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
oliverschmidt0096f6a2005-05-04 21:50:17 +0000262 CTK_TEXTENTRY_NORMAL, 0, 0, NULL
263#define CTK_TEXTENTRY_INPUT(x, y, w, h, text, len, input) \
264 NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
265 CTK_TEXTENTRY_NORMAL, 0, 0, (ctk_textentry_input)input
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000266struct ctk_textentry {
267 struct ctk_widget *next;
268 struct ctk_window *window;
269 unsigned char x, y;
270 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000271 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000272#if CTK_CONF_WIDGET_FLAGS
273 unsigned char flags;
274#endif /* CTK_CONF_WIDGET_FLAGS */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000275 char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000276 unsigned char len;
277 unsigned char state;
278 unsigned char xpos, ypos;
oliverschmidt0096f6a2005-05-04 21:50:17 +0000279 ctk_textentry_input input;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000280};
281
282
oliverschmidt84b30842004-06-27 12:32:16 +0000283#if CTK_CONF_ICON_BITMAPS
284#define CTK_ICON_BITMAP(bitmap) bitmap
285#else
286#define CTK_ICON_BITMAP(bitmap) NULL
287#endif
288
289#if CTK_CONF_ICON_TEXTMAPS
290#define CTK_ICON_TEXTMAP(textmap) textmap
291#else
292#define CTK_ICON_TEXTMAP(textmap) NULL
293#endif
294
adamdunkelsb27d85a2003-09-01 22:23:26 +0000295/**
296 * Instantiating macro for the ctk_icon widget.
297 *
298 * This macro is used when instantiating a ctk_icon widget and is
299 * intended to be used together with a struct assignment like this:
300 \code
301 struct ctk_icon icon =
302 {CTK_ICON("An icon", bitmapptr, textmapptr)};
303 \endcode
304 * \param title The icon's text.
305 * \param bitmap A pointer to the icon's bitmap image.
306 * \param textmap A pointer to the icon's text version of the bitmap.
307 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000308#define CTK_ICON(title, bitmap, textmap) \
adamdunkels1f9a9a12004-07-04 11:42:47 +0000309 NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, 4, CTK_WIDGET_FLAG_INITIALIZER(0) \
310 title, EK_ID_NONE, \
oliverschmidt84b30842004-06-27 12:32:16 +0000311 CTK_ICON_BITMAP(bitmap), CTK_ICON_TEXTMAP(textmap)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000312struct ctk_icon {
313 struct ctk_widget *next;
314 struct ctk_window *window;
315 unsigned char x, y;
316 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000317 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000318#if CTK_CONF_WIDGET_FLAGS
319 unsigned char flags;
320#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200321 const char *title;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000322 ek_id_t owner;
Adrien Destugues69a6e722017-06-03 10:17:17 +0200323 const unsigned char *bitmap;
324 const char *textmap;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000325};
326
adamdunkels3eac04f2004-09-12 07:22:39 +0000327#define CTK_BITMAP(x, y, w, h, bitmap, bitmap_width, bitmap_height) \
328 NULL, NULL, x, y, CTK_WIDGET_BITMAP, w, h, \
329 CTK_WIDGET_FLAG_INITIALIZER(0) bitmap, bitmap_width, bitmap_height
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000330struct ctk_bitmap {
331 struct ctk_widget *next;
332 struct ctk_window *window;
333 unsigned char x, y;
334 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000335 unsigned char w, h;
adamdunkels3eac04f2004-09-12 07:22:39 +0000336#if CTK_CONF_WIDGET_FLAGS
337 unsigned char flags;
338#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200339 const unsigned char *bitmap;
adamdunkels3eac04f2004-09-12 07:22:39 +0000340 unsigned short bw, bh;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000341};
342
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000343#define CTK_TEXTMAP_NORMAL 0
344#define CTK_TEXTMAP_ACTIVE 1
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000345
adamdunkels1f9a9a12004-07-04 11:42:47 +0000346#define CTK_TEXTMAP(x, y, w, h, textmap) \
347 NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, CTK_TEXTMAP_NORMAL
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000348struct ctk_textmap {
349 struct ctk_widget *next;
350 struct ctk_window *window;
351 unsigned char x, y;
352 unsigned char type;
353 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000354#if CTK_CONF_WIDGET_FLAGS
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000355 unsigned char flags;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000356#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200357 const char *textmap;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000358 unsigned char state;
359};
360
adamdunkels1f9a9a12004-07-04 11:42:47 +0000361
adamdunkelsb27d85a2003-09-01 22:23:26 +0000362/**
363 * \internal The CTK button widget structure.
364 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000365struct ctk_widget_button {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200366 const char *text; /**< The button text. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000367};
368
adamdunkelsb27d85a2003-09-01 22:23:26 +0000369/**
370 * \internal The CTK label widget structure.
371 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000372struct ctk_widget_label {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200373 const char *text; /**< The label text. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000374};
375
adamdunkelsb27d85a2003-09-01 22:23:26 +0000376/**
377 * \internal The CTK hyperlink widget structure.
378 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000379struct ctk_widget_hyperlink {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200380 const char *text; /**< The text of the hyperlink. */
381 const char *url; /**< The hyperlink's URL. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000382};
383
384struct ctk_widget_textentry {
385 char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000386 unsigned char len;
387 unsigned char state;
388 unsigned char xpos, ypos;
oliverschmidt0096f6a2005-05-04 21:50:17 +0000389 ctk_textentry_input input;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000390};
391
392struct ctk_widget_icon {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200393 const char *title;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000394 ek_id_t owner;
Adrien Destugues69a6e722017-06-03 10:17:17 +0200395 const unsigned char *bitmap;
396 const char *textmap;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000397};
398
399struct ctk_widget_bitmap {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200400 const unsigned char *bitmap;
adamdunkels3eac04f2004-09-12 07:22:39 +0000401 unsigned short bw, bh;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000402};
adamdunkelse937ded2003-10-01 07:53:57 +0000403/** @} */
404
405/**
406 * \addtogroup ctkdraw
407 * @{
408 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000409
adamdunkelsb27d85a2003-09-01 22:23:26 +0000410/**
411 * The generic CTK widget structure that contains all other widget
412 * structures.
413 *
414 * Since the widgets of a window are arranged on a linked list, the
415 * widget structure contains a next pointer which is used for this
416 * purpose. The widget structure also contains the placement and the
417 * size of the widget.
418 *
419 * Finally, the actual per-widget structure is contained in this
420 * top-level widget structure.
421 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000422struct ctk_widget {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000423 struct ctk_widget *next; /**< The next widget in the linked list
424 of widgets that is contained in the
425 ctk_window structure. */
426 struct ctk_window *window; /**< The window in which the widget is
427 contained. */
428 unsigned char x, /**< The x position of the widget within
429 the containing window, in character
430 coordinates. */
431 y; /**< The y position of the widget within
432 the containing window, in character
433 coordinates. */
434 unsigned char type; /**< The type of the widget:
435 CTK_WIDGET_SEPARATOR,
436 CTK_WIDGET_LABEL, CTK_WIDGET_BUTTON,
437 CTK_WIDGET_HYPERLINK,
438 CTK_WIDGET_TEXTENTRY,
439 CTK_WIDGET_BITMAP or
440 CTK_WIDGET_ICON. */
441 unsigned char w, /**< The width of the widget in character
442 coordinates. */
443 h; /**< The height of the widget in
444 character coordinates. */
adamdunkels1f9a9a12004-07-04 11:42:47 +0000445#if CTK_CONF_WIDGET_FLAGS
446 unsigned char flags;
447#endif /* CTK_CONF_WIDGET_FLAGS */
448
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000449 union {
450 struct ctk_widget_label label;
451 struct ctk_widget_button button;
452 struct ctk_widget_hyperlink hyperlink;
453 struct ctk_widget_textentry textentry;
454 struct ctk_widget_icon icon;
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000455 struct ctk_widget_bitmap bitmap;
adamdunkelsb27d85a2003-09-01 22:23:26 +0000456 } widget; /**< The union which contains the actual
457 widget structure, as determined by the
458 type field. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000459};
460
adamdunkelse937ded2003-10-01 07:53:57 +0000461
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000462struct ctk_desktop;
463
adamdunkels1f9a9a12004-07-04 11:42:47 +0000464#define CTK_WIDGET_FLAG_NONE 0
465#define CTK_WIDGET_FLAG_MONOSPACE 1
466#define CTK_WIDGET_FLAG_CENTER 2
467
468#if CTK_CONF_WIDGET_FLAGS
469#define CTK_WIDGET_SET_FLAG(w, f) ((struct ctk_widget *)(w))->flags = (f)
470#else /* CTK_CONF_WIDGET_FLAGS */
471#define CTK_WIDGET_SET_FLAG(w, f)
472#endif /* CTK_CONF_WIDGET_FLAGS */
473
adamdunkelsb27d85a2003-09-01 22:23:26 +0000474/**
adamdunkelse937ded2003-10-01 07:53:57 +0000475 * Representation of a CTK window.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000476 *
477 * For the CTK, each window is repessented by a ctk_window
478 * structure. All open windows are kept on a doubly linked list,
479 * linked by the next and prev fields in the ctk_window struct. The
480 * window structure holds all widgets that is contained in the window
481 * as well as a pointer to the currently selected widget.
482 *
483 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000484struct ctk_window {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000485 struct ctk_window *next, /**< The next window in the doubly linked
486 list of open windows. */
487
488 *prev; /**< The previous window in the doubly
489 linked list of open windows. */
490 struct ctk_desktop *desktop;/**< The desktop on which this window is
491 open. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000492
adamdunkelsb27d85a2003-09-01 22:23:26 +0000493 ek_id_t owner; /**< The process that owns the
494 window. This process will be the
495 receiver of all CTK signals that
496 pertain to this window. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000497
Adrien Destugues69a6e722017-06-03 10:17:17 +0200498 const char *title; /**< The title of the window. Used for
adamdunkelsb27d85a2003-09-01 22:23:26 +0000499 constructing the "Dekstop" menu. */
500 unsigned char titlelen; /**< The length of the title, cached for
501 speed reasons. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000502
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000503#if CTK_CONF_WINDOWCLOSE
adamdunkelsb27d85a2003-09-01 22:23:26 +0000504 struct ctk_button closebutton; /**< The closebutton. This is also
505 present in the list of active
506 widgets. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000507#else /* CTK_CONF_WINDOWCLOSE */
508 struct ctk_label closebutton;
509#endif /* CTK_CONF_WINDOWCLOSE */
510
511#if CTK_CONF_WINDOWMOVE
adamdunkelsb27d85a2003-09-01 22:23:26 +0000512 struct ctk_button titlebutton;/**< The titlebutton which is used for
513 moving the window. This is also
514 present in the list of active
515 widgets. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000516#else /* CTK_CONF_WINDOWMOVE */
517 struct ctk_label titlebutton;
518#endif /* CTK_CONF_WINDOWMOVE */
519
adamdunkelsb27d85a2003-09-01 22:23:26 +0000520 unsigned char x, /**< The x coordinate of the window, in
521 characters. */
522 y; /**< The y coordinate of the window, in
523 characters. */
524 unsigned char w, /**< The width of the window, excluding
525 window borders. */
526 h; /**< The height of the window,
527 excluding window borders. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000528
529
adamdunkelsb27d85a2003-09-01 22:23:26 +0000530 struct ctk_widget *inactive; /**< The list if widgets that cannot be
531 selected by the user. Labels and
532 separator widgets are placed on this
533 list. */
534 struct ctk_widget *active; /**< The list of widgets that can be
535 selected by the user. Buttons,
536 hyperlinks, text entry fields, etc.,
537 are placed on this list. */
538 struct ctk_widget *focused; /**< A pointer to the widget on the
539 active list that is currently
540 selected, or NULL if no widget is
541 selected. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000542};
543
adamdunkelsb27d85a2003-09-01 22:23:26 +0000544/**
adamdunkelse937ded2003-10-01 07:53:57 +0000545 * Representation of an individual menu item.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000546 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000547struct ctk_menuitem {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200548 const char *title; /**< The menu items text. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000549 unsigned char titlelen;/**< The length of the item text, cached for
550 speed. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000551};
552
adamdunkelsb27d85a2003-09-01 22:23:26 +0000553/**
adamdunkelse937ded2003-10-01 07:53:57 +0000554 * Representation of an individual menu.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000555 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000556struct ctk_menu {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000557 struct ctk_menu *next; /**< Apointer to the next menu, or is NULL if
558 this is the last menu, and should be used
559 by the ctk-draw module when stepping
560 through the menus when drawing them on
561 screen. */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200562 const char *title; /**< The menu title. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000563 unsigned char titlelen;/**< The length of the title in
564 characters. Cached for speed reasons. */
adamdunkels78c03dc2003-04-09 13:45:05 +0000565#if CC_UNSIGNED_CHAR_BUGS
adamdunkels6ccf7212003-04-10 07:04:45 +0000566 unsigned int nitems;
567 unsigned int active;
adamdunkels78c03dc2003-04-09 13:45:05 +0000568#else /* CC_UNSIGNED_CHAR_BUGS */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000569 unsigned char nitems; /**< The total number of menu items in the
570 menu. */
571 unsigned char active; /**< The currently active menu item. */
adamdunkels78c03dc2003-04-09 13:45:05 +0000572#endif /* CC_UNSIGNED_CHAR_BUGS */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000573 struct ctk_menuitem items[CTK_CONF_MAXMENUITEMS];
adamdunkelsb27d85a2003-09-01 22:23:26 +0000574 /**< The array which contains all the menu
575 items. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000576};
577
adamdunkelsb27d85a2003-09-01 22:23:26 +0000578/**
adamdunkelse937ded2003-10-01 07:53:57 +0000579 * Representation of the menu bar.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000580 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000581struct ctk_menus {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000582 struct ctk_menu *menus; /**< A pointer to a linked list of all
583 menus, including the open menu and
584 the desktop menu.*/
585 struct ctk_menu *open; /**< The currently open menu, if
586 any. If all menus are closed, this
587 item is NULL: */
588 struct ctk_menu *desktopmenu; /**< A pointer to the "Desktop" menu
589 that can be used for drawing the
590 desktop menu in a special way (such
591 as drawing it at the rightmost
592 position). */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000593};
594
adamdunkelse937ded2003-10-01 07:53:57 +0000595/** @} */
596
597
adamdunkelsb27d85a2003-09-01 22:23:26 +0000598/**
599 * \internal The structure describing a Contiki desktop.
600 */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000601struct ctk_desktop {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200602 const char *name; /**< The name of the desktop. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000603
604 struct ctk_window desktop_window; /**< The background window which
605 contains tha desktop icons. */
606 struct ctk_window *windows; /**< The list of open windows. */
607 struct ctk_window *dialog; /**< A pointer to the open dialog, or
608 NULL if no dialog is open. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000609
610#if CTK_CONF_MENUS
adamdunkelsb27d85a2003-09-01 22:23:26 +0000611 struct ctk_menus menus; /**< The list of desktop menus. */
612 struct ctk_menu *lastmenu; /**< Pointer to the menu that was last open. */
613 struct ctk_menu desktopmenu;/**< The desktop menu. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000614#endif /* CTK_CONF_MENUS */
615
adamdunkelsb27d85a2003-09-01 22:23:26 +0000616 unsigned char height, /**< The height of the desktop, in characters. */
617 width; /**< The width of the desktop, in characters. */
618
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000619
adamdunkelsb27d85a2003-09-01 22:23:26 +0000620#define CTK_REDRAW_NONE 0 /**< \internal Redraw flag: nothing
621 to be redrawn. */
622#define CTK_REDRAW_ALL 1 /**< \internal Redraw flag:
623 everything should be redrawn. */
624#define CTK_REDRAW_WINDOWS 2 /**< \internal Redraw flag: redraw
625 windows in queue.*/
626#define CTK_REDRAW_WIDGETS 4 /**< \internal Redraw flag: redraw
627 widgets in queue. */
628#define CTK_REDRAW_MENUS 8 /**< \internal Redraw flag: redraw
629 menus. */
630#define CTK_REDRAW_PART 16 /**< \internal Redraw flag: redraw
631 parts of the desktop. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000632
633#ifndef CTK_CONF_MAX_REDRAWWIDGETS
634#define CTK_CONF_MAX_REDRAWWIDGETS 8
635#endif /* CTK_CONF_MAX_REDRAWWIDGETS */
636#ifndef CTK_CONF_MAX_REDRAWWINDOWS
637#define CTK_CONF_MAX_REDRAWWINDOWS 8
638#endif /* CTK_CONF_MAX_REDRAWWINDOWS */
639
adamdunkelsb27d85a2003-09-01 22:23:26 +0000640 unsigned char redraw; /**< The redraw flag. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000641
adamdunkelsb27d85a2003-09-01 22:23:26 +0000642 struct ctk_widget *redraw_widgets[CTK_CONF_MAX_REDRAWWIDGETS]; /**< The list of widgets to be redrawn. */
643 unsigned char redraw_widgetptr; /**< Pointer to the last widget on the redraw_widgets list. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000644
adamdunkelsb27d85a2003-09-01 22:23:26 +0000645 struct ctk_window *redraw_windows[CTK_CONF_MAX_REDRAWWINDOWS]; /**< The list of windows to be redrawn. */
646 unsigned char redraw_windowptr; /**< Pointer to the last window on the redraw_windows list. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000647
adamdunkelsb27d85a2003-09-01 22:23:26 +0000648 unsigned char redraw_y1, /**< The lower y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
649 redraw_y2; /**< The upper y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000650};
651
652
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000653/* Global CTK modes. */
654#define CTK_MODE_NORMAL 0
655#define CTK_MODE_WINDOWMOVE 1
656#define CTK_MODE_SCREENSAVER 2
657#define CTK_MODE_EXTERNAL 3
658
659/* General ctk functions. */
660void ctk_init(void);
adamdunkels28ad2b32004-08-09 20:30:50 +0000661void ctk_restore(void);
662
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000663void ctk_mode_set(unsigned char mode);
664unsigned char ctk_mode_get(void);
adamdunkels9795b2e2003-08-09 23:32:37 +0000665/*void ctk_redraw(void);*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000666
667/* Functions for manipulating windows. */
668void ctk_window_new(struct ctk_window *window,
669 unsigned char w, unsigned char h,
Adrien Destugues69a6e722017-06-03 10:17:17 +0200670 const char *title);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000671void ctk_window_clear(struct ctk_window *w);
672void ctk_window_open(struct ctk_window *w);
oliverschmidtcd6c30b2005-05-05 20:54:16 +0000673#define ctk_window_move(w,xpos,ypos) do { (w)->x=xpos; (w)->y=ypos; } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000674void ctk_window_close(struct ctk_window *w);
675void ctk_window_redraw(struct ctk_window *w);
676#define ctk_window_isopen(w) ((w)->next != NULL)
677
678
679/* Functions for manipulating dialogs. */
680void ctk_dialog_new(struct ctk_window *window,
681 unsigned char w, unsigned char h);
682void ctk_dialog_open(struct ctk_window *d);
683void ctk_dialog_close(void);
684
685/* Functions for manipulating menus. */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200686void ctk_menu_new(struct ctk_menu *menu, const char *title);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000687void ctk_menu_add(struct ctk_menu *menu);
688void ctk_menu_remove(struct ctk_menu *menu);
Adrien Destugues69a6e722017-06-03 10:17:17 +0200689unsigned char ctk_menuitem_add(struct ctk_menu *menu, const char *name);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000690
691/* Functions for icons. */
adamdunkelse937ded2003-10-01 07:53:57 +0000692
693/**
694 * \addtogroup ctkappfunc
695 * @{
696 */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000697/**
698 * Add an icon to the desktop.
699 *
700 * \param icon The icon to be added.
adamdunkels0404ef12003-09-04 19:36:04 +0000701 *
702 * \param id The process ID of the process that owns the icon.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000703 */
adamdunkels0404ef12003-09-04 19:36:04 +0000704#define CTK_ICON_ADD(icon, id) ctk_icon_add((struct ctk_widget *)icon, id)
705void ctk_icon_add(struct ctk_widget *icon, ek_id_t id);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000706
707/* Functions for manipulating widgets. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000708
709/**
710 * Add a widget to a window.
711 *
712 * \param win The window to which the widget should be added.
713 * \param widg The widget to be added.
714 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000715#define CTK_WIDGET_ADD(win, widg) \
716 ctk_widget_add(win, (struct ctk_widget *)widg)
adamdunkelsa6557e42003-08-11 22:27:51 +0000717void CC_FASTCALL ctk_widget_add(struct ctk_window *window,
718 struct ctk_widget *widget);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000719
adamdunkelsb27d85a2003-09-01 22:23:26 +0000720/**
721 * Set focus to a widget.
722 *
723 * \param win The widget's window.
724 * \param widg The widget
725 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000726#define CTK_WIDGET_FOCUS(win, widg) \
727 (win)->focused = (struct ctk_widget *)(widg)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000728
729/**
730 * Add a widget to the redraw queue.
731 *
732 * \param widg The widget to be redrawn.
733 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000734#define CTK_WIDGET_REDRAW(widg) \
735 ctk_widget_redraw((struct ctk_widget *)widg)
736void ctk_widget_redraw(struct ctk_widget *w);
737
adamdunkelsb27d85a2003-09-01 22:23:26 +0000738/**
739 * Obtain the type of a widget.
740 *
741 * \param w The widget.
742 */
adamdunkels3a08a492003-04-11 20:16:02 +0000743#define CTK_WIDGET_TYPE(w) ((w)->type)
744
adamdunkelse8b21d02003-04-24 17:18:27 +0000745
adamdunkelsb27d85a2003-09-01 22:23:26 +0000746/**
747 * Sets the width of a widget.
748 *
749 * \param widget The widget.
750 * \param width The width of the widget, in characters.
751 */
adamdunkelse8b21d02003-04-24 17:18:27 +0000752#define CTK_WIDGET_SET_WIDTH(widget, width) do { \
753 ((struct ctk_widget *)(widget))->w = (width); } while(0)
754
adamdunkelsb27d85a2003-09-01 22:23:26 +0000755/**
756 * Retrieves the x position of a widget, relative to the window in
757 * which the widget is contained.
758 *
759 * \param w The widget.
760 * \return The x position of the widget.
761 */
adamdunkelse8b21d02003-04-24 17:18:27 +0000762#define CTK_WIDGET_XPOS(w) (((struct ctk_widget *)(w))->x)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000763
764/**
765 * Sets the x position of a widget, relative to the window in
766 * which the widget is contained.
767 *
768 * \param w The widget.
769 * \param xpos The x position of the widget.
770 */
771#define CTK_WIDGET_SET_XPOS(w, xpos) \
772 ((struct ctk_widget *)(w))->x = (xpos)
773/**
774 * Retrieves the y position of a widget, relative to the window in
775 * which the widget is contained.
776 *
777 * \param w The widget.
778 * \return The y position of the widget.
779 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000780#define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
781
adamdunkelsb27d85a2003-09-01 22:23:26 +0000782/**
783 * Sets the y position of a widget, relative to the window in
784 * which the widget is contained.
785 *
786 * \param w The widget.
787 * \param ypos The y position of the widget.
788 */
789#define CTK_WIDGET_SET_YPOS(w, ypos) \
790 ((struct ctk_widget *)(w))->y = (ypos)
791
792/* XXX: should be removed.
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000793#define ctk_textentry_set_height(w, height) \
794 (w)->widget.textentry.h = (height)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000795*/
796
797/** \def ctk_label_set_height(w, height)
798 * \brief Set the height of a label.
799 *
800 * \param w The CTK label widget.
801 * \param height The new height of the label.
802 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000803#define ctk_label_set_height(w, height) \
804 (w)->widget.label.h = (height)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000805
806/**
807 * Set the text of a label.
808 *
809 * \param l The CTK label widget.
810 * \param t The new text of the label.
811 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000812#define ctk_label_set_text(l, t) (l)->text = (t)
813
adamdunkelsb27d85a2003-09-01 22:23:26 +0000814/**
815 * Set the text of a button.
816 *
817 * \param b The CTK button widget.
818 * \param t The new text of the button.
819 */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000820#define ctk_button_set_text(b, t) (b)->text = (t)
821
adamdunkels58917a82003-04-18 00:18:38 +0000822#define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m)
823
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000824#define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000825 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000826 (widg)->next = NULL; \
827 (widg)->type = CTK_WIDGET_BUTTON; \
828 (widg)->x = (xpos); \
829 (widg)->y = (ypos); \
830 (widg)->w = (width); \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000831 (widg)->h = 1; \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000832 (widg)->text = (buttontext); \
833 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000834
835#define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000836 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000837 (widg)->next = NULL; \
838 (widg)->type = CTK_WIDGET_LABEL; \
839 (widg)->x = (xpos); \
840 (widg)->y = (ypos); \
841 (widg)->w = (width); \
842 (widg)->h = (height); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000843 (widg)->text = (labeltext); \
844 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000845
adamdunkels58917a82003-04-18 00:18:38 +0000846#define CTK_BITMAP_NEW(widg, xpos, ypos, width, height, bmap) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000847 do { (widg)->window = NULL; \
adamdunkels58917a82003-04-18 00:18:38 +0000848 (widg)->next = NULL; \
849 (widg)->type = CTK_WIDGET_BITMAP; \
850 (widg)->x = (xpos); \
851 (widg)->y = (ypos); \
852 (widg)->w = (width); \
853 (widg)->h = (height); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000854 (widg)->bitmap = (bmap); \
855 } while(0)
adamdunkels58917a82003-04-18 00:18:38 +0000856
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000857#define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000858 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000859 (widg)->next = NULL; \
860 (widg)->type = CTK_WIDGET_TEXTENTRY; \
861 (widg)->x = (xxpos); \
862 (widg)->y = (yypos); \
863 (widg)->w = (width); \
oliverschmidt0096f6a2005-05-04 21:50:17 +0000864 (widg)->h = 1; \
865 (widg)->text = (textptr); \
866 (widg)->len = (textlen); \
867 (widg)->state = CTK_TEXTENTRY_NORMAL; \
868 (widg)->xpos = 0; \
869 (widg)->ypos = 0; \
870 (widg)->input = NULL; \
871 } while(0)
872
873#define CTK_TEXTENTRY_INPUT_NEW(widg, xxpos, yypos, width, height, textptr, textlen, iinput) \
874 do { (widg)->window = NULL; \
875 (widg)->next = NULL; \
876 (widg)->type = CTK_WIDGET_TEXTENTRY; \
877 (widg)->x = (xxpos); \
878 (widg)->y = (yypos); \
879 (widg)->w = (width); \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000880 (widg)->h = (height); \
881 (widg)->text = (textptr); \
882 (widg)->len = (textlen); \
883 (widg)->state = CTK_TEXTENTRY_NORMAL; \
884 (widg)->xpos = 0; \
adamdunkels28ad2b32004-08-09 20:30:50 +0000885 (widg)->ypos = 0; \
oliverschmidt0096f6a2005-05-04 21:50:17 +0000886 (widg)->input = (ctk_textentry_input)(iinput); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000887 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000888
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000889#define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000890 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000891 (widg)->next = NULL; \
892 (widg)->type = CTK_WIDGET_HYPERLINK; \
893 (widg)->x = (xpos); \
894 (widg)->y = (ypos); \
895 (widg)->w = (width); \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000896 (widg)->h = 1; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000897 (widg)->text = (linktext); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000898 (widg)->url = (linkurl); \
899 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000900
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000901/* Desktop interface. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000902void ctk_desktop_redraw(struct ctk_desktop *d);
903unsigned char ctk_desktop_width(struct ctk_desktop *d);
904unsigned char ctk_desktop_height(struct ctk_desktop *d);
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000905
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000906/* Signals. */
adamdunkels1f9a9a12004-07-04 11:42:47 +0000907extern ek_event_t ctk_signal_keypress,
adamdunkels3a08a492003-04-11 20:16:02 +0000908 ctk_signal_widget_activate,
909 ctk_signal_widget_select,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000910 ctk_signal_timer,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000911 ctk_signal_menu_activate,
adamdunkelsc4902862003-04-09 00:30:45 +0000912 ctk_signal_window_close,
913 ctk_signal_pointer_move,
adamdunkels3a08a492003-04-11 20:16:02 +0000914 ctk_signal_pointer_button;
915
adamdunkelse8b21d02003-04-24 17:18:27 +0000916#if CTK_CONF_SCREENSAVER
adamdunkels1f9a9a12004-07-04 11:42:47 +0000917extern ek_event_t ctk_signal_screensaver_stop,
adamdunkels9795b2e2003-08-09 23:32:37 +0000918 ctk_signal_screensaver_start;
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000919
920extern unsigned short ctk_screensaver_timeout;
adamdunkelsb27d85a2003-09-01 22:23:26 +0000921/**
922 * Set the screensaver timeout, in seconds.
923 *
924 * \param t The timeout in seconds.
925 */
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000926#define CTK_SCREENSAVER_SET_TIMEOUT(t) ctk_screensaver_timeout = (t)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000927/**
928 * Obtain the screensaver timeout, in seconds.
929 *
930 * \raturn The timeout in seconds.
931 */
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000932#define CTK_SCREENSAVER_TIMEOUT() ctk_screensaver_timeout
adamdunkelse8b21d02003-04-24 17:18:27 +0000933#endif /* CTK_CONF_SCREENSAVER */
934
adamdunkels3a08a492003-04-11 20:16:02 +0000935/* These should no longer be used: */
adamdunkels1f9a9a12004-07-04 11:42:47 +0000936extern ek_event_t ctk_signal_button_activate,
adamdunkels3a08a492003-04-11 20:16:02 +0000937 ctk_signal_button_hover,
938 ctk_signal_hyperlink_activate,
939 ctk_signal_hyperlink_hover;
adamdunkelse937ded2003-10-01 07:53:57 +0000940/** @} */
941
942/**
943 * \addtogroup ctkdraw
944 * @{
945 */
adamdunkels3a08a492003-04-11 20:16:02 +0000946
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000947/* Focus flags */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000948/** Widget focus flag: no focus. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000949#define CTK_FOCUS_NONE 0
adamdunkelsb27d85a2003-09-01 22:23:26 +0000950/** Widget focus flag: widget has focus. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000951#define CTK_FOCUS_WIDGET 1
adamdunkelsb27d85a2003-09-01 22:23:26 +0000952/** Widget focus flag: widget's window is the foremost one. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000953#define CTK_FOCUS_WINDOW 2
adamdunkelsb27d85a2003-09-01 22:23:26 +0000954/** Widget focus flag: widget is in a dialog. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000955#define CTK_FOCUS_DIALOG 4
956
adamdunkelse937ded2003-10-01 07:53:57 +0000957/** @} */
958/** @} */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000959#endif /* __CTK_H__ */