PropertyList.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. // PropertyList.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "PropertyList.h"
  5. #define IDC_PROPCMBBOX 712
  6. #define IDC_PROPEDITBOX 713
  7. #define IDC_PROPBTNCTRL 714
  8. #define IDC_PROPCHECKBOXCTRL 715
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CPropertyList
  11. CPropertyList::CPropertyList()
  12. {
  13. m_Dirty = false;
  14. m_curSel = -1;
  15. }
  16. CPropertyList::~CPropertyList()
  17. {
  18. for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
  19. i != m_PropertyItems.end(); ++i)
  20. {
  21. delete *i;
  22. }
  23. }
  24. BEGIN_MESSAGE_MAP(CPropertyList, CListBox)
  25. //{{AFX_MSG_MAP(CPropertyList)
  26. ON_WM_CREATE()
  27. ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange)
  28. ON_WM_LBUTTONUP()
  29. ON_WM_KILLFOCUS()
  30. ON_WM_LBUTTONDOWN()
  31. ON_WM_RBUTTONUP()
  32. ON_WM_MOUSEMOVE()
  33. //}}AFX_MSG_MAP
  34. ON_CBN_KILLFOCUS(IDC_PROPCMBBOX, OnKillfocusCmbBox)
  35. ON_CBN_SELCHANGE(IDC_PROPCMBBOX, OnSelchangeCmbBox)
  36. ON_EN_KILLFOCUS(IDC_PROPEDITBOX, OnKillfocusEditBox)
  37. ON_EN_CHANGE(IDC_PROPEDITBOX, OnChangeEditBox)
  38. ON_BN_CLICKED(IDC_PROPBTNCTRL, OnButton)
  39. ON_BN_CLICKED(IDC_PROPCHECKBOXCTRL, OnCheckBox)
  40. ON_COMMAND(42, OnDelete)
  41. ON_COMMAND(43, OnHelp)
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CPropertyList message handlers
  45. BOOL CPropertyList::PreCreateWindow(CREATESTRUCT& cs)
  46. {
  47. if (!CListBox::PreCreateWindow(cs))
  48. return FALSE;
  49. cs.style &= ~(LBS_OWNERDRAWVARIABLE | LBS_SORT);
  50. cs.style |= LBS_OWNERDRAWFIXED;
  51. m_bTracking = FALSE;
  52. m_nDivider = 0;
  53. m_bDivIsSet = FALSE;
  54. return TRUE;
  55. }
  56. void CPropertyList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  57. {
  58. lpMeasureItemStruct->itemHeight = 20; //pixels
  59. }
  60. void CPropertyList::DrawItem(LPDRAWITEMSTRUCT lpDIS)
  61. {
  62. CDC dc;
  63. dc.Attach(lpDIS->hDC);
  64. CRect rectFull = lpDIS->rcItem;
  65. CRect rect = rectFull;
  66. if (m_nDivider==0)
  67. m_nDivider = rect.Width() / 2;
  68. rect.left = m_nDivider;
  69. CRect rect2 = rectFull;
  70. rect2.right = rect.left - 1;
  71. UINT nIndex = lpDIS->itemID;
  72. if (nIndex != (UINT) -1)
  73. {
  74. //draw two rectangles, one for each row column
  75. dc.FillSolidRect(rect2,RGB(192,192,192));
  76. dc.DrawEdge(rect2,EDGE_SUNKEN,BF_BOTTOMRIGHT);
  77. dc.DrawEdge(rect,EDGE_SUNKEN,BF_BOTTOM);
  78. //get the CPropertyItem for the current row
  79. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(nIndex);
  80. //write the property name in the first rectangle
  81. dc.SetBkMode(TRANSPARENT);
  82. dc.DrawText(pItem->m_propName,CRect(rect2.left+3,rect2.top+3,
  83. rect2.right-3,rect2.bottom+3),
  84. DT_LEFT | DT_SINGLELINE);
  85. //write the initial property value in the second rectangle
  86. dc.DrawText(pItem->m_curValue,CRect(rect.left+3,rect.top+3,
  87. rect.right+3,rect.bottom+3),
  88. DT_LEFT | DT_SINGLELINE);
  89. }
  90. dc.Detach();
  91. }
  92. int CPropertyList::AddItem(CString txt)
  93. {
  94. int nIndex = AddString(txt);
  95. return nIndex;
  96. }
  97. int CPropertyList::AddPropItem(CPropertyItem* pItem)
  98. {
  99. int nIndex = AddString(_T(""));
  100. SetItemDataPtr(nIndex,pItem);
  101. m_PropertyItems.insert(pItem);
  102. return nIndex;
  103. }
  104. int CPropertyList::AddProperty(const char* name,
  105. const char* value,
  106. const char* helpString,
  107. int type,
  108. const char* comboItems)
  109. {
  110. CPropertyItem* pItem = 0;
  111. for(int i =0; i < this->GetCount(); ++i)
  112. {
  113. CPropertyItem* item = this->GetItem(i);
  114. if(item->m_propName == name)
  115. {
  116. pItem = item;
  117. if(pItem->m_curValue != value)
  118. {
  119. pItem->m_curValue = value;
  120. pItem->m_HelpString = helpString;
  121. m_Dirty = true;
  122. Invalidate();
  123. }
  124. return i;
  125. }
  126. }
  127. // if it is not in the displayed list, then
  128. // check for it in the m_PropertyItems list as
  129. // a removed item
  130. for(std::set<CPropertyItem*>::iterator
  131. p = m_PropertyItems.begin();
  132. p != m_PropertyItems.end(); ++p)
  133. {
  134. if((*p)->m_propName == name)
  135. {
  136. pItem = *p;
  137. pItem->m_Removed = false;
  138. pItem->m_curValue = value;
  139. pItem->m_HelpString = helpString;
  140. Invalidate();
  141. }
  142. }
  143. // if it is not found, then create a new one
  144. if(!pItem)
  145. {
  146. pItem = new CPropertyItem(name, value, helpString, type, comboItems);
  147. }
  148. return this->AddPropItem(pItem);
  149. }
  150. int CPropertyList::OnCreate(LPCREATESTRUCT lpCreateStruct)
  151. {
  152. if (CListBox::OnCreate(lpCreateStruct) == -1)
  153. return -1;
  154. m_bDivIsSet = FALSE;
  155. m_nDivider = 0;
  156. m_bTracking = FALSE;
  157. m_hCursorSize = AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);
  158. m_hCursorArrow = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
  159. m_SSerif8Font.CreatePointFont(80,_T("MS Sans Serif"));
  160. return 0;
  161. }
  162. void CPropertyList::OnSelchange()
  163. {
  164. CRect rect;
  165. CString lBoxSelText;
  166. GetItemRect(m_curSel,rect);
  167. rect.left = m_nDivider;
  168. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  169. if (m_btnCtrl)
  170. m_btnCtrl.ShowWindow(SW_HIDE);
  171. if (m_CheckBoxControl)
  172. m_CheckBoxControl.ShowWindow(SW_HIDE);
  173. if (pItem->m_nItemType==CPropertyList::COMBO)
  174. {
  175. //display the combo box. If the combo box has already been
  176. //created then simply move it to the new location, else create it
  177. m_nLastBox = 0;
  178. if (m_cmbBox)
  179. m_cmbBox.MoveWindow(rect);
  180. else
  181. {
  182. rect.bottom += 100;
  183. m_cmbBox.Create(CBS_DROPDOWNLIST
  184. | CBS_NOINTEGRALHEIGHT | WS_VISIBLE
  185. | WS_CHILD | WS_BORDER,
  186. rect,this,IDC_PROPCMBBOX);
  187. m_cmbBox.SetFont(&m_SSerif8Font);
  188. }
  189. //add the choices for this particular property
  190. CString cmbItems = pItem->m_cmbItems;
  191. lBoxSelText = pItem->m_curValue;
  192. m_cmbBox.ResetContent();
  193. int i,i2;
  194. i=0;
  195. while ((i2=cmbItems.Find('|',i)) != -1)
  196. {
  197. m_cmbBox.AddString(cmbItems.Mid(i,i2-i));
  198. i=i2+1;
  199. }
  200. if(i != 0)
  201. m_cmbBox.AddString(cmbItems.Mid(i));
  202. m_cmbBox.ShowWindow(SW_SHOW);
  203. m_cmbBox.SetFocus();
  204. //jump to the property's current value in the combo box
  205. int j = m_cmbBox.FindStringExact(0,lBoxSelText);
  206. if (j != CB_ERR)
  207. m_cmbBox.SetCurSel(j);
  208. else
  209. m_cmbBox.SetCurSel(0);
  210. }
  211. else if (pItem->m_nItemType==CPropertyList::EDIT)
  212. {
  213. //display edit box
  214. m_nLastBox = 1;
  215. m_prevSel = m_curSel;
  216. rect.bottom -= 3;
  217. if (m_editBox)
  218. m_editBox.MoveWindow(rect);
  219. else
  220. {
  221. m_editBox.Create(ES_LEFT | ES_AUTOHSCROLL | WS_VISIBLE
  222. | WS_CHILD | WS_BORDER,
  223. rect,this,IDC_PROPEDITBOX);
  224. m_editBox.SetFont(&m_SSerif8Font);
  225. }
  226. lBoxSelText = pItem->m_curValue;
  227. m_editBox.ShowWindow(SW_SHOW);
  228. m_editBox.SetFocus();
  229. //set the text in the edit box to the property's current value
  230. m_editBox.SetWindowText(lBoxSelText);
  231. }
  232. else if (pItem->m_nItemType == CPropertyList::CHECKBOX)
  233. {
  234. rect.bottom -= 3;
  235. if (m_CheckBoxControl)
  236. m_CheckBoxControl.MoveWindow(rect);
  237. else
  238. {
  239. m_CheckBoxControl.Create("check",BS_CHECKBOX
  240. | BM_SETCHECK |BS_LEFTTEXT
  241. | WS_VISIBLE | WS_CHILD,
  242. rect,this,IDC_PROPCHECKBOXCTRL);
  243. m_CheckBoxControl.SetFont(&m_SSerif8Font);
  244. }
  245. lBoxSelText = pItem->m_curValue;
  246. m_CheckBoxControl.ShowWindow(SW_SHOW);
  247. m_CheckBoxControl.SetFocus();
  248. //set the text in the edit box to the property's current value
  249. if(lBoxSelText == "ON")
  250. {
  251. m_CheckBoxControl.SetCheck(1);
  252. }
  253. else
  254. {
  255. m_CheckBoxControl.SetCheck(0);
  256. }
  257. }
  258. else
  259. DisplayButton(rect);
  260. }
  261. void CPropertyList::DisplayButton(CRect region)
  262. {
  263. //displays a button if the property is a file/color/font chooser
  264. m_nLastBox = 2;
  265. m_prevSel = m_curSel;
  266. if (region.Width() > 25)
  267. region.left = region.right - 25;
  268. region.bottom -= 3;
  269. if (m_btnCtrl)
  270. m_btnCtrl.MoveWindow(region);
  271. else
  272. {
  273. m_btnCtrl.Create("...",BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD,
  274. region,this,IDC_PROPBTNCTRL);
  275. m_btnCtrl.SetFont(&m_SSerif8Font);
  276. }
  277. m_btnCtrl.ShowWindow(SW_SHOW);
  278. m_btnCtrl.SetFocus();
  279. }
  280. void CPropertyList::OnKillFocus(CWnd* pNewWnd)
  281. {
  282. //m_btnCtrl.ShowWindow(SW_HIDE);
  283. CListBox::OnKillFocus(pNewWnd);
  284. }
  285. void CPropertyList::OnKillfocusCmbBox()
  286. {
  287. m_cmbBox.ShowWindow(SW_HIDE);
  288. Invalidate();
  289. }
  290. void CPropertyList::OnKillfocusEditBox()
  291. {
  292. CString newStr;
  293. m_editBox.ShowWindow(SW_HIDE);
  294. Invalidate();
  295. }
  296. void CPropertyList::OnSelchangeCmbBox()
  297. {
  298. CString selStr;
  299. if (m_cmbBox)
  300. {
  301. m_cmbBox.GetLBText(m_cmbBox.GetCurSel(),selStr);
  302. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  303. pItem->m_curValue = selStr;
  304. m_Dirty = true;
  305. }
  306. }
  307. void CPropertyList::OnChangeEditBox()
  308. {
  309. CString newStr;
  310. m_editBox.GetWindowText(newStr);
  311. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  312. pItem->m_curValue = newStr;
  313. m_Dirty = true;
  314. }
  315. void CPropertyList::OnCheckBox()
  316. {
  317. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  318. if(m_CheckBoxControl.GetCheck())
  319. {
  320. pItem->m_curValue = "ON";
  321. }
  322. else
  323. {
  324. pItem->m_curValue = "OFF";
  325. }
  326. m_Dirty = true;
  327. }
  328. // Insane Microsoft way of setting the initial directory
  329. // for the Shbrowseforfolder function...
  330. // SetSelProc
  331. // Callback procedure to set the initial selection of the browser.
  332. int CALLBACK SetSelProc( HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM
  333. lpData )
  334. {
  335. if (uMsg==BFFM_INITIALIZED)
  336. {
  337. ::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData );
  338. }
  339. return 0;
  340. }
  341. void CPropertyList::OnButton()
  342. {
  343. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  344. //display the appropriate common dialog depending on what type
  345. //of chooser is associated with the property
  346. if (pItem->m_nItemType == CPropertyList::COLOR)
  347. {
  348. COLORREF initClr;
  349. CString currClr = pItem->m_curValue;
  350. //parse the property's current color value
  351. if (currClr.Find("RGB") > -1)
  352. {
  353. int j = currClr.Find(',',3);
  354. CString bufr = currClr.Mid(4,j-4);
  355. int RVal = atoi(bufr);
  356. int j2 = currClr.Find(',',j+1);
  357. bufr = currClr.Mid(j+1,j2-(j+1));
  358. int GVal = atoi(bufr);
  359. int j3 = currClr.Find(')',j2+1);
  360. bufr = currClr.Mid(j2+1,j3-(j2+1));
  361. int BVal = atoi(bufr);
  362. initClr = RGB(RVal,GVal,BVal);
  363. }
  364. else
  365. initClr = 0;
  366. CColorDialog ClrDlg(initClr);
  367. if (IDOK == ClrDlg.DoModal())
  368. {
  369. COLORREF selClr = ClrDlg.GetColor();
  370. CString clrStr;
  371. clrStr.Format("RGB(%d,%d,%d)",GetRValue(selClr),
  372. GetGValue(selClr),GetBValue(selClr));
  373. m_btnCtrl.ShowWindow(SW_HIDE);
  374. pItem->m_curValue = clrStr;
  375. m_Dirty = true;
  376. Invalidate();
  377. }
  378. }
  379. else if (pItem->m_nItemType == CPropertyList::FILE)
  380. {
  381. CString SelectedFile;
  382. CString Filter("All Files (*.*)||");
  383. CFileDialog FileDlg(TRUE, NULL, NULL, NULL,
  384. Filter);
  385. CString initialDir;
  386. CString currPath = pItem->m_curValue;
  387. if (currPath.GetLength() > 0)
  388. {
  389. int endSlash = currPath.ReverseFind('\\');
  390. if(endSlash == -1)
  391. {
  392. endSlash = currPath.ReverseFind('/');
  393. }
  394. initialDir = currPath.Left(endSlash);
  395. }
  396. initialDir.Replace("/", "\\");
  397. FileDlg.m_ofn.lpstrTitle = "Select file";
  398. if (currPath.GetLength() > 0)
  399. FileDlg.m_ofn.lpstrInitialDir = initialDir;
  400. if(IDOK == FileDlg.DoModal())
  401. {
  402. SelectedFile = FileDlg.GetPathName();
  403. m_btnCtrl.ShowWindow(SW_HIDE);
  404. pItem->m_curValue = SelectedFile;
  405. m_Dirty = true;
  406. Invalidate();
  407. }
  408. }
  409. else if (pItem->m_nItemType == CPropertyList::PATH)
  410. {
  411. CString initialDir;
  412. CString currPath = pItem->m_curValue;
  413. if (currPath.GetLength() > 0)
  414. {
  415. int endSlash = currPath.ReverseFind('\\');
  416. if(endSlash == -1)
  417. {
  418. endSlash = currPath.ReverseFind('/');
  419. }
  420. initialDir = currPath.Left(endSlash);
  421. }
  422. initialDir.Replace("/", "\\");
  423. char szPathName[4096];
  424. BROWSEINFO bi;
  425. bi.lpfn = SetSelProc;
  426. bi.lParam = (LPARAM)(LPCSTR) initialDir;
  427. bi.hwndOwner = m_hWnd;
  428. bi.pidlRoot = NULL;
  429. bi.pszDisplayName = (LPTSTR)szPathName;
  430. bi.lpszTitle = "Select Directory";
  431. bi.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS;
  432. LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
  433. BOOL bSuccess = SHGetPathFromIDList(pidl, szPathName);
  434. CString SelectedFile;
  435. if(bSuccess)
  436. {
  437. SelectedFile = szPathName;
  438. m_btnCtrl.ShowWindow(SW_HIDE);
  439. pItem->m_curValue = SelectedFile;
  440. m_Dirty = true;
  441. Invalidate();
  442. }
  443. }
  444. else if (pItem->m_nItemType == CPropertyList::FONT)
  445. {
  446. CFontDialog FontDlg(NULL,CF_EFFECTS | CF_SCREENFONTS,NULL,this);
  447. if(IDOK == FontDlg.DoModal())
  448. {
  449. CString faceName = FontDlg.GetFaceName();
  450. m_btnCtrl.ShowWindow(SW_HIDE);
  451. pItem->m_curValue = faceName;
  452. m_Dirty = true;
  453. Invalidate();
  454. }
  455. }
  456. }
  457. void CPropertyList::OnLButtonUp(UINT nFlags, CPoint point)
  458. {
  459. if (m_bTracking)
  460. {
  461. //if columns were being resized then this indicates
  462. //that mouse is up so resizing is done. Need to redraw
  463. //columns to reflect their new widths.
  464. m_bTracking = FALSE;
  465. //if mouse was captured then release it
  466. if (GetCapture()==this)
  467. ::ReleaseCapture();
  468. ::ClipCursor(NULL);
  469. CClientDC dc(this);
  470. InvertLine(&dc,CPoint(point.x,m_nDivTop),CPoint(point.x,m_nDivBtm));
  471. //set the divider position to the new value
  472. m_nDivider = point.x;
  473. //redraw
  474. Invalidate();
  475. }
  476. else
  477. {
  478. BOOL loc;
  479. int i = ItemFromPoint(point,loc);
  480. m_curSel = i;
  481. CListBox::OnLButtonUp(nFlags, point);
  482. }
  483. }
  484. void CPropertyList::OnLButtonDown(UINT nFlags, CPoint point)
  485. {
  486. if ((point.x>=m_nDivider-5) && (point.x<=m_nDivider+5))
  487. {
  488. //if mouse clicked on divider line, then start resizing
  489. ::SetCursor(m_hCursorSize);
  490. CRect windowRect;
  491. GetWindowRect(windowRect);
  492. windowRect.left += 10; windowRect.right -= 10;
  493. //do not let mouse leave the list box boundary
  494. ::ClipCursor(windowRect);
  495. if (m_cmbBox)
  496. m_cmbBox.ShowWindow(SW_HIDE);
  497. if (m_editBox)
  498. m_editBox.ShowWindow(SW_HIDE);
  499. CRect clientRect;
  500. GetClientRect(clientRect);
  501. m_bTracking = TRUE;
  502. m_nDivTop = clientRect.top;
  503. m_nDivBtm = clientRect.bottom;
  504. m_nOldDivX = point.x;
  505. CClientDC dc(this);
  506. InvertLine(&dc,CPoint(m_nOldDivX,m_nDivTop),CPoint(m_nOldDivX,m_nDivBtm));
  507. //capture the mouse
  508. SetCapture();
  509. }
  510. else
  511. {
  512. m_bTracking = FALSE;
  513. CListBox::OnLButtonDown(nFlags, point);
  514. }
  515. }
  516. void CPropertyList::OnMouseMove(UINT nFlags, CPoint point)
  517. {
  518. if (m_bTracking)
  519. {
  520. //move divider line to the mouse pos. if columns are
  521. //currently being resized
  522. CClientDC dc(this);
  523. //remove old divider line
  524. InvertLine(&dc,CPoint(m_nOldDivX,m_nDivTop),CPoint(m_nOldDivX,m_nDivBtm));
  525. //draw new divider line
  526. InvertLine(&dc,CPoint(point.x,m_nDivTop),CPoint(point.x,m_nDivBtm));
  527. m_nOldDivX = point.x;
  528. }
  529. else if ((point.x >= m_nDivider-5) && (point.x <= m_nDivider+5))
  530. //set the cursor to a sizing cursor if the cursor is over the row divider
  531. ::SetCursor(m_hCursorSize);
  532. else
  533. CListBox::OnMouseMove(nFlags, point);
  534. }
  535. void CPropertyList::InvertLine(CDC* pDC,CPoint ptFrom,CPoint ptTo)
  536. {
  537. int nOldMode = pDC->SetROP2(R2_NOT);
  538. pDC->MoveTo(ptFrom);
  539. pDC->LineTo(ptTo);
  540. pDC->SetROP2(nOldMode);
  541. }
  542. void CPropertyList::PreSubclassWindow()
  543. {
  544. m_bDivIsSet = FALSE;
  545. m_nDivider = 0;
  546. m_bTracking = FALSE;
  547. m_curSel = 1;
  548. m_hCursorSize = AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);
  549. m_hCursorArrow = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
  550. m_SSerif8Font.CreatePointFont(80,_T("MS Sans Serif"));
  551. }
  552. CPropertyItem* CPropertyList::GetItem(int index)
  553. {
  554. return (CPropertyItem*)GetItemDataPtr(index);
  555. }
  556. void CPropertyList::OnRButtonUp( UINT nFlags, CPoint point )
  557. {
  558. CMenu menu;
  559. CRect rect;
  560. this->GetWindowRect(&rect);
  561. BOOL loc;
  562. m_curSel = ItemFromPoint(point,loc);
  563. menu.CreatePopupMenu();
  564. menu.AppendMenu(MF_STRING | MF_ENABLED, 42, "Delete Cache Entry");
  565. menu.AppendMenu(MF_STRING | MF_ENABLED, 43, "Help For Cache Entry");
  566. menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
  567. rect.TopLeft().x + point.x,
  568. rect.TopLeft().y + point.y, this, NULL);
  569. }
  570. void CPropertyList::OnDelete()
  571. {
  572. if(m_curSel == -1 || this->GetCount() <= 0)
  573. {
  574. return;
  575. }
  576. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  577. pItem->m_Removed = true;
  578. this->DeleteString(m_curSel);
  579. Invalidate();
  580. }
  581. void CPropertyList::OnHelp()
  582. {
  583. if(m_curSel == -1 || this->GetCount() <= 0)
  584. {
  585. return;
  586. }
  587. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
  588. MessageBox(pItem->m_HelpString);
  589. }
  590. void CPropertyList::RemoveAll()
  591. {
  592. int c = this->GetCount();
  593. for(int i =0; i < c; ++i)
  594. {
  595. CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(0);
  596. pItem->m_Removed = true;
  597. this->DeleteString(0);
  598. }
  599. Invalidate();
  600. }