/* INCLUDES *******************************************************************/
-#include "consrv.h"
-#include "include/conio.h"
-#include "include/settings.h"
-#include "guisettings.h"
+#include <consrv.h>
#define NDEBUG
#include <debug.h>
-
/* FUNCTIONS ******************************************************************/
+COLORREF RGBFromAttrib2(PCONSOLE Console, WORD Attribute)
+{
+ HPALETTE hPalette = Console->ActiveBuffer->PaletteHandle;
+ PALETTEENTRY pe;
+
+ if (hPalette == NULL) return RGBFromAttrib(Console, Attribute);
+
+ GetPaletteEntries(hPalette, Attribute, 1, &pe);
+ return PALETTERGB(pe.peRed, pe.peGreen, pe.peBlue);
+}
+
VOID
-GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer)
+GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
+ PGUI_CONSOLE_DATA GuiData)
{
/*
* This function supposes that the system clipboard was opened.
Console->Selection.srSelection.Right,
Console->Selection.srSelection.Bottom);
+#ifdef IS_WHITESPACE
+#undef IS_WHITESPACE
+#endif
+#define IS_WHITESPACE(c) ((c) == L'\0' || (c) == L' ' || (c) == L'\t')
+
/* Basic size for one line... */
size = selWidth;
/* ... and for the other lines, add newline characters if needed. */
size += 1; /* Null-termination */
size *= sizeof(WCHAR);
- /* Allocate memory, it will be passed to the system and may not be freed here */
+ /* Allocate some memory area to be given to the clipboard, so it will not be freed here */
hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size);
if (hData == NULL) return;
data = GlobalLock(hData);
- if (data == NULL) return;
+ if (data == NULL)
+ {
+ GlobalFree(hData);
+ return;
+ }
DPRINT("Copying %dx%d selection\n", selWidth, selHeight);
dstPos = data;
for (yPos = 0; yPos < selHeight; yPos++)
{
- ptr = ConioCoordToPointer(Buffer,
+ ULONG length = selWidth;
+
+ ptr = ConioCoordToPointer(Buffer,
Console->Selection.srSelection.Left,
- yPos + Console->Selection.srSelection.Top);
+ Console->Selection.srSelection.Top + yPos);
+
+ /* Trim whitespace from the right */
+ while (length > 0)
+ {
+ if (IS_WHITESPACE(ptr[length-1].Char.UnicodeChar))
+ --length;
+ else
+ break;
+ }
+
/* Copy only the characters, leave attributes alone */
- for (xPos = 0; xPos < selWidth; xPos++)
+ for (xPos = 0; xPos < length; xPos++)
{
/*
* Sometimes, applications can put NULL chars into the screen-buffer
* (this behaviour is allowed). Detect this and replace by a space.
- * FIXME - HACK: Improve the way we're doing that (i.e., put spaces
- * instead of NULLs (or even, nothing) only if it exists a non-null
- * char *after* those NULLs, before the end-of-line of the selection.
- * Do the same concerning spaces -- i.e. trailing spaces --).
*/
dstPos[xPos] = (ptr[xPos].Char.UnicodeChar ? ptr[xPos].Char.UnicodeChar : L' ');
}
- dstPos += selWidth;
+ dstPos += length;
/* Add newline characters if we are not in inline-text copy mode */
if (!InlineCopyMode)
}
VOID
-GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer)
+GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
+ PGUI_CONSOLE_DATA GuiData)
{
/*
* This function supposes that the system clipboard was opened.
LPWSTR str;
WCHAR CurChar = 0;
- SHORT VkKey; // MAKEWORD(low = vkey_code, high = shift_state);
+ USHORT VkKey; // MAKEWORD(low = vkey_code, high = shift_state);
INPUT_RECORD er;
hData = GetClipboardData(CF_UNICODETEXT);
LastAttribute = ConioCoordToPointer(Buffer, LeftChar, TopLine)->Attributes;
- SetTextColor(GuiData->hMemDC, RGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute)));
- SetBkColor(GuiData->hMemDC, RGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute)));
+ SetTextColor(GuiData->hMemDC, RGBFromAttrib2(Console, TextAttribFromAttrib(LastAttribute)));
+ SetBkColor(GuiData->hMemDC, RGBFromAttrib2(Console, BkgdAttribFromAttrib(LastAttribute)));
OldFont = SelectObject(GuiData->hMemDC, GuiData->Font);
Attribute = From->Attributes;
if (Attribute != LastAttribute)
{
- SetTextColor(GuiData->hMemDC, RGBFromAttrib(Console, TextAttribFromAttrib(Attribute)));
- SetBkColor(GuiData->hMemDC, RGBFromAttrib(Console, BkgdAttribFromAttrib(Attribute)));
+ SetTextColor(GuiData->hMemDC, RGBFromAttrib2(Console, TextAttribFromAttrib(Attribute)));
+ SetBkColor(GuiData->hMemDC, RGBFromAttrib2(Console, BkgdAttribFromAttrib(Attribute)));
LastAttribute = Attribute;
}
}
Attribute = ConioCoordToPointer(Buffer, Buffer->CursorPosition.X, Buffer->CursorPosition.Y)->Attributes;
if (Attribute == DEFAULT_SCREEN_ATTRIB) Attribute = Buffer->ScreenDefaultAttrib;
- CursorBrush = CreateSolidBrush(RGBFromAttrib(Console, Attribute));
+ CursorBrush = CreateSolidBrush(RGBFromAttrib2(Console, TextAttribFromAttrib(Attribute)));
OldBrush = SelectObject(GuiData->hMemDC, CursorBrush);
PatBlt(GuiData->hMemDC,