Author: gedmurphy Date: Tue Nov 24 21:17:43 2015 New Revision: 70101
URL: http://svn.reactos.org/svn/reactos?rev=70101&view=rev Log: [CHARMAP_NEW] - Allow the dialog to be resized, which in turn will grow / shrink the grid view and the fonts inside it. This means users can make the grid larger if they don't have their glasses on or want to see all the fonts in more detail. We no longer need a large font window popping out from the grid when you click on a cell (which I was never a fan of). - Don't allow scrolling previous to row 0 or after the last row
Modified: trunk/reactos/base/applications/charmap_new/GridView.cpp trunk/reactos/base/applications/charmap_new/GridView.h trunk/reactos/base/applications/charmap_new/MainWindow.cpp trunk/reactos/base/applications/charmap_new/lang/en-US.rc
Modified: trunk/reactos/base/applications/charmap_new/GridView.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/charmap_n... ============================================================================== --- trunk/reactos/base/applications/charmap_new/GridView.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/charmap_new/GridView.cpp [iso-8859-1] Tue Nov 24 21:17:43 2015 @@ -22,7 +22,8 @@ CGridView::CGridView() : m_xNumCells(20), m_yNumCells(10), - ScrollPosition(0) + m_ScrollPosition(0), + m_NumRows(0) { m_szMapWndClass = L"CharGridWClass"; } @@ -78,7 +79,7 @@ if (hdc == NULL) return false;
// Setup the logfont structure - NewFont.Font.lfHeight = GetDeviceCaps(hdc, LOGPIXELSY) / 5; + NewFont.Font.lfHeight = 0; // This is set in WM_SIZE NewFont.Font.lfCharSet = DEFAULT_CHARSET; StringCchCopyW(NewFont.Font.lfFaceName, LF_FACESIZE, FontName);
@@ -127,12 +128,12 @@ NewFont.NumValidGlyphs = j;
// Calculate the number of rows required to hold all glyphs - int Rows = NewFont.NumValidGlyphs / m_xNumCells; + m_NumRows = NewFont.NumValidGlyphs / m_xNumCells; if (NewFont.NumValidGlyphs % m_xNumCells) - Rows += 1; + m_NumRows += 1;
// Set the scrollbar in relation to the rows - SetScrollRange(m_hwnd, SB_VERT, 0, Rows, FALSE); + SetScrollRange(m_hwnd, SB_VERT, 0, m_NumRows - m_yNumCells, FALSE);
// We're done, update the current font m_CurrentFont = NewFont; @@ -224,7 +225,7 @@
// Get the client area we can draw on. The position we set above includes // a scrollbar which we obvioulsy can't draw on. GetClientRect gives us - // the size without the scroll, and it more efficient than getting the + // the size without the scroll, and it's more efficient than getting the // scroll metrics and calculating the size from that RECT ClientRect; GetClientRect(m_hwnd, &ClientRect); @@ -234,6 +235,26 @@ // Let all the cells know about their new coords UpdateCellCoordinates();
+ // We scale the font size up or down depending on the cell size + if (m_CurrentFont.hFont) + { + // Delete the existing font + DeleteObject(m_CurrentFont.hFont); + + HDC hdc; + hdc = GetDC(m_hwnd); + if (hdc) + { + // Update the font size with respect to the cell size + m_CurrentFont.Font.lfHeight = (m_CellSize.cy - 5); + m_CurrentFont.hFont = CreateFontIndirectW(&m_CurrentFont.Font); + ReleaseDC(m_hwnd, hdc); + } + } + + // Redraw the whole grid + InvalidateRect(m_hwnd, &ClientRect, TRUE); + return 0; }
@@ -242,42 +263,47 @@ _In_ INT Pos) {
- INT PrevScrollPosition = ScrollPosition; + INT PrevScrollPosition = m_ScrollPosition;
switch (Value) { case SB_LINEUP: - ScrollPosition -= 1; + m_ScrollPosition -= 1; break;
case SB_LINEDOWN: - ScrollPosition += 1; + m_ScrollPosition += 1; break;
case SB_PAGEUP: - ScrollPosition -= m_yNumCells; + m_ScrollPosition -= m_yNumCells; break;
case SB_PAGEDOWN: - ScrollPosition += m_yNumCells; + m_ScrollPosition += m_yNumCells; break;
case SB_THUMBTRACK: - ScrollPosition = Pos; + m_ScrollPosition = Pos; break;
default: break; }
+ // Make sure we don't scroll past row 0 or max rows + m_ScrollPosition = max(0, m_ScrollPosition); + m_ScrollPosition = min(m_ScrollPosition, m_NumRows); + + // Check if there's a difference from the previous position INT ScrollDiff; - ScrollDiff = PrevScrollPosition - ScrollPosition; + ScrollDiff = PrevScrollPosition - m_ScrollPosition; if (ScrollDiff) { // Set the new scrollbar position in the scroll box SetScrollPos(m_hwnd, SB_VERT, - ScrollPosition, + m_ScrollPosition, TRUE);
// Check if the scrollbar has moved more than the @@ -288,7 +314,7 @@ GetClientRect(m_hwnd, &rect);
// Scroll the visible cells which remain within the grid - // and invalid any new ones which appear from the top / bottom + // and invalidate any new ones which appear from the top / bottom ScrollWindowEx(m_hwnd, 0, ScrollDiff * m_CellSize.cy, @@ -441,22 +467,23 @@ { // Calculate which glyph to start at based on scroll position int i; - i = m_xNumCells * ScrollPosition; + i = m_xNumCells * m_ScrollPosition;
// Make sure we have the correct font on the DC HFONT hOldFont; hOldFont = (HFONT)SelectFont(PaintStruct->hdc, m_CurrentFont.hFont);
- // Traverse all the cells and tell them to paint themselves + // Traverse all the cells for (int y = 0; y < m_yNumCells; y++) for (int x = 0; x < m_xNumCells; x++) { + // Update the glyph for this cell WCHAR ch = (WCHAR)m_CurrentFont.ValidGlyphs[i]; m_Cells[y][x]->SetChar(ch);
+ // Tell it to paint itself m_Cells[y][x]->OnPaint(*PaintStruct); - i++; }
@@ -487,6 +514,7 @@ { // Remove focus from any existing cell m_ActiveCell->SetFocus(false); + InvalidateRect(m_hwnd, m_ActiveCell->GetCellCoordinates(), TRUE); }
// Set the new active cell and give it focus
Modified: trunk/reactos/base/applications/charmap_new/GridView.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/charmap_n... ============================================================================== --- trunk/reactos/base/applications/charmap_new/GridView.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/charmap_new/GridView.h [iso-8859-1] Tue Nov 24 21:17:43 2015 @@ -29,8 +29,8 @@ CCell*** m_Cells; // *m_Cells[][]; CCell *m_ActiveCell;
- HFONT hFont; - INT ScrollPosition; + INT m_ScrollPosition; + int m_NumRows;
CurrentFont m_CurrentFont;
@@ -45,6 +45,8 @@ bool SetFont( _In_ CAtlString& FontName ); + + HWND GetHwnd() { return m_hwnd; }
private: static LRESULT
Modified: trunk/reactos/base/applications/charmap_new/MainWindow.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/charmap_n... ============================================================================== --- trunk/reactos/base/applications/charmap_new/MainWindow.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/charmap_new/MainWindow.cpp [iso-8859-1] Tue Nov 24 21:17:43 2015 @@ -214,7 +214,9 @@ }
BOOL -CCharMapWindow::OnSize(void) +CCharMapWindow::OnSize( + _In_ WPARAM wParam + ) { RECT rcClient, rcStatus; INT lvHeight, iStatusHeight; @@ -229,14 +231,11 @@ // Get the full client rect GetClientRect(m_hMainWnd, &rcClient);
- // Calculate the remaining height for the treeview + // Calculate the remaining height for the gridview lvHeight = rcClient.bottom - iStatusHeight;
- // Resize the device view - //m_GridView->OnSize(0, - // iToolHeight, - // rcClient.right, - // lvHeight); + // Resize the grid view + SendMessageW(m_GridView->GetHwnd(), WM_SIZE, wParam, 0);
return TRUE; } @@ -352,7 +351,7 @@
case WM_SIZE: { - return This->OnSize(); + return This->OnSize(wParam); }
case WM_NOTIFY: @@ -526,7 +525,7 @@ Length = GetWindowTextLengthW(hCombo); if (!Length) return false;
- CAtlStringW FontName;// = L"hahaha"; + CAtlStringW FontName; FontName.Preallocate(Length);
SendMessageW(hCombo,
Modified: trunk/reactos/base/applications/charmap_new/lang/en-US.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/charmap_n... ============================================================================== --- trunk/reactos/base/applications/charmap_new/lang/en-US.rc [iso-8859-1] (original) +++ trunk/reactos/base/applications/charmap_new/lang/en-US.rc [iso-8859-1] Tue Nov 24 21:17:43 2015 @@ -2,11 +2,11 @@
IDD_CHARMAP DIALOGEX 6, 6, 290, 224 FONT 8, "MS Shell Dlg", 0, 0 -STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX +STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_SIZEBOX CAPTION "ReactOS Character Map" BEGIN LTEXT "Font:", IDC_STATIC, 6, 7, 24, 9 - COMBOBOX IDC_FONTCOMBO, 36, 5, 210, 210, WS_CHILD | WS_VISIBLE | + COMBOBOX IDC_FONTCOMBO, 28, 5, 150, 210, WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS LTEXT "Characters to copy:", IDC_STATIC, 6, 188, 66, 9 CONTROL "", IDC_TEXTBOX, RICHEDIT_CLASS, ES_AUTOHSCROLL | WS_BORDER |