adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 1 | /** |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 2 | * \defgroup ctk The CTK graphical user interface. |
| 3 | * @{ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 4 | * The Contiki Toolkit (CTK) provides the graphical user interface for |
| 5 | * the Contiki system. |
| 6 | * |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * \file |
| 11 | * The Contiki Toolkit CTK, the Contiki GUI. |
| 12 | * \author Adam Dunkels <adam@dunkels.com> |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 13 | */ |
| 14 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 15 | /* |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 16 | * Copyright (c) 2002-2003, Adam Dunkels. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 17 | * 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. |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 28 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 29 | * 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 | * |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 44 | * This file is part of the Contiki operating system. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 45 | * |
oliverschmidt | cd6c30b | 2005-05-05 20:54:16 +0000 | [diff] [blame] | 46 | * $Id: ctk.c,v 1.50 2005/05/05 20:54:16 oliverschmidt Exp $ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 47 | * |
| 48 | */ |
| 49 | |
| 50 | #include "ek.h" |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 51 | #include "cc.h" |
| 52 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 53 | #include "ctk.h" |
| 54 | #include "ctk-draw.h" |
| 55 | #include "ctk-conf.h" |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 56 | #include "ctk-mouse.h" |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 57 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 58 | #include "timer.h" |
| 59 | |
adamdunkels | 591724c | 2003-08-01 00:07:19 +0000 | [diff] [blame] | 60 | #include <string.h> |
| 61 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 62 | static unsigned char height, width; |
| 63 | |
| 64 | static unsigned char mode; |
| 65 | |
| 66 | static struct ctk_window desktop_window; |
| 67 | static struct ctk_window *windows; |
| 68 | static struct ctk_window *dialog; |
| 69 | |
| 70 | #if CTK_CONF_MENUS |
| 71 | static struct ctk_menus menus; |
| 72 | static struct ctk_menu *lastmenu; |
| 73 | static struct ctk_menu desktopmenu; |
| 74 | #endif /* CTK_CONF_MENUS */ |
| 75 | |
| 76 | #ifndef NULL |
| 77 | #define NULL (void *)0 |
| 78 | #endif /* NULL */ |
| 79 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 80 | #define REDRAW_NONE 0 |
| 81 | #define REDRAW_ALL 1 |
| 82 | #define REDRAW_FOCUS 2 |
| 83 | #define REDRAW_WIDGETS 4 |
| 84 | #define REDRAW_MENUS 8 |
| 85 | #define REDRAW_MENUPART 16 |
| 86 | |
| 87 | #define MAX_REDRAWWIDGETS 4 |
| 88 | static unsigned char redraw; |
| 89 | static struct ctk_widget *redraw_widgets[MAX_REDRAWWIDGETS]; |
| 90 | static unsigned char redraw_widgetptr; |
| 91 | static unsigned char maxnitems; |
| 92 | |
| 93 | static unsigned char iconx, icony; |
adamdunkels | 591724c | 2003-08-01 00:07:19 +0000 | [diff] [blame] | 94 | #define ICONX_START (width - 6) |
adamdunkels | 125483e | 2004-08-09 20:29:35 +0000 | [diff] [blame] | 95 | #define ICONY_START (height - 7) |
adamdunkels | 591724c | 2003-08-01 00:07:19 +0000 | [diff] [blame] | 96 | #define ICONX_DELTA -16 |
adamdunkels | 125483e | 2004-08-09 20:29:35 +0000 | [diff] [blame] | 97 | #define ICONY_DELTA -5 |
| 98 | #define ICONY_MAX height |
| 99 | #define ICONY_MIN 0 |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 100 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 101 | #ifndef ctk_arch_isprint |
| 102 | unsigned char ctk_arch_isprint(char c); |
| 103 | #endif /* ctk_arch_isprint */ |
| 104 | |
| 105 | EK_POLLHANDLER(ctk_poll); |
| 106 | EK_EVENTHANDLER(ctk_eventhandler, ev, data); |
| 107 | EK_PROCESS(p, "CTK Contiki GUI", EK_PRIO_NORMAL, ctk_eventhandler, |
| 108 | ctk_poll, NULL); |
| 109 | /*static struct ek_proc p = |
| 110 | {DISPATCHER_PROC("CTK Contiki GUI", ctk_idle, NULL, NULL)};*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 111 | static ek_id_t ctkid; |
| 112 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 113 | /** @} */ |
| 114 | |
| 115 | /** |
| 116 | * \addtogroup signals System signals |
| 117 | * @{ |
| 118 | */ |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 119 | ek_event_t |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 120 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 121 | /** |
| 122 | * Emitted for every key being pressed. |
| 123 | * |
| 124 | * The key is passed as signal data.*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 125 | ctk_signal_keypress, |
| 126 | |
| 127 | /** Emitted when a widget is activated (pressed). A pointer to the |
| 128 | widget is passed as signal data. */ |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 129 | ctk_signal_widget_activate, |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 130 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 131 | /** Same as ctk_signal_widget_activate. */ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 132 | ctk_signal_button_activate, |
| 133 | |
| 134 | /** Emitted when a widget is selected. A pointer to the widget is |
| 135 | passed as signal data. */ |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 136 | ctk_signal_widget_select, |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 137 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 138 | /** Same as ctk_signal_widget_select. */ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 139 | ctk_signal_button_hover, |
| 140 | |
| 141 | /** Emitted when a hyperlink is activated. The signal is broadcast |
| 142 | to all listeners. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 143 | ctk_signal_hyperlink_activate, |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 144 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 145 | /** Same as ctk_signal_widget_select. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 146 | ctk_signal_hyperlink_hover, |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 147 | |
| 148 | /** Emitted when a menu item is activated. The number of the menu |
| 149 | item is passed as signal data. */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 150 | ctk_signal_menu_activate, |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 151 | |
| 152 | /** Emitted when a window is closed. A pointer to the window is |
| 153 | passed as signal data. */ |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 154 | ctk_signal_window_close, |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 155 | |
| 156 | /** Emitted when the mouse pointer is moved. A NULL pointer is |
| 157 | passed as signal data and it is up to the listening process to |
| 158 | check the position of the mouse using the CTK mouse API.*/ |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 159 | ctk_signal_pointer_move, |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 160 | |
| 161 | /** Emitted when a mouse button is pressed. The button is passed as |
| 162 | signal data to the listening process. */ |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 163 | ctk_signal_pointer_button; |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 164 | |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 165 | #if CTK_CONF_SCREENSAVER |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 166 | /** Emitted when the user has been idle long enough for the |
| 167 | screensaver to start. */ |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 168 | ek_event_t ctk_signal_screensaver_stop, |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 169 | /** Emitted when the user presses a key or moves the mouse when the |
| 170 | screensaver is active. */ |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 171 | ctk_signal_screensaver_start; |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 172 | #endif /* CTK_CONF_SCREENSAVER */ |
| 173 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 174 | /** @} */ |
| 175 | |
| 176 | /** |
| 177 | * \addtogroup ctk |
| 178 | * @{ |
| 179 | */ |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 180 | |
adamdunkels | 19a787c | 2003-04-09 09:22:24 +0000 | [diff] [blame] | 181 | #if CTK_CONF_MOUSE_SUPPORT |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 182 | unsigned short mouse_x, mouse_y, mouse_button; |
adamdunkels | 19a787c | 2003-04-09 09:22:24 +0000 | [diff] [blame] | 183 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 184 | |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 185 | static unsigned short screensaver_timer = 0; |
adamdunkels | e2f4d2a | 2003-04-28 23:21:42 +0000 | [diff] [blame] | 186 | unsigned short ctk_screensaver_timeout = (5*60); |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 187 | /*static ek_clock_t start, current;*/ |
| 188 | static struct timer timer; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 189 | |
oliverschmidt | 1151124 | 2005-05-04 23:05:37 +0000 | [diff] [blame] | 190 | static void CC_FASTCALL |
| 191 | textentry_input(ctk_arch_key_t c, |
| 192 | CC_REGISTER_ARG struct ctk_textentry *t); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 193 | #if CTK_CONF_MENUS |
| 194 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 195 | /** |
| 196 | * \internal Creates the Desktop menu. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 197 | * |
| 198 | * Creates the leftmost menu, "Desktop". Since the desktop menu |
| 199 | * contains the list of all open windows, this function will be called |
| 200 | * whenever a window is opened or closed. |
| 201 | */ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 202 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 203 | static void |
| 204 | make_desktopmenu(void) |
| 205 | { |
| 206 | struct ctk_window *w; |
| 207 | |
| 208 | desktopmenu.nitems = 0; |
| 209 | |
| 210 | if(windows == NULL) { |
| 211 | ctk_menuitem_add(&desktopmenu, "(No windows)"); |
| 212 | } else { |
| 213 | for(w = windows; w != NULL; w = w->next) { |
| 214 | ctk_menuitem_add(&desktopmenu, w->title); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | #endif /* CTK_CONF_MENUS */ |
| 219 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 125483e | 2004-08-09 20:29:35 +0000 | [diff] [blame] | 220 | static void |
| 221 | arrange_icons(void) |
| 222 | { |
| 223 | struct ctk_widget *icon; |
| 224 | |
| 225 | iconx = ICONX_START; |
| 226 | icony = ICONY_START; |
| 227 | |
| 228 | for(icon = desktop_window.active; icon != NULL; icon = icon->next) { |
| 229 | |
| 230 | icon->x = iconx; |
| 231 | icon->y = icony; |
| 232 | |
| 233 | icony += ICONY_DELTA; |
| 234 | if(icony >= ICONY_MAX || |
| 235 | icony < ICONY_MIN) { |
| 236 | icony = ICONY_START; |
| 237 | iconx += ICONX_DELTA; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | /*-----------------------------------------------------------------------------------*/ |
| 242 | void |
| 243 | ctk_restore(void) |
| 244 | { |
| 245 | ctk_draw_init(); |
| 246 | |
| 247 | height = ctk_draw_height(); |
| 248 | width = ctk_draw_width(); |
| 249 | |
| 250 | arrange_icons(); |
| 251 | |
| 252 | redraw = REDRAW_ALL; |
| 253 | } |
| 254 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 255 | /** |
| 256 | * Initializes the Contiki Toolkit. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 257 | * |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 258 | * This function must be called before any other CTK function, but |
| 259 | * after the inizialitation of the dispatcher module. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 260 | */ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 261 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 262 | void |
| 263 | ctk_init(void) |
| 264 | { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 265 | ctkid = ek_start(&p); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 266 | |
| 267 | windows = NULL; |
| 268 | dialog = NULL; |
| 269 | |
| 270 | #if CTK_CONF_MENUS |
| 271 | ctk_menu_new(&desktopmenu, "Desktop"); |
| 272 | make_desktopmenu(); |
| 273 | menus.menus = menus.desktopmenu = &desktopmenu; |
| 274 | #endif /* CTK_CONF_MENUS */ |
| 275 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 276 | #if CTK_CONF_MOUSE_SUPPORT |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 277 | ctk_mouse_init(); |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 278 | ctk_mouse_show(); |
| 279 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 280 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 281 | ctk_draw_init(); |
| 282 | |
| 283 | height = ctk_draw_height(); |
| 284 | width = ctk_draw_width(); |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 285 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 286 | desktop_window.active = NULL; |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 287 | desktop_window.owner = ctkid; |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 288 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 289 | ctk_signal_keypress = ek_alloc_event(); |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 290 | |
| 291 | ctk_signal_button_activate = |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 292 | ctk_signal_widget_activate = ek_alloc_event(); |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 293 | |
| 294 | ctk_signal_button_hover = |
| 295 | ctk_signal_hyperlink_hover = |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 296 | ctk_signal_widget_select = ek_alloc_event(); |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 297 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 298 | ctk_signal_hyperlink_activate = ek_alloc_event(); |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 299 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 300 | ctk_signal_menu_activate = ek_alloc_event(); |
| 301 | ctk_signal_window_close = ek_alloc_event(); |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 302 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 303 | ctk_signal_pointer_move = ek_alloc_event(); |
| 304 | ctk_signal_pointer_button = ek_alloc_event(); |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 305 | |
| 306 | |
| 307 | #if CTK_CONF_SCREENSAVER |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 308 | ctk_signal_screensaver_start = ek_alloc_event(); |
| 309 | ctk_signal_screensaver_stop = ek_alloc_event(); |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 310 | #endif /* CTK_CONF_SCREENSAVER */ |
| 311 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 312 | |
| 313 | mode = CTK_MODE_NORMAL; |
| 314 | |
| 315 | iconx = ICONX_START; |
| 316 | icony = ICONY_START; |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 317 | |
| 318 | redraw = REDRAW_ALL; |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 319 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 320 | /* start = ek_clock();*/ |
| 321 | timer_set(&timer, CLOCK_SECOND); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 322 | } |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 323 | |
| 324 | /** |
| 325 | * \addtogroup ctkappfunc |
| 326 | * @{ |
| 327 | */ |
| 328 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 329 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 330 | /** |
| 331 | * Sets the current CTK mode. |
| 332 | * |
| 333 | * The CTK mode can be either CTK_MODE_NORMAL, CTK_MODE_SCREENSAVER or |
| 334 | * CTK_MODE_EXTERNAL. CTK_MODE_NORMAL is the normal mode, in which |
| 335 | * keypresses and mouse pointer movements are processed and the screen |
| 336 | * is redrawn. In CTK_MODE_SCREENSAVER, no screen redraws are |
| 337 | * performed and the first key press or pointer movement will cause |
| 338 | * the ctk_signal_screensaver_stop to be emitted. In the |
| 339 | * CTK_MODE_EXTERNAL mode, key presses and pointer movements are |
| 340 | * ignored and no screen redraws are made. |
| 341 | * |
| 342 | * \param m The mode. |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 343 | */ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 344 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 345 | void |
| 346 | ctk_mode_set(unsigned char m) { |
| 347 | mode = m; |
| 348 | } |
| 349 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 350 | /** |
| 351 | * Retrieves the current CTK mode. |
| 352 | * |
| 353 | * \return The current CTK mode. |
| 354 | */ |
| 355 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 356 | unsigned char |
| 357 | ctk_mode_get(void) { |
| 358 | return mode; |
| 359 | } |
| 360 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 361 | /** |
| 362 | * Add an icon to the desktop. |
| 363 | * |
| 364 | * \param icon The icon to be added. |
adamdunkels | 0404ef1 | 2003-09-04 19:36:04 +0000 | [diff] [blame] | 365 | * |
| 366 | * \param id The process ID of the process that owns the icon. |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 367 | */ |
| 368 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 369 | void |
adamdunkels | 0404ef1 | 2003-09-04 19:36:04 +0000 | [diff] [blame] | 370 | ctk_icon_add(CC_REGISTER_ARG struct ctk_widget *icon, ek_id_t id) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 371 | { |
adamdunkels | 0404ef1 | 2003-09-04 19:36:04 +0000 | [diff] [blame] | 372 | #if CTK_CONF_ICONS |
adamdunkels | 125483e | 2004-08-09 20:29:35 +0000 | [diff] [blame] | 373 | /* icon->x = iconx; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 374 | icon->y = icony; |
adamdunkels | 0404ef1 | 2003-09-04 19:36:04 +0000 | [diff] [blame] | 375 | icon->widget.icon.owner = id; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 376 | |
| 377 | icony += ICONY_DELTA; |
| 378 | if(icony >= ICONY_MAX) { |
| 379 | icony = ICONY_START; |
| 380 | iconx += ICONX_DELTA; |
adamdunkels | 125483e | 2004-08-09 20:29:35 +0000 | [diff] [blame] | 381 | }*/ |
| 382 | icon->widget.icon.owner = id; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 383 | ctk_widget_add(&desktop_window, icon); |
adamdunkels | 125483e | 2004-08-09 20:29:35 +0000 | [diff] [blame] | 384 | arrange_icons(); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 385 | #endif /* CTK_CONF_ICONS */ |
| 386 | } |
| 387 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 388 | /** |
| 389 | * Open a dialog box. |
| 390 | * |
| 391 | * \param d The dialog to be opened. |
| 392 | */ |
| 393 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 394 | void |
| 395 | ctk_dialog_open(struct ctk_window *d) |
| 396 | { |
| 397 | dialog = d; |
adamdunkels | 591724c | 2003-08-01 00:07:19 +0000 | [diff] [blame] | 398 | redraw |= REDRAW_FOCUS; |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 399 | } |
| 400 | /*-----------------------------------------------------------------------------------*/ |
| 401 | /** |
| 402 | * Close the dialog box, if one is open. |
| 403 | * |
| 404 | */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 405 | /*-----------------------------------------------------------------------------------*/ |
| 406 | void |
| 407 | ctk_dialog_close(void) |
| 408 | { |
| 409 | dialog = NULL; |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 410 | redraw |= REDRAW_ALL; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 411 | } |
| 412 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 413 | /** |
| 414 | * Open a window, or bring window to front if already open. |
| 415 | * |
| 416 | * \param w The window to be opened. |
| 417 | */ |
| 418 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 419 | void |
adamdunkels | d07a542 | 2003-04-05 12:22:35 +0000 | [diff] [blame] | 420 | ctk_window_open(CC_REGISTER_ARG struct ctk_window *w) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 421 | { |
| 422 | struct ctk_window *w2; |
| 423 | |
| 424 | /* Check if already open. */ |
| 425 | for(w2 = windows; w2 != w && w2 != NULL; w2 = w2->next); |
| 426 | if(w2 == NULL) { |
| 427 | /* Not open, so we add it at the head of the list of open |
| 428 | windows. */ |
| 429 | w->next = windows; |
| 430 | if(windows != NULL) { |
| 431 | windows->prev = w; |
| 432 | } |
| 433 | windows = w; |
| 434 | w->prev = NULL; |
| 435 | } else { |
| 436 | /* Window already open, so we move it to the front of the windows |
| 437 | list. */ |
| 438 | if(w != windows) { |
| 439 | if(w->next != NULL) { |
| 440 | w->next->prev = w->prev; |
| 441 | } |
| 442 | if(w->prev != NULL) { |
| 443 | w->prev->next = w->next; |
| 444 | } |
| 445 | w->next = windows; |
| 446 | windows->prev = w; |
| 447 | windows = w; |
| 448 | w->prev = NULL; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | #if CTK_CONF_MENUS |
| 453 | /* Recreate the Desktop menu's window entries.*/ |
| 454 | make_desktopmenu(); |
| 455 | #endif /* CTK_CONF_MENUS */ |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 456 | |
| 457 | redraw |= REDRAW_ALL; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 458 | } |
| 459 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 460 | /** |
| 461 | * Close a window if it is open. |
| 462 | * |
| 463 | * If the window is not open, this function does nothing. |
| 464 | * |
| 465 | * \param w The window to be closed. |
| 466 | */ |
| 467 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 468 | void |
| 469 | ctk_window_close(struct ctk_window *w) |
| 470 | { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 471 | static struct ctk_window *w2; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 472 | |
| 473 | if(w == NULL) { |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | /* Check if the window to be closed is the first window on the |
| 478 | list. */ |
| 479 | if(w == windows) { |
| 480 | windows = w->next; |
| 481 | if(windows != NULL) { |
| 482 | windows->prev = NULL; |
| 483 | } |
| 484 | w->next = w->prev = NULL; |
| 485 | } else { |
| 486 | /* Otherwise we step through the list until we find the window |
| 487 | before the one to be closed. We then redirect its ->next |
| 488 | pointer and its ->next->prev. */ |
adamdunkels | 3cf116a | 2003-04-08 19:28:15 +0000 | [diff] [blame] | 489 | for(w2 = windows; w2 != NULL && w2->next != w; w2 = w2->next); |
| 490 | |
| 491 | if(w2 == NULL) { |
| 492 | /* The window wasn't open, so there is nothing more for us to |
| 493 | do. */ |
| 494 | return; |
| 495 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 496 | |
| 497 | if(w->next != NULL) { |
| 498 | w->next->prev = w->prev; |
| 499 | } |
| 500 | w2->next = w->next; |
| 501 | |
| 502 | w->next = w->prev = NULL; |
| 503 | } |
| 504 | |
| 505 | #if CTK_CONF_MENUS |
| 506 | /* Recreate the Desktop menu's window entries.*/ |
| 507 | make_desktopmenu(); |
| 508 | #endif /* CTK_CONF_MENUS */ |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 509 | redraw |= REDRAW_ALL; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 510 | } |
| 511 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 512 | /** |
| 513 | * \internal Create the move and close buttons on the window titlebar. |
| 514 | */ |
| 515 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | d07a542 | 2003-04-05 12:22:35 +0000 | [diff] [blame] | 516 | static void |
| 517 | make_windowbuttons(CC_REGISTER_ARG struct ctk_window *window) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 518 | { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 519 | unsigned char placement; |
| 520 | |
| 521 | if(ctk_draw_windowtitle_height >= 2) { |
| 522 | placement = -1 - ctk_draw_windowtitle_height/2; |
| 523 | } else { |
| 524 | placement = -1; |
| 525 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 526 | #if CTK_CONF_WINDOWMOVE |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 527 | CTK_BUTTON_NEW(&window->titlebutton, 0, placement, |
| 528 | window->titlelen, window->title); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 529 | #else |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 530 | CTK_LABEL_NEW(&window->titlebutton, 0, placement, |
| 531 | window->titlelen, 1, window->title); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 532 | #endif /* CTK_CONF_WINDOWMOVE */ |
| 533 | CTK_WIDGET_ADD(window, &window->titlebutton); |
| 534 | |
| 535 | |
| 536 | #if CTK_CONF_WINDOWCLOSE |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 537 | CTK_BUTTON_NEW(&window->closebutton, window->w - 3, placement, |
| 538 | 1, "x"); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 539 | #else |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 540 | CTK_LABEL_NEW(&window->closebutton, window->w - 4, placement, |
| 541 | 3, 1, " "); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 542 | #endif /* CTK_CONF_WINDOWCLOSE */ |
| 543 | CTK_WIDGET_ADD(window, &window->closebutton); |
| 544 | } |
| 545 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 546 | /** |
| 547 | * Remove all widgets from a window. |
| 548 | * |
| 549 | * \param w The window to be cleared. |
| 550 | */ |
| 551 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 552 | void |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 553 | ctk_window_clear(struct ctk_window *w) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 554 | { |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 555 | w->active = w->inactive = w->focused = NULL; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 556 | |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 557 | make_windowbuttons(w); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 558 | } |
| 559 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 560 | /** |
| 561 | * Add a menu to the menu bar. |
| 562 | * |
| 563 | * \param menu The menu to be added. |
| 564 | * |
| 565 | * \note Do not call this function multiple times for the same menu, |
| 566 | * as no check is made to see if the menu already is in the menu bar. |
| 567 | */ |
| 568 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 569 | void |
| 570 | ctk_menu_add(struct ctk_menu *menu) |
| 571 | { |
| 572 | #if CTK_CONF_MENUS |
| 573 | struct ctk_menu *m; |
| 574 | |
| 575 | if(lastmenu == NULL) { |
| 576 | lastmenu = menu; |
| 577 | } |
| 578 | |
| 579 | for(m = menus.menus; m->next != NULL; m = m->next) { |
| 580 | if(m == menu) { |
| 581 | return; |
| 582 | } |
| 583 | } |
| 584 | m->next = menu; |
| 585 | menu->next = NULL; |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 586 | |
| 587 | redraw |= REDRAW_MENUPART; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 588 | #endif /* CTK_CONF_MENUS */ |
| 589 | } |
| 590 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 591 | /** |
| 592 | * Remove a menu from the menu bar. |
| 593 | * |
| 594 | * \param menu The menu to be removed. |
| 595 | */ |
| 596 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 597 | void |
| 598 | ctk_menu_remove(struct ctk_menu *menu) |
| 599 | { |
| 600 | #if CTK_CONF_MENUS |
| 601 | struct ctk_menu *m; |
| 602 | |
| 603 | for(m = menus.menus; m->next != NULL; m = m->next) { |
| 604 | if(m->next == menu) { |
| 605 | m->next = menu->next; |
adamdunkels | 4662303 | 2003-08-12 21:12:59 +0000 | [diff] [blame] | 606 | if(menu == lastmenu) { |
| 607 | lastmenu = NULL; |
| 608 | } |
| 609 | redraw |= REDRAW_MENUPART; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 610 | return; |
| 611 | } |
| 612 | } |
| 613 | #endif /* CTK_CONF_MENUS */ |
| 614 | } |
| 615 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 616 | /** |
| 617 | * \internal Redraws everything on the screen within the clip |
| 618 | * interval. |
| 619 | * |
| 620 | * \param clipy1 The upper bound of the clip interval |
| 621 | * \param clipy2 The lower bound of the clip interval |
| 622 | */ |
| 623 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 624 | static void CC_FASTCALL |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 625 | do_redraw_all(unsigned char clipy1, unsigned char clipy2) |
| 626 | { |
| 627 | struct ctk_window *w; |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 628 | static struct ctk_widget *widget; |
oliverschmidt | e99386b | 2004-12-27 22:03:04 +0000 | [diff] [blame] | 629 | unsigned char focus; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 630 | |
| 631 | if(mode != CTK_MODE_NORMAL && |
| 632 | mode != CTK_MODE_WINDOWMOVE) { |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | ctk_draw_clear(clipy1, clipy2); |
| 637 | |
| 638 | /* Draw widgets in root window */ |
| 639 | for(widget = desktop_window.active; |
| 640 | widget != NULL; widget = widget->next) { |
oliverschmidt | f42b7bc | 2004-06-27 15:04:01 +0000 | [diff] [blame] | 641 | ctk_draw_widget(widget, windows != NULL? 0: CTK_FOCUS_WINDOW, clipy1, clipy2); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /* Draw windows */ |
| 645 | if(windows != NULL) { |
| 646 | /* Find the last window.*/ |
| 647 | for(w = windows; w->next != NULL; w = w->next); |
| 648 | |
| 649 | /* Draw the windows from back to front. */ |
| 650 | for(; w != windows; w = w->prev) { |
adamdunkels | 9d3a0e5 | 2003-04-02 09:53:59 +0000 | [diff] [blame] | 651 | ctk_draw_clear_window(w, 0, clipy1, clipy2); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 652 | ctk_draw_window(w, 0, clipy1, clipy2, 1); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 653 | } |
oliverschmidt | e99386b | 2004-12-27 22:03:04 +0000 | [diff] [blame] | 654 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 655 | /* Draw focused window */ |
oliverschmidt | e99386b | 2004-12-27 22:03:04 +0000 | [diff] [blame] | 656 | focus = mode == CTK_MODE_WINDOWMOVE? |
| 657 | CTK_FOCUS_WIDGET|CTK_FOCUS_WINDOW: |
| 658 | CTK_FOCUS_WINDOW; |
| 659 | ctk_draw_clear_window(windows, focus, clipy1, clipy2); |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 660 | ctk_draw_window(windows, focus, clipy1, clipy2, 1); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /* Draw dialog (if any) */ |
| 664 | if(dialog != NULL) { |
| 665 | ctk_draw_dialog(dialog); |
| 666 | } |
| 667 | |
| 668 | #if CTK_CONF_MENUS |
| 669 | ctk_draw_menus(&menus); |
| 670 | #endif /* CTK_CONF_MENUS */ |
| 671 | } |
| 672 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 673 | /** |
| 674 | * Redraw the entire desktop. |
| 675 | * |
| 676 | * \param d The desktop to be redrawn. |
| 677 | * |
| 678 | * \note Currently the parameter d is not used, but must be set to |
| 679 | * NULL. |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 680 | * |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 681 | */ |
| 682 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 683 | void |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 684 | ctk_desktop_redraw(struct ctk_desktop *d) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 685 | { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 686 | if(EK_CURRENT() == &p) { |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 687 | if(mode == CTK_MODE_NORMAL || |
| 688 | mode == CTK_MODE_WINDOWMOVE) { |
| 689 | do_redraw_all(1, height); |
| 690 | } |
| 691 | } else { |
| 692 | redraw |= REDRAW_ALL; |
| 693 | } |
| 694 | } |
| 695 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 696 | /** |
| 697 | * Redraw a window. |
| 698 | * |
| 699 | * This function redraws the window, but only if it is the foremost |
| 700 | * one on the desktop. |
| 701 | * |
| 702 | * \param w The window to be redrawn. |
| 703 | */ |
| 704 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 705 | void |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 706 | ctk_window_redraw(struct ctk_window *w) |
| 707 | { |
| 708 | /* Only redraw the window if it is a dialog or if it is the foremost |
| 709 | window. */ |
| 710 | if(mode != CTK_MODE_NORMAL) { |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | if(w == dialog) { |
| 715 | ctk_draw_dialog(w); |
| 716 | } else if(dialog == NULL && |
| 717 | #if CTK_CONF_MENUS |
| 718 | menus.open == NULL && |
| 719 | #endif /* CTK_CONF_MENUS */ |
| 720 | windows == w) { |
| 721 | ctk_draw_window(w, CTK_FOCUS_WINDOW, |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 722 | 0, height, 0); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 726 | /** |
| 727 | * \internal Creates a new window. |
| 728 | * |
| 729 | * \param window The window to be created. |
| 730 | * \param w The width of the window. |
| 731 | * \param h The height of the window. |
| 732 | * \param title The title of the window. |
| 733 | */ |
| 734 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 735 | static void |
adamdunkels | d07a542 | 2003-04-05 12:22:35 +0000 | [diff] [blame] | 736 | window_new(CC_REGISTER_ARG struct ctk_window *window, |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 737 | unsigned char w, unsigned char h, |
| 738 | char *title) |
| 739 | { |
adamdunkels | 4b7a7ab | 2003-04-09 19:22:19 +0000 | [diff] [blame] | 740 | |
| 741 | if(w >= width - 2) { |
| 742 | window->x = 0; |
| 743 | } else { |
| 744 | window->x = (width - w - 2) / 2; |
| 745 | } |
oliverschmidt | 432bc5a | 2004-12-22 22:52:53 +0000 | [diff] [blame] | 746 | if(h >= height - 2 - ctk_draw_windowtitle_height) { |
adamdunkels | 4b7a7ab | 2003-04-09 19:22:19 +0000 | [diff] [blame] | 747 | window->y = 0; |
| 748 | } else { |
oliverschmidt | 432bc5a | 2004-12-22 22:52:53 +0000 | [diff] [blame] | 749 | window->y = (height - h - 2 - ctk_draw_windowtitle_height) / 2; |
adamdunkels | 4b7a7ab | 2003-04-09 19:22:19 +0000 | [diff] [blame] | 750 | } |
| 751 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 752 | window->w = w; |
| 753 | window->h = h; |
| 754 | window->title = title; |
| 755 | if(title != NULL) { |
| 756 | window->titlelen = strlen(title); |
| 757 | } else { |
| 758 | window->titlelen = 0; |
| 759 | } |
| 760 | window->next = window->prev = NULL; |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 761 | /* window->owner = DISPATCHER_CURRENT();*/ |
| 762 | window->owner = EK_PROC_ID(EK_CURRENT()); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 763 | window->active = window->inactive = window->focused = NULL; |
| 764 | } |
| 765 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 766 | /** |
| 767 | * Create a new window. |
| 768 | * |
| 769 | * Creates a new window. The memory for the window structure must |
| 770 | * already be allocated by the caller, and is usually done with a |
| 771 | * static declaration. |
| 772 | * |
| 773 | * This function sets up the internal structure of the ctk_window |
| 774 | * struct and creates the move and close buttons, but it does not open |
| 775 | * the window. The window must be explicitly opened by calling the |
| 776 | * ctk_window_open() function. |
| 777 | * |
| 778 | * \param window The window to be created. |
| 779 | * \param w The width of the new window. |
| 780 | * \param h The height of the new window. |
| 781 | * \param title The title of the new window. |
| 782 | */ |
| 783 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 784 | void |
| 785 | ctk_window_new(struct ctk_window *window, |
| 786 | unsigned char w, unsigned char h, |
| 787 | char *title) |
| 788 | { |
| 789 | window_new(window, w, h, title); |
| 790 | |
| 791 | make_windowbuttons(window); |
| 792 | } |
| 793 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 794 | /** |
| 795 | * Creates a new dialog. |
| 796 | * |
| 797 | * This function only sets up the internal structure of the ctk_window |
| 798 | * struct but does not open the dialog. The dialog must be explicitly |
| 799 | * opened by calling the ctk_dialog_open() function. |
| 800 | * |
| 801 | * \param dialog The dialog to be created. |
| 802 | * \param w The width of the dialog. |
| 803 | * \param h The height of the dialog. |
| 804 | */ |
| 805 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 806 | void |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 807 | ctk_dialog_new(CC_REGISTER_ARG struct ctk_window *dialog, |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 808 | unsigned char w, unsigned char h) |
| 809 | { |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 810 | window_new(dialog, w, h, NULL); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 811 | } |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 812 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 813 | /** |
| 814 | * Creates a new menu. |
| 815 | * |
| 816 | * This function sets up the internal structure of the menu, but does |
| 817 | * not add it to the menubar. Use the function ctk_menu_add() for that |
| 818 | * purpose. |
| 819 | * |
| 820 | * \param menu The menu to be created. |
| 821 | * \param title The title of the menu. |
| 822 | */ |
| 823 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 824 | void |
adamdunkels | d07a542 | 2003-04-05 12:22:35 +0000 | [diff] [blame] | 825 | ctk_menu_new(CC_REGISTER_ARG struct ctk_menu *menu, |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 826 | char *title) |
| 827 | { |
| 828 | #if CTK_CONF_MENUS |
| 829 | menu->next = NULL; |
| 830 | menu->title = title; |
| 831 | menu->titlelen = strlen(title); |
| 832 | menu->active = 0; |
| 833 | menu->nitems = 0; |
| 834 | #endif /* CTK_CONF_MENUS */ |
| 835 | } |
| 836 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 837 | /** |
| 838 | * Adds a menu item to a menu. |
| 839 | * |
| 840 | * In CTK, each menu item is identified by a number which is unique |
| 841 | * within each menu. When a menu item is selected, a |
| 842 | * ctk_menuitem_activated signal is emitted and the menu item number |
| 843 | * is passed as signal data with the signal. |
| 844 | * |
| 845 | * \param menu The menu to which the menu item should be added. |
| 846 | * \param name The name of the menu item. |
| 847 | * \return The number of the menu item. |
| 848 | */ |
| 849 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 850 | unsigned char |
adamdunkels | d07a542 | 2003-04-05 12:22:35 +0000 | [diff] [blame] | 851 | ctk_menuitem_add(CC_REGISTER_ARG struct ctk_menu *menu, |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 852 | char *name) |
| 853 | { |
| 854 | #if CTK_CONF_MENUS |
| 855 | if(menu->nitems == CTK_CONF_MAXMENUITEMS) { |
| 856 | return 0; |
| 857 | } |
| 858 | menu->items[menu->nitems].title = name; |
| 859 | menu->items[menu->nitems].titlelen = strlen(name); |
| 860 | return menu->nitems++; |
| 861 | #else |
| 862 | return 0; |
| 863 | #endif /* CTK_CONF_MENUS */ |
| 864 | } |
| 865 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 866 | /** |
| 867 | * \internal Adds a widget to the list of widgets that should be |
| 868 | * redrawn. |
| 869 | * |
| 870 | * \param w The widget that should be redrawn. |
| 871 | */ |
| 872 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 873 | static void CC_FASTCALL |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 874 | add_redrawwidget(struct ctk_widget *w) |
| 875 | { |
| 876 | static unsigned char i; |
| 877 | |
| 878 | if(redraw_widgetptr == MAX_REDRAWWIDGETS) { |
| 879 | redraw |= REDRAW_FOCUS; |
| 880 | } else { |
| 881 | redraw |= REDRAW_WIDGETS; |
| 882 | /* Check if it is in the queue already. If so, we don't add it |
| 883 | again. */ |
| 884 | for(i = 0; i < redraw_widgetptr; ++i) { |
| 885 | if(redraw_widgets[i] == w) { |
| 886 | return; |
| 887 | } |
| 888 | } |
| 889 | redraw_widgets[redraw_widgetptr++] = w; |
| 890 | } |
| 891 | } |
| 892 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 893 | /** |
| 894 | * \internal Checks if a widget redrawn and adds it to the list of |
| 895 | * widgets to be redrawn. |
| 896 | * |
| 897 | * A widget can be redrawn only if the current CTK mode is |
| 898 | * CTK_MODE_NORMAL, if no menu is open, and the widget is in the |
| 899 | * foremost window. |
| 900 | * |
| 901 | * \param widget The widget that should be redrawn. |
| 902 | */ |
| 903 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c4dbb8d | 2003-08-29 20:38:54 +0000 | [diff] [blame] | 904 | static void |
| 905 | widget_redraw(struct ctk_widget *widget) |
| 906 | { |
| 907 | struct ctk_window *window; |
| 908 | |
| 909 | if(mode != CTK_MODE_NORMAL || widget == NULL) { |
| 910 | return; |
| 911 | } |
| 912 | |
| 913 | /* Only redraw widgets that are in the foremost window. If we would |
| 914 | allow redrawing widgets in non-focused windows, we would have to |
| 915 | redraw all the windows that cover the non-focused window as well, |
| 916 | which would lead to flickering. |
| 917 | |
| 918 | Also, we avoid drawing any widgets when the menus are active. |
| 919 | */ |
| 920 | |
| 921 | #if CTK_CONF_MENUS |
| 922 | if(menus.open == NULL) |
| 923 | #endif /* CTK_CONF_MENUS */ |
| 924 | { |
| 925 | window = widget->window; |
| 926 | if(window == dialog) { |
| 927 | ctk_draw_widget(widget, CTK_FOCUS_DIALOG, 0, height); |
| 928 | } else if(dialog == NULL && |
| 929 | (window == windows || |
| 930 | window == &desktop_window)) { |
| 931 | ctk_draw_widget(widget, CTK_FOCUS_WINDOW, 0, height); |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 936 | /** |
| 937 | * Redraws a widget. |
| 938 | * |
| 939 | * This function will set a flag which causes the widget to be redrawn |
| 940 | * next time the CTK process is scheduled. |
| 941 | * |
| 942 | * \param widget The widget that is to be redrawn. |
| 943 | * |
| 944 | * \note This function should usually not be called directly since it |
| 945 | * requires typecasting of the widget parameter. The wrapper macro |
| 946 | * CTK_WIDGET_REDRAW() does the required typecast and should be used |
| 947 | * instead. |
| 948 | */ |
| 949 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 950 | void |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 951 | ctk_widget_redraw(struct ctk_widget *widget) |
| 952 | { |
adamdunkels | 9f667f2 | 2003-04-16 18:29:19 +0000 | [diff] [blame] | 953 | if(mode != CTK_MODE_NORMAL || widget == NULL) { |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 954 | return; |
| 955 | } |
| 956 | |
adamdunkels | c4dbb8d | 2003-08-29 20:38:54 +0000 | [diff] [blame] | 957 | /* Since this function isn't called by CTK itself, we only queue the |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 958 | redraw request. */ |
adamdunkels | c4dbb8d | 2003-08-29 20:38:54 +0000 | [diff] [blame] | 959 | add_redrawwidget(widget); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 960 | } |
| 961 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 962 | /** |
| 963 | * Adds a widget to a window. |
| 964 | * |
| 965 | * This function adds a widget to a window. The order of which the |
| 966 | * widgets are added is important, as it sets the order to which |
| 967 | * widgets are cycled with the widget selection keys. |
| 968 | * |
| 969 | * \param window The window to which the widhet should be added. |
| 970 | * \param widget The widget to be added. |
| 971 | */ |
| 972 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 973 | void CC_FASTCALL |
adamdunkels | d07a542 | 2003-04-05 12:22:35 +0000 | [diff] [blame] | 974 | ctk_widget_add(CC_REGISTER_ARG struct ctk_window *window, |
| 975 | CC_REGISTER_ARG struct ctk_widget *widget) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 976 | { |
| 977 | if(widget->type == CTK_WIDGET_LABEL || |
| 978 | widget->type == CTK_WIDGET_SEPARATOR) { |
| 979 | widget->next = window->inactive; |
| 980 | window->inactive = widget; |
| 981 | widget->window = window; |
| 982 | } else { |
| 983 | widget->next = window->active; |
| 984 | window->active = widget; |
| 985 | widget->window = window; |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 986 | /* if(window->focused == NULL) { |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 987 | window->focused = widget; |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 988 | }*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 992 | /** |
| 993 | * Gets the width of the desktop. |
| 994 | * |
| 995 | * \param d The desktop. |
| 996 | * \return The width of the desktop, in characters. |
| 997 | * |
| 998 | * \note The d parameter is currently unused and must be set to NULL. |
| 999 | */ |
| 1000 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | e2f4d2a | 2003-04-28 23:21:42 +0000 | [diff] [blame] | 1001 | unsigned char |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 1002 | ctk_desktop_width(struct ctk_desktop *d) |
adamdunkels | e2f4d2a | 2003-04-28 23:21:42 +0000 | [diff] [blame] | 1003 | { |
| 1004 | return ctk_draw_width(); |
| 1005 | } |
| 1006 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 1007 | /** |
| 1008 | * Gets the height of the desktop. |
| 1009 | * |
| 1010 | * \param d The desktop. |
| 1011 | * \return The height of the desktop, in characters. |
| 1012 | * |
| 1013 | * \note The d parameter is currently unused and must be set to NULL. |
| 1014 | */ |
| 1015 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | e2f4d2a | 2003-04-28 23:21:42 +0000 | [diff] [blame] | 1016 | unsigned char |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 1017 | ctk_desktop_height(struct ctk_desktop *d) |
adamdunkels | e2f4d2a | 2003-04-28 23:21:42 +0000 | [diff] [blame] | 1018 | { |
| 1019 | return ctk_draw_height(); |
| 1020 | } |
| 1021 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3529869 | 2003-08-31 22:16:49 +0000 | [diff] [blame] | 1022 | /** |
| 1023 | * \internal Selects a widget in the window of the widget. |
| 1024 | * |
| 1025 | * \param focus The widget to be focused. |
| 1026 | */ |
| 1027 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1028 | static void CC_FASTCALL |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1029 | select_widget(struct ctk_widget *focus) |
adamdunkels | e068331 | 2003-04-09 09:02:52 +0000 | [diff] [blame] | 1030 | { |
| 1031 | struct ctk_window *window; |
| 1032 | |
| 1033 | window = focus->window; |
| 1034 | |
| 1035 | if(focus != window->focused) { |
| 1036 | window->focused = focus; |
| 1037 | /* The operation changed the focus, so we emit a "hover" signal |
| 1038 | for those widgets that support it. */ |
| 1039 | |
| 1040 | if(window->focused->type == CTK_WIDGET_HYPERLINK) { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1041 | ek_post(window->owner, ctk_signal_hyperlink_hover, window->focused); |
adamdunkels | e068331 | 2003-04-09 09:02:52 +0000 | [diff] [blame] | 1042 | } else if(window->focused->type == CTK_WIDGET_BUTTON) { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1043 | ek_post(window->owner, ctk_signal_button_hover, window->focused); |
adamdunkels | e068331 | 2003-04-09 09:02:52 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | add_redrawwidget(window->focused); |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 1047 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1048 | ek_post(focus->window->owner, ctk_signal_widget_select, focus); |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 1049 | |
adamdunkels | e068331 | 2003-04-09 09:02:52 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | } |
| 1053 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1054 | #define UP 0 |
| 1055 | #define DOWN 1 |
| 1056 | #define LEFT 2 |
| 1057 | #define RIGHT 3 |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1058 | static void CC_FASTCALL |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1059 | switch_focus_widget(unsigned char direction) |
| 1060 | { |
| 1061 | register struct ctk_window *window; |
| 1062 | register struct ctk_widget *focus; |
| 1063 | struct ctk_widget *widget; |
| 1064 | |
| 1065 | |
| 1066 | if(dialog != NULL) { |
| 1067 | window = dialog; |
| 1068 | } else { |
| 1069 | window = windows; |
| 1070 | } |
| 1071 | |
| 1072 | /* If there are no windows open, we move focus around between the |
| 1073 | icons on the root window instead. */ |
| 1074 | if(window == NULL) { |
| 1075 | window = &desktop_window; |
| 1076 | } |
| 1077 | |
| 1078 | focus = window->focused; |
adamdunkels | e8bdfe1 | 2003-04-25 08:49:17 +0000 | [diff] [blame] | 1079 | if(focus == NULL) { |
| 1080 | focus = window->active; |
adamdunkels | 6b9d5e8 | 2004-09-19 15:24:19 +0000 | [diff] [blame] | 1081 | if(focus == NULL) { |
| 1082 | return; |
| 1083 | } |
adamdunkels | e8bdfe1 | 2003-04-25 08:49:17 +0000 | [diff] [blame] | 1084 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1085 | add_redrawwidget(focus); |
| 1086 | |
| 1087 | if((direction & 1) == 0) { |
| 1088 | /* Move focus "up" */ |
| 1089 | focus = focus->next; |
| 1090 | } else { |
| 1091 | /* Move focus "down" */ |
| 1092 | for(widget = window->active; |
| 1093 | widget != NULL; widget = widget->next) { |
| 1094 | if(widget->next == focus) { |
| 1095 | break; |
| 1096 | } |
| 1097 | } |
| 1098 | focus = widget; |
| 1099 | if(focus == NULL) { |
| 1100 | if(window->active != NULL) { |
| 1101 | for(focus = window->active; |
adamdunkels | a05d540 | 2003-08-24 22:38:12 +0000 | [diff] [blame] | 1102 | focus->next != NULL; focus = focus->next); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | if(focus == NULL) { |
| 1107 | focus = window->active; |
| 1108 | } |
adamdunkels | e068331 | 2003-04-09 09:02:52 +0000 | [diff] [blame] | 1109 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1110 | select_widget(focus); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1111 | } |
| 1112 | /*-----------------------------------------------------------------------------------*/ |
| 1113 | #if CTK_CONF_MENUS |
| 1114 | static void |
| 1115 | switch_open_menu(unsigned char rightleft) |
| 1116 | { |
| 1117 | struct ctk_menu *menu; |
| 1118 | |
| 1119 | if(rightleft == 0) { |
| 1120 | /* Move right */ |
| 1121 | for(menu = menus.menus; menu != NULL; menu = menu->next) { |
| 1122 | if(menu->next == menus.open) { |
| 1123 | break; |
| 1124 | } |
| 1125 | } |
| 1126 | lastmenu = menus.open; |
| 1127 | menus.open = menu; |
| 1128 | if(menus.open == NULL) { |
| 1129 | for(menu = menus.menus; |
| 1130 | menu->next != NULL; menu = menu->next); |
| 1131 | menus.open = menu; |
| 1132 | } |
| 1133 | } else { |
| 1134 | /* Move to left */ |
| 1135 | lastmenu = menus.open; |
| 1136 | menus.open = menus.open->next; |
| 1137 | if(menus.open == NULL) { |
| 1138 | menus.open = menus.menus; |
| 1139 | } |
| 1140 | } |
| 1141 | |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 1142 | menus.open->active = 0; |
| 1143 | |
| 1144 | /* if(menus.open->nitems > maxnitems) { |
| 1145 | maxnitems = menus.open->nitems; |
| 1146 | }*/ |
| 1147 | |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1148 | /* ctk_desktop_redraw();*/ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1149 | } |
| 1150 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 1151 | static void |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1152 | switch_menu_item(unsigned char updown) |
| 1153 | { |
| 1154 | register struct ctk_menu *m; |
| 1155 | |
| 1156 | m = menus.open; |
| 1157 | |
| 1158 | if(updown == 0) { |
| 1159 | /* Move up */ |
| 1160 | if(m->active == 0) { |
| 1161 | m->active = m->nitems - 1; |
| 1162 | } else { |
| 1163 | --m->active; |
| 1164 | if(m->items[m->active].title[0] == '-') { |
| 1165 | --m->active; |
| 1166 | } |
| 1167 | } |
| 1168 | } else { |
| 1169 | /* Move down */ |
| 1170 | if(m->active >= m->nitems - 1) { |
| 1171 | m->active = 0; |
| 1172 | } else { |
| 1173 | ++m->active; |
| 1174 | if(m->items[m->active].title[0] == '-') { |
| 1175 | ++m->active; |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | } |
| 1181 | #endif /* CTK_CONF_MENUS */ |
| 1182 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1183 | static unsigned char CC_FASTCALL |
adamdunkels | d07a542 | 2003-04-05 12:22:35 +0000 | [diff] [blame] | 1184 | activate(CC_REGISTER_ARG struct ctk_widget *w) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1185 | { |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1186 | if(w->type == CTK_WIDGET_BUTTON) { |
| 1187 | if(w == (struct ctk_widget *)&windows->closebutton) { |
| 1188 | #if CTK_CONF_WINDOWCLOSE |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1189 | ek_post(w->window->owner, ctk_signal_window_close, windows); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1190 | ctk_window_close(windows); |
| 1191 | return REDRAW_ALL; |
| 1192 | #endif /* CTK_CONF_WINDOWCLOSE */ |
| 1193 | } else if(w == (struct ctk_widget *)&windows->titlebutton) { |
oliverschmidt | e99386b | 2004-12-27 22:03:04 +0000 | [diff] [blame] | 1194 | #if CTK_CONF_WINDOWMOVE |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1195 | mode = CTK_MODE_WINDOWMOVE; |
oliverschmidt | e99386b | 2004-12-27 22:03:04 +0000 | [diff] [blame] | 1196 | return REDRAW_ALL; |
| 1197 | #endif /* CTK_CONF_WINDOWMOVE */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1198 | } else { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1199 | ek_post(w->window->owner, ctk_signal_widget_activate, w); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1200 | } |
| 1201 | #if CTK_CONF_ICONS |
| 1202 | } else if(w->type == CTK_WIDGET_ICON) { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1203 | if(w->widget.icon.owner != EK_ID_NONE) { |
| 1204 | ek_post(w->widget.icon.owner, ctk_signal_widget_activate, w); |
| 1205 | } else { |
| 1206 | ek_post(w->window->owner, ctk_signal_widget_activate, w); |
| 1207 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1208 | #endif /* CTK_CONF_ICONS */ |
| 1209 | } else if(w->type == CTK_WIDGET_HYPERLINK) { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1210 | ek_post(EK_BROADCAST, ctk_signal_hyperlink_activate, w); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1211 | } else if(w->type == CTK_WIDGET_TEXTENTRY) { |
| 1212 | if(w->widget.textentry.state == CTK_TEXTENTRY_NORMAL) { |
oliverschmidt | 1151124 | 2005-05-04 23:05:37 +0000 | [diff] [blame] | 1213 | w->widget.textentry.state = CTK_TEXTENTRY_EDIT; |
| 1214 | textentry_input(0, (struct ctk_textentry *)w); |
oliverschmidt | f28743b | 2005-05-04 22:33:45 +0000 | [diff] [blame] | 1215 | } else { |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1216 | w->widget.textentry.state = CTK_TEXTENTRY_NORMAL; |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1217 | ek_post(w->window->owner, ctk_signal_widget_activate, w); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1218 | } |
| 1219 | add_redrawwidget(w); |
| 1220 | return REDRAW_WIDGETS; |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 1221 | } else { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1222 | ek_post(w->window->owner, ctk_signal_widget_activate, w); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1223 | } |
| 1224 | return REDRAW_NONE; |
| 1225 | } |
| 1226 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1227 | static void CC_FASTCALL |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1228 | textentry_input(ctk_arch_key_t c, |
adamdunkels | d07a542 | 2003-04-05 12:22:35 +0000 | [diff] [blame] | 1229 | CC_REGISTER_ARG struct ctk_textentry *t) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1230 | { |
adamdunkels | af610eb | 2003-08-05 13:50:51 +0000 | [diff] [blame] | 1231 | register char *cptr, *cptr2; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1232 | static unsigned char len, txpos, typos, tlen; |
| 1233 | |
oliverschmidt | 0096f6a | 2005-05-04 21:50:17 +0000 | [diff] [blame] | 1234 | if(t->input != NULL && t->input(c, t)) { |
| 1235 | return; |
| 1236 | } |
| 1237 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1238 | txpos = t->xpos; |
| 1239 | typos = t->ypos; |
| 1240 | tlen = t->len; |
| 1241 | |
oliverschmidt | cd6c30b | 2005-05-05 20:54:16 +0000 | [diff] [blame] | 1242 | cptr = &t->text[txpos + typos * (tlen + 1)]; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1243 | |
| 1244 | switch(c) { |
| 1245 | case CH_CURS_LEFT: |
| 1246 | if(txpos > 0) { |
| 1247 | --txpos; |
| 1248 | } |
| 1249 | break; |
| 1250 | |
| 1251 | case CH_CURS_RIGHT: |
oliverschmidt | d52d46c | 2004-06-14 22:11:01 +0000 | [diff] [blame] | 1252 | if(txpos < tlen - 1 && *cptr != 0) { |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1253 | ++txpos; |
| 1254 | } |
| 1255 | break; |
| 1256 | |
| 1257 | case CH_CURS_UP: |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1258 | txpos = 0; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1259 | break; |
| 1260 | |
oliverschmidt | 1151124 | 2005-05-04 23:05:37 +0000 | [diff] [blame] | 1261 | case 0: |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1262 | case CH_CURS_DOWN: |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1263 | txpos = strlen(t->text); |
oliverschmidt | d52d46c | 2004-06-14 22:11:01 +0000 | [diff] [blame] | 1264 | if(txpos == tlen) { |
| 1265 | --txpos; |
| 1266 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1267 | break; |
| 1268 | |
| 1269 | case CH_ENTER: |
adamdunkels | 04ec5b4 | 2003-08-20 20:55:22 +0000 | [diff] [blame] | 1270 | /* t->state = CTK_TEXTENTRY_NORMAL;*/ |
| 1271 | activate((struct ctk_widget *)t); |
adamdunkels | a05d540 | 2003-08-24 22:38:12 +0000 | [diff] [blame] | 1272 | switch_focus_widget(DOWN); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1273 | break; |
| 1274 | |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 1275 | case CTK_CONF_WIDGETDOWN_KEY: |
| 1276 | t->state = CTK_TEXTENTRY_NORMAL; |
| 1277 | switch_focus_widget(DOWN); |
| 1278 | break; |
| 1279 | case CTK_CONF_WIDGETUP_KEY: |
| 1280 | t->state = CTK_TEXTENTRY_NORMAL; |
| 1281 | switch_focus_widget(UP); |
| 1282 | break; |
| 1283 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1284 | default: |
oliverschmidt | d52d46c | 2004-06-14 22:11:01 +0000 | [diff] [blame] | 1285 | len = tlen - txpos; |
| 1286 | if(c == CH_DEL) { |
| 1287 | if(len == 1 && *cptr != 0) { |
| 1288 | *cptr = 0; |
adamdunkels | c961908 | 2004-06-06 06:19:25 +0000 | [diff] [blame] | 1289 | } else { |
oliverschmidt | d52d46c | 2004-06-14 22:11:01 +0000 | [diff] [blame] | 1290 | if(txpos > 0) { |
| 1291 | --txpos; |
| 1292 | strcpy(cptr - 1, cptr); |
| 1293 | } |
| 1294 | } |
| 1295 | } else { |
| 1296 | if(ctk_arch_isprint(c)) { |
| 1297 | if(len > 1) { |
adamdunkels | c961908 | 2004-06-06 06:19:25 +0000 | [diff] [blame] | 1298 | cptr2 = cptr + len - 1; |
oliverschmidt | d52d46c | 2004-06-14 22:11:01 +0000 | [diff] [blame] | 1299 | while(cptr2 > cptr) { |
| 1300 | *cptr2 = *(cptr2 - 1); |
adamdunkels | c961908 | 2004-06-06 06:19:25 +0000 | [diff] [blame] | 1301 | --cptr2; |
| 1302 | } |
adamdunkels | c961908 | 2004-06-06 06:19:25 +0000 | [diff] [blame] | 1303 | ++txpos; |
| 1304 | } |
oliverschmidt | d52d46c | 2004-06-14 22:11:01 +0000 | [diff] [blame] | 1305 | *cptr = c; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | break; |
| 1309 | } |
| 1310 | |
| 1311 | t->xpos = txpos; |
| 1312 | t->ypos = typos; |
| 1313 | } |
| 1314 | /*-----------------------------------------------------------------------------------*/ |
| 1315 | #if CTK_CONF_MENUS |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 1316 | static unsigned char |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1317 | activate_menu(void) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1318 | { |
| 1319 | struct ctk_window *w; |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1320 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1321 | lastmenu = menus.open; |
| 1322 | if(menus.open == &desktopmenu) { |
| 1323 | for(w = windows; w != NULL; w = w->next) { |
| 1324 | if(w->title == desktopmenu.items[desktopmenu.active].title) { |
| 1325 | ctk_window_open(w); |
| 1326 | menus.open = NULL; |
| 1327 | return REDRAW_ALL; |
| 1328 | } |
| 1329 | } |
| 1330 | } else { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1331 | ek_post(EK_BROADCAST, ctk_signal_menu_activate, menus.open); |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1332 | } |
| 1333 | menus.open = NULL; |
| 1334 | return REDRAW_MENUPART; |
| 1335 | } |
| 1336 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1337 | static unsigned char |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1338 | menus_input(ctk_arch_key_t c) |
| 1339 | { |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1340 | |
| 1341 | if(menus.open->nitems > maxnitems) { |
| 1342 | maxnitems = menus.open->nitems; |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | switch(c) { |
| 1347 | case CH_CURS_RIGHT: |
| 1348 | switch_open_menu(1); |
| 1349 | |
| 1350 | return REDRAW_MENUPART; |
| 1351 | |
| 1352 | case CH_CURS_DOWN: |
| 1353 | switch_menu_item(1); |
| 1354 | return REDRAW_MENUS; |
| 1355 | |
| 1356 | case CH_CURS_LEFT: |
| 1357 | switch_open_menu(0); |
| 1358 | return REDRAW_MENUPART; |
| 1359 | |
| 1360 | case CH_CURS_UP: |
| 1361 | switch_menu_item(0); |
| 1362 | return REDRAW_MENUS; |
| 1363 | |
| 1364 | case CH_ENTER: |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1365 | return activate_menu(); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1366 | |
adamdunkels | 88ed9c4 | 2003-03-28 12:10:09 +0000 | [diff] [blame] | 1367 | case CTK_CONF_MENU_KEY: |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1368 | lastmenu = menus.open; |
| 1369 | menus.open = NULL; |
| 1370 | return REDRAW_MENUPART; |
| 1371 | } |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1372 | |
| 1373 | return REDRAW_NONE; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1374 | } |
| 1375 | #endif /* CTK_CONF_MENUS */ |
| 1376 | /*-----------------------------------------------------------------------------------*/ |
| 1377 | static void |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1378 | handle_timer(void) |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1379 | { |
| 1380 | if(mode == CTK_MODE_NORMAL) { |
| 1381 | ++screensaver_timer; |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 1382 | if(screensaver_timer >= ctk_screensaver_timeout) { |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1383 | #if CTK_CONF_SCREENSAVER |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1384 | ek_post(EK_BROADCAST, ctk_signal_screensaver_start, NULL); |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1385 | #ifdef CTK_SCREENSAVER_INIT |
| 1386 | CTK_SCREENSAVER_INIT(); |
| 1387 | #endif /* CTK_SCREENSAVER_INIT */ |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 1388 | |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1389 | #endif /* CTK_CONF_SCREENSAVER */ |
| 1390 | screensaver_timer = 0; |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | /*-----------------------------------------------------------------------------------*/ |
| 1395 | static void |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1396 | unfocus_widget(CC_REGISTER_ARG struct ctk_widget *w) |
| 1397 | { |
| 1398 | if(w != NULL) { |
| 1399 | redraw |= REDRAW_WIDGETS; |
| 1400 | add_redrawwidget(w); |
| 1401 | if(CTK_WIDGET_TYPE(w) == CTK_WIDGET_TEXTENTRY) { |
| 1402 | ((struct ctk_textentry *)w)->state = |
| 1403 | CTK_TEXTENTRY_NORMAL; |
| 1404 | } |
| 1405 | w->window->focused = NULL; |
| 1406 | } |
| 1407 | } |
| 1408 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1409 | EK_POLLHANDLER(ctk_poll) |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1410 | { |
| 1411 | static ctk_arch_key_t c; |
adamdunkels | 19a787c | 2003-04-09 09:22:24 +0000 | [diff] [blame] | 1412 | static unsigned char i; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1413 | register struct ctk_window *window; |
adamdunkels | 19a787c | 2003-04-09 09:22:24 +0000 | [diff] [blame] | 1414 | register struct ctk_widget *widget; |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1415 | register struct ctk_widget **widgetptr; |
adamdunkels | 19a787c | 2003-04-09 09:22:24 +0000 | [diff] [blame] | 1416 | #if CTK_CONF_MOUSE_SUPPORT |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1417 | static unsigned char mxc, myc, mouse_button_changed, mouse_moved, |
| 1418 | mouse_clicked; |
| 1419 | static unsigned char menux; |
adamdunkels | af610eb | 2003-08-05 13:50:51 +0000 | [diff] [blame] | 1420 | register struct ctk_menu *menu; |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1421 | |
adamdunkels | 19a787c | 2003-04-09 09:22:24 +0000 | [diff] [blame] | 1422 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1423 | |
| 1424 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1425 | /* current = ek_clock(); |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 1426 | |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 1427 | if((current - start) >= CLK_TCK) { |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1428 | timer(); |
| 1429 | start = current; |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1430 | } */ |
| 1431 | if(timer_expired(&timer)) { |
| 1432 | timer_reset(&timer); |
| 1433 | handle_timer(); |
| 1434 | } |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1435 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1436 | #if CTK_CONF_MENUS |
| 1437 | if(menus.open != NULL) { |
| 1438 | maxnitems = menus.open->nitems; |
| 1439 | } else { |
| 1440 | maxnitems = 0; |
| 1441 | } |
| 1442 | #endif /* CTK_CONF_MENUS */ |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1443 | |
| 1444 | #if CTK_CONF_MOUSE_SUPPORT |
| 1445 | mouse_button_changed = mouse_moved = mouse_clicked = 0; |
| 1446 | |
| 1447 | /* See if there is any change in the buttons. */ |
| 1448 | if(ctk_mouse_button() != mouse_button) { |
| 1449 | mouse_button = ctk_mouse_button(); |
| 1450 | mouse_button_changed = 1; |
| 1451 | if(mouse_button == 0) { |
| 1452 | mouse_clicked = 1; |
| 1453 | } |
| 1454 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1455 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1456 | /* Check if the mouse pointer has moved. */ |
| 1457 | if(ctk_mouse_x() != mouse_x || |
| 1458 | ctk_mouse_y() != mouse_y) { |
| 1459 | mouse_x = ctk_mouse_x(); |
| 1460 | mouse_y = ctk_mouse_y(); |
| 1461 | mouse_moved = 1; |
| 1462 | } |
| 1463 | |
| 1464 | mxc = ctk_mouse_xtoc(mouse_x); |
| 1465 | myc = ctk_mouse_ytoc(mouse_y); |
| 1466 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |
| 1467 | |
| 1468 | |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 1469 | #if CTK_CONF_SCREENSAVER |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1470 | if(mode == CTK_MODE_SCREENSAVER) { |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1471 | if(ctk_arch_keyavail() |
| 1472 | #if CTK_CONF_MOUSE_SUPPORT |
| 1473 | || mouse_moved || mouse_button_changed |
| 1474 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1475 | ) { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1476 | ek_post(EK_BROADCAST, ctk_signal_screensaver_stop, NULL); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1477 | mode = CTK_MODE_NORMAL; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1478 | } |
adamdunkels | 6610962 | 2003-04-24 17:17:10 +0000 | [diff] [blame] | 1479 | } else |
| 1480 | #endif /* CTK_CONF_SCREENSAVER */ |
| 1481 | if(mode == CTK_MODE_NORMAL) { |
adamdunkels | 19a787c | 2003-04-09 09:22:24 +0000 | [diff] [blame] | 1482 | #if CTK_CONF_MOUSE_SUPPORT |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1483 | /* If there is any change in the mouse conditions, find out in |
| 1484 | which window the mouse pointer currently is in order to send |
| 1485 | the correct signals, or bring a window to focus. */ |
| 1486 | if(mouse_moved || mouse_button_changed) { |
| 1487 | ctk_mouse_show(); |
| 1488 | screensaver_timer = 0; |
| 1489 | |
| 1490 | if(myc == 0) { |
| 1491 | /* Here we should do whatever needs to be done when the mouse |
| 1492 | moves around and clicks in the menubar. */ |
| 1493 | if(mouse_clicked) { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1494 | static unsigned char titlelen; |
| 1495 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1496 | /* Find out which menu that the mouse pointer is in. Start |
| 1497 | with the ->next menu after the desktop menu. We assume |
| 1498 | that the menus start one character from the left screen |
| 1499 | side and that the desktop menu is farthest to the |
| 1500 | right. */ |
| 1501 | menux = 1; |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1502 | for(menu = menus.menus->next; |
| 1503 | menu != NULL; menu = menu->next) { |
| 1504 | titlelen = menu->titlelen; |
| 1505 | if(mxc >= menux && mxc <= menux + titlelen) { |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1506 | break; |
adamdunkels | e068331 | 2003-04-09 09:02:52 +0000 | [diff] [blame] | 1507 | } |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1508 | menux += titlelen; |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 1509 | } |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1510 | |
| 1511 | /* Also check desktop menu. */ |
| 1512 | if(mxc >= width - 7 && |
| 1513 | mxc <= width - 1) { |
| 1514 | menu = &desktopmenu; |
| 1515 | } |
| 1516 | |
| 1517 | menus.open = menu; |
| 1518 | redraw |= REDRAW_MENUPART; |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 1519 | } |
adamdunkels | e068331 | 2003-04-09 09:02:52 +0000 | [diff] [blame] | 1520 | } else { |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1521 | --myc; |
| 1522 | |
| 1523 | if(menus.open != NULL) { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1524 | static unsigned char nitems; |
| 1525 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1526 | /* Do whatever needs to be done when a menu is open. */ |
| 1527 | |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1528 | /* First check if the mouse pointer is in the currently open |
| 1529 | menu. */ |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1530 | if(menus.open == &desktopmenu) { |
| 1531 | menux = width - CTK_CONF_MENUWIDTH; |
| 1532 | } else { |
| 1533 | menux = 1; |
| 1534 | for(menu = menus.menus->next; menu != menus.open; |
| 1535 | menu = menu->next) { |
| 1536 | menux += menu->titlelen; |
| 1537 | } |
| 1538 | } |
| 1539 | |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1540 | nitems = menus.open->nitems; |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1541 | /* Find out which of the menu items the mouse is pointing |
| 1542 | to. */ |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1543 | if(mxc >= menux && mxc <= menux + CTK_CONF_MENUWIDTH) { |
| 1544 | if(myc <= nitems) { |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1545 | menus.open->active = myc; |
| 1546 | } else { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1547 | menus.open->active = nitems - 1; |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1548 | } |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | if(mouse_clicked) { |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1552 | if(mxc >= menux && mxc <= menux + CTK_CONF_MENUWIDTH && |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1553 | myc <= nitems) { |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1554 | redraw |= activate_menu(); |
| 1555 | } else { |
| 1556 | lastmenu = menus.open; |
| 1557 | menus.open = NULL; |
| 1558 | redraw |= REDRAW_MENUPART; |
| 1559 | } |
| 1560 | } else { |
| 1561 | redraw |= REDRAW_MENUS; |
| 1562 | } |
| 1563 | } else { |
| 1564 | |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1565 | /* Walk through the windows from top to bottom to see in |
| 1566 | which window the mouse pointer is. */ |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1567 | if(dialog != NULL) { |
| 1568 | window = dialog; |
| 1569 | } else { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1570 | for(window = windows; window != NULL; |
| 1571 | window = window->next) { |
| 1572 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1573 | /* Check if the mouse is within the window. */ |
| 1574 | if(mxc >= window->x && |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1575 | mxc <= window->x + window->w + |
| 1576 | 2 * ctk_draw_windowborder_width && |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1577 | myc >= window->y && |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1578 | myc <= window->y + window->h + |
| 1579 | ctk_draw_windowtitle_height + |
| 1580 | ctk_draw_windowborder_height) { |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1581 | break; |
| 1582 | } |
| 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | |
| 1587 | /* If we didn't find any window, and there are no windows |
| 1588 | open, the mouse pointer will definately be within the |
| 1589 | background desktop window. */ |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 1590 | if(window == NULL) { |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1591 | window = &desktop_window; |
| 1592 | } |
| 1593 | |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1594 | /* If the mouse pointer moves around outside of the |
| 1595 | currently focused window (or dialog), we should not have |
| 1596 | any focused widgets in the focused window so we make sure |
| 1597 | that there are none. */ |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1598 | if(windows != NULL && |
| 1599 | window != windows && |
| 1600 | windows->focused != NULL){ |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1601 | /*add_redrawwidget(windows->focused); |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1602 | windows->focused = NULL; |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1603 | redraw |= REDRAW_WIDGETS;*/ |
| 1604 | unfocus_widget(windows->focused); |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | if(window != NULL) { |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1608 | /* If the mouse was clicked outside of the current window, |
| 1609 | we bring the clicked window to front. */ |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1610 | if(dialog == NULL && |
| 1611 | window != &desktop_window && |
| 1612 | window != windows && |
| 1613 | mouse_clicked) { |
| 1614 | /* Bring window to front. */ |
| 1615 | ctk_window_open(window); |
| 1616 | redraw |= REDRAW_ALL; |
| 1617 | } else { |
| 1618 | |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1619 | /* Find out which widget currently is under the mouse |
| 1620 | pointer and give it focus, unless it already has |
| 1621 | focus. */ |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1622 | mxc = mxc - window->x - ctk_draw_windowborder_width; |
| 1623 | myc = myc - window->y - ctk_draw_windowtitle_height; |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1624 | |
adamdunkels | 965e292 | 2003-06-30 20:44:57 +0000 | [diff] [blame] | 1625 | /* See if the mouse pointer is on a widget. If so, it |
| 1626 | should be selected and, if the button is clicked, |
| 1627 | activated. */ |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1628 | for(widget = window->active; widget != NULL; |
| 1629 | widget = widget->next) { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1630 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1631 | if(mxc >= widget->x && |
| 1632 | mxc <= widget->x + widget->w && |
| 1633 | (myc == widget->y || |
| 1634 | ((widget->type == CTK_WIDGET_BITMAP || |
| 1635 | /*widget->type == CTK_WIDGET_TEXTMAP ||*/ |
| 1636 | widget->type == CTK_WIDGET_ICON) && |
| 1637 | (myc >= widget->y && |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1638 | myc <= widget->y + |
| 1639 | ((struct ctk_bitmap *)widget)->h)))) { |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1640 | break; |
| 1641 | } |
| 1642 | } |
| 1643 | |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1644 | |
| 1645 | /* if the mouse is moved in the focused window, we emit |
| 1646 | a ctk_signal_pointer_move signal to the owner of the |
| 1647 | window. */ |
adamdunkels | 58917a8 | 2003-04-18 00:18:38 +0000 | [diff] [blame] | 1648 | if(mouse_moved && |
| 1649 | (window != &desktop_window || |
| 1650 | windows == NULL)) { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1651 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1652 | ek_post(window->owner, ctk_signal_pointer_move, NULL); |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1653 | |
| 1654 | /* If there was a focused widget that is not below the |
| 1655 | mouse pointer, we remove focus from the widget and |
| 1656 | redraw it. */ |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1657 | if(window->focused != NULL && |
| 1658 | widget != window->focused) { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1659 | /* add_redrawwidget(window->focused); |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1660 | if(CTK_WIDGET_TYPE(window->focused) == |
| 1661 | CTK_WIDGET_TEXTENTRY) { |
| 1662 | ((struct ctk_textentry *)(window->focused))->state = |
| 1663 | CTK_TEXTENTRY_NORMAL; |
| 1664 | } |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1665 | window->focused = NULL;*/ |
| 1666 | unfocus_widget(window->focused); |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1667 | } |
| 1668 | redraw |= REDRAW_WIDGETS; |
| 1669 | if(widget != NULL) { |
| 1670 | select_widget(widget); |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | if(mouse_button_changed) { |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1675 | ek_post(window->owner, ctk_signal_pointer_button, |
| 1676 | (ek_data_t)mouse_button); |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1677 | if(mouse_clicked && widget != NULL) { |
| 1678 | select_widget(widget); |
| 1679 | redraw |= activate(widget); |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | } |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 1685 | } |
| 1686 | } |
adamdunkels | 19a787c | 2003-04-09 09:22:24 +0000 | [diff] [blame] | 1687 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |
adamdunkels | c490286 | 2003-04-09 00:30:45 +0000 | [diff] [blame] | 1688 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1689 | while(ctk_arch_keyavail()) { |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1690 | |
| 1691 | ctk_mouse_hide(); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1692 | |
| 1693 | screensaver_timer = 0; |
| 1694 | |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1695 | c = ctk_arch_getkey(); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1696 | |
| 1697 | if(dialog != NULL) { |
| 1698 | window = dialog; |
| 1699 | } else if(windows != NULL) { |
| 1700 | window = windows; |
| 1701 | } else { |
| 1702 | window = &desktop_window; |
adamdunkels | 54d32c7 | 2004-09-01 18:14:37 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1705 | widget = window->focused; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1706 | |
| 1707 | if(widget != NULL && |
| 1708 | widget->type == CTK_WIDGET_TEXTENTRY && |
| 1709 | widget->widget.textentry.state == CTK_TEXTENTRY_EDIT) { |
| 1710 | textentry_input(c, (struct ctk_textentry *)widget); |
| 1711 | add_redrawwidget(widget); |
| 1712 | #if CTK_CONF_MENUS |
| 1713 | } else if(menus.open != NULL) { |
| 1714 | redraw |= menus_input(c); |
| 1715 | #endif /* CTK_CONF_MENUS */ |
| 1716 | } else { |
| 1717 | switch(c) { |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 1718 | case CTK_CONF_WIDGETDOWN_KEY: |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1719 | switch_focus_widget(DOWN); |
| 1720 | break; |
adamdunkels | 9795b2e | 2003-08-09 23:32:37 +0000 | [diff] [blame] | 1721 | case CTK_CONF_WIDGETUP_KEY: |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1722 | switch_focus_widget(UP); |
| 1723 | break; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1724 | #if CTK_CONF_MENUS |
| 1725 | case CTK_CONF_MENU_KEY: |
| 1726 | if(dialog == NULL) { |
| 1727 | if(lastmenu == NULL) { |
| 1728 | menus.open = menus.menus; |
| 1729 | } else { |
| 1730 | menus.open = lastmenu; |
| 1731 | } |
| 1732 | menus.open->active = 0; |
| 1733 | redraw |= REDRAW_MENUS; |
| 1734 | } |
| 1735 | break; |
| 1736 | #endif /* CTK_CONF_MENUS */ |
| 1737 | case CTK_CONF_WINDOWSWITCH_KEY: |
| 1738 | if(windows != NULL) { |
| 1739 | for(window = windows; window->next != NULL; |
| 1740 | window = window->next); |
| 1741 | ctk_window_open(window); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1742 | } |
| 1743 | break; |
| 1744 | default: |
adamdunkels | 54d32c7 | 2004-09-01 18:14:37 +0000 | [diff] [blame] | 1745 | |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1746 | if(c == CH_ENTER && |
| 1747 | widget != NULL) { |
| 1748 | redraw |= activate(widget); |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1749 | } else { |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1750 | if(widget != NULL && |
| 1751 | widget->type == CTK_WIDGET_TEXTENTRY) { |
oliverschmidt | f28743b | 2005-05-04 22:33:45 +0000 | [diff] [blame] | 1752 | if(widget->widget.textentry.state == CTK_TEXTENTRY_NORMAL) { |
oliverschmidt | 1151124 | 2005-05-04 23:05:37 +0000 | [diff] [blame] | 1753 | widget->widget.textentry.state = CTK_TEXTENTRY_EDIT; |
| 1754 | textentry_input(0, (struct ctk_textentry *)widget); |
oliverschmidt | f28743b | 2005-05-04 22:33:45 +0000 | [diff] [blame] | 1755 | } |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1756 | textentry_input(c, (struct ctk_textentry *)widget); |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1757 | add_redrawwidget(widget); |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1758 | } else { |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1759 | /* window->focused = NULL;*/ |
| 1760 | unfocus_widget(window->focused); |
adamdunkels | 54d32c7 | 2004-09-01 18:14:37 +0000 | [diff] [blame] | 1761 | ek_post_synch(window->owner, ctk_signal_keypress, (ek_data_t)c); |
adamdunkels | 3af580f | 2003-08-11 22:27:13 +0000 | [diff] [blame] | 1762 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1763 | } |
| 1764 | break; |
| 1765 | } |
| 1766 | } |
| 1767 | |
adamdunkels | c4dbb8d | 2003-08-29 20:38:54 +0000 | [diff] [blame] | 1768 | #if 0 |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1769 | if(redraw & REDRAW_WIDGETS) { |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1770 | widgetptr = redraw_widgets; |
| 1771 | for(i = 0; i < MAX_REDRAWWIDGETS; ++i) { |
adamdunkels | c4dbb8d | 2003-08-29 20:38:54 +0000 | [diff] [blame] | 1772 | widget_redraw(*widgetptr); |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1773 | *widgetptr = NULL; |
| 1774 | ++widgetptr; |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1775 | } |
| 1776 | redraw &= ~REDRAW_WIDGETS; |
| 1777 | redraw_widgetptr = 0; |
| 1778 | } |
adamdunkels | c4dbb8d | 2003-08-29 20:38:54 +0000 | [diff] [blame] | 1779 | #endif /* 0 */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1780 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1781 | #if CTK_CONF_WINDOWMOVE |
| 1782 | } else if(mode == CTK_MODE_WINDOWMOVE) { |
| 1783 | |
| 1784 | redraw = 0; |
| 1785 | |
| 1786 | window = windows; |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1787 | |
| 1788 | #if CTK_CONF_MOUSE_SUPPORT |
| 1789 | |
| 1790 | /* If the mouse has moved, we move the window as well. */ |
| 1791 | if(mouse_moved) { |
| 1792 | |
| 1793 | if(window->w + mxc + 2 >= width) { |
| 1794 | window->x = width - 2 - window->w; |
| 1795 | } else { |
| 1796 | window->x = mxc; |
| 1797 | } |
| 1798 | |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1799 | if(window->h + myc + ctk_draw_windowtitle_height + |
| 1800 | ctk_draw_windowborder_height >= height) { |
| 1801 | window->y = height - window->h - |
| 1802 | ctk_draw_windowtitle_height - ctk_draw_windowborder_height; |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1803 | } else { |
| 1804 | window->y = myc; |
| 1805 | } |
| 1806 | if(window->y > 0) { |
| 1807 | --window->y; |
| 1808 | } |
| 1809 | |
| 1810 | redraw = REDRAW_ALL; |
| 1811 | } |
| 1812 | |
| 1813 | /* Check if the mouse has been clicked, and stop moving the window |
| 1814 | if so. */ |
| 1815 | if(mouse_button_changed && |
| 1816 | mouse_button == 0) { |
| 1817 | mode = CTK_MODE_NORMAL; |
| 1818 | redraw = REDRAW_ALL; |
| 1819 | } |
| 1820 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1821 | |
| 1822 | while(mode == CTK_MODE_WINDOWMOVE && ctk_arch_keyavail()) { |
| 1823 | |
| 1824 | screensaver_timer = 0; |
| 1825 | |
| 1826 | c = ctk_arch_getkey(); |
| 1827 | |
| 1828 | switch(c) { |
| 1829 | case CH_CURS_RIGHT: |
| 1830 | ++window->x; |
| 1831 | if(window->x + window->w + 1 >= width) { |
| 1832 | --window->x; |
| 1833 | } |
| 1834 | redraw = REDRAW_ALL; |
| 1835 | break; |
| 1836 | case CH_CURS_LEFT: |
| 1837 | if(window->x > 0) { |
| 1838 | --window->x; |
| 1839 | } |
| 1840 | redraw = REDRAW_ALL; |
| 1841 | break; |
| 1842 | case CH_CURS_DOWN: |
| 1843 | ++window->y; |
| 1844 | if(window->y + window->h + 2 >= height) { |
| 1845 | --window->y; |
| 1846 | } |
| 1847 | redraw = REDRAW_ALL; |
| 1848 | break; |
| 1849 | case CH_CURS_UP: |
| 1850 | if(window->y > 0) { |
| 1851 | --window->y; |
| 1852 | } |
| 1853 | redraw = REDRAW_ALL; |
| 1854 | break; |
adamdunkels | 4dd8eeb | 2003-08-15 18:49:22 +0000 | [diff] [blame] | 1855 | default: |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1856 | mode = CTK_MODE_NORMAL; |
| 1857 | redraw = REDRAW_ALL; |
| 1858 | break; |
| 1859 | } |
| 1860 | } |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1861 | #endif /* CTK_CONF_WINDOWMOVE */ |
| 1862 | } |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1863 | |
| 1864 | if(redraw & REDRAW_ALL) { |
| 1865 | do_redraw_all(1, height); |
| 1866 | #if CTK_CONF_MENUS |
| 1867 | } else if(redraw & REDRAW_MENUPART) { |
| 1868 | do_redraw_all(1, maxnitems + 1); |
| 1869 | } else if(redraw & REDRAW_MENUS) { |
| 1870 | ctk_draw_menus(&menus); |
| 1871 | #endif /* CTK_CONF_MENUS */ |
| 1872 | } else if(redraw & REDRAW_FOCUS) { |
| 1873 | if(dialog != NULL) { |
| 1874 | ctk_window_redraw(dialog); |
| 1875 | } else if(windows != NULL) { |
| 1876 | ctk_window_redraw(windows); |
| 1877 | } else { |
| 1878 | ctk_window_redraw(&desktop_window); |
| 1879 | } |
| 1880 | } else if(redraw & REDRAW_WIDGETS) { |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1881 | widgetptr = redraw_widgets; |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1882 | for(i = 0; i < MAX_REDRAWWIDGETS; ++i) { |
adamdunkels | c4dbb8d | 2003-08-29 20:38:54 +0000 | [diff] [blame] | 1883 | widget_redraw(*widgetptr); |
adamdunkels | cf90b0d | 2003-08-09 13:34:16 +0000 | [diff] [blame] | 1884 | *widgetptr = NULL; |
| 1885 | ++widgetptr; |
adamdunkels | b248656 | 2003-04-11 20:22:03 +0000 | [diff] [blame] | 1886 | } |
| 1887 | } |
| 1888 | redraw = 0; |
| 1889 | redraw_widgetptr = 0; |
| 1890 | |
adamdunkels | ca9ddcb | 2003-03-19 14:13:31 +0000 | [diff] [blame] | 1891 | } |
| 1892 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 3b548c8 | 2004-07-04 11:41:39 +0000 | [diff] [blame] | 1893 | EK_EVENTHANDLER(ctk_eventhandler, ev, data) |
| 1894 | { |
| 1895 | |
| 1896 | } |
| 1897 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 1898 | /** @} */ |
| 1899 | /** @} */ |
| 1900 | |