blob: 4989d97a914cbff12d22beda8acfff3f041e9591 [file] [log] [blame]
adamdunkelsca9ddcb2003-03-19 14:13:31 +00001/*
2 * Copyright (c) 2002, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. All advertising materials mentioning features or use of this
15 * software must display the following acknowledgement:
16 * This product includes software developed by Adam Dunkels.
17 * 4. The name of the author may not be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * This file is part of the "ctk" console GUI toolkit for cc65
34 *
adamdunkelse8b21d02003-04-24 17:18:27 +000035 * $Id: ctk.h,v 1.9 2003/04/24 17:18:27 adamdunkels Exp $
adamdunkelsca9ddcb2003-03-19 14:13:31 +000036 *
37 */
38
39#ifndef __CTK_H__
40#define __CTK_H__
41
42#include "ctk-conf.h"
43#include "ek.h"
44
adamdunkels78c03dc2003-04-09 13:45:05 +000045#include "cc.h"
46
adamdunkelsca9ddcb2003-03-19 14:13:31 +000047/* Defintions for the CTK widget types. */
48#define CTK_WIDGET_SEPARATOR 1
49#define CTK_WIDGET_LABEL 2
50#define CTK_WIDGET_BUTTON 3
51#define CTK_WIDGET_HYPERLINK 4
52#define CTK_WIDGET_TEXTENTRY 5
adamdunkels1d5eb5e2003-03-28 12:10:39 +000053#define CTK_WIDGET_BITMAP 6
54#define CTK_WIDGET_ICON 7
adamdunkelsca9ddcb2003-03-19 14:13:31 +000055
56struct ctk_widget;
57
58#define CTK_SEPARATOR(x, y, w) \
59 NULL, NULL, x, y, CTK_WIDGET_SEPARATOR, w
60struct ctk_separator {
61 struct ctk_widget *next;
62 struct ctk_window *window;
63 unsigned char x, y;
64 unsigned char type;
65 unsigned char w;
66};
67
68#define CTK_BUTTON(x, y, w, text) \
69 NULL, NULL, x, y, CTK_WIDGET_BUTTON, w, text
70struct ctk_button {
71 struct ctk_widget *next;
72 struct ctk_window *window;
73 unsigned char x, y;
74 unsigned char type;
75 unsigned char w;
76 char *text;
77};
78
79#define CTK_LABEL(x, y, w, h, text) \
80 NULL, NULL, x, y, CTK_WIDGET_LABEL, w, text, h
81struct ctk_label {
82 struct ctk_widget *next;
83 struct ctk_window *window;
84 unsigned char x, y;
85 unsigned char type;
86 unsigned char w;
87 char *text;
88 unsigned char h;
89};
90
91#define CTK_HYPERLINK(x, y, w, text, url) \
92 NULL, NULL, x, y, CTK_WIDGET_HYPERLINK, w, text, url
93struct ctk_hyperlink {
94 struct ctk_widget *next;
95 struct ctk_window *window;
96 unsigned char x, y;
97 unsigned char type;
98 unsigned char w;
99 char *text;
100 char *url;
101};
102
103/* Editing modes of the CTK textentry widget. */
104#define CTK_TEXTENTRY_NORMAL 0
105#define CTK_TEXTENTRY_EDIT 1
106
107
108#define CTK_TEXTENTRY(x, y, w, h, text, len) \
109 NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, text, h, len, \
110 CTK_TEXTENTRY_NORMAL, 0, 0
111struct ctk_textentry {
112 struct ctk_widget *next;
113 struct ctk_window *window;
114 unsigned char x, y;
115 unsigned char type;
116 unsigned char w;
117 char *text;
118 unsigned char h;
119 unsigned char len;
120 unsigned char state;
121 unsigned char xpos, ypos;
122};
123
124
125#define CTK_ICON(title, bitmap, textmap) \
adamdunkels3a08a492003-04-11 20:16:02 +0000126 NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, title, 4, 0, bitmap, textmap
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000127struct ctk_icon {
128 struct ctk_widget *next;
129 struct ctk_window *window;
130 unsigned char x, y;
131 unsigned char type;
132 unsigned char w;
133 char *title;
adamdunkelsc4902862003-04-09 00:30:45 +0000134 unsigned char h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000135 ek_id_t owner;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000136 unsigned char *bitmap;
137 char *textmap;
138};
139
140#define CTK_BITMAP(x, y, w, h, bitmap) \
141 NULL, NULL, x, y, CTK_WIDGET_BITMAP, w, bitmap, h
142struct ctk_bitmap {
143 struct ctk_widget *next;
144 struct ctk_window *window;
145 unsigned char x, y;
146 unsigned char type;
147 unsigned char w;
148 unsigned char *bitmap;
149 unsigned char h;
150};
151
152
153
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000154struct ctk_widget_button {
155 char *text;
156};
157
158struct ctk_widget_label {
159 char *text;
160 unsigned char h;
161};
162
163struct ctk_widget_hyperlink {
164 char *text;
165 char *url;
166};
167
168struct ctk_widget_textentry {
169 char *text;
170 unsigned char h;
171 unsigned char len;
172 unsigned char state;
173 unsigned char xpos, ypos;
174};
175
176struct ctk_widget_icon {
177 char *title;
adamdunkelsc4902862003-04-09 00:30:45 +0000178 unsigned char h;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000179 ek_id_t owner;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000180 unsigned char *bitmap;
181 char *textmap;
182};
183
184struct ctk_widget_bitmap {
185 unsigned char *bitmap;
186 unsigned char h;
187};
188
189struct ctk_widget {
190 struct ctk_widget *next;
191 struct ctk_window *window;
192 unsigned char x, y;
193 unsigned char type;
194 unsigned char w;
195 union {
196 struct ctk_widget_label label;
197 struct ctk_widget_button button;
198 struct ctk_widget_hyperlink hyperlink;
199 struct ctk_widget_textentry textentry;
200 struct ctk_widget_icon icon;
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000201 struct ctk_widget_bitmap bitmap;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000202 } widget;
203};
204
205/* Definition of the CTK window structure. */
206struct ctk_window {
207 struct ctk_window *next, *prev;
208 ek_id_t owner;
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000209
210 char *title;
211 unsigned char titlelen;
212
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000213#if CTK_CONF_WINDOWCLOSE
214 struct ctk_button closebutton;
215#else /* CTK_CONF_WINDOWCLOSE */
216 struct ctk_label closebutton;
217#endif /* CTK_CONF_WINDOWCLOSE */
218
219#if CTK_CONF_WINDOWMOVE
220 struct ctk_button titlebutton;
221#else /* CTK_CONF_WINDOWMOVE */
222 struct ctk_label titlebutton;
223#endif /* CTK_CONF_WINDOWMOVE */
224
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000225 unsigned char x, y;
226 unsigned char w, h;
227
228
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000229 struct ctk_widget *inactive;
230 struct ctk_widget *active;
231 struct ctk_widget *focused;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000232};
233
234struct ctk_menuitem {
235 char *title;
236 unsigned char titlelen;
237};
238
239struct ctk_menu {
240 struct ctk_menu *next;
241 char *title;
242 unsigned char titlelen;
adamdunkels78c03dc2003-04-09 13:45:05 +0000243#if CC_UNSIGNED_CHAR_BUGS
adamdunkels6ccf7212003-04-10 07:04:45 +0000244 unsigned int nitems;
245 unsigned int active;
adamdunkels78c03dc2003-04-09 13:45:05 +0000246#else /* CC_UNSIGNED_CHAR_BUGS */
247 unsigned char nitems;
248 unsigned char active;
249#endif /* CC_UNSIGNED_CHAR_BUGS */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000250 struct ctk_menuitem items[CTK_CONF_MAXMENUITEMS];
251};
252
253struct ctk_menus {
254 struct ctk_menu *menus;
255 struct ctk_menu *open;
256 struct ctk_menu *desktopmenu;
257};
258
259/* Global CTK modes. */
260#define CTK_MODE_NORMAL 0
261#define CTK_MODE_WINDOWMOVE 1
262#define CTK_MODE_SCREENSAVER 2
263#define CTK_MODE_EXTERNAL 3
264
265/* General ctk functions. */
266void ctk_init(void);
267void ctk_mode_set(unsigned char mode);
268unsigned char ctk_mode_get(void);
269void ctk_redraw(void);
270
271/* Functions for manipulating windows. */
272void ctk_window_new(struct ctk_window *window,
273 unsigned char w, unsigned char h,
274 char *title);
275void ctk_window_clear(struct ctk_window *w);
276void ctk_window_open(struct ctk_window *w);
277#define ctk_window_move(w,xpos,ypos) do {(w)->x=xpos; (w)->y=ypos;}while(0)
278void ctk_window_close(struct ctk_window *w);
279void ctk_window_redraw(struct ctk_window *w);
280#define ctk_window_isopen(w) ((w)->next != NULL)
281
282
283/* Functions for manipulating dialogs. */
284void ctk_dialog_new(struct ctk_window *window,
285 unsigned char w, unsigned char h);
286void ctk_dialog_open(struct ctk_window *d);
287void ctk_dialog_close(void);
288
289/* Functions for manipulating menus. */
290void ctk_menu_new(struct ctk_menu *menu, char *title);
291void ctk_menu_add(struct ctk_menu *menu);
292void ctk_menu_remove(struct ctk_menu *menu);
293unsigned char ctk_menuitem_add(struct ctk_menu *menu, char *name);
294
295/* Functions for icons. */
296#define CTK_ICON_ADD(icon, id) ctk_icon_add((struct ctk_widget *)icon, id)
297void ctk_icon_add(struct ctk_widget *icon, ek_id_t id);
298
299/* Functions for manipulating widgets. */
300#define CTK_WIDGET_ADD(win, widg) \
301 ctk_widget_add(win, (struct ctk_widget *)widg)
302void ctk_widget_add(struct ctk_window *window,
303 struct ctk_widget *widget);
304
305#define CTK_WIDGET_FOCUS(win, widg) \
306 (win)->focused = (struct ctk_widget *)(widg)
307#define CTK_WIDGET_REDRAW(widg) \
308 ctk_widget_redraw((struct ctk_widget *)widg)
309void ctk_widget_redraw(struct ctk_widget *w);
310
adamdunkels3a08a492003-04-11 20:16:02 +0000311#define CTK_WIDGET_TYPE(w) ((w)->type)
312
adamdunkelse8b21d02003-04-24 17:18:27 +0000313#define CTK_WIDGET_SET_XPOS(w, xpos) ((struct ctk_widget *)(w))->x = (xpos)
314#define CTK_WIDGET_SET_YPOS(w, ypos) ((struct ctk_widget *)(w))->y = (ypos)
315
316#define CTK_WIDGET_SET_WIDTH(widget, width) do { \
317 ((struct ctk_widget *)(widget))->w = (width); } while(0)
318
319#define CTK_WIDGET_XPOS(w) (((struct ctk_widget *)(w))->x)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000320#define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
321
322#define ctk_textentry_set_height(w, height) \
323 (w)->widget.textentry.h = (height)
324#define ctk_label_set_height(w, height) \
325 (w)->widget.label.h = (height)
326#define ctk_label_set_text(l, t) (l)->text = (t)
327
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000328#define ctk_button_set_text(b, t) (b)->text = (t)
329
adamdunkels58917a82003-04-18 00:18:38 +0000330#define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m)
331
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000332#define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
333 (widg)->window = NULL; \
334 (widg)->next = NULL; \
335 (widg)->type = CTK_WIDGET_BUTTON; \
336 (widg)->x = (xpos); \
337 (widg)->y = (ypos); \
338 (widg)->w = (width); \
339 (widg)->text = (buttontext)
340
341#define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
342 (widg)->window = NULL; \
343 (widg)->next = NULL; \
344 (widg)->type = CTK_WIDGET_LABEL; \
345 (widg)->x = (xpos); \
346 (widg)->y = (ypos); \
347 (widg)->w = (width); \
348 (widg)->h = (height); \
349 (widg)->text = (labeltext)
350
adamdunkels58917a82003-04-18 00:18:38 +0000351#define CTK_BITMAP_NEW(widg, xpos, ypos, width, height, bmap) \
352 (widg)->window = NULL; \
353 (widg)->next = NULL; \
354 (widg)->type = CTK_WIDGET_BITMAP; \
355 (widg)->x = (xpos); \
356 (widg)->y = (ypos); \
357 (widg)->w = (width); \
358 (widg)->h = (height); \
359 (widg)->bitmap = (bmap)
360
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000361#define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
362 (widg)->window = NULL; \
363 (widg)->next = NULL; \
364 (widg)->type = CTK_WIDGET_TEXTENTRY; \
365 (widg)->x = (xxpos); \
366 (widg)->y = (yypos); \
367 (widg)->w = (width); \
368 (widg)->h = (height); \
369 (widg)->text = (textptr); \
370 (widg)->len = (textlen); \
371 (widg)->state = CTK_TEXTENTRY_NORMAL; \
372 (widg)->xpos = 0; \
373 (widg)->ypos = 0
374
375
376
377#define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
378 (widg)->window = NULL; \
379 (widg)->next = NULL; \
380 (widg)->type = CTK_WIDGET_HYPERLINK; \
381 (widg)->x = (xpos); \
382 (widg)->y = (ypos); \
383 (widg)->w = (width); \
384 (widg)->text = (linktext); \
385 (widg)->url = (linkurl)
386
387/* Signals. */
388extern ek_signal_t ctk_signal_keypress,
adamdunkels3a08a492003-04-11 20:16:02 +0000389 ctk_signal_widget_activate,
390 ctk_signal_widget_select,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000391 ctk_signal_timer,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000392 ctk_signal_menu_activate,
adamdunkelsc4902862003-04-09 00:30:45 +0000393 ctk_signal_window_close,
394 ctk_signal_pointer_move,
adamdunkels3a08a492003-04-11 20:16:02 +0000395 ctk_signal_pointer_button;
396
adamdunkelse8b21d02003-04-24 17:18:27 +0000397#if CTK_CONF_SCREENSAVER
398extern ek_signal_t ctk_signal_screensaver_start,
399 ctk_signal_screensaver_stop,
400 ctk_signal_screensaver_uninstall;
401#endif /* CTK_CONF_SCREENSAVER */
402
adamdunkels3a08a492003-04-11 20:16:02 +0000403/* These should no longer be used: */
404extern ek_signal_t ctk_signal_button_activate,
405 ctk_signal_button_hover,
406 ctk_signal_hyperlink_activate,
407 ctk_signal_hyperlink_hover;
408
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000409/* Focus flags */
410#define CTK_FOCUS_NONE 0
411#define CTK_FOCUS_WIDGET 1
412#define CTK_FOCUS_WINDOW 2
413#define CTK_FOCUS_DIALOG 4
414
415
416
417#endif /* __CTK_H__ */