[ACPPAGE] Make use of the PCH.
[reactos.git] / dll / cpl / console / layout.c
index fac40bb..9123a1f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * PROJECT:         ReactOS Console Configuration DLL
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            dll/win32/console/layout.c
+ * FILE:            dll/cpl/console/layout.c
  * PURPOSE:         Layout dialog
  * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@reactos.org)
  *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
 #define NDEBUG
 #include <debug.h>
 
-const WCHAR szPreviewText[] =
-    L"C:\\ReactOS> dir                       \n" \
-    L"SYSTEM       <DIR>      13-04-15  5:00a\n" \
-    L"SYSTEM32     <DIR>      13-04-15  5:00a\n" \
-    L"readme   txt       1739 13-04-15  5:00a\n" \
-    L"explorer exe    3329536 13-04-15  5:00a\n" \
-    L"vgafonts cab      18736 13-04-15  5:00a\n" \
-    L"setuplog txt        313 13-04-15  5:00a\n" \
-    L"win      ini       7005 13-04-15  5:00a\n" ;
+/* CONSOLE WINDOW PREVIEW Control *********************************************/
 
+#define WIN_PREVIEW_CLASS L"WinPreview"
 
-VOID
-PaintConsole(LPDRAWITEMSTRUCT drawItem,
-             PCONSOLE_PROPS pConInfo)
+typedef struct _WINPREV_DATA
+{
+    HWND hWnd;      // The window which this structure refers to
+    RECT rcMaxArea; // Maximum rectangle in which the preview window can be sized
+    SIZE siPreview; // Actual size of the preview window
+    SIZE siVirtScr; // Width and Height of the virtual screen
+    PVOID pData;    // Private data
+} WINPREV_DATA, *PWINPREV_DATA;
+
+static LRESULT CALLBACK
+WinPrevProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
+BOOL
+RegisterWinPrevClass(
+    IN HINSTANCE hInstance)
+{
+    WNDCLASSW WndClass;
+
+    WndClass.lpszClassName = WIN_PREVIEW_CLASS;
+    WndClass.lpfnWndProc = WinPrevProc;
+    WndClass.style = 0;
+    WndClass.hInstance = hInstance;
+    WndClass.hIcon = NULL;
+    WndClass.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_ARROW));
+    WndClass.hbrBackground =  (HBRUSH)(COLOR_BACKGROUND + 1);
+    WndClass.lpszMenuName = NULL;
+    WndClass.cbClsExtra = 0;
+    WndClass.cbWndExtra = 0; // sizeof(PWINPREV_DATA);
+
+    return (RegisterClassW(&WndClass) != 0);
+}
+
+BOOL
+UnRegisterWinPrevClass(
+    IN HINSTANCE hInstance)
+{
+    return UnregisterClassW(WIN_PREVIEW_CLASS, hInstance);
+}
+
+static VOID
+WinPrev_OnDisplayChange(
+    IN PWINPREV_DATA pData)
+{
+    // RECT rcNew;
+
+    pData->siVirtScr.cx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
+    pData->siVirtScr.cy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
+
+    /*
+     * The rescaling factor "siPreview / siVirtScr" should be the minimum of the ratios
+     *    pData->rcMaxArea.right  / pData->siVirtScr.cx , and
+     *    pData->rcMaxArea.bottom / pData->siVirtScr.cy ,
+     * or equivalently, the maximum of the inverse of these ratios.
+     * This condition is equivalent to the following inequality being tested.
+     */
+    // if (pData->siVirtScr.cx / pData->rcMaxArea.right >= pData->siVirtScr.cy / pData->rcMaxArea.bottom)
+    if (pData->siVirtScr.cx * pData->rcMaxArea.bottom >= pData->siVirtScr.cy * pData->rcMaxArea.right)
+    {
+        pData->siPreview.cx = MulDiv(pData->siVirtScr.cx, pData->rcMaxArea.right, pData->siVirtScr.cx);
+        pData->siPreview.cy = MulDiv(pData->siVirtScr.cy, pData->rcMaxArea.right, pData->siVirtScr.cx);
+    }
+    else
+    {
+        pData->siPreview.cx = MulDiv(pData->siVirtScr.cx, pData->rcMaxArea.bottom, pData->siVirtScr.cy);
+        pData->siPreview.cy = MulDiv(pData->siVirtScr.cy, pData->rcMaxArea.bottom, pData->siVirtScr.cy);
+    }
+
+    /*
+     * Now, the lengths in screen-units can be rescaled into preview-units with:
+     *    MulDiv(cx, pData->siPreview.cx, pData->siVirtScr.cx);
+     * and:
+     *    MulDiv(cy, pData->siPreview.cy, pData->siVirtScr.cy);
+     */
+
+#if 0 // TODO: Investigate!
+    /*
+     * Since both rcMaxArea and siPreview are client window area sizes,
+     * transform them into window sizes.
+     */
+    SetRect(&rcNew, 0, 0, pData->siPreview.cx, pData->siPreview.cy);
+    AdjustWindowRect(&rcNew,
+                     WS_BORDER,
+                     // GetWindowLongPtrW(pData->hWnd, GWL_STYLE) & ~WS_OVERLAPPED,
+                     FALSE);
+    OffsetRect(&rcNew, -rcNew.left, -rcNew.top);
+    rcNew.right += 2;
+    rcNew.bottom += 2;
+#endif
+
+    SetWindowPos(pData->hWnd,
+                 0 /* HWND_TOP */,
+                 0, 0,
+                 pData->siPreview.cx, pData->siPreview.cy,
+                 // rcNew.right, rcNew.bottom,
+                 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
+}
+
+#define RescaleCX(pData, len)   \
+    MulDiv((len), (pData)->siPreview.cx, (pData)->siVirtScr.cx)
+
+#define RescaleCY(pData, len)   \
+    MulDiv((len), (pData)->siPreview.cy, (pData)->siVirtScr.cy)
+
+#define RescaleRect(pData, rect)    \
+do { \
+    (rect).left   = RescaleCX((pData), (rect).left);    \
+    (rect).right  = RescaleCX((pData), (rect).right);   \
+    (rect).top    = RescaleCY((pData), (rect).top);     \
+    (rect).bottom = RescaleCY((pData), (rect).bottom);  \
+} while (0)
+
+#if 0
+static VOID
+WinPrev_OnSize(VOID)
+{
+}
+#endif
+
+static VOID
+WinPrev_OnDraw(
+    IN HDC hDC,
+    IN PWINPREV_DATA pData)
 {
-    PGUI_CONSOLE_INFO GuiInfo = pConInfo->TerminalInfo.TermInfo;
+    PCONSOLE_STATE_INFO pConInfo = (PCONSOLE_STATE_INFO)pData->pData;
     HBRUSH hBrush;
-    RECT cRect, fRect;
-    DWORD startx, starty;
-    DWORD endx, endy;
-    DWORD sizex, sizey;
+    RECT rcWin, fRect;
+    SIZE /*siBorder,*/ siFrame, siButton, siScroll;
+    SIZE resize;
+
+    RECT rcItem;
+
+    GetClientRect(pData->hWnd, &rcItem);
 
-    FillRect(drawItem->hDC, &drawItem->rcItem, GetSysColorBrush(COLOR_BACKGROUND));
+    /*
+     * Retrieve some system metrics and rescale them.
+     * They will be added separately, so that to always round the sizes up.
+     */
 
-    // FIXME: Use: SM_CXSIZE, SM_CYSIZE, SM_CXVSCROLL, SM_CYHSCROLL, SM_CXMIN, SM_CYMIN, SM_CXFRAME, SM_CYFRAME
-    /* Use it for scaling */
-    sizex = drawItem->rcItem.right  - drawItem->rcItem.left;
-    sizey = drawItem->rcItem.bottom - drawItem->rcItem.top ;
+    /* Don't care about border as it is almost always 1 and <= frame size */
+    /* Example: Frame = 4, or 13 ... while Border = 1 */
+    // siBorder.cx = GetSystemMetrics(SM_CXBORDER);
+    // siBorder.cy = GetSystemMetrics(SM_CYBORDER);
 
-    if ( GuiInfo->WindowOrigin.x == MAXDWORD &&
-         GuiInfo->WindowOrigin.y == MAXDWORD )
+    /* Window frame size */
+    siFrame.cx = GetSystemMetrics(SM_CXFRAME);
+    if (siFrame.cx > 0)
     {
-        startx = sizex / 3;
-        starty = sizey / 3;
+        siFrame.cx = RescaleCX(pData, siFrame.cx);
+        siFrame.cx = max(1, siFrame.cx);
+    }
+    siFrame.cy = GetSystemMetrics(SM_CYFRAME);
+    if (siFrame.cy > 0)
+    {
+        siFrame.cy = RescaleCY(pData, siFrame.cy);
+        siFrame.cy = max(1, siFrame.cy);
+    }
+
+    /* Window caption buttons */
+    siButton.cx = GetSystemMetrics(SM_CXSIZE);
+    siButton.cx = RescaleCX(pData, siButton.cx);
+    siButton.cx = max(1, siButton.cx);
+
+    siButton.cy = GetSystemMetrics(SM_CYSIZE);
+    siButton.cy = RescaleCY(pData, siButton.cy);
+    siButton.cy = max(1, siButton.cy);
+
+    /* Enlarge them for improving their appearance */
+    // siButton.cx *= 2;
+    siButton.cy *= 2;
+
+    /* Dimensions of the scrollbars */
+    siScroll.cx = GetSystemMetrics(SM_CXVSCROLL);
+    siScroll.cx = RescaleCX(pData, siScroll.cx);
+    siScroll.cx = max(1, siScroll.cx);
+
+    siScroll.cy = GetSystemMetrics(SM_CYHSCROLL);
+    siScroll.cy = RescaleCY(pData, siScroll.cy);
+    siScroll.cy = max(1, siScroll.cy);
+
+
+    // FIXME: Use SM_CXMIN, SM_CYMIN ??
+
+
+    /*
+     * Compute the console window layout
+     */
+
+    /* We start with the console client area, rescaled for the preview */
+    SetRect(&rcWin, 0, 0,
+            pConInfo->WindowSize.X * pConInfo->FontSize.X,
+            pConInfo->WindowSize.Y * pConInfo->FontSize.Y);
+    RescaleRect(pData, rcWin);
+
+    /* Add the scrollbars if needed (does not account for any frame) */
+    if (pConInfo->WindowSize.X < pConInfo->ScreenBufferSize.X)
+    {
+        /* Horizontal scrollbar */
+        rcWin.bottom += siScroll.cy;
+        // NOTE: If an additional exterior frame is needed, add +1
     }
     else
     {
-        // TODO:
-        // Calculate pos correctly when console centered
-        startx = GuiInfo->WindowOrigin.x;
-        starty = GuiInfo->WindowOrigin.y;
+        /* No scrollbar */
+        siScroll.cy = 0;
     }
+    if (pConInfo->WindowSize.Y < pConInfo->ScreenBufferSize.Y)
+    {
+        /* Vertical scrollbar */
+        rcWin.right += siScroll.cx;
+        // NOTE: If an additional exterior frame is needed, add +1
+    }
+    else
+    {
+        /* No scrollbar */
+        siScroll.cx = 0;
+    }
+
+    /* Add the title bar, taking into account the frames */
+    rcWin.top -= siButton.cy - 1;
+
+    /* If we have a non-zero window frame size, add an interior border and the frame */
+    resize.cx = (siFrame.cx > 0 ? 1 + siFrame.cx : 0);
+    resize.cy = (siFrame.cy > 0 ? 1 + siFrame.cy : 0);
+
+    /* Add the outer border */
+    ++resize.cx, ++resize.cy;
 
-    // TODO:
-    // Stretch console when bold fonts are selected
-    endx = startx + pConInfo->ci.ConsoleSize.X; // drawItem->rcItem.right - startx + 15;
-    endy = starty + pConInfo->ci.ConsoleSize.Y; // starty + sizey / 3;
+    InflateRect(&rcWin, resize.cx, resize.cy);
+
+    /* Finally, move the window rectangle back to its correct origin */
+    OffsetRect(&rcWin, -rcWin.left, -rcWin.top);
+
+    if ( pConInfo->WindowPosition.x == MAXDWORD &&
+         pConInfo->WindowPosition.y == MAXDWORD )
+    {
+        // OffsetRect(&rcWin, (rcItem.right - rcItem.left) / 3, (rcItem.bottom - rcItem.top) / 3);
+        OffsetRect(&rcWin, 0, 0);
+    }
+    else
+    {
+        OffsetRect(&rcWin,
+                   RescaleCX(pData, pConInfo->WindowPosition.x),
+                   RescaleCY(pData, pConInfo->WindowPosition.y));
+    }
 
-    /* Draw console size */
-    SetRect(&cRect, startx, starty, endx, endy);
-    FillRect(drawItem->hDC, &cRect, GetSysColorBrush(COLOR_WINDOWFRAME));
 
-    /* Draw console border */
-    SetRect(&fRect, startx + 1, starty + 1, cRect.right - 1, cRect.bottom - 1);
-    FrameRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER));
+    /*
+     * Paint the preview window
+     */
+
+    /* Fill the background with desktop colour */
+    FillRect(hDC, &rcItem, GetSysColorBrush(COLOR_BACKGROUND));
+
+    /*
+     * Draw the exterior frame. Use 'FillRect' instead of 'FrameRect'
+     * so that, when we want to draw frames around other elements,
+     * we can just instead separate them with space instead of redrawing
+     * a frame with 'FrameRect'.
+     */
+    FillRect(hDC, &rcWin, GetSysColorBrush(COLOR_WINDOWFRAME));
+    InflateRect(&rcWin, -1, -1);
+
+    /* Draw the border */
+    hBrush = GetSysColorBrush(COLOR_ACTIVEBORDER);
+    if (siFrame.cx > 0)
+    {
+        SetRect(&fRect, rcWin.left, rcWin.top, rcWin.left + siFrame.cx, rcWin.bottom);
+        FillRect(hDC, &fRect, hBrush);
+        SetRect(&fRect, rcWin.right - siFrame.cx, rcWin.top, rcWin.right, rcWin.bottom);
+        FillRect(hDC, &fRect, hBrush);
+
+        InflateRect(&rcWin, -siFrame.cx, 0);
+    }
+    if (siFrame.cy > 0)
+    {
+        SetRect(&fRect, rcWin.left, rcWin.top, rcWin.right, rcWin.top + siFrame.cy);
+        FillRect(hDC, &fRect, hBrush);
+        SetRect(&fRect, rcWin.left, rcWin.bottom - siFrame.cy, rcWin.right, rcWin.bottom);
+        FillRect(hDC, &fRect, hBrush);
+
+        InflateRect(&rcWin, 0, -siFrame.cy);
+    }
+
+    /* Draw the interior frame if we had a border */
+    if (siFrame.cx > 0 || siFrame.cy > 0)
+    {
+#if 0 // See the remark above
+        SetRect(&fRect, rcWin.left, rcWin.top, rcWin.right, rcWin.bottom);
+        FrameRect(hDC, &fRect, GetSysColorBrush(COLOR_WINDOWFRAME));
+#endif
+        InflateRect(&rcWin, (siFrame.cx > 0 ? -1 : 0), (siFrame.cy > 0 ? -1 : 0));
+    }
+
+    /* Draw the console window title bar */
+    hBrush = GetSysColorBrush(COLOR_BTNFACE);
 
-    /* Draw left box */
-    SetRect(&fRect, startx + 3, starty + 3, startx + 5, starty + 5);
-    FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER));
+    /* Draw the system menu (left button) */
+    SetRect(&fRect, rcWin.left, rcWin.top, rcWin.left + siButton.cx, rcWin.top + siButton.cy - 2);
+    // DrawFrameControl(hDC, &fRect, DFC_CAPTION, DFCS_CAPTIONCLOSE);
+    FillRect(hDC, &fRect, hBrush);
+    fRect.right++; // Separation
 
-    /* Draw window title */
-    SetRect(&fRect, startx + 7, starty + 3, cRect.right - 9, starty + 5);
-    FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVECAPTION));
+    /* Draw the caption bar */
+    SetRect(&fRect, fRect.right, fRect.top, rcWin.right - 2 * (siButton.cx + 1), fRect.bottom);
+    FillRect(hDC, &fRect, GetSysColorBrush(COLOR_ACTIVECAPTION));
+    fRect.right++; // Separation
 
-    /* Draw first right box */
-    SetRect(&fRect, fRect.right + 1, starty + 3, fRect.right + 3, starty + 5);
-    FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER));
+    /* Draw the minimize menu (first right button) */
+    SetRect(&fRect, fRect.right, fRect.top, fRect.right + siButton.cx, fRect.bottom);
+    // DrawFrameControl(hDC, &fRect, DFC_CAPTION, DFCS_CAPTIONMIN);
+    FillRect(hDC, &fRect, hBrush);
+    fRect.right++; // Separation
 
-    /* Draw second right box */
-    SetRect(&fRect, fRect.right + 1, starty + 3, fRect.right + 3, starty + 5);
-    FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER));
+    /* Draw the maximize menu (second right button) */
+    SetRect(&fRect, fRect.right, fRect.top, fRect.right + siButton.cx, fRect.bottom);
+    // DrawFrameControl(hDC, &fRect, DFC_CAPTION, DFCS_CAPTIONMAX);
+    FillRect(hDC, &fRect, hBrush);
 
-    /* Draw scrollbar */
-    SetRect(&fRect, cRect.right - 5, fRect.bottom + 1, cRect.right - 3, cRect.bottom - 3);
-    FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_SCROLLBAR));
+    rcWin.top += siButton.cy - 1;
 
-    /* Draw console background */
-    hBrush = CreateSolidBrush(pConInfo->ci.Colors[BkgdAttribFromAttrib(pConInfo->ci.ScreenAttrib)]);
-    SetRect(&fRect, startx + 3, starty + 6, cRect.right - 6, cRect.bottom - 3);
-    FillRect(drawItem->hDC, &fRect, hBrush);
-    DeleteObject((HGDIOBJ)hBrush);
+    /* Add the scrollbars if needed */
+    if (siScroll.cy > 0 || siScroll.cx > 0)
+    {
+        LONG right, bottom;
+
+        right  = rcWin.right;
+        bottom = rcWin.bottom;
+
+        /*
+         * If both the horizontal and vertical scrollbars are present,
+         * reserve some space for the "dead square" at the bottom right.
+         */
+        if (siScroll.cy > 0 && siScroll.cx > 0)
+        {
+            right  -= (1 + siScroll.cx);
+            bottom -= (1 + siScroll.cy);
+        }
+
+        hBrush = GetSysColorBrush(COLOR_SCROLLBAR);
+
+        /* Horizontal scrollbar */
+        if (siScroll.cy > 0)
+        {
+            SetRect(&fRect, rcWin.left, rcWin.bottom - siScroll.cy, right, rcWin.bottom);
+            FillRect(hDC, &fRect, hBrush);
+        }
+
+        /* Vertical scrollbar */
+        if (siScroll.cx > 0)
+        {
+            SetRect(&fRect, rcWin.right - siScroll.cx, rcWin.top, rcWin.right, bottom);
+            FillRect(hDC, &fRect, hBrush);
+        }
+
+        /*
+         * If both the horizontal and vertical scrollbars are present,
+         * draw the "dead square" at the bottom right.
+         */
+        if (siScroll.cy > 0 && siScroll.cx > 0)
+        {
+            SetRect(&fRect, rcWin.right - siScroll.cx, rcWin.bottom - siScroll.cy, rcWin.right, rcWin.bottom);
+            FillRect(hDC, &fRect, hBrush);
+        }
+
+        // NOTE: If an additional exterior frame is needed, remove +1 for each direction
+        rcWin.right  -= siScroll.cx;
+        rcWin.bottom -= siScroll.cy;
+    }
+
+    /* Draw the console background */
+    hBrush = CreateSolidBrush(pConInfo->ColorTable[BkgdAttribFromAttrib(pConInfo->ScreenAttributes)]);
+    FillRect(hDC, &rcWin, hBrush);
+    DeleteObject(hBrush);
 }
 
-BOOL
-PaintText(LPDRAWITEMSTRUCT drawItem,
-          PCONSOLE_PROPS pConInfo,
-          TEXT_TYPE TextMode)
+static LRESULT CALLBACK
+WinPrevProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    PWINPREV_DATA pData;
+
+    pData = (PWINPREV_DATA)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
+
+    switch (msg)
+    {
+        case WM_CREATE:
+        {
+            pData = (PWINPREV_DATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pData));
+            if (!pData)
+            {
+                /* We failed to allocate our private data, halt the window creation */
+                return (LRESULT)-1;
+            }
+            pData->hWnd  = hWnd;
+            pData->pData = ConInfo;
+            GetClientRect(pData->hWnd, &pData->rcMaxArea);
+            // LPCREATESTRUCT::cx and cy give window (not client) size
+            WinPrev_OnDisplayChange(pData);
+            SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pData);
+            break;
+        }
+
+        case WM_DESTROY:
+        {
+            if (pData)
+                HeapFree(GetProcessHeap(), 0, pData);
+            break;
+        }
+
+        case WM_DISPLAYCHANGE:
+        {
+            WinPrev_OnDisplayChange(pData);
+            UpdateWindow(hWnd);
+            // InvalidateRect(hWnd, NULL, FALSE);
+            break;
+        }
+
+        case WM_SIZE:
+            break;
+
+        case WM_ERASEBKGND:
+            return 1;
+
+        case WM_PAINT:
+        {
+            PAINTSTRUCT ps;
+            BeginPaint(hWnd, &ps);
+            WinPrev_OnDraw(ps.hdc, pData);
+            EndPaint(hWnd, &ps);
+            return 0;
+        }
+    }
+
+    return DefWindowProcW(hWnd, msg, wParam, lParam);
+}
+
+
+/* CONSOLE TEXT PREVIEW *******************************************************/
+
+const WCHAR szPreviewText[] =
+    L"C:\\ReactOS> dir                       \n" \
+    L"SYSTEM       <DIR>      13-04-15  5:00a\n" \
+    L"SYSTEM32     <DIR>      13-04-15  5:00a\n" \
+    L"readme   txt       1739 13-04-15  5:00a\n" \
+    L"explorer exe    3329536 13-04-15  5:00a\n" \
+    L"vgafonts cab      18736 13-04-15  5:00a\n" \
+    L"setuplog txt        313 13-04-15  5:00a\n" \
+    L"win      ini       7005 13-04-15  5:00a\n" ;
+
+VOID
+PaintText(
+    IN LPDRAWITEMSTRUCT drawItem,
+    IN PCONSOLE_STATE_INFO pConInfo,
+    IN TEXT_TYPE TextMode)
 {
-    PGUI_CONSOLE_INFO GuiInfo = pConInfo->TerminalInfo.TermInfo;
     USHORT CurrentAttrib;
     COLORREF pbkColor, ptColor;
     COLORREF nbkColor, ntColor;
     HBRUSH hBrush;
-    HFONT Font, OldFont;
+    HFONT hOldFont;
 
     if (TextMode == Screen)
-        CurrentAttrib = pConInfo->ci.ScreenAttrib;
+        CurrentAttrib = pConInfo->ScreenAttributes;
     else if (TextMode == Popup)
-        CurrentAttrib = pConInfo->ci.PopupAttrib;
+        CurrentAttrib = pConInfo->PopupAttributes;
     else
-        return FALSE;
+        return;
 
-    nbkColor = pConInfo->ci.Colors[BkgdAttribFromAttrib(CurrentAttrib)];
-    ntColor  = pConInfo->ci.Colors[TextAttribFromAttrib(CurrentAttrib)];
+    nbkColor = pConInfo->ColorTable[BkgdAttribFromAttrib(CurrentAttrib)];
+    ntColor  = pConInfo->ColorTable[TextAttribFromAttrib(CurrentAttrib)];
 
     hBrush = CreateSolidBrush(nbkColor);
-    if (!hBrush) return FALSE;
-
-    Font = CreateFontW(GuiInfo->FontSize.Y,
-                       0, // GuiInfo->FontSize.X,
-                       0,
-                       TA_BASELINE,
-                       GuiInfo->FontWeight,
-                       FALSE,
-                       FALSE,
-                       FALSE,
-                       OEM_CHARSET,
-                       OUT_DEFAULT_PRECIS,
-                       CLIP_DEFAULT_PRECIS,
-                       NONANTIALIASED_QUALITY,
-                       FIXED_PITCH | GuiInfo->FontFamily /* FF_DONTCARE */,
-                       GuiInfo->FaceName);
-    if (Font == NULL)
-    {
-        DPRINT1("PaintText: CreateFont failed\n");
-        return FALSE;
-    }
+    if (!hBrush) return;
 
-    OldFont = SelectObject(drawItem->hDC, Font);
-    if (OldFont == NULL)
-    {
-        DeleteObject(Font);
-        return FALSE;
-    }
+    hOldFont = SelectObject(drawItem->hDC, hCurrentFont);
+    //if (hOldFont == NULL)
+    //{
+    //    DeleteObject(hBrush);
+    //    return;
+    //}
 
     FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
 
-    ptColor = SetTextColor(drawItem->hDC, ntColor);
+    /* Add a few space between the preview window border and the text sample */
+    InflateRect(&drawItem->rcItem, -2, -2);
+
+    ptColor  = SetTextColor(drawItem->hDC, ntColor);
     pbkColor = SetBkColor(drawItem->hDC, nbkColor);
-    DrawTextW(drawItem->hDC, szPreviewText, wcslen(szPreviewText), &drawItem->rcItem, 0);
+    DrawTextW(drawItem->hDC, szPreviewText, (INT)wcslen(szPreviewText), &drawItem->rcItem, 0);
     SetTextColor(drawItem->hDC, ptColor);
     SetBkColor(drawItem->hDC, pbkColor);
-    DeleteObject((HGDIOBJ)hBrush);
-
-    SelectObject(drawItem->hDC, OldFont);
-    DeleteObject(Font);
 
-    return TRUE;
+    SelectObject(drawItem->hDC, hOldFont);
+    DeleteObject(hBrush);
 }
 
+
+/* LAYOUT DIALOG **************************************************************/
+
 INT_PTR
 CALLBACK
-LayoutProc(HWND hwndDlg,
+LayoutProc(HWND hDlg,
            UINT uMsg,
            WPARAM wParam,
            LPARAM lParam)
 {
-    PCONSOLE_PROPS pConInfo = (PCONSOLE_PROPS)GetWindowLongPtr(hwndDlg, DWLP_USER);
-    PGUI_CONSOLE_INFO GuiInfo = (pConInfo ? pConInfo->TerminalInfo.TermInfo : NULL);
-
-    UNREFERENCED_PARAMETER(hwndDlg);
-    UNREFERENCED_PARAMETER(wParam);
-
     switch (uMsg)
     {
         case WM_INITDIALOG:
@@ -184,11 +530,6 @@ LayoutProc(HWND hwndDlg,
             LONG cxVirtScr, cyVirtScr; // Width and Height of the virtual screen
             LONG cxFrame  , cyFrame  ; // Thickness of the window frame
 
-            pConInfo = (PCONSOLE_PROPS)((LPPROPSHEETPAGE)lParam)->lParam;
-            GuiInfo  = pConInfo->TerminalInfo.TermInfo;
-            SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo);
-
-            /* Multi-monitor support */
             xVirtScr  = GetSystemMetrics(SM_XVIRTUALSCREEN);
             yVirtScr  = GetSystemMetrics(SM_YVIRTUALSCREEN);
             cxVirtScr = GetSystemMetrics(SM_CXVIRTUALSCREEN);
@@ -196,50 +537,52 @@ LayoutProc(HWND hwndDlg,
             cxFrame   = GetSystemMetrics(SM_CXFRAME);
             cyFrame   = GetSystemMetrics(SM_CYFRAME);
 
-            SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT, UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
-            SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_SCREEN_BUFFER_WIDTH , UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
-            SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_WINDOW_SIZE_HEIGHT, UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
-            SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_WINDOW_SIZE_WIDTH , UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
+            SendDlgItemMessageW(hDlg, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT, UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
+            SendDlgItemMessageW(hDlg, IDC_UPDOWN_SCREEN_BUFFER_WIDTH , UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
+            SendDlgItemMessageW(hDlg, IDC_UPDOWN_WINDOW_SIZE_HEIGHT, UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
+            SendDlgItemMessageW(hDlg, IDC_UPDOWN_WINDOW_SIZE_WIDTH , UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
 
-            SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, pConInfo->ci.ScreenBufferSize.Y, FALSE);
-            SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH , pConInfo->ci.ScreenBufferSize.X, FALSE);
-            SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, pConInfo->ci.ConsoleSize.Y, FALSE);
-            SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH , pConInfo->ci.ConsoleSize.X, FALSE);
+            SetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, ConInfo->ScreenBufferSize.Y, FALSE);
+            SetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH , ConInfo->ScreenBufferSize.X, FALSE);
+            SetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, ConInfo->WindowSize.Y, FALSE);
+            SetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_WIDTH , ConInfo->WindowSize.X, FALSE);
 
-            SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT, UDM_SETRANGE, 0,
+            SendDlgItemMessageW(hDlg, IDC_UPDOWN_WINDOW_POS_LEFT, UDM_SETRANGE, 0,
                                 (LPARAM)MAKELONG(xVirtScr + cxVirtScr - cxFrame, xVirtScr - cxFrame));
-            SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP , UDM_SETRANGE, 0,
+            SendDlgItemMessageW(hDlg, IDC_UPDOWN_WINDOW_POS_TOP , UDM_SETRANGE, 0,
                                 (LPARAM)MAKELONG(yVirtScr + cyVirtScr - cyFrame, yVirtScr - cyFrame));
 
-            SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, GuiInfo->WindowOrigin.x, TRUE);
-            SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP , GuiInfo->WindowOrigin.y, TRUE);
+            SetDlgItemInt(hDlg, IDC_EDIT_WINDOW_POS_LEFT, ConInfo->WindowPosition.x, TRUE);
+            SetDlgItemInt(hDlg, IDC_EDIT_WINDOW_POS_TOP , ConInfo->WindowPosition.y, TRUE);
 
-            if (GuiInfo->AutoPosition)
+            if (ConInfo->AutoPosition)
             {
-                EnableDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, FALSE);
-                EnableDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_TOP , FALSE);
-                EnableDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT, FALSE);
-                EnableDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP , FALSE);
+                EnableDlgItem(hDlg, IDC_EDIT_WINDOW_POS_LEFT, FALSE);
+                EnableDlgItem(hDlg, IDC_EDIT_WINDOW_POS_TOP , FALSE);
+                EnableDlgItem(hDlg, IDC_UPDOWN_WINDOW_POS_LEFT, FALSE);
+                EnableDlgItem(hDlg, IDC_UPDOWN_WINDOW_POS_TOP , FALSE);
             }
-            CheckDlgButton(hwndDlg, IDC_CHECK_SYSTEM_POS_WINDOW,
-                           GuiInfo->AutoPosition ? BST_CHECKED : BST_UNCHECKED);
+            CheckDlgButton(hDlg, IDC_CHECK_SYSTEM_POS_WINDOW,
+                           ConInfo->AutoPosition ? BST_CHECKED : BST_UNCHECKED);
 
             return TRUE;
         }
 
-        case WM_DRAWITEM:
+        case WM_DISPLAYCHANGE:
         {
-            PaintConsole((LPDRAWITEMSTRUCT)lParam, pConInfo);
-            return TRUE;
+            /* Retransmit to the preview window */
+            SendDlgItemMessageW(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW,
+                                WM_DISPLAYCHANGE, wParam, lParam);
+            break;
         }
 
         case WM_NOTIFY:
         {
-            LPNMUPDOWN  lpnmud =  (LPNMUPDOWN)lParam;
-            LPPSHNOTIFY lppsn  = (LPPSHNOTIFY)lParam;
+            LPPSHNOTIFY lppsn = (LPPSHNOTIFY)lParam;
 
             if (lppsn->hdr.code == UDN_DELTAPOS)
             {
+                LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
                 DWORD wheight, wwidth;
                 DWORD sheight, swidth;
                 DWORD left, top;
@@ -250,7 +593,7 @@ LayoutProc(HWND hwndDlg,
                 }
                 else
                 {
-                    wwidth = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, NULL, FALSE);
+                    wwidth = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, NULL, FALSE);
                 }
 
                 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_SIZE_HEIGHT)
@@ -259,7 +602,7 @@ LayoutProc(HWND hwndDlg,
                 }
                 else
                 {
-                    wheight = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, NULL, FALSE);
+                    wheight = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, NULL, FALSE);
                 }
 
                 if (lppsn->hdr.idFrom == IDC_UPDOWN_SCREEN_BUFFER_WIDTH)
@@ -268,7 +611,7 @@ LayoutProc(HWND hwndDlg,
                 }
                 else
                 {
-                    swidth = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, NULL, FALSE);
+                    swidth = GetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, NULL, FALSE);
                 }
 
                 if (lppsn->hdr.idFrom == IDC_UPDOWN_SCREEN_BUFFER_HEIGHT)
@@ -277,7 +620,7 @@ LayoutProc(HWND hwndDlg,
                 }
                 else
                 {
-                    sheight = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, NULL, FALSE);
+                    sheight = GetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, NULL, FALSE);
                 }
 
                 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_POS_LEFT)
@@ -286,7 +629,7 @@ LayoutProc(HWND hwndDlg,
                 }
                 else
                 {
-                    left = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, TRUE);
+                    left = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, TRUE);
                 }
 
                 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_POS_TOP)
@@ -295,7 +638,7 @@ LayoutProc(HWND hwndDlg,
                 }
                 else
                 {
-                    top = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, NULL, TRUE);
+                    top = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_POS_TOP, NULL, TRUE);
                 }
 
                 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_SIZE_WIDTH || lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_SIZE_HEIGHT)
@@ -303,12 +646,12 @@ LayoutProc(HWND hwndDlg,
                     /* Automatically adjust screen buffer size when window size enlarges */
                     if (wwidth >= swidth)
                     {
-                        SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, wwidth, TRUE);
+                        SetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, wwidth, TRUE);
                         swidth = wwidth;
                     }
                     if (wheight >= sheight)
                     {
-                        SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, wheight, TRUE);
+                        SetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, wheight, TRUE);
                         sheight = wheight;
                     }
                 }
@@ -322,189 +665,188 @@ LayoutProc(HWND hwndDlg,
                     /* Automatically adjust window size when screen buffer decreases */
                     if (wwidth > swidth)
                     {
-                        SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, swidth, TRUE);
+                        SetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, swidth, TRUE);
                         wwidth = swidth;
                     }
                     if (wheight > sheight)
                     {
-                        SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, sheight, TRUE);
+                        SetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, sheight, TRUE);
                         wheight = sheight;
                     }
                 }
 
-                pConInfo->ci.ScreenBufferSize.X = (SHORT)swidth;
-                pConInfo->ci.ScreenBufferSize.Y = (SHORT)sheight;
-                pConInfo->ci.ConsoleSize.X = (SHORT)wwidth;
-                pConInfo->ci.ConsoleSize.Y = (SHORT)wheight;
-                GuiInfo->WindowOrigin.x = left;
-                GuiInfo->WindowOrigin.y = top;
-                PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                ConInfo->ScreenBufferSize.X = (SHORT)swidth;
+                ConInfo->ScreenBufferSize.Y = (SHORT)sheight;
+                ConInfo->WindowSize.X = (SHORT)wwidth;
+                ConInfo->WindowSize.Y = (SHORT)wheight;
+                ConInfo->WindowPosition.x = left;
+                ConInfo->WindowPosition.y = top;
+
+                InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW), NULL, TRUE);
+                PropSheet_Changed(GetParent(hDlg), hDlg);
             }
             break;
         }
 
         case WM_COMMAND:
         {
-            switch (LOWORD(wParam))
+            if (HIWORD(wParam) == EN_KILLFOCUS)
             {
+                switch (LOWORD(wParam))
+                {
                 case IDC_EDIT_SCREEN_BUFFER_WIDTH:
                 {
-                    if (HIWORD(wParam) == EN_KILLFOCUS)
-                    {
-                        DWORD swidth, wwidth;
+                    DWORD swidth, wwidth;
 
-                        swidth = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, NULL, FALSE);
-                        wwidth = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH  , NULL, FALSE);
-
-                        /* Be sure that the (new) screen buffer width is in the correct range */
-                        swidth = min(max(swidth, 1), 0xFFFF);
+                    swidth = GetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, NULL, FALSE);
+                    wwidth = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_WIDTH  , NULL, FALSE);
 
-                        /* Automatically adjust window size when screen buffer decreases */
-                        if (wwidth > swidth)
-                        {
-                            wwidth = swidth;
-                            SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, wwidth, TRUE);
-                        }
+                    /* Be sure that the (new) screen buffer width is in the correct range */
+                    swidth = min(max(swidth, 1), 0xFFFF);
 
-                        pConInfo->ci.ScreenBufferSize.X = (SHORT)swidth;
-                        pConInfo->ci.ConsoleSize.X      = (SHORT)wwidth;
-                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                    /* Automatically adjust window size when screen buffer decreases */
+                    if (wwidth > swidth)
+                    {
+                        wwidth = swidth;
+                        SetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, wwidth, TRUE);
                     }
+
+                    ConInfo->ScreenBufferSize.X = (SHORT)swidth;
+                    ConInfo->WindowSize.X       = (SHORT)wwidth;
+
+                    InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW), NULL, TRUE);
+                    PropSheet_Changed(GetParent(hDlg), hDlg);
                     break;
                 }
 
                 case IDC_EDIT_WINDOW_SIZE_WIDTH:
                 {
-                    if (HIWORD(wParam) == EN_KILLFOCUS)
-                    {
-                        DWORD swidth, wwidth;
+                    DWORD swidth, wwidth;
 
-                        swidth = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, NULL, FALSE);
-                        wwidth = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH  , NULL, FALSE);
+                    swidth = GetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, NULL, FALSE);
+                    wwidth = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_WIDTH  , NULL, FALSE);
 
-                        /* Automatically adjust screen buffer size when window size enlarges */
-                        if (wwidth >= swidth)
-                        {
-                            swidth = wwidth;
-
-                            /* Be sure that the (new) screen buffer width is in the correct range */
-                            swidth = min(max(swidth, 1), 0xFFFF);
+                    /* Automatically adjust screen buffer size when window size enlarges */
+                    if (wwidth >= swidth)
+                    {
+                        swidth = wwidth;
 
-                            SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, swidth, TRUE);
-                        }
+                        /* Be sure that the (new) screen buffer width is in the correct range */
+                        swidth = min(max(swidth, 1), 0xFFFF);
 
-                        pConInfo->ci.ScreenBufferSize.X = (SHORT)swidth;
-                        pConInfo->ci.ConsoleSize.X      = (SHORT)wwidth;
-                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                        SetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, swidth, TRUE);
                     }
+
+                    ConInfo->ScreenBufferSize.X = (SHORT)swidth;
+                    ConInfo->WindowSize.X       = (SHORT)wwidth;
+
+                    InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW), NULL, TRUE);
+                    PropSheet_Changed(GetParent(hDlg), hDlg);
                     break;
                 }
 
                 case IDC_EDIT_SCREEN_BUFFER_HEIGHT:
                 {
-                    if (HIWORD(wParam) == EN_KILLFOCUS)
-                    {
-                        DWORD sheight, wheight;
+                    DWORD sheight, wheight;
 
-                        sheight = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, NULL, FALSE);
-                        wheight = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT  , NULL, FALSE);
+                    sheight = GetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, NULL, FALSE);
+                    wheight = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT  , NULL, FALSE);
 
-                        /* Be sure that the (new) screen buffer width is in the correct range */
-                        sheight = min(max(sheight, 1), 0xFFFF);
-
-                        /* Automatically adjust window size when screen buffer decreases */
-                        if (wheight > sheight)
-                        {
-                            wheight = sheight;
-                            SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, wheight, TRUE);
-                        }
+                    /* Be sure that the (new) screen buffer width is in the correct range */
+                    sheight = min(max(sheight, 1), 0xFFFF);
 
-                        pConInfo->ci.ScreenBufferSize.Y = (SHORT)sheight;
-                        pConInfo->ci.ConsoleSize.Y      = (SHORT)wheight;
-                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                    /* Automatically adjust window size when screen buffer decreases */
+                    if (wheight > sheight)
+                    {
+                        wheight = sheight;
+                        SetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, wheight, TRUE);
                     }
+
+                    ConInfo->ScreenBufferSize.Y = (SHORT)sheight;
+                    ConInfo->WindowSize.Y       = (SHORT)wheight;
+
+                    InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW), NULL, TRUE);
+                    PropSheet_Changed(GetParent(hDlg), hDlg);
                     break;
                 }
 
                 case IDC_EDIT_WINDOW_SIZE_HEIGHT:
                 {
-                    if (HIWORD(wParam) == EN_KILLFOCUS)
-                    {
-                        DWORD sheight, wheight;
+                    DWORD sheight, wheight;
 
-                        sheight = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, NULL, FALSE);
-                        wheight = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT  , NULL, FALSE);
+                    sheight = GetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, NULL, FALSE);
+                    wheight = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT  , NULL, FALSE);
 
-                        /* Automatically adjust screen buffer size when window size enlarges */
-                        if (wheight >= sheight)
-                        {
-                            sheight = wheight;
-
-                            /* Be sure that the (new) screen buffer width is in the correct range */
-                            sheight = min(max(sheight, 1), 0xFFFF);
+                    /* Automatically adjust screen buffer size when window size enlarges */
+                    if (wheight >= sheight)
+                    {
+                        sheight = wheight;
 
-                            SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, sheight, TRUE);
-                        }
+                        /* Be sure that the (new) screen buffer width is in the correct range */
+                        sheight = min(max(sheight, 1), 0xFFFF);
 
-                        pConInfo->ci.ScreenBufferSize.Y = (SHORT)sheight;
-                        pConInfo->ci.ConsoleSize.Y      = (SHORT)wheight;
-                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                        SetDlgItemInt(hDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, sheight, TRUE);
                     }
+
+                    ConInfo->ScreenBufferSize.Y = (SHORT)sheight;
+                    ConInfo->WindowSize.Y       = (SHORT)wheight;
+
+                    InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW), NULL, TRUE);
+                    PropSheet_Changed(GetParent(hDlg), hDlg);
                     break;
                 }
 
                 case IDC_EDIT_WINDOW_POS_LEFT:
                 case IDC_EDIT_WINDOW_POS_TOP:
                 {
-                    if (HIWORD(wParam) == EN_KILLFOCUS)
-                    {
-                        DWORD left, top;
+                    ConInfo->WindowPosition.x = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, TRUE);
+                    ConInfo->WindowPosition.y = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_POS_TOP , NULL, TRUE);
 
-                        left = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, TRUE);
-                        top  = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP , NULL, TRUE);
-
-                        GuiInfo->WindowOrigin.x = left;
-                        GuiInfo->WindowOrigin.y = top;
-                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
-                    }
+                    InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW), NULL, TRUE);
+                    PropSheet_Changed(GetParent(hDlg), hDlg);
                     break;
                 }
+                }
+            }
+            else
+            if (HIWORD(wParam) == BN_CLICKED &&
+                LOWORD(wParam) == IDC_CHECK_SYSTEM_POS_WINDOW)
+            {
+                if (IsDlgButtonChecked(hDlg, IDC_CHECK_SYSTEM_POS_WINDOW) == BST_CHECKED)
+                {
+                    EnableDlgItem(hDlg, IDC_EDIT_WINDOW_POS_LEFT, FALSE);
+                    EnableDlgItem(hDlg, IDC_EDIT_WINDOW_POS_TOP , FALSE);
+                    EnableDlgItem(hDlg, IDC_UPDOWN_WINDOW_POS_LEFT, FALSE);
+                    EnableDlgItem(hDlg, IDC_UPDOWN_WINDOW_POS_TOP , FALSE);
+
+                    ConInfo->AutoPosition = TRUE;
+                    // Do not touch ConInfo->WindowPosition !!
 
-                case IDC_CHECK_SYSTEM_POS_WINDOW:
+                    InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW), NULL, TRUE);
+                    PropSheet_Changed(GetParent(hDlg), hDlg);
+                }
+                else
                 {
-                    LONG res = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
-                    if (res == BST_CHECKED)
-                    {
-                        ULONG left, top;
+                    ULONG left, top;
 
-                        left = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, TRUE);
-                        top  = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP , NULL, TRUE);
+                    left = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, TRUE);
+                    top  = GetDlgItemInt(hDlg, IDC_EDIT_WINDOW_POS_TOP , NULL, TRUE);
 
-                        GuiInfo->AutoPosition   = FALSE;
-                        GuiInfo->WindowOrigin.x = left;
-                        GuiInfo->WindowOrigin.y = top;
-                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                    EnableDlgItem(hDlg, IDC_EDIT_WINDOW_POS_LEFT, TRUE);
+                    EnableDlgItem(hDlg, IDC_EDIT_WINDOW_POS_TOP , TRUE);
+                    EnableDlgItem(hDlg, IDC_UPDOWN_WINDOW_POS_LEFT, TRUE);
+                    EnableDlgItem(hDlg, IDC_UPDOWN_WINDOW_POS_TOP , TRUE);
 
-                        SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
-                        EnableDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, TRUE);
-                        EnableDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_TOP , TRUE);
-                        EnableDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT, TRUE);
-                        EnableDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP , TRUE);
-                    }
-                    else if (res == BST_UNCHECKED)
-                    {
-                        GuiInfo->AutoPosition = TRUE;
-                        // Do not touch GuiInfo->WindowOrigin !!
-                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
-
-                        SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
-                        EnableDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, FALSE);
-                        EnableDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_TOP , FALSE);
-                        EnableDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT, FALSE);
-                        EnableDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP , FALSE);
-                    }
+                    ConInfo->AutoPosition     = FALSE;
+                    ConInfo->WindowPosition.x = left;
+                    ConInfo->WindowPosition.y = top;
+
+                    InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_LAYOUT_WINDOW_PREVIEW), NULL, TRUE);
+                    PropSheet_Changed(GetParent(hDlg), hDlg);
                 }
             }
+
+            break;
         }
 
         default: