[CONSRV]
[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 _CONSOLE_SCREEN_BUFFER
30 {
31 Object_t Header; /* Object header */
32 BYTE *Buffer; /* pointer to screen buffer */
33 USHORT MaxX, MaxY; /* size of the entire scrollback buffer */
34 USHORT ShowX, ShowY; /* beginning offset for the actual display area */
35 ULONG CurrentX; /* Current X cursor position */
36 ULONG CurrentY; /* Current Y cursor position */
37 WORD DefaultAttrib; /* default char attribute */
38 USHORT VirtualY; /* top row of buffer being displayed, reported to callers */
39 CONSOLE_CURSOR_INFO CursorInfo;
40 USHORT Mode;
41 LIST_ENTRY ListEntry; /* entry in console's list of buffers */
42 } CONSOLE_SCREEN_BUFFER, *PCONSOLE_SCREEN_BUFFER;
43
44 typedef struct _CONSOLE
45 {
46 Object_t Header; /* Object header */
47 LONG ReferenceCount;
48 CRITICAL_SECTION Lock;
49
50 struct _CONSOLE *Prev, *Next; /* Next and Prev consoles in console wheel */
51 struct _CONSOLE_VTBL *Vtbl; /* Using CUI or GUI consoles */
52
53 CLIENT_ID ConsoleLeaderCID; /* Contains the Console Leader Process CID */
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 _ALIAS_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 PCONSOLE_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 WORD Mode; /* Console mode flags */
82 UNICODE_STRING Title; /* Title of console */
83 DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
84 HWND hWindow;
85 COORD Size;
86 PVOID PrivateData;
87
88 UINT CodePage;
89 UINT OutputCodePage;
90
91 CONSOLE_SELECTION_INFO Selection;
92 } CONSOLE, *PCONSOLE;
93
94 /**************************************************************\
95 \** Define the Console Leader Process for the console window **/
96 #define GWLP_CONSOLEWND_ALLOC (2 * sizeof(LONG_PTR))
97 #define GWLP_CONSOLE_LEADER_PID 0
98 #define GWLP_CONSOLE_LEADER_TID 4
99
100 #define SetConsoleWndConsoleLeaderCID(Console) \
101 do { \
102 SetWindowLongPtrW((Console)->hWindow, GWLP_CONSOLE_LEADER_PID, (LONG_PTR)((Console)->ConsoleLeaderCID.UniqueProcess)); \
103 SetWindowLongPtrW((Console)->hWindow, GWLP_CONSOLE_LEADER_TID, (LONG_PTR)((Console)->ConsoleLeaderCID.UniqueThread )); \
104 } while(0)
105 /**************************************************************/
106
107 typedef struct _CONSOLE_VTBL
108 {
109 VOID (WINAPI *InitScreenBuffer)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
110 VOID (WINAPI *WriteStream)(PCONSOLE Console, SMALL_RECT *Block, LONG CursorStartX, LONG CursorStartY,
111 UINT ScrolledLines, CHAR *Buffer, UINT Length);
112 VOID (WINAPI *DrawRegion)(PCONSOLE Console, SMALL_RECT *Region);
113 BOOL (WINAPI *SetCursorInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
114 BOOL (WINAPI *SetScreenInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer,
115 UINT OldCursorX, UINT OldCursorY);
116 BOOL (WINAPI *UpdateScreenInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
117 BOOL (WINAPI *ChangeTitle)(PCONSOLE Console);
118 VOID (WINAPI *CleanupConsole)(PCONSOLE Console);
119 BOOL (WINAPI *ChangeIcon)(PCONSOLE Console, HICON hWindowIcon);
120 NTSTATUS (WINAPI *ResizeBuffer)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Size);
121 } CONSOLE_VTBL, *PCONSOLE_VTBL;
122
123 typedef struct ConsoleInput_t
124 {
125 LIST_ENTRY ListEntry;
126 INPUT_RECORD InputEvent;
127 } ConsoleInput;
128
129 /* CONSOLE_SELECTION_INFO dwFlags values */
130 #define CONSOLE_NO_SELECTION 0x0
131 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
132 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
133 #define CONSOLE_MOUSE_SELECTION 0x4
134 #define CONSOLE_MOUSE_DOWN 0x8
135 /* HistoryFlags values */
136 #define HISTORY_NO_DUP_FLAG 0x1
137
138 /* PauseFlags values (internal only) */
139 #define PAUSED_FROM_KEYBOARD 0x1
140 #define PAUSED_FROM_SCROLLBAR 0x2
141 #define PAUSED_FROM_SELECTION 0x4
142
143 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
144 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
145 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
146 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
147 (ScrolledLines), (Buffer), (Length))
148 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
149 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
150 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
151 #define ConioUpdateScreenInfo(Console, Buff) \
152 (Console)->Vtbl->UpdateScreenInfo(Console, Buff)
153 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
154 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
155 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon(Console, hWindowIcon)
156 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer(Console, Buff, Size)
157
158 /* console.c */
159 NTSTATUS FASTCALL ConioConsoleFromProcessData(PCONSOLE_PROCESS_DATA ProcessData,
160 PCONSOLE *Console);
161 VOID WINAPI ConioDeleteConsole(PCONSOLE Console);
162 VOID WINAPI CsrInitConsoleSupport(VOID);
163 NTSTATUS WINAPI CsrInitConsole(PCONSOLE* NewConsole, int ShowCmd, PCSR_PROCESS ConsoleLeaderProcess);
164 VOID FASTCALL ConioPause(PCONSOLE Console, UINT Flags);
165 VOID FASTCALL ConioUnpause(PCONSOLE Console, UINT Flags);
166 VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCONSOLE_PROCESS_DATA ProcessData);
167 VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event,
168 PCONSOLE_PROCESS_DATA ProcessData,
169 DWORD Timeout);
170
171 /* coninput.c */
172 #define ConioLockConsole(ProcessData, Handle, Ptr, Access) \
173 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_CONSOLE_MAGIC)
174 #define ConioUnlockConsole(Console) \
175 Win32CsrUnlockObject((Object_t *) Console)
176 void WINAPI ConioProcessKey(MSG *msg, PCONSOLE Console, BOOL TextMode);
177
178 /* conoutput.c */
179 #define ConioRectHeight(Rect) \
180 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
181 #define ConioRectWidth(Rect) \
182 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
183 #define ConioLockScreenBuffer(ProcessData, Handle, Ptr, Access) \
184 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_SCREEN_BUFFER_MAGIC)
185 #define ConioUnlockScreenBuffer(Buff) \
186 Win32CsrUnlockObject((Object_t *) Buff)
187 PBYTE FASTCALL ConioCoordToPointer(PCONSOLE_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
188 VOID FASTCALL ConioDrawConsole(PCONSOLE Console);
189 NTSTATUS FASTCALL ConioWriteConsole(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER Buff,
190 CHAR *Buffer, DWORD Length, BOOL Attrib);
191 NTSTATUS FASTCALL CsrInitConsoleScreenBuffer(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER Buffer);
192 VOID WINAPI ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer);
193 DWORD FASTCALL ConioEffectiveCursorSize(PCONSOLE Console, DWORD Scale);
194
195 /* alias.c */
196 VOID IntDeleteAllAliases(struct _ALIAS_HEADER *RootHeader);
197
198 /* lineinput.c */
199 struct _HISTORY_BUFFER;
200 VOID FASTCALL HistoryDeleteBuffer(struct _HISTORY_BUFFER *Hist);
201 VOID FASTCALL LineInputKeyDown(PCONSOLE Console, KEY_EVENT_RECORD *KeyEvent);
202
203 /* EOF */