[CONSRV]: Move all references to VDM screenbuffers from condrv back to consrv (only...
[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 // This is ALMOST a HACK!!!!!!!
16 // Helpers for code refactoring
17 #ifdef USE_NEW_CONSOLE_WAY
18
19 #define _CONSRV_CONSOLE _WINSRV_CONSOLE
20 #define CONSRV_CONSOLE WINSRV_CONSOLE
21 #define PCONSRV_CONSOLE PWINSRV_CONSOLE
22
23 #else
24
25 #define _CONSRV_CONSOLE _CONSOLE
26 #define CONSRV_CONSOLE CONSOLE
27 #define PCONSRV_CONSOLE PCONSOLE
28
29 #endif
30
31 /* Default attributes */
32 #define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
33 #define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
34 BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
35
36
37 /* Object type magic numbers */
38 typedef enum _CONSOLE_IO_OBJECT_TYPE
39 {
40 UNKNOWN = 0x00, // --> Unknown object
41 TEXTMODE_BUFFER = 0x01, // --> Output-type object for text SBs
42 GRAPHICS_BUFFER = 0x02, // --> Output-type object for graphics SBs
43 SCREEN_BUFFER = 0x03, // --> Any SB type
44 INPUT_BUFFER = 0x04, // --> Input-type object
45 ANY_TYPE_BUFFER = 0x07, // --> Any IO object
46 } CONSOLE_IO_OBJECT_TYPE;
47
48 typedef struct _CONSOLE_IO_OBJECT
49 {
50 CONSOLE_IO_OBJECT_TYPE Type;
51
52 struct _CONSOLE* /* PCONSOLE */ Console;
53 LONG ReferenceCount; /* Is incremented each time a console object gets referenced */
54
55 LONG AccessRead, AccessWrite;
56 LONG ExclusiveRead, ExclusiveWrite;
57 } CONSOLE_IO_OBJECT, *PCONSOLE_IO_OBJECT;
58
59
60 /******************************************************************************\
61 |* *|
62 |* Abstract "class" for screen-buffers, be they text-mode or graphics *|
63 |* *|
64 \******************************************************************************/
65
66 /*
67 * See conoutput.c for the implementation
68 */
69
70 typedef struct _CONSOLE_SCREEN_BUFFER CONSOLE_SCREEN_BUFFER,
71 *PCONSOLE_SCREEN_BUFFER;
72
73 typedef struct _CONSOLE_SCREEN_BUFFER_VTBL
74 {
75 CONSOLE_IO_OBJECT_TYPE (*GetType)(PCONSOLE_SCREEN_BUFFER This);
76 } CONSOLE_SCREEN_BUFFER_VTBL, *PCONSOLE_SCREEN_BUFFER_VTBL;
77
78 #define GetType(This) (This)->Vtbl->GetType(This)
79
80 struct _CONSOLE_SCREEN_BUFFER
81 {
82 CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
83 PCONSOLE_SCREEN_BUFFER_VTBL Vtbl; /* Virtual table */
84
85 LIST_ENTRY ListEntry; /* Entry in console's list of buffers */
86
87 COORD ScreenBufferSize; /* Size of this screen buffer. (Rows, Columns) for text-mode and (Width, Height) for graphics-mode */
88 COORD ViewSize; /* Associated "view" (i.e. console) size */
89
90 COORD OldScreenBufferSize; /* Old size of this screen buffer */
91 COORD OldViewSize; /* Old associated view size */
92
93 COORD ViewOrigin; /* Beginning offset for the actual display area */
94
95 /***** Put that VV in TEXTMODE_SCREEN_BUFFER ?? *****/
96 USHORT VirtualY; /* Top row of buffer being displayed, reported to callers */
97
98 COORD CursorPosition; /* Current cursor position */
99 BOOLEAN CursorBlinkOn;
100 BOOLEAN ForceCursorOff;
101 // ULONG CursorSize;
102 CONSOLE_CURSOR_INFO CursorInfo; // FIXME: Keep this member or not ??
103 /*********************************************/
104
105 HPALETTE PaletteHandle; /* Handle to the color palette associated to this buffer */
106 UINT PaletteUsage; /* The new use of the system palette. See SetSystemPaletteUse 'uUsage' parameter */
107
108 // WORD ScreenDefaultAttrib; /* Default screen char attribute */
109 // WORD PopupDefaultAttrib; /* Default popup char attribute */
110 USHORT Mode; /* Output buffer modes */
111
112 // PVOID Data; /* Private data for the frontend to use */
113 };
114
115
116
117 /******************************************************************************\
118 |* *|
119 |* Text-mode and graphics-mode screen-buffer "classes" *|
120 |* *|
121 \******************************************************************************/
122
123 /*
124 * See text.c for the implementation
125 */
126
127 /************************************************************************
128 * Screen buffer structure represents the win32 screen buffer object. *
129 * Internally, the portion of the buffer being shown CAN loop past the *
130 * bottom of the virtual buffer and wrap around to the top. Win32 does *
131 * not do this. I decided to do this because it eliminates the need to *
132 * do a massive memcpy() to scroll the contents of the buffer up to *
133 * scroll the screen on output, instead I just shift down the position *
134 * to be displayed, and let it wrap around to the top again. *
135 * The VirtualY member keeps track of the top Y coord that win32 *
136 * clients THINK is currently being displayed, because they think that *
137 * when the display reaches the bottom of the buffer and another line *
138 * being printed causes another line to scroll down, that the buffer IS *
139 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
140 * internally, I just wrap back to the top of the buffer. *
141 ************************************************************************/
142
143 typedef struct _TEXTMODE_BUFFER_INFO
144 {
145 COORD ScreenBufferSize;
146 USHORT ScreenAttrib;
147 USHORT PopupAttrib;
148 ULONG CursorSize;
149 BOOLEAN IsCursorVisible;
150 } TEXTMODE_BUFFER_INFO, *PTEXTMODE_BUFFER_INFO;
151
152 typedef struct _TEXTMODE_SCREEN_BUFFER
153 {
154 CONSOLE_SCREEN_BUFFER; /* Screen buffer base class - MUST BE IN FIRST PLACE */
155
156 PCHAR_INFO Buffer; /* Pointer to UNICODE screen buffer (Buffer->Char.UnicodeChar only is valid, not Char.AsciiChar) */
157
158 WORD ScreenDefaultAttrib; /* Default screen char attribute */
159 WORD PopupDefaultAttrib; /* Default popup char attribute */
160 } TEXTMODE_SCREEN_BUFFER, *PTEXTMODE_SCREEN_BUFFER;
161
162
163 /*
164 * See graphics.c for the implementation
165 */
166
167 typedef struct _GRAPHICS_BUFFER_INFO
168 {
169 CONSOLE_GRAPHICS_BUFFER_INFO Info;
170 } GRAPHICS_BUFFER_INFO, *PGRAPHICS_BUFFER_INFO;
171
172 typedef struct _GRAPHICS_SCREEN_BUFFER
173 {
174 CONSOLE_SCREEN_BUFFER; /* Screen buffer base class - MUST BE IN FIRST PLACE */
175
176 ULONG BitMapInfoLength; /* Real size of the structure pointed by BitMapInfo */
177 LPBITMAPINFO BitMapInfo; /* Information on the bitmap buffer */
178 ULONG BitMapUsage; /* See the uUsage parameter of GetDIBits */
179 HANDLE hSection; /* Handle to the memory shared section for the bitmap buffer */
180 PVOID BitMap; /* Our bitmap buffer */
181
182 PVOID ClientBitMap; /* A copy of the client view of our bitmap buffer */
183 HANDLE Mutex; /* Our mutex, used to synchronize read / writes to the bitmap buffer */
184 HANDLE ClientMutex; /* A copy of the client handle to our mutex */
185 HANDLE ClientProcess; /* Handle to the client process who opened the buffer, to unmap the view */
186 } GRAPHICS_SCREEN_BUFFER, *PGRAPHICS_SCREEN_BUFFER;
187
188
189
190 typedef struct _CONSOLE_INPUT_BUFFER
191 {
192 CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
193
194 ULONG InputBufferSize; /* Size of this input buffer -- UNUSED!! */
195 LIST_ENTRY InputEvents; /* List head for input event queue */
196 HANDLE ActiveEvent; /* Event set when an input event is added in its queue */
197
198 USHORT Mode; /* Input buffer modes */
199 } CONSOLE_INPUT_BUFFER, *PCONSOLE_INPUT_BUFFER;
200
201
202 typedef struct _TERMINAL TERMINAL, *PTERMINAL;
203 /* HACK: */ typedef struct _CONSOLE_INFO *PCONSOLE_INFO;
204 typedef struct _TERMINAL_VTBL
205 {
206 /*
207 * Internal interface (functions called by the console server only)
208 */
209 NTSTATUS (NTAPI *InitTerminal)(IN OUT PTERMINAL This,
210 IN struct _CONSOLE* Console);
211 VOID (NTAPI *DeinitTerminal)(IN OUT PTERMINAL This);
212
213
214
215 /************ Line discipline ***************/
216
217 /* Interface used only for text-mode screen buffers */
218
219 NTSTATUS (NTAPI *ReadStream)(IN OUT PTERMINAL This,
220 IN BOOLEAN Unicode,
221 /**PWCHAR Buffer,**/
222 OUT PVOID Buffer,
223 IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl,
224 IN PVOID Parameter OPTIONAL,
225 IN ULONG NumCharsToRead,
226 OUT PULONG NumCharsRead OPTIONAL);
227 NTSTATUS (NTAPI *WriteStream)(IN OUT PTERMINAL This,
228 PTEXTMODE_SCREEN_BUFFER Buff,
229 PWCHAR Buffer,
230 DWORD Length,
231 BOOL Attrib);
232
233 /************ Line discipline ***************/
234
235
236
237 /* Interface used for both text-mode and graphics screen buffers */
238 VOID (NTAPI *DrawRegion)(IN OUT PTERMINAL This,
239 SMALL_RECT* Region);
240 BOOL (NTAPI *SetCursorInfo)(IN OUT PTERMINAL This,
241 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
242 BOOL (NTAPI *SetScreenInfo)(IN OUT PTERMINAL This,
243 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
244 SHORT OldCursorX,
245 SHORT OldCursorY);
246 VOID (NTAPI *ResizeTerminal)(IN OUT PTERMINAL This);
247 VOID (NTAPI *SetActiveScreenBuffer)(IN OUT PTERMINAL This);
248 VOID (NTAPI *ReleaseScreenBuffer)(IN OUT PTERMINAL This,
249 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer);
250
251 /*
252 * External interface (functions corresponding to the Console API)
253 */
254 VOID (NTAPI *GetLargestConsoleWindowSize)(IN OUT PTERMINAL This,
255 PCOORD pSize);
256 BOOL (NTAPI *SetPalette)(IN OUT PTERMINAL This,
257 HPALETTE PaletteHandle,
258 UINT PaletteUsage);
259 INT (NTAPI *ShowMouseCursor)(IN OUT PTERMINAL This,
260 BOOL Show);
261
262 #if 0 // Possible future front-end interface
263 BOOL (NTAPI *GetTerminalProperty)(IN OUT PTERMINAL This,
264 ULONG Flag,
265 PVOID Info,
266 ULONG Size);
267 BOOL (NTAPI *SetTerminalProperty)(IN OUT PTERMINAL This,
268 ULONG Flag,
269 PVOID Info /*,
270 ULONG Size */);
271 #endif
272 } TERMINAL_VTBL, *PTERMINAL_VTBL;
273
274 struct _TERMINAL
275 {
276 PTERMINAL_VTBL Vtbl; /* Virtual table */
277 struct _CONSOLE* Console; /* Console to which the frontend is attached to */
278 PVOID Data; /* Private data */
279 };
280
281 /*
282 * WARNING: Change the state of the console ONLY when the console is locked !
283 */
284 typedef enum _CONSOLE_STATE
285 {
286 CONSOLE_INITIALIZING, /* Console is initializing */
287 CONSOLE_RUNNING , /* Console running */
288 CONSOLE_TERMINATING , /* Console about to be destroyed (but still not) */
289 CONSOLE_IN_DESTRUCTION /* Console in destruction */
290 } CONSOLE_STATE, *PCONSOLE_STATE;
291
292 // HACK!!
293 struct _CONSOLE;
294 /* HACK: */ typedef struct _CONSOLE *PCONSOLE;
295 #ifndef USE_NEW_CONSOLE_WAY
296 #include "conio_winsrv.h"
297 #endif
298
299 typedef struct _CONSOLE
300 {
301 /******************************* Console Set-up *******************************/
302
303 #ifndef USE_NEW_CONSOLE_WAY
304 WINSRV_CONSOLE; // HACK HACK!!
305 #endif
306
307 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 */
308 CRITICAL_SECTION Lock;
309
310 ULONG ConsoleID; /* The ID of the console */
311 LIST_ENTRY ListEntry; /* Entry in the list of consoles */
312
313 CONSOLE_STATE State; /* State of the console */
314 TERMINAL TermIFace; /* Terminal-specific interface */
315
316 HANDLE UnpauseEvent; /* When != NULL, event for pausing the console */
317
318 /******************************** Input buffer ********************************/
319 CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
320 UINT InputCodePage;
321
322 /******************************* Screen buffers *******************************/
323 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
324 PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
325 UINT OutputCodePage;
326
327 /****************************** Other properties ******************************/
328 COORD ConsoleSize; /* The current size of the console, for text-mode only */
329 BOOLEAN FixedSize; /* TRUE if the console is of fixed size */
330
331 } CONSOLE; // , *PCONSOLE;
332
333 /* console.c */
334 VOID NTAPI
335 ConDrvPause(PCONSOLE Console);
336 VOID NTAPI
337 ConDrvUnpause(PCONSOLE Console);
338
339 NTSTATUS
340 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent,
341 IN PCONSOLE_PROCESS_DATA ProcessData);
342
343
344 #define GetConsoleInputBufferMode(Console) \
345 (Console)->InputBuffer.Mode
346
347
348 /* conoutput.c */
349 PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y);
350 VOID ConioDrawConsole(PCONSOLE /*PCONSRV_CONSOLE*/ Console);
351 NTSTATUS ConioResizeBuffer(PCONSOLE /*PCONSRV_CONSOLE*/ Console,
352 PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
353 COORD Size);
354
355 /* EOF */