1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
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)
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
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.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
35 // Description: Implementation file for ecConflictListCtrl
42 //####DESCRIPTIONEND####
44 //===========================================================================
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #pragma implementation "conflictwin.h"
57 // Includes other headers for precompiled compilation
64 #include "conflictwin.h"
65 #include "configtool.h"
66 #include "configtooldoc.h"
67 #include "configtree.h"
73 IMPLEMENT_CLASS(ecConflictListCtrl, wxListCtrl)
75 BEGIN_EVENT_TABLE(ecConflictListCtrl, wxListCtrl)
76 EVT_RIGHT_DOWN(ecConflictListCtrl::OnRightClick)
77 EVT_LEFT_DCLICK(ecConflictListCtrl::OnLeftDClick)
79 EVT_MENU(ecID_LOCATE_ITEM, ecConflictListCtrl::OnLocate)
80 EVT_MENU(ecID_RESOLVE_ITEM, ecConflictListCtrl::OnResolve)
83 ecConflictListCtrl::ecConflictListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
84 const wxSize& sz, long style):
85 wxListCtrl(parent, id, pt, sz, style)
87 if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
88 wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Conflicts")).Ok())
90 SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Conflicts")));
93 InsertColumn(0, "Item", wxLIST_FORMAT_LEFT, 200);
94 InsertColumn(1, "Conflict", wxLIST_FORMAT_LEFT, 80);
95 InsertColumn(2, "Property", wxLIST_FORMAT_LEFT, 200);
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"));
107 ecConflictListCtrl::~ecConflictListCtrl()
109 delete m_contextMenu;
112 void ecConflictListCtrl::OnRightClick(wxMouseEvent& event)
115 long item = HitTest(wxPoint(event.GetX(), event.GetY()), flags);
117 if (item >= 0 && !GetParent ()->IsKindOf (CLASSINFO(wxDialog))) // this menu for conflicts view only
119 m_contextItem = item;
121 // Find which column we're on
122 m_contextCol = wxListCtrlFindColumn(*this, 3, event.GetX());
124 // GetContextMenu()->SetClientData((void*) TRUE);
125 PopupMenu(GetContextMenu(), event.GetX(), event.GetY());
131 PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
135 void ecConflictListCtrl::OnLeftDClick(wxMouseEvent& event)
137 if (!GetParent ()->IsKindOf (CLASSINFO(wxDialog))) // handle double click for conflicts view only
139 long sel = wxListCtrlGetSelection(* this);
142 // Find which column we're on
143 int col = wxListCtrlFindColumn(*this, 3, event.GetX());
145 ecConfigItem * pItem = AssociatedItem (sel, col); // get the referenced item
147 if (pItem) { // if a referenced item was found
148 wxGetApp().GetTreeCtrl()->SelectItem (pItem->GetTreeItem()); // select the refreenced item
154 void ecConflictListCtrl::OnLocate(wxCommandEvent& event)
156 if (m_contextItem > -1)
158 ecConfigItem * pItem = AssociatedItem (m_contextItem, m_contextCol); // get the referenced item
160 if (pItem) { // if a referenced item was found
161 wxGetApp().GetTreeCtrl()->SelectItem (pItem->GetTreeItem()); // select the refreenced item
166 void ecConflictListCtrl::OnResolve(wxCommandEvent& event)
168 ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc();
170 wxList conflictsOfInterest;
172 long n = GetItemCount();
174 for (i = 0; i < n; i++)
176 if (GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED)
178 conflictsOfInterest.Append((wxObject*) (void*) GetItemData(i));
182 pDoc->ResolveGlobalConflicts(& conflictsOfInterest);
186 void ecConflictListCtrl::AddConflict (const CdlConflict &conf)
188 // set the item column string
189 wxString strMacroName = (conf)->get_node ()->get_name ().c_str ();
190 int nIndex = InsertItem (GetItemCount (), strMacroName);
192 nIndex = GetItemCount() - 1;
194 SetItemData (nIndex, (long) (conf));
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"));
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
219 strProperty += argv_i->c_str (); // add the argument to the string
220 strProperty += wxT (" "); // separate arguments by a space character
223 strProperty.Trim (TRUE); // remove the trailing space character
224 SetItem (nIndex, 2, strProperty);
227 void ecConflictListCtrl::AddConflicts (const std::list<CdlConflict>& conflicts)
229 for (std::list<CdlConflict>::const_iterator conf_i=conflicts.begin (); conf_i != conflicts.end (); conf_i++) {
230 AddConflict(*conf_i);
234 ecConfigItem *ecConflictListCtrl::AssociatedItem(int nRow,int nCol)
236 const CdlConflict conflict = (CdlConflict) GetItemData (nRow);
237 wxASSERT (conflict != NULL);
239 ecConfigItem *pItem=NULL;
244 const CdlGoalExpression goal = dynamic_cast<CdlGoalExpression> (conflict->get_property ());
245 if (! goal) // if the item is not a goal expression
247 const CdlExpression expression = goal->get_expression ();
248 if (1 == expression->references.size ()) // if the property contains a single reference
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);
257 pItem = wxGetApp().GetConfigToolDoc ()->Find(wxString(conflict->get_node ()->get_name ().c_str()));
265 // This is taken from CRulesView::FillRules in the MFC version
266 void ecConflictListCtrl::FillRules()
268 CdlConfiguration CdlConfig = wxGetApp().GetConfigToolDoc()->GetCdlConfig ();
270 { // if configuration information
273 wxHashTable arMap(wxKEY_INTEGER);
275 for ( i = 0 ; i < GetItemCount(); i++)
277 arMap.Put(GetItemData(i), (wxObject*) i);
280 std::list<CdlConflict>::const_iterator conf_i;
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
285 if (!arMap.Get((long) * conf_i))
291 //for (conf_i = CdlConfig->get_structural_conflicts().begin (); conf_i != CdlConfig->get_structural_conflicts().end (); conf_i++) { // for each conflict
293 // if(!arMap.Lookup(*conf_i,w)){
298 if(bRefill || nCount != GetItemCount())
301 //m_List.AddConflicts(CdlConfig->get_structural_conflicts());
302 AddConflicts(CdlConfig->get_all_conflicts());
308 int CRulesList::CompareFunc(LPARAM lParam1, LPARAM lParam2)
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);
319 void CRulesList::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
321 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
322 LPARAM nCol=pNMListView->iSubItem;
323 if((nCol&0x7fffffff)==(0x7fffffff&m_nLastCol)){
324 nCol=m_nLastCol^0x80000000;
327 SortItems(CompareFunc,(DWORD)this);
332 void CRulesList::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
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
346 UNUSED_ALWAYS(pNMHDR);