Correct the test for the ODS_SELECTED bit in the WM_DRAWITEM message
[wine.git] / dlls / commdlg / fontdlg.c
blob29e3915d837097d3259ada45572db37d81b403b2
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 "wine/winbase16.h"
33 #include "wine/winuser16.h"
34 #include "heap.h"
35 #include "commdlg.h"
36 #include "dlgs.h"
37 #include "wine/debug.h"
38 #include "cderr.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
42 #include "cdlg.h"
43 #include "fontdlg.h"
45 static HBITMAP hBitmapTT = 0;
48 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
49 LPARAM lParam);
50 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
51 LPARAM lParam);
52 BOOL16 CALLBACK FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
53 LPARAM lParam);
55 /* There is a table here of all charsets, and the sample text for each.
56 * There is a second table that translates a charset into an index into
57 * the first table.
60 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
63 static const WCHAR stWestern[]={'A','a','B','b','Y','y','Z','z',0}; /* Western and default */
64 static const WCHAR stSymbol[]={'S','y','m','b','o','l',0}; /* Symbol */
65 static const WCHAR stShiftJis[]={'A','a',0x3042,0x3041,0x30a2,0x30a1,0x4e9c,0x5b87,0}; /* Shift JIS */
66 static const WCHAR stHangul[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Hangul */
67 static const WCHAR stGB2312[]={0x5fae,0x8f6f,0x4e2d,0x6587,0x8f6f,0x4ef6,0}; /* GB2312 */
68 static const WCHAR stBIG5[]={0x4e2d,0x6587,0x5b57,0x578b,0x7bc4,0x4f8b,0}; /* BIG5 */
69 static const WCHAR stGreek[]={'A','a','B','b',0x0391,0x03b1,0x0392,0x03b2,0}; /* Greek */
70 static const WCHAR stTurkish[]={'A','a','B','b',0x011e,0x011f,0x015e,0x015f,0}; /* Turkish */
71 static const WCHAR stHebrew[]={'A','a','B','b',0x05e0,0x05e1,0x05e9,0x05ea,0}; /* Hebrew */
72 static const WCHAR stArabic[]={'A','a','B','b',0x0627,0x0628,0x062c,0x062f,0x0647,0x0648,0x0632,0};/* Arabic */
73 static const WCHAR stBaltic[]={'A','a','B','b','Y','y','Z','z',0}; /* Baltic */
74 static const WCHAR stVietname[]={'A','a','B','b',0x01a0,0x01a1,0x01af,0x01b0,0}; /* Vietnamese */
75 static const WCHAR stCyrillic[]={'A','a','B','b',0x0411,0x0431,0x0424,0x0444,0}; /* Cyrillic */
76 static const WCHAR stEastEur[]={'A','a','B','b',0xc1,0xe1,0xd4,0xf4,0}; /* East European */
77 static const WCHAR stThai[]={'A','a','B','b',0x0e2d,0x0e31,0x0e01,0x0e29,0x0e23,0x0e44,0x0e17,0x0e22,0}; /* Thai */
78 static const WCHAR stJohab[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Johab */
79 static const WCHAR stMac[]={'A','a','B','b','Y','y','Z','z',0}; /* Mac */
80 static const WCHAR stOEM[]={'A','a','B','b',0xf8,0xf1,0xfd,0}; /* OEM */
81 /* the following character sets actually behave different (Win2K observation):
82 * the sample string is 'sticky': it uses the sample string of the previous
83 * selected character set. That behaviour looks like some default, which is
84 * not (yet) implemented. */
85 static const WCHAR stVISCII[]={'A','a','B','b',0}; /* VISCII */
86 static const WCHAR stTCVN[]={'A','a','B','b',0}; /* TCVN */
87 static const WCHAR stKOI8[]={'A','a','B','b',0}; /* KOI-8 */
88 static const WCHAR stIso88593[]={'A','a','B','b',0}; /* ISO-8859-3 */
89 static const WCHAR stIso88594[]={'A','a','B','b',0}; /* ISO-8859-4 */
90 static const WCHAR stIso885910[]={'A','a','B','b',0}; /* ISO-8859-10 */
91 static const WCHAR stCeltic[]={'A','a','B','b',0};/* Celtic */
93 static const WCHAR *sample_lang_text[]={
94 stWestern,stSymbol,stShiftJis,stHangul,stGB2312,
95 stBIG5,stGreek,stTurkish,stHebrew,stArabic,
96 stBaltic,stVietname,stCyrillic,stEastEur,stThai,
97 stJohab,stMac,stOEM,stVISCII,stTCVN,
98 stKOI8,stIso88593,stIso88594,stIso885910,stCeltic};
101 static const int CHARSET_ORDER[256]={
102 CI(ANSI), 0, CI(SYMBOL), 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, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0,
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 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, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
117 CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
120 struct {
121 int mask;
122 char *name;
123 } cfflags[] = {
124 #define XX(x) { x, #x },
125 XX(CF_SCREENFONTS)
126 XX(CF_PRINTERFONTS)
127 XX(CF_SHOWHELP)
128 XX(CF_ENABLEHOOK)
129 XX(CF_ENABLETEMPLATE)
130 XX(CF_ENABLETEMPLATEHANDLE)
131 XX(CF_INITTOLOGFONTSTRUCT)
132 XX(CF_USESTYLE)
133 XX(CF_EFFECTS)
134 XX(CF_APPLY)
135 XX(CF_ANSIONLY)
136 XX(CF_NOVECTORFONTS)
137 XX(CF_NOSIMULATIONS)
138 XX(CF_LIMITSIZE)
139 XX(CF_FIXEDPITCHONLY)
140 XX(CF_WYSIWYG)
141 XX(CF_FORCEFONTEXIST)
142 XX(CF_SCALABLEONLY)
143 XX(CF_TTONLY)
144 XX(CF_NOFACESEL)
145 XX(CF_NOSTYLESEL)
146 XX(CF_NOSIZESEL)
147 XX(CF_SELECTSCRIPT)
148 XX(CF_NOSCRIPTSEL)
149 XX(CF_NOVERTFONTS)
150 #undef XX
151 {0,NULL},
154 void _dump_cf_flags(DWORD cflags)
156 int i;
158 for (i=0;cfflags[i].name;i++)
159 if (cfflags[i].mask & cflags)
160 MESSAGE("%s|",cfflags[i].name);
161 MESSAGE("\n");
164 /***********************************************************************
165 * ChooseFontA (COMDLG32.@)
167 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
169 LPCVOID template;
170 HRSRC hResInfo;
171 HINSTANCE hDlginst;
172 HGLOBAL hDlgTmpl;
174 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
176 template=(LPCVOID)lpChFont->hInstance;
177 } else
179 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
181 hDlginst=lpChFont->hInstance;
182 if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
183 (LPSTR)RT_DIALOG)))
185 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
186 return FALSE;
188 } else
190 hDlginst=COMDLG32_hInstance;
191 if (!(hResInfo = FindResourceA(hDlginst, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
193 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
194 return FALSE;
197 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
198 !(template = LockResource( hDlgTmpl )))
200 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
201 return FALSE;
204 if (TRACE_ON(commdlg))
205 _dump_cf_flags(lpChFont->Flags);
207 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
208 FIXME(": unimplemented flag (ignored)\n");
210 return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
211 lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
214 /***********************************************************************
215 * ChooseFontW (COMDLG32.@)
217 * NOTES:
219 * The LOGFONT conversion functions will break if the structure ever
220 * grows beyond the lfFaceName element.
222 * The CHOOSEFONT conversion functions assume that both versions of
223 * lpLogFont and lpszStyle (if used) point to pre-allocated objects.
225 * The ASCII version of lpTemplateName is created by ChooseFontAtoW
226 * and freed by ChooseFontWtoA.
228 inline static VOID LogFontWtoA(const LOGFONTW *lfw, LOGFONTA *lfa)
230 memcpy(lfa, lfw, sizeof(LOGFONTA));
231 WideCharToMultiByte(CP_ACP, 0, lfw->lfFaceName, -1, lfa->lfFaceName,
232 LF_FACESIZE, NULL, NULL);
233 lfa->lfFaceName[LF_FACESIZE - 1] = '\0';
236 inline static VOID LogFontAtoW(const LOGFONTA *lfa, LOGFONTW *lfw)
238 memcpy(lfw, lfa, sizeof(LOGFONTA));
239 MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw->lfFaceName,
240 LF_FACESIZE);
241 lfw->lfFaceName[LF_FACESIZE - 1] = 0;
244 static BOOL ChooseFontWtoA(const CHOOSEFONTW *cfw, CHOOSEFONTA *cfa)
246 LOGFONTA *lpLogFont = cfa->lpLogFont;
247 LPSTR lpszStyle = cfa->lpszStyle;
249 memcpy(cfa, cfw, sizeof(CHOOSEFONTA));
250 cfa->lpLogFont = lpLogFont;
251 cfa->lpszStyle = lpszStyle;
253 LogFontWtoA(cfw->lpLogFont, lpLogFont);
255 if ((cfw->Flags&CF_ENABLETEMPLATE)!=0 && HIWORD(cfw->lpTemplateName)!=0)
257 cfa->lpTemplateName = HEAP_strdupWtoA(GetProcessHeap(), 0,
258 cfw->lpTemplateName);
259 if (cfa->lpTemplateName == NULL)
260 return FALSE;
263 if ((cfw->Flags & CF_USESTYLE) != 0 && cfw->lpszStyle != NULL)
265 WideCharToMultiByte(CP_ACP, 0, cfw->lpszStyle, -1, cfa->lpszStyle,
266 LF_FACESIZE, NULL, NULL);
267 cfa->lpszStyle[LF_FACESIZE - 1] = '\0';
270 return TRUE;
273 static VOID ChooseFontAtoW(const CHOOSEFONTA *cfa, CHOOSEFONTW *cfw)
275 LOGFONTW *lpLogFont = cfw->lpLogFont;
276 LPWSTR lpszStyle = cfw->lpszStyle;
277 LPCWSTR lpTemplateName = cfw->lpTemplateName;
279 memcpy(cfw, cfa, sizeof(CHOOSEFONTA));
280 cfw->lpLogFont = lpLogFont;
281 cfw->lpszStyle = lpszStyle;
282 cfw->lpTemplateName = lpTemplateName;
284 LogFontAtoW(cfa->lpLogFont, lpLogFont);
286 if ((cfa->Flags&CF_ENABLETEMPLATE)!=0 && HIWORD(cfa->lpTemplateName) != 0)
287 HeapFree(GetProcessHeap(), 0, (LPSTR)(cfa->lpTemplateName));
289 if ((cfa->Flags & CF_USESTYLE) != 0 && cfa->lpszStyle != NULL)
291 MultiByteToWideChar(CP_ACP, 0, cfa->lpszStyle, -1, cfw->lpszStyle,
292 LF_FACESIZE);
293 cfw->lpszStyle[LF_FACESIZE - 1] = 0;
297 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
299 CHOOSEFONTA cf_a;
300 LOGFONTA lf_a;
301 CHAR style_a[LF_FACESIZE];
303 cf_a.lpLogFont = &lf_a;
304 cf_a.lpszStyle = style_a;
306 if (ChooseFontWtoA(lpChFont, &cf_a) == FALSE)
308 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
309 return FALSE;
312 if (ChooseFontA(&cf_a) == FALSE)
314 if (cf_a.lpTemplateName != NULL)
315 HeapFree(GetProcessHeap(), 0, (LPSTR)(cf_a.lpTemplateName));
316 return FALSE;
319 ChooseFontAtoW(&cf_a, lpChFont);
321 return TRUE;
324 #if 0
325 /***********************************************************************
326 * ChooseFontW (COMDLG32.@)
328 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
330 BOOL bRet=FALSE;
331 CHOOSEFONTA cf32a;
332 LOGFONTA lf32a;
333 LPCVOID template;
334 HANDLE hResInfo, hDlgTmpl;
336 if (TRACE_ON(commdlg))
337 _dump_cf_flags(lpChFont->Flags);
339 if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
341 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
342 return FALSE;
344 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
345 !(template = LockResource( hDlgTmpl )))
347 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
348 return FALSE;
351 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
352 CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
353 memcpy(&cf32a, lpChFont, sizeof(cf32a));
354 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
356 WideCharToMultiByte( CP_ACP, 0, lpChFont->lpLogFont->lfFaceName, -1,
357 lf32a.lfFaceName, LF_FACESIZE, NULL, NULL );
358 lf32a.lfFaceName[LF_FACESIZE-1] = 0;
359 cf32a.lpLogFont=&lf32a;
360 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
361 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
362 bRet = DialogBoxIndirectParamW(COMDLG32_hInstance, template,
363 lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
364 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
365 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
366 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
367 MultiByteToWideChar( CP_ACP, 0, lf32a.lfFaceName, -1,
368 lpChFont->lpLogFont->lfFaceName, LF_FACESIZE );
369 lpChFont->lpLogFont->lfFaceName[LF_FACESIZE-1] = 0;
370 return bRet;
372 #endif
374 #define TEXT_EXTRAS 4
375 #define TEXT_COLORS 16
377 static const COLORREF textcolors[TEXT_COLORS]=
379 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
380 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
381 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
382 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
385 /***********************************************************************
386 * CFn_HookCallChk32 [internal]
388 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
390 if (lpcf)
391 if(lpcf->Flags & CF_ENABLEHOOK)
392 if (lpcf->lpfnHook)
393 return TRUE;
394 return FALSE;
397 /*************************************************************************
398 * AddFontFamily [internal]
400 INT AddFontFamily(const LOGFONTA *lplf, UINT nFontType,
401 LPCHOOSEFONTA lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
403 int i;
404 WORD w;
406 TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
408 if (lpcf->Flags & CF_FIXEDPITCHONLY)
409 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
410 return 1;
411 if (lpcf->Flags & CF_ANSIONLY)
412 if (lplf->lfCharSet != ANSI_CHARSET)
413 return 1;
414 if (lpcf->Flags & CF_TTONLY)
415 if (!(nFontType & TRUETYPE_FONTTYPE))
416 return 1;
418 if (e) e->added++;
420 i=SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
421 if (i == CB_ERR) {
422 i = SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
423 if( i != CB_ERR) {
424 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
425 /* store some important font information */
426 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
429 return 1;
432 /*************************************************************************
433 * FontFamilyEnumProc32 [internal]
435 static INT WINAPI FontFamilyEnumProc(const LOGFONTA *lpLogFont,
436 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam)
438 LPCFn_ENUMSTRUCT e;
439 e=(LPCFn_ENUMSTRUCT)lParam;
440 return AddFontFamily(lpLogFont, dwFontType, e->lpcf32a, e->hWnd1, e);
443 /*************************************************************************
444 * SetFontStylesToCombo2 [internal]
446 * Fill font style information into combobox (without using font.c directly)
448 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTA *lplf)
450 #define FSTYLES 4
451 struct FONTSTYLE
453 int italic;
454 int weight;
455 char stname[20];
457 static struct FONTSTYLE fontstyles[FSTYLES]={
458 { 0,FW_NORMAL,"Regular"}, { 1,FW_NORMAL,"Italic"},
459 { 0,FW_BOLD,"Bold"}, { 1,FW_BOLD,"Bold Italic"}
461 HFONT hf;
462 TEXTMETRICA tm;
463 int i,j;
464 LOGFONTA lf;
466 memcpy(&lf, lplf, sizeof(LOGFONTA));
468 for (i=0;i<FSTYLES;i++)
470 lf.lfItalic=fontstyles[i].italic;
471 lf.lfWeight=fontstyles[i].weight;
472 hf=CreateFontIndirectA(&lf);
473 hf=SelectObject(hdc,hf);
474 GetTextMetricsA(hdc,&tm);
475 hf=SelectObject(hdc,hf);
476 DeleteObject(hf);
477 /* font successful created ? */
478 if (tm.tmWeight==fontstyles[i].weight &&
479 ((tm.tmItalic != 0)==fontstyles[i].italic))
481 j=SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
482 if (j==CB_ERR) return 1;
483 j=SendMessageA(hwnd, CB_SETITEMDATA, j,
484 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
485 if (j==CB_ERR) return 1;
488 return 0;
491 /*************************************************************************
492 * AddFontSizeToCombo3 [internal]
494 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
496 int j;
497 char buffer[20];
499 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
500 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
502 sprintf(buffer, "%2d", h);
503 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
504 if (j==CB_ERR)
506 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
507 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
508 if (j==CB_ERR) return 1;
511 return 0;
514 /*************************************************************************
515 * SetFontSizesToCombo3 [internal]
517 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
519 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
520 int i;
522 for (i=0; sizes[i]; i++)
523 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
524 return 0;
527 /***********************************************************************
528 * AddFontStyle [internal]
530 INT AddFontStyle( const ENUMLOGFONTEXA *lpElfex, UINT nFontType,
531 LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg,
532 BOOL iswin16)
534 int i;
535 const LOGFONTA *lplf = &(lpElfex->elfLogFont);
536 HWND hcmb5;
538 TRACE("(nFontType=%d)\n",nFontType);
539 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
540 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
541 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
542 lplf->lfEscapement,lplf->lfOrientation,
543 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
544 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
545 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
546 if (nFontType & RASTER_FONTTYPE)
548 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
549 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
551 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
553 HDC hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
554 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
555 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
556 ReleaseDC(hDlg,hdc);
557 if (i)
558 return 0;
560 if( iswin16 || !( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
561 i = SendMessageA( hcmb5, CB_FINDSTRINGEXACT, 0,
562 (LPARAM)lpElfex->elfScript);
563 if( i == CB_ERR) {
564 i = SendMessageA( hcmb5, CB_ADDSTRING, 0,
565 (LPARAM)lpElfex->elfScript);
566 if( i != CB_ERR)
567 SendMessageA( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
569 return 1 ;
572 static INT CFn_FitFontSize( HWND hDlg, int points)
574 int i,n;
575 int ret = 0;
576 /* look for fitting font size in combobox3 */
577 n=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
578 for (i=0;i<n;i++)
580 if (points == (int)SendDlgItemMessageA
581 (hDlg,cmb3, CB_GETITEMDATA,i,0))
583 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
584 SendMessageA(hDlg, WM_COMMAND,
585 MAKEWPARAM(cmb3, CBN_SELCHANGE),
586 (LPARAM)GetDlgItem(hDlg,cmb3));
587 ret = 1;
588 break;
591 return ret;
594 static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
596 LONG id;
597 int i, ret = 0;
598 /* look for fitting font style in combobox2 */
599 for (i=0;i<TEXT_EXTRAS;i++)
601 id =SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
602 if (packedstyle == id)
604 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
605 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
606 (LPARAM)GetDlgItem(hDlg,cmb2));
607 ret = 1;
608 break;
611 return ret;
615 static INT CFn_FitCharSet( HWND hDlg, int charset )
617 int i,n,cs;
618 /* look for fitting char set in combobox5 */
619 n=SendDlgItemMessageA(hDlg, cmb5, CB_GETCOUNT, 0, 0);
620 for (i=0;i<n;i++)
622 cs =SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, i, 0);
623 if (charset == cs)
625 SendDlgItemMessageA(hDlg, cmb5, CB_SETCURSEL, i, 0);
626 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
627 (LPARAM)GetDlgItem(hDlg,cmb2));
628 return 1;
631 /* no charset fits: select the first one in the list */
632 SendDlgItemMessageA(hDlg, cmb5, CB_SETCURSEL, 0, 0);
633 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
634 (LPARAM)GetDlgItem(hDlg,cmb2));
635 return 0;
638 /***********************************************************************
639 * FontStyleEnumProc32 [internal]
641 static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXA *lpElfex,
642 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam )
644 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
645 HWND hcmb2=s->hWnd1;
646 HWND hcmb3=s->hWnd2;
647 HWND hDlg=GetParent(hcmb3);
648 return AddFontStyle( lpElfex, dwFontType, s->lpcf32a,
649 hcmb2, hcmb3, hDlg, FALSE);
652 /***********************************************************************
653 * CFn_WMInitDialog [internal]
655 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
656 LPCHOOSEFONTA lpcf)
658 HDC hdc;
659 int i,j,init=0;
660 long pstyle;
661 LPLOGFONTA lpxx;
662 HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
664 SetWindowLongA(hDlg, DWL_USER, lParam);
665 lpxx=lpcf->lpLogFont;
666 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
668 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
670 ERR("structure size failure !!!\n");
671 EndDialog (hDlg, 0);
672 return FALSE;
674 if (!hBitmapTT)
675 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
677 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
678 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
679 if (!(lpcf->Flags & CF_APPLY))
680 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
681 if (lpcf->Flags & CF_EFFECTS)
683 for (i=0;i<TEXT_COLORS;i++)
685 char name[30];
687 if( LoadStringA(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
688 sizeof(name)/sizeof(*name) )==0 )
690 strcpy( name, "[color name]" );
692 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
693 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
694 /* look for a fitting value in color combobox */
695 if (textcolors[j]==lpcf->rgbColors)
696 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
699 else
701 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
702 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
703 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
704 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
705 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
707 hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
708 if (hdc)
710 CFn_ENUMSTRUCT s;
711 s.hWnd1=GetDlgItem(hDlg,cmb1);
712 s.lpcf32a=lpcf;
713 do {
714 s.added = 0;
715 if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s)) {
716 TRACE("EnumFontFamilies returns 0\n");
717 break;
719 if (s.added) break;
720 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
721 FIXME("No font found with fixed pitch only, dropping flag.\n");
722 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
723 continue;
725 if (lpcf->Flags & CF_TTONLY) {
726 FIXME("No font found with truetype only, dropping flag.\n");
727 lpcf->Flags &= ~CF_TTONLY;
728 continue;
730 break;
731 } while (1);
734 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
736 /* look for fitting font name in combobox1 */
737 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
738 if (j!=CB_ERR)
740 INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
741 lpxx->lfHeight;
742 int charset = lpxx->lfCharSet;
743 pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
744 FW_NORMAL,lpxx->lfItalic !=0);
745 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
746 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
747 (LPARAM)GetDlgItem(hDlg,cmb1));
748 init=1;
749 /* look for fitting font style in combobox2 */
750 CFn_FitFontStyle(hDlg, pstyle);
751 /* look for fitting font size in combobox3 */
752 CFn_FitFontSize(hDlg, height);
753 CFn_FitCharSet( hDlg, charset );
756 if (!init)
758 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
759 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
760 (LPARAM)GetDlgItem(hDlg,cmb1));
762 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
764 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
765 if (j!=CB_ERR)
767 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
768 SendMessageA(hDlg,WM_COMMAND,cmb2,
769 MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
773 else
775 WARN("HDC failure !!!\n");
776 EndDialog (hDlg, 0);
777 return FALSE;
780 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
781 ReleaseDC(hDlg,hdc);
782 SetCursor(hcursor);
783 return TRUE;
787 /***********************************************************************
788 * CFn_WMMeasureItem [internal]
790 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
792 BITMAP bm;
793 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
794 if (!hBitmapTT)
795 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
796 GetObjectA( hBitmapTT, sizeof(bm), &bm );
797 lpmi->itemHeight=bm.bmHeight;
798 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
799 return 0;
803 /***********************************************************************
804 * CFn_WMDrawItem [internal]
806 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
808 HBRUSH hBrush;
809 char buffer[40];
810 BITMAP bm;
811 COLORREF cr, oldText=0, oldBk=0;
812 RECT rect;
813 #if 0
814 HDC hMemDC;
815 int nFontType;
816 HBITMAP hBitmap; /* for later TT usage */
817 #endif
818 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
820 if (lpdi->itemID == (UINT)-1) /* got no items */
821 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
822 else
824 if (lpdi->CtlType == ODT_COMBOBOX)
826 if (lpdi->itemState & ODS_SELECTED)
828 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
829 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
830 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
831 } else
833 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
834 SelectObject(lpdi->hDC, hBrush);
836 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
838 else
839 return TRUE; /* this should never happen */
841 rect=lpdi->rcItem;
842 switch (lpdi->CtlID)
844 case cmb1:
845 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
846 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
847 (LPARAM)buffer);
848 GetObjectA( hBitmapTT, sizeof(bm), &bm );
849 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
850 lpdi->rcItem.top, buffer, strlen(buffer));
851 #if 0
852 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
853 /* FIXME: draw bitmap if truetype usage */
854 if (nFontType&TRUETYPE_FONTTYPE)
856 hMemDC = CreateCompatibleDC(lpdi->hDC);
857 hBitmap = SelectObject(hMemDC, hBitmapTT);
858 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
859 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
860 SelectObject(hMemDC, hBitmap);
861 DeleteDC(hMemDC);
863 #endif
864 break;
865 case cmb2:
866 case cmb3:
867 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
868 case cmb5:
869 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
870 (LPARAM)buffer);
871 TextOutA(lpdi->hDC, lpdi->rcItem.left,
872 lpdi->rcItem.top, buffer, strlen(buffer));
873 break;
875 case cmb4:
876 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
877 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
878 (LPARAM)buffer);
879 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
880 lpdi->rcItem.top, buffer, strlen(buffer));
881 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
882 hBrush = CreateSolidBrush(cr);
883 if (hBrush)
885 hBrush = SelectObject (lpdi->hDC, hBrush) ;
886 rect.right=rect.left+25;
887 rect.top++;
888 rect.left+=5;
889 rect.bottom--;
890 Rectangle( lpdi->hDC, rect.left, rect.top,
891 rect.right, rect.bottom );
892 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
894 rect=lpdi->rcItem;
895 rect.left+=25+5;
896 break;
898 default:
899 return TRUE; /* this should never happen */
901 if (lpdi->itemState & ODS_SELECTED)
903 SetTextColor(lpdi->hDC, oldText);
904 SetBkColor(lpdi->hDC, oldBk);
907 return TRUE;
910 /***********************************************************************
911 * CFn_WMCommand [internal]
913 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
914 LPCHOOSEFONTA lpcf)
916 int i,j;
917 long l;
918 HDC hdc;
919 LPLOGFONTA lpxx=lpcf->lpLogFont;
921 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
922 switch (LOWORD(wParam))
924 case cmb1:
925 if (HIWORD(wParam)==CBN_SELCHANGE)
927 hdc=((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
928 if (hdc)
930 INT pointsize; /* save current pointsize */
931 LONG pstyle; /* save current style */
932 int charset;
933 int idx;
934 idx = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
935 pointsize = (int)SendDlgItemMessageA( hDlg, cmb3, CB_GETITEMDATA,
936 idx, 0);
937 idx = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
938 pstyle = SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
939 idx = SendDlgItemMessageA(hDlg, cmb5, CB_GETCURSEL, 0, 0);
940 charset = SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, idx, 0);
942 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
943 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
944 SendDlgItemMessageA(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
945 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL, 0, 0);
946 if (i!=CB_ERR)
948 HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
949 CFn_ENUMSTRUCT s;
950 LOGFONTA enumlf;
951 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
952 (LPARAM)enumlf.lfFaceName);
953 TRACE("WM_COMMAND/cmb1 =>%s\n",enumlf.lfFaceName);
954 s.hWnd1=GetDlgItem(hDlg, cmb2);
955 s.hWnd2=GetDlgItem(hDlg, cmb3);
956 s.lpcf32a=lpcf;
957 enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
958 enumlf.lfPitchAndFamily = 0;
959 EnumFontFamiliesExA(hdc, &enumlf,
960 (FONTENUMPROCA)FontStyleEnumProc, (LPARAM)&s, 0);
961 CFn_FitFontStyle(hDlg, pstyle);
962 if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
963 if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
964 SetCursor(hcursor);
966 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
967 ReleaseDC(hDlg,hdc);
969 else
971 WARN("HDC failure !!!\n");
972 EndDialog (hDlg, 0);
973 return TRUE;
976 case chx1:
977 case chx2:
978 case cmb2:
979 case cmb3:
980 case cmb5:
981 if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
983 char str[256];
984 WINDOWINFO wininfo;
986 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
987 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
988 if (i==CB_ERR)
989 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
990 else
992 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
993 (LPARAM)str);
994 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
995 j=HIWORD(l);
996 lpcf->nFontType = LOWORD(l);
997 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
998 /* same value reported to the EnumFonts
999 call back with the extra FONTTYPE_... bits added */
1000 lpxx->lfPitchAndFamily=j&0xff;
1001 lpxx->lfCharSet=j>>8;
1003 strcpy(lpxx->lfFaceName,str);
1004 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1005 if (i!=CB_ERR)
1007 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
1008 if (0!=(lpxx->lfItalic=HIWORD(l)))
1009 lpcf->nFontType |= ITALIC_FONTTYPE;
1010 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
1011 lpcf->nFontType |= BOLD_FONTTYPE;
1013 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1014 if (i!=CB_ERR)
1015 lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
1016 else
1017 lpxx->lfHeight=0;
1018 i=SendDlgItemMessageA(hDlg, cmb5, CB_GETCURSEL, 0, 0);
1019 if (i!=CB_ERR)
1020 lpxx->lfCharSet=SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, i, 0);
1021 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
1022 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
1023 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
1024 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
1025 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
1026 lpxx->lfQuality=DEFAULT_QUALITY;
1027 lpcf->iPointSize= -10*lpxx->lfHeight;
1029 wininfo.cbSize=sizeof(wininfo);
1031 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
1033 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
1034 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
1037 break;
1039 case cmb4:
1040 i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
1041 if (i!=CB_ERR)
1043 WINDOWINFO wininfo;
1045 lpcf->rgbColors=textcolors[i];
1046 wininfo.cbSize=sizeof(wininfo);
1048 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
1050 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
1051 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
1054 break;
1056 case psh15:
1057 i=RegisterWindowMessageA( HELPMSGSTRINGA );
1058 if (lpcf->hwndOwner)
1059 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
1060 /* if (CFn_HookCallChk(lpcf))
1061 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
1062 break;
1064 case IDOK:
1065 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1066 ( (lpcf->Flags & CF_LIMITSIZE) &&
1067 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
1068 (-lpxx->lfHeight <= lpcf->nSizeMax)))
1069 EndDialog(hDlg, TRUE);
1070 else
1072 char buffer[80];
1073 sprintf(buffer,"Select a font size between %d and %d points.",
1074 lpcf->nSizeMin,lpcf->nSizeMax);
1075 MessageBoxA(hDlg, buffer, NULL, MB_OK);
1077 return(TRUE);
1078 case IDCANCEL:
1079 EndDialog(hDlg, FALSE);
1080 return(TRUE);
1082 return(FALSE);
1085 LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1087 return TRUE;
1090 LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam,
1091 LPCHOOSEFONTA lpcf )
1093 WINDOWINFO info;
1095 info.cbSize=sizeof(info);
1097 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
1099 PAINTSTRUCT ps;
1100 HDC hdc;
1101 HPEN hOrigPen;
1102 HFONT hOrigFont;
1103 COLORREF rgbPrev;
1104 LOGFONTA lf = *(lpcf->lpLogFont);
1106 MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1107 hdc=BeginPaint( hDlg, &ps );
1109 /* Paint frame */
1110 MoveToEx( hdc, info.rcWindow.left, info.rcWindow.bottom, NULL );
1111 hOrigPen=SelectObject( hdc, CreatePen( PS_SOLID, 2,
1112 GetSysColor( COLOR_3DSHADOW ) ));
1113 LineTo( hdc, info.rcWindow.left, info.rcWindow.top );
1114 LineTo( hdc, info.rcWindow.right, info.rcWindow.top );
1115 DeleteObject(SelectObject( hdc, CreatePen( PS_SOLID, 2,
1116 GetSysColor( COLOR_3DLIGHT ) )));
1117 LineTo( hdc, info.rcWindow.right, info.rcWindow.bottom );
1118 LineTo( hdc, info.rcWindow.left, info.rcWindow.bottom );
1119 DeleteObject(SelectObject( hdc, hOrigPen ));
1121 /* Draw the sample text itself */
1122 info.rcWindow.right--;
1123 info.rcWindow.bottom--;
1124 info.rcWindow.top++;
1125 info.rcWindow.left++;
1126 lf.lfHeight = MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1127 hOrigFont = SelectObject( hdc, CreateFontIndirectA( &lf ) );
1128 rgbPrev=SetTextColor( hdc, lpcf->rgbColors );
1130 DrawTextW( hdc,
1131 sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]],
1132 -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1134 EndPaint( hDlg, &ps );
1137 return FALSE;
1140 /***********************************************************************
1141 * FormatCharDlgProcA [internal]
1143 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1144 LPARAM lParam)
1146 LPCHOOSEFONTA lpcf;
1147 INT_PTR res = FALSE;
1148 if (uMsg!=WM_INITDIALOG)
1150 lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);
1151 if (!lpcf && uMsg != WM_MEASUREITEM)
1152 return FALSE;
1153 if (CFn_HookCallChk32(lpcf))
1154 res=CallWindowProcA((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1155 if (res)
1156 return res;
1158 else
1160 lpcf=(LPCHOOSEFONTA)lParam;
1161 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
1163 TRACE("CFn_WMInitDialog returned FALSE\n");
1164 return FALSE;
1166 if (CFn_HookCallChk32(lpcf))
1167 return CallWindowProcA((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1169 switch (uMsg)
1171 case WM_MEASUREITEM:
1172 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1173 case WM_DRAWITEM:
1174 return CFn_WMDrawItem(hDlg, wParam, lParam);
1175 case WM_COMMAND:
1176 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1177 case WM_DESTROY:
1178 return CFn_WMDestroy(hDlg, wParam, lParam);
1179 case WM_CHOOSEFONT_GETLOGFONT:
1180 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1181 lParam);
1182 FIXME("current logfont back to caller\n");
1183 break;
1184 case WM_PAINT:
1185 return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1187 return res;
1190 /***********************************************************************
1191 * FormatCharDlgProcW [internal]
1193 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1194 LPARAM lParam)
1196 LPCHOOSEFONTW lpcf32w;
1197 LPCHOOSEFONTA lpcf32a;
1198 INT_PTR res = FALSE;
1199 if (uMsg!=WM_INITDIALOG)
1201 lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);
1202 if (!lpcf32w)
1203 return FALSE;
1204 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1205 res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
1206 if (res)
1207 return res;
1209 else
1211 lpcf32w=(LPCHOOSEFONTW)lParam;
1212 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1213 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
1215 TRACE("CFn_WMInitDialog returned FALSE\n");
1216 return FALSE;
1218 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1219 return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1221 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1222 switch (uMsg)
1224 case WM_MEASUREITEM:
1225 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1226 case WM_DRAWITEM:
1227 return CFn_WMDrawItem(hDlg, wParam, lParam);
1228 case WM_COMMAND:
1229 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
1230 case WM_DESTROY:
1231 return CFn_WMDestroy(hDlg, wParam, lParam);
1232 case WM_CHOOSEFONT_GETLOGFONT:
1233 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1234 lParam);
1235 FIXME("current logfont back to caller\n");
1236 break;
1238 return res;