If using the default values, also set dwType to REG_SZ as our default
[wine] / dlls / commdlg / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
34 #include "heap.h"
35 #include "commdlg.h"
36 #include "dlgs.h"
37 #include "wine/debug.h"
38 #include "cderr.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
41
42 #include "cdlg.h"
43 #include "fontdlg.h"
44
45 static HBITMAP hBitmapTT = 0;
46
47
48 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
49                                   LPARAM lParam);
50 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
51                                   LPARAM lParam);
52 BOOL16 CALLBACK FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
53                                    LPARAM lParam);
54
55 /* There is a table here of all charsets, and the sample text for each.
56  * There is a second table that translates a charset into an index into
57  * the first table.
58  */
59
60 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
61 #define SAMPLE_EXTLEN 10
62
63 static const WCHAR SAMPLE_LANG_TEXT[][SAMPLE_EXTLEN]={
64     {'Y','y','Z','z',0}, /* Western and default */
65     {0}, /* Symbol */
66     {0}, /* Shift JIS */
67     {0}, /* Hangul */
68     {0}, /* GB2312 */
69     {0}, /* BIG5 */
70     {0}, /* Greek */
71     {0}, /* Turkish */
72     {0x05e0, 0x05e1, 0x05e9, 0x05ea, 0}, /* Hebrew */
73     {0}, /* Arabic */
74     {0}, /* Baltic */
75     {0}, /* Vietnamese */
76     {0}, /* Russian */
77     {0}, /* East European */
78     {0}, /* Thai */
79     {0}, /* Johab */
80     {0}, /* Mac */
81     {0}, /* OEM */
82     {0}, /* VISCII */
83     {0}, /* TCVN */
84     {0}, /* KOI-8 */
85     {0}, /* ISO-8859-3 */
86     {0}, /* ISO-8859-4 */
87     {0}, /* ISO-8859-10 */
88     {0} /* Celtic */
89 };
90
91 static const int CHARSET_ORDER[256]={
92     CI(ANSI), 0, CI(SYMBOL), 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     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0,
97     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100     CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 0, 0, 0, 0, 0, 0, 0,
101     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102     0, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103     0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
104     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
105     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
106     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
107     CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
108 };
109
110 struct {
111     int         mask;
112     char        *name;
113 } cfflags[] = {
114 #define XX(x) { x, #x },
115     XX(CF_SCREENFONTS)
116     XX(CF_PRINTERFONTS)
117     XX(CF_SHOWHELP)
118     XX(CF_ENABLEHOOK)
119     XX(CF_ENABLETEMPLATE)
120     XX(CF_ENABLETEMPLATEHANDLE)
121     XX(CF_INITTOLOGFONTSTRUCT)
122     XX(CF_USESTYLE)
123     XX(CF_EFFECTS)
124     XX(CF_APPLY)
125     XX(CF_ANSIONLY)
126     XX(CF_NOVECTORFONTS)
127     XX(CF_NOSIMULATIONS)
128     XX(CF_LIMITSIZE)
129     XX(CF_FIXEDPITCHONLY)
130     XX(CF_WYSIWYG)
131     XX(CF_FORCEFONTEXIST)
132     XX(CF_SCALABLEONLY)
133     XX(CF_TTONLY)
134     XX(CF_NOFACESEL)
135     XX(CF_NOSTYLESEL)
136     XX(CF_NOSIZESEL)
137     XX(CF_SELECTSCRIPT)
138     XX(CF_NOSCRIPTSEL)
139     XX(CF_NOVERTFONTS)
140 #undef XX
141     {0,NULL},
142 };
143
144 void _dump_cf_flags(DWORD cflags) 
145 {
146     int i;
147
148     for (i=0;cfflags[i].name;i++)
149         if (cfflags[i].mask & cflags)
150             MESSAGE("%s|",cfflags[i].name);
151     MESSAGE("\n");
152 }
153
154 /***********************************************************************
155  *           ChooseFontA   (COMDLG32.@)
156  */
157 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
158 {
159   LPCVOID template;
160   HRSRC hResInfo;
161   HINSTANCE hDlginst;
162   HGLOBAL hDlgTmpl;
163
164   if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
165   {
166     template=(LPCVOID)lpChFont->hInstance;
167   } else
168   {
169     if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
170     {
171       hDlginst=lpChFont->hInstance;
172       if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
173         (LPSTR)RT_DIALOG)))
174       {
175         COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
176         return FALSE;
177       }
178     } else
179     {
180       hDlginst=COMDLG32_hInstance;
181       if (!(hResInfo = FindResourceA(hDlginst, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
182       {
183         COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
184         return FALSE;
185       }
186     }
187     if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
188         !(template = LockResource( hDlgTmpl )))
189     {
190       COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
191       return FALSE;
192     }
193   }
194   if (TRACE_ON(commdlg))
195         _dump_cf_flags(lpChFont->Flags);
196
197   if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
198     FIXME(": unimplemented flag (ignored)\n");
199
200   return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
201             lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
202 }
203
204 /***********************************************************************
205  *           ChooseFontW   (COMDLG32.@)
206  *
207  *  NOTES:
208  *
209  *      The LOGFONT conversion functions will break if the structure ever
210  *      grows beyond the lfFaceName element.
211  *
212  *      The CHOOSEFONT conversion functions assume that both versions of
213  *      lpLogFont and lpszStyle (if used) point to pre-allocated objects.
214  *
215  *      The ASCII version of lpTemplateName is created by ChooseFontAtoW
216  *      and freed by ChooseFontWtoA.
217  */
218 inline static VOID LogFontWtoA(const LOGFONTW *lfw, LOGFONTA *lfa)
219 {
220     memcpy(lfa, lfw, sizeof(LOGFONTA));
221     WideCharToMultiByte(CP_ACP, 0, lfw->lfFaceName, -1, lfa->lfFaceName,
222             LF_FACESIZE, NULL, NULL);
223     lfa->lfFaceName[LF_FACESIZE - 1] = '\0';
224 }
225
226 inline static VOID LogFontAtoW(const LOGFONTA *lfa, LOGFONTW *lfw)
227 {
228     memcpy(lfw, lfa, sizeof(LOGFONTA));
229     MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw->lfFaceName,
230             LF_FACESIZE);
231     lfw->lfFaceName[LF_FACESIZE - 1] = 0;
232 }
233
234 static BOOL ChooseFontWtoA(const CHOOSEFONTW *cfw, CHOOSEFONTA *cfa)
235 {
236     LOGFONTA    *lpLogFont = cfa->lpLogFont;
237     LPSTR       lpszStyle = cfa->lpszStyle;
238
239     memcpy(cfa, cfw, sizeof(CHOOSEFONTA));
240     cfa->lpLogFont = lpLogFont;
241     cfa->lpszStyle = lpszStyle;
242
243     LogFontWtoA(cfw->lpLogFont, lpLogFont);
244
245     if ((cfw->Flags&CF_ENABLETEMPLATE)!=0 && HIWORD(cfw->lpTemplateName)!=0)
246     {
247         cfa->lpTemplateName = HEAP_strdupWtoA(GetProcessHeap(), 0,
248                 cfw->lpTemplateName);
249         if (cfa->lpTemplateName == NULL)
250             return FALSE;
251     }
252
253     if ((cfw->Flags & CF_USESTYLE) != 0 && cfw->lpszStyle != NULL)
254     {
255         WideCharToMultiByte(CP_ACP, 0, cfw->lpszStyle, -1, cfa->lpszStyle,
256                 LF_FACESIZE, NULL, NULL);
257         cfa->lpszStyle[LF_FACESIZE - 1] = '\0';
258     }
259
260     return TRUE;
261 }
262
263 static VOID ChooseFontAtoW(const CHOOSEFONTA *cfa, CHOOSEFONTW *cfw)
264 {
265     LOGFONTW    *lpLogFont = cfw->lpLogFont;
266     LPWSTR      lpszStyle = cfw->lpszStyle;
267     LPCWSTR     lpTemplateName = cfw->lpTemplateName;
268
269     memcpy(cfw, cfa, sizeof(CHOOSEFONTA));
270     cfw->lpLogFont = lpLogFont;
271     cfw->lpszStyle = lpszStyle;
272     cfw->lpTemplateName = lpTemplateName;
273
274     LogFontAtoW(cfa->lpLogFont, lpLogFont);
275
276     if ((cfa->Flags&CF_ENABLETEMPLATE)!=0 && HIWORD(cfa->lpTemplateName) != 0)
277         HeapFree(GetProcessHeap(), 0, (LPSTR)(cfa->lpTemplateName));
278
279     if ((cfa->Flags & CF_USESTYLE) != 0 && cfa->lpszStyle != NULL)
280     {
281         MultiByteToWideChar(CP_ACP, 0, cfa->lpszStyle, -1, cfw->lpszStyle,
282                 LF_FACESIZE);
283         cfw->lpszStyle[LF_FACESIZE - 1] = 0;
284     }
285 }
286
287 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
288 {
289     CHOOSEFONTA     cf_a;
290     LOGFONTA        lf_a;
291     CHAR            style_a[LF_FACESIZE];
292
293     cf_a.lpLogFont = &lf_a;
294     cf_a.lpszStyle = style_a;
295
296     if (ChooseFontWtoA(lpChFont, &cf_a) == FALSE)
297     {
298         COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
299         return FALSE;
300     }
301
302     if (ChooseFontA(&cf_a) == FALSE)
303     {
304         if (cf_a.lpTemplateName != NULL)
305             HeapFree(GetProcessHeap(), 0, (LPSTR)(cf_a.lpTemplateName));
306         return FALSE;
307     }
308
309     ChooseFontAtoW(&cf_a, lpChFont);
310
311     return TRUE;
312 }
313
314 #if 0
315 /***********************************************************************
316  *           ChooseFontW   (COMDLG32.@)
317  */
318 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
319 {
320   BOOL bRet=FALSE;
321   CHOOSEFONTA cf32a;
322   LOGFONTA lf32a;
323   LPCVOID template;
324   HANDLE hResInfo, hDlgTmpl;
325
326   if (TRACE_ON(commdlg))
327         _dump_cf_flags(lpChFont->Flags);
328
329   if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
330   {
331     COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
332     return FALSE;
333   }
334   if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
335       !(template = LockResource( hDlgTmpl )))
336   {
337     COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
338     return FALSE;
339   }
340
341   if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
342     CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
343   memcpy(&cf32a, lpChFont, sizeof(cf32a));
344   memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
345
346   WideCharToMultiByte( CP_ACP, 0, lpChFont->lpLogFont->lfFaceName, -1,
347                        lf32a.lfFaceName, LF_FACESIZE, NULL, NULL );
348   lf32a.lfFaceName[LF_FACESIZE-1] = 0;
349   cf32a.lpLogFont=&lf32a;
350   cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
351   lpChFont->lpTemplateName=(LPWSTR)&cf32a;
352   bRet = DialogBoxIndirectParamW(COMDLG32_hInstance, template,
353             lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
354   HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
355   lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
356   memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
357   MultiByteToWideChar( CP_ACP, 0, lf32a.lfFaceName, -1,
358                        lpChFont->lpLogFont->lfFaceName, LF_FACESIZE );
359   lpChFont->lpLogFont->lfFaceName[LF_FACESIZE-1] = 0;
360   return bRet;
361 }
362 #endif
363
364 #define TEXT_EXTRAS 4
365 #define TEXT_COLORS 16
366
367 static const COLORREF textcolors[TEXT_COLORS]=
368 {
369  0x00000000L,0x00000080L,0x00008000L,0x00008080L,
370  0x00800000L,0x00800080L,0x00808000L,0x00808080L,
371  0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
372  0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
373 };
374
375 /***********************************************************************
376  *                          CFn_HookCallChk32                 [internal]
377  */
378 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
379 {
380  if (lpcf)
381   if(lpcf->Flags & CF_ENABLEHOOK)
382    if (lpcf->lpfnHook)
383     return TRUE;
384  return FALSE;
385 }
386
387 /*************************************************************************
388  *              AddFontFamily                               [internal]
389  */
390 INT AddFontFamily(const LOGFONTA *lplf, UINT nFontType,
391                            LPCHOOSEFONTA lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
392 {
393   int i;
394   WORD w;
395
396   TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
397
398   if (lpcf->Flags & CF_FIXEDPITCHONLY)
399    if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
400      return 1;
401   if (lpcf->Flags & CF_ANSIONLY)
402    if (lplf->lfCharSet != ANSI_CHARSET)
403      return 1;
404   if (lpcf->Flags & CF_TTONLY)
405    if (!(nFontType & TRUETYPE_FONTTYPE))
406      return 1;
407
408   if (e) e->added++;
409
410   i=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
411   if (i!=CB_ERR)
412   {
413     w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
414     SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
415     return 1 ;        /* store some important font information */
416   }
417   else
418     return 0;
419 }
420
421 /*************************************************************************
422  *              FontFamilyEnumProc32                           [internal]
423  */
424 static INT WINAPI FontFamilyEnumProc(const LOGFONTA *lpLogFont,
425           const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam)
426 {
427   LPCFn_ENUMSTRUCT e;
428   e=(LPCFn_ENUMSTRUCT)lParam;
429   return AddFontFamily(lpLogFont, dwFontType, e->lpcf32a, e->hWnd1, e);
430 }
431
432 /*************************************************************************
433  *              SetFontStylesToCombo2                           [internal]
434  *
435  * Fill font style information into combobox  (without using font.c directly)
436  */
437 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTA *lplf)
438 {
439    #define FSTYLES 4
440    struct FONTSTYLE
441           { int italic;
442             int weight;
443             char stname[20]; };
444    static struct FONTSTYLE fontstyles[FSTYLES]={
445           { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
446           { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
447    HFONT hf;
448    TEXTMETRICA tm;
449    int i,j;
450    LOGFONTA lf;
451
452    memcpy(&lf, lplf, sizeof(LOGFONTA));
453
454    for (i=0;i<FSTYLES;i++)
455    {
456      lf.lfItalic=fontstyles[i].italic;
457      lf.lfWeight=fontstyles[i].weight;
458      hf=CreateFontIndirectA(&lf);
459      hf=SelectObject(hdc,hf);
460      GetTextMetricsA(hdc,&tm);
461      hf=SelectObject(hdc,hf);
462      DeleteObject(hf);
463
464      if (tm.tmWeight==fontstyles[i].weight &&
465          tm.tmItalic==fontstyles[i].italic)    /* font successful created ? */
466      {
467        j=SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
468        if (j==CB_ERR) return 1;
469        j=SendMessageA(hwnd, CB_SETITEMDATA, j,
470                                  MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
471        if (j==CB_ERR) return 1;
472      }
473    }
474   return 0;
475 }
476
477 /*************************************************************************
478  *              AddFontSizeToCombo3                           [internal]
479  */
480 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
481 {
482     int j;
483     char buffer[20];
484
485     if (  (!(lpcf->Flags & CF_LIMITSIZE))  ||
486         ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
487     {
488         sprintf(buffer, "%2d", h);
489         j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
490         if (j==CB_ERR)
491         {
492             j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
493             if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
494             if (j==CB_ERR) return 1;
495         }
496     }
497     return 0;
498 }
499
500 /*************************************************************************
501  *              SetFontSizesToCombo3                           [internal]
502  */
503 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
504 {
505   static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
506   int i;
507
508   for (i=0; sizes[i]; i++)
509     if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
510   return 0;
511 }
512
513 /***********************************************************************
514  *                 AddFontStyle                          [internal]
515  */
516 INT AddFontStyle(const LOGFONTA *lplf, UINT nFontType,
517     LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
518 {
519   int i;
520
521   TRACE("(nFontType=%d)\n",nFontType);
522   TRACE("  %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
523                " ch=%d op=%d cp=%d q=%d pf=%xh\n",
524                lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
525                lplf->lfEscapement,lplf->lfOrientation,
526                lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
527                lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
528                lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
529   if (nFontType & RASTER_FONTTYPE)
530   {
531     if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
532   } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
533
534   if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
535   {
536        HDC hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
537        i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
538        if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
539          ReleaseDC(hDlg,hdc);
540        if (i)
541         return 0;
542   }
543   return 1 ;
544
545 }
546
547 /***********************************************************************
548  *                 FontStyleEnumProc32                     [internal]
549  */
550 static INT WINAPI FontStyleEnumProc( const LOGFONTA *lpFont,
551           const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam )
552 {
553   LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
554   HWND hcmb2=s->hWnd1;
555   HWND hcmb3=s->hWnd2;
556   HWND hDlg=GetParent(hcmb3);
557   return AddFontStyle(lpFont, dwFontType, s->lpcf32a, hcmb2,
558                       hcmb3, hDlg);
559 }
560
561 /***********************************************************************
562  *           CFn_WMInitDialog                            [internal]
563  */
564 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
565                          LPCHOOSEFONTA lpcf)
566 {
567   HDC hdc;
568   int i,j,init=0;
569   long l;
570   LPLOGFONTA lpxx;
571   HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
572
573   SetWindowLongA(hDlg, DWL_USER, lParam);
574   lpxx=lpcf->lpLogFont;
575   TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
576
577   if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
578   {
579     ERR("structure size failure !!!\n");
580     EndDialog (hDlg, 0);
581     return FALSE;
582   }
583   if (!hBitmapTT)
584     hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
585
586   if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
587     ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
588   if (!(lpcf->Flags & CF_APPLY))
589     ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
590   if (lpcf->Flags & CF_EFFECTS)
591   {
592     for (i=0;i<TEXT_COLORS;i++)
593     {
594       char name[30];
595
596       if( LoadStringA(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
597               sizeof(name)/sizeof(*name) )==0 )
598       {
599           strcpy( name, "[color name]" );
600       }
601       j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
602       SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
603       /* look for a fitting value in color combobox */
604       if (textcolors[j]==lpcf->rgbColors)
605         SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
606     }
607   }
608   else
609   {
610     ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
611     ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
612     ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
613     ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
614     ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
615   }
616   hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
617   if (hdc)
618   {
619     CFn_ENUMSTRUCT s;
620     s.hWnd1=GetDlgItem(hDlg,cmb1);
621     s.lpcf32a=lpcf;
622     do {
623         s.added = 0;
624         if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s)) {
625           TRACE("EnumFontFamilies returns 0\n");
626           break;
627         }
628         if (s.added) break;
629         if (lpcf->Flags & CF_FIXEDPITCHONLY) {
630             FIXME("No font found with fixed pitch only, dropping flag.\n");
631             lpcf->Flags &= ~CF_FIXEDPITCHONLY;
632             continue;
633         }
634         if (lpcf->Flags & CF_TTONLY) {
635             FIXME("No font found with truetype only, dropping flag.\n");
636             lpcf->Flags &= ~CF_TTONLY;
637             continue;
638         }
639         break;
640      } while (1);
641
642
643     if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
644     {
645       /* look for fitting font name in combobox1 */
646       j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
647       if (j!=CB_ERR)
648       {
649         SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
650         SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
651                      (LPARAM)GetDlgItem(hDlg,cmb1));
652         init=1;
653         /* look for fitting font style in combobox2 */
654         l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
655         for (i=0;i<TEXT_EXTRAS;i++)
656         {
657           if (l==SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0))
658             SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
659         }
660
661         /* look for fitting font size in combobox3 */
662         j=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
663         for (i=0;i<j;i++)
664         {
665           if (lpxx->lfHeight==(int)SendDlgItemMessageA(hDlg,cmb3, CB_GETITEMDATA,i,0))
666             SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
667         }
668       }
669     }
670     if (!init)
671     {
672       SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
673       SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
674                    (LPARAM)GetDlgItem(hDlg,cmb1));
675     }
676     if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
677     {
678       j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
679       if (j!=CB_ERR)
680       {
681         j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
682         SendMessageA(hDlg,WM_COMMAND,cmb2,
683                        MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
684       }
685     }
686   }
687   else
688   {
689     WARN("HDC failure !!!\n");
690     EndDialog (hDlg, 0);
691     return FALSE;
692   }
693
694   if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
695     ReleaseDC(hDlg,hdc);
696   SetCursor(hcursor);
697   return TRUE;
698 }
699
700
701 /***********************************************************************
702  *           CFn_WMMeasureItem                           [internal]
703  */
704 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
705 {
706   BITMAP bm;
707   LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
708   if (!hBitmapTT)
709     hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
710   GetObjectA( hBitmapTT, sizeof(bm), &bm );
711   lpmi->itemHeight=bm.bmHeight;
712   /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
713   return 0;
714 }
715
716
717 /***********************************************************************
718  *           CFn_WMDrawItem                              [internal]
719  */
720 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
721 {
722   HBRUSH hBrush;
723   char buffer[40];
724   BITMAP bm;
725   COLORREF cr, oldText=0, oldBk=0;
726   RECT rect;
727 #if 0
728   HDC hMemDC;
729   int nFontType;
730   HBITMAP hBitmap; /* for later TT usage */
731 #endif
732   LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
733
734   if (lpdi->itemID == (UINT)-1)  /* got no items */
735     DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
736   else
737   {
738    if (lpdi->CtlType == ODT_COMBOBOX)
739    {
740      if (lpdi->itemState ==ODS_SELECTED)
741      {
742        hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
743        oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
744        oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
745      }  else
746      {
747        hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
748        SelectObject(lpdi->hDC, hBrush);
749      }
750      FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
751    }
752    else
753      return TRUE;       /* this should never happen */
754
755    rect=lpdi->rcItem;
756    switch (lpdi->CtlID)
757    {
758     case cmb1:  /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
759                 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
760                                (LPARAM)buffer);
761                 GetObjectA( hBitmapTT, sizeof(bm), &bm );
762                 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
763                            lpdi->rcItem.top, buffer, strlen(buffer));
764 #if 0
765                 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
766                   /* FIXME: draw bitmap if truetype usage */
767                 if (nFontType&TRUETYPE_FONTTYPE)
768                 {
769                   hMemDC = CreateCompatibleDC(lpdi->hDC);
770                   hBitmap = SelectObject(hMemDC, hBitmapTT);
771                   BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
772                            bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
773                   SelectObject(hMemDC, hBitmap);
774                   DeleteDC(hMemDC);
775                 }
776 #endif
777                 break;
778     case cmb2:
779     case cmb3:  /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
780                 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
781                                (LPARAM)buffer);
782                 TextOutA(lpdi->hDC, lpdi->rcItem.left,
783                            lpdi->rcItem.top, buffer, strlen(buffer));
784                 break;
785
786     case cmb4:  /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
787                 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
788                                (LPARAM)buffer);
789                 TextOutA(lpdi->hDC, lpdi->rcItem.left +  25+5,
790                            lpdi->rcItem.top, buffer, strlen(buffer));
791                 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
792                 hBrush = CreateSolidBrush(cr);
793                 if (hBrush)
794                 {
795                   hBrush = SelectObject (lpdi->hDC, hBrush) ;
796                   rect.right=rect.left+25;
797                   rect.top++;
798                   rect.left+=5;
799                   rect.bottom--;
800                   Rectangle( lpdi->hDC, rect.left, rect.top,
801                                rect.right, rect.bottom );
802                   DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
803                 }
804                 rect=lpdi->rcItem;
805                 rect.left+=25+5;
806                 break;
807
808     default:    return TRUE;    /* this should never happen */
809    }
810    if (lpdi->itemState == ODS_SELECTED)
811    {
812      SetTextColor(lpdi->hDC, oldText);
813      SetBkColor(lpdi->hDC, oldBk);
814    }
815  }
816  return TRUE;
817 }
818
819 /***********************************************************************
820  *           CFn_WMCommand                               [internal]
821  */
822 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
823                       LPCHOOSEFONTA lpcf)
824 {
825   int i,j;
826   long l;
827   HDC hdc;
828   LPLOGFONTA lpxx=lpcf->lpLogFont;
829
830   TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
831   switch (LOWORD(wParam))
832   {
833         case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
834                   {
835                     hdc=((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
836                     if (hdc)
837                     {
838                       SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
839                       SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
840                       i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
841                       if (i!=CB_ERR)
842                       {
843                         HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
844                         CFn_ENUMSTRUCT s;
845                         char str[256];
846                         SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
847                                               (LPARAM)str);
848                         TRACE("WM_COMMAND/cmb1 =>%s\n",str);
849                         s.hWnd1=GetDlgItem(hDlg, cmb2);
850                         s.hWnd2=GetDlgItem(hDlg, cmb3);
851                         s.lpcf32a=lpcf;
852                         EnumFontFamiliesA(hdc, str, FontStyleEnumProc, (LPARAM)&s);
853                         SendDlgItemMessageA(hDlg,cmb2, CB_SETCURSEL, 0, 0);
854                         SendDlgItemMessageA(hDlg,cmb3, CB_SETCURSEL, 0, 0);
855                         SetCursor(hcursor);
856                       }
857                       if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
858                         ReleaseDC(hDlg,hdc);
859                     }
860                     else
861                     {
862                       WARN("HDC failure !!!\n");
863                       EndDialog (hDlg, 0);
864                       return TRUE;
865                     }
866                   }
867         case chx1:
868         case chx2:
869         case cmb2:
870         case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
871                   {
872                     char str[256];
873                     WINDOWINFO wininfo;
874
875                     TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
876                     i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
877                     if (i==CB_ERR)
878                       i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
879                     else
880                     {
881                       SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
882                                             (LPARAM)str);
883                       l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
884                       j=HIWORD(l);
885                       lpcf->nFontType = LOWORD(l);
886                       /* FIXME:   lpcf->nFontType |= ....  SIMULATED_FONTTYPE and so */
887                       /* same value reported to the EnumFonts
888                        call back with the extra FONTTYPE_...  bits added */
889                       lpxx->lfPitchAndFamily=j&0xff;
890                       lpxx->lfCharSet=j>>8;
891                     }
892                     strcpy(lpxx->lfFaceName,str);
893                     i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
894                     if (i!=CB_ERR)
895                     {
896                       l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
897                       if (0!=(lpxx->lfItalic=HIWORD(l)))
898                         lpcf->nFontType |= ITALIC_FONTTYPE;
899                       if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
900                         lpcf->nFontType |= BOLD_FONTTYPE;
901                     }
902                     i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
903                     if (i!=CB_ERR)
904                       lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
905                     else
906                       lpxx->lfHeight=0;
907                     lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
908                     lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
909                     lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
910                     lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
911                     lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
912                     lpxx->lfQuality=DEFAULT_QUALITY;
913                     lpcf->iPointSize= -10*lpxx->lfHeight;
914
915                     wininfo.cbSize=sizeof(wininfo);
916
917                     if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
918                     {
919                         InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
920                     }
921                   }
922                   break;
923
924         case cmb4:
925                   i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
926                   if (i!=CB_ERR)
927                   {
928                     WINDOWINFO wininfo;
929
930                    lpcf->rgbColors=textcolors[i];
931                     wininfo.cbSize=sizeof(wininfo);
932
933                     if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
934                     {
935                         InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
936                     }
937                   }
938                   break;
939
940         case psh15:i=RegisterWindowMessageA( HELPMSGSTRINGA );
941                   if (lpcf->hwndOwner)
942                     SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
943 /*                if (CFn_HookCallChk(lpcf))
944                     CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
945                   break;
946
947         case IDOK:if (  (!(lpcf->Flags & CF_LIMITSIZE))  ||
948                      ( (lpcf->Flags & CF_LIMITSIZE) &&
949                       (-lpxx->lfHeight >= lpcf->nSizeMin) &&
950                       (-lpxx->lfHeight <= lpcf->nSizeMax)))
951                      EndDialog(hDlg, TRUE);
952                   else
953                   {
954                    char buffer[80];
955                    sprintf(buffer,"Select a font size between %d and %d points.",
956                            lpcf->nSizeMin,lpcf->nSizeMax);
957                    MessageBoxA(hDlg, buffer, NULL, MB_OK);
958                   }
959                   return(TRUE);
960         case IDCANCEL:EndDialog(hDlg, FALSE);
961                   return(TRUE);
962         }
963       return(FALSE);
964 }
965
966 LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
967 {
968   return TRUE;
969 }
970
971 static LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam,
972                       LPCHOOSEFONTA lpcf )
973 {
974     WINDOWINFO info;
975
976     info.cbSize=sizeof(info);
977
978     if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
979     {
980         PAINTSTRUCT ps;
981         HDC hdc;
982         HPEN hOrigPen;
983         HFONT hOrigFont;
984         COLORREF rgbPrev;
985         WCHAR sample[SAMPLE_EXTLEN+5]={'A','a','B','b'};
986         /* Always start with this basic sample */
987
988         hdc=BeginPaint( hDlg, &ps );
989
990         /* Paint frame */
991         MoveToEx( hdc, info.rcWindow.left, info.rcWindow.bottom, NULL );
992         hOrigPen=SelectObject( hdc, CreatePen( PS_SOLID, 2,
993                     GetSysColor( COLOR_3DSHADOW ) )); 
994         LineTo( hdc, info.rcWindow.left, info.rcWindow.top );
995         LineTo( hdc, info.rcWindow.right, info.rcWindow.top );
996         DeleteObject(SelectObject( hdc, CreatePen( PS_SOLID, 2,
997                     GetSysColor( COLOR_3DLIGHT ) )));
998         LineTo( hdc, info.rcWindow.right, info.rcWindow.bottom );
999         LineTo( hdc, info.rcWindow.left, info.rcWindow.bottom );
1000         DeleteObject(SelectObject( hdc, hOrigPen ));
1001
1002         /* Draw the sample text itself */
1003         lstrcatW(sample, SAMPLE_LANG_TEXT[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]] );
1004         
1005         info.rcWindow.right--;
1006         info.rcWindow.bottom--;
1007         info.rcWindow.top++;
1008         info.rcWindow.left++;
1009         hOrigFont=SelectObject( hdc, CreateFontIndirectA( lpcf->lpLogFont ) );
1010         rgbPrev=SetTextColor( hdc, lpcf->rgbColors );
1011
1012         DrawTextW( hdc, sample, -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1013         
1014         EndPaint( hDlg, &ps );
1015     }
1016
1017     return FALSE;
1018 }
1019
1020 /***********************************************************************
1021  *           FormatCharDlgProcA   [internal]
1022  */
1023 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1024                                     LPARAM lParam)
1025 {
1026   LPCHOOSEFONTA lpcf;
1027   INT_PTR res = FALSE;
1028   if (uMsg!=WM_INITDIALOG)
1029   {
1030    lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);
1031    if (!lpcf)
1032      return FALSE;
1033    if (CFn_HookCallChk32(lpcf))
1034      res=CallWindowProcA((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1035    if (res)
1036      return res;
1037   }
1038   else
1039   {
1040     lpcf=(LPCHOOSEFONTA)lParam;
1041     if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
1042     {
1043       TRACE("CFn_WMInitDialog returned FALSE\n");
1044       return FALSE;
1045     }
1046     if (CFn_HookCallChk32(lpcf))
1047       return CallWindowProcA((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1048   }
1049   switch (uMsg)
1050     {
1051       case WM_MEASUREITEM:
1052                         return CFn_WMMeasureItem(hDlg, wParam, lParam);
1053       case WM_DRAWITEM:
1054                         return CFn_WMDrawItem(hDlg, wParam, lParam);
1055       case WM_COMMAND:
1056                         return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1057       case WM_DESTROY:
1058                         return CFn_WMDestroy(hDlg, wParam, lParam);
1059       case WM_CHOOSEFONT_GETLOGFONT:
1060                          TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1061                                       lParam);
1062                          FIXME("current logfont back to caller\n");
1063                         break;
1064       case WM_PAINT:
1065                         return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1066     }
1067   return res;
1068 }
1069
1070 /***********************************************************************
1071  *           FormatCharDlgProcW   [internal]
1072  */
1073 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1074                                     LPARAM lParam)
1075 {
1076   LPCHOOSEFONTW lpcf32w;
1077   LPCHOOSEFONTA lpcf32a;
1078   INT_PTR res = FALSE;
1079   if (uMsg!=WM_INITDIALOG)
1080   {
1081    lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);
1082    if (!lpcf32w)
1083      return FALSE;
1084    if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1085      res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
1086    if (res)
1087      return res;
1088   }
1089   else
1090   {
1091     lpcf32w=(LPCHOOSEFONTW)lParam;
1092     lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1093     if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
1094     {
1095       TRACE("CFn_WMInitDialog returned FALSE\n");
1096       return FALSE;
1097     }
1098     if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1099       return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1100   }
1101   lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1102   switch (uMsg)
1103     {
1104       case WM_MEASUREITEM:
1105                         return CFn_WMMeasureItem(hDlg, wParam, lParam);
1106       case WM_DRAWITEM:
1107                         return CFn_WMDrawItem(hDlg, wParam, lParam);
1108       case WM_COMMAND:
1109                         return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
1110       case WM_DESTROY:
1111                         return CFn_WMDestroy(hDlg, wParam, lParam);
1112       case WM_CHOOSEFONT_GETLOGFONT:
1113                          TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1114                                       lParam);
1115                          FIXME("current logfont back to caller\n");
1116                         break;
1117     }
1118   return res;
1119 }