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