306aa4192cd20fe52a80bb678f6e887c5605d14b
[reactos.git] / reactos / win32ss / user / winsrv / consrv / frontends / terminal.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: frontends/terminal.c
5 * PURPOSE: ConSrv terminal.
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <consrv.h>
12
13 // #include "frontends/gui/guiterm.h"
14 #ifdef TUITERM_COMPILE
15 #include "frontends/tui/tuiterm.h"
16 #endif
17
18 #define NDEBUG
19 #include <debug.h>
20
21
22
23
24
25 /********** HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK ************/
26
27 /* GLOBALS ********************************************************************/
28
29 /*
30 * From MSDN:
31 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
32 * If they are the same, the function fails, and GetLastError returns
33 * ERROR_INVALID_PARAMETER."
34 */
35 #define ConsoleInputUnicodeCharToAnsiChar(Console, dChar, sWChar) \
36 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
37 WideCharToMultiByte((Console)->InputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
38
39 #define ConsoleInputAnsiCharToUnicodeChar(Console, dWChar, sChar) \
40 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
41 MultiByteToWideChar((Console)->InputCodePage, 0, (sChar), 1, (dWChar), 1)
42
43 typedef struct ConsoleInput_t
44 {
45 LIST_ENTRY ListEntry;
46 INPUT_RECORD InputEvent;
47 } ConsoleInput;
48
49
50 /* PRIVATE FUNCTIONS **********************************************************/
51
52 #if 0
53
54 static VOID
55 ConioInputEventToAnsi(PCONSOLE Console, PINPUT_RECORD InputEvent)
56 {
57 if (InputEvent->EventType == KEY_EVENT)
58 {
59 WCHAR UnicodeChar = InputEvent->Event.KeyEvent.uChar.UnicodeChar;
60 InputEvent->Event.KeyEvent.uChar.UnicodeChar = 0;
61 ConsoleInputUnicodeCharToAnsiChar(Console,
62 &InputEvent->Event.KeyEvent.uChar.AsciiChar,
63 &UnicodeChar);
64 }
65 }
66
67 static VOID
68 ConioInputEventToUnicode(PCONSOLE Console, PINPUT_RECORD InputEvent)
69 {
70 if (InputEvent->EventType == KEY_EVENT)
71 {
72 CHAR AsciiChar = InputEvent->Event.KeyEvent.uChar.AsciiChar;
73 InputEvent->Event.KeyEvent.uChar.AsciiChar = 0;
74 ConsoleInputAnsiCharToUnicodeChar(Console,
75 &InputEvent->Event.KeyEvent.uChar.UnicodeChar,
76 &AsciiChar);
77 }
78 }
79
80 #endif
81
82 /********** HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK ************/
83
84
85
86
87
88
89
90
91 /* CONSRV TERMINAL FRONTENDS INTERFACE ****************************************/
92
93 /***************/
94 #ifdef TUITERM_COMPILE
95 NTSTATUS NTAPI
96 TuiLoadFrontEnd(IN OUT PFRONTEND FrontEnd,
97 IN OUT PCONSOLE_INFO ConsoleInfo,
98 IN OUT PVOID ExtraConsoleInfo,
99 IN ULONG ProcessId);
100 NTSTATUS NTAPI
101 TuiUnloadFrontEnd(IN OUT PFRONTEND FrontEnd);
102 #endif
103
104 NTSTATUS NTAPI
105 GuiLoadFrontEnd(IN OUT PFRONTEND FrontEnd,
106 IN OUT PCONSOLE_INFO ConsoleInfo,
107 IN OUT PVOID ExtraConsoleInfo,
108 IN ULONG ProcessId);
109 NTSTATUS NTAPI
110 GuiUnloadFrontEnd(IN OUT PFRONTEND FrontEnd);
111 /***************/
112
113 typedef
114 NTSTATUS (NTAPI *FRONTEND_LOAD)(IN OUT PFRONTEND FrontEnd,
115 IN OUT PCONSOLE_INFO ConsoleInfo,
116 IN OUT PVOID ExtraConsoleInfo,
117 IN ULONG ProcessId);
118
119 typedef
120 NTSTATUS (NTAPI *FRONTEND_UNLOAD)(IN OUT PFRONTEND FrontEnd);
121
122 /*
123 * If we are not in GUI-mode, start the text-mode terminal emulator.
124 * If we fail, try to start the GUI-mode terminal emulator.
125 *
126 * Try to open the GUI-mode terminal emulator. Two cases are possible:
127 * - We are in GUI-mode, therefore GuiMode == TRUE, the previous test-case
128 * failed and we start GUI-mode terminal emulator.
129 * - We are in text-mode, therefore GuiMode == FALSE, the previous test-case
130 * succeeded BUT we failed at starting text-mode terminal emulator.
131 * Then GuiMode was switched to TRUE in order to try to open the GUI-mode
132 * terminal emulator (Win32k will automatically switch to graphical mode,
133 * therefore no additional code is needed).
134 */
135
136 /*
137 * NOTE: Each entry of the table should be retrieved when loading a front-end
138 * (examples of the CSR servers which register some data for CSRSS).
139 */
140 static struct
141 {
142 CHAR FrontEndName[80];
143 FRONTEND_LOAD FrontEndLoad;
144 FRONTEND_UNLOAD FrontEndUnload;
145 } FrontEndLoadingMethods[] =
146 {
147 #ifdef TUITERM_COMPILE
148 {"TUI", TuiLoadFrontEnd, TuiUnloadFrontEnd},
149 #endif
150 {"GUI", GuiLoadFrontEnd, GuiUnloadFrontEnd},
151
152 // {"Not found", 0, NULL}
153 };
154
155 static NTSTATUS
156 ConSrvLoadFrontEnd(IN OUT PFRONTEND FrontEnd,
157 IN OUT PCONSOLE_INFO ConsoleInfo,
158 IN OUT PVOID ExtraConsoleInfo,
159 IN ULONG ProcessId)
160 {
161 NTSTATUS Status = STATUS_SUCCESS;
162 ULONG i;
163
164 /*
165 * Choose an adequate terminal front-end to load, and load it
166 */
167 for (i = 0; i < sizeof(FrontEndLoadingMethods) / sizeof(FrontEndLoadingMethods[0]); ++i)
168 {
169 DPRINT("CONSRV: Trying to load %s frontend...\n",
170 FrontEndLoadingMethods[i].FrontEndName);
171 Status = FrontEndLoadingMethods[i].FrontEndLoad(FrontEnd,
172 ConsoleInfo,
173 ExtraConsoleInfo,
174 ProcessId);
175 if (NT_SUCCESS(Status))
176 {
177 /* Save the unload callback */
178 FrontEnd->UnloadFrontEnd = FrontEndLoadingMethods[i].FrontEndUnload;
179
180 DPRINT("CONSRV: %s frontend loaded successfully\n",
181 FrontEndLoadingMethods[i].FrontEndName);
182 break;
183 }
184 else
185 {
186 DPRINT1("CONSRV: Loading %s frontend failed, Status = 0x%08lx , continuing...\n",
187 FrontEndLoadingMethods[i].FrontEndName, Status);
188 }
189 }
190
191 return Status;
192 }
193
194 static NTSTATUS
195 ConSrvUnloadFrontEnd(IN PFRONTEND FrontEnd)
196 {
197 if (FrontEnd == NULL) return STATUS_INVALID_PARAMETER;
198 // return FrontEnd->Vtbl->UnloadFrontEnd(FrontEnd);
199 return FrontEnd->UnloadFrontEnd(FrontEnd);
200 }
201
202 // See after...
203 static TERMINAL_VTBL ConSrvTermVtbl;
204
205 NTSTATUS NTAPI
206 ConSrvInitTerminal(IN OUT PTERMINAL Terminal,
207 IN OUT PCONSOLE_INFO ConsoleInfo,
208 IN OUT PVOID ExtraConsoleInfo,
209 IN ULONG ProcessId)
210 {
211 NTSTATUS Status;
212 PFRONTEND FrontEnd;
213
214 /* Load a suitable frontend for the ConSrv terminal */
215 FrontEnd = ConsoleAllocHeap(HEAP_ZERO_MEMORY, sizeof(*FrontEnd));
216 if (!FrontEnd) return STATUS_NO_MEMORY;
217
218 Status = ConSrvLoadFrontEnd(FrontEnd,
219 ConsoleInfo,
220 ExtraConsoleInfo,
221 ProcessId);
222 if (!NT_SUCCESS(Status))
223 {
224 DPRINT1("CONSRV: Failed to initialize a frontend, Status = 0x%08lx\n", Status);
225 ConsoleFreeHeap(FrontEnd);
226 return Status;
227 }
228 DPRINT("CONSRV: Frontend initialized\n");
229
230 /* Initialize the ConSrv terminal */
231 Terminal->Vtbl = &ConSrvTermVtbl;
232 // Terminal->Console will be initialized by ConDrvRegisterTerminal
233 Terminal->Context = FrontEnd; /* We store the frontend pointer in the terminal private context */
234
235 return STATUS_SUCCESS;
236 }
237
238 NTSTATUS NTAPI
239 ConSrvDeinitTerminal(IN OUT PTERMINAL Terminal)
240 {
241 NTSTATUS Status = STATUS_SUCCESS;
242 PFRONTEND FrontEnd = Terminal->Context;
243
244 /* Reset the ConSrv terminal */
245 Terminal->Context = NULL;
246 Terminal->Vtbl = NULL;
247
248 /* Unload the frontend */
249 if (FrontEnd != NULL)
250 {
251 Status = ConSrvUnloadFrontEnd(FrontEnd);
252 ConsoleFreeHeap(FrontEnd);
253 }
254
255 return Status;
256 }
257
258
259 /* CONSRV TERMINAL INTERFACE **************************************************/
260
261 static NTSTATUS NTAPI
262 ConSrvTermInitTerminal(IN OUT PTERMINAL This,
263 IN PCONSOLE Console)
264 {
265 NTSTATUS Status;
266 PFRONTEND FrontEnd = This->Context;
267
268 /* Initialize the console pointer for our frontend */
269 FrontEnd->Console = Console;
270
271 /** HACK HACK!! Copy FrontEnd into the console!! **/
272 DPRINT1("Using FrontEndIFace HACK(1), should be removed after proper implementation!\n");
273 Console->FrontEndIFace = *FrontEnd;
274
275 Status = FrontEnd->Vtbl->InitFrontEnd(FrontEnd, FrontEnd->Console);
276 if (!NT_SUCCESS(Status))
277 DPRINT1("InitFrontEnd failed, Status = 0x%08lx\n", Status);
278
279 /** HACK HACK!! Be sure FrontEndIFace is correctly updated in the console!! **/
280 DPRINT("Using FrontEndIFace HACK(2), should be removed after proper implementation!\n");
281 Console->FrontEndIFace = *FrontEnd;
282
283 return Status;
284 }
285
286 static VOID NTAPI
287 ConSrvTermDeinitTerminal(IN OUT PTERMINAL This)
288 {
289 PFRONTEND FrontEnd = This->Context;
290 FrontEnd->Vtbl->DeinitFrontEnd(FrontEnd);
291 }
292
293
294
295 /************ Line discipline ***************/
296
297 static NTSTATUS NTAPI
298 ConSrvTermReadStream(IN OUT PTERMINAL This,
299 IN BOOLEAN Unicode,
300 /**PWCHAR Buffer,**/
301 OUT PVOID Buffer,
302 IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl,
303 IN PVOID Parameter OPTIONAL,
304 IN ULONG NumCharsToRead,
305 OUT PULONG NumCharsRead OPTIONAL)
306 {
307 PFRONTEND FrontEnd = This->Context;
308 PCONSRV_CONSOLE Console = FrontEnd->Console;
309 PCONSOLE_INPUT_BUFFER InputBuffer = &Console->InputBuffer;
310 PUNICODE_STRING ExeName = Parameter;
311
312 // STATUS_PENDING : Wait if more to read ; STATUS_SUCCESS : Don't wait.
313 NTSTATUS Status = STATUS_PENDING;
314
315 PLIST_ENTRY CurrentEntry;
316 ConsoleInput *Input;
317 ULONG i;
318
319 /* Validity checks */
320 // ASSERT(Console == InputBuffer->Header.Console);
321 ASSERT((Buffer != NULL) || (Buffer == NULL && NumCharsToRead == 0));
322
323 /* We haven't read anything (yet) */
324 i = ReadControl->nInitialChars;
325
326 if (InputBuffer->Mode & ENABLE_LINE_INPUT)
327 {
328 /* COOKED mode, call the line discipline */
329
330 if (Console->LineBuffer == NULL)
331 {
332 /* Starting a new line */
333 Console->LineMaxSize = max(256, NumCharsToRead);
334
335 Console->LineBuffer = ConsoleAllocHeap(0, Console->LineMaxSize * sizeof(WCHAR));
336 if (Console->LineBuffer == NULL) return STATUS_NO_MEMORY;
337
338 Console->LinePos = Console->LineSize = ReadControl->nInitialChars;
339 Console->LineComplete = Console->LineUpPressed = FALSE;
340 Console->LineInsertToggle = Console->InsertMode;
341 Console->LineWakeupMask = ReadControl->dwCtrlWakeupMask;
342
343 /*
344 * Pre-filling the buffer is only allowed in the Unicode API,
345 * so we don't need to worry about ANSI <-> Unicode conversion.
346 */
347 memcpy(Console->LineBuffer, Buffer, Console->LineSize * sizeof(WCHAR));
348 if (Console->LineSize == Console->LineMaxSize)
349 {
350 Console->LineComplete = TRUE;
351 Console->LinePos = 0;
352 }
353 }
354
355 /* If we don't have a complete line yet, process the pending input */
356 while (!Console->LineComplete && !IsListEmpty(&InputBuffer->InputEvents))
357 {
358 /* Remove input event from queue */
359 CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
360 if (IsListEmpty(&InputBuffer->InputEvents))
361 {
362 ResetEvent(InputBuffer->ActiveEvent);
363 }
364 Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
365
366 /* Only pay attention to key down */
367 if (Input->InputEvent.EventType == KEY_EVENT &&
368 Input->InputEvent.Event.KeyEvent.bKeyDown)
369 {
370 LineInputKeyDown(Console, ExeName,
371 &Input->InputEvent.Event.KeyEvent);
372 ReadControl->dwControlKeyState = Input->InputEvent.Event.KeyEvent.dwControlKeyState;
373 }
374 ConsoleFreeHeap(Input);
375 }
376
377 /* Check if we have a complete line to read from */
378 if (Console->LineComplete)
379 {
380 while (i < NumCharsToRead && Console->LinePos != Console->LineSize)
381 {
382 WCHAR Char = Console->LineBuffer[Console->LinePos++];
383
384 if (Unicode)
385 {
386 ((PWCHAR)Buffer)[i] = Char;
387 }
388 else
389 {
390 ConsoleInputUnicodeCharToAnsiChar(Console, &((PCHAR)Buffer)[i], &Char);
391 }
392 ++i;
393 }
394
395 if (Console->LinePos == Console->LineSize)
396 {
397 /* Entire line has been read */
398 ConsoleFreeHeap(Console->LineBuffer);
399 Console->LineBuffer = NULL;
400 }
401
402 Status = STATUS_SUCCESS;
403 }
404 }
405 else
406 {
407 /* RAW mode */
408
409 /* Character input */
410 while (i < NumCharsToRead && !IsListEmpty(&InputBuffer->InputEvents))
411 {
412 /* Remove input event from queue */
413 CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
414 if (IsListEmpty(&InputBuffer->InputEvents))
415 {
416 ResetEvent(InputBuffer->ActiveEvent);
417 }
418 Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
419
420 /* Only pay attention to valid characters, on key down */
421 if (Input->InputEvent.EventType == KEY_EVENT &&
422 Input->InputEvent.Event.KeyEvent.bKeyDown &&
423 Input->InputEvent.Event.KeyEvent.uChar.UnicodeChar != L'\0')
424 {
425 WCHAR Char = Input->InputEvent.Event.KeyEvent.uChar.UnicodeChar;
426
427 if (Unicode)
428 {
429 ((PWCHAR)Buffer)[i] = Char;
430 }
431 else
432 {
433 ConsoleInputUnicodeCharToAnsiChar(Console, &((PCHAR)Buffer)[i], &Char);
434 }
435 ++i;
436
437 /* Did read something */
438 Status = STATUS_SUCCESS;
439 }
440 ConsoleFreeHeap(Input);
441 }
442 }
443
444 // FIXME: Only set if Status == STATUS_SUCCESS ???
445 if (NumCharsRead) *NumCharsRead = i;
446
447 return Status;
448 }
449
450
451
452
453 /* GLOBALS ********************************************************************/
454
455 #define TAB_WIDTH 8
456
457 // See condrv/text.c
458 /*static*/ VOID
459 ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff);
460
461 static VOID
462 ConioNextLine(PTEXTMODE_SCREEN_BUFFER Buff, PSMALL_RECT UpdateRect, PUINT ScrolledLines)
463 {
464 /* If we hit bottom, slide the viewable screen */
465 if (++Buff->CursorPosition.Y == Buff->ScreenBufferSize.Y)
466 {
467 Buff->CursorPosition.Y--;
468 if (++Buff->VirtualY == Buff->ScreenBufferSize.Y)
469 {
470 Buff->VirtualY = 0;
471 }
472 (*ScrolledLines)++;
473 ClearLineBuffer(Buff);
474 if (UpdateRect->Top != 0)
475 {
476 UpdateRect->Top--;
477 }
478 }
479 UpdateRect->Left = 0;
480 UpdateRect->Right = Buff->ScreenBufferSize.X - 1;
481 UpdateRect->Bottom = Buff->CursorPosition.Y;
482 }
483
484 static NTSTATUS
485 ConioWriteConsole(PFRONTEND FrontEnd,
486 PTEXTMODE_SCREEN_BUFFER Buff,
487 PWCHAR Buffer,
488 DWORD Length,
489 BOOL Attrib)
490 {
491 PCONSRV_CONSOLE Console = FrontEnd->Console;
492
493 UINT i;
494 PCHAR_INFO Ptr;
495 SMALL_RECT UpdateRect;
496 SHORT CursorStartX, CursorStartY;
497 UINT ScrolledLines;
498
499 CursorStartX = Buff->CursorPosition.X;
500 CursorStartY = Buff->CursorPosition.Y;
501 UpdateRect.Left = Buff->ScreenBufferSize.X;
502 UpdateRect.Top = Buff->CursorPosition.Y;
503 UpdateRect.Right = -1;
504 UpdateRect.Bottom = Buff->CursorPosition.Y;
505 ScrolledLines = 0;
506
507 for (i = 0; i < Length; i++)
508 {
509 /*
510 * If we are in processed mode, interpret special characters and
511 * display them correctly. Otherwise, just put them into the buffer.
512 */
513 if (Buff->Mode & ENABLE_PROCESSED_OUTPUT)
514 {
515 /* --- CR --- */
516 if (Buffer[i] == L'\r')
517 {
518 Buff->CursorPosition.X = 0;
519 UpdateRect.Left = min(UpdateRect.Left, Buff->CursorPosition.X);
520 UpdateRect.Right = max(UpdateRect.Right, Buff->CursorPosition.X);
521 continue;
522 }
523 /* --- LF --- */
524 else if (Buffer[i] == L'\n')
525 {
526 Buff->CursorPosition.X = 0;
527 ConioNextLine(Buff, &UpdateRect, &ScrolledLines);
528 continue;
529 }
530 /* --- BS --- */
531 else if (Buffer[i] == L'\b')
532 {
533 /* Only handle BS if we're not on the first pos of the first line */
534 if (0 != Buff->CursorPosition.X || 0 != Buff->CursorPosition.Y)
535 {
536 if (0 == Buff->CursorPosition.X)
537 {
538 /* slide virtual position up */
539 Buff->CursorPosition.X = Buff->ScreenBufferSize.X - 1;
540 Buff->CursorPosition.Y--;
541 UpdateRect.Top = min(UpdateRect.Top, Buff->CursorPosition.Y);
542 }
543 else
544 {
545 Buff->CursorPosition.X--;
546 }
547 Ptr = ConioCoordToPointer(Buff, Buff->CursorPosition.X, Buff->CursorPosition.Y);
548 Ptr->Char.UnicodeChar = L' ';
549 Ptr->Attributes = Buff->ScreenDefaultAttrib;
550 UpdateRect.Left = min(UpdateRect.Left, Buff->CursorPosition.X);
551 UpdateRect.Right = max(UpdateRect.Right, Buff->CursorPosition.X);
552 }
553 continue;
554 }
555 /* --- TAB --- */
556 else if (Buffer[i] == L'\t')
557 {
558 UINT EndX;
559
560 UpdateRect.Left = min(UpdateRect.Left, Buff->CursorPosition.X);
561 EndX = (Buff->CursorPosition.X + TAB_WIDTH) & ~(TAB_WIDTH - 1);
562 EndX = min(EndX, (UINT)Buff->ScreenBufferSize.X);
563 Ptr = ConioCoordToPointer(Buff, Buff->CursorPosition.X, Buff->CursorPosition.Y);
564 while (Buff->CursorPosition.X < EndX)
565 {
566 Ptr->Char.UnicodeChar = L' ';
567 Ptr->Attributes = Buff->ScreenDefaultAttrib;
568 ++Ptr;
569 Buff->CursorPosition.X++;
570 }
571 UpdateRect.Right = max(UpdateRect.Right, Buff->CursorPosition.X - 1);
572 if (Buff->CursorPosition.X == Buff->ScreenBufferSize.X)
573 {
574 if (Buff->Mode & ENABLE_WRAP_AT_EOL_OUTPUT)
575 {
576 Buff->CursorPosition.X = 0;
577 ConioNextLine(Buff, &UpdateRect, &ScrolledLines);
578 }
579 else
580 {
581 Buff->CursorPosition.X--;
582 }
583 }
584 continue;
585 }
586 /* --- BEL ---*/
587 else if (Buffer[i] == L'\a')
588 {
589 FrontEnd->Vtbl->RingBell(FrontEnd);
590 continue;
591 }
592 }
593 UpdateRect.Left = min(UpdateRect.Left, Buff->CursorPosition.X);
594 UpdateRect.Right = max(UpdateRect.Right, Buff->CursorPosition.X);
595
596 Ptr = ConioCoordToPointer(Buff, Buff->CursorPosition.X, Buff->CursorPosition.Y);
597 Ptr->Char.UnicodeChar = Buffer[i];
598 if (Attrib) Ptr->Attributes = Buff->ScreenDefaultAttrib;
599
600 Buff->CursorPosition.X++;
601 if (Buff->CursorPosition.X == Buff->ScreenBufferSize.X)
602 {
603 if (Buff->Mode & ENABLE_WRAP_AT_EOL_OUTPUT)
604 {
605 Buff->CursorPosition.X = 0;
606 ConioNextLine(Buff, &UpdateRect, &ScrolledLines);
607 }
608 else
609 {
610 Buff->CursorPosition.X = CursorStartX;
611 }
612 }
613 }
614
615 if (!ConioIsRectEmpty(&UpdateRect) && (PCONSOLE_SCREEN_BUFFER)Buff == Console->ActiveBuffer)
616 {
617 // TermWriteStream(Console, &UpdateRect, CursorStartX, CursorStartY,
618 // ScrolledLines, Buffer, Length);
619 FrontEnd->Vtbl->WriteStream(FrontEnd,
620 &UpdateRect,
621 CursorStartX,
622 CursorStartY,
623 ScrolledLines,
624 Buffer,
625 Length);
626 }
627
628 return STATUS_SUCCESS;
629 }
630
631
632
633 static NTSTATUS NTAPI
634 ConSrvTermWriteStream(IN OUT PTERMINAL This,
635 PTEXTMODE_SCREEN_BUFFER Buff,
636 PWCHAR Buffer,
637 DWORD Length,
638 BOOL Attrib)
639 {
640 PFRONTEND FrontEnd = This->Context;
641 return ConioWriteConsole(FrontEnd,
642 Buff,
643 Buffer,
644 Length,
645 Attrib);
646 }
647
648 /************ Line discipline ***************/
649
650
651
652 VOID
653 ConioDrawConsole(PCONSRV_CONSOLE Console)
654 {
655 SMALL_RECT Region;
656 PCONSOLE_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer;
657
658 if (!ActiveBuffer) return;
659
660 ConioInitRect(&Region, 0, 0,
661 ActiveBuffer->ViewSize.Y - 1,
662 ActiveBuffer->ViewSize.X - 1);
663 TermDrawRegion(Console, &Region);
664 // Console->FrontEndIFace.Vtbl->DrawRegion(&Console->FrontEndIFace, &Region);
665 }
666
667 static VOID NTAPI
668 ConSrvTermDrawRegion(IN OUT PTERMINAL This,
669 SMALL_RECT* Region)
670 {
671 PFRONTEND FrontEnd = This->Context;
672 FrontEnd->Vtbl->DrawRegion(FrontEnd, Region);
673 }
674
675 static BOOL NTAPI
676 ConSrvTermSetCursorInfo(IN OUT PTERMINAL This,
677 PCONSOLE_SCREEN_BUFFER ScreenBuffer)
678 {
679 PFRONTEND FrontEnd = This->Context;
680 return FrontEnd->Vtbl->SetCursorInfo(FrontEnd, ScreenBuffer);
681 }
682
683 static BOOL NTAPI
684 ConSrvTermSetScreenInfo(IN OUT PTERMINAL This,
685 PCONSOLE_SCREEN_BUFFER ScreenBuffer,
686 SHORT OldCursorX,
687 SHORT OldCursorY)
688 {
689 PFRONTEND FrontEnd = This->Context;
690 return FrontEnd->Vtbl->SetScreenInfo(FrontEnd,
691 ScreenBuffer,
692 OldCursorX,
693 OldCursorY);
694 }
695
696 static VOID NTAPI
697 ConSrvTermResizeTerminal(IN OUT PTERMINAL This)
698 {
699 PFRONTEND FrontEnd = This->Context;
700 FrontEnd->Vtbl->ResizeTerminal(FrontEnd);
701 }
702
703 static VOID NTAPI
704 ConSrvTermSetActiveScreenBuffer(IN OUT PTERMINAL This)
705 {
706 PFRONTEND FrontEnd = This->Context;
707 FrontEnd->Vtbl->SetActiveScreenBuffer(FrontEnd);
708 }
709
710 static VOID NTAPI
711 ConSrvTermReleaseScreenBuffer(IN OUT PTERMINAL This,
712 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer)
713 {
714 PFRONTEND FrontEnd = This->Context;
715 FrontEnd->Vtbl->ReleaseScreenBuffer(FrontEnd, ScreenBuffer);
716 }
717
718 static VOID NTAPI
719 ConSrvTermGetLargestConsoleWindowSize(IN OUT PTERMINAL This,
720 PCOORD pSize)
721 {
722 PFRONTEND FrontEnd = This->Context;
723 FrontEnd->Vtbl->GetLargestConsoleWindowSize(FrontEnd, pSize);
724 }
725
726 static BOOL NTAPI
727 ConSrvTermSetPalette(IN OUT PTERMINAL This,
728 HPALETTE PaletteHandle,
729 UINT PaletteUsage)
730 {
731 PFRONTEND FrontEnd = This->Context;
732 return FrontEnd->Vtbl->SetPalette(FrontEnd, PaletteHandle, PaletteUsage);
733 }
734
735 static INT NTAPI
736 ConSrvTermShowMouseCursor(IN OUT PTERMINAL This,
737 BOOL Show)
738 {
739 PFRONTEND FrontEnd = This->Context;
740 return FrontEnd->Vtbl->ShowMouseCursor(FrontEnd, Show);
741 }
742
743 static TERMINAL_VTBL ConSrvTermVtbl =
744 {
745 ConSrvTermInitTerminal,
746 ConSrvTermDeinitTerminal,
747
748 ConSrvTermReadStream,
749 ConSrvTermWriteStream,
750
751 ConSrvTermDrawRegion,
752 ConSrvTermSetCursorInfo,
753 ConSrvTermSetScreenInfo,
754 ConSrvTermResizeTerminal,
755 ConSrvTermSetActiveScreenBuffer,
756 ConSrvTermReleaseScreenBuffer,
757 ConSrvTermGetLargestConsoleWindowSize,
758 ConSrvTermSetPalette,
759 ConSrvTermShowMouseCursor,
760 };
761
762 #if 0
763 VOID
764 ResetFrontEnd(IN PCONSOLE Console)
765 {
766 if (!Console) return;
767
768 /* Reinitialize the frontend interface */
769 RtlZeroMemory(&Console->FrontEndIFace, sizeof(Console->FrontEndIFace));
770 Console->FrontEndIFace.Vtbl = &ConSrvTermVtbl;
771 }
772 #endif
773
774 /* EOF */