[FONTVIEW] Formatting only (for PR #5305)

This commit is contained in:
Stanislav Motylkov 2023-06-13 12:44:46 +03:00
parent fa4c3bd560
commit 2e836fb339
2 changed files with 715 additions and 748 deletions

View file

@ -1,23 +1,8 @@
/*
* fontview display class
*
* display.c
*
* Copyright (C) 2007 Timo Kreuzer <timo <dot> kreuzer <at> reactos <dot> org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* PROJECT: ReactOS Font Viewer
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Display class
* COPYRIGHT: Copyright 2007 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include "precomp.h"
@ -37,488 +22,488 @@ LRESULT CALLBACK DisplayProc(HWND, UINT, WPARAM, LPARAM);
/* Internal data storage type */
typedef struct
{
int nPageHeight;
WCHAR szTypeFaceName[LF_FULLFACESIZE];
WCHAR szFormat[MAX_FORMAT];
WCHAR szString[MAX_STRING];
int nPageHeight;
WCHAR szTypeFaceName[LF_FULLFACESIZE];
WCHAR szFormat[MAX_FORMAT];
WCHAR szString[MAX_STRING];
HFONT hCaptionFont;
HFONT hCharSetFont;
HFONT hSizeFont;
HFONT hFonts[MAX_SIZES];
int nSizes[MAX_SIZES];
int nHeights[MAX_SIZES];
HFONT hCaptionFont;
HFONT hCharSetFont;
HFONT hSizeFont;
HFONT hFonts[MAX_SIZES];
int nSizes[MAX_SIZES];
int nHeights[MAX_SIZES];
} DISPLAYDATA;
/* This is the only public function, it registers the class */
BOOL
Display_InitClass(HINSTANCE hInstance)
{
WNDCLASSEXW wincl;
WNDCLASSEXW wincl;
/* Set the fontdisplay window class structure */
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.style = CS_DBLCLKS;
wincl.lpfnWndProc = DisplayProc;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hInstance = hInstance;
wincl.hIcon = NULL;
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.hbrBackground = GetStockObject(WHITE_BRUSH);
wincl.lpszMenuName = NULL;
wincl.lpszClassName = g_szFontDisplayClassName;
wincl.hIconSm = NULL;
/* Set the fontdisplay window class structure */
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.style = CS_DBLCLKS;
wincl.lpfnWndProc = DisplayProc;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hInstance = hInstance;
wincl.hIcon = NULL;
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.hbrBackground = GetStockObject(WHITE_BRUSH);
wincl.lpszMenuName = NULL;
wincl.lpszClassName = g_szFontDisplayClassName;
wincl.hIconSm = NULL;
/* Register the window class, and if it fails return FALSE */
if (!RegisterClassExW (&wincl))
{
return FALSE;
}
return TRUE;
/* Register the window class, and if it fails return FALSE */
if (!RegisterClassExW (&wincl))
{
return FALSE;
}
return TRUE;
}
static int
Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos)
{
HFONT hOldFont;
TEXTMETRIC tm;
int i, y;
WCHAR szSize[5];
WCHAR szCaption[LF_FULLFACESIZE + 20];
HFONT hOldFont;
TEXTMETRIC tm;
int i, y;
WCHAR szSize[5];
WCHAR szCaption[LF_FULLFACESIZE + 20];
/* This is the location on the DC where we draw */
y = -nYPos;
/* This is the location on the DC where we draw */
y = -nYPos;
hOldFont = SelectObject(hDC, pData->hCaptionFont);
GetTextMetrics(hDC, &tm);
hOldFont = SelectObject(hDC, pData->hCaptionFont);
GetTextMetrics(hDC, &tm);
swprintf(szCaption, L"%s%s", pData->szTypeFaceName, pData->szFormat);
TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
y += tm.tmHeight + SPACING1;
swprintf(szCaption, L"%s%s", pData->szTypeFaceName, pData->szFormat);
TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
y += tm.tmHeight + SPACING1;
/* Draw a separation Line */
SelectObject(hDC, GetStockObject(BLACK_PEN));
MoveToEx(hDC, 0, y, NULL);
LineTo(hDC, 10000, y);
y += SPACING2;
/* Draw a separation Line */
SelectObject(hDC, GetStockObject(BLACK_PEN));
MoveToEx(hDC, 0, y, NULL);
LineTo(hDC, 10000, y);
y += SPACING2;
/* TODO: Output font info */
/* TODO: Output font info */
/* Output Character set */
SelectObject(hDC, pData->hCharSetFont);
GetTextMetrics(hDC, &tm);
swprintf(szCaption, L"abcdefghijklmnopqrstuvwxyz");
TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
y += tm.tmHeight + 1;
/* Output Character set */
SelectObject(hDC, pData->hCharSetFont);
GetTextMetrics(hDC, &tm);
swprintf(szCaption, L"abcdefghijklmnopqrstuvwxyz");
TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
y += tm.tmHeight + 1;
swprintf(szCaption, L"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
y += tm.tmHeight + 1;
swprintf(szCaption, L"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
y += tm.tmHeight + 1;
swprintf(szCaption, L"0123456789.:,;(\"~!@#$%%^&*')");
TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
y += tm.tmHeight + 1;
swprintf(szCaption, L"0123456789.:,;(\"~!@#$%%^&*')");
TextOutW(hDC, 0, y, szCaption, (INT)wcslen(szCaption));
y += tm.tmHeight + 1;
/* Draw a separation Line */
SelectObject(hDC, GetStockObject(BLACK_PEN));
MoveToEx(hDC, 0, y, NULL);
LineTo(hDC, 10000, y);
y += SPACING2;
/* Draw a separation Line */
SelectObject(hDC, GetStockObject(BLACK_PEN));
MoveToEx(hDC, 0, y, NULL);
LineTo(hDC, 10000, y);
y += SPACING2;
/* Output the strings for different sizes */
for (i = 0; i < MAX_SIZES; i++)
{
SelectObject(hDC, pData->hFonts[i]);
TextOutW(hDC, 20, y, pData->szString, (INT)wcslen(pData->szString));
GetTextMetrics(hDC, &tm);
y += tm.tmHeight + 1;
SelectObject(hDC, pData->hSizeFont);
swprintf(szSize, L"%d", pData->nSizes[i]);
TextOutW(hDC, 0, y - 13 - tm.tmDescent, szSize, (INT)wcslen(szSize));
}
SelectObject(hDC, hOldFont);
/* Output the strings for different sizes */
for (i = 0; i < MAX_SIZES; i++)
{
SelectObject(hDC, pData->hFonts[i]);
TextOutW(hDC, 20, y, pData->szString, (INT)wcslen(pData->szString));
GetTextMetrics(hDC, &tm);
y += tm.tmHeight + 1;
SelectObject(hDC, pData->hSizeFont);
swprintf(szSize, L"%d", pData->nSizes[i]);
TextOutW(hDC, 0, y - 13 - tm.tmDescent, szSize, (INT)wcslen(szSize));
}
SelectObject(hDC, hOldFont);
return y;
return y;
}
static int
CALLBACK
EnumFontFamProcW(
const LOGFONTW *lpelfe,
const TEXTMETRICW *lptm,
DWORD FontType,
LPARAM lParam)
const LOGFONTW *lpelfe,
const TEXTMETRICW *lptm,
DWORD FontType,
LPARAM lParam)
{
PNEWTEXTMETRICW pntmw = (PNEWTEXTMETRICW)lptm;
PBOOL pfOpenType = (PBOOL)lParam;
PNEWTEXTMETRICW pntmw = (PNEWTEXTMETRICW)lptm;
PBOOL pfOpenType = (PBOOL)lParam;
if (FontType & TRUETYPE_FONTTYPE)
{
if (pntmw->ntmFlags & (NTM_TT_OPENTYPE | NTM_PS_OPENTYPE))
{
*pfOpenType = TRUE;
return FALSE;
}
}
return TRUE;
if (FontType & TRUETYPE_FONTTYPE)
{
if (pntmw->ntmFlags & (NTM_TT_OPENTYPE | NTM_PS_OPENTYPE))
{
*pfOpenType = TRUE;
return FALSE;
}
}
return TRUE;
}
static LRESULT
Display_SetTypeFace(HWND hwnd, PLOGFONTW pLogFont)
{
DISPLAYDATA* pData;
TEXTMETRIC tm;
HDC hDC;
RECT rect;
SCROLLINFO si;
int i;
LOGFONTW logfont;
BOOL fOpenType;
BYTE Buffer[512];
LPOUTLINETEXTMETRICW pOTM = (LPOUTLINETEXTMETRICW)Buffer;
LPWSTR pch;
DISPLAYDATA* pData;
TEXTMETRIC tm;
HDC hDC;
RECT rect;
SCROLLINFO si;
int i;
LOGFONTW logfont;
BOOL fOpenType;
BYTE Buffer[512];
LPOUTLINETEXTMETRICW pOTM = (LPOUTLINETEXTMETRICW)Buffer;
LPWSTR pch;
/* Set the new type face name */
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
lstrcpynW(pData->szTypeFaceName, pLogFont->lfFaceName,
ARRAYSIZE(pData->szTypeFaceName));
/* Set the new type face name */
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
lstrcpynW(pData->szTypeFaceName, pLogFont->lfFaceName,
ARRAYSIZE(pData->szTypeFaceName));
/* Create the new fonts */
hDC = GetDC(hwnd);
DeleteObject(pData->hCharSetFont);
/* Create the new fonts */
hDC = GetDC(hwnd);
DeleteObject(pData->hCharSetFont);
logfont = *pLogFont;
logfont.lfHeight = -MulDiv(16, GetDeviceCaps(GetDC(NULL), LOGPIXELSY), 72);
pData->hCharSetFont = CreateFontIndirectW(&logfont);
logfont = *pLogFont;
logfont.lfHeight = -MulDiv(16, GetDeviceCaps(GetDC(NULL), LOGPIXELSY), 72);
pData->hCharSetFont = CreateFontIndirectW(&logfont);
/* Get font format */
SelectObject(hDC, pData->hCharSetFont);
GetTextMetrics(hDC, &tm);
if (tm.tmPitchAndFamily & TMPF_TRUETYPE)
{
if (GetOutlineTextMetricsW(hDC, sizeof(Buffer), pOTM))
{
LPBYTE pb = Buffer;
pb += (WORD)(DWORD_PTR)pOTM->otmpStyleName;
pch = (LPWSTR)pb;
if (*pch)
{
lstrcatW(pData->szTypeFaceName, L" ");
lstrcatW(pData->szTypeFaceName, pch);
}
}
/* Get font format */
SelectObject(hDC, pData->hCharSetFont);
GetTextMetrics(hDC, &tm);
if (tm.tmPitchAndFamily & TMPF_TRUETYPE)
{
if (GetOutlineTextMetricsW(hDC, sizeof(Buffer), pOTM))
{
LPBYTE pb = Buffer;
pb += (WORD)(DWORD_PTR)pOTM->otmpStyleName;
pch = (LPWSTR)pb;
if (*pch)
{
lstrcatW(pData->szTypeFaceName, L" ");
lstrcatW(pData->szTypeFaceName, pch);
}
}
fOpenType = FALSE;
EnumFontFamiliesExW(hDC, &logfont,
EnumFontFamProcW, (LPARAM)&fOpenType, 0);
fOpenType = FALSE;
EnumFontFamiliesExW(hDC, &logfont,
EnumFontFamProcW, (LPARAM)&fOpenType, 0);
if (fOpenType)
swprintf(pData->szFormat, L" (OpenType)");
else
swprintf(pData->szFormat, L" (TrueType)");
}
else if (tm.tmPitchAndFamily & TMPF_VECTOR)
{
swprintf(pData->szFormat, L" (Vector)");
}
else
{
swprintf(pData->szFormat, L" (Raster)");
}
if (fOpenType)
swprintf(pData->szFormat, L" (OpenType)");
else
swprintf(pData->szFormat, L" (TrueType)");
}
else if (tm.tmPitchAndFamily & TMPF_VECTOR)
{
swprintf(pData->szFormat, L" (Vector)");
}
else
{
swprintf(pData->szFormat, L" (Raster)");
}
for (i = 0; i < MAX_SIZES; i++)
{
DeleteObject(pData->hFonts[i]);
logfont.lfHeight = -MulDiv(pData->nSizes[i], GetDeviceCaps(hDC, LOGPIXELSY), 72);
pData->hFonts[i] = CreateFontIndirectW(&logfont);
}
for (i = 0; i < MAX_SIZES; i++)
{
DeleteObject(pData->hFonts[i]);
logfont.lfHeight = -MulDiv(pData->nSizes[i], GetDeviceCaps(hDC, LOGPIXELSY), 72);
pData->hFonts[i] = CreateFontIndirectW(&logfont);
}
/* Calculate new page dimensions */
pData->nPageHeight = Display_DrawText(hDC, pData, 0);
ReleaseDC(hwnd, hDC);
/* Calculate new page dimensions */
pData->nPageHeight = Display_DrawText(hDC, pData, 0);
ReleaseDC(hwnd, hDC);
/* Set the vertical scrolling range and page size */
GetClientRect(hwnd, &rect);
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;
si.nMin = 0;
si.nMax = pData->nPageHeight;
si.nPage = rect.bottom;
si.nPos = 0;
si.nTrackPos = 0;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
/* Set the vertical scrolling range and page size */
GetClientRect(hwnd, &rect);
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;
si.nMin = 0;
si.nMax = pData->nPageHeight;
si.nPage = rect.bottom;
si.nPos = 0;
si.nTrackPos = 0;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
return 0;
return 0;
}
static LRESULT
Display_SetString(HWND hwnd, LPCWSTR pszString)
{
DISPLAYDATA* pData;
DISPLAYDATA* pData;
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
lstrcpynW(pData->szString, pszString, ARRAYSIZE(pData->szString));
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
lstrcpynW(pData->szString, pszString, ARRAYSIZE(pData->szString));
InvalidateRect(hwnd, NULL, TRUE);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
return 0;
}
static LRESULT
Display_OnCreate(HWND hwnd)
{
DISPLAYDATA* pData;
const int nSizes[MAX_SIZES] = {8, 12, 18, 24, 36, 48, 60, 72};
int i;
LOGFONTW LogFont = {50, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
DEFAULT_PITCH , L"MS Shell Dlg"};
DISPLAYDATA* pData;
const int nSizes[MAX_SIZES] = {8, 12, 18, 24, 36, 48, 60, 72};
int i;
LOGFONTW LogFont = {50, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
DEFAULT_PITCH , L"MS Shell Dlg"};
/* Create data structure */
pData = malloc(sizeof(DISPLAYDATA));
ZeroMemory(pData, sizeof(DISPLAYDATA));
/* Create data structure */
pData = malloc(sizeof(DISPLAYDATA));
ZeroMemory(pData, sizeof(DISPLAYDATA));
/* Set the window's GWLP_USERDATA to our data structure */
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pData);
/* Set the window's GWLP_USERDATA to our data structure */
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pData);
for (i = 0; i < MAX_SIZES; i++)
{
pData->nSizes[i] = nSizes[i];
}
for (i = 0; i < MAX_SIZES; i++)
{
pData->nSizes[i] = nSizes[i];
}
pData->hCaptionFont = CreateFontIndirectW(&LogFont);
LogFont.lfHeight = 12;
pData->hSizeFont = CreateFontIndirectW(&LogFont);
pData->hCaptionFont = CreateFontIndirectW(&LogFont);
LogFont.lfHeight = 12;
pData->hSizeFont = CreateFontIndirectW(&LogFont);
Display_SetString(hwnd,
L"Jackdaws love my big sphinx of quartz. 1234567890");
Display_SetString(hwnd,
L"Jackdaws love my big sphinx of quartz. 1234567890");
Display_SetTypeFace(hwnd, &LogFont);
Display_SetTypeFace(hwnd, &LogFont);
return 0;
return 0;
}
static LRESULT
Display_OnPaint(HWND hwnd)
{
DISPLAYDATA* pData;
PAINTSTRUCT ps;
SCROLLINFO si;
DISPLAYDATA* pData;
PAINTSTRUCT ps;
SCROLLINFO si;
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
/* Get the Scroll position */
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
/* Get the Scroll position */
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
BeginPaint(hwnd, &ps);
BeginPaint(hwnd, &ps);
/* Erase background */
FillRect(ps.hdc, &ps.rcPaint, GetStockObject(WHITE_BRUSH));
/* Erase background */
FillRect(ps.hdc, &ps.rcPaint, GetStockObject(WHITE_BRUSH));
/* Draw the text */
Display_DrawText(ps.hdc, pData, si.nPos);
/* Draw the text */
Display_DrawText(ps.hdc, pData, si.nPos);
EndPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
return 0;
}
static LRESULT
Display_OnSize(HWND hwnd)
{
RECT rect;
SCROLLINFO si;
int nOldPos;
RECT rect;
SCROLLINFO si;
int nOldPos;
GetClientRect(hwnd, &rect);
GetClientRect(hwnd, &rect);
/* Get the old scroll pos */
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
nOldPos = si.nPos;
/* Get the old scroll pos */
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
nOldPos = si.nPos;
/* Set the new page size */
si.fMask = SIF_PAGE;
si.nPage = rect.bottom;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
/* Set the new page size */
si.fMask = SIF_PAGE;
si.nPage = rect.bottom;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
/* Get the new scroll pos */
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
/* Get the new scroll pos */
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
/* If they don't match ... */
if (nOldPos != si.nPos)
{
/* ... scroll the window */
ScrollWindowEx(hwnd, 0, nOldPos - si.nPos, NULL, NULL, NULL, NULL, SW_INVALIDATE);
UpdateWindow(hwnd);
}
/* If they don't match ... */
if (nOldPos != si.nPos)
{
/* ... scroll the window */
ScrollWindowEx(hwnd, 0, nOldPos - si.nPos, NULL, NULL, NULL, NULL, SW_INVALIDATE);
UpdateWindow(hwnd);
}
return 0;
return 0;
}
static LRESULT
Display_OnVScroll(HWND hwnd, WPARAM wParam)
{
SCROLLINFO si;
int nPos;
SCROLLINFO si;
int nPos;
si.cbSize = sizeof(si);
si.fMask = SIF_POS | SIF_RANGE | SIF_TRACKPOS;
GetScrollInfo(hwnd, SB_VERT, &si);
si.cbSize = sizeof(si);
si.fMask = SIF_POS | SIF_RANGE | SIF_TRACKPOS;
GetScrollInfo(hwnd, SB_VERT, &si);
switch(LOWORD(wParam))
{
case SB_PAGEUP:
nPos = si.nPos - 50;
break;
case SB_PAGEDOWN:
nPos = si.nPos + 50;
break;
case SB_LINEUP:
nPos = si.nPos - 10;
break;
case SB_LINEDOWN:
nPos = si.nPos + 10;
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
nPos = si.nTrackPos;
break;
default:
nPos = si.nPos;
}
switch(LOWORD(wParam))
{
case SB_PAGEUP:
nPos = si.nPos - 50;
break;
case SB_PAGEDOWN:
nPos = si.nPos + 50;
break;
case SB_LINEUP:
nPos = si.nPos - 10;
break;
case SB_LINEDOWN:
nPos = si.nPos + 10;
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
nPos = si.nTrackPos;
break;
default:
nPos = si.nPos;
}
nPos = max(nPos, si.nMin);
nPos = min(nPos, si.nMax);
if (nPos != si.nPos)
{
ScrollWindowEx(hwnd, 0, si.nPos - nPos, NULL, NULL, NULL, NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.nPos = nPos;
si.fMask = SIF_POS;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
UpdateWindow(hwnd);
}
nPos = max(nPos, si.nMin);
nPos = min(nPos, si.nMax);
if (nPos != si.nPos)
{
ScrollWindowEx(hwnd, 0, si.nPos - nPos, NULL, NULL, NULL, NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.nPos = nPos;
si.fMask = SIF_POS;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
UpdateWindow(hwnd);
}
return 0;
return 0;
}
static LRESULT
Display_OnDestroy(HWND hwnd)
{
DISPLAYDATA* pData;
int i;
DISPLAYDATA* pData;
int i;
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
/* Delete the fonts */
DeleteObject(pData->hCaptionFont);
DeleteObject(pData->hCharSetFont);
DeleteObject(pData->hSizeFont);
/* Delete the fonts */
DeleteObject(pData->hCaptionFont);
DeleteObject(pData->hCharSetFont);
DeleteObject(pData->hSizeFont);
for (i = 0; i < MAX_SIZES; i++)
{
DeleteObject(pData->hFonts[i]);
}
for (i = 0; i < MAX_SIZES; i++)
{
DeleteObject(pData->hFonts[i]);
}
/* Free the data structure */
free(pData);
/* Free the data structure */
free(pData);
return 0;
return 0;
}
LRESULT
Display_OnPrint(HWND hwnd)
{
PRINTDLG pfont;
TEXTMETRIC tm;
int copies, yPos;
PRINTDLG pfont;
TEXTMETRIC tm;
int copies, yPos;
/* Clears the memory before using it */
ZeroMemory(&pfont, sizeof(pfont));
/* Clears the memory before using it */
ZeroMemory(&pfont, sizeof(pfont));
pfont.lStructSize = sizeof(pfont);
pfont.hwndOwner = hwnd;
pfont.hDevMode = NULL;
pfont.hDevNames = NULL;
pfont.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
pfont.nCopies = 1;
pfont.nFromPage = 0xFFFF;
pfont.nToPage = 0xFFFF;
pfont.nMinPage = 1;
pfont.nMaxPage = 0xFFFF;
pfont.lStructSize = sizeof(pfont);
pfont.hwndOwner = hwnd;
pfont.hDevMode = NULL;
pfont.hDevNames = NULL;
pfont.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
pfont.nCopies = 1;
pfont.nFromPage = 0xFFFF;
pfont.nToPage = 0xFFFF;
pfont.nMinPage = 1;
pfont.nMaxPage = 0xFFFF;
/* Opens up the print dialog box */
if (PrintDlg(&pfont))
{
DOCINFO docinfo;
/* Opens up the print dialog box */
if (PrintDlg(&pfont))
{
DOCINFO docinfo;
#if 0
DISPLAYDATA* pData;
DISPLAYDATA* pData;
pData = malloc(sizeof(DISPLAYDATA));
ZeroMemory(pData, sizeof(DISPLAYDATA));
pData = malloc(sizeof(DISPLAYDATA));
ZeroMemory(pData, sizeof(DISPLAYDATA));
/* Sets up the font layout */
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
/* Sets up the font layout */
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
#endif
docinfo.cbSize = sizeof(DOCINFO);
docinfo.lpszDocName = L"Printing Font";
docinfo.lpszOutput = NULL;
docinfo.lpszDatatype = NULL;
docinfo.fwType = 0;
docinfo.cbSize = sizeof(DOCINFO);
docinfo.lpszDocName = L"Printing Font";
docinfo.lpszOutput = NULL;
docinfo.lpszDatatype = NULL;
docinfo.fwType = 0;
/* We start printing */
StartDoc(pfont.hDC, &docinfo);
/* We start printing */
StartDoc(pfont.hDC, &docinfo);
/* Grabs the text metrics for the printer */
GetTextMetrics(pfont.hDC, &tm);
/* Grabs the text metrics for the printer */
GetTextMetrics(pfont.hDC, &tm);
/* Start out with 0 for the y position for the page */
yPos = 0;
/* Start out with 0 for the y position for the page */
yPos = 0;
/* Starts out with the current page */
StartPage(pfont.hDC);
/* Starts out with the current page */
StartPage(pfont.hDC);
/* Used when printing for more than one copy */
for (copies = 0; copies < pfont.nCopies; copies++)
{
/* Test output */
TextOutW(pfont.hDC, 10, yPos, L"Testing...1...2...3", 19);
/* Used when printing for more than one copy */
for (copies = 0; copies < pfont.nCopies; copies++)
{
/* Test output */
TextOutW(pfont.hDC, 10, yPos, L"Testing...1...2...3", 19);
/* TODO: Determine if using Display_DrawText() will work for both rendering out to the
window and to the printer output */
/* TODO: Determine if using Display_DrawText() will work for both rendering out to the
window and to the printer output */
#if 0
Display_DrawText(pfont.hDC, pData, yPos);
Display_DrawText(pfont.hDC, pData, yPos);
#endif
/* Ends the current page */
EndPage(pfont.hDC);
/* Ends the current page */
EndPage(pfont.hDC);
/* If we are making more than one copy, start a new page */
if (copies != pfont.nCopies)
{
yPos = 0;
StartPage(pfont.hDC);
}
}
/* If we are making more than one copy, start a new page */
if (copies != pfont.nCopies)
{
yPos = 0;
StartPage(pfont.hDC);
}
}
/* The printing is now over */
EndDoc(pfont.hDC);
/* The printing is now over */
EndDoc(pfont.hDC);
DeleteDC(pfont.hDC);
DeleteDC(pfont.hDC);
#if 0
/* Frees the memory since we no longer need it for now */
free(pData);
/* Frees the memory since we no longer need it for now */
free(pData);
#endif
}
}
return 0;
return 0;
}
LRESULT
@ -542,36 +527,35 @@ Display_GetFullName(HWND hwnd, INT length, PWSTR ptr)
LRESULT CALLBACK
DisplayProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return Display_OnCreate(hwnd);
switch (message)
{
case WM_CREATE:
return Display_OnCreate(hwnd);
case WM_PAINT:
return Display_OnPaint(hwnd);
case WM_PAINT:
return Display_OnPaint(hwnd);
case WM_SIZE:
return Display_OnSize(hwnd);
case WM_SIZE:
return Display_OnSize(hwnd);
case WM_VSCROLL:
return Display_OnVScroll(hwnd, wParam);
case WM_VSCROLL:
return Display_OnVScroll(hwnd, wParam);
case FVM_SETTYPEFACE:
return Display_SetTypeFace(hwnd, (PLOGFONTW)lParam);
case FVM_SETTYPEFACE:
return Display_SetTypeFace(hwnd, (PLOGFONTW)lParam);
case FVM_SETSTRING:
return Display_SetString(hwnd, (WCHAR *)lParam);
case FVM_SETSTRING:
return Display_SetString(hwnd, (WCHAR *)lParam);
case FVM_GETFULLNAME:
return Display_GetFullName(hwnd, (INT)wParam, (PWSTR)lParam);
case FVM_GETFULLNAME:
return Display_GetFullName(hwnd, (INT)wParam, (PWSTR)lParam);
case WM_DESTROY:
return Display_OnDestroy(hwnd);
case WM_DESTROY:
return Display_OnDestroy(hwnd);
default:
return DefWindowProcW(hwnd, message, wParam, lParam);
}
default:
return DefWindowProcW(hwnd, message, wParam, lParam);
}
return 0;
return 0;
}

View file

@ -1,24 +1,9 @@
/*
* fontview
*
* fontview.c
*
* Copyright (C) 2007 Timo Kreuzer <timo <dot> kreuzer <at> reactos <dot> org>
* Copyright (C) 2016-2017 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* PROJECT: ReactOS Font Viewer
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Main source file
* COPYRIGHT: Copyright 2007 Timo Kreuzer <timo.kreuzer@reactos.org>
* Copyright 2016-2017 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#include "precomp.h"
@ -47,50 +32,50 @@ BOOL WINAPI GetFontResourceInfoW(LPCWSTR lpFileName, DWORD *pdwBufSize, void* lp
DWORD
FormatString(
DWORD dwFlags,
HINSTANCE hInstance,
DWORD dwStringId,
DWORD dwLanguageId,
LPWSTR lpBuffer,
DWORD nSize,
va_list* Arguments
DWORD dwFlags,
HINSTANCE hInstance,
DWORD dwStringId,
DWORD dwLanguageId,
LPWSTR lpBuffer,
DWORD nSize,
va_list* Arguments
)
{
DWORD dwRet;
int len;
WCHAR Buffer[1000];
DWORD dwRet;
int len;
WCHAR Buffer[1000];
len = LoadStringW(hInstance, dwStringId, (LPWSTR)Buffer, 1000);
len = LoadStringW(hInstance, dwStringId, (LPWSTR)Buffer, 1000);
if (len)
{
dwFlags |= FORMAT_MESSAGE_FROM_STRING;
dwFlags &= ~(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM);
dwRet = FormatMessageW(dwFlags, Buffer, 0, dwLanguageId, lpBuffer, nSize, Arguments);
return dwRet;
}
return 0;
if (len)
{
dwFlags |= FORMAT_MESSAGE_FROM_STRING;
dwFlags &= ~(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM);
dwRet = FormatMessageW(dwFlags, Buffer, 0, dwLanguageId, lpBuffer, nSize, Arguments);
return dwRet;
}
return 0;
}
static void
ErrorMsgBox(HWND hParent, DWORD dwMessageId, ...)
{
HLOCAL hMemCaption = NULL;
HLOCAL hMemText = NULL;
va_list args;
HLOCAL hMemCaption = NULL;
HLOCAL hMemText = NULL;
va_list args;
va_start(args, dwMessageId);
FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, dwMessageId, 0, (LPWSTR)&hMemText, 0, &args);
va_end(args);
va_start(args, dwMessageId);
FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, dwMessageId, 0, (LPWSTR)&hMemText, 0, &args);
va_end(args);
FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, IDS_ERROR, 0, (LPWSTR)&hMemCaption, 0, NULL);
FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, IDS_ERROR, 0, (LPWSTR)&hMemCaption, 0, NULL);
MessageBoxW(hParent, hMemText, hMemCaption, MB_ICONERROR);
MessageBoxW(hParent, hMemText, hMemCaption, MB_ICONERROR);
LocalFree(hMemCaption);
LocalFree(hMemText);
LocalFree(hMemCaption);
LocalFree(hMemText);
}
int WINAPI
@ -99,14 +84,14 @@ wWinMain(HINSTANCE hThisInstance,
LPWSTR lpCmdLine,
int nCmdShow)
{
int argc;
INT i;
WCHAR** argv;
DWORD dwSize;
HWND hMainWnd;
MSG msg;
WNDCLASSEXW wincl;
LPCWSTR fileName;
int argc;
INT i;
WCHAR** argv;
DWORD dwSize;
HWND hMainWnd;
MSG msg;
WNDCLASSEXW wincl;
LPCWSTR fileName;
switch (GetUserDefaultUILanguage())
{
@ -118,48 +103,48 @@ wWinMain(HINSTANCE hThisInstance,
break;
}
g_hInstance = hThisInstance;
g_hInstance = hThisInstance;
/* Get unicode command line */
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argc < 2)
{
/* Get unicode command line */
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argc < 2)
{
#if 0
WCHAR szFileName[MAX_PATH] = L"";
OPENFILENAMEW fontOpen;
WCHAR szFileName[MAX_PATH] = L"";
OPENFILENAMEW fontOpen;
WCHAR filter[MAX_PATH*2] = {0}, dialogTitle[MAX_PATH];
LoadStringW(NULL, IDS_OPEN, dialogTitle, ARRAYSIZE(dialogTitle));
LoadStringW(NULL, IDS_FILTER_LIST, filter, ARRAYSIZE(filter) - 1);
LoadStringW(NULL, IDS_OPEN, dialogTitle, ARRAYSIZE(dialogTitle));
LoadStringW(NULL, IDS_FILTER_LIST, filter, ARRAYSIZE(filter) - 1);
/* Clears out any values of fontOpen before we use it */
ZeroMemory(&fontOpen, sizeof(fontOpen));
/* Clears out any values of fontOpen before we use it */
ZeroMemory(&fontOpen, sizeof(fontOpen));
/* Sets up the open dialog box */
fontOpen.lStructSize = sizeof(fontOpen);
fontOpen.hwndOwner = NULL;
fontOpen.lpstrFilter = filter;
fontOpen.lpstrFile = szFileName;
fontOpen.lpstrTitle = dialogTitle;
fontOpen.nMaxFile = MAX_PATH;
fontOpen.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
fontOpen.lpstrDefExt = L"ttf";
/* Sets up the open dialog box */
fontOpen.lStructSize = sizeof(fontOpen);
fontOpen.hwndOwner = NULL;
fontOpen.lpstrFilter = filter;
fontOpen.lpstrFile = szFileName;
fontOpen.lpstrTitle = dialogTitle;
fontOpen.nMaxFile = MAX_PATH;
fontOpen.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
fontOpen.lpstrDefExt = L"ttf";
/* Opens up the Open File dialog box in order to chose a font file. */
if(GetOpenFileNameW(&fontOpen))
{
fileName = fontOpen.lpstrFile;
g_fileName = fileName;
} else {
/* If the user decides to close out of the open dialog effectively
exiting the program altogether */
return 0;
}
/* Opens up the Open File dialog box in order to chose a font file. */
if(GetOpenFileNameW(&fontOpen))
{
fileName = fontOpen.lpstrFile;
g_fileName = fileName;
} else {
/* If the user decides to close out of the open dialog effectively
exiting the program altogether */
return 0;
}
#endif
}
else
{
/* Try to add the font resource from command line */
}
else
{
/* Try to add the font resource from command line */
for (i = 1; i < argc; ++i)
{
// Treat the last argument as filename
@ -189,269 +174,269 @@ wWinMain(HINSTANCE hThisInstance,
fileName = argv[i];
}
}
g_fileName = fileName;
}
g_fileName = fileName;
}
if (!AddFontResourceW(g_fileName))
{
ErrorMsgBox(0, IDS_ERROR_NOFONT, g_fileName);
return -1;
}
if (!AddFontResourceW(g_fileName))
{
ErrorMsgBox(0, IDS_ERROR_NOFONT, g_fileName);
return -1;
}
/* Get the font name */
dwSize = sizeof(g_LogFonts);
ZeroMemory(g_LogFonts, sizeof(g_LogFonts));
if (!GetFontResourceInfoW(fileName, &dwSize, g_LogFonts, 2))
{
ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
return -1;
}
g_NumFonts = 0;
for (i = 0; i < ARRAYSIZE(g_LogFonts); ++i)
{
if (g_LogFonts[i].lfFaceName[0] == 0)
break;
/* Get the font name */
dwSize = sizeof(g_LogFonts);
ZeroMemory(g_LogFonts, sizeof(g_LogFonts));
if (!GetFontResourceInfoW(fileName, &dwSize, g_LogFonts, 2))
{
ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
return -1;
}
g_NumFonts = 0;
for (i = 0; i < ARRAYSIZE(g_LogFonts); ++i)
{
if (g_LogFonts[i].lfFaceName[0] == 0)
break;
++g_NumFonts;
}
if (g_NumFonts == 0)
{
ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
return -1;
}
++g_NumFonts;
}
if (g_NumFonts == 0)
{
ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
return -1;
}
/* get font title */
dwSize = sizeof(g_FontTitle);
ZeroMemory(g_FontTitle, sizeof(g_FontTitle));
GetFontResourceInfoW(fileName, &dwSize, g_FontTitle, 1);
/* get font title */
dwSize = sizeof(g_FontTitle);
ZeroMemory(g_FontTitle, sizeof(g_FontTitle));
GetFontResourceInfoW(fileName, &dwSize, g_FontTitle, 1);
if (!Display_InitClass(hThisInstance))
{
ErrorMsgBox(0, IDS_ERROR_NOCLASS);
return -1;
}
if (!Display_InitClass(hThisInstance))
{
ErrorMsgBox(0, IDS_ERROR_NOCLASS);
return -1;
}
/* The main window class */
wincl.cbSize = sizeof (WNDCLASSEXW);
wincl.style = CS_DBLCLKS;
wincl.lpfnWndProc = MainWndProc;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hInstance = hThisInstance;
wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT));
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
wincl.lpszMenuName = NULL;
wincl.lpszClassName = g_szFontViewClassName;
wincl.hIconSm = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT));
/* The main window class */
wincl.cbSize = sizeof (WNDCLASSEXW);
wincl.style = CS_DBLCLKS;
wincl.lpfnWndProc = MainWndProc;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hInstance = hThisInstance;
wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT));
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
wincl.lpszMenuName = NULL;
wincl.lpszClassName = g_szFontViewClassName;
wincl.hIconSm = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT));
/* Register the window class, and if it fails quit the program */
if (!RegisterClassExW (&wincl))
{
ErrorMsgBox(0, IDS_ERROR_NOCLASS);
return 0;
}
/* Register the window class, and if it fails quit the program */
if (!RegisterClassExW (&wincl))
{
ErrorMsgBox(0, IDS_ERROR_NOCLASS);
return 0;
}
/* The class is registered, let's create the main window */
hMainWnd = CreateWindowExW(
0, /* Extended possibilities for variation */
g_szFontViewClassName, /* Classname */
g_FontTitle, /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
ShowWindow(hMainWnd, nCmdShow);
/* The class is registered, let's create the main window */
hMainWnd = CreateWindowExW(
0, /* Extended possibilities for variation */
g_szFontViewClassName, /* Classname */
g_FontTitle, /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
ShowWindow(hMainWnd, nCmdShow);
/* Main message loop */
while (GetMessage (&msg, NULL, 0, 0))
{
if (IsDialogMessage(hMainWnd, &msg))
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/* Main message loop */
while (GetMessage (&msg, NULL, 0, 0))
{
if (IsDialogMessage(hMainWnd, &msg))
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
RemoveFontResourceW(argv[1]);
RemoveFontResourceW(argv[1]);
return (int)msg.wParam;
return (int)msg.wParam;
}
static LRESULT
MainWnd_OnCreate(HWND hwnd)
{
WCHAR szQuit[MAX_BUTTONNAME];
WCHAR szPrint[MAX_BUTTONNAME];
WCHAR szString[MAX_STRING];
WCHAR szPrevious[MAX_STRING];
WCHAR szNext[MAX_STRING];
HWND hDisplay, hButtonInstall, hButtonPrint, hButtonPrev, hButtonNext;
WCHAR szQuit[MAX_BUTTONNAME];
WCHAR szPrint[MAX_BUTTONNAME];
WCHAR szString[MAX_STRING];
WCHAR szPrevious[MAX_STRING];
WCHAR szNext[MAX_STRING];
HWND hDisplay, hButtonInstall, hButtonPrint, hButtonPrev, hButtonNext;
/* create the display window */
hDisplay = CreateWindowExW(
0, /* Extended style */
g_szFontDisplayClassName, /* Classname */
L"", /* Title text */
WS_CHILD | WS_VSCROLL, /* Window style */
0, /* X-pos */
HEADER_SIZE, /* Y-Pos */
550, /* Width */
370-HEADER_SIZE, /* Height */
hwnd, /* Parent */
(HMENU)IDC_DISPLAY, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
/* create the display window */
hDisplay = CreateWindowExW(
0, /* Extended style */
g_szFontDisplayClassName, /* Classname */
L"", /* Title text */
WS_CHILD | WS_VSCROLL, /* Window style */
0, /* X-pos */
HEADER_SIZE, /* Y-Pos */
550, /* Width */
370-HEADER_SIZE, /* Height */
hwnd, /* Parent */
(HMENU)IDC_DISPLAY, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
LoadStringW(g_hInstance, IDS_STRING, szString, MAX_STRING);
SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString);
LoadStringW(g_hInstance, IDS_STRING, szString, MAX_STRING);
SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString);
/* Create the install button */
LoadStringW(g_hInstance, IDS_INSTALL, szQuit, MAX_BUTTONNAME);
hButtonInstall = CreateWindowExW(
0, /* Extended style */
L"button", /* Classname */
szQuit, /* Title text */
WS_CHILD | WS_VISIBLE, /* Window style */
BUTTON_POS_X, /* X-pos */
BUTTON_POS_Y, /* Y-Pos */
BUTTON_WIDTH, /* Width */
BUTTON_HEIGHT, /* Height */
hwnd, /* Parent */
(HMENU)IDC_INSTALL, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
SendMessage(hButtonInstall, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
/* Create the install button */
LoadStringW(g_hInstance, IDS_INSTALL, szQuit, MAX_BUTTONNAME);
hButtonInstall = CreateWindowExW(
0, /* Extended style */
L"button", /* Classname */
szQuit, /* Title text */
WS_CHILD | WS_VISIBLE, /* Window style */
BUTTON_POS_X, /* X-pos */
BUTTON_POS_Y, /* Y-Pos */
BUTTON_WIDTH, /* Width */
BUTTON_HEIGHT, /* Height */
hwnd, /* Parent */
(HMENU)IDC_INSTALL, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
SendMessage(hButtonInstall, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
EnableWindow(hButtonInstall, !g_DisableInstall);
/* Create the print button */
LoadStringW(g_hInstance, IDS_PRINT, szPrint, MAX_BUTTONNAME);
hButtonPrint = CreateWindowExW(
0, /* Extended style */
L"button", /* Classname */
szPrint, /* Title text */
WS_CHILD | WS_VISIBLE, /* Window style */
450, /* X-pos */
BUTTON_POS_Y, /* Y-Pos */
BUTTON_WIDTH, /* Width */
BUTTON_HEIGHT, /* Height */
hwnd, /* Parent */
(HMENU)IDC_PRINT, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
SendMessage(hButtonPrint, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
/* Create the print button */
LoadStringW(g_hInstance, IDS_PRINT, szPrint, MAX_BUTTONNAME);
hButtonPrint = CreateWindowExW(
0, /* Extended style */
L"button", /* Classname */
szPrint, /* Title text */
WS_CHILD | WS_VISIBLE, /* Window style */
450, /* X-pos */
BUTTON_POS_Y, /* Y-Pos */
BUTTON_WIDTH, /* Width */
BUTTON_HEIGHT, /* Height */
hwnd, /* Parent */
(HMENU)IDC_PRINT, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
SendMessage(hButtonPrint, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
/* Create the previous button */
LoadStringW(g_hInstance, IDS_PREVIOUS, szPrevious, MAX_BUTTONNAME);
hButtonPrev = CreateWindowExW(
0, /* Extended style */
L"button", /* Classname */
szPrevious, /* Title text */
WS_CHILD | WS_VISIBLE, /* Window style */
450, /* X-pos */
BUTTON_POS_Y, /* Y-Pos */
BUTTON_WIDTH, /* Width */
BUTTON_HEIGHT, /* Height */
hwnd, /* Parent */
(HMENU)IDC_PREV, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
SendMessage(hButtonPrev, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
/* Create the previous button */
LoadStringW(g_hInstance, IDS_PREVIOUS, szPrevious, MAX_BUTTONNAME);
hButtonPrev = CreateWindowExW(
0, /* Extended style */
L"button", /* Classname */
szPrevious, /* Title text */
WS_CHILD | WS_VISIBLE, /* Window style */
450, /* X-pos */
BUTTON_POS_Y, /* Y-Pos */
BUTTON_WIDTH, /* Width */
BUTTON_HEIGHT, /* Height */
hwnd, /* Parent */
(HMENU)IDC_PREV, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
SendMessage(hButtonPrev, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
/* Create the next button */
LoadStringW(g_hInstance, IDS_NEXT, szNext, MAX_BUTTONNAME);
hButtonNext = CreateWindowExW(
0, /* Extended style */
L"button", /* Classname */
szNext, /* Title text */
WS_CHILD | WS_VISIBLE, /* Window style */
450, /* X-pos */
BUTTON_POS_Y, /* Y-Pos */
BUTTON_WIDTH, /* Width */
BUTTON_HEIGHT, /* Height */
hwnd, /* Parent */
(HMENU)IDC_NEXT, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
SendMessage(hButtonNext, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
/* Create the next button */
LoadStringW(g_hInstance, IDS_NEXT, szNext, MAX_BUTTONNAME);
hButtonNext = CreateWindowExW(
0, /* Extended style */
L"button", /* Classname */
szNext, /* Title text */
WS_CHILD | WS_VISIBLE, /* Window style */
450, /* X-pos */
BUTTON_POS_Y, /* Y-Pos */
BUTTON_WIDTH, /* Width */
BUTTON_HEIGHT, /* Height */
hwnd, /* Parent */
(HMENU)IDC_NEXT, /* Identifier */
g_hInstance, /* Program Instance handler */
NULL /* Window Creation data */
);
SendMessage(hButtonNext, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
EnableWindow(hButtonPrev, FALSE);
if (g_NumFonts <= 1)
EnableWindow(hButtonNext, FALSE);
EnableWindow(hButtonPrev, FALSE);
if (g_NumFonts <= 1)
EnableWindow(hButtonNext, FALSE);
/* Init the display window with the font name */
g_FontIndex = 0;
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_LogFonts[g_FontIndex]);
ShowWindow(hDisplay, SW_SHOWNORMAL);
/* Init the display window with the font name */
g_FontIndex = 0;
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_LogFonts[g_FontIndex]);
ShowWindow(hDisplay, SW_SHOWNORMAL);
if (g_FontPrint)
PostMessage(hwnd, WM_COMMAND, IDC_PRINT, 0);
if (g_FontPrint)
PostMessage(hwnd, WM_COMMAND, IDC_PRINT, 0);
return 0;
return 0;
}
static LRESULT
MainWnd_OnSize(HWND hwnd)
{
RECT rc;
HWND hInstall, hPrint, hPrev, hNext, hDisplay;
HDWP hDWP;
RECT rc;
HWND hInstall, hPrint, hPrev, hNext, hDisplay;
HDWP hDWP;
GetClientRect(hwnd, &rc);
GetClientRect(hwnd, &rc);
hDWP = BeginDeferWindowPos(5);
hDWP = BeginDeferWindowPos(5);
hInstall = GetDlgItem(hwnd, IDC_INSTALL);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hInstall, NULL, BUTTON_POS_X, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, SWP_NOZORDER);
hInstall = GetDlgItem(hwnd, IDC_INSTALL);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hInstall, NULL, BUTTON_POS_X, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, SWP_NOZORDER);
hPrint = GetDlgItem(hwnd, IDC_PRINT);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hPrint, NULL, BUTTON_POS_X + BUTTON_WIDTH + BUTTON_PADDING, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, SWP_NOZORDER);
hPrint = GetDlgItem(hwnd, IDC_PRINT);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hPrint, NULL, BUTTON_POS_X + BUTTON_WIDTH + BUTTON_PADDING, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, SWP_NOZORDER);
hPrev = GetDlgItem(hwnd, IDC_PREV);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hPrev, NULL, rc.right - (BUTTON_WIDTH * 2 + BUTTON_PADDING + BUTTON_POS_X), BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, SWP_NOZORDER);
hPrev = GetDlgItem(hwnd, IDC_PREV);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hPrev, NULL, rc.right - (BUTTON_WIDTH * 2 + BUTTON_PADDING + BUTTON_POS_X), BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, SWP_NOZORDER);
hNext = GetDlgItem(hwnd, IDC_NEXT);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hNext, NULL, rc.right - (BUTTON_WIDTH + BUTTON_POS_X), BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, SWP_NOZORDER);
hNext = GetDlgItem(hwnd, IDC_NEXT);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hNext, NULL, rc.right - (BUTTON_WIDTH + BUTTON_POS_X), BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, SWP_NOZORDER);
hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hDisplay, NULL, 0, HEADER_SIZE, rc.right, rc.bottom - HEADER_SIZE, SWP_NOZORDER);
hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
if (hDWP)
hDWP = DeferWindowPos(hDWP, hDisplay, NULL, 0, HEADER_SIZE, rc.right, rc.bottom - HEADER_SIZE, SWP_NOZORDER);
EndDeferWindowPos(hDWP);
EndDeferWindowPos(hDWP);
InvalidateRect(hwnd, NULL, TRUE);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
return 0;
}
static LRESULT
MainWnd_OnPaint(HWND hwnd)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rc;
HDC hDC;
PAINTSTRUCT ps;
RECT rc;
hDC = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
rc.top = HEADER_SIZE - 2;
rc.bottom = HEADER_SIZE;
FillRect(hDC, &rc, GetStockObject(GRAY_BRUSH));
EndPaint(hwnd, &ps);
return 0;
hDC = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
rc.top = HEADER_SIZE - 2;
rc.bottom = HEADER_SIZE;
FillRect(hDC, &rc, GetStockObject(GRAY_BRUSH));
EndPaint(hwnd, &ps);
return 0;
}
static LRESULT
@ -542,37 +527,37 @@ MainWnd_OnInstall(HWND hwnd)
static LRESULT
MainWnd_OnPrev(HWND hwnd)
{
HWND hDisplay;
if (g_FontIndex > 0)
{
--g_FontIndex;
EnableWindow(GetDlgItem(hwnd, IDC_NEXT), TRUE);
if (g_FontIndex == 0)
EnableWindow(GetDlgItem(hwnd, IDC_PREV), FALSE);
HWND hDisplay;
if (g_FontIndex > 0)
{
--g_FontIndex;
EnableWindow(GetDlgItem(hwnd, IDC_NEXT), TRUE);
if (g_FontIndex == 0)
EnableWindow(GetDlgItem(hwnd, IDC_PREV), FALSE);
hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_LogFonts[g_FontIndex]);
InvalidateRect(hDisplay, NULL, TRUE);
}
return 0;
hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_LogFonts[g_FontIndex]);
InvalidateRect(hDisplay, NULL, TRUE);
}
return 0;
}
static LRESULT
MainWnd_OnNext(HWND hwnd)
{
HWND hDisplay;
if (g_FontIndex + 1 < g_NumFonts)
{
++g_FontIndex;
EnableWindow(GetDlgItem(hwnd, IDC_PREV), TRUE);
if (g_FontIndex == g_NumFonts - 1)
EnableWindow(GetDlgItem(hwnd, IDC_NEXT), FALSE);
HWND hDisplay;
if (g_FontIndex + 1 < g_NumFonts)
{
++g_FontIndex;
EnableWindow(GetDlgItem(hwnd, IDC_PREV), TRUE);
if (g_FontIndex == g_NumFonts - 1)
EnableWindow(GetDlgItem(hwnd, IDC_NEXT), FALSE);
hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_LogFonts[g_FontIndex]);
InvalidateRect(hDisplay, NULL, TRUE);
}
return 0;
hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_LogFonts[g_FontIndex]);
InvalidateRect(hDisplay, NULL, TRUE);
}
return 0;
}
LRESULT CALLBACK
@ -580,41 +565,39 @@ MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return MainWnd_OnCreate(hwnd);
case WM_CREATE:
return MainWnd_OnCreate(hwnd);
case WM_PAINT:
return MainWnd_OnPaint(hwnd);
case WM_PAINT:
return MainWnd_OnPaint(hwnd);
case WM_SIZE:
return MainWnd_OnSize(hwnd);
case WM_SIZE:
return MainWnd_OnSize(hwnd);
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_INSTALL:
return MainWnd_OnInstall(hwnd);
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_INSTALL:
return MainWnd_OnInstall(hwnd);
case IDC_PRINT:
return Display_OnPrint(hwnd);
case IDC_PRINT:
return Display_OnPrint(hwnd);
case IDC_PREV:
return MainWnd_OnPrev(hwnd);
case IDC_PREV:
return MainWnd_OnPrev(hwnd);
case IDC_NEXT:
return MainWnd_OnNext(hwnd);
}
break;
case IDC_NEXT:
return MainWnd_OnNext(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProcW(hwnd, message, wParam, lParam);
}
default: /* for messages that we don't deal with */
return DefWindowProcW(hwnd, message, wParam, lParam);
}
return 0;
return 0;
}
/* EOF */