summaryrefslogtreecommitdiffabout
path: root/FontsPage.cpp
authorMichael Krelin <hacker@klever.net>2004-07-05 01:53:09 (UTC)
committer Michael Krelin <hacker@klever.net>2004-07-05 01:53:09 (UTC)
commit955d4e00adc9f39ab93bf21f07506eb75b013c70 (patch) (unidiff)
tree92493a2c9ac206b822e24a9e5a6f6b1589be6afb /FontsPage.cpp
downloadT42-955d4e00adc9f39ab93bf21f07506eb75b013c70.zip
T42-955d4e00adc9f39ab93bf21f07506eb75b013c70.tar.gz
T42-955d4e00adc9f39ab93bf21f07506eb75b013c70.tar.bz2
initial commit into svn repository
git-svn-id: http://svn.klever.net/kin/T42/trunk@1 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'FontsPage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--FontsPage.cpp333
1 files changed, 333 insertions, 0 deletions
diff --git a/FontsPage.cpp b/FontsPage.cpp
new file mode 100644
index 0000000..772f962
--- a/dev/null
+++ b/FontsPage.cpp
@@ -0,0 +1,333 @@
1// FontsPage.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "T42.h"
6#include "FontsPage.h"
7
8#ifdef _DEBUG
9#define new DEBUG_NEW
10#undef THIS_FILE
11static char THIS_FILE[] = __FILE__;
12#endif
13
14/////////////////////////////////////////////////////////////////////////////
15// CFontsPage property page
16
17IMPLEMENT_DYNCREATE(CFontsPage, CPropertyPage)
18
19CFontsPage::CFontsPage() : CPropertyPage(CFontsPage::IDD)
20{
21 //{{AFX_DATA_INIT(CFontsPage)
22 //}}AFX_DATA_INIT
23CRichEditCtrl tmp;
24 tmp.Create(WS_CHILD,CRect(0,0,0,0),AfxGetApp()->m_pMainWnd,0);
25 memset(&m_fmtChar,0,sizeof(m_fmtChar));
26 m_fmtLast=NULL;
27}
28
29CFontsPage::~CFontsPage()
30{
31}
32
33void CFontsPage::DoDataExchange(CDataExchange* pDX)
34{
35 CPropertyPage::DoDataExchange(pDX);
36 //{{AFX_DATA_MAP(CFontsPage)
37 DDX_Control(pDX, IDC_TIP, m_TipCtl);
38 DDX_Control(pDX, IDC_FORECOLOR, m_fgColorCtl);
39 DDX_Control(pDX, IDC_BACKCOLOR, m_bgColorCtl);
40 DDX_Control(pDX, IDC_CHARSET, m_CharsetCtl);
41 DDX_Control(pDX, IDC_UNDERLINE, m_UnderlineCtl);
42 DDX_Control(pDX, IDC_STRIKEOUT, m_StrikeoutCtl);
43 DDX_Control(pDX, IDC_ITALIC, m_ItalicCtl);
44 DDX_Control(pDX, IDC_BOLD, m_BoldCtl);
45 DDX_Control(pDX, IDC_FONTSIZE, m_SizeCtl);
46 DDX_Control(pDX, IDC_FORMATNAME, m_FormatsCtl);
47 DDX_Control(pDX, IDC_FACES, m_FacesCtl);
48 DDX_Control(pDX, IDC_SAMPLE, m_SampleCtl);
49 //}}AFX_DATA_MAP
50}
51
52
53BEGIN_MESSAGE_MAP(CFontsPage, CPropertyPage)
54 //{{AFX_MSG_MAP(CFontsPage)
55 ON_CBN_SELENDOK(IDC_FACES, OnSelendokFaces)
56 ON_BN_CLICKED(IDC_BOLD, OnBold)
57 ON_CBN_SELENDOK(IDC_FONTSIZE, OnSelendokFontsize)
58 ON_CBN_EDITCHANGE(IDC_FONTSIZE, OnEditchangeFontsize)
59 ON_BN_CLICKED(IDC_ITALIC, OnItalic)
60 ON_BN_CLICKED(IDC_STRIKEOUT, OnStrikeout)
61 ON_BN_CLICKED(IDC_UNDERLINE, OnUnderline)
62 ON_CBN_SELENDOK(IDC_CHARSET, OnSelendokCharset)
63 ON_BN_CLICKED(IDC_BACKCOLOR, OnBackcolor)
64 ON_BN_CLICKED(IDC_FORECOLOR, OnForecolor)
65 ON_LBN_SELCHANGE(IDC_FORMATNAME, OnSelchangeFormatname)
66 //}}AFX_MSG_MAP
67END_MESSAGE_MAP()
68
69/////////////////////////////////////////////////////////////////////////////
70// CFontsPage message handlers
71
72BOOL CFontsPage::OnInitDialog()
73{
74 CPropertyPage::OnInitDialog();
75
76 m_SampleCtl.GetDefaultCharFormat(m_fmtDefChar);
77
78 // Fill in faces combo
79 m_FacesCtl.ResetContent();
80CClientDC dc(NULL);
81LOGFONT lf;
82 memset(&lf,0,sizeof(lf));
83 lf.lfCharSet = DEFAULT_CHARSET;
84 EnumFontFamiliesEx(dc.m_hDC,&lf,(FONTENUMPROC)FillInFaces,(LPARAM)&m_FacesCtl,0);
85
86 // Fill in formats list
87 FillInFormats();
88
89 return TRUE; // return TRUE unless you set the focus to a control
90 // EXCEPTION: OCX Property Pages should return FALSE
91}
92
93int CALLBACK CFontsPage::FillInFaces(const ENUMLOGFONTEX* lpelfe,const TEXTMETRIC* lpntme,const int FontType,const LPARAM lParam)
94{
95 //if(FontType!=TRUETYPE_FONTTYPE)
96 // return 1;
97CComboBox* cb = (CComboBox*)lParam;
98 ASSERT(cb);
99 if(cb->FindString(0,lpelfe->elfLogFont.lfFaceName)>=0)
100 return 1;
101 cb->AddString(lpelfe->elfLogFont.lfFaceName);
102 return 1;
103}
104
105
106void CFontsPage::UpdateFormat(BOOL bSave)
107{
108 if(bSave){
109 CString tmp;
110 m_FacesCtl.GetWindowText(tmp);
111 strcpy(m_fmtChar.szFaceName,tmp); m_fmtChar.dwMask|=CFM_FACE;
112 m_SizeCtl.GetWindowText(tmp);
113 m_fmtChar.yHeight = atoi(tmp)?(atoi(tmp)*REFS2PTS):m_fmtChar.yHeight;
114 m_fmtChar.dwMask|=CFM_SIZE;
115 if(m_BoldCtl.GetCheck())
116 m_fmtChar.dwEffects|=CFE_BOLD;
117 else
118 m_fmtChar.dwEffects&=~CFE_BOLD;
119 m_fmtChar.dwMask|=CFM_BOLD;
120 if(m_ItalicCtl.GetCheck())
121 m_fmtChar.dwEffects|=CFE_ITALIC;
122 else
123 m_fmtChar.dwEffects&=~CFE_ITALIC;
124 m_fmtChar.dwMask|=CFM_ITALIC;
125 if(m_StrikeoutCtl.GetCheck())
126 m_fmtChar.dwEffects|=CFE_STRIKEOUT;
127 else
128 m_fmtChar.dwEffects&=~CFE_STRIKEOUT;
129 m_fmtChar.dwMask|=CFM_STRIKEOUT;
130 if(m_UnderlineCtl.GetCheck())
131 m_fmtChar.dwEffects|=CFE_UNDERLINE;
132 else
133 m_fmtChar.dwEffects&=~CFE_UNDERLINE;
134 m_fmtChar.dwMask|=CFM_UNDERLINE;
135 if(m_CharsetCtl.IsWindowEnabled())
136 m_fmtChar.bCharSet=m_CharsetCtl.GetItemData(m_CharsetCtl.GetCurSel());
137 else
138 m_fmtChar.bCharSet=DEFAULT_CHARSET;
139 m_fmtChar.crTextColor = m_fgColorCtl.m_Color;
140 m_fmtChar.dwMask|=CFM_COLOR;
141 m_fmtChar.dwEffects&=~CFE_AUTOCOLOR;
142 UpdateSample();
143 }else{
144 if(m_fmtChar.cbSize!=sizeof(m_fmtChar))
145 memmove(&m_fmtChar,&m_fmtDefChar,sizeof(m_fmtChar));
146 if(m_fmtChar.dwMask&CFM_FACE)
147 m_FacesCtl.SelectString(0,m_fmtChar.szFaceName);
148 CString tmp;
149 if(m_fmtChar.dwMask&CFM_SIZE){
150 tmp.Format("%d",m_fmtChar.yHeight/REFS2PTS);
151 m_SizeCtl.SetWindowText(tmp);
152 }
153 if(m_fmtChar.dwMask&CFM_BOLD)
154 m_BoldCtl.SetCheck((m_fmtChar.dwEffects&CFE_BOLD)?1:0);
155 if(m_fmtChar.dwMask&CFM_ITALIC)
156 m_ItalicCtl.SetCheck((m_fmtChar.dwEffects&CFE_ITALIC)?1:0);
157 if(m_fmtChar.dwMask&CFM_STRIKEOUT)
158 m_StrikeoutCtl.SetCheck((m_fmtChar.dwEffects&CFE_STRIKEOUT)?1:0);
159 if(m_fmtChar.dwMask&CFM_UNDERLINE)
160 m_UnderlineCtl.SetCheck((m_fmtChar.dwEffects&CFE_UNDERLINE)?1:0);
161 m_fgColorCtl.m_Color = (m_fmtChar.dwMask&CFM_COLOR)?m_fmtChar.crTextColor:0;
162 m_fgColorCtl.Invalidate();
163 FillCharsets();
164 }
165}
166
167void CFontsPage::UpdateSample()
168{
169 m_SampleCtl.SetReadOnly(TRUE);
170 m_SampleCtl.SetTargetDevice(NULL,0);
171 m_SampleCtl.SetSel(0,-1);
172 m_SampleCtl.ReplaceSel(
173 (m_fmtChar.dwMask&CFM_FACE)
174 ? (
175 (*m_fmtChar.szFaceName)
176 ? m_fmtChar.szFaceName
177 : "Sample"
178 )
179 : "Sample"
180 );
181 m_SampleCtl.SetSel(0,-1);
182 m_SampleCtl.SetSelectionCharFormat(m_fmtChar);
183PARAFORMAT pf;
184 memset(&pf,0,sizeof(pf));
185 pf.cbSize = sizeof(pf);
186 pf.dwMask = PFM_ALIGNMENT;
187 pf.wAlignment = PFA_CENTER;
188 m_SampleCtl.SetParaFormat(pf);
189 m_SampleCtl.HideSelection(TRUE,TRUE);
190 if(m_bgColorCtl.IsWindowEnabled())
191 m_SampleCtl.SetBackgroundColor(FALSE,m_bgColorCtl.m_Color);
192}
193
194void CFontsPage::OnSelendokFaces()
195{
196 UpdateFormat(TRUE);
197 FillCharsets();
198}
199
200void CFontsPage::OnSelendokFontsize()
201{
202CString tmp;
203 m_SizeCtl.GetLBText(m_SizeCtl.GetCurSel(),tmp);
204 m_SizeCtl.SetWindowText(tmp);
205 UpdateFormat(TRUE);
206}
207void CFontsPage::OnEditchangeFontsize()
208{
209 UpdateFormat(TRUE);
210}
211
212void CFontsPage::OnBold()
213{
214 UpdateFormat(TRUE);
215}
216void CFontsPage::OnItalic()
217{
218 UpdateFormat(TRUE);
219}
220void CFontsPage::OnStrikeout()
221{
222 UpdateFormat(TRUE);
223}
224void CFontsPage::OnUnderline()
225{
226 UpdateFormat(TRUE);
227}
228
229void CFontsPage::FillCharsets()
230{
231 m_CharsetCtl.EnableWindow(TRUE);
232 m_CharsetCtl.ResetContent();
233CString tmp;
234 tmp.LoadString(IDS_CHARSET_AUTO);
235 VERIFY(m_CharsetCtl.AddString(tmp)==0);
236 VERIFY(m_CharsetCtl.SetItemData(0,DEFAULT_CHARSET)!=LB_ERR);
237 if(m_fmtChar.dwMask&CFM_FACE && *m_fmtChar.szFaceName){
238 CClientDC dc(NULL);
239 LOGFONT lf;
240 memset(&lf,0,sizeof(lf));
241 lf.lfCharSet = DEFAULT_CHARSET;
242 strcpy(lf.lfFaceName,m_fmtChar.szFaceName);
243 EnumFontFamiliesEx(dc.m_hDC,&lf,(FONTENUMPROC)FillInCharsets,(LPARAM)&m_CharsetCtl,0);
244 }
245int ii = m_CharsetCtl.GetCount();
246 for(int i=0;i<ii;i++){
247 if(m_CharsetCtl.GetItemData(i)==m_fmtChar.bCharSet){
248 m_CharsetCtl.SetCurSel(i);
249 break;
250 }
251 }
252 m_CharsetCtl.EnableWindow(m_CharsetCtl.GetCount()>1);
253}
254
255int CALLBACK CFontsPage::FillInCharsets(const ENUMLOGFONTEX* lpelfe,const TEXTMETRIC* lpntme,const int FontType,const LPARAM lParam)
256{
257 //if(FontType!=TRUETYPE_FONTTYPE)
258 // return 1;
259CComboBox* cb = (CComboBox*)lParam;
260 ASSERT(cb);
261 if(cb->FindString(0,(char*)lpelfe->elfScript)>=0)
262 return 1;
263int i = cb->AddString((char*)lpelfe->elfScript);
264 ASSERT(i>=0);
265 VERIFY(cb->SetItemData(i,lpelfe->elfLogFont.lfCharSet)!=LB_ERR);
266 return 1;
267}
268
269void CFontsPage::OnSelendokCharset()
270{
271 UpdateFormat(TRUE);
272}
273
274void CFontsPage::FillInFormats()
275{
276 AddFmt(IDS_FMT_T42LOCAL,&m_fmtT42Local);
277 AddFmt(IDS_FMT_T42REMOTE,&m_fmtT42Remote);
278 AddFmt(IDS_FMT_T42SYSTEM,&m_fmtT42System,0);
279 m_FormatsCtl.SetCurSel(0);
280 OnSelchangeFormatname();
281}
282void CFontsPage::AddFmt(UINT name,CFontFormat* cf,UINT flags)
283{
284CString f;
285 VERIFY(f.LoadString(name));
286int lf = f.Find('\n');
287int i = m_FormatsCtl.AddString((lf<0)?f:f.Left(lf));
288 ASSERT(i>=0);
289 m_FormatsCtl.SetItemData(i,(LPARAM)cf);
290 cf->m_Tip = (lf<0)?"":f.Mid(lf+1);
291 cf->m_Flags = flags;
292}
293void CFontsPage::OnSelchangeFormatname()
294{
295CFontFormat* fmt = (CFontFormat*)m_FormatsCtl.GetItemData(m_FormatsCtl.GetCurSel());
296 if(m_fmtLast){
297 memmove(&m_fmtLast->m_fmtChar,&m_fmtChar,sizeof(m_fmtLast->m_fmtChar));
298 if(m_fmtLast->m_Flags&CFontFormat::flagBGColor)
299 m_fmtLast->m_bgColor = m_bgColorCtl.m_Color;
300 }
301BOOL bBG = fmt->m_Flags&CFontFormat::flagBGColor;
302 m_bgColorCtl.EnableWindow(bBG);
303 m_TipCtl.SetWindowText(fmt->m_Tip);
304 m_fmtLast = fmt;
305 memmove(&m_fmtChar,&m_fmtLast->m_fmtChar,sizeof(m_fmtChar));
306 if(bBG){
307 m_bgColorCtl.m_Color = m_fmtLast->m_bgColor;
308 m_bgColorCtl.Invalidate();
309 }
310 UpdateFormat(FALSE);
311 UpdateSample();
312}
313
314void CFontsPage::OnBackcolor()
315{
316 m_bgColorCtl.SetColor();
317 UpdateFormat(TRUE);
318}
319void CFontsPage::OnForecolor()
320{
321 m_fgColorCtl.SetColor();
322 UpdateFormat(TRUE);
323}
324
325void CFontsPage::OnOK()
326{
327 if(m_fmtLast){
328 memmove(&m_fmtLast->m_fmtChar,&m_fmtChar,sizeof(m_fmtLast->m_fmtChar));
329 if(m_fmtLast->m_Flags&CFontFormat::flagBGColor)
330 m_fmtLast->m_bgColor = m_bgColorCtl.m_Color;
331 }
332 CPropertyPage::OnOK();
333}