Make ChooseFontW use ChooseFontA.
[wine] / dlls / commdlg / fontdlg.c
1 /*
2  * COMMDLG - Font Dialog
3  *
4  * Copyright 1994 Martin Ayotte
5  * Copyright 1996 Albrecht Kleine
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include "windef.h"
13 #include "winnls.h"
14 #include "winbase.h"
15 #include "wingdi.h"
16 #include "wine/winbase16.h"
17 #include "wine/winuser16.h"
18 #include "heap.h"
19 #include "commdlg.h"
20 #include "dlgs.h"
21 #include "debugtools.h"
22 #include "cderr.h"
23
24 DEFAULT_DEBUG_CHANNEL(commdlg);
25
26 #include "cdlg.h"
27
28 static HBITMAP16 hBitmapTT = 0; 
29
30
31 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
32                                   LPARAM lParam);
33 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
34                                   LPARAM lParam);
35 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
36                                    LPARAM lParam);
37
38 static void FONT_LogFont16To32A( const LPLOGFONT16 font16, LPLOGFONTA font32 )
39 {
40     font32->lfHeight = font16->lfHeight;
41     font32->lfWidth = font16->lfWidth;
42     font32->lfEscapement = font16->lfEscapement;
43     font32->lfOrientation = font16->lfOrientation;
44     font32->lfWeight = font16->lfWeight;
45     font32->lfItalic = font16->lfItalic;
46     font32->lfUnderline = font16->lfUnderline;
47     font32->lfStrikeOut = font16->lfStrikeOut;
48     font32->lfCharSet = font16->lfCharSet;
49     font32->lfOutPrecision = font16->lfOutPrecision;
50     font32->lfClipPrecision = font16->lfClipPrecision;
51     font32->lfQuality = font16->lfQuality;
52     font32->lfPitchAndFamily = font16->lfPitchAndFamily;
53     lstrcpynA( font32->lfFaceName, font16->lfFaceName, LF_FACESIZE );
54 }
55
56 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONTA chf32a)
57 {
58   chf32a->lStructSize=sizeof(CHOOSEFONTA);
59   chf32a->hwndOwner=chf16->hwndOwner;
60   chf32a->hDC=chf16->hDC;
61   chf32a->iPointSize=chf16->iPointSize;
62   chf32a->Flags=chf16->Flags;
63   chf32a->rgbColors=chf16->rgbColors;
64   chf32a->lCustData=chf16->lCustData;
65   chf32a->lpfnHook=NULL;
66   chf32a->lpTemplateName=MapSL(chf16->lpTemplateName);
67   chf32a->hInstance=chf16->hInstance;
68   chf32a->lpszStyle=MapSL(chf16->lpszStyle);
69   chf32a->nFontType=chf16->nFontType;
70   chf32a->nSizeMax=chf16->nSizeMax;
71   chf32a->nSizeMin=chf16->nSizeMin;
72   FONT_LogFont16To32A(MapSL(chf16->lpLogFont), chf32a->lpLogFont);
73 }
74
75 struct {
76     int         mask;
77     char        *name;
78 } cfflags[] = {
79 #define XX(x) { x, #x },
80     XX(CF_SCREENFONTS)
81     XX(CF_PRINTERFONTS)
82     XX(CF_SHOWHELP)
83     XX(CF_ENABLEHOOK)
84     XX(CF_ENABLETEMPLATE)
85     XX(CF_ENABLETEMPLATEHANDLE)
86     XX(CF_INITTOLOGFONTSTRUCT)
87     XX(CF_USESTYLE)
88     XX(CF_EFFECTS)
89     XX(CF_APPLY)
90     XX(CF_ANSIONLY)
91     XX(CF_NOVECTORFONTS)
92     XX(CF_NOSIMULATIONS)
93     XX(CF_LIMITSIZE)
94     XX(CF_FIXEDPITCHONLY)
95     XX(CF_WYSIWYG)
96     XX(CF_FORCEFONTEXIST)
97     XX(CF_SCALABLEONLY)
98     XX(CF_TTONLY)
99     XX(CF_NOFACESEL)
100     XX(CF_NOSTYLESEL)
101     XX(CF_NOSIZESEL)
102     XX(CF_SELECTSCRIPT)
103     XX(CF_NOSCRIPTSEL)
104     XX(CF_NOVERTFONTS)
105 #undef XX
106     {0,NULL},
107 };
108
109 static void
110 _dump_cf_flags(DWORD cflags) {
111     int i;
112
113     for (i=0;cfflags[i].name;i++)
114         if (cfflags[i].mask & cflags)
115             MESSAGE("%s|",cfflags[i].name);
116     MESSAGE("\n");
117 }
118
119
120 /***********************************************************************
121  *                        ChooseFont16   (COMMDLG.15)     
122  */
123 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
124 {
125     HINSTANCE16 hInst;
126     HANDLE16 hDlgTmpl16 = 0, hResource16 = 0;
127     HGLOBAL16 hGlobal16 = 0;
128     BOOL16 bRet = FALSE;
129     LPCVOID template;
130     FARPROC16 ptr;
131     CHOOSEFONTA cf32a;
132     LOGFONTA lf32a;
133     LOGFONT16 *font16;
134     SEGPTR lpTemplateName;
135     
136     cf32a.lpLogFont=&lf32a;
137     CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
138
139     TRACE("ChooseFont\n");
140     if (!lpChFont) return FALSE;    
141
142     if (TRACE_ON(commdlg))
143         _dump_cf_flags(lpChFont->Flags);
144
145     if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
146     {
147         if (!(template = LockResource16( lpChFont->hInstance )))
148         {
149             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
150             return FALSE;
151         }
152     }
153     else if (lpChFont->Flags & CF_ENABLETEMPLATE)
154     {
155         HANDLE16 hResInfo;
156         if (!(hResInfo = FindResource16( lpChFont->hInstance,
157                                          MapSL(lpChFont->lpTemplateName),
158                                          RT_DIALOGA)))
159         {
160             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
161             return FALSE;
162         }
163         if (!(hDlgTmpl16 = LoadResource16( lpChFont->hInstance, hResInfo )) ||
164             !(template = LockResource16( hDlgTmpl16 )))
165         {
166             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
167             return FALSE;
168         }
169     }
170     else
171     {
172         HANDLE hResInfo, hDlgTmpl32;
173         LPCVOID template32;
174         DWORD size;
175         if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
176         {
177             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
178             return FALSE;
179         }
180         if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo)) ||
181             !(template32 = LockResource(hDlgTmpl32)))
182         {
183             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
184             return FALSE;
185         }
186         size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo);
187         hGlobal16 = GlobalAlloc16(0, size);
188         if (!hGlobal16)
189         {
190             COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
191             ERR("alloc failure for %ld bytes\n", size);
192             return FALSE;
193         }
194         template = GlobalLock16(hGlobal16);
195         if (!template)
196         {
197             COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
198             ERR("global lock failure for %x handle\n", hGlobal16);
199             GlobalFree16(hGlobal16);
200             return FALSE;
201         }
202         ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
203         hDlgTmpl16 = hGlobal16;         
204
205     }
206
207     /* lpTemplateName is not used in the dialog */
208     lpTemplateName=lpChFont->lpTemplateName;
209     lpChFont->lpTemplateName=(SEGPTR)&cf32a;
210
211     ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 16);
212     hInst = GetWindowLongA(lpChFont->hwndOwner, GWL_HINSTANCE);
213     bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChFont->hwndOwner,
214                      (DLGPROC16) ptr, (DWORD)lpChFont);
215     if (hResource16) FreeResource16(hDlgTmpl16);
216     if (hGlobal16)
217     {
218         GlobalUnlock16(hGlobal16);
219         GlobalFree16(hGlobal16);
220     }
221     lpChFont->lpTemplateName=lpTemplateName;
222
223
224     font16 = MapSL(lpChFont->lpLogFont);
225     font16->lfHeight = cf32a.lpLogFont->lfHeight;
226     font16->lfWidth = cf32a.lpLogFont->lfWidth;
227     font16->lfEscapement = cf32a.lpLogFont->lfEscapement;
228     font16->lfOrientation = cf32a.lpLogFont->lfOrientation;
229     font16->lfWeight = cf32a.lpLogFont->lfWeight;
230     font16->lfItalic = cf32a.lpLogFont->lfItalic;
231     font16->lfUnderline = cf32a.lpLogFont->lfUnderline;
232     font16->lfStrikeOut = cf32a.lpLogFont->lfStrikeOut;
233     font16->lfCharSet = cf32a.lpLogFont->lfCharSet;
234     font16->lfOutPrecision = cf32a.lpLogFont->lfOutPrecision;
235     font16->lfClipPrecision = cf32a.lpLogFont->lfClipPrecision;
236     font16->lfQuality = cf32a.lpLogFont->lfQuality;
237     font16->lfPitchAndFamily = cf32a.lpLogFont->lfPitchAndFamily;
238     lstrcpynA( font16->lfFaceName, cf32a.lpLogFont->lfFaceName, LF_FACESIZE );
239     return bRet;
240 }
241
242
243 /***********************************************************************
244  *           ChooseFontA   (COMDLG32.3)
245  */
246 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
247 {
248   LPCVOID template;
249   HANDLE hResInfo, hDlgTmpl;
250
251   if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
252   {
253     COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
254     return FALSE;
255   }
256   if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
257       !(template = LockResource( hDlgTmpl )))
258   {
259     COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
260     return FALSE;
261   }
262   if (TRACE_ON(commdlg))
263         _dump_cf_flags(lpChFont->Flags);
264
265   if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
266     CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
267   return DialogBoxIndirectParamA(COMMDLG_hInstance32, template, 
268             lpChFont->hwndOwner, (DLGPROC)FormatCharDlgProcA, (LPARAM)lpChFont );
269 }
270
271 /***********************************************************************
272  *           ChooseFontW   (COMDLG32.4)
273  *
274  *  NOTES:
275  *
276  *      The LOGFONT conversion functions will break if the structure ever
277  *      grows beyond the lfFaceName element.
278  *
279  *      The CHOOSEFONT conversion functions assume that both versions of
280  *      lpLogFont and lpszStyle (if used) point to pre-allocated objects.
281  *
282  *      The ASCII version of lpTemplateName is created by ChooseFontAtoW
283  *      and freed by ChooseFontWtoA.
284  */
285 inline static VOID LogFontWtoA(const LOGFONTW *lfw, LOGFONTA *lfa)
286 {
287     memcpy(lfa, lfw, sizeof(LOGFONTA));
288     WideCharToMultiByte(CP_ACP, 0, lfw->lfFaceName, -1, lfa->lfFaceName,
289             LF_FACESIZE, NULL, NULL);
290     lfa->lfFaceName[LF_FACESIZE - 1] = '\0';
291 }
292
293 inline static VOID LogFontAtoW(const LOGFONTA *lfa, LOGFONTW *lfw)
294 {
295     memcpy(lfw, lfa, sizeof(LOGFONTA));
296     MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw->lfFaceName,
297             LF_FACESIZE);
298     lfw->lfFaceName[LF_FACESIZE - 1] = 0;
299 }
300
301 static BOOL ChooseFontWtoA(const CHOOSEFONTW *cfw, CHOOSEFONTA *cfa)
302 {
303     LOGFONTA    *lpLogFont = cfa->lpLogFont;
304     LPSTR       lpszStyle = cfa->lpszStyle;
305
306     memcpy(cfa, cfw, sizeof(CHOOSEFONTA));
307     cfa->lpLogFont = lpLogFont;
308     cfa->lpszStyle = lpszStyle;
309     
310     LogFontWtoA(cfw->lpLogFont, lpLogFont);
311     
312     if (cfw->lpTemplateName != NULL)
313     {
314         cfa->lpTemplateName = HEAP_strdupWtoA(GetProcessHeap(), 0,
315                 cfw->lpTemplateName);
316         if (cfa->lpTemplateName == NULL)
317             return FALSE;
318     }
319         
320     if ((cfw->Flags & CF_USESTYLE) != 0 && cfw->lpszStyle != NULL)
321     {
322         WideCharToMultiByte(CP_ACP, 0, cfw->lpszStyle, -1, cfa->lpszStyle,
323                 LF_FACESIZE, NULL, NULL);
324         cfa->lpszStyle[LF_FACESIZE - 1] = '\0';
325     }
326     
327     return TRUE;
328 }
329
330 static VOID ChooseFontAtoW(const CHOOSEFONTA *cfa, CHOOSEFONTW *cfw)
331 {
332     LOGFONTW    *lpLogFont = cfw->lpLogFont;
333     LPWSTR      lpszStyle = cfw->lpszStyle;
334     LPCWSTR     lpTemplateName = cfw->lpTemplateName;
335
336     memcpy(cfw, cfa, sizeof(CHOOSEFONTA));
337     cfw->lpLogFont = lpLogFont;
338     cfw->lpszStyle = lpszStyle;
339     cfw->lpTemplateName = lpTemplateName;
340     
341     LogFontAtoW(cfa->lpLogFont, lpLogFont);
342     
343     if (cfa->lpTemplateName != NULL)
344         HeapFree(GetProcessHeap(), 0, (LPSTR)(cfa->lpTemplateName));
345     
346     if ((cfa->Flags & CF_USESTYLE) != 0 && cfa->lpszStyle != NULL)
347     {
348         MultiByteToWideChar(CP_ACP, 0, cfa->lpszStyle, -1, cfw->lpszStyle,
349                 LF_FACESIZE);
350         cfw->lpszStyle[LF_FACESIZE - 1] = 0;
351     }
352 }
353
354 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
355 {
356     CHOOSEFONTA     cf_a;
357     LOGFONTA        lf_a;
358     CHAR            style_a[LF_FACESIZE];
359     
360     cf_a.lpLogFont = &lf_a;
361     cf_a.lpszStyle = style_a;
362     
363     if (ChooseFontWtoA(lpChFont, &cf_a) == FALSE)
364     {
365         COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
366         return FALSE;
367     }
368     
369     if (ChooseFontA(&cf_a) == FALSE)
370     {
371         if (cf_a.lpTemplateName != NULL)
372             HeapFree(GetProcessHeap(), 0, (LPSTR)(cf_a.lpTemplateName));
373         return FALSE;
374     }
375     
376     ChooseFontAtoW(&cf_a, lpChFont);
377     
378     return TRUE;
379 }
380
381 #if 0
382 /***********************************************************************
383  *           ChooseFontW   (COMDLG32.4)
384  */
385 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
386 {
387   BOOL bRet=FALSE;
388   CHOOSEFONTA cf32a;
389   LOGFONTA lf32a;
390   LPCVOID template;
391   HANDLE hResInfo, hDlgTmpl;
392
393   if (TRACE_ON(commdlg))
394         _dump_cf_flags(lpChFont->Flags);
395
396   if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
397   {
398     COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
399     return FALSE;
400   }
401   if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
402       !(template = LockResource( hDlgTmpl )))
403   {
404     COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
405     return FALSE;
406   }
407
408   if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
409     CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
410   memcpy(&cf32a, lpChFont, sizeof(cf32a));
411   memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
412
413   WideCharToMultiByte( CP_ACP, 0, lpChFont->lpLogFont->lfFaceName, -1,
414                        lf32a.lfFaceName, LF_FACESIZE, NULL, NULL );
415   lf32a.lfFaceName[LF_FACESIZE-1] = 0;
416   cf32a.lpLogFont=&lf32a;
417   cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
418   lpChFont->lpTemplateName=(LPWSTR)&cf32a;
419   bRet = DialogBoxIndirectParamW(COMMDLG_hInstance32, template, 
420             lpChFont->hwndOwner, (DLGPROC)FormatCharDlgProcW, (LPARAM)lpChFont );
421   HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
422   lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
423   memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
424   MultiByteToWideChar( CP_ACP, 0, lf32a.lfFaceName, -1,
425                        lpChFont->lpLogFont->lfFaceName, LF_FACESIZE );
426   lpChFont->lpLogFont->lfFaceName[LF_FACESIZE-1] = 0;
427   return bRet;
428 }
429 #endif
430
431 #define TEXT_EXTRAS 4
432 #define TEXT_COLORS 16
433
434 static const COLORREF textcolors[TEXT_COLORS]=
435 {
436  0x00000000L,0x00000080L,0x00008000L,0x00008080L,
437  0x00800000L,0x00800080L,0x00808000L,0x00808080L,
438  0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
439  0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
440 };
441
442 /***********************************************************************
443  *                          CFn_HookCallChk                 [internal]
444  */
445 static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
446 {
447  if (lpcf)
448   if(lpcf->Flags & CF_ENABLEHOOK)
449    if (lpcf->lpfnHook)
450     return TRUE;
451  return FALSE;
452 }
453
454 /***********************************************************************
455  *                          CFn_HookCallChk32                 [internal]
456  */
457 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
458 {
459  if (lpcf)
460   if(lpcf->Flags & CF_ENABLEHOOK)
461    if (lpcf->lpfnHook)
462     return TRUE;
463  return FALSE;
464 }
465
466 typedef struct
467 {
468   HWND hWnd1;
469   HWND hWnd2;
470   LPCHOOSEFONTA lpcf32a;
471   int  added;
472 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
473
474 /*************************************************************************
475  *              AddFontFamily                               [internal]
476  */
477 static INT AddFontFamily(const LOGFONTA *lplf, UINT nFontType, 
478                            LPCHOOSEFONTA lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
479 {
480   int i;
481   WORD w;
482
483   TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
484
485   if (lpcf->Flags & CF_FIXEDPITCHONLY)
486    if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
487      return 1;
488   if (lpcf->Flags & CF_ANSIONLY)
489    if (lplf->lfCharSet != ANSI_CHARSET)
490      return 1;
491   if (lpcf->Flags & CF_TTONLY)
492    if (!(nFontType & TRUETYPE_FONTTYPE))
493      return 1;   
494
495   if (e) e->added++;
496
497   i=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
498   if (i!=CB_ERR)
499   {
500     w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
501     SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
502     return 1 ;        /* store some important font information */
503   }
504   else
505     return 0;
506 }
507
508 /*************************************************************************
509  *              FontFamilyEnumProc32                           [internal]
510  */
511 static INT WINAPI FontFamilyEnumProc(const LOGFONTA *lpLogFont, 
512           const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam)
513 {
514   LPCFn_ENUMSTRUCT e;
515   e=(LPCFn_ENUMSTRUCT)lParam;
516   return AddFontFamily(lpLogFont, dwFontType, e->lpcf32a, e->hWnd1, e);
517 }
518
519 /***********************************************************************
520  *                FontFamilyEnumProc16                     (COMMDLG.19)
521  */
522 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
523                                    UINT16 nFontType, LPARAM lParam )
524 {
525   HWND16 hwnd=LOWORD(lParam);
526   HWND hDlg=GetParent(hwnd);
527   LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER); 
528   LOGFONT16 *lplf = MapSL( logfont );
529   LOGFONTA lf32a;
530   FONT_LogFont16To32A(lplf, &lf32a);
531   return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
532                        hwnd,NULL);
533 }
534
535 /*************************************************************************
536  *              SetFontStylesToCombo2                           [internal]
537  *
538  * Fill font style information into combobox  (without using font.c directly)
539  */
540 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTA *lplf)
541 {
542    #define FSTYLES 4
543    struct FONTSTYLE
544           { int italic; 
545             int weight;
546             char stname[20]; };
547    static struct FONTSTYLE fontstyles[FSTYLES]={ 
548           { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
549           { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
550    HFONT hf;
551    TEXTMETRICA tm;
552    int i,j;
553    LOGFONTA lf;
554
555    memcpy(&lf, lplf, sizeof(LOGFONTA));
556
557    for (i=0;i<FSTYLES;i++)
558    {
559      lf.lfItalic=fontstyles[i].italic;
560      lf.lfWeight=fontstyles[i].weight;
561      hf=CreateFontIndirectA(&lf);
562      hf=SelectObject(hdc,hf);
563      GetTextMetricsA(hdc,&tm);
564      hf=SelectObject(hdc,hf);
565      DeleteObject(hf);
566
567      if (tm.tmWeight==fontstyles[i].weight &&
568          tm.tmItalic==fontstyles[i].italic)    /* font successful created ? */
569      {
570        j=SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
571        if (j==CB_ERR) return 1;
572        j=SendMessageA(hwnd, CB_SETITEMDATA, j,
573                                  MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
574        if (j==CB_ERR) return 1;                                 
575      }
576    }  
577   return 0;
578 }
579
580 /*************************************************************************
581  *              AddFontSizeToCombo3                           [internal]
582  */
583 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
584 {
585     int j;
586     char buffer[20];
587
588     if (  (!(lpcf->Flags & CF_LIMITSIZE))  ||
589         ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
590     {
591         sprintf(buffer, "%2d", h);
592         j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
593         if (j==CB_ERR)
594         {
595             j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);      
596             if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h); 
597             if (j==CB_ERR) return 1;
598         }
599     }
600     return 0;
601
602  
603 /*************************************************************************
604  *              SetFontSizesToCombo3                           [internal]
605  */
606 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
607 {
608   static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
609   int i;
610
611   for (i=0; sizes[i]; i++)
612     if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
613   return 0;
614 }
615
616 /***********************************************************************
617  *                 AddFontStyle                          [internal]
618  */
619 static INT AddFontStyle(const LOGFONTA *lplf, UINT nFontType, 
620     LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
621 {
622   int i;
623   
624   TRACE("(nFontType=%d)\n",nFontType);
625   TRACE("  %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
626                " ch=%d op=%d cp=%d q=%d pf=%xh\n",
627                lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
628                lplf->lfEscapement,lplf->lfOrientation,
629                lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
630                lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
631                lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
632   if (nFontType & RASTER_FONTTYPE)
633   {
634     if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
635   } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
636
637   if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
638   {
639        HDC hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
640        i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
641        if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
642          ReleaseDC(hDlg,hdc);
643        if (i)
644         return 0;
645   }
646   return 1 ;
647
648 }    
649
650 /***********************************************************************
651  *                 FontStyleEnumProc16                     (COMMDLG.18)
652  */
653 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
654                                   UINT16 nFontType, LPARAM lParam )
655 {
656   HWND16 hcmb2=LOWORD(lParam);
657   HWND16 hcmb3=HIWORD(lParam);
658   HWND hDlg=GetParent(hcmb3);
659   LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER); 
660   LOGFONT16 *lplf = MapSL(logfont);
661   LOGFONTA lf32a;
662   FONT_LogFont16To32A(lplf, &lf32a);
663   return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
664                       hcmb2, hcmb3, hDlg);
665 }
666
667 /***********************************************************************
668  *                 FontStyleEnumProc32                     [internal]
669  */
670 static INT WINAPI FontStyleEnumProc( const LOGFONTA *lpFont, 
671           const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam )
672 {
673   LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
674   HWND hcmb2=s->hWnd1;
675   HWND hcmb3=s->hWnd2;
676   HWND hDlg=GetParent(hcmb3);
677   return AddFontStyle(lpFont, dwFontType, s->lpcf32a, hcmb2,
678                       hcmb3, hDlg);
679 }
680
681 /***********************************************************************
682  *           CFn_WMInitDialog                            [internal]
683  */
684 static LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
685                          LPCHOOSEFONTA lpcf)
686 {
687   HDC hdc;
688   int i,j,res,init=0;
689   long l;
690   LPLOGFONTA lpxx;
691   HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
692
693   SetWindowLongA(hDlg, DWL_USER, lParam); 
694   lpxx=lpcf->lpLogFont;
695   TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
696
697   if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
698   {
699     ERR("structure size failure !!!\n");
700     EndDialog (hDlg, 0); 
701     return FALSE;
702   }
703   if (!hBitmapTT)
704     hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
705
706   /* This font will be deleted by WM_COMMAND */
707   SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,
708      CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
709                          
710   if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
711     ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
712   if (!(lpcf->Flags & CF_APPLY))
713     ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
714   if (lpcf->Flags & CF_EFFECTS)
715   {
716     for (res=1,i=0;res && i<TEXT_COLORS;i++)
717     {
718       /* FIXME: load color name from resource:  res=LoadString(...,i+....,buffer,.....); */
719       char name[20];
720       strcpy( name, "[color name]" );
721       j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
722       SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
723       /* look for a fitting value in color combobox */
724       if (textcolors[j]==lpcf->rgbColors)
725         SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
726     }
727   }
728   else
729   {
730     ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
731     ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
732     ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
733     ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
734     ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
735   }
736   hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
737   if (hdc)
738   {
739     CFn_ENUMSTRUCT s;
740     s.hWnd1=GetDlgItem(hDlg,cmb1);
741     s.lpcf32a=lpcf;
742     do {
743         s.added = 0;
744         if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s)) {
745           TRACE("EnumFontFamilies returns 0\n");
746           break;
747         }
748         if (s.added) break;
749         if (lpcf->Flags & CF_FIXEDPITCHONLY) {
750             FIXME("No founds found with fixed pitch only, dropping flag.\n");
751             lpcf->Flags &= ~CF_FIXEDPITCHONLY;
752             continue;
753         }
754         if (lpcf->Flags & CF_TTONLY) {
755             FIXME("No founds found with truetype only, dropping flag.\n");
756             lpcf->Flags &= ~CF_TTONLY;
757             continue;
758         }
759         break;
760      } while (1);
761
762
763     if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
764     {
765       /* look for fitting font name in combobox1 */
766       j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
767       if (j!=CB_ERR)
768       {
769         SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
770         SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
771                        GetDlgItem(hDlg,cmb1));
772         init=1;
773         /* look for fitting font style in combobox2 */
774         l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
775         for (i=0;i<TEXT_EXTRAS;i++)
776         {
777           if (l==SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0))
778             SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
779         }
780       
781         /* look for fitting font size in combobox3 */
782         j=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
783         for (i=0;i<j;i++)
784         {
785           if (lpxx->lfHeight==(int)SendDlgItemMessageA(hDlg,cmb3, CB_GETITEMDATA,i,0))
786             SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
787         }
788       }
789     }
790     if (!init)
791     {
792       SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
793       SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
794                        GetDlgItem(hDlg,cmb1));
795     }    
796     if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
797     {
798       j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
799       if (j!=CB_ERR)
800       {
801         j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
802         SendMessageA(hDlg,WM_COMMAND,cmb2,
803                        MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
804       }
805     }
806   }
807   else
808   {
809     WARN("HDC failure !!!\n");
810     EndDialog (hDlg, 0); 
811     return FALSE;
812   }
813
814   if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
815     ReleaseDC(hDlg,hdc);
816   SetCursor(hcursor);   
817   return TRUE;
818 }
819
820
821 /***********************************************************************
822  *           CFn_WMMeasureItem                           [internal]
823  */
824 static LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
825 {
826   BITMAP bm;
827   LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
828   if (!hBitmapTT)
829     hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
830   GetObjectA( hBitmapTT, sizeof(bm), &bm );
831   lpmi->itemHeight=bm.bmHeight;
832   /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
833   return 0;
834 }
835
836
837 /***********************************************************************
838  *           CFn_WMDrawItem                              [internal]
839  */
840 static LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
841 {
842   HBRUSH hBrush;
843   char buffer[40];
844   BITMAP bm;
845   COLORREF cr, oldText=0, oldBk=0;
846   RECT rect;
847 #if 0  
848   HDC hMemDC;
849   int nFontType;
850   HBITMAP hBitmap; /* for later TT usage */
851 #endif  
852   LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
853
854   if (lpdi->itemID == 0xFFFF)                   /* got no items */
855     DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
856   else
857   {
858    if (lpdi->CtlType == ODT_COMBOBOX)
859    {
860      if (lpdi->itemState ==ODS_SELECTED)
861      {
862        hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
863        oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
864        oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
865      }  else
866      {
867        hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
868        SelectObject(lpdi->hDC, hBrush);
869      }
870      FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
871    }
872    else
873      return TRUE;       /* this should never happen */
874
875    rect=lpdi->rcItem;
876    switch (lpdi->CtlID)
877    {
878     case cmb1:  /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
879                 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
880                                (LPARAM)buffer);           
881                 GetObjectA( hBitmapTT, sizeof(bm), &bm );
882                 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
883                            lpdi->rcItem.top, buffer, strlen(buffer));
884 #if 0
885                 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
886                   /* FIXME: draw bitmap if truetype usage */
887                 if (nFontType&TRUETYPE_FONTTYPE)
888                 {
889                   hMemDC = CreateCompatibleDC(lpdi->hDC);
890                   hBitmap = SelectObject(hMemDC, hBitmapTT);
891                   BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
892                            bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
893                   SelectObject(hMemDC, hBitmap);
894                   DeleteDC(hMemDC);
895                 }
896 #endif
897                 break;
898     case cmb2:
899     case cmb3:  /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
900                 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
901                                (LPARAM)buffer);
902                 TextOutA(lpdi->hDC, lpdi->rcItem.left,
903                            lpdi->rcItem.top, buffer, strlen(buffer));
904                 break;
905
906     case cmb4:  /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
907                 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
908                                (LPARAM)buffer);
909                 TextOutA(lpdi->hDC, lpdi->rcItem.left +  25+5,
910                            lpdi->rcItem.top, buffer, strlen(buffer));
911                 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
912                 hBrush = CreateSolidBrush(cr);
913                 if (hBrush)
914                 {
915                   hBrush = SelectObject (lpdi->hDC, hBrush) ;
916                   rect.right=rect.left+25;
917                   rect.top++;
918                   rect.left+=5;
919                   rect.bottom--;
920                   Rectangle( lpdi->hDC, rect.left, rect.top,
921                                rect.right, rect.bottom );
922                   DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
923                 }
924                 rect=lpdi->rcItem;
925                 rect.left+=25+5;
926                 break;
927
928     default:    return TRUE;    /* this should never happen */
929    }
930    if (lpdi->itemState == ODS_SELECTED)
931    {
932      SetTextColor(lpdi->hDC, oldText);
933      SetBkColor(lpdi->hDC, oldBk);
934    }
935  }
936  return TRUE;
937 }
938
939 /***********************************************************************
940  *           CFn_WMCtlColor                              [internal]
941  */
942 static LRESULT CFn_WMCtlColorStatic(HWND hDlg, WPARAM wParam, LPARAM lParam,
943                              LPCHOOSEFONTA lpcf)
944 {
945   if (lpcf->Flags & CF_EFFECTS)
946    if (GetDlgCtrlID(lParam)==stc6)
947    {
948      SetTextColor((HDC)wParam, lpcf->rgbColors);
949      return GetStockObject(WHITE_BRUSH);
950    }
951   return 0;
952 }
953
954 /***********************************************************************
955  *           CFn_WMCommand                               [internal]
956  */
957 static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
958                       LPCHOOSEFONTA lpcf)
959 {
960   HFONT hFont;
961   int i,j;
962   long l;
963   HDC hdc;
964   LPLOGFONTA lpxx=lpcf->lpLogFont;
965   
966   TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
967   switch (LOWORD(wParam))
968   {
969         case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
970                   {
971                     hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
972                     if (hdc)
973                     {
974                       SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT16, 0, 0); 
975                       SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
976                       i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
977                       if (i!=CB_ERR)
978                       {
979                         HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
980                         CFn_ENUMSTRUCT s;
981                         char str[256];
982                         SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
983                                               (LPARAM)str);
984                         TRACE("WM_COMMAND/cmb1 =>%s\n",str);
985                         s.hWnd1=GetDlgItem(hDlg, cmb2);
986                         s.hWnd2=GetDlgItem(hDlg, cmb3);
987                         s.lpcf32a=lpcf;
988                         EnumFontFamiliesA(hdc, str, FontStyleEnumProc, (LPARAM)&s);
989                         SendDlgItemMessageA(hDlg,cmb2, CB_SETCURSEL, 0, 0);
990                         SendDlgItemMessageA(hDlg,cmb3, CB_SETCURSEL, 0, 0);
991                         SetCursor(hcursor);
992                       }
993                       if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
994                         ReleaseDC(hDlg,hdc);
995                     }
996                     else
997                     {
998                       WARN("HDC failure !!!\n");
999                       EndDialog (hDlg, 0); 
1000                       return TRUE;
1001                     }
1002                   }
1003         case chx1:
1004         case chx2:
1005         case cmb2:
1006         case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
1007                   {
1008                     char str[256];
1009                     TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
1010                     i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
1011                     if (i==CB_ERR)
1012                       i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
1013                     else
1014                     {
1015                       SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
1016                                             (LPARAM)str);
1017                       l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
1018                       j=HIWORD(l);
1019                       lpcf->nFontType = LOWORD(l);
1020                       /* FIXME:   lpcf->nFontType |= ....  SIMULATED_FONTTYPE and so */
1021                       /* same value reported to the EnumFonts
1022                        call back with the extra FONTTYPE_...  bits added */
1023                       lpxx->lfPitchAndFamily=j&0xff;
1024                       lpxx->lfCharSet=j>>8;
1025                     }
1026                     strcpy(lpxx->lfFaceName,str);
1027                     i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1028                     if (i!=CB_ERR)
1029                     {
1030                       l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
1031                       if (0!=(lpxx->lfItalic=HIWORD(l)))
1032                         lpcf->nFontType |= ITALIC_FONTTYPE;
1033                       if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
1034                         lpcf->nFontType |= BOLD_FONTTYPE;
1035                     }
1036                     i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1037                     if (i!=CB_ERR)
1038                       lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
1039                     else
1040                       lpxx->lfHeight=0;
1041                     lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
1042                     lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
1043                     lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
1044                     lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
1045                     lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
1046                     lpxx->lfQuality=DEFAULT_QUALITY;
1047                     lpcf->iPointSize= -10*lpxx->lfHeight;
1048
1049                     hFont=CreateFontIndirectA(lpxx);
1050                     if (hFont)
1051                     {
1052                       HFONT oldFont=SendDlgItemMessageA(hDlg, stc6, 
1053                           WM_GETFONT, 0, 0);
1054                       SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,hFont,TRUE);
1055                       DeleteObject(oldFont);
1056                     }
1057                   }
1058                   break;
1059
1060         case cmb4:i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
1061                   if (i!=CB_ERR)
1062                   {
1063                    lpcf->rgbColors=textcolors[i];
1064                    InvalidateRect( GetDlgItem(hDlg,stc6), NULL, 0 );
1065                   }
1066                   break;
1067         
1068         case psh15:i=RegisterWindowMessageA( HELPMSGSTRINGA );
1069                   if (lpcf->hwndOwner)
1070                     SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
1071 /*                if (CFn_HookCallChk(lpcf))
1072                     CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
1073                   break;
1074
1075         case IDOK:if (  (!(lpcf->Flags & CF_LIMITSIZE))  ||
1076                      ( (lpcf->Flags & CF_LIMITSIZE) && 
1077                       (-lpxx->lfHeight >= lpcf->nSizeMin) && 
1078                       (-lpxx->lfHeight <= lpcf->nSizeMax)))
1079                      EndDialog(hDlg, TRUE);
1080                   else
1081                   {
1082                    char buffer[80];
1083                    sprintf(buffer,"Select a font size between %d and %d points.",
1084                            lpcf->nSizeMin,lpcf->nSizeMax);
1085                    MessageBoxA(hDlg, buffer, NULL, MB_OK);
1086                   } 
1087                   return(TRUE);
1088         case IDCANCEL:EndDialog(hDlg, FALSE);
1089                   return(TRUE);
1090         }
1091       return(FALSE);
1092 }
1093
1094 static LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1095 {
1096   DeleteObject(SendDlgItemMessageA(hwnd, stc6, WM_GETFONT, 0, 0));
1097   return TRUE;
1098 }
1099
1100
1101 /***********************************************************************
1102  *           FormatCharDlgProc16   (COMMDLG.16)
1103              FIXME: 1. some strings are "hardcoded", but it's better load from sysres
1104                     2. some CF_.. flags are not supported
1105                     3. some TType extensions
1106  */
1107 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
1108                                    LPARAM lParam)
1109 {
1110   LPCHOOSEFONT16 lpcf;
1111   LPCHOOSEFONTA lpcf32a;
1112   LRESULT res=0;  
1113   if (message!=WM_INITDIALOG)
1114   {
1115    lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);   
1116    if (!lpcf)
1117       return FALSE;
1118    if (CFn_HookCallChk(lpcf))
1119      res=CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg,message,wParam,lParam);
1120    if (res)
1121     return res;
1122   }
1123   else
1124   {
1125     lpcf=(LPCHOOSEFONT16)lParam;
1126     lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
1127     if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a)) 
1128     {
1129       TRACE("CFn_WMInitDialog returned FALSE\n");
1130       return FALSE;
1131     }  
1132     if (CFn_HookCallChk(lpcf))
1133       return CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1134   }
1135   lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
1136   switch (message)
1137     {
1138     case WM_MEASUREITEM:
1139         {
1140             MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
1141             MEASUREITEMSTRUCT mis;
1142             mis.CtlType    = mis16->CtlType;
1143             mis.CtlID      = mis16->CtlID;
1144             mis.itemID     = mis16->itemID;
1145             mis.itemWidth  = mis16->itemWidth;
1146             mis.itemHeight = mis16->itemHeight;
1147             mis.itemData   = mis16->itemData;
1148             res = CFn_WMMeasureItem(hDlg, wParam, (LPARAM)&mis);
1149             mis16->itemWidth  = (UINT16)mis.itemWidth;
1150             mis16->itemHeight = (UINT16)mis.itemHeight;
1151         }
1152         break;
1153     case WM_DRAWITEM:
1154         {
1155             DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
1156             DRAWITEMSTRUCT dis;
1157             dis.CtlType    = dis16->CtlType;
1158             dis.CtlID      = dis16->CtlID;
1159             dis.itemID     = dis16->itemID;
1160             dis.itemAction = dis16->itemAction;
1161             dis.itemState  = dis16->itemState;
1162             dis.hwndItem   = dis16->hwndItem;
1163             dis.hDC        = dis16->hDC;
1164             dis.itemData   = dis16->itemData;
1165             CONV_RECT16TO32( &dis16->rcItem, &dis.rcItem );
1166             res = CFn_WMDrawItem(hDlg, wParam, (LPARAM)&dis);
1167         }
1168         break;
1169     case WM_CTLCOLOR:
1170         if (HIWORD(lParam) == CTLCOLOR_STATIC)
1171             res=CFn_WMCtlColorStatic(hDlg, (HDC)wParam, (HWND)LOWORD(lParam), lpcf32a);
1172         break;
1173     case WM_COMMAND:
1174         res=CFn_WMCommand(hDlg, MAKEWPARAM( wParam, HIWORD(lParam) ), LOWORD(lParam), lpcf32a);
1175         break;
1176     case WM_DESTROY:
1177         res=CFn_WMDestroy(hDlg, wParam, lParam);
1178         break;
1179     case WM_CHOOSEFONT_GETLOGFONT:
1180         TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1181         FIXME("current logfont back to caller\n");
1182         break;
1183     }
1184   return res;
1185 }
1186
1187 /***********************************************************************
1188  *           FormatCharDlgProcA   [internal]
1189  */
1190 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1191                                     LPARAM lParam)
1192 {
1193   LPCHOOSEFONTA lpcf;
1194   LRESULT res=FALSE;
1195   if (uMsg!=WM_INITDIALOG)
1196   {
1197    lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);   
1198    if (!lpcf)
1199      return FALSE;
1200    if (CFn_HookCallChk32(lpcf))
1201      res=CallWindowProcA((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1202    if (res)
1203      return res;
1204   }
1205   else
1206   {
1207     lpcf=(LPCHOOSEFONTA)lParam;
1208     if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf)) 
1209     {
1210       TRACE("CFn_WMInitDialog returned FALSE\n");
1211       return FALSE;
1212     }  
1213     if (CFn_HookCallChk32(lpcf))
1214       return CallWindowProcA((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1215   }
1216   switch (uMsg)
1217     {
1218       case WM_MEASUREITEM:
1219                         return CFn_WMMeasureItem(hDlg, wParam, lParam);
1220       case WM_DRAWITEM:
1221                         return CFn_WMDrawItem(hDlg, wParam, lParam);
1222       case WM_CTLCOLORSTATIC:
1223                         return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
1224       case WM_COMMAND:
1225                         return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1226       case WM_DESTROY:
1227                         return CFn_WMDestroy(hDlg, wParam, lParam);
1228       case WM_CHOOSEFONT_GETLOGFONT:
1229                          TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1230                                       lParam);
1231                          FIXME("current logfont back to caller\n");
1232                         break;
1233     }
1234   return res;
1235 }
1236
1237 /***********************************************************************
1238  *           FormatCharDlgProcW   [internal]
1239  */
1240 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1241                                     LPARAM lParam)
1242 {
1243   LPCHOOSEFONTW lpcf32w;
1244   LPCHOOSEFONTA lpcf32a;
1245   LRESULT res=FALSE;
1246   if (uMsg!=WM_INITDIALOG)
1247   {
1248    lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);   
1249    if (!lpcf32w)
1250      return FALSE;
1251    if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1252      res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
1253    if (res)
1254      return res;
1255   }
1256   else
1257   {
1258     lpcf32w=(LPCHOOSEFONTW)lParam;
1259     lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1260     if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a)) 
1261     {
1262       TRACE("CFn_WMInitDialog returned FALSE\n");
1263       return FALSE;
1264     }  
1265     if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1266       return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1267   }
1268   lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1269   switch (uMsg)
1270     {
1271       case WM_MEASUREITEM:
1272                         return CFn_WMMeasureItem(hDlg, wParam, lParam);
1273       case WM_DRAWITEM:
1274                         return CFn_WMDrawItem(hDlg, wParam, lParam);
1275       case WM_CTLCOLORSTATIC:
1276                         return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
1277       case WM_COMMAND:
1278                         return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
1279       case WM_DESTROY:
1280                         return CFn_WMDestroy(hDlg, wParam, lParam);
1281       case WM_CHOOSEFONT_GETLOGFONT: 
1282                          TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1283                                       lParam);
1284                          FIXME("current logfont back to caller\n");
1285                         break;
1286     }
1287   return res;
1288 }
1289
1290