move from branch
[reactos.git] / reactos / dll / win32 / comdlg32 / fontdlg.c
1 /*
2 * COMMDLG - Font Dialog
3 *
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <precomp.h>
23
24 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
25
26 static const WCHAR strWineFontData[] = {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A',0};
27 static const WCHAR strWineFontData_a[] =
28 {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A','_','A',0};
29 static const WCHAR chooseFontW[] = {'C','H','O','O','S','E','_','F','O','N','T',0};
30
31 #include "cdlg.h"
32
33 /* image list with TrueType bitmaps and more */
34 static HIMAGELIST himlTT = 0;
35 #define TTBITMAP_XSIZE 20 /* x-size of the bitmaps */
36
37 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
38 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
39
40 /* There is a table here of all charsets, and the sample text for each.
41 * There is a second table that translates a charset into an index into
42 * the first table.
43 */
44
45 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
46
47
48 static const WCHAR stWestern[]={'A','a','B','b','Y','y','Z','z',0}; /* Western and default */
49 static const WCHAR stSymbol[]={'S','y','m','b','o','l',0}; /* Symbol */
50 static const WCHAR stShiftJis[]={'A','a',0x3042,0x3041,0x30a2,0x30a1,0x4e9c,0x5b87,0}; /* Shift JIS */
51 static const WCHAR stHangul[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Hangul */
52 static const WCHAR stGB2312[]={0x5fae,0x8f6f,0x4e2d,0x6587,0x8f6f,0x4ef6,0}; /* GB2312 */
53 static const WCHAR stBIG5[]={0x4e2d,0x6587,0x5b57,0x578b,0x7bc4,0x4f8b,0}; /* BIG5 */
54 static const WCHAR stGreek[]={'A','a','B','b',0x0391,0x03b1,0x0392,0x03b2,0}; /* Greek */
55 static const WCHAR stTurkish[]={'A','a','B','b',0x011e,0x011f,0x015e,0x015f,0}; /* Turkish */
56 static const WCHAR stHebrew[]={'A','a','B','b',0x05e0,0x05e1,0x05e9,0x05ea,0}; /* Hebrew */
57 static const WCHAR stArabic[]={'A','a','B','b',0x0627,0x0628,0x062c,0x062f,0x0647,0x0648,0x0632,0};/* Arabic */
58 static const WCHAR stBaltic[]={'A','a','B','b','Y','y','Z','z',0}; /* Baltic */
59 static const WCHAR stVietname[]={'A','a','B','b',0x01a0,0x01a1,0x01af,0x01b0,0}; /* Vietnamese */
60 static const WCHAR stCyrillic[]={'A','a','B','b',0x0411,0x0431,0x0424,0x0444,0}; /* Cyrillic */
61 static const WCHAR stEastEur[]={'A','a','B','b',0xc1,0xe1,0xd4,0xf4,0}; /* East European */
62 static const WCHAR stThai[]={'A','a','B','b',0x0e2d,0x0e31,0x0e01,0x0e29,0x0e23,0x0e44,0x0e17,0x0e22,0}; /* Thai */
63 static const WCHAR stJohab[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Johab */
64 static const WCHAR stMac[]={'A','a','B','b','Y','y','Z','z',0}; /* Mac */
65 static const WCHAR stOEM[]={'A','a','B','b',0xf8,0xf1,0xfd,0}; /* OEM */
66 /* the following character sets actually behave different (Win2K observation):
67 * the sample string is 'sticky': it uses the sample string of the previous
68 * selected character set. That behaviour looks like some default, which is
69 * not (yet) implemented. */
70 static const WCHAR stVISCII[]={'A','a','B','b',0}; /* VISCII */
71 static const WCHAR stTCVN[]={'A','a','B','b',0}; /* TCVN */
72 static const WCHAR stKOI8[]={'A','a','B','b',0}; /* KOI-8 */
73 static const WCHAR stIso88593[]={'A','a','B','b',0}; /* ISO-8859-3 */
74 static const WCHAR stIso88594[]={'A','a','B','b',0}; /* ISO-8859-4 */
75 static const WCHAR stIso885910[]={'A','a','B','b',0}; /* ISO-8859-10 */
76 static const WCHAR stCeltic[]={'A','a','B','b',0};/* Celtic */
77
78 static const WCHAR *sample_lang_text[]={
79 stWestern,stSymbol,stShiftJis,stHangul,stGB2312,
80 stBIG5,stGreek,stTurkish,stHebrew,stArabic,
81 stBaltic,stVietname,stCyrillic,stEastEur,stThai,
82 stJohab,stMac,stOEM,stVISCII,stTCVN,
83 stKOI8,stIso88593,stIso88594,stIso885910,stCeltic};
84
85
86 static const BYTE CHARSET_ORDER[256]={
87 CI(ANSI), 0, CI(SYMBOL), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 0, 0, 0, 0, 0, 0, 0,
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
102 CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
103 };
104
105 static const struct {
106 DWORD mask;
107 const char *name;
108 } cfflags[] = {
109 #define XX(x) { x, #x },
110 XX(CF_SCREENFONTS)
111 XX(CF_PRINTERFONTS)
112 XX(CF_SHOWHELP)
113 XX(CF_ENABLEHOOK)
114 XX(CF_ENABLETEMPLATE)
115 XX(CF_ENABLETEMPLATEHANDLE)
116 XX(CF_INITTOLOGFONTSTRUCT)
117 XX(CF_USESTYLE)
118 XX(CF_EFFECTS)
119 XX(CF_APPLY)
120 XX(CF_ANSIONLY)
121 XX(CF_NOVECTORFONTS)
122 XX(CF_NOSIMULATIONS)
123 XX(CF_LIMITSIZE)
124 XX(CF_FIXEDPITCHONLY)
125 XX(CF_WYSIWYG)
126 XX(CF_FORCEFONTEXIST)
127 XX(CF_SCALABLEONLY)
128 XX(CF_TTONLY)
129 XX(CF_NOFACESEL)
130 XX(CF_NOSTYLESEL)
131 XX(CF_NOSIZESEL)
132 XX(CF_SELECTSCRIPT)
133 XX(CF_NOSCRIPTSEL)
134 XX(CF_NOVERTFONTS)
135 #undef XX
136 };
137
138 void _dump_cf_flags(DWORD cflags)
139 {
140 int i;
141
142 for (i = 0; i < sizeof(cfflags)/sizeof(cfflags[0]); i++)
143 if (cfflags[i].mask & cflags)
144 TRACE("%s|",cfflags[i].name);
145 TRACE("\n");
146 }
147
148 /***********************************************************************
149 * ChooseFontW (COMDLG32.@)
150 *
151 * Create a font dialog box.
152 *
153 * PARAMS
154 * lpChFont [I/O] in: information to initialize the dialog box.
155 * out: User's color selection
156 *
157 * RETURNS
158 * TRUE: Ok button clicked.
159 * FALSE: Cancel button clicked, or error.
160 */
161 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
162 {
163 LPCVOID template;
164 HRSRC hResInfo;
165 HINSTANCE hDlginst;
166 HGLOBAL hDlgTmpl;
167
168 TRACE("(%p)\n", lpChFont);
169
170 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
171 {
172 template=(LPCVOID)lpChFont->hInstance;
173 } else
174 {
175 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
176 {
177 hDlginst=lpChFont->hInstance;
178 if( !(hResInfo = FindResourceW(hDlginst, lpChFont->lpTemplateName,
179 (LPWSTR)RT_DIALOG)))
180 {
181 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
182 return FALSE;
183 }
184 } else
185 {
186 hDlginst=COMDLG32_hInstance;
187 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
188 {
189 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
190 return FALSE;
191 }
192 }
193 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
194 !(template = LockResource( hDlgTmpl )))
195 {
196 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
197 return FALSE;
198 }
199 }
200 if (TRACE_ON(commdlg))
201 _dump_cf_flags(lpChFont->Flags);
202
203 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
204 FIXME(": unimplemented flag (ignored)\n");
205
206 return DialogBoxIndirectParamW(COMDLG32_hInstance, template,
207 lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
208 }
209
210 /***********************************************************************
211 * ChooseFontA (COMDLG32.@)
212 *
213 * See ChosseFontW.
214 */
215 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
216 {
217 LPCVOID template;
218 HRSRC hResInfo;
219 HINSTANCE hDlginst;
220 HGLOBAL hDlgTmpl;
221
222 TRACE("(%p)\n", lpChFont);
223
224 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
225 {
226 template=(LPCVOID)lpChFont->hInstance;
227 } else
228 {
229 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
230 {
231 hDlginst=lpChFont->hInstance;
232 if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
233 (LPSTR)RT_DIALOG)))
234 {
235 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
236 return FALSE;
237 }
238 } else
239 {
240 hDlginst=COMDLG32_hInstance;
241 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
242 {
243 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
244 return FALSE;
245 }
246 }
247 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
248 !(template = LockResource( hDlgTmpl )))
249 {
250 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
251 return FALSE;
252 }
253 }
254 if (TRACE_ON(commdlg))
255 _dump_cf_flags(lpChFont->Flags);
256 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
257 FIXME(": unimplemented flag (ignored)\n");
258
259 return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
260 lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
261 }
262
263 #define TEXT_EXTRAS 4
264 #define TEXT_COLORS 16
265
266 static const COLORREF textcolors[TEXT_COLORS]=
267 {
268 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
269 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
270 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
271 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
272 };
273
274 /***********************************************************************
275 * CFn_HookCallChk32 [internal]
276 */
277 static BOOL CFn_HookCallChk32(LPCHOOSEFONTW lpcf)
278 {
279 if (lpcf)
280 if(lpcf->Flags & CF_ENABLEHOOK)
281 if (lpcf->lpfnHook)
282 return TRUE;
283 return FALSE;
284 }
285
286 /*************************************************************************
287 * AddFontFamily [internal]
288 */
289 INT AddFontFamily(const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
290 UINT nFontType, LPCHOOSEFONTW lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
291 {
292 int i;
293 WORD w;
294 const LOGFONTW *lplf = &(lpElfex->elfLogFont);
295
296 TRACE("font=%s (nFontType=%d)\n", debugstr_w(lplf->lfFaceName), nFontType);
297
298 if (lpcf->Flags & CF_FIXEDPITCHONLY)
299 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
300 return 1;
301 if (lpcf->Flags & CF_ANSIONLY)
302 if (lplf->lfCharSet != ANSI_CHARSET)
303 return 1;
304 if (lpcf->Flags & CF_TTONLY)
305 if (!(nFontType & TRUETYPE_FONTTYPE))
306 return 1;
307
308 if (e) e->added++;
309
310 i=SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
311 if (i == CB_ERR) {
312 i = SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
313 if( i != CB_ERR) {
314 /* store some important font information */
315 w = (lplf->lfPitchAndFamily) << 8 |
316 (HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
317 SendMessageW(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
318 }
319 }
320 return 1;
321 }
322
323 /*************************************************************************
324 * FontFamilyEnumProc32 [internal]
325 */
326 static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXW *lpElfex,
327 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam)
328 {
329 LPCFn_ENUMSTRUCT e;
330 e=(LPCFn_ENUMSTRUCT)lParam;
331 return AddFontFamily( lpElfex, (NEWTEXTMETRICEXW *) metrics,
332 dwFontType, e->lpcf32w, e->hWnd1, e);
333 }
334
335 /*************************************************************************
336 * SetFontStylesToCombo2 [internal]
337 *
338 * Fill font style information into combobox (without using font.c directly)
339 */
340 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf)
341 {
342 #define FSTYLES 4
343 struct FONTSTYLE
344 {
345 int italic;
346 int weight;
347 const WCHAR *stname;
348 };
349 static const WCHAR strRegular[] = {'R','e','g','u','l','a','r',0};
350 static const WCHAR strItalic[] = {'I','t','a','l','i','c',0};
351 static const WCHAR strBold[] = {'B','o','l','d',0};
352 static const WCHAR strBoldItalic[] = {'B','o','l','d',' ','I','t','a','l','i','c',0};
353 static const struct FONTSTYLE fontstyles[FSTYLES]={
354 { 0, FW_NORMAL, strRegular },
355 { 1, FW_NORMAL, strItalic },
356 { 0, FW_BOLD, strBold },
357 { 1, FW_BOLD, strBoldItalic }
358 };
359 HFONT hf;
360 TEXTMETRICW tm;
361 int i,j;
362 LOGFONTW lf;
363
364 memcpy(&lf, lplf, sizeof(LOGFONTW));
365
366 for (i=0;i<FSTYLES;i++)
367 {
368 lf.lfItalic=fontstyles[i].italic;
369 lf.lfWeight=fontstyles[i].weight;
370 hf=CreateFontIndirectW(&lf);
371 hf=SelectObject(hdc,hf);
372 GetTextMetricsW(hdc,&tm);
373 hf=SelectObject(hdc,hf);
374 DeleteObject(hf);
375 /* font successful created ? */
376 if (tm.tmWeight==fontstyles[i].weight &&
377 ((tm.tmItalic != 0)==fontstyles[i].italic))
378 {
379 j=SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
380 if (j==CB_ERR) return 1;
381 j=SendMessageW(hwnd, CB_SETITEMDATA, j,
382 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
383 if (j==CB_ERR) return 1;
384 }
385 }
386 return 0;
387 }
388
389 /*************************************************************************
390 * AddFontSizeToCombo3 [internal]
391 */
392 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTW lpcf)
393 {
394 int j;
395 WCHAR buffer[20];
396 static const WCHAR strFormat[] = {'%','2','d',0};
397
398 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
399 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
400 {
401 wsprintfW(buffer, strFormat, h);
402 j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
403 if (j==CB_ERR)
404 {
405 j=SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
406 if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
407 if (j==CB_ERR) return 1;
408 }
409 }
410 return 0;
411 }
412
413 /*************************************************************************
414 * SetFontSizesToCombo3 [internal]
415 */
416 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTW lpcf)
417 {
418 static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
419 int i;
420
421 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
422 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
423 return 0;
424 }
425
426 /*************************************************************************
427 * CFn_GetDC [internal]
428 */
429 static inline HDC CFn_GetDC(LPCHOOSEFONTW lpcf)
430 {
431 HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
432 lpcf->hDC :
433 GetDC(0);
434 if(!ret) ERR("HDC failure!!!\n");
435 return ret;
436 }
437
438 /*************************************************************************
439 * CFn_ReleaseDC [internal]
440 */
441 static inline void CFn_ReleaseDC(LPCHOOSEFONTW lpcf, HDC hdc)
442 {
443 if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
444 ReleaseDC(0, hdc);
445 }
446
447 /***********************************************************************
448 * AddFontStyle [internal]
449 */
450 INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
451 UINT nFontType, LPCHOOSEFONTW lpcf, HWND hcmb2, HWND hcmb3,
452 HWND hDlg, BOOL iswin16)
453 {
454 int i;
455 const LOGFONTW *lplf = &(lpElfex->elfLogFont);
456 HWND hcmb5;
457 HDC hdc;
458
459 TRACE("(nFontType=%d)\n",nFontType);
460 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
461 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
462 debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
463 lplf->lfEscapement,lplf->lfOrientation,
464 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
465 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
466 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
467 if (nFontType & RASTER_FONTTYPE)
468 {
469 INT points;
470 if(!(hdc = CFn_GetDC(lpcf))) return 0;
471 points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
472 72, GetDeviceCaps(hdc, LOGPIXELSY));
473 CFn_ReleaseDC(lpcf, hdc);
474 i = AddFontSizeToCombo3(hcmb3, points, lpcf);
475 if(i) return 0;
476 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
477
478 if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
479 {
480 if(!(hdc = CFn_GetDC(lpcf))) return 0;
481 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
482 CFn_ReleaseDC(lpcf, hdc);
483 if (i)
484 return 0;
485 }
486 if( iswin16 || !( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
487 i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
488 (LPARAM)lpElfex->elfScript);
489 if( i == CB_ERR) {
490 i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
491 (LPARAM)lpElfex->elfScript);
492 if( i != CB_ERR)
493 SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
494 }
495 return 1 ;
496 }
497
498 static INT CFn_FitFontSize( HWND hDlg, int points)
499 {
500 int i,n;
501 int ret = 0;
502 /* look for fitting font size in combobox3 */
503 n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
504 for (i=0;i<n;i++)
505 {
506 if (points == (int)SendDlgItemMessageW
507 (hDlg,cmb3, CB_GETITEMDATA,i,0))
508 {
509 SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0);
510 SendMessageW(hDlg, WM_COMMAND,
511 MAKEWPARAM(cmb3, CBN_SELCHANGE),
512 (LPARAM)GetDlgItem(hDlg,cmb3));
513 ret = 1;
514 break;
515 }
516 }
517 return ret;
518 }
519
520 static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
521 {
522 LONG id;
523 int i, ret = 0;
524 /* look for fitting font style in combobox2 */
525 for (i=0;i<TEXT_EXTRAS;i++)
526 {
527 id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
528 if (packedstyle == id)
529 {
530 SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
531 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
532 (LPARAM)GetDlgItem(hDlg,cmb2));
533 ret = 1;
534 break;
535 }
536 }
537 return ret;
538 }
539
540
541 static INT CFn_FitCharSet( HWND hDlg, int charset )
542 {
543 int i,n,cs;
544 /* look for fitting char set in combobox5 */
545 n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0);
546 for (i=0;i<n;i++)
547 {
548 cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
549 if (charset == cs)
550 {
551 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0);
552 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
553 (LPARAM)GetDlgItem(hDlg,cmb2));
554 return 1;
555 }
556 }
557 /* no charset fits: select the first one in the list */
558 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0);
559 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
560 (LPARAM)GetDlgItem(hDlg,cmb2));
561 return 0;
562 }
563
564 /***********************************************************************
565 * FontStyleEnumProc32 [internal]
566 */
567 static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
568 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
569 {
570 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
571 HWND hcmb2=s->hWnd1;
572 HWND hcmb3=s->hWnd2;
573 HWND hDlg=GetParent(hcmb3);
574 return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
575 dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg, FALSE);
576 }
577
578 /***********************************************************************
579 * CFn_WMInitDialog [internal]
580 */
581 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
582 LPCHOOSEFONTW lpcf)
583 {
584 HDC hdc;
585 int i,j,init=0;
586 long pstyle;
587 CFn_ENUMSTRUCT s;
588 LPLOGFONTW lpxx;
589 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
590 static const WCHAR strColorName[] = {'[','c','o','l','o','r',' ','n','a','m','e',']',0};
591
592 SetPropW(hDlg, strWineFontData, (HANDLE)lpcf);
593 lpxx=lpcf->lpLogFont;
594 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
595
596 if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
597 {
598 ERR("structure size failure !!!\n");
599 EndDialog (hDlg, 0);
600 return FALSE;
601 }
602 if (!himlTT)
603 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
604 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
605
606 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
607 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
608 if (!(lpcf->Flags & CF_APPLY))
609 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
610 if (lpcf->Flags & CF_EFFECTS)
611 {
612 for (i=0;i<TEXT_COLORS;i++)
613 {
614 WCHAR name[30];
615
616 if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
617 sizeof(name)/sizeof(*name) )==0 )
618 {
619 memcpy(name, strColorName, sizeof(strColorName));
620 }
621 j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
622 SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[i]);
623 /* look for a fitting value in color combobox */
624 if (textcolors[i]==lpcf->rgbColors)
625 SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0);
626 }
627 }
628 else
629 {
630 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
631 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
632 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
633 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
634 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
635 }
636 if(!(hdc = CFn_GetDC(lpcf)))
637 {
638 EndDialog (hDlg, 0);
639 return FALSE;
640 }
641 s.hWnd1=GetDlgItem(hDlg,cmb1);
642 s.lpcf32w=lpcf;
643 do {
644 LOGFONTW elf;
645 s.added = 0;
646 elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
647 elf.lfPitchAndFamily = 0;
648 elf.lfFaceName[0] = '\0'; /* enum all fonts */
649 if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0))
650 {
651 TRACE("EnumFontFamiliesEx returns 0\n");
652 break;
653 }
654 if (s.added) break;
655 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
656 FIXME("No font found with fixed pitch only, dropping flag.\n");
657 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
658 continue;
659 }
660 if (lpcf->Flags & CF_TTONLY) {
661 FIXME("No font found with truetype only, dropping flag.\n");
662 lpcf->Flags &= ~CF_TTONLY;
663 continue;
664 }
665 break;
666 } while (1);
667
668
669 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
670 {
671 /* look for fitting font name in combobox1 */
672 j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LPARAM)lpxx->lfFaceName);
673 if (j!=CB_ERR)
674 {
675 INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
676 lpxx->lfHeight;
677 INT points;
678 int charset = lpxx->lfCharSet;
679 points = MulDiv( height, 72, GetDeviceCaps(hdc, LOGPIXELSY));
680 pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
681 FW_NORMAL,lpxx->lfItalic !=0);
682 SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0);
683 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
684 (LPARAM)GetDlgItem(hDlg,cmb1));
685 init=1;
686 /* look for fitting font style in combobox2 */
687 CFn_FitFontStyle(hDlg, pstyle);
688 /* look for fitting font size in combobox3 */
689 CFn_FitFontSize(hDlg, points);
690 CFn_FitCharSet( hDlg, charset );
691 }
692 }
693 if (!init)
694 {
695 SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0);
696 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
697 (LPARAM)GetDlgItem(hDlg,cmb1));
698 }
699 if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle)
700 {
701 j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle);
702 if (j!=CB_ERR)
703 {
704 j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0);
705 SendMessageW(hDlg,WM_COMMAND,cmb2,
706 MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
707 }
708 }
709 CFn_ReleaseDC(lpcf, hdc);
710 SetCursor(hcursor);
711 return TRUE;
712 }
713
714
715 /***********************************************************************
716 * CFn_WMMeasureItem [internal]
717 */
718 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
719 {
720 HDC hdc;
721 HFONT hfontprev;
722 TEXTMETRICW tm;
723 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
724 INT height = 0;
725
726 if (!himlTT)
727 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
728 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
729 ImageList_GetIconSize( himlTT, 0, &height);
730 lpmi->itemHeight = height + 2;
731 /* use MAX of bitmap height and tm.tmHeight .*/
732 hdc=GetDC(hDlg);
733 if(!hdc) return 0;
734 hfontprev = SelectObject( hdc, GetStockObject( SYSTEM_FONT));
735 GetTextMetricsW(hdc, &tm);
736 if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
737 SelectObject(hdc, hfontprev);
738 ReleaseDC(hDlg, hdc);
739 return 0;
740 }
741
742
743 /***********************************************************************
744 * CFn_WMDrawItem [internal]
745 */
746 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
747 {
748 HBRUSH hBrush;
749 WCHAR buffer[40];
750 COLORREF cr, oldText=0, oldBk=0;
751 RECT rect;
752 int nFontType;
753 int idx;
754 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
755
756 if (lpdi->itemID == (UINT)-1) /* got no items */
757 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
758 else
759 {
760 if (lpdi->CtlType == ODT_COMBOBOX)
761 {
762 if (lpdi->itemState & ODS_SELECTED)
763 {
764 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
765 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
766 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
767 } else
768 {
769 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
770 SelectObject(lpdi->hDC, hBrush);
771 }
772 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
773 }
774 else
775 return TRUE; /* this should never happen */
776
777 rect=lpdi->rcItem;
778 switch (lpdi->CtlID)
779 {
780 case cmb1:
781 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
782 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
783 (LPARAM)buffer);
784 TextOutW(lpdi->hDC, lpdi->rcItem.left + TTBITMAP_XSIZE + 10,
785 lpdi->rcItem.top, buffer, lstrlenW(buffer));
786 nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
787 idx = -1;
788 if (nFontType & TRUETYPE_FONTTYPE) {
789 idx = 0; /* picture: TT */
790 if( nFontType & NTM_TT_OPENTYPE)
791 idx = 2; /* picture: O */
792 } else if( nFontType & NTM_PS_OPENTYPE)
793 idx = 3; /* picture: O+ps */
794 else if( nFontType & NTM_TYPE1)
795 idx = 4; /* picture: a */
796 else if( nFontType & DEVICE_FONTTYPE)
797 idx = 1; /* picture: printer */
798 if( idx >= 0)
799 ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
800 lpdi->rcItem.top, ILD_TRANSPARENT);
801 break;
802 case cmb2:
803 case cmb3:
804 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
805 case cmb5:
806 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
807 (LPARAM)buffer);
808 TextOutW(lpdi->hDC, lpdi->rcItem.left,
809 lpdi->rcItem.top, buffer, lstrlenW(buffer));
810 break;
811
812 case cmb4:
813 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
814 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
815 (LPARAM)buffer);
816 TextOutW(lpdi->hDC, lpdi->rcItem.left + 25+5,
817 lpdi->rcItem.top, buffer, lstrlenW(buffer));
818 cr = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
819 hBrush = CreateSolidBrush(cr);
820 if (hBrush)
821 {
822 hBrush = SelectObject (lpdi->hDC, hBrush) ;
823 rect.right=rect.left+25;
824 rect.top++;
825 rect.left+=5;
826 rect.bottom--;
827 Rectangle( lpdi->hDC, rect.left, rect.top,
828 rect.right, rect.bottom );
829 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
830 }
831 rect=lpdi->rcItem;
832 rect.left+=25+5;
833 break;
834
835 default:
836 return TRUE; /* this should never happen */
837 }
838 if (lpdi->itemState & ODS_SELECTED)
839 {
840 SetTextColor(lpdi->hDC, oldText);
841 SetBkColor(lpdi->hDC, oldBk);
842 }
843 }
844 return TRUE;
845 }
846
847 /***********************************************************************
848 * CFn_WMCommand [internal]
849 */
850 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
851 LPCHOOSEFONTW lpcf)
852 {
853 int i;
854 long l;
855 HDC hdc;
856 LPLOGFONTW lpxx=lpcf->lpLogFont;
857
858 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
859 switch (LOWORD(wParam))
860 {
861 case cmb1:
862 if (HIWORD(wParam)==CBN_SELCHANGE)
863 {
864 INT pointsize; /* save current pointsize */
865 LONG pstyle; /* save current style */
866 int charset;
867 int idx;
868 if(!(hdc = CFn_GetDC(lpcf)))
869 {
870 EndDialog (hDlg, 0);
871 return TRUE;
872 }
873 idx = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
874 pointsize = (int)SendDlgItemMessageW( hDlg, cmb3, CB_GETITEMDATA,
875 idx, 0);
876 idx = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
877 pstyle = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
878 idx = SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
879 charset = SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, idx, 0);
880
881 SendDlgItemMessageW(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
882 SendDlgItemMessageW(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
883 SendDlgItemMessageW(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
884 i=SendDlgItemMessageW(hDlg, cmb1, CB_GETCURSEL, 0, 0);
885 if (i!=CB_ERR)
886 {
887 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
888 CFn_ENUMSTRUCT s;
889 LOGFONTW enumlf;
890 SendDlgItemMessageW(hDlg, cmb1, CB_GETLBTEXT, i,
891 (LPARAM)enumlf.lfFaceName);
892 TRACE("WM_COMMAND/cmb1 =>%s\n", debugstr_w(enumlf.lfFaceName));
893 s.hWnd1=GetDlgItem(hDlg, cmb2);
894 s.hWnd2=GetDlgItem(hDlg, cmb3);
895 s.lpcf32w=lpcf;
896 enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
897 enumlf.lfPitchAndFamily = 0;
898 EnumFontFamiliesExW(hdc, &enumlf,
899 (FONTENUMPROCW)FontStyleEnumProc, (LPARAM)&s, 0);
900 CFn_FitFontStyle(hDlg, pstyle);
901 if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
902 if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
903 SetCursor(hcursor);
904 }
905 CFn_ReleaseDC(lpcf, hdc);
906 }
907 case chx1:
908 case chx2:
909 case cmb2:
910 case cmb3:
911 case cmb5:
912 if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
913 {
914 WCHAR str[256];
915 WINDOWINFO wininfo;
916
917 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
918 i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0);
919 if (i==CB_ERR)
920 i=GetDlgItemTextW( hDlg, cmb1, str, 256 );
921 else
922 {
923 SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i,
924 (LPARAM)str);
925 l=SendDlgItemMessageW(hDlg,cmb1,CB_GETITEMDATA,i,0);
926 lpcf->nFontType = LOWORD(l);
927 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
928 /* same value reported to the EnumFonts
929 call back with the extra FONTTYPE_... bits added */
930 lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
931 }
932 lstrcpyW(lpxx->lfFaceName,str);
933 i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
934 if (i!=CB_ERR)
935 {
936 l=SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
937 if (0!=(lpxx->lfItalic=HIWORD(l)))
938 lpcf->nFontType |= ITALIC_FONTTYPE;
939 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
940 lpcf->nFontType |= BOLD_FONTTYPE;
941 }
942 i=SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
943 if( i != CB_ERR)
944 lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageW(hDlg, cmb3,
945 CB_GETITEMDATA , i, 0));
946 else
947 lpcf->iPointSize = 100;
948 hdc = CFn_GetDC(lpcf);
949 if( hdc)
950 {
951 lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
952 GetDeviceCaps(hdc, LOGPIXELSY), 720);
953 CFn_ReleaseDC(lpcf, hdc);
954 } else
955 lpxx->lfHeight = -lpcf->iPointSize / 10;
956 i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
957 if (i!=CB_ERR)
958 lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
959 else
960 lpxx->lfCharSet = DEFAULT_CHARSET;
961 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
962 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
963 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
964 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
965 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
966 lpxx->lfQuality=DEFAULT_QUALITY;
967
968 wininfo.cbSize=sizeof(wininfo);
969
970 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
971 {
972 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
973 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
974 }
975 }
976 break;
977
978 case cmb4:
979 i=SendDlgItemMessageW(hDlg, cmb4, CB_GETCURSEL, 0, 0);
980 if (i!=CB_ERR)
981 {
982 WINDOWINFO wininfo;
983
984 lpcf->rgbColors = SendDlgItemMessageW(hDlg, cmb4, CB_GETITEMDATA, i, 0);
985 wininfo.cbSize=sizeof(wininfo);
986
987 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
988 {
989 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
990 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
991 }
992 }
993 break;
994
995 case psh15:
996 i=RegisterWindowMessageW( HELPMSGSTRINGW );
997 if (lpcf->hwndOwner)
998 SendMessageW(lpcf->hwndOwner, i, 0, (LPARAM)GetPropW(hDlg, strWineFontData));
999 /* if (CFn_HookCallChk(lpcf))
1000 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
1001 break;
1002
1003 case IDOK:
1004 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1005 ( (lpcf->Flags & CF_LIMITSIZE) &&
1006 (lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
1007 (lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
1008 EndDialog(hDlg, TRUE);
1009 else
1010 {
1011 WCHAR buffer[80];
1012 WCHAR format[80];
1013 LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, sizeof(format)/sizeof(WCHAR));
1014 wsprintfW(buffer, format, lpcf->nSizeMin,lpcf->nSizeMax);
1015 MessageBoxW(hDlg, buffer, NULL, MB_OK);
1016 }
1017 return(TRUE);
1018 case IDCANCEL:
1019 EndDialog(hDlg, FALSE);
1020 return(TRUE);
1021 }
1022 return(FALSE);
1023 }
1024
1025 static LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcfw)
1026 {
1027 LPCHOOSEFONTA lpcfa;
1028 LPSTR lpszStyle;
1029 LPLOGFONTA lpLogFonta;
1030 int len;
1031
1032 lpcfa = GetPropW(hwnd, strWineFontData_a);
1033 lpLogFonta = lpcfa->lpLogFont;
1034 lpszStyle = lpcfa->lpszStyle;
1035 memcpy(lpcfa, lpcfw, sizeof(CHOOSEFONTA));
1036 lpcfa->lpLogFont = lpLogFonta;
1037 lpcfa->lpszStyle = lpszStyle;
1038 memcpy(lpcfa->lpLogFont, lpcfw->lpLogFont, sizeof(LOGFONTA));
1039 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpLogFont->lfFaceName,
1040 LF_FACESIZE, lpcfa->lpLogFont->lfFaceName, LF_FACESIZE, 0, 0);
1041
1042 if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) {
1043 len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, -1, 0, 0);
1044 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, lpcfa->lpszStyle, len, 0, 0);
1045 HeapFree(GetProcessHeap(), 0, lpcfw->lpszStyle);
1046 }
1047
1048 HeapFree(GetProcessHeap(), 0, lpcfw->lpLogFont);
1049 HeapFree(GetProcessHeap(), 0, lpcfw);
1050 SetPropW(hwnd, strWineFontData, 0);
1051
1052 return TRUE;
1053 }
1054
1055 LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcf)
1056 {
1057 WINDOWINFO info;
1058
1059 info.cbSize=sizeof(info);
1060 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
1061 {
1062 PAINTSTRUCT ps;
1063 HDC hdc;
1064 HPEN hOrigPen;
1065 HFONT hOrigFont;
1066 LOGFONTW lf = *(lpcf->lpLogFont);
1067
1068 MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1069 hdc = BeginPaint( hDlg, &ps );
1070
1071 TRACE("erase %d, rect=(%ld,%ld)-(%ld,%ld)\n", ps.fErase,
1072 ps.rcPaint.left, ps.rcPaint.top,
1073 ps.rcPaint.right, ps.rcPaint.bottom);
1074
1075 /* Paint frame */
1076 MoveToEx( hdc, info.rcWindow.left, info.rcWindow.bottom, NULL );
1077 hOrigPen=SelectObject( hdc, CreatePen( PS_SOLID, 2,
1078 GetSysColor( COLOR_3DSHADOW ) ));
1079 LineTo( hdc, info.rcWindow.left, info.rcWindow.top );
1080 LineTo( hdc, info.rcWindow.right, info.rcWindow.top );
1081 DeleteObject(SelectObject( hdc, CreatePen( PS_SOLID, 2,
1082 GetSysColor( COLOR_3DLIGHT ) )));
1083 LineTo( hdc, info.rcWindow.right, info.rcWindow.bottom );
1084 LineTo( hdc, info.rcWindow.left, info.rcWindow.bottom );
1085 DeleteObject(SelectObject( hdc, hOrigPen ));
1086
1087 /* Draw the sample text itself */
1088 info.rcWindow.right--;
1089 info.rcWindow.bottom--;
1090 info.rcWindow.top++;
1091 info.rcWindow.left++;
1092 hOrigFont = SelectObject( hdc, CreateFontIndirectW( &lf ) );
1093 SetTextColor( hdc, lpcf->rgbColors );
1094
1095 DrawTextW( hdc,
1096 sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]],
1097 -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1098
1099 DeleteObject(SelectObject( hdc, hOrigFont ));
1100 EndPaint( hDlg, &ps );
1101 }
1102 return FALSE;
1103 }
1104
1105 /***********************************************************************
1106 * FormatCharDlgProcA [internal]
1107 */
1108 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1109 LPARAM lParam)
1110 {
1111 LPCHOOSEFONTW lpcfw;
1112 LPCHOOSEFONTA lpcfa;
1113 INT_PTR res = FALSE;
1114 int len;
1115
1116 if (uMsg!=WM_INITDIALOG) {
1117 lpcfw = (LPCHOOSEFONTW)GetPropW(hDlg, strWineFontData);
1118 if (!lpcfw)
1119 return FALSE;
1120 if (CFn_HookCallChk32(lpcfw))
1121 res=CallWindowProcA((WNDPROC)lpcfw->lpfnHook, hDlg, uMsg, wParam, lParam);
1122 if (res)
1123 return res;
1124 } else {
1125 lpcfa=(LPCHOOSEFONTA)lParam;
1126 SetPropW(hDlg, strWineFontData_a, (HANDLE)lParam);
1127
1128 lpcfw = HeapAlloc(GetProcessHeap(), 0, sizeof(CHOOSEFONTW));
1129 memcpy(lpcfw, lpcfa, sizeof(CHOOSEFONTA));
1130 lpcfw->lpLogFont = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGFONTW));
1131 memcpy(lpcfw->lpLogFont, lpcfa->lpLogFont, sizeof(LOGFONTA));
1132 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpLogFont->lfFaceName,
1133 LF_FACESIZE, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE);
1134
1135 if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle) {
1136 len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, NULL, 0);
1137 lpcfw->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1138 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, lpcfw->lpszStyle, len);
1139 }
1140
1141 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcfw))
1142 {
1143 TRACE("CFn_WMInitDialog returned FALSE\n");
1144 return FALSE;
1145 }
1146 if (CFn_HookCallChk32(lpcfw))
1147 return CallWindowProcA((WNDPROC)lpcfa->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1148 }
1149 switch (uMsg)
1150 {
1151 case WM_MEASUREITEM:
1152 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1153 case WM_DRAWITEM:
1154 return CFn_WMDrawItem(hDlg, wParam, lParam);
1155 case WM_COMMAND:
1156 return CFn_WMCommand(hDlg, wParam, lParam, lpcfw);
1157 case WM_DESTROY:
1158 return CFn_WMDestroy(hDlg, wParam, lParam, lpcfw);
1159 case WM_CHOOSEFONT_GETLOGFONT:
1160 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1161 FIXME("current logfont back to caller\n");
1162 break;
1163 case WM_PAINT:
1164 return CFn_WMPaint(hDlg, wParam, lParam, lpcfw);
1165 }
1166 return res;
1167 }
1168
1169 /***********************************************************************
1170 * FormatCharDlgProcW [internal]
1171 */
1172 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1173 LPARAM lParam)
1174 {
1175 LPCHOOSEFONTW lpcf;
1176 INT_PTR res = FALSE;
1177
1178 if (uMsg!=WM_INITDIALOG)
1179 {
1180 lpcf=(LPCHOOSEFONTW)GetPropW(hDlg, strWineFontData);
1181 if (!lpcf)
1182 return FALSE;
1183 if (CFn_HookCallChk32(lpcf))
1184 res=CallWindowProcW((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1185 if (res)
1186 return res;
1187 }
1188 else
1189 {
1190 lpcf=(LPCHOOSEFONTW)lParam;
1191 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
1192 {
1193 TRACE("CFn_WMInitDialog returned FALSE\n");
1194 return FALSE;
1195 }
1196 if (CFn_HookCallChk32(lpcf))
1197 return CallWindowProcW((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1198 }
1199 switch (uMsg)
1200 {
1201 case WM_MEASUREITEM:
1202 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1203 case WM_DRAWITEM:
1204 return CFn_WMDrawItem(hDlg, wParam, lParam);
1205 case WM_COMMAND:
1206 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1207 case WM_DESTROY:
1208 return TRUE;
1209 case WM_CHOOSEFONT_GETLOGFONT:
1210 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1211 FIXME("current logfont back to caller\n");
1212 break;
1213 case WM_PAINT:
1214 return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1215 }
1216 return res;
1217 }