Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Server-side console management |
| 3 | * |
| 4 | * Copyright (C) 1998 Alexandre Julliard |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 5 | * 2001 Eric Pouech |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 6 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
Patrik Stridvall | 9633632 | 1999-10-24 22:13:47 +0000 | [diff] [blame] | 23 | #include "config.h" |
Alexandre Julliard | 5769d1d | 2002-04-26 19:05:15 +0000 | [diff] [blame] | 24 | #include "wine/port.h" |
Patrik Stridvall | 9633632 | 1999-10-24 22:13:47 +0000 | [diff] [blame] | 25 | |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 26 | #include <assert.h> |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 27 | #include <string.h> |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 29 | #include <unistd.h> |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 30 | #include <signal.h> |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 31 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 32 | #include "handle.h" |
| 33 | #include "process.h" |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 34 | #include "request.h" |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 35 | #include "unicode.h" |
| 36 | #include "console.h" |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 37 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 38 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 39 | static void console_input_dump( struct object *obj, int verbose ); |
| 40 | static void console_input_destroy( struct object *obj ); |
| 41 | static int console_input_signaled( struct object *obj, struct thread *thread ); |
| 42 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 43 | static const struct object_ops console_input_ops = |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 44 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 45 | sizeof(struct console_input), /* size */ |
| 46 | console_input_dump, /* dump */ |
| 47 | add_queue, /* add_queue */ |
| 48 | remove_queue, /* remove_queue */ |
| 49 | console_input_signaled, /* signaled */ |
| 50 | no_satisfied, /* satisfied */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 51 | no_get_fd, /* get_fd */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 52 | console_input_destroy /* destroy */ |
| 53 | }; |
| 54 | |
| 55 | static void console_input_events_dump( struct object *obj, int verbose ); |
| 56 | static void console_input_events_destroy( struct object *obj ); |
| 57 | static int console_input_events_signaled( struct object *obj, struct thread *thread ); |
| 58 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 59 | struct console_input_events |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 60 | { |
| 61 | struct object obj; /* object header */ |
| 62 | int num_alloc; /* number of allocated events */ |
| 63 | int num_used; /* number of actually used events */ |
| 64 | struct console_renderer_event* events; |
| 65 | }; |
| 66 | |
| 67 | static const struct object_ops console_input_events_ops = |
| 68 | { |
| 69 | sizeof(struct console_input_events), /* size */ |
| 70 | console_input_events_dump, /* dump */ |
| 71 | add_queue, /* add_queue */ |
| 72 | remove_queue, /* remove_queue */ |
| 73 | console_input_events_signaled, /* signaled */ |
| 74 | no_satisfied, /* satisfied */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 75 | no_get_fd, /* get_fd */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 76 | console_input_events_destroy /* destroy */ |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 79 | struct screen_buffer |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 80 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 81 | struct object obj; /* object header */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 82 | struct screen_buffer *next; /* linked list of all screen buffers */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 83 | struct screen_buffer *prev; |
| 84 | struct console_input *input; /* associated console input */ |
| 85 | int mode; /* output mode */ |
| 86 | int cursor_size; /* size of cursor (percentage filled) */ |
| 87 | int cursor_visible;/* cursor visibility flag */ |
| 88 | int cursor_x; /* position of cursor */ |
| 89 | int cursor_y; /* position of cursor */ |
| 90 | int width; /* size (w-h) of the screen buffer */ |
| 91 | int height; |
| 92 | int max_width; /* size (w-h) of the window given font size */ |
| 93 | int max_height; |
| 94 | char_info_t *data; /* the data for each cell - a width x height matrix */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 95 | unsigned short attr; /* default attribute for screen buffer */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 96 | rectangle_t win; /* current visible window on the screen buffer * |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 97 | * as seen in wineconsole */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 100 | static void screen_buffer_dump( struct object *obj, int verbose ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 101 | static void screen_buffer_destroy( struct object *obj ); |
| 102 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 103 | static const struct object_ops screen_buffer_ops = |
| 104 | { |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 105 | sizeof(struct screen_buffer), /* size */ |
| 106 | screen_buffer_dump, /* dump */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 107 | no_add_queue, /* add_queue */ |
| 108 | NULL, /* remove_queue */ |
| 109 | NULL, /* signaled */ |
| 110 | NULL, /* satisfied */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 111 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 112 | screen_buffer_destroy /* destroy */ |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 115 | static struct screen_buffer *screen_buffer_list; |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 116 | |
Eric Pouech | a908756 | 2002-01-02 21:45:47 +0000 | [diff] [blame] | 117 | static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 118 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 119 | /* dumps the renderer events of a console */ |
| 120 | static void console_input_events_dump( struct object *obj, int verbose ) |
| 121 | { |
| 122 | struct console_input_events *evts = (struct console_input_events *)obj; |
| 123 | assert( obj->ops == &console_input_events_ops ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 124 | fprintf( stderr, "Console input events: %d/%d events\n", |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 125 | evts->num_used, evts->num_alloc ); |
| 126 | } |
| 127 | |
| 128 | /* destroys the renderer events of a console */ |
| 129 | static void console_input_events_destroy( struct object *obj ) |
| 130 | { |
| 131 | struct console_input_events *evts = (struct console_input_events *)obj; |
| 132 | assert( obj->ops == &console_input_events_ops ); |
| 133 | free( evts->events ); |
| 134 | } |
| 135 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 136 | /* the renderer events list is signaled when it's not empty */ |
| 137 | static int console_input_events_signaled( struct object *obj, struct thread *thread ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 138 | { |
| 139 | struct console_input_events *evts = (struct console_input_events *)obj; |
| 140 | assert( obj->ops == &console_input_events_ops ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 141 | return (evts->num_used != 0); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* add an event to the console's renderer events list */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 145 | static void console_input_events_append( struct console_input_events* evts, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 146 | struct console_renderer_event* evt) |
| 147 | { |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 148 | int collapsed = FALSE; |
| 149 | |
| 150 | /* to be done even when evt has been generated by the rendere ? */ |
| 151 | |
| 152 | /* try to collapse evt into current queue's events */ |
| 153 | if (evts->num_used) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 154 | { |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 155 | struct console_renderer_event* last = &evts->events[evts->num_used - 1]; |
| 156 | |
| 157 | if (last->event == CONSOLE_RENDERER_UPDATE_EVENT && |
| 158 | evt->event == CONSOLE_RENDERER_UPDATE_EVENT) |
| 159 | { |
| 160 | /* if two update events overlap, collapse them into a single one */ |
| 161 | if (last->u.update.bottom + 1 >= evt->u.update.top && |
| 162 | evt->u.update.bottom + 1 >= last->u.update.top) |
| 163 | { |
| 164 | last->u.update.top = min(last->u.update.top, evt->u.update.top); |
| 165 | last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom); |
| 166 | collapsed = TRUE; |
| 167 | } |
| 168 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 169 | } |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 170 | if (!collapsed) |
| 171 | { |
| 172 | if (evts->num_used == evts->num_alloc) |
| 173 | { |
| 174 | evts->num_alloc += 16; |
| 175 | evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) ); |
| 176 | assert(evts->events); |
| 177 | } |
| 178 | evts->events[evts->num_used++] = *evt; |
| 179 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 180 | wake_up( &evts->obj, 0 ); |
| 181 | } |
| 182 | |
| 183 | /* retrieves events from the console's renderer events list */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 184 | static void console_input_events_get( struct console_input_events* evts ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 185 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 186 | size_t num = get_reply_max_size() / sizeof(evts->events[0]); |
| 187 | |
| 188 | if (num > evts->num_used) num = evts->num_used; |
| 189 | set_reply_data( evts->events, num * sizeof(evts->events[0]) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 190 | if (num < evts->num_used) |
| 191 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 192 | memmove( &evts->events[0], &evts->events[num], |
| 193 | (evts->num_used - num) * sizeof(evts->events[0]) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 194 | } |
| 195 | evts->num_used -= num; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static struct console_input_events *create_console_input_events(void) |
| 199 | { |
| 200 | struct console_input_events* evt; |
| 201 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame^] | 202 | if (!(evt = alloc_object( &console_input_events_ops ))) return NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 203 | evt->num_alloc = evt->num_used = 0; |
| 204 | evt->events = NULL; |
| 205 | return evt; |
| 206 | } |
| 207 | |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 208 | static struct object *create_console_input( struct thread* renderer ) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 209 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 210 | struct console_input *console_input; |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 211 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame^] | 212 | if (!(console_input = alloc_object( &console_input_ops ))) return NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 213 | console_input->renderer = renderer; |
| 214 | console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | |
| 215 | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT; |
| 216 | console_input->num_proc = 0; |
| 217 | console_input->active = NULL; |
| 218 | console_input->recnum = 0; |
| 219 | console_input->records = NULL; |
| 220 | console_input->evt = create_console_input_events(); |
| 221 | console_input->title = NULL; |
| 222 | console_input->history_size = 50; |
| 223 | console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) ); |
| 224 | console_input->history_index = 0; |
| 225 | console_input->history_mode = 0; |
Eric Pouech | fa8b85a | 2003-01-09 06:01:32 +0000 | [diff] [blame] | 226 | console_input->edition_mode = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 227 | |
| 228 | if (!console_input->history || !console_input->evt) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 229 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 230 | release_object( console_input ); |
| 231 | return NULL; |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 232 | } |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 233 | return &console_input->obj; |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 236 | static struct screen_buffer *create_console_output( struct console_input *console_input ) |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 237 | { |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 238 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 239 | struct console_renderer_event evt; |
| 240 | int i; |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 241 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame^] | 242 | if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL; |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 243 | screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT; |
| 244 | screen_buffer->input = console_input; |
| 245 | screen_buffer->cursor_size = 100; |
| 246 | screen_buffer->cursor_visible = 1; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 247 | screen_buffer->width = 80; |
| 248 | screen_buffer->height = 150; |
| 249 | screen_buffer->max_width = 80; |
| 250 | screen_buffer->max_height = 25; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 251 | screen_buffer->cursor_x = 0; |
| 252 | screen_buffer->cursor_y = 0; |
Eric Pouech | a908756 | 2002-01-02 21:45:47 +0000 | [diff] [blame] | 253 | screen_buffer->attr = 0x0F; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 254 | screen_buffer->win.left = 0; |
| 255 | screen_buffer->win.right = screen_buffer->max_width - 1; |
| 256 | screen_buffer->win.top = 0; |
| 257 | screen_buffer->win.bottom = screen_buffer->max_height - 1; |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 258 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 259 | if ((screen_buffer->next = screen_buffer_list)) screen_buffer->next->prev = screen_buffer; |
| 260 | screen_buffer->prev = NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 261 | screen_buffer_list = screen_buffer; |
| 262 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 263 | if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height * |
| 264 | sizeof(*screen_buffer->data) ))) |
| 265 | { |
| 266 | release_object( screen_buffer ); |
| 267 | return NULL; |
| 268 | } |
| 269 | /* clear the first row */ |
| 270 | for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info; |
| 271 | /* and copy it to all other rows */ |
| 272 | for (i = 1; i < screen_buffer->height; i++) |
| 273 | memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data, |
| 274 | screen_buffer->width * sizeof(char_info_t) ); |
| 275 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 276 | if (!console_input->active) |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 277 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 278 | console_input->active = (struct screen_buffer*)grab_object( screen_buffer ); |
| 279 | |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 280 | /* generate the initial events */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 281 | evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT; |
| 282 | console_input_events_append( console_input->evt, &evt ); |
| 283 | |
| 284 | evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT; |
| 285 | evt.u.resize.width = screen_buffer->width; |
| 286 | evt.u.resize.height = screen_buffer->height; |
| 287 | console_input_events_append( console_input->evt, &evt ); |
| 288 | |
| 289 | evt.event = CONSOLE_RENDERER_DISPLAY_EVENT; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 290 | evt.u.display.left = screen_buffer->win.left; |
| 291 | evt.u.display.top = screen_buffer->win.top; |
| 292 | evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1; |
| 293 | evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 294 | console_input_events_append( console_input->evt, &evt ); |
| 295 | |
| 296 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
| 297 | evt.u.update.top = 0; |
| 298 | evt.u.update.bottom = screen_buffer->height - 1; |
| 299 | console_input_events_append( console_input->evt, &evt ); |
| 300 | |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 301 | evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT; |
| 302 | evt.u.cursor_geom.size = screen_buffer->cursor_size; |
| 303 | evt.u.cursor_geom.visible = screen_buffer->cursor_visible; |
| 304 | console_input_events_append( console_input->evt, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 305 | |
| 306 | evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 307 | evt.u.cursor_pos.x = screen_buffer->cursor_x; |
| 308 | evt.u.cursor_pos.y = screen_buffer->cursor_y; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 309 | console_input_events_append( console_input->evt, &evt ); |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 310 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 311 | return screen_buffer; |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* free the console for this process */ |
| 315 | int free_console( struct process *process ) |
| 316 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 317 | struct console_input* console = process->console; |
| 318 | |
| 319 | if (!console || !console->renderer) return 0; |
| 320 | |
| 321 | process->console = NULL; |
| 322 | if (--console->num_proc == 0) |
| 323 | { |
| 324 | /* all processes have terminated... tell the renderer to terminate too */ |
| 325 | struct console_renderer_event evt; |
| 326 | evt.event = CONSOLE_RENDERER_EXIT_EVENT; |
| 327 | console_input_events_append( console->evt, &evt ); |
| 328 | } |
| 329 | release_object( console ); |
| 330 | |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 331 | return 1; |
| 332 | } |
| 333 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 334 | /* let process inherit the console from parent... this handle two cases : |
| 335 | * 1/ generic console inheritance |
| 336 | * 2/ parent is a renderer which launches process, and process should attach to the console |
| 337 | * renderered by parent |
| 338 | */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 339 | void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 340 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 341 | int done = 0; |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 342 | struct process* parent = parent_thread->process; |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 343 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 344 | /* if parent is a renderer, then attach current process to its console |
| 345 | * a bit hacky.... |
| 346 | */ |
| 347 | if (hconin) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 348 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 349 | struct console_input* console; |
| 350 | |
| 351 | if ((console = (struct console_input*)get_handle_obj( parent, hconin, 0, NULL ))) |
| 352 | { |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 353 | if (console->renderer == parent_thread) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 354 | { |
| 355 | process->console = (struct console_input*)grab_object( console ); |
| 356 | process->console->num_proc++; |
| 357 | done = 1; |
| 358 | } |
| 359 | release_object( console ); |
| 360 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 361 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 362 | /* otherwise, if parent has a console, attach child to this console */ |
| 363 | if (!done && parent->console) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 364 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 365 | assert(parent->console->renderer); |
| 366 | process->console = (struct console_input*)grab_object( parent->console ); |
| 367 | process->console->num_proc++; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 368 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 371 | int is_console_object( struct object *obj ) |
| 372 | { |
| 373 | return (obj->ops == &console_input_ops || obj->ops == &screen_buffer_ops); |
| 374 | } |
| 375 | |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 376 | static struct console_input* console_input_get( obj_handle_t handle, unsigned access ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 377 | { |
| 378 | struct console_input* console = 0; |
| 379 | |
| 380 | if (handle) |
| 381 | console = (struct console_input *)get_handle_obj( current->process, handle, |
| 382 | access, &console_input_ops ); |
| 383 | else if (current->process->console) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 384 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 385 | assert( current->process->console->renderer ); |
| 386 | console = (struct console_input *)grab_object( current->process->console ); |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 387 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 388 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 389 | if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER); |
| 390 | return console; |
| 391 | } |
Alexandre Julliard | 57e1131 | 1999-05-16 16:59:38 +0000 | [diff] [blame] | 392 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 393 | /* check if a console input is signaled: yes if non read input records */ |
| 394 | static int console_input_signaled( struct object *obj, struct thread *thread ) |
| 395 | { |
| 396 | struct console_input *console = (struct console_input *)obj; |
| 397 | assert( obj->ops == &console_input_ops ); |
| 398 | return console->recnum ? 1 : 0; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 401 | struct console_signal_info { |
| 402 | struct console_input *console; |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 403 | process_id_t group; |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 404 | int signal; |
| 405 | }; |
| 406 | |
| 407 | static int propagate_console_signal_cb(struct process *process, void *user) |
| 408 | { |
| 409 | struct console_signal_info* csi = (struct console_signal_info*)user; |
| 410 | |
| 411 | if (process->console == csi->console && process->running_threads && |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 412 | (!csi->group || process->group_id == csi->group)) |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 413 | { |
| 414 | struct thread *thread = process->thread_list; |
| 415 | |
| 416 | while (thread) |
| 417 | { |
| 418 | struct thread *next = thread->proc_next; |
| 419 | kill( thread->unix_pid, csi->signal ); |
| 420 | thread = next; |
| 421 | } |
| 422 | } |
| 423 | return FALSE; |
| 424 | } |
| 425 | |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 426 | static void propagate_console_signal( struct console_input *console, |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 427 | int sig, process_id_t group_id ) |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 428 | { |
| 429 | struct console_signal_info csi; |
| 430 | |
| 431 | if (!console) |
| 432 | { |
| 433 | set_error( STATUS_INVALID_PARAMETER ); |
| 434 | return; |
| 435 | } |
| 436 | /* FIXME: should support the other events (like CTRL_BREAK) */ |
| 437 | if (sig != CTRL_C_EVENT) |
| 438 | { |
| 439 | set_error( STATUS_NOT_IMPLEMENTED ); |
| 440 | return; |
| 441 | } |
| 442 | csi.console = console; |
| 443 | csi.signal = SIGINT; |
| 444 | csi.group = group_id; |
| 445 | |
| 446 | enum_processes(propagate_console_signal_cb, &csi); |
| 447 | } |
| 448 | |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 449 | static int get_console_mode( obj_handle_t handle ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 450 | { |
| 451 | struct object *obj; |
| 452 | int ret = 0; |
| 453 | |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 454 | if ((obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL ))) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 455 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 456 | if (obj->ops == &console_input_ops) |
| 457 | ret = ((struct console_input *)obj)->mode; |
| 458 | else if (obj->ops == &screen_buffer_ops) |
| 459 | ret = ((struct screen_buffer *)obj)->mode; |
| 460 | else |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 461 | set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 462 | release_object( obj ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 463 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 464 | return ret; |
| 465 | } |
| 466 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 467 | /* changes the mode of either a console input or a screen buffer */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 468 | static int set_console_mode( obj_handle_t handle, int mode ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 469 | { |
| 470 | struct object *obj; |
| 471 | int ret = 0; |
| 472 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 473 | if (!(obj = get_handle_obj( current->process, handle, GENERIC_WRITE, NULL ))) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 474 | return 0; |
| 475 | if (obj->ops == &console_input_ops) |
| 476 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 477 | /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 478 | ((struct console_input *)obj)->mode = mode; |
| 479 | ret = 1; |
| 480 | } |
| 481 | else if (obj->ops == &screen_buffer_ops) |
| 482 | { |
| 483 | ((struct screen_buffer *)obj)->mode = mode; |
| 484 | ret = 1; |
| 485 | } |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 486 | else set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 487 | release_object( obj ); |
| 488 | return ret; |
| 489 | } |
| 490 | |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 491 | /* add input events to a console input queue */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 492 | static int write_console_input( struct console_input* console, int count, |
| 493 | const INPUT_RECORD *records ) |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 494 | { |
| 495 | INPUT_RECORD *new_rec; |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 496 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 497 | if (!count) return 0; |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 498 | if (!(new_rec = realloc( console->records, |
| 499 | (console->recnum + count) * sizeof(INPUT_RECORD) ))) |
| 500 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 501 | set_error( STATUS_NO_MEMORY ); |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 502 | release_object( console ); |
| 503 | return -1; |
| 504 | } |
| 505 | console->records = new_rec; |
| 506 | memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 507 | |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 508 | if (console->mode & ENABLE_PROCESSED_INPUT) |
| 509 | { |
| 510 | int i = 0; |
| 511 | while (i < count) |
| 512 | { |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 513 | if (records[i].EventType == KEY_EVENT && |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 514 | records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 && |
| 515 | !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY)) |
| 516 | { |
| 517 | if (i != count - 1) |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 518 | memcpy( &console->records[console->recnum + i], |
| 519 | &console->records[console->recnum + i + 1], |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 520 | (count - i - 1) * sizeof(INPUT_RECORD) ); |
| 521 | count--; |
| 522 | if (records[i].Event.KeyEvent.bKeyDown) |
| 523 | { |
| 524 | /* send SIGINT to all processes attached to this console */ |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 525 | propagate_console_signal( console, CTRL_C_EVENT, 0 ); |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | else i++; |
| 529 | } |
| 530 | } |
| 531 | console->recnum += count; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 532 | /* wake up all waiters */ |
| 533 | wake_up( &console->obj, 0 ); |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 534 | return count; |
| 535 | } |
| 536 | |
| 537 | /* retrieve a pointer to the console input records */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 538 | static int read_console_input( obj_handle_t handle, int count, int flush ) |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 539 | { |
| 540 | struct console_input *console; |
| 541 | |
| 542 | if (!(console = (struct console_input *)get_handle_obj( current->process, handle, |
| 543 | GENERIC_READ, &console_input_ops ))) |
| 544 | return -1; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 545 | |
| 546 | if (!count) |
| 547 | { |
| 548 | /* special case: do not retrieve anything, but return |
| 549 | * the total number of records available */ |
| 550 | count = console->recnum; |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | if (count > console->recnum) count = console->recnum; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 555 | set_reply_data( console->records, count * sizeof(INPUT_RECORD) ); |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 556 | } |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 557 | if (flush) |
| 558 | { |
| 559 | int i; |
| 560 | for (i = count; i < console->recnum; i++) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 561 | console->records[i-count] = console->records[i]; |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 562 | if ((console->recnum -= count) > 0) |
| 563 | { |
| 564 | INPUT_RECORD *new_rec = realloc( console->records, |
| 565 | console->recnum * sizeof(INPUT_RECORD) ); |
| 566 | if (new_rec) console->records = new_rec; |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | free( console->records ); |
| 571 | console->records = NULL; |
| 572 | } |
| 573 | } |
| 574 | release_object( console ); |
| 575 | return count; |
| 576 | } |
| 577 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 578 | /* set misc console input information */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 579 | static int set_console_input_info( const struct set_console_input_info_request *req, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 580 | const WCHAR *title, size_t len ) |
| 581 | { |
| 582 | struct console_input *console; |
| 583 | struct console_renderer_event evt; |
| 584 | |
| 585 | if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) goto error; |
| 586 | |
| 587 | if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB) |
| 588 | { |
| 589 | struct screen_buffer *screen_buffer; |
| 590 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 591 | screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 592 | GENERIC_READ, &screen_buffer_ops ); |
| 593 | if (!screen_buffer || screen_buffer->input != console) |
| 594 | { |
| 595 | set_error( STATUS_INVALID_PARAMETER ); |
| 596 | if (screen_buffer) release_object( screen_buffer ); |
| 597 | goto error; |
| 598 | } |
| 599 | |
| 600 | if (screen_buffer != console->active) |
| 601 | { |
| 602 | if (console->active) release_object( console->active ); |
| 603 | console->active = screen_buffer; |
| 604 | evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT; |
| 605 | console_input_events_append( console->evt, &evt ); |
| 606 | } |
| 607 | else |
| 608 | release_object( screen_buffer ); |
| 609 | } |
| 610 | if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE) |
| 611 | { |
| 612 | WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) ); |
| 613 | if (new_title) |
| 614 | { |
| 615 | memcpy( new_title, title, len + sizeof(WCHAR) ); |
| 616 | new_title[len / sizeof(WCHAR)] = 0; |
| 617 | if (console->title) free( console->title ); |
| 618 | console->title = new_title; |
Eric Pouech | 47205b8 | 2002-05-11 22:53:56 +0000 | [diff] [blame] | 619 | evt.event = CONSOLE_RENDERER_TITLE_EVENT; |
| 620 | console_input_events_append( console->evt, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE) |
| 624 | { |
| 625 | console->history_mode = req->history_mode; |
| 626 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 627 | if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) && |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 628 | console->history_size != req->history_size) |
| 629 | { |
| 630 | WCHAR** mem = NULL; |
| 631 | int i; |
| 632 | int delta; |
| 633 | |
| 634 | if (req->history_size) |
| 635 | { |
| 636 | mem = mem_alloc( req->history_size * sizeof(WCHAR*) ); |
| 637 | if (!mem) goto error; |
| 638 | memset( mem, 0, req->history_size * sizeof(WCHAR*) ); |
| 639 | } |
| 640 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 641 | delta = (console->history_index > req->history_size) ? |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 642 | (console->history_index - req->history_size) : 0; |
| 643 | |
| 644 | for (i = delta; i < console->history_index; i++) |
| 645 | { |
| 646 | mem[i - delta] = console->history[i]; |
| 647 | console->history[i] = NULL; |
| 648 | } |
| 649 | console->history_index -= delta; |
| 650 | |
| 651 | for (i = 0; i < console->history_size; i++) |
| 652 | if (console->history[i]) free( console->history[i] ); |
| 653 | free( console->history ); |
| 654 | console->history = mem; |
| 655 | console->history_size = req->history_size; |
| 656 | } |
Eric Pouech | fa8b85a | 2003-01-09 06:01:32 +0000 | [diff] [blame] | 657 | if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE) |
| 658 | { |
| 659 | console->edition_mode = req->edition_mode; |
| 660 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 661 | release_object( console ); |
| 662 | return 1; |
| 663 | error: |
| 664 | if (console) release_object( console ); |
| 665 | return 0; |
| 666 | } |
| 667 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 668 | /* resize a screen buffer */ |
| 669 | static int change_screen_buffer_size( struct screen_buffer *screen_buffer, |
| 670 | int new_width, int new_height ) |
| 671 | { |
| 672 | int i, old_width, old_height, copy_width, copy_height; |
| 673 | char_info_t *new_data; |
| 674 | |
| 675 | if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) ))) |
| 676 | { |
| 677 | set_error( STATUS_NO_MEMORY ); |
| 678 | return 0; |
| 679 | } |
| 680 | old_width = screen_buffer->width; |
| 681 | old_height = screen_buffer->height; |
| 682 | copy_width = min( old_width, new_width ); |
| 683 | copy_height = min( old_height, new_height ); |
| 684 | |
| 685 | /* copy all the rows */ |
| 686 | for (i = 0; i < copy_height; i++) |
| 687 | { |
| 688 | memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width], |
| 689 | copy_width * sizeof(char_info_t) ); |
| 690 | } |
| 691 | |
| 692 | /* clear the end of each row */ |
| 693 | if (new_width > old_width) |
| 694 | { |
| 695 | /* fill first row */ |
| 696 | for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info; |
| 697 | /* and blast it to the other rows */ |
| 698 | for (i = 1; i < copy_height; i++) |
| 699 | memcpy( &new_data[i * new_width + old_width], &new_data[old_width], |
| 700 | (new_width - old_width) * sizeof(char_info_t) ); |
| 701 | } |
| 702 | |
| 703 | /* clear remaining rows */ |
| 704 | if (new_height > old_height) |
| 705 | { |
| 706 | /* fill first row */ |
| 707 | for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info; |
| 708 | /* and blast it to the other rows */ |
| 709 | for (i = old_height+1; i < new_height; i++) |
| 710 | memcpy( &new_data[i * new_width], &new_data[old_height * new_width], |
| 711 | new_width * sizeof(char_info_t) ); |
| 712 | } |
| 713 | free( screen_buffer->data ); |
| 714 | screen_buffer->data = new_data; |
| 715 | screen_buffer->width = new_width; |
| 716 | screen_buffer->height = new_height; |
| 717 | return 1; |
| 718 | } |
| 719 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 720 | /* set misc screen buffer information */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 721 | static int set_console_output_info( struct screen_buffer *screen_buffer, |
| 722 | const struct set_console_output_info_request *req ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 723 | { |
| 724 | struct console_renderer_event evt; |
| 725 | |
| 726 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM) |
| 727 | { |
| 728 | if (req->cursor_size < 1 || req->cursor_size > 100) |
| 729 | { |
| 730 | set_error( STATUS_INVALID_PARAMETER ); |
| 731 | return 0; |
| 732 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 733 | if (screen_buffer->cursor_size != req->cursor_size || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 734 | screen_buffer->cursor_visible != req->cursor_visible) |
| 735 | { |
| 736 | screen_buffer->cursor_size = req->cursor_size; |
| 737 | screen_buffer->cursor_visible = req->cursor_visible; |
| 738 | evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT; |
| 739 | evt.u.cursor_geom.size = req->cursor_size; |
| 740 | evt.u.cursor_geom.visible = req->cursor_visible; |
| 741 | console_input_events_append( screen_buffer->input->evt, &evt ); |
| 742 | } |
| 743 | } |
| 744 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS) |
| 745 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 746 | if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 747 | req->cursor_y < 0 || req->cursor_y >= screen_buffer->height) |
| 748 | { |
| 749 | set_error( STATUS_INVALID_PARAMETER ); |
| 750 | return 0; |
| 751 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 752 | if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 753 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 754 | screen_buffer->cursor_x = req->cursor_x; |
| 755 | screen_buffer->cursor_y = req->cursor_y; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 756 | evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT; |
| 757 | evt.u.cursor_pos.x = req->cursor_x; |
| 758 | evt.u.cursor_pos.y = req->cursor_y; |
| 759 | console_input_events_append( screen_buffer->input->evt, &evt ); |
| 760 | } |
| 761 | } |
| 762 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE) |
| 763 | { |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 764 | unsigned cc; |
| 765 | |
| 766 | /* new screen-buffer cannot be smaller than actual window */ |
| 767 | if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 || |
| 768 | req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1) |
| 769 | { |
| 770 | set_error( STATUS_INVALID_PARAMETER ); |
| 771 | return 0; |
| 772 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 773 | /* FIXME: there are also some basic minimum and max size to deal with */ |
| 774 | if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 775 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 776 | evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT; |
| 777 | evt.u.resize.width = req->width; |
| 778 | evt.u.resize.height = req->height; |
| 779 | console_input_events_append( screen_buffer->input->evt, &evt ); |
| 780 | |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 781 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
| 782 | evt.u.update.top = 0; |
| 783 | evt.u.update.bottom = screen_buffer->height - 1; |
| 784 | console_input_events_append( screen_buffer->input->evt, &evt ); |
| 785 | |
| 786 | /* scroll window to display sb */ |
| 787 | if (screen_buffer->win.right >= req->width) |
| 788 | { |
| 789 | screen_buffer->win.right -= screen_buffer->win.left; |
| 790 | screen_buffer->win.left = 0; |
| 791 | } |
| 792 | if (screen_buffer->win.bottom >= req->height) |
| 793 | { |
| 794 | screen_buffer->win.bottom -= screen_buffer->win.top; |
| 795 | screen_buffer->win.top = 0; |
| 796 | } |
| 797 | /* reset cursor if needed (normally, if cursor was outside of new sb, the |
| 798 | * window has been shifted so that the new position of the cursor will be |
| 799 | * visible */ |
| 800 | cc = 0; |
| 801 | if (screen_buffer->cursor_x >= req->width) |
| 802 | { |
| 803 | screen_buffer->cursor_x = req->width - 1; |
| 804 | cc++; |
| 805 | } |
| 806 | if (screen_buffer->cursor_y >= req->height) |
| 807 | { |
| 808 | screen_buffer->cursor_y = req->height - 1; |
| 809 | cc++; |
| 810 | } |
| 811 | if (cc) |
| 812 | { |
| 813 | evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT; |
| 814 | evt.u.cursor_pos.x = req->cursor_x; |
| 815 | evt.u.cursor_pos.y = req->cursor_y; |
| 816 | console_input_events_append( screen_buffer->input->evt, &evt ); |
| 817 | } |
| 818 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 819 | if (screen_buffer == screen_buffer->input->active && |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 820 | screen_buffer->input->mode & ENABLE_WINDOW_INPUT) |
| 821 | { |
| 822 | INPUT_RECORD ir; |
| 823 | ir.EventType = WINDOW_BUFFER_SIZE_EVENT; |
| 824 | ir.Event.WindowBufferSizeEvent.dwSize.X = req->width; |
| 825 | ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height; |
| 826 | write_console_input( screen_buffer->input, 1, &ir ); |
| 827 | } |
| 828 | } |
| 829 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR) |
| 830 | { |
| 831 | screen_buffer->attr = req->attr; |
| 832 | } |
| 833 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW) |
| 834 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 835 | if (req->win_left < 0 || req->win_left > req->win_right || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 836 | req->win_right >= screen_buffer->width || |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 837 | req->win_top < 0 || req->win_top > req->win_bottom || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 838 | req->win_bottom >= screen_buffer->height) |
| 839 | { |
| 840 | set_error( STATUS_INVALID_PARAMETER ); |
| 841 | return 0; |
| 842 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 843 | if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top || |
| 844 | screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 845 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 846 | screen_buffer->win.left = req->win_left; |
| 847 | screen_buffer->win.top = req->win_top; |
| 848 | screen_buffer->win.right = req->win_right; |
| 849 | screen_buffer->win.bottom = req->win_bottom; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 850 | evt.event = CONSOLE_RENDERER_DISPLAY_EVENT; |
| 851 | evt.u.display.left = req->win_left; |
| 852 | evt.u.display.top = req->win_top; |
| 853 | evt.u.display.width = req->win_right - req->win_left + 1; |
| 854 | evt.u.display.height = req->win_bottom - req->win_top + 1; |
| 855 | console_input_events_append( screen_buffer->input->evt, &evt ); |
| 856 | } |
| 857 | } |
| 858 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE) |
| 859 | { |
| 860 | /* can only be done by renderer */ |
| 861 | if (current->process->console != screen_buffer->input) |
| 862 | { |
| 863 | set_error( STATUS_INVALID_PARAMETER ); |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | screen_buffer->max_width = req->max_width; |
| 868 | screen_buffer->max_height = req->max_height; |
| 869 | } |
| 870 | |
| 871 | return 1; |
| 872 | } |
| 873 | |
| 874 | /* appends a new line to history (history is a fixed size array) */ |
| 875 | static void console_input_append_hist( struct console_input* console, const WCHAR* buf, size_t len ) |
| 876 | { |
| 877 | WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) ); |
| 878 | |
| 879 | if (!ptr) |
| 880 | { |
| 881 | set_error( STATUS_NO_MEMORY ); |
| 882 | return; |
| 883 | } |
| 884 | if (!console || !console->history_size) |
| 885 | { |
| 886 | set_error( STATUS_INVALID_PARAMETER ); /* FIXME */ |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | memcpy( ptr, buf, len * sizeof(WCHAR) ); |
| 891 | ptr[len] = 0; |
| 892 | |
| 893 | if (console->history_mode && console->history_index && |
| 894 | strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0) |
| 895 | { |
| 896 | /* ok, mode ask us to not use twice the same string... |
| 897 | * so just free mem and returns |
| 898 | */ |
| 899 | set_error( STATUS_ALIAS_EXISTS ); |
| 900 | free(ptr); |
| 901 | return; |
| 902 | } |
| 903 | |
| 904 | if (console->history_index < console->history_size) |
| 905 | { |
| 906 | console->history[console->history_index++] = ptr; |
| 907 | } |
| 908 | else |
| 909 | { |
| 910 | free( console->history[0]) ; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 911 | memmove( &console->history[0], &console->history[1], |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 912 | (console->history_size - 1) * sizeof(WCHAR*) ); |
| 913 | console->history[console->history_size - 1] = ptr; |
| 914 | } |
| 915 | } |
| 916 | |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 917 | /* returns a line from the cache */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 918 | static size_t console_input_get_hist( struct console_input *console, int index ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 919 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 920 | size_t ret = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 921 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 922 | if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER ); |
| 923 | else |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 924 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 925 | ret = strlenW( console->history[index] ) * sizeof(WCHAR); |
| 926 | set_reply_data( console->history[index], min( ret, get_reply_max_size() )); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 927 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 928 | return ret; |
| 929 | } |
| 930 | |
| 931 | /* dumb dump */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 932 | static void console_input_dump( struct object *obj, int verbose ) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 933 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 934 | struct console_input *console = (struct console_input *)obj; |
| 935 | assert( obj->ops == &console_input_ops ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 936 | fprintf( stderr, "Console input active=%p evt=%p\n", |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 937 | console->active, console->evt ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 940 | static void console_input_destroy( struct object *obj ) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 941 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 942 | struct console_input* console_in = (struct console_input *)obj; |
| 943 | struct screen_buffer* curr; |
| 944 | int i; |
| 945 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 946 | assert( obj->ops == &console_input_ops ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 947 | if (console_in->title) free( console_in->title ); |
| 948 | if (console_in->records) free( console_in->records ); |
| 949 | |
| 950 | if (console_in->active) release_object( console_in->active ); |
| 951 | console_in->active = NULL; |
| 952 | |
| 953 | for (curr = screen_buffer_list; curr; curr = curr->next) |
| 954 | { |
| 955 | if (curr->input == console_in) curr->input = NULL; |
| 956 | } |
| 957 | |
| 958 | release_object( console_in->evt ); |
| 959 | console_in->evt = NULL; |
| 960 | |
| 961 | for (i = 0; i < console_in->history_size; i++) |
| 962 | if (console_in->history[i]) free( console_in->history[i] ); |
| 963 | if (console_in->history) free( console_in->history ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | static void screen_buffer_dump( struct object *obj, int verbose ) |
| 967 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 968 | struct screen_buffer *screen_buffer = (struct screen_buffer *)obj; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 969 | assert( obj->ops == &screen_buffer_ops ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 970 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 971 | fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | static void screen_buffer_destroy( struct object *obj ) |
| 975 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 976 | struct screen_buffer *screen_buffer = (struct screen_buffer *)obj; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 977 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 978 | assert( obj->ops == &screen_buffer_ops ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 979 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 980 | if (screen_buffer->next) screen_buffer->next->prev = screen_buffer->prev; |
| 981 | if (screen_buffer->prev) screen_buffer->prev->next = screen_buffer->next; |
| 982 | else screen_buffer_list = screen_buffer->next; |
| 983 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 984 | if (screen_buffer->input && screen_buffer->input->active == screen_buffer) |
| 985 | { |
| 986 | struct screen_buffer* sb; |
| 987 | for (sb = screen_buffer_list; sb && sb->input != screen_buffer->input; sb = sb->next); |
| 988 | screen_buffer->input->active = sb; |
| 989 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 990 | if (screen_buffer->data) free( screen_buffer->data ); |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 991 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 992 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 993 | /* write data into a screen buffer */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 994 | static int write_console_output( struct screen_buffer *screen_buffer, size_t size, |
| 995 | const void* data, enum char_info_mode mode, |
| 996 | int x, int y, int wrap ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 997 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 998 | int i; |
| 999 | char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1000 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1001 | if (y >= screen_buffer->height) return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1002 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1003 | if (wrap) |
| 1004 | end = screen_buffer->data + screen_buffer->height * screen_buffer->width; |
| 1005 | else |
| 1006 | end = screen_buffer->data + (y+1) * screen_buffer->width; |
| 1007 | |
| 1008 | switch(mode) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1009 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1010 | case CHAR_INFO_MODE_TEXT: |
| 1011 | { |
| 1012 | const WCHAR *ptr = data; |
| 1013 | for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i]; |
| 1014 | } |
| 1015 | break; |
| 1016 | case CHAR_INFO_MODE_ATTR: |
| 1017 | { |
| 1018 | const unsigned short *ptr = data; |
| 1019 | for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i]; |
| 1020 | } |
| 1021 | break; |
| 1022 | case CHAR_INFO_MODE_TEXTATTR: |
| 1023 | { |
| 1024 | const char_info_t *ptr = data; |
| 1025 | for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i]; |
| 1026 | } |
| 1027 | break; |
| 1028 | case CHAR_INFO_MODE_TEXTSTDATTR: |
| 1029 | { |
| 1030 | const WCHAR *ptr = data; |
| 1031 | for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) |
| 1032 | { |
| 1033 | dest->ch = ptr[i]; |
| 1034 | dest->attr = screen_buffer->attr; |
| 1035 | } |
| 1036 | } |
| 1037 | break; |
| 1038 | default: |
| 1039 | set_error( STATUS_INVALID_PARAMETER ); |
| 1040 | return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1043 | if (i && screen_buffer == screen_buffer->input->active) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1044 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1045 | struct console_renderer_event evt; |
| 1046 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 1047 | evt.u.update.top = y + x / screen_buffer->width; |
| 1048 | evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1049 | console_input_events_append( screen_buffer->input->evt, &evt ); |
| 1050 | } |
| 1051 | return i; |
| 1052 | } |
| 1053 | |
| 1054 | /* fill a screen buffer with uniform data */ |
| 1055 | static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data, |
| 1056 | enum char_info_mode mode, int x, int y, int count, int wrap ) |
| 1057 | { |
| 1058 | int i; |
| 1059 | char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x; |
| 1060 | |
| 1061 | if (y >= screen_buffer->height) return 0; |
| 1062 | |
| 1063 | if (wrap) |
| 1064 | end = screen_buffer->data + screen_buffer->height * screen_buffer->width; |
| 1065 | else |
| 1066 | end = screen_buffer->data + (y+1) * screen_buffer->width; |
| 1067 | |
| 1068 | if (count > end - dest) count = end - dest; |
| 1069 | |
| 1070 | switch(mode) |
| 1071 | { |
| 1072 | case CHAR_INFO_MODE_TEXT: |
| 1073 | for (i = 0; i < count; i++) dest[i].ch = data.ch; |
| 1074 | break; |
| 1075 | case CHAR_INFO_MODE_ATTR: |
| 1076 | for (i = 0; i < count; i++) dest[i].attr = data.attr; |
| 1077 | break; |
| 1078 | case CHAR_INFO_MODE_TEXTATTR: |
| 1079 | for (i = 0; i < count; i++) dest[i] = data; |
| 1080 | break; |
| 1081 | case CHAR_INFO_MODE_TEXTSTDATTR: |
| 1082 | for (i = 0; i < count; i++) |
| 1083 | { |
| 1084 | dest[i].ch = data.ch; |
| 1085 | dest[i].attr = screen_buffer->attr; |
| 1086 | } |
| 1087 | break; |
| 1088 | default: |
| 1089 | set_error( STATUS_INVALID_PARAMETER ); |
| 1090 | return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1093 | if (count && screen_buffer == screen_buffer->input->active) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1094 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1095 | struct console_renderer_event evt; |
| 1096 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
| 1097 | evt.u.update.top = y; |
| 1098 | evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width; |
| 1099 | console_input_events_append( screen_buffer->input->evt, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1100 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1101 | return i; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /* read data from a screen buffer */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1105 | static void read_console_output( struct screen_buffer *screen_buffer, int x, int y, |
| 1106 | enum char_info_mode mode, int wrap ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1107 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1108 | int i; |
| 1109 | char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1110 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1111 | if (y >= screen_buffer->height) return; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1112 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1113 | if (wrap) |
| 1114 | end = screen_buffer->data + screen_buffer->height * screen_buffer->width; |
| 1115 | else |
| 1116 | end = screen_buffer->data + (y+1) * screen_buffer->width; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1117 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1118 | switch(mode) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1119 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1120 | case CHAR_INFO_MODE_TEXT: |
| 1121 | { |
| 1122 | WCHAR *data; |
| 1123 | int count = min( end - src, get_reply_max_size() / sizeof(*data) ); |
| 1124 | if ((data = set_reply_data_size( count * sizeof(*data) ))) |
| 1125 | { |
| 1126 | for (i = 0; i < count; i++) data[i] = src[i].ch; |
| 1127 | } |
| 1128 | } |
| 1129 | break; |
| 1130 | case CHAR_INFO_MODE_ATTR: |
| 1131 | { |
| 1132 | unsigned short *data; |
| 1133 | int count = min( end - src, get_reply_max_size() / sizeof(*data) ); |
| 1134 | if ((data = set_reply_data_size( count * sizeof(*data) ))) |
| 1135 | { |
| 1136 | for (i = 0; i < count; i++) data[i] = src[i].attr; |
| 1137 | } |
| 1138 | } |
| 1139 | break; |
| 1140 | case CHAR_INFO_MODE_TEXTATTR: |
| 1141 | { |
| 1142 | char_info_t *data; |
| 1143 | int count = min( end - src, get_reply_max_size() / sizeof(*data) ); |
| 1144 | if ((data = set_reply_data_size( count * sizeof(*data) ))) |
| 1145 | { |
| 1146 | for (i = 0; i < count; i++) data[i] = src[i]; |
| 1147 | } |
| 1148 | } |
| 1149 | break; |
| 1150 | default: |
| 1151 | set_error( STATUS_INVALID_PARAMETER ); |
| 1152 | break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1153 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /* scroll parts of a screen buffer */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 1157 | static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1158 | int w, int h ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1159 | { |
| 1160 | struct screen_buffer *screen_buffer; |
| 1161 | int j; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1162 | char_info_t *psrc, *pdst; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1163 | struct console_renderer_event evt; |
| 1164 | |
| 1165 | if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle, |
| 1166 | GENERIC_READ, &screen_buffer_ops ))) |
| 1167 | return; |
| 1168 | if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 || |
| 1169 | xsrc + w > screen_buffer->width || |
| 1170 | xdst + w > screen_buffer->width || |
| 1171 | ysrc + h > screen_buffer->height || |
| 1172 | ydst + h > screen_buffer->height || |
| 1173 | w == 0 || h == 0) |
| 1174 | { |
| 1175 | set_error( STATUS_INVALID_PARAMETER ); |
| 1176 | release_object( screen_buffer ); |
| 1177 | return; |
| 1178 | } |
| 1179 | |
| 1180 | if (ysrc < ydst) |
| 1181 | { |
| 1182 | psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc]; |
| 1183 | pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst]; |
| 1184 | |
| 1185 | for (j = h; j > 0; j--) |
| 1186 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1187 | memcpy(pdst, psrc, w * sizeof(*pdst) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1188 | pdst -= screen_buffer->width; |
| 1189 | psrc -= screen_buffer->width; |
| 1190 | } |
| 1191 | } |
| 1192 | else |
| 1193 | { |
| 1194 | psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc]; |
| 1195 | pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst]; |
| 1196 | |
| 1197 | for (j = 0; j < h; j++) |
| 1198 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1199 | /* we use memmove here because when psrc and pdst are the same, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1200 | * copies are done on the same row, so the dst and src blocks |
| 1201 | * can overlap */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1202 | memmove( pdst, psrc, w * sizeof(*pdst) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1203 | pdst += screen_buffer->width; |
| 1204 | psrc += screen_buffer->width; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | /* FIXME: this could be enhanced, by signalling scroll */ |
| 1209 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
| 1210 | evt.u.update.top = min(ysrc, ydst); |
| 1211 | evt.u.update.bottom = max(ysrc, ydst) + h - 1; |
| 1212 | console_input_events_append( screen_buffer->input->evt, &evt ); |
| 1213 | |
| 1214 | release_object( screen_buffer ); |
| 1215 | } |
| 1216 | |
| 1217 | /* allocate a console for the renderer */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1218 | DECL_HANDLER(alloc_console) |
| 1219 | { |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 1220 | obj_handle_t in = 0; |
| 1221 | obj_handle_t evt = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1222 | struct process *process; |
| 1223 | struct process *renderer = current->process; |
| 1224 | struct console_input *console; |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 1225 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1226 | process = (req->pid) ? get_process_from_id( req->pid ) : |
| 1227 | (struct process *)grab_object( renderer->parent ); |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 1228 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1229 | reply->handle_in = 0; |
| 1230 | reply->event = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1231 | if (!process) return; |
| 1232 | if (process != renderer && process->console) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1233 | { |
| 1234 | set_error( STATUS_ACCESS_DENIED ); |
| 1235 | goto the_end; |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 1236 | } |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 1237 | |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 1238 | if ((console = (struct console_input*)create_console_input( current ))) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1239 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1240 | if ((in = alloc_handle( renderer, console, req->access, req->inherit ))) |
| 1241 | { |
| 1242 | if ((evt = alloc_handle( renderer, console->evt, |
| 1243 | SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, FALSE ))) |
| 1244 | { |
| 1245 | if (process != renderer) |
| 1246 | { |
| 1247 | process->console = (struct console_input*)grab_object( console ); |
| 1248 | console->num_proc++; |
| 1249 | } |
| 1250 | reply->handle_in = in; |
| 1251 | reply->event = evt; |
| 1252 | release_object( console ); |
| 1253 | goto the_end; |
| 1254 | } |
| 1255 | close_handle( renderer, in, NULL ); |
| 1256 | } |
| 1257 | free_console( process ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1258 | } |
| 1259 | the_end: |
| 1260 | release_object( process ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /* free the console of the current process */ |
| 1264 | DECL_HANDLER(free_console) |
| 1265 | { |
| 1266 | free_console( current->process ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1269 | /* let the renderer peek the events it's waiting on */ |
| 1270 | DECL_HANDLER(get_console_renderer_events) |
| 1271 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1272 | struct console_input_events *evt; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1273 | |
| 1274 | evt = (struct console_input_events *)get_handle_obj( current->process, req->handle, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1275 | GENERIC_WRITE, &console_input_events_ops ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1276 | if (!evt) return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1277 | console_input_events_get( evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1278 | release_object( evt ); |
| 1279 | } |
| 1280 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1281 | /* open a handle to the process console */ |
| 1282 | DECL_HANDLER(open_console) |
| 1283 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1284 | struct object *obj = NULL; |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 1285 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1286 | reply->handle = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1287 | switch (req->from) |
| 1288 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1289 | case 0: |
| 1290 | if (current->process->console && current->process->console->renderer) |
| 1291 | obj = grab_object( (struct object*)current->process->console ); |
| 1292 | break; |
| 1293 | case 1: |
| 1294 | if (current->process->console && current->process->console->renderer && |
| 1295 | current->process->console->active) |
| 1296 | obj = grab_object( (struct object*)current->process->console->active ); |
| 1297 | break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1298 | default: |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 1299 | if ((obj = get_handle_obj( current->process, (obj_handle_t)req->from, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1300 | GENERIC_READ|GENERIC_WRITE, &console_input_ops ))) |
| 1301 | { |
| 1302 | struct console_input* console = (struct console_input*)obj; |
| 1303 | obj = (console->active) ? grab_object( console->active ) : NULL; |
| 1304 | release_object( console ); |
| 1305 | } |
| 1306 | break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | /* FIXME: req->share is not used (as in screen buffer creation) */ |
| 1310 | if (obj) |
| 1311 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1312 | reply->handle = alloc_handle( current->process, obj, req->access, req->inherit ); |
| 1313 | release_object( obj ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1314 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1315 | else if (!get_error()) set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1318 | /* set info about a console input */ |
| 1319 | DECL_HANDLER(set_console_input_info) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1320 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1321 | set_console_input_info( req, get_req_data(), get_req_data_size() ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /* get info about a console (output only) */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1325 | DECL_HANDLER(get_console_input_info) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1326 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1327 | struct console_input *console; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 1328 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1329 | if (!(console = console_input_get( req->handle, GENERIC_READ ))) return; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1330 | if (console->title) |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 1331 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1332 | size_t len = strlenW( console->title ) * sizeof(WCHAR); |
| 1333 | if (len > get_reply_max_size()) len = get_reply_max_size(); |
| 1334 | set_reply_data( console->title, len ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 1335 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1336 | reply->history_mode = console->history_mode; |
| 1337 | reply->history_size = console->history_size; |
| 1338 | reply->history_index = console->history_index; |
Eric Pouech | fa8b85a | 2003-01-09 06:01:32 +0000 | [diff] [blame] | 1339 | reply->edition_mode = console->edition_mode; |
| 1340 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1341 | release_object( console ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | /* get a console mode (input or output) */ |
| 1345 | DECL_HANDLER(get_console_mode) |
| 1346 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1347 | reply->mode = get_console_mode( req->handle ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | /* set a console mode (input or output) */ |
| 1351 | DECL_HANDLER(set_console_mode) |
| 1352 | { |
| 1353 | set_console_mode( req->handle, req->mode ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | /* add input records to a console input queue */ |
| 1357 | DECL_HANDLER(write_console_input) |
| 1358 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1359 | struct console_input *console; |
| 1360 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1361 | reply->written = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1362 | if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle, |
| 1363 | GENERIC_WRITE, &console_input_ops ))) |
| 1364 | return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1365 | reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD), |
| 1366 | get_req_data() ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1367 | release_object( console ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /* fetch input records from a console input queue */ |
| 1371 | DECL_HANDLER(read_console_input) |
| 1372 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1373 | int count = get_reply_max_size() / sizeof(INPUT_RECORD); |
| 1374 | reply->read = read_console_input( req->handle, count, req->flush ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1375 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1376 | |
| 1377 | /* appends a string to console's history */ |
| 1378 | DECL_HANDLER(append_console_input_history) |
| 1379 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1380 | struct console_input *console; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1381 | |
| 1382 | if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1383 | console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1384 | release_object( console ); |
| 1385 | } |
| 1386 | |
| 1387 | /* appends a string to console's history */ |
| 1388 | DECL_HANDLER(get_console_input_history) |
| 1389 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1390 | struct console_input *console; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1391 | |
| 1392 | if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1393 | reply->total = console_input_get_hist( console, req->index ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1394 | release_object( console ); |
| 1395 | } |
| 1396 | |
| 1397 | /* creates a screen buffer */ |
| 1398 | DECL_HANDLER(create_console_output) |
| 1399 | { |
| 1400 | struct console_input* console; |
| 1401 | struct screen_buffer* screen_buffer; |
| 1402 | |
| 1403 | if (!(console = console_input_get( req->handle_in, GENERIC_WRITE))) return; |
| 1404 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1405 | screen_buffer = create_console_output( console ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1406 | if (screen_buffer) |
| 1407 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1408 | /* FIXME: should store sharing and test it when opening the CONOUT$ device |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1409 | * see file.c on how this could be done */ |
| 1410 | reply->handle_out = alloc_handle( current->process, screen_buffer, |
| 1411 | req->access, req->inherit ); |
| 1412 | release_object( screen_buffer ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1413 | } |
| 1414 | release_object( console ); |
| 1415 | } |
| 1416 | |
| 1417 | /* set info about a console screen buffer */ |
| 1418 | DECL_HANDLER(set_console_output_info) |
| 1419 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1420 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1421 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1422 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
| 1423 | GENERIC_WRITE, &screen_buffer_ops))) |
| 1424 | { |
| 1425 | set_console_output_info( screen_buffer, req ); |
| 1426 | release_object( screen_buffer ); |
| 1427 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | /* get info about a console screen buffer */ |
| 1431 | DECL_HANDLER(get_console_output_info) |
| 1432 | { |
| 1433 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1434 | |
| 1435 | if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1436 | GENERIC_READ, &screen_buffer_ops))) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1437 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1438 | reply->cursor_size = screen_buffer->cursor_size; |
| 1439 | reply->cursor_visible = screen_buffer->cursor_visible; |
| 1440 | reply->cursor_x = screen_buffer->cursor_x; |
| 1441 | reply->cursor_y = screen_buffer->cursor_y; |
| 1442 | reply->width = screen_buffer->width; |
| 1443 | reply->height = screen_buffer->height; |
| 1444 | reply->attr = screen_buffer->attr; |
| 1445 | reply->win_left = screen_buffer->win.left; |
| 1446 | reply->win_top = screen_buffer->win.top; |
| 1447 | reply->win_right = screen_buffer->win.right; |
| 1448 | reply->win_bottom = screen_buffer->win.bottom; |
| 1449 | reply->max_width = screen_buffer->max_width; |
| 1450 | reply->max_height = screen_buffer->max_height; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1451 | release_object( screen_buffer ); |
| 1452 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | /* read data (chars & attrs) from a screen buffer */ |
| 1456 | DECL_HANDLER(read_console_output) |
| 1457 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1458 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1459 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1460 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
| 1461 | GENERIC_READ, &screen_buffer_ops ))) |
| 1462 | { |
| 1463 | read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap ); |
| 1464 | reply->width = screen_buffer->width; |
| 1465 | reply->height = screen_buffer->height; |
| 1466 | release_object( screen_buffer ); |
| 1467 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | /* write data (char and/or attrs) to a screen buffer */ |
| 1471 | DECL_HANDLER(write_console_output) |
| 1472 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1473 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1474 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1475 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
| 1476 | GENERIC_WRITE, &screen_buffer_ops))) |
| 1477 | { |
| 1478 | reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(), |
| 1479 | req->mode, req->x, req->y, req->wrap ); |
| 1480 | reply->width = screen_buffer->width; |
| 1481 | reply->height = screen_buffer->height; |
| 1482 | release_object( screen_buffer ); |
| 1483 | } |
| 1484 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1485 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1486 | /* fill a screen buffer with constant data (chars and/or attributes) */ |
| 1487 | DECL_HANDLER(fill_console_output) |
| 1488 | { |
| 1489 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1490 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1491 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
| 1492 | GENERIC_WRITE, &screen_buffer_ops))) |
| 1493 | { |
| 1494 | reply->written = fill_console_output( screen_buffer, req->data, req->mode, |
| 1495 | req->x, req->y, req->count, req->wrap ); |
| 1496 | release_object( screen_buffer ); |
| 1497 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | /* move a rect of data in a screen buffer */ |
| 1501 | DECL_HANDLER(move_console_output) |
| 1502 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1503 | scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1504 | req->w, req->h ); |
| 1505 | } |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 1506 | |
| 1507 | /* sends a signal to a console (process, group...) */ |
| 1508 | DECL_HANDLER(send_console_signal) |
| 1509 | { |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 1510 | process_id_t group; |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 1511 | |
| 1512 | group = req->group_id ? req->group_id : current->process->group_id; |
| 1513 | |
| 1514 | if (!group) |
| 1515 | set_error( STATUS_INVALID_PARAMETER); |
| 1516 | else |
| 1517 | propagate_console_signal( current->process->console, req->signal, group ); |
| 1518 | } |