Added some defines concerning SChannel CSPs.
[wine/multimedia.git] / dlls / commdlg / fontdlg.c
blobcec484f553044f1c1c11ab00cf0f21cfa080d6fd
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
37 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
39 static const WCHAR strWineFontData[] = {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A',0};
40 static const WCHAR strWineFontData_a[] =
41 {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A','_','A',0};
42 static const WCHAR chooseFontW[] = {'C','H','O','O','S','E','_','F','O','N','T',0};
44 #include "cdlg.h"
46 /* image list with TrueType bitmaps and more */
47 static HIMAGELIST himlTT = 0;
48 #define TTBITMAP_XSIZE 20 /* x-size of the bitmaps */
50 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
51 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
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
55 * the first table.
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 {
119 DWORD mask;
120 const char *name;
121 } cfflags[] = {
122 #define XX(x) { x, #x },
123 XX(CF_SCREENFONTS)
124 XX(CF_PRINTERFONTS)
125 XX(CF_SHOWHELP)
126 XX(CF_ENABLEHOOK)
127 XX(CF_ENABLETEMPLATE)
128 XX(CF_ENABLETEMPLATEHANDLE)
129 XX(CF_INITTOLOGFONTSTRUCT)
130 XX(CF_USESTYLE)
131 XX(CF_EFFECTS)
132 XX(CF_APPLY)
133 XX(CF_ANSIONLY)
134 XX(CF_NOVECTORFONTS)
135 XX(CF_NOSIMULATIONS)
136 XX(CF_LIMITSIZE)
137 XX(CF_FIXEDPITCHONLY)
138 XX(CF_WYSIWYG)
139 XX(CF_FORCEFONTEXIST)
140 XX(CF_SCALABLEONLY)
141 XX(CF_TTONLY)
142 XX(CF_NOFACESEL)
143 XX(CF_NOSTYLESEL)
144 XX(CF_NOSIZESEL)
145 XX(CF_SELECTSCRIPT)
146 XX(CF_NOSCRIPTSEL)
147 XX(CF_NOVERTFONTS)
148 #undef XX
151 void _dump_cf_flags(DWORD cflags)
153 int i;
155 for (i = 0; i < sizeof(cfflags)/sizeof(cfflags[0]); i++)
156 if (cfflags[i].mask & cflags)
157 TRACE("%s|",cfflags[i].name);
158 TRACE("\n");
161 /***********************************************************************
162 * ChooseFontW (COMDLG32.@)
164 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
166 LPCVOID template;
167 HRSRC hResInfo;
168 HINSTANCE hDlginst;
169 HGLOBAL hDlgTmpl;
171 TRACE("(%p)\n", lpChFont);
173 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
175 template=(LPCVOID)lpChFont->hInstance;
176 } else
178 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
180 hDlginst=lpChFont->hInstance;
181 if( !(hResInfo = FindResourceW(hDlginst, lpChFont->lpTemplateName,
182 (LPWSTR)RT_DIALOG)))
184 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
185 return FALSE;
187 } else
189 hDlginst=COMDLG32_hInstance;
190 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
192 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
193 return FALSE;
196 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
197 !(template = LockResource( hDlgTmpl )))
199 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
200 return FALSE;
203 if (TRACE_ON(commdlg))
204 _dump_cf_flags(lpChFont->Flags);
206 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
207 FIXME(": unimplemented flag (ignored)\n");
209 return DialogBoxIndirectParamW(COMDLG32_hInstance, template,
210 lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
213 /***********************************************************************
214 * ChooseFontA (COMDLG32.@)
216 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
218 LPCVOID template;
219 HRSRC hResInfo;
220 HINSTANCE hDlginst;
221 HGLOBAL hDlgTmpl;
223 TRACE("(%p)\n", lpChFont);
225 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
227 template=(LPCVOID)lpChFont->hInstance;
228 } else
230 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
232 hDlginst=lpChFont->hInstance;
233 if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
234 (LPSTR)RT_DIALOG)))
236 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
237 return FALSE;
239 } else
241 hDlginst=COMDLG32_hInstance;
242 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
244 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
245 return FALSE;
248 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
249 !(template = LockResource( hDlgTmpl )))
251 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
252 return FALSE;
255 if (TRACE_ON(commdlg))
256 _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 );
264 #define TEXT_EXTRAS 4
265 #define TEXT_COLORS 16
267 static const COLORREF textcolors[TEXT_COLORS]=
269 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
270 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
271 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
272 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
275 /***********************************************************************
276 * CFn_HookCallChk32 [internal]
278 static BOOL CFn_HookCallChk32(LPCHOOSEFONTW lpcf)
280 if (lpcf)
281 if(lpcf->Flags & CF_ENABLEHOOK)
282 if (lpcf->lpfnHook)
283 return TRUE;
284 return FALSE;
287 /*************************************************************************
288 * AddFontFamily [internal]
290 INT AddFontFamily(const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
291 UINT nFontType, LPCHOOSEFONTW lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
293 int i;
294 WORD w;
295 const LOGFONTW *lplf = &(lpElfex->elfLogFont);
297 TRACE("font=%s (nFontType=%d)\n", debugstr_w(lplf->lfFaceName), nFontType);
299 if (lpcf->Flags & CF_FIXEDPITCHONLY)
300 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
301 return 1;
302 if (lpcf->Flags & CF_ANSIONLY)
303 if (lplf->lfCharSet != ANSI_CHARSET)
304 return 1;
305 if (lpcf->Flags & CF_TTONLY)
306 if (!(nFontType & TRUETYPE_FONTTYPE))
307 return 1;
309 if (e) e->added++;
311 i=SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
312 if (i == CB_ERR) {
313 i = SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
314 if( i != CB_ERR) {
315 /* store some important font information */
316 w = (lplf->lfPitchAndFamily) << 8 |
317 (HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
318 SendMessageW(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
321 return 1;
324 /*************************************************************************
325 * FontFamilyEnumProc32 [internal]
327 static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXW *lpElfex,
328 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam)
330 LPCFn_ENUMSTRUCT e;
331 e=(LPCFn_ENUMSTRUCT)lParam;
332 return AddFontFamily( lpElfex, (NEWTEXTMETRICEXW *) metrics,
333 dwFontType, e->lpcf32w, e->hWnd1, e);
336 /*************************************************************************
337 * SetFontStylesToCombo2 [internal]
339 * Fill font style information into combobox (without using font.c directly)
341 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf)
343 #define FSTYLES 4
344 struct FONTSTYLE
346 int italic;
347 int weight;
348 const WCHAR *stname;
350 static const WCHAR strRegular[] = {'R','e','g','u','l','a','r',0};
351 static const WCHAR strItalic[] = {'I','t','a','l','i','c',0};
352 static const WCHAR strBold[] = {'B','o','l','d',0};
353 static const WCHAR strBoldItalic[] = {'B','o','l','d',' ','I','t','a','l','i','c',0};
354 static const struct FONTSTYLE fontstyles[FSTYLES]={
355 { 0, FW_NORMAL, strRegular },
356 { 1, FW_NORMAL, strItalic },
357 { 0, FW_BOLD, strBold },
358 { 1, FW_BOLD, strBoldItalic }
360 HFONT hf;
361 TEXTMETRICW tm;
362 int i,j;
363 LOGFONTW lf;
365 memcpy(&lf, lplf, sizeof(LOGFONTW));
367 for (i=0;i<FSTYLES;i++)
369 lf.lfItalic=fontstyles[i].italic;
370 lf.lfWeight=fontstyles[i].weight;
371 hf=CreateFontIndirectW(&lf);
372 hf=SelectObject(hdc,hf);
373 GetTextMetricsW(hdc,&tm);
374 hf=SelectObject(hdc,hf);
375 DeleteObject(hf);
376 /* font successful created ? */
377 if (tm.tmWeight==fontstyles[i].weight &&
378 ((tm.tmItalic != 0)==fontstyles[i].italic))
380 j=SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
381 if (j==CB_ERR) return 1;
382 j=SendMessageW(hwnd, CB_SETITEMDATA, j,
383 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
384 if (j==CB_ERR) return 1;
387 return 0;
390 /*************************************************************************
391 * AddFontSizeToCombo3 [internal]
393 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTW lpcf)
395 int j;
396 char buffer[20];
398 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
399 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
401 sprintf(buffer, "%2d", h);
402 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
403 if (j==CB_ERR)
405 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
406 if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
407 if (j==CB_ERR) return 1;
410 return 0;
413 /*************************************************************************
414 * SetFontSizesToCombo3 [internal]
416 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTW lpcf)
418 static const BYTE sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
419 int i;
421 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
422 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
423 return 0;
426 /*************************************************************************
427 * CFn_GetDC [internal]
429 inline HDC CFn_GetDC(LPCHOOSEFONTW lpcf)
431 HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
432 lpcf->hDC :
433 GetDC(0);
434 if(!ret) ERR("HDC failure!!!\n");
435 return ret;
438 /*************************************************************************
439 * CFn_ReleaseDC [internal]
441 inline void CFn_ReleaseDC(LPCHOOSEFONTW lpcf, HDC hdc)
443 if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
444 ReleaseDC(0, hdc);
447 /***********************************************************************
448 * AddFontStyle [internal]
450 INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
451 UINT nFontType, LPCHOOSEFONTW lpcf, HWND hcmb2, HWND hcmb3,
452 HWND hDlg, BOOL iswin16)
454 int i;
455 const LOGFONTW *lplf = &(lpElfex->elfLogFont);
456 HWND hcmb5;
457 HDC hdc;
459 TRACE("(nFontType=%d)\n",nFontType);
460 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
461 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
462 debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
463 lplf->lfEscapement,lplf->lfOrientation,
464 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
465 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
466 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
467 if (nFontType & RASTER_FONTTYPE)
469 INT points;
470 if(!(hdc = CFn_GetDC(lpcf))) return 0;
471 points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
472 72, GetDeviceCaps(hdc, LOGPIXELSY));
473 CFn_ReleaseDC(lpcf, hdc);
474 i = AddFontSizeToCombo3(hcmb3, points, lpcf);
475 if(i) return 0;
476 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
478 if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
480 if(!(hdc = CFn_GetDC(lpcf))) return 0;
481 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
482 CFn_ReleaseDC(lpcf, hdc);
483 if (i)
484 return 0;
486 if( iswin16 || !( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
487 i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
488 (LPARAM)lpElfex->elfScript);
489 if( i == CB_ERR) {
490 i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
491 (LPARAM)lpElfex->elfScript);
492 if( i != CB_ERR)
493 SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
495 return 1 ;
498 static INT CFn_FitFontSize( HWND hDlg, int points)
500 int i,n;
501 int ret = 0;
502 /* look for fitting font size in combobox3 */
503 n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
504 for (i=0;i<n;i++)
506 if (points == (int)SendDlgItemMessageW
507 (hDlg,cmb3, CB_GETITEMDATA,i,0))
509 SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0);
510 SendMessageW(hDlg, WM_COMMAND,
511 MAKEWPARAM(cmb3, CBN_SELCHANGE),
512 (LPARAM)GetDlgItem(hDlg,cmb3));
513 ret = 1;
514 break;
517 return ret;
520 static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
522 LONG id;
523 int i, ret = 0;
524 /* look for fitting font style in combobox2 */
525 for (i=0;i<TEXT_EXTRAS;i++)
527 id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
528 if (packedstyle == id)
530 SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
531 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
532 (LPARAM)GetDlgItem(hDlg,cmb2));
533 ret = 1;
534 break;
537 return ret;
541 static INT CFn_FitCharSet( HWND hDlg, int charset )
543 int i,n,cs;
544 /* look for fitting char set in combobox5 */
545 n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0);
546 for (i=0;i<n;i++)
548 cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
549 if (charset == cs)
551 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0);
552 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
553 (LPARAM)GetDlgItem(hDlg,cmb2));
554 return 1;
557 /* no charset fits: select the first one in the list */
558 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0);
559 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
560 (LPARAM)GetDlgItem(hDlg,cmb2));
561 return 0;
564 /***********************************************************************
565 * FontStyleEnumProc32 [internal]
567 static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
568 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
570 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
571 HWND hcmb2=s->hWnd1;
572 HWND hcmb3=s->hWnd2;
573 HWND hDlg=GetParent(hcmb3);
574 return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
575 dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg, FALSE);
578 /***********************************************************************
579 * CFn_WMInitDialog [internal]
581 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
582 LPCHOOSEFONTW lpcf)
584 HDC hdc;
585 int i,j,init=0;
586 long pstyle;
587 CFn_ENUMSTRUCT s;
588 LPLOGFONTW lpxx;
589 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
590 static const WCHAR strColorName[] = {'[','c','o','l','o','r',' ','n','a','m','e',']',0};
592 SetPropW(hDlg, strWineFontData, (HANDLE)lParam);
593 lpxx=lpcf->lpLogFont;
594 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
596 if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
598 ERR("structure size failure !!!\n");
599 EndDialog (hDlg, 0);
600 return FALSE;
602 if (!himlTT)
603 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
604 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
606 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
607 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
608 if (!(lpcf->Flags & CF_APPLY))
609 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
610 if (lpcf->Flags & CF_EFFECTS)
612 for (i=0;i<TEXT_COLORS;i++)
614 WCHAR name[30];
616 if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
617 sizeof(name)/sizeof(*name) )==0 )
619 memcpy(name, strColorName, sizeof(strColorName));
621 j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
622 SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[j]);
623 /* look for a fitting value in color combobox */
624 if (textcolors[j]==lpcf->rgbColors)
625 SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0);
628 else
630 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
631 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
632 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
633 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
634 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
636 if(!(hdc = CFn_GetDC(lpcf)))
638 EndDialog (hDlg, 0);
639 return FALSE;
641 s.hWnd1=GetDlgItem(hDlg,cmb1);
642 s.lpcf32w=lpcf;
643 do {
644 LOGFONTW elf;
645 s.added = 0;
646 elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
647 elf.lfPitchAndFamily = 0;
648 elf.lfFaceName[0] = '\0'; /* enum all fonts */
649 if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0))
651 TRACE("EnumFontFamiliesEx returns 0\n");
652 break;
654 if (s.added) break;
655 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
656 FIXME("No font found with fixed pitch only, dropping flag.\n");
657 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
658 continue;
660 if (lpcf->Flags & CF_TTONLY) {
661 FIXME("No font found with truetype only, dropping flag.\n");
662 lpcf->Flags &= ~CF_TTONLY;
663 continue;
665 break;
666 } while (1);
669 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
671 /* look for fitting font name in combobox1 */
672 j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
673 if (j!=CB_ERR)
675 INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
676 lpxx->lfHeight;
677 INT points;
678 int charset = lpxx->lfCharSet;
679 points = MulDiv( height, 72, GetDeviceCaps(hdc, LOGPIXELSY));
680 pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
681 FW_NORMAL,lpxx->lfItalic !=0);
682 SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0);
683 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
684 (LPARAM)GetDlgItem(hDlg,cmb1));
685 init=1;
686 /* look for fitting font style in combobox2 */
687 CFn_FitFontStyle(hDlg, pstyle);
688 /* look for fitting font size in combobox3 */
689 CFn_FitFontSize(hDlg, points);
690 CFn_FitCharSet( hDlg, charset );
693 if (!init)
695 SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0);
696 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
697 (LPARAM)GetDlgItem(hDlg,cmb1));
699 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
701 j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
702 if (j!=CB_ERR)
704 j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0);
705 SendMessageW(hDlg,WM_COMMAND,cmb2,
706 MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
709 CFn_ReleaseDC(lpcf, hdc);
710 SetCursor(hcursor);
711 return TRUE;
715 /***********************************************************************
716 * CFn_WMMeasureItem [internal]
718 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
720 HDC hdc;
721 HFONT hfontprev;
722 TEXTMETRICW tm;
723 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
724 if (!himlTT)
725 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
726 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
727 ImageList_GetIconSize( himlTT, 0, &lpmi->itemHeight);
728 lpmi->itemHeight += 2;
729 /* use MAX of bitmap height and tm.tmHeight .*/
730 hdc=GetDC(hDlg);
731 if(!hdc) return 0;
732 hfontprev = SelectObject( hdc, GetStockObject( SYSTEM_FONT));
733 GetTextMetricsW(hdc, &tm);
734 if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
735 SelectObject(hdc, hfontprev);
736 ReleaseDC(hDlg, hdc);
737 return 0;
741 /***********************************************************************
742 * CFn_WMDrawItem [internal]
744 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
746 HBRUSH hBrush;
747 WCHAR buffer[40];
748 COLORREF cr, oldText=0, oldBk=0;
749 RECT rect;
750 int nFontType;
751 int idx;
752 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
754 if (lpdi->itemID == (UINT)-1) /* got no items */
755 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
756 else
758 if (lpdi->CtlType == ODT_COMBOBOX)
760 if (lpdi->itemState & ODS_SELECTED)
762 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
763 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
764 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
765 } else
767 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
768 SelectObject(lpdi->hDC, hBrush);
770 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
772 else
773 return TRUE; /* this should never happen */
775 rect=lpdi->rcItem;
776 switch (lpdi->CtlID)
778 case cmb1:
779 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
780 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
781 (LPARAM)buffer);
782 TextOutW(lpdi->hDC, lpdi->rcItem.left + TTBITMAP_XSIZE + 10,
783 lpdi->rcItem.top, buffer, lstrlenW(buffer));
784 nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
785 idx = -1;
786 if (nFontType & TRUETYPE_FONTTYPE) {
787 idx = 0; /* picture: TT */
788 if( nFontType & NTM_TT_OPENTYPE)
789 idx = 2; /* picture: O */
790 } else if( nFontType & NTM_PS_OPENTYPE)
791 idx = 3; /* picture: O+ps */
792 else if( nFontType & NTM_TYPE1)
793 idx = 4; /* picture: a */
794 else if( nFontType & DEVICE_FONTTYPE)
795 idx = 1; /* picture: printer */
796 if( idx >= 0)
797 ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
798 lpdi->rcItem.top, ILD_TRANSPARENT);
799 break;
800 case cmb2:
801 case cmb3:
802 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
803 case cmb5:
804 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
805 (LPARAM)buffer);
806 TextOutW(lpdi->hDC, lpdi->rcItem.left,
807 lpdi->rcItem.top, buffer, lstrlenW(buffer));
808 break;
810 case cmb4:
811 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
812 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
813 (LPARAM)buffer);
814 TextOutW(lpdi->hDC, lpdi->rcItem.left + 25+5,
815 lpdi->rcItem.top, buffer, lstrlenW(buffer));
816 cr = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
817 hBrush = CreateSolidBrush(cr);
818 if (hBrush)
820 hBrush = SelectObject (lpdi->hDC, hBrush) ;
821 rect.right=rect.left+25;
822 rect.top++;
823 rect.left+=5;
824 rect.bottom--;
825 Rectangle( lpdi->hDC, rect.left, rect.top,
826 rect.right, rect.bottom );
827 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
829 rect=lpdi->rcItem;
830 rect.left+=25+5;
831 break;
833 default:
834 return TRUE; /* this should never happen */
836 if (lpdi->itemState & ODS_SELECTED)
838 SetTextColor(lpdi->hDC, oldText);
839 SetBkColor(lpdi->hDC, oldBk);
842 return TRUE;
845 /***********************************************************************
846 * CFn_WMCommand [internal]
848 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
849 LPCHOOSEFONTW lpcf)
851 int i;
852 long l;
853 HDC hdc;
854 LPLOGFONTW lpxx=lpcf->lpLogFont;
856 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
857 switch (LOWORD(wParam))
859 case cmb1:
860 if (HIWORD(wParam)==CBN_SELCHANGE)
862 INT pointsize; /* save current pointsize */
863 LONG pstyle; /* save current style */
864 int charset;
865 int idx;
866 if(!(hdc = CFn_GetDC(lpcf)))
868 EndDialog (hDlg, 0);
869 return TRUE;
871 idx = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
872 pointsize = (int)SendDlgItemMessageW( hDlg, cmb3, CB_GETITEMDATA,
873 idx, 0);
874 idx = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
875 pstyle = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
876 idx = SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
877 charset = SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, idx, 0);
879 SendDlgItemMessageW(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
880 SendDlgItemMessageW(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
881 SendDlgItemMessageW(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
882 i=SendDlgItemMessageW(hDlg, cmb1, CB_GETCURSEL, 0, 0);
883 if (i!=CB_ERR)
885 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
886 CFn_ENUMSTRUCT s;
887 LOGFONTW enumlf;
888 SendDlgItemMessageW(hDlg, cmb1, CB_GETLBTEXT, i,
889 (LPARAM)enumlf.lfFaceName);
890 TRACE("WM_COMMAND/cmb1 =>%s\n", debugstr_w(enumlf.lfFaceName));
891 s.hWnd1=GetDlgItem(hDlg, cmb2);
892 s.hWnd2=GetDlgItem(hDlg, cmb3);
893 s.lpcf32w=lpcf;
894 enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
895 enumlf.lfPitchAndFamily = 0;
896 EnumFontFamiliesExW(hdc, &enumlf,
897 (FONTENUMPROCW)FontStyleEnumProc, (LPARAM)&s, 0);
898 CFn_FitFontStyle(hDlg, pstyle);
899 if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
900 if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
901 SetCursor(hcursor);
903 CFn_ReleaseDC(lpcf, hdc);
905 case chx1:
906 case chx2:
907 case cmb2:
908 case cmb3:
909 case cmb5:
910 if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
912 WCHAR str[256];
913 WINDOWINFO wininfo;
915 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
916 i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0);
917 if (i==CB_ERR)
918 i=GetDlgItemTextW( hDlg, cmb1, str, 256 );
919 else
921 SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i,
922 (LPARAM)str);
923 l=SendDlgItemMessageW(hDlg,cmb1,CB_GETITEMDATA,i,0);
924 lpcf->nFontType = LOWORD(l);
925 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
926 /* same value reported to the EnumFonts
927 call back with the extra FONTTYPE_... bits added */
928 lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
930 lstrcpyW(lpxx->lfFaceName,str);
931 i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
932 if (i!=CB_ERR)
934 l=SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
935 if (0!=(lpxx->lfItalic=HIWORD(l)))
936 lpcf->nFontType |= ITALIC_FONTTYPE;
937 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
938 lpcf->nFontType |= BOLD_FONTTYPE;
940 i=SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
941 if( i != CB_ERR)
942 lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageW(hDlg, cmb3,
943 CB_GETITEMDATA , i, 0));
944 else
945 lpcf->iPointSize = 100;
946 hdc = CFn_GetDC(lpcf);
947 if( hdc)
949 lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
950 GetDeviceCaps(hdc, LOGPIXELSY), 720);
951 CFn_ReleaseDC(lpcf, hdc);
952 } else
953 lpxx->lfHeight = -lpcf->iPointSize / 10;
954 i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
955 if (i!=CB_ERR)
956 lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
957 else
958 lpxx->lfCharSet = DEFAULT_CHARSET;
959 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
960 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
961 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
962 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
963 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
964 lpxx->lfQuality=DEFAULT_QUALITY;
966 wininfo.cbSize=sizeof(wininfo);
968 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
970 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
971 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
974 break;
976 case cmb4:
977 i=SendDlgItemMessageW(hDlg, cmb4, CB_GETCURSEL, 0, 0);
978 if (i!=CB_ERR)
980 WINDOWINFO wininfo;
982 lpcf->rgbColors=textcolors[i];
983 wininfo.cbSize=sizeof(wininfo);
985 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
987 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
988 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
991 break;
993 case psh15:
994 i=RegisterWindowMessageW( HELPMSGSTRINGW );
995 if (lpcf->hwndOwner)
996 SendMessageW(lpcf->hwndOwner, i, 0, (LPARAM)GetPropW(hDlg, strWineFontData));
997 /* if (CFn_HookCallChk(lpcf))
998 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
999 break;
1001 case IDOK:
1002 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1003 ( (lpcf->Flags & CF_LIMITSIZE) &&
1004 (lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
1005 (lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
1006 EndDialog(hDlg, TRUE);
1007 else
1009 char buffer[80];
1010 sprintf(buffer,"Select a font size between %d and %d points.",
1011 lpcf->nSizeMin,lpcf->nSizeMax);
1012 MessageBoxA(hDlg, buffer, NULL, MB_OK);
1014 return(TRUE);
1015 case IDCANCEL:
1016 EndDialog(hDlg, FALSE);
1017 return(TRUE);
1019 return(FALSE);
1022 LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcfw)
1024 LPCHOOSEFONTA lpcfa;
1025 LPCSTR lpTemplateName;
1026 LPSTR lpszStyle;
1027 LPLOGFONTA lpLogFonta;
1028 int len;
1030 lpcfa = GetPropW(hwnd, strWineFontData_a);
1031 lpLogFonta = lpcfa->lpLogFont;
1032 lpTemplateName = lpcfa->lpTemplateName;
1033 lpszStyle = lpcfa->lpszStyle;
1034 memcpy(lpcfa, lpcfw, sizeof(CHOOSEFONTA));
1035 lpcfa->lpLogFont = lpLogFonta;
1036 lpcfa->lpTemplateName = lpTemplateName;
1037 lpcfa->lpszStyle = lpszStyle;
1038 memcpy(lpcfa->lpLogFont, lpcfw->lpLogFont, sizeof(LOGFONTA));
1039 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpLogFont->lfFaceName,
1040 LF_FACESIZE, lpcfa->lpLogFont->lfFaceName, LF_FACESIZE, 0, 0);
1042 if(lpcfw->lpszStyle) {
1043 len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, -1, 0, 0);
1044 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, lpcfa->lpszStyle, len, 0, 0);
1045 HeapFree(GetProcessHeap(), 0, lpcfw->lpszStyle);
1048 HeapFree(GetProcessHeap(), 0, (LPBYTE)lpcfw->lpTemplateName);
1049 HeapFree(GetProcessHeap(), 0, lpcfw->lpLogFont);
1050 HeapFree(GetProcessHeap(), 0, lpcfw);
1052 return TRUE;
1055 LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcf)
1057 WINDOWINFO info;
1059 info.cbSize=sizeof(info);
1060 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
1062 PAINTSTRUCT ps;
1063 HDC hdc;
1064 HPEN hOrigPen;
1065 HFONT hOrigFont;
1066 COLORREF rgbPrev;
1067 LOGFONTW lf = *(lpcf->lpLogFont);
1069 MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1070 hdc = BeginPaint( hDlg, &ps );
1072 TRACE("erase %d, rect=(%ld,%ld)-(%ld,%ld)\n", ps.fErase,
1073 ps.rcPaint.left, ps.rcPaint.top,
1074 ps.rcPaint.right, ps.rcPaint.bottom);
1076 /* Paint frame */
1077 MoveToEx( hdc, info.rcWindow.left, info.rcWindow.bottom, NULL );
1078 hOrigPen=SelectObject( hdc, CreatePen( PS_SOLID, 2,
1079 GetSysColor( COLOR_3DSHADOW ) ));
1080 LineTo( hdc, info.rcWindow.left, info.rcWindow.top );
1081 LineTo( hdc, info.rcWindow.right, info.rcWindow.top );
1082 DeleteObject(SelectObject( hdc, CreatePen( PS_SOLID, 2,
1083 GetSysColor( COLOR_3DLIGHT ) )));
1084 LineTo( hdc, info.rcWindow.right, info.rcWindow.bottom );
1085 LineTo( hdc, info.rcWindow.left, info.rcWindow.bottom );
1086 DeleteObject(SelectObject( hdc, hOrigPen ));
1088 /* Draw the sample text itself */
1089 info.rcWindow.right--;
1090 info.rcWindow.bottom--;
1091 info.rcWindow.top++;
1092 info.rcWindow.left++;
1093 hOrigFont = SelectObject( hdc, CreateFontIndirectW( &lf ) );
1094 rgbPrev=SetTextColor( hdc, lpcf->rgbColors );
1096 DrawTextW( hdc,
1097 sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]],
1098 -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1100 DeleteObject(SelectObject( hdc, hOrigFont ));
1101 EndPaint( hDlg, &ps );
1103 return FALSE;
1106 /***********************************************************************
1107 * FormatCharDlgProcA [internal]
1109 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1110 LPARAM lParam)
1112 LPCHOOSEFONTW lpcfw;
1113 LPCHOOSEFONTA lpcfa;
1114 INT_PTR res = FALSE;
1115 int len;
1117 if (uMsg!=WM_INITDIALOG) {
1118 lpcfw = (LPCHOOSEFONTW)GetPropW(hDlg, strWineFontData);
1119 if (!lpcfw)
1120 return FALSE;
1121 if (CFn_HookCallChk32(lpcfw))
1122 res=CallWindowProcA((WNDPROC)lpcfw->lpfnHook, hDlg, uMsg, wParam, lParam);
1123 if (res)
1124 return res;
1125 } else {
1126 lpcfa=(LPCHOOSEFONTA)lParam;
1127 SetPropW(hDlg, strWineFontData_a, (HANDLE)lParam);
1129 lpcfw = HeapAlloc(GetProcessHeap(), 0, sizeof(CHOOSEFONTW));
1130 memcpy(lpcfw, lpcfa, sizeof(CHOOSEFONTA));
1131 lpcfw->lpLogFont = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGFONTW));
1132 memcpy(lpcfw->lpLogFont, lpcfa->lpLogFont, sizeof(LOGFONTA));
1133 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpLogFont->lfFaceName,
1134 LF_FACESIZE, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE);
1136 if(lpcfa->lpszStyle) {
1137 len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, NULL, 0);
1138 lpcfw->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1139 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, lpcfw->lpszStyle, len);
1142 if(lpcfa->lpTemplateName) {
1143 len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpTemplateName, -1, NULL, 0);
1144 lpcfw->lpTemplateName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1145 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpTemplateName,
1146 -1, (LPWSTR)lpcfw->lpTemplateName, len);
1149 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcfw))
1151 TRACE("CFn_WMInitDialog returned FALSE\n");
1152 return FALSE;
1154 if (CFn_HookCallChk32(lpcfw))
1155 return CallWindowProcA((WNDPROC)lpcfa->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1157 switch (uMsg)
1159 case WM_MEASUREITEM:
1160 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1161 case WM_DRAWITEM:
1162 return CFn_WMDrawItem(hDlg, wParam, lParam);
1163 case WM_COMMAND:
1164 return CFn_WMCommand(hDlg, wParam, lParam, lpcfw);
1165 case WM_DESTROY:
1166 return CFn_WMDestroy(hDlg, wParam, lParam, lpcfw);
1167 case WM_CHOOSEFONT_GETLOGFONT:
1168 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1169 FIXME("current logfont back to caller\n");
1170 break;
1171 case WM_PAINT:
1172 return CFn_WMPaint(hDlg, wParam, lParam, lpcfw);
1174 return res;
1177 /***********************************************************************
1178 * FormatCharDlgProcW [internal]
1180 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1181 LPARAM lParam)
1183 LPCHOOSEFONTW lpcf;
1184 INT_PTR res = FALSE;
1186 if (uMsg!=WM_INITDIALOG)
1188 lpcf=(LPCHOOSEFONTW)GetPropW(hDlg, strWineFontData);
1189 if (!lpcf)
1190 return FALSE;
1191 if (CFn_HookCallChk32(lpcf))
1192 res=CallWindowProcW((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1193 if (res)
1194 return res;
1196 else
1198 lpcf=(LPCHOOSEFONTW)lParam;
1199 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
1201 TRACE("CFn_WMInitDialog returned FALSE\n");
1202 return FALSE;
1204 if (CFn_HookCallChk32(lpcf))
1205 return CallWindowProcW((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1207 switch (uMsg)
1209 case WM_MEASUREITEM:
1210 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1211 case WM_DRAWITEM:
1212 return CFn_WMDrawItem(hDlg, wParam, lParam);
1213 case WM_COMMAND:
1214 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1215 case WM_DESTROY:
1216 return TRUE;
1217 case WM_CHOOSEFONT_GETLOGFONT:
1218 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1219 FIXME("current logfont back to caller\n");
1220 break;
1221 case WM_PAINT:
1222 return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1224 return res;