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