Added LGPL standard comment, and copyright notices where necessary.
[wine/multimedia.git] / dlls / commdlg / fontdlg.c
blobfd4618bf0fe5bff4e7c0f3a08beafe62d44aa0af
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 <stdio.h>
25 #include <string.h>
26 #include "windef.h"
27 #include "winnls.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "wine/winbase16.h"
31 #include "wine/winuser16.h"
32 #include "heap.h"
33 #include "commdlg.h"
34 #include "dlgs.h"
35 #include "wine/debug.h"
36 #include "cderr.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
40 #include "cdlg.h"
42 static HBITMAP16 hBitmapTT = 0;
45 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
46 LPARAM lParam);
47 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
48 LPARAM lParam);
49 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
50 LPARAM lParam);
52 static void FONT_LogFont16To32A( const LPLOGFONT16 font16, LPLOGFONTA font32 )
54 font32->lfHeight = font16->lfHeight;
55 font32->lfWidth = font16->lfWidth;
56 font32->lfEscapement = font16->lfEscapement;
57 font32->lfOrientation = font16->lfOrientation;
58 font32->lfWeight = font16->lfWeight;
59 font32->lfItalic = font16->lfItalic;
60 font32->lfUnderline = font16->lfUnderline;
61 font32->lfStrikeOut = font16->lfStrikeOut;
62 font32->lfCharSet = font16->lfCharSet;
63 font32->lfOutPrecision = font16->lfOutPrecision;
64 font32->lfClipPrecision = font16->lfClipPrecision;
65 font32->lfQuality = font16->lfQuality;
66 font32->lfPitchAndFamily = font16->lfPitchAndFamily;
67 lstrcpynA( font32->lfFaceName, font16->lfFaceName, LF_FACESIZE );
70 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONTA chf32a)
72 chf32a->lStructSize=sizeof(CHOOSEFONTA);
73 chf32a->hwndOwner=chf16->hwndOwner;
74 chf32a->hDC=chf16->hDC;
75 chf32a->iPointSize=chf16->iPointSize;
76 chf32a->Flags=chf16->Flags;
77 chf32a->rgbColors=chf16->rgbColors;
78 chf32a->lCustData=chf16->lCustData;
79 chf32a->lpfnHook=NULL;
80 chf32a->lpTemplateName=MapSL(chf16->lpTemplateName);
81 chf32a->hInstance=chf16->hInstance;
82 chf32a->lpszStyle=MapSL(chf16->lpszStyle);
83 chf32a->nFontType=chf16->nFontType;
84 chf32a->nSizeMax=chf16->nSizeMax;
85 chf32a->nSizeMin=chf16->nSizeMin;
86 FONT_LogFont16To32A(MapSL(chf16->lpLogFont), chf32a->lpLogFont);
89 struct {
90 int mask;
91 char *name;
92 } cfflags[] = {
93 #define XX(x) { x, #x },
94 XX(CF_SCREENFONTS)
95 XX(CF_PRINTERFONTS)
96 XX(CF_SHOWHELP)
97 XX(CF_ENABLEHOOK)
98 XX(CF_ENABLETEMPLATE)
99 XX(CF_ENABLETEMPLATEHANDLE)
100 XX(CF_INITTOLOGFONTSTRUCT)
101 XX(CF_USESTYLE)
102 XX(CF_EFFECTS)
103 XX(CF_APPLY)
104 XX(CF_ANSIONLY)
105 XX(CF_NOVECTORFONTS)
106 XX(CF_NOSIMULATIONS)
107 XX(CF_LIMITSIZE)
108 XX(CF_FIXEDPITCHONLY)
109 XX(CF_WYSIWYG)
110 XX(CF_FORCEFONTEXIST)
111 XX(CF_SCALABLEONLY)
112 XX(CF_TTONLY)
113 XX(CF_NOFACESEL)
114 XX(CF_NOSTYLESEL)
115 XX(CF_NOSIZESEL)
116 XX(CF_SELECTSCRIPT)
117 XX(CF_NOSCRIPTSEL)
118 XX(CF_NOVERTFONTS)
119 #undef XX
120 {0,NULL},
123 static void
124 _dump_cf_flags(DWORD cflags) {
125 int i;
127 for (i=0;cfflags[i].name;i++)
128 if (cfflags[i].mask & cflags)
129 MESSAGE("%s|",cfflags[i].name);
130 MESSAGE("\n");
134 /***********************************************************************
135 * ChooseFont (COMMDLG.15)
137 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
139 HINSTANCE16 hInst;
140 HANDLE16 hDlgTmpl16 = 0, hResource16 = 0;
141 HGLOBAL16 hGlobal16 = 0;
142 BOOL16 bRet = FALSE;
143 LPCVOID template;
144 FARPROC16 ptr;
145 CHOOSEFONTA cf32a;
146 LOGFONTA lf32a;
147 LOGFONT16 *font16;
148 SEGPTR lpTemplateName;
150 cf32a.lpLogFont=&lf32a;
151 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
153 TRACE("ChooseFont\n");
154 if (!lpChFont) return FALSE;
156 if (TRACE_ON(commdlg))
157 _dump_cf_flags(lpChFont->Flags);
159 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
161 if (!(template = LockResource16( lpChFont->hInstance )))
163 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
164 return FALSE;
167 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
169 HANDLE16 hResInfo;
170 if (!(hResInfo = FindResource16( lpChFont->hInstance,
171 MapSL(lpChFont->lpTemplateName),
172 RT_DIALOGA)))
174 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
175 return FALSE;
177 if (!(hDlgTmpl16 = LoadResource16( lpChFont->hInstance, hResInfo )) ||
178 !(template = LockResource16( hDlgTmpl16 )))
180 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
181 return FALSE;
184 else
186 HANDLE hResInfo, hDlgTmpl32;
187 LPCVOID template32;
188 DWORD size;
189 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
191 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
192 return FALSE;
194 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo)) ||
195 !(template32 = LockResource(hDlgTmpl32)))
197 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
198 return FALSE;
200 size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo);
201 hGlobal16 = GlobalAlloc16(0, size);
202 if (!hGlobal16)
204 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
205 ERR("alloc failure for %ld bytes\n", size);
206 return FALSE;
208 template = GlobalLock16(hGlobal16);
209 if (!template)
211 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
212 ERR("global lock failure for %x handle\n", hGlobal16);
213 GlobalFree16(hGlobal16);
214 return FALSE;
216 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
217 hDlgTmpl16 = hGlobal16;
221 /* lpTemplateName is not used in the dialog */
222 lpTemplateName=lpChFont->lpTemplateName;
223 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
225 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 16);
226 hInst = GetWindowLongA(lpChFont->hwndOwner, GWL_HINSTANCE);
227 bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChFont->hwndOwner,
228 (DLGPROC16) ptr, (DWORD)lpChFont);
229 if (hResource16) FreeResource16(hDlgTmpl16);
230 if (hGlobal16)
232 GlobalUnlock16(hGlobal16);
233 GlobalFree16(hGlobal16);
235 lpChFont->lpTemplateName=lpTemplateName;
238 font16 = MapSL(lpChFont->lpLogFont);
239 font16->lfHeight = cf32a.lpLogFont->lfHeight;
240 font16->lfWidth = cf32a.lpLogFont->lfWidth;
241 font16->lfEscapement = cf32a.lpLogFont->lfEscapement;
242 font16->lfOrientation = cf32a.lpLogFont->lfOrientation;
243 font16->lfWeight = cf32a.lpLogFont->lfWeight;
244 font16->lfItalic = cf32a.lpLogFont->lfItalic;
245 font16->lfUnderline = cf32a.lpLogFont->lfUnderline;
246 font16->lfStrikeOut = cf32a.lpLogFont->lfStrikeOut;
247 font16->lfCharSet = cf32a.lpLogFont->lfCharSet;
248 font16->lfOutPrecision = cf32a.lpLogFont->lfOutPrecision;
249 font16->lfClipPrecision = cf32a.lpLogFont->lfClipPrecision;
250 font16->lfQuality = cf32a.lpLogFont->lfQuality;
251 font16->lfPitchAndFamily = cf32a.lpLogFont->lfPitchAndFamily;
252 lstrcpynA( font16->lfFaceName, cf32a.lpLogFont->lfFaceName, LF_FACESIZE );
253 return bRet;
257 /***********************************************************************
258 * ChooseFontA (COMDLG32.@)
260 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
262 LPCVOID template;
263 HANDLE hResInfo, hDlgTmpl;
265 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
267 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
268 return FALSE;
270 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
271 !(template = LockResource( hDlgTmpl )))
273 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
274 return FALSE;
276 if (TRACE_ON(commdlg))
277 _dump_cf_flags(lpChFont->Flags);
279 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
280 CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
281 return DialogBoxIndirectParamA(COMMDLG_hInstance32, template,
282 lpChFont->hwndOwner, (DLGPROC)FormatCharDlgProcA, (LPARAM)lpChFont );
285 /***********************************************************************
286 * ChooseFontW (COMDLG32.@)
288 * NOTES:
290 * The LOGFONT conversion functions will break if the structure ever
291 * grows beyond the lfFaceName element.
293 * The CHOOSEFONT conversion functions assume that both versions of
294 * lpLogFont and lpszStyle (if used) point to pre-allocated objects.
296 * The ASCII version of lpTemplateName is created by ChooseFontAtoW
297 * and freed by ChooseFontWtoA.
299 inline static VOID LogFontWtoA(const LOGFONTW *lfw, LOGFONTA *lfa)
301 memcpy(lfa, lfw, sizeof(LOGFONTA));
302 WideCharToMultiByte(CP_ACP, 0, lfw->lfFaceName, -1, lfa->lfFaceName,
303 LF_FACESIZE, NULL, NULL);
304 lfa->lfFaceName[LF_FACESIZE - 1] = '\0';
307 inline static VOID LogFontAtoW(const LOGFONTA *lfa, LOGFONTW *lfw)
309 memcpy(lfw, lfa, sizeof(LOGFONTA));
310 MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw->lfFaceName,
311 LF_FACESIZE);
312 lfw->lfFaceName[LF_FACESIZE - 1] = 0;
315 static BOOL ChooseFontWtoA(const CHOOSEFONTW *cfw, CHOOSEFONTA *cfa)
317 LOGFONTA *lpLogFont = cfa->lpLogFont;
318 LPSTR lpszStyle = cfa->lpszStyle;
320 memcpy(cfa, cfw, sizeof(CHOOSEFONTA));
321 cfa->lpLogFont = lpLogFont;
322 cfa->lpszStyle = lpszStyle;
324 LogFontWtoA(cfw->lpLogFont, lpLogFont);
326 if (cfw->lpTemplateName != NULL)
328 cfa->lpTemplateName = HEAP_strdupWtoA(GetProcessHeap(), 0,
329 cfw->lpTemplateName);
330 if (cfa->lpTemplateName == NULL)
331 return FALSE;
334 if ((cfw->Flags & CF_USESTYLE) != 0 && cfw->lpszStyle != NULL)
336 WideCharToMultiByte(CP_ACP, 0, cfw->lpszStyle, -1, cfa->lpszStyle,
337 LF_FACESIZE, NULL, NULL);
338 cfa->lpszStyle[LF_FACESIZE - 1] = '\0';
341 return TRUE;
344 static VOID ChooseFontAtoW(const CHOOSEFONTA *cfa, CHOOSEFONTW *cfw)
346 LOGFONTW *lpLogFont = cfw->lpLogFont;
347 LPWSTR lpszStyle = cfw->lpszStyle;
348 LPCWSTR lpTemplateName = cfw->lpTemplateName;
350 memcpy(cfw, cfa, sizeof(CHOOSEFONTA));
351 cfw->lpLogFont = lpLogFont;
352 cfw->lpszStyle = lpszStyle;
353 cfw->lpTemplateName = lpTemplateName;
355 LogFontAtoW(cfa->lpLogFont, lpLogFont);
357 if (cfa->lpTemplateName != NULL)
358 HeapFree(GetProcessHeap(), 0, (LPSTR)(cfa->lpTemplateName));
360 if ((cfa->Flags & CF_USESTYLE) != 0 && cfa->lpszStyle != NULL)
362 MultiByteToWideChar(CP_ACP, 0, cfa->lpszStyle, -1, cfw->lpszStyle,
363 LF_FACESIZE);
364 cfw->lpszStyle[LF_FACESIZE - 1] = 0;
368 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
370 CHOOSEFONTA cf_a;
371 LOGFONTA lf_a;
372 CHAR style_a[LF_FACESIZE];
374 cf_a.lpLogFont = &lf_a;
375 cf_a.lpszStyle = style_a;
377 if (ChooseFontWtoA(lpChFont, &cf_a) == FALSE)
379 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
380 return FALSE;
383 if (ChooseFontA(&cf_a) == FALSE)
385 if (cf_a.lpTemplateName != NULL)
386 HeapFree(GetProcessHeap(), 0, (LPSTR)(cf_a.lpTemplateName));
387 return FALSE;
390 ChooseFontAtoW(&cf_a, lpChFont);
392 return TRUE;
395 #if 0
396 /***********************************************************************
397 * ChooseFontW (COMDLG32.@)
399 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
401 BOOL bRet=FALSE;
402 CHOOSEFONTA cf32a;
403 LOGFONTA lf32a;
404 LPCVOID template;
405 HANDLE hResInfo, hDlgTmpl;
407 if (TRACE_ON(commdlg))
408 _dump_cf_flags(lpChFont->Flags);
410 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
412 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
413 return FALSE;
415 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
416 !(template = LockResource( hDlgTmpl )))
418 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
419 return FALSE;
422 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
423 CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
424 memcpy(&cf32a, lpChFont, sizeof(cf32a));
425 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
427 WideCharToMultiByte( CP_ACP, 0, lpChFont->lpLogFont->lfFaceName, -1,
428 lf32a.lfFaceName, LF_FACESIZE, NULL, NULL );
429 lf32a.lfFaceName[LF_FACESIZE-1] = 0;
430 cf32a.lpLogFont=&lf32a;
431 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
432 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
433 bRet = DialogBoxIndirectParamW(COMMDLG_hInstance32, template,
434 lpChFont->hwndOwner, (DLGPROC)FormatCharDlgProcW, (LPARAM)lpChFont );
435 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
436 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
437 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
438 MultiByteToWideChar( CP_ACP, 0, lf32a.lfFaceName, -1,
439 lpChFont->lpLogFont->lfFaceName, LF_FACESIZE );
440 lpChFont->lpLogFont->lfFaceName[LF_FACESIZE-1] = 0;
441 return bRet;
443 #endif
445 #define TEXT_EXTRAS 4
446 #define TEXT_COLORS 16
448 static const COLORREF textcolors[TEXT_COLORS]=
450 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
451 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
452 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
453 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
456 /***********************************************************************
457 * CFn_HookCallChk [internal]
459 static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
461 if (lpcf)
462 if(lpcf->Flags & CF_ENABLEHOOK)
463 if (lpcf->lpfnHook)
464 return TRUE;
465 return FALSE;
468 /***********************************************************************
469 * CFn_HookCallChk32 [internal]
471 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
473 if (lpcf)
474 if(lpcf->Flags & CF_ENABLEHOOK)
475 if (lpcf->lpfnHook)
476 return TRUE;
477 return FALSE;
480 typedef struct
482 HWND hWnd1;
483 HWND hWnd2;
484 LPCHOOSEFONTA lpcf32a;
485 int added;
486 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
488 /*************************************************************************
489 * AddFontFamily [internal]
491 static INT AddFontFamily(const LOGFONTA *lplf, UINT nFontType,
492 LPCHOOSEFONTA lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
494 int i;
495 WORD w;
497 TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
499 if (lpcf->Flags & CF_FIXEDPITCHONLY)
500 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
501 return 1;
502 if (lpcf->Flags & CF_ANSIONLY)
503 if (lplf->lfCharSet != ANSI_CHARSET)
504 return 1;
505 if (lpcf->Flags & CF_TTONLY)
506 if (!(nFontType & TRUETYPE_FONTTYPE))
507 return 1;
509 if (e) e->added++;
511 i=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
512 if (i!=CB_ERR)
514 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
515 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
516 return 1 ; /* store some important font information */
518 else
519 return 0;
522 /*************************************************************************
523 * FontFamilyEnumProc32 [internal]
525 static INT WINAPI FontFamilyEnumProc(const LOGFONTA *lpLogFont,
526 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam)
528 LPCFn_ENUMSTRUCT e;
529 e=(LPCFn_ENUMSTRUCT)lParam;
530 return AddFontFamily(lpLogFont, dwFontType, e->lpcf32a, e->hWnd1, e);
533 /***********************************************************************
534 * FontFamilyEnumProc (COMMDLG.19)
536 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
537 UINT16 nFontType, LPARAM lParam )
539 HWND16 hwnd=LOWORD(lParam);
540 HWND hDlg=GetParent(hwnd);
541 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
542 LOGFONT16 *lplf = MapSL( logfont );
543 LOGFONTA lf32a;
544 FONT_LogFont16To32A(lplf, &lf32a);
545 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
546 hwnd,NULL);
549 /*************************************************************************
550 * SetFontStylesToCombo2 [internal]
552 * Fill font style information into combobox (without using font.c directly)
554 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTA *lplf)
556 #define FSTYLES 4
557 struct FONTSTYLE
558 { int italic;
559 int weight;
560 char stname[20]; };
561 static struct FONTSTYLE fontstyles[FSTYLES]={
562 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
563 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
564 HFONT hf;
565 TEXTMETRICA tm;
566 int i,j;
567 LOGFONTA lf;
569 memcpy(&lf, lplf, sizeof(LOGFONTA));
571 for (i=0;i<FSTYLES;i++)
573 lf.lfItalic=fontstyles[i].italic;
574 lf.lfWeight=fontstyles[i].weight;
575 hf=CreateFontIndirectA(&lf);
576 hf=SelectObject(hdc,hf);
577 GetTextMetricsA(hdc,&tm);
578 hf=SelectObject(hdc,hf);
579 DeleteObject(hf);
581 if (tm.tmWeight==fontstyles[i].weight &&
582 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
584 j=SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
585 if (j==CB_ERR) return 1;
586 j=SendMessageA(hwnd, CB_SETITEMDATA, j,
587 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
588 if (j==CB_ERR) return 1;
591 return 0;
594 /*************************************************************************
595 * AddFontSizeToCombo3 [internal]
597 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
599 int j;
600 char buffer[20];
602 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
603 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
605 sprintf(buffer, "%2d", h);
606 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
607 if (j==CB_ERR)
609 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
610 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
611 if (j==CB_ERR) return 1;
614 return 0;
617 /*************************************************************************
618 * SetFontSizesToCombo3 [internal]
620 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
622 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
623 int i;
625 for (i=0; sizes[i]; i++)
626 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
627 return 0;
630 /***********************************************************************
631 * AddFontStyle [internal]
633 static INT AddFontStyle(const LOGFONTA *lplf, UINT nFontType,
634 LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
636 int i;
638 TRACE("(nFontType=%d)\n",nFontType);
639 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
640 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
641 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
642 lplf->lfEscapement,lplf->lfOrientation,
643 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
644 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
645 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
646 if (nFontType & RASTER_FONTTYPE)
648 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
649 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
651 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
653 HDC hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
654 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
655 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
656 ReleaseDC(hDlg,hdc);
657 if (i)
658 return 0;
660 return 1 ;
664 /***********************************************************************
665 * FontStyleEnumProc (COMMDLG.18)
667 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
668 UINT16 nFontType, LPARAM lParam )
670 HWND16 hcmb2=LOWORD(lParam);
671 HWND16 hcmb3=HIWORD(lParam);
672 HWND hDlg=GetParent(hcmb3);
673 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
674 LOGFONT16 *lplf = MapSL(logfont);
675 LOGFONTA lf32a;
676 FONT_LogFont16To32A(lplf, &lf32a);
677 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
678 hcmb2, hcmb3, hDlg);
681 /***********************************************************************
682 * FontStyleEnumProc32 [internal]
684 static INT WINAPI FontStyleEnumProc( const LOGFONTA *lpFont,
685 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam )
687 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
688 HWND hcmb2=s->hWnd1;
689 HWND hcmb3=s->hWnd2;
690 HWND hDlg=GetParent(hcmb3);
691 return AddFontStyle(lpFont, dwFontType, s->lpcf32a, hcmb2,
692 hcmb3, hDlg);
695 /***********************************************************************
696 * CFn_WMInitDialog [internal]
698 static LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
699 LPCHOOSEFONTA lpcf)
701 HDC hdc;
702 int i,j,res,init=0;
703 long l;
704 LPLOGFONTA lpxx;
705 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
707 SetWindowLongA(hDlg, DWL_USER, lParam);
708 lpxx=lpcf->lpLogFont;
709 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
711 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
713 ERR("structure size failure !!!\n");
714 EndDialog (hDlg, 0);
715 return FALSE;
717 if (!hBitmapTT)
718 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
720 /* This font will be deleted by WM_COMMAND */
721 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,
722 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
724 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
725 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
726 if (!(lpcf->Flags & CF_APPLY))
727 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
728 if (lpcf->Flags & CF_EFFECTS)
730 for (res=1,i=0;res && i<TEXT_COLORS;i++)
732 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
733 char name[20];
734 strcpy( name, "[color name]" );
735 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
736 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
737 /* look for a fitting value in color combobox */
738 if (textcolors[j]==lpcf->rgbColors)
739 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
742 else
744 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
745 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
746 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
747 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
748 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
750 hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
751 if (hdc)
753 CFn_ENUMSTRUCT s;
754 s.hWnd1=GetDlgItem(hDlg,cmb1);
755 s.lpcf32a=lpcf;
756 do {
757 s.added = 0;
758 if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s)) {
759 TRACE("EnumFontFamilies returns 0\n");
760 break;
762 if (s.added) break;
763 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
764 FIXME("No founds found with fixed pitch only, dropping flag.\n");
765 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
766 continue;
768 if (lpcf->Flags & CF_TTONLY) {
769 FIXME("No founds found with truetype only, dropping flag.\n");
770 lpcf->Flags &= ~CF_TTONLY;
771 continue;
773 break;
774 } while (1);
777 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
779 /* look for fitting font name in combobox1 */
780 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
781 if (j!=CB_ERR)
783 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
784 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
785 GetDlgItem(hDlg,cmb1));
786 init=1;
787 /* look for fitting font style in combobox2 */
788 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
789 for (i=0;i<TEXT_EXTRAS;i++)
791 if (l==SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0))
792 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
795 /* look for fitting font size in combobox3 */
796 j=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
797 for (i=0;i<j;i++)
799 if (lpxx->lfHeight==(int)SendDlgItemMessageA(hDlg,cmb3, CB_GETITEMDATA,i,0))
800 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
804 if (!init)
806 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
807 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
808 GetDlgItem(hDlg,cmb1));
810 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
812 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
813 if (j!=CB_ERR)
815 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
816 SendMessageA(hDlg,WM_COMMAND,cmb2,
817 MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
821 else
823 WARN("HDC failure !!!\n");
824 EndDialog (hDlg, 0);
825 return FALSE;
828 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
829 ReleaseDC(hDlg,hdc);
830 SetCursor(hcursor);
831 return TRUE;
835 /***********************************************************************
836 * CFn_WMMeasureItem [internal]
838 static LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
840 BITMAP bm;
841 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
842 if (!hBitmapTT)
843 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
844 GetObjectA( hBitmapTT, sizeof(bm), &bm );
845 lpmi->itemHeight=bm.bmHeight;
846 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
847 return 0;
851 /***********************************************************************
852 * CFn_WMDrawItem [internal]
854 static LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
856 HBRUSH hBrush;
857 char buffer[40];
858 BITMAP bm;
859 COLORREF cr, oldText=0, oldBk=0;
860 RECT rect;
861 #if 0
862 HDC hMemDC;
863 int nFontType;
864 HBITMAP hBitmap; /* for later TT usage */
865 #endif
866 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
868 if (lpdi->itemID == (UINT)-1) /* got no items */
869 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
870 else
872 if (lpdi->CtlType == ODT_COMBOBOX)
874 if (lpdi->itemState ==ODS_SELECTED)
876 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
877 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
878 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
879 } else
881 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
882 SelectObject(lpdi->hDC, hBrush);
884 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
886 else
887 return TRUE; /* this should never happen */
889 rect=lpdi->rcItem;
890 switch (lpdi->CtlID)
892 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
893 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
894 (LPARAM)buffer);
895 GetObjectA( hBitmapTT, sizeof(bm), &bm );
896 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
897 lpdi->rcItem.top, buffer, strlen(buffer));
898 #if 0
899 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
900 /* FIXME: draw bitmap if truetype usage */
901 if (nFontType&TRUETYPE_FONTTYPE)
903 hMemDC = CreateCompatibleDC(lpdi->hDC);
904 hBitmap = SelectObject(hMemDC, hBitmapTT);
905 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
906 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
907 SelectObject(hMemDC, hBitmap);
908 DeleteDC(hMemDC);
910 #endif
911 break;
912 case cmb2:
913 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
914 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
915 (LPARAM)buffer);
916 TextOutA(lpdi->hDC, lpdi->rcItem.left,
917 lpdi->rcItem.top, buffer, strlen(buffer));
918 break;
920 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
921 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
922 (LPARAM)buffer);
923 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
924 lpdi->rcItem.top, buffer, strlen(buffer));
925 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
926 hBrush = CreateSolidBrush(cr);
927 if (hBrush)
929 hBrush = SelectObject (lpdi->hDC, hBrush) ;
930 rect.right=rect.left+25;
931 rect.top++;
932 rect.left+=5;
933 rect.bottom--;
934 Rectangle( lpdi->hDC, rect.left, rect.top,
935 rect.right, rect.bottom );
936 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
938 rect=lpdi->rcItem;
939 rect.left+=25+5;
940 break;
942 default: return TRUE; /* this should never happen */
944 if (lpdi->itemState == ODS_SELECTED)
946 SetTextColor(lpdi->hDC, oldText);
947 SetBkColor(lpdi->hDC, oldBk);
950 return TRUE;
953 /***********************************************************************
954 * CFn_WMCtlColor [internal]
956 static LRESULT CFn_WMCtlColorStatic(HWND hDlg, WPARAM wParam, LPARAM lParam,
957 LPCHOOSEFONTA lpcf)
959 if (lpcf->Flags & CF_EFFECTS)
960 if (GetDlgCtrlID(lParam)==stc6)
962 SetTextColor((HDC)wParam, lpcf->rgbColors);
963 return GetStockObject(WHITE_BRUSH);
965 return 0;
968 /***********************************************************************
969 * CFn_WMCommand [internal]
971 static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
972 LPCHOOSEFONTA lpcf)
974 HFONT hFont;
975 int i,j;
976 long l;
977 HDC hdc;
978 LPLOGFONTA lpxx=lpcf->lpLogFont;
980 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
981 switch (LOWORD(wParam))
983 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
985 hdc=((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
986 if (hdc)
988 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
989 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
990 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
991 if (i!=CB_ERR)
993 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
994 CFn_ENUMSTRUCT s;
995 char str[256];
996 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
997 (LPARAM)str);
998 TRACE("WM_COMMAND/cmb1 =>%s\n",str);
999 s.hWnd1=GetDlgItem(hDlg, cmb2);
1000 s.hWnd2=GetDlgItem(hDlg, cmb3);
1001 s.lpcf32a=lpcf;
1002 EnumFontFamiliesA(hdc, str, FontStyleEnumProc, (LPARAM)&s);
1003 SendDlgItemMessageA(hDlg,cmb2, CB_SETCURSEL, 0, 0);
1004 SendDlgItemMessageA(hDlg,cmb3, CB_SETCURSEL, 0, 0);
1005 SetCursor(hcursor);
1007 if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
1008 ReleaseDC(hDlg,hdc);
1010 else
1012 WARN("HDC failure !!!\n");
1013 EndDialog (hDlg, 0);
1014 return TRUE;
1017 case chx1:
1018 case chx2:
1019 case cmb2:
1020 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
1022 char str[256];
1023 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
1024 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
1025 if (i==CB_ERR)
1026 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
1027 else
1029 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
1030 (LPARAM)str);
1031 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
1032 j=HIWORD(l);
1033 lpcf->nFontType = LOWORD(l);
1034 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
1035 /* same value reported to the EnumFonts
1036 call back with the extra FONTTYPE_... bits added */
1037 lpxx->lfPitchAndFamily=j&0xff;
1038 lpxx->lfCharSet=j>>8;
1040 strcpy(lpxx->lfFaceName,str);
1041 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1042 if (i!=CB_ERR)
1044 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
1045 if (0!=(lpxx->lfItalic=HIWORD(l)))
1046 lpcf->nFontType |= ITALIC_FONTTYPE;
1047 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
1048 lpcf->nFontType |= BOLD_FONTTYPE;
1050 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1051 if (i!=CB_ERR)
1052 lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
1053 else
1054 lpxx->lfHeight=0;
1055 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
1056 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
1057 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
1058 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
1059 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
1060 lpxx->lfQuality=DEFAULT_QUALITY;
1061 lpcf->iPointSize= -10*lpxx->lfHeight;
1063 hFont=CreateFontIndirectA(lpxx);
1064 if (hFont)
1066 HFONT oldFont=SendDlgItemMessageA(hDlg, stc6,
1067 WM_GETFONT, 0, 0);
1068 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,hFont,TRUE);
1069 DeleteObject(oldFont);
1072 break;
1074 case cmb4:i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
1075 if (i!=CB_ERR)
1077 lpcf->rgbColors=textcolors[i];
1078 InvalidateRect( GetDlgItem(hDlg,stc6), NULL, 0 );
1080 break;
1082 case psh15:i=RegisterWindowMessageA( HELPMSGSTRINGA );
1083 if (lpcf->hwndOwner)
1084 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
1085 /* if (CFn_HookCallChk(lpcf))
1086 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
1087 break;
1089 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1090 ( (lpcf->Flags & CF_LIMITSIZE) &&
1091 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
1092 (-lpxx->lfHeight <= lpcf->nSizeMax)))
1093 EndDialog(hDlg, TRUE);
1094 else
1096 char buffer[80];
1097 sprintf(buffer,"Select a font size between %d and %d points.",
1098 lpcf->nSizeMin,lpcf->nSizeMax);
1099 MessageBoxA(hDlg, buffer, NULL, MB_OK);
1101 return(TRUE);
1102 case IDCANCEL:EndDialog(hDlg, FALSE);
1103 return(TRUE);
1105 return(FALSE);
1108 static LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1110 DeleteObject(SendDlgItemMessageA(hwnd, stc6, WM_GETFONT, 0, 0));
1111 return TRUE;
1115 /***********************************************************************
1116 * FormatCharDlgProc (COMMDLG.16)
1117 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
1118 2. some CF_.. flags are not supported
1119 3. some TType extensions
1121 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
1122 LPARAM lParam)
1124 LPCHOOSEFONT16 lpcf;
1125 LPCHOOSEFONTA lpcf32a;
1126 LRESULT res=0;
1127 if (message!=WM_INITDIALOG)
1129 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
1130 if (!lpcf)
1131 return FALSE;
1132 if (CFn_HookCallChk(lpcf))
1133 res=CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg,message,wParam,lParam);
1134 if (res)
1135 return res;
1137 else
1139 lpcf=(LPCHOOSEFONT16)lParam;
1140 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
1141 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
1143 TRACE("CFn_WMInitDialog returned FALSE\n");
1144 return FALSE;
1146 if (CFn_HookCallChk(lpcf))
1147 return CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1149 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
1150 switch (message)
1152 case WM_MEASUREITEM:
1154 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
1155 MEASUREITEMSTRUCT mis;
1156 mis.CtlType = mis16->CtlType;
1157 mis.CtlID = mis16->CtlID;
1158 mis.itemID = mis16->itemID;
1159 mis.itemWidth = mis16->itemWidth;
1160 mis.itemHeight = mis16->itemHeight;
1161 mis.itemData = mis16->itemData;
1162 res = CFn_WMMeasureItem(hDlg, wParam, (LPARAM)&mis);
1163 mis16->itemWidth = (UINT16)mis.itemWidth;
1164 mis16->itemHeight = (UINT16)mis.itemHeight;
1166 break;
1167 case WM_DRAWITEM:
1169 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
1170 DRAWITEMSTRUCT dis;
1171 dis.CtlType = dis16->CtlType;
1172 dis.CtlID = dis16->CtlID;
1173 dis.itemID = dis16->itemID;
1174 dis.itemAction = dis16->itemAction;
1175 dis.itemState = dis16->itemState;
1176 dis.hwndItem = dis16->hwndItem;
1177 dis.hDC = dis16->hDC;
1178 dis.itemData = dis16->itemData;
1179 CONV_RECT16TO32( &dis16->rcItem, &dis.rcItem );
1180 res = CFn_WMDrawItem(hDlg, wParam, (LPARAM)&dis);
1182 break;
1183 case WM_CTLCOLOR:
1184 if (HIWORD(lParam) == CTLCOLOR_STATIC)
1185 res=CFn_WMCtlColorStatic(hDlg, (HDC)wParam, (HWND)LOWORD(lParam), lpcf32a);
1186 break;
1187 case WM_COMMAND:
1188 res=CFn_WMCommand(hDlg, MAKEWPARAM( wParam, HIWORD(lParam) ), LOWORD(lParam), lpcf32a);
1189 break;
1190 case WM_DESTROY:
1191 res=CFn_WMDestroy(hDlg, wParam, lParam);
1192 break;
1193 case WM_CHOOSEFONT_GETLOGFONT:
1194 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1195 FIXME("current logfont back to caller\n");
1196 break;
1198 return res;
1201 /***********************************************************************
1202 * FormatCharDlgProcA [internal]
1204 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1205 LPARAM lParam)
1207 LPCHOOSEFONTA lpcf;
1208 LRESULT res=FALSE;
1209 if (uMsg!=WM_INITDIALOG)
1211 lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);
1212 if (!lpcf)
1213 return FALSE;
1214 if (CFn_HookCallChk32(lpcf))
1215 res=CallWindowProcA((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1216 if (res)
1217 return res;
1219 else
1221 lpcf=(LPCHOOSEFONTA)lParam;
1222 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
1224 TRACE("CFn_WMInitDialog returned FALSE\n");
1225 return FALSE;
1227 if (CFn_HookCallChk32(lpcf))
1228 return CallWindowProcA((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1230 switch (uMsg)
1232 case WM_MEASUREITEM:
1233 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1234 case WM_DRAWITEM:
1235 return CFn_WMDrawItem(hDlg, wParam, lParam);
1236 case WM_CTLCOLORSTATIC:
1237 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
1238 case WM_COMMAND:
1239 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1240 case WM_DESTROY:
1241 return CFn_WMDestroy(hDlg, wParam, lParam);
1242 case WM_CHOOSEFONT_GETLOGFONT:
1243 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1244 lParam);
1245 FIXME("current logfont back to caller\n");
1246 break;
1248 return res;
1251 /***********************************************************************
1252 * FormatCharDlgProcW [internal]
1254 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1255 LPARAM lParam)
1257 LPCHOOSEFONTW lpcf32w;
1258 LPCHOOSEFONTA lpcf32a;
1259 LRESULT res=FALSE;
1260 if (uMsg!=WM_INITDIALOG)
1262 lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);
1263 if (!lpcf32w)
1264 return FALSE;
1265 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1266 res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
1267 if (res)
1268 return res;
1270 else
1272 lpcf32w=(LPCHOOSEFONTW)lParam;
1273 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1274 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
1276 TRACE("CFn_WMInitDialog returned FALSE\n");
1277 return FALSE;
1279 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1280 return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1282 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1283 switch (uMsg)
1285 case WM_MEASUREITEM:
1286 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1287 case WM_DRAWITEM:
1288 return CFn_WMDrawItem(hDlg, wParam, lParam);
1289 case WM_CTLCOLORSTATIC:
1290 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
1291 case WM_COMMAND:
1292 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
1293 case WM_DESTROY:
1294 return CFn_WMDestroy(hDlg, wParam, lParam);
1295 case WM_CHOOSEFONT_GETLOGFONT:
1296 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1297 lParam);
1298 FIXME("current logfont back to caller\n");
1299 break;
1301 return res;