[WIN32SS][WINSRV] Fullwidth character handling Part 2 (#2240)
[reactos.git] / win32ss / user / winsrv / consrv / frontends / gui / conwnd.c
index 9da1e92..633317c 100644 (file)
@@ -20,7 +20,7 @@
 #define NDEBUG
 #include <debug.h>
 
-#include "font.h"
+#include "concfg/font.h"
 #include "guiterm.h"
 #include "resource.h"
 
@@ -149,7 +149,7 @@ RegisterConWndClass(IN HINSTANCE hInstance)
     WndClass.hIcon = ghDefaultIcon;
     WndClass.hIconSm = ghDefaultIconSm;
     WndClass.hCursor = ghDefaultCursor;
-    WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // The color of a terminal when it is switched off.
+    WndClass.hbrBackground = NULL;
     WndClass.lpszMenuName = NULL;
     WndClass.cbClsExtra = 0;
     WndClass.cbWndExtra = GWLP_CONWND_ALLOC;
@@ -231,30 +231,32 @@ VOID
 CreateSysMenu(HWND hWnd)
 {
     MENUITEMINFOW mii;
+    HMENU hMenu;
+    PWCHAR ptrTab;
     WCHAR szMenuStringBack[255];
-    WCHAR *ptrTab;
-    HMENU hMenu = GetSystemMenu(hWnd, FALSE);
-    if (hMenu != NULL)
-    {
-        mii.cbSize = sizeof(mii);
-        mii.fMask = MIIM_STRING;
-        mii.dwTypeData = szMenuStringBack;
-        mii.cch = sizeof(szMenuStringBack)/sizeof(WCHAR);
 
-        GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
+    hMenu = GetSystemMenu(hWnd, FALSE);
+    if (hMenu == NULL)
+        return;
 
-        ptrTab = wcschr(szMenuStringBack, '\t');
-        if (ptrTab)
-        {
-           *ptrTab = '\0';
-           mii.cch = wcslen(szMenuStringBack);
+    mii.cbSize = sizeof(mii);
+    mii.fMask = MIIM_STRING;
+    mii.dwTypeData = szMenuStringBack;
+    mii.cch = ARRAYSIZE(szMenuStringBack);
 
-           SetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
-        }
+    GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
 
-        AppendMenuItems(hMenu, GuiConsoleMainMenuItems);
-        DrawMenuBar(hWnd);
+    ptrTab = wcschr(szMenuStringBack, L'\t');
+    if (ptrTab)
+    {
+        *ptrTab = L'\0';
+        mii.cch = wcslen(szMenuStringBack);
+
+        SetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
     }
+
+    AppendMenuItems(hMenu, GuiConsoleMainMenuItems);
+    DrawMenuBar(hWnd);
 }
 
 static VOID
@@ -597,6 +599,7 @@ OnNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
     Console = GuiData->Console;
 
     GuiData->hWindow = hWnd;
+    GuiData->hSysMenu = GetSystemMenu(hWnd, FALSE);
 
     /* Initialize the fonts */
     if (!InitFonts(GuiData,
@@ -1014,6 +1017,8 @@ OnPaint(PGUI_CONSOLE_DATA GuiData)
             PaintSelectionRect(GuiData, &ps);
         }
 
+        // TODO: Move cursor display here!
+
         LeaveCriticalSection(&GuiData->Lock);
     }
     EndPaint(GuiData->hWindow, &ps);
@@ -1370,6 +1375,7 @@ OnNcDestroy(HWND hWnd)
     /* Free the GuiData registration */
     SetWindowLongPtrW(hWnd, GWLP_USERDATA, (DWORD_PTR)NULL);
 
+    /* Reset the system menu back to default and destroy the previous menu */
     GetSystemMenu(hWnd, TRUE);
 
     if (GuiData)
@@ -2031,7 +2037,7 @@ OnSize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
     PCONSRV_CONSOLE Console = GuiData->Console;
 
     /* Do nothing if the window is hidden */
-    if (!GuiData->IsWindowVisible) return;
+    if (!GuiData->IsWindowVisible || IsIconic(GuiData->hWindow)) return;
 
     if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) return;
 
@@ -2061,8 +2067,8 @@ OnSize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
         if ((windy % HeightUnit) >= (HeightUnit / 2)) ++chary;
 
         /* Compensate for added scroll bars in window */
-        if (charx < (DWORD)Buff->ScreenBufferSize.X) windy -= GetSystemMetrics(SM_CYHSCROLL); // Window will have a horizontal scroll bar
-        if (chary < (DWORD)Buff->ScreenBufferSize.Y) windx -= GetSystemMetrics(SM_CXVSCROLL); // Window will have a vertical scroll bar
+        if (Buff->ViewSize.X < Buff->ScreenBufferSize.X) windy -= GetSystemMetrics(SM_CYHSCROLL); // Window will have a horizontal scroll bar
+        if (Buff->ViewSize.Y < Buff->ScreenBufferSize.Y) windx -= GetSystemMetrics(SM_CXVSCROLL); // Window will have a vertical scroll bar
 
         charx = windx / (int)WidthUnit ;
         chary = windy / (int)HeightUnit;
@@ -2208,6 +2214,9 @@ ConWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
             if (OnClose(GuiData)) goto Default;
             break;
 
+        case WM_ERASEBKGND:
+            return TRUE;
+
         case WM_PAINT:
             OnPaint(GuiData);
             break;