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
11 #define CSR_DEFAULT_CURSOR_SIZE 25
12 #define CURSOR_BLINK_TIME 500
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)
22 #define PM_CREATE_CONSOLE (WM_APP + 1)
23 #define PM_DESTROY_CONSOLE (WM_APP + 2)
24 #define PM_CONSOLE_BEEP (WM_APP + 3)
25 #define PM_CONSOLE_SET_TITLE (WM_APP + 4)
28 /************************************************************************
29 * Screen buffer structure represents the win32 screen buffer object. *
30 * Internally, the portion of the buffer being shown CAN loop past the *
31 * bottom of the virtual buffer and wrap around to the top. Win32 does *
32 * not do this. I decided to do this because it eliminates the need to *
33 * do a massive memcpy() to scroll the contents of the buffer up to *
34 * scroll the screen on output, instead I just shift down the position *
35 * to be displayed, and let it wrap around to the top again. *
36 * The VirtualY member keeps track of the top Y coord that win32 *
37 * clients THINK is currently being displayed, because they think that *
38 * when the display reaches the bottom of the buffer and another line *
39 * being printed causes another line to scroll down, that the buffer IS *
40 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
41 * internally, I just wrap back to the top of the buffer. *
42 ************************************************************************/
44 typedef struct _CONSOLE_SCREEN_BUFFER
46 Object_t Header
; /* Object header */
47 LIST_ENTRY ListEntry
; /* Entry in console's list of buffers */
49 BYTE
*Buffer
; /* CHAR_INFO */ /* Pointer to screen buffer */
51 COORD ScreenBufferSize
; /* Size of this screen buffer */
52 COORD CursorPosition
; /* Current cursor position */
54 USHORT ShowX
, ShowY
; /* Beginning offset for the actual display area */
55 USHORT VirtualY
; /* Top row of buffer being displayed, reported to callers */
57 BOOLEAN CursorBlinkOn
;
58 BOOLEAN ForceCursorOff
;
60 CONSOLE_CURSOR_INFO CursorInfo
; // FIXME: Keep this member or not ??
62 WORD ScreenDefaultAttrib
; /* Default screen char attribute */
63 WORD PopupDefaultAttrib
; /* Default popup char attribute */
65 } CONSOLE_SCREEN_BUFFER
, *PCONSOLE_SCREEN_BUFFER
;
67 typedef struct _CONSOLE_INPUT_BUFFER
69 Object_t Header
; /* Object header */
71 ULONG InputBufferSize
; /* Size of this input buffer */
72 LIST_ENTRY InputEvents
; /* List head for input event queue */
73 HANDLE ActiveEvent
; /* Event set when an input event is added in its queue */
74 LIST_ENTRY ReadWaitQueue
; /* List head for the queue of read wait blocks */
76 USHORT Mode
; /* Console Input Buffer mode flags */
77 } CONSOLE_INPUT_BUFFER
, *PCONSOLE_INPUT_BUFFER
;
79 typedef struct ConsoleInput_t
82 INPUT_RECORD InputEvent
;
85 typedef struct _CONSOLE
87 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 */
88 CRITICAL_SECTION Lock
;
90 struct _CONSOLE
*Prev
, *Next
; /* Next and Prev consoles in console wheel */
91 struct _CONSOLE_VTBL
*Vtbl
; /* Using CUI or GUI consoles */
93 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 ?? */
94 LIST_ENTRY ProcessList
;
96 /**************************** Input buffer and data ***************************/
97 CONSOLE_INPUT_BUFFER InputBuffer
; /* Input buffer of the console */
99 PWCHAR LineBuffer
; /* Current line being input, in line buffered mode */
100 WORD LineMaxSize
; /* Maximum size of line in characters (including CR+LF) */
101 WORD LineSize
; /* Current size of line */
102 WORD LinePos
; /* Current position within line */
103 BOOLEAN LineComplete
; /* User pressed enter, ready to send back to client */
104 BOOLEAN LineUpPressed
;
105 BOOLEAN LineInsertToggle
; /* Replace character over cursor instead of inserting */
106 ULONG LineWakeupMask
; /* Bitmap of which control characters will end line input */
113 CONSOLE_SELECTION_INFO Selection
;
115 /******************************* Screen buffers *******************************/
116 LIST_ENTRY BufferList
; /* List of all screen buffers for this console */
117 PCONSOLE_SCREEN_BUFFER ActiveBuffer
; /* Pointer to currently active screen buffer */
120 LIST_ENTRY WriteWaitQueue
; /* List head for the queue of write wait blocks */
122 DWORD HardwareState
; /* _GDI_MANAGED, _DIRECT */
123 /* BOOLEAN */ ULONG FullScreen
; // Give the type of console: GUI (windowed) or TUI (fullscreen)
125 /**************************** Aliases and Histories ***************************/
126 struct _ALIAS_HEADER
*Aliases
;
127 LIST_ENTRY HistoryBuffers
;
128 ULONG HistoryBufferSize
; /* Size for newly created history buffers */
129 ULONG NumberOfHistoryBuffers
; /* Maximum number of history buffers allowed */
130 BOOLEAN HistoryNoDup
; /* Remove old duplicate history entries */
132 /******************************* Common UI data *******************************/
133 UNICODE_STRING OriginalTitle
; /* Original title of console, the one when the console leader is launched. It is always NULL-terminated */
134 UNICODE_STRING Title
; /* Title of console. It is always NULL-terminated */
136 COORD Size
; /* Size of the console (different of the size of the screen buffer */
137 COLORREF Colors
[16]; /* Colour palette */
139 /****************************** GUI-related data ******************************/
140 HWND hWindow
; /* Handle to the console's window */
141 HICON hIcon
; /* Handle to its icon (used when freeing) */
143 PVOID GuiData
; /* PGUI_CONSOLE_DATA */
145 } CONSOLE
, *PCONSOLE
;
147 /**************************************************************\
148 \** Define the Console Leader Process for the console window **/
149 #define GWLP_CONSOLEWND_ALLOC (2 * sizeof(LONG_PTR))
150 #define GWLP_CONSOLE_LEADER_PID 0
151 #define GWLP_CONSOLE_LEADER_TID 4
153 #define SetConsoleWndConsoleLeaderCID(Console) \
155 SetWindowLongPtrW((Console)->hWindow, GWLP_CONSOLE_LEADER_PID, (LONG_PTR)((Console)->ConsoleLeaderCID.UniqueProcess)); \
156 SetWindowLongPtrW((Console)->hWindow, GWLP_CONSOLE_LEADER_TID, (LONG_PTR)((Console)->ConsoleLeaderCID.UniqueThread )); \
158 /**************************************************************/
160 typedef struct _CONSOLE_VTBL
162 VOID (WINAPI
*WriteStream
)(PCONSOLE Console
, SMALL_RECT
* Block
, LONG CursorStartX
, LONG CursorStartY
,
163 UINT ScrolledLines
, CHAR
*Buffer
, UINT Length
);
164 VOID (WINAPI
*DrawRegion
)(PCONSOLE Console
, SMALL_RECT
* Region
);
165 BOOL (WINAPI
*SetCursorInfo
)(PCONSOLE Console
, PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
166 BOOL (WINAPI
*SetScreenInfo
)(PCONSOLE Console
, PCONSOLE_SCREEN_BUFFER ScreenBuffer
,
167 UINT OldCursorX
, UINT OldCursorY
);
168 BOOL (WINAPI
*UpdateScreenInfo
)(PCONSOLE Console
, PCONSOLE_SCREEN_BUFFER ScreenBuffer
);
169 VOID (WINAPI
*ChangeTitle
)(PCONSOLE Console
);
170 VOID (WINAPI
*CleanupConsole
)(PCONSOLE Console
);
171 BOOL (WINAPI
*ChangeIcon
)(PCONSOLE Console
, HICON hWindowIcon
);
172 NTSTATUS (WINAPI
*ResizeBuffer
)(PCONSOLE Console
, PCONSOLE_SCREEN_BUFFER ScreenBuffer
, COORD Size
);
173 BOOL (WINAPI
*ProcessKeyCallback
)(PCONSOLE Console
, MSG
* msg
, BYTE KeyStateMenu
, DWORD ShiftState
, UINT VirtualKeyCode
, BOOL Down
);
174 } CONSOLE_VTBL
, *PCONSOLE_VTBL
;
176 /* CONSOLE_SELECTION_INFO dwFlags values */
177 #define CONSOLE_NO_SELECTION 0x0
178 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
179 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
180 #define CONSOLE_MOUSE_SELECTION 0x4
181 #define CONSOLE_MOUSE_DOWN 0x8
182 /* HistoryFlags values */
183 #define HISTORY_NO_DUP_FLAG 0x1
185 /* PauseFlags values (internal only) */
186 #define PAUSED_FROM_KEYBOARD 0x1
187 #define PAUSED_FROM_SCROLLBAR 0x2
188 #define PAUSED_FROM_SELECTION 0x4
190 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
191 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
192 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
193 (ScrolledLines), (Buffer), (Length))
194 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
195 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
196 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
197 #define ConioUpdateScreenInfo(Console, Buff) \
198 (Console)->Vtbl->UpdateScreenInfo((Console), (Buff))
199 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
200 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
201 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon((Console), (hWindowIcon))
202 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer((Console), (Buff), (Size))
203 #define ConioProcessKeyCallback(Console, Msg, KeyStateMenu, ShiftState, VirtualKeyCode, Down) (Console)->Vtbl->ProcessKeyCallback((Console), (Msg), (KeyStateMenu), (ShiftState), (VirtualKeyCode), (Down))
206 VOID WINAPI
ConSrvDeleteConsole(PCONSOLE Console
);
207 VOID WINAPI
ConSrvInitConsoleSupport(VOID
);
208 NTSTATUS WINAPI
ConSrvInitConsole(OUT PCONSOLE
* NewConsole
,
210 IN OUT PCONSOLE_START_INFO ConsoleStartInfo
,
211 IN PCSR_PROCESS ConsoleLeaderProcess
);
212 VOID FASTCALL
ConioPause(PCONSOLE Console
, UINT Flags
);
213 VOID FASTCALL
ConioUnpause(PCONSOLE Console
, UINT Flags
);
214 VOID FASTCALL
ConSrvConsoleCtrlEvent(DWORD Event
, PCONSOLE_PROCESS_DATA ProcessData
);
215 VOID FASTCALL
ConSrvConsoleCtrlEventTimeout(DWORD Event
,
216 PCONSOLE_PROCESS_DATA ProcessData
,
220 #define ConSrvGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
221 ConSrvGetObject((ProcessData), (Handle), (Object_t **)(Ptr), NULL, \
222 (Access), (LockConsole), CONIO_INPUT_BUFFER_MAGIC)
223 #define ConSrvGetInputBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole) \
224 ConSrvGetObject((ProcessData), (Handle), (Object_t **)(Ptr), (Entry), \
225 (Access), (LockConsole), CONIO_INPUT_BUFFER_MAGIC)
226 #define ConSrvReleaseInputBuffer(Buff, IsConsoleLocked) \
227 ConSrvReleaseObject(&(Buff)->Header, (IsConsoleLocked))
228 VOID WINAPI
ConioProcessKey(PCONSOLE Console
, MSG
* msg
);
231 #define ConioRectHeight(Rect) \
232 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
233 #define ConioRectWidth(Rect) \
234 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
235 #define ConSrvGetScreenBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
236 ConSrvGetObject((ProcessData), (Handle), (Object_t **)(Ptr), NULL, \
237 (Access), (LockConsole), CONIO_SCREEN_BUFFER_MAGIC)
238 #define ConSrvGetScreenBufferAndHandleEntry(ProcessData, Handle, Ptr, Entry, Access, LockConsole) \
239 ConSrvGetObject((ProcessData), (Handle), (Object_t **)(Ptr), (Entry), \
240 (Access), (LockConsole), CONIO_SCREEN_BUFFER_MAGIC)
241 #define ConSrvReleaseScreenBuffer(Buff, IsConsoleLocked) \
242 ConSrvReleaseObject(&(Buff)->Header, (IsConsoleLocked))
243 PBYTE FASTCALL
ConioCoordToPointer(PCONSOLE_SCREEN_BUFFER Buf
, ULONG X
, ULONG Y
);
244 VOID FASTCALL
ConioDrawConsole(PCONSOLE Console
);
245 NTSTATUS FASTCALL
ConioWriteConsole(PCONSOLE Console
, PCONSOLE_SCREEN_BUFFER Buff
,
246 CHAR
*Buffer
, DWORD Length
, BOOL Attrib
);
247 NTSTATUS FASTCALL
ConSrvCreateScreenBuffer(IN OUT PCONSOLE Console
,
248 OUT PCONSOLE_SCREEN_BUFFER
* Buffer
,
249 IN COORD ScreenBufferSize
,
250 IN USHORT ScreenAttrib
,
251 IN USHORT PopupAttrib
);
252 VOID WINAPI
ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer
);
253 DWORD FASTCALL
ConioEffectiveCursorSize(PCONSOLE Console
, DWORD Scale
);
256 VOID
IntDeleteAllAliases(struct _ALIAS_HEADER
*RootHeader
);
259 struct _HISTORY_BUFFER
;
260 VOID FASTCALL
HistoryDeleteBuffer(struct _HISTORY_BUFFER
*Hist
);
261 VOID FASTCALL
LineInputKeyDown(PCONSOLE Console
, KEY_EVENT_RECORD
*KeyEvent
);