- Revert 47615. Please fix actual sysreg instead of adding inconsistency between...
[reactos.git] / rosapps / templates / imagesoft / font.c
1 #include <precomp.h>
2
3 int CALLBACK
4 EnumFontSizes(ENUMLOGFONTEX *lpelfe,
5 NEWTEXTMETRICEX *lpntme,
6 DWORD FontType,
7 LPARAM lParam)
8 {
9 static int ttsizes[] = { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };
10 TCHAR ach[100];
11
12 BOOL fTrueType = (lpelfe->elfLogFont.lfOutPrecision == OUT_STROKE_PRECIS) ? TRUE : FALSE;
13
14 HWND hwndCombo = (HWND)lParam;
15 INT i, idx;
16
17 if (fTrueType)
18 {
19 for (i = 0; i < (sizeof(ttsizes) / sizeof(ttsizes[0])); i++)
20 {
21 wsprintf(ach, _T("%d"), ttsizes[i]);
22
23 idx = (INT)SendMessage(hwndCombo,
24 CB_ADDSTRING,
25 0,
26 (LPARAM)ach);
27
28 SendMessage(hwndCombo,
29 CB_SETITEMDATA,
30 idx,
31 ttsizes[i]);
32 }
33 return 0;
34 }
35
36 return 1;
37 }
38
39
40 /* Font-enumeration callback */
41 int CALLBACK
42 EnumFontNames(ENUMLOGFONTEX *lpelfe,
43 NEWTEXTMETRICEX *lpntme,
44 DWORD FontType,
45 LPARAM lParam)
46 {
47 HWND hwndCombo = (HWND)lParam;
48 TCHAR *pszName = lpelfe->elfLogFont.lfFaceName;
49
50 /* make sure font doesn't already exist in our list */
51 if(SendMessage(hwndCombo,
52 CB_FINDSTRING,
53 0,
54 (LPARAM)pszName) == CB_ERR)
55 {
56 INT idx;
57 BOOL fFixed;
58 BOOL fTrueType;
59
60 /* add the font */
61 idx = (INT)SendMessage(hwndCombo,
62 CB_ADDSTRING,
63 0,
64 (LPARAM)pszName);
65
66 /* record the font's attributes (Fixedwidth and Truetype) */
67 fFixed = (lpelfe->elfLogFont.lfPitchAndFamily & FIXED_PITCH) ? TRUE : FALSE;
68 fTrueType = (lpelfe->elfLogFont.lfOutPrecision == OUT_STROKE_PRECIS) ? TRUE : FALSE;
69
70 /* store this information in the list-item's userdata area */
71 SendMessage(hwndCombo,
72 CB_SETITEMDATA,
73 idx,
74 MAKEWPARAM(fFixed, fTrueType));
75 }
76
77 return 1;
78 }
79
80
81 VOID
82 FillFontSizeComboList(HWND hwndCombo)
83 {
84 LOGFONT lf = { 0 };
85 HDC hdc = GetDC(hwndCombo);
86
87 /* default size */
88 INT cursize = 12;
89 INT i, count, nearest = 0;
90
91 HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
92
93 SendMessage(hwndCombo,
94 WM_SETFONT,
95 (WPARAM)hFont,
96 0);
97
98 lf.lfCharSet = DEFAULT_CHARSET;
99 lf.lfPitchAndFamily = 0;
100
101 /* empty the list */
102 SendMessage(hwndCombo,
103 CB_RESETCONTENT,
104 0,
105 0);
106
107 /* enumerate font sizes */
108 EnumFontFamiliesEx(hdc,
109 &lf,
110 (FONTENUMPROC)EnumFontSizes,
111 (LPARAM)hwndCombo,
112 0);
113
114 /* set selection to first item */
115 count = (INT)SendMessage(hwndCombo,
116 CB_GETCOUNT,
117 0,
118 0);
119
120 for(i = 0; i < count; i++)
121 {
122 INT n = (INT)SendMessage(hwndCombo,
123 CB_GETITEMDATA,
124 i,
125 0);
126
127 if (n <= cursize)
128 nearest = i;
129 }
130
131 SendMessage(hwndCombo,
132 CB_SETCURSEL,
133 nearest,
134 0);
135
136 ReleaseDC(hwndCombo,
137 hdc);
138 }
139
140
141 /* Initialize the font-list by enumeration all system fonts */
142 VOID
143 FillFontStyleComboList(HWND hwndCombo)
144 {
145 HDC hdc = GetDC(hwndCombo);
146 LOGFONT lf;
147
148 /* FIXME: draw each font in its own style */
149 HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
150 SendMessage(hwndCombo,
151 WM_SETFONT,
152 (WPARAM)hFont,
153 0);
154
155 /* FIXME: set this in relation to the widest string */
156 SendMessage(hwndCombo, CB_SETDROPPEDWIDTH, 150, 0);
157
158 lf.lfCharSet = ANSI_CHARSET; // DEFAULT_CHARSET;
159 lf.lfFaceName[0] = _T('\0'); // all fonts
160 lf.lfPitchAndFamily = 0;
161
162 /* store the list of fonts in the combo */
163 EnumFontFamiliesEx(hdc,
164 &lf,
165 (FONTENUMPROC)EnumFontNames,
166 (LPARAM)hwndCombo, 0);
167
168 ReleaseDC(hwndCombo,
169 hdc);
170
171 /* set default to Arial */
172 SendMessage(hwndCombo,
173 CB_SELECTSTRING,
174 -1,
175 (LPARAM)_T("Arial"));
176
177
178 }