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 /* 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)
21 /* Object type magic numbers */
22 typedef enum _CONSOLE_IO_OBJECT_TYPE
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
30 } CONSOLE_IO_OBJECT_TYPE
;
32 typedef struct _CONSOLE_IO_OBJECT
34 CONSOLE_IO_OBJECT_TYPE Type
;
36 struct _CONSOLE
* /* PCONSOLE */ Console
;
37 LONG ReferenceCount
; /* Is incremented each time a console object gets referenced */
39 LONG AccessRead
, AccessWrite
;
40 LONG ExclusiveRead
, ExclusiveWrite
;
41 } CONSOLE_IO_OBJECT
, *PCONSOLE_IO_OBJECT
;
44 /******************************************************************************\
46 |* Abstract "class" for screen-buffers, be they text-mode or graphics *|
48 \******************************************************************************/
51 * See conoutput.c for the implementation
54 typedef struct _CONSOLE_SCREEN_BUFFER CONSOLE_SCREEN_BUFFER
,
55 *PCONSOLE_SCREEN_BUFFER
;
57 typedef struct _CONSOLE_SCREEN_BUFFER_VTBL
59 CONSOLE_IO_OBJECT_TYPE (*GetType
)(PCONSOLE_SCREEN_BUFFER This
);
60 } CONSOLE_SCREEN_BUFFER_VTBL
, *PCONSOLE_SCREEN_BUFFER_VTBL
;
62 #define GetType(This) (This)->Vtbl->GetType(This)
64 struct _CONSOLE_SCREEN_BUFFER
66 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
67 PCONSOLE_SCREEN_BUFFER_VTBL Vtbl
; /* Virtual table */
69 LIST_ENTRY ListEntry
; /* Entry in console's list of buffers */
71 COORD ScreenBufferSize
; /* Size of this screen buffer. (Rows, Columns) for text-mode and (Width, Height) for graphics-mode */
72 COORD ViewSize
; /* Associated "view" (i.e. console) size */
74 COORD OldScreenBufferSize
; /* Old size of this screen buffer */
75 COORD OldViewSize
; /* Old associated view size */
77 COORD ViewOrigin
; /* Beginning offset for the actual display area */
79 /***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
80 USHORT VirtualY
; /* Top row of buffer being displayed, reported to callers */
82 COORD CursorPosition
; /* Current cursor position */
83 BOOLEAN CursorBlinkOn
;
84 BOOLEAN ForceCursorOff
;
86 CONSOLE_CURSOR_INFO CursorInfo
; // FIXME: Keep this member or not ??
87 /*********************************************/
89 HPALETTE PaletteHandle
; /* Handle to the color palette associated to this buffer */
90 UINT PaletteUsage
; /* The new use of the system palette. See SetSystemPaletteUse 'uUsage' parameter */
92 // WORD ScreenDefaultAttrib; /* Default screen char attribute */
93 // WORD PopupDefaultAttrib; /* Default popup char attribute */
94 USHORT Mode
; /* Output buffer modes */
96 // PVOID Data; /* Private data for the frontend to use */
101 /******************************************************************************\
103 |* Text-mode and graphics-mode screen-buffer "classes" *|
105 \******************************************************************************/
108 * See text.c for the implementation
111 /************************************************************************
112 * Screen buffer structure represents the win32 screen buffer object. *
113 * Internally, the portion of the buffer being shown CAN loop past the *
114 * bottom of the virtual buffer and wrap around to the top. Win32 does *
115 * not do this. I decided to do this because it eliminates the need to *
116 * do a massive memcpy() to scroll the contents of the buffer up to *
117 * scroll the screen on output, instead I just shift down the position *
118 * to be displayed, and let it wrap around to the top again. *
119 * The VirtualY member keeps track of the top Y coord that win32 *
120 * clients THINK is currently being displayed, because they think that *
121 * when the display reaches the bottom of the buffer and another line *
122 * being printed causes another line to scroll down, that the buffer IS *
123 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
124 * internally, I just wrap back to the top of the buffer. *
125 ************************************************************************/
127 typedef struct _TEXTMODE_BUFFER_INFO
129 COORD ScreenBufferSize
;
133 BOOLEAN IsCursorVisible
;
134 } TEXTMODE_BUFFER_INFO
, *PTEXTMODE_BUFFER_INFO
;
136 typedef struct _TEXTMODE_SCREEN_BUFFER
138 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
140 PCHAR_INFO Buffer
; /* Pointer to UNICODE screen buffer (Buffer->Char.UnicodeChar only is valid, not Char.AsciiChar) */
142 WORD ScreenDefaultAttrib
; /* Default screen char attribute */
143 WORD PopupDefaultAttrib
; /* Default popup char attribute */
144 } TEXTMODE_SCREEN_BUFFER
, *PTEXTMODE_SCREEN_BUFFER
;
148 * See graphics.c for the implementation
151 typedef struct _GRAPHICS_BUFFER_INFO
153 CONSOLE_GRAPHICS_BUFFER_INFO Info
;
154 } GRAPHICS_BUFFER_INFO
, *PGRAPHICS_BUFFER_INFO
;
156 typedef struct _GRAPHICS_SCREEN_BUFFER
158 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
160 ULONG BitMapInfoLength
; /* Real size of the structure pointed by BitMapInfo */
161 LPBITMAPINFO BitMapInfo
; /* Information on the bitmap buffer */
162 ULONG BitMapUsage
; /* See the uUsage parameter of GetDIBits */
163 HANDLE hSection
; /* Handle to the memory shared section for the bitmap buffer */
164 PVOID BitMap
; /* Our bitmap buffer */
166 PVOID ClientBitMap
; /* A copy of the client view of our bitmap buffer */
167 HANDLE Mutex
; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
168 HANDLE ClientMutex
; /* A copy of the client handle to our mutex */
169 HANDLE ClientProcess
; /* Handle to the client process who opened the buffer, to unmap the view */
170 } GRAPHICS_SCREEN_BUFFER
, *PGRAPHICS_SCREEN_BUFFER
;
174 typedef struct _CONSOLE_INPUT_BUFFER
176 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
178 ULONG InputBufferSize
; /* Size of this input buffer */
179 LIST_ENTRY InputEvents
; /* List head for input event queue */
180 HANDLE ActiveEvent
; /* Event set when an input event is added in its queue */
182 USHORT Mode
; /* Input buffer modes */
183 } CONSOLE_INPUT_BUFFER
, *PCONSOLE_INPUT_BUFFER
;
186 typedef struct _TERMINAL TERMINAL
, *PTERMINAL
;
187 /* HACK: */ typedef struct _CONSOLE_INFO
*PCONSOLE_INFO
;
188 typedef struct _TERMINAL_VTBL
191 * Internal interface (functions called by the console server only)
193 NTSTATUS (NTAPI
*InitTerminal
)(IN OUT PTERMINAL This
,
194 IN
struct _CONSOLE
* Console
);
195 VOID (NTAPI
*DeinitTerminal
)(IN OUT PTERMINAL This
);
197 /* Interface used for both text-mode and graphics screen buffers */
198 VOID (NTAPI
*DrawRegion
)(IN OUT PTERMINAL This
,
200 /* Interface used only for text-mode screen buffers */
201 VOID (NTAPI
*WriteStream
)(IN OUT PTERMINAL This
,
208 BOOL (NTAPI
*SetCursorInfo
)(IN OUT PTERMINAL This
,
209 PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
210 BOOL (NTAPI
*SetScreenInfo
)(IN OUT PTERMINAL This
,
211 PCONSOLE_SCREEN_BUFFER ScreenBuffer
,
214 VOID (NTAPI
*ResizeTerminal
)(IN OUT PTERMINAL This
);
215 VOID (NTAPI
*SetActiveScreenBuffer
)(IN OUT PTERMINAL This
);
216 VOID (NTAPI
*ReleaseScreenBuffer
)(IN OUT PTERMINAL This
,
217 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
220 * External interface (functions corresponding to the Console API)
222 VOID (NTAPI
*ChangeTitle
)(IN OUT PTERMINAL This
);
223 VOID (NTAPI
*GetLargestConsoleWindowSize
)(IN OUT PTERMINAL This
,
225 // BOOL (NTAPI *GetSelectionInfo)(IN OUT PTERMINAL This,
226 // PCONSOLE_SELECTION_INFO pSelectionInfo);
227 BOOL (NTAPI
*SetPalette
)(IN OUT PTERMINAL This
,
228 HPALETTE PaletteHandle
,
230 INT (NTAPI
*ShowMouseCursor
)(IN OUT PTERMINAL This
,
233 #if 0 // Possible future front-end interface
234 BOOL (NTAPI
*GetTerminalProperty
)(IN OUT PTERMINAL This
,
238 BOOL (NTAPI
*SetTerminalProperty
)(IN OUT PTERMINAL This
,
243 } TERMINAL_VTBL
, *PTERMINAL_VTBL
;
247 PTERMINAL_VTBL Vtbl
; /* Virtual table */
248 struct _CONSOLE
* Console
; /* Console to which the frontend is attached to */
249 PVOID Data
; /* Private data */
253 * WARNING: Change the state of the console ONLY when the console is locked !
255 typedef enum _CONSOLE_STATE
257 CONSOLE_INITIALIZING
, /* Console is initializing */
258 CONSOLE_RUNNING
, /* Console running */
259 CONSOLE_TERMINATING
, /* Console about to be destroyed (but still not) */
260 CONSOLE_IN_DESTRUCTION
/* Console in destruction */
261 } CONSOLE_STATE
, *PCONSOLE_STATE
;
265 /* HACK: */ typedef struct _CONSOLE
*PCONSOLE
;
266 #include "conio_winsrv.h"
268 typedef struct _CONSOLE
270 /******************************* Console Set-up *******************************/
271 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 */
272 CRITICAL_SECTION Lock
;
274 /**/WINSRV_CONSOLE
;/**/ // HACK HACK!!
276 CONSOLE_STATE State
; /* State of the console */
277 TERMINAL TermIFace
; /* Frontend-specific interface */
279 ULONG ConsoleID
; /* The ID of the console */
280 LIST_ENTRY ListEntry
; /* Entry in the list of consoles */
282 HANDLE UnpauseEvent
; /* When != NULL, event for pausing the console */
284 /******************************** Input buffer ********************************/
285 CONSOLE_INPUT_BUFFER InputBuffer
; /* Input buffer of the console */
288 /******************************* Screen buffers *******************************/
289 LIST_ENTRY BufferList
; /* List of all screen buffers for this console */
290 PCONSOLE_SCREEN_BUFFER ActiveBuffer
; /* Pointer to currently active screen buffer */
293 /****************************** Other properties ******************************/
294 UNICODE_STRING OriginalTitle
; /* Original title of console, the one defined when the console leader is launched; it never changes. Always NULL-terminated */
295 UNICODE_STRING Title
; /* Title of console. Always NULL-terminated */
297 COORD ConsoleSize
; /* The current size of the console, for text-mode only */
298 BOOLEAN FixedSize
; /* TRUE if the console is of fixed size */
300 } CONSOLE
; // , *PCONSOLE;
304 ConDrvPause(PCONSOLE Console
);
306 ConDrvUnpause(PCONSOLE Console
);
309 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent
,
310 IN PCONSOLE_PROCESS_DATA ProcessData
);
314 ConioAddInputEvents(PCONSOLE Console
,
315 PINPUT_RECORD InputRecords
,
316 ULONG NumEventsToWrite
,
317 PULONG NumEventsWritten
,
318 BOOLEAN AppendToEnd
);
320 ConioProcessInputEvent(PCONSOLE Console
,
321 PINPUT_RECORD InputEvent
);
327 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
328 * If they are the same, the function fails, and GetLastError returns
329 * ERROR_INVALID_PARAMETER."
331 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
332 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
333 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
335 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
336 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
337 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
339 PCHAR_INFO
ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff
, ULONG X
, ULONG Y
);
340 VOID
ConioDrawConsole(PCONSOLE Console
);
341 NTSTATUS
ConioResizeBuffer(PCONSOLE Console
,
342 PTEXTMODE_SCREEN_BUFFER ScreenBuffer
,
344 NTSTATUS
ConioWriteConsole(PCONSOLE Console
,
345 PTEXTMODE_SCREEN_BUFFER Buff
,