QListCtrl.cpp 34 KB

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