QListCtrl.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. // QListCtrl.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "QListCtrl.h"
  6. #include "ProcessPaste.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #define ROW_BOTTOM_BORDER 2
  13. #define ROW_LEFT_BORDER 3
  14. #define COLOR_SHADOW RGB(245, 245, 245)
  15. #define DUMMY_COL_WIDTH 1
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CQListCtrl
  18. CQListCtrl::CQListCtrl()
  19. {
  20. m_pchTip = NULL;
  21. m_pwchTip = NULL;
  22. LOGFONT lf;
  23. lf.lfHeight = -9;
  24. lf.lfWidth = 0;
  25. lf.lfEscapement = 0;
  26. lf.lfOrientation = 0;
  27. lf.lfWeight = FW_LIGHT;
  28. lf.lfItalic = FALSE;
  29. lf.lfUnderline = FALSE;
  30. lf.lfStrikeOut = FALSE;
  31. lf.lfCharSet = ANSI_CHARSET;
  32. lf.lfOutPrecision = OUT_STRING_PRECIS;
  33. lf.lfClipPrecision = CLIP_STROKE_PRECIS;
  34. lf.lfQuality = DEFAULT_QUALITY;
  35. lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
  36. lstrcpy(lf.lfFaceName, "Small Font");
  37. m_SmallFont = CreateFontIndirect(&lf);
  38. m_bShowTextForFirstTenHotKeys = true;
  39. m_bStartTop = true;
  40. // m_Accelerator = NULL; //!!!!!
  41. }
  42. CQListCtrl::~CQListCtrl()
  43. {
  44. if(m_pchTip != NULL)
  45. delete m_pchTip;
  46. if(m_pwchTip != NULL)
  47. delete m_pwchTip;
  48. DestroyAndCreateAccelerator(FALSE);
  49. }
  50. // returns the position 1-10 if the index is in the FirstTen block else -1
  51. int CQListCtrl::GetFirstTenNum( int index )
  52. {
  53. // set firstTenNum to the first ten number (1-10) corresponding to the given index
  54. int firstTenNum = -1; // -1 means that nItem is not in the FirstTen block.
  55. int count = GetItemCount();
  56. if( m_bStartTop )
  57. {
  58. if( 0 <= index && index <= 9 )
  59. firstTenNum = index + 1;
  60. }
  61. else // we are starting at the bottom and going up
  62. {
  63. int idxStartFirstTen = count-10; // start of the FirstTen block
  64. // if index is within the FirstTen block
  65. if( idxStartFirstTen <= index && index < count )
  66. firstTenNum = count - index;
  67. }
  68. return firstTenNum;
  69. }
  70. // returns the list index corresponding to the given FirstTen position number.
  71. // (ret < 0) means that "num" is not in the FirstTen block
  72. int CQListCtrl::GetFirstTenIndex( int num )
  73. {
  74. if( num <= 0 || num > 10 )
  75. return -1;
  76. if( m_bStartTop )
  77. return num-1;
  78. // else we are starting at the bottom and going up
  79. int count = GetItemCount();
  80. return count - num;
  81. }
  82. BEGIN_MESSAGE_MAP(CQListCtrl, CListCtrl)
  83. //{{AFX_MSG_MAP(CQListCtrl)
  84. ON_NOTIFY_REFLECT(LVN_KEYDOWN, OnKeydown)
  85. ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
  86. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdrawList)
  87. ON_WM_SYSKEYDOWN()
  88. ON_WM_ERASEBKGND()
  89. ON_WM_CREATE()
  90. ON_WM_VSCROLL()
  91. ON_WM_HSCROLL()
  92. //}}AFX_MSG_MAP
  93. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
  94. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
  95. ON_WM_KILLFOCUS()
  96. END_MESSAGE_MAP()
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CQListCtrl message handlers
  99. void CQListCtrl::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult)
  100. {
  101. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  102. switch (pLVKeyDow->wVKey)
  103. {
  104. case VK_RETURN:
  105. {
  106. ARRAY arr;
  107. GetSelectionIndexes(arr);
  108. SendSelection(arr);
  109. }
  110. break;
  111. case VK_ESCAPE:
  112. GetParent()->SendMessage(NM_END, 0, 0);
  113. break;
  114. case VK_RIGHT:
  115. {
  116. int nItem = GetNextItem(-1, LVNI_SELECTED);
  117. if (nItem != -1)
  118. GetParent()->SendMessage(NM_RIGHT, nItem, 0);
  119. }
  120. break;
  121. case VK_LEFT:
  122. GetParent()->SendMessage(NM_LEFT, 0, 0);
  123. break;
  124. case VK_DELETE:
  125. GetParent()->SendMessage(NM_DELETE, 0, 0);
  126. break;
  127. }
  128. *pResult = 0;
  129. }
  130. void CQListCtrl::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
  131. {
  132. LPNMITEMACTIVATE lpnmItem = (LPNMITEMACTIVATE) pNMHDR;
  133. UINT Flags;
  134. int nItem = -1;
  135. if ((nItem = HitTest(lpnmItem->ptAction, &Flags)) != -1)
  136. {
  137. if (Flags | LVHT_ONITEM)
  138. SendSelection(nItem);
  139. }
  140. *pResult = 0;
  141. }
  142. void CQListCtrl::SendSelection(int nItem)
  143. {
  144. GetParent()->SendMessage(NM_SELECT, 1, (LPARAM) &nItem);
  145. }
  146. void CQListCtrl::SendSelection(ARRAY &arrItems)
  147. {
  148. GetParent()->SendMessage(NM_SELECT, arrItems.GetSize(), (LPARAM) arrItems.GetData());
  149. }
  150. void CQListCtrl::GetSelectionIndexes(ARRAY &arr)
  151. {
  152. arr.RemoveAll();
  153. POSITION pos = GetFirstSelectedItemPosition();
  154. while (pos)
  155. arr.Add(GetNextSelectedItem(pos));
  156. /*
  157. int nItem = GetNextItem(-1, LVNI_SELECTED);
  158. while (nItem != -1)
  159. {
  160. arr.Add(nItem);
  161. nItem = GetNextItem(nItem, LVNI_SELECTED);
  162. }
  163. */
  164. }
  165. void CQListCtrl::GetSelectionItemData(ARRAY &arr)
  166. {
  167. DWORD dwData;
  168. int i;
  169. arr.RemoveAll();
  170. POSITION pos = GetFirstSelectedItemPosition();
  171. while (pos)
  172. {
  173. i = GetNextSelectedItem(pos);
  174. dwData = GetItemData(i);
  175. arr.Add( dwData );
  176. }
  177. /*
  178. int nItem = GetNextItem(-1, LVNI_SELECTED);
  179. while (nItem != -1)
  180. {
  181. arr.Add((int)GetItemData(nItem));
  182. nItem = GetNextItem(nItem, LVNI_SELECTED);
  183. }
  184. */
  185. }
  186. void CQListCtrl::RemoveAllSelection()
  187. {
  188. POSITION pos = GetFirstSelectedItemPosition();
  189. while (pos)
  190. {
  191. SetSelection(GetNextSelectedItem(pos), FALSE);
  192. }
  193. }
  194. BOOL CQListCtrl::SetSelection(int nRow, BOOL bSelect)
  195. {
  196. if(bSelect)
  197. return SetItemState(nRow, LVIS_SELECTED, LVIS_SELECTED);
  198. else
  199. return SetItemState(nRow, ~LVIS_SELECTED, LVIS_SELECTED);
  200. }
  201. BOOL CQListCtrl::SetText(int nRow, int nCol, CString cs)
  202. {
  203. return SetItemText(nRow, nCol, cs);
  204. }
  205. BOOL CQListCtrl::SetCaret(int nRow, BOOL bFocus)
  206. {
  207. if(bFocus)
  208. return SetItemState(nRow, LVIS_FOCUSED, LVIS_FOCUSED);
  209. else
  210. return SetItemState(nRow, ~LVIS_FOCUSED, LVIS_FOCUSED);
  211. }
  212. long CQListCtrl::GetCaret()
  213. {
  214. return GetNextItem(-1, LVNI_FOCUSED);
  215. }
  216. // moves the caret to the given index, selects it, and ensures it is visible.
  217. BOOL CQListCtrl::SetListPos( int index )
  218. {
  219. if( index < 0 || index >= GetItemCount() )
  220. return FALSE;
  221. RemoveAllSelection();
  222. SetCaret(index);
  223. SetSelection(index);
  224. EnsureVisible(index,FALSE);
  225. return TRUE;
  226. }
  227. BOOL CQListCtrl::SetFormattedText(int nRow, int nCol, LPCTSTR lpszFormat,...)
  228. {
  229. CString csText;
  230. va_list vlist;
  231. ASSERT(AfxIsValidString(lpszFormat));
  232. va_start(vlist,lpszFormat);
  233. csText.FormatV(lpszFormat,vlist);
  234. va_end(vlist);
  235. return SetText(nRow,nCol,csText);
  236. }
  237. void CQListCtrl::SetNumberOfLinesPerRow(int nLines)
  238. {
  239. CDC *pDC = GetDC();
  240. CRect crRect(0, 0, 0, 0);
  241. CFont *pOldFont = pDC->SelectObject(GetFont());
  242. //Get the height to draw one character
  243. pDC->DrawText("W", crRect, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
  244. pDC->SelectObject(pOldFont);
  245. //Get the total height of each row
  246. int nHeight = (crRect.Height() * nLines) + ROW_BOTTOM_BORDER;
  247. //Create a image list of that height and set it to the list box
  248. CImageList imglist;
  249. imglist.Create(DUMMY_COL_WIDTH, nHeight, ILC_COLOR16 | ILC_MASK, 1, 1);
  250. SetImageList(&imglist, LVSIL_SMALL );
  251. }
  252. void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
  253. {
  254. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  255. *pResult = 0;
  256. // Request item-specific notifications if this is the
  257. // beginning of the paint cycle.
  258. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
  259. {
  260. *pResult = CDRF_NOTIFYITEMDRAW;
  261. }
  262. else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
  263. {
  264. LVITEM rItem;
  265. int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
  266. CDC* pDC = CDC::FromHandle ( pLVCD->nmcd.hdc );
  267. COLORREF crBkgnd;
  268. BOOL bListHasFocus;
  269. CRect rcItem;
  270. bListHasFocus = ( GetSafeHwnd() == ::GetFocus() );
  271. // Get the image index and selected/focused state of the
  272. // item being drawn.
  273. ZeroMemory ( &rItem, sizeof(LVITEM) );
  274. rItem.mask = LVIF_STATE;
  275. rItem.iItem = nItem;
  276. rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  277. GetItem(&rItem);
  278. // Get the rect that bounds the text label.
  279. GetItemRect(nItem, rcItem, LVIR_LABEL);
  280. rcItem.left -= DUMMY_COL_WIDTH;
  281. CPen cpWhite;
  282. cpWhite.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
  283. CPen *pOldPen = NULL;
  284. COLORREF OldColor = -1;
  285. int nOldBKMode = -1;
  286. // Draw the background of the list item. Colors are selected
  287. // according to the item's state.
  288. if(rItem.state & LVIS_SELECTED)
  289. {
  290. if(bListHasFocus)
  291. {
  292. crBkgnd = GetSysColor(COLOR_HIGHLIGHT);
  293. OldColor = pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
  294. pOldPen = pDC->SelectObject((CPen*)&cpWhite);
  295. }
  296. else
  297. {
  298. crBkgnd = GetSysColor(COLOR_BTNFACE);
  299. OldColor = pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));
  300. }
  301. }
  302. else
  303. {
  304. //Shade alternating Rows
  305. if((nItem % 2) == 0)
  306. crBkgnd = COLOR_SHADOW;
  307. else
  308. crBkgnd = GetSysColor(COLOR_WINDOW);
  309. OldColor = pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));
  310. }
  311. pDC->FillSolidRect(rcItem, crBkgnd);
  312. nOldBKMode = pDC->SetBkMode(TRANSPARENT);
  313. CRect rcText = rcItem;
  314. rcText.left += ROW_LEFT_BORDER;
  315. rcText.top++;
  316. // Draw the text.
  317. CString csText = GetItemText(nItem, 0);
  318. // set firstTenNum to the first ten number (1-10) corresponding to
  319. // the current nItem.
  320. // -1 means that nItem is not in the FirstTen block.
  321. int firstTenNum = GetFirstTenNum(nItem);
  322. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  323. {
  324. rcText.left += 12;
  325. }
  326. pDC->DrawText(csText, rcText, DT_VCENTER | DT_EXPANDTABS);
  327. // Draw a focus rect around the item if necessary.
  328. if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
  329. pDC->DrawFocusRect(rcItem);
  330. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  331. {
  332. CString cs;
  333. if( firstTenNum == 10 )
  334. cs = "0";
  335. else
  336. cs.Format("%d", firstTenNum);
  337. CRect crClient;
  338. GetWindowRect(crClient);
  339. ScreenToClient(crClient);
  340. CRect crHotKey = rcItem;
  341. crHotKey.right = crHotKey.left + 11;
  342. crHotKey.left += 2;
  343. crHotKey.top += 2;
  344. HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
  345. pDC->DrawText(cs, crHotKey, DT_BOTTOM);
  346. pDC->MoveTo(CPoint(rcItem.left + 11, rcItem.top));
  347. pDC->LineTo(CPoint(rcItem.left + 11, rcItem.bottom));
  348. pDC->SelectObject(hOldFont);
  349. }
  350. if(pOldPen)
  351. pDC->SelectObject(pOldPen);
  352. if(OldColor > -1)
  353. pDC->SetTextColor(OldColor);
  354. if(nOldBKMode > -1)
  355. pDC->SetBkMode(nOldBKMode);
  356. *pResult = CDRF_SKIPDEFAULT; // We've painted everything.
  357. }
  358. }
  359. void CQListCtrl::RefreshVisibleRows()
  360. {
  361. int nTopIndex = GetTopIndex();
  362. int nLastIndex = nTopIndex + GetCountPerPage();
  363. RedrawItems(nTopIndex, nLastIndex);
  364. ::UpdateWindow(m_hWnd);
  365. }
  366. void CQListCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  367. {
  368. if(GetKeyState(VK_RETURN) & 0x800)
  369. GetParent()->SendMessage(NM_PROPERTIES, 0, 0);
  370. else
  371. CListCtrl::OnSysKeyDown(nChar, nRepCnt, nFlags);
  372. }
  373. BOOL CQListCtrl::OnEraseBkgnd(CDC* pDC)
  374. {
  375. // return TRUE;
  376. return CListCtrl::OnEraseBkgnd(pDC);
  377. }
  378. BOOL CQListCtrl::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  379. {
  380. // need to handle both ANSI and UNICODE versions of the message
  381. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  382. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  383. CString strTipText;
  384. UINT nID = pNMHDR->idFrom;
  385. if(nID == 0) // Notification in NT from automatically
  386. return FALSE; // created tooltip
  387. ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 500);
  388. // Use Item's name as the tool tip. Change this for something different.
  389. // Like use its file size, etc.
  390. strTipText = GetToolTipText(nID-1);
  391. //Replace the tabs with spaces, the tooltip didn't like the \t s
  392. strTipText.Replace("\t", " ");
  393. #ifndef _UNICODE
  394. if (pNMHDR->code == TTN_NEEDTEXTA)
  395. {
  396. if(m_pchTip != NULL)
  397. delete m_pchTip;
  398. m_pchTip = new TCHAR[strTipText.GetLength()+1];
  399. lstrcpyn(m_pchTip, strTipText, strTipText.GetLength());
  400. m_pchTip[strTipText.GetLength()] = 0;
  401. pTTTW->lpszText = (WCHAR*)m_pchTip;
  402. }
  403. else
  404. {
  405. if(m_pwchTip != NULL)
  406. delete m_pwchTip;
  407. m_pwchTip = new WCHAR[strTipText.GetLength()+1];
  408. _mbstowcsz(m_pwchTip, strTipText, strTipText.GetLength());
  409. m_pwchTip[strTipText.GetLength()] = 0; // end of text
  410. pTTTW->lpszText = (WCHAR*)m_pwchTip;
  411. }
  412. #else
  413. if(pNMHDR->code == TTN_NEEDTEXTA)
  414. {
  415. if(m_pchTip != NULL)
  416. delete m_pchTip;
  417. m_pchTip = new TCHAR[strTipText.GetLength()+1];
  418. _wcstombsz(m_pchTip, strTipText, strTipText.GetLength());
  419. m_pchTip[strTipText.GetLength()] = 0; // end of text
  420. pTTTA->lpszText = (LPTSTR)m_pchTip;
  421. }
  422. else
  423. {
  424. if(m_pwchTip != NULL)
  425. delete m_pwchTip;
  426. m_pwchTip = new WCHAR[strTipText.GetLength()+1];
  427. lstrcpyn(m_pwchTip, strTipText, strTipText.GetLength());
  428. m_pwchTip[strTipText.GetLength()] = 0;
  429. pTTTA->lpszText = (LPTSTR) m_pwchTip;
  430. }
  431. #endif
  432. *pResult = 0;
  433. return TRUE; // message was handled
  434. }
  435. int CQListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
  436. {
  437. CRect rect;
  438. GetClientRect(&rect);
  439. if(rect.PtInRect(point))
  440. {
  441. if(GetItemCount())
  442. {
  443. int nTopIndex = GetTopIndex();
  444. int nBottomIndex = nTopIndex + GetCountPerPage();
  445. if(nBottomIndex > GetItemCount()) nBottomIndex = GetItemCount();
  446. for(int nIndex = nTopIndex; nIndex <= nBottomIndex; nIndex++)
  447. {
  448. GetItemRect(nIndex, rect, LVIR_BOUNDS);
  449. if(rect.PtInRect(point))
  450. {
  451. pTI->hwnd = m_hWnd;
  452. pTI->uId = (UINT)(nIndex+1);
  453. pTI->lpszText = LPSTR_TEXTCALLBACK;
  454. pTI->rect = rect;
  455. return pTI->uId;
  456. }
  457. }
  458. }
  459. }
  460. return -1;
  461. }
  462. int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  463. {
  464. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  465. return -1;
  466. EnableToolTips();
  467. m_Popup.Init();
  468. // m_Popup.Init( GetToolTips()->m_hWnd );
  469. // m_Popup.m_TI.hwnd = m_hWnd;
  470. return 0;
  471. }
  472. BOOL CQListCtrl::PreTranslateMessage(MSG* pMsg)
  473. {
  474. /* !!!!!
  475. //if(m_Accelerator)
  476. //{
  477. // m_CheckingAccelerator = true;
  478. // if(TranslateAccelerator(m_hWnd, m_Accelerator, pMsg) != 0)
  479. // {
  480. // m_CheckingAccelerator = false;
  481. // return TRUE;
  482. // }
  483. // m_CheckingAccelerator = false;
  484. //}
  485. */
  486. CAccel* pAccel = m_Accels.OnMsg( pMsg );
  487. if( pAccel && GetParent()->SendMessage(NM_SELECT_DB_ID, pAccel->Cmd, 0) )
  488. return TRUE;
  489. switch(pMsg->message)
  490. {
  491. case WM_KEYDOWN:
  492. m_Popup.Hide(); // hide the manual tooltip on any keypress
  493. WPARAM vk = pMsg->wParam;
  494. // if a number key was pressed
  495. if( '0' <= vk && vk <= '9' )
  496. {
  497. // if <Ctrl> is required but is absent, then break
  498. if( g_Opt.m_bUseCtrlNumAccel && !(GetKeyState(VK_CONTROL) & 0x8000) )
  499. break;
  500. int index = vk - '0';
  501. // '0' is actually 10 in the ditto window
  502. if( index == 0 )
  503. index = 10;
  504. // translate num 1-10 into the actual index (based upon m_bStartTop)
  505. index = GetFirstTenIndex( index );
  506. GetParent()->SendMessage(NM_SELECT_INDEX, index, 0);
  507. return TRUE;
  508. }
  509. switch( vk )
  510. {
  511. case 'A': // Ctrl-A = Select All
  512. if(GetKeyState(VK_CONTROL) & 0x8000)
  513. {
  514. int nCount = GetItemCount();
  515. for(int i = 0; i < nCount; i++)
  516. {
  517. SetSelection(i);
  518. }
  519. return TRUE;
  520. }
  521. break;
  522. case VK_F3:
  523. int nItem = GetCaret();
  524. GetItemPosition( nItem, &m_Popup.m_Pos );
  525. ClientToScreen( &m_Popup.m_Pos );
  526. // GetClientRect( &m_Popup.m_TI.rect ); // put tooltip to the left of the item
  527. m_Popup.Show( GetToolTipText(nItem) );
  528. } // end switch(vk)
  529. break; // end case WM_KEYDOWN
  530. } // end switch(pMsg->message)
  531. return CListCtrl::PreTranslateMessage(pMsg);
  532. }
  533. CString CQListCtrl::GetToolTipText(int nItem)
  534. {
  535. CString cs;
  536. if((GetStyle() & LVS_OWNERDATA))
  537. {
  538. CWnd* pParent=GetParent();
  539. if(pParent && (pParent->GetSafeHwnd() != NULL))
  540. {
  541. CQListToolTipText info;
  542. memset(&info, 0, sizeof(info));
  543. info.hdr.code = NM_GETTOOLTIPTEXT;
  544. info.hdr.hwndFrom = GetSafeHwnd();
  545. info.hdr.idFrom = GetDlgCtrlID();
  546. info.lItem = nItem;
  547. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  548. cs = info.cText;
  549. }
  550. }
  551. return cs;
  552. }
  553. DWORD CQListCtrl::GetItemData(int nItem)
  554. {
  555. if((GetStyle() & LVS_OWNERDATA))
  556. {
  557. CWnd* pParent=GetParent();
  558. if(pParent && (pParent->GetSafeHwnd() != NULL))
  559. {
  560. LV_DISPINFO info;
  561. memset(&info, 0, sizeof(info));
  562. info.hdr.code = LVN_GETDISPINFO;
  563. info.hdr.hwndFrom = GetSafeHwnd();
  564. info.hdr.idFrom = GetDlgCtrlID();
  565. info.item.iItem = nItem;
  566. info.item.lParam = -1;
  567. info.item.mask = LVIF_PARAM;
  568. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  569. return info.item.lParam;
  570. }
  571. }
  572. return CListCtrl::GetItemData(nItem);
  573. }
  574. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  575. {
  576. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  577. }
  578. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  579. {
  580. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  581. }
  582. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate)
  583. {
  584. // !!!!!!
  585. //if(m_Accelerator)
  586. //{
  587. // DestroyAcceleratorTable(m_Accelerator);
  588. // m_Accelerator = NULL;
  589. //}
  590. //
  591. //if(bCreate)
  592. // m_Accelerator = CMainTable::LoadAcceleratorKeys();
  593. m_Accels.Clear();
  594. if( bCreate )
  595. CMainTable::LoadAcceleratorKeys( m_Accels );
  596. }
  597. /* !!!!!
  598. //BOOL CQListCtrl::OnCommand(WPARAM wParam, LPARAM lParam)
  599. //{
  600. // //return 1 if from accelerator
  601. // if((HIWORD(wParam) == 1) && (m_CheckingAccelerator))
  602. // {
  603. // USHORT usPasteID = LOWORD(wParam);
  604. //
  605. // GetParent()->SendMessage(NM_SELECT_DB_ID, usPasteID, 0);
  606. //
  607. // return TRUE;
  608. // }
  609. //
  610. // return CListCtrl::OnCommand(wParam, lParam);
  611. //}
  612. */
  613. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  614. {
  615. CListCtrl::OnKillFocus(pNewWnd);
  616. m_Popup.Hide();
  617. }