ReactOS 0.4.16-dev-297-gc569aee
text.c File Reference
#include <consrv.h>
#include <debug.h>
Include dependency graph for text.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define ConsoleOutputUnicodeToAnsiChar(Console, dChar, sWChar)
 
#define ConsoleOutputAnsiToUnicodeChar(Console, dWChar, sChar)
 

Functions

VOID ClearLineBuffer (PTEXTMODE_SCREEN_BUFFER Buff)
 
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN CONSOLE_IO_OBJECT_TYPE Type, IN SIZE_T Size)
 
VOID CONSOLE_SCREEN_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
NTSTATUS TEXTMODE_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PTEXTMODE_BUFFER_INFO TextModeInfo)
 
VOID TEXTMODE_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
PCHAR_INFO ConioCoordToPointer (PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
 
static VOID ConioComputeUpdateRect (IN PTEXTMODE_SCREEN_BUFFER Buff, IN OUT PSMALL_RECT UpdateRect, IN PCOORD Start, IN UINT Length)
 
static VOID ConioCopyRegion (IN PTEXTMODE_SCREEN_BUFFER ScreenBuffer, IN PSMALL_RECT SrcRegion, IN PCOORD DstOrigin)
 
static VOID ConioFillRegion (IN PTEXTMODE_SCREEN_BUFFER ScreenBuffer, IN PSMALL_RECT Region, IN PSMALL_RECT ExcludeRegion OPTIONAL, IN CHAR_INFO FillChar)
 
NTSTATUS NTAPI ConDrvWriteConsoleInput (IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, IN BOOLEAN AppendToEnd, IN PINPUT_RECORD InputRecord, IN ULONG NumEventsToWrite, OUT PULONG NumEventsWritten OPTIONAL)
 
NTSTATUS ConioResizeBuffer (PCONSOLE Console, PTEXTMODE_SCREEN_BUFFER ScreenBuffer, COORD Size)
 
NTSTATUS NTAPI ConDrvChangeScreenBufferAttributes (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN USHORT NewScreenAttrib, IN USHORT NewPopupAttrib)
 
NTSTATUS NTAPI ConDrvReadConsoleOutput (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN BOOLEAN Unicode, OUT PCHAR_INFO CharInfo, IN OUT PSMALL_RECT ReadRegion)
 
NTSTATUS NTAPI ConDrvWriteConsoleOutput (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN BOOLEAN Unicode, IN PCHAR_INFO CharInfo, IN OUT PSMALL_RECT WriteRegion)
 
NTSTATUS NTAPI ConDrvWriteConsoleOutputVDM (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCHAR_CELL CharInfo, IN COORD CharInfoSize, IN PSMALL_RECT WriteRegion)
 
NTSTATUS NTAPI ConDrvWriteConsole (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER ScreenBuffer, IN BOOLEAN Unicode, IN PVOID StringBuffer, IN ULONG NumCharsToWrite, OUT PULONG NumCharsWritten OPTIONAL)
 
static NTSTATUS IntReadConsoleOutputStringChars (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PVOID StringBuffer, IN BOOLEAN Unicode, IN ULONG NumCodesToRead, IN PCOORD ReadCoord, OUT PULONG NumCodesRead OPTIONAL)
 
static NTSTATUS IntReadConsoleOutputStringAttributes (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PWORD StringBuffer, IN ULONG NumCodesToRead, IN PCOORD ReadCoord, OUT PULONG NumCodesRead OPTIONAL)
 
NTSTATUS NTAPI ConDrvReadConsoleOutputString (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN CODE_TYPE CodeType, OUT PVOID StringBuffer, IN ULONG NumCodesToRead, IN PCOORD ReadCoord, OUT PULONG NumCodesRead OPTIONAL)
 
static NTSTATUS IntWriteConsoleOutputStringChars (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PVOID StringBuffer, IN BOOLEAN Unicode, IN ULONG NumCodesToWrite, IN PCOORD WriteCoord, OUT PULONG NumCodesWritten OPTIONAL)
 
static NTSTATUS IntWriteConsoleOutputStringAttribute (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PWORD StringBuffer, IN ULONG NumCodesToWrite, IN PCOORD WriteCoord, OUT PULONG NumCodesWritten OPTIONAL)
 
NTSTATUS NTAPI ConDrvWriteConsoleOutputString (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN CODE_TYPE CodeType, IN PVOID StringBuffer, IN ULONG NumCodesToWrite, IN PCOORD WriteCoord, OUT PULONG NumCodesWritten OPTIONAL)
 
NTSTATUS NTAPI ConDrvFillConsoleOutput (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN CODE_TYPE CodeType, IN CODE_ELEMENT Code, IN ULONG NumCodesToWrite, IN PCOORD WriteCoord, OUT PULONG NumCodesWritten OPTIONAL)
 
NTSTATUS NTAPI ConDrvGetConsoleScreenBufferInfo (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PCOORD ScreenBufferSize, OUT PCOORD CursorPosition, OUT PCOORD ViewOrigin, OUT PCOORD ViewSize, OUT PCOORD MaximumViewSize, OUT PWORD Attributes)
 
NTSTATUS NTAPI ConDrvSetConsoleTextAttribute (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN WORD Attributes)
 
NTSTATUS NTAPI ConDrvSetConsoleScreenBufferSize (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCOORD Size)
 
NTSTATUS NTAPI ConDrvScrollConsoleScreenBuffer (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN BOOLEAN Unicode, IN PSMALL_RECT ScrollRectangle, IN BOOLEAN UseClipRectangle, IN PSMALL_RECT ClipRectangle OPTIONAL, IN PCOORD DestinationOrigin, IN CHAR_INFO FillChar)
 
NTSTATUS NTAPI ConDrvSetConsoleWindowInfo (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN BOOLEAN Absolute, IN PSMALL_RECT WindowRect)
 

Macro Definition Documentation

◆ ConsoleOutputAnsiToUnicodeChar

#define ConsoleOutputAnsiToUnicodeChar (   Console,
  dWChar,
  sChar 
)
Value:
do { \
ASSERT((ULONG_PTR)(dWChar) != (ULONG_PTR)(sChar)); \
MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1); \
} while (0)
CConsole Console
UINT OutputCodePage
Definition: console.c:26
uint32_t ULONG_PTR
Definition: typedefs.h:65

Definition at line 31 of file text.c.

◆ ConsoleOutputUnicodeToAnsiChar

#define ConsoleOutputUnicodeToAnsiChar (   Console,
  dChar,
  sWChar 
)
Value:
do { \
ASSERT((ULONG_PTR)(dChar) != (ULONG_PTR)(sWChar)); \
WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL); \
} while (0)
#define NULL
Definition: types.h:112

Definition at line 25 of file text.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file text.c.

Function Documentation

◆ ClearLineBuffer()

VOID ClearLineBuffer ( PTEXTMODE_SCREEN_BUFFER  Buff)

Definition at line 151 of file text.c.

152{
153 PCHAR_INFO Ptr = ConioCoordToPointer(Buff, 0, Buff->CursorPosition.Y);
154 SHORT Pos;
155
156 for (Pos = 0; Pos < Buff->ScreenBufferSize.X; Pos++, Ptr++)
157 {
158 /* Fill the cell */
159 Ptr->Char.UnicodeChar = L' ';
160 Ptr->Attributes = Buff->ScreenDefaultAttrib;
161 }
162}
ush Pos
Definition: deflate.h:92
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define L(x)
Definition: ntvdm.h:50
short SHORT
Definition: pedump.c:59
USHORT ScreenDefaultAttrib
Definition: conio.h:131
PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
Definition: text.c:143

Referenced by ConioNextLine(), and TEXTMODE_BUFFER_Initialize().

◆ ConDrvChangeScreenBufferAttributes()

NTSTATUS NTAPI ConDrvChangeScreenBufferAttributes ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN USHORT  NewScreenAttrib,
IN USHORT  NewPopupAttrib 
)

Definition at line 497 of file text.c.

501{
502 USHORT X, Y;
504
505 COORD TopLeft = {0};
506 ULONG NumCodesToWrite;
507 USHORT OldScreenAttrib, OldPopupAttrib;
508
509 if (Console == NULL || Buffer == NULL)
510 {
512 }
513
514 /* Validity check */
515 ASSERT(Console == Buffer->Header.Console);
516
517 /* Sanitize the new attributes */
518 NewScreenAttrib &= ~COMMON_LVB_SBCSDBCS;
519 NewPopupAttrib &= ~COMMON_LVB_SBCSDBCS;
520
521 NumCodesToWrite = Buffer->ScreenBufferSize.X * Buffer->ScreenBufferSize.Y;
522 OldScreenAttrib = Buffer->ScreenDefaultAttrib;
523 OldPopupAttrib = Buffer->PopupDefaultAttrib;
524
525 for (Y = 0; Y < Buffer->ScreenBufferSize.Y; ++Y)
526 {
528 for (X = 0; X < Buffer->ScreenBufferSize.X; ++X)
529 {
530 /*
531 * Change the current colors only if they are the old ones.
532 */
533
534 /* Foreground color */
535 if ((Ptr->Attributes & 0x0F) == (OldScreenAttrib & 0x0F))
536 Ptr->Attributes = (Ptr->Attributes & 0xFFF0) | (NewScreenAttrib & 0x0F);
537 if ((Ptr->Attributes & 0x0F) == (OldPopupAttrib & 0x0F))
538 Ptr->Attributes = (Ptr->Attributes & 0xFFF0) | (NewPopupAttrib & 0x0F);
539
540 /* Background color */
541 if ((Ptr->Attributes & 0xF0) == (OldScreenAttrib & 0xF0))
542 Ptr->Attributes = (Ptr->Attributes & 0xFF0F) | (NewScreenAttrib & 0xF0);
543 if ((Ptr->Attributes & 0xF0) == (OldPopupAttrib & 0xF0))
544 Ptr->Attributes = (Ptr->Attributes & 0xFF0F) | (NewPopupAttrib & 0xF0);
545
546 ++Ptr;
547 }
548 }
549
550 /* Save foreground and background attributes for both screen and popup */
551 Buffer->ScreenDefaultAttrib = NewScreenAttrib;
552 Buffer->PopupDefaultAttrib = NewPopupAttrib;
553
554 /* Refresh the display if needed */
555 if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
556 {
558 ConioComputeUpdateRect(Buffer, &UpdateRect, &TopLeft, NumCodesToWrite);
560 }
561
562 return STATUS_SUCCESS;
563}
Definition: bufpool.h:45
#define Y(I)
#define X(b, s)
#define ASSERT(a)
Definition: mode.c:44
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: bl.h:1338
#define TermDrawRegion(Console, Region)
Definition: term.h:22
static int UpdateRect(TreeListData *pData, unsigned uItem, unsigned uSub)
Definition: treelist.c:1529
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static VOID ConioComputeUpdateRect(IN PTEXTMODE_SCREEN_BUFFER Buff, IN OUT PSMALL_RECT UpdateRect, IN PCOORD Start, IN UINT Length)
Definition: text.c:165

Referenced by ConSrvApplyUserSettings().

◆ ConDrvFillConsoleOutput()

NTSTATUS NTAPI ConDrvFillConsoleOutput ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN CODE_TYPE  CodeType,
IN CODE_ELEMENT  Code,
IN ULONG  NumCodesToWrite,
IN PCOORD  WriteCoord,
OUT PULONG NumCodesWritten  OPTIONAL 
)

Definition at line 1251 of file text.c.

1258{
1259 SHORT X, Y;
1260 SHORT XStart;
1261 ULONG nNumChars = 0;
1263 BOOLEAN bLead, bFullwidth;
1264
1265 if (Console == NULL || Buffer == NULL || WriteCoord == NULL)
1266 {
1268 }
1269
1270 /* Validity check */
1271 ASSERT(Console == Buffer->Header.Console);
1272
1273 if (NumCodesWritten)
1274 *NumCodesWritten = 0;
1275
1276 if (NumCodesToWrite == 0)
1277 return STATUS_SUCCESS; // Nothing to do!
1278
1279 /* Do nothing if the writing starting point is outside of the screen buffer */
1280 if ( WriteCoord->X < 0 || WriteCoord->X >= Buffer->ScreenBufferSize.X ||
1281 WriteCoord->Y < 0 || WriteCoord->Y >= Buffer->ScreenBufferSize.Y )
1282 {
1283 return STATUS_SUCCESS;
1284 }
1285
1286 NumCodesToWrite = min(NumCodesToWrite, (ULONG)Buffer->ScreenBufferSize.X * Buffer->ScreenBufferSize.Y);
1287
1288 if (CodeType == CODE_ASCII)
1289 {
1290 /* Conversion from the ASCII char to the UNICODE char */
1291 CODE_ELEMENT tmp;
1293 Code = tmp;
1294 }
1295
1296 XStart = WriteCoord->X;
1297
1298 /* For Chinese, Japanese and Korean */
1299 X = XStart;
1300 Y = WriteCoord->Y;
1301 bLead = TRUE;
1302 bFullwidth = FALSE;
1303 if (Console->IsCJK)
1304 {
1305 bFullwidth = IS_FULL_WIDTH(Code.UnicodeChar);
1306 if (X > 0)
1307 {
1308 Ptr = ConioCoordToPointer(Buffer, X - 1, Y);
1309 if (Ptr->Attributes & COMMON_LVB_LEADING_BYTE)
1310 {
1311 Ptr->Char.UnicodeChar = L' ';
1312 Ptr->Attributes &= ~COMMON_LVB_SBCSDBCS;
1313 }
1314 }
1315 }
1316
1317 for (Y = WriteCoord->Y; Y < Buffer->ScreenBufferSize.Y; ++Y)
1318 {
1319 Ptr = ConioCoordToPointer(Buffer, XStart, Y);
1320 for (X = XStart; X < Buffer->ScreenBufferSize.X; ++X)
1321 {
1322 if (nNumChars >= NumCodesToWrite)
1323 goto Quit;
1324
1325 switch (CodeType)
1326 {
1327 case CODE_ASCII:
1328 case CODE_UNICODE:
1329 Ptr->Char.UnicodeChar = Code.UnicodeChar;
1330 Ptr->Attributes &= ~COMMON_LVB_SBCSDBCS;
1331 if (bFullwidth)
1332 {
1333 if (bLead)
1334 Ptr->Attributes |= COMMON_LVB_LEADING_BYTE;
1335 else
1336 Ptr->Attributes |= COMMON_LVB_TRAILING_BYTE;
1337 }
1338 bLead = !bLead;
1339 break;
1340
1341 case CODE_ATTRIBUTE:
1342 Ptr->Attributes &= COMMON_LVB_SBCSDBCS;
1343 Ptr->Attributes |= (Code.Attribute & ~COMMON_LVB_SBCSDBCS);
1344 break;
1345 }
1346
1347 ++Ptr;
1348
1349 ++nNumChars;
1350 }
1351 /* Restart at the beginning of the next line */
1352 XStart = 0;
1353 }
1354Quit:
1355
1356 if ((nNumChars & 1) & bFullwidth)
1357 {
1358 if (X + Y * Buffer->ScreenBufferSize.X > 0)
1359 {
1360 Ptr = ConioCoordToPointer(Buffer, X - 1, Y);
1361 Ptr->Char.UnicodeChar = L' ';
1362 Ptr->Attributes &= ~COMMON_LVB_SBCSDBCS;
1363 }
1364 }
1365
1366 if (NumCodesWritten)
1367 *NumCodesWritten = nNumChars;
1368
1369 if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
1370 {
1372 ConioComputeUpdateRect(Buffer, &UpdateRect, WriteCoord, nNumChars);
1374 }
1375
1376 return STATUS_SUCCESS;
1377}
unsigned char BOOLEAN
#define IS_FULL_WIDTH(wch)
Definition: console.c:333
@ CODE_ASCII
Definition: conmsg.h:517
@ CODE_UNICODE
Definition: conmsg.h:518
@ CODE_ATTRIBUTE
Definition: conmsg.h:519
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define min(a, b)
Definition: monoChain.cc:55
WCHAR UnicodeChar
Definition: conmsg.h:525
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1701
#define ConsoleOutputAnsiToUnicodeChar(Console, dWChar, sChar)
Definition: text.c:31
#define COMMON_LVB_TRAILING_BYTE
Definition: wincon.h:49
#define COMMON_LVB_LEADING_BYTE
Definition: wincon.h:48
#define COMMON_LVB_SBCSDBCS
Definition: wincon.h:56

Referenced by CON_API(), and DrawBox().

◆ ConDrvGetConsoleScreenBufferInfo()

NTSTATUS NTAPI ConDrvGetConsoleScreenBufferInfo ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
OUT PCOORD  ScreenBufferSize,
OUT PCOORD  CursorPosition,
OUT PCOORD  ViewOrigin,
OUT PCOORD  ViewSize,
OUT PCOORD  MaximumViewSize,
OUT PWORD  Attributes 
)

Definition at line 1380 of file text.c.

1388{
1389 COORD LargestWindowSize;
1390
1391 if (Console == NULL || Buffer == NULL || ScreenBufferSize == NULL ||
1392 CursorPosition == NULL || ViewOrigin == NULL || ViewSize == NULL ||
1393 MaximumViewSize == NULL || Attributes == NULL)
1394 {
1396 }
1397
1398 /* Validity check */
1399 ASSERT(Console == Buffer->Header.Console);
1400
1401 *ScreenBufferSize = Buffer->ScreenBufferSize;
1402 *CursorPosition = Buffer->CursorPosition;
1403 *ViewOrigin = Buffer->ViewOrigin;
1404 *ViewSize = Buffer->ViewSize;
1405 *Attributes = Buffer->ScreenDefaultAttrib;
1406
1407 /*
1408 * Retrieve the largest possible console window size, taking
1409 * into account the size of the console screen buffer.
1410 */
1411 TermGetLargestConsoleWindowSize(Console, &LargestWindowSize);
1412 LargestWindowSize.X = min(LargestWindowSize.X, Buffer->ScreenBufferSize.X);
1413 LargestWindowSize.Y = min(LargestWindowSize.Y, Buffer->ScreenBufferSize.Y);
1414 *MaximumViewSize = LargestWindowSize;
1415
1416 return STATUS_SUCCESS;
1417}
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:408
static USHORT CursorPosition
Definition: pc98cons.c:20
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
#define TermGetLargestConsoleWindowSize(Console, pSize)
Definition: term.h:34
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes

Referenced by CON_API().

◆ ConDrvReadConsoleOutput()

NTSTATUS NTAPI ConDrvReadConsoleOutput ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN BOOLEAN  Unicode,
OUT PCHAR_INFO  CharInfo,
IN OUT PSMALL_RECT  ReadRegion 
)

Definition at line 569 of file text.c.

574{
575 SHORT X, Y;
577 PCHAR_INFO CurCharInfo;
578 SMALL_RECT CapturedReadRegion;
580
581 if (Console == NULL || Buffer == NULL || CharInfo == NULL || ReadRegion == NULL)
582 {
584 }
585
586 /* Validity check */
587 ASSERT(Console == Buffer->Header.Console);
588
589 CapturedReadRegion = *ReadRegion;
590
591 /* Make sure ReadRegion is inside the screen buffer */
593 Buffer->ScreenBufferSize.Y - 1,
594 Buffer->ScreenBufferSize.X - 1);
595 if (!ConioGetIntersection(&CapturedReadRegion, &CapturedReadRegion, &ScreenBuffer))
596 {
597 /*
598 * It is okay to have a ReadRegion completely outside
599 * the screen buffer. No data is read then.
600 */
601 return STATUS_SUCCESS;
602 }
603
604 CurCharInfo = CharInfo;
605
606 for (Y = CapturedReadRegion.Top; Y <= CapturedReadRegion.Bottom; ++Y)
607 {
608 Ptr = ConioCoordToPointer(Buffer, CapturedReadRegion.Left, Y);
609 for (X = CapturedReadRegion.Left; X <= CapturedReadRegion.Right; ++X)
610 {
611 if (Unicode)
612 {
613 CurCharInfo->Char.UnicodeChar = Ptr->Char.UnicodeChar;
614 }
615 else
616 {
617 // ConsoleOutputUnicodeToAnsiChar(Console, &CurCharInfo->Char.AsciiChar, &Ptr->Char.UnicodeChar);
618 WideCharToMultiByte(Console->OutputCodePage, 0, &Ptr->Char.UnicodeChar, 1,
619 &CurCharInfo->Char.AsciiChar, 1, NULL, NULL);
620 }
621#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
622 /* NOTE: Windows < 8 compatibility: DBCS flags are filtered out */
623 CurCharInfo->Attributes = (Ptr->Attributes & ~COMMON_LVB_SBCSDBCS);
624#else
625 CurCharInfo->Attributes = Ptr->Attributes;
626#endif
627 ++Ptr;
628 ++CurCharInfo;
629 }
630 }
631
632 *ReadRegion = CapturedReadRegion;
633
634 return STATUS_SUCCESS;
635}
#define WideCharToMultiByte
Definition: compat.h:111
HANDLE ScreenBuffer
Definition: notevil.c:37
union _CHAR_INFO::@3283 Char
CHAR AsciiChar
Definition: wincon.h:185
WCHAR UnicodeChar
Definition: wincon.h:184
WORD Attributes
Definition: wincon.h:187
SHORT Top
Definition: tui.c:25
SHORT Right
Definition: tui.c:26
SHORT Left
Definition: tui.c:24
SHORT Bottom
Definition: tui.c:27
static __inline BOOLEAN ConioGetIntersection(OUT PSMALL_RECT Intersection, IN PSMALL_RECT Rect1, IN PSMALL_RECT Rect2)
Definition: rect.h:38
#define ConioInitRect(Rect, top, left, bottom, right)
Definition: rect.h:20

Referenced by CON_API(), and CreatePopupWindow().

◆ ConDrvReadConsoleOutputString()

NTSTATUS NTAPI ConDrvReadConsoleOutputString ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN CODE_TYPE  CodeType,
OUT PVOID  StringBuffer,
IN ULONG  NumCodesToRead,
IN PCOORD  ReadCoord,
OUT PULONG NumCodesRead  OPTIONAL 
)

Definition at line 942 of file text.c.

950{
951 if (Console == NULL || Buffer == NULL || ReadCoord == NULL /* || EndCoord == NULL */)
952 {
954 }
955
956 /* Validity checks */
957 ASSERT(Console == Buffer->Header.Console);
958 ASSERT((StringBuffer != NULL) || (StringBuffer == NULL && NumCodesToRead == 0));
959
960 if (NumCodesRead)
961 *NumCodesRead = 0;
962
963 if (!StringBuffer || (NumCodesToRead == 0))
964 return STATUS_SUCCESS; // Nothing to do!
965
966 /* Do nothing if the reading starting point is outside of the screen buffer */
967 if ( ReadCoord->X < 0 || ReadCoord->X >= Buffer->ScreenBufferSize.X ||
968 ReadCoord->Y < 0 || ReadCoord->Y >= Buffer->ScreenBufferSize.Y )
969 {
970 return STATUS_SUCCESS;
971 }
972
973 NumCodesToRead = min(NumCodesToRead, (ULONG)Buffer->ScreenBufferSize.X * Buffer->ScreenBufferSize.Y);
974
975 switch (CodeType)
976 {
977 case CODE_ASCII:
978 {
980 Buffer,
982 FALSE,
983 NumCodesToRead,
984 ReadCoord,
985 NumCodesRead);
986 }
987
988 case CODE_UNICODE:
989 {
991 Buffer,
993 TRUE,
994 NumCodesToRead,
995 ReadCoord,
996 NumCodesRead);
997 }
998
999 case CODE_ATTRIBUTE:
1000 {
1001 C_ASSERT(RTL_FIELD_SIZE(CODE_ELEMENT, Attribute) == sizeof(WORD));
1003 Buffer,
1005 NumCodesToRead,
1006 ReadCoord,
1007 NumCodesRead);
1008 }
1009
1010 default:
1012 }
1013}
unsigned short WORD
Definition: ntddk_ex.h:93
#define C_ASSERT(e)
Definition: intsafe.h:73
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:86
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
WORD * PWORD
Definition: pedump.c:67
static NTSTATUS IntReadConsoleOutputStringAttributes(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PWORD StringBuffer, IN ULONG NumCodesToRead, IN PCOORD ReadCoord, OUT PULONG NumCodesRead OPTIONAL)
Definition: text.c:903
static NTSTATUS IntReadConsoleOutputStringChars(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PVOID StringBuffer, IN BOOLEAN Unicode, IN ULONG NumCodesToRead, IN PCOORD ReadCoord, OUT PULONG NumCodesRead OPTIONAL)
Definition: text.c:835

Referenced by CON_API().

◆ ConDrvScrollConsoleScreenBuffer()

NTSTATUS NTAPI ConDrvScrollConsoleScreenBuffer ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN BOOLEAN  Unicode,
IN PSMALL_RECT  ScrollRectangle,
IN BOOLEAN  UseClipRectangle,
IN PSMALL_RECT ClipRectangle  OPTIONAL,
IN PCOORD  DestinationOrigin,
IN CHAR_INFO  FillChar 
)

Definition at line 1454 of file text.c.

1463{
1464 COORD CapturedDestinationOrigin;
1466 SMALL_RECT CapturedClipRectangle;
1467 SMALL_RECT SrcRegion;
1468 SMALL_RECT DstRegion;
1469 SMALL_RECT UpdateRegion;
1470
1471 if (Console == NULL || Buffer == NULL || ScrollRectangle == NULL ||
1472 (UseClipRectangle && (ClipRectangle == NULL)) || DestinationOrigin == NULL)
1473 {
1475 }
1476
1477 /* Validity check */
1478 ASSERT(Console == Buffer->Header.Console);
1479
1480 CapturedDestinationOrigin = *DestinationOrigin;
1481
1482 /* Make sure the source rectangle is inside the screen buffer */
1484 Buffer->ScreenBufferSize.Y - 1,
1485 Buffer->ScreenBufferSize.X - 1);
1486 if (!ConioGetIntersection(&SrcRegion, ScrollRectangle, &ScreenBuffer))
1487 {
1488 return STATUS_SUCCESS;
1489 }
1490
1491 /* If the source was clipped on the left or top, adjust the destination accordingly */
1492 if (ScrollRectangle->Left < 0)
1493 CapturedDestinationOrigin.X -= ScrollRectangle->Left;
1494 if (ScrollRectangle->Top < 0)
1495 CapturedDestinationOrigin.Y -= ScrollRectangle->Top;
1496
1497 /*
1498 * If a clip rectangle is provided, clip it to the screen buffer,
1499 * otherwise use the latter one as the clip rectangle.
1500 */
1501 if (UseClipRectangle)
1502 {
1503 CapturedClipRectangle = *ClipRectangle;
1504 if (!ConioGetIntersection(&CapturedClipRectangle, &CapturedClipRectangle, &ScreenBuffer))
1505 {
1506 return STATUS_SUCCESS;
1507 }
1508 }
1509 else
1510 {
1511 CapturedClipRectangle = ScreenBuffer;
1512 }
1513
1514 /*
1515 * Windows compatibility: Do nothing if the intersection of the source region
1516 * with the clip rectangle is empty, even if the intersection of destination
1517 * region with the clip rectangle is NOT empty and therefore it would have
1518 * been possible to copy contents to it...
1519 */
1520 if (!ConioGetIntersection(&UpdateRegion, &SrcRegion, &CapturedClipRectangle))
1521 {
1522 return STATUS_SUCCESS;
1523 }
1524
1525 /* Initialize the destination rectangle, of same size as the source rectangle */
1526 ConioInitRect(&DstRegion,
1527 CapturedDestinationOrigin.Y,
1528 CapturedDestinationOrigin.X,
1529 CapturedDestinationOrigin.Y + ConioRectHeight(&SrcRegion) - 1,
1530 CapturedDestinationOrigin.X + ConioRectWidth(&SrcRegion ) - 1);
1531
1532 if (ConioGetIntersection(&DstRegion, &DstRegion, &CapturedClipRectangle))
1533 {
1534 /*
1535 * Build the region image, within the source region,
1536 * of the destination region we should copy into.
1537 */
1538 SrcRegion.Left += DstRegion.Left - CapturedDestinationOrigin.X;
1539 SrcRegion.Top += DstRegion.Top - CapturedDestinationOrigin.Y;
1540 SrcRegion.Right = SrcRegion.Left + (DstRegion.Right - DstRegion.Left);
1541 SrcRegion.Bottom = SrcRegion.Top + (DstRegion.Bottom - DstRegion.Top);
1542
1543 /* Do the copy */
1544 CapturedDestinationOrigin.X = DstRegion.Left;
1545 CapturedDestinationOrigin.Y = DstRegion.Top;
1546 ConioCopyRegion(Buffer, &SrcRegion, &CapturedDestinationOrigin);
1547 }
1548
1549 if (!Unicode)
1550 {
1551 /* Conversion from the ASCII char to the UNICODE char */
1552 WCHAR tmp;
1553 ConsoleOutputAnsiToUnicodeChar(Console, &tmp, &FillChar.Char.AsciiChar);
1554 FillChar.Char.UnicodeChar = tmp;
1555 }
1556 /* Sanitize the attribute */
1557 FillChar.Attributes &= ~COMMON_LVB_SBCSDBCS;
1558
1559 /*
1560 * Fill the intersection (== UpdateRegion) of the source region with the
1561 * clip rectangle, excluding the destination region.
1562 */
1563 ConioFillRegion(Buffer, &UpdateRegion, &DstRegion, FillChar);
1564
1565 if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
1566 {
1567 ConioGetUnion(&UpdateRegion, &UpdateRegion, &DstRegion);
1568 if (ConioGetIntersection(&UpdateRegion, &UpdateRegion, &CapturedClipRectangle))
1569 {
1570 /* Draw update region */
1571 TermDrawRegion(Console, &UpdateRegion);
1572 }
1573 }
1574
1575 return STATUS_SUCCESS;
1576}
#define ConioRectWidth(Rect)
Definition: readwrite.c:24
#define ConioRectHeight(Rect)
Definition: readwrite.c:22
static VOID ConioFillRegion(IN PTEXTMODE_SCREEN_BUFFER ScreenBuffer, IN PSMALL_RECT Region, IN PSMALL_RECT ExcludeRegion OPTIONAL, IN CHAR_INFO FillChar)
Definition: text.c:290
static VOID ConioCopyRegion(IN PTEXTMODE_SCREEN_BUFFER ScreenBuffer, IN PSMALL_RECT SrcRegion, IN PCOORD DstOrigin)
Definition: text.c:193
static __inline BOOLEAN ConioGetUnion(OUT PSMALL_RECT Union, IN PSMALL_RECT Rect1, IN PSMALL_RECT Rect2)
Definition: rect.h:64
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CON_API().

◆ ConDrvSetConsoleScreenBufferSize()

NTSTATUS NTAPI ConDrvSetConsoleScreenBufferSize ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN PCOORD  Size 
)

Definition at line 1435 of file text.c.

1438{
1440
1441 if (Console == NULL || Buffer == NULL || Size == NULL)
1443
1444 /* Validity check */
1445 ASSERT(Console == Buffer->Header.Console);
1446
1449
1450 return Status;
1451}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
#define TermResizeTerminal(Console)
Definition: term.h:28
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
NTSTATUS ConioResizeBuffer(PCONSOLE Console, PTEXTMODE_SCREEN_BUFFER ScreenBuffer, COORD Size)
Definition: text.c:359

Referenced by CON_API().

◆ ConDrvSetConsoleTextAttribute()

NTSTATUS NTAPI ConDrvSetConsoleTextAttribute ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN WORD  Attributes 
)

Definition at line 1420 of file text.c.

1423{
1424 if (Console == NULL || Buffer == NULL)
1426
1427 /* Validity check */
1428 ASSERT(Console == Buffer->Header.Console);
1429
1430 Buffer->ScreenDefaultAttrib = (Attributes & ~COMMON_LVB_SBCSDBCS);
1431 return STATUS_SUCCESS;
1432}

Referenced by CON_API().

◆ ConDrvSetConsoleWindowInfo()

NTSTATUS NTAPI ConDrvSetConsoleWindowInfo ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN BOOLEAN  Absolute,
IN PSMALL_RECT  WindowRect 
)

Definition at line 1579 of file text.c.

1583{
1584 SMALL_RECT CapturedWindowRect;
1585 COORD LargestWindowSize;
1586
1587 if (Console == NULL || Buffer == NULL || WindowRect == NULL)
1589
1590 /* Validity check */
1591 ASSERT(Console == Buffer->Header.Console);
1592
1593 CapturedWindowRect = *WindowRect;
1594
1595 if (!Absolute)
1596 {
1597 /* Relative positions are given, transform them to absolute ones */
1598 CapturedWindowRect.Left += Buffer->ViewOrigin.X;
1599 CapturedWindowRect.Top += Buffer->ViewOrigin.Y;
1600 CapturedWindowRect.Right += Buffer->ViewOrigin.X + Buffer->ViewSize.X - 1;
1601 CapturedWindowRect.Bottom += Buffer->ViewOrigin.Y + Buffer->ViewSize.Y - 1;
1602 }
1603
1604 /*
1605 * The MSDN documentation on SetConsoleWindowInfo() is partially wrong about
1606 * the performed checks this API performs. While it is correct that the
1607 * 'Right'/'Bottom' members cannot be strictly smaller than the 'Left'/'Top'
1608 * members (the rectangle cannot be empty), they can be equal (describe one cell).
1609 * Also, if the 'Left' or 'Top' members are negative, this is automatically
1610 * corrected for, and the window rectangle coordinates are shifted accordingly.
1611 */
1612 if (ConioIsRectEmpty(&CapturedWindowRect))
1613 {
1615 }
1616
1617 /*
1618 * Forbid window sizes larger than the largest allowed console window size,
1619 * taking into account the size of the console screen buffer.
1620 */
1621 TermGetLargestConsoleWindowSize(Console, &LargestWindowSize);
1622 LargestWindowSize.X = min(LargestWindowSize.X, Buffer->ScreenBufferSize.X);
1623 LargestWindowSize.Y = min(LargestWindowSize.Y, Buffer->ScreenBufferSize.Y);
1624 if ((ConioRectWidth(&CapturedWindowRect) > LargestWindowSize.X) ||
1625 (ConioRectHeight(&CapturedWindowRect) > LargestWindowSize.Y))
1626 {
1628 }
1629
1630 /* Shift the window rectangle coordinates if 'Left' or 'Top' are negative */
1631 if (CapturedWindowRect.Left < 0)
1632 {
1633 CapturedWindowRect.Right -= CapturedWindowRect.Left;
1634 CapturedWindowRect.Left = 0;
1635 }
1636 if (CapturedWindowRect.Top < 0)
1637 {
1638 CapturedWindowRect.Bottom -= CapturedWindowRect.Top;
1639 CapturedWindowRect.Top = 0;
1640 }
1641
1642 /* Clip the window rectangle to the screen buffer */
1643 CapturedWindowRect.Right = min(CapturedWindowRect.Right , Buffer->ScreenBufferSize.X);
1644 CapturedWindowRect.Bottom = min(CapturedWindowRect.Bottom, Buffer->ScreenBufferSize.Y);
1645
1646 Buffer->ViewOrigin.X = CapturedWindowRect.Left;
1647 Buffer->ViewOrigin.Y = CapturedWindowRect.Top;
1648
1649 Buffer->ViewSize.X = ConioRectWidth(&CapturedWindowRect);
1650 Buffer->ViewSize.Y = ConioRectHeight(&CapturedWindowRect);
1651
1653
1654 return STATUS_SUCCESS;
1655}
#define ConioIsRectEmpty(Rect)
Definition: rect.h:28

Referenced by CON_API().

◆ ConDrvWriteConsole()

NTSTATUS NTAPI ConDrvWriteConsole ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  ScreenBuffer,
IN BOOLEAN  Unicode,
IN PVOID  StringBuffer,
IN ULONG  NumCharsToWrite,
OUT PULONG NumCharsWritten  OPTIONAL 
)

Definition at line 763 of file text.c.

769{
772 ULONG Written = 0;
774
775 if (Console == NULL || ScreenBuffer == NULL /* || StringBuffer == NULL */)
777
778 /* Validity checks */
779 ASSERT(Console == ScreenBuffer->Header.Console);
780 ASSERT((StringBuffer != NULL) || (StringBuffer == NULL && NumCharsToWrite == 0));
781
782 /* Stop here if the console is paused */
783 if (Console->ConsolePaused) return STATUS_PENDING;
784
785 /* Convert the string to UNICODE */
786 if (Unicode)
787 {
789 }
790 else
791 {
792 Length = MultiByteToWideChar(Console->OutputCodePage, 0,
794 NumCharsToWrite,
795 NULL, 0);
796 Buffer = ConsoleAllocHeap(0, Length * sizeof(WCHAR));
797 if (Buffer)
798 {
799 MultiByteToWideChar(Console->OutputCodePage, 0,
801 NumCharsToWrite,
803 }
804 else
805 {
807 }
808 }
809
810 /* Send it */
811 if (Buffer)
812 {
813 if (NT_SUCCESS(Status))
814 {
817 Buffer,
818 NumCharsToWrite,
819 TRUE);
820 if (NT_SUCCESS(Status))
821 {
822 Written = NumCharsToWrite;
823 }
824 }
825
826 if (!Unicode) ConsoleFreeHeap(Buffer);
827 }
828
829 if (NumCharsWritten) *NumCharsWritten = Written;
830
831 return Status;
832}
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define MultiByteToWideChar
Definition: compat.h:110
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define TermWriteStream(Console, ScreenBuffer, Buffer, Length, Attrib)
Definition: term.h:17
uint16_t * PWCHAR
Definition: typedefs.h:56
char * PCHAR
Definition: typedefs.h:51
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15

Referenced by DoWriteConsole().

◆ ConDrvWriteConsoleInput()

NTSTATUS NTAPI ConDrvWriteConsoleInput ( IN PCONSOLE  Console,
IN PCONSOLE_INPUT_BUFFER  InputBuffer,
IN BOOLEAN  AppendToEnd,
IN PINPUT_RECORD  InputRecord,
IN ULONG  NumEventsToWrite,
OUT PULONG NumEventsWritten  OPTIONAL 
)

Definition at line 330 of file coninput.c.

336{
337 if (Console == NULL || InputBuffer == NULL /* || InputRecord == NULL */)
339
340 /* Validity checks */
341 ASSERT(Console == InputBuffer->Header.Console);
342 ASSERT((InputRecord != NULL) || (InputRecord == NULL && NumEventsToWrite == 0));
343
344 /* Now, add the events */
345 if (NumEventsWritten) *NumEventsWritten = 0;
346
347 // FIXME: If we add back UNICODE support, it's here that we need to do the translation.
348
349 return AddInputEvents(Console,
350 InputRecord,
351 NumEventsToWrite,
352 NumEventsWritten,
353 AppendToEnd);
354}
static NTSTATUS AddInputEvents(PCONSOLE Console, PINPUT_RECORD InputRecords, ULONG NumEventsToWrite, PULONG NumEventsWritten, BOOLEAN AppendToEnd)
Definition: coninput.c:21
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953

Referenced by ConioResizeBuffer().

◆ ConDrvWriteConsoleOutput()

NTSTATUS NTAPI ConDrvWriteConsoleOutput ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN BOOLEAN  Unicode,
IN PCHAR_INFO  CharInfo,
IN OUT PSMALL_RECT  WriteRegion 
)

Definition at line 638 of file text.c.

643{
644 SHORT X, Y;
646 PCHAR_INFO CurCharInfo;
647 SMALL_RECT CapturedWriteRegion;
649
650 if (Console == NULL || Buffer == NULL || CharInfo == NULL || WriteRegion == NULL)
651 {
653 }
654
655 /* Validity check */
656 ASSERT(Console == Buffer->Header.Console);
657
658 CapturedWriteRegion = *WriteRegion;
659
660 /* Make sure WriteRegion is inside the screen buffer */
662 Buffer->ScreenBufferSize.Y - 1,
663 Buffer->ScreenBufferSize.X - 1);
664 if (!ConioGetIntersection(&CapturedWriteRegion, &CapturedWriteRegion, &ScreenBuffer))
665 {
666 /*
667 * It is okay to have a WriteRegion completely outside
668 * the screen buffer. No data is written then.
669 */
670 return STATUS_SUCCESS;
671 }
672
673 CurCharInfo = CharInfo;
674
675 for (Y = CapturedWriteRegion.Top; Y <= CapturedWriteRegion.Bottom; ++Y)
676 {
677 Ptr = ConioCoordToPointer(Buffer, CapturedWriteRegion.Left, Y);
678 for (X = CapturedWriteRegion.Left; X <= CapturedWriteRegion.Right; ++X)
679 {
680 if (Unicode)
681 {
682 Ptr->Char.UnicodeChar = CurCharInfo->Char.UnicodeChar;
683 }
684 else
685 {
686 ConsoleOutputAnsiToUnicodeChar(Console, &Ptr->Char.UnicodeChar, &CurCharInfo->Char.AsciiChar);
687 }
688 // TODO: Sanitize DBCS attributes?
689 Ptr->Attributes = CurCharInfo->Attributes;
690 ++Ptr;
691 ++CurCharInfo;
692 }
693 }
694
695 TermDrawRegion(Console, &CapturedWriteRegion);
696
697 *WriteRegion = CapturedWriteRegion;
698
699 return STATUS_SUCCESS;
700}

Referenced by CON_API(), and DestroyPopupWindow().

◆ ConDrvWriteConsoleOutputString()

NTSTATUS NTAPI ConDrvWriteConsoleOutputString ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN CODE_TYPE  CodeType,
IN PVOID  StringBuffer,
IN ULONG  NumCodesToWrite,
IN PCOORD  WriteCoord,
OUT PULONG NumCodesWritten  OPTIONAL 
)

Definition at line 1161 of file text.c.

1169{
1171
1172 if (Console == NULL || Buffer == NULL || WriteCoord == NULL /* || EndCoord == NULL */)
1173 {
1175 }
1176
1177 /* Validity checks */
1178 ASSERT(Console == Buffer->Header.Console);
1179 ASSERT((StringBuffer != NULL) || (StringBuffer == NULL && NumCodesToWrite == 0));
1180
1181 if (NumCodesWritten)
1182 *NumCodesWritten = 0;
1183
1184 if (!StringBuffer || (NumCodesToWrite == 0))
1185 return STATUS_SUCCESS; // Nothing to do!
1186
1187 /* Do nothing if the writing starting point is outside of the screen buffer */
1188 if ( WriteCoord->X < 0 || WriteCoord->X >= Buffer->ScreenBufferSize.X ||
1189 WriteCoord->Y < 0 || WriteCoord->Y >= Buffer->ScreenBufferSize.Y )
1190 {
1191 return STATUS_SUCCESS;
1192 }
1193
1194 NumCodesToWrite = min(NumCodesToWrite, (ULONG)Buffer->ScreenBufferSize.X * Buffer->ScreenBufferSize.Y);
1195
1196 switch (CodeType)
1197 {
1198 case CODE_ASCII:
1199 {
1200 C_ASSERT(RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar) == sizeof(CHAR));
1202 Buffer,
1204 FALSE,
1205 NumCodesToWrite,
1206 WriteCoord,
1207 NumCodesWritten);
1208 break;
1209 }
1210
1211 case CODE_UNICODE:
1212 {
1213 C_ASSERT(RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar) == sizeof(WCHAR));
1215 Buffer,
1217 TRUE,
1218 NumCodesToWrite,
1219 WriteCoord,
1220 NumCodesWritten);
1221 break;
1222 }
1223
1224 case CODE_ATTRIBUTE:
1225 {
1226 C_ASSERT(RTL_FIELD_SIZE(CODE_ELEMENT, Attribute) == sizeof(WORD));
1228 Buffer,
1230 NumCodesToWrite,
1231 WriteCoord,
1232 NumCodesWritten);
1233 break;
1234 }
1235
1236 default:
1238 }
1239
1240 if ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer)
1241 {
1243 ConioComputeUpdateRect(Buffer, &UpdateRect, WriteCoord, NumCodesToWrite);
1245 }
1246
1247 return Status;
1248}
static NTSTATUS IntWriteConsoleOutputStringAttribute(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PWORD StringBuffer, IN ULONG NumCodesToWrite, IN PCOORD WriteCoord, OUT PULONG NumCodesWritten OPTIONAL)
Definition: text.c:1120
static NTSTATUS IntWriteConsoleOutputStringChars(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PVOID StringBuffer, IN BOOLEAN Unicode, IN ULONG NumCodesToWrite, IN PCOORD WriteCoord, OUT PULONG NumCodesWritten OPTIONAL)
Definition: text.c:1016
char CHAR
Definition: xmlstorage.h:175

Referenced by CON_API().

◆ ConDrvWriteConsoleOutputVDM()

NTSTATUS NTAPI ConDrvWriteConsoleOutputVDM ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN PCHAR_CELL  CharInfo,
IN COORD  CharInfoSize,
IN PSMALL_RECT  WriteRegion 
)

Definition at line 708 of file text.c.

713{
714 SHORT X, Y;
716 PCHAR_CELL CurCharInfo;
717 SMALL_RECT CapturedWriteRegion;
719
720 if (Console == NULL || Buffer == NULL || CharInfo == NULL || WriteRegion == NULL)
721 {
723 }
724
725 /* Validity check */
726 ASSERT(Console == Buffer->Header.Console);
727
728 CapturedWriteRegion = *WriteRegion;
729
730 /* Make sure WriteRegion is inside the screen buffer */
732 Buffer->ScreenBufferSize.Y - 1,
733 Buffer->ScreenBufferSize.X - 1);
734 if (!ConioGetIntersection(&CapturedWriteRegion, &CapturedWriteRegion, &ScreenBuffer))
735 {
736 /*
737 * It is okay to have a WriteRegion completely outside
738 * the screen buffer. No data is written then.
739 */
740 return STATUS_SUCCESS;
741 }
742
743 // CurCharInfo = CharInfo;
744
745 for (Y = CapturedWriteRegion.Top; Y <= CapturedWriteRegion.Bottom; ++Y)
746 {
747 CurCharInfo = CharInfo + Y * CharInfoSize.X + CapturedWriteRegion.Left;
748
749 Ptr = ConioCoordToPointer(Buffer, CapturedWriteRegion.Left, Y);
750 for (X = CapturedWriteRegion.Left; X <= CapturedWriteRegion.Right; ++X)
751 {
752 ConsoleOutputAnsiToUnicodeChar(Console, &Ptr->Char.UnicodeChar, &CurCharInfo->Char);
753 Ptr->Attributes = CurCharInfo->Attributes;
754 ++Ptr;
755 ++CurCharInfo;
756 }
757 }
758
759 return STATUS_SUCCESS;
760}
BYTE Attributes
Definition: svga.h:393
CHAR Char
Definition: svga.h:392

Referenced by CON_API().

◆ ConioComputeUpdateRect()

static VOID ConioComputeUpdateRect ( IN PTEXTMODE_SCREEN_BUFFER  Buff,
IN OUT PSMALL_RECT  UpdateRect,
IN PCOORD  Start,
IN UINT  Length 
)
static

Definition at line 165 of file text.c.

169{
170 if ((UINT)Buff->ScreenBufferSize.X <= Start->X + Length)
171 {
172 UpdateRect->Left = 0;
173 UpdateRect->Right = Buff->ScreenBufferSize.X - 1;
174 }
175 else
176 {
177 UpdateRect->Left = Start->X;
178 UpdateRect->Right = Start->X + Length - 1;
179 }
180 UpdateRect->Top = Start->Y;
181 UpdateRect->Bottom = Start->Y + (Start->X + Length - 1) / Buff->ScreenBufferSize.X;
182 if (Buff->ScreenBufferSize.Y <= UpdateRect->Bottom)
183 {
184 UpdateRect->Bottom = Buff->ScreenBufferSize.Y - 1;
185 }
186}
return pTarget Start()
if(dx< 0)
Definition: linetemp.h:194
unsigned int UINT
Definition: ndis.h:50

Referenced by ConDrvChangeScreenBufferAttributes(), ConDrvFillConsoleOutput(), and ConDrvWriteConsoleOutputString().

◆ ConioCoordToPointer()

◆ ConioCopyRegion()

static VOID ConioCopyRegion ( IN PTEXTMODE_SCREEN_BUFFER  ScreenBuffer,
IN PSMALL_RECT  SrcRegion,
IN PCOORD  DstOrigin 
)
static

Definition at line 193 of file text.c.

197{
199 SHORT SY, DY;
200 SHORT YDelta;
201 PCHAR_INFO PtrSrc, PtrDst;
202#if 0
203 SHORT SXOrg, DXOrg;
204 SHORT SX, DX;
205 SHORT XDelta;
206 UINT i, j;
207#endif
208
209 if (ConioIsRectEmpty(SrcRegion))
210 return;
211
212#if 0
213 ASSERT(SrcRegion->Left >= 0 && SrcRegion->Left < ScreenBuffer->ScreenBufferSize.X);
214 ASSERT(SrcRegion->Right >= 0 && SrcRegion->Right < ScreenBuffer->ScreenBufferSize.X);
215 ASSERT(SrcRegion->Top >= 0 && SrcRegion->Top < ScreenBuffer->ScreenBufferSize.Y);
216 ASSERT(SrcRegion->Bottom >= 0 && SrcRegion->Bottom < ScreenBuffer->ScreenBufferSize.Y);
217 // ASSERT(DstOrigin->X >= 0 && DstOrigin->X < ScreenBuffer->ScreenBufferSize.X);
218 // ASSERT(DstOrigin->Y >= 0 && DstOrigin->Y < ScreenBuffer->ScreenBufferSize.Y);
219#endif
220
221 /* If the source and destination regions are the same, just bail out */
222 if ((SrcRegion->Left == DstOrigin->X) && (SrcRegion->Top == DstOrigin->Y))
223 return;
224
225 SY = SrcRegion->Top;
226 DY = DstOrigin->Y;
227 YDelta = 1;
228 if (SY < DY)
229 {
230 /* Moving down: work from bottom up */
231 SY = SrcRegion->Bottom;
232 DY = DstOrigin->Y + (SrcRegion->Bottom - SrcRegion->Top);
233 YDelta = -1;
234 }
235
236#if 0
237 SXOrg = SrcRegion->Left;
238 DXOrg = DstOrigin->X;
239 XDelta = 1;
240 if (SXOrg < DXOrg)
241 {
242 /* Moving right: work from right to left */
243 SXOrg = SrcRegion->Right;
244 DXOrg = DstOrigin->X + (SrcRegion->Right - SrcRegion->Left);
245 XDelta = -1;
246 }
247#endif
248
249 /* Loop through the source region */
250 Width = ConioRectWidth(SrcRegion);
251 Height = ConioRectHeight(SrcRegion);
252#if 0
253 for (i = 0; i < Height; ++i, SY += YDelta, DY += YDelta)
254#else
255 for (; Height-- > 0; SY += YDelta, DY += YDelta)
256#endif
257 {
258#if 0
259 SX = SXOrg;
260 DX = DXOrg;
261
262 PtrSrc = ConioCoordToPointer(ScreenBuffer, SX, SY);
263 PtrDst = ConioCoordToPointer(ScreenBuffer, DX, DY);
264#else
265 PtrSrc = ConioCoordToPointer(ScreenBuffer, SrcRegion->Left, SY);
266 PtrDst = ConioCoordToPointer(ScreenBuffer, DstOrigin->X, DY);
267#endif
268
269 // TODO: Correctly support copying full-width characters.
270 // By construction the source region is supposed to contain valid
271 // (possibly fullwidth) characters, so for these after the copy
272 // we need to check the characters at the borders and adjust the
273 // attributes accordingly.
274
275#if 0
276 for (j = 0; j < Width; ++j, SX += XDelta, DX += XDelta)
277 {
278 *PtrDst = *PtrSrc;
279 PtrSrc += XDelta;
280 PtrDst += XDelta;
281 }
282#else
283 /* RtlMoveMemory() takes into account for the direction of the copy */
284 RtlMoveMemory(PtrDst, PtrSrc, Width * sizeof(CHAR_INFO));
285#endif
286 }
287}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define DX
Definition: i386-dis.c:425
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88

Referenced by ConDrvScrollConsoleScreenBuffer().

◆ ConioFillRegion()

static VOID ConioFillRegion ( IN PTEXTMODE_SCREEN_BUFFER  ScreenBuffer,
IN PSMALL_RECT  Region,
IN PSMALL_RECT ExcludeRegion  OPTIONAL,
IN CHAR_INFO  FillChar 
)
static

Definition at line 290 of file text.c.

295{
296 SHORT X, Y;
298 // BOOLEAN bFullwidth;
299
300 /* Bail out if the region to fill is empty */
302 return;
303
304 /* Sanitize the exclusion region: if it's empty, ignore the region */
305 if (ExcludeRegion && ConioIsRectEmpty(ExcludeRegion))
306 ExcludeRegion = NULL;
307
308#if 0
309 ASSERT(Region->Left >= 0 && Region->Left < ScreenBuffer->ScreenBufferSize.X);
310 ASSERT(Region->Right >= 0 && Region->Right < ScreenBuffer->ScreenBufferSize.X);
311 ASSERT(Region->Top >= 0 && Region->Top < ScreenBuffer->ScreenBufferSize.Y);
312 ASSERT(Region->Bottom >= 0 && Region->Bottom < ScreenBuffer->ScreenBufferSize.Y);
313
314 if (ExcludeRegion)
315 {
316 ASSERT(ExcludeRegion->Left >= 0 && ExcludeRegion->Left < ScreenBuffer->ScreenBufferSize.X);
317 ASSERT(ExcludeRegion->Right >= 0 && ExcludeRegion->Right < ScreenBuffer->ScreenBufferSize.X);
318 ASSERT(ExcludeRegion->Top >= 0 && ExcludeRegion->Top < ScreenBuffer->ScreenBufferSize.Y);
319 ASSERT(ExcludeRegion->Bottom >= 0 && ExcludeRegion->Bottom < ScreenBuffer->ScreenBufferSize.Y);
320 }
321#endif
322
323 // bFullwidth = (ScreenBuffer->Header.Console->IsCJK && IS_FULL_WIDTH(FillChar.Char.UnicodeChar));
324
325 /* Loop through the destination region */
326 for (Y = Region->Top; Y <= Region->Bottom; ++Y)
327 {
329 for (X = Region->Left; X <= Region->Right; ++X)
330 {
331 // TODO: Correctly support filling with full-width characters.
332
333 if (!ExcludeRegion ||
334 !(X >= ExcludeRegion->Left && X <= ExcludeRegion->Right &&
335 Y >= ExcludeRegion->Top && Y <= ExcludeRegion->Bottom))
336 {
337 /* We are outside the excluded region, fill the destination */
338 *Ptr = FillChar;
339 // Ptr->Attributes &= ~COMMON_LVB_SBCSDBCS;
340 }
341
342 ++Ptr;
343 }
344 }
345}
static LPHIST_ENTRY Bottom
Definition: history.c:54

Referenced by ConDrvScrollConsoleScreenBuffer().

◆ ConioResizeBuffer()

NTSTATUS ConioResizeBuffer ( PCONSOLE  Console,
PTEXTMODE_SCREEN_BUFFER  ScreenBuffer,
COORD  Size 
)

Definition at line 359 of file text.c.

362{
365 ULONG_PTR Offset = 0;
366 WORD CurrentAttribute;
367 USHORT CurrentY;
368 PCHAR_INFO OldBuffer;
369 DWORD i;
370 DWORD diff;
371
372 /* Zero size is invalid */
373 if (Size.X == 0 || Size.Y == 0)
375
376 /* Buffer size is not allowed to be smaller than the view size */
377 if (Size.X < ScreenBuffer->ViewSize.X || Size.Y < ScreenBuffer->ViewSize.Y)
379
380 if (Size.X == ScreenBuffer->ScreenBufferSize.X && Size.Y == ScreenBuffer->ScreenBufferSize.Y)
381 {
382 // FIXME: Trigger a buffer resize event ??
383 return STATUS_SUCCESS;
384 }
385
386 if (Console->FixedSize)
387 {
388 /*
389 * The console is in fixed-size mode, so we cannot resize anything
390 * at the moment. However, keep those settings somewhere so that
391 * we can try to set them up when we will be allowed to do so.
392 */
393 ScreenBuffer->OldScreenBufferSize = Size;
394 return STATUS_NOT_SUPPORTED; // STATUS_SUCCESS
395 }
396
398 if (!Buffer) return STATUS_NO_MEMORY;
399
400 DPRINT("Resizing (%d,%d) to (%d,%d)\n", ScreenBuffer->ScreenBufferSize.X, ScreenBuffer->ScreenBufferSize.Y, Size.X, Size.Y);
401
402 OldBuffer = ScreenBuffer->Buffer;
403
404 for (CurrentY = 0; CurrentY < ScreenBuffer->ScreenBufferSize.Y && CurrentY < Size.Y; CurrentY++)
405 {
406 Ptr = ConioCoordToPointer(ScreenBuffer, 0, CurrentY);
407
408 if (Size.X <= ScreenBuffer->ScreenBufferSize.X)
409 {
410 /* Reduce size */
411 RtlCopyMemory(Buffer + Offset, Ptr, Size.X * sizeof(CHAR_INFO));
412 Offset += Size.X;
413
414 /* If we have cut a trailing full-width character in half, remove it completely */
415 Ptr = Buffer + Offset - 1;
416 if (Ptr->Attributes & COMMON_LVB_LEADING_BYTE)
417 {
418 Ptr->Char.UnicodeChar = L' ';
419 /* Keep all the other original attributes intact */
420 Ptr->Attributes &= ~COMMON_LVB_SBCSDBCS;
421 }
422 }
423 else
424 {
425 /* Enlarge size */
426 RtlCopyMemory(Buffer + Offset, Ptr, ScreenBuffer->ScreenBufferSize.X * sizeof(CHAR_INFO));
427 Offset += ScreenBuffer->ScreenBufferSize.X;
428
429 /* The attribute to be used is the one of the last cell of the current line */
430 CurrentAttribute = ConioCoordToPointer(ScreenBuffer,
431 ScreenBuffer->ScreenBufferSize.X - 1,
432 CurrentY)->Attributes;
433 CurrentAttribute &= ~COMMON_LVB_SBCSDBCS;
434
435 diff = Size.X - ScreenBuffer->ScreenBufferSize.X;
436
437 /* Zero-out the new part of the buffer */
438 for (i = 0; i < diff; i++)
439 {
440 Ptr = Buffer + Offset;
441 Ptr->Char.UnicodeChar = L' ';
442 Ptr->Attributes = CurrentAttribute;
443 ++Offset;
444 }
445 }
446 }
447
448 if (Size.Y > ScreenBuffer->ScreenBufferSize.Y)
449 {
450 diff = Size.X * (Size.Y - ScreenBuffer->ScreenBufferSize.Y);
451
452 /* Zero-out the new part of the buffer */
453 for (i = 0; i < diff; i++)
454 {
455 Ptr = Buffer + Offset;
456 Ptr->Char.UnicodeChar = L' ';
457 Ptr->Attributes = ScreenBuffer->ScreenDefaultAttrib;
458 ++Offset;
459 }
460 }
461
463 ConsoleFreeHeap(OldBuffer);
464 ScreenBuffer->ScreenBufferSize = ScreenBuffer->OldScreenBufferSize = Size;
465 ScreenBuffer->VirtualY = 0;
466
467 /* Ensure the cursor and the view are within the buffer */
468 ScreenBuffer->CursorPosition.X = min(ScreenBuffer->CursorPosition.X, Size.X - 1);
469 ScreenBuffer->CursorPosition.Y = min(ScreenBuffer->CursorPosition.Y, Size.Y - 1);
470 ScreenBuffer->ViewOrigin.X = min(ScreenBuffer->ViewOrigin.X, Size.X - ScreenBuffer->ViewSize.X);
471 ScreenBuffer->ViewOrigin.Y = min(ScreenBuffer->ViewOrigin.Y, Size.Y - ScreenBuffer->ViewSize.Y);
472
473 /*
474 * Trigger a buffer resize event
475 */
476 if (Console->InputBuffer.Mode & ENABLE_WINDOW_INPUT)
477 {
478 ULONG NumEventsWritten;
479 INPUT_RECORD er;
480
482 er.Event.WindowBufferSizeEvent.dwSize = ScreenBuffer->ScreenBufferSize;
483
484 // ConioProcessInputEvent(Console, &er);
486 &Console->InputBuffer,
487 TRUE,
488 &er,
489 1,
490 &NumEventsWritten);
491 }
492
493 return STATUS_SUCCESS;
494}
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define DPRINT
Definition: sndvol32.h:73
union _INPUT_RECORD::@3285 Event
WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent
Definition: wincon.h:277
WORD EventType
Definition: wincon.h:273
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
NTSTATUS NTAPI ConDrvWriteConsoleInput(IN PCONSOLE Console, IN PCONSOLE_INPUT_BUFFER InputBuffer, IN BOOLEAN AppendToEnd, IN PINPUT_RECORD InputRecord, IN ULONG NumEventsToWrite, OUT PULONG NumEventsWritten OPTIONAL)
Definition: coninput.c:330
#define WINDOW_BUFFER_SIZE_EVENT
Definition: wincon.h:130
#define ENABLE_WINDOW_INPUT
Definition: wincon.h:81

Referenced by ConDrvSetConsoleScreenBufferSize(), and ConSrvApplyUserSettings().

◆ CONSOLE_SCREEN_BUFFER_Destroy()

VOID CONSOLE_SCREEN_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 55 of file conoutput.c.

56{
57 switch (Buffer->Header.Type)
58 {
59 case TEXTMODE_BUFFER:
61 break;
62
63 case GRAPHICS_BUFFER:
65 break;
66
67 case SCREEN_BUFFER:
68 {
69 /* Free the palette handle */
70 if (Buffer->PaletteHandle != NULL)
71 DeleteObject(Buffer->PaletteHandle);
72
73 /* Free the screen buffer memory */
75 break;
76 }
77
78 default:
79 break;
80 }
81}
VOID GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: graphics.c:236
VOID TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: text.c:126
pKey DeleteObject()
#define TEXTMODE_BUFFER
Definition: pccons.c:21
@ SCREEN_BUFFER
Definition: conio.h:27
@ GRAPHICS_BUFFER
Definition: conio.h:26

Referenced by ConDrvDeleteScreenBuffer(), TEXTMODE_BUFFER_Destroy(), and TEXTMODE_BUFFER_Initialize().

◆ CONSOLE_SCREEN_BUFFER_Initialize()

NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN PCONSOLE  Console,
IN CONSOLE_IO_OBJECT_TYPE  Type,
IN SIZE_T  Size 
)

Definition at line 37 of file conoutput.c.

42{
43 if (Buffer == NULL || Console == NULL)
45
48
49 /* Initialize the header with the default type */
50 ConSrvInitObject(&(*Buffer)->Header, Type /* SCREEN_BUFFER */, Console);
51 return STATUS_SUCCESS;
52}
Type
Definition: Type.h:7
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID ConSrvInitObject(IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
Definition: handle.c:211

Referenced by TEXTMODE_BUFFER_Initialize().

◆ IntReadConsoleOutputStringAttributes()

static NTSTATUS IntReadConsoleOutputStringAttributes ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
OUT PWORD  StringBuffer,
IN ULONG  NumCodesToRead,
IN PCOORD  ReadCoord,
OUT PULONG NumCodesRead  OPTIONAL 
)
static

Definition at line 903 of file text.c.

910{
911 SHORT X, Y;
912 SHORT XStart = ReadCoord->X;
913 ULONG nNumChars = 0;
915
916 for (Y = ReadCoord->Y; Y < Buffer->ScreenBufferSize.Y; ++Y)
917 {
918 Ptr = ConioCoordToPointer(Buffer, XStart, Y);
919 for (X = XStart; X < Buffer->ScreenBufferSize.X; ++X)
920 {
921 if (nNumChars >= NumCodesToRead)
922 goto Quit;
923
924 *StringBuffer = Ptr->Attributes;
925 ++Ptr;
926
927 ++StringBuffer;
928 ++nNumChars;
929 }
930 /* Restart at the beginning of the next line */
931 XStart = 0;
932 }
933Quit:
934
935 if (NumCodesRead)
936 *NumCodesRead = nNumChars;
937
938 return STATUS_SUCCESS;
939}

Referenced by ConDrvReadConsoleOutputString().

◆ IntReadConsoleOutputStringChars()

static NTSTATUS IntReadConsoleOutputStringChars ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
OUT PVOID  StringBuffer,
IN BOOLEAN  Unicode,
IN ULONG  NumCodesToRead,
IN PCOORD  ReadCoord,
OUT PULONG NumCodesRead  OPTIONAL 
)
static

Definition at line 835 of file text.c.

843{
844 ULONG CodeSize;
846 SHORT X, Y;
847 SHORT XStart = ReadCoord->X;
848 ULONG nNumChars = 0;
850 BOOLEAN bCJK = Console->IsCJK;
851
852 CodeSize = (Unicode ? RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar)
853 : RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar));
854
855 for (Y = ReadCoord->Y; Y < Buffer->ScreenBufferSize.Y; ++Y)
856 {
857 Ptr = ConioCoordToPointer(Buffer, XStart, Y);
858 for (X = XStart; X < Buffer->ScreenBufferSize.X; ++X)
859 {
860 if (nNumChars >= NumCodesToRead)
861 goto Quit;
862
863 /*
864 * For Chinese, Japanese and Korean.
865 * For full-width characters: copy only the character specified
866 * in the leading-byte cell, skipping the trailing-byte cell.
867 */
868 if (bCJK && (Ptr->Attributes & COMMON_LVB_TRAILING_BYTE))
869 {
870 /*
871 * Windows "compensates" for the fact this is a full-width
872 * character by reducing the amount of characters to be read.
873 * The understanding being that the specified amount of
874 * characters is also in "units" of (half-width) cells.
875 */
876 if (NumCodesToRead > 0) --NumCodesToRead;
877 ++Ptr;
878 continue;
879 }
880
881 if (Unicode)
882 *(PWCHAR)ReadBuffer = Ptr->Char.UnicodeChar;
883 else
885
886 ++Ptr;
887
888 ReadBuffer += CodeSize;
889 ++nNumChars;
890 }
891 /* Restart at the beginning of the next line */
892 XStart = 0;
893 }
894Quit:
895
896 if (NumCodesRead)
897 *NumCodesRead = nNumChars;
898
899 return STATUS_SUCCESS;
900}
#define ReadBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:339
unsigned char * LPBYTE
Definition: typedefs.h:53
#define ConsoleOutputUnicodeToAnsiChar(Console, dChar, sWChar)
Definition: text.c:25

Referenced by ConDrvReadConsoleOutputString().

◆ IntWriteConsoleOutputStringAttribute()

static NTSTATUS IntWriteConsoleOutputStringAttribute ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN PWORD  StringBuffer,
IN ULONG  NumCodesToWrite,
IN PCOORD  WriteCoord,
OUT PULONG NumCodesWritten  OPTIONAL 
)
static

Definition at line 1120 of file text.c.

1127{
1128 SHORT X, Y;
1129 SHORT XStart = WriteCoord->X;
1130 ULONG nNumChars = 0;
1132
1133 for (Y = WriteCoord->Y; Y < Buffer->ScreenBufferSize.Y; ++Y)
1134 {
1135 Ptr = ConioCoordToPointer(Buffer, XStart, Y);
1136 for (X = XStart; X < Buffer->ScreenBufferSize.X; ++X)
1137 {
1138 if (nNumChars >= NumCodesToWrite)
1139 goto Quit;
1140
1141 Ptr->Attributes &= COMMON_LVB_SBCSDBCS;
1142 Ptr->Attributes |= (*StringBuffer & ~COMMON_LVB_SBCSDBCS);
1143
1144 ++Ptr;
1145
1146 ++StringBuffer;
1147 ++nNumChars;
1148 }
1149 /* Restart at the beginning of the next line */
1150 XStart = 0;
1151 }
1152Quit:
1153
1154 if (NumCodesWritten)
1155 *NumCodesWritten = nNumChars;
1156
1157 return STATUS_SUCCESS;
1158}

Referenced by ConDrvWriteConsoleOutputString().

◆ IntWriteConsoleOutputStringChars()

static NTSTATUS IntWriteConsoleOutputStringChars ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN PVOID  StringBuffer,
IN BOOLEAN  Unicode,
IN ULONG  NumCodesToWrite,
IN PCOORD  WriteCoord,
OUT PULONG NumCodesWritten  OPTIONAL 
)
static

Definition at line 1016 of file text.c.

1024{
1027 PWCHAR tmpString = NULL;
1028 ULONG Length;
1029 SHORT X, Y;
1030 SHORT XStart = WriteCoord->X;
1031 ULONG nNumChars = 0;
1033 BOOLEAN bCJK = Console->IsCJK;
1034
1035 /* Convert the string to UNICODE */
1036 if (Unicode)
1037 {
1039 }
1040 else
1041 {
1042 /* Convert the ASCII string into Unicode before writing it to the console */
1043 Length = MultiByteToWideChar(Console->OutputCodePage, 0,
1045 NumCodesToWrite,
1046 NULL, 0);
1047 tmpString = ConsoleAllocHeap(0, Length * sizeof(WCHAR));
1048 if (!tmpString)
1049 {
1051 goto Quit;
1052 }
1053
1054 MultiByteToWideChar(Console->OutputCodePage, 0,
1056 NumCodesToWrite,
1057 tmpString, Length);
1058
1059 NumCodesToWrite = Length;
1060 WriteBuffer = tmpString;
1061 }
1062
1063 for (Y = WriteCoord->Y; Y < Buffer->ScreenBufferSize.Y; ++Y)
1064 {
1065 Ptr = ConioCoordToPointer(Buffer, XStart, Y);
1066 for (X = XStart; X < Buffer->ScreenBufferSize.X; ++X)
1067 {
1068 if (nNumChars >= NumCodesToWrite)
1069 goto Quit;
1070
1071 /* For Chinese, Japanese and Korean */
1072 if (bCJK && IS_FULL_WIDTH(*WriteBuffer))
1073 {
1074 /* A full-width character cannot cross a line boundary */
1075 if (X >= Buffer->ScreenBufferSize.X - 1)
1076 {
1077 /* Go to next line */
1078 break; // Break the X-loop only.
1079 }
1080
1081 /* Set the leading byte */
1082 Ptr->Char.UnicodeChar = *WriteBuffer;
1083 Ptr->Attributes &= ~COMMON_LVB_SBCSDBCS;
1084 Ptr->Attributes |= COMMON_LVB_LEADING_BYTE;
1085 ++Ptr;
1086
1087 /* Set the trailing byte */
1088 Ptr->Char.UnicodeChar = L' ';
1089 Ptr->Attributes &= ~COMMON_LVB_SBCSDBCS;
1090 Ptr->Attributes |= COMMON_LVB_TRAILING_BYTE;
1091 }
1092 else
1093 {
1094 Ptr->Char.UnicodeChar = *WriteBuffer;
1095 }
1096
1097 ++Ptr;
1098
1099 ++WriteBuffer;
1100 ++nNumChars;
1101 }
1102 /* Restart at the beginning of the next line */
1103 XStart = 0;
1104 }
1105Quit:
1106
1107 if (tmpString)
1108 {
1109 ASSERT(!Unicode);
1110 ConsoleFreeHeap(tmpString);
1111 }
1112
1113 if (NumCodesWritten)
1114 *NumCodesWritten = nNumChars;
1115
1116 return Status;
1117}
#define WriteBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:344

Referenced by ConDrvWriteConsoleOutputString().

◆ TEXTMODE_BUFFER_Destroy()

VOID TEXTMODE_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 126 of file text.c.

127{
129
130 /*
131 * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
132 * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
133 */
134 Buffer->Header.Type = SCREEN_BUFFER;
135
136 ConsoleFreeHeap(Buff->Buffer);
137
139}
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
struct _TEXTMODE_SCREEN_BUFFER * PTEXTMODE_SCREEN_BUFFER

Referenced by CONSOLE_SCREEN_BUFFER_Destroy().

◆ TEXTMODE_BUFFER_Initialize()

NTSTATUS TEXTMODE_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN PCONSOLE  Console,
IN HANDLE  ProcessHandle,
IN PTEXTMODE_BUFFER_INFO  TextModeInfo 
)

Definition at line 54 of file text.c.

58{
60 PTEXTMODE_SCREEN_BUFFER NewBuffer = NULL;
61
63
64 if (Console == NULL || Buffer == NULL || TextModeInfo == NULL)
66
67 if ((TextModeInfo->ScreenBufferSize.X == 0) ||
68 (TextModeInfo->ScreenBufferSize.Y == 0))
69 {
71 }
72
73 *Buffer = NULL;
74
76 Console,
79 if (!NT_SUCCESS(Status)) return Status;
80
81 NewBuffer->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
82 TextModeInfo->ScreenBufferSize.X *
83 TextModeInfo->ScreenBufferSize.Y *
84 sizeof(CHAR_INFO));
85 if (NewBuffer->Buffer == NULL)
86 {
89 }
90
91 NewBuffer->ScreenBufferSize = TextModeInfo->ScreenBufferSize;
92 NewBuffer->OldScreenBufferSize = NewBuffer->ScreenBufferSize;
93
94 /*
95 * Set and fix the view size if needed.
96 * The rule is: ScreenBufferSize >= ViewSize (== ConsoleSize)
97 */
98 NewBuffer->ViewSize.X = min(max(TextModeInfo->ViewSize.X, 1), NewBuffer->ScreenBufferSize.X);
99 NewBuffer->ViewSize.Y = min(max(TextModeInfo->ViewSize.Y, 1), NewBuffer->ScreenBufferSize.Y);
100 NewBuffer->OldViewSize = NewBuffer->ViewSize;
101
102 NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
103 NewBuffer->VirtualY = 0;
104
105 NewBuffer->CursorBlinkOn = NewBuffer->ForceCursorOff = FALSE;
106 NewBuffer->CursorInfo.bVisible = (TextModeInfo->IsCursorVisible && (TextModeInfo->CursorSize != 0));
107 NewBuffer->CursorInfo.dwSize = min(max(TextModeInfo->CursorSize, 0), 100);
108
109 NewBuffer->ScreenDefaultAttrib = (TextModeInfo->ScreenAttrib & ~COMMON_LVB_SBCSDBCS);
110 NewBuffer->PopupDefaultAttrib = (TextModeInfo->PopupAttrib & ~COMMON_LVB_SBCSDBCS);
111
112 /* Initialize buffer to be empty with default attributes */
113 for (NewBuffer->CursorPosition.Y = 0 ; NewBuffer->CursorPosition.Y < NewBuffer->ScreenBufferSize.Y; NewBuffer->CursorPosition.Y++)
114 {
115 ClearLineBuffer(NewBuffer);
116 }
117 NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
118
120
121 *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
122 return STATUS_SUCCESS;
123}
#define ENABLE_WRAP_AT_EOL_OUTPUT
Definition: blue.h:54
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:53
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
BOOLEAN ForceCursorOff
Definition: conio.h:73
COORD CursorPosition
Definition: conio.h:71
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:75
COORD OldScreenBufferSize
Definition: conio.h:65
COORD ScreenBufferSize
Definition: conio.h:62
BOOLEAN CursorBlinkOn
Definition: conio.h:72
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN CONSOLE_IO_OBJECT_TYPE Type, IN SIZE_T Size)
Definition: conoutput.c:37
VOID ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff)
Definition: text.c:151
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER

Referenced by ConDrvCreateScreenBuffer().