2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
23 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(commdlg
);
32 static HBITMAP16 hBitmapTT
= 0;
35 LRESULT WINAPI
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
37 LRESULT WINAPI
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
41 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16
, LPCHOOSEFONTA chf32a
)
43 chf32a
->lStructSize
=sizeof(CHOOSEFONTA
);
44 chf32a
->hwndOwner
=chf16
->hwndOwner
;
45 chf32a
->hDC
=chf16
->hDC
;
46 chf32a
->iPointSize
=chf16
->iPointSize
;
47 chf32a
->Flags
=chf16
->Flags
;
48 chf32a
->rgbColors
=chf16
->rgbColors
;
49 chf32a
->lCustData
=chf16
->lCustData
;
50 chf32a
->lpfnHook
=NULL
;
51 chf32a
->lpTemplateName
=PTR_SEG_TO_LIN(chf16
->lpTemplateName
);
52 chf32a
->hInstance
=chf16
->hInstance
;
53 chf32a
->lpszStyle
=PTR_SEG_TO_LIN(chf16
->lpszStyle
);
54 chf32a
->nFontType
=chf16
->nFontType
;
55 chf32a
->nSizeMax
=chf16
->nSizeMax
;
56 chf32a
->nSizeMin
=chf16
->nSizeMin
;
57 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16
->lpLogFont
), chf32a
->lpLogFont
);
61 /***********************************************************************
62 * ChooseFont16 (COMMDLG.15)
64 BOOL16 WINAPI
ChooseFont16(LPCHOOSEFONT16 lpChFont
)
67 HANDLE16 hDlgTmpl
= 0;
68 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
73 SEGPTR lpTemplateName
;
75 cf32a
.lpLogFont
=&lf32a
;
76 CFn_CHOOSEFONT16to32A(lpChFont
, &cf32a
);
78 TRACE("ChooseFont\n");
79 if (!lpChFont
) return FALSE
;
81 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
)
83 if (!(template = LockResource16( lpChFont
->hInstance
)))
85 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
89 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
92 if (!(hResInfo
= FindResource16( lpChFont
->hInstance
,
93 lpChFont
->lpTemplateName
,
96 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
99 if (!(hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
)) ||
100 !(template = LockResource16( hDlgTmpl
)))
102 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
109 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
111 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
114 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
115 !(template = LockResource( hDlgTmpl
)))
117 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
123 hInst
= GetWindowLongA( lpChFont
->hwndOwner
, GWL_HINSTANCE
);
125 /* lpTemplateName is not used in the dialog */
126 lpTemplateName
=lpChFont
->lpTemplateName
;
127 lpChFont
->lpTemplateName
=(SEGPTR
)&cf32a
;
129 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
131 (DLGPROC16
)FormatCharDlgProcA
,
132 (DWORD
)lpChFont
, WIN_PROC_32A
);
133 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
134 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
135 lpChFont
->lpTemplateName
=lpTemplateName
;
136 FONT_LogFont32ATo16(cf32a
.lpLogFont
,
137 (LPLOGFONT16
)(PTR_SEG_TO_LIN(lpChFont
->lpLogFont
)));
142 /***********************************************************************
143 * ChooseFontA (COMDLG32.3)
145 BOOL WINAPI
ChooseFontA(LPCHOOSEFONTA lpChFont
)
149 HINSTANCE hInst
=GetWindowLongA( lpChFont
->hwndOwner
, GWL_HINSTANCE
);
151 HANDLE hResInfo
, hDlgTmpl
;
153 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
155 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
158 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
159 !(template = LockResource( hDlgTmpl
)))
161 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
165 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
166 CF_ENABLETEMPLATEHANDLE
)) FIXME(": unimplemented flag (ignored)\n");
167 hwndDialog
= DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
168 (DLGPROC16
)FormatCharDlgProcA
, (LPARAM
)lpChFont
, WIN_PROC_32A
);
169 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
173 /***********************************************************************
174 * ChooseFontW (COMDLG32.4)
176 BOOL WINAPI
ChooseFontW(LPCHOOSEFONTW lpChFont
)
180 HINSTANCE hInst
=GetWindowLongA( lpChFont
->hwndOwner
, GWL_HINSTANCE
);
184 HANDLE hResInfo
, hDlgTmpl
;
186 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
188 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
191 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
192 !(template = LockResource( hDlgTmpl
)))
194 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
198 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
199 CF_ENABLETEMPLATEHANDLE
)) FIXME(": unimplemented flag (ignored)\n");
200 memcpy(&cf32a
, lpChFont
, sizeof(cf32a
));
201 memcpy(&lf32a
, lpChFont
->lpLogFont
, sizeof(LOGFONTA
));
202 lstrcpynWtoA(lf32a
.lfFaceName
, lpChFont
->lpLogFont
->lfFaceName
, LF_FACESIZE
);
203 cf32a
.lpLogFont
=&lf32a
;
204 cf32a
.lpszStyle
=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont
->lpszStyle
);
205 lpChFont
->lpTemplateName
=(LPWSTR
)&cf32a
;
206 hwndDialog
=DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
207 (DLGPROC16
)FormatCharDlgProcW
, (LPARAM
)lpChFont
, WIN_PROC_32W
);
208 if (hwndDialog
)bRet
=DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
209 HeapFree(GetProcessHeap(), 0, cf32a
.lpszStyle
);
210 lpChFont
->lpTemplateName
=(LPWSTR
)cf32a
.lpTemplateName
;
211 memcpy(lpChFont
->lpLogFont
, &lf32a
, sizeof(CHOOSEFONTA
));
212 lstrcpynAtoW(lpChFont
->lpLogFont
->lfFaceName
, lf32a
.lfFaceName
, LF_FACESIZE
);
217 #define TEXT_EXTRAS 4
218 #define TEXT_COLORS 16
220 static const COLORREF textcolors
[TEXT_COLORS
]=
222 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
223 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
224 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
225 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
228 /***********************************************************************
229 * CFn_HookCallChk [internal]
231 static BOOL
CFn_HookCallChk(LPCHOOSEFONT16 lpcf
)
234 if(lpcf
->Flags
& CF_ENABLEHOOK
)
240 /***********************************************************************
241 * CFn_HookCallChk32 [internal]
243 static BOOL
CFn_HookCallChk32(LPCHOOSEFONTA lpcf
)
246 if(lpcf
->Flags
& CF_ENABLEHOOK
)
253 /*************************************************************************
254 * AddFontFamily [internal]
256 static INT
AddFontFamily(LPLOGFONTA lplf
, UINT nFontType
,
257 LPCHOOSEFONTA lpcf
, HWND hwnd
)
262 TRACE("font=%s (nFontType=%d)\n", lplf
->lfFaceName
,nFontType
);
264 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
265 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
267 if (lpcf
->Flags
& CF_ANSIONLY
)
268 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
270 if (lpcf
->Flags
& CF_TTONLY
)
271 if (!(nFontType
& TRUETYPE_FONTTYPE
))
274 i
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)lplf
->lfFaceName
);
277 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
278 SendMessageA(hwnd
, CB_SETITEMDATA
, i
, MAKELONG(nFontType
,w
));
279 return 1 ; /* store some important font information */
289 LPCHOOSEFONTA lpcf32a
;
290 } CFn_ENUMSTRUCT
, *LPCFn_ENUMSTRUCT
;
292 /*************************************************************************
293 * FontFamilyEnumProc32 [internal]
295 static INT WINAPI
FontFamilyEnumProc(LPENUMLOGFONTA lpEnumLogFont
,
296 LPNEWTEXTMETRICA metrics
, UINT nFontType
, LPARAM lParam
)
299 e
=(LPCFn_ENUMSTRUCT
)lParam
;
300 return AddFontFamily(&lpEnumLogFont
->elfLogFont
, nFontType
, e
->lpcf32a
, e
->hWnd1
);
303 /***********************************************************************
304 * FontFamilyEnumProc16 (COMMDLG.19)
306 INT16 WINAPI
FontFamilyEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
307 UINT16 nFontType
, LPARAM lParam
)
309 HWND16 hwnd
=LOWORD(lParam
);
310 HWND16 hDlg
=GetParent16(hwnd
);
311 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
312 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN( logfont
);
314 FONT_LogFont16To32A(lplf
, &lf32a
);
315 return AddFontFamily(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
319 /*************************************************************************
320 * SetFontStylesToCombo2 [internal]
322 * Fill font style information into combobox (without using font.c directly)
324 static int SetFontStylesToCombo2(HWND hwnd
, HDC hdc
, LPLOGFONTA lplf
)
331 static struct FONTSTYLE fontstyles
[FSTYLES
]={
332 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
333 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
338 for (i
=0;i
<FSTYLES
;i
++)
340 lplf
->lfItalic
=fontstyles
[i
].italic
;
341 lplf
->lfWeight
=fontstyles
[i
].weight
;
342 hf
=CreateFontIndirectA(lplf
);
343 hf
=SelectObject(hdc
,hf
);
344 GetTextMetrics16(hdc
,&tm
);
345 hf
=SelectObject(hdc
,hf
);
348 if (tm
.tmWeight
==fontstyles
[i
].weight
&&
349 tm
.tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
351 char *str
= SEGPTR_STRDUP(fontstyles
[i
].stname
);
352 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(str
) );
354 if (j
==CB_ERR
) return 1;
355 j
=SendMessage16(hwnd
, CB_SETITEMDATA16
, j
,
356 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
357 if (j
==CB_ERR
) return 1;
363 /*************************************************************************
364 * AddFontSizeToCombo3 [internal]
366 static int AddFontSizeToCombo3(HWND hwnd
, UINT h
, LPCHOOSEFONTA lpcf
)
371 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
372 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
374 sprintf(buffer
, "%2d", h
);
375 j
=SendMessageA(hwnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buffer
);
378 j
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
379 if (j
!=CB_ERR
) j
= SendMessageA(hwnd
, CB_SETITEMDATA
, j
, h
);
380 if (j
==CB_ERR
) return 1;
386 /*************************************************************************
387 * SetFontSizesToCombo3 [internal]
389 static int SetFontSizesToCombo3(HWND hwnd
, LPCHOOSEFONTA lpcf
)
391 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
394 for (i
=0; sizes
[i
]; i
++)
395 if (AddFontSizeToCombo3(hwnd
, sizes
[i
], lpcf
)) return 1;
399 /***********************************************************************
400 * AddFontStyle [internal]
402 static INT
AddFontStyle(LPLOGFONTA lplf
, UINT nFontType
,
403 LPCHOOSEFONTA lpcf
, HWND hcmb2
, HWND hcmb3
, HWND hDlg
)
407 TRACE("(nFontType=%d)\n",nFontType
);
408 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
409 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
410 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,
411 lplf
->lfEscapement
,lplf
->lfOrientation
,
412 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,
413 lplf
->lfStrikeOut
,lplf
->lfCharSet
, lplf
->lfOutPrecision
,
414 lplf
->lfClipPrecision
,lplf
->lfQuality
, lplf
->lfPitchAndFamily
);
415 if (nFontType
& RASTER_FONTTYPE
)
417 if (AddFontSizeToCombo3(hcmb3
, lplf
->lfHeight
, lpcf
)) return 0;
418 } else if (SetFontSizesToCombo3(hcmb3
, lpcf
)) return 0;
420 if (!SendMessageA(hcmb2
, CB_GETCOUNT
, 0, 0))
422 HDC hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
423 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
);
424 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
433 /***********************************************************************
434 * FontStyleEnumProc16 (COMMDLG.18)
436 INT16 WINAPI
FontStyleEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
437 UINT16 nFontType
, LPARAM lParam
)
439 HWND16 hcmb2
=LOWORD(lParam
);
440 HWND16 hcmb3
=HIWORD(lParam
);
441 HWND16 hDlg
=GetParent16(hcmb3
);
442 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
443 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN(logfont
);
445 FONT_LogFont16To32A(lplf
, &lf32a
);
446 return AddFontStyle(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
450 /***********************************************************************
451 * FontStyleEnumProc32 [internal]
453 static INT WINAPI
FontStyleEnumProc( LPENUMLOGFONTA lpFont
,
454 LPNEWTEXTMETRICA metrics
, UINT nFontType
, LPARAM lParam
)
456 LPCFn_ENUMSTRUCT s
=(LPCFn_ENUMSTRUCT
)lParam
;
459 HWND hDlg
=GetParent(hcmb3
);
460 return AddFontStyle(&lpFont
->elfLogFont
, nFontType
, s
->lpcf32a
, hcmb2
,
464 /***********************************************************************
465 * CFn_WMInitDialog [internal]
467 static LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
474 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
476 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
477 lpxx
=lpcf
->lpLogFont
;
478 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
480 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONTA
))
482 ERR("structure size failure !!!\n");
487 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
489 /* This font will be deleted by WM_COMMAND */
490 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,
491 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL
),FALSE
);
493 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
494 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
495 if (!(lpcf
->Flags
& CF_APPLY
))
496 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
497 if (lpcf
->Flags
& CF_EFFECTS
)
499 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
501 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
503 strcpy( name
, "[color name]" );
504 j
=SendDlgItemMessageA(hDlg
, cmb4
, CB_ADDSTRING
, 0, (LPARAM
)name
);
505 SendDlgItemMessageA(hDlg
, cmb4
, CB_SETITEMDATA16
, j
, textcolors
[j
]);
506 /* look for a fitting value in color combobox */
507 if (textcolors
[j
]==lpcf
->rgbColors
)
508 SendDlgItemMessageA(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
513 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
514 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
515 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
516 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
517 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
519 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
523 s
.hWnd1
=GetDlgItem(hDlg
,cmb1
);
525 if (!EnumFontFamiliesA(hdc
, NULL
, FontFamilyEnumProc
, (LPARAM
)&s
))
526 TRACE("EnumFontFamilies returns 0\n");
527 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
529 /* look for fitting font name in combobox1 */
530 j
=SendDlgItemMessageA(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
533 SendDlgItemMessageA(hDlg
, cmb1
, CB_SETCURSEL
, j
, 0);
534 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
535 GetDlgItem(hDlg
,cmb1
));
537 /* look for fitting font style in combobox2 */
538 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
539 for (i
=0;i
<TEXT_EXTRAS
;i
++)
541 if (l
==SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0))
542 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
545 /* look for fitting font size in combobox3 */
546 j
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCOUNT
, 0, 0);
549 if (lpxx
->lfHeight
==(int)SendDlgItemMessageA(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
550 SendDlgItemMessageA(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
556 SendDlgItemMessageA(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
557 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
558 GetDlgItem(hDlg
,cmb1
));
560 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
562 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
565 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
566 SendMessageA(hDlg
,WM_COMMAND
,cmb2
,
567 MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
573 WARN("HDC failure !!!\n");
578 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
585 /***********************************************************************
586 * CFn_WMMeasureItem [internal]
588 static LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
591 LPMEASUREITEMSTRUCT lpmi
=(LPMEASUREITEMSTRUCT
)lParam
;
593 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
594 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
595 lpmi
->itemHeight
=bm
.bmHeight
;
596 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
601 /***********************************************************************
602 * CFn_WMDrawItem [internal]
604 static LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
609 COLORREF cr
, oldText
=0, oldBk
=0;
614 HBITMAP hBitmap
; /* for later TT usage */
616 LPDRAWITEMSTRUCT lpdi
= (LPDRAWITEMSTRUCT
)lParam
;
618 if (lpdi
->itemID
== 0xFFFF) /* got no items */
619 DrawFocusRect(lpdi
->hDC
, &lpdi
->rcItem
);
622 if (lpdi
->CtlType
== ODT_COMBOBOX
)
624 if (lpdi
->itemState
==ODS_SELECTED
)
626 hBrush
=GetSysColorBrush(COLOR_HIGHLIGHT
);
627 oldText
=SetTextColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
628 oldBk
=SetBkColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHT
));
631 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
632 SelectObject(lpdi
->hDC
, hBrush
);
634 FillRect(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
637 return TRUE
; /* this should never happen */
642 case cmb1
: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
643 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
645 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
646 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
647 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
649 nFontType
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
650 /* FIXME: draw bitmap if truetype usage */
651 if (nFontType
&TRUETYPE_FONTTYPE
)
653 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
654 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
655 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
656 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
657 SelectObject(hMemDC
, hBitmap
);
663 case cmb3
: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
664 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
666 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
,
667 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
670 case cmb4
: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
671 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
673 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
674 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
675 cr
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
676 hBrush
= CreateSolidBrush(cr
);
679 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
680 rect
.right
=rect
.left
+25;
684 Rectangle( lpdi
->hDC
, rect
.left
, rect
.top
,
685 rect
.right
, rect
.bottom
);
686 DeleteObject( SelectObject (lpdi
->hDC
, hBrush
)) ;
692 default: return TRUE
; /* this should never happen */
694 if (lpdi
->itemState
== ODS_SELECTED
)
696 SetTextColor(lpdi
->hDC
, oldText
);
697 SetBkColor(lpdi
->hDC
, oldBk
);
703 /***********************************************************************
704 * CFn_WMCtlColor [internal]
706 static LRESULT
CFn_WMCtlColorStatic(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
709 if (lpcf
->Flags
& CF_EFFECTS
)
710 if (GetDlgCtrlID(lParam
)==stc6
)
712 SetTextColor((HDC
)wParam
, lpcf
->rgbColors
);
713 return GetStockObject(WHITE_BRUSH
);
718 /***********************************************************************
719 * CFn_WMCommand [internal]
721 static LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
728 LPLOGFONTA lpxx
=lpcf
->lpLogFont
;
730 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG
)wParam
, lParam
);
731 switch (LOWORD(wParam
))
733 case cmb1
:if (HIWORD(wParam
)==CBN_SELCHANGE
)
735 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
738 SendDlgItemMessageA(hDlg
, cmb2
, CB_RESETCONTENT16
, 0, 0);
739 SendDlgItemMessageA(hDlg
, cmb3
, CB_RESETCONTENT16
, 0, 0);
740 i
=SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL16
, 0, 0);
743 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
746 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETLBTEXT
, i
,
748 TRACE("WM_COMMAND/cmb1 =>%s\n",str
);
749 s
.hWnd1
=GetDlgItem(hDlg
, cmb2
);
750 s
.hWnd2
=GetDlgItem(hDlg
, cmb3
);
752 EnumFontFamiliesA(hdc
, str
, FontStyleEnumProc
, (LPARAM
)&s
);
755 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
760 WARN("HDC failure !!!\n");
768 case cmb3
:if (HIWORD(wParam
)==CBN_SELCHANGE
|| HIWORD(wParam
)== BN_CLICKED
)
771 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
772 i
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
774 i
=GetDlgItemTextA( hDlg
, cmb1
, str
, 256 );
777 SendDlgItemMessageA(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
779 l
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
781 lpcf
->nFontType
= LOWORD(l
);
782 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
783 /* same value reported to the EnumFonts
784 call back with the extra FONTTYPE_... bits added */
785 lpxx
->lfPitchAndFamily
=j
&0xff;
786 lpxx
->lfCharSet
=j
>>8;
788 strcpy(lpxx
->lfFaceName
,str
);
789 i
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
792 l
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0);
793 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
794 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
795 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
796 lpcf
->nFontType
|= BOLD_FONTTYPE
;
798 i
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
800 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessageA(hDlg
, cmb3
, CB_GETITEMDATA
, i
, 0));
803 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
804 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
805 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
806 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
807 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
808 lpxx
->lfQuality
=DEFAULT_QUALITY
;
809 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
811 hFont
=CreateFontIndirectA(lpxx
);
814 HFONT oldFont
=SendDlgItemMessageA(hDlg
, stc6
,
816 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
817 DeleteObject(oldFont
);
822 case cmb4
:i
=SendDlgItemMessageA(hDlg
, cmb4
, CB_GETCURSEL
, 0, 0);
825 lpcf
->rgbColors
=textcolors
[i
];
826 InvalidateRect( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
830 case psh15
:i
=RegisterWindowMessageA( HELPMSGSTRING
);
832 SendMessageA(lpcf
->hwndOwner
, i
, 0, (LPARAM
)GetWindowLongA(hDlg
, DWL_USER
));
833 /* if (CFn_HookCallChk(lpcf))
834 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
837 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
838 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
839 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
840 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
841 EndDialog(hDlg
, TRUE
);
845 sprintf(buffer
,"Select a font size between %d and %d points.",
846 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
847 MessageBoxA(hDlg
, buffer
, NULL
, MB_OK
);
850 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
856 static LRESULT
CFn_WMDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
858 DeleteObject(SendDlgItemMessageA(hwnd
, stc6
, WM_GETFONT
, 0, 0));
863 /***********************************************************************
864 * FormatCharDlgProc16 (COMMDLG.16)
865 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
866 2. some CF_.. flags are not supported
867 3. some TType extensions
869 LRESULT WINAPI
FormatCharDlgProc16(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
,
873 LPCHOOSEFONTA lpcf32a
;
877 if (message
!=WM_INITDIALOG
)
879 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
882 if (CFn_HookCallChk(lpcf
))
883 res
=CallWindowProc16((WNDPROC16
)lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
889 lpcf
=(LPCHOOSEFONT16
)lParam
;
890 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
891 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
893 TRACE("CFn_WMInitDialog returned FALSE\n");
896 if (CFn_HookCallChk(lpcf
))
897 return CallWindowProc16((WNDPROC16
)lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
899 WINPROC_MapMsg16To32A(message
, wParam
, &uMsg32
, &wParam32
, &lParam
);
900 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
904 res
=CFn_WMMeasureItem(hDlg
, wParam32
, lParam
);
907 res
=CFn_WMDrawItem(hDlg
, wParam32
, lParam
);
909 case WM_CTLCOLORSTATIC
:
910 res
=CFn_WMCtlColorStatic(hDlg
, wParam32
, lParam
, lpcf32a
);
913 res
=CFn_WMCommand(hDlg
, wParam32
, lParam
, lpcf32a
);
916 res
=CFn_WMDestroy(hDlg
, wParam32
, lParam
);
918 case WM_CHOOSEFONT_GETLOGFONT
:
919 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
921 FIXME("current logfont back to caller\n");
924 WINPROC_UnmapMsg16To32A(hDlg
,uMsg32
, wParam32
, lParam
, res
);
928 /***********************************************************************
929 * FormatCharDlgProcA [internal]
931 LRESULT WINAPI
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
936 if (uMsg
!=WM_INITDIALOG
)
938 lpcf
=(LPCHOOSEFONTA
)GetWindowLongA(hDlg
, DWL_USER
);
941 if (CFn_HookCallChk32(lpcf
))
942 res
=CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
948 lpcf
=(LPCHOOSEFONTA
)lParam
;
949 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf
))
951 TRACE("CFn_WMInitDialog returned FALSE\n");
954 if (CFn_HookCallChk32(lpcf
))
955 return CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
960 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
962 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
963 case WM_CTLCOLORSTATIC
:
964 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf
);
966 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf
);
968 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
969 case WM_CHOOSEFONT_GETLOGFONT
:
970 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
972 FIXME("current logfont back to caller\n");
978 /***********************************************************************
979 * FormatCharDlgProcW [internal]
981 LRESULT WINAPI
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
984 LPCHOOSEFONTW lpcf32w
;
985 LPCHOOSEFONTA lpcf32a
;
987 if (uMsg
!=WM_INITDIALOG
)
989 lpcf32w
=(LPCHOOSEFONTW
)GetWindowLongA(hDlg
, DWL_USER
);
992 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
993 res
=CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
999 lpcf32w
=(LPCHOOSEFONTW
)lParam
;
1000 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1001 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
1003 TRACE("CFn_WMInitDialog returned FALSE\n");
1006 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1007 return CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1009 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1012 case WM_MEASUREITEM
:
1013 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1015 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1016 case WM_CTLCOLORSTATIC
:
1017 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf32a
);
1019 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf32a
);
1021 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1022 case WM_CHOOSEFONT_GETLOGFONT
:
1023 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1025 FIXME("current logfont back to caller\n");