New debug scheme with explicit debug channels declaration.
[wine.git] / dlls / commdlg / fontdlg.c
blobc0f768d6a9a9eb46884a53a8b79f7d90aa03ed1c
1 /*
2 * COMMDLG - Font Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "winbase.h"
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
14 #include "win.h"
15 #include "heap.h"
16 #include "message.h"
17 #include "commdlg.h"
18 #include "resource.h"
19 #include "dialog.h"
20 #include "dlgs.h"
21 #include "module.h"
22 #include "debug.h"
23 #include "font.h"
24 #include "winproc.h"
25 #include "cderr.h"
27 DEFAULT_DEBUG_CHANNEL(commdlg)
29 static HBITMAP16 hBitmapTT = 0;
34 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONTA chf32a)
36 chf32a->lStructSize=sizeof(CHOOSEFONTA);
37 chf32a->hwndOwner=chf16->hwndOwner;
38 chf32a->hDC=chf16->hDC;
39 chf32a->iPointSize=chf16->iPointSize;
40 chf32a->Flags=chf16->Flags;
41 chf32a->rgbColors=chf16->rgbColors;
42 chf32a->lCustData=chf16->lCustData;
43 chf32a->lpfnHook=NULL;
44 chf32a->lpTemplateName=PTR_SEG_TO_LIN(chf16->lpTemplateName);
45 chf32a->hInstance=chf16->hInstance;
46 chf32a->lpszStyle=PTR_SEG_TO_LIN(chf16->lpszStyle);
47 chf32a->nFontType=chf16->nFontType;
48 chf32a->nSizeMax=chf16->nSizeMax;
49 chf32a->nSizeMin=chf16->nSizeMin;
50 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16->lpLogFont), chf32a->lpLogFont);
54 /***********************************************************************
55 * ChooseFont16 (COMMDLG.15)
57 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
59 HINSTANCE16 hInst;
60 HANDLE16 hDlgTmpl = 0;
61 BOOL16 bRet = FALSE, win32Format = FALSE;
62 LPCVOID template;
63 HWND hwndDialog;
64 CHOOSEFONTA cf32a;
65 LOGFONTA lf32a;
66 SEGPTR lpTemplateName;
68 cf32a.lpLogFont=&lf32a;
69 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
71 TRACE(commdlg,"ChooseFont\n");
72 if (!lpChFont) return FALSE;
74 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
76 if (!(template = LockResource16( lpChFont->hInstance )))
78 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
79 return FALSE;
82 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
84 HANDLE16 hResInfo;
85 if (!(hResInfo = FindResource16( lpChFont->hInstance,
86 lpChFont->lpTemplateName,
87 RT_DIALOG16)))
89 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
90 return FALSE;
92 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
93 !(template = LockResource16( hDlgTmpl )))
95 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
96 return FALSE;
99 else
101 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
102 win32Format = TRUE;
105 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
107 /* lpTemplateName is not used in the dialog */
108 lpTemplateName=lpChFont->lpTemplateName;
109 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
111 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
112 lpChFont->hwndOwner,
113 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
114 (DWORD)lpChFont, WIN_PROC_16 );
115 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
116 if (hDlgTmpl) FreeResource16( hDlgTmpl );
117 lpChFont->lpTemplateName=lpTemplateName;
118 FONT_LogFont32ATo16(cf32a.lpLogFont,
119 (LPLOGFONT16)(PTR_SEG_TO_LIN(lpChFont->lpLogFont)));
120 return bRet;
124 /***********************************************************************
125 * ChooseFont32A (COMDLG32.3)
127 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
129 BOOL bRet=FALSE;
130 HWND hwndDialog;
131 HINSTANCE hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
132 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
133 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
134 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
135 hwndDialog = DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
136 (DLGPROC16)FormatCharDlgProcA, (LPARAM)lpChFont, WIN_PROC_32A );
137 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
138 return bRet;
141 /***********************************************************************
142 * ChooseFont32W (COMDLG32.4)
144 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
146 BOOL bRet=FALSE;
147 HWND hwndDialog;
148 HINSTANCE hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
149 CHOOSEFONTA cf32a;
150 LOGFONTA lf32a;
151 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
152 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
153 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
154 memcpy(&cf32a, lpChFont, sizeof(cf32a));
155 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
156 lstrcpynWtoA(lf32a.lfFaceName, lpChFont->lpLogFont->lfFaceName, LF_FACESIZE);
157 cf32a.lpLogFont=&lf32a;
158 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
159 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
160 hwndDialog=DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
161 (DLGPROC16)FormatCharDlgProcW, (LPARAM)lpChFont, WIN_PROC_32W );
162 if (hwndDialog)bRet=DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
163 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
164 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
165 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
166 lstrcpynAtoW(lpChFont->lpLogFont->lfFaceName, lf32a.lfFaceName, LF_FACESIZE);
167 return bRet;
171 #define TEXT_EXTRAS 4
172 #define TEXT_COLORS 16
174 static const COLORREF textcolors[TEXT_COLORS]=
176 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
177 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
178 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
179 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
182 /***********************************************************************
183 * CFn_HookCallChk [internal]
185 static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
187 if (lpcf)
188 if(lpcf->Flags & CF_ENABLEHOOK)
189 if (lpcf->lpfnHook)
190 return TRUE;
191 return FALSE;
194 /***********************************************************************
195 * CFn_HookCallChk32 [internal]
197 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
199 if (lpcf)
200 if(lpcf->Flags & CF_ENABLEHOOK)
201 if (lpcf->lpfnHook)
202 return TRUE;
203 return FALSE;
207 /*************************************************************************
208 * AddFontFamily [internal]
210 static INT AddFontFamily(LPLOGFONTA lplf, UINT nFontType,
211 LPCHOOSEFONTA lpcf, HWND hwnd)
213 int i;
214 WORD w;
216 TRACE(commdlg,"font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
218 if (lpcf->Flags & CF_FIXEDPITCHONLY)
219 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
220 return 1;
221 if (lpcf->Flags & CF_ANSIONLY)
222 if (lplf->lfCharSet != ANSI_CHARSET)
223 return 1;
224 if (lpcf->Flags & CF_TTONLY)
225 if (!(nFontType & TRUETYPE_FONTTYPE))
226 return 1;
228 i=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
229 if (i!=CB_ERR)
231 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
232 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
233 return 1 ; /* store some important font information */
235 else
236 return 0;
239 typedef struct
241 HWND hWnd1;
242 HWND hWnd2;
243 LPCHOOSEFONTA lpcf32a;
244 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
246 /*************************************************************************
247 * FontFamilyEnumProc32 [internal]
249 INT WINAPI FontFamilyEnumProc(LPENUMLOGFONTA lpEnumLogFont,
250 LPNEWTEXTMETRICA metrics, UINT nFontType, LPARAM lParam)
252 LPCFn_ENUMSTRUCT e;
253 e=(LPCFn_ENUMSTRUCT)lParam;
254 return AddFontFamily(&lpEnumLogFont->elfLogFont, nFontType, e->lpcf32a, e->hWnd1);
257 /***********************************************************************
258 * FontFamilyEnumProc16 (COMMDLG.19)
260 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
261 UINT16 nFontType, LPARAM lParam )
263 HWND16 hwnd=LOWORD(lParam);
264 HWND16 hDlg=GetParent16(hwnd);
265 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
266 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
267 LOGFONTA lf32a;
268 FONT_LogFont16To32A(lplf, &lf32a);
269 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
270 hwnd);
273 /*************************************************************************
274 * SetFontStylesToCombo2 [internal]
276 * Fill font style information into combobox (without using font.c directly)
278 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, LPLOGFONTA lplf)
280 #define FSTYLES 4
281 struct FONTSTYLE
282 { int italic;
283 int weight;
284 char stname[20]; };
285 static struct FONTSTYLE fontstyles[FSTYLES]={
286 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
287 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
288 HFONT16 hf;
289 TEXTMETRIC16 tm;
290 int i,j;
292 for (i=0;i<FSTYLES;i++)
294 lplf->lfItalic=fontstyles[i].italic;
295 lplf->lfWeight=fontstyles[i].weight;
296 hf=CreateFontIndirectA(lplf);
297 hf=SelectObject(hdc,hf);
298 GetTextMetrics16(hdc,&tm);
299 hf=SelectObject(hdc,hf);
300 DeleteObject(hf);
302 if (tm.tmWeight==fontstyles[i].weight &&
303 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
305 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
306 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
307 SEGPTR_FREE(str);
308 if (j==CB_ERR) return 1;
309 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
310 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
311 if (j==CB_ERR) return 1;
314 return 0;
317 /*************************************************************************
318 * AddFontSizeToCombo3 [internal]
320 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
322 int j;
323 char buffer[20];
325 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
326 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
328 sprintf(buffer, "%2d", h);
329 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
330 if (j==CB_ERR)
332 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
333 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
334 if (j==CB_ERR) return 1;
337 return 0;
340 /*************************************************************************
341 * SetFontSizesToCombo3 [internal]
343 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
345 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
346 int i;
348 for (i=0; sizes[i]; i++)
349 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
350 return 0;
353 /***********************************************************************
354 * AddFontStyle [internal]
356 INT AddFontStyle(LPLOGFONTA lplf, UINT nFontType,
357 LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
359 int i;
361 TRACE(commdlg,"(nFontType=%d)\n",nFontType);
362 TRACE(commdlg," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
363 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
364 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
365 lplf->lfEscapement,lplf->lfOrientation,
366 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
367 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
368 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
369 if (nFontType & RASTER_FONTTYPE)
371 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
372 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
374 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
376 HDC hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
377 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
378 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
379 ReleaseDC(hDlg,hdc);
380 if (i)
381 return 0;
383 return 1 ;
387 /***********************************************************************
388 * FontStyleEnumProc16 (COMMDLG.18)
390 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
391 UINT16 nFontType, LPARAM lParam )
393 HWND16 hcmb2=LOWORD(lParam);
394 HWND16 hcmb3=HIWORD(lParam);
395 HWND16 hDlg=GetParent16(hcmb3);
396 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
397 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
398 LOGFONTA lf32a;
399 FONT_LogFont16To32A(lplf, &lf32a);
400 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
401 hcmb2, hcmb3, hDlg);
404 /***********************************************************************
405 * FontStyleEnumProc32 [internal]
407 INT WINAPI FontStyleEnumProc( LPENUMLOGFONTA lpFont,
408 LPNEWTEXTMETRICA metrics, UINT nFontType, LPARAM lParam )
410 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
411 HWND hcmb2=s->hWnd1;
412 HWND hcmb3=s->hWnd2;
413 HWND hDlg=GetParent(hcmb3);
414 return AddFontStyle(&lpFont->elfLogFont, nFontType, s->lpcf32a, hcmb2,
415 hcmb3, hDlg);
418 /***********************************************************************
419 * CFn_WMInitDialog [internal]
421 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
422 LPCHOOSEFONTA lpcf)
424 HDC hdc;
425 int i,j,res,init=0;
426 long l;
427 LPLOGFONTA lpxx;
428 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
430 SetWindowLongA(hDlg, DWL_USER, lParam);
431 lpxx=lpcf->lpLogFont;
432 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
434 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
436 ERR(commdlg,"structure size failure !!!\n");
437 EndDialog (hDlg, 0);
438 return FALSE;
440 if (!hBitmapTT)
441 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
443 /* This font will be deleted by WM_COMMAND */
444 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,
445 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
447 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
448 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
449 if (!(lpcf->Flags & CF_APPLY))
450 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
451 if (lpcf->Flags & CF_EFFECTS)
453 for (res=1,i=0;res && i<TEXT_COLORS;i++)
455 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
456 char name[20];
457 strcpy( name, "[color name]" );
458 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
459 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
460 /* look for a fitting value in color combobox */
461 if (textcolors[j]==lpcf->rgbColors)
462 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
465 else
467 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
468 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
469 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
470 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
471 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
473 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
474 if (hdc)
476 CFn_ENUMSTRUCT s;
477 s.hWnd1=GetDlgItem(hDlg,cmb1);
478 s.lpcf32a=lpcf;
479 if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s))
480 TRACE(commdlg,"EnumFontFamilies returns 0\n");
481 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
483 /* look for fitting font name in combobox1 */
484 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
485 if (j!=CB_ERR)
487 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
488 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
489 GetDlgItem(hDlg,cmb1));
490 init=1;
491 /* look for fitting font style in combobox2 */
492 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
493 for (i=0;i<TEXT_EXTRAS;i++)
495 if (l==SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0))
496 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
499 /* look for fitting font size in combobox3 */
500 j=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
501 for (i=0;i<j;i++)
503 if (lpxx->lfHeight==(int)SendDlgItemMessageA(hDlg,cmb3, CB_GETITEMDATA,i,0))
504 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
508 if (!init)
510 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
511 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
512 GetDlgItem(hDlg,cmb1));
514 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
516 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
517 if (j!=CB_ERR)
519 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
520 SendMessageA(hDlg,WM_COMMAND,cmb2,
521 MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
525 else
527 WARN(commdlg,"HDC failure !!!\n");
528 EndDialog (hDlg, 0);
529 return FALSE;
532 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
533 ReleaseDC(hDlg,hdc);
534 SetCursor(hcursor);
535 return TRUE;
539 /***********************************************************************
540 * CFn_WMMeasureItem [internal]
542 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
544 BITMAP bm;
545 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
546 if (!hBitmapTT)
547 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
548 GetObjectA( hBitmapTT, sizeof(bm), &bm );
549 lpmi->itemHeight=bm.bmHeight;
550 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
551 return 0;
555 /***********************************************************************
556 * CFn_WMDrawItem [internal]
558 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
560 HBRUSH hBrush;
561 char buffer[40];
562 BITMAP bm;
563 COLORREF cr, oldText=0, oldBk=0;
564 RECT rect;
565 #if 0
566 HDC hMemDC;
567 int nFontType;
568 HBITMAP hBitmap; /* for later TT usage */
569 #endif
570 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
572 if (lpdi->itemID == 0xFFFF) /* got no items */
573 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
574 else
576 if (lpdi->CtlType == ODT_COMBOBOX)
578 if (lpdi->itemState ==ODS_SELECTED)
580 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
581 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
582 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
583 } else
585 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
586 SelectObject(lpdi->hDC, hBrush);
588 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
590 else
591 return TRUE; /* this should never happen */
593 rect=lpdi->rcItem;
594 switch (lpdi->CtlID)
596 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
597 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
598 (LPARAM)buffer);
599 GetObjectA( hBitmapTT, sizeof(bm), &bm );
600 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
601 lpdi->rcItem.top, buffer, lstrlenA(buffer));
602 #if 0
603 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
604 /* FIXME: draw bitmap if truetype usage */
605 if (nFontType&TRUETYPE_FONTTYPE)
607 hMemDC = CreateCompatibleDC(lpdi->hDC);
608 hBitmap = SelectObject(hMemDC, hBitmapTT);
609 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
610 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
611 SelectObject(hMemDC, hBitmap);
612 DeleteDC(hMemDC);
614 #endif
615 break;
616 case cmb2:
617 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
618 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
619 (LPARAM)buffer);
620 TextOutA(lpdi->hDC, lpdi->rcItem.left,
621 lpdi->rcItem.top, buffer, lstrlenA(buffer));
622 break;
624 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
625 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
626 (LPARAM)buffer);
627 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
628 lpdi->rcItem.top, buffer, lstrlenA(buffer));
629 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
630 hBrush = CreateSolidBrush(cr);
631 if (hBrush)
633 hBrush = SelectObject (lpdi->hDC, hBrush) ;
634 rect.right=rect.left+25;
635 rect.top++;
636 rect.left+=5;
637 rect.bottom--;
638 Rectangle( lpdi->hDC, rect.left, rect.top,
639 rect.right, rect.bottom );
640 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
642 rect=lpdi->rcItem;
643 rect.left+=25+5;
644 break;
646 default: return TRUE; /* this should never happen */
648 if (lpdi->itemState == ODS_SELECTED)
650 SetTextColor(lpdi->hDC, oldText);
651 SetBkColor(lpdi->hDC, oldBk);
654 return TRUE;
657 /***********************************************************************
658 * CFn_WMCtlColor [internal]
660 LRESULT CFn_WMCtlColorStatic(HWND hDlg, WPARAM wParam, LPARAM lParam,
661 LPCHOOSEFONTA lpcf)
663 if (lpcf->Flags & CF_EFFECTS)
664 if (GetDlgCtrlID(lParam)==stc6)
666 SetTextColor((HDC)wParam, lpcf->rgbColors);
667 return GetStockObject(WHITE_BRUSH);
669 return 0;
672 /***********************************************************************
673 * CFn_WMCommand [internal]
675 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
676 LPCHOOSEFONTA lpcf)
678 HFONT hFont;
679 int i,j;
680 long l;
681 HDC hdc;
682 LPLOGFONTA lpxx=lpcf->lpLogFont;
684 TRACE(commdlg,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
685 switch (LOWORD(wParam))
687 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
689 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
690 if (hdc)
692 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
693 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
694 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
695 if (i!=CB_ERR)
697 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
698 CFn_ENUMSTRUCT s;
699 char str[256];
700 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
701 (LPARAM)str);
702 TRACE(commdlg,"WM_COMMAND/cmb1 =>%s\n",str);
703 s.hWnd1=GetDlgItem(hDlg, cmb2);
704 s.hWnd2=GetDlgItem(hDlg, cmb3);
705 s.lpcf32a=lpcf;
706 EnumFontFamiliesA(hdc, str, FontStyleEnumProc, (LPARAM)&s);
707 SetCursor(hcursor);
709 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
710 ReleaseDC(hDlg,hdc);
712 else
714 WARN(commdlg,"HDC failure !!!\n");
715 EndDialog (hDlg, 0);
716 return TRUE;
719 case chx1:
720 case chx2:
721 case cmb2:
722 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
724 char str[256];
725 TRACE(commdlg,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
726 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
727 if (i==CB_ERR)
728 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
729 else
731 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
732 (LPARAM)str);
733 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
734 j=HIWORD(l);
735 lpcf->nFontType = LOWORD(l);
736 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
737 /* same value reported to the EnumFonts
738 call back with the extra FONTTYPE_... bits added */
739 lpxx->lfPitchAndFamily=j&0xff;
740 lpxx->lfCharSet=j>>8;
742 strcpy(lpxx->lfFaceName,str);
743 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
744 if (i!=CB_ERR)
746 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
747 if (0!=(lpxx->lfItalic=HIWORD(l)))
748 lpcf->nFontType |= ITALIC_FONTTYPE;
749 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
750 lpcf->nFontType |= BOLD_FONTTYPE;
752 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
753 if (i!=CB_ERR)
754 lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
755 else
756 lpxx->lfHeight=0;
757 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
758 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
759 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
760 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
761 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
762 lpxx->lfQuality=DEFAULT_QUALITY;
763 lpcf->iPointSize= -10*lpxx->lfHeight;
765 hFont=CreateFontIndirectA(lpxx);
766 if (hFont)
768 HFONT oldFont=SendDlgItemMessageA(hDlg, stc6,
769 WM_GETFONT, 0, 0);
770 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,hFont,TRUE);
771 DeleteObject(oldFont);
774 break;
776 case cmb4:i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
777 if (i!=CB_ERR)
779 lpcf->rgbColors=textcolors[i];
780 InvalidateRect( GetDlgItem(hDlg,stc6), NULL, 0 );
782 break;
784 case psh15:i=RegisterWindowMessageA( HELPMSGSTRING );
785 if (lpcf->hwndOwner)
786 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
787 /* if (CFn_HookCallChk(lpcf))
788 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
789 break;
791 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
792 ( (lpcf->Flags & CF_LIMITSIZE) &&
793 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
794 (-lpxx->lfHeight <= lpcf->nSizeMax)))
795 EndDialog(hDlg, TRUE);
796 else
798 char buffer[80];
799 sprintf(buffer,"Select a font size between %d and %d points.",
800 lpcf->nSizeMin,lpcf->nSizeMax);
801 MessageBoxA(hDlg, buffer, NULL, MB_OK);
803 return(TRUE);
804 case IDCANCEL:EndDialog(hDlg, FALSE);
805 return(TRUE);
807 return(FALSE);
810 static LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
812 DeleteObject(SendDlgItemMessageA(hwnd, stc6, WM_GETFONT, 0, 0));
813 return TRUE;
817 /***********************************************************************
818 * FormatCharDlgProc16 (COMMDLG.16)
819 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
820 2. some CF_.. flags are not supported
821 3. some TType extensions
823 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
824 LPARAM lParam)
826 LPCHOOSEFONT16 lpcf;
827 LPCHOOSEFONTA lpcf32a;
828 UINT uMsg32;
829 WPARAM wParam32;
830 LRESULT res=0;
831 if (message!=WM_INITDIALOG)
833 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
834 if (!lpcf)
835 return FALSE;
836 if (CFn_HookCallChk(lpcf))
837 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
838 if (res)
839 return res;
841 else
843 lpcf=(LPCHOOSEFONT16)lParam;
844 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
845 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
847 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
848 return FALSE;
850 if (CFn_HookCallChk(lpcf))
851 return CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
853 WINPROC_MapMsg16To32A(message, wParam, &uMsg32, &wParam32, &lParam);
854 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
855 switch (uMsg32)
857 case WM_MEASUREITEM:
858 res=CFn_WMMeasureItem(hDlg, wParam32, lParam);
859 break;
860 case WM_DRAWITEM:
861 res=CFn_WMDrawItem(hDlg, wParam32, lParam);
862 break;
863 case WM_CTLCOLORSTATIC:
864 res=CFn_WMCtlColorStatic(hDlg, wParam32, lParam, lpcf32a);
865 break;
866 case WM_COMMAND:
867 res=CFn_WMCommand(hDlg, wParam32, lParam, lpcf32a);
868 break;
869 case WM_DESTROY:
870 res=CFn_WMDestroy(hDlg, wParam32, lParam);
871 break;
872 case WM_CHOOSEFONT_GETLOGFONT:
873 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
874 lParam);
875 FIXME(commdlg, "current logfont back to caller\n");
876 break;
878 WINPROC_UnmapMsg16To32A(hDlg,uMsg32, wParam32, lParam, res);
879 return res;
882 /***********************************************************************
883 * FormatCharDlgProc32A [internal]
885 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
886 LPARAM lParam)
888 LPCHOOSEFONTA lpcf;
889 LRESULT res=FALSE;
890 if (uMsg!=WM_INITDIALOG)
892 lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);
893 if (!lpcf)
894 return FALSE;
895 if (CFn_HookCallChk32(lpcf))
896 res=CallWindowProcA(lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
897 if (res)
898 return res;
900 else
902 lpcf=(LPCHOOSEFONTA)lParam;
903 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
905 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
906 return FALSE;
908 if (CFn_HookCallChk32(lpcf))
909 return CallWindowProcA(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
911 switch (uMsg)
913 case WM_MEASUREITEM:
914 return CFn_WMMeasureItem(hDlg, wParam, lParam);
915 case WM_DRAWITEM:
916 return CFn_WMDrawItem(hDlg, wParam, lParam);
917 case WM_CTLCOLORSTATIC:
918 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
919 case WM_COMMAND:
920 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
921 case WM_DESTROY:
922 return CFn_WMDestroy(hDlg, wParam, lParam);
923 case WM_CHOOSEFONT_GETLOGFONT:
924 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
925 lParam);
926 FIXME(commdlg, "current logfont back to caller\n");
927 break;
929 return res;
932 /***********************************************************************
933 * FormatCharDlgProc32W [internal]
935 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
936 LPARAM lParam)
938 LPCHOOSEFONTW lpcf32w;
939 LPCHOOSEFONTA lpcf32a;
940 LRESULT res=FALSE;
941 if (uMsg!=WM_INITDIALOG)
943 lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);
944 if (!lpcf32w)
945 return FALSE;
946 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
947 res=CallWindowProcW(lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
948 if (res)
949 return res;
951 else
953 lpcf32w=(LPCHOOSEFONTW)lParam;
954 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
955 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
957 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
958 return FALSE;
960 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
961 return CallWindowProcW(lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
963 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
964 switch (uMsg)
966 case WM_MEASUREITEM:
967 return CFn_WMMeasureItem(hDlg, wParam, lParam);
968 case WM_DRAWITEM:
969 return CFn_WMDrawItem(hDlg, wParam, lParam);
970 case WM_CTLCOLORSTATIC:
971 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
972 case WM_COMMAND:
973 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
974 case WM_DESTROY:
975 return CFn_WMDestroy(hDlg, wParam, lParam);
976 case WM_CHOOSEFONT_GETLOGFONT:
977 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
978 lParam);
979 FIXME(commdlg, "current logfont back to caller\n");
980 break;
982 return res;