0023821: Improve qmake project files for Qt samples
[occt.git] / samples / mfc / standard / 08_HLR / src / Properties / FontPropertyPage.cpp
CommitLineData
7fd59977 1// FontPropertyPage.cpp : implementation file
2//
3
4#include "stdafx.h"
5
6#include "FontPropertyPage.h"
7
8#include "HLRApp.h"
9#include "Aspect_FontMapEntry.hxx"
10
11#ifdef _DEBUG
12//#define new DEBUG_NEW
13#undef THIS_FILE
14static char THIS_FILE[] = __FILE__;
15#endif
16
17/////////////////////////////////////////////////////////////////////////////
18// CFontPropertyPage property page
19
20IMPLEMENT_DYNCREATE(CFontPropertyPage, CPropertyPage)
21
22CFontPropertyPage::CFontPropertyPage() : CPropertyPage(CFontPropertyPage::IDD)
23{
24 //{{AFX_DATA_INIT(CFontPropertyPage)
25 m_FontMapSize = _T("Computing...");
26 m_CurrentEntryValue = _T("Computing...");
27 m_CurrentEntryStyle = _T("Computing...");
28 m_CurrentEntrySize = _T("Computing...");
29 m_CurrentEntrySlant = _T("Computing...");
30 m_NewEntryValue = _T("");
31 m_NewEntrySize = 1.0;
32 m_NewEntrySlant = 0.0;
33 //}}AFX_DATA_INIT
34}
35
36CFontPropertyPage::~CFontPropertyPage()
37{
38}
39
40BOOL CFontPropertyPage::OnInitDialog()
41{
42 CPropertyPage::OnInitDialog();
43
44 m_NewEntry_Type.AddString("DEFAULT");
45 m_NewEntry_Type.AddString("COURIER");
46 m_NewEntry_Type.AddString("HELVETICA");
47 m_NewEntry_Type.AddString("TIMES");
48 m_NewEntry_Type.AddString("USERDEFINED");
49 m_NewEntry_Type.SetCurSel(1);
50
51 // TODO: Add extra initialization here
52 UpdateDisplay(1);
53
54 return TRUE; // return TRUE unless you set the focus to a control
55 // EXCEPTION: OCX Property Pages should return FALSE
56}
57
58
59void CFontPropertyPage::DoDataExchange(CDataExchange* pDX)
60{
61 CPropertyPage::DoDataExchange(pDX);
62 //{{AFX_DATA_MAP(CFontPropertyPage)
63 DDX_Text (pDX, IDC_FontMap_STATIC_Size , m_FontMapSize );
64 DDX_Control(pDX, IDC_FontMap_TAB , m_TabCtrl );
65 DDX_Text (pDX, IDC_FontMap_STATIC_CurrentEntryValue , m_CurrentEntryValue );
66 DDX_Text (pDX, IDC_FontMap_STATIC_CurrentEntryType , m_CurrentEntryStyle );
67 DDX_Text (pDX, IDC_FontMap_STATIC_CurrentEntrySize , m_CurrentEntrySize );
68 DDX_Text (pDX, IDC_FontMap_STATIC_CurrentEntrySlant , m_CurrentEntrySlant );
69
70 DDX_Control(pDX, IDC_FontMap_COMBO_NewEntryType , m_NewEntry_Type );
71 DDX_Text(pDX, IDC_FontMap_EDIT_NewEntryValue, m_NewEntryValue);
72 DDX_Text(pDX, IDC_FontMap_EDIT_NewEntrySize, m_NewEntrySize);
73 DDX_Text(pDX, IDC_FontMap_EDIT_NewEntrySlant, m_NewEntrySlant);
74 //}}AFX_DATA_MAP
75}
76
77
78BEGIN_MESSAGE_MAP(CFontPropertyPage, CPropertyPage)
79 //{{AFX_MSG_MAP(CFontPropertyPage)
80 ON_NOTIFY(TCN_SELCHANGE, IDC_FontMap_TAB, OnSelchangeFontMapTAB)
81 ON_BN_CLICKED(IDC_FontMap_BUTTON_NewEntry_EditFont, OnFontMapBUTTONNewEntryEditFont)
82 ON_BN_CLICKED(IDC_FontMap_BUTTON_UpdateCurrent, OnFontMapBUTTONUpdateCurrent)
83 ON_CBN_SELCHANGE(IDC_FontMap_COMBO_NewEntryType, OnSelchangeFontMapCOMBONewEntryType)
84 ON_BN_CLICKED(IDC_FontMap_BUTTON_NewEntry, OnFontMapBUTTONNewEntry)
85 //}}AFX_MSG_MAP
86END_MESSAGE_MAP()
87
88/////////////////////////////////////////////////////////////////////////////
89// CFontPropertyPage message handlers
90void CFontPropertyPage::UpdateDisplay(int CurrentSelectionIndex)
91{
92 // Update the size of the Width map
93 TCollection_AsciiString SizeMessage(myFontMap->Size());
94 m_FontMapSize = _T(SizeMessage.ToCString());
95
96 // clear the Tab Ctrl
97 m_TabCtrl.DeleteAllItems();
98 TC_ITEM TabCtrlItem;
99 TabCtrlItem.mask = TCIF_TEXT;
100 for(int i =1;i<=myFontMap->Size();i++)
101 {
102 Aspect_FontMapEntry aFontMapEntry = myFontMap->Entry(i);
103 TCollection_AsciiString EntryNumerMessage(aFontMapEntry.Index());
104 TabCtrlItem.pszText = (LPSTR) EntryNumerMessage.ToCString();
105 m_TabCtrl.InsertItem( aFontMapEntry.Index(), &TabCtrlItem );
106 }
107 m_TabCtrl.SetCurSel(CurrentSelectionIndex-1);
108 // update the current Entry informations
109 Aspect_FontMapEntry aFontMapEntry = myFontMap->Entry(CurrentSelectionIndex);
110
111 Aspect_FontStyle TheType = aFontMapEntry.Type();
112 m_CurrentEntryValue = (TheType.Value() == NULL?" ":TheType.Value());
113
114 TCollection_AsciiString Message;
115 switch (TheType.Style())
116 {
117 case Aspect_TOF_DEFAULT : Message = "Aspect_TOF_DEFAULT"; break;
118 case Aspect_TOF_COURIER : Message = "Aspect_TOF_COURIER"; break;
119 case Aspect_TOF_HELVETICA : Message = "Aspect_TOF_HELVETICA"; break;
120 case Aspect_TOF_TIMES : Message = "Aspect_TOF_TIMES"; break;
121 case Aspect_TOF_USERDEFINED : Message = "Aspect_TOF_USERDEFINED"; break;
122 default: Message = "Underknown";
123 }
124 m_CurrentEntryStyle = _T(Message.ToCString());
125
126 Message = TheType.Size ();
127 m_CurrentEntrySize = _T(Message.ToCString());
128
129 Message = TheType.Slant ();
130 m_CurrentEntrySlant = _T(Message.ToCString());
131
132 // update The New Entry :
133 switch (TheType.Style())
134 {
135 case Aspect_TOF_DEFAULT : m_NewEntry_Type.SetCurSel(0); break;
136 case Aspect_TOF_COURIER : m_NewEntry_Type.SetCurSel(1); break;
137 case Aspect_TOF_HELVETICA : m_NewEntry_Type.SetCurSel(2); break;
138 case Aspect_TOF_TIMES : m_NewEntry_Type.SetCurSel(3); break;
139 case Aspect_TOF_USERDEFINED : m_NewEntry_Type.SetCurSel(4); break;
140 default: ;
141 }
142
143 m_NewEntryValue = (TheType.Value() == NULL?" ":TheType.Value());
144 m_NewEntrySize = TheType.Size ();
145 m_NewEntrySlant = TheType.Slant ();
146 if (TheType.Style()==Aspect_TOF_USERDEFINED)
147 {
148 GetDlgItem(IDC_FontMap_EDIT_NewEntrySize)->ShowWindow(SW_HIDE);
149 GetDlgItem(IDC_FontMap_EDIT_NewEntrySlant)->ShowWindow(SW_HIDE);
150 GetDlgItem(IDC_FontMap_BUTTON_NewEntry_EditFont)->ShowWindow(SW_SHOW);
151 }
152 else
153 {
154 GetDlgItem(IDC_FontMap_EDIT_NewEntrySize)->ShowWindow(SW_SHOW);
155 GetDlgItem(IDC_FontMap_EDIT_NewEntrySlant)->ShowWindow(SW_SHOW);
156 GetDlgItem(IDC_FontMap_BUTTON_NewEntry_EditFont)->ShowWindow(SW_HIDE);
157 }
158 UpdateData(false);
159}
160
161void CFontPropertyPage::OnSelchangeFontMapTAB(NMHDR* pNMHDR, LRESULT* pResult)
162{
163 // TODO: Add your control notification handler code here
164 UpdateDisplay( m_TabCtrl.GetCurSel()+1);
165 *pResult = 0;
166}
167
168void CFontPropertyPage::OnSelchangeFontMapCOMBONewEntryType()
169{
170 UpdateData(true);
171 // update the New Entry Value message
172 if (m_NewEntry_Type.GetCurSel() == Aspect_TOF_USERDEFINED)
173 {
174 // allow the user to select a font from the common CFontDialog
175 GetDlgItem(IDC_FontMap_BUTTON_NewEntry_EditFont)->ShowWindow(SW_SHOW);
176 m_NewEntryValue = "Please Select a Font";
177 // remove the posiblility to update while a font was selected
178 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_HIDE);
179 GetDlgItem(IDC_FontMap_BUTTON_NewEntry)->ShowWindow(SW_HIDE);
180 GetDlgItem(IDC_FontMap_EDIT_NewEntrySize)->ShowWindow(SW_HIDE);
181 GetDlgItem(IDC_FontMap_EDIT_NewEntrySlant)->ShowWindow(SW_HIDE);
182 }
183 else
184 {
185 GetDlgItem(IDC_FontMap_EDIT_NewEntrySize)->ShowWindow(SW_SHOW);
186 GetDlgItem(IDC_FontMap_EDIT_NewEntrySlant)->ShowWindow(SW_SHOW);
187 GetDlgItem(IDC_FontMap_BUTTON_NewEntry_EditFont)->ShowWindow(SW_HIDE);
188 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_SHOW);
189 GetDlgItem(IDC_FontMap_BUTTON_NewEntry)->ShowWindow(SW_SHOW);
190 Aspect_FontStyle TheType((Aspect_TypeOfFont)m_NewEntry_Type.GetCurSel(),m_NewEntrySize);
191 m_NewEntryValue = (TheType.Value() == NULL?" ":TheType.Value());
192 }
193 UpdateData(false);
194
195}
196
197#include "WNT_FontMapEntry.hxx"
198void CFontPropertyPage::OnFontMapBUTTONNewEntryEditFont()
199{
200 Handle(WNT_FontMapEntry) anEntry = new WNT_FontMapEntry((char* const)(LPCTSTR )m_NewEntryValue);
201 Standard_Address anAddress = anEntry->LogFont();
202 LOGFONT* lf = (LOGFONT*)(anAddress );
203 CFontDialog dlg(lf);
204 if (dlg.DoModal() == IDOK)
205 {
206 TCHAR buff[ 255 ];
207 wsprintf ( buff, "%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%d-%s",
208 lf->lfHeight, lf->lfWidth, lf->lfEscapement, lf->lfOrientation, lf->lfWeight, lf->lfItalic,
209 lf->lfUnderline, lf->lfStrikeOut, lf->lfCharSet, lf->lfOutPrecision, lf->lfClipPrecision, lf->lfQuality,
210 lf->lfPitchAndFamily, lf->lfFaceName);
211
212 GetDlgItem(IDC_FontMap_BUTTON_UpdateCurrent)->ShowWindow(SW_SHOW);
213 GetDlgItem(IDC_FontMap_BUTTON_NewEntry)->ShowWindow(SW_SHOW);
214 Aspect_FontStyle TheType(buff);
215 m_NewEntryValue = (TheType.Value() == NULL?" ":TheType.Value());
216 }
217 UpdateData(false);
218}
219
220void CFontPropertyPage::OnFontMapBUTTONUpdateCurrent()
221{
222 // The Entry to modify :
223 Aspect_FontMapEntry aFontMapEntry = myFontMap->Entry( m_TabCtrl.GetCurSel()+1);
224
225 UpdateData(true);
226 Aspect_TypeOfFont aTypeOfFont = (Aspect_TypeOfFont)m_NewEntry_Type.GetCurSel();
227
228 if (aTypeOfFont == Aspect_TOF_USERDEFINED)
229 {
230 Aspect_FontStyle TheType((Standard_CString)(LPCTSTR )m_NewEntryValue);
231 aFontMapEntry.SetType(TheType);
232 }
233 else
234 {
235 Aspect_FontStyle TheType((Aspect_TypeOfFont)m_NewEntry_Type.GetCurSel(),m_NewEntrySize,m_NewEntrySlant);
236 aFontMapEntry.SetType(TheType);
237 }
238 myFontMap->AddEntry(aFontMapEntry); // in fact just update
239 SetModified(true);
240 UpdateDisplay(m_TabCtrl.GetCurSel()+1);
241 UpdateData(false);
242}
243
244
245void CFontPropertyPage::OnFontMapBUTTONNewEntry()
246{
247 // The Entry to modify :
248 Aspect_FontMapEntry aFontMapEntry;
249
250 UpdateData(true);
251 Aspect_TypeOfFont aTypeOfFont = (Aspect_TypeOfFont)m_NewEntry_Type.GetCurSel();
252
253 if (aTypeOfFont == Aspect_TOF_USERDEFINED)
254 {
255 Aspect_FontStyle TheType((Standard_CString)(LPCTSTR )m_NewEntryValue);
256 aFontMapEntry.SetType(TheType);
257 }
258 else
259 {
260 Aspect_FontStyle TheType((Aspect_TypeOfFont)m_NewEntry_Type.GetCurSel(),m_NewEntrySize,m_NewEntrySlant);
261 aFontMapEntry.SetType(TheType);
262 }
263 myFontMap->AddEntry(aFontMapEntry); // in fact just update
264 SetModified(true);
265 UpdateDisplay(m_TabCtrl.GetCurSel()+1);
266 UpdateData(false);
267}
268
269BOOL CFontPropertyPage::OnApply()
270{
271 myViewer->SetFontMap(myFontMap);
272 myViewer->Update();
273
274 return CPropertyPage::OnApply();
275}