[CONSRV]
[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
13 /************************************************************************
14 * Screen buffer structure represents the win32 screen buffer object. *
15 * Internally, the portion of the buffer being shown CAN loop past the *
16 * bottom of the virtual buffer and wrap around to the top. Win32 does *
17 * not do this. I decided to do this because it eliminates the need to *
18 * do a massive memcpy() to scroll the contents of the buffer up to *
19 * scroll the screen on output, instead I just shift down the position *
20 * to be displayed, and let it wrap around to the top again. *
21 * The VirtualY member keeps track of the top Y coord that win32 *
22 * clients THINK is currently being displayed, because they think that *
23 * when the display reaches the bottom of the buffer and another line *
24 * being printed causes another line to scroll down, that the buffer IS *
25 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
26 * internally, I just wrap back to the top of the buffer. *
27 ************************************************************************/
28
29 typedef struct _CONSOLE_SCREEN_BUFFER
30 {
31 Object_t Header; /* Object header */
32 LIST_ENTRY ListEntry; /* Entry in console's list of buffers */
33
34 BYTE *Buffer; /* Pointer to screen buffer */
35 USHORT MaxX, MaxY; /* Size of the entire scrollback buffer */
36 USHORT ShowX, ShowY; /* Beginning offset for the actual display area */
37 ULONG CurrentX; /* Current X cursor position */
38 ULONG CurrentY; /* Current Y cursor position */
39 WORD DefaultAttrib; /* Default char attribute */
40 USHORT VirtualY; /* Top row of buffer being displayed, reported to callers */
41 CONSOLE_CURSOR_INFO CursorInfo;
42 USHORT Mode;
43 } CONSOLE_SCREEN_BUFFER, *PCONSOLE_SCREEN_BUFFER;
44
45 typedef struct _CONSOLE_INPUT_BUFFER
46 {
47 Object_t Header; /* Object header */
48
49 LIST_ENTRY InputEvents; /* List head for input event queue */
50 HANDLE ActiveEvent; /* Event set when an input event is added in its queue */
51 LIST_ENTRY ReadWaitQueue; /* List head for the queue of read wait blocks */
52 WORD Mode; /* Console Input Buffer mode flags */
53 } CONSOLE_INPUT_BUFFER, *PCONSOLE_INPUT_BUFFER;
54
55 typedef struct ConsoleInput_t
56 {
57 LIST_ENTRY ListEntry;
58 INPUT_RECORD InputEvent;
59 } ConsoleInput;
60
61 typedef struct _CONSOLE
62 {
63 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 */
64 CRITICAL_SECTION Lock;
65
66 struct _CONSOLE *Prev, *Next; /* Next and Prev consoles in console wheel */
67 struct _CONSOLE_VTBL *Vtbl; /* Using CUI or GUI consoles */
68
69 CLIENT_ID ConsoleLeaderCID; /* Contains the Console Leader Process CID for this console. TODO: Is it possible to compute it via the contents of the ProcessList list ?? */
70 LIST_ENTRY ProcessList;
71
72 /**************************** Input buffer and data ***************************/
73 CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
74
75 PWCHAR LineBuffer; /* Current line being input, in line buffered mode */
76 WORD LineMaxSize; /* Maximum size of line in characters (including CR+LF) */
77 WORD LineSize; /* Current size of line */
78 WORD LinePos; /* Current position within line */
79 BOOLEAN LineComplete; /* User pressed enter, ready to send back to client */
80 BOOLEAN LineUpPressed;
81 BOOLEAN LineInsertToggle; /* Replace character over cursor instead of inserting */
82 ULONG LineWakeupMask; /* Bitmap of which control characters will end line input */
83
84 UINT CodePage;
85 UINT OutputCodePage;
86
87 CONSOLE_SELECTION_INFO Selection;
88
89 /**************************** Aliases and Histories ***************************/
90 struct _ALIAS_HEADER *Aliases;
91 LIST_ENTRY HistoryBuffers;
92 UINT HistoryBufferSize; /* Size for newly created history buffers */
93 UINT NumberOfHistoryBuffers; /* Maximum number of history buffers allowed */
94 BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
95
96 /******************************* Screen buffers *******************************/
97 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
98 PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
99 BYTE PauseFlags;
100 HANDLE UnpauseEvent;
101 LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks */
102
103 DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
104
105 /****************************** GUI-related data ******************************/
106 UNICODE_STRING Title; /* Title of console */
107 HWND hWindow;
108 COORD Size;
109 PVOID GuiData;
110
111 } CONSOLE, *PCONSOLE;
112
113 /**************************************************************\
114 \** Define the Console Leader Process for the console window **/
115 #define GWLP_CONSOLEWND_ALLOC (2 * sizeof(LONG_PTR))
116 #define GWLP_CONSOLE_LEADER_PID 0
117 #define GWLP_CONSOLE_LEADER_TID 4
118
119 #define SetConsoleWndConsoleLeaderCID(Console) \
120 do { \
121 SetWindowLongPtrW((Console)->hWindow, GWLP_CONSOLE_LEADER_PID, (LONG_PTR)((Console)->ConsoleLeaderCID.UniqueProcess)); \
122 SetWindowLongPtrW((Console)->hWindow, GWLP_CONSOLE_LEADER_TID, (LONG_PTR)((Console)->ConsoleLeaderCID.UniqueThread )); \
123 } while(0)
124 /**************************************************************/
125
126 typedef struct _CONSOLE_VTBL
127 {
128 VOID (WINAPI *InitScreenBuffer)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
129 VOID (WINAPI *WriteStream)(PCONSOLE Console, SMALL_RECT* Block, LONG CursorStartX, LONG CursorStartY,
130 UINT ScrolledLines, CHAR *Buffer, UINT Length);
131 VOID (WINAPI *DrawRegion)(PCONSOLE Console, SMALL_RECT* Region);
132 BOOL (WINAPI *SetCursorInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
133 BOOL (WINAPI *SetScreenInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer,
134 UINT OldCursorX, UINT OldCursorY);
135 BOOL (WINAPI *UpdateScreenInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
136 BOOL (WINAPI *ChangeTitle)(PCONSOLE Console);
137 VOID (WINAPI *CleanupConsole)(PCONSOLE Console);
138 BOOL (WINAPI *ChangeIcon)(PCONSOLE Console, HICON hWindowIcon);
139 NTSTATUS (WINAPI *ResizeBuffer)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Size);
140 } CONSOLE_VTBL, *PCONSOLE_VTBL;
141
142 /* CONSOLE_SELECTION_INFO dwFlags values */
143 #define CONSOLE_NO_SELECTION 0x0
144 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
145 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
146 #define CONSOLE_MOUSE_SELECTION 0x4
147 #define CONSOLE_MOUSE_DOWN 0x8
148 /* HistoryFlags values */
149 #define HISTORY_NO_DUP_FLAG 0x1
150
151 /* PauseFlags values (internal only) */
152 #define PAUSED_FROM_KEYBOARD 0x1
153 #define PAUSED_FROM_SCROLLBAR 0x2
154 #define PAUSED_FROM_SELECTION 0x4
155
156 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
157 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
158 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
159 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
160 (ScrolledLines), (Buffer), (Length))
161 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
162 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
163 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
164 #define ConioUpdateScreenInfo(Console, Buff) \
165 (Console)->Vtbl->UpdateScreenInfo((Console), (Buff))
166 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
167 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
168 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon((Console), (hWindowIcon))
169 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer((Console), (Buff), (Size))
170
171 /* console.c */
172 #define ConioGetConsole(ProcessData, Console, LockConsole) \
173 ConioConsoleFromProcessData((ProcessData), (Console), (LockConsole))
174 #define ConioReleaseConsole(Console, ConsoleLocked) \
175 Win32CsrUnlockConsole((Console), (ConsoleLocked))
176 VOID WINAPI ConioDeleteConsole(PCONSOLE Console);
177 VOID WINAPI CsrInitConsoleSupport(VOID);
178 NTSTATUS WINAPI CsrInitConsole(PCONSOLE* NewConsole, int ShowCmd, PCSR_PROCESS ConsoleLeaderProcess);
179 VOID FASTCALL ConioPause(PCONSOLE Console, UINT Flags);
180 VOID FASTCALL ConioUnpause(PCONSOLE Console, UINT Flags);
181 VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCONSOLE_PROCESS_DATA ProcessData);
182 VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event,
183 PCONSOLE_PROCESS_DATA ProcessData,
184 DWORD Timeout);
185
186 /* coninput.c */
187 #define ConioGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
188 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), NULL, \
189 (Access), (LockConsole), CONIO_INPUT_BUFFER_MAGIC)
190 #define ConioGetInputBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole) \
191 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), (Entry), \
192 (Access), (LockConsole), CONIO_INPUT_BUFFER_MAGIC)
193 #define ConioReleaseInputBuffer(Buff, IsConsoleLocked) \
194 Win32CsrUnlockObject(&(Buff)->Header, (IsConsoleLocked))
195 void WINAPI ConioProcessKey(MSG *msg, PCONSOLE Console, BOOL TextMode);
196
197 /* conoutput.c */
198 #define ConioRectHeight(Rect) \
199 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
200 #define ConioRectWidth(Rect) \
201 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
202 #define ConioGetScreenBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
203 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), NULL, \
204 (Access), (LockConsole), CONIO_SCREEN_BUFFER_MAGIC)
205 #define ConioGetScreenBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole) \
206 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), (Entry), \
207 (Access), (LockConsole), CONIO_SCREEN_BUFFER_MAGIC)
208 #define ConioReleaseScreenBuffer(Buff, IsConsoleLocked) \
209 Win32CsrUnlockObject(&(Buff)->Header, (IsConsoleLocked))
210 PBYTE FASTCALL ConioCoordToPointer(PCONSOLE_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
211 VOID FASTCALL ConioDrawConsole(PCONSOLE Console);
212 NTSTATUS FASTCALL ConioWriteConsole(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER Buff,
213 CHAR *Buffer, DWORD Length, BOOL Attrib);
214 NTSTATUS FASTCALL CsrInitConsoleScreenBuffer(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER Buffer);
215 VOID WINAPI ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer);
216 DWORD FASTCALL ConioEffectiveCursorSize(PCONSOLE Console, DWORD Scale);
217
218 /* alias.c */
219 VOID IntDeleteAllAliases(struct _ALIAS_HEADER *RootHeader);
220
221 /* lineinput.c */
222 struct _HISTORY_BUFFER;
223 VOID FASTCALL HistoryDeleteBuffer(struct _HISTORY_BUFFER *Hist);
224 VOID FASTCALL LineInputKeyDown(PCONSOLE Console, KEY_EVENT_RECORD *KeyEvent);
225
226 /* EOF */