[CONSRV]: Still some code refactoring....
[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 BOOLEAN QuickEdit;
135
136 /******************************* Pausing support ******************************/
137 BYTE PauseFlags;
138 LIST_ENTRY ReadWaitQueue; /* List head for the queue of unique input buffer read wait blocks */
139 LIST_ENTRY WriteWaitQueue; /* List head for the queue of current screen-buffer write wait blocks */
140
141 /**************************** Aliases and Histories ***************************/
142 struct _ALIAS_HEADER *Aliases;
143 LIST_ENTRY HistoryBuffers;
144 ULONG HistoryBufferSize; /* Size for newly created history buffers */
145 ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed */
146 BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
147
148 /************************ Virtual DOS Machine support *************************/
149 COORD VDMBufferSize; /* Real size of the VDM buffer, in units of ??? */
150 HANDLE VDMBufferSection; /* Handle to the memory shared section for the VDM buffer */
151 PVOID VDMBuffer; /* Our VDM buffer */
152 PVOID ClientVDMBuffer; /* A copy of the client view of our VDM buffer */
153 HANDLE VDMClientProcess; /* Handle to the client process who opened the buffer, to unmap the view */
154
155 HANDLE StartHardwareEvent;
156 HANDLE EndHardwareEvent;
157 HANDLE ErrorHardwareEvent;
158
159 /****************************** Other properties ******************************/
160 COLORREF Colors[16]; /* Colour palette */
161
162 } WINSRV_CONSOLE, *PWINSRV_CONSOLE;
163
164 /* console.c */
165 VOID ConioPause(PCONSRV_CONSOLE Console, UINT Flags);
166 VOID ConioUnpause(PCONSRV_CONSOLE Console, UINT Flags);
167
168 PCONSOLE_PROCESS_DATA NTAPI
169 ConSrvGetConsoleLeaderProcess(IN PCONSRV_CONSOLE Console);
170 NTSTATUS
171 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent,
172 IN PCONSOLE_PROCESS_DATA ProcessData);
173 NTSTATUS NTAPI
174 ConSrvConsoleProcessCtrlEvent(IN PCONSRV_CONSOLE Console,
175 IN ULONG ProcessGroupId,
176 IN ULONG CtrlEvent);
177
178 /* coninput.c */
179 VOID NTAPI ConioProcessKey(PCONSRV_CONSOLE Console, MSG* msg);
180 DWORD ConioEffectiveCursorSize(PCONSRV_CONSOLE Console,
181 DWORD Scale);
182
183 NTSTATUS
184 ConioAddInputEvents(PCONSRV_CONSOLE Console,
185 PINPUT_RECORD InputRecords,
186 ULONG NumEventsToWrite,
187 PULONG NumEventsWritten,
188 BOOLEAN AppendToEnd);
189 NTSTATUS
190 ConioProcessInputEvent(PCONSRV_CONSOLE Console,
191 PINPUT_RECORD InputEvent);
192
193 /* conoutput.c */
194
195 /*
196 * From MSDN:
197 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
198 * If they are the same, the function fails, and GetLastError returns
199 * ERROR_INVALID_PARAMETER."
200 */
201 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
202 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
203 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
204
205 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
206 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
207 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
208
209 PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y);
210 VOID ConioDrawConsole(PCONSRV_CONSOLE Console);
211 NTSTATUS ConioResizeBuffer(PCONSRV_CONSOLE Console,
212 PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
213 COORD Size);
214 NTSTATUS ConioWriteConsole(PCONSRV_CONSOLE Console,
215 PTEXTMODE_SCREEN_BUFFER Buff,
216 PWCHAR Buffer,
217 DWORD Length,
218 BOOL Attrib);
219
220 /* EOF */