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
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
37 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
45 static HBITMAP hBitmapTT
= 0;
48 INT_PTR CALLBACK
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
50 INT_PTR CALLBACK
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
52 BOOL16 CALLBACK
FormatCharDlgProc16(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
,
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
60 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
61 #define SAMPLE_EXTLEN 10
63 static const WCHAR SAMPLE_LANG_TEXT
[][SAMPLE_EXTLEN
]={
64 {'Y','y','Z','z',0}, /* Western and default */
72 {0x05e0, 0x05e1, 0x05e9, 0x05ea, 0}, /* Hebrew */
77 {0}, /* East European */
87 {0}, /* ISO-8859-10 */
91 static const int CHARSET_ORDER
[256]={
92 CI(ANSI
), 0, CI(SYMBOL
), 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, 0, 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, CI(MAC
), 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 CI(JIS
), CI(HANGUL
), CI(JOHAB
), 0, 0, 0, CI(GB2312
), 0, CI(BIG5
), 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, CI(GREEK
), CI(TURKISH
), CI(VIETNAMESE
), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, CI(HEBREW
), CI(ARABIC
), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC
), 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN
), 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI
), 0,
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE
), 0,
107 CI(VISCII
), CI(TCVN
), CI(KOI8
), CI(ISO3
), CI(ISO4
), CI(ISO10
), CI(CELTIC
), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM
),
114 #define XX(x) { x, #x },
119 XX(CF_ENABLETEMPLATE
)
120 XX(CF_ENABLETEMPLATEHANDLE
)
121 XX(CF_INITTOLOGFONTSTRUCT
)
129 XX(CF_FIXEDPITCHONLY
)
131 XX(CF_FORCEFONTEXIST
)
144 void _dump_cf_flags(DWORD cflags
)
148 for (i
=0;cfflags
[i
].name
;i
++)
149 if (cfflags
[i
].mask
& cflags
)
150 MESSAGE("%s|",cfflags
[i
].name
);
154 /***********************************************************************
155 * ChooseFontA (COMDLG32.@)
157 BOOL WINAPI
ChooseFontA(LPCHOOSEFONTA lpChFont
)
164 if ( (lpChFont
->Flags
&CF_ENABLETEMPLATEHANDLE
)!=0 )
166 template=(LPCVOID
)lpChFont
->hInstance
;
169 if ( (lpChFont
->Flags
&CF_ENABLETEMPLATE
)!=0 )
171 hDlginst
=lpChFont
->hInstance
;
172 if( !(hResInfo
= FindResourceA(hDlginst
, lpChFont
->lpTemplateName
,
175 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
180 hDlginst
=COMDLG32_hInstance
;
181 if (!(hResInfo
= FindResourceA(hDlginst
, "CHOOSE_FONT", (LPSTR
)RT_DIALOG
)))
183 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
187 if (!(hDlgTmpl
= LoadResource(hDlginst
, hResInfo
)) ||
188 !(template = LockResource( hDlgTmpl
)))
190 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
194 if (TRACE_ON(commdlg
))
195 _dump_cf_flags(lpChFont
->Flags
);
197 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
))
198 FIXME(": unimplemented flag (ignored)\n");
200 return DialogBoxIndirectParamA(COMDLG32_hInstance
, template,
201 lpChFont
->hwndOwner
, FormatCharDlgProcA
, (LPARAM
)lpChFont
);
204 /***********************************************************************
205 * ChooseFontW (COMDLG32.@)
209 * The LOGFONT conversion functions will break if the structure ever
210 * grows beyond the lfFaceName element.
212 * The CHOOSEFONT conversion functions assume that both versions of
213 * lpLogFont and lpszStyle (if used) point to pre-allocated objects.
215 * The ASCII version of lpTemplateName is created by ChooseFontAtoW
216 * and freed by ChooseFontWtoA.
218 inline static VOID
LogFontWtoA(const LOGFONTW
*lfw
, LOGFONTA
*lfa
)
220 memcpy(lfa
, lfw
, sizeof(LOGFONTA
));
221 WideCharToMultiByte(CP_ACP
, 0, lfw
->lfFaceName
, -1, lfa
->lfFaceName
,
222 LF_FACESIZE
, NULL
, NULL
);
223 lfa
->lfFaceName
[LF_FACESIZE
- 1] = '\0';
226 inline static VOID
LogFontAtoW(const LOGFONTA
*lfa
, LOGFONTW
*lfw
)
228 memcpy(lfw
, lfa
, sizeof(LOGFONTA
));
229 MultiByteToWideChar(CP_ACP
, 0, lfa
->lfFaceName
, -1, lfw
->lfFaceName
,
231 lfw
->lfFaceName
[LF_FACESIZE
- 1] = 0;
234 static BOOL
ChooseFontWtoA(const CHOOSEFONTW
*cfw
, CHOOSEFONTA
*cfa
)
236 LOGFONTA
*lpLogFont
= cfa
->lpLogFont
;
237 LPSTR lpszStyle
= cfa
->lpszStyle
;
239 memcpy(cfa
, cfw
, sizeof(CHOOSEFONTA
));
240 cfa
->lpLogFont
= lpLogFont
;
241 cfa
->lpszStyle
= lpszStyle
;
243 LogFontWtoA(cfw
->lpLogFont
, lpLogFont
);
245 if ((cfw
->Flags
&CF_ENABLETEMPLATE
)!=0 && HIWORD(cfw
->lpTemplateName
)!=0)
247 cfa
->lpTemplateName
= HEAP_strdupWtoA(GetProcessHeap(), 0,
248 cfw
->lpTemplateName
);
249 if (cfa
->lpTemplateName
== NULL
)
253 if ((cfw
->Flags
& CF_USESTYLE
) != 0 && cfw
->lpszStyle
!= NULL
)
255 WideCharToMultiByte(CP_ACP
, 0, cfw
->lpszStyle
, -1, cfa
->lpszStyle
,
256 LF_FACESIZE
, NULL
, NULL
);
257 cfa
->lpszStyle
[LF_FACESIZE
- 1] = '\0';
263 static VOID
ChooseFontAtoW(const CHOOSEFONTA
*cfa
, CHOOSEFONTW
*cfw
)
265 LOGFONTW
*lpLogFont
= cfw
->lpLogFont
;
266 LPWSTR lpszStyle
= cfw
->lpszStyle
;
267 LPCWSTR lpTemplateName
= cfw
->lpTemplateName
;
269 memcpy(cfw
, cfa
, sizeof(CHOOSEFONTA
));
270 cfw
->lpLogFont
= lpLogFont
;
271 cfw
->lpszStyle
= lpszStyle
;
272 cfw
->lpTemplateName
= lpTemplateName
;
274 LogFontAtoW(cfa
->lpLogFont
, lpLogFont
);
276 if ((cfa
->Flags
&CF_ENABLETEMPLATE
)!=0 && HIWORD(cfa
->lpTemplateName
) != 0)
277 HeapFree(GetProcessHeap(), 0, (LPSTR
)(cfa
->lpTemplateName
));
279 if ((cfa
->Flags
& CF_USESTYLE
) != 0 && cfa
->lpszStyle
!= NULL
)
281 MultiByteToWideChar(CP_ACP
, 0, cfa
->lpszStyle
, -1, cfw
->lpszStyle
,
283 cfw
->lpszStyle
[LF_FACESIZE
- 1] = 0;
287 BOOL WINAPI
ChooseFontW(LPCHOOSEFONTW lpChFont
)
291 CHAR style_a
[LF_FACESIZE
];
293 cf_a
.lpLogFont
= &lf_a
;
294 cf_a
.lpszStyle
= style_a
;
296 if (ChooseFontWtoA(lpChFont
, &cf_a
) == FALSE
)
298 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
302 if (ChooseFontA(&cf_a
) == FALSE
)
304 if (cf_a
.lpTemplateName
!= NULL
)
305 HeapFree(GetProcessHeap(), 0, (LPSTR
)(cf_a
.lpTemplateName
));
309 ChooseFontAtoW(&cf_a
, lpChFont
);
315 /***********************************************************************
316 * ChooseFontW (COMDLG32.@)
318 BOOL WINAPI
ChooseFontW(LPCHOOSEFONTW lpChFont
)
324 HANDLE hResInfo
, hDlgTmpl
;
326 if (TRACE_ON(commdlg
))
327 _dump_cf_flags(lpChFont
->Flags
);
329 if (!(hResInfo
= FindResourceA(COMDLG32_hInstance
, "CHOOSE_FONT", (LPSTR
)RT_DIALOG
)))
331 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
334 if (!(hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
335 !(template = LockResource( hDlgTmpl
)))
337 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
341 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
342 CF_ENABLETEMPLATEHANDLE
)) FIXME(": unimplemented flag (ignored)\n");
343 memcpy(&cf32a
, lpChFont
, sizeof(cf32a
));
344 memcpy(&lf32a
, lpChFont
->lpLogFont
, sizeof(LOGFONTA
));
346 WideCharToMultiByte( CP_ACP
, 0, lpChFont
->lpLogFont
->lfFaceName
, -1,
347 lf32a
.lfFaceName
, LF_FACESIZE
, NULL
, NULL
);
348 lf32a
.lfFaceName
[LF_FACESIZE
-1] = 0;
349 cf32a
.lpLogFont
=&lf32a
;
350 cf32a
.lpszStyle
=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont
->lpszStyle
);
351 lpChFont
->lpTemplateName
=(LPWSTR
)&cf32a
;
352 bRet
= DialogBoxIndirectParamW(COMDLG32_hInstance
, template,
353 lpChFont
->hwndOwner
, FormatCharDlgProcW
, (LPARAM
)lpChFont
);
354 HeapFree(GetProcessHeap(), 0, cf32a
.lpszStyle
);
355 lpChFont
->lpTemplateName
=(LPWSTR
)cf32a
.lpTemplateName
;
356 memcpy(lpChFont
->lpLogFont
, &lf32a
, sizeof(CHOOSEFONTA
));
357 MultiByteToWideChar( CP_ACP
, 0, lf32a
.lfFaceName
, -1,
358 lpChFont
->lpLogFont
->lfFaceName
, LF_FACESIZE
);
359 lpChFont
->lpLogFont
->lfFaceName
[LF_FACESIZE
-1] = 0;
364 #define TEXT_EXTRAS 4
365 #define TEXT_COLORS 16
367 static const COLORREF textcolors
[TEXT_COLORS
]=
369 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
370 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
371 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
372 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
375 /***********************************************************************
376 * CFn_HookCallChk32 [internal]
378 static BOOL
CFn_HookCallChk32(LPCHOOSEFONTA lpcf
)
381 if(lpcf
->Flags
& CF_ENABLEHOOK
)
387 /*************************************************************************
388 * AddFontFamily [internal]
390 INT
AddFontFamily(const LOGFONTA
*lplf
, UINT nFontType
,
391 LPCHOOSEFONTA lpcf
, HWND hwnd
, LPCFn_ENUMSTRUCT e
)
396 TRACE("font=%s (nFontType=%d)\n", lplf
->lfFaceName
,nFontType
);
398 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
399 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
401 if (lpcf
->Flags
& CF_ANSIONLY
)
402 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
404 if (lpcf
->Flags
& CF_TTONLY
)
405 if (!(nFontType
& TRUETYPE_FONTTYPE
))
410 i
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)lplf
->lfFaceName
);
413 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
414 SendMessageA(hwnd
, CB_SETITEMDATA
, i
, MAKELONG(nFontType
,w
));
415 return 1 ; /* store some important font information */
421 /*************************************************************************
422 * FontFamilyEnumProc32 [internal]
424 static INT WINAPI
FontFamilyEnumProc(const LOGFONTA
*lpLogFont
,
425 const TEXTMETRICA
*metrics
, DWORD dwFontType
, LPARAM lParam
)
428 e
=(LPCFn_ENUMSTRUCT
)lParam
;
429 return AddFontFamily(lpLogFont
, dwFontType
, e
->lpcf32a
, e
->hWnd1
, e
);
432 /*************************************************************************
433 * SetFontStylesToCombo2 [internal]
435 * Fill font style information into combobox (without using font.c directly)
437 static int SetFontStylesToCombo2(HWND hwnd
, HDC hdc
, const LOGFONTA
*lplf
)
446 static struct FONTSTYLE fontstyles
[FSTYLES
]={
447 { 0,FW_NORMAL
,"Regular"}, { 1,FW_NORMAL
,"Italic"},
448 { 0,FW_BOLD
,"Bold"}, { 1,FW_BOLD
,"Bold Italic"}
455 memcpy(&lf
, lplf
, sizeof(LOGFONTA
));
457 for (i
=0;i
<FSTYLES
;i
++)
459 lf
.lfItalic
=fontstyles
[i
].italic
;
460 lf
.lfWeight
=fontstyles
[i
].weight
;
461 hf
=CreateFontIndirectA(&lf
);
462 hf
=SelectObject(hdc
,hf
);
463 GetTextMetricsA(hdc
,&tm
);
464 hf
=SelectObject(hdc
,hf
);
466 /* font successful created ? */
467 if (tm
.tmWeight
==fontstyles
[i
].weight
&&
468 ((tm
.tmItalic
!= 0)==fontstyles
[i
].italic
))
470 j
=SendMessageA(hwnd
,CB_ADDSTRING
,0,(LPARAM
)fontstyles
[i
].stname
);
471 if (j
==CB_ERR
) return 1;
472 j
=SendMessageA(hwnd
, CB_SETITEMDATA
, j
,
473 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
474 if (j
==CB_ERR
) return 1;
480 /*************************************************************************
481 * AddFontSizeToCombo3 [internal]
483 static int AddFontSizeToCombo3(HWND hwnd
, UINT h
, LPCHOOSEFONTA lpcf
)
488 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
489 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
491 sprintf(buffer
, "%2d", h
);
492 j
=SendMessageA(hwnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buffer
);
495 j
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
496 if (j
!=CB_ERR
) j
= SendMessageA(hwnd
, CB_SETITEMDATA
, j
, h
);
497 if (j
==CB_ERR
) return 1;
503 /*************************************************************************
504 * SetFontSizesToCombo3 [internal]
506 static int SetFontSizesToCombo3(HWND hwnd
, LPCHOOSEFONTA lpcf
)
508 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
511 for (i
=0; sizes
[i
]; i
++)
512 if (AddFontSizeToCombo3(hwnd
, sizes
[i
], lpcf
)) return 1;
516 /***********************************************************************
517 * AddFontStyle [internal]
519 INT
AddFontStyle(const LOGFONTA
*lplf
, UINT nFontType
,
520 LPCHOOSEFONTA lpcf
, HWND hcmb2
, HWND hcmb3
, HWND hDlg
)
524 TRACE("(nFontType=%d)\n",nFontType
);
525 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
526 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
527 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,
528 lplf
->lfEscapement
,lplf
->lfOrientation
,
529 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,
530 lplf
->lfStrikeOut
,lplf
->lfCharSet
, lplf
->lfOutPrecision
,
531 lplf
->lfClipPrecision
,lplf
->lfQuality
, lplf
->lfPitchAndFamily
);
532 if (nFontType
& RASTER_FONTTYPE
)
534 if (AddFontSizeToCombo3(hcmb3
, lplf
->lfHeight
, lpcf
)) return 0;
535 } else if (SetFontSizesToCombo3(hcmb3
, lpcf
)) return 0;
537 if (!SendMessageA(hcmb2
, CB_GETCOUNT
, 0, 0))
539 HDC hdc
= ((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
540 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
);
541 if (!((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
))
550 /***********************************************************************
551 * FontStyleEnumProc32 [internal]
553 static INT WINAPI
FontStyleEnumProc( const LOGFONTA
*lpFont
,
554 const TEXTMETRICA
*metrics
, DWORD dwFontType
, LPARAM lParam
)
556 LPCFn_ENUMSTRUCT s
=(LPCFn_ENUMSTRUCT
)lParam
;
559 HWND hDlg
=GetParent(hcmb3
);
560 return AddFontStyle(lpFont
, dwFontType
, s
->lpcf32a
, hcmb2
,
564 /***********************************************************************
565 * CFn_WMInitDialog [internal]
567 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
574 HCURSOR hcursor
=SetCursor(LoadCursorA(0,(LPSTR
)IDC_WAIT
));
576 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
577 lpxx
=lpcf
->lpLogFont
;
578 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
580 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONTA
))
582 ERR("structure size failure !!!\n");
587 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
589 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
590 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
591 if (!(lpcf
->Flags
& CF_APPLY
))
592 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
593 if (lpcf
->Flags
& CF_EFFECTS
)
595 for (i
=0;i
<TEXT_COLORS
;i
++)
599 if( LoadStringA(COMDLG32_hInstance
, IDS_COLOR_BLACK
+i
, name
,
600 sizeof(name
)/sizeof(*name
) )==0 )
602 strcpy( name
, "[color name]" );
604 j
=SendDlgItemMessageA(hDlg
, cmb4
, CB_ADDSTRING
, 0, (LPARAM
)name
);
605 SendDlgItemMessageA(hDlg
, cmb4
, CB_SETITEMDATA16
, j
, textcolors
[j
]);
606 /* look for a fitting value in color combobox */
607 if (textcolors
[j
]==lpcf
->rgbColors
)
608 SendDlgItemMessageA(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
613 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
614 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
615 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
616 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
617 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
619 hdc
= ((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
623 s
.hWnd1
=GetDlgItem(hDlg
,cmb1
);
627 if (!EnumFontFamiliesA(hdc
, NULL
, FontFamilyEnumProc
, (LPARAM
)&s
)) {
628 TRACE("EnumFontFamilies returns 0\n");
632 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
) {
633 FIXME("No font found with fixed pitch only, dropping flag.\n");
634 lpcf
->Flags
&= ~CF_FIXEDPITCHONLY
;
637 if (lpcf
->Flags
& CF_TTONLY
) {
638 FIXME("No font found with truetype only, dropping flag.\n");
639 lpcf
->Flags
&= ~CF_TTONLY
;
646 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
648 /* look for fitting font name in combobox1 */
649 j
=SendDlgItemMessageA(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
652 SendDlgItemMessageA(hDlg
, cmb1
, CB_SETCURSEL
, j
, 0);
653 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
654 (LPARAM
)GetDlgItem(hDlg
,cmb1
));
656 /* look for fitting font style in combobox2 */
657 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
658 for (i
=0;i
<TEXT_EXTRAS
;i
++)
660 if (l
==SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0))
661 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
664 /* look for fitting font size in combobox3 */
665 j
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCOUNT
, 0, 0);
668 if (lpxx
->lfHeight
==(int)SendDlgItemMessageA(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
669 SendDlgItemMessageA(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
675 SendDlgItemMessageA(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
676 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
677 (LPARAM
)GetDlgItem(hDlg
,cmb1
));
679 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
681 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
684 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
685 SendMessageA(hDlg
,WM_COMMAND
,cmb2
,
686 MAKELONG(HWND_16(GetDlgItem(hDlg
,cmb2
)),CBN_SELCHANGE
));
692 WARN("HDC failure !!!\n");
697 if (!((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
))
704 /***********************************************************************
705 * CFn_WMMeasureItem [internal]
707 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
710 LPMEASUREITEMSTRUCT lpmi
=(LPMEASUREITEMSTRUCT
)lParam
;
712 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
713 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
714 lpmi
->itemHeight
=bm
.bmHeight
;
715 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
720 /***********************************************************************
721 * CFn_WMDrawItem [internal]
723 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
728 COLORREF cr
, oldText
=0, oldBk
=0;
733 HBITMAP hBitmap
; /* for later TT usage */
735 LPDRAWITEMSTRUCT lpdi
= (LPDRAWITEMSTRUCT
)lParam
;
737 if (lpdi
->itemID
== (UINT
)-1) /* got no items */
738 DrawFocusRect(lpdi
->hDC
, &lpdi
->rcItem
);
741 if (lpdi
->CtlType
== ODT_COMBOBOX
)
743 if (lpdi
->itemState
==ODS_SELECTED
)
745 hBrush
=GetSysColorBrush(COLOR_HIGHLIGHT
);
746 oldText
=SetTextColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
747 oldBk
=SetBkColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHT
));
750 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
751 SelectObject(lpdi
->hDC
, hBrush
);
753 FillRect(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
756 return TRUE
; /* this should never happen */
762 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
763 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
765 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
766 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
767 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
769 nFontType
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
770 /* FIXME: draw bitmap if truetype usage */
771 if (nFontType
&TRUETYPE_FONTTYPE
)
773 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
774 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
775 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
776 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
777 SelectObject(hMemDC
, hBitmap
);
784 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
785 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
787 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
,
788 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
792 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
793 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
795 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
796 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
797 cr
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
798 hBrush
= CreateSolidBrush(cr
);
801 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
802 rect
.right
=rect
.left
+25;
806 Rectangle( lpdi
->hDC
, rect
.left
, rect
.top
,
807 rect
.right
, rect
.bottom
);
808 DeleteObject( SelectObject (lpdi
->hDC
, hBrush
)) ;
815 return TRUE
; /* this should never happen */
817 if (lpdi
->itemState
== ODS_SELECTED
)
819 SetTextColor(lpdi
->hDC
, oldText
);
820 SetBkColor(lpdi
->hDC
, oldBk
);
826 /***********************************************************************
827 * CFn_WMCommand [internal]
829 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
835 LPLOGFONTA lpxx
=lpcf
->lpLogFont
;
837 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG
)wParam
, lParam
);
838 switch (LOWORD(wParam
))
841 if (HIWORD(wParam
)==CBN_SELCHANGE
)
843 hdc
=((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
846 SendDlgItemMessageA(hDlg
, cmb2
, CB_RESETCONTENT16
, 0, 0);
847 SendDlgItemMessageA(hDlg
, cmb3
, CB_RESETCONTENT16
, 0, 0);
848 i
=SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL16
, 0, 0);
851 HCURSOR hcursor
=SetCursor(LoadCursorA(0,(LPSTR
)IDC_WAIT
));
854 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETLBTEXT
, i
,
856 TRACE("WM_COMMAND/cmb1 =>%s\n",str
);
857 s
.hWnd1
=GetDlgItem(hDlg
, cmb2
);
858 s
.hWnd2
=GetDlgItem(hDlg
, cmb3
);
860 EnumFontFamiliesA(hdc
, str
, FontStyleEnumProc
, (LPARAM
)&s
);
861 SendDlgItemMessageA(hDlg
,cmb2
, CB_SETCURSEL
, 0, 0);
862 SendDlgItemMessageA(hDlg
,cmb3
, CB_SETCURSEL
, 0, 0);
865 if (!((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
))
870 WARN("HDC failure !!!\n");
879 if (HIWORD(wParam
)==CBN_SELCHANGE
|| HIWORD(wParam
)== BN_CLICKED
)
884 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
885 i
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
887 i
=GetDlgItemTextA( hDlg
, cmb1
, str
, 256 );
890 SendDlgItemMessageA(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
892 l
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
894 lpcf
->nFontType
= LOWORD(l
);
895 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
896 /* same value reported to the EnumFonts
897 call back with the extra FONTTYPE_... bits added */
898 lpxx
->lfPitchAndFamily
=j
&0xff;
899 lpxx
->lfCharSet
=j
>>8;
901 strcpy(lpxx
->lfFaceName
,str
);
902 i
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
905 l
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0);
906 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
907 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
908 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
909 lpcf
->nFontType
|= BOLD_FONTTYPE
;
911 i
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
913 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessageA(hDlg
, cmb3
, CB_GETITEMDATA
, i
, 0));
916 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
917 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
918 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
919 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
920 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
921 lpxx
->lfQuality
=DEFAULT_QUALITY
;
922 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
924 wininfo
.cbSize
=sizeof(wininfo
);
926 if( GetWindowInfo( GetDlgItem( hDlg
, stc5
), &wininfo
) )
928 MapWindowPoints( 0, hDlg
, (LPPOINT
) &wininfo
.rcWindow
, 2);
929 InvalidateRect( hDlg
, &wininfo
.rcWindow
, TRUE
);
935 i
=SendDlgItemMessageA(hDlg
, cmb4
, CB_GETCURSEL
, 0, 0);
940 lpcf
->rgbColors
=textcolors
[i
];
941 wininfo
.cbSize
=sizeof(wininfo
);
943 if( GetWindowInfo( GetDlgItem( hDlg
, stc5
), &wininfo
) )
945 MapWindowPoints( 0, hDlg
, (LPPOINT
) &wininfo
.rcWindow
, 2);
946 InvalidateRect( hDlg
, &wininfo
.rcWindow
, TRUE
);
952 i
=RegisterWindowMessageA( HELPMSGSTRINGA
);
954 SendMessageA(lpcf
->hwndOwner
, i
, 0, (LPARAM
)GetWindowLongA(hDlg
, DWL_USER
));
955 /* if (CFn_HookCallChk(lpcf))
956 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
960 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
961 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
962 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
963 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
964 EndDialog(hDlg
, TRUE
);
968 sprintf(buffer
,"Select a font size between %d and %d points.",
969 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
970 MessageBoxA(hDlg
, buffer
, NULL
, MB_OK
);
974 EndDialog(hDlg
, FALSE
);
980 LRESULT
CFn_WMDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
985 static LRESULT
CFn_WMPaint(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
990 info
.cbSize
=sizeof(info
);
992 if( GetWindowInfo( GetDlgItem( hDlg
, stc5
), &info
) )
999 WCHAR sample
[SAMPLE_EXTLEN
+5]={'A','a','B','b'};
1000 LOGFONTA lf
= *(lpcf
->lpLogFont
);
1001 /* Always start with this basic sample */
1003 MapWindowPoints( 0, hDlg
, (LPPOINT
) &info
.rcWindow
, 2);
1004 hdc
=BeginPaint( hDlg
, &ps
);
1007 MoveToEx( hdc
, info
.rcWindow
.left
, info
.rcWindow
.bottom
, NULL
);
1008 hOrigPen
=SelectObject( hdc
, CreatePen( PS_SOLID
, 2,
1009 GetSysColor( COLOR_3DSHADOW
) ));
1010 LineTo( hdc
, info
.rcWindow
.left
, info
.rcWindow
.top
);
1011 LineTo( hdc
, info
.rcWindow
.right
, info
.rcWindow
.top
);
1012 DeleteObject(SelectObject( hdc
, CreatePen( PS_SOLID
, 2,
1013 GetSysColor( COLOR_3DLIGHT
) )));
1014 LineTo( hdc
, info
.rcWindow
.right
, info
.rcWindow
.bottom
);
1015 LineTo( hdc
, info
.rcWindow
.left
, info
.rcWindow
.bottom
);
1016 DeleteObject(SelectObject( hdc
, hOrigPen
));
1018 /* Draw the sample text itself */
1019 lstrcatW(sample
, SAMPLE_LANG_TEXT
[CHARSET_ORDER
[lpcf
->lpLogFont
->lfCharSet
]] );
1021 info
.rcWindow
.right
--;
1022 info
.rcWindow
.bottom
--;
1023 info
.rcWindow
.top
++;
1024 info
.rcWindow
.left
++;
1025 lf
.lfHeight
= MulDiv(lf
.lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1026 hOrigFont
= SelectObject( hdc
, CreateFontIndirectA( &lf
) );
1027 rgbPrev
=SetTextColor( hdc
, lpcf
->rgbColors
);
1029 DrawTextW( hdc
, sample
, -1, &info
.rcWindow
, DT_CENTER
|DT_VCENTER
|DT_SINGLELINE
);
1031 EndPaint( hDlg
, &ps
);
1037 /***********************************************************************
1038 * FormatCharDlgProcA [internal]
1040 INT_PTR CALLBACK
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1044 INT_PTR res
= FALSE
;
1045 if (uMsg
!=WM_INITDIALOG
)
1047 lpcf
=(LPCHOOSEFONTA
)GetWindowLongA(hDlg
, DWL_USER
);
1050 if (CFn_HookCallChk32(lpcf
))
1051 res
=CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
1057 lpcf
=(LPCHOOSEFONTA
)lParam
;
1058 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf
))
1060 TRACE("CFn_WMInitDialog returned FALSE\n");
1063 if (CFn_HookCallChk32(lpcf
))
1064 return CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1068 case WM_MEASUREITEM
:
1069 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1071 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1073 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf
);
1075 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1076 case WM_CHOOSEFONT_GETLOGFONT
:
1077 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1079 FIXME("current logfont back to caller\n");
1082 return CFn_WMPaint(hDlg
, wParam
, lParam
, lpcf
);
1087 /***********************************************************************
1088 * FormatCharDlgProcW [internal]
1090 INT_PTR CALLBACK
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1093 LPCHOOSEFONTW lpcf32w
;
1094 LPCHOOSEFONTA lpcf32a
;
1095 INT_PTR res
= FALSE
;
1096 if (uMsg
!=WM_INITDIALOG
)
1098 lpcf32w
=(LPCHOOSEFONTW
)GetWindowLongA(hDlg
, DWL_USER
);
1101 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1102 res
=CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
1108 lpcf32w
=(LPCHOOSEFONTW
)lParam
;
1109 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1110 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
1112 TRACE("CFn_WMInitDialog returned FALSE\n");
1115 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1116 return CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1118 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1121 case WM_MEASUREITEM
:
1122 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1124 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1126 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf32a
);
1128 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1129 case WM_CHOOSEFONT_GETLOGFONT
:
1130 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1132 FIXME("current logfont back to caller\n");