adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1 | /* |
| 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 | * |
adamdunkels | e8b21d0 | 2003-04-24 17:18:27 +0000 | [diff] [blame^] | 35 | * $Id: ctk.h,v 1.9 2003/04/24 17:18:27 adamdunkels Exp $ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 36 | * |
| 37 | */ |
| 38 | |
| 39 | #ifndef __CTK_H__ |
| 40 | #define __CTK_H__ |
| 41 | |
| 42 | #include "ctk-conf.h" |
| 43 | #include "ek.h" |
| 44 | |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 45 | #include "cc.h" |
| 46 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 47 | /* 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 |
adamdunkels | 1d5eb5e | 2003-03-28 12:10:39 +0000 | [diff] [blame] | 53 | #define CTK_WIDGET_BITMAP 6 |
| 54 | #define CTK_WIDGET_ICON 7 |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 55 | |
| 56 | struct ctk_widget; |
| 57 | |
| 58 | #define CTK_SEPARATOR(x, y, w) \ |
| 59 | NULL, NULL, x, y, CTK_WIDGET_SEPARATOR, w |
| 60 | struct 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 |
| 70 | struct 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 |
| 81 | struct 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 |
| 93 | struct 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 |
| 111 | struct 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) \ |
adamdunkels | 3a08a49 | 2003-04-11 20:16:02 +0000 | [diff] [blame] | 126 | NULL, NULL, 0, 0, CTK_WIDGET_ICON, 2, title, 4, 0, bitmap, textmap |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 127 | struct 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; |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 134 | unsigned char h; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 135 | ek_id_t owner; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 136 | 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 |
| 142 | struct 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 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 154 | struct ctk_widget_button { |
| 155 | char *text; |
| 156 | }; |
| 157 | |
| 158 | struct ctk_widget_label { |
| 159 | char *text; |
| 160 | unsigned char h; |
| 161 | }; |
| 162 | |
| 163 | struct ctk_widget_hyperlink { |
| 164 | char *text; |
| 165 | char *url; |
| 166 | }; |
| 167 | |
| 168 | struct 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 | |
| 176 | struct ctk_widget_icon { |
| 177 | char *title; |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 178 | unsigned char h; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 179 | ek_id_t owner; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 180 | unsigned char *bitmap; |
| 181 | char *textmap; |
| 182 | }; |
| 183 | |
| 184 | struct ctk_widget_bitmap { |
| 185 | unsigned char *bitmap; |
| 186 | unsigned char h; |
| 187 | }; |
| 188 | |
| 189 | struct 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; |
adamdunkels | 1d5eb5e | 2003-03-28 12:10:39 +0000 | [diff] [blame] | 201 | struct ctk_widget_bitmap bitmap; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 202 | } widget; |
| 203 | }; |
| 204 | |
| 205 | /* Definition of the CTK window structure. */ |
| 206 | struct ctk_window { |
| 207 | struct ctk_window *next, *prev; |
| 208 | ek_id_t owner; |
adamdunkels | 1d5eb5e | 2003-03-28 12:10:39 +0000 | [diff] [blame] | 209 | |
| 210 | char *title; |
| 211 | unsigned char titlelen; |
| 212 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 213 | #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 | |
adamdunkels | 1d5eb5e | 2003-03-28 12:10:39 +0000 | [diff] [blame] | 225 | unsigned char x, y; |
| 226 | unsigned char w, h; |
| 227 | |
| 228 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 229 | struct ctk_widget *inactive; |
| 230 | struct ctk_widget *active; |
| 231 | struct ctk_widget *focused; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | struct ctk_menuitem { |
| 235 | char *title; |
| 236 | unsigned char titlelen; |
| 237 | }; |
| 238 | |
| 239 | struct ctk_menu { |
| 240 | struct ctk_menu *next; |
| 241 | char *title; |
| 242 | unsigned char titlelen; |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 243 | #if CC_UNSIGNED_CHAR_BUGS |
adamdunkels | 6ccf721 | 2003-04-10 07:04:45 +0000 | [diff] [blame] | 244 | unsigned int nitems; |
| 245 | unsigned int active; |
adamdunkels | 78c03dc | 2003-04-09 13:45:05 +0000 | [diff] [blame] | 246 | #else /* CC_UNSIGNED_CHAR_BUGS */ |
| 247 | unsigned char nitems; |
| 248 | unsigned char active; |
| 249 | #endif /* CC_UNSIGNED_CHAR_BUGS */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 250 | struct ctk_menuitem items[CTK_CONF_MAXMENUITEMS]; |
| 251 | }; |
| 252 | |
| 253 | struct 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. */ |
| 266 | void ctk_init(void); |
| 267 | void ctk_mode_set(unsigned char mode); |
| 268 | unsigned char ctk_mode_get(void); |
| 269 | void ctk_redraw(void); |
| 270 | |
| 271 | /* Functions for manipulating windows. */ |
| 272 | void ctk_window_new(struct ctk_window *window, |
| 273 | unsigned char w, unsigned char h, |
| 274 | char *title); |
| 275 | void ctk_window_clear(struct ctk_window *w); |
| 276 | void ctk_window_open(struct ctk_window *w); |
| 277 | #define ctk_window_move(w,xpos,ypos) do {(w)->x=xpos; (w)->y=ypos;}while(0) |
| 278 | void ctk_window_close(struct ctk_window *w); |
| 279 | void ctk_window_redraw(struct ctk_window *w); |
| 280 | #define ctk_window_isopen(w) ((w)->next != NULL) |
| 281 | |
| 282 | |
| 283 | /* Functions for manipulating dialogs. */ |
| 284 | void ctk_dialog_new(struct ctk_window *window, |
| 285 | unsigned char w, unsigned char h); |
| 286 | void ctk_dialog_open(struct ctk_window *d); |
| 287 | void ctk_dialog_close(void); |
| 288 | |
| 289 | /* Functions for manipulating menus. */ |
| 290 | void ctk_menu_new(struct ctk_menu *menu, char *title); |
| 291 | void ctk_menu_add(struct ctk_menu *menu); |
| 292 | void ctk_menu_remove(struct ctk_menu *menu); |
| 293 | unsigned 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) |
| 297 | void 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) |
| 302 | void 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) |
| 309 | void ctk_widget_redraw(struct ctk_widget *w); |
| 310 | |
adamdunkels | 3a08a49 | 2003-04-11 20:16:02 +0000 | [diff] [blame] | 311 | #define CTK_WIDGET_TYPE(w) ((w)->type) |
| 312 | |
adamdunkels | e8b21d0 | 2003-04-24 17:18:27 +0000 | [diff] [blame^] | 313 | #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) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 320 | #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 | |
adamdunkels | 1d5eb5e | 2003-03-28 12:10:39 +0000 | [diff] [blame] | 328 | #define ctk_button_set_text(b, t) (b)->text = (t) |
| 329 | |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 330 | #define ctk_bitmap_set_bitmap(b, m) (b)->bitmap = (m) |
| 331 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 332 | #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 | |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 351 | #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 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 361 | #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. */ |
| 388 | extern ek_signal_t ctk_signal_keypress, |
adamdunkels | 3a08a49 | 2003-04-11 20:16:02 +0000 | [diff] [blame] | 389 | ctk_signal_widget_activate, |
| 390 | ctk_signal_widget_select, |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 391 | ctk_signal_timer, |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 392 | ctk_signal_menu_activate, |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 393 | ctk_signal_window_close, |
| 394 | ctk_signal_pointer_move, |
adamdunkels | 3a08a49 | 2003-04-11 20:16:02 +0000 | [diff] [blame] | 395 | ctk_signal_pointer_button; |
| 396 | |
adamdunkels | e8b21d0 | 2003-04-24 17:18:27 +0000 | [diff] [blame^] | 397 | #if CTK_CONF_SCREENSAVER |
| 398 | extern ek_signal_t ctk_signal_screensaver_start, |
| 399 | ctk_signal_screensaver_stop, |
| 400 | ctk_signal_screensaver_uninstall; |
| 401 | #endif /* CTK_CONF_SCREENSAVER */ |
| 402 | |
adamdunkels | 3a08a49 | 2003-04-11 20:16:02 +0000 | [diff] [blame] | 403 | /* These should no longer be used: */ |
| 404 | extern ek_signal_t ctk_signal_button_activate, |
| 405 | ctk_signal_button_hover, |
| 406 | ctk_signal_hyperlink_activate, |
| 407 | ctk_signal_hyperlink_hover; |
| 408 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 409 | /* 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__ */ |