From 4cb478b7120433c1d8004fb158d2b5c3ccf417e1 Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Tue, 1 Dec 2015 21:29:12 +0000 Subject: [PATCH] [CHARMAP] - Hackfix the existing charmap for the 0.4 release (just in case I don't get time to finish the new one). This fixes showing invalid glyphs and also removes the advanced section as it was unimplemented. svn path=/trunk/; revision=70228 --- reactos/base/applications/charmap/charmap.c | 45 ++++++---- reactos/base/applications/charmap/map.c | 98 ++++++++++++++------- reactos/base/applications/charmap/precomp.h | 12 +-- 3 files changed, 105 insertions(+), 50 deletions(-) diff --git a/reactos/base/applications/charmap/charmap.c b/reactos/base/applications/charmap/charmap.c index 25d922cb36f..3fd96aa2b07 100644 --- a/reactos/base/applications/charmap/charmap.c +++ b/reactos/base/applications/charmap/charmap.c @@ -12,6 +12,8 @@ #include #include +#define REMOVE_ADVANCED + #define ID_ABOUT 0x1 HINSTANCE hInstance; @@ -237,7 +239,7 @@ AddCharToSelection(HWND hDlg, WCHAR ch) SendMessage(hText, WM_CHAR, (WPARAM)ch, 0); } - +#ifndef REMOVE_ADVANCED static void UpdateSettings(HWND hDlg) @@ -245,20 +247,24 @@ UpdateSettings(HWND hDlg) if (hDlg == hCharmapDlg) { Settings.IsAdvancedView = - SendDlgItemMessage(hDlg, IDC_CHECK_ADVANCED, BM_GETCHECK, 0, 0); + SendDlgItemMessage(hDlg, IDC_CHECK_ADVANCED, BM_GETCHECK, 0, 0); + } if (hDlg == hAdvancedDlg) { } } +#endif static void ChangeView(HWND hWnd) { RECT rcCharmap; +#ifndef REMOVE_ADVANCED RECT rcAdvanced; +#endif RECT rcPanelExt; RECT rcPanelInt; RECT rcStatus; @@ -268,7 +274,9 @@ ChangeView(HWND hWnd) UINT DeskTopWidth, DeskTopHeight; GetClientRect(hCharmapDlg, &rcCharmap); +#ifndef REMOVE_ADVANCED GetClientRect(hAdvancedDlg, &rcAdvanced); +#endif GetWindowRect(hWnd, &rcPanelExt); GetClientRect(hWnd, &rcPanelInt); GetClientRect(hStatusWnd, &rcStatus); @@ -280,19 +288,19 @@ ChangeView(HWND hWnd) DeY = (rcPanelExt.bottom - rcPanelExt.top) - rcPanelInt.bottom; MoveWindow(hCharmapDlg, 0, 0, rcCharmap.right, rcCharmap.bottom, FALSE); +#ifndef REMOVE_ADVANCED MoveWindow(hAdvancedDlg, 0, rcCharmap.bottom, rcAdvanced.right, rcAdvanced.bottom, FALSE); - ShowWindow(hAdvancedDlg, (Settings.IsAdvancedView) ? SW_SHOW : SW_HIDE); - +#endif xPos = rcPanelExt.left; yPos = rcPanelExt.top; Width = DeX + rcCharmap.right; Height = DeY + rcCharmap.bottom + rcStatus.bottom; - +#ifndef REMOVE_ADVANCED if (Settings.IsAdvancedView) Height += rcAdvanced.bottom; - +#endif if ((xPos + Width) > DeskTopWidth) xPos += DeskTopWidth - (xPos + Width); @@ -318,6 +326,9 @@ CharMapDlgProc(HWND hDlg, case WM_INITDIALOG: { DWORD evMask; +#ifdef REMOVE_ADVANCED + HWND hAdv; +#endif FillFontStyleComboList(GetDlgItem(hDlg, IDC_FONTCOMBO)); @@ -328,7 +339,10 @@ CharMapDlgProc(HWND hDlg, evMask = SendDlgItemMessage(hDlg, IDC_TEXTBOX, EM_GETEVENTMASK, 0, 0); evMask |= ENM_CHANGE; SendDlgItemMessage(hDlg, IDC_TEXTBOX, EM_SETEVENTMASK, 0, (LPARAM)evMask); - +#ifdef REMOVE_ADVANCED + hAdv = GetDlgItem(hDlg, IDC_CHECK_ADVANCED); + ShowWindow(hAdv, SW_HIDE); +#endif return TRUE; } @@ -370,11 +384,12 @@ CharMapDlgProc(HWND hDlg, case IDC_COPY: CopyCharacters(hDlg); break; - +#ifndef REMOVE_ADVANCED case IDC_CHECK_ADVANCED: UpdateSettings(hDlg); ChangeView(GetParent(hDlg)); break; +#endif } } break; @@ -385,7 +400,7 @@ CharMapDlgProc(HWND hDlg, return FALSE; } - +#ifndef REMOVE_ADVANCED static INT_PTR CALLBACK @@ -405,7 +420,7 @@ AdvancedDlgProc(HWND hDlg, return FALSE; } - +#endif static int OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) { @@ -416,12 +431,12 @@ OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) MAKEINTRESOURCE(IDD_CHARMAP), hWnd, CharMapDlgProc); - +#ifndef REMOVE_ADVANCED hAdvancedDlg = CreateDialog(hInstance, - MAKEINTRESOURCE(IDD_ADVANCED), - hWnd, - AdvancedDlgProc); - + MAKEINTRESOURCE(IDD_ADVANCED), + hWnd, + AdvancedDlgProc); +#endif hStatusWnd = CreateWindow(STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, diff --git a/reactos/base/applications/charmap/map.c b/reactos/base/applications/charmap/map.c index 2a3c80df46e..13b20a41cbe 100644 --- a/reactos/base/applications/charmap/map.c +++ b/reactos/base/applications/charmap/map.c @@ -16,14 +16,6 @@ static const WCHAR szLrgCellWndClass[] = L"LrgCellWnd"; #define MAX_ROWS (0xFFFF / XCELLS) + 1 - YCELLS -static -VOID -TagFontToCell(PCELL pCell, - WCHAR ch) -{ - pCell->ch = ch; -} - static VOID @@ -107,33 +99,47 @@ FillGrid(PMAP infoPtr, INT x, y; RECT rc; PCELL Cell; + INT i, added; hOldFont = SelectObject(ps->hdc, infoPtr->hFont); - for (y = 0; y < YCELLS; y++) - for (x = 0; x < XCELLS; x++) + i = XCELLS * infoPtr->iYStart; + + added = 0; + x = y = 0; + while ((y <= YCELLS) && (x <= XCELLS)) { + 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; + + DrawTextW(ps->hdc, + &ch, + 1, + &Cell->CellInt, + DT_CENTER | DT_VCENTER | DT_SINGLELINE); + + added++; } - ch = (WCHAR)((XCELLS * (y + infoPtr->iYStart)) + x); + i++; + ch = (WCHAR)i; - TagFontToCell(Cell, ch); - - DrawTextW(ps->hdc, - &ch, - 1, - &Cell->CellInt, - DT_CENTER | DT_VCENTER | DT_SINGLELINE); + // move to the next cell + x++; + if (x > XCELLS - 1) + { + x = 0; + y++; + } } - SelectObject(ps->hdc, hOldFont); } @@ -213,6 +219,9 @@ SetFont(PMAP infoPtr, LPWSTR lpFontName) { HDC hdc; + WCHAR ch[MAX_GLYPHS]; + WORD out[MAX_GLYPHS]; + DWORD i, j, Rows; /* Destroy Zoom window, since it was created with older font */ DestroyWindow(infoPtr->hLrgWnd); @@ -225,9 +234,7 @@ 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; wcsncpy(infoPtr->CurrentFont.lfFaceName, @@ -246,6 +253,39 @@ SetFont(PMAP infoPtr, { CreateLargeCell(infoPtr); } + + // 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) + { + 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); + + Rows = infoPtr->NumValidGlyphs / XCELLS; + if (infoPtr->NumValidGlyphs % XCELLS) + Rows += 1; + + SetScrollRange(infoPtr->hMapWnd, SB_VERT, 0, Rows - YCELLS, FALSE); } @@ -379,8 +419,7 @@ OnCreate(PMAP infoPtr, SetGrid(infoPtr); - SetScrollRange(hwnd, SB_VERT, 0, MAX_ROWS, FALSE); - SetScrollPos(hwnd, SB_VERT, 0, TRUE); + SetScrollPos(infoPtr->hParent, SB_VERT, 0, TRUE); Ret = TRUE; } @@ -424,8 +463,7 @@ OnVScroll(PMAP infoPtr, break; } - infoPtr->iYStart = max(0, - min(infoPtr->iYStart, MAX_ROWS)); + infoPtr->iYStart = max(0, min(infoPtr->iYStart, MAX_ROWS)); iYDiff = iOldYStart - infoPtr->iYStart; if (iYDiff) diff --git a/reactos/base/applications/charmap/precomp.h b/reactos/base/applications/charmap/precomp.h index 83c1417e8e8..aa640328fc9 100644 --- a/reactos/base/applications/charmap/precomp.h +++ b/reactos/base/applications/charmap/precomp.h @@ -1,16 +1,14 @@ #ifndef __CHARMAP_PRECOMP_H #define __CHARMAP_PRECOMP_H -#include -#include -#include -#include -#include +#include #include "resource.h" #define SIZEOF(_v) (sizeof(_v) / sizeof(*_v)) +#define MAX_GLYPHS 65536 + #define XCELLS 20 #define YCELLS 10 #define XLARGE 45 @@ -44,6 +42,10 @@ typedef struct _MAP HFONT hFont; LOGFONTW CurrentFont; INT iYStart; + + USHORT ValidGlyphs[MAX_GLYPHS]; + USHORT NumValidGlyphs; + } MAP, *PMAP; typedef struct {