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