[CONSRV]: Move all references to VDM screenbuffers from condrv back to consrv (only...
[reactos.git] / win32ss / user / winsrv / consrv / condrv / text.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Driver DLL
4 * FILE: win32ss/user/winsrv/consrv/condrv/text.c
5 * PURPOSE: Console Output Functions for text-mode screen-buffers
6 * PROGRAMMERS: Jeffrey Morlan
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #include <consrv.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 /* GLOBALS ********************************************************************/
18
19 /*
20 * From MSDN:
21 * "The lpMultiByteStr and lpWideCharStr pointers must not be the same.
22 * If they are the same, the function fails, and GetLastError returns
23 * ERROR_INVALID_PARAMETER."
24 */
25 #define ConsoleOutputUnicodeToAnsiChar(Console, dChar, sWChar) \
26 ASSERT((ULONG_PTR)dChar != (ULONG_PTR)sWChar); \
27 WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL)
28
29 #define ConsoleOutputAnsiToUnicodeChar(Console, dWChar, sChar) \
30 ASSERT((ULONG_PTR)dWChar != (ULONG_PTR)sChar); \
31 MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1)
32
33 /* PRIVATE FUNCTIONS **********************************************************/
34
35 CONSOLE_IO_OBJECT_TYPE
36 TEXTMODE_BUFFER_GetType(PCONSOLE_SCREEN_BUFFER This)
37 {
38 // return This->Header.Type;
39 return TEXTMODE_BUFFER;
40 }
41
42 static CONSOLE_SCREEN_BUFFER_VTBL TextVtbl =
43 {
44 TEXTMODE_BUFFER_GetType,
45 };
46
47
48 /*static*/ VOID
49 ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff);
50
51
52 NTSTATUS
53 CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
54 IN PCONSOLE Console,
55 IN PCONSOLE_SCREEN_BUFFER_VTBL Vtbl,
56 IN SIZE_T Size);
57 VOID
58 CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer);
59
60
61 NTSTATUS
62 TEXTMODE_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER* Buffer,
63 IN PCONSOLE Console,
64 IN HANDLE ProcessHandle,
65 IN PTEXTMODE_BUFFER_INFO TextModeInfo)
66 {
67 NTSTATUS Status = STATUS_SUCCESS;
68 PTEXTMODE_SCREEN_BUFFER NewBuffer = NULL;
69
70 UNREFERENCED_PARAMETER(ProcessHandle);
71
72 if (Console == NULL || Buffer == NULL || TextModeInfo == NULL)
73 return STATUS_INVALID_PARAMETER;
74
75 *Buffer = NULL;
76
77 Status = CONSOLE_SCREEN_BUFFER_Initialize((PCONSOLE_SCREEN_BUFFER*)&NewBuffer,
78 Console,
79 &TextVtbl,
80 sizeof(TEXTMODE_SCREEN_BUFFER));
81 if (!NT_SUCCESS(Status)) return Status;
82 NewBuffer->Header.Type = TEXTMODE_BUFFER;
83
84 NewBuffer->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
85 TextModeInfo->ScreenBufferSize.X *
86 TextModeInfo->ScreenBufferSize.Y *
87 sizeof(CHAR_INFO));
88 if (NewBuffer->Buffer == NULL)
89 {
90 CONSOLE_SCREEN_BUFFER_Destroy((PCONSOLE_SCREEN_BUFFER)NewBuffer);
91 return STATUS_INSUFFICIENT_RESOURCES;
92 }
93
94 NewBuffer->ScreenBufferSize = NewBuffer->OldScreenBufferSize
95 = TextModeInfo->ScreenBufferSize;
96 NewBuffer->ViewSize = NewBuffer->OldViewSize
97 = Console->ConsoleSize;
98
99 NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
100 NewBuffer->VirtualY = 0;
101
102 NewBuffer->CursorBlinkOn = NewBuffer->ForceCursorOff = FALSE;
103 NewBuffer->CursorInfo.bVisible = (TextModeInfo->IsCursorVisible && (TextModeInfo->CursorSize != 0));
104 NewBuffer->CursorInfo.dwSize = min(max(TextModeInfo->CursorSize, 0), 100);
105
106 NewBuffer->ScreenDefaultAttrib = TextModeInfo->ScreenAttrib;
107 NewBuffer->PopupDefaultAttrib = TextModeInfo->PopupAttrib;
108
109 /* Initialize buffer to be empty with default attributes */
110 for (NewBuffer->CursorPosition.Y = 0 ; NewBuffer->CursorPosition.Y < NewBuffer->ScreenBufferSize.Y; NewBuffer->CursorPosition.Y++)
111 {
112 ClearLineBuffer(NewBuffer);
113 }
114 NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
115
116 NewBuffer->Mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
117
118 *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
119 return STATUS_SUCCESS;
120 }
121
122 VOID
123 TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
124 {
125 PTEXTMODE_SCREEN_BUFFER Buff = (PTEXTMODE_SCREEN_BUFFER)Buffer;
126
127 /*
128 * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
129 * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
130 */
131 Buffer->Header.Type = SCREEN_BUFFER;
132
133 ConsoleFreeHeap(Buff->Buffer);
134
135 CONSOLE_SCREEN_BUFFER_Destroy(Buffer);
136 }
137
138
139 PCHAR_INFO
140 ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
141 {
142 return &Buff->Buffer[((Y + Buff->VirtualY) % Buff->ScreenBufferSize.Y) * Buff->ScreenBufferSize.X + X];
143 }
144
145 /*static*/ VOID
146 ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff)
147 {
148 PCHAR_INFO Ptr = ConioCoordToPointer(Buff, 0, Buff->CursorPosition.Y);
149 SHORT Pos;
150
151 for (Pos = 0; Pos < Buff->ScreenBufferSize.X; Pos++, Ptr++)
152 {
153 /* Fill the cell */
154 Ptr->Char.UnicodeChar = L' ';
155 Ptr->Attributes = Buff->ScreenDefaultAttrib;
156 }
157 }
158
159 static VOID
160 ConioComputeUpdateRect(IN PTEXTMODE_SCREEN_BUFFER Buff,
161 IN OUT PSMALL_RECT UpdateRect,
162 IN PCOORD Start,
163 IN UINT Length)
164 {
165 if (Buff->ScreenBufferSize.X <= Start->X + Length)
166 {
167 UpdateRect->Left = 0;
168 }
169 else
170 {
171 UpdateRect->Left = Start->X;
172 }
173 if (Buff->ScreenBufferSize.X <= Start->X + Length)
174 {
175 UpdateRect->Right = Buff->ScreenBufferSize.X - 1;
176 }
177 else
178 {
179 UpdateRect->Right = Start->X + Length - 1;
180 }
181 UpdateRect->Top = Start->Y;
182 UpdateRect->Bottom = Start->Y + (Start->X + Length - 1) / Buff->ScreenBufferSize.X;
183 if (Buff->ScreenBufferSize.Y <= UpdateRect->Bottom)
184 {
185 UpdateRect->Bottom = Buff->ScreenBufferSize.Y - 1;
186 }
187 }
188
189 /*
190 * Move from one rectangle to another. We must be careful about the order that
191 * this is done, to avoid overwriting parts of the source before they are moved.
192 */
193 static VOID
194 ConioMoveRegion(PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
195 PSMALL_RECT SrcRegion,
196 PSMALL_RECT DstRegion,
197 PSMALL_RECT ClipRegion,
198 CHAR_INFO FillChar)
199 {
200 int Width = ConioRectWidth(SrcRegion);
201 int Height = ConioRectHeight(SrcRegion);
202 int SX, SY;
203 int DX, DY;
204 int XDelta, YDelta;
205 int i, j;
206
207 SY = SrcRegion->Top;
208 DY = DstRegion->Top;
209 YDelta = 1;
210 if (SY < DY)
211 {
212 /* Moving down: work from bottom up */
213 SY = SrcRegion->Bottom;
214 DY = DstRegion->Bottom;
215 YDelta = -1;
216 }
217 for (i = 0; i < Height; i++)
218 {
219 PCHAR_INFO SRow = ConioCoordToPointer(ScreenBuffer, 0, SY);
220 PCHAR_INFO DRow = ConioCoordToPointer(ScreenBuffer, 0, DY);
221
222 SX = SrcRegion->Left;
223 DX = DstRegion->Left;
224 XDelta = 1;
225 if (SX < DX)
226 {
227 /* Moving right: work from right to left */
228 SX = SrcRegion->Right;
229 DX = DstRegion->Right;
230 XDelta = -1;
231 }
232 for (j = 0; j < Width; j++)
233 {
234 CHAR_INFO Cell = SRow[SX];
235 if (SX >= ClipRegion->Left && SX <= ClipRegion->Right &&
236 SY >= ClipRegion->Top && SY <= ClipRegion->Bottom)
237 {
238 SRow[SX] = FillChar;
239 }
240 if (DX >= ClipRegion->Left && DX <= ClipRegion->Right &&
241 DY >= ClipRegion->Top && DY <= ClipRegion->Bottom)
242 {
243 DRow[DX] = Cell;
244 }
245 SX += XDelta;
246 DX += XDelta;
247 }
248 SY += YDelta;
249 DY += YDelta;
250 }
251 }
252
253 // FIXME!
254 NTSTATUS NTAPI
255 ConDrvWriteConsoleInput(IN PCONSOLE Console,
256 IN PCONSOLE_INPUT_BUFFER InputBuffer,
257 IN BOOLEAN AppendToEnd,
258 IN PINPUT_RECORD InputRecord,
259 IN ULONG NumEventsToWrite,
260 OUT PULONG NumEventsWritten OPTIONAL);
261
262 NTSTATUS
263 ConioResizeBuffer(PCONSOLE Console,
264 PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
265 COORD Size)
266 {
267 PCHAR_INFO Buffer;
268 DWORD Offset = 0;
269 PCHAR_INFO ptr;
270 WORD CurrentAttribute;
271 USHORT CurrentY;
272 PCHAR_INFO OldBuffer;
273 DWORD i;
274 DWORD diff;
275
276 /* Buffer size is not allowed to be smaller than the view size */
277 if (Size.X < ScreenBuffer->ViewSize.X || Size.Y < ScreenBuffer->ViewSize.Y)
278 return STATUS_INVALID_PARAMETER;
279
280 if (Size.X == ScreenBuffer->ScreenBufferSize.X && Size.Y == ScreenBuffer->ScreenBufferSize.Y)
281 {
282 // FIXME: Trigger a buffer resize event ??
283 return STATUS_SUCCESS;
284 }
285
286 if (Console->FixedSize)
287 {
288 /*
289 * The console is in fixed-size mode, so we cannot resize anything
290 * at the moment. However, keep those settings somewhere so that
291 * we can try to set them up when we will be allowed to do so.
292 */
293 ScreenBuffer->OldScreenBufferSize = Size;
294 return STATUS_NOT_SUPPORTED; // STATUS_SUCCESS
295 }
296
297 Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY, Size.X * Size.Y * sizeof(CHAR_INFO));
298 if (!Buffer) return STATUS_NO_MEMORY;
299
300 DPRINT("Resizing (%d,%d) to (%d,%d)\n", ScreenBuffer->ScreenBufferSize.X, ScreenBuffer->ScreenBufferSize.Y, Size.X, Size.Y);
301 OldBuffer = ScreenBuffer->Buffer;
302
303 for (CurrentY = 0; CurrentY < ScreenBuffer->ScreenBufferSize.Y && CurrentY < Size.Y; CurrentY++)
304 {
305 ptr = ConioCoordToPointer(ScreenBuffer, 0, CurrentY);
306 if (Size.X <= ScreenBuffer->ScreenBufferSize.X)
307 {
308 /* Reduce size */
309 RtlCopyMemory(Buffer + Offset, ptr, Size.X * sizeof(CHAR_INFO));
310 Offset += Size.X;
311 }
312 else
313 {
314 /* Enlarge size */
315 RtlCopyMemory(Buffer + Offset, ptr, ScreenBuffer->ScreenBufferSize.X * sizeof(CHAR_INFO));
316 Offset += ScreenBuffer->ScreenBufferSize.X;
317
318 /* The attribute to be used is the one of the last cell of the current line */
319 CurrentAttribute = ConioCoordToPointer(ScreenBuffer,
320 ScreenBuffer->ScreenBufferSize.X - 1,
321 CurrentY)->Attributes;
322
323 diff = Size.X - ScreenBuffer->ScreenBufferSize.X;
324
325 /* Zero-out the new part of the buffer */
326 for (i = 0; i < diff; i++)
327 {
328 ptr = Buffer + Offset;
329 ptr->Char.UnicodeChar = L' ';
330 ptr->Attributes = CurrentAttribute;
331 ++Offset;
332 }
333 }
334 }
335
336 if (Size.Y > ScreenBuffer->ScreenBufferSize.Y)
337 {
338 diff = Size.X * (Size.Y - ScreenBuffer->ScreenBufferSize.Y);
339
340 /* Zero-out the new part of the buffer */
341 for (i = 0; i < diff; i++)
342 {
343 ptr = Buffer + Offset;
344 ptr->Char.UnicodeChar = L' ';
345 ptr->Attributes = ScreenBuffer->ScreenDefaultAttrib;
346 ++Offset;
347 }
348 }
349
350 (void)InterlockedExchangePointer((PVOID volatile*)&ScreenBuffer->Buffer, Buffer);
351 ConsoleFreeHeap(OldBuffer);
352 ScreenBuffer->ScreenBufferSize = ScreenBuffer->OldScreenBufferSize = Size;
353 ScreenBuffer->VirtualY = 0;
354
355 /* Ensure cursor and window are within buffer */
356 if (ScreenBuffer->CursorPosition.X >= Size.X)
357 ScreenBuffer->CursorPosition.X = Size.X - 1;
358 if (ScreenBuffer->CursorPosition.Y >= Size.Y)
359 ScreenBuffer->CursorPosition.Y = Size.Y - 1;
360 if (ScreenBuffer->ViewOrigin.X > Size.X - ScreenBuffer->ViewSize.X)
361 ScreenBuffer->ViewOrigin.X = Size.X - ScreenBuffer->ViewSize.X;
362 if (ScreenBuffer->ViewOrigin.Y > Size.Y - ScreenBuffer->ViewSize.Y)
363 ScreenBuffer->ViewOrigin.Y = Size.Y - ScreenBuffer->ViewSize.Y;
364
365 /*
366 * Trigger a buffer resize event
367 */
368 if (Console->InputBuffer.Mode & ENABLE_WINDOW_INPUT)
369 {
370 ULONG NumEventsWritten;
371 INPUT_RECORD er;
372
373 er.EventType = WINDOW_BUFFER_SIZE_EVENT;
374 er.Event.WindowBufferSizeEvent.dwSize = ScreenBuffer->ScreenBufferSize;
375
376 // ConioProcessInputEvent(Console, &er);
377 ConDrvWriteConsoleInput(Console,
378 &Console->InputBuffer,
379 TRUE,
380 &er,
381 1,
382 &NumEventsWritten);
383 }
384
385 return STATUS_SUCCESS;
386 }
387
388 NTSTATUS NTAPI
389 ConDrvChangeScreenBufferAttributes(IN PCONSOLE Console,
390 IN PTEXTMODE_SCREEN_BUFFER Buffer,
391 IN USHORT NewScreenAttrib,
392 IN USHORT NewPopupAttrib)
393 {
394 DWORD X, Y, Length;
395 PCHAR_INFO Ptr;
396
397 COORD TopLeft = {0};
398 ULONG NumCodesToWrite;
399 USHORT OldScreenAttrib, OldPopupAttrib;
400
401 if (Console == NULL || Buffer == NULL)
402 {
403 return STATUS_INVALID_PARAMETER;
404 }
405
406 /* Validity check */
407 ASSERT(Console == Buffer->Header.Console);
408
409 NumCodesToWrite = Buffer->ScreenBufferSize.X * Buffer->ScreenBufferSize.Y;
410 OldScreenAttrib = Buffer->ScreenDefaultAttrib;
411 OldPopupAttrib = Buffer->PopupDefaultAttrib;
412
413 X = TopLeft.X;
414 Y = (TopLeft.Y + Buffer->VirtualY) % Buffer->ScreenBufferSize.Y;
415 Length = NumCodesToWrite;
416
417 // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work
418 // Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X]; // May work
419
420 while (Length--)
421 {
422 // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work either
423 Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X];
424
425 /*
426 * Change the current colors only if they are the old ones.
427 */
428
429 /* Foreground color */
430 if ((Ptr->Attributes & 0x0F) == (OldScreenAttrib & 0x0F))
431 Ptr->Attributes = (Ptr->Attributes & 0xFFF0) | (NewScreenAttrib & 0x0F);
432 if ((Ptr->Attributes & 0x0F) == (OldPopupAttrib & 0x0F))
433 Ptr->Attributes = (Ptr->Attributes & 0xFFF0) | (NewPopupAttrib & 0x0F);
434
435 /* Background color */
436 if ((Ptr->Attributes & 0xF0) == (OldScreenAttrib & 0xF0))
437 Ptr->Attributes = (Ptr->Attributes & 0xFF0F) | (NewScreenAttrib & 0xF0);
438 if ((Ptr->Attributes & 0xF0) == (OldPopupAttrib & 0xF0))
439 Ptr->Attributes = (Ptr->Attributes & 0xFF0F) | (NewPopupAttrib & 0xF0);
440
441 // ++Ptr;
442
443 if (++X == Buffer->ScreenBufferSize.X)
444 {
445 X = 0;
446
447 if (++Y == Buffer->ScreenBufferSize.Y)
448 {
449 Y = 0;
450 }
451 }
452 }
453
454 /* Save foreground and background colors for both screen and popup */
455 Buffer->ScreenDefaultAttrib = (NewScreenAttrib & 0x00FF);
456 Buffer->PopupDefaultAttrib = (NewPopupAttrib & 0x00FF);
457
458 /* Refresh the display if needed */
459 if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
460 {
461 SMALL_RECT UpdateRect;
462 ConioComputeUpdateRect(Buffer, &UpdateRect, &TopLeft, NumCodesToWrite);
463 TermDrawRegion(Console, &UpdateRect);
464 }
465
466 return STATUS_SUCCESS;
467 }
468
469
470 /* PUBLIC DRIVER APIS *********************************************************/
471
472 NTSTATUS NTAPI
473 ConDrvReadConsoleOutput(IN PCONSOLE Console,
474 IN PTEXTMODE_SCREEN_BUFFER Buffer,
475 IN BOOLEAN Unicode,
476 OUT PCHAR_INFO CharInfo/*Buffer*/,
477 IN OUT PSMALL_RECT ReadRegion)
478 {
479 SHORT X, Y;
480 SMALL_RECT ScreenBuffer;
481 PCHAR_INFO CurCharInfo;
482 SMALL_RECT CapturedReadRegion;
483 PCHAR_INFO Ptr;
484
485 if (Console == NULL || Buffer == NULL || CharInfo == NULL || ReadRegion == NULL)
486 {
487 return STATUS_INVALID_PARAMETER;
488 }
489
490 /* Validity check */
491 ASSERT(Console == Buffer->Header.Console);
492
493 CapturedReadRegion = *ReadRegion;
494
495 /* Make sure ReadRegion is inside the screen buffer */
496 ConioInitRect(&ScreenBuffer, 0, 0,
497 Buffer->ScreenBufferSize.Y - 1, Buffer->ScreenBufferSize.X - 1);
498 if (!ConioGetIntersection(&CapturedReadRegion, &ScreenBuffer, &CapturedReadRegion))
499 {
500 /*
501 * It is okay to have a ReadRegion completely outside
502 * the screen buffer. No data is read then.
503 */
504 return STATUS_SUCCESS;
505 }
506
507 CurCharInfo = CharInfo;
508
509 for (Y = CapturedReadRegion.Top; Y <= CapturedReadRegion.Bottom; ++Y)
510 {
511 Ptr = ConioCoordToPointer(Buffer, CapturedReadRegion.Left, Y);
512 for (X = CapturedReadRegion.Left; X <= CapturedReadRegion.Right; ++X)
513 {
514 if (Unicode)
515 {
516 CurCharInfo->Char.UnicodeChar = Ptr->Char.UnicodeChar;
517 }
518 else
519 {
520 // ConsoleOutputUnicodeToAnsiChar(Console, &CurCharInfo->Char.AsciiChar, &Ptr->Char.UnicodeChar);
521 WideCharToMultiByte(Console->OutputCodePage, 0, &Ptr->Char.UnicodeChar, 1,
522 &CurCharInfo->Char.AsciiChar, 1, NULL, NULL);
523 }
524 CurCharInfo->Attributes = Ptr->Attributes;
525 ++Ptr;
526 ++CurCharInfo;
527 }
528 }
529
530 *ReadRegion = CapturedReadRegion;
531
532 return STATUS_SUCCESS;
533 }
534
535 NTSTATUS NTAPI
536 ConDrvWriteConsoleOutput(IN PCONSOLE Console,
537 IN PTEXTMODE_SCREEN_BUFFER Buffer,
538 IN BOOLEAN Unicode,
539 IN PCHAR_INFO CharInfo/*Buffer*/,
540 IN OUT PSMALL_RECT WriteRegion)
541 {
542 SHORT X, Y;
543 SMALL_RECT ScreenBuffer;
544 PCHAR_INFO CurCharInfo;
545 SMALL_RECT CapturedWriteRegion;
546 PCHAR_INFO Ptr;
547
548 if (Console == NULL || Buffer == NULL || CharInfo == NULL || WriteRegion == NULL)
549 {
550 return STATUS_INVALID_PARAMETER;
551 }
552
553 /* Validity check */
554 ASSERT(Console == Buffer->Header.Console);
555
556 CapturedWriteRegion = *WriteRegion;
557
558 /* Make sure WriteRegion is inside the screen buffer */
559 ConioInitRect(&ScreenBuffer, 0, 0,
560 Buffer->ScreenBufferSize.Y - 1, Buffer->ScreenBufferSize.X - 1);
561 if (!ConioGetIntersection(&CapturedWriteRegion, &ScreenBuffer, &CapturedWriteRegion))
562 {
563 /*
564 * It is okay to have a WriteRegion completely outside
565 * the screen buffer. No data is written then.
566 */
567 return STATUS_SUCCESS;
568 }
569
570 CurCharInfo = CharInfo;
571
572 for (Y = CapturedWriteRegion.Top; Y <= CapturedWriteRegion.Bottom; ++Y)
573 {
574 Ptr = ConioCoordToPointer(Buffer, CapturedWriteRegion.Left, Y);
575 for (X = CapturedWriteRegion.Left; X <= CapturedWriteRegion.Right; ++X)
576 {
577 if (Unicode)
578 {
579 Ptr->Char.UnicodeChar = CurCharInfo->Char.UnicodeChar;
580 }
581 else
582 {
583 ConsoleOutputAnsiToUnicodeChar(Console, &Ptr->Char.UnicodeChar, &CurCharInfo->Char.AsciiChar);
584 }
585 Ptr->Attributes = CurCharInfo->Attributes;
586 ++Ptr;
587 ++CurCharInfo;
588 }
589 }
590
591 TermDrawRegion(Console, &CapturedWriteRegion);
592
593 *WriteRegion = CapturedWriteRegion;
594
595 return STATUS_SUCCESS;
596 }
597
598 /*
599 * NOTE: This function is strongly inspired by ConDrvWriteConsoleOutput...
600 * FIXME: This function MUST be moved into consrv/conoutput.c because only
601 * consrv knows how to manipulate VDM screenbuffers.
602 */
603 NTSTATUS NTAPI
604 ConDrvWriteConsoleOutputVDM(IN PCONSOLE Console,
605 IN PTEXTMODE_SCREEN_BUFFER Buffer,
606 IN PCHAR_CELL CharInfo/*Buffer*/,
607 IN COORD CharInfoSize,
608 IN PSMALL_RECT WriteRegion)
609 {
610 SHORT X, Y;
611 SMALL_RECT ScreenBuffer;
612 PCHAR_CELL CurCharInfo;
613 SMALL_RECT CapturedWriteRegion;
614 PCHAR_INFO Ptr;
615
616 if (Console == NULL || Buffer == NULL || CharInfo == NULL || WriteRegion == NULL)
617 {
618 return STATUS_INVALID_PARAMETER;
619 }
620
621 /* Validity check */
622 ASSERT(Console == Buffer->Header.Console);
623
624 CapturedWriteRegion = *WriteRegion;
625
626 /* Make sure WriteRegion is inside the screen buffer */
627 ConioInitRect(&ScreenBuffer, 0, 0,
628 Buffer->ScreenBufferSize.Y - 1, Buffer->ScreenBufferSize.X - 1);
629 if (!ConioGetIntersection(&CapturedWriteRegion, &ScreenBuffer, &CapturedWriteRegion))
630 {
631 /*
632 * It is okay to have a WriteRegion completely outside
633 * the screen buffer. No data is written then.
634 */
635 return STATUS_SUCCESS;
636 }
637
638 // CurCharInfo = CharInfo;
639
640 for (Y = CapturedWriteRegion.Top; Y <= CapturedWriteRegion.Bottom; ++Y)
641 {
642 /**/CurCharInfo = CharInfo + Y * CharInfoSize.X + CapturedWriteRegion.Left;/**/
643
644 Ptr = ConioCoordToPointer(Buffer, CapturedWriteRegion.Left, Y);
645 for (X = CapturedWriteRegion.Left; X <= CapturedWriteRegion.Right; ++X)
646 {
647 ConsoleOutputAnsiToUnicodeChar(Console, &Ptr->Char.UnicodeChar, &CurCharInfo->Char);
648 Ptr->Attributes = CurCharInfo->Attributes;
649 ++Ptr;
650 ++CurCharInfo;
651 }
652 }
653
654 return STATUS_SUCCESS;
655 }
656
657 NTSTATUS NTAPI
658 ConDrvWriteConsole(IN PCONSOLE Console,
659 IN PTEXTMODE_SCREEN_BUFFER ScreenBuffer,
660 IN BOOLEAN Unicode,
661 IN PVOID StringBuffer,
662 IN ULONG NumCharsToWrite,
663 OUT PULONG NumCharsWritten OPTIONAL)
664 {
665 NTSTATUS Status = STATUS_SUCCESS;
666 PWCHAR Buffer = NULL;
667 ULONG Written = 0;
668 ULONG Length;
669
670 if (Console == NULL || ScreenBuffer == NULL /* || StringBuffer == NULL */)
671 return STATUS_INVALID_PARAMETER;
672
673 /* Validity checks */
674 ASSERT(Console == ScreenBuffer->Header.Console);
675 ASSERT((StringBuffer != NULL) || (StringBuffer == NULL && NumCharsToWrite == 0));
676
677 /* Stop here if the console is paused */
678 if (Console->UnpauseEvent != NULL) return STATUS_PENDING;
679
680 /* Convert the string to UNICODE */
681 if (Unicode)
682 {
683 Buffer = StringBuffer;
684 }
685 else
686 {
687 Length = MultiByteToWideChar(Console->OutputCodePage, 0,
688 (PCHAR)StringBuffer,
689 NumCharsToWrite,
690 NULL, 0);
691 Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length * sizeof(WCHAR));
692 if (Buffer)
693 {
694 MultiByteToWideChar(Console->OutputCodePage, 0,
695 (PCHAR)StringBuffer,
696 NumCharsToWrite,
697 (PWCHAR)Buffer, Length);
698 }
699 else
700 {
701 Status = STATUS_NO_MEMORY;
702 }
703 }
704
705 /* Send it */
706 if (Buffer)
707 {
708 if (NT_SUCCESS(Status))
709 {
710 Status = TermWriteStream(Console,
711 ScreenBuffer,
712 Buffer,
713 NumCharsToWrite,
714 TRUE);
715 if (NT_SUCCESS(Status))
716 {
717 Written = NumCharsToWrite;
718 }
719 }
720
721 if (!Unicode) RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
722 }
723
724 if (NumCharsWritten) *NumCharsWritten = Written;
725
726 return Status;
727 }
728
729 NTSTATUS NTAPI
730 ConDrvReadConsoleOutputString(IN PCONSOLE Console,
731 IN PTEXTMODE_SCREEN_BUFFER Buffer,
732 IN CODE_TYPE CodeType,
733 OUT PVOID StringBuffer,
734 IN ULONG NumCodesToRead,
735 IN PCOORD ReadCoord,
736 // OUT PCOORD EndCoord,
737 OUT PULONG NumCodesRead OPTIONAL)
738 {
739 SHORT Xpos, Ypos;
740 PVOID ReadBuffer;
741 ULONG i;
742 ULONG CodeSize;
743 PCHAR_INFO Ptr;
744
745 if (Console == NULL || Buffer == NULL || ReadCoord == NULL /* || EndCoord == NULL */)
746 {
747 return STATUS_INVALID_PARAMETER;
748 }
749
750 /* Validity checks */
751 ASSERT(Console == Buffer->Header.Console);
752 ASSERT((StringBuffer != NULL) || (StringBuffer == NULL && NumCodesToRead == 0));
753
754 //
755 // FIXME: Make overflow checks on ReadCoord !!!!!!
756 //
757
758 if (NumCodesRead) *NumCodesRead = 0;
759
760 switch (CodeType)
761 {
762 case CODE_ASCII:
763 CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
764 break;
765
766 case CODE_UNICODE:
767 CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
768 break;
769
770 case CODE_ATTRIBUTE:
771 CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
772 break;
773
774 default:
775 return STATUS_INVALID_PARAMETER;
776 }
777
778 ReadBuffer = StringBuffer;
779 Xpos = ReadCoord->X;
780 Ypos = (ReadCoord->Y + Buffer->VirtualY) % Buffer->ScreenBufferSize.Y;
781
782 /*
783 * MSDN (ReadConsoleOutputAttribute and ReadConsoleOutputCharacter) :
784 *
785 * If the number of attributes (resp. characters) to be read from extends
786 * beyond the end of the specified screen buffer row, attributes (resp.
787 * characters) are read from the next row. If the number of attributes
788 * (resp. characters) to be read from extends beyond the end of the console
789 * screen buffer, attributes (resp. characters) up to the end of the console
790 * screen buffer are read.
791 *
792 * TODO: Do NOT loop up to NumCodesToRead, but stop before
793 * if we are going to overflow...
794 */
795 // Ptr = ConioCoordToPointer(Buffer, Xpos, Ypos); // Doesn't work
796 for (i = 0; i < min(NumCodesToRead, Buffer->ScreenBufferSize.X * Buffer->ScreenBufferSize.Y); ++i)
797 {
798 // Ptr = ConioCoordToPointer(Buffer, Xpos, Ypos); // Doesn't work either
799 Ptr = &Buffer->Buffer[Xpos + Ypos * Buffer->ScreenBufferSize.X];
800
801 switch (CodeType)
802 {
803 case CODE_ASCII:
804 ConsoleOutputUnicodeToAnsiChar(Console, (PCHAR)ReadBuffer, &Ptr->Char.UnicodeChar);
805 break;
806
807 case CODE_UNICODE:
808 *(PWCHAR)ReadBuffer = Ptr->Char.UnicodeChar;
809 break;
810
811 case CODE_ATTRIBUTE:
812 *(PWORD)ReadBuffer = Ptr->Attributes;
813 break;
814 }
815 ReadBuffer = (PVOID)((ULONG_PTR)ReadBuffer + CodeSize);
816 // ++Ptr;
817
818 Xpos++;
819
820 if (Xpos == Buffer->ScreenBufferSize.X)
821 {
822 Xpos = 0;
823 Ypos++;
824
825 if (Ypos == Buffer->ScreenBufferSize.Y)
826 {
827 Ypos = 0;
828 }
829 }
830 }
831
832 // EndCoord->X = Xpos;
833 // EndCoord->Y = (Ypos - Buffer->VirtualY + Buffer->ScreenBufferSize.Y) % Buffer->ScreenBufferSize.Y;
834
835 if (NumCodesRead)
836 *NumCodesRead = (ULONG)((ULONG_PTR)ReadBuffer - (ULONG_PTR)StringBuffer) / CodeSize;
837 // <= NumCodesToRead
838
839 return STATUS_SUCCESS;
840 }
841
842 NTSTATUS NTAPI
843 ConDrvWriteConsoleOutputString(IN PCONSOLE Console,
844 IN PTEXTMODE_SCREEN_BUFFER Buffer,
845 IN CODE_TYPE CodeType,
846 IN PVOID StringBuffer,
847 IN ULONG NumCodesToWrite,
848 IN PCOORD WriteCoord,
849 // OUT PCOORD EndCoord,
850 OUT PULONG NumCodesWritten OPTIONAL)
851 {
852 NTSTATUS Status = STATUS_SUCCESS;
853 PVOID WriteBuffer = NULL;
854 PWCHAR tmpString = NULL;
855 DWORD X, Y, Length; // , Written = 0;
856 ULONG CodeSize;
857 PCHAR_INFO Ptr;
858
859 if (Console == NULL || Buffer == NULL || WriteCoord == NULL /* || EndCoord == NULL */)
860 {
861 return STATUS_INVALID_PARAMETER;
862 }
863
864 /* Validity checks */
865 ASSERT(Console == Buffer->Header.Console);
866 ASSERT((StringBuffer != NULL) || (StringBuffer == NULL && NumCodesToWrite == 0));
867
868 //
869 // FIXME: Make overflow checks on WriteCoord !!!!!!
870 //
871
872 if (NumCodesWritten) *NumCodesWritten = 0;
873
874 switch (CodeType)
875 {
876 case CODE_ASCII:
877 CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
878 break;
879
880 case CODE_UNICODE:
881 CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
882 break;
883
884 case CODE_ATTRIBUTE:
885 CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
886 break;
887
888 default:
889 return STATUS_INVALID_PARAMETER;
890 }
891
892 if (CodeType == CODE_ASCII)
893 {
894 /* Convert the ASCII string into Unicode before writing it to the console */
895 Length = MultiByteToWideChar(Console->OutputCodePage, 0,
896 (PCHAR)StringBuffer,
897 NumCodesToWrite,
898 NULL, 0);
899 tmpString = WriteBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length * sizeof(WCHAR));
900 if (WriteBuffer)
901 {
902 MultiByteToWideChar(Console->OutputCodePage, 0,
903 (PCHAR)StringBuffer,
904 NumCodesToWrite,
905 (PWCHAR)WriteBuffer, Length);
906 }
907 else
908 {
909 Status = STATUS_NO_MEMORY;
910 }
911
912 // FIXME: Quick fix: fix the CodeType and CodeSize since the
913 // ASCII string was converted into UNICODE.
914 // A proper fix needs to be written.
915 CodeType = CODE_UNICODE;
916 CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
917 }
918 else
919 {
920 /* For CODE_UNICODE or CODE_ATTRIBUTE, we are already OK */
921 WriteBuffer = StringBuffer;
922 }
923
924 if (WriteBuffer == NULL || !NT_SUCCESS(Status)) goto Cleanup;
925
926 X = WriteCoord->X;
927 Y = (WriteCoord->Y + Buffer->VirtualY) % Buffer->ScreenBufferSize.Y;
928 Length = NumCodesToWrite;
929 // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work
930 // Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X]; // May work
931
932 while (Length--)
933 {
934 // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work either
935 Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X];
936
937 switch (CodeType)
938 {
939 case CODE_ASCII:
940 case CODE_UNICODE:
941 Ptr->Char.UnicodeChar = *(PWCHAR)WriteBuffer;
942 break;
943
944 case CODE_ATTRIBUTE:
945 Ptr->Attributes = *(PWORD)WriteBuffer;
946 break;
947 }
948 WriteBuffer = (PVOID)((ULONG_PTR)WriteBuffer + CodeSize);
949 // ++Ptr;
950
951 // Written++;
952 if (++X == Buffer->ScreenBufferSize.X)
953 {
954 X = 0;
955
956 if (++Y == Buffer->ScreenBufferSize.Y)
957 {
958 Y = 0;
959 }
960 }
961 }
962
963 if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
964 {
965 SMALL_RECT UpdateRect;
966 ConioComputeUpdateRect(Buffer, &UpdateRect, WriteCoord, NumCodesToWrite);
967 TermDrawRegion(Console, &UpdateRect);
968 }
969
970 // EndCoord->X = X;
971 // EndCoord->Y = (Y + Buffer->ScreenBufferSize.Y - Buffer->VirtualY) % Buffer->ScreenBufferSize.Y;
972
973 Cleanup:
974 if (tmpString) RtlFreeHeap(RtlGetProcessHeap(), 0, tmpString);
975
976 if (NumCodesWritten) *NumCodesWritten = NumCodesToWrite; // Written;
977 return Status;
978 }
979
980 NTSTATUS NTAPI
981 ConDrvFillConsoleOutput(IN PCONSOLE Console,
982 IN PTEXTMODE_SCREEN_BUFFER Buffer,
983 IN CODE_TYPE CodeType,
984 IN CODE_ELEMENT Code,
985 IN ULONG NumCodesToWrite,
986 IN PCOORD WriteCoord,
987 OUT PULONG NumCodesWritten OPTIONAL)
988 {
989 DWORD X, Y, Length; // , Written = 0;
990 PCHAR_INFO Ptr;
991
992 if (Console == NULL || Buffer == NULL || WriteCoord == NULL)
993 {
994 return STATUS_INVALID_PARAMETER;
995 }
996
997 /* Validity check */
998 ASSERT(Console == Buffer->Header.Console);
999
1000 //
1001 // FIXME: Make overflow checks on WriteCoord !!!!!!
1002 //
1003
1004 if (NumCodesWritten) *NumCodesWritten = 0;
1005
1006 if (CodeType == CODE_ASCII)
1007 {
1008 /* Conversion from the ASCII char to the UNICODE char */
1009 CODE_ELEMENT tmp;
1010 ConsoleOutputAnsiToUnicodeChar(Console, &tmp.UnicodeChar, &Code.AsciiChar);
1011 Code = tmp;
1012 }
1013
1014 X = WriteCoord->X;
1015 Y = (WriteCoord->Y + Buffer->VirtualY) % Buffer->ScreenBufferSize.Y;
1016 Length = NumCodesToWrite;
1017 // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work
1018 // Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X]; // May work
1019
1020 while (Length--)
1021 {
1022 // Ptr = ConioCoordToPointer(Buffer, X, Y); // Doesn't work either
1023 Ptr = &Buffer->Buffer[X + Y * Buffer->ScreenBufferSize.X];
1024
1025 switch (CodeType)
1026 {
1027 case CODE_ASCII:
1028 case CODE_UNICODE:
1029 Ptr->Char.UnicodeChar = Code.UnicodeChar;
1030 break;
1031
1032 case CODE_ATTRIBUTE:
1033 Ptr->Attributes = Code.Attribute;
1034 break;
1035 }
1036 // ++Ptr;
1037
1038 // Written++;
1039 if (++X == Buffer->ScreenBufferSize.X)
1040 {
1041 X = 0;
1042
1043 if (++Y == Buffer->ScreenBufferSize.Y)
1044 {
1045 Y = 0;
1046 }
1047 }
1048 }
1049
1050 if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
1051 {
1052 SMALL_RECT UpdateRect;
1053 ConioComputeUpdateRect(Buffer, &UpdateRect, WriteCoord, NumCodesToWrite);
1054 TermDrawRegion(Console, &UpdateRect);
1055 }
1056
1057 if (NumCodesWritten) *NumCodesWritten = NumCodesToWrite; // Written;
1058 return STATUS_SUCCESS;
1059 }
1060
1061 NTSTATUS NTAPI
1062 ConDrvGetConsoleScreenBufferInfo(IN PCONSOLE Console,
1063 IN PTEXTMODE_SCREEN_BUFFER Buffer,
1064 OUT PCOORD ScreenBufferSize,
1065 OUT PCOORD CursorPosition,
1066 OUT PCOORD ViewOrigin,
1067 OUT PCOORD ViewSize,
1068 OUT PCOORD MaximumViewSize,
1069 OUT PWORD Attributes)
1070 {
1071 if (Console == NULL || Buffer == NULL || ScreenBufferSize == NULL ||
1072 CursorPosition == NULL || ViewOrigin == NULL || ViewSize == NULL ||
1073 MaximumViewSize == NULL || Attributes == NULL)
1074 {
1075 return STATUS_INVALID_PARAMETER;
1076 }
1077
1078 /* Validity check */
1079 ASSERT(Console == Buffer->Header.Console);
1080
1081 *ScreenBufferSize = Buffer->ScreenBufferSize;
1082 *CursorPosition = Buffer->CursorPosition;
1083 *ViewOrigin = Buffer->ViewOrigin;
1084 *ViewSize = Buffer->ViewSize;
1085 *Attributes = Buffer->ScreenDefaultAttrib;
1086
1087 // FIXME: Refine the computation
1088 *MaximumViewSize = Buffer->ScreenBufferSize;
1089
1090 return STATUS_SUCCESS;
1091 }
1092
1093 NTSTATUS NTAPI
1094 ConDrvSetConsoleTextAttribute(IN PCONSOLE Console,
1095 IN PTEXTMODE_SCREEN_BUFFER Buffer,
1096 IN WORD Attributes)
1097 {
1098 if (Console == NULL || Buffer == NULL)
1099 return STATUS_INVALID_PARAMETER;
1100
1101 /* Validity check */
1102 ASSERT(Console == Buffer->Header.Console);
1103
1104 Buffer->ScreenDefaultAttrib = Attributes;
1105 return STATUS_SUCCESS;
1106 }
1107
1108 NTSTATUS NTAPI
1109 ConDrvSetConsoleScreenBufferSize(IN PCONSOLE Console,
1110 IN PTEXTMODE_SCREEN_BUFFER Buffer,
1111 IN PCOORD Size)
1112 {
1113 NTSTATUS Status;
1114
1115 if (Console == NULL || Buffer == NULL || Size == NULL)
1116 return STATUS_INVALID_PARAMETER;
1117
1118 /* Validity check */
1119 ASSERT(Console == Buffer->Header.Console);
1120
1121 Status = ConioResizeBuffer(Console, Buffer, *Size);
1122 if (NT_SUCCESS(Status)) TermResizeTerminal(Console);
1123
1124 return Status;
1125 }
1126
1127 NTSTATUS NTAPI
1128 ConDrvScrollConsoleScreenBuffer(IN PCONSOLE Console,
1129 IN PTEXTMODE_SCREEN_BUFFER Buffer,
1130 IN BOOLEAN Unicode,
1131 IN PSMALL_RECT ScrollRectangle,
1132 IN BOOLEAN UseClipRectangle,
1133 IN PSMALL_RECT ClipRectangle OPTIONAL,
1134 IN PCOORD DestinationOrigin,
1135 IN CHAR_INFO FillChar)
1136 {
1137 COORD CapturedDestinationOrigin;
1138 SMALL_RECT ScreenBuffer;
1139 SMALL_RECT SrcRegion;
1140 SMALL_RECT DstRegion;
1141 SMALL_RECT UpdateRegion;
1142 SMALL_RECT CapturedClipRectangle;
1143
1144 if (Console == NULL || Buffer == NULL || ScrollRectangle == NULL ||
1145 (UseClipRectangle ? ClipRectangle == NULL : FALSE) || DestinationOrigin == NULL)
1146 {
1147 return STATUS_INVALID_PARAMETER;
1148 }
1149
1150 /* Validity check */
1151 ASSERT(Console == Buffer->Header.Console);
1152
1153 CapturedDestinationOrigin = *DestinationOrigin;
1154
1155 /* Make sure the source rectangle is inside the screen buffer */
1156 ConioInitRect(&ScreenBuffer, 0, 0,
1157 Buffer->ScreenBufferSize.Y - 1, Buffer->ScreenBufferSize.X - 1);
1158 if (!ConioGetIntersection(&SrcRegion, &ScreenBuffer, ScrollRectangle))
1159 {
1160 return STATUS_SUCCESS;
1161 }
1162
1163 /* If the source was clipped on the left or top, adjust the destination accordingly */
1164 if (ScrollRectangle->Left < 0)
1165 {
1166 CapturedDestinationOrigin.X -= ScrollRectangle->Left;
1167 }
1168 if (ScrollRectangle->Top < 0)
1169 {
1170 CapturedDestinationOrigin.Y -= ScrollRectangle->Top;
1171 }
1172
1173 if (UseClipRectangle)
1174 {
1175 CapturedClipRectangle = *ClipRectangle;
1176 if (!ConioGetIntersection(&CapturedClipRectangle, &CapturedClipRectangle, &ScreenBuffer))
1177 {
1178 return STATUS_SUCCESS;
1179 }
1180 }
1181 else
1182 {
1183 CapturedClipRectangle = ScreenBuffer;
1184 }
1185
1186 ConioInitRect(&DstRegion,
1187 CapturedDestinationOrigin.Y,
1188 CapturedDestinationOrigin.X,
1189 CapturedDestinationOrigin.Y + ConioRectHeight(&SrcRegion) - 1,
1190 CapturedDestinationOrigin.X + ConioRectWidth(&SrcRegion ) - 1);
1191
1192 if (!Unicode)
1193 {
1194 WCHAR tmp;
1195 ConsoleOutputAnsiToUnicodeChar(Console, &tmp, &FillChar.Char.AsciiChar);
1196 FillChar.Char.UnicodeChar = tmp;
1197 }
1198
1199 ConioMoveRegion(Buffer, &SrcRegion, &DstRegion, &CapturedClipRectangle, FillChar);
1200
1201 if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
1202 {
1203 ConioGetUnion(&UpdateRegion, &SrcRegion, &DstRegion);
1204 if (ConioGetIntersection(&UpdateRegion, &UpdateRegion, &CapturedClipRectangle))
1205 {
1206 /* Draw update region */
1207 TermDrawRegion(Console, &UpdateRegion);
1208 }
1209 }
1210
1211 return STATUS_SUCCESS;
1212 }
1213
1214 NTSTATUS NTAPI
1215 ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
1216 IN PTEXTMODE_SCREEN_BUFFER Buffer,
1217 IN BOOLEAN Absolute,
1218 IN PSMALL_RECT WindowRect)
1219 {
1220 SMALL_RECT CapturedWindowRect;
1221
1222 if (Console == NULL || Buffer == NULL || WindowRect == NULL)
1223 return STATUS_INVALID_PARAMETER;
1224
1225 /* Validity check */
1226 ASSERT(Console == Buffer->Header.Console);
1227
1228 CapturedWindowRect = *WindowRect;
1229
1230 if (Absolute == FALSE)
1231 {
1232 /* Relative positions given. Transform them to absolute ones */
1233 CapturedWindowRect.Left += Buffer->ViewOrigin.X;
1234 CapturedWindowRect.Top += Buffer->ViewOrigin.Y;
1235 CapturedWindowRect.Right += Buffer->ViewOrigin.X + Buffer->ViewSize.X - 1;
1236 CapturedWindowRect.Bottom += Buffer->ViewOrigin.Y + Buffer->ViewSize.Y - 1;
1237 }
1238
1239 /* See MSDN documentation on SetConsoleWindowInfo about the performed checks */
1240 if ( (CapturedWindowRect.Left < 0) || (CapturedWindowRect.Top < 0) ||
1241 (CapturedWindowRect.Right >= Buffer->ScreenBufferSize.X) ||
1242 (CapturedWindowRect.Bottom >= Buffer->ScreenBufferSize.Y) ||
1243 (CapturedWindowRect.Right <= CapturedWindowRect.Left) ||
1244 (CapturedWindowRect.Bottom <= CapturedWindowRect.Top) )
1245 {
1246 return STATUS_INVALID_PARAMETER;
1247 }
1248
1249 Buffer->ViewOrigin.X = CapturedWindowRect.Left;
1250 Buffer->ViewOrigin.Y = CapturedWindowRect.Top;
1251
1252 Buffer->ViewSize.X = CapturedWindowRect.Right - CapturedWindowRect.Left + 1;
1253 Buffer->ViewSize.Y = CapturedWindowRect.Bottom - CapturedWindowRect.Top + 1;
1254
1255 // TermResizeTerminal(Console);
1256
1257 return STATUS_SUCCESS;
1258 }
1259
1260 /* EOF */