[CONSRV]
[reactos.git] / win32ss / user / winsrv / consrv / include / conio_winsrv.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: consrv/include/conio_winsrv.h
5 * PURPOSE: Public Console I/O Interface
6 * PROGRAMMERS: Gé van Geldorp
7 * Jeffrey Morlan
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 */
10
11 #pragma once
12
13 #include "rect.h"
14
15 // This is ALMOST a HACK!!!!!!!
16 // Helpers for code refactoring
17 #define _CONSRV_CONSOLE _CONSOLE
18 #define CONSRV_CONSOLE CONSOLE
19 #define PCONSRV_CONSOLE PCONSOLE
20
21 // #define _CONSRV_CONSOLE _WINSRV_CONSOLE
22 // #define CONSRV_CONSOLE WINSRV_CONSOLE
23 // #define PCONSRV_CONSOLE PWINSRV_CONSOLE
24
25
26 #define CSR_DEFAULT_CURSOR_SIZE 25
27
28 /* VGA character cell */
29 typedef struct _CHAR_CELL
30 {
31 CHAR Char;
32 BYTE Attributes;
33 } CHAR_CELL, *PCHAR_CELL;
34 C_ASSERT(sizeof(CHAR_CELL) == 2);
35
36
37 typedef struct _FRONTEND FRONTEND, *PFRONTEND;
38 /* HACK: */ typedef struct _CONSOLE_INFO *PCONSOLE_INFO;
39 typedef struct _FRONTEND_VTBL
40 {
41 // NTSTATUS (NTAPI *UnloadFrontEnd)(IN OUT PFRONTEND This);
42
43 /*
44 * Internal interface (functions called by the console server only)
45 */
46 NTSTATUS (NTAPI *InitFrontEnd)(IN OUT PFRONTEND This,
47 IN struct _CONSRV_CONSOLE* Console);
48 VOID (NTAPI *DeinitFrontEnd)(IN OUT PFRONTEND This);
49
50 /* Interface used for both text-mode and graphics screen buffers */
51 VOID (NTAPI *DrawRegion)(IN OUT PFRONTEND This,
52 SMALL_RECT* Region);
53 /* Interface used only for text-mode screen buffers */
54 VOID (NTAPI *WriteStream)(IN OUT PFRONTEND This,
55 SMALL_RECT* Region,
56 SHORT CursorStartX,
57 SHORT CursorStartY,
58 UINT ScrolledLines,
59 PWCHAR Buffer,
60 UINT Length);
61 BOOL (NTAPI *SetCursorInfo)(IN OUT PFRONTEND This,
62 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
63 BOOL (NTAPI *SetScreenInfo)(IN OUT PFRONTEND This,
64 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
65 SHORT OldCursorX,
66 SHORT OldCursorY);
67 VOID (NTAPI *ResizeTerminal)(IN OUT PFRONTEND This);
68 VOID (NTAPI *SetActiveScreenBuffer)(IN OUT PFRONTEND This);
69 VOID (NTAPI *ReleaseScreenBuffer)(IN OUT PFRONTEND This,
70 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer);
71 VOID (NTAPI *RefreshInternalInfo)(IN OUT PFRONTEND This);
72
73 /*
74 * External interface (functions corresponding to the Console API)
75 */
76 VOID (NTAPI *ChangeTitle)(IN OUT PFRONTEND This);
77 BOOL (NTAPI *ChangeIcon)(IN OUT PFRONTEND This,
78 HICON IconHandle);
79 HWND (NTAPI *GetConsoleWindowHandle)(IN OUT PFRONTEND This);
80 VOID (NTAPI *GetLargestConsoleWindowSize)(IN OUT PFRONTEND This,
81 PCOORD pSize);
82 BOOL (NTAPI *GetSelectionInfo)(IN OUT PFRONTEND This,
83 PCONSOLE_SELECTION_INFO pSelectionInfo);
84 BOOL (NTAPI *SetPalette)(IN OUT PFRONTEND This,
85 HPALETTE PaletteHandle,
86 UINT PaletteUsage);
87 ULONG (NTAPI *GetDisplayMode)(IN OUT PFRONTEND This);
88 BOOL (NTAPI *SetDisplayMode)(IN OUT PFRONTEND This,
89 ULONG NewMode);
90 INT (NTAPI *ShowMouseCursor)(IN OUT PFRONTEND This,
91 BOOL Show);
92 BOOL (NTAPI *SetMouseCursor)(IN OUT PFRONTEND This,
93 HCURSOR CursorHandle);
94 HMENU (NTAPI *MenuControl)(IN OUT PFRONTEND This,
95 UINT CmdIdLow,
96 UINT CmdIdHigh);
97 BOOL (NTAPI *SetMenuClose)(IN OUT PFRONTEND This,
98 BOOL Enable);
99 } FRONTEND_VTBL, *PFRONTEND_VTBL;
100
101 struct _FRONTEND
102 {
103 PFRONTEND_VTBL Vtbl; /* Virtual table */
104 NTSTATUS (NTAPI *UnloadFrontEnd)(IN OUT PFRONTEND This);
105
106 struct _CONSRV_CONSOLE* Console; /* Console to which the frontend is attached to */
107 PVOID Data; /* Private data */
108 PVOID OldData; /* Reserved */
109 };
110
111 /* PauseFlags values (internal only) */
112 #define PAUSED_FROM_KEYBOARD 0x1
113 #define PAUSED_FROM_SCROLLBAR 0x2
114 #define PAUSED_FROM_SELECTION 0x4
115
116 typedef struct _WINSRV_CONSOLE
117 {
118 /******************************* Console Set-up *******************************/
119 /* This **MUST** be FIRST!! */
120 // CONSOLE;
121 // PCONSOLE Console;
122
123 // LONG ReferenceCount; /* Is incremented each time a handle to something in the console (a screen-buffer or the input buffer of this console) gets referenced */
124 // CRITICAL_SECTION Lock;
125 // CONSOLE_STATE State; /* State of the console */
126
127 FRONTEND FrontEndIFace; /* Frontend-specific interface */
128
129 /******************************* Process support ******************************/
130 LIST_ENTRY ProcessList; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
131 PCONSOLE_PROCESS_DATA NotifiedLastCloseProcess; /* Pointer to the unique process that needs to be notified when the console leader process is killed */
132 BOOLEAN NotifyLastClose; /* TRUE if the console should send a control event when the console leader process is killed */
133
134 /******************************* Pausing support ******************************/
135 BYTE PauseFlags;
136 LIST_ENTRY ReadWaitQueue; /* List head for the queue of unique input buffer read wait blocks */
137 LIST_ENTRY WriteWaitQueue; /* List head for the queue of current screen-buffer write wait blocks */
138
139 /**************************** Aliases and Histories ***************************/
140 struct _ALIAS_HEADER *Aliases;
141 LIST_ENTRY HistoryBuffers;
142 ULONG HistoryBufferSize; /* Size for newly created history buffers */
143 ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed */
144 BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
145
146 /**************************** Input Line Discipline ***************************/
147 PWCHAR LineBuffer; /* Current line being input, in line buffered mode */
148 ULONG LineMaxSize; /* Maximum size of line in characters (including CR+LF) */
149 ULONG LineSize; /* Current size of line */
150 ULONG LinePos; /* Current position within line */
151 BOOLEAN LineComplete; /* User pressed enter, ready to send back to client */
152 BOOLEAN LineUpPressed;
153 BOOLEAN LineInsertToggle; /* Replace character over cursor instead of inserting */
154 ULONG LineWakeupMask; /* Bitmap of which control characters will end line input */
155
156 BOOLEAN InsertMode;
157 BOOLEAN QuickEdit;
158
159 /************************ Virtual DOS Machine support *************************/
160 COORD VDMBufferSize; /* Real size of the VDM buffer, in units of ??? */
161 HANDLE VDMBufferSection; /* Handle to the memory shared section for the VDM buffer */
162 PVOID VDMBuffer; /* Our VDM buffer */
163 PVOID ClientVDMBuffer; /* A copy of the client view of our VDM buffer */
164 HANDLE VDMClientProcess; /* Handle to the client process who opened the buffer, to unmap the view */
165
166 HANDLE StartHardwareEvent;
167 HANDLE EndHardwareEvent;
168 HANDLE ErrorHardwareEvent;
169
170 /****************************** Other properties ******************************/
171 COLORREF Colors[16]; /* Colour palette */
172
173 } WINSRV_CONSOLE, *PWINSRV_CONSOLE;
174
175 /* console.c */
176 VOID ConioPause(PCONSRV_CONSOLE Console, UINT Flags);
177 VOID ConioUnpause(PCONSRV_CONSOLE Console, UINT Flags);
178
179 PCONSOLE_PROCESS_DATA NTAPI
180 ConSrvGetConsoleLeaderProcess(IN PCONSRV_CONSOLE Console);
181 NTSTATUS
182 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent,
183 IN PCONSOLE_PROCESS_DATA ProcessData);
184 NTSTATUS NTAPI
185 ConSrvConsoleProcessCtrlEvent(IN PCONSRV_CONSOLE Console,
186 IN ULONG ProcessGroupId,
187 IN ULONG CtrlEvent);
188
189 /* coninput.c */
190 VOID NTAPI ConioProcessKey(PCONSRV_CONSOLE Console, MSG* msg);
191 DWORD ConioEffectiveCursorSize(PCONSRV_CONSOLE Console,
192 DWORD Scale);
193
194 NTSTATUS
195 ConioAddInputEvents(PCONSRV_CONSOLE Console,
196 PINPUT_RECORD InputRecords,
197 ULONG NumEventsToWrite,
198 PULONG NumEventsWritten,
199 BOOLEAN AppendToEnd);
200 NTSTATUS
201 ConioProcessInputEvent(PCONSRV_CONSOLE Console,
202 PINPUT_RECORD InputEvent);
203
204 /* conoutput.c */
205
206 /*
207 * From MSDN:
208 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
209 * If they are the same, the function fails, and GetLastError returns
210 * ERROR_INVALID_PARAMETER."
211 */
212 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
213 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
214 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
215
216 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
217 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
218 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
219
220 PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y);
221 VOID ConioDrawConsole(PCONSRV_CONSOLE Console);
222 NTSTATUS ConioResizeBuffer(PCONSRV_CONSOLE Console,
223 PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
224 COORD Size);
225
226 /* EOF */