[WIN32CSR]
[reactos.git] / reactos / subsystems / win32 / csrss / win32csr / conio.h
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: subsys/csrss/include/conio.h
6 * PURPOSE: CSRSS internal console I/O interface
7 */
8
9 #pragma once
10
11 #include "api.h"
12 #include "win32csr.h"
13
14 #define CSR_DEFAULT_CURSOR_SIZE 25
15
16 /* Object type magic numbers */
17
18 #define CONIO_CONSOLE_MAGIC 0x00000001
19 #define CONIO_SCREEN_BUFFER_MAGIC 0x00000002
20
21 /************************************************************************
22 * Screen buffer structure represents the win32 screen buffer object. *
23 * Internally, the portion of the buffer being shown CAN loop past the *
24 * bottom of the virtual buffer and wrap around to the top. Win32 does *
25 * not do this. I decided to do this because it eliminates the need to *
26 * do a massive memcpy() to scroll the contents of the buffer up to *
27 * scroll the screen on output, instead I just shift down the position *
28 * to be displayed, and let it wrap around to the top again. *
29 * The VirtualY member keeps track of the top Y coord that win32 *
30 * clients THINK is currently being displayed, because they think that *
31 * when the display reaches the bottom of the buffer and another line *
32 * being printed causes another line to scroll down, that the buffer IS *
33 * memcpy()'s up, and the bottom of the buffer is still displayed, but *
34 * internally, I just wrap back to the top of the buffer. *
35 ***********************************************************************/
36
37 typedef struct tagCSRSS_SCREEN_BUFFER
38 {
39 Object_t Header; /* Object header */
40 BYTE *Buffer; /* pointer to screen buffer */
41 USHORT MaxX, MaxY; /* size of the entire scrollback buffer */
42 USHORT ShowX, ShowY; /* beginning offset for the actual display area */
43 ULONG CurrentX; /* Current X cursor position */
44 ULONG CurrentY; /* Current Y cursor position */
45 WORD DefaultAttrib; /* default char attribute */
46 USHORT VirtualY; /* top row of buffer being displayed, reported to callers */
47 CONSOLE_CURSOR_INFO CursorInfo;
48 USHORT Mode;
49 LIST_ENTRY ListEntry; /* entry in console's list of buffers */
50 } CSRSS_SCREEN_BUFFER, *PCSRSS_SCREEN_BUFFER;
51
52 typedef struct tagCSRSS_CONSOLE *PCSRSS_CONSOLE;
53
54 typedef struct tagCSRSS_CONSOLE_VTBL
55 {
56 VOID (WINAPI *InitScreenBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
57 VOID (WINAPI *WriteStream)(PCSRSS_CONSOLE Console, SMALL_RECT *Block, LONG CursorStartX, LONG CursorStartY,
58 UINT ScrolledLines, CHAR *Buffer, UINT Length);
59 VOID (WINAPI *DrawRegion)(PCSRSS_CONSOLE Console, SMALL_RECT *Region);
60 BOOL (WINAPI *SetCursorInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
61 BOOL (WINAPI *SetScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer,
62 UINT OldCursorX, UINT OldCursorY);
63 BOOL (WINAPI *UpdateScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
64 BOOL (WINAPI *ChangeTitle)(PCSRSS_CONSOLE Console);
65 VOID (WINAPI *CleanupConsole)(PCSRSS_CONSOLE Console);
66 BOOL (WINAPI *ChangeIcon)(PCSRSS_CONSOLE Console, HICON hWindowIcon);
67 NTSTATUS (WINAPI *ResizeBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer, COORD Size);
68 } CSRSS_CONSOLE_VTBL, *PCSRSS_CONSOLE_VTBL;
69
70 typedef struct tagCSRSS_CONSOLE
71 {
72 Object_t Header; /* Object header */
73 LONG ReferenceCount;
74 CRITICAL_SECTION Lock;
75 PCSRSS_CONSOLE Prev, Next; /* Next and Prev consoles in console wheel */
76 HANDLE ActiveEvent;
77 LIST_ENTRY InputEvents; /* List head for input event queue */
78 WORD WaitingChars;
79 WORD WaitingLines; /* number of chars and lines in input queue */
80 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
81 PCSRSS_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
82 WORD Mode; /* Console mode flags */
83 WORD EchoCount; /* count of chars to echo, in line buffered mode */
84 UNICODE_STRING Title; /* Title of console */
85 BOOL EarlyReturn; /* wake client and return data, even if we are in line buffered mode, and we don't have a complete line */
86 DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
87 HWND hWindow;
88 COORD Size;
89 PVOID PrivateData;
90 UINT CodePage;
91 UINT OutputCodePage;
92 PCSRSS_CONSOLE_VTBL Vtbl;
93 LIST_ENTRY ProcessList;
94 struct tagALIAS_HEADER *Aliases;
95 CONSOLE_SELECTION_INFO Selection;
96 } CSRSS_CONSOLE;
97
98 typedef struct ConsoleInput_t
99 {
100 LIST_ENTRY ListEntry;
101 INPUT_RECORD InputEvent;
102 BOOLEAN Echoed; // already been echoed or not
103 BOOLEAN Fake; // synthesized, not a real event
104 BOOLEAN NotChar; // message should not be used to return a character
105 } ConsoleInput;
106
107 /* CONSOLE_SELECTION_INFO dwFlags values */
108 #define CONSOLE_NO_SELECTION 0x0
109 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
110 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
111 #define CONSOLE_MOUSE_SELECTION 0x4
112 #define CONSOLE_MOUSE_DOWN 0x8
113
114 NTSTATUS FASTCALL ConioConsoleFromProcessData(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_CONSOLE *Console);
115 VOID WINAPI ConioDeleteConsole(Object_t *Object);
116 VOID WINAPI ConioDeleteScreenBuffer(PCSRSS_SCREEN_BUFFER Buffer);
117 VOID WINAPI CsrInitConsoleSupport(VOID);
118 void WINAPI ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode);
119 PBYTE FASTCALL ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
120 VOID FASTCALL ConioDrawConsole(PCSRSS_CONSOLE Console);
121 VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData);
122 VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event, PCSRSS_PROCESS_DATA ProcessData,
123 DWORD Timeout);
124
125 /* api/conio.c */
126 CSR_API(CsrWriteConsole);
127 CSR_API(CsrAllocConsole);
128 CSR_API(CsrFreeConsole);
129 CSR_API(CsrReadConsole);
130 CSR_API(CsrConnectProcess);
131 CSR_API(CsrGetScreenBufferInfo);
132 CSR_API(CsrSetCursor);
133 CSR_API(CsrFillOutputChar);
134 CSR_API(CsrReadInputEvent);
135 CSR_API(CsrWriteConsoleOutputChar);
136 CSR_API(CsrWriteConsoleOutputAttrib);
137 CSR_API(CsrFillOutputAttrib);
138 CSR_API(CsrGetCursorInfo);
139 CSR_API(CsrSetCursorInfo);
140 CSR_API(CsrSetTextAttrib);
141 CSR_API(CsrSetConsoleMode);
142 CSR_API(CsrGetConsoleMode);
143 CSR_API(CsrCreateScreenBuffer);
144 CSR_API(CsrSetScreenBuffer);
145 CSR_API(CsrSetTitle);
146 CSR_API(CsrGetTitle);
147 CSR_API(CsrWriteConsoleOutput);
148 CSR_API(CsrFlushInputBuffer);
149 CSR_API(CsrScrollConsoleScreenBuffer);
150 CSR_API(CsrReadConsoleOutputChar);
151 CSR_API(CsrReadConsoleOutputAttrib);
152 CSR_API(CsrGetNumberOfConsoleInputEvents);
153 CSR_API(CsrPeekConsoleInput);
154 CSR_API(CsrReadConsoleOutput);
155 CSR_API(CsrWriteConsoleInput);
156 CSR_API(CsrHardwareStateProperty);
157 CSR_API(CsrGetConsoleWindow);
158 CSR_API(CsrSetConsoleIcon);
159 CSR_API(CsrGetConsoleCodePage);
160 CSR_API(CsrSetConsoleCodePage);
161 CSR_API(CsrGetConsoleOutputCodePage);
162 CSR_API(CsrSetConsoleOutputCodePage);
163 CSR_API(CsrGetProcessList);
164 CSR_API(CsrGenerateCtrlEvent);
165 CSR_API(CsrSetScreenBufferSize);
166 CSR_API(CsrGetConsoleSelectionInfo);
167
168 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
169 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
170 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
171 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
172 (ScrolledLines), (Buffer), (Length))
173 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
174 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
175 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
176 #define ConioUpdateScreenInfo(Console, Buff) \
177 (Console)->Vtbl->UpdateScreenInfo(Console, Buff)
178 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
179 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
180 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon(Console, hWindowIcon)
181 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer(Console, Buff, Size)
182
183 #define ConioRectHeight(Rect) \
184 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
185 #define ConioRectWidth(Rect) \
186 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
187
188 #define ConioLockConsole(ProcessData, Handle, Ptr, Access) \
189 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_CONSOLE_MAGIC)
190 #define ConioUnlockConsole(Console) \
191 Win32CsrUnlockObject((Object_t *) Console)
192 #define ConioLockScreenBuffer(ProcessData, Handle, Ptr, Access) \
193 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_SCREEN_BUFFER_MAGIC)
194 #define ConioUnlockScreenBuffer(Buff) \
195 Win32CsrUnlockObject((Object_t *) Buff)
196
197 /* alias.c */
198 VOID IntDeleteAllAliases(struct tagALIAS_HEADER *RootHeader);
199 CSR_API(CsrAddConsoleAlias);
200 CSR_API(CsrGetConsoleAlias);
201 CSR_API(CsrGetAllConsoleAliases);
202 CSR_API(CsrGetAllConsoleAliasesLength);
203 CSR_API(CsrGetConsoleAliasesExes);
204 CSR_API(CsrGetConsoleAliasesExesLength);
205
206 /* EOF */