ReactOS 0.4.15-dev-7953-g1f49173
popup.c File Reference
#include "consrv.h"
#include "popup.h"
#include <debug.h>
Include dependency graph for popup.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

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 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)
 
static VOID DrawBox (PTEXTMODE_SCREEN_BUFFER Buffer, IN SHORT xLeft, IN SHORT yTop, IN SHORT Width, IN SHORT Height)
 
PPOPUP_WINDOW CreatePopupWindow (IN PCONSRV_CONSOLE Console, IN PCONSOLE_SCREEN_BUFFER ScreenBuffer, IN SHORT xLeft, IN SHORT yTop, IN SHORT Width, IN SHORT Height)
 
VOID DestroyPopupWindow (IN PPOPUP_WINDOW Popup)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 20 of file popup.c.

Function Documentation

◆ 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
CConsole Console
#define IS_FULL_WIDTH(wch)
Definition: console.c:337
Definition: bufpool.h:45
@ CODE_ASCII
Definition: conmsg.h:517
@ CODE_UNICODE
Definition: conmsg.h:518
@ CODE_ATTRIBUTE
Definition: conmsg.h:519
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define Y(I)
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define X(b, s)
#define ASSERT(a)
Definition: mode.c:44
#define min(a, b)
Definition: monoChain.cc:55
#define L(x)
Definition: ntvdm.h:50
short SHORT
Definition: pedump.c:59
#define STATUS_SUCCESS
Definition: shellext.h:65
#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
WCHAR UnicodeChar
Definition: conmsg.h:525
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1701
static VOID ConioComputeUpdateRect(IN PTEXTMODE_SCREEN_BUFFER Buff, IN OUT PSMALL_RECT UpdateRect, IN PCOORD Start, IN UINT Length)
Definition: text.c:165
#define ConsoleOutputAnsiToUnicodeChar(Console, dWChar, sChar)
Definition: text.c:31
PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
Definition: text.c:143
#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 DrawBox().

◆ 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
CHAR AsciiChar
Definition: wincon.h:185
WCHAR UnicodeChar
Definition: wincon.h:184
WORD Attributes
Definition: wincon.h:187
union _CHAR_INFO::@3290 Char
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 CreatePopupWindow().

◆ 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 DestroyPopupWindow().

◆ CreatePopupWindow()

PPOPUP_WINDOW CreatePopupWindow ( IN PCONSRV_CONSOLE  Console,
IN PCONSOLE_SCREEN_BUFFER  ScreenBuffer,
IN SHORT  xLeft,
IN SHORT  yTop,
IN SHORT  Width,
IN SHORT  Height 
)

Definition at line 184 of file popup.c.

191{
195
196 ASSERT((PCONSOLE)Console == ScreenBuffer->Header.Console);
197
199 return NULL;
200
202
203 /* Create the popup window */
205 if (Popup == NULL) return NULL;
206
207 Popup->ScreenBuffer = Buffer;
208 Popup->Origin.X = xLeft;
209 Popup->Origin.Y = yTop;
210 Popup->Size.X = Width;
211 Popup->Size.Y = Height;
212
213 /* Save old contents */
215 Popup->Size.X * Popup->Size.Y *
216 sizeof(*Popup->OldContents));
217 if (Popup->OldContents == NULL)
218 {
220 return NULL;
221 }
222 Region.Left = Popup->Origin.X;
223 Region.Top = Popup->Origin.Y;
224 Region.Right = Popup->Origin.X + Popup->Size.X - 1;
225 Region.Bottom = Popup->Origin.Y + Popup->Size.Y - 1;
226 ConDrvReadConsoleOutput(Buffer->Header.Console,
227 Buffer,
228 TRUE,
229 Popup->OldContents,
230 &Region);
231
232 /* Draw it */
234 xLeft, yTop,
235 Width, Height);
236
237 /* Add it into the list of popups */
238 InsertTailList(&Console->PopupWindows, &Popup->ListEntry);
239
240 return Popup;
241}
@ Popup
Definition: console.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define InsertTailList(ListHead, Entry)
#define TEXTMODE_BUFFER
Definition: pccons.c:21
NTSTATUS NTAPI ConDrvReadConsoleOutput(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN BOOLEAN Unicode, OUT PCHAR_INFO CharInfo, IN OUT PSMALL_RECT ReadRegion)
Definition: text.c:569
static VOID DrawBox(PTEXTMODE_SCREEN_BUFFER Buffer, IN SHORT xLeft, IN SHORT yTop, IN SHORT Width, IN SHORT Height)
Definition: popup.c:49
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
struct _TEXTMODE_SCREEN_BUFFER * PTEXTMODE_SCREEN_BUFFER
#define GetType(This)
Definition: conio.h:54

Referenced by HistoryDisplayCurrentHistory().

◆ DestroyPopupWindow()

VOID DestroyPopupWindow ( IN PPOPUP_WINDOW  Popup)

Definition at line 244 of file popup.c.

246{
248
249 if (Popup == NULL) return;
250
251 /* Remove it from the list of popups */
252 RemoveEntryList(&Popup->ListEntry);
253
254 /* Restore the old screen-buffer contents */
255 Region.Left = Popup->Origin.X;
256 Region.Top = Popup->Origin.Y;
257 Region.Right = Popup->Origin.X + Popup->Size.X - 1;
258 Region.Bottom = Popup->Origin.Y + Popup->Size.Y - 1;
259 ConDrvWriteConsoleOutput(Popup->ScreenBuffer->Header.Console,
260 Popup->ScreenBuffer,
261 TRUE,
262 Popup->OldContents,
263 &Region);
264
265 /* Free memory */
266 ConsoleFreeHeap(Popup->OldContents);
268}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
NTSTATUS NTAPI ConDrvWriteConsoleOutput(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN BOOLEAN Unicode, IN PCHAR_INFO CharInfo, IN OUT PSMALL_RECT WriteRegion)
Definition: text.c:638

Referenced by LineInputKeyDown().

◆ DrawBox()

static VOID DrawBox ( PTEXTMODE_SCREEN_BUFFER  Buffer,
IN SHORT  xLeft,
IN SHORT  yTop,
IN SHORT  Width,
IN SHORT  Height 
)
static

Definition at line 49 of file popup.c.

54{
55 COORD coPos;
56 DWORD Written;
58
59 /* Set screen attributes */
60 coPos.X = xLeft;
61 Code.Attribute = Buffer->PopupDefaultAttrib;
62 for (coPos.Y = yTop; coPos.Y < yTop + Height; coPos.Y++)
63 {
64 ConDrvFillConsoleOutput(Buffer->Header.Console,
65 Buffer,
67 Code,
68 Width,
69 &coPos,
70 &Written);
71 }
72
73 /* draw upper left corner */
74 coPos.X = xLeft;
75 coPos.Y = yTop;
76 Code.AsciiChar = 0xDA; // '+'
77 ConDrvFillConsoleOutput(Buffer->Header.Console,
78 Buffer,
80 Code,
81 1,
82 &coPos,
83 &Written);
84
85 /* draw upper edge */
86 coPos.X = xLeft + 1;
87 coPos.Y = yTop;
88 Code.AsciiChar = 0xC4; // '-'
89 ConDrvFillConsoleOutput(Buffer->Header.Console,
90 Buffer,
92 Code,
93 Width - 2,
94 &coPos,
95 &Written);
96
97 /* draw upper right corner */
98 coPos.X = xLeft + Width - 1;
99 coPos.Y = yTop;
100 Code.AsciiChar = 0xBF; // '+'
101 ConDrvFillConsoleOutput(Buffer->Header.Console,
102 Buffer,
104 Code,
105 1,
106 &coPos,
107 &Written);
108
109 /* Draw right edge, inner space and left edge */
110 for (coPos.Y = yTop + 1; coPos.Y < yTop + Height - 1; coPos.Y++)
111 {
112 coPos.X = xLeft;
113 Code.AsciiChar = 0xB3; // '|'
114 ConDrvFillConsoleOutput(Buffer->Header.Console,
115 Buffer,
117 Code,
118 1,
119 &coPos,
120 &Written);
121
122 coPos.X = xLeft + 1;
123 Code.AsciiChar = ' ';
124 ConDrvFillConsoleOutput(Buffer->Header.Console,
125 Buffer,
127 Code,
128 Width - 2,
129 &coPos,
130 &Written);
131
132 coPos.X = xLeft + Width - 1;
133 Code.AsciiChar = 0xB3; // '|'
134 ConDrvFillConsoleOutput(Buffer->Header.Console,
135 Buffer,
137 Code,
138 1,
139 &coPos,
140 &Written);
141 }
142
143 /* draw lower left corner */
144 coPos.X = xLeft;
145 coPos.Y = yTop + Height - 1;
146 Code.AsciiChar = 0xC0; // '+'
147 ConDrvFillConsoleOutput(Buffer->Header.Console,
148 Buffer,
150 Code,
151 1,
152 &coPos,
153 &Written);
154
155 /* draw lower edge */
156 coPos.X = xLeft + 1;
157 coPos.Y = yTop + Height - 1;
158 Code.AsciiChar = 0xC4; // '-'
159 ConDrvFillConsoleOutput(Buffer->Header.Console,
160 Buffer,
162 Code,
163 Width - 2,
164 &coPos,
165 &Written);
166
167 /* draw lower right corner */
168 coPos.X = xLeft + Width - 1;
169 coPos.Y = yTop + Height - 1;
170 Code.AsciiChar = 0xD9; // '+'
171 ConDrvFillConsoleOutput(Buffer->Header.Console,
172 Buffer,
174 Code,
175 1,
176 &coPos,
177 &Written);
178}
#define Code
Definition: deflate.h:80
unsigned long DWORD
Definition: ntddk_ex.h:95
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: text.c:1251
Definition: bl.h:1338
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339

Referenced by CreatePopupWindow().