[CONSOLE.CPL-KERNEL32]
[reactos.git] / reactos / win32ss / user / consrv / include / conio.h
1 /*
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
7 * Jeffrey Morlan
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 */
10
11 #pragma once
12
13 #define CSR_DEFAULT_CURSOR_SIZE 25
14
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)
19
20 /* Object type magic numbers */
21 typedef enum _CONSOLE_IO_OBJECT_TYPE
22 {
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;
29
30 typedef struct _CONSOLE_IO_OBJECT
31 {
32 CONSOLE_IO_OBJECT_TYPE Type;
33 struct _CONSOLE* /* PCONSOLE */ Console;
34 LONG AccessRead, AccessWrite;
35 LONG ExclusiveRead, ExclusiveWrite;
36 LONG HandleCount;
37 } CONSOLE_IO_OBJECT, *PCONSOLE_IO_OBJECT;
38
39
40 /******************************************************************************\
41 |* *|
42 |* Abstract "class" for screen-buffers, be they text-mode or graphics *|
43 |* *|
44 \******************************************************************************/
45
46 /*
47 * See conoutput.c for the implementation
48 */
49
50 typedef struct _CONSOLE_SCREEN_BUFFER CONSOLE_SCREEN_BUFFER,
51 *PCONSOLE_SCREEN_BUFFER;
52
53 typedef struct _CONSOLE_SCREEN_BUFFER_VTBL
54 {
55 CONSOLE_IO_OBJECT_TYPE (*GetType)(PCONSOLE_SCREEN_BUFFER This);
56 } CONSOLE_SCREEN_BUFFER_VTBL, *PCONSOLE_SCREEN_BUFFER_VTBL;
57
58 #define GetType(This) (This)->Vtbl->GetType(This)
59
60 struct _CONSOLE_SCREEN_BUFFER
61 {
62 CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
63 PCONSOLE_SCREEN_BUFFER_VTBL Vtbl; /* Virtual table */
64
65 LIST_ENTRY ListEntry; /* Entry in console's list of buffers */
66
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 */
69
70 COORD OldScreenBufferSize; /* Old size of this screen buffer */
71 COORD OldViewSize; /* Old associated view size */
72
73 COORD ViewOrigin; /* Beginning offset for the actual display area */
74
75 /***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
76 USHORT VirtualY; /* Top row of buffer being displayed, reported to callers */
77
78 COORD CursorPosition; /* Current cursor position */
79 BOOLEAN CursorBlinkOn;
80 BOOLEAN ForceCursorOff;
81 // ULONG CursorSize;
82 CONSOLE_CURSOR_INFO CursorInfo; // FIXME: Keep this member or not ??
83 /*********************************************/
84
85 // WORD ScreenDefaultAttrib; /* Default screen char attribute */
86 // WORD PopupDefaultAttrib; /* Default popup char attribute */
87 USHORT Mode; /* Output buffer modes */
88 };
89
90
91
92 /******************************************************************************\
93 |* *|
94 |* Text-mode and graphics-mode screen-buffer "classes" *|
95 |* *|
96 \******************************************************************************/
97
98 /*
99 * See text.c for the implementation
100 */
101
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 ************************************************************************/
117
118 typedef struct _TEXTMODE_BUFFER_INFO
119 {
120 COORD ScreenBufferSize;
121 USHORT ScreenAttrib;
122 USHORT PopupAttrib;
123 BOOLEAN IsCursorVisible;
124 ULONG CursorSize;
125 } TEXTMODE_BUFFER_INFO, *PTEXTMODE_BUFFER_INFO;
126
127 typedef struct _TEXTMODE_SCREEN_BUFFER
128 {
129 CONSOLE_SCREEN_BUFFER; /* Screen buffer base class - MUST BE IN FIRST PLACE */
130
131 BYTE *Buffer; /* CHAR_INFO */ /* Pointer to screen buffer */
132
133 WORD ScreenDefaultAttrib; /* Default screen char attribute */
134 WORD PopupDefaultAttrib; /* Default popup char attribute */
135 } TEXTMODE_SCREEN_BUFFER, *PTEXTMODE_SCREEN_BUFFER;
136
137
138 /*
139 * See graphics.c for the implementation
140 */
141
142 typedef struct _GRAPHICS_BUFFER_INFO
143 {
144 CONSOLE_GRAPHICS_BUFFER_INFO Info;
145 } GRAPHICS_BUFFER_INFO, *PGRAPHICS_BUFFER_INFO;
146
147 typedef struct _GRAPHICS_SCREEN_BUFFER
148 {
149 CONSOLE_SCREEN_BUFFER; /* Screen buffer base class - MUST BE IN FIRST PLACE */
150
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;
161
162
163
164 typedef struct _CONSOLE_INPUT_BUFFER
165 {
166 CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
167
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 */
172
173 USHORT Mode; /* Input buffer modes */
174 } CONSOLE_INPUT_BUFFER, *PCONSOLE_INPUT_BUFFER;
175
176 typedef struct _FRONTEND_VTBL
177 {
178 /*
179 * Internal interface (functions called by the console server only)
180 */
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,
185 SMALL_RECT* Region);
186 /* Interface used only for text-mode screen buffers */
187 VOID (WINAPI *WriteStream)(struct _CONSOLE* Console,
188 SMALL_RECT* Block,
189 SHORT CursorStartX,
190 SHORT CursorStartY,
191 UINT ScrolledLines,
192 CHAR *Buffer,
193 UINT Length);
194 BOOL (WINAPI *SetCursorInfo)(struct _CONSOLE* Console,
195 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
196 BOOL (WINAPI *SetScreenInfo)(struct _CONSOLE* Console,
197 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
198 SHORT OldCursorX,
199 SHORT OldCursorY);
200 VOID (WINAPI *ResizeTerminal)(struct _CONSOLE* Console);
201 BOOL (WINAPI *ProcessKeyCallback)(struct _CONSOLE* Console,
202 MSG* msg,
203 BYTE KeyStateMenu,
204 DWORD ShiftState,
205 UINT VirtualKeyCode,
206 BOOL Down);
207 VOID (WINAPI *RefreshInternalInfo)(struct _CONSOLE* Console);
208
209 /*
210 * External interface (functions corresponding to the Console API)
211 */
212 VOID (WINAPI *ChangeTitle)(struct _CONSOLE* Console);
213 BOOL (WINAPI *ChangeIcon)(struct _CONSOLE* Console,
214 HICON hWindowIcon);
215 HWND (WINAPI *GetConsoleWindowHandle)(struct _CONSOLE* Console);
216 VOID (WINAPI *GetLargestConsoleWindowSize)(struct _CONSOLE* Console,
217 PCOORD pSize);
218 ULONG (WINAPI *GetDisplayMode)(struct _CONSOLE* Console);
219 BOOL (WINAPI *SetDisplayMode)(struct _CONSOLE* Console,
220 ULONG NewMode);
221
222 #if 0 // Possible future front-end interface
223 BOOL (WINAPI *GetFrontEndProperty)(struct _CONSOLE* Console,
224 ULONG Flag,
225 PVOID Info,
226 ULONG Size);
227 BOOL (WINAPI *SetFrontEndProperty)(struct _CONSOLE* Console,
228 ULONG Flag,
229 PVOID Info /*,
230 ULONG Size */);
231 #endif
232 } FRONTEND_VTBL, *PFRONTEND_VTBL;
233
234 typedef struct _FRONTEND_IFACE
235 {
236 PFRONTEND_VTBL Vtbl; /* Virtual table */
237 PVOID Data; /* Private data */
238 PVOID OldData; /* Reserved */
239 } FRONTEND_IFACE, *PFRONTEND_IFACE;
240
241 /*
242 * WARNING: Change the state of the console ONLY when the console is locked !
243 */
244 typedef enum _CONSOLE_STATE
245 {
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;
251
252 typedef struct _CONSOLE
253 {
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 */
257
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" */
260
261 FRONTEND_IFACE TermIFace; /* Frontend-specific interface */
262
263 /**************************** Input buffer and data ***************************/
264 CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
265
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 /***************************************************/
276
277 BOOLEAN QuickEdit;
278 BOOLEAN InsertMode;
279 UINT CodePage;
280 UINT OutputCodePage;
281
282 CONSOLE_SELECTION_INFO Selection; /* Contains information about the selection */
283 COORD dwSelectionCursor; /* Selection cursor position, most of the time different from Selection.dwSelectionAnchor */
284
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 */
288 BYTE PauseFlags;
289 HANDLE UnpauseEvent;
290 LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks */
291
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 */
298
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 */
302
303 COORD ConsoleSize; /* The current size of the console, for text-mode only */
304 BOOLEAN FixedSize; /* TRUE if the console is of fixed size */
305
306 COLORREF Colors[16]; /* Colour palette */
307
308 } CONSOLE, *PCONSOLE;
309
310 /* PauseFlags values (internal only) */
311 #define PAUSED_FROM_KEYBOARD 0x1
312 #define PAUSED_FROM_SCROLLBAR 0x2
313 #define PAUSED_FROM_SELECTION 0x4
314
315 /* console.c */
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,
320 DWORD Event);
321
322 /* coninput.c */
323 VOID WINAPI ConioProcessKey(PCONSOLE Console, MSG* msg);
324 NTSTATUS FASTCALL ConioProcessInputEvent(PCONSOLE Console,
325 PINPUT_RECORD InputEvent);
326
327 /* conoutput.c */
328 #define ConioInitRect(Rect, top, left, bottom, right) \
329 do { \
330 ((Rect)->Top) = top; \
331 ((Rect)->Left) = left; \
332 ((Rect)->Bottom) = bottom; \
333 ((Rect)->Right) = right; \
334 } while (0)
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)
341
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,
346 COORD Size);
347 NTSTATUS ConioWriteConsole(PCONSOLE Console,
348 PTEXTMODE_SCREEN_BUFFER Buff,
349 CHAR *Buffer,
350 DWORD Length,
351 BOOL Attrib);
352 DWORD FASTCALL ConioEffectiveCursorSize(PCONSOLE Console,
353 DWORD Scale);
354
355 /* EOF */