PropertyList.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. // PropertyList.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "shellapi.h"
  5. #include "CMakeSetup.h"
  6. #include "CMakeSetupDialog.h"
  7. #include "PathDialog.h"
  8. #include "../cmCacheManager.h"
  9. #include "../cmSystemTools.h"
  10. #include "../cmake.h"
  11. #define IDC_PROPCMBBOX 712
  12. #define IDC_PROPEDITBOX 713
  13. #define IDC_PROPBTNCTRL 714
  14. #define IDC_PROPCHECKBOXCTRL 715
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CPropertyList
  17. CPropertyList::CPropertyList()
  18. {
  19. m_Dirty = false;
  20. m_ShowAdvanced = false;
  21. m_curSel = -1;
  22. }
  23. CPropertyList::~CPropertyList()
  24. {
  25. for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
  26. i != m_PropertyItems.end(); ++i)
  27. {
  28. delete *i;
  29. }
  30. }
  31. BEGIN_MESSAGE_MAP(CPropertyList, CListBox)
  32. //{{AFX_MSG_MAP(CPropertyList)
  33. ON_WM_CREATE()
  34. ON_WM_VSCROLL()
  35. ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange)
  36. ON_WM_LBUTTONUP()
  37. ON_WM_KILLFOCUS()
  38. ON_WM_LBUTTONDOWN()
  39. ON_WM_RBUTTONUP()
  40. ON_WM_MOUSEMOVE()
  41. //}}AFX_MSG_MAP
  42. ON_CBN_KILLFOCUS(IDC_PROPCMBBOX, OnKillfocusCmbBox)
  43. ON_CBN_SELCHANGE(IDC_PROPCMBBOX, OnSelchangeCmbBox)
  44. ON_EN_KILLFOCUS(IDC_PROPEDITBOX, OnKillfocusEditBox)
  45. ON_EN_CHANGE(IDC_PROPEDITBOX, OnChangeEditBox)
  46. ON_BN_CLICKED(IDC_PROPBTNCTRL, OnButton)
  47. ON_BN_CLICKED(IDC_PROPCHECKBOXCTRL, OnCheckBox)
  48. ON_COMMAND(42, OnDelete)
  49. ON_COMMAND(43, OnHelp)
  50. ON_COMMAND(44, OnIgnore)
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CPropertyList message handlers
  54. BOOL CPropertyList::PreCreateWindow(CREATESTRUCT& cs)
  55. {
  56. if (!CListBox::PreCreateWindow(cs))
  57. return FALSE;
  58. cs.style &= ~(LBS_OWNERDRAWVARIABLE | LBS_SORT);
  59. cs.style |= LBS_OWNERDRAWFIXED;
  60. m_bTracking = FALSE;
  61. m_nDivider = 0;
  62. m_bDivIsSet = FALSE;
  63. return TRUE;
  64. }
  65. void CPropertyList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  66. {
  67. lpMeasureItemStruct->itemHeight = 20; //pixels
  68. }
  69. void CPropertyList::DrawItem(LPDRAWITEMSTRUCT lpDIS)
  70. {
  71. CDC dc;
  72. dc.Attach(lpDIS->hDC);
  73. CRect rectFull = lpDIS->rcItem;
  74. CRect rect = rectFull;
  75. if (m_nDivider==0)
  76. m_nDivider = rect.Width() / 2;
  77. rect.left = m_nDivider;
  78. CRect rect2 = rectFull;
  79. rect2.right = rect.left - 1;
  80. UINT nIndex = lpDIS->itemID;
  81. if (nIndex != (UINT) -1)
  82. {
  83. //get the CPropertyItem for the current row
  84. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(nIndex);
  85. //draw two rectangles, one for each row column
  86. if(pItem->m_NewValue)
  87. {
  88. dc.FillSolidRect(rect2,RGB(255,100, 100));
  89. }
  90. else
  91. {
  92. dc.FillSolidRect(rect2,RGB(192,192,192));
  93. }
  94. dc.DrawEdge(rect2,EDGE_SUNKEN,BF_BOTTOMRIGHT);
  95. dc.DrawEdge(rect,EDGE_SUNKEN,BF_BOTTOM);
  96. //write the property name in the first rectangle
  97. dc.SetBkMode(TRANSPARENT);
  98. dc.DrawText(pItem->m_propName,CRect(rect2.left+3,rect2.top+3,
  99. rect2.right-3,rect2.bottom+3),
  100. DT_LEFT | DT_SINGLELINE);
  101. //write the initial property value in the second rectangle
  102. dc.DrawText(pItem->m_curValue,CRect(rect.left+3,rect.top+3,
  103. rect.right+3,rect.bottom+3),
  104. DT_LEFT | DT_SINGLELINE);
  105. }
  106. dc.Detach();
  107. }
  108. int CPropertyList::AddItem(CString txt)
  109. {
  110. int nIndex = AddString(txt);
  111. return nIndex;
  112. }
  113. // order = 0 sorted
  114. // order = 1 add to top
  115. // order = 2 add to bottom
  116. int CPropertyList::AddPropItem(CPropertyItem* pItem, int order)
  117. {
  118. if(pItem->m_Advanced && ! m_ShowAdvanced)
  119. {
  120. m_PropertyItems.insert(pItem);
  121. return 0;
  122. }
  123. this->HideControls();
  124. int nIndex;
  125. if(order)
  126. {
  127. if(order == 1)
  128. {
  129. order = 0;
  130. }
  131. if(order == 2)
  132. {
  133. order = -1;
  134. }
  135. nIndex = InsertString(order, _T(""));
  136. }
  137. else
  138. {
  139. nIndex = AddString(pItem->m_propName);
  140. }
  141. SetItemDataPtr(nIndex,pItem);
  142. m_PropertyItems.insert(pItem);
  143. return nIndex;
  144. }
  145. void CPropertyList::AddProperty(const char* name,
  146. const char* value,
  147. const char* helpString,
  148. int type,
  149. const char* comboItems,
  150. bool reverseOrder,
  151. bool advanced)
  152. {
  153. CPropertyItem* pItem = 0;
  154. for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
  155. i != m_PropertyItems.end(); ++i)
  156. {
  157. CPropertyItem* item = *i;
  158. if(item->m_propName == name)
  159. {
  160. pItem = item;
  161. if(pItem->m_curValue != value)
  162. {
  163. pItem->m_curValue = value;
  164. pItem->m_HelpString = helpString;
  165. InvalidateList();
  166. }
  167. pItem->m_Advanced = advanced;
  168. return;
  169. }
  170. }
  171. // if it is not found, then create a new one
  172. if(!pItem)
  173. {
  174. pItem = new CPropertyItem(name, value, helpString, type, comboItems);
  175. pItem->m_NewValue = true;
  176. }
  177. pItem->m_Advanced = advanced;
  178. int order = 0;
  179. if(reverseOrder)
  180. {
  181. order = 1;
  182. }
  183. this->AddPropItem(pItem, order);
  184. return;
  185. }
  186. int CPropertyList::OnCreate(LPCREATESTRUCT lpCreateStruct)
  187. {
  188. if (CListBox::OnCreate(lpCreateStruct) == -1)
  189. return -1;
  190. m_bDivIsSet = FALSE;
  191. m_nDivider = 0;
  192. m_bTracking = FALSE;
  193. m_hCursorSize = AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);
  194. m_hCursorArrow = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
  195. m_SSerif8Font.CreatePointFont(80,_T("MS Sans Serif"));
  196. return 0;
  197. }
  198. void CPropertyList::OnSelchange()
  199. {
  200. CRect rect;
  201. CString lBoxSelText;
  202. GetItemRect(m_curSel,rect);
  203. rect.left = m_nDivider;
  204. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  205. if (m_btnCtrl)
  206. m_btnCtrl.ShowWindow(SW_HIDE);
  207. if (m_CheckBoxControl)
  208. m_CheckBoxControl.ShowWindow(SW_HIDE);
  209. if (pItem->m_nItemType==CPropertyList::COMBO)
  210. {
  211. //display the combo box. If the combo box has already been
  212. //created then simply move it to the new location, else create it
  213. m_nLastBox = 0;
  214. if (m_cmbBox)
  215. m_cmbBox.MoveWindow(rect);
  216. else
  217. {
  218. rect.bottom += 100;
  219. m_cmbBox.Create(CBS_DROPDOWNLIST
  220. | CBS_NOINTEGRALHEIGHT | WS_VISIBLE
  221. | WS_CHILD | WS_BORDER,
  222. rect,this,IDC_PROPCMBBOX);
  223. m_cmbBox.SetFont(&m_SSerif8Font);
  224. }
  225. //add the choices for this particular property
  226. CString cmbItems = pItem->m_cmbItems;
  227. lBoxSelText = pItem->m_curValue;
  228. m_cmbBox.ResetContent();
  229. int i,i2;
  230. i=0;
  231. while ((i2=cmbItems.Find('|',i)) != -1)
  232. {
  233. m_cmbBox.AddString(cmbItems.Mid(i,i2-i));
  234. i=i2+1;
  235. }
  236. if(i != 0)
  237. m_cmbBox.AddString(cmbItems.Mid(i));
  238. m_cmbBox.ShowWindow(SW_SHOW);
  239. m_cmbBox.SetFocus();
  240. //jump to the property's current value in the combo box
  241. int j = m_cmbBox.FindStringExact(0,lBoxSelText);
  242. if (j != CB_ERR)
  243. m_cmbBox.SetCurSel(j);
  244. else
  245. m_cmbBox.SetCurSel(0);
  246. }
  247. else if (pItem->m_nItemType==CPropertyList::EDIT)
  248. {
  249. //display edit box
  250. m_nLastBox = 1;
  251. m_prevSel = m_curSel;
  252. rect.bottom -= 3;
  253. if (m_editBox)
  254. m_editBox.MoveWindow(rect);
  255. else
  256. {
  257. m_editBox.Create(ES_LEFT | ES_AUTOHSCROLL | WS_VISIBLE
  258. | WS_CHILD | WS_BORDER,
  259. rect,this,IDC_PROPEDITBOX);
  260. m_editBox.SetFont(&m_SSerif8Font);
  261. }
  262. lBoxSelText = pItem->m_curValue;
  263. m_editBox.ShowWindow(SW_SHOW);
  264. m_editBox.SetFocus();
  265. //set the text in the edit box to the property's current value
  266. m_editBox.SetWindowText(lBoxSelText);
  267. }
  268. else if (pItem->m_nItemType == CPropertyList::CHECKBOX)
  269. {
  270. rect.bottom -= 3;
  271. if (m_CheckBoxControl)
  272. m_CheckBoxControl.MoveWindow(rect);
  273. else
  274. {
  275. m_CheckBoxControl.Create("check",BS_CHECKBOX
  276. | BM_SETCHECK |BS_LEFTTEXT
  277. | WS_VISIBLE | WS_CHILD,
  278. rect,this,IDC_PROPCHECKBOXCTRL);
  279. m_CheckBoxControl.SetFont(&m_SSerif8Font);
  280. }
  281. lBoxSelText = pItem->m_curValue;
  282. m_CheckBoxControl.ShowWindow(SW_SHOW);
  283. m_CheckBoxControl.SetFocus();
  284. //set the text in the edit box to the property's current value
  285. if(lBoxSelText == "ON")
  286. {
  287. m_CheckBoxControl.SetCheck(1);
  288. }
  289. else
  290. {
  291. m_CheckBoxControl.SetCheck(0);
  292. }
  293. }
  294. else
  295. DisplayButton(rect);
  296. }
  297. void CPropertyList::DisplayButton(CRect region)
  298. {
  299. //displays a button if the property is a file/color/font chooser
  300. m_nLastBox = 2;
  301. m_prevSel = m_curSel;
  302. if (region.Width() > 25)
  303. region.left = region.right - 25;
  304. region.bottom -= 3;
  305. if (m_btnCtrl)
  306. m_btnCtrl.MoveWindow(region);
  307. else
  308. {
  309. m_btnCtrl.Create("...",BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD,
  310. region,this,IDC_PROPBTNCTRL);
  311. m_btnCtrl.SetFont(&m_SSerif8Font);
  312. }
  313. m_btnCtrl.ShowWindow(SW_SHOW);
  314. m_btnCtrl.SetFocus();
  315. }
  316. void CPropertyList::OnKillFocus(CWnd* pNewWnd)
  317. {
  318. //m_btnCtrl.ShowWindow(SW_HIDE);
  319. CListBox::OnKillFocus(pNewWnd);
  320. }
  321. void CPropertyList::OnKillfocusCmbBox()
  322. {
  323. m_cmbBox.ShowWindow(SW_HIDE);
  324. Invalidate();
  325. }
  326. void CPropertyList::OnKillfocusEditBox()
  327. {
  328. CString newStr;
  329. m_editBox.ShowWindow(SW_HIDE);
  330. Invalidate();
  331. }
  332. void CPropertyList::OnSelchangeCmbBox()
  333. {
  334. CString selStr;
  335. if (m_cmbBox)
  336. {
  337. m_cmbBox.GetLBText(m_cmbBox.GetCurSel(),selStr);
  338. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  339. pItem->m_curValue = selStr;
  340. m_Dirty = true;
  341. }
  342. }
  343. void CPropertyList::OnChangeEditBox()
  344. {
  345. CString newStr;
  346. m_editBox.GetWindowText(newStr);
  347. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  348. if(pItem->m_curValue != newStr)
  349. {
  350. pItem->m_curValue = newStr;
  351. m_Dirty = true;
  352. }
  353. }
  354. void CPropertyList::HideControls()
  355. {
  356. if(m_editBox)
  357. {
  358. m_editBox.ShowWindow(SW_HIDE);
  359. }
  360. if(m_cmbBox)
  361. {
  362. m_cmbBox.ShowWindow(SW_HIDE);
  363. }
  364. if(m_CheckBoxControl)
  365. {
  366. m_CheckBoxControl.ShowWindow(SW_HIDE);
  367. }
  368. if(m_btnCtrl)
  369. {
  370. m_btnCtrl.ShowWindow(SW_HIDE);
  371. }
  372. }
  373. void CPropertyList::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
  374. {
  375. this->HideControls();
  376. CListBox::OnVScroll(nSBCode, nPos, pScrollBar);
  377. }
  378. void CPropertyList::OnCheckBox()
  379. {
  380. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  381. if(m_CheckBoxControl.GetCheck())
  382. {
  383. pItem->m_curValue = "ON";
  384. }
  385. else
  386. {
  387. pItem->m_curValue = "OFF";
  388. }
  389. m_Dirty = true;
  390. }
  391. void CPropertyList::OnButton()
  392. {
  393. if(m_PropertyItems.size() == 0)
  394. {
  395. return;
  396. }
  397. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  398. // The dialogs might change the working directory. Save it.
  399. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  400. //display the appropriate common dialog depending on what type
  401. //of chooser is associated with the property
  402. if (pItem->m_nItemType == CPropertyList::FILE)
  403. {
  404. CString SelectedFile;
  405. CString Filter("All Files (*.*)||");
  406. CFileDialog FileDlg(TRUE, NULL, NULL, NULL,
  407. Filter);
  408. CString initialDir;
  409. CString currPath = pItem->m_curValue;
  410. if (currPath.Right(9) == "-NOTFOUND" || currPath == "NOTFOUND")
  411. {
  412. currPath = "";
  413. }
  414. if (currPath.GetLength() > 0)
  415. {
  416. int endSlash = currPath.ReverseFind('\\');
  417. if(endSlash == -1)
  418. {
  419. endSlash = currPath.ReverseFind('/');
  420. }
  421. initialDir = currPath.Left(endSlash);
  422. }
  423. initialDir.Replace("/", "\\");
  424. FileDlg.m_ofn.lpstrTitle = "Select file";
  425. if (currPath.GetLength() > 0)
  426. FileDlg.m_ofn.lpstrInitialDir = initialDir;
  427. if(IDOK == FileDlg.DoModal())
  428. {
  429. SelectedFile = FileDlg.GetPathName();
  430. m_btnCtrl.ShowWindow(SW_HIDE);
  431. std::string path = SelectedFile;
  432. cmSystemTools::ConvertToUnixSlashes(path);
  433. pItem->m_curValue = path.c_str();
  434. m_Dirty = true;
  435. InvalidateList();
  436. }
  437. }
  438. else if (pItem->m_nItemType == CPropertyList::PATH)
  439. {
  440. CString initialDir = pItem->m_curValue;
  441. // convert back to windos style path
  442. initialDir.Replace("/", "\\");
  443. CString title = "Setting Cache Value: ";
  444. title += pItem->m_propName;
  445. CPathDialog dlg("Select Path", title, initialDir);
  446. if(dlg.DoModal()==IDOK)
  447. {
  448. CString SelectedFile = dlg.GetPathName();
  449. m_btnCtrl.ShowWindow(SW_HIDE);
  450. std::string path = SelectedFile;
  451. cmSystemTools::ConvertToUnixSlashes(path);
  452. pItem->m_curValue = path.c_str();
  453. m_Dirty = true;
  454. InvalidateList();
  455. }
  456. }
  457. cmSystemTools::ChangeDirectory(cwd.c_str());
  458. }
  459. void CPropertyList::OnLButtonUp(UINT nFlags, CPoint point)
  460. {
  461. if (m_bTracking)
  462. {
  463. //if columns were being resized then this indicates
  464. //that mouse is up so resizing is done. Need to redraw
  465. //columns to reflect their new widths.
  466. m_bTracking = FALSE;
  467. //if mouse was captured then release it
  468. if (GetCapture()==this)
  469. ::ReleaseCapture();
  470. ::ClipCursor(NULL);
  471. CClientDC dc(this);
  472. InvertLine(&dc,CPoint(point.x,m_nDivTop),CPoint(point.x,m_nDivBtm));
  473. //set the divider position to the new value
  474. m_nDivider = point.x;
  475. //redraw
  476. Invalidate();
  477. }
  478. else
  479. {
  480. BOOL loc;
  481. int i = ItemFromPoint(point,loc);
  482. m_curSel = i;
  483. CListBox::OnLButtonUp(nFlags, point);
  484. }
  485. }
  486. void CPropertyList::OnLButtonDown(UINT nFlags, CPoint point)
  487. {
  488. if ((point.x>=m_nDivider-5) && (point.x<=m_nDivider+5))
  489. {
  490. //if mouse clicked on divider line, then start resizing
  491. ::SetCursor(m_hCursorSize);
  492. CRect windowRect;
  493. GetWindowRect(windowRect);
  494. windowRect.left += 10; windowRect.right -= 10;
  495. //do not let mouse leave the list box boundary
  496. ::ClipCursor(windowRect);
  497. if (m_cmbBox)
  498. m_cmbBox.ShowWindow(SW_HIDE);
  499. if (m_editBox)
  500. m_editBox.ShowWindow(SW_HIDE);
  501. CRect clientRect;
  502. GetClientRect(clientRect);
  503. m_bTracking = TRUE;
  504. m_nDivTop = clientRect.top;
  505. m_nDivBtm = clientRect.bottom;
  506. m_nOldDivX = point.x;
  507. CClientDC dc(this);
  508. InvertLine(&dc,CPoint(m_nOldDivX,m_nDivTop),CPoint(m_nOldDivX,m_nDivBtm));
  509. //capture the mouse
  510. SetCapture();
  511. }
  512. else
  513. {
  514. m_bTracking = FALSE;
  515. CListBox::OnLButtonDown(nFlags, point);
  516. }
  517. }
  518. void CPropertyList::OnMouseMove(UINT nFlags, CPoint point)
  519. {
  520. if (m_bTracking)
  521. {
  522. //move divider line to the mouse pos. if columns are
  523. //currently being resized
  524. CClientDC dc(this);
  525. //remove old divider line
  526. InvertLine(&dc,CPoint(m_nOldDivX,m_nDivTop),CPoint(m_nOldDivX,m_nDivBtm));
  527. //draw new divider line
  528. InvertLine(&dc,CPoint(point.x,m_nDivTop),CPoint(point.x,m_nDivBtm));
  529. m_nOldDivX = point.x;
  530. }
  531. else if ((point.x >= m_nDivider-5) && (point.x <= m_nDivider+5))
  532. //set the cursor to a sizing cursor if the cursor is over the row divider
  533. ::SetCursor(m_hCursorSize);
  534. else
  535. {
  536. BOOL loc;
  537. int curSel = ItemFromPoint(point,loc);
  538. if(!loc && curSel < 65535)
  539. {
  540. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(curSel);
  541. m_CMakeSetupDialog->SetDlgItemText(IDC_PROGRESS, pItem->m_HelpString);
  542. }
  543. CListBox::OnMouseMove(nFlags, point);
  544. }
  545. }
  546. void CPropertyList::InvertLine(CDC* pDC,CPoint ptFrom,CPoint ptTo)
  547. {
  548. int nOldMode = pDC->SetROP2(R2_NOT);
  549. pDC->MoveTo(ptFrom);
  550. pDC->LineTo(ptTo);
  551. pDC->SetROP2(nOldMode);
  552. }
  553. void CPropertyList::PreSubclassWindow()
  554. {
  555. m_bDivIsSet = FALSE;
  556. m_nDivider = 0;
  557. m_bTracking = FALSE;
  558. m_curSel = 1;
  559. m_hCursorSize = AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);
  560. m_hCursorArrow = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
  561. m_SSerif8Font.CreatePointFont(80,_T("MS Sans Serif"));
  562. }
  563. CPropertyItem* CPropertyList::GetItem(int index)
  564. {
  565. return (CPropertyItem*)GetItemDataPtr(index);
  566. }
  567. void CPropertyList::OnRButtonUp( UINT nFlags, CPoint point )
  568. {
  569. CMenu menu;
  570. CRect rect;
  571. this->GetWindowRect(&rect);
  572. BOOL loc;
  573. m_curSel = ItemFromPoint(point,loc);
  574. menu.CreatePopupMenu();
  575. menu.AppendMenu(MF_STRING | MF_ENABLED, 44, "Ignore Cache Entry");
  576. menu.AppendMenu(MF_STRING | MF_ENABLED, 42, "Delete Cache Entry");
  577. menu.AppendMenu(MF_STRING | MF_ENABLED, 43, "Help For Cache Entry");
  578. menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
  579. rect.TopLeft().x + point.x,
  580. rect.TopLeft().y + point.y, this, NULL);
  581. }
  582. void CPropertyList::RemoveProperty(const char* name)
  583. {
  584. this->HideControls();
  585. for(int i =0; i < this->GetCount(); ++i)
  586. {
  587. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(i);
  588. if(pItem->m_propName == name)
  589. {
  590. m_PropertyItems.erase(pItem);
  591. delete pItem;
  592. this->DeleteString(i);
  593. return;
  594. }
  595. }
  596. }
  597. void CPropertyList::OnIgnore()
  598. {
  599. if(m_curSel == -1 || this->GetCount() <= 0)
  600. {
  601. return;
  602. }
  603. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  604. pItem->m_curValue = "IGNORE";
  605. InvalidateList();
  606. }
  607. void CPropertyList::OnDelete()
  608. {
  609. if(m_curSel == -1 || this->GetCount() <= 0)
  610. {
  611. return;
  612. }
  613. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  614. m_CMakeSetupDialog->GetCMakeInstance()->GetCacheManager()->RemoveCacheEntry(pItem->m_propName);
  615. m_PropertyItems.erase(pItem);
  616. delete pItem;
  617. this->DeleteString(m_curSel);
  618. this->HideControls();
  619. this->SetTopIndex(0);
  620. InvalidateList();
  621. }
  622. void CPropertyList::OnHelp()
  623. {
  624. if(m_curSel == -1 || this->GetCount() <= 0)
  625. {
  626. return;
  627. }
  628. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  629. MessageBox(pItem->m_HelpString, pItem->m_propName, MB_OK|MB_ICONINFORMATION);
  630. }
  631. void CPropertyList::RemoveAll()
  632. {
  633. int c = this->GetCount();
  634. for(int i =0; i < c; ++i)
  635. {
  636. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(0);
  637. this->DeleteString(0);
  638. }
  639. for(std::set<CPropertyItem*>::iterator ii = m_PropertyItems.begin();
  640. ii != m_PropertyItems.end(); ++ii)
  641. {
  642. delete *ii;
  643. }
  644. m_PropertyItems.clear();
  645. m_Dirty = false;
  646. this->HideControls();
  647. InvalidateList();
  648. }
  649. void CPropertyList::InvalidateList()
  650. {
  651. Invalidate();
  652. m_Dirty = true;
  653. }
  654. void CPropertyList::ShowAdvanced()
  655. {
  656. this->SetRedraw(FALSE);
  657. this->ResetContent();
  658. m_ShowAdvanced = true;
  659. std::map<std::string, CPropertyItem*> sortProps;
  660. for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
  661. i != m_PropertyItems.end(); ++i)
  662. {
  663. sortProps[(const char*)(*i)->m_propName] = *i;
  664. }
  665. for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
  666. i != sortProps.end(); ++i)
  667. {
  668. CPropertyItem* item = i->second;
  669. if(item->m_NewValue)
  670. {
  671. this->AddPropItem(item, 2);
  672. }
  673. }
  674. for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
  675. i != sortProps.end(); ++i)
  676. {
  677. CPropertyItem* item = i->second;
  678. if(!item->m_NewValue)
  679. {
  680. this->AddPropItem(item, 2);
  681. }
  682. }
  683. this->SetRedraw(TRUE);
  684. this->InvalidateList();
  685. }
  686. void CPropertyList::HideAdvanced()
  687. {
  688. this->SetRedraw(FALSE);
  689. this->ResetContent();
  690. m_ShowAdvanced = false;
  691. std::map<std::string, CPropertyItem*> sortProps;
  692. for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
  693. i != m_PropertyItems.end(); ++i)
  694. {
  695. sortProps[(const char*)(*i)->m_propName] = *i;
  696. }
  697. for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
  698. i != sortProps.end(); ++i)
  699. {
  700. CPropertyItem* item = i->second;
  701. if(item->m_NewValue && !item->m_Advanced)
  702. {
  703. this->AddPropItem(item, 2);
  704. }
  705. }
  706. for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
  707. i != sortProps.end(); ++i)
  708. {
  709. CPropertyItem* item = i->second;
  710. if(!item->m_Advanced && !item->m_NewValue)
  711. {
  712. this->AddPropItem(item, 2);
  713. }
  714. }
  715. this->SetRedraw(TRUE);
  716. this->InvalidateList();
  717. }