QListCtrl.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485
  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_DBLCLK, OnDblclk)
  112. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdrawList)
  113. ON_WM_MOUSEMOVE()
  114. ON_WM_SYSKEYDOWN()
  115. ON_WM_ERASEBKGND()
  116. ON_WM_CREATE()
  117. ON_WM_HSCROLL()
  118. ON_WM_TIMER()
  119. ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnSelectionChange)
  120. ON_WM_VSCROLL()
  121. ON_WM_WINDOWPOSCHANGED()
  122. ON_WM_MOUSEWHEEL()
  123. //}}AFX_MSG_MAP
  124. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
  125. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
  126. ON_WM_KILLFOCUS()
  127. ON_WM_MEASUREITEM_REFLECT()
  128. END_MESSAGE_MAP()
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CQListCtrl message handlers
  131. void CQListCtrl::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult)
  132. {
  133. LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
  134. *pResult = 0;
  135. }
  136. DROPEFFECT CQListCtrl::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
  137. {
  138. return DROPEFFECT_COPY;
  139. }
  140. void CQListCtrl::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
  141. {
  142. LPNMITEMACTIVATE lpnmItem = (LPNMITEMACTIVATE) pNMHDR;
  143. UINT Flags;
  144. int nItem = -1;
  145. if ((nItem = HitTest(lpnmItem->ptAction, &Flags)) != -1)
  146. {
  147. if (Flags | LVHT_ONITEM)
  148. SendSelection(nItem);
  149. }
  150. *pResult = 0;
  151. }
  152. void CQListCtrl::SendSelection(int nItem)
  153. {
  154. GetParent()->SendMessage(NM_SELECT, 1, (LPARAM) &nItem);
  155. }
  156. void CQListCtrl::SendSelection(ARRAY &arrItems)
  157. {
  158. GetParent()->SendMessage(NM_SELECT, arrItems.GetSize(), (LPARAM) arrItems.GetData());
  159. }
  160. void CQListCtrl::GetSelectionIndexes(ARRAY &arr)
  161. {
  162. arr.RemoveAll();
  163. POSITION pos = GetFirstSelectedItemPosition();
  164. while (pos)
  165. {
  166. arr.Add(GetNextSelectedItem(pos));
  167. }
  168. }
  169. bool CQListCtrl::PutSelectedItemOnDittoCopyBuffer(long lBuffer)
  170. {
  171. bool bRet = false;
  172. ARRAY arr;
  173. GetSelectionItemData(arr);
  174. INT_PTR nCount = arr.GetSize();
  175. if(nCount > 0 && arr[0])
  176. {
  177. CDittoCopyBuffer::PutClipOnDittoCopyBuffer(arr[0], lBuffer);
  178. bRet = true;
  179. }
  180. return bRet;
  181. }
  182. void CQListCtrl::GetSelectionItemData(ARRAY &arr)
  183. {
  184. DWORD dwData;
  185. int i;
  186. arr.RemoveAll();
  187. POSITION pos = GetFirstSelectedItemPosition();
  188. while (pos)
  189. {
  190. i = GetNextSelectedItem(pos);
  191. dwData = GetItemData(i);
  192. arr.Add( dwData );
  193. }
  194. }
  195. void CQListCtrl::RemoveAllSelection()
  196. {
  197. POSITION pos = GetFirstSelectedItemPosition();
  198. while (pos)
  199. {
  200. SetSelection(GetNextSelectedItem(pos), FALSE);
  201. }
  202. }
  203. BOOL CQListCtrl::SetSelection(int nRow, BOOL bSelect)
  204. {
  205. if(bSelect)
  206. return SetItemState(nRow, LVIS_SELECTED, LVIS_SELECTED);
  207. else
  208. return SetItemState(nRow, ~LVIS_SELECTED, LVIS_SELECTED);
  209. }
  210. BOOL CQListCtrl::SetText(int nRow, int nCol, CString cs)
  211. {
  212. return SetItemText(nRow, nCol, cs);
  213. }
  214. BOOL CQListCtrl::SetCaret(int nRow, BOOL bFocus)
  215. {
  216. if(bFocus)
  217. return SetItemState(nRow, LVIS_FOCUSED, LVIS_FOCUSED);
  218. else
  219. return SetItemState(nRow, ~LVIS_FOCUSED, LVIS_FOCUSED);
  220. }
  221. long CQListCtrl::GetCaret()
  222. {
  223. return GetNextItem(-1, LVNI_FOCUSED);
  224. }
  225. // moves the caret to the given index, selects it, and ensures it is visible.
  226. BOOL CQListCtrl::SetListPos( int index )
  227. {
  228. if( index < 0 || index >= GetItemCount() )
  229. return FALSE;
  230. RemoveAllSelection();
  231. SetCaret(index);
  232. SetSelection(index);
  233. EnsureVisible(index,FALSE);
  234. return TRUE;
  235. }
  236. BOOL CQListCtrl::SetFormattedText(int nRow, int nCol, LPCTSTR lpszFormat,...)
  237. {
  238. CString csText;
  239. va_list vlist;
  240. ASSERT(AfxIsValidString(lpszFormat));
  241. va_start(vlist,lpszFormat);
  242. csText.FormatV(lpszFormat,vlist);
  243. va_end(vlist);
  244. return SetText(nRow,nCol,csText);
  245. }
  246. void CQListCtrl::SetNumberOfLinesPerRow(int nLines)
  247. {
  248. if(m_linesPerRow != nLines)
  249. {
  250. m_linesPerRow = nLines;
  251. CRect rc;
  252. GetWindowRect( &rc );
  253. WINDOWPOS wp;
  254. wp.hwnd = m_hWnd;
  255. wp.cx = rc.Width();
  256. wp.cy = rc.Height();
  257. wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
  258. SendMessage( WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp );
  259. }
  260. }
  261. void CQListCtrl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  262. {
  263. TEXTMETRIC tm;
  264. HDC hDC = ::GetDC(NULL);
  265. CFont* pFont = GetFont();
  266. HFONT hFontOld = (HFONT)SelectObject(hDC, pFont->GetSafeHandle());
  267. GetTextMetrics(hDC, &tm);
  268. lpMeasureItemStruct->itemHeight = ((tm.tmHeight + tm.tmExternalLeading) * m_linesPerRow) + ROW_BOTTOM_BORDER;
  269. m_rowHeight = lpMeasureItemStruct->itemHeight;
  270. SelectObject(hDC, hFontOld);
  271. ::ReleaseDC(NULL, hDC);
  272. }
  273. void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
  274. {
  275. NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
  276. *pResult = 0;
  277. // Request item-specific notifications if this is the
  278. // beginning of the paint cycle.
  279. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
  280. {
  281. *pResult = CDRF_NOTIFYITEMDRAW;
  282. }
  283. else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
  284. {
  285. LVITEM rItem;
  286. int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
  287. CDC* pDC = CDC::FromHandle ( pLVCD->nmcd.hdc );
  288. COLORREF crBkgnd;
  289. BOOL bListHasFocus;
  290. CRect rcItem;
  291. bListHasFocus = ( GetSafeHwnd() == ::GetFocus() );
  292. // Get the image index and selected/focused state of the
  293. // item being drawn.
  294. ZeroMemory ( &rItem, sizeof(LVITEM) );
  295. rItem.mask = LVIF_STATE;
  296. rItem.iItem = nItem;
  297. rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  298. GetItem(&rItem);
  299. // Get the rect that bounds the text label.
  300. GetItemRect(nItem, rcItem, LVIR_LABEL);
  301. rcItem.left -= DUMMY_COL_WIDTH;
  302. COLORREF OldColor = -1;
  303. int nOldBKMode = -1;
  304. CString csText;
  305. LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize);
  306. GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize);
  307. csText.ReleaseBuffer();
  308. // extract symbols
  309. CString strSymbols;
  310. int nSymEnd = csText.Find('|');
  311. if (nSymEnd >= 0)
  312. {
  313. strSymbols = csText.Left(nSymEnd);
  314. csText = csText.Mid(nSymEnd + 1);
  315. }
  316. // Draw the background of the list item. Colors are selected
  317. // according to the item's state.
  318. if(rItem.state & LVIS_SELECTED)
  319. {
  320. if(bListHasFocus)
  321. {
  322. crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG();
  323. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText());
  324. }
  325. else
  326. {
  327. crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG();
  328. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText());
  329. }
  330. }
  331. else
  332. {
  333. //Shade alternating Rows
  334. if((nItem % 2) == 0)
  335. {
  336. crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG();
  337. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText());
  338. }
  339. else
  340. {
  341. crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG();
  342. OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText());
  343. }
  344. }
  345. pDC->FillSolidRect(rcItem, crBkgnd);
  346. nOldBKMode = pDC->SetBkMode(TRANSPARENT);
  347. CRect rcText = rcItem;
  348. rcText.left += ROW_LEFT_BORDER;
  349. rcText.top++;
  350. // set firstTenNum to the first ten number (1-10) corresponding to
  351. // the current nItem.
  352. // -1 means that nItem is not in the FirstTen block.
  353. int firstTenNum = GetFirstTenNum(nItem);
  354. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  355. {
  356. rcText.left += theApp.m_metrics.ScaleX(12);
  357. }
  358. // if we are inside a group, don't display the "in group" flag
  359. if( theApp.m_GroupID > 0 )
  360. {
  361. int nFlag = strSymbols.Find(_T("!"));
  362. if( nFlag >= 0 )
  363. strSymbols.Delete(nFlag);
  364. }
  365. DrawBitMap(nItem, rcText, pDC, csText);
  366. // draw the symbol box
  367. if( strSymbols.GetLength() > 0 )
  368. {
  369. if(strSymbols.Find('G') >= 0) //group
  370. {
  371. m_groupFolder.Draw(pDC, this, rcText.left, rcText.top, false, false);
  372. rcText.left += m_groupFolder.ImageWidth() + theApp.m_metrics.ScaleX(2);
  373. }
  374. if (strSymbols.Find('*') >= 0 &&
  375. strSymbols.Find('G') < 0 &&
  376. strSymbols.Find(_T("sticky")) < 0) //don't auto delete
  377. {
  378. m_dontDeleteImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  379. rcText.left += m_dontDeleteImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  380. }
  381. if (strSymbols.Find('s') >= 0) // has shortcut
  382. {
  383. m_shortCutImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  384. rcText.left += m_shortCutImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  385. }
  386. if (strSymbols.Find('!') >= 0) // in group
  387. {
  388. m_inFolderImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  389. rcText.left += m_inFolderImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  390. }
  391. if (strSymbols.Find('Q') >= 0) // has quick paste text
  392. {
  393. }
  394. if (strSymbols.Find(_T("Sticky")) >= 0) //sticky clip
  395. {
  396. m_stickyImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
  397. rcText.left += m_stickyImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
  398. }
  399. }
  400. if(DrawRtfText(nItem, rcText, pDC) == FALSE)
  401. {
  402. if (m_searchText.GetLength() > 0 &&
  403. FindNoCaseAndInsert(csText, m_searchText, _T("<font color='#ff0000'>"), _T("</font>")) > 0)
  404. {
  405. DrawHTML(pDC->m_hDC, csText, csText.GetLength(), rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
  406. }
  407. else
  408. {
  409. pDC->DrawText(csText, rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
  410. }
  411. }
  412. // Draw a focus rect around the item if necessary.
  413. if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
  414. pDC->DrawFocusRect(rcItem);
  415. if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
  416. {
  417. CString cs;
  418. if( firstTenNum == 10 )
  419. cs = "0";
  420. else
  421. cs.Format(_T("%d"), firstTenNum);
  422. CRect crClient;
  423. GetWindowRect(crClient);
  424. ScreenToClient(crClient);
  425. CRect crHotKey = rcItem;
  426. crHotKey.right = crHotKey.left + theApp.m_metrics.ScaleX(11);
  427. crHotKey.left += theApp.m_metrics.ScaleX(2);
  428. crHotKey.top += theApp.m_metrics.ScaleX(2);
  429. HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
  430. pDC->DrawText(cs, crHotKey, DT_BOTTOM);
  431. pDC->MoveTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(11), rcItem.top));
  432. pDC->LineTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(11), rcItem.bottom));
  433. pDC->SelectObject(hOldFont);
  434. }
  435. // restore the previous values
  436. if(OldColor > -1)
  437. pDC->SetTextColor(OldColor);
  438. if(nOldBKMode > -1)
  439. pDC->SetBkMode(nOldBKMode);
  440. *pResult = CDRF_SKIPDEFAULT; // We've painted everything.
  441. }
  442. }
  443. BOOL CQListCtrl::DrawRtfText(int nItem, CRect &crRect, CDC *pDC)
  444. {
  445. if(g_Opt.m_bDrawRTF == FALSE)
  446. return FALSE;
  447. BOOL bRet = FALSE;
  448. CClipFormat* pThumbnail = GetItem_CF_RTF_ClipFormat(nItem);
  449. if(pThumbnail == NULL)
  450. return FALSE;
  451. // if there's no data, then we're done.
  452. if(pThumbnail->m_hgData == NULL)
  453. return FALSE;
  454. if(m_pFormatter == NULL)
  455. {
  456. m_pFormatter = new CFormattedTextDraw;
  457. m_pFormatter->Create();
  458. }
  459. if(m_pFormatter)
  460. {
  461. char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
  462. if(pData)
  463. {
  464. CComBSTR bStr(pData);
  465. m_pFormatter->put_RTFText(bStr);
  466. m_pFormatter->Draw(pDC->m_hDC, crRect);
  467. GlobalUnlock(pThumbnail->m_hgData);
  468. bRet = TRUE;
  469. }
  470. }
  471. return bRet;
  472. }
  473. // DrawBitMap loads a DIB from the DB, draws a crRect thumbnail of the image
  474. // to pDC and caches that thumbnail as a DIB in m_ThumbNails[ ItemID ].
  475. // ALL items are cached in m_ThumbNails (those without images are cached with NULL m_hgData)
  476. BOOL CQListCtrl::DrawBitMap(int nItem, CRect &crRect, CDC *pDC, const CString &csDescription)
  477. {
  478. if(g_Opt.m_bDrawThumbnail == FALSE)
  479. return FALSE;
  480. CClipFormatQListCtrl *format = GetItem_CF_DIB_ClipFormat(nItem);
  481. if(format != NULL)
  482. {
  483. HGLOBAL smallImage = format->GetDib(pDC, crRect.Height());
  484. if(smallImage != NULL)
  485. {
  486. //Will return the width of the bitmap in nWidth
  487. int nWidth = 0;
  488. if(CBitmapHelper::DrawDIB(pDC, smallImage, crRect.left, crRect.top, nWidth))
  489. {
  490. // adjust the rect so other information can be drawn next to the thumbnail
  491. crRect.left += nWidth + 3;
  492. }
  493. }
  494. }
  495. else if(csDescription.Find(_T("CF_DIB")) == 0)
  496. {
  497. crRect.left += crRect.Height();
  498. }
  499. return TRUE;
  500. }
  501. void CQListCtrl::RefreshVisibleRows()
  502. {
  503. int nTopIndex = GetTopIndex();
  504. int nLastIndex = nTopIndex + GetCountPerPage();
  505. RedrawItems(nTopIndex, nLastIndex);
  506. }
  507. void CQListCtrl::RefreshRow(int row)
  508. {
  509. RedrawItems(row, row);
  510. }
  511. void CQListCtrl::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  512. {
  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. CAccel a;
  628. if(m_Accels.OnMsg(pMsg, a))
  629. {
  630. switch(a.Cmd)
  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. if(a.RefId == CHotKey::PASTE_OPEN_CLIP)
  643. {
  644. GetParent()->SendMessage(NM_SELECT_DB_ID, a.Cmd, 0);
  645. }
  646. else if(a.RefId == CHotKey::MOVE_TO_GROUP)
  647. {
  648. GetParent()->SendMessage(NM_MOVE_TO_GROUP, a.Cmd, 0);
  649. }
  650. }
  651. return TRUE;
  652. }
  653. if(VALID_TOOLTIP)
  654. {
  655. if(m_pToolTip->OnMsg(pMsg))
  656. return TRUE;
  657. }
  658. switch(pMsg->message)
  659. {
  660. case WM_KEYDOWN:
  661. if(HandleKeyDown(pMsg->wParam, pMsg->lParam))
  662. return TRUE;
  663. break; // end case WM_KEYDOWN
  664. case WM_VSCROLL:
  665. ASSERT(FALSE);
  666. break;
  667. } // end switch(pMsg->message)
  668. return CListCtrl::PreTranslateMessage(pMsg);
  669. }
  670. BOOL CQListCtrl::HandleKeyDown(WPARAM wParam, LPARAM lParam)
  671. {
  672. if(VALID_TOOLTIP)
  673. {
  674. MSG Msg;
  675. Msg.lParam = lParam;
  676. Msg.wParam = wParam;
  677. Msg.message = WM_KEYDOWN;
  678. if(m_pToolTip->OnMsg(&Msg))
  679. return TRUE;
  680. }
  681. WPARAM vk = wParam;
  682. // if a number key was pressed
  683. if('0' <= vk && vk <= '9')
  684. {
  685. // if <Ctrl> is required but is absent, then break
  686. if(g_Opt.m_bUseCtrlNumAccel && !(GetKeyState(VK_CONTROL) & 0x8000))
  687. return FALSE;
  688. int index = (int)vk - '0';
  689. // '0' is actually 10 in the ditto window
  690. if(index == 0)
  691. index = 10;
  692. // translate num 1-10 into the actual index (based upon m_bStartTop)
  693. index = GetFirstTenIndex(index);
  694. GetParent()->SendMessage(NM_SELECT_INDEX, index, 0);
  695. return TRUE;
  696. }
  697. if(VK_NUMPAD0 <= vk && vk <= VK_NUMPAD9)
  698. {
  699. // if <Ctrl> is required but is absent, then break
  700. if( g_Opt.m_bUseCtrlNumAccel && !(GetKeyState(VK_CONTROL) & 0x8000) )
  701. return FALSE;
  702. int index = (int)vk - VK_NUMPAD0;
  703. // '0' is actually 10 in the ditto window
  704. if(index == 0)
  705. index = 10;
  706. // translate num 1-10 into the actual index (based upon m_bStartTop)
  707. index = GetFirstTenIndex(index);
  708. GetParent()->SendMessage(NM_SELECT_INDEX, index, 0);
  709. return TRUE;
  710. }
  711. switch( vk )
  712. {
  713. case 'X': // Ctrl-X = Cut (prepare for moving the items into a Group)
  714. if(GetKeyState(VK_CONTROL) & 0x8000)
  715. {
  716. LoadCopyOrCutToClipboard();
  717. theApp.IC_Cut(); // uses selection
  718. return TRUE;
  719. }
  720. break;
  721. case 'C': // Ctrl-C = Copy (prepare for copying the items into a Group)
  722. if(GetKeyState(VK_CONTROL) & 0x8000)
  723. {
  724. LoadCopyOrCutToClipboard();
  725. theApp.IC_Copy(); // uses selection
  726. return TRUE;
  727. }
  728. break;
  729. case 'V': // Ctrl-V = Paste (actually performs the copy or move of items into the current Group)
  730. if(GetKeyState(VK_CONTROL) & 0x8000)
  731. {
  732. theApp.IC_Paste();
  733. return TRUE;
  734. }
  735. break;
  736. case 'A': // Ctrl-A = Select All
  737. if(GetKeyState(VK_CONTROL) & 0x8000)
  738. {
  739. int nCount = GetItemCount();
  740. for(int i = 0; i < nCount; i++)
  741. {
  742. SetSelection(i);
  743. }
  744. return TRUE;
  745. }
  746. break;
  747. } // end switch(vk)
  748. return FALSE;
  749. }
  750. void CQListCtrl::LoadCopyOrCutToClipboard()
  751. {
  752. ARRAY arr;
  753. GetSelectionItemData(arr);
  754. INT_PTR count = arr.GetSize();
  755. if(count <= 0)
  756. return;
  757. CProcessPaste paste;
  758. //Don't send the paste just load it into memory
  759. paste.m_bSendPaste = false;
  760. if(count > 1)
  761. paste.GetClipIDs().Copy(arr);
  762. else
  763. paste.GetClipIDs().Add(arr[0]);
  764. //Don't move these to the top
  765. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  766. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  767. paste.DoPaste();
  768. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  769. }
  770. bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
  771. {
  772. if (this->GetSelectedCount() == 0)
  773. {
  774. return false;
  775. }
  776. int clipId = this->GetItemData(this->GetCaret());
  777. if(VALID_TOOLTIP &&
  778. m_pToolTip->GetClipId() == clipId &&
  779. ::IsWindow(m_toolTipHwnd))
  780. {
  781. return false;
  782. }
  783. int nItem = GetCaret();
  784. CRect rc, crWindow;
  785. GetWindowRect(&crWindow);
  786. GetItemRect(nItem, rc, LVIR_BOUNDS);
  787. ClientToScreen(rc);
  788. CPoint pt;
  789. if(CGetSetOptions::GetRememberDescPos())
  790. {
  791. CGetSetOptions::GetDescWndPoint(pt);
  792. }
  793. else if(bFromAuto == false)
  794. {
  795. pt = CPoint(rc.left, rc.bottom);
  796. }
  797. else
  798. {
  799. pt = CPoint((crWindow.left + (crWindow.right - crWindow.left)/2), rc.bottom);
  800. }
  801. CString csDescription;
  802. GetToolTipText(nItem, csDescription);
  803. if (m_pToolTip == NULL ||
  804. fromNextPrev == false ||
  805. ::IsWindow(m_toolTipHwnd) == FALSE)
  806. {
  807. m_pToolTip->DestroyWindow();
  808. m_pToolTip = new CToolTipEx;
  809. m_pToolTip->Create(this);
  810. m_toolTipHwnd = m_pToolTip->GetSafeHwnd();
  811. m_pToolTip->SetNotifyWnd(GetParent());
  812. }
  813. else if(VALID_TOOLTIP)
  814. {
  815. CRect r;
  816. m_pToolTip->GetWindowRect(r);
  817. pt = r.TopLeft();
  818. m_pToolTip->SetBitmap(NULL);
  819. m_pToolTip->SetRTFText("");
  820. m_pToolTip->SetToolTipText(_T(""));
  821. }
  822. if(VALID_TOOLTIP)
  823. {
  824. m_pToolTip->SetClipId(clipId);
  825. m_pToolTip->SetSearchText(m_searchText);
  826. m_pToolTip->SetToolTipText(_T(""));
  827. m_pToolTip->SetRTFText(" ");
  828. bool bSetPlainText = false;
  829. CClipFormat Clip;
  830. Clip.m_cfType = CF_UNICODETEXT;
  831. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  832. {
  833. LPVOID pvData = GlobalLock(Clip.m_hgData);
  834. if(pvData)
  835. {
  836. CString csText = (WCHAR*)pvData;
  837. m_pToolTip->SetToolTipText(csText);
  838. bSetPlainText = true;
  839. }
  840. GlobalUnlock(Clip.m_hgData);
  841. Clip.Free();
  842. Clip.Clear();
  843. }
  844. if(bSetPlainText == false)
  845. {
  846. Clip.m_cfType = CF_TEXT;
  847. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  848. {
  849. LPVOID pvData = GlobalLock(Clip.m_hgData);
  850. if(pvData)
  851. {
  852. CString csText = (char*)pvData;
  853. m_pToolTip->SetToolTipText(csText);
  854. bSetPlainText = true;
  855. }
  856. GlobalUnlock(Clip.m_hgData);
  857. Clip.Free();
  858. Clip.Clear();
  859. }
  860. }
  861. if(bSetPlainText == false)
  862. {
  863. m_pToolTip->SetToolTipText(csDescription);
  864. }
  865. Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
  866. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  867. {
  868. LPVOID pvData = GlobalLock(Clip.m_hgData);
  869. if(pvData)
  870. {
  871. m_pToolTip->SetRTFText((char*)pvData);
  872. }
  873. GlobalUnlock(Clip.m_hgData);
  874. Clip.Free();
  875. Clip.Clear();
  876. }
  877. Clip.m_cfType = CF_DIB;
  878. if(GetClipData(nItem, Clip) && Clip.m_hgData)
  879. {
  880. CBitmap *pBitMap = new CBitmap;
  881. if(pBitMap)
  882. {
  883. CRect rcItem;
  884. GetWindowRect(rcItem);
  885. CDC *pDC = GetDC();;
  886. CBitmapHelper::GetCBitmap(&Clip, pDC, pBitMap, MAXINT);
  887. ReleaseDC(pDC);
  888. //Tooltip wnd will release
  889. m_pToolTip->SetBitmap(pBitMap);
  890. }
  891. Clip.Free();
  892. Clip.Clear();
  893. }
  894. m_pToolTip->Show(pt);
  895. }
  896. return true;
  897. }
  898. void CQListCtrl::GetToolTipText(int nItem, CString &csText)
  899. {
  900. CWnd* pParent=GetParent();
  901. if(pParent && (pParent->GetSafeHwnd() != NULL))
  902. {
  903. CQListToolTipText info;
  904. memset(&info, 0, sizeof(info));
  905. info.hdr.code = NM_GETTOOLTIPTEXT;
  906. info.hdr.hwndFrom = GetSafeHwnd();
  907. info.hdr.idFrom = GetDlgCtrlID();
  908. info.lItem = nItem;
  909. //plus 100 for extra info - shortcut and such
  910. info.cchTextMax = g_Opt.m_bDescTextSize + 100;
  911. info.pszText = csText.GetBufferSetLength(info.cchTextMax);
  912. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  913. csText.ReleaseBuffer();
  914. }
  915. }
  916. BOOL CQListCtrl::GetClipData(int nItem, CClipFormat &Clip)
  917. {
  918. return theApp.GetClipData(GetItemData(nItem), Clip);
  919. }
  920. DWORD CQListCtrl::GetItemData(int nItem)
  921. {
  922. if((GetStyle() & LVS_OWNERDATA))
  923. {
  924. CWnd* pParent=GetParent();
  925. if(pParent && (pParent->GetSafeHwnd() != NULL))
  926. {
  927. LV_DISPINFO info;
  928. memset(&info, 0, sizeof(info));
  929. info.hdr.code = LVN_GETDISPINFO;
  930. info.hdr.hwndFrom = GetSafeHwnd();
  931. info.hdr.idFrom = GetDlgCtrlID();
  932. info.item.iItem = nItem;
  933. info.item.lParam = -1;
  934. info.item.mask = LVIF_PARAM;
  935. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  936. return (DWORD)info.item.lParam;
  937. }
  938. }
  939. return (DWORD)CListCtrl::GetItemData(nItem);
  940. }
  941. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_DIB_ClipFormat(int nItem)
  942. {
  943. CClipFormatQListCtrl *format = NULL;
  944. CWnd* pParent=GetParent();
  945. if(pParent && (pParent->GetSafeHwnd() != NULL))
  946. {
  947. LV_DISPINFO info;
  948. memset(&info, 0, sizeof(info));
  949. info.hdr.code = LVN_GETDISPINFO;
  950. info.hdr.hwndFrom = GetSafeHwnd();
  951. info.hdr.idFrom = GetDlgCtrlID();
  952. info.item.iItem = nItem;
  953. info.item.lParam = NULL;
  954. info.item.mask = LVIF_CF_DIB;
  955. pParent->SendMessage(WM_NOTIFY,(WPARAM)info.hdr.idFrom,(LPARAM)&info);
  956. if(info.item.lParam != NULL)
  957. {
  958. format = (CClipFormatQListCtrl *)info.item.lParam;
  959. }
  960. }
  961. return format;
  962. }
  963. CClipFormatQListCtrl* CQListCtrl::GetItem_CF_RTF_ClipFormat(int nItem)
  964. {
  965. CClipFormatQListCtrl *format = NULL;
  966. CWnd* pParent=GetParent();
  967. if(pParent && (pParent->GetSafeHwnd() != NULL))
  968. {
  969. LV_DISPINFO info;
  970. memset(&info, 0, sizeof(info));
  971. info.hdr.code = LVN_GETDISPINFO;
  972. info.hdr.hwndFrom = GetSafeHwnd();
  973. info.hdr.idFrom = GetDlgCtrlID();
  974. info.item.iItem = nItem;
  975. info.item.lParam = NULL;
  976. info.item.mask = LVIF_CF_RICHTEXT;
  977. pParent->SendMessage(WM_NOTIFY, (WPARAM)info.hdr.idFrom, (LPARAM)&info);
  978. if(info.item.lParam != NULL)
  979. {
  980. format = (CClipFormatQListCtrl *)info.item.lParam;
  981. }
  982. }
  983. return format;
  984. }
  985. void CQListCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  986. {
  987. CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
  988. }
  989. void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate, CppSQLite3DB &db)
  990. {
  991. m_Accels.RemoveAll();
  992. if(bCreate)
  993. {
  994. CMainTableFunctions::LoadAcceleratorKeys(m_Accels, db);
  995. LoadDittoCopyBufferHotkeys();
  996. }
  997. }
  998. void CQListCtrl::LoadDittoCopyBufferHotkeys()
  999. {
  1000. CCopyBufferItem Item;
  1001. CAccel a;
  1002. g_Opt.GetCopyBufferItem(0, Item);
  1003. if(Item.m_lCopyHotKey > 0)
  1004. {
  1005. a.Cmd = COPY_BUFFER_HOT_KEY_1_ID;
  1006. a.Key = Item.m_lCopyHotKey;
  1007. m_Accels.AddAccel(a);
  1008. }
  1009. g_Opt.GetCopyBufferItem(1, Item);
  1010. if(Item.m_lCopyHotKey > 0)
  1011. {
  1012. a.Cmd = COPY_BUFFER_HOT_KEY_2_ID;
  1013. a.Key = Item.m_lCopyHotKey;
  1014. m_Accels.AddAccel(a);
  1015. }
  1016. g_Opt.GetCopyBufferItem(2, Item);
  1017. if(Item.m_lCopyHotKey > 0)
  1018. {
  1019. a.Cmd = COPY_BUFFER_HOT_KEY_3_ID;
  1020. a.Key = Item.m_lCopyHotKey;
  1021. m_Accels.AddAccel(a);
  1022. }
  1023. }
  1024. void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
  1025. {
  1026. CListCtrl::OnKillFocus(pNewWnd);
  1027. //if(FocusOnToolTip() == FALSE)
  1028. //m_pToolTip->Hide();
  1029. }
  1030. HWND CQListCtrl::GetToolTipHWnd()
  1031. {
  1032. if(VALID_TOOLTIP)
  1033. return m_pToolTip->GetSafeHwnd();
  1034. return NULL;
  1035. }
  1036. BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
  1037. {
  1038. return CListCtrl::SetItemCountEx(iCount, dwFlags);
  1039. }
  1040. void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
  1041. {
  1042. NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
  1043. if((pnmv->uNewState == 3) ||
  1044. (pnmv->uNewState == 1))
  1045. {
  1046. if(g_Opt.m_bAllwaysShowDescription)
  1047. {
  1048. KillTimer(TIMER_SHOW_PROPERTIES);
  1049. SetTimer(TIMER_SHOW_PROPERTIES, 300, NULL);
  1050. }
  1051. if(GetSelectedCount() > 0 )
  1052. theApp.SetStatus(NULL, FALSE);
  1053. }
  1054. if(GetSelectedCount() == this->GetItemCount())
  1055. {
  1056. if(m_allSelected == false)
  1057. {
  1058. Log(StrF(_T("List box Select All")));
  1059. GetParent()->SendMessage(NM_ALL_SELECTED, 0, 0);
  1060. m_allSelected = true;
  1061. }
  1062. }
  1063. else if(m_allSelected == true)
  1064. {
  1065. Log(StrF(_T("List box REMOVED Select All")));
  1066. m_allSelected = false;
  1067. }
  1068. }
  1069. void CQListCtrl::OnTimer(UINT_PTR nIDEvent)
  1070. {
  1071. //http://support.microsoft.com/kb/200054
  1072. //OnTimer() Is Not Called Repeatedly for a List Control
  1073. bool callBase = true;
  1074. switch(nIDEvent)
  1075. {
  1076. case TIMER_SHOW_PROPERTIES:
  1077. {
  1078. if( theApp.m_bShowingQuickPaste )
  1079. ShowFullDescription(true);
  1080. KillTimer(TIMER_SHOW_PROPERTIES);
  1081. callBase = false;
  1082. }
  1083. break;
  1084. case TIMER_HIDE_SCROL:
  1085. {
  1086. CPoint cursorPos;
  1087. GetCursorPos(&cursorPos);
  1088. CRect crWindow;
  1089. this->GetWindowRect(&crWindow);
  1090. //check and see if they moved out of the scroll area
  1091. //If they did tell our parent so
  1092. if(MouseInScrollBarArea(crWindow, cursorPos) == false)
  1093. {
  1094. StopHideScrollBarTimer();
  1095. }
  1096. callBase = false;
  1097. }
  1098. break;
  1099. case TIMER_SHOW_SCROLL:
  1100. {
  1101. CPoint cursorPos;
  1102. GetCursorPos(&cursorPos);
  1103. CRect crWindow;
  1104. this->GetWindowRect(&crWindow);
  1105. //Adjust for the v-scroll bar being off of the screen
  1106. crWindow.right -= theApp.m_metrics.ScaleX(GetSystemMetrics(SM_CXVSCROLL));
  1107. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1108. //Check and see if we are still in the cursor area
  1109. if(MouseInScrollBarArea(crWindow, cursorPos))
  1110. {
  1111. m_timerToHideScrollAreaSet = true;
  1112. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
  1113. //Start looking to hide the scroll bars
  1114. SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
  1115. }
  1116. KillTimer(TIMER_SHOW_SCROLL);
  1117. callBase = false;
  1118. }
  1119. break;
  1120. }
  1121. if(callBase)
  1122. {
  1123. CListCtrl::OnTimer(nIDEvent);
  1124. }
  1125. }
  1126. void CQListCtrl::SetLogFont(LOGFONT &font)
  1127. {
  1128. m_Font.DeleteObject();
  1129. m_Font.CreateFontIndirect(&font);
  1130. SetFont(&m_Font);
  1131. }
  1132. void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1133. {
  1134. CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  1135. }
  1136. BOOL CQListCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1137. {
  1138. return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
  1139. }
  1140. BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  1141. {
  1142. NMLVCACHEHINT* pcachehint = NULL;
  1143. if(message == WM_NOTIFY)
  1144. {
  1145. NMHDR* phdr = (NMHDR*)lParam;
  1146. switch(phdr->code)
  1147. {
  1148. case LVN_ODCACHEHINT:
  1149. pcachehint= (NMLVCACHEHINT*) phdr;
  1150. GetParent()->SendMessage(NM_FILL_REST_OF_LIST, pcachehint->iFrom, pcachehint->iTo);
  1151. return FALSE;
  1152. }
  1153. }
  1154. return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
  1155. }
  1156. BOOL CQListCtrl::OnItemDeleted(long lID)
  1157. {
  1158. BOOL bRet2 = m_RTFData.RemoveKey(lID);
  1159. return (bRet2);
  1160. }
  1161. void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
  1162. {
  1163. if(g_Opt.m_showScrollBar == FALSE)
  1164. {
  1165. CRect crWindow;
  1166. this->GetWindowRect(&crWindow);
  1167. ScreenToClient(&crWindow);
  1168. crWindow.right -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1169. crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));
  1170. if(MouseInScrollBarArea(crWindow, point))
  1171. {
  1172. if((GetTickCount() - m_mouseOverScrollAreaStart) > 500)
  1173. {
  1174. SetTimer(TIMER_SHOW_SCROLL, 500, NULL);
  1175. m_mouseOverScrollAreaStart = GetTickCount();
  1176. }
  1177. }
  1178. else
  1179. {
  1180. if(m_timerToHideScrollAreaSet)
  1181. {
  1182. StopHideScrollBarTimer();
  1183. }
  1184. KillTimer(TIMER_SHOW_SCROLL);
  1185. }
  1186. }
  1187. }
  1188. bool CQListCtrl::MouseInScrollBarArea(CRect crWindow, CPoint point)
  1189. {
  1190. CRect crRight(crWindow);
  1191. CRect crBottom(crWindow);
  1192. crRight.left = crRight.right - theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXVSCROLL));
  1193. crBottom.top = crBottom.bottom - theApp.m_metrics.ScaleY(::GetSystemMetrics(SM_CYHSCROLL));
  1194. /*CString cs;
  1195. cs.Format(_T("point.x: %d, Width: %d, Height: %d\n"), point.x, crWindow.Width(), crWindow.Height());
  1196. OutputDebugString(cs);*/
  1197. if(crRight.PtInRect(point) || crBottom.PtInRect(point))
  1198. {
  1199. return true;
  1200. }
  1201. return false;
  1202. }
  1203. void CQListCtrl::StopHideScrollBarTimer()
  1204. {
  1205. GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
  1206. m_timerToHideScrollAreaSet = false;
  1207. KillTimer(TIMER_HIDE_SCROL);
  1208. }
  1209. void CQListCtrl::SetSearchText(CString text)
  1210. {
  1211. m_searchText = text;
  1212. }
  1213. void CQListCtrl::HidePopup()
  1214. {
  1215. if(VALID_TOOLTIP)
  1216. m_pToolTip->Hide();
  1217. }