Release 1.6-rc2.
[wine/testsucceed.git] / dlls / comdlg32 / fontdlg.c
blobe5b87bfeb987503996db9f428e34a35912525417
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "commdlg.h"
33 #include "dlgs.h"
34 #include "wine/debug.h"
35 #include "cderr.h"
36 #include "cdlg.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
40 typedef struct
42 HWND hWnd1;
43 HWND hWnd2;
44 LPCHOOSEFONTW lpcf32w;
45 int added;
46 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
49 static const WCHAR strWineFontData[] = {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A',0};
50 static const WCHAR strWineFontData_a[] =
51 {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A','_','A',0};
52 static const WCHAR chooseFontW[] = {'C','H','O','O','S','E','_','F','O','N','T',0};
54 /* image list with TrueType bitmaps and more */
55 static HIMAGELIST himlTT = 0;
56 #define TTBITMAP_XSIZE 20 /* x-size of the bitmaps */
58 static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
59 static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
61 /* There is a table here of all charsets, and the sample text for each.
62 * There is a second table that translates a charset into an index into
63 * the first table.
66 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
69 static const WCHAR stWestern[]={'A','a','B','b','Y','y','Z','z',0}; /* Western and default */
70 static const WCHAR stSymbol[]={'S','y','m','b','o','l',0}; /* Symbol */
71 static const WCHAR stShiftJis[]={'A','a',0x3042,0x3041,0x30a2,0x30a1,0x4e9c,0x5b87,0}; /* Shift JIS */
72 static const WCHAR stHangul[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Hangul */
73 static const WCHAR stGB2312[]={0x5fae,0x8f6f,0x4e2d,0x6587,0x8f6f,0x4ef6,0}; /* GB2312 */
74 static const WCHAR stBIG5[]={0x4e2d,0x6587,0x5b57,0x578b,0x7bc4,0x4f8b,0}; /* BIG5 */
75 static const WCHAR stGreek[]={'A','a','B','b',0x0391,0x03b1,0x0392,0x03b2,0}; /* Greek */
76 static const WCHAR stTurkish[]={'A','a','B','b',0x011e,0x011f,0x015e,0x015f,0}; /* Turkish */
77 static const WCHAR stHebrew[]={'A','a','B','b',0x05e0,0x05e1,0x05e9,0x05ea,0}; /* Hebrew */
78 static const WCHAR stArabic[]={'A','a','B','b',0x0627,0x0628,0x062c,0x062f,0x0647,0x0648,0x0632,0};/* Arabic */
79 static const WCHAR stBaltic[]={'A','a','B','b','Y','y','Z','z',0}; /* Baltic */
80 static const WCHAR stVietname[]={'A','a','B','b',0x01a0,0x01a1,0x01af,0x01b0,0}; /* Vietnamese */
81 static const WCHAR stCyrillic[]={'A','a','B','b',0x0411,0x0431,0x0424,0x0444,0}; /* Cyrillic */
82 static const WCHAR stEastEur[]={'A','a','B','b',0xc1,0xe1,0xd4,0xf4,0}; /* East European */
83 static const WCHAR stThai[]={'A','a','B','b',0x0e2d,0x0e31,0x0e01,0x0e29,0x0e23,0x0e44,0x0e17,0x0e22,0}; /* Thai */
84 static const WCHAR stJohab[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Johab */
85 static const WCHAR stMac[]={'A','a','B','b','Y','y','Z','z',0}; /* Mac */
86 static const WCHAR stOEM[]={'A','a','B','b',0xf8,0xf1,0xfd,0}; /* OEM */
87 /* the following character sets actually behave different (Win2K observation):
88 * the sample string is 'sticky': it uses the sample string of the previous
89 * selected character set. That behaviour looks like some default, which is
90 * not (yet) implemented. */
91 static const WCHAR stVISCII[]={'A','a','B','b',0}; /* VISCII */
92 static const WCHAR stTCVN[]={'A','a','B','b',0}; /* TCVN */
93 static const WCHAR stKOI8[]={'A','a','B','b',0}; /* KOI-8 */
94 static const WCHAR stIso88593[]={'A','a','B','b',0}; /* ISO-8859-3 */
95 static const WCHAR stIso88594[]={'A','a','B','b',0}; /* ISO-8859-4 */
96 static const WCHAR stIso885910[]={'A','a','B','b',0}; /* ISO-8859-10 */
97 static const WCHAR stCeltic[]={'A','a','B','b',0};/* Celtic */
99 static const WCHAR * const sample_lang_text[]={
100 stWestern,stSymbol,stShiftJis,stHangul,stGB2312,
101 stBIG5,stGreek,stTurkish,stHebrew,stArabic,
102 stBaltic,stVietname,stCyrillic,stEastEur,stThai,
103 stJohab,stMac,stOEM,stVISCII,stTCVN,
104 stKOI8,stIso88593,stIso88594,stIso885910,stCeltic};
107 static const BYTE CHARSET_ORDER[256]={
108 CI(ANSI), 0, CI(SYMBOL), 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0,
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 0, 0, 0, 0, 0, 0, 0,
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 0, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119 0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
123 CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
126 static const struct {
127 DWORD mask;
128 const char *name;
129 } cfflags[] = {
130 #define XX(x) { x, #x },
131 XX(CF_SCREENFONTS)
132 XX(CF_PRINTERFONTS)
133 XX(CF_SHOWHELP)
134 XX(CF_ENABLEHOOK)
135 XX(CF_ENABLETEMPLATE)
136 XX(CF_ENABLETEMPLATEHANDLE)
137 XX(CF_INITTOLOGFONTSTRUCT)
138 XX(CF_USESTYLE)
139 XX(CF_EFFECTS)
140 XX(CF_APPLY)
141 XX(CF_ANSIONLY)
142 XX(CF_NOVECTORFONTS)
143 XX(CF_NOSIMULATIONS)
144 XX(CF_LIMITSIZE)
145 XX(CF_FIXEDPITCHONLY)
146 XX(CF_WYSIWYG)
147 XX(CF_FORCEFONTEXIST)
148 XX(CF_SCALABLEONLY)
149 XX(CF_TTONLY)
150 XX(CF_NOFACESEL)
151 XX(CF_NOSTYLESEL)
152 XX(CF_NOSIZESEL)
153 XX(CF_SELECTSCRIPT)
154 XX(CF_NOSCRIPTSEL)
155 XX(CF_NOVERTFONTS)
156 #undef XX
159 static void _dump_cf_flags(DWORD cflags)
161 unsigned int i;
163 for (i = 0; i < sizeof(cfflags)/sizeof(cfflags[0]); i++)
164 if (cfflags[i].mask & cflags)
165 TRACE("%s|",cfflags[i].name);
166 TRACE("\n");
169 /***********************************************************************
170 * ChooseFontW (COMDLG32.@)
172 * Create a font dialog box.
174 * PARAMS
175 * lpChFont [I/O] in: information to initialize the dialog box.
176 * out: User's color selection
178 * RETURNS
179 * TRUE: Ok button clicked.
180 * FALSE: Cancel button clicked, or error.
182 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
184 LPCVOID template;
185 HRSRC hResInfo;
186 HINSTANCE hDlginst;
187 HGLOBAL hDlgTmpl;
189 TRACE("(%p)\n", lpChFont);
191 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
193 template=lpChFont->hInstance;
194 } else
196 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
198 hDlginst=lpChFont->hInstance;
199 if( !(hResInfo = FindResourceW(hDlginst, lpChFont->lpTemplateName,
200 (LPWSTR)RT_DIALOG)))
202 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
203 return FALSE;
205 } else
207 hDlginst=COMDLG32_hInstance;
208 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
210 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
211 return FALSE;
214 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
215 !(template = LockResource( hDlgTmpl )))
217 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
218 return FALSE;
221 if (TRACE_ON(commdlg))
222 _dump_cf_flags(lpChFont->Flags);
224 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
225 FIXME(": unimplemented flag (ignored)\n");
227 return DialogBoxIndirectParamW(COMDLG32_hInstance, template,
228 lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
231 /***********************************************************************
232 * ChooseFontA (COMDLG32.@)
234 * See ChooseFontW.
236 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
238 LPCVOID template;
239 HRSRC hResInfo;
240 HINSTANCE hDlginst;
241 HGLOBAL hDlgTmpl;
243 TRACE("(%p)\n", lpChFont);
245 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
247 template=lpChFont->hInstance;
248 } else
250 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
252 hDlginst=lpChFont->hInstance;
253 if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
254 (LPSTR)RT_DIALOG)))
256 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
257 return FALSE;
259 } else
261 hDlginst=COMDLG32_hInstance;
262 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
264 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
265 return FALSE;
268 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
269 !(template = LockResource( hDlgTmpl )))
271 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
272 return FALSE;
275 if (TRACE_ON(commdlg))
276 _dump_cf_flags(lpChFont->Flags);
277 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
278 FIXME(": unimplemented flag (ignored)\n");
280 return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
281 lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
284 #define TEXT_EXTRAS 4
285 #define TEXT_COLORS 16
287 static const COLORREF textcolors[TEXT_COLORS]=
289 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
290 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
291 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
292 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
295 /***********************************************************************
296 * CFn_HookCallChk32 [internal]
298 static BOOL CFn_HookCallChk32(const CHOOSEFONTW *lpcf)
300 if (lpcf)
301 if(lpcf->Flags & CF_ENABLEHOOK)
302 if (lpcf->lpfnHook)
303 return TRUE;
304 return FALSE;
307 /*************************************************************************
308 * AddFontFamily [internal]
310 static INT AddFontFamily(const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
311 UINT nFontType, const CHOOSEFONTW *lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
313 int i;
314 WORD w;
315 const LOGFONTW *lplf = &(lpElfex->elfLogFont);
317 TRACE("font=%s (nFontType=%d)\n", debugstr_w(lplf->lfFaceName), nFontType);
319 if (lpcf->Flags & CF_FIXEDPITCHONLY)
320 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
321 return 1;
322 if (lpcf->Flags & CF_ANSIONLY)
323 if (lplf->lfCharSet != ANSI_CHARSET)
324 return 1;
325 if (lpcf->Flags & CF_TTONLY)
326 if (!(nFontType & TRUETYPE_FONTTYPE))
327 return 1;
329 if (e) e->added++;
331 i=SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
332 if (i == CB_ERR) {
333 i = SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
334 if( i != CB_ERR) {
335 /* store some important font information */
336 w = (lplf->lfPitchAndFamily) << 8 |
337 (HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
338 SendMessageW(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
341 return 1;
344 /*************************************************************************
345 * FontFamilyEnumProc32 [internal]
347 static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXW *lpElfex,
348 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam)
350 LPCFn_ENUMSTRUCT e;
351 e=(LPCFn_ENUMSTRUCT)lParam;
352 return AddFontFamily( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
353 dwFontType, e->lpcf32w, e->hWnd1, e);
356 /*************************************************************************
357 * SetFontStylesToCombo2 [internal]
359 * Fill font style information into combobox (without using font.c directly)
361 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf)
363 #define FSTYLES 4
364 struct FONTSTYLE
366 int italic;
367 int weight;
368 UINT resId;
370 static const struct FONTSTYLE fontstyles[FSTYLES]={
371 { 0, FW_NORMAL, IDS_FONT_REGULAR },
372 { 1, FW_NORMAL, IDS_FONT_ITALIC },
373 { 0, FW_BOLD, IDS_FONT_BOLD },
374 { 1, FW_BOLD, IDS_FONT_BOLD_ITALIC }
376 HFONT hf;
377 TEXTMETRICW tm;
378 int i,j;
379 LOGFONTW lf;
381 lf = *lplf;
383 for (i=0;i<FSTYLES;i++)
385 lf.lfItalic=fontstyles[i].italic;
386 lf.lfWeight=fontstyles[i].weight;
387 hf=CreateFontIndirectW(&lf);
388 hf=SelectObject(hdc,hf);
389 GetTextMetricsW(hdc,&tm);
390 hf=SelectObject(hdc,hf);
391 DeleteObject(hf);
392 /* font successful created ? */
393 if (((fontstyles[i].weight == FW_NORMAL && tm.tmWeight <= FW_MEDIUM) ||
394 (fontstyles[i].weight == FW_BOLD && tm.tmWeight > FW_MEDIUM)) &&
395 ((tm.tmItalic != 0)==fontstyles[i].italic))
397 WCHAR name[64];
398 LoadStringW(COMDLG32_hInstance, fontstyles[i].resId, name, 64);
399 j=SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)name );
400 if (j==CB_ERR) return 1;
401 j=SendMessageW(hwnd, CB_SETITEMDATA, j,
402 MAKELONG(tm.tmWeight,fontstyles[i].italic));
403 if (j==CB_ERR) return 1;
406 return 0;
409 /*************************************************************************
410 * AddFontSizeToCombo3 [internal]
412 static int AddFontSizeToCombo3(HWND hwnd, UINT h, const CHOOSEFONTW *lpcf)
414 int j;
415 WCHAR buffer[20];
416 static const WCHAR strFormat[] = {'%','2','d',0};
418 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
419 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
421 wsprintfW(buffer, strFormat, h);
422 j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
423 if (j==CB_ERR)
425 j=SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
426 if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
427 if (j==CB_ERR) return 1;
430 return 0;
433 /*************************************************************************
434 * SetFontSizesToCombo3 [internal]
436 static int SetFontSizesToCombo3(HWND hwnd, const CHOOSEFONTW *lpcf)
438 static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
439 unsigned int i;
441 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
442 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
443 return 0;
446 /*************************************************************************
447 * CFn_GetDC [internal]
449 static inline HDC CFn_GetDC(const CHOOSEFONTW *lpcf)
451 HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
452 lpcf->hDC :
453 GetDC(0);
454 if(!ret) ERR("HDC failure!!!\n");
455 return ret;
458 /*************************************************************************
459 * GetScreenDPI [internal]
461 static inline int GetScreenDPI(void)
463 HDC hdc;
464 int result;
466 hdc = GetDC(0);
467 result = GetDeviceCaps(hdc, LOGPIXELSY);
468 ReleaseDC(0, hdc);
470 return result;
473 /*************************************************************************
474 * CFn_ReleaseDC [internal]
476 static inline void CFn_ReleaseDC(const CHOOSEFONTW *lpcf, HDC hdc)
478 if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
479 ReleaseDC(0, hdc);
482 /***********************************************************************
483 * AddFontStyle [internal]
485 static INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
486 UINT nFontType, const CHOOSEFONTW *lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
488 int i;
489 const LOGFONTW *lplf = &(lpElfex->elfLogFont);
490 HWND hcmb5;
491 HDC hdc;
493 TRACE("(nFontType=%d)\n",nFontType);
494 TRACE(" %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
495 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
496 debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
497 lplf->lfEscapement,lplf->lfOrientation,
498 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
499 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
500 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
501 if (nFontType & RASTER_FONTTYPE)
503 INT points;
504 points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
505 72, GetScreenDPI());
506 i = AddFontSizeToCombo3(hcmb3, points, lpcf);
507 if(i) return 0;
508 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
510 if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
512 if(!(hdc = CFn_GetDC(lpcf))) return 0;
513 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
514 CFn_ReleaseDC(lpcf, hdc);
515 if (i)
516 return 0;
518 if (!( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
519 i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
520 (LPARAM)lpElfex->elfScript);
521 if( i == CB_ERR) {
522 i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
523 (LPARAM)lpElfex->elfScript);
524 if( i != CB_ERR)
525 SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
527 return 1 ;
530 static INT CFn_FitFontSize( HWND hDlg, int points)
532 int i,n;
533 int ret = 0;
534 /* look for fitting font size in combobox3 */
535 n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
536 for (i=0;i<n;i++)
538 if (points == (int)SendDlgItemMessageW
539 (hDlg,cmb3, CB_GETITEMDATA,i,0))
541 SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0);
542 SendMessageW(hDlg, WM_COMMAND,
543 MAKEWPARAM(cmb3, CBN_SELCHANGE),
544 (LPARAM)GetDlgItem(hDlg,cmb3));
545 ret = 1;
546 break;
549 return ret;
552 static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
554 LONG id;
555 int i, ret = 0;
556 /* look for fitting font style in combobox2 */
557 for (i=0;i<TEXT_EXTRAS;i++)
559 id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
560 if (packedstyle == id)
562 SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
563 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
564 (LPARAM)GetDlgItem(hDlg,cmb2));
565 ret = 1;
566 break;
569 return ret;
573 static INT CFn_FitCharSet( HWND hDlg, int charset )
575 int i,n,cs;
576 /* look for fitting char set in combobox5 */
577 n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0);
578 for (i=0;i<n;i++)
580 cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
581 if (charset == cs)
583 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0);
584 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
585 (LPARAM)GetDlgItem(hDlg,cmb2));
586 return 1;
589 /* no charset fits: select the first one in the list */
590 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0);
591 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
592 (LPARAM)GetDlgItem(hDlg,cmb2));
593 return 0;
596 /***********************************************************************
597 * FontStyleEnumProc32 [internal]
599 static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
600 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
602 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
603 HWND hcmb2=s->hWnd1;
604 HWND hcmb3=s->hWnd2;
605 HWND hDlg=GetParent(hcmb3);
606 return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
607 dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg);
610 /***********************************************************************
611 * CFn_WMInitDialog [internal]
613 static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf)
615 HDC hdc;
616 int i,j,init=0;
617 long pstyle;
618 CFn_ENUMSTRUCT s;
619 LPLOGFONTW lpxx;
620 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
621 static const WCHAR strColorName[] = {'[','c','o','l','o','r',' ','n','a','m','e',']',0};
623 SetPropW(hDlg, strWineFontData, lpcf);
624 lpxx=lpcf->lpLogFont;
625 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
627 if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
629 ERR("structure size failure !!!\n");
630 EndDialog (hDlg, 0);
631 return FALSE;
633 if (!himlTT)
634 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
635 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
637 /* Set effect flags */
638 if((lpcf->Flags & CF_EFFECTS) && (lpcf->Flags & CF_INITTOLOGFONTSTRUCT))
640 if(lpxx->lfUnderline)
641 CheckDlgButton(hDlg, chx2, TRUE);
642 if(lpxx->lfStrikeOut)
643 CheckDlgButton(hDlg, chx1, TRUE);
646 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
647 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
648 if (!(lpcf->Flags & CF_APPLY))
649 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
650 if (lpcf->Flags & CF_NOSCRIPTSEL)
651 EnableWindow(GetDlgItem(hDlg,cmb5),FALSE);
652 if (lpcf->Flags & CF_EFFECTS)
654 for (i=0;i<TEXT_COLORS;i++)
656 WCHAR name[30];
658 if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
659 sizeof(name)/sizeof(*name) )==0 )
661 memcpy(name, strColorName, sizeof(strColorName));
663 j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
664 SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[i]);
665 /* look for a fitting value in color combobox */
666 if (textcolors[i]==lpcf->rgbColors)
667 SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0);
670 else
672 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
673 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
674 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
675 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
676 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
678 if(!(hdc = CFn_GetDC(lpcf)))
680 EndDialog (hDlg, 0);
681 return FALSE;
683 s.hWnd1=GetDlgItem(hDlg,cmb1);
684 s.lpcf32w=lpcf;
685 do {
686 LOGFONTW elf;
687 s.added = 0;
688 elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
689 elf.lfPitchAndFamily = 0;
690 elf.lfFaceName[0] = '\0'; /* enum all fonts */
691 if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0))
693 TRACE("EnumFontFamiliesEx returns 0\n");
694 break;
696 if (s.added) break;
697 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
698 FIXME("No font found with fixed pitch only, dropping flag.\n");
699 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
700 continue;
702 if (lpcf->Flags & CF_TTONLY) {
703 FIXME("No font found with truetype only, dropping flag.\n");
704 lpcf->Flags &= ~CF_TTONLY;
705 continue;
707 break;
708 } while (1);
711 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
713 /* look for fitting font name in combobox1 */
714 j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LPARAM)lpxx->lfFaceName);
715 if (j!=CB_ERR)
717 INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
718 lpxx->lfHeight;
719 INT points;
720 int charset = lpxx->lfCharSet;
721 points = MulDiv( height, 72, GetScreenDPI());
722 pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
723 FW_NORMAL,lpxx->lfItalic !=0);
724 SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0);
725 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
726 (LPARAM)GetDlgItem(hDlg,cmb1));
727 init=1;
728 /* look for fitting font style in combobox2 */
729 CFn_FitFontStyle(hDlg, pstyle);
730 /* look for fitting font size in combobox3 */
731 CFn_FitFontSize(hDlg, points);
732 CFn_FitCharSet( hDlg, charset );
735 if (!init)
737 SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0);
738 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
739 (LPARAM)GetDlgItem(hDlg,cmb1));
740 SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,0,0);
741 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
742 (LPARAM)GetDlgItem(hDlg,cmb1));
743 SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,0,0);
744 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb3, CBN_SELCHANGE),
745 (LPARAM)GetDlgItem(hDlg,cmb3));
746 SendDlgItemMessageW(hDlg,cmb5,CB_SETCURSEL,0,0);
747 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
748 (LPARAM)GetDlgItem(hDlg,cmb5));
750 if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle)
752 j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle);
753 if (j!=CB_ERR)
755 j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0);
756 SendMessageW(hDlg,WM_COMMAND,cmb2,
757 MAKELONG(LOWORD(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
760 CFn_ReleaseDC(lpcf, hdc);
761 SetCursor(hcursor);
762 return TRUE;
766 /***********************************************************************
767 * CFn_WMMeasureItem [internal]
769 static LRESULT CFn_WMMeasureItem(HWND hDlg, LPARAM lParam)
771 HDC hdc;
772 HFONT hfontprev;
773 TEXTMETRICW tm;
774 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
775 INT height = 0, cx;
777 if (!himlTT)
778 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
779 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
780 ImageList_GetIconSize( himlTT, &cx, &height);
781 lpmi->itemHeight = height + 2;
782 /* use MAX of bitmap height and tm.tmHeight .*/
783 hdc=GetDC(hDlg);
784 if(!hdc) return 0;
785 hfontprev = SelectObject( hdc, (HFONT)SendMessageW( hDlg, WM_GETFONT, 0, 0 ));
786 GetTextMetricsW(hdc, &tm);
787 if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
788 SelectObject(hdc, hfontprev);
789 ReleaseDC(hDlg, hdc);
790 return 0;
794 /***********************************************************************
795 * CFn_WMDrawItem [internal]
797 static LRESULT CFn_WMDrawItem(LPARAM lParam)
799 HBRUSH hBrush;
800 WCHAR buffer[40];
801 COLORREF cr, oldText=0, oldBk=0;
802 RECT rect;
803 int nFontType;
804 int cx, cy, idx;
805 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
807 if (lpdi->itemID == (UINT)-1) /* got no items */
808 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
809 else
811 if (lpdi->CtlType == ODT_COMBOBOX)
813 if (lpdi->itemState & ODS_SELECTED)
815 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
816 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
817 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
818 } else
820 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
821 SelectObject(lpdi->hDC, hBrush);
823 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
825 else
826 return TRUE; /* this should never happen */
828 rect=lpdi->rcItem;
829 switch (lpdi->CtlID)
831 case cmb1:
832 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
833 ImageList_GetIconSize( himlTT, &cx, &cy);
834 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
835 (LPARAM)buffer);
836 TextOutW(lpdi->hDC, lpdi->rcItem.left + cx + 4,
837 lpdi->rcItem.top, buffer, lstrlenW(buffer));
838 nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
839 idx = -1;
840 if (nFontType & TRUETYPE_FONTTYPE) {
841 idx = 0; /* picture: TT */
842 if( nFontType & NTM_TT_OPENTYPE)
843 idx = 2; /* picture: O */
844 } else if( nFontType & NTM_PS_OPENTYPE)
845 idx = 3; /* picture: O+ps */
846 else if( nFontType & NTM_TYPE1)
847 idx = 4; /* picture: a */
848 else if( nFontType & DEVICE_FONTTYPE)
849 idx = 1; /* picture: printer */
850 if( idx >= 0)
851 ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
852 (lpdi->rcItem.top + lpdi->rcItem.bottom - cy) / 2, ILD_TRANSPARENT);
853 break;
854 case cmb2:
855 case cmb3:
856 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
857 case cmb5:
858 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
859 (LPARAM)buffer);
860 TextOutW(lpdi->hDC, lpdi->rcItem.left,
861 lpdi->rcItem.top, buffer, lstrlenW(buffer));
862 break;
864 case cmb4:
865 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
866 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
867 (LPARAM)buffer);
868 TextOutW(lpdi->hDC, lpdi->rcItem.left + 25+5,
869 lpdi->rcItem.top, buffer, lstrlenW(buffer));
870 cr = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
871 hBrush = CreateSolidBrush(cr);
872 if (hBrush)
874 hBrush = SelectObject (lpdi->hDC, hBrush) ;
875 rect.right=rect.left+25;
876 rect.top++;
877 rect.left+=5;
878 rect.bottom--;
879 Rectangle( lpdi->hDC, rect.left, rect.top,
880 rect.right, rect.bottom );
881 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
883 rect=lpdi->rcItem;
884 rect.left+=25+5;
885 break;
887 default:
888 return TRUE; /* this should never happen */
890 if (lpdi->itemState & ODS_SELECTED)
892 SetTextColor(lpdi->hDC, oldText);
893 SetBkColor(lpdi->hDC, oldBk);
896 return TRUE;
899 /***********************************************************************
900 * CFn_WMCommand [internal]
902 static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcf)
904 int i;
905 long l;
906 HDC hdc;
908 if (!lpcf) return FALSE;
910 TRACE("WM_COMMAND wParam=%08X lParam=%08lX\n", (LONG)wParam, lParam);
911 switch (LOWORD(wParam))
913 case cmb1:
914 if (HIWORD(wParam)==CBN_SELCHANGE)
916 INT pointsize; /* save current pointsize */
917 LONG pstyle; /* save current style */
918 int charset;
919 int idx;
920 if(!(hdc = CFn_GetDC(lpcf)))
922 EndDialog (hDlg, 0);
923 return TRUE;
925 idx = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
926 pointsize = (int)SendDlgItemMessageW( hDlg, cmb3, CB_GETITEMDATA,
927 idx, 0);
928 idx = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
929 pstyle = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
930 idx = SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
931 charset = SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, idx, 0);
933 SendDlgItemMessageW(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
934 SendDlgItemMessageW(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
935 SendDlgItemMessageW(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
936 i=SendDlgItemMessageW(hDlg, cmb1, CB_GETCURSEL, 0, 0);
937 if (i!=CB_ERR)
939 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
940 CFn_ENUMSTRUCT s;
941 LOGFONTW enumlf;
942 SendDlgItemMessageW(hDlg, cmb1, CB_GETLBTEXT, i,
943 (LPARAM)enumlf.lfFaceName);
944 TRACE("WM_COMMAND/cmb1 =>%s\n", debugstr_w(enumlf.lfFaceName));
945 s.hWnd1=GetDlgItem(hDlg, cmb2);
946 s.hWnd2=GetDlgItem(hDlg, cmb3);
947 s.lpcf32w=lpcf;
948 enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
949 enumlf.lfPitchAndFamily = 0;
950 EnumFontFamiliesExW(hdc, &enumlf,
951 (FONTENUMPROCW)FontStyleEnumProc, (LPARAM)&s, 0);
952 CFn_FitFontStyle(hDlg, pstyle);
953 if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
954 if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
955 SetCursor(hcursor);
957 CFn_ReleaseDC(lpcf, hdc);
959 break;
960 case chx1:
961 case chx2:
962 case cmb2:
963 case cmb3:
964 case cmb5:
965 if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
967 WCHAR str[256];
968 WINDOWINFO wininfo;
969 LPLOGFONTW lpxx=lpcf->lpLogFont;
971 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
972 i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0);
973 if (i==CB_ERR)
974 i=GetDlgItemTextW( hDlg, cmb1, str, 256 );
975 else
977 SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i,
978 (LPARAM)str);
979 l=SendDlgItemMessageW(hDlg,cmb1,CB_GETITEMDATA,i,0);
980 lpcf->nFontType = LOWORD(l);
981 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
982 /* same value reported to the EnumFonts
983 call back with the extra FONTTYPE_... bits added */
984 lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
986 lstrcpynW(lpxx->lfFaceName, str, sizeof(lpxx->lfFaceName)/sizeof(lpxx->lfFaceName[0]));
987 i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
988 if (i!=CB_ERR)
990 l=SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
991 if (0!=(lpxx->lfItalic=HIWORD(l)))
992 lpcf->nFontType |= ITALIC_FONTTYPE;
993 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
994 lpcf->nFontType |= BOLD_FONTTYPE;
996 i=SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
997 if( i != CB_ERR)
998 lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageW(hDlg, cmb3,
999 CB_GETITEMDATA , i, 0));
1000 else
1001 lpcf->iPointSize = 100;
1002 lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
1003 GetScreenDPI(), 720);
1004 i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
1005 if (i!=CB_ERR)
1006 lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
1007 else
1008 lpxx->lfCharSet = DEFAULT_CHARSET;
1009 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
1010 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
1011 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
1012 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
1013 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
1014 lpxx->lfQuality=DEFAULT_QUALITY;
1016 wininfo.cbSize=sizeof(wininfo);
1018 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
1020 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
1021 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
1024 break;
1026 case cmb4:
1027 i=SendDlgItemMessageW(hDlg, cmb4, CB_GETCURSEL, 0, 0);
1028 if (i!=CB_ERR)
1030 WINDOWINFO wininfo;
1032 lpcf->rgbColors = SendDlgItemMessageW(hDlg, cmb4, CB_GETITEMDATA, i, 0);
1033 wininfo.cbSize=sizeof(wininfo);
1035 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
1037 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
1038 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
1041 break;
1043 case psh15:
1044 i=RegisterWindowMessageW( HELPMSGSTRINGW );
1045 if (lpcf->hwndOwner)
1046 SendMessageW(lpcf->hwndOwner, i, 0, (LPARAM)GetPropW(hDlg, strWineFontData));
1047 break;
1049 case IDOK:
1050 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1051 ( (lpcf->Flags & CF_LIMITSIZE) &&
1052 (lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
1053 (lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
1054 EndDialog(hDlg, TRUE);
1055 else
1057 WCHAR buffer[80];
1058 WCHAR format[80];
1059 DWORD_PTR args[2];
1060 LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, sizeof(format)/sizeof(WCHAR));
1061 args[0] = lpcf->nSizeMin;
1062 args[1] = lpcf->nSizeMax;
1063 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
1064 format, 0, 0, buffer, sizeof(buffer)/sizeof(*buffer),
1065 (__ms_va_list*)args);
1066 MessageBoxW(hDlg, buffer, NULL, MB_OK);
1068 return(TRUE);
1069 case IDCANCEL:
1070 EndDialog(hDlg, FALSE);
1071 return(TRUE);
1073 return(FALSE);
1076 static LRESULT CFn_WMDestroy(HWND hwnd, LPCHOOSEFONTW lpcfw)
1078 LPCHOOSEFONTA lpcfa;
1079 LPSTR lpszStyle;
1080 LPLOGFONTA lpLogFonta;
1081 int len;
1083 if (!lpcfw) return FALSE;
1085 lpcfa = GetPropW(hwnd, strWineFontData_a);
1086 lpLogFonta = lpcfa->lpLogFont;
1087 lpszStyle = lpcfa->lpszStyle;
1088 memcpy(lpcfa, lpcfw, sizeof(CHOOSEFONTA));
1089 lpcfa->lpLogFont = lpLogFonta;
1090 lpcfa->lpszStyle = lpszStyle;
1091 memcpy(lpcfa->lpLogFont, lpcfw->lpLogFont, sizeof(LOGFONTA));
1092 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpLogFont->lfFaceName,
1093 LF_FACESIZE, lpcfa->lpLogFont->lfFaceName, LF_FACESIZE, 0, 0);
1095 if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) {
1096 len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, 0, 0, 0);
1097 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, lpcfa->lpszStyle, len, 0, 0);
1098 HeapFree(GetProcessHeap(), 0, lpcfw->lpszStyle);
1101 HeapFree(GetProcessHeap(), 0, lpcfw->lpLogFont);
1102 HeapFree(GetProcessHeap(), 0, lpcfw);
1103 SetPropW(hwnd, strWineFontData, 0);
1105 return TRUE;
1108 static LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam, const CHOOSEFONTW *lpcf)
1110 WINDOWINFO info;
1112 if (!lpcf) return FALSE;
1114 info.cbSize=sizeof(info);
1115 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
1117 PAINTSTRUCT ps;
1118 HDC hdc;
1119 HFONT hOrigFont;
1120 LOGFONTW lf = *(lpcf->lpLogFont);
1122 MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1123 hdc = BeginPaint( hDlg, &ps );
1125 TRACE("erase %d, rect=(%d,%d)-(%d,%d)\n", ps.fErase,
1126 ps.rcPaint.left, ps.rcPaint.top,
1127 ps.rcPaint.right, ps.rcPaint.bottom);
1129 /* Paint frame */
1130 DrawEdge( hdc, &info.rcWindow, EDGE_SUNKEN, BF_RECT|BF_ADJUST );
1132 /* Draw the sample text itself */
1133 hOrigFont = SelectObject( hdc, CreateFontIndirectW( &lf ) );
1134 SetTextColor( hdc, lpcf->rgbColors );
1136 DrawTextW( hdc,
1137 sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]],
1138 -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1140 DeleteObject(SelectObject( hdc, hOrigFont ));
1141 EndPaint( hDlg, &ps );
1143 return FALSE;
1146 /***********************************************************************
1147 * FormatCharDlgProcA [internal]
1149 static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1151 LPCHOOSEFONTW lpcfw;
1152 LPCHOOSEFONTA lpcfa;
1153 INT_PTR res = FALSE;
1154 int len;
1156 if (uMsg!=WM_INITDIALOG) {
1157 lpcfw = GetPropW(hDlg, strWineFontData);
1158 if (lpcfw && CFn_HookCallChk32(lpcfw))
1159 res=CallWindowProcA((WNDPROC)lpcfw->lpfnHook, hDlg, uMsg, wParam, lParam);
1160 if (res)
1161 return res;
1162 } else {
1163 lpcfa=(LPCHOOSEFONTA)lParam;
1164 SetPropW(hDlg, strWineFontData_a, (HANDLE)lParam);
1166 lpcfw = HeapAlloc(GetProcessHeap(), 0, sizeof(CHOOSEFONTW));
1167 memcpy(lpcfw, lpcfa, sizeof(CHOOSEFONTA));
1168 lpcfw->lpLogFont = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGFONTW));
1169 memcpy(lpcfw->lpLogFont, lpcfa->lpLogFont, sizeof(LOGFONTA));
1170 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpLogFont->lfFaceName,
1171 LF_FACESIZE, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE);
1173 if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle) {
1174 len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, NULL, 0);
1175 lpcfw->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1176 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, lpcfw->lpszStyle, len);
1179 if (!CFn_WMInitDialog(hDlg, lParam, lpcfw))
1181 TRACE("CFn_WMInitDialog returned FALSE\n");
1182 return FALSE;
1184 if (CFn_HookCallChk32(lpcfw))
1185 return CallWindowProcA((WNDPROC)lpcfa->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1187 switch (uMsg)
1189 case WM_MEASUREITEM:
1190 return CFn_WMMeasureItem(hDlg,lParam);
1191 case WM_DRAWITEM:
1192 return CFn_WMDrawItem(lParam);
1193 case WM_COMMAND:
1194 return CFn_WMCommand(hDlg, wParam, lParam, lpcfw);
1195 case WM_DESTROY:
1196 return CFn_WMDestroy(hDlg, lpcfw);
1197 case WM_CHOOSEFONT_GETLOGFONT:
1199 LOGFONTA *logfont = (LOGFONTA *)lParam;
1200 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1201 memcpy( logfont, lpcfw->lpLogFont, FIELD_OFFSET( LOGFONTA, lfFaceName ));
1202 WideCharToMultiByte( CP_ACP, 0, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE,
1203 logfont->lfFaceName, LF_FACESIZE, NULL, NULL );
1204 break;
1206 case WM_PAINT:
1207 return CFn_WMPaint(hDlg, wParam, lParam, lpcfw);
1209 return res;
1212 /***********************************************************************
1213 * FormatCharDlgProcW [internal]
1215 static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1217 LPCHOOSEFONTW lpcf;
1218 INT_PTR res = FALSE;
1220 if (uMsg!=WM_INITDIALOG)
1222 lpcf= GetPropW(hDlg, strWineFontData);
1223 if (lpcf && CFn_HookCallChk32(lpcf))
1224 res=CallWindowProcW((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1225 if (res)
1226 return res;
1228 else
1230 lpcf=(LPCHOOSEFONTW)lParam;
1231 if (!CFn_WMInitDialog(hDlg, lParam, lpcf))
1233 TRACE("CFn_WMInitDialog returned FALSE\n");
1234 return FALSE;
1236 if (CFn_HookCallChk32(lpcf))
1237 return CallWindowProcW((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1239 switch (uMsg)
1241 case WM_MEASUREITEM:
1242 return CFn_WMMeasureItem(hDlg, lParam);
1243 case WM_DRAWITEM:
1244 return CFn_WMDrawItem(lParam);
1245 case WM_COMMAND:
1246 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1247 case WM_DESTROY:
1248 return TRUE;
1249 case WM_CHOOSEFONT_GETLOGFONT:
1250 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1251 memcpy( (LOGFONTW *)lParam, lpcf->lpLogFont, sizeof(LOGFONTW) );
1252 break;
1253 case WM_PAINT:
1254 return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1256 return res;