ReactOS  0.4.15-dev-1389-g828d5fa
conio.h
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Console Server DLL
4  * FILE: win32ss/user/winsrv/consrv/include/conio.h
5  * PURPOSE: Public Console I/O Interface
6  * PROGRAMMERS: Gé van Geldorp
7  * Jeffrey Morlan
8  * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9  */
10 
11 #pragma once
12 
13 #include "rect.h"
14 
15 /* Default attributes */
16 #define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
17 #define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
18  BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
19 
20 
21 /* Object type magic numbers */
23 {
24  UNKNOWN = 0x00, // --> Unknown object
25  TEXTMODE_BUFFER = 0x01, // --> Output-type object for text SBs
26  GRAPHICS_BUFFER = 0x02, // --> Output-type object for graphics SBs
27  SCREEN_BUFFER = 0x03, // --> Any SB type
28  INPUT_BUFFER = 0x04, // --> Input-type object
29  ANY_TYPE_BUFFER = 0x07, // --> Any IO object
31 
32 typedef struct _CONSOLE_IO_OBJECT
33 {
35 
36  struct _CONSOLE* /* PCONSOLE */ Console;
37  LONG ReferenceCount; /* Is incremented each time a console object gets referenced */
38 
42 
43 
44 /******************************************************************************\
45 |* *|
46 |* Abstract "class" for screen-buffers, be they text-mode or graphics *|
47 |* *|
48 \******************************************************************************/
49 
50 /*
51  * See conoutput.c for the implementation
52  */
53 
54 #define GetType(This) (((PCONSOLE_SCREEN_BUFFER)(This))->Header.Type)
55 
56 typedef struct _CONSOLE_SCREEN_BUFFER
57 {
58  CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
59 
60  LIST_ENTRY ListEntry; /* Entry in console's list of buffers */
61 
62  COORD ScreenBufferSize; /* Size of this screen buffer. (Rows, Columns) for text-mode and (Width, Height) for graphics-mode */
63  COORD ViewSize; /* Associated "view" (i.e. console) size */
64 
65  COORD OldScreenBufferSize; /* Old size of this screen buffer */
66  COORD OldViewSize; /* Old associated view size */
67 
68  COORD ViewOrigin; /* Beginning offset for the actual display area */
69 
70 /***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
71  COORD CursorPosition; /* Current cursor position */
74 // ULONG CursorSize;
75  CONSOLE_CURSOR_INFO CursorInfo; // FIXME: Keep this member or not ??
76 /*********************************************/
77 
78  HPALETTE PaletteHandle; /* Handle to the color palette associated to this buffer */
79  UINT PaletteUsage; /* The new use of the system palette. See SetSystemPaletteUse 'uUsage' parameter */
80 
81 // USHORT ScreenDefaultAttrib; /* Default screen char attribute */
82 // USHORT PopupDefaultAttrib; /* Default popup char attribute */
83  USHORT Mode; /* Output buffer modes */
85 
86 
87 
88 /******************************************************************************\
89 |* *|
90 |* Text-mode and graphics-mode screen-buffer "classes" *|
91 |* *|
92 \******************************************************************************/
93 
94 /*
95  * See text.c for the implementation
96  */
97 
98 /************************************************************************
99  * Screen buffer structure represents the win32 screen buffer object. *
100  * Internally, the portion of the buffer being shown CAN loop past the *
101  * bottom of the virtual buffer and wrap around to the top. Win32 does *
102  * not do this. I decided to do this because it eliminates the need to *
103  * do a massive memcpy() to scroll the contents of the buffer up to *
104  * scroll the screen on output, instead I just shift down the position *
105  * to be displayed, and let it wrap around to the top again. *
106  * The VirtualY member keeps track of the top Y coord that win32 *
107  * clients THINK is currently being displayed, because they think that *
108  * when the display reaches the bottom of the buffer and another line *
109  * being printed causes another line to scroll down, that the buffer IS *
110  * memcpy()'s up, and the bottom of the buffer is still displayed, but *
111  * internally, I just wrap back to the top of the buffer. *
112  ************************************************************************/
113 
114 typedef struct _TEXTMODE_BUFFER_INFO
115 {
123 
125 {
126  CONSOLE_SCREEN_BUFFER; /* Screen buffer base class - MUST BE IN FIRST PLACE */
127 
128  USHORT VirtualY; /* Top row of buffer being displayed, reported to callers */
129  PCHAR_INFO Buffer; /* Pointer to UNICODE screen buffer (Buffer->Char.UnicodeChar only is valid, not Char.AsciiChar) */
130 
131  USHORT ScreenDefaultAttrib; /* Default screen char attribute */
132  USHORT PopupDefaultAttrib; /* Default popup char attribute */
134 
135 
136 /*
137  * See graphics.c for the implementation
138  */
139 
140 typedef struct _GRAPHICS_BUFFER_INFO
141 {
144 
146 {
147  CONSOLE_SCREEN_BUFFER; /* Screen buffer base class - MUST BE IN FIRST PLACE */
148 
149  ULONG BitMapInfoLength; /* Real size of the structure pointed by BitMapInfo */
150  LPBITMAPINFO BitMapInfo; /* Information on the bitmap buffer */
151  ULONG BitMapUsage; /* See the uUsage parameter of GetDIBits */
152  HANDLE hSection; /* Handle to the memory shared section for the bitmap buffer */
153  PVOID BitMap; /* Our bitmap buffer */
154 
155  PVOID ClientBitMap; /* A copy of the client view of our bitmap buffer */
156  HANDLE Mutex; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
157  HANDLE ClientMutex; /* A copy of the client handle to our mutex */
158  HANDLE ClientProcess; /* Handle to the client process who opened the buffer, to unmap the view */
160 
161 
162 
163 typedef struct _CONSOLE_INPUT_BUFFER
164 {
165  CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
166 
167  ULONG InputBufferSize; /* Size of this input buffer (maximum number of events) -- UNUSED!! */
168  ULONG NumberOfEvents; /* Current number of events in the queue */
169  LIST_ENTRY InputEvents; /* Input events queue list head */
170  HANDLE ActiveEvent; /* Event set when an input event is added to the queue */
171 
172  USHORT Mode; /* Input buffer modes */
174 
175 
176 /*
177  * Structure used to hold console information
178  */
179 typedef struct _CONSOLE_INFO
180 {
183  COORD ConsoleSize; /* The size of the console */
184 
188 
189  USHORT ScreenAttrib; // CHAR_INFO ScreenFillAttrib
191 
193 
195 
196 typedef struct _TERMINAL TERMINAL, *PTERMINAL;
197 
198 typedef struct _TERMINAL_VTBL
199 {
200  /*
201  * Internal interface (functions called by the console server only)
202  */
203  NTSTATUS (NTAPI *InitTerminal)(IN OUT PTERMINAL This,
204  IN struct _CONSOLE* Console);
205  VOID (NTAPI *DeinitTerminal)(IN OUT PTERMINAL This);
206 
207 
208 
209 /************ Line discipline ***************/
210 
211  /* Interface used only for text-mode screen buffers */
212 
213  NTSTATUS (NTAPI *ReadStream)(IN OUT PTERMINAL This,
216  OUT PVOID Buffer,
220  OUT PULONG NumCharsRead OPTIONAL);
221  NTSTATUS (NTAPI *WriteStream)(IN OUT PTERMINAL This,
223  PWCHAR Buffer,
224  DWORD Length,
225  BOOL Attrib);
226 
227 /************ Line discipline ***************/
228 
229 
230 
231  /* Interface used for both text-mode and graphics screen buffers */
234  BOOL (NTAPI *SetCursorInfo)(IN OUT PTERMINAL This,
236  BOOL (NTAPI *SetScreenInfo)(IN OUT PTERMINAL This,
239  SHORT OldCursorY);
240  VOID (NTAPI *ResizeTerminal)(IN OUT PTERMINAL This);
242  VOID (NTAPI *ReleaseScreenBuffer)(IN OUT PTERMINAL This,
244 
245  /*
246  * External interface (functions corresponding to the Console API)
247  */
250  BOOL (NTAPI *SetPalette)(IN OUT PTERMINAL This,
251  HPALETTE PaletteHandle,
253  INT (NTAPI *ShowMouseCursor)(IN OUT PTERMINAL This,
255 
256 #if 0 // Possible future terminal interface
257  BOOL (NTAPI *GetTerminalProperty)(IN OUT PTERMINAL This,
258  ULONG Flag,
259  PVOID Info,
260  ULONG Size);
261  BOOL (NTAPI *SetTerminalProperty)(IN OUT PTERMINAL This,
262  ULONG Flag,
263  PVOID Info /*,
264  ULONG Size */);
265 #endif
267 
268 struct _TERMINAL
269 {
270  PTERMINAL_VTBL Vtbl; /* Virtual table */
271  struct _CONSOLE* Console; /* Console to which the terminal is attached to */
272  PVOID Context; /* Private context */
273 };
274 
275 /*
276  * WARNING: Change the state of the console ONLY when the console is locked !
277  */
278 typedef enum _CONSOLE_STATE
279 {
280  CONSOLE_INITIALIZING, /* Console is initializing */
281  CONSOLE_RUNNING , /* Console running */
282  CONSOLE_TERMINATING , /* Console about to be destroyed (but still not) */
283  CONSOLE_IN_DESTRUCTION /* Console in destruction */
285 
286 typedef struct _CONSOLE
287 {
288 /******************************* Console Set-up *******************************/
289  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 */
291 
292  CONSOLE_STATE State; /* State of the console */
293  TERMINAL TermIFace; /* Terminal-specific interface */
294 
295  BOOLEAN ConsolePaused; /* If TRUE, the console is paused */
296 
297 /******************************** Input buffer ********************************/
298  CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
300 
301 /******************************* Screen buffers *******************************/
302  LIST_ENTRY BufferList; /* List of all screen buffers for this console */
303  PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
305 
306 /****************************** Other properties ******************************/
307  COORD ConsoleSize; /* The current size of the console, for text-mode only */
308  BOOLEAN FixedSize; /* TRUE if the console is of fixed size */
309  BOOLEAN IsCJK; /* TRUE if Chinese, Japanese or Korean (CJK) */
310 } CONSOLE, *PCONSOLE;
311 
312 /* console.c */
313 VOID NTAPI
315 VOID NTAPI
317 
318 #define GetConsoleInputBufferMode(Console) \
319  (Console)->InputBuffer.Mode
320 
321 
322 /* conoutput.c */
326  COORD Size);
327 
328 /* wcwidth.c */
329 int mk_wcwidth_cjk(wchar_t ucs);
330 
331 // NOTE: The check against 0x80 is to avoid calling the helper function
332 // for characters that we already know are not full-width.
333 #define IS_FULL_WIDTH(wch) \
334  (((USHORT)(wch) >= 0x0080) && (mk_wcwidth_cjk(wch) == 2))
335 
336 /* EOF */
struct _CONSOLE_INFO CONSOLE_INFO
CONSOLE_GRAPHICS_BUFFER_INFO Info
Definition: conio.h:142
BOOLEAN ForceCursorOff
Definition: conio.h:187
LONG ExclusiveWrite
Definition: conio.h:40
struct _GRAPHICS_BUFFER_INFO * PGRAPHICS_BUFFER_INFO
PCONSOLE_SCREEN_BUFFER SHORT SHORT OldCursorY
Definition: conio.h:237
HPALETTE PaletteHandle
Definition: conio.h:251
#define IN
Definition: typedefs.h:39
COORD ConsoleSize
Definition: conio.h:183
USHORT PopupDefaultAttrib
Definition: conio.h:132
ULONG InputBufferSize
Definition: conio.h:181
#define Y(I)
PTERMINAL_VTBL Vtbl
Definition: conio.h:270
BOOLEAN CursorBlinkOn
Definition: conio.h:72
PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
Definition: text.c:143
COORD ScreenBufferSize
Definition: conio.h:182
LONG ReferenceCount
Definition: conio.h:289
ULONG NumberOfEvents
Definition: conio.h:168
PCOORD pSize
Definition: conio.h:249
HANDLE ActiveEvent
Definition: conio.h:170
BOOLEAN ConsolePaused
Definition: conio.h:295
LONG NTSTATUS
Definition: precomp.h:26
PCONSOLE_SCREEN_BUFFER ScreenBuffer
Definition: conio.h:235
COORD CursorPosition
Definition: conio.h:71
BOOL Show
Definition: conio.h:254
IN BOOLEAN OUT PVOID IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl
Definition: conio.h:214
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
VOID NTAPI ConDrvUnpause(PCONSOLE Console)
Definition: console.c:313
LONG AccessRead
Definition: conio.h:39
BOOLEAN IsCursorVisible
Definition: conio.h:121
BOOLEAN IsCJK
Definition: conio.h:309
uint16_t * PWCHAR
Definition: typedefs.h:56
_In_ PVOID Parameter
Definition: ldrtypes.h:241
PCONSOLE_SCREEN_BUFFER ActiveBuffer
Definition: conio.h:303
USHORT PopupAttrib
Definition: conio.h:190
enum _CONSOLE_STATE * PCONSOLE_STATE
LONG AccessWrite
Definition: conio.h:39
COORD OldScreenBufferSize
Definition: conio.h:65
COORD ConsoleSize
Definition: conio.h:307
SMALL_RECT * Region
Definition: conio.h:233
CONSOLE_IO_OBJECT Header
Definition: conio.h:58
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
struct _CONSOLE_INPUT_BUFFER * PCONSOLE_INPUT_BUFFER
NTSTATUS ConioResizeBuffer(PCONSOLE Console, PTEXTMODE_SCREEN_BUFFER ScreenBuffer, COORD Size)
Definition: text.c:359
struct _CONSOLE * Console
Definition: conio.h:36
HPALETTE PaletteHandle
Definition: conio.h:78
BOOL(NTAPI *SetCursorInfo)(IN OUT PTERMINAL This
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PCONSOLE_SCREEN_BUFFER SHORT OldCursorX
Definition: conio.h:237
LPBITMAPINFO BitMapInfo
Definition: conio.h:150
struct _CONSOLE_SCREEN_BUFFER CONSOLE_SCREEN_BUFFER
COORD ScreenBufferSize
Definition: conio.h:62
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
short SHORT
Definition: pedump.c:59
INT(NTAPI *ShowMouseCursor)(IN OUT PTERMINAL This
ULONG CodePage
Definition: conio.h:192
LONG ReferenceCount
Definition: conio.h:37
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
unsigned char BOOLEAN
struct _CONSOLE_IO_OBJECT CONSOLE_IO_OBJECT
CONSOLE_STATE State
Definition: conio.h:292
NTSTATUS(NTAPI *InitTerminal)(IN OUT PTERMINAL This
struct _TERMINAL_VTBL * PTERMINAL_VTBL
struct _CONSOLE_IO_OBJECT * PCONSOLE_IO_OBJECT
BOOLEAN FixedSize
Definition: conio.h:308
IN BOOLEAN Unicode
Definition: conio.h:214
struct _CONSOLE_INFO * PCONSOLE_INFO
IN BOOLEAN OUT PVOID IN OUT PCONSOLE_READCONSOLE_CONTROL IN PVOID Parameter OPTIONAL
Definition: conio.h:214
UINT OutputCodePage
Definition: conio.h:304
struct _CONSOLE CONSOLE
LIST_ENTRY BufferList
Definition: conio.h:302
Definition: xml2sdb.h:79
VOID(NTAPI *DeinitTerminal)(IN OUT PTERMINAL This)
COORD WINAPI DECLSPEC_HOTPATCH GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
Definition: console.c:1675
unsigned long DWORD
Definition: ntddk_ex.h:95
CONSOLE_INPUT_BUFFER InputBuffer
Definition: conio.h:298
CONSOLE_IO_OBJECT Header
Definition: conio.h:165
struct _GRAPHICS_SCREEN_BUFFER * PGRAPHICS_SCREEN_BUFFER
IN BOOLEAN OUT PVOID IN OUT PCONSOLE_READCONSOLE_CONTROL IN PVOID Parameter IN ULONG NumCharsToRead
Definition: conio.h:214
struct _TERMINAL_VTBL TERMINAL_VTBL
TERMINAL TermIFace
Definition: conio.h:293
USHORT ScreenDefaultAttrib
Definition: conio.h:131
UINT InputCodePage
Definition: conio.h:299
Definition: typedefs.h:119
struct _TEXTMODE_SCREEN_BUFFER TEXTMODE_SCREEN_BUFFER
BOOLEAN ForceCursorOff
Definition: conio.h:73
BOOLEAN CursorBlinkOn
Definition: conio.h:186
Definition: bl.h:1338
static VOID SetActiveScreenBuffer(HANDLE ScreenBuffer)
Definition: video.c:439
struct _GRAPHICS_BUFFER_INFO GRAPHICS_BUFFER_INFO
USHORT PopupAttrib
Definition: conio.h:119
enum _CONSOLE_STATE CONSOLE_STATE
LIST_ENTRY ListEntry
Definition: conio.h:60
USHORT ScreenAttrib
Definition: conio.h:189
ULONG InputBufferSize
Definition: conio.h:167
struct _CONSOLE_INPUT_BUFFER CONSOLE_INPUT_BUFFER
PVOID Context
Definition: conio.h:272
CRITICAL_SECTION Lock
Definition: conio.h:290
IN PCONSOLE_SCREEN_BUFFER ScreenBuffer
Definition: conio.h:243
struct _TERMINAL * PTERMINAL
Definition: conio.h:196
unsigned short USHORT
Definition: pedump.c:61
PTEXTMODE_SCREEN_BUFFER PWCHAR DWORD BOOL Attrib
Definition: conio.h:222
_CONSOLE_IO_OBJECT_TYPE
Definition: conio.h:22
unsigned int * PULONG
Definition: retypes.h:1
IN BOOLEAN OUT PVOID Buffer
Definition: conio.h:214
unsigned int UINT
Definition: ndis.h:50
ULONG CursorSize
Definition: conio.h:185
PTEXTMODE_SCREEN_BUFFER Buff
Definition: conio.h:222
int mk_wcwidth_cjk(wchar_t ucs)
Definition: wcwidth.c:230
struct _TEXTMODE_BUFFER_INFO * PTEXTMODE_BUFFER_INFO
struct _CONSOLE * Console
Definition: conio.h:271
CConsole Console
PTEXTMODE_SCREEN_BUFFER PWCHAR DWORD Length
Definition: conio.h:222
PCHAR_INFO Buffer
Definition: conio.h:129
HANDLE ScreenBuffer
Definition: notevil.c:37
#define OUT
Definition: typedefs.h:40
CONSOLE_IO_OBJECT_TYPE Type
Definition: conio.h:34
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI ConDrvPause(PCONSOLE Console)
Definition: console.c:303
HPALETTE UINT PaletteUsage
Definition: conio.h:251
IN struct _CONSOLE * Console
Definition: conio.h:204
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:75
LIST_ENTRY InputEvents
Definition: conio.h:169
enum _CONSOLE_IO_OBJECT_TYPE CONSOLE_IO_OBJECT_TYPE
struct _TEXTMODE_SCREEN_BUFFER * PTEXTMODE_SCREEN_BUFFER
COORD ScreenBufferSize
Definition: conio.h:116
struct _TEXTMODE_BUFFER_INFO TEXTMODE_BUFFER_INFO
LONG ExclusiveRead
Definition: conio.h:40
struct _CONSOLE * PCONSOLE
struct _GRAPHICS_SCREEN_BUFFER GRAPHICS_SCREEN_BUFFER
static VOID DrawRegion(PGUI_CONSOLE_DATA GuiData, SMALL_RECT *Region)
Definition: guiterm.c:76
USHORT ScreenAttrib
Definition: conio.h:118