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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [common/] [win32/] [AddRemoveDialog.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
// AddRemoveDialog.cpp : implementation file
23
//
24
 
25
#include "stdafx.h"
26
 
27
#include "AddRemoveDialog.h"
28
#ifdef _DEBUG
29
#define new DEBUG_NEW
30
#undef THIS_FILE
31
static char THIS_FILE[] = __FILE__;
32
#endif
33
 
34
/////////////////////////////////////////////////////////////////////////////
35
// CAddRemoveDialog dialog
36
 
37
void CAddRemoveDialog::AfxDataInit()
38
{
39
        //{{AFX_DATA_INIT(CAddRemoveDialog)
40
                // NOTE: the ClassWizard will add member initialization here
41
        //}}AFX_DATA_INIT
42
}
43
 
44
CAddRemoveDialog::CAddRemoveDialog(CWnd* pParent /*=NULL*/)
45
        : CeCosDialog(IDD, pParent),
46
    m_bSort(false),
47
    m_arbSel(NULL),
48
    m_bHaveDescs(false),
49
    m_nHorizontalResizingLimit(0)
50
{
51
        AfxDataInit ();
52
}
53
 
54
CAddRemoveDialog::CAddRemoveDialog(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
55
        : CeCosDialog(nIDTemplate, pParent),
56
    m_bSort(false),
57
    m_arbSel(NULL),
58
    m_nHorizontalResizingLimit(0)
59
{
60
        AfxDataInit ();
61
}
62
 
63
void CAddRemoveDialog::DoDataExchange(CDataExchange* pDX)
64
{
65
        CeCosDialog::DoDataExchange(pDX);
66
        //{{AFX_DATA_MAP(CAddRemoveDialog)
67
        DDX_Control(pDX, IDC_PACKAGE_DESC, m_wndDesc);
68
        DDX_Control(pDX, IDC_ADDREMOVE_LIST2, m_List2);
69
        DDX_Control(pDX, IDC_ADDREMOVE_LIST1, m_List1);
70
        DDX_Control(pDX, IDC_ADDREMOVE_ADD,   m_Add);
71
        DDX_Control(pDX, IDC_ADDREMOVE_REMOVE,m_Remove);
72
        //}}AFX_DATA_MAP
73
}
74
 
75
 
76
BEGIN_MESSAGE_MAP(CAddRemoveDialog, CeCosDialog)
77
        //{{AFX_MSG_MAP(CAddRemoveDialog)
78
        ON_BN_CLICKED(IDC_ADDREMOVE_ADD, OnAdd)
79
        ON_BN_CLICKED(IDC_ADDREMOVE_REMOVE, OnRemove)
80
        ON_LBN_DBLCLK(IDC_ADDREMOVE_LIST1, OnDblclkList1)
81
        ON_LBN_DBLCLK(IDC_ADDREMOVE_LIST2, OnDblclkList2)
82
        ON_LBN_SELCHANGE(IDC_ADDREMOVE_LIST1, OnSelchangeList1)
83
        ON_LBN_SELCHANGE(IDC_ADDREMOVE_LIST2, OnSelchangeList2)
84
        ON_WM_DESTROY()
85
        //}}AFX_MSG_MAP
86
END_MESSAGE_MAP()
87
 
88
/////////////////////////////////////////////////////////////////////////////
89
// CAddRemoveDialog message handlers
90
 
91
void CAddRemoveDialog::OnAdd()
92
{
93
    Add(m_List1,m_List2);
94
    m_Add.EnableWindow(FALSE);
95
    m_Remove.EnableWindow(TRUE);
96
}
97
 
98
void CAddRemoveDialog::OnRemove()
99
{
100
    Add(m_List2,m_List1);
101
    m_Add.EnableWindow(TRUE);
102
    m_Remove.EnableWindow(FALSE);
103
}
104
 
105
void CAddRemoveDialog::Insert(LPCTSTR pszItem, bool bAdded, LPCTSTR pszDesc/*=NULL*/)
106
{
107
    m_bHaveDescs|=(NULL!=pszDesc);
108
    m_arnItems.  Add(bAdded);
109
    m_arstrItems.Add(pszItem);
110
    m_arstrDescs.Add(pszDesc?pszDesc:_T(""));
111
}
112
 
113
BOOL CAddRemoveDialog::OnInitDialog()
114
{
115
        CeCosDialog::OnInitDialog();
116
 
117
    m_arbSel=new int[GetCount()];
118
 
119
    SetWindowText(m_strCaption);
120
    SetSortMode(m_List1);
121
    SetSortMode(m_List2);
122
 
123
        int cxExtent=0;
124
    CDC *pDC=m_List1.GetDC();
125
        CFont *pOldFont=pDC->SelectObject(m_List1.GetFont());
126
    for(int i=GetCount()-1;i>=0;--i) {
127
        const CString &str=m_arstrItems[i];
128
                cxExtent=max(cxExtent,pDC->GetTextExtent(str).cx);
129
        CListBox &lb=m_arnItems[i]?m_List2:m_List1;
130
        lb.SetItemData(lb.AddString(str),(DWORD)i);
131
    }
132
    pDC->SelectObject(pOldFont);
133
 
134
    SetDlgItemText(IDC_ADDREMOVE_TEXT1,m_strMessage1);
135
    SetDlgItemText(IDC_ADDREMOVE_TEXT2,m_strMessage2);
136
 
137
        CRect rcLb1;
138
        m_List1.GetWindowRect(rcLb1);
139
    CRect rcDialog;
140
    GetWindowRect(rcDialog);
141
 
142
        int nExpand=cxExtent-(rcLb1.Width()-GetSystemMetrics(SM_CXVSCROLL)-2*GetSystemMetrics(SM_CXBORDER)-5);
143
    nExpand=min(nExpand,m_nHorizontalResizingLimit);
144
        if(nExpand>0){
145
                MoveChild(IDOK,2*nExpand,Move);
146
                MoveChild(IDCANCEL,2*nExpand,Move);
147
                MoveChild(IDC_ADDREMOVE_ADD,nExpand,Move);
148
                MoveChild(IDC_ADDREMOVE_REMOVE,nExpand,Move);
149
                MoveChild(IDC_ADDREMOVE_LIST1,nExpand,Stretch);
150
                MoveChild(IDC_ADDREMOVE_TEXT2,nExpand,Move);
151
                MoveChild(IDC_ADDREMOVE_LIST2,nExpand,Move);
152
                MoveChild(IDC_ADDREMOVE_LIST2,nExpand,Stretch);
153
                MoveChild(IDC_PACKAGE_DESC,2*nExpand,Stretch);
154
            rcDialog.right+=2*nExpand; // MoveWindow call is below
155
        }
156
 
157
    // enable horizontal scrolling if necessary, assuming the
158
        // listboxes have identical widths and accommodating a
159
        // 2 pixel border at each side of each listbox
160
        m_List1.SetHorizontalExtent (cxExtent + 4);
161
        m_List2.SetHorizontalExtent (cxExtent + 4);
162
 
163
    m_Add.EnableWindow(m_List1.GetCount()>0);
164
    m_Remove.EnableWindow(m_List2.GetCount()>0);
165
 
166
    if(!m_bHaveDescs){
167
        // Remove the description pane if not used:
168
        CRect rcDesc;
169
        m_wndDesc.GetWindowRect(rcDesc);
170
        m_wndDesc.ShowWindow(SW_HIDE);
171
            int delta=(rcDesc.Height()+(rcDesc.top-rcLb1.bottom));
172
        MoveChild(IDOK,delta,Up);
173
        MoveChild(IDCANCEL,delta,Up);
174
        rcDialog.bottom-=delta;
175
    }
176
 
177
    // Finally, adjust dialog size according to calculations:
178
    MoveWindow(rcDialog);
179
 
180
        return TRUE;  // return TRUE unless you set the focus to a control
181
                      // EXCEPTION: OCX Property Pages should return FALSE
182
}
183
 
184
void CAddRemoveDialog::OnDblclkList1()
185
{
186
    OnDblclk(m_List1,m_List2);
187
    m_Add.EnableWindow(FALSE);
188
    m_Remove.EnableWindow(TRUE);
189
}
190
 
191
void CAddRemoveDialog::OnDblclkList2()
192
{
193
    OnDblclk(m_List2,m_List1);
194
    m_Add.EnableWindow(TRUE);
195
    m_Remove.EnableWindow(FALSE);
196
}
197
 
198
int CAddRemoveDialog::Add(CListBox &lb1,CListBox &lb2)
199
{
200
    int nSelCount=lb1.GetSelItems(lb1.GetCount(),m_arbSel);
201
    for(int i=nSelCount-1;i>=0;--i){
202
        Xfer(lb1,lb2,m_arbSel[i]);
203
    }
204
    ClearSel(lb1);
205
    lb2.SetFocus();
206
    return nSelCount;
207
}
208
 
209
void CAddRemoveDialog::OnDblclk(CListBox &lb1,CListBox &lb2)
210
{
211
    BOOL bOutside;
212
    DWORD dwPos=GetMessagePos();
213
    POINTS pts=MAKEPOINTS(dwPos);
214
    CRect rc(pts.x,pts.y,0,0);
215
    lb1.ScreenToClient(rc);
216
    CPoint pt(rc.left,rc.top);
217
    int nItem=lb1.ItemFromPoint(pt,bOutside);
218
    if(!bOutside){
219
        Xfer(lb1,lb2,nItem);
220
    }
221
    ClearSel(lb1);
222
    lb2.SetFocus();
223
}
224
 
225
void CAddRemoveDialog::ClearSel(CListBox &lb)
226
{
227
    for(int i=lb.GetCount()-1;i>=0;--i){
228
        lb.SetSel(i,FALSE);
229
    }
230
}
231
 
232
void CAddRemoveDialog::OnSelchangeList1()
233
{
234
    ClearSel(m_List2);
235
    m_Add.EnableWindow(m_List1.GetSelCount()>0);
236
    UpdateDescription(m_List1);
237
    m_Remove.EnableWindow(FALSE);
238
}
239
 
240
void CAddRemoveDialog::OnSelchangeList2()
241
{
242
    ClearSel(m_List1);
243
    m_Remove.EnableWindow(m_List2.GetSelCount()>0);
244
    UpdateDescription(m_List2);
245
    m_Add.EnableWindow(FALSE);
246
}
247
 
248
void CAddRemoveDialog::Xfer(CListBox &lb1, CListBox &lb2, int nItem)
249
{
250
    CString strItem;
251
    lb1.GetText(nItem,strItem);
252
    int nNewItem=lb2.AddString(strItem);
253
    lb2.SetSel(nNewItem,TRUE);
254
    DWORD nIndex=lb1.GetItemData(nItem);
255
    lb2.SetItemData(nNewItem,nIndex);
256
    m_arnItems[(int)nIndex]^=1;
257
    lb1.DeleteString(nItem);
258
}
259
 
260
bool CAddRemoveDialog::IsAdded(LPCTSTR pszItem) const
261
{
262
    for(int i=GetCount()-1;i>=0;--i){
263
        if(m_arstrItems[i]==pszItem){
264
            return 0!=m_arnItems[i];
265
        }
266
    }
267
    ASSERT(false);
268
    return false;
269
}
270
 
271
 
272
void CAddRemoveDialog::SetCaption(LPCTSTR pszCaption)
273
{
274
    m_strCaption=pszCaption;
275
}
276
 
277
void CAddRemoveDialog::SetMessage(LPCTSTR pszText1,LPCTSTR pszText2)
278
{
279
    m_strMessage1=pszText1;
280
    m_strMessage2=pszText2;
281
}
282
 
283
void CAddRemoveDialog::OnDestroy()
284
{
285
        CeCosDialog::OnDestroy();
286
    deleteZA(m_arbSel);
287
}
288
 
289
// Add the "sort" property to the listboxes.  Unfortunately this entails
290
// recreating them.
291
void CAddRemoveDialog::SetSortMode(CListBox &lb)
292
{
293
    DWORD dwStyle=lb.GetStyle();
294
    if(m_bSort!=(0!=(dwStyle&LBS_SORT))){
295
        if(m_bSort){
296
            dwStyle|=LBS_SORT;
297
        } else {
298
            dwStyle&=~LBS_SORT;
299
        }
300
        dwStyle|=WS_HSCROLL; // For some reason this doesn't come through GetStyle()
301
        CRect rect;
302
        lb.GetWindowRect(rect);
303
        ScreenToClient(rect);
304
        DWORD dwStyleEx=lb.GetExStyle();
305
        CFont *pFont=lb.GetFont();
306
        DWORD id=lb.GetDlgCtrlID();
307
        lb.DestroyWindow();
308
        lb.Detach();
309
        // CreateEx not Create to get ourselves a 3D border
310
        lb.CreateEx(dwStyleEx,_T("LISTBOX"),NULL,dwStyle,rect,this,id);
311
        lb.SetFont(pFont);
312
    }
313
}
314
 
315
// Implement ctrl/A on listboxes
316
BOOL CAddRemoveDialog::PreTranslateMessage(MSG* pMsg)
317
{
318
    if(WM_CHAR==pMsg->message && 1==pMsg->wParam){
319
        if(pMsg->hwnd==m_List1.m_hWnd){
320
            m_List1.SelItemRange(TRUE,0,m_List1.GetCount()-1);
321
            ClearSel(m_List2);
322
            m_Add.EnableWindow(m_List1.GetCount()>0);
323
            m_Remove.EnableWindow(FALSE);
324
            return TRUE;
325
        } else if(pMsg->hwnd==m_List2.m_hWnd){
326
            m_List2.SelItemRange(TRUE,0,m_List2.GetCount()-1);
327
            ClearSel(m_List1);
328
            m_Remove.EnableWindow(m_List2.GetCount()>0);
329
            m_Add.EnableWindow(FALSE);
330
            return TRUE;
331
        }
332
    }
333
 
334
        return CeCosDialog::PreTranslateMessage(pMsg);
335
}
336
 
337
void CAddRemoveDialog::MoveChild(UINT id,int delta,MoveType how)
338
{
339
    CWnd *pWnd=GetDlgItem(id);
340
    CRect rect;
341
        pWnd->GetWindowRect(rect);
342
        ScreenToClient(rect);
343
    switch(how){
344
        case Move:
345
                rect.left+=delta;
346
                rect.right+=delta;
347
            break;
348
        case Stretch:
349
                rect.right+=delta;
350
            break;
351
        case Up:
352
            rect.top-=delta;
353
            rect.bottom-=delta;
354
            break;
355
    }
356
    pWnd->MoveWindow(rect);
357
}
358
 
359
void CAddRemoveDialog::UpdateDescription(CListBox &lb)
360
{
361
    CString strDesc;
362
    // Set the description if the listbox has exactly one item selected
363
    if(1==lb.GetSelCount()){
364
            int nIndex;
365
            lb.GetSelItems(1,&nIndex);
366
        strDesc=m_arstrDescs[lb.GetItemData(nIndex)];
367
    }
368
    m_wndDesc.SetWindowText(strDesc);
369
}
370
 
371
void CAddRemoveDialog::SetHorizontalResizingLimit(int nPercent)
372
{
373
    m_nHorizontalResizingLimit=nPercent;
374
}

powered by: WebSVN 2.1.0

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