Skip to content

Commit 858c7e6

Browse files
committed
[CONSRV]
- Fix console selection and selection mode text that displays in the console title: - Correctly set selection flags; - Ignore the first mouse event when the console is being activated with the mouse, when we are in "QuickEdit" mode (avoids e.g. an erroneous paste if somebody right-clicks on the console); gather the console window position to consistently update GuiData->GuiInfo.WindowOrigin (needed when console properties are displayed). svn path=/trunk/; revision=62739
1 parent 4496c73 commit 858c7e6

File tree

1 file changed

+120
-57
lines changed
  • reactos/win32ss/user/winsrv/consrv/frontends/gui

1 file changed

+120
-57
lines changed

reactos/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c

Lines changed: 120 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "resource.h"
2525

2626
/* GUI Console Window Class name */
27-
#define GUI_CONSOLE_WINDOW_CLASS L"ConsoleWindowClass"
27+
#define GUI_CONWND_CLASS L"ConsoleWindowClass"
2828

2929
#ifndef WM_APP
3030
#define WM_APP 0x8000
@@ -277,22 +277,16 @@ GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM
277277
{
278278
case ID_SYSTEM_EDIT_MARK:
279279
{
280-
LPWSTR WindowTitle = NULL;
281-
SIZE_T Length = 0;
280+
/* Clear the old selection */
281+
// GuiConsoleUpdateSelection(Console, NULL);
282+
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
282283

284+
/* Restart a new selection */
283285
Console->dwSelectionCursor.X = ActiveBuffer->ViewOrigin.X;
284286
Console->dwSelectionCursor.Y = ActiveBuffer->ViewOrigin.Y;
285287
Console->Selection.dwSelectionAnchor = Console->dwSelectionCursor;
286-
Console->Selection.dwFlags |= CONSOLE_SELECTION_IN_PROGRESS;
287288
GuiConsoleUpdateSelection(Console, &Console->Selection.dwSelectionAnchor);
288289

289-
Length = Console->Title.Length + sizeof(L"Mark - ")/sizeof(WCHAR) + 1;
290-
WindowTitle = ConsoleAllocHeap(0, Length * sizeof(WCHAR));
291-
wcscpy(WindowTitle, L"Mark - ");
292-
wcscat(WindowTitle, Console->Title.Buffer);
293-
SetWindowText(GuiData->hWindow, WindowTitle);
294-
ConsoleFreeHeap(WindowTitle);
295-
296290
break;
297291
}
298292

@@ -306,8 +300,9 @@ GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM
306300

307301
case ID_SYSTEM_EDIT_SELECTALL:
308302
{
309-
LPWSTR WindowTitle = NULL;
310-
SIZE_T Length = 0;
303+
/* Clear the old selection */
304+
// GuiConsoleUpdateSelection(Console, NULL);
305+
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
311306

312307
/*
313308
* The selection area extends to the whole screen buffer's width.
@@ -337,16 +332,10 @@ GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM
337332
Console->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
338333
}
339334

340-
Console->Selection.dwFlags |= CONSOLE_SELECTION_IN_PROGRESS | CONSOLE_MOUSE_SELECTION;
335+
/* Restart a new selection */
336+
Console->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION;
341337
GuiConsoleUpdateSelection(Console, &Console->dwSelectionCursor);
342338

343-
Length = Console->Title.Length + sizeof(L"Selection - ")/sizeof(WCHAR) + 1;
344-
WindowTitle = ConsoleAllocHeap(0, Length * sizeof(WCHAR));
345-
wcscpy(WindowTitle, L"Selection - ");
346-
wcscat(WindowTitle, Console->Title.Buffer);
347-
SetWindowText(GuiData->hWindow, WindowTitle);
348-
ConsoleFreeHeap(WindowTitle);
349-
350339
break;
351340
}
352341

@@ -579,14 +568,16 @@ static VOID
579568
GuiConsoleUpdateSelection(PCONSOLE Console, PCOORD coord)
580569
{
581570
PGUI_CONSOLE_DATA GuiData = Console->TermIFace.Data;
582-
RECT oldRect, newRect;
571+
RECT oldRect;
583572

584573
SmallRectToRect(GuiData, &oldRect, &Console->Selection.srSelection);
585574

586575
if (coord != NULL)
587576
{
577+
RECT newRect;
588578
SMALL_RECT rc;
589-
/* exchange left/top with right/bottom if required */
579+
580+
/* Exchange left/top with right/bottom if required */
590581
rc.Left = min(Console->Selection.dwSelectionAnchor.X, coord->X);
591582
rc.Top = min(Console->Selection.dwSelectionAnchor.Y, coord->Y);
592583
rc.Right = max(Console->Selection.dwSelectionAnchor.X, coord->X);
@@ -600,7 +591,7 @@ GuiConsoleUpdateSelection(PCONSOLE Console, PCOORD coord)
600591
{
601592
HRGN rgn1, rgn2;
602593

603-
/* calculate the region that needs to be updated */
594+
/* Calculate the region that needs to be updated */
604595
if ((rgn1 = CreateRectRgnIndirect(&oldRect)))
605596
{
606597
if ((rgn2 = CreateRectRgnIndirect(&newRect)))
@@ -619,20 +610,54 @@ GuiConsoleUpdateSelection(PCONSOLE Console, PCOORD coord)
619610
{
620611
InvalidateRect(GuiData->hWindow, &newRect, FALSE);
621612
}
613+
622614
Console->Selection.dwFlags |= CONSOLE_SELECTION_NOT_EMPTY;
623615
Console->Selection.srSelection = rc;
624616
Console->dwSelectionCursor = *coord;
625-
ConioPause(Console, PAUSED_FROM_SELECTION);
617+
618+
if ((Console->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) == 0)
619+
{
620+
LPWSTR SelectionType, WindowTitle = NULL;
621+
SIZE_T Length = 0;
622+
623+
/* Clear the old selection */
624+
if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
625+
{
626+
InvalidateRect(GuiData->hWindow, &oldRect, FALSE);
627+
}
628+
629+
if (Console->Selection.dwFlags & CONSOLE_MOUSE_SELECTION)
630+
{
631+
SelectionType = L"Selection - ";
632+
}
633+
else
634+
{
635+
SelectionType = L"Mark - ";
636+
}
637+
638+
Length = Console->Title.Length + wcslen(SelectionType) + 1;
639+
WindowTitle = ConsoleAllocHeap(0, Length * sizeof(WCHAR));
640+
wcscpy(WindowTitle, SelectionType);
641+
wcscat(WindowTitle, Console->Title.Buffer);
642+
SetWindowText(GuiData->hWindow, WindowTitle);
643+
ConsoleFreeHeap(WindowTitle);
644+
645+
Console->Selection.dwFlags |= CONSOLE_SELECTION_IN_PROGRESS;
646+
ConioPause(Console, PAUSED_FROM_SELECTION);
647+
}
626648
}
627649
else
628650
{
629-
/* clear the selection */
651+
/* Clear the selection */
630652
if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)
631653
{
632654
InvalidateRect(GuiData->hWindow, &oldRect, FALSE);
633655
}
656+
634657
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
635658
ConioUnpause(Console, PAUSED_FROM_SELECTION);
659+
660+
SetWindowText(GuiData->hWindow, Console->Title.Buffer);
636661
}
637662
}
638663

@@ -768,8 +793,6 @@ GuiConsoleHandleKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM l
768793
{
769794
/* Cancel selection if ESC or Ctrl-C are pressed */
770795
GuiConsoleUpdateSelection(Console, NULL);
771-
SetWindowText(GuiData->hWindow, Console->Title.Buffer);
772-
773796
goto Quit;
774797
}
775798

@@ -879,7 +902,6 @@ GuiConsoleHandleKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM l
879902
{
880903
/* Clear the selection and send the key into the input buffer */
881904
GuiConsoleUpdateSelection(Console, NULL);
882-
SetWindowText(GuiData->hWindow, Console->Title.Buffer);
883905
}
884906
else
885907
{
@@ -1096,18 +1118,19 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
10961118
{
10971119
if (msg != WM_LBUTTONDOWN &&
10981120
msg != WM_MBUTTONDOWN &&
1099-
msg != WM_RBUTTONDOWN)
1121+
msg != WM_RBUTTONDOWN &&
1122+
msg != WM_MOUSEMOVE)
11001123
{
11011124
/*
1102-
* If this mouse signal is not a button-down action,
1125+
* If this mouse signal is not a button-down action or a move,
11031126
* then it is the last signal being ignored.
11041127
*/
11051128
GuiData->IgnoreNextMouseSignal = FALSE;
11061129
}
11071130
else
11081131
{
11091132
/*
1110-
* This mouse signal is a button-down action.
1133+
* This mouse signal is a button-down action or a move.
11111134
* Ignore it and perform default action.
11121135
*/
11131136
Err = TRUE;
@@ -1128,33 +1151,28 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
11281151
{
11291152
case WM_LBUTTONDOWN:
11301153
{
1131-
LPWSTR WindowTitle = NULL;
1132-
SIZE_T Length = 0;
1154+
/* Clear the old selection */
1155+
// GuiConsoleUpdateSelection(Console, NULL);
1156+
Console->Selection.dwFlags = CONSOLE_NO_SELECTION;
11331157

1158+
/* Restart a new selection */
11341159
Console->Selection.dwSelectionAnchor = PointToCoord(GuiData, lParam);
11351160
SetCapture(GuiData->hWindow);
1136-
Console->Selection.dwFlags |= CONSOLE_SELECTION_IN_PROGRESS | CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN;
1161+
Console->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN;
11371162
GuiConsoleUpdateSelection(Console, &Console->Selection.dwSelectionAnchor);
11381163

1139-
Length = Console->Title.Length + sizeof(L"Selection - ")/sizeof(WCHAR) + 1;
1140-
WindowTitle = ConsoleAllocHeap(0, Length * sizeof(WCHAR));
1141-
wcscpy(WindowTitle, L"Selection - ");
1142-
wcscat(WindowTitle, Console->Title.Buffer);
1143-
SetWindowText(GuiData->hWindow, WindowTitle);
1144-
ConsoleFreeHeap(WindowTitle);
1145-
11461164
break;
11471165
}
11481166

11491167
case WM_LBUTTONUP:
11501168
{
1151-
COORD c;
1169+
// COORD c;
11521170

11531171
if (!(Console->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) break;
11541172

1155-
c = PointToCoord(GuiData, lParam);
1173+
// c = PointToCoord(GuiData, lParam);
11561174
Console->Selection.dwFlags &= ~CONSOLE_MOUSE_DOWN;
1157-
GuiConsoleUpdateSelection(Console, &c);
1175+
// GuiConsoleUpdateSelection(Console, &c);
11581176
ReleaseCapture();
11591177

11601178
break;
@@ -1166,6 +1184,9 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
11661184

11671185
if (GetType(Buffer) == TEXTMODE_BUFFER)
11681186
{
1187+
#ifdef IS_WHITESPACE
1188+
#undef IS_WHITESPACE
1189+
#endif
11691190
#define IS_WHITESPACE(c) \
11701191
((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')
11711192

@@ -1192,10 +1213,19 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
11921213
++ptrR;
11931214
}
11941215

1216+
/*
1217+
* Update the selection started with the single
1218+
* left-click that preceded this double-click.
1219+
*/
11951220
Console->Selection.dwSelectionAnchor = cL;
11961221
Console->dwSelectionCursor = cR;
11971222

1223+
SetCapture(GuiData->hWindow);
1224+
Console->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN;
11981225
GuiConsoleUpdateSelection(Console, &Console->dwSelectionCursor);
1226+
1227+
/* Ignore the next mouse move signal */
1228+
GuiData->IgnoreNextMouseSignal = TRUE;
11991229
}
12001230

12011231
break;
@@ -1213,6 +1243,7 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
12131243
GuiConsoleCopy(GuiData);
12141244
}
12151245

1246+
/* Ignore the next mouse move signal */
12161247
GuiData->IgnoreNextMouseSignal = TRUE;
12171248
break;
12181249
}
@@ -1378,9 +1409,10 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
13781409
static VOID
13791410
GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData)
13801411
{
1412+
PCONSOLE Console = GuiData->Console;
1413+
13811414
if (OpenClipboard(GuiData->hWindow) == TRUE)
13821415
{
1383-
PCONSOLE Console = GuiData->Console;
13841416
PCONSOLE_SCREEN_BUFFER Buffer = GuiData->ActiveBuffer;
13851417

13861418
if (GetType(Buffer) == TEXTMODE_BUFFER)
@@ -1393,11 +1425,10 @@ GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData)
13931425
}
13941426

13951427
CloseClipboard();
1396-
1397-
/* Clear the selection */
1398-
GuiConsoleUpdateSelection(Console, NULL);
1399-
SetWindowText(GuiData->hWindow, Console->Title.Buffer);
14001428
}
1429+
1430+
/* Clear the selection */
1431+
GuiConsoleUpdateSelection(Console, NULL);
14011432
}
14021433

14031434
VOID
@@ -1739,7 +1770,14 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
17391770
}
17401771
}
17411772

1742-
if (ActivationState == WA_CLICKACTIVE) GuiData->IgnoreNextMouseSignal = TRUE;
1773+
/*
1774+
* When we are in QuickEdit mode, ignore the next mouse signal
1775+
* when we are going to be enabled again via the mouse, in order
1776+
* to prevent e.g. an erroneous right-click from the user which
1777+
* would have as an effect to paste some unwanted text...
1778+
*/
1779+
if (Console->QuickEdit && (ActivationState == WA_CLICKACTIVE))
1780+
GuiData->IgnoreNextMouseSignal = TRUE;
17431781

17441782
break;
17451783
}
@@ -1752,6 +1790,10 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
17521790
GuiConsoleHandlePaint(GuiData);
17531791
break;
17541792

1793+
case WM_TIMER:
1794+
GuiConsoleHandleTimer(GuiData);
1795+
break;
1796+
17551797
case WM_PALETTECHANGED:
17561798
{
17571799
PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
@@ -1815,10 +1857,6 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
18151857
break;
18161858
}
18171859

1818-
case WM_TIMER:
1819-
GuiConsoleHandleTimer(GuiData);
1820-
break;
1821-
18221860
case WM_SETCURSOR:
18231861
{
18241862
/*
@@ -2013,6 +2051,25 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
20132051
GuiConsoleGetMinMaxInfo(GuiData, (PMINMAXINFO)lParam);
20142052
break;
20152053

2054+
case WM_MOVE:
2055+
{
2056+
if (ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE))
2057+
{
2058+
// TODO: Simplify the code.
2059+
// See: GuiConsoleNotifyWndProc() PM_CREATE_CONSOLE.
2060+
2061+
RECT rcWnd;
2062+
2063+
/* Retrieve our real position */
2064+
GetWindowRect(GuiData->hWindow, &rcWnd);
2065+
GuiData->GuiInfo.WindowOrigin.x = rcWnd.left;
2066+
GuiData->GuiInfo.WindowOrigin.y = rcWnd.top;
2067+
2068+
LeaveCriticalSection(&Console->Lock);
2069+
}
2070+
break;
2071+
}
2072+
20162073
case WM_SIZE:
20172074
GuiConsoleResize(GuiData, wParam, lParam);
20182075
break;
@@ -2101,9 +2158,10 @@ GuiConsoleNotifyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
21012158
{
21022159
PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA)lParam;
21032160
PCONSOLE Console = GuiData->Console;
2161+
RECT rcWnd;
21042162

21052163
NewWindow = CreateWindowExW(WS_EX_CLIENTEDGE,
2106-
GUI_CONSOLE_WINDOW_CLASS,
2164+
GUI_CONWND_CLASS,
21072165
Console->Title.Buffer,
21082166
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
21092167
CW_USEDEFAULT,
@@ -2136,6 +2194,11 @@ GuiConsoleNotifyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
21362194
SendMessageW(GuiData->hWindow, WM_SETICON, ICON_SMALL, (LPARAM)GuiData->hIconSm);
21372195
}
21382196

2197+
/* Retrieve our real position */
2198+
GetWindowRect(GuiData->hWindow, &rcWnd);
2199+
GuiData->GuiInfo.WindowOrigin.x = rcWnd.left;
2200+
GuiData->GuiInfo.WindowOrigin.y = rcWnd.top;
2201+
21392202
/* Move and resize the window to the user's values */
21402203
/* CAN WE DEADLOCK ?? */
21412204
GuiConsoleMoveWindow(GuiData);
@@ -2289,7 +2352,7 @@ GuiInit(VOID)
22892352
LR_SHARED);
22902353
ghDefaultCursor = LoadCursorW(NULL, IDC_ARROW);
22912354
wc.cbSize = sizeof(WNDCLASSEXW);
2292-
wc.lpszClassName = GUI_CONSOLE_WINDOW_CLASS;
2355+
wc.lpszClassName = GUI_CONWND_CLASS;
22932356
wc.lpfnWndProc = GuiConsoleWndProc;
22942357
wc.style = CS_DBLCLKS /* | CS_HREDRAW | CS_VREDRAW */;
22952358
wc.hInstance = ConSrvDllInstance;

0 commit comments

Comments
 (0)