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
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 ************************************************************************/
29 typedef struct _CONSOLE_SCREEN_BUFFER
31 Object_t Header
; /* Object header */
32 LIST_ENTRY ListEntry
; /* Entry in console's list of buffers */
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
;
43 } CONSOLE_SCREEN_BUFFER
, *PCONSOLE_SCREEN_BUFFER
;
45 typedef struct _CONSOLE_INPUT_BUFFER
47 Object_t Header
; /* Object header */
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
;
55 typedef struct ConsoleInput_t
58 INPUT_RECORD InputEvent
;
61 typedef struct _CONSOLE
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
;
66 struct _CONSOLE
*Prev
, *Next
; /* Next and Prev consoles in console wheel */
67 struct _CONSOLE_VTBL
*Vtbl
; /* Using CUI or GUI consoles */
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
;
72 /**************************** Input buffer and data ***************************/
73 CONSOLE_INPUT_BUFFER InputBuffer
; /* Input buffer of the console */
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 */
87 CONSOLE_SELECTION_INFO Selection
;
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 */
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 */
101 LIST_ENTRY WriteWaitQueue
; /* List head for the queue of write wait blocks */
103 DWORD HardwareState
; /* _GDI_MANAGED, _DIRECT */
105 /****************************** GUI-related data ******************************/
106 UNICODE_STRING Title
; /* Title of console */
111 } CONSOLE
, *PCONSOLE
;
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
119 #define SetConsoleWndConsoleLeaderCID(Console) \
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 )); \
124 /**************************************************************/
126 typedef struct _CONSOLE_VTBL
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
;
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
151 /* PauseFlags values (internal only) */
152 #define PAUSED_FROM_KEYBOARD 0x1
153 #define PAUSED_FROM_SCROLLBAR 0x2
154 #define PAUSED_FROM_SELECTION 0x4
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))
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
,
187 #define ConioGetInputBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
188 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), (Access), (LockConsole), CONIO_INPUT_BUFFER_MAGIC)
189 #define ConioReleaseInputBuffer(Buff, IsConsoleLocked) \
190 Win32CsrUnlockObject(&(Buff)->Header, (IsConsoleLocked))
191 void WINAPI
ConioProcessKey(MSG
*msg
, PCONSOLE Console
, BOOL TextMode
);
194 #define ConioRectHeight(Rect) \
195 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
196 #define ConioRectWidth(Rect) \
197 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
198 #define ConioGetScreenBuffer(ProcessData, Handle, Ptr, Access, LockConsole) \
199 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), (Access), (LockConsole), CONIO_SCREEN_BUFFER_MAGIC)
200 #define ConioReleaseScreenBuffer(Buff, IsConsoleLocked) \
201 Win32CsrUnlockObject(&(Buff)->Header, (IsConsoleLocked))
202 PBYTE FASTCALL
ConioCoordToPointer(PCONSOLE_SCREEN_BUFFER Buf
, ULONG X
, ULONG Y
);
203 VOID FASTCALL
ConioDrawConsole(PCONSOLE Console
);
204 NTSTATUS FASTCALL
ConioWriteConsole(PCONSOLE Console
, PCONSOLE_SCREEN_BUFFER Buff
,
205 CHAR
*Buffer
, DWORD Length
, BOOL Attrib
);
206 NTSTATUS FASTCALL
CsrInitConsoleScreenBuffer(PCONSOLE Console
, PCONSOLE_SCREEN_BUFFER Buffer
);
207 VOID WINAPI
ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer
);
208 DWORD FASTCALL
ConioEffectiveCursorSize(PCONSOLE Console
, DWORD Scale
);
211 VOID
IntDeleteAllAliases(struct _ALIAS_HEADER
*RootHeader
);
214 struct _HISTORY_BUFFER
;
215 VOID FASTCALL
HistoryDeleteBuffer(struct _HISTORY_BUFFER
*Hist
);
216 VOID FASTCALL
LineInputKeyDown(PCONSOLE Console
, KEY_EVENT_RECORD
*KeyEvent
);