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