[CONSRV]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 18 Oct 2016 23:51:59 +0000 (23:51 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 18 Oct 2016 23:51:59 +0000 (23:51 +0000)
- Call TermGetLargestConsoleWindowSize to obtain the largest console window size allowed on the system, and use it for GetConsoleScreenBufferInfo and for SetConsoleWindowInfo too, where it is used to check if the given user window size is not too large.
- Improve GuiGetLargestConsoleWindowSize for multi-monitor situations.
- Remove the redundant definition of GetScreenBufferSizeUnits in guiterm.c (it already exists in conwnd.c).

svn path=/trunk/; revision=72993

reactos/win32ss/user/winsrv/consrv/condrv/dummyterm.c
reactos/win32ss/user/winsrv/consrv/condrv/text.c
reactos/win32ss/user/winsrv/consrv/frontendctl.c
reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
reactos/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
reactos/win32ss/user/winsrv/consrv/settings.c

index fa87462..7261994 100644 (file)
@@ -112,6 +112,10 @@ static VOID NTAPI
 DummyGetLargestConsoleWindowSize(IN OUT PTERMINAL This,
                                  PCOORD pSize)
 {
 DummyGetLargestConsoleWindowSize(IN OUT PTERMINAL This,
                                  PCOORD pSize)
 {
+    /* Return a standard size */
+    if (!pSize) return;
+    pSize->X = 80;
+    pSize->Y = 25;
 }
 
 static BOOL NTAPI
 }
 
 static BOOL NTAPI
index d54d820..5b4d415 100644 (file)
@@ -1065,6 +1065,8 @@ ConDrvGetConsoleScreenBufferInfo(IN  PCONSOLE Console,
                                  OUT PCOORD MaximumViewSize,
                                  OUT PWORD  Attributes)
 {
                                  OUT PCOORD MaximumViewSize,
                                  OUT PWORD  Attributes)
 {
+    COORD LargestWindowSize;
+
     if (Console == NULL || Buffer == NULL || ScreenBufferSize == NULL ||
         CursorPosition  == NULL || ViewOrigin == NULL || ViewSize == NULL ||
         MaximumViewSize == NULL || Attributes == NULL)
     if (Console == NULL || Buffer == NULL || ScreenBufferSize == NULL ||
         CursorPosition  == NULL || ViewOrigin == NULL || ViewSize == NULL ||
         MaximumViewSize == NULL || Attributes == NULL)
@@ -1081,8 +1083,14 @@ ConDrvGetConsoleScreenBufferInfo(IN  PCONSOLE Console,
     *ViewSize         = Buffer->ViewSize;
     *Attributes       = Buffer->ScreenDefaultAttrib;
 
     *ViewSize         = Buffer->ViewSize;
     *Attributes       = Buffer->ScreenDefaultAttrib;
 
-    // FIXME: Refine the computation
-    *MaximumViewSize  = Buffer->ScreenBufferSize;
+    /*
+     * Retrieve the largest possible console window size, taking
+     * into account the size of the console screen buffer.
+     */
+    TermGetLargestConsoleWindowSize(Console, &LargestWindowSize);
+    LargestWindowSize.X = min(LargestWindowSize.X, Buffer->ScreenBufferSize.X);
+    LargestWindowSize.Y = min(LargestWindowSize.Y, Buffer->ScreenBufferSize.Y);
+    *MaximumViewSize = LargestWindowSize;
 
     return STATUS_SUCCESS;
 }
 
     return STATUS_SUCCESS;
 }
@@ -1216,6 +1224,7 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
                            IN PSMALL_RECT WindowRect)
 {
     SMALL_RECT CapturedWindowRect;
                            IN PSMALL_RECT WindowRect)
 {
     SMALL_RECT CapturedWindowRect;
+    COORD LargestWindowSize;
 
     if (Console == NULL || Buffer == NULL || WindowRect == NULL)
         return STATUS_INVALID_PARAMETER;
 
     if (Console == NULL || Buffer == NULL || WindowRect == NULL)
         return STATUS_INVALID_PARAMETER;
@@ -1227,7 +1236,7 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
 
     if (!Absolute)
     {
 
     if (!Absolute)
     {
-        /* Relative positions given. Transform them to absolute ones */
+        /* Relative positions are given, transform them to absolute ones */
         CapturedWindowRect.Left   += Buffer->ViewOrigin.X;
         CapturedWindowRect.Top    += Buffer->ViewOrigin.Y;
         CapturedWindowRect.Right  += Buffer->ViewOrigin.X + Buffer->ViewSize.X - 1;
         CapturedWindowRect.Left   += Buffer->ViewOrigin.X;
         CapturedWindowRect.Top    += Buffer->ViewOrigin.Y;
         CapturedWindowRect.Right  += Buffer->ViewOrigin.X + Buffer->ViewSize.X - 1;
@@ -1248,6 +1257,19 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
         return STATUS_INVALID_PARAMETER;
     }
 
         return STATUS_INVALID_PARAMETER;
     }
 
+    /*
+     * Forbid window sizes larger than the largest allowed console window size,
+     * taking into account the size of the console screen buffer.
+     */
+    TermGetLargestConsoleWindowSize(Console, &LargestWindowSize);
+    LargestWindowSize.X = min(LargestWindowSize.X, Buffer->ScreenBufferSize.X);
+    LargestWindowSize.Y = min(LargestWindowSize.Y, Buffer->ScreenBufferSize.Y);
+    if ((CapturedWindowRect.Right - CapturedWindowRect.Left + 1 > LargestWindowSize.X) ||
+        (CapturedWindowRect.Bottom - CapturedWindowRect.Top + 1 > LargestWindowSize.Y))
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
     /* Shift the window rectangle coordinates if 'Left' or 'Top' are negative */
     if (CapturedWindowRect.Left < 0)
     {
     /* Shift the window rectangle coordinates if 'Left' or 'Top' are negative */
     if (CapturedWindowRect.Left < 0)
     {
@@ -1260,11 +1282,9 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
         CapturedWindowRect.Top = 0;
     }
 
         CapturedWindowRect.Top = 0;
     }
 
-    if ((CapturedWindowRect.Right  >= Buffer->ScreenBufferSize.X) ||
-        (CapturedWindowRect.Bottom >= Buffer->ScreenBufferSize.Y))
-    {
-        return STATUS_INVALID_PARAMETER;
-    }
+    /* Clip the window rectangle to the screen buffer */
+    CapturedWindowRect.Right  = min(CapturedWindowRect.Right , Buffer->ScreenBufferSize.X);
+    CapturedWindowRect.Bottom = min(CapturedWindowRect.Bottom, Buffer->ScreenBufferSize.Y);
 
     Buffer->ViewOrigin.X = CapturedWindowRect.Left;
     Buffer->ViewOrigin.Y = CapturedWindowRect.Top;
 
     Buffer->ViewOrigin.X = CapturedWindowRect.Left;
     Buffer->ViewOrigin.Y = CapturedWindowRect.Top;
index 7d4cd84..9ea1fe9 100644 (file)
@@ -174,6 +174,12 @@ CSR_API(SrvGetLargestConsoleWindowSize)
     if (!NT_SUCCESS(Status)) return Status;
 
     Console = Buff->Header.Console;
     if (!NT_SUCCESS(Status)) return Status;
 
     Console = Buff->Header.Console;
+
+    /*
+     * Retrieve the largest possible console window size, without
+     * taking into account the size of the console screen buffer
+     * (thus differs from ConDrvGetConsoleScreenBufferInfo).
+     */
     TermGetLargestConsoleWindowSize(Console, &GetLargestWindowSizeRequest->Size);
 
     ConSrvReleaseScreenBuffer(Buff, TRUE);
     TermGetLargestConsoleWindowSize(Console, &GetLargestWindowSizeRequest->Size);
 
     ConSrvReleaseScreenBuffer(Buff, TRUE);
index 1a9806b..3966670 100644 (file)
@@ -172,8 +172,8 @@ UnRegisterConWndClass(HINSTANCE hInstance)
 }
 
 
 }
 
 
-
-static VOID
+/* NOTE: Also used in guiterm.c */
+/* static */ VOID
 GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer,
                          IN PGUI_CONSOLE_DATA GuiData,
                          OUT PUINT WidthUnit,
 GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer,
                          IN PGUI_CONSOLE_DATA GuiData,
                          OUT PUINT WidthUnit,
index 61f4ade..d479a5a 100644 (file)
@@ -56,29 +56,12 @@ UnRegisterConWndClass(HINSTANCE hInstance);
 
 /* FUNCTIONS ******************************************************************/
 
 
 /* FUNCTIONS ******************************************************************/
 
-static VOID
+/* NOTE: Defined in conwnd.c */
+VOID
 GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer,
                          IN PGUI_CONSOLE_DATA GuiData,
                          OUT PUINT WidthUnit,
 GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer,
                          IN PGUI_CONSOLE_DATA GuiData,
                          OUT PUINT WidthUnit,
-                         OUT PUINT HeightUnit)
-{
-    if (Buffer == NULL || GuiData == NULL ||
-        WidthUnit == NULL || HeightUnit == NULL)
-    {
-        return;
-    }
-
-    if (GetType(Buffer) == TEXTMODE_BUFFER)
-    {
-        *WidthUnit  = GuiData->CharWidth ;
-        *HeightUnit = GuiData->CharHeight;
-    }
-    else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
-    {
-        *WidthUnit  = 1;
-        *HeightUnit = 1;
-    }
-}
+                         OUT PUINT HeightUnit);
 
 VOID
 GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData)
 
 VOID
 GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData)
@@ -817,13 +800,9 @@ GuiSetActiveScreenBuffer(IN OUT PFRONTEND This)
 
     /* Change the current palette */
     if (ActiveBuffer->PaletteHandle == NULL)
 
     /* Change the current palette */
     if (ActiveBuffer->PaletteHandle == NULL)
-    {
         hPalette = GuiData->hSysPalette;
         hPalette = GuiData->hSysPalette;
-    }
     else
     else
-    {
         hPalette = ActiveBuffer->PaletteHandle;
         hPalette = ActiveBuffer->PaletteHandle;
-    }
 
     DPRINT("GuiSetActiveScreenBuffer using palette 0x%p\n", hPalette);
 
 
     DPRINT("GuiSetActiveScreenBuffer using palette 0x%p\n", hPalette);
 
@@ -937,9 +916,7 @@ GuiChangeIcon(IN OUT PFRONTEND This,
     }
 
     if (hIcon == NULL)
     }
 
     if (hIcon == NULL)
-    {
         return FALSE;
         return FALSE;
-    }
 
     if (hIcon != GuiData->hIcon)
     {
 
     if (hIcon != GuiData->hIcon)
     {
@@ -976,41 +953,60 @@ GuiGetLargestConsoleWindowSize(IN OUT PFRONTEND This,
 {
     PGUI_CONSOLE_DATA GuiData = This->Context;
     PCONSOLE_SCREEN_BUFFER ActiveBuffer;
 {
     PGUI_CONSOLE_DATA GuiData = This->Context;
     PCONSOLE_SCREEN_BUFFER ActiveBuffer;
-    RECT WorkArea;
-    LONG width, height;
+    HMONITOR hMonitor;
+    MONITORINFO MonitorInfo;
+    LONG Width, Height;
     UINT WidthUnit, HeightUnit;
 
     if (!pSize) return;
 
     UINT WidthUnit, HeightUnit;
 
     if (!pSize) return;
 
-    if (!SystemParametersInfoW(SPI_GETWORKAREA, 0, &WorkArea, 0))
+    /*
+     * Retrieve the monitor that is mostly covered by the current console window;
+     * default to primary monitor otherwise.
+     */
+    MonitorInfo.cbSize = sizeof(MonitorInfo);
+    hMonitor = MonitorFromWindow(GuiData->hWindow, MONITOR_DEFAULTTOPRIMARY);
+    if (hMonitor && GetMonitorInfoW(hMonitor, &MonitorInfo))
     {
     {
-        DPRINT1("SystemParametersInfoW failed - What to do ??\n");
-        return;
+        /* Retrieve the width and height of the client area of this monitor */
+        Width  = MonitorInfo.rcWork.right - MonitorInfo.rcWork.left;
+        Height = MonitorInfo.rcWork.bottom - MonitorInfo.rcWork.top;
+    }
+    else
+    {
+        /*
+         * Retrieve the width and height of the client area for a full-screen
+         * window on the primary display monitor.
+         */
+        Width  = GetSystemMetrics(SM_CXFULLSCREEN);
+        Height = GetSystemMetrics(SM_CYFULLSCREEN);
+
+        // RECT WorkArea;
+        // SystemParametersInfoW(SPI_GETWORKAREA, 0, &WorkArea, 0);
+        // Width  = WorkArea.right;
+        // Height = WorkArea.bottom;
     }
 
     ActiveBuffer = GuiData->ActiveBuffer;
     }
 
     ActiveBuffer = GuiData->ActiveBuffer;
+#if 0
+    // NOTE: This would be surprising if we wouldn't have an associated buffer...
     if (ActiveBuffer)
     if (ActiveBuffer)
-    {
+#endif
         GetScreenBufferSizeUnits(ActiveBuffer, GuiData, &WidthUnit, &HeightUnit);
         GetScreenBufferSizeUnits(ActiveBuffer, GuiData, &WidthUnit, &HeightUnit);
-    }
+#if 0
     else
     else
-    {
-        /* Default: text mode */
-        WidthUnit  = GuiData->CharWidth ;
-        HeightUnit = GuiData->CharHeight;
-    }
-
-    width  = WorkArea.right;
-    height = WorkArea.bottom;
+        /* Default: graphics mode */
+        WidthUnit = HeightUnit = 1;
+#endif
 
 
-    width  -= (2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)));
-    height -= (2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION));
+    Width  -= (2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)));
+    Height -= (2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION));
 
 
-    if (width  < 0) width  = 0;
-    if (height < 0) height = 0;
+    if (Width  < 0) Width  = 0;
+    if (Height < 0) Height = 0;
 
 
-    pSize->X = (SHORT)(width  / (int)WidthUnit ) /* HACK */ + 2;
-    pSize->Y = (SHORT)(height / (int)HeightUnit) /* HACK */ + 1;
+    pSize->X = (SHORT)(Width  / (int)WidthUnit ) /* HACK */ + 2;
+    pSize->Y = (SHORT)(Height / (int)HeightUnit) /* HACK */ + 1;
 }
 
 static BOOL NTAPI
 }
 
 static BOOL NTAPI
index 5b0d465..f700c95 100644 (file)
@@ -52,6 +52,9 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
     ActiveBuffer->CursorInfo.bVisible = (ConsoleInfo->CursorSize != 0);
     ActiveBuffer->CursorInfo.dwSize   = min(max(ConsoleInfo->CursorSize, 0), 100);
 
     ActiveBuffer->CursorInfo.bVisible = (ConsoleInfo->CursorSize != 0);
     ActiveBuffer->CursorInfo.dwSize   = min(max(ConsoleInfo->CursorSize, 0), 100);
 
+    // FIXME: Check ConsoleInfo->WindowSize with respect to
+    // TermGetLargestConsoleWindowSize(...).
+
     if (GetType(ActiveBuffer) == TEXTMODE_BUFFER)
     {
         PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer;
     if (GetType(ActiveBuffer) == TEXTMODE_BUFFER)
     {
         PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer;