1 /*
2  * PROJECT:     PAINT for ReactOS
3  * LICENSE:     LGPL
4  * FILE:        base/applications/mspaint/dialogs.cpp
5  * PURPOSE:     Window procedures of the dialog windows plus launching functions
6  * PROGRAMMERS: Benedikt Freisen
7  */
8 
9 /* INCLUDES *********************************************************/
10 
11 #include "precomp.h"
12 
13 #include "dialogs.h"
14 
15 #include <winnls.h>
16 
17 /* GLOBALS **********************************************************/
18 
19 CMirrorRotateDialog mirrorRotateDialog;
20 CAttributesDialog attributesDialog;
21 CStretchSkewDialog stretchSkewDialog;
22 CFontsDialog fontsDialog;
23 
24 /* FUNCTIONS ********************************************************/
25 
26 LRESULT CMirrorRotateDialog::OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
27 {
28     CheckDlgButton(IDD_MIRRORROTATERB1, BST_CHECKED);
29     CheckDlgButton(IDD_MIRRORROTATERB4, BST_CHECKED);
30     return 0;
31 }
32 
33 LRESULT CMirrorRotateDialog::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
34 {
35     EndDialog(0);
36     return 0;
37 }
38 
39 LRESULT CMirrorRotateDialog::OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
40 {
41     if (IsDlgButtonChecked(IDD_MIRRORROTATERB1))
42         EndDialog(1);
43     else if (IsDlgButtonChecked(IDD_MIRRORROTATERB2))
44         EndDialog(2);
45     else if (IsDlgButtonChecked(IDD_MIRRORROTATERB4))
46         EndDialog(3);
47     else if (IsDlgButtonChecked(IDD_MIRRORROTATERB5))
48         EndDialog(4);
49     else if (IsDlgButtonChecked(IDD_MIRRORROTATERB6))
50         EndDialog(5);
51     return 0;
52 }
53 
54 LRESULT CMirrorRotateDialog::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
55 {
56     EndDialog(0);
57     return 0;
58 }
59 
60 LRESULT CMirrorRotateDialog::OnRadioButton3(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
61 {
62     ::EnableWindow(GetDlgItem(IDD_MIRRORROTATERB4), TRUE);
63     ::EnableWindow(GetDlgItem(IDD_MIRRORROTATERB5), TRUE);
64     ::EnableWindow(GetDlgItem(IDD_MIRRORROTATERB6), TRUE);
65     return 0;
66 }
67 
68 LRESULT CMirrorRotateDialog::OnRadioButton12(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
69 {
70     ::EnableWindow(GetDlgItem(IDD_MIRRORROTATERB4), FALSE);
71     ::EnableWindow(GetDlgItem(IDD_MIRRORROTATERB5), FALSE);
72     ::EnableWindow(GetDlgItem(IDD_MIRRORROTATERB6), FALSE);
73     return 0;
74 }
75 
76 
77 
78 LRESULT CAttributesDialog::OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
79 {
80     newWidth = imageModel.GetWidth();
81     newHeight = imageModel.GetHeight();
82 
83     CheckDlgButton(IDD_ATTRIBUTESRB3, BST_CHECKED);
84     CheckDlgButton(IDD_ATTRIBUTESRB5, BST_CHECKED);
85     SetDlgItemInt(IDD_ATTRIBUTESEDIT1, newWidth, FALSE);
86     SetDlgItemInt(IDD_ATTRIBUTESEDIT2, newHeight, FALSE);
87 
88     if (isAFile)
89     {
90         TCHAR date[100];
91         TCHAR temp[100];
92         GetDateFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, date, _countof(date));
93         GetTimeFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, temp, _countof(temp));
94         _tcscat(date, _T(" "));
95         _tcscat(date, temp);
96         CString strSize;
97         strSize.Format(IDS_FILESIZE, fileSize);
98         SetDlgItemText(IDD_ATTRIBUTESTEXT6, date);
99         SetDlgItemText(IDD_ATTRIBUTESTEXT7, strSize);
100     }
101     CString strRes;
102     strRes.Format(IDS_PRINTRES, fileHPPM, fileVPPM);
103     SetDlgItemText(IDD_ATTRIBUTESTEXT8, strRes);
104     return 0;
105 }
106 
107 LRESULT CAttributesDialog::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
108 {
109     EndDialog(0);
110     return 0;
111 }
112 
113 LRESULT CAttributesDialog::OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
114 {
115     EndDialog(1);
116     return 0;
117 }
118 
119 LRESULT CAttributesDialog::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
120 {
121     EndDialog(0);
122     return 0;
123 }
124 
125 LRESULT CAttributesDialog::OnDefault(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
126 {
127     newWidth = imageModel.GetWidth();
128     newHeight = imageModel.GetHeight();
129     CheckDlgButton(IDD_ATTRIBUTESRB3, BST_CHECKED);
130     CheckDlgButton(IDD_ATTRIBUTESRB5, BST_CHECKED);
131     SetDlgItemInt(IDD_ATTRIBUTESEDIT1, newWidth, FALSE);
132     SetDlgItemInt(IDD_ATTRIBUTESEDIT2, newHeight, FALSE);
133     return 0;
134 }
135 
136 LRESULT CAttributesDialog::OnRadioButton1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
137 {
138     CString strNum;
139     strNum.Format(_T("%.3lf"), newWidth / (0.0254 * fileHPPM));
140     SetDlgItemText(IDD_ATTRIBUTESEDIT1, strNum);
141     strNum.Format(_T("%.3lf"), newHeight / (0.0254 * fileVPPM));
142     SetDlgItemText(IDD_ATTRIBUTESEDIT2, strNum);
143     return 0;
144 }
145 
146 LRESULT CAttributesDialog::OnRadioButton2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
147 {
148     CString strNum;
149     strNum.Format(_T("%.3lf"), newWidth * 100.0 / fileHPPM);
150     SetDlgItemText(IDD_ATTRIBUTESEDIT1, strNum);
151     strNum.Format(_T("%.3lf"), newHeight * 100.0 / fileVPPM);
152     SetDlgItemText(IDD_ATTRIBUTESEDIT2, strNum);
153     return 0;
154 }
155 
156 LRESULT CAttributesDialog::OnRadioButton3(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
157 {
158     SetDlgItemInt(IDD_ATTRIBUTESEDIT1, newWidth, FALSE);
159     SetDlgItemInt(IDD_ATTRIBUTESEDIT2, newHeight, FALSE);
160     return 0;
161 }
162 
163 LRESULT CAttributesDialog::OnEdit1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
164 {
165     if (Edit_GetModify(hWndCtl))
166     {
167         TCHAR tempS[100];
168         if (IsDlgButtonChecked(IDD_ATTRIBUTESRB1))
169         {
170             GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, _countof(tempS));
171             newWidth = max(1, (int) (_tcstod(tempS, NULL) * fileHPPM * 0.0254));
172         }
173         else if (IsDlgButtonChecked(IDD_ATTRIBUTESRB2))
174         {
175             GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, _countof(tempS));
176             newWidth = max(1, (int) (_tcstod(tempS, NULL) * fileHPPM / 100));
177         }
178         else if (IsDlgButtonChecked(IDD_ATTRIBUTESRB3))
179         {
180             GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, _countof(tempS));
181             newWidth = max(1, _tstoi(tempS));
182         }
183         Edit_SetModify(hWndCtl, FALSE);
184     }
185     return 0;
186 }
187 
188 LRESULT CAttributesDialog::OnEdit2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
189 {
190     if (Edit_GetModify(hWndCtl))
191     {
192         TCHAR tempS[100];
193         if (IsDlgButtonChecked(IDD_ATTRIBUTESRB1))
194         {
195             GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, _countof(tempS));
196             newHeight = max(1, (int) (_tcstod(tempS, NULL) * fileVPPM * 0.0254));
197         }
198         else if (IsDlgButtonChecked(IDD_ATTRIBUTESRB2))
199         {
200             GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, _countof(tempS));
201             newHeight = max(1, (int) (_tcstod(tempS, NULL) * fileVPPM / 100));
202         }
203         else if (IsDlgButtonChecked(IDD_ATTRIBUTESRB3))
204         {
205             GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, _countof(tempS));
206             newHeight = max(1, _tstoi(tempS));
207         }
208         Edit_SetModify(hWndCtl, FALSE);
209     }
210     return 0;
211 }
212 
213 
214 
215 LRESULT CStretchSkewDialog::OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
216 {
217     SetDlgItemInt(IDD_STRETCHSKEWEDITHSTRETCH, 100, FALSE);
218     SetDlgItemInt(IDD_STRETCHSKEWEDITVSTRETCH, 100, FALSE);
219     SetDlgItemInt(IDD_STRETCHSKEWEDITHSKEW, 0, FALSE);
220     SetDlgItemInt(IDD_STRETCHSKEWEDITVSKEW, 0, FALSE);
221     return 0;
222 }
223 
224 LRESULT CStretchSkewDialog::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
225 {
226     EndDialog(0);
227     return 0;
228 }
229 
230 LRESULT CStretchSkewDialog::OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
231 {
232     CString strrcIntNumbers;
233     CString strrcPercentage;
234     CString strrcAngle;
235     BOOL tr1, tr2, tr3, tr4;
236 
237     strrcIntNumbers.LoadString(hProgInstance, IDS_INTNUMBERS);
238     strrcPercentage.LoadString(hProgInstance, IDS_PERCENTAGE);
239     strrcAngle.LoadString(hProgInstance, IDS_ANGLE);
240 
241     percentage.x = GetDlgItemInt(IDD_STRETCHSKEWEDITHSTRETCH, &tr1, FALSE);
242     percentage.y = GetDlgItemInt(IDD_STRETCHSKEWEDITVSTRETCH, &tr2, FALSE);
243     angle.x = GetDlgItemInt(IDD_STRETCHSKEWEDITHSKEW, &tr3, TRUE);
244     angle.y = GetDlgItemInt(IDD_STRETCHSKEWEDITVSKEW, &tr4, TRUE);
245 
246     if (!(tr1 && tr2 && tr3 && tr4))
247         MessageBox(strrcIntNumbers, NULL, MB_ICONEXCLAMATION);
248     else if (percentage.x < 1 || percentage.x > 500 || percentage.y < 1 || percentage.y > 500)
249         MessageBox(strrcPercentage, NULL, MB_ICONEXCLAMATION);
250     else if (angle.x < -89 || angle.x > 89 || angle.y < -89 || angle.y > 89)
251         MessageBox(strrcAngle, NULL, MB_ICONEXCLAMATION);
252     else
253         EndDialog(1);
254     return 0;
255 }
256 
257 LRESULT CStretchSkewDialog::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
258 {
259     EndDialog(0);
260     return 0;
261 }
262 
263 static INT CALLBACK
264 EnumFontFamProc(ENUMLOGFONT *lpelf, NEWTEXTMETRIC *lpntm, INT FontType, LPARAM lParam)
265 {
266     CSimpleArray<CString>& arrFontNames = *reinterpret_cast<CSimpleArray<CString>*>(lParam);
267     LPTSTR name = lpelf->elfLogFont.lfFaceName;
268     if (name[0] == TEXT('@')) // Vertical fonts
269         return TRUE;
270 
271     for (INT i = 0; i < arrFontNames.GetSize(); ++i)
272     {
273         if (arrFontNames[i] == name) // Already exists
274             return TRUE;
275     }
276 
277     arrFontNames.Add(name);
278     return TRUE;
279 }
280 
281 // TODO: AutoComplete font names
282 // TODO: Vertical text
283 CFontsDialog::CFontsDialog()
284 {
285 }
286 
287 void CFontsDialog::InitFontNames()
288 {
289     // List the fonts
290     CSimpleArray<CString> arrFontNames;
291     HDC hDC = CreateCompatibleDC(NULL);
292     if (hDC)
293     {
294         EnumFontFamilies(hDC, NULL, (FONTENUMPROC)EnumFontFamProc,
295                          reinterpret_cast<LPARAM>(&arrFontNames));
296         DeleteDC(hDC);
297     }
298 
299     // Actually add them to the combobox
300     HWND hwndNames = GetDlgItem(IDD_FONTSNAMES);
301     SendMessage(hwndNames, CB_RESETCONTENT, 0, 0);
302     for (INT i = 0; i < arrFontNames.GetSize(); ++i)
303     {
304         ComboBox_AddString(hwndNames, arrFontNames[i]);
305     }
306 
307     ::SetWindowText(hwndNames, registrySettings.strFontName);
308 }
309 
310 void CFontsDialog::InitFontSizes()
311 {
312     static const INT s_sizes[] =
313     {
314         8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72
315     };
316 
317     HWND hwndSizes = GetDlgItem(IDD_FONTSSIZES);
318     ComboBox_ResetContent(hwndSizes);
319 
320     TCHAR szText[16];
321     for (UINT i = 0; i < _countof(s_sizes); ++i)
322     {
323         wsprintf(szText, TEXT("%d"), s_sizes[i]);
324         INT iItem = ComboBox_AddString(hwndSizes, szText);
325         if (s_sizes[i] == (INT)registrySettings.PointSize)
326             ComboBox_SetCurSel(hwndSizes, iItem);
327     }
328 
329     if (ComboBox_GetCurSel(hwndSizes) == CB_ERR)
330     {
331         wsprintf(szText, TEXT("%d"), (INT)registrySettings.PointSize);
332         ::SetWindowText(hwndSizes, szText);
333     }
334 }
335 
336 void CFontsDialog::InitToolbar()
337 {
338     HWND hwndToolbar = GetDlgItem(IDD_FONTSTOOLBAR);
339     SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
340     SendMessage(hwndToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
341     SendMessage(hwndToolbar, TB_SETBUTTONWIDTH, 0, MAKELPARAM(20, 20));
342 
343     TBADDBITMAP AddBitmap;
344     AddBitmap.hInst = hProgInstance;
345     AddBitmap.nID = IDB_FONTSTOOLBAR;
346     SendMessage(hwndToolbar, TB_ADDBITMAP, 4, (LPARAM)&AddBitmap);
347 
348     HIMAGELIST himl = ImageList_LoadImage(hProgInstance, MAKEINTRESOURCE(IDB_FONTSTOOLBAR),
349                                           16, 8, RGB(255, 0, 255), IMAGE_BITMAP,
350                                           LR_CREATEDIBSECTION);
351     SendMessage(hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl);
352 
353     TBBUTTON buttons[] =
354     {
355         { 0, IDM_BOLD, TBSTATE_ENABLED, TBSTYLE_CHECK },
356         { 1, IDM_ITALIC, TBSTATE_ENABLED, TBSTYLE_CHECK },
357         { 2, IDM_UNDERLINE, TBSTATE_ENABLED, TBSTYLE_CHECK },
358         { 3, IDM_VERTICAL, 0, TBSTYLE_CHECK }, // TODO:
359     };
360     SendMessage(hwndToolbar, TB_ADDBUTTONS, _countof(buttons), (LPARAM)&buttons);
361 
362     SendMessage(hwndToolbar, TB_CHECKBUTTON, IDM_BOLD, registrySettings.Bold);
363     SendMessage(hwndToolbar, TB_CHECKBUTTON, IDM_ITALIC, registrySettings.Italic);
364     SendMessage(hwndToolbar, TB_CHECKBUTTON, IDM_UNDERLINE, registrySettings.Underline);
365 }
366 
367 LRESULT CFontsDialog::OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
368 {
369     // TODO: Tooltips
370     InitFontNames();
371     InitFontSizes();
372     InitToolbar();
373 
374     if (registrySettings.FontsPositionX != 0 || registrySettings.FontsPositionY != 0)
375     {
376         SetWindowPos(NULL,
377                      registrySettings.FontsPositionX, registrySettings.FontsPositionY,
378                      0, 0,
379                      SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
380         SendMessage(DM_REPOSITION, 0, 0);
381     }
382 
383     if (!registrySettings.ShowTextTool)
384         ShowWindow(SW_HIDE);
385 
386     return TRUE;
387 }
388 
389 LRESULT CFontsDialog::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
390 {
391     ShowWindow(SW_HIDE); // Just hide. Recycle for optimization
392     return 0;
393 }
394 
395 void CFontsDialog::OnFontName(UINT codeNotify)
396 {
397     HWND hwndNames = GetDlgItem(IDD_FONTSNAMES);
398     INT iItem = CB_ERR;
399     UINT cch;
400     TCHAR szText[LF_FACESIZE];
401 
402     switch (codeNotify)
403     {
404         case CBN_SELCHANGE:
405             iItem = ComboBox_GetCurSel(hwndNames);
406             cch = ComboBox_GetLBTextLen(hwndNames, iItem);
407             if (iItem != CB_ERR && 0 < cch && cch < _countof(szText))
408             {
409                 ComboBox_GetLBText(hwndNames, iItem, szText);
410             }
411             break;
412 
413         case CBN_EDITCHANGE:
414             GetDlgItemText(IDD_FONTSNAMES, szText, _countof(szText));
415             iItem = ComboBox_FindStringExact(hwndNames, -1, szText);
416             break;
417     }
418 
419     if (iItem != CB_ERR && registrySettings.strFontName.CompareNoCase(szText) != 0)
420     {
421         registrySettings.strFontName = szText;
422         toolsModel.NotifyToolChanged();
423     }
424 }
425 
426 void CFontsDialog::OnFontSize(UINT codeNotify)
427 {
428     HWND hwndSizes = GetDlgItem(IDD_FONTSSIZES);
429     WCHAR szText[8];
430     INT iItem, PointSize = 0;
431     UINT cch;
432 
433     switch (codeNotify)
434     {
435         case CBN_SELCHANGE:
436             iItem = ComboBox_GetCurSel(hwndSizes);
437             cch = ComboBox_GetLBTextLen(hwndSizes, iItem);
438             if (iItem != CB_ERR && 0 < cch && cch < _countof(szText))
439             {
440                 ComboBox_GetLBText(hwndSizes, iItem, szText);
441                 PointSize = _ttoi(szText);
442             }
443             break;
444 
445         case CBN_EDITCHANGE:
446             ::GetWindowText(hwndSizes, szText, _countof(szText));
447             PointSize = _ttoi(szText);
448             break;
449     }
450 
451     if (PointSize > 0)
452     {
453         registrySettings.PointSize = PointSize;
454         toolsModel.NotifyToolChanged();
455     }
456 }
457 
458 LRESULT CFontsDialog::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
459 {
460     UINT id = LOWORD(wParam);
461     UINT codeNotify = HIWORD(wParam);
462     HWND hwndToolbar = GetDlgItem(IDD_FONTSTOOLBAR);
463     BOOL bChecked = ::SendMessage(hwndToolbar, TB_ISBUTTONCHECKED, id, 0);
464 
465     switch (id)
466     {
467         case IDCANCEL:
468             ShowWindow(SW_HIDE);
469             registrySettings.ShowTextTool = FALSE;
470             break;
471 
472         case IDD_FONTSNAMES:
473             OnFontName(codeNotify);
474             break;
475 
476         case IDD_FONTSSIZES:
477             OnFontSize(codeNotify);
478             break;
479 
480         case IDM_BOLD:
481             registrySettings.Bold = bChecked;
482             toolsModel.NotifyToolChanged();
483             break;
484 
485         case IDM_ITALIC:
486             registrySettings.Italic = bChecked;
487             toolsModel.NotifyToolChanged();
488             break;
489 
490         case IDM_UNDERLINE:
491             registrySettings.Underline = bChecked;
492             toolsModel.NotifyToolChanged();
493             break;
494 
495         case IDM_VERTICAL:
496             // TODO:
497             break;
498     }
499     return 0;
500 }
501 
502 LRESULT CFontsDialog::OnNotify(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
503 {
504     NMHDR *pnmhdr = reinterpret_cast<NMHDR *>(lParam);
505     if (pnmhdr->code == TTN_NEEDTEXT)
506     {
507         LPTOOLTIPTEXT pToolTip = reinterpret_cast<LPTOOLTIPTEXT>(lParam);
508         pToolTip->hinst = hProgInstance;
509         switch (pnmhdr->idFrom)
510         {
511             case IDM_BOLD:      pToolTip->lpszText = MAKEINTRESOURCE(IDS_BOLD); break;
512             case IDM_ITALIC:    pToolTip->lpszText = MAKEINTRESOURCE(IDS_ITALIC); break;
513             case IDM_UNDERLINE: pToolTip->lpszText = MAKEINTRESOURCE(IDS_UNDERLINE); break;
514             case IDM_VERTICAL:  pToolTip->lpszText = MAKEINTRESOURCE(IDS_VERTICAL); break;
515 
516             default:
517                 break;
518         }
519     }
520     return 0;
521 }
522 
523 LRESULT CFontsDialog::OnMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
524 {
525     RECT rc;
526     GetWindowRect(&rc);
527     registrySettings.FontsPositionX = rc.left;
528     registrySettings.FontsPositionY = rc.top;
529     return 0;
530 }
531 
532 LRESULT CFontsDialog::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
533 {
534     if (wParam != TOOL_TEXT)
535         ShowWindow(SW_HIDE);
536 
537     return 0;
538 }
539 
540 LRESULT CFontsDialog::OnMeasureItem(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
541 {
542     if (wParam == IDD_FONTSNAMES)
543     {
544         LPMEASUREITEMSTRUCT pMeasureItem = reinterpret_cast<LPMEASUREITEMSTRUCT>(lParam);
545         RECT rc;
546         ::GetClientRect(GetDlgItem(IDD_FONTSNAMES), &rc);
547         pMeasureItem->itemWidth = rc.right - rc.left;
548         pMeasureItem->itemHeight = GetSystemMetrics(SM_CYVSCROLL);
549         return TRUE;
550     }
551     return 0;
552 }
553 
554 LRESULT CFontsDialog::OnDrawItem(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
555 {
556     // TODO: Owner-draw the font types
557     if (wParam == IDD_FONTSNAMES)
558     {
559         LPDRAWITEMSTRUCT pDrawItem = reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);
560         if (pDrawItem->itemID == (UINT)-1)
561             return TRUE;
562 
563         SetBkMode(pDrawItem->hDC, TRANSPARENT);
564 
565         HWND hwndItem = pDrawItem->hwndItem;
566         RECT rcItem = pDrawItem->rcItem;
567         if (pDrawItem->itemState & ODS_SELECTED)
568         {
569             FillRect(pDrawItem->hDC, &rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
570             SetTextColor(pDrawItem->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
571         }
572         else
573         {
574             FillRect(pDrawItem->hDC, &rcItem, GetSysColorBrush(COLOR_WINDOW));
575             SetTextColor(pDrawItem->hDC, GetSysColor(COLOR_WINDOWTEXT));
576         }
577 
578         TCHAR szText[LF_FACESIZE];
579         if ((UINT)ComboBox_GetLBTextLen(hwndItem, pDrawItem->itemID) < _countof(szText))
580         {
581             szText[0] = 0;
582             ComboBox_GetLBText(hwndItem, pDrawItem->itemID, szText);
583 
584             rcItem.left += 24;
585             DrawText(pDrawItem->hDC, szText, -1, &rcItem, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
586         }
587 
588         if (pDrawItem->itemState & ODS_FOCUS)
589             ::DrawFocusRect(pDrawItem->hDC, &pDrawItem->rcItem);
590 
591         return TRUE;
592     }
593     return 0;
594 }
595