2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/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 INPUT_BUFFER
= 0x01, // --> Input-type handles
24 SCREEN_BUFFER
= 0x02 // --> Output-type handles
25 } CONSOLE_IO_OBJECT_TYPE
;
27 typedef struct _CONSOLE_IO_OBJECT
29 CONSOLE_IO_OBJECT_TYPE Type
;
30 struct _CONSOLE
* /* PCONSOLE */ Console
;
31 LONG AccessRead
, AccessWrite
;
32 LONG ExclusiveRead
, ExclusiveWrite
;
34 } CONSOLE_IO_OBJECT
, *PCONSOLE_IO_OBJECT
;
36 /************************************************************************
37 * Screen buffer structure represents the win32 screen buffer object. *
38 * Internally, the portion of the buffer being shown CAN loop past the *
39 * bottom of the virtual buffer and wrap around to the top. Win32 does *
40 * not do this. I decided to do this because it eliminates the need to *
41 * do a massive memcpy() to scroll the contents of the buffer up to *
42 * scroll the screen on output, instead I just shift down the position *
43 * to be displayed, and let it wrap around to the top again. *
44 * The VirtualY member keeps track of the top Y coord that win32 *
45 * clients THINK is currently being displayed, because they think that *
46 * when the display reaches the bottom of the buffer and another line *
47 * being printed causes another line to scroll down, that the buffer IS *
48 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
49 * internally, I just wrap back to the top of the buffer. *
50 ************************************************************************/
52 typedef struct _CONSOLE_SCREEN_BUFFER
54 CONSOLE_IO_OBJECT Header
; /* Object header */
55 LIST_ENTRY ListEntry
; /* Entry in console's list of buffers */
57 BYTE
*Buffer
; /* CHAR_INFO */ /* Pointer to screen buffer */
59 COORD ScreenBufferSize
; /* Size of this screen buffer */
60 COORD CursorPosition
; /* Current cursor position */
62 USHORT ShowX
, ShowY
; /* Beginning offset for the actual display area */
63 USHORT VirtualY
; /* Top row of buffer being displayed, reported to callers */
65 BOOLEAN CursorBlinkOn
;
66 BOOLEAN ForceCursorOff
;
68 CONSOLE_CURSOR_INFO CursorInfo
; // FIXME: Keep this member or not ??
70 WORD ScreenDefaultAttrib
; /* Default screen char attribute */
71 WORD PopupDefaultAttrib
; /* Default popup char attribute */
74 } CONSOLE_SCREEN_BUFFER
, *PCONSOLE_SCREEN_BUFFER
;
76 typedef struct _CONSOLE_INPUT_BUFFER
78 CONSOLE_IO_OBJECT Header
; /* Object header */
80 ULONG InputBufferSize
; /* Size of this input buffer */
81 LIST_ENTRY InputEvents
; /* List head for input event queue */
82 HANDLE ActiveEvent
; /* Event set when an input event is added in its queue */
83 LIST_ENTRY ReadWaitQueue
; /* List head for the queue of read wait blocks */
85 USHORT Mode
; /* Console Input Buffer mode flags */
86 } CONSOLE_INPUT_BUFFER
, *PCONSOLE_INPUT_BUFFER
;
88 typedef struct _FRONTEND_VTBL
91 * Internal interface (functions called by the console server only)
93 VOID (WINAPI
*CleanupConsole
)(struct _CONSOLE
* Console
);
94 VOID (WINAPI
*WriteStream
)(struct _CONSOLE
* Console
,
101 VOID (WINAPI
*DrawRegion
)(struct _CONSOLE
* Console
,
103 BOOL (WINAPI
*SetCursorInfo
)(struct _CONSOLE
* Console
,
104 PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
105 BOOL (WINAPI
*SetScreenInfo
)(struct _CONSOLE
* Console
,
106 PCONSOLE_SCREEN_BUFFER ScreenBuffer
,
109 BOOL (WINAPI
*UpdateScreenInfo
)(struct _CONSOLE
* Console
,
110 PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
111 BOOL (WINAPI
*IsBufferResizeSupported
)(struct _CONSOLE
* Console
);
112 VOID (WINAPI
*ResizeTerminal
)(struct _CONSOLE
* Console
);
113 BOOL (WINAPI
*ProcessKeyCallback
)(struct _CONSOLE
* Console
,
119 VOID (WINAPI
*RefreshInternalInfo
)(struct _CONSOLE
* Console
);
122 * External interface (functions corresponding to the Console API)
124 VOID (WINAPI
*ChangeTitle
)(struct _CONSOLE
* Console
);
125 BOOL (WINAPI
*ChangeIcon
)(struct _CONSOLE
* Console
,
127 HWND (WINAPI
*GetConsoleWindowHandle
)(struct _CONSOLE
* Console
);
128 VOID (WINAPI
*GetLargestConsoleWindowSize
)(struct _CONSOLE
* Console
,
131 } FRONTEND_VTBL
, *PFRONTEND_VTBL
;
133 typedef struct _FRONTEND_IFACE
135 PFRONTEND_VTBL Vtbl
; /* Virtual table */
136 PVOID Data
; /* Private data */
137 PVOID OldData
; /* Reserved */
138 } FRONTEND_IFACE
, *PFRONTEND_IFACE
;
141 * WARNING: Change the state of the console ONLY when the console is locked !
143 typedef enum _CONSOLE_STATE
145 CONSOLE_INITIALIZING
, /* Console is initializing */
146 CONSOLE_RUNNING
, /* Console running */
147 CONSOLE_TERMINATING
, /* Console about to be destroyed (but still not) */
148 CONSOLE_IN_DESTRUCTION
/* Console in destruction */
149 } CONSOLE_STATE
, *PCONSOLE_STATE
;
151 typedef struct _CONSOLE
153 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 */
154 CRITICAL_SECTION Lock
;
155 CONSOLE_STATE State
; /* State of the console */
157 LIST_ENTRY Entry
; /* Entry in the list of consoles */
158 LIST_ENTRY ProcessList
; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
160 FRONTEND_IFACE TermIFace
; /* Frontend-specific interface */
162 /**************************** Input buffer and data ***************************/
163 CONSOLE_INPUT_BUFFER InputBuffer
; /* Input buffer of the console */
165 PWCHAR LineBuffer
; /* Current line being input, in line buffered mode */
166 WORD LineMaxSize
; /* Maximum size of line in characters (including CR+LF) */
167 WORD LineSize
; /* Current size of line */
168 WORD LinePos
; /* Current position within line */
169 BOOLEAN LineComplete
; /* User pressed enter, ready to send back to client */
170 BOOLEAN LineUpPressed
;
171 BOOLEAN LineInsertToggle
; /* Replace character over cursor instead of inserting */
172 ULONG LineWakeupMask
; /* Bitmap of which control characters will end line input */
179 CONSOLE_SELECTION_INFO Selection
; /* Contains information about the selection */
180 COORD dwSelectionCursor
; /* Selection cursor position, most of the time different from Selection.dwSelectionAnchor */
182 /******************************* Screen buffers *******************************/
183 LIST_ENTRY BufferList
; /* List of all screen buffers for this console */
184 PCONSOLE_SCREEN_BUFFER ActiveBuffer
; /* Pointer to currently active screen buffer */
187 LIST_ENTRY WriteWaitQueue
; /* List head for the queue of write wait blocks */
189 ULONG HardwareState
; /* _GDI_MANAGED, _DIRECT */
191 /**************************** Aliases and Histories ***************************/
192 struct _ALIAS_HEADER
*Aliases
;
193 LIST_ENTRY HistoryBuffers
;
194 ULONG HistoryBufferSize
; /* Size for newly created history buffers */
195 ULONG NumberOfHistoryBuffers
; /* Maximum number of history buffers allowed */
196 BOOLEAN HistoryNoDup
; /* Remove old duplicate history entries */
198 /****************************** Other properties ******************************/
199 UNICODE_STRING OriginalTitle
; /* Original title of console, the one when the console leader is launched. Always NULL-terminated */
200 UNICODE_STRING Title
; /* Title of console. Always NULL-terminated */
202 /* SIZE */ COORD ConsoleSize
; /* The size of the console */
203 COLORREF Colors
[16]; /* Colour palette */
205 } CONSOLE
, *PCONSOLE
;
207 /* PauseFlags values (internal only) */
208 #define PAUSED_FROM_KEYBOARD 0x1
209 #define PAUSED_FROM_SCROLLBAR 0x2
210 #define PAUSED_FROM_SELECTION 0x4
213 VOID FASTCALL
ConioPause(PCONSOLE Console
, UINT Flags
);
214 VOID FASTCALL
ConioUnpause(PCONSOLE Console
, UINT Flags
);
215 ULONG FASTCALL
ConSrvConsoleProcessCtrlEvent(PCONSOLE Console
,
216 ULONG ProcessGroupId
,
220 VOID WINAPI
ConioProcessKey(PCONSOLE Console
, MSG
* msg
);
221 NTSTATUS FASTCALL
ConioProcessInputEvent(PCONSOLE Console
,
222 PINPUT_RECORD InputEvent
);
225 #define ConioRectHeight(Rect) \
226 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
227 #define ConioRectWidth(Rect) \
228 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
230 PBYTE FASTCALL
ConioCoordToPointer(PCONSOLE_SCREEN_BUFFER Buf
,
233 VOID FASTCALL
ConioDrawConsole(PCONSOLE Console
);
234 NTSTATUS FASTCALL
ConioResizeBuffer(PCONSOLE Console
,
235 PCONSOLE_SCREEN_BUFFER ScreenBuffer
,
237 NTSTATUS FASTCALL
ConioWriteConsole(PCONSOLE Console
,
238 PCONSOLE_SCREEN_BUFFER Buff
,
242 DWORD FASTCALL
ConioEffectiveCursorSize(PCONSOLE Console
,