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
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
13 #define CSR_DEFAULT_CURSOR_SIZE 25
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)
20 /* Object type magic numbers */
21 typedef enum _CONSOLE_IO_OBJECT_TYPE
23 // ANY_TYPE_BUFFER = 0x00, // --> Match any types of IO handles
24 TEXTMODE_BUFFER
= 0x01, // --> Output-type handles for text SBs
25 GRAPHICS_BUFFER
= 0x02, // --> Output-type handles for graphics SBs
26 SCREEN_BUFFER
= 0x03, // --> Any SB type
27 INPUT_BUFFER
= 0x04 // --> Input-type handles
28 } CONSOLE_IO_OBJECT_TYPE
;
30 typedef struct _CONSOLE_IO_OBJECT
32 CONSOLE_IO_OBJECT_TYPE Type
;
33 struct _CONSOLE
* /* PCONSOLE */ Console
;
34 LONG AccessRead
, AccessWrite
;
35 LONG ExclusiveRead
, ExclusiveWrite
;
37 } CONSOLE_IO_OBJECT
, *PCONSOLE_IO_OBJECT
;
40 /******************************************************************************\
42 |* Abstract "class" for screen-buffers, be they text-mode or graphics *|
44 \******************************************************************************/
47 * See conoutput.c for the implementation
50 typedef struct _CONSOLE_SCREEN_BUFFER CONSOLE_SCREEN_BUFFER
,
51 *PCONSOLE_SCREEN_BUFFER
;
53 typedef struct _CONSOLE_SCREEN_BUFFER_VTBL
55 CONSOLE_IO_OBJECT_TYPE (*GetType
)(PCONSOLE_SCREEN_BUFFER This
);
56 } CONSOLE_SCREEN_BUFFER_VTBL
, *PCONSOLE_SCREEN_BUFFER_VTBL
;
58 #define GetType(This) (This)->Vtbl->GetType(This)
60 struct _CONSOLE_SCREEN_BUFFER
62 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
63 PCONSOLE_SCREEN_BUFFER_VTBL Vtbl
; /* Virtual table */
65 LIST_ENTRY ListEntry
; /* Entry in console's list of buffers */
67 // PVOID Data; /* Private data for the frontend to use */
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 */
97 /******************************************************************************\
99 |* Text-mode and graphics-mode screen-buffer "classes" *|
101 \******************************************************************************/
104 * See text.c for the implementation
107 /************************************************************************
108 * Screen buffer structure represents the win32 screen buffer object. *
109 * Internally, the portion of the buffer being shown CAN loop past the *
110 * bottom of the virtual buffer and wrap around to the top. Win32 does *
111 * not do this. I decided to do this because it eliminates the need to *
112 * do a massive memcpy() to scroll the contents of the buffer up to *
113 * scroll the screen on output, instead I just shift down the position *
114 * to be displayed, and let it wrap around to the top again. *
115 * The VirtualY member keeps track of the top Y coord that win32 *
116 * clients THINK is currently being displayed, because they think that *
117 * when the display reaches the bottom of the buffer and another line *
118 * being printed causes another line to scroll down, that the buffer IS *
119 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
120 * internally, I just wrap back to the top of the buffer. *
121 ************************************************************************/
123 typedef struct _TEXTMODE_BUFFER_INFO
125 COORD ScreenBufferSize
;
128 BOOLEAN IsCursorVisible
;
130 } TEXTMODE_BUFFER_INFO
, *PTEXTMODE_BUFFER_INFO
;
132 typedef struct _TEXTMODE_SCREEN_BUFFER
134 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
136 PCHAR_INFO Buffer
; /* Pointer to UNICODE screen buffer (Buffer->Char.UnicodeChar only is valid, not Char.AsciiChar) */
138 WORD ScreenDefaultAttrib
; /* Default screen char attribute */
139 WORD PopupDefaultAttrib
; /* Default popup char attribute */
140 } TEXTMODE_SCREEN_BUFFER
, *PTEXTMODE_SCREEN_BUFFER
;
144 * See graphics.c for the implementation
147 typedef struct _GRAPHICS_BUFFER_INFO
149 CONSOLE_GRAPHICS_BUFFER_INFO Info
;
150 } GRAPHICS_BUFFER_INFO
, *PGRAPHICS_BUFFER_INFO
;
152 typedef struct _GRAPHICS_SCREEN_BUFFER
154 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
156 ULONG BitMapInfoLength
; /* Real size of the structure pointed by BitMapInfo */
157 LPBITMAPINFO BitMapInfo
; /* Information on the bitmap buffer */
158 ULONG BitMapUsage
; /* See the uUsage parameter of GetDIBits */
159 HANDLE hSection
; /* Handle to the memory shared section for the bitmap buffer */
160 PVOID BitMap
; /* Our bitmap buffer */
161 PVOID ClientBitMap
; /* A copy of the client view of our bitmap buffer */
162 HANDLE Mutex
; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
163 HANDLE ClientMutex
; /* A copy of the client handle to our mutex */
164 HANDLE ClientProcess
; /* Handle to the client process who opened the buffer, to unmap the view */
165 } GRAPHICS_SCREEN_BUFFER
, *PGRAPHICS_SCREEN_BUFFER
;
169 typedef struct _CONSOLE_INPUT_BUFFER
171 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
173 ULONG InputBufferSize
; /* Size of this input buffer */
174 LIST_ENTRY InputEvents
; /* List head for input event queue */
175 HANDLE ActiveEvent
; /* Event set when an input event is added in its queue */
176 LIST_ENTRY ReadWaitQueue
; /* List head for the queue of read wait blocks */
178 USHORT Mode
; /* Input buffer modes */
179 } CONSOLE_INPUT_BUFFER
, *PCONSOLE_INPUT_BUFFER
;
182 typedef struct _FRONTEND FRONTEND
, *PFRONTEND
;
183 /* HACK: */ typedef struct _CONSOLE_INFO
*PCONSOLE_INFO
;
184 typedef struct _FRONTEND_VTBL
187 * Internal interface (functions called by the console server only)
189 NTSTATUS (NTAPI
*InitFrontEnd
)(IN OUT PFRONTEND This
,
190 IN
struct _CONSOLE
* Console
);
191 VOID (NTAPI
*DeinitFrontEnd
)(IN OUT PFRONTEND This
);
193 /* Interface used for both text-mode and graphics screen buffers */
194 VOID (NTAPI
*DrawRegion
)(IN OUT PFRONTEND This
,
196 /* Interface used only for text-mode screen buffers */
197 VOID (NTAPI
*WriteStream
)(IN OUT PFRONTEND This
,
204 BOOL (NTAPI
*SetCursorInfo
)(IN OUT PFRONTEND This
,
205 PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
206 BOOL (NTAPI
*SetScreenInfo
)(IN OUT PFRONTEND This
,
207 PCONSOLE_SCREEN_BUFFER ScreenBuffer
,
210 VOID (NTAPI
*ResizeTerminal
)(IN OUT PFRONTEND This
);
211 VOID (NTAPI
*SetActiveScreenBuffer
)(IN OUT PFRONTEND This
);
212 VOID (NTAPI
*ReleaseScreenBuffer
)(IN OUT PFRONTEND This
,
213 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
214 BOOL (NTAPI
*ProcessKeyCallback
)(IN OUT PFRONTEND This
,
220 VOID (NTAPI
*RefreshInternalInfo
)(IN OUT PFRONTEND This
);
223 * External interface (functions corresponding to the Console API)
225 VOID (NTAPI
*ChangeTitle
)(IN OUT PFRONTEND This
);
226 BOOL (NTAPI
*ChangeIcon
)(IN OUT PFRONTEND This
,
228 HWND (NTAPI
*GetConsoleWindowHandle
)(IN OUT PFRONTEND This
);
229 VOID (NTAPI
*GetLargestConsoleWindowSize
)(IN OUT PFRONTEND This
,
231 BOOL (NTAPI
*GetSelectionInfo
)(IN OUT PFRONTEND This
,
232 PCONSOLE_SELECTION_INFO pSelectionInfo
);
233 BOOL (NTAPI
*SetPalette
)(IN OUT PFRONTEND This
,
234 HPALETTE PaletteHandle
,
236 ULONG (NTAPI
*GetDisplayMode
)(IN OUT PFRONTEND This
);
237 BOOL (NTAPI
*SetDisplayMode
)(IN OUT PFRONTEND This
,
239 INT (NTAPI
*ShowMouseCursor
)(IN OUT PFRONTEND This
,
241 BOOL (NTAPI
*SetMouseCursor
)(IN OUT PFRONTEND This
,
242 HCURSOR CursorHandle
);
243 HMENU (NTAPI
*MenuControl
)(IN OUT PFRONTEND This
,
246 BOOL (NTAPI
*SetMenuClose
)(IN OUT PFRONTEND This
,
249 #if 0 // Possible future front-end interface
250 BOOL (NTAPI
*GetFrontEndProperty
)(IN OUT PFRONTEND This
,
254 BOOL (NTAPI
*SetFrontEndProperty
)(IN OUT PFRONTEND This
,
259 } FRONTEND_VTBL
, *PFRONTEND_VTBL
;
263 PFRONTEND_VTBL Vtbl
; /* Virtual table */
264 struct _CONSOLE
* Console
; /* Console to which the frontend is attached to */
265 PVOID Data
; /* Private data */
266 PVOID OldData
; /* Reserved */
270 * WARNING: Change the state of the console ONLY when the console is locked !
272 typedef enum _CONSOLE_STATE
274 CONSOLE_INITIALIZING
, /* Console is initializing */
275 CONSOLE_RUNNING
, /* Console running */
276 CONSOLE_TERMINATING
, /* Console about to be destroyed (but still not) */
277 CONSOLE_IN_DESTRUCTION
/* Console in destruction */
278 } CONSOLE_STATE
, *PCONSOLE_STATE
;
280 typedef struct _CONSOLE
282 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 */
283 CRITICAL_SECTION Lock
;
284 CONSOLE_STATE State
; /* State of the console */
286 LIST_ENTRY ProcessList
; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
287 PCONSOLE_PROCESS_DATA NotifiedLastCloseProcess
; /* Pointer to the unique process that needs to be notified when the console leader process is killed */
288 BOOLEAN NotifyLastClose
; /* TRUE if the console should send a control event when the console leader process is killed */
290 FRONTEND TermIFace
; /* Frontend-specific interface */
292 /**************************** Input buffer and data ***************************/
293 CONSOLE_INPUT_BUFFER InputBuffer
; /* Input buffer of the console */
295 /** Put those things in TEXTMODE_SCREEN_BUFFER ?? **/
296 PWCHAR LineBuffer
; /* Current line being input, in line buffered mode */
297 WORD LineMaxSize
; /* Maximum size of line in characters (including CR+LF) */
298 WORD LineSize
; /* Current size of line */
299 WORD LinePos
; /* Current position within line */
300 BOOLEAN LineComplete
; /* User pressed enter, ready to send back to client */
301 BOOLEAN LineUpPressed
;
302 BOOLEAN LineInsertToggle
; /* Replace character over cursor instead of inserting */
303 ULONG LineWakeupMask
; /* Bitmap of which control characters will end line input */
304 /***************************************************/
310 /******************************* Screen buffers *******************************/
311 LIST_ENTRY BufferList
; /* List of all screen buffers for this console */
312 PCONSOLE_SCREEN_BUFFER ActiveBuffer
; /* Pointer to currently active screen buffer */
315 LIST_ENTRY WriteWaitQueue
; /* List head for the queue of write wait blocks */
318 /**************************** Aliases and Histories ***************************/
319 struct _ALIAS_HEADER
*Aliases
;
320 LIST_ENTRY HistoryBuffers
;
321 ULONG HistoryBufferSize
; /* Size for newly created history buffers */
322 ULONG NumberOfHistoryBuffers
; /* Maximum number of history buffers allowed */
323 BOOLEAN HistoryNoDup
; /* Remove old duplicate history entries */
325 /****************************** Other properties ******************************/
326 UNICODE_STRING OriginalTitle
; /* Original title of console, the one defined when the console leader is launched; it never changes. Always NULL-terminated */
327 UNICODE_STRING Title
; /* Title of console. Always NULL-terminated */
329 COORD ConsoleSize
; /* The current size of the console, for text-mode only */
330 BOOLEAN FixedSize
; /* TRUE if the console is of fixed size */
332 COLORREF Colors
[16]; /* Colour palette */
334 } CONSOLE
, *PCONSOLE
;
336 /* PauseFlags values (internal only) */
337 #define PAUSED_FROM_KEYBOARD 0x1
338 #define PAUSED_FROM_SCROLLBAR 0x2
339 #define PAUSED_FROM_SELECTION 0x4
342 VOID FASTCALL
ConioPause(PCONSOLE Console
, UINT Flags
);
343 VOID FASTCALL
ConioUnpause(PCONSOLE Console
, UINT Flags
);
345 PCONSOLE_PROCESS_DATA NTAPI
346 ConDrvGetConsoleLeaderProcess(IN PCONSOLE Console
);
348 ConDrvConsoleCtrlEvent(IN ULONG CtrlEvent
,
349 IN PCONSOLE_PROCESS_DATA ProcessData
);
351 ConDrvConsoleProcessCtrlEvent(IN PCONSOLE Console
,
352 IN ULONG ProcessGroupId
,
356 VOID NTAPI
ConioProcessKey(PCONSOLE Console
, MSG
* msg
);
357 NTSTATUS FASTCALL
ConioAddInputEvent(PCONSOLE Console
,
358 PINPUT_RECORD InputEvent
,
359 BOOLEAN AppendToEnd
);
360 NTSTATUS FASTCALL
ConioProcessInputEvent(PCONSOLE Console
,
361 PINPUT_RECORD InputEvent
);
364 #define ConioInitRect(Rect, top, left, bottom, right) \
366 ((Rect)->Top) = top; \
367 ((Rect)->Left) = left; \
368 ((Rect)->Bottom) = bottom; \
369 ((Rect)->Right) = right; \
371 #define ConioIsRectEmpty(Rect) \
372 (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
373 #define ConioRectHeight(Rect) \
374 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
375 #define ConioRectWidth(Rect) \
376 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
378 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
379 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
381 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
382 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
384 PCHAR_INFO
ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff
, ULONG X
, ULONG Y
);
385 VOID FASTCALL
ConioDrawConsole(PCONSOLE Console
);
386 NTSTATUS
ConioResizeBuffer(PCONSOLE Console
,
387 PTEXTMODE_SCREEN_BUFFER ScreenBuffer
,
389 NTSTATUS
ConioWriteConsole(PCONSOLE Console
,
390 PTEXTMODE_SCREEN_BUFFER Buff
,
394 DWORD FASTCALL
ConioEffectiveCursorSize(PCONSOLE Console
,