2 * Server-side console management
4 * Copyright (C) 1998 Alexandre Julliard
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
33 #define WIN32_NO_STATUS
41 /* specific access rights (FIXME: should use finer-grained access rights) */
42 #define CONSOLE_READ 0x01
43 #define CONSOLE_WRITE 0x02
46 struct console_input_events
;
50 struct object obj
; /* object header */
51 int num_proc
; /* number of processes attached to this console */
52 struct thread
*renderer
; /* console renderer thread */
53 int mode
; /* input mode */
54 struct screen_buffer
*active
; /* active screen buffer */
55 int recnum
; /* number of input records */
56 INPUT_RECORD
*records
; /* input records */
57 struct console_input_events
*evt
; /* synchronization event with renderer */
58 WCHAR
*title
; /* console title */
59 WCHAR
**history
; /* lines history */
60 int history_size
; /* number of entries in history array */
61 int history_index
; /* number of used entries in history array */
62 int history_mode
; /* mode of history (non zero means remove doubled strings */
63 int edition_mode
; /* index to edition mode flavors */
64 int input_cp
; /* console input codepage */
65 int output_cp
; /* console output codepage */
66 user_handle_t win
; /* window handle if backend supports it */
67 struct event
*event
; /* event to wait on for input queue */
70 static unsigned int console_map_access( struct object
*obj
, unsigned int access
);
72 static void console_input_dump( struct object
*obj
, int verbose
);
73 static void console_input_destroy( struct object
*obj
);
75 static const struct object_ops console_input_ops
=
77 sizeof(struct console_input
), /* size */
78 console_input_dump
, /* dump */
79 no_add_queue
, /* add_queue */
80 NULL
, /* remove_queue */
82 no_satisfied
, /* satisfied */
83 no_signal
, /* signal */
84 no_get_fd
, /* get_fd */
85 console_map_access
, /* map_access */
86 no_lookup_name
, /* lookup_name */
87 no_open_file
, /* open_file */
88 no_close_handle
, /* close_handle */
89 console_input_destroy
/* destroy */
92 static void console_input_events_dump( struct object
*obj
, int verbose
);
93 static void console_input_events_destroy( struct object
*obj
);
94 static int console_input_events_signaled( struct object
*obj
, struct thread
*thread
);
96 struct console_input_events
98 struct object obj
; /* object header */
99 int num_alloc
; /* number of allocated events */
100 int num_used
; /* number of actually used events */
101 struct console_renderer_event
* events
;
104 static const struct object_ops console_input_events_ops
=
106 sizeof(struct console_input_events
), /* size */
107 console_input_events_dump
, /* dump */
108 add_queue
, /* add_queue */
109 remove_queue
, /* remove_queue */
110 console_input_events_signaled
, /* signaled */
111 no_satisfied
, /* satisfied */
112 no_signal
, /* signal */
113 no_get_fd
, /* get_fd */
114 console_map_access
, /* map_access */
115 no_lookup_name
, /* lookup_name */
116 no_open_file
, /* open_file */
117 no_close_handle
, /* close_handle */
118 console_input_events_destroy
/* destroy */
123 struct object obj
; /* object header */
124 struct list entry
; /* entry in list of all screen buffers */
125 struct console_input
*input
; /* associated console input */
126 int mode
; /* output mode */
127 int cursor_size
; /* size of cursor (percentage filled) */
128 int cursor_visible
;/* cursor visibility flag */
129 int cursor_x
; /* position of cursor */
130 int cursor_y
; /* position of cursor */
131 int width
; /* size (w-h) of the screen buffer */
133 int max_width
; /* size (w-h) of the window given font size */
135 char_info_t
*data
; /* the data for each cell - a width x height matrix */
136 unsigned short attr
; /* default attribute for screen buffer */
137 rectangle_t win
; /* current visible window on the screen buffer *
138 * as seen in wineconsole */
141 static void screen_buffer_dump( struct object
*obj
, int verbose
);
142 static void screen_buffer_destroy( struct object
*obj
);
144 static const struct object_ops screen_buffer_ops
=
146 sizeof(struct screen_buffer
), /* size */
147 screen_buffer_dump
, /* dump */
148 no_add_queue
, /* add_queue */
149 NULL
, /* remove_queue */
151 NULL
, /* satisfied */
152 no_signal
, /* signal */
153 no_get_fd
, /* get_fd */
154 console_map_access
, /* map_access */
155 no_lookup_name
, /* lookup_name */
156 no_open_file
, /* open_file */
157 no_close_handle
, /* close_handle */
158 screen_buffer_destroy
/* destroy */
161 static struct list screen_buffer_list
= LIST_INIT(screen_buffer_list
);
163 static const char_info_t empty_char_info
= { ' ', 0x000f }; /* white on black space */
165 /* access mapping for all console objects */
166 static unsigned int console_map_access( struct object
*obj
, unsigned int access
)
168 if (access
& GENERIC_READ
) access
|= SYNCHRONIZE
| STANDARD_RIGHTS_READ
| CONSOLE_READ
;
169 if (access
& GENERIC_WRITE
) access
|= SYNCHRONIZE
| STANDARD_RIGHTS_WRITE
| CONSOLE_WRITE
;
170 if (access
& GENERIC_EXECUTE
) access
|= SYNCHRONIZE
| STANDARD_RIGHTS_EXECUTE
;
171 if (access
& GENERIC_ALL
) access
|= STANDARD_RIGHTS_ALL
| CONSOLE_READ
| CONSOLE_WRITE
;
172 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
175 /* dumps the renderer events of a console */
176 static void console_input_events_dump( struct object
*obj
, int verbose
)
178 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
179 assert( obj
->ops
== &console_input_events_ops
);
180 fprintf( stderr
, "Console input events: %d/%d events\n",
181 evts
->num_used
, evts
->num_alloc
);
184 /* destroys the renderer events of a console */
185 static void console_input_events_destroy( struct object
*obj
)
187 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
188 assert( obj
->ops
== &console_input_events_ops
);
189 free( evts
->events
);
192 /* the renderer events list is signaled when it's not empty */
193 static int console_input_events_signaled( struct object
*obj
, struct thread
*thread
)
195 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
196 assert( obj
->ops
== &console_input_events_ops
);
197 return (evts
->num_used
!= 0);
200 /* add an event to the console's renderer events list */
201 static void console_input_events_append( struct console_input_events
* evts
,
202 struct console_renderer_event
* evt
)
204 int collapsed
= FALSE
;
206 /* to be done even when evt has been generated by the rendere ? */
208 /* try to collapse evt into current queue's events */
211 struct console_renderer_event
* last
= &evts
->events
[evts
->num_used
- 1];
213 if (last
->event
== CONSOLE_RENDERER_UPDATE_EVENT
&&
214 evt
->event
== CONSOLE_RENDERER_UPDATE_EVENT
)
216 /* if two update events overlap, collapse them into a single one */
217 if (last
->u
.update
.bottom
+ 1 >= evt
->u
.update
.top
&&
218 evt
->u
.update
.bottom
+ 1 >= last
->u
.update
.top
)
220 last
->u
.update
.top
= min(last
->u
.update
.top
, evt
->u
.update
.top
);
221 last
->u
.update
.bottom
= max(last
->u
.update
.bottom
, evt
->u
.update
.bottom
);
228 if (evts
->num_used
== evts
->num_alloc
)
230 evts
->num_alloc
+= 16;
231 evts
->events
= realloc( evts
->events
, evts
->num_alloc
* sizeof(*evt
) );
232 assert(evts
->events
);
234 evts
->events
[evts
->num_used
++] = *evt
;
236 wake_up( &evts
->obj
, 0 );
239 /* retrieves events from the console's renderer events list */
240 static void console_input_events_get( struct console_input_events
* evts
)
242 data_size_t num
= get_reply_max_size() / sizeof(evts
->events
[0]);
244 if (num
> evts
->num_used
) num
= evts
->num_used
;
245 set_reply_data( evts
->events
, num
* sizeof(evts
->events
[0]) );
246 if (num
< evts
->num_used
)
248 memmove( &evts
->events
[0], &evts
->events
[num
],
249 (evts
->num_used
- num
) * sizeof(evts
->events
[0]) );
251 evts
->num_used
-= num
;
254 static struct console_input_events
*create_console_input_events(void)
256 struct console_input_events
* evt
;
258 if (!(evt
= alloc_object( &console_input_events_ops
))) return NULL
;
259 evt
->num_alloc
= evt
->num_used
= 0;
264 static struct object
*create_console_input( struct thread
* renderer
)
266 struct console_input
*console_input
;
268 if (!(console_input
= alloc_object( &console_input_ops
))) return NULL
;
269 console_input
->renderer
= renderer
;
270 console_input
->mode
= ENABLE_PROCESSED_INPUT
| ENABLE_LINE_INPUT
|
271 ENABLE_ECHO_INPUT
| ENABLE_MOUSE_INPUT
;
272 console_input
->num_proc
= 0;
273 console_input
->active
= NULL
;
274 console_input
->recnum
= 0;
275 console_input
->records
= NULL
;
276 console_input
->evt
= create_console_input_events();
277 console_input
->title
= NULL
;
278 console_input
->history_size
= 50;
279 console_input
->history
= calloc( console_input
->history_size
, sizeof(WCHAR
*) );
280 console_input
->history_index
= 0;
281 console_input
->history_mode
= 0;
282 console_input
->edition_mode
= 0;
283 console_input
->input_cp
= 0;
284 console_input
->output_cp
= 0;
285 console_input
->win
= 0;
286 console_input
->event
= create_event( NULL
, NULL
, 0, 1, 0 );
288 if (!console_input
->history
|| !console_input
->evt
)
290 release_object( console_input
);
293 return &console_input
->obj
;
296 static struct screen_buffer
*create_console_output( struct console_input
*console_input
)
298 struct screen_buffer
*screen_buffer
;
301 if (!(screen_buffer
= alloc_object( &screen_buffer_ops
))) return NULL
;
302 screen_buffer
->mode
= ENABLE_PROCESSED_OUTPUT
| ENABLE_WRAP_AT_EOL_OUTPUT
;
303 screen_buffer
->input
= console_input
;
304 screen_buffer
->cursor_size
= 100;
305 screen_buffer
->cursor_visible
= 1;
306 screen_buffer
->width
= 80;
307 screen_buffer
->height
= 150;
308 screen_buffer
->max_width
= 80;
309 screen_buffer
->max_height
= 25;
310 screen_buffer
->cursor_x
= 0;
311 screen_buffer
->cursor_y
= 0;
312 screen_buffer
->attr
= 0x0F;
313 screen_buffer
->win
.left
= 0;
314 screen_buffer
->win
.right
= screen_buffer
->max_width
- 1;
315 screen_buffer
->win
.top
= 0;
316 screen_buffer
->win
.bottom
= screen_buffer
->max_height
- 1;
318 list_add_head( &screen_buffer_list
, &screen_buffer
->entry
);
320 if (!(screen_buffer
->data
= malloc( screen_buffer
->width
* screen_buffer
->height
*
321 sizeof(*screen_buffer
->data
) )))
323 release_object( screen_buffer
);
326 /* clear the first row */
327 for (i
= 0; i
< screen_buffer
->width
; i
++) screen_buffer
->data
[i
] = empty_char_info
;
328 /* and copy it to all other rows */
329 for (i
= 1; i
< screen_buffer
->height
; i
++)
330 memcpy( &screen_buffer
->data
[i
* screen_buffer
->width
], screen_buffer
->data
,
331 screen_buffer
->width
* sizeof(char_info_t
) );
333 if (!console_input
->active
)
335 struct console_renderer_event evt
;
336 console_input
->active
= (struct screen_buffer
*)grab_object( screen_buffer
);
338 /* generate the initial events */
339 evt
.event
= CONSOLE_RENDERER_ACTIVE_SB_EVENT
;
340 memset(&evt
.u
, 0, sizeof(evt
.u
));
341 console_input_events_append( console_input
->evt
, &evt
);
343 evt
.event
= CONSOLE_RENDERER_SB_RESIZE_EVENT
;
344 evt
.u
.resize
.width
= screen_buffer
->width
;
345 evt
.u
.resize
.height
= screen_buffer
->height
;
346 console_input_events_append( console_input
->evt
, &evt
);
348 evt
.event
= CONSOLE_RENDERER_DISPLAY_EVENT
;
349 evt
.u
.display
.left
= screen_buffer
->win
.left
;
350 evt
.u
.display
.top
= screen_buffer
->win
.top
;
351 evt
.u
.display
.width
= screen_buffer
->win
.right
- screen_buffer
->win
.left
+ 1;
352 evt
.u
.display
.height
= screen_buffer
->win
.bottom
- screen_buffer
->win
.top
+ 1;
353 console_input_events_append( console_input
->evt
, &evt
);
355 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
356 evt
.u
.update
.top
= 0;
357 evt
.u
.update
.bottom
= screen_buffer
->height
- 1;
358 console_input_events_append( console_input
->evt
, &evt
);
360 evt
.event
= CONSOLE_RENDERER_CURSOR_GEOM_EVENT
;
361 evt
.u
.cursor_geom
.size
= screen_buffer
->cursor_size
;
362 evt
.u
.cursor_geom
.visible
= screen_buffer
->cursor_visible
;
363 console_input_events_append( console_input
->evt
, &evt
);
365 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
366 evt
.u
.cursor_pos
.x
= screen_buffer
->cursor_x
;
367 evt
.u
.cursor_pos
.y
= screen_buffer
->cursor_y
;
368 console_input_events_append( console_input
->evt
, &evt
);
370 return screen_buffer
;
373 /* free the console for this process */
374 int free_console( struct process
*process
)
376 struct console_input
* console
= process
->console
;
378 if (!console
|| !console
->renderer
) return 0;
380 process
->console
= NULL
;
381 if (--console
->num_proc
== 0)
383 /* all processes have terminated... tell the renderer to terminate too */
384 struct console_renderer_event evt
;
385 evt
.event
= CONSOLE_RENDERER_EXIT_EVENT
;
386 memset(&evt
.u
, 0, sizeof(evt
.u
));
387 console_input_events_append( console
->evt
, &evt
);
389 release_object( console
);
394 /* let process inherit the console from parent... this handle two cases :
395 * 1/ generic console inheritance
396 * 2/ parent is a renderer which launches process, and process should attach to the console
397 * renderered by parent
399 void inherit_console(struct thread
*parent_thread
, struct process
*process
, obj_handle_t hconin
)
402 struct process
* parent
= parent_thread
->process
;
404 /* if parent is a renderer, then attach current process to its console
409 struct console_input
* console
;
411 /* FIXME: should we check some access rights ? */
412 if ((console
= (struct console_input
*)get_handle_obj( parent
, hconin
,
413 0, &console_input_ops
)))
415 if (console
->renderer
== parent_thread
)
417 process
->console
= (struct console_input
*)grab_object( console
);
418 process
->console
->num_proc
++;
421 release_object( console
);
423 else clear_error(); /* ignore error */
425 /* otherwise, if parent has a console, attach child to this console */
426 if (!done
&& parent
->console
)
428 assert(parent
->console
->renderer
);
429 process
->console
= (struct console_input
*)grab_object( parent
->console
);
430 process
->console
->num_proc
++;
434 struct thread
*console_get_renderer( struct console_input
*console
)
436 return console
->renderer
;
439 static struct console_input
* console_input_get( obj_handle_t handle
, unsigned access
)
441 struct console_input
* console
= NULL
;
444 console
= (struct console_input
*)get_handle_obj( current
->process
, handle
,
445 access
, &console_input_ops
);
446 else if (current
->process
->console
)
448 assert( current
->process
->console
->renderer
);
449 console
= (struct console_input
*)grab_object( current
->process
->console
);
452 if (!console
&& !get_error()) set_error(STATUS_INVALID_PARAMETER
);
456 struct console_signal_info
458 struct console_input
*console
;
463 static int propagate_console_signal_cb(struct process
*process
, void *user
)
465 struct console_signal_info
* csi
= (struct console_signal_info
*)user
;
467 if (process
->console
== csi
->console
&& process
->running_threads
&&
468 (!csi
->group
|| process
->group_id
== csi
->group
))
470 /* find a suitable thread to signal */
471 struct thread
*thread
;
472 LIST_FOR_EACH_ENTRY( thread
, &process
->thread_list
, struct thread
, proc_entry
)
474 if (send_thread_signal( thread
, csi
->signal
)) break;
480 static void propagate_console_signal( struct console_input
*console
,
481 int sig
, process_id_t group_id
)
483 struct console_signal_info csi
;
487 set_error( STATUS_INVALID_PARAMETER
);
490 /* FIXME: should support the other events (like CTRL_BREAK) */
491 if (sig
!= CTRL_C_EVENT
)
493 set_error( STATUS_NOT_IMPLEMENTED
);
496 csi
.console
= console
;
498 csi
.group
= group_id
;
500 enum_processes(propagate_console_signal_cb
, &csi
);
503 static int get_console_mode( obj_handle_t handle
)
508 if ((obj
= get_handle_obj( current
->process
, handle
, CONSOLE_READ
, NULL
)))
510 if (obj
->ops
== &console_input_ops
)
511 ret
= ((struct console_input
*)obj
)->mode
;
512 else if (obj
->ops
== &screen_buffer_ops
)
513 ret
= ((struct screen_buffer
*)obj
)->mode
;
515 set_error( STATUS_OBJECT_TYPE_MISMATCH
);
516 release_object( obj
);
521 /* changes the mode of either a console input or a screen buffer */
522 static int set_console_mode( obj_handle_t handle
, int mode
)
527 if (!(obj
= get_handle_obj( current
->process
, handle
, CONSOLE_WRITE
, NULL
)))
529 if (obj
->ops
== &console_input_ops
)
531 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
532 ((struct console_input
*)obj
)->mode
= mode
;
535 else if (obj
->ops
== &screen_buffer_ops
)
537 ((struct screen_buffer
*)obj
)->mode
= mode
;
540 else set_error( STATUS_OBJECT_TYPE_MISMATCH
);
541 release_object( obj
);
545 /* add input events to a console input queue */
546 static int write_console_input( struct console_input
* console
, int count
,
547 const INPUT_RECORD
*records
)
549 INPUT_RECORD
*new_rec
;
551 if (!count
) return 0;
552 if (!(new_rec
= realloc( console
->records
,
553 (console
->recnum
+ count
) * sizeof(INPUT_RECORD
) )))
555 set_error( STATUS_NO_MEMORY
);
556 release_object( console
);
559 console
->records
= new_rec
;
560 memcpy( new_rec
+ console
->recnum
, records
, count
* sizeof(INPUT_RECORD
) );
562 if (console
->mode
& ENABLE_PROCESSED_INPUT
)
567 if (records
[i
].EventType
== KEY_EVENT
&&
568 records
[i
].Event
.KeyEvent
.uChar
.UnicodeChar
== 'C' - 64 &&
569 !(records
[i
].Event
.KeyEvent
.dwControlKeyState
& ENHANCED_KEY
))
572 memcpy( &console
->records
[console
->recnum
+ i
],
573 &console
->records
[console
->recnum
+ i
+ 1],
574 (count
- i
- 1) * sizeof(INPUT_RECORD
) );
576 if (records
[i
].Event
.KeyEvent
.bKeyDown
)
578 /* send SIGINT to all processes attached to this console */
579 propagate_console_signal( console
, CTRL_C_EVENT
, 0 );
585 if (!console
->recnum
&& count
) set_event( console
->event
);
586 console
->recnum
+= count
;
590 /* retrieve a pointer to the console input records */
591 static int read_console_input( obj_handle_t handle
, int count
, int flush
)
593 struct console_input
*console
;
595 if (!(console
= (struct console_input
*)get_handle_obj( current
->process
, handle
,
596 CONSOLE_READ
, &console_input_ops
)))
601 /* special case: do not retrieve anything, but return
602 * the total number of records available */
603 count
= console
->recnum
;
607 if (count
> console
->recnum
) count
= console
->recnum
;
608 set_reply_data( console
->records
, count
* sizeof(INPUT_RECORD
) );
613 for (i
= count
; i
< console
->recnum
; i
++)
614 console
->records
[i
-count
] = console
->records
[i
];
615 if ((console
->recnum
-= count
) > 0)
617 INPUT_RECORD
*new_rec
= realloc( console
->records
,
618 console
->recnum
* sizeof(INPUT_RECORD
) );
619 if (new_rec
) console
->records
= new_rec
;
623 free( console
->records
);
624 console
->records
= NULL
;
625 reset_event( console
->event
);
628 release_object( console
);
632 /* set misc console input information */
633 static int set_console_input_info( const struct set_console_input_info_request
*req
,
634 const WCHAR
*title
, data_size_t len
)
636 struct console_input
*console
;
637 struct console_renderer_event evt
;
639 if (!(console
= console_input_get( req
->handle
, CONSOLE_WRITE
))) goto error
;
641 memset(&evt
.u
, 0, sizeof(evt
.u
));
642 if (req
->mask
& SET_CONSOLE_INPUT_INFO_ACTIVE_SB
)
644 struct screen_buffer
*screen_buffer
;
646 screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->active_sb
,
647 CONSOLE_WRITE
, &screen_buffer_ops
);
648 if (!screen_buffer
|| screen_buffer
->input
!= console
)
650 set_error( STATUS_INVALID_HANDLE
);
651 if (screen_buffer
) release_object( screen_buffer
);
655 if (screen_buffer
!= console
->active
)
657 if (console
->active
) release_object( console
->active
);
658 console
->active
= screen_buffer
;
659 evt
.event
= CONSOLE_RENDERER_ACTIVE_SB_EVENT
;
660 console_input_events_append( console
->evt
, &evt
);
663 release_object( screen_buffer
);
665 if (req
->mask
& SET_CONSOLE_INPUT_INFO_TITLE
)
667 WCHAR
*new_title
= mem_alloc( len
+ sizeof(WCHAR
) );
670 memcpy( new_title
, title
, len
);
671 new_title
[len
/ sizeof(WCHAR
)] = 0;
672 free( console
->title
);
673 console
->title
= new_title
;
674 evt
.event
= CONSOLE_RENDERER_TITLE_EVENT
;
675 console_input_events_append( console
->evt
, &evt
);
678 if (req
->mask
& SET_CONSOLE_INPUT_INFO_HISTORY_MODE
)
680 console
->history_mode
= req
->history_mode
;
682 if ((req
->mask
& SET_CONSOLE_INPUT_INFO_HISTORY_SIZE
) &&
683 console
->history_size
!= req
->history_size
)
689 if (req
->history_size
)
691 mem
= mem_alloc( req
->history_size
* sizeof(WCHAR
*) );
692 if (!mem
) goto error
;
693 memset( mem
, 0, req
->history_size
* sizeof(WCHAR
*) );
696 delta
= (console
->history_index
> req
->history_size
) ?
697 (console
->history_index
- req
->history_size
) : 0;
699 for (i
= delta
; i
< console
->history_index
; i
++)
701 mem
[i
- delta
] = console
->history
[i
];
702 console
->history
[i
] = NULL
;
704 console
->history_index
-= delta
;
706 for (i
= 0; i
< console
->history_size
; i
++)
707 if (console
->history
[i
]) free( console
->history
[i
] );
708 free( console
->history
);
709 console
->history
= mem
;
710 console
->history_size
= req
->history_size
;
712 if (req
->mask
& SET_CONSOLE_INPUT_INFO_EDITION_MODE
)
714 console
->edition_mode
= req
->edition_mode
;
716 if (req
->mask
& SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE
)
718 console
->input_cp
= req
->input_cp
;
720 if (req
->mask
& SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE
)
722 console
->output_cp
= req
->output_cp
;
724 if (req
->mask
& SET_CONSOLE_INPUT_INFO_WIN
)
726 console
->win
= req
->win
;
728 release_object( console
);
731 if (console
) release_object( console
);
735 /* resize a screen buffer */
736 static int change_screen_buffer_size( struct screen_buffer
*screen_buffer
,
737 int new_width
, int new_height
)
739 int i
, old_width
, old_height
, copy_width
, copy_height
;
740 char_info_t
*new_data
;
742 if (!(new_data
= malloc( new_width
* new_height
* sizeof(*new_data
) )))
744 set_error( STATUS_NO_MEMORY
);
747 old_width
= screen_buffer
->width
;
748 old_height
= screen_buffer
->height
;
749 copy_width
= min( old_width
, new_width
);
750 copy_height
= min( old_height
, new_height
);
752 /* copy all the rows */
753 for (i
= 0; i
< copy_height
; i
++)
755 memcpy( &new_data
[i
* new_width
], &screen_buffer
->data
[i
* old_width
],
756 copy_width
* sizeof(char_info_t
) );
759 /* clear the end of each row */
760 if (new_width
> old_width
)
763 for (i
= old_width
; i
< new_width
; i
++) new_data
[i
] = empty_char_info
;
764 /* and blast it to the other rows */
765 for (i
= 1; i
< copy_height
; i
++)
766 memcpy( &new_data
[i
* new_width
+ old_width
], &new_data
[old_width
],
767 (new_width
- old_width
) * sizeof(char_info_t
) );
770 /* clear remaining rows */
771 if (new_height
> old_height
)
774 for (i
= 0; i
< new_width
; i
++) new_data
[old_height
* new_width
+ i
] = empty_char_info
;
775 /* and blast it to the other rows */
776 for (i
= old_height
+1; i
< new_height
; i
++)
777 memcpy( &new_data
[i
* new_width
], &new_data
[old_height
* new_width
],
778 new_width
* sizeof(char_info_t
) );
780 free( screen_buffer
->data
);
781 screen_buffer
->data
= new_data
;
782 screen_buffer
->width
= new_width
;
783 screen_buffer
->height
= new_height
;
787 /* set misc screen buffer information */
788 static int set_console_output_info( struct screen_buffer
*screen_buffer
,
789 const struct set_console_output_info_request
*req
)
791 struct console_renderer_event evt
;
793 memset(&evt
.u
, 0, sizeof(evt
.u
));
794 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM
)
796 if (req
->cursor_size
< 1 || req
->cursor_size
> 100)
798 set_error( STATUS_INVALID_PARAMETER
);
801 if (screen_buffer
->cursor_size
!= req
->cursor_size
||
802 screen_buffer
->cursor_visible
!= req
->cursor_visible
)
804 screen_buffer
->cursor_size
= req
->cursor_size
;
805 screen_buffer
->cursor_visible
= req
->cursor_visible
;
806 evt
.event
= CONSOLE_RENDERER_CURSOR_GEOM_EVENT
;
807 evt
.u
.cursor_geom
.size
= req
->cursor_size
;
808 evt
.u
.cursor_geom
.visible
= req
->cursor_visible
;
809 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
812 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_CURSOR_POS
)
814 if (req
->cursor_x
< 0 || req
->cursor_x
>= screen_buffer
->width
||
815 req
->cursor_y
< 0 || req
->cursor_y
>= screen_buffer
->height
)
817 set_error( STATUS_INVALID_PARAMETER
);
820 if (screen_buffer
->cursor_x
!= req
->cursor_x
|| screen_buffer
->cursor_y
!= req
->cursor_y
)
822 screen_buffer
->cursor_x
= req
->cursor_x
;
823 screen_buffer
->cursor_y
= req
->cursor_y
;
824 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
825 evt
.u
.cursor_pos
.x
= req
->cursor_x
;
826 evt
.u
.cursor_pos
.y
= req
->cursor_y
;
827 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
830 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_SIZE
)
834 /* new screen-buffer cannot be smaller than actual window */
835 if (req
->width
< screen_buffer
->win
.right
- screen_buffer
->win
.left
+ 1 ||
836 req
->height
< screen_buffer
->win
.bottom
- screen_buffer
->win
.top
+ 1)
838 set_error( STATUS_INVALID_PARAMETER
);
841 /* FIXME: there are also some basic minimum and max size to deal with */
842 if (!change_screen_buffer_size( screen_buffer
, req
->width
, req
->height
)) return 0;
844 evt
.event
= CONSOLE_RENDERER_SB_RESIZE_EVENT
;
845 evt
.u
.resize
.width
= req
->width
;
846 evt
.u
.resize
.height
= req
->height
;
847 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
849 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
850 evt
.u
.update
.top
= 0;
851 evt
.u
.update
.bottom
= screen_buffer
->height
- 1;
852 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
854 /* scroll window to display sb */
855 if (screen_buffer
->win
.right
>= req
->width
)
857 screen_buffer
->win
.right
-= screen_buffer
->win
.left
;
858 screen_buffer
->win
.left
= 0;
860 if (screen_buffer
->win
.bottom
>= req
->height
)
862 screen_buffer
->win
.bottom
-= screen_buffer
->win
.top
;
863 screen_buffer
->win
.top
= 0;
865 /* reset cursor if needed (normally, if cursor was outside of new sb, the
866 * window has been shifted so that the new position of the cursor will be
869 if (screen_buffer
->cursor_x
>= req
->width
)
871 screen_buffer
->cursor_x
= req
->width
- 1;
874 if (screen_buffer
->cursor_y
>= req
->height
)
876 screen_buffer
->cursor_y
= req
->height
- 1;
881 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
882 evt
.u
.cursor_pos
.x
= req
->cursor_x
;
883 evt
.u
.cursor_pos
.y
= req
->cursor_y
;
884 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
887 if (screen_buffer
== screen_buffer
->input
->active
&&
888 screen_buffer
->input
->mode
& ENABLE_WINDOW_INPUT
)
891 ir
.EventType
= WINDOW_BUFFER_SIZE_EVENT
;
892 ir
.Event
.WindowBufferSizeEvent
.dwSize
.X
= req
->width
;
893 ir
.Event
.WindowBufferSizeEvent
.dwSize
.Y
= req
->height
;
894 write_console_input( screen_buffer
->input
, 1, &ir
);
897 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_ATTR
)
899 screen_buffer
->attr
= req
->attr
;
901 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW
)
903 if (req
->win_left
< 0 || req
->win_left
> req
->win_right
||
904 req
->win_right
>= screen_buffer
->width
||
905 req
->win_top
< 0 || req
->win_top
> req
->win_bottom
||
906 req
->win_bottom
>= screen_buffer
->height
)
908 set_error( STATUS_INVALID_PARAMETER
);
911 if (screen_buffer
->win
.left
!= req
->win_left
|| screen_buffer
->win
.top
!= req
->win_top
||
912 screen_buffer
->win
.right
!= req
->win_right
|| screen_buffer
->win
.bottom
!= req
->win_bottom
)
914 screen_buffer
->win
.left
= req
->win_left
;
915 screen_buffer
->win
.top
= req
->win_top
;
916 screen_buffer
->win
.right
= req
->win_right
;
917 screen_buffer
->win
.bottom
= req
->win_bottom
;
918 evt
.event
= CONSOLE_RENDERER_DISPLAY_EVENT
;
919 evt
.u
.display
.left
= req
->win_left
;
920 evt
.u
.display
.top
= req
->win_top
;
921 evt
.u
.display
.width
= req
->win_right
- req
->win_left
+ 1;
922 evt
.u
.display
.height
= req
->win_bottom
- req
->win_top
+ 1;
923 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
926 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_MAX_SIZE
)
928 /* can only be done by renderer */
929 if (current
->process
->console
!= screen_buffer
->input
)
931 set_error( STATUS_INVALID_PARAMETER
);
935 screen_buffer
->max_width
= req
->max_width
;
936 screen_buffer
->max_height
= req
->max_height
;
942 /* appends a new line to history (history is a fixed size array) */
943 static void console_input_append_hist( struct console_input
* console
, const WCHAR
* buf
, data_size_t len
)
945 WCHAR
* ptr
= mem_alloc( (len
+ 1) * sizeof(WCHAR
) );
950 if (!console
|| !console
->history_size
)
952 set_error( STATUS_INVALID_PARAMETER
); /* FIXME */
957 memcpy( ptr
, buf
, len
* sizeof(WCHAR
) );
960 if (console
->history_mode
&& console
->history_index
&&
961 strncmpW( console
->history
[console
->history_index
- 1], ptr
, len
* sizeof(WCHAR
) ) == 0)
963 /* ok, mode ask us to not use twice the same string...
964 * so just free mem and returns
966 set_error( STATUS_ALIAS_EXISTS
);
971 if (console
->history_index
< console
->history_size
)
973 console
->history
[console
->history_index
++] = ptr
;
977 free( console
->history
[0]) ;
978 memmove( &console
->history
[0], &console
->history
[1],
979 (console
->history_size
- 1) * sizeof(WCHAR
*) );
980 console
->history
[console
->history_size
- 1] = ptr
;
984 /* returns a line from the cache */
985 static data_size_t
console_input_get_hist( struct console_input
*console
, int index
)
989 if (index
>= console
->history_index
) set_error( STATUS_INVALID_PARAMETER
);
992 ret
= strlenW( console
->history
[index
] ) * sizeof(WCHAR
);
993 set_reply_data( console
->history
[index
], min( ret
, get_reply_max_size() ));
999 static void console_input_dump( struct object
*obj
, int verbose
)
1001 struct console_input
*console
= (struct console_input
*)obj
;
1002 assert( obj
->ops
== &console_input_ops
);
1003 fprintf( stderr
, "Console input active=%p evt=%p\n",
1004 console
->active
, console
->evt
);
1007 static void console_input_destroy( struct object
*obj
)
1009 struct console_input
* console_in
= (struct console_input
*)obj
;
1010 struct screen_buffer
* curr
;
1013 assert( obj
->ops
== &console_input_ops
);
1014 free( console_in
->title
);
1015 free( console_in
->records
);
1017 if (console_in
->active
) release_object( console_in
->active
);
1018 console_in
->active
= NULL
;
1020 LIST_FOR_EACH_ENTRY( curr
, &screen_buffer_list
, struct screen_buffer
, entry
)
1022 if (curr
->input
== console_in
) curr
->input
= NULL
;
1025 release_object( console_in
->evt
);
1026 console_in
->evt
= NULL
;
1027 release_object( console_in
->event
);
1029 for (i
= 0; i
< console_in
->history_size
; i
++)
1030 if (console_in
->history
[i
]) free( console_in
->history
[i
] );
1031 free( console_in
->history
);
1034 static void screen_buffer_dump( struct object
*obj
, int verbose
)
1036 struct screen_buffer
*screen_buffer
= (struct screen_buffer
*)obj
;
1037 assert( obj
->ops
== &screen_buffer_ops
);
1039 fprintf(stderr
, "Console screen buffer input=%p\n", screen_buffer
->input
);
1042 static void screen_buffer_destroy( struct object
*obj
)
1044 struct screen_buffer
*screen_buffer
= (struct screen_buffer
*)obj
;
1046 assert( obj
->ops
== &screen_buffer_ops
);
1048 list_remove( &screen_buffer
->entry
);
1050 if (screen_buffer
->input
&& screen_buffer
->input
->active
== screen_buffer
)
1052 struct screen_buffer
*sb
;
1054 screen_buffer
->input
->active
= NULL
;
1055 LIST_FOR_EACH_ENTRY( sb
, &screen_buffer_list
, struct screen_buffer
, entry
)
1057 if (sb
->input
== screen_buffer
->input
)
1059 sb
->input
->active
= sb
;
1064 free( screen_buffer
->data
);
1067 /* write data into a screen buffer */
1068 static int write_console_output( struct screen_buffer
*screen_buffer
, data_size_t size
,
1069 const void* data
, enum char_info_mode mode
,
1070 int x
, int y
, int wrap
)
1073 char_info_t
*end
, *dest
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
1075 if (y
>= screen_buffer
->height
) return 0;
1078 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1080 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1084 case CHAR_INFO_MODE_TEXT
:
1086 const WCHAR
*ptr
= data
;
1087 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) dest
->ch
= ptr
[i
];
1090 case CHAR_INFO_MODE_ATTR
:
1092 const unsigned short *ptr
= data
;
1093 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) dest
->attr
= ptr
[i
];
1096 case CHAR_INFO_MODE_TEXTATTR
:
1098 const char_info_t
*ptr
= data
;
1099 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) *dest
= ptr
[i
];
1102 case CHAR_INFO_MODE_TEXTSTDATTR
:
1104 const WCHAR
*ptr
= data
;
1105 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++)
1108 dest
->attr
= screen_buffer
->attr
;
1113 set_error( STATUS_INVALID_PARAMETER
);
1117 if (i
&& screen_buffer
== screen_buffer
->input
->active
)
1119 struct console_renderer_event evt
;
1120 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1121 memset(&evt
.u
, 0, sizeof(evt
.u
));
1122 evt
.u
.update
.top
= y
+ x
/ screen_buffer
->width
;
1123 evt
.u
.update
.bottom
= y
+ (x
+ i
- 1) / screen_buffer
->width
;
1124 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1129 /* fill a screen buffer with uniform data */
1130 static int fill_console_output( struct screen_buffer
*screen_buffer
, char_info_t data
,
1131 enum char_info_mode mode
, int x
, int y
, int count
, int wrap
)
1134 char_info_t
*end
, *dest
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
1136 if (y
>= screen_buffer
->height
) return 0;
1139 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1141 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1143 if (count
> end
- dest
) count
= end
- dest
;
1147 case CHAR_INFO_MODE_TEXT
:
1148 for (i
= 0; i
< count
; i
++) dest
[i
].ch
= data
.ch
;
1150 case CHAR_INFO_MODE_ATTR
:
1151 for (i
= 0; i
< count
; i
++) dest
[i
].attr
= data
.attr
;
1153 case CHAR_INFO_MODE_TEXTATTR
:
1154 for (i
= 0; i
< count
; i
++) dest
[i
] = data
;
1156 case CHAR_INFO_MODE_TEXTSTDATTR
:
1157 for (i
= 0; i
< count
; i
++)
1159 dest
[i
].ch
= data
.ch
;
1160 dest
[i
].attr
= screen_buffer
->attr
;
1164 set_error( STATUS_INVALID_PARAMETER
);
1168 if (count
&& screen_buffer
== screen_buffer
->input
->active
)
1170 struct console_renderer_event evt
;
1171 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1172 memset(&evt
.u
, 0, sizeof(evt
.u
));
1173 evt
.u
.update
.top
= y
;
1174 evt
.u
.update
.bottom
= (y
* screen_buffer
->width
+ x
+ count
- 1) / screen_buffer
->width
;
1175 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1180 /* read data from a screen buffer */
1181 static void read_console_output( struct screen_buffer
*screen_buffer
, int x
, int y
,
1182 enum char_info_mode mode
, int wrap
)
1185 char_info_t
*end
, *src
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
1187 if (y
>= screen_buffer
->height
) return;
1190 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1192 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1196 case CHAR_INFO_MODE_TEXT
:
1199 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1200 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1202 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
].ch
;
1206 case CHAR_INFO_MODE_ATTR
:
1208 unsigned short *data
;
1209 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1210 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1212 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
].attr
;
1216 case CHAR_INFO_MODE_TEXTATTR
:
1219 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1220 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1222 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
];
1227 set_error( STATUS_INVALID_PARAMETER
);
1232 /* scroll parts of a screen buffer */
1233 static void scroll_console_output( obj_handle_t handle
, int xsrc
, int ysrc
, int xdst
, int ydst
,
1236 struct screen_buffer
*screen_buffer
;
1238 char_info_t
*psrc
, *pdst
;
1239 struct console_renderer_event evt
;
1241 if (!(screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, handle
,
1242 CONSOLE_READ
, &screen_buffer_ops
)))
1244 if (xsrc
< 0 || ysrc
< 0 || xdst
< 0 || ydst
< 0 ||
1245 xsrc
+ w
> screen_buffer
->width
||
1246 xdst
+ w
> screen_buffer
->width
||
1247 ysrc
+ h
> screen_buffer
->height
||
1248 ydst
+ h
> screen_buffer
->height
||
1251 set_error( STATUS_INVALID_PARAMETER
);
1252 release_object( screen_buffer
);
1258 psrc
= &screen_buffer
->data
[(ysrc
+ h
- 1) * screen_buffer
->width
+ xsrc
];
1259 pdst
= &screen_buffer
->data
[(ydst
+ h
- 1) * screen_buffer
->width
+ xdst
];
1261 for (j
= h
; j
> 0; j
--)
1263 memcpy(pdst
, psrc
, w
* sizeof(*pdst
) );
1264 pdst
-= screen_buffer
->width
;
1265 psrc
-= screen_buffer
->width
;
1270 psrc
= &screen_buffer
->data
[ysrc
* screen_buffer
->width
+ xsrc
];
1271 pdst
= &screen_buffer
->data
[ydst
* screen_buffer
->width
+ xdst
];
1273 for (j
= 0; j
< h
; j
++)
1275 /* we use memmove here because when psrc and pdst are the same,
1276 * copies are done on the same row, so the dst and src blocks
1278 memmove( pdst
, psrc
, w
* sizeof(*pdst
) );
1279 pdst
+= screen_buffer
->width
;
1280 psrc
+= screen_buffer
->width
;
1284 /* FIXME: this could be enhanced, by signalling scroll */
1285 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1286 memset(&evt
.u
, 0, sizeof(evt
.u
));
1287 evt
.u
.update
.top
= min(ysrc
, ydst
);
1288 evt
.u
.update
.bottom
= max(ysrc
, ydst
) + h
- 1;
1289 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1291 release_object( screen_buffer
);
1294 /* allocate a console for the renderer */
1295 DECL_HANDLER(alloc_console
)
1297 obj_handle_t in
= 0;
1298 obj_handle_t evt
= 0;
1299 struct process
*process
;
1300 struct process
*renderer
= current
->process
;
1301 struct console_input
*console
;
1305 if (!(process
= get_process_from_id( req
->pid
))) return;
1309 if (!(process
= renderer
->parent
))
1311 set_error( STATUS_ACCESS_DENIED
);
1314 grab_object( process
);
1317 if (process
!= renderer
&& process
->console
)
1319 set_error( STATUS_ACCESS_DENIED
);
1322 if ((console
= (struct console_input
*)create_console_input( current
)))
1324 if ((in
= alloc_handle( renderer
, console
, req
->access
, req
->attributes
)))
1326 if ((evt
= alloc_handle( renderer
, console
->evt
, SYNCHRONIZE
|GENERIC_READ
|GENERIC_WRITE
, 0 )))
1328 if (process
!= renderer
)
1330 process
->console
= (struct console_input
*)grab_object( console
);
1331 console
->num_proc
++;
1333 reply
->handle_in
= in
;
1335 release_object( console
);
1338 close_handle( renderer
, in
);
1340 free_console( process
);
1343 release_object( process
);
1346 /* free the console of the current process */
1347 DECL_HANDLER(free_console
)
1349 free_console( current
->process
);
1352 /* let the renderer peek the events it's waiting on */
1353 DECL_HANDLER(get_console_renderer_events
)
1355 struct console_input_events
*evt
;
1357 evt
= (struct console_input_events
*)get_handle_obj( current
->process
, req
->handle
,
1358 CONSOLE_READ
, &console_input_events_ops
);
1360 console_input_events_get( evt
);
1361 release_object( evt
);
1364 /* open a handle to the process console */
1365 DECL_HANDLER(open_console
)
1367 struct object
*obj
= NULL
;
1370 if (req
->from
== (obj_handle_t
)0)
1372 if (current
->process
->console
&& current
->process
->console
->renderer
)
1373 obj
= grab_object( (struct object
*)current
->process
->console
);
1375 else if (req
->from
== (obj_handle_t
)1)
1377 if (current
->process
->console
&& current
->process
->console
->renderer
&&
1378 current
->process
->console
->active
)
1379 obj
= grab_object( (struct object
*)current
->process
->console
->active
);
1381 else if ((obj
= get_handle_obj( current
->process
, req
->from
,
1382 CONSOLE_READ
|CONSOLE_WRITE
, &console_input_ops
)))
1384 struct console_input
*console
= (struct console_input
*)obj
;
1385 obj
= (console
->active
) ? grab_object( console
->active
) : NULL
;
1386 release_object( console
);
1389 /* FIXME: req->share is not used (as in screen buffer creation) */
1392 reply
->handle
= alloc_handle( current
->process
, obj
, req
->access
, req
->attributes
);
1393 release_object( obj
);
1395 else if (!get_error()) set_error( STATUS_ACCESS_DENIED
);
1398 /* set info about a console input */
1399 DECL_HANDLER(set_console_input_info
)
1401 set_console_input_info( req
, get_req_data(), get_req_data_size() );
1404 /* get info about a console (output only) */
1405 DECL_HANDLER(get_console_input_info
)
1407 struct console_input
*console
;
1409 if (!(console
= console_input_get( req
->handle
, CONSOLE_READ
))) return;
1412 data_size_t len
= strlenW( console
->title
) * sizeof(WCHAR
);
1413 if (len
> get_reply_max_size()) len
= get_reply_max_size();
1414 set_reply_data( console
->title
, len
);
1416 reply
->history_mode
= console
->history_mode
;
1417 reply
->history_size
= console
->history_size
;
1418 reply
->history_index
= console
->history_index
;
1419 reply
->edition_mode
= console
->edition_mode
;
1420 reply
->input_cp
= console
->input_cp
;
1421 reply
->output_cp
= console
->output_cp
;
1422 reply
->win
= console
->win
;
1424 release_object( console
);
1427 /* get a console mode (input or output) */
1428 DECL_HANDLER(get_console_mode
)
1430 reply
->mode
= get_console_mode( req
->handle
);
1433 /* set a console mode (input or output) */
1434 DECL_HANDLER(set_console_mode
)
1436 set_console_mode( req
->handle
, req
->mode
);
1439 /* add input records to a console input queue */
1440 DECL_HANDLER(write_console_input
)
1442 struct console_input
*console
;
1445 if (!(console
= (struct console_input
*)get_handle_obj( current
->process
, req
->handle
,
1446 CONSOLE_WRITE
, &console_input_ops
)))
1448 reply
->written
= write_console_input( console
, get_req_data_size() / sizeof(INPUT_RECORD
),
1450 release_object( console
);
1453 /* fetch input records from a console input queue */
1454 DECL_HANDLER(read_console_input
)
1456 int count
= get_reply_max_size() / sizeof(INPUT_RECORD
);
1457 reply
->read
= read_console_input( req
->handle
, count
, req
->flush
);
1460 /* appends a string to console's history */
1461 DECL_HANDLER(append_console_input_history
)
1463 struct console_input
*console
;
1465 if (!(console
= console_input_get( req
->handle
, CONSOLE_WRITE
))) return;
1466 console_input_append_hist( console
, get_req_data(), get_req_data_size() / sizeof(WCHAR
) );
1467 release_object( console
);
1470 /* appends a string to console's history */
1471 DECL_HANDLER(get_console_input_history
)
1473 struct console_input
*console
;
1475 if (!(console
= console_input_get( req
->handle
, CONSOLE_WRITE
))) return;
1476 reply
->total
= console_input_get_hist( console
, req
->index
);
1477 release_object( console
);
1480 /* creates a screen buffer */
1481 DECL_HANDLER(create_console_output
)
1483 struct console_input
* console
;
1484 struct screen_buffer
* screen_buffer
;
1486 if (!(console
= console_input_get( req
->handle_in
, CONSOLE_WRITE
))) return;
1488 screen_buffer
= create_console_output( console
);
1491 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1492 * see file.c on how this could be done */
1493 reply
->handle_out
= alloc_handle( current
->process
, screen_buffer
, req
->access
, req
->attributes
);
1494 release_object( screen_buffer
);
1496 release_object( console
);
1499 /* set info about a console screen buffer */
1500 DECL_HANDLER(set_console_output_info
)
1502 struct screen_buffer
*screen_buffer
;
1504 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1505 CONSOLE_WRITE
, &screen_buffer_ops
)))
1507 set_console_output_info( screen_buffer
, req
);
1508 release_object( screen_buffer
);
1512 /* get info about a console screen buffer */
1513 DECL_HANDLER(get_console_output_info
)
1515 struct screen_buffer
*screen_buffer
;
1517 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1518 CONSOLE_READ
, &screen_buffer_ops
)))
1520 reply
->cursor_size
= screen_buffer
->cursor_size
;
1521 reply
->cursor_visible
= screen_buffer
->cursor_visible
;
1522 reply
->cursor_x
= screen_buffer
->cursor_x
;
1523 reply
->cursor_y
= screen_buffer
->cursor_y
;
1524 reply
->width
= screen_buffer
->width
;
1525 reply
->height
= screen_buffer
->height
;
1526 reply
->attr
= screen_buffer
->attr
;
1527 reply
->win_left
= screen_buffer
->win
.left
;
1528 reply
->win_top
= screen_buffer
->win
.top
;
1529 reply
->win_right
= screen_buffer
->win
.right
;
1530 reply
->win_bottom
= screen_buffer
->win
.bottom
;
1531 reply
->max_width
= screen_buffer
->max_width
;
1532 reply
->max_height
= screen_buffer
->max_height
;
1533 release_object( screen_buffer
);
1537 /* read data (chars & attrs) from a screen buffer */
1538 DECL_HANDLER(read_console_output
)
1540 struct screen_buffer
*screen_buffer
;
1542 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1543 CONSOLE_READ
, &screen_buffer_ops
)))
1545 read_console_output( screen_buffer
, req
->x
, req
->y
, req
->mode
, req
->wrap
);
1546 reply
->width
= screen_buffer
->width
;
1547 reply
->height
= screen_buffer
->height
;
1548 release_object( screen_buffer
);
1552 /* write data (char and/or attrs) to a screen buffer */
1553 DECL_HANDLER(write_console_output
)
1555 struct screen_buffer
*screen_buffer
;
1557 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1558 CONSOLE_WRITE
, &screen_buffer_ops
)))
1560 reply
->written
= write_console_output( screen_buffer
, get_req_data_size(), get_req_data(),
1561 req
->mode
, req
->x
, req
->y
, req
->wrap
);
1562 reply
->width
= screen_buffer
->width
;
1563 reply
->height
= screen_buffer
->height
;
1564 release_object( screen_buffer
);
1568 /* fill a screen buffer with constant data (chars and/or attributes) */
1569 DECL_HANDLER(fill_console_output
)
1571 struct screen_buffer
*screen_buffer
;
1573 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1574 CONSOLE_WRITE
, &screen_buffer_ops
)))
1576 reply
->written
= fill_console_output( screen_buffer
, req
->data
, req
->mode
,
1577 req
->x
, req
->y
, req
->count
, req
->wrap
);
1578 release_object( screen_buffer
);
1582 /* move a rect of data in a screen buffer */
1583 DECL_HANDLER(move_console_output
)
1585 scroll_console_output( req
->handle
, req
->x_src
, req
->y_src
, req
->x_dst
, req
->y_dst
,
1589 /* sends a signal to a console (process, group...) */
1590 DECL_HANDLER(send_console_signal
)
1594 group
= req
->group_id
? req
->group_id
: current
->process
->group_id
;
1597 set_error( STATUS_INVALID_PARAMETER
);
1599 propagate_console_signal( current
->process
->console
, req
->signal
, group
);
1602 /* get console which renderer is 'current' */
1603 static int cgwe_enum( struct process
* process
, void* user
)
1605 if (process
->console
&& process
->console
->renderer
== current
)
1607 *(struct console_input
**)user
= process
->console
;
1613 DECL_HANDLER(get_console_wait_event
)
1615 struct console_input
* console
= NULL
;
1617 if (current
->process
->console
&& current
->process
->console
->renderer
)
1618 console
= (struct console_input
*)grab_object( (struct object
*)current
->process
->console
);
1619 else enum_processes(cgwe_enum
, &console
);
1623 reply
->handle
= alloc_handle( current
->process
, console
->event
, EVENT_ALL_ACCESS
, 0 );
1624 release_object( console
);
1626 else set_error( STATUS_INVALID_PARAMETER
);