Fix broken merge.
[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: win32ss/user/winsrv/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 // PVOID Data; /* Private data for the frontend to use */
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
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 BOOLEAN IsCursorVisible;
129 ULONG CursorSize;
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 PVOID ClientBitMap; /* A copy of the client view of our bitmap buffer */
162 HANDLE Mutex; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
163 HANDLE ClientMutex; /* A copy of the client handle to our mutex */
164 HANDLE ClientProcess; /* Handle to the client process who opened the buffer, to unmap the view */
165 } GRAPHICS_SCREEN_BUFFER, *PGRAPHICS_SCREEN_BUFFER;
166
167
168
169 typedef struct _CONSOLE_INPUT_BUFFER
170 {
171 CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
172
173 ULONG InputBufferSize; /* Size of this input buffer */
174 LIST_ENTRY InputEvents; /* List head for input event queue */
175 HANDLE ActiveEvent; /* Event set when an input event is added in its queue */
176 LIST_ENTRY ReadWaitQueue; /* List head for the queue of read wait blocks */
177
178 USHORT Mode; /* Input buffer modes */
179 } CONSOLE_INPUT_BUFFER, *PCONSOLE_INPUT_BUFFER;
180
181
182 typedef struct _FRONTEND FRONTEND, *PFRONTEND;
183 /* HACK: */ typedef struct _CONSOLE_INFO *PCONSOLE_INFO;
184 typedef struct _FRONTEND_VTBL
185 {
186 /*
187 * Internal interface (functions called by the console server only)
188 */
189 NTSTATUS (NTAPI *InitFrontEnd)(IN OUT PFRONTEND This,
190 IN struct _CONSOLE* Console);
191 VOID (NTAPI *DeinitFrontEnd)(IN OUT PFRONTEND This);
192
193 /* Interface used for both text-mode and graphics screen buffers */
194 VOID (NTAPI *DrawRegion)(IN OUT PFRONTEND This,
195 SMALL_RECT* Region);
196 /* Interface used only for text-mode screen buffers */
197 VOID (NTAPI *WriteStream)(IN OUT PFRONTEND This,
198 SMALL_RECT* Block,
199 SHORT CursorStartX,
200 SHORT CursorStartY,
201 UINT ScrolledLines,
202 PWCHAR Buffer,
203 UINT Length);
204 BOOL (NTAPI *SetCursorInfo)(IN OUT PFRONTEND This,
205 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
206 BOOL (NTAPI *SetScreenInfo)(IN OUT PFRONTEND This,
207 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
208 SHORT OldCursorX,
209 SHORT OldCursorY);
210 VOID (NTAPI *ResizeTerminal)(IN OUT PFRONTEND This);
211 VOID (NTAPI *SetActiveScreenBuffer)(IN OUT PFRONTEND This);
212 VOID (NTAPI *ReleaseScreenBuffer)(IN OUT PFRONTEND This,
213 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer);
214 BOOL (NTAPI *ProcessKeyCallback)(IN OUT PFRONTEND This,
215 MSG* msg,
216 BYTE KeyStateMenu,
217 DWORD ShiftState,
218 UINT VirtualKeyCode,
219 BOOL Down);
220 VOID (NTAPI *RefreshInternalInfo)(IN OUT PFRONTEND This);
221
222 /*
223 * External interface (functions corresponding to the Console API)
224 */
225 VOID (NTAPI *ChangeTitle)(IN OUT PFRONTEND This);
226 BOOL (NTAPI *ChangeIcon)(IN OUT PFRONTEND This,
227 HICON IconHandle);
228 HWND (NTAPI *GetConsoleWindowHandle)(IN OUT PFRONTEND This);
229 VOID (NTAPI *GetLargestConsoleWindowSize)(IN OUT PFRONTEND This,
230 PCOORD pSize);
231 BOOL (NTAPI *SetPalette)(IN OUT PFRONTEND This,
232 HPALETTE PaletteHandle,
233 UINT PaletteUsage);
234 ULONG (NTAPI *GetDisplayMode)(IN OUT PFRONTEND This);
235 BOOL (NTAPI *SetDisplayMode)(IN OUT PFRONTEND This,
236 ULONG NewMode);
237 INT (NTAPI *ShowMouseCursor)(IN OUT PFRONTEND This,
238 BOOL Show);
239 BOOL (NTAPI *SetMouseCursor)(IN OUT PFRONTEND This,
240 HCURSOR CursorHandle);
241 HMENU (NTAPI *MenuControl)(IN OUT PFRONTEND This,
242 UINT CmdIdLow,
243 UINT CmdIdHigh);
244 BOOL (NTAPI *SetMenuClose)(IN OUT PFRONTEND This,
245 BOOL Enable);
246
247 #if 0 // Possible future front-end interface
248 BOOL (NTAPI *GetFrontEndProperty)(IN OUT PFRONTEND This,
249 ULONG Flag,
250 PVOID Info,
251 ULONG Size);
252 BOOL (NTAPI *SetFrontEndProperty)(IN OUT PFRONTEND This,
253 ULONG Flag,
254 PVOID Info /*,
255 ULONG Size */);
256 #endif
257 } FRONTEND_VTBL, *PFRONTEND_VTBL;
258
259 struct _FRONTEND
260 {
261 PFRONTEND_VTBL Vtbl; /* Virtual table */
262 struct _CONSOLE* Console; /* Console to which the frontend is attached to */
263 PVOID Data; /* Private data */
264 PVOID OldData; /* Reserved */
265 };
266
267 /*
268 * WARNING: Change the state of the console ONLY when the console is locked !
269 */
270 typedef enum _CONSOLE_STATE
271 {
272 CONSOLE_INITIALIZING, /* Console is initializing */
273 CONSOLE_RUNNING , /* Console running */
274 CONSOLE_TERMINATING , /* Console about to be destroyed (but still not) */
275 CONSOLE_IN_DESTRUCTION /* Console in destruction */
276 } CONSOLE_STATE, *PCONSOLE_STATE;
277
278 typedef struct _CONSOLE
279 {
280 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 */
281 CRITICAL_SECTION Lock;
282 CONSOLE_STATE State; /* State of the console */
283
284 LIST_ENTRY ProcessList; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
285 PCONSOLE_PROCESS_DATA NotifiedLastCloseProcess; /* Pointer to the unique process that needs to be notified when all the other processes have been detached from the console */
286 BOOLEAN NotifyLastClose; /* TRUE if the console should send a control event to the last attached process after all the others detached, if it wanted to be notified */
287
288 FRONTEND TermIFace; /* Frontend-specific interface */
289
290 /**************************** Input buffer and data ***************************/
291 CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
292
293 /** Put those things in TEXTMODE_SCREEN_BUFFER ?? **/
294 PWCHAR LineBuffer; /* Current line being input, in line buffered mode */
295 WORD LineMaxSize; /* Maximum size of line in characters (including CR+LF) */
296 WORD LineSize; /* Current size of line */
297 WORD LinePos; /* Current position within line */
298 BOOLEAN LineComplete; /* User pressed enter, ready to send back to client */
299 BOOLEAN LineUpPressed;
300 BOOLEAN LineInsertToggle; /* Replace character over cursor instead of inserting */
301 ULONG LineWakeupMask; /* Bitmap of which control characters will end line input */
302 /***************************************************/
303
304 BOOLEAN QuickEdit;
305 BOOLEAN InsertMode;
306 UINT CodePage;
307
308 CONSOLE_SELECTION_INFO Selection; /* Contains information about the selection */
309 COORD dwSelectionCursor; /* Selection cursor position, most of the time different from Selection.dwSelectionAnchor */
310
311 /******************************* Screen buffers *******************************/
312 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
313 PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
314 BYTE PauseFlags;
315 HANDLE UnpauseEvent;
316 LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks */
317 UINT OutputCodePage;
318
319 /**************************** Aliases and Histories ***************************/
320 struct _ALIAS_HEADER *Aliases;
321 LIST_ENTRY HistoryBuffers;
322 ULONG HistoryBufferSize; /* Size for newly created history buffers */
323 ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed */
324 BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
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 COORD ConsoleSize; /* The current size of the console, for text-mode only */
331 BOOLEAN FixedSize; /* TRUE if the console is of fixed size */
332
333 COLORREF Colors[16]; /* Colour palette */
334
335 } CONSOLE, *PCONSOLE;
336
337 /* PauseFlags values (internal only) */
338 #define PAUSED_FROM_KEYBOARD 0x1
339 #define PAUSED_FROM_SCROLLBAR 0x2
340 #define PAUSED_FROM_SELECTION 0x4
341
342 /* console.c */
343 VOID FASTCALL ConioPause(PCONSOLE Console, UINT Flags);
344 VOID FASTCALL ConioUnpause(PCONSOLE Console, UINT Flags);
345
346 NTSTATUS NTAPI
347 ConDrvConsoleProcessCtrlEvent(IN PCONSOLE Console,
348 IN ULONG ProcessGroupId,
349 IN ULONG CtrlEvent);
350
351 /* coninput.c */
352 VOID NTAPI ConioProcessKey(PCONSOLE Console, MSG* msg);
353 NTSTATUS FASTCALL ConioAddInputEvent(PCONSOLE Console,
354 PINPUT_RECORD InputEvent,
355 BOOLEAN AppendToEnd);
356 NTSTATUS FASTCALL ConioProcessInputEvent(PCONSOLE Console,
357 PINPUT_RECORD InputEvent);
358
359 /* conoutput.c */
360 #define ConioInitRect(Rect, top, left, bottom, right) \
361 do { \
362 ((Rect)->Top) = top; \
363 ((Rect)->Left) = left; \
364 ((Rect)->Bottom) = bottom; \
365 ((Rect)->Right) = right; \
366 } while (0)
367 #define ConioIsRectEmpty(Rect) \
368 (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
369 #define ConioRectHeight(Rect) \
370 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
371 #define ConioRectWidth(Rect) \
372 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
373
374 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
375 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
376
377 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
378 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
379
380 PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y);
381 VOID FASTCALL ConioDrawConsole(PCONSOLE Console);
382 NTSTATUS ConioResizeBuffer(PCONSOLE Console,
383 PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
384 COORD Size);
385 NTSTATUS ConioWriteConsole(PCONSOLE Console,
386 PTEXTMODE_SCREEN_BUFFER Buff,
387 PWCHAR Buffer,
388 DWORD Length,
389 BOOL Attrib);
390 DWORD FASTCALL ConioEffectiveCursorSize(PCONSOLE Console,
391 DWORD Scale);
392
393 /* EOF */