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