2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
36 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
44 static void FONT_LogFont16To32A( const LPLOGFONT16 font16
, LPLOGFONTA font32
)
46 font32
->lfHeight
= font16
->lfHeight
;
47 font32
->lfWidth
= font16
->lfWidth
;
48 font32
->lfEscapement
= font16
->lfEscapement
;
49 font32
->lfOrientation
= font16
->lfOrientation
;
50 font32
->lfWeight
= font16
->lfWeight
;
51 font32
->lfItalic
= font16
->lfItalic
;
52 font32
->lfUnderline
= font16
->lfUnderline
;
53 font32
->lfStrikeOut
= font16
->lfStrikeOut
;
54 font32
->lfCharSet
= font16
->lfCharSet
;
55 font32
->lfOutPrecision
= font16
->lfOutPrecision
;
56 font32
->lfClipPrecision
= font16
->lfClipPrecision
;
57 font32
->lfQuality
= font16
->lfQuality
;
58 font32
->lfPitchAndFamily
= font16
->lfPitchAndFamily
;
59 lstrcpynA( font32
->lfFaceName
, font16
->lfFaceName
, LF_FACESIZE
);
62 static void FONT_Metrics16To32A( const TEXTMETRIC16
*pm16
,
63 NEWTEXTMETRICEXA
*pnm32a
)
65 ZeroMemory( pnm32a
, sizeof(NEWTEXTMETRICEXA
));
66 /* NOTE: only the fields used by AddFontStyle() are filled in */
67 pnm32a
->ntmTm
.tmHeight
= pm16
->tmHeight
;
68 pnm32a
->ntmTm
.tmExternalLeading
= pm16
->tmExternalLeading
;
71 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16
, LPCHOOSEFONTA chf32a
)
73 chf32a
->lStructSize
=sizeof(CHOOSEFONTA
);
74 chf32a
->hwndOwner
=HWND_32(chf16
->hwndOwner
);
75 chf32a
->hDC
=HDC_32(chf16
->hDC
);
76 chf32a
->iPointSize
=chf16
->iPointSize
;
77 chf32a
->Flags
=chf16
->Flags
;
78 chf32a
->rgbColors
=chf16
->rgbColors
;
79 chf32a
->lCustData
=chf16
->lCustData
;
80 chf32a
->lpfnHook
=NULL
;
81 chf32a
->lpTemplateName
=MapSL(chf16
->lpTemplateName
);
82 chf32a
->hInstance
=HINSTANCE_32(chf16
->hInstance
);
83 chf32a
->lpszStyle
=MapSL(chf16
->lpszStyle
);
84 chf32a
->nFontType
=chf16
->nFontType
;
85 chf32a
->nSizeMax
=chf16
->nSizeMax
;
86 chf32a
->nSizeMin
=chf16
->nSizeMin
;
87 FONT_LogFont16To32A(MapSL(chf16
->lpLogFont
), chf32a
->lpLogFont
);
90 /***********************************************************************
91 * CFn_HookCallChk [internal]
93 static BOOL
CFn_HookCallChk(LPCHOOSEFONT16 lpcf
)
96 if(lpcf
->Flags
& CF_ENABLEHOOK
)
102 /***********************************************************************
103 * FontFamilyEnumProc (COMMDLG.19)
105 INT16 WINAPI
FontFamilyEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
106 UINT16 nFontType
, LPARAM lParam
)
108 HWND hwnd
=HWND_32(LOWORD(lParam
));
109 HWND hDlg
=GetParent(hwnd
);
110 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
111 LOGFONT16
*lplf
= MapSL( logfont
);
112 TEXTMETRIC16
*lpmtrx16
= MapSL(metrics
);
113 ENUMLOGFONTEXA elf32a
;
114 NEWTEXTMETRICEXA nmtrx32a
;
115 FONT_LogFont16To32A(lplf
, &(elf32a
.elfLogFont
));
116 FONT_Metrics16To32A(lpmtrx16
, &nmtrx32a
);
117 return AddFontFamily(&elf32a
, &nmtrx32a
, nFontType
,
118 (LPCHOOSEFONTA
)lpcf
->lpTemplateName
, hwnd
,NULL
);
121 /***********************************************************************
122 * FontStyleEnumProc (COMMDLG.18)
124 INT16 WINAPI
FontStyleEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
125 UINT16 nFontType
, LPARAM lParam
)
127 HWND hcmb2
=HWND_32(LOWORD(lParam
));
128 HWND hcmb3
=HWND_32(HIWORD(lParam
));
129 HWND hDlg
=GetParent(hcmb3
);
130 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
131 LOGFONT16
*lplf
= MapSL(logfont
);
132 TEXTMETRIC16
*lpmtrx16
= MapSL(metrics
);
133 ENUMLOGFONTEXA elf32a
;
134 NEWTEXTMETRICEXA nmtrx32a
;
135 FONT_LogFont16To32A(lplf
, &(elf32a
.elfLogFont
));
136 FONT_Metrics16To32A(lpmtrx16
, &nmtrx32a
);
137 return AddFontStyle(&elf32a
, &nmtrx32a
, nFontType
,
138 (LPCHOOSEFONTA
)lpcf
->lpTemplateName
, hcmb2
, hcmb3
, hDlg
, TRUE
);
141 /***********************************************************************
142 * ChooseFont (COMMDLG.15)
144 BOOL16 WINAPI
ChooseFont16(LPCHOOSEFONT16 lpChFont
)
147 HANDLE16 hDlgTmpl16
= 0, hResource16
= 0;
148 HGLOBAL16 hGlobal16
= 0;
155 SEGPTR lpTemplateName
;
157 cf32a
.lpLogFont
=&lf32a
;
158 CFn_CHOOSEFONT16to32A(lpChFont
, &cf32a
);
160 TRACE("ChooseFont\n");
161 if (!lpChFont
) return FALSE
;
163 if (TRACE_ON(commdlg
))
164 _dump_cf_flags(lpChFont
->Flags
);
166 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
)
168 if (!(template = LockResource16( lpChFont
->hInstance
)))
170 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
174 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
177 if (!(hResInfo
= FindResource16( lpChFont
->hInstance
,
178 MapSL(lpChFont
->lpTemplateName
),
181 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
184 if (!(hDlgTmpl16
= LoadResource16( lpChFont
->hInstance
, hResInfo
)) ||
185 !(template = LockResource16( hDlgTmpl16
)))
187 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
197 if (!(hResInfo
= FindResourceA(COMDLG32_hInstance
, "CHOOSE_FONT", (LPSTR
)RT_DIALOG
)))
199 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
202 if (!(hDlgTmpl32
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
203 !(template32
= LockResource(hDlgTmpl32
)))
205 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
208 size
= SizeofResource(COMDLG32_hInstance
, hResInfo
);
209 hGlobal16
= GlobalAlloc16(0, size
);
212 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
213 ERR("alloc failure for %ld bytes\n", size
);
216 template = GlobalLock16(hGlobal16
);
219 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
220 ERR("global lock failure for %x handle\n", hGlobal16
);
221 GlobalFree16(hGlobal16
);
224 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
225 hDlgTmpl16
= hGlobal16
;
229 /* lpTemplateName is not used in the dialog */
230 lpTemplateName
=lpChFont
->lpTemplateName
;
231 lpChFont
->lpTemplateName
=(SEGPTR
)&cf32a
;
233 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 16);
234 hInst
= GetWindowLongA(HWND_32(lpChFont
->hwndOwner
), GWL_HINSTANCE
);
235 bRet
= DialogBoxIndirectParam16(hInst
, hDlgTmpl16
, lpChFont
->hwndOwner
,
236 (DLGPROC16
) ptr
, (DWORD
)lpChFont
);
237 if (hResource16
) FreeResource16(hDlgTmpl16
);
240 GlobalUnlock16(hGlobal16
);
241 GlobalFree16(hGlobal16
);
243 lpChFont
->lpTemplateName
=lpTemplateName
;
245 lpChFont
->iPointSize
= cf32a
.iPointSize
;
246 lpChFont
->Flags
= cf32a
.Flags
;
247 lpChFont
->rgbColors
= cf32a
.rgbColors
;
248 lpChFont
->lCustData
= cf32a
.lCustData
;
249 lpChFont
->nFontType
= cf32a
.nFontType
;
251 font16
= MapSL(lpChFont
->lpLogFont
);
252 font16
->lfHeight
= cf32a
.lpLogFont
->lfHeight
;
253 font16
->lfWidth
= cf32a
.lpLogFont
->lfWidth
;
254 font16
->lfEscapement
= cf32a
.lpLogFont
->lfEscapement
;
255 font16
->lfOrientation
= cf32a
.lpLogFont
->lfOrientation
;
256 font16
->lfWeight
= cf32a
.lpLogFont
->lfWeight
;
257 font16
->lfItalic
= cf32a
.lpLogFont
->lfItalic
;
258 font16
->lfUnderline
= cf32a
.lpLogFont
->lfUnderline
;
259 font16
->lfStrikeOut
= cf32a
.lpLogFont
->lfStrikeOut
;
260 font16
->lfCharSet
= cf32a
.lpLogFont
->lfCharSet
;
261 font16
->lfOutPrecision
= cf32a
.lpLogFont
->lfOutPrecision
;
262 font16
->lfClipPrecision
= cf32a
.lpLogFont
->lfClipPrecision
;
263 font16
->lfQuality
= cf32a
.lpLogFont
->lfQuality
;
264 font16
->lfPitchAndFamily
= cf32a
.lpLogFont
->lfPitchAndFamily
;
265 lstrcpynA( font16
->lfFaceName
, cf32a
.lpLogFont
->lfFaceName
, LF_FACESIZE
);
269 /***********************************************************************
270 * FormatCharDlgProc (COMMDLG.16)
271 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
272 2. some CF_.. flags are not supported
273 3. some TType extensions
275 BOOL16 CALLBACK
FormatCharDlgProc16(HWND16 hDlg16
, UINT16 message
,
276 WPARAM16 wParam
, LPARAM lParam
)
278 HWND hDlg
= HWND_32(hDlg16
);
281 if (message
!=WM_INITDIALOG
)
283 lpcf
=(LPCHOOSEFONT16
)GetWindowLongA(hDlg
, DWL_USER
);
284 if (!lpcf
&& message
!= WM_MEASUREITEM
)
286 if (CFn_HookCallChk(lpcf
))
287 res
=CallWindowProc16((WNDPROC16
)lpcf
->lpfnHook
,hDlg16
,message
,wParam
,lParam
);
293 lpcf
=(LPCHOOSEFONT16
)lParam
;
294 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
))
296 TRACE("CFn_WMInitDialog returned FALSE\n");
299 if (CFn_HookCallChk(lpcf
))
300 return CallWindowProc16((WNDPROC16
)lpcf
->lpfnHook
,hDlg16
,WM_INITDIALOG
,wParam
,lParam
);
306 MEASUREITEMSTRUCT16
* mis16
= MapSL(lParam
);
307 MEASUREITEMSTRUCT mis
;
308 mis
.CtlType
= mis16
->CtlType
;
309 mis
.CtlID
= mis16
->CtlID
;
310 mis
.itemID
= mis16
->itemID
;
311 mis
.itemWidth
= mis16
->itemWidth
;
312 mis
.itemHeight
= mis16
->itemHeight
;
313 mis
.itemData
= mis16
->itemData
;
314 res
= CFn_WMMeasureItem(hDlg
, wParam
, (LPARAM
)&mis
);
315 mis16
->itemWidth
= (UINT16
)mis
.itemWidth
;
316 mis16
->itemHeight
= (UINT16
)mis
.itemHeight
;
321 DRAWITEMSTRUCT16
* dis16
= MapSL(lParam
);
323 dis
.CtlType
= dis16
->CtlType
;
324 dis
.CtlID
= dis16
->CtlID
;
325 dis
.itemID
= dis16
->itemID
;
326 dis
.itemAction
= dis16
->itemAction
;
327 dis
.itemState
= dis16
->itemState
;
328 dis
.hwndItem
= HWND_32(dis16
->hwndItem
);
329 dis
.hDC
= HDC_32(dis16
->hDC
);
330 dis
.itemData
= dis16
->itemData
;
331 CONV_RECT16TO32( &dis16
->rcItem
, &dis
.rcItem
);
332 res
= CFn_WMDrawItem(hDlg
, wParam
, (LPARAM
)&dis
);
336 res
=CFn_WMCommand(hDlg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ), LOWORD(lParam
),
337 (LPCHOOSEFONTA
)lpcf
->lpTemplateName
);
340 res
=CFn_WMDestroy(hDlg
, wParam
, lParam
);
342 case WM_CHOOSEFONT_GETLOGFONT
:
343 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam
);
344 FIXME("current logfont back to caller\n");
347 res
= CFn_WMPaint(hDlg
, wParam
, lParam
, (LPCHOOSEFONTA
)lpcf
->lpTemplateName
);