- Selection info is per-terminal.
- Lock the console only when needed.

svn path=/trunk/; revision=62864
This commit is contained in:
Hermès Bélusca-Maïto 2014-04-22 03:44:13 +00:00
parent fefde4e142
commit 66bad13542
13 changed files with 185 additions and 172 deletions

View file

@ -575,11 +575,6 @@ ConDrvInitConsole(OUT PHANDLE NewConsoleHandle,
Console->LineInsertToggle = Console->InsertMode;
// LineWakeupMask
// FIXME: This is terminal-specific !! VV
RtlZeroMemory(&Console->Selection, sizeof(CONSOLE_SELECTION_INFO));
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
// dwSelectionCursor
/* Set-up the code page */
Console->CodePage = Console->OutputCodePage = ConsoleInfo->CodePage;

View file

@ -116,6 +116,13 @@ DummyGetLargestConsoleWindowSize(IN OUT PFRONTEND This,
{
}
static BOOL NTAPI
DummyGetSelectionInfo(IN OUT PFRONTEND This,
PCONSOLE_SELECTION_INFO pSelectionInfo)
{
return TRUE;
}
static BOOL NTAPI
DummySetPalette(IN OUT PFRONTEND This,
HPALETTE PaletteHandle,
@ -183,6 +190,7 @@ static FRONTEND_VTBL DummyVtbl =
DummyChangeIcon,
DummyGetConsoleWindowHandle,
DummyGetLargestConsoleWindowSize,
DummyGetSelectionInfo,
DummySetPalette,
DummyGetDisplayMode,
DummySetDisplayMode,

View file

@ -308,14 +308,13 @@ CSR_API(SrvGetConsoleSelectionInfo)
PCONSOLE Console;
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (NT_SUCCESS(Status))
{
memset(&GetSelectionInfoRequest->Info, 0, sizeof(CONSOLE_SELECTION_INFO));
if (Console->Selection.dwFlags != 0)
GetSelectionInfoRequest->Info = Console->Selection;
ConSrvReleaseConsole(Console, TRUE);
}
if (!NT_SUCCESS(Status)) return Status;
Status = (TermGetSelectionInfo(Console, &GetSelectionInfoRequest->Info)
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL);
ConSrvReleaseConsole(Console, TRUE);
return Status;
}

View file

@ -266,11 +266,15 @@ SendMenuEvent(PCONSOLE Console, UINT CmdId)
{
INPUT_RECORD er;
DPRINT1("Menu item ID: %d\n", CmdId);
if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
er.EventType = MENU_EVENT;
er.Event.MenuEvent.dwCommandId = CmdId;
DPRINT("Menu item ID: %d\n", CmdId);
ConioProcessInputEvent(Console, &er);
LeaveCriticalSection(&Console->Lock);
}
static VOID
@ -283,36 +287,34 @@ UpdateSelection(PGUI_CONSOLE_DATA GuiData, PCOORD coord);
static VOID
Mark(PGUI_CONSOLE_DATA GuiData)
{
PCONSOLE Console = GuiData->Console;
PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
/* Clear the old selection */
// UpdateSelection(GuiData, NULL);
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
GuiData->Selection.dwFlags = CONSOLE_NO_SELECTION;
/* Restart a new selection */
Console->dwSelectionCursor.X = ActiveBuffer->ViewOrigin.X;
Console->dwSelectionCursor.Y = ActiveBuffer->ViewOrigin.Y;
Console->Selection.dwSelectionAnchor = Console->dwSelectionCursor;
UpdateSelection(GuiData, &Console->Selection.dwSelectionAnchor);
GuiData->dwSelectionCursor.X = ActiveBuffer->ViewOrigin.X;
GuiData->dwSelectionCursor.Y = ActiveBuffer->ViewOrigin.Y;
GuiData->Selection.dwSelectionAnchor = GuiData->dwSelectionCursor;
UpdateSelection(GuiData, &GuiData->Selection.dwSelectionAnchor);
}
static VOID
SelectAll(PGUI_CONSOLE_DATA GuiData)
{
PCONSOLE Console = GuiData->Console;
PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
/* Clear the old selection */
// UpdateSelection(GuiData, NULL);
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
GuiData->Selection.dwFlags = CONSOLE_NO_SELECTION;
/*
* The selection area extends to the whole screen buffer's width.
*/
Console->Selection.dwSelectionAnchor.X = 0;
Console->Selection.dwSelectionAnchor.Y = 0;
Console->dwSelectionCursor.X = ActiveBuffer->ScreenBufferSize.X - 1;
GuiData->Selection.dwSelectionAnchor.X = 0;
GuiData->Selection.dwSelectionAnchor.Y = 0;
GuiData->dwSelectionCursor.X = ActiveBuffer->ScreenBufferSize.X - 1;
/*
* Determine whether the selection must extend to just some part
@ -325,19 +327,19 @@ SelectAll(PGUI_CONSOLE_DATA GuiData)
* We select all the characters from the first line
* to the line where the cursor is positioned.
*/
Console->dwSelectionCursor.Y = ActiveBuffer->CursorPosition.Y;
GuiData->dwSelectionCursor.Y = ActiveBuffer->CursorPosition.Y;
}
else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
{
/*
* We select all the screen buffer area.
*/
Console->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
GuiData->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
}
/* Restart a new selection */
Console->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION;
UpdateSelection(GuiData, &Console->dwSelectionCursor);
GuiData->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION;
UpdateSelection(GuiData, &GuiData->dwSelectionCursor);
}
static LRESULT
@ -346,12 +348,6 @@ OnCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
LRESULT Ret = TRUE;
PCONSOLE Console = GuiData->Console;
if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE))
{
Ret = FALSE;
goto Quit;
}
/*
* In case the selected menu item belongs to the user-reserved menu id range,
* send to him a menu event and return directly. The user must handle those
@ -360,7 +356,7 @@ OnCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
if (GuiData->CmdIdLow <= (UINT)wParam && (UINT)wParam <= GuiData->CmdIdHigh)
{
SendMenuEvent(Console, (UINT)wParam);
goto Unlock_Quit;
goto Quit;
}
/* ... otherwise, perform actions. */
@ -403,8 +399,6 @@ OnCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
break;
}
Unlock_Quit:
LeaveCriticalSection(&Console->Lock);
Quit:
if (!Ret)
Ret = DefWindowProcW(GuiData->hWindow, WM_SYSCOMMAND, wParam, lParam);
@ -643,12 +637,12 @@ OnFocus(PGUI_CONSOLE_DATA GuiData, BOOL SetFocus)
er.Event.FocusEvent.bSetFocus = SetFocus;
ConioProcessInputEvent(Console, &er);
LeaveCriticalSection(&Console->Lock);
if (SetFocus)
DPRINT1("TODO: Create console caret\n");
else
DPRINT1("TODO: Destroy console caret\n");
LeaveCriticalSection(&Console->Lock);
}
static VOID
@ -671,7 +665,7 @@ UpdateSelection(PGUI_CONSOLE_DATA GuiData, PCOORD coord)
PCONSOLE Console = GuiData->Console;
RECT oldRect;
SmallRectToRect(GuiData, &oldRect, &Console->Selection.srSelection);
SmallRectToRect(GuiData, &oldRect, &GuiData->Selection.srSelection);
if (coord != NULL)
{
@ -679,16 +673,16 @@ UpdateSelection(PGUI_CONSOLE_DATA GuiData, PCOORD coord)
SMALL_RECT rc;
/* Exchange left/top with right/bottom if required */
rc.Left = min(Console->Selection.dwSelectionAnchor.X, coord->X);
rc.Top = min(Console->Selection.dwSelectionAnchor.Y, coord->Y);
rc.Right = max(Console->Selection.dwSelectionAnchor.X, coord->X);
rc.Bottom = max(Console->Selection.dwSelectionAnchor.Y, coord->Y);
rc.Left = min(GuiData->Selection.dwSelectionAnchor.X, coord->X);
rc.Top = min(GuiData->Selection.dwSelectionAnchor.Y, coord->Y);
rc.Right = max(GuiData->Selection.dwSelectionAnchor.X, coord->X);
rc.Bottom = max(GuiData->Selection.dwSelectionAnchor.Y, coord->Y);
SmallRectToRect(GuiData, &newRect, &rc);
if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
if (GuiData->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
{
if (memcmp(&rc, &Console->Selection.srSelection, sizeof(SMALL_RECT)) != 0)
if (memcmp(&rc, &GuiData->Selection.srSelection, sizeof(SMALL_RECT)) != 0)
{
HRGN rgn1, rgn2;
@ -712,22 +706,22 @@ UpdateSelection(PGUI_CONSOLE_DATA GuiData, PCOORD coord)
InvalidateRect(GuiData->hWindow, &newRect, FALSE);
}
Console->Selection.dwFlags |= CONSOLE_SELECTION_NOT_EMPTY;
Console->Selection.srSelection = rc;
Console->dwSelectionCursor = *coord;
GuiData->Selection.dwFlags |= CONSOLE_SELECTION_NOT_EMPTY;
GuiData->Selection.srSelection = rc;
GuiData->dwSelectionCursor = *coord;
if ((Console->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) == 0)
if ((GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) == 0)
{
LPWSTR SelectionType, WindowTitle = NULL;
SIZE_T Length = 0;
/* Clear the old selection */
if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
if (GuiData->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
{
InvalidateRect(GuiData->hWindow, &oldRect, FALSE);
}
if (Console->Selection.dwFlags & CONSOLE_MOUSE_SELECTION)
if (GuiData->Selection.dwFlags & CONSOLE_MOUSE_SELECTION)
{
SelectionType = L"Selection - ";
}
@ -743,19 +737,19 @@ UpdateSelection(PGUI_CONSOLE_DATA GuiData, PCOORD coord)
SetWindowText(GuiData->hWindow, WindowTitle);
ConsoleFreeHeap(WindowTitle);
Console->Selection.dwFlags |= CONSOLE_SELECTION_IN_PROGRESS;
GuiData->Selection.dwFlags |= CONSOLE_SELECTION_IN_PROGRESS;
ConioPause(Console, PAUSED_FROM_SELECTION);
}
}
else
{
/* Clear the selection */
if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
if (GuiData->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
{
InvalidateRect(GuiData->hWindow, &oldRect, FALSE);
}
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
GuiData->Selection.dwFlags = CONSOLE_NO_SELECTION;
ConioUnpause(Console, PAUSED_FROM_SELECTION);
SetWindowText(GuiData->hWindow, Console->Title.Buffer);
@ -777,17 +771,10 @@ GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
static VOID
OnPaint(PGUI_CONSOLE_DATA GuiData)
{
BOOL Success = TRUE;
PCONSOLE Console = GuiData->Console;
PCONSOLE_SCREEN_BUFFER ActiveBuffer;
PAINTSTRUCT ps;
RECT rcPaint;
if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE))
{
Success = FALSE;
goto Quit;
}
ActiveBuffer = GuiData->ActiveBuffer;
BeginPaint(GuiData->hWindow, &ps);
@ -820,9 +807,9 @@ OnPaint(PGUI_CONSOLE_DATA GuiData)
rcPaint.top,
SRCCOPY);
if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
if (GuiData->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
{
SmallRectToRect(GuiData, &rcPaint, &Console->Selection.srSelection);
SmallRectToRect(GuiData, &rcPaint, &GuiData->Selection.srSelection);
/* Invert the selection */
if (IntersectRect(&rcPaint, &ps.rcPaint, &rcPaint))
@ -835,12 +822,6 @@ OnPaint(PGUI_CONSOLE_DATA GuiData)
}
EndPaint(GuiData->hWindow, &ps);
Quit:
if (Success)
LeaveCriticalSection(&Console->Lock);
else
DefWindowProcW(GuiData->hWindow, WM_PAINT, 0, 0);
return;
}
@ -898,7 +879,7 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
ActiveBuffer = GuiData->ActiveBuffer;
if (Console->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS)
if (GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS)
{
WORD VirtualKeyCode = LOWORD(wParam);
@ -918,7 +899,7 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
goto Quit;
}
if ((Console->Selection.dwFlags & CONSOLE_MOUSE_SELECTION) == 0)
if ((GuiData->Selection.dwFlags & CONSOLE_MOUSE_SELECTION) == 0)
{
/* Keyboard selection mode */
BOOL Interpreted = FALSE;
@ -929,8 +910,8 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
case VK_LEFT:
{
Interpreted = TRUE;
if (Console->dwSelectionCursor.X > 0)
Console->dwSelectionCursor.X--;
if (GuiData->dwSelectionCursor.X > 0)
GuiData->dwSelectionCursor.X--;
break;
}
@ -938,8 +919,8 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
case VK_RIGHT:
{
Interpreted = TRUE;
if (Console->dwSelectionCursor.X < ActiveBuffer->ScreenBufferSize.X - 1)
Console->dwSelectionCursor.X++;
if (GuiData->dwSelectionCursor.X < ActiveBuffer->ScreenBufferSize.X - 1)
GuiData->dwSelectionCursor.X++;
break;
}
@ -947,8 +928,8 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
case VK_UP:
{
Interpreted = TRUE;
if (Console->dwSelectionCursor.Y > 0)
Console->dwSelectionCursor.Y--;
if (GuiData->dwSelectionCursor.Y > 0)
GuiData->dwSelectionCursor.Y--;
break;
}
@ -956,8 +937,8 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
case VK_DOWN:
{
Interpreted = TRUE;
if (Console->dwSelectionCursor.Y < ActiveBuffer->ScreenBufferSize.Y - 1)
Console->dwSelectionCursor.Y++;
if (GuiData->dwSelectionCursor.Y < ActiveBuffer->ScreenBufferSize.Y - 1)
GuiData->dwSelectionCursor.Y++;
break;
}
@ -965,24 +946,24 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
case VK_HOME:
{
Interpreted = TRUE;
Console->dwSelectionCursor.X = 0;
Console->dwSelectionCursor.Y = 0;
GuiData->dwSelectionCursor.X = 0;
GuiData->dwSelectionCursor.Y = 0;
break;
}
case VK_END:
{
Interpreted = TRUE;
Console->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
GuiData->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
break;
}
case VK_PRIOR:
{
Interpreted = TRUE;
Console->dwSelectionCursor.Y -= ActiveBuffer->ViewSize.Y;
if (Console->dwSelectionCursor.Y < 0)
Console->dwSelectionCursor.Y = 0;
GuiData->dwSelectionCursor.Y -= ActiveBuffer->ViewSize.Y;
if (GuiData->dwSelectionCursor.Y < 0)
GuiData->dwSelectionCursor.Y = 0;
break;
}
@ -990,9 +971,9 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
case VK_NEXT:
{
Interpreted = TRUE;
Console->dwSelectionCursor.Y += ActiveBuffer->ViewSize.Y;
if (Console->dwSelectionCursor.Y >= ActiveBuffer->ScreenBufferSize.Y)
Console->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
GuiData->dwSelectionCursor.Y += ActiveBuffer->ViewSize.Y;
if (GuiData->dwSelectionCursor.Y >= ActiveBuffer->ScreenBufferSize.Y)
GuiData->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
break;
}
@ -1004,9 +985,9 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
if (Interpreted)
{
if (!MajPressed)
Console->Selection.dwSelectionAnchor = Console->dwSelectionCursor;
GuiData->Selection.dwSelectionAnchor = GuiData->dwSelectionCursor;
UpdateSelection(GuiData, &Console->dwSelectionCursor);
UpdateSelection(GuiData, &GuiData->dwSelectionCursor);
}
else if (!IsSystemKey(VirtualKeyCode))
{
@ -1032,7 +1013,7 @@ OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
}
}
if ((Console->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) == 0)
if ((GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) == 0)
{
MSG Message;
@ -1265,7 +1246,7 @@ OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
goto Quit;
}
if ( (Console->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) ||
if ( (GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) ||
(Console->QuickEdit) )
{
switch (msg)
@ -1274,13 +1255,13 @@ OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
{
/* Clear the old selection */
// UpdateSelection(GuiData, NULL);
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
GuiData->Selection.dwFlags = CONSOLE_NO_SELECTION;
/* Restart a new selection */
Console->Selection.dwSelectionAnchor = PointToCoord(GuiData, lParam);
GuiData->Selection.dwSelectionAnchor = PointToCoord(GuiData, lParam);
SetCapture(GuiData->hWindow);
Console->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN;
UpdateSelection(GuiData, &Console->Selection.dwSelectionAnchor);
GuiData->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN;
UpdateSelection(GuiData, &GuiData->Selection.dwSelectionAnchor);
break;
}
@ -1289,10 +1270,10 @@ OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
{
// COORD c;
if (!(Console->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) break;
if (!(GuiData->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) break;
// c = PointToCoord(GuiData, lParam);
Console->Selection.dwFlags &= ~CONSOLE_MOUSE_DOWN;
GuiData->Selection.dwFlags &= ~CONSOLE_MOUSE_DOWN;
// UpdateSelection(GuiData, &c);
ReleaseCapture();
@ -1338,11 +1319,11 @@ OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
* Update the selection started with the single
* left-click that preceded this double-click.
*/
Console->Selection.dwSelectionAnchor = cL;
Console->dwSelectionCursor = cR;
GuiData->Selection.dwSelectionAnchor = cL;
GuiData->dwSelectionCursor = cR;
Console->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN;
UpdateSelection(GuiData, &Console->dwSelectionCursor);
GuiData->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN;
UpdateSelection(GuiData, &GuiData->dwSelectionCursor);
/* Ignore the next mouse move signal */
GuiData->IgnoreNextMouseSignal = TRUE;
@ -1354,7 +1335,7 @@ OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
{
if (!(Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY))
if (!(GuiData->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY))
{
Paste(GuiData);
}
@ -1373,7 +1354,7 @@ OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
COORD c;
if (!(wParam & MK_LBUTTON)) break;
if (!(Console->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) break;
if (!(GuiData->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) break;
c = PointToCoord(GuiData, lParam); /* TODO: Scroll buffer to bring c into view */
UpdateSelection(GuiData, &c);
@ -1674,11 +1655,8 @@ OnSize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
static VOID
OnMove(PGUI_CONSOLE_DATA GuiData)
{
PCONSOLE Console = GuiData->Console;
RECT rcWnd;
if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
// TODO: Simplify the code.
// See: GuiConsoleNotifyWndProc() PM_CREATE_CONSOLE.
@ -1686,8 +1664,6 @@ OnMove(PGUI_CONSOLE_DATA GuiData)
GetWindowRect(GuiData->hWindow, &rcWnd);
GuiData->GuiInfo.WindowOrigin.x = rcWnd.left;
GuiData->GuiInfo.WindowOrigin.y = rcWnd.top;
LeaveCriticalSection(&Console->Lock);
}
/*
@ -2042,20 +2018,16 @@ ConWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* Enable or disable the Copy and Paste items */
EnableMenuItem(hMenu, ID_SYSTEM_EDIT_COPY , MF_BYCOMMAND |
((Console->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) &&
(Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY) ? MF_ENABLED : MF_GRAYED));
((GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) &&
(GuiData->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY) ? MF_ENABLED : MF_GRAYED));
// FIXME: Following whether the active screen buffer is text-mode
// or graphics-mode, search for CF_UNICODETEXT or CF_BITMAP formats.
EnableMenuItem(hMenu, ID_SYSTEM_EDIT_PASTE, MF_BYCOMMAND |
(!(Console->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) &&
(!(GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) &&
IsClipboardFormatAvailable(CF_UNICODETEXT) ? MF_ENABLED : MF_GRAYED));
}
if (ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE))
{
SendMenuEvent(Console, WM_INITMENU);
LeaveCriticalSection(&Console->Lock);
}
SendMenuEvent(Console, WM_INITMENU);
break;
}
@ -2063,11 +2035,7 @@ ConWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (HIWORD(wParam) == 0xFFFF) // Allow all the menu flags
{
if (ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE))
{
SendMenuEvent(Console, WM_MENUSELECT);
LeaveCriticalSection(&Console->Lock);
}
SendMenuEvent(Console, WM_MENUSELECT);
}
break;
}
@ -2170,11 +2138,7 @@ ConWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case PM_APPLY_CONSOLE_INFO:
{
if (ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE))
{
GuiApplyUserSettings(GuiData, (HANDLE)wParam, (BOOL)lParam);
LeaveCriticalSection(&Console->Lock);
}
GuiApplyUserSettings(GuiData, (HANDLE)wParam, (BOOL)lParam);
break;
}

View file

@ -63,6 +63,8 @@ typedef struct _GUI_CONSOLE_DATA
PCONSOLE Console; /* Pointer to the owned console */
PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to the active screen buffer (then maybe the previous Console member is redundant?? Or not...) */
CONSOLE_SELECTION_INFO Selection; /* Contains information about the selection */
COORD dwSelectionCursor; /* Selection cursor position, most of the time different from Selection.dwSelectionAnchor */
GUI_CONSOLE_INFO GuiInfo; /* GUI terminal settings */
} GUI_CONSOLE_DATA, *PGUI_CONSOLE_DATA;

View file

@ -25,8 +25,6 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
* This function supposes that the system clipboard was opened.
*/
PCONSOLE Console = Buffer->Header.Console;
HDC hMemDC;
HBITMAP hBitmapTarget, hBitmapOld;
HPALETTE hPalette, hPaletteOld;
@ -34,13 +32,13 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
if (Buffer->BitMap == NULL) return;
selWidth = Console->Selection.srSelection.Right - Console->Selection.srSelection.Left + 1;
selHeight = Console->Selection.srSelection.Bottom - Console->Selection.srSelection.Top + 1;
selWidth = GuiData->Selection.srSelection.Right - GuiData->Selection.srSelection.Left + 1;
selHeight = GuiData->Selection.srSelection.Bottom - GuiData->Selection.srSelection.Top + 1;
DPRINT1("Selection is (%d|%d) to (%d|%d)\n",
Console->Selection.srSelection.Left,
Console->Selection.srSelection.Top,
Console->Selection.srSelection.Right,
Console->Selection.srSelection.Bottom);
GuiData->Selection.srSelection.Left,
GuiData->Selection.srSelection.Top,
GuiData->Selection.srSelection.Right,
GuiData->Selection.srSelection.Bottom);
hMemDC = CreateCompatibleDC(GuiData->hMemDC);
if (hMemDC == NULL) return;
@ -74,8 +72,8 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
StretchDIBits(hMemDC,
0, 0,
selWidth, selHeight,
Console->Selection.srSelection.Left,
Console->Selection.srSelection.Top,
GuiData->Selection.srSelection.Left,
GuiData->Selection.srSelection.Top,
selWidth, selHeight,
Buffer->BitMap,
Buffer->BitMapInfo,
@ -87,8 +85,8 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
0, 0,
selWidth, selHeight,
/* Coordinates / size of the corresponding image portion, in the graphics screen-buffer's frame */
Console->Selection.srSelection.Left,
Console->Selection.srSelection.Top,
GuiData->Selection.srSelection.Left,
GuiData->Selection.srSelection.Top,
0,
Buffer->ScreenBufferSize.Y, // == Buffer->BitMapInfo->bmiHeader.biHeight
Buffer->BitMap,
@ -128,8 +126,13 @@ GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
PRECT rcView,
PRECT rcFramebuffer)
{
PCONSOLE Console = Buffer->Header.Console;
// ASSERT(Console == GuiData->Console);
if (Buffer->BitMap == NULL) return;
if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
rcFramebuffer->left = Buffer->ViewOrigin.X * 1 + rcView->left;
rcFramebuffer->top = Buffer->ViewOrigin.Y * 1 + rcView->top;
rcFramebuffer->right = Buffer->ViewOrigin.X * 1 + rcView->right;
@ -160,6 +163,8 @@ GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
/* Release the mutex */
NtReleaseMutant(Buffer->Mutex, NULL);
LeaveCriticalSection(&Console->Lock);
}
/* EOF */

View file

@ -238,6 +238,8 @@ GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
DPRINT("GuiConsoleShowConsoleProperties entered\n");
if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
/*
* Create a memory section to share with the applet, and map it.
*/
@ -253,7 +255,7 @@ GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to create a shared section ; Status = %lu\n", Status);
return;
goto Quit;
}
Status = NtMapViewOfSection(hSection,
@ -269,8 +271,7 @@ GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n", Status);
NtClose(hSection);
return;
goto Quit;
}
@ -408,11 +409,13 @@ GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
Quit:
/* We have finished, close the section handle */
NtClose(hSection);
if (hSection) NtClose(hSection);
LeaveCriticalSection(&Console->Lock);
return;
}
NTSTATUS
VOID
GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
HANDLE hClientSection,
BOOL SaveSettings)
@ -427,6 +430,8 @@ GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
PTERMINAL_INFO TermInfo = NULL;
PGUI_CONSOLE_INFO GuiInfo = NULL;
if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
/* Get the console leader process, our client */
ProcessData = ConDrvGetConsoleLeaderProcess(Console);
@ -439,7 +444,7 @@ GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
if (!NT_SUCCESS(Status))
{
DPRINT1("Error when mapping client handle, Status = %lu\n", Status);
return Status;
goto Quit;
}
/* Get a view of the shared section */
@ -456,8 +461,7 @@ GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
if (!NT_SUCCESS(Status))
{
DPRINT1("Error when mapping view of file, Status = %lu\n", Status);
NtClose(hSection);
return Status;
goto Quit;
}
_SEH2_TRY
@ -530,9 +534,14 @@ GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
Quit:
/* Finally, close the section and return */
NtUnmapViewOfSection(NtCurrentProcess(), pConInfo);
NtClose(hSection);
return Status;
if (hSection)
{
NtUnmapViewOfSection(NtCurrentProcess(), pConInfo);
NtClose(hSection);
}
LeaveCriticalSection(&Console->Lock);
return;
}
/* EOF */

View file

@ -55,7 +55,7 @@ GuiConsoleGetDefaultSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
VOID
GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
BOOL Defaults);
NTSTATUS
VOID
GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
HANDLE hClientSection,
BOOL SaveSettings);

View file

@ -532,6 +532,10 @@ GuiInitFrontEnd(IN OUT PFRONTEND This,
/* There is no user-reserved menu id range by default */
GuiData->CmdIdLow = GuiData->CmdIdHigh = 0;
/* Initialize the selection */
RtlZeroMemory(&GuiData->Selection, sizeof(CONSOLE_SELECTION_INFO));
GuiData->Selection.dwFlags = CONSOLE_NO_SELECTION;
/*
* We need to wait until the GUI has been fully initialized
* to retrieve custom settings i.e. WindowSize etc...
@ -938,6 +942,21 @@ GuiGetLargestConsoleWindowSize(IN OUT PFRONTEND This,
pSize->Y = (SHORT)(height / (int)HeightUnit) /* HACK */ + 1;
}
static BOOL NTAPI
GuiGetSelectionInfo(IN OUT PFRONTEND This,
PCONSOLE_SELECTION_INFO pSelectionInfo)
{
PGUI_CONSOLE_DATA GuiData = This->Data;
if (pSelectionInfo == NULL) return FALSE;
ZeroMemory(pSelectionInfo, sizeof(CONSOLE_SELECTION_INFO));
if (GuiData->Selection.dwFlags != CONSOLE_NO_SELECTION)
RtlCopyMemory(pSelectionInfo, &GuiData->Selection, sizeof(CONSOLE_SELECTION_INFO));
return TRUE;
}
static BOOL NTAPI
GuiSetPalette(IN OUT PFRONTEND This,
HPALETTE PaletteHandle,
@ -1084,6 +1103,7 @@ static FRONTEND_VTBL GuiVtbl =
GuiChangeIcon,
GuiGetConsoleWindowHandle,
GuiGetLargestConsoleWindowSize,
GuiGetSelectionInfo,
GuiSetPalette,
GuiGetDisplayMode,
GuiSetDisplayMode,

View file

@ -20,7 +20,7 @@
/* FUNCTIONS ******************************************************************/
COLORREF RGBFromAttrib2(PCONSOLE Console, WORD Attribute)
COLORREF PaletteRGBFromAttrib(PCONSOLE Console, WORD Attribute)
{
HPALETTE hPalette = Console->ActiveBuffer->PaletteHandle;
PALETTEENTRY pe;
@ -39,8 +39,6 @@ GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
* This function supposes that the system clipboard was opened.
*/
PCONSOLE Console = Buffer->Header.Console;
/*
* Pressing the Shift key while copying text, allows us to copy
* text without newline characters (inline-text copy mode).
@ -53,13 +51,13 @@ GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
ULONG selWidth, selHeight;
ULONG xPos, yPos, size;
selWidth = Console->Selection.srSelection.Right - Console->Selection.srSelection.Left + 1;
selHeight = Console->Selection.srSelection.Bottom - Console->Selection.srSelection.Top + 1;
selWidth = GuiData->Selection.srSelection.Right - GuiData->Selection.srSelection.Left + 1;
selHeight = GuiData->Selection.srSelection.Bottom - GuiData->Selection.srSelection.Top + 1;
DPRINT("Selection is (%d|%d) to (%d|%d)\n",
Console->Selection.srSelection.Left,
Console->Selection.srSelection.Top,
Console->Selection.srSelection.Right,
Console->Selection.srSelection.Bottom);
GuiData->Selection.srSelection.Left,
GuiData->Selection.srSelection.Top,
GuiData->Selection.srSelection.Right,
GuiData->Selection.srSelection.Bottom);
#ifdef IS_WHITESPACE
#undef IS_WHITESPACE
@ -99,8 +97,8 @@ GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
ULONG length = selWidth;
ptr = ConioCoordToPointer(Buffer,
Console->Selection.srSelection.Left,
Console->Selection.srSelection.Top + yPos);
GuiData->Selection.srSelection.Left,
GuiData->Selection.srSelection.Top + yPos);
/* Trim whitespace from the right */
while (length > 0)
@ -230,6 +228,8 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
if (Buffer->Buffer == NULL) return;
if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
rcFramebuffer->left = Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->left;
rcFramebuffer->top = Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->top;
rcFramebuffer->right = Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->right;
@ -245,8 +245,8 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
LastAttribute = ConioCoordToPointer(Buffer, LeftChar, TopLine)->Attributes;
SetTextColor(GuiData->hMemDC, RGBFromAttrib2(Console, TextAttribFromAttrib(LastAttribute)));
SetBkColor(GuiData->hMemDC, RGBFromAttrib2(Console, BkgdAttribFromAttrib(LastAttribute)));
SetTextColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute)));
SetBkColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute)));
OldFont = SelectObject(GuiData->hMemDC, GuiData->Font);
@ -275,8 +275,8 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
Attribute = From->Attributes;
if (Attribute != LastAttribute)
{
SetTextColor(GuiData->hMemDC, RGBFromAttrib2(Console, TextAttribFromAttrib(Attribute)));
SetBkColor(GuiData->hMemDC, RGBFromAttrib2(Console, BkgdAttribFromAttrib(Attribute)));
SetTextColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, TextAttribFromAttrib(Attribute)));
SetBkColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, BkgdAttribFromAttrib(Attribute)));
LastAttribute = Attribute;
}
}
@ -308,7 +308,7 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
Attribute = ConioCoordToPointer(Buffer, Buffer->CursorPosition.X, Buffer->CursorPosition.Y)->Attributes;
if (Attribute == DEFAULT_SCREEN_ATTRIB) Attribute = Buffer->ScreenDefaultAttrib;
CursorBrush = CreateSolidBrush(RGBFromAttrib2(Console, TextAttribFromAttrib(Attribute)));
CursorBrush = CreateSolidBrush(PaletteRGBFromAttrib(Console, TextAttribFromAttrib(Attribute)));
OldBrush = SelectObject(GuiData->hMemDC, CursorBrush);
PatBlt(GuiData->hMemDC,
@ -323,6 +323,8 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
}
SelectObject(GuiData->hMemDC, OldFont);
LeaveCriticalSection(&Console->Lock);
}
/* EOF */

View file

@ -746,6 +746,13 @@ TuiGetLargestConsoleWindowSize(IN OUT PFRONTEND This,
*pSize = PhysicalConsoleSize;
}
static BOOL NTAPI
TuiGetSelectionInfo(IN OUT PFRONTEND This,
PCONSOLE_SELECTION_INFO pSelectionInfo)
{
return TRUE;
}
static BOOL NTAPI
TuiSetPalette(IN OUT PFRONTEND This,
HPALETTE PaletteHandle,
@ -813,6 +820,7 @@ static FRONTEND_VTBL TuiVtbl =
TuiChangeIcon,
TuiGetConsoleWindowHandle,
TuiGetLargestConsoleWindowSize,
TuiGetSelectionInfo,
TuiSetPalette,
TuiGetDisplayMode,
TuiSetDisplayMode,

View file

@ -228,6 +228,8 @@ typedef struct _FRONTEND_VTBL
HWND (NTAPI *GetConsoleWindowHandle)(IN OUT PFRONTEND This);
VOID (NTAPI *GetLargestConsoleWindowSize)(IN OUT PFRONTEND This,
PCOORD pSize);
BOOL (NTAPI *GetSelectionInfo)(IN OUT PFRONTEND This,
PCONSOLE_SELECTION_INFO pSelectionInfo);
BOOL (NTAPI *SetPalette)(IN OUT PFRONTEND This,
HPALETTE PaletteHandle,
UINT PaletteUsage);
@ -305,9 +307,6 @@ typedef struct _CONSOLE
BOOLEAN InsertMode;
UINT CodePage;
CONSOLE_SELECTION_INFO Selection; /* Contains information about the selection */
COORD dwSelectionCursor; /* Selection cursor position, most of the time different from Selection.dwSelectionAnchor */
/******************************* Screen buffers *******************************/
LIST_ENTRY BufferList; /* List of all screen buffers for this console */
PCONSOLE_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */

View file

@ -38,6 +38,8 @@
(Console)->TermIFace.Vtbl->GetConsoleWindowHandle(&(Console)->TermIFace)
#define TermGetLargestConsoleWindowSize(Console, pSize) \
(Console)->TermIFace.Vtbl->GetLargestConsoleWindowSize(&(Console)->TermIFace, (pSize))
#define TermGetSelectionInfo(Console, pSelectionInfo) \
(Console)->TermIFace.Vtbl->GetSelectionInfo(&(Console)->TermIFace, (pSelectionInfo))
#define TermSetPalette(Console, PaletteHandle, PaletteUsage) \
(Console)->TermIFace.Vtbl->SetPalette(&(Console)->TermIFace, (PaletteHandle), (PaletteUsage))
#define TermGetDisplayMode(Console) \