c7960f3afb23c4a8272bbe4f5838565199626be7
[reactos.git] / win32ss / user / consrv / include / conio.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/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 INPUT_BUFFER = 0x01, // --> Input-type handles
24 SCREEN_BUFFER = 0x02 // --> Output-type handles
25 } CONSOLE_IO_OBJECT_TYPE;
26
27 typedef struct _CONSOLE_IO_OBJECT
28 {
29 CONSOLE_IO_OBJECT_TYPE Type;
30 struct _CONSOLE* /* PCONSOLE */ Console;
31 LONG AccessRead, AccessWrite;
32 LONG ExclusiveRead, ExclusiveWrite;
33 LONG HandleCount;
34 } CONSOLE_IO_OBJECT, *PCONSOLE_IO_OBJECT;
35
36 /************************************************************************
37 * Screen buffer structure represents the win32 screen buffer object. *
38 * Internally, the portion of the buffer being shown CAN loop past the *
39 * bottom of the virtual buffer and wrap around to the top. Win32 does *
40 * not do this. I decided to do this because it eliminates the need to *
41 * do a massive memcpy() to scroll the contents of the buffer up to *
42 * scroll the screen on output, instead I just shift down the position *
43 * to be displayed, and let it wrap around to the top again. *
44 * The VirtualY member keeps track of the top Y coord that win32 *
45 * clients THINK is currently being displayed, because they think that *
46 * when the display reaches the bottom of the buffer and another line *
47 * being printed causes another line to scroll down, that the buffer IS *
48 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
49 * internally, I just wrap back to the top of the buffer. *
50 ************************************************************************/
51
52 typedef struct _CONSOLE_SCREEN_BUFFER
53 {
54 CONSOLE_IO_OBJECT Header; /* Object header */
55 LIST_ENTRY ListEntry; /* Entry in console's list of buffers */
56
57 BYTE *Buffer; /* CHAR_INFO */ /* Pointer to screen buffer */
58
59 COORD ScreenBufferSize; /* Size of this screen buffer */
60 COORD CursorPosition; /* Current cursor position */
61
62 USHORT ShowX, ShowY; /* Beginning offset for the actual display area */
63 USHORT VirtualY; /* Top row of buffer being displayed, reported to callers */
64
65 BOOLEAN CursorBlinkOn;
66 BOOLEAN ForceCursorOff;
67 ULONG CursorSize;
68 CONSOLE_CURSOR_INFO CursorInfo; // FIXME: Keep this member or not ??
69
70 WORD ScreenDefaultAttrib; /* Default screen char attribute */
71 WORD PopupDefaultAttrib; /* Default popup char attribute */
72 USHORT Mode;
73 ULONG DisplayMode;
74 } CONSOLE_SCREEN_BUFFER, *PCONSOLE_SCREEN_BUFFER;
75
76 typedef struct _CONSOLE_INPUT_BUFFER
77 {
78 CONSOLE_IO_OBJECT Header; /* Object header */
79
80 ULONG InputBufferSize; /* Size of this input buffer */
81 LIST_ENTRY InputEvents; /* List head for input event queue */
82 HANDLE ActiveEvent; /* Event set when an input event is added in its queue */
83 LIST_ENTRY ReadWaitQueue; /* List head for the queue of read wait blocks */
84
85 USHORT Mode; /* Console Input Buffer mode flags */
86 } CONSOLE_INPUT_BUFFER, *PCONSOLE_INPUT_BUFFER;
87
88 typedef struct _FRONTEND_VTBL
89 {
90 /*
91 * Internal interface (functions called by the console server only)
92 */
93 VOID (WINAPI *CleanupConsole)(struct _CONSOLE* Console);
94 VOID (WINAPI *WriteStream)(struct _CONSOLE* Console,
95 SMALL_RECT* Block,
96 LONG CursorStartX,
97 LONG CursorStartY,
98 UINT ScrolledLines,
99 CHAR *Buffer,
100 UINT Length);
101 VOID (WINAPI *DrawRegion)(struct _CONSOLE* Console,
102 SMALL_RECT* Region);
103 BOOL (WINAPI *SetCursorInfo)(struct _CONSOLE* Console,
104 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
105 BOOL (WINAPI *SetScreenInfo)(struct _CONSOLE* Console,
106 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
107 UINT OldCursorX,
108 UINT OldCursorY);
109 BOOL (WINAPI *UpdateScreenInfo)(struct _CONSOLE* Console,
110 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
111 BOOL (WINAPI *IsBufferResizeSupported)(struct _CONSOLE* Console);
112 VOID (WINAPI *ResizeTerminal)(struct _CONSOLE* Console);
113 BOOL (WINAPI *ProcessKeyCallback)(struct _CONSOLE* Console,
114 MSG* msg,
115 BYTE KeyStateMenu,
116 DWORD ShiftState,
117 UINT VirtualKeyCode,
118 BOOL Down);
119 VOID (WINAPI *RefreshInternalInfo)(struct _CONSOLE* Console);
120
121 /*
122 * External interface (functions corresponding to the Console API)
123 */
124 VOID (WINAPI *ChangeTitle)(struct _CONSOLE* Console);
125 BOOL (WINAPI *ChangeIcon)(struct _CONSOLE* Console,
126 HICON hWindowIcon);
127 HWND (WINAPI *GetConsoleWindowHandle)(struct _CONSOLE* Console);
128 VOID (WINAPI *GetLargestConsoleWindowSize)(struct _CONSOLE* Console,
129 PCOORD pSize);
130
131 } FRONTEND_VTBL, *PFRONTEND_VTBL;
132
133 typedef struct _FRONTEND_IFACE
134 {
135 PFRONTEND_VTBL Vtbl; /* Virtual table */
136 PVOID Data; /* Private data */
137 PVOID OldData; /* Reserved */
138 } FRONTEND_IFACE, *PFRONTEND_IFACE;
139
140 /*
141 * WARNING: Change the state of the console ONLY when the console is locked !
142 */
143 typedef enum _CONSOLE_STATE
144 {
145 CONSOLE_INITIALIZING, /* Console is initializing */
146 CONSOLE_RUNNING , /* Console running */
147 CONSOLE_TERMINATING , /* Console about to be destroyed (but still not) */
148 CONSOLE_IN_DESTRUCTION /* Console in destruction */
149 } CONSOLE_STATE, *PCONSOLE_STATE;
150
151 typedef struct _CONSOLE
152 {
153 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 */
154 CRITICAL_SECTION Lock;
155 CONSOLE_STATE State; /* State of the console */
156
157 LIST_ENTRY Entry; /* Entry in the list of consoles */
158 LIST_ENTRY ProcessList; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
159
160 FRONTEND_IFACE TermIFace; /* Frontend-specific interface */
161
162 /**************************** Input buffer and data ***************************/
163 CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
164
165 PWCHAR LineBuffer; /* Current line being input, in line buffered mode */
166 WORD LineMaxSize; /* Maximum size of line in characters (including CR+LF) */
167 WORD LineSize; /* Current size of line */
168 WORD LinePos; /* Current position within line */
169 BOOLEAN LineComplete; /* User pressed enter, ready to send back to client */
170 BOOLEAN LineUpPressed;
171 BOOLEAN LineInsertToggle; /* Replace character over cursor instead of inserting */
172 ULONG LineWakeupMask; /* Bitmap of which control characters will end line input */
173
174 BOOLEAN QuickEdit;
175 BOOLEAN InsertMode;
176 UINT CodePage;
177 UINT OutputCodePage;
178
179 CONSOLE_SELECTION_INFO Selection; /* Contains information about the selection */
180 COORD dwSelectionCursor; /* Selection cursor position, most of the time different from Selection.dwSelectionAnchor */
181
182 /******************************* Screen buffers *******************************/
183 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
184 PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
185 BYTE PauseFlags;
186 HANDLE UnpauseEvent;
187 LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks */
188
189 ULONG HardwareState; /* _GDI_MANAGED, _DIRECT */
190
191 /**************************** Aliases and Histories ***************************/
192 struct _ALIAS_HEADER *Aliases;
193 LIST_ENTRY HistoryBuffers;
194 ULONG HistoryBufferSize; /* Size for newly created history buffers */
195 ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed */
196 BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
197
198 /****************************** Other properties ******************************/
199 UNICODE_STRING OriginalTitle; /* Original title of console, the one when the console leader is launched. Always NULL-terminated */
200 UNICODE_STRING Title; /* Title of console. Always NULL-terminated */
201
202 /* SIZE */ COORD ConsoleSize; /* The size of the console */
203 COLORREF Colors[16]; /* Colour palette */
204
205 } CONSOLE, *PCONSOLE;
206
207 /* PauseFlags values (internal only) */
208 #define PAUSED_FROM_KEYBOARD 0x1
209 #define PAUSED_FROM_SCROLLBAR 0x2
210 #define PAUSED_FROM_SELECTION 0x4
211
212 /* console.c */
213 VOID FASTCALL ConioPause(PCONSOLE Console, UINT Flags);
214 VOID FASTCALL ConioUnpause(PCONSOLE Console, UINT Flags);
215 ULONG FASTCALL ConSrvConsoleProcessCtrlEvent(PCONSOLE Console,
216 ULONG ProcessGroupId,
217 DWORD Event);
218
219 /* coninput.c */
220 VOID WINAPI ConioProcessKey(PCONSOLE Console, MSG* msg);
221 NTSTATUS FASTCALL ConioProcessInputEvent(PCONSOLE Console,
222 PINPUT_RECORD InputEvent);
223
224 /* conoutput.c */
225 #define ConioRectHeight(Rect) \
226 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
227 #define ConioRectWidth(Rect) \
228 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
229
230 PBYTE FASTCALL ConioCoordToPointer(PCONSOLE_SCREEN_BUFFER Buf,
231 ULONG X,
232 ULONG Y);
233 VOID FASTCALL ConioDrawConsole(PCONSOLE Console);
234 NTSTATUS FASTCALL ConioResizeBuffer(PCONSOLE Console,
235 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
236 COORD Size);
237 NTSTATUS FASTCALL ConioWriteConsole(PCONSOLE Console,
238 PCONSOLE_SCREEN_BUFFER Buff,
239 CHAR *Buffer,
240 DWORD Length,
241 BOOL Attrib);
242 DWORD FASTCALL ConioEffectiveCursorSize(PCONSOLE Console,
243 DWORD Scale);
244
245 /* EOF */