[CSRSRV]
[reactos.git] / win32ss / user / consrv / conio.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/consrv/conio.h
5 * PURPOSE: Internal console I/O interface
6 * PROGRAMMERS:
7 */
8
9 #pragma once
10
11 #define CSR_DEFAULT_CURSOR_SIZE 25
12 #define CURSOR_BLINK_TIME 500
13
14 /* Default attributes */
15 #define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
16 #define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
17 BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
18
19
20 /************************************************************************
21 * Screen buffer structure represents the win32 screen buffer object. *
22 * Internally, the portion of the buffer being shown CAN loop past the *
23 * bottom of the virtual buffer and wrap around to the top. Win32 does *
24 * not do this. I decided to do this because it eliminates the need to *
25 * do a massive memcpy() to scroll the contents of the buffer up to *
26 * scroll the screen on output, instead I just shift down the position *
27 * to be displayed, and let it wrap around to the top again. *
28 * The VirtualY member keeps track of the top Y coord that win32 *
29 * clients THINK is currently being displayed, because they think that *
30 * when the display reaches the bottom of the buffer and another line *
31 * being printed causes another line to scroll down, that the buffer IS *
32 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
33 * internally, I just wrap back to the top of the buffer. *
34 ************************************************************************/
35
36 typedef struct _CONSOLE_SCREEN_BUFFER
37 {
38 Object_t Header; /* Object header */
39 LIST_ENTRY ListEntry; /* Entry in console's list of buffers */
40
41 BYTE *Buffer; /* CHAR_INFO */ /* Pointer to screen buffer */
42
43 COORD ScreenBufferSize; /* Size of this screen buffer */
44 COORD CursorPosition; /* Current cursor position */
45
46 USHORT ShowX, ShowY; /* Beginning offset for the actual display area */
47 USHORT VirtualY; /* Top row of buffer being displayed, reported to callers */
48
49 BOOLEAN CursorBlinkOn;
50 BOOLEAN ForceCursorOff;
51 ULONG CursorSize;
52 CONSOLE_CURSOR_INFO CursorInfo; // FIXME: Keep this member or not ??
53
54 WORD ScreenDefaultAttrib; /* Default screen char attribute */
55 WORD PopupDefaultAttrib; /* Default popup char attribute */
56 USHORT Mode;
57 } CONSOLE_SCREEN_BUFFER, *PCONSOLE_SCREEN_BUFFER;
58
59 typedef struct _CONSOLE_INPUT_BUFFER
60 {
61 Object_t Header; /* Object header */
62
63 ULONG InputBufferSize; /* Size of this input buffer */
64 LIST_ENTRY InputEvents; /* List head for input event queue */
65 HANDLE ActiveEvent; /* Event set when an input event is added in its queue */
66 LIST_ENTRY ReadWaitQueue; /* List head for the queue of read wait blocks */
67
68 USHORT Mode; /* Console Input Buffer mode flags */
69 } CONSOLE_INPUT_BUFFER, *PCONSOLE_INPUT_BUFFER;
70
71 typedef struct ConsoleInput_t
72 {
73 LIST_ENTRY ListEntry;
74 INPUT_RECORD InputEvent;
75 } ConsoleInput;
76
77 typedef struct _TERMINAL_VTBL
78 {
79 /*
80 * Internal interface (functions called by the console server only)
81 */
82 VOID (WINAPI *CleanupConsole)(struct _CONSOLE* Console);
83 VOID (WINAPI *WriteStream)(struct _CONSOLE* Console,
84 SMALL_RECT* Block,
85 LONG CursorStartX,
86 LONG CursorStartY,
87 UINT ScrolledLines,
88 CHAR *Buffer,
89 UINT Length);
90 VOID (WINAPI *DrawRegion)(struct _CONSOLE* Console,
91 SMALL_RECT* Region);
92 BOOL (WINAPI *SetCursorInfo)(struct _CONSOLE* Console,
93 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
94 BOOL (WINAPI *SetScreenInfo)(struct _CONSOLE* Console,
95 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
96 UINT OldCursorX,
97 UINT OldCursorY);
98 BOOL (WINAPI *UpdateScreenInfo)(struct _CONSOLE* Console,
99 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
100 NTSTATUS (WINAPI *ResizeBuffer)(struct _CONSOLE* Console,
101 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
102 COORD Size);
103 BOOL (WINAPI *ProcessKeyCallback)(struct _CONSOLE* Console,
104 MSG* msg,
105 BYTE KeyStateMenu,
106 DWORD ShiftState,
107 UINT VirtualKeyCode,
108 BOOL Down);
109
110 /*
111 * External interface (functions corresponding to the Console API)
112 */
113 VOID (WINAPI *ChangeTitle)(struct _CONSOLE* Console);
114 BOOL (WINAPI *ChangeIcon)(struct _CONSOLE* Console,
115 HICON hWindowIcon);
116 HWND (WINAPI *GetConsoleWindowHandle)(struct _CONSOLE* Console);
117
118 } TERMINAL_VTBL, *PTERMINAL_VTBL;
119
120 #define ConioDrawRegion(Console, Region) (Console)->TermIFace.Vtbl->DrawRegion((Console), (Region))
121 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
122 (Console)->TermIFace.Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
123 (ScrolledLines), (Buffer), (Length))
124 #define ConioSetCursorInfo(Console, Buff) (Console)->TermIFace.Vtbl->SetCursorInfo((Console), (Buff))
125 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
126 (Console)->TermIFace.Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
127 #define ConioUpdateScreenInfo(Console, Buff) \
128 (Console)->TermIFace.Vtbl->UpdateScreenInfo((Console), (Buff))
129 #define ConioChangeTitle(Console) (Console)->TermIFace.Vtbl->ChangeTitle(Console)
130 #define ConioCleanupConsole(Console) (Console)->TermIFace.Vtbl->CleanupConsole(Console)
131 #define ConioChangeIcon(Console, hWindowIcon) (Console)->TermIFace.Vtbl->ChangeIcon((Console), (hWindowIcon))
132 #define ConioResizeBuffer(Console, Buff, Size) (Console)->TermIFace.Vtbl->ResizeBuffer((Console), (Buff), (Size))
133 #define ConioProcessKeyCallback(Console, Msg, KeyStateMenu, ShiftState, VirtualKeyCode, Down) \
134 (Console)->TermIFace.Vtbl->ProcessKeyCallback((Console), (Msg), (KeyStateMenu), (ShiftState), (VirtualKeyCode), (Down))
135
136 typedef struct _TERMINAL_IFACE
137 {
138 PTERMINAL_VTBL Vtbl; /* Virtual table */
139 PVOID Data; /* Private data */
140 PVOID OldData; /* Reserved */
141 } TERMINAL_IFACE, *PTERMINAL_IFACE;
142
143 typedef struct _CONSOLE
144 {
145 LONG ReferenceCount; /* Is incremented each time a handle to a screen-buffer or the input buffer of this console gets referenced, or the console gets locked */
146 CRITICAL_SECTION Lock;
147
148 struct _CONSOLE *Prev, *Next; /* Next and Prev consoles in console wheel */
149 LIST_ENTRY ProcessList; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
150
151 TERMINAL_IFACE TermIFace; /* Terminal-specific interface */
152
153 /**************************** Input buffer and data ***************************/
154 CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
155
156 PWCHAR LineBuffer; /* Current line being input, in line buffered mode */
157 WORD LineMaxSize; /* Maximum size of line in characters (including CR+LF) */
158 WORD LineSize; /* Current size of line */
159 WORD LinePos; /* Current position within line */
160 BOOLEAN LineComplete; /* User pressed enter, ready to send back to client */
161 BOOLEAN LineUpPressed;
162 BOOLEAN LineInsertToggle; /* Replace character over cursor instead of inserting */
163 ULONG LineWakeupMask; /* Bitmap of which control characters will end line input */
164
165 BOOLEAN QuickEdit;
166 BOOLEAN InsertMode;
167 UINT CodePage;
168 UINT OutputCodePage;
169
170 CONSOLE_SELECTION_INFO Selection;
171
172 /******************************* Screen buffers *******************************/
173 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
174 PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
175 BYTE PauseFlags;
176 HANDLE UnpauseEvent;
177 LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks */
178
179 DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
180 /* BOOLEAN */ ULONG FullScreen; // Give the type of console: GUI (windowed) or TUI (fullscreen)
181
182 /**************************** Aliases and Histories ***************************/
183 struct _ALIAS_HEADER *Aliases;
184 LIST_ENTRY HistoryBuffers;
185 ULONG HistoryBufferSize; /* Size for newly created history buffers */
186 ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed */
187 BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
188
189 /****************************** Other properties ******************************/
190 UNICODE_STRING OriginalTitle; /* Original title of console, the one when the console leader is launched. Always NULL-terminated */
191 UNICODE_STRING Title; /* Title of console. Always NULL-terminated */
192
193 COORD Size; /* Size of the console (different of the size of the screen buffer */
194 COLORREF Colors[16]; /* Colour palette */
195
196 } CONSOLE, *PCONSOLE;
197
198 /**************************************************************\
199 \** Define the Console Leader Process for the console window **/
200 #define GWLP_CONSOLEWND_ALLOC (2 * sizeof(LONG_PTR))
201 #define GWLP_CONSOLE_LEADER_PID 0
202 #define GWLP_CONSOLE_LEADER_TID 4
203
204 #define SetConsoleWndConsoleLeaderCID(GuiData) \
205 do { \
206 PCONSOLE_PROCESS_DATA ProcessData; \
207 CLIENT_ID ConsoleLeaderCID; \
208 ProcessData = CONTAINING_RECORD((GuiData)->Console->ProcessList.Blink, \
209 CONSOLE_PROCESS_DATA, \
210 ConsoleLink); \
211 ConsoleLeaderCID = ProcessData->Process->ClientId; \
212 SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_PID, (LONG_PTR)(ConsoleLeaderCID.UniqueProcess)); \
213 SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_TID, (LONG_PTR)(ConsoleLeaderCID.UniqueThread )); \
214 } while(0)
215 /**************************************************************/
216
217 /* CONSOLE_SELECTION_INFO dwFlags values */
218 #define CONSOLE_NO_SELECTION 0x0
219 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
220 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
221 #define CONSOLE_MOUSE_SELECTION 0x4
222 #define CONSOLE_MOUSE_DOWN 0x8
223
224 /* HistoryFlags values */
225 #define HISTORY_NO_DUP_FLAG 0x1
226
227 /* PauseFlags values (internal only) */
228 #define PAUSED_FROM_KEYBOARD 0x1
229 #define PAUSED_FROM_SCROLLBAR 0x2
230 #define PAUSED_FROM_SELECTION 0x4
231
232 /* console.c */
233 VOID WINAPI ConSrvDeleteConsole(PCONSOLE Console);
234 VOID WINAPI ConSrvInitConsoleSupport(VOID);
235 NTSTATUS WINAPI ConSrvInitConsole(OUT PCONSOLE* NewConsole,
236 IN LPCWSTR AppPath,
237 IN OUT PCONSOLE_START_INFO ConsoleStartInfo,
238 IN PCSR_PROCESS ConsoleLeaderProcess);
239 VOID FASTCALL ConioPause(PCONSOLE Console, UINT Flags);
240 VOID FASTCALL ConioUnpause(PCONSOLE Console, UINT Flags);
241 VOID FASTCALL ConSrvConsoleCtrlEvent(DWORD Event, PCONSOLE_PROCESS_DATA ProcessData);
242 VOID FASTCALL ConSrvConsoleCtrlEventTimeout(DWORD Event,
243 PCONSOLE_PROCESS_DATA ProcessData,
244 DWORD Timeout);
245
246 /* coninput.c */
247 #define ConSrvGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
248 ConSrvGetObject((ProcessData), (Handle), (Object_t **)(Ptr), NULL, \
249 (Access), (LockConsole), CONIO_INPUT_BUFFER_MAGIC)
250 #define ConSrvGetInputBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole) \
251 ConSrvGetObject((ProcessData), (Handle), (Object_t **)(Ptr), (Entry), \
252 (Access), (LockConsole), CONIO_INPUT_BUFFER_MAGIC)
253 #define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked) \
254 ConSrvReleaseObject(&(Buff)->Header, (IsConsoleLocked))
255 VOID WINAPI ConioProcessKey(PCONSOLE Console, MSG* msg);
256
257 /* conoutput.c */
258 #define ConioRectHeight(Rect) \
259 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
260 #define ConioRectWidth(Rect) \
261 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
262 #define ConSrvGetScreenBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
263 ConSrvGetObject((ProcessData), (Handle), (Object_t **)(Ptr), NULL, \
264 (Access), (LockConsole), CONIO_SCREEN_BUFFER_MAGIC)
265 #define ConSrvGetScreenBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole) \
266 ConSrvGetObject((ProcessData), (Handle), (Object_t **)(Ptr), (Entry), \
267 (Access), (LockConsole), CONIO_SCREEN_BUFFER_MAGIC)
268 #define ConSrvReleaseScreenBuffer(Buff, IsConsoleLocked) \
269 ConSrvReleaseObject(&(Buff)->Header, (IsConsoleLocked))
270 PBYTE FASTCALL ConioCoordToPointer(PCONSOLE_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
271 VOID FASTCALL ConioDrawConsole(PCONSOLE Console);
272 NTSTATUS FASTCALL ConioWriteConsole(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER Buff,
273 CHAR *Buffer, DWORD Length, BOOL Attrib);
274 NTSTATUS FASTCALL ConSrvCreateScreenBuffer(IN OUT PCONSOLE Console,
275 OUT PCONSOLE_SCREEN_BUFFER* Buffer,
276 IN COORD ScreenBufferSize,
277 IN USHORT ScreenAttrib,
278 IN USHORT PopupAttrib,
279 IN BOOLEAN IsCursorVisible,
280 IN ULONG CursorSize);
281 VOID WINAPI ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer);
282 DWORD FASTCALL ConioEffectiveCursorSize(PCONSOLE Console, DWORD Scale);
283
284 /* alias.c */
285 VOID IntDeleteAllAliases(struct _ALIAS_HEADER *RootHeader);
286
287 /* lineinput.c */
288 struct _HISTORY_BUFFER;
289 VOID FASTCALL HistoryDeleteBuffer(struct _HISTORY_BUFFER *Hist);
290 VOID FASTCALL LineInputKeyDown(PCONSOLE Console, KEY_EVENT_RECORD *KeyEvent);
291
292 /* EOF */