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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [propertywin.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, 2008, 2009 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
// propertywin.cpp :
23
//
24
//===========================================================================
25
//#####DESCRIPTIONBEGIN####
26
//
27
// Author(s):   julians, jld
28
// Contact(s):  julians
29
// Date:        2000/09/04
30
// Version:     $Id: propertywin.cpp,v 1.7 2001/04/24 14:39:13 julians Exp $
31
// Purpose:
32
// Description: Implementation file for ecPropertyListCtrl
33
// Requires:
34
// Provides:
35
// See also:
36
// Known bugs:
37
// Usage:
38
//
39
//####DESCRIPTIONEND####
40
//
41
//===========================================================================
42
 
43
// ============================================================================
44
// declarations
45
// ============================================================================
46
 
47
// ----------------------------------------------------------------------------
48
// headers
49
// ----------------------------------------------------------------------------
50
#ifdef __GNUG__
51
    #pragma implementation "propertywin.h"
52
#endif
53
 
54
// Includes other headers for precompiled compilation
55
#include "ecpch.h"
56
 
57
#ifdef __BORLANDC__
58
    #pragma hdrstop
59
#endif
60
 
61
#include "propertywin.h"
62
#include "configtool.h"
63
#include "configitem.h"
64
#include "configtooldoc.h"
65
#include "ecutils.h"
66
 
67
// specify the CDL properties which are to be visible in the properties view
68
const std::string ecPropertyListCtrl::visible_properties [] =
69
{
70
        CdlPropertyId_ActiveIf,
71
        CdlPropertyId_BuildProc,
72
        CdlPropertyId_Calculated,
73
        CdlPropertyId_CancelProc,
74
        CdlPropertyId_CheckProc,
75
        CdlPropertyId_Compile,
76
        CdlPropertyId_ConfirmProc,
77
        CdlPropertyId_DecorationProc,
78
        CdlPropertyId_DefaultValue,
79
        CdlPropertyId_Define,
80
        CdlPropertyId_DefineHeader,
81
        CdlPropertyId_DefineProc,
82
//      CdlPropertyId_Description,
83
        CdlPropertyId_Dialog,
84
//      CdlPropertyId_Display,
85
        CdlPropertyId_DisplayProc,
86
        CdlPropertyId_Doc,
87
        CdlPropertyId_EntryProc,
88
        CdlPropertyId_Flavor,
89
        CdlPropertyId_DefineFormat,
90
        CdlPropertyId_Group,
91
        CdlPropertyId_Hardware,
92
        CdlPropertyId_IfDefine,
93
        CdlPropertyId_Implements,
94
        CdlPropertyId_IncludeDir,
95
        CdlPropertyId_IncludeFiles,
96
        CdlPropertyId_InitProc,
97
        CdlPropertyId_InstallProc,
98
        CdlPropertyId_LegalValues,
99
        CdlPropertyId_Library,
100
        CdlPropertyId_LicenseProc,
101
        CdlPropertyId_Make,
102
        CdlPropertyId_Makefile,
103
        CdlPropertyId_MakeObject,
104
        CdlPropertyId_NoDefine,
105
        CdlPropertyId_Object,
106
        CdlPropertyId_Parent,
107
        CdlPropertyId_Requires,
108
        CdlPropertyId_Screen,
109
        CdlPropertyId_Script,
110
        CdlPropertyId_UpdateProc,
111
        CdlPropertyId_Wizard
112
};
113
 
114
const wxChar* ecPropertyListCtrl::sm_fieldTypeImage[ecMAXFIELDTYPE]=
115
        {wxT("Type"), wxT("Value"), wxT("Default"), wxT("Macro"), wxT("File"), wxT("URL"), wxT("Enabled")};
116
 
117
 
118
/*
119
 * ecPropertyListCtrl
120
 */
121
 
122
IMPLEMENT_CLASS(ecPropertyListCtrl, wxListCtrl)
123
 
124
BEGIN_EVENT_TABLE(ecPropertyListCtrl, wxListCtrl)
125
    EVT_RIGHT_DOWN(ecPropertyListCtrl::OnRightClick)
126
    EVT_LEFT_DCLICK(ecPropertyListCtrl::OnDoubleClick)
127
END_EVENT_TABLE()
128
 
129
ecPropertyListCtrl::ecPropertyListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
130
        const wxSize& sz, long style):
131
        wxListCtrl(parent, id, pt, sz, style)
132
{
133
    if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
134
         wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Properties")).Ok())
135
    {
136
        SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Properties")));
137
    }
138
 
139
    m_f[0]=0.25;
140
    m_f[1]=0.75;
141
    m_pti = NULL;
142
    m_nFirstProperty = 0;
143
    m_nOnSizeRecursionCount = 0;
144
 
145
    AddColumns();
146
 
147
#if 0
148
    int j;
149
    int i = 0;
150
    for (j = 0; j < 4; j++)
151
    {
152
 
153
        // Insert some dummy items
154
 
155
        wxListItem info;
156
        info.m_text = _("URL");
157
        info.m_mask = wxLIST_MASK_TEXT ; // | wxLIST_MASK_IMAGE | wxLIST_MASK_DATA;
158
        info.m_itemId = i;
159
        info.m_image = -1;
160
        //info.m_data = (long) doc;
161
 
162
        long item = InsertItem(info);
163
 
164
        SetItem(i, 1, _("redirects/interrupts.html"));
165
        i ++;
166
 
167
        info.m_text = _("Enabled");
168
        info.m_mask = wxLIST_MASK_TEXT ; // | wxLIST_MASK_IMAGE | wxLIST_MASK_DATA;
169
        info.m_itemId = i;
170
        info.m_image = -1;
171
        //info.m_data = (long) doc;
172
 
173
        item = InsertItem(info);
174
 
175
        SetItem(i, 1, _("True"));
176
        i ++;
177
    }
178
#endif
179
 
180
}
181
 
182
void ecPropertyListCtrl::OnRightClick(wxMouseEvent& event)
183
{
184
    PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
185
}
186
 
187
void ecPropertyListCtrl::AddColumns()
188
{
189
    InsertColumn(0, "Property", wxLIST_FORMAT_LEFT, 100);
190
    InsertColumn(1, "Value", wxLIST_FORMAT_LEFT, 100);
191
}
192
 
193
void ecPropertyListCtrl::Fill(ecConfigItem *pti)
194
{
195
    if(NULL==pti){
196
        ClearAll();
197
        AddColumns();
198
        m_nFirstProperty=0;
199
        m_pti=NULL;
200
    } else /* if(pti!=m_pti) */ {
201
        m_pti=pti;
202
        m_nMaxValueWidth=0;
203
        ecOptionType type=m_pti->GetOptionType();
204
        int i;
205
 
206
        // Initially flag all items as unnecessary - calls of SetItem or SetProperty will change this
207
        for(i=GetItemCount()-1;i>=0;--i){
208
            SetItemData(i,0);
209
        }
210
        if (m_pti->HasBool () || (ecOptionTypeNone!=type)){
211
            SetItem(ecMacro, m_pti->GetMacro ());
212
        }
213
 
214
        if (m_pti->HasBool ()){
215
            SetItem(ecEnabled, m_pti->IsEnabled() ? wxT("True") : wxT("False"));
216
        }
217
 
218
        if(!m_pti->GetFilename().IsEmpty()){
219
            SetItem(ecFile, m_pti->GetFilename());
220
        }
221
        SetItem(ecURL, m_pti->GetURL());
222
 
223
        if (ecOptionTypeNone!=type){
224
 
225
            switch(type){
226
            case ecString:
227
                SetItem(ecValue, m_pti->StringValue());
228
                SetItem(ecDefaultValue, m_pti->StringDefaultValue());
229
                break;
230
            case ecLong:
231
                SetItem(ecValue, ecUtils::IntToStr(m_pti->Value(), wxGetApp().GetSettings().m_bHex));
232
                SetItem(ecDefaultValue, ecUtils::IntToStr(m_pti->DefaultValue(), wxGetApp().GetSettings().m_bHex));
233
                break;
234
            case ecDouble:
235
                SetItem(ecValue, ecUtils::DoubleToStr(m_pti->DoubleValue()));
236
                SetItem(ecDefaultValue, ecUtils::DoubleToStr(m_pti->DoubleDefaultValue()));
237
                break;
238
            case ecEnumerated:
239
                SetItem(ecValue,m_pti->StringValue());
240
                SetItem(ecDefaultValue,m_pti->StringDefaultValue());
241
                break;
242
            default:
243
                wxASSERT( FALSE );
244
                break;
245
            }
246
            // TODO: set image
247
            // SetItem(ecType, ecConfigItem::TreeItemTypeImage[type]);
248
        }
249
 
250
        // List all the properties applicable to me
251
        const std::string name = ecUtils::UnicodeToStdStr (m_pti->GetMacro ());
252
        if (name.size () > 0)
253
        {
254
            const CdlConfiguration config = wxGetApp().GetConfigToolDoc ()->GetCdlConfig ();
255
            const CdlNode node = config->find_node (name, true);
256
            wxASSERT (node);
257
            const std::vector<CdlProperty> & properties = node->get_properties ();
258
            std::vector<CdlProperty>::const_iterator property_i;
259
            // CMapStringToPtr map; // count of each property name
260
            wxHashTable map(wxKEY_STRING);  // count of each property name
261
 
262
            for (property_i = properties.begin (); property_i != properties.end (); property_i++) {// for each property
263
                // get the property name
264
                const CdlProperty &prop=*property_i;
265
                const wxString strName(prop->get_property_name ().c_str());
266
                enum {VISIBLE_PROPERTIES_COUNT=sizeof visible_properties/sizeof visible_properties[0]};
267
                if (std::find (visible_properties, visible_properties + VISIBLE_PROPERTIES_COUNT, ecUtils::UnicodeToStdStr(strName)) != visible_properties + VISIBLE_PROPERTIES_COUNT) {// if the property should be displayed
268
                    // set the property arguments
269
                    wxString strPropertyArgs;
270
                    const std::vector<std::string> & argv = prop->get_argv ();
271
                    void *p;
272
                    p = (void*) map.Delete(strName);
273
 
274
                    p=(void *)((int)p+1);
275
                    map.Put(strName, (wxObject*) p);
276
 
277
                    std::vector<std::string>::const_iterator argv_i;
278
                    for (argv_i = argv.begin (); argv_i != argv.end (); argv_i++){ // for each property argument...
279
                        if (argv_i != argv.begin ()){                              // ...except the first (the property name)
280
                            wxString strArg(ecUtils::StripExtraWhitespace (wxString(argv_i->c_str())));
281
                            if (strPropertyArgs.Len() + strArg.Len() + 1 > 256) {// if the string is too long for the list control
282
                                break; // no need to add any further arguments
283
                            }
284
                            strPropertyArgs += strArg; // add the argument to the string
285
                            strPropertyArgs += wxT (" "); // separate arguments by a space character
286
                        }
287
                    }
288
                    // the list control appears to display a maximum of 256 characters
289
                    int nIndex=SetItem(strName, strPropertyArgs, GetItemCount(), (int)p);
290
                    SetItemData(nIndex, (long) prop);
291
 
292
                    // display the exclamation icon if the property is in a conflicts list
293
                    bool bConflictItem =
294
                        //                                      PropertyInConflictsList (* property_i, config->get_structural_conflicts ()) || ignore for now
295
                        PropertyInConflictsList (prop, config->get_all_conflicts ());
296
 
297
                    // TODO: set the image for a conflict item
298
                    // CListCtrl::SetItem (nIndex, 0, LVIF_IMAGE, NULL, bConflictItem ? 1 : 0, 0, 0, 0 );
299
                }
300
            }
301
        }
302
 
303
        for(i=GetItemCount()-1;i>=0;--i){
304
            if(0==GetItemData(i)){
305
                DeleteItem(i);
306
                if(i<m_nFirstProperty){
307
                    m_nFirstProperty--;
308
                }
309
            }
310
        }
311
        // TODO
312
#if 0
313
        CRect rect;
314
        GetClientRect(rect);
315
        int nAvailWidth=rect.Width()-GetColumnWidth(0);
316
        int w=max(m_nMaxValueWidth,nAvailWidth);
317
        m_f[1]=double(w)/double(rect.Width());
318
        SetColumnWidth(1,w);
319
#endif
320
    }
321
 
322
    SetColumnWidth(1, wxLIST_AUTOSIZE); // resize the value column for the longest item
323
    if (GetColumnWidth(1) < 100)        // but at least wide enough for the column heading
324
        SetColumnWidth(1, 100);
325
 
326
    Refresh();
327
}
328
 
329
bool ecPropertyListCtrl::PropertyInConflictsList (CdlProperty property, const std::list<CdlConflict> & conflicts)
330
{
331
    std::list<CdlConflict>::const_iterator conf_i;
332
    for (conf_i = conflicts.begin (); conf_i != conflicts.end (); conf_i++) // for each conflict
333
        if (property == (* conf_i)->get_property ())
334
            return true;
335
 
336
        return false;
337
}
338
 
339
void ecPropertyListCtrl::RefreshValue()
340
{
341
    if (!m_pti)
342
        return;
343
 
344
    if (m_pti->HasBool ()){
345
        SetItem(ecEnabled, m_pti->IsEnabled () ? wxT("True") : wxT("False"));
346
    }
347
    if (m_pti->GetOptionType () != ecOptionTypeNone){
348
        SetItem(ecValue, m_pti->StringValue());
349
    }
350
    for (int nItem = m_nFirstProperty; nItem < GetItemCount (); nItem++)
351
    {
352
        CdlProperty property = (CdlProperty) GetItemData (nItem);
353
        wxASSERT (property);
354
 
355
        // display the exclamation icon if the property is in a conflicts list
356
        const CdlConfiguration config = wxGetApp().GetConfigToolDoc ()->GetCdlConfig ();
357
        bool bConflictItem =
358
            //                                          PropertyInConflictsList (property, config->get_structural_conflicts ()) || ignore for now
359
            PropertyInConflictsList (property, config->get_all_conflicts ());
360
 
361
        // TODO
362
        // CListCtrl::SetItem (nItem, 0, LVIF_IMAGE, NULL, bConflictItem ? 1 : 0, 0, 0, 0 );
363
    }
364
 
365
}
366
 
367
int ecPropertyListCtrl::SetItem(ecFieldType f, const wxString& value)
368
{
369
    int nIndex=SetItem(sm_fieldTypeImage[f], value, m_nFirstProperty);
370
    if(nIndex==m_nFirstProperty){
371
        m_nFirstProperty++;
372
    }
373
    SetItemData(nIndex,1);
374
    return nIndex;
375
}
376
 
377
int ecPropertyListCtrl::SetItem(const wxString& item, const wxString& value, int nInsertAs, int nRepeat)
378
{
379
    wxASSERT( nInsertAs <= GetItemCount() );
380
 
381
    int nIndex = -2;
382
    do {
383
        nIndex = FindItem(nIndex+1, item);
384
    } while (--nRepeat > 0 && nIndex != -1);
385
 
386
    if(-1==nIndex){
387
        nIndex = InsertItem(nInsertAs, item);
388
    }
389
 
390
    wxListCtrl::SetItem(nIndex, 1, value);
391
 
392
    // TODO
393
#if 0
394
    CDC *pDC=GetDC();
395
    CFont *pOldFont=pDC->SelectObject(GetFont());
396
    m_nMaxValueWidth=max(m_nMaxValueWidth,pDC->GetTextExtent(pszValue).cx);
397
    pDC->SelectObject(pOldFont);
398
    ReleaseDC(pDC);
399
#endif
400
 
401
    return nIndex;
402
}
403
 
404
void ecPropertyListCtrl::OnDoubleClick(wxMouseEvent& event)
405
{
406
    // Double-clicked the item
407
 
408
    int flags;
409
    long item = HitTest(event.GetPosition(), flags);
410
    if (item > -1)
411
    {
412
        const wxString strText = wxListCtrlGetItemTextColumn(*this, item,0);
413
        if(strText == wxT("File")){
414
            m_pti->ViewHeader();
415
        } else if (strText == wxT("URL")) {
416
            m_pti->ViewURL();
417
        }
418
    }
419
 
420
    // TODO
421
#if 0    
422
    int pos=GetMessagePos();
423
    CPoint pt(GET_X_LPARAM(pos),GET_Y_LPARAM(pos));
424
    ScreenToClient(&pt);
425
    int nItem=HitTest(pt,NULL);
426
 
427
    if(GetItemData(nItem)>1){
428
        // This is a property row
429
        const CdlGoalExpression goal = dynamic_cast<CdlGoalExpression> ((CdlProperty) GetItemData (nItem));
430
        if (goal){
431
            // This is a rule row
432
            const CdlExpression expression = goal->get_expression ();
433
            if (1 == expression->references.size ()) // if the property contains a single reference
434
            {
435
                // assume that the reference is to another user visible node and try to find it
436
                std::string macro_name = expression->references [0].get_destination_name ();
437
                CConfigItem * pItem = CConfigTool::GetConfigToolDoc ()->Find (CString (macro_name.c_str ()));
438
                if (pItem) // the referenced node was found so select it
439
                {
440
                    CConfigTool::GetControlView()->GetTreeCtrl().SelectItem(pItem->HItem());
441
                }
442
            }
443
        }
444
    } else {
445
        const CString strText(GetItemText(nItem,0));
446
        if(strText==FieldTypeImage[File]){
447
            m_pti->ViewHeader();
448
        } else if (strText==FieldTypeImage[URL]) {
449
            m_pti->ViewURL();
450
        }
451
    }
452
#endif
453
    event.Skip();
454
}

powered by: WebSVN 2.1.0

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