1d1ab7f908dd42f64c8eda28eecead27f3792f92
[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 } CSRSS_SCREEN_BUFFER, *PCSRSS_SCREEN_BUFFER;
50
51 typedef struct tagCSRSS_CONSOLE *PCSRSS_CONSOLE;
52
53 typedef struct tagCSRSS_CONSOLE_VTBL
54 {
55 VOID (WINAPI *InitScreenBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
56 VOID (WINAPI *WriteStream)(PCSRSS_CONSOLE Console, RECT *Block, LONG CursorStartX, LONG CursorStartY,
57 UINT ScrolledLines, CHAR *Buffer, UINT Length);
58 VOID (WINAPI *DrawRegion)(PCSRSS_CONSOLE Console, RECT *Region);
59 BOOL (WINAPI *SetCursorInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
60 BOOL (WINAPI *SetScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer,
61 UINT OldCursorX, UINT OldCursorY);
62 BOOL (WINAPI *UpdateScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
63 BOOL (WINAPI *ChangeTitle)(PCSRSS_CONSOLE Console);
64 VOID (WINAPI *CleanupConsole)(PCSRSS_CONSOLE Console);
65 BOOL (WINAPI *ChangeIcon)(PCSRSS_CONSOLE Console, HICON hWindowIcon);
66 NTSTATUS (WINAPI *ResizeBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer, COORD Size);
67 } CSRSS_CONSOLE_VTBL, *PCSRSS_CONSOLE_VTBL;
68
69 typedef struct tagCSRSS_CONSOLE
70 {
71 Object_t Header; /* Object header */
72 PCSRSS_CONSOLE Prev, Next; /* Next and Prev consoles in console wheel */
73 HANDLE ActiveEvent;
74 LIST_ENTRY InputEvents; /* List head for input event queue */
75 WORD WaitingChars;
76 WORD WaitingLines; /* number of chars and lines in input queue */
77 PCSRSS_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
78 WORD Mode; /* Console mode flags */
79 WORD EchoCount; /* count of chars to echo, in line buffered mode */
80 UNICODE_STRING Title; /* Title of console */
81 BOOL EarlyReturn; /* wake client and return data, even if we are in line buffered mode, and we don't have a complete line */
82 DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
83 HWND hWindow;
84 COORD Size;
85 PVOID PrivateData;
86 UINT CodePage;
87 UINT OutputCodePage;
88 PCSRSS_CONSOLE_VTBL Vtbl;
89 LIST_ENTRY ProcessList;
90 struct tagALIAS_HEADER *Aliases;
91 } CSRSS_CONSOLE;
92
93 typedef struct ConsoleInput_t
94 {
95 LIST_ENTRY ListEntry;
96 INPUT_RECORD InputEvent;
97 BOOLEAN Echoed; // already been echoed or not
98 BOOLEAN Fake; // synthesized, not a real event
99 BOOLEAN NotChar; // message should not be used to return a character
100 } ConsoleInput;
101
102 NTSTATUS FASTCALL ConioConsoleFromProcessData(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_CONSOLE *Console);
103 VOID WINAPI ConioDeleteConsole(Object_t *Object);
104 VOID WINAPI ConioDeleteScreenBuffer(Object_t *Buffer);
105 VOID WINAPI CsrInitConsoleSupport(VOID);
106 void WINAPI ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode);
107 PBYTE FASTCALL ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
108 VOID FASTCALL ConioDrawConsole(PCSRSS_CONSOLE Console);
109 VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData);
110 VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event, PCSRSS_PROCESS_DATA ProcessData,
111 DWORD Timeout);
112
113 /* api/conio.c */
114 CSR_API(CsrWriteConsole);
115 CSR_API(CsrAllocConsole);
116 CSR_API(CsrFreeConsole);
117 CSR_API(CsrReadConsole);
118 CSR_API(CsrConnectProcess);
119 CSR_API(CsrGetScreenBufferInfo);
120 CSR_API(CsrSetCursor);
121 CSR_API(CsrFillOutputChar);
122 CSR_API(CsrReadInputEvent);
123 CSR_API(CsrWriteConsoleOutputChar);
124 CSR_API(CsrWriteConsoleOutputAttrib);
125 CSR_API(CsrFillOutputAttrib);
126 CSR_API(CsrGetCursorInfo);
127 CSR_API(CsrSetCursorInfo);
128 CSR_API(CsrSetTextAttrib);
129 CSR_API(CsrSetConsoleMode);
130 CSR_API(CsrGetConsoleMode);
131 CSR_API(CsrCreateScreenBuffer);
132 CSR_API(CsrSetScreenBuffer);
133 CSR_API(CsrSetTitle);
134 CSR_API(CsrGetTitle);
135 CSR_API(CsrWriteConsoleOutput);
136 CSR_API(CsrFlushInputBuffer);
137 CSR_API(CsrScrollConsoleScreenBuffer);
138 CSR_API(CsrReadConsoleOutputChar);
139 CSR_API(CsrReadConsoleOutputAttrib);
140 CSR_API(CsrGetNumberOfConsoleInputEvents);
141 CSR_API(CsrPeekConsoleInput);
142 CSR_API(CsrReadConsoleOutput);
143 CSR_API(CsrWriteConsoleInput);
144 CSR_API(CsrHardwareStateProperty);
145 CSR_API(CsrGetConsoleWindow);
146 CSR_API(CsrSetConsoleIcon);
147 CSR_API(CsrGetConsoleCodePage);
148 CSR_API(CsrSetConsoleCodePage);
149 CSR_API(CsrGetConsoleOutputCodePage);
150 CSR_API(CsrSetConsoleOutputCodePage);
151 CSR_API(CsrGetProcessList);
152 CSR_API(CsrGenerateCtrlEvent);
153 CSR_API(CsrSetScreenBufferSize);
154
155 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
156 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
157 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
158 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
159 (ScrolledLines), (Buffer), (Length))
160 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
161 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
162 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
163 #define ConioUpdateScreenInfo(Console, Buff) \
164 (Console)->Vtbl->UpdateScreenInfo(Console, Buff)
165 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
166 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
167 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon(Console, hWindowIcon)
168 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer(Console, Buff, Size)
169
170 #define ConioRectHeight(Rect) \
171 (((Rect)->top) > ((Rect)->bottom) ? 0 : ((Rect)->bottom) - ((Rect)->top) + 1)
172 #define ConioRectWidth(Rect) \
173 (((Rect)->left) > ((Rect)->right) ? 0 : ((Rect)->right) - ((Rect)->left) + 1)
174
175 #define ConioLockConsole(ProcessData, Handle, Ptr, Access) \
176 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_CONSOLE_MAGIC)
177 #define ConioUnlockConsole(Console) \
178 Win32CsrUnlockObject((Object_t *) Console)
179 #define ConioLockScreenBuffer(ProcessData, Handle, Ptr, Access) \
180 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_SCREEN_BUFFER_MAGIC)
181 #define ConioUnlockScreenBuffer(Buff) \
182 Win32CsrUnlockObject((Object_t *) Buff)
183
184 /* alias.c */
185 VOID IntDeleteAllAliases(struct tagALIAS_HEADER *RootHeader);
186 CSR_API(CsrAddConsoleAlias);
187 CSR_API(CsrGetConsoleAlias);
188 CSR_API(CsrGetAllConsoleAliases);
189 CSR_API(CsrGetAllConsoleAliasesLength);
190 CSR_API(CsrGetConsoleAliasesExes);
191 CSR_API(CsrGetConsoleAliasesExesLength);
192
193 /* EOF */