Updated.
[wine/multimedia.git] / dlls / commdlg / fontdlg16.c
blob61dd598efa70dd1973604ab8fcc4955532a51240
1 /*
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
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winnls.h"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
34 #include "commdlg.h"
35 #include "dlgs.h"
36 #include "wine/debug.h"
37 #include "cderr.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
41 #include "cdlg.h"
42 #include "fontdlg.h"
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 CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONTA chf32a)
64 chf32a->lStructSize=sizeof(CHOOSEFONTA);
65 chf32a->hwndOwner=HWND_32(chf16->hwndOwner);
66 chf32a->hDC=HDC_32(chf16->hDC);
67 chf32a->iPointSize=chf16->iPointSize;
68 chf32a->Flags=chf16->Flags;
69 chf32a->rgbColors=chf16->rgbColors;
70 chf32a->lCustData=chf16->lCustData;
71 chf32a->lpfnHook=NULL;
72 chf32a->lpTemplateName=MapSL(chf16->lpTemplateName);
73 chf32a->hInstance=HINSTANCE_32(chf16->hInstance);
74 chf32a->lpszStyle=MapSL(chf16->lpszStyle);
75 chf32a->nFontType=chf16->nFontType;
76 chf32a->nSizeMax=chf16->nSizeMax;
77 chf32a->nSizeMin=chf16->nSizeMin;
78 FONT_LogFont16To32A(MapSL(chf16->lpLogFont), chf32a->lpLogFont);
81 /***********************************************************************
82 * CFn_HookCallChk [internal]
84 static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
86 if (lpcf)
87 if(lpcf->Flags & CF_ENABLEHOOK)
88 if (lpcf->lpfnHook)
89 return TRUE;
90 return FALSE;
93 /***********************************************************************
94 * FontFamilyEnumProc (COMMDLG.19)
96 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
97 UINT16 nFontType, LPARAM lParam )
99 HWND hwnd=HWND_32(LOWORD(lParam));
100 HWND hDlg=GetParent(hwnd);
101 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
102 LOGFONT16 *lplf = MapSL( logfont );
103 LOGFONTA lf32a;
104 FONT_LogFont16To32A(lplf, &lf32a);
105 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
106 hwnd,NULL);
109 /***********************************************************************
110 * FontStyleEnumProc (COMMDLG.18)
112 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
113 UINT16 nFontType, LPARAM lParam )
115 HWND hcmb2=HWND_32(LOWORD(lParam));
116 HWND hcmb3=HWND_32(HIWORD(lParam));
117 HWND hDlg=GetParent(hcmb3);
118 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
119 LOGFONT16 *lplf = MapSL(logfont);
120 LOGFONTA lf32a;
121 FONT_LogFont16To32A(lplf, &lf32a);
122 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
123 hcmb2, hcmb3, hDlg);
126 /***********************************************************************
127 * ChooseFont (COMMDLG.15)
129 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
131 HINSTANCE16 hInst;
132 HANDLE16 hDlgTmpl16 = 0, hResource16 = 0;
133 HGLOBAL16 hGlobal16 = 0;
134 BOOL16 bRet = FALSE;
135 LPCVOID template;
136 FARPROC16 ptr;
137 CHOOSEFONTA cf32a;
138 LOGFONTA lf32a;
139 LOGFONT16 *font16;
140 SEGPTR lpTemplateName;
142 cf32a.lpLogFont=&lf32a;
143 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
145 TRACE("ChooseFont\n");
146 if (!lpChFont) return FALSE;
148 if (TRACE_ON(commdlg))
149 _dump_cf_flags(lpChFont->Flags);
151 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
153 if (!(template = LockResource16( lpChFont->hInstance )))
155 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
156 return FALSE;
159 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
161 HANDLE16 hResInfo;
162 if (!(hResInfo = FindResource16( lpChFont->hInstance,
163 MapSL(lpChFont->lpTemplateName),
164 (LPSTR)RT_DIALOG)))
166 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
167 return FALSE;
169 if (!(hDlgTmpl16 = LoadResource16( lpChFont->hInstance, hResInfo )) ||
170 !(template = LockResource16( hDlgTmpl16 )))
172 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
173 return FALSE;
176 else
178 HRSRC hResInfo;
179 HGLOBAL hDlgTmpl32;
180 LPCVOID template32;
181 DWORD size;
182 if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
184 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
185 return FALSE;
187 if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo)) ||
188 !(template32 = LockResource(hDlgTmpl32)))
190 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
191 return FALSE;
193 size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo);
194 hGlobal16 = GlobalAlloc16(0, size);
195 if (!hGlobal16)
197 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
198 ERR("alloc failure for %ld bytes\n", size);
199 return FALSE;
201 template = GlobalLock16(hGlobal16);
202 if (!template)
204 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
205 ERR("global lock failure for %x handle\n", hGlobal16);
206 GlobalFree16(hGlobal16);
207 return FALSE;
209 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
210 hDlgTmpl16 = hGlobal16;
214 /* lpTemplateName is not used in the dialog */
215 lpTemplateName=lpChFont->lpTemplateName;
216 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
218 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 16);
219 hInst = GetWindowLongA(HWND_32(lpChFont->hwndOwner), GWL_HINSTANCE);
220 bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChFont->hwndOwner,
221 (DLGPROC16) ptr, (DWORD)lpChFont);
222 if (hResource16) FreeResource16(hDlgTmpl16);
223 if (hGlobal16)
225 GlobalUnlock16(hGlobal16);
226 GlobalFree16(hGlobal16);
228 lpChFont->lpTemplateName=lpTemplateName;
231 font16 = MapSL(lpChFont->lpLogFont);
232 font16->lfHeight = cf32a.lpLogFont->lfHeight;
233 font16->lfWidth = cf32a.lpLogFont->lfWidth;
234 font16->lfEscapement = cf32a.lpLogFont->lfEscapement;
235 font16->lfOrientation = cf32a.lpLogFont->lfOrientation;
236 font16->lfWeight = cf32a.lpLogFont->lfWeight;
237 font16->lfItalic = cf32a.lpLogFont->lfItalic;
238 font16->lfUnderline = cf32a.lpLogFont->lfUnderline;
239 font16->lfStrikeOut = cf32a.lpLogFont->lfStrikeOut;
240 font16->lfCharSet = cf32a.lpLogFont->lfCharSet;
241 font16->lfOutPrecision = cf32a.lpLogFont->lfOutPrecision;
242 font16->lfClipPrecision = cf32a.lpLogFont->lfClipPrecision;
243 font16->lfQuality = cf32a.lpLogFont->lfQuality;
244 font16->lfPitchAndFamily = cf32a.lpLogFont->lfPitchAndFamily;
245 lstrcpynA( font16->lfFaceName, cf32a.lpLogFont->lfFaceName, LF_FACESIZE );
246 return bRet;
249 /***********************************************************************
250 * FormatCharDlgProc (COMMDLG.16)
251 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
252 2. some CF_.. flags are not supported
253 3. some TType extensions
255 BOOL16 CALLBACK FormatCharDlgProc16(HWND16 hDlg16, UINT16 message,
256 WPARAM16 wParam, LPARAM lParam)
258 HWND hDlg = HWND_32(hDlg16);
259 LPCHOOSEFONT16 lpcf;
260 LPCHOOSEFONTA lpcf32a;
261 BOOL16 res=0;
262 if (message!=WM_INITDIALOG)
264 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
265 if (!lpcf)
266 return FALSE;
267 if (CFn_HookCallChk(lpcf))
268 res=CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg16,message,wParam,lParam);
269 if (res)
270 return res;
272 else
274 lpcf=(LPCHOOSEFONT16)lParam;
275 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
276 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
278 TRACE("CFn_WMInitDialog returned FALSE\n");
279 return FALSE;
281 if (CFn_HookCallChk(lpcf))
282 return CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg16,WM_INITDIALOG,wParam,lParam);
284 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
285 switch (message)
287 case WM_MEASUREITEM:
289 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
290 MEASUREITEMSTRUCT mis;
291 mis.CtlType = mis16->CtlType;
292 mis.CtlID = mis16->CtlID;
293 mis.itemID = mis16->itemID;
294 mis.itemWidth = mis16->itemWidth;
295 mis.itemHeight = mis16->itemHeight;
296 mis.itemData = mis16->itemData;
297 res = CFn_WMMeasureItem(hDlg, wParam, (LPARAM)&mis);
298 mis16->itemWidth = (UINT16)mis.itemWidth;
299 mis16->itemHeight = (UINT16)mis.itemHeight;
301 break;
302 case WM_DRAWITEM:
304 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
305 DRAWITEMSTRUCT dis;
306 dis.CtlType = dis16->CtlType;
307 dis.CtlID = dis16->CtlID;
308 dis.itemID = dis16->itemID;
309 dis.itemAction = dis16->itemAction;
310 dis.itemState = dis16->itemState;
311 dis.hwndItem = HWND_32(dis16->hwndItem);
312 dis.hDC = HDC_32(dis16->hDC);
313 dis.itemData = dis16->itemData;
314 CONV_RECT16TO32( &dis16->rcItem, &dis.rcItem );
315 res = CFn_WMDrawItem(hDlg, wParam, (LPARAM)&dis);
317 break;
318 case WM_COMMAND:
319 res=CFn_WMCommand(hDlg, MAKEWPARAM( wParam, HIWORD(lParam) ), LOWORD(lParam), lpcf32a);
320 break;
321 case WM_DESTROY:
322 res=CFn_WMDestroy(hDlg, wParam, lParam);
323 break;
324 case WM_CHOOSEFONT_GETLOGFONT:
325 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
326 FIXME("current logfont back to caller\n");
327 break;
329 return res;