2009-10-12 03:35:35 +00:00
|
|
|
/*
|
2023-06-13 09:44:46 +00:00
|
|
|
* 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>
|
2009-10-12 03:35:35 +00:00
|
|
|
*/
|
|
|
|
|
2014-01-06 20:48:44 +00:00
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <malloc.h>
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
#define SPACING1 8
|
|
|
|
#define SPACING2 5
|
|
|
|
|
2017-02-08 17:56:22 +00:00
|
|
|
extern INT g_NumFonts;
|
|
|
|
extern WCHAR g_FontTitle[];
|
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
const WCHAR g_szFontDisplayClassName[] = L"FontDisplayClass";
|
|
|
|
LRESULT CALLBACK DisplayProc(HWND, UINT, WPARAM, LPARAM);
|
|
|
|
|
|
|
|
/* Internal data storage type */
|
|
|
|
typedef struct
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
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];
|
2009-10-12 03:35:35 +00:00
|
|
|
} DISPLAYDATA;
|
|
|
|
|
|
|
|
/* This is the only public function, it registers the class */
|
|
|
|
BOOL
|
|
|
|
Display_InitClass(HINSTANCE hInstance)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
/* Register the window class, and if it fails return FALSE */
|
|
|
|
if (!RegisterClassExW (&wincl))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* Draw a separation Line */
|
|
|
|
SelectObject(hDC, GetStockObject(BLACK_PEN));
|
|
|
|
MoveToEx(hDC, 0, y, NULL);
|
|
|
|
LineTo(hDC, 10000, y);
|
|
|
|
y += SPACING2;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
return y;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 11:39:15 +00:00
|
|
|
static int
|
|
|
|
CALLBACK
|
|
|
|
EnumFontFamProcW(
|
2023-06-13 09:44:46 +00:00
|
|
|
const LOGFONTW *lpelfe,
|
|
|
|
const TEXTMETRICW *lptm,
|
|
|
|
DWORD FontType,
|
|
|
|
LPARAM lParam)
|
2013-02-16 11:39:15 +00:00
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
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;
|
2013-02-16 11:39:15 +00:00
|
|
|
}
|
2013-02-16 11:46:05 +00:00
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
static LRESULT
|
2017-02-08 17:56:22 +00:00
|
|
|
Display_SetTypeFace(HWND hwnd, PLOGFONTW pLogFont)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
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));
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
return 0;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT
|
2017-02-08 17:56:22 +00:00
|
|
|
Display_SetString(HWND hwnd, LPCWSTR pszString)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
DISPLAYDATA* pData;
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
lstrcpynW(pData->szString, pszString, ARRAYSIZE(pData->szString));
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
InvalidateRect(hwnd, NULL, TRUE);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
return 0;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT
|
|
|
|
Display_OnCreate(HWND hwnd)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
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));
|
|
|
|
|
|
|
|
/* 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];
|
|
|
|
}
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
pData->hCaptionFont = CreateFontIndirectW(&LogFont);
|
|
|
|
LogFont.lfHeight = 12;
|
|
|
|
pData->hSizeFont = CreateFontIndirectW(&LogFont);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
Display_SetString(hwnd,
|
|
|
|
L"Jackdaws love my big sphinx of quartz. 1234567890");
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
Display_SetTypeFace(hwnd, &LogFont);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
return 0;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT
|
|
|
|
Display_OnPaint(HWND hwnd)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
DISPLAYDATA* pData;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
SCROLLINFO si;
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Get the Scroll position */
|
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_POS;
|
|
|
|
GetScrollInfo(hwnd, SB_VERT, &si);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
BeginPaint(hwnd, &ps);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Erase background */
|
|
|
|
FillRect(ps.hdc, &ps.rcPaint, GetStockObject(WHITE_BRUSH));
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Draw the text */
|
|
|
|
Display_DrawText(ps.hdc, pData, si.nPos);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
EndPaint(hwnd, &ps);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
return 0;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT
|
|
|
|
Display_OnSize(HWND hwnd)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
RECT rect;
|
|
|
|
SCROLLINFO si;
|
|
|
|
int nOldPos;
|
|
|
|
|
|
|
|
GetClientRect(hwnd, &rect);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT
|
|
|
|
Display_OnVScroll(HWND hwnd, WPARAM wParam)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
SCROLLINFO si;
|
|
|
|
int nPos;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT
|
|
|
|
Display_OnDestroy(HWND hwnd)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
DISPLAYDATA* pData;
|
|
|
|
int i;
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Delete the fonts */
|
|
|
|
DeleteObject(pData->hCaptionFont);
|
|
|
|
DeleteObject(pData->hCharSetFont);
|
|
|
|
DeleteObject(pData->hSizeFont);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
for (i = 0; i < MAX_SIZES; i++)
|
|
|
|
{
|
|
|
|
DeleteObject(pData->hFonts[i]);
|
|
|
|
}
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Free the data structure */
|
|
|
|
free(pData);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
return 0;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 14:25:19 +00:00
|
|
|
LRESULT
|
|
|
|
Display_OnPrint(HWND hwnd)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
PRINTDLG pfont;
|
|
|
|
TEXTMETRIC tm;
|
|
|
|
int copies, yPos;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* Opens up the print dialog box */
|
|
|
|
if (PrintDlg(&pfont))
|
|
|
|
{
|
|
|
|
DOCINFO docinfo;
|
2013-06-16 12:43:35 +00:00
|
|
|
#if 0
|
2023-06-13 09:44:46 +00:00
|
|
|
DISPLAYDATA* pData;
|
2013-06-16 12:43:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
pData = malloc(sizeof(DISPLAYDATA));
|
|
|
|
ZeroMemory(pData, sizeof(DISPLAYDATA));
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Sets up the font layout */
|
|
|
|
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
2013-06-16 12:43:35 +00:00
|
|
|
#endif
|
2023-06-13 09:44:46 +00:00
|
|
|
docinfo.cbSize = sizeof(DOCINFO);
|
|
|
|
docinfo.lpszDocName = L"Printing Font";
|
|
|
|
docinfo.lpszOutput = NULL;
|
|
|
|
docinfo.lpszDatatype = NULL;
|
|
|
|
docinfo.fwType = 0;
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* We start printing */
|
|
|
|
StartDoc(pfont.hDC, &docinfo);
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Grabs the text metrics for the printer */
|
|
|
|
GetTextMetrics(pfont.hDC, &tm);
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Start out with 0 for the y position for the page */
|
|
|
|
yPos = 0;
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Starts out with the current page */
|
|
|
|
StartPage(pfont.hDC);
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* 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);
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* TODO: Determine if using Display_DrawText() will work for both rendering out to the
|
|
|
|
window and to the printer output */
|
2013-06-16 12:43:35 +00:00
|
|
|
#if 0
|
2023-06-13 09:44:46 +00:00
|
|
|
Display_DrawText(pfont.hDC, pData, yPos);
|
2013-06-16 12:43:35 +00:00
|
|
|
#endif
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Ends the current page */
|
|
|
|
EndPage(pfont.hDC);
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* If we are making more than one copy, start a new page */
|
|
|
|
if (copies != pfont.nCopies)
|
|
|
|
{
|
|
|
|
yPos = 0;
|
|
|
|
StartPage(pfont.hDC);
|
|
|
|
}
|
|
|
|
}
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
/* The printing is now over */
|
|
|
|
EndDoc(pfont.hDC);
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
DeleteDC(pfont.hDC);
|
2013-06-16 12:43:35 +00:00
|
|
|
#if 0
|
2023-06-13 09:44:46 +00:00
|
|
|
/* Frees the memory since we no longer need it for now */
|
|
|
|
free(pData);
|
2013-06-16 12:43:35 +00:00
|
|
|
#endif
|
2023-06-13 09:44:46 +00:00
|
|
|
}
|
2012-07-15 14:25:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
return 0;
|
2012-07-15 14:25:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 23:00:19 +00:00
|
|
|
LRESULT
|
|
|
|
Display_GetFullName(HWND hwnd, INT length, PWSTR ptr)
|
|
|
|
{
|
|
|
|
DISPLAYDATA *pData;
|
|
|
|
INT len;
|
|
|
|
|
|
|
|
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
|
|
|
|
len = wcslen(pData->szTypeFaceName) + wcslen(pData->szFormat) + 2;
|
|
|
|
|
|
|
|
if (ptr != NULL && length >= len)
|
|
|
|
{
|
|
|
|
swprintf(ptr, L"%s%s", pData->szTypeFaceName, pData->szFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (LRESULT)len;
|
|
|
|
}
|
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
LRESULT CALLBACK
|
|
|
|
DisplayProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2023-06-13 09:44:46 +00:00
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_CREATE:
|
|
|
|
return Display_OnCreate(hwnd);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
case WM_PAINT:
|
|
|
|
return Display_OnPaint(hwnd);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
case WM_SIZE:
|
|
|
|
return Display_OnSize(hwnd);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
case WM_VSCROLL:
|
|
|
|
return Display_OnVScroll(hwnd, wParam);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
case FVM_SETTYPEFACE:
|
|
|
|
return Display_SetTypeFace(hwnd, (PLOGFONTW)lParam);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
case FVM_SETSTRING:
|
|
|
|
return Display_SetString(hwnd, (WCHAR *)lParam);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
case FVM_GETFULLNAME:
|
|
|
|
return Display_GetFullName(hwnd, (INT)wParam, (PWSTR)lParam);
|
2017-02-28 23:00:19 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
case WM_DESTROY:
|
|
|
|
return Display_OnDestroy(hwnd);
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
default:
|
|
|
|
return DefWindowProcW(hwnd, message, wParam, lParam);
|
|
|
|
}
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2023-06-13 09:44:46 +00:00
|
|
|
return 0;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|