blob: f50dd1c86c28f10876831ee2a0206c43b4e48144 [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 *
adamdunkels6ccf7212003-04-10 07:04:45 +000035 * $Id: ctk.h,v 1.6 2003/04/10 07:04:45 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) \
adamdunkelsc4902862003-04-09 00:30:45 +0000126 NULL, NULL, 0, 0, CTK_WIDGET_ICON, 0, 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
311#define CTK_WIDGET_YPOS(w) (((struct ctk_widget *)(w))->y)
312
313#define ctk_textentry_set_height(w, height) \
314 (w)->widget.textentry.h = (height)
315#define ctk_label_set_height(w, height) \
316 (w)->widget.label.h = (height)
317#define ctk_label_set_text(l, t) (l)->text = (t)
318
adamdunkels1d5eb5e2003-03-28 12:10:39 +0000319#define ctk_button_set_text(b, t) (b)->text = (t)
320
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000321#define CTK_BUTTON_NEW(widg, xpos, ypos, width, buttontext) \
322 (widg)->window = NULL; \
323 (widg)->next = NULL; \
324 (widg)->type = CTK_WIDGET_BUTTON; \
325 (widg)->x = (xpos); \
326 (widg)->y = (ypos); \
327 (widg)->w = (width); \
328 (widg)->text = (buttontext)
329
330#define CTK_LABEL_NEW(widg, xpos, ypos, width, height, labeltext) \
331 (widg)->window = NULL; \
332 (widg)->next = NULL; \
333 (widg)->type = CTK_WIDGET_LABEL; \
334 (widg)->x = (xpos); \
335 (widg)->y = (ypos); \
336 (widg)->w = (width); \
337 (widg)->h = (height); \
338 (widg)->text = (labeltext)
339
340#define CTK_TEXTENTRY_NEW(widg, xxpos, yypos, width, height, textptr, textlen) \
341 (widg)->window = NULL; \
342 (widg)->next = NULL; \
343 (widg)->type = CTK_WIDGET_TEXTENTRY; \
344 (widg)->x = (xxpos); \
345 (widg)->y = (yypos); \
346 (widg)->w = (width); \
347 (widg)->h = (height); \
348 (widg)->text = (textptr); \
349 (widg)->len = (textlen); \
350 (widg)->state = CTK_TEXTENTRY_NORMAL; \
351 (widg)->xpos = 0; \
352 (widg)->ypos = 0
353
354
355
356#define CTK_HYPERLINK_NEW(widg, xpos, ypos, width, linktext, linkurl) \
357 (widg)->window = NULL; \
358 (widg)->next = NULL; \
359 (widg)->type = CTK_WIDGET_HYPERLINK; \
360 (widg)->x = (xpos); \
361 (widg)->y = (ypos); \
362 (widg)->w = (width); \
363 (widg)->text = (linktext); \
364 (widg)->url = (linkurl)
365
366/* Signals. */
367extern ek_signal_t ctk_signal_keypress,
368 ctk_signal_timer,
369 ctk_signal_button_activate,
370 ctk_signal_button_hover,
371 ctk_signal_hyperlink_activate,
372 ctk_signal_hyperlink_hover,
373 ctk_signal_menu_activate,
adamdunkelsc4902862003-04-09 00:30:45 +0000374 ctk_signal_window_close,
375 ctk_signal_pointer_move,
376 ctk_signal_pointer_down,
377 ctk_signal_pointer_up;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000378
379/* Focus flags */
380#define CTK_FOCUS_NONE 0
381#define CTK_FOCUS_WIDGET 1
382#define CTK_FOCUS_WINDOW 2
383#define CTK_FOCUS_DIALOG 4
384
385
386
387#endif /* __CTK_H__ */