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", RT_DIALOGA
)))
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", RT_DIALOGA
)))
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
)
444 static struct FONTSTYLE fontstyles
[FSTYLES
]={
445 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
446 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
452 memcpy(&lf
, lplf
, sizeof(LOGFONTA
));
454 for (i
=0;i
<FSTYLES
;i
++)
456 lf
.lfItalic
=fontstyles
[i
].italic
;
457 lf
.lfWeight
=fontstyles
[i
].weight
;
458 hf
=CreateFontIndirectA(&lf
);
459 hf
=SelectObject(hdc
,hf
);
460 GetTextMetricsA(hdc
,&tm
);
461 hf
=SelectObject(hdc
,hf
);
464 if (tm
.tmWeight
==fontstyles
[i
].weight
&&
465 tm
.tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
467 j
=SendMessageA(hwnd
,CB_ADDSTRING
,0,(LPARAM
)fontstyles
[i
].stname
);
468 if (j
==CB_ERR
) return 1;
469 j
=SendMessageA(hwnd
, CB_SETITEMDATA
, j
,
470 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
471 if (j
==CB_ERR
) return 1;
477 /*************************************************************************
478 * AddFontSizeToCombo3 [internal]
480 static int AddFontSizeToCombo3(HWND hwnd
, UINT h
, LPCHOOSEFONTA lpcf
)
485 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
486 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
488 sprintf(buffer
, "%2d", h
);
489 j
=SendMessageA(hwnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buffer
);
492 j
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
493 if (j
!=CB_ERR
) j
= SendMessageA(hwnd
, CB_SETITEMDATA
, j
, h
);
494 if (j
==CB_ERR
) return 1;
500 /*************************************************************************
501 * SetFontSizesToCombo3 [internal]
503 static int SetFontSizesToCombo3(HWND hwnd
, LPCHOOSEFONTA lpcf
)
505 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
508 for (i
=0; sizes
[i
]; i
++)
509 if (AddFontSizeToCombo3(hwnd
, sizes
[i
], lpcf
)) return 1;
513 /***********************************************************************
514 * AddFontStyle [internal]
516 INT
AddFontStyle(const LOGFONTA
*lplf
, UINT nFontType
,
517 LPCHOOSEFONTA lpcf
, HWND hcmb2
, HWND hcmb3
, HWND hDlg
)
521 TRACE("(nFontType=%d)\n",nFontType
);
522 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
523 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
524 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,
525 lplf
->lfEscapement
,lplf
->lfOrientation
,
526 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,
527 lplf
->lfStrikeOut
,lplf
->lfCharSet
, lplf
->lfOutPrecision
,
528 lplf
->lfClipPrecision
,lplf
->lfQuality
, lplf
->lfPitchAndFamily
);
529 if (nFontType
& RASTER_FONTTYPE
)
531 if (AddFontSizeToCombo3(hcmb3
, lplf
->lfHeight
, lpcf
)) return 0;
532 } else if (SetFontSizesToCombo3(hcmb3
, lpcf
)) return 0;
534 if (!SendMessageA(hcmb2
, CB_GETCOUNT
, 0, 0))
536 HDC hdc
= ((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
537 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
);
538 if (!((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
))
547 /***********************************************************************
548 * FontStyleEnumProc32 [internal]
550 static INT WINAPI
FontStyleEnumProc( const LOGFONTA
*lpFont
,
551 const TEXTMETRICA
*metrics
, DWORD dwFontType
, LPARAM lParam
)
553 LPCFn_ENUMSTRUCT s
=(LPCFn_ENUMSTRUCT
)lParam
;
556 HWND hDlg
=GetParent(hcmb3
);
557 return AddFontStyle(lpFont
, dwFontType
, s
->lpcf32a
, hcmb2
,
561 /***********************************************************************
562 * CFn_WMInitDialog [internal]
564 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
571 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
573 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
574 lpxx
=lpcf
->lpLogFont
;
575 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
577 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONTA
))
579 ERR("structure size failure !!!\n");
584 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
586 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
587 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
588 if (!(lpcf
->Flags
& CF_APPLY
))
589 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
590 if (lpcf
->Flags
& CF_EFFECTS
)
592 for (i
=0;i
<TEXT_COLORS
;i
++)
596 if( LoadStringA(COMDLG32_hInstance
, IDS_COLOR_BLACK
+i
, name
,
597 sizeof(name
)/sizeof(*name
) )==0 )
599 strcpy( name
, "[color name]" );
601 j
=SendDlgItemMessageA(hDlg
, cmb4
, CB_ADDSTRING
, 0, (LPARAM
)name
);
602 SendDlgItemMessageA(hDlg
, cmb4
, CB_SETITEMDATA16
, j
, textcolors
[j
]);
603 /* look for a fitting value in color combobox */
604 if (textcolors
[j
]==lpcf
->rgbColors
)
605 SendDlgItemMessageA(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
610 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
611 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
612 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
613 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
614 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
616 hdc
= ((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
620 s
.hWnd1
=GetDlgItem(hDlg
,cmb1
);
624 if (!EnumFontFamiliesA(hdc
, NULL
, FontFamilyEnumProc
, (LPARAM
)&s
)) {
625 TRACE("EnumFontFamilies returns 0\n");
629 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
) {
630 FIXME("No font found with fixed pitch only, dropping flag.\n");
631 lpcf
->Flags
&= ~CF_FIXEDPITCHONLY
;
634 if (lpcf
->Flags
& CF_TTONLY
) {
635 FIXME("No font found with truetype only, dropping flag.\n");
636 lpcf
->Flags
&= ~CF_TTONLY
;
643 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
645 /* look for fitting font name in combobox1 */
646 j
=SendDlgItemMessageA(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
649 SendDlgItemMessageA(hDlg
, cmb1
, CB_SETCURSEL
, j
, 0);
650 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
651 (LPARAM
)GetDlgItem(hDlg
,cmb1
));
653 /* look for fitting font style in combobox2 */
654 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
655 for (i
=0;i
<TEXT_EXTRAS
;i
++)
657 if (l
==SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0))
658 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
661 /* look for fitting font size in combobox3 */
662 j
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCOUNT
, 0, 0);
665 if (lpxx
->lfHeight
==(int)SendDlgItemMessageA(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
666 SendDlgItemMessageA(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
672 SendDlgItemMessageA(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
673 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
674 (LPARAM
)GetDlgItem(hDlg
,cmb1
));
676 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
678 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
681 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
682 SendMessageA(hDlg
,WM_COMMAND
,cmb2
,
683 MAKELONG(HWND_16(GetDlgItem(hDlg
,cmb2
)),CBN_SELCHANGE
));
689 WARN("HDC failure !!!\n");
694 if (!((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
))
701 /***********************************************************************
702 * CFn_WMMeasureItem [internal]
704 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
707 LPMEASUREITEMSTRUCT lpmi
=(LPMEASUREITEMSTRUCT
)lParam
;
709 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
710 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
711 lpmi
->itemHeight
=bm
.bmHeight
;
712 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
717 /***********************************************************************
718 * CFn_WMDrawItem [internal]
720 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
725 COLORREF cr
, oldText
=0, oldBk
=0;
730 HBITMAP hBitmap
; /* for later TT usage */
732 LPDRAWITEMSTRUCT lpdi
= (LPDRAWITEMSTRUCT
)lParam
;
734 if (lpdi
->itemID
== (UINT
)-1) /* got no items */
735 DrawFocusRect(lpdi
->hDC
, &lpdi
->rcItem
);
738 if (lpdi
->CtlType
== ODT_COMBOBOX
)
740 if (lpdi
->itemState
==ODS_SELECTED
)
742 hBrush
=GetSysColorBrush(COLOR_HIGHLIGHT
);
743 oldText
=SetTextColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
744 oldBk
=SetBkColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHT
));
747 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
748 SelectObject(lpdi
->hDC
, hBrush
);
750 FillRect(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
753 return TRUE
; /* this should never happen */
758 case cmb1
: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
759 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
761 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
762 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
763 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
765 nFontType
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
766 /* FIXME: draw bitmap if truetype usage */
767 if (nFontType
&TRUETYPE_FONTTYPE
)
769 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
770 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
771 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
772 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
773 SelectObject(hMemDC
, hBitmap
);
779 case cmb3
: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
780 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
782 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
,
783 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
786 case cmb4
: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
787 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
789 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
790 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
791 cr
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
792 hBrush
= CreateSolidBrush(cr
);
795 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
796 rect
.right
=rect
.left
+25;
800 Rectangle( lpdi
->hDC
, rect
.left
, rect
.top
,
801 rect
.right
, rect
.bottom
);
802 DeleteObject( SelectObject (lpdi
->hDC
, hBrush
)) ;
808 default: return TRUE
; /* this should never happen */
810 if (lpdi
->itemState
== ODS_SELECTED
)
812 SetTextColor(lpdi
->hDC
, oldText
);
813 SetBkColor(lpdi
->hDC
, oldBk
);
819 /***********************************************************************
820 * CFn_WMCommand [internal]
822 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
828 LPLOGFONTA lpxx
=lpcf
->lpLogFont
;
830 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG
)wParam
, lParam
);
831 switch (LOWORD(wParam
))
833 case cmb1
:if (HIWORD(wParam
)==CBN_SELCHANGE
)
835 hdc
=((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
838 SendDlgItemMessageA(hDlg
, cmb2
, CB_RESETCONTENT16
, 0, 0);
839 SendDlgItemMessageA(hDlg
, cmb3
, CB_RESETCONTENT16
, 0, 0);
840 i
=SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL16
, 0, 0);
843 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
846 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETLBTEXT
, i
,
848 TRACE("WM_COMMAND/cmb1 =>%s\n",str
);
849 s
.hWnd1
=GetDlgItem(hDlg
, cmb2
);
850 s
.hWnd2
=GetDlgItem(hDlg
, cmb3
);
852 EnumFontFamiliesA(hdc
, str
, FontStyleEnumProc
, (LPARAM
)&s
);
853 SendDlgItemMessageA(hDlg
,cmb2
, CB_SETCURSEL
, 0, 0);
854 SendDlgItemMessageA(hDlg
,cmb3
, CB_SETCURSEL
, 0, 0);
857 if (!((lpcf
->Flags
& CF_PRINTERFONTS
) && lpcf
->hDC
))
862 WARN("HDC failure !!!\n");
870 case cmb3
:if (HIWORD(wParam
)==CBN_SELCHANGE
|| HIWORD(wParam
)== BN_CLICKED
)
875 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
876 i
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
878 i
=GetDlgItemTextA( hDlg
, cmb1
, str
, 256 );
881 SendDlgItemMessageA(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
883 l
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
885 lpcf
->nFontType
= LOWORD(l
);
886 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
887 /* same value reported to the EnumFonts
888 call back with the extra FONTTYPE_... bits added */
889 lpxx
->lfPitchAndFamily
=j
&0xff;
890 lpxx
->lfCharSet
=j
>>8;
892 strcpy(lpxx
->lfFaceName
,str
);
893 i
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
896 l
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0);
897 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
898 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
899 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
900 lpcf
->nFontType
|= BOLD_FONTTYPE
;
902 i
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
904 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessageA(hDlg
, cmb3
, CB_GETITEMDATA
, i
, 0));
907 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
908 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
909 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
910 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
911 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
912 lpxx
->lfQuality
=DEFAULT_QUALITY
;
913 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
915 wininfo
.cbSize
=sizeof(wininfo
);
917 if( GetWindowInfo( GetDlgItem( hDlg
, stc5
), &wininfo
) )
919 InvalidateRect( hDlg
, &wininfo
.rcWindow
, TRUE
);
925 i
=SendDlgItemMessageA(hDlg
, cmb4
, CB_GETCURSEL
, 0, 0);
930 lpcf
->rgbColors
=textcolors
[i
];
931 wininfo
.cbSize
=sizeof(wininfo
);
933 if( GetWindowInfo( GetDlgItem( hDlg
, stc5
), &wininfo
) )
935 InvalidateRect( hDlg
, &wininfo
.rcWindow
, TRUE
);
940 case psh15
:i
=RegisterWindowMessageA( HELPMSGSTRINGA
);
942 SendMessageA(lpcf
->hwndOwner
, i
, 0, (LPARAM
)GetWindowLongA(hDlg
, DWL_USER
));
943 /* if (CFn_HookCallChk(lpcf))
944 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
947 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
948 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
949 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
950 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
951 EndDialog(hDlg
, TRUE
);
955 sprintf(buffer
,"Select a font size between %d and %d points.",
956 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
957 MessageBoxA(hDlg
, buffer
, NULL
, MB_OK
);
960 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
966 LRESULT
CFn_WMDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
971 static LRESULT
CFn_WMPaint(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
976 info
.cbSize
=sizeof(info
);
978 if( GetWindowInfo( GetDlgItem( hDlg
, stc5
), &info
) )
985 WCHAR sample
[SAMPLE_EXTLEN
+5]={'A','a','B','b'};
986 /* Always start with this basic sample */
988 hdc
=BeginPaint( hDlg
, &ps
);
991 MoveToEx( hdc
, info
.rcWindow
.left
, info
.rcWindow
.bottom
, NULL
);
992 hOrigPen
=SelectObject( hdc
, CreatePen( PS_SOLID
, 2,
993 GetSysColor( COLOR_3DSHADOW
) ));
994 LineTo( hdc
, info
.rcWindow
.left
, info
.rcWindow
.top
);
995 LineTo( hdc
, info
.rcWindow
.right
, info
.rcWindow
.top
);
996 DeleteObject(SelectObject( hdc
, CreatePen( PS_SOLID
, 2,
997 GetSysColor( COLOR_3DLIGHT
) )));
998 LineTo( hdc
, info
.rcWindow
.right
, info
.rcWindow
.bottom
);
999 LineTo( hdc
, info
.rcWindow
.left
, info
.rcWindow
.bottom
);
1000 DeleteObject(SelectObject( hdc
, hOrigPen
));
1002 /* Draw the sample text itself */
1003 lstrcatW(sample
, SAMPLE_LANG_TEXT
[CHARSET_ORDER
[lpcf
->lpLogFont
->lfCharSet
]] );
1005 info
.rcWindow
.right
--;
1006 info
.rcWindow
.bottom
--;
1007 info
.rcWindow
.top
++;
1008 info
.rcWindow
.left
++;
1009 hOrigFont
=SelectObject( hdc
, CreateFontIndirectA( lpcf
->lpLogFont
) );
1010 rgbPrev
=SetTextColor( hdc
, lpcf
->rgbColors
);
1012 DrawTextW( hdc
, sample
, -1, &info
.rcWindow
, DT_CENTER
|DT_VCENTER
|DT_SINGLELINE
);
1014 EndPaint( hDlg
, &ps
);
1020 /***********************************************************************
1021 * FormatCharDlgProcA [internal]
1023 INT_PTR CALLBACK
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1027 INT_PTR res
= FALSE
;
1028 if (uMsg
!=WM_INITDIALOG
)
1030 lpcf
=(LPCHOOSEFONTA
)GetWindowLongA(hDlg
, DWL_USER
);
1033 if (CFn_HookCallChk32(lpcf
))
1034 res
=CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
1040 lpcf
=(LPCHOOSEFONTA
)lParam
;
1041 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf
))
1043 TRACE("CFn_WMInitDialog returned FALSE\n");
1046 if (CFn_HookCallChk32(lpcf
))
1047 return CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1051 case WM_MEASUREITEM
:
1052 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1054 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1056 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf
);
1058 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1059 case WM_CHOOSEFONT_GETLOGFONT
:
1060 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1062 FIXME("current logfont back to caller\n");
1065 return CFn_WMPaint(hDlg
, wParam
, lParam
, lpcf
);
1070 /***********************************************************************
1071 * FormatCharDlgProcW [internal]
1073 INT_PTR CALLBACK
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1076 LPCHOOSEFONTW lpcf32w
;
1077 LPCHOOSEFONTA lpcf32a
;
1078 INT_PTR res
= FALSE
;
1079 if (uMsg
!=WM_INITDIALOG
)
1081 lpcf32w
=(LPCHOOSEFONTW
)GetWindowLongA(hDlg
, DWL_USER
);
1084 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1085 res
=CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
1091 lpcf32w
=(LPCHOOSEFONTW
)lParam
;
1092 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1093 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
1095 TRACE("CFn_WMInitDialog returned FALSE\n");
1098 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1099 return CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1101 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1104 case WM_MEASUREITEM
:
1105 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1107 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1109 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf32a
);
1111 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1112 case WM_CHOOSEFONT_GETLOGFONT
:
1113 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1115 FIXME("current logfont back to caller\n");