Author: tkreuzer
Date: Fri May 25 11:48:17 2007
New Revision: 26883
URL:
http://svn.reactos.org/svn/reactos?rev=26883&view=rev
Log:
- initialize display class with "Ms Shell Dlg"
- don't show display window until font is set
- use negative value for font size (patch by roytam1)
See issue #2260 for more details.
Modified:
trunk/rosapps/fontview/display.c
trunk/rosapps/fontview/fontview.c
Modified: trunk/rosapps/fontview/display.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/fontview/display.c?rev=268…
==============================================================================
--- trunk/rosapps/fontview/display.c (original)
+++ trunk/rosapps/fontview/display.c Fri May 25 11:48:17 2007
@@ -91,14 +91,7 @@
hOldFont = SelectObject(hDC, pData->hCaptionFont);
GetTextMetrics(hDC, &tm);
- if (*pData->szFormat == 0)
- {
- swprintf(szCaption, pData->szTypeFaceName);
- }
- else
- {
- swprintf(szCaption, L"%s (%s)", pData->szTypeFaceName,
pData->szFormat);
- }
+ swprintf(szCaption, L"%s%s", pData->szTypeFaceName, pData->szFormat);
TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
y += tm.tmHeight + SPACING1;
@@ -148,34 +141,109 @@
}
static LRESULT
+Display_SetTypeFace(HWND hwnd, LPARAM lParam)
+{
+ DISPLAYDATA* pData;
+ TEXTMETRIC tm;
+ HDC hDC;
+ RECT rect;
+ SCROLLINFO si;
+ int i;
+
+ /* Set the new type face name */
+ pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ snwprintf(pData->szTypeFaceName, MAX_TYPEFACENAME, (WCHAR*)lParam);
+
+ /* Create the new fonts */
+ hDC = GetDC(hwnd);
+ DeleteObject(pData->hCharSetFont);
+ pData->hCharSetFont = CreateFontW(-MulDiv(16, GetDeviceCaps(GetDC(NULL), LOGPIXELSY),
72),
+ 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
+ ANSI_CHARSET, OUT_DEFAULT_PRECIS,
+ CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
+ DEFAULT_PITCH , pData->szTypeFaceName);
+
+ /* Get font format */
+ // FIXME: Get the real font format (OpenType?)
+ SelectObject(hDC, pData->hCharSetFont);
+ GetTextMetrics(hDC, &tm);
+ if ((tm.tmPitchAndFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE)
+ {
+ swprintf(pData->szFormat, L" (TrueType)");
+ }
+
+ for (i = 0; i < MAX_SIZES; i++)
+ {
+ DeleteObject(pData->hFonts[i]);
+ pData->hFonts[i] = CreateFontW(-MulDiv(pData->nSizes[i], GetDeviceCaps(hDC,
LOGPIXELSY), 72),
+ 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
+ ANSI_CHARSET, OUT_DEFAULT_PRECIS,
+ CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
+ DEFAULT_PITCH , pData->szTypeFaceName);
+ }
+
+ /* 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;
+}
+
+static LRESULT
+Display_SetString(HWND hwnd, LPARAM lParam)
+{
+ DISPLAYDATA* pData;
+
+ pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ snwprintf(pData->szString, MAX_STRING, (WCHAR*)lParam);
+
+ // FIXME: redraw the window
+
+ return 0;
+}
+
+static LRESULT
Display_OnCreate(HWND hwnd)
{
DISPLAYDATA* pData;
const int nSizes[7] = {12, 18, 24, 36, 48, 60, 72};
int i;
- /* Initialize data structure */
+ /* Create data structure */
pData = malloc(sizeof(DISPLAYDATA));
- pData->nPageHeight = 0;
- swprintf(pData->szTypeFaceName, L"");
- swprintf(pData->szFormat, L"");
- swprintf(pData->szString, L"");
-
- for (i = 0; i < MAX_SIZES; i++)
- {
- pData->nSizes[i] = nSizes[i];
- }
-
- pData->hCaptionFont = CreateFontW(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");
-
- pData->hSizeFont = CreateFontW(12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
- ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
- DEFAULT_PITCH , L"Ms Shell Dlg");
+ 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];
+ }
+
+ pData->hCaptionFont = CreateFontW(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");
+
+ pData->hSizeFont = CreateFontW(12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
+ ANSI_CHARSET, OUT_DEFAULT_PRECIS,
+ CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
+ DEFAULT_PITCH , L"Ms Shell Dlg");
+
+ Display_SetString(hwnd, (LPARAM)L"Jackdaws love my big sphinx of quartz.
1234567890");
+ Display_SetTypeFace(hwnd, (LPARAM)L"Ms Shell Dlg");
return 0;
}
@@ -196,7 +264,7 @@
BeginPaint(hwnd, &ps);
- /* Fill with white */
+ /* Erase background */
FillRect(ps.hdc, &ps.rcPaint, GetStockObject(WHITE_BRUSH));
/* Draw the text */
@@ -216,7 +284,7 @@
GetClientRect(hwnd, &rect);
- /* Get the old pos */
+ /* Get the old scroll pos */
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
@@ -227,15 +295,15 @@
si.nPage = rect.bottom;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
- /* Get the new pos */
+ /* Get the new scroll pos */
si.fMask = SIF_POS;
GetScrollInfo(hwnd, SB_VERT, &si);
- /* If the don't match ... */
+ /* If they don't match ... */
if (nOldPos != si.nPos)
{
/* ... scroll the window */
- ScrollWindowEx(hwnd, 0, -(si.nPos - nOldPos), NULL, NULL, NULL, NULL, SW_INVALIDATE);
+ ScrollWindowEx(hwnd, 0, nOldPos - si.nPos, NULL, NULL, NULL, NULL, SW_INVALIDATE);
UpdateWindow(hwnd);
}
@@ -278,7 +346,7 @@
nPos = min(nPos, si.nMax);
if (nPos != si.nPos)
{
- ScrollWindowEx(hwnd, 0, -(nPos - si.nPos), NULL, NULL, NULL, NULL, SW_INVALIDATE);
+ ScrollWindowEx(hwnd, 0, si.nPos - nPos, NULL, NULL, NULL, NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.nPos = nPos;
si.fMask = SIF_POS;
@@ -290,75 +358,6 @@
}
static LRESULT
-Display_SetTypeFace(HWND hwnd, LPARAM lParam)
-{
- DISPLAYDATA* pData;
- TEXTMETRIC tm;
- HDC hDC;
- RECT rect;
- SCROLLINFO si;
- int i;
-
- /* Set the new type face name */
- pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- snwprintf(pData->szTypeFaceName, MAX_TYPEFACENAME, (WCHAR*)lParam);
-
- /* Create the new fonts */
- hDC = GetDC(hwnd);
- pData->hCharSetFont = CreateFontW(-MulDiv(16, GetDeviceCaps(GetDC(NULL), LOGPIXELSY),
72), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
- ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
- DEFAULT_PITCH , pData->szTypeFaceName);
-
- /* Get font format */
- SelectObject(hDC, pData->hCharSetFont);
- GetTextMetrics(hDC, &tm);
- if ((tm.tmPitchAndFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE)
- {
- swprintf(pData->szFormat, L"TrueType");
- }
-
- for (i = 0; i < MAX_SIZES; i++)
- {
- pData->hFonts[i] = CreateFontW(MulDiv(pData->nSizes[i], GetDeviceCaps(hDC,
LOGPIXELSY), 72),
- 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
- ANSI_CHARSET, OUT_DEFAULT_PRECIS,
- CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
- DEFAULT_PITCH , pData->szTypeFaceName);
- SelectObject(hDC, pData->hFonts[i]);
- }
-
- /* 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;
-}
-
-static LRESULT
-Display_SetString(HWND hwnd, LPARAM lParam)
-{
- DISPLAYDATA* pData;
-
- pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- snwprintf(pData->szString, MAX_STRING, (WCHAR*)lParam);
-
- // FIXME: redraw the window
-
- return 0;
-}
-
-static LRESULT
Display_OnDestroy(HWND hwnd)
{
DISPLAYDATA* pData;
@@ -385,8 +384,8 @@
LRESULT CALLBACK
DisplayProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch (message)
- {
+ switch (message)
+ {
case WM_CREATE:
return Display_OnCreate(hwnd);
@@ -405,13 +404,13 @@
case FVM_SETSTRING:
return Display_SetString(hwnd, lParam);
- case WM_DESTROY:
+ case WM_DESTROY:
return Display_OnDestroy(hwnd);
- default:
- return DefWindowProcW(hwnd, message, wParam, lParam);
- }
-
- return 0;
-}
-
+ default:
+ return DefWindowProcW(hwnd, message, wParam, lParam);
+ }
+
+ return 0;
+}
+
Modified: trunk/rosapps/fontview/fontview.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/fontview/fontview.c?rev=26…
==============================================================================
--- trunk/rosapps/fontview/fontview.c (original)
+++ trunk/rosapps/fontview/fontview.c Fri May 25 11:48:17 2007
@@ -191,7 +191,7 @@
0, /* Extended style */
g_szFontDisplayClassName, /* Classname */
L"", /* Title text */
- WS_CHILD | WS_VSCROLL| WS_VISIBLE, /* Window style */
+ WS_CHILD | WS_VSCROLL, /* Window style */
0, /* X-pos */
HEADER_SIZE, /* Y-Pos */
550, /* Width */
@@ -202,10 +202,12 @@
NULL /* Window Creation data */
);
- /* Init the display window with the font name */
LoadStringW(g_hInstance, IDS_STRING, szString, MAX_STRING);
SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString);
+
+ /* Init the display window with the font name */
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)g_szTypeFaceName);
+ ShowWindow(hDisplay, SW_SHOWNORMAL);
/* Create the quit button */
LoadStringW(g_hInstance, IDS_QUIT, szQuit, MAX_BUTTONNAME);