2 * fontview display class
6 * Copyright (C) 2007 Timo Kreuzer <timo <dot> kreuzer <at> reactos <dot> org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 const WCHAR g_szFontDisplayClassName
[] = L
"FontDisplayClass";
32 LRESULT CALLBACK
DisplayProc(HWND
, UINT
, WPARAM
, LPARAM
);
34 /* Internal data storage type */
38 WCHAR szTypeFaceName
[LF_FULLFACESIZE
];
39 WCHAR szFormat
[MAX_FORMAT
];
40 WCHAR szString
[MAX_STRING
];
45 HFONT hFonts
[MAX_SIZES
];
46 int nSizes
[MAX_SIZES
];
47 int nHeights
[MAX_SIZES
];
50 /* This is the only public function, it registers the class */
52 Display_InitClass(HINSTANCE hInstance
)
56 /* Set the fontdisplay window class structure */
57 wincl
.cbSize
= sizeof(WNDCLASSEX
);
58 wincl
.style
= CS_DBLCLKS
;
59 wincl
.lpfnWndProc
= DisplayProc
;
62 wincl
.hInstance
= hInstance
;
64 wincl
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
65 wincl
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
66 wincl
.lpszMenuName
= NULL
;
67 wincl
.lpszClassName
= g_szFontDisplayClassName
;
70 /* Register the window class, and if it fails return FALSE */
71 if (!RegisterClassExW (&wincl
))
79 Display_DrawText(HDC hDC
, DISPLAYDATA
* pData
, int nYPos
)
85 WCHAR szCaption
[LF_FULLFACESIZE
+ 20];
87 /* This is the location on the DC where we draw */
90 hOldFont
= SelectObject(hDC
, pData
->hCaptionFont
);
91 GetTextMetrics(hDC
, &tm
);
93 swprintf(szCaption
, L
"%s%s", pData
->szTypeFaceName
, pData
->szFormat
);
94 TextOutW(hDC
, 0, y
, szCaption
, wcslen(szCaption
));
95 y
+= tm
.tmHeight
+ SPACING1
;
97 /* Draw a seperation Line */
98 SelectObject(hDC
, GetStockObject(BLACK_PEN
));
99 MoveToEx(hDC
, 0, y
, NULL
);
100 LineTo(hDC
, 10000, y
);
103 /* TODO: Output font info */
105 /* Output Character set */
106 hOldFont
= SelectObject(hDC
, pData
->hCharSetFont
);
107 GetTextMetrics(hDC
, &tm
);
108 swprintf(szCaption
, L
"abcdefghijklmnopqrstuvwxyz");
109 TextOutW(hDC
, 0, y
, szCaption
, wcslen(szCaption
));
110 y
+= tm
.tmHeight
+ 1;
112 swprintf(szCaption
, L
"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
113 TextOutW(hDC
, 0, y
, szCaption
, wcslen(szCaption
));
114 y
+= tm
.tmHeight
+ 1;
116 swprintf(szCaption
, L
"0123456789.:,;(\"~!@#$%^&*')");
117 TextOutW(hDC
, 0, y
, szCaption
, wcslen(szCaption
));
118 y
+= tm
.tmHeight
+ 1;
120 /* Draw a seperation Line */
121 SelectObject(hDC
, GetStockObject(BLACK_PEN
));
122 MoveToEx(hDC
, 0, y
, NULL
);
123 LineTo(hDC
, 10000, y
);
126 /* Output the strings for different sizes */
127 for (i
= 0; i
< MAX_SIZES
; i
++)
129 SelectObject(hDC
, pData
->hFonts
[i
]);
130 TextOutW(hDC
, 20, y
, pData
->szString
, wcslen(pData
->szString
));
131 GetTextMetrics(hDC
, &tm
);
132 y
+= tm
.tmHeight
+ 1;
133 SelectObject(hDC
, pData
->hSizeFont
);
134 swprintf(szSize
, L
"%d", pData
->nSizes
[i
]);
135 TextOutW(hDC
, 0, y
- 13 - tm
.tmDescent
, szSize
, wcslen(szSize
));
137 SelectObject(hDC
, hOldFont
);
143 Display_SetTypeFace(HWND hwnd
, PEXTLOGFONTW pExtLogFont
)
153 /* Set the new type face name */
154 pData
= (DISPLAYDATA
*)GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
155 _snwprintf(pData
->szTypeFaceName
, LF_FULLFACESIZE
, pExtLogFont
->elfFullName
);
157 /* Create the new fonts */
159 DeleteObject(pData
->hCharSetFont
);
161 logfont
= pExtLogFont
->elfLogFont
;
162 logfont
.lfHeight
= -MulDiv(16, GetDeviceCaps(GetDC(NULL
), LOGPIXELSY
), 72);
163 pData
->hCharSetFont
= CreateFontIndirectW(&logfont
);
165 /* Get font format */
166 // FIXME: Get the real font format (OpenType?)
167 SelectObject(hDC
, pData
->hCharSetFont
);
168 GetTextMetrics(hDC
, &tm
);
169 if ((tm
.tmPitchAndFamily
& TMPF_TRUETYPE
) == TMPF_TRUETYPE
)
171 swprintf(pData
->szFormat
, L
" (TrueType)");
174 for (i
= 0; i
< MAX_SIZES
; i
++)
176 DeleteObject(pData
->hFonts
[i
]);
177 logfont
.lfHeight
= -MulDiv(pData
->nSizes
[i
], GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
178 pData
->hFonts
[i
] = CreateFontIndirectW(&logfont
);
181 /* Calculate new page dimensions */
182 pData
->nPageHeight
= Display_DrawText(hDC
, pData
, 0);
183 ReleaseDC(hwnd
, hDC
);
185 /* Set the vertical scrolling range and page size */
186 GetClientRect(hwnd
, &rect
);
187 si
.cbSize
= sizeof(si
);
188 si
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
| SIF_TRACKPOS
;
190 si
.nMax
= pData
->nPageHeight
;
191 si
.nPage
= rect
.bottom
;
194 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
200 Display_SetString(HWND hwnd
, LPARAM lParam
)
204 pData
= (DISPLAYDATA
*)GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
205 _snwprintf(pData
->szString
, MAX_STRING
, (WCHAR
*)lParam
);
207 // FIXME: redraw the window
213 Display_OnCreate(HWND hwnd
)
216 const int nSizes
[MAX_SIZES
] = {8, 12, 18, 24, 36, 48, 60, 72};
218 EXTLOGFONTW ExtLogFont
= {{50, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
,
219 ANSI_CHARSET
, OUT_DEFAULT_PRECIS
,
220 CLIP_DEFAULT_PRECIS
, PROOF_QUALITY
,
221 DEFAULT_PITCH
, L
"Ms Shell Dlg"},
224 /* Create data structure */
225 pData
= malloc(sizeof(DISPLAYDATA
));
226 ZeroMemory(pData
, sizeof(DISPLAYDATA
));
228 /* Set the window's GWLP_USERDATA to our data structure */
229 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)pData
);
231 for (i
= 0; i
< MAX_SIZES
; i
++)
233 pData
->nSizes
[i
] = nSizes
[i
];
236 pData
->hCaptionFont
= CreateFontIndirectW(&ExtLogFont
.elfLogFont
);
237 ExtLogFont
.elfLogFont
.lfHeight
= 12;
238 pData
->hSizeFont
= CreateFontIndirectW(&ExtLogFont
.elfLogFont
);
240 Display_SetString(hwnd
, (LPARAM
)L
"Jackdaws love my big sphinx of quartz. 1234567890");
242 Display_SetTypeFace(hwnd
, &ExtLogFont
);
248 Display_OnPaint(HWND hwnd
)
254 pData
= (DISPLAYDATA
*)GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
256 /* Get the Scroll position */
257 si
.cbSize
= sizeof(si
);
259 GetScrollInfo(hwnd
, SB_VERT
, &si
);
261 BeginPaint(hwnd
, &ps
);
263 /* Erase background */
264 FillRect(ps
.hdc
, &ps
.rcPaint
, GetStockObject(WHITE_BRUSH
));
267 Display_DrawText(ps
.hdc
, pData
, si
.nPos
);
275 Display_OnSize(HWND hwnd
)
281 GetClientRect(hwnd
, &rect
);
283 /* Get the old scroll pos */
284 si
.cbSize
= sizeof(si
);
286 GetScrollInfo(hwnd
, SB_VERT
, &si
);
289 /* Set the new page size */
291 si
.nPage
= rect
.bottom
;
292 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
294 /* Get the new scroll pos */
296 GetScrollInfo(hwnd
, SB_VERT
, &si
);
298 /* If they don't match ... */
299 if (nOldPos
!= si
.nPos
)
301 /* ... scroll the window */
302 ScrollWindowEx(hwnd
, 0, nOldPos
- si
.nPos
, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
310 Display_OnVScroll(HWND hwnd
, WPARAM wParam
)
315 si
.cbSize
= sizeof(si
);
316 si
.fMask
= SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
317 GetScrollInfo(hwnd
, SB_VERT
, &si
);
319 switch(LOWORD(wParam
))
334 case SB_THUMBPOSITION
:
341 nPos
= max(nPos
, si
.nMin
);
342 nPos
= min(nPos
, si
.nMax
);
345 ScrollWindowEx(hwnd
, 0, si
.nPos
- nPos
, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
346 si
.cbSize
= sizeof(si
);
349 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
357 Display_OnDestroy(HWND hwnd
)
362 pData
= (DISPLAYDATA
*)GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
364 /* Delete the fonts */
365 DeleteObject(pData
->hCaptionFont
);
366 DeleteObject(pData
->hCharSetFont
);
367 DeleteObject(pData
->hSizeFont
);
369 for (i
= 0; i
< MAX_SIZES
; i
++)
371 DeleteObject(pData
->hFonts
[i
]);
374 /* Free the data structure */
381 DisplayProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
386 return Display_OnCreate(hwnd
);
389 return Display_OnPaint(hwnd
);
392 return Display_OnSize(hwnd
);
395 return Display_OnVScroll(hwnd
, wParam
);
397 case FVM_SETTYPEFACE
:
398 return Display_SetTypeFace(hwnd
, (PEXTLOGFONTW
)lParam
);
401 return Display_SetString(hwnd
, lParam
);
404 return Display_OnDestroy(hwnd
);
407 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);