[KERNEL32][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 #define CSR_DEFAULT_CURSOR_SIZE 25
14
15 typedef struct _FRONTEND FRONTEND, *PFRONTEND;
16 /* HACK: */ typedef struct _CONSOLE_INFO *PCONSOLE_INFO;
17 typedef struct _FRONTEND_VTBL
18 {
19 // NTSTATUS (NTAPI *UnloadFrontEnd)(IN OUT PFRONTEND This);
20
21 /*
22 * Internal interface (functions called by the console server only)
23 */
24 NTSTATUS (NTAPI *InitFrontEnd)(IN OUT PFRONTEND This,
25 IN struct _CONSOLE* Console);
26 VOID (NTAPI *DeinitFrontEnd)(IN OUT PFRONTEND This);
27
28 /* Interface used for both text-mode and graphics screen buffers */
29 VOID (NTAPI *DrawRegion)(IN OUT PFRONTEND This,
30 SMALL_RECT* Region);
31 /* Interface used only for text-mode screen buffers */
32 VOID (NTAPI *WriteStream)(IN OUT PFRONTEND This,
33 SMALL_RECT* Region,
34 SHORT CursorStartX,
35 SHORT CursorStartY,
36 UINT ScrolledLines,
37 PWCHAR Buffer,
38 UINT Length);
39 BOOL (NTAPI *SetCursorInfo)(IN OUT PFRONTEND This,
40 PCONSOLE_SCREEN_BUFFER ScreenBuffer);
41 BOOL (NTAPI *SetScreenInfo)(IN OUT PFRONTEND This,
42 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
43 SHORT OldCursorX,
44 SHORT OldCursorY);
45 VOID (NTAPI *ResizeTerminal)(IN OUT PFRONTEND This);
46 VOID (NTAPI *SetActiveScreenBuffer)(IN OUT PFRONTEND This);
47 VOID (NTAPI *ReleaseScreenBuffer)(IN OUT PFRONTEND This,
48 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer);
49 VOID (NTAPI *RefreshInternalInfo)(IN OUT PFRONTEND This);
50
51 /*
52 * External interface (functions corresponding to the Console API)
53 */
54 VOID (NTAPI *ChangeTitle)(IN OUT PFRONTEND This);
55 BOOL (NTAPI *ChangeIcon)(IN OUT PFRONTEND This,
56 HICON IconHandle);
57 HWND (NTAPI *GetConsoleWindowHandle)(IN OUT PFRONTEND This);
58 VOID (NTAPI *GetLargestConsoleWindowSize)(IN OUT PFRONTEND This,
59 PCOORD pSize);
60 BOOL (NTAPI *GetSelectionInfo)(IN OUT PFRONTEND This,
61 PCONSOLE_SELECTION_INFO pSelectionInfo);
62 BOOL (NTAPI *SetPalette)(IN OUT PFRONTEND This,
63 HPALETTE PaletteHandle,
64 UINT PaletteUsage);
65 ULONG (NTAPI *GetDisplayMode)(IN OUT PFRONTEND This);
66 BOOL (NTAPI *SetDisplayMode)(IN OUT PFRONTEND This,
67 ULONG NewMode);
68 INT (NTAPI *ShowMouseCursor)(IN OUT PFRONTEND This,
69 BOOL Show);
70 BOOL (NTAPI *SetMouseCursor)(IN OUT PFRONTEND This,
71 HCURSOR CursorHandle);
72 HMENU (NTAPI *MenuControl)(IN OUT PFRONTEND This,
73 UINT CmdIdLow,
74 UINT CmdIdHigh);
75 BOOL (NTAPI *SetMenuClose)(IN OUT PFRONTEND This,
76 BOOL Enable);
77 } FRONTEND_VTBL, *PFRONTEND_VTBL;
78
79 struct _FRONTEND
80 {
81 PFRONTEND_VTBL Vtbl; /* Virtual table */
82 NTSTATUS (NTAPI *UnloadFrontEnd)(IN OUT PFRONTEND This);
83
84 struct _CONSOLE* Console; /* Console to which the frontend is attached to */
85 PVOID Data; /* Private data */
86 PVOID OldData; /* Reserved */
87 };
88
89 /* PauseFlags values (internal only) */
90 #define PAUSED_FROM_KEYBOARD 0x1
91 #define PAUSED_FROM_SCROLLBAR 0x2
92 #define PAUSED_FROM_SELECTION 0x4
93
94 typedef struct _WINSRV_CONSOLE
95 {
96 /******************************* Console Set-up *******************************/
97 /* This **MUST** be FIRST!! */
98 // CONSOLE;
99
100 // 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 */
101 // CRITICAL_SECTION Lock;
102 // CONSOLE_STATE State; /* State of the console */
103
104 FRONTEND FrontEndIFace; /* Frontend-specific interface */
105
106 /******************************* Process support ******************************/
107 LIST_ENTRY ProcessList; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
108 PCONSOLE_PROCESS_DATA NotifiedLastCloseProcess; /* Pointer to the unique process that needs to be notified when the console leader process is killed */
109 BOOLEAN NotifyLastClose; /* TRUE if the console should send a control event when the console leader process is killed */
110
111 BOOLEAN QuickEdit;
112
113 /******************************* Pausing support ******************************/
114 BYTE PauseFlags;
115 LIST_ENTRY ReadWaitQueue; /* List head for the queue of unique input buffer read wait blocks */
116 LIST_ENTRY WriteWaitQueue; /* List head for the queue of current screen-buffer write wait blocks */
117
118 /**************************** Aliases and Histories ***************************/
119 struct _ALIAS_HEADER *Aliases;
120 LIST_ENTRY HistoryBuffers;
121 ULONG HistoryBufferSize; /* Size for newly created history buffers */
122 ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed */
123 BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
124
125 } WINSRV_CONSOLE, *PWINSRV_CONSOLE;
126
127 /* console.c */
128 VOID ConioPause(PCONSOLE Console, UINT Flags);
129 VOID ConioUnpause(PCONSOLE Console, UINT Flags);
130
131 PCONSOLE_PROCESS_DATA NTAPI
132 ConSrvGetConsoleLeaderProcess(IN PCONSOLE Console);
133 NTSTATUS
134 ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent,
135 IN PCONSOLE_PROCESS_DATA ProcessData);
136 NTSTATUS NTAPI
137 ConSrvConsoleProcessCtrlEvent(IN PCONSOLE Console,
138 IN ULONG ProcessGroupId,
139 IN ULONG CtrlEvent);
140
141 /* coninput.c */
142 VOID NTAPI ConioProcessKey(PCONSOLE Console, MSG* msg);
143 NTSTATUS
144 ConioAddInputEvents(PCONSOLE Console,
145 PINPUT_RECORD InputRecords,
146 ULONG NumEventsToWrite,
147 PULONG NumEventsWritten,
148 BOOLEAN AppendToEnd);
149 NTSTATUS
150 ConioProcessInputEvent(PCONSOLE Console,
151 PINPUT_RECORD InputEvent);
152
153 /* conoutput.c */
154 #define ConioInitRect(Rect, top, left, bottom, right) \
155 do { \
156 ((Rect)->Top) = top; \
157 ((Rect)->Left) = left; \
158 ((Rect)->Bottom) = bottom; \
159 ((Rect)->Right) = right; \
160 } while (0)
161 #define ConioIsRectEmpty(Rect) \
162 (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
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
168 /*
169 * From MSDN:
170 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
171 * If they are the same, the function fails, and GetLastError returns
172 * ERROR_INVALID_PARAMETER."
173 */
174 #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \
175 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
176 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
177
178 #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \
179 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
180 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
181
182 PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y);
183 VOID ConioDrawConsole(PCONSOLE Console);
184 NTSTATUS ConioResizeBuffer(PCONSOLE Console,
185 PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
186 COORD Size);
187 NTSTATUS ConioWriteConsole(PCONSOLE Console,
188 PTEXTMODE_SCREEN_BUFFER Buff,
189 PWCHAR Buffer,
190 DWORD Length,
191 BOOL Attrib);
192 DWORD ConioEffectiveCursorSize(PCONSOLE Console,
193 DWORD Scale);
194
195 /* EOF */