QListCtrl.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  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. #define TIMER_SHOW_PROPERTIES 1
  21. #define TIMER_HIDE_SCROL 2
  22. #define TIMER_SHOW_SCROLL 3
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CQListCtrl
  25. CQListCtrl::CQListCtrl()
  26. {
  27. m_pchTip = NULL;
  28. m_pwchTip = NULL;
  29. m_linesPerRow = 1;
  30. LOGFONT lf;
  31. lf.lfHeight = -9;
  32. lf.lfWidth = 0;
  33. lf.lfEscapement = 0;
  34. lf.lfOrientation = 0;
  35. lf.lfWeight = FW_LIGHT;
  36. lf.lfItalic = FALSE;
  37. lf.lfUnderline = FALSE;
  38. lf.lfStrikeOut = FALSE;
  39. lf.lfCharSet = ANSI_CHARSET;
  40. lf.lfOutPrecision = OUT_STRING_PRECIS;
  41. lf.lfClipPrecision = CLIP_STROKE_PRECIS;
  42. lf.lfQuality = DEFAULT_QUALITY;
  43. lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
  44. lstrcpy(lf.lfFaceName, _T("Small Font"));
  45. m_SmallFont = ::CreateFontIndirect(&lf);
  46. m_bShowTextForFirstTenHotKeys = true;
  47. m_bStartTop = true;
  48. m_pToolTip = NULL;
  49. m_pFormatter = NULL;
  50. m_allSelected = false;
  51. m_mouseOverScrollAreaStart = 0;
  52. }
  53. CQListCtrl::~CQListCtrl()
  54. {
  55. if(m_pchTip != NULL)
  56. delete m_pchTip;
  57. if(m_pwchTip != NULL)
  58. delete m_pwchTip;
  59. if( m_SmallFont )
  60. ::DeleteObject( m_SmallFont );
  61. m_Font.DeleteObject();
  62. if(m_pFormatter)
  63. {
  64. delete m_pFormatter;
  65. m_pFormatter = NULL;
  66. }
  67. }
  68. // returns the position 1-10 if the index is in the FirstTen block else -1
  69. int CQListCtrl::GetFirstTenNum( int index )
  70. {
  71. // set firstTenNum to the first ten number (1-10) corresponding to the given index
  72. int firstTenNum = -1; // -1 means that nItem is not in the FirstTen block.
  73. int count = GetItemCount();
  74. if( m_bStartTop )
  75. {
  76. if( 0 <= index && index <= 9 )
  77. firstTenNum = index + 1;
  78. }
  79. else // we are starting at the bottom and going up
  80. {
  81. int idxStartFirstTen = count-10; // start of the FirstTen block
  82. // if index is within the FirstTen block
  83. if( idxStartFirstTen <= index && index < count )
  84. firstTenNum = count - index;
  85. }
  86. return firstTenNum;
  87. }
  88. // returns the list index corresponding to the given FirstTen position number.
  89. // (ret < 0) means that "num" is not in the FirstTen block
  90. int CQListCtrl::GetFirstTenIndex( int num )
  91. {
  92. if( num <= 0 || num > 10 )
  93. return -1;
  94. if( m_bStartTop )
  95. return num-1;
  96. // else we are starting at the bottom and going up
  97. int count = GetItemCount();
  98. return count - num;
  99. }
  100. BEGIN_MESSAGE_MAP(CQListCtrl, CListCtrl)
  101. //{{AFX_MSG_MAP(CQListCtrl)
  102. ON_NOTIFY_REFLECT(LVN_KEYDOWN, OnKeydown)
  103. ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
  104. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdrawList)
  105. ON_WM_MOUSEMOVE()
  106. ON_WM_SYSKEYDOWN()
  107. ON_WM_ERASEBKGND()
  108. ON_WM_CREATE()
  109. ON_WM_HSCROLL()
  110. ON_WM_TIMER()
  111. ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnSelectionChange)
  112. ON_WM_VSCROLL()
  113. ON_WM_WINDOWPOSCHANGED()
  114. ON_WM_MOUSEWHEEL()
  115. //}}AFX_MSG_MAP
  116. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
  117. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
  118. ON_WM_KILLFOCUS()
  119. ON_WM_MEASUREITEM_REFLECT()
  120. END_MESSAGE_MAP()
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CQListCtrl message handlers
  123. void CQListCtrl::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult)
  124. {
  125. LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
  126. switch (pLVKeyDown->wVKey)
  127. {
  128. case VK_RETURN:
  129. {
  130. ARRAY arr;
  131. GetSelectionIndexes(arr);
  132. SendSelection(arr);
  133. }
  134. break;
  135. case VK_ESCAPE:
  136. GetParent()->SendMessage(NM_END, 0, 0);
  137. break;
  138. case VK_RIGHT:
  139. {
  140. int nItem = GetNextItem(-1, LVNI_SELECTED);
  141. if (nItem != -1)
  142. GetParent()->SendMessage(NM_RIGHT, nItem, 0);
  143. }
  144. break;
  145. case VK_LEFT:
  146. GetParent()->SendMessage(NM_LEFT, 0, 0);
  147. break;
  148. case VK_DELETE:
  149. GetParent()->SendMessage(NM_DELETE, 0, 0);
  150. break;
  151. }
  152. *pResult = 0;
  153. }
  154. void CQListCtrl::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
  155. {
  156. LPNMITEMACTIVATE lpnmItem = (LPNMITEMACTIVATE) pNMHDR;
  157. UINT Flags;
  158. int nItem = -1;
  159. if ((nItem = HitTest(lpnmItem->ptAction, &Flags)) != -1)
  160. {
  161. if (Flags | LVHT_ONITEM)
  162. SendSelection(nItem);
  163. }
  164. *pResult = 0;
  165. }
  166. void CQListCtrl::SendSelection(int nItem)
  167. {
  168. GetParent()->SendMessage(NM_SELECT, 1, (LPARAM) &nItem);
  169. }
  170. void CQListCtrl::SendSelection(ARRAY &arrItems)
  171. {
  172. GetParent()->SendMessage(NM_SELECT, arrItems.GetSize(), (LPARAM) arrItems.GetData());
  173. }
  174. void CQListCtrl::GetSelectionIndexes(ARRAY &arr)
  175. {
  176. arr.RemoveAll();
  177. POSITION pos = GetFirstSelectedItemPosition();
  178. while (pos)
  179. {
  180. arr.Add(GetNextSelectedItem(pos));
  181. }
  182. }
  183. bool CQListCtrl::PutSelectedItemOnDittoCopyBuffer(long lBuffer)
  184. {
  185. bool bRet = false;
  186. ARRAY arr;
  187. GetSelectionItemData(arr);
  188. INT_PTR nCount = arr.GetSize();
  189. if(nCount > 0 && arr[0])
  190. {
  191. CDittoCopyBuffer::PutClipOnDittoCopyBuffer(arr[0], lBuffer);
  192. bRet = true;
  193. }
  194. return bRet;
  195. }
  196. void CQListCtrl::GetSelectionItemData(ARRAY &arr)
  197. {
  198. DWORD dwData;
  199. int i;
  200. arr.RemoveAll();
  201. POSITION pos = GetFirstSelectedItemPosition();
  202. while (pos)
  203. {
  204. i = GetNextSelectedItem(pos);
  205. dwData = GetItemData(i);
  206. arr.Add( dwData );
  207. }
  208. }
  209. void CQListCtrl::RemoveAllSelection()
  210. {
  211. POSITION pos = GetFirstSelectedItemPosition();
  212. while (pos)
  213. {
  214. SetSelection(GetNextSelectedItem(pos), FALSE);
  215. }
  216. }
  217. BOOL CQListCtrl::SetSelection(int nRow, BOOL bSelect)
  218. {
  219. if(bSelect)
  220. return SetItemState(nRow, LVIS_SELECTED, LVIS_SELECTED);
  221. else
  222. return SetItemState(nRow, ~LVIS_SELECTED, LVIS_SELECTED);
  223. }
  224. BOOL CQListCtrl::SetText(int nRow, int nCol, CString cs)
  225. {
  226. return SetItemText(nRow, nCol, cs);
  227. }
  228. BOOL CQListCtrl::SetCaret(int nRow, BOOL bFocus)
  229. {
  230. if(bFocus)
  231. return SetItemState(nRow, LVIS_FOCUSED, LVIS_FOCUSED);
  232. else
  233. return SetItemState(nRow, ~LVIS_FOCUSED, LVIS_FOCUSED);
  234. }
  235. long CQListCtrl::GetCaret()
  236. {
  237. return GetNextItem(-1, LVNI_FOCUSED);
  238. }
  239. // moves the caret to the given index, selects it, and ensures it is visible.
  240. BOOL CQListCtrl::SetListPos( int index )
  241. {
  242. if( index < 0 || index >= GetItemCount() )
  243. return FALSE;
  244. RemoveAllSelection();
  245. SetCaret(index);
  246. SetSelection(index);
  247. EnsureVisible(index,FALSE);
  248. return TRUE;
  249. }
  250. BOOL CQListCtrl::SetFormattedText(int nRow, int nCol, LPCTSTR lpszFormat,...)
  251. {
  252. CString csText;
  253. va_list vlist;
  254. ASSERT(AfxIsValidString(lpszFormat));
  255. va_start(vlist,lpszFormat);
  256. csText.FormatV(lpszFormat,vlist);
  257. va_end(vlist);
  258. return SetText(nRow,nCol,csText);
  259. }
  260. void CQListCtrl::SetNumberOfLinesPerRow(int nLines)
  261. {
  262. if(m_linesPerRow != nLines)
  263. {
  264. m_linesPerRow = nLines;
  265. CRect rc;
  266. GetWindowRect( &rc );
  267. WINDOWPOS wp;
  268. wp.hwnd = m_hWnd;
  269. wp.cx = rc.Width();
  270. wp.cy = rc.Height();
  271. wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
  272. SendMessage( WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp );
  273. }
  274. }
  275. void CQListCtrl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  276. {
  277. TEXTMETRIC tm;
  278. HDC hDC = ::GetDC(NULL);
  279. CFont* pFont = GetFont();
  280. HFONT hFontOld = (HFONT)SelectObject(hDC, pFont->GetSafeHandle());
  281. GetTextMetrics(hDC, &tm);
  282. lpMeasureItemStruct->itemHeight = ((tm.tmHeight + tm.tmExternalLeading) * m_linesPerRow) + ROW_BOTTOM_BORDER;
  283. SelectObject(hDC, hFontOld);
  284. ::ReleaseDC(NULL, hDC);
  285. }
  286. void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
  287. {
  288. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  289. *pResult = 0;
  290. // Request item-specific notifications if this is the
  291. // beginning of the paint cycle.
  292. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
  293. {
  294. *pResult = CDRF_NOTIFYITEMDRAW;
  295. }
  296. else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
  297. {
  298. LVITEM rItem;
  299. int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
  300. CDC* pDC = CDC::FromHandle ( pLVCD->nmcd.hdc );
  301. COLORREF crBkgnd;
  302. BOOL bListHasFocus;
  303. CRect rcItem;
  304. bListHasFocus = ( GetSafeHwnd() == ::GetFocus() );
  305. // Get the image index and selected/focused state of the
  306. // item being drawn.
  307. ZeroMemory ( &rItem, sizeof(LVITEM) );
  308. rItem.mask = LVIF_STATE;
  309. rItem.iItem = nItem;
  310. rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  311. GetItem(&rItem);
  312. // Get the rect that bounds the text label.
  313. GetItemRect(nItem, rcItem, LVIR_LABEL);
  314. rcItem.left -= DUMMY_COL_WIDTH;
  315. COLORREF OldColor = -1;
  316. int nOldBKMode = -1;
  317. // Draw the background of the list item. Colors are selected
  318. // according to the item's state.
  319. if(rItem.state & LVIS_SELECTED)
  320. {
  321. if(bListHasFocus)
  322. {
  323. crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG();
  324. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText());
  325. }
  326. else
  327. {
  328. crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG();
  329. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText());
  330. }
  331. }
  332. else
  333. {
  334. //Shade alternating Rows
  335. if((nItem % 2) == 0)
  336. {
  337. crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG();
  338. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText());
  339. }
  340. else
  341. {
  342. crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG();
  343. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText());
  344. }
  345. }
  346. pDC->FillSolidRect(rcItem, crBkgnd);
  347. nOldBKMode = pDC->SetBkMode(TRANSPARENT);
  348. CRect rcText = rcItem;
  349. rcText.left += ROW_LEFT_BORDER;
  350. rcText.top++;
  351. // Draw the text.
  352. //CString csText = GetItemText(nItem, 0);
  353. CString csText;
  354. LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize);
  355. GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize);
  356. csText.ReleaseBuffer();
  357. // extract symbols
  358. CString strSymbols;
  359. int nSymEnd = csText.Find('|');
  360. if( nSymEnd >= 0 )
  361. {
  362. strSymbols = csText.Left(nSymEnd);
  363. csText = csText.Mid(nSymEnd+1);
  364. }
  365. // set firstTenNum to the first ten number (1-10) corresponding to
  366. // the current nItem.
  367. // -1 means that nItem is not in the FirstTen block.
  368. int firstTenNum = GetFirstTenNum(nItem);
  369. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  370. {
  371. rcText.left += 12;
  372. }
  373. // if we are inside a group, don't display the "in group" flag
  374. if( theApp.m_GroupID > 0 )
  375. {
  376. int nFlag = strSymbols.Find(_T("!"));
  377. if( nFlag >= 0 )
  378. strSymbols.Delete(nFlag);
  379. }
  380. DrawBitMap(nItem, rcText, pDC, csText);
  381. // draw the symbol box
  382. if( strSymbols.GetLength() > 0 )
  383. {
  384. strSymbols = " " + strSymbols + " "; // leave space for box
  385. // add spaces to leave room for the symbols
  386. CRect rectSym(rcText.left, rcText.top+1, rcText.left, rcText.top+1);
  387. CRect rectSpace(0,0,0,0);
  388. //Get text bounds
  389. pDC->DrawText(" ", &rectSpace, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
  390. pDC->DrawText(strSymbols, &rectSym, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
  391. VERIFY( rectSpace.Width() > 0 );
  392. // int numSpaces = rectSym.Width() / rectSpace.Width();
  393. // numSpaces++;
  394. // csText = CString(' ',numSpaces) + csText;
  395. // draw the symbols
  396. pDC->FillSolidRect( rectSym, GetSysColor(COLOR_ACTIVECAPTION) );
  397. //pDC->FillSolidRect( rectSym, RGB(0,255,255) );
  398. pDC->Draw3dRect(rectSym, GetSysColor(COLOR_3DLIGHT), GetSysColor(COLOR_3DDKSHADOW));
  399. // COLORREF crOld = pDC->SetTextColor(GetSysColor(COLOR_INFOTEXT));
  400. COLORREF crOld = pDC->SetTextColor(RGB(255, 255, 255));
  401. pDC->DrawText(strSymbols, rectSym, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
  402. pDC->SetTextColor(crOld);
  403. rcText.left += rectSym.Width() + 2;
  404. }
  405. if(DrawRtfText(nItem, rcText, pDC) == FALSE)
  406. {
  407. pDC->DrawText(csText, rcText, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
  408. }
  409. // Draw a focus rect around the item if necessary.
  410. if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
  411. pDC->DrawFocusRect(rcItem);
  412. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  413. {
  414. CString cs;
  415. if( firstTenNum == 10 )
  416. cs = "0";
  417. else
  418. cs.Format(_T("%d"), firstTenNum);
  419. CRect crClient;
  420. GetWindowRect(crClient);
  421. ScreenToClient(crClient);
  422. CRect crHotKey = rcItem;
  423. crHotKey.right = crHotKey.left + 11;
  424. crHotKey.left += 2;
  425. crHotKey.top += 2;
  426. HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
  427. pDC->DrawText(cs, crHotKey, DT_BOTTOM);
  428. pDC->MoveTo(CPoint(rcItem.left + 11, rcItem.top));
  429. pDC->LineTo(CPoint(rcItem.left + 11, rcItem.bottom));
  430. pDC->SelectObject(hOldFont);
  431. }
  432. // restore the previous values
  433. if(OldColor > -1)
  434. pDC->SetTextColor(OldColor);
  435. if(nOldBKMode > -1)
  436. pDC->SetBkMode(nOldBKMode);
  437. *pResult = CDRF_SKIPDEFAULT; // We've painted everything.
  438. }
  439. }
  440. BOOL CQListCtrl::DrawRtfText(int nItem, CRect &crRect, CDC *pDC)
  441. {
  442. if(g_Opt.m_bDrawRTF == FALSE)
  443. return FALSE;
  444. BOOL bRet = FALSE;
  445. CClipFormat* pThumbnail = GetItem_CF_RTF_ClipFormat(nItem);
  446. if(pThumbnail == NULL)
  447. return FALSE;
  448. // if there's no data, then we're done.
  449. if(pThumbnail->m_hgData == NULL)
  450. return FALSE;
  451. if(m_pFormatter == NULL)
  452. {
  453. m_pFormatter = new CFormattedTextDraw;
  454. m_pFormatter->Create();
  455. }
  456. if(m_pFormatter)
  457. {
  458. char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
  459. if(pData)
  460. {
  461. CComBSTR bStr(pData);
  462. m_pFormatter->put_RTFText(bStr);
  463. m_pFormatter->Draw(pDC->m_hDC, crRect);
  464. GlobalUnlock(pThumbnail->m_hgData);
  465. bRet = TRUE;
  466. }
  467. }
  468. return bRet;
  469. }
  470. // DrawBitMap loads a DIB from the DB, draws a crRect thumbnail of the image
  471. // to pDC and caches that thumbnail as a DIB in m_ThumbNails[ ItemID ].
  472. // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
  473. BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC, const CString &csDescription)
  474. {
  475. if(g_Opt.m_bDrawThumbnail == FALSE)
  476. return FALSE;
  477. CClipFormatQListCtrl *format = GetItem_CF_DIB_ClipFormat(nItem);
  478. if(format != NULL)
  479. {
  480. HGLOBAL smallImage = format->GetDib(pDC, crRect.Height());
  481. if(smallImage != NULL)
  482. {
  483. //Will return the width of the bitmap in nWidth
  484. int nWidth = 0;
  485. if(CBitmapHelper::DrawDIB(pDC, smallImage, crRect.left, crRect.top, nWidth))
  486. {
  487. // adjust the rect so other information can be drawn next to the thumbnail
  488. crRect.left += nWidth + 3;
  489. }
  490. }
  491. }
  492. else if(csDescription.Find(_T("CF_DIB")) == 0)
  493. {
  494. crRect.left += crRect.Height();
  495. }
  496. return TRUE;
  497. }
  498. void CQListCtrl::RefreshVisibleRows()
  499. {
  500. int nTopIndex = GetTopIndex();
  501. int nLastIndex = nTopIndex + GetCountPerPage();
  502. RedrawItems(nTopIndex, nLastIndex);
  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_PTR 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((int)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_PTR 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 = (int)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 = (int)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_PTR count = arr.GetSize();
  763. if(count <= 0)
  764. return;
  765. CProcessPaste paste;
  766. //Don't send the paste just load it into memory
  767. paste.m_bSendPaste = false;
  768. if(count > 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 (DWORD)info.item.lParam;
  910. }
  911. }
  912. return (DWORD)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 /* = 0 */)
  1008. {
  1009. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1010. }
  1011. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1012. {
  1013. NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
  1014. if((pnmv->uNewState == 3) ||
  1015. (pnmv->uNewState == 1))
  1016. {
  1017. if(g_Opt.m_bAllwaysShowDescription)
  1018. {
  1019. KillTimer(TIMER_SHOW_PROPERTIES);
  1020. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1021. }
  1022. if(GetSelectedCount() > 0 )
  1023. theApp.SetStatus(NULL, FALSE);
  1024. }
  1025. if(GetSelectedCount() == this->GetItemCount())
  1026. {
  1027. if(m_allSelected == false)
  1028. {
  1029. Log(StrF(_T("List box Select All")));
  1030. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1031. m_allSelected = true;
  1032. }
  1033. }
  1034. else if(m_allSelected == true)
  1035. {
  1036. Log(StrF(_T("List box REMOVED Select All")));
  1037. m_allSelected = false;
  1038. }
  1039. }
  1040. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1041. {
  1042. //http://support.microsoft.com/kb/200054
  1043. //OnTimer() Is Not Called Repeatedly for a List Control
  1044. bool callBase = true;
  1045. switch(nIDEvent)
  1046. {
  1047. case TIMER_SHOW_PROPERTIES:
  1048. {
  1049. if( theApp.m_bShowingQuickPaste )
  1050. ShowFullDescription(true);
  1051. KillTimer(TIMER_SHOW_PROPERTIES);
  1052. callBase = false;
  1053. }
  1054. break;
  1055. case TIMER_HIDE_SCROL:
  1056. {
  1057. CPoint cursorPos;
  1058. GetCursorPos(&cursorPos);
  1059. CRect crWindow;
  1060. this->GetWindowRect(&crWindow);
  1061. //check and see if they moved out of the scroll area
  1062. //If they did tell our parent so
  1063. if(MouseInScrollBarArea(crWindow, cursorPos) == false)
  1064. {
  1065. StopHideScrollBarTimer();
  1066. }
  1067. callBase = false;
  1068. }
  1069. break;
  1070. case TIMER_SHOW_SCROLL:
  1071. {
  1072. CPoint cursorPos;
  1073. GetCursorPos(&cursorPos);
  1074. CRect crWindow;
  1075. this->GetWindowRect(&crWindow);
  1076. //Adjust for the v-scroll bar being off of the screen
  1077. crWindow.right -= theApp.m_metrics.ScaleX(GetSystemMetrics(SM_CXVSCROLL));
  1078. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1079. //Check and see if we are still in the cursor area
  1080. if(MouseInScrollBarArea(crWindow, cursorPos))
  1081. {
  1082. m_timerToHideScrollAreaSet = true;
  1083. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1084. //Start looking to hide the scroll bars
  1085. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1086. }
  1087. KillTimer(TIMER_SHOW_SCROLL);
  1088. callBase = false;
  1089. }
  1090. break;
  1091. }
  1092. if(callBase)
  1093. {
  1094. CListCtrl::OnTimer(nIDEvent);
  1095. }
  1096. }
  1097. void CQListCtrl::SetLogFont(LOGFONT &font)
  1098. {
  1099. m_Font.DeleteObject();
  1100. m_Font.CreateFontIndirect(&font);
  1101. SetFont(&m_Font);
  1102. }
  1103. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1104. {
  1105. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1106. }
  1107. BOOL CQListCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1108. {
  1109. return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
  1110. }
  1111. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1112. {
  1113. NMLVCACHEHINT* pcachehint = NULL;
  1114. if(message == WM_NOTIFY)
  1115. {
  1116. NMHDR* phdr = (NMHDR*)lParam;
  1117. switch(phdr->code)
  1118. {
  1119. case LVN_ODCACHEHINT:
  1120. pcachehint= (NMLVCACHEHINT*) phdr;
  1121. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1122. return FALSE;
  1123. }
  1124. }
  1125. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1126. }
  1127. BOOL CQListCtrl::OnItemDeleted(long lID)
  1128. {
  1129. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1130. return (bRet2);
  1131. }
  1132. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1133. {
  1134. CRect crWindow;
  1135. this->GetWindowRect(&crWindow);
  1136. ScreenToClient(&crWindow);
  1137. crWindow.right -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1138. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1139. if(MouseInScrollBarArea(crWindow, point))
  1140. {
  1141. if((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1142. {
  1143. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1144. m_mouseOverScrollAreaStart = GetTickCount();
  1145. }
  1146. }
  1147. else
  1148. {
  1149. if(m_timerToHideScrollAreaSet)
  1150. {
  1151. StopHideScrollBarTimer();
  1152. }
  1153. KillTimer(TIMER_SHOW_SCROLL);
  1154. }
  1155. }
  1156. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1157. {
  1158. CRect crRight(crWindow);
  1159. CRect crBottom(crWindow);
  1160. crRight.left = crRight.right - theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1161. crBottom.top = crBottom.bottom - theApp.m_metrics.ScaleY(::GetSystemMetrics(SM_CYHSCROLL));
  1162. /*CString cs;
  1163. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1164. OutputDebugString(cs);*/
  1165. if(crRight.PtInRect(point) || crBottom.PtInRect(point))
  1166. {
  1167. return true;
  1168. }
  1169. return false;
  1170. }
  1171. void CQListCtrl::StopHideScrollBarTimer()
  1172. {
  1173. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1174. m_timerToHideScrollAreaSet = false;
  1175. KillTimer(TIMER_HIDE_SCROL);
  1176. }