commdlg: Updated Korean translation.
[wine/multimedia.git] / server / console.c
blobf6b97bda1cfb0718931869a4a0122456c955bf68
1 /*
2 * Server-side console management
4 * Copyright (C) 1998 Alexandre Julliard
5 * 2001 Eric Pouech
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.
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.
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
23 #include "config.h"
24 #include "wine/port.h"
26 #include <assert.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <signal.h>
32 #include "ntstatus.h"
33 #define WIN32_NO_STATUS
34 #include "handle.h"
35 #include "process.h"
36 #include "request.h"
37 #include "unicode.h"
38 #include "console.h"
39 #include "winternl.h"
41 /* specific access rights (FIXME: should use finer-grained access rights) */
42 #define CONSOLE_READ 0x01
43 #define CONSOLE_WRITE 0x02
45 static unsigned int console_map_access( struct object *obj, unsigned int access );
47 static void console_input_dump( struct object *obj, int verbose );
48 static void console_input_destroy( struct object *obj );
50 static const struct object_ops console_input_ops =
52 sizeof(struct console_input), /* size */
53 console_input_dump, /* dump */
54 no_add_queue, /* add_queue */
55 NULL, /* remove_queue */
56 NULL, /* signaled */
57 no_satisfied, /* satisfied */
58 no_signal, /* signal */
59 no_get_fd, /* get_fd */
60 console_map_access, /* map_access */
61 no_lookup_name, /* lookup_name */
62 no_close_handle, /* close_handle */
63 console_input_destroy /* destroy */
66 static void console_input_events_dump( struct object *obj, int verbose );
67 static void console_input_events_destroy( struct object *obj );
68 static int console_input_events_signaled( struct object *obj, struct thread *thread );
70 struct console_input_events
72 struct object obj; /* object header */
73 int num_alloc; /* number of allocated events */
74 int num_used; /* number of actually used events */
75 struct console_renderer_event* events;
78 static const struct object_ops console_input_events_ops =
80 sizeof(struct console_input_events), /* size */
81 console_input_events_dump, /* dump */
82 add_queue, /* add_queue */
83 remove_queue, /* remove_queue */
84 console_input_events_signaled, /* signaled */
85 no_satisfied, /* satisfied */
86 no_signal, /* signal */
87 no_get_fd, /* get_fd */
88 console_map_access, /* map_access */
89 no_lookup_name, /* lookup_name */
90 no_close_handle, /* close_handle */
91 console_input_events_destroy /* destroy */
94 struct screen_buffer
96 struct object obj; /* object header */
97 struct list entry; /* entry in list of all screen buffers */
98 struct console_input *input; /* associated console input */
99 int mode; /* output mode */
100 int cursor_size; /* size of cursor (percentage filled) */
101 int cursor_visible;/* cursor visibility flag */
102 int cursor_x; /* position of cursor */
103 int cursor_y; /* position of cursor */
104 int width; /* size (w-h) of the screen buffer */
105 int height;
106 int max_width; /* size (w-h) of the window given font size */
107 int max_height;
108 char_info_t *data; /* the data for each cell - a width x height matrix */
109 unsigned short attr; /* default attribute for screen buffer */
110 rectangle_t win; /* current visible window on the screen buffer *
111 * as seen in wineconsole */
114 static void screen_buffer_dump( struct object *obj, int verbose );
115 static void screen_buffer_destroy( struct object *obj );
117 static const struct object_ops screen_buffer_ops =
119 sizeof(struct screen_buffer), /* size */
120 screen_buffer_dump, /* dump */
121 no_add_queue, /* add_queue */
122 NULL, /* remove_queue */
123 NULL, /* signaled */
124 NULL, /* satisfied */
125 no_signal, /* signal */
126 no_get_fd, /* get_fd */
127 console_map_access, /* map_access */
128 no_lookup_name, /* lookup_name */
129 no_close_handle, /* close_handle */
130 screen_buffer_destroy /* destroy */
133 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
135 static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */
137 /* access mapping for all console objects */
138 static unsigned int console_map_access( struct object *obj, unsigned int access )
140 if (access & GENERIC_READ) access |= SYNCHRONIZE | STANDARD_RIGHTS_READ | CONSOLE_READ;
141 if (access & GENERIC_WRITE) access |= SYNCHRONIZE | STANDARD_RIGHTS_WRITE | CONSOLE_WRITE;
142 if (access & GENERIC_EXECUTE) access |= SYNCHRONIZE | STANDARD_RIGHTS_EXECUTE;
143 if (access & GENERIC_ALL) access |= STANDARD_RIGHTS_ALL | CONSOLE_READ | CONSOLE_WRITE;
144 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
147 /* dumps the renderer events of a console */
148 static void console_input_events_dump( struct object *obj, int verbose )
150 struct console_input_events *evts = (struct console_input_events *)obj;
151 assert( obj->ops == &console_input_events_ops );
152 fprintf( stderr, "Console input events: %d/%d events\n",
153 evts->num_used, evts->num_alloc );
156 /* destroys the renderer events of a console */
157 static void console_input_events_destroy( struct object *obj )
159 struct console_input_events *evts = (struct console_input_events *)obj;
160 assert( obj->ops == &console_input_events_ops );
161 free( evts->events );
164 /* the renderer events list is signaled when it's not empty */
165 static int console_input_events_signaled( struct object *obj, struct thread *thread )
167 struct console_input_events *evts = (struct console_input_events *)obj;
168 assert( obj->ops == &console_input_events_ops );
169 return (evts->num_used != 0);
172 /* add an event to the console's renderer events list */
173 static void console_input_events_append( struct console_input_events* evts,
174 struct console_renderer_event* evt)
176 int collapsed = FALSE;
178 /* to be done even when evt has been generated by the rendere ? */
180 /* try to collapse evt into current queue's events */
181 if (evts->num_used)
183 struct console_renderer_event* last = &evts->events[evts->num_used - 1];
185 if (last->event == CONSOLE_RENDERER_UPDATE_EVENT &&
186 evt->event == CONSOLE_RENDERER_UPDATE_EVENT)
188 /* if two update events overlap, collapse them into a single one */
189 if (last->u.update.bottom + 1 >= evt->u.update.top &&
190 evt->u.update.bottom + 1 >= last->u.update.top)
192 last->u.update.top = min(last->u.update.top, evt->u.update.top);
193 last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom);
194 collapsed = TRUE;
198 if (!collapsed)
200 if (evts->num_used == evts->num_alloc)
202 evts->num_alloc += 16;
203 evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) );
204 assert(evts->events);
206 evts->events[evts->num_used++] = *evt;
208 wake_up( &evts->obj, 0 );
211 /* retrieves events from the console's renderer events list */
212 static void console_input_events_get( struct console_input_events* evts )
214 size_t num = get_reply_max_size() / sizeof(evts->events[0]);
216 if (num > evts->num_used) num = evts->num_used;
217 set_reply_data( evts->events, num * sizeof(evts->events[0]) );
218 if (num < evts->num_used)
220 memmove( &evts->events[0], &evts->events[num],
221 (evts->num_used - num) * sizeof(evts->events[0]) );
223 evts->num_used -= num;
226 static struct console_input_events *create_console_input_events(void)
228 struct console_input_events* evt;
230 if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
231 evt->num_alloc = evt->num_used = 0;
232 evt->events = NULL;
233 return evt;
236 static struct object *create_console_input( struct thread* renderer )
238 struct console_input *console_input;
240 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
241 console_input->renderer = renderer;
242 console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
243 ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
244 console_input->num_proc = 0;
245 console_input->active = NULL;
246 console_input->recnum = 0;
247 console_input->records = NULL;
248 console_input->evt = create_console_input_events();
249 console_input->title = NULL;
250 console_input->history_size = 50;
251 console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
252 console_input->history_index = 0;
253 console_input->history_mode = 0;
254 console_input->edition_mode = 0;
255 console_input->event = create_event( NULL, NULL, 0, 1, 0 );
257 if (!console_input->history || !console_input->evt)
259 release_object( console_input );
260 return NULL;
262 return &console_input->obj;
265 static struct screen_buffer *create_console_output( struct console_input *console_input )
267 struct screen_buffer *screen_buffer;
268 struct console_renderer_event evt;
269 int i;
271 if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL;
272 screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
273 screen_buffer->input = console_input;
274 screen_buffer->cursor_size = 100;
275 screen_buffer->cursor_visible = 1;
276 screen_buffer->width = 80;
277 screen_buffer->height = 150;
278 screen_buffer->max_width = 80;
279 screen_buffer->max_height = 25;
280 screen_buffer->cursor_x = 0;
281 screen_buffer->cursor_y = 0;
282 screen_buffer->attr = 0x0F;
283 screen_buffer->win.left = 0;
284 screen_buffer->win.right = screen_buffer->max_width - 1;
285 screen_buffer->win.top = 0;
286 screen_buffer->win.bottom = screen_buffer->max_height - 1;
288 list_add_head( &screen_buffer_list, &screen_buffer->entry );
290 if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
291 sizeof(*screen_buffer->data) )))
293 release_object( screen_buffer );
294 return NULL;
296 /* clear the first row */
297 for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info;
298 /* and copy it to all other rows */
299 for (i = 1; i < screen_buffer->height; i++)
300 memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data,
301 screen_buffer->width * sizeof(char_info_t) );
303 if (!console_input->active)
305 console_input->active = (struct screen_buffer*)grab_object( screen_buffer );
307 /* generate the initial events */
308 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
309 console_input_events_append( console_input->evt, &evt );
311 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
312 evt.u.resize.width = screen_buffer->width;
313 evt.u.resize.height = screen_buffer->height;
314 console_input_events_append( console_input->evt, &evt );
316 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
317 evt.u.display.left = screen_buffer->win.left;
318 evt.u.display.top = screen_buffer->win.top;
319 evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1;
320 evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1;
321 console_input_events_append( console_input->evt, &evt );
323 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
324 evt.u.update.top = 0;
325 evt.u.update.bottom = screen_buffer->height - 1;
326 console_input_events_append( console_input->evt, &evt );
328 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
329 evt.u.cursor_geom.size = screen_buffer->cursor_size;
330 evt.u.cursor_geom.visible = screen_buffer->cursor_visible;
331 console_input_events_append( console_input->evt, &evt );
333 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
334 evt.u.cursor_pos.x = screen_buffer->cursor_x;
335 evt.u.cursor_pos.y = screen_buffer->cursor_y;
336 console_input_events_append( console_input->evt, &evt );
338 return screen_buffer;
341 /* free the console for this process */
342 int free_console( struct process *process )
344 struct console_input* console = process->console;
346 if (!console || !console->renderer) return 0;
348 process->console = NULL;
349 if (--console->num_proc == 0)
351 /* all processes have terminated... tell the renderer to terminate too */
352 struct console_renderer_event evt;
353 evt.event = CONSOLE_RENDERER_EXIT_EVENT;
354 console_input_events_append( console->evt, &evt );
356 release_object( console );
358 return 1;
361 /* let process inherit the console from parent... this handle two cases :
362 * 1/ generic console inheritance
363 * 2/ parent is a renderer which launches process, and process should attach to the console
364 * renderered by parent
366 void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin)
368 int done = 0;
369 struct process* parent = parent_thread->process;
371 /* if parent is a renderer, then attach current process to its console
372 * a bit hacky....
374 if (hconin)
376 struct console_input* console;
378 /* FIXME: should we check some access rights ? */
379 if ((console = (struct console_input*)get_handle_obj( parent, hconin,
380 0, &console_input_ops )))
382 if (console->renderer == parent_thread)
384 process->console = (struct console_input*)grab_object( console );
385 process->console->num_proc++;
386 done = 1;
388 release_object( console );
390 else clear_error(); /* ignore error */
392 /* otherwise, if parent has a console, attach child to this console */
393 if (!done && parent->console)
395 assert(parent->console->renderer);
396 process->console = (struct console_input*)grab_object( parent->console );
397 process->console->num_proc++;
401 static struct console_input* console_input_get( obj_handle_t handle, unsigned access )
403 struct console_input* console = NULL;
405 if (handle)
406 console = (struct console_input *)get_handle_obj( current->process, handle,
407 access, &console_input_ops );
408 else if (current->process->console)
410 assert( current->process->console->renderer );
411 console = (struct console_input *)grab_object( current->process->console );
414 if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER);
415 return console;
418 struct console_signal_info
420 struct console_input *console;
421 process_id_t group;
422 int signal;
425 static int propagate_console_signal_cb(struct process *process, void *user)
427 struct console_signal_info* csi = (struct console_signal_info*)user;
429 if (process->console == csi->console && process->running_threads &&
430 (!csi->group || process->group_id == csi->group))
432 /* find a suitable thread to signal */
433 struct thread *thread;
434 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
436 if (send_thread_signal( thread, csi->signal )) break;
439 return FALSE;
442 static void propagate_console_signal( struct console_input *console,
443 int sig, process_id_t group_id )
445 struct console_signal_info csi;
447 if (!console)
449 set_error( STATUS_INVALID_PARAMETER );
450 return;
452 /* FIXME: should support the other events (like CTRL_BREAK) */
453 if (sig != CTRL_C_EVENT)
455 set_error( STATUS_NOT_IMPLEMENTED );
456 return;
458 csi.console = console;
459 csi.signal = SIGINT;
460 csi.group = group_id;
462 enum_processes(propagate_console_signal_cb, &csi);
465 static int get_console_mode( obj_handle_t handle )
467 struct object *obj;
468 int ret = 0;
470 if ((obj = get_handle_obj( current->process, handle, CONSOLE_READ, NULL )))
472 if (obj->ops == &console_input_ops)
473 ret = ((struct console_input *)obj)->mode;
474 else if (obj->ops == &screen_buffer_ops)
475 ret = ((struct screen_buffer *)obj)->mode;
476 else
477 set_error( STATUS_OBJECT_TYPE_MISMATCH );
478 release_object( obj );
480 return ret;
483 /* changes the mode of either a console input or a screen buffer */
484 static int set_console_mode( obj_handle_t handle, int mode )
486 struct object *obj;
487 int ret = 0;
489 if (!(obj = get_handle_obj( current->process, handle, CONSOLE_WRITE, NULL )))
490 return 0;
491 if (obj->ops == &console_input_ops)
493 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
494 ((struct console_input *)obj)->mode = mode;
495 ret = 1;
497 else if (obj->ops == &screen_buffer_ops)
499 ((struct screen_buffer *)obj)->mode = mode;
500 ret = 1;
502 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
503 release_object( obj );
504 return ret;
507 /* add input events to a console input queue */
508 static int write_console_input( struct console_input* console, int count,
509 const INPUT_RECORD *records )
511 INPUT_RECORD *new_rec;
513 if (!count) return 0;
514 if (!(new_rec = realloc( console->records,
515 (console->recnum + count) * sizeof(INPUT_RECORD) )))
517 set_error( STATUS_NO_MEMORY );
518 release_object( console );
519 return -1;
521 console->records = new_rec;
522 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
524 if (console->mode & ENABLE_PROCESSED_INPUT)
526 int i = 0;
527 while (i < count)
529 if (records[i].EventType == KEY_EVENT &&
530 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
531 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
533 if (i != count - 1)
534 memcpy( &console->records[console->recnum + i],
535 &console->records[console->recnum + i + 1],
536 (count - i - 1) * sizeof(INPUT_RECORD) );
537 count--;
538 if (records[i].Event.KeyEvent.bKeyDown)
540 /* send SIGINT to all processes attached to this console */
541 propagate_console_signal( console, CTRL_C_EVENT, 0 );
544 else i++;
547 if (!console->recnum && count) set_event( console->event );
548 console->recnum += count;
549 return count;
552 /* retrieve a pointer to the console input records */
553 static int read_console_input( obj_handle_t handle, int count, int flush )
555 struct console_input *console;
557 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
558 CONSOLE_READ, &console_input_ops )))
559 return -1;
561 if (!count)
563 /* special case: do not retrieve anything, but return
564 * the total number of records available */
565 count = console->recnum;
567 else
569 if (count > console->recnum) count = console->recnum;
570 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
572 if (flush)
574 int i;
575 for (i = count; i < console->recnum; i++)
576 console->records[i-count] = console->records[i];
577 if ((console->recnum -= count) > 0)
579 INPUT_RECORD *new_rec = realloc( console->records,
580 console->recnum * sizeof(INPUT_RECORD) );
581 if (new_rec) console->records = new_rec;
583 else
585 free( console->records );
586 console->records = NULL;
587 reset_event( console->event );
590 release_object( console );
591 return count;
594 /* set misc console input information */
595 static int set_console_input_info( const struct set_console_input_info_request *req,
596 const WCHAR *title, size_t len )
598 struct console_input *console;
599 struct console_renderer_event evt;
601 if (!(console = console_input_get( req->handle, CONSOLE_WRITE ))) goto error;
603 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
605 struct screen_buffer *screen_buffer;
607 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
608 CONSOLE_READ, &screen_buffer_ops );
609 if (!screen_buffer || screen_buffer->input != console)
611 set_error( STATUS_INVALID_PARAMETER );
612 if (screen_buffer) release_object( screen_buffer );
613 goto error;
616 if (screen_buffer != console->active)
618 if (console->active) release_object( console->active );
619 console->active = screen_buffer;
620 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
621 console_input_events_append( console->evt, &evt );
623 else
624 release_object( screen_buffer );
626 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
628 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
629 if (new_title)
631 memcpy( new_title, title, len );
632 new_title[len / sizeof(WCHAR)] = 0;
633 if (console->title) free( console->title );
634 console->title = new_title;
635 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
636 console_input_events_append( console->evt, &evt );
639 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
641 console->history_mode = req->history_mode;
643 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
644 console->history_size != req->history_size)
646 WCHAR** mem = NULL;
647 int i;
648 int delta;
650 if (req->history_size)
652 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
653 if (!mem) goto error;
654 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
657 delta = (console->history_index > req->history_size) ?
658 (console->history_index - req->history_size) : 0;
660 for (i = delta; i < console->history_index; i++)
662 mem[i - delta] = console->history[i];
663 console->history[i] = NULL;
665 console->history_index -= delta;
667 for (i = 0; i < console->history_size; i++)
668 if (console->history[i]) free( console->history[i] );
669 free( console->history );
670 console->history = mem;
671 console->history_size = req->history_size;
673 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
675 console->edition_mode = req->edition_mode;
677 release_object( console );
678 return 1;
679 error:
680 if (console) release_object( console );
681 return 0;
684 /* resize a screen buffer */
685 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
686 int new_width, int new_height )
688 int i, old_width, old_height, copy_width, copy_height;
689 char_info_t *new_data;
691 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
693 set_error( STATUS_NO_MEMORY );
694 return 0;
696 old_width = screen_buffer->width;
697 old_height = screen_buffer->height;
698 copy_width = min( old_width, new_width );
699 copy_height = min( old_height, new_height );
701 /* copy all the rows */
702 for (i = 0; i < copy_height; i++)
704 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
705 copy_width * sizeof(char_info_t) );
708 /* clear the end of each row */
709 if (new_width > old_width)
711 /* fill first row */
712 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
713 /* and blast it to the other rows */
714 for (i = 1; i < copy_height; i++)
715 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
716 (new_width - old_width) * sizeof(char_info_t) );
719 /* clear remaining rows */
720 if (new_height > old_height)
722 /* fill first row */
723 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
724 /* and blast it to the other rows */
725 for (i = old_height+1; i < new_height; i++)
726 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
727 new_width * sizeof(char_info_t) );
729 free( screen_buffer->data );
730 screen_buffer->data = new_data;
731 screen_buffer->width = new_width;
732 screen_buffer->height = new_height;
733 return 1;
736 /* set misc screen buffer information */
737 static int set_console_output_info( struct screen_buffer *screen_buffer,
738 const struct set_console_output_info_request *req )
740 struct console_renderer_event evt;
742 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
744 if (req->cursor_size < 1 || req->cursor_size > 100)
746 set_error( STATUS_INVALID_PARAMETER );
747 return 0;
749 if (screen_buffer->cursor_size != req->cursor_size ||
750 screen_buffer->cursor_visible != req->cursor_visible)
752 screen_buffer->cursor_size = req->cursor_size;
753 screen_buffer->cursor_visible = req->cursor_visible;
754 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
755 evt.u.cursor_geom.size = req->cursor_size;
756 evt.u.cursor_geom.visible = req->cursor_visible;
757 console_input_events_append( screen_buffer->input->evt, &evt );
760 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
762 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
763 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
765 set_error( STATUS_INVALID_PARAMETER );
766 return 0;
768 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
770 screen_buffer->cursor_x = req->cursor_x;
771 screen_buffer->cursor_y = req->cursor_y;
772 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
773 evt.u.cursor_pos.x = req->cursor_x;
774 evt.u.cursor_pos.y = req->cursor_y;
775 console_input_events_append( screen_buffer->input->evt, &evt );
778 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
780 unsigned cc;
782 /* new screen-buffer cannot be smaller than actual window */
783 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
784 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
786 set_error( STATUS_INVALID_PARAMETER );
787 return 0;
789 /* FIXME: there are also some basic minimum and max size to deal with */
790 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
792 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
793 evt.u.resize.width = req->width;
794 evt.u.resize.height = req->height;
795 console_input_events_append( screen_buffer->input->evt, &evt );
797 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
798 evt.u.update.top = 0;
799 evt.u.update.bottom = screen_buffer->height - 1;
800 console_input_events_append( screen_buffer->input->evt, &evt );
802 /* scroll window to display sb */
803 if (screen_buffer->win.right >= req->width)
805 screen_buffer->win.right -= screen_buffer->win.left;
806 screen_buffer->win.left = 0;
808 if (screen_buffer->win.bottom >= req->height)
810 screen_buffer->win.bottom -= screen_buffer->win.top;
811 screen_buffer->win.top = 0;
813 /* reset cursor if needed (normally, if cursor was outside of new sb, the
814 * window has been shifted so that the new position of the cursor will be
815 * visible */
816 cc = 0;
817 if (screen_buffer->cursor_x >= req->width)
819 screen_buffer->cursor_x = req->width - 1;
820 cc++;
822 if (screen_buffer->cursor_y >= req->height)
824 screen_buffer->cursor_y = req->height - 1;
825 cc++;
827 if (cc)
829 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
830 evt.u.cursor_pos.x = req->cursor_x;
831 evt.u.cursor_pos.y = req->cursor_y;
832 console_input_events_append( screen_buffer->input->evt, &evt );
835 if (screen_buffer == screen_buffer->input->active &&
836 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
838 INPUT_RECORD ir;
839 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
840 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
841 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
842 write_console_input( screen_buffer->input, 1, &ir );
845 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
847 screen_buffer->attr = req->attr;
849 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
851 if (req->win_left < 0 || req->win_left > req->win_right ||
852 req->win_right >= screen_buffer->width ||
853 req->win_top < 0 || req->win_top > req->win_bottom ||
854 req->win_bottom >= screen_buffer->height)
856 set_error( STATUS_INVALID_PARAMETER );
857 return 0;
859 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
860 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
862 screen_buffer->win.left = req->win_left;
863 screen_buffer->win.top = req->win_top;
864 screen_buffer->win.right = req->win_right;
865 screen_buffer->win.bottom = req->win_bottom;
866 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
867 evt.u.display.left = req->win_left;
868 evt.u.display.top = req->win_top;
869 evt.u.display.width = req->win_right - req->win_left + 1;
870 evt.u.display.height = req->win_bottom - req->win_top + 1;
871 console_input_events_append( screen_buffer->input->evt, &evt );
874 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
876 /* can only be done by renderer */
877 if (current->process->console != screen_buffer->input)
879 set_error( STATUS_INVALID_PARAMETER );
880 return 0;
883 screen_buffer->max_width = req->max_width;
884 screen_buffer->max_height = req->max_height;
887 return 1;
890 /* appends a new line to history (history is a fixed size array) */
891 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, size_t len )
893 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
895 if (!ptr)
897 set_error( STATUS_NO_MEMORY );
898 return;
900 if (!console || !console->history_size)
902 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
903 return;
906 memcpy( ptr, buf, len * sizeof(WCHAR) );
907 ptr[len] = 0;
909 if (console->history_mode && console->history_index &&
910 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
912 /* ok, mode ask us to not use twice the same string...
913 * so just free mem and returns
915 set_error( STATUS_ALIAS_EXISTS );
916 free(ptr);
917 return;
920 if (console->history_index < console->history_size)
922 console->history[console->history_index++] = ptr;
924 else
926 free( console->history[0]) ;
927 memmove( &console->history[0], &console->history[1],
928 (console->history_size - 1) * sizeof(WCHAR*) );
929 console->history[console->history_size - 1] = ptr;
933 /* returns a line from the cache */
934 static size_t console_input_get_hist( struct console_input *console, int index )
936 size_t ret = 0;
938 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
939 else
941 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
942 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
944 return ret;
947 /* dumb dump */
948 static void console_input_dump( struct object *obj, int verbose )
950 struct console_input *console = (struct console_input *)obj;
951 assert( obj->ops == &console_input_ops );
952 fprintf( stderr, "Console input active=%p evt=%p\n",
953 console->active, console->evt );
956 static void console_input_destroy( struct object *obj )
958 struct console_input* console_in = (struct console_input *)obj;
959 struct screen_buffer* curr;
960 int i;
962 assert( obj->ops == &console_input_ops );
963 if (console_in->title) free( console_in->title );
964 if (console_in->records) free( console_in->records );
966 if (console_in->active) release_object( console_in->active );
967 console_in->active = NULL;
969 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
971 if (curr->input == console_in) curr->input = NULL;
974 release_object( console_in->evt );
975 console_in->evt = NULL;
976 release_object( console_in->event );
978 for (i = 0; i < console_in->history_size; i++)
979 if (console_in->history[i]) free( console_in->history[i] );
980 if (console_in->history) free( console_in->history );
983 static void screen_buffer_dump( struct object *obj, int verbose )
985 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
986 assert( obj->ops == &screen_buffer_ops );
988 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
991 static void screen_buffer_destroy( struct object *obj )
993 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
995 assert( obj->ops == &screen_buffer_ops );
997 list_remove( &screen_buffer->entry );
999 if (screen_buffer->input && screen_buffer->input->active == screen_buffer)
1001 struct screen_buffer *sb;
1003 screen_buffer->input->active = NULL;
1004 LIST_FOR_EACH_ENTRY( sb, &screen_buffer_list, struct screen_buffer, entry )
1006 if (sb->input == screen_buffer->input)
1008 sb->input->active = sb;
1009 break;
1013 if (screen_buffer->data) free( screen_buffer->data );
1016 /* write data into a screen buffer */
1017 static int write_console_output( struct screen_buffer *screen_buffer, size_t size,
1018 const void* data, enum char_info_mode mode,
1019 int x, int y, int wrap )
1021 int i;
1022 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1024 if (y >= screen_buffer->height) return 0;
1026 if (wrap)
1027 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1028 else
1029 end = screen_buffer->data + (y+1) * screen_buffer->width;
1031 switch(mode)
1033 case CHAR_INFO_MODE_TEXT:
1035 const WCHAR *ptr = data;
1036 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1038 break;
1039 case CHAR_INFO_MODE_ATTR:
1041 const unsigned short *ptr = data;
1042 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1044 break;
1045 case CHAR_INFO_MODE_TEXTATTR:
1047 const char_info_t *ptr = data;
1048 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1050 break;
1051 case CHAR_INFO_MODE_TEXTSTDATTR:
1053 const WCHAR *ptr = data;
1054 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1056 dest->ch = ptr[i];
1057 dest->attr = screen_buffer->attr;
1060 break;
1061 default:
1062 set_error( STATUS_INVALID_PARAMETER );
1063 return 0;
1066 if (i && screen_buffer == screen_buffer->input->active)
1068 struct console_renderer_event evt;
1069 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1070 evt.u.update.top = y + x / screen_buffer->width;
1071 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1072 console_input_events_append( screen_buffer->input->evt, &evt );
1074 return i;
1077 /* fill a screen buffer with uniform data */
1078 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1079 enum char_info_mode mode, int x, int y, int count, int wrap )
1081 int i;
1082 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1084 if (y >= screen_buffer->height) return 0;
1086 if (wrap)
1087 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1088 else
1089 end = screen_buffer->data + (y+1) * screen_buffer->width;
1091 if (count > end - dest) count = end - dest;
1093 switch(mode)
1095 case CHAR_INFO_MODE_TEXT:
1096 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1097 break;
1098 case CHAR_INFO_MODE_ATTR:
1099 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1100 break;
1101 case CHAR_INFO_MODE_TEXTATTR:
1102 for (i = 0; i < count; i++) dest[i] = data;
1103 break;
1104 case CHAR_INFO_MODE_TEXTSTDATTR:
1105 for (i = 0; i < count; i++)
1107 dest[i].ch = data.ch;
1108 dest[i].attr = screen_buffer->attr;
1110 break;
1111 default:
1112 set_error( STATUS_INVALID_PARAMETER );
1113 return 0;
1116 if (count && screen_buffer == screen_buffer->input->active)
1118 struct console_renderer_event evt;
1119 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1120 evt.u.update.top = y;
1121 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1122 console_input_events_append( screen_buffer->input->evt, &evt );
1124 return i;
1127 /* read data from a screen buffer */
1128 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1129 enum char_info_mode mode, int wrap )
1131 int i;
1132 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1134 if (y >= screen_buffer->height) return;
1136 if (wrap)
1137 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1138 else
1139 end = screen_buffer->data + (y+1) * screen_buffer->width;
1141 switch(mode)
1143 case CHAR_INFO_MODE_TEXT:
1145 WCHAR *data;
1146 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1147 if ((data = set_reply_data_size( count * sizeof(*data) )))
1149 for (i = 0; i < count; i++) data[i] = src[i].ch;
1152 break;
1153 case CHAR_INFO_MODE_ATTR:
1155 unsigned short *data;
1156 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1157 if ((data = set_reply_data_size( count * sizeof(*data) )))
1159 for (i = 0; i < count; i++) data[i] = src[i].attr;
1162 break;
1163 case CHAR_INFO_MODE_TEXTATTR:
1165 char_info_t *data;
1166 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1167 if ((data = set_reply_data_size( count * sizeof(*data) )))
1169 for (i = 0; i < count; i++) data[i] = src[i];
1172 break;
1173 default:
1174 set_error( STATUS_INVALID_PARAMETER );
1175 break;
1179 /* scroll parts of a screen buffer */
1180 static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst,
1181 int w, int h )
1183 struct screen_buffer *screen_buffer;
1184 int j;
1185 char_info_t *psrc, *pdst;
1186 struct console_renderer_event evt;
1188 if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle,
1189 CONSOLE_READ, &screen_buffer_ops )))
1190 return;
1191 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1192 xsrc + w > screen_buffer->width ||
1193 xdst + w > screen_buffer->width ||
1194 ysrc + h > screen_buffer->height ||
1195 ydst + h > screen_buffer->height ||
1196 w == 0 || h == 0)
1198 set_error( STATUS_INVALID_PARAMETER );
1199 release_object( screen_buffer );
1200 return;
1203 if (ysrc < ydst)
1205 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1206 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1208 for (j = h; j > 0; j--)
1210 memcpy(pdst, psrc, w * sizeof(*pdst) );
1211 pdst -= screen_buffer->width;
1212 psrc -= screen_buffer->width;
1215 else
1217 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1218 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1220 for (j = 0; j < h; j++)
1222 /* we use memmove here because when psrc and pdst are the same,
1223 * copies are done on the same row, so the dst and src blocks
1224 * can overlap */
1225 memmove( pdst, psrc, w * sizeof(*pdst) );
1226 pdst += screen_buffer->width;
1227 psrc += screen_buffer->width;
1231 /* FIXME: this could be enhanced, by signalling scroll */
1232 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1233 evt.u.update.top = min(ysrc, ydst);
1234 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1235 console_input_events_append( screen_buffer->input->evt, &evt );
1237 release_object( screen_buffer );
1240 /* allocate a console for the renderer */
1241 DECL_HANDLER(alloc_console)
1243 obj_handle_t in = 0;
1244 obj_handle_t evt = 0;
1245 struct process *process;
1246 struct process *renderer = current->process;
1247 struct console_input *console;
1249 process = (req->pid) ? get_process_from_id( req->pid ) :
1250 (struct process *)grab_object( renderer->parent );
1252 reply->handle_in = 0;
1253 reply->event = 0;
1254 if (!process) return;
1255 if (process != renderer && process->console)
1257 set_error( STATUS_ACCESS_DENIED );
1258 goto the_end;
1260 if ((console = (struct console_input*)create_console_input( current )))
1262 if ((in = alloc_handle( renderer, console, req->access, req->attributes )))
1264 if ((evt = alloc_handle( renderer, console->evt, SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, 0 )))
1266 if (process != renderer)
1268 process->console = (struct console_input*)grab_object( console );
1269 console->num_proc++;
1271 reply->handle_in = in;
1272 reply->event = evt;
1273 release_object( console );
1274 goto the_end;
1276 close_handle( renderer, in, NULL );
1278 free_console( process );
1280 the_end:
1281 release_object( process );
1284 /* free the console of the current process */
1285 DECL_HANDLER(free_console)
1287 free_console( current->process );
1290 /* let the renderer peek the events it's waiting on */
1291 DECL_HANDLER(get_console_renderer_events)
1293 struct console_input_events *evt;
1295 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1296 CONSOLE_READ, &console_input_events_ops );
1297 if (!evt) return;
1298 console_input_events_get( evt );
1299 release_object( evt );
1302 /* open a handle to the process console */
1303 DECL_HANDLER(open_console)
1305 struct object *obj = NULL;
1307 reply->handle = 0;
1308 switch (req->from)
1310 case 0:
1311 if (current->process->console && current->process->console->renderer)
1312 obj = grab_object( (struct object*)current->process->console );
1313 break;
1314 case 1:
1315 if (current->process->console && current->process->console->renderer &&
1316 current->process->console->active)
1317 obj = grab_object( (struct object*)current->process->console->active );
1318 break;
1319 default:
1320 if ((obj = get_handle_obj( current->process, (obj_handle_t)req->from,
1321 CONSOLE_READ|CONSOLE_WRITE, &console_input_ops )))
1323 struct console_input* console = (struct console_input*)obj;
1324 obj = (console->active) ? grab_object( console->active ) : NULL;
1325 release_object( console );
1327 break;
1330 /* FIXME: req->share is not used (as in screen buffer creation) */
1331 if (obj)
1333 reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
1334 release_object( obj );
1336 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1339 /* set info about a console input */
1340 DECL_HANDLER(set_console_input_info)
1342 set_console_input_info( req, get_req_data(), get_req_data_size() );
1345 /* get info about a console (output only) */
1346 DECL_HANDLER(get_console_input_info)
1348 struct console_input *console;
1350 if (!(console = console_input_get( req->handle, CONSOLE_READ ))) return;
1351 if (console->title)
1353 size_t len = strlenW( console->title ) * sizeof(WCHAR);
1354 if (len > get_reply_max_size()) len = get_reply_max_size();
1355 set_reply_data( console->title, len );
1357 reply->history_mode = console->history_mode;
1358 reply->history_size = console->history_size;
1359 reply->history_index = console->history_index;
1360 reply->edition_mode = console->edition_mode;
1362 release_object( console );
1365 /* get a console mode (input or output) */
1366 DECL_HANDLER(get_console_mode)
1368 reply->mode = get_console_mode( req->handle );
1371 /* set a console mode (input or output) */
1372 DECL_HANDLER(set_console_mode)
1374 set_console_mode( req->handle, req->mode );
1377 /* add input records to a console input queue */
1378 DECL_HANDLER(write_console_input)
1380 struct console_input *console;
1382 reply->written = 0;
1383 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1384 CONSOLE_WRITE, &console_input_ops )))
1385 return;
1386 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1387 get_req_data() );
1388 release_object( console );
1391 /* fetch input records from a console input queue */
1392 DECL_HANDLER(read_console_input)
1394 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1395 reply->read = read_console_input( req->handle, count, req->flush );
1398 /* appends a string to console's history */
1399 DECL_HANDLER(append_console_input_history)
1401 struct console_input *console;
1403 if (!(console = console_input_get( req->handle, CONSOLE_WRITE ))) return;
1404 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1405 release_object( console );
1408 /* appends a string to console's history */
1409 DECL_HANDLER(get_console_input_history)
1411 struct console_input *console;
1413 if (!(console = console_input_get( req->handle, CONSOLE_WRITE ))) return;
1414 reply->total = console_input_get_hist( console, req->index );
1415 release_object( console );
1418 /* creates a screen buffer */
1419 DECL_HANDLER(create_console_output)
1421 struct console_input* console;
1422 struct screen_buffer* screen_buffer;
1424 if (!(console = console_input_get( req->handle_in, CONSOLE_WRITE ))) return;
1426 screen_buffer = create_console_output( console );
1427 if (screen_buffer)
1429 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1430 * see file.c on how this could be done */
1431 reply->handle_out = alloc_handle( current->process, screen_buffer, req->access, req->attributes );
1432 release_object( screen_buffer );
1434 release_object( console );
1437 /* set info about a console screen buffer */
1438 DECL_HANDLER(set_console_output_info)
1440 struct screen_buffer *screen_buffer;
1442 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1443 CONSOLE_WRITE, &screen_buffer_ops)))
1445 set_console_output_info( screen_buffer, req );
1446 release_object( screen_buffer );
1450 /* get info about a console screen buffer */
1451 DECL_HANDLER(get_console_output_info)
1453 struct screen_buffer *screen_buffer;
1455 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1456 CONSOLE_READ, &screen_buffer_ops)))
1458 reply->cursor_size = screen_buffer->cursor_size;
1459 reply->cursor_visible = screen_buffer->cursor_visible;
1460 reply->cursor_x = screen_buffer->cursor_x;
1461 reply->cursor_y = screen_buffer->cursor_y;
1462 reply->width = screen_buffer->width;
1463 reply->height = screen_buffer->height;
1464 reply->attr = screen_buffer->attr;
1465 reply->win_left = screen_buffer->win.left;
1466 reply->win_top = screen_buffer->win.top;
1467 reply->win_right = screen_buffer->win.right;
1468 reply->win_bottom = screen_buffer->win.bottom;
1469 reply->max_width = screen_buffer->max_width;
1470 reply->max_height = screen_buffer->max_height;
1471 release_object( screen_buffer );
1475 /* read data (chars & attrs) from a screen buffer */
1476 DECL_HANDLER(read_console_output)
1478 struct screen_buffer *screen_buffer;
1480 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1481 CONSOLE_READ, &screen_buffer_ops )))
1483 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1484 reply->width = screen_buffer->width;
1485 reply->height = screen_buffer->height;
1486 release_object( screen_buffer );
1490 /* write data (char and/or attrs) to a screen buffer */
1491 DECL_HANDLER(write_console_output)
1493 struct screen_buffer *screen_buffer;
1495 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1496 CONSOLE_WRITE, &screen_buffer_ops)))
1498 reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1499 req->mode, req->x, req->y, req->wrap );
1500 reply->width = screen_buffer->width;
1501 reply->height = screen_buffer->height;
1502 release_object( screen_buffer );
1506 /* fill a screen buffer with constant data (chars and/or attributes) */
1507 DECL_HANDLER(fill_console_output)
1509 struct screen_buffer *screen_buffer;
1511 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1512 CONSOLE_WRITE, &screen_buffer_ops)))
1514 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1515 req->x, req->y, req->count, req->wrap );
1516 release_object( screen_buffer );
1520 /* move a rect of data in a screen buffer */
1521 DECL_HANDLER(move_console_output)
1523 scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst,
1524 req->w, req->h );
1527 /* sends a signal to a console (process, group...) */
1528 DECL_HANDLER(send_console_signal)
1530 process_id_t group;
1532 group = req->group_id ? req->group_id : current->process->group_id;
1534 if (!group)
1535 set_error( STATUS_INVALID_PARAMETER );
1536 else
1537 propagate_console_signal( current->process->console, req->signal, group );
1540 /* get console which renderer is 'current' */
1541 static int cgwe_enum( struct process* process, void* user)
1543 if (process->console && process->console->renderer == current)
1545 *(struct console_input**)user = process->console;
1546 return 1;
1548 return 0;
1551 DECL_HANDLER(get_console_wait_event)
1553 struct console_input* console = NULL;
1555 if (current->process->console && current->process->console->renderer)
1556 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1557 else enum_processes(cgwe_enum, &console);
1559 if (console)
1561 reply->handle = alloc_handle( current->process, console->event, EVENT_ALL_ACCESS, 0 );
1562 release_object( console );
1564 else set_error( STATUS_INVALID_PARAMETER );