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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [common/] [win32/] [RulesList.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
// RulesView.cpp : implementation file
26
//
27
 
28
#include "stdafx.h"
29
#include "ConfigToolDoc.h"
30
#include "RulesList.h"
31
 
32
#include "RulesView.h"
33
#include "ControlView.h"
34
#include "ConfigItem.h"
35
#include "ConfigTool.h"
36
 
37
#define INCLUDEFILE <string>
38
#include "IncludeSTL.h"
39
 
40
#ifdef _DEBUG
41
#define new DEBUG_NEW
42
#undef THIS_FILE
43
static char THIS_FILE[] = __FILE__;
44
#endif
45
 
46
/////////////////////////////////////////////////////////////////////////////
47
// CRulesList
48
 
49
CRulesList::CRulesList():
50
  m_nLastCol(0x7fffffff),
51
  m_fWidth(0.0)
52
{
53
  m_f[0]=3.0/7.0;
54
  m_f[1]=1.0/7.0;
55
  m_f[2]=3.0/7.0;
56
}
57
 
58
CRulesList::~CRulesList()
59
{
60
}
61
 
62
BEGIN_MESSAGE_MAP(CRulesList, CTTListCtrl)
63
        //{{AFX_MSG_MAP(CRulesList)
64
        ON_WM_CREATE()
65
        ON_WM_SIZE()
66
        ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
67
        ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
68
  ON_NOTIFY(HDN_ENDTRACKW, 0, OnEndTrack)
69
        //}}AFX_MSG_MAP
70
END_MESSAGE_MAP()
71
 
72
/////////////////////////////////////////////////////////////////////////////
73
// CRulesList drawing
74
 
75
/////////////////////////////////////////////////////////////////////////////
76
// CRulesList message handlers
77
 
78
void CRulesList::AddConflict (const CdlConflict &conf)
79
{
80
  // set the item column string
81
  CString strMacroName = (conf)->get_node ()->get_name ().c_str ();
82
  int nIndex = InsertItem (GetItemCount (), strMacroName);
83
  SetItemData (nIndex, (DWORD) (conf));
84
 
85
  // set the conflict column string
86
  if (0 != dynamic_cast<CdlConflict_Unresolved> (conf)) {// a conflict of type 'unresolved'
87
    SetItemText (nIndex, 1, _T("Unresolved"));
88
  } else if (0 != dynamic_cast<CdlConflict_IllegalValue> (conf)) { // a conflict of type 'illegal value'
89
    SetItemText (nIndex, 1, _T("Illegal"));
90
  } else if (0 != dynamic_cast<CdlConflict_EvalException> (conf)) { // a conflict of type 'evaluation exception'
91
    SetItemText (nIndex, 1, _T("Exception"));
92
  } else if (0 != dynamic_cast<CdlConflict_Requires> (conf)) { // a conflict of type 'goal unsatisfied'
93
    SetItemText (nIndex, 1, _T("Unsatisfied"));
94
  } else if (0 != dynamic_cast<CdlConflict_Data> (conf)) { // a conflict of type 'bad data'
95
    SetItemText (nIndex, 1, _T("Bad data"));
96
  } else {
97
    ASSERT (0);
98
  }
99
 
100
        // set the property column string
101
        CString strProperty = conf->get_property ()->get_property_name ().c_str ();
102
        strProperty += _T(" ");
103
        const std::vector<std::string> & argv = conf->get_property ()->get_argv ();
104
        std::vector<std::string>::const_iterator argv_i;
105
  for (argv_i = argv.begin (); argv_i != argv.end (); argv_i++) {// for each property argument...
106
    if (argv_i != argv.begin ())                              // ...except the first
107
    {
108
      strProperty += argv_i->c_str (); // add the argument to the string
109
      strProperty += _T (" "); // separate arguments by a space character
110
    }
111
  }
112
        strProperty.TrimRight (); // remove the trailing space character
113
        SetItemText (nIndex, 2, strProperty);
114
}
115
 
116
int CRulesList::OnCreate(LPCREATESTRUCT lpCreateStruct)
117
{
118
  lpCreateStruct->style|=LVS_REPORT;
119
        if (CTTListCtrl::OnCreate(lpCreateStruct) == -1)
120
                return -1;
121
        SetExtendedStyle(LVS_EX_FULLROWSELECT);
122
 
123
        InsertColumn(0,_T("Item"),        LVCFMT_LEFT,0,0);
124
        InsertColumn(1,_T("Conflict"),LVCFMT_LEFT,0,1);
125
        InsertColumn(2,_T("Property"),LVCFMT_LEFT,0,2);
126
 
127
  return 0;
128
}
129
 
130
void CRulesList::OnSize(UINT nType, int cx, int cy)
131
{
132
        CTTListCtrl::OnSize(nType, cx, cy);
133
  m_fWidth=cx;
134
  for(int i=0;i<NCOLS;i++){
135
          SetColumnWidth(i,int(cx*m_f[i]));
136
  }
137
}
138
 
139
int CRulesList::CompareFunc(LPARAM lParam1, LPARAM lParam2)
140
{
141
        LV_FINDINFO find1 = { LVFI_PARAM, NULL, lParam1, NULL, NULL };
142
        LV_FINDINFO find2 = { LVFI_PARAM, NULL, lParam2, NULL, NULL };
143
        const int nIndex1 = FindItem (&find1);
144
        const int nIndex2 = FindItem (&find2);
145
        const CString str1 = GetItemText (nIndex1, m_nLastCol & 0x7fffffff);
146
        const CString str2 = GetItemText (nIndex2, m_nLastCol & 0x7fffffff);
147
        return (m_nLastCol & 0x80000000) ^ str1.Compare (str2);
148
}
149
 
150
void CRulesList::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
151
{
152
        NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
153
        LPARAM nCol=pNMListView->iSubItem;
154
        if((nCol&0x7fffffff)==(0x7fffffff&m_nLastCol)){
155
                nCol=m_nLastCol^0x80000000;
156
        }
157
  m_nLastCol=nCol;
158
        SortItems(CompareFunc,(DWORD)this);
159
 
160
        *pResult = 0;
161
}
162
 
163
void CRulesList::OnEndTrack(NMHEADER *pNMHeader, LRESULT*)
164
{
165
  m_f[pNMHeader->iItem]=pNMHeader->pitem->cxy/m_fWidth;
166
}
167
 
168
void CRulesList::AddConflicts (const std::list<CdlConflict>& conflicts)
169
{
170
  for (std::list<CdlConflict>::const_iterator conf_i=conflicts.begin (); conf_i != conflicts.end (); conf_i++) {
171
    AddConflict(*conf_i);
172
  }
173
}
174
 
175
void CRulesList::AddConflicts (const std::vector<CdlConflict>& conflicts)
176
{
177
  for (std::vector<CdlConflict>::const_iterator conf_i=conflicts.begin (); conf_i != conflicts.end (); conf_i++) {
178
    AddConflict(*conf_i);
179
  }
180
}
181
 
182
void CRulesList::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
183
{
184
  if (GetParent ()->IsKindOf (RUNTIME_CLASS (CRulesView))) { // handle double click for conflicts view only
185
    NM_LISTVIEW * pNMListView = (NM_LISTVIEW *) pNMHDR;
186
    int nItem = pNMListView->iItem;
187
    if (-1 != nItem) { // if the double click was on a row of the list
188
      CConfigItem * pItem = AssociatedItem (nItem, pNMListView->iSubItem); // get the referenced item
189
      if (pItem) { // if a referenced item was found
190
        CConfigTool::GetControlView ()->SelectItem (pItem); // select the refreenced item
191
      }
192
    }
193
  }
194
 
195
  *pResult = 0;
196
  UNUSED_ALWAYS(pNMHDR);
197
}
198
 
199
CConfigItem *CRulesList::AssociatedItem(int nRow,int nCol)
200
{
201
  const CdlConflict conflict = (CdlConflict) GetItemData (nRow);
202
  ASSERT (conflict);
203
 
204
  CConfigItem *pItem=NULL;
205
  switch(nCol){
206
    case 2:
207
      {
208
        const CdlGoalExpression goal = dynamic_cast<CdlGoalExpression> (conflict->get_property ());
209
        if (! goal) // if the item is not a goal expression
210
          break; // do nothing
211
        const CdlExpression expression = goal->get_expression ();
212
        if (1 == expression->references.size ()) // if the property contains a single reference
213
                {
214
          // assume that the reference is to another user visible node and try to find it
215
          const CString strName(expression->references [0].get_destination_name ().c_str());
216
          pItem = CConfigTool::GetConfigToolDoc ()->Find(strName);
217
        }
218
      }
219
      break;
220
    case 0:
221
      pItem = CConfigTool::GetConfigToolDoc ()->Find(CString(conflict->get_node ()->get_name ().c_str()));
222
      break;
223
    default:
224
      break;
225
  }
226
  return pItem;
227
}

powered by: WebSVN 2.1.0

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