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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [standalone/] [wxwin/] [conflictwin.cpp] - Blame information for rev 637

Go to most recent revision | 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
// configtree.cpp :
26
//
27
//===========================================================================
28
//#####DESCRIPTIONBEGIN####
29
//
30
// Author(s):   julians
31
// Contact(s):  julians
32
// Date:        2000/09/04
33
// Version:     $Id: conflictwin.cpp,v 1.1.1.1 2004-02-14 13:28:51 phoenix Exp $
34
// Purpose:
35
// Description: Implementation file for ecConflictListCtrl
36
// Requires:
37
// Provides:
38
// See also:
39
// Known bugs:
40
// Usage:
41
//
42
//####DESCRIPTIONEND####
43
//
44
//===========================================================================
45
 
46
// ============================================================================
47
// declarations
48
// ============================================================================
49
 
50
// ----------------------------------------------------------------------------
51
// headers
52
// ----------------------------------------------------------------------------
53
#ifdef __GNUG__
54
    #pragma implementation "conflictwin.h"
55
#endif
56
 
57
// Includes other headers for precompiled compilation
58
#include "ecpch.h"
59
 
60
#ifdef __BORLANDC__
61
    #pragma hdrstop
62
#endif
63
 
64
#include "conflictwin.h"
65
#include "configtool.h"
66
#include "configtooldoc.h"
67
#include "configtree.h"
68
 
69
/*
70
 * ecConflictListCtrl
71
 */
72
 
73
IMPLEMENT_CLASS(ecConflictListCtrl, wxListCtrl)
74
 
75
BEGIN_EVENT_TABLE(ecConflictListCtrl, wxListCtrl)
76
    EVT_RIGHT_DOWN(ecConflictListCtrl::OnRightClick)
77
    EVT_LEFT_DCLICK(ecConflictListCtrl::OnLeftDClick)
78
 
79
    EVT_MENU(ecID_LOCATE_ITEM, ecConflictListCtrl::OnLocate)
80
    EVT_MENU(ecID_RESOLVE_ITEM, ecConflictListCtrl::OnResolve)
81
END_EVENT_TABLE()
82
 
83
ecConflictListCtrl::ecConflictListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
84
        const wxSize& sz, long style):
85
        wxListCtrl(parent, id, pt, sz, style)
86
{
87
    if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
88
         wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Conflicts")).Ok())
89
    {
90
        SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Conflicts")));
91
    }
92
 
93
    InsertColumn(0, "Item", wxLIST_FORMAT_LEFT, 200);
94
    InsertColumn(1, "Conflict", wxLIST_FORMAT_LEFT, 80);
95
    InsertColumn(2, "Property", wxLIST_FORMAT_LEFT, 200);
96
 
97
    m_contextMenu = new wxMenu;
98
    m_contextMenu->Append(ecID_WHATS_THIS, _("&What's This?"));
99
    m_contextMenu->AppendSeparator();
100
    m_contextMenu->Append(ecID_LOCATE_ITEM, _("&Locate"));
101
    m_contextMenu->Append(ecID_RESOLVE_ITEM, _("&Resolve"));
102
 
103
    m_contextItem = -1;
104
    m_contextCol = 0;
105
}
106
 
107
ecConflictListCtrl::~ecConflictListCtrl()
108
{
109
    delete m_contextMenu;
110
}
111
 
112
void ecConflictListCtrl::OnRightClick(wxMouseEvent& event)
113
{
114
    int flags = 0;
115
    long item = HitTest(wxPoint(event.GetX(), event.GetY()), flags);
116
 
117
    if (item >= 0 && !GetParent ()->IsKindOf (CLASSINFO(wxDialog)))  // this menu for conflicts view only
118
    {
119
        m_contextItem = item;
120
 
121
        // Find which column we're on
122
        m_contextCol = wxListCtrlFindColumn(*this, 3, event.GetX());
123
 
124
        // GetContextMenu()->SetClientData((void*) TRUE);
125
        PopupMenu(GetContextMenu(), event.GetX(), event.GetY());
126
    }
127
    else
128
    {
129
        m_contextItem = -1;
130
 
131
        PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
132
    }
133
}
134
 
135
void ecConflictListCtrl::OnLeftDClick(wxMouseEvent& event)
136
{
137
    if (!GetParent ()->IsKindOf (CLASSINFO(wxDialog)))  // handle double click for conflicts view only
138
    {
139
        long sel = wxListCtrlGetSelection(* this);
140
        if (sel >= 0)
141
        {
142
            // Find which column we're on
143
            int col = wxListCtrlFindColumn(*this, 3, event.GetX());
144
 
145
            ecConfigItem * pItem = AssociatedItem (sel, col); // get the referenced item
146
 
147
            if (pItem) { // if a referenced item was found
148
                wxGetApp().GetTreeCtrl()->SelectItem (pItem->GetTreeItem()); // select the refreenced item
149
            }
150
        }
151
    }
152
}
153
 
154
void ecConflictListCtrl::OnLocate(wxCommandEvent& event)
155
{
156
    if (m_contextItem > -1)
157
    {
158
        ecConfigItem * pItem = AssociatedItem (m_contextItem, m_contextCol); // get the referenced item
159
 
160
        if (pItem) { // if a referenced item was found
161
            wxGetApp().GetTreeCtrl()->SelectItem (pItem->GetTreeItem()); // select the refreenced item
162
        }
163
    }
164
}
165
 
166
void ecConflictListCtrl::OnResolve(wxCommandEvent& event)
167
{
168
    ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc();
169
 
170
    wxList conflictsOfInterest;
171
 
172
    long n = GetItemCount();
173
    long i;
174
    for (i = 0; i < n; i++)
175
    {
176
        if (GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED)
177
        {
178
            conflictsOfInterest.Append((wxObject*) (void*) GetItemData(i));
179
        }
180
    }
181
 
182
    pDoc->ResolveGlobalConflicts(& conflictsOfInterest);
183
}
184
 
185
 
186
void ecConflictListCtrl::AddConflict (const CdlConflict &conf)
187
{
188
    // set the item column string
189
    wxString strMacroName = (conf)->get_node ()->get_name ().c_str ();
190
    int nIndex = InsertItem (GetItemCount (), strMacroName);
191
 
192
    nIndex = GetItemCount() - 1;
193
 
194
    SetItemData (nIndex, (long) (conf));
195
 
196
    // set the conflict column string
197
    if (0 != dynamic_cast<CdlConflict_Unresolved> (conf)) {// a conflict of type 'unresolved'
198
        SetItem (nIndex, 1, wxT("Unresolved"));
199
    } else if (0 != dynamic_cast<CdlConflict_IllegalValue> (conf)) { // a conflict of type 'illegal value'
200
        SetItem (nIndex, 1, wxT("Illegal"));
201
    } else if (0 != dynamic_cast<CdlConflict_EvalException> (conf)) { // a conflict of type 'evaluation exception'
202
        SetItem (nIndex, 1, wxT("Exception"));
203
    } else if (0 != dynamic_cast<CdlConflict_Requires> (conf)) { // a conflict of type 'goal unsatisfied'
204
        SetItem (nIndex, 1, wxT("Unsatisfied"));
205
    } else if (0 != dynamic_cast<CdlConflict_Data> (conf)) { // a conflict of type 'bad data'
206
        SetItem (nIndex, 1, wxT("Bad data"));
207
    } else {
208
        wxASSERT (0);
209
    }
210
 
211
    // set the property column string
212
    wxString strProperty = conf->get_property ()->get_property_name ().c_str ();
213
    strProperty += wxT(" ");
214
    const std::vector<std::string> & argv = conf->get_property ()->get_argv ();
215
    std::vector<std::string>::const_iterator argv_i;
216
    for (argv_i = argv.begin (); argv_i != argv.end (); argv_i++) {// for each property argument...
217
        if (argv_i != argv.begin ())                              // ...except the first
218
        {
219
            strProperty += argv_i->c_str (); // add the argument to the string
220
            strProperty += wxT (" "); // separate arguments by a space character
221
        }
222
    }
223
    strProperty.Trim (TRUE); // remove the trailing space character
224
    SetItem (nIndex, 2, strProperty);
225
}
226
 
227
void ecConflictListCtrl::AddConflicts (const std::list<CdlConflict>& conflicts)
228
{
229
    for (std::list<CdlConflict>::const_iterator conf_i=conflicts.begin (); conf_i != conflicts.end (); conf_i++) {
230
        AddConflict(*conf_i);
231
    }
232
}
233
 
234
ecConfigItem *ecConflictListCtrl::AssociatedItem(int nRow,int nCol)
235
{
236
    const CdlConflict conflict = (CdlConflict) GetItemData (nRow);
237
    wxASSERT (conflict != NULL);
238
 
239
    ecConfigItem *pItem=NULL;
240
    switch(nCol)
241
    {
242
    case 2:
243
        {
244
            const CdlGoalExpression goal = dynamic_cast<CdlGoalExpression> (conflict->get_property ());
245
            if (! goal) // if the item is not a goal expression
246
                break; // do nothing
247
            const CdlExpression expression = goal->get_expression ();
248
            if (1 == expression->references.size ()) // if the property contains a single reference
249
            {
250
                // assume that the reference is to another user visible node and try to find it
251
                const wxString strName(expression->references [0].get_destination_name ().c_str());
252
                pItem = wxGetApp().GetConfigToolDoc ()->Find(strName);
253
            }
254
        }
255
        break;
256
    case 0:
257
        pItem = wxGetApp().GetConfigToolDoc ()->Find(wxString(conflict->get_node ()->get_name ().c_str()));
258
        break;
259
    default:
260
        break;
261
    }
262
    return pItem;
263
}
264
 
265
// This is taken from CRulesView::FillRules in the MFC version
266
void ecConflictListCtrl::FillRules()
267
{
268
    CdlConfiguration CdlConfig = wxGetApp().GetConfigToolDoc()->GetCdlConfig ();
269
    if (CdlConfig)
270
    { // if configuration information
271
        int nCount=0;
272
        bool bRefill=false;
273
        wxHashTable arMap(wxKEY_INTEGER);
274
        int i;
275
        for ( i = 0 ; i < GetItemCount(); i++)
276
        {
277
            arMap.Put(GetItemData(i), (wxObject*) i);
278
        }
279
 
280
        std::list<CdlConflict>::const_iterator conf_i;
281
 
282
        const std::list<CdlConflict>& conflicts=CdlConfig->get_all_conflicts();
283
        for (conf_i = conflicts.begin (); conf_i != conflicts.end (); conf_i++) { // for each conflict
284
            nCount++;
285
            if (!arMap.Get((long) * conf_i))
286
            {
287
                bRefill=true;
288
                break;
289
            }
290
        }
291
        //for (conf_i = CdlConfig->get_structural_conflicts().begin (); conf_i != CdlConfig->get_structural_conflicts().end (); conf_i++) { // for each conflict
292
        //  nCount++;
293
        //  if(!arMap.Lookup(*conf_i,w)){
294
        //    bRefill=true;
295
        //    break;
296
        //  }
297
        //}
298
        if(bRefill || nCount != GetItemCount())
299
        {
300
            DeleteAllItems();
301
            //m_List.AddConflicts(CdlConfig->get_structural_conflicts());
302
            AddConflicts(CdlConfig->get_all_conflicts());
303
        }
304
    }
305
}
306
 
307
#if 0
308
int CRulesList::CompareFunc(LPARAM lParam1, LPARAM lParam2)
309
{
310
        LV_FINDINFO find1 = { LVFI_PARAM, NULL, lParam1, NULL, NULL };
311
        LV_FINDINFO find2 = { LVFI_PARAM, NULL, lParam2, NULL, NULL };
312
        const int nIndex1 = FindItem (&find1);
313
        const int nIndex2 = FindItem (&find2);
314
        const CString str1 = GetItemText (nIndex1, m_nLastCol & 0x7fffffff);
315
        const CString str2 = GetItemText (nIndex2, m_nLastCol & 0x7fffffff);
316
        return (m_nLastCol & 0x80000000) ^ str1.Compare (str2);
317
}
318
 
319
void CRulesList::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
320
{
321
        NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
322
        LPARAM nCol=pNMListView->iSubItem;
323
        if((nCol&0x7fffffff)==(0x7fffffff&m_nLastCol)){
324
                nCol=m_nLastCol^0x80000000;
325
        }
326
  m_nLastCol=nCol;
327
        SortItems(CompareFunc,(DWORD)this);
328
 
329
        *pResult = 0;
330
}
331
 
332
void CRulesList::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
333
{
334
  if (GetParent ()->IsKindOf (RUNTIME_CLASS (CRulesView))) { // handle double click for conflicts view only
335
    NM_LISTVIEW * pNMListView = (NM_LISTVIEW *) pNMHDR;
336
    int nItem = pNMListView->iItem;
337
    if (-1 != nItem) { // if the double click was on a row of the list
338
      CConfigItem * pItem = AssociatedItem (nItem, pNMListView->iSubItem); // get the referenced item
339
      if (pItem) { // if a referenced item was found
340
        CConfigTool::GetControlView ()->SelectItem (pItem); // select the refreenced item
341
      }
342
    }
343
  }
344
 
345
  *pResult = 0;
346
  UNUSED_ALWAYS(pNMHDR);
347
}
348
 
349
#endif

powered by: WebSVN 2.1.0

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