2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/console/font.c
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 * Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
18 * Current active font, corresponding to the active console font,
19 * and used for painting the text samples.
21 FONT_PREVIEW FontPreview
= {NULL
, 0, 0};
25 * Standard font pixel/point heights for TrueType fonts
27 static const SHORT TrueTypePoints
[] =
29 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72
32 typedef struct _FONTSIZE_LIST_CTL
34 LIST_CTL RasterSizeList
; // ListBox for Raster font sizes; needs to handle bisection.
35 HWND hWndTTSizeList
; // ComboBox for TrueType font sizes.
36 BOOL bIsTTSizeDirty
; // TRUE or FALSE depending on whether we have edited the edit zone.
37 BOOL UseRasterOrTTList
; // TRUE: Use the Raster size list; FALSE: Use the TrueType size list.
38 BOOL TTSizePixelUnit
; // TRUE: Size in pixels (default); FALSE: Size in points.
39 LONG CurrentRasterSize
;
40 LONG CurrentTTSize
; // In whatever unit (pixels or points) currently selected.
41 } FONTSIZE_LIST_CTL
, *PFONTSIZE_LIST_CTL
;
43 /* Used by FontTypeChange() only */
44 static INT CurrentSelFont
= LB_ERR
;
45 static DWORD CurrentFontType
= (DWORD
)-1; // Invalid font type
50 IN FONT_PREVIEW
* Preview
,
51 IN PCONSOLE_STATE_INFO pConInfo
)
53 if (Preview
->hFont
) DeleteObject(Preview
->hFont
);
54 Preview
->hFont
= CreateConsoleFont(pConInfo
);
55 if (Preview
->hFont
== NULL
)
56 DPRINT1("RefreshFontPreview: CreateConsoleFont() failed\n");
57 GetFontCellSize(NULL
, Preview
->hFont
, &Preview
->CharHeight
, &Preview
->CharWidth
);
62 IN FONT_PREVIEW
* Preview
,
67 if (Preview
->hFont
) DeleteObject(Preview
->hFont
);
68 Preview
->hFont
= hFont
;
69 Preview
->CharWidth
= CharWidth
;
70 Preview
->CharHeight
= CharHeight
;
75 RasterSizeList_GetCount(
78 return (INT
)SendMessageW(ListCtl
->hWndList
, LB_GETCOUNT
, 0, 0);
83 RasterSizeList_GetData(
87 return (ULONG_PTR
)SendMessageW(ListCtl
->hWndList
, LB_GETITEMDATA
, (WPARAM
)Index
, 0);
92 LogicalSizeToPointSize(
102 // LogicalSize = tm.tmHeight - tm.tmInternalLeading;
103 PointSize
= MulDiv(LogicalSize
, 72, GetDeviceCaps(hDC
, LOGPIXELSY
));
106 ReleaseDC(NULL
, hDC
);
112 PointSizeToLogicalSize(
122 LogicalSize
= MulDiv(PointSize
, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
125 ReleaseDC(NULL
, hDC
);
132 FontSizeList_SelectFontSize(
133 IN PFONTSIZE_LIST_CTL SizeList
,
137 WCHAR szFontSize
[100];
140 // FIXME: Check whether FontSize == 0
141 // (or in the case of raster font maybe, whether HIWORD(FontSize) == Height == 0) ??
144 /* Find and select the best font size in the list corresponding to the current size */
145 if (SizeList
->UseRasterOrTTList
)
149 /* Raster font size (in pixels) */
150 SizeList
->CurrentRasterSize
= FontSize
;
152 nSel
= BisectListSortedByValue(&SizeList
->RasterSizeList
, FontSize
, NULL
, FALSE
);
153 idx
= (INT
)SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_GETCOUNT
, 0, 0);
156 /* Not found, select the first element of the list */
159 else if (nSel
>= idx
)
162 * We got an index beyond the end of the list (as per Bisect* functionality),
163 * so instead, select the last element of the list.
167 SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_SETCURSEL
, (WPARAM
)nSel
, 0);
171 /* TrueType font size (in pixels or points) */
172 SizeList
->CurrentTTSize
= FontSize
;
174 // _ultow(szFontSize, FontSize, 10);
175 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d", FontSize
);
177 /* Find the font size in the list, or add it both in the ComboBox list, sorted by size value (string), and its edit box */
178 nSel
= SendMessageW(SizeList
->hWndTTSizeList
, CB_FINDSTRINGEXACT
, 0, (LPARAM
)szFontSize
);
181 nSel
= (UINT
)SendMessageW(SizeList
->hWndTTSizeList
, CB_ADDSTRING
, -1, (LPARAM
)szFontSize
);
182 // ComboBox_SetText(...)
183 SetWindowTextW(SizeList
->hWndTTSizeList
, szFontSize
);
184 SizeList
->bIsTTSizeDirty
= TRUE
;
186 SendMessageW(SizeList
->hWndTTSizeList
, CB_SETCURSEL
, (WPARAM
)nSel
, 0);
191 FontSizeList_GetSelectedFontSize(
192 IN PFONTSIZE_LIST_CTL SizeList
)
196 PWCHAR pszNext
= NULL
;
197 WCHAR szFontSize
[100];
199 if (SizeList
->UseRasterOrTTList
)
201 /* Raster font size (in pixels) */
203 nSel
= (INT
)SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_GETCURSEL
, 0, 0);
204 if (nSel
== LB_ERR
) return 0;
206 FontSize
= (LONG
)SizeList
->RasterSizeList
.GetData(&SizeList
->RasterSizeList
, nSel
);
207 if (FontSize
== LB_ERR
) return 0;
209 SizeList
->CurrentRasterSize
= FontSize
;
213 /* TrueType font size (in pixels or points) */
215 if (!SizeList
->bIsTTSizeDirty
)
218 * The user just selected an existing size, read the ComboBox selection.
220 * See: https://support.microsoft.com/en-us/help/66365/how-to-process-a-cbn-selchange-notification-message
223 nSel
= SendMessageW(SizeList
->hWndTTSizeList
, CB_GETCURSEL
, 0, 0);
224 SendMessageW(SizeList
->hWndTTSizeList
, CB_GETLBTEXT
, nSel
, (LPARAM
)szFontSize
);
226 /* Validate the font size */
227 FontSize
= wcstoul(szFontSize
, &pszNext
, 10);
228 if ((FontSize
== 0) || (*pszNext
))
233 /* Read the ComboBox edit string, as the user has entered a custom size */
234 // ComboBox_GetText(...)
235 GetWindowTextW(SizeList
->hWndTTSizeList
, szFontSize
, ARRAYSIZE(szFontSize
));
237 /* Validate the font size */
238 FontSize
= wcstoul(szFontSize
, &pszNext
, 10);
239 if ((FontSize
== 0) || (*pszNext
))
242 /* Find if the font size already exists in the list; if not, add it */
243 nSel
= SendMessageW(SizeList
->hWndTTSizeList
, CB_FINDSTRINGEXACT
, 0, (LPARAM
)szFontSize
);
246 nSel
= (UINT
)SendMessageW(SizeList
->hWndTTSizeList
, CB_ADDSTRING
, -1, (LPARAM
)szFontSize
);
247 //// ComboBox_SetText(...)
248 //SetWindowTextW(SizeList->hWndTTSizeList, szFontSize);
249 //SizeList->bIsTTSizeDirty = TRUE;
251 SendMessageW(SizeList
->hWndTTSizeList
, CB_SETCURSEL
, (WPARAM
)nSel
, 0);
254 SizeList
->bIsTTSizeDirty
= FALSE
;
256 SizeList
->CurrentTTSize
= FontSize
;
259 * If the font size is given in points, instead of pixels,
260 * convert it into logical size.
262 if (!SizeList
->TTSizePixelUnit
)
263 FontSize
= -PointSizeToLogicalSize(NULL
, FontSize
);
273 IN LPCWSTR pszFaceName
,
278 /* Make sure the font doesn't already exist in the list */
279 if (SendMessageW(hWndList
, LB_FINDSTRINGEXACT
, 0, (LPARAM
)pszFaceName
) != LB_ERR
)
283 iItem
= (INT
)SendMessageW(hWndList
, LB_ADDSTRING
, 0, (LPARAM
)pszFaceName
);
286 DPRINT1("Failed to add font '%S'\n", pszFaceName
);
290 DPRINT1("Add font '%S'\n", pszFaceName
);
292 /* Store this information in the list-item's userdata area */
293 // SendMessageW(hWndList, LB_SETITEMDATA, idx, MAKELPARAM(fFixed, fTrueType));
294 SendMessageW(hWndList
, LB_SETITEMDATA
, iItem
, (LPARAM
)FontType
);
297 typedef struct _FACE_NAMES_PROC_PARAM
301 } FACE_NAMES_PROC_PARAM
, *PFACE_NAMES_PROC_PARAM
;
306 IN PNEWTEXTMETRICW lpntm
,
310 PFACE_NAMES_PROC_PARAM Param
= (PFACE_NAMES_PROC_PARAM
)lParam
;
312 if (IsValidConsoleFont2(lplf
, lpntm
, FontType
, Param
->CodePage
))
314 /* Add the font to the list */
315 AddFontToList(Param
->hWndList
, lplf
->lfFaceName
, FontType
);
318 /* Continue the font enumeration */
325 IN PNEWTEXTMETRICW lpntm
,
329 PFONTSIZE_LIST_CTL SizeList
= (PFONTSIZE_LIST_CTL
)lParam
;
330 UINT iItem
, iDupItem
;
331 WCHAR szFontSize
[100];
333 if (FontType
!= TRUETYPE_FONTTYPE
)
339 * Width = FontSize.X = LOWORD(FontSize);
340 * Height = FontSize.Y = HIWORD(FontSize);
343 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d x %d", lplf
->lfWidth
, lplf
->lfHeight
);
344 FontSize
= MAKEWPARAM(lplf
->lfWidth
, lplf
->lfHeight
);
346 /* Add the font size into the list, sorted by size value. Avoid any duplicates. */
347 /* Store this information in the list-item's userdata area */
349 iItem
= BisectListSortedByValue(&SizeList
->RasterSizeList
, FontSize
, &iDupItem
, TRUE
);
352 if (iDupItem
== LB_ERR
)
354 iItem
= (UINT
)SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_INSERTSTRING
, iItem
, (LPARAM
)szFontSize
);
355 if (iItem
!= LB_ERR
&& iItem
!= LB_ERRSPACE
)
356 iItem
= SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_SETITEMDATA
, iItem
, FontSize
);
363 /* TrueType or vectored font: list all the hardcoded font points */
365 for (i
= 0; i
< ARRAYSIZE(TrueTypePoints
); ++i
)
367 // _ultow(szFontSize, TrueTypePoints[i], 10);
368 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d", TrueTypePoints
[i
]);
370 /* Add the font size into the list, sorted by size value (string). Avoid any duplicates. */
371 if (SendMessageW(SizeList
->hWndTTSizeList
, CB_FINDSTRINGEXACT
, 0, (LPARAM
)szFontSize
) == CB_ERR
)
372 iItem
= (UINT
)SendMessageW(SizeList
->hWndTTSizeList
, CB_INSERTSTRING
, -1, (LPARAM
)szFontSize
);
375 /* Stop the enumeration now */
381 FaceNameList_Initialize(
385 FACE_NAMES_PROC_PARAM Param
;
390 Param
.hWndList
= hWndList
;
391 Param
.CodePage
= CodePage
;
393 ZeroMemory(&lf
, sizeof(lf
));
394 lf
.lfCharSet
= DEFAULT_CHARSET
; // CodePageToCharSet(CodePage);
395 // lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
398 EnumFontFamiliesExW(hDC
, &lf
, (FONTENUMPROCW
)EnumFaceNamesProc
, (LPARAM
)&Param
, 0);
399 ReleaseDC(NULL
, hDC
);
401 idx
= (INT
)SendMessageW(hWndList
, LB_GETCOUNT
, 0, 0);
402 if (idx
!= LB_ERR
&& idx
!= 0)
404 /* We have found some fonts and filled the list, we are fine! */
408 /* No fonts were found. Manually add default ones into the list. */
409 DPRINT1("The ideal console fonts were not found; manually add default ones.\n");
411 AddFontToList(hWndList
, L
"Terminal", RASTER_FONTTYPE
);
412 AddFontToList(hWndList
, L
"Lucida Console", TRUETYPE_FONTTYPE
);
413 if (CodePageToCharSet(CodePage
) != DEFAULT_CHARSET
)
414 AddFontToList(hWndList
, L
"Droid Sans Fallback", TRUETYPE_FONTTYPE
);
418 FaceNameList_SelectFont(
421 IN PFONTSIZE_LIST_CTL SizeList
,
429 iItem
= (INT
)SendMessageW(hWndList
, LB_FINDSTRINGEXACT
, 0, (LPARAM
)FaceName
);
431 iItem
= (INT
)SendMessageW(hWndList
, LB_FINDSTRINGEXACT
, 0, (LPARAM
)L
"Terminal");
434 SendMessageW(hWndList
, LB_SETCURSEL
, (WPARAM
)iItem
, 0);
436 if (FontWeight
>= FW_BOLD
)
437 CheckDlgButton(hDlg
, IDC_CHECK_BOLD_FONTS
, BST_CHECKED
);
439 CheckDlgButton(hDlg
, IDC_CHECK_BOLD_FONTS
, BST_UNCHECKED
);
441 /* Select the current font size */
444 * Width = FontSize.X = LOWORD(FontSize);
445 * Height = FontSize.Y = HIWORD(FontSize);
447 SizeList
->CurrentRasterSize
= MAKELONG(FontSize
.X
, FontSize
.Y
);
448 SizeList
->CurrentTTSize
= FontSize
.Y
;
449 // FontSizeList_SelectFontSize(SizeList, SizeList->CurrentRasterSize);
457 IN PFONTSIZE_LIST_CTL SizeList
)
461 if (SizeList
->UseRasterOrTTList
)
464 * Raster font: show the Raster size list, and
465 * hide the TrueType size list and the units.
468 // EnableDlgItem(hDlg, IDC_CHECK_BOLD_FONTS, FALSE);
470 hDlgItem
= GetDlgItem(hDlg
, IDC_RADIO_PIXEL_UNIT
);
471 ShowWindow(hDlgItem
, SW_HIDE
);
472 EnableWindow(hDlgItem
, FALSE
);
474 hDlgItem
= GetDlgItem(hDlg
, IDC_RADIO_POINT_UNIT
);
475 ShowWindow(hDlgItem
, SW_HIDE
);
476 EnableWindow(hDlgItem
, FALSE
);
478 hDlgItem
= SizeList
->hWndTTSizeList
;
479 ShowWindow(hDlgItem
, SW_HIDE
);
480 EnableWindow(hDlgItem
, FALSE
);
482 hDlgItem
= SizeList
->RasterSizeList
.hWndList
;
483 EnableWindow(hDlgItem
, TRUE
);
484 ShowWindow(hDlgItem
, SW_SHOW
);
489 * TrueType font: show the TrueType size list
490 * and the units, and hide the Raster size list.
493 // EnableDlgItem(hDlg, IDC_CHECK_BOLD_FONTS, TRUE);
495 hDlgItem
= SizeList
->RasterSizeList
.hWndList
;
496 ShowWindow(hDlgItem
, SW_HIDE
);
497 EnableWindow(hDlgItem
, FALSE
);
499 hDlgItem
= SizeList
->hWndTTSizeList
;
500 EnableWindow(hDlgItem
, TRUE
);
501 ShowWindow(hDlgItem
, SW_SHOW
);
503 hDlgItem
= GetDlgItem(hDlg
, IDC_RADIO_PIXEL_UNIT
);
504 EnableWindow(hDlgItem
, TRUE
);
505 ShowWindow(hDlgItem
, SW_SHOW
);
507 hDlgItem
= GetDlgItem(hDlg
, IDC_RADIO_POINT_UNIT
);
508 EnableWindow(hDlgItem
, TRUE
);
509 ShowWindow(hDlgItem
, SW_SHOW
);
516 IN PFONTSIZE_LIST_CTL SizeList
,
517 IN OUT PCONSOLE_STATE_INFO pConInfo
);
522 IN PFONTSIZE_LIST_CTL SizeList
,
523 IN OUT PCONSOLE_STATE_INFO pConInfo
)
525 HWND hListBox
= GetDlgItem(hDlg
, IDC_LBOX_FONTTYPE
);
529 LPCWSTR FontGrpBoxLabelTpl
= NULL
;
530 WCHAR FontGrpBoxLabel
[260];
532 nSel
= (INT
)SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
533 if (nSel
== LB_ERR
) return FALSE
;
536 * This is disabled, because there can be external parameters
537 * that may have changed (e.g. ConInfo->FontWeight, code page, ...)
538 * and that we don't control here, and that need a font refresh.
541 /* Check whether the selection has changed */
542 if (nSel
== CurrentSelFont
)
546 Length
= (INT
)SendMessageW(hListBox
, LB_GETTEXTLEN
, nSel
, 0);
547 if (Length
== LB_ERR
) return FALSE
;
549 FaceName
= HeapAlloc(GetProcessHeap(),
551 (Length
+ 1) * sizeof(WCHAR
));
552 if (FaceName
== NULL
) return FALSE
;
554 Length
= (INT
)SendMessageW(hListBox
, LB_GETTEXT
, nSel
, (LPARAM
)FaceName
);
555 FaceName
[Length
] = L
'\0';
557 StringCchCopyW(pConInfo
->FaceName
, ARRAYSIZE(pConInfo
->FaceName
), FaceName
);
558 DPRINT("pConInfo->FaceName = '%S'\n", pConInfo
->FaceName
);
561 * Retrieve the read-only font group box label string template,
562 * and set the group box label to the name of the selected font.
564 Length
= LoadStringW(hApplet
, IDS_GROUPBOX_FONT_NAME
, (LPWSTR
)&FontGrpBoxLabelTpl
, 0);
565 if (FontGrpBoxLabelTpl
&& Length
> 0)
567 StringCchCopyNW(FontGrpBoxLabel
, ARRAYSIZE(FontGrpBoxLabel
), FontGrpBoxLabelTpl
, Length
);
568 StringCchCatW(FontGrpBoxLabel
, ARRAYSIZE(FontGrpBoxLabel
), FaceName
);
569 SetDlgItemTextW(hDlg
, IDC_GROUPBOX_FONT_NAME
, FontGrpBoxLabel
);
572 HeapFree(GetProcessHeap(), 0, FaceName
);
575 * Reset the font size list, only:
576 * - if we have changed the type of font, or
577 * - if the font type is the same and is RASTER but the font has changed.
578 * Otherwise, if the font type is not RASTER and has not changed,
579 * we always display the TrueType default sizes and we don't need to
580 * recreate the list when we change between different TrueType fonts.
582 FontType
= SendMessageW(hListBox
, LB_GETITEMDATA
, nSel
, 0);
583 if (FontType
!= LB_ERR
)
585 SizeList
->UseRasterOrTTList
= (FontType
== RASTER_FONTTYPE
);
587 /* Display the correct font size list (if needed) */
588 if (CurrentFontType
!= FontType
)
589 UpdateFontSizeList(hDlg
, SizeList
);
591 /* Enumerate the available sizes for the selected font */
592 if ((CurrentFontType
!= FontType
) ||
593 (FontType
== RASTER_FONTTYPE
&& CurrentSelFont
!= nSel
))
598 if (SizeList
->UseRasterOrTTList
)
599 SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_RESETCONTENT
, 0, 0);
601 SendMessageW(SizeList
->hWndTTSizeList
, CB_RESETCONTENT
, 0, 0);
603 ZeroMemory(&lf
, sizeof(lf
));
604 lf
.lfCharSet
= DEFAULT_CHARSET
; // CodePageToCharSet(pConInfo->CodePage);
605 // lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
606 StringCchCopyW(lf
.lfFaceName
, ARRAYSIZE(lf
.lfFaceName
), pConInfo
->FaceName
);
609 EnumFontFamiliesExW(hDC
, &lf
, (FONTENUMPROCW
)EnumFontSizesProc
, (LPARAM
)SizeList
, 0);
610 ReleaseDC(NULL
, hDC
);
612 /* Re-select the current font size */
613 if (SizeList
->UseRasterOrTTList
)
614 FontSizeList_SelectFontSize(SizeList
, SizeList
->CurrentRasterSize
);
616 FontSizeList_SelectFontSize(SizeList
, SizeList
->CurrentTTSize
);
621 /* We failed, display the raster fonts size list */
622 SizeList
->UseRasterOrTTList
= TRUE
;
623 UpdateFontSizeList(hDlg
, SizeList
);
625 CurrentFontType
= FontType
;
626 CurrentSelFont
= nSel
;
628 FontSizeChange(hDlg
, SizeList
, pConInfo
);
635 IN PFONTSIZE_LIST_CTL SizeList
,
636 IN OUT PCONSOLE_STATE_INFO pConInfo
)
639 UINT CharWidth
, CharHeight
;
641 WCHAR szFontSize
[100];
644 * Retrieve the current selected font size.
645 * - If SizeList->UseRasterOrTTList is TRUE, or if it is FALSE but
646 * if SizeList->TTSizePixelUnit is TRUE, then the font size is in pixels;
647 * - If SizeList->TTSizePixelUnit is FALSE, then the font size is in points.
649 FontSize
= FontSizeList_GetSelectedFontSize(SizeList
);
651 return FALSE
; // We have got an invalid font size...
654 * For TrueType fonts we set the requested width to zero
655 * so as to obtain a default aspect-ratio width.
657 CharHeight
= (UINT
)(SizeList
->UseRasterOrTTList
? HIWORD(FontSize
) : FontSize
);
658 CharWidth
= (UINT
)(SizeList
->UseRasterOrTTList
? LOWORD(FontSize
) : 0);
660 hFont
= CreateConsoleFont2((LONG
)CharHeight
, (LONG
)CharWidth
, pConInfo
);
662 DPRINT1("FontSizeChange: CreateConsoleFont2() failed\n");
664 /* Retrieve the real character size in pixels */
665 GetFontCellSize(NULL
, hFont
, &CharHeight
, &CharWidth
);
668 * Update the font preview as well, and store the font handle. It will be
669 * freed at later update or when the font preview is refreshed or reset.
670 * For TrueType fonts, the preview will show the actual character width.
672 UpdateFontPreview(&FontPreview
, hFont
, CharWidth
, CharHeight
);
676 * Width = FontSize.X = LOWORD(FontSize);
677 * Height = FontSize.Y = HIWORD(FontSize);
679 pConInfo
->FontSize
.X
= (SHORT
)(SizeList
->UseRasterOrTTList
? CharWidth
: 0);
680 pConInfo
->FontSize
.Y
= (SHORT
)CharHeight
;
682 DPRINT("pConInfo->FontSize = (%d x %d) ; (CharWidth x CharHeight) = (%d x %d)\n",
683 pConInfo
->FontSize
.X
, pConInfo
->FontSize
.Y
, CharWidth
, CharHeight
);
685 InvalidateRect(GetDlgItem(hDlg
, IDC_STATIC_FONT_WINDOW_PREVIEW
), NULL
, TRUE
);
686 InvalidateRect(GetDlgItem(hDlg
, IDC_STATIC_SELECT_FONT_PREVIEW
), NULL
, TRUE
);
688 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d", CharWidth
);
689 SetDlgItemText(hDlg
, IDC_FONT_SIZE_X
, szFontSize
);
690 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d", CharHeight
);
691 SetDlgItemText(hDlg
, IDC_FONT_SIZE_Y
, szFontSize
);
704 PFONTSIZE_LIST_CTL SizeList
;
706 SizeList
= (PFONTSIZE_LIST_CTL
)GetWindowLongPtrW(hDlg
, DWLP_USER
);
712 HWND hFontList
= GetDlgItem(hDlg
, IDC_LBOX_FONTTYPE
);
714 SizeList
= (PFONTSIZE_LIST_CTL
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*SizeList
));
718 return (INT_PTR
)TRUE
;
720 SizeList
->RasterSizeList
.hWndList
= GetDlgItem(hDlg
, IDC_LBOX_FONTSIZE
);
721 SizeList
->RasterSizeList
.GetCount
= RasterSizeList_GetCount
;
722 SizeList
->RasterSizeList
.GetData
= RasterSizeList_GetData
;
723 SizeList
->hWndTTSizeList
= GetDlgItem(hDlg
, IDC_CBOX_FONTSIZE
);
724 SizeList
->bIsTTSizeDirty
= FALSE
;
725 SetWindowLongPtrW(hDlg
, DWLP_USER
, (LONG_PTR
)SizeList
);
727 /* By default show the raster font size list */
728 SizeList
->UseRasterOrTTList
= TRUE
;
730 /* By default show the font sizes in pixel units */
731 CheckRadioButton(hDlg
, IDC_RADIO_PIXEL_UNIT
, IDC_RADIO_POINT_UNIT
, IDC_RADIO_PIXEL_UNIT
);
732 SizeList
->TTSizePixelUnit
= TRUE
;
734 UpdateFontSizeList(hDlg
, SizeList
);
736 /* Initialize the font list */
737 FaceNameList_Initialize(hFontList
, ConInfo
->CodePage
);
739 /* Select the current font */
740 DPRINT1("ConInfo->FaceName = '%S'\n", ConInfo
->FaceName
);
741 FaceNameList_SelectFont(hDlg
, hFontList
,
748 /* Refresh everything */
749 FontTypeChange(hDlg
, SizeList
, ConInfo
);
757 HeapFree(GetProcessHeap(), 0, SizeList
);
758 return (INT_PTR
)TRUE
;
763 LPDRAWITEMSTRUCT drawItem
= (LPDRAWITEMSTRUCT
)lParam
;
765 if (drawItem
->CtlID
== IDC_STATIC_SELECT_FONT_PREVIEW
)
766 PaintText(drawItem
, ConInfo
, Screen
);
771 case WM_DISPLAYCHANGE
:
773 /* Retransmit to the preview window */
774 SendDlgItemMessageW(hDlg
, IDC_STATIC_FONT_WINDOW_PREVIEW
,
775 WM_DISPLAYCHANGE
, wParam
, lParam
);
780 case PSM_QUERYSIBLINGS
:
783 * If this is a notification from the "Options" dialog because we
784 * changed the code page, treat it using the WM_FONTCHANGE case,
785 * otherwise ignore it.
787 if (wParam
!= IDL_CODEPAGE
)
796 /* The pool of font resources has changed, re-enumerate the fonts */
797 HWND hFontList
= GetDlgItem(hDlg
, IDC_LBOX_FONTTYPE
);
799 /* Initialize the font list */
800 FaceNameList_Initialize(hFontList
, ConInfo
->CodePage
);
802 /* Select the current font */
803 FaceNameList_SelectFont(hDlg
, hFontList
,
810 /* Refresh everything */
811 FontTypeChange(hDlg
, SizeList
, ConInfo
);
817 switch (((LPNMHDR
)lParam
)->code
)
821 ApplyConsoleInfo(hDlg
);
831 if (HIWORD(wParam
) == LBN_SELCHANGE
/* || CBN_SELCHANGE */)
833 switch (LOWORD(wParam
))
835 case IDC_LBOX_FONTTYPE
:
837 /* Change the property sheet state only if the font has really changed */
838 if (FontTypeChange(hDlg
, SizeList
, ConInfo
))
839 PropSheet_Changed(GetParent(hDlg
), hDlg
);
843 case IDC_LBOX_FONTSIZE
:
844 case IDC_CBOX_FONTSIZE
:
846 /* Change the property sheet state only if the font has really changed */
847 if (FontSizeChange(hDlg
, SizeList
, ConInfo
))
848 PropSheet_Changed(GetParent(hDlg
), hDlg
);
853 /* NOTE: CBN_EDITUPDATE is sent first, and is followed by CBN_EDITCHANGE */
854 else if (HIWORD(wParam
) == CBN_EDITUPDATE
&& LOWORD(wParam
) == IDC_CBOX_FONTSIZE
)
857 PWCHAR pszNext
= NULL
;
858 WCHAR szFontSize
[100];
859 WCHAR szMessage
[260];
861 /* Read the ComboBox edit string, as the user has entered a custom size */
862 GetWindowTextW(SizeList
->hWndTTSizeList
, szFontSize
, ARRAYSIZE(szFontSize
));
864 /* Validate the font size */
865 FontSize
= wcstoul(szFontSize
, &pszNext
, 10);
866 if ((FontSize
== 0) || (*pszNext
))
869 StringCchPrintfW(szMessage
, ARRAYSIZE(szMessage
), L
"\"%s\" is not a valid font size.", szFontSize
);
870 MessageBoxW(hDlg
, szMessage
, L
"Error", MB_ICONINFORMATION
| MB_OK
);
872 /**/SizeList
->bIsTTSizeDirty
= TRUE
;/**/
874 else if (HIWORD(wParam
) == CBN_KILLFOCUS
&& LOWORD(wParam
) == IDC_CBOX_FONTSIZE
)
876 /* Change the property sheet state only if the font has really changed */
877 if (FontSizeChange(hDlg
, SizeList
, ConInfo
))
878 PropSheet_Changed(GetParent(hDlg
), hDlg
);
881 if (HIWORD(wParam
) == BN_CLICKED
)
883 switch (LOWORD(wParam
))
885 case IDC_CHECK_BOLD_FONTS
:
887 if (IsDlgButtonChecked(hDlg
, IDC_CHECK_BOLD_FONTS
) == BST_CHECKED
)
888 ConInfo
->FontWeight
= FW_BOLD
;
890 ConInfo
->FontWeight
= FW_NORMAL
;
892 FontTypeChange(hDlg
, SizeList
, ConInfo
);
893 PropSheet_Changed(GetParent(hDlg
), hDlg
);
897 case IDC_RADIO_PIXEL_UNIT
:
898 case IDC_RADIO_POINT_UNIT
:
900 SizeList
->TTSizePixelUnit
= (LOWORD(wParam
) == IDC_RADIO_PIXEL_UNIT
);
902 /* The call is valid only for TrueType fonts */
903 if (CurrentFontType
!= TRUETYPE_FONTTYPE
)
906 /* Change the property sheet state only if the font has really changed */
907 if (FontSizeChange(hDlg
, SizeList
, ConInfo
))
908 PropSheet_Changed(GetParent(hDlg
), hDlg
);