[SNDVOL32] Add the small line dialog
[reactos.git] / base / applications / charmap / map.c
index 0029656..a8a9c8a 100644 (file)
@@ -7,20 +7,14 @@
  *
  */
 
-#include <precomp.h>
+#include "precomp.h"
 
 #include <stdlib.h>
 
 static const WCHAR szMapWndClass[] = L"FontMapWnd";
 static const WCHAR szLrgCellWndClass[] = L"LrgCellWnd";
 
-static
-VOID
-TagFontToCell(PCELL pCell,
-              WCHAR ch)
-{
-    pCell->ch = ch;
-}
+#define MAX_ROWS (0xFFFF / XCELLS) + 1 - YCELLS
 
 
 static
@@ -105,33 +99,40 @@ FillGrid(PMAP infoPtr,
     INT x, y;
     RECT rc;
     PCELL Cell;
+    INT i, added;
 
     hOldFont = SelectObject(ps->hdc,
                             infoPtr->hFont);
 
+    i = XCELLS * infoPtr->iYStart;
+
+    added = 0;
+
     for (y = 0; y < YCELLS; y++)
     for (x = 0; x < XCELLS; x++)
     {
+        ch = (WCHAR)infoPtr->ValidGlyphs[i];
+
         Cell = &infoPtr->Cells[y][x];
 
-        if (!IntersectRect(&rc,
-                           &ps->rcPaint,
-                           &Cell->CellExt))
+        if (IntersectRect(&rc,
+                            &ps->rcPaint,
+                            &Cell->CellExt))
         {
-            continue;
-        }
+            Cell->ch = ch;
 
-        ch = (WCHAR)((XCELLS * (y + infoPtr->iYStart)) + x);
+            DrawTextW(ps->hdc,
+                        &ch,
+                        1,
+                        &Cell->CellInt,
+                        DT_CENTER | DT_VCENTER | DT_SINGLELINE);
 
-        TagFontToCell(Cell, ch);
+            added++;
+        }
 
-        DrawTextW(ps->hdc,
-                  &ch,
-                  1,
-                  &Cell->CellInt,
-                  DT_CENTER | DT_VCENTER | DT_SINGLELINE);
+        i++;
+        ch = (WCHAR)i;
     }
-
     SelectObject(ps->hdc,
                  hOldFont);
 }
@@ -211,6 +212,9 @@ SetFont(PMAP infoPtr,
         LPWSTR lpFontName)
 {
     HDC hdc;
+    WCHAR ch[MAX_GLYPHS];
+    WORD out[MAX_GLYPHS];
+    DWORD i, j;
 
     /* Destroy Zoom window, since it was created with older font */
     DestroyWindow(infoPtr->hLrgWnd);
@@ -223,13 +227,12 @@ SetFont(PMAP infoPtr,
                sizeof(LOGFONTW));
 
     hdc = GetDC(infoPtr->hMapWnd);
-    infoPtr->CurrentFont.lfHeight = GetDeviceCaps(hdc,
-                                                  LOGPIXELSY) / 5;
-    ReleaseDC(infoPtr->hMapWnd, hdc);
+    infoPtr->CurrentFont.lfHeight = GetDeviceCaps(hdc, LOGPIXELSY) / 5;
 
     infoPtr->CurrentFont.lfCharSet =  DEFAULT_CHARSET;
-    wcscpy(infoPtr->CurrentFont.lfFaceName,
-           lpFontName);
+    wcsncpy(infoPtr->CurrentFont.lfFaceName,
+            lpFontName,
+            sizeof(infoPtr->CurrentFont.lfFaceName) / sizeof(infoPtr->CurrentFont.lfFaceName[0]));
 
     infoPtr->hFont = CreateFontIndirectW(&infoPtr->CurrentFont);
 
@@ -237,12 +240,43 @@ SetFont(PMAP infoPtr,
                    NULL,
                    TRUE);
 
-    /* Test if zoom window must be reopened */
-    if (infoPtr->pActiveCell != NULL &&
-        infoPtr->pActiveCell->bLarge)
+    infoPtr->pActiveCell = &infoPtr->Cells[0][0];
+
+    // Get all the valid glyphs in this font
+
+    SelectObject(hdc, infoPtr->hFont);
+
+    for (i = 0; i < MAX_GLYPHS; i++)
+        ch[i] = (WCHAR)i;
+
+    if (GetGlyphIndicesW(hdc,
+                         ch,
+                         MAX_GLYPHS,
+                         out,
+                         GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR)
     {
-        CreateLargeCell(infoPtr);
+        j = 0;
+        for (i = 0; i < MAX_GLYPHS; i++)
+        {
+            if (out[i] != 0xffff)
+            {
+                infoPtr->ValidGlyphs[j] = ch[i];
+                j++;
+            }
+        }
+        infoPtr->NumValidGlyphs = j;
     }
+
+    ReleaseDC(infoPtr->hMapWnd, hdc);
+
+    infoPtr->NumRows = infoPtr->NumValidGlyphs / XCELLS;
+    if (infoPtr->NumValidGlyphs % XCELLS)
+        infoPtr->NumRows += 1;
+    infoPtr->NumRows = (infoPtr->NumRows > YCELLS) ? infoPtr->NumRows - YCELLS : 0;
+
+    SetScrollRange(infoPtr->hMapWnd, SB_VERT, 0, infoPtr->NumRows, FALSE);
+    SetScrollPos(infoPtr->hMapWnd, SB_VERT, 0, TRUE);
+    infoPtr->iYStart = 0;
 }
 
 
@@ -342,9 +376,9 @@ OnClick(PMAP infoPtr,
 
 static
 BOOL
-OnCreate(PMAP infoPtr,
-         HWND hwnd,
-         HWND hParent)
+MapOnCreate(PMAP infoPtr,
+            HWND hwnd,
+            HWND hParent)
 {
     RECT rc;
     BOOL Ret = FALSE;
@@ -376,8 +410,7 @@ OnCreate(PMAP infoPtr,
 
             SetGrid(infoPtr);
 
-            SetScrollRange(hwnd, SB_VERT, 0, 255, FALSE);
-            SetScrollPos(hwnd, SB_VERT, 0, TRUE);
+            SetScrollPos(infoPtr->hParent, SB_VERT, 0, TRUE);
 
             Ret = TRUE;
         }
@@ -421,8 +454,8 @@ OnVScroll(PMAP infoPtr,
             break;
        }
 
-    infoPtr->iYStart = max(0,
-                         min(infoPtr->iYStart, 255*16));
+    infoPtr->iYStart = max(0, infoPtr->iYStart);
+    infoPtr->iYStart = min(infoPtr->iYStart, infoPtr->NumRows);
 
     iYDiff = iOldYStart - infoPtr->iYStart;
     if (iYDiff)
@@ -484,7 +517,7 @@ OnPaint(PMAP infoPtr,
         {
             return;
         }
-        hdc = (HDC)wParam;
+        ps.hdc = (HDC)wParam;
     }
     else
     {
@@ -525,9 +558,9 @@ MapWndProc(HWND hwnd,
     {
         case WM_CREATE:
         {
-            if (!OnCreate(infoPtr,
-                          hwnd,
-                          ((LPCREATESTRUCTW)lParam)->hwndParent))
+            if (!MapOnCreate(infoPtr,
+                             hwnd,
+                             ((LPCREATESTRUCTW)lParam)->hwndParent))
             {
                 return (LRESULT)-1;
             }