1 // PreviewDialog.cpp : implementation file
5 #include "PreviewDialog.h"
7 #include "UIFontBuilder.h"
8 #include "FontGlyphCode.h"
13 static char THIS_FILE
[] = __FILE__
;
16 /////////////////////////////////////////////////////////////////////////////
17 // CPreviewDialog dialog
19 using Unicode::unicode_char_t
;
21 CPreviewDialog::CPreviewDialog(CWnd
* pParent
, const std::set
<unicode_char_t
> & idSet
, CFont
* font
, int fontSizePixels
)
22 : CDialog(CPreviewDialog::IDD
, pParent
)
24 //{{AFX_DATA_INIT(CPreviewDialog)
25 m_textInfoValue
= _T("");
26 m_textInfoExcludedValue
= _T("");
33 _snwprintf (buf
, 1023, _T("%d characters in range.\n"), m_idSet
.size ());
35 m_textInfoExcludedValue
= _T ("0 characters excluded.\n");
36 m_textInfoValue
= buf
;
39 m_fontSizePixels
= fontSizePixels
;
43 void CPreviewDialog::DoDataExchange(CDataExchange
* pDX
)
45 CDialog::DoDataExchange(pDX
);
46 //{{AFX_DATA_MAP(CPreviewDialog)
47 DDX_Control(pDX
, IDC_LIST_PREVIEW
, m_listPreview
);
48 DDX_Text(pDX
, IDC_TEXT_INFO
, m_textInfoValue
);
49 DDX_Text(pDX
, IDC_TEXT_INFO_EXCLUDED
, m_textInfoExcludedValue
);
54 BEGIN_MESSAGE_MAP(CPreviewDialog
, CDialog
)
55 //{{AFX_MSG_MAP(CPreviewDialog)
56 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_LIST_PREVIEW
, OnItemchangedListPreview
)
60 /////////////////////////////////////////////////////////////////////////////
61 // CPreviewDialog message handlers
63 BOOL
CPreviewDialog::OnInitDialog()
65 CDialog::OnInitDialog();
67 m_listPreview
.SetFont (m_font
);
69 m_listPreview
.InsertColumn (0, _T("Code"), LVCFMT_LEFT
, 100);
70 m_listPreview
.InsertColumn (1, _T("Sample"), LVCFMT_LEFT
, 100);
71 m_listPreview
.InsertColumn (2, _T("A"), LVCFMT_LEFT
, 100);
72 m_listPreview
.InsertColumn (3, _T("B"), LVCFMT_LEFT
, 100);
73 m_listPreview
.InsertColumn (4, _T("C"), LVCFMT_LEFT
, 100);
74 m_listPreview
.InsertColumn (5, _T("Glyph"), LVCFMT_LEFT
, 100);
78 TCHAR numbuf
[5] = {0,0,0,0,0};
82 ScreenDC
= (HDC
)(*myDC
);
87 m_font
->GetLogFont (&lfont
);
102 DEFAULT_PITCH
| FF_DONTCARE
,
105 myDC
->SelectObject(TheFont
);
109 for (std::set
<unicode_char_t
>::const_iterator iter
= m_idSet
.begin (); iter
!= m_idSet
.end (); ++iter
, ++i
)
113 _snwprintf (numbuf
, 4, _T ("%04x"), *iter
);
114 m_listPreview
.InsertItem (i
, numbuf
);
115 m_listPreview
.SetItemData (i
, *iter
);
117 m_listPreview
.SetItemText (i
, 1, buf
);
120 USHORT
const index
= GetTTUnicodeGlyphIndex(ScreenDC
, *iter
);
122 abcf
.abcfA
= abcf
.abcfB
= abcf
.abcfC
= -1;
125 if(!myDC
->GetCharABCWidths(*iter
, *iter
, &abcf
))
127 int err
= GetLastError();
129 _snwprintf(t
, 512, _T("%x\n"), err
);
130 OutputDebugString(t
);
134 _snwprintf (numbuf
, 4, _T ("%4.1f"), abcf
.abcfA
);
135 m_listPreview
.SetItemText(i
, 2, numbuf
);
136 _snwprintf (numbuf
, 4, _T ("%4.1f"), abcf
.abcfB
);
137 m_listPreview
.SetItemText(i
, 3, numbuf
);
138 _snwprintf (numbuf
, 4, _T ("%4.1f"), abcf
.abcfC
);
139 m_listPreview
.SetItemText(i
, 4, numbuf
);
140 _snwprintf (numbuf
, 4, _T ("%4d"), index
);
141 m_listPreview
.SetItemText(i
, 5, numbuf
);
144 // TODO: Add extra initialization here
146 return TRUE
; // return TRUE unless you set the focus to a control
147 // EXCEPTION: OCX Property Pages should return FALSE
150 //-----------------------------------------------------------------
152 const CPreviewDialog::ExclusionVector_t
& CPreviewDialog::getExclusionVector () const
154 return m_exclusionVector
;
158 void CPreviewDialog::OnOK()
160 // TODO: Add extra validation here
161 POSITION pos
= m_listPreview
.GetFirstSelectedItemPosition ();
165 int nItem
= m_listPreview
.GetNextSelectedItem (pos
);
166 m_exclusionVector
.push_back (static_cast<Unicode::unicode_char_t
>(m_listPreview
.GetItemData (nItem
)));
172 void CPreviewDialog::OnItemchangedListPreview(NMHDR
*, LRESULT
* pResult
)
175 //NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
177 // TODO: this gets called every type the selection changes, so we should really
178 // try to do the text field update less often!
180 size_t selcount
= m_listPreview
.GetSelectedCount ();
184 _snwprintf (buf
, 127, _T("%d characters excluded."), selcount
);
186 m_textInfoExcludedValue
= buf
;