2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
16 #include "wine/winbase16.h"
17 #include "wine/winuser16.h"
21 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(commdlg);
28 static HBITMAP16 hBitmapTT = 0;
31 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
33 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
35 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
38 static void FONT_LogFont16To32A( const LPLOGFONT16 font16, LPLOGFONTA font32 )
40 font32->lfHeight = font16->lfHeight;
41 font32->lfWidth = font16->lfWidth;
42 font32->lfEscapement = font16->lfEscapement;
43 font32->lfOrientation = font16->lfOrientation;
44 font32->lfWeight = font16->lfWeight;
45 font32->lfItalic = font16->lfItalic;
46 font32->lfUnderline = font16->lfUnderline;
47 font32->lfStrikeOut = font16->lfStrikeOut;
48 font32->lfCharSet = font16->lfCharSet;
49 font32->lfOutPrecision = font16->lfOutPrecision;
50 font32->lfClipPrecision = font16->lfClipPrecision;
51 font32->lfQuality = font16->lfQuality;
52 font32->lfPitchAndFamily = font16->lfPitchAndFamily;
53 lstrcpynA( font32->lfFaceName, font16->lfFaceName, LF_FACESIZE );
56 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONTA chf32a)
58 chf32a->lStructSize=sizeof(CHOOSEFONTA);
59 chf32a->hwndOwner=chf16->hwndOwner;
60 chf32a->hDC=chf16->hDC;
61 chf32a->iPointSize=chf16->iPointSize;
62 chf32a->Flags=chf16->Flags;
63 chf32a->rgbColors=chf16->rgbColors;
64 chf32a->lCustData=chf16->lCustData;
65 chf32a->lpfnHook=NULL;
66 chf32a->lpTemplateName=MapSL(chf16->lpTemplateName);
67 chf32a->hInstance=chf16->hInstance;
68 chf32a->lpszStyle=MapSL(chf16->lpszStyle);
69 chf32a->nFontType=chf16->nFontType;
70 chf32a->nSizeMax=chf16->nSizeMax;
71 chf32a->nSizeMin=chf16->nSizeMin;
72 FONT_LogFont16To32A(MapSL(chf16->lpLogFont), chf32a->lpLogFont);
79 #define XX(x) { x, #x },
85 XX(CF_ENABLETEMPLATEHANDLE)
86 XX(CF_INITTOLOGFONTSTRUCT)
110 _dump_cf_flags(DWORD cflags) {
113 for (i=0;cfflags[i].name;i++)
114 if (cfflags[i].mask & cflags)
115 MESSAGE("%s|",cfflags[i].name);
120 /***********************************************************************
121 * ChooseFont16 (COMMDLG.15)
123 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
126 HANDLE16 hDlgTmpl16 = 0, hResource16 = 0;
127 HGLOBAL16 hGlobal16 = 0;
134 SEGPTR lpTemplateName;
136 cf32a.lpLogFont=&lf32a;
137 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
139 TRACE("ChooseFont\n");
140 if (!lpChFont) return FALSE;
142 if (TRACE_ON(commdlg))
143 _dump_cf_flags(lpChFont->Flags);
145 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
147 if (!(template = LockResource16( lpChFont->hInstance )))
149 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
153 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
156 if (!(hResInfo = FindResource16( lpChFont->hInstance,
157 MapSL(lpChFont->lpTemplateName),
160 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
163 if (!(hDlgTmpl16 = LoadResource16( lpChFont->hInstance, hResInfo )) ||
164 !(template = LockResource16( hDlgTmpl16 )))
166 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
172 HANDLE hResInfo, hDlgTmpl32;
175 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
177 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
180 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo)) ||
181 !(template32 = LockResource(hDlgTmpl32)))
183 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
186 size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo);
187 hGlobal16 = GlobalAlloc16(0, size);
190 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
191 ERR("alloc failure for %ld bytes\n", size);
194 template = GlobalLock16(hGlobal16);
197 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
198 ERR("global lock failure for %x handle\n", hGlobal16);
199 GlobalFree16(hGlobal16);
202 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
203 hDlgTmpl16 = hGlobal16;
207 /* lpTemplateName is not used in the dialog */
208 lpTemplateName=lpChFont->lpTemplateName;
209 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
211 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 16);
212 hInst = GetWindowLongA(lpChFont->hwndOwner, GWL_HINSTANCE);
213 bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChFont->hwndOwner,
214 (DLGPROC16) ptr, (DWORD)lpChFont);
215 if (hResource16) FreeResource16(hDlgTmpl16);
218 GlobalUnlock16(hGlobal16);
219 GlobalFree16(hGlobal16);
221 lpChFont->lpTemplateName=lpTemplateName;
224 font16 = MapSL(lpChFont->lpLogFont);
225 font16->lfHeight = cf32a.lpLogFont->lfHeight;
226 font16->lfWidth = cf32a.lpLogFont->lfWidth;
227 font16->lfEscapement = cf32a.lpLogFont->lfEscapement;
228 font16->lfOrientation = cf32a.lpLogFont->lfOrientation;
229 font16->lfWeight = cf32a.lpLogFont->lfWeight;
230 font16->lfItalic = cf32a.lpLogFont->lfItalic;
231 font16->lfUnderline = cf32a.lpLogFont->lfUnderline;
232 font16->lfStrikeOut = cf32a.lpLogFont->lfStrikeOut;
233 font16->lfCharSet = cf32a.lpLogFont->lfCharSet;
234 font16->lfOutPrecision = cf32a.lpLogFont->lfOutPrecision;
235 font16->lfClipPrecision = cf32a.lpLogFont->lfClipPrecision;
236 font16->lfQuality = cf32a.lpLogFont->lfQuality;
237 font16->lfPitchAndFamily = cf32a.lpLogFont->lfPitchAndFamily;
238 lstrcpynA( font16->lfFaceName, cf32a.lpLogFont->lfFaceName, LF_FACESIZE );
243 /***********************************************************************
244 * ChooseFontA (COMDLG32.3)
246 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
249 HANDLE hResInfo, hDlgTmpl;
251 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
253 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
256 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
257 !(template = LockResource( hDlgTmpl )))
259 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
262 if (TRACE_ON(commdlg))
263 _dump_cf_flags(lpChFont->Flags);
265 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
266 CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
267 return DialogBoxIndirectParamA(COMMDLG_hInstance32, template,
268 lpChFont->hwndOwner, (DLGPROC)FormatCharDlgProcA, (LPARAM)lpChFont );
271 /***********************************************************************
272 * ChooseFontW (COMDLG32.4)
276 * The LOGFONT conversion functions will break if the structure ever
277 * grows beyond the lfFaceName element.
279 * The CHOOSEFONT conversion functions assume that both versions of
280 * lpLogFont and lpszStyle (if used) point to pre-allocated objects.
282 * The ASCII version of lpTemplateName is created by ChooseFontAtoW
283 * and freed by ChooseFontWtoA.
285 inline static VOID LogFontWtoA(const LOGFONTW *lfw, LOGFONTA *lfa)
287 memcpy(lfa, lfw, sizeof(LOGFONTA));
288 WideCharToMultiByte(CP_ACP, 0, lfw->lfFaceName, -1, lfa->lfFaceName,
289 LF_FACESIZE, NULL, NULL);
290 lfa->lfFaceName[LF_FACESIZE - 1] = '\0';
293 inline static VOID LogFontAtoW(const LOGFONTA *lfa, LOGFONTW *lfw)
295 memcpy(lfw, lfa, sizeof(LOGFONTA));
296 MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw->lfFaceName,
298 lfw->lfFaceName[LF_FACESIZE - 1] = 0;
301 static BOOL ChooseFontWtoA(const CHOOSEFONTW *cfw, CHOOSEFONTA *cfa)
303 LOGFONTA *lpLogFont = cfa->lpLogFont;
304 LPSTR lpszStyle = cfa->lpszStyle;
306 memcpy(cfa, cfw, sizeof(CHOOSEFONTA));
307 cfa->lpLogFont = lpLogFont;
308 cfa->lpszStyle = lpszStyle;
310 LogFontWtoA(cfw->lpLogFont, lpLogFont);
312 if (cfw->lpTemplateName != NULL)
314 cfa->lpTemplateName = HEAP_strdupWtoA(GetProcessHeap(), 0,
315 cfw->lpTemplateName);
316 if (cfa->lpTemplateName == NULL)
320 if ((cfw->Flags & CF_USESTYLE) != 0 && cfw->lpszStyle != NULL)
322 WideCharToMultiByte(CP_ACP, 0, cfw->lpszStyle, -1, cfa->lpszStyle,
323 LF_FACESIZE, NULL, NULL);
324 cfa->lpszStyle[LF_FACESIZE - 1] = '\0';
330 static VOID ChooseFontAtoW(const CHOOSEFONTA *cfa, CHOOSEFONTW *cfw)
332 LOGFONTW *lpLogFont = cfw->lpLogFont;
333 LPWSTR lpszStyle = cfw->lpszStyle;
334 LPCWSTR lpTemplateName = cfw->lpTemplateName;
336 memcpy(cfw, cfa, sizeof(CHOOSEFONTA));
337 cfw->lpLogFont = lpLogFont;
338 cfw->lpszStyle = lpszStyle;
339 cfw->lpTemplateName = lpTemplateName;
341 LogFontAtoW(cfa->lpLogFont, lpLogFont);
343 if (cfa->lpTemplateName != NULL)
344 HeapFree(GetProcessHeap(), 0, (LPSTR)(cfa->lpTemplateName));
346 if ((cfa->Flags & CF_USESTYLE) != 0 && cfa->lpszStyle != NULL)
348 MultiByteToWideChar(CP_ACP, 0, cfa->lpszStyle, -1, cfw->lpszStyle,
350 cfw->lpszStyle[LF_FACESIZE - 1] = 0;
354 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
358 CHAR style_a[LF_FACESIZE];
360 cf_a.lpLogFont = &lf_a;
361 cf_a.lpszStyle = style_a;
363 if (ChooseFontWtoA(lpChFont, &cf_a) == FALSE)
365 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
369 if (ChooseFontA(&cf_a) == FALSE)
371 if (cf_a.lpTemplateName != NULL)
372 HeapFree(GetProcessHeap(), 0, (LPSTR)(cf_a.lpTemplateName));
376 ChooseFontAtoW(&cf_a, lpChFont);
382 /***********************************************************************
383 * ChooseFontW (COMDLG32.4)
385 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
391 HANDLE hResInfo, hDlgTmpl;
393 if (TRACE_ON(commdlg))
394 _dump_cf_flags(lpChFont->Flags);
396 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
398 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
401 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
402 !(template = LockResource( hDlgTmpl )))
404 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
408 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
409 CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
410 memcpy(&cf32a, lpChFont, sizeof(cf32a));
411 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
413 WideCharToMultiByte( CP_ACP, 0, lpChFont->lpLogFont->lfFaceName, -1,
414 lf32a.lfFaceName, LF_FACESIZE, NULL, NULL );
415 lf32a.lfFaceName[LF_FACESIZE-1] = 0;
416 cf32a.lpLogFont=&lf32a;
417 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
418 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
419 bRet = DialogBoxIndirectParamW(COMMDLG_hInstance32, template,
420 lpChFont->hwndOwner, (DLGPROC)FormatCharDlgProcW, (LPARAM)lpChFont );
421 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
422 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
423 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
424 MultiByteToWideChar( CP_ACP, 0, lf32a.lfFaceName, -1,
425 lpChFont->lpLogFont->lfFaceName, LF_FACESIZE );
426 lpChFont->lpLogFont->lfFaceName[LF_FACESIZE-1] = 0;
431 #define TEXT_EXTRAS 4
432 #define TEXT_COLORS 16
434 static const COLORREF textcolors[TEXT_COLORS]=
436 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
437 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
438 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
439 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
442 /***********************************************************************
443 * CFn_HookCallChk [internal]
445 static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
448 if(lpcf->Flags & CF_ENABLEHOOK)
454 /***********************************************************************
455 * CFn_HookCallChk32 [internal]
457 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
460 if(lpcf->Flags & CF_ENABLEHOOK)
470 LPCHOOSEFONTA lpcf32a;
472 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
474 /*************************************************************************
475 * AddFontFamily [internal]
477 static INT AddFontFamily(const LOGFONTA *lplf, UINT nFontType,
478 LPCHOOSEFONTA lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
483 TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
485 if (lpcf->Flags & CF_FIXEDPITCHONLY)
486 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
488 if (lpcf->Flags & CF_ANSIONLY)
489 if (lplf->lfCharSet != ANSI_CHARSET)
491 if (lpcf->Flags & CF_TTONLY)
492 if (!(nFontType & TRUETYPE_FONTTYPE))
497 i=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
500 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
501 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
502 return 1 ; /* store some important font information */
508 /*************************************************************************
509 * FontFamilyEnumProc32 [internal]
511 static INT WINAPI FontFamilyEnumProc(const LOGFONTA *lpLogFont,
512 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam)
515 e=(LPCFn_ENUMSTRUCT)lParam;
516 return AddFontFamily(lpLogFont, dwFontType, e->lpcf32a, e->hWnd1, e);
519 /***********************************************************************
520 * FontFamilyEnumProc16 (COMMDLG.19)
522 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
523 UINT16 nFontType, LPARAM lParam )
525 HWND16 hwnd=LOWORD(lParam);
526 HWND hDlg=GetParent(hwnd);
527 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
528 LOGFONT16 *lplf = MapSL( logfont );
530 FONT_LogFont16To32A(lplf, &lf32a);
531 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
535 /*************************************************************************
536 * SetFontStylesToCombo2 [internal]
538 * Fill font style information into combobox (without using font.c directly)
540 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTA *lplf)
547 static struct FONTSTYLE fontstyles[FSTYLES]={
548 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
549 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
555 memcpy(&lf, lplf, sizeof(LOGFONTA));
557 for (i=0;i<FSTYLES;i++)
559 lf.lfItalic=fontstyles[i].italic;
560 lf.lfWeight=fontstyles[i].weight;
561 hf=CreateFontIndirectA(&lf);
562 hf=SelectObject(hdc,hf);
563 GetTextMetricsA(hdc,&tm);
564 hf=SelectObject(hdc,hf);
567 if (tm.tmWeight==fontstyles[i].weight &&
568 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
570 j=SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
571 if (j==CB_ERR) return 1;
572 j=SendMessageA(hwnd, CB_SETITEMDATA, j,
573 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
574 if (j==CB_ERR) return 1;
580 /*************************************************************************
581 * AddFontSizeToCombo3 [internal]
583 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
588 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
589 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
591 sprintf(buffer, "%2d", h);
592 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
595 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
596 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
597 if (j==CB_ERR) return 1;
603 /*************************************************************************
604 * SetFontSizesToCombo3 [internal]
606 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
608 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
611 for (i=0; sizes[i]; i++)
612 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
616 /***********************************************************************
617 * AddFontStyle [internal]
619 static INT AddFontStyle(const LOGFONTA *lplf, UINT nFontType,
620 LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
624 TRACE("(nFontType=%d)\n",nFontType);
625 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
626 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
627 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
628 lplf->lfEscapement,lplf->lfOrientation,
629 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
630 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
631 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
632 if (nFontType & RASTER_FONTTYPE)
634 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
635 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
637 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
639 HDC hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
640 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
641 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
650 /***********************************************************************
651 * FontStyleEnumProc16 (COMMDLG.18)
653 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
654 UINT16 nFontType, LPARAM lParam )
656 HWND16 hcmb2=LOWORD(lParam);
657 HWND16 hcmb3=HIWORD(lParam);
658 HWND hDlg=GetParent(hcmb3);
659 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
660 LOGFONT16 *lplf = MapSL(logfont);
662 FONT_LogFont16To32A(lplf, &lf32a);
663 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
667 /***********************************************************************
668 * FontStyleEnumProc32 [internal]
670 static INT WINAPI FontStyleEnumProc( const LOGFONTA *lpFont,
671 const TEXTMETRICA *metrics, DWORD dwFontType, LPARAM lParam )
673 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
676 HWND hDlg=GetParent(hcmb3);
677 return AddFontStyle(lpFont, dwFontType, s->lpcf32a, hcmb2,
681 /***********************************************************************
682 * CFn_WMInitDialog [internal]
684 static LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
691 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
693 SetWindowLongA(hDlg, DWL_USER, lParam);
694 lpxx=lpcf->lpLogFont;
695 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
697 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
699 ERR("structure size failure !!!\n");
704 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
706 /* This font will be deleted by WM_COMMAND */
707 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,
708 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
710 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
711 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
712 if (!(lpcf->Flags & CF_APPLY))
713 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
714 if (lpcf->Flags & CF_EFFECTS)
716 for (res=1,i=0;res && i<TEXT_COLORS;i++)
718 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
720 strcpy( name, "[color name]" );
721 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
722 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
723 /* look for a fitting value in color combobox */
724 if (textcolors[j]==lpcf->rgbColors)
725 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
730 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
731 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
732 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
733 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
734 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
736 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
740 s.hWnd1=GetDlgItem(hDlg,cmb1);
744 if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s)) {
745 TRACE("EnumFontFamilies returns 0\n");
749 if (lpcf->Flags & CF_FIXEDPITCHONLY) {
750 FIXME("No founds found with fixed pitch only, dropping flag.\n");
751 lpcf->Flags &= ~CF_FIXEDPITCHONLY;
754 if (lpcf->Flags & CF_TTONLY) {
755 FIXME("No founds found with truetype only, dropping flag.\n");
756 lpcf->Flags &= ~CF_TTONLY;
763 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
765 /* look for fitting font name in combobox1 */
766 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
769 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
770 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
771 GetDlgItem(hDlg,cmb1));
773 /* look for fitting font style in combobox2 */
774 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
775 for (i=0;i<TEXT_EXTRAS;i++)
777 if (l==SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0))
778 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
781 /* look for fitting font size in combobox3 */
782 j=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
785 if (lpxx->lfHeight==(int)SendDlgItemMessageA(hDlg,cmb3, CB_GETITEMDATA,i,0))
786 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
792 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
793 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
794 GetDlgItem(hDlg,cmb1));
796 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
798 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
801 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
802 SendMessageA(hDlg,WM_COMMAND,cmb2,
803 MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
809 WARN("HDC failure !!!\n");
814 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
821 /***********************************************************************
822 * CFn_WMMeasureItem [internal]
824 static LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
827 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
829 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
830 GetObjectA( hBitmapTT, sizeof(bm), &bm );
831 lpmi->itemHeight=bm.bmHeight;
832 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
837 /***********************************************************************
838 * CFn_WMDrawItem [internal]
840 static LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
845 COLORREF cr, oldText=0, oldBk=0;
850 HBITMAP hBitmap; /* for later TT usage */
852 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
854 if (lpdi->itemID == 0xFFFF) /* got no items */
855 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
858 if (lpdi->CtlType == ODT_COMBOBOX)
860 if (lpdi->itemState ==ODS_SELECTED)
862 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
863 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
864 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
867 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
868 SelectObject(lpdi->hDC, hBrush);
870 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
873 return TRUE; /* this should never happen */
878 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
879 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
881 GetObjectA( hBitmapTT, sizeof(bm), &bm );
882 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
883 lpdi->rcItem.top, buffer, strlen(buffer));
885 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
886 /* FIXME: draw bitmap if truetype usage */
887 if (nFontType&TRUETYPE_FONTTYPE)
889 hMemDC = CreateCompatibleDC(lpdi->hDC);
890 hBitmap = SelectObject(hMemDC, hBitmapTT);
891 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
892 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
893 SelectObject(hMemDC, hBitmap);
899 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
900 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
902 TextOutA(lpdi->hDC, lpdi->rcItem.left,
903 lpdi->rcItem.top, buffer, strlen(buffer));
906 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
907 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
909 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
910 lpdi->rcItem.top, buffer, strlen(buffer));
911 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
912 hBrush = CreateSolidBrush(cr);
915 hBrush = SelectObject (lpdi->hDC, hBrush) ;
916 rect.right=rect.left+25;
920 Rectangle( lpdi->hDC, rect.left, rect.top,
921 rect.right, rect.bottom );
922 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
928 default: return TRUE; /* this should never happen */
930 if (lpdi->itemState == ODS_SELECTED)
932 SetTextColor(lpdi->hDC, oldText);
933 SetBkColor(lpdi->hDC, oldBk);
939 /***********************************************************************
940 * CFn_WMCtlColor [internal]
942 static LRESULT CFn_WMCtlColorStatic(HWND hDlg, WPARAM wParam, LPARAM lParam,
945 if (lpcf->Flags & CF_EFFECTS)
946 if (GetDlgCtrlID(lParam)==stc6)
948 SetTextColor((HDC)wParam, lpcf->rgbColors);
949 return GetStockObject(WHITE_BRUSH);
954 /***********************************************************************
955 * CFn_WMCommand [internal]
957 static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
964 LPLOGFONTA lpxx=lpcf->lpLogFont;
966 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
967 switch (LOWORD(wParam))
969 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
971 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
974 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
975 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
976 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
979 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
982 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
984 TRACE("WM_COMMAND/cmb1 =>%s\n",str);
985 s.hWnd1=GetDlgItem(hDlg, cmb2);
986 s.hWnd2=GetDlgItem(hDlg, cmb3);
988 EnumFontFamiliesA(hdc, str, FontStyleEnumProc, (LPARAM)&s);
989 SendDlgItemMessageA(hDlg,cmb2, CB_SETCURSEL, 0, 0);
990 SendDlgItemMessageA(hDlg,cmb3, CB_SETCURSEL, 0, 0);
993 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
998 WARN("HDC failure !!!\n");
1006 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
1009 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
1010 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
1012 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
1015 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
1017 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
1019 lpcf->nFontType = LOWORD(l);
1020 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
1021 /* same value reported to the EnumFonts
1022 call back with the extra FONTTYPE_... bits added */
1023 lpxx->lfPitchAndFamily=j&0xff;
1024 lpxx->lfCharSet=j>>8;
1026 strcpy(lpxx->lfFaceName,str);
1027 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1030 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
1031 if (0!=(lpxx->lfItalic=HIWORD(l)))
1032 lpcf->nFontType |= ITALIC_FONTTYPE;
1033 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
1034 lpcf->nFontType |= BOLD_FONTTYPE;
1036 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1038 lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
1041 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
1042 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
1043 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
1044 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
1045 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
1046 lpxx->lfQuality=DEFAULT_QUALITY;
1047 lpcf->iPointSize= -10*lpxx->lfHeight;
1049 hFont=CreateFontIndirectA(lpxx);
1052 HFONT oldFont=SendDlgItemMessageA(hDlg, stc6,
1054 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,hFont,TRUE);
1055 DeleteObject(oldFont);
1060 case cmb4:i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
1063 lpcf->rgbColors=textcolors[i];
1064 InvalidateRect( GetDlgItem(hDlg,stc6), NULL, 0 );
1068 case psh15:i=RegisterWindowMessageA( HELPMSGSTRINGA );
1069 if (lpcf->hwndOwner)
1070 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
1071 /* if (CFn_HookCallChk(lpcf))
1072 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
1075 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1076 ( (lpcf->Flags & CF_LIMITSIZE) &&
1077 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
1078 (-lpxx->lfHeight <= lpcf->nSizeMax)))
1079 EndDialog(hDlg, TRUE);
1083 sprintf(buffer,"Select a font size between %d and %d points.",
1084 lpcf->nSizeMin,lpcf->nSizeMax);
1085 MessageBoxA(hDlg, buffer, NULL, MB_OK);
1088 case IDCANCEL:EndDialog(hDlg, FALSE);
1094 static LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1096 DeleteObject(SendDlgItemMessageA(hwnd, stc6, WM_GETFONT, 0, 0));
1101 /***********************************************************************
1102 * FormatCharDlgProc16 (COMMDLG.16)
1103 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
1104 2. some CF_.. flags are not supported
1105 3. some TType extensions
1107 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
1110 LPCHOOSEFONT16 lpcf;
1111 LPCHOOSEFONTA lpcf32a;
1113 if (message!=WM_INITDIALOG)
1115 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
1118 if (CFn_HookCallChk(lpcf))
1119 res=CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg,message,wParam,lParam);
1125 lpcf=(LPCHOOSEFONT16)lParam;
1126 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
1127 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
1129 TRACE("CFn_WMInitDialog returned FALSE\n");
1132 if (CFn_HookCallChk(lpcf))
1133 return CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1135 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
1138 case WM_MEASUREITEM:
1140 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
1141 MEASUREITEMSTRUCT mis;
1142 mis.CtlType = mis16->CtlType;
1143 mis.CtlID = mis16->CtlID;
1144 mis.itemID = mis16->itemID;
1145 mis.itemWidth = mis16->itemWidth;
1146 mis.itemHeight = mis16->itemHeight;
1147 mis.itemData = mis16->itemData;
1148 res = CFn_WMMeasureItem(hDlg, wParam, (LPARAM)&mis);
1149 mis16->itemWidth = (UINT16)mis.itemWidth;
1150 mis16->itemHeight = (UINT16)mis.itemHeight;
1155 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
1157 dis.CtlType = dis16->CtlType;
1158 dis.CtlID = dis16->CtlID;
1159 dis.itemID = dis16->itemID;
1160 dis.itemAction = dis16->itemAction;
1161 dis.itemState = dis16->itemState;
1162 dis.hwndItem = dis16->hwndItem;
1163 dis.hDC = dis16->hDC;
1164 dis.itemData = dis16->itemData;
1165 CONV_RECT16TO32( &dis16->rcItem, &dis.rcItem );
1166 res = CFn_WMDrawItem(hDlg, wParam, (LPARAM)&dis);
1170 if (HIWORD(lParam) == CTLCOLOR_STATIC)
1171 res=CFn_WMCtlColorStatic(hDlg, (HDC)wParam, (HWND)LOWORD(lParam), lpcf32a);
1174 res=CFn_WMCommand(hDlg, MAKEWPARAM( wParam, HIWORD(lParam) ), LOWORD(lParam), lpcf32a);
1177 res=CFn_WMDestroy(hDlg, wParam, lParam);
1179 case WM_CHOOSEFONT_GETLOGFONT:
1180 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1181 FIXME("current logfont back to caller\n");
1187 /***********************************************************************
1188 * FormatCharDlgProcA [internal]
1190 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1195 if (uMsg!=WM_INITDIALOG)
1197 lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);
1200 if (CFn_HookCallChk32(lpcf))
1201 res=CallWindowProcA((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1207 lpcf=(LPCHOOSEFONTA)lParam;
1208 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
1210 TRACE("CFn_WMInitDialog returned FALSE\n");
1213 if (CFn_HookCallChk32(lpcf))
1214 return CallWindowProcA((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1218 case WM_MEASUREITEM:
1219 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1221 return CFn_WMDrawItem(hDlg, wParam, lParam);
1222 case WM_CTLCOLORSTATIC:
1223 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
1225 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1227 return CFn_WMDestroy(hDlg, wParam, lParam);
1228 case WM_CHOOSEFONT_GETLOGFONT:
1229 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1231 FIXME("current logfont back to caller\n");
1237 /***********************************************************************
1238 * FormatCharDlgProcW [internal]
1240 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1243 LPCHOOSEFONTW lpcf32w;
1244 LPCHOOSEFONTA lpcf32a;
1246 if (uMsg!=WM_INITDIALOG)
1248 lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);
1251 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1252 res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
1258 lpcf32w=(LPCHOOSEFONTW)lParam;
1259 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1260 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
1262 TRACE("CFn_WMInitDialog returned FALSE\n");
1265 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1266 return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1268 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1271 case WM_MEASUREITEM:
1272 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1274 return CFn_WMDrawItem(hDlg, wParam, lParam);
1275 case WM_CTLCOLORSTATIC:
1276 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
1278 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
1280 return CFn_WMDestroy(hDlg, wParam, lParam);
1281 case WM_CHOOSEFONT_GETLOGFONT:
1282 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1284 FIXME("current logfont back to caller\n");