QListCtrl.cpp 34 KB

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