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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [common/] [win32/] [CdlPackagesDialog.cpp] - Blame information for rev 174

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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