[KERNEL32][CONSRV] Use more often the internal ConioRectHeight/Width() and ConioIsRec...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 22 Feb 2020 20:15:58 +0000 (21:15 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 22 Feb 2020 20:15:58 +0000 (21:15 +0100)
dll/win32/kernel32/client/console/readwrite.c
win32ss/user/winsrv/consrv/condrv/text.c
win32ss/user/winsrv/consrv/conoutput.c
win32ss/user/winsrv/consrv/frontends/gui/graphics.c
win32ss/user/winsrv/consrv/frontends/gui/text.c
win32ss/user/winsrv/consrv/include/rect.h

index c10d833..b06f7ab 100644 (file)
@@ -20,9 +20,9 @@
 
 /* See consrv/include/rect.h */
 #define ConioRectHeight(Rect) \
-    (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
+    (((Rect)->Top > (Rect)->Bottom) ? 0 : ((Rect)->Bottom - (Rect)->Top + 1))
 #define ConioRectWidth(Rect) \
-    (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
+    (((Rect)->Left > (Rect)->Right) ? 0 : ((Rect)->Right - (Rect)->Left + 1))
 
 
 /* PRIVATE FUNCTIONS **********************************************************/
@@ -436,8 +436,7 @@ IntReadConsoleOutput(IN HANDLE hConsoleOutput,
 
             /* Copy into the buffer */
 
-            SizeX = ReadOutputRequest->ReadRegion.Right -
-                    ReadOutputRequest->ReadRegion.Left + 1;
+            SizeX = ConioRectWidth(&ReadOutputRequest->ReadRegion);
 
             for (y = 0, Y = ReadOutputRequest->ReadRegion.Top; Y <= ReadOutputRequest->ReadRegion.Bottom; ++y, ++Y)
             {
@@ -913,8 +912,7 @@ IntWriteConsoleOutput(IN HANDLE hConsoleOutput,
 
         /* Copy into the buffer */
 
-        SizeX = WriteOutputRequest->WriteRegion.Right -
-                WriteOutputRequest->WriteRegion.Left + 1;
+        SizeX = ConioRectWidth(&WriteOutputRequest->WriteRegion);
 
         for (y = 0, Y = WriteOutputRequest->WriteRegion.Top; Y <= WriteOutputRequest->WriteRegion.Bottom; ++y, ++Y)
         {
index 7108fcf..33abb74 100644 (file)
@@ -1607,15 +1607,14 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
     }
 
     /*
-     * The MSDN documentation on SetConsoleWindowInfo is partially wrong about
+     * The MSDN documentation on SetConsoleWindowInfo() is partially wrong about
      * the performed checks this API performs. While it is correct that the
      * 'Right'/'Bottom' members cannot be strictly smaller than the 'Left'/'Top'
-     * members, they can be equal.
+     * members (the rectangle cannot be empty), they can be equal (describe one cell).
      * Also, if the 'Left' or 'Top' members are negative, this is automatically
      * corrected for, and the window rectangle coordinates are shifted accordingly.
      */
-    if ((CapturedWindowRect.Right  < CapturedWindowRect.Left) ||
-        (CapturedWindowRect.Bottom < CapturedWindowRect.Top))
+    if (ConioIsRectEmpty(&CapturedWindowRect))
     {
         return STATUS_INVALID_PARAMETER;
     }
@@ -1627,8 +1626,8 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
     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))
+    if ((ConioRectWidth(&CapturedWindowRect)  > LargestWindowSize.X) ||
+        (ConioRectHeight(&CapturedWindowRect) > LargestWindowSize.Y))
     {
         return STATUS_INVALID_PARAMETER;
     }
@@ -1652,8 +1651,8 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
     Buffer->ViewOrigin.X = CapturedWindowRect.Left;
     Buffer->ViewOrigin.Y = CapturedWindowRect.Top;
 
-    Buffer->ViewSize.X = CapturedWindowRect.Right - CapturedWindowRect.Left + 1;
-    Buffer->ViewSize.Y = CapturedWindowRect.Bottom - CapturedWindowRect.Top + 1;
+    Buffer->ViewSize.X = ConioRectWidth(&CapturedWindowRect);
+    Buffer->ViewSize.Y = ConioRectHeight(&CapturedWindowRect);
 
     TermResizeTerminal(Console);
 
index 0f8bc2b..079d781 100644 (file)
@@ -497,8 +497,8 @@ CSR_API(SrvReadConsoleOutput)
 
     DPRINT("SrvReadConsoleOutput\n");
 
-    NumCells = (ReadOutputRequest->ReadRegion.Right - ReadOutputRequest->ReadRegion.Left + 1) *
-               (ReadOutputRequest->ReadRegion.Bottom - ReadOutputRequest->ReadRegion.Top + 1);
+    NumCells = ConioRectWidth(&ReadOutputRequest->ReadRegion) *
+               ConioRectHeight(&ReadOutputRequest->ReadRegion);
 
     /*
      * For optimization purposes, Windows (and hence ReactOS, too, for
@@ -562,8 +562,8 @@ CSR_API(SrvWriteConsoleOutput)
 
     DPRINT("SrvWriteConsoleOutput\n");
 
-    NumCells = (WriteOutputRequest->WriteRegion.Right - WriteOutputRequest->WriteRegion.Left + 1) *
-               (WriteOutputRequest->WriteRegion.Bottom - WriteOutputRequest->WriteRegion.Top + 1);
+    NumCells = ConioRectWidth(&WriteOutputRequest->WriteRegion) *
+               ConioRectHeight(&WriteOutputRequest->WriteRegion);
 
     Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(Process),
                                      WriteOutputRequest->OutputHandle,
index ab0bc69..63fd616 100644 (file)
@@ -32,8 +32,8 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
 
     if (Buffer->BitMap == NULL) return;
 
-    selWidth  = GuiData->Selection.srSelection.Right - GuiData->Selection.srSelection.Left + 1;
-    selHeight = GuiData->Selection.srSelection.Bottom - GuiData->Selection.srSelection.Top + 1;
+    selWidth  = ConioRectWidth(&GuiData->Selection.srSelection);
+    selHeight = ConioRectHeight(&GuiData->Selection.srSelection);
     DPRINT("Selection is (%d|%d) to (%d|%d)\n",
            GuiData->Selection.srSelection.Left,
            GuiData->Selection.srSelection.Top,
index 0397be7..fcbcbaf 100644 (file)
@@ -57,12 +57,11 @@ CopyBlock(PTEXTMODE_SCREEN_BUFFER Buffer,
            Selection->Left, Selection->Top, Selection->Right, Selection->Bottom);
 
     /* Prevent against empty blocks */
-    if (Selection == NULL) return;
-    if (Selection->Left > Selection->Right || Selection->Top > Selection->Bottom)
+    if ((Selection == NULL) || ConioIsRectEmpty(Selection))
         return;
 
-    selWidth  = Selection->Right - Selection->Left + 1;
-    selHeight = Selection->Bottom - Selection->Top + 1;
+    selWidth  = ConioRectWidth(Selection);
+    selHeight = ConioRectHeight(Selection);
 
     /* Basic size for one line... */
     size = selWidth;
index 9785935..9ab5651 100644 (file)
@@ -29,9 +29,9 @@ do {    \
     (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
 
 #define ConioRectHeight(Rect) \
-    (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
+    (((Rect)->Top > (Rect)->Bottom) ? 0 : ((Rect)->Bottom - (Rect)->Top + 1))
 #define ConioRectWidth(Rect) \
-    (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
+    (((Rect)->Left > (Rect)->Right) ? 0 : ((Rect)->Right - (Rect)->Left + 1))
 
 
 static __inline BOOLEAN