f6558a5a89127dea404bab43b5eb6eeb181cc40a
[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 HANDLE ActiveEvent;
56 LIST_ENTRY InputEvents; /* List head for input event queue */
57 PWCHAR LineBuffer; /* current line being input, in line buffered mode */
58 WORD LineMaxSize; /* maximum size of line in characters (including CR+LF) */
59 WORD LineSize; /* current size of line */
60 WORD LinePos; /* current position within line */
61 BOOLEAN LineComplete; /* user pressed enter, ready to send back to client */
62 BOOLEAN LineUpPressed;
63 BOOLEAN LineInsertToggle; /* replace character over cursor instead of inserting */
64 ULONG LineWakeupMask; /* bitmap of which control characters will end line input */
65 LIST_ENTRY HistoryBuffers;
66 UINT HistoryBufferSize; /* size for newly created history buffers */
67 UINT NumberOfHistoryBuffers; /* maximum number of history buffers allowed */
68 BOOLEAN HistoryNoDup; /* remove old duplicate history entries */
69 LIST_ENTRY BufferList; /* List of all screen buffers for this console */
70 PCSRSS_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
71 WORD Mode; /* Console mode flags */
72 UNICODE_STRING Title; /* Title of console */
73 DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
74 HWND hWindow;
75 COORD Size;
76 PVOID PrivateData;
77 UINT CodePage;
78 UINT OutputCodePage;
79 struct tagCSRSS_CONSOLE_VTBL *Vtbl;
80 LIST_ENTRY ProcessList;
81 struct tagALIAS_HEADER *Aliases;
82 CONSOLE_SELECTION_INFO Selection;
83 BYTE PauseFlags;
84 HANDLE UnpauseEvent;
85 } CSRSS_CONSOLE, *PCSRSS_CONSOLE;
86
87 typedef struct tagCSRSS_CONSOLE_VTBL
88 {
89 VOID (WINAPI *InitScreenBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
90 VOID (WINAPI *WriteStream)(PCSRSS_CONSOLE Console, SMALL_RECT *Block, LONG CursorStartX, LONG CursorStartY,
91 UINT ScrolledLines, CHAR *Buffer, UINT Length);
92 VOID (WINAPI *DrawRegion)(PCSRSS_CONSOLE Console, SMALL_RECT *Region);
93 BOOL (WINAPI *SetCursorInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
94 BOOL (WINAPI *SetScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer,
95 UINT OldCursorX, UINT OldCursorY);
96 BOOL (WINAPI *UpdateScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
97 BOOL (WINAPI *ChangeTitle)(PCSRSS_CONSOLE Console);
98 VOID (WINAPI *CleanupConsole)(PCSRSS_CONSOLE Console);
99 BOOL (WINAPI *ChangeIcon)(PCSRSS_CONSOLE Console, HICON hWindowIcon);
100 NTSTATUS (WINAPI *ResizeBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer, COORD Size);
101 } CSRSS_CONSOLE_VTBL, *PCSRSS_CONSOLE_VTBL;
102
103 typedef struct ConsoleInput_t
104 {
105 LIST_ENTRY ListEntry;
106 INPUT_RECORD InputEvent;
107 } ConsoleInput;
108
109 /* CONSOLE_SELECTION_INFO dwFlags values */
110 #define CONSOLE_NO_SELECTION 0x0
111 #define CONSOLE_SELECTION_IN_PROGRESS 0x1
112 #define CONSOLE_SELECTION_NOT_EMPTY 0x2
113 #define CONSOLE_MOUSE_SELECTION 0x4
114 #define CONSOLE_MOUSE_DOWN 0x8
115 /* HistoryFlags values */
116 #define HISTORY_NO_DUP_FLAG 0x1
117
118 /* PauseFlags values (internal only) */
119 #define PAUSED_FROM_KEYBOARD 0x1
120 #define PAUSED_FROM_SCROLLBAR 0x2
121 #define PAUSED_FROM_SELECTION 0x4
122
123 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
124 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
125 #define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
126 (Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
127 (ScrolledLines), (Buffer), (Length))
128 #define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
129 #define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
130 (Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
131 #define ConioUpdateScreenInfo(Console, Buff) \
132 (Console)->Vtbl->UpdateScreenInfo(Console, Buff)
133 #define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
134 #define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
135 #define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon(Console, hWindowIcon)
136 #define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer(Console, Buff, Size)
137
138 /* console.c */
139 NTSTATUS FASTCALL ConioConsoleFromProcessData(PCONSOLE_PROCESS_DATA ProcessData,
140 PCSRSS_CONSOLE *Console);
141 VOID WINAPI ConioDeleteConsole(Object_t *Object);
142 VOID WINAPI CsrInitConsoleSupport(VOID);
143 VOID FASTCALL ConioPause(PCSRSS_CONSOLE Console, UINT Flags);
144 VOID FASTCALL ConioUnpause(PCSRSS_CONSOLE Console, UINT Flags);
145 VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCONSOLE_PROCESS_DATA ProcessData);
146 VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event,
147 PCONSOLE_PROCESS_DATA ProcessData,
148 DWORD Timeout);
149
150 /* coninput.c */
151 #define ConioLockConsole(ProcessData, Handle, Ptr, Access) \
152 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_CONSOLE_MAGIC)
153 #define ConioUnlockConsole(Console) \
154 Win32CsrUnlockObject((Object_t *) Console)
155 void WINAPI ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode);
156
157 /* conoutput.c */
158 #define ConioRectHeight(Rect) \
159 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
160 #define ConioRectWidth(Rect) \
161 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
162 #define ConioLockScreenBuffer(ProcessData, Handle, Ptr, Access) \
163 Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), Access, CONIO_SCREEN_BUFFER_MAGIC)
164 #define ConioUnlockScreenBuffer(Buff) \
165 Win32CsrUnlockObject((Object_t *) Buff)
166 PBYTE FASTCALL ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buf, ULONG X, ULONG Y);
167 VOID FASTCALL ConioDrawConsole(PCSRSS_CONSOLE Console);
168 NTSTATUS FASTCALL ConioWriteConsole(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff,
169 CHAR *Buffer, DWORD Length, BOOL Attrib);
170 NTSTATUS FASTCALL CsrInitConsoleScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer);
171 VOID WINAPI ConioDeleteScreenBuffer(PCSRSS_SCREEN_BUFFER Buffer);
172 DWORD FASTCALL ConioEffectiveCursorSize(PCSRSS_CONSOLE Console, DWORD Scale);
173
174 /* alias.c */
175 VOID IntDeleteAllAliases(struct tagALIAS_HEADER *RootHeader);
176
177 /* lineinput.c */
178 struct tagHISTORY_BUFFER;
179 VOID FASTCALL HistoryDeleteBuffer(struct tagHISTORY_BUFFER *Hist);
180 VOID FASTCALL LineInputKeyDown(PCSRSS_CONSOLE Console, KEY_EVENT_RECORD *KeyEvent);
181
182 /* EOF */