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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
36 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
44 static const WCHAR strWineFontData16[] =
45 {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A','1','6',0};
47 static void FONT_LogFont16To32W( const LOGFONT16 *font16, LPLOGFONTW font32 )
49 font32->lfHeight = font16->lfHeight;
50 font32->lfWidth = font16->lfWidth;
51 font32->lfEscapement = font16->lfEscapement;
52 font32->lfOrientation = font16->lfOrientation;
53 font32->lfWeight = font16->lfWeight;
54 font32->lfItalic = font16->lfItalic;
55 font32->lfUnderline = font16->lfUnderline;
56 font32->lfStrikeOut = font16->lfStrikeOut;
57 font32->lfCharSet = font16->lfCharSet;
58 font32->lfOutPrecision = font16->lfOutPrecision;
59 font32->lfClipPrecision = font16->lfClipPrecision;
60 font32->lfQuality = font16->lfQuality;
61 font32->lfPitchAndFamily = font16->lfPitchAndFamily;
62 MultiByteToWideChar(CP_ACP, 0, font16->lfFaceName,
63 LF_FACESIZE, font32->lfFaceName, LF_FACESIZE);
66 static void FONT_Metrics16To32W( const TEXTMETRIC16 *pm16,
67 NEWTEXTMETRICEXW *pnm32w)
69 ZeroMemory( pnm32w, sizeof(NEWTEXTMETRICEXW));
70 /* NOTE: only the fields used by AddFontStyle() are filled in */
71 pnm32w->ntmTm.tmHeight = pm16->tmHeight;
72 pnm32w->ntmTm.tmExternalLeading = pm16->tmExternalLeading;
75 static void CFn_CHOOSEFONT16to32W(const CHOOSEFONT16 *chf16, LPCHOOSEFONTW chf32w)
78 if (chf16->Flags & CF_ENABLETEMPLATE)
80 len = MultiByteToWideChar( CP_ACP, 0, MapSL(chf16->lpTemplateName), -1, NULL, 0);
81 chf32w->lpTemplateName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
82 MultiByteToWideChar( CP_ACP, 0, MapSL(chf16->lpTemplateName),
83 -1, (LPWSTR)chf32w->lpTemplateName, len);
85 if (chf16->Flags & CF_USESTYLE)
87 len = MultiByteToWideChar( CP_ACP, 0, MapSL(chf16->lpszStyle), -1, NULL, 0);
88 chf32w->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
89 MultiByteToWideChar( CP_ACP, 0, MapSL(chf16->lpszStyle), -1, chf32w->lpszStyle, len);
91 chf32w->lStructSize=sizeof(CHOOSEFONTW);
92 chf32w->hwndOwner=HWND_32(chf16->hwndOwner);
93 chf32w->hDC=HDC_32(chf16->hDC);
94 chf32w->iPointSize=chf16->iPointSize;
95 chf32w->Flags=chf16->Flags;
96 chf32w->rgbColors=chf16->rgbColors;
97 chf32w->lCustData=chf16->lCustData;
98 chf32w->lpfnHook=NULL;
99 chf32w->hInstance=HINSTANCE_32(chf16->hInstance);
100 chf32w->nFontType=chf16->nFontType;
101 chf32w->nSizeMax=chf16->nSizeMax;
102 chf32w->nSizeMin=chf16->nSizeMin;
103 FONT_LogFont16To32W(MapSL(chf16->lpLogFont), chf32w->lpLogFont);
106 /***********************************************************************
107 * CFn_HookCallChk [internal]
109 static BOOL CFn_HookCallChk(const CHOOSEFONT16 *lpcf)
112 if(lpcf->Flags & CF_ENABLEHOOK)
118 /***********************************************************************
119 * FontFamilyEnumProc (COMMDLG.19)
121 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
122 UINT16 nFontType, LPARAM lParam )
124 HWND hwnd=HWND_32(LOWORD(lParam));
125 HWND hDlg=GetParent(hwnd);
127 LOGFONT16 *lplf = MapSL( logfont );
128 TEXTMETRIC16 *lpmtrx16 = MapSL(metrics);
129 ENUMLOGFONTEXW elf32w;
130 NEWTEXTMETRICEXW nmtrx32w;
132 lpcf = (LPCHOOSEFONT16)GetPropW(hDlg, strWineFontData16);
133 FONT_LogFont16To32W(lplf, &(elf32w.elfLogFont));
134 FONT_Metrics16To32W(lpmtrx16, &nmtrx32w);
135 return AddFontFamily(&elf32w, &nmtrx32w, nFontType,
136 (LPCHOOSEFONTW)lpcf->lpTemplateName, hwnd,NULL);
139 /***********************************************************************
140 * FontStyleEnumProc (COMMDLG.18)
142 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
143 UINT16 nFontType, LPARAM lParam )
145 HWND hcmb2=HWND_32(LOWORD(lParam));
146 HWND hcmb3=HWND_32(HIWORD(lParam));
147 HWND hDlg=GetParent(hcmb3);
149 LOGFONT16 *lplf = MapSL(logfont);
150 TEXTMETRIC16 *lpmtrx16 = MapSL(metrics);
151 ENUMLOGFONTEXW elf32w;
152 NEWTEXTMETRICEXW nmtrx32w;
154 lpcf = (LPCHOOSEFONT16)GetPropW(hDlg, strWineFontData16);
155 FONT_LogFont16To32W(lplf, &(elf32w.elfLogFont));
156 FONT_Metrics16To32W(lpmtrx16, &nmtrx32w);
157 return AddFontStyle(&elf32w, &nmtrx32w, nFontType,
158 (LPCHOOSEFONTW)lpcf->lpTemplateName, hcmb2, hcmb3, hDlg, TRUE);
161 /***********************************************************************
162 * ChooseFont (COMMDLG.15)
164 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
167 HANDLE16 hDlgTmpl16 = 0;
168 HGLOBAL16 hGlobal16 = 0;
175 SEGPTR lpTemplateName;
177 TRACE("ChooseFont\n");
179 if (!lpChFont) return FALSE;
181 cf32w.lpLogFont=&lf32w;
182 CFn_CHOOSEFONT16to32W(lpChFont, &cf32w);
184 if (TRACE_ON(commdlg))
185 _dump_cf_flags(lpChFont->Flags);
187 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
189 if (!(template = LockResource16( lpChFont->hInstance )))
191 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
195 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
198 if (!(hResInfo = FindResource16( lpChFont->hInstance,
199 MapSL(lpChFont->lpTemplateName),
202 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
205 if (!(hDlgTmpl16 = LoadResource16( lpChFont->hInstance, hResInfo )) ||
206 !(template = LockResource16( hDlgTmpl16 )))
208 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
218 if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
220 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
223 if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo)) ||
224 !(template32 = LockResource(hDlgTmpl32)))
226 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
229 size = SizeofResource(COMDLG32_hInstance, hResInfo);
230 hGlobal16 = GlobalAlloc16(0, size);
233 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
234 ERR("alloc failure for %d bytes\n", size);
237 template = GlobalLock16(hGlobal16);
240 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
241 ERR("global lock failure for %x handle\n", hGlobal16);
242 GlobalFree16(hGlobal16);
245 ConvertDialog32To16(template32, size, template);
246 hDlgTmpl16 = hGlobal16;
250 /* lpTemplateName is not used in the dialog */
251 lpTemplateName=lpChFont->lpTemplateName;
252 lpChFont->lpTemplateName=(SEGPTR)&cf32w;
254 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 16);
255 hInst = GetWindowLongPtrA(HWND_32(lpChFont->hwndOwner), GWLP_HINSTANCE);
256 bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChFont->hwndOwner,
257 (DLGPROC16) ptr, (DWORD)lpChFont);
260 GlobalUnlock16(hGlobal16);
261 GlobalFree16(hGlobal16);
263 lpChFont->lpTemplateName=lpTemplateName;
265 lpChFont->iPointSize = cf32w.iPointSize;
266 lpChFont->Flags = cf32w.Flags;
267 lpChFont->rgbColors = cf32w.rgbColors;
268 lpChFont->lCustData = cf32w.lCustData;
269 lpChFont->nFontType = cf32w.nFontType;
271 font16 = MapSL(lpChFont->lpLogFont);
272 font16->lfHeight = cf32w.lpLogFont->lfHeight;
273 font16->lfWidth = cf32w.lpLogFont->lfWidth;
274 font16->lfEscapement = cf32w.lpLogFont->lfEscapement;
275 font16->lfOrientation = cf32w.lpLogFont->lfOrientation;
276 font16->lfWeight = cf32w.lpLogFont->lfWeight;
277 font16->lfItalic = cf32w.lpLogFont->lfItalic;
278 font16->lfUnderline = cf32w.lpLogFont->lfUnderline;
279 font16->lfStrikeOut = cf32w.lpLogFont->lfStrikeOut;
280 font16->lfCharSet = cf32w.lpLogFont->lfCharSet;
281 font16->lfOutPrecision = cf32w.lpLogFont->lfOutPrecision;
282 font16->lfClipPrecision = cf32w.lpLogFont->lfClipPrecision;
283 font16->lfQuality = cf32w.lpLogFont->lfQuality;
284 font16->lfPitchAndFamily = cf32w.lpLogFont->lfPitchAndFamily;
285 WideCharToMultiByte(CP_ACP, 0, cf32w.lpLogFont->lfFaceName,
286 LF_FACESIZE, font16->lfFaceName, LF_FACESIZE, 0, 0);
288 HeapFree(GetProcessHeap(), 0, (LPBYTE)cf32w.lpTemplateName);
289 HeapFree(GetProcessHeap(), 0, cf32w.lpszStyle);
294 /***********************************************************************
295 * FormatCharDlgProc (COMMDLG.16)
296 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
297 2. some CF_.. flags are not supported
298 3. some TType extensions
300 BOOL16 CALLBACK FormatCharDlgProc16(HWND16 hDlg16, UINT16 message,
301 WPARAM16 wParam, LPARAM lParam)
303 HWND hDlg = HWND_32(hDlg16);
306 if (message!=WM_INITDIALOG)
308 lpcf = (LPCHOOSEFONT16)GetPropW(hDlg, strWineFontData16);
311 if (CFn_HookCallChk(lpcf))
312 res=CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg16,message,wParam,lParam);
318 lpcf=(LPCHOOSEFONT16)lParam;
319 if (!CFn_WMInitDialog(hDlg, wParam, lParam, (LPCHOOSEFONTW)lpcf->lpTemplateName))
321 TRACE("CFn_WMInitDialog returned FALSE\n");
324 SetPropW(hDlg, strWineFontData16, (HANDLE)lParam);
325 if (CFn_HookCallChk(lpcf))
326 return CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg16,WM_INITDIALOG,wParam,lParam);
332 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
333 MEASUREITEMSTRUCT mis;
334 mis.CtlType = mis16->CtlType;
335 mis.CtlID = mis16->CtlID;
336 mis.itemID = mis16->itemID;
337 mis.itemWidth = mis16->itemWidth;
338 mis.itemHeight = mis16->itemHeight;
339 mis.itemData = mis16->itemData;
340 res = CFn_WMMeasureItem(hDlg, wParam, (LPARAM)&mis);
341 mis16->itemWidth = (UINT16)mis.itemWidth;
342 mis16->itemHeight = (UINT16)mis.itemHeight;
347 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
349 dis.CtlType = dis16->CtlType;
350 dis.CtlID = dis16->CtlID;
351 dis.itemID = dis16->itemID;
352 dis.itemAction = dis16->itemAction;
353 dis.itemState = dis16->itemState;
354 dis.hwndItem = HWND_32(dis16->hwndItem);
355 dis.hDC = HDC_32(dis16->hDC);
356 dis.itemData = dis16->itemData;
357 dis.rcItem.left = dis16->rcItem.left;
358 dis.rcItem.top = dis16->rcItem.top;
359 dis.rcItem.right = dis16->rcItem.right;
360 dis.rcItem.bottom = dis16->rcItem.bottom;
361 res = CFn_WMDrawItem(hDlg, wParam, (LPARAM)&dis);
365 res=CFn_WMCommand(hDlg, MAKEWPARAM( wParam, HIWORD(lParam) ), LOWORD(lParam),
366 (LPCHOOSEFONTW)lpcf->lpTemplateName);
370 case WM_CHOOSEFONT_GETLOGFONT:
371 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
372 FIXME("current logfont back to caller\n");
375 res= CFn_WMPaint(hDlg, wParam, lParam, (LPCHOOSEFONTW)lpcf->lpTemplateName);