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
30 #include "wine/winbase16.h"
31 #include "wine/winuser16.h"
35 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
43 static HBITMAP hBitmapTT = 0;
46 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
48 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
50 BOOL16 CALLBACK FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
53 /* There is a table here of all charsets, and the sample text for each.
54 * There is a second table that translates a charset into an index into
58 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
59 #define SAMPLE_EXTLEN 10
61 static const WCHAR SAMPLE_LANG_TEXT[][SAMPLE_EXTLEN]={
62 {'Y','y','Z','z',0}, /* Western and default */
70 {0x05e0, 0x05e1, 0x05e9, 0x05ea, 0}, /* Hebrew */
75 {0}, /* East European */
85 {0}, /* ISO-8859-10 */
89 static const int CHARSET_ORDER[256]={
90 CI(ANSI), 0, CI(SYMBOL), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0,
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
105 CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
112 #define XX(x) { x, #x },
117 XX(CF_ENABLETEMPLATE)
118 XX(CF_ENABLETEMPLATEHANDLE)
119 XX(CF_INITTOLOGFONTSTRUCT)
127 XX(CF_FIXEDPITCHONLY)
129 XX(CF_FORCEFONTEXIST)
142 void _dump_cf_flags(DWORD cflags)
146 for (i=0;cfflags[i].name;i++)
147 if (cfflags[i].mask & cflags)
148 MESSAGE("%s|",cfflags[i].name);
152 /***********************************************************************
153 * ChooseFontA (COMDLG32.@)
155 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
162 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
164 template=(LPCVOID)lpChFont->hInstance;
167 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
169 hDlginst=lpChFont->hInstance;
170 if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
173 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
178 hDlginst=COMDLG32_hInstance;
179 if (!(hResInfo = FindResourceA(hDlginst, "CHOOSE_FONT", RT_DIALOGA)))
181 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
185 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
186 !(template = LockResource( hDlgTmpl )))
188 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
192 if (TRACE_ON(commdlg))
193 _dump_cf_flags(lpChFont->Flags);
195 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS ))
196 FIXME(": unimplemented flag (ignored)\n");
198 return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
199 lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
202 /***********************************************************************
203 * ChooseFontW (COMDLG32.@)
207 * The LOGFONT conversion functions will break if the structure ever
208 * grows beyond the lfFaceName element.
210 * The CHOOSEFONT conversion functions assume that both versions of
211 * lpLogFont and lpszStyle (if used) point to pre-allocated objects.
213 * The ASCII version of lpTemplateName is created by ChooseFontAtoW
214 * and freed by ChooseFontWtoA.
216 inline static VOID LogFontWtoA(const LOGFONTW *lfw, LOGFONTA *lfa)
218 memcpy(lfa, lfw, sizeof(LOGFONTA));
219 WideCharToMultiByte(CP_ACP, 0, lfw->lfFaceName, -1, lfa->lfFaceName,
220 LF_FACESIZE, NULL, NULL);
221 lfa->lfFaceName[LF_FACESIZE - 1] = '\0';
224 inline static VOID LogFontAtoW(const LOGFONTA *lfa, LOGFONTW *lfw)
226 memcpy(lfw, lfa, sizeof(LOGFONTA));
227 MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw->lfFaceName,
229 lfw->lfFaceName[LF_FACESIZE - 1] = 0;
232 static BOOL ChooseFontWtoA(const CHOOSEFONTW *cfw, CHOOSEFONTA *cfa)
234 LOGFONTA *lpLogFont = cfa->lpLogFont;
235 LPSTR lpszStyle = cfa->lpszStyle;
237 memcpy(cfa, cfw, sizeof(CHOOSEFONTA));
238 cfa->lpLogFont = lpLogFont;
239 cfa->lpszStyle = lpszStyle;
241 LogFontWtoA(cfw->lpLogFont, lpLogFont);
243 if ((cfw->Flags&CF_ENABLETEMPLATE)!=0 && HIWORD(cfw->lpTemplateName)!=0)
245 cfa->lpTemplateName = HEAP_strdupWtoA(GetProcessHeap(), 0,
246 cfw->lpTemplateName);
247 if (cfa->lpTemplateName == NULL)
251 if ((cfw->Flags & CF_USESTYLE) != 0 && cfw->lpszStyle != NULL)
253 WideCharToMultiByte(CP_ACP, 0, cfw->lpszStyle, -1, cfa->lpszStyle,
254 LF_FACESIZE, NULL, NULL);
255 cfa->lpszStyle[LF_FACESIZE - 1] = '\0';
261 static VOID ChooseFontAtoW(const CHOOSEFONTA *cfa, CHOOSEFONTW *cfw)
263 LOGFONTW *lpLogFont = cfw->lpLogFont;
264 LPWSTR lpszStyle = cfw->lpszStyle;
265 LPCWSTR lpTemplateName = cfw->lpTemplateName;
267 memcpy(cfw, cfa, sizeof(CHOOSEFONTA));
268 cfw->lpLogFont = lpLogFont;
269 cfw->lpszStyle = lpszStyle;
270 cfw->lpTemplateName = lpTemplateName;
272 LogFontAtoW(cfa->lpLogFont, lpLogFont);
274 if ((cfa->Flags&CF_ENABLETEMPLATE)!=0 && HIWORD(cfa->lpTemplateName) != 0)
275 HeapFree(GetProcessHeap(), 0, (LPSTR)(cfa->lpTemplateName));
277 if ((cfa->Flags & CF_USESTYLE) != 0 && cfa->lpszStyle != NULL)
279 MultiByteToWideChar(CP_ACP, 0, cfa->lpszStyle, -1, cfw->lpszStyle,
281 cfw->lpszStyle[LF_FACESIZE - 1] = 0;
285 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
289 CHAR style_a[LF_FACESIZE];
291 cf_a.lpLogFont = &lf_a;
292 cf_a.lpszStyle = style_a;
294 if (ChooseFontWtoA(lpChFont, &cf_a) == FALSE)
296 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
300 if (ChooseFontA(&cf_a) == FALSE)
302 if (cf_a.lpTemplateName != NULL)
303 HeapFree(GetProcessHeap(), 0, (LPSTR)(cf_a.lpTemplateName));
307 ChooseFontAtoW(&cf_a, lpChFont);
313 /***********************************************************************
314 * ChooseFontW (COMDLG32.@)
316 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
322 HANDLE hResInfo, hDlgTmpl;
324 if (TRACE_ON(commdlg))
325 _dump_cf_flags(lpChFont->Flags);
327 if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_FONT", RT_DIALOGA)))
329 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
332 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
333 !(template = LockResource( hDlgTmpl )))
335 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
339 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
340 CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
341 memcpy(&cf32a, lpChFont, sizeof(cf32a));
342 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
344 WideCharToMultiByte( CP_ACP, 0, lpChFont->lpLogFont->lfFaceName, -1,
345 lf32a.lfFaceName, LF_FACESIZE, NULL, NULL );
346 lf32a.lfFaceName[LF_FACESIZE-1] = 0;
347 cf32a.lpLogFont=&lf32a;
348 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
349 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
350 bRet = DialogBoxIndirectParamW(COMDLG32_hInstance, template,
351 lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
352 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
353 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
354 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
355 MultiByteToWideChar( CP_ACP, 0, lf32a.lfFaceName, -1,
356 lpChFont->lpLogFont->lfFaceName, LF_FACESIZE );
357 lpChFont->lpLogFont->lfFaceName[LF_FACESIZE-1] = 0;
362 #define TEXT_EXTRAS 4
363 #define TEXT_COLORS 16
365 static const COLORREF textcolors[TEXT_COLORS]=
367 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
368 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
369 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
370 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
373 /***********************************************************************
374 * CFn_HookCallChk32 [internal]
376 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
379 if(lpcf->Flags & CF_ENABLEHOOK)
385 /*************************************************************************
386 * AddFontFamily [internal]
388 INT AddFontFamily(const LOGFONTA *lplf, UINT nFontType,
389 LPCHOOSEFONTA lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
394 TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
396 if (lpcf->Flags & CF_FIXEDPITCHONLY)
397 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
399 if (lpcf->Flags & CF_ANSIONLY)
400 if (lplf->lfCharSet != ANSI_CHARSET)
402 if (lpcf->Flags & CF_TTONLY)
403 if (!(nFontType & TRUETYPE_FONTTYPE))
408 i=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
411 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
412 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
413 return 1 ; /* store some important font information */
419 /*************************************************************************
420 * FontFamilyEnumProc32 [internal]
422 static INT WINAPI FontFamilyEnumProc(const LOGFONTA *lpLogFont,
423 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam)
426 e=(LPCFn_ENUMSTRUCT)lParam;
427 return AddFontFamily(lpLogFont, dwFontType, e->lpcf32a, e->hWnd1, e);
430 /*************************************************************************
431 * SetFontStylesToCombo2 [internal]
433 * Fill font style information into combobox (without using font.c directly)
435 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTA *lplf)
442 static struct FONTSTYLE fontstyles[FSTYLES]={
443 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
444 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
450 memcpy(&lf, lplf, sizeof(LOGFONTA));
452 for (i=0;i<FSTYLES;i++)
454 lf.lfItalic=fontstyles[i].italic;
455 lf.lfWeight=fontstyles[i].weight;
456 hf=CreateFontIndirectA(&lf);
457 hf=SelectObject(hdc,hf);
458 GetTextMetricsA(hdc,&tm);
459 hf=SelectObject(hdc,hf);
462 if (tm.tmWeight==fontstyles[i].weight &&
463 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
465 j=SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
466 if (j==CB_ERR) return 1;
467 j=SendMessageA(hwnd, CB_SETITEMDATA, j,
468 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
469 if (j==CB_ERR) return 1;
475 /*************************************************************************
476 * AddFontSizeToCombo3 [internal]
478 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
483 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
484 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
486 sprintf(buffer, "%2d", h);
487 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
490 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
491 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
492 if (j==CB_ERR) return 1;
498 /*************************************************************************
499 * SetFontSizesToCombo3 [internal]
501 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
503 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
506 for (i=0; sizes[i]; i++)
507 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
511 /***********************************************************************
512 * AddFontStyle [internal]
514 INT AddFontStyle(const LOGFONTA *lplf, UINT nFontType,
515 LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
519 TRACE("(nFontType=%d)\n",nFontType);
520 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
521 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
522 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
523 lplf->lfEscapement,lplf->lfOrientation,
524 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
525 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
526 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
527 if (nFontType & RASTER_FONTTYPE)
529 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
530 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
532 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
534 HDC hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
535 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
536 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
545 /***********************************************************************
546 * FontStyleEnumProc32 [internal]
548 static INT WINAPI FontStyleEnumProc( const LOGFONTA *lpFont,
549 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam )
551 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
554 HWND hDlg=GetParent(hcmb3);
555 return AddFontStyle(lpFont, dwFontType, s->lpcf32a, hcmb2,
559 /***********************************************************************
560 * CFn_WMInitDialog [internal]
562 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
569 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
571 SetWindowLongA(hDlg, DWL_USER, lParam);
572 lpxx=lpcf->lpLogFont;
573 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
575 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
577 ERR("structure size failure !!!\n");
582 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
584 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
585 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
586 if (!(lpcf->Flags & CF_APPLY))
587 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
588 if (lpcf->Flags & CF_EFFECTS)
590 for (i=0;i<TEXT_COLORS;i++)
594 if( LoadStringA(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
595 sizeof(name)/sizeof(*name) )==0 )
597 strcpy( name, "[color name]" );
599 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
600 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
601 /* look for a fitting value in color combobox */
602 if (textcolors[j]==lpcf->rgbColors)
603 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
608 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
609 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
610 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
611 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
612 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
614 hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
618 s.hWnd1=GetDlgItem(hDlg,cmb1);
622 if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s)) {
623 TRACE("EnumFontFamilies returns 0\n");
627 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
628 FIXME("No font found with fixed pitch only, dropping flag.\n");
629 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
632 if (lpcf->Flags & CF_TTONLY) {
633 FIXME("No font found with truetype only, dropping flag.\n");
634 lpcf->Flags &= ~CF_TTONLY;
641 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
643 /* look for fitting font name in combobox1 */
644 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
647 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
648 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
649 (LPARAM)GetDlgItem(hDlg,cmb1));
651 /* look for fitting font style in combobox2 */
652 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
653 for (i=0;i<TEXT_EXTRAS;i++)
655 if (l==SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0))
656 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
659 /* look for fitting font size in combobox3 */
660 j=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
663 if (lpxx->lfHeight==(int)SendDlgItemMessageA(hDlg,cmb3, CB_GETITEMDATA,i,0))
664 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
670 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
671 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
672 (LPARAM)GetDlgItem(hDlg,cmb1));
674 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
676 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
679 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
680 SendMessageA(hDlg,WM_COMMAND,cmb2,
681 MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
687 WARN("HDC failure !!!\n");
692 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
699 /***********************************************************************
700 * CFn_WMMeasureItem [internal]
702 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
705 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
707 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
708 GetObjectA( hBitmapTT, sizeof(bm), &bm );
709 lpmi->itemHeight=bm.bmHeight;
710 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
715 /***********************************************************************
716 * CFn_WMDrawItem [internal]
718 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
723 COLORREF cr, oldText=0, oldBk=0;
728 HBITMAP hBitmap; /* for later TT usage */
730 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
732 if (lpdi->itemID == (UINT)-1) /* got no items */
733 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
736 if (lpdi->CtlType == ODT_COMBOBOX)
738 if (lpdi->itemState ==ODS_SELECTED)
740 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
741 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
742 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
745 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
746 SelectObject(lpdi->hDC, hBrush);
748 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
751 return TRUE; /* this should never happen */
756 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
757 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
759 GetObjectA( hBitmapTT, sizeof(bm), &bm );
760 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
761 lpdi->rcItem.top, buffer, strlen(buffer));
763 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
764 /* FIXME: draw bitmap if truetype usage */
765 if (nFontType&TRUETYPE_FONTTYPE)
767 hMemDC = CreateCompatibleDC(lpdi->hDC);
768 hBitmap = SelectObject(hMemDC, hBitmapTT);
769 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
770 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
771 SelectObject(hMemDC, hBitmap);
777 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
778 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
780 TextOutA(lpdi->hDC, lpdi->rcItem.left,
781 lpdi->rcItem.top, buffer, strlen(buffer));
784 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
785 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
787 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
788 lpdi->rcItem.top, buffer, strlen(buffer));
789 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
790 hBrush = CreateSolidBrush(cr);
793 hBrush = SelectObject (lpdi->hDC, hBrush) ;
794 rect.right=rect.left+25;
798 Rectangle( lpdi->hDC, rect.left, rect.top,
799 rect.right, rect.bottom );
800 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
806 default: return TRUE; /* this should never happen */
808 if (lpdi->itemState == ODS_SELECTED)
810 SetTextColor(lpdi->hDC, oldText);
811 SetBkColor(lpdi->hDC, oldBk);
817 /***********************************************************************
818 * CFn_WMCommand [internal]
820 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
826 LPLOGFONTA lpxx=lpcf->lpLogFont;
828 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
829 switch (LOWORD(wParam))
831 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
833 hdc=((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
836 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
837 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
838 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
841 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
844 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
846 TRACE("WM_COMMAND/cmb1 =>%s\n",str);
847 s.hWnd1=GetDlgItem(hDlg, cmb2);
848 s.hWnd2=GetDlgItem(hDlg, cmb3);
850 EnumFontFamiliesA(hdc, str, FontStyleEnumProc, (LPARAM)&s);
851 SendDlgItemMessageA(hDlg,cmb2, CB_SETCURSEL, 0, 0);
852 SendDlgItemMessageA(hDlg,cmb3, CB_SETCURSEL, 0, 0);
855 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
860 WARN("HDC failure !!!\n");
868 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
873 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
874 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
876 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
879 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
881 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
883 lpcf->nFontType = LOWORD(l);
884 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
885 /* same value reported to the EnumFonts
886 call back with the extra FONTTYPE_... bits added */
887 lpxx->lfPitchAndFamily=j&0xff;
888 lpxx->lfCharSet=j>>8;
890 strcpy(lpxx->lfFaceName,str);
891 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
894 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
895 if (0!=(lpxx->lfItalic=HIWORD(l)))
896 lpcf->nFontType |= ITALIC_FONTTYPE;
897 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
898 lpcf->nFontType |= BOLD_FONTTYPE;
900 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
902 lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
905 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
906 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
907 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
908 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
909 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
910 lpxx->lfQuality=DEFAULT_QUALITY;
911 lpcf->iPointSize= -10*lpxx->lfHeight;
913 wininfo.cbSize=sizeof(wininfo);
915 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
917 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
923 i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
928 lpcf->rgbColors=textcolors[i];
929 wininfo.cbSize=sizeof(wininfo);
931 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
933 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
938 case psh15:i=RegisterWindowMessageA( HELPMSGSTRINGA );
940 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
941 /* if (CFn_HookCallChk(lpcf))
942 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
945 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
946 ( (lpcf->Flags & CF_LIMITSIZE) &&
947 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
948 (-lpxx->lfHeight <= lpcf->nSizeMax)))
949 EndDialog(hDlg, TRUE);
953 sprintf(buffer,"Select a font size between %d and %d points.",
954 lpcf->nSizeMin,lpcf->nSizeMax);
955 MessageBoxA(hDlg, buffer, NULL, MB_OK);
958 case IDCANCEL:EndDialog(hDlg, FALSE);
964 LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
969 static LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam,
974 info.cbSize=sizeof(info);
976 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
983 WCHAR sample[SAMPLE_EXTLEN+5]={'A','a','B','b'};
984 /* Always start with this basic sample */
986 hdc=BeginPaint( hDlg, &ps );
989 MoveToEx( hdc, info.rcWindow.left, info.rcWindow.bottom, NULL );
990 hOrigPen=SelectObject( hdc, CreatePen( PS_SOLID, 2,
991 GetSysColor( COLOR_3DSHADOW ) ));
992 LineTo( hdc, info.rcWindow.left, info.rcWindow.top );
993 LineTo( hdc, info.rcWindow.right, info.rcWindow.top );
994 DeleteObject(SelectObject( hdc, CreatePen( PS_SOLID, 2,
995 GetSysColor( COLOR_3DLIGHT ) )));
996 LineTo( hdc, info.rcWindow.right, info.rcWindow.bottom );
997 LineTo( hdc, info.rcWindow.left, info.rcWindow.bottom );
998 DeleteObject(SelectObject( hdc, hOrigPen ));
1000 /* Draw the sample text itself */
1001 lstrcatW(sample, SAMPLE_LANG_TEXT[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]] );
1003 info.rcWindow.right--;
1004 info.rcWindow.bottom--;
1005 info.rcWindow.top++;
1006 info.rcWindow.left++;
1007 hOrigFont=SelectObject( hdc, CreateFontIndirectA( lpcf->lpLogFont ) );
1008 rgbPrev=SetTextColor( hdc, lpcf->rgbColors );
1010 DrawTextW( hdc, sample, -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1012 EndPaint( hDlg, &ps );
1018 /***********************************************************************
1019 * FormatCharDlgProcA [internal]
1021 INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1025 INT_PTR res = FALSE;
1026 if (uMsg!=WM_INITDIALOG)
1028 lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);
1031 if (CFn_HookCallChk32(lpcf))
1032 res=CallWindowProcA((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1038 lpcf=(LPCHOOSEFONTA)lParam;
1039 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
1041 TRACE("CFn_WMInitDialog returned FALSE\n");
1044 if (CFn_HookCallChk32(lpcf))
1045 return CallWindowProcA((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1049 case WM_MEASUREITEM:
1050 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1052 return CFn_WMDrawItem(hDlg, wParam, lParam);
1054 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1056 return CFn_WMDestroy(hDlg, wParam, lParam);
1057 case WM_CHOOSEFONT_GETLOGFONT:
1058 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1060 FIXME("current logfont back to caller\n");
1063 return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1068 /***********************************************************************
1069 * FormatCharDlgProcW [internal]
1071 INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1074 LPCHOOSEFONTW lpcf32w;
1075 LPCHOOSEFONTA lpcf32a;
1076 INT_PTR res = FALSE;
1077 if (uMsg!=WM_INITDIALOG)
1079 lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);
1082 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1083 res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
1089 lpcf32w=(LPCHOOSEFONTW)lParam;
1090 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1091 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
1093 TRACE("CFn_WMInitDialog returned FALSE\n");
1096 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1097 return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1099 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1102 case WM_MEASUREITEM:
1103 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1105 return CFn_WMDrawItem(hDlg, wParam, lParam);
1107 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
1109 return CFn_WMDestroy(hDlg, wParam, lParam);
1110 case WM_CHOOSEFONT_GETLOGFONT:
1111 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1113 FIXME("current logfont back to caller\n");