2013-04-07 23:18:59 +00:00
/*
* COPYRIGHT : See COPYING in the top level directory
* PROJECT : ReactOS Console Server DLL
2015-10-05 12:21:25 +00:00
* FILE : win32ss / user / winsrv / consrv / include / conio . h
2013-04-07 23:18:59 +00:00
* PURPOSE : Public Console I / O Interface
2013-04-10 20:22:30 +00:00
* PROGRAMMERS : G <EFBFBD> van Geldorp
* Jeffrey Morlan
* Hermes Belusca - Maito ( hermes . belusca @ sfr . fr )
2013-04-07 23:18:59 +00:00
*/
# pragma once
2014-08-04 16:25:12 +00:00
# include "rect.h"
2013-04-07 23:18:59 +00:00
/* Default attributes */
# define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
# define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY )
2014-08-09 19:47:40 +00:00
2013-04-07 23:18:59 +00:00
/* Object type magic numbers */
typedef enum _CONSOLE_IO_OBJECT_TYPE
{
2014-08-11 13:31:22 +00:00
UNKNOWN = 0x00 , // --> Unknown object
TEXTMODE_BUFFER = 0x01 , // --> Output-type object for text SBs
GRAPHICS_BUFFER = 0x02 , // --> Output-type object for graphics SBs
2013-05-29 00:29:07 +00:00
SCREEN_BUFFER = 0x03 , // --> Any SB type
2014-08-11 13:31:22 +00:00
INPUT_BUFFER = 0x04 , // --> Input-type object
ANY_TYPE_BUFFER = 0x07 , // --> Any IO object
2013-04-07 23:18:59 +00:00
} CONSOLE_IO_OBJECT_TYPE ;
typedef struct _CONSOLE_IO_OBJECT
{
CONSOLE_IO_OBJECT_TYPE Type ;
2014-08-11 13:31:22 +00:00
2013-04-08 21:03:24 +00:00
struct _CONSOLE * /* PCONSOLE */ Console ;
2014-08-11 13:31:22 +00:00
LONG ReferenceCount ; /* Is incremented each time a console object gets referenced */
2013-04-07 23:18:59 +00:00
LONG AccessRead , AccessWrite ;
LONG ExclusiveRead , ExclusiveWrite ;
} CONSOLE_IO_OBJECT , * PCONSOLE_IO_OBJECT ;
2013-05-29 00:29:07 +00:00
/******************************************************************************\
| * * |
| * Abstract " class " for screen - buffers , be they text - mode or graphics * |
| * * |
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* See conoutput . c for the implementation
*/
2020-04-12 17:03:30 +00:00
# define GetType(This) (((PCONSOLE_SCREEN_BUFFER)(This))->Header.Type)
2013-05-29 00:29:07 +00:00
2020-04-12 17:03:30 +00:00
typedef struct _CONSOLE_SCREEN_BUFFER
2013-05-29 00:29:07 +00:00
{
CONSOLE_IO_OBJECT Header ; /* Object header - MUST BE IN FIRST PLACE */
LIST_ENTRY ListEntry ; /* Entry in console's list of buffers */
2013-10-13 00:11:38 +00:00
COORD ScreenBufferSize ; /* Size of this screen buffer. (Rows, Columns) for text-mode and (Width, Height) for graphics-mode */
2013-05-29 00:29:07 +00:00
COORD ViewSize ; /* Associated "view" (i.e. console) size */
COORD OldScreenBufferSize ; /* Old size of this screen buffer */
COORD OldViewSize ; /* Old associated view size */
2013-06-23 00:18:47 +00:00
COORD ViewOrigin ; /* Beginning offset for the actual display area */
2013-05-29 00:29:07 +00:00
/***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
COORD CursorPosition ; /* Current cursor position */
BOOLEAN CursorBlinkOn ;
BOOLEAN ForceCursorOff ;
// ULONG CursorSize;
CONSOLE_CURSOR_INFO CursorInfo ; // FIXME: Keep this member or not ??
/*********************************************/
2013-10-12 15:37:50 +00:00
HPALETTE PaletteHandle ; /* Handle to the color palette associated to this buffer */
UINT PaletteUsage ; /* The new use of the system palette. See SetSystemPaletteUse 'uUsage' parameter */
2020-02-23 20:45:55 +00:00
// USHORT ScreenDefaultAttrib; /* Default screen char attribute */
// USHORT PopupDefaultAttrib; /* Default popup char attribute */
2013-05-29 00:29:07 +00:00
USHORT Mode ; /* Output buffer modes */
2020-04-12 17:03:30 +00:00
} CONSOLE_SCREEN_BUFFER , * PCONSOLE_SCREEN_BUFFER ;
2013-05-29 00:29:07 +00:00
/******************************************************************************\
| * * |
| * Text - mode and graphics - mode screen - buffer " classes " * |
| * * |
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* See text . c for the implementation
*/
2013-04-07 23:18:59 +00:00
/************************************************************************
* Screen buffer structure represents the win32 screen buffer object . *
* Internally , the portion of the buffer being shown CAN loop past the *
* bottom of the virtual buffer and wrap around to the top . Win32 does *
* not do this . I decided to do this because it eliminates the need to *
* do a massive memcpy ( ) to scroll the contents of the buffer up to *
* scroll the screen on output , instead I just shift down the position *
* to be displayed , and let it wrap around to the top again . *
* The VirtualY member keeps track of the top Y coord that win32 *
* clients THINK is currently being displayed , because they think that *
* when the display reaches the bottom of the buffer and another line *
* being printed causes another line to scroll down , that the buffer IS *
* memcpy ( ) ' s up , and the bottom of the buffer is still displayed , but *
* internally , I just wrap back to the top of the buffer . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2013-05-29 00:29:07 +00:00
typedef struct _TEXTMODE_BUFFER_INFO
2013-04-07 23:18:59 +00:00
{
2013-05-29 00:29:07 +00:00
COORD ScreenBufferSize ;
2020-02-23 20:45:55 +00:00
COORD ViewSize ;
2013-05-29 00:29:07 +00:00
USHORT ScreenAttrib ;
USHORT PopupAttrib ;
ULONG CursorSize ;
2014-05-02 16:46:13 +00:00
BOOLEAN IsCursorVisible ;
2013-05-29 00:29:07 +00:00
} TEXTMODE_BUFFER_INFO , * PTEXTMODE_BUFFER_INFO ;
typedef struct _TEXTMODE_SCREEN_BUFFER
{
2013-06-14 01:10:43 +00:00
CONSOLE_SCREEN_BUFFER ; /* Screen buffer base class - MUST BE IN FIRST PLACE */
2013-04-07 23:18:59 +00:00
2020-03-01 16:22:05 +00:00
USHORT VirtualY ; /* Top row of buffer being displayed, reported to callers */
2013-06-14 01:10:43 +00:00
PCHAR_INFO Buffer ; /* Pointer to UNICODE screen buffer (Buffer->Char.UnicodeChar only is valid, not Char.AsciiChar) */
2013-04-07 23:18:59 +00:00
2020-02-23 20:45:55 +00:00
USHORT ScreenDefaultAttrib ; /* Default screen char attribute */
USHORT PopupDefaultAttrib ; /* Default popup char attribute */
2013-05-29 00:29:07 +00:00
} TEXTMODE_SCREEN_BUFFER , * PTEXTMODE_SCREEN_BUFFER ;
2013-04-07 23:18:59 +00:00
2013-05-29 00:29:07 +00:00
/*
* See graphics . c for the implementation
*/
typedef struct _GRAPHICS_BUFFER_INFO
{
CONSOLE_GRAPHICS_BUFFER_INFO Info ;
} GRAPHICS_BUFFER_INFO , * PGRAPHICS_BUFFER_INFO ;
typedef struct _GRAPHICS_SCREEN_BUFFER
{
CONSOLE_SCREEN_BUFFER ; /* Screen buffer base class - MUST BE IN FIRST PLACE */
ULONG BitMapInfoLength ; /* Real size of the structure pointed by BitMapInfo */
LPBITMAPINFO BitMapInfo ; /* Information on the bitmap buffer */
ULONG BitMapUsage ; /* See the uUsage parameter of GetDIBits */
HANDLE hSection ; /* Handle to the memory shared section for the bitmap buffer */
PVOID BitMap ; /* Our bitmap buffer */
2014-05-02 16:46:13 +00:00
2013-05-29 00:29:07 +00:00
PVOID ClientBitMap ; /* A copy of the client view of our bitmap buffer */
HANDLE Mutex ; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
HANDLE ClientMutex ; /* A copy of the client handle to our mutex */
HANDLE ClientProcess ; /* Handle to the client process who opened the buffer, to unmap the view */
} GRAPHICS_SCREEN_BUFFER , * PGRAPHICS_SCREEN_BUFFER ;
2013-04-07 23:18:59 +00:00
typedef struct _CONSOLE_INPUT_BUFFER
{
2013-05-29 00:29:07 +00:00
CONSOLE_IO_OBJECT Header ; /* Object header - MUST BE IN FIRST PLACE */
2013-04-07 23:18:59 +00:00
2020-02-22 22:19:45 +00:00
ULONG InputBufferSize ; /* Size of this input buffer (maximum number of events) -- UNUSED!! */
ULONG NumberOfEvents ; /* Current number of events in the queue */
LIST_ENTRY InputEvents ; /* Input events queue list head */
HANDLE ActiveEvent ; /* Event set when an input event is added to the queue */
2013-04-07 23:18:59 +00:00
2013-05-29 00:29:07 +00:00
USHORT Mode ; /* Input buffer modes */
2013-04-07 23:18:59 +00:00
} CONSOLE_INPUT_BUFFER , * PCONSOLE_INPUT_BUFFER ;
2013-06-23 00:18:47 +00:00
2015-03-24 23:58:44 +00:00
/*
* Structure used to hold console information
*/
typedef struct _CONSOLE_INFO
{
ULONG InputBufferSize ;
COORD ScreenBufferSize ;
COORD ConsoleSize ; /* The size of the console */
ULONG CursorSize ;
BOOLEAN CursorBlinkOn ;
BOOLEAN ForceCursorOff ;
USHORT ScreenAttrib ; // CHAR_INFO ScreenFillAttrib
USHORT PopupAttrib ;
ULONG CodePage ;
} CONSOLE_INFO , * PCONSOLE_INFO ;
2020-04-12 17:03:30 +00:00
typedef struct _TERMINAL TERMINAL , * PTERMINAL ;
2014-05-02 16:46:13 +00:00
typedef struct _TERMINAL_VTBL
2013-04-07 23:18:59 +00:00
{
/*
* Internal interface ( functions called by the console server only )
*/
2014-05-03 01:59:28 +00:00
NTSTATUS ( NTAPI * InitTerminal ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
IN struct _CONSOLE * Console ) ;
2014-05-03 01:59:28 +00:00
VOID ( NTAPI * DeinitTerminal ) ( IN OUT PTERMINAL This ) ;
2013-06-23 00:18:47 +00:00
2014-08-29 19:54:10 +00:00
/************ Line discipline ***************/
2013-05-29 00:29:07 +00:00
/* Interface used only for text-mode screen buffers */
2014-08-29 19:54:10 +00:00
NTSTATUS ( NTAPI * ReadStream ) ( IN OUT PTERMINAL This ,
2014-12-14 16:53:47 +00:00
IN BOOLEAN Unicode ,
/**PWCHAR Buffer,**/
OUT PVOID Buffer ,
IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl ,
IN PVOID Parameter OPTIONAL ,
IN ULONG NumCharsToRead ,
OUT PULONG NumCharsRead OPTIONAL ) ;
2014-08-29 19:54:10 +00:00
NTSTATUS ( NTAPI * WriteStream ) ( IN OUT PTERMINAL This ,
PTEXTMODE_SCREEN_BUFFER Buff ,
PWCHAR Buffer ,
DWORD Length ,
BOOL Attrib ) ;
/************ Line discipline ***************/
2014-08-31 11:58:50 +00:00
/* Interface used for both text-mode and graphics screen buffers */
VOID ( NTAPI * DrawRegion ) ( IN OUT PTERMINAL This ,
SMALL_RECT * Region ) ;
2014-05-02 16:46:13 +00:00
BOOL ( NTAPI * SetCursorInfo ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
PCONSOLE_SCREEN_BUFFER ScreenBuffer ) ;
2014-05-02 16:46:13 +00:00
BOOL ( NTAPI * SetScreenInfo ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
PCONSOLE_SCREEN_BUFFER ScreenBuffer ,
SHORT OldCursorX ,
SHORT OldCursorY ) ;
2014-05-02 16:46:13 +00:00
VOID ( NTAPI * ResizeTerminal ) ( IN OUT PTERMINAL This ) ;
VOID ( NTAPI * SetActiveScreenBuffer ) ( IN OUT PTERMINAL This ) ;
VOID ( NTAPI * ReleaseScreenBuffer ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
IN PCONSOLE_SCREEN_BUFFER ScreenBuffer ) ;
2013-04-07 23:18:59 +00:00
/*
* External interface ( functions corresponding to the Console API )
*/
2014-05-02 16:46:13 +00:00
VOID ( NTAPI * GetLargestConsoleWindowSize ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
PCOORD pSize ) ;
2014-05-02 16:46:13 +00:00
BOOL ( NTAPI * SetPalette ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
HPALETTE PaletteHandle ,
UINT PaletteUsage ) ;
2014-05-02 16:46:13 +00:00
INT ( NTAPI * ShowMouseCursor ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
BOOL Show ) ;
2013-05-29 00:29:07 +00:00
2014-12-14 21:18:40 +00:00
#if 0 // Possible future terminal interface
2014-05-03 01:59:28 +00:00
BOOL ( NTAPI * GetTerminalProperty ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
ULONG Flag ,
PVOID Info ,
ULONG Size ) ;
2014-05-03 01:59:28 +00:00
BOOL ( NTAPI * SetTerminalProperty ) ( IN OUT PTERMINAL This ,
2013-10-12 15:44:22 +00:00
ULONG Flag ,
PVOID Info /*,
ULONG Size */ ) ;
2013-05-29 00:29:07 +00:00
# endif
2014-05-02 16:46:13 +00:00
} TERMINAL_VTBL , * PTERMINAL_VTBL ;
2013-04-07 23:18:59 +00:00
2014-05-02 16:46:13 +00:00
struct _TERMINAL
2013-04-07 23:18:59 +00:00
{
2014-05-02 16:46:13 +00:00
PTERMINAL_VTBL Vtbl ; /* Virtual table */
2014-12-14 21:18:40 +00:00
struct _CONSOLE * Console ; /* Console to which the terminal is attached to */
2014-12-14 21:51:32 +00:00
PVOID Context ; /* Private context */
2013-06-23 00:18:47 +00:00
} ;
2013-04-07 23:18:59 +00:00
/*
* WARNING : Change the state of the console ONLY when the console is locked !
*/
typedef enum _CONSOLE_STATE
{
CONSOLE_INITIALIZING , /* Console is initializing */
CONSOLE_RUNNING , /* Console running */
CONSOLE_TERMINATING , /* Console about to be destroyed (but still not) */
CONSOLE_IN_DESTRUCTION /* Console in destruction */
} CONSOLE_STATE , * PCONSOLE_STATE ;
typedef struct _CONSOLE
{
2014-05-02 16:46:13 +00:00
/******************************* Console Set-up *******************************/
2014-08-31 14:57:43 +00:00
LONG ReferenceCount ; /* Is incremented each time a handle to something in the console (a screen-buffer or the input buffer of this console) gets referenced */
CRITICAL_SECTION Lock ;
2014-12-14 17:30:38 +00:00
CONSOLE_STATE State ; /* State of the console */
TERMINAL TermIFace ; /* Terminal-specific interface */
2020-03-01 16:22:05 +00:00
BOOLEAN ConsolePaused ; /* If TRUE, the console is paused */
2014-08-29 19:45:45 +00:00
/******************************** Input buffer ********************************/
2013-07-06 19:47:53 +00:00
CONSOLE_INPUT_BUFFER InputBuffer ; /* Input buffer of the console */
2014-05-02 18:44:26 +00:00
UINT InputCodePage ;
2013-04-07 23:18:59 +00:00
/******************************* Screen buffers *******************************/
LIST_ENTRY BufferList ; /* List of all screen buffers for this console */
PCONSOLE_SCREEN_BUFFER ActiveBuffer ; /* Pointer to currently active screen buffer */
2013-06-14 01:10:43 +00:00
UINT OutputCodePage ;
2013-04-07 23:18:59 +00:00
/****************************** Other properties ******************************/
2013-05-29 00:29:07 +00:00
COORD ConsoleSize ; /* The current size of the console, for text-mode only */
BOOLEAN FixedSize ; /* TRUE if the console is of fixed size */
2020-01-07 06:26:58 +00:00
BOOLEAN IsCJK ; /* TRUE if Chinese, Japanese or Korean (CJK) */
2020-04-10 18:37:28 +00:00
} CONSOLE , * PCONSOLE ;
2013-04-07 23:18:59 +00:00
/* console.c */
2014-05-02 16:46:13 +00:00
VOID NTAPI
ConDrvPause ( PCONSOLE Console ) ;
VOID NTAPI
ConDrvUnpause ( PCONSOLE Console ) ;
2013-06-23 00:18:47 +00:00
2014-09-05 21:08:15 +00:00
# define GetConsoleInputBufferMode(Console) \
( Console ) - > InputBuffer . Mode
2013-04-07 23:18:59 +00:00
/* conoutput.c */
2013-06-14 01:10:43 +00:00
PCHAR_INFO ConioCoordToPointer ( PTEXTMODE_SCREEN_BUFFER Buff , ULONG X , ULONG Y ) ;
2020-03-01 16:22:05 +00:00
NTSTATUS ConioResizeBuffer ( PCONSOLE Console ,
2013-05-29 00:29:07 +00:00
PTEXTMODE_SCREEN_BUFFER ScreenBuffer ,
COORD Size ) ;
2013-04-07 23:18:59 +00:00
2020-01-07 06:26:58 +00:00
/* wcwidth.c */
int mk_wcwidth_cjk ( wchar_t ucs ) ;
2020-02-09 21:22:52 +00:00
// NOTE: The check against 0x80 is to avoid calling the helper function
// for characters that we already know are not full-width.
# define IS_FULL_WIDTH(wch) \
( ( ( USHORT ) ( wch ) > = 0x0080 ) & & ( mk_wcwidth_cjk ( wch ) = = 2 ) )
2013-04-07 23:18:59 +00:00
/* EOF */