ReactOS  0.4.14-dev-838-g99f979d
text.c File Reference
#include <consrv.h>
#include <debug.h>
#include "guiterm.h"
Include dependency graph for text.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define IS_WHITESPACE(c)   ((c) == L'\0' || (c) == L' ' || (c) == L'\t')
 

Functions

static COLORREF PaletteRGBFromAttrib (PCONSRV_CONSOLE Console, WORD Attribute)
 
static VOID CopyBlock (PTEXTMODE_SCREEN_BUFFER Buffer, PSMALL_RECT Selection)
 
static VOID CopyLines (PTEXTMODE_SCREEN_BUFFER Buffer, PCOORD Begin, PCOORD End)
 
VOID PasteText (IN PCONSRV_CONSOLE Console, IN PWCHAR Buffer, IN SIZE_T cchSize)
 
VOID GetSelectionBeginEnd (PCOORD Begin, PCOORD End, PCOORD SelectionAnchor, PSMALL_RECT SmallRect)
 
VOID GuiCopyFromTextModeBuffer (PTEXTMODE_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData)
 
VOID GuiPasteToTextModeBuffer (PTEXTMODE_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData)
 
VOID GuiPaintTextModeBuffer (PTEXTMODE_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData, PRECT rcView, PRECT rcFramebuffer)
 

Macro Definition Documentation

◆ IS_WHITESPACE

#define IS_WHITESPACE (   c)    ((c) == L'\0' || (c) == L' ' || (c) == L'\t')

Definition at line 23 of file text.c.

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file text.c.

Function Documentation

◆ CopyBlock()

static VOID CopyBlock ( PTEXTMODE_SCREEN_BUFFER  Buffer,
PSMALL_RECT  Selection 
)
static

Definition at line 40 of file text.c.

42 {
43  /*
44  * Pressing the Shift key while copying text, allows us to copy
45  * text without newline characters (inline-text copy mode).
46  */
47  BOOL InlineCopyMode = !!(GetKeyState(VK_SHIFT) & KEY_PRESSED);
48 
49  HANDLE hData;
51  LPWSTR data, dstPos;
52  ULONG selWidth, selHeight;
53  ULONG xPos, yPos;
54  ULONG size;
55 
56  DPRINT("CopyBlock(%u, %u, %u, %u)\n",
57  Selection->Left, Selection->Top, Selection->Right, Selection->Bottom);
58 
59  /* Prevent against empty blocks */
60  if (Selection == NULL) return;
61  if (Selection->Left > Selection->Right || Selection->Top > Selection->Bottom)
62  return;
63 
64  selWidth = Selection->Right - Selection->Left + 1;
65  selHeight = Selection->Bottom - Selection->Top + 1;
66 
67  /* Basic size for one line... */
68  size = selWidth;
69  /* ... and for the other lines, add newline characters if needed. */
70  if (selHeight > 0)
71  {
72  /*
73  * If we are not in inline-text copy mode, each selected line must
74  * finish with \r\n . Otherwise, the lines will be just concatenated.
75  */
76  size += (selWidth + (!InlineCopyMode ? 2 : 0)) * (selHeight - 1);
77  }
78  else
79  {
80  DPRINT1("This case must never happen, because selHeight is at least == 1\n");
81  }
82 
83  size++; /* Null-termination */
84  size *= sizeof(WCHAR);
85 
86  /* Allocate some memory area to be given to the clipboard, so it will not be freed here */
88  if (hData == NULL) return;
89 
90  data = GlobalLock(hData);
91  if (data == NULL)
92  {
93  GlobalFree(hData);
94  return;
95  }
96 
97  DPRINT("Copying %dx%d selection\n", selWidth, selHeight);
98  dstPos = data;
99 
100  for (yPos = 0; yPos < selHeight; yPos++)
101  {
102  ULONG length = selWidth;
103 
105  Selection->Left,
106  Selection->Top + yPos);
107 
108  /* Trim whitespace from the right */
109  while (length > 0)
110  {
111  if (IS_WHITESPACE(ptr[length-1].Char.UnicodeChar))
112  --length;
113  else
114  break;
115  }
116 
117  /* Copy only the characters, leave attributes alone */
118  for (xPos = 0; xPos < length; xPos++)
119  {
120  /*
121  * Sometimes, applications can put NULL chars into the screen-buffer
122  * (this behaviour is allowed). Detect this and replace by a space.
123  */
124  *dstPos++ = (ptr[xPos].Char.UnicodeChar ? ptr[xPos].Char.UnicodeChar : L' ');
125  }
126 
127  /* Add newline characters if we are not in inline-text copy mode */
128  if (!InlineCopyMode)
129  {
130  if (yPos != (selHeight - 1))
131  {
132  wcscat(dstPos, L"\r\n");
133  dstPos += 2;
134  }
135  }
136  }
137 
138  DPRINT("Setting data <%S> to clipboard\n", data);
139  GlobalUnlock(hData);
140 
141  EmptyClipboard();
143 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
Definition: text.c:142
HANDLE WINAPI SetClipboardData(_In_ UINT, _In_opt_ HANDLE)
SHORT Right
Definition: wincon.h:178
SHORT Left
Definition: wincon.h:176
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IS_WHITESPACE(c)
Definition: text.c:23
static PVOID ptr
Definition: dispmode.c:27
#define VK_SHIFT
Definition: winuser.h:2177
#define CF_UNICODETEXT
Definition: constants.h:408
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
SHORT WINAPI GetKeyState(_In_ int)
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
GLsizeiptr size
Definition: glext.h:5919
#define KEY_PRESSED
Definition: conwnd.h:26
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
SHORT Bottom
Definition: wincon.h:179
static const WCHAR L[]
Definition: oid.c:1250
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
SHORT Top
Definition: wincon.h:177
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define GMEM_MOVEABLE
Definition: winbase.h:291
#define GMEM_ZEROINIT
Definition: winbase.h:303

Referenced by GuiCopyFromTextModeBuffer().

◆ CopyLines()

static VOID CopyLines ( PTEXTMODE_SCREEN_BUFFER  Buffer,
PCOORD  Begin,
PCOORD  End 
)
static

Definition at line 146 of file text.c.

149 {
150  HANDLE hData;
151  PCHAR_INFO ptr;
152  LPWSTR data, dstPos;
153  ULONG NumChars, size;
154  ULONG xPos, yPos, xBeg, xEnd;
155 
156  DPRINT("CopyLines((%u, %u) ; (%u, %u))\n",
157  Begin->X, Begin->Y, End->X, End->Y);
158 
159  /* Prevent against empty blocks... */
160  if (Begin == NULL || End == NULL) return;
161  /* ... or malformed blocks */
162  if (Begin->Y > End->Y || (Begin->Y == End->Y && Begin->X > End->X)) return;
163 
164  /* Compute the number of characters to copy */
165  if (End->Y == Begin->Y) // top == bottom
166  {
167  NumChars = End->X - Begin->X + 1;
168  }
169  else // if (End->Y > Begin->Y)
170  {
171  NumChars = Buffer->ScreenBufferSize.X - Begin->X;
172 
173  if (End->Y >= Begin->Y + 2)
174  {
175  NumChars += (End->Y - Begin->Y - 1) * Buffer->ScreenBufferSize.X;
176  }
177 
178  NumChars += End->X + 1;
179  }
180 
181  size = (NumChars + 1) * sizeof(WCHAR); /* Null-terminated */
182 
183  /* Allocate some memory area to be given to the clipboard, so it will not be freed here */
185  if (hData == NULL) return;
186 
187  data = GlobalLock(hData);
188  if (data == NULL)
189  {
190  GlobalFree(hData);
191  return;
192  }
193 
194  DPRINT("Copying %d characters\n", NumChars);
195  dstPos = data;
196 
197  /*
198  * We need to walk per-lines, and not just looping in the big screen-buffer
199  * array, because of the way things are stored inside it. The downside is
200  * that it makes the code more complicated.
201  */
202  for (yPos = Begin->Y; (yPos <= (ULONG)End->Y) && (NumChars > 0); yPos++)
203  {
204  xBeg = (yPos == Begin->Y ? Begin->X : 0);
205  xEnd = (yPos == End->Y ? End->X : Buffer->ScreenBufferSize.X - 1);
206 
207  ptr = ConioCoordToPointer(Buffer, 0, yPos);
208 
209  /* Copy only the characters, leave attributes alone */
210  for (xPos = xBeg; (xPos <= xEnd) && (NumChars-- > 0); xPos++)
211  {
212  /*
213  * Sometimes, applications can put NULL chars into the screen-buffer
214  * (this behaviour is allowed). Detect this and replace by a space.
215  */
216  *dstPos++ = (ptr[xPos].Char.UnicodeChar ? ptr[xPos].Char.UnicodeChar : L' ');
217  }
218  }
219 
220  DPRINT("Setting data <%S> to clipboard\n", data);
221  GlobalUnlock(hData);
222 
223  EmptyClipboard();
225 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
Definition: text.c:142
HANDLE WINAPI SetClipboardData(_In_ UINT, _In_opt_ HANDLE)
static PVOID ptr
Definition: dispmode.c:27
#define CF_UNICODETEXT
Definition: constants.h:408
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
ULONG X
Definition: bl.h:1340
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static const WCHAR L[]
Definition: oid.c:1250
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
unsigned int ULONG
Definition: retypes.h:1
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 const char BOOLEAN Begin
Definition: acpixf.h:1293
WCHAR * LPWSTR
Definition: xmlstorage.h:184
ULONG Y
Definition: bl.h:1341
#define GMEM_MOVEABLE
Definition: winbase.h:291
#define GMEM_ZEROINIT
Definition: winbase.h:303

Referenced by GuiCopyFromTextModeBuffer().

◆ GetSelectionBeginEnd()

VOID GetSelectionBeginEnd ( PCOORD  Begin,
PCOORD  End,
PCOORD  SelectionAnchor,
PSMALL_RECT  SmallRect 
)

Definition at line 721 of file conwnd.c.

724 {
725  if (Begin == NULL || End == NULL) return;
726 
727  *Begin = *SelectionAnchor;
728  End->X = (SelectionAnchor->X == SmallRect->Left) ? SmallRect->Right
729  /* Case X != Left, must be == Right */ : SmallRect->Left;
730  End->Y = (SelectionAnchor->Y == SmallRect->Top ) ? SmallRect->Bottom
731  /* Case Y != Top, must be == Bottom */ : SmallRect->Top;
732 
733  /* Exchange Begin / End if Begin > End lexicographically */
734  if (Begin->Y > End->Y || (Begin->Y == End->Y && Begin->X > End->X))
735  {
736  End->X = _InterlockedExchange16(&Begin->X, End->X);
737  End->Y = _InterlockedExchange16(&Begin->Y, End->Y);
738  }
739 }
SHORT Right
Definition: wincon.h:178
SHORT Left
Definition: wincon.h:176
short _InterlockedExchange16(_Interlocked_operand_ short volatile *_Target, short _Value)
smooth NULL
Definition: ftsmooth.c:416
ULONG X
Definition: bl.h:1340
SHORT Bottom
Definition: wincon.h:179
SHORT Top
Definition: wincon.h:177
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 const char BOOLEAN Begin
Definition: acpixf.h:1293
ULONG Y
Definition: bl.h:1341

Referenced by CreateSelectionRgn(), and GuiCopyFromTextModeBuffer().

◆ GuiCopyFromTextModeBuffer()

VOID GuiCopyFromTextModeBuffer ( PTEXTMODE_SCREEN_BUFFER  Buffer,
PGUI_CONSOLE_DATA  GuiData 
)

Definition at line 297 of file text.c.

299 {
300  /*
301  * This function supposes that the system clipboard was opened.
302  */
303 
304  BOOL LineSelection = GuiData->LineSelection;
305 
306  DPRINT("Selection is (%d|%d) to (%d|%d) in %s mode\n",
307  GuiData->Selection.srSelection.Left,
308  GuiData->Selection.srSelection.Top,
309  GuiData->Selection.srSelection.Right,
310  GuiData->Selection.srSelection.Bottom,
311  (LineSelection ? "line" : "block"));
312 
313  if (!LineSelection)
314  {
316  }
317  else
318  {
319  COORD Begin, End;
320 
322  &GuiData->Selection.dwSelectionAnchor,
323  &GuiData->Selection.srSelection);
324 
325  CopyLines(Buffer, &Begin, &End);
326  }
327 }
static VOID CopyLines(PTEXTMODE_SCREEN_BUFFER Buffer, PCOORD Begin, PCOORD End)
Definition: text.c:146
CONSOLE_SELECTION_INFO Selection
Definition: conwnd.h:92
SMALL_RECT srSelection
Definition: wincon.h:195
VOID GetSelectionBeginEnd(PCOORD Begin, PCOORD End, PCOORD SelectionAnchor, PSMALL_RECT SmallRect)
Definition: conwnd.c:721
unsigned int BOOL
Definition: ntddk_ex.h:94
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
static VOID CopyBlock(PTEXTMODE_SCREEN_BUFFER Buffer, PSMALL_RECT Selection)
Definition: text.c:40
BOOL LineSelection
Definition: conwnd.h:94
SHORT Left
Definition: blue.h:32
SHORT Bottom
Definition: blue.h:35
SHORT Top
Definition: blue.h:33
Definition: bl.h:1338
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 const char BOOLEAN Begin
Definition: acpixf.h:1293
SHORT Right
Definition: blue.h:34

Referenced by Copy().

◆ GuiPaintTextModeBuffer()

VOID GuiPaintTextModeBuffer ( PTEXTMODE_SCREEN_BUFFER  Buffer,
PGUI_CONSOLE_DATA  GuiData,
PRECT  rcView,
PRECT  rcFramebuffer 
)

Definition at line 355 of file text.c.

359 {
360  PCONSRV_CONSOLE Console = Buffer->Header.Console;
361  ULONG TopLine, BottomLine, LeftColumn, RightColumn;
362  ULONG Line, Char, Start;
363  PCHAR_INFO From;
364  PWCHAR To;
365  WORD LastAttribute, Attribute;
366  ULONG CursorX, CursorY, CursorHeight;
367  HBRUSH CursorBrush, OldBrush;
368  HFONT OldFont, NewFont;
369  BOOLEAN IsUnderline;
370 
371  // ASSERT(Console == GuiData->Console);
372 
373  ConioInitLongRect(rcFramebuffer, 0, 0, 0, 0);
374 
375  if (Buffer->Buffer == NULL)
376  return;
377 
379  return;
380 
381  ConioInitLongRect(rcFramebuffer,
382  Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->top,
383  Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->left,
384  Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->bottom,
385  Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->right);
386 
387  LeftColumn = rcFramebuffer->left / GuiData->CharWidth;
388  RightColumn = rcFramebuffer->right / GuiData->CharWidth;
389  if (RightColumn >= (ULONG)Buffer->ScreenBufferSize.X)
390  RightColumn = Buffer->ScreenBufferSize.X - 1;
391 
392  TopLine = rcFramebuffer->top / GuiData->CharHeight;
393  BottomLine = rcFramebuffer->bottom / GuiData->CharHeight;
394  if (BottomLine >= (ULONG)Buffer->ScreenBufferSize.Y)
395  BottomLine = Buffer->ScreenBufferSize.Y - 1;
396 
397  LastAttribute = ConioCoordToPointer(Buffer, LeftColumn, TopLine)->Attributes;
398 
401 
402  /* We use the underscore flag as a underline flag */
403  IsUnderline = !!(LastAttribute & COMMON_LVB_UNDERSCORE);
404  /* Select the new font */
405  NewFont = GuiData->Font[IsUnderline ? FONT_BOLD : FONT_NORMAL];
406  OldFont = SelectObject(GuiData->hMemDC, NewFont);
407 
408  if (Console->IsCJK)
409  {
410  for (Line = TopLine; Line <= BottomLine; Line++)
411  {
412  for (Char = LeftColumn; Char <= RightColumn; Char++)
413  {
414  From = ConioCoordToPointer(Buffer, Char, Line);
415  Attribute = From->Attributes;
418 
419  /* Change underline state if needed */
420  if (!!(Attribute & COMMON_LVB_UNDERSCORE) != IsUnderline)
421  {
422  IsUnderline = !!(Attribute & COMMON_LVB_UNDERSCORE);
423 
424  /* Select the new font */
425  NewFont = GuiData->Font[IsUnderline ? FONT_BOLD : FONT_NORMAL];
426  SelectObject(GuiData->hMemDC, NewFont);
427  }
428 
429  if (Attribute & COMMON_LVB_TRAILING_BYTE)
430  continue;
431 
432  TextOutW(GuiData->hMemDC,
433  Char * GuiData->CharWidth,
434  Line * GuiData->CharHeight,
435  &From->Char.UnicodeChar, 1);
436  }
437  }
438  }
439  else
440  {
441  for (Line = TopLine; Line <= BottomLine; Line++)
442  {
443  WCHAR LineBuffer[80]; // Buffer containing a part or all the line to be displayed
444  From = ConioCoordToPointer(Buffer, LeftColumn, Line); // Get the first code of the line
445  Start = LeftColumn;
446  To = LineBuffer;
447 
448  for (Char = LeftColumn; Char <= RightColumn; Char++)
449  {
450  /*
451  * We flush the buffer if the new attribute is different
452  * from the current one, or if the buffer is full.
453  */
454  if (From->Attributes != LastAttribute || (Char - Start == sizeof(LineBuffer) / sizeof(WCHAR)))
455  {
456  TextOutW(GuiData->hMemDC,
457  Start * GuiData->CharWidth,
458  Line * GuiData->CharHeight,
459  LineBuffer,
460  Char - Start);
461  Start = Char;
462  To = LineBuffer;
463  Attribute = From->Attributes;
464  if (Attribute != LastAttribute)
465  {
466  LastAttribute = Attribute;
469 
470  /* Change underline state if needed */
471  if (!!(LastAttribute & COMMON_LVB_UNDERSCORE) != IsUnderline)
472  {
473  IsUnderline = !!(LastAttribute & COMMON_LVB_UNDERSCORE);
474  /* Select the new font */
475  NewFont = GuiData->Font[IsUnderline ? FONT_BOLD : FONT_NORMAL];
476  SelectObject(GuiData->hMemDC, NewFont);
477  }
478  }
479  }
480 
481  *(To++) = (From++)->Char.UnicodeChar;
482  }
483 
484  TextOutW(GuiData->hMemDC,
485  Start * GuiData->CharWidth,
486  Line * GuiData->CharHeight,
487  LineBuffer,
488  RightColumn - Start + 1);
489  }
490  }
491 
492  /* Restore the old font */
493  SelectObject(GuiData->hMemDC, OldFont);
494 
495  /*
496  * Draw the caret
497  */
498  if (Buffer->CursorInfo.bVisible &&
499  Buffer->CursorBlinkOn &&
500  !Buffer->ForceCursorOff)
501  {
502  CursorX = Buffer->CursorPosition.X;
503  CursorY = Buffer->CursorPosition.Y;
504  if (LeftColumn <= CursorX && CursorX <= RightColumn &&
505  TopLine <= CursorY && CursorY <= BottomLine)
506  {
507  CursorHeight = ConioEffectiveCursorSize(Console, GuiData->CharHeight);
508 
509  Attribute = ConioCoordToPointer(Buffer, Buffer->CursorPosition.X, Buffer->CursorPosition.Y)->Attributes;
510  if (Attribute == DEFAULT_SCREEN_ATTRIB)
511  Attribute = Buffer->ScreenDefaultAttrib;
512 
514  OldBrush = SelectObject(GuiData->hMemDC, CursorBrush);
515 
516  if (Attribute & COMMON_LVB_LEADING_BYTE)
517  {
518  /* The caret is on the leading byte */
519  PatBlt(GuiData->hMemDC,
520  CursorX * GuiData->CharWidth,
521  CursorY * GuiData->CharHeight + (GuiData->CharHeight - CursorHeight),
522  GuiData->CharWidth * 2,
523  CursorHeight,
524  PATCOPY);
525  }
526  else if (Attribute & COMMON_LVB_TRAILING_BYTE)
527  {
528  /* The caret is on the trailing byte */
529  PatBlt(GuiData->hMemDC,
530  (CursorX - 1) * GuiData->CharWidth,
531  CursorY * GuiData->CharHeight + (GuiData->CharHeight - CursorHeight),
532  GuiData->CharWidth * 2,
533  CursorHeight,
534  PATCOPY);
535  }
536  else
537  {
538  PatBlt(GuiData->hMemDC,
539  CursorX * GuiData->CharWidth,
540  CursorY * GuiData->CharHeight + (GuiData->CharHeight - CursorHeight),
541  GuiData->CharWidth,
542  CursorHeight,
543  PATCOPY);
544  }
545 
546  SelectObject(GuiData->hMemDC, OldBrush);
547  DeleteObject(CursorBrush);
548  }
549  }
550 
552 }
#define DEFAULT_SCREEN_ATTRIB
Definition: settings.c:29
#define TRUE
Definition: types.h:120
BOOL WINAPI TextOutW(_In_ HDC hdc, _In_ INT nXStart, _In_ INT nYStart, _In_reads_(cchString) LPCWSTR lpString, _In_ INT cchString)
Definition: text.c:66
static COLORREF PaletteRGBFromAttrib(PCONSRV_CONSOLE Console, WORD Attribute)
Definition: text.c:28
PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
Definition: text.c:142
WCHAR UnicodeChar
Definition: wincon.h:169
static ULONG CursorY
Definition: display.c:137
LONG top
Definition: windef.h:307
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
uint16_t * PWCHAR
Definition: typedefs.h:54
LONG left
Definition: windef.h:306
#define PCONSRV_CONSOLE
Definition: conio.h:27
LONG right
Definition: windef.h:308
#define COMMON_LVB_UNDERSCORE
Definition: wincon.h:54
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:975
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
UINT CharHeight
Definition: conwnd.h:87
#define FONT_NORMAL
Definition: conwnd.h:35
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
HFONT Font[FONT_MAXNO]
Definition: conwnd.h:85
#define BkgdAttribFromAttrib(Attribute)
Definition: settings.h:73
#define ConioInitLongRect(Rect, Top, Left, Bottom, Right)
Definition: rect.h:12
__wchar_t WCHAR
Definition: xmlstorage.h:180
WORD Attributes
Definition: wincon.h:172
union _CHAR_INFO::@3171 Char
unsigned short WORD
Definition: ntddk_ex.h:93
Definition: partlist.h:33
Definition: ncftp.h:79
static ULONG CursorX
Definition: display.c:136
#define TextAttribFromAttrib(Attribute)
Definition: settings.h:72
#define PATCOPY
Definition: wingdi.h:334
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:120
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
UINT CharWidth
Definition: conwnd.h:86
DWORD FASTCALL ConioEffectiveCursorSize(PCONSOLE Console, DWORD Scale)
Definition: text.c:303
CConsole Console
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define COMMON_LVB_LEADING_BYTE
Definition: wincon.h:48
unsigned int ULONG
Definition: retypes.h:1
LONG bottom
Definition: windef.h:309
COLORREF WINAPI SetTextColor(_In_ HDC hdc, _In_ COLORREF crColor)
Definition: text.c:888
#define COMMON_LVB_TRAILING_BYTE
Definition: wincon.h:49
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
struct Line Line

Referenced by OnPaint().

◆ GuiPasteToTextModeBuffer()

VOID GuiPasteToTextModeBuffer ( PTEXTMODE_SCREEN_BUFFER  Buffer,
PGUI_CONSOLE_DATA  GuiData 
)

Definition at line 330 of file text.c.

332 {
333  /*
334  * This function supposes that the system clipboard was opened.
335  */
336 
337  PCONSRV_CONSOLE Console = Buffer->Header.Console;
338 
339  HANDLE hData;
340  LPWSTR pszText;
341 
343  if (hData == NULL) return;
344 
345  pszText = GlobalLock(hData);
346  if (pszText == NULL) return;
347 
348  DPRINT("Got data <%S> from clipboard\n", pszText);
349  PasteText(Console, pszText, wcslen(pszText));
350 
351  GlobalUnlock(hData);
352 }
#define PCONSRV_CONSOLE
Definition: conio.h:27
VOID PasteText(IN PCONSRV_CONSOLE Console, IN PWCHAR Buffer, IN SIZE_T cchSize)
Definition: text.c:229
#define CF_UNICODETEXT
Definition: constants.h:408
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HANDLE WINAPI GetClipboardData(_In_ UINT)
CConsole Console
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by Paste().

◆ PaletteRGBFromAttrib()

static COLORREF PaletteRGBFromAttrib ( PCONSRV_CONSOLE  Console,
WORD  Attribute 
)
static

Definition at line 28 of file text.c.

29 {
30  HPALETTE hPalette = Console->ActiveBuffer->PaletteHandle;
31  PALETTEENTRY pe;
32 
33  if (hPalette == NULL) return RGBFromAttrib(Console, Attribute);
34 
35  GetPaletteEntries(hPalette, Attribute, 1, &pe);
36  return PALETTERGB(pe.peRed, pe.peGreen, pe.peBlue);
37 }
UINT WINAPI GetPaletteEntries(HPALETTE hpal, UINT iStartIndex, UINT cEntries, LPPALETTEENTRY ppe)
Definition: palette.c:64
smooth NULL
Definition: ftsmooth.c:416
#define RGBFromAttrib(Console, Attribute)
Definition: settings.h:71
#define PALETTERGB(r, g, b)
Definition: wingdi.h:2941
CConsole Console

Referenced by GuiPaintTextModeBuffer().

◆ PasteText()

VOID PasteText ( IN PCONSRV_CONSOLE  Console,
IN PWCHAR  Buffer,
IN SIZE_T  cchSize 
)

Definition at line 229 of file text.c.

233 {
234  USHORT VkKey; // MAKEWORD(low = vkey_code, high = shift_state);
235  INPUT_RECORD er;
236  WCHAR CurChar = 0;
237 
238  /* Do nothing if we have nothing to paste */
239  if (!Buffer || (cchSize <= 0))
240  return;
241 
242  er.EventType = KEY_EVENT;
243  er.Event.KeyEvent.wRepeatCount = 1;
244  while (cchSize--)
245  {
246  /* \r or \n characters. Go to the line only if we get "\r\n" sequence. */
247  if (CurChar == L'\r' && *Buffer == L'\n')
248  {
249  ++Buffer;
250  continue;
251  }
252  CurChar = *Buffer++;
253 
254  /* Get the key code (+ shift state) corresponding to the character */
255  VkKey = VkKeyScanW(CurChar);
256  if (VkKey == 0xFFFF)
257  {
258  DPRINT1("FIXME: TODO: VkKeyScanW failed - Should simulate the key!\n");
259  /*
260  * We don't really need the scan/key code because we actually only
261  * use the UnicodeChar for output purposes. It may pose few problems
262  * later on but it's not of big importance. One trick would be to
263  * convert the character to OEM / multibyte and use MapVirtualKey()
264  * on each byte (simulating an Alt-0xxx OEM keyboard press).
265  */
266  }
267 
268  /* Pressing some control keys */
269 
270  /* Pressing the character key, with the control keys maintained pressed */
272  er.Event.KeyEvent.wVirtualKeyCode = LOBYTE(VkKey);
276  if (HIBYTE(VkKey) & 1)
278  if (HIBYTE(VkKey) & 2)
279  er.Event.KeyEvent.dwControlKeyState |= LEFT_CTRL_PRESSED; // RIGHT_CTRL_PRESSED;
280  if (HIBYTE(VkKey) & 4)
281  er.Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED; // RIGHT_ALT_PRESSED;
282 
284 
285  /* Up all the character and control keys */
288  }
289 }
#define TRUE
Definition: types.h:120
WCHAR UnicodeChar
Definition: wincon.h:230
WORD wVirtualScanCode
Definition: wincon.h:228
#define LOBYTE(W)
Definition: jmemdos.c:487
DWORD dwControlKeyState
Definition: wincon.h:233
#define HIBYTE(W)
Definition: jmemdos.c:486
#define SHIFT_PRESSED
Definition: wincon.h:135
WORD wVirtualKeyCode
Definition: wincon.h:227
WORD wRepeatCount
Definition: wincon.h:226
#define KEY_EVENT
Definition: wincon.h:122
Definition: bufpool.h:45
UINT WINAPI MapVirtualKeyW(_In_ UINT, _In_ UINT)
#define LEFT_ALT_PRESSED
Definition: wincon.h:132
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAPVK_VK_TO_VSC
Definition: winuser.h:2330
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
static const WCHAR L[]
Definition: oid.c:1250
static TCHAR CurChar
Definition: parser.c:52
union _KEY_EVENT_RECORD::@3172 uChar
unsigned short USHORT
Definition: pedump.c:61
CConsole Console
WORD EventType
Definition: wincon.h:261
#define DPRINT1
Definition: precomp.h:8
SHORT WINAPI VkKeyScanW(_In_ WCHAR)
union _INPUT_RECORD::@3173 Event
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
NTSTATUS ConioProcessInputEvent(PCONSRV_CONSOLE Console, PINPUT_RECORD InputEvent)
Definition: coninput.c:195

Referenced by GuiPasteToTextModeBuffer(), and OnDropFiles().