2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
21 #include "debugtools.h"
26 DEFAULT_DEBUG_CHANNEL(commdlg
)
30 static HBITMAP16 hBitmapTT
= 0;
35 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16
, LPCHOOSEFONTA chf32a
)
37 chf32a
->lStructSize
=sizeof(CHOOSEFONTA
);
38 chf32a
->hwndOwner
=chf16
->hwndOwner
;
39 chf32a
->hDC
=chf16
->hDC
;
40 chf32a
->iPointSize
=chf16
->iPointSize
;
41 chf32a
->Flags
=chf16
->Flags
;
42 chf32a
->rgbColors
=chf16
->rgbColors
;
43 chf32a
->lCustData
=chf16
->lCustData
;
44 chf32a
->lpfnHook
=NULL
;
45 chf32a
->lpTemplateName
=PTR_SEG_TO_LIN(chf16
->lpTemplateName
);
46 chf32a
->hInstance
=chf16
->hInstance
;
47 chf32a
->lpszStyle
=PTR_SEG_TO_LIN(chf16
->lpszStyle
);
48 chf32a
->nFontType
=chf16
->nFontType
;
49 chf32a
->nSizeMax
=chf16
->nSizeMax
;
50 chf32a
->nSizeMin
=chf16
->nSizeMin
;
51 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16
->lpLogFont
), chf32a
->lpLogFont
);
55 /***********************************************************************
56 * ChooseFont16 (COMMDLG.15)
58 BOOL16 WINAPI
ChooseFont16(LPCHOOSEFONT16 lpChFont
)
61 HANDLE16 hDlgTmpl
= 0;
62 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
67 SEGPTR lpTemplateName
;
69 cf32a
.lpLogFont
=&lf32a
;
70 CFn_CHOOSEFONT16to32A(lpChFont
, &cf32a
);
72 TRACE("ChooseFont\n");
73 if (!lpChFont
) return FALSE
;
75 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
)
77 if (!(template = LockResource16( lpChFont
->hInstance
)))
79 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
83 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
86 if (!(hResInfo
= FindResource16( lpChFont
->hInstance
,
87 lpChFont
->lpTemplateName
,
90 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
93 if (!(hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
)) ||
94 !(template = LockResource16( hDlgTmpl
)))
96 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
103 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
105 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
108 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
109 !(template = LockResource( hDlgTmpl
)))
111 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
117 hInst
= GetWindowLongA( lpChFont
->hwndOwner
, GWL_HINSTANCE
);
119 /* lpTemplateName is not used in the dialog */
120 lpTemplateName
=lpChFont
->lpTemplateName
;
121 lpChFont
->lpTemplateName
=(SEGPTR
)&cf32a
;
123 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
125 (DLGPROC16
)FormatCharDlgProcA
,
126 (DWORD
)lpChFont
, WIN_PROC_32A
);
127 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
128 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
129 lpChFont
->lpTemplateName
=lpTemplateName
;
130 FONT_LogFont32ATo16(cf32a
.lpLogFont
,
131 (LPLOGFONT16
)(PTR_SEG_TO_LIN(lpChFont
->lpLogFont
)));
136 /***********************************************************************
137 * ChooseFont32A (COMDLG32.3)
139 BOOL WINAPI
ChooseFontA(LPCHOOSEFONTA lpChFont
)
143 HINSTANCE hInst
=GetWindowLongA( lpChFont
->hwndOwner
, GWL_HINSTANCE
);
145 HANDLE hResInfo
, hDlgTmpl
;
147 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
149 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
152 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
153 !(template = LockResource( hDlgTmpl
)))
155 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
159 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
160 CF_ENABLETEMPLATEHANDLE
)) FIXME(": unimplemented flag (ignored)\n");
161 hwndDialog
= DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
162 (DLGPROC16
)FormatCharDlgProcA
, (LPARAM
)lpChFont
, WIN_PROC_32A
);
163 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
167 /***********************************************************************
168 * ChooseFont32W (COMDLG32.4)
170 BOOL WINAPI
ChooseFontW(LPCHOOSEFONTW lpChFont
)
174 HINSTANCE hInst
=GetWindowLongA( lpChFont
->hwndOwner
, GWL_HINSTANCE
);
178 HANDLE hResInfo
, hDlgTmpl
;
180 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_FONT", RT_DIALOGA
)))
182 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
185 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
186 !(template = LockResource( hDlgTmpl
)))
188 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
192 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
193 CF_ENABLETEMPLATEHANDLE
)) FIXME(": unimplemented flag (ignored)\n");
194 memcpy(&cf32a
, lpChFont
, sizeof(cf32a
));
195 memcpy(&lf32a
, lpChFont
->lpLogFont
, sizeof(LOGFONTA
));
196 lstrcpynWtoA(lf32a
.lfFaceName
, lpChFont
->lpLogFont
->lfFaceName
, LF_FACESIZE
);
197 cf32a
.lpLogFont
=&lf32a
;
198 cf32a
.lpszStyle
=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont
->lpszStyle
);
199 lpChFont
->lpTemplateName
=(LPWSTR
)&cf32a
;
200 hwndDialog
=DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
201 (DLGPROC16
)FormatCharDlgProcW
, (LPARAM
)lpChFont
, WIN_PROC_32W
);
202 if (hwndDialog
)bRet
=DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
203 HeapFree(GetProcessHeap(), 0, cf32a
.lpszStyle
);
204 lpChFont
->lpTemplateName
=(LPWSTR
)cf32a
.lpTemplateName
;
205 memcpy(lpChFont
->lpLogFont
, &lf32a
, sizeof(CHOOSEFONTA
));
206 lstrcpynAtoW(lpChFont
->lpLogFont
->lfFaceName
, lf32a
.lfFaceName
, LF_FACESIZE
);
211 #define TEXT_EXTRAS 4
212 #define TEXT_COLORS 16
214 static const COLORREF textcolors
[TEXT_COLORS
]=
216 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
217 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
218 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
219 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
222 /***********************************************************************
223 * CFn_HookCallChk [internal]
225 static BOOL
CFn_HookCallChk(LPCHOOSEFONT16 lpcf
)
228 if(lpcf
->Flags
& CF_ENABLEHOOK
)
234 /***********************************************************************
235 * CFn_HookCallChk32 [internal]
237 static BOOL
CFn_HookCallChk32(LPCHOOSEFONTA lpcf
)
240 if(lpcf
->Flags
& CF_ENABLEHOOK
)
247 /*************************************************************************
248 * AddFontFamily [internal]
250 static INT
AddFontFamily(LPLOGFONTA lplf
, UINT nFontType
,
251 LPCHOOSEFONTA lpcf
, HWND hwnd
)
256 TRACE("font=%s (nFontType=%d)\n", lplf
->lfFaceName
,nFontType
);
258 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
259 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
261 if (lpcf
->Flags
& CF_ANSIONLY
)
262 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
264 if (lpcf
->Flags
& CF_TTONLY
)
265 if (!(nFontType
& TRUETYPE_FONTTYPE
))
268 i
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)lplf
->lfFaceName
);
271 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
272 SendMessageA(hwnd
, CB_SETITEMDATA
, i
, MAKELONG(nFontType
,w
));
273 return 1 ; /* store some important font information */
283 LPCHOOSEFONTA lpcf32a
;
284 } CFn_ENUMSTRUCT
, *LPCFn_ENUMSTRUCT
;
286 /*************************************************************************
287 * FontFamilyEnumProc32 [internal]
289 static INT WINAPI
FontFamilyEnumProc(LPENUMLOGFONTA lpEnumLogFont
,
290 LPNEWTEXTMETRICA metrics
, UINT nFontType
, LPARAM lParam
)
293 e
=(LPCFn_ENUMSTRUCT
)lParam
;
294 return AddFontFamily(&lpEnumLogFont
->elfLogFont
, nFontType
, e
->lpcf32a
, e
->hWnd1
);
297 /***********************************************************************
298 * FontFamilyEnumProc16 (COMMDLG.19)
300 INT16 WINAPI
FontFamilyEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
301 UINT16 nFontType
, LPARAM lParam
)
303 HWND16 hwnd
=LOWORD(lParam
);
304 HWND16 hDlg
=GetParent16(hwnd
);
305 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
306 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN( logfont
);
308 FONT_LogFont16To32A(lplf
, &lf32a
);
309 return AddFontFamily(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
313 /*************************************************************************
314 * SetFontStylesToCombo2 [internal]
316 * Fill font style information into combobox (without using font.c directly)
318 static int SetFontStylesToCombo2(HWND hwnd
, HDC hdc
, LPLOGFONTA lplf
)
325 static struct FONTSTYLE fontstyles
[FSTYLES
]={
326 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
327 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
332 for (i
=0;i
<FSTYLES
;i
++)
334 lplf
->lfItalic
=fontstyles
[i
].italic
;
335 lplf
->lfWeight
=fontstyles
[i
].weight
;
336 hf
=CreateFontIndirectA(lplf
);
337 hf
=SelectObject(hdc
,hf
);
338 GetTextMetrics16(hdc
,&tm
);
339 hf
=SelectObject(hdc
,hf
);
342 if (tm
.tmWeight
==fontstyles
[i
].weight
&&
343 tm
.tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
345 char *str
= SEGPTR_STRDUP(fontstyles
[i
].stname
);
346 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(str
) );
348 if (j
==CB_ERR
) return 1;
349 j
=SendMessage16(hwnd
, CB_SETITEMDATA16
, j
,
350 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
351 if (j
==CB_ERR
) return 1;
357 /*************************************************************************
358 * AddFontSizeToCombo3 [internal]
360 static int AddFontSizeToCombo3(HWND hwnd
, UINT h
, LPCHOOSEFONTA lpcf
)
365 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
366 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
368 sprintf(buffer
, "%2d", h
);
369 j
=SendMessageA(hwnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buffer
);
372 j
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
373 if (j
!=CB_ERR
) j
= SendMessageA(hwnd
, CB_SETITEMDATA
, j
, h
);
374 if (j
==CB_ERR
) return 1;
380 /*************************************************************************
381 * SetFontSizesToCombo3 [internal]
383 static int SetFontSizesToCombo3(HWND hwnd
, LPCHOOSEFONTA lpcf
)
385 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
388 for (i
=0; sizes
[i
]; i
++)
389 if (AddFontSizeToCombo3(hwnd
, sizes
[i
], lpcf
)) return 1;
393 /***********************************************************************
394 * AddFontStyle [internal]
396 static INT
AddFontStyle(LPLOGFONTA lplf
, UINT nFontType
,
397 LPCHOOSEFONTA lpcf
, HWND hcmb2
, HWND hcmb3
, HWND hDlg
)
401 TRACE("(nFontType=%d)\n",nFontType
);
402 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
403 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
404 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,
405 lplf
->lfEscapement
,lplf
->lfOrientation
,
406 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,
407 lplf
->lfStrikeOut
,lplf
->lfCharSet
, lplf
->lfOutPrecision
,
408 lplf
->lfClipPrecision
,lplf
->lfQuality
, lplf
->lfPitchAndFamily
);
409 if (nFontType
& RASTER_FONTTYPE
)
411 if (AddFontSizeToCombo3(hcmb3
, lplf
->lfHeight
, lpcf
)) return 0;
412 } else if (SetFontSizesToCombo3(hcmb3
, lpcf
)) return 0;
414 if (!SendMessageA(hcmb2
, CB_GETCOUNT
, 0, 0))
416 HDC hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
417 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
);
418 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
427 /***********************************************************************
428 * FontStyleEnumProc16 (COMMDLG.18)
430 INT16 WINAPI
FontStyleEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
431 UINT16 nFontType
, LPARAM lParam
)
433 HWND16 hcmb2
=LOWORD(lParam
);
434 HWND16 hcmb3
=HIWORD(lParam
);
435 HWND16 hDlg
=GetParent16(hcmb3
);
436 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
437 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN(logfont
);
439 FONT_LogFont16To32A(lplf
, &lf32a
);
440 return AddFontStyle(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
444 /***********************************************************************
445 * FontStyleEnumProc32 [internal]
447 static INT WINAPI
FontStyleEnumProc( LPENUMLOGFONTA lpFont
,
448 LPNEWTEXTMETRICA metrics
, UINT nFontType
, LPARAM lParam
)
450 LPCFn_ENUMSTRUCT s
=(LPCFn_ENUMSTRUCT
)lParam
;
453 HWND hDlg
=GetParent(hcmb3
);
454 return AddFontStyle(&lpFont
->elfLogFont
, nFontType
, s
->lpcf32a
, hcmb2
,
458 /***********************************************************************
459 * CFn_WMInitDialog [internal]
461 static LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
468 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
470 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
471 lpxx
=lpcf
->lpLogFont
;
472 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
474 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONTA
))
476 ERR("structure size failure !!!\n");
481 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
483 /* This font will be deleted by WM_COMMAND */
484 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,
485 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL
),FALSE
);
487 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
488 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
489 if (!(lpcf
->Flags
& CF_APPLY
))
490 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
491 if (lpcf
->Flags
& CF_EFFECTS
)
493 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
495 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
497 strcpy( name
, "[color name]" );
498 j
=SendDlgItemMessageA(hDlg
, cmb4
, CB_ADDSTRING
, 0, (LPARAM
)name
);
499 SendDlgItemMessageA(hDlg
, cmb4
, CB_SETITEMDATA16
, j
, textcolors
[j
]);
500 /* look for a fitting value in color combobox */
501 if (textcolors
[j
]==lpcf
->rgbColors
)
502 SendDlgItemMessageA(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
507 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
508 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
509 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
510 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
511 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
513 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
517 s
.hWnd1
=GetDlgItem(hDlg
,cmb1
);
519 if (!EnumFontFamiliesA(hdc
, NULL
, FontFamilyEnumProc
, (LPARAM
)&s
))
520 TRACE("EnumFontFamilies returns 0\n");
521 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
523 /* look for fitting font name in combobox1 */
524 j
=SendDlgItemMessageA(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
527 SendDlgItemMessageA(hDlg
, cmb1
, CB_SETCURSEL
, j
, 0);
528 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
529 GetDlgItem(hDlg
,cmb1
));
531 /* look for fitting font style in combobox2 */
532 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
533 for (i
=0;i
<TEXT_EXTRAS
;i
++)
535 if (l
==SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0))
536 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
539 /* look for fitting font size in combobox3 */
540 j
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCOUNT
, 0, 0);
543 if (lpxx
->lfHeight
==(int)SendDlgItemMessageA(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
544 SendDlgItemMessageA(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
550 SendDlgItemMessageA(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
551 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
552 GetDlgItem(hDlg
,cmb1
));
554 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
556 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
559 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
560 SendMessageA(hDlg
,WM_COMMAND
,cmb2
,
561 MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
567 WARN("HDC failure !!!\n");
572 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
579 /***********************************************************************
580 * CFn_WMMeasureItem [internal]
582 static LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
585 LPMEASUREITEMSTRUCT lpmi
=(LPMEASUREITEMSTRUCT
)lParam
;
587 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
588 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
589 lpmi
->itemHeight
=bm
.bmHeight
;
590 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
595 /***********************************************************************
596 * CFn_WMDrawItem [internal]
598 static LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
603 COLORREF cr
, oldText
=0, oldBk
=0;
608 HBITMAP hBitmap
; /* for later TT usage */
610 LPDRAWITEMSTRUCT lpdi
= (LPDRAWITEMSTRUCT
)lParam
;
612 if (lpdi
->itemID
== 0xFFFF) /* got no items */
613 DrawFocusRect(lpdi
->hDC
, &lpdi
->rcItem
);
616 if (lpdi
->CtlType
== ODT_COMBOBOX
)
618 if (lpdi
->itemState
==ODS_SELECTED
)
620 hBrush
=GetSysColorBrush(COLOR_HIGHLIGHT
);
621 oldText
=SetTextColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
622 oldBk
=SetBkColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHT
));
625 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
626 SelectObject(lpdi
->hDC
, hBrush
);
628 FillRect(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
631 return TRUE
; /* this should never happen */
636 case cmb1
: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
637 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
639 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
640 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
641 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
643 nFontType
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
644 /* FIXME: draw bitmap if truetype usage */
645 if (nFontType
&TRUETYPE_FONTTYPE
)
647 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
648 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
649 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
650 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
651 SelectObject(hMemDC
, hBitmap
);
657 case cmb3
: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
658 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
660 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
,
661 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
664 case cmb4
: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
665 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
667 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
668 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
669 cr
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
670 hBrush
= CreateSolidBrush(cr
);
673 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
674 rect
.right
=rect
.left
+25;
678 Rectangle( lpdi
->hDC
, rect
.left
, rect
.top
,
679 rect
.right
, rect
.bottom
);
680 DeleteObject( SelectObject (lpdi
->hDC
, hBrush
)) ;
686 default: return TRUE
; /* this should never happen */
688 if (lpdi
->itemState
== ODS_SELECTED
)
690 SetTextColor(lpdi
->hDC
, oldText
);
691 SetBkColor(lpdi
->hDC
, oldBk
);
697 /***********************************************************************
698 * CFn_WMCtlColor [internal]
700 static LRESULT
CFn_WMCtlColorStatic(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
703 if (lpcf
->Flags
& CF_EFFECTS
)
704 if (GetDlgCtrlID(lParam
)==stc6
)
706 SetTextColor((HDC
)wParam
, lpcf
->rgbColors
);
707 return GetStockObject(WHITE_BRUSH
);
712 /***********************************************************************
713 * CFn_WMCommand [internal]
715 static LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
722 LPLOGFONTA lpxx
=lpcf
->lpLogFont
;
724 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG
)wParam
, lParam
);
725 switch (LOWORD(wParam
))
727 case cmb1
:if (HIWORD(wParam
)==CBN_SELCHANGE
)
729 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
732 SendDlgItemMessageA(hDlg
, cmb2
, CB_RESETCONTENT16
, 0, 0);
733 SendDlgItemMessageA(hDlg
, cmb3
, CB_RESETCONTENT16
, 0, 0);
734 i
=SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL16
, 0, 0);
737 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
740 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETLBTEXT
, i
,
742 TRACE("WM_COMMAND/cmb1 =>%s\n",str
);
743 s
.hWnd1
=GetDlgItem(hDlg
, cmb2
);
744 s
.hWnd2
=GetDlgItem(hDlg
, cmb3
);
746 EnumFontFamiliesA(hdc
, str
, FontStyleEnumProc
, (LPARAM
)&s
);
749 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
754 WARN("HDC failure !!!\n");
762 case cmb3
:if (HIWORD(wParam
)==CBN_SELCHANGE
|| HIWORD(wParam
)== BN_CLICKED
)
765 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
766 i
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
768 i
=GetDlgItemTextA( hDlg
, cmb1
, str
, 256 );
771 SendDlgItemMessageA(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
773 l
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
775 lpcf
->nFontType
= LOWORD(l
);
776 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
777 /* same value reported to the EnumFonts
778 call back with the extra FONTTYPE_... bits added */
779 lpxx
->lfPitchAndFamily
=j
&0xff;
780 lpxx
->lfCharSet
=j
>>8;
782 strcpy(lpxx
->lfFaceName
,str
);
783 i
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
786 l
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0);
787 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
788 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
789 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
790 lpcf
->nFontType
|= BOLD_FONTTYPE
;
792 i
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
794 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessageA(hDlg
, cmb3
, CB_GETITEMDATA
, i
, 0));
797 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
798 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
799 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
800 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
801 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
802 lpxx
->lfQuality
=DEFAULT_QUALITY
;
803 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
805 hFont
=CreateFontIndirectA(lpxx
);
808 HFONT oldFont
=SendDlgItemMessageA(hDlg
, stc6
,
810 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
811 DeleteObject(oldFont
);
816 case cmb4
:i
=SendDlgItemMessageA(hDlg
, cmb4
, CB_GETCURSEL
, 0, 0);
819 lpcf
->rgbColors
=textcolors
[i
];
820 InvalidateRect( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
824 case psh15
:i
=RegisterWindowMessageA( HELPMSGSTRING
);
826 SendMessageA(lpcf
->hwndOwner
, i
, 0, (LPARAM
)GetWindowLongA(hDlg
, DWL_USER
));
827 /* if (CFn_HookCallChk(lpcf))
828 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
831 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
832 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
833 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
834 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
835 EndDialog(hDlg
, TRUE
);
839 sprintf(buffer
,"Select a font size between %d and %d points.",
840 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
841 MessageBoxA(hDlg
, buffer
, NULL
, MB_OK
);
844 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
850 static LRESULT
CFn_WMDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
852 DeleteObject(SendDlgItemMessageA(hwnd
, stc6
, WM_GETFONT
, 0, 0));
857 /***********************************************************************
858 * FormatCharDlgProc16 (COMMDLG.16)
859 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
860 2. some CF_.. flags are not supported
861 3. some TType extensions
863 LRESULT WINAPI
FormatCharDlgProc16(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
,
867 LPCHOOSEFONTA lpcf32a
;
871 if (message
!=WM_INITDIALOG
)
873 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
876 if (CFn_HookCallChk(lpcf
))
877 res
=CallWindowProc16((WNDPROC16
)lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
883 lpcf
=(LPCHOOSEFONT16
)lParam
;
884 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
885 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
887 TRACE("CFn_WMInitDialog returned FALSE\n");
890 if (CFn_HookCallChk(lpcf
))
891 return CallWindowProc16((WNDPROC16
)lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
893 WINPROC_MapMsg16To32A(message
, wParam
, &uMsg32
, &wParam32
, &lParam
);
894 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
898 res
=CFn_WMMeasureItem(hDlg
, wParam32
, lParam
);
901 res
=CFn_WMDrawItem(hDlg
, wParam32
, lParam
);
903 case WM_CTLCOLORSTATIC
:
904 res
=CFn_WMCtlColorStatic(hDlg
, wParam32
, lParam
, lpcf32a
);
907 res
=CFn_WMCommand(hDlg
, wParam32
, lParam
, lpcf32a
);
910 res
=CFn_WMDestroy(hDlg
, wParam32
, lParam
);
912 case WM_CHOOSEFONT_GETLOGFONT
:
913 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
915 FIXME("current logfont back to caller\n");
918 WINPROC_UnmapMsg16To32A(hDlg
,uMsg32
, wParam32
, lParam
, res
);
922 /***********************************************************************
923 * FormatCharDlgProc32A [internal]
925 LRESULT WINAPI
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
930 if (uMsg
!=WM_INITDIALOG
)
932 lpcf
=(LPCHOOSEFONTA
)GetWindowLongA(hDlg
, DWL_USER
);
935 if (CFn_HookCallChk32(lpcf
))
936 res
=CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
942 lpcf
=(LPCHOOSEFONTA
)lParam
;
943 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf
))
945 TRACE("CFn_WMInitDialog returned FALSE\n");
948 if (CFn_HookCallChk32(lpcf
))
949 return CallWindowProcA((WNDPROC
)lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
954 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
956 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
957 case WM_CTLCOLORSTATIC
:
958 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf
);
960 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf
);
962 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
963 case WM_CHOOSEFONT_GETLOGFONT
:
964 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
966 FIXME("current logfont back to caller\n");
972 /***********************************************************************
973 * FormatCharDlgProc32W [internal]
975 LRESULT WINAPI
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
978 LPCHOOSEFONTW lpcf32w
;
979 LPCHOOSEFONTA lpcf32a
;
981 if (uMsg
!=WM_INITDIALOG
)
983 lpcf32w
=(LPCHOOSEFONTW
)GetWindowLongA(hDlg
, DWL_USER
);
986 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
987 res
=CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
993 lpcf32w
=(LPCHOOSEFONTW
)lParam
;
994 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
995 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
997 TRACE("CFn_WMInitDialog returned FALSE\n");
1000 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
1001 return CallWindowProcW((WNDPROC
)lpcf32w
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1003 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
1006 case WM_MEASUREITEM
:
1007 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
1009 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
1010 case WM_CTLCOLORSTATIC
:
1011 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf32a
);
1013 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf32a
);
1015 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
1016 case WM_CHOOSEFONT_GETLOGFONT
:
1017 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1019 FIXME("current logfont back to caller\n");