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