test: resize.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# resize.c File Reference

`#include "precomp.h"`

Go to the source code of this file.

## Functions

VOID | CalculateNewSize (IN PBOOLEAN MaximizedX, IN PBOOLEAN MaximizedY, IN OUT PSHORT DeltaX, IN OUT PSHORT DeltaY, IN SHORT WindowSizeX, IN SHORT WindowSizeY, IN COORD ScreenBufferSize, IN COORD FontSize)
VOID | ProcessResizeWindow (IN PSCREEN_INFORMATION ScreenInfo, IN PCONSOLE_INFORMATION Console, IN LPWINDOWPOS WindowPos)

## Function Documentation

VOID CalculateNewSize | ( | IN PBOOLEAN | MaximizedX,
|  | IN PBOOLEAN | MaximizedY,
|  | IN OUT PSHORT | DeltaX,
|  | IN OUT PSHORT | DeltaY,
|  | IN SHORT | WindowSizeX,
|  | IN SHORT | WindowSizeY,
|  | IN COORD | ScreenBufferSize,
|  | IN COORD | FontSize
| ) |

Definition at line 261 of file resize.c.

References FALSE, HorizontalScrollSize, SHORT, TRUE, and VerticalScrollSize.

Referenced by ProcessResizeWindow().

    00271 {
    00272     SHORT MaxDeltaX = ScreenBufferSize.X - WindowSizeX;
    00273     SHORT MaxDeltaY = ScreenBufferSize.Y - WindowSizeY;
    00274     SHORT MinDeltaX = 1 - WindowSizeX;
    00275     SHORT MinDeltaY = 1 - WindowSizeY;
    00276
    00277     while (TRUE) {
    00278
    00279         /*
    00280          * Do we need to remove a horizontal scroll bar?
    00281          */
    00282         if (!*MaximizedX && *DeltaX >= MaxDeltaX) {
    00283             *MaximizedX = TRUE;
    00284             *DeltaY += (VerticalScrollSize+FontSize.Y-1) / FontSize.Y;
    00285         }
    00286
    00287         /*
    00288          * Do we need to remove a vertical scroll bar?
    00289          */
    00290         else if (!*MaximizedY && *DeltaY >= MaxDeltaY) {
    00291             *MaximizedY = TRUE;
    00292             *DeltaX += (HorizontalScrollSize+FontSize.X-1) / FontSize.X;
    00293         }
    00294
    00295         /*
    00296          * Do we need to add a horizontal scroll bar?
    00297          */
    00298         else if (*MaximizedX && *DeltaX < MaxDeltaX) {
    00299             *MaximizedX = FALSE;
    00300             *DeltaY -= (VerticalScrollSize+FontSize.Y-1) / FontSize.Y;
    00301         }
    00302
    00303         /*
    00304          * Do we need to add a vertical scroll bar?
    00305          */
    00306         else if (*MaximizedY && *DeltaY < MaxDeltaY) {
    00307             *MaximizedY = FALSE;
    00308             *DeltaX -= (HorizontalScrollSize+FontSize.X-1) / FontSize.X;
    00309         }
    00310
    00311         /*
    00312          * Everything is done, so get out.
    00313          */
    00314         else {
    00315             if (*DeltaX > MaxDeltaX)
    00316                 *DeltaX = MaxDeltaX;
    00317             else if (*DeltaX < MinDeltaX)
    00318                 *DeltaX = MinDeltaX;
    00319             if (*DeltaY > MaxDeltaY)
    00320                 *DeltaY = MaxDeltaY;
    00321             else if (*DeltaY < MinDeltaY)
    00322                 *DeltaY = MinDeltaY;
    00323             return;
    00324         }
    00325     }
    00326 }

VOID ProcessResizeWindow | ( | IN PSCREEN_INFORMATION | ScreenInfo,
|  | IN PCONSOLE_INFORMATION | Console,
|  | IN LPWINDOWPOS | WindowPos
| ) |

Definition at line 40 of file resize.c.

References ASSERT, CalculateNewSize(), CONSOLE_TEXTMODE_BUFFER, CONSOLE_WINDOW_SIZE_X, CONSOLE_WINDOW_SIZE_Y, DbgPrint, DWORD, HorizontalClientToWindow, HorizontalScrollSize, InitializeSystemMetrics(), RESIZE_SCROLL_BARS, SCR_FONTSIZE(), SCREEN_BUFFER_CHANGE, SHORT, TRUE, VerticalClientToWindow, and VerticalScrollSize.

Referenced by ConsoleWindowProc().

    00045 {
    00046     SHORT DeltaX,DeltaY;
    00047     SHORT PixelDeltaX,PixelDeltaY;
    00048     DWORD Flags=0;
    00049     COORD FontSize;
    00050
    00051 #ifdef THERESES_DEBUG
    00052 DbgPrint("WM_WINDOWPOSCHANGING message ");
    00053 DbgPrint("  WindowSize is %d %d\n",CONSOLE_WINDOW_SIZE_X(ScreenInfo),CONSOLE_WINDOW_SIZE_Y(ScreenInfo));
    00054 DbgPrint("  WindowRect is %d %d %d %d\n",Console->WindowRect.left,
    00055                                          Console->WindowRect.top,
    00056                                          Console->WindowRect.right,
    00057                                          Console->WindowRect.bottom);
    00058 DbgPrint("  window pos is %d %d %d %d\n",WindowPos->x,
    00059                                          WindowPos->y,
    00060                                          WindowPos->cx,
    00061                                          WindowPos->cy);
    00062 #endif
    00063
    00064     //
    00065     // If the window is not being resized, don't do anything
    00066     //
    00067
    00068     if (WindowPos->flags & SWP_NOSIZE) {
    00069         return;
    00070     }
    00071
    00072     if (ScreenInfo->Flags & CONSOLE_TEXTMODE_BUFFER) {
    00073         FontSize = SCR_FONTSIZE(ScreenInfo);
    00074     } else {
    00075         FontSize.X = 1;
    00076         FontSize.Y = 1;
    00077     }
    00078
    00079     //
    00080     // If the frame changed, update the system metrics
    00081     //
    00082
    00083     if (WindowPos->flags & SWP_FRAMECHANGED) {
    00084
    00085         InitializeSystemMetrics();
    00086         if (Console->VerticalClientToWindow != VerticalClientToWindow ||
    00087             Console->HorizontalClientToWindow != HorizontalClientToWindow) {
    00088
    00089             Console->VerticalClientToWindow = VerticalClientToWindow;
    00090             Console->HorizontalClientToWindow = HorizontalClientToWindow;
    00091             Console->WindowRect.left = WindowPos->x;
    00092             Console->WindowRect.top = WindowPos->y;
    00093             Console->WindowRect.right = WindowPos->x + WindowPos->cx;
    00094             Console->WindowRect.bottom = WindowPos->y + WindowPos->cy;
    00095             return;
    00096         }
    00097     }
    00098
    00099     PixelDeltaX = (SHORT)(WindowPos->cx - (Console->WindowRect.right - Console->WindowRect.left));
    00100     PixelDeltaY = (SHORT)(WindowPos->cy - (Console->WindowRect.bottom - Console->WindowRect.top));
    00101
    00102     if (WindowPos->cx >= (ScreenInfo->ScreenBufferSize.X * FontSize.X + VerticalClientToWindow) &&
    00103         WindowPos->cy >= (ScreenInfo->ScreenBufferSize.Y * FontSize.Y + HorizontalClientToWindow)) {
    00104
    00105         //
    00106         // handle maximized case
    00107         //
    00108
    00109         ScreenInfo->WindowMaximizedX = TRUE;
    00110         ScreenInfo->WindowMaximizedY = TRUE;
    00111         DeltaX = (SHORT)(ScreenInfo->ScreenBufferSize.X - CONSOLE_WINDOW_SIZE_X(ScreenInfo));
    00112         DeltaY = (SHORT)(ScreenInfo->ScreenBufferSize.Y - CONSOLE_WINDOW_SIZE_Y(ScreenInfo));
    00113     } else {
    00114
    00115         DeltaX = PixelDeltaX / FontSize.X;
    00116         DeltaY = PixelDeltaY / FontSize.Y;
    00117
    00118         //
    00119         // the only time we will get a WM_WINDOWPOSCHANGING message to grow the
    00120         // window larger than the maximum window size is when another app calls
    00121         // SetWindowPos for our window.  the program manager does that when
    00122         // the user requests Tiling.
    00123         //
    00124
    00125         CalculateNewSize(&ScreenInfo->WindowMaximizedX,
    00126                          &ScreenInfo->WindowMaximizedY,
    00127                          &DeltaX,
    00128                          &DeltaY,
    00129                          (SHORT)(CONSOLE_WINDOW_SIZE_X(ScreenInfo)),
    00130                          (SHORT)(CONSOLE_WINDOW_SIZE_Y(ScreenInfo)),
    00131                          ScreenInfo->ScreenBufferSize,
    00132                          FontSize
    00133                         );
    00134 #ifdef THERESES_DEBUG
    00135 DbgPrint("Delta X Y is now %d %d\n",DeltaX,DeltaY);
    00136 DbgPrint("Maximized X Y is now %d %d\n",ScreenInfo->WindowMaximizedX,ScreenInfo->WindowMaximizedY);
    00137 #endif
    00138     }
    00139
    00140     //
    00141     // don't move window when resizing less than a column or row.
    00142     //
    00143
    00144     if (!DeltaX && !DeltaY && (PixelDeltaX || PixelDeltaY)) {
    00145         COORD OriginDifference;
    00146
    00147         //
    00148         // handle tiling case.  tiling can move the window without resizing, but using
    00149         // a size message. we detect this by checking for the window origin changed by
    00150         // more than one character.
    00151         //
    00152
    00153         OriginDifference.X = (SHORT)(WindowPos->x - Console->WindowRect.left);
    00154         OriginDifference.Y = (SHORT)(WindowPos->y - Console->WindowRect.top);
    00155         if (OriginDifference.X < FontSize.X && OriginDifference.X > -FontSize.X &&
    00156             OriginDifference.Y < FontSize.Y && OriginDifference.Y > -FontSize.Y) {
    00157             WindowPos->x = Console->WindowRect.left;
    00158             WindowPos->y = Console->WindowRect.top;
    00159             WindowPos->cx = Console->WindowRect.right - Console->WindowRect.left;
    00160             WindowPos->cy = Console->WindowRect.bottom - Console->WindowRect.top;
    00161             return;
    00162         }
    00163     }
    00164
    00165     Flags |= RESIZE_SCROLL_BARS;
    00166     WindowPos->cx = (DeltaX + CONSOLE_WINDOW_SIZE_X(ScreenInfo)) * FontSize.X + (!ScreenInfo->WindowMaximizedY * VerticalScrollSize) + VerticalClientToWindow;
    00167     WindowPos->cy = (DeltaY + CONSOLE_WINDOW_SIZE_Y(ScreenInfo)) * FontSize.Y + (!ScreenInfo->WindowMaximizedX * HorizontalScrollSize) + HorizontalClientToWindow;
    00168
    00169     //
    00170     // reflect the new window size in the
    00171     // console window structure
    00172     //
    00173
    00174     {
    00175     SHORT ScrollRange,ScrollPos;
    00176
    00177     //
    00178     // PercentFromTop = ScrollPos / ScrollRange;
    00179     // PercentFromBottom = (ScrollRange - ScrollPos) / ScrollRange;
    00180     //
    00181     // if drag top border up
    00182     //     Window.Top -= NumLines * PercentFromBottom;
    00183     //     Window.Bottom +=  NumLines - (NumLines * PercentFromBottom);
    00184     //
    00185     // if drag top border down
    00186     //     Window.Top += NumLines * PercentFromBottom;
    00187     //     Window.Bottom -=  NumLines - (NumLines * PercentFromBottom);
    00188     //
    00189     // if drag bottom border up
    00190     //     Window.Top -= NumLines * PercentFromTop;
    00191     //     Window.Bottom +=  NumLines - (NumLines * PercentFromTop);
    00192     //
    00193     // if drag bottom border down
    00194     //     Window.Top += NumLines * PercentFromTop;
    00195     //     Window.Bottom -=  NumLines - (NumLines * PercentFromTop);
    00196     //
    00197
    00198     ScrollRange = (SHORT)(ScreenInfo->ScreenBufferSize.X - CONSOLE_WINDOW_SIZE_X(ScreenInfo));
    00199     ScrollPos = ScreenInfo->Window.Left;
    00200
    00201     if (WindowPos->x != Console->WindowRect.left) {
    00202         SHORT NumLinesFromRight;
    00203         if (ScrollRange) {
    00204             NumLinesFromRight = DeltaX * (ScrollRange - ScrollPos) / ScrollRange;
    00205         } else {
    00206             NumLinesFromRight = DeltaX; // have scroll pos at left edge
    00207         }
    00208         ScreenInfo->Window.Left -= DeltaX - NumLinesFromRight;
    00209         ScreenInfo->Window.Right += NumLinesFromRight;
    00210     } else {
    00211         SHORT NumLinesFromLeft;
    00212         if (ScrollRange) {
    00213             NumLinesFromLeft = DeltaX * ScrollPos / ScrollRange;
    00214         } else {
    00215             NumLinesFromLeft = 0;   // have scroll pos at left edge
    00216         }
    00217         ScreenInfo->Window.Left -= NumLinesFromLeft;
    00218         ScreenInfo->Window.Right += DeltaX - NumLinesFromLeft;
    00219     }
    00220
    00221     ScrollRange = (SHORT)(ScreenInfo->ScreenBufferSize.Y - CONSOLE_WINDOW_SIZE_Y(ScreenInfo));
    00222     ScrollPos = ScreenInfo->Window.Top;
    00223     if (WindowPos->y != Console->WindowRect.top) {
    00224         SHORT NumLinesFromBottom;
    00225         if (ScrollRange) {
    00226             NumLinesFromBottom = DeltaY * (ScrollRange - ScrollPos) / ScrollRange;
    00227         } else {
    00228             NumLinesFromBottom = DeltaY; // have scroll pos at top edge
    00229         }
    00230         ScreenInfo->Window.Top -= DeltaY - NumLinesFromBottom;
    00231         ScreenInfo->Window.Bottom += NumLinesFromBottom;
    00232     } else {
    00233         SHORT NumLinesFromTop;
    00234         if (ScrollRange) {
    00235             NumLinesFromTop = DeltaY * ScrollPos / ScrollRange;
    00236         } else {
    00237             NumLinesFromTop = 0;   // have scroll pos at top edge
    00238         }
    00239         ScreenInfo->Window.Top -= NumLinesFromTop;
    00240         ScreenInfo->Window.Bottom += DeltaY - NumLinesFromTop;
    00241     }
    00242     }
    00243
    00244     if (ScreenInfo->WindowMaximizedX)
    00245         ASSERT (CONSOLE_WINDOW_SIZE_X(ScreenInfo) == ScreenInfo->ScreenBufferSize.X);
    00246     if (ScreenInfo->WindowMaximizedY)
    00247         ASSERT (CONSOLE_WINDOW_SIZE_Y(ScreenInfo) == ScreenInfo->ScreenBufferSize.Y);
    00248 #ifdef THERESES_DEBUG
    00249 DbgPrint("  WindowSize is now %d %d\n",CONSOLE_WINDOW_SIZE_X(ScreenInfo),CONSOLE_WINDOW_SIZE_Y(ScreenInfo));
    00250 DbgPrint("  window pos is now %d %d %d %d\n",WindowPos->x,
    00251                                          WindowPos->y,
    00252                                          WindowPos->cx,
    00253                                          WindowPos->cy);
    00254 #endif
    00255     Console->ResizeFlags = Flags | (Console->ResizeFlags & SCREEN_BUFFER_CHANGE);
    00256 }