2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
23 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(commdlg);
32 static HBITMAP16 hBitmapTT = 0;
37 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONTA chf32a)
39 chf32a->lStructSize=sizeof(CHOOSEFONTA);
40 chf32a->hwndOwner=chf16->hwndOwner;
41 chf32a->hDC=chf16->hDC;
42 chf32a->iPointSize=chf16->iPointSize;
43 chf32a->Flags=chf16->Flags;
44 chf32a->rgbColors=chf16->rgbColors;
45 chf32a->lCustData=chf16->lCustData;
46 chf32a->lpfnHook=NULL;
47 chf32a->lpTemplateName=PTR_SEG_TO_LIN(chf16->lpTemplateName);
48 chf32a->hInstance=chf16->hInstance;
49 chf32a->lpszStyle=PTR_SEG_TO_LIN(chf16->lpszStyle);
50 chf32a->nFontType=chf16->nFontType;
51 chf32a->nSizeMax=chf16->nSizeMax;
52 chf32a->nSizeMin=chf16->nSizeMin;
53 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16->lpLogFont), chf32a->lpLogFont);
57 /***********************************************************************
58 * ChooseFont16 (COMMDLG.15)
60 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
63 HANDLE16 hDlgTmpl = 0;
64 BOOL16 bRet = FALSE, win32Format = FALSE;
69 SEGPTR lpTemplateName;
71 cf32a.lpLogFont=&lf32a;
72 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
74 TRACE("ChooseFont\n");
75 if (!lpChFont) return FALSE;
77 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
79 if (!(template = LockResource16( lpChFont->hInstance )))
81 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
85 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
88 if (!(hResInfo = FindResource16( lpChFont->hInstance,
89 lpChFont->lpTemplateName,
92 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
95 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
96 !(template = LockResource16( hDlgTmpl )))
98 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
105 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
107 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
110 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
111 !(template = LockResource( hDlgTmpl )))
113 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
119 hInst = GetWindowLongA( lpChFont->hwndOwner, GWL_HINSTANCE );
121 /* lpTemplateName is not used in the dialog */
122 lpTemplateName=lpChFont->lpTemplateName;
123 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
125 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
127 (DLGPROC16)FormatCharDlgProcA,
128 (DWORD)lpChFont, WIN_PROC_32A );
129 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
130 if (hDlgTmpl) FreeResource16( hDlgTmpl );
131 lpChFont->lpTemplateName=lpTemplateName;
132 FONT_LogFont32ATo16(cf32a.lpLogFont,
133 (LPLOGFONT16)(PTR_SEG_TO_LIN(lpChFont->lpLogFont)));
138 /***********************************************************************
139 * ChooseFontA (COMDLG32.3)
141 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
145 HINSTANCE hInst=GetWindowLongA( lpChFont->hwndOwner, GWL_HINSTANCE );
147 HANDLE hResInfo, hDlgTmpl;
149 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
151 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
154 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
155 !(template = LockResource( hDlgTmpl )))
157 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
161 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
162 CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
163 hwndDialog = DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
164 (DLGPROC16)FormatCharDlgProcA, (LPARAM)lpChFont, WIN_PROC_32A );
165 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
169 /***********************************************************************
170 * ChooseFontW (COMDLG32.4)
172 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
176 HINSTANCE hInst=GetWindowLongA( lpChFont->hwndOwner, GWL_HINSTANCE );
180 HANDLE hResInfo, hDlgTmpl;
182 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
184 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
187 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
188 !(template = LockResource( hDlgTmpl )))
190 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
194 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
195 CF_ENABLETEMPLATEHANDLE)) FIXME(": unimplemented flag (ignored)\n");
196 memcpy(&cf32a, lpChFont, sizeof(cf32a));
197 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
198 lstrcpynWtoA(lf32a.lfFaceName, lpChFont->lpLogFont->lfFaceName, LF_FACESIZE);
199 cf32a.lpLogFont=&lf32a;
200 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
201 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
202 hwndDialog=DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
203 (DLGPROC16)FormatCharDlgProcW, (LPARAM)lpChFont, WIN_PROC_32W );
204 if (hwndDialog)bRet=DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
205 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
206 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
207 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
208 lstrcpynAtoW(lpChFont->lpLogFont->lfFaceName, lf32a.lfFaceName, LF_FACESIZE);
213 #define TEXT_EXTRAS 4
214 #define TEXT_COLORS 16
216 static const COLORREF textcolors[TEXT_COLORS]=
218 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
219 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
220 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
221 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
224 /***********************************************************************
225 * CFn_HookCallChk [internal]
227 static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
230 if(lpcf->Flags & CF_ENABLEHOOK)
236 /***********************************************************************
237 * CFn_HookCallChk32 [internal]
239 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
242 if(lpcf->Flags & CF_ENABLEHOOK)
249 /*************************************************************************
250 * AddFontFamily [internal]
252 static INT AddFontFamily(LPLOGFONTA lplf, UINT nFontType,
253 LPCHOOSEFONTA lpcf, HWND hwnd)
258 TRACE("font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
260 if (lpcf->Flags & CF_FIXEDPITCHONLY)
261 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
263 if (lpcf->Flags & CF_ANSIONLY)
264 if (lplf->lfCharSet != ANSI_CHARSET)
266 if (lpcf->Flags & CF_TTONLY)
267 if (!(nFontType & TRUETYPE_FONTTYPE))
270 i=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
273 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
274 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
275 return 1 ; /* store some important font information */
285 LPCHOOSEFONTA lpcf32a;
286 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
288 /*************************************************************************
289 * FontFamilyEnumProc32 [internal]
291 static INT WINAPI FontFamilyEnumProc(LPENUMLOGFONTA lpEnumLogFont,
292 LPNEWTEXTMETRICA metrics, UINT nFontType, LPARAM lParam)
295 e=(LPCFn_ENUMSTRUCT)lParam;
296 return AddFontFamily(&lpEnumLogFont->elfLogFont, nFontType, e->lpcf32a, e->hWnd1);
299 /***********************************************************************
300 * FontFamilyEnumProc16 (COMMDLG.19)
302 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
303 UINT16 nFontType, LPARAM lParam )
305 HWND16 hwnd=LOWORD(lParam);
306 HWND16 hDlg=GetParent16(hwnd);
307 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
308 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
310 FONT_LogFont16To32A(lplf, &lf32a);
311 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
315 /*************************************************************************
316 * SetFontStylesToCombo2 [internal]
318 * Fill font style information into combobox (without using font.c directly)
320 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, LPLOGFONTA lplf)
327 static struct FONTSTYLE fontstyles[FSTYLES]={
328 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
329 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
334 for (i=0;i<FSTYLES;i++)
336 lplf->lfItalic=fontstyles[i].italic;
337 lplf->lfWeight=fontstyles[i].weight;
338 hf=CreateFontIndirectA(lplf);
339 hf=SelectObject(hdc,hf);
340 GetTextMetrics16(hdc,&tm);
341 hf=SelectObject(hdc,hf);
344 if (tm.tmWeight==fontstyles[i].weight &&
345 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
347 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
348 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
350 if (j==CB_ERR) return 1;
351 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
352 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
353 if (j==CB_ERR) return 1;
359 /*************************************************************************
360 * AddFontSizeToCombo3 [internal]
362 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
367 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
368 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
370 sprintf(buffer, "%2d", h);
371 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
374 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
375 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
376 if (j==CB_ERR) return 1;
382 /*************************************************************************
383 * SetFontSizesToCombo3 [internal]
385 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
387 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
390 for (i=0; sizes[i]; i++)
391 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
395 /***********************************************************************
396 * AddFontStyle [internal]
398 static INT AddFontStyle(LPLOGFONTA lplf, UINT nFontType,
399 LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
403 TRACE("(nFontType=%d)\n",nFontType);
404 TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
405 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
406 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
407 lplf->lfEscapement,lplf->lfOrientation,
408 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
409 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
410 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
411 if (nFontType & RASTER_FONTTYPE)
413 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
414 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
416 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
418 HDC hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
419 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
420 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
429 /***********************************************************************
430 * FontStyleEnumProc16 (COMMDLG.18)
432 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
433 UINT16 nFontType, LPARAM lParam )
435 HWND16 hcmb2=LOWORD(lParam);
436 HWND16 hcmb3=HIWORD(lParam);
437 HWND16 hDlg=GetParent16(hcmb3);
438 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
439 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
441 FONT_LogFont16To32A(lplf, &lf32a);
442 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
446 /***********************************************************************
447 * FontStyleEnumProc32 [internal]
449 static INT WINAPI FontStyleEnumProc( LPENUMLOGFONTA lpFont,
450 LPNEWTEXTMETRICA metrics, UINT nFontType, LPARAM lParam )
452 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
455 HWND hDlg=GetParent(hcmb3);
456 return AddFontStyle(&lpFont->elfLogFont, nFontType, s->lpcf32a, hcmb2,
460 /***********************************************************************
461 * CFn_WMInitDialog [internal]
463 static LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
470 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
472 SetWindowLongA(hDlg, DWL_USER, lParam);
473 lpxx=lpcf->lpLogFont;
474 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
476 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
478 ERR("structure size failure !!!\n");
483 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
485 /* This font will be deleted by WM_COMMAND */
486 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,
487 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
489 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
490 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
491 if (!(lpcf->Flags & CF_APPLY))
492 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
493 if (lpcf->Flags & CF_EFFECTS)
495 for (res=1,i=0;res && i<TEXT_COLORS;i++)
497 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
499 strcpy( name, "[color name]" );
500 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
501 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
502 /* look for a fitting value in color combobox */
503 if (textcolors[j]==lpcf->rgbColors)
504 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
509 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
510 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
511 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
512 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
513 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
515 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
519 s.hWnd1=GetDlgItem(hDlg,cmb1);
521 if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s))
522 TRACE("EnumFontFamilies returns 0\n");
523 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
525 /* look for fitting font name in combobox1 */
526 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
529 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
530 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
531 GetDlgItem(hDlg,cmb1));
533 /* look for fitting font style in combobox2 */
534 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
535 for (i=0;i<TEXT_EXTRAS;i++)
537 if (l==SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0))
538 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
541 /* look for fitting font size in combobox3 */
542 j=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
545 if (lpxx->lfHeight==(int)SendDlgItemMessageA(hDlg,cmb3, CB_GETITEMDATA,i,0))
546 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
552 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
553 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
554 GetDlgItem(hDlg,cmb1));
556 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
558 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
561 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
562 SendMessageA(hDlg,WM_COMMAND,cmb2,
563 MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
569 WARN("HDC failure !!!\n");
574 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
581 /***********************************************************************
582 * CFn_WMMeasureItem [internal]
584 static LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
587 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
589 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
590 GetObjectA( hBitmapTT, sizeof(bm), &bm );
591 lpmi->itemHeight=bm.bmHeight;
592 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
597 /***********************************************************************
598 * CFn_WMDrawItem [internal]
600 static LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
605 COLORREF cr, oldText=0, oldBk=0;
610 HBITMAP hBitmap; /* for later TT usage */
612 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
614 if (lpdi->itemID == 0xFFFF) /* got no items */
615 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
618 if (lpdi->CtlType == ODT_COMBOBOX)
620 if (lpdi->itemState ==ODS_SELECTED)
622 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
623 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
624 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
627 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
628 SelectObject(lpdi->hDC, hBrush);
630 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
633 return TRUE; /* this should never happen */
638 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
639 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
641 GetObjectA( hBitmapTT, sizeof(bm), &bm );
642 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
643 lpdi->rcItem.top, buffer, lstrlenA(buffer));
645 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
646 /* FIXME: draw bitmap if truetype usage */
647 if (nFontType&TRUETYPE_FONTTYPE)
649 hMemDC = CreateCompatibleDC(lpdi->hDC);
650 hBitmap = SelectObject(hMemDC, hBitmapTT);
651 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
652 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
653 SelectObject(hMemDC, hBitmap);
659 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
660 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
662 TextOutA(lpdi->hDC, lpdi->rcItem.left,
663 lpdi->rcItem.top, buffer, lstrlenA(buffer));
666 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
667 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
669 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
670 lpdi->rcItem.top, buffer, lstrlenA(buffer));
671 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
672 hBrush = CreateSolidBrush(cr);
675 hBrush = SelectObject (lpdi->hDC, hBrush) ;
676 rect.right=rect.left+25;
680 Rectangle( lpdi->hDC, rect.left, rect.top,
681 rect.right, rect.bottom );
682 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
688 default: return TRUE; /* this should never happen */
690 if (lpdi->itemState == ODS_SELECTED)
692 SetTextColor(lpdi->hDC, oldText);
693 SetBkColor(lpdi->hDC, oldBk);
699 /***********************************************************************
700 * CFn_WMCtlColor [internal]
702 static LRESULT CFn_WMCtlColorStatic(HWND hDlg, WPARAM wParam, LPARAM lParam,
705 if (lpcf->Flags & CF_EFFECTS)
706 if (GetDlgCtrlID(lParam)==stc6)
708 SetTextColor((HDC)wParam, lpcf->rgbColors);
709 return GetStockObject(WHITE_BRUSH);
714 /***********************************************************************
715 * CFn_WMCommand [internal]
717 static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
724 LPLOGFONTA lpxx=lpcf->lpLogFont;
726 TRACE("WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
727 switch (LOWORD(wParam))
729 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
731 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
734 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
735 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
736 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
739 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
742 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
744 TRACE("WM_COMMAND/cmb1 =>%s\n",str);
745 s.hWnd1=GetDlgItem(hDlg, cmb2);
746 s.hWnd2=GetDlgItem(hDlg, cmb3);
748 EnumFontFamiliesA(hdc, str, FontStyleEnumProc, (LPARAM)&s);
751 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
756 WARN("HDC failure !!!\n");
764 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
767 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
768 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
770 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
773 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
775 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
777 lpcf->nFontType = LOWORD(l);
778 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
779 /* same value reported to the EnumFonts
780 call back with the extra FONTTYPE_... bits added */
781 lpxx->lfPitchAndFamily=j&0xff;
782 lpxx->lfCharSet=j>>8;
784 strcpy(lpxx->lfFaceName,str);
785 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
788 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
789 if (0!=(lpxx->lfItalic=HIWORD(l)))
790 lpcf->nFontType |= ITALIC_FONTTYPE;
791 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
792 lpcf->nFontType |= BOLD_FONTTYPE;
794 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
796 lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
799 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
800 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
801 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
802 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
803 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
804 lpxx->lfQuality=DEFAULT_QUALITY;
805 lpcf->iPointSize= -10*lpxx->lfHeight;
807 hFont=CreateFontIndirectA(lpxx);
810 HFONT oldFont=SendDlgItemMessageA(hDlg, stc6,
812 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,hFont,TRUE);
813 DeleteObject(oldFont);
818 case cmb4:i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
821 lpcf->rgbColors=textcolors[i];
822 InvalidateRect( GetDlgItem(hDlg,stc6), NULL, 0 );
826 case psh15:i=RegisterWindowMessageA( HELPMSGSTRING );
828 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
829 /* if (CFn_HookCallChk(lpcf))
830 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
833 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
834 ( (lpcf->Flags & CF_LIMITSIZE) &&
835 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
836 (-lpxx->lfHeight <= lpcf->nSizeMax)))
837 EndDialog(hDlg, TRUE);
841 sprintf(buffer,"Select a font size between %d and %d points.",
842 lpcf->nSizeMin,lpcf->nSizeMax);
843 MessageBoxA(hDlg, buffer, NULL, MB_OK);
846 case IDCANCEL:EndDialog(hDlg, FALSE);
852 static LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
854 DeleteObject(SendDlgItemMessageA(hwnd, stc6, WM_GETFONT, 0, 0));
859 /***********************************************************************
860 * FormatCharDlgProc16 (COMMDLG.16)
861 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
862 2. some CF_.. flags are not supported
863 3. some TType extensions
865 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
869 LPCHOOSEFONTA lpcf32a;
873 if (message!=WM_INITDIALOG)
875 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
878 if (CFn_HookCallChk(lpcf))
879 res=CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg,message,wParam,lParam);
885 lpcf=(LPCHOOSEFONT16)lParam;
886 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
887 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
889 TRACE("CFn_WMInitDialog returned FALSE\n");
892 if (CFn_HookCallChk(lpcf))
893 return CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
895 WINPROC_MapMsg16To32A(message, wParam, &uMsg32, &wParam32, &lParam);
896 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
900 res=CFn_WMMeasureItem(hDlg, wParam32, lParam);
903 res=CFn_WMDrawItem(hDlg, wParam32, lParam);
905 case WM_CTLCOLORSTATIC:
906 res=CFn_WMCtlColorStatic(hDlg, wParam32, lParam, lpcf32a);
909 res=CFn_WMCommand(hDlg, wParam32, lParam, lpcf32a);
912 res=CFn_WMDestroy(hDlg, wParam32, lParam);
914 case WM_CHOOSEFONT_GETLOGFONT:
915 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
917 FIXME("current logfont back to caller\n");
920 WINPROC_UnmapMsg16To32A(hDlg,uMsg32, wParam32, lParam, res);
924 /***********************************************************************
925 * FormatCharDlgProcA [internal]
927 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
932 if (uMsg!=WM_INITDIALOG)
934 lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);
937 if (CFn_HookCallChk32(lpcf))
938 res=CallWindowProcA((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
944 lpcf=(LPCHOOSEFONTA)lParam;
945 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
947 TRACE("CFn_WMInitDialog returned FALSE\n");
950 if (CFn_HookCallChk32(lpcf))
951 return CallWindowProcA((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
956 return CFn_WMMeasureItem(hDlg, wParam, lParam);
958 return CFn_WMDrawItem(hDlg, wParam, lParam);
959 case WM_CTLCOLORSTATIC:
960 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
962 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
964 return CFn_WMDestroy(hDlg, wParam, lParam);
965 case WM_CHOOSEFONT_GETLOGFONT:
966 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
968 FIXME("current logfont back to caller\n");
974 /***********************************************************************
975 * FormatCharDlgProcW [internal]
977 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
980 LPCHOOSEFONTW lpcf32w;
981 LPCHOOSEFONTA lpcf32a;
983 if (uMsg!=WM_INITDIALOG)
985 lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);
988 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
989 res=CallWindowProcW((WNDPROC)lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
995 lpcf32w=(LPCHOOSEFONTW)lParam;
996 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
997 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
999 TRACE("CFn_WMInitDialog returned FALSE\n");
1002 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1003 return CallWindowProcW((WNDPROC)lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1005 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1008 case WM_MEASUREITEM:
1009 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1011 return CFn_WMDrawItem(hDlg, wParam, lParam);
1012 case WM_CTLCOLORSTATIC:
1013 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
1015 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
1017 return CFn_WMDestroy(hDlg, wParam, lParam);
1018 case WM_CHOOSEFONT_GETLOGFONT:
1019 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1021 FIXME("current logfont back to caller\n");