da5554ccef1302db3f37e634d14e53090594d7ad
[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
201
202
203 /************ Line discipline ***************/
204
205 /* Interface used only for text-mode screen buffers */
206
207 NTSTATUS (NTAPI *ReadStream)(IN OUT PTERMINAL This,
208 /**/IN PUNICODE_STRING ExeName /**/OPTIONAL/**/,/**/
209 IN BOOLEAN Unicode,
210 /**PWCHAR Buffer,**/
211 OUT PVOID Buffer,
212 IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl,
213 IN ULONG NumCharsToRead,
214 OUT PULONG NumCharsRead OPTIONAL);
215 NTSTATUS (NTAPI *WriteStream)(IN OUT PTERMINAL This,
216 PTEXTMODE_SCREEN_BUFFER Buff,
217 PWCHAR Buffer,
218 DWORD Length,
219 BOOL Attrib);
220
221 /************ Line discipline ***************/
222
223
224
225 BOOL (NTAPI *SetCursorInfo)(IN OUT PTERMINAL This,
226 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
227 BOOL (NTAPI *SetScreenInfo)(IN OUT PTERMINAL This,
228 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
229 SHORT OldCursorX,
230 SHORT OldCursorY);
231 VOID (NTAPI *ResizeTerminal)(IN OUT PTERMINAL This);
232 VOID (NTAPI *SetActiveScreenBuffer)(IN OUT PTERMINAL This);
233 VOID (NTAPI *ReleaseScreenBuffer)(IN OUT PTERMINAL This,
234 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer);
235
236 /*
237 * External interface (functions corresponding to the Console API)
238 */
239 VOID (NTAPI *ChangeTitle)(IN OUT PTERMINAL This);
240 VOID (NTAPI *GetLargestConsoleWindowSize)(IN OUT PTERMINAL This,
241 PCOORD pSize);
242 // BOOL (NTAPI *GetSelectionInfo)(IN OUT PTERMINAL This,
243 // PCONSOLE_SELECTION_INFO pSelectionInfo);
244 BOOL (NTAPI *SetPalette)(IN OUT PTERMINAL This,
245 HPALETTE PaletteHandle,
246 UINT PaletteUsage);
247 INT (NTAPI *ShowMouseCursor)(IN OUT PTERMINAL This,
248 BOOL Show);
249
250 #if 0 // Possible future front-end interface
251 BOOL (NTAPI *GetTerminalProperty)(IN OUT PTERMINAL This,
252 ULONG Flag,
253 PVOID Info,
254 ULONG Size);
255 BOOL (NTAPI *SetTerminalProperty)(IN OUT PTERMINAL This,
256 ULONG Flag,
257 PVOID Info /*,
258 ULONG Size */);
259 #endif
260 } TERMINAL_VTBL, *PTERMINAL_VTBL;
261
262 struct _TERMINAL
263 {
264 PTERMINAL_VTBL Vtbl; /* Virtual table */
265 struct _CONSOLE* Console; /* Console to which the frontend is attached to */
266 PVOID Data; /* Private data */
267 };
268
269 /*
270 * WARNING: Change the state of the console ONLY when the console is locked !
271 */
272 typedef enum _CONSOLE_STATE
273 {
274 CONSOLE_INITIALIZING, /* Console is initializing */
275 CONSOLE_RUNNING , /* Console running */
276 CONSOLE_TERMINATING , /* Console about to be destroyed (but still not) */
277 CONSOLE_IN_DESTRUCTION /* Console in destruction */
278 } CONSOLE_STATE, *PCONSOLE_STATE;
279
280 // HACK!!
281 struct _CONSOLE;
282 /* HACK: */ typedef struct _CONSOLE *PCONSOLE;
283 #include "conio_winsrv.h"
284
285 typedef struct _CONSOLE
286 {
287 /******************************* Console Set-up *******************************/
288 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 */
289 CRITICAL_SECTION Lock;
290
291 /**/WINSRV_CONSOLE;/**/ // HACK HACK!!
292
293 CONSOLE_STATE State; /* State of the console */
294 TERMINAL TermIFace; /* Frontend-specific interface */
295
296 ULONG ConsoleID; /* The ID of the console */
297 LIST_ENTRY ListEntry; /* Entry in the list of consoles */
298
299 HANDLE UnpauseEvent; /* When != NULL, event for pausing the console */
300
301 /******************************** Input buffer ********************************/
302 CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
303 UINT InputCodePage;
304
305 /******************************* Screen buffers *******************************/
306 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
307 PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
308 UINT OutputCodePage;
309
310 /****************************** Other properties ******************************/
311 UNICODE_STRING OriginalTitle; /* Original title of console, the one defined when the console leader is launched; it never changes. Always NULL-terminated */
312 UNICODE_STRING Title; /* Title of console. Always NULL-terminated */
313
314 COORD ConsoleSize; /* The current size of the console, for text-mode only */
315 BOOLEAN FixedSize; /* TRUE if the console is of fixed size */
316
317 } CONSOLE; // , *PCONSOLE;
318
319 /* console.c */
320 VOID NTAPI
321 ConDrvPause(PCONSOLE Console);
322 VOID NTAPI
323 ConDrvUnpause(PCONSOLE Console);
324
325 NTSTATUS
326 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent,
327 IN PCONSOLE_PROCESS_DATA ProcessData);
328
329 /* conoutput.c */
330
331 /*
332 * From MSDN:
333 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
334 * If they are the same, the function fails, and GetLastError returns
335 * ERROR_INVALID_PARAMETER."
336 */
337 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
338 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
339 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
340
341 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
342 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
343 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
344
345 PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y);
346 VOID ConioDrawConsole(PCONSOLE Console);
347 NTSTATUS ConioResizeBuffer(PCONSOLE Console,
348 PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
349 COORD Size);
350
351 /* EOF */