QListCtrl.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. // QListCtrl.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "QListCtrl.h"
  6. #include "ProcessPaste.h"
  7. #include "BitmapHelper.h"
  8. #include "MainTableFunctions.h"
  9. #include "DittoCopyBuffer.h"
  10. #include <atlbase.h>
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. #define ROW_BOTTOM_BORDER 2
  17. #define ROW_LEFT_BORDER 3
  18. #define COLOR_SHADOW RGB(245, 245, 245)
  19. #define DUMMY_COL_WIDTH 1
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CQListCtrl
  22. CQListCtrl::CQListCtrl()
  23. {
  24. m_pchTip = NULL;
  25. m_pwchTip = NULL;
  26. LOGFONT lf;
  27. lf.lfHeight = -9;
  28. lf.lfWidth = 0;
  29. lf.lfEscapement = 0;
  30. lf.lfOrientation = 0;
  31. lf.lfWeight = FW_LIGHT;
  32. lf.lfItalic = FALSE;
  33. lf.lfUnderline = FALSE;
  34. lf.lfStrikeOut = FALSE;
  35. lf.lfCharSet = ANSI_CHARSET;
  36. lf.lfOutPrecision = OUT_STRING_PRECIS;
  37. lf.lfClipPrecision = CLIP_STROKE_PRECIS;
  38. lf.lfQuality = DEFAULT_QUALITY;
  39. lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
  40. lstrcpy(lf.lfFaceName, _T("Small Font"));
  41. m_SmallFont = ::CreateFontIndirect(&lf);
  42. m_bShowTextForFirstTenHotKeys = true;
  43. m_bStartTop = true;
  44. m_pToolTip = NULL;
  45. m_pFormatter = NULL;
  46. m_allSelected = false;
  47. }
  48. CQListCtrl::~CQListCtrl()
  49. {
  50. if(m_pchTip != NULL)
  51. delete m_pchTip;
  52. if(m_pwchTip != NULL)
  53. delete m_pwchTip;
  54. if( m_SmallFont )
  55. ::DeleteObject( m_SmallFont );
  56. m_Font.DeleteObject();
  57. if(m_pFormatter)
  58. {
  59. delete m_pFormatter;
  60. m_pFormatter = NULL;
  61. }
  62. }
  63. // returns the position 1-10 if the index is in the FirstTen block else -1
  64. int CQListCtrl::GetFirstTenNum( int index )
  65. {
  66. // set firstTenNum to the first ten number (1-10) corresponding to the given index
  67. int firstTenNum = -1; // -1 means that nItem is not in the FirstTen block.
  68. int count = GetItemCount();
  69. if( m_bStartTop )
  70. {
  71. if( 0 <= index && index <= 9 )
  72. firstTenNum = index + 1;
  73. }
  74. else // we are starting at the bottom and going up
  75. {
  76. int idxStartFirstTen = count-10; // start of the FirstTen block
  77. // if index is within the FirstTen block
  78. if( idxStartFirstTen <= index && index < count )
  79. firstTenNum = count - index;
  80. }
  81. return firstTenNum;
  82. }
  83. // returns the list index corresponding to the given FirstTen position number.
  84. // (ret < 0) means that "num" is not in the FirstTen block
  85. int CQListCtrl::GetFirstTenIndex( int num )
  86. {
  87. if( num <= 0 || num > 10 )
  88. return -1;
  89. if( m_bStartTop )
  90. return num-1;
  91. // else we are starting at the bottom and going up
  92. int count = GetItemCount();
  93. return count - num;
  94. }
  95. BEGIN_MESSAGE_MAP(CQListCtrl, CListCtrl)
  96. //{{AFX_MSG_MAP(CQListCtrl)
  97. ON_NOTIFY_REFLECT(LVN_KEYDOWN, OnKeydown)
  98. ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
  99. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdrawList)
  100. ON_WM_SYSKEYDOWN()
  101. ON_WM_ERASEBKGND()
  102. ON_WM_CREATE()
  103. ON_WM_HSCROLL()
  104. ON_WM_TIMER()
  105. ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnSelectionChange)
  106. ON_WM_VSCROLL()
  107. ON_WM_WINDOWPOSCHANGED()
  108. ON_WM_MOUSEWHEEL()
  109. //}}AFX_MSG_MAP
  110. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
  111. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
  112. ON_WM_KILLFOCUS()
  113. END_MESSAGE_MAP()
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CQListCtrl message handlers
  116. void CQListCtrl::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult)
  117. {
  118. LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
  119. switch (pLVKeyDown->wVKey)
  120. {
  121. case VK_RETURN:
  122. {
  123. ARRAY arr;
  124. GetSelectionIndexes(arr);
  125. SendSelection(arr);
  126. }
  127. break;
  128. case VK_ESCAPE:
  129. GetParent()->SendMessage(NM_END, 0, 0);
  130. break;
  131. case VK_RIGHT:
  132. {
  133. int nItem = GetNextItem(-1, LVNI_SELECTED);
  134. if (nItem != -1)
  135. GetParent()->SendMessage(NM_RIGHT, nItem, 0);
  136. }
  137. break;
  138. case VK_LEFT:
  139. GetParent()->SendMessage(NM_LEFT, 0, 0);
  140. break;
  141. case VK_DELETE:
  142. GetParent()->SendMessage(NM_DELETE, 0, 0);
  143. break;
  144. }
  145. *pResult = 0;
  146. }
  147. void CQListCtrl::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
  148. {
  149. LPNMITEMACTIVATE lpnmItem = (LPNMITEMACTIVATE) pNMHDR;
  150. UINT Flags;
  151. int nItem = -1;
  152. if ((nItem = HitTest(lpnmItem->ptAction, &Flags)) != -1)
  153. {
  154. if (Flags | LVHT_ONITEM)
  155. SendSelection(nItem);
  156. }
  157. *pResult = 0;
  158. }
  159. void CQListCtrl::SendSelection(int nItem)
  160. {
  161. GetParent()->SendMessage(NM_SELECT, 1, (LPARAM) &nItem);
  162. }
  163. void CQListCtrl::SendSelection(ARRAY &arrItems)
  164. {
  165. GetParent()->SendMessage(NM_SELECT, arrItems.GetSize(), (LPARAM) arrItems.GetData());
  166. }
  167. void CQListCtrl::GetSelectionIndexes(ARRAY &arr)
  168. {
  169. arr.RemoveAll();
  170. POSITION pos = GetFirstSelectedItemPosition();
  171. while (pos)
  172. {
  173. arr.Add(GetNextSelectedItem(pos));
  174. }
  175. }
  176. bool CQListCtrl::PutSelectedItemOnDittoCopyBuffer(long lBuffer)
  177. {
  178. bool bRet = false;
  179. ARRAY arr;
  180. GetSelectionItemData(arr);
  181. int nCount = arr.GetSize();
  182. if(nCount > 0 && arr[0])
  183. {
  184. CDittoCopyBuffer::PutClipOnDittoCopyBuffer(arr[0], lBuffer);
  185. bRet = true;
  186. }
  187. return bRet;
  188. }
  189. void CQListCtrl::GetSelectionItemData(ARRAY &arr)
  190. {
  191. DWORD dwData;
  192. int i;
  193. arr.RemoveAll();
  194. POSITION pos = GetFirstSelectedItemPosition();
  195. while (pos)
  196. {
  197. i = GetNextSelectedItem(pos);
  198. dwData = GetItemData(i);
  199. arr.Add( dwData );
  200. }
  201. }
  202. void CQListCtrl::RemoveAllSelection()
  203. {
  204. POSITION pos = GetFirstSelectedItemPosition();
  205. while (pos)
  206. {
  207. SetSelection(GetNextSelectedItem(pos), FALSE);
  208. }
  209. }
  210. BOOL CQListCtrl::SetSelection(int nRow, BOOL bSelect)
  211. {
  212. if(bSelect)
  213. return SetItemState(nRow, LVIS_SELECTED, LVIS_SELECTED);
  214. else
  215. return SetItemState(nRow, ~LVIS_SELECTED, LVIS_SELECTED);
  216. }
  217. BOOL CQListCtrl::SetText(int nRow, int nCol, CString cs)
  218. {
  219. return SetItemText(nRow, nCol, cs);
  220. }
  221. BOOL CQListCtrl::SetCaret(int nRow, BOOL bFocus)
  222. {
  223. if(bFocus)
  224. return SetItemState(nRow, LVIS_FOCUSED, LVIS_FOCUSED);
  225. else
  226. return SetItemState(nRow, ~LVIS_FOCUSED, LVIS_FOCUSED);
  227. }
  228. long CQListCtrl::GetCaret()
  229. {
  230. return GetNextItem(-1, LVNI_FOCUSED);
  231. }
  232. // moves the caret to the given index, selects it, and ensures it is visible.
  233. BOOL CQListCtrl::SetListPos( int index )
  234. {
  235. if( index < 0 || index >= GetItemCount() )
  236. return FALSE;
  237. RemoveAllSelection();
  238. SetCaret(index);
  239. SetSelection(index);
  240. EnsureVisible(index,FALSE);
  241. //similutate a click on the selected item
  242. //I was having a problem with the previous selection still be there
  243. //when you shift selected it would still have the previous selection as the anchor
  244. CWnd *pFocus = GetFocus();
  245. if(pFocus == NULL || pFocus == this)
  246. {
  247. CRect rect;
  248. if(GetItemRect(index, rect, LVIR_BOUNDS))
  249. {
  250. CPoint pt(rect.TopLeft());
  251. pt.x += 2;
  252. pt.y += 2;
  253. PostMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(pt.x, pt.y));
  254. PostMessage(WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(pt.x, pt.y));
  255. }
  256. }
  257. return TRUE;
  258. }
  259. BOOL CQListCtrl::SetFormattedText(int nRow, int nCol, LPCTSTR lpszFormat,...)
  260. {
  261. CString csText;
  262. va_list vlist;
  263. ASSERT(AfxIsValidString(lpszFormat));
  264. va_start(vlist,lpszFormat);
  265. csText.FormatV(lpszFormat,vlist);
  266. va_end(vlist);
  267. return SetText(nRow,nCol,csText);
  268. }
  269. void CQListCtrl::SetNumberOfLinesPerRow(int nLines)
  270. {
  271. CDC *pDC = GetDC();
  272. CRect crRect(0, 0, 0, 0);
  273. CFont *pOldFont = pDC->SelectObject(GetFont());
  274. //Get the height to draw one character
  275. pDC->DrawText("W", crRect, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
  276. pDC->SelectObject(pOldFont);
  277. //Get the total height of each row
  278. int nHeight = (crRect.Height() * nLines) + ROW_BOTTOM_BORDER;
  279. //Create a image list of that height and set it to the list box
  280. CImageList imglist;
  281. imglist.Create(DUMMY_COL_WIDTH, nHeight, ILC_COLOR16 | ILC_MASK, 1, 1);
  282. SetImageList(&imglist, LVSIL_SMALL );
  283. ReleaseDC(pDC);
  284. }
  285. void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
  286. {
  287. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  288. *pResult = 0;
  289. // Request item-specific notifications if this is the
  290. // beginning of the paint cycle.
  291. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
  292. {
  293. *pResult = CDRF_NOTIFYITEMDRAW;
  294. }
  295. else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
  296. {
  297. LVITEM rItem;
  298. int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
  299. CDC* pDC = CDC::FromHandle ( pLVCD->nmcd.hdc );
  300. COLORREF crBkgnd;
  301. BOOL bListHasFocus;
  302. CRect rcItem;
  303. bListHasFocus = ( GetSafeHwnd() == ::GetFocus() );
  304. // Get the image index and selected/focused state of the
  305. // item being drawn.
  306. ZeroMemory ( &rItem, sizeof(LVITEM) );
  307. rItem.mask = LVIF_STATE;
  308. rItem.iItem = nItem;
  309. rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  310. GetItem(&rItem);
  311. // Get the rect that bounds the text label.
  312. GetItemRect(nItem, rcItem, LVIR_LABEL);
  313. rcItem.left -= DUMMY_COL_WIDTH;
  314. COLORREF OldColor = -1;
  315. int nOldBKMode = -1;
  316. // Draw the background of the list item. Colors are selected
  317. // according to the item's state.
  318. if(rItem.state & LVIS_SELECTED)
  319. {
  320. if(bListHasFocus)
  321. {
  322. crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG();
  323. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText());
  324. }
  325. else
  326. {
  327. crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG();
  328. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText());
  329. }
  330. }
  331. else
  332. {
  333. //Shade alternating Rows
  334. if((nItem % 2) == 0)
  335. {
  336. crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG();
  337. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText());
  338. }
  339. else
  340. {
  341. crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG();
  342. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText());
  343. }
  344. }
  345. pDC->FillSolidRect(rcItem, crBkgnd);
  346. nOldBKMode = pDC->SetBkMode(TRANSPARENT);
  347. CRect rcText = rcItem;
  348. rcText.left += ROW_LEFT_BORDER;
  349. rcText.top++;
  350. // Draw the text.
  351. //CString csText = GetItemText(nItem, 0);
  352. CString csText;
  353. LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize);
  354. GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize);
  355. csText.ReleaseBuffer();
  356. // extract symbols
  357. CString strSymbols;
  358. int nSymEnd = csText.Find('|');
  359. if( nSymEnd >= 0 )
  360. {
  361. strSymbols = csText.Left(nSymEnd);
  362. csText = csText.Mid(nSymEnd+1);
  363. }
  364. // set firstTenNum to the first ten number (1-10) corresponding to
  365. // the current nItem.
  366. // -1 means that nItem is not in the FirstTen block.
  367. int firstTenNum = GetFirstTenNum(nItem);
  368. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  369. {
  370. rcText.left += 12;
  371. }
  372. // if we are inside a group, don't display the "in group" flag
  373. if( theApp.m_GroupID > 0 )
  374. {
  375. int nFlag = strSymbols.Find(_T("!"));
  376. if( nFlag >= 0 )
  377. strSymbols.Delete(nFlag);
  378. }
  379. DrawBitMap(nItem, rcText, pDC, csText);
  380. // draw the symbol box
  381. if( strSymbols.GetLength() > 0 )
  382. {
  383. strSymbols = " " + strSymbols + " "; // leave space for box
  384. // add spaces to leave room for the symbols
  385. CRect rectSym(rcText.left, rcText.top+1, rcText.left, rcText.top+1);
  386. CRect rectSpace(0,0,0,0);
  387. //Get text bounds
  388. pDC->DrawText(" ", &rectSpace, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
  389. pDC->DrawText(strSymbols, &rectSym, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
  390. VERIFY( rectSpace.Width() > 0 );
  391. // int numSpaces = rectSym.Width() / rectSpace.Width();
  392. // numSpaces++;
  393. // csText = CString(' ',numSpaces) + csText;
  394. // draw the symbols
  395. pDC->FillSolidRect( rectSym, GetSysColor(COLOR_ACTIVECAPTION) );
  396. //pDC->FillSolidRect( rectSym, RGB(0,255,255) );
  397. pDC->Draw3dRect(rectSym, GetSysColor(COLOR_3DLIGHT), GetSysColor(COLOR_3DDKSHADOW));
  398. // COLORREF crOld = pDC->SetTextColor(GetSysColor(COLOR_INFOTEXT));
  399. COLORREF crOld = pDC->SetTextColor(RGB(255, 255, 255));
  400. pDC->DrawText(strSymbols, rectSym, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
  401. pDC->SetTextColor(crOld);
  402. rcText.left += rectSym.Width() + 2;
  403. }
  404. if(DrawRtfText(nItem, rcText, pDC) == FALSE)
  405. {
  406. pDC->DrawText(csText, rcText, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
  407. }
  408. // Draw a focus rect around the item if necessary.
  409. if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
  410. pDC->DrawFocusRect(rcItem);
  411. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  412. {
  413. CString cs;
  414. if( firstTenNum == 10 )
  415. cs = "0";
  416. else
  417. cs.Format(_T("%d"), firstTenNum);
  418. CRect crClient;
  419. GetWindowRect(crClient);
  420. ScreenToClient(crClient);
  421. CRect crHotKey = rcItem;
  422. crHotKey.right = crHotKey.left + 11;
  423. crHotKey.left += 2;
  424. crHotKey.top += 2;
  425. HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
  426. pDC->DrawText(cs, crHotKey, DT_BOTTOM);
  427. pDC->MoveTo(CPoint(rcItem.left + 11, rcItem.top));
  428. pDC->LineTo(CPoint(rcItem.left + 11, rcItem.bottom));
  429. pDC->SelectObject(hOldFont);
  430. }
  431. // restore the previous values
  432. if(OldColor > -1)
  433. pDC->SetTextColor(OldColor);
  434. if(nOldBKMode > -1)
  435. pDC->SetBkMode(nOldBKMode);
  436. *pResult = CDRF_SKIPDEFAULT; // We've painted everything.
  437. }
  438. }
  439. BOOL CQListCtrl::DrawRtfText(int nItem, CRect &crRect, CDC *pDC)
  440. {
  441. if(g_Opt.m_bDrawRTF == FALSE)
  442. return FALSE;
  443. BOOL bRet = FALSE;
  444. CClipFormat* pThumbnail = GetItem_CF_RTF_ClipFormat(nItem);
  445. if(pThumbnail == NULL)
  446. return FALSE;
  447. // if there's no data, then we're done.
  448. if(pThumbnail->m_hgData == NULL)
  449. return FALSE;
  450. if(m_pFormatter == NULL)
  451. {
  452. m_pFormatter = new CFormattedTextDraw;
  453. m_pFormatter->Create();
  454. }
  455. if(m_pFormatter)
  456. {
  457. char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
  458. if(pData)
  459. {
  460. CComBSTR bStr(pData);
  461. m_pFormatter->put_RTFText(bStr);
  462. m_pFormatter->Draw(pDC->m_hDC, crRect);
  463. GlobalUnlock(pThumbnail->m_hgData);
  464. bRet = TRUE;
  465. }
  466. }
  467. return bRet;
  468. }
  469. // DrawBitMap loads a DIB from the DB, draws a crRect thumbnail of the image
  470. // to pDC and caches that thumbnail as a DIB in m_ThumbNails[ ItemID ].
  471. // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
  472. BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC, const CString &csDescription)
  473. {
  474. if(g_Opt.m_bDrawThumbnail == FALSE)
  475. return FALSE;
  476. CClipFormatQListCtrl *format = GetItem_CF_DIB_ClipFormat(nItem);
  477. if(format != NULL)
  478. {
  479. HGLOBAL smallImage = format->GetDib(pDC, crRect.Height());
  480. if(smallImage != NULL)
  481. {
  482. //Will return the width of the bitmap in nWidth
  483. int nWidth = 0;
  484. if(CBitmapHelper::DrawDIB(pDC, smallImage, crRect.left, crRect.top, nWidth))
  485. {
  486. // adjust the rect so other information can be drawn next to the thumbnail
  487. crRect.left += nWidth + 3;
  488. }
  489. }
  490. }
  491. else if(csDescription.Find(_T("CF_DIB")) == 0)
  492. {
  493. crRect.left += crRect.Height();
  494. }
  495. return TRUE;
  496. }
  497. void CQListCtrl::RefreshVisibleRows()
  498. {
  499. int nTopIndex = GetTopIndex();
  500. int nLastIndex = nTopIndex + GetCountPerPage();
  501. RedrawItems(nTopIndex, nLastIndex);
  502. ::UpdateWindow(m_hWnd);
  503. }
  504. void CQListCtrl::RefreshRow(int row)
  505. {
  506. RedrawItems(row, row);
  507. }
  508. void CQListCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  509. {
  510. if(GetKeyState(VK_RETURN) & 0x800)
  511. GetParent()->SendMessage(NM_PROPERTIES, 0, 0);
  512. else
  513. CListCtrl::OnSysKeyDown(nChar, nRepCnt, nFlags);
  514. }
  515. BOOL CQListCtrl::OnEraseBkgnd(CDC* pDC)
  516. {
  517. // Simply returning TRUE seems OK since we do custom item
  518. // painting. However, there is a pixel buffer around the
  519. // border of this control (not within the item rects)
  520. // which becomes visually corrupt if it is not erased.
  521. // In most cases, I do not notice the erasure, so I have kept
  522. // the call to CListCtrl::OnEraseBkgnd(pDC);
  523. // However, for some reason, bulk erasure is very noticeable when
  524. // shift-scrolling the page to select a block of items, so
  525. // I made a special case for that:
  526. if( GetSelectedCount() >= 2 )
  527. return TRUE;
  528. return CListCtrl::OnEraseBkgnd(pDC);
  529. }
  530. BOOL CQListCtrl::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  531. {
  532. // need to handle both ANSI and UNICODE versions of the message
  533. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  534. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  535. CString strTipText;
  536. UINT nID = pNMHDR->idFrom;
  537. if(nID == 0) // Notification in NT from automatically
  538. return FALSE; // created tooltip
  539. ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 500);
  540. // Use Item's name as the tool tip. Change this for something different.
  541. // Like use its file size, etc.
  542. GetToolTipText(nID-1, strTipText);
  543. //Replace the tabs with spaces, the tooltip didn't like the \t s
  544. strTipText.Replace(_T("\t"), _T(" "));
  545. int nLength = strTipText.GetLength()+2;
  546. #ifndef _UNICODE
  547. if (pNMHDR->code == TTN_NEEDTEXTA)
  548. {
  549. if(m_pchTip != NULL)
  550. delete m_pchTip;
  551. m_pchTip = new TCHAR[nLength];
  552. lstrcpyn(m_pchTip, strTipText, nLength-1);
  553. m_pchTip[nLength-1] = 0;
  554. pTTTW->lpszText = (WCHAR*)m_pchTip;
  555. }
  556. else
  557. {
  558. if(m_pwchTip != NULL)
  559. delete m_pwchTip;
  560. m_pwchTip = new WCHAR[nLength];
  561. _mbstowcsz(m_pwchTip, strTipText, nLength-1);
  562. m_pwchTip[nLength-1] = 0; // end of text
  563. pTTTW->lpszText = (WCHAR*)m_pwchTip;
  564. }
  565. #else
  566. if(pNMHDR->code == TTN_NEEDTEXTA)
  567. {
  568. if(m_pchTip != NULL)
  569. delete m_pchTip;
  570. m_pchTip = new TCHAR[nLength];
  571. STRNCPY(m_pchTip, strTipText, nLength-1);
  572. m_pchTip[nLength-1] = 0; // end of text
  573. pTTTW->lpszText = (LPTSTR)m_pchTip;
  574. }
  575. else
  576. {
  577. if(m_pwchTip != NULL)
  578. delete m_pwchTip;
  579. m_pwchTip = new WCHAR[nLength];
  580. lstrcpyn(m_pwchTip, strTipText, nLength-1);
  581. m_pwchTip[nLength-1] = 0;
  582. pTTTW->lpszText = (LPTSTR) m_pwchTip;
  583. }
  584. #endif
  585. *pResult = 0;
  586. return TRUE; // message was handled
  587. }
  588. int CQListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
  589. {
  590. CRect rect;
  591. GetClientRect(&rect);
  592. if(rect.PtInRect(point))
  593. {
  594. if(GetItemCount())
  595. {
  596. int nTopIndex = GetTopIndex();
  597. int nBottomIndex = nTopIndex + GetCountPerPage();
  598. if(nBottomIndex > GetItemCount()) nBottomIndex = GetItemCount();
  599. for(int nIndex = nTopIndex; nIndex <= nBottomIndex; nIndex++)
  600. {
  601. GetItemRect(nIndex, rect, LVIR_BOUNDS);
  602. if(rect.PtInRect(point))
  603. {
  604. pTI->hwnd = m_hWnd;
  605. pTI->uId = (UINT)(nIndex+1);
  606. pTI->lpszText = LPSTR_TEXTCALLBACK;
  607. pTI->rect = rect;
  608. return pTI->uId;
  609. }
  610. }
  611. }
  612. }
  613. return -1;
  614. }
  615. int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  616. {
  617. if (CListCtrl::OnCreate(lpCreateStruct) == -1)
  618. return -1;
  619. EnableToolTips();
  620. m_pToolTip = new CToolTipEx;
  621. m_pToolTip->Create(this);
  622. m_pToolTip->SetNotifyWnd(GetParent());
  623. return 0;
  624. }
  625. BOOL CQListCtrl::PreTranslateMessage(MSG* pMsg)
  626. {
  627. DWORD dID;
  628. if(m_Accels.OnMsg(pMsg, dID))
  629. {
  630. switch(dID)
  631. {
  632. case COPY_BUFFER_HOT_KEY_1_ID:
  633. PutSelectedItemOnDittoCopyBuffer(0);
  634. break;
  635. case COPY_BUFFER_HOT_KEY_2_ID:
  636. PutSelectedItemOnDittoCopyBuffer(1);
  637. break;
  638. case COPY_BUFFER_HOT_KEY_3_ID:
  639. PutSelectedItemOnDittoCopyBuffer(2);
  640. break;
  641. default:
  642. GetParent()->SendMessage(NM_SELECT_DB_ID, dID, 0);
  643. }
  644. return TRUE;
  645. }
  646. if(m_pToolTip)
  647. {
  648. if(m_pToolTip->OnMsg(pMsg))
  649. return TRUE;
  650. }
  651. switch(pMsg->message)
  652. {
  653. case WM_KEYDOWN:
  654. if(HandleKeyDown(pMsg->wParam, pMsg->lParam))
  655. return TRUE;
  656. break; // end case WM_KEYDOWN
  657. case WM_VSCROLL:
  658. ASSERT(FALSE);
  659. break;
  660. } // end switch(pMsg->message)
  661. return CListCtrl::PreTranslateMessage(pMsg);
  662. }
  663. BOOL CQListCtrl::HandleKeyDown(WPARAM wParam, LPARAM lParam)
  664. {
  665. if(m_pToolTip)
  666. {
  667. MSG Msg;
  668. Msg.lParam = lParam;
  669. Msg.wParam = wParam;
  670. Msg.message = WM_KEYDOWN;
  671. if(m_pToolTip->OnMsg(&Msg))
  672. return TRUE;
  673. }
  674. WPARAM vk = wParam;
  675. // if a number key was pressed
  676. if('0' <= vk && vk <= '9')
  677. {
  678. // if <Ctrl> is required but is absent, then break
  679. if(g_Opt.m_bUseCtrlNumAccel && !(GetKeyState(VK_CONTROL) & 0x8000))
  680. return FALSE;
  681. int index = vk - '0';
  682. // '0' is actually 10 in the ditto window
  683. if(index == 0)
  684. index = 10;
  685. // translate num 1-10 into the actual index (based upon m_bStartTop)
  686. index = GetFirstTenIndex(index);
  687. GetParent()->SendMessage(NM_SELECT_INDEX, index, 0);
  688. return TRUE;
  689. }
  690. if(VK_NUMPAD0 <= vk && vk <= VK_NUMPAD9)
  691. {
  692. // if <Ctrl> is required but is absent, then break
  693. if( g_Opt.m_bUseCtrlNumAccel && !(GetKeyState(VK_CONTROL) & 0x8000) )
  694. return FALSE;
  695. int index = vk - VK_NUMPAD0;
  696. // '0' is actually 10 in the ditto window
  697. if(index == 0)
  698. index = 10;
  699. // translate num 1-10 into the actual index (based upon m_bStartTop)
  700. index = GetFirstTenIndex(index);
  701. GetParent()->SendMessage(NM_SELECT_INDEX, index, 0);
  702. return TRUE;
  703. }
  704. switch( vk )
  705. {
  706. case 'X': // Ctrl-X = Cut (prepare for moving the items into a Group)
  707. if(GetKeyState(VK_CONTROL) & 0x8000)
  708. {
  709. LoadCopyOrCutToClipboard();
  710. theApp.IC_Cut(); // uses selection
  711. return TRUE;
  712. }
  713. break;
  714. case 'C': // Ctrl-C = Copy (prepare for copying the items into a Group)
  715. if(GetKeyState(VK_CONTROL) & 0x8000)
  716. {
  717. LoadCopyOrCutToClipboard();
  718. theApp.IC_Copy(); // uses selection
  719. return TRUE;
  720. }
  721. break;
  722. case 'V': // Ctrl-V = Paste (actually performs the copy or move of items into the current Group)
  723. if(GetKeyState(VK_CONTROL) & 0x8000)
  724. {
  725. theApp.IC_Paste();
  726. return TRUE;
  727. }
  728. break;
  729. case 'A': // Ctrl-A = Select All
  730. if(GetKeyState(VK_CONTROL) & 0x8000)
  731. {
  732. int nCount = GetItemCount();
  733. for(int i = 0; i < nCount; i++)
  734. {
  735. SetSelection(i);
  736. }
  737. return TRUE;
  738. }
  739. break;
  740. case VK_F3:
  741. {
  742. ShowFullDescription();
  743. return TRUE;
  744. }
  745. case VK_BACK:
  746. theApp.EnterGroupID( theApp.m_GroupParentID );
  747. return TRUE;
  748. case VK_SPACE:
  749. if(GetKeyState(VK_CONTROL) & 0x8000)
  750. {
  751. theApp.ShowPersistent( !g_Opt.m_bShowPersistent );
  752. return TRUE;
  753. }
  754. break;
  755. } // end switch(vk)
  756. return FALSE;
  757. }
  758. void CQListCtrl::LoadCopyOrCutToClipboard()
  759. {
  760. ARRAY arr;
  761. GetSelectionItemData(arr);
  762. int nCount = arr.GetSize();
  763. if(nCount <= 0)
  764. return;
  765. CProcessPaste paste;
  766. //Don't send the paste just load it into memory
  767. paste.m_bSendPaste = false;
  768. if(nCount > 1)
  769. paste.GetClipIDs().Copy(arr);
  770. else
  771. paste.GetClipIDs().Add(arr[0]);
  772. //Don't move these to the top
  773. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  774. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  775. paste.DoPaste();
  776. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  777. }
  778. void CQListCtrl::ShowFullDescription(bool bFromAuto)
  779. {
  780. int nItem = GetCaret();
  781. CRect rc, crWindow;
  782. GetWindowRect(&crWindow);
  783. GetItemRect(nItem, rc, LVIR_BOUNDS);
  784. ClientToScreen(rc);
  785. CPoint pt;
  786. if(bFromAuto == false)
  787. {
  788. pt = CPoint(rc.left, rc.bottom);
  789. }
  790. else
  791. pt = CPoint((crWindow.left + (crWindow.right - crWindow.left)/2), rc.bottom);
  792. CString csDescription;
  793. GetToolTipText(nItem, csDescription);
  794. m_pToolTip->DestroyWindow();
  795. m_pToolTip = new CToolTipEx;
  796. m_pToolTip->Create(this);
  797. m_pToolTip->SetNotifyWnd(GetParent());
  798. if(m_pToolTip)
  799. {
  800. m_pToolTip->SetToolTipText(_T(""));
  801. m_pToolTip->SetRTFText(" ");
  802. bool bSetPlainText = false;
  803. CClipFormat Clip;
  804. Clip.m_cfType = CF_UNICODETEXT;
  805. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  806. {
  807. LPVOID pvData = GlobalLock(Clip.m_hgData);
  808. if(pvData)
  809. {
  810. CString csText = (WCHAR*)pvData;
  811. m_pToolTip->SetToolTipText(csText);
  812. bSetPlainText = true;
  813. }
  814. GlobalUnlock(Clip.m_hgData);
  815. Clip.Free();
  816. Clip.Clear();
  817. }
  818. if(bSetPlainText == false)
  819. {
  820. Clip.m_cfType = CF_TEXT;
  821. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  822. {
  823. LPVOID pvData = GlobalLock(Clip.m_hgData);
  824. if(pvData)
  825. {
  826. CString csText = (char*)pvData;
  827. m_pToolTip->SetToolTipText(csText);
  828. bSetPlainText = true;
  829. }
  830. GlobalUnlock(Clip.m_hgData);
  831. Clip.Free();
  832. Clip.Clear();
  833. }
  834. }
  835. if(bSetPlainText == false)
  836. {
  837. m_pToolTip->SetToolTipText(csDescription);
  838. }
  839. Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
  840. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  841. {
  842. LPVOID pvData = GlobalLock(Clip.m_hgData);
  843. if(pvData)
  844. {
  845. m_pToolTip->SetRTFText((char*)pvData);
  846. }
  847. GlobalUnlock(Clip.m_hgData);
  848. Clip.Free();
  849. Clip.Clear();
  850. }
  851. Clip.m_cfType = CF_DIB;
  852. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  853. {
  854. CBitmap *pBitMap = new CBitmap;
  855. if(pBitMap)
  856. {
  857. CRect rcItem;
  858. GetWindowRect(rcItem);
  859. CDC *pDC = GetDC();;
  860. CBitmapHelper::GetCBitmap(&Clip, pDC, pBitMap, (rcItem.Width() * 2));
  861. ReleaseDC(pDC);
  862. //Tooltip wnd will release
  863. m_pToolTip->SetBitmap(pBitMap);
  864. }
  865. Clip.Free();
  866. Clip.Clear();
  867. }
  868. m_pToolTip->Show(pt);
  869. }
  870. }
  871. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  872. {
  873. CWnd* pParent=GetParent();
  874. if(pParent && (pParent->GetSafeHwnd() != NULL))
  875. {
  876. CQListToolTipText info;
  877. memset(&info, 0, sizeof(info));
  878. info.hdr.code = NM_GETTOOLTIPTEXT;
  879. info.hdr.hwndFrom = GetSafeHwnd();
  880. info.hdr.idFrom = GetDlgCtrlID();
  881. info.lItem = nItem;
  882. //plus 100 for extra info - shortcut and such
  883. info.cchTextMax = g_Opt.m_bDescTextSize + 100;
  884. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  885. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  886. csText.ReleaseBuffer();
  887. }
  888. }
  889. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  890. {
  891. return theApp.GetClipData(GetItemData(nItem), Clip);
  892. }
  893. DWORD CQListCtrl::GetItemData(int nItem)
  894. {
  895. if((GetStyle() & LVS_OWNERDATA))
  896. {
  897. CWnd* pParent=GetParent();
  898. if(pParent && (pParent->GetSafeHwnd() != NULL))
  899. {
  900. LV_DISPINFO info;
  901. memset(&info, 0, sizeof(info));
  902. info.hdr.code = LVN_GETDISPINFO;
  903. info.hdr.hwndFrom = GetSafeHwnd();
  904. info.hdr.idFrom = GetDlgCtrlID();
  905. info.item.iItem = nItem;
  906. info.item.lParam = -1;
  907. info.item.mask = LVIF_PARAM;
  908. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  909. return info.item.lParam;
  910. }
  911. }
  912. return CListCtrl::GetItemData(nItem);
  913. }
  914. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  915. {
  916. CClipFormatQListCtrl *format = NULL;
  917. CWnd* pParent=GetParent();
  918. if(pParent && (pParent->GetSafeHwnd() != NULL))
  919. {
  920. LV_DISPINFO info;
  921. memset(&info, 0, sizeof(info));
  922. info.hdr.code = LVN_GETDISPINFO;
  923. info.hdr.hwndFrom = GetSafeHwnd();
  924. info.hdr.idFrom = GetDlgCtrlID();
  925. info.item.iItem = nItem;
  926. info.item.lParam = NULL;
  927. info.item.mask = LVIF_CF_DIB;
  928. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  929. if(info.item.lParam != NULL)
  930. {
  931. format = (CClipFormatQListCtrl *)info.item.lParam;
  932. }
  933. }
  934. return format;
  935. }
  936. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  937. {
  938. CClipFormatQListCtrl *format = NULL;
  939. CWnd* pParent=GetParent();
  940. if(pParent && (pParent->GetSafeHwnd() != NULL))
  941. {
  942. LV_DISPINFO info;
  943. memset(&info, 0, sizeof(info));
  944. info.hdr.code = LVN_GETDISPINFO;
  945. info.hdr.hwndFrom = GetSafeHwnd();
  946. info.hdr.idFrom = GetDlgCtrlID();
  947. info.item.iItem = nItem;
  948. info.item.lParam = NULL;
  949. info.item.mask = LVIF_CF_RICHTEXT;
  950. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  951. if(info.item.lParam != NULL)
  952. {
  953. format = (CClipFormatQListCtrl *)info.item.lParam;
  954. }
  955. }
  956. return format;
  957. }
  958. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  959. {
  960. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  961. }
  962. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  963. {
  964. m_Accels.m_Map.RemoveAll();
  965. if(bCreate)
  966. {
  967. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  968. LoadDittoCopyBufferHotkeys();
  969. }
  970. }
  971. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  972. {
  973. CCopyBufferItem Item;
  974. CAccel a;
  975. g_Opt.GetCopyBufferItem(0, Item);
  976. if(Item.m_lCopyHotKey > 0)
  977. {
  978. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  979. a.Key = Item.m_lCopyHotKey;
  980. m_Accels.AddAccel(a);
  981. }
  982. g_Opt.GetCopyBufferItem(1, Item);
  983. if(Item.m_lCopyHotKey > 0)
  984. {
  985. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  986. a.Key = Item.m_lCopyHotKey;
  987. m_Accels.AddAccel(a);
  988. }
  989. g_Opt.GetCopyBufferItem(2, Item);
  990. if(Item.m_lCopyHotKey > 0)
  991. {
  992. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  993. a.Key = Item.m_lCopyHotKey;
  994. m_Accels.AddAccel(a);
  995. }
  996. }
  997. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  998. {
  999. CListCtrl::OnKillFocus(pNewWnd);
  1000. // if(FocusOnToolTip() == FALSE)
  1001. // m_pToolTip->Hide();
  1002. }
  1003. HWND CQListCtrl::GetToolTipHWnd()
  1004. {
  1005. return m_pToolTip->GetSafeHwnd();
  1006. }
  1007. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = LVSICF_NOINVALIDATEALL */)
  1008. {
  1009. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1010. }
  1011. #define TIMER_SHOW_PROPERTIES 1
  1012. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1013. {
  1014. NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
  1015. if((pnmv->uNewState == 3) ||
  1016. (pnmv->uNewState == 1))
  1017. {
  1018. if(g_Opt.m_bAllwaysShowDescription)
  1019. {
  1020. KillTimer(TIMER_SHOW_PROPERTIES);
  1021. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1022. }
  1023. if(GetSelectedCount() > 0 )
  1024. theApp.SetStatus(NULL, FALSE);
  1025. }
  1026. if(GetSelectedCount() == this->GetItemCount())
  1027. {
  1028. if(m_allSelected == false)
  1029. {
  1030. Log(StrF(_T("List box Select All")));
  1031. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1032. m_allSelected = true;
  1033. }
  1034. }
  1035. else if(m_allSelected == true)
  1036. {
  1037. Log(StrF(_T("List box REMOVED Select All")));
  1038. m_allSelected = false;
  1039. }
  1040. }
  1041. void CQListCtrl::OnTimer(UINT nIDEvent)
  1042. {
  1043. if(nIDEvent == TIMER_SHOW_PROPERTIES)
  1044. {
  1045. if( theApp.m_bShowingQuickPaste )
  1046. ShowFullDescription(true);
  1047. KillTimer(TIMER_SHOW_PROPERTIES);
  1048. }
  1049. CListCtrl::OnTimer(nIDEvent);
  1050. }
  1051. void CQListCtrl::SetLogFont(LOGFONT &font)
  1052. {
  1053. m_Font.DeleteObject();
  1054. m_Font.CreateFontIndirect(&font);
  1055. SetFont(&m_Font);
  1056. }
  1057. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1058. {
  1059. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1060. }
  1061. BOOL CQListCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1062. {
  1063. return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
  1064. }
  1065. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1066. {
  1067. NMLVCACHEHINT* pcachehint = NULL;
  1068. if(message == WM_NOTIFY)
  1069. {
  1070. NMHDR* phdr = (NMHDR*)lParam;
  1071. switch(phdr->code)
  1072. {
  1073. case LVN_ODCACHEHINT:
  1074. pcachehint= (NMLVCACHEHINT*) phdr;
  1075. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1076. return FALSE;
  1077. }
  1078. }
  1079. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1080. }
  1081. BOOL CQListCtrl::OnItemDeleted(long lID)
  1082. {
  1083. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1084. return (bRet2);
  1085. }