2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
27 DEFAULT_DEBUG_CHANNEL(commdlg
)
31 static HBITMAP16 hBitmapTT
= 0;
36 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16
, LPCHOOSEFONTA chf32a
)
38 chf32a
->lStructSize
=sizeof(CHOOSEFONTA
);
39 chf32a
->hwndOwner
=chf16
->hwndOwner
;
40 chf32a
->hDC
=chf16
->hDC
;
41 chf32a
->iPointSize
=chf16
->iPointSize
;
42 chf32a
->Flags
=chf16
->Flags
;
43 chf32a
->rgbColors
=chf16
->rgbColors
;
44 chf32a
->lCustData
=chf16
->lCustData
;
45 chf32a
->lpfnHook
=NULL
;
46 chf32a
->lpTemplateName
=PTR_SEG_TO_LIN(chf16
->lpTemplateName
);
47 chf32a
->hInstance
=chf16
->hInstance
;
48 chf32a
->lpszStyle
=PTR_SEG_TO_LIN(chf16
->lpszStyle
);
49 chf32a
->nFontType
=chf16
->nFontType
;
50 chf32a
->nSizeMax
=chf16
->nSizeMax
;
51 chf32a
->nSizeMin
=chf16
->nSizeMin
;
52 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16
->lpLogFont
), chf32a
->lpLogFont
);
56 /***********************************************************************
57 * ChooseFont16 (COMMDLG.15)
59 BOOL16 WINAPI
ChooseFont16(LPCHOOSEFONT16 lpChFont
)
62 HANDLE16 hDlgTmpl
= 0;
63 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
68 SEGPTR lpTemplateName
;
70 cf32a
.lpLogFont
=&lf32a
;
71 CFn_CHOOSEFONT16to32A(lpChFont
, &cf32a
);
73 TRACE(commdlg
,"ChooseFont\n");
74 if (!lpChFont
) return FALSE
;
76 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
)
78 if (!(template = LockResource16( lpChFont
->hInstance
)))
80 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
84 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
87 if (!(hResInfo
= FindResource16( lpChFont
->hInstance
,
88 lpChFont
->lpTemplateName
,
91 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
94 if (!(hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
)) ||
95 !(template = LockResource16( hDlgTmpl
)))
97 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
104 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
106 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
109 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
110 !(template = LockResource( hDlgTmpl
)))
112 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
118 hInst
= WIN_GetWindowInstance( lpChFont
->hwndOwner
);
120 /* lpTemplateName is not used in the dialog */
121 lpTemplateName
=lpChFont
->lpTemplateName
;
122 lpChFont
->lpTemplateName
=(SEGPTR
)&cf32a
;
124 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
126 (DLGPROC16
)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
127 (DWORD
)lpChFont
, WIN_PROC_16
);
128 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
129 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
130 lpChFont
->lpTemplateName
=lpTemplateName
;
131 FONT_LogFont32ATo16(cf32a
.lpLogFont
,
132 (LPLOGFONT16
)(PTR_SEG_TO_LIN(lpChFont
->lpLogFont
)));
137 /***********************************************************************
138 * ChooseFont32A (COMDLG32.3)
140 BOOL WINAPI
ChooseFontA(LPCHOOSEFONTA lpChFont
)
144 HINSTANCE hInst
=WIN_GetWindowInstance( lpChFont
->hwndOwner
);
146 HANDLE hResInfo
, hDlgTmpl
;
148 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
150 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
153 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
154 !(template = LockResource( hDlgTmpl
)))
156 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
160 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
161 CF_ENABLETEMPLATEHANDLE
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
162 hwndDialog
= DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
163 (DLGPROC16
)FormatCharDlgProcA
, (LPARAM
)lpChFont
, WIN_PROC_32A
);
164 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
168 /***********************************************************************
169 * ChooseFont32W (COMDLG32.4)
171 BOOL WINAPI
ChooseFontW(LPCHOOSEFONTW lpChFont
)
175 HINSTANCE hInst
=WIN_GetWindowInstance( lpChFont
->hwndOwner
);
179 HANDLE hResInfo
, hDlgTmpl
;
181 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
183 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
186 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
187 !(template = LockResource( hDlgTmpl
)))
189 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
193 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
194 CF_ENABLETEMPLATEHANDLE
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
195 memcpy(&cf32a
, lpChFont
, sizeof(cf32a
));
196 memcpy(&lf32a
, lpChFont
->lpLogFont
, sizeof(LOGFONTA
));
197 lstrcpynWtoA(lf32a
.lfFaceName
, lpChFont
->lpLogFont
->lfFaceName
, LF_FACESIZE
);
198 cf32a
.lpLogFont
=&lf32a
;
199 cf32a
.lpszStyle
=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont
->lpszStyle
);
200 lpChFont
->lpTemplateName
=(LPWSTR
)&cf32a
;
201 hwndDialog
=DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
202 (DLGPROC16
)FormatCharDlgProcW
, (LPARAM
)lpChFont
, WIN_PROC_32W
);
203 if (hwndDialog
)bRet
=DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
204 HeapFree(GetProcessHeap(), 0, cf32a
.lpszStyle
);
205 lpChFont
->lpTemplateName
=(LPWSTR
)cf32a
.lpTemplateName
;
206 memcpy(lpChFont
->lpLogFont
, &lf32a
, sizeof(CHOOSEFONTA
));
207 lstrcpynAtoW(lpChFont
->lpLogFont
->lfFaceName
, lf32a
.lfFaceName
, LF_FACESIZE
);
212 #define TEXT_EXTRAS 4
213 #define TEXT_COLORS 16
215 static const COLORREF textcolors
[TEXT_COLORS
]=
217 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
218 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
219 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
220 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
223 /***********************************************************************
224 * CFn_HookCallChk [internal]
226 static BOOL
CFn_HookCallChk(LPCHOOSEFONT16 lpcf
)
229 if(lpcf
->Flags
& CF_ENABLEHOOK
)
235 /***********************************************************************
236 * CFn_HookCallChk32 [internal]
238 static BOOL
CFn_HookCallChk32(LPCHOOSEFONTA lpcf
)
241 if(lpcf
->Flags
& CF_ENABLEHOOK
)
248 /*************************************************************************
249 * AddFontFamily [internal]
251 static INT
AddFontFamily(LPLOGFONTA lplf
, UINT nFontType
,
252 LPCHOOSEFONTA lpcf
, HWND hwnd
)
257 TRACE(commdlg
,"font=%s (nFontType=%d)\n", lplf
->lfFaceName
,nFontType
);
259 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
260 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
262 if (lpcf
->Flags
& CF_ANSIONLY
)
263 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
265 if (lpcf
->Flags
& CF_TTONLY
)
266 if (!(nFontType
& TRUETYPE_FONTTYPE
))
269 i
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)lplf
->lfFaceName
);
272 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
273 SendMessageA(hwnd
, CB_SETITEMDATA
, i
, MAKELONG(nFontType
,w
));
274 return 1 ; /* store some important font information */
284 LPCHOOSEFONTA lpcf32a
;
285 } CFn_ENUMSTRUCT
, *LPCFn_ENUMSTRUCT
;
287 /*************************************************************************
288 * FontFamilyEnumProc32 [internal]
290 INT WINAPI
FontFamilyEnumProc(LPENUMLOGFONTA lpEnumLogFont
,
291 LPNEWTEXTMETRICA metrics
, UINT nFontType
, LPARAM lParam
)
294 e
=(LPCFn_ENUMSTRUCT
)lParam
;
295 return AddFontFamily(&lpEnumLogFont
->elfLogFont
, nFontType
, e
->lpcf32a
, e
->hWnd1
);
298 /***********************************************************************
299 * FontFamilyEnumProc16 (COMMDLG.19)
301 INT16 WINAPI
FontFamilyEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
302 UINT16 nFontType
, LPARAM lParam
)
304 HWND16 hwnd
=LOWORD(lParam
);
305 HWND16 hDlg
=GetParent16(hwnd
);
306 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
307 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN( logfont
);
309 FONT_LogFont16To32A(lplf
, &lf32a
);
310 return AddFontFamily(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
314 /*************************************************************************
315 * SetFontStylesToCombo2 [internal]
317 * Fill font style information into combobox (without using font.c directly)
319 static int SetFontStylesToCombo2(HWND hwnd
, HDC hdc
, LPLOGFONTA lplf
)
326 static struct FONTSTYLE fontstyles
[FSTYLES
]={
327 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
328 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
333 for (i
=0;i
<FSTYLES
;i
++)
335 lplf
->lfItalic
=fontstyles
[i
].italic
;
336 lplf
->lfWeight
=fontstyles
[i
].weight
;
337 hf
=CreateFontIndirectA(lplf
);
338 hf
=SelectObject(hdc
,hf
);
339 GetTextMetrics16(hdc
,&tm
);
340 hf
=SelectObject(hdc
,hf
);
343 if (tm
.tmWeight
==fontstyles
[i
].weight
&&
344 tm
.tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
346 char *str
= SEGPTR_STRDUP(fontstyles
[i
].stname
);
347 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(str
) );
349 if (j
==CB_ERR
) return 1;
350 j
=SendMessage16(hwnd
, CB_SETITEMDATA16
, j
,
351 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
352 if (j
==CB_ERR
) return 1;
358 /*************************************************************************
359 * AddFontSizeToCombo3 [internal]
361 static int AddFontSizeToCombo3(HWND hwnd
, UINT h
, LPCHOOSEFONTA lpcf
)
366 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
367 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
369 sprintf(buffer
, "%2d", h
);
370 j
=SendMessageA(hwnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buffer
);
373 j
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
374 if (j
!=CB_ERR
) j
= SendMessageA(hwnd
, CB_SETITEMDATA
, j
, h
);
375 if (j
==CB_ERR
) return 1;
381 /*************************************************************************
382 * SetFontSizesToCombo3 [internal]
384 static int SetFontSizesToCombo3(HWND hwnd
, LPCHOOSEFONTA lpcf
)
386 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
389 for (i
=0; sizes
[i
]; i
++)
390 if (AddFontSizeToCombo3(hwnd
, sizes
[i
], lpcf
)) return 1;
394 /***********************************************************************
395 * AddFontStyle [internal]
397 INT
AddFontStyle(LPLOGFONTA lplf
, UINT nFontType
,
398 LPCHOOSEFONTA lpcf
, HWND hcmb2
, HWND hcmb3
, HWND hDlg
)
402 TRACE(commdlg
,"(nFontType=%d)\n",nFontType
);
403 TRACE(commdlg
," %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
404 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
405 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,
406 lplf
->lfEscapement
,lplf
->lfOrientation
,
407 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,
408 lplf
->lfStrikeOut
,lplf
->lfCharSet
, lplf
->lfOutPrecision
,
409 lplf
->lfClipPrecision
,lplf
->lfQuality
, lplf
->lfPitchAndFamily
);
410 if (nFontType
& RASTER_FONTTYPE
)
412 if (AddFontSizeToCombo3(hcmb3
, lplf
->lfHeight
, lpcf
)) return 0;
413 } else if (SetFontSizesToCombo3(hcmb3
, lpcf
)) return 0;
415 if (!SendMessageA(hcmb2
, CB_GETCOUNT
, 0, 0))
417 HDC hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
418 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
);
419 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
428 /***********************************************************************
429 * FontStyleEnumProc16 (COMMDLG.18)
431 INT16 WINAPI
FontStyleEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
432 UINT16 nFontType
, LPARAM lParam
)
434 HWND16 hcmb2
=LOWORD(lParam
);
435 HWND16 hcmb3
=HIWORD(lParam
);
436 HWND16 hDlg
=GetParent16(hcmb3
);
437 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
438 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN(logfont
);
440 FONT_LogFont16To32A(lplf
, &lf32a
);
441 return AddFontStyle(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
445 /***********************************************************************
446 * FontStyleEnumProc32 [internal]
448 INT WINAPI
FontStyleEnumProc( LPENUMLOGFONTA lpFont
,
449 LPNEWTEXTMETRICA metrics
, UINT nFontType
, LPARAM lParam
)
451 LPCFn_ENUMSTRUCT s
=(LPCFn_ENUMSTRUCT
)lParam
;
454 HWND hDlg
=GetParent(hcmb3
);
455 return AddFontStyle(&lpFont
->elfLogFont
, nFontType
, s
->lpcf32a
, hcmb2
,
459 /***********************************************************************
460 * CFn_WMInitDialog [internal]
462 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
469 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
471 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
472 lpxx
=lpcf
->lpLogFont
;
473 TRACE(commdlg
,"WM_INITDIALOG lParam=%08lX\n", lParam
);
475 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONTA
))
477 ERR(commdlg
,"structure size failure !!!\n");
482 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
484 /* This font will be deleted by WM_COMMAND */
485 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,
486 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL
),FALSE
);
488 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
489 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
490 if (!(lpcf
->Flags
& CF_APPLY
))
491 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
492 if (lpcf
->Flags
& CF_EFFECTS
)
494 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
496 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
498 strcpy( name
, "[color name]" );
499 j
=SendDlgItemMessageA(hDlg
, cmb4
, CB_ADDSTRING
, 0, (LPARAM
)name
);
500 SendDlgItemMessageA(hDlg
, cmb4
, CB_SETITEMDATA16
, j
, textcolors
[j
]);
501 /* look for a fitting value in color combobox */
502 if (textcolors
[j
]==lpcf
->rgbColors
)
503 SendDlgItemMessageA(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
508 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
509 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
510 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
511 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
512 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
514 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
518 s
.hWnd1
=GetDlgItem(hDlg
,cmb1
);
520 if (!EnumFontFamiliesA(hdc
, NULL
, FontFamilyEnumProc
, (LPARAM
)&s
))
521 TRACE(commdlg
,"EnumFontFamilies returns 0\n");
522 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
524 /* look for fitting font name in combobox1 */
525 j
=SendDlgItemMessageA(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
528 SendDlgItemMessageA(hDlg
, cmb1
, CB_SETCURSEL
, j
, 0);
529 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
530 GetDlgItem(hDlg
,cmb1
));
532 /* look for fitting font style in combobox2 */
533 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
534 for (i
=0;i
<TEXT_EXTRAS
;i
++)
536 if (l
==SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0))
537 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
540 /* look for fitting font size in combobox3 */
541 j
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCOUNT
, 0, 0);
544 if (lpxx
->lfHeight
==(int)SendDlgItemMessageA(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
545 SendDlgItemMessageA(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
551 SendDlgItemMessageA(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
552 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
553 GetDlgItem(hDlg
,cmb1
));
555 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
557 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
560 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
561 SendMessageA(hDlg
,WM_COMMAND
,cmb2
,
562 MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
568 WARN(commdlg
,"HDC failure !!!\n");
573 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
580 /***********************************************************************
581 * CFn_WMMeasureItem [internal]
583 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
586 LPMEASUREITEMSTRUCT lpmi
=(LPMEASUREITEMSTRUCT
)lParam
;
588 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
589 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
590 lpmi
->itemHeight
=bm
.bmHeight
;
591 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
596 /***********************************************************************
597 * CFn_WMDrawItem [internal]
599 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
604 COLORREF cr
, oldText
=0, oldBk
=0;
609 HBITMAP hBitmap
; /* for later TT usage */
611 LPDRAWITEMSTRUCT lpdi
= (LPDRAWITEMSTRUCT
)lParam
;
613 if (lpdi
->itemID
== 0xFFFF) /* got no items */
614 DrawFocusRect(lpdi
->hDC
, &lpdi
->rcItem
);
617 if (lpdi
->CtlType
== ODT_COMBOBOX
)
619 if (lpdi
->itemState
==ODS_SELECTED
)
621 hBrush
=GetSysColorBrush(COLOR_HIGHLIGHT
);
622 oldText
=SetTextColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
623 oldBk
=SetBkColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHT
));
626 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
627 SelectObject(lpdi
->hDC
, hBrush
);
629 FillRect(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
632 return TRUE
; /* this should never happen */
637 case cmb1
: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
638 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
640 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
641 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
642 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
644 nFontType
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
645 /* FIXME: draw bitmap if truetype usage */
646 if (nFontType
&TRUETYPE_FONTTYPE
)
648 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
649 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
650 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
651 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
652 SelectObject(hMemDC
, hBitmap
);
658 case cmb3
: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
659 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
661 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
,
662 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
665 case cmb4
: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
666 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
668 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
669 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
670 cr
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
671 hBrush
= CreateSolidBrush(cr
);
674 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
675 rect
.right
=rect
.left
+25;
679 Rectangle( lpdi
->hDC
, rect
.left
, rect
.top
,
680 rect
.right
, rect
.bottom
);
681 DeleteObject( SelectObject (lpdi
->hDC
, hBrush
)) ;
687 default: return TRUE
; /* this should never happen */
689 if (lpdi
->itemState
== ODS_SELECTED
)
691 SetTextColor(lpdi
->hDC
, oldText
);
692 SetBkColor(lpdi
->hDC
, oldBk
);
698 /***********************************************************************
699 * CFn_WMCtlColor [internal]
701 LRESULT
CFn_WMCtlColorStatic(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
704 if (lpcf
->Flags
& CF_EFFECTS
)
705 if (GetDlgCtrlID(lParam
)==stc6
)
707 SetTextColor((HDC
)wParam
, lpcf
->rgbColors
);
708 return GetStockObject(WHITE_BRUSH
);
713 /***********************************************************************
714 * CFn_WMCommand [internal]
716 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
723 LPLOGFONTA lpxx
=lpcf
->lpLogFont
;
725 TRACE(commdlg
,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG
)wParam
, lParam
);
726 switch (LOWORD(wParam
))
728 case cmb1
:if (HIWORD(wParam
)==CBN_SELCHANGE
)
730 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
733 SendDlgItemMessageA(hDlg
, cmb2
, CB_RESETCONTENT16
, 0, 0);
734 SendDlgItemMessageA(hDlg
, cmb3
, CB_RESETCONTENT16
, 0, 0);
735 i
=SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL16
, 0, 0);
738 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
741 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETLBTEXT
, i
,
743 TRACE(commdlg
,"WM_COMMAND/cmb1 =>%s\n",str
);
744 s
.hWnd1
=GetDlgItem(hDlg
, cmb2
);
745 s
.hWnd2
=GetDlgItem(hDlg
, cmb3
);
747 EnumFontFamiliesA(hdc
, str
, FontStyleEnumProc
, (LPARAM
)&s
);
750 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
755 WARN(commdlg
,"HDC failure !!!\n");
763 case cmb3
:if (HIWORD(wParam
)==CBN_SELCHANGE
|| HIWORD(wParam
)== BN_CLICKED
)
766 TRACE(commdlg
,"WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
767 i
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
769 i
=GetDlgItemTextA( hDlg
, cmb1
, str
, 256 );
772 SendDlgItemMessageA(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
774 l
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
776 lpcf
->nFontType
= LOWORD(l
);
777 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
778 /* same value reported to the EnumFonts
779 call back with the extra FONTTYPE_... bits added */
780 lpxx
->lfPitchAndFamily
=j
&0xff;
781 lpxx
->lfCharSet
=j
>>8;
783 strcpy(lpxx
->lfFaceName
,str
);
784 i
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
787 l
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0);
788 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
789 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
790 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
791 lpcf
->nFontType
|= BOLD_FONTTYPE
;
793 i
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
795 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessageA(hDlg
, cmb3
, CB_GETITEMDATA
, i
, 0));
798 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
799 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
800 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
801 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
802 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
803 lpxx
->lfQuality
=DEFAULT_QUALITY
;
804 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
806 hFont
=CreateFontIndirectA(lpxx
);
809 HFONT oldFont
=SendDlgItemMessageA(hDlg
, stc6
,
811 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
812 DeleteObject(oldFont
);
817 case cmb4
:i
=SendDlgItemMessageA(hDlg
, cmb4
, CB_GETCURSEL
, 0, 0);
820 lpcf
->rgbColors
=textcolors
[i
];
821 InvalidateRect( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
825 case psh15
:i
=RegisterWindowMessageA( HELPMSGSTRING
);
827 SendMessageA(lpcf
->hwndOwner
, i
, 0, (LPARAM
)GetWindowLongA(hDlg
, DWL_USER
));
828 /* if (CFn_HookCallChk(lpcf))
829 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
832 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
833 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
834 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
835 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
836 EndDialog(hDlg
, TRUE
);
840 sprintf(buffer
,"Select a font size between %d and %d points.",
841 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
842 MessageBoxA(hDlg
, buffer
, NULL
, MB_OK
);
845 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
851 static LRESULT
CFn_WMDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
853 DeleteObject(SendDlgItemMessageA(hwnd
, stc6
, WM_GETFONT
, 0, 0));
858 /***********************************************************************
859 * FormatCharDlgProc16 (COMMDLG.16)
860 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
861 2. some CF_.. flags are not supported
862 3. some TType extensions
864 LRESULT WINAPI
FormatCharDlgProc16(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
,
868 LPCHOOSEFONTA lpcf32a
;
872 if (message
!=WM_INITDIALOG
)
874 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
877 if (CFn_HookCallChk(lpcf
))
878 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
884 lpcf
=(LPCHOOSEFONT16
)lParam
;
885 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
886 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
888 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
891 if (CFn_HookCallChk(lpcf
))
892 return CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
894 WINPROC_MapMsg16To32A(message
, wParam
, &uMsg32
, &wParam32
, &lParam
);
895 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
899 res
=CFn_WMMeasureItem(hDlg
, wParam32
, lParam
);
902 res
=CFn_WMDrawItem(hDlg
, wParam32
, lParam
);
904 case WM_CTLCOLORSTATIC
:
905 res
=CFn_WMCtlColorStatic(hDlg
, wParam32
, lParam
, lpcf32a
);
908 res
=CFn_WMCommand(hDlg
, wParam32
, lParam
, lpcf32a
);
911 res
=CFn_WMDestroy(hDlg
, wParam32
, lParam
);
913 case WM_CHOOSEFONT_GETLOGFONT
:
914 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
916 FIXME(commdlg
, "current logfont back to caller\n");
919 WINPROC_UnmapMsg16To32A(hDlg
,uMsg32
, wParam32
, lParam
, res
);
923 /***********************************************************************
924 * FormatCharDlgProc32A [internal]
926 LRESULT WINAPI
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
931 if (uMsg
!=WM_INITDIALOG
)
933 lpcf
=(LPCHOOSEFONTA
)GetWindowLongA(hDlg
, DWL_USER
);
936 if (CFn_HookCallChk32(lpcf
))
937 res
=CallWindowProcA(lpcf
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
943 lpcf
=(LPCHOOSEFONTA
)lParam
;
944 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf
))
946 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
949 if (CFn_HookCallChk32(lpcf
))
950 return CallWindowProcA(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
955 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
957 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
958 case WM_CTLCOLORSTATIC
:
959 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf
);
961 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf
);
963 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
964 case WM_CHOOSEFONT_GETLOGFONT
:
965 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
967 FIXME(commdlg
, "current logfont back to caller\n");
973 /***********************************************************************
974 * FormatCharDlgProc32W [internal]
976 LRESULT WINAPI
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
979 LPCHOOSEFONTW lpcf32w
;
980 LPCHOOSEFONTA lpcf32a
;
982 if (uMsg
!=WM_INITDIALOG
)
984 lpcf32w
=(LPCHOOSEFONTW
)GetWindowLongA(hDlg
, DWL_USER
);
987 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
988 res
=CallWindowProcW(lpcf32w
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
994 lpcf32w
=(LPCHOOSEFONTW
)lParam
;
995 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
996 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
998 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
1001 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1002 return CallWindowProcW(lpcf32w
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1004 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1007 case WM_MEASUREITEM
:
1008 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1010 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1011 case WM_CTLCOLORSTATIC
:
1012 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf32a
);
1014 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf32a
);
1016 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1017 case WM_CHOOSEFONT_GETLOGFONT
:
1018 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1020 FIXME(commdlg
, "current logfont back to caller\n");