Sync with trunk r58033.
[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 /* Object type magic numbers */
14
15 #define CONIO_CONSOLE_MAGIC 0x00000001
16 #define CONIO_SCREEN_BUFFER_MAGIC 0x00000002
17
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 ***********************************************************************/
33
34 typedef struct tagCSRSS_SCREEN_BUFFER
35 {
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;
45 USHORT Mode;
46 LIST_ENTRY ListEntry; /* entry in console's list of buffers */
47 } CSRSS_SCREEN_BUFFER, *PCSRSS_SCREEN_BUFFER;
48
49 typedef struct tagCSRSS_CONSOLE
50 {
51 Object_t Header; /* Object header */
52 LONG ReferenceCount;
53 CRITICAL_SECTION Lock;
54 struct tagCSRSS_CONSOLE *Prev, *Next; /* Next and Prev consoles in console wheel */
55
56 HANDLE ActiveEvent; /* Event set when an input event is added in its queue */
57 LIST_ENTRY ReadWaitQueue; /* List head for the queue of read wait blocks */
58
59 LIST_ENTRY InputEvents; /* List head for input event queue */
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 LIST_ENTRY HistoryBuffers;
69 UINT HistoryBufferSize; /* size for newly created history buffers */
70 UINT NumberOfHistoryBuffers; /* maximum number of history buffers allowed */
71 BOOLEAN HistoryNoDup; /* remove old duplicate history entries */
72 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
73 PCSRSS_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
74 WORD Mode; /* Console mode flags */
75 UNICODE_STRING Title; /* Title of console */
76 DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
77 HWND hWindow;
78 COORD Size;
79 PVOID PrivateData;
80 UINT CodePage;
81 UINT OutputCodePage;
82 struct tagCSRSS_CONSOLE_VTBL *Vtbl;
83 LIST_ENTRY ProcessList;
84 struct tagALIAS_HEADER *Aliases;
85 CONSOLE_SELECTION_INFO Selection;
86
87 BYTE PauseFlags;
88 HANDLE UnpauseEvent;
89 LIST_ENTRY WriteWaitQueue; /* List head for the queue of write wait blocks */
90 } CSRSS_CONSOLE, *PCSRSS_CONSOLE;
91
92 typedef struct tagCSRSS_CONSOLE_VTBL
93 {
94 VOID (WINAPI *InitScreenBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
95 VOID (WINAPI *WriteStream)(PCSRSS_CONSOLE Console, SMALL_RECT *Block, LONG CursorStartX, LONG CursorStartY,
96 UINT ScrolledLines, CHAR *Buffer, UINT Length);
97 VOID (WINAPI *DrawRegion)(PCSRSS_CONSOLE Console, SMALL_RECT *Region);
98 BOOL (WINAPI *SetCursorInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
99 BOOL (WINAPI *SetScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer,
100 UINT OldCursorX, UINT OldCursorY);
101 BOOL (WINAPI *UpdateScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
102 BOOL (WINAPI *ChangeTitle)(PCSRSS_CONSOLE Console);
103 VOID (WINAPI *CleanupConsole)(PCSRSS_CONSOLE Console);
104 BOOL (WINAPI *ChangeIcon)(PCSRSS_CONSOLE Console, HICON hWindowIcon);
105 NTSTATUS (WINAPI *ResizeBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer, COORD Size);
106 } CSRSS_CONSOLE_VTBL, *PCSRSS_CONSOLE_VTBL;
107
108 typedef struct ConsoleInput_t
109 {
110 LIST_ENTRY ListEntry;
111 INPUT_RECORD InputEvent;
112 } ConsoleInput;
113
114 /* CONSOLE_SELECTION_INFO dwFlags values */
115 #define CONSOLE_NO_SELECTION 0x0
116 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
117 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
118 #define CONSOLE_MOUSE_SELECTION 0x4
119 #define CONSOLE_MOUSE_DOWN 0x8
120 /* HistoryFlags values */
121 #define HISTORY_NO_DUP_FLAG 0x1
122
123 /* PauseFlags values (internal only) */
124 #define PAUSED_FROM_KEYBOARD 0x1
125 #define PAUSED_FROM_SCROLLBAR 0x2
126 #define PAUSED_FROM_SELECTION 0x4
127
128 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
129 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
130 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
131 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
132 (ScrolledLines), (Buffer), (Length))
133 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
134 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
135 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
136 #define ConioUpdateScreenInfo(Console, Buff) \
137 (Console)->Vtbl->UpdateScreenInfo(Console, Buff)
138 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
139 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
140 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon(Console, hWindowIcon)
141 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer(Console, Buff, Size)
142
143 /* console.c */
144 NTSTATUS FASTCALL ConioConsoleFromProcessData(PCONSOLE_PROCESS_DATA ProcessData,
145 PCSRSS_CONSOLE *Console);
146 VOID WINAPI ConioDeleteConsole(Object_t *Object);
147 VOID WINAPI CsrInitConsoleSupport(VOID);
148 VOID FASTCALL ConioPause(PCSRSS_CONSOLE Console, UINT Flags);
149 VOID FASTCALL ConioUnpause(PCSRSS_CONSOLE Console, UINT Flags);
150 VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCONSOLE_PROCESS_DATA ProcessData);
151 VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event,
152 PCONSOLE_PROCESS_DATA ProcessData,
153 DWORD Timeout);
154
155 /* coninput.c */
156 #define ConioLockConsole(ProcessData, Handle, Ptr, Access) \
157 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_CONSOLE_MAGIC)
158 #define ConioUnlockConsole(Console) \
159 Win32CsrUnlockObject((Object_t *) Console)
160 void WINAPI ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode);
161
162 /* conoutput.c */
163 #define ConioRectHeight(Rect) \
164 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
165 #define ConioRectWidth(Rect) \
166 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
167 #define ConioLockScreenBuffer(ProcessData, Handle, Ptr, Access) \
168 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_SCREEN_BUFFER_MAGIC)
169 #define ConioUnlockScreenBuffer(Buff) \
170 Win32CsrUnlockObject((Object_t *) Buff)
171 PBYTE FASTCALL ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
172 VOID FASTCALL ConioDrawConsole(PCSRSS_CONSOLE Console);
173 NTSTATUS FASTCALL ConioWriteConsole(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff,
174 CHAR *Buffer, DWORD Length, BOOL Attrib);
175 NTSTATUS FASTCALL CsrInitConsoleScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer);
176 VOID WINAPI ConioDeleteScreenBuffer(PCSRSS_SCREEN_BUFFER Buffer);
177 DWORD FASTCALL ConioEffectiveCursorSize(PCSRSS_CONSOLE Console, DWORD Scale);
178
179 /* alias.c */
180 VOID IntDeleteAllAliases(struct tagALIAS_HEADER *RootHeader);
181
182 /* lineinput.c */
183 struct tagHISTORY_BUFFER;
184 VOID FASTCALL HistoryDeleteBuffer(struct tagHISTORY_BUFFER *Hist);
185 VOID FASTCALL LineInputKeyDown(PCSRSS_CONSOLE Console, KEY_EVENT_RECORD *KeyEvent);
186
187 /* EOF */