Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
7.1 KiB

  1. #include "windows.h"
  2. #include <port1632.h>
  3. #include "fontsel.h"
  4. #define TA_LOWERCASE 0x01 // taken from winfile.h!
  5. #define TA_BOLD 0x02
  6. #define TA_ITALIC 0x04
  7. extern HANDLE hAppInstance;
  8. extern BOOL wTextAttribs;
  9. extern HWND hwndFrame;
  10. extern WORD wHelpMessage;
  11. typedef struct {
  12. HWND hwndLB;
  13. HDC hdc;
  14. } ENUM_FONT_DATA, *LPENUM_FONT_DATA;
  15. INT APIENTRY FontSizeEnumProc(const LOGFONT *lplf, const TEXTMETRIC *lptm, DWORD nFontType, LPARAM lpData);
  16. INT APIENTRY FontFaceEnumProc(const LOGFONT *lplf, const TEXTMETRIC *lptm, DWORD nFontType, LPARAM lpData);
  17. INT_PTR APIENTRY FontDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  18. INT APIENTRY GetHeightFromPointsString(LPSTR sz);
  19. VOID APIENTRY WFHelp(HWND hwnd);
  20. BOOL
  21. APIENTRY
  22. MyChooseFont(
  23. LPMYCHOOSEFONT lpcf
  24. )
  25. {
  26. INT_PTR ret;
  27. ret = DialogBoxParam(hAppInstance, MAKEINTRESOURCE(FONTDLG), lpcf->hwndOwner, FontDlgProc, (LPARAM)lpcf);
  28. return ret == IDOK;
  29. }
  30. INT
  31. APIENTRY
  32. FontFaceEnumProc(
  33. const LOGFONT *lplf,
  34. const TEXTMETRIC *lptm,
  35. DWORD nFontType,
  36. LPARAM lParam
  37. )
  38. {
  39. LPENUM_FONT_DATA lpData = (LPENUM_FONT_DATA) lParam;
  40. if (lplf->lfCharSet == ANSI_CHARSET) {
  41. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
  42. }
  43. return TRUE;
  44. }
  45. LPSTR
  46. NEAR
  47. PASCAL
  48. GetPointString(
  49. LPSTR buf,
  50. HDC hdc,
  51. INT height
  52. )
  53. {
  54. wsprintf(buf, "%d", MulDiv((height < 0) ? -height : height, 72, GetDeviceCaps(hdc, LOGPIXELSY)));
  55. return buf;
  56. }
  57. INT
  58. APIENTRY
  59. FontSizeEnumProc(
  60. const LOGFONT *lplf,
  61. const TEXTMETRIC *lptm,
  62. DWORD nFontType,
  63. LPARAM lParam
  64. )
  65. {
  66. INT height;
  67. CHAR buf[20];
  68. LPENUM_FONT_DATA lpData = (LPENUM_FONT_DATA) lParam;
  69. if (!(nFontType & RASTER_FONTTYPE)) {
  70. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)(LPSTR)"6");
  71. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)(LPSTR)"8");
  72. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)(LPSTR)"10");
  73. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)(LPSTR)"12");
  74. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)(LPSTR)"14");
  75. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)(LPSTR)"18");
  76. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)(LPSTR)"24");
  77. } else {
  78. height = lptm->tmHeight - lptm->tmInternalLeading;
  79. GetPointString(buf, lpData->hdc, height);
  80. SendMessage(lpData->hwndLB, CB_ADDSTRING, 0, (LPARAM)(LPSTR)buf);
  81. }
  82. return TRUE;
  83. }
  84. VOID
  85. NEAR
  86. PASCAL
  87. EnumFontSizes(
  88. HWND hDlg,
  89. HDC hdc,
  90. LPSTR szFace,
  91. INT height
  92. )
  93. {
  94. ENUM_FONT_DATA data;
  95. CHAR szTemp[10];
  96. SendDlgItemMessage(hDlg, IDD_PTSIZE, CB_RESETCONTENT, 0, 0L);
  97. data.hwndLB = GetDlgItem(hDlg, IDD_PTSIZE);
  98. data.hdc = hdc;
  99. EnumFonts(hdc, szFace, FontSizeEnumProc, (LPARAM)&data);
  100. GetPointString(szTemp, hdc, height);
  101. if ((INT)SendDlgItemMessage(hDlg, IDD_PTSIZE, CB_SELECTSTRING, -1, (LPARAM)szTemp) < 0)
  102. SendDlgItemMessage(hDlg, IDD_PTSIZE, CB_SETCURSEL, 0, 0L);
  103. }
  104. // needs to be exported of course
  105. INT_PTR
  106. APIENTRY
  107. FontDlgProc(
  108. HWND hDlg,
  109. UINT wMsg,
  110. WPARAM wParam,
  111. LPARAM lParam
  112. )
  113. {
  114. LOGFONT lf;
  115. ENUM_FONT_DATA data;
  116. HDC hdc;
  117. CHAR szTemp[80];
  118. INT sel;
  119. static LPMYCHOOSEFONT lpcf;
  120. switch (wMsg) {
  121. case WM_INITDIALOG:
  122. lpcf = (LPMYCHOOSEFONT)lParam;
  123. hdc = GetDC(NULL); // screen fonts
  124. data.hwndLB = GetDlgItem(hDlg, IDD_FACE);
  125. data.hdc = hdc;
  126. EnumFonts(hdc, NULL, FontFaceEnumProc, (LPARAM)&data);
  127. sel = (INT)SendDlgItemMessage(hDlg, IDD_FACE, CB_SELECTSTRING, -1, (LPARAM)(lpcf->lpLogFont)->lfFaceName);
  128. if (sel < 0) {
  129. SendDlgItemMessage(hDlg, IDD_FACE, CB_SETCURSEL, 0, 0L);
  130. sel = 0;
  131. }
  132. GetDlgItemText(hDlg, IDD_FACE, szTemp, sizeof(szTemp));
  133. EnumFontSizes(hDlg, hdc, szTemp, lpcf->lpLogFont->lfHeight);
  134. ReleaseDC(NULL, hdc);
  135. CheckDlgButton(hDlg, IDD_ITALIC, lpcf->lpLogFont->lfItalic);
  136. CheckDlgButton(hDlg, IDD_BOLD, (WORD)(lpcf->lpLogFont->lfWeight > 500));
  137. CheckDlgButton(hDlg, IDD_LOWERCASE, (WORD)(wTextAttribs & TA_LOWERCASE));
  138. break;
  139. case WM_COMMAND:
  140. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  141. case IDD_HELP:
  142. goto DoHelp;
  143. case IDD_FACE:
  144. switch (GET_WM_COMMAND_CMD(wParam, lParam)) {
  145. case CBN_SELCHANGE:
  146. GetDlgItemText(hDlg, IDD_FACE, szTemp, sizeof(szTemp));
  147. hdc = GetDC(NULL); // screen fonts
  148. EnumFontSizes(hDlg, hdc, szTemp, lpcf->lpLogFont->lfHeight);
  149. ReleaseDC(NULL, hdc);
  150. break;
  151. }
  152. break;
  153. case IDCANCEL:
  154. EndDialog(hDlg, FALSE);
  155. break;
  156. case IDOK:
  157. if (IsDlgButtonChecked(hDlg, IDD_LOWERCASE))
  158. wTextAttribs |= TA_LOWERCASE;
  159. else
  160. wTextAttribs &= ~TA_LOWERCASE;
  161. if (IsDlgButtonChecked(hDlg, IDD_ITALIC))
  162. wTextAttribs |= TA_ITALIC;
  163. else
  164. wTextAttribs &= ~TA_ITALIC;
  165. if (IsDlgButtonChecked(hDlg, IDD_BOLD))
  166. wTextAttribs |= TA_BOLD;
  167. else
  168. wTextAttribs &= ~TA_BOLD;
  169. GetDlgItemText(hDlg, IDD_FACE, (LPSTR)lf.lfFaceName, sizeof(lf.lfFaceName));
  170. GetDlgItemText(hDlg, IDD_PTSIZE, szTemp, sizeof(szTemp));
  171. lf.lfHeight = (SHORT)GetHeightFromPointsString(szTemp);
  172. lf.lfWeight = (SHORT)(IsDlgButtonChecked(hDlg, IDD_BOLD) ? 800 : 400);
  173. lf.lfItalic = (BYTE)IsDlgButtonChecked(hDlg, IDD_ITALIC);
  174. lf.lfWidth = 0;
  175. lf.lfEscapement = 0;
  176. lf.lfOrientation = 0;
  177. lf.lfUnderline = 0;
  178. lf.lfStrikeOut = 0;
  179. lf.lfCharSet = ANSI_CHARSET;
  180. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  181. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  182. lf.lfQuality = DEFAULT_QUALITY;
  183. lf.lfPitchAndFamily = DEFAULT_PITCH;
  184. *(lpcf->lpLogFont) = lf;
  185. EndDialog(hDlg, TRUE);
  186. break;
  187. default:
  188. return FALSE;
  189. }
  190. break;
  191. default:
  192. if (wMsg == wHelpMessage) {
  193. DoHelp:
  194. WFHelp(hDlg);
  195. return TRUE;
  196. } else
  197. return FALSE;
  198. }
  199. return TRUE;
  200. }