2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: consrv/include/conio.h
5 * PURPOSE: Public Console I/O Interface
6 * PROGRAMMERS: Gé van Geldorp
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
15 #define CSR_DEFAULT_CURSOR_SIZE 25
17 /* Default attributes */
18 #define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
19 #define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
20 BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
22 /* Object type magic numbers */
23 typedef enum _CONSOLE_IO_OBJECT_TYPE
25 // ANY_TYPE_BUFFER = 0x00, // --> Match any types of IO handles
26 TEXTMODE_BUFFER
= 0x01, // --> Output-type handles for text SBs
27 GRAPHICS_BUFFER
= 0x02, // --> Output-type handles for graphics SBs
28 SCREEN_BUFFER
= 0x03, // --> Any SB type
29 INPUT_BUFFER
= 0x04 // --> Input-type handles
30 } CONSOLE_IO_OBJECT_TYPE
;
32 typedef struct _CONSOLE_IO_OBJECT
34 CONSOLE_IO_OBJECT_TYPE Type
;
35 struct _CONSOLE
* /* PCONSOLE */ Console
;
36 LONG AccessRead
, AccessWrite
;
37 LONG ExclusiveRead
, ExclusiveWrite
;
39 } CONSOLE_IO_OBJECT
, *PCONSOLE_IO_OBJECT
;
42 /******************************************************************************\
44 |* Abstract "class" for screen-buffers, be they text-mode or graphics *|
46 \******************************************************************************/
49 * See conoutput.c for the implementation
52 typedef struct _CONSOLE_SCREEN_BUFFER CONSOLE_SCREEN_BUFFER
,
53 *PCONSOLE_SCREEN_BUFFER
;
55 typedef struct _CONSOLE_SCREEN_BUFFER_VTBL
57 CONSOLE_IO_OBJECT_TYPE (*GetType
)(PCONSOLE_SCREEN_BUFFER This
);
58 } CONSOLE_SCREEN_BUFFER_VTBL
, *PCONSOLE_SCREEN_BUFFER_VTBL
;
60 #define GetType(This) (This)->Vtbl->GetType(This)
62 struct _CONSOLE_SCREEN_BUFFER
64 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
65 PCONSOLE_SCREEN_BUFFER_VTBL Vtbl
; /* Virtual table */
67 LIST_ENTRY ListEntry
; /* Entry in console's list of buffers */
69 COORD ScreenBufferSize
; /* Size of this screen buffer. (Rows, Columns) for text-mode and (Width, Height) for graphics-mode */
70 COORD ViewSize
; /* Associated "view" (i.e. console) size */
72 COORD OldScreenBufferSize
; /* Old size of this screen buffer */
73 COORD OldViewSize
; /* Old associated view size */
75 COORD ViewOrigin
; /* Beginning offset for the actual display area */
77 /***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
78 USHORT VirtualY
; /* Top row of buffer being displayed, reported to callers */
80 COORD CursorPosition
; /* Current cursor position */
81 BOOLEAN CursorBlinkOn
;
82 BOOLEAN ForceCursorOff
;
84 CONSOLE_CURSOR_INFO CursorInfo
; // FIXME: Keep this member or not ??
85 /*********************************************/
87 HPALETTE PaletteHandle
; /* Handle to the color palette associated to this buffer */
88 UINT PaletteUsage
; /* The new use of the system palette. See SetSystemPaletteUse 'uUsage' parameter */
90 // WORD ScreenDefaultAttrib; /* Default screen char attribute */
91 // WORD PopupDefaultAttrib; /* Default popup char attribute */
92 USHORT Mode
; /* Output buffer modes */
94 // PVOID Data; /* Private data for the frontend to use */
99 /******************************************************************************\
101 |* Text-mode and graphics-mode screen-buffer "classes" *|
103 \******************************************************************************/
106 * See text.c for the implementation
109 /************************************************************************
110 * Screen buffer structure represents the win32 screen buffer object. *
111 * Internally, the portion of the buffer being shown CAN loop past the *
112 * bottom of the virtual buffer and wrap around to the top. Win32 does *
113 * not do this. I decided to do this because it eliminates the need to *
114 * do a massive memcpy() to scroll the contents of the buffer up to *
115 * scroll the screen on output, instead I just shift down the position *
116 * to be displayed, and let it wrap around to the top again. *
117 * The VirtualY member keeps track of the top Y coord that win32 *
118 * clients THINK is currently being displayed, because they think that *
119 * when the display reaches the bottom of the buffer and another line *
120 * being printed causes another line to scroll down, that the buffer IS *
121 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
122 * internally, I just wrap back to the top of the buffer. *
123 ************************************************************************/
125 typedef struct _TEXTMODE_BUFFER_INFO
127 COORD ScreenBufferSize
;
131 BOOLEAN IsCursorVisible
;
132 } TEXTMODE_BUFFER_INFO
, *PTEXTMODE_BUFFER_INFO
;
134 typedef struct _TEXTMODE_SCREEN_BUFFER
136 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
138 PCHAR_INFO Buffer
; /* Pointer to UNICODE screen buffer (Buffer->Char.UnicodeChar only is valid, not Char.AsciiChar) */
140 WORD ScreenDefaultAttrib
; /* Default screen char attribute */
141 WORD PopupDefaultAttrib
; /* Default popup char attribute */
142 } TEXTMODE_SCREEN_BUFFER
, *PTEXTMODE_SCREEN_BUFFER
;
146 * See graphics.c for the implementation
149 typedef struct _GRAPHICS_BUFFER_INFO
151 CONSOLE_GRAPHICS_BUFFER_INFO Info
;
152 } GRAPHICS_BUFFER_INFO
, *PGRAPHICS_BUFFER_INFO
;
154 typedef struct _GRAPHICS_SCREEN_BUFFER
156 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
158 ULONG BitMapInfoLength
; /* Real size of the structure pointed by BitMapInfo */
159 LPBITMAPINFO BitMapInfo
; /* Information on the bitmap buffer */
160 ULONG BitMapUsage
; /* See the uUsage parameter of GetDIBits */
161 HANDLE hSection
; /* Handle to the memory shared section for the bitmap buffer */
162 PVOID BitMap
; /* Our bitmap buffer */
164 PVOID ClientBitMap
; /* A copy of the client view of our bitmap buffer */
165 HANDLE Mutex
; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
166 HANDLE ClientMutex
; /* A copy of the client handle to our mutex */
167 HANDLE ClientProcess
; /* Handle to the client process who opened the buffer, to unmap the view */
168 } GRAPHICS_SCREEN_BUFFER
, *PGRAPHICS_SCREEN_BUFFER
;
172 typedef struct _CONSOLE_INPUT_BUFFER
174 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
176 ULONG InputBufferSize
; /* Size of this input buffer */
177 LIST_ENTRY InputEvents
; /* List head for input event queue */
178 HANDLE ActiveEvent
; /* Event set when an input event is added in its queue */
180 USHORT Mode
; /* Input buffer modes */
181 } CONSOLE_INPUT_BUFFER
, *PCONSOLE_INPUT_BUFFER
;
184 typedef struct _TERMINAL TERMINAL
, *PTERMINAL
;
185 /* HACK: */ typedef struct _CONSOLE_INFO
*PCONSOLE_INFO
;
186 typedef struct _TERMINAL_VTBL
189 * Internal interface (functions called by the console server only)
191 NTSTATUS (NTAPI
*InitTerminal
)(IN OUT PTERMINAL This
,
192 IN
struct _CONSOLE
* Console
);
193 VOID (NTAPI
*DeinitTerminal
)(IN OUT PTERMINAL This
);
195 /* Interface used for both text-mode and graphics screen buffers */
196 VOID (NTAPI
*DrawRegion
)(IN OUT PTERMINAL This
,
198 /* Interface used only for text-mode screen buffers */
199 VOID (NTAPI
*WriteStream
)(IN OUT PTERMINAL This
,
206 BOOL (NTAPI
*SetCursorInfo
)(IN OUT PTERMINAL This
,
207 PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
208 BOOL (NTAPI
*SetScreenInfo
)(IN OUT PTERMINAL This
,
209 PCONSOLE_SCREEN_BUFFER ScreenBuffer
,
212 VOID (NTAPI
*ResizeTerminal
)(IN OUT PTERMINAL This
);
213 VOID (NTAPI
*SetActiveScreenBuffer
)(IN OUT PTERMINAL This
);
214 VOID (NTAPI
*ReleaseScreenBuffer
)(IN OUT PTERMINAL This
,
215 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
218 * External interface (functions corresponding to the Console API)
220 VOID (NTAPI
*ChangeTitle
)(IN OUT PTERMINAL This
);
221 VOID (NTAPI
*GetLargestConsoleWindowSize
)(IN OUT PTERMINAL This
,
223 // BOOL (NTAPI *GetSelectionInfo)(IN OUT PTERMINAL This,
224 // PCONSOLE_SELECTION_INFO pSelectionInfo);
225 BOOL (NTAPI
*SetPalette
)(IN OUT PTERMINAL This
,
226 HPALETTE PaletteHandle
,
228 INT (NTAPI
*ShowMouseCursor
)(IN OUT PTERMINAL This
,
231 #if 0 // Possible future front-end interface
232 BOOL (NTAPI
*GetTerminalProperty
)(IN OUT PTERMINAL This
,
236 BOOL (NTAPI
*SetTerminalProperty
)(IN OUT PTERMINAL This
,
241 } TERMINAL_VTBL
, *PTERMINAL_VTBL
;
245 PTERMINAL_VTBL Vtbl
; /* Virtual table */
246 struct _CONSOLE
* Console
; /* Console to which the frontend is attached to */
247 PVOID Data
; /* Private data */
251 * WARNING: Change the state of the console ONLY when the console is locked !
253 typedef enum _CONSOLE_STATE
255 CONSOLE_INITIALIZING
, /* Console is initializing */
256 CONSOLE_RUNNING
, /* Console running */
257 CONSOLE_TERMINATING
, /* Console about to be destroyed (but still not) */
258 CONSOLE_IN_DESTRUCTION
/* Console in destruction */
259 } CONSOLE_STATE
, *PCONSOLE_STATE
;
263 struct _WINSRV_CONSOLE
;
264 /* HACK: */ typedef struct _CONSOLE
*PCONSOLE
;
265 #include "conio_winsrv.h"
267 typedef struct _CONSOLE
269 /******************************* Console Set-up *******************************/
270 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 */
271 CRITICAL_SECTION Lock
;
273 /**/WINSRV_CONSOLE
;/**/ // HACK HACK!!
275 CONSOLE_STATE State
; /* State of the console */
276 TERMINAL TermIFace
; /* Frontend-specific interface */
278 ULONG ConsoleID
; /* The ID of the console */
279 LIST_ENTRY ListEntry
; /* Entry in the list of consoles */
281 /**************************** Input buffer and data ***************************/
282 CONSOLE_INPUT_BUFFER InputBuffer
; /* Input buffer of the console */
285 /** Put those things in CONSOLE_INPUT_BUFFER ?? **/
286 PWCHAR LineBuffer
; /* Current line being input, in line buffered mode */
287 ULONG LineMaxSize
; /* Maximum size of line in characters (including CR+LF) */
288 ULONG LineSize
; /* Current size of line */
289 ULONG LinePos
; /* Current position within line */
290 BOOLEAN LineComplete
; /* User pressed enter, ready to send back to client */
291 BOOLEAN LineUpPressed
;
292 BOOLEAN LineInsertToggle
; /* Replace character over cursor instead of inserting */
293 ULONG LineWakeupMask
; /* Bitmap of which control characters will end line input */
294 /*************************************************/
298 /******************************* Screen buffers *******************************/
299 LIST_ENTRY BufferList
; /* List of all screen buffers for this console */
300 PCONSOLE_SCREEN_BUFFER ActiveBuffer
; /* Pointer to currently active screen buffer */
303 /****************************** Other properties ******************************/
304 UNICODE_STRING OriginalTitle
; /* Original title of console, the one defined when the console leader is launched; it never changes. Always NULL-terminated */
305 UNICODE_STRING Title
; /* Title of console. Always NULL-terminated */
307 HANDLE UnpauseEvent
; /* When != NULL, event for pausing the console */
309 COORD ConsoleSize
; /* The current size of the console, for text-mode only */
310 BOOLEAN FixedSize
; /* TRUE if the console is of fixed size */
312 COLORREF Colors
[16]; /* Colour palette */
314 } CONSOLE
; // , *PCONSOLE;
316 // #include "conio_winsrv.h"
320 ConDrvPause(PCONSOLE Console
);
322 ConDrvUnpause(PCONSOLE Console
);
324 PCONSOLE_PROCESS_DATA NTAPI
325 ConSrvGetConsoleLeaderProcess(IN PCONSOLE Console
);
327 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent
,
328 IN PCONSOLE_PROCESS_DATA ProcessData
);
330 ConSrvConsoleProcessCtrlEvent(IN PCONSOLE Console
,
331 IN ULONG ProcessGroupId
,
335 VOID NTAPI
ConioProcessKey(PCONSOLE Console
, MSG
* msg
);
337 ConioAddInputEvents(PCONSOLE Console
,
338 PINPUT_RECORD InputRecords
,
339 ULONG NumEventsToWrite
,
340 PULONG NumEventsWritten
,
341 BOOLEAN AppendToEnd
);
343 ConioProcessInputEvent(PCONSOLE Console
,
344 PINPUT_RECORD InputEvent
);
350 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
351 * If they are the same, the function fails, and GetLastError returns
352 * ERROR_INVALID_PARAMETER."
354 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
355 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
356 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
358 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
359 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
360 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
362 PCHAR_INFO
ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff
, ULONG X
, ULONG Y
);
363 VOID
ConioDrawConsole(PCONSOLE Console
);
364 NTSTATUS
ConioResizeBuffer(PCONSOLE Console
,
365 PTEXTMODE_SCREEN_BUFFER ScreenBuffer
,
367 NTSTATUS
ConioWriteConsole(PCONSOLE Console
,
368 PTEXTMODE_SCREEN_BUFFER Buff
,
372 DWORD
ConioEffectiveCursorSize(PCONSOLE Console
,