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
34 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
39 #define WINE_FONTDATA "__WINE_FONTDLGDATA"
43 /* image list with TrueType bitmaps and more */
44 static HIMAGELIST himlTT = 0;
45 #define TTBITMAP_XSIZE 20 /* x-size of the bitmaps */
48 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
50 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
53 /* There is a table here of all charsets, and the sample text for each.
54 * There is a second table that translates a charset into an index into
58 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
61 static const WCHAR stWestern[]={'A','a','B','b','Y','y','Z','z',0}; /* Western and default */
62 static const WCHAR stSymbol[]={'S','y','m','b','o','l',0}; /* Symbol */
63 static const WCHAR stShiftJis[]={'A','a',0x3042,0x3041,0x30a2,0x30a1,0x4e9c,0x5b87,0}; /* Shift JIS */
64 static const WCHAR stHangul[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Hangul */
65 static const WCHAR stGB2312[]={0x5fae,0x8f6f,0x4e2d,0x6587,0x8f6f,0x4ef6,0}; /* GB2312 */
66 static const WCHAR stBIG5[]={0x4e2d,0x6587,0x5b57,0x578b,0x7bc4,0x4f8b,0}; /* BIG5 */
67 static const WCHAR stGreek[]={'A','a','B','b',0x0391,0x03b1,0x0392,0x03b2,0}; /* Greek */
68 static const WCHAR stTurkish[]={'A','a','B','b',0x011e,0x011f,0x015e,0x015f,0}; /* Turkish */
69 static const WCHAR stHebrew[]={'A','a','B','b',0x05e0,0x05e1,0x05e9,0x05ea,0}; /* Hebrew */
70 static const WCHAR stArabic[]={'A','a','B','b',0x0627,0x0628,0x062c,0x062f,0x0647,0x0648,0x0632,0};/* Arabic */
71 static const WCHAR stBaltic[]={'A','a','B','b','Y','y','Z','z',0}; /* Baltic */
72 static const WCHAR stVietname[]={'A','a','B','b',0x01a0,0x01a1,0x01af,0x01b0,0}; /* Vietnamese */
73 static const WCHAR stCyrillic[]={'A','a','B','b',0x0411,0x0431,0x0424,0x0444,0}; /* Cyrillic */
74 static const WCHAR stEastEur[]={'A','a','B','b',0xc1,0xe1,0xd4,0xf4,0}; /* East European */
75 static const WCHAR stThai[]={'A','a','B','b',0x0e2d,0x0e31,0x0e01,0x0e29,0x0e23,0x0e44,0x0e17,0x0e22,0}; /* Thai */
76 static const WCHAR stJohab[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Johab */
77 static const WCHAR stMac[]={'A','a','B','b','Y','y','Z','z',0}; /* Mac */
78 static const WCHAR stOEM[]={'A','a','B','b',0xf8,0xf1,0xfd,0}; /* OEM */
79 /* the following character sets actually behave different (Win2K observation):
80 * the sample string is 'sticky': it uses the sample string of the previous
81 * selected character set. That behaviour looks like some default, which is
82 * not (yet) implemented. */
83 static const WCHAR stVISCII[]={'A','a','B','b',0}; /* VISCII */
84 static const WCHAR stTCVN[]={'A','a','B','b',0}; /* TCVN */
85 static const WCHAR stKOI8[]={'A','a','B','b',0}; /* KOI-8 */
86 static const WCHAR stIso88593[]={'A','a','B','b',0}; /* ISO-8859-3 */
87 static const WCHAR stIso88594[]={'A','a','B','b',0}; /* ISO-8859-4 */
88 static const WCHAR stIso885910[]={'A','a','B','b',0}; /* ISO-8859-10 */
89 static const WCHAR stCeltic[]={'A','a','B','b',0};/* Celtic */
91 static const WCHAR *sample_lang_text[]={
92 stWestern,stSymbol,stShiftJis,stHangul,stGB2312,
93 stBIG5,stGreek,stTurkish,stHebrew,stArabic,
94 stBaltic,stVietname,stCyrillic,stEastEur,stThai,
95 stJohab,stMac,stOEM,stVISCII,stTCVN,
96 stKOI8,stIso88593,stIso88594,stIso885910,stCeltic};
99 static const BYTE CHARSET_ORDER[256]={
100 CI(ANSI), 0, CI(SYMBOL), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 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, CI(MAC), 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, 0, 0, 0,
108 CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 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, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
115 CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
118 static const struct {
122 #define XX(x) { x, #x },
127 XX(CF_ENABLETEMPLATE)
128 XX(CF_ENABLETEMPLATEHANDLE)
129 XX(CF_INITTOLOGFONTSTRUCT)
137 XX(CF_FIXEDPITCHONLY)
139 XX(CF_FORCEFONTEXIST)
151 void _dump_cf_flags(DWORD cflags)
155 for (i = 0; i < sizeof(cfflags)/sizeof(cfflags[0]); i++)
156 if (cfflags[i].mask & cflags)
157 TRACE("%s|",cfflags[i].name);
161 /***********************************************************************
162 * ChooseFontW (COMDLG32.@)
164 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
171 static const WCHAR chooseFontW[] = {'C','H','O','O','S','E','_',
174 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
176 template=(LPCVOID)lpChFont->hInstance;
179 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
181 hDlginst=lpChFont->hInstance;
182 if( !(hResInfo = FindResourceW(hDlginst, lpChFont->lpTemplateName,
185 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
190 hDlginst=COMDLG32_hInstance;
191 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
193 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
197 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
198 !(template = LockResource( hDlgTmpl )))
200 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
204 if (TRACE_ON(commdlg))
205 _dump_cf_flags(lpChFont->Flags);
207 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
208 FIXME(": unimplemented flag (ignored)\n");
210 return DialogBoxIndirectParamW(COMDLG32_hInstance, template,
211 lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
214 /***********************************************************************
215 * ChooseFontA (COMDLG32.@)
217 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
224 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
226 template=(LPCVOID)lpChFont->hInstance;
229 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
231 hDlginst=lpChFont->hInstance;
232 if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
235 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
240 hDlginst=COMDLG32_hInstance;
241 if (!(hResInfo = FindResourceA(hDlginst, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
243 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
247 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
248 !(template = LockResource( hDlgTmpl )))
250 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
254 if (TRACE_ON(commdlg))
255 _dump_cf_flags(lpChFont->Flags);
257 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
258 FIXME(": unimplemented flag (ignored)\n");
260 return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
261 lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
265 #define TEXT_EXTRAS 4
266 #define TEXT_COLORS 16
268 static const COLORREF textcolors[TEXT_COLORS]=
270 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
271 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
272 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
273 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
276 /***********************************************************************
277 * CFn_HookCallChk32 [internal]
279 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
282 if(lpcf->Flags & CF_ENABLEHOOK)
288 /*************************************************************************
289 * AddFontFamily [internal]
291 INT AddFontFamily(const ENUMLOGFONTEXA *lpElfex, const NEWTEXTMETRICEXA *lpNTM,
292 UINT nFontType, LPCHOOSEFONTA lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
296 const LOGFONTA *lplf = &(lpElfex->elfLogFont);
298 TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
300 if (lpcf->Flags & CF_FIXEDPITCHONLY)
301 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
303 if (lpcf->Flags & CF_ANSIONLY)
304 if (lplf->lfCharSet != ANSI_CHARSET)
306 if (lpcf->Flags & CF_TTONLY)
307 if (!(nFontType & TRUETYPE_FONTTYPE))
312 i=SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
314 i = SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
316 /* store some important font information */
317 w = (lplf->lfPitchAndFamily) << 8 |
318 (HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
319 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
325 /*************************************************************************
326 * FontFamilyEnumProc32 [internal]
328 static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXA *lpElfex,
329 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam)
332 e=(LPCFn_ENUMSTRUCT)lParam;
333 return AddFontFamily( lpElfex, (NEWTEXTMETRICEXA *) metrics,
334 dwFontType, e->lpcf32a, e->hWnd1, e);
337 /*************************************************************************
338 * SetFontStylesToCombo2 [internal]
340 * Fill font style information into combobox (without using font.c directly)
342 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTA *lplf)
351 static const struct FONTSTYLE fontstyles[FSTYLES]={
352 { 0,FW_NORMAL,"Regular"}, { 1,FW_NORMAL,"Italic"},
353 { 0,FW_BOLD,"Bold"}, { 1,FW_BOLD,"Bold Italic"}
360 memcpy(&lf, lplf, sizeof(LOGFONTA));
362 for (i=0;i<FSTYLES;i++)
364 lf.lfItalic=fontstyles[i].italic;
365 lf.lfWeight=fontstyles[i].weight;
366 hf=CreateFontIndirectA(&lf);
367 hf=SelectObject(hdc,hf);
368 GetTextMetricsA(hdc,&tm);
369 hf=SelectObject(hdc,hf);
371 /* font successful created ? */
372 if (tm.tmWeight==fontstyles[i].weight &&
373 ((tm.tmItalic != 0)==fontstyles[i].italic))
375 j=SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
376 if (j==CB_ERR) return 1;
377 j=SendMessageA(hwnd, CB_SETITEMDATA, j,
378 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
379 if (j==CB_ERR) return 1;
385 /*************************************************************************
386 * AddFontSizeToCombo3 [internal]
388 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
393 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
394 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
396 sprintf(buffer, "%2d", h);
397 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
400 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
401 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
402 if (j==CB_ERR) return 1;
408 /*************************************************************************
409 * SetFontSizesToCombo3 [internal]
411 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
413 static const char sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
416 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
417 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
421 /*************************************************************************
422 * CFn_GetDC [internal]
424 inline HDC CFn_GetDC(LPCHOOSEFONTA lpcf)
426 HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
429 if(!ret) ERR("HDC failure!!!\n");
433 /*************************************************************************
434 * CFn_ReleaseDC [internal]
436 inline void CFn_ReleaseDC(LPCHOOSEFONTA lpcf, HDC hdc)
438 if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
442 /***********************************************************************
443 * AddFontStyle [internal]
445 INT AddFontStyle( const ENUMLOGFONTEXA *lpElfex, const NEWTEXTMETRICEXA *lpNTM,
446 UINT nFontType, LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3,
447 HWND hDlg, BOOL iswin16)
450 const LOGFONTA *lplf = &(lpElfex->elfLogFont);
454 TRACE("(nFontType=%d)\n",nFontType);
455 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
456 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
457 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
458 lplf->lfEscapement,lplf->lfOrientation,
459 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
460 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
461 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
462 if (nFontType & RASTER_FONTTYPE)
465 if(!(hdc = CFn_GetDC(lpcf))) return 0;
466 points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
467 72, GetDeviceCaps(hdc, LOGPIXELSY));
468 CFn_ReleaseDC(lpcf, hdc);
469 i = AddFontSizeToCombo3(hcmb3, points, lpcf);
471 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
473 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
475 if(!(hdc = CFn_GetDC(lpcf))) return 0;
476 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
477 CFn_ReleaseDC(lpcf, hdc);
481 if( iswin16 || !( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
482 i = SendMessageA( hcmb5, CB_FINDSTRINGEXACT, 0,
483 (LPARAM)lpElfex->elfScript);
485 i = SendMessageA( hcmb5, CB_ADDSTRING, 0,
486 (LPARAM)lpElfex->elfScript);
488 SendMessageA( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
493 static INT CFn_FitFontSize( HWND hDlg, int points)
497 /* look for fitting font size in combobox3 */
498 n=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
501 if (points == (int)SendDlgItemMessageA
502 (hDlg,cmb3, CB_GETITEMDATA,i,0))
504 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
505 SendMessageA(hDlg, WM_COMMAND,
506 MAKEWPARAM(cmb3, CBN_SELCHANGE),
507 (LPARAM)GetDlgItem(hDlg,cmb3));
515 static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
519 /* look for fitting font style in combobox2 */
520 for (i=0;i<TEXT_EXTRAS;i++)
522 id =SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
523 if (packedstyle == id)
525 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
526 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
527 (LPARAM)GetDlgItem(hDlg,cmb2));
536 static INT CFn_FitCharSet( HWND hDlg, int charset )
539 /* look for fitting char set in combobox5 */
540 n=SendDlgItemMessageA(hDlg, cmb5, CB_GETCOUNT, 0, 0);
543 cs =SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, i, 0);
546 SendDlgItemMessageA(hDlg, cmb5, CB_SETCURSEL, i, 0);
547 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
548 (LPARAM)GetDlgItem(hDlg,cmb2));
552 /* no charset fits: select the first one in the list */
553 SendDlgItemMessageA(hDlg, cmb5, CB_SETCURSEL, 0, 0);
554 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
555 (LPARAM)GetDlgItem(hDlg,cmb2));
559 /***********************************************************************
560 * FontStyleEnumProc32 [internal]
562 static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXA *lpElfex,
563 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam )
565 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
568 HWND hDlg=GetParent(hcmb3);
569 return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXA *) metrics,
570 dwFontType, s->lpcf32a, hcmb2, hcmb3, hDlg, FALSE);
573 /***********************************************************************
574 * CFn_WMInitDialog [internal]
576 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
584 HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
586 SetPropA(hDlg, WINE_FONTDATA, (HANDLE)lParam);
587 lpxx=lpcf->lpLogFont;
588 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
590 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
592 ERR("structure size failure !!!\n");
597 himlTT = ImageList_LoadImageA( COMDLG32_hInstance, MAKEINTRESOURCEA(38),
598 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
600 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
601 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
602 if (!(lpcf->Flags & CF_APPLY))
603 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
604 if (lpcf->Flags & CF_EFFECTS)
606 for (i=0;i<TEXT_COLORS;i++)
610 if( LoadStringA(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
611 sizeof(name)/sizeof(*name) )==0 )
613 strcpy( name, "[color name]" );
615 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
616 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[j]);
617 /* look for a fitting value in color combobox */
618 if (textcolors[j]==lpcf->rgbColors)
619 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
624 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
625 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
626 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
627 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
628 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
630 if(!(hdc = CFn_GetDC(lpcf)))
635 s.hWnd1=GetDlgItem(hDlg,cmb1);
640 elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
641 elf.lfPitchAndFamily = 0;
642 elf.lfFaceName[0] = '\0'; /* enum all fonts */
643 if (!EnumFontFamiliesExA(hdc, &elf, (FONTENUMPROCA)FontFamilyEnumProc, (LPARAM)&s, 0))
645 TRACE("EnumFontFamiliesEx returns 0\n");
649 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
650 FIXME("No font found with fixed pitch only, dropping flag.\n");
651 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
654 if (lpcf->Flags & CF_TTONLY) {
655 FIXME("No font found with truetype only, dropping flag.\n");
656 lpcf->Flags &= ~CF_TTONLY;
663 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
665 /* look for fitting font name in combobox1 */
666 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
669 INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
672 int charset = lpxx->lfCharSet;
673 points = MulDiv( height, 72, GetDeviceCaps(hdc, LOGPIXELSY));
674 pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
675 FW_NORMAL,lpxx->lfItalic !=0);
676 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
677 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
678 (LPARAM)GetDlgItem(hDlg,cmb1));
680 /* look for fitting font style in combobox2 */
681 CFn_FitFontStyle(hDlg, pstyle);
682 /* look for fitting font size in combobox3 */
683 CFn_FitFontSize(hDlg, points);
684 CFn_FitCharSet( hDlg, charset );
689 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
690 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
691 (LPARAM)GetDlgItem(hDlg,cmb1));
693 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
695 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
698 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
699 SendMessageA(hDlg,WM_COMMAND,cmb2,
700 MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
703 CFn_ReleaseDC(lpcf, hdc);
709 /***********************************************************************
710 * CFn_WMMeasureItem [internal]
712 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
717 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
719 himlTT = ImageList_LoadImageA( COMDLG32_hInstance, MAKEINTRESOURCEA(38),
720 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
721 ImageList_GetIconSize( himlTT, 0, &lpmi->itemHeight);
722 lpmi->itemHeight += 2;
723 /* use MAX of bitmap height and tm.tmHeight .*/
726 hfontprev = SelectObject( hdc, GetStockObject( SYSTEM_FONT));
727 GetTextMetricsW( hdc, &tm);
728 if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
729 SelectObject( hdc, hfontprev);
730 ReleaseDC( hDlg, hdc);
735 /***********************************************************************
736 * CFn_WMDrawItem [internal]
738 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
742 COLORREF cr, oldText=0, oldBk=0;
746 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
748 if (lpdi->itemID == (UINT)-1) /* got no items */
749 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
752 if (lpdi->CtlType == ODT_COMBOBOX)
754 if (lpdi->itemState & ODS_SELECTED)
756 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
757 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
758 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
761 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
762 SelectObject(lpdi->hDC, hBrush);
764 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
767 return TRUE; /* this should never happen */
773 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
774 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
776 TextOutA(lpdi->hDC, lpdi->rcItem.left + TTBITMAP_XSIZE + 10,
777 lpdi->rcItem.top, buffer, strlen(buffer));
778 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
780 if (nFontType & TRUETYPE_FONTTYPE) {
781 idx = 0; /* picture: TT */
782 if( nFontType & NTM_TT_OPENTYPE)
783 idx = 2; /* picture: O */
784 } else if( nFontType & NTM_PS_OPENTYPE)
785 idx = 3; /* picture: O+ps */
786 else if( nFontType & NTM_TYPE1)
787 idx = 4; /* picture: a */
788 else if( nFontType & DEVICE_FONTTYPE)
789 idx = 1; /* picture: printer */
791 ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
792 lpdi->rcItem.top, ILD_TRANSPARENT);
796 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
798 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
800 TextOutA(lpdi->hDC, lpdi->rcItem.left,
801 lpdi->rcItem.top, buffer, strlen(buffer));
805 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
806 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
808 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
809 lpdi->rcItem.top, buffer, strlen(buffer));
810 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
811 hBrush = CreateSolidBrush(cr);
814 hBrush = SelectObject (lpdi->hDC, hBrush) ;
815 rect.right=rect.left+25;
819 Rectangle( lpdi->hDC, rect.left, rect.top,
820 rect.right, rect.bottom );
821 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
828 return TRUE; /* this should never happen */
830 if (lpdi->itemState & ODS_SELECTED)
832 SetTextColor(lpdi->hDC, oldText);
833 SetBkColor(lpdi->hDC, oldBk);
839 /***********************************************************************
840 * CFn_WMCommand [internal]
842 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
848 LPLOGFONTA lpxx=lpcf->lpLogFont;
850 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
851 switch (LOWORD(wParam))
854 if (HIWORD(wParam)==CBN_SELCHANGE)
856 INT pointsize; /* save current pointsize */
857 LONG pstyle; /* save current style */
860 if(!(hdc = CFn_GetDC(lpcf)))
865 idx = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
866 pointsize = (int)SendDlgItemMessageA( hDlg, cmb3, CB_GETITEMDATA,
868 idx = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
869 pstyle = SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
870 idx = SendDlgItemMessageA(hDlg, cmb5, CB_GETCURSEL, 0, 0);
871 charset = SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, idx, 0);
873 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
874 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
875 SendDlgItemMessageA(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
876 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL, 0, 0);
879 HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
882 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
883 (LPARAM)enumlf.lfFaceName);
884 TRACE("WM_COMMAND/cmb1 =>%s\n",enumlf.lfFaceName);
885 s.hWnd1=GetDlgItem(hDlg, cmb2);
886 s.hWnd2=GetDlgItem(hDlg, cmb3);
888 enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
889 enumlf.lfPitchAndFamily = 0;
890 EnumFontFamiliesExA(hdc, &enumlf,
891 (FONTENUMPROCA)FontStyleEnumProc, (LPARAM)&s, 0);
892 CFn_FitFontStyle(hDlg, pstyle);
893 if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
894 if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
897 CFn_ReleaseDC(lpcf, hdc);
904 if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
909 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
910 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
912 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
915 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
917 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
918 lpcf->nFontType = LOWORD(l);
919 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
920 /* same value reported to the EnumFonts
921 call back with the extra FONTTYPE_... bits added */
922 lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
924 strcpy(lpxx->lfFaceName,str);
925 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
928 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
929 if (0!=(lpxx->lfItalic=HIWORD(l)))
930 lpcf->nFontType |= ITALIC_FONTTYPE;
931 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
932 lpcf->nFontType |= BOLD_FONTTYPE;
934 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
936 lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageA(hDlg, cmb3,
937 CB_GETITEMDATA , i, 0));
939 lpcf->iPointSize = 100;
940 hdc = CFn_GetDC(lpcf);
943 lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
944 GetDeviceCaps(hdc, LOGPIXELSY), 720);
945 CFn_ReleaseDC(lpcf, hdc);
947 lpxx->lfHeight = -lpcf->iPointSize / 10;
948 i=SendDlgItemMessageA(hDlg, cmb5, CB_GETCURSEL, 0, 0);
950 lpxx->lfCharSet=SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, i, 0);
952 lpxx->lfCharSet = DEFAULT_CHARSET;
953 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
954 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
955 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
956 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
957 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
958 lpxx->lfQuality=DEFAULT_QUALITY;
960 wininfo.cbSize=sizeof(wininfo);
962 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
964 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
965 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
971 i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
976 lpcf->rgbColors=textcolors[i];
977 wininfo.cbSize=sizeof(wininfo);
979 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
981 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
982 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
988 i=RegisterWindowMessageA( HELPMSGSTRINGA );
990 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetPropA(hDlg, WINE_FONTDATA));
991 /* if (CFn_HookCallChk(lpcf))
992 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
996 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
997 ( (lpcf->Flags & CF_LIMITSIZE) &&
998 (lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
999 (lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
1000 EndDialog(hDlg, TRUE);
1004 sprintf(buffer,"Select a font size between %d and %d points.",
1005 lpcf->nSizeMin,lpcf->nSizeMax);
1006 MessageBoxA(hDlg, buffer, NULL, MB_OK);
1010 EndDialog(hDlg, FALSE);
1016 LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1021 LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam,
1022 LPCHOOSEFONTA lpcf )
1026 info.cbSize=sizeof(info);
1028 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
1035 LOGFONTA lf = *(lpcf->lpLogFont);
1037 MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1038 hdc = BeginPaint( hDlg, &ps );
1040 TRACE("erase %d, rect=(%ld,%ld)-(%ld,%ld)\n", ps.fErase,
1041 ps.rcPaint.left, ps.rcPaint.top,
1042 ps.rcPaint.right, ps.rcPaint.bottom);
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 );
1074 /***********************************************************************
1075 * FormatCharDlgProcA [internal]
1077 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1081 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;
1134 if (uMsg!=WM_INITDIALOG)
1136 lpcf32w=(LPCHOOSEFONTW)GetPropA(hDlg, WINE_FONTDATA);
1139 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1140 res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
1146 lpcf32w=(LPCHOOSEFONTW)lParam;
1147 if (!CFn_WMInitDialog(hDlg, wParam, lParam, (LPCHOOSEFONTA)lpcf32w))
1149 TRACE("CFn_WMInitDialog returned FALSE\n");
1152 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1153 return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1157 case WM_MEASUREITEM:
1158 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1160 return CFn_WMDrawItem(hDlg, wParam, lParam);
1162 return CFn_WMCommand(hDlg, wParam, lParam, (LPCHOOSEFONTW)lpcf32w);
1164 return CFn_WMDestroy(hDlg, wParam, lParam);
1165 case WM_CHOOSEFONT_GETLOGFONT:
1166 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1168 FIXME("current logfont back to caller\n");