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
)
29 static HBITMAP16 hBitmapTT
= 0;
34 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16
, LPCHOOSEFONTA chf32a
)
36 chf32a
->lStructSize
=sizeof(CHOOSEFONTA
);
37 chf32a
->hwndOwner
=chf16
->hwndOwner
;
38 chf32a
->hDC
=chf16
->hDC
;
39 chf32a
->iPointSize
=chf16
->iPointSize
;
40 chf32a
->Flags
=chf16
->Flags
;
41 chf32a
->rgbColors
=chf16
->rgbColors
;
42 chf32a
->lCustData
=chf16
->lCustData
;
43 chf32a
->lpfnHook
=NULL
;
44 chf32a
->lpTemplateName
=PTR_SEG_TO_LIN(chf16
->lpTemplateName
);
45 chf32a
->hInstance
=chf16
->hInstance
;
46 chf32a
->lpszStyle
=PTR_SEG_TO_LIN(chf16
->lpszStyle
);
47 chf32a
->nFontType
=chf16
->nFontType
;
48 chf32a
->nSizeMax
=chf16
->nSizeMax
;
49 chf32a
->nSizeMin
=chf16
->nSizeMin
;
50 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16
->lpLogFont
), chf32a
->lpLogFont
);
54 /***********************************************************************
55 * ChooseFont16 (COMMDLG.15)
57 BOOL16 WINAPI
ChooseFont16(LPCHOOSEFONT16 lpChFont
)
60 HANDLE16 hDlgTmpl
= 0;
61 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
66 SEGPTR lpTemplateName
;
68 cf32a
.lpLogFont
=&lf32a
;
69 CFn_CHOOSEFONT16to32A(lpChFont
, &cf32a
);
71 TRACE(commdlg
,"ChooseFont\n");
72 if (!lpChFont
) return FALSE
;
74 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
)
76 if (!(template = LockResource16( lpChFont
->hInstance
)))
78 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
82 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
85 if (!(hResInfo
= FindResource16( lpChFont
->hInstance
,
86 lpChFont
->lpTemplateName
,
89 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
92 if (!(hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
)) ||
93 !(template = LockResource16( hDlgTmpl
)))
95 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
101 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT
);
105 hInst
= WIN_GetWindowInstance( lpChFont
->hwndOwner
);
107 /* lpTemplateName is not used in the dialog */
108 lpTemplateName
=lpChFont
->lpTemplateName
;
109 lpChFont
->lpTemplateName
=(SEGPTR
)&cf32a
;
111 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
113 (DLGPROC16
)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
114 (DWORD
)lpChFont
, WIN_PROC_16
);
115 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
116 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
117 lpChFont
->lpTemplateName
=lpTemplateName
;
118 FONT_LogFont32ATo16(cf32a
.lpLogFont
,
119 (LPLOGFONT16
)(PTR_SEG_TO_LIN(lpChFont
->lpLogFont
)));
124 /***********************************************************************
125 * ChooseFont32A (COMDLG32.3)
127 BOOL WINAPI
ChooseFontA(LPCHOOSEFONTA lpChFont
)
131 HINSTANCE hInst
=WIN_GetWindowInstance( lpChFont
->hwndOwner
);
132 LPCVOID
template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT
);
133 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
134 CF_ENABLETEMPLATEHANDLE
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
135 hwndDialog
= DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
136 (DLGPROC16
)FormatCharDlgProcA
, (LPARAM
)lpChFont
, WIN_PROC_32A
);
137 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
141 /***********************************************************************
142 * ChooseFont32W (COMDLG32.4)
144 BOOL WINAPI
ChooseFontW(LPCHOOSEFONTW lpChFont
)
148 HINSTANCE hInst
=WIN_GetWindowInstance( lpChFont
->hwndOwner
);
151 LPCVOID
template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT
);
152 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
153 CF_ENABLETEMPLATEHANDLE
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
154 memcpy(&cf32a
, lpChFont
, sizeof(cf32a
));
155 memcpy(&lf32a
, lpChFont
->lpLogFont
, sizeof(LOGFONTA
));
156 lstrcpynWtoA(lf32a
.lfFaceName
, lpChFont
->lpLogFont
->lfFaceName
, LF_FACESIZE
);
157 cf32a
.lpLogFont
=&lf32a
;
158 cf32a
.lpszStyle
=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont
->lpszStyle
);
159 lpChFont
->lpTemplateName
=(LPWSTR
)&cf32a
;
160 hwndDialog
=DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
161 (DLGPROC16
)FormatCharDlgProcW
, (LPARAM
)lpChFont
, WIN_PROC_32W
);
162 if (hwndDialog
)bRet
=DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
163 HeapFree(GetProcessHeap(), 0, cf32a
.lpszStyle
);
164 lpChFont
->lpTemplateName
=(LPWSTR
)cf32a
.lpTemplateName
;
165 memcpy(lpChFont
->lpLogFont
, &lf32a
, sizeof(CHOOSEFONTA
));
166 lstrcpynAtoW(lpChFont
->lpLogFont
->lfFaceName
, lf32a
.lfFaceName
, LF_FACESIZE
);
171 #define TEXT_EXTRAS 4
172 #define TEXT_COLORS 16
174 static const COLORREF textcolors
[TEXT_COLORS
]=
176 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
177 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
178 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
179 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
182 /***********************************************************************
183 * CFn_HookCallChk [internal]
185 static BOOL
CFn_HookCallChk(LPCHOOSEFONT16 lpcf
)
188 if(lpcf
->Flags
& CF_ENABLEHOOK
)
194 /***********************************************************************
195 * CFn_HookCallChk32 [internal]
197 static BOOL
CFn_HookCallChk32(LPCHOOSEFONTA lpcf
)
200 if(lpcf
->Flags
& CF_ENABLEHOOK
)
207 /*************************************************************************
208 * AddFontFamily [internal]
210 static INT
AddFontFamily(LPLOGFONTA lplf
, UINT nFontType
,
211 LPCHOOSEFONTA lpcf
, HWND hwnd
)
216 TRACE(commdlg
,"font=%s (nFontType=%d)\n", lplf
->lfFaceName
,nFontType
);
218 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
219 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
221 if (lpcf
->Flags
& CF_ANSIONLY
)
222 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
224 if (lpcf
->Flags
& CF_TTONLY
)
225 if (!(nFontType
& TRUETYPE_FONTTYPE
))
228 i
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)lplf
->lfFaceName
);
231 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
232 SendMessageA(hwnd
, CB_SETITEMDATA
, i
, MAKELONG(nFontType
,w
));
233 return 1 ; /* store some important font information */
243 LPCHOOSEFONTA lpcf32a
;
244 } CFn_ENUMSTRUCT
, *LPCFn_ENUMSTRUCT
;
246 /*************************************************************************
247 * FontFamilyEnumProc32 [internal]
249 INT WINAPI
FontFamilyEnumProc(LPENUMLOGFONTA lpEnumLogFont
,
250 LPNEWTEXTMETRICA metrics
, UINT nFontType
, LPARAM lParam
)
253 e
=(LPCFn_ENUMSTRUCT
)lParam
;
254 return AddFontFamily(&lpEnumLogFont
->elfLogFont
, nFontType
, e
->lpcf32a
, e
->hWnd1
);
257 /***********************************************************************
258 * FontFamilyEnumProc16 (COMMDLG.19)
260 INT16 WINAPI
FontFamilyEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
261 UINT16 nFontType
, LPARAM lParam
)
263 HWND16 hwnd
=LOWORD(lParam
);
264 HWND16 hDlg
=GetParent16(hwnd
);
265 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
266 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN( logfont
);
268 FONT_LogFont16To32A(lplf
, &lf32a
);
269 return AddFontFamily(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
273 /*************************************************************************
274 * SetFontStylesToCombo2 [internal]
276 * Fill font style information into combobox (without using font.c directly)
278 static int SetFontStylesToCombo2(HWND hwnd
, HDC hdc
, LPLOGFONTA lplf
)
285 static struct FONTSTYLE fontstyles
[FSTYLES
]={
286 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
287 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
292 for (i
=0;i
<FSTYLES
;i
++)
294 lplf
->lfItalic
=fontstyles
[i
].italic
;
295 lplf
->lfWeight
=fontstyles
[i
].weight
;
296 hf
=CreateFontIndirectA(lplf
);
297 hf
=SelectObject(hdc
,hf
);
298 GetTextMetrics16(hdc
,&tm
);
299 hf
=SelectObject(hdc
,hf
);
302 if (tm
.tmWeight
==fontstyles
[i
].weight
&&
303 tm
.tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
305 char *str
= SEGPTR_STRDUP(fontstyles
[i
].stname
);
306 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(str
) );
308 if (j
==CB_ERR
) return 1;
309 j
=SendMessage16(hwnd
, CB_SETITEMDATA16
, j
,
310 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
311 if (j
==CB_ERR
) return 1;
317 /*************************************************************************
318 * AddFontSizeToCombo3 [internal]
320 static int AddFontSizeToCombo3(HWND hwnd
, UINT h
, LPCHOOSEFONTA lpcf
)
325 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
326 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
328 sprintf(buffer
, "%2d", h
);
329 j
=SendMessageA(hwnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buffer
);
332 j
=SendMessageA(hwnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
333 if (j
!=CB_ERR
) j
= SendMessageA(hwnd
, CB_SETITEMDATA
, j
, h
);
334 if (j
==CB_ERR
) return 1;
340 /*************************************************************************
341 * SetFontSizesToCombo3 [internal]
343 static int SetFontSizesToCombo3(HWND hwnd
, LPCHOOSEFONTA lpcf
)
345 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
348 for (i
=0; sizes
[i
]; i
++)
349 if (AddFontSizeToCombo3(hwnd
, sizes
[i
], lpcf
)) return 1;
353 /***********************************************************************
354 * AddFontStyle [internal]
356 INT
AddFontStyle(LPLOGFONTA lplf
, UINT nFontType
,
357 LPCHOOSEFONTA lpcf
, HWND hcmb2
, HWND hcmb3
, HWND hDlg
)
361 TRACE(commdlg
,"(nFontType=%d)\n",nFontType
);
362 TRACE(commdlg
," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
363 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
364 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,
365 lplf
->lfEscapement
,lplf
->lfOrientation
,
366 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,
367 lplf
->lfStrikeOut
,lplf
->lfCharSet
, lplf
->lfOutPrecision
,
368 lplf
->lfClipPrecision
,lplf
->lfQuality
, lplf
->lfPitchAndFamily
);
369 if (nFontType
& RASTER_FONTTYPE
)
371 if (AddFontSizeToCombo3(hcmb3
, lplf
->lfHeight
, lpcf
)) return 0;
372 } else if (SetFontSizesToCombo3(hcmb3
, lpcf
)) return 0;
374 if (!SendMessageA(hcmb2
, CB_GETCOUNT
, 0, 0))
376 HDC hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
377 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
);
378 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
387 /***********************************************************************
388 * FontStyleEnumProc16 (COMMDLG.18)
390 INT16 WINAPI
FontStyleEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
391 UINT16 nFontType
, LPARAM lParam
)
393 HWND16 hcmb2
=LOWORD(lParam
);
394 HWND16 hcmb3
=HIWORD(lParam
);
395 HWND16 hDlg
=GetParent16(hcmb3
);
396 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
397 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN(logfont
);
399 FONT_LogFont16To32A(lplf
, &lf32a
);
400 return AddFontStyle(&lf32a
, nFontType
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
,
404 /***********************************************************************
405 * FontStyleEnumProc32 [internal]
407 INT WINAPI
FontStyleEnumProc( LPENUMLOGFONTA lpFont
,
408 LPNEWTEXTMETRICA metrics
, UINT nFontType
, LPARAM lParam
)
410 LPCFn_ENUMSTRUCT s
=(LPCFn_ENUMSTRUCT
)lParam
;
413 HWND hDlg
=GetParent(hcmb3
);
414 return AddFontStyle(&lpFont
->elfLogFont
, nFontType
, s
->lpcf32a
, hcmb2
,
418 /***********************************************************************
419 * CFn_WMInitDialog [internal]
421 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
428 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
430 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
431 lpxx
=lpcf
->lpLogFont
;
432 TRACE(commdlg
,"WM_INITDIALOG lParam=%08lX\n", lParam
);
434 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONTA
))
436 ERR(commdlg
,"structure size failure !!!\n");
441 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
443 /* This font will be deleted by WM_COMMAND */
444 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,
445 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL
),FALSE
);
447 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
448 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
449 if (!(lpcf
->Flags
& CF_APPLY
))
450 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
451 if (lpcf
->Flags
& CF_EFFECTS
)
453 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
455 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
457 strcpy( name
, "[color name]" );
458 j
=SendDlgItemMessageA(hDlg
, cmb4
, CB_ADDSTRING
, 0, (LPARAM
)name
);
459 SendDlgItemMessageA(hDlg
, cmb4
, CB_SETITEMDATA16
, j
, textcolors
[j
]);
460 /* look for a fitting value in color combobox */
461 if (textcolors
[j
]==lpcf
->rgbColors
)
462 SendDlgItemMessageA(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
467 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
468 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
469 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
470 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
471 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
473 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
477 s
.hWnd1
=GetDlgItem(hDlg
,cmb1
);
479 if (!EnumFontFamiliesA(hdc
, NULL
, FontFamilyEnumProc
, (LPARAM
)&s
))
480 TRACE(commdlg
,"EnumFontFamilies returns 0\n");
481 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
483 /* look for fitting font name in combobox1 */
484 j
=SendDlgItemMessageA(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
487 SendDlgItemMessageA(hDlg
, cmb1
, CB_SETCURSEL
, j
, 0);
488 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
489 GetDlgItem(hDlg
,cmb1
));
491 /* look for fitting font style in combobox2 */
492 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
493 for (i
=0;i
<TEXT_EXTRAS
;i
++)
495 if (l
==SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0))
496 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
499 /* look for fitting font size in combobox3 */
500 j
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCOUNT
, 0, 0);
503 if (lpxx
->lfHeight
==(int)SendDlgItemMessageA(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
504 SendDlgItemMessageA(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
510 SendDlgItemMessageA(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
511 SendMessageA(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
512 GetDlgItem(hDlg
,cmb1
));
514 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
516 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
519 j
=SendDlgItemMessageA(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
520 SendMessageA(hDlg
,WM_COMMAND
,cmb2
,
521 MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
527 WARN(commdlg
,"HDC failure !!!\n");
532 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
539 /***********************************************************************
540 * CFn_WMMeasureItem [internal]
542 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
545 LPMEASUREITEMSTRUCT lpmi
=(LPMEASUREITEMSTRUCT
)lParam
;
547 hBitmapTT
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE
));
548 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
549 lpmi
->itemHeight
=bm
.bmHeight
;
550 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
555 /***********************************************************************
556 * CFn_WMDrawItem [internal]
558 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
563 COLORREF cr
, oldText
=0, oldBk
=0;
568 HBITMAP hBitmap
; /* for later TT usage */
570 LPDRAWITEMSTRUCT lpdi
= (LPDRAWITEMSTRUCT
)lParam
;
572 if (lpdi
->itemID
== 0xFFFF) /* got no items */
573 DrawFocusRect(lpdi
->hDC
, &lpdi
->rcItem
);
576 if (lpdi
->CtlType
== ODT_COMBOBOX
)
578 if (lpdi
->itemState
==ODS_SELECTED
)
580 hBrush
=GetSysColorBrush(COLOR_HIGHLIGHT
);
581 oldText
=SetTextColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
582 oldBk
=SetBkColor(lpdi
->hDC
, GetSysColor(COLOR_HIGHLIGHT
));
585 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
586 SelectObject(lpdi
->hDC
, hBrush
);
588 FillRect(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
591 return TRUE
; /* this should never happen */
596 case cmb1
: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
597 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
599 GetObjectA( hBitmapTT
, sizeof(bm
), &bm
);
600 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
601 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
603 nFontType
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
604 /* FIXME: draw bitmap if truetype usage */
605 if (nFontType
&TRUETYPE_FONTTYPE
)
607 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
608 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
609 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
610 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
611 SelectObject(hMemDC
, hBitmap
);
617 case cmb3
: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
618 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
620 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
,
621 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
624 case cmb4
: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
625 SendMessageA(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
627 TextOutA(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
628 lpdi
->rcItem
.top
, buffer
, lstrlenA(buffer
));
629 cr
= SendMessageA(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
630 hBrush
= CreateSolidBrush(cr
);
633 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
634 rect
.right
=rect
.left
+25;
638 Rectangle( lpdi
->hDC
, rect
.left
, rect
.top
,
639 rect
.right
, rect
.bottom
);
640 DeleteObject( SelectObject (lpdi
->hDC
, hBrush
)) ;
646 default: return TRUE
; /* this should never happen */
648 if (lpdi
->itemState
== ODS_SELECTED
)
650 SetTextColor(lpdi
->hDC
, oldText
);
651 SetBkColor(lpdi
->hDC
, oldBk
);
657 /***********************************************************************
658 * CFn_WMCtlColor [internal]
660 LRESULT
CFn_WMCtlColorStatic(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
663 if (lpcf
->Flags
& CF_EFFECTS
)
664 if (GetDlgCtrlID(lParam
)==stc6
)
666 SetTextColor((HDC
)wParam
, lpcf
->rgbColors
);
667 return GetStockObject(WHITE_BRUSH
);
672 /***********************************************************************
673 * CFn_WMCommand [internal]
675 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
,
682 LPLOGFONTA lpxx
=lpcf
->lpLogFont
;
684 TRACE(commdlg
,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG
)wParam
, lParam
);
685 switch (LOWORD(wParam
))
687 case cmb1
:if (HIWORD(wParam
)==CBN_SELCHANGE
)
689 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
692 SendDlgItemMessageA(hDlg
, cmb2
, CB_RESETCONTENT16
, 0, 0);
693 SendDlgItemMessageA(hDlg
, cmb3
, CB_RESETCONTENT16
, 0, 0);
694 i
=SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL16
, 0, 0);
697 HCURSOR hcursor
=SetCursor(LoadCursorA(0,IDC_WAITA
));
700 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETLBTEXT
, i
,
702 TRACE(commdlg
,"WM_COMMAND/cmb1 =>%s\n",str
);
703 s
.hWnd1
=GetDlgItem(hDlg
, cmb2
);
704 s
.hWnd2
=GetDlgItem(hDlg
, cmb3
);
706 EnumFontFamiliesA(hdc
, str
, FontStyleEnumProc
, (LPARAM
)&s
);
709 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
714 WARN(commdlg
,"HDC failure !!!\n");
722 case cmb3
:if (HIWORD(wParam
)==CBN_SELCHANGE
|| HIWORD(wParam
)== BN_CLICKED
)
725 TRACE(commdlg
,"WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
726 i
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
728 i
=GetDlgItemTextA( hDlg
, cmb1
, str
, 256 );
731 SendDlgItemMessageA(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
733 l
=SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
735 lpcf
->nFontType
= LOWORD(l
);
736 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
737 /* same value reported to the EnumFonts
738 call back with the extra FONTTYPE_... bits added */
739 lpxx
->lfPitchAndFamily
=j
&0xff;
740 lpxx
->lfCharSet
=j
>>8;
742 strcpy(lpxx
->lfFaceName
,str
);
743 i
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
746 l
=SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0);
747 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
748 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
749 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
750 lpcf
->nFontType
|= BOLD_FONTTYPE
;
752 i
=SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
754 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessageA(hDlg
, cmb3
, CB_GETITEMDATA
, i
, 0));
757 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
758 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
759 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
760 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
761 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
762 lpxx
->lfQuality
=DEFAULT_QUALITY
;
763 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
765 hFont
=CreateFontIndirectA(lpxx
);
768 HFONT oldFont
=SendDlgItemMessageA(hDlg
, stc6
,
770 SendDlgItemMessageA(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
771 DeleteObject(oldFont
);
776 case cmb4
:i
=SendDlgItemMessageA(hDlg
, cmb4
, CB_GETCURSEL
, 0, 0);
779 lpcf
->rgbColors
=textcolors
[i
];
780 InvalidateRect( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
784 case psh15
:i
=RegisterWindowMessageA( HELPMSGSTRING
);
786 SendMessageA(lpcf
->hwndOwner
, i
, 0, (LPARAM
)GetWindowLongA(hDlg
, DWL_USER
));
787 /* if (CFn_HookCallChk(lpcf))
788 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
791 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
792 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
793 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
794 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
795 EndDialog(hDlg
, TRUE
);
799 sprintf(buffer
,"Select a font size between %d and %d points.",
800 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
801 MessageBoxA(hDlg
, buffer
, NULL
, MB_OK
);
804 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
810 static LRESULT
CFn_WMDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
812 DeleteObject(SendDlgItemMessageA(hwnd
, stc6
, WM_GETFONT
, 0, 0));
817 /***********************************************************************
818 * FormatCharDlgProc16 (COMMDLG.16)
819 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
820 2. some CF_.. flags are not supported
821 3. some TType extensions
823 LRESULT WINAPI
FormatCharDlgProc16(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
,
827 LPCHOOSEFONTA lpcf32a
;
831 if (message
!=WM_INITDIALOG
)
833 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
836 if (CFn_HookCallChk(lpcf
))
837 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
843 lpcf
=(LPCHOOSEFONT16
)lParam
;
844 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
845 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
847 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
850 if (CFn_HookCallChk(lpcf
))
851 return CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
853 WINPROC_MapMsg16To32A(message
, wParam
, &uMsg32
, &wParam32
, &lParam
);
854 lpcf32a
=(LPCHOOSEFONTA
)lpcf
->lpTemplateName
;
858 res
=CFn_WMMeasureItem(hDlg
, wParam32
, lParam
);
861 res
=CFn_WMDrawItem(hDlg
, wParam32
, lParam
);
863 case WM_CTLCOLORSTATIC
:
864 res
=CFn_WMCtlColorStatic(hDlg
, wParam32
, lParam
, lpcf32a
);
867 res
=CFn_WMCommand(hDlg
, wParam32
, lParam
, lpcf32a
);
870 res
=CFn_WMDestroy(hDlg
, wParam32
, lParam
);
872 case WM_CHOOSEFONT_GETLOGFONT
:
873 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
875 FIXME(commdlg
, "current logfont back to caller\n");
878 WINPROC_UnmapMsg16To32A(hDlg
,uMsg32
, wParam32
, lParam
, res
);
882 /***********************************************************************
883 * FormatCharDlgProc32A [internal]
885 LRESULT WINAPI
FormatCharDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
890 if (uMsg
!=WM_INITDIALOG
)
892 lpcf
=(LPCHOOSEFONTA
)GetWindowLongA(hDlg
, DWL_USER
);
895 if (CFn_HookCallChk32(lpcf
))
896 res
=CallWindowProcA(lpcf
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
902 lpcf
=(LPCHOOSEFONTA
)lParam
;
903 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf
))
905 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
908 if (CFn_HookCallChk32(lpcf
))
909 return CallWindowProcA(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
914 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
916 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
917 case WM_CTLCOLORSTATIC
:
918 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf
);
920 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf
);
922 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
923 case WM_CHOOSEFONT_GETLOGFONT
:
924 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
926 FIXME(commdlg
, "current logfont back to caller\n");
932 /***********************************************************************
933 * FormatCharDlgProc32W [internal]
935 LRESULT WINAPI
FormatCharDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
938 LPCHOOSEFONTW lpcf32w
;
939 LPCHOOSEFONTA lpcf32a
;
941 if (uMsg
!=WM_INITDIALOG
)
943 lpcf32w
=(LPCHOOSEFONTW
)GetWindowLongA(hDlg
, DWL_USER
);
946 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
947 res
=CallWindowProcW(lpcf32w
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
953 lpcf32w
=(LPCHOOSEFONTW
)lParam
;
954 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
955 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
957 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
960 if (CFn_HookCallChk32((LPCHOOSEFONTA
)lpcf32w
))
961 return CallWindowProcW(lpcf32w
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
963 lpcf32a
=(LPCHOOSEFONTA
)lpcf32w
->lpTemplateName
;
967 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
969 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
970 case WM_CTLCOLORSTATIC
:
971 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf32a
);
973 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf32a
);
975 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
976 case WM_CHOOSEFONT_GETLOGFONT
:
977 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
979 FIXME(commdlg
, "current logfont back to caller\n");