ole32: Make CoCreateInstance hookable for Steam.
[wine/multimedia.git] / dlls / comdlg32 / fontdlg.c
blob9e73ec95684194af85388f4a28bd9c1d921ee75a
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)
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)
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;
328 if (lpcf->Flags & CF_NOVERTFONTS)
329 if (lplf->lfFaceName[0] == '@')
330 return 1;
332 if (e) e->added++;
334 i=SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
335 if (i == CB_ERR) {
336 i = SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
337 if( i != CB_ERR) {
338 /* store some important font information */
339 w = (lplf->lfPitchAndFamily) << 8 |
340 (HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
341 SendMessageW(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
344 return 1;
347 /*************************************************************************
348 * FontFamilyEnumProc32 [internal]
350 static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXW *lpElfex,
351 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam)
353 LPCFn_ENUMSTRUCT e;
354 e=(LPCFn_ENUMSTRUCT)lParam;
355 return AddFontFamily( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
356 dwFontType, e->lpcf32w, e->hWnd1, e);
359 /*************************************************************************
360 * SetFontStylesToCombo2 [internal]
362 * Fill font style information into combobox (without using font.c directly)
364 static BOOL SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf)
366 #define FSTYLES 4
367 struct FONTSTYLE
369 int italic;
370 int weight;
371 UINT resId;
373 static const struct FONTSTYLE fontstyles[FSTYLES]={
374 { 0, FW_NORMAL, IDS_FONT_REGULAR },
375 { 1, FW_NORMAL, IDS_FONT_ITALIC },
376 { 0, FW_BOLD, IDS_FONT_BOLD },
377 { 1, FW_BOLD, IDS_FONT_BOLD_ITALIC }
379 HFONT hf;
380 TEXTMETRICW tm;
381 int i,j;
382 LOGFONTW lf;
384 lf = *lplf;
386 for (i=0;i<FSTYLES;i++)
388 lf.lfItalic=fontstyles[i].italic;
389 lf.lfWeight=fontstyles[i].weight;
390 hf=CreateFontIndirectW(&lf);
391 hf=SelectObject(hdc,hf);
392 GetTextMetricsW(hdc,&tm);
393 hf=SelectObject(hdc,hf);
394 DeleteObject(hf);
395 /* font successful created ? */
396 if (((fontstyles[i].weight == FW_NORMAL && tm.tmWeight <= FW_MEDIUM) ||
397 (fontstyles[i].weight == FW_BOLD && tm.tmWeight > FW_MEDIUM)) &&
398 ((tm.tmItalic != 0)==fontstyles[i].italic))
400 WCHAR name[64];
401 LoadStringW(COMDLG32_hInstance, fontstyles[i].resId, name, 64);
402 j=SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)name );
403 if (j==CB_ERR) return TRUE;
404 j=SendMessageW(hwnd, CB_SETITEMDATA, j,
405 MAKELONG(tm.tmWeight,fontstyles[i].italic));
406 if (j==CB_ERR) return TRUE;
409 return FALSE;
412 /*************************************************************************
413 * AddFontSizeToCombo3 [internal]
415 static BOOL AddFontSizeToCombo3(HWND hwnd, UINT h, const CHOOSEFONTW *lpcf)
417 int j;
418 WCHAR buffer[20];
419 static const WCHAR strFormat[] = {'%','2','d',0};
421 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
422 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
424 wsprintfW(buffer, strFormat, h);
425 j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
426 if (j==CB_ERR)
428 j=SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
429 if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
430 if (j==CB_ERR) return TRUE;
433 return FALSE;
436 /*************************************************************************
437 * SetFontSizesToCombo3 [internal]
439 static BOOL SetFontSizesToCombo3(HWND hwnd, const CHOOSEFONTW *lpcf)
441 static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
442 unsigned int i;
444 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
445 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return TRUE;
446 return FALSE;
449 /*************************************************************************
450 * CFn_GetDC [internal]
452 static inline HDC CFn_GetDC(const CHOOSEFONTW *lpcf)
454 HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
455 lpcf->hDC :
456 GetDC(0);
457 if(!ret) ERR("HDC failure!!!\n");
458 return ret;
461 /*************************************************************************
462 * GetScreenDPI [internal]
464 static inline int GetScreenDPI(void)
466 HDC hdc;
467 int result;
469 hdc = GetDC(0);
470 result = GetDeviceCaps(hdc, LOGPIXELSY);
471 ReleaseDC(0, hdc);
473 return result;
476 /*************************************************************************
477 * CFn_ReleaseDC [internal]
479 static inline void CFn_ReleaseDC(const CHOOSEFONTW *lpcf, HDC hdc)
481 if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
482 ReleaseDC(0, hdc);
485 /***********************************************************************
486 * AddFontStyle [internal]
488 static INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
489 UINT nFontType, const CHOOSEFONTW *lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
491 int i;
492 const LOGFONTW *lplf = &(lpElfex->elfLogFont);
493 HWND hcmb5;
494 HDC hdc;
496 TRACE("(nFontType=%d)\n",nFontType);
497 TRACE(" %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
498 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
499 debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
500 lplf->lfEscapement,lplf->lfOrientation,
501 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
502 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
503 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
504 if (nFontType & RASTER_FONTTYPE)
506 INT points;
507 points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
508 72, GetScreenDPI());
509 if (AddFontSizeToCombo3(hcmb3, points, lpcf))
510 return 0;
511 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
513 if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
515 BOOL res;
516 if(!(hdc = CFn_GetDC(lpcf))) return 0;
517 res = SetFontStylesToCombo2(hcmb2,hdc,lplf);
518 CFn_ReleaseDC(lpcf, hdc);
519 if (res)
520 return 0;
522 if (!( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
523 i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
524 (LPARAM)lpElfex->elfScript);
525 if( i == CB_ERR) {
526 i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
527 (LPARAM)lpElfex->elfScript);
528 if( i != CB_ERR)
529 SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
531 return 1 ;
534 static BOOL CFn_FitFontSize( HWND hDlg, int points)
536 int i,n;
537 BOOL ret = FALSE;
538 /* look for fitting font size in combobox3 */
539 n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
540 for (i=0;i<n;i++)
542 if (points == (int)SendDlgItemMessageW
543 (hDlg,cmb3, CB_GETITEMDATA,i,0))
545 SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0);
546 SendMessageW(hDlg, WM_COMMAND,
547 MAKEWPARAM(cmb3, CBN_SELCHANGE),
548 (LPARAM)GetDlgItem(hDlg,cmb3));
549 ret = TRUE;
550 break;
553 return ret;
556 static BOOL CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
558 LONG id;
559 int i;
560 BOOL ret = FALSE;
561 /* look for fitting font style in combobox2 */
562 for (i=0;i<TEXT_EXTRAS;i++)
564 id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
565 if (packedstyle == id)
567 SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
568 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
569 (LPARAM)GetDlgItem(hDlg,cmb2));
570 ret = TRUE;
571 break;
574 return ret;
578 static BOOL CFn_FitCharSet( HWND hDlg, int charset )
580 int i,n,cs;
581 /* look for fitting char set in combobox5 */
582 n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0);
583 for (i=0;i<n;i++)
585 cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
586 if (charset == cs)
588 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0);
589 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
590 (LPARAM)GetDlgItem(hDlg,cmb2));
591 return TRUE;
594 /* no charset fits: select the first one in the list */
595 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0);
596 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
597 (LPARAM)GetDlgItem(hDlg,cmb2));
598 return FALSE;
601 /***********************************************************************
602 * FontStyleEnumProc32 [internal]
604 static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
605 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
607 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
608 HWND hcmb2=s->hWnd1;
609 HWND hcmb3=s->hWnd2;
610 HWND hDlg=GetParent(hcmb3);
611 return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
612 dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg);
615 /***********************************************************************
616 * CFn_WMInitDialog [internal]
618 static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf)
620 HDC hdc;
621 int i,j;
622 BOOL init = FALSE;
623 long pstyle;
624 CFn_ENUMSTRUCT s;
625 LPLOGFONTW lpxx;
626 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
627 static const WCHAR strColorName[] = {'[','c','o','l','o','r',' ','n','a','m','e',']',0};
629 SetPropW(hDlg, strWineFontData, lpcf);
630 lpxx=lpcf->lpLogFont;
631 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
633 if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
635 ERR("structure size failure!!!\n");
636 EndDialog (hDlg, 0);
637 return FALSE;
639 if (!himlTT)
640 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
641 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
643 /* Set effect flags */
644 if((lpcf->Flags & CF_EFFECTS) && (lpcf->Flags & CF_INITTOLOGFONTSTRUCT))
646 if(lpxx->lfUnderline)
647 CheckDlgButton(hDlg, chx2, TRUE);
648 if(lpxx->lfStrikeOut)
649 CheckDlgButton(hDlg, chx1, TRUE);
652 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
653 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
654 if (!(lpcf->Flags & CF_APPLY))
655 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
656 if (lpcf->Flags & CF_NOSCRIPTSEL)
657 EnableWindow(GetDlgItem(hDlg,cmb5),FALSE);
658 if (lpcf->Flags & CF_EFFECTS)
660 for (i=0;i<TEXT_COLORS;i++)
662 WCHAR name[30];
664 if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
665 sizeof(name)/sizeof(*name) )==0 )
667 memcpy(name, strColorName, sizeof(strColorName));
669 j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
670 SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[i]);
671 /* look for a fitting value in color combobox */
672 if (textcolors[i]==lpcf->rgbColors)
673 SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0);
676 else
678 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
679 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
680 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
681 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
682 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
684 if(!(hdc = CFn_GetDC(lpcf)))
686 EndDialog (hDlg, 0);
687 return FALSE;
689 s.hWnd1=GetDlgItem(hDlg,cmb1);
690 s.lpcf32w=lpcf;
691 do {
692 LOGFONTW elf;
693 s.added = 0;
694 elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
695 elf.lfPitchAndFamily = 0;
696 elf.lfFaceName[0] = '\0'; /* enum all fonts */
697 if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0))
699 TRACE("EnumFontFamiliesEx returns 0\n");
700 break;
702 if (s.added) break;
703 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
704 FIXME("No font found with fixed pitch only, dropping flag.\n");
705 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
706 continue;
708 if (lpcf->Flags & CF_TTONLY) {
709 FIXME("No font found with truetype only, dropping flag.\n");
710 lpcf->Flags &= ~CF_TTONLY;
711 continue;
713 break;
714 } while (1);
717 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
719 /* look for fitting font name in combobox1 */
720 j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LPARAM)lpxx->lfFaceName);
721 if (j!=CB_ERR)
723 INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
724 lpxx->lfHeight;
725 INT points;
726 int charset = lpxx->lfCharSet;
727 points = MulDiv( height, 72, GetScreenDPI());
728 pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
729 FW_NORMAL,lpxx->lfItalic !=0);
730 SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0);
731 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
732 (LPARAM)GetDlgItem(hDlg,cmb1));
733 init = TRUE;
734 /* look for fitting font style in combobox2 */
735 CFn_FitFontStyle(hDlg, pstyle);
736 /* look for fitting font size in combobox3 */
737 CFn_FitFontSize(hDlg, points);
738 CFn_FitCharSet( hDlg, charset );
741 if (!init)
743 SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0);
744 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
745 (LPARAM)GetDlgItem(hDlg,cmb1));
746 SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,0,0);
747 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
748 (LPARAM)GetDlgItem(hDlg,cmb1));
749 SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,0,0);
750 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb3, CBN_SELCHANGE),
751 (LPARAM)GetDlgItem(hDlg,cmb3));
752 SendDlgItemMessageW(hDlg,cmb5,CB_SETCURSEL,0,0);
753 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
754 (LPARAM)GetDlgItem(hDlg,cmb5));
756 if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle)
758 j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle);
759 if (j!=CB_ERR)
761 j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0);
762 SendMessageW(hDlg,WM_COMMAND,cmb2,
763 MAKELONG(LOWORD(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
766 CFn_ReleaseDC(lpcf, hdc);
767 SetCursor(hcursor);
768 return TRUE;
772 /***********************************************************************
773 * CFn_WMMeasureItem [internal]
775 static LRESULT CFn_WMMeasureItem(HWND hDlg, LPARAM lParam)
777 HDC hdc;
778 HFONT hfontprev;
779 TEXTMETRICW tm;
780 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
781 INT height = 0, cx;
783 if (!himlTT)
784 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
785 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
786 ImageList_GetIconSize( himlTT, &cx, &height);
787 lpmi->itemHeight = height + 2;
788 /* use MAX of bitmap height and tm.tmHeight .*/
789 hdc=GetDC(hDlg);
790 if(!hdc) return 0;
791 hfontprev = SelectObject( hdc, (HFONT)SendMessageW( hDlg, WM_GETFONT, 0, 0 ));
792 GetTextMetricsW(hdc, &tm);
793 if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
794 SelectObject(hdc, hfontprev);
795 ReleaseDC(hDlg, hdc);
796 return 0;
800 /***********************************************************************
801 * CFn_WMDrawItem [internal]
803 static LRESULT CFn_WMDrawItem(LPARAM lParam)
805 HBRUSH hBrush;
806 WCHAR buffer[40];
807 COLORREF cr, oldText=0, oldBk=0;
808 RECT rect;
809 int nFontType;
810 int cx, cy, idx;
811 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
813 if (lpdi->itemID == (UINT)-1) /* got no items */
814 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
815 else
817 if (lpdi->CtlType == ODT_COMBOBOX)
819 if (lpdi->itemState & ODS_SELECTED)
821 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
822 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
823 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
824 } else
826 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
827 SelectObject(lpdi->hDC, hBrush);
829 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
831 else
832 return TRUE; /* this should never happen */
834 rect=lpdi->rcItem;
835 switch (lpdi->CtlID)
837 case cmb1:
838 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
839 ImageList_GetIconSize( himlTT, &cx, &cy);
840 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
841 (LPARAM)buffer);
842 TextOutW(lpdi->hDC, lpdi->rcItem.left + cx + 4,
843 lpdi->rcItem.top, buffer, lstrlenW(buffer));
844 nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
845 idx = -1;
846 if (nFontType & TRUETYPE_FONTTYPE) {
847 idx = 0; /* picture: TT */
848 if( nFontType & NTM_TT_OPENTYPE)
849 idx = 2; /* picture: O */
850 } else if( nFontType & NTM_PS_OPENTYPE)
851 idx = 3; /* picture: O+ps */
852 else if( nFontType & NTM_TYPE1)
853 idx = 4; /* picture: a */
854 else if( nFontType & DEVICE_FONTTYPE)
855 idx = 1; /* picture: printer */
856 if( idx >= 0)
857 ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
858 (lpdi->rcItem.top + lpdi->rcItem.bottom - cy) / 2, ILD_TRANSPARENT);
859 break;
860 case cmb2:
861 case cmb3:
862 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
863 case cmb5:
864 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
865 (LPARAM)buffer);
866 TextOutW(lpdi->hDC, lpdi->rcItem.left,
867 lpdi->rcItem.top, buffer, lstrlenW(buffer));
868 break;
870 case cmb4:
871 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
872 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
873 (LPARAM)buffer);
874 TextOutW(lpdi->hDC, lpdi->rcItem.left + 25+5,
875 lpdi->rcItem.top, buffer, lstrlenW(buffer));
876 cr = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
877 hBrush = CreateSolidBrush(cr);
878 if (hBrush)
880 hBrush = SelectObject (lpdi->hDC, hBrush) ;
881 rect.right=rect.left+25;
882 rect.top++;
883 rect.left+=5;
884 rect.bottom--;
885 Rectangle( lpdi->hDC, rect.left, rect.top,
886 rect.right, rect.bottom );
887 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
889 rect=lpdi->rcItem;
890 rect.left+=25+5;
891 break;
893 default:
894 return TRUE; /* this should never happen */
896 if (lpdi->itemState & ODS_SELECTED)
898 SetTextColor(lpdi->hDC, oldText);
899 SetBkColor(lpdi->hDC, oldBk);
902 return TRUE;
905 /***********************************************************************
906 * CFn_WMCommand [internal]
908 static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcf)
910 int i;
911 long l;
912 HDC hdc;
914 if (!lpcf) return FALSE;
916 TRACE("WM_COMMAND wParam=%08X lParam=%08lX\n", (LONG)wParam, lParam);
917 switch (LOWORD(wParam))
919 case cmb1:
920 if (HIWORD(wParam)==CBN_SELCHANGE)
922 INT pointsize; /* save current pointsize */
923 LONG pstyle; /* save current style */
924 int charset;
925 int idx;
926 if(!(hdc = CFn_GetDC(lpcf)))
928 EndDialog (hDlg, 0);
929 return TRUE;
931 idx = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
932 pointsize = (int)SendDlgItemMessageW( hDlg, cmb3, CB_GETITEMDATA,
933 idx, 0);
934 idx = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
935 pstyle = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
936 idx = SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
937 charset = SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, idx, 0);
939 SendDlgItemMessageW(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
940 SendDlgItemMessageW(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
941 SendDlgItemMessageW(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
942 i=SendDlgItemMessageW(hDlg, cmb1, CB_GETCURSEL, 0, 0);
943 if (i!=CB_ERR)
945 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
946 CFn_ENUMSTRUCT s;
947 LOGFONTW enumlf;
948 SendDlgItemMessageW(hDlg, cmb1, CB_GETLBTEXT, i,
949 (LPARAM)enumlf.lfFaceName);
950 TRACE("WM_COMMAND/cmb1 =>%s\n", debugstr_w(enumlf.lfFaceName));
951 s.hWnd1=GetDlgItem(hDlg, cmb2);
952 s.hWnd2=GetDlgItem(hDlg, cmb3);
953 s.lpcf32w=lpcf;
954 enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
955 enumlf.lfPitchAndFamily = 0;
956 EnumFontFamiliesExW(hdc, &enumlf,
957 (FONTENUMPROCW)FontStyleEnumProc, (LPARAM)&s, 0);
958 CFn_FitFontStyle(hDlg, pstyle);
959 if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
960 if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
961 SetCursor(hcursor);
963 CFn_ReleaseDC(lpcf, hdc);
965 break;
966 case chx1:
967 case chx2:
968 case cmb2:
969 case cmb3:
970 case cmb5:
971 if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
973 WCHAR str[256];
974 WINDOWINFO wininfo;
975 LPLOGFONTW lpxx=lpcf->lpLogFont;
977 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
978 i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0);
979 if (i==CB_ERR)
980 i=GetDlgItemTextW( hDlg, cmb1, str, 256 );
981 else
983 SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i,
984 (LPARAM)str);
985 l=SendDlgItemMessageW(hDlg,cmb1,CB_GETITEMDATA,i,0);
986 lpcf->nFontType = LOWORD(l);
987 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
988 /* same value reported to the EnumFonts
989 call back with the extra FONTTYPE_... bits added */
990 lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
992 lstrcpynW(lpxx->lfFaceName, str, sizeof(lpxx->lfFaceName)/sizeof(lpxx->lfFaceName[0]));
993 i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
994 if (i!=CB_ERR)
996 l=SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
997 if (0!=(lpxx->lfItalic=HIWORD(l)))
998 lpcf->nFontType |= ITALIC_FONTTYPE;
999 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
1000 lpcf->nFontType |= BOLD_FONTTYPE;
1002 i=SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1003 if( i != CB_ERR)
1004 lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageW(hDlg, cmb3,
1005 CB_GETITEMDATA , i, 0));
1006 else
1007 lpcf->iPointSize = 100;
1008 lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
1009 GetScreenDPI(), 720);
1010 i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
1011 if (i!=CB_ERR)
1012 lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
1013 else
1014 lpxx->lfCharSet = DEFAULT_CHARSET;
1015 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
1016 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
1017 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
1018 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
1019 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
1020 lpxx->lfQuality=DEFAULT_QUALITY;
1022 wininfo.cbSize=sizeof(wininfo);
1024 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
1026 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
1027 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
1030 break;
1032 case cmb4:
1033 i=SendDlgItemMessageW(hDlg, cmb4, CB_GETCURSEL, 0, 0);
1034 if (i!=CB_ERR)
1036 WINDOWINFO wininfo;
1038 lpcf->rgbColors = SendDlgItemMessageW(hDlg, cmb4, CB_GETITEMDATA, i, 0);
1039 wininfo.cbSize=sizeof(wininfo);
1041 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
1043 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
1044 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
1047 break;
1049 case psh15:
1050 i=RegisterWindowMessageW( HELPMSGSTRINGW );
1051 if (lpcf->hwndOwner)
1052 SendMessageW(lpcf->hwndOwner, i, 0, (LPARAM)GetPropW(hDlg, strWineFontData));
1053 break;
1055 case IDOK:
1056 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1057 ( (lpcf->Flags & CF_LIMITSIZE) &&
1058 (lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
1059 (lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
1060 EndDialog(hDlg, TRUE);
1061 else
1063 WCHAR buffer[80];
1064 WCHAR format[80];
1065 DWORD_PTR args[2];
1066 LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, sizeof(format)/sizeof(WCHAR));
1067 args[0] = lpcf->nSizeMin;
1068 args[1] = lpcf->nSizeMax;
1069 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
1070 format, 0, 0, buffer, sizeof(buffer)/sizeof(*buffer),
1071 (__ms_va_list*)args);
1072 MessageBoxW(hDlg, buffer, NULL, MB_OK);
1074 return(TRUE);
1075 case IDCANCEL:
1076 EndDialog(hDlg, FALSE);
1077 return(TRUE);
1079 return(FALSE);
1082 static LRESULT CFn_WMDestroy(HWND hwnd, LPCHOOSEFONTW lpcfw)
1084 LPCHOOSEFONTA lpcfa;
1085 LPSTR lpszStyle;
1086 LPLOGFONTA lpLogFonta;
1087 int len;
1089 if (!lpcfw) return FALSE;
1091 lpcfa = GetPropW(hwnd, strWineFontData_a);
1092 lpLogFonta = lpcfa->lpLogFont;
1093 lpszStyle = lpcfa->lpszStyle;
1094 memcpy(lpcfa, lpcfw, sizeof(CHOOSEFONTA));
1095 lpcfa->lpLogFont = lpLogFonta;
1096 lpcfa->lpszStyle = lpszStyle;
1097 memcpy(lpcfa->lpLogFont, lpcfw->lpLogFont, sizeof(LOGFONTA));
1098 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpLogFont->lfFaceName,
1099 LF_FACESIZE, lpcfa->lpLogFont->lfFaceName, LF_FACESIZE, 0, 0);
1101 if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) {
1102 len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, 0, 0, 0);
1103 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, lpcfa->lpszStyle, len, 0, 0);
1104 HeapFree(GetProcessHeap(), 0, lpcfw->lpszStyle);
1107 HeapFree(GetProcessHeap(), 0, lpcfw->lpLogFont);
1108 HeapFree(GetProcessHeap(), 0, lpcfw);
1109 SetPropW(hwnd, strWineFontData, 0);
1111 return TRUE;
1114 static LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam, const CHOOSEFONTW *lpcf)
1116 WINDOWINFO info;
1118 if (!lpcf) return FALSE;
1120 info.cbSize=sizeof(info);
1121 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
1123 PAINTSTRUCT ps;
1124 HDC hdc;
1125 HFONT hOrigFont;
1126 LOGFONTW lf = *(lpcf->lpLogFont);
1128 MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1129 hdc = BeginPaint( hDlg, &ps );
1131 TRACE("erase %d, rect=(%d,%d)-(%d,%d)\n", ps.fErase,
1132 ps.rcPaint.left, ps.rcPaint.top,
1133 ps.rcPaint.right, ps.rcPaint.bottom);
1135 /* Paint frame */
1136 DrawEdge( hdc, &info.rcWindow, EDGE_SUNKEN, BF_RECT|BF_ADJUST );
1138 /* Draw the sample text itself */
1139 hOrigFont = SelectObject( hdc, CreateFontIndirectW( &lf ) );
1140 SetTextColor( hdc, lpcf->rgbColors );
1142 DrawTextW( hdc,
1143 sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]],
1144 -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1146 DeleteObject(SelectObject( hdc, hOrigFont ));
1147 EndPaint( hDlg, &ps );
1149 return FALSE;
1152 /***********************************************************************
1153 * FormatCharDlgProcA [internal]
1155 static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1157 LPCHOOSEFONTW lpcfw;
1158 LPCHOOSEFONTA lpcfa;
1159 INT_PTR res = FALSE;
1160 int len;
1162 if (uMsg!=WM_INITDIALOG) {
1163 lpcfw = GetPropW(hDlg, strWineFontData);
1164 if (lpcfw && CFn_HookCallChk32(lpcfw))
1165 res=CallWindowProcA((WNDPROC)lpcfw->lpfnHook, hDlg, uMsg, wParam, lParam);
1166 if (res)
1167 return res;
1168 } else {
1169 lpcfa=(LPCHOOSEFONTA)lParam;
1170 SetPropW(hDlg, strWineFontData_a, (HANDLE)lParam);
1172 lpcfw = HeapAlloc(GetProcessHeap(), 0, sizeof(CHOOSEFONTW));
1173 memcpy(lpcfw, lpcfa, sizeof(CHOOSEFONTA));
1174 lpcfw->lpLogFont = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGFONTW));
1175 memcpy(lpcfw->lpLogFont, lpcfa->lpLogFont, sizeof(LOGFONTA));
1176 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpLogFont->lfFaceName,
1177 LF_FACESIZE, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE);
1179 if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle) {
1180 len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, NULL, 0);
1181 lpcfw->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1182 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, lpcfw->lpszStyle, len);
1185 if (!CFn_WMInitDialog(hDlg, lParam, lpcfw))
1187 TRACE("CFn_WMInitDialog returned FALSE\n");
1188 return FALSE;
1190 if (CFn_HookCallChk32(lpcfw))
1191 return CallWindowProcA((WNDPROC)lpcfa->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1193 switch (uMsg)
1195 case WM_MEASUREITEM:
1196 return CFn_WMMeasureItem(hDlg,lParam);
1197 case WM_DRAWITEM:
1198 return CFn_WMDrawItem(lParam);
1199 case WM_COMMAND:
1200 return CFn_WMCommand(hDlg, wParam, lParam, lpcfw);
1201 case WM_DESTROY:
1202 return CFn_WMDestroy(hDlg, lpcfw);
1203 case WM_CHOOSEFONT_GETLOGFONT:
1205 LOGFONTA *logfont = (LOGFONTA *)lParam;
1206 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1207 memcpy( logfont, lpcfw->lpLogFont, FIELD_OFFSET( LOGFONTA, lfFaceName ));
1208 WideCharToMultiByte( CP_ACP, 0, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE,
1209 logfont->lfFaceName, LF_FACESIZE, NULL, NULL );
1210 break;
1212 case WM_PAINT:
1213 return CFn_WMPaint(hDlg, wParam, lParam, lpcfw);
1215 return res;
1218 /***********************************************************************
1219 * FormatCharDlgProcW [internal]
1221 static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1223 LPCHOOSEFONTW lpcf;
1224 INT_PTR res = FALSE;
1226 if (uMsg!=WM_INITDIALOG)
1228 lpcf= GetPropW(hDlg, strWineFontData);
1229 if (lpcf && CFn_HookCallChk32(lpcf))
1230 res=CallWindowProcW((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1231 if (res)
1232 return res;
1234 else
1236 lpcf=(LPCHOOSEFONTW)lParam;
1237 if (!CFn_WMInitDialog(hDlg, lParam, lpcf))
1239 TRACE("CFn_WMInitDialog returned FALSE\n");
1240 return FALSE;
1242 if (CFn_HookCallChk32(lpcf))
1243 return CallWindowProcW((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1245 switch (uMsg)
1247 case WM_MEASUREITEM:
1248 return CFn_WMMeasureItem(hDlg, lParam);
1249 case WM_DRAWITEM:
1250 return CFn_WMDrawItem(lParam);
1251 case WM_COMMAND:
1252 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1253 case WM_DESTROY:
1254 return TRUE;
1255 case WM_CHOOSEFONT_GETLOGFONT:
1256 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1257 memcpy( (LOGFONTW *)lParam, lpcf->lpLogFont, sizeof(LOGFONTW) );
1258 break;
1259 case WM_PAINT:
1260 return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1262 return res;