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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [common/] [win32/] [PropertiesList.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
// PropertiesView2.cpp : implementation file
23
//
24
//
25
//===========================================================================
26
//#####DESCRIPTIONBEGIN####
27
//
28
// Author(s):   sdf
29
// Contact(s):  sdf
30
// Date:                1998/08/11
31
// Version:             0.01
32
// Purpose:     
33
// Description: This is the implementation of the properties window view.
34
// Requires:    
35
// Provides:    
36
// See also:    
37
// Known bugs:  
38
// Usage:       
39
//
40
//####DESCRIPTIONEND####
41
//
42
//===========================================================================
43
 
44
#include "stdafx.h"
45
#include "PropertiesList.h"
46
#include "ConfigToolDoc.h"
47
#include "ConfigItem.H"
48
 
49
#include "CTUtils.h"
50
#include "ControlView.h"
51
#include "ConfigTool.h"
52
 
53
#define INCLUDEFILE <string>
54
#include "IncludeSTL.h"
55
 
56
#ifdef _DEBUG
57
#define new DEBUG_NEW
58
#undef THIS_FILE
59
static char THIS_FILE[] = __FILE__;
60
#endif
61
 
62
 
63
// specify the CDL properties which are to be visible in the properties view
64
const std::string CPropertiesList::visible_properties [] =
65
{
66
        CdlPropertyId_ActiveIf,
67
        CdlPropertyId_BuildProc,
68
        CdlPropertyId_Calculated,
69
        CdlPropertyId_CancelProc,
70
        CdlPropertyId_CheckProc,
71
        CdlPropertyId_Compile,
72
        CdlPropertyId_ConfirmProc,
73
        CdlPropertyId_DecorationProc,
74
        CdlPropertyId_DefaultValue,
75
        CdlPropertyId_Define,
76
        CdlPropertyId_DefineHeader,
77
        CdlPropertyId_DefineProc,
78
//      CdlPropertyId_Description,
79
        CdlPropertyId_Dialog,
80
//      CdlPropertyId_Display,
81
        CdlPropertyId_DisplayProc,
82
        CdlPropertyId_Doc,
83
        CdlPropertyId_EntryProc,
84
        CdlPropertyId_Flavor,
85
        CdlPropertyId_DefineFormat,
86
        CdlPropertyId_Group,
87
        CdlPropertyId_Hardware,
88
        CdlPropertyId_IfDefine,
89
        CdlPropertyId_Implements,
90
        CdlPropertyId_IncludeDir,
91
        CdlPropertyId_IncludeFiles,
92
        CdlPropertyId_InitProc,
93
        CdlPropertyId_InstallProc,
94
        CdlPropertyId_LegalValues,
95
        CdlPropertyId_Library,
96
        CdlPropertyId_LicenseProc,
97
        CdlPropertyId_Make,
98
        CdlPropertyId_Makefile,
99
        CdlPropertyId_MakeObject,
100
        CdlPropertyId_NoDefine,
101
        CdlPropertyId_Object,
102
        CdlPropertyId_Parent,
103
        CdlPropertyId_Requires,
104
        CdlPropertyId_Screen,
105
        CdlPropertyId_Script,
106
        CdlPropertyId_UpdateProc,
107
        CdlPropertyId_Wizard
108
};
109
 
110
/////////////////////////////////////////////////////////////////////////////
111
// CPropertiesList
112
 
113
CPropertiesList::CPropertiesList() :
114
  m_pti(NULL),
115
  m_nFirstProperty(0),
116
  m_nOnSizeRecursionCount(0)
117
{
118
  m_f[0]=0.25;
119
  m_f[1]=0.75;
120
  m_GrayPen.CreatePen(PS_SOLID,1,RGB(192,192,192));
121
}
122
 
123
CPropertiesList::~CPropertiesList()
124
{
125
}
126
//CListCtrl
127
 
128
BEGIN_MESSAGE_MAP(CPropertiesList, CListCtrl)
129
        //{{AFX_MSG_MAP(CPropertiesList)
130
  ON_NOTIFY(HDN_ENDTRACKW, 0, OnEndTrack)
131
        ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
132
        ON_WM_CREATE()
133
        ON_WM_SIZE()
134
        ON_WM_PAINT()
135
        ON_NOTIFY_REFLECT(HDN_TRACK, OnTrack)
136
        //}}AFX_MSG_MAP
137
END_MESSAGE_MAP()
138
 
139
const LPCTSTR CPropertiesList::FieldTypeImage[MAXFIELDTYPE]=
140
        {_T("Type"), _T("Value"), _T("Default"), _T("Macro"), _T("File"), _T("URL"), _T("Enabled")};
141
 
142
/////////////////////////////////////////////////////////////////////////////
143
// CPropertiesList message handlers
144
 
145
void CPropertiesList::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
146
{
147
 
148
  // Double-clicked the item    
149
 
150
  // We do not use the parameters on the OnDblClk handlers in order to preserve compatibility
151
  // between pre- and post-4.71 comctrl32.dll versions.
152
 
153
  int pos=GetMessagePos();
154
  CPoint pt(GET_X_LPARAM(pos),GET_Y_LPARAM(pos));
155
  ScreenToClient(&pt);
156
  int nItem=HitTest(pt,NULL);
157
 
158
  if(GetItemData(nItem)>1){
159
    // This is a property row
160
    const CdlGoalExpression goal = dynamic_cast<CdlGoalExpression> ((CdlProperty) GetItemData (nItem));
161
    if (goal){
162
      // This is a rule row
163
      const CdlExpression expression = goal->get_expression ();
164
      if (1 == expression->references.size ()) // if the property contains a single reference
165
      {
166
        // assume that the reference is to another user visible node and try to find it
167
        std::string macro_name = expression->references [0].get_destination_name ();
168
        CConfigItem * pItem = CConfigTool::GetConfigToolDoc ()->Find (CString (macro_name.c_str ()));
169
        if (pItem) // the referenced node was found so select it
170
        {
171
          CConfigTool::GetControlView()->GetTreeCtrl().SelectItem(pItem->HItem());
172
        }
173
      }
174
    }
175
  } else {
176
    const CString strText(GetItemText(nItem,0));
177
    if(strText==FieldTypeImage[File]){
178
      m_pti->ViewHeader();
179
    } else if (strText==FieldTypeImage[URL]) {
180
      m_pti->ViewURL();
181
    }
182
  }
183
 
184
        UNUSED_ALWAYS(pResult);
185
        UNUSED_ALWAYS(pNMHDR);
186
}
187
void CPropertiesList::OnPaint()
188
{
189
        // Default painting
190
  Default();
191
 
192
        // Draw the grid
193
        int nItems=GetItemCount();
194
        if(nItems>0){
195
                CDC &dc=*GetDC(); // device context for painting
196
    CRect rcHeader;
197
    GetHeaderCtrl()->GetClientRect(rcHeader);
198
    dc.ExcludeClipRect(rcHeader);
199
                CFont *pOldFont=dc.SelectObject(GetFont());
200
    CPen *pOldPen=dc.SelectObject(&m_GrayPen);
201
 
202
    CRect rect;
203
                GetItemRect(0,rect,LVIR_BOUNDS);
204
 
205
    int cy=rect.top-1;
206
                int dy=rect.Height();
207
 
208
    // This prevents the vertical line leaving shadows when column dragging occurs
209
    rect.top--;
210
    rect.bottom=rect.top+1;
211
    dc.FillSolidRect(rect,GetSysColor(COLOR_WINDOW));
212
 
213
                // Vertical line
214
                GetItemRect(0,rect,LVIR_LABEL);
215
 
216
    dc.MoveTo(rect.right-1,cy-1);
217
                dc.LineTo(rect.right-1,cy+dy*nItems);
218
 
219
    GetClientRect(rect);
220
    int cx=rect.Width();
221
 
222
    for(int i=0;i<nItems;i++){
223
                        cy+=dy;
224
                        dc.MoveTo(0,cy);
225
                        dc.LineTo(cx,cy);
226
                }
227
 
228
                dc.SelectObject(pOldPen);
229
                dc.SelectObject(pOldFont);
230
 
231
                ReleaseDC(&dc);
232
        }
233
}
234
 
235
void CPropertiesList::Fill(CConfigItem *pti)
236
{
237
  if(NULL==pti){
238
    DeleteAllItems();
239
    m_nFirstProperty=0;
240
    m_pti=NULL;
241
  } else if(pti!=m_pti){
242
    m_pti=pti;
243
    m_nMaxValueWidth=0;
244
    CConfigItem::TreeItemType type=m_pti->Type();
245
    int i;
246
 
247
    // Initially flag all items as unnecessary - calls of SetItem or SetProperty will change this
248
    for(i=GetItemCount()-1;i>=0;--i){
249
      SetItemData(i,0);
250
    }
251
          if (m_pti->HasBool () || (CConfigItem::None!=type)){
252
      SetItem(Macro, m_pti->Macro ());
253
    }
254
 
255
    if (m_pti->HasBool ()){
256
      SetItem(Enabled,m_pti->IsEnabled() ? _T("True") : _T("False"));
257
    }
258
 
259
    if(!m_pti->FileName().IsEmpty()){
260
      SetItem(File,m_pti->FileName());
261
    }
262
    SetItem(URL,m_pti->GetURL());
263
 
264
    if(CConfigItem::None!=type){
265
      switch(type){
266
        case CConfigItem::String:
267
          SetItem(Value,m_pti->StringValue());
268
          SetItem(DefaultValue,m_pti->StringDefaultValue());
269
          break;
270
        case CConfigItem::Integer:
271
          SetItem(Value,CUtils::IntToStr(m_pti->Value(),CConfigTool::GetConfigToolDoc()->m_bHex));
272
          SetItem(DefaultValue,CUtils::IntToStr(m_pti->DefaultValue(),CConfigTool::GetConfigToolDoc()->m_bHex));
273
          break;
274
        case CConfigItem::Double:
275
          SetItem(Value,CUtils::DoubleToStr(m_pti->DoubleValue()));
276
          SetItem(DefaultValue,CUtils::DoubleToStr(m_pti->DoubleDefaultValue()));
277
          break;
278
        case CConfigItem::Enum:
279
          SetItem(Value,m_pti->StringValue());
280
          SetItem(DefaultValue,m_pti->StringDefaultValue());
281
          break;
282
        default:
283
          ASSERT(FALSE);
284
          break;
285
      }
286
      SetItem(Type,CConfigItem::TreeItemTypeImage[type]);
287
    }
288
 
289
    // List all the properties applicable to me
290
    const std::string name = CUtils::UnicodeToStdStr (m_pti->Macro ());
291
    if (name.size () > 0)
292
    {
293
      const CdlConfiguration config = CConfigTool::GetConfigToolDoc ()->GetCdlConfig ();
294
      const CdlNode node = config->find_node (name, true);
295
      ASSERT (node);
296
      const std::vector<CdlProperty> & properties = node->get_properties ();
297
      std::vector<CdlProperty>::const_iterator property_i;
298
      CMapStringToPtr map; // count of each property name
299
      for (property_i = properties.begin (); property_i != properties.end (); property_i++) {// for each property
300
        // get the property name
301
        const CdlProperty &prop=*property_i;
302
        const CString strName(prop->get_property_name ().c_str());
303
        enum {VISIBLE_PROPERTIES_COUNT=sizeof visible_properties/sizeof visible_properties[0]};
304
        if (std::find (visible_properties, visible_properties + VISIBLE_PROPERTIES_COUNT, CUtils::UnicodeToStdStr(strName)) != visible_properties + VISIBLE_PROPERTIES_COUNT) {// if the property should be displayed
305
          // set the property arguments
306
          CString strPropertyArgs;
307
          const std::vector<std::string> & argv = prop->get_argv ();
308
          void *p;
309
          if(!map.Lookup(strName,p)){
310
            p=0;
311
          }
312
 
313
          p=(void *)((int)p+1);
314
          map.SetAt(strName,p);
315
 
316
          std::vector<std::string>::const_iterator argv_i;
317
          for (argv_i = argv.begin (); argv_i != argv.end (); argv_i++){ // for each property argument...
318
            if (argv_i != argv.begin ()){                              // ...except the first (the property name)
319
              CString strArg(CUtils::StripExtraWhitespace (CString(argv_i->c_str())));
320
              if (strPropertyArgs.GetLength () + strArg.GetLength() + 1 > 256) {// if the string is too long for the list control
321
                break; // no need to add any further arguments
322
              }
323
              strPropertyArgs += strArg; // add the argument to the string
324
              strPropertyArgs += _T (" "); // separate arguments by a space character
325
            }
326
          }
327
          // the list control appears to display a maximum of 256 characters
328
          int nIndex=SetItem(strName,strPropertyArgs,GetItemCount(),(int)p);
329
          SetItemData(nIndex,(DWORD)prop);
330
 
331
          // display the exclamation icon if the property is in a conflicts list
332
          bool bConflictItem =
333
            //                                  PropertyInConflictsList (* property_i, config->get_structural_conflicts ()) || ignore for now
334
            PropertyInConflictsList (prop, config->get_all_conflicts ());
335
          CListCtrl::SetItem (nIndex, 0, LVIF_IMAGE, NULL, bConflictItem ? 1 : 0, 0, 0, 0 );
336
        }
337
      }
338
    }
339
 
340
    for(i=GetItemCount()-1;i>=0;--i){
341
      if(0==GetItemData(i)){
342
        DeleteItem(i);
343
        if(i<m_nFirstProperty){
344
          m_nFirstProperty--;
345
        }
346
      }
347
    }
348
    CRect rect;
349
    GetClientRect(rect);
350
    int nAvailWidth=rect.Width()-GetColumnWidth(0);
351
    int w=max(m_nMaxValueWidth,nAvailWidth);
352
    m_f[1]=double(w)/double(rect.Width());
353
    SetColumnWidth(1,w);
354
  }
355
}
356
 
357
 
358
bool CPropertiesList::PropertyInConflictsList (CdlProperty property, const std::list<CdlConflict> & conflicts)
359
{
360
        std::list<CdlConflict>::const_iterator conf_i;
361
    for (conf_i = conflicts.begin (); conf_i != conflicts.end (); conf_i++) // for each conflict
362
                if (property == (* conf_i)->get_property ())
363
                        return true;
364
 
365
        return false;
366
}
367
 
368
// set item text in the properties list control, extending the list if necessary
369
int CPropertiesList::SetItemTextGrow(int nItem, LPCTSTR lpszItem)
370
{
371
        while (GetItemCount () < nItem + 1)
372
        {
373
    int n=InsertItem (GetItemCount (), _T(""));
374
                if (-1 == n){
375
                        return -1;
376
                }
377
        }
378
        return SetItemText (nItem, 0, lpszItem);
379
}
380
 
381
 
382
int CPropertiesList::OnCreate(LPCREATESTRUCT lpCreateStruct)
383
{
384
  lpCreateStruct->style|=WS_HSCROLL|WS_VSCROLL|LVS_REPORT|LVS_REPORT|LVS_SINGLESEL;
385
        if (CListCtrl::OnCreate(lpCreateStruct) == -1)
386
                return -1;
387
 
388
  //GetHeaderCtrl()->ModifyStyle(HDS_FULLDRAG,0,0); // remove HDS_FULLDRAG style from header
389
 
390
        ListView_SetExtendedListViewStyle(GetSafeHwnd(),/*LVS_EX_GRIDLINES|*/LVS_EX_FULLROWSELECT/*|LVS_EX_ONECLICKACTIVATE*//*|LVS_EX_TRACKSELECT*/);
391
        InsertColumn(0,_T("Property"),LVCFMT_LEFT,0,0);
392
        InsertColumn(1,_T("Value"),LVCFMT_LEFT,0,1);
393
 
394
        return 0;
395
}
396
 
397
 
398
void CPropertiesList::OnSize(UINT nType, int cx, int cy)
399
{
400
        CListCtrl::OnSize(nType, cx, cy);
401
  if(0==m_nOnSizeRecursionCount++){//prevent recursion
402
    m_fWidth=cx;
403
    for(int i=0;i<NCOLS;i++){
404
            SetColumnWidth(i,int(cx*m_f[i]));
405
    }
406
  }
407
  m_nOnSizeRecursionCount--;
408
}
409
 
410
void CPropertiesList::OnEndTrack(NMHEADER *pNMHeader, LRESULT*)
411
{
412
  m_f[pNMHeader->iItem]=pNMHeader->pitem->cxy/m_fWidth;
413
}
414
 
415
void CPropertiesList::OnTrack(NMHEADER*, LRESULT*)
416
{
417
  CRect rect;
418
  GetItemRect(0,rect,LVIR_BOUNDS);
419
  rect.bottom=rect.top+2;
420
  InvalidateRect(rect);
421
}
422
 
423
void CPropertiesList::RefreshValue()
424
{
425
  if (m_pti->HasBool ()){
426
                SetItem(CPropertiesList::Enabled, m_pti->IsEnabled () ? _T("True") : _T("False"));
427
  }
428
  if (m_pti->Type () != CConfigItem::None){
429
                SetItem(CPropertiesList::Value,m_pti->StringValue());
430
  }
431
        for (int nItem = m_nFirstProperty; nItem < GetItemCount (); nItem++)
432
        {
433
                CdlProperty property = (CdlProperty) GetItemData (nItem);
434
                ASSERT (property);
435
 
436
                // display the exclamation icon if the property is in a conflicts list
437
                const CdlConfiguration config = CConfigTool::GetConfigToolDoc ()->GetCdlConfig ();
438
                bool bConflictItem =
439
//                                              PropertyInConflictsList (property, config->get_structural_conflicts ()) || ignore for now
440
                        PropertyInConflictsList (property, config->get_all_conflicts ());
441
    CListCtrl::SetItem (nItem, 0, LVIF_IMAGE, NULL, bConflictItem ? 1 : 0, 0, 0, 0 );
442
        }
443
 
444
}
445
 
446
int CPropertiesList::SetItem(FieldType f, LPCTSTR pszValue)
447
{
448
  int nIndex=SetItem(FieldTypeImage[f],pszValue,m_nFirstProperty);
449
  if(nIndex==m_nFirstProperty){
450
    m_nFirstProperty++;
451
  }
452
  SetItemData(nIndex,1);
453
  return nIndex;
454
}
455
 
456
int CPropertiesList::SetItem(LPCTSTR pszItem, LPCTSTR pszValue, int nInsertAs,int nRepeat)
457
{
458
  ASSERT(nInsertAs<=GetItemCount());
459
  LVFINDINFO info;
460
  info.flags =LVFI_STRING;
461
  info.psz   =pszItem;
462
  info.vkDirection=VK_DOWN;
463
  int nIndex=-1;
464
  do {
465
    nIndex=FindItem(&info,nIndex);
466
  } while (--nRepeat>0 && nIndex!=-1);
467
 
468
  if(-1==nIndex){
469
    nIndex=InsertItem(nInsertAs,pszItem);
470
  }
471
 
472
  SetItemText(nIndex,1,pszValue);
473
  CDC *pDC=GetDC();
474
  CFont *pOldFont=pDC->SelectObject(GetFont());
475
  m_nMaxValueWidth=max(m_nMaxValueWidth,pDC->GetTextExtent(pszValue).cx);
476
        pDC->SelectObject(pOldFont);
477
        ReleaseDC(pDC);
478
  return nIndex;
479
 
480
}

powered by: WebSVN 2.1.0

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