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

Subversion Repositories openrisc

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

Go to most recent revision | 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
// CdlPackagesDialog.cpp : implementation file
23
//
24
 
25
#include "stdafx.h"
26
#include "ConfigTool.h"
27
#include "ConfigtoolDoc.h"
28
#include "AddRemoveDialog.h"
29
#include "CdlPackagesDialog.h"
30
#include "CTUtils.h"
31
 
32
#ifdef _DEBUG
33
#define new DEBUG_NEW
34
#undef THIS_FILE
35
static char THIS_FILE[] = __FILE__;
36
#endif
37
 
38
/////////////////////////////////////////////////////////////////////////////
39
// CCdlPackagesDialog dialog
40
 
41
 
42
CCdlPackagesDialog::CCdlPackagesDialog(CWnd* pParent /*=NULL*/)
43
        : CAddRemoveDialog(IDD_CDL_PACKAGES, pParent)
44
{
45
        //{{AFX_DATA_INIT(CCdlPackagesDialog)
46
        m_strPackageDescription = _T("");
47
        //}}AFX_DATA_INIT
48
}
49
 
50
 
51
void CCdlPackagesDialog::DoDataExchange(CDataExchange* pDX)
52
{
53
        CAddRemoveDialog::DoDataExchange(pDX);
54
        //{{AFX_DATA_MAP(CCdlPackagesDialog)
55
        DDX_Control(pDX, IDC_PACKAGE_VER, m_cboPackageVersion);
56
        DDX_Text(pDX, IDC_PACKAGE_DESC, m_strPackageDescription);
57
        //}}AFX_DATA_MAP
58
}
59
 
60
 
61
BEGIN_MESSAGE_MAP(CCdlPackagesDialog, CAddRemoveDialog)
62
        //{{AFX_MSG_MAP(CCdlPackagesDialog)
63
        ON_LBN_SELCHANGE(IDC_ADDREMOVE_LIST1, OnSelchangeList1)
64
        ON_LBN_SELCHANGE(IDC_ADDREMOVE_LIST2, OnSelchangeList2)
65
        ON_CBN_SELCHANGE(IDC_PACKAGE_VER, OnSelchangePackageVersion)
66
        ON_BN_CLICKED(IDC_ADDREMOVE_ADD, OnAdd)
67
        ON_BN_CLICKED(IDC_ADDREMOVE_REMOVE, OnRemove)
68
        ON_LBN_DBLCLK(IDC_ADDREMOVE_LIST1, OnDblclkList1)
69
        ON_LBN_DBLCLK(IDC_ADDREMOVE_LIST2, OnDblclkList2)
70
        //}}AFX_MSG_MAP
71
END_MESSAGE_MAP()
72
 
73
/////////////////////////////////////////////////////////////////////////////
74
// CCdlPackagesDialog message handlers
75
 
76
void CCdlPackagesDialog::OnSelchangeList1 ()
77
{
78
        CAddRemoveDialog::OnSelchangeList1 ();
79
        UpdatePackageDescription ();
80
        UpdateVersionList ();
81
        UpdateHardwareSelectionFlag ();
82
}
83
 
84
void CCdlPackagesDialog::OnSelchangeList2 ()
85
{
86
        CAddRemoveDialog::OnSelchangeList2 ();
87
        UpdatePackageDescription ();
88
        UpdateVersionList ();
89
        UpdateHardwareSelectionFlag ();
90
}
91
 
92
void CCdlPackagesDialog::UpdateVersionList ()
93
{
94
        m_cboPackageVersion.ResetContent (); // clear the version combo box
95
 
96
        CListBox * pListBox = NULL;
97
        int nListSelCount = m_List1.GetSelCount ();
98
        if (nListSelCount)
99
        {
100
                pListBox = &m_List1;
101
        }
102
        else
103
        {
104
                nListSelCount = m_List2.GetSelCount ();
105
                if (nListSelCount)
106
                        pListBox = &m_List2;
107
        }
108
 
109
        if (pListBox) // if there are packages selected
110
        {
111
                std::list<std::string> common_versions;
112
                bool bCommonSelectedVersion = true;
113
                int nCommonVersionIndex=-1;
114
 
115
                // retrieve the list box indices of the selected packages
116
 
117
                int * arnIndices = new int [nListSelCount];
118
                pListBox->GetSelItems (nListSelCount, arnIndices);
119
                for (int nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
120
                {
121
                        // retrieve the first package alias
122
 
123
                        CString strPackageAlias;
124
                        pListBox->GetText (arnIndices [nIndex], strPackageAlias);
125
 
126
                        // retrieve the dialog item array index for use in
127
                        // comparing current version strings
128
 
129
                        const int nVersionIndex = (int) pListBox->GetItemData (arnIndices [nIndex]);
130
 
131
                        // retrieve the installed version array
132
 
133
                        TRACE (_T("Retrieving versions for '%s'\n"), strPackageAlias);
134
                        CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
135
                        const std::vector<std::string>& versions = pDoc->GetCdlPkgData ()->get_package_versions (CUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias)));
136
 
137
                        if (0 == nIndex) // if this is the first selected package
138
                        {
139
                                // use the version array to initialise a linked list of version
140
                                // strings held in common between the selected packages
141
                                for (unsigned int uCount = 0; uCount < versions.size (); uCount++)
142
                                {
143
                                        TRACE (_T("Adding common version '%s'\n"), CString (versions [uCount].c_str ()));
144
                                        common_versions.push_back (versions [uCount]);
145
                                }
146
                                nCommonVersionIndex = nVersionIndex; // save the item array index
147
                        }
148
                        else // this is not the first selected package
149
                        {
150
                                std::list<std::string>::iterator i_common_versions = common_versions.begin ();
151
                                while (i_common_versions != common_versions.end ()) // iterate through the common versions
152
                                {
153
                                        if (versions.end () == std::find (versions.begin (), versions.end (), * i_common_versions)) // if the common version is not in the versions list
154
                                        {
155
                                                TRACE (_T("Removing common version '%s'\n"), CString (i_common_versions->c_str ()));
156
                                                common_versions.erase (i_common_versions++); // remove the version from the common versions list
157
                                        }
158
                                        else
159
                                        {
160
                                                i_common_versions++;
161
                                        }
162
                                }
163
                                if (bCommonSelectedVersion) // if the selected versions of all preceding packages are identical
164
                                {
165
                                        // check if the selected version of this package matches that of the preceding ones
166
                                        bCommonSelectedVersion = (m_arstrVersions [nVersionIndex] == m_arstrVersions [nCommonVersionIndex]);
167
                                }
168
                        }
169
                }
170
 
171
                // add the common versions to the version combo box
172
 
173
                std::list<std::string>::iterator i_common_versions;
174
                for (i_common_versions = common_versions.begin (); i_common_versions != common_versions.end (); i_common_versions++)
175
                {
176
                        TRACE (_T("Adding version '%s'\n"), CString (i_common_versions->c_str ()));
177
                        m_cboPackageVersion.AddString (CString (i_common_versions->c_str ()));
178
                }
179
 
180
                // select the common current version (if any) in the version combo box
181
 
182
                if (bCommonSelectedVersion)
183
                {
184
                        TRACE (_T("Selecting version '%s'\n"), m_arstrVersions [nCommonVersionIndex]);
185
                        m_cboPackageVersion.SelectString (-1, m_arstrVersions [nCommonVersionIndex]);
186
                }
187
 
188
                // enable the version combo box only if there are multiple common versions
189
 
190
                m_cboPackageVersion.EnableWindow (common_versions.size () > 1);
191
 
192
                delete [] arnIndices;
193
        }
194
        else // there are no packages selected
195
        {
196
                m_cboPackageVersion.EnableWindow (FALSE); // disable the version combo box
197
        }
198
}
199
 
200
void CCdlPackagesDialog::UpdatePackageDescription ()
201
{
202
        CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
203
 
204
        CListBox * pListBox = NULL;
205
        if (1 == m_List1.GetSelCount ())
206
                pListBox = &m_List1;
207
        else if (1 == m_List2.GetSelCount ())
208
                pListBox = &m_List2;
209
 
210
        if (pListBox)
211
        {
212
                int nIndex;
213
                pListBox->GetSelItems (1, &nIndex);
214
                CString strPackageAlias;
215
                pListBox->GetText (nIndex, strPackageAlias);
216
                m_strPackageDescription = pDoc->GetCdlPkgData ()->get_package_description (CUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias))).c_str ();
217
                m_strPackageDescription = CUtils::StripExtraWhitespace (m_strPackageDescription);
218
        }
219
        else
220
        {
221
                m_strPackageDescription = _T("");
222
        }
223
 
224
        UpdateData (FALSE);
225
}
226
 
227
void CCdlPackagesDialog::Insert (LPCTSTR pszItem, bool bAdded, LPCTSTR pszDesc /* = NULL */, LPCTSTR pszVersion /* = NULL */)
228
{
229
        TRACE (_T("CCdlPackagesDialog::Insert() adding package %s version '%s'\n"), pszItem, pszVersion);
230
        CAddRemoveDialog::Insert (pszItem, bAdded, pszDesc);
231
        m_arstrVersions.Add (pszVersion);
232
}
233
 
234
 
235
BOOL CCdlPackagesDialog::OnInitDialog()
236
{
237
    m_arbSel=new int [GetCount ()];
238
        CeCosDialog::OnInitDialog ();
239
 
240
        // prepare for the measurement of listbox item widths
241
        int nWidth = 0;
242
    CDC * pDC = m_List1.GetDC ();
243
        CFont * pOldFont = pDC->SelectObject (m_List1.GetFont ());
244
 
245
        // add the items to the listboxes and measure their widths in pixels
246
    for (int i = GetCount () - 1; i >= 0; --i)
247
        {
248
                TRACE (_T("Adding item '%s' index %d\n"), m_arstrItems [i], i);
249
        CListBox & lb = m_arnItems [i] ? m_List2 : m_List1; // determine which listbox
250
        lb.SetItemData (lb.AddString (m_arstrItems [i]), (DWORD) i); // add the item
251
                CSize sizeText = pDC->GetTextExtent (m_arstrItems [i]); // measure the width of the item
252
                nWidth = max (nWidth, sizeText.cx); // record the maximum width of items to date
253
    }
254
 
255
        // restore the device context following measurements
256
    pDC->SelectObject (pOldFont);
257
 
258
        // enable horizontal scrolling if necessary, assuming the
259
        // listboxes have identical widths and accommodating a
260
        // 2 pixel border at each side of each listbox
261
        m_List1.SetHorizontalExtent (nWidth + 4);
262
        m_List2.SetHorizontalExtent (nWidth + 4);
263
 
264
        // enable listboxes only if they have any content
265
    m_Add.EnableWindow (m_List1.GetSelCount () > 0);
266
    m_Remove.EnableWindow (m_List2.GetSelCount () > 0);
267
 
268
        return TRUE;  // return TRUE unless you set the focus to a control
269
                      // EXCEPTION: OCX Property Pages should return FALSE
270
}
271
 
272
void CCdlPackagesDialog::OnSelchangePackageVersion()
273
{
274
        if (CB_ERR == m_cboPackageVersion.GetCurSel ()) // if there is no version selection
275
                return; // do nothing
276
 
277
        CListBox * pListBox = NULL;
278
        int nListSelCount = m_List1.GetSelCount ();
279
        if (nListSelCount)
280
        {
281
                pListBox = &m_List1;
282
        }
283
        else
284
        {
285
                nListSelCount = m_List2.GetSelCount ();
286
                if (nListSelCount)
287
                        pListBox = &m_List2;
288
        }
289
 
290
        ASSERT (pListBox);
291
 
292
        // retrieve the list box indices of the selected packages
293
 
294
        int * arnIndices = new int [nListSelCount];
295
        pListBox->GetSelItems (nListSelCount, arnIndices);
296
 
297
        for (int nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
298
        {
299
                // set the package version to that specified in the version combo box
300
                m_cboPackageVersion.GetLBText (m_cboPackageVersion.GetCurSel (), m_arstrVersions [pListBox->GetItemData (arnIndices [nIndex])]);
301
                TRACE (_T("Version '%s' selected for package %s\n"), m_arstrVersions [pListBox->GetItemData (arnIndices [nIndex])], m_arstrItems [pListBox->GetItemData (arnIndices [nIndex])]);
302
        }
303
        delete [] arnIndices;
304
}
305
 
306
void CCdlPackagesDialog::OnAdd()
307
{
308
        if (m_bHardwarePackageSelected)
309
                HardwarePackageMessageBox ();
310
        else
311
                CAddRemoveDialog::OnAdd ();
312
}
313
 
314
void CCdlPackagesDialog::OnRemove()
315
{
316
        if (m_bHardwarePackageSelected)
317
                HardwarePackageMessageBox ();
318
        else
319
                CAddRemoveDialog::OnRemove ();
320
}
321
 
322
void CCdlPackagesDialog::OnDblclkList1()
323
{
324
        if (m_bHardwarePackageSelected)
325
                HardwarePackageMessageBox ();
326
        else
327
                CAddRemoveDialog::OnDblclkList1 ();
328
}
329
 
330
void CCdlPackagesDialog::OnDblclkList2()
331
{
332
        if (m_bHardwarePackageSelected)
333
                HardwarePackageMessageBox ();
334
        else
335
                CAddRemoveDialog::OnDblclkList2 ();
336
}
337
 
338
CString CCdlPackagesDialog::GetVersion(LPCTSTR pszItem)
339
{
340
    for (int nCount = GetCount () - 1; nCount >= 0; --nCount)
341
        {
342
        if (m_arstrItems [nCount] == pszItem)
343
                {
344
            return m_arstrVersions [nCount];
345
        }
346
    }
347
    ASSERT (false);
348
    return _T("");
349
}
350
 
351
void CCdlPackagesDialog::UpdateHardwareSelectionFlag()
352
{
353
        m_bHardwarePackageSelected = false;
354
 
355
        CListBox * pListBox = NULL;
356
        int nListSelCount = m_List1.GetSelCount ();
357
        if (nListSelCount)
358
        {
359
                pListBox = &m_List1;
360
        }
361
        else
362
        {
363
                nListSelCount = m_List2.GetSelCount ();
364
                if (nListSelCount)
365
                        pListBox = &m_List2;
366
        }
367
 
368
        if (pListBox) // if there are packages selected
369
        {
370
                CConfigToolDoc * pDoc = CConfigTool::GetConfigToolDoc ();
371
 
372
                // retrieve the list box indices of the selected packages
373
 
374
                int * arnIndices = new int [nListSelCount];
375
                pListBox->GetSelItems (nListSelCount, arnIndices);
376
 
377
                for (int nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
378
                {
379
                        CString strPackageAlias;
380
                        pListBox->GetText (arnIndices [nIndex], strPackageAlias);
381
 
382
                        // check if the package is a hardware package
383
 
384
                        TRACE (_T("Checking '%s' for hardware status\n"), strPackageAlias);
385
                        if (pDoc->GetCdlPkgData ()->is_hardware_package (CUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias))))
386
                        {
387
                                m_bHardwarePackageSelected = true;
388
                                break;
389
                        }
390
                }
391
 
392
                delete [] arnIndices;
393
        }
394
}
395
 
396
void CCdlPackagesDialog::HardwarePackageMessageBox()
397
{
398
        AfxMessageBox (_T("Add and remove hardware packages by selecting a new hardware template."));
399
}

powered by: WebSVN 2.1.0

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