1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //=================================================================
27 // SectionGeneralPage.cpp
29 // Memory Layout Tool section general property page class
31 //=================================================================
32 //#####DESCRIPTIONBEGIN####
34 // Author(s): John Dallaway
36 // Date: 1998/07/29 $RcsDate$ {or whatever}
37 // Version: 0.00+ $RcsVersion$ {or whatever}
38 // Purpose: Provides a derivation of the MFC CeCosPropertyPage class for
39 // general section property selection
40 // See also: SectionGeneralPage.h
41 // Known bugs: <UPDATE_ME_AT_RELEASE_TIME>
43 //####DESCRIPTIONEND####
46 #include "ConfigtoolDoc.h"
47 #include "SectionGeneralPage.h"
48 #include "ConfigTool.h"
57 static char THIS_FILE[] = __FILE__;
60 /////////////////////////////////////////////////////////////////////////////
61 // CSectionGeneralPage property page
63 IMPLEMENT_DYNCREATE(CSectionGeneralPage, CeCosPropertyPage)
65 CSectionGeneralPage::CSectionGeneralPage() : CeCosPropertyPage(CSectionGeneralPage::IDD)
67 //{{AFX_DATA_INIT(CSectionGeneralPage)
68 m_strFinalRelativeName = _T("");
69 m_strNameUser = _T("");
70 m_strNameLinker = _T("");
72 m_strFinalAddress = _T("");
73 m_strSectionSize = _T("");
75 m_bFinalAbsolute = TRUE;
78 CSectionGeneralPage::~CSectionGeneralPage()
82 void CSectionGeneralPage::DoDataExchange(CDataExchange* pDX)
84 CeCosPropertyPage::DoDataExchange(pDX);
85 //{{AFX_DATA_MAP(CSectionGeneralPage)
86 DDX_Control(pDX, IDC_SECTION_GENERAL_ALIGNMENT, m_cboAlignment);
87 DDX_Control(pDX, IDC_SECTION_GENERAL_NAME_USER, m_edtNameUser);
88 DDX_Control(pDX, IDC_SECTION_GENERAL_NAME_LINKER, m_cboNameLinker);
89 DDX_Control(pDX, IDC_SECTION_GENERAL_FINAL_ABSOLUTE_ADDRESS, m_edtFinalAddress);
90 DDX_Control(pDX, IDC_SECTION_GENERAL_FINAL_RELATIVE_NAME, m_cboFinalRelativeName);
91 DDX_Control(pDX, IDC_SECTION_GENERAL_KNOWN_SIZE, m_btnSectionSizeKnown);
92 DDX_Control(pDX, IDC_SECTION_GENERAL_SIZE, m_edtSectionSize);
93 DDX_Control(pDX, IDC_SECTION_GENERAL_FINAL_RELATIVE, m_btnFinalRelative);
94 DDX_Control(pDX, IDC_SECTION_GENERAL_FINAL_ABSOLUTE, m_btnFinalAbsolute);
95 DDX_Control(pDX, IDC_SECTION_GENERAL_NAME_LINKER_DEFINED, m_btnNameLinkerDefined);
96 DDX_Control(pDX, IDC_SECTION_GENERAL_NAME_USER_DEFINED, m_btnNameUserDefined);
97 DDX_CBString(pDX, IDC_SECTION_GENERAL_FINAL_RELATIVE_NAME, m_strFinalRelativeName);
98 DDX_Text(pDX, IDC_SECTION_GENERAL_NAME_USER, m_strNameUser);
99 DDX_CBString(pDX, IDC_SECTION_GENERAL_NAME_LINKER, m_strNameLinker);
100 DDX_CBIndex(pDX, IDC_SECTION_GENERAL_ALIGNMENT, m_nAlignment);
101 DDX_Text(pDX, IDC_SECTION_GENERAL_FINAL_ABSOLUTE_ADDRESS, m_strFinalAddress);
102 DDX_Text(pDX, IDC_SECTION_GENERAL_SIZE, m_strSectionSize);
107 BEGIN_MESSAGE_MAP(CSectionGeneralPage, CeCosPropertyPage)
108 //{{AFX_MSG_MAP(CSectionGeneralPage)
109 ON_BN_CLICKED(IDC_SECTION_GENERAL_KNOWN_SIZE, OnSectionSizeKnown)
110 ON_BN_CLICKED(IDC_SECTION_GENERAL_FINAL_RELATIVE, OnSectionGeneralFinalType)
111 ON_BN_CLICKED(IDC_SECTION_GENERAL_NAME_LINKER_DEFINED, OnSectionGeneralNameType)
112 ON_BN_CLICKED(IDC_SECTION_GENERAL_FINAL_ABSOLUTE, OnSectionGeneralFinalType)
113 ON_BN_CLICKED(IDC_SECTION_GENERAL_NAME_USER_DEFINED, OnSectionGeneralNameType)
117 /////////////////////////////////////////////////////////////////////////////
118 // CSectionGeneralPage message handlers
120 void CSectionGeneralPage::OnSectionSizeKnown()
122 // enable size edit box according to 'size known' check box
124 m_edtSectionSize.EnableWindow (m_btnSectionSizeKnown.GetCheck () && (! m_bNameLinkerDefined));
127 void CSectionGeneralPage::OnSectionGeneralFinalType()
129 // enable/disable dialog controls according to absolute/relative radio button state
131 m_bFinalAbsolute = m_btnFinalAbsolute.GetCheck();
133 m_edtFinalAddress.EnableWindow (m_bFinalAbsolute);
134 m_cboFinalRelativeName.EnableWindow (! m_bFinalAbsolute);
135 // m_cboFinalRelativeVMA.EnableWindow (! m_bFinalAbsolute); FIXME disabled for now (remove ?)
136 if (m_cboAlignment.IsWindowEnabled () && m_bFinalAbsolute)
137 m_cboAlignment.SetCurSel (0); // reset to 1 byte alignment
138 m_cboAlignment.EnableWindow (! m_bFinalAbsolute);
141 BOOL CSectionGeneralPage::OnInitDialog()
144 CeCosPropertyPage::OnInitDialog();
146 mem_map * lpMemoryMap = & CConfigTool::GetConfigToolDoc()->MemoryMap;
148 // copy current and unused section names into the linker-defined section names combo box
150 for (list <string>::iterator name = lpMemoryMap->linker_defined_section_list.begin (); name != lpMemoryMap->linker_defined_section_list.end (); ++name)
151 if (! lpMemoryMap->section_exists (name->c_str ()) || // section name is unused
152 (m_bNameLinkerDefined && (m_strNameLinker == name->c_str ()))) // or section name is that of the current section
153 m_cboNameLinker.AddString (CString(name->c_str ()));
155 // select the initial name in the combo box
157 if (m_bNameLinkerDefined && (m_strNameLinker != _T(""))) // the current selection is linker defined
158 m_cboNameLinker.SetCurSel (m_cboNameLinker.FindString (-1, m_strNameLinker));
159 else if (m_cboNameLinker.GetCount () > 0) // there are names in the combo box
160 m_cboNameLinker.SetCurSel (0); // select the first name
161 else // there are no names in the combo
162 m_btnNameLinkerDefined.EnableWindow (FALSE); // disable the linker-defined section radio button
164 // select the initial section name type radio button
166 if ((! m_bNameLinkerDefined) || (m_cboNameLinker.GetCount () == 0))
168 m_btnNameUserDefined.SetCheck (1); // user-defined section
169 if (m_bNameLinkerDefined)
170 m_dwSectionSize = 0; // default section size for new sections
171 m_btnSectionSizeKnown.SetCheck (m_dwSectionSize > 0); // of known size
174 m_btnNameLinkerDefined.SetCheck (1); // linker-defined section
176 OnSectionGeneralNameType (); // refresh the state of other controls
178 // copy section names into the relative name combo box
180 for (list <mem_section>::iterator section = lpMemoryMap->section_list.begin (); section != lpMemoryMap->section_list.end (); ++section)
181 if ((((section->size !=0) || (section->linker_defined)) && // eliminate user-defined sections of unknown size
182 ((m_bNameLinkerDefined && (m_strNameLinker == _T(""))) || // if not a new section
183 ((section->final_location->following_section == NULL) && // eliminate sections with used anchors
184 ((section->relocates) || (section->initial_location->following_section == NULL)))) && // eliminate sections already used as final anchors unless a new section
185 (section->name.c_str () != m_strNameLinker) && // eliminate the current section
186 (section->name.c_str () != m_strNameUser)) || // eliminate the current section
187 ((!m_bFinalAbsolute) && (m_strFinalRelativeName == section->name.c_str()))) // or section name is the current final relative name
188 m_cboFinalRelativeName.AddString (CString(section->name.c_str ()));
190 // select the initial name in the combo box
192 if ((! m_bFinalAbsolute) && (m_strFinalRelativeName != _T("")))
193 m_cboFinalRelativeName.SetCurSel (m_cboFinalRelativeName.FindString (-1, m_strFinalRelativeName));
194 else if (m_cboFinalRelativeName.GetCount () > 0) // there are names in the combo box
195 m_cboFinalRelativeName.SetCurSel (0); // select the first name
197 m_btnFinalRelative.EnableWindow (FALSE); // disable the relative type radio button
199 // select the initial final location type radio button
201 if (m_bFinalAbsolute)
202 m_btnFinalAbsolute.SetCheck (1);
204 m_btnFinalRelative.SetCheck (1);
206 OnSectionGeneralFinalType (); // refresh the state of the other controls
208 return TRUE; // return TRUE unless you set the focus to a control
209 // EXCEPTION: OCX Property Pages should return FALSE
212 void CSectionGeneralPage::OnSectionGeneralNameType()
214 // enable/disable dialog controls according to linker/user defined radio button state
216 m_bNameLinkerDefined = m_btnNameLinkerDefined.GetCheck ();
218 m_cboNameLinker.EnableWindow (m_bNameLinkerDefined);
219 m_edtNameUser.EnableWindow (! m_bNameLinkerDefined);
220 m_btnSectionSizeKnown.EnableWindow (! m_bNameLinkerDefined);
221 OnSectionSizeKnown (); // update state of section size edit box
224 BOOL CSectionGeneralPage::OnKillActive()
227 if (! UpdateData (TRUE))
230 if (! m_bNameLinkerDefined)
232 if ((m_strNameUser == _T("")) || (m_strNameUser.FindOneOf (LD_ILLEGAL_CHARS) != -1))
234 AfxMessageBox (IDS_VALIDATE_SECTION_NAME);
235 m_edtNameUser.SetFocus ();
239 mem_map * lpMemoryMap = & CConfigTool::GetConfigToolDoc()->MemoryMap;
240 for (list <string>::iterator name = lpMemoryMap->linker_defined_section_list.begin (); name != lpMemoryMap->linker_defined_section_list.end (); ++name)
241 if (m_strNameUser == name->c_str ()) // the user-defined name clashes with a linker-defined name
243 AfxMessageBox (IDS_VALIDATE_SECTION_NAME_CLASH);
244 m_edtNameUser.SetFocus ();
245 m_edtNameUser.SetSel (0, -1); // select all text
250 // convert address and alignment information to a DWORD representation
252 CString strAlignment;
253 m_cboAlignment.GetLBText (m_nAlignment, strAlignment);
254 _stscanf (strAlignment, _T("%lx"), &m_dwAlignment);
256 if (m_bFinalAbsolute)
259 if (_stscanf (m_strFinalAddress, _T("%lx%1s"), &m_dwFinalAddress, lpszDummy) != 1)
261 AfxMessageBox (IDS_VALIDATE_SECTION_START_ADDRESS);
262 m_edtFinalAddress.SetFocus ();
263 m_edtFinalAddress.SetSel (0, -1); // select all text
268 // convert section size to a DWORD representation
270 if ((! m_bNameLinkerDefined) && m_btnSectionSizeKnown.GetCheck ())
273 if (_stscanf (m_strSectionSize, _T("%lx%1s"), &m_dwSectionSize, lpszDummy) != 1)
275 AfxMessageBox (IDS_VALIDATE_SECTION_SIZE);
276 m_edtSectionSize.SetFocus ();
277 m_edtSectionSize.SetSel (0, -1); // select all text
284 return CeCosPropertyPage::OnKillActive();
288 BOOL CSectionGeneralPage::OnSetActive()
290 // generate hex strings for display
292 if ((m_bNameLinkerDefined && (m_strNameLinker == _T(""))) ||
293 ((! m_bNameLinkerDefined) && (m_strNameUser == _T("")))) // a new section
295 m_strFinalAddress = _T("");
296 m_strSectionSize = _T("");
298 else if (m_bFinalAbsolute)
299 m_strFinalAddress.Format (_T("%08lX"), m_dwFinalAddress);
301 if (m_bNameLinkerDefined || (m_dwSectionSize == 0))
302 m_strSectionSize == _T("");
304 m_strSectionSize.Format (_T("%lX"), m_dwSectionSize);
306 if (m_bFinalAbsolute)
310 CString strAlignment;
311 strAlignment.Format (_T("%08lX"), m_dwAlignment);
312 m_nAlignment = m_cboAlignment.FindString (-1, strAlignment);
315 if (! UpdateData (FALSE))
318 return CeCosPropertyPage::OnSetActive();