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 // 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 COORD ScreenBufferSize
; /* Size of this screen buffer. (Rows, Columns) for text-mode and (Width, Height) for graphics */
68 COORD ViewSize
; /* Associated "view" (i.e. console) size */
70 COORD OldScreenBufferSize
; /* Old size of this screen buffer */
71 COORD OldViewSize
; /* Old associated view size */
73 COORD ViewOrigin
; /* Beginning offset for the actual display area */
75 /***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
76 USHORT VirtualY
; /* Top row of buffer being displayed, reported to callers */
78 COORD CursorPosition
; /* Current cursor position */
79 BOOLEAN CursorBlinkOn
;
80 BOOLEAN ForceCursorOff
;
82 CONSOLE_CURSOR_INFO CursorInfo
; // FIXME: Keep this member or not ??
83 /*********************************************/
85 // WORD ScreenDefaultAttrib; /* Default screen char attribute */
86 // WORD PopupDefaultAttrib; /* Default popup char attribute */
87 USHORT Mode
; /* Output buffer modes */
92 /******************************************************************************\
94 |* Text-mode and graphics-mode screen-buffer "classes" *|
96 \******************************************************************************/
99 * See text.c for the implementation
102 /************************************************************************
103 * Screen buffer structure represents the win32 screen buffer object. *
104 * Internally, the portion of the buffer being shown CAN loop past the *
105 * bottom of the virtual buffer and wrap around to the top. Win32 does *
106 * not do this. I decided to do this because it eliminates the need to *
107 * do a massive memcpy() to scroll the contents of the buffer up to *
108 * scroll the screen on output, instead I just shift down the position *
109 * to be displayed, and let it wrap around to the top again. *
110 * The VirtualY member keeps track of the top Y coord that win32 *
111 * clients THINK is currently being displayed, because they think that *
112 * when the display reaches the bottom of the buffer and another line *
113 * being printed causes another line to scroll down, that the buffer IS *
114 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
115 * internally, I just wrap back to the top of the buffer. *
116 ************************************************************************/
118 typedef struct _TEXTMODE_BUFFER_INFO
120 COORD ScreenBufferSize
;
123 BOOLEAN IsCursorVisible
;
125 } TEXTMODE_BUFFER_INFO
, *PTEXTMODE_BUFFER_INFO
;
127 typedef struct _TEXTMODE_SCREEN_BUFFER
129 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
131 BYTE
*Buffer
; /* CHAR_INFO */ /* Pointer to screen buffer */
133 WORD ScreenDefaultAttrib
; /* Default screen char attribute */
134 WORD PopupDefaultAttrib
; /* Default popup char attribute */
135 } TEXTMODE_SCREEN_BUFFER
, *PTEXTMODE_SCREEN_BUFFER
;
139 * See graphics.c for the implementation
142 typedef struct _GRAPHICS_BUFFER_INFO
144 CONSOLE_GRAPHICS_BUFFER_INFO Info
;
145 } GRAPHICS_BUFFER_INFO
, *PGRAPHICS_BUFFER_INFO
;
147 typedef struct _GRAPHICS_SCREEN_BUFFER
149 CONSOLE_SCREEN_BUFFER
; /* Screen buffer base class - MUST BE IN FIRST PLACE */
151 ULONG BitMapInfoLength
; /* Real size of the structure pointed by BitMapInfo */
152 LPBITMAPINFO BitMapInfo
; /* Information on the bitmap buffer */
153 ULONG BitMapUsage
; /* See the uUsage parameter of GetDIBits */
154 HANDLE hSection
; /* Handle to the memory shared section for the bitmap buffer */
155 PVOID BitMap
; /* Our bitmap buffer */
156 PVOID ClientBitMap
; /* A copy of the client view of our bitmap buffer */
157 HANDLE Mutex
; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
158 HANDLE ClientMutex
; /* A copy of the client handle to our mutex */
159 HANDLE ClientProcess
; /* Handle to the client process who opened the buffer, to unmap the view */
160 } GRAPHICS_SCREEN_BUFFER
, *PGRAPHICS_SCREEN_BUFFER
;
164 typedef struct _CONSOLE_INPUT_BUFFER
166 CONSOLE_IO_OBJECT Header
; /* Object header - MUST BE IN FIRST PLACE */
168 ULONG InputBufferSize
; /* Size of this input buffer */
169 LIST_ENTRY InputEvents
; /* List head for input event queue */
170 HANDLE ActiveEvent
; /* Event set when an input event is added in its queue */
171 LIST_ENTRY ReadWaitQueue
; /* List head for the queue of read wait blocks */
173 USHORT Mode
; /* Input buffer modes */
174 } CONSOLE_INPUT_BUFFER
, *PCONSOLE_INPUT_BUFFER
;
176 typedef struct _FRONTEND_VTBL
179 * Internal interface (functions called by the console server only)
181 // BOOL (WINAPI *Init)();
182 VOID (WINAPI
*CleanupConsole
)(struct _CONSOLE
* Console
);
183 /* Interface used for both text-mode and graphics screen buffers */
184 VOID (WINAPI
*DrawRegion
)(struct _CONSOLE
* Console
,
186 /* Interface used only for text-mode screen buffers */
187 VOID (WINAPI
*WriteStream
)(struct _CONSOLE
* Console
,
194 BOOL (WINAPI
*SetCursorInfo
)(struct _CONSOLE
* Console
,
195 PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
196 BOOL (WINAPI
*SetScreenInfo
)(struct _CONSOLE
* Console
,
197 PCONSOLE_SCREEN_BUFFER ScreenBuffer
,
200 VOID (WINAPI
*ResizeTerminal
)(struct _CONSOLE
* Console
);
201 BOOL (WINAPI
*ProcessKeyCallback
)(struct _CONSOLE
* Console
,
207 VOID (WINAPI
*RefreshInternalInfo
)(struct _CONSOLE
* Console
);
210 * External interface (functions corresponding to the Console API)
212 VOID (WINAPI
*ChangeTitle
)(struct _CONSOLE
* Console
);
213 BOOL (WINAPI
*ChangeIcon
)(struct _CONSOLE
* Console
,
215 HWND (WINAPI
*GetConsoleWindowHandle
)(struct _CONSOLE
* Console
);
216 VOID (WINAPI
*GetLargestConsoleWindowSize
)(struct _CONSOLE
* Console
,
218 ULONG (WINAPI
*GetDisplayMode
)(struct _CONSOLE
* Console
);
219 BOOL (WINAPI
*SetDisplayMode
)(struct _CONSOLE
* Console
,
222 #if 0 // Possible future front-end interface
223 BOOL (WINAPI
*GetFrontEndProperty
)(struct _CONSOLE
* Console
,
227 BOOL (WINAPI
*SetFrontEndProperty
)(struct _CONSOLE
* Console
,
232 } FRONTEND_VTBL
, *PFRONTEND_VTBL
;
234 typedef struct _FRONTEND_IFACE
236 PFRONTEND_VTBL Vtbl
; /* Virtual table */
237 PVOID Data
; /* Private data */
238 PVOID OldData
; /* Reserved */
239 } FRONTEND_IFACE
, *PFRONTEND_IFACE
;
242 * WARNING: Change the state of the console ONLY when the console is locked !
244 typedef enum _CONSOLE_STATE
246 CONSOLE_INITIALIZING
, /* Console is initializing */
247 CONSOLE_RUNNING
, /* Console running */
248 CONSOLE_TERMINATING
, /* Console about to be destroyed (but still not) */
249 CONSOLE_IN_DESTRUCTION
/* Console in destruction */
250 } CONSOLE_STATE
, *PCONSOLE_STATE
;
252 typedef struct _CONSOLE
254 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 */
255 CRITICAL_SECTION Lock
;
256 CONSOLE_STATE State
; /* State of the console */
258 LIST_ENTRY Entry
; /* Entry in the list of consoles */
259 LIST_ENTRY ProcessList
; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
261 FRONTEND_IFACE TermIFace
; /* Frontend-specific interface */
263 /**************************** Input buffer and data ***************************/
264 CONSOLE_INPUT_BUFFER InputBuffer
; /* Input buffer of the console */
266 /** Put those things in TEXTMODE_SCREEN_BUFFER ?? **/
267 PWCHAR LineBuffer
; /* Current line being input, in line buffered mode */
268 WORD LineMaxSize
; /* Maximum size of line in characters (including CR+LF) */
269 WORD LineSize
; /* Current size of line */
270 WORD LinePos
; /* Current position within line */
271 BOOLEAN LineComplete
; /* User pressed enter, ready to send back to client */
272 BOOLEAN LineUpPressed
;
273 BOOLEAN LineInsertToggle
; /* Replace character over cursor instead of inserting */
274 ULONG LineWakeupMask
; /* Bitmap of which control characters will end line input */
275 /***************************************************/
282 CONSOLE_SELECTION_INFO Selection
; /* Contains information about the selection */
283 COORD dwSelectionCursor
; /* Selection cursor position, most of the time different from Selection.dwSelectionAnchor */
285 /******************************* Screen buffers *******************************/
286 LIST_ENTRY BufferList
; /* List of all screen buffers for this console */
287 PCONSOLE_SCREEN_BUFFER ActiveBuffer
; /* Pointer to currently active screen buffer */
290 LIST_ENTRY WriteWaitQueue
; /* List head for the queue of write wait blocks */
292 /**************************** Aliases and Histories ***************************/
293 struct _ALIAS_HEADER
*Aliases
;
294 LIST_ENTRY HistoryBuffers
;
295 ULONG HistoryBufferSize
; /* Size for newly created history buffers */
296 ULONG NumberOfHistoryBuffers
; /* Maximum number of history buffers allowed */
297 BOOLEAN HistoryNoDup
; /* Remove old duplicate history entries */
299 /****************************** Other properties ******************************/
300 UNICODE_STRING OriginalTitle
; /* Original title of console, the one defined when the console leader is launched; it never changes. Always NULL-terminated */
301 UNICODE_STRING Title
; /* Title of console. Always NULL-terminated */
303 COORD ConsoleSize
; /* The current size of the console, for text-mode only */
304 BOOLEAN FixedSize
; /* TRUE if the console is of fixed size */
306 COLORREF Colors
[16]; /* Colour palette */
308 } CONSOLE
, *PCONSOLE
;
310 /* PauseFlags values (internal only) */
311 #define PAUSED_FROM_KEYBOARD 0x1
312 #define PAUSED_FROM_SCROLLBAR 0x2
313 #define PAUSED_FROM_SELECTION 0x4
316 VOID FASTCALL
ConioPause(PCONSOLE Console
, UINT Flags
);
317 VOID FASTCALL
ConioUnpause(PCONSOLE Console
, UINT Flags
);
318 ULONG FASTCALL
ConSrvConsoleProcessCtrlEvent(PCONSOLE Console
,
319 ULONG ProcessGroupId
,
323 VOID WINAPI
ConioProcessKey(PCONSOLE Console
, MSG
* msg
);
324 NTSTATUS FASTCALL
ConioProcessInputEvent(PCONSOLE Console
,
325 PINPUT_RECORD InputEvent
);
328 #define ConioInitRect(Rect, top, left, bottom, right) \
330 ((Rect)->Top) = top; \
331 ((Rect)->Left) = left; \
332 ((Rect)->Bottom) = bottom; \
333 ((Rect)->Right) = right; \
335 #define ConioIsRectEmpty(Rect) \
336 (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
337 #define ConioRectHeight(Rect) \
338 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
339 #define ConioRectWidth(Rect) \
340 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
342 PBYTE
ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff
, ULONG X
, ULONG Y
);
343 VOID FASTCALL
ConioDrawConsole(PCONSOLE Console
);
344 NTSTATUS
ConioResizeBuffer(PCONSOLE Console
,
345 PTEXTMODE_SCREEN_BUFFER ScreenBuffer
,
347 NTSTATUS
ConioWriteConsole(PCONSOLE Console
,
348 PTEXTMODE_SCREEN_BUFFER Buff
,
352 DWORD FASTCALL
ConioEffectiveCursorSize(PCONSOLE Console
,