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 // This is ALMOST a HACK!!!!!!!
16 // Helpers for code refactoring
17 #ifdef USE_NEW_CONSOLE_WAY
19 #define _CONSRV_CONSOLE _WINSRV_CONSOLE
20 #define CONSRV_CONSOLE WINSRV_CONSOLE
21 #define PCONSRV_CONSOLE PWINSRV_CONSOLE
25 #define _CONSRV_CONSOLE _CONSOLE
26 #define CONSRV_CONSOLE CONSOLE
27 #define PCONSRV_CONSOLE PCONSOLE
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)
37 /* Object type magic numbers */
38 typedef enum _CONSOLE_IO_OBJECT_TYPE
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
46 } CONSOLE_IO_OBJECT_TYPE
;
48 typedef struct _CONSOLE_IO_OBJECT
50 CONSOLE_IO_OBJECT_TYPE Type
;
52 struct _CONSOLE
* /* PCONSOLE */ Console
;
53 LONG ReferenceCount
; /* Is incremented each time a console object gets referenced */
55 LONG AccessRead
, AccessWrite
;
56 LONG ExclusiveRead
, ExclusiveWrite
;
57 } CONSOLE_IO_OBJECT
, *PCONSOLE_IO_OBJECT
;
60 /******************************************************************************\
62 |* Abstract "class" for screen-buffers, be they text-mode or graphics *|
64 \******************************************************************************/
67 * See conoutput.c for the implementation
70 typedef struct _CONSOLE_SCREEN_BUFFER CONSOLE_SCREEN_BUFFER
,
71 *PCONSOLE_SCREEN_BUFFER
;
73 typedef struct _CONSOLE_SCREEN_BUFFER_VTBL
75 CONSOLE_IO_OBJECT_TYPE (*GetType
)(PCONSOLE_SCREEN_BUFFER This
);
76 } CONSOLE_SCREEN_BUFFER_VTBL
, *PCONSOLE_SCREEN_BUFFER_VTBL
;
78 #define GetType(This) (This)->Vtbl->GetType(This)
80 struct _CONSOLE_SCREEN_BUFFER
82 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
83 PCONSOLE_SCREEN_BUFFER_VTBL Vtbl
; /* Virtual table */
85 LIST_ENTRY ListEntry
; /* Entry in console's list of buffers */
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 */
90 COORD OldScreenBufferSize
; /* Old size of this screen buffer */
91 COORD OldViewSize
; /* Old associated view size */
93 COORD ViewOrigin
; /* Beginning offset for the actual display area */
95 /***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
96 USHORT VirtualY
; /* Top row of buffer being displayed, reported to callers */
98 COORD CursorPosition
; /* Current cursor position */
99 BOOLEAN CursorBlinkOn
;
100 BOOLEAN ForceCursorOff
;
102 CONSOLE_CURSOR_INFO CursorInfo
; // FIXME: Keep this member or not ??
103 /*********************************************/
105 HPALETTE PaletteHandle
; /* Handle to the color palette associated to this buffer */
106 UINT PaletteUsage
; /* The new use of the system palette. See SetSystemPaletteUse 'uUsage' parameter */
108 // WORD ScreenDefaultAttrib; /* Default screen char attribute */
109 // WORD PopupDefaultAttrib; /* Default popup char attribute */
110 USHORT Mode
; /* Output buffer modes */
115 /******************************************************************************\
117 |* Text-mode and graphics-mode screen-buffer "classes" *|
119 \******************************************************************************/
122 * See text.c for the implementation
125 /************************************************************************
126 * Screen buffer structure represents the win32 screen buffer object. *
127 * Internally, the portion of the buffer being shown CAN loop past the *
128 * bottom of the virtual buffer and wrap around to the top. Win32 does *
129 * not do this. I decided to do this because it eliminates the need to *
130 * do a massive memcpy() to scroll the contents of the buffer up to *
131 * scroll the screen on output, instead I just shift down the position *
132 * to be displayed, and let it wrap around to the top again. *
133 * The VirtualY member keeps track of the top Y coord that win32 *
134 * clients THINK is currently being displayed, because they think that *
135 * when the display reaches the bottom of the buffer and another line *
136 * being printed causes another line to scroll down, that the buffer IS *
137 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
138 * internally, I just wrap back to the top of the buffer. *
139 ************************************************************************/
141 typedef struct _TEXTMODE_BUFFER_INFO
143 COORD ScreenBufferSize
;
147 BOOLEAN IsCursorVisible
;
148 } TEXTMODE_BUFFER_INFO
, *PTEXTMODE_BUFFER_INFO
;
150 typedef struct _TEXTMODE_SCREEN_BUFFER
152 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
154 PCHAR_INFO Buffer
; /* Pointer to UNICODE screen buffer (Buffer->Char.UnicodeChar only is valid, not Char.AsciiChar) */
156 WORD ScreenDefaultAttrib
; /* Default screen char attribute */
157 WORD PopupDefaultAttrib
; /* Default popup char attribute */
158 } TEXTMODE_SCREEN_BUFFER
, *PTEXTMODE_SCREEN_BUFFER
;
162 * See graphics.c for the implementation
165 typedef struct _GRAPHICS_BUFFER_INFO
167 CONSOLE_GRAPHICS_BUFFER_INFO Info
;
168 } GRAPHICS_BUFFER_INFO
, *PGRAPHICS_BUFFER_INFO
;
170 typedef struct _GRAPHICS_SCREEN_BUFFER
172 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
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 */
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 */
184 } GRAPHICS_SCREEN_BUFFER
, *PGRAPHICS_SCREEN_BUFFER
;
188 typedef struct _CONSOLE_INPUT_BUFFER
190 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
192 ULONG InputBufferSize
; /* Size of this input buffer -- UNUSED!! */
193 LIST_ENTRY InputEvents
; /* List head for input event queue */
194 HANDLE ActiveEvent
; /* Event set when an input event is added in its queue */
196 USHORT Mode
; /* Input buffer modes */
197 } CONSOLE_INPUT_BUFFER
, *PCONSOLE_INPUT_BUFFER
;
200 typedef struct _TERMINAL TERMINAL
, *PTERMINAL
;
201 /* HACK: */ typedef struct _CONSOLE_INFO
*PCONSOLE_INFO
;
202 typedef struct _TERMINAL_VTBL
205 * Internal interface (functions called by the console server only)
207 NTSTATUS (NTAPI
*InitTerminal
)(IN OUT PTERMINAL This
,
208 IN
struct _CONSOLE
* Console
);
209 VOID (NTAPI
*DeinitTerminal
)(IN OUT PTERMINAL This
);
213 /************ Line discipline ***************/
215 /* Interface used only for text-mode screen buffers */
217 NTSTATUS (NTAPI
*ReadStream
)(IN OUT PTERMINAL This
,
221 IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl
,
222 IN PVOID Parameter OPTIONAL
,
223 IN ULONG NumCharsToRead
,
224 OUT PULONG NumCharsRead OPTIONAL
);
225 NTSTATUS (NTAPI
*WriteStream
)(IN OUT PTERMINAL This
,
226 PTEXTMODE_SCREEN_BUFFER Buff
,
231 /************ Line discipline ***************/
235 /* Interface used for both text-mode and graphics screen buffers */
236 VOID (NTAPI
*DrawRegion
)(IN OUT PTERMINAL This
,
238 BOOL (NTAPI
*SetCursorInfo
)(IN OUT PTERMINAL This
,
239 PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
240 BOOL (NTAPI
*SetScreenInfo
)(IN OUT PTERMINAL This
,
241 PCONSOLE_SCREEN_BUFFER ScreenBuffer
,
244 VOID (NTAPI
*ResizeTerminal
)(IN OUT PTERMINAL This
);
245 VOID (NTAPI
*SetActiveScreenBuffer
)(IN OUT PTERMINAL This
);
246 VOID (NTAPI
*ReleaseScreenBuffer
)(IN OUT PTERMINAL This
,
247 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
250 * External interface (functions corresponding to the Console API)
252 VOID (NTAPI
*GetLargestConsoleWindowSize
)(IN OUT PTERMINAL This
,
254 BOOL (NTAPI
*SetPalette
)(IN OUT PTERMINAL This
,
255 HPALETTE PaletteHandle
,
257 INT (NTAPI
*ShowMouseCursor
)(IN OUT PTERMINAL This
,
260 #if 0 // Possible future terminal interface
261 BOOL (NTAPI
*GetTerminalProperty
)(IN OUT PTERMINAL This
,
265 BOOL (NTAPI
*SetTerminalProperty
)(IN OUT PTERMINAL This
,
270 } TERMINAL_VTBL
, *PTERMINAL_VTBL
;
274 PTERMINAL_VTBL Vtbl
; /* Virtual table */
275 struct _CONSOLE
* Console
; /* Console to which the terminal is attached to */
276 PVOID Context
; /* Private context */
280 * WARNING: Change the state of the console ONLY when the console is locked !
282 typedef enum _CONSOLE_STATE
284 CONSOLE_INITIALIZING
, /* Console is initializing */
285 CONSOLE_RUNNING
, /* Console running */
286 CONSOLE_TERMINATING
, /* Console about to be destroyed (but still not) */
287 CONSOLE_IN_DESTRUCTION
/* Console in destruction */
288 } CONSOLE_STATE
, *PCONSOLE_STATE
;
292 /* HACK: */ typedef struct _CONSOLE
*PCONSOLE
;
293 #ifndef USE_NEW_CONSOLE_WAY
294 #include "conio_winsrv.h"
297 typedef struct _CONSOLE
299 /******************************* Console Set-up *******************************/
301 #ifndef USE_NEW_CONSOLE_WAY
302 WINSRV_CONSOLE
; // HACK HACK!!
305 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 */
306 CRITICAL_SECTION Lock
;
308 ULONG ConsoleID
; /* The ID of the console */
309 LIST_ENTRY ListEntry
; /* Entry in the list of consoles */
311 CONSOLE_STATE State
; /* State of the console */
312 TERMINAL TermIFace
; /* Terminal-specific interface */
314 HANDLE UnpauseEvent
; /* When != NULL, event for pausing the console */
316 /******************************** Input buffer ********************************/
317 CONSOLE_INPUT_BUFFER InputBuffer
; /* Input buffer of the console */
320 /******************************* Screen buffers *******************************/
321 LIST_ENTRY BufferList
; /* List of all screen buffers for this console */
322 PCONSOLE_SCREEN_BUFFER ActiveBuffer
; /* Pointer to currently active screen buffer */
325 /****************************** Other properties ******************************/
326 COORD ConsoleSize
; /* The current size of the console, for text-mode only */
327 BOOLEAN FixedSize
; /* TRUE if the console is of fixed size */
329 } CONSOLE
; // , *PCONSOLE;
333 ConDrvPause(PCONSOLE Console
);
335 ConDrvUnpause(PCONSOLE Console
);
338 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent
,
339 IN PCONSOLE_PROCESS_DATA ProcessData
);
342 #define GetConsoleInputBufferMode(Console) \
343 (Console)->InputBuffer.Mode
347 PCHAR_INFO
ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff
, ULONG X
, ULONG Y
);
348 NTSTATUS
ConioResizeBuffer(PCONSOLE
/*PCONSRV_CONSOLE*/ Console
,
349 PTEXTMODE_SCREEN_BUFFER ScreenBuffer
,