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