Author: akhaldi Date: Thu Jul 28 19:40:27 2016 New Revision: 72039
URL: http://svn.reactos.org/svn/reactos?rev=72039&view=rev Log: [0.4.2] * Merge the console work by Hermès in r72030. CORE-8394 CORE-9900
Modified: branches/ros-branch-0_4_2/reactos/ (props changed) branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/text.c
Propchange: branches/ros-branch-0_4_2/reactos/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Jul 28 19:40:27 2016 @@ -20,4 +20,4 @@ /branches/usb-bringup:51335,51337,51341-51343,51348,51350,51353,51355,51365-51369,51372,51384-54388,54396-54398,54736-54737,54752-54754,54756-54760,54762,54764-54765,54767-54768,54772,54774-54777,54781,54787,54790-54792,54797-54798,54806,54808,54834-54838,54843,54850,54852,54856,54858-54859 /branches/usb-bringup-trunk:55019-55543,55548-55554,55556-55567 /branches/wlan-bringup:54809-54998 -/trunk/reactos:72020-72022,72026,72028,72032-72034 +/trunk/reactos:72020-72022,72026,72028,72030,72032-72034
Modified: branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c URL: http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_2/reactos/win32ss... ============================================================================== --- branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c [iso-8859-1] (original) +++ branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c [iso-8859-1] Thu Jul 28 19:40:27 2016 @@ -179,11 +179,7 @@ OUT PUINT WidthUnit, OUT PUINT HeightUnit) { - if (Buffer == NULL || GuiData == NULL || - WidthUnit == NULL || HeightUnit == NULL) - { - return; - } + ASSERT(Buffer && GuiData && WidthUnit && HeightUnit);
if (GetType(Buffer) == TEXTMODE_BUFFER) { @@ -449,7 +445,7 @@ 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION);
/* Set scrollbar sizes */ - sInfo.cbSize = sizeof(SCROLLINFO); + sInfo.cbSize = sizeof(sInfo); sInfo.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; sInfo.nMin = 0; if (Buff->ScreenBufferSize.Y > Buff->ViewSize.Y) @@ -937,6 +933,8 @@ if (SelectionAnchor) GuiData->Selection.dwSelectionAnchor = *SelectionAnchor;
+ // TODO: Scroll buffer to bring 'coord' into view + if (coord != NULL) { SMALL_RECT rc; @@ -947,7 +945,7 @@ * into line-selection mode, the selection mode of *nix terminals. */ BOOL OldLineSel = GuiData->LineSelection; - GuiData->LineSelection = !!(GetKeyState(VK_CONTROL) & 0x8000); + GuiData->LineSelection = !!(GetKeyState(VK_CONTROL) & KEY_PRESSED);
/* Exchange left/top with right/bottom if required */ rc.Left = min(GuiData->Selection.dwSelectionAnchor.X, coord->X); @@ -1179,7 +1177,7 @@ goto Quit; } else if ( VirtualKeyCode == VK_ESCAPE || - (VirtualKeyCode == 'C' && (GetKeyState(VK_CONTROL) & 0x8000)) ) + (VirtualKeyCode == 'C' && (GetKeyState(VK_CONTROL) & KEY_PRESSED)) ) { /* Cancel selection if ESC or Ctrl-C are pressed */ UpdateSelection(GuiData, NULL, NULL); @@ -1190,7 +1188,7 @@ { /* Keyboard selection mode */ BOOL Interpreted = FALSE; - BOOL MajPressed = !!(GetKeyState(VK_SHIFT) & 0x8000); + BOOL MajPressed = !!(GetKeyState(VK_SHIFT) & KEY_PRESSED);
switch (VirtualKeyCode) { @@ -1348,7 +1346,7 @@ int OldScrollX = -1, OldScrollY = -1; int NewScrollX = -1, NewScrollY = -1;
- xScroll.cbSize = sizeof(SCROLLINFO); + xScroll.cbSize = sizeof(xScroll); xScroll.fMask = SIF_POS; // Capture the original position of the scroll bars and save them. if (GetScrollInfo(GuiData->hWindow, SB_HORZ, &xScroll)) OldScrollX = xScroll.nPos; @@ -1475,6 +1473,114 @@ return DefWindowProcW(hWnd, WM_NCDESTROY, 0, 0); }
+static VOID +OnScroll(PGUI_CONSOLE_DATA GuiData, INT nBar, WORD sbCode) +{ + PCONSRV_CONSOLE Console = GuiData->Console; + PCONSOLE_SCREEN_BUFFER Buff; + SCROLLINFO sInfo; + INT oldPos, Maximum; + PSHORT pOriginXY; + + ASSERT(nBar == SB_HORZ || nBar == SB_VERT); + + if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) return; + + Buff = GuiData->ActiveBuffer; + + if (nBar == SB_HORZ) + { + Maximum = Buff->ScreenBufferSize.X - Buff->ViewSize.X; + pOriginXY = &Buff->ViewOrigin.X; + } + else // if (nBar == SB_VERT) + { + Maximum = Buff->ScreenBufferSize.Y - Buff->ViewSize.Y; + pOriginXY = &Buff->ViewOrigin.Y; + } + + /* Set scrollbar sizes */ + sInfo.cbSize = sizeof(sInfo); + sInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE | SIF_TRACKPOS; + + if (!GetScrollInfo(GuiData->hWindow, nBar, &sInfo)) goto Quit; + + oldPos = sInfo.nPos; + + switch (sbCode) + { + case SB_LINEUP: // SB_LINELEFT: + sInfo.nPos--; + break; + + case SB_LINEDOWN: // SB_LINERIGHT: + sInfo.nPos++; + break; + + case SB_PAGEUP: // SB_PAGELEFT: + sInfo.nPos -= sInfo.nPage; + break; + + case SB_PAGEDOWN: // SB_PAGERIGHT: + sInfo.nPos += sInfo.nPage; + break; + + case SB_THUMBTRACK: + sInfo.nPos = sInfo.nTrackPos; + ConioPause(Console, PAUSED_FROM_SCROLLBAR); + break; + + case SB_THUMBPOSITION: + sInfo.nPos = sInfo.nTrackPos; + ConioUnpause(Console, PAUSED_FROM_SCROLLBAR); + break; + + case SB_TOP: // SB_LEFT: + sInfo.nPos = sInfo.nMin; + break; + + case SB_BOTTOM: // SB_RIGHT: + sInfo.nPos = sInfo.nMax; + break; + + default: + break; + } + + sInfo.nPos = min(max(sInfo.nPos, 0), Maximum); + + if (oldPos != sInfo.nPos) + { + USHORT OldX = Buff->ViewOrigin.X; + USHORT OldY = Buff->ViewOrigin.Y; + UINT WidthUnit, HeightUnit; + + /* We now modify either Buff->ViewOrigin.X or Buff->ViewOrigin.Y */ + *pOriginXY = sInfo.nPos; + + GetScreenBufferSizeUnits(Buff, GuiData, &WidthUnit, &HeightUnit); + + ScrollWindowEx(GuiData->hWindow, + (OldX - Buff->ViewOrigin.X) * WidthUnit , + (OldY - Buff->ViewOrigin.Y) * HeightUnit, + NULL, + NULL, + NULL, + NULL, + SW_INVALIDATE); + + sInfo.fMask = SIF_POS; + SetScrollInfo(GuiData->hWindow, nBar, &sInfo, TRUE); + + UpdateWindow(GuiData->hWindow); + // InvalidateRect(GuiData->hWindow, NULL, FALSE); + } + +Quit: + LeaveCriticalSection(&Console->Lock); + return; +} + static COORD PointToCoord(PGUI_CONSOLE_DATA GuiData, LPARAM lParam) { @@ -1504,7 +1610,7 @@ static LRESULT OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam) { - BOOL Err = FALSE; + BOOL DoDefault = FALSE; PCONSRV_CONSOLE Console = GuiData->Console;
/* @@ -1545,14 +1651,14 @@ * This mouse signal is a button-down action. * Ignore it and perform default action. */ - Err = TRUE; + DoDefault = TRUE; } goto Quit; }
if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) { - Err = TRUE; + DoDefault = TRUE; goto Quit; }
@@ -1563,16 +1669,32 @@ { case WM_LBUTTONDOWN: { - /* Clear the old selection */ - GuiData->Selection.dwFlags = CONSOLE_NO_SELECTION; - - /* Restart a new selection */ - GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam); - SetCapture(GuiData->hWindow); - GuiData->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN; - UpdateSelection(GuiData, - &GuiData->dwSelectionCursor, - &GuiData->dwSelectionCursor); + /* Check for selection state */ + if ( (GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) && + (GuiData->Selection.dwFlags & CONSOLE_MOUSE_SELECTION) && + (GetKeyState(VK_SHIFT) & KEY_PRESSED) ) + { + /* + * A mouse selection is currently in progress and the user + * has pressed the SHIFT key and clicked somewhere, update + * the selection. + */ + GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam); + UpdateSelection(GuiData, NULL, &GuiData->dwSelectionCursor); + } + else + { + /* Clear the old selection */ + GuiData->Selection.dwFlags = CONSOLE_NO_SELECTION; + + /* Restart a new selection */ + GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam); + SetCapture(GuiData->hWindow); + GuiData->Selection.dwFlags |= CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN; + UpdateSelection(GuiData, + &GuiData->dwSelectionCursor, + &GuiData->dwSelectionCursor); + }
break; } @@ -1630,6 +1752,7 @@
/* Ignore the next mouse move signal */ GuiData->IgnoreNextMouseSignal = TRUE; +#undef IS_WORD_SEP }
break; @@ -1654,18 +1777,16 @@
case WM_MOUSEMOVE: { - if (!(wParam & MK_LBUTTON)) break; + if (!(GET_KEYSTATE_WPARAM(wParam) & MK_LBUTTON)) break; if (!(GuiData->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) break;
- // TODO: Scroll buffer to bring SelectionCursor into view GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam); UpdateSelection(GuiData, NULL, &GuiData->dwSelectionCursor); - break; }
default: - Err = FALSE; // TRUE; + DoDefault = TRUE; // FALSE; break; } } @@ -1706,7 +1827,7 @@ if (wButton & ~(XBUTTON1 | XBUTTON2)) { DPRINT1("X-button 0x%04x invalid\n", wButton); - Err = TRUE; + DoDefault = TRUE; break; }
@@ -1777,7 +1898,7 @@ if (wButton & ~(XBUTTON1 | XBUTTON2)) { DPRINT1("X-button 0x%04x invalid\n", wButton); - Err = TRUE; + DoDefault = TRUE; break; }
@@ -1803,7 +1924,7 @@ break;
default: - Err = TRUE; + DoDefault = TRUE; break; }
@@ -1831,7 +1952,7 @@ break; }
- if (!Err) + if (!DoDefault) { if (wKeyState & MK_LBUTTON) dwButtonState |= FROM_LEFT_1ST_BUTTON_PRESSED; @@ -1844,21 +1965,21 @@ if (wKeyState & MK_XBUTTON2) dwButtonState |= FROM_LEFT_4TH_BUTTON_PRESSED;
- if (GetKeyState(VK_RMENU) & 0x8000) + if (GetKeyState(VK_RMENU) & KEY_PRESSED) dwControlKeyState |= RIGHT_ALT_PRESSED; - if (GetKeyState(VK_LMENU) & 0x8000) + if (GetKeyState(VK_LMENU) & KEY_PRESSED) dwControlKeyState |= LEFT_ALT_PRESSED; - if (GetKeyState(VK_RCONTROL) & 0x8000) + if (GetKeyState(VK_RCONTROL) & KEY_PRESSED) dwControlKeyState |= RIGHT_CTRL_PRESSED; - if (GetKeyState(VK_LCONTROL) & 0x8000) + if (GetKeyState(VK_LCONTROL) & KEY_PRESSED) dwControlKeyState |= LEFT_CTRL_PRESSED; - if (GetKeyState(VK_SHIFT) & 0x8000) + if (GetKeyState(VK_SHIFT) & KEY_PRESSED) dwControlKeyState |= SHIFT_PRESSED; - if (GetKeyState(VK_NUMLOCK) & 0x0001) + if (GetKeyState(VK_NUMLOCK) & KEY_TOGGLED) dwControlKeyState |= NUMLOCK_ON; - if (GetKeyState(VK_SCROLL) & 0x0001) + if (GetKeyState(VK_SCROLL) & KEY_TOGGLED) dwControlKeyState |= SCROLLLOCK_ON; - if (GetKeyState(VK_CAPITAL) & 0x0001) + if (GetKeyState(VK_CAPITAL) & KEY_TOGGLED) dwControlKeyState |= CAPSLOCK_ON; /* See WM_CHAR MSDN documentation for instance */ if (lParam & 0x01000000) @@ -1876,16 +1997,42 @@ } else { - Err = TRUE; + DoDefault = TRUE; }
LeaveCriticalSection(&Console->Lock);
Quit: - if (Err) - return DefWindowProcW(GuiData->hWindow, msg, wParam, lParam); - else + if (!DoDefault) return 0; + + if (msg == WM_MOUSEWHEEL || msg == WM_MOUSEHWHEEL) + { + INT nBar; + WORD sbCode; + // WORD wKeyState = GET_KEYSTATE_WPARAM(wParam); + SHORT wDelta = GET_WHEEL_DELTA_WPARAM(wParam); + + if (msg == WM_MOUSEWHEEL) + nBar = SB_VERT; + else // if (msg == WM_MOUSEHWHEEL) + nBar = SB_HORZ; + + // NOTE: We currently do not support zooming... + // if (wKeyState & MK_CONTROL) + + // FIXME: For some reason our win32k does not set the key states + // when sending WM_MOUSEWHEEL or WM_MOUSEHWHEEL ... + // if (wKeyState & MK_SHIFT) + if (GetKeyState(VK_SHIFT) & KEY_PRESSED) + sbCode = (wDelta >= 0 ? SB_PAGEUP : SB_PAGEDOWN); + else + sbCode = (wDelta >= 0 ? SB_LINEUP : SB_LINEDOWN); + + OnScroll(GuiData, nBar, sbCode); + } + + return DefWindowProcW(GuiData->hWindow, msg, wParam, lParam); }
VOID @@ -2001,29 +2148,29 @@ windx = LOWORD(lParam); windy = HIWORD(lParam);
- // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar) + /* Compensate for existing scroll bars (because lParam values do not accommodate scroll bar) */ if (Buff->ViewSize.X < Buff->ScreenBufferSize.X) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar if (Buff->ViewSize.Y < Buff->ScreenBufferSize.Y) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar
charx = windx / (int)WidthUnit ; chary = windy / (int)HeightUnit;
- // Character alignment (round size up or down) + /* Character alignment (round size up or down) */ if ((windx % WidthUnit ) >= (WidthUnit / 2)) ++charx; if ((windy % HeightUnit) >= (HeightUnit / 2)) ++chary;
- // Compensate for added scroll bars in new window + /* Compensate for added scroll bars in new window */ if (charx < (DWORD)Buff->ScreenBufferSize.X) windy -= GetSystemMetrics(SM_CYHSCROLL); // new window will have a horizontal scroll bar if (chary < (DWORD)Buff->ScreenBufferSize.Y) windx -= GetSystemMetrics(SM_CXVSCROLL); // new window will have a vertical scroll bar
charx = windx / (int)WidthUnit ; chary = windy / (int)HeightUnit;
- // Character alignment (round size up or down) + /* Character alignment (round size up or down) */ if ((windx % WidthUnit ) >= (WidthUnit / 2)) ++charx; if ((windy % HeightUnit) >= (HeightUnit / 2)) ++chary;
- // Resize window + /* Resize window */ if ((charx != Buff->ViewSize.X) || (chary != Buff->ViewSize.Y)) { Buff->ViewSize.X = (charx <= (DWORD)Buff->ScreenBufferSize.X) ? charx : Buff->ScreenBufferSize.X; @@ -2032,7 +2179,7 @@
ResizeConWnd(GuiData, WidthUnit, HeightUnit);
- // Adjust the start of the visible area if we are attempting to show nonexistent areas + /* Adjust the start of the visible area if we are attempting to show nonexistent areas */ if ((Buff->ScreenBufferSize.X - Buff->ViewOrigin.X) < Buff->ViewSize.X) Buff->ViewOrigin.X = Buff->ScreenBufferSize.X - Buff->ViewSize.X; if ((Buff->ScreenBufferSize.Y - Buff->ViewOrigin.Y) < Buff->ViewSize.Y) Buff->ViewOrigin.Y = Buff->ScreenBufferSize.Y - Buff->ViewSize.Y; InvalidateRect(GuiData->hWindow, NULL, TRUE); @@ -2084,114 +2231,6 @@ //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN); } */ - -static LRESULT -OnScroll(PGUI_CONSOLE_DATA GuiData, UINT uMsg, WPARAM wParam) -{ - PCONSRV_CONSOLE Console = GuiData->Console; - PCONSOLE_SCREEN_BUFFER Buff; - SCROLLINFO sInfo; - int fnBar; - int old_pos, Maximum; - PSHORT pShowXY; - - if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) return 0; - - Buff = GuiData->ActiveBuffer; - - if (uMsg == WM_HSCROLL) - { - fnBar = SB_HORZ; - Maximum = Buff->ScreenBufferSize.X - Buff->ViewSize.X; - pShowXY = &Buff->ViewOrigin.X; - } - else - { - fnBar = SB_VERT; - Maximum = Buff->ScreenBufferSize.Y - Buff->ViewSize.Y; - pShowXY = &Buff->ViewOrigin.Y; - } - - /* set scrollbar sizes */ - sInfo.cbSize = sizeof(SCROLLINFO); - sInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE | SIF_TRACKPOS; - - if (!GetScrollInfo(GuiData->hWindow, fnBar, &sInfo)) goto Quit; - - old_pos = sInfo.nPos; - - switch (LOWORD(wParam)) - { - case SB_LINELEFT: - sInfo.nPos -= 1; - break; - - case SB_LINERIGHT: - sInfo.nPos += 1; - break; - - case SB_PAGELEFT: - sInfo.nPos -= sInfo.nPage; - break; - - case SB_PAGERIGHT: - sInfo.nPos += sInfo.nPage; - break; - - case SB_THUMBTRACK: - sInfo.nPos = sInfo.nTrackPos; - ConioPause(Console, PAUSED_FROM_SCROLLBAR); - break; - - case SB_THUMBPOSITION: - ConioUnpause(Console, PAUSED_FROM_SCROLLBAR); - break; - - case SB_TOP: - sInfo.nPos = sInfo.nMin; - break; - - case SB_BOTTOM: - sInfo.nPos = sInfo.nMax; - break; - - default: - break; - } - - sInfo.nPos = max(sInfo.nPos, 0); - sInfo.nPos = min(sInfo.nPos, Maximum); - - if (old_pos != sInfo.nPos) - { - USHORT OldX = Buff->ViewOrigin.X; - USHORT OldY = Buff->ViewOrigin.Y; - UINT WidthUnit, HeightUnit; - - *pShowXY = sInfo.nPos; - - GetScreenBufferSizeUnits(Buff, GuiData, &WidthUnit, &HeightUnit); - - ScrollWindowEx(GuiData->hWindow, - (OldX - Buff->ViewOrigin.X) * WidthUnit , - (OldY - Buff->ViewOrigin.Y) * HeightUnit, - NULL, - NULL, - NULL, - NULL, - SW_INVALIDATE); - - sInfo.fMask = SIF_POS; - SetScrollInfo(GuiData->hWindow, fnBar, &sInfo, TRUE); - - UpdateWindow(GuiData->hWindow); - // InvalidateRect(GuiData->hWindow, NULL, FALSE); - } - -Quit: - LeaveCriticalSection(&Console->Lock); - return 0; -}
static LRESULT CALLBACK @@ -2378,11 +2417,12 @@ }
case WM_HSCROLL: + OnScroll(GuiData, SB_HORZ, LOWORD(wParam)); + break; + case WM_VSCROLL: - { - Result = OnScroll(GuiData, msg, wParam); - break; - } + OnScroll(GuiData, SB_VERT, LOWORD(wParam)); + break;
case WM_CONTEXTMENU: {
Modified: branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h URL: http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_2/reactos/win32ss... ============================================================================== --- branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h [iso-8859-1] (original) +++ branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.h [iso-8859-1] Thu Jul 28 19:40:27 2016 @@ -20,6 +20,10 @@ #define PM_RESIZE_TERMINAL (WM_APP + 3) #define PM_CONSOLE_BEEP (WM_APP + 4) #define PM_CONSOLE_SET_TITLE (WM_APP + 5) + +/* Flags for GetKeyState */ +#define KEY_TOGGLED 0x0001 +#define KEY_PRESSED 0x8000
/* typedef struct _CONSOLE_FONT
Modified: branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/text.c URL: http://svn.reactos.org/svn/reactos/branches/ros-branch-0_4_2/reactos/win32ss... ============================================================================== --- branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/text.c [iso-8859-1] (original) +++ branches/ros-branch-0_4_2/reactos/win32ss/user/winsrv/consrv/frontends/gui/text.c [iso-8859-1] Thu Jul 28 19:40:27 2016 @@ -44,7 +44,7 @@ * Pressing the Shift key while copying text, allows us to copy * text without newline characters (inline-text copy mode). */ - BOOL InlineCopyMode = !!(GetKeyState(VK_SHIFT) & 0x8000); + BOOL InlineCopyMode = !!(GetKeyState(VK_SHIFT) & KEY_PRESSED);
HANDLE hData; PCHAR_INFO ptr;