2 * Win32 console functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1997 Karl Garrison
6 * Copyright 1998 John Richardson
7 * Copyright 1998 Marcus Meissner
8 * Copyright 2001,2002,2004 Eric Pouech
9 * Copyright 2001 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /* Reference applications:
27 * - IDA (interactive disassembler) full version 3.75. Works.
28 * - LYNX/W32. Works mostly, some keys crash it.
32 #include "wine/port.h"
47 #include "wine/winbase16.h"
48 #include "wine/server.h"
49 #include "wine/exception.h"
50 #include "wine/unicode.h"
51 #include "wine/debug.h"
53 #include "console_private.h"
54 #include "kernel_private.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(console
);
59 static UINT console_input_codepage
;
60 static UINT console_output_codepage
;
63 /* map input records to ASCII */
64 static void input_records_WtoA( INPUT_RECORD
*buffer
, int count
)
69 for (i
= 0; i
< count
; i
++)
71 if (buffer
[i
].EventType
!= KEY_EVENT
) continue;
72 WideCharToMultiByte( GetConsoleCP(), 0,
73 &buffer
[i
].Event
.KeyEvent
.uChar
.UnicodeChar
, 1, &ch
, 1, NULL
, NULL
);
74 buffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
= ch
;
78 /* map input records to Unicode */
79 static void input_records_AtoW( INPUT_RECORD
*buffer
, int count
)
84 for (i
= 0; i
< count
; i
++)
86 if (buffer
[i
].EventType
!= KEY_EVENT
) continue;
87 MultiByteToWideChar( GetConsoleCP(), 0,
88 &buffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
, 1, &ch
, 1 );
89 buffer
[i
].Event
.KeyEvent
.uChar
.UnicodeChar
= ch
;
93 /* map char infos to ASCII */
94 static void char_info_WtoA( CHAR_INFO
*buffer
, int count
)
100 WideCharToMultiByte( GetConsoleOutputCP(), 0, &buffer
->Char
.UnicodeChar
, 1,
101 &ch
, 1, NULL
, NULL
);
102 buffer
->Char
.AsciiChar
= ch
;
107 /* map char infos to Unicode */
108 static void char_info_AtoW( CHAR_INFO
*buffer
, int count
)
114 MultiByteToWideChar( GetConsoleOutputCP(), 0, &buffer
->Char
.AsciiChar
, 1, &ch
, 1 );
115 buffer
->Char
.UnicodeChar
= ch
;
121 /******************************************************************************
122 * GetConsoleWindow [KERNEL32.@]
124 HWND WINAPI
GetConsoleWindow(VOID
)
131 /******************************************************************************
132 * GetConsoleCP [KERNEL32.@] Returns the OEM code page for the console
137 UINT WINAPI
GetConsoleCP(VOID
)
139 if (!console_input_codepage
)
141 console_input_codepage
= GetOEMCP();
142 TRACE("%u\n", console_input_codepage
);
144 return console_input_codepage
;
148 /******************************************************************************
149 * SetConsoleCP [KERNEL32.@]
151 BOOL WINAPI
SetConsoleCP(UINT cp
)
153 if (!IsValidCodePage( cp
)) return FALSE
;
154 console_input_codepage
= cp
;
159 /***********************************************************************
160 * GetConsoleOutputCP (KERNEL32.@)
162 UINT WINAPI
GetConsoleOutputCP(VOID
)
164 if (!console_output_codepage
)
166 console_output_codepage
= GetOEMCP();
167 TRACE("%u\n", console_output_codepage
);
169 return console_output_codepage
;
173 /******************************************************************************
174 * SetConsoleOutputCP [KERNEL32.@] Set the output codepage used by the console
177 * cp [I] code page to set
183 BOOL WINAPI
SetConsoleOutputCP(UINT cp
)
185 if (!IsValidCodePage( cp
)) return FALSE
;
186 console_output_codepage
= cp
;
191 /***********************************************************************
194 BOOL WINAPI
Beep( DWORD dwFreq
, DWORD dwDur
)
196 static const char beep
= '\a';
197 /* dwFreq and dwDur are ignored by Win95 */
198 if (isatty(2)) write( 2, &beep
, 1 );
203 /******************************************************************
204 * OpenConsoleW (KERNEL32.@)
207 * Open a handle to the current process console.
208 * Returns INVALID_HANDLE_VALUE on failure.
210 HANDLE WINAPI
OpenConsoleW(LPCWSTR name
, DWORD access
, BOOL inherit
, DWORD creation
)
212 static const WCHAR coninW
[] = {'C','O','N','I','N','$',0};
213 static const WCHAR conoutW
[] = {'C','O','N','O','U','T','$',0};
217 if (strcmpiW(coninW
, name
) == 0)
219 else if (strcmpiW(conoutW
, name
) == 0)
223 SetLastError(ERROR_INVALID_NAME
);
224 return INVALID_HANDLE_VALUE
;
226 if (creation
!= OPEN_EXISTING
)
228 SetLastError(ERROR_INVALID_PARAMETER
);
229 return INVALID_HANDLE_VALUE
;
232 SERVER_START_REQ( open_console
)
235 req
->access
= access
;
236 req
->share
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
237 req
->inherit
= inherit
;
239 wine_server_call_err( req
);
243 return ret
? console_handle_map(ret
) : INVALID_HANDLE_VALUE
;
246 /******************************************************************
247 * VerifyConsoleIoHandle (KERNEL32.@)
251 BOOL WINAPI
VerifyConsoleIoHandle(HANDLE handle
)
255 if (!is_console_handle(handle
)) return FALSE
;
256 SERVER_START_REQ(get_console_mode
)
258 req
->handle
= console_handle_unmap(handle
);
259 ret
= !wine_server_call_err( req
);
265 /******************************************************************
266 * DuplicateConsoleHandle (KERNEL32.@)
270 HANDLE WINAPI
DuplicateConsoleHandle(HANDLE handle
, DWORD access
, BOOL inherit
,
275 if (!is_console_handle(handle
) ||
276 !DuplicateHandle(GetCurrentProcess(), console_handle_unmap(handle
),
277 GetCurrentProcess(), &ret
, access
, inherit
, options
))
278 return INVALID_HANDLE_VALUE
;
279 return console_handle_map(ret
);
282 /******************************************************************
283 * CloseConsoleHandle (KERNEL32.@)
287 BOOL WINAPI
CloseConsoleHandle(HANDLE handle
)
289 if (!is_console_handle(handle
))
291 SetLastError(ERROR_INVALID_PARAMETER
);
294 return CloseHandle(console_handle_unmap(handle
));
297 /******************************************************************
298 * GetConsoleInputWaitHandle (KERNEL32.@)
302 HANDLE WINAPI
GetConsoleInputWaitHandle(void)
304 static HANDLE console_wait_event
;
306 /* FIXME: this is not thread safe */
307 if (!console_wait_event
)
309 SERVER_START_REQ(get_console_wait_event
)
311 if (!wine_server_call_err( req
)) console_wait_event
= reply
->handle
;
315 return console_wait_event
;
319 /******************************************************************************
320 * WriteConsoleInputA [KERNEL32.@]
322 BOOL WINAPI
WriteConsoleInputA( HANDLE handle
, const INPUT_RECORD
*buffer
,
323 DWORD count
, LPDWORD written
)
328 if (!(recW
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(*recW
) ))) return FALSE
;
329 memcpy( recW
, buffer
, count
*sizeof(*recW
) );
330 input_records_AtoW( recW
, count
);
331 ret
= WriteConsoleInputW( handle
, recW
, count
, written
);
332 HeapFree( GetProcessHeap(), 0, recW
);
337 /******************************************************************************
338 * WriteConsoleInputW [KERNEL32.@]
340 BOOL WINAPI
WriteConsoleInputW( HANDLE handle
, const INPUT_RECORD
*buffer
,
341 DWORD count
, LPDWORD written
)
345 TRACE("(%p,%p,%ld,%p)\n", handle
, buffer
, count
, written
);
347 if (written
) *written
= 0;
348 SERVER_START_REQ( write_console_input
)
350 req
->handle
= console_handle_unmap(handle
);
351 wine_server_add_data( req
, buffer
, count
* sizeof(INPUT_RECORD
) );
352 if ((ret
= !wine_server_call_err( req
)) && written
)
353 *written
= reply
->written
;
361 /***********************************************************************
362 * WriteConsoleOutputA (KERNEL32.@)
364 BOOL WINAPI
WriteConsoleOutputA( HANDLE hConsoleOutput
, const CHAR_INFO
*lpBuffer
,
365 COORD size
, COORD coord
, LPSMALL_RECT region
)
369 COORD new_size
, new_coord
;
372 new_size
.X
= min( region
->Right
- region
->Left
+ 1, size
.X
- coord
.X
);
373 new_size
.Y
= min( region
->Bottom
- region
->Top
+ 1, size
.Y
- coord
.Y
);
375 if (new_size
.X
<= 0 || new_size
.Y
<= 0)
377 region
->Bottom
= region
->Top
+ new_size
.Y
- 1;
378 region
->Right
= region
->Left
+ new_size
.X
- 1;
382 /* only copy the useful rectangle */
383 if (!(ciw
= HeapAlloc( GetProcessHeap(), 0, sizeof(CHAR_INFO
) * new_size
.X
* new_size
.Y
)))
385 for (y
= 0; y
< new_size
.Y
; y
++)
387 memcpy( &ciw
[y
* new_size
.X
], &lpBuffer
[(y
+ coord
.Y
) * size
.X
+ coord
.X
],
388 new_size
.X
* sizeof(CHAR_INFO
) );
389 char_info_AtoW( &ciw
[ y
* new_size
.X
], new_size
.X
);
391 new_coord
.X
= new_coord
.Y
= 0;
392 ret
= WriteConsoleOutputW( hConsoleOutput
, ciw
, new_size
, new_coord
, region
);
393 HeapFree( GetProcessHeap(), 0, ciw
);
398 /***********************************************************************
399 * WriteConsoleOutputW (KERNEL32.@)
401 BOOL WINAPI
WriteConsoleOutputW( HANDLE hConsoleOutput
, const CHAR_INFO
*lpBuffer
,
402 COORD size
, COORD coord
, LPSMALL_RECT region
)
404 int width
, height
, y
;
407 TRACE("(%p,%p,(%d,%d),(%d,%d),(%d,%dx%d,%d)\n",
408 hConsoleOutput
, lpBuffer
, size
.X
, size
.Y
, coord
.X
, coord
.Y
,
409 region
->Left
, region
->Top
, region
->Right
, region
->Bottom
);
411 width
= min( region
->Right
- region
->Left
+ 1, size
.X
- coord
.X
);
412 height
= min( region
->Bottom
- region
->Top
+ 1, size
.Y
- coord
.Y
);
414 if (width
> 0 && height
> 0)
416 for (y
= 0; y
< height
; y
++)
418 SERVER_START_REQ( write_console_output
)
420 req
->handle
= console_handle_unmap(hConsoleOutput
);
421 req
->x
= region
->Left
;
422 req
->y
= region
->Top
+ y
;
423 req
->mode
= CHAR_INFO_MODE_TEXTATTR
;
425 wine_server_add_data( req
, &lpBuffer
[(y
+ coord
.Y
) * size
.X
+ coord
.X
],
426 width
* sizeof(CHAR_INFO
));
427 if ((ret
= !wine_server_call_err( req
)))
429 width
= min( width
, reply
->width
- region
->Left
);
430 height
= min( height
, reply
->height
- region
->Top
);
437 region
->Bottom
= region
->Top
+ height
- 1;
438 region
->Right
= region
->Left
+ width
- 1;
443 /******************************************************************************
444 * WriteConsoleOutputCharacterA [KERNEL32.@] Copies character to consecutive
445 * cells in the console screen buffer
448 * hConsoleOutput [I] Handle to screen buffer
449 * str [I] Pointer to buffer with chars to write
450 * length [I] Number of cells to write to
451 * coord [I] Coords of first cell
452 * lpNumCharsWritten [O] Pointer to number of cells written
454 BOOL WINAPI
WriteConsoleOutputCharacterA( HANDLE hConsoleOutput
, LPCSTR str
, DWORD length
,
455 COORD coord
, LPDWORD lpNumCharsWritten
)
461 TRACE("(%p,%s,%ld,%dx%d,%p)\n", hConsoleOutput
,
462 debugstr_an(str
, length
), length
, coord
.X
, coord
.Y
, lpNumCharsWritten
);
464 lenW
= MultiByteToWideChar( GetConsoleOutputCP(), 0, str
, length
, NULL
, 0 );
466 if (lpNumCharsWritten
) *lpNumCharsWritten
= 0;
468 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) ))) return FALSE
;
469 MultiByteToWideChar( GetConsoleOutputCP(), 0, str
, length
, strW
, lenW
);
471 ret
= WriteConsoleOutputCharacterW( hConsoleOutput
, strW
, lenW
, coord
, lpNumCharsWritten
);
472 HeapFree( GetProcessHeap(), 0, strW
);
477 /******************************************************************************
478 * WriteConsoleOutputAttribute [KERNEL32.@] Sets attributes for some cells in
479 * the console screen buffer
482 * hConsoleOutput [I] Handle to screen buffer
483 * attr [I] Pointer to buffer with write attributes
484 * length [I] Number of cells to write to
485 * coord [I] Coords of first cell
486 * lpNumAttrsWritten [O] Pointer to number of cells written
493 BOOL WINAPI
WriteConsoleOutputAttribute( HANDLE hConsoleOutput
, CONST WORD
*attr
, DWORD length
,
494 COORD coord
, LPDWORD lpNumAttrsWritten
)
498 TRACE("(%p,%p,%ld,%dx%d,%p)\n", hConsoleOutput
,attr
,length
,coord
.X
,coord
.Y
,lpNumAttrsWritten
);
500 SERVER_START_REQ( write_console_output
)
502 req
->handle
= console_handle_unmap(hConsoleOutput
);
505 req
->mode
= CHAR_INFO_MODE_ATTR
;
507 wine_server_add_data( req
, attr
, length
* sizeof(WORD
) );
508 if ((ret
= !wine_server_call_err( req
)))
510 if (lpNumAttrsWritten
) *lpNumAttrsWritten
= reply
->written
;
518 /******************************************************************************
519 * FillConsoleOutputCharacterA [KERNEL32.@]
522 * hConsoleOutput [I] Handle to screen buffer
523 * ch [I] Character to write
524 * length [I] Number of cells to write to
525 * coord [I] Coords of first cell
526 * lpNumCharsWritten [O] Pointer to number of cells written
532 BOOL WINAPI
FillConsoleOutputCharacterA( HANDLE hConsoleOutput
, CHAR ch
, DWORD length
,
533 COORD coord
, LPDWORD lpNumCharsWritten
)
537 MultiByteToWideChar( GetConsoleOutputCP(), 0, &ch
, 1, &wch
, 1 );
538 return FillConsoleOutputCharacterW(hConsoleOutput
, wch
, length
, coord
, lpNumCharsWritten
);
542 /******************************************************************************
543 * FillConsoleOutputCharacterW [KERNEL32.@] Writes characters to console
546 * hConsoleOutput [I] Handle to screen buffer
547 * ch [I] Character to write
548 * length [I] Number of cells to write to
549 * coord [I] Coords of first cell
550 * lpNumCharsWritten [O] Pointer to number of cells written
556 BOOL WINAPI
FillConsoleOutputCharacterW( HANDLE hConsoleOutput
, WCHAR ch
, DWORD length
,
557 COORD coord
, LPDWORD lpNumCharsWritten
)
561 TRACE("(%p,%s,%ld,(%dx%d),%p)\n",
562 hConsoleOutput
, debugstr_wn(&ch
, 1), length
, coord
.X
, coord
.Y
, lpNumCharsWritten
);
564 SERVER_START_REQ( fill_console_output
)
566 req
->handle
= console_handle_unmap(hConsoleOutput
);
569 req
->mode
= CHAR_INFO_MODE_TEXT
;
573 if ((ret
= !wine_server_call_err( req
)))
575 if (lpNumCharsWritten
) *lpNumCharsWritten
= reply
->written
;
583 /******************************************************************************
584 * FillConsoleOutputAttribute [KERNEL32.@] Sets attributes for console
587 * hConsoleOutput [I] Handle to screen buffer
588 * attr [I] Color attribute to write
589 * length [I] Number of cells to write to
590 * coord [I] Coords of first cell
591 * lpNumAttrsWritten [O] Pointer to number of cells written
597 BOOL WINAPI
FillConsoleOutputAttribute( HANDLE hConsoleOutput
, WORD attr
, DWORD length
,
598 COORD coord
, LPDWORD lpNumAttrsWritten
)
602 TRACE("(%p,%d,%ld,(%dx%d),%p)\n",
603 hConsoleOutput
, attr
, length
, coord
.X
, coord
.Y
, lpNumAttrsWritten
);
605 SERVER_START_REQ( fill_console_output
)
607 req
->handle
= console_handle_unmap(hConsoleOutput
);
610 req
->mode
= CHAR_INFO_MODE_ATTR
;
612 req
->data
.attr
= attr
;
614 if ((ret
= !wine_server_call_err( req
)))
616 if (lpNumAttrsWritten
) *lpNumAttrsWritten
= reply
->written
;
624 /******************************************************************************
625 * ReadConsoleOutputCharacterA [KERNEL32.@]
628 BOOL WINAPI
ReadConsoleOutputCharacterA(HANDLE hConsoleOutput
, LPSTR lpstr
, DWORD count
,
629 COORD coord
, LPDWORD read_count
)
633 LPWSTR wptr
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
));
635 if (read_count
) *read_count
= 0;
636 if (!wptr
) return FALSE
;
638 if ((ret
= ReadConsoleOutputCharacterW( hConsoleOutput
, wptr
, count
, coord
, &read
)))
640 read
= WideCharToMultiByte( GetConsoleOutputCP(), 0, wptr
, read
, lpstr
, count
, NULL
, NULL
);
641 if (read_count
) *read_count
= read
;
643 HeapFree( GetProcessHeap(), 0, wptr
);
648 /******************************************************************************
649 * ReadConsoleOutputCharacterW [KERNEL32.@]
652 BOOL WINAPI
ReadConsoleOutputCharacterW( HANDLE hConsoleOutput
, LPWSTR buffer
, DWORD count
,
653 COORD coord
, LPDWORD read_count
)
657 TRACE( "(%p,%p,%ld,%dx%d,%p)\n", hConsoleOutput
, buffer
, count
, coord
.X
, coord
.Y
, read_count
);
659 SERVER_START_REQ( read_console_output
)
661 req
->handle
= console_handle_unmap(hConsoleOutput
);
664 req
->mode
= CHAR_INFO_MODE_TEXT
;
666 wine_server_set_reply( req
, buffer
, count
* sizeof(WCHAR
) );
667 if ((ret
= !wine_server_call_err( req
)))
669 if (read_count
) *read_count
= wine_server_reply_size(reply
) / sizeof(WCHAR
);
677 /******************************************************************************
678 * ReadConsoleOutputAttribute [KERNEL32.@]
680 BOOL WINAPI
ReadConsoleOutputAttribute(HANDLE hConsoleOutput
, LPWORD lpAttribute
, DWORD length
,
681 COORD coord
, LPDWORD read_count
)
685 TRACE("(%p,%p,%ld,%dx%d,%p)\n",
686 hConsoleOutput
, lpAttribute
, length
, coord
.X
, coord
.Y
, read_count
);
688 SERVER_START_REQ( read_console_output
)
690 req
->handle
= console_handle_unmap(hConsoleOutput
);
693 req
->mode
= CHAR_INFO_MODE_ATTR
;
695 wine_server_set_reply( req
, lpAttribute
, length
* sizeof(WORD
) );
696 if ((ret
= !wine_server_call_err( req
)))
698 if (read_count
) *read_count
= wine_server_reply_size(reply
) / sizeof(WORD
);
706 /******************************************************************************
707 * ReadConsoleOutputA [KERNEL32.@]
710 BOOL WINAPI
ReadConsoleOutputA( HANDLE hConsoleOutput
, LPCHAR_INFO lpBuffer
, COORD size
,
711 COORD coord
, LPSMALL_RECT region
)
716 ret
= ReadConsoleOutputW( hConsoleOutput
, lpBuffer
, size
, coord
, region
);
717 if (ret
&& region
->Right
>= region
->Left
)
719 for (y
= 0; y
<= region
->Bottom
- region
->Top
; y
++)
721 char_info_WtoA( &lpBuffer
[(coord
.Y
+ y
) * size
.X
+ coord
.X
],
722 region
->Right
- region
->Left
+ 1 );
729 /******************************************************************************
730 * ReadConsoleOutputW [KERNEL32.@]
732 * NOTE: The NT4 (sp5) kernel crashes on me if size is (0,0). I don't
733 * think we need to be *that* compatible. -- AJ
735 BOOL WINAPI
ReadConsoleOutputW( HANDLE hConsoleOutput
, LPCHAR_INFO lpBuffer
, COORD size
,
736 COORD coord
, LPSMALL_RECT region
)
738 int width
, height
, y
;
741 width
= min( region
->Right
- region
->Left
+ 1, size
.X
- coord
.X
);
742 height
= min( region
->Bottom
- region
->Top
+ 1, size
.Y
- coord
.Y
);
744 if (width
> 0 && height
> 0)
746 for (y
= 0; y
< height
; y
++)
748 SERVER_START_REQ( read_console_output
)
750 req
->handle
= console_handle_unmap(hConsoleOutput
);
751 req
->x
= region
->Left
;
752 req
->y
= region
->Top
+ y
;
753 req
->mode
= CHAR_INFO_MODE_TEXTATTR
;
755 wine_server_set_reply( req
, &lpBuffer
[(y
+coord
.Y
) * size
.X
+ coord
.X
],
756 width
* sizeof(CHAR_INFO
) );
757 if ((ret
= !wine_server_call_err( req
)))
759 width
= min( width
, reply
->width
- region
->Left
);
760 height
= min( height
, reply
->height
- region
->Top
);
767 region
->Bottom
= region
->Top
+ height
- 1;
768 region
->Right
= region
->Left
+ width
- 1;
773 /******************************************************************************
774 * ReadConsoleInputA [KERNEL32.@] Reads data from a console
777 * handle [I] Handle to console input buffer
778 * buffer [O] Address of buffer for read data
779 * count [I] Number of records to read
780 * pRead [O] Address of number of records read
786 BOOL WINAPI
ReadConsoleInputA( HANDLE handle
, PINPUT_RECORD buffer
, DWORD count
, LPDWORD pRead
)
790 if (!ReadConsoleInputW( handle
, buffer
, count
, &read
)) return FALSE
;
791 input_records_WtoA( buffer
, read
);
792 if (pRead
) *pRead
= read
;
797 /***********************************************************************
798 * PeekConsoleInputA (KERNEL32.@)
800 * Gets 'count' first events (or less) from input queue.
802 BOOL WINAPI
PeekConsoleInputA( HANDLE handle
, PINPUT_RECORD buffer
, DWORD count
, LPDWORD pRead
)
806 if (!PeekConsoleInputW( handle
, buffer
, count
, &read
)) return FALSE
;
807 input_records_WtoA( buffer
, read
);
808 if (pRead
) *pRead
= read
;
813 /***********************************************************************
814 * PeekConsoleInputW (KERNEL32.@)
816 BOOL WINAPI
PeekConsoleInputW( HANDLE handle
, PINPUT_RECORD buffer
, DWORD count
, LPDWORD read
)
819 SERVER_START_REQ( read_console_input
)
821 req
->handle
= console_handle_unmap(handle
);
823 wine_server_set_reply( req
, buffer
, count
* sizeof(INPUT_RECORD
) );
824 if ((ret
= !wine_server_call_err( req
)))
826 if (read
) *read
= count
? reply
->read
: 0;
834 /***********************************************************************
835 * GetNumberOfConsoleInputEvents (KERNEL32.@)
837 BOOL WINAPI
GetNumberOfConsoleInputEvents( HANDLE handle
, LPDWORD nrofevents
)
840 SERVER_START_REQ( read_console_input
)
842 req
->handle
= console_handle_unmap(handle
);
844 if ((ret
= !wine_server_call_err( req
)))
846 if (nrofevents
) *nrofevents
= reply
->read
;
854 /******************************************************************************
857 * Helper function for ReadConsole, ReadConsoleInput and FlushConsoleInputBuffer
860 * 0 for error, 1 for no INPUT_RECORD ready, 2 with INPUT_RECORD ready
862 enum read_console_input_return
{rci_error
= 0, rci_timeout
= 1, rci_gotone
= 2};
863 static enum read_console_input_return
read_console_input(HANDLE handle
, PINPUT_RECORD ir
, DWORD timeout
)
865 enum read_console_input_return ret
;
867 if (WaitForSingleObject(GetConsoleInputWaitHandle(), timeout
) != WAIT_OBJECT_0
)
869 SERVER_START_REQ( read_console_input
)
871 req
->handle
= console_handle_unmap(handle
);
873 wine_server_set_reply( req
, ir
, sizeof(INPUT_RECORD
) );
874 if (wine_server_call_err( req
) || !reply
->read
) ret
= rci_error
;
875 else ret
= rci_gotone
;
883 /***********************************************************************
884 * FlushConsoleInputBuffer (KERNEL32.@)
886 BOOL WINAPI
FlushConsoleInputBuffer( HANDLE handle
)
888 enum read_console_input_return last
;
891 while ((last
= read_console_input(handle
, &ir
, 0)) == rci_gotone
);
893 return last
== rci_timeout
;
897 /***********************************************************************
898 * SetConsoleTitleA (KERNEL32.@)
900 BOOL WINAPI
SetConsoleTitleA( LPCSTR title
)
905 DWORD len
= MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, NULL
, 0 );
906 if (!(titleW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
)))) return FALSE
;
907 MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, titleW
, len
);
908 ret
= SetConsoleTitleW(titleW
);
909 HeapFree(GetProcessHeap(), 0, titleW
);
914 /***********************************************************************
915 * GetConsoleTitleA (KERNEL32.@)
917 DWORD WINAPI
GetConsoleTitleA(LPSTR title
, DWORD size
)
919 WCHAR
*ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * size
);
923 ret
= GetConsoleTitleW( ptr
, size
);
926 WideCharToMultiByte( GetConsoleOutputCP(), 0, ptr
, ret
+ 1, title
, size
, NULL
, NULL
);
929 HeapFree(GetProcessHeap(), 0, ptr
);
934 /******************************************************************************
935 * GetConsoleTitleW [KERNEL32.@] Retrieves title string for console
938 * title [O] Address of buffer for title
939 * size [I] Size of buffer
942 * Success: Length of string copied
945 DWORD WINAPI
GetConsoleTitleW(LPWSTR title
, DWORD size
)
949 SERVER_START_REQ( get_console_input_info
)
952 wine_server_set_reply( req
, title
, (size
-1) * sizeof(WCHAR
) );
953 if (!wine_server_call_err( req
))
955 ret
= wine_server_reply_size(reply
) / sizeof(WCHAR
);
964 /***********************************************************************
965 * GetLargestConsoleWindowSize (KERNEL32.@)
968 * This should return a COORD, but calling convention for returning
969 * structures is different between Windows and gcc on i386.
974 #undef GetLargestConsoleWindowSize
975 DWORD WINAPI
GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
983 TRACE("(%p), returning %dx%d (%lx)\n", hConsoleOutput
, x
.c
.X
, x
.c
.Y
, x
.w
);
986 #endif /* defined(__i386__) */
989 /***********************************************************************
990 * GetLargestConsoleWindowSize (KERNEL32.@)
993 * This should return a COORD, but calling convention for returning
994 * structures is different between Windows and gcc on i386.
999 COORD WINAPI
GetLargestConsoleWindowSize(HANDLE hConsoleOutput
)
1004 TRACE("(%p), returning %dx%d\n", hConsoleOutput
, c
.X
, c
.Y
);
1007 #endif /* defined(__i386__) */
1009 static WCHAR
* S_EditString
/* = NULL */;
1010 static unsigned S_EditStrPos
/* = 0 */;
1012 /***********************************************************************
1013 * FreeConsole (KERNEL32.@)
1015 BOOL WINAPI
FreeConsole(VOID
)
1019 SERVER_START_REQ(free_console
)
1021 ret
= !wine_server_call_err( req
);
1027 /******************************************************************
1028 * start_console_renderer
1030 * helper for AllocConsole
1031 * starts the renderer process
1033 static BOOL
start_console_renderer_helper(const char* appname
, STARTUPINFOA
* si
,
1038 PROCESS_INFORMATION pi
;
1040 /* FIXME: use dynamic allocation for most of the buffers below */
1041 ret
= snprintf(buffer
, sizeof(buffer
), "%s --use-event=%d", appname
, (INT
)hEvent
);
1042 if ((ret
> -1) && (ret
< sizeof(buffer
)) &&
1043 CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
,
1044 NULL
, NULL
, si
, &pi
))
1046 if (WaitForSingleObject(hEvent
, INFINITE
) != WAIT_OBJECT_0
) return FALSE
;
1048 TRACE("Started wineconsole pid=%08lx tid=%08lx\n",
1049 pi
.dwProcessId
, pi
.dwThreadId
);
1056 static BOOL
start_console_renderer(STARTUPINFOA
* si
)
1060 OBJECT_ATTRIBUTES attr
;
1063 attr
.Length
= sizeof(attr
);
1064 attr
.RootDirectory
= 0;
1065 attr
.Attributes
= OBJ_INHERIT
;
1066 attr
.ObjectName
= NULL
;
1067 attr
.SecurityDescriptor
= NULL
;
1068 attr
.SecurityQualityOfService
= NULL
;
1070 NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, &attr
, TRUE
, FALSE
);
1071 if (!hEvent
) return FALSE
;
1073 /* first try environment variable */
1074 if ((p
= getenv("WINECONSOLE")) != NULL
)
1076 ret
= start_console_renderer_helper(p
, si
, hEvent
);
1078 ERR("Couldn't launch Wine console from WINECONSOLE env var (%s)... "
1079 "trying default access\n", p
);
1082 /* then try the regular PATH */
1084 ret
= start_console_renderer_helper("wineconsole", si
, hEvent
);
1086 CloseHandle(hEvent
);
1090 /***********************************************************************
1091 * AllocConsole (KERNEL32.@)
1093 * creates an xterm with a pty to our program
1095 BOOL WINAPI
AllocConsole(void)
1097 HANDLE handle_in
= INVALID_HANDLE_VALUE
;
1098 HANDLE handle_out
= INVALID_HANDLE_VALUE
;
1099 HANDLE handle_err
= INVALID_HANDLE_VALUE
;
1100 STARTUPINFOA siCurrent
;
1101 STARTUPINFOA siConsole
;
1103 SECURITY_ATTRIBUTES sa
;
1107 handle_in
= CreateFileA( "CONIN$", GENERIC_READ
|GENERIC_WRITE
|SYNCHRONIZE
,
1108 0, NULL
, OPEN_EXISTING
, 0, 0 );
1110 if (handle_in
!= INVALID_HANDLE_VALUE
)
1112 /* we already have a console opened on this process, don't create a new one */
1113 CloseHandle(handle_in
);
1117 GetStartupInfoA(&siCurrent
);
1119 memset(&siConsole
, 0, sizeof(siConsole
));
1120 siConsole
.cb
= sizeof(siConsole
);
1121 /* setup a view arguments for wineconsole (it'll use them as default values) */
1122 if (siCurrent
.dwFlags
& STARTF_USECOUNTCHARS
)
1124 siConsole
.dwFlags
|= STARTF_USECOUNTCHARS
;
1125 siConsole
.dwXCountChars
= siCurrent
.dwXCountChars
;
1126 siConsole
.dwYCountChars
= siCurrent
.dwYCountChars
;
1128 if (siCurrent
.dwFlags
& STARTF_USEFILLATTRIBUTE
)
1130 siConsole
.dwFlags
|= STARTF_USEFILLATTRIBUTE
;
1131 siConsole
.dwFillAttribute
= siCurrent
.dwFillAttribute
;
1133 if (siCurrent
.dwFlags
& STARTF_USESHOWWINDOW
)
1135 siConsole
.dwFlags
|= STARTF_USESHOWWINDOW
;
1136 siConsole
.wShowWindow
= siCurrent
.wShowWindow
;
1138 /* FIXME (should pass the unicode form) */
1139 if (siCurrent
.lpTitle
)
1140 siConsole
.lpTitle
= siCurrent
.lpTitle
;
1141 else if (GetModuleFileNameA(0, buffer
, sizeof(buffer
)))
1143 buffer
[sizeof(buffer
) - 1] = '\0';
1144 siConsole
.lpTitle
= buffer
;
1147 if (!start_console_renderer(&siConsole
))
1150 if( !(siCurrent
.dwFlags
& STARTF_USESTDHANDLES
) ) {
1151 /* all std I/O handles are inheritable by default */
1152 sa
.nLength
= sizeof(sa
);
1153 sa
.lpSecurityDescriptor
= NULL
;
1154 sa
.bInheritHandle
= TRUE
;
1156 handle_in
= CreateFileA( "CONIN$", GENERIC_READ
|GENERIC_WRITE
|SYNCHRONIZE
,
1157 0, &sa
, OPEN_EXISTING
, 0, 0 );
1158 if (handle_in
== INVALID_HANDLE_VALUE
) goto the_end
;
1160 handle_out
= CreateFileA( "CONOUT$", GENERIC_READ
|GENERIC_WRITE
,
1161 0, &sa
, OPEN_EXISTING
, 0, 0 );
1162 if (handle_out
== INVALID_HANDLE_VALUE
) goto the_end
;
1164 if (!DuplicateHandle(GetCurrentProcess(), handle_out
, GetCurrentProcess(),
1165 &handle_err
, 0, TRUE
, DUPLICATE_SAME_ACCESS
))
1168 /* STARTF_USESTDHANDLES flag: use handles from StartupInfo */
1169 handle_in
= siCurrent
.hStdInput
;
1170 handle_out
= siCurrent
.hStdOutput
;
1171 handle_err
= siCurrent
.hStdError
;
1174 /* NT resets the STD_*_HANDLEs on console alloc */
1175 SetStdHandle(STD_INPUT_HANDLE
, handle_in
);
1176 SetStdHandle(STD_OUTPUT_HANDLE
, handle_out
);
1177 SetStdHandle(STD_ERROR_HANDLE
, handle_err
);
1179 SetLastError(ERROR_SUCCESS
);
1184 ERR("Can't allocate console\n");
1185 if (handle_in
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_in
);
1186 if (handle_out
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_out
);
1187 if (handle_err
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_err
);
1193 /***********************************************************************
1194 * ReadConsoleA (KERNEL32.@)
1196 BOOL WINAPI
ReadConsoleA(HANDLE hConsoleInput
, LPVOID lpBuffer
, DWORD nNumberOfCharsToRead
,
1197 LPDWORD lpNumberOfCharsRead
, LPVOID lpReserved
)
1199 LPWSTR ptr
= HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead
* sizeof(WCHAR
));
1203 if ((ret
= ReadConsoleW(hConsoleInput
, ptr
, nNumberOfCharsToRead
, &ncr
, NULL
)))
1204 ncr
= WideCharToMultiByte(CP_ACP
, 0, ptr
, ncr
, lpBuffer
, nNumberOfCharsToRead
, NULL
, NULL
);
1206 if (lpNumberOfCharsRead
) *lpNumberOfCharsRead
= ncr
;
1207 HeapFree(GetProcessHeap(), 0, ptr
);
1212 /***********************************************************************
1213 * ReadConsoleW (KERNEL32.@)
1215 BOOL WINAPI
ReadConsoleW(HANDLE hConsoleInput
, LPVOID lpBuffer
,
1216 DWORD nNumberOfCharsToRead
, LPDWORD lpNumberOfCharsRead
, LPVOID lpReserved
)
1219 LPWSTR xbuf
= (LPWSTR
)lpBuffer
;
1222 TRACE("(%p,%p,%ld,%p,%p)\n",
1223 hConsoleInput
, lpBuffer
, nNumberOfCharsToRead
, lpNumberOfCharsRead
, lpReserved
);
1225 if (!GetConsoleMode(hConsoleInput
, &mode
))
1228 if (mode
& ENABLE_LINE_INPUT
)
1230 if (!S_EditString
|| S_EditString
[S_EditStrPos
] == 0)
1232 HeapFree(GetProcessHeap(), 0, S_EditString
);
1233 if (!(S_EditString
= CONSOLE_Readline(hConsoleInput
)))
1237 charsread
= lstrlenW(&S_EditString
[S_EditStrPos
]);
1238 if (charsread
> nNumberOfCharsToRead
) charsread
= nNumberOfCharsToRead
;
1239 memcpy(xbuf
, &S_EditString
[S_EditStrPos
], charsread
* sizeof(WCHAR
));
1240 S_EditStrPos
+= charsread
;
1245 DWORD timeout
= INFINITE
;
1247 /* FIXME: should we read at least 1 char? The SDK does not say */
1248 /* wait for at least one available input record (it doesn't mean we'll have
1249 * chars stored in xbuf...)
1254 if (read_console_input(hConsoleInput
, &ir
, timeout
) != rci_gotone
) break;
1256 if (ir
.EventType
== KEY_EVENT
&& ir
.Event
.KeyEvent
.bKeyDown
&&
1257 ir
.Event
.KeyEvent
.uChar
.UnicodeChar
&&
1258 !(ir
.Event
.KeyEvent
.dwControlKeyState
& ENHANCED_KEY
))
1260 xbuf
[charsread
++] = ir
.Event
.KeyEvent
.uChar
.UnicodeChar
;
1262 } while (charsread
< nNumberOfCharsToRead
);
1263 /* nothing has been read */
1264 if (timeout
== INFINITE
) return FALSE
;
1267 if (lpNumberOfCharsRead
) *lpNumberOfCharsRead
= charsread
;
1273 /***********************************************************************
1274 * ReadConsoleInputW (KERNEL32.@)
1276 BOOL WINAPI
ReadConsoleInputW(HANDLE hConsoleInput
, PINPUT_RECORD lpBuffer
,
1277 DWORD nLength
, LPDWORD lpNumberOfEventsRead
)
1280 DWORD timeout
= INFINITE
;
1284 if (lpNumberOfEventsRead
) *lpNumberOfEventsRead
= 0;
1288 /* loop until we get at least one event */
1289 while (read_console_input(hConsoleInput
, &lpBuffer
[idx
], timeout
) == rci_gotone
&&
1293 if (lpNumberOfEventsRead
) *lpNumberOfEventsRead
= idx
;
1298 /******************************************************************************
1299 * WriteConsoleOutputCharacterW [KERNEL32.@] Copies character to consecutive
1300 * cells in the console screen buffer
1303 * hConsoleOutput [I] Handle to screen buffer
1304 * str [I] Pointer to buffer with chars to write
1305 * length [I] Number of cells to write to
1306 * coord [I] Coords of first cell
1307 * lpNumCharsWritten [O] Pointer to number of cells written
1314 BOOL WINAPI
WriteConsoleOutputCharacterW( HANDLE hConsoleOutput
, LPCWSTR str
, DWORD length
,
1315 COORD coord
, LPDWORD lpNumCharsWritten
)
1319 TRACE("(%p,%s,%ld,%dx%d,%p)\n", hConsoleOutput
,
1320 debugstr_wn(str
, length
), length
, coord
.X
, coord
.Y
, lpNumCharsWritten
);
1322 SERVER_START_REQ( write_console_output
)
1324 req
->handle
= console_handle_unmap(hConsoleOutput
);
1327 req
->mode
= CHAR_INFO_MODE_TEXT
;
1329 wine_server_add_data( req
, str
, length
* sizeof(WCHAR
) );
1330 if ((ret
= !wine_server_call_err( req
)))
1332 if (lpNumCharsWritten
) *lpNumCharsWritten
= reply
->written
;
1340 /******************************************************************************
1341 * SetConsoleTitleW [KERNEL32.@] Sets title bar string for console
1344 * title [I] Address of new title
1350 BOOL WINAPI
SetConsoleTitleW(LPCWSTR title
)
1354 TRACE("(%s)\n", debugstr_w(title
));
1355 SERVER_START_REQ( set_console_input_info
)
1358 req
->mask
= SET_CONSOLE_INPUT_INFO_TITLE
;
1359 wine_server_add_data( req
, title
, strlenW(title
) * sizeof(WCHAR
) );
1360 ret
= !wine_server_call_err( req
);
1367 /***********************************************************************
1368 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
1370 BOOL WINAPI
GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons
)
1372 FIXME("(%p): stub\n", nrofbuttons
);
1377 /******************************************************************************
1378 * SetConsoleInputExeNameW [KERNEL32.@]
1383 BOOL WINAPI
SetConsoleInputExeNameW(LPCWSTR name
)
1385 FIXME("(%s): stub!\n", debugstr_w(name
));
1387 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1391 /******************************************************************************
1392 * SetConsoleInputExeNameA [KERNEL32.@]
1397 BOOL WINAPI
SetConsoleInputExeNameA(LPCSTR name
)
1399 int len
= MultiByteToWideChar(CP_ACP
, 0, name
, -1, NULL
, 0);
1400 LPWSTR xptr
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1403 if (!xptr
) return FALSE
;
1405 MultiByteToWideChar(CP_ACP
, 0, name
, -1, xptr
, len
);
1406 ret
= SetConsoleInputExeNameW(xptr
);
1407 HeapFree(GetProcessHeap(), 0, xptr
);
1412 /******************************************************************
1413 * CONSOLE_DefaultHandler
1415 * Final control event handler
1417 static BOOL WINAPI
CONSOLE_DefaultHandler(DWORD dwCtrlType
)
1419 FIXME("Terminating process %lx on event %lx\n", GetCurrentProcessId(), dwCtrlType
);
1421 /* should never go here */
1425 /******************************************************************************
1426 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
1429 * func [I] Address of handler function
1430 * add [I] Handler to add or remove
1437 struct ConsoleHandler
1439 PHANDLER_ROUTINE handler
;
1440 struct ConsoleHandler
* next
;
1443 static struct ConsoleHandler CONSOLE_DefaultConsoleHandler
= {CONSOLE_DefaultHandler
, NULL
};
1444 static struct ConsoleHandler
* CONSOLE_Handlers
= &CONSOLE_DefaultConsoleHandler
;
1446 static CRITICAL_SECTION CONSOLE_CritSect
;
1447 static CRITICAL_SECTION_DEBUG critsect_debug
=
1449 0, 0, &CONSOLE_CritSect
,
1450 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1451 0, 0, { 0, (DWORD
)(__FILE__
": CONSOLE_CritSect") }
1453 static CRITICAL_SECTION CONSOLE_CritSect
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1455 /*****************************************************************************/
1457 /******************************************************************
1458 * SetConsoleCtrlHandler (KERNEL32.@)
1460 BOOL WINAPI
SetConsoleCtrlHandler(PHANDLER_ROUTINE func
, BOOL add
)
1464 TRACE("(%p,%i)\n", func
, add
);
1468 RtlEnterCriticalSection(&CONSOLE_CritSect
);
1470 NtCurrentTeb()->Peb
->ProcessParameters
->ConsoleFlags
|= 1;
1472 NtCurrentTeb()->Peb
->ProcessParameters
->ConsoleFlags
&= ~1;
1473 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
1477 struct ConsoleHandler
* ch
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct ConsoleHandler
));
1479 if (!ch
) return FALSE
;
1481 RtlEnterCriticalSection(&CONSOLE_CritSect
);
1482 ch
->next
= CONSOLE_Handlers
;
1483 CONSOLE_Handlers
= ch
;
1484 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
1488 struct ConsoleHandler
** ch
;
1489 RtlEnterCriticalSection(&CONSOLE_CritSect
);
1490 for (ch
= &CONSOLE_Handlers
; *ch
; ch
= &(*ch
)->next
)
1492 if ((*ch
)->handler
== func
) break;
1496 struct ConsoleHandler
* rch
= *ch
;
1499 if (rch
== &CONSOLE_DefaultConsoleHandler
)
1501 ERR("Who's trying to remove default handler???\n");
1502 SetLastError(ERROR_INVALID_PARAMETER
);
1508 HeapFree(GetProcessHeap(), 0, rch
);
1513 WARN("Attempt to remove non-installed CtrlHandler %p\n", func
);
1514 SetLastError(ERROR_INVALID_PARAMETER
);
1517 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
1522 static WINE_EXCEPTION_FILTER(CONSOLE_CtrlEventHandler
)
1524 TRACE("(%lx)\n", GetExceptionCode());
1525 return EXCEPTION_EXECUTE_HANDLER
;
1528 /******************************************************************
1529 * CONSOLE_SendEventThread
1531 * Internal helper to pass an event to the list on installed handlers
1533 static DWORD WINAPI
CONSOLE_SendEventThread(void* pmt
)
1535 DWORD event
= (DWORD
)pmt
;
1536 struct ConsoleHandler
* ch
;
1538 if (event
== CTRL_C_EVENT
)
1540 BOOL caught_by_dbg
= TRUE
;
1541 /* First, try to pass the ctrl-C event to the debugger (if any)
1542 * If it continues, there's nothing more to do
1543 * Otherwise, we need to send the ctrl-C event to the handlers
1547 RaiseException( DBG_CONTROL_C
, 0, 0, NULL
);
1549 __EXCEPT(CONSOLE_CtrlEventHandler
)
1551 caught_by_dbg
= FALSE
;
1554 if (caught_by_dbg
) return 0;
1555 /* the debugger didn't continue... so, pass to ctrl handlers */
1557 RtlEnterCriticalSection(&CONSOLE_CritSect
);
1558 for (ch
= CONSOLE_Handlers
; ch
; ch
= ch
->next
)
1560 if (ch
->handler(event
)) break;
1562 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
1566 /******************************************************************
1567 * CONSOLE_HandleCtrlC
1569 * Check whether the shall manipulate CtrlC events
1571 int CONSOLE_HandleCtrlC(unsigned sig
)
1573 /* FIXME: better test whether a console is attached to this process ??? */
1574 extern unsigned CONSOLE_GetNumHistoryEntries(void);
1575 if (CONSOLE_GetNumHistoryEntries() == (unsigned)-1) return 0;
1577 /* check if we have to ignore ctrl-C events */
1578 if (!(NtCurrentTeb()->Peb
->ProcessParameters
->ConsoleFlags
& 1))
1580 /* Create a separate thread to signal all the events.
1581 * This is needed because:
1582 * - this function can be called in an Unix signal handler (hence on an
1583 * different stack than the thread that's running). This breaks the
1584 * Win32 exception mechanisms (where the thread's stack is checked).
1585 * - since the current thread, while processing the signal, can hold the
1586 * console critical section, we need another execution environment where
1587 * we can wait on this critical section
1589 CreateThread(NULL
, 0, CONSOLE_SendEventThread
, (void*)CTRL_C_EVENT
, 0, NULL
);
1594 /******************************************************************************
1595 * GenerateConsoleCtrlEvent [KERNEL32.@] Simulate a CTRL-C or CTRL-BREAK
1598 * dwCtrlEvent [I] Type of event
1599 * dwProcessGroupID [I] Process group ID to send event to
1603 * Failure: False (and *should* [but doesn't] set LastError)
1605 BOOL WINAPI
GenerateConsoleCtrlEvent(DWORD dwCtrlEvent
,
1606 DWORD dwProcessGroupID
)
1610 TRACE("(%ld, %ld)\n", dwCtrlEvent
, dwProcessGroupID
);
1612 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
1614 ERR("Invalid event %ld for PGID %ld\n", dwCtrlEvent
, dwProcessGroupID
);
1618 SERVER_START_REQ( send_console_signal
)
1620 req
->signal
= dwCtrlEvent
;
1621 req
->group_id
= dwProcessGroupID
;
1622 ret
= !wine_server_call_err( req
);
1626 /* FIXME: shall this function be synchronous, ie only return when all events
1627 * have been handled by all processes in the given group ?
1628 * As of today, we don't wait...
1634 /******************************************************************************
1635 * CreateConsoleScreenBuffer [KERNEL32.@] Creates a console screen buffer
1638 * dwDesiredAccess [I] Access flag
1639 * dwShareMode [I] Buffer share mode
1640 * sa [I] Security attributes
1641 * dwFlags [I] Type of buffer to create
1642 * lpScreenBufferData [I] Reserved
1645 * Should call SetLastError
1648 * Success: Handle to new console screen buffer
1649 * Failure: INVALID_HANDLE_VALUE
1651 HANDLE WINAPI
CreateConsoleScreenBuffer(DWORD dwDesiredAccess
, DWORD dwShareMode
,
1652 LPSECURITY_ATTRIBUTES sa
, DWORD dwFlags
,
1653 LPVOID lpScreenBufferData
)
1655 HANDLE ret
= INVALID_HANDLE_VALUE
;
1657 TRACE("(%ld,%ld,%p,%ld,%p)\n",
1658 dwDesiredAccess
, dwShareMode
, sa
, dwFlags
, lpScreenBufferData
);
1660 if (dwFlags
!= CONSOLE_TEXTMODE_BUFFER
|| lpScreenBufferData
!= NULL
)
1662 SetLastError(ERROR_INVALID_PARAMETER
);
1663 return INVALID_HANDLE_VALUE
;
1666 SERVER_START_REQ(create_console_output
)
1669 req
->access
= dwDesiredAccess
;
1670 req
->share
= dwShareMode
;
1671 req
->inherit
= (sa
&& sa
->bInheritHandle
);
1672 if (!wine_server_call_err( req
)) ret
= reply
->handle_out
;
1680 /***********************************************************************
1681 * GetConsoleScreenBufferInfo (KERNEL32.@)
1683 BOOL WINAPI
GetConsoleScreenBufferInfo(HANDLE hConsoleOutput
, LPCONSOLE_SCREEN_BUFFER_INFO csbi
)
1687 SERVER_START_REQ(get_console_output_info
)
1689 req
->handle
= console_handle_unmap(hConsoleOutput
);
1690 if ((ret
= !wine_server_call_err( req
)))
1692 csbi
->dwSize
.X
= reply
->width
;
1693 csbi
->dwSize
.Y
= reply
->height
;
1694 csbi
->dwCursorPosition
.X
= reply
->cursor_x
;
1695 csbi
->dwCursorPosition
.Y
= reply
->cursor_y
;
1696 csbi
->wAttributes
= reply
->attr
;
1697 csbi
->srWindow
.Left
= reply
->win_left
;
1698 csbi
->srWindow
.Right
= reply
->win_right
;
1699 csbi
->srWindow
.Top
= reply
->win_top
;
1700 csbi
->srWindow
.Bottom
= reply
->win_bottom
;
1701 csbi
->dwMaximumWindowSize
.X
= reply
->max_width
;
1702 csbi
->dwMaximumWindowSize
.Y
= reply
->max_height
;
1707 TRACE("(%p,(%d,%d) (%d,%d) %d (%d,%d-%d,%d) (%d,%d)\n",
1708 hConsoleOutput
, csbi
->dwSize
.X
, csbi
->dwSize
.Y
,
1709 csbi
->dwCursorPosition
.X
, csbi
->dwCursorPosition
.Y
,
1711 csbi
->srWindow
.Left
, csbi
->srWindow
.Top
, csbi
->srWindow
.Right
, csbi
->srWindow
.Bottom
,
1712 csbi
->dwMaximumWindowSize
.X
, csbi
->dwMaximumWindowSize
.Y
);
1718 /******************************************************************************
1719 * SetConsoleActiveScreenBuffer [KERNEL32.@] Sets buffer to current console
1725 BOOL WINAPI
SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput
)
1729 TRACE("(%p)\n", hConsoleOutput
);
1731 SERVER_START_REQ( set_console_input_info
)
1734 req
->mask
= SET_CONSOLE_INPUT_INFO_ACTIVE_SB
;
1735 req
->active_sb
= hConsoleOutput
;
1736 ret
= !wine_server_call_err( req
);
1743 /***********************************************************************
1744 * GetConsoleMode (KERNEL32.@)
1746 BOOL WINAPI
GetConsoleMode(HANDLE hcon
, LPDWORD mode
)
1750 SERVER_START_REQ(get_console_mode
)
1752 req
->handle
= console_handle_unmap(hcon
);
1753 ret
= !wine_server_call_err( req
);
1754 if (ret
&& mode
) *mode
= reply
->mode
;
1761 /******************************************************************************
1762 * SetConsoleMode [KERNEL32.@] Sets input mode of console's input buffer
1765 * hcon [I] Handle to console input or screen buffer
1766 * mode [I] Input or output mode to set
1773 * ENABLE_PROCESSED_INPUT 0x01
1774 * ENABLE_LINE_INPUT 0x02
1775 * ENABLE_ECHO_INPUT 0x04
1776 * ENABLE_WINDOW_INPUT 0x08
1777 * ENABLE_MOUSE_INPUT 0x10
1779 BOOL WINAPI
SetConsoleMode(HANDLE hcon
, DWORD mode
)
1783 SERVER_START_REQ(set_console_mode
)
1785 req
->handle
= console_handle_unmap(hcon
);
1787 ret
= !wine_server_call_err( req
);
1790 /* FIXME: when resetting a console input to editline mode, I think we should
1791 * empty the S_EditString buffer
1794 TRACE("(%p,%lx) retval == %d\n", hcon
, mode
, ret
);
1800 /******************************************************************
1801 * CONSOLE_WriteChars
1803 * WriteConsoleOutput helper: hides server call semantics
1804 * writes a string at a given pos with standard attribute
1806 int CONSOLE_WriteChars(HANDLE hCon
, LPCWSTR lpBuffer
, int nc
, COORD
* pos
)
1812 SERVER_START_REQ( write_console_output
)
1814 req
->handle
= console_handle_unmap(hCon
);
1817 req
->mode
= CHAR_INFO_MODE_TEXTSTDATTR
;
1819 wine_server_add_data( req
, lpBuffer
, nc
* sizeof(WCHAR
) );
1820 if (!wine_server_call_err( req
)) written
= reply
->written
;
1824 if (written
> 0) pos
->X
+= written
;
1828 /******************************************************************
1831 * WriteConsoleOutput helper: handles passing to next line (+scrolling if necessary)
1834 static int next_line(HANDLE hCon
, CONSOLE_SCREEN_BUFFER_INFO
* csbi
)
1840 csbi
->dwCursorPosition
.X
= 0;
1841 csbi
->dwCursorPosition
.Y
++;
1843 if (csbi
->dwCursorPosition
.Y
< csbi
->dwSize
.Y
) return 1;
1846 src
.Bottom
= csbi
->dwSize
.Y
- 1;
1848 src
.Right
= csbi
->dwSize
.X
- 1;
1853 ci
.Attributes
= csbi
->wAttributes
;
1854 ci
.Char
.UnicodeChar
= ' ';
1856 csbi
->dwCursorPosition
.Y
--;
1857 if (!ScrollConsoleScreenBufferW(hCon
, &src
, NULL
, dst
, &ci
))
1862 /******************************************************************
1865 * WriteConsoleOutput helper: writes a block of non special characters
1866 * Block can spread on several lines, and wrapping, if needed, is
1870 static int write_block(HANDLE hCon
, CONSOLE_SCREEN_BUFFER_INFO
* csbi
,
1871 DWORD mode
, LPCWSTR ptr
, int len
)
1873 int blk
; /* number of chars to write on current line */
1874 int done
; /* number of chars already written */
1876 if (len
<= 0) return 1;
1878 if (mode
& ENABLE_WRAP_AT_EOL_OUTPUT
) /* writes remaining on next line */
1880 for (done
= 0; done
< len
; done
+= blk
)
1882 blk
= min(len
- done
, csbi
->dwSize
.X
- csbi
->dwCursorPosition
.X
);
1884 if (CONSOLE_WriteChars(hCon
, ptr
+ done
, blk
, &csbi
->dwCursorPosition
) != blk
)
1886 if (csbi
->dwCursorPosition
.X
== csbi
->dwSize
.X
&& !next_line(hCon
, csbi
))
1892 int pos
= csbi
->dwCursorPosition
.X
;
1893 /* FIXME: we could reduce the number of loops
1894 * but, in most cases we wouldn't gain lots of time (it would only
1895 * happen if we're asked to overwrite more than twice the part of the line,
1898 for (blk
= done
= 0; done
< len
; done
+= blk
)
1900 blk
= min(len
- done
, csbi
->dwSize
.X
- csbi
->dwCursorPosition
.X
);
1902 csbi
->dwCursorPosition
.X
= pos
;
1903 if (CONSOLE_WriteChars(hCon
, ptr
+ done
, blk
, &csbi
->dwCursorPosition
) != blk
)
1911 /***********************************************************************
1912 * WriteConsoleW (KERNEL32.@)
1914 BOOL WINAPI
WriteConsoleW(HANDLE hConsoleOutput
, LPCVOID lpBuffer
, DWORD nNumberOfCharsToWrite
,
1915 LPDWORD lpNumberOfCharsWritten
, LPVOID lpReserved
)
1919 const WCHAR
* psz
= lpBuffer
;
1920 CONSOLE_SCREEN_BUFFER_INFO csbi
;
1923 TRACE("%p %s %ld %p %p\n",
1924 hConsoleOutput
, debugstr_wn(lpBuffer
, nNumberOfCharsToWrite
),
1925 nNumberOfCharsToWrite
, lpNumberOfCharsWritten
, lpReserved
);
1927 if (lpNumberOfCharsWritten
) *lpNumberOfCharsWritten
= 0;
1929 if (!GetConsoleMode(hConsoleOutput
, &mode
) ||
1930 !GetConsoleScreenBufferInfo(hConsoleOutput
, &csbi
))
1933 if (mode
& ENABLE_PROCESSED_OUTPUT
)
1937 for (i
= 0; i
< nNumberOfCharsToWrite
; i
++)
1941 case '\b': case '\t': case '\n': case '\a': case '\r':
1942 /* don't handle here the i-th char... done below */
1943 if ((k
= i
- first
) > 0)
1945 if (!write_block(hConsoleOutput
, &csbi
, mode
, &psz
[first
], k
))
1955 if (csbi
.dwCursorPosition
.X
> 0) csbi
.dwCursorPosition
.X
--;
1959 WCHAR tmp
[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
1961 if (!write_block(hConsoleOutput
, &csbi
, mode
, tmp
,
1962 ((csbi
.dwCursorPosition
.X
+ 8) & ~7) - csbi
.dwCursorPosition
.X
))
1967 next_line(hConsoleOutput
, &csbi
);
1973 csbi
.dwCursorPosition
.X
= 0;
1981 /* write the remaining block (if any) if processed output is enabled, or the
1982 * entire buffer otherwise
1984 if ((k
= nNumberOfCharsToWrite
- first
) > 0)
1986 if (!write_block(hConsoleOutput
, &csbi
, mode
, &psz
[first
], k
))
1992 SetConsoleCursorPosition(hConsoleOutput
, csbi
.dwCursorPosition
);
1993 if (lpNumberOfCharsWritten
) *lpNumberOfCharsWritten
= nw
;
1998 /***********************************************************************
1999 * WriteConsoleA (KERNEL32.@)
2001 BOOL WINAPI
WriteConsoleA(HANDLE hConsoleOutput
, LPCVOID lpBuffer
, DWORD nNumberOfCharsToWrite
,
2002 LPDWORD lpNumberOfCharsWritten
, LPVOID lpReserved
)
2008 n
= MultiByteToWideChar(CP_ACP
, 0, lpBuffer
, nNumberOfCharsToWrite
, NULL
, 0);
2010 if (lpNumberOfCharsWritten
) *lpNumberOfCharsWritten
= 0;
2011 xstring
= HeapAlloc(GetProcessHeap(), 0, n
* sizeof(WCHAR
));
2012 if (!xstring
) return 0;
2014 MultiByteToWideChar(CP_ACP
, 0, lpBuffer
, nNumberOfCharsToWrite
, xstring
, n
);
2016 ret
= WriteConsoleW(hConsoleOutput
, xstring
, n
, lpNumberOfCharsWritten
, 0);
2018 HeapFree(GetProcessHeap(), 0, xstring
);
2023 /******************************************************************************
2024 * SetConsoleCursorPosition [KERNEL32.@]
2025 * Sets the cursor position in console
2028 * hConsoleOutput [I] Handle of console screen buffer
2029 * dwCursorPosition [I] New cursor position coordinates
2033 BOOL WINAPI
SetConsoleCursorPosition(HANDLE hcon
, COORD pos
)
2036 CONSOLE_SCREEN_BUFFER_INFO csbi
;
2040 TRACE("%p %d %d\n", hcon
, pos
.X
, pos
.Y
);
2042 SERVER_START_REQ(set_console_output_info
)
2044 req
->handle
= console_handle_unmap(hcon
);
2045 req
->cursor_x
= pos
.X
;
2046 req
->cursor_y
= pos
.Y
;
2047 req
->mask
= SET_CONSOLE_OUTPUT_INFO_CURSOR_POS
;
2048 ret
= !wine_server_call_err( req
);
2052 if (!ret
|| !GetConsoleScreenBufferInfo(hcon
, &csbi
))
2055 /* if cursor is no longer visible, scroll the visible window... */
2056 w
= csbi
.srWindow
.Right
- csbi
.srWindow
.Left
+ 1;
2057 h
= csbi
.srWindow
.Bottom
- csbi
.srWindow
.Top
+ 1;
2058 if (pos
.X
< csbi
.srWindow
.Left
)
2060 csbi
.srWindow
.Left
= min(pos
.X
, csbi
.dwSize
.X
- w
);
2063 else if (pos
.X
> csbi
.srWindow
.Right
)
2065 csbi
.srWindow
.Left
= max(pos
.X
, w
) - w
+ 1;
2068 csbi
.srWindow
.Right
= csbi
.srWindow
.Left
+ w
- 1;
2070 if (pos
.Y
< csbi
.srWindow
.Top
)
2072 csbi
.srWindow
.Top
= min(pos
.Y
, csbi
.dwSize
.Y
- h
);
2075 else if (pos
.Y
> csbi
.srWindow
.Bottom
)
2077 csbi
.srWindow
.Top
= max(pos
.Y
, h
) - h
+ 1;
2080 csbi
.srWindow
.Bottom
= csbi
.srWindow
.Top
+ h
- 1;
2082 ret
= (do_move
) ? SetConsoleWindowInfo(hcon
, TRUE
, &csbi
.srWindow
) : TRUE
;
2087 /******************************************************************************
2088 * GetConsoleCursorInfo [KERNEL32.@] Gets size and visibility of console
2091 * hcon [I] Handle to console screen buffer
2092 * cinfo [O] Address of cursor information
2098 BOOL WINAPI
GetConsoleCursorInfo(HANDLE hCon
, LPCONSOLE_CURSOR_INFO cinfo
)
2102 SERVER_START_REQ(get_console_output_info
)
2104 req
->handle
= console_handle_unmap(hCon
);
2105 ret
= !wine_server_call_err( req
);
2108 cinfo
->dwSize
= reply
->cursor_size
;
2109 cinfo
->bVisible
= reply
->cursor_visible
;
2114 TRACE("(%p) returning (%ld,%d)\n", hCon
, cinfo
->dwSize
, cinfo
->bVisible
);
2119 /******************************************************************************
2120 * SetConsoleCursorInfo [KERNEL32.@] Sets size and visibility of cursor
2123 * hcon [I] Handle to console screen buffer
2124 * cinfo [I] Address of cursor information
2129 BOOL WINAPI
SetConsoleCursorInfo(HANDLE hCon
, LPCONSOLE_CURSOR_INFO cinfo
)
2133 TRACE("(%p,%ld,%d)\n", hCon
, cinfo
->dwSize
, cinfo
->bVisible
);
2134 SERVER_START_REQ(set_console_output_info
)
2136 req
->handle
= console_handle_unmap(hCon
);
2137 req
->cursor_size
= cinfo
->dwSize
;
2138 req
->cursor_visible
= cinfo
->bVisible
;
2139 req
->mask
= SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM
;
2140 ret
= !wine_server_call_err( req
);
2147 /******************************************************************************
2148 * SetConsoleWindowInfo [KERNEL32.@] Sets size and position of console
2151 * hcon [I] Handle to console screen buffer
2152 * bAbsolute [I] Coordinate type flag
2153 * window [I] Address of new window rectangle
2158 BOOL WINAPI
SetConsoleWindowInfo(HANDLE hCon
, BOOL bAbsolute
, LPSMALL_RECT window
)
2160 SMALL_RECT p
= *window
;
2163 TRACE("(%p,%d,(%d,%d-%d,%d))\n", hCon
, bAbsolute
, p
.Left
, p
.Top
, p
.Right
, p
.Bottom
);
2167 CONSOLE_SCREEN_BUFFER_INFO csbi
;
2169 if (!GetConsoleScreenBufferInfo(hCon
, &csbi
))
2171 p
.Left
+= csbi
.srWindow
.Left
;
2172 p
.Top
+= csbi
.srWindow
.Top
;
2173 p
.Right
+= csbi
.srWindow
.Right
;
2174 p
.Bottom
+= csbi
.srWindow
.Bottom
;
2176 SERVER_START_REQ(set_console_output_info
)
2178 req
->handle
= console_handle_unmap(hCon
);
2179 req
->win_left
= p
.Left
;
2180 req
->win_top
= p
.Top
;
2181 req
->win_right
= p
.Right
;
2182 req
->win_bottom
= p
.Bottom
;
2183 req
->mask
= SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW
;
2184 ret
= !wine_server_call_err( req
);
2192 /******************************************************************************
2193 * SetConsoleTextAttribute [KERNEL32.@] Sets colors for text
2195 * Sets the foreground and background color attributes of characters
2196 * written to the screen buffer.
2202 BOOL WINAPI
SetConsoleTextAttribute(HANDLE hConsoleOutput
, WORD wAttr
)
2206 TRACE("(%p,%d)\n", hConsoleOutput
, wAttr
);
2207 SERVER_START_REQ(set_console_output_info
)
2209 req
->handle
= console_handle_unmap(hConsoleOutput
);
2211 req
->mask
= SET_CONSOLE_OUTPUT_INFO_ATTR
;
2212 ret
= !wine_server_call_err( req
);
2219 /******************************************************************************
2220 * SetConsoleScreenBufferSize [KERNEL32.@] Changes size of console
2223 * hConsoleOutput [I] Handle to console screen buffer
2224 * dwSize [I] New size in character rows and cols
2230 BOOL WINAPI
SetConsoleScreenBufferSize(HANDLE hConsoleOutput
, COORD dwSize
)
2234 TRACE("(%p,(%d,%d))\n", hConsoleOutput
, dwSize
.X
, dwSize
.Y
);
2235 SERVER_START_REQ(set_console_output_info
)
2237 req
->handle
= console_handle_unmap(hConsoleOutput
);
2238 req
->width
= dwSize
.X
;
2239 req
->height
= dwSize
.Y
;
2240 req
->mask
= SET_CONSOLE_OUTPUT_INFO_SIZE
;
2241 ret
= !wine_server_call_err( req
);
2248 /******************************************************************************
2249 * ScrollConsoleScreenBufferA [KERNEL32.@]
2252 BOOL WINAPI
ScrollConsoleScreenBufferA(HANDLE hConsoleOutput
, LPSMALL_RECT lpScrollRect
,
2253 LPSMALL_RECT lpClipRect
, COORD dwDestOrigin
,
2258 ciw
.Attributes
= lpFill
->Attributes
;
2259 MultiByteToWideChar(CP_ACP
, 0, &lpFill
->Char
.AsciiChar
, 1, &ciw
.Char
.UnicodeChar
, 1);
2261 return ScrollConsoleScreenBufferW(hConsoleOutput
, lpScrollRect
, lpClipRect
,
2262 dwDestOrigin
, &ciw
);
2265 /******************************************************************
2266 * CONSOLE_FillLineUniform
2268 * Helper function for ScrollConsoleScreenBufferW
2269 * Fills a part of a line with a constant character info
2271 void CONSOLE_FillLineUniform(HANDLE hConsoleOutput
, int i
, int j
, int len
, LPCHAR_INFO lpFill
)
2273 SERVER_START_REQ( fill_console_output
)
2275 req
->handle
= console_handle_unmap(hConsoleOutput
);
2276 req
->mode
= CHAR_INFO_MODE_TEXTATTR
;
2281 req
->data
.ch
= lpFill
->Char
.UnicodeChar
;
2282 req
->data
.attr
= lpFill
->Attributes
;
2283 wine_server_call_err( req
);
2288 /******************************************************************************
2289 * ScrollConsoleScreenBufferW [KERNEL32.@]
2293 BOOL WINAPI
ScrollConsoleScreenBufferW(HANDLE hConsoleOutput
, LPSMALL_RECT lpScrollRect
,
2294 LPSMALL_RECT lpClipRect
, COORD dwDestOrigin
,
2302 CONSOLE_SCREEN_BUFFER_INFO csbi
;
2307 TRACE("(%p,(%d,%d-%d,%d),(%d,%d-%d,%d),%d-%d,%p)\n", hConsoleOutput
,
2308 lpScrollRect
->Left
, lpScrollRect
->Top
,
2309 lpScrollRect
->Right
, lpScrollRect
->Bottom
,
2310 lpClipRect
->Left
, lpClipRect
->Top
,
2311 lpClipRect
->Right
, lpClipRect
->Bottom
,
2312 dwDestOrigin
.X
, dwDestOrigin
.Y
, lpFill
);
2314 TRACE("(%p,(%d,%d-%d,%d),(nil),%d-%d,%p)\n", hConsoleOutput
,
2315 lpScrollRect
->Left
, lpScrollRect
->Top
,
2316 lpScrollRect
->Right
, lpScrollRect
->Bottom
,
2317 dwDestOrigin
.X
, dwDestOrigin
.Y
, lpFill
);
2319 if (!GetConsoleScreenBufferInfo(hConsoleOutput
, &csbi
))
2322 src
.X
= lpScrollRect
->Left
;
2323 src
.Y
= lpScrollRect
->Top
;
2325 /* step 1: get dst rect */
2326 dst
.Left
= dwDestOrigin
.X
;
2327 dst
.Top
= dwDestOrigin
.Y
;
2328 dst
.Right
= dst
.Left
+ (lpScrollRect
->Right
- lpScrollRect
->Left
);
2329 dst
.Bottom
= dst
.Top
+ (lpScrollRect
->Bottom
- lpScrollRect
->Top
);
2331 /* step 2a: compute the final clip rect (optional passed clip and screen buffer limits */
2334 clip
.Left
= max(0, lpClipRect
->Left
);
2335 clip
.Right
= min(csbi
.dwSize
.X
- 1, lpClipRect
->Right
);
2336 clip
.Top
= max(0, lpClipRect
->Top
);
2337 clip
.Bottom
= min(csbi
.dwSize
.Y
- 1, lpClipRect
->Bottom
);
2342 clip
.Right
= csbi
.dwSize
.X
- 1;
2344 clip
.Bottom
= csbi
.dwSize
.Y
- 1;
2346 if (clip
.Left
> clip
.Right
|| clip
.Top
> clip
.Bottom
) return FALSE
;
2348 /* step 2b: clip dst rect */
2349 if (dst
.Left
< clip
.Left
) {src
.X
+= clip
.Left
- dst
.Left
; dst
.Left
= clip
.Left
;}
2350 if (dst
.Top
< clip
.Top
) {src
.Y
+= clip
.Top
- dst
.Top
; dst
.Top
= clip
.Top
;}
2351 if (dst
.Right
> clip
.Right
) dst
.Right
= clip
.Right
;
2352 if (dst
.Bottom
> clip
.Bottom
) dst
.Bottom
= clip
.Bottom
;
2354 /* step 3: transfer the bits */
2355 SERVER_START_REQ(move_console_output
)
2357 req
->handle
= console_handle_unmap(hConsoleOutput
);
2360 req
->x_dst
= dst
.Left
;
2361 req
->y_dst
= dst
.Top
;
2362 req
->w
= dst
.Right
- dst
.Left
+ 1;
2363 req
->h
= dst
.Bottom
- dst
.Top
+ 1;
2364 ret
= !wine_server_call_err( req
);
2368 if (!ret
) return FALSE
;
2370 /* step 4: clean out the exposed part */
2372 /* have to write cell [i,j] if it is not in dst rect (because it has already
2373 * been written to by the scroll) and is in clip (we shall not write
2376 for (j
= max(lpScrollRect
->Top
, clip
.Top
); j
<= min(lpScrollRect
->Bottom
, clip
.Bottom
); j
++)
2378 inside
= dst
.Top
<= j
&& j
<= dst
.Bottom
;
2380 for (i
= max(lpScrollRect
->Left
, clip
.Left
); i
<= min(lpScrollRect
->Right
, clip
.Right
); i
++)
2382 if (inside
&& dst
.Left
<= i
&& i
<= dst
.Right
)
2386 CONSOLE_FillLineUniform(hConsoleOutput
, start
, j
, i
- start
, lpFill
);
2392 if (start
== -1) start
= i
;
2396 CONSOLE_FillLineUniform(hConsoleOutput
, start
, j
, i
- start
, lpFill
);
2403 /* ====================================================================
2405 * Console manipulation functions
2407 * ====================================================================*/
2409 /* some missing functions...
2410 * FIXME: those are likely to be defined as undocumented function in kernel32 (or part of them)
2411 * should get the right API and implement them
2412 * GetConsoleCommandHistory[AW] (dword dword dword)
2413 * GetConsoleCommandHistoryLength[AW]
2414 * SetConsoleCommandHistoryMode
2415 * SetConsoleNumberOfCommands[AW]
2417 int CONSOLE_GetHistory(int idx
, WCHAR
* buf
, int buf_len
)
2421 SERVER_START_REQ( get_console_input_history
)
2425 if (buf
&& buf_len
> 1)
2427 wine_server_set_reply( req
, buf
, (buf_len
- 1) * sizeof(WCHAR
) );
2429 if (!wine_server_call_err( req
))
2431 if (buf
) buf
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
2432 len
= reply
->total
/ sizeof(WCHAR
) + 1;
2439 /******************************************************************
2440 * CONSOLE_AppendHistory
2444 BOOL
CONSOLE_AppendHistory(const WCHAR
* ptr
)
2446 size_t len
= strlenW(ptr
);
2449 while (len
&& (ptr
[len
- 1] == '\n' || ptr
[len
- 1] == '\r')) len
--;
2451 SERVER_START_REQ( append_console_input_history
)
2454 wine_server_add_data( req
, ptr
, len
* sizeof(WCHAR
) );
2455 ret
= !wine_server_call_err( req
);
2461 /******************************************************************
2462 * CONSOLE_GetNumHistoryEntries
2466 unsigned CONSOLE_GetNumHistoryEntries(void)
2469 SERVER_START_REQ(get_console_input_info
)
2472 if (!wine_server_call_err( req
)) ret
= reply
->history_index
;
2478 /******************************************************************
2479 * CONSOLE_GetEditionMode
2483 BOOL
CONSOLE_GetEditionMode(HANDLE hConIn
, int* mode
)
2485 unsigned ret
= FALSE
;
2486 SERVER_START_REQ(get_console_input_info
)
2488 req
->handle
= console_handle_unmap(hConIn
);
2489 if ((ret
= !wine_server_call_err( req
)))
2490 *mode
= reply
->edition_mode
;