Mercurial > ecos
comparison host/tools/configtool/common/win32/FailingRulesDialog.cpp @ 76:435cced73e2f ecos-v1_3_1-release
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
| author | jlarmour |
|---|---|
| date | Tue, 28 Mar 2000 14:10:45 +0000 |
| parents | |
| children | 42f843b391aa |
comparison
equal
deleted
inserted
replaced
| 75:41bf073c0c32 | 76:435cced73e2f |
|---|---|
| 1 //####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 // FailingRulesDialog.cpp : implementation file | |
| 26 // | |
| 27 | |
| 28 #include "stdafx.h" | |
| 29 #ifndef PLUGIN | |
| 30 #include "BCMenu.h" | |
| 31 #endif | |
| 32 #include "FailingRulesDialog.h" | |
| 33 #include "ConfigItem.h" | |
| 34 #include "ConfigTool.h" | |
| 35 #include "ConfigToolDoc.h" | |
| 36 #include "ControlView.h" | |
| 37 #include "CTUtils.h" | |
| 38 | |
| 39 #ifdef _DEBUG | |
| 40 #define new DEBUG_NEW | |
| 41 #undef THIS_FILE | |
| 42 static char THIS_FILE[] = __FILE__; | |
| 43 #endif | |
| 44 | |
| 45 ///////////////////////////////////////////////////////////////////////////// | |
| 46 // CFailingRulesDialog dialog | |
| 47 | |
| 48 | |
| 49 CFailingRulesDialog::CFailingRulesDialog(std::list<CdlConflict> conflicts,CdlTransaction transaction/*=NULL*/,CPtrArray *parConflictsOfInterest/*=NULL*/) | |
| 50 : CeCosDialog(CFailingRulesDialog::IDD, NULL), | |
| 51 m_conflicts(conflicts), | |
| 52 m_Transaction(transaction), | |
| 53 m_parConflictsOfInterest(parConflictsOfInterest) | |
| 54 { | |
| 55 for (std::list<CdlConflict>::const_iterator conf_i= m_conflicts.begin (); conf_i != m_conflicts.end (); conf_i++) { // for each conflict | |
| 56 int nSolutions=(*conf_i)->get_solution().size(); | |
| 57 SolutionInfo *pInfo=(SolutionInfo *)malloc(sizeof(SolutionInfo)+(nSolutions-1)*sizeof(int)); | |
| 58 pInfo->nCount=nSolutions; | |
| 59 for(int i=0;i<nSolutions;i++){ | |
| 60 pInfo->arItem[i]=SolutionInfo::CHECKED; | |
| 61 } | |
| 62 m_Map.SetAt(*conf_i,pInfo); | |
| 63 } | |
| 64 | |
| 65 //{{AFX_DATA_INIT(CFailingRulesDialog) | |
| 66 // NOTE: the ClassWizard will add member initialization here | |
| 67 //}}AFX_DATA_INIT | |
| 68 } | |
| 69 | |
| 70 CFailingRulesDialog::~CFailingRulesDialog() | |
| 71 { | |
| 72 for(POSITION pos = m_Map.GetStartPosition(); pos != NULL; ){ | |
| 73 CdlConflict conflict; | |
| 74 SolutionInfo *pInfo=NULL; | |
| 75 m_Map.GetNextAssoc(pos, (void *&)conflict, (void *&)pInfo); | |
| 76 free(pInfo); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void CFailingRulesDialog::DoDataExchange(CDataExchange* pDX) | |
| 81 { | |
| 82 CeCosDialog::DoDataExchange(pDX); | |
| 83 //{{AFX_DATA_MAP(CFailingRulesDialog) | |
| 84 DDX_Control(pDX, IDC_LIST2, m_List); | |
| 85 //}}AFX_DATA_MAP | |
| 86 } | |
| 87 | |
| 88 | |
| 89 BEGIN_MESSAGE_MAP(CFailingRulesDialog, CeCosDialog) | |
| 90 //{{AFX_MSG_MAP(CFailingRulesDialog) | |
| 91 ON_BN_CLICKED(IDC_RESET, OnReset) | |
| 92 ON_BN_CLICKED(IDC_CONFLICTS_NONE, OnConflictsNone) | |
| 93 ON_BN_CLICKED(ID_RESOLVE_CONFLICTS_CONTINUE, OnOK) | |
| 94 ON_BN_CLICKED(ID_RESOLVE_CONFLICTS_CANCEL,OnCancel) | |
| 95 ON_COMMAND(ID_LOCATE,OnLocate) | |
| 96 //}}AFX_MSG_MAP | |
| 97 END_MESSAGE_MAP() | |
| 98 | |
| 99 ///////////////////////////////////////////////////////////////////////////// | |
| 100 // CFailingRulesDialog message handlers | |
| 101 | |
| 102 BOOL CFailingRulesDialog::OnInitDialog() | |
| 103 { | |
| 104 CeCosDialog::OnInitDialog(); | |
| 105 m_List.SetExtendedStyle(LVS_EX_CHECKBOXES); | |
| 106 m_List.InsertColumn(0,_T("Item")); | |
| 107 m_List.InsertColumn(1,_T("Value")); | |
| 108 | |
| 109 CRect rect; | |
| 110 GetDlgItem(IDC_LIST1)->GetWindowRect(rect); | |
| 111 ScreenToClient(rect); | |
| 112 | |
| 113 m_RulesList.CreateEx(WS_EX_CLIENTEDGE,WC_LISTVIEW,NULL,WS_VISIBLE|WS_CHILD|LVS_SHOWSELALWAYS,rect,this,IDC_LIST1); | |
| 114 // Select the first item and fill the solution set | |
| 115 m_RulesList.AddConflicts(m_conflicts); | |
| 116 | |
| 117 if(m_parConflictsOfInterest && m_parConflictsOfInterest->GetSize()>0){ | |
| 118 CPtrArray &arConflictsOfInterest=*m_parConflictsOfInterest; | |
| 119 for(int i=m_RulesList.GetItemCount()-1;i>=0;--i){ | |
| 120 for(int j=arConflictsOfInterest.GetSize()-1;j>=0;--j){ | |
| 121 CdlConflict conflict=(CdlConflict)m_RulesList.GetItemData(i); | |
| 122 if(arConflictsOfInterest[j]==conflict){ | |
| 123 m_RulesList.SetItemState(i,LVIS_SELECTED, LVIS_SELECTED); | |
| 124 m_RulesList.EnsureVisible(i,false); | |
| 125 arConflictsOfInterest.RemoveAt(j); | |
| 126 break; | |
| 127 } | |
| 128 } | |
| 129 } | |
| 130 } else { | |
| 131 for(int i=m_RulesList.GetItemCount()-1;i>=0;--i){ | |
| 132 m_RulesList.SetItemState(i,LVIS_SELECTED, LVIS_SELECTED); | |
| 133 } | |
| 134 } | |
| 135 SetButtons(); | |
| 136 return false; // return TRUE unless you set the focus to a control | |
| 137 // EXCEPTION: OCX Property Pages should return FALSE | |
| 138 } | |
| 139 | |
| 140 void CFailingRulesDialog::OnCancel() | |
| 141 { | |
| 142 CeCosDialog::OnCancel(); | |
| 143 } | |
| 144 | |
| 145 void CFailingRulesDialog::OnOK() | |
| 146 { | |
| 147 // Ensure we have the current conflict check array | |
| 148 for(POSITION pos = m_RulesList.GetFirstSelectedItemPosition();pos;){ | |
| 149 int nItem = m_RulesList.GetNextSelectedItem(pos); | |
| 150 RemoveConflictSolutions((CdlConflict)m_RulesList.GetItemData(nItem)); | |
| 151 } | |
| 152 | |
| 153 // Dismiss the window | |
| 154 CeCosDialog::OnOK(); | |
| 155 | |
| 156 for (std::list<CdlConflict>::const_iterator conf_i= m_conflicts.begin (); conf_i != m_conflicts.end (); conf_i++) { // for each conflict | |
| 157 CdlConflict conflict=*conf_i; | |
| 158 //int nSolutions=conflict->get_solution().size(); | |
| 159 SolutionInfo &info=Info(conflict); | |
| 160 int nIndex=0; | |
| 161 const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution(); | |
| 162 for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin();soln_i != Solution.end(); soln_i++) { | |
| 163 if(SolutionInfo::CHECKED==info.arItem[nIndex++]){ | |
| 164 CdlValuable valuable = soln_i->first; | |
| 165 CdlValue value=soln_i->second; | |
| 166 CdlValueFlavor flavor = valuable->get_flavor(); | |
| 167 const CString strName(valuable->get_name().c_str()); | |
| 168 const CString strValue(value.get_value().c_str()); | |
| 169 bool rc=true; | |
| 170 CString str; | |
| 171 try { | |
| 172 switch(flavor) { | |
| 173 case CdlValueFlavor_None : | |
| 174 str=_T("set CdlValueFlavor_None"); | |
| 175 rc=false; | |
| 176 break; | |
| 177 case CdlValueFlavor_Bool : | |
| 178 str.Format(_T("%s %s\n"),value.is_enabled()?_T("disable"):_T("enable"),strName); | |
| 179 valuable->set_enabled (m_Transaction, value.is_enabled(), CdlValueSource_User); | |
| 180 break; | |
| 181 case CdlValueFlavor_BoolData : | |
| 182 { | |
| 183 bool bEnabled=value.is_enabled(); | |
| 184 str.Format(_T("%s %s and set value to %s\n"),bEnabled?_T("disable"):_T("enable"),strName,strValue); | |
| 185 CdlSimpleValue simple_value = valuable->get_simple_value (); | |
| 186 valuable->set_enabled_and_value (m_Transaction, bEnabled, simple_value, CdlValueSource_User); | |
| 187 } | |
| 188 break; | |
| 189 case CdlValueFlavor_Data : | |
| 190 str.Format(_T("set %s to %s\n"),strName,strValue); | |
| 191 valuable->set_value (m_Transaction, CUtils::UnicodeToStdStr (strValue), CdlValueSource_User); | |
| 192 break; | |
| 193 } | |
| 194 } | |
| 195 catch(...){ | |
| 196 rc=false; | |
| 197 } | |
| 198 if(rc){ | |
| 199 CConfigTool::GetConfigToolDoc()->SetModifiedFlag(); | |
| 200 } else { | |
| 201 CUtils::MessageBoxF(_T("Failed to %s\n"),str); | |
| 202 } | |
| 203 } | |
| 204 } | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 void CFailingRulesDialog::SetAll(bool bOnOff) | |
| 209 { | |
| 210 for(int i=m_List.GetItemCount()-1;i>=0;--i){ | |
| 211 m_List.SetCheck(i,bOnOff); | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 void CFailingRulesDialog::OnReset() | |
| 216 { | |
| 217 SetAll(true); | |
| 218 } | |
| 219 | |
| 220 void CFailingRulesDialog::OnConflictsNone() | |
| 221 { | |
| 222 SetAll(false); | |
| 223 } | |
| 224 | |
| 225 BOOL CFailingRulesDialog::OnItemChanged(UINT, LPNMLISTVIEW pnmv, LRESULT* pResult) | |
| 226 { | |
| 227 bool bWasSelected=(pnmv->uOldState & LVIS_SELECTED); | |
| 228 bool bIsSelected =(pnmv->uNewState & LVIS_SELECTED); | |
| 229 | |
| 230 if(bWasSelected != bIsSelected) { | |
| 231 CdlConflict conflict=(CdlConflict) m_RulesList.GetItemData(pnmv->iItem); | |
| 232 if(bIsSelected){ | |
| 233 if(1==m_List.GetSelectedCount()){ | |
| 234 GetDlgItem(IDC_STATIC1)->ShowWindow(SW_HIDE); | |
| 235 m_List.ShowWindow(SW_SHOW); | |
| 236 } | |
| 237 AddConflictSolutions(conflict); | |
| 238 } else { | |
| 239 RemoveConflictSolutions(conflict); | |
| 240 } | |
| 241 } | |
| 242 *pResult = 0; | |
| 243 return false; | |
| 244 } | |
| 245 | |
| 246 // We need to use this because the OnItemChanged handler successive receives "not selected" followed by "selected" | |
| 247 // notifications. The result is that the "Select one or more conflicts to display available solutions" message | |
| 248 // would be seen briefly when clicking from one selection to another. | |
| 249 BOOL CFailingRulesDialog::OnClick(UINT,LPNMLISTVIEW pnmv, LRESULT* pResult) | |
| 250 { | |
| 251 if(-1==pnmv->iItem && 0==m_List.GetSelectedCount()){ | |
| 252 SetDlgItemText(IDC_STATIC1,_T("Select one or more conflicts to display available solutions")); | |
| 253 m_List.ShowWindow(SW_HIDE); | |
| 254 GetDlgItem(IDC_STATIC1)->ShowWindow(SW_SHOW); | |
| 255 GetDlgItem(IDC_RESET)->EnableWindow(false); | |
| 256 GetDlgItem(IDC_CONFLICTS_NONE)->EnableWindow(false); | |
| 257 } | |
| 258 *pResult = 0; | |
| 259 return false; // not handled | |
| 260 } | |
| 261 | |
| 262 void CFailingRulesDialog::RemoveConflictSolutions(CdlConflict conflict) | |
| 263 { | |
| 264 SolutionInfo &info=Info(conflict); | |
| 265 for(int i=0;i<info.nCount;i++){ | |
| 266 int nItem=info.arItem[i]; | |
| 267 ASSERT(nItem>=0); | |
| 268 info.arItem[i]=(1==m_List.GetCheck(nItem)?SolutionInfo::CHECKED:SolutionInfo::UNCHECKED); | |
| 269 int nRefs=m_List.GetItemData(nItem); | |
| 270 if(1==nRefs){ | |
| 271 m_List.DeleteItem(nItem); | |
| 272 for(int i=0;i<m_RulesList.GetItemCount();i++){ | |
| 273 SolutionInfo &info=Info((CdlConflict)m_RulesList.GetItemData(i)); | |
| 274 for(int j=0;j<info.nCount;j++){ | |
| 275 if(info.arItem[j]>nItem){ | |
| 276 info.arItem[j]--; | |
| 277 } | |
| 278 } | |
| 279 } | |
| 280 } else { | |
| 281 m_List.SetItemData(nItem,nRefs-1); | |
| 282 } | |
| 283 } | |
| 284 } | |
| 285 | |
| 286 void CFailingRulesDialog::AddConflictSolutions(CdlConflict conflict) | |
| 287 { | |
| 288 SolutionInfo &info=Info(conflict); | |
| 289 | |
| 290 const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution(); | |
| 291 | |
| 292 int i=0; | |
| 293 for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin(); | |
| 294 soln_i != Solution.end(); soln_i++) { | |
| 295 CdlValuable valuable = soln_i->first; | |
| 296 CdlValue value=soln_i->second; | |
| 297 CdlValueFlavor flavor = valuable->get_flavor(); | |
| 298 | |
| 299 CString strValue; | |
| 300 switch(flavor) { | |
| 301 case CdlValueFlavor_None : | |
| 302 break; | |
| 303 case CdlValueFlavor_Bool : | |
| 304 strValue=value.is_enabled() ? _T("Enabled") : _T("Disabled"); | |
| 305 break; | |
| 306 case CdlValueFlavor_BoolData : | |
| 307 strValue.Format(_T("%s, %s"), value.is_enabled() ? _T("Enabled") : _T("Disabled"), CString(value.get_value().c_str())); | |
| 308 break; | |
| 309 case CdlValueFlavor_Data : | |
| 310 strValue=value.get_value().c_str(); | |
| 311 break; | |
| 312 } | |
| 313 | |
| 314 const CString strName(soln_i->first->get_name().c_str()); | |
| 315 LVFINDINFO fi; | |
| 316 fi.flags=LVFI_STRING; | |
| 317 fi.psz=strName; | |
| 318 int nIndex=m_List.FindItem(&fi); | |
| 319 if(-1==nIndex || strValue!=m_List.GetItemText(nIndex,1)){ | |
| 320 // We don't have an existing solution that matches this one | |
| 321 nIndex=m_List.GetItemCount(); | |
| 322 m_List.InsertItem(nIndex,strName); | |
| 323 m_List.SetItemData(nIndex,1); | |
| 324 m_List.SetItemText(nIndex,1,strValue); | |
| 325 ASSERT(info.arItem[i]<0); | |
| 326 m_List.SetCheck(nIndex,SolutionInfo::CHECKED==info.arItem[i]); | |
| 327 } else { | |
| 328 // We do - to avoid duplicates, increment the "ref count" | |
| 329 m_List.SetItemData(nIndex,m_List.GetItemData(nIndex)+1); | |
| 330 } | |
| 331 info.arItem[i++]=nIndex; | |
| 332 } | |
| 333 if(0==i){ | |
| 334 SetDlgItemText(IDC_STATIC1,_T("No solution is available for this conflict")); | |
| 335 m_List.ShowWindow(SW_HIDE); | |
| 336 } else { | |
| 337 SetDlgItemText(IDC_STATIC1,_T("Proposed solution:")); | |
| 338 m_List.ShowWindow(SW_SHOW); | |
| 339 m_List.SetColumnWidth(0,LVSCW_AUTOSIZE); | |
| 340 CRect rect; | |
| 341 m_List.GetClientRect(rect); | |
| 342 m_List.SetColumnWidth(1,rect.Width()-m_List.GetColumnWidth(0)); | |
| 343 } | |
| 344 } | |
| 345 | |
| 346 BOOL CFailingRulesDialog::OnSolutionItemChanged(UINT,LPNMLISTVIEW, LRESULT*) | |
| 347 { | |
| 348 SetButtons(); | |
| 349 return false; // not handled | |
| 350 } | |
| 351 | |
| 352 CFailingRulesDialog::SolutionInfo & CFailingRulesDialog::Info(const CdlConflict conflict) | |
| 353 { | |
| 354 SolutionInfo *pInfo; | |
| 355 VERIFY(m_Map.Lookup(conflict,(void *&)pInfo)); | |
| 356 return *pInfo; | |
| 357 } | |
| 358 | |
| 359 BOOL CFailingRulesDialog::OnRClick(UINT, LPNMITEMACTIVATE pnmv, LRESULT* pResult) | |
| 360 { | |
| 361 DWORD dwPos=GetMessagePos(); | |
| 362 CPoint pt(GET_X_LPARAM(dwPos),GET_Y_LPARAM(dwPos)); | |
| 363 m_nContextItem=pnmv->iItem; | |
| 364 m_nContextRow=pnmv->iSubItem; | |
| 365 if(-1!=m_nContextItem){ | |
| 366 //m_RulesList.SetItemState(m_nContextItem,LVIS_SELECTED,LVIS_SELECTED); | |
| 367 Menu menu; | |
| 368 menu.CreatePopupMenu(); | |
| 369 menu.AppendMenu(1==m_RulesList.GetSelectedCount() && m_RulesList.AssociatedItem(m_nContextItem,m_nContextRow)?MF_STRING:(MF_STRING|MF_GRAYED),ID_LOCATE,_T("&Locate")); | |
| 370 #ifndef PLUGIN | |
| 371 SuppressNextContextMenuMessage(); | |
| 372 #endif | |
| 373 menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pt.x,pt.y,this); | |
| 374 } | |
| 375 | |
| 376 *pResult = 0; | |
| 377 return TRUE; // handled | |
| 378 } | |
| 379 | |
| 380 void CFailingRulesDialog::OnLocate() | |
| 381 { | |
| 382 CConfigItem *pItem=m_RulesList.AssociatedItem(m_nContextItem,m_nContextRow); | |
| 383 if (pItem) { | |
| 384 CConfigTool::GetControlView()->SelectItem(pItem); | |
| 385 } | |
| 386 } | |
| 387 | |
| 388 | |
| 389 void CFailingRulesDialog::SetButtons() | |
| 390 { | |
| 391 int nCheckCount=0; | |
| 392 int nItemCount=m_List.GetItemCount(); | |
| 393 for(int i=nItemCount-1;i>=0;--i){ | |
| 394 nCheckCount+=m_List.GetCheck(i); | |
| 395 } | |
| 396 GetDlgItem(IDC_RESET)->EnableWindow(nItemCount>0 && nCheckCount<nItemCount); | |
| 397 GetDlgItem(IDC_CONFLICTS_NONE)->EnableWindow(nItemCount>0 && nCheckCount>0); | |
| 398 } | |
| 399 | |
| 400 // We have to dispatch our own notify messages because the multiple inheritance of CCSHDialog prevents | |
| 401 // the message map from compiling properly for ON_NOTIFY messages. | |
| 402 BOOL CFailingRulesDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult ) | |
| 403 { | |
| 404 LPNMHDR pHdr=(LPNMHDR)lParam; | |
| 405 bool bHandled=false; | |
| 406 switch(pHdr->idFrom){ | |
| 407 case IDC_LIST1: | |
| 408 switch (pHdr->code) { | |
| 409 case LVN_ITEMCHANGED: | |
| 410 bHandled=OnItemChanged(wParam, (LPNMLISTVIEW)lParam, pResult); | |
| 411 break; | |
| 412 case NM_CLICK: | |
| 413 bHandled=OnClick(wParam, (LPNMLISTVIEW)lParam, pResult); | |
| 414 break; | |
| 415 case NM_RCLICK: | |
| 416 bHandled=OnRClick(wParam, (LPNMITEMACTIVATE)lParam, pResult); | |
| 417 break; | |
| 418 default: | |
| 419 break; | |
| 420 } | |
| 421 break; | |
| 422 case IDC_LIST2: | |
| 423 switch (pHdr->code) { | |
| 424 case LVN_ITEMCHANGED: | |
| 425 bHandled=OnSolutionItemChanged(wParam,(LPNMLISTVIEW)lParam, pResult); | |
| 426 break; | |
| 427 default: | |
| 428 break; | |
| 429 } | |
| 430 break; | |
| 431 } | |
| 432 return bHandled || CeCosDialog::OnNotify(wParam,lParam,pResult); | |
| 433 } |
