OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [common/] [win32/] [CdlTemplatesDialog.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// CdlTemplatesDialog.cpp : implementation file
23
//
24
 
25
#include "stdafx.h"
26
#include "Configtool.h"
27
#include "ConfigtoolDoc.h"
28
#include "CTUtils.h"
29
#include "CdlTemplatesDialog.h"
30
 
31
#ifdef _DEBUG
32
#define new DEBUG_NEW
33
#undef THIS_FILE
34
static char THIS_FILE[] = __FILE__;
35
#endif
36
 
37
/////////////////////////////////////////////////////////////////////////////
38
// CCdlTemplatesDialog dialog
39
 
40
 
41
CCdlTemplatesDialog::CCdlTemplatesDialog(CWnd* pParent /*=NULL*/)
42
        : CeCosDialog(IDD, pParent)
43
{
44
        //{{AFX_DATA_INIT(CCdlTemplatesDialog)
45
        m_strCdlTemplateDescription = _T("");
46
        m_strCdlTemplatePackages = _T("");
47
        //}}AFX_DATA_INIT
48
}
49
 
50
 
51
void CCdlTemplatesDialog::DoDataExchange(CDataExchange* pDX)
52
{
53
        CeCosDialog::DoDataExchange(pDX);
54
        //{{AFX_DATA_MAP(CCdlTemplatesDialog)
55
        DDX_Control(pDX, IDC_CDL_TEMPLATE_PACKAGES, m_edtCdlTemplatePackages);
56
        DDX_Control(pDX, IDC_CDL_TEMPLATE, m_cboCdlTemplate);
57
        DDX_Control(pDX, IDC_CDL_TEMPLATE_VER, m_cboCdlTemplateVersion);
58
        DDX_Control(pDX, IDC_CDL_HARDWARE, m_cboCdlHardware);
59
        DDX_Text(pDX, IDC_CDL_HARDWARE_DESC, m_strCdlHardwareDescription);
60
        DDX_Text(pDX, IDC_CDL_TEMPLATE_DESC, m_strCdlTemplateDescription);
61
        DDX_Text(pDX, IDC_CDL_TEMPLATE_PACKAGES, m_strCdlTemplatePackages);
62
        //}}AFX_DATA_MAP
63
}
64
 
65
 
66
BEGIN_MESSAGE_MAP(CCdlTemplatesDialog, CeCosDialog)
67
        //{{AFX_MSG_MAP(CCdlTemplatesDialog)
68
        ON_CBN_SELCHANGE(IDC_CDL_HARDWARE, OnSelchangeCdlHardware)
69
        ON_BN_CLICKED(IDC_DETAILS, OnDetails)
70
        ON_WM_CANCELMODE()
71
        ON_CBN_SELCHANGE(IDC_CDL_TEMPLATE, OnSelchangeCdlTemplate)
72
        ON_CBN_SELCHANGE(IDC_CDL_TEMPLATE_VER, OnSelchangeCdlTemplateVersion)
73
        //}}AFX_MSG_MAP
74
END_MESSAGE_MAP()
75
 
76
/////////////////////////////////////////////////////////////////////////////
77
// CCdlTemplatesDialog message handlers
78
 
79
BOOL CCdlTemplatesDialog::OnInitDialog()
80
{
81
        CeCosDialog::OnInitDialog();
82
 
83
        ShowDetails (false); // hide the details initially
84
 
85
        CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
86
 
87
        // populate the hardware combo box
88
        m_hardware = pDoc->GetCdlConfig ()->get_hardware ();
89
        const std::vector<std::string> & targets = pDoc->GetCdlPkgData ()->get_targets ();
90
        std::vector<std::string>::const_iterator target_i;
91
        for (target_i = targets.begin (); target_i != targets.end (); target_i++)
92
        {
93
                const std::vector<std::string> & aliases = pDoc->GetCdlPkgData ()->get_target_aliases (* target_i);
94
 
95
                // use the first alias (if any) as the description
96
                CString strTargetDescription = aliases.size () ? aliases [0].c_str () : target_i->c_str ();
97
                int nIndex = m_cboCdlHardware.AddString (strTargetDescription);
98
                m_cboCdlHardware.SetItemData (nIndex, (DWORD) target_i); // store the target iterator
99
                if (m_hardware == * target_i)            // if current target...
100
                        m_cboCdlHardware.SetCurSel (nIndex); // ...select the string
101
        }
102
 
103
        if (CB_ERR == m_cboCdlHardware.GetCurSel ()) // if no target selected...
104
                m_cboCdlHardware.SetCurSel (0);          // ...select the first one
105
 
106
        // populate the template combo box
107
        m_template = pDoc->GetCdlConfig ()->get_template ();
108
        const std::vector<std::string> & templates = pDoc->GetCdlPkgData ()->get_templates ();
109
        std::vector<std::string>::const_iterator template_i;
110
        for (template_i = templates.begin (); template_i != templates.end (); template_i++)
111
        {
112
                CString strTemplateDescription = template_i->c_str ();
113
                int nIndex = m_cboCdlTemplate.AddString (strTemplateDescription);
114
                m_cboCdlTemplate.SetItemData (nIndex, (DWORD) template_i); // store the template iterator
115
                if (m_template == * template_i)          // if current template...
116
                        m_cboCdlTemplate.SetCurSel (nIndex); // ...select the string
117
        }
118
 
119
        if (CB_ERR == m_cboCdlTemplate.GetCurSel ()) // if no template selected...
120
                m_cboCdlTemplate.SetCurSel (0);          // ...select the first one
121
 
122
        // display initial target and template descriptions
123
        OnSelchangeCdlHardware ();
124
        OnSelchangeCdlTemplate ();
125
 
126
        // populate the template version combo box
127
        UpdateVersionList (pDoc->GetTemplateVersion ());
128
 
129
        return TRUE;  // return TRUE unless you set the focus to a control
130
                      // EXCEPTION: OCX Property Pages should return FALSE
131
}
132
 
133
void CCdlTemplatesDialog::OnSelchangeCdlHardware()
134
{
135
        CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
136
 
137
        // the target has changed so retrieve the new target description
138
        const int nIndex = m_cboCdlHardware.GetCurSel ();
139
        m_hardware = * (std::vector<std::string>::const_iterator) m_cboCdlHardware.GetItemData (nIndex);
140
        m_strCdlHardwareDescription = pDoc->GetCdlPkgData ()->get_target_description (m_hardware).c_str ();
141
        m_strCdlHardwareDescription = CUtils::StripExtraWhitespace (m_strCdlHardwareDescription);
142
 
143
    UpdateDetails (); // display new hardware packages in details box
144
    UpdateData (FALSE); // display new target description
145
}
146
 
147
void CCdlTemplatesDialog::OnSelchangeCdlTemplate()
148
{
149
        // the template has changed so update the version combo box
150
        int nIndex = m_cboCdlTemplate.GetCurSel ();
151
        m_template = * (std::vector<std::string>::const_iterator) m_cboCdlTemplate.GetItemData (nIndex);
152
        UpdateVersionList (""); // repopulate template versions combo box and select most recent version
153
}
154
 
155
void CCdlTemplatesDialog::UpdateVersionList(std::string default_version)
156
{
157
  // clear the version combo box
158
  m_cboCdlTemplateVersion.ResetContent ();
159
 
160
  // get the template version information
161
  CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
162
  const std::vector<std::string>& versions = pDoc->GetCdlPkgData ()->get_template_versions (m_template);
163
  ASSERT (versions.size () > 0);
164
 
165
  // add the template versions to the version combo box
166
  for (unsigned int version = 0; version < versions.size (); version++) {
167
    TRACE (_T("Adding version '%s'\n"), CString (versions [version].c_str ()));
168
    m_cboCdlTemplateVersion.AddString (CString (versions [version].c_str ()));
169
  }
170
 
171
  // select the appropriate version in the version combo box
172
  if ("" == default_version) { // if no default version specified
173
    m_cboCdlTemplateVersion.SetCurSel (versions.size () - 1); // select the most recent version
174
  } else { // a default version was specified
175
    m_cboCdlTemplateVersion.SelectString (-1, CString (default_version.c_str ()));
176
  }
177
  OnSelchangeCdlTemplateVersion ();
178
 
179
  // enable the version combo box only if there are multiple versions
180
  m_cboCdlTemplateVersion.EnableWindow (versions.size () > 1);
181
}
182
 
183
void CCdlTemplatesDialog::UpdateDetails()
184
{
185
  // retrieve the template and target package names
186
  CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
187
  const std::vector<std::string> & template_packages = pDoc->GetCdlPkgData ()->get_template_packages (m_template, m_template_version);
188
  std::vector<std::string> packages = pDoc->GetCdlPkgData ()->get_target_packages (m_hardware);
189
  packages.insert (packages.end (), template_packages.begin (), template_packages.end ());
190
 
191
  // retrieve the zeroth (verbose) package alias for each package
192
  std::vector<std::string> aliases;
193
  for (unsigned int i = 0; i < packages.size (); i++)
194
  {
195
    if (pDoc->GetCdlPkgData ()->is_known_package (packages [i])) // if the package is installed
196
    {
197
      aliases.push_back (pDoc->GetCdlPkgData ()->get_package_aliases (packages [i]) [0]);
198
    }
199
    else // package is not installed
200
    {
201
      aliases.push_back ("Unknown package " + packages [i]);
202
    }
203
  }
204
 
205
  // sort the aliases into alphabetical order
206
  std::sort (aliases.begin (), aliases.end ());
207
 
208
  // copy the aliases into the details box
209
  m_strCdlTemplatePackages = _T("");
210
  for (i = 0; i < aliases.size (); i++)
211
  {
212
    m_strCdlTemplatePackages += aliases [i].c_str ();
213
    m_strCdlTemplatePackages += _T("\r\n"); // add a CRLF between each alias
214
  }
215
  m_strCdlTemplatePackages.TrimRight (); // remove the trailing CRLF
216
}
217
 
218
void CCdlTemplatesDialog::OnSelchangeCdlTemplateVersion()
219
{
220
  CString strVersion;
221
  CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
222
  m_cboCdlTemplateVersion.GetLBText (m_cboCdlTemplateVersion.GetCurSel (), strVersion);
223
  TRACE (_T("Version '%s' selected\n"), strVersion);
224
  m_template_version = CUtils::UnicodeToStdStr (strVersion);
225
  m_strCdlTemplateDescription = pDoc->GetCdlPkgData ()->get_template_description (m_template, m_template_version).c_str ();
226
  m_strCdlTemplateDescription = CUtils::StripExtraWhitespace (m_strCdlTemplateDescription);
227
 
228
  UpdateDetails (); // display new template packages in details box
229
  UpdateData (FALSE); // display new template description
230
}
231
 
232
void CCdlTemplatesDialog::OnDetails()
233
{
234
    ShowDetails (! m_edtCdlTemplatePackages.IsWindowVisible ());
235
}
236
 
237
void CCdlTemplatesDialog::ShowDetails(bool bShow)
238
{
239
    // show or hide the windows
240
    m_edtCdlTemplatePackages.ShowWindow (bShow ? SW_SHOW : SW_HIDE);
241
    GetDlgItem (IDC_CDL_TEMPLATE_PACKAGES_STATIC)->ShowWindow (bShow ? SW_SHOW : SW_HIDE);
242
    GetDlgItem (IDC_DETAILS)->SetWindowText (bShow ? _T("&Details <<") : _T("&Details >>"));
243
 
244
    // resize the dialog box
245
    CRect rect1,rect2;
246
    GetDlgItem (IDC_DETAILS)->GetWindowRect (rect1);
247
    m_edtCdlTemplatePackages.GetWindowRect (rect2);
248
    int delta = rect2.bottom - rect1.bottom;
249
    CRect rcDlg;
250
    GetWindowRect (rcDlg);
251
    rcDlg.bottom += bShow ? delta : - delta;
252
    MoveWindow (rcDlg);
253
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.