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