2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
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.
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.
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
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
37 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
42 #define WINE_FONTDATA "__WINE_FONTDLGDATA"
46 /* image list with TrueType bitmaps and more */
47 static HIMAGELIST himlTT = 0;
48 #define TTBITMAP_XSIZE 20 /* x-size of the bitmaps */
51 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
53 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
56 /* There is a table here of all charsets, and the sample text for each.
57 * There is a second table that translates a charset into an index into
61 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
64 static const WCHAR stWestern[]={'A','a','B','b','Y','y','Z','z',0}; /* Western and default */
65 static const WCHAR stSymbol[]={'S','y','m','b','o','l',0}; /* Symbol */
66 static const WCHAR stShiftJis[]={'A','a',0x3042,0x3041,0x30a2,0x30a1,0x4e9c,0x5b87,0}; /* Shift JIS */
67 static const WCHAR stHangul[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Hangul */
68 static const WCHAR stGB2312[]={0x5fae,0x8f6f,0x4e2d,0x6587,0x8f6f,0x4ef6,0}; /* GB2312 */
69 static const WCHAR stBIG5[]={0x4e2d,0x6587,0x5b57,0x578b,0x7bc4,0x4f8b,0}; /* BIG5 */
70 static const WCHAR stGreek[]={'A','a','B','b',0x0391,0x03b1,0x0392,0x03b2,0}; /* Greek */
71 static const WCHAR stTurkish[]={'A','a','B','b',0x011e,0x011f,0x015e,0x015f,0}; /* Turkish */
72 static const WCHAR stHebrew[]={'A','a','B','b',0x05e0,0x05e1,0x05e9,0x05ea,0}; /* Hebrew */
73 static const WCHAR stArabic[]={'A','a','B','b',0x0627,0x0628,0x062c,0x062f,0x0647,0x0648,0x0632,0};/* Arabic */
74 static const WCHAR stBaltic[]={'A','a','B','b','Y','y','Z','z',0}; /* Baltic */
75 static const WCHAR stVietname[]={'A','a','B','b',0x01a0,0x01a1,0x01af,0x01b0,0}; /* Vietnamese */
76 static const WCHAR stCyrillic[]={'A','a','B','b',0x0411,0x0431,0x0424,0x0444,0}; /* Cyrillic */
77 static const WCHAR stEastEur[]={'A','a','B','b',0xc1,0xe1,0xd4,0xf4,0}; /* East European */
78 static const WCHAR stThai[]={'A','a','B','b',0x0e2d,0x0e31,0x0e01,0x0e29,0x0e23,0x0e44,0x0e17,0x0e22,0}; /* Thai */
79 static const WCHAR stJohab[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Johab */
80 static const WCHAR stMac[]={'A','a','B','b','Y','y','Z','z',0}; /* Mac */
81 static const WCHAR stOEM[]={'A','a','B','b',0xf8,0xf1,0xfd,0}; /* OEM */
82 /* the following character sets actually behave different (Win2K observation):
83 * the sample string is 'sticky': it uses the sample string of the previous
84 * selected character set. That behaviour looks like some default, which is
85 * not (yet) implemented. */
86 static const WCHAR stVISCII[]={'A','a','B','b',0}; /* VISCII */
87 static const WCHAR stTCVN[]={'A','a','B','b',0}; /* TCVN */
88 static const WCHAR stKOI8[]={'A','a','B','b',0}; /* KOI-8 */
89 static const WCHAR stIso88593[]={'A','a','B','b',0}; /* ISO-8859-3 */
90 static const WCHAR stIso88594[]={'A','a','B','b',0}; /* ISO-8859-4 */
91 static const WCHAR stIso885910[]={'A','a','B','b',0}; /* ISO-8859-10 */
92 static const WCHAR stCeltic[]={'A','a','B','b',0};/* Celtic */
94 static const WCHAR *sample_lang_text[]={
95 stWestern,stSymbol,stShiftJis,stHangul,stGB2312,
96 stBIG5,stGreek,stTurkish,stHebrew,stArabic,
97 stBaltic,stVietname,stCyrillic,stEastEur,stThai,
98 stJohab,stMac,stOEM,stVISCII,stTCVN,
99 stKOI8,stIso88593,stIso88594,stIso885910,stCeltic};
102 static const int CHARSET_ORDER[256]={
103 CI(ANSI), 0, CI(SYMBOL), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0,
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 0, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
118 CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
125 #define XX(x) { x, #x },
130 XX(CF_ENABLETEMPLATE)
131 XX(CF_ENABLETEMPLATEHANDLE)
132 XX(CF_INITTOLOGFONTSTRUCT)
140 XX(CF_FIXEDPITCHONLY)
142 XX(CF_FORCEFONTEXIST)
155 void _dump_cf_flags(DWORD cflags)
159 for (i=0;cfflags[i].name;i++)
160 if (cfflags[i].mask & cflags)
161 MESSAGE("%s|",cfflags[i].name);
165 /***********************************************************************
166 * ChooseFontW (COMDLG32.@)
168 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
175 static const WCHAR chooseFontW[] = {'C','H','O','O','S','E','_',
178 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
180 template=(LPCVOID)lpChFont->hInstance;
183 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
185 hDlginst=lpChFont->hInstance;
186 if( !(hResInfo = FindResourceW(hDlginst, lpChFont->lpTemplateName,
189 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
194 hDlginst=COMDLG32_hInstance;
195 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
197 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
201 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
202 !(template = LockResource( hDlgTmpl )))
204 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
208 if (TRACE_ON(commdlg))
209 _dump_cf_flags(lpChFont->Flags);
211 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
212 FIXME(": unimplemented flag (ignored)\n");
214 return DialogBoxIndirectParamW(COMDLG32_hInstance, template,
215 lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
218 /***********************************************************************
219 * ChooseFontA (COMDLG32.@)
221 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
228 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
230 template=(LPCVOID)lpChFont->hInstance;
233 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
235 hDlginst=lpChFont->hInstance;
236 if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
239 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
244 hDlginst=COMDLG32_hInstance;
245 if (!(hResInfo = FindResourceA(hDlginst, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
247 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
251 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
252 !(template = LockResource( hDlgTmpl )))
254 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
258 if (TRACE_ON(commdlg))
259 _dump_cf_flags(lpChFont->Flags);
261 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
262 FIXME(": unimplemented flag (ignored)\n");
264 return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
265 lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
269 #define TEXT_EXTRAS 4
270 #define TEXT_COLORS 16
272 static const COLORREF textcolors[TEXT_COLORS]=
274 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
275 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
276 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
277 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
280 /***********************************************************************
281 * CFn_HookCallChk32 [internal]
283 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
286 if(lpcf->Flags & CF_ENABLEHOOK)
292 /*************************************************************************
293 * AddFontFamily [internal]
295 INT AddFontFamily(const ENUMLOGFONTEXA *lpElfex, const NEWTEXTMETRICEXA *lpNTM,
296 UINT nFontType, LPCHOOSEFONTA lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
300 const LOGFONTA *lplf = &(lpElfex->elfLogFont);
302 TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
304 if (lpcf->Flags & CF_FIXEDPITCHONLY)
305 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
307 if (lpcf->Flags & CF_ANSIONLY)
308 if (lplf->lfCharSet != ANSI_CHARSET)
310 if (lpcf->Flags & CF_TTONLY)
311 if (!(nFontType & TRUETYPE_FONTTYPE))
316 i=SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
318 i = SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
320 /* store some important font information */
321 w = (lplf->lfPitchAndFamily) << 8 |
322 (HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
323 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
329 /*************************************************************************
330 * FontFamilyEnumProc32 [internal]
332 static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXA *lpElfex,
333 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam)
336 e=(LPCFn_ENUMSTRUCT)lParam;
337 return AddFontFamily( lpElfex, (NEWTEXTMETRICEXA *) metrics,
338 dwFontType, e->lpcf32a, e->hWnd1, e);
341 /*************************************************************************
342 * SetFontStylesToCombo2 [internal]
344 * Fill font style information into combobox (without using font.c directly)
346 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTA *lplf)
355 static struct FONTSTYLE fontstyles[FSTYLES]={
356 { 0,FW_NORMAL,"Regular"}, { 1,FW_NORMAL,"Italic"},
357 { 0,FW_BOLD,"Bold"}, { 1,FW_BOLD,"Bold Italic"}
364 memcpy(&lf, lplf, sizeof(LOGFONTA));
366 for (i=0;i<FSTYLES;i++)
368 lf.lfItalic=fontstyles[i].italic;
369 lf.lfWeight=fontstyles[i].weight;
370 hf=CreateFontIndirectA(&lf);
371 hf=SelectObject(hdc,hf);
372 GetTextMetricsA(hdc,&tm);
373 hf=SelectObject(hdc,hf);
375 /* font successful created ? */
376 if (tm.tmWeight==fontstyles[i].weight &&
377 ((tm.tmItalic != 0)==fontstyles[i].italic))
379 j=SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
380 if (j==CB_ERR) return 1;
381 j=SendMessageA(hwnd, CB_SETITEMDATA, j,
382 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
383 if (j==CB_ERR) return 1;
389 /*************************************************************************
390 * AddFontSizeToCombo3 [internal]
392 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
397 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
398 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
400 sprintf(buffer, "%2d", h);
401 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
404 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
405 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
406 if (j==CB_ERR) return 1;
412 /*************************************************************************
413 * SetFontSizesToCombo3 [internal]
415 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
417 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
420 for (i=0; sizes[i]; i++)
421 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
425 /*************************************************************************
426 * CFn_GetDC [internal]
428 inline HDC CFn_GetDC(LPCHOOSEFONTA lpcf)
430 HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
433 if(!ret) ERR("HDC failure!!!\n");
437 /*************************************************************************
438 * CFn_ReleaseDC [internal]
440 inline void CFn_ReleaseDC(LPCHOOSEFONTA lpcf, HDC hdc)
442 if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
446 /***********************************************************************
447 * AddFontStyle [internal]
449 INT AddFontStyle( const ENUMLOGFONTEXA *lpElfex, const NEWTEXTMETRICEXA *lpNTM,
450 UINT nFontType, LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3,
451 HWND hDlg, BOOL iswin16)
454 const LOGFONTA *lplf = &(lpElfex->elfLogFont);
458 TRACE("(nFontType=%d)\n",nFontType);
459 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
460 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
461 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
462 lplf->lfEscapement,lplf->lfOrientation,
463 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
464 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
465 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
466 if (nFontType & RASTER_FONTTYPE)
469 if(!(hdc = CFn_GetDC(lpcf))) return 0;
470 points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
471 72, GetDeviceCaps(hdc, LOGPIXELSY));
472 CFn_ReleaseDC(lpcf, hdc);
473 i = AddFontSizeToCombo3(hcmb3, points, lpcf);
475 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
477 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
479 if(!(hdc = CFn_GetDC(lpcf))) return 0;
480 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
481 CFn_ReleaseDC(lpcf, hdc);
485 if( iswin16 || !( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
486 i = SendMessageA( hcmb5, CB_FINDSTRINGEXACT, 0,
487 (LPARAM)lpElfex->elfScript);
489 i = SendMessageA( hcmb5, CB_ADDSTRING, 0,
490 (LPARAM)lpElfex->elfScript);
492 SendMessageA( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
497 static INT CFn_FitFontSize( HWND hDlg, int points)
501 /* look for fitting font size in combobox3 */
502 n=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
505 if (points == (int)SendDlgItemMessageA
506 (hDlg,cmb3, CB_GETITEMDATA,i,0))
508 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
509 SendMessageA(hDlg, WM_COMMAND,
510 MAKEWPARAM(cmb3, CBN_SELCHANGE),
511 (LPARAM)GetDlgItem(hDlg,cmb3));
519 static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
523 /* look for fitting font style in combobox2 */
524 for (i=0;i<TEXT_EXTRAS;i++)
526 id =SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
527 if (packedstyle == id)
529 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
530 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
531 (LPARAM)GetDlgItem(hDlg,cmb2));
540 static INT CFn_FitCharSet( HWND hDlg, int charset )
543 /* look for fitting char set in combobox5 */
544 n=SendDlgItemMessageA(hDlg, cmb5, CB_GETCOUNT, 0, 0);
547 cs =SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, i, 0);
550 SendDlgItemMessageA(hDlg, cmb5, CB_SETCURSEL, i, 0);
551 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
552 (LPARAM)GetDlgItem(hDlg,cmb2));
556 /* no charset fits: select the first one in the list */
557 SendDlgItemMessageA(hDlg, cmb5, CB_SETCURSEL, 0, 0);
558 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
559 (LPARAM)GetDlgItem(hDlg,cmb2));
563 /***********************************************************************
564 * FontStyleEnumProc32 [internal]
566 static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXA *lpElfex,
567 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam )
569 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
572 HWND hDlg=GetParent(hcmb3);
573 return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXA *) metrics,
574 dwFontType, s->lpcf32a, hcmb2, hcmb3, hDlg, FALSE);
577 /***********************************************************************
578 * CFn_WMInitDialog [internal]
580 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
588 HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
590 SetPropA(hDlg, WINE_FONTDATA, (HANDLE)lParam);
591 lpxx=lpcf->lpLogFont;
592 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
594 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
596 ERR("structure size failure !!!\n");
601 himlTT = ImageList_LoadImageA( COMDLG32_hInstance, MAKEINTRESOURCEA(38),
602 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
604 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
605 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
606 if (!(lpcf->Flags & CF_APPLY))
607 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
608 if (lpcf->Flags & CF_EFFECTS)
610 for (i=0;i<TEXT_COLORS;i++)
614 if( LoadStringA(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
615 sizeof(name)/sizeof(*name) )==0 )
617 strcpy( name, "[color name]" );
619 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
620 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
621 /* look for a fitting value in color combobox */
622 if (textcolors[j]==lpcf->rgbColors)
623 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
628 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
629 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
630 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
631 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
632 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
634 if(!(hdc = CFn_GetDC(lpcf)))
639 s.hWnd1=GetDlgItem(hDlg,cmb1);
644 elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
645 elf.lfPitchAndFamily = 0;
646 elf.lfFaceName[0] = '\0'; /* enum all fonts */
647 if (!EnumFontFamiliesExA(hdc, &elf, (FONTENUMPROCA)FontFamilyEnumProc, (LPARAM)&s, 0))
649 TRACE("EnumFontFamiliesEx returns 0\n");
653 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
654 FIXME("No font found with fixed pitch only, dropping flag.\n");
655 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
658 if (lpcf->Flags & CF_TTONLY) {
659 FIXME("No font found with truetype only, dropping flag.\n");
660 lpcf->Flags &= ~CF_TTONLY;
667 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
669 /* look for fitting font name in combobox1 */
670 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
673 INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
676 int charset = lpxx->lfCharSet;
677 points = MulDiv( height, 72, GetDeviceCaps(hdc, LOGPIXELSY));
678 pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
679 FW_NORMAL,lpxx->lfItalic !=0);
680 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
681 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
682 (LPARAM)GetDlgItem(hDlg,cmb1));
684 /* look for fitting font style in combobox2 */
685 CFn_FitFontStyle(hDlg, pstyle);
686 /* look for fitting font size in combobox3 */
687 CFn_FitFontSize(hDlg, points);
688 CFn_FitCharSet( hDlg, charset );
693 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
694 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
695 (LPARAM)GetDlgItem(hDlg,cmb1));
697 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
699 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
702 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
703 SendMessageA(hDlg,WM_COMMAND,cmb2,
704 MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
707 CFn_ReleaseDC(lpcf, hdc);
713 /***********************************************************************
714 * CFn_WMMeasureItem [internal]
716 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
721 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
723 himlTT = ImageList_LoadImageA( COMDLG32_hInstance, MAKEINTRESOURCEA(38),
724 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
725 ImageList_GetIconSize( himlTT, 0, &lpmi->itemHeight);
726 lpmi->itemHeight += 2;
727 /* use MAX of bitmap height and tm.tmHeight .*/
730 hfontprev = SelectObject( hdc, GetStockObject( SYSTEM_FONT));
731 GetTextMetricsW( hdc, &tm);
732 if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
733 SelectObject( hdc, hfontprev);
734 ReleaseDC( hDlg, hdc);
739 /***********************************************************************
740 * CFn_WMDrawItem [internal]
742 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
746 COLORREF cr, oldText=0, oldBk=0;
750 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
752 if (lpdi->itemID == (UINT)-1) /* got no items */
753 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
756 if (lpdi->CtlType == ODT_COMBOBOX)
758 if (lpdi->itemState & ODS_SELECTED)
760 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
761 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
762 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
765 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
766 SelectObject(lpdi->hDC, hBrush);
768 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
771 return TRUE; /* this should never happen */
777 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
778 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
780 TextOutA(lpdi->hDC, lpdi->rcItem.left + TTBITMAP_XSIZE + 10,
781 lpdi->rcItem.top, buffer, strlen(buffer));
782 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
784 if (nFontType & TRUETYPE_FONTTYPE) {
785 idx = 0; /* picture: TT */
786 if( nFontType & NTM_TT_OPENTYPE)
787 idx = 2; /* picture: O */
788 } else if( nFontType & NTM_PS_OPENTYPE)
789 idx = 3; /* picture: O+ps */
790 else if( nFontType & NTM_TYPE1)
791 idx = 4; /* picture: a */
792 else if( nFontType & DEVICE_FONTTYPE)
793 idx = 1; /* picture: printer */
795 ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
796 lpdi->rcItem.top, ILD_TRANSPARENT);
800 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
802 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
804 TextOutA(lpdi->hDC, lpdi->rcItem.left,
805 lpdi->rcItem.top, buffer, strlen(buffer));
809 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
810 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
812 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
813 lpdi->rcItem.top, buffer, strlen(buffer));
814 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
815 hBrush = CreateSolidBrush(cr);
818 hBrush = SelectObject (lpdi->hDC, hBrush) ;
819 rect.right=rect.left+25;
823 Rectangle( lpdi->hDC, rect.left, rect.top,
824 rect.right, rect.bottom );
825 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
832 return TRUE; /* this should never happen */
834 if (lpdi->itemState & ODS_SELECTED)
836 SetTextColor(lpdi->hDC, oldText);
837 SetBkColor(lpdi->hDC, oldBk);
843 /***********************************************************************
844 * CFn_WMCommand [internal]
846 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
852 LPLOGFONTA lpxx=lpcf->lpLogFont;
854 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
855 switch (LOWORD(wParam))
858 if (HIWORD(wParam)==CBN_SELCHANGE)
860 INT pointsize; /* save current pointsize */
861 LONG pstyle; /* save current style */
864 if(!(hdc = CFn_GetDC(lpcf)))
869 idx = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
870 pointsize = (int)SendDlgItemMessageA( hDlg, cmb3, CB_GETITEMDATA,
872 idx = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
873 pstyle = SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
874 idx = SendDlgItemMessageA(hDlg, cmb5, CB_GETCURSEL, 0, 0);
875 charset = SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, idx, 0);
877 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
878 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
879 SendDlgItemMessageA(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
880 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL, 0, 0);
883 HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
886 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
887 (LPARAM)enumlf.lfFaceName);
888 TRACE("WM_COMMAND/cmb1 =>%s\n",enumlf.lfFaceName);
889 s.hWnd1=GetDlgItem(hDlg, cmb2);
890 s.hWnd2=GetDlgItem(hDlg, cmb3);
892 enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
893 enumlf.lfPitchAndFamily = 0;
894 EnumFontFamiliesExA(hdc, &enumlf,
895 (FONTENUMPROCA)FontStyleEnumProc, (LPARAM)&s, 0);
896 CFn_FitFontStyle(hDlg, pstyle);
897 if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
898 if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
901 CFn_ReleaseDC(lpcf, hdc);
908 if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
913 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
914 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
916 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
919 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
921 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
922 lpcf->nFontType = LOWORD(l);
923 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
924 /* same value reported to the EnumFonts
925 call back with the extra FONTTYPE_... bits added */
926 lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
928 strcpy(lpxx->lfFaceName,str);
929 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
932 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
933 if (0!=(lpxx->lfItalic=HIWORD(l)))
934 lpcf->nFontType |= ITALIC_FONTTYPE;
935 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
936 lpcf->nFontType |= BOLD_FONTTYPE;
938 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
940 lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageA(hDlg, cmb3,
941 CB_GETITEMDATA , i, 0));
943 lpcf->iPointSize = 100;
944 hdc = CFn_GetDC(lpcf);
947 lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
948 GetDeviceCaps(hdc, LOGPIXELSY), 720);
949 CFn_ReleaseDC(lpcf, hdc);
951 lpxx->lfHeight = -lpcf->iPointSize / 10;
952 i=SendDlgItemMessageA(hDlg, cmb5, CB_GETCURSEL, 0, 0);
954 lpxx->lfCharSet=SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, i, 0);
956 lpxx->lfCharSet = DEFAULT_CHARSET;
957 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
958 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
959 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
960 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
961 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
962 lpxx->lfQuality=DEFAULT_QUALITY;
964 wininfo.cbSize=sizeof(wininfo);
966 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
968 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
969 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
975 i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
980 lpcf->rgbColors=textcolors[i];
981 wininfo.cbSize=sizeof(wininfo);
983 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
985 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
986 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
992 i=RegisterWindowMessageA( HELPMSGSTRINGA );
994 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetPropA(hDlg, WINE_FONTDATA));
995 /* if (CFn_HookCallChk(lpcf))
996 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
1000 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1001 ( (lpcf->Flags & CF_LIMITSIZE) &&
1002 (lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
1003 (lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
1004 EndDialog(hDlg, TRUE);
1008 sprintf(buffer,"Select a font size between %d and %d points.",
1009 lpcf->nSizeMin,lpcf->nSizeMax);
1010 MessageBoxA(hDlg, buffer, NULL, MB_OK);
1014 EndDialog(hDlg, FALSE);
1020 LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1025 LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam,
1026 LPCHOOSEFONTA lpcf )
1030 info.cbSize=sizeof(info);
1032 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
1039 LOGFONTA lf = *(lpcf->lpLogFont);
1041 MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1042 hdc=BeginPaint( hDlg, &ps );
1045 MoveToEx( hdc, info.rcWindow.left, info.rcWindow.bottom, NULL );
1046 hOrigPen=SelectObject( hdc, CreatePen( PS_SOLID, 2,
1047 GetSysColor( COLOR_3DSHADOW ) ));
1048 LineTo( hdc, info.rcWindow.left, info.rcWindow.top );
1049 LineTo( hdc, info.rcWindow.right, info.rcWindow.top );
1050 DeleteObject(SelectObject( hdc, CreatePen( PS_SOLID, 2,
1051 GetSysColor( COLOR_3DLIGHT ) )));
1052 LineTo( hdc, info.rcWindow.right, info.rcWindow.bottom );
1053 LineTo( hdc, info.rcWindow.left, info.rcWindow.bottom );
1054 DeleteObject(SelectObject( hdc, hOrigPen ));
1056 /* Draw the sample text itself */
1057 info.rcWindow.right--;
1058 info.rcWindow.bottom--;
1059 info.rcWindow.top++;
1060 info.rcWindow.left++;
1061 hOrigFont = SelectObject( hdc, CreateFontIndirectA( &lf ) );
1062 rgbPrev=SetTextColor( hdc, lpcf->rgbColors );
1065 sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]],
1066 -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1068 DeleteObject(SelectObject( hdc, hOrigFont ));
1069 EndPaint( hDlg, &ps );
1075 /***********************************************************************
1076 * FormatCharDlgProcA [internal]
1078 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1082 INT_PTR res = FALSE;
1083 if (uMsg!=WM_INITDIALOG)
1085 lpcf=(LPCHOOSEFONTA)GetPropA(hDlg, WINE_FONTDATA);
1086 if (!lpcf && uMsg != WM_MEASUREITEM)
1088 if (CFn_HookCallChk32(lpcf))
1089 res=CallWindowProcA((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1095 lpcf=(LPCHOOSEFONTA)lParam;
1096 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
1098 TRACE("CFn_WMInitDialog returned FALSE\n");
1101 if (CFn_HookCallChk32(lpcf))
1102 return CallWindowProcA((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1106 case WM_MEASUREITEM:
1107 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1109 return CFn_WMDrawItem(hDlg, wParam, lParam);
1111 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1113 return CFn_WMDestroy(hDlg, wParam, lParam);
1114 case WM_CHOOSEFONT_GETLOGFONT:
1115 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1117 FIXME("current logfont back to caller\n");
1120 return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1125 /***********************************************************************
1126 * FormatCharDlgProcW [internal]
1128 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1131 LPCHOOSEFONTW lpcf32w;
1132 INT_PTR res = FALSE;
1133 if (uMsg!=WM_INITDIALOG)
1135 lpcf32w=(LPCHOOSEFONTW)GetPropA(hDlg, WINE_FONTDATA);
1138 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1139 res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
1145 lpcf32w=(LPCHOOSEFONTW)lParam;
1146 if (!CFn_WMInitDialog(hDlg, wParam, lParam, (LPCHOOSEFONTA)lpcf32w))
1148 TRACE("CFn_WMInitDialog returned FALSE\n");
1151 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1152 return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1156 case WM_MEASUREITEM:
1157 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1159 return CFn_WMDrawItem(hDlg, wParam, lParam);
1161 return CFn_WMCommand(hDlg, wParam, lParam, (LPCHOOSEFONTW)lpcf32w);
1163 return CFn_WMDestroy(hDlg, wParam, lParam);
1164 case WM_CHOOSEFONT_GETLOGFONT:
1165 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1167 FIXME("current logfont back to caller\n");