Changed CBGetDroppedControlRect to be compliant with Windows API.
[wine/testsucceed.git] / dlls / commdlg / fontdlg.c
blob7dce147dbe89e73c484081accfabce2ee6ab15a6
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 #include "cdlg.h"
31 static HBITMAP16 hBitmapTT = 0;
36 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONTA chf32a)
38 chf32a->lStructSize=sizeof(CHOOSEFONTA);
39 chf32a->hwndOwner=chf16->hwndOwner;
40 chf32a->hDC=chf16->hDC;
41 chf32a->iPointSize=chf16->iPointSize;
42 chf32a->Flags=chf16->Flags;
43 chf32a->rgbColors=chf16->rgbColors;
44 chf32a->lCustData=chf16->lCustData;
45 chf32a->lpfnHook=NULL;
46 chf32a->lpTemplateName=PTR_SEG_TO_LIN(chf16->lpTemplateName);
47 chf32a->hInstance=chf16->hInstance;
48 chf32a->lpszStyle=PTR_SEG_TO_LIN(chf16->lpszStyle);
49 chf32a->nFontType=chf16->nFontType;
50 chf32a->nSizeMax=chf16->nSizeMax;
51 chf32a->nSizeMin=chf16->nSizeMin;
52 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16->lpLogFont), chf32a->lpLogFont);
56 /***********************************************************************
57 * ChooseFont16 (COMMDLG.15)
59 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
61 HINSTANCE16 hInst;
62 HANDLE16 hDlgTmpl = 0;
63 BOOL16 bRet = FALSE, win32Format = FALSE;
64 LPCVOID template;
65 HWND hwndDialog;
66 CHOOSEFONTA cf32a;
67 LOGFONTA lf32a;
68 SEGPTR lpTemplateName;
70 cf32a.lpLogFont=&lf32a;
71 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
73 TRACE(commdlg,"ChooseFont\n");
74 if (!lpChFont) return FALSE;
76 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
78 if (!(template = LockResource16( lpChFont->hInstance )))
80 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
81 return FALSE;
84 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
86 HANDLE16 hResInfo;
87 if (!(hResInfo = FindResource16( lpChFont->hInstance,
88 lpChFont->lpTemplateName,
89 RT_DIALOG16)))
91 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
92 return FALSE;
94 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
95 !(template = LockResource16( hDlgTmpl )))
97 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
98 return FALSE;
101 else
103 HANDLE hResInfo;
104 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
106 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
107 return FALSE;
109 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
110 !(template = LockResource( hDlgTmpl )))
112 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
113 return FALSE;
115 win32Format = TRUE;
118 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
120 /* lpTemplateName is not used in the dialog */
121 lpTemplateName=lpChFont->lpTemplateName;
122 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
124 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
125 lpChFont->hwndOwner,
126 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
127 (DWORD)lpChFont, WIN_PROC_16 );
128 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
129 if (hDlgTmpl) FreeResource16( hDlgTmpl );
130 lpChFont->lpTemplateName=lpTemplateName;
131 FONT_LogFont32ATo16(cf32a.lpLogFont,
132 (LPLOGFONT16)(PTR_SEG_TO_LIN(lpChFont->lpLogFont)));
133 return bRet;
137 /***********************************************************************
138 * ChooseFont32A (COMDLG32.3)
140 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
142 BOOL bRet=FALSE;
143 HWND hwndDialog;
144 HINSTANCE hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
145 LPCVOID template;
146 HANDLE hResInfo, hDlgTmpl;
148 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
150 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
151 return FALSE;
153 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
154 !(template = LockResource( hDlgTmpl )))
156 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
157 return FALSE;
160 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
161 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
162 hwndDialog = DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
163 (DLGPROC16)FormatCharDlgProcA, (LPARAM)lpChFont, WIN_PROC_32A );
164 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
165 return bRet;
168 /***********************************************************************
169 * ChooseFont32W (COMDLG32.4)
171 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
173 BOOL bRet=FALSE;
174 HWND hwndDialog;
175 HINSTANCE hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
176 CHOOSEFONTA cf32a;
177 LOGFONTA lf32a;
178 LPCVOID template;
179 HANDLE hResInfo, hDlgTmpl;
181 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_FONT", RT_DIALOGA)))
183 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
184 return FALSE;
186 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
187 !(template = LockResource( hDlgTmpl )))
189 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
190 return FALSE;
193 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
194 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
195 memcpy(&cf32a, lpChFont, sizeof(cf32a));
196 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONTA));
197 lstrcpynWtoA(lf32a.lfFaceName, lpChFont->lpLogFont->lfFaceName, LF_FACESIZE);
198 cf32a.lpLogFont=&lf32a;
199 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
200 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
201 hwndDialog=DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
202 (DLGPROC16)FormatCharDlgProcW, (LPARAM)lpChFont, WIN_PROC_32W );
203 if (hwndDialog)bRet=DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
204 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
205 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
206 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONTA));
207 lstrcpynAtoW(lpChFont->lpLogFont->lfFaceName, lf32a.lfFaceName, LF_FACESIZE);
208 return bRet;
212 #define TEXT_EXTRAS 4
213 #define TEXT_COLORS 16
215 static const COLORREF textcolors[TEXT_COLORS]=
217 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
218 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
219 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
220 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
223 /***********************************************************************
224 * CFn_HookCallChk [internal]
226 static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
228 if (lpcf)
229 if(lpcf->Flags & CF_ENABLEHOOK)
230 if (lpcf->lpfnHook)
231 return TRUE;
232 return FALSE;
235 /***********************************************************************
236 * CFn_HookCallChk32 [internal]
238 static BOOL CFn_HookCallChk32(LPCHOOSEFONTA lpcf)
240 if (lpcf)
241 if(lpcf->Flags & CF_ENABLEHOOK)
242 if (lpcf->lpfnHook)
243 return TRUE;
244 return FALSE;
248 /*************************************************************************
249 * AddFontFamily [internal]
251 static INT AddFontFamily(LPLOGFONTA lplf, UINT nFontType,
252 LPCHOOSEFONTA lpcf, HWND hwnd)
254 int i;
255 WORD w;
257 TRACE(commdlg,"font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
259 if (lpcf->Flags & CF_FIXEDPITCHONLY)
260 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
261 return 1;
262 if (lpcf->Flags & CF_ANSIONLY)
263 if (lplf->lfCharSet != ANSI_CHARSET)
264 return 1;
265 if (lpcf->Flags & CF_TTONLY)
266 if (!(nFontType & TRUETYPE_FONTTYPE))
267 return 1;
269 i=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
270 if (i!=CB_ERR)
272 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
273 SendMessageA(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
274 return 1 ; /* store some important font information */
276 else
277 return 0;
280 typedef struct
282 HWND hWnd1;
283 HWND hWnd2;
284 LPCHOOSEFONTA lpcf32a;
285 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
287 /*************************************************************************
288 * FontFamilyEnumProc32 [internal]
290 INT WINAPI FontFamilyEnumProc(LPENUMLOGFONTA lpEnumLogFont,
291 LPNEWTEXTMETRICA metrics, UINT nFontType, LPARAM lParam)
293 LPCFn_ENUMSTRUCT e;
294 e=(LPCFn_ENUMSTRUCT)lParam;
295 return AddFontFamily(&lpEnumLogFont->elfLogFont, nFontType, e->lpcf32a, e->hWnd1);
298 /***********************************************************************
299 * FontFamilyEnumProc16 (COMMDLG.19)
301 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
302 UINT16 nFontType, LPARAM lParam )
304 HWND16 hwnd=LOWORD(lParam);
305 HWND16 hDlg=GetParent16(hwnd);
306 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
307 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
308 LOGFONTA lf32a;
309 FONT_LogFont16To32A(lplf, &lf32a);
310 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
311 hwnd);
314 /*************************************************************************
315 * SetFontStylesToCombo2 [internal]
317 * Fill font style information into combobox (without using font.c directly)
319 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, LPLOGFONTA lplf)
321 #define FSTYLES 4
322 struct FONTSTYLE
323 { int italic;
324 int weight;
325 char stname[20]; };
326 static struct FONTSTYLE fontstyles[FSTYLES]={
327 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
328 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
329 HFONT16 hf;
330 TEXTMETRIC16 tm;
331 int i,j;
333 for (i=0;i<FSTYLES;i++)
335 lplf->lfItalic=fontstyles[i].italic;
336 lplf->lfWeight=fontstyles[i].weight;
337 hf=CreateFontIndirectA(lplf);
338 hf=SelectObject(hdc,hf);
339 GetTextMetrics16(hdc,&tm);
340 hf=SelectObject(hdc,hf);
341 DeleteObject(hf);
343 if (tm.tmWeight==fontstyles[i].weight &&
344 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
346 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
347 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
348 SEGPTR_FREE(str);
349 if (j==CB_ERR) return 1;
350 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
351 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
352 if (j==CB_ERR) return 1;
355 return 0;
358 /*************************************************************************
359 * AddFontSizeToCombo3 [internal]
361 static int AddFontSizeToCombo3(HWND hwnd, UINT h, LPCHOOSEFONTA lpcf)
363 int j;
364 char buffer[20];
366 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
367 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
369 sprintf(buffer, "%2d", h);
370 j=SendMessageA(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
371 if (j==CB_ERR)
373 j=SendMessageA(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
374 if (j!=CB_ERR) j = SendMessageA(hwnd, CB_SETITEMDATA, j, h);
375 if (j==CB_ERR) return 1;
378 return 0;
381 /*************************************************************************
382 * SetFontSizesToCombo3 [internal]
384 static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
386 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
387 int i;
389 for (i=0; sizes[i]; i++)
390 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
391 return 0;
394 /***********************************************************************
395 * AddFontStyle [internal]
397 INT AddFontStyle(LPLOGFONTA lplf, UINT nFontType,
398 LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
400 int i;
402 TRACE(commdlg,"(nFontType=%d)\n",nFontType);
403 TRACE(commdlg," %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
404 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
405 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
406 lplf->lfEscapement,lplf->lfOrientation,
407 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
408 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
409 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
410 if (nFontType & RASTER_FONTTYPE)
412 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
413 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
415 if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
417 HDC hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
418 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
419 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
420 ReleaseDC(hDlg,hdc);
421 if (i)
422 return 0;
424 return 1 ;
428 /***********************************************************************
429 * FontStyleEnumProc16 (COMMDLG.18)
431 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
432 UINT16 nFontType, LPARAM lParam )
434 HWND16 hcmb2=LOWORD(lParam);
435 HWND16 hcmb3=HIWORD(lParam);
436 HWND16 hDlg=GetParent16(hcmb3);
437 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
438 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
439 LOGFONTA lf32a;
440 FONT_LogFont16To32A(lplf, &lf32a);
441 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
442 hcmb2, hcmb3, hDlg);
445 /***********************************************************************
446 * FontStyleEnumProc32 [internal]
448 INT WINAPI FontStyleEnumProc( LPENUMLOGFONTA lpFont,
449 LPNEWTEXTMETRICA metrics, UINT nFontType, LPARAM lParam )
451 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
452 HWND hcmb2=s->hWnd1;
453 HWND hcmb3=s->hWnd2;
454 HWND hDlg=GetParent(hcmb3);
455 return AddFontStyle(&lpFont->elfLogFont, nFontType, s->lpcf32a, hcmb2,
456 hcmb3, hDlg);
459 /***********************************************************************
460 * CFn_WMInitDialog [internal]
462 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
463 LPCHOOSEFONTA lpcf)
465 HDC hdc;
466 int i,j,res,init=0;
467 long l;
468 LPLOGFONTA lpxx;
469 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
471 SetWindowLongA(hDlg, DWL_USER, lParam);
472 lpxx=lpcf->lpLogFont;
473 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
475 if (lpcf->lStructSize != sizeof(CHOOSEFONTA))
477 ERR(commdlg,"structure size failure !!!\n");
478 EndDialog (hDlg, 0);
479 return FALSE;
481 if (!hBitmapTT)
482 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
484 /* This font will be deleted by WM_COMMAND */
485 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,
486 CreateFontA(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
488 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
489 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
490 if (!(lpcf->Flags & CF_APPLY))
491 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
492 if (lpcf->Flags & CF_EFFECTS)
494 for (res=1,i=0;res && i<TEXT_COLORS;i++)
496 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
497 char name[20];
498 strcpy( name, "[color name]" );
499 j=SendDlgItemMessageA(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
500 SendDlgItemMessageA(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
501 /* look for a fitting value in color combobox */
502 if (textcolors[j]==lpcf->rgbColors)
503 SendDlgItemMessageA(hDlg,cmb4, CB_SETCURSEL,j,0);
506 else
508 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
509 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
510 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
511 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
512 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
514 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
515 if (hdc)
517 CFn_ENUMSTRUCT s;
518 s.hWnd1=GetDlgItem(hDlg,cmb1);
519 s.lpcf32a=lpcf;
520 if (!EnumFontFamiliesA(hdc, NULL, FontFamilyEnumProc, (LPARAM)&s))
521 TRACE(commdlg,"EnumFontFamilies returns 0\n");
522 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
524 /* look for fitting font name in combobox1 */
525 j=SendDlgItemMessageA(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
526 if (j!=CB_ERR)
528 SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
529 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
530 GetDlgItem(hDlg,cmb1));
531 init=1;
532 /* look for fitting font style in combobox2 */
533 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
534 for (i=0;i<TEXT_EXTRAS;i++)
536 if (l==SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0))
537 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
540 /* look for fitting font size in combobox3 */
541 j=SendDlgItemMessageA(hDlg, cmb3, CB_GETCOUNT, 0, 0);
542 for (i=0;i<j;i++)
544 if (lpxx->lfHeight==(int)SendDlgItemMessageA(hDlg,cmb3, CB_GETITEMDATA,i,0))
545 SendDlgItemMessageA(hDlg,cmb3,CB_SETCURSEL,i,0);
549 if (!init)
551 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
552 SendMessageA(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
553 GetDlgItem(hDlg,cmb1));
555 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
557 j=SendDlgItemMessageA(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
558 if (j!=CB_ERR)
560 j=SendDlgItemMessageA(hDlg,cmb2,CB_SETCURSEL,j,0);
561 SendMessageA(hDlg,WM_COMMAND,cmb2,
562 MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
566 else
568 WARN(commdlg,"HDC failure !!!\n");
569 EndDialog (hDlg, 0);
570 return FALSE;
573 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
574 ReleaseDC(hDlg,hdc);
575 SetCursor(hcursor);
576 return TRUE;
580 /***********************************************************************
581 * CFn_WMMeasureItem [internal]
583 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
585 BITMAP bm;
586 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
587 if (!hBitmapTT)
588 hBitmapTT = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_TRTYPE));
589 GetObjectA( hBitmapTT, sizeof(bm), &bm );
590 lpmi->itemHeight=bm.bmHeight;
591 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
592 return 0;
596 /***********************************************************************
597 * CFn_WMDrawItem [internal]
599 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
601 HBRUSH hBrush;
602 char buffer[40];
603 BITMAP bm;
604 COLORREF cr, oldText=0, oldBk=0;
605 RECT rect;
606 #if 0
607 HDC hMemDC;
608 int nFontType;
609 HBITMAP hBitmap; /* for later TT usage */
610 #endif
611 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
613 if (lpdi->itemID == 0xFFFF) /* got no items */
614 DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
615 else
617 if (lpdi->CtlType == ODT_COMBOBOX)
619 if (lpdi->itemState ==ODS_SELECTED)
621 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
622 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
623 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
624 } else
626 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
627 SelectObject(lpdi->hDC, hBrush);
629 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
631 else
632 return TRUE; /* this should never happen */
634 rect=lpdi->rcItem;
635 switch (lpdi->CtlID)
637 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
638 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
639 (LPARAM)buffer);
640 GetObjectA( hBitmapTT, sizeof(bm), &bm );
641 TextOutA(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
642 lpdi->rcItem.top, buffer, lstrlenA(buffer));
643 #if 0
644 nFontType = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
645 /* FIXME: draw bitmap if truetype usage */
646 if (nFontType&TRUETYPE_FONTTYPE)
648 hMemDC = CreateCompatibleDC(lpdi->hDC);
649 hBitmap = SelectObject(hMemDC, hBitmapTT);
650 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
651 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
652 SelectObject(hMemDC, hBitmap);
653 DeleteDC(hMemDC);
655 #endif
656 break;
657 case cmb2:
658 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
659 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
660 (LPARAM)buffer);
661 TextOutA(lpdi->hDC, lpdi->rcItem.left,
662 lpdi->rcItem.top, buffer, lstrlenA(buffer));
663 break;
665 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
666 SendMessageA(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
667 (LPARAM)buffer);
668 TextOutA(lpdi->hDC, lpdi->rcItem.left + 25+5,
669 lpdi->rcItem.top, buffer, lstrlenA(buffer));
670 cr = SendMessageA(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
671 hBrush = CreateSolidBrush(cr);
672 if (hBrush)
674 hBrush = SelectObject (lpdi->hDC, hBrush) ;
675 rect.right=rect.left+25;
676 rect.top++;
677 rect.left+=5;
678 rect.bottom--;
679 Rectangle( lpdi->hDC, rect.left, rect.top,
680 rect.right, rect.bottom );
681 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
683 rect=lpdi->rcItem;
684 rect.left+=25+5;
685 break;
687 default: return TRUE; /* this should never happen */
689 if (lpdi->itemState == ODS_SELECTED)
691 SetTextColor(lpdi->hDC, oldText);
692 SetBkColor(lpdi->hDC, oldBk);
695 return TRUE;
698 /***********************************************************************
699 * CFn_WMCtlColor [internal]
701 LRESULT CFn_WMCtlColorStatic(HWND hDlg, WPARAM wParam, LPARAM lParam,
702 LPCHOOSEFONTA lpcf)
704 if (lpcf->Flags & CF_EFFECTS)
705 if (GetDlgCtrlID(lParam)==stc6)
707 SetTextColor((HDC)wParam, lpcf->rgbColors);
708 return GetStockObject(WHITE_BRUSH);
710 return 0;
713 /***********************************************************************
714 * CFn_WMCommand [internal]
716 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
717 LPCHOOSEFONTA lpcf)
719 HFONT hFont;
720 int i,j;
721 long l;
722 HDC hdc;
723 LPLOGFONTA lpxx=lpcf->lpLogFont;
725 TRACE(commdlg,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
726 switch (LOWORD(wParam))
728 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
730 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
731 if (hdc)
733 SendDlgItemMessageA(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
734 SendDlgItemMessageA(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
735 i=SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
736 if (i!=CB_ERR)
738 HCURSOR hcursor=SetCursor(LoadCursorA(0,IDC_WAITA));
739 CFn_ENUMSTRUCT s;
740 char str[256];
741 SendDlgItemMessageA(hDlg, cmb1, CB_GETLBTEXT, i,
742 (LPARAM)str);
743 TRACE(commdlg,"WM_COMMAND/cmb1 =>%s\n",str);
744 s.hWnd1=GetDlgItem(hDlg, cmb2);
745 s.hWnd2=GetDlgItem(hDlg, cmb3);
746 s.lpcf32a=lpcf;
747 EnumFontFamiliesA(hdc, str, FontStyleEnumProc, (LPARAM)&s);
748 SetCursor(hcursor);
750 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
751 ReleaseDC(hDlg,hdc);
753 else
755 WARN(commdlg,"HDC failure !!!\n");
756 EndDialog (hDlg, 0);
757 return TRUE;
760 case chx1:
761 case chx2:
762 case cmb2:
763 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
765 char str[256];
766 TRACE(commdlg,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
767 i=SendDlgItemMessageA(hDlg,cmb1,CB_GETCURSEL,0,0);
768 if (i==CB_ERR)
769 i=GetDlgItemTextA( hDlg, cmb1, str, 256 );
770 else
772 SendDlgItemMessageA(hDlg,cmb1,CB_GETLBTEXT,i,
773 (LPARAM)str);
774 l=SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,i,0);
775 j=HIWORD(l);
776 lpcf->nFontType = LOWORD(l);
777 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
778 /* same value reported to the EnumFonts
779 call back with the extra FONTTYPE_... bits added */
780 lpxx->lfPitchAndFamily=j&0xff;
781 lpxx->lfCharSet=j>>8;
783 strcpy(lpxx->lfFaceName,str);
784 i=SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
785 if (i!=CB_ERR)
787 l=SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0);
788 if (0!=(lpxx->lfItalic=HIWORD(l)))
789 lpcf->nFontType |= ITALIC_FONTTYPE;
790 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
791 lpcf->nFontType |= BOLD_FONTTYPE;
793 i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
794 if (i!=CB_ERR)
795 lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
796 else
797 lpxx->lfHeight=0;
798 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
799 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
800 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
801 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
802 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
803 lpxx->lfQuality=DEFAULT_QUALITY;
804 lpcf->iPointSize= -10*lpxx->lfHeight;
806 hFont=CreateFontIndirectA(lpxx);
807 if (hFont)
809 HFONT oldFont=SendDlgItemMessageA(hDlg, stc6,
810 WM_GETFONT, 0, 0);
811 SendDlgItemMessageA(hDlg,stc6,WM_SETFONT,hFont,TRUE);
812 DeleteObject(oldFont);
815 break;
817 case cmb4:i=SendDlgItemMessageA(hDlg, cmb4, CB_GETCURSEL, 0, 0);
818 if (i!=CB_ERR)
820 lpcf->rgbColors=textcolors[i];
821 InvalidateRect( GetDlgItem(hDlg,stc6), NULL, 0 );
823 break;
825 case psh15:i=RegisterWindowMessageA( HELPMSGSTRING );
826 if (lpcf->hwndOwner)
827 SendMessageA(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLongA(hDlg, DWL_USER));
828 /* if (CFn_HookCallChk(lpcf))
829 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
830 break;
832 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
833 ( (lpcf->Flags & CF_LIMITSIZE) &&
834 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
835 (-lpxx->lfHeight <= lpcf->nSizeMax)))
836 EndDialog(hDlg, TRUE);
837 else
839 char buffer[80];
840 sprintf(buffer,"Select a font size between %d and %d points.",
841 lpcf->nSizeMin,lpcf->nSizeMax);
842 MessageBoxA(hDlg, buffer, NULL, MB_OK);
844 return(TRUE);
845 case IDCANCEL:EndDialog(hDlg, FALSE);
846 return(TRUE);
848 return(FALSE);
851 static LRESULT CFn_WMDestroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
853 DeleteObject(SendDlgItemMessageA(hwnd, stc6, WM_GETFONT, 0, 0));
854 return TRUE;
858 /***********************************************************************
859 * FormatCharDlgProc16 (COMMDLG.16)
860 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
861 2. some CF_.. flags are not supported
862 3. some TType extensions
864 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
865 LPARAM lParam)
867 LPCHOOSEFONT16 lpcf;
868 LPCHOOSEFONTA lpcf32a;
869 UINT uMsg32;
870 WPARAM wParam32;
871 LRESULT res=0;
872 if (message!=WM_INITDIALOG)
874 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
875 if (!lpcf)
876 return FALSE;
877 if (CFn_HookCallChk(lpcf))
878 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
879 if (res)
880 return res;
882 else
884 lpcf=(LPCHOOSEFONT16)lParam;
885 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
886 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
888 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
889 return FALSE;
891 if (CFn_HookCallChk(lpcf))
892 return CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
894 WINPROC_MapMsg16To32A(message, wParam, &uMsg32, &wParam32, &lParam);
895 lpcf32a=(LPCHOOSEFONTA)lpcf->lpTemplateName;
896 switch (uMsg32)
898 case WM_MEASUREITEM:
899 res=CFn_WMMeasureItem(hDlg, wParam32, lParam);
900 break;
901 case WM_DRAWITEM:
902 res=CFn_WMDrawItem(hDlg, wParam32, lParam);
903 break;
904 case WM_CTLCOLORSTATIC:
905 res=CFn_WMCtlColorStatic(hDlg, wParam32, lParam, lpcf32a);
906 break;
907 case WM_COMMAND:
908 res=CFn_WMCommand(hDlg, wParam32, lParam, lpcf32a);
909 break;
910 case WM_DESTROY:
911 res=CFn_WMDestroy(hDlg, wParam32, lParam);
912 break;
913 case WM_CHOOSEFONT_GETLOGFONT:
914 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
915 lParam);
916 FIXME(commdlg, "current logfont back to caller\n");
917 break;
919 WINPROC_UnmapMsg16To32A(hDlg,uMsg32, wParam32, lParam, res);
920 return res;
923 /***********************************************************************
924 * FormatCharDlgProc32A [internal]
926 LRESULT WINAPI FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
927 LPARAM lParam)
929 LPCHOOSEFONTA lpcf;
930 LRESULT res=FALSE;
931 if (uMsg!=WM_INITDIALOG)
933 lpcf=(LPCHOOSEFONTA)GetWindowLongA(hDlg, DWL_USER);
934 if (!lpcf)
935 return FALSE;
936 if (CFn_HookCallChk32(lpcf))
937 res=CallWindowProcA(lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
938 if (res)
939 return res;
941 else
943 lpcf=(LPCHOOSEFONTA)lParam;
944 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
946 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
947 return FALSE;
949 if (CFn_HookCallChk32(lpcf))
950 return CallWindowProcA(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
952 switch (uMsg)
954 case WM_MEASUREITEM:
955 return CFn_WMMeasureItem(hDlg, wParam, lParam);
956 case WM_DRAWITEM:
957 return CFn_WMDrawItem(hDlg, wParam, lParam);
958 case WM_CTLCOLORSTATIC:
959 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
960 case WM_COMMAND:
961 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
962 case WM_DESTROY:
963 return CFn_WMDestroy(hDlg, wParam, lParam);
964 case WM_CHOOSEFONT_GETLOGFONT:
965 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
966 lParam);
967 FIXME(commdlg, "current logfont back to caller\n");
968 break;
970 return res;
973 /***********************************************************************
974 * FormatCharDlgProc32W [internal]
976 LRESULT WINAPI FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
977 LPARAM lParam)
979 LPCHOOSEFONTW lpcf32w;
980 LPCHOOSEFONTA lpcf32a;
981 LRESULT res=FALSE;
982 if (uMsg!=WM_INITDIALOG)
984 lpcf32w=(LPCHOOSEFONTW)GetWindowLongA(hDlg, DWL_USER);
985 if (!lpcf32w)
986 return FALSE;
987 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
988 res=CallWindowProcW(lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
989 if (res)
990 return res;
992 else
994 lpcf32w=(LPCHOOSEFONTW)lParam;
995 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
996 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
998 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
999 return FALSE;
1001 if (CFn_HookCallChk32((LPCHOOSEFONTA)lpcf32w))
1002 return CallWindowProcW(lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1004 lpcf32a=(LPCHOOSEFONTA)lpcf32w->lpTemplateName;
1005 switch (uMsg)
1007 case WM_MEASUREITEM:
1008 return CFn_WMMeasureItem(hDlg, wParam, lParam);
1009 case WM_DRAWITEM:
1010 return CFn_WMDrawItem(hDlg, wParam, lParam);
1011 case WM_CTLCOLORSTATIC:
1012 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
1013 case WM_COMMAND:
1014 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
1015 case WM_DESTROY:
1016 return CFn_WMDestroy(hDlg, wParam, lParam);
1017 case WM_CHOOSEFONT_GETLOGFONT:
1018 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
1019 lParam);
1020 FIXME(commdlg, "current logfont back to caller\n");
1021 break;
1023 return res;