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