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 /* Object type magic numbers */
15 #define CONIO_CONSOLE_MAGIC 0x00000001
16 #define CONIO_SCREEN_BUFFER_MAGIC 0x00000002
18 /************************************************************************
19 * Screen buffer structure represents the win32 screen buffer object. *
20 * Internally, the portion of the buffer being shown CAN loop past the *
21 * bottom of the virtual buffer and wrap around to the top. Win32 does *
22 * not do this. I decided to do this because it eliminates the need to *
23 * do a massive memcpy() to scroll the contents of the buffer up to *
24 * scroll the screen on output, instead I just shift down the position *
25 * to be displayed, and let it wrap around to the top again. *
26 * The VirtualY member keeps track of the top Y coord that win32 *
27 * clients THINK is currently being displayed, because they think that *
28 * when the display reaches the bottom of the buffer and another line *
29 * being printed causes another line to scroll down, that the buffer IS *
30 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
31 * internally, I just wrap back to the top of the buffer. *
32 ***********************************************************************/
34 typedef struct tagCSRSS_SCREEN_BUFFER
36 Object_t Header
; /* Object header */
37 BYTE
*Buffer
; /* pointer to screen buffer */
38 USHORT MaxX
, MaxY
; /* size of the entire scrollback buffer */
39 USHORT ShowX
, ShowY
; /* beginning offset for the actual display area */
40 ULONG CurrentX
; /* Current X cursor position */
41 ULONG CurrentY
; /* Current Y cursor position */
42 WORD DefaultAttrib
; /* default char attribute */
43 USHORT VirtualY
; /* top row of buffer being displayed, reported to callers */
44 CONSOLE_CURSOR_INFO CursorInfo
;
46 LIST_ENTRY ListEntry
; /* entry in console's list of buffers */
47 } CSRSS_SCREEN_BUFFER
, *PCSRSS_SCREEN_BUFFER
;
49 typedef struct tagCSRSS_CONSOLE
51 Object_t Header
; /* Object header */
53 CRITICAL_SECTION Lock
;
55 struct tagCSRSS_CONSOLE
*Prev
, *Next
; /* Next and Prev consoles in console wheel */
56 struct tagCSRSS_CONSOLE_VTBL
*Vtbl
; /* Using CUI or GUI consoles */
58 LIST_ENTRY ProcessList
;
60 LIST_ENTRY InputEvents
; /* List head for input event queue */
61 HANDLE ActiveEvent
; /* Event set when an input event is added in its queue */
62 LIST_ENTRY ReadWaitQueue
; /* List head for the queue of read wait blocks */
64 PWCHAR LineBuffer
; /* current line being input, in line buffered mode */
65 WORD LineMaxSize
; /* maximum size of line in characters (including CR+LF) */
66 WORD LineSize
; /* current size of line */
67 WORD LinePos
; /* current position within line */
68 BOOLEAN LineComplete
; /* user pressed enter, ready to send back to client */
69 BOOLEAN LineUpPressed
;
70 BOOLEAN LineInsertToggle
; /* replace character over cursor instead of inserting */
71 ULONG LineWakeupMask
; /* bitmap of which control characters will end line input */
73 struct tagALIAS_HEADER
*Aliases
;
74 LIST_ENTRY HistoryBuffers
;
75 UINT HistoryBufferSize
; /* size for newly created history buffers */
76 UINT NumberOfHistoryBuffers
; /* maximum number of history buffers allowed */
77 BOOLEAN HistoryNoDup
; /* remove old duplicate history entries */
79 LIST_ENTRY BufferList
; /* List of all screen buffers for this console */
80 PCSRSS_SCREEN_BUFFER ActiveBuffer
; /* Pointer to currently active screen buffer */
83 LIST_ENTRY WriteWaitQueue
; /* List head for the queue of write wait blocks */
85 WORD Mode
; /* Console mode flags */
86 UNICODE_STRING Title
; /* Title of console */
87 DWORD HardwareState
; /* _GDI_MANAGED, _DIRECT */
95 CONSOLE_SELECTION_INFO Selection
;
96 } CSRSS_CONSOLE
, *PCSRSS_CONSOLE
;
98 typedef struct tagCSRSS_CONSOLE_VTBL
100 VOID (WINAPI
*InitScreenBuffer
)(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER ScreenBuffer
);
101 VOID (WINAPI
*WriteStream
)(PCSRSS_CONSOLE Console
, SMALL_RECT
*Block
, LONG CursorStartX
, LONG CursorStartY
,
102 UINT ScrolledLines
, CHAR
*Buffer
, UINT Length
);
103 VOID (WINAPI
*DrawRegion
)(PCSRSS_CONSOLE Console
, SMALL_RECT
*Region
);
104 BOOL (WINAPI
*SetCursorInfo
)(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER ScreenBuffer
);
105 BOOL (WINAPI
*SetScreenInfo
)(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER ScreenBuffer
,
106 UINT OldCursorX
, UINT OldCursorY
);
107 BOOL (WINAPI
*UpdateScreenInfo
)(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER ScreenBuffer
);
108 BOOL (WINAPI
*ChangeTitle
)(PCSRSS_CONSOLE Console
);
109 VOID (WINAPI
*CleanupConsole
)(PCSRSS_CONSOLE Console
);
110 BOOL (WINAPI
*ChangeIcon
)(PCSRSS_CONSOLE Console
, HICON hWindowIcon
);
111 NTSTATUS (WINAPI
*ResizeBuffer
)(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER ScreenBuffer
, COORD Size
);
112 } CSRSS_CONSOLE_VTBL
, *PCSRSS_CONSOLE_VTBL
;
114 typedef struct ConsoleInput_t
116 LIST_ENTRY ListEntry
;
117 INPUT_RECORD InputEvent
;
120 /* CONSOLE_SELECTION_INFO dwFlags values */
121 #define CONSOLE_NO_SELECTION 0x0
122 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
123 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
124 #define CONSOLE_MOUSE_SELECTION 0x4
125 #define CONSOLE_MOUSE_DOWN 0x8
126 /* HistoryFlags values */
127 #define HISTORY_NO_DUP_FLAG 0x1
129 /* PauseFlags values (internal only) */
130 #define PAUSED_FROM_KEYBOARD 0x1
131 #define PAUSED_FROM_SCROLLBAR 0x2
132 #define PAUSED_FROM_SELECTION 0x4
134 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
135 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
136 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
137 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
138 (ScrolledLines), (Buffer), (Length))
139 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
140 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
141 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
142 #define ConioUpdateScreenInfo(Console, Buff) \
143 (Console)->Vtbl->UpdateScreenInfo(Console, Buff)
144 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
145 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
146 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon(Console, hWindowIcon)
147 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer(Console, Buff, Size)
150 NTSTATUS FASTCALL
ConioConsoleFromProcessData(PCONSOLE_PROCESS_DATA ProcessData
,
151 PCSRSS_CONSOLE
*Console
);
152 VOID WINAPI
ConioDeleteConsole(Object_t
*Object
);
153 VOID WINAPI
CsrInitConsoleSupport(VOID
);
154 VOID FASTCALL
ConioPause(PCSRSS_CONSOLE Console
, UINT Flags
);
155 VOID FASTCALL
ConioUnpause(PCSRSS_CONSOLE Console
, UINT Flags
);
156 VOID FASTCALL
ConioConsoleCtrlEvent(DWORD Event
, PCONSOLE_PROCESS_DATA ProcessData
);
157 VOID FASTCALL
ConioConsoleCtrlEventTimeout(DWORD Event
,
158 PCONSOLE_PROCESS_DATA ProcessData
,
162 #define ConioLockConsole(ProcessData, Handle, Ptr, Access) \
163 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_CONSOLE_MAGIC)
164 #define ConioUnlockConsole(Console) \
165 Win32CsrUnlockObject((Object_t *) Console)
166 void WINAPI
ConioProcessKey(MSG
*msg
, PCSRSS_CONSOLE Console
, BOOL TextMode
);
169 #define ConioRectHeight(Rect) \
170 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
171 #define ConioRectWidth(Rect) \
172 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
173 #define ConioLockScreenBuffer(ProcessData, Handle, Ptr, Access) \
174 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_SCREEN_BUFFER_MAGIC)
175 #define ConioUnlockScreenBuffer(Buff) \
176 Win32CsrUnlockObject((Object_t *) Buff)
177 PBYTE FASTCALL
ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buf
, ULONG X
, ULONG Y
);
178 VOID FASTCALL
ConioDrawConsole(PCSRSS_CONSOLE Console
);
179 NTSTATUS FASTCALL
ConioWriteConsole(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
,
180 CHAR
*Buffer
, DWORD Length
, BOOL Attrib
);
181 NTSTATUS FASTCALL
CsrInitConsoleScreenBuffer(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buffer
);
182 VOID WINAPI
ConioDeleteScreenBuffer(PCSRSS_SCREEN_BUFFER Buffer
);
183 DWORD FASTCALL
ConioEffectiveCursorSize(PCSRSS_CONSOLE Console
, DWORD Scale
);
186 VOID
IntDeleteAllAliases(struct tagALIAS_HEADER
*RootHeader
);
189 struct tagHISTORY_BUFFER
;
190 VOID FASTCALL
HistoryDeleteBuffer(struct tagHISTORY_BUFFER
*Hist
);
191 VOID FASTCALL
LineInputKeyDown(PCSRSS_CONSOLE Console
, KEY_EVENT_RECORD
*KeyEvent
);