QListCtrl.cpp 30 KB

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