2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
16 #include "wine/winbase16.h"
17 #include "wine/winuser16.h"
21 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(commdlg
);
28 static HBITMAP16 hBitmapTT
= 0;
31 LRESULT WINAPI
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
33 LRESULT WINAPI
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
35 LRESULT WINAPI
FormatCharDlgProc16(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
,
38 static void FONT_LogFont16To32A( const LPLOGFONT16 font16
, LPLOGFONTA font32
)
40 font32
->lfHeight
= font16
->lfHeight
;
41 font32
->lfWidth
= font16
->lfWidth
;
42 font32
->lfEscapement
= font16
->lfEscapement
;
43 font32
->lfOrientation
= font16
->lfOrientation
;
44 font32
->lfWeight
= font16
->lfWeight
;
45 font32
->lfItalic
= font16
->lfItalic
;
46 font32
->lfUnderline
= font16
->lfUnderline
;
47 font32
->lfStrikeOut
= font16
->lfStrikeOut
;
48 font32
->lfCharSet
= font16
->lfCharSet
;
49 font32
->lfOutPrecision
= font16
->lfOutPrecision
;
50 font32
->lfClipPrecision
= font16
->lfClipPrecision
;
51 font32
->lfQuality
= font16
->lfQuality
;
52 font32
->lfPitchAndFamily
= font16
->lfPitchAndFamily
;
53 lstrcpynA( font32
->lfFaceName
, font16
->lfFaceName
, LF_FACESIZE
);
56 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16
, LPCHOOSEFONTA chf32a
)
58 chf32a
->lStructSize
=sizeof(CHOOSEFONTA
);
59 chf32a
->hwndOwner
=chf16
->hwndOwner
;
60 chf32a
->hDC
=chf16
->hDC
;
61 chf32a
->iPointSize
=chf16
->iPointSize
;
62 chf32a
->Flags
=chf16
->Flags
;
63 chf32a
->rgbColors
=chf16
->rgbColors
;
64 chf32a
->lCustData
=chf16
->lCustData
;
65 chf32a
->lpfnHook
=NULL
;
66 chf32a
->lpTemplateName
=MapSL(chf16
->lpTemplateName
);
67 chf32a
->hInstance
=chf16
->hInstance
;
68 chf32a
->lpszStyle
=MapSL(chf16
->lpszStyle
);
69 chf32a
->nFontType
=chf16
->nFontType
;
70 chf32a
->nSizeMax
=chf16
->nSizeMax
;
71 chf32a
->nSizeMin
=chf16
->nSizeMin
;
72 FONT_LogFont16To32A(MapSL(chf16
->lpLogFont
), chf32a
->lpLogFont
);
79 #define XX(x) { x, #x },
85 XX(CF_ENABLETEMPLATEHANDLE
)
86 XX(CF_INITTOLOGFONTSTRUCT
)
110 _dump_cf_flags(DWORD cflags
) {
113 for (i
=0;cfflags
[i
].name
;i
++)
114 if (cfflags
[i
].mask
& cflags
)
115 MESSAGE("%s|",cfflags
[i
].name
);
120 /***********************************************************************
121 * ChooseFont16 (COMMDLG.15)
123 BOOL16 WINAPI
ChooseFont16(LPCHOOSEFONT16 lpChFont
)
126 HANDLE16 hDlgTmpl16
= 0, hResource16
= 0;
127 HGLOBAL16 hGlobal16
= 0;
134 SEGPTR lpTemplateName
;
136 cf32a
.lpLogFont
=&lf32a
;
137 CFn_CHOOSEFONT16to32A(lpChFont
, &cf32a
);
139 TRACE("ChooseFont\n");
140 if (!lpChFont
) return FALSE
;
142 if (TRACE_ON(commdlg
))
143 _dump_cf_flags(lpChFont
->Flags
);
145 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
)
147 if (!(template = LockResource16( lpChFont
->hInstance
)))
149 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
153 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
156 if (!(hResInfo
= FindResource16( lpChFont
->hInstance
,
157 MapSL(lpChFont
->lpTemplateName
),
160 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
163 if (!(hDlgTmpl16
= LoadResource16( lpChFont
->hInstance
, hResInfo
)) ||
164 !(template = LockResource16( hDlgTmpl16
)))
166 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
172 HANDLE hResInfo
, hDlgTmpl32
;
175 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
177 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
180 if (!(hDlgTmpl32
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
181 !(template32
= LockResource(hDlgTmpl32
)))
183 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
186 size
= SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo
);
187 hGlobal16
= GlobalAlloc16(0, size
);
190 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
191 ERR("alloc failure for %ld bytes\n", size
);
194 template = GlobalLock16(hGlobal16
);
197 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
198 ERR("global lock failure for %x handle\n", hGlobal16
);
199 GlobalFree16(hGlobal16
);
202 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
203 hDlgTmpl16
= hGlobal16
;
207 /* lpTemplateName is not used in the dialog */
208 lpTemplateName
=lpChFont
->lpTemplateName
;
209 lpChFont
->lpTemplateName
=(SEGPTR
)&cf32a
;
211 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 16);
212 hInst
= GetWindowLongA(lpChFont
->hwndOwner
, GWL_HINSTANCE
);
213 bRet
= DialogBoxIndirectParam16(hInst
, hDlgTmpl16
, lpChFont
->hwndOwner
,
214 (DLGPROC16
) ptr
, (DWORD
)lpChFont
);
215 if (hResource16
) FreeResource16(hDlgTmpl16
);
218 GlobalUnlock16(hGlobal16
);
219 GlobalFree16(hGlobal16
);
221 lpChFont
->lpTemplateName
=lpTemplateName
;
224 font16
= MapSL(lpChFont
->lpLogFont
);
225 font16
->lfHeight
= cf32a
.lpLogFont
->lfHeight
;
226 font16
->lfWidth
= cf32a
.lpLogFont
->lfWidth
;
227 font16
->lfEscapement
= cf32a
.lpLogFont
->lfEscapement
;
228 font16
->lfOrientation
= cf32a
.lpLogFont
->lfOrientation
;
229 font16
->lfWeight
= cf32a
.lpLogFont
->lfWeight
;
230 font16
->lfItalic
= cf32a
.lpLogFont
->lfItalic
;
231 font16
->lfUnderline
= cf32a
.lpLogFont
->lfUnderline
;
232 font16
->lfStrikeOut
= cf32a
.lpLogFont
->lfStrikeOut
;
233 font16
->lfCharSet
= cf32a
.lpLogFont
->lfCharSet
;
234 font16
->lfOutPrecision
= cf32a
.lpLogFont
->lfOutPrecision
;
235 font16
->lfClipPrecision
= cf32a
.lpLogFont
->lfClipPrecision
;
236 font16
->lfQuality
= cf32a
.lpLogFont
->lfQuality
;
237 font16
->lfPitchAndFamily
= cf32a
.lpLogFont
->lfPitchAndFamily
;
238 lstrcpynA( font16
->lfFaceName
, cf32a
.lpLogFont
->lfFaceName
, LF_FACESIZE
);
243 /***********************************************************************
244 * ChooseFontA (COMDLG32.3)
246 BOOL WINAPI
ChooseFontA(LPCHOOSEFONTA lpChFont
)
249 HANDLE hResInfo
, hDlgTmpl
;
251 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
253 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
256 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
257 !(template = LockResource( hDlgTmpl
)))
259 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
262 if (TRACE_ON(commdlg
))
263 _dump_cf_flags(lpChFont
->Flags
);
265 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
266 CF_ENABLETEMPLATEHANDLE
)) FIXME(": unimplemented flag (ignored)\n");
267 return DialogBoxIndirectParamA(COMMDLG_hInstance32
, template,
268 lpChFont
->hwndOwner
, (DLGPROC
)FormatCharDlgProcA
, (LPARAM
)lpChFont
);
271 /***********************************************************************
272 * ChooseFontW (COMDLG32.4)
274 BOOL WINAPI
ChooseFontW(LPCHOOSEFONTW lpChFont
)
280 HANDLE hResInfo
, hDlgTmpl
;
282 if (TRACE_ON(commdlg
))
283 _dump_cf_flags(lpChFont
->Flags
);
285 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
287 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
290 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
291 !(template = LockResource( hDlgTmpl
)))
293 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
297 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
298 CF_ENABLETEMPLATEHANDLE
)) FIXME(": unimplemented flag (ignored)\n");
299 memcpy(&cf32a
, lpChFont
, sizeof(cf32a
));
300 memcpy(&lf32a
, lpChFont
->lpLogFont
, sizeof(LOGFONTA
));
302 WideCharToMultiByte( CP_ACP
, 0, lpChFont
->lpLogFont
->lfFaceName
, -1,
303 lf32a
.lfFaceName
, LF_FACESIZE
, NULL
, NULL
);
304 lf32a
.lfFaceName
[LF_FACESIZE
-1] = 0;
305 cf32a
.lpLogFont
=&lf32a
;
306 cf32a
.lpszStyle
=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont
->lpszStyle
);
307 lpChFont
->lpTemplateName
=(LPWSTR
)&cf32a
;
308 bRet
= DialogBoxIndirectParamW(COMMDLG_hInstance32
, template,
309 lpChFont
->hwndOwner
, (DLGPROC
)FormatCharDlgProcW
, (LPARAM
)lpChFont
);
310 HeapFree(GetProcessHeap(), 0, cf32a
.lpszStyle
);
311 lpChFont
->lpTemplateName
=(LPWSTR
)cf32a
.lpTemplateName
;
312 memcpy(lpChFont
->lpLogFont
, &lf32a
, sizeof(CHOOSEFONTA
));
313 MultiByteToWideChar( CP_ACP
, 0, lf32a
.lfFaceName
, -1,
314 lpChFont
->lpLogFont
->lfFaceName
, LF_FACESIZE
);
315 lpChFont
->lpLogFont
->lfFaceName
[LF_FACESIZE
-1] = 0;
320 #define TEXT_EXTRAS 4
321 #define TEXT_COLORS 16
323 static const COLORREF textcolors
[TEXT_COLORS
]=
325 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
326 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
327 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
328 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
331 /***********************************************************************
332 * CFn_HookCallChk [internal]
334 static BOOL
CFn_HookCallChk(LPCHOOSEFONT16 lpcf
)
337 if(lpcf
->Flags
& CF_ENABLEHOOK
)
343 /***********************************************************************
344 * CFn_HookCallChk32 [internal]
346 static BOOL
CFn_HookCallChk32(LPCHOOSEFONTA lpcf
)
349 if(lpcf
->Flags
& CF_ENABLEHOOK
)
359 LPCHOOSEFONTA lpcf32a
;
361 } CFn_ENUMSTRUCT
, *LPCFn_ENUMSTRUCT
;
363 /*************************************************************************
364 * AddFontFamily [internal]
366 static INT
AddFontFamily(const LOGFONTA
*lplf
, UINT nFontType
,
367 LPCHOOSEFONTA lpcf
, HWND hwnd
, LPCFn_ENUMSTRUCT e
)
372 TRACE("font=%s (nFontType=%d)\n", lplf
->lfFaceName
,nFontType
);
374 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
375 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
377 if (lpcf
->Flags
& CF_ANSIONLY
)
378 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
380 if (lpcf
->Flags
& CF_TTONLY
)
381 if (!(nFontType
& TRUETYPE_FONTTYPE
))
386 i
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)lplf
->lfFaceName
);
389 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
390 SendMessageA(hwnd
, CB_SETITEMDATA
, i
, MAKELONG(nFontType
,w
));
391 return 1 ; /* store some important font information */
397 /*************************************************************************
398 * FontFamilyEnumProc32 [internal]
400 static INT WINAPI
FontFamilyEnumProc(const LOGFONTA
*lpLogFont
,
401 const TEXTMETRICA
*metrics
, DWORD dwFontType
, LPARAM lParam
)
404 e
=(LPCFn_ENUMSTRUCT
)lParam
;
405 return AddFontFamily(lpLogFont
, dwFontType
, e
->lpcf32a
, e
->hWnd1
, e
);
408 /***********************************************************************
409 * FontFamilyEnumProc16 (COMMDLG.19)
411 INT16 WINAPI
FontFamilyEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
412 UINT16 nFontType
, LPARAM lParam
)
414 HWND16 hwnd
=LOWORD(lParam
);
415 HWND hDlg
=GetParent(hwnd
);
416 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
417 LOGFONT16
*lplf
= MapSL( logfont
);
419 FONT_LogFont16To32A(lplf
, &lf32a
);
420 return AddFontFamily(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
424 /*************************************************************************
425 * SetFontStylesToCombo2 [internal]
427 * Fill font style information into combobox (without using font.c directly)
429 static int SetFontStylesToCombo2(HWND hwnd
, HDC hdc
, const LOGFONTA
*lplf
)
436 static struct FONTSTYLE fontstyles
[FSTYLES
]={
437 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
438 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
444 memcpy(&lf
, lplf
, sizeof(LOGFONTA
));
446 for (i
=0;i
<FSTYLES
;i
++)
448 lf
.lfItalic
=fontstyles
[i
].italic
;
449 lf
.lfWeight
=fontstyles
[i
].weight
;
450 hf
=CreateFontIndirectA(&lf
);
451 hf
=SelectObject(hdc
,hf
);
452 GetTextMetricsA(hdc
,&tm
);
453 hf
=SelectObject(hdc
,hf
);
456 if (tm
.tmWeight
==fontstyles
[i
].weight
&&
457 tm
.tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
459 j
=SendMessageA(hwnd
,CB_ADDSTRING
,0,(LPARAM
)fontstyles
[i
].stname
);
460 if (j
==CB_ERR
) return 1;
461 j
=SendMessageA(hwnd
, CB_SETITEMDATA
, j
,
462 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
463 if (j
==CB_ERR
) return 1;
469 /*************************************************************************
470 * AddFontSizeToCombo3 [internal]
472 static int AddFontSizeToCombo3(HWND hwnd
, UINT h
, LPCHOOSEFONTA lpcf
)
477 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
478 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
480 sprintf(buffer
, "%2d", h
);
481 j
=SendMessageA(hwnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buffer
);
484 j
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
485 if (j
!=CB_ERR
) j
= SendMessageA(hwnd
, CB_SETITEMDATA
, j
, h
);
486 if (j
==CB_ERR
) return 1;
492 /*************************************************************************
493 * SetFontSizesToCombo3 [internal]
495 static int SetFontSizesToCombo3(HWND hwnd
, LPCHOOSEFONTA lpcf
)
497 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
500 for (i
=0; sizes
[i
]; i
++)
501 if (AddFontSizeToCombo3(hwnd
, sizes
[i
], lpcf
)) return 1;
505 /***********************************************************************
506 * AddFontStyle [internal]
508 static INT
AddFontStyle(const LOGFONTA
*lplf
, UINT nFontType
,
509 LPCHOOSEFONTA lpcf
, HWND hcmb2
, HWND hcmb3
, HWND hDlg
)
513 TRACE("(nFontType=%d)\n",nFontType
);
514 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
515 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
516 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,
517 lplf
->lfEscapement
,lplf
->lfOrientation
,
518 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,
519 lplf
->lfStrikeOut
,lplf
->lfCharSet
, lplf
->lfOutPrecision
,
520 lplf
->lfClipPrecision
,lplf
->lfQuality
, lplf
->lfPitchAndFamily
);
521 if (nFontType
& RASTER_FONTTYPE
)
523 if (AddFontSizeToCombo3(hcmb3
, lplf
->lfHeight
, lpcf
)) return 0;
524 } else if (SetFontSizesToCombo3(hcmb3
, lpcf
)) return 0;
526 if (!SendMessageA(hcmb2
, CB_GETCOUNT
, 0, 0))
528 HDC hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
529 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
);
530 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
539 /***********************************************************************
540 * FontStyleEnumProc16 (COMMDLG.18)
542 INT16 WINAPI
FontStyleEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
543 UINT16 nFontType
, LPARAM lParam
)
545 HWND16 hcmb2
=LOWORD(lParam
);
546 HWND16 hcmb3
=HIWORD(lParam
);
547 HWND hDlg
=GetParent(hcmb3
);
548 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
549 LOGFONT16
*lplf
= MapSL(logfont
);
551 FONT_LogFont16To32A(lplf
, &lf32a
);
552 return AddFontStyle(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
556 /***********************************************************************
557 * FontStyleEnumProc32 [internal]
559 static INT WINAPI
FontStyleEnumProc( const LOGFONTA
*lpFont
,
560 const TEXTMETRICA
*metrics
, DWORD dwFontType
, LPARAM lParam
)
562 LPCFn_ENUMSTRUCT s
=(LPCFn_ENUMSTRUCT
)lParam
;
565 HWND hDlg
=GetParent(hcmb3
);
566 return AddFontStyle(lpFont
, dwFontType
, s
->lpcf32a
, hcmb2
,
570 /***********************************************************************
571 * CFn_WMInitDialog [internal]
573 static LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
580 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
582 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
583 lpxx
=lpcf
->lpLogFont
;
584 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
586 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONTA
))
588 ERR("structure size failure !!!\n");
593 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
595 /* This font will be deleted by WM_COMMAND */
596 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,
597 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL
),FALSE
);
599 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
600 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
601 if (!(lpcf
->Flags
& CF_APPLY
))
602 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
603 if (lpcf
->Flags
& CF_EFFECTS
)
605 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
607 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
609 strcpy( name
, "[color name]" );
610 j
=SendDlgItemMessageA(hDlg
, cmb4
, CB_ADDSTRING
, 0, (LPARAM
)name
);
611 SendDlgItemMessageA(hDlg
, cmb4
, CB_SETITEMDATA16
, j
, textcolors
[j
]);
612 /* look for a fitting value in color combobox */
613 if (textcolors
[j
]==lpcf
->rgbColors
)
614 SendDlgItemMessageA(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
619 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
620 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
621 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
622 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
623 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
625 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
629 s
.hWnd1
=GetDlgItem(hDlg
,cmb1
);
633 if (!EnumFontFamiliesA(hdc
, NULL
, FontFamilyEnumProc
, (LPARAM
)&s
)) {
634 TRACE("EnumFontFamilies returns 0\n");
638 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
) {
639 FIXME("No founds found with fixed pitch only, dropping flag.\n");
640 lpcf
->Flags
&= ~CF_FIXEDPITCHONLY
;
643 if (lpcf
->Flags
& CF_TTONLY
) {
644 FIXME("No founds found with truetype only, dropping flag.\n");
645 lpcf
->Flags
&= ~CF_TTONLY
;
652 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
654 /* look for fitting font name in combobox1 */
655 j
=SendDlgItemMessageA(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
658 SendDlgItemMessageA(hDlg
, cmb1
, CB_SETCURSEL
, j
, 0);
659 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
660 GetDlgItem(hDlg
,cmb1
));
662 /* look for fitting font style in combobox2 */
663 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
664 for (i
=0;i
<TEXT_EXTRAS
;i
++)
666 if (l
==SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0))
667 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
670 /* look for fitting font size in combobox3 */
671 j
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCOUNT
, 0, 0);
674 if (lpxx
->lfHeight
==(int)SendDlgItemMessageA(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
675 SendDlgItemMessageA(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
681 SendDlgItemMessageA(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
682 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
683 GetDlgItem(hDlg
,cmb1
));
685 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
687 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
690 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
691 SendMessageA(hDlg
,WM_COMMAND
,cmb2
,
692 MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
698 WARN("HDC failure !!!\n");
703 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
710 /***********************************************************************
711 * CFn_WMMeasureItem [internal]
713 static LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
716 LPMEASUREITEMSTRUCT lpmi
=(LPMEASUREITEMSTRUCT
)lParam
;
718 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
719 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
720 lpmi
->itemHeight
=bm
.bmHeight
;
721 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
726 /***********************************************************************
727 * CFn_WMDrawItem [internal]
729 static LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
734 COLORREF cr
, oldText
=0, oldBk
=0;
739 HBITMAP hBitmap
; /* for later TT usage */
741 LPDRAWITEMSTRUCT lpdi
= (LPDRAWITEMSTRUCT
)lParam
;
743 if (lpdi
->itemID
== 0xFFFF) /* got no items */
744 DrawFocusRect(lpdi
->hDC
, &lpdi
->rcItem
);
747 if (lpdi
->CtlType
== ODT_COMBOBOX
)
749 if (lpdi
->itemState
==ODS_SELECTED
)
751 hBrush
=GetSysColorBrush(COLOR_HIGHLIGHT
);
752 oldText
=SetTextColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
753 oldBk
=SetBkColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHT
));
756 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
757 SelectObject(lpdi
->hDC
, hBrush
);
759 FillRect(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
762 return TRUE
; /* this should never happen */
767 case cmb1
: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
768 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
770 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
771 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
772 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
774 nFontType
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
775 /* FIXME: draw bitmap if truetype usage */
776 if (nFontType
&TRUETYPE_FONTTYPE
)
778 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
779 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
780 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
781 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
782 SelectObject(hMemDC
, hBitmap
);
788 case cmb3
: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
789 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
791 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
,
792 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
795 case cmb4
: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
796 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
798 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
799 lpdi
->rcItem
.top
, buffer
, strlen(buffer
));
800 cr
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
801 hBrush
= CreateSolidBrush(cr
);
804 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
805 rect
.right
=rect
.left
+25;
809 Rectangle( lpdi
->hDC
, rect
.left
, rect
.top
,
810 rect
.right
, rect
.bottom
);
811 DeleteObject( SelectObject (lpdi
->hDC
, hBrush
)) ;
817 default: return TRUE
; /* this should never happen */
819 if (lpdi
->itemState
== ODS_SELECTED
)
821 SetTextColor(lpdi
->hDC
, oldText
);
822 SetBkColor(lpdi
->hDC
, oldBk
);
828 /***********************************************************************
829 * CFn_WMCtlColor [internal]
831 static LRESULT
CFn_WMCtlColorStatic(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
834 if (lpcf
->Flags
& CF_EFFECTS
)
835 if (GetDlgCtrlID(lParam
)==stc6
)
837 SetTextColor((HDC
)wParam
, lpcf
->rgbColors
);
838 return GetStockObject(WHITE_BRUSH
);
843 /***********************************************************************
844 * CFn_WMCommand [internal]
846 static LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
853 LPLOGFONTA lpxx
=lpcf
->lpLogFont
;
855 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG
)wParam
, lParam
);
856 switch (LOWORD(wParam
))
858 case cmb1
:if (HIWORD(wParam
)==CBN_SELCHANGE
)
860 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
863 SendDlgItemMessageA(hDlg
, cmb2
, CB_RESETCONTENT16
, 0, 0);
864 SendDlgItemMessageA(hDlg
, cmb3
, CB_RESETCONTENT16
, 0, 0);
865 i
=SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL16
, 0, 0);
868 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
871 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETLBTEXT
, i
,
873 TRACE("WM_COMMAND/cmb1 =>%s\n",str
);
874 s
.hWnd1
=GetDlgItem(hDlg
, cmb2
);
875 s
.hWnd2
=GetDlgItem(hDlg
, cmb3
);
877 EnumFontFamiliesA(hdc
, str
, FontStyleEnumProc
, (LPARAM
)&s
);
878 SendDlgItemMessageA(hDlg
,cmb2
, CB_SETCURSEL
, 0, 0);
879 SendDlgItemMessageA(hDlg
,cmb3
, CB_SETCURSEL
, 0, 0);
882 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
887 WARN("HDC failure !!!\n");
895 case cmb3
:if (HIWORD(wParam
)==CBN_SELCHANGE
|| HIWORD(wParam
)== BN_CLICKED
)
898 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
899 i
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
901 i
=GetDlgItemTextA( hDlg
, cmb1
, str
, 256 );
904 SendDlgItemMessageA(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
906 l
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
908 lpcf
->nFontType
= LOWORD(l
);
909 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
910 /* same value reported to the EnumFonts
911 call back with the extra FONTTYPE_... bits added */
912 lpxx
->lfPitchAndFamily
=j
&0xff;
913 lpxx
->lfCharSet
=j
>>8;
915 strcpy(lpxx
->lfFaceName
,str
);
916 i
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
919 l
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0);
920 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
921 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
922 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
923 lpcf
->nFontType
|= BOLD_FONTTYPE
;
925 i
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
927 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessageA(hDlg
, cmb3
, CB_GETITEMDATA
, i
, 0));
930 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
931 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
932 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
933 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
934 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
935 lpxx
->lfQuality
=DEFAULT_QUALITY
;
936 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
938 hFont
=CreateFontIndirectA(lpxx
);
941 HFONT oldFont
=SendDlgItemMessageA(hDlg
, stc6
,
943 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
944 DeleteObject(oldFont
);
949 case cmb4
:i
=SendDlgItemMessageA(hDlg
, cmb4
, CB_GETCURSEL
, 0, 0);
952 lpcf
->rgbColors
=textcolors
[i
];
953 InvalidateRect( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
957 case psh15
:i
=RegisterWindowMessageA( HELPMSGSTRINGA
);
959 SendMessageA(lpcf
->hwndOwner
, i
, 0, (LPARAM
)GetWindowLongA(hDlg
, DWL_USER
));
960 /* if (CFn_HookCallChk(lpcf))
961 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
964 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
965 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
966 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
967 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
968 EndDialog(hDlg
, TRUE
);
972 sprintf(buffer
,"Select a font size between %d and %d points.",
973 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
974 MessageBoxA(hDlg
, buffer
, NULL
, MB_OK
);
977 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
983 static LRESULT
CFn_WMDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
985 DeleteObject(SendDlgItemMessageA(hwnd
, stc6
, WM_GETFONT
, 0, 0));
990 /***********************************************************************
991 * FormatCharDlgProc16 (COMMDLG.16)
992 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
993 2. some CF_.. flags are not supported
994 3. some TType extensions
996 LRESULT WINAPI
FormatCharDlgProc16(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
,
1000 LPCHOOSEFONTA lpcf32a
;
1002 if (message
!=WM_INITDIALOG
)
1004 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
1007 if (CFn_HookCallChk(lpcf
))
1008 res
=CallWindowProc16((WNDPROC16
)lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
1014 lpcf
=(LPCHOOSEFONT16
)lParam
;
1015 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
1016 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
1018 TRACE("CFn_WMInitDialog returned FALSE\n");
1021 if (CFn_HookCallChk(lpcf
))
1022 return CallWindowProc16((WNDPROC16
)lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1024 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
1027 case WM_MEASUREITEM
:
1029 MEASUREITEMSTRUCT16
* mis16
= MapSL(lParam
);
1030 MEASUREITEMSTRUCT mis
;
1031 mis
.CtlType
= mis16
->CtlType
;
1032 mis
.CtlID
= mis16
->CtlID
;
1033 mis
.itemID
= mis16
->itemID
;
1034 mis
.itemWidth
= mis16
->itemWidth
;
1035 mis
.itemHeight
= mis16
->itemHeight
;
1036 mis
.itemData
= mis16
->itemData
;
1037 res
= CFn_WMMeasureItem(hDlg
, wParam
, (LPARAM
)&mis
);
1038 mis16
->itemWidth
= (UINT16
)mis
.itemWidth
;
1039 mis16
->itemHeight
= (UINT16
)mis
.itemHeight
;
1044 DRAWITEMSTRUCT16
* dis16
= MapSL(lParam
);
1046 dis
.CtlType
= dis16
->CtlType
;
1047 dis
.CtlID
= dis16
->CtlID
;
1048 dis
.itemID
= dis16
->itemID
;
1049 dis
.itemAction
= dis16
->itemAction
;
1050 dis
.itemState
= dis16
->itemState
;
1051 dis
.hwndItem
= dis16
->hwndItem
;
1052 dis
.hDC
= dis16
->hDC
;
1053 dis
.itemData
= dis16
->itemData
;
1054 CONV_RECT16TO32( &dis16
->rcItem
, &dis
.rcItem
);
1055 res
= CFn_WMDrawItem(hDlg
, wParam
, (LPARAM
)&dis
);
1059 if (HIWORD(lParam
) == CTLCOLOR_STATIC
)
1060 res
=CFn_WMCtlColorStatic(hDlg
, (HDC
)wParam
, (HWND
)LOWORD(lParam
), lpcf32a
);
1063 res
=CFn_WMCommand(hDlg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ), LOWORD(lParam
), lpcf32a
);
1066 res
=CFn_WMDestroy(hDlg
, wParam
, lParam
);
1068 case WM_CHOOSEFONT_GETLOGFONT
:
1069 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam
);
1070 FIXME("current logfont back to caller\n");
1076 /***********************************************************************
1077 * FormatCharDlgProcA [internal]
1079 LRESULT WINAPI
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1084 if (uMsg
!=WM_INITDIALOG
)
1086 lpcf
=(LPCHOOSEFONTA
)GetWindowLongA(hDlg
, DWL_USER
);
1089 if (CFn_HookCallChk32(lpcf
))
1090 res
=CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
1096 lpcf
=(LPCHOOSEFONTA
)lParam
;
1097 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf
))
1099 TRACE("CFn_WMInitDialog returned FALSE\n");
1102 if (CFn_HookCallChk32(lpcf
))
1103 return CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1107 case WM_MEASUREITEM
:
1108 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1110 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1111 case WM_CTLCOLORSTATIC
:
1112 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf
);
1114 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf
);
1116 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1117 case WM_CHOOSEFONT_GETLOGFONT
:
1118 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1120 FIXME("current logfont back to caller\n");
1126 /***********************************************************************
1127 * FormatCharDlgProcW [internal]
1129 LRESULT WINAPI
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1132 LPCHOOSEFONTW lpcf32w
;
1133 LPCHOOSEFONTA lpcf32a
;
1135 if (uMsg
!=WM_INITDIALOG
)
1137 lpcf32w
=(LPCHOOSEFONTW
)GetWindowLongA(hDlg
, DWL_USER
);
1140 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1141 res
=CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
1147 lpcf32w
=(LPCHOOSEFONTW
)lParam
;
1148 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1149 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
1151 TRACE("CFn_WMInitDialog returned FALSE\n");
1154 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1155 return CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1157 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1160 case WM_MEASUREITEM
:
1161 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1163 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1164 case WM_CTLCOLORSTATIC
:
1165 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf32a
);
1167 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf32a
);
1169 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1170 case WM_CHOOSEFONT_GETLOGFONT
:
1171 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1173 FIXME("current logfont back to caller\n");