blob: 6c25356f71292c231e4c2838303b947a6cf1d472 [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
Adrien Destugues47867802017-06-05 13:43:16 +0200236struct ctk_textentry;
oliverschmidt0096f6a2005-05-04 21:50:17 +0000237typedef unsigned char (* ctk_textentry_input)(ctk_arch_key_t c,
238 struct ctk_textentry *t);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000239
adamdunkelsb27d85a2003-09-01 22:23:26 +0000240/**
241 * Instantiating macro for the ctk_textentry widget.
242 *
243 * This macro is used when instantiating a ctk_textentry widget and is
244 * intended to be used together with a struct assignment like this:
245 \code
246 struct ctk_textentry tentry =
247 {CTK_TEXTENTRY(0, 0, 30, 1, textbuffer, 50)};
248 \endcode
249 * \note The height of the text entry widget is obsolete and not
250 * intended to be used.
251 *
adamdunkelsb27d85a2003-09-01 22:23:26 +0000252 * \param x The x position of the widget, relative to the widget's
253 * window.
254 * \param y The y position of the widget, relative to the widget's
255 * window.
adamdunkelse937ded2003-10-01 07:53:57 +0000256 * \param w The widget's width.
257 * \param h The text entry height (obsolete).
258 * \param text A pointer to the buffer that should be edited.
259 * \param len The length of the text buffer
adamdunkelsb27d85a2003-09-01 22:23:26 +0000260 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000261#define CTK_TEXTENTRY(x, y, w, h, text, len) \
adamdunkels1f9a9a12004-07-04 11:42:47 +0000262 NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
oliverschmidt0096f6a2005-05-04 21:50:17 +0000263 CTK_TEXTENTRY_NORMAL, 0, 0, NULL
264#define CTK_TEXTENTRY_INPUT(x, y, w, h, text, len, input) \
265 NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
266 CTK_TEXTENTRY_NORMAL, 0, 0, (ctk_textentry_input)input
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000267struct ctk_textentry {
268 struct ctk_widget *next;
269 struct ctk_window *window;
270 unsigned char x, y;
271 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000272 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000273#if CTK_CONF_WIDGET_FLAGS
274 unsigned char flags;
275#endif /* CTK_CONF_WIDGET_FLAGS */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000276 char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000277 unsigned char len;
278 unsigned char state;
279 unsigned char xpos, ypos;
oliverschmidt0096f6a2005-05-04 21:50:17 +0000280 ctk_textentry_input input;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000281};
282
283
oliverschmidt84b30842004-06-27 12:32:16 +0000284#if CTK_CONF_ICON_BITMAPS
285#define CTK_ICON_BITMAP(bitmap) bitmap
286#else
287#define CTK_ICON_BITMAP(bitmap) NULL
288#endif
289
290#if CTK_CONF_ICON_TEXTMAPS
291#define CTK_ICON_TEXTMAP(textmap) textmap
292#else
293#define CTK_ICON_TEXTMAP(textmap) NULL
294#endif
295
adamdunkelsb27d85a2003-09-01 22:23:26 +0000296/**
297 * Instantiating macro for the ctk_icon widget.
298 *
299 * This macro is used when instantiating a ctk_icon widget and is
300 * intended to be used together with a struct assignment like this:
301 \code
302 struct ctk_icon icon =
303 {CTK_ICON("An icon", bitmapptr, textmapptr)};
304 \endcode
305 * \param title The icon's text.
306 * \param bitmap A pointer to the icon's bitmap image.
307 * \param textmap A pointer to the icon's text version of the bitmap.
308 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000309#define CTK_ICON(title, bitmap, textmap) \
adamdunkels1f9a9a12004-07-04 11:42:47 +0000310 NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, 4, CTK_WIDGET_FLAG_INITIALIZER(0) \
311 title, EK_ID_NONE, \
oliverschmidt84b30842004-06-27 12:32:16 +0000312 CTK_ICON_BITMAP(bitmap), CTK_ICON_TEXTMAP(textmap)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000313struct ctk_icon {
314 struct ctk_widget *next;
315 struct ctk_window *window;
316 unsigned char x, y;
317 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000318 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000319#if CTK_CONF_WIDGET_FLAGS
320 unsigned char flags;
321#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200322 const char *title;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000323 ek_id_t owner;
Adrien Destugues69a6e722017-06-03 10:17:17 +0200324 const unsigned char *bitmap;
325 const char *textmap;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000326};
327
adamdunkels3eac04f2004-09-12 07:22:39 +0000328#define CTK_BITMAP(x, y, w, h, bitmap, bitmap_width, bitmap_height) \
329 NULL, NULL, x, y, CTK_WIDGET_BITMAP, w, h, \
330 CTK_WIDGET_FLAG_INITIALIZER(0) bitmap, bitmap_width, bitmap_height
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000331struct ctk_bitmap {
332 struct ctk_widget *next;
333 struct ctk_window *window;
334 unsigned char x, y;
335 unsigned char type;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000336 unsigned char w, h;
adamdunkels3eac04f2004-09-12 07:22:39 +0000337#if CTK_CONF_WIDGET_FLAGS
338 unsigned char flags;
339#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200340 const unsigned char *bitmap;
adamdunkels3eac04f2004-09-12 07:22:39 +0000341 unsigned short bw, bh;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000342};
343
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000344#define CTK_TEXTMAP_NORMAL 0
345#define CTK_TEXTMAP_ACTIVE 1
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000346
adamdunkels1f9a9a12004-07-04 11:42:47 +0000347#define CTK_TEXTMAP(x, y, w, h, textmap) \
348 NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text, CTK_TEXTMAP_NORMAL
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000349struct ctk_textmap {
350 struct ctk_widget *next;
351 struct ctk_window *window;
352 unsigned char x, y;
353 unsigned char type;
354 unsigned char w, h;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000355#if CTK_CONF_WIDGET_FLAGS
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000356 unsigned char flags;
adamdunkels1f9a9a12004-07-04 11:42:47 +0000357#endif /* CTK_CONF_WIDGET_FLAGS */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200358 const char *textmap;
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000359 unsigned char state;
360};
361
adamdunkels1f9a9a12004-07-04 11:42:47 +0000362
adamdunkelsb27d85a2003-09-01 22:23:26 +0000363/**
364 * \internal The CTK button widget structure.
365 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000366struct ctk_widget_button {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200367 const char *text; /**< The button text. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000368};
369
adamdunkelsb27d85a2003-09-01 22:23:26 +0000370/**
371 * \internal The CTK label widget structure.
372 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000373struct ctk_widget_label {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200374 const char *text; /**< The label text. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000375};
376
adamdunkelsb27d85a2003-09-01 22:23:26 +0000377/**
378 * \internal The CTK hyperlink widget structure.
379 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000380struct ctk_widget_hyperlink {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200381 const char *text; /**< The text of the hyperlink. */
382 const char *url; /**< The hyperlink's URL. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000383};
384
385struct ctk_widget_textentry {
386 char *text;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000387 unsigned char len;
388 unsigned char state;
389 unsigned char xpos, ypos;
oliverschmidt0096f6a2005-05-04 21:50:17 +0000390 ctk_textentry_input input;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000391};
392
393struct ctk_widget_icon {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200394 const char *title;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000395 ek_id_t owner;
Adrien Destugues69a6e722017-06-03 10:17:17 +0200396 const unsigned char *bitmap;
397 const char *textmap;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000398};
399
400struct ctk_widget_bitmap {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200401 const unsigned char *bitmap;
adamdunkels3eac04f2004-09-12 07:22:39 +0000402 unsigned short bw, bh;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000403};
adamdunkelse937ded2003-10-01 07:53:57 +0000404/** @} */
405
406/**
407 * \addtogroup ctkdraw
408 * @{
409 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000410
adamdunkelsb27d85a2003-09-01 22:23:26 +0000411/**
412 * The generic CTK widget structure that contains all other widget
413 * structures.
414 *
415 * Since the widgets of a window are arranged on a linked list, the
416 * widget structure contains a next pointer which is used for this
417 * purpose. The widget structure also contains the placement and the
418 * size of the widget.
419 *
420 * Finally, the actual per-widget structure is contained in this
421 * top-level widget structure.
422 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000423struct ctk_widget {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000424 struct ctk_widget *next; /**< The next widget in the linked list
425 of widgets that is contained in the
426 ctk_window structure. */
427 struct ctk_window *window; /**< The window in which the widget is
428 contained. */
429 unsigned char x, /**< The x position of the widget within
430 the containing window, in character
431 coordinates. */
432 y; /**< The y position of the widget within
433 the containing window, in character
434 coordinates. */
435 unsigned char type; /**< The type of the widget:
436 CTK_WIDGET_SEPARATOR,
437 CTK_WIDGET_LABEL, CTK_WIDGET_BUTTON,
438 CTK_WIDGET_HYPERLINK,
439 CTK_WIDGET_TEXTENTRY,
440 CTK_WIDGET_BITMAP or
441 CTK_WIDGET_ICON. */
442 unsigned char w, /**< The width of the widget in character
443 coordinates. */
444 h; /**< The height of the widget in
445 character coordinates. */
adamdunkels1f9a9a12004-07-04 11:42:47 +0000446#if CTK_CONF_WIDGET_FLAGS
447 unsigned char flags;
448#endif /* CTK_CONF_WIDGET_FLAGS */
449
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000450 union {
451 struct ctk_widget_label label;
452 struct ctk_widget_button button;
453 struct ctk_widget_hyperlink hyperlink;
454 struct ctk_widget_textentry textentry;
455 struct ctk_widget_icon icon;
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000456 struct ctk_widget_bitmap bitmap;
adamdunkelsb27d85a2003-09-01 22:23:26 +0000457 } widget; /**< The union which contains the actual
458 widget structure, as determined by the
459 type field. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000460};
461
adamdunkelse937ded2003-10-01 07:53:57 +0000462
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000463struct ctk_desktop;
464
adamdunkels1f9a9a12004-07-04 11:42:47 +0000465#define CTK_WIDGET_FLAG_NONE 0
466#define CTK_WIDGET_FLAG_MONOSPACE 1
467#define CTK_WIDGET_FLAG_CENTER 2
468
469#if CTK_CONF_WIDGET_FLAGS
470#define CTK_WIDGET_SET_FLAG(w, f) ((struct ctk_widget *)(w))->flags = (f)
471#else /* CTK_CONF_WIDGET_FLAGS */
472#define CTK_WIDGET_SET_FLAG(w, f)
473#endif /* CTK_CONF_WIDGET_FLAGS */
474
adamdunkelsb27d85a2003-09-01 22:23:26 +0000475/**
adamdunkelse937ded2003-10-01 07:53:57 +0000476 * Representation of a CTK window.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000477 *
478 * For the CTK, each window is repessented by a ctk_window
479 * structure. All open windows are kept on a doubly linked list,
480 * linked by the next and prev fields in the ctk_window struct. The
481 * window structure holds all widgets that is contained in the window
482 * as well as a pointer to the currently selected widget.
483 *
484 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000485struct ctk_window {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000486 struct ctk_window *next, /**< The next window in the doubly linked
487 list of open windows. */
488
489 *prev; /**< The previous window in the doubly
490 linked list of open windows. */
491 struct ctk_desktop *desktop;/**< The desktop on which this window is
492 open. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000493
adamdunkelsb27d85a2003-09-01 22:23:26 +0000494 ek_id_t owner; /**< The process that owns the
495 window. This process will be the
496 receiver of all CTK signals that
497 pertain to this window. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000498
Adrien Destugues69a6e722017-06-03 10:17:17 +0200499 const char *title; /**< The title of the window. Used for
adamdunkelsb27d85a2003-09-01 22:23:26 +0000500 constructing the "Dekstop" menu. */
501 unsigned char titlelen; /**< The length of the title, cached for
502 speed reasons. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000503
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000504#if CTK_CONF_WINDOWCLOSE
adamdunkelsb27d85a2003-09-01 22:23:26 +0000505 struct ctk_button closebutton; /**< The closebutton. This is also
506 present in the list of active
507 widgets. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000508#else /* CTK_CONF_WINDOWCLOSE */
509 struct ctk_label closebutton;
510#endif /* CTK_CONF_WINDOWCLOSE */
511
512#if CTK_CONF_WINDOWMOVE
adamdunkelsb27d85a2003-09-01 22:23:26 +0000513 struct ctk_button titlebutton;/**< The titlebutton which is used for
514 moving the window. This is also
515 present in the list of active
516 widgets. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000517#else /* CTK_CONF_WINDOWMOVE */
518 struct ctk_label titlebutton;
519#endif /* CTK_CONF_WINDOWMOVE */
520
adamdunkelsb27d85a2003-09-01 22:23:26 +0000521 unsigned char x, /**< The x coordinate of the window, in
522 characters. */
523 y; /**< The y coordinate of the window, in
524 characters. */
525 unsigned char w, /**< The width of the window, excluding
526 window borders. */
527 h; /**< The height of the window,
528 excluding window borders. */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000529
530
adamdunkelsb27d85a2003-09-01 22:23:26 +0000531 struct ctk_widget *inactive; /**< The list if widgets that cannot be
532 selected by the user. Labels and
533 separator widgets are placed on this
534 list. */
535 struct ctk_widget *active; /**< The list of widgets that can be
536 selected by the user. Buttons,
537 hyperlinks, text entry fields, etc.,
538 are placed on this list. */
539 struct ctk_widget *focused; /**< A pointer to the widget on the
540 active list that is currently
541 selected, or NULL if no widget is
542 selected. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000543};
544
adamdunkelsb27d85a2003-09-01 22:23:26 +0000545/**
adamdunkelse937ded2003-10-01 07:53:57 +0000546 * Representation of an individual menu item.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000547 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000548struct ctk_menuitem {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200549 const char *title; /**< The menu items text. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000550 unsigned char titlelen;/**< The length of the item text, cached for
551 speed. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000552};
553
adamdunkelsb27d85a2003-09-01 22:23:26 +0000554/**
adamdunkelse937ded2003-10-01 07:53:57 +0000555 * Representation of an individual menu.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000556 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000557struct ctk_menu {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000558 struct ctk_menu *next; /**< Apointer to the next menu, or is NULL if
559 this is the last menu, and should be used
560 by the ctk-draw module when stepping
561 through the menus when drawing them on
562 screen. */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200563 const char *title; /**< The menu title. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000564 unsigned char titlelen;/**< The length of the title in
565 characters. Cached for speed reasons. */
adamdunkels78c03dc2003-04-09 13:45:05 +0000566#if CC_UNSIGNED_CHAR_BUGS
adamdunkels6ccf7212003-04-10 07:04:45 +0000567 unsigned int nitems;
568 unsigned int active;
adamdunkels78c03dc2003-04-09 13:45:05 +0000569#else /* CC_UNSIGNED_CHAR_BUGS */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000570 unsigned char nitems; /**< The total number of menu items in the
571 menu. */
572 unsigned char active; /**< The currently active menu item. */
adamdunkels78c03dc2003-04-09 13:45:05 +0000573#endif /* CC_UNSIGNED_CHAR_BUGS */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000574 struct ctk_menuitem items[CTK_CONF_MAXMENUITEMS];
adamdunkelsb27d85a2003-09-01 22:23:26 +0000575 /**< The array which contains all the menu
576 items. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000577};
578
adamdunkelsb27d85a2003-09-01 22:23:26 +0000579/**
adamdunkelse937ded2003-10-01 07:53:57 +0000580 * Representation of the menu bar.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000581 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000582struct ctk_menus {
adamdunkelsb27d85a2003-09-01 22:23:26 +0000583 struct ctk_menu *menus; /**< A pointer to a linked list of all
584 menus, including the open menu and
585 the desktop menu.*/
586 struct ctk_menu *open; /**< The currently open menu, if
587 any. If all menus are closed, this
588 item is NULL: */
589 struct ctk_menu *desktopmenu; /**< A pointer to the "Desktop" menu
590 that can be used for drawing the
591 desktop menu in a special way (such
592 as drawing it at the rightmost
593 position). */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000594};
595
adamdunkelse937ded2003-10-01 07:53:57 +0000596/** @} */
597
598
adamdunkelsb27d85a2003-09-01 22:23:26 +0000599/**
600 * \internal The structure describing a Contiki desktop.
601 */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000602struct ctk_desktop {
Adrien Destugues69a6e722017-06-03 10:17:17 +0200603 const char *name; /**< The name of the desktop. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000604
605 struct ctk_window desktop_window; /**< The background window which
606 contains tha desktop icons. */
607 struct ctk_window *windows; /**< The list of open windows. */
608 struct ctk_window *dialog; /**< A pointer to the open dialog, or
609 NULL if no dialog is open. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000610
611#if CTK_CONF_MENUS
adamdunkelsb27d85a2003-09-01 22:23:26 +0000612 struct ctk_menus menus; /**< The list of desktop menus. */
613 struct ctk_menu *lastmenu; /**< Pointer to the menu that was last open. */
614 struct ctk_menu desktopmenu;/**< The desktop menu. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000615#endif /* CTK_CONF_MENUS */
616
adamdunkelsb27d85a2003-09-01 22:23:26 +0000617 unsigned char height, /**< The height of the desktop, in characters. */
618 width; /**< The width of the desktop, in characters. */
619
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000620
adamdunkelsb27d85a2003-09-01 22:23:26 +0000621#define CTK_REDRAW_NONE 0 /**< \internal Redraw flag: nothing
622 to be redrawn. */
623#define CTK_REDRAW_ALL 1 /**< \internal Redraw flag:
624 everything should be redrawn. */
625#define CTK_REDRAW_WINDOWS 2 /**< \internal Redraw flag: redraw
626 windows in queue.*/
627#define CTK_REDRAW_WIDGETS 4 /**< \internal Redraw flag: redraw
628 widgets in queue. */
629#define CTK_REDRAW_MENUS 8 /**< \internal Redraw flag: redraw
630 menus. */
631#define CTK_REDRAW_PART 16 /**< \internal Redraw flag: redraw
632 parts of the desktop. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000633
634#ifndef CTK_CONF_MAX_REDRAWWIDGETS
635#define CTK_CONF_MAX_REDRAWWIDGETS 8
636#endif /* CTK_CONF_MAX_REDRAWWIDGETS */
637#ifndef CTK_CONF_MAX_REDRAWWINDOWS
638#define CTK_CONF_MAX_REDRAWWINDOWS 8
639#endif /* CTK_CONF_MAX_REDRAWWINDOWS */
640
adamdunkelsb27d85a2003-09-01 22:23:26 +0000641 unsigned char redraw; /**< The redraw flag. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000642
adamdunkelsb27d85a2003-09-01 22:23:26 +0000643 struct ctk_widget *redraw_widgets[CTK_CONF_MAX_REDRAWWIDGETS]; /**< The list of widgets to be redrawn. */
644 unsigned char redraw_widgetptr; /**< Pointer to the last widget on the redraw_widgets list. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000645
adamdunkelsb27d85a2003-09-01 22:23:26 +0000646 struct ctk_window *redraw_windows[CTK_CONF_MAX_REDRAWWINDOWS]; /**< The list of windows to be redrawn. */
647 unsigned char redraw_windowptr; /**< Pointer to the last window on the redraw_windows list. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000648
adamdunkelsb27d85a2003-09-01 22:23:26 +0000649 unsigned char redraw_y1, /**< The lower y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
650 redraw_y2; /**< The upper y bound of the area to be redrawn if CTK_REDRAW_PART is flagged. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000651};
652
653
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000654/* Global CTK modes. */
655#define CTK_MODE_NORMAL 0
656#define CTK_MODE_WINDOWMOVE 1
657#define CTK_MODE_SCREENSAVER 2
658#define CTK_MODE_EXTERNAL 3
659
660/* General ctk functions. */
661void ctk_init(void);
adamdunkels28ad2b32004-08-09 20:30:50 +0000662void ctk_restore(void);
663
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000664void ctk_mode_set(unsigned char mode);
665unsigned char ctk_mode_get(void);
adamdunkels9795b2e2003-08-09 23:32:37 +0000666/*void ctk_redraw(void);*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000667
668/* Functions for manipulating windows. */
669void ctk_window_new(struct ctk_window *window,
670 unsigned char w, unsigned char h,
Adrien Destugues69a6e722017-06-03 10:17:17 +0200671 const char *title);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000672void ctk_window_clear(struct ctk_window *w);
673void ctk_window_open(struct ctk_window *w);
oliverschmidtcd6c30b2005-05-05 20:54:16 +0000674#define ctk_window_move(w,xpos,ypos) do { (w)->x=xpos; (w)->y=ypos; } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000675void ctk_window_close(struct ctk_window *w);
676void ctk_window_redraw(struct ctk_window *w);
677#define ctk_window_isopen(w) ((w)->next != NULL)
678
679
680/* Functions for manipulating dialogs. */
681void ctk_dialog_new(struct ctk_window *window,
682 unsigned char w, unsigned char h);
683void ctk_dialog_open(struct ctk_window *d);
684void ctk_dialog_close(void);
685
686/* Functions for manipulating menus. */
Adrien Destugues69a6e722017-06-03 10:17:17 +0200687void ctk_menu_new(struct ctk_menu *menu, const char *title);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000688void ctk_menu_add(struct ctk_menu *menu);
689void ctk_menu_remove(struct ctk_menu *menu);
Adrien Destugues69a6e722017-06-03 10:17:17 +0200690unsigned char ctk_menuitem_add(struct ctk_menu *menu, const char *name);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000691
692/* Functions for icons. */
adamdunkelse937ded2003-10-01 07:53:57 +0000693
694/**
695 * \addtogroup ctkappfunc
696 * @{
697 */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000698/**
699 * Add an icon to the desktop.
700 *
701 * \param icon The icon to be added.
adamdunkels0404ef12003-09-04 19:36:04 +0000702 *
703 * \param id The process ID of the process that owns the icon.
adamdunkelsb27d85a2003-09-01 22:23:26 +0000704 */
adamdunkels0404ef12003-09-04 19:36:04 +0000705#define CTK_ICON_ADD(icon, id) ctk_icon_add((struct ctk_widget *)icon, id)
706void ctk_icon_add(struct ctk_widget *icon, ek_id_t id);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000707
708/* Functions for manipulating widgets. */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000709
710/**
711 * Add a widget to a window.
712 *
713 * \param win The window to which the widget should be added.
714 * \param widg The widget to be added.
715 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000716#define CTK_WIDGET_ADD(win, widg) \
717 ctk_widget_add(win, (struct ctk_widget *)widg)
adamdunkelsa6557e42003-08-11 22:27:51 +0000718void CC_FASTCALL ctk_widget_add(struct ctk_window *window,
719 struct ctk_widget *widget);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000720
adamdunkelsb27d85a2003-09-01 22:23:26 +0000721/**
722 * Set focus to a widget.
723 *
724 * \param win The widget's window.
725 * \param widg The widget
726 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000727#define CTK_WIDGET_FOCUS(win, widg) \
728 (win)->focused = (struct ctk_widget *)(widg)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000729
730/**
731 * Add a widget to the redraw queue.
732 *
733 * \param widg The widget to be redrawn.
734 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000735#define CTK_WIDGET_REDRAW(widg) \
736 ctk_widget_redraw((struct ctk_widget *)widg)
737void ctk_widget_redraw(struct ctk_widget *w);
738
adamdunkelsb27d85a2003-09-01 22:23:26 +0000739/**
740 * Obtain the type of a widget.
741 *
742 * \param w The widget.
743 */
adamdunkels3a08a492003-04-11 20:16:02 +0000744#define CTK_WIDGET_TYPE(w) ((w)->type)
745
adamdunkelse8b21d02003-04-24 17:18:27 +0000746
adamdunkelsb27d85a2003-09-01 22:23:26 +0000747/**
748 * Sets the width of a widget.
749 *
750 * \param widget The widget.
751 * \param width The width of the widget, in characters.
752 */
adamdunkelse8b21d02003-04-24 17:18:27 +0000753#define CTK_WIDGET_SET_WIDTH(widget, width) do { \
754 ((struct ctk_widget *)(widget))->w = (width); } while(0)
755
adamdunkelsb27d85a2003-09-01 22:23:26 +0000756/**
757 * Retrieves the x position of a widget, relative to the window in
758 * which the widget is contained.
759 *
760 * \param w The widget.
761 * \return The x position of the widget.
762 */
adamdunkelse8b21d02003-04-24 17:18:27 +0000763#define CTK_WIDGET_XPOS(w) (((struct ctk_widget *)(w))->x)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000764
765/**
766 * Sets the x position of a widget, relative to the window in
767 * which the widget is contained.
768 *
769 * \param w The widget.
770 * \param xpos The x position of the widget.
771 */
772#define CTK_WIDGET_SET_XPOS(w, xpos) \
773 ((struct ctk_widget *)(w))->x = (xpos)
774/**
775 * Retrieves the y position of a widget, relative to the window in
776 * which the widget is contained.
777 *
778 * \param w The widget.
779 * \return The y position of the widget.
780 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000781#define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
782
adamdunkelsb27d85a2003-09-01 22:23:26 +0000783/**
784 * Sets the y position of a widget, relative to the window in
785 * which the widget is contained.
786 *
787 * \param w The widget.
788 * \param ypos The y position of the widget.
789 */
790#define CTK_WIDGET_SET_YPOS(w, ypos) \
791 ((struct ctk_widget *)(w))->y = (ypos)
792
793/* XXX: should be removed.
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000794#define ctk_textentry_set_height(w, height) \
795 (w)->widget.textentry.h = (height)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000796*/
797
798/** \def ctk_label_set_height(w, height)
799 * \brief Set the height of a label.
800 *
801 * \param w The CTK label widget.
802 * \param height The new height of the label.
803 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000804#define ctk_label_set_height(w, height) \
805 (w)->widget.label.h = (height)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000806
807/**
808 * Set the text of a label.
809 *
810 * \param l The CTK label widget.
811 * \param t The new text of the label.
812 */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000813#define ctk_label_set_text(l, t) (l)->text = (t)
814
adamdunkelsb27d85a2003-09-01 22:23:26 +0000815/**
816 * Set the text of a button.
817 *
818 * \param b The CTK button widget.
819 * \param t The new text of the button.
820 */
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000821#define ctk_button_set_text(b, t) (b)->text = (t)
822
adamdunkels58917a82003-04-18 00:18:38 +0000823#define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m)
824
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000825#define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000826 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000827 (widg)->next = NULL; \
828 (widg)->type = CTK_WIDGET_BUTTON; \
829 (widg)->x = (xpos); \
830 (widg)->y = (ypos); \
831 (widg)->w = (width); \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000832 (widg)->h = 1; \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000833 (widg)->text = (buttontext); \
834 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000835
836#define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000837 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000838 (widg)->next = NULL; \
839 (widg)->type = CTK_WIDGET_LABEL; \
840 (widg)->x = (xpos); \
841 (widg)->y = (ypos); \
842 (widg)->w = (width); \
843 (widg)->h = (height); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000844 (widg)->text = (labeltext); \
845 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000846
adamdunkels58917a82003-04-18 00:18:38 +0000847#define CTK_BITMAP_NEW(widg, xpos, ypos, width, height, bmap) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000848 do { (widg)->window = NULL; \
adamdunkels58917a82003-04-18 00:18:38 +0000849 (widg)->next = NULL; \
850 (widg)->type = CTK_WIDGET_BITMAP; \
851 (widg)->x = (xpos); \
852 (widg)->y = (ypos); \
853 (widg)->w = (width); \
854 (widg)->h = (height); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000855 (widg)->bitmap = (bmap); \
856 } while(0)
adamdunkels58917a82003-04-18 00:18:38 +0000857
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000858#define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000859 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000860 (widg)->next = NULL; \
861 (widg)->type = CTK_WIDGET_TEXTENTRY; \
862 (widg)->x = (xxpos); \
863 (widg)->y = (yypos); \
864 (widg)->w = (width); \
oliverschmidt0096f6a2005-05-04 21:50:17 +0000865 (widg)->h = 1; \
866 (widg)->text = (textptr); \
867 (widg)->len = (textlen); \
868 (widg)->state = CTK_TEXTENTRY_NORMAL; \
869 (widg)->xpos = 0; \
870 (widg)->ypos = 0; \
871 (widg)->input = NULL; \
872 } while(0)
873
874#define CTK_TEXTENTRY_INPUT_NEW(widg, xxpos, yypos, width, height, textptr, textlen, iinput) \
875 do { (widg)->window = NULL; \
876 (widg)->next = NULL; \
877 (widg)->type = CTK_WIDGET_TEXTENTRY; \
878 (widg)->x = (xxpos); \
879 (widg)->y = (yypos); \
880 (widg)->w = (width); \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000881 (widg)->h = (height); \
882 (widg)->text = (textptr); \
883 (widg)->len = (textlen); \
884 (widg)->state = CTK_TEXTENTRY_NORMAL; \
885 (widg)->xpos = 0; \
adamdunkels28ad2b32004-08-09 20:30:50 +0000886 (widg)->ypos = 0; \
oliverschmidt0096f6a2005-05-04 21:50:17 +0000887 (widg)->input = (ctk_textentry_input)(iinput); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000888 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000889
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000890#define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000891 do { (widg)->window = NULL; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000892 (widg)->next = NULL; \
893 (widg)->type = CTK_WIDGET_HYPERLINK; \
894 (widg)->x = (xpos); \
895 (widg)->y = (ypos); \
896 (widg)->w = (width); \
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000897 (widg)->h = 1; \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000898 (widg)->text = (linktext); \
adamdunkelsb27d85a2003-09-01 22:23:26 +0000899 (widg)->url = (linkurl); \
900 } while(0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000901
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000902/* Desktop interface. */
adamdunkelseb9bf6c2003-06-30 20:45:50 +0000903void ctk_desktop_redraw(struct ctk_desktop *d);
904unsigned char ctk_desktop_width(struct ctk_desktop *d);
905unsigned char ctk_desktop_height(struct ctk_desktop *d);
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000906
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000907/* Signals. */
adamdunkels1f9a9a12004-07-04 11:42:47 +0000908extern ek_event_t ctk_signal_keypress,
adamdunkels3a08a492003-04-11 20:16:02 +0000909 ctk_signal_widget_activate,
910 ctk_signal_widget_select,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000911 ctk_signal_timer,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000912 ctk_signal_menu_activate,
adamdunkelsc4902862003-04-09 00:30:45 +0000913 ctk_signal_window_close,
914 ctk_signal_pointer_move,
adamdunkels3a08a492003-04-11 20:16:02 +0000915 ctk_signal_pointer_button;
916
adamdunkelse8b21d02003-04-24 17:18:27 +0000917#if CTK_CONF_SCREENSAVER
adamdunkels1f9a9a12004-07-04 11:42:47 +0000918extern ek_event_t ctk_signal_screensaver_stop,
adamdunkels9795b2e2003-08-09 23:32:37 +0000919 ctk_signal_screensaver_start;
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000920
921extern unsigned short ctk_screensaver_timeout;
adamdunkelsb27d85a2003-09-01 22:23:26 +0000922/**
923 * Set the screensaver timeout, in seconds.
924 *
925 * \param t The timeout in seconds.
926 */
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000927#define CTK_SCREENSAVER_SET_TIMEOUT(t) ctk_screensaver_timeout = (t)
adamdunkelsb27d85a2003-09-01 22:23:26 +0000928/**
929 * Obtain the screensaver timeout, in seconds.
930 *
931 * \raturn The timeout in seconds.
932 */
adamdunkelse2f4d2a2003-04-28 23:21:42 +0000933#define CTK_SCREENSAVER_TIMEOUT() ctk_screensaver_timeout
adamdunkelse8b21d02003-04-24 17:18:27 +0000934#endif /* CTK_CONF_SCREENSAVER */
935
adamdunkels3a08a492003-04-11 20:16:02 +0000936/* These should no longer be used: */
adamdunkels1f9a9a12004-07-04 11:42:47 +0000937extern ek_event_t ctk_signal_button_activate,
adamdunkels3a08a492003-04-11 20:16:02 +0000938 ctk_signal_button_hover,
939 ctk_signal_hyperlink_activate,
940 ctk_signal_hyperlink_hover;
adamdunkelse937ded2003-10-01 07:53:57 +0000941/** @} */
942
943/**
944 * \addtogroup ctkdraw
945 * @{
946 */
adamdunkels3a08a492003-04-11 20:16:02 +0000947
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000948/* Focus flags */
adamdunkelsb27d85a2003-09-01 22:23:26 +0000949/** Widget focus flag: no focus. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000950#define CTK_FOCUS_NONE 0
adamdunkelsb27d85a2003-09-01 22:23:26 +0000951/** Widget focus flag: widget has focus. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000952#define CTK_FOCUS_WIDGET 1
adamdunkelsb27d85a2003-09-01 22:23:26 +0000953/** Widget focus flag: widget's window is the foremost one. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000954#define CTK_FOCUS_WINDOW 2
adamdunkelsb27d85a2003-09-01 22:23:26 +0000955/** Widget focus flag: widget is in a dialog. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000956#define CTK_FOCUS_DIALOG 4
957
adamdunkelse937ded2003-10-01 07:53:57 +0000958/** @} */
959/** @} */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000960#endif /* __CTK_H__ */