24
24
#include "resource.h"
25
25
26
26
/* GUI Console Window Class name */
27
- #define GUI_CONSOLE_WINDOW_CLASS L"ConsoleWindowClass"
27
+ #define GUI_CONWND_CLASS L"ConsoleWindowClass"
28
28
29
29
#ifndef WM_APP
30
30
#define WM_APP 0x8000
@@ -277,22 +277,16 @@ GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM
277
277
{
278
278
case ID_SYSTEM_EDIT_MARK :
279
279
{
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 ;
282
283
284
+ /* Restart a new selection */
283
285
Console -> dwSelectionCursor .X = ActiveBuffer -> ViewOrigin .X ;
284
286
Console -> dwSelectionCursor .Y = ActiveBuffer -> ViewOrigin .Y ;
285
287
Console -> Selection .dwSelectionAnchor = Console -> dwSelectionCursor ;
286
- Console -> Selection .dwFlags |= CONSOLE_SELECTION_IN_PROGRESS ;
287
288
GuiConsoleUpdateSelection (Console , & Console -> Selection .dwSelectionAnchor );
288
289
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
-
296
290
break ;
297
291
}
298
292
@@ -306,8 +300,9 @@ GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM
306
300
307
301
case ID_SYSTEM_EDIT_SELECTALL :
308
302
{
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 ;
311
306
312
307
/*
313
308
* The selection area extends to the whole screen buffer's width.
@@ -337,16 +332,10 @@ GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM
337
332
Console -> dwSelectionCursor .Y = ActiveBuffer -> ScreenBufferSize .Y - 1 ;
338
333
}
339
334
340
- Console -> Selection .dwFlags |= CONSOLE_SELECTION_IN_PROGRESS | CONSOLE_MOUSE_SELECTION ;
335
+ /* Restart a new selection */
336
+ Console -> Selection .dwFlags |= CONSOLE_MOUSE_SELECTION ;
341
337
GuiConsoleUpdateSelection (Console , & Console -> dwSelectionCursor );
342
338
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
-
350
339
break ;
351
340
}
352
341
@@ -579,14 +568,16 @@ static VOID
579
568
GuiConsoleUpdateSelection (PCONSOLE Console , PCOORD coord )
580
569
{
581
570
PGUI_CONSOLE_DATA GuiData = Console -> TermIFace .Data ;
582
- RECT oldRect , newRect ;
571
+ RECT oldRect ;
583
572
584
573
SmallRectToRect (GuiData , & oldRect , & Console -> Selection .srSelection );
585
574
586
575
if (coord != NULL )
587
576
{
577
+ RECT newRect ;
588
578
SMALL_RECT rc ;
589
- /* exchange left/top with right/bottom if required */
579
+
580
+ /* Exchange left/top with right/bottom if required */
590
581
rc .Left = min (Console -> Selection .dwSelectionAnchor .X , coord -> X );
591
582
rc .Top = min (Console -> Selection .dwSelectionAnchor .Y , coord -> Y );
592
583
rc .Right = max (Console -> Selection .dwSelectionAnchor .X , coord -> X );
@@ -600,7 +591,7 @@ GuiConsoleUpdateSelection(PCONSOLE Console, PCOORD coord)
600
591
{
601
592
HRGN rgn1 , rgn2 ;
602
593
603
- /* calculate the region that needs to be updated */
594
+ /* Calculate the region that needs to be updated */
604
595
if ((rgn1 = CreateRectRgnIndirect (& oldRect )))
605
596
{
606
597
if ((rgn2 = CreateRectRgnIndirect (& newRect )))
@@ -619,20 +610,54 @@ GuiConsoleUpdateSelection(PCONSOLE Console, PCOORD coord)
619
610
{
620
611
InvalidateRect (GuiData -> hWindow , & newRect , FALSE);
621
612
}
613
+
622
614
Console -> Selection .dwFlags |= CONSOLE_SELECTION_NOT_EMPTY ;
623
615
Console -> Selection .srSelection = rc ;
624
616
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
+ }
626
648
}
627
649
else
628
650
{
629
- /* clear the selection */
651
+ /* Clear the selection */
630
652
if (Console -> Selection .dwFlags & CONSOLE_SELECTION_NOT_EMPTY )
631
653
{
632
654
InvalidateRect (GuiData -> hWindow , & oldRect , FALSE);
633
655
}
656
+
634
657
Console -> Selection .dwFlags = CONSOLE_NO_SELECTION ;
635
658
ConioUnpause (Console , PAUSED_FROM_SELECTION );
659
+
660
+ SetWindowText (GuiData -> hWindow , Console -> Title .Buffer );
636
661
}
637
662
}
638
663
@@ -768,8 +793,6 @@ GuiConsoleHandleKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM l
768
793
{
769
794
/* Cancel selection if ESC or Ctrl-C are pressed */
770
795
GuiConsoleUpdateSelection (Console , NULL );
771
- SetWindowText (GuiData -> hWindow , Console -> Title .Buffer );
772
-
773
796
goto Quit ;
774
797
}
775
798
@@ -879,7 +902,6 @@ GuiConsoleHandleKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM l
879
902
{
880
903
/* Clear the selection and send the key into the input buffer */
881
904
GuiConsoleUpdateSelection (Console , NULL );
882
- SetWindowText (GuiData -> hWindow , Console -> Title .Buffer );
883
905
}
884
906
else
885
907
{
@@ -1096,18 +1118,19 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
1096
1118
{
1097
1119
if (msg != WM_LBUTTONDOWN &&
1098
1120
msg != WM_MBUTTONDOWN &&
1099
- msg != WM_RBUTTONDOWN )
1121
+ msg != WM_RBUTTONDOWN &&
1122
+ msg != WM_MOUSEMOVE )
1100
1123
{
1101
1124
/*
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 ,
1103
1126
* then it is the last signal being ignored.
1104
1127
*/
1105
1128
GuiData -> IgnoreNextMouseSignal = FALSE;
1106
1129
}
1107
1130
else
1108
1131
{
1109
1132
/*
1110
- * This mouse signal is a button-down action.
1133
+ * This mouse signal is a button-down action or a move .
1111
1134
* Ignore it and perform default action.
1112
1135
*/
1113
1136
Err = TRUE;
@@ -1128,33 +1151,28 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
1128
1151
{
1129
1152
case WM_LBUTTONDOWN :
1130
1153
{
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 ;
1133
1157
1158
+ /* Restart a new selection */
1134
1159
Console -> Selection .dwSelectionAnchor = PointToCoord (GuiData , lParam );
1135
1160
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 ;
1137
1162
GuiConsoleUpdateSelection (Console , & Console -> Selection .dwSelectionAnchor );
1138
1163
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
-
1146
1164
break ;
1147
1165
}
1148
1166
1149
1167
case WM_LBUTTONUP :
1150
1168
{
1151
- COORD c ;
1169
+ // COORD c;
1152
1170
1153
1171
if (!(Console -> Selection .dwFlags & CONSOLE_MOUSE_DOWN )) break ;
1154
1172
1155
- c = PointToCoord (GuiData , lParam );
1173
+ // c = PointToCoord(GuiData, lParam);
1156
1174
Console -> Selection .dwFlags &= ~CONSOLE_MOUSE_DOWN ;
1157
- GuiConsoleUpdateSelection (Console , & c );
1175
+ // GuiConsoleUpdateSelection(Console, &c);
1158
1176
ReleaseCapture ();
1159
1177
1160
1178
break ;
@@ -1166,6 +1184,9 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
1166
1184
1167
1185
if (GetType (Buffer ) == TEXTMODE_BUFFER )
1168
1186
{
1187
+ #ifdef IS_WHITESPACE
1188
+ #undef IS_WHITESPACE
1189
+ #endif
1169
1190
#define IS_WHITESPACE (c ) \
1170
1191
((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')
1171
1192
@@ -1192,10 +1213,19 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
1192
1213
++ ptrR ;
1193
1214
}
1194
1215
1216
+ /*
1217
+ * Update the selection started with the single
1218
+ * left-click that preceded this double-click.
1219
+ */
1195
1220
Console -> Selection .dwSelectionAnchor = cL ;
1196
1221
Console -> dwSelectionCursor = cR ;
1197
1222
1223
+ SetCapture (GuiData -> hWindow );
1224
+ Console -> Selection .dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN ;
1198
1225
GuiConsoleUpdateSelection (Console , & Console -> dwSelectionCursor );
1226
+
1227
+ /* Ignore the next mouse move signal */
1228
+ GuiData -> IgnoreNextMouseSignal = TRUE;
1199
1229
}
1200
1230
1201
1231
break ;
@@ -1213,6 +1243,7 @@ GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
1213
1243
GuiConsoleCopy (GuiData );
1214
1244
}
1215
1245
1246
+ /* Ignore the next mouse move signal */
1216
1247
GuiData -> IgnoreNextMouseSignal = TRUE;
1217
1248
break ;
1218
1249
}
@@ -1378,9 +1409,10 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
1378
1409
static VOID
1379
1410
GuiConsoleCopy (PGUI_CONSOLE_DATA GuiData )
1380
1411
{
1412
+ PCONSOLE Console = GuiData -> Console ;
1413
+
1381
1414
if (OpenClipboard (GuiData -> hWindow ) == TRUE)
1382
1415
{
1383
- PCONSOLE Console = GuiData -> Console ;
1384
1416
PCONSOLE_SCREEN_BUFFER Buffer = GuiData -> ActiveBuffer ;
1385
1417
1386
1418
if (GetType (Buffer ) == TEXTMODE_BUFFER )
@@ -1393,11 +1425,10 @@ GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData)
1393
1425
}
1394
1426
1395
1427
CloseClipboard ();
1396
-
1397
- /* Clear the selection */
1398
- GuiConsoleUpdateSelection (Console , NULL );
1399
- SetWindowText (GuiData -> hWindow , Console -> Title .Buffer );
1400
1428
}
1429
+
1430
+ /* Clear the selection */
1431
+ GuiConsoleUpdateSelection (Console , NULL );
1401
1432
}
1402
1433
1403
1434
VOID
@@ -1739,7 +1770,14 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1739
1770
}
1740
1771
}
1741
1772
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;
1743
1781
1744
1782
break ;
1745
1783
}
@@ -1752,6 +1790,10 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1752
1790
GuiConsoleHandlePaint (GuiData );
1753
1791
break ;
1754
1792
1793
+ case WM_TIMER :
1794
+ GuiConsoleHandleTimer (GuiData );
1795
+ break ;
1796
+
1755
1797
case WM_PALETTECHANGED :
1756
1798
{
1757
1799
PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData -> ActiveBuffer ;
@@ -1815,10 +1857,6 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1815
1857
break ;
1816
1858
}
1817
1859
1818
- case WM_TIMER :
1819
- GuiConsoleHandleTimer (GuiData );
1820
- break ;
1821
-
1822
1860
case WM_SETCURSOR :
1823
1861
{
1824
1862
/*
@@ -2013,6 +2051,25 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2013
2051
GuiConsoleGetMinMaxInfo (GuiData , (PMINMAXINFO )lParam );
2014
2052
break ;
2015
2053
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
+
2016
2073
case WM_SIZE :
2017
2074
GuiConsoleResize (GuiData , wParam , lParam );
2018
2075
break ;
@@ -2101,9 +2158,10 @@ GuiConsoleNotifyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2101
2158
{
2102
2159
PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA )lParam ;
2103
2160
PCONSOLE Console = GuiData -> Console ;
2161
+ RECT rcWnd ;
2104
2162
2105
2163
NewWindow = CreateWindowExW (WS_EX_CLIENTEDGE ,
2106
- GUI_CONSOLE_WINDOW_CLASS ,
2164
+ GUI_CONWND_CLASS ,
2107
2165
Console -> Title .Buffer ,
2108
2166
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL ,
2109
2167
CW_USEDEFAULT ,
@@ -2136,6 +2194,11 @@ GuiConsoleNotifyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2136
2194
SendMessageW (GuiData -> hWindow , WM_SETICON , ICON_SMALL , (LPARAM )GuiData -> hIconSm );
2137
2195
}
2138
2196
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
+
2139
2202
/* Move and resize the window to the user's values */
2140
2203
/* CAN WE DEADLOCK ?? */
2141
2204
GuiConsoleMoveWindow (GuiData );
@@ -2289,7 +2352,7 @@ GuiInit(VOID)
2289
2352
LR_SHARED );
2290
2353
ghDefaultCursor = LoadCursorW (NULL , IDC_ARROW );
2291
2354
wc .cbSize = sizeof (WNDCLASSEXW );
2292
- wc .lpszClassName = GUI_CONSOLE_WINDOW_CLASS ;
2355
+ wc .lpszClassName = GUI_CONWND_CLASS ;
2293
2356
wc .lpfnWndProc = GuiConsoleWndProc ;
2294
2357
wc .style = CS_DBLCLKS /* | CS_HREDRAW | CS_VREDRAW */ ;
2295
2358
wc .hInstance = ConSrvDllInstance ;
0 commit comments