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