[KERNEL32]
[reactos.git] / win32ss / user / consrv / conio.h
1 /*
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
6 * PROGRAMMERS:
7 */
8
9 #pragma once
10
11 #define CSR_DEFAULT_CURSOR_SIZE 25
12
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 ************************************************************************/
28
29 typedef struct tagCSRSS_SCREEN_BUFFER
30 {
31 Object_t Header; /* Object header */
32 LIST_ENTRY ListEntry; /* Entry in console's list of buffers */
33
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;
42 USHORT Mode;
43 } CSRSS_SCREEN_BUFFER, *PCSRSS_SCREEN_BUFFER;
44
45 typedef struct tagCSRSS_CONSOLE
46 {
47 Object_t Header; /* Object header */
48 LONG ReferenceCount;
49 CRITICAL_SECTION Lock;
50
51 struct tagCSRSS_CONSOLE *Prev, *Next; /* Next and Prev consoles in console wheel */
52 struct tagCSRSS_CONSOLE_VTBL *Vtbl; /* Using CUI or GUI consoles */
53
54 LIST_ENTRY ProcessList;
55
56 LIST_ENTRY InputEvents; /* List head for input event queue */
57 HANDLE ActiveEvent; /* Event set when an input event is added in its queue */
58 LIST_ENTRY ReadWaitQueue; /* List head for the queue of read wait blocks */
59
60 PWCHAR LineBuffer; /* current line being input, in line buffered mode */
61 WORD LineMaxSize; /* maximum size of line in characters (including CR+LF) */
62 WORD LineSize; /* current size of line */
63 WORD LinePos; /* current position within line */
64 BOOLEAN LineComplete; /* user pressed enter, ready to send back to client */
65 BOOLEAN LineUpPressed;
66 BOOLEAN LineInsertToggle; /* replace character over cursor instead of inserting */
67 ULONG LineWakeupMask; /* bitmap of which control characters will end line input */
68
69 struct tagALIAS_HEADER *Aliases;
70 LIST_ENTRY HistoryBuffers;
71 UINT HistoryBufferSize; /* size for newly created history buffers */
72 UINT NumberOfHistoryBuffers; /* maximum number of history buffers allowed */
73 BOOLEAN HistoryNoDup; /* remove old duplicate history entries */
74
75 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
76 PCSRSS_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
77 BYTE PauseFlags;
78 HANDLE UnpauseEvent;
79 LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks */
80
81 #if 0
82 /* Pointers to lists of wait blocks, when they contain satisfied waits to be freed */
83 PLIST_ENTRY SatisfiedWaits;
84
85 /* Pointers to lists of wait blocks, when they contain satisfied waits to be freed */
86 PLIST_ENTRY ReadSatisfiedWaits;
87 PLIST_ENTRY WriteSatisfiedWaits;
88 #endif
89
90 WORD Mode; /* Console mode flags */
91 UNICODE_STRING Title; /* Title of console */
92 DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
93 HWND hWindow;
94 COORD Size;
95 PVOID PrivateData;
96
97 UINT CodePage;
98 UINT OutputCodePage;
99
100 CONSOLE_SELECTION_INFO Selection;
101 } CSRSS_CONSOLE, *PCSRSS_CONSOLE;
102
103 typedef struct tagCSRSS_CONSOLE_VTBL
104 {
105 VOID (WINAPI *InitScreenBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
106 VOID (WINAPI *WriteStream)(PCSRSS_CONSOLE Console, SMALL_RECT *Block, LONG CursorStartX, LONG CursorStartY,
107 UINT ScrolledLines, CHAR *Buffer, UINT Length);
108 VOID (WINAPI *DrawRegion)(PCSRSS_CONSOLE Console, SMALL_RECT *Region);
109 BOOL (WINAPI *SetCursorInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
110 BOOL (WINAPI *SetScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer,
111 UINT OldCursorX, UINT OldCursorY);
112 BOOL (WINAPI *UpdateScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
113 BOOL (WINAPI *ChangeTitle)(PCSRSS_CONSOLE Console);
114 VOID (WINAPI *CleanupConsole)(PCSRSS_CONSOLE Console);
115 BOOL (WINAPI *ChangeIcon)(PCSRSS_CONSOLE Console, HICON hWindowIcon);
116 NTSTATUS (WINAPI *ResizeBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer, COORD Size);
117 } CSRSS_CONSOLE_VTBL, *PCSRSS_CONSOLE_VTBL;
118
119 typedef struct ConsoleInput_t
120 {
121 LIST_ENTRY ListEntry;
122 INPUT_RECORD InputEvent;
123 } ConsoleInput;
124
125 /* CONSOLE_SELECTION_INFO dwFlags values */
126 #define CONSOLE_NO_SELECTION 0x0
127 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
128 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
129 #define CONSOLE_MOUSE_SELECTION 0x4
130 #define CONSOLE_MOUSE_DOWN 0x8
131 /* HistoryFlags values */
132 #define HISTORY_NO_DUP_FLAG 0x1
133
134 /* PauseFlags values (internal only) */
135 #define PAUSED_FROM_KEYBOARD 0x1
136 #define PAUSED_FROM_SCROLLBAR 0x2
137 #define PAUSED_FROM_SELECTION 0x4
138
139 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
140 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
141 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
142 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
143 (ScrolledLines), (Buffer), (Length))
144 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
145 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
146 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
147 #define ConioUpdateScreenInfo(Console, Buff) \
148 (Console)->Vtbl->UpdateScreenInfo(Console, Buff)
149 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
150 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
151 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon(Console, hWindowIcon)
152 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer(Console, Buff, Size)
153
154 /* console.c */
155 NTSTATUS FASTCALL ConioConsoleFromProcessData(PCONSOLE_PROCESS_DATA ProcessData,
156 PCSRSS_CONSOLE *Console);
157 VOID WINAPI ConioDeleteConsole(PCSRSS_CONSOLE Console);
158 VOID WINAPI CsrInitConsoleSupport(VOID);
159 VOID FASTCALL ConioPause(PCSRSS_CONSOLE Console, UINT Flags);
160 VOID FASTCALL ConioUnpause(PCSRSS_CONSOLE Console, UINT Flags);
161 VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCONSOLE_PROCESS_DATA ProcessData);
162 VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event,
163 PCONSOLE_PROCESS_DATA ProcessData,
164 DWORD Timeout);
165
166 /* coninput.c */
167 #define ConioLockConsole(ProcessData, Handle, Ptr, Access) \
168 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_CONSOLE_MAGIC)
169 #define ConioUnlockConsole(Console) \
170 Win32CsrUnlockObject((Object_t *) Console)
171 void WINAPI ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode);
172
173 /* conoutput.c */
174 #define ConioRectHeight(Rect) \
175 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
176 #define ConioRectWidth(Rect) \
177 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
178 #define ConioLockScreenBuffer(ProcessData, Handle, Ptr, Access) \
179 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_SCREEN_BUFFER_MAGIC)
180 #define ConioUnlockScreenBuffer(Buff) \
181 Win32CsrUnlockObject((Object_t *) Buff)
182 PBYTE FASTCALL ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
183 VOID FASTCALL ConioDrawConsole(PCSRSS_CONSOLE Console);
184 NTSTATUS FASTCALL ConioWriteConsole(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff,
185 CHAR *Buffer, DWORD Length, BOOL Attrib);
186 NTSTATUS FASTCALL CsrInitConsoleScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer);
187 VOID WINAPI ConioDeleteScreenBuffer(PCSRSS_SCREEN_BUFFER Buffer);
188 DWORD FASTCALL ConioEffectiveCursorSize(PCSRSS_CONSOLE Console, DWORD Scale);
189
190 /* alias.c */
191 VOID IntDeleteAllAliases(struct tagALIAS_HEADER *RootHeader);
192
193 /* lineinput.c */
194 struct tagHISTORY_BUFFER;
195 VOID FASTCALL HistoryDeleteBuffer(struct tagHISTORY_BUFFER *Hist);
196 VOID FASTCALL LineInputKeyDown(PCSRSS_CONSOLE Console, KEY_EVENT_RECORD *KeyEvent);
197
198 /* EOF */