8d3dc9f6a4df9911b2f5d03c90e6ab3762a914ed
[reactos.git] / win32ss / user / winsrv / consrv / include / conio.h
1 /*
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
7 * Jeffrey Morlan
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 */
10
11 #pragma once
12
13 #include "rect.h"
14
15 #define CSR_DEFAULT_CURSOR_SIZE 25
16
17 /* Default attributes */
18 #define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
19 #define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
20 BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
21
22 /* VGA character cell */
23 typedef struct _CHAR_CELL
24 {
25 CHAR Char;
26 BYTE Attributes;
27 } CHAR_CELL, *PCHAR_CELL;
28 C_ASSERT(sizeof(CHAR_CELL) == 2);
29
30
31 /* Object type magic numbers */
32 typedef enum _CONSOLE_IO_OBJECT_TYPE
33 {
34 UNKNOWN = 0x00, // --> Unknown object
35 TEXTMODE_BUFFER = 0x01, // --> Output-type object for text SBs
36 GRAPHICS_BUFFER = 0x02, // --> Output-type object for graphics SBs
37 SCREEN_BUFFER = 0x03, // --> Any SB type
38 INPUT_BUFFER = 0x04, // --> Input-type object
39 ANY_TYPE_BUFFER = 0x07, // --> Any IO object
40 } CONSOLE_IO_OBJECT_TYPE;
41
42 typedef struct _CONSOLE_IO_OBJECT
43 {
44 CONSOLE_IO_OBJECT_TYPE Type;
45
46 struct _CONSOLE* /* PCONSOLE */ Console;
47 LONG ReferenceCount; /* Is incremented each time a console object gets referenced */
48
49 LONG AccessRead, AccessWrite;
50 LONG ExclusiveRead, ExclusiveWrite;
51 } CONSOLE_IO_OBJECT, *PCONSOLE_IO_OBJECT;
52
53
54 /******************************************************************************\
55 |* *|
56 |* Abstract "class" for screen-buffers, be they text-mode or graphics *|
57 |* *|
58 \******************************************************************************/
59
60 /*
61 * See conoutput.c for the implementation
62 */
63
64 typedef struct _CONSOLE_SCREEN_BUFFER CONSOLE_SCREEN_BUFFER,
65 *PCONSOLE_SCREEN_BUFFER;
66
67 typedef struct _CONSOLE_SCREEN_BUFFER_VTBL
68 {
69 CONSOLE_IO_OBJECT_TYPE (*GetType)(PCONSOLE_SCREEN_BUFFER This);
70 } CONSOLE_SCREEN_BUFFER_VTBL, *PCONSOLE_SCREEN_BUFFER_VTBL;
71
72 #define GetType(This) (This)->Vtbl->GetType(This)
73
74 struct _CONSOLE_SCREEN_BUFFER
75 {
76 CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
77 PCONSOLE_SCREEN_BUFFER_VTBL Vtbl; /* Virtual table */
78
79 LIST_ENTRY ListEntry; /* Entry in console's list of buffers */
80
81 COORD ScreenBufferSize; /* Size of this screen buffer. (Rows, Columns) for text-mode and (Width, Height) for graphics-mode */
82 COORD ViewSize; /* Associated "view" (i.e. console) size */
83
84 COORD OldScreenBufferSize; /* Old size of this screen buffer */
85 COORD OldViewSize; /* Old associated view size */
86
87 COORD ViewOrigin; /* Beginning offset for the actual display area */
88
89 /***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
90 USHORT VirtualY; /* Top row of buffer being displayed, reported to callers */
91
92 COORD CursorPosition; /* Current cursor position */
93 BOOLEAN CursorBlinkOn;
94 BOOLEAN ForceCursorOff;
95 // ULONG CursorSize;
96 CONSOLE_CURSOR_INFO CursorInfo; // FIXME: Keep this member or not ??
97 /*********************************************/
98
99 HPALETTE PaletteHandle; /* Handle to the color palette associated to this buffer */
100 UINT PaletteUsage; /* The new use of the system palette. See SetSystemPaletteUse 'uUsage' parameter */
101
102 // WORD ScreenDefaultAttrib; /* Default screen char attribute */
103 // WORD PopupDefaultAttrib; /* Default popup char attribute */
104 USHORT Mode; /* Output buffer modes */
105
106 // PVOID Data; /* Private data for the frontend to use */
107 };
108
109
110
111 /******************************************************************************\
112 |* *|
113 |* Text-mode and graphics-mode screen-buffer "classes" *|
114 |* *|
115 \******************************************************************************/
116
117 /*
118 * See text.c for the implementation
119 */
120
121 /************************************************************************
122 * Screen buffer structure represents the win32 screen buffer object. *
123 * Internally, the portion of the buffer being shown CAN loop past the *
124 * bottom of the virtual buffer and wrap around to the top. Win32 does *
125 * not do this. I decided to do this because it eliminates the need to *
126 * do a massive memcpy() to scroll the contents of the buffer up to *
127 * scroll the screen on output, instead I just shift down the position *
128 * to be displayed, and let it wrap around to the top again. *
129 * The VirtualY member keeps track of the top Y coord that win32 *
130 * clients THINK is currently being displayed, because they think that *
131 * when the display reaches the bottom of the buffer and another line *
132 * being printed causes another line to scroll down, that the buffer IS *
133 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
134 * internally, I just wrap back to the top of the buffer. *
135 ************************************************************************/
136
137 typedef struct _TEXTMODE_BUFFER_INFO
138 {
139 COORD ScreenBufferSize;
140 USHORT ScreenAttrib;
141 USHORT PopupAttrib;
142 ULONG CursorSize;
143 BOOLEAN IsCursorVisible;
144 } TEXTMODE_BUFFER_INFO, *PTEXTMODE_BUFFER_INFO;
145
146 typedef struct _TEXTMODE_SCREEN_BUFFER
147 {
148 CONSOLE_SCREEN_BUFFER; /* Screen buffer base class - MUST BE IN FIRST PLACE */
149
150 PCHAR_INFO Buffer; /* Pointer to UNICODE screen buffer (Buffer->Char.UnicodeChar only is valid, not Char.AsciiChar) */
151
152 WORD ScreenDefaultAttrib; /* Default screen char attribute */
153 WORD PopupDefaultAttrib; /* Default popup char attribute */
154 } TEXTMODE_SCREEN_BUFFER, *PTEXTMODE_SCREEN_BUFFER;
155
156
157 /*
158 * See graphics.c for the implementation
159 */
160
161 typedef struct _GRAPHICS_BUFFER_INFO
162 {
163 CONSOLE_GRAPHICS_BUFFER_INFO Info;
164 } GRAPHICS_BUFFER_INFO, *PGRAPHICS_BUFFER_INFO;
165
166 typedef struct _GRAPHICS_SCREEN_BUFFER
167 {
168 CONSOLE_SCREEN_BUFFER; /* Screen buffer base class - MUST BE IN FIRST PLACE */
169
170 ULONG BitMapInfoLength; /* Real size of the structure pointed by BitMapInfo */
171 LPBITMAPINFO BitMapInfo; /* Information on the bitmap buffer */
172 ULONG BitMapUsage; /* See the uUsage parameter of GetDIBits */
173 HANDLE hSection; /* Handle to the memory shared section for the bitmap buffer */
174 PVOID BitMap; /* Our bitmap buffer */
175
176 PVOID ClientBitMap; /* A copy of the client view of our bitmap buffer */
177 HANDLE Mutex; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
178 HANDLE ClientMutex; /* A copy of the client handle to our mutex */
179 HANDLE ClientProcess; /* Handle to the client process who opened the buffer, to unmap the view */
180 } GRAPHICS_SCREEN_BUFFER, *PGRAPHICS_SCREEN_BUFFER;
181
182
183
184 typedef struct _CONSOLE_INPUT_BUFFER
185 {
186 CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
187
188 ULONG InputBufferSize; /* Size of this input buffer */
189 LIST_ENTRY InputEvents; /* List head for input event queue */
190 HANDLE ActiveEvent; /* Event set when an input event is added in its queue */
191
192 USHORT Mode; /* Input buffer modes */
193 } CONSOLE_INPUT_BUFFER, *PCONSOLE_INPUT_BUFFER;
194
195
196 typedef struct _TERMINAL TERMINAL, *PTERMINAL;
197 /* HACK: */ typedef struct _CONSOLE_INFO *PCONSOLE_INFO;
198 typedef struct _TERMINAL_VTBL
199 {
200 /*
201 * Internal interface (functions called by the console server only)
202 */
203 NTSTATUS (NTAPI *InitTerminal)(IN OUT PTERMINAL This,
204 IN struct _CONSOLE* Console);
205 VOID (NTAPI *DeinitTerminal)(IN OUT PTERMINAL This);
206
207 /* Interface used for both text-mode and graphics screen buffers */
208 VOID (NTAPI *DrawRegion)(IN OUT PTERMINAL This,
209 SMALL_RECT* Region);
210 /* Interface used only for text-mode screen buffers */
211 VOID (NTAPI *WriteStream)(IN OUT PTERMINAL This,
212 SMALL_RECT* Region,
213 SHORT CursorStartX,
214 SHORT CursorStartY,
215 UINT ScrolledLines,
216 PWCHAR Buffer,
217 UINT Length);
218 BOOL (NTAPI *SetCursorInfo)(IN OUT PTERMINAL This,
219 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
220 BOOL (NTAPI *SetScreenInfo)(IN OUT PTERMINAL This,
221 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
222 SHORT OldCursorX,
223 SHORT OldCursorY);
224 VOID (NTAPI *ResizeTerminal)(IN OUT PTERMINAL This);
225 VOID (NTAPI *SetActiveScreenBuffer)(IN OUT PTERMINAL This);
226 VOID (NTAPI *ReleaseScreenBuffer)(IN OUT PTERMINAL This,
227 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer);
228
229 /*
230 * External interface (functions corresponding to the Console API)
231 */
232 VOID (NTAPI *ChangeTitle)(IN OUT PTERMINAL This);
233 VOID (NTAPI *GetLargestConsoleWindowSize)(IN OUT PTERMINAL This,
234 PCOORD pSize);
235 // BOOL (NTAPI *GetSelectionInfo)(IN OUT PTERMINAL This,
236 // PCONSOLE_SELECTION_INFO pSelectionInfo);
237 BOOL (NTAPI *SetPalette)(IN OUT PTERMINAL This,
238 HPALETTE PaletteHandle,
239 UINT PaletteUsage);
240 INT (NTAPI *ShowMouseCursor)(IN OUT PTERMINAL This,
241 BOOL Show);
242
243 #if 0 // Possible future front-end interface
244 BOOL (NTAPI *GetTerminalProperty)(IN OUT PTERMINAL This,
245 ULONG Flag,
246 PVOID Info,
247 ULONG Size);
248 BOOL (NTAPI *SetTerminalProperty)(IN OUT PTERMINAL This,
249 ULONG Flag,
250 PVOID Info /*,
251 ULONG Size */);
252 #endif
253 } TERMINAL_VTBL, *PTERMINAL_VTBL;
254
255 struct _TERMINAL
256 {
257 PTERMINAL_VTBL Vtbl; /* Virtual table */
258 struct _CONSOLE* Console; /* Console to which the frontend is attached to */
259 PVOID Data; /* Private data */
260 };
261
262 /*
263 * WARNING: Change the state of the console ONLY when the console is locked !
264 */
265 typedef enum _CONSOLE_STATE
266 {
267 CONSOLE_INITIALIZING, /* Console is initializing */
268 CONSOLE_RUNNING , /* Console running */
269 CONSOLE_TERMINATING , /* Console about to be destroyed (but still not) */
270 CONSOLE_IN_DESTRUCTION /* Console in destruction */
271 } CONSOLE_STATE, *PCONSOLE_STATE;
272
273 // HACK!!
274 struct _CONSOLE;
275 struct _WINSRV_CONSOLE;
276 /* HACK: */ typedef struct _CONSOLE *PCONSOLE;
277 #include "conio_winsrv.h"
278
279 typedef struct _CONSOLE
280 {
281 /******************************* Console Set-up *******************************/
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
285 /**/WINSRV_CONSOLE;/**/ // HACK HACK!!
286
287 CONSOLE_STATE State; /* State of the console */
288 TERMINAL TermIFace; /* Frontend-specific interface */
289
290 ULONG ConsoleID; /* The ID of the console */
291 LIST_ENTRY ListEntry; /* Entry in the list of consoles */
292
293 /**************************** Input buffer and data ***************************/
294 CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
295 UINT InputCodePage;
296
297 /** Put those things in CONSOLE_INPUT_BUFFER ?? **/
298 PWCHAR LineBuffer; /* Current line being input, in line buffered mode */
299 ULONG LineMaxSize; /* Maximum size of line in characters (including CR+LF) */
300 ULONG LineSize; /* Current size of line */
301 ULONG LinePos; /* Current position within line */
302 BOOLEAN LineComplete; /* User pressed enter, ready to send back to client */
303 BOOLEAN LineUpPressed;
304 BOOLEAN LineInsertToggle; /* Replace character over cursor instead of inserting */
305 ULONG LineWakeupMask; /* Bitmap of which control characters will end line input */
306 /*************************************************/
307
308 BOOLEAN InsertMode;
309
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 */
313 UINT OutputCodePage;
314
315 /**** Per-console Virtual DOS Machine Text-mode Buffer ****/
316 COORD VDMBufferSize; /* Real size of the VDM buffer, in units of ??? */
317 HANDLE VDMBufferSection; /* Handle to the memory shared section for the VDM buffer */
318 PVOID VDMBuffer; /* Our VDM buffer */
319 PVOID ClientVDMBuffer; /* A copy of the client view of our VDM buffer */
320 HANDLE VDMClientProcess; /* Handle to the client process who opened the buffer, to unmap the view */
321
322 HANDLE StartHardwareEvent;
323 HANDLE EndHardwareEvent;
324 HANDLE ErrorHardwareEvent;
325
326 /****************************** Other properties ******************************/
327 UNICODE_STRING OriginalTitle; /* Original title of console, the one defined when the console leader is launched; it never changes. Always NULL-terminated */
328 UNICODE_STRING Title; /* Title of console. Always NULL-terminated */
329
330 HANDLE UnpauseEvent; /* When != NULL, event for pausing the console */
331
332 COORD ConsoleSize; /* The current size of the console, for text-mode only */
333 BOOLEAN FixedSize; /* TRUE if the console is of fixed size */
334
335 COLORREF Colors[16]; /* Colour palette */
336
337 } CONSOLE; // , *PCONSOLE;
338
339 // #include "conio_winsrv.h"
340
341 /* console.c */
342 VOID NTAPI
343 ConDrvPause(PCONSOLE Console);
344 VOID NTAPI
345 ConDrvUnpause(PCONSOLE Console);
346
347 PCONSOLE_PROCESS_DATA NTAPI
348 ConSrvGetConsoleLeaderProcess(IN PCONSOLE Console);
349 NTSTATUS
350 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent,
351 IN PCONSOLE_PROCESS_DATA ProcessData);
352 NTSTATUS NTAPI
353 ConSrvConsoleProcessCtrlEvent(IN PCONSOLE Console,
354 IN ULONG ProcessGroupId,
355 IN ULONG CtrlEvent);
356
357 /* coninput.c */
358 VOID NTAPI ConioProcessKey(PCONSOLE Console, MSG* msg);
359 NTSTATUS
360 ConioAddInputEvents(PCONSOLE Console,
361 PINPUT_RECORD InputRecords,
362 ULONG NumEventsToWrite,
363 PULONG NumEventsWritten,
364 BOOLEAN AppendToEnd);
365 NTSTATUS
366 ConioProcessInputEvent(PCONSOLE Console,
367 PINPUT_RECORD InputEvent);
368
369 /* conoutput.c */
370
371 /*
372 * From MSDN:
373 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
374 * If they are the same, the function fails, and GetLastError returns
375 * ERROR_INVALID_PARAMETER."
376 */
377 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
378 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
379 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
380
381 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
382 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
383 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
384
385 PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y);
386 VOID ConioDrawConsole(PCONSOLE Console);
387 NTSTATUS ConioResizeBuffer(PCONSOLE Console,
388 PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
389 COORD Size);
390 NTSTATUS ConioWriteConsole(PCONSOLE Console,
391 PTEXTMODE_SCREEN_BUFFER Buff,
392 PWCHAR Buffer,
393 DWORD Length,
394 BOOL Attrib);
395 DWORD ConioEffectiveCursorSize(PCONSOLE Console,
396 DWORD Scale);
397
398 /* EOF */