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 // CdlTemplatesDialog.cpp : implementation file
29 #include "Configtool.h"
30 #include "ConfigtoolDoc.h"
32 #include "CdlTemplatesDialog.h"
37 static char THIS_FILE[] = __FILE__;
40 /////////////////////////////////////////////////////////////////////////////
41 // CCdlTemplatesDialog dialog
44 CCdlTemplatesDialog::CCdlTemplatesDialog(CWnd* pParent /*=NULL*/)
45 : CeCosDialog(IDD, pParent)
47 //{{AFX_DATA_INIT(CCdlTemplatesDialog)
48 m_strCdlTemplateDescription = _T("");
49 m_strCdlTemplatePackages = _T("");
54 void CCdlTemplatesDialog::DoDataExchange(CDataExchange* pDX)
56 CeCosDialog::DoDataExchange(pDX);
57 //{{AFX_DATA_MAP(CCdlTemplatesDialog)
58 DDX_Control(pDX, IDC_CDL_TEMPLATE_PACKAGES, m_edtCdlTemplatePackages);
59 DDX_Control(pDX, IDC_CDL_TEMPLATE, m_cboCdlTemplate);
60 DDX_Control(pDX, IDC_CDL_TEMPLATE_VER, m_cboCdlTemplateVersion);
61 DDX_Control(pDX, IDC_CDL_HARDWARE, m_cboCdlHardware);
62 DDX_Text(pDX, IDC_CDL_HARDWARE_DESC, m_strCdlHardwareDescription);
63 DDX_Text(pDX, IDC_CDL_TEMPLATE_DESC, m_strCdlTemplateDescription);
64 DDX_Text(pDX, IDC_CDL_TEMPLATE_PACKAGES, m_strCdlTemplatePackages);
69 BEGIN_MESSAGE_MAP(CCdlTemplatesDialog, CeCosDialog)
70 //{{AFX_MSG_MAP(CCdlTemplatesDialog)
71 ON_CBN_SELCHANGE(IDC_CDL_HARDWARE, OnSelchangeCdlHardware)
72 ON_BN_CLICKED(IDC_DETAILS, OnDetails)
74 ON_CBN_SELCHANGE(IDC_CDL_TEMPLATE, OnSelchangeCdlTemplate)
75 ON_CBN_SELCHANGE(IDC_CDL_TEMPLATE_VER, OnSelchangeCdlTemplateVersion)
79 /////////////////////////////////////////////////////////////////////////////
80 // CCdlTemplatesDialog message handlers
82 BOOL CCdlTemplatesDialog::OnInitDialog()
84 CeCosDialog::OnInitDialog();
86 ShowDetails (false); // hide the details initially
88 CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
90 // populate the hardware combo box
91 m_hardware = pDoc->GetCdlConfig ()->get_hardware ();
92 const std::vector<std::string> & targets = pDoc->GetCdlPkgData ()->get_targets ();
93 std::vector<std::string>::const_iterator target_i;
94 for (target_i = targets.begin (); target_i != targets.end (); target_i++)
96 const std::vector<std::string> & aliases = pDoc->GetCdlPkgData ()->get_target_aliases (* target_i);
98 // use the first alias (if any) as the description
99 CString strTargetDescription = aliases.size () ? aliases [0].c_str () : target_i->c_str ();
100 int nIndex = m_cboCdlHardware.AddString (strTargetDescription);
101 m_cboCdlHardware.SetItemData (nIndex, (DWORD) target_i); // store the target iterator
102 if (m_hardware == * target_i) // if current target...
103 m_cboCdlHardware.SetCurSel (nIndex); // ...select the string
106 if (CB_ERR == m_cboCdlHardware.GetCurSel ()) // if no target selected...
107 m_cboCdlHardware.SetCurSel (0); // ...select the first one
109 // populate the template combo box
110 m_template = pDoc->GetCdlConfig ()->get_template ();
111 const std::vector<std::string> & templates = pDoc->GetCdlPkgData ()->get_templates ();
112 std::vector<std::string>::const_iterator template_i;
113 for (template_i = templates.begin (); template_i != templates.end (); template_i++)
115 CString strTemplateDescription = template_i->c_str ();
116 int nIndex = m_cboCdlTemplate.AddString (strTemplateDescription);
117 m_cboCdlTemplate.SetItemData (nIndex, (DWORD) template_i); // store the template iterator
118 if (m_template == * template_i) // if current template...
119 m_cboCdlTemplate.SetCurSel (nIndex); // ...select the string
122 if (CB_ERR == m_cboCdlTemplate.GetCurSel ()) // if no template selected...
123 m_cboCdlTemplate.SetCurSel (0); // ...select the first one
125 // display initial target and template descriptions
126 OnSelchangeCdlHardware ();
127 OnSelchangeCdlTemplate ();
129 // populate the template version combo box
130 UpdateVersionList (pDoc->GetTemplateVersion ());
132 return TRUE; // return TRUE unless you set the focus to a control
133 // EXCEPTION: OCX Property Pages should return FALSE
136 void CCdlTemplatesDialog::OnSelchangeCdlHardware()
138 CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
140 // the target has changed so retrieve the new target description
141 const int nIndex = m_cboCdlHardware.GetCurSel ();
142 m_hardware = * (std::vector<std::string>::const_iterator) m_cboCdlHardware.GetItemData (nIndex);
143 m_strCdlHardwareDescription = pDoc->GetCdlPkgData ()->get_target_description (m_hardware).c_str ();
144 m_strCdlHardwareDescription = CUtils::StripExtraWhitespace (m_strCdlHardwareDescription);
146 UpdateDetails (); // display new hardware packages in details box
147 UpdateData (FALSE); // display new target description
150 void CCdlTemplatesDialog::OnSelchangeCdlTemplate()
152 // the template has changed so update the version combo box
153 int nIndex = m_cboCdlTemplate.GetCurSel ();
154 m_template = * (std::vector<std::string>::const_iterator) m_cboCdlTemplate.GetItemData (nIndex);
155 UpdateVersionList (""); // repopulate template versions combo box and select most recent version
158 void CCdlTemplatesDialog::UpdateVersionList(std::string default_version)
160 // clear the version combo box
161 m_cboCdlTemplateVersion.ResetContent ();
163 // get the template version information
164 CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
165 const std::vector<std::string>& versions = pDoc->GetCdlPkgData ()->get_template_versions (m_template);
166 ASSERT (versions.size () > 0);
168 // add the template versions to the version combo box
169 for (unsigned int version = 0; version < versions.size (); version++) {
170 TRACE (_T("Adding version '%s'\n"), CString (versions [version].c_str ()));
171 m_cboCdlTemplateVersion.AddString (CString (versions [version].c_str ()));
174 // select the appropriate version in the version combo box
175 if ("" == default_version) { // if no default version specified
176 m_cboCdlTemplateVersion.SetCurSel (versions.size () - 1); // select the most recent version
177 } else { // a default version was specified
178 m_cboCdlTemplateVersion.SelectString (-1, CString (default_version.c_str ()));
180 OnSelchangeCdlTemplateVersion ();
182 // enable the version combo box only if there are multiple versions
183 m_cboCdlTemplateVersion.EnableWindow (versions.size () > 1);
186 void CCdlTemplatesDialog::UpdateDetails()
188 // retrieve the template and target package names
189 CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
190 const std::vector<std::string> & template_packages = pDoc->GetCdlPkgData ()->get_template_packages (m_template, m_template_version);
191 std::vector<std::string> packages = pDoc->GetCdlPkgData ()->get_target_packages (m_hardware);
192 packages.insert (packages.end (), template_packages.begin (), template_packages.end ());
194 // retrieve the zeroth (verbose) package alias for each package
195 std::vector<std::string> aliases;
196 for (unsigned int i = 0; i < packages.size (); i++)
198 if (pDoc->GetCdlPkgData ()->is_known_package (packages [i])) // if the package is installed
200 aliases.push_back (pDoc->GetCdlPkgData ()->get_package_aliases (packages [i]) [0]);
202 else // package is not installed
204 aliases.push_back ("Unknown package " + packages [i]);
208 // sort the aliases into alphabetical order
209 std::sort (aliases.begin (), aliases.end ());
211 // copy the aliases into the details box
212 m_strCdlTemplatePackages = _T("");
213 for (i = 0; i < aliases.size (); i++)
215 m_strCdlTemplatePackages += aliases [i].c_str ();
216 m_strCdlTemplatePackages += _T("\r\n"); // add a CRLF between each alias
218 m_strCdlTemplatePackages.TrimRight (); // remove the trailing CRLF
221 void CCdlTemplatesDialog::OnSelchangeCdlTemplateVersion()
224 CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
225 m_cboCdlTemplateVersion.GetLBText (m_cboCdlTemplateVersion.GetCurSel (), strVersion);
226 TRACE (_T("Version '%s' selected\n"), strVersion);
227 m_template_version = CUtils::UnicodeToStdStr (strVersion);
228 m_strCdlTemplateDescription = pDoc->GetCdlPkgData ()->get_template_description (m_template, m_template_version).c_str ();
229 m_strCdlTemplateDescription = CUtils::StripExtraWhitespace (m_strCdlTemplateDescription);
231 UpdateDetails (); // display new template packages in details box
232 UpdateData (FALSE); // display new template description
235 void CCdlTemplatesDialog::OnDetails()
237 ShowDetails (! m_edtCdlTemplatePackages.IsWindowVisible ());
240 void CCdlTemplatesDialog::ShowDetails(bool bShow)
242 // show or hide the windows
243 m_edtCdlTemplatePackages.ShowWindow (bShow ? SW_SHOW : SW_HIDE);
244 GetDlgItem (IDC_CDL_TEMPLATE_PACKAGES_STATIC)->ShowWindow (bShow ? SW_SHOW : SW_HIDE);
245 GetDlgItem (IDC_DETAILS)->SetWindowText (bShow ? _T("&Details <<") : _T("&Details >>"));
247 // resize the dialog box
249 GetDlgItem (IDC_DETAILS)->GetWindowRect (rect1);
250 m_edtCdlTemplatePackages.GetWindowRect (rect2);
251 int delta = rect2.bottom - rect1.bottom;
253 GetWindowRect (rcDlg);
254 rcDlg.bottom += bShow ? delta : - delta;